|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ k5 }0 O0 ?0 N, n
0 k1 b5 ]! W6 H' x! {: b如何获取选择点映射到视图空间中?源码分享( E$ t1 @+ C0 C1 o' j. q* o. R
& l* s9 H8 H ?- b- V- //------------------------------------------------------------------------------
1 ?8 B* q+ @# |/ ^9 U5 g% W P - // Select Screen Position and map to Modeling View Plane$ g* c% [* _0 z: ^
- //------------------------------------------------------------------------------
3 C" s3 d$ z8 O, o - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
/ t! s" N6 L2 R6 _/ M - {. B/ B# p) B; C* G
- NXOpen::View* myView = NULL;
3 b" y5 D% V2 T4 ` - NXOpen::Point3d myCursor(0, 0, 0);6 d: L+ w: J% J# g# M9 _7 @
p1 j7 L- O. _- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
2 z$ J# V/ [7 v9 S8 s' p- g1 x. O- x - if (myResponse == NXOpen::Selection::DialogResponsePick)
2 A( k [$ K- S" _7 {6 Q - {+ }9 F2 S" k/ O% L' U- u
- // obtain the current default annotation plane where PMIs are placed on
. |; u6 D( R, j+ s8 s) e) ^7 T - NXOpen::Xform *xform1;$ ~) b7 V8 i7 M1 f% L
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
% z4 ^+ ~8 L/ @1 ?! b - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();. n% I0 _! |: r7 z: K
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
1 |- G+ W* k( R- x7 T/ x2 c' z - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);; t2 t! o% M% y1 U. ~
$ \7 Q' d. \& E6 N; L' N0 t9 w- // create the ray 'into the screen' at the selected cursor position
8 D! t+ n& ~2 w. N+ _+ I - NXOpen::Matrix3x3 vmx = myView->Matrix();
# X7 G' F: O4 G$ U - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);0 I, q" l* E% I# h2 V8 i% K% W$ } r
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
/ ?) V$ [& G- k7 D - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);2 j% {. f, [. M& y6 |
- lineRay->SetName("Ray");
* i/ _% X3 v4 r - & [6 o- t& A$ j% o
- // create the plane from the view to intersect with the ray
; z( [ I4 r. Q. B - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);. G* @3 o$ c% ^3 t9 _: Y
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);( x: U2 p9 Q- r. g6 z- S5 \ _& y
- planeView->SetName("ViewPlane");
Z% d8 ~/ c( e
$ [+ i$ Q) k* @/ \" S' `- // now create the intersection point
G6 ~( s' l$ @9 l" T$ j - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);' A* T$ P+ r0 w
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ i y3 _! h: D4 q5 S5 o1 s
- pntInterSect->SeTColor(10);& c" k+ E5 V' D+ Q! j0 b! x Z
- pntInterSect->SetName("Intersection");
' i, \# o1 U( x8 t" e9 O8 O - 7 u7 h3 A D) A9 C y' d# K& y
- pos = pntInterSect->Coordinates();( h; W) z3 H. g$ \% D
- print("\nPMI Position:", pos);
9 M& m, n4 O8 O8 R0 ]$ _. R, H3 U
! m# C7 O5 S6 C- // clean up - comment to see intermediate objects
) j* @, g* R) U' A - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");- k! W* Z, T( {: I
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect); {1 L3 k7 O1 K4 {8 h
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
# ]8 E( `: D+ v3 `( M5 o! N, v9 } - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
: i& g$ O9 V u8 q& m - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
" x' k7 ?' Q3 r' X% Z! R8 J - m_session->DeleteUndoMark(markDel, NULL);1 F; S1 _1 F* x4 @& n; A
) B) ]& q2 y2 O- return true;
/ ~! z& f5 x, N - }& W$ w& Q) T: _5 p; p0 X5 R
- & i: C E# }6 V* S- x
- return false;( W- Q7 g% G# F$ Y
- }
复制代码 ) e( N* C, p) C. ]
! z, q5 f# W p
|
|