|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% f. P) L* U: L& W
/ l/ u# [0 O8 R2 [5 l9 O6 d如何获取选择点映射到视图空间中?源码分享% Y! e' J5 C) T. u0 l: M
+ ]6 k+ Q: f! t6 s0 n
- //------------------------------------------------------------------------------
4 I) f5 @! f9 ]6 s% U - // Select Screen Position and map to Modeling View Plane
5 ~6 r/ z# v3 n+ M( i - //------------------------------------------------------------------------------
" v" H4 l5 `. I - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos), R" r# ]" \2 `
- {; R7 j/ T3 {1 K- }/ S
- NXOpen::View* myView = NULL;9 e7 Y8 t7 A5 s* k, O
- NXOpen::Point3d myCursor(0, 0, 0);
* x% W' y& Y' X5 X0 `) f; C - 9 T. \$ q9 h1 A$ n
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);! U" _2 q( E5 s+ U6 x
- if (myResponse == NXOpen::Selection::DialogResponsePick)
7 ?' B7 B5 o+ s( L - {: f1 q+ F) o6 D: s: a: I
- // obtain the current default annotation plane where PMIs are placed on: ~4 ~7 S, F# Q# e8 m6 P
- NXOpen::Xform *xform1;
7 C# Y# _7 R- i# J6 ] - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);) i& ^7 B+ C9 o& c) F/ c2 S
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();6 [( U. a: o# g& l
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();9 I3 z }* \, r* d9 N
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: Y" a9 t$ l1 e( I: c5 U5 Z
/ V) Y' u- t5 k8 c% p0 b' Q- // create the ray 'into the screen' at the selected cursor position. j: i7 y M- r6 r+ _
- NXOpen::Matrix3x3 vmx = myView->Matrix();4 c9 K n# r y5 U) a
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);. D. A! A# o( e5 G1 h# `
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);* W2 E! P( O N9 Z; ]' H5 u& |
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);7 B+ o7 i7 \6 Y9 r; A- e% {& j/ Z
- lineRay->SetName("Ray");
`+ k# b, J8 p7 G2 Q* Z3 Q2 N& g
+ O6 J! O0 W+ Z V2 }" O- // create the plane from the view to intersect with the ray/ |/ Z/ k( U0 F! d( E: D
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
) d! h) J2 j! n - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 D% {# @- V8 [* R
- planeView->SetName("ViewPlane");
3 u" n6 d+ l4 S& K - $ G0 h1 [( |5 d# {8 O' q4 Y
- // now create the intersection point
+ ^) ]4 @3 f' l1 D: @ D! m; n8 Z - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
, M; W0 E$ @7 A# E4 Z - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* c$ K* C+ s2 n' q& {
- pntInterSect->SeTColor(10);
. h6 A' j% D& | - pntInterSect->SetName("Intersection");
* ?0 V6 x5 {% D - 0 R7 v1 O. H0 ?
- pos = pntInterSect->Coordinates();0 X$ X: `$ j4 E! b5 w4 B+ D2 @
- print("\nPMI Position:", pos);
7 f @1 q$ L- S0 N - & j+ p5 P' ~- f7 F! o" a3 ]
- // clean up - comment to see intermediate objects7 E! K0 g- E0 }; v6 {. a$ O4 I
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" k5 |0 \/ ~/ O6 B4 g4 L3 d: h$ V
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
0 z4 p( `( _* u" t5 R - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);2 q) q' ^( v' P+ h. V2 P9 n: z+ k
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
4 a" |5 Z, k$ |+ Z2 P5 C- s - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);; G% j! N2 U% v$ m1 y
- m_session->DeleteUndoMark(markDel, NULL);
5 x: [* G/ V3 N. h
2 T' j% L5 Z" z3 x7 p8 J- l% x- return true;6 L% e5 ~& S+ Y
- }2 ~6 F; J( X( m e: L" G
& T2 L6 N c/ O+ d( n- return false;/ ^5 T, ]! e4 K" x- N
- }
复制代码 9 S8 N" Q' m3 \3 [+ j. I* s
( y1 W" ?0 X0 J* u# S' e# d+ A+ N
|
|