|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, g0 r9 U" G9 a- {! ^
( d1 C. q% j( b, m7 r如何获取选择点映射到视图空间中?源码分享1 \* N+ j1 F! |, k( |5 O
4 y2 ]' f6 E' {
- //------------------------------------------------------------------------------1 q. s& |. E4 @1 }& Z0 v
- // Select Screen Position and map to Modeling View Plane
( V5 Y+ Y+ J$ F+ Y) S: S3 s( E( P5 p - //------------------------------------------------------------------------------- Z, {$ ]3 Z# T$ N3 S: W+ r7 ~
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
6 ?/ r4 t. y% t5 a( j - {
. C( K9 x/ w; _ - NXOpen::View* myView = NULL;
- g# z" h8 U, O- `" c4 G - NXOpen::Point3d myCursor(0, 0, 0);! d; a3 \6 g; |! z* Q8 X
- , i/ C: o# |9 }# M' m
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);& i6 g. j* A. S) v2 t0 u- C* M
- if (myResponse == NXOpen::Selection::DialogResponsePick)
4 T8 x6 ^* X- b! t" x* L7 O( a - {
% F! {" i% i8 ^ - // obtain the current default annotation plane where PMIs are placed on
6 p+ S( M( y' I1 V. }$ g% K7 h) l - NXOpen::Xform *xform1;
) ^2 _% W2 L2 x: A$ k# | - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
; h! S1 l7 L1 W7 e |' a% u - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
' e/ L8 ^; \" n" U3 L - NXOpen::Point3d ptDefaultPlane = xform1->Origin();# R! X( l- q4 x0 u% c" P
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
4 r8 O: l f6 F. R
2 n- A# ~& M/ z Q% ?$ ?- // create the ray 'into the screen' at the selected cursor position
: F! F0 ^: v1 U1 v: s9 l9 ^2 c9 E - NXOpen::Matrix3x3 vmx = myView->Matrix();
# r; `% |/ d6 G - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
# j( D* n. ~( J# E7 S3 d5 P3 s% g5 V% d - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);5 f' J5 H! Z6 c8 {( i
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
$ `, t" j) n3 V* y+ w7 S a% x - lineRay->SetName("Ray");
s @+ I; ?) j$ F6 Y8 k; k4 n/ ] - 2 _# P+ n' x* p! ~4 n
- // create the plane from the view to intersect with the ray; q. l$ r7 d$ w* E9 e
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);$ O- G6 `, N2 e9 y) n# V2 |% Y
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
$ p; z% |) X8 U8 s - planeView->SetName("ViewPlane");, o6 D" Z( q! {
8 x; ?& l/ k& y& g0 m9 Q1 ]" s- // now create the intersection point0 ~8 V z8 o8 z9 y
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);: P' L& r) Z' p
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; x6 X" v$ W5 P6 x+ x' `
- pntInterSect->SeTColor(10);' G1 z# R" V/ ~5 e
- pntInterSect->SetName("Intersection");, F8 C7 }0 ~/ T, p o1 `
# K b( ~/ S, A) K8 u, d' ^- pos = pntInterSect->Coordinates();6 I4 `+ A- x2 h4 W9 C1 ~- w
- print("\nPMI Position:", pos);8 i9 @1 q* Z: t
- ( I& z: A8 L( X- d
- // clean up - comment to see intermediate objects
# z/ H4 L; N: B" ^. ^5 | - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete"); e2 P8 L) ]$ N" u @
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);. V `* x G& m* b6 I: h9 o7 }2 ?
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
8 I5 v, n7 `6 s5 r$ A/ x - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
9 H6 b! m+ p9 n- d2 |+ P M - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);5 E8 ~. v5 u4 x. y* Y; {* F% y
- m_session->DeleteUndoMark(markDel, NULL);
L# M8 L. ]! M$ a- ^# k/ P, T - 3 q0 }: ]$ w. N) @% {$ k
- return true;3 f* M" \0 a t1 l9 o; q
- }& G- O) } I3 q4 N: P$ P" y
- 3 Q6 o# B* B1 Z9 A+ Z
- return false;
4 b! |" E9 l; @' g* M) J6 f; ` - }
复制代码
' Y- I1 x; k L4 u5 n8 s, ^6 D: p+ M; D& ~
|
|