|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 O3 E* W- J* F8 U7 P; v. \6 J2 Q/ z/ a6 |
如何获取选择点映射到视图空间中?源码分享( R, T# i1 [/ G! b! [& o
& D, q. R+ U. A# j2 c, m- //------------------------------------------------------------------------------
' I1 j7 }" c( c9 O1 G$ G - // Select Screen Position and map to Modeling View Plane' r \6 l: e1 C0 Y% o8 N
- //------------------------------------------------------------------------------
+ ?* r5 V; L& W( N# J$ c- R - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
0 o2 }; B, x1 _% Z" m- F - {
3 s' c" ]% [3 g) Q u0 n - NXOpen::View* myView = NULL;- S( q. ?+ f2 P
- NXOpen::Point3d myCursor(0, 0, 0);
& z; E3 J1 W R1 H+ O* t
9 u0 Q0 x( T0 y" n I6 J7 P! t- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);5 i$ v. o1 R/ {& e* W
- if (myResponse == NXOpen::Selection::DialogResponsePick)
. i( f6 d* V' V* K3 X9 _1 c - {" W& e; w6 f2 O: w; p3 q: U
- // obtain the current default annotation plane where PMIs are placed on
# i" v! H3 A9 b9 W7 ? - NXOpen::Xform *xform1;9 `0 A! f& e$ X. F, F
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
* v+ ^: U; h+ E4 z0 l- M - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();+ _9 y- @. `: w5 z0 ^7 c2 ^& u4 o- [
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();& R9 v- c0 C' f' a& k& q& F! n
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 s! |; E: z2 V+ H* I7 u
" t1 ?* ?( q9 U. |- // create the ray 'into the screen' at the selected cursor position
+ z; a5 h& Z+ d# K; Z - NXOpen::Matrix3x3 vmx = myView->Matrix();
9 S+ i" I7 C' h/ j6 D! |0 y- x - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);3 J5 G [6 ^& l! L, p. K( K
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
/ l- Y& n. \6 z4 s/ P: c - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
( `8 p4 T% V# }2 ~% U$ y: ?8 h - lineRay->SetName("Ray");
) Q0 ^- Z+ d4 i0 ?- Q3 I
o' u9 x& @" P% x- // create the plane from the view to intersect with the ray/ y, U( j" S* v ? t( N! h" o
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
1 L- c4 C( o" Q - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);- S0 r& @7 r7 o N
- planeView->SetName("ViewPlane");
; b6 m8 M) e1 L; j% ]9 X2 H0 ? - $ f; s+ C7 a8 u3 K R
- // now create the intersection point
2 O7 c5 E- q' s1 ~ - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 d& K1 o& B: W3 Q! ]+ ]5 D& w" Z
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 J" ^9 c- u2 W' T
- pntInterSect->SeTColor(10);
5 f# Q) X" `. W8 ^ - pntInterSect->SetName("Intersection");' ]; r R9 {/ l2 H
- * e1 H2 N5 O! A" j! {' I% a/ z( z
- pos = pntInterSect->Coordinates();0 J' i/ J4 N: N
- print("\nPMI Position:", pos);
7 H/ O. m9 n! y! `; I - 2 u5 l3 \( Z/ u5 G$ ~
- // clean up - comment to see intermediate objects% f+ K) Z" y- i4 E5 c( ^1 F# R$ P N
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete"); }. L% T: M- f6 k; m( _* `. C
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);& G( f$ B [* l; {5 w+ e& [) M8 k; ^ k
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
/ f! U$ N, _+ G1 J - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
9 o; M9 T% y; }8 z: _, r; B# k9 a - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
1 q( h6 n: n# b( p6 X, x- \9 b - m_session->DeleteUndoMark(markDel, NULL);% n+ I2 v; Y, p. j4 U4 K* x
- $ I2 o. i4 e& q; i9 F. h6 D
- return true; h( B) Z9 Y" C3 S/ |
- }! H* o4 g8 F1 @% a
- # t- f, H* T' d) D+ q4 g6 [
- return false;9 l8 p! S9 K6 U& O
- }
复制代码
) Y: C% _! N% _, Y$ K
1 A$ S8 l( ?) i+ ~- b5 [ |
|