|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& g& s/ r" a4 D1 @$ j$ U
: S# r! e8 z" D% R2 X: E
如何获取选择点映射到视图空间中?源码分享) M2 J& Z5 J. g' i E5 ~
& u: A) V2 S) O" n/ L, `; y
- //------------------------------------------------------------------------------
3 f* s3 d! {- U5 v, w: H [ - // Select Screen Position and map to Modeling View Plane) T* Q* z$ C- _5 r; e( j( {
- //------------------------------------------------------------------------------! f1 ?7 }& D: k* h$ {; [7 N
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos), s, w1 o1 _5 V" M9 `
- {
# y/ r9 ?0 y- U( [. B: q; U - NXOpen::View* myView = NULL;
* z$ e! s$ `0 e( Y4 w# Y - NXOpen::Point3d myCursor(0, 0, 0);
$ _! I) q4 D- u# o+ G" y - . t7 r7 v2 g" @7 R
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);( }7 W0 f; w l; x% _7 C2 s) Y
- if (myResponse == NXOpen::Selection::DialogResponsePick)1 c2 I: A. L( X
- {
- x( ?' s0 ~4 R, F5 n' n2 n - // obtain the current default annotation plane where PMIs are placed on
1 T7 N( S5 \# k) B9 b0 ^& j - NXOpen::Xform *xform1;
5 o+ [( k6 v0 ]6 K" K, o. I1 v - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
/ X) }7 D; D3 d l - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();6 p$ A; U$ [- A+ Z1 W: ~; O4 h
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
2 C# p/ B) Q) w - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);4 u; x2 T' G- B5 o/ I+ [1 b
- ' ]4 v4 n! Z1 T* E' t; Y4 U k6 I
- // create the ray 'into the screen' at the selected cursor position( [5 l9 b2 L, r4 `
- NXOpen::Matrix3x3 vmx = myView->Matrix();
. `, v) c; o( K- ?1 r& P1 K' A: ~ - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);* s. P2 G1 U: i% b
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);2 h# l5 y8 ]- w
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
( F |& K- ?: k7 u0 Z4 s" U. ~ - lineRay->SetName("Ray");& ^" i4 B7 j- A, q! U
7 T/ E) F8 n+ g8 i% \- // create the plane from the view to intersect with the ray8 j2 C0 f, v0 B9 x6 Q4 h, y
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
" q4 W. c: C, c- y7 r( N2 O/ z+ `4 R - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
4 S9 F3 N+ ^' Q% n$ e4 d7 | - planeView->SetName("ViewPlane");$ G$ ?8 k) [, V( u) A6 y6 W7 ~" y B
- 1 d0 h* s/ e' G: E' k
- // now create the intersection point
8 C4 Y. b/ r6 `/ J8 b' b& t - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
8 r+ u; |/ o; o2 ?# ` H7 w - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* ], V7 M. F, j5 Z
- pntInterSect->SeTColor(10);( h' v) k1 c, ] D0 S, n
- pntInterSect->SetName("Intersection");
% G% d5 @- n' @1 @ - : _* E8 o) C: P# x3 x) c& _8 l
- pos = pntInterSect->Coordinates();/ a+ e- x$ ~: o6 m
- print("\nPMI Position:", pos);7 k, C8 U! ?! i( J% G8 _
3 e; R4 ^. Q; B- // clean up - comment to see intermediate objects0 c% v* k- F" i! j+ b3 R5 O
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
! x1 r7 e* q9 B. Z! P( G, W- K - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);; b, g$ [; [( n
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);" N0 R7 P, m! k% E) W" s
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
7 E) @( n+ u, x* ^# V5 ` - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
Q6 ]& X7 w2 I- W) n u/ V/ O - m_session->DeleteUndoMark(markDel, NULL);/ t* B! w! A: V) D' n
5 }4 s' f! N* u7 S. e' N4 H- return true;! B' B6 `6 n( x9 V: W6 {- e
- }. W2 |6 B% s( O) E2 P
- + A0 y/ t$ Q+ v( x" N
- return false;! O$ y3 m4 K- P" B4 Y' X) K F
- }
复制代码
) @6 R7 i' ^( [0 T6 `+ m) E2 s5 @
, s$ H' y4 a' K3 o9 d0 F |
|