查看: 1421|回复: 0

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

[复制链接]

4

主题

3

回帖

44

积分

管理员

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

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

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

×

" M( y5 Y# a: F% K2 T9 i7 n3 ^! D9 ^
如何获取选择点映射到视图空间中?源码分享
8 N7 X2 v" C+ K4 h
1 h' l' I. B0 X8 [
  1. //------------------------------------------------------------------------------
    2 e  f; p& R3 F
  2. // Select Screen Position and map to Modeling View Plane
    4 g+ ?4 x2 C6 S! _3 V
  3. //------------------------------------------------------------------------------. c1 e) r* C. t: p/ C8 g* S
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    ( o3 |- Z, `  u+ n
  5. {
    ) ^: M% m3 U, j# K2 L( `# ^
  6.     NXOpen::View* myView = NULL;7 h6 b! B. m& c8 b: n( s% k! Z
  7.     NXOpen::Point3d myCursor(0, 0, 0);+ b* V. W) m6 W) S& d- d

  8. , w5 m6 x: m0 Z+ u
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    5 m" h/ a1 ?! `" Z) ^
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)! s" d7 t6 X! B8 O+ o! k; O7 Q
  11.     {( G5 z% C: }: o) R0 d2 {) T
  12.         // obtain the current default annotation plane where PMIs are placed on- J. _$ ?" M( B5 S. ?" {3 {6 E$ E
  13.         NXOpen::Xform *xform1;
    ! b# h" M& H( c8 z9 h1 N1 b
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    1 O( \2 `7 h( L$ M+ q% l5 R
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();( b- H: e5 g5 a5 L3 W0 |( @, x' }
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();' v& l+ [' f1 S
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    3 I0 P  h# }3 C# N( W8 u% `1 `1 d5 u6 I
  18. . D& ~( j. E- s1 h; Q2 _1 D
  19.         // create the ray 'into the screen' at the selected cursor position
    8 D4 W4 E& W2 [0 ]8 N
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    0 a+ s5 s5 w1 L, e  E# _; n$ A
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ) e4 T: p3 U' _4 Y. V
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    $ A4 h  Y0 a& w3 X5 a5 ^
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ N+ K2 ?6 b2 v2 w0 k
  24.         lineRay->SetName("Ray");
    ( t. @6 o5 ~7 t+ J. ]0 A

  25. ! j* m. M( R& x/ C% v3 s' c0 V
  26.         // create the plane from the view to intersect with the ray$ W4 X% ~! a$ G1 `/ S
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    * d* C- n: g% |9 p) f) q- n. l+ b
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    0 b, c) a3 c; [. i/ `! u
  29.         planeView->SetName("ViewPlane");. B& c7 F* p6 b: [4 ^
  30. 8 O3 g# l* L% |8 R. q; Q5 Q; z- B
  31.         // now create the intersection point, L# d) e* r5 }& p4 C3 @! \9 B
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);* k# x4 A- h8 p/ l1 ?6 C
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);' L+ o* v+ u+ F4 c$ g, B+ E
  34.         pntInterSect->SeTColor(10);
    5 [$ |, l& f" U  z
  35.         pntInterSect->SetName("Intersection");* d9 F3 T8 x9 o- }9 x/ k$ K

  36. 9 L3 q+ ]; {7 u" c# H% i
  37.         pos = pntInterSect->Coordinates();" \0 e! W' c0 N$ e7 P* t( N) V+ I
  38.         print("\nPMI Position:", pos);
    ! s) B2 \' x: T; F" `
  39. . ^: W, N; L9 |6 z" F
  40.         // clean up - comment to see intermediate objects9 V! a3 d- ]8 \
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    9 [$ L5 ~& C0 f
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);1 M2 U0 Z- W& h. Z
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    9 e- k4 v$ `8 w/ @3 w, _6 v! H
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);2 J! Y; J7 X: L- t& {+ O" n$ e" D
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    % j, {( \9 }& X  v0 v; q
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ' r8 @# K# o: x# w$ s) C3 R% v
  47. 2 b. k* o9 A1 M% c+ C! H4 c4 f
  48.         return true;% s/ K+ p5 i. }8 z
  49.     }6 A" g& G! w( B, v' Z0 a

  50. $ o; g! p3 q8 x8 N3 z. K+ i/ L2 n
  51.     return false;" s# W1 v$ u& Y4 f9 u! ~' L4 K
  52. }
复制代码
. V+ V6 r: @1 G2 c, x6 ~& L
, \6 y3 |, H1 L' W9 _& R
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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