|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 w( z/ O; V( @6 J( [% T: \' _6 o* T8 A; U9 ?3 q' x
如何获取选择点映射到视图空间中?源码分享
1 U7 m/ J o0 T- F7 A
' P- ?- Z9 H, g g- //------------------------------------------------------------------------------4 U5 o& m4 V5 C( ]
- // Select Screen Position and map to Modeling View Plane
/ }& [6 Q: a0 h$ R - //------------------------------------------------------------------------------; |, M4 T; s/ W! K' r% ^9 f( o
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
) H; c: Z4 e3 R- ^( N. u - {
- {5 Z, X, {4 b! M' h: ~4 W - NXOpen::View* myView = NULL;
n+ {% _: p# {. T& n - NXOpen::Point3d myCursor(0, 0, 0); c- ]) |. j3 S* F
- ) P5 O6 t$ {* I+ A4 Q
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);+ V) U/ Y, N' w) ^7 }
- if (myResponse == NXOpen::Selection::DialogResponsePick)
/ z* ]$ s% j8 _0 j# y; M* L - {
/ F* Y) |' ~ F- P" G - // obtain the current default annotation plane where PMIs are placed on2 a7 \7 b9 i/ ]# u/ J7 Z" R$ H6 G
- NXOpen::Xform *xform1;
* y b- J+ f) H- F/ A - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
* j. Y: b' o7 ~9 L8 n' d - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
, p1 \ c! x" {: O5 Y - NXOpen::Point3d ptDefaultPlane = xform1->Origin();; y0 I7 @, d5 {4 R; ]3 c
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
# _, c6 }. p8 ?$ V/ c
! @, k* G, k- @1 W) P- // create the ray 'into the screen' at the selected cursor position6 [! W M) I% Z) J; k" h5 f
- NXOpen::Matrix3x3 vmx = myView->Matrix();" E7 t% k8 c1 [8 z
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);6 U, W/ Q$ w. ^ Y
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);2 H1 a4 Z+ T, p, R( ]# k
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);( M$ |* d$ `- P) P* o
- lineRay->SetName("Ray");
8 ^! m( x( |8 R# ]4 S+ @. S/ C* [
! e6 g0 Y& D: w' P* o& H- // create the plane from the view to intersect with the ray3 N3 F5 C6 J& }9 H, q9 A* ~& |% X
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
K9 y/ P8 [6 Y# ^ - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% V' j- h* k! _' m1 F
- planeView->SetName("ViewPlane");
+ ]( J! ^8 w# v! k( g) t* Y
5 W. |0 F/ g& W+ J# T3 p- // now create the intersection point
( ?- v; B5 r! x4 R3 K# S& q - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
8 z2 R; K# {# v9 P3 B - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, h+ j6 ~- w$ e7 l1 h. j9 D" ?/ a
- pntInterSect->SeTColor(10);9 V8 Y) N, r: W0 c
- pntInterSect->SetName("Intersection");# z8 b, s: N* P+ ` X9 v
; l- L7 x; g J( e' W' w- pos = pntInterSect->Coordinates();4 l: d/ f# s( `2 p4 e- |9 e- }" |
- print("\nPMI Position:", pos);. W9 b1 q) Z+ r5 g" d7 \
- % B4 y, m2 R4 E& ~- b
- // clean up - comment to see intermediate objects+ _* M( ]3 S7 y' C* q4 `0 v( H. a
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# P6 f) g5 D9 \& F
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);6 ]) ?7 D6 Q9 w5 q) l
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);+ ~/ Z% f! R+ x6 N
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay); h9 B% r9 d: D
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
' m/ M/ i( N) v! \4 F4 X: E" R; O - m_session->DeleteUndoMark(markDel, NULL);
. y/ S0 Q, j1 i* [+ V) O; }* u - # |# K# s. A) p% |
- return true;8 c1 p& ?% B- v
- }
/ J/ a3 M2 o- @8 V' D' y - : W" u% E' t) h/ ~. v" }
- return false;- R% l2 i# l l7 q" V, K
- }
复制代码 7 E) p1 H4 z2 O& \* t8 @1 n& \$ `
% m7 F" c) N' I
|
|