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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

( ^$ n+ H6 m& r  d. P" c* ?6 A- g7 b. F1 v
如何获取选择点映射到视图空间中?源码分享1 y# @+ l% a8 X, n, q1 k( v" q4 t

! L) r8 H/ n$ E8 G' x
  1. //------------------------------------------------------------------------------% w0 s& G* p! z) ^/ ~
  2. // Select Screen Position and map to Modeling View Plane
    , p. h2 u2 v0 b/ h0 o
  3. //------------------------------------------------------------------------------
    5 w* \  a9 ]+ a4 p  f4 j
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    7 s8 R' h5 h+ p  S5 B
  5. {0 n7 u1 a8 D" O: v8 ?( {
  6.     NXOpen::View* myView = NULL;
    # {/ r) t9 ?6 K; b/ O
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    3 i$ H( N6 j0 t: n
  8. ; X( B/ U$ N" r' }+ T% m! `8 \
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    3 m7 O6 d/ ]% J3 a8 `
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    # G6 K5 ~+ w; S
  11.     {
    7 K) d7 I% r$ J1 a, ^
  12.         // obtain the current default annotation plane where PMIs are placed on  Z! s! Y) _7 e0 e1 B
  13.         NXOpen::Xform *xform1;% n2 t2 x6 n0 i0 q( t
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);, R' z2 X- ^! @- A' {/ [
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    . V* L( S1 _1 n0 H) e3 U+ L# M+ X
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();; N& Y! G  `1 p2 x8 P
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);0 r% {1 E7 Q: O: x
  18. : o8 b% |6 h' J; E# A) Y  _( [% [2 `
  19.         // create the ray 'into the screen' at the selected cursor position6 o5 H6 k" {9 o% O4 U
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();3 C0 F# v2 _, k1 ^( J! x
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);0 n5 ?9 p8 @9 P  v4 U8 \
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);7 d( i# ^; r2 A9 a5 |4 l
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ; n+ F, T2 H2 y0 ^. s5 g/ y
  24.         lineRay->SetName("Ray");  g  U/ h# u, z$ X9 D5 R1 Q+ }

  25. 0 R/ F; _6 x/ ~6 A) V) F: L
  26.         // create the plane from the view to intersect with the ray$ F8 |+ B% j, U) J' `" J) S
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    5 ?! |# z, ^+ n! v: j
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# v/ e% y' Y* w- O) O$ b
  29.         planeView->SetName("ViewPlane");
      e4 G$ d# w& m* l: H2 X+ |+ n
  30. 9 x" X8 L  ^( P, _: g% q  i4 S1 _
  31.         // now create the intersection point9 q- \  b" O* P1 R# l  c# D
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    / ~8 z: l& O6 t: k" c- ~2 j
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ N, }; |) O2 _
  34.         pntInterSect->SeTColor(10);9 G: x- ?5 F. q: u5 i2 z3 Z* b
  35.         pntInterSect->SetName("Intersection");2 A, [7 `# C. x1 L

  36. 0 w/ h* h& a- i6 U; t" g
  37.         pos = pntInterSect->Coordinates();" G0 T, m# ?+ d" K. L. i
  38.         print("\nPMI Position:", pos);/ C0 h6 {& ~% m0 i9 R$ ~. E* n+ v5 o
  39.   u) g/ ?( `8 r: p- @& p, K
  40.         // clean up - comment to see intermediate objects8 E. g0 @3 v7 e* h1 v* t4 u
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    % Z5 V- X& b! Y+ W- F
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);& u4 R  E7 }' Q7 Q
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    ; g/ b) H1 V& C' F
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    : r- {1 w+ g' a# a  |% K
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    & H  K3 H/ k9 w  y7 d% a
  46.         m_session->DeleteUndoMark(markDel, NULL);# }+ Q) V% d4 s& ~! t/ ^% h5 m
  47. 1 L! V9 c' \* Z, b9 p0 R
  48.         return true;6 Q& Y1 D" ~. H! R2 V% r
  49.     }" u. i$ _2 b; O
  50. : }; y" @9 V% {# Y3 Q& c; z
  51.     return false;
    . |8 B% j8 d1 A/ A% ^
  52. }
复制代码
0 R# Z3 x" [  |! O' X/ Q$ C+ i

' f% N$ m5 i9 ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了