|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: j0 y; s# j6 @- L1 o
/ H5 ^4 S0 O. }) \; F如何获取选择点映射到视图空间中?源码分享
& S! q1 k8 e% J5 C E& S z
$ [( w% |7 D" O: R8 ?- //------------------------------------------------------------------------------9 W& ^( O$ s1 v+ Q
- // Select Screen Position and map to Modeling View Plane: d" s1 \: ~: |0 k: y+ E3 _
- //------------------------------------------------------------------------------
. H) J; \ |$ ]$ j# c+ f - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
* d$ D1 r/ Z. L: _# \ - {
! ~. z1 f! j, s% W - NXOpen::View* myView = NULL;
3 p3 G( R2 d. T! A- q9 R - NXOpen::Point3d myCursor(0, 0, 0);, k$ K2 V' j$ G! f/ s1 v8 N
- 7 V5 a, c* j9 v/ {0 A. [) i4 |
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);$ K$ E- c0 C0 _8 Z. |$ E5 z
- if (myResponse == NXOpen::Selection::DialogResponsePick)0 G8 ]* v; ^: I1 z; {' `) o
- {& ~5 B6 t! b; u6 S7 z
- // obtain the current default annotation plane where PMIs are placed on7 G+ z) c: d/ r: d, q, }
- NXOpen::Xform *xform1;# `! X& X3 _% X) B: E1 K
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
4 T1 J( o6 s' [9 S - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();, v d0 p7 c+ p# X f
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
# x, B) P. ~4 n: s; B4 s$ S' A3 ~ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);( B. h: v% a ^, b2 i" w
% S# N6 }! u, v) S- // create the ray 'into the screen' at the selected cursor position
. B! ~. C$ I# l. [ - NXOpen::Matrix3x3 vmx = myView->Matrix();# x# L. u. T% I; P! F
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);! z% W1 a- S; @4 u
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
, b. Q3 W- l" C8 P - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);7 M; E5 I. E2 h8 I9 R. ]" A
- lineRay->SetName("Ray");
, x. d% t% W5 c+ `3 L' m, B
0 j: c# u/ G+ Q2 B- // create the plane from the view to intersect with the ray# F( O* K* a- t0 }5 b% H
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);0 ^$ I2 |5 X: q. o" T
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);! g' r+ w7 v. D3 E
- planeView->SetName("ViewPlane");
& H+ W# }7 { b; l
5 e2 t& o P/ x5 d4 T% {- // now create the intersection point
3 U. s7 j9 V: Q' v - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);0 c0 y: r% z& z0 m6 }$ M/ U: a
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);0 ?. }) s+ L: k( O: u& L9 }
- pntInterSect->SeTColor(10);
$ u. z- X" O8 }( }8 H8 [% c - pntInterSect->SetName("Intersection");1 B5 Z! u5 N% S
5 m; m" n; }9 w5 l% N# _& F- pos = pntInterSect->Coordinates();& M7 |0 l2 M7 i7 q% Y3 y
- print("\nPMI Position:", pos);
$ a) F& V: F5 Y$ T
& q z! q( Z9 g* m/ Y* Q- // clean up - comment to see intermediate objects
3 m+ g( {, y* p( A0 ^' t - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
- c- r) O, q: n: } - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);4 {( l" k; a+ z1 _
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);# w: W2 X+ R& D; e1 c
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
' E" h0 i, w6 W5 g2 c - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
* N( J' L3 n2 z: {5 Q* t% T - m_session->DeleteUndoMark(markDel, NULL);
% V$ {% u0 X- }, w7 a - " D5 C+ k$ e8 M* A
- return true;
5 M( N2 X8 ^! l+ f! t" F# v) p4 X - }4 O" _3 I8 r8 D. l) `: C0 |
7 n4 I; w3 o. g; v5 p8 z. S) L- return false;
/ \$ }( S2 c& O8 c; ` - }
复制代码 9 S. D& F& ^) C+ ~- D
2 Y( _3 H& u. U5 Z& {# K
|
|