|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& `' f' v9 Z4 A) A! r' p: P" j
# `# Z/ R. y/ p/ C+ @* {+ y如何获取选择点映射到视图空间中?源码分享+ F9 H1 f; ]# [0 x0 m+ X
4 l+ ?9 W/ t6 G8 T" M- //------------------------------------------------------------------------------
( k' j# y- C) r; i: M" B - // Select Screen Position and map to Modeling View Plane
. H3 d4 o2 p* P2 C& x$ B$ H - //------------------------------------------------------------------------------
& l8 ?6 [( k. h" A2 L - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
" }4 X1 O, V# s& Q( ~3 R - {
7 Z9 ~, E. Q3 i8 {8 c6 k - NXOpen::View* myView = NULL;! E8 H" @1 n( y7 d, E' G
- NXOpen::Point3d myCursor(0, 0, 0);
+ d4 W! s' ?7 I" b3 f
/ E' u& K2 ^- L; C- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
1 B4 Y- z% H; i9 i - if (myResponse == NXOpen::Selection::DialogResponsePick)" W. q" x$ j) s1 H( B, i6 _; S7 v/ [
- {% v5 N/ Y: ]+ g& P
- // obtain the current default annotation plane where PMIs are placed on
' E" |4 j* g) g1 d. u1 Y H% |3 n - NXOpen::Xform *xform1;" [4 ?1 Z! P- z, Y
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);+ W, R# C# I, K" k
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();7 k3 w9 m( a" g7 J* a
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();- E# m6 v3 P( P% i, h/ m6 H6 D2 E, }
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
3 D( g6 k9 h- M/ O - 7 F! i3 U8 r" A' q% a3 W0 f
- // create the ray 'into the screen' at the selected cursor position) }( N# u4 S: i3 ]4 w" N6 L. y/ r
- NXOpen::Matrix3x3 vmx = myView->Matrix();' e6 e5 _/ K% p# [/ U8 ]
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
! o# a) y; ~. v# L6 w |) u* f! _ - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
0 x9 @! n, S+ u8 s. L c$ |+ o - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
4 f) P( a* n! H$ W- u# T - lineRay->SetName("Ray");
5 A* u6 W7 I( V; T: |4 B9 ] |& K - - v/ F! N. [3 ^$ Y4 m
- // create the plane from the view to intersect with the ray T! J: }- u, J$ \' v
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
5 D6 z" s9 Q" ]; g/ H - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# {2 H2 y2 _ K7 U
- planeView->SetName("ViewPlane");! t' U# l. k9 b. w* J* U9 G
0 ?8 D, L w0 a8 F- // now create the intersection point5 q* g; _5 b8 S7 {
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling); u \6 _+ }8 y! i7 j2 C5 b
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
. ]1 U- w7 m! e* q5 n" }0 |2 K - pntInterSect->SeTColor(10);" j @/ A5 i( n& r5 ]/ j
- pntInterSect->SetName("Intersection");
' C1 ?, w6 @; a: m2 U
9 V5 n2 N4 t K4 `& a2 b( y" U2 e- pos = pntInterSect->Coordinates();
8 |1 q' y$ t/ b, g6 ]) U7 t - print("\nPMI Position:", pos);* X/ X5 z, D- a8 W2 C' a
- ! L& X0 a* j- G" d
- // clean up - comment to see intermediate objects" K2 a9 r: e3 E) x0 A0 X
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
6 N0 Q; Y2 D. ^ N - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
4 W) V# x2 ^5 _ z - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);* ]! \5 f& K0 N1 \! S$ `
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);) A4 o B, q8 G( }9 _* Y
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);6 Q) E. @/ W8 g/ ?! V5 `, n/ T4 y
- m_session->DeleteUndoMark(markDel, NULL);" A& s' ~+ J9 y) z( D( x2 s# o
- 3 c4 m+ ~6 f) O$ b. C' I' S9 y
- return true;" r5 O6 q0 N6 i! |" Z' T
- } ~- l' r- M7 n
; y2 r0 x4 B4 c2 u& n6 Z' K- return false;
6 ^" z/ _3 Z8 K- _) L. d0 A. n( g - }
复制代码
8 L4 X3 @! f5 a& ^6 f( _
' a! b- Y- G* Z, O! ? n0 D |
|