|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 w8 ?& o) y4 G& R
4 f7 v' e% O; \( s, N- T
如何获取选择点映射到视图空间中?源码分享2 V# E2 R/ c2 e
, s& U0 g: k1 X+ `" v- i; Z/ T- //------------------------------------------------------------------------------2 ?. E: e$ w6 d, M6 A
- // Select Screen Position and map to Modeling View Plane
% V/ t; e% f6 _, K - //------------------------------------------------------------------------------1 {0 k4 F5 @" n) L( n
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)' o4 I. e8 q" x% W. Q! z' ?+ L
- {$ @: a' G% g5 v9 T" T, o
- NXOpen::View* myView = NULL;- B* l" x$ B4 N& q
- NXOpen::Point3d myCursor(0, 0, 0);
$ \7 _0 C- u, s3 k
% l7 D$ e" R- B- m- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- K5 o: X. w. n1 w! M
- if (myResponse == NXOpen::Selection::DialogResponsePick)& d/ H) b* K# V7 C$ {- l
- {8 \$ {+ J) l5 [8 j8 B* a" h
- // obtain the current default annotation plane where PMIs are placed on! {; z. w$ Q* a* e' Q
- NXOpen::Xform *xform1;
# W- G/ H ]2 ^ - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
7 I( J- U6 ?8 g+ }( m - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
- v. F3 o9 G2 I; O - NXOpen::Point3d ptDefaultPlane = xform1->Origin();7 }- w+ D* Z2 F/ ^
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
+ }- u' k+ ?4 H2 ? W$ L
& r5 f) y. g+ `- // create the ray 'into the screen' at the selected cursor position4 u' d4 D( o* Y1 ]
- NXOpen::Matrix3x3 vmx = myView->Matrix();" C7 B0 C+ L* G
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);( l& [( p4 j+ n+ ~- p0 M6 f8 H
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);. S& v+ |( z9 \; S3 L& d
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
. o* [# X7 I3 i9 U6 X - lineRay->SetName("Ray");
; ?/ V' K7 [' E3 `; M8 d& Q( b - ; N: P7 a0 X F1 O$ H' p
- // create the plane from the view to intersect with the ray
) X4 C7 u/ e- d, W* m3 ]- h - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
. X# ] Q$ A% C: H# M' n0 w Z; |& i6 L - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. o/ e& J y! c1 f6 M% G2 L
- planeView->SetName("ViewPlane");
6 T3 @5 Y6 t) o5 m2 ~ - 2 u4 B* B; [, a* e5 F: D- F; O! U
- // now create the intersection point% [) \' K1 p* S* y+ O7 Z5 v7 z- p
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);# i" d% t( F; G" M" O+ I
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 N# w. _+ I0 `+ O
- pntInterSect->SeTColor(10);# Z3 ?2 I ?4 h, o5 i/ q% ]
- pntInterSect->SetName("Intersection");0 `3 [9 s5 j( S" G- ~
( t" I1 l, r9 u* Q- c- pos = pntInterSect->Coordinates();
5 R0 L+ H& J8 ]4 g - print("\nPMI Position:", pos);
3 U4 K4 w2 S* l' I R7 Z3 J. q
! _8 c( x. y. b3 G Y. }/ O) Y- // clean up - comment to see intermediate objects- _5 C2 ?/ s4 l8 D, h
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");+ R B& c5 E8 O. p. U7 Y
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
$ v- q/ n8 }+ o" J. W# o& R8 E" A' _ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
6 D$ S5 \+ U D( A$ r+ w; d - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
+ I2 _! y, G, {# h - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
& w1 ~' C7 A4 Y$ k, d( q - m_session->DeleteUndoMark(markDel, NULL);
2 O* [# k/ G% ~# s+ G5 } - # @: o1 v& I+ ~1 N7 s1 ^- Y: ?
- return true;
z0 Z* n' u% h4 s4 z" B" y( a8 D6 L - }& v& w# l1 m( `8 S5 R
- 9 {% l1 ?5 g$ v8 C, X
- return false;
6 t2 V! K' W: a) e - }
复制代码
# f, i8 @+ t' H+ Z% ^( O% R- W$ j5 h7 n0 M t ?2 H9 ?
|
|