|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
! m5 g/ \+ f3 f
r6 P7 o J) ?, a9 x如何获取选择点映射到视图空间中?源码分享
& W; ^' f* t' E1 c% B0 j) W
6 V4 k( o3 f( f0 y% Z- //------------------------------------------------------------------------------1 x3 e) {. B% K3 x+ y
- // Select Screen Position and map to Modeling View Plane
; P0 m. x) m% r1 N) E7 R% ? - //------------------------------------------------------------------------------; V8 a- K: H6 w
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
5 c& M) b1 C0 o: x7 u - {
- P4 e; f* ~8 }7 g& Q - NXOpen::View* myView = NULL; g6 z: ^9 ? o
- NXOpen::Point3d myCursor(0, 0, 0);" L3 n3 f+ J' z; T
3 Z% A. |# M1 J- u4 W- g- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);8 |6 Q* M2 `, ?3 ~% e
- if (myResponse == NXOpen::Selection::DialogResponsePick) q$ V" J! h4 V
- {* L% y2 x( t- }8 k! f+ \, e
- // obtain the current default annotation plane where PMIs are placed on+ b$ \& l' s( s
- NXOpen::Xform *xform1;
0 h4 c# a6 t8 ~+ Q8 i9 I; O: E - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);, r! b5 Q7 b# g+ Y& M+ x
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
~5 Y3 n0 ~/ c& o1 S, L - NXOpen::Point3d ptDefaultPlane = xform1->Origin();3 y: P& ^ ]7 R
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
/ v6 e" G [4 h - 3 G/ f0 }, R( F3 |% T H
- // create the ray 'into the screen' at the selected cursor position( G: q, Y% v4 j/ Z8 {, B
- NXOpen::Matrix3x3 vmx = myView->Matrix();% o/ m9 g- X/ f" _/ U
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);+ A* E% ]: g% r/ A6 D5 S9 s/ E
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
3 M. U7 L3 o" ?" ^# ` - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
* w/ d+ k" ? C4 h4 s' t8 J* f - lineRay->SetName("Ray");& ?- M7 V' _* x
- + A) _& i! S; } E) \# f
- // create the plane from the view to intersect with the ray
- Q3 R% W; G& Y! |/ [3 t) B. Q* F - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);4 W% x7 f. k2 Y {+ f& F6 u7 w( I
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 n4 G% C7 e( s: X* N# W
- planeView->SetName("ViewPlane");, U. e. m& y% v4 Z# [ |9 O
- 7 g$ h9 i9 k* R# z3 l' F7 J
- // now create the intersection point$ c$ b, q5 ^ \6 n6 F, R% L
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
% Y% R$ Z# G% V# S9 }7 C* r' k - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 k$ X' [' `# d. H) c- g
- pntInterSect->SeTColor(10);* Q0 m5 z. S. g* M: E8 a9 ]
- pntInterSect->SetName("Intersection");" S# B7 A% Q; t3 ]! k" H
2 J: U. i3 W U( n1 g! N- pos = pntInterSect->Coordinates();
R" F a! C1 | - print("\nPMI Position:", pos);
/ f1 B& {3 ?5 T; S, L8 W
" |- ?! H& y" `. _6 s! j- }- // clean up - comment to see intermediate objects4 T0 k( X o9 l) l. i# r1 X7 I
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");. o7 J7 c' x7 @
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
9 N. Q% h1 O2 o" p7 V# K - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) N; l. T/ q% p, Q* z) B
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);. W' ?, T$ G+ m# X& \8 Q
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);( `) K+ b) B0 y1 s( `
- m_session->DeleteUndoMark(markDel, NULL);
! J k6 r; A2 D9 ~0 ?+ d
! O; d7 V* ?5 N$ F/ Z4 l- return true;
7 E$ P8 b, \5 B- i7 l - }
1 j9 R/ Y( I0 k, e' o% t. n - 6 g& u" f7 m! e, h
- return false;
2 w: ?9 [) J; h - }
复制代码
+ t2 O5 h6 { c0 v6 l
$ |% B- A4 ^1 S4 t) j |
|