|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 O0 T; }. v( ~8 A! ]' T/ `& D5 n
& D/ |0 o5 C! H, L6 U$ A
如何获取选择点映射到视图空间中?源码分享4 O* A+ l+ @& q' m* y+ J
3 S4 c) D" M0 p6 J7 b( p. J7 `( N- //------------------------------------------------------------------------------
4 f- H3 s1 z. ~9 l) m/ z - // Select Screen Position and map to Modeling View Plane
0 r- G% g, c5 j: C: M- H, ] - //------------------------------------------------------------------------------# A1 {" Q' r! g0 M
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)& g" L/ D# f% R: a0 p
- {
- _- K2 t. O/ ?- s! h - NXOpen::View* myView = NULL;
) e" a2 S j, [1 ?3 } - NXOpen::Point3d myCursor(0, 0, 0);$ u. S1 k" n" y8 {5 F6 q
- ; a1 P) O9 w# |* i2 L
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);$ h. F! h' y; S6 b; R3 r: u; `7 E5 u
- if (myResponse == NXOpen::Selection::DialogResponsePick)
- i# _' ~: |- G/ \ - {& i- F0 h6 Y9 C5 X7 ]7 r
- // obtain the current default annotation plane where PMIs are placed on
1 T3 p6 u# J; L7 `6 b - NXOpen::Xform *xform1;& G7 }2 x, e4 r; p
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);( z8 B8 Z0 t S! F
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();8 j; p( t+ T- b* ?+ p! S
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();/ l& D* s8 W: @- M) U6 k
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);2 l8 i4 ~( N* S5 n
- ! X" T% N3 U" o! R( W
- // create the ray 'into the screen' at the selected cursor position
# u" q7 E: I1 k- e - NXOpen::Matrix3x3 vmx = myView->Matrix();
# N/ J6 m' b# h4 _ n - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
# n7 U2 g) x( R y( B' [4 o$ v - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);! S. L2 m. a, ~- p1 e, h# h; X
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) q/ t% x) l% F. Z. B& ]5 U
- lineRay->SetName("Ray");
9 Q5 N6 Z/ z; D
" y- Q$ S# E% T: r) L. O- // create the plane from the view to intersect with the ray
4 `* p, X2 k8 l - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);* R, O K ` a0 s
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
% U' [- F) F$ c9 Y - planeView->SetName("ViewPlane");* }% N" M* W+ S5 L, r# ?
: t6 T: T5 s) n/ p" N& [+ _- // now create the intersection point8 d! ]% o4 {* ~% |1 C8 H4 k, M# R/ V: G
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
( y2 U6 F7 @9 C, \* e - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
! [7 a7 r' L! [+ l+ O6 g( @& G - pntInterSect->SeTColor(10);' `% V0 y) K3 X
- pntInterSect->SetName("Intersection"); w- S& E" \) g9 I( S& w
- 7 c% V5 _ X( }! R& S
- pos = pntInterSect->Coordinates();0 ^0 p% t$ J3 \4 B P8 R+ G. R3 e1 H4 B
- print("\nPMI Position:", pos); i6 }6 v7 E4 r [$ S% I
- * b/ ~5 ?7 @! r; r$ @# B& l5 ?
- // clean up - comment to see intermediate objects5 v M- y, |0 l5 b
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" B X- O6 k3 Q& S
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
. q% h5 s- h/ J - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView); {; o2 n1 ^. h" b: n! x# [
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);& T/ s" E& {: T. P- n$ @/ L3 p
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);6 M$ u( x6 ^) P* {! H: k
- m_session->DeleteUndoMark(markDel, NULL);3 P+ t) b+ k0 _% Y
- ! g( n' Y8 ^% w* p; g
- return true;
# @+ G+ G9 ?6 Z; A; @. y - }
! D0 k$ q/ \ O$ r
4 c) v* i+ g; U' b2 O/ c( k7 C- return false;4 j* W7 d: n5 P% b! L) m2 x" W( U# D
- }
复制代码
+ K [8 n/ k' n0 l7 b% _* l( P, M- P8 z1 n
|
|