|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 f" d. k# _5 G
* u0 ]0 Y$ u0 U( ?+ v
如何获取选择点映射到视图空间中?源码分享
+ M4 a# \! p" ^+ Z0 B, ]
7 v; G7 [) j& g N- //------------------------------------------------------------------------------
1 c3 d7 b9 J# F: ^/ ?. X - // Select Screen Position and map to Modeling View Plane
/ z- r& R& f$ z8 C* H! }% x+ T - //------------------------------------------------------------------------------! `7 O! ~4 _, K3 _) J# y" ~
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)5 \+ l3 Y- C4 }
- {
8 ~- m' w( i( z0 m; S7 X, f - NXOpen::View* myView = NULL;, n% R$ i7 I" k4 ]; ]( T# K
- NXOpen::Point3d myCursor(0, 0, 0);! a* @& V1 U8 L7 C
- % s/ T% m; ]" k0 r$ |
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);( _. v3 o3 p- j$ o
- if (myResponse == NXOpen::Selection::DialogResponsePick)7 f4 A9 u4 B# z5 T2 T" p
- {7 ?5 }9 |' h4 t/ j
- // obtain the current default annotation plane where PMIs are placed on
t8 |; q- A7 _: U - NXOpen::Xform *xform1;
9 B- T4 T! W6 [$ W; q9 n4 c - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
" I. [+ O. `/ g8 x( ^4 T: U' Y. @ - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
, i8 p2 k& U# t% B - NXOpen::Point3d ptDefaultPlane = xform1->Origin();! D" z, p# B* K/ F- H) ~
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);/ t6 S" ]2 o% u1 Q+ M. ^# K
- $ r( Z* z& o$ o8 H8 i+ @
- // create the ray 'into the screen' at the selected cursor position
+ X) P* O/ z8 l' O* v, w% n! Q - NXOpen::Matrix3x3 vmx = myView->Matrix();
: J( i0 Y0 @& L3 G: C4 s3 r/ H - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
4 V' T8 V) O* ]" S. |$ P) m - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);5 k; O6 u( P0 n
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
4 \; T( S6 T% j4 q- o - lineRay->SetName("Ray");9 f0 v C' L: h! Q( {+ O: o
- w, F& V- |, Z; ?
- // create the plane from the view to intersect with the ray3 u, h8 \. {" Z6 ^
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
. V! e) u4 v: C) [+ i$ H, F. c; E, v4 \ - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
0 X- W& O: K% |+ c - planeView->SetName("ViewPlane");: M6 ` u* K$ n& }. b
: {' K4 M' n3 g! H3 V) p# A- // now create the intersection point2 v: f* `( Z3 @# E0 Z. S" W2 j
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& E( G3 k @4 l' Q8 L
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);' g; v9 h) y6 o' q( c
- pntInterSect->SeTColor(10);
1 S/ F5 R+ [, ]) H - pntInterSect->SetName("Intersection");# _% _: [+ n* \& C9 {2 q( [
) W5 I) l9 @4 Q% q- pos = pntInterSect->Coordinates();
* j1 P% p4 a) j9 L; \+ F - print("\nPMI Position:", pos);
/ }& d! D2 N8 t3 c C: f - - @. f! b5 k0 U/ T+ h, d- K
- // clean up - comment to see intermediate objects
' E p; x& u& G' g6 V; y - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
6 j- y, @$ P, F# i+ p/ w - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);7 o5 ~7 r5 ?+ K! n6 C; b" o/ T
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
! ]4 N; q- \, ]; u# V" K6 ~ - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);; Y% Z" b, ?( X2 T" O# p( r7 v
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);4 E0 G* T2 l4 C1 d( W7 X- e
- m_session->DeleteUndoMark(markDel, NULL);. q6 p! r% T8 I/ P4 Z% v
! p- \$ r3 [( X- return true;' P2 p. Y2 H% F; R6 z
- }, r! Z% q4 |4 a3 v5 t- P
- 5 f3 O! K/ i; _% x& p5 l+ r$ y
- return false;, S# S8 a2 x7 h3 g- T* p
- }
复制代码 7 ^6 N5 C) S% @+ M9 k% V
2 G# J* K, q9 U
|
|