|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) ?6 Z, }+ h% b# b3 n8 V
& M( M6 s P4 s/ a8 n* P* E如何获取选择点映射到视图空间中?源码分享7 _; o; L$ [1 U1 Y* J) X; j
* ]6 D$ c, z+ {7 Q9 G7 v
- //------------------------------------------------------------------------------
8 A/ S2 X+ k' j - // Select Screen Position and map to Modeling View Plane
* X, V$ v4 K+ ^. y - //------------------------------------------------------------------------------( ?9 X# j' R6 b8 P3 m
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
9 x F# _* C& ? - {# A/ ]* c( P& ~# @0 T$ l7 H
- NXOpen::View* myView = NULL;
8 \6 b7 \# S8 A. c0 y; N$ o0 E - NXOpen::Point3d myCursor(0, 0, 0);
; s6 |3 w& P: c# {
K" T: U/ ~3 F# f- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
/ w1 z3 }0 ^) _ - if (myResponse == NXOpen::Selection::DialogResponsePick)* i6 D. Q. t, `9 S* X O# n
- {
7 F' }, K) R% ] ~ - // obtain the current default annotation plane where PMIs are placed on
* M; A; P9 {& ~) P* u5 x1 o& M - NXOpen::Xform *xform1;
( u, j3 ?% A' |+ a5 V5 K) O - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);# e4 L1 T5 Y1 b. S! ~0 a8 X
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();5 \2 H5 Z1 k, O' `1 U
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
3 [0 @" k T. ^; ]* W2 m: ^0 K - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: n: w9 O, g% a/ q3 A: }
- " m6 Y! z; r. B5 ~; L6 J
- // create the ray 'into the screen' at the selected cursor position& v$ Z7 w& T/ A) g1 ] u! S. R" _
- NXOpen::Matrix3x3 vmx = myView->Matrix();
7 t9 D! Q1 q% @3 }! C4 q7 W - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" i. t, {+ i$ O5 G$ @2 Q2 l$ a
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000); V# O; x& A0 q7 m( [
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);8 m& Z7 }9 K3 J" K# X/ a6 x1 a
- lineRay->SetName("Ray");8 _/ H9 {- }9 ?7 R
- 4 s d8 c6 R! |9 c9 X
- // create the plane from the view to intersect with the ray& ` ?3 X- G+ W! T
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
1 V/ b! n- {5 ~. l) B/ k - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
$ x7 B' ~9 ~! l# f - planeView->SetName("ViewPlane");
9 H5 |. B( U5 l9 t: ~4 x! i - ( U* f9 z1 ~6 H
- // now create the intersection point
: f! Q& f: l8 t0 ` - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 L8 X4 t' |+ K
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
2 p1 d* i( U! E, h* H8 a* t% d - pntInterSect->SeTColor(10);! }1 n% g/ Y K( m2 j1 z, {
- pntInterSect->SetName("Intersection");6 }, b M5 w0 F) F( v' I \
- ' z# {) ]/ O- o9 p/ G
- pos = pntInterSect->Coordinates();5 z i7 q. m D9 D
- print("\nPMI Position:", pos);
' G4 q8 ?9 N V1 F7 S$ q D, v/ n
8 J" W& X6 [8 x# p8 l1 r" |- // clean up - comment to see intermediate objects
1 _2 a/ J8 R5 f @4 @# y' @ - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
5 c. J% A# [0 J - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
" P4 E4 F/ P, ~ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
- Q# |' `( k7 }9 G3 t - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
' C: s5 E" A( ?" z - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
" y4 U7 h' U. ]* V# W - m_session->DeleteUndoMark(markDel, NULL);! L4 x8 }5 b8 H% c; ~0 a( Z3 D
) T* l, j2 l5 u7 n, o8 U% o- return true;
3 @2 g1 |; W" u ]# N% j5 @ - }
. n6 a2 P/ [8 @0 ], M1 S
3 ]4 Q2 C2 Z; M+ @0 e+ U* ^. D9 ?- return false;
4 j X; f0 D1 h; a - }
复制代码
3 V# q% i3 D8 z) L4 {* |. Y: d) {5 t
. R, c }2 X/ d( e |
|