|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 M; {: B O: U. r6 d! Y) q6 ?) }
# P+ p8 S2 ^+ I
如何获取选择点映射到视图空间中?源码分享& p+ o( h, K$ ~; Y
" K/ z, U5 p. a$ Q6 W
- //------------------------------------------------------------------------------* P8 n. r6 P/ S' p
- // Select Screen Position and map to Modeling View Plane* Q- |; E8 G1 o3 F
- //------------------------------------------------------------------------------1 e- K* \% E3 A; I/ \
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
% c" o, x5 z, ~5 c* g8 d) e5 z - {# c2 i+ f+ M2 v* f, A4 ?& X
- NXOpen::View* myView = NULL;
5 M$ P' b) d, F2 U6 d - NXOpen::Point3d myCursor(0, 0, 0);
* O/ ^3 ~! D9 Z6 v - ( ^& H' l- W' E% K9 {8 O
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);. {/ T* j" k8 B5 P
- if (myResponse == NXOpen::Selection::DialogResponsePick)* U: n$ a- n/ \4 l
- {
1 k0 z4 i' P5 e' \- w. _ - // obtain the current default annotation plane where PMIs are placed on2 O" p: S0 a3 A4 l
- NXOpen::Xform *xform1;
n9 t1 N8 {, p7 J: D6 g4 K - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);( H3 o5 }+ o( e, J: q& O
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();( e2 u8 B- H- `+ n7 Q: Q8 \
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
! d2 f. F- R6 x: Y& ?+ `3 x - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: q4 H; |: _3 y0 J0 O9 m
& ~2 `* O- U# ?& s" H1 v- // create the ray 'into the screen' at the selected cursor position
% @- y( A. @ ?) y5 m# x3 _ - NXOpen::Matrix3x3 vmx = myView->Matrix();, w6 s4 Z2 j7 ~$ F0 b+ G$ o
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);7 m3 \- L+ n0 R$ q2 `; V# C, Z
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
8 s9 P9 x# w/ P1 y% f - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
5 \" P7 J" E% W! H - lineRay->SetName("Ray");0 v& S; H* B* j
4 Z7 A4 `2 N! T3 y2 S- // create the plane from the view to intersect with the ray- D4 T8 q) G4 q) W, P
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
X% ^/ G$ [1 V" B* N5 @% ^4 l0 F- t3 D - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 P! K, t. J l/ h
- planeView->SetName("ViewPlane");6 p `9 X$ u# |" a
- 3 |: E" D& X6 E0 D+ l
- // now create the intersection point
& [" O2 n X7 e0 }# ^ - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& H' u2 \9 Y- |. C
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
6 s, O5 V4 A9 v# ^* {4 O& ^ - pntInterSect->SeTColor(10);; Q8 {( [, ^2 \$ ]7 R+ I! T$ p
- pntInterSect->SetName("Intersection");6 s; A$ E& t, l5 `# {/ z& w' M0 a' g
- + I! y% ?- G& ~+ [! \) y
- pos = pntInterSect->Coordinates();' n8 r/ M6 l) ^+ ]& g7 K
- print("\nPMI Position:", pos);3 u6 P: M. j5 `, V6 h0 `
- % l: `) |- Z0 s- P+ A
- // clean up - comment to see intermediate objects1 r; O1 F5 o; Y# H' j
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");/ a1 k0 [/ Q" \ }' ^! O; ~
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
. E, g9 E1 L" S# i& S) \: `, S - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
+ |$ V5 Z% n( H4 i" V' B4 \* t - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
" a; h. j/ v) J! S0 }" n: h3 L - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);: @# C% a7 ?6 Z2 Y1 R* j0 Z" k
- m_session->DeleteUndoMark(markDel, NULL);" A% {6 }/ A8 ?1 O
- . L) j- `$ R0 j( T# n
- return true;
& X! n& X+ N+ w* e' T - }4 C# f: o2 z* D6 f# o; V
) I5 E7 `& y2 L9 K' m6 Y6 `- return false;5 |4 y; D- r- U1 e3 M
- }
复制代码
5 k2 b# A9 k$ b" N( K
* d/ G! r- q; Q |
|