|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 T( n7 x" v F! b0 x
/ G0 e' I; J( _. L如何获取选择点映射到视图空间中?源码分享
9 ?, d; M: E; u) C }7 y
4 F' A" ~% I; N' l- }* t1 V- //------------------------------------------------------------------------------, \8 h9 K. V* T8 v3 q5 {3 `1 A( e
- // Select Screen Position and map to Modeling View Plane
% \" [: p& T) ?, N - //------------------------------------------------------------------------------( M- W# w9 t: ^" S8 f! N
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
2 I7 N& Q; M# b* A) T: Y - {! t3 a2 ]+ e( M' y
- NXOpen::View* myView = NULL;6 P d- J7 [) `$ Y: \8 V# p
- NXOpen::Point3d myCursor(0, 0, 0);
" w5 H) Y! w. P/ c7 _3 e( Y
: H5 ]; i( [: V; Q- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);, [4 R/ i0 W, q$ v- E$ S, A( ?
- if (myResponse == NXOpen::Selection::DialogResponsePick)/ B. |+ C' B1 ? d' ]+ |
- { d& ~/ m6 D, H
- // obtain the current default annotation plane where PMIs are placed on* y4 r% L) y1 P% H. D3 G9 G
- NXOpen::Xform *xform1;
) }% Q& N5 h+ A; Q$ W - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
+ ]! H% \) p* ~* n2 f* @$ w - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation(); n- \7 ~2 N) q, q, I/ \2 Z
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
" F8 n5 j5 f8 e, r2 [. {2 c+ r5 b - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);1 e1 {; u2 n3 |* L/ U7 [
" o @$ q3 U6 g+ B% O2 ?# Q- // create the ray 'into the screen' at the selected cursor position9 ?+ i' Z, r& f1 [
- NXOpen::Matrix3x3 vmx = myView->Matrix();9 g6 U' |3 h1 E. f) a6 E1 P3 v
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
5 d% l3 j' [, s: \# N - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);) J8 [5 @7 p* w; r* H
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
, W+ G( f* p! o, S, w, ^% \2 d0 a7 O$ E - lineRay->SetName("Ray"); d9 O% z; j0 o5 D. M- I' _8 c
- 1 h* h2 i" v& a( Z0 C6 o
- // create the plane from the view to intersect with the ray# Q0 ~# C! S+ y+ j: M3 {
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);0 _& x! f# A0 _! H
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% B8 h% K3 D" N) [2 C
- planeView->SetName("ViewPlane");
" h' B2 y, k7 A: ^0 ~% Z - / a1 n2 p2 }+ A3 T/ V
- // now create the intersection point
5 m! j& J- E1 B6 c - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
" o, m2 x! ~; t; S* u! e; c - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; T( ]8 f- A3 t1 g
- pntInterSect->SeTColor(10);
+ z+ l8 `( ]. ?% x& E; X3 R - pntInterSect->SetName("Intersection");( ^1 a( j3 n+ b: ` b. M2 v
- 5 f) O1 N1 `1 t" v \
- pos = pntInterSect->Coordinates();
K& v7 H) j( \4 ^. ~ - print("\nPMI Position:", pos);
+ s4 S% @. o# f5 Z. t8 Q4 d - & e6 f# T* S" b
- // clean up - comment to see intermediate objects( z1 M/ E# N; @) A8 V
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
X0 x$ j1 ~$ y; Q/ { - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
3 k6 G, b% l# R# b4 G; J - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
5 v+ O/ P3 W. l# _! x) n, X# Z - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
4 f: P0 p0 A/ }3 K5 w4 y( ` - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);- [, Z0 k; i1 y2 y; U. S
- m_session->DeleteUndoMark(markDel, NULL);$ E$ t k0 X* I! {
' \0 {- t0 X5 ]$ S) y% k# @7 m- return true;
$ \+ K( E/ @: i9 t, l* F8 }3 T - }
3 G( ^8 H+ f3 u - 8 y) k; O& F, |0 c
- return false;6 `3 A& Q* {- A) l2 d# Z
- }
复制代码
! P8 U% `! w: z( C/ U' C
! p! a; \) r+ V0 U% p: g- ` |
|