|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 g9 m+ Y9 I( W; k. T7 y7 w I9 c
, S! u8 O0 J/ `- J* L/ U如何获取选择点映射到视图空间中?源码分享
9 u# u$ ~5 K3 |3 ]8 Z1 b% D% O0 }7 V* x; y% Z3 C1 D% u- o; c5 z
- //------------------------------------------------------------------------------
: i# k4 u% `3 X: M - // Select Screen Position and map to Modeling View Plane* u" Y% ]5 Z4 \- _
- //------------------------------------------------------------------------------
" y3 @# Q. u3 l" }/ C - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)% R# z1 v3 u% U9 U0 y e
- {
" G! c- m8 A6 { - NXOpen::View* myView = NULL;9 z% B. g* M2 P
- NXOpen::Point3d myCursor(0, 0, 0);
4 O- ` `) q" }6 y& J* r/ ?3 {
+ W: D2 x! C5 h$ w8 N) l- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
! \' V" j& N9 v, c/ S - if (myResponse == NXOpen::Selection::DialogResponsePick)+ n% @7 ?) t! T
- {; r8 ^; g; L* O& N# j# G/ R3 |; Z
- // obtain the current default annotation plane where PMIs are placed on1 }1 w+ R" N7 I; A4 }3 W0 T
- NXOpen::Xform *xform1;
7 ~3 |$ ] j2 B: k* W3 a9 D G - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);- n9 X8 K! \8 X" G# B# U9 ]
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
3 Y# X @" ~3 l w - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
u ?$ H/ c2 _' }6 _9 l5 X L, C - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 \. y/ n9 \/ ]# \7 `& U. D8 [4 G
- . @ X$ c4 [7 n5 a, G+ f; @
- // create the ray 'into the screen' at the selected cursor position ` V: ?' G Q9 F* l
- NXOpen::Matrix3x3 vmx = myView->Matrix();
% s4 Z, y3 h1 j' Y/ ` - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);2 g6 d& j) {8 x; T* j' \! a& D
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
2 q1 b7 J s+ W5 e - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# Y) m; [$ A# e# N( j1 Q+ U
- lineRay->SetName("Ray");
! A+ u L% c5 d7 i" E" q - 5 r9 E( m' n5 H( }0 M
- // create the plane from the view to intersect with the ray
0 ~' a& O# m! L/ [% P' X2 o8 W - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);! I( Y& y' s8 h) R
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
& @3 B4 c9 h y - planeView->SetName("ViewPlane");
. @' E, A" d) ]6 t& h5 W& I
! H" `0 U8 k/ L- // now create the intersection point
( i( e- m4 o& Q: A& F - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);" ?/ t0 p( ]! H6 m4 t
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, Q' @6 T# Y+ O. ^5 O2 ~% f
- pntInterSect->SeTColor(10);
5 r1 G. Q) h. I0 Z6 k- {" b - pntInterSect->SetName("Intersection");
6 T z" r N" @( r; T! j - 1 d0 ]8 o- t. s) F' u* S; N
- pos = pntInterSect->Coordinates();
' v' w" ~% T/ v+ \2 P8 z - print("\nPMI Position:", pos);
, `6 `# R! s6 | ^) Q' `0 ~! I# M - 0 m* j5 J" s/ Z, v
- // clean up - comment to see intermediate objects
, Y/ P, O. K& _8 t. p - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# W, E! @7 x1 b3 G8 \# O
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
; [% d q3 `# v5 r( O - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);* L6 w- H* @, n' U7 M
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);% a/ `2 Z9 b; o# K1 n
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);5 J9 U, x3 ~5 `& {" r: Y; L$ C+ m
- m_session->DeleteUndoMark(markDel, NULL);' j2 U, {( p1 D0 p2 V
- 7 q$ E, q% q7 ]) K9 d) U
- return true;/ K; R% ]; X2 V7 Y/ P; C v' k- p
- }
# m- y$ A9 U, ?' G% d - ) s" f" F; ]- r3 \9 _1 G
- return false;
2 ], Y7 M. F' D' U5 F) U1 A - }
复制代码 % ~: Z% q* A: G" V7 J
. \) v) L; g. c3 Q7 c |
|