|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) Z' M5 a1 a' r9 E- f
: V) y/ q+ b0 d! P7 o如何获取选择点映射到视图空间中?源码分享$ b/ t) O7 e$ w; Y/ n
/ z0 c) u0 W2 L" |! t' T- //------------------------------------------------------------------------------
( q: l$ f+ o" d8 a3 ?7 P( S1 x - // Select Screen Position and map to Modeling View Plane
F# x9 e, f! |! N3 y - //------------------------------------------------------------------------------
$ |3 \0 E% u& I8 A' j - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
5 r2 \9 F4 D& \* k - {. W; l$ P+ a1 }0 ~/ k
- NXOpen::View* myView = NULL;, p* }3 U% n- f$ Q
- NXOpen::Point3d myCursor(0, 0, 0);
' L- w& l+ o9 s% F% f- e
- ^9 e4 \/ c/ r- c f; }- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
" W8 V! R& h$ m# A7 n- F - if (myResponse == NXOpen::Selection::DialogResponsePick)# n1 ~( V9 F/ r* m5 W/ U m
- {* B& k! [, i1 d. r
- // obtain the current default annotation plane where PMIs are placed on p E( `7 a& J; _; Q# B4 h
- NXOpen::Xform *xform1;, I+ {6 Q2 q' G
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
3 K3 I3 D" c; H& s - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();# q3 t: U9 Q9 j1 Y
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
1 s* V# o& ]6 B - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
. y5 R+ z! G- S/ O Z
- w# ^! a6 K* ]8 l- // create the ray 'into the screen' at the selected cursor position+ q4 p. X% d0 N
- NXOpen::Matrix3x3 vmx = myView->Matrix();
: r% q0 ~4 a9 L4 { - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
# K. D# J4 Q2 z+ Z2 c% k9 ? - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);7 \) p( E$ S1 o0 q" X
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
' a2 N# G% K2 V9 K, P$ \: Z - lineRay->SetName("Ray");
0 ~# A6 T7 ~& t
& [, U: t+ g8 ]) K; L" [) K* B- // create the plane from the view to intersect with the ray; o- `, I% [: ~/ ]5 E1 H
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
# a8 o. F; J' e) \0 D - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
& B/ ~$ _9 t/ J, { - planeView->SetName("ViewPlane");
9 ~0 c! u1 D0 N/ ] _, Q( O
, f+ p$ c" c% j$ N- // now create the intersection point
$ O4 ?2 k7 u, O# W4 k; B$ I - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ t* j, _% Q: g2 |+ X
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
/ {0 K9 i+ t5 r- ] - pntInterSect->SeTColor(10);
5 i9 ^2 J) n0 y. z ~! ` - pntInterSect->SetName("Intersection");
* D# p# h" c; O - 2 R( @2 T& B* r6 Q! z6 _3 C7 {, i
- pos = pntInterSect->Coordinates();8 ^+ p: V4 A P3 c
- print("\nPMI Position:", pos);8 Z% `# a- C+ J3 y: @. q( q
; R) _! O1 n* U- // clean up - comment to see intermediate objects/ a4 @; Q# b3 l) x
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");& i% Y. d/ V( c# B* B% x
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
; K. b$ I) ~( ?- ^4 {5 Z/ h- B ~ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
0 d1 l; L% l0 U0 H( }+ ^ - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
% H# Y; s5 e6 a! [& x0 f% s - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);8 |3 U" O0 k, s4 I& p' D+ l" Q
- m_session->DeleteUndoMark(markDel, NULL);
: C: X$ ^0 n6 [+ i
$ l' ^/ B3 F3 I9 T5 R- return true;
+ l! E" {1 J( z$ a& e( S, o; O2 \ - }
! j [8 @8 @) Z+ W: f+ c# Z' z3 S* H9 a - ; }3 v/ k5 \; _+ S; @' y9 c7 A+ ^
- return false;
/ y* A& x9 v8 j - }
复制代码
; F7 z' e* L5 G6 g1 Q
; d% |) X9 Z) C8 W, q7 d3 O |
|