|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ J% v/ Z0 M8 i' {7 j( S0 u. p& x/ K2 T
如何获取选择点映射到视图空间中?源码分享
) T! I1 |6 m) z2 x/ t1 l4 [9 Q8 }# }& W7 z. } V5 @* R6 @
- //------------------------------------------------------------------------------2 e' x; Y9 C/ U1 Q. e& M6 ~0 W6 R
- // Select Screen Position and map to Modeling View Plane
+ z- ^) @' o* G& ^" S. T# D - //------------------------------------------------------------------------------0 {, r$ V" e+ I2 c9 m( b7 v G
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
7 y: Q V) h3 J, { - {
( V9 r9 j5 U0 s) B! p" d - NXOpen::View* myView = NULL;
0 H" V6 m+ q. e9 ]+ L; D - NXOpen::Point3d myCursor(0, 0, 0);
* H1 r& I7 j; K& O' @
: O; j7 K7 ~ L& r- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);& O0 z/ q6 r* {' O# n
- if (myResponse == NXOpen::Selection::DialogResponsePick)
" g/ E' G( o7 c% Z: h3 C% y+ s - {5 ~" n# H. X; t6 k$ P! o
- // obtain the current default annotation plane where PMIs are placed on
* A6 j4 F/ G& _# e. L- L - NXOpen::Xform *xform1;8 s; d7 x l; h1 x: C
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);4 q, j r' i5 Z- z0 T
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();. b4 \! k% \& ]7 @2 u! t
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();% u, p0 ~( i. _; u
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);1 t/ q4 J$ g% u: d
- . [- a* m6 d- U, \4 q
- // create the ray 'into the screen' at the selected cursor position
1 ~7 Y2 y4 O0 \3 @( g& f - NXOpen::Matrix3x3 vmx = myView->Matrix();
- F' ?8 r! H0 b - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
1 \* R6 R, F E7 b5 h/ U9 [7 g$ D - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);, U7 K) w: V" y- g3 R0 Z; S5 h
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
6 U- B5 Y% ^; z5 n/ a - lineRay->SetName("Ray");" ]( B4 H# H0 z& w" m5 d
- 7 k: m' P: {+ ^
- // create the plane from the view to intersect with the ray4 M' W" G0 M! O1 S
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
8 z7 H U& g+ P - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
$ l. t( M9 b. s8 F& | - planeView->SetName("ViewPlane");
4 G" `8 H' Y9 L% u - 9 l7 Y; g# k0 k8 [+ A; v
- // now create the intersection point
& i, z$ ~$ @+ ]7 k - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
+ ?; v8 N% M) K - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
6 ?4 b2 ~- j. L& V* z2 P5 s! V - pntInterSect->SeTColor(10);% ?( Y' z! o! V1 Z* J6 R0 L
- pntInterSect->SetName("Intersection");
) ? y0 G4 |) D4 m( p8 q# V
i. }/ p0 d0 k+ ~( w2 J- pos = pntInterSect->Coordinates();
/ E+ @5 r/ Y6 |0 T* V ~ - print("\nPMI Position:", pos);
6 B2 j9 _7 K9 a7 q, g
8 q4 M( l/ y3 u/ J$ l3 {. G- // clean up - comment to see intermediate objects
! c. e+ ~" C2 U6 | e6 O5 o - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");, e9 [2 l7 o) x
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
6 R- \7 B' h( Q) v8 b - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) _/ r+ g$ W% p* z' C- w
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);2 O" O) u2 W1 I8 d; H' X9 j9 c: s
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);2 \/ M& K% ?( d7 a
- m_session->DeleteUndoMark(markDel, NULL);
% @, m) Q% t" w
7 \% q4 a+ K2 a# S) R$ H- return true;
- b. j) M0 `5 D$ G5 s3 f - }, Y& f3 D# z- R. J* g- N
8 X; ]- G( r- b9 i6 [4 _- return false;
1 I! U3 b+ ~- v( P - }
复制代码 + i1 f4 {. l H o b: W4 R) \+ B# G7 c
) B T. Z& X Q) f2 B8 i |
|