|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* F3 Y8 L. i( D' T; [
$ d& q8 x4 v1 `- ?# ^如何获取选择点映射到视图空间中?源码分享
5 l5 z/ ^: v; ^
( C/ Q' e9 m% L5 J- //------------------------------------------------------------------------------
: m0 i0 v% {; r+ i6 ~ ~* e u - // Select Screen Position and map to Modeling View Plane) @! J- H: o+ z/ c, i" b5 M" b
- //------------------------------------------------------------------------------; d/ w8 x7 ~8 y3 ?8 w0 T9 P
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
0 g; [9 {% o* E- \ - {
4 I3 d0 Y$ i% `$ y. K - NXOpen::View* myView = NULL;
6 B, M% ]4 Q! V - NXOpen::Point3d myCursor(0, 0, 0);
% @0 o; W! n: a; g) b* M! f8 \ ]; f
+ c% s8 v" X( L7 `9 D/ ^- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);# t& [: T/ n: T) t! |6 i
- if (myResponse == NXOpen::Selection::DialogResponsePick)' F/ P/ q9 f0 E3 @5 L$ E+ S
- {
5 \4 V$ X' J0 e - // obtain the current default annotation plane where PMIs are placed on
3 t7 g! s, D; G# ~6 Z0 X G - NXOpen::Xform *xform1;
* X8 {" ~9 p I" Y/ c - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);( K9 W U, s) V
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();2 t6 S+ G3 {/ K+ d
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
U Z# A& J# q - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
& \6 P9 E3 n( G* Q
' t" X9 Q; g2 [7 ]' L* e2 w: a- // create the ray 'into the screen' at the selected cursor position
: \/ G0 M. v! d - NXOpen::Matrix3x3 vmx = myView->Matrix();
, m5 I# j: v) D2 t* [; s - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
# D+ h+ u8 X+ w- w! H7 { - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);, b2 j% C. Z5 t5 u% h8 }; x
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);6 m( z0 j4 k& Y; z5 e) L
- lineRay->SetName("Ray");
9 V/ u" O: X6 [2 E
. F! F$ N9 [ w$ c- // create the plane from the view to intersect with the ray8 ^1 S6 ?8 X, I% `" t1 S
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling); t( P* ^: f! l( n
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);) ~* L; E9 w$ _% F o
- planeView->SetName("ViewPlane");
6 r6 W/ U; x. B8 a) m1 M - , p. O1 x9 X e2 M* G
- // now create the intersection point* l9 U1 h: f* B3 v# O
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
' J( f& k4 i: m' o - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);: K8 ?# \" B! W+ T! T
- pntInterSect->SeTColor(10);
5 `. B. {. S$ O) @ - pntInterSect->SetName("Intersection");* i! n8 i/ k0 M& f. U; `
- 0 X# ~9 [; v* K1 S2 C
- pos = pntInterSect->Coordinates();
$ W, z% B, j3 h, s" X - print("\nPMI Position:", pos);9 P. j4 d" Y1 d
8 o! x: \" f1 A+ u- // clean up - comment to see intermediate objects
! h/ C; o" Z& f - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
: V2 v# C0 Z% M( ~6 C, z0 w - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);7 ]* f& W" D% \' F+ ]! z3 J5 M
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);, U' f$ i: k. [ O' ^1 _& p) B
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);" a" w' A" F1 I5 c, F* D( d: l7 P. T
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
) K1 o3 C6 u5 W0 K3 d - m_session->DeleteUndoMark(markDel, NULL);7 y; w7 f! N* f' g( |
3 u( ]( A3 J% w7 C4 P5 v# Z0 w- return true;
9 k, v' t( H7 L A( k. \4 _ - }% ?4 D! C* K ?5 @/ ] X
- 9 Q c6 i8 ~# u# ]# c
- return false;
* g1 l* Z) o2 e' R& i3 M7 J - }
复制代码 ) }) U1 d) {# R* f" M
4 q3 D5 H* b: |0 I# l; e
|
|