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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
- X' S: M; G4 P& E) w4 }
& \/ m, k/ I* P! }
如何获取选择点映射到视图空间中?源码分享
2 A  v! m# R4 Q, G+ D' c& Q: k
7 s) z) v# v0 |& v( J9 G
  1. //------------------------------------------------------------------------------
    ) K2 N* P/ R4 F/ x
  2. // Select Screen Position and map to Modeling View Plane
    2 G3 j6 ^! D1 V1 \5 K) D
  3. //------------------------------------------------------------------------------
    % r; ~- ?! r) q7 R, R$ K: C9 S
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    , K4 h" a8 X8 E7 ]) `
  5. {/ u  I" L. f; k& W1 ^7 q
  6.     NXOpen::View* myView = NULL;1 x6 y* q  y, s
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    1 L" X* T, y( p! R# X
  8. : Y, m3 V0 S; y- Y. _" O! b
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);$ L/ d9 m: ^; Q, p" }$ L$ L* A
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    ; S! _4 k; Q) |% R0 g" f
  11.     {$ D8 |2 W3 _; J
  12.         // obtain the current default annotation plane where PMIs are placed on
    3 S$ t" t# Q6 ^2 [, N, {: Y
  13.         NXOpen::Xform *xform1;+ w7 w, Y5 O3 P$ N$ K
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);4 I4 n- D3 G$ g0 c) H2 f
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();/ Y+ v6 b# R7 l& z) A
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();# |' v+ q$ s% V% o' R
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    # g$ U; z6 B1 }
  18. $ Y; d% ^. [2 i2 ^
  19.         // create the ray 'into the screen' at the selected cursor position
    , `" e' t6 t: B5 j  |
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    7 W& _% X/ V5 Z2 o) I1 ]
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    4 \( d4 W/ `5 U4 ?  [
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    $ C1 Y9 e* r8 G- ^9 K5 A
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);, R# J' i- B" O/ C% V0 j+ x
  24.         lineRay->SetName("Ray");- b* a# W' q/ A, `2 q' m  e

  25. , z: v2 `! |. e" Q) @3 q. h/ I0 W+ v, x' `
  26.         // create the plane from the view to intersect with the ray7 q0 R; Y% Q. g/ t, a6 F
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);" i$ S7 d: K, }5 ^% T$ t
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);: V8 a# G+ \* z2 c. f. s2 s9 B: E
  29.         planeView->SetName("ViewPlane");
    / E, \/ ]1 a' U  W

  30. ; @2 e- F6 W& f! x7 @
  31.         // now create the intersection point+ u: B& G& \3 Y$ J1 |
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    & w% d$ ?; \0 x' M7 h
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    # ^# q& J6 E8 u# x7 D" g
  34.         pntInterSect->SeTColor(10);/ e) A! v* K* A: J
  35.         pntInterSect->SetName("Intersection");9 V- ^/ X  f2 w( M) _/ p8 z
  36. 1 m( e+ J  l% t! y' F* ]" c4 O
  37.         pos = pntInterSect->Coordinates();
    9 o; |1 g2 K% y& \! |5 V
  38.         print("\nPMI Position:", pos);
    + d) U3 w$ w+ E( J7 F9 Y
  39. 4 c) O/ J! ^# i( M5 F% z
  40.         // clean up - comment to see intermediate objects
    " s9 M' D( m0 n2 V
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    * D0 D2 U' t) X1 ?6 h0 h5 o& C8 m
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);4 j" m/ P. @" Q- O, z
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    * P+ l& ]& H$ m5 f; }
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);# C1 t3 D/ x& v1 y4 D" d
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    4 h/ R! B+ U- C( a3 s& m
  46.         m_session->DeleteUndoMark(markDel, NULL);  \" }! M5 w/ B, m: I/ }% U

  47. $ i: k/ G' Y' h! s. I" |: t& e8 R, V- ~
  48.         return true;
    & U" A' v* M3 V* v
  49.     }" _2 N# b6 w; D3 G) t$ L
  50. % k2 P9 k3 M& _
  51.     return false;
    3 B- X2 f( S1 o4 g3 Q( h- V
  52. }
复制代码
# e4 B. t; \- n# v+ q0 \
, h/ J" u1 J) l9 o2 T! i1 B
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了