|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& n6 c; H, O, Y- M
6 I' j7 L+ g) h& I8 v6 c1 t如何获取选择点映射到视图空间中?源码分享
8 J* y; I0 e8 s. t
8 e9 H4 d, j! F3 a- //------------------------------------------------------------------------------
) m4 A$ f6 Y7 k9 O - // Select Screen Position and map to Modeling View Plane
0 O3 b5 n$ ^1 p2 z$ X: Z. c - //------------------------------------------------------------------------------1 ^+ J& c P) n) ~
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
. ?" W0 h2 ~5 A - {
1 ~5 {, A# U+ C - NXOpen::View* myView = NULL;% g& z) S+ t; \9 F* o" E6 T" D0 {2 h
- NXOpen::Point3d myCursor(0, 0, 0);; l! g; B! f! _6 r
- 5 x( v; m, k/ D3 X# W. U0 S
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);+ A* `( j' w" I, D
- if (myResponse == NXOpen::Selection::DialogResponsePick)2 L1 C: J. b; ^* x
- {
0 |! Z0 A# s% P! L - // obtain the current default annotation plane where PMIs are placed on
" g) [# {( ^0 @+ T( k& Z. V - NXOpen::Xform *xform1;
5 \& W. l8 W' ~. | X' k - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);2 ^5 I: E6 A4 W: \; S
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
7 t0 j& f6 o; G# l1 `* w: s O* O6 c - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
7 u, @8 H$ W# `1 W8 `# ~ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
3 O* p( z0 N2 V2 b4 [+ p, [1 h0 B# J - / ~. N0 k( N( v/ ]
- // create the ray 'into the screen' at the selected cursor position
3 m1 Q. P' \$ V# ? - NXOpen::Matrix3x3 vmx = myView->Matrix();( K2 N: [) Y. ?
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" e# g' W: s5 q9 C
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);8 |1 @- a! \ g" x& N- a
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
{5 S9 _( m% W6 w2 ^ - lineRay->SetName("Ray");; C. ^, i: X0 I! [+ A5 P
- * K5 f1 D9 M5 B
- // create the plane from the view to intersect with the ray
5 B' H6 m) I" o! j; J - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);* D) o K6 `8 D6 R0 z/ B
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 l O' C, g0 P% _
- planeView->SetName("ViewPlane");
- o0 T6 m$ y% k" X/ X2 E
5 R5 ?* r/ r5 ~- // now create the intersection point
7 d: b+ T3 E; A+ K - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
5 A! Z- M0 f6 T - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 z. n1 i C1 \4 t# P
- pntInterSect->SeTColor(10);
2 S0 |' K( E4 U, ~3 ]5 D9 Z$ e - pntInterSect->SetName("Intersection");
1 i& h4 G' x+ r
' v! M2 u$ |6 D9 c3 p- pos = pntInterSect->Coordinates();/ @ c5 U" W7 k0 r7 N1 A: \
- print("\nPMI Position:", pos);0 f* S5 A+ u4 f
. N% q; Z8 {( n5 u8 V- // clean up - comment to see intermediate objects5 P& f/ ^. H6 a) F# f2 b. F
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");- F5 v8 F" F' p
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
/ Y [( ~6 m, @2 {: e0 u7 B4 h3 C - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& r9 n# Z; i1 c: \8 A* X
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
! }& T4 |1 [- j9 ~& e5 X7 B - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);5 O( e5 t( @& q) J# o* a
- m_session->DeleteUndoMark(markDel, NULL);
: D0 ]2 R$ ?+ e0 A
' Y) P8 G! e3 S- return true;' Z0 r. Q/ t/ R. U# g& d
- }
9 k* E# N: L! C' E$ o; _ - + ~% y! F8 m# H8 U/ N1 U" S
- return false; H2 ?* U; s, d
- }
复制代码
# ?; U! ~1 @' J! ~0 N: n) ^; @' Q! M; x+ B4 X
|
|