|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: t( ]9 r2 ^( T6 S4 U+ {; H9 A
9 a! T8 H4 y' I( P/ |( x6 ^- W
如何获取选择点映射到视图空间中?源码分享, B. n6 f! d' f. F5 P& [
( F4 L3 y: H- N7 i
- //------------------------------------------------------------------------------
% |- S! i9 t S& m, k( R - // Select Screen Position and map to Modeling View Plane: q* b0 z9 B w$ f$ ^5 A
- //------------------------------------------------------------------------------
@5 V' g% h% l# q - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
% l( n' Y/ C" |! `8 W8 i9 K5 ?" d - {
* ~% \# W' ]1 B - NXOpen::View* myView = NULL;' c$ B: Z2 h2 n3 I
- NXOpen::Point3d myCursor(0, 0, 0);
& M0 r" d r3 ]1 g. J7 W' Y - 1 C# {& c$ N( m) i* M$ X
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
1 P3 T7 d1 H0 L# z: V - if (myResponse == NXOpen::Selection::DialogResponsePick)
0 u$ f: [2 L; i# r) I9 a - {4 x% [: [* c" a& L4 ^8 q) x) n$ ~
- // obtain the current default annotation plane where PMIs are placed on
9 q( Y1 [* r" O: g( R' a4 ^ - NXOpen::Xform *xform1;
& {- s1 K7 W3 p2 e0 T! ` - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
# O) ~+ F% R- | - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();" d+ E3 h/ U" N2 b$ ?
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
$ }. C* P3 g1 }( U - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);5 j0 a6 Q; @6 z9 `$ F$ z; n! p% n& |
% s+ _! g3 R" r( M* E6 [: I* p- // create the ray 'into the screen' at the selected cursor position
6 z9 @7 \, X9 \. Q3 M3 ~ - NXOpen::Matrix3x3 vmx = myView->Matrix();4 C" s* X, X% W. N7 ^0 E# Q2 q1 M- D
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
8 J% T2 u# d5 T. A; ]+ X- l2 a7 s - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
# B3 C9 F& \8 J6 w - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);' e/ k. g4 e. u7 b- C, Y/ y/ Q
- lineRay->SetName("Ray");
8 v! R' ^7 V6 c - ) s5 {# N0 X2 ~$ ?! b
- // create the plane from the view to intersect with the ray
0 C: L( I2 S4 S5 I - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
; m& U; }1 L7 F- W! u* ] - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
( a9 B+ `( y; q: L/ X9 F - planeView->SetName("ViewPlane");
9 I2 h; f1 s7 N7 _1 ?& e& I - 0 C8 R% ~5 ^; u/ O9 A) Z$ M6 k* S" M
- // now create the intersection point' C9 E, P. U- |2 m6 n! f
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
6 |$ t9 X% Q2 i3 r' x" f/ p/ V - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. V7 z& h. x1 @! I
- pntInterSect->SeTColor(10);/ ]& u3 g. D8 ]* y
- pntInterSect->SetName("Intersection");
! B" r9 f8 E/ | - : M+ \8 t0 S/ h$ P: M+ t
- pos = pntInterSect->Coordinates();
. Z: S+ f# b( w5 H! a2 s' B - print("\nPMI Position:", pos);9 K4 L9 d1 G( [7 Y5 @% W F+ [* S
( E4 O1 q& c+ v. F2 w. O- // clean up - comment to see intermediate objects
' d( K- I8 k$ I9 q4 s - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
: d! n; i. }- {7 M" t* m W3 U' e - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);) P3 |8 q' U8 u. C* f6 o
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);! I1 _1 ~1 w' p/ @' I
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
. @2 W5 f+ F/ I+ p( x - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
' K+ B4 u7 s* O) Q/ J! k - m_session->DeleteUndoMark(markDel, NULL);3 F; ` p) g8 b, B# h
: u5 R$ |% O4 {. G* ^: o- return true;
, A. f* }: d7 y: |/ w! T - }
' g7 m& M! N M" n) L - 9 A+ M' H7 j. n8 C: w5 r
- return false;
9 t5 [! @+ F. N1 A0 a - }
复制代码
# |. o9 k+ N5 G/ G$ _
* ` z! p$ q( K, n: i; x* y |
|