|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; d3 J( u7 P/ T* K- R1 T
+ @1 J( A* M- h3 z- ]$ r6 o2 l如何获取选择点映射到视图空间中?源码分享
$ @9 ?! ?" o! o8 u$ L
4 O) L+ b3 k3 t9 |* o/ _: f- //------------------------------------------------------------------------------
! M8 _7 T# u: x4 j- h - // Select Screen Position and map to Modeling View Plane2 J' A6 X4 [* C: y
- //------------------------------------------------------------------------------
' t4 {, I/ {3 {* n3 }$ B* ` - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
5 B! \2 I- C: ~! F; T/ r - {
, B6 X5 x5 B, v" \ - NXOpen::View* myView = NULL;
. I- y$ q' J, D" S1 X7 v, Y6 E - NXOpen::Point3d myCursor(0, 0, 0);
$ q8 s& _$ _, j1 V - & Q( p' v G* [3 \% q
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);8 i# I7 i: c4 W# y4 H Z. L7 B7 D6 |
- if (myResponse == NXOpen::Selection::DialogResponsePick)# Q! y! U7 @) h- z1 H
- {
: z) @) O& P6 F0 h8 U$ _1 d - // obtain the current default annotation plane where PMIs are placed on
1 P! ?3 @ @- i4 Z3 @ - NXOpen::Xform *xform1;
: N) _5 v0 G! e" W6 b! Z. R - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
$ T9 r" L/ w" K# b - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
; w w6 J* F# E. i( L% g$ c - NXOpen::Point3d ptDefaultPlane = xform1->Origin();, _1 [( { c4 L. \
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
2 `( c7 I' [6 v& |$ t
. _8 E9 a1 A$ `: G9 Y7 ~3 q( [- // create the ray 'into the screen' at the selected cursor position
5 u# s/ A1 P4 c3 M8 `, w - NXOpen::Matrix3x3 vmx = myView->Matrix();
4 v& E' y% B- N; i( n% {3 m - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);7 }4 ?" u) H$ F' o
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
9 A9 L0 l" y4 f5 R9 X2 p - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
: I' A* @/ U9 Y1 t - lineRay->SetName("Ray");
/ ^; T+ s9 {1 `5 o1 e% H
7 U( z& J/ d5 y% \4 Z- // create the plane from the view to intersect with the ray
( R/ m% u7 y4 S- u - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
* }5 L1 p* i7 A% J1 ~& i+ T2 g - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 f1 j4 p$ ~ r" ]6 Q8 b, E
- planeView->SetName("ViewPlane");, G) @% r! ^( W1 t2 t
- ) b; S y. _& Q! [8 l. I
- // now create the intersection point' K9 Y7 C R4 K3 D5 D: N/ p( _
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
: }' t+ B! E* B" O: @# n- S9 v8 W - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 Y0 X& D/ n- V2 H/ m- S
- pntInterSect->SeTColor(10);
8 M! {0 m6 H1 x/ g - pntInterSect->SetName("Intersection");
* n3 {2 e- P2 D6 ^+ h - Z! X1 y. p: q
- pos = pntInterSect->Coordinates();2 q8 f; H/ p5 B+ g
- print("\nPMI Position:", pos);' ~ l. H) W9 q1 H! c4 N# B
2 F3 Q) T! G- @- // clean up - comment to see intermediate objects4 K, D8 p1 p) x3 ^ L6 C6 z
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
/ i, C9 j9 h; k - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
. c5 b( C2 f; A% G - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);9 T) {2 ~; M; I" K. h2 M
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
$ E0 z# e0 g* u( f; {$ l" ?3 B* N" F1 C - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);& J& I0 {6 e$ U4 d- y$ G/ i
- m_session->DeleteUndoMark(markDel, NULL);
/ z2 p% R9 Z% B+ `! ?4 _ \
4 e) U+ \/ f/ }3 ~5 i0 `' Z- return true;$ q: x$ y, C+ O+ T+ I% L. N% G
- }5 v; i! U! v- h* H
- 9 D5 R8 S% o, Y- a& }( ]3 P
- return false;
6 V9 L5 L: N+ C# c+ v - }
复制代码
* J( c0 J( a- L/ Y( W& L+ p7 h1 }; E$ k' A% v* V# V
|
|