|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 ? L- w$ U1 W& Q k4 w
. c) `5 K7 g( q4 Q9 Y4 E2 E: f
如何获取选择点映射到视图空间中?源码分享) o+ U5 m* I3 f* G! L/ q
) _' S% J- Z% b& U
- //------------------------------------------------------------------------------) l) Z d- |8 M% R- ]; f
- // Select Screen Position and map to Modeling View Plane
" v" W8 m( |/ t& n - //------------------------------------------------------------------------------) n2 H8 y' {5 u5 _( E. p( P
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)0 `6 o; `( U- r$ J* c
- {
! s) Q% |5 ]$ e8 L' p8 W \ - NXOpen::View* myView = NULL;
0 |1 p# E% u5 Y2 Q d0 I/ [8 K - NXOpen::Point3d myCursor(0, 0, 0);& r/ i) V9 V$ g
5 v! g- x, d2 Y ^; l5 V+ w: I- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
6 W; B$ n _5 F9 W9 v - if (myResponse == NXOpen::Selection::DialogResponsePick)
. e0 N% v O$ g% @) j: u2 r - {
7 k$ S+ s0 ?- a3 A" o' m2 v - // obtain the current default annotation plane where PMIs are placed on& P7 N8 l5 p% c8 e+ R. B
- NXOpen::Xform *xform1;1 q! [( w2 o% ?& z
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);: M1 {% q& k9 b' u8 V
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
7 G5 d6 p4 n6 _$ m - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
% s& l- ]5 ]% Y2 D2 z$ G& j% x: } - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);' a; B0 k: _7 `( w# P8 I0 C# ^3 x* l, l
" c. Q/ v) J+ o$ P/ T- // create the ray 'into the screen' at the selected cursor position
0 ?* E6 g4 j/ v - NXOpen::Matrix3x3 vmx = myView->Matrix();: E( d- ~" p4 c8 f' H0 I7 {
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);3 d6 h& c% C+ B& d
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);9 U% \; X, l4 B/ v$ M" S
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
/ J) Z4 a! `, X/ I" q+ | - lineRay->SetName("Ray");
- E% Q' |7 v3 o1 T! b$ z
: Y1 J9 u/ I9 I q0 Q6 ^ ^- // create the plane from the view to intersect with the ray
0 D( S8 t$ R% T! X; l6 T - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);( T- P9 _! n8 X( A
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ t/ x7 s/ |5 \9 ?8 h+ ~! X
- planeView->SetName("ViewPlane");
) C1 I, O- L: G* M: F
5 ^3 |0 C# L5 D- x. ` L9 P B, m- // now create the intersection point
8 Y4 ~9 T) O/ x' X: V! I - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);0 f0 d: ?. l* l
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 |7 K1 i4 P3 U' S
- pntInterSect->SeTColor(10);
/ }5 ?/ |# F/ V8 r' J) k. l - pntInterSect->SetName("Intersection");$ m" M$ I# \- c: s9 r+ p9 n
) l7 u, M8 S3 t q2 @8 T9 d- pos = pntInterSect->Coordinates();+ r' ^# {- t% M2 Q+ [1 X3 _- v* a
- print("\nPMI Position:", pos);( p1 H+ T; C2 s4 N# ?3 ]
- 6 t, }( @. l# s5 X2 a
- // clean up - comment to see intermediate objects
; B7 X5 g8 K5 s: |3 H4 d, e) E - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
6 p3 y) x9 I$ P6 J8 @ - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);- ^5 G" ~5 H) W7 H: \' [
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& D- X1 P" r3 _: [
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
' F7 W* J9 v! i: a4 M. m - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);( e1 y+ f- z3 J$ ]
- m_session->DeleteUndoMark(markDel, NULL);
; U3 L% X2 X- x6 B2 I( N% s9 F; d
3 |2 l B4 M& e* S- return true;2 D: s1 |+ x2 F
- }$ I! y; z% u4 @+ q" y
3 }; S. J6 B0 j. h q- return false;' L7 b' J% t8 X. f [0 ]' ~# i. g0 {
- }
复制代码
+ z3 _7 R& C9 V7 t- X
4 M! _+ w; ~: x0 v4 J2 h$ t' _ |
|