|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( ^$ n+ H6 m& r d. P" c* ?6 A- g7 b. F1 v
如何获取选择点映射到视图空间中?源码分享1 y# @+ l% a8 X, n, q1 k( v" q4 t
! L) r8 H/ n$ E8 G' x- //------------------------------------------------------------------------------% w0 s& G* p! z) ^/ ~
- // Select Screen Position and map to Modeling View Plane
, p. h2 u2 v0 b/ h0 o - //------------------------------------------------------------------------------
5 w* \ a9 ]+ a4 p f4 j - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
7 s8 R' h5 h+ p S5 B - {0 n7 u1 a8 D" O: v8 ?( {
- NXOpen::View* myView = NULL;
# {/ r) t9 ?6 K; b/ O - NXOpen::Point3d myCursor(0, 0, 0);
3 i$ H( N6 j0 t: n - ; X( B/ U$ N" r' }+ T% m! `8 \
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
3 m7 O6 d/ ]% J3 a8 ` - if (myResponse == NXOpen::Selection::DialogResponsePick)
# G6 K5 ~+ w; S - {
7 K) d7 I% r$ J1 a, ^ - // obtain the current default annotation plane where PMIs are placed on Z! s! Y) _7 e0 e1 B
- NXOpen::Xform *xform1;% n2 t2 x6 n0 i0 q( t
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);, R' z2 X- ^! @- A' {/ [
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
. V* L( S1 _1 n0 H) e3 U+ L# M+ X - NXOpen::Point3d ptDefaultPlane = xform1->Origin();; N& Y! G `1 p2 x8 P
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);0 r% {1 E7 Q: O: x
- : o8 b% |6 h' J; E# A) Y _( [% [2 `
- // create the ray 'into the screen' at the selected cursor position6 o5 H6 k" {9 o% O4 U
- NXOpen::Matrix3x3 vmx = myView->Matrix();3 C0 F# v2 _, k1 ^( J! x
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);0 n5 ?9 p8 @9 P v4 U8 \
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);7 d( i# ^; r2 A9 a5 |4 l
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
; n+ F, T2 H2 y0 ^. s5 g/ y - lineRay->SetName("Ray"); g U/ h# u, z$ X9 D5 R1 Q+ }
0 R/ F; _6 x/ ~6 A) V) F: L- // create the plane from the view to intersect with the ray$ F8 |+ B% j, U) J' `" J) S
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
5 ?! |# z, ^+ n! v: j - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# v/ e% y' Y* w- O) O$ b
- planeView->SetName("ViewPlane");
e4 G$ d# w& m* l: H2 X+ |+ n - 9 x" X8 L ^( P, _: g% q i4 S1 _
- // now create the intersection point9 q- \ b" O* P1 R# l c# D
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
/ ~8 z: l& O6 t: k" c- ~2 j - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ N, }; |) O2 _
- pntInterSect->SeTColor(10);9 G: x- ?5 F. q: u5 i2 z3 Z* b
- pntInterSect->SetName("Intersection");2 A, [7 `# C. x1 L
0 w/ h* h& a- i6 U; t" g- pos = pntInterSect->Coordinates();" G0 T, m# ?+ d" K. L. i
- print("\nPMI Position:", pos);/ C0 h6 {& ~% m0 i9 R$ ~. E* n+ v5 o
- u) g/ ?( `8 r: p- @& p, K
- // clean up - comment to see intermediate objects8 E. g0 @3 v7 e* h1 v* t4 u
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
% Z5 V- X& b! Y+ W- F - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);& u4 R E7 }' Q7 Q
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
; g/ b) H1 V& C' F - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
: r- {1 w+ g' a# a |% K - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
& H K3 H/ k9 w y7 d% a - m_session->DeleteUndoMark(markDel, NULL);# }+ Q) V% d4 s& ~! t/ ^% h5 m
- 1 L! V9 c' \* Z, b9 p0 R
- return true;6 Q& Y1 D" ~. H! R2 V% r
- }" u. i$ _2 b; O
- : }; y" @9 V% {# Y3 Q& c; z
- return false;
. |8 B% j8 d1 A/ A% ^ - }
复制代码 0 R# Z3 x" [ |! O' X/ Q$ C+ i
' f% N$ m5 i9 ? |
|