|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ L% b! ]( V* Z6 J6 l* D
( b) v" R. r) W6 h- p4 ]( U1 H如何获取选择点映射到视图空间中?源码分享
9 Z6 W! u1 z+ X+ n
& _/ a, o. l( a% v$ n' ~0 j( t- //------------------------------------------------------------------------------2 ^+ M; u) D2 I% V5 J& L: N, T8 r
- // Select Screen Position and map to Modeling View Plane" ?8 X4 D9 i u) D2 Q5 m3 R Q+ s; I- C
- //------------------------------------------------------------------------------' ~* r# g6 K; [. q! G6 K# I
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos); b3 D/ q5 I2 \( q% y+ o* O0 y
- { H; ]8 x$ I* f% ]
- NXOpen::View* myView = NULL;
( e" `# y. A3 f1 R/ ]# m - NXOpen::Point3d myCursor(0, 0, 0);: F* w+ \# J, P. I5 m
9 F! s) F0 c. c# q! L* v; p" v- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
5 P6 g; ^: H8 \& K# V; m - if (myResponse == NXOpen::Selection::DialogResponsePick)
# E* H2 q4 v6 Q9 H8 | - {# u/ [+ O, M4 w3 n# ~2 S. J6 y( p# y
- // obtain the current default annotation plane where PMIs are placed on# S3 L( [. x4 e9 ^7 g: c
- NXOpen::Xform *xform1;
$ U6 ~- [' N3 j: R- `6 b- X8 X - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
7 S2 t4 e6 |* {# n$ p6 U9 I6 D - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
* n; Q, O& \4 n4 _! _# D - NXOpen::Point3d ptDefaultPlane = xform1->Origin();5 x7 `. v3 Q- A+ e5 I; C
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);; k4 F( `9 e6 O6 b. b
7 a f- N( a- r0 E- // create the ray 'into the screen' at the selected cursor position5 `! d6 |: u, o9 F }3 a6 R
- NXOpen::Matrix3x3 vmx = myView->Matrix();
" |/ R3 |4 p1 k8 R$ N# I, _ - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);; m% g* w) O+ H+ G/ m6 j( G8 Q. o
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);) O: R' Z1 T; |
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) a: G' W+ r5 d5 Z ^% U; S% q& H% H
- lineRay->SetName("Ray");
; T8 x( Z1 I8 d, \) l
' g# L. u5 l5 [- // create the plane from the view to intersect with the ray
& ~0 P. K4 b( R2 H4 R7 s+ v; @ - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
# D- [( t3 S( | - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 c# L% P, ?+ g6 R; A
- planeView->SetName("ViewPlane");
3 J& e) u3 W7 O7 Q- @ - / ~. K' v0 f8 T$ ?3 ~! M
- // now create the intersection point
8 k4 _: X8 d1 k+ a1 h - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 @/ V9 B6 l; C5 g
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
6 s6 F1 P/ i, N! I6 v# g4 L - pntInterSect->SeTColor(10);+ z* q$ a8 M1 @
- pntInterSect->SetName("Intersection");
2 N% y0 \" w# O( I
; Y+ ?! P" S" e- pos = pntInterSect->Coordinates();
% |/ ~$ J+ Y$ J3 B, u e7 E$ [ - print("\nPMI Position:", pos);
7 m- Q2 r! |$ d; N; R
7 t T2 F% V( V o# d' ?7 V- // clean up - comment to see intermediate objects5 y- i* P( ?4 W2 k; \1 b
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");: _/ R Z- @9 F& d G2 ~ K
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);" q y6 d: K7 o _2 u1 z
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) m6 q: ~9 f+ z3 U% @: N9 }& k
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
6 ^3 w, |. ~' C0 ^ - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
4 _9 i7 K, h8 Q4 D6 L! p) a! B) z - m_session->DeleteUndoMark(markDel, NULL);. `, D6 q, b- U" O+ T. r$ b" I
3 m" g9 ^% h$ n7 G$ W- return true;( C+ C' X4 w0 I9 y& z; [* c& [) B
- }
6 E6 y+ \% ~9 Z6 c - 4 R" `& P6 g! |% b3 W
- return false;
- ^/ |4 a% c* d6 E; o# x1 Q - }
复制代码 - X- N* H$ i' ?5 Q) A
' C- Q4 K; x; Q8 L2 V- e/ ` |
|