|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
" M( y5 Y# a: F% K2 T9 i7 n3 ^! D9 ^
如何获取选择点映射到视图空间中?源码分享
8 N7 X2 v" C+ K4 h
1 h' l' I. B0 X8 [- //------------------------------------------------------------------------------
2 e f; p& R3 F - // Select Screen Position and map to Modeling View Plane
4 g+ ?4 x2 C6 S! _3 V - //------------------------------------------------------------------------------. c1 e) r* C. t: p/ C8 g* S
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
( o3 |- Z, ` u+ n - {
) ^: M% m3 U, j# K2 L( `# ^ - NXOpen::View* myView = NULL;7 h6 b! B. m& c8 b: n( s% k! Z
- NXOpen::Point3d myCursor(0, 0, 0);+ b* V. W) m6 W) S& d- d
, w5 m6 x: m0 Z+ u- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
5 m" h/ a1 ?! `" Z) ^ - if (myResponse == NXOpen::Selection::DialogResponsePick)! s" d7 t6 X! B8 O+ o! k; O7 Q
- {( G5 z% C: }: o) R0 d2 {) T
- // obtain the current default annotation plane where PMIs are placed on- J. _$ ?" M( B5 S. ?" {3 {6 E$ E
- NXOpen::Xform *xform1;
! b# h" M& H( c8 z9 h1 N1 b - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
1 O( \2 `7 h( L$ M+ q% l5 R - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();( b- H: e5 g5 a5 L3 W0 |( @, x' }
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();' v& l+ [' f1 S
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
3 I0 P h# }3 C# N( W8 u% `1 `1 d5 u6 I - . D& ~( j. E- s1 h; Q2 _1 D
- // create the ray 'into the screen' at the selected cursor position
8 D4 W4 E& W2 [0 ]8 N - NXOpen::Matrix3x3 vmx = myView->Matrix();
0 a+ s5 s5 w1 L, e E# _; n$ A - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
) e4 T: p3 U' _4 Y. V - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
$ A4 h Y0 a& w3 X5 a5 ^ - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ N+ K2 ?6 b2 v2 w0 k
- lineRay->SetName("Ray");
( t. @6 o5 ~7 t+ J. ]0 A
! j* m. M( R& x/ C% v3 s' c0 V- // create the plane from the view to intersect with the ray$ W4 X% ~! a$ G1 `/ S
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
* d* C- n: g% |9 p) f) q- n. l+ b - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
0 b, c) a3 c; [. i/ `! u - planeView->SetName("ViewPlane");. B& c7 F* p6 b: [4 ^
- 8 O3 g# l* L% |8 R. q; Q5 Q; z- B
- // now create the intersection point, L# d) e* r5 }& p4 C3 @! \9 B
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);* k# x4 A- h8 p/ l1 ?6 C
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);' L+ o* v+ u+ F4 c$ g, B+ E
- pntInterSect->SeTColor(10);
5 [$ |, l& f" U z - pntInterSect->SetName("Intersection");* d9 F3 T8 x9 o- }9 x/ k$ K
9 L3 q+ ]; {7 u" c# H% i- pos = pntInterSect->Coordinates();" \0 e! W' c0 N$ e7 P* t( N) V+ I
- print("\nPMI Position:", pos);
! s) B2 \' x: T; F" ` - . ^: W, N; L9 |6 z" F
- // clean up - comment to see intermediate objects9 V! a3 d- ]8 \
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
9 [$ L5 ~& C0 f - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);1 M2 U0 Z- W& h. Z
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
9 e- k4 v$ `8 w/ @3 w, _6 v! H - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);2 J! Y; J7 X: L- t& {+ O" n$ e" D
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
% j, {( \9 }& X v0 v; q - m_session->DeleteUndoMark(markDel, NULL);
' r8 @# K# o: x# w$ s) C3 R% v - 2 b. k* o9 A1 M% c+ C! H4 c4 f
- return true;% s/ K+ p5 i. }8 z
- }6 A" g& G! w( B, v' Z0 a
$ o; g! p3 q8 x8 N3 z. K+ i/ L2 n- return false;" s# W1 v$ u& Y4 f9 u! ~' L4 K
- }
复制代码 . V+ V6 r: @1 G2 c, x6 ~& L
, \6 y3 |, H1 L' W9 _& R
|
|