|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* X, X+ ` L* w! ]$ _6 @1 i6 k) v4 n. I6 X: i Q( P
如何获取选择点映射到视图空间中?源码分享
/ O) E4 g: _1 w/ W
: h' ^3 c7 |9 M% L- //------------------------------------------------------------------------------6 M) n) e* z2 s Z' C# I
- // Select Screen Position and map to Modeling View Plane! |# j5 b) k% Y% b. V4 s. d
- //------------------------------------------------------------------------------/ T: b" b4 b) M" P0 A3 b8 g/ z
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
- ]% P( G) |7 Z) |7 } - {
2 ~9 Q- q. \9 H; j( Y - NXOpen::View* myView = NULL;
( c& O* Y# ? V - NXOpen::Point3d myCursor(0, 0, 0);% {9 J S, Q- [. [. @
1 Q/ p$ L: P. z7 a- Q/ \ s. j- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);: z( s* u( u( d5 A; q, F7 ^
- if (myResponse == NXOpen::Selection::DialogResponsePick)
0 `9 B8 c9 J! U2 Q$ @ - {, l0 @$ S t( x0 t1 I6 g$ ~: t
- // obtain the current default annotation plane where PMIs are placed on
4 Z! p' t! L& \8 M8 x) k - NXOpen::Xform *xform1;$ F) I) B8 U- K# g! t( q
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);! I3 j, }6 S; f
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
9 B9 _7 u9 \8 Z, p; S* y - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
6 E" O5 u1 l2 m( n3 }+ Q8 ]& x, Q - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);5 P3 J! Q2 @) s9 M7 j. X
- " d# R' W6 L: @6 w$ S# o- i
- // create the ray 'into the screen' at the selected cursor position; f9 P+ q- `7 ~7 w
- NXOpen::Matrix3x3 vmx = myView->Matrix();
" i( k/ d; g3 { - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);7 |3 r4 v( B7 @ c
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);1 P$ ?$ O+ H. F4 y% s0 Y
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
0 J; t* _- {: H6 P5 S - lineRay->SetName("Ray");
0 V5 H4 {' c2 [% D. [% y
; S+ R, u$ s! X4 Y9 x- // create the plane from the view to intersect with the ray; u' G7 r2 F0 m. [4 w
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);& a J0 Y# a, E# X; ]+ U
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
* k6 g3 u% m' Y: t" y1 m - planeView->SetName("ViewPlane");
1 d# P8 y! M( w1 w
! k' i: u& s1 Z: c6 J& Q/ @- // now create the intersection point0 ]( F" |0 h# y, v9 p: @' E
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
7 E( V) {6 h3 \* ]* ^4 o - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# \! I& i- E+ c% Q2 b0 ?% s& j9 z% C
- pntInterSect->SeTColor(10);# |7 A, z0 y5 W1 B
- pntInterSect->SetName("Intersection");
, C1 }* v0 D3 D# \
! N/ N V# | n/ }- pos = pntInterSect->Coordinates();
( ^. f e! Q: l - print("\nPMI Position:", pos);
0 \$ S; C+ O$ R# Z! j% T0 W# R
& k( j$ @9 B; H- // clean up - comment to see intermediate objects9 e/ r: @" r( h2 F1 L; L
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
t- s- f5 X7 D; M! @ p9 @1 ] - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);1 b, H T7 Q/ Y x0 x/ [; Q
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);# F; ^8 E0 c. P! ~3 l5 A: S4 t$ R% z* K
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
/ G- j9 V8 T+ {8 D+ K7 r - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
% ]9 B% I+ n8 B% k - m_session->DeleteUndoMark(markDel, NULL);
/ o3 n& i1 k( \" u" l
/ B2 u/ J, V# \3 Y1 \) B- return true;
) Z% u: X5 t: ^' B+ h - }# p: `* E% }$ v) b: Y
' ~- Y$ _4 a) j- return false;
1 H8 c0 l4 e y+ N - }
复制代码 / I) T6 v- m2 ^+ ^! \
) ~) h7 h2 @1 A: v |
|