|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ \; O; _1 T1 j4 d) v# t' E5 {' e9 C, D w0 {% P
如何获取选择点映射到视图空间中?源码分享
" L: F5 g" e; L9 F# e
, I' E/ v+ j6 @- //------------------------------------------------------------------------------
1 @) Q) o3 j7 J% h/ j" m - // Select Screen Position and map to Modeling View Plane% ^' X5 O! w6 f; @& ^3 K
- //------------------------------------------------------------------------------
4 d5 z I+ f/ ]6 P% ^ - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
+ }2 V0 G" @# W! ` - {
+ c$ E' \1 v1 |" u6 F: ~2 F' j - NXOpen::View* myView = NULL;" p2 s! O6 I, E. j4 a( F( ?
- NXOpen::Point3d myCursor(0, 0, 0);1 W' k- D/ R) n9 \# d8 B9 \
- 4 e: G$ U: J" L# V5 l9 F( X8 I
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);, b8 B. l+ z F7 _- W+ Y
- if (myResponse == NXOpen::Selection::DialogResponsePick)( i- \ M2 u" R; i* L
- {# R: O3 f' m, M2 X2 s+ L% w
- // obtain the current default annotation plane where PMIs are placed on
1 `: n: X3 S+ g- r% v% b, h* f5 g - NXOpen::Xform *xform1;1 w s6 k/ \- F2 w0 ]
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
! h" }8 e- \" v% h' u - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
3 }) @' D# C0 @5 I1 `9 h - NXOpen::Point3d ptDefaultPlane = xform1->Origin();6 F% J/ f" V6 F9 j
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
+ ]1 r4 k7 q' O) v - & w7 X5 z% {1 H
- // create the ray 'into the screen' at the selected cursor position
3 I- y9 n7 e) O6 W - NXOpen::Matrix3x3 vmx = myView->Matrix();8 A# W/ p( \. s7 E% w V+ D
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
! f: j9 x5 r5 D) @ O' }* v) Z! F6 f$ ~ - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
G' m Y3 O0 S5 z1 ] - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);1 R+ P; c' Y) Y& I
- lineRay->SetName("Ray");
) y! ]& x, |7 a+ R - 6 Y# i4 _2 N( p# ?
- // create the plane from the view to intersect with the ray; N1 g' {! @% B3 n6 {% {1 v- `. d
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);+ ~+ h) N: V- ]) c6 h9 W7 l
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
: J5 Q+ E6 |. {$ l9 r1 p, o7 w - planeView->SetName("ViewPlane");3 {; H; t+ x/ S
; B) o9 X! \% P% z- c2 L- // now create the intersection point
% s" ^/ ^0 F: j$ ^1 \ - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
. j# w+ ?- V9 b y9 Z" Y - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
* p9 c1 H$ Q% R2 w! b/ ~" C# R2 M - pntInterSect->SeTColor(10);
* W8 \ m E; W9 g) l - pntInterSect->SetName("Intersection");) _1 t3 G4 L% B5 {' }/ {8 I
- * e7 c0 X% N% \ s6 e$ H
- pos = pntInterSect->Coordinates();
& @8 L5 ~- G/ t( y$ `6 f" z8 q - print("\nPMI Position:", pos);" O" a1 f# F1 R# \7 ?) I% m7 @
# ]" H ?! `: J e. Q- t- // clean up - comment to see intermediate objects
3 `" A7 }* P6 X6 k9 G% D1 m$ H - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
- G0 k4 C4 i; J - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' G: [( x" |" j' M; ?, i' s
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);. f6 [3 Q( y! q* m& k( Z6 _
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
) C5 L3 g; m5 v) G3 t - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel); K/ g" n& z h6 b; q8 u
- m_session->DeleteUndoMark(markDel, NULL);
9 R' {, v/ [7 J4 Q
7 E+ U5 j3 e# N+ ^- return true;5 y# x$ G2 c9 e f/ V4 {" S
- }
- k% p' Q9 z3 X - 2 O, Z' ^9 G9 M' F/ D6 U R& y
- return false;
! X; O4 p/ ^3 i( M$ a. G - }
复制代码
0 J6 U" i6 ?3 H' B: x/ c3 p8 h: W2 O
|
|