|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 U! E2 o9 J# M- E) a9 M {
( E) t. E+ B4 \( S7 |8 n如何获取选择点映射到视图空间中?源码分享
1 U$ k8 t. l) a* o T9 m: ?$ \+ w* _% J# h
- //------------------------------------------------------------------------------
1 A* R% S' c7 H! a' v l" d# [ - // Select Screen Position and map to Modeling View Plane3 {) M: w2 W6 q6 @( J8 z7 k
- //------------------------------------------------------------------------------
$ A7 r& J. ~. j1 B - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
, j: S A0 [- I- K1 D - {: r8 h' Y+ t& o; j/ T( a6 y
- NXOpen::View* myView = NULL;
1 p* c" t( w6 R. L& e5 P - NXOpen::Point3d myCursor(0, 0, 0);2 k C! A! M# w( P% W. Q A! @
% E$ h8 r& Q1 V% f$ C" [6 J, j$ x- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);' T) m, I6 E# v
- if (myResponse == NXOpen::Selection::DialogResponsePick)8 O; S. g4 N; v
- {$ F% {( Q( d) M, `
- // obtain the current default annotation plane where PMIs are placed on/ G" d @+ b7 y- A# O# B$ B: j
- NXOpen::Xform *xform1;3 p0 G% [$ I4 }" B& j" h9 O) n
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
# r9 T2 V$ ~' \* G/ `! [! i+ F - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
) G! G2 z) W: b1 X. T- F - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
$ O. f3 l9 P8 ?7 W9 w# a - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);% C8 b6 W# r4 [
; v* p" M9 L; U& K. _; V5 d% V- // create the ray 'into the screen' at the selected cursor position
, L' X8 }3 J% a$ f6 s' R - NXOpen::Matrix3x3 vmx = myView->Matrix();
$ ^2 f4 W. i I/ r4 `% U7 J( m - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
5 S* [) z( r* r7 R5 b - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);0 E& u# n5 O! k4 R, M8 ]% C
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);0 }- `" Z: D$ g3 u2 @; E) F
- lineRay->SetName("Ray");
- s2 k2 t* u$ D) R6 l. k7 h! J0 p - 4 r% d3 `% p) b" i/ `
- // create the plane from the view to intersect with the ray
# t! B9 A. r7 j, n/ ]! d - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
+ s) b4 g; r5 H7 i3 l! ?4 ~0 q - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
! y4 C- ], d& L7 J& h1 P - planeView->SetName("ViewPlane");5 L( v8 r$ t7 |
- + [" z7 H; N& m4 Y
- // now create the intersection point( j' \9 C7 d6 k# U7 J" m$ Q6 [
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);5 j7 z- ?- Q9 r* ~8 X
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
+ x! f+ ^" P6 p - pntInterSect->SeTColor(10);
5 a4 f: ~+ N# |$ ]' {, ] - pntInterSect->SetName("Intersection");
# v7 {8 ]7 P2 y! b v - 6 P2 g. s- u! X7 m' \
- pos = pntInterSect->Coordinates();
3 {2 G! P) P) B( R! o# z - print("\nPMI Position:", pos);; J8 H* ?# X$ R1 D# Q
7 `. B, v, Z6 m" f+ u4 W1 N- // clean up - comment to see intermediate objects
+ e# _' ]$ R, P: n- z+ } - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");1 `% |2 O g. n( ]
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);) d8 n/ X$ F1 \
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
' g* y" b5 F: N& i) C7 Y* x( S - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
8 ^" _: z N' O* o; L1 i8 h! U - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
' {* K" I4 r4 f$ S6 H; {+ m. j - m_session->DeleteUndoMark(markDel, NULL);4 m7 _/ [/ u1 @2 W* t: Y
- * ^1 W- S1 d' C1 x0 [& p
- return true;: e1 X# h, u! D; c" | h1 Q
- }
7 b( s( p' H: {7 @' m- J& v# ~( ~ - 0 O8 J( W" V) S3 P! x
- return false;
& q! _0 _3 K/ ^+ T! E- s - }
复制代码 ) A+ L8 C3 Z& V
3 ]) {6 Y0 b& l) ~2 f4 w) C8 K5 R |
|