|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" G$ e( f3 x2 A0 E+ D- @! [" j: y6 J3 Y" N5 D
如何获取选择点映射到视图空间中?源码分享7 L+ t7 y5 D5 }% j: R5 U
3 k& t. ?% F+ m, E5 o2 Z- //------------------------------------------------------------------------------9 _2 N6 w/ ?+ x. w
- // Select Screen Position and map to Modeling View Plane5 ^! y# v1 z( U; {' e9 q
- //------------------------------------------------------------------------------& o q- i" H; j1 ]& Q1 @
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos): A4 U% p; H# }) {% P( s# N D
- {7 _# p! Y- B8 P$ x
- NXOpen::View* myView = NULL;, r7 ~6 c9 |2 y
- NXOpen::Point3d myCursor(0, 0, 0);/ P8 n/ N& l, ?4 J% L, C7 c
: I( }% I# y# r/ P2 e w- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
0 Y- s$ i! e* w% Z N3 y( M# h - if (myResponse == NXOpen::Selection::DialogResponsePick): ~% t7 ~/ Q! [3 m: j
- {
0 P# G) L: s8 ?2 X8 Y - // obtain the current default annotation plane where PMIs are placed on
2 u& R: M( S4 h% C( Z. f - NXOpen::Xform *xform1;
3 s. ]- ?: z$ A4 Q) o3 e: M* H) d/ [ - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
$ o6 a; Q% C# H2 O4 \/ d$ d - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
& s2 T# f- l5 s0 Y - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
8 o3 R) f9 J& W: q. a - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);/ @9 r5 x3 \) n. j- @" u
- ! y+ j3 C( i, p0 z, w4 r0 A6 w
- // create the ray 'into the screen' at the selected cursor position1 S" P- G" B r4 p, E0 @6 F: w
- NXOpen::Matrix3x3 vmx = myView->Matrix();
* Q' ]) B9 c" R - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);/ H, C- D! N1 ^9 N
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);. [; M5 Z% H& ~, C
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
5 Y7 n' l9 b2 h) m - lineRay->SetName("Ray");7 F! D ~3 C5 n8 F
^+ J. D# g( g- // create the plane from the view to intersect with the ray
" `, _' v9 b: j4 y! v% x8 x8 | - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
/ j2 M5 W' G. B- L4 e+ x u - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, s/ k1 a& i* C
- planeView->SetName("ViewPlane");
/ P" Z5 { e p; E s" E& g
2 C6 U$ ]5 N6 {6 [: \- // now create the intersection point$ _! n8 J8 o, S0 I
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);: t' W: @' Q* l% {
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);8 t& S1 O, a8 [
- pntInterSect->SeTColor(10);( o" G/ C) `( d) Y
- pntInterSect->SetName("Intersection");3 c5 e5 W' ^; a/ q
- / x1 n, m- t" E u9 M
- pos = pntInterSect->Coordinates();7 i% a& {3 L% c# }
- print("\nPMI Position:", pos);$ ~" s: n4 N3 d
/ s3 a: o4 E/ Q- // clean up - comment to see intermediate objects
6 s+ I) O1 g7 z% v9 V - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
8 v7 ?, ]7 e3 }3 a - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);; \9 Q Q. ]; ?- `: K
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);2 c1 ` f! L- n; Q8 ~" k9 D
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
. R B3 [% d1 v: Y - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
+ ^; A$ h; E4 v! O# }, k, v \ - m_session->DeleteUndoMark(markDel, NULL);
& u, l+ I2 x7 o% N; Y6 _ - 6 a3 |' n' e; d. H$ Z2 |* r9 E
- return true;
' c& o1 c" B* I - }
, Q7 t8 q; U9 A# @+ c, ]
5 L. E, q3 t9 X- return false;6 z% D, R$ l7 ~" A) C
- }
复制代码 6 J; [7 I2 V; k2 r5 F# T& [
4 P# Q! s' A6 L+ w
|
|