|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- {; T/ ]4 J& M
4 L& T4 ?! j+ C7 |3 R8 I4 |如何获取选择点映射到视图空间中?源码分享
/ x0 K+ h/ x* M9 A3 p. D9 K' y2 v/ m) _) ~2 ?- Q2 V
- //------------------------------------------------------------------------------
9 a8 r) V8 A* G* z; j6 m - // Select Screen Position and map to Modeling View Plane
' p% E/ _) K/ S O' M - //------------------------------------------------------------------------------3 R( ^" l S2 Y+ l% u- s/ E3 Z; W
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
' z& H/ q# O1 h- W - {( E2 r5 Z9 z; c$ h' S! W) z) i
- NXOpen::View* myView = NULL;7 p/ {0 W4 x& g2 r: O- ?+ k) ^" E
- NXOpen::Point3d myCursor(0, 0, 0);
" x7 U- \# X: L: B6 u: I' D+ _) F - \0 e- E9 Q( N' M6 l3 N
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
5 }2 u+ ?9 c! f e9 u: e - if (myResponse == NXOpen::Selection::DialogResponsePick)/ Y v1 x z+ u5 ^
- {
8 m, _* _3 x3 Y+ o3 M - // obtain the current default annotation plane where PMIs are placed on
, `7 I& W- p1 j- e) ^ - NXOpen::Xform *xform1;
" a2 A$ T" }6 O G) y - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
# ?1 {- s8 A+ G: x7 ]& B2 l% T - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
% t2 C' u) Z! t' R - NXOpen::Point3d ptDefaultPlane = xform1->Origin();( Q. G9 P# Y. G9 B2 Q- j; z
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);* j+ x8 ]' X) U! h: b
- ) }5 E/ P( ~4 e: `" y9 g! }
- // create the ray 'into the screen' at the selected cursor position2 @1 |1 l r7 [( | `! r0 u
- NXOpen::Matrix3x3 vmx = myView->Matrix();
$ F% g7 z* p9 U. w) f% y - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);' K4 |" r u8 u7 Y" ~6 j
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);# J' M1 P6 j) J3 i1 J" S
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
! D! d! y$ X$ P2 s( u - lineRay->SetName("Ray");
" ?: ^7 O* m( y. E- |6 K: h' E - " k" p: j" G, a0 p
- // create the plane from the view to intersect with the ray
! s. [, t" U9 I7 B0 n2 v! A - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);. w0 F& W& q+ C+ j3 u
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);8 c. H: q6 }! ]& D: n2 h
- planeView->SetName("ViewPlane");
4 j7 z3 {! [0 ?: m
8 l& z z2 \7 h9 f \' h# {- // now create the intersection point
" r& G' \" N0 m' c - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);2 V% b& Z l- {6 O2 s8 R
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
' ?. |: @9 M* u) A: i - pntInterSect->SeTColor(10);
( X1 Y3 H* _" E+ O1 ~3 a& [1 N - pntInterSect->SetName("Intersection");" N: ^2 s0 h* o8 L
- 7 K" c ^1 a* \' I
- pos = pntInterSect->Coordinates();$ a! E6 B2 a" D* k4 q1 q) J
- print("\nPMI Position:", pos);8 b: ^- H: T" d' i1 ~( f
- 7 v4 w$ V6 w( q+ @8 c' r1 o
- // clean up - comment to see intermediate objects
" {, u( c& O" H( k - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
4 `! [2 _2 k5 C5 q" g - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);8 @ B' [: i3 x" _) g
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);1 Z0 J/ p' J- M% l" t0 E5 B/ m
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);, z) X% J* b) g/ T
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
! Z0 Q- k7 b& j9 |+ E& h. i - m_session->DeleteUndoMark(markDel, NULL);% E. B. U& R2 R2 @7 ]$ ]$ h
1 j" S: d8 Z/ I2 l2 u- return true;7 S6 @ D$ |9 f$ e$ q5 i
- }% C3 \. ]9 O v O8 q$ f
( g- l$ o" n* c% T6 y- return false;/ L. r: O3 l; x3 q
- }
复制代码
6 b! n8 p5 }( |6 {0 Z! f q- E% ?: R: a8 p
|
|