|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 l9 L5 M4 q) R" J" h5 Z8 \# W/ ~
5 l m. e" V8 x3 C% B$ q如何获取选择点映射到视图空间中?源码分享) C; g; B$ r6 f6 ]8 g) V4 G
7 f" J6 U& d' s( j2 ~) j- //------------------------------------------------------------------------------1 {$ U$ r' U3 @- W
- // Select Screen Position and map to Modeling View Plane0 ?$ @8 ?9 \& @/ V) d
- //------------------------------------------------------------------------------
: H% e) M0 S, [9 L f# @ - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)" |7 i7 |, }/ j* a: z3 |8 V, ?
- {
: L2 `6 M" A( F# P% J S, Y - NXOpen::View* myView = NULL;$ E( d( [" G- }& q
- NXOpen::Point3d myCursor(0, 0, 0);/ o0 C: s, c+ L" x! a
# T+ W/ l, M Z! |- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
4 d4 ?6 j8 G9 i - if (myResponse == NXOpen::Selection::DialogResponsePick), ^4 n2 x1 i: N1 n, T
- {
+ P; ~ M T; r - // obtain the current default annotation plane where PMIs are placed on% Y C0 ~8 u& q8 M2 z) k# b' k* j
- NXOpen::Xform *xform1; J6 i% A! u5 P4 x- G: m
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);" Q0 j4 a0 J- W3 [& h* }
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();% u0 D/ j- w+ Q7 V( {
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
5 ^9 e5 @' n6 X4 p: j" S; G - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);9 v( p/ |& u+ d/ K- H) i2 l7 i
% M- K! C; L1 `. U% A4 \+ ?+ z- // create the ray 'into the screen' at the selected cursor position
- R" _* J7 U2 ?2 p1 X - NXOpen::Matrix3x3 vmx = myView->Matrix(); ?$ L2 [& A# `+ A- l
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
4 X. C* G& m; B# u( a9 b C - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
$ H. Y. ^6 o4 W: O4 [- ]4 B - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
( {* {, [* g1 |8 K3 Q - lineRay->SetName("Ray");
+ D6 d6 W7 ? F. k, D* g - ( O2 K: B+ h0 V/ Z. \/ S
- // create the plane from the view to intersect with the ray' A* c; z; v( n! k# }# e
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
@& N" [* B# p# E. a - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 Q, y* T, {& o& }+ ~1 e% d$ P
- planeView->SetName("ViewPlane");
+ N; V' H) C1 T2 J
4 N8 {, F2 I% E& {# e- R6 m# }- // now create the intersection point/ D: @9 b9 k# f8 R( c/ M% _
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
! R- T5 p2 e! | - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
" G* U! ^. ]* v+ D# ] - pntInterSect->SeTColor(10);' `8 C6 d1 o& n: V# g
- pntInterSect->SetName("Intersection");
" \; s% U! y, _0 Z. m* ^
! \( ^6 O/ p# p8 F3 R- pos = pntInterSect->Coordinates();
- Y/ a# b* a0 ^) K - print("\nPMI Position:", pos);
0 }# ~) i5 G) }: @& z4 K* y/ J
: R# r0 c' W" [- // clean up - comment to see intermediate objects# G- q: c7 c8 x
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
. w8 s: O% s% D8 ^1 O y+ G - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);# ^8 p" E2 x$ {# K; ?9 f4 P
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
( b" _8 l4 H* E% b - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
3 r/ N; t) @! o# H% } - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
; p, Q! R' @: |# j$ o - m_session->DeleteUndoMark(markDel, NULL);
, z# `# }4 z, e8 x
( W- z. B& c& j6 Q6 h2 K0 g8 l% j2 p" h- return true;( D. ^" i. k! {
- }
; s$ m1 j/ w+ Z$ R3 E0 Q - * W& ^1 F/ ^9 N Q3 W5 _6 ]
- return false;
6 u7 C3 }6 B! A9 P# z+ A - }
复制代码 . u0 C8 n( S% [2 J {% c1 {
5 u9 d7 s7 _( B# ~
|
|