|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 U- M, Q' |: c3 d4 }' f" D7 w! m; L' g" j' K. e5 S2 Z
如何获取选择点映射到视图空间中?源码分享
) P& x9 `2 m3 U& Q9 T- Y! [' v! f- O+ U( I; H" h8 i G
- //------------------------------------------------------------------------------5 N0 v; s. \, |4 _6 J
- // Select Screen Position and map to Modeling View Plane
7 c+ R$ J+ F y5 Z - //------------------------------------------------------------------------------, u; C+ _+ J3 M+ {: Z/ B A0 ^
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)4 E7 j0 ?6 R5 I
- {6 k: W" f6 ~1 Q0 P4 i; N
- NXOpen::View* myView = NULL;
$ C w' n o3 U - NXOpen::Point3d myCursor(0, 0, 0);9 b5 T, A. Q$ t
- & C) ]0 {2 Q7 ?+ o& u8 ^
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- r: N# t$ F/ j. G8 t
- if (myResponse == NXOpen::Selection::DialogResponsePick)
* ]+ ~" ~- A# u) ^+ Q - {
8 r" \5 i! c' q3 t. O( r8 k - // obtain the current default annotation plane where PMIs are placed on% i1 M2 @ B; N* Y* }& { {3 {
- NXOpen::Xform *xform1;
' Z2 a& p5 r3 `; Z% K$ q3 @ - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% H0 u6 B. ]; i% Y% _) J8 |5 \
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();9 A! [+ b9 }, l3 T( ~: @4 Y
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();% A) i( j% u0 }- Z4 o% T
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);) b4 Y2 G; |: ~! N# @) e) Y! S
" P2 A& ?4 f. F- // create the ray 'into the screen' at the selected cursor position
; Z3 O3 f+ ~+ G+ v! m7 V - NXOpen::Matrix3x3 vmx = myView->Matrix();
! o# B; K6 R% @5 n1 r+ y) } - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);: y6 n7 {% J( d- {" S$ C
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);0 _4 g' A2 I! ?- O: K. p
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# [6 U( l; B4 u5 j
- lineRay->SetName("Ray");
! y3 x# ^! x2 \+ C V% m - : `. L# w( d/ [3 W- N0 c5 |$ L3 T
- // create the plane from the view to intersect with the ray
/ C1 y' n8 T$ g0 H: J4 _ - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
, ^+ i8 J& L W2 Q& l- h* h - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, m3 A: T8 I$ \2 @' d: ~
- planeView->SetName("ViewPlane");
7 j( Z+ I8 ~4 n4 }6 a5 K - 7 A; e7 i; e) Y
- // now create the intersection point
9 [1 |* y8 g& b5 H - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
% b( M5 s+ I* ~3 [: o - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
_- x# _. H. ]2 z - pntInterSect->SeTColor(10);" Z9 s) g: s' G% u% Y) z
- pntInterSect->SetName("Intersection"); j6 u4 q4 y5 _0 T- V- }
- 5 F3 ?6 b8 K j
- pos = pntInterSect->Coordinates();1 a5 K# I3 y: _& M
- print("\nPMI Position:", pos);
2 L8 z4 f3 {. Z, \6 V: t - i! j: D/ s' V. i# ^% ?) h
- // clean up - comment to see intermediate objects
1 T: H$ ^4 C: G0 _( d4 c1 g2 v) q - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
0 P+ i6 l$ ^8 w0 Q+ C% V - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);% A1 t0 a# I' }1 K. _, Z* ]
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);5 i6 m# c, |9 r& X% }4 y B
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
1 b* L! U8 ]+ _" c6 l - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
& g* S6 Z7 S; l - m_session->DeleteUndoMark(markDel, NULL);
& R+ ]7 M$ j9 K' @5 M - : O) H7 L; s1 w& p& Q
- return true;
: Z x! ^' s2 j3 W) x - }
, x( T: L- c M+ r. f
; z. Z/ h3 i: w( F- return false;0 t/ x3 E+ Q4 h Y
- }
复制代码 ( x9 k+ P% Y- }
, c4 P+ Y! x2 A" X |
|