|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# P' V6 ]; b* d4 j( W6 y
! X( \ u4 h& H3 S如何获取选择点映射到视图空间中?源码分享
2 O' y2 ]" ^2 F4 }! C4 j. A, t4 s
- //------------------------------------------------------------------------------
: j2 z% g: X1 t) A: w - // Select Screen Position and map to Modeling View Plane
) x( F" R! S' O$ V& V+ h - //------------------------------------------------------------------------------; R8 x5 O- e. [; } }( ]
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
0 a1 Q* d% w2 q9 a4 K5 r# r - {# I. D0 D/ Z2 I% |- G) K: Y
- NXOpen::View* myView = NULL;' H3 R$ g: h' [. B8 R7 p- }1 v+ p( ~
- NXOpen::Point3d myCursor(0, 0, 0);: b" x1 d3 K* v/ u
- : A0 J/ ^- N* o" d& R
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
( w* C9 g9 N* _1 w& V& X2 { - if (myResponse == NXOpen::Selection::DialogResponsePick)
- K8 ?. ]- `, C& r - {
0 o" e! A$ _& l2 _- q - // obtain the current default annotation plane where PMIs are placed on
7 ?! x! ^0 t: z% b! e& a: V- w - NXOpen::Xform *xform1;# k& x" Y) D# O" @2 S
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);6 Q i* |, h9 O4 h, H
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
1 L f3 C1 n- m5 b! e. E6 y: Y - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
) B n# P8 M% s - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
% v" _9 t4 V8 v/ N) X' Q& [4 F
! j; F4 f- {" D% X. g- // create the ray 'into the screen' at the selected cursor position7 u1 }$ v/ ]. w) |
- NXOpen::Matrix3x3 vmx = myView->Matrix();4 c* j8 h% i5 z4 P
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
6 Y" n5 E) z% M! W. P - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
2 E0 C, c2 m/ |: a, g - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
) D9 M3 h4 s9 g! O- K9 ?8 _/ f" G - lineRay->SetName("Ray");) q8 o0 V' a# W% R* U* u+ `
- ! A' N4 i3 _% Y8 k
- // create the plane from the view to intersect with the ray0 I, Z( p* n9 D* `8 W/ y; i
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);4 l& N# r. u+ {# L0 e3 E- A5 S% y
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible); N; X6 r/ B2 k! H2 X0 k" ~# r
- planeView->SetName("ViewPlane");- i; v/ w5 w3 i( L
+ P4 |7 Y$ x) I' u' u: e- // now create the intersection point* {! X! e# i1 N! N
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);% D* F1 J) N- A! T5 M
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
3 H( ]" _; y4 ~9 N2 }% P Y5 x - pntInterSect->SeTColor(10);
* Y' t3 F; V$ i& X8 D3 u T" N% c - pntInterSect->SetName("Intersection");# L1 c9 \% Y8 T7 u7 P
! g& @$ [3 S: x/ P- pos = pntInterSect->Coordinates();
) j. f, O6 j1 o* J& [+ J9 W' r' S; l - print("\nPMI Position:", pos);
& g* y- ~0 u0 f* r8 n: \+ R+ O - * w) [3 _3 I, w+ v! _' [
- // clean up - comment to see intermediate objects
F6 x/ B6 z* x# J4 T3 V - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
* Y0 G, q7 H/ d4 j% d4 o3 t - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);9 v O; g2 m! M( R' V
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);; x, V; U) H1 s5 L3 v
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
' t6 r( I8 d- Z, z2 Y- F - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
2 S; m! q) O& s/ _ - m_session->DeleteUndoMark(markDel, NULL);
, P7 M( a6 F3 N9 p5 e2 W+ e
: U& \% S6 J5 e* `+ r* K- return true;; W6 I, \3 U4 v0 K) X8 G
- }
! ~7 r& ^" {4 f, o0 N$ u" l+ V - : Q+ |1 D9 [- h8 u# A1 ^3 _
- return false;, z& Q4 |( u8 i- R0 i$ ?: D6 P( Q/ V
- }
复制代码 5 Q9 l* e$ X7 m# b$ o& [
! t5 ` i, [9 B% ~2 t- | |
|