|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* Y7 k# t* s' z1 M
8 |8 G. P G* t, W: T
如何获取选择点映射到视图空间中?源码分享
8 [/ w, c5 }! a* v" X! D5 ]3 ^" U; |1 ~/ X& C8 w0 Q
- //------------------------------------------------------------------------------
# f4 Y: K1 i& y! P% z - // Select Screen Position and map to Modeling View Plane
. ~, x$ z2 O# {& f - //------------------------------------------------------------------------------# C+ i2 d$ N0 z0 g1 o% ]
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
; @) R$ i9 X/ W$ c - {
* a% x3 f( H8 r - NXOpen::View* myView = NULL;6 r- o( l9 Q `% s/ M
- NXOpen::Point3d myCursor(0, 0, 0);
7 }/ B; i- ]4 F! `; ^) q6 ^- X, B& G5 @
) Z" P t% @( c8 |- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
i6 ~: r* X* M# u2 [, e) M - if (myResponse == NXOpen::Selection::DialogResponsePick)
) r- l' U1 i9 f q# E - {4 S& o% s# T& N9 T
- // obtain the current default annotation plane where PMIs are placed on
. |4 k( S n6 d7 \5 Z9 e' H0 t - NXOpen::Xform *xform1;. c: w* }7 U X* t* i6 v9 i6 \# ?7 u
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);& n2 x3 T9 k7 g: y U& s
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();' R3 F$ X f" ^8 H, N& k) @
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
, v6 ~9 y' b5 e; H - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
( A7 }% L- a9 X( w- Q
- g2 y: R+ [1 D. {/ n' f$ K- // create the ray 'into the screen' at the selected cursor position
& ?. z) W" I$ B' \$ w! W - NXOpen::Matrix3x3 vmx = myView->Matrix();
# ~9 g8 e% j6 L - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
' H. K7 s5 _5 Y/ N d' | - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);$ h. y" e- S$ p! s: q
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2); m/ |& s% P0 Y( C: X, ~* k
- lineRay->SetName("Ray");
) I- H! i$ I, h: |) q8 F! S
# J H T# f$ q7 S+ ?3 }7 W4 q- // create the plane from the view to intersect with the ray
1 ]6 K7 o, K# w0 \ - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);2 |: L5 q, ~* u
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
! ^2 M1 M9 D q4 B - planeView->SetName("ViewPlane");
" ^5 e0 @* @, R5 J7 `( P - / k, C* p) [) V- I. r k' l4 S
- // now create the intersection point
- V% ~% X! a3 s- P - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);9 L9 w, F0 J$ F" F, I
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 U: w% w1 O/ i* \* {
- pntInterSect->SeTColor(10);
% B8 ~/ M( z4 j1 Z - pntInterSect->SetName("Intersection");
5 N {( _) |# M4 ]3 r - 4 z z7 x% U7 i% g8 X* Y# [
- pos = pntInterSect->Coordinates();! a) z& b7 V" W( f0 {! p
- print("\nPMI Position:", pos);7 W# Z8 {; m/ H
- 5 M A# H. z5 b$ |4 r
- // clean up - comment to see intermediate objects, e; _% J: D" g' a* E9 [5 y- c5 j) Q0 J0 K
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");2 k, I1 l( h' v1 D+ o7 n
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
) z' b* s6 q' j- s5 d9 ~ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
# u( f4 n$ c2 b+ b, o - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);6 S" c6 S7 }$ d/ I( j1 B
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);* V% E: f& W0 m( T* t5 \. q
- m_session->DeleteUndoMark(markDel, NULL);
+ z6 k4 d! |. |% l: j - # \1 F$ N) G r5 X( M/ s
- return true;
. G: p$ C2 [2 y( R$ J - }, H! u8 @& A: p5 z$ W c9 D: n1 m6 z
/ F. `, j+ j! I% u |5 U- return false;7 {! b% u% l: `/ H* w9 j& a
- }
复制代码
+ q) k& c6 ?1 S( g$ x8 T
7 K6 c7 a7 m r- R! I7 Y* ~( e' F |
|