|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 e x/ Y1 ^. i* N- t% n
2 n6 k( y7 ]& x
如何获取选择点映射到视图空间中?源码分享
# o; B% `7 ^( U+ I+ \/ p. Q4 w: M; u/ ~% W( ~2 U3 ]6 x
- //------------------------------------------------------------------------------/ P n7 L/ d! h0 Y
- // Select Screen Position and map to Modeling View Plane4 i7 @# p$ a6 G8 W6 p( L. `: _
- //------------------------------------------------------------------------------: c7 v7 C& H' [' l
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
+ X& q% d3 U/ L0 K - {5 U% p( o5 z: Y- _- f9 W: Z! A3 `
- NXOpen::View* myView = NULL;
% P3 j5 p& q( X4 a4 v, I4 w5 ~: z# G - NXOpen::Point3d myCursor(0, 0, 0);+ g+ d1 D4 O" V% {
& M7 T; G) l" S- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);# t7 O: P+ ~9 [& D6 y) L
- if (myResponse == NXOpen::Selection::DialogResponsePick)* h) ]) i" i; W% Z8 S0 Y! L
- {
6 U' l/ E) [: A" \) m- f" B - // obtain the current default annotation plane where PMIs are placed on
8 R1 v$ K5 g8 S9 K n( ?0 g9 a - NXOpen::Xform *xform1;5 H+ ~ f1 u, x( w8 S1 i
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
! i( |! D b3 w0 c5 ` - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
) L% _8 Y9 K% i# D - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
- a0 N+ U, l5 n; @9 D9 Z9 H- y - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);3 F7 S% T+ z: U& U4 Y# o
- ) b: N5 A m2 I
- // create the ray 'into the screen' at the selected cursor position
+ ~9 l; s! W5 X# y: C" d5 G - NXOpen::Matrix3x3 vmx = myView->Matrix();
N' S& g# J% V4 O# _) { - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);+ _3 L- D2 r7 H: v
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
8 R3 U/ k! d7 W& s% J - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
# y w; f4 }- S# ]! ?* M - lineRay->SetName("Ray");
; q% q1 B; [1 R; R$ v+ U) v
) j9 t+ A* F. \1 {& y: q- [- // create the plane from the view to intersect with the ray7 S" u2 O3 h% l5 C) l
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);2 c: V2 q- N2 m) V! e' J
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
6 N' I5 t( F$ z2 U - planeView->SetName("ViewPlane");
- k( ~) P2 `$ m, C: v( ^ - # S5 I( B7 M/ ]; G; R
- // now create the intersection point
: J1 t/ \( P; m- D - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);1 K% E' m: D: H) H3 r- [
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# v3 O: r+ i9 T |( h9 R$ B, y
- pntInterSect->SeTColor(10);. l4 }4 W% T2 _: b( y8 [# x. S
- pntInterSect->SetName("Intersection");
' t# e' O( |- p6 B/ m w/ c0 `5 E; q - 7 N9 g5 V v1 W" n
- pos = pntInterSect->Coordinates();
# i0 ~0 O9 C% F0 f - print("\nPMI Position:", pos);4 b( M+ @; C' P
- : I8 Y) ]1 f) M3 n- ?& F6 G$ o
- // clean up - comment to see intermediate objects
4 X, {' f; k/ j( H - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");3 U, P& m x* Z) r' ~- c
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
' [ r, d! r e& J - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
: t, s3 o' [& T) L9 U, ^ - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);. B" W; Z3 ?- [/ L5 }! s
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);& B9 r# A3 _/ E# S$ Z {+ E
- m_session->DeleteUndoMark(markDel, NULL);
/ s& Q3 ?0 { k: [& r& p+ o
a/ z4 {% a: c& h- return true;
W+ M' |' Q0 O2 k - }$ W2 l+ n) e) q. B- U" ?& z. r
4 M& U8 c+ [# ?5 l" e& Q- return false;
9 D6 }- K% i2 e, w# P - }
复制代码
8 _3 |( G: F% Z
8 l) ^5 F( e" ~2 q( e& a |
|