|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 ^' K! y+ r; n2 A( ~: F+ F R" X
7 e6 F x/ R: R$ k1 q4 a如何获取选择点映射到视图空间中?源码分享
; l4 S0 o5 X M6 @
' r( i, u5 ^& x2 r* ?3 D- //------------------------------------------------------------------------------
, @ b$ r" v, E$ y* }" ?* K - // Select Screen Position and map to Modeling View Plane
5 G+ |7 j9 Q. [ o9 u& H& B - //------------------------------------------------------------------------------
7 n( L% E' J5 T6 ^8 a - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
_0 h. z0 `4 o - {0 G0 [2 C1 d+ b2 {
- NXOpen::View* myView = NULL;
% I0 |7 n0 k$ R5 E N" P% P* l - NXOpen::Point3d myCursor(0, 0, 0);
1 L1 f: ]8 f& g4 f: ?) D
% S1 L u" w$ C$ y; ~4 ?9 W- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);4 |( @: q$ T0 o: D& ^- y: n6 |
- if (myResponse == NXOpen::Selection::DialogResponsePick)/ j; _/ K+ C7 y7 r5 h( q9 w& K# ~
- {0 b/ Z5 l6 s. S7 o% I1 e3 z O
- // obtain the current default annotation plane where PMIs are placed on( s3 h4 ^3 {2 y. q
- NXOpen::Xform *xform1;
1 u7 U1 m/ u! C3 N - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
( [. R O. ?* [/ i$ m" P4 ]* G4 ^ - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();; x/ l- M1 t$ W; M9 E
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
' H! [! T$ j/ B - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
3 \/ t% `2 d0 g! U
" ^9 @- S; b& Z- // create the ray 'into the screen' at the selected cursor position
5 R& |% H4 t# N+ O! k& Y - NXOpen::Matrix3x3 vmx = myView->Matrix();
) p3 @1 Q3 @& v - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" Z4 U/ I2 q8 O# f1 x, C+ e1 l
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
# Y4 S; n; M3 E5 @3 P) H( ^+ P6 Q - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ V$ ?& f- r# R) |
- lineRay->SetName("Ray");0 T! N1 p6 @" ~4 n
+ u, e' R J8 O/ @: w& _& u- // create the plane from the view to intersect with the ray
% @3 Q9 ^0 _- t' } - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);; {* j; N2 t% T, N
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; r- |+ g [# {/ _1 W
- planeView->SetName("ViewPlane");. s, v# ^2 u. P9 H. V% R; Q6 z
- 9 p# B1 ^' W) ~/ Q/ s
- // now create the intersection point
7 B& r# I# u/ H1 `1 i4 p - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ n' a* a( |& a0 [* f, e/ K8 H9 h: M
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);( l; W. o/ M& {' x
- pntInterSect->SeTColor(10);
( D9 P4 r# x2 t7 ? - pntInterSect->SetName("Intersection");; j c; Y- f/ D1 J# E# j, L
- " h; ?1 k0 y% t5 ]
- pos = pntInterSect->Coordinates();% @3 n0 V2 M1 M
- print("\nPMI Position:", pos);
, ^' [; C; C+ O* |/ O
7 J# h& v# D% P- ~1 E7 u t) m- // clean up - comment to see intermediate objects
% h- C8 k( |, d8 g3 E& f - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# M' R& H! B( S. @8 b. Y* n1 ?# X
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' D' J* W2 i4 V2 f6 o* P1 J( i" j
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
& n# n. C- l3 ? - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 l- o$ C0 e% C% I3 F$ J8 j
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);# Q0 S, o e- H3 y! x- {
- m_session->DeleteUndoMark(markDel, NULL);
1 B! o1 \: L Y3 T+ v% r
7 u7 V, \8 [7 W) E* `- return true;9 o9 E! c( E1 M
- }
6 M9 H9 f* w4 w5 X1 q" ?9 r) t - - L) `1 ?4 H. R6 M
- return false;
: P/ |5 N3 q& B! x& U3 v, ] - }
复制代码 ' ~' L. p/ K5 f- f- h+ a
6 U* @2 a a3 ?8 I' r
|
|