|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 O: N* S/ I8 }9 Y# c
6 S3 h3 X; v" q2 b& I
如何获取选择点映射到视图空间中?源码分享, A1 ?8 z1 k5 D
. Q1 w- Y0 y, C" _7 ]3 G* B
- //------------------------------------------------------------------------------
) m& f) X! f' s3 A4 I - // Select Screen Position and map to Modeling View Plane v% P, p8 o5 ]) v' J7 q
- //------------------------------------------------------------------------------
* Z; L5 h- i9 |" j9 b- J) e' l - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)8 U! I1 |" J3 B+ z. }! z( z: o8 k' u3 E
- {
; ~# W7 Q5 Y9 h8 E4 G7 K* V& ^ - NXOpen::View* myView = NULL;7 U; ` ~$ V- w+ @- N
- NXOpen::Point3d myCursor(0, 0, 0);$ k4 K( H* C B+ {( `7 V
" u7 B# X+ L* y0 m- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
/ v8 O4 d, K2 T/ S' w! X9 d - if (myResponse == NXOpen::Selection::DialogResponsePick)
& o& F7 i" E, e' ?7 p; \/ | - {; l0 i' |6 u5 ~/ _; A; @
- // obtain the current default annotation plane where PMIs are placed on
: p, `" S* N2 s2 R0 A- A - NXOpen::Xform *xform1;% N: t- A3 Q6 x+ v: B( ~
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
/ `( x2 J# |+ t - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
* S. m( n+ A" A* r; ~4 d ` - NXOpen::Point3d ptDefaultPlane = xform1->Origin();1 J# [7 P( x7 l2 W
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
# X4 b) m. K3 |+ p; w' J9 o9 I - + s8 T9 Q( q- z
- // create the ray 'into the screen' at the selected cursor position/ H7 e; V( m1 R: f
- NXOpen::Matrix3x3 vmx = myView->Matrix();4 P5 g5 C5 [2 _. z9 S* q) K* Y
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);1 [, o9 h8 A7 t+ x
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
6 n( {, Q) t. N, i( p' S" P - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);6 G* b1 X5 s: y
- lineRay->SetName("Ray");" h5 E) M0 l# Y+ d) i
5 X( H! L1 g$ {4 b" e; |- // create the plane from the view to intersect with the ray* m5 x4 {- X' X
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);+ A4 k' N0 e ]4 }& K
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);2 b& ?$ J" c8 I+ i0 P6 k
- planeView->SetName("ViewPlane");
4 F: y% R4 h4 O# M - 2 u7 f/ ?9 y0 {3 o# P
- // now create the intersection point: n) s2 \/ G2 M( V2 O3 n
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
+ i4 S, p N. j7 u% q$ l - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
5 U; s! c3 @) B. j0 x8 n% U6 U - pntInterSect->SeTColor(10);
! c- \& h' t, Z e# H" a/ i) A5 Q - pntInterSect->SetName("Intersection");8 w3 v" z' z! |+ f
, Y$ o0 a. v+ l% R$ `8 t7 u' i& u+ z- pos = pntInterSect->Coordinates(); u- H. y3 N' f) E5 j; @. ]2 T
- print("\nPMI Position:", pos);9 M8 Z4 Y+ o- L% w+ f1 x
0 S I3 }* X! | @) S- // clean up - comment to see intermediate objects4 r- E% R& T* o
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
, n( R' `# R& h Z3 z8 B& { - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);# s6 y2 I& u& e# w# M$ b4 C0 V
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
; x; V+ ]" g1 H6 I* N8 ^4 Z - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);7 v( p; z; ~# j2 [4 M6 G; A
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
& r( `3 |* i: e - m_session->DeleteUndoMark(markDel, NULL);
; ? ~9 q( X8 [6 D4 G - 8 m9 {( U8 y: |, `6 Y( ~
- return true;
, t7 a9 W5 I' K0 m: S0 ? - }7 \- o5 J* ]/ r8 m s' G2 a2 L$ J% G
" @. L" X6 ~8 W0 r& i- return false;2 t; x# a( p4 c( G
- }
复制代码
$ ?- o& u1 H& | e, d2 u. E+ v' A# R0 G3 y, Z9 @$ T* j0 Y
|
|