|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 x' F* |2 J3 h+ k8 l. {# p- E( D1 P! B0 y) Q, h" D
如何获取选择点映射到视图空间中?源码分享- x. p( F' \& u, m2 r
5 ?. H0 ]% l( ^2 D' ~) X- //------------------------------------------------------------------------------9 r- o. p: t+ c' [0 ~: g
- // Select Screen Position and map to Modeling View Plane0 x- E- ]8 l8 J: [' m @
- //------------------------------------------------------------------------------
. A$ z1 R" t w6 `) m - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
! x6 y8 U/ _! |' y - {! ?( l( t& h3 `7 j& g
- NXOpen::View* myView = NULL;3 K; Q. D1 h* N% i( D7 R# e
- NXOpen::Point3d myCursor(0, 0, 0);" G% o' ?( A q1 w0 B
. U, h' q% J# R! Y- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);* @, e- B6 b- m2 c \) {
- if (myResponse == NXOpen::Selection::DialogResponsePick)5 C) ]( V7 y# i
- {$ r3 ?6 u R& i1 P
- // obtain the current default annotation plane where PMIs are placed on
# f/ |5 }: H& ~ - NXOpen::Xform *xform1;
3 D( n- g7 p; g" B x0 C+ G - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
: k4 h6 q. h( r7 f( ? - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();* x, E/ B8 {! \; _
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
5 s. D7 a8 g2 C6 u6 \ - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
4 D) ` j% d$ Q/ a2 O1 P! B2 q
+ F) k4 {, e8 j4 X# f: I) I# s- // create the ray 'into the screen' at the selected cursor position
" U1 u* m/ _; F) [5 e1 E K - NXOpen::Matrix3x3 vmx = myView->Matrix();
" M) m% R9 Y; L% C/ L - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);$ Z7 B8 t6 H$ ^# S9 A: n
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);2 R! V' C9 N Q% ?3 x/ }
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
+ P4 M8 w, s4 x) z2 S: ~" S; P& D+ ~ - lineRay->SetName("Ray");
8 n" z1 U# S d6 Z( I- t/ n - ! N0 k v( B9 D+ Y' a/ t" z
- // create the plane from the view to intersect with the ray& u% N" m: n- i; R
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
! W: }' k% ?! D( E. h' k - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; }* Z' u2 L; j& y& c3 C3 M - planeView->SetName("ViewPlane");
! O' Q$ a4 x( [% P6 _2 y - 7 q: i- L1 A; ^; A7 f# a% Y
- // now create the intersection point- l; R) p& ^( K5 c
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ x6 C9 o& b: h( N# a
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
. m7 d& r4 k2 b - pntInterSect->SeTColor(10);9 v) C V, ~3 {- i) b9 N
- pntInterSect->SetName("Intersection");
- c! \5 h: |3 R& p. Z6 F1 Q, P4 J - $ M% ~3 `. `, y3 I+ X v
- pos = pntInterSect->Coordinates();- P/ K! j) t6 h8 h( h) a# z1 T, G
- print("\nPMI Position:", pos);
2 d& w" t" }& e7 V8 q& H3 k4 V% @& u
7 ]# v1 G1 r, C; T. G) {- // clean up - comment to see intermediate objects
9 G# E% }7 ?, ]3 X; _2 V - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
- _" S3 _; |; _ x; X+ \ - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
/ _7 O4 w6 ^, z3 _) X5 O; N - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
8 }( X5 A5 L' Z; p, `: a4 M - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
& `5 b M/ w8 i - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel); e* y. I5 N1 f# d8 U H, K; `
- m_session->DeleteUndoMark(markDel, NULL);
. y% y* T9 E0 R% p- A - . z5 H) _ ?0 ]. A. Z
- return true;; ^; _( f- i' Z5 `$ G
- }/ ^! C6 H0 m& e3 k9 a% ]& L- n- w
- 9 P. h% l/ E U+ H! {
- return false;
+ e4 ^8 K" k4 q. N$ M - }
复制代码 : W' L/ B. L1 D2 s1 t. a) f/ n/ R9 ]( ^
: H! l3 a" }+ n0 I( e
|
|