|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% U" `9 n s# U; h% x8 g' l
3 t: N0 C0 l- b) C
如何获取选择点映射到视图空间中?源码分享
: |/ |# A# e' F d( Z# T2 b0 }, H& i* I, h* f5 j
- //------------------------------------------------------------------------------
% x; z+ Q2 n( [8 P7 o! b% v - // Select Screen Position and map to Modeling View Plane
( }4 }3 [+ a& f z& a1 ~ - //------------------------------------------------------------------------------
% S' y0 A5 F( @. |( { - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
7 A/ y1 G: G$ i; r, r3 [9 Z - {5 ]8 E. F% {- o2 q3 A) o: N2 P
- NXOpen::View* myView = NULL;
: R* q, `$ @. B( e! f3 A" h - NXOpen::Point3d myCursor(0, 0, 0);
( A, ?4 c! J, Q - ) R u: n% k/ K) {& E( w( A+ F
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);* b& X, T4 t, f4 `) m
- if (myResponse == NXOpen::Selection::DialogResponsePick)8 j U* N! j! f& H9 C" ?2 G
- {
9 \1 z4 N) Y1 H$ U: \7 X9 o! a3 ? - // obtain the current default annotation plane where PMIs are placed on
0 U1 ?* I+ t9 q$ q3 @; V8 Z8 j - NXOpen::Xform *xform1;
$ n8 U) Y. l; ^2 { - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);8 g& u' l, z2 Z+ I) [( F
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation(); n5 C# z1 ]9 U6 v& p5 B: w" P
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
4 R: @& ?* I5 I$ g - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);' F# L$ S! R k. \
% @ T: p/ z. G. o- i4 ^ Y- // create the ray 'into the screen' at the selected cursor position; m6 H9 p8 ^! ~3 q- c
- NXOpen::Matrix3x3 vmx = myView->Matrix();& v, T' K6 H" G. }" o# z
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);1 ?1 z& n8 a2 ^; d8 V I0 j! f) a3 n
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
# d- g$ ~: V, {! C6 q1 T( ^5 ] - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) N f3 U& E0 y4 \& H
- lineRay->SetName("Ray");
9 p- [. c! g* G, s/ P% F: p
( W, D* t6 Z# h6 `- // create the plane from the view to intersect with the ray
! p+ F3 e5 P b3 r" n3 x6 E4 s - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
! B' S0 i; }- |3 S/ } - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);! q5 M( C1 D3 z2 |- l o
- planeView->SetName("ViewPlane");$ g: f6 U5 |) ?7 V
- ( @0 q/ r$ f6 a# b; N4 X4 l
- // now create the intersection point' Y2 v+ j. g# ]8 M5 M4 s; T8 \* [! U
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
. w8 F+ s$ P3 ]; {( Z9 F* A9 d/ | - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; L( I7 M6 P. H8 z6 ~6 }& N" \+ Z
- pntInterSect->SeTColor(10);# l: d/ Y5 t4 `2 `, u1 `" w
- pntInterSect->SetName("Intersection");
5 W' a" b6 J# |
! k. u) b: N- O6 B- pos = pntInterSect->Coordinates();
8 G3 P. n' l& ~# ~. @ - print("\nPMI Position:", pos);
9 @5 I* u4 [: ^# O
* R2 J2 \4 l/ p+ _" i$ M0 Q5 O$ P4 |- // clean up - comment to see intermediate objects
/ ^3 p1 ]1 t- L. `/ K/ s - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
( Y; H4 M' @4 \- k1 S, y - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
% W [" L/ Q" @! _8 g - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);# g( G# z% P6 [
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);$ ?- z# P4 N3 r; m. Y# f* s
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);2 ]$ g* o; ~/ @; A% k0 |
- m_session->DeleteUndoMark(markDel, NULL);) ]5 L0 q0 H( E1 U. k' ?
- 9 P0 Z9 f* q( F
- return true;. Y8 e' U! i; t0 {- N4 G$ F" J a
- }
8 O" e5 r8 A9 s- a/ n$ U+ |
1 M5 I6 e0 `. b( b: T9 [1 L- return false;
7 z: M8 S$ n* Z7 G: ~4 R - }
复制代码
. [3 O2 L3 f+ U' O# c( k" Z1 E6 v9 w' n7 C5 R
|
|