查看: 1576|回复: 0

[资料分享] 如何获取选择点映射到视图空间中?源码分享

[复制链接]

6

主题

4

回帖

60

积分

管理员

积分
60
发表于 2023-7-15 12:08:47 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×

$ J* _. l, M2 y
% T2 T. Z# `2 Z9 B' \: \7 [如何获取选择点映射到视图空间中?源码分享& V6 I, N0 U- c  }8 C, j8 c
/ c, P( |) }0 h5 N; O/ w8 S& K: N3 l
  1. //------------------------------------------------------------------------------; r' R) x) R( q! X: r: K5 M
  2. // Select Screen Position and map to Modeling View Plane
    % C$ e5 d% L* C# h! ]6 q. k
  3. //------------------------------------------------------------------------------
    * a% g% O1 c( F
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)( H* m# c8 V* C
  5. {
    & G) n( a/ o2 b1 e8 o" s. E
  6.     NXOpen::View* myView = NULL;% X% ~) |! j6 b. s" a
  7.     NXOpen::Point3d myCursor(0, 0, 0);6 `1 k: Q( H: W* s

  8. 9 ?& o& ^% P* l4 T3 Z+ r8 `
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);' M+ ^' ~4 d7 [; t  x, ]$ a3 W: ?3 c
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)/ H1 J: p/ U( M0 c' v
  11.     {
    % _  [! U) b  m" b6 \# L% c* j
  12.         // obtain the current default annotation plane where PMIs are placed on
    6 b& t( a2 d0 E( [/ ]& q" @- Y
  13.         NXOpen::Xform *xform1;" O, Q7 u9 h# ~# U
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);  W% g$ I7 `8 a# j% f
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();2 C# x4 C1 q6 K7 q
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    : I6 t0 @: ]' J: D: h0 T
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);9 I( k3 N, y! S+ b

  18. - \- v. T; ]; ?* b. Z( B" e6 V
  19.         // create the ray 'into the screen' at the selected cursor position& ?7 M( r3 l( `) p$ W4 O
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();+ ]" {& _5 E. u' V! H
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    5 c9 q! H$ f" r7 }! G9 B2 q$ z% r
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);( E7 P% R+ Y# P. u9 J
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ( @! S) N! F3 Z0 V1 ~+ [7 X' y+ l
  24.         lineRay->SetName("Ray");
    9 h3 @% @5 N& F8 C7 N

  25. 7 _6 l. O* p3 Y' {) k# f
  26.         // create the plane from the view to intersect with the ray
    8 ]7 G& y% ~: C" n6 q  x5 G
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);% n2 g5 x/ m2 ]$ S
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 v- I) i4 }9 P2 t7 U6 M
  29.         planeView->SetName("ViewPlane");/ ^$ c- g+ I! E+ s4 h* N0 h: C7 ^

  30. 6 V3 |9 t, ]  _
  31.         // now create the intersection point7 }. Q, ~- x3 F6 L- E2 Q
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ! c. y& D; @2 a( u: t+ a: ~& o( {
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ( U9 H, ]( I) |; b3 X
  34.         pntInterSect->SeTColor(10);( ^2 N+ M' Y/ Q
  35.         pntInterSect->SetName("Intersection");, }, ], y3 t: T/ N. Z3 p

  36. / i1 ]" o0 L1 t7 k: k
  37.         pos = pntInterSect->Coordinates();1 ]( S( f6 E2 a: X% D
  38.         print("\nPMI Position:", pos);  C7 S+ O$ `2 j: D1 u  D
  39. : X0 G, ^4 Z4 }% o$ n
  40.         // clean up - comment to see intermediate objects) m8 A/ z! g1 h( [! r. ?  }: w
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");/ q1 R8 d+ _' V* u% ~) M* o
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);0 B+ S+ ~) |" v3 @1 _" z
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    ! r. ?/ ]& s* @5 A8 d9 Y8 f+ V
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);# H! a% \% D. S; l$ |
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ( D1 x+ w2 |% d  I" l4 h
  46.         m_session->DeleteUndoMark(markDel, NULL);0 \& \: |' b( i: p1 n* h
  47. 0 {5 v% J# [8 l
  48.         return true;3 [5 a( [, G- m
  49.     }
    6 h0 _& v( m: }  e0 g2 k( S

  50. 3 s  p9 T7 z: n2 i: y2 ]
  51.     return false;+ a0 F2 s, Q( K4 @7 M
  52. }
复制代码

* \. p. t( H* d/ K
" I1 @  d+ ]6 m6 i; R: W: \% B
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部