PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
* M: V! q3 K! Q: S8 c2 k

+ W3 E9 U3 I+ M2 [- q. ^* W+ V如何获取选择点映射到视图空间中?源码分享
$ Z. V: `  ^# e+ w$ F3 I4 W; R* g: R
  1. //------------------------------------------------------------------------------
    * q, d+ {2 j8 s$ O
  2. // Select Screen Position and map to Modeling View Plane
    ) Z, ?, O; J* `8 p6 p; p" x
  3. //------------------------------------------------------------------------------' R% q" u3 f& I' w/ [% e% r7 j
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    9 j5 M/ n' F7 P& X9 Y7 Q
  5. {
    ! `2 |1 q9 [9 G8 B6 H
  6.     NXOpen::View* myView = NULL;) z& V9 j  a4 i9 T8 T
  7.     NXOpen::Point3d myCursor(0, 0, 0);, ]2 ^. D, u; a# y9 m  G* y

  8. ) F, t+ B( F) v: V* f: l: |* L" d
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    / q. d. B4 R1 f* f3 t5 V! U
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    4 u; `; N% r- H- @
  11.     {
    - S  w7 I: h9 U* }2 s
  12.         // obtain the current default annotation plane where PMIs are placed on  I; y2 ]. a+ J# N' |' B4 A% g
  13.         NXOpen::Xform *xform1;6 }2 ?& I! d7 {4 H1 z
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);; Y' o) b/ o* Z1 X* l' T
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();, }9 g9 G3 M6 \$ S  M2 w- e4 _+ y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();$ Q1 P7 v# e, u) g' `, F
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    " g% o( r. M, d$ B; D4 Y
  18. ! D. I1 Y# c3 Z% m7 L
  19.         // create the ray 'into the screen' at the selected cursor position
    # o7 B- Z1 o& [1 J, k
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    , c" n* d/ M: U7 i
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);# G5 a! @% ~: E
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);9 z% @- ]  P% R. a6 l
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);+ h2 R5 x& ~9 p# K; A
  24.         lineRay->SetName("Ray");' w3 l3 Q) }' ?, K' l  C
  25. * E5 d7 S  w8 G. v  a# f1 w; ?
  26.         // create the plane from the view to intersect with the ray3 O3 q  C  d7 v' e* |( d. v
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    $ |  I& m+ K5 `, `
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. j" p0 r* ^1 n2 I/ }$ Q6 A0 m+ J
  29.         planeView->SetName("ViewPlane");
    # `0 P; p3 U, u# S8 m
  30. 4 C2 h- }2 {0 C- r4 P
  31.         // now create the intersection point
    & f1 @) E. I$ ^! X  k7 A5 I( Z7 `
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);) k; @( n6 X6 H
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* L+ F) r7 r% I& M' ^
  34.         pntInterSect->SeTColor(10);
    ! s0 G/ C  y2 y; p7 Z
  35.         pntInterSect->SetName("Intersection");+ Y: ~+ \  Z: U, V4 P! A# G, J3 w$ W
  36. - D9 G, H& Q6 h( s+ }- U0 j, n
  37.         pos = pntInterSect->Coordinates();5 E: ~  ]# |# i& h/ {! i
  38.         print("\nPMI Position:", pos);. H9 m+ [9 X, a4 G
  39. 0 _- }( \5 N) P. u
  40.         // clean up - comment to see intermediate objects1 c, L3 r, u/ z0 R6 ^' h. x
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");3 |; P+ ?, M7 w. p7 D
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    3 z$ a6 E; p; S- ?
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);' Z. N9 w/ W, \9 [" {' S
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);* L4 ?2 j+ C. K% D9 ~' p' k
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);% T: ~3 E' y" Z% {9 L# T
  46.         m_session->DeleteUndoMark(markDel, NULL);
    , U( J- Q" ^, \9 M% L" C* o  S

  47. : \+ q# Q5 q( m9 @: |
  48.         return true;$ Z5 c( l9 L5 |  q
  49.     }- Y5 q5 c3 z2 F! h/ S7 J  v5 \3 C

  50. & f% @7 [1 `) E; a; {2 z. G$ k; I3 B
  51.     return false;9 y! Z" i9 F0 W$ [! ]; z& T
  52. }
复制代码

4 O2 g4 U8 Z  H3 e( T% j
  U' Y; e* B3 b) k) Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了