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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

5 U- W4 O% D, m9 r+ o4 G/ Y! {8 w" y& T! t; w0 B
如何获取选择点映射到视图空间中?源码分享* k6 m' v. ^4 t& K; P1 t5 _

4 ?8 x4 l; O! k8 Y3 P# i8 K4 x. I
  1. //------------------------------------------------------------------------------' f: h3 A1 V0 M: b4 t  B; \5 c* [( {
  2. // Select Screen Position and map to Modeling View Plane
    $ [+ L- I7 y/ v5 @
  3. //------------------------------------------------------------------------------
    " x- R7 z+ g, w& b( ?
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    " g" U5 p  u* p; k0 Y* @
  5. {$ O1 e3 L; b2 A% X: W" ]# I& ~
  6.     NXOpen::View* myView = NULL;
    5 @- R/ j0 F) H# z# \
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    * f% M# \* k( ?9 Q$ r: V
  8. 4 |6 L5 i2 z8 f* x4 V  m1 d1 m/ L5 Q
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    3 H. w) D$ @! @# s0 v
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)7 l9 n* c9 s4 o/ e5 x* b5 y
  11.     {
    / [* E+ [: M' Z9 x! |, I
  12.         // obtain the current default annotation plane where PMIs are placed on
    ) c6 E8 e3 D  m8 n, a
  13.         NXOpen::Xform *xform1;
    , m) a$ b" W" ?
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    ) w" T4 Q. a# O& K) d8 D
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    3 B9 v1 X9 i- M
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    2 y' R# y; \7 T" a' y
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    ' X+ {" T" V+ Z# y
  18. ! Z  X# W- {  b* G
  19.         // create the ray 'into the screen' at the selected cursor position
      K! L: N6 k: F1 d$ j4 F
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    & [$ w: c& i0 _: }# }4 B$ P1 r
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);  S# H6 Z* g. a6 L3 N! Y2 e1 m5 @
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);4 y, |& c2 h$ w/ d- A  _
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    . H5 a! ~; p+ n& L* `
  24.         lineRay->SetName("Ray");
    6 S# \* [- q* w9 B& Y& Y, U+ ]$ Y

  25. , J8 R0 R3 E) d; M4 T9 b. k" v
  26.         // create the plane from the view to intersect with the ray
    ( z! I3 }3 {8 i, ?. T0 i
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ' Q$ Q! b' l( X: x4 v; ]" K
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);' _7 ^" u/ R+ Y0 @. @
  29.         planeView->SetName("ViewPlane");$ f- Y! y- X9 I9 B# H* N8 p6 y1 T
  30. # `8 m! d- e* o& f
  31.         // now create the intersection point& a, {/ c. B3 ]+ y
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& h2 {  t8 D8 @! Y
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    + [" b; a8 ^: _- T+ J6 [
  34.         pntInterSect->SeTColor(10);
    0 P$ y. Z. @# k9 N  Y
  35.         pntInterSect->SetName("Intersection");
      o( D" u" L% z/ K

  36. ; k( D0 ^6 p! ~- M8 y. v. A
  37.         pos = pntInterSect->Coordinates();
    7 @. V- L- {8 W2 e$ W/ A
  38.         print("\nPMI Position:", pos);
    9 J3 _0 X/ F# O- e; n$ L  ?* w

  39. 9 a, V! x7 I  t
  40.         // clean up - comment to see intermediate objects
    % O9 X+ S" P5 N2 J! Z5 _
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    ' X- V; Y% r( [! E+ I
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);: L& ^6 V. T; G6 R9 j$ k8 s
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- Q: y$ I5 `7 N: C. T
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);& A& X) l; s, A3 e9 o
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);3 s% m+ c$ k  G5 D2 q4 D
  46.         m_session->DeleteUndoMark(markDel, NULL);8 g. Y) Z$ b! t$ y; O
  47. ' d# E* b$ ^  a" K/ o8 B5 z& x
  48.         return true;
    2 _4 S9 R7 e$ T/ I* }6 j; v8 b7 H+ l
  49.     }+ v' V( K4 q. {2 Z# o  q" s! Z
  50. ! o. C) D5 g! o! ^, p+ V- A0 }
  51.     return false;4 J- f: N/ g& J: c& j
  52. }
复制代码
  R3 m; ]+ T6 q4 t) T

1 h- q0 {  B8 G  U7 x1 J
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了