|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
0 K* W4 z4 y7 I( k1 b u
+ T' w3 g8 i7 L8 S如何获取选择点映射到视图空间中?源码分享
Z' U0 A1 N3 K6 o5 r* z: ]
3 v& r; v- n( a* A% R- //------------------------------------------------------------------------------( R$ Z# D! d1 F& h
- // Select Screen Position and map to Modeling View Plane; `! Y s; k7 v( b" h
- //------------------------------------------------------------------------------
0 w, D/ T, [4 @' |" ?$ X: H - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
: S+ c2 N+ w+ }7 J/ w - {- t8 V) r9 t3 o8 H# J) O
- NXOpen::View* myView = NULL;& M; Q# Q) }$ `; g& _9 j
- NXOpen::Point3d myCursor(0, 0, 0);6 d# V$ u. }9 _& ~( ?- T: s
- # w1 Y5 w8 ]: d# ?
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
( [4 L- Q" ^5 I% n" X l8 z7 w5 h - if (myResponse == NXOpen::Selection::DialogResponsePick)
6 o* G8 l* P$ q; n1 t; `1 j - {
1 y+ j" w9 H ?: M1 a& P/ f - // obtain the current default annotation plane where PMIs are placed on' M6 i( O3 X* b
- NXOpen::Xform *xform1;) E" _# G! ^: b# M" G/ L, K: ?/ {2 s
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
+ \2 j2 K! ?2 s6 z - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
: O9 M% \3 V4 K4 ^ - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
; N2 j5 [4 J! T0 i0 z( W - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
. f4 T9 @, w5 O% u; I: \" j5 n/ {& n - ; l! \3 O1 E* w0 p+ I# H+ @
- // create the ray 'into the screen' at the selected cursor position) p& S( M ~$ N& {
- NXOpen::Matrix3x3 vmx = myView->Matrix();
( }( t6 K+ ~& S+ F - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);& w" @) C9 V3 o1 l
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);: \# l; N& N$ `- ~; k- P
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
" m/ p" y! ]8 }: _ E0 C - lineRay->SetName("Ray");
7 w5 G; V+ v# o$ P) K( m/ D
6 y4 L2 ~$ P; m- // create the plane from the view to intersect with the ray
. V+ A7 O G' c3 z% T - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
4 l, F* s' n9 {" r - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# D- ?9 A" f: K4 z' Q
- planeView->SetName("ViewPlane");+ q8 u" K0 u$ @* g1 X, J8 s. P5 l
0 z- ?- y" {4 \! c& i- // now create the intersection point
* E/ t( {4 i9 X M+ I4 u - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);8 ?' F0 u8 l9 M( \/ ^
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);7 I8 L& g$ r8 v0 | L8 z( V
- pntInterSect->SeTColor(10);$ z5 G: [4 }: D' z; c7 O, r
- pntInterSect->SetName("Intersection");* m5 n5 v1 M! p2 o& t& d" Y
+ X+ Q- f; o- s, H; L' ^- pos = pntInterSect->Coordinates();' |8 T# ?& @0 T' N% {+ x r) C7 m* Y
- print("\nPMI Position:", pos);
! X$ h- T, }& I' e - * n) M( r! l# C2 t, ~4 M4 z5 T
- // clean up - comment to see intermediate objects
' F$ T. i! r2 T5 w$ m0 ]$ ~ - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
/ f3 Z6 L# m. u0 ^) Y% L- q" R7 r - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
* ^: c6 j8 G8 z4 i - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
$ \. ~0 W8 D1 v1 s: }, X1 z- X - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);/ v6 c$ C( U* o9 L( v
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
) u |9 H+ q% v S# Z* Z3 L) e - m_session->DeleteUndoMark(markDel, NULL);' S8 Z* q w, A+ ]2 B
9 |. t) i( F) `; ]- return true;
/ Q, e0 o$ V* q' V$ L - }
t6 }$ W6 d ?! C' c, t! o - & w0 H3 t5 q& e+ ^ t& O! ?
- return false;2 ?4 D3 w- T- Q; @0 F# j
- }
复制代码
4 d- Q4 q- [. }- Y/ `9 ?) ?( d- P1 ~
|
|