PLM之家PLMHome-工业软件践行者

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

[复制链接]

2023-7-15 12:08:47 1326 0

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

& `' f' v9 Z4 A) A! r' p: P" j
# `# Z/ R. y/ p/ C+ @* {+ y如何获取选择点映射到视图空间中?源码分享+ F9 H1 f; ]# [0 x0 m+ X

4 l+ ?9 W/ t6 G8 T" M
  1. //------------------------------------------------------------------------------
    ( k' j# y- C) r; i: M" B
  2. // Select Screen Position and map to Modeling View Plane
    . H3 d4 o2 p* P2 C& x$ B$ H
  3. //------------------------------------------------------------------------------
    & l8 ?6 [( k. h" A2 L
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    " }4 X1 O, V# s& Q( ~3 R
  5. {
    7 Z9 ~, E. Q3 i8 {8 c6 k
  6.     NXOpen::View* myView = NULL;! E8 H" @1 n( y7 d, E' G
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    + d4 W! s' ?7 I" b3 f

  8. / E' u& K2 ^- L; C
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    1 B4 Y- z% H; i9 i
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)" W. q" x$ j) s1 H( B, i6 _; S7 v/ [
  11.     {% v5 N/ Y: ]+ g& P
  12.         // obtain the current default annotation plane where PMIs are placed on
    ' E" |4 j* g) g1 d. u1 Y  H% |3 n
  13.         NXOpen::Xform *xform1;" [4 ?1 Z! P- z, Y
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);+ W, R# C# I, K" k
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();7 k3 w9 m( a" g7 J* a
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();- E# m6 v3 P( P% i, h/ m6 H6 D2 E, }
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    3 D( g6 k9 h- M/ O
  18. 7 F! i3 U8 r" A' q% a3 W0 f
  19.         // create the ray 'into the screen' at the selected cursor position) }( N# u4 S: i3 ]4 w" N6 L. y/ r
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();' e6 e5 _/ K% p# [/ U8 ]
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ! o# a) y; ~. v# L6 w  |) u* f! _
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    0 x9 @! n, S+ u8 s. L  c$ |+ o
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    4 f) P( a* n! H$ W- u# T
  24.         lineRay->SetName("Ray");
    5 A* u6 W7 I( V; T: |4 B9 ]  |& K
  25. - v/ F! N. [3 ^$ Y4 m
  26.         // create the plane from the view to intersect with the ray  T! J: }- u, J$ \' v
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    5 D6 z" s9 Q" ]; g/ H
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# {2 H2 y2 _  K7 U
  29.         planeView->SetName("ViewPlane");! t' U# l. k9 b. w* J* U9 G

  30. 0 ?8 D, L  w0 a8 F
  31.         // now create the intersection point5 q* g; _5 b8 S7 {
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);  u  \6 _+ }8 y! i7 j2 C5 b
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    . ]1 U- w7 m! e* q5 n" }0 |2 K
  34.         pntInterSect->SeTColor(10);" j  @/ A5 i( n& r5 ]/ j
  35.         pntInterSect->SetName("Intersection");
    ' C1 ?, w6 @; a: m2 U

  36. 9 V5 n2 N4 t  K4 `& a2 b( y" U2 e
  37.         pos = pntInterSect->Coordinates();
    8 |1 q' y$ t/ b, g6 ]) U7 t
  38.         print("\nPMI Position:", pos);* X/ X5 z, D- a8 W2 C' a
  39. ! L& X0 a* j- G" d
  40.         // clean up - comment to see intermediate objects" K2 a9 r: e3 E) x0 A0 X
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    6 N0 Q; Y2 D. ^  N
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    4 W) V# x2 ^5 _  z
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);* ]! \5 f& K0 N1 \! S$ `
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);) A4 o  B, q8 G( }9 _* Y
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);6 Q) E. @/ W8 g/ ?! V5 `, n/ T4 y
  46.         m_session->DeleteUndoMark(markDel, NULL);" A& s' ~+ J9 y) z( D( x2 s# o
  47. 3 c4 m+ ~6 f) O$ b. C' I' S9 y
  48.         return true;" r5 O6 q0 N6 i! |" Z' T
  49.     }  ~- l' r- M7 n

  50. ; y2 r0 x4 B4 c2 u& n6 Z' K
  51.     return false;
    6 ^" z/ _3 Z8 K- _) L. d0 A. n( g
  52. }
复制代码

8 L4 X3 @! f5 a& ^6 f( _
' a! b- Y- G* Z, O! ?  n0 D
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了