|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 o' O& I! h; F# R5 M
# O0 H* I: e5 Z, k" s* X如何获取选择点映射到视图空间中?源码分享
0 F4 W. R+ J( V5 O# u+ [+ F# G
4 T* {9 i6 W& L- //------------------------------------------------------------------------------/ Y6 o/ U' E% ?3 p, ?
- // Select Screen Position and map to Modeling View Plane- N# s( g5 _- f% S. K1 B A. Z2 G( p
- //------------------------------------------------------------------------------7 h9 f. `, S; h3 L. Q+ H- L
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)0 U6 K' J3 ^/ t% R$ h! N$ X7 z) K, C
- {" i0 S, |- ^+ h- q0 C, q
- NXOpen::View* myView = NULL;
& X5 j0 Z( {" V8 c1 p1 V- g - NXOpen::Point3d myCursor(0, 0, 0);
$ A% }( o' [# C0 s0 N5 T" ` v1 r - 6 J. ?+ {; b# I& r
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
. M8 A& B: a L3 w. {5 s - if (myResponse == NXOpen::Selection::DialogResponsePick)2 P4 O2 q! P' v3 I2 O( M& m8 k0 d; s
- {3 E3 L' [" j/ Q, z& |
- // obtain the current default annotation plane where PMIs are placed on
% e& C8 C | v4 W D" m. U - NXOpen::Xform *xform1;
2 h8 w o0 g Z. X- f - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);+ z7 E& i+ B, {) }- [
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();9 R7 a2 e8 X5 |% M* Q
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();$ I% C0 e8 H( `) w2 N
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
* P( b% {" R8 ^ - " w, V" Z. L( w' I
- // create the ray 'into the screen' at the selected cursor position0 n: I( ]& k- w) i8 x
- NXOpen::Matrix3x3 vmx = myView->Matrix();9 q$ @5 N% p" D, Q/ X6 U, c
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
$ y8 z, H2 R2 \% {2 V4 g2 S- }: F - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);, ^6 q2 m8 Z {, z/ p! q" o
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ K3 ~, g( T5 I' L! C
- lineRay->SetName("Ray");' c- G+ o4 D+ I
; Q0 O1 m; _* E5 _9 B! q- // create the plane from the view to intersect with the ray
0 c6 X4 D- `( o' E# n+ b6 h - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);) P! C+ M0 y- `% s
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible); }7 e* j2 o0 R3 Q }
- planeView->SetName("ViewPlane");
4 A( {9 I& \- o, J0 W) t3 ?6 x
( G" |7 i% U; V" U5 A( I- // now create the intersection point
# ?9 `2 d/ r! x& z* f - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
: l5 T, k N' J2 l - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 U* E0 k- P0 T" f
- pntInterSect->SeTColor(10);
- M, E6 D8 o. \8 H4 i% S0 @' c - pntInterSect->SetName("Intersection");
4 I/ `* Y# w* C% B/ F5 Z
! E7 O8 K6 i; V) P% Z# i- pos = pntInterSect->Coordinates();: n3 ?& b! C; O
- print("\nPMI Position:", pos);+ U2 _/ n' F0 B$ E, K' Z, z" P
$ o4 e& K9 y$ R3 l- // clean up - comment to see intermediate objects8 Z6 Z+ \- O. V" I* O) A
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");* F- v& \( |, ?9 w' G8 B0 y
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
, Z" Q& A0 s u2 f9 R+ v - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- C8 \) z0 a, v" H+ j7 b& G
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
! i% j) g( A) ]% Y% x8 k# O- Q- R - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
! l& O% x' s+ l/ N9 v6 d - m_session->DeleteUndoMark(markDel, NULL);2 \4 H8 g" m$ S( r
- ) @2 ?8 s) d( T, h9 I2 w8 a# U
- return true;
) m& x* f: K1 ?4 W2 @" _- @ - }
& Z$ w/ f) l" F- Q
$ ~4 J7 X5 ?) K; j; B7 @7 P. Y- return false;
, M# C3 ], w( b. N - }
复制代码
/ i q9 I$ C5 t# {; I
- G+ o: S% d/ B# d' ~3 g& G, M |
|