查看: 1557|回复: 0

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
& v1 W5 c7 X% G2 e
+ i+ O$ X0 l6 e# U9 }& d; {
如何获取选择点映射到视图空间中?源码分享
8 {- w. n6 u. C$ ]1 S# @+ n* I
6 g. }4 J% Y; P, t
  1. //------------------------------------------------------------------------------  W) R- K: A% D9 v4 L" N
  2. // Select Screen Position and map to Modeling View Plane
    3 D$ n* l/ g8 @! C7 e
  3. //------------------------------------------------------------------------------
    % L# s+ T" X: m: a: `& J
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)- n& H- C1 P/ x2 G& Y/ P& P
  5. {
    ) B! ~0 z0 ?) U4 W$ b  V
  6.     NXOpen::View* myView = NULL;
    3 s9 P5 @! z0 w. z! l* l
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    / m. [$ L, M! {. l

  8. ' E/ w4 Y) N$ X' j& D! r
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    5 |: X5 Y- E, E/ C, e: \' ~
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)! k3 y$ W; z+ x1 H# u; q3 [- ]
  11.     {0 N0 U2 U+ p! `( ?  l' w) b
  12.         // obtain the current default annotation plane where PMIs are placed on7 @3 y1 [/ ?( s, A
  13.         NXOpen::Xform *xform1;' [* c( K- |0 p: e2 C
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);1 r0 l; d8 Y. ?  i
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
      j6 q; J3 b8 p* r' \
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    ! G* T* x  s9 h) q- q! w* e6 A6 c' J
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);; p6 S/ }& M, E/ e, ?' a

  18. % y2 C" @# {# o( ~% J- i
  19.         // create the ray 'into the screen' at the selected cursor position
    3 d9 a  }3 j! P0 {7 Z1 X$ c
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();3 M. q0 S% o+ X* c: A5 ^4 i
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    # {  ]7 a2 L& e9 L& V* n3 f, a9 T
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);% _3 l4 e5 L+ @# [
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    9 X; I- t1 x+ S1 e2 k$ ?1 n
  24.         lineRay->SetName("Ray");" N$ L  e; T# z
  25. " F! A7 p/ c' g# K( k# T
  26.         // create the plane from the view to intersect with the ray
    ! \9 Y2 \  O! F% b* c
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    * ]# n0 D% `- q# i
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# `+ F7 H  Z4 F+ |7 ?) O
  29.         planeView->SetName("ViewPlane");& W6 Y- `) {) Q, _
  30. / `2 H* S4 e& S8 T$ l) `8 |' H( G
  31.         // now create the intersection point
    4 v$ a3 H, U; X6 b0 ]4 R
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& r& Y# l+ T+ _) v7 r$ e
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    6 P. u( F, A6 s8 \
  34.         pntInterSect->SeTColor(10);
    0 j% _, }! \9 O0 g6 w7 K
  35.         pntInterSect->SetName("Intersection");
    9 G: V3 |. A. S: |5 Y+ f( }( N

  36. 5 }7 T' p% v8 J- i' N3 q
  37.         pos = pntInterSect->Coordinates();
    0 s# \$ v; F$ i  H0 I9 |9 O
  38.         print("\nPMI Position:", pos);
    " E4 ]- g/ v6 \
  39. 8 R& Q- D3 M) n$ r
  40.         // clean up - comment to see intermediate objects" Y8 R, }) j( Z+ U
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");, Q$ A& o. b6 @7 c" b4 [
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    $ q! {, _- M9 ?' F( n
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
      |# B* t) \& \) }  W- W1 x# [) I
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);+ S9 U. D3 O" `) X2 {: c
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    8 s( h7 r; l, p! U0 F9 r2 q
  46.         m_session->DeleteUndoMark(markDel, NULL);" M9 _0 ~  j0 P1 A- {, W( i6 C, c& Z, ^
  47. 7 w- \6 m1 K1 Q) R9 h9 c: p
  48.         return true;
    ( a! z6 `' F& G( w
  49.     }% r! x! l2 w2 W* F$ |5 k; d9 v
  50. ' A" a3 Q7 a* y3 _- B  f
  51.     return false;1 f+ O! W. A; B& P
  52. }
复制代码

5 @. f6 ?+ @/ `! ^4 x9 v* \0 J/ @/ A( L  Q8 g3 w! ^
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部