|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' e) x; P/ E, t$ j. t/ a( d/ g! V& `: d/ a- c# [' K- m% g
如何获取选择点映射到视图空间中?源码分享1 A5 q$ \& Y5 l! ^2 k" c
" I' l, a$ {0 y1 W
- //------------------------------------------------------------------------------1 ], y8 [& A3 M& ~! I
- // Select Screen Position and map to Modeling View Plane+ y. y/ K7 N% l) V: G! l
- //------------------------------------------------------------------------------
5 l5 @& F, X+ \0 b9 k) \0 f5 D - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)8 M" O% u# Y" }
- {
, @: R7 t: i% }: Z* [" B - NXOpen::View* myView = NULL;* |+ s- c7 Q% R) O
- NXOpen::Point3d myCursor(0, 0, 0);
' g# K* {! ~# p0 V, G- J
. |1 W4 w: i8 D2 B5 E. S- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
+ F9 c! ^2 w$ P% d! K - if (myResponse == NXOpen::Selection::DialogResponsePick)" Y6 C9 c9 L% z, K. \2 |
- {; |. d Z0 @ m1 ^( \* f: d
- // obtain the current default annotation plane where PMIs are placed on
7 M3 W3 q3 m( b3 W - NXOpen::Xform *xform1;
4 I& S1 i$ N8 t' H3 f2 Q) x - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
* j0 V. h( s6 M: o$ j( E1 ` - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
; x1 i- m" Z, `0 ]6 ~0 `2 ^* g - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
+ P+ j7 Y, G& a$ q. ?! P. S1 ~ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);2 J% k# l6 |- G5 h8 U
- - K8 i+ u7 H' n2 R" r: \
- // create the ray 'into the screen' at the selected cursor position
- c! M2 ]$ H! H# x4 @! z; ?! P - NXOpen::Matrix3x3 vmx = myView->Matrix();
8 }! y5 X* U' j0 O! ~ - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);* ^0 D& W8 [3 h1 |% }
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);5 e5 h6 Q; |' B) A- R# L8 `
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);5 [3 @' Q2 I7 Q7 t3 p
- lineRay->SetName("Ray");1 p( w; z9 G& o# S6 q. `
) i7 Z' h3 ?6 o- // create the plane from the view to intersect with the ray* u! w: {7 g; r+ G# `
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
- T2 ^# D5 K- C - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
- k) r3 ~ E: a) G2 `% G - planeView->SetName("ViewPlane");
$ {( B- a# h, t1 \' X5 Y J! I
* [2 P4 Z% v# Q) y7 m" j3 C+ {5 h3 e- // now create the intersection point
, ?) ] ?, i' L+ _2 k - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
' F& T6 i# l- k8 J - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% N0 A$ {, T1 m5 i8 d* u
- pntInterSect->SeTColor(10);
, x T' _" o- F% l) y8 U - pntInterSect->SetName("Intersection");' U* v1 C. s6 k% }# b0 u# d
) ]1 U2 H) e% l( f' x- pos = pntInterSect->Coordinates();
& N0 g9 _8 c( z - print("\nPMI Position:", pos);
- A( b5 K- Z6 p) d$ w+ d6 e - * |6 s$ K) F' ^( l+ \5 D' o
- // clean up - comment to see intermediate objects
' I) L5 F3 K( o9 W9 x - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");/ U/ W& y1 M+ h. H. Q3 o
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
6 n: ^3 X7 n8 g* V - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);" Y7 a! \( O9 z" O
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
& r1 p) D( K5 l2 n1 r# B* r - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
: P! V' u+ y3 j - m_session->DeleteUndoMark(markDel, NULL);
+ S. f4 h }. N% X% | - + G# `' ~/ _0 N" L2 h$ ~
- return true;6 N5 v x) D3 t
- }3 q6 q9 Q: r/ X: H* I
: d+ h- d* w G9 C& j0 L8 w* N5 W! i- return false; o$ n" z6 r# ?# p2 X. w/ ^
- }
复制代码
( ~5 ?" p1 E4 \( W
) ]5 m! e6 f4 \8 s& {, f. d# w |
|