|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; ~* E7 f, v' e
0 A7 I: T6 u% A& M8 ~0 C% {如何获取选择点映射到视图空间中?源码分享& [, V" F% \: h2 \
9 b, _5 H; C7 M2 [4 @5 S" K
- //------------------------------------------------------------------------------* v$ b g1 ~" N
- // Select Screen Position and map to Modeling View Plane
, C+ r' X+ z4 _. \/ c, m1 T" ]3 b - //------------------------------------------------------------------------------
+ T; Q/ a4 }/ Y% z2 C# j5 [ - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)( m1 O4 \7 A+ ]' k6 c8 X
- {
) L+ t* E e0 I - NXOpen::View* myView = NULL;
7 N% m' T# |6 N$ @$ G: u - NXOpen::Point3d myCursor(0, 0, 0);
$ ]) B9 F6 e9 y0 A- I* Y" @" C! N
3 V) h9 D& W- Z$ J/ o# W; ^- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);2 s |) f) x' @3 _, @ n
- if (myResponse == NXOpen::Selection::DialogResponsePick): I2 u9 j- q# V) f) b
- {) d0 f( s" R% n j+ g8 H) q) A" O' I8 T
- // obtain the current default annotation plane where PMIs are placed on
$ G6 H/ s* k! Q/ x& s5 p - NXOpen::Xform *xform1;2 F* c: b. t, X3 W
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);: ^9 u7 I; r8 U) A3 g& t0 ]
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
: i# p1 h) {$ y( C6 ?- n) a8 m - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
6 H# }* C! F# L; L; E1 Q1 L! Z, [ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
* G9 n& k }. O' A$ X - ( i8 l0 C' T! n3 [, B- w% W- J0 x6 X
- // create the ray 'into the screen' at the selected cursor position
. l8 z; l4 A5 c' ^ - NXOpen::Matrix3x3 vmx = myView->Matrix();! Q# {9 U) k$ M9 {' D& n: H
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
, B, ^) h, I) W; y& ?$ ~ D; o6 V - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);) q( T4 f/ p7 ^
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);2 z+ j5 O9 p S& J0 N4 G+ ]
- lineRay->SetName("Ray");9 s" e) ?/ g3 m( e/ V( e7 [
: U/ h. C9 D* ?, T- r1 N$ F- // create the plane from the view to intersect with the ray
) f ?4 u! o0 O/ v - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
. Y& k" ~3 f X4 T# a - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
1 m5 R0 S0 ]' `+ b, j" E8 R- {: u J - planeView->SetName("ViewPlane");4 r/ i) O* [8 _# h2 L
6 Q8 @! j0 P0 ^+ T8 f- // now create the intersection point" ^+ I0 v! B$ U( G0 C# U
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);' \: r' j* T0 ?) S
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
4 H1 \% L# Y1 [# r# I# B - pntInterSect->SeTColor(10);* [- A1 {5 h9 I. m8 O
- pntInterSect->SetName("Intersection");4 [2 z( F9 A# }. ^/ |
" h5 _- O$ Y; H! ?, v/ ^% X- pos = pntInterSect->Coordinates();
5 h3 i# h$ o3 n$ c1 Q - print("\nPMI Position:", pos);# M, f) O- H# b+ N* y" I. j
- 5 d$ |) |; I& H
- // clean up - comment to see intermediate objects$ }; `' P9 X# J" l4 p# ~
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
6 q o' q/ ? {5 K" T - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);" ~8 m- O8 \- q* Z+ i+ }6 r
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
5 e0 P& k1 F, a( L; c - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);# g. m! W* J+ j: ?% L! \4 ?
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);: V- w2 T4 r: H2 g) j/ @1 G
- m_session->DeleteUndoMark(markDel, NULL);
* x: ~# Q# \% h! C9 y# N, t - 4 c; D" T1 O0 H4 X
- return true;" r: j9 o3 r S5 |$ n! h' ~% z
- }: z: O2 W4 [0 u% E, k( U
% W. w4 A* Z( a& n8 Y- return false;+ T7 H1 G- I) q* Z q; P+ [/ S
- }
复制代码 . v+ I. K8 @( T2 p
4 t- I& ]% p! ~/ v: H
|
|