|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. Q# w+ S( e. }5 ~& S a6 b7 Z
4 H; j! b3 W. e$ L. u# N3 Y
如何获取选择点映射到视图空间中?源码分享9 W6 @5 D `9 ]! m
, N2 e$ x4 l& A7 H* ?* M
- //------------------------------------------------------------------------------2 T" ]& G B2 _" v( U) \
- // Select Screen Position and map to Modeling View Plane
4 w0 N0 o' m/ `9 z* @3 U7 U" { - //------------------------------------------------------------------------------5 i2 j/ C1 O3 A6 Y
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
% e) C. r' [# J# [2 }# @ - {
\( o4 L5 d k3 D$ O - NXOpen::View* myView = NULL;! ?- W: G( x8 J9 X ~2 M. `
- NXOpen::Point3d myCursor(0, 0, 0);
, ^& `( H. [9 D: A3 m - ! T3 Z% m. a; w+ k
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
+ |) U0 ~" H/ f! G - if (myResponse == NXOpen::Selection::DialogResponsePick)
- V2 U- [# y! z8 T! o* ? - {
" a$ `! ^4 `( q& Z' t9 ~+ M0 B - // obtain the current default annotation plane where PMIs are placed on! H+ Z# E g7 F L; Y T# ? [
- NXOpen::Xform *xform1;, v3 O0 h# ^3 ?5 e2 n, f- W
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
9 p# b0 ]& q$ r7 E% R* h9 R - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
8 u, ?6 B3 E$ N# Y6 F q$ L - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
5 `2 `0 L$ [( t% A& ?! [ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);3 `- s* d+ F+ u+ y& ^ y- `3 |
- _& W6 @8 b5 D5 X- // create the ray 'into the screen' at the selected cursor position
$ ~( h2 @2 `! W# {& I - NXOpen::Matrix3x3 vmx = myView->Matrix();
9 {6 D0 |8 X9 w+ a( T - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);+ h5 {. m! O) _/ }8 k5 Z& E
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);, F$ I5 y# R# K$ d7 T/ o
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
2 o/ s, \) C$ Q" H - lineRay->SetName("Ray");
E. U& P: X/ U6 m5 w& ?" r
& l6 H/ u5 x' J% m2 y- // create the plane from the view to intersect with the ray
( e+ C/ y+ a3 T - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
+ L6 H0 q( k5 f6 U# E0 E7 i0 b - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* N8 d+ C3 v* {6 s
- planeView->SetName("ViewPlane");! N3 h# Q1 A8 _+ C! P" L
5 d. r H7 O% t3 s: ^3 d- // now create the intersection point
! v7 R! B' C" G - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
1 y- A/ L2 s3 d1 _8 z5 u - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible); A1 R0 h( t: j* i( \& Y! b' s
- pntInterSect->SeTColor(10);
1 i1 K& H, \ ]1 {" Z% ~3 \1 w - pntInterSect->SetName("Intersection");
7 W' s& ^+ J( ] - # f4 Q2 f5 O2 r. o" }$ S
- pos = pntInterSect->Coordinates();
: t2 N. R) o1 L* v - print("\nPMI Position:", pos);
# [& Z5 N1 F1 C& A - - x" z. X$ }$ l7 U
- // clean up - comment to see intermediate objects
: C- v, f, g4 ^' H4 t - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
9 \5 O9 C9 I* A# E0 U+ H- g - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
8 S( J2 G4 K3 S. X, p7 ?; o- P2 { - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
* C I4 R/ o0 D; o% g2 l - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);; c1 g6 D' r+ b- |
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
+ V) d) X2 w$ R" ^! Z! s - m_session->DeleteUndoMark(markDel, NULL);
/ N3 O/ a+ c5 P& z( b2 ], _ - - m* e8 a7 O+ X! p: j d
- return true;, {) w" H0 ?6 x X4 P8 d1 M
- }
- y9 ]4 t0 r( P& E3 E6 j
}1 a' p8 v, O5 K- l- return false;2 L9 X0 U( T4 l0 r
- }
复制代码
6 p4 X# V4 @7 b! e! L6 o. G/ f; P; [0 G
|
|