|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ a0 ]( [* r; j _# h( J
; F" k+ V5 H9 E+ b0 w如何获取选择点映射到视图空间中?源码分享1 f0 [6 `( z; X- a. F- M7 {
5 \& n4 Z, @% \ Q
- //------------------------------------------------------------------------------# W g* _4 V, J" `: C0 i
- // Select Screen Position and map to Modeling View Plane" O2 F4 A6 b: ]/ a! F" E
- //------------------------------------------------------------------------------
4 r% K: @6 @, c - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)5 T; z0 d1 Z0 Z$ |8 m
- {$ l5 x1 Y. x5 }$ k# b$ r( F
- NXOpen::View* myView = NULL;
- H! m( W' l) z } - NXOpen::Point3d myCursor(0, 0, 0);
! X8 A# R+ G4 U5 l" I0 A6 P
3 d0 e( e ^/ u* s2 r6 \- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);: G, C8 @+ d: u7 w
- if (myResponse == NXOpen::Selection::DialogResponsePick)4 m* D$ z3 A5 U9 x8 Z3 j* ~! q
- {% J7 ?, d T4 ^1 [
- // obtain the current default annotation plane where PMIs are placed on
7 d0 ^. Z& Z1 K4 c7 j/ z - NXOpen::Xform *xform1;
) ^9 E# T! F9 P. b - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);: X& G" \6 G8 E/ x1 R/ x4 i
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
& c$ H7 L1 F# g2 L; X! U' J - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
1 F+ e9 R) Z" K1 q( b1 ^/ h: Q - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 l4 ]+ m, y1 q/ n4 O& s0 u6 @; B
* s( a2 U3 _3 U$ i9 z- // create the ray 'into the screen' at the selected cursor position( j. O' Q+ Z3 D5 ]7 O) @: o* m
- NXOpen::Matrix3x3 vmx = myView->Matrix();+ C' O$ G/ ^! L8 N; |( F& {4 u3 `
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);! N: c" K n: ^; I
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
1 g4 Q% F9 r/ G/ X. m* q" [ - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);$ g9 O; S: c* w1 \ R& f- X
- lineRay->SetName("Ray");
- R$ H& O! k5 k1 z3 g! n - 8 s+ c; N9 A$ ~. h7 @
- // create the plane from the view to intersect with the ray* a! @$ q* v$ M, J; U
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);+ n- q7 P0 m9 I# I3 d" e
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible); O5 [$ `( I, e! \# g) b; B1 G3 @3 t
- planeView->SetName("ViewPlane");
2 G z1 o- |# S- K% X1 }
8 y9 L4 t3 F# G( q+ A0 T' |- // now create the intersection point
& Q U4 B) v" p; Y4 w3 o2 S - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
1 j' g2 r! Y9 [( F+ w( K, N' |$ x - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);7 d3 S0 D+ N. \1 B
- pntInterSect->SeTColor(10);: D( J- z# e9 d7 s; R
- pntInterSect->SetName("Intersection");
+ Z$ y0 N6 b7 Q5 @2 l( t! s
6 P% _$ d3 q! r, V7 J6 {- pos = pntInterSect->Coordinates();
( M- j) E2 v5 h% Z9 {$ p$ h3 J* Q - print("\nPMI Position:", pos);
; O. A- n' d4 t" _$ \+ j
. Z( o# P8 H- ^% L# i* _- // clean up - comment to see intermediate objects
4 P u9 u$ G$ j K% `* z - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");! O& [ S( [3 @7 s0 v3 e
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);4 _1 y% N0 W$ j! N1 b. Y0 t
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
# |# a p ]9 G2 A - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);3 V* K F t4 h2 R2 @6 i
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
% b2 p2 {$ Y0 A - m_session->DeleteUndoMark(markDel, NULL);
6 W& ~5 B6 v8 q- X) @0 { f - % T( U1 C6 J7 i. [, `. H, s
- return true;/ H6 g! U7 O7 t3 J+ {. e' p T
- }
" j. ?3 V' @) s( w& [3 E
0 p1 x! N0 ?: F% m- k& p- return false;
# Y5 A. ?# v9 @ - }
复制代码
' N4 f( Y2 |+ ~* c. [) I$ z
4 c# l( v9 M/ d; h |
|