|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
/ y' D9 d* }" s2 z( v2 ?, S8 G8 J0 i+ H( n: ]7 x6 a3 }0 @
如何获取选择点映射到视图空间中?源码分享
6 {; ~7 p+ F0 n& @- g3 f* F; J6 @' W% Z; e- c% f, t5 y
- //------------------------------------------------------------------------------
3 G g& K' j0 c8 U - // Select Screen Position and map to Modeling View Plane+ k5 n3 |8 X+ l9 R+ m% }
- //------------------------------------------------------------------------------8 I! W* h! d$ q' o. ~3 m9 ^
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
7 m l5 o6 V$ y3 O$ y5 P* ^* e - { H+ z! L% [$ H/ _7 a+ t* Y# N$ S
- NXOpen::View* myView = NULL;
) M! D( c2 a4 s- Q+ L - NXOpen::Point3d myCursor(0, 0, 0);& Y0 ^& m3 Q3 G" b* k. f
- / ]6 y, o/ S/ t
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
* J% `: k3 R+ D - if (myResponse == NXOpen::Selection::DialogResponsePick)
6 `$ q3 G- i# q6 A - {3 L" m. G, Y: J8 t% j
- // obtain the current default annotation plane where PMIs are placed on
* D6 G) m: u8 C, w5 B - NXOpen::Xform *xform1;
# M; ], g' b/ L ]1 U# g - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% {0 k( j+ Y" z# s' y
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
* @6 J: B' Q0 K7 Y- ` - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
+ a* `0 G1 P! l$ O2 i) n" G3 i - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);$ G6 F% i/ m& p) a
- 2 [( v8 U( X2 W( [
- // create the ray 'into the screen' at the selected cursor position
1 h: g9 J: p# Y- k5 ?2 b4 V - NXOpen::Matrix3x3 vmx = myView->Matrix();
8 K7 u1 j7 _' W- i4 W/ ^# `6 T - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
$ J( G+ F0 g0 t, A L9 [7 n - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
* h% H' G! g( V7 x6 X% L - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
3 [' {/ K4 d/ `. c% I9 E- ~: y - lineRay->SetName("Ray");
7 } O/ M# D$ c9 v0 _( S% P+ ~
- S+ J5 F9 J: ]+ h, }- // create the plane from the view to intersect with the ray
v5 l* m Q1 ~- s - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
/ ^) H) C- U5 `6 h; E - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
8 m# N% q! a4 u8 G+ [ - planeView->SetName("ViewPlane");. i v. y! i3 ^' r
) B9 s+ p9 s4 D; P9 `2 B- // now create the intersection point# c( `; v8 U0 Q9 |8 E
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 J6 H* J: K* y/ k- e$ a
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
3 X6 \. t# ^; o- S0 ?9 m* A; f& n - pntInterSect->SeTColor(10);+ J1 R$ ]2 _, d+ }& p
- pntInterSect->SetName("Intersection");; z2 O% K8 j* @) b9 `; |9 c0 }
) d6 `5 u! w; f) b0 h5 Q- pos = pntInterSect->Coordinates();7 z% b |- D; Q! G0 E0 ^" D1 P
- print("\nPMI Position:", pos);
0 A& \ H8 { `7 n0 H; [; S
" t+ F9 j: \* X8 ~6 G( G- // clean up - comment to see intermediate objects
3 f: c* k+ Y, n* C- P0 d2 P" V& y v - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
7 m. ~- V# \$ t, \0 E4 i% U% ? - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
; d; `* S1 u4 ]0 ~7 ? - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);. P" u6 P, E4 U+ B1 p9 `& d: X
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);- O% A6 A2 w8 Q
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);0 ]6 e% Y3 W6 {8 \# x1 `9 r* Q" V
- m_session->DeleteUndoMark(markDel, NULL);* _" K3 e, e- x3 e7 `! s
2 q/ G$ b+ t3 V3 B0 j$ _- return true; M v6 R, ?% T5 L( o
- }/ [/ j7 T8 ?! ], I: L
8 N! L) i: l; z/ s0 `- return false;% P) m. {, [" g9 `0 x
- }
复制代码
7 y; P% D: l: i1 ^0 y5 F) J! M# Z2 P4 w8 t& W
|
|