|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 P$ h Y1 d# R( x1 j7 n
+ \2 G3 W, A6 @4 k' @
如何获取选择点映射到视图空间中?源码分享
% Z; E$ {: @* v* ], U9 a B8 Q. Y5 f& H% _ I; D' }, S
- //------------------------------------------------------------------------------
' r4 a4 n8 z9 m* T3 b h5 ^# C - // Select Screen Position and map to Modeling View Plane& U& S- i4 N4 K. V* G+ Z6 l
- //------------------------------------------------------------------------------
! Z. R- I3 B3 O: B( g - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
: ^$ O. s0 L0 n( I1 } - {
\2 S9 M8 v/ F& \: W - NXOpen::View* myView = NULL;
( e4 l7 \' A$ h# D ? - NXOpen::Point3d myCursor(0, 0, 0);
3 _8 o/ l6 E, a! |( V/ X - + m+ W5 A) a1 C5 F2 A( Z8 E! q0 N. N
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);& M2 R6 v( r8 Z
- if (myResponse == NXOpen::Selection::DialogResponsePick), v5 s. B% q" e. ^& ^/ ~2 r* I" ]( v
- {9 _ W; q: l: p- p! m
- // obtain the current default annotation plane where PMIs are placed on
( g6 _" L, }3 }+ j - NXOpen::Xform *xform1;4 z7 u, Y2 n7 Q5 z/ ]) }
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView); |2 b9 ?" m( m, n# L. t
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
# R. m! X0 O/ o: b! H$ w* s - NXOpen::Point3d ptDefaultPlane = xform1->Origin();2 ?9 e6 ]1 g2 {1 d6 s
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
" q7 |$ |/ y/ ?! Q' \0 z7 |0 R" }
( S6 H) r, J5 F3 i, e- // create the ray 'into the screen' at the selected cursor position
& e: E1 j: m( R* u6 B4 L - NXOpen::Matrix3x3 vmx = myView->Matrix();
7 u8 M5 N- L9 ?1 ^ - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000); R, x4 h, j& S, Z2 J
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
# r+ p9 T+ C( l9 E - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# G0 Z# v I" q3 V. w
- lineRay->SetName("Ray");7 Q3 c6 y6 m3 v+ c
+ W8 ]' p" n8 P- // create the plane from the view to intersect with the ray
p2 r! e+ D; A& @! W o% J& v - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
y8 s; I0 P' R& Q- l$ I" q/ {+ K; Y - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
! X) K+ P& z/ J) T) K2 N+ c - planeView->SetName("ViewPlane");
# f- N) x' u$ d0 v+ C5 A' e* x - 2 ^9 ?# U, Z4 ]) |; w
- // now create the intersection point
' k7 q; w0 X3 Y7 l/ q - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);/ }0 ]2 B' q# S3 w* l9 M+ @8 R' Z
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 h5 |; v- F2 O! o) k3 s4 l
- pntInterSect->SeTColor(10);
R& F8 f+ L7 V4 F% [; A$ J - pntInterSect->SetName("Intersection");
, P# e: \$ H5 F: q - 7 m! X- C2 B3 ?8 i; g
- pos = pntInterSect->Coordinates();
) ?) d ~" U# X( ~! E - print("\nPMI Position:", pos);* P& e) F6 l' ?0 e, ]* N' \9 i7 R. d
# x* j; C3 ]. Y I5 h# ?( B- // clean up - comment to see intermediate objects. q# Y( P: R2 J+ A2 L: R& h
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");2 Y* `; I" w- `* \2 O
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
+ u Z# i5 A: h" E" ^ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
5 `6 v# T8 z" V- w, _& W - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
" B2 n) o$ U/ G7 G - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
! A6 M! m# w+ P( y, C - m_session->DeleteUndoMark(markDel, NULL);! Y7 P1 c }; A
" ^ T, o0 ?) a! D7 N- return true;0 S9 c3 o. X: }; J3 o
- }
) p, k' t! H" W- {- ^7 P - 0 Y3 j1 Z% r* h: {& N/ r! N8 l
- return false;
}( S! k' o) x) f& j) V+ M$ ] - }
复制代码 5 E) g1 U7 Z0 Z. p+ w& {
2 w+ s k" Z8 ]: l4 d
|
|