|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 Y% W1 j) k+ p! ?, b% n- V
: @3 A) _5 v/ A u( Q$ b$ I6 r
如何获取选择点映射到视图空间中?源码分享
* @/ d3 T8 n, w+ j2 U& q! Y% A# X9 q* w% {
- //------------------------------------------------------------------------------2 x/ r8 m* C2 E, k9 }3 P( x
- // Select Screen Position and map to Modeling View Plane4 [4 E5 l: Y( k8 Q2 A& A- X
- //------------------------------------------------------------------------------
0 [) S; x+ A1 E7 z+ M9 |# V( _$ y0 L - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)2 W$ Y. S0 D0 W. G$ q; G9 j4 J
- {0 U; }: e9 I4 ^) M! `, N! }: o* g
- NXOpen::View* myView = NULL;
" \9 J/ {5 Y/ `( @ - NXOpen::Point3d myCursor(0, 0, 0);
7 K* q! _$ U$ ?& E9 g7 a1 t
/ G2 w: d: A! @4 T9 t1 s- q- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
; @7 [5 c) h I* z* O( M - if (myResponse == NXOpen::Selection::DialogResponsePick)
% N/ S& A6 d# T" u. ?! } - {
0 Q1 b4 G2 H/ f Y0 b. T6 O2 F6 g - // obtain the current default annotation plane where PMIs are placed on, Q0 U7 {+ a+ ~- e$ K
- NXOpen::Xform *xform1;
2 a5 }5 @' N: n - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);; \1 }0 m- D, a- J0 B* ~+ W
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
% Q" K7 i- {* [/ @ - NXOpen::Point3d ptDefaultPlane = xform1->Origin();( m4 Z- |6 a' @6 j
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
6 Z" g; e" Z! H A& P/ T - 3 P% Y+ C6 W6 G2 }, c/ j
- // create the ray 'into the screen' at the selected cursor position
( R0 F# s: s7 U7 i7 B' R- i' y& l - NXOpen::Matrix3x3 vmx = myView->Matrix();! p( H% r' ~0 U3 i, X3 s( F" ^
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
9 X6 {+ J0 r' H5 a% h) e0 c - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);) m& D( c/ M5 i: K+ |
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);2 \$ g4 \5 p8 S4 Y) y+ R( T
- lineRay->SetName("Ray");; e0 c: c* \7 g* z0 F, V
- % F; d {+ Y# N9 @
- // create the plane from the view to intersect with the ray
- Y+ u# r. n3 W5 g& | - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
3 q. t7 ~2 ~( E - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; ~$ ^% r" G+ c
- planeView->SetName("ViewPlane");" h/ c$ I5 Y2 ]" x3 V8 S
R' { K& x! g7 g8 ^5 K- // now create the intersection point
4 j! v& G) Z$ z0 ] - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
4 Z, \% _, F! R$ ^! W - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ b/ ]' ^+ g! U5 ?8 I; x6 T; ^' @+ L
- pntInterSect->SeTColor(10);9 r; `/ T" c/ V: }( P& \& |" i: h4 R
- pntInterSect->SetName("Intersection");
) y/ Y0 J( e/ [2 M% t+ I - 4 \/ S# B5 F' j; C2 j/ j
- pos = pntInterSect->Coordinates();4 i" s4 w" H! o. p4 b7 M4 k2 H: |
- print("\nPMI Position:", pos);4 ~4 t8 Y, n) W+ p' |6 z8 W
% n" y8 }2 X. V- // clean up - comment to see intermediate objects
% B1 v9 F0 N. H3 r. U - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
% p8 `/ J& M& g+ ?6 }6 i7 u - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);; [: R! o* `4 O1 V' r# v; w
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);! |; N' b. e% n$ Z9 _* d
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
6 D* O' _$ }/ O2 ~ R4 A& O8 t - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
3 N; `8 ^% p- o( W - m_session->DeleteUndoMark(markDel, NULL);
; @( [ \* I* o
4 q8 ~' h- n0 a0 d- v* J0 |8 T4 r- return true; _ B4 j, M; @ i
- }
1 T- w4 H1 [# f# k( w0 D - ) R" o" ~/ a+ {: {2 ?9 {
- return false;" `! C' ]& G7 Q) B3 [% [: t1 N
- }
复制代码
% e# @# v* d* |) U8 P/ A. M* X0 d3 q7 P, r
|
|