|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( l4 S, i- L' H6 O
u0 M8 A }8 k- W6 t" s
如何获取选择点映射到视图空间中?源码分享9 w' }: ^5 L1 ?5 a! R
( Q8 ]" m1 R7 T% X7 q- //------------------------------------------------------------------------------
( o3 L# ^7 O# e - // Select Screen Position and map to Modeling View Plane
9 v1 O' I: d- I' P - //------------------------------------------------------------------------------) l; f" o7 P1 Q" J# y
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
) s9 v; i% k! [; w5 @! { - {2 P5 w3 ]9 w) l
- NXOpen::View* myView = NULL;5 L/ J* ^& i! B( Y! W
- NXOpen::Point3d myCursor(0, 0, 0);& |! p3 q7 M7 \# X4 I) G! z; s
! c' H3 l6 i. W1 H- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
1 O! d9 f, }& k: g - if (myResponse == NXOpen::Selection::DialogResponsePick)# j: l$ c# I: Y/ I0 z6 a7 f
- {
1 s! t5 ~2 t6 H( j5 a/ K5 D0 U - // obtain the current default annotation plane where PMIs are placed on
& u$ x9 @3 O& d5 O* F# B" S - NXOpen::Xform *xform1;
8 K- I+ D5 `* r% c$ v0 J' \ - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);' L& J' q$ D2 O( e; h0 x9 l
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();/ n; _7 s! l+ r( {
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
3 o" K% H; v h& v5 I( c3 m - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);( a; G4 t+ w6 A& l0 c! g/ J
' y5 l8 R9 O$ C- n6 Z. i/ i- // create the ray 'into the screen' at the selected cursor position+ ]! E; h0 B7 }' J
- NXOpen::Matrix3x3 vmx = myView->Matrix();
3 |0 g0 I9 m; i5 i3 L3 P - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);, x! Z4 k+ s1 j' t( V2 {& \( b
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
1 i" [) q7 S5 g" ~ v - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
$ ?9 o% Y! [% Z# M1 w - lineRay->SetName("Ray");
4 u/ G) q0 U$ i6 x0 h$ s- t! n: H - 5 I5 R0 C: Z3 n x9 S0 K
- // create the plane from the view to intersect with the ray
4 I" T1 y! O, }( m7 u - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);, X1 @1 {* V1 B: X% Y
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
f' m E" l0 t; g6 m& w - planeView->SetName("ViewPlane");: L' e: R) u5 _/ a9 b
) a$ F0 |9 @; q7 z: v" z3 N. g- // now create the intersection point
& w5 }7 [- |4 r3 [7 t. ~6 _* Q1 ? - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);! Z, }7 V. L8 {2 @9 N
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
# |) n4 Z" q$ U! G9 Q) c" ^( b - pntInterSect->SeTColor(10);9 [. y& l, o9 Y9 ~4 X
- pntInterSect->SetName("Intersection");
3 x# y& S5 T' U9 O3 w" {; R
; K( t$ ?' S: m! k- pos = pntInterSect->Coordinates();4 C$ w" X0 j5 ]" x- e/ c/ A
- print("\nPMI Position:", pos);8 r% ~2 x( S% ?/ s" p9 [1 i
: z0 k8 |4 V3 X1 ~) ]# f2 [( r- // clean up - comment to see intermediate objects0 K3 n. X0 x; K( r( q
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");. y1 O! w% o3 d5 c( X& l
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
0 n$ U" Z- b. T! e - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);7 r7 Z7 X& ~0 r9 d: D& ^
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);! {, g: i7 i5 h3 j8 B8 F% V
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
- h# i" z7 c( T g4 q - m_session->DeleteUndoMark(markDel, NULL);6 E$ v1 X# e, ~" n4 K
4 z& v6 j0 W% V0 J, K* D L- return true;0 G& W U7 g( V0 a$ u; o
- }0 h O- S% a. W- V3 m3 m# H% M! N
9 ?1 C* k6 b" @6 d d h- ^/ B5 E- return false;. L. E9 Z! P4 G) o0 f; `
- }
复制代码 3 P( ~# f k/ L- T
- j) ~! G* E+ H- k. ?8 Y
|
|