|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% a2 y0 ?+ i) c @& B$ f- l3 I
. b! |; f4 M' h6 [如何获取选择点映射到视图空间中?源码分享* z5 Y- H; t+ ~7 R$ A* z
8 z3 j T% _1 E6 X- //------------------------------------------------------------------------------
- g/ H- n c) [' @ - // Select Screen Position and map to Modeling View Plane
+ M! A% N! Q5 B" s, N - //------------------------------------------------------------------------------. u+ K; l- b! A1 d
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
+ l+ [; t# I8 F2 l - {
7 C! d$ N# `% Y/ `6 G" Z. m$ B - NXOpen::View* myView = NULL; m9 }; U5 c4 r1 A, Y
- NXOpen::Point3d myCursor(0, 0, 0);
1 [# g: }9 V I/ t
) l; }& w- r2 |$ E% E! }8 J; {. r- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);* D5 F; c E- M, D; n8 V3 ~
- if (myResponse == NXOpen::Selection::DialogResponsePick)2 R7 \3 {1 s5 S
- {
( j- j( V* w" f - // obtain the current default annotation plane where PMIs are placed on
3 H) D/ r0 v5 V* Q& f; T - NXOpen::Xform *xform1;7 M- E3 A- f# f! r7 H. t
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
# @/ ?- [# s0 t' _2 o( M) h - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
1 m; \+ ?' ~ r6 z - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
5 c3 J) a) M3 a5 {$ e$ [) j7 y1 r9 J - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);8 |5 Z0 c# [% l& [* n
- 8 x2 Z/ Q8 O: N: B& a3 z! L
- // create the ray 'into the screen' at the selected cursor position
/ W; V% A5 d% R5 d% c - NXOpen::Matrix3x3 vmx = myView->Matrix();0 i* L; ]. K( a7 H, T* P
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);, [/ o, W+ q4 v9 {3 k
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);( I& f' A6 S" F
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);& v e$ m9 q7 O( k
- lineRay->SetName("Ray");
3 o4 h, e% n X" L, j$ `4 z; s, q - - E1 U: E1 w8 p
- // create the plane from the view to intersect with the ray
' }) Q, M- m/ r/ O* b - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
; K( l0 J8 m! L/ H - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);2 f2 S: O) e( t7 |: s2 u
- planeView->SetName("ViewPlane");& m- n6 j6 R3 m1 l. k3 H
2 c, u+ d1 e! r7 R- // now create the intersection point4 d, k$ U. K, z$ s# I# V: D4 p# m
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
0 {1 Q9 @; C U3 f- e7 S6 n/ g' F. |% ? - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 A0 z, q- \' {, K* l3 J( Z0 C' `
- pntInterSect->SeTColor(10);
# e6 [) w7 K7 \2 p - pntInterSect->SetName("Intersection");7 X# c0 z5 v9 b, R2 f
, a) y \6 f; o1 v# x- pos = pntInterSect->Coordinates();3 J/ h# R2 a# A
- print("\nPMI Position:", pos);
: y2 }9 P) X, K- L - 4 c, R* ?5 D1 ~* u/ a7 s' U
- // clean up - comment to see intermediate objects% v! i3 H# t6 P; k9 a
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
9 t4 u- G& ~; g* i - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
* C' T9 n6 i( q! O& @) E - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);4 a/ X( I0 L2 A7 Z# o. J1 j
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
' q9 p3 e R9 B/ t4 _9 p - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
! T! r" M- Q/ k7 z8 i - m_session->DeleteUndoMark(markDel, NULL);
+ c/ q; g! `7 f+ w( n/ `% P - 8 V" N: }' U0 A! w+ o9 C, D
- return true;
2 z- p" L' f$ Z - }% c8 D; h6 v9 ]! C* T
- ' b; ]5 Z q7 @- f; [3 s. R. P
- return false;2 l! V, u2 G+ f5 v0 m9 Z
- }
复制代码
+ P- J5 t* v# y! l2 `7 a
* x+ ^. i6 a& G8 r) T1 ~ |
|