|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) R% o; v5 [* F* L8 _- P' I
( p3 o) E8 _( j& j
如何获取选择点映射到视图空间中?源码分享) i2 u q Q& R$ x% ]! G# C0 p3 P
# l: _4 v; e# h. ?1 [3 P3 N( a2 q
- //------------------------------------------------------------------------------
1 S" i j- P3 Q y - // Select Screen Position and map to Modeling View Plane/ D% |* i+ S; s. C" l
- //------------------------------------------------------------------------------# o1 A- P- |% x9 d5 K0 l5 o5 m
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
, K3 I/ s( s% B6 o& ^% C - {3 R; u3 T" T2 Y9 R% ?( X
- NXOpen::View* myView = NULL;5 W( W8 b3 b/ K+ R" t$ a( n
- NXOpen::Point3d myCursor(0, 0, 0);3 M, f/ @7 j* t4 H( Q' K
- ; M0 Z9 H5 L; _
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- \$ g7 q0 J0 ^
- if (myResponse == NXOpen::Selection::DialogResponsePick)
, o! k( w( i" s8 ?# ~+ s - {( g$ L/ @: ~8 P9 \- N% E- D$ q
- // obtain the current default annotation plane where PMIs are placed on
0 n" s6 p/ i. `% Z - NXOpen::Xform *xform1;
# C7 U0 S1 C* H4 C0 ]: K$ ^' x' Y6 R+ B - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);5 |% T/ o/ |9 W$ T- [
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
: v4 N q9 N: m/ v$ d) t& Q) @ - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
" V& O" x+ E- \% m3 ] - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);( b2 C0 v( [0 @
' B, C6 o0 s- M& H; a. k4 P( n- // create the ray 'into the screen' at the selected cursor position
# E0 y* ?# o) | d1 B. H/ ` - NXOpen::Matrix3x3 vmx = myView->Matrix();' ]9 W. c' Z7 K$ c) y; V
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);2 b+ I2 G. d% F4 B# o0 ?* n! d
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
; G" i$ t! f- p4 r! h/ F; H$ ^ - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
! H# ]7 |% w* x. m- e5 V, D - lineRay->SetName("Ray");0 I) D" q% J/ ~: A8 ~2 Y4 z' l
- I5 Y* E0 X/ R# j) |
- // create the plane from the view to intersect with the ray
9 O+ m# Z6 k: x: r& ?+ q - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);. h) Y+ X5 Z) w( e' d
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 C% n* L( L$ k/ {" Q
- planeView->SetName("ViewPlane");1 A( `, _( h+ v" {- T* Y8 I1 k
4 ]/ _$ Q# d! F# N1 _9 w3 a: O- // now create the intersection point; J* A5 b) f; U, p* c ]. C
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
) E' ?# k2 `$ G3 R - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
/ _( ]1 z, ]$ d( o - pntInterSect->SeTColor(10);
9 ?0 e5 w! r( x* a( P - pntInterSect->SetName("Intersection");
2 j# i' P; L3 P' T8 j
4 c6 P/ g+ T3 r- pos = pntInterSect->Coordinates();
; l4 ^& i. ]9 v' t2 Y. g - print("\nPMI Position:", pos);
( A9 f* m7 `. a6 G
( b- W; S5 P& R- // clean up - comment to see intermediate objects! s2 S; j) P/ Y
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
/ W% i' O* R4 Y - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);+ E- u2 t& t% G3 t, }: a# [! q5 f' r
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
0 T; T e9 {; P; @% ]9 j - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
9 G' `, ^1 C% D& p$ T5 g - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
! {8 x. |0 t3 S - m_session->DeleteUndoMark(markDel, NULL);% R2 X1 ~" y; G* I
- , H1 D. c" p( i- i
- return true;) T0 J+ J5 Q8 y& _, W/ I) z! s
- }% e3 z- f/ v( o! X; {$ f
4 Y3 w, E4 ^1 H& e- return false;
4 t3 L8 m/ R% E9 R( A - }
复制代码
! S. p: V _6 O" ]5 D6 ?6 \8 h6 w
|
|