|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! s4 g! L6 `* Y. k$ n
# I& j! Y, b S: F( v2 ]* c如何获取选择点映射到视图空间中?源码分享
9 z+ ?' \0 x5 ^+ L- C0 d! X
) F$ g3 u3 m. r, N! h- //------------------------------------------------------------------------------! ]: b# n9 k+ T9 T5 s0 I
- // Select Screen Position and map to Modeling View Plane
) l& k/ Z6 V1 a/ v% C - //------------------------------------------------------------------------------% p" Z: U1 O! [* }% ^8 O& q0 _
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos): u/ a# T" P/ }3 `( d2 U
- {
, [- d3 V+ g! ~8 T" P' k9 u2 Q - NXOpen::View* myView = NULL;8 ?0 l; e' T6 K5 l$ ]8 I
- NXOpen::Point3d myCursor(0, 0, 0);
( r6 [" ^4 k9 b; @ - . q/ X$ w/ k4 k+ U6 P, a
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);" U, y) J: J9 ?8 [1 Y
- if (myResponse == NXOpen::Selection::DialogResponsePick)
+ ]$ p1 o( _2 E2 p8 u6 _+ P - {3 }; C, U) j. x, d, |
- // obtain the current default annotation plane where PMIs are placed on
' s* s$ L7 O* J$ ~7 W* o' q! O - NXOpen::Xform *xform1;4 r7 x7 R1 c( P0 m2 v
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
+ I. G3 P8 K% a# w& M - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
3 Z2 J# {, }$ b* d. X- H3 }. k4 s' E - NXOpen::Point3d ptDefaultPlane = xform1->Origin();3 J' J& l3 ~1 l2 t
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
# X! l# h" |1 A+ e* R8 I3 S
; r+ Y( B! a3 `( h: J; }& j- // create the ray 'into the screen' at the selected cursor position* p" @& J6 j$ d9 r: y: e6 i
- NXOpen::Matrix3x3 vmx = myView->Matrix();: _0 q$ ~1 L; T, N/ k+ s
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
7 {4 a6 l1 h0 f9 @" i: d" ? - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000); F! v9 L! k+ b
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
6 p q4 L* `+ |& `8 U: n+ k - lineRay->SetName("Ray");" K: Z$ @; R1 x$ N( V8 E b. O' T
- " }6 j# j7 c# c: L4 C& ?
- // create the plane from the view to intersect with the ray
) g1 E3 H! L0 Y* I! ]1 Q2 _ - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);6 j( y% x1 \# e! T2 a
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
" [6 H+ p ?& f$ U- s - planeView->SetName("ViewPlane");, `& T) V. C+ {$ c
- 8 W+ g) [1 R: o: b B
- // now create the intersection point
]4 a4 a) k# g, I8 v - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
7 Y/ c2 X4 L: f+ t2 Y$ N8 u - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; G+ v2 u/ b6 G/ i: _
- pntInterSect->SeTColor(10);2 Z% k0 U9 ~7 f3 { t
- pntInterSect->SetName("Intersection");
* V7 o7 Q8 d/ K Y/ I: q* w
6 y4 {7 i* \9 s* g; N- pos = pntInterSect->Coordinates();
) T$ F8 `2 N0 C7 y6 Y- j - print("\nPMI Position:", pos);+ G0 ^' l$ D5 D, A
- 4 i" [, m: r2 s( E% P Q$ i
- // clean up - comment to see intermediate objects
0 E& |9 R" k9 @ - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");+ ~- l4 D# `" b6 Q$ c, g0 {0 G- e
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
- k p& |" U7 z- [* B8 f( R$ ? - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);3 R" M. l& k3 w8 D/ J
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
) r7 A3 P7 R+ c' Z" {* S% a - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
* P8 I% ^; J8 `8 {9 ]; W0 n) M - m_session->DeleteUndoMark(markDel, NULL);
6 Z# a; U" G# m0 f
' q1 E4 \& F( D# z2 G( j1 F- return true;8 Y2 w/ X& a3 a( m8 ~8 Q0 {
- }
% @: R% E1 z7 U - - L( ]. V" D$ H4 ~: J6 Y0 e# a
- return false;
1 ^( I8 i0 l, a4 \8 b# x% U - }
复制代码
% n6 a: o7 o- U" G! X
2 {! {2 T) R' _* G, p1 F9 y |
|