PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

admin 发表于 2023-7-15 12:08:47 |阅读模式

admin 楼主

2023-7-15 12:08:47

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

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

x
. l9 C' c/ r/ _4 {1 S- l
( y  W3 v* l6 P$ |5 n
如何获取选择点映射到视图空间中?源码分享
! Z, d  A4 |; b' |/ P- h% T% U$ V: n( g3 ?7 P2 c! c6 z4 Q7 A* D
  1. //------------------------------------------------------------------------------. s1 k8 ^5 ]% i1 N- S0 S0 Y! Y
  2. // Select Screen Position and map to Modeling View Plane0 l* ]. Y6 Q. ^0 m, B
  3. //------------------------------------------------------------------------------
    , I, K, N- X2 S
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)6 P& f3 P8 a0 j8 |1 v/ L
  5. {
      R5 G+ o: r! H- @& Z/ j
  6.     NXOpen::View* myView = NULL;0 X: q& d4 O: L. `0 p& z
  7.     NXOpen::Point3d myCursor(0, 0, 0);* R) i9 A6 B" I8 G: P( t$ _& A  ~" h
  8. - R7 H+ @# s# k$ e
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    " D) Z6 @3 x  ^
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)/ w, `! I; \) [- z; f
  11.     {3 Y7 w/ |  Y/ y
  12.         // obtain the current default annotation plane where PMIs are placed on  Z0 b9 i0 B! U3 x) L5 @
  13.         NXOpen::Xform *xform1;
    ! t0 [; x& k. W/ u6 F
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% L. A7 N9 f  q2 k  w1 u( K
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();1 q4 j9 \3 l6 k: q/ `
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();0 i$ F9 v2 d4 v3 w1 R: S
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    ' ~* Y3 k& z6 ^2 @" k* u

  18. # z5 |6 ~, e9 I/ ~
  19.         // create the ray 'into the screen' at the selected cursor position6 ?0 C: h9 e& e4 J" {$ Z
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();3 \+ w# ]: u& b  x/ L7 q
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    $ o+ u9 h' a5 @. g
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    * @/ U& l5 C  S( P9 B9 I# s& U# ^
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);% O2 L- S& i' }0 g, V- P
  24.         lineRay->SetName("Ray");7 k! r% ~. ]# i* s2 l$ J4 d
  25. 0 B6 Z" c3 e0 c
  26.         // create the plane from the view to intersect with the ray
    ; m9 M) n/ w& f/ l6 D
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    1 y: r  R7 J3 T; J$ B; {
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ; L! S5 I' J* \$ E* K
  29.         planeView->SetName("ViewPlane");% f% @/ Q9 B4 f1 c' O

  30. 9 g, [+ J2 W$ |+ L7 S& N
  31.         // now create the intersection point
    ) @/ {' g# P! \( Y: n3 G
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);, ]) @0 }# X/ r4 E# E9 T
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    / @) }3 k  z+ i! z+ c& [0 G
  34.         pntInterSect->SeTColor(10);/ X# T" @) V+ f; g
  35.         pntInterSect->SetName("Intersection");
    : G7 D0 z* g3 S5 I+ f! Q
  36. . z" |4 {) m" D/ }
  37.         pos = pntInterSect->Coordinates();$ U2 o$ M. F) P/ f/ m
  38.         print("\nPMI Position:", pos);  y" ]. g: q( V4 P

  39.   f+ t- o/ d( a+ L
  40.         // clean up - comment to see intermediate objects
    2 S% U  v1 ?& i& h
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");6 v5 U& h0 a5 a
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
      K% c' {* r4 c: F" L& a* m
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    9 Q, `, d4 k5 N/ I0 h
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);3 p( m7 J) M0 c! F/ ?0 h: @
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ' |# F, Z6 n0 g" M# \
  46.         m_session->DeleteUndoMark(markDel, NULL);
    5 E6 D6 z  m2 g* J
  47. 9 B+ g! ?& ^% Q+ [& v8 H9 v
  48.         return true;! X! ~0 w3 k5 r5 E0 G* P! y; K
  49.     }
    " A3 u) k: p/ ]: ?( E2 F
  50. ' R. t5 [6 M: `: {
  51.     return false;
    8 S$ \4 [4 l9 U& s
  52. }
复制代码

7 ]% d" k* I* u) E+ {4 P
: }2 P$ E6 p8 V. x
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了