|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 G$ Q3 z3 b, S+ v% C
; _8 z: Q0 T& S- g如何获取选择点映射到视图空间中?源码分享
5 }7 ^$ z6 n# h. F, Z7 s. Q+ K2 L. g$ i# m- c* a/ Z
- //------------------------------------------------------------------------------
8 i5 |* p3 Z( C4 D - // Select Screen Position and map to Modeling View Plane# C6 D4 J2 k4 ~1 k
- //------------------------------------------------------------------------------
2 V# ~4 l4 O! q - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
: Y9 o# t3 N% C! X1 } - {1 `9 p" u ]. M- p
- NXOpen::View* myView = NULL;4 a( ?" j. @2 ]7 C' H; k: d8 C
- NXOpen::Point3d myCursor(0, 0, 0);2 K: `3 P4 p! m7 L9 X( Y: R
/ w/ @; _5 m$ o6 w- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
, o6 Q0 o' z( v" B - if (myResponse == NXOpen::Selection::DialogResponsePick)
6 `) e, T9 i7 R& }2 Y9 H - {
* V/ g% F+ @' y - // obtain the current default annotation plane where PMIs are placed on
" ^& |! Q$ z4 ~2 u - NXOpen::Xform *xform1;$ a) q. w* O* N% S
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);. n _5 J+ P& d0 E. }
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();2 D, h( U# j& b, N! H, R8 R F3 h' \
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();3 H: U: z" K' I6 |# s& O! c4 K+ `
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
2 l+ y4 ~" S6 H1 Q# [ - ' p4 p9 c" A" L3 m
- // create the ray 'into the screen' at the selected cursor position
- y& J2 q) l3 A' O2 p0 P - NXOpen::Matrix3x3 vmx = myView->Matrix();
/ V6 w; @' ]8 [% [! H9 @3 } - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);/ V- ?" I4 Q$ I6 \/ O) x
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);0 T* s. |- q& O: a% ]; z/ p3 w* h+ I
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
3 [: ]/ w4 a0 I$ R. d* } - lineRay->SetName("Ray");
5 a7 v" R7 s' ~" k! g+ ~- |
9 O8 r% `; d* Z! @1 {2 e- // create the plane from the view to intersect with the ray, ?+ Y& G( L( ]
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);/ s9 E0 d& C, f H
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
) W" s" C+ Y: y! `0 i - planeView->SetName("ViewPlane");
. R& I) ~' c. ?1 O - ! o! }( K: M% n) F/ k8 X
- // now create the intersection point8 }! ?5 m* ?6 R8 F
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
3 ^; B2 J# T8 ~. T$ @, W" w - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, r. [3 X2 l' E5 V
- pntInterSect->SeTColor(10);
* T" Q0 B9 P, W2 _* x! Q) k3 F. k/ k0 W - pntInterSect->SetName("Intersection");- N$ S9 q) |$ S
; ~" J$ P. M/ q- h( L, S. Z- pos = pntInterSect->Coordinates();
- [* u( L" J$ x( k3 ]% U+ G - print("\nPMI Position:", pos); B5 j8 ?: |) w
0 P4 I7 g" H* A3 `7 X4 b+ e- // clean up - comment to see intermediate objects
4 Q7 j$ S8 t, a8 O' \1 U, D7 B7 U - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
/ w4 X* R4 c& [! ?& W" M) C, P - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
; `, r" A$ L' u7 z" }3 W - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);, c7 L0 ~! _+ h8 `2 r. w8 i) t
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
, U' s3 `, @: ?! X - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
; l; p) n" H. t; M9 `- D - m_session->DeleteUndoMark(markDel, NULL);
: w3 r4 ~2 a7 c; { - 2 H: u w% H/ [2 s0 F" \( |
- return true;' l4 r: R Q; j' O8 N1 Q
- }
. b7 }2 @& H# _. x: v/ K
6 B# M" q G1 b3 Q- return false;" N/ ~/ U8 R" t; H2 i2 K+ `
- }
复制代码
! @1 Z) {* s3 m9 t: J5 _! O
: a" E. @, L- K; I |
|