|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- A, o3 ?7 ]# r2 M3 W, f3 S1 Q
& s" [! n* {$ T+ E+ P; D3 S
如何获取选择点映射到视图空间中?源码分享
, Q/ |( l* {; a6 _5 [3 \* i$ R9 b5 S) D: c7 {
- //------------------------------------------------------------------------------
; ] E+ E p% T7 H% \( ~) X& J3 ^ - // Select Screen Position and map to Modeling View Plane
5 b6 O/ t) {! T% j - //------------------------------------------------------------------------------6 N! K" C" y+ f
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
# G" D, y, d$ L6 m9 V: ] - {
4 R4 M! |6 m% S( A6 \/ | - NXOpen::View* myView = NULL;
5 ], J9 E4 w5 }. f9 U, t0 j - NXOpen::Point3d myCursor(0, 0, 0);9 ^0 R/ W* W! A! Z' b2 w- E2 k
* a# c% b& |5 ?+ k8 ~. G `- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);$ |% w* I- ~6 G- R: U# E
- if (myResponse == NXOpen::Selection::DialogResponsePick)
0 J9 A9 ~. r' c' u$ [1 t! P# f; [* [ - {
+ Y1 m, B& l* P q - // obtain the current default annotation plane where PMIs are placed on+ |; G2 ?% \* w# V/ b o
- NXOpen::Xform *xform1;& {- x' u/ d$ x( {. h* ~7 J
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);/ L+ I" J+ K; |8 k0 a3 {: C
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
; g/ t6 ?! J: {' b - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
4 ` _2 o, X0 \% G - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
a& G& g, s1 O& K
/ H& A% r! M8 R- // create the ray 'into the screen' at the selected cursor position
+ w, }( ~) F/ R4 s/ j - NXOpen::Matrix3x3 vmx = myView->Matrix();& E$ _ U; x9 [+ P. V
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
! t ` G1 s7 ^' a - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);% ^% c' E6 d$ E) S+ G7 c: ], \+ Q* I$ D
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);7 k5 `! v# x! l& k
- lineRay->SetName("Ray");5 R: x3 ]/ u6 ~% X' y; z+ ^
- 5 h" i( |: {! A' O
- // create the plane from the view to intersect with the ray: p) y$ q6 G& R! H# Z% u) `% q- y
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
0 ^- @9 s) S- Z @" z - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 y7 J# ^$ ~0 d( D% {
- planeView->SetName("ViewPlane");& [8 C, s: o, ?0 P8 H8 H. u/ x
; R1 |6 k1 V' p9 q' ~7 k. \: r- // now create the intersection point
8 L* }# v0 R9 y8 h" S# a& h' A3 F - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ e" `2 \& F- |3 C/ r
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);& x h s7 h; ~- y4 ~3 \
- pntInterSect->SeTColor(10);& `( l9 S: [1 ^* n3 o
- pntInterSect->SetName("Intersection");& F2 l; b: l5 M. m% R& W
- 7 y2 q8 q; C4 R7 A2 K3 n$ k
- pos = pntInterSect->Coordinates();
! Y, I) ]' M0 I; c6 I, L - print("\nPMI Position:", pos);7 c% u4 _* c1 E3 I& b3 \! P
- 9 ^9 z1 B1 } n0 K2 M, O
- // clean up - comment to see intermediate objects
* ~5 e* J/ p: \' w3 R4 P* s - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
! r) D" F& R7 s7 n4 [ - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
& P: h @# B; f6 e( G, p - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
! D9 ?& B' d& o0 l; l - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);1 {: C" n" t" W8 g% k
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
+ P3 a5 `- r z) f$ N - m_session->DeleteUndoMark(markDel, NULL);
6 `* M) ]' f, I3 z( ` - * h" x1 E5 f& a+ c1 p; H
- return true;' S, T3 h& i+ B% l5 J
- }
1 G' V& T/ r$ m5 H# W9 { - ( i; y% e0 _4 {9 J0 H, p
- return false;3 Z) b x- B) O7 Q) t3 w+ u, x
- }
复制代码 2 [* L7 I& ^+ O8 ]
+ s% s4 e' F8 U7 E X; K/ a6 f |
|