|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) [% i/ c5 ~* C) i8 |0 Z3 q3 y1 o! g/ ]! Y9 ]: S7 O7 ]: |" e
如何获取选择点映射到视图空间中?源码分享: Y- A8 y6 Z( D
+ h$ F6 U- O q/ H) s2 F. G) a- //------------------------------------------------------------------------------
/ R* d L5 M5 ?4 C; u9 F5 A - // Select Screen Position and map to Modeling View Plane
2 l9 q# Q I% J) m - //------------------------------------------------------------------------------
- l) W7 a& I- r2 m" r$ e- H - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)6 T( C4 Q0 Y, e A3 G5 j
- {
. ~( Y# Q7 b' o' o8 w0 V2 S - NXOpen::View* myView = NULL;
/ t- \' @6 s, G$ J3 ^) V0 ~ - NXOpen::Point3d myCursor(0, 0, 0);
! \9 @7 s. N R' i q+ ~
5 t6 n$ G$ G9 Q% r3 }- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
: H& ~, ?: `+ G - if (myResponse == NXOpen::Selection::DialogResponsePick)
+ b; N0 N/ i. |) g! U - {
% f6 K8 k9 q# u+ `, {+ Q6 e( ^ - // obtain the current default annotation plane where PMIs are placed on$ w8 ~( ~2 V& [8 v4 E, C( V
- NXOpen::Xform *xform1;2 {7 a6 s+ d! X7 U& M- e
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);8 G! }& B; I" C( C2 c
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
: f8 g7 l: W2 J2 p - NXOpen::Point3d ptDefaultPlane = xform1->Origin();* E! C ^% i1 a+ P- I
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);. J& z: }4 i. g% t" ~ l8 Y
- " J* d' Y, O5 Z+ T: ~4 A
- // create the ray 'into the screen' at the selected cursor position+ v& U- E# b( u3 z' c# W: [0 j
- NXOpen::Matrix3x3 vmx = myView->Matrix();
# G/ X0 {" ~, `! S - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);5 I( u& n! f6 J2 k6 H
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);$ P& L' T$ k; ?8 [7 `: k# o
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
F+ |, J" f$ |, T) i - lineRay->SetName("Ray");
5 L* N* V. Q( [# q - # o9 m/ E# c0 D1 U b" \2 Z; |# w
- // create the plane from the view to intersect with the ray' G! w* n% j1 M2 |& j1 Y6 k! s
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
/ t* x- h# m! G3 B, s# P6 F( [ - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; H; Y; a, o5 i/ f1 ?# i3 R
- planeView->SetName("ViewPlane");
; x0 @ B5 M, }, }7 P7 m& x% }; K
. v9 w! q( ~2 I) O% G6 _- // now create the intersection point
/ s! |* x4 s o$ b# Q p - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);8 Z" C4 L/ i2 x4 l7 N$ e
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; o3 v( L' b, {" a - pntInterSect->SeTColor(10);
, q% l4 C! F* O/ t) l+ [8 P' ? - pntInterSect->SetName("Intersection");' w0 r; T* i: b& @, Z3 e
# e; d8 E; |# D/ k6 `; q. i1 l- pos = pntInterSect->Coordinates();
1 d0 v& i- P4 q/ y& [; k! [ - print("\nPMI Position:", pos);
% p, Y/ M. b+ D1 D; ^# J
$ u& w* w4 Q) o$ N- // clean up - comment to see intermediate objects
, J2 V' v( |' }) F2 a* t - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
& w: i* O( M& @+ o - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
+ ]7 `( B& U2 S+ @; q: j; g& E! g% h - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);$ b4 k6 ^! ^' j
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);2 K f: q% W) ^7 P5 @7 [. {' B C+ {; J
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
) [ R* Q5 d2 R* i7 ? - m_session->DeleteUndoMark(markDel, NULL);, p5 y# O; _0 `- |3 o" B
( J$ }* ]* V% X3 C% {- t9 E, d- return true;* Q$ B( B5 z& H
- }
8 {$ F( \) G7 M* ?# o - 9 w! B- Y& i, z' A
- return false;7 g0 t8 ^+ Z$ |. r: v/ U" G
- }
复制代码
! @) o+ F0 ^4 j
4 d! m( D' B0 Q3 h |
|