|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* Z3 G4 z3 K2 h* x/ Z$ A% Z- J* e m& v! Z7 f$ V7 a* h
如何获取选择点映射到视图空间中?源码分享- o: |7 [; @8 C0 D& a7 d( `
1 R3 L" _2 F4 w% a" ~, g5 q" P- //------------------------------------------------------------------------------' V, [9 x, [" X" y+ z, F
- // Select Screen Position and map to Modeling View Plane! H$ w- Z3 j% S* L/ l8 _3 `
- //------------------------------------------------------------------------------
& V; u6 [- C4 X; E - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
3 c! m! y, d8 ]9 U - {) e0 I8 ?4 O$ d9 c
- NXOpen::View* myView = NULL;5 ]- V* m M% x- t* I$ o# q
- NXOpen::Point3d myCursor(0, 0, 0);# Y9 M1 L7 c+ H/ |
/ e' F& }# p9 L9 S$ T- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
& N; A( f" i+ V, i" w7 s - if (myResponse == NXOpen::Selection::DialogResponsePick)# f& d2 `$ c. z- x
- {
% Y. v, i! u; n& | - // obtain the current default annotation plane where PMIs are placed on
" m, C3 R! [9 i, a - NXOpen::Xform *xform1;
, ^% B" J+ X0 ^9 O - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);. Z9 u5 p& G3 K! z2 f. q0 t0 t
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
. U% V3 K. Q4 E9 m3 N% A9 m$ n - NXOpen::Point3d ptDefaultPlane = xform1->Origin();' L; C& J& i9 T( q
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);" d, U' o3 Q. B. Y6 }; b
7 U, {) F9 }. @# G- // create the ray 'into the screen' at the selected cursor position
; O2 }5 S7 v' ?2 } - NXOpen::Matrix3x3 vmx = myView->Matrix();
8 I" F! o7 N/ @; b; d* T - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" O4 Z3 `8 Z6 l# z- e
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);% D& V0 e: n0 D; k) w1 f) U& p
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);2 P* c2 }3 c/ H: Q8 I% \
- lineRay->SetName("Ray");8 P& a6 v9 {& u1 r1 ]
1 k' v' o" _; u" H1 E0 d0 c0 s- // create the plane from the view to intersect with the ray5 E: h: n' t" Z+ Z
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
6 v1 ]$ H" ]5 z5 a& c* n+ `! j8 ~3 ` - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
) E& V2 r" w# B; Z - planeView->SetName("ViewPlane");3 r* q' ?) U, K9 p! e2 N% T1 O: U( d
- # ?6 W) v$ ~2 s: h' J: l! |
- // now create the intersection point7 z( V" B1 \9 \0 G
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
) j, ^" s* Y8 t* O - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 w& N( g2 q! i. N
- pntInterSect->SeTColor(10);
* f* N) c/ M% | W$ w - pntInterSect->SetName("Intersection");
4 h! E- c/ L$ ~+ K$ ~% e" Y
1 ^ U- `( Q, ~, L5 t- pos = pntInterSect->Coordinates();% Y) j( K1 W, u5 J) _
- print("\nPMI Position:", pos);- N3 N* r% v# W# u4 ~
- ; O! l/ u: }3 Q6 y+ D
- // clean up - comment to see intermediate objects" f* I3 X$ l: W& G( Z
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");% e( q! S; J- x. P0 ?. j
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);# q2 O: ^4 G: Q7 G
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) L( d/ s3 G/ \9 I) s' t
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);7 R- Q% _- e* \1 @* R' q0 F/ ]# W) @
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
3 F0 T2 U7 Q: R! K5 [2 @- ], P& i - m_session->DeleteUndoMark(markDel, NULL);
9 ?! \ z# F% x# }
9 i" [2 e# Z) g/ m- [ i# x- return true;
0 Q' U2 n$ Z; h - }2 ]4 d5 B/ V2 c; i- F2 Y0 L* ]
5 [' X! W3 n# W- return false;# ^/ r& G7 A- e7 d3 D2 p
- }
复制代码 2 Q3 Z( c+ i6 E! h
% A" K6 y, D9 @2 o
|
|