|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' P0 J; U7 s9 l. j% z" ~
1 C' ^" `: t6 v9 \- {: c如何获取选择点映射到视图空间中?源码分享
1 a: s9 Z+ s U! I7 Q, E6 ~! i P( J8 f" e
- //------------------------------------------------------------------------------
$ f6 r3 j+ E7 s( o9 n2 g9 s - // Select Screen Position and map to Modeling View Plane- {; u8 c) K6 t6 j
- //------------------------------------------------------------------------------
: @8 a. s3 H, G9 u$ y8 D( T - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
" }: O2 c( G! {+ ?$ F* E! B$ q - {
, [# o0 T; V' e, T B3 G - NXOpen::View* myView = NULL;
6 }; O; r# o% y - NXOpen::Point3d myCursor(0, 0, 0);/ `+ T) i! v/ E4 v' |
- ! f) R! z3 E* F7 S$ L Q
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);5 Q9 |6 f2 T; M9 h4 s
- if (myResponse == NXOpen::Selection::DialogResponsePick)
; b' f7 ?7 I/ r3 q3 a, v - {: B6 A* w5 t. Z: D. S6 Z) c
- // obtain the current default annotation plane where PMIs are placed on
2 S3 k5 A0 `& [# P H$ @ j - NXOpen::Xform *xform1; Y5 G. k ~& \
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);$ t$ z" ~% \* I7 ]% U8 o
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();. J% V- E ]/ _( s M
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();; z7 E9 F% k- m* ^
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);) k5 M: T: M3 O! v- ^" x
- ( l7 `+ m2 `4 b
- // create the ray 'into the screen' at the selected cursor position
6 [2 H6 ~, M. d6 ^* J; O$ A4 Y - NXOpen::Matrix3x3 vmx = myView->Matrix();# d. M/ o, Z' c1 n
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);: B' i0 O; m, n5 x2 i1 ^- _& x
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);1 ^, W0 a( V" N( P2 r8 L8 b
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ h4 v1 u" ^1 h% S% y+ j
- lineRay->SetName("Ray");9 N+ Y( q' I+ ^7 }
- l2 V. u7 T9 `2 J8 ^. x$ D( u; `+ {
- // create the plane from the view to intersect with the ray
7 K# q& O \: j6 X - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
9 D3 K# P' j$ L: j! R. U& g - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 b% {" Y6 i! { s9 k
- planeView->SetName("ViewPlane");
+ W9 ~9 p7 g7 L/ a
4 D5 q: Q7 S$ ?7 p8 f' d- // now create the intersection point8 C" L, ^5 p% x- V) K% V D
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
2 V0 a, T) d5 i5 J, ~. i2 { - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
' ]2 Q, E: [1 t3 B. { - pntInterSect->SeTColor(10);
9 g! y$ Z: I& `6 e - pntInterSect->SetName("Intersection");# t6 w7 X9 b' x! N6 d; j% F( k1 {
6 L" r" \# g f& k9 l( S0 f; M. T- pos = pntInterSect->Coordinates();! N! a; E3 y* y- c9 h( w
- print("\nPMI Position:", pos);1 t! Q- s0 x/ m, w* w3 o
- * U U# K& H' n, q3 @* R" O
- // clean up - comment to see intermediate objects. z% K0 z' L, F, ?
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
# W# ]" b3 }& B3 i7 r1 Z8 a% Z - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);4 v! l7 |. S0 v) J
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);( X7 Z! a: c$ j1 ]
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);% n2 e) o1 @/ V; b' d; D
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
* O: l/ ?5 n" m3 m. S3 m - m_session->DeleteUndoMark(markDel, NULL);
3 Z$ G, L/ O% k. ^7 Z
& A) }0 E4 N! E/ r' O, _/ k* U- return true;6 ? h1 r/ S/ E) [9 c6 S) p# r
- }
4 F6 G7 s/ T3 i1 K
% V9 b/ r# K" R. J' J- return false;; {2 {. v& ^& Y$ |6 r
- }
复制代码
8 e" Z/ ~6 a2 X9 Z; g$ i
& G2 s' T1 Y% y, N8 W( y |
|