|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 S+ z3 r+ B' n& F% q
}5 G2 P& Q0 B- G
如何获取选择点映射到视图空间中?源码分享 ]+ x/ s0 a3 h
+ n# F7 h1 @: b: d8 O
- //------------------------------------------------------------------------------
( A* f) d6 A1 m, k - // Select Screen Position and map to Modeling View Plane2 C' M$ s: Q- s
- //------------------------------------------------------------------------------
! j; s0 @+ T, P2 V( z, j7 N8 S& a - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos): B5 _, J2 p6 J- j5 P
- {/ G! e3 _0 F' Z9 j
- NXOpen::View* myView = NULL;
( a( K; y- \! N; N$ t: h, K5 q - NXOpen::Point3d myCursor(0, 0, 0);
~7 @* Y: g( Z, h - V; G. c8 }. o4 C: `
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);; J/ i) c% w; x" R6 i. X% }
- if (myResponse == NXOpen::Selection::DialogResponsePick)4 ]" l/ U0 C/ g2 F" h( d- k
- {
2 h8 |# R+ I. k& b% C, Y - // obtain the current default annotation plane where PMIs are placed on& m6 i& `8 r | ?$ J0 Z
- NXOpen::Xform *xform1;
6 J) i: e# B. X( E - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
) R! S; k7 O2 _" F5 _5 j( o* z8 x- N - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();/ @6 S6 V+ _! v) T6 T7 v
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();# E0 Q/ H# A' s# V( T j
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
3 @" |% f2 J' W( d- A% r( v - : |4 ]9 g% s( o0 N- _" n" s
- // create the ray 'into the screen' at the selected cursor position& U* z7 y8 S, u; K$ _
- NXOpen::Matrix3x3 vmx = myView->Matrix();
2 e, G7 h+ _2 U' x( N4 F) C - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
7 ?, j! d: | q% j$ } - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
3 ?- U" r" i# ~1 H, G# O - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) }# T/ T8 a+ q1 C; P8 w
- lineRay->SetName("Ray");
& O$ Q9 I( b& h- ?
% g: Q: J8 o0 N j0 K. I! a2 Z+ ~2 ~- // create the plane from the view to intersect with the ray8 x; v+ ^! G) R+ r
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);& k' ~( I+ y% C; c. l3 T$ @$ O2 Z
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
" j" R9 y/ d( c e6 }! s - planeView->SetName("ViewPlane");
|3 y0 {. i0 N' U p
5 K5 U& P- t: e" E# e& F- // now create the intersection point# I% H$ g. J" z
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
4 s: N; F& g7 e2 H - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
/ j) k( ~. A* k8 u7 R, C - pntInterSect->SeTColor(10);
) q) ^9 Z4 _3 R1 h! K3 h - pntInterSect->SetName("Intersection");
8 a: E9 `5 r8 o$ s1 _/ A5 d1 X - 7 e, S: r% O3 E
- pos = pntInterSect->Coordinates();
; F* G3 w. D5 q3 o# J' _/ O - print("\nPMI Position:", pos);6 v5 ^( C3 C' [
- , U3 P( f- V. p% T( j
- // clean up - comment to see intermediate objects6 @, Q1 v" e, N% t( q' U2 s! V8 R/ a
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
, U$ \9 y0 o; J' E - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
N5 R/ g, U% E8 u0 D9 K - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
# ]0 r. n( m& S3 T+ Z* x - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
; R* D& ?6 k7 W! W! u" u c2 l5 c - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
' d2 N+ X) B& A; b9 H1 Y4 z9 v9 n - m_session->DeleteUndoMark(markDel, NULL); d/ F5 e- z& u$ Y% y9 J
- - i# @/ Y$ o% E6 C. F3 V. P, N
- return true;% t& B7 e) y4 c- l; u
- }
; D% M( M8 `6 |8 ~8 V6 y8 { - + P: [/ j9 ^8 F' u+ p# d; k: w
- return false;- H9 j, g* [. Q+ v+ @
- }
复制代码 * e) r9 y0 D* b1 Y, g
. |2 b5 N5 U2 C( x# @- P7 b |
|