|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# p7 v }% e8 {% x; b( b
& Y* p8 q- T( T# ~如何获取选择点映射到视图空间中?源码分享
9 @0 N) R3 E8 C& {% H+ r( t' e- ]1 q; [' p7 ?/ @( j, U
- //------------------------------------------------------------------------------
4 f- I8 V& A' x/ X/ U - // Select Screen Position and map to Modeling View Plane+ H8 t G4 [5 \, W: ]7 q0 [
- //------------------------------------------------------------------------------% {( J) R# t( ?
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
K) W, \+ [6 ^% `' T - {: f: A D! J" Q' l9 C3 V
- NXOpen::View* myView = NULL;. {! l8 \/ l: S( L& w6 _
- NXOpen::Point3d myCursor(0, 0, 0);& l$ G: b d' K5 \
7 k; K+ Q* I8 c+ X/ K/ s- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
* ^! }5 o! a4 a2 u - if (myResponse == NXOpen::Selection::DialogResponsePick)
+ \2 K% d" f; A - {- L+ B9 m+ @, T% F
- // obtain the current default annotation plane where PMIs are placed on' B" U8 ^, m" ?, d) t3 x2 G
- NXOpen::Xform *xform1;
9 t" S7 R+ C( F$ ^ - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
+ {( I5 z* m9 u+ V9 g2 o - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
+ a& ?! c7 J1 V' X5 K - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
; f; w9 S8 T; v# u5 M. l3 ] - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);/ N, K1 c0 H g8 p. ~1 b$ M
# V4 W- W% X S9 F- // create the ray 'into the screen' at the selected cursor position6 K* G. n) M5 @6 p- ]8 w& L
- NXOpen::Matrix3x3 vmx = myView->Matrix();) n/ e7 H$ |7 g
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
! q$ t7 x0 D3 b) Q. ~ - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);/ s. ^- k7 S" G) T& a# m6 w
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
, Y( ~& _! q+ H: l, c9 @ t - lineRay->SetName("Ray");
) k+ H& r& M# H" f! B% @ - 9 G! M+ S) \) i' s
- // create the plane from the view to intersect with the ray6 M4 q( }5 g+ [9 U D d
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
( _8 F/ \4 J6 a - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
! y I; b0 E$ k, Z2 D - planeView->SetName("ViewPlane");3 F) C3 W) z9 B: p1 z6 I( S& @
- . M$ h4 T0 o: [9 E1 H5 J
- // now create the intersection point
7 i1 V+ T. ?9 X( r4 x - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
; f6 f$ h8 x( ]1 S6 |5 k - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; D. V1 E0 o* W
- pntInterSect->SeTColor(10);- _& L; d3 X1 G* Z% I
- pntInterSect->SetName("Intersection"); ~; f- Y% K, M; ~
- " d$ E5 J/ T) l" G
- pos = pntInterSect->Coordinates();" q4 o/ r' |( s% p/ T! h9 U f) m
- print("\nPMI Position:", pos);5 l. J( c( g5 T) x
4 g7 P- f% A4 e7 o4 n. ]- // clean up - comment to see intermediate objects
- J+ w" i4 ~2 z3 D, X& ^/ c1 L - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");! I3 f* R. A$ L o9 y0 Q. ^
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' w( P2 }3 @5 Q6 m
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);0 J6 B2 F' P3 D, z0 r9 B; G; Z
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 ~8 I% x: q5 H X X/ }( S
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);, L# x- H0 s* D" F8 H
- m_session->DeleteUndoMark(markDel, NULL);
# d5 ]/ L. @7 c. t6 N; Y; I - % w: S0 t" l" a" [5 i ?$ S
- return true;
$ Z4 ^# y- |5 U. {% O4 H* v - }% w3 Q8 y o x$ J* Z
3 K, k% j" b# v- return false;$ }7 g' s5 Z. G# Y
- }
复制代码 5 j6 G, h$ q/ ?
0 J' J- r2 F) V% X2 d, Q6 Y' G
|
|