|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( ~! l$ d- T5 @4 w) T
/ M1 i H, o& r如何获取选择点映射到视图空间中?源码分享7 n$ ~, n0 K0 a: W
7 i3 ?& ^+ ~8 U2 O
- //------------------------------------------------------------------------------' Y6 d( i" S, m0 y* R. w! w
- // Select Screen Position and map to Modeling View Plane+ m' C. @( O+ w1 o! a6 _; ]! E
- //------------------------------------------------------------------------------- y! w, O6 q; y- i
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
6 B8 d0 H) A" }1 e# f: w( V - {
! l7 b P, k5 A0 |, J) ^2 N - NXOpen::View* myView = NULL;% F- l1 w: k" D- x& @. o
- NXOpen::Point3d myCursor(0, 0, 0);$ S- W3 ?: e8 m/ d* I
- : L8 ?% l+ l% u2 m
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
3 |7 C9 \3 u! B - if (myResponse == NXOpen::Selection::DialogResponsePick)$ ]0 t0 }) M- k
- {$ ]' e7 R0 f' i9 n9 i% V. W
- // obtain the current default annotation plane where PMIs are placed on
- R" j, _4 d2 R+ `8 Z G; A4 ?' k - NXOpen::Xform *xform1;
+ N) X' A3 L% e6 C - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);4 a$ x! O7 v R3 O
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
, z$ q0 W% D# G- Q8 Y - NXOpen::Point3d ptDefaultPlane = xform1->Origin();: {0 ~" K9 P# J, Z8 A
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);5 W% S& g `) s) T! }
- ' u7 ^8 Q' p$ [6 I4 P$ m6 Q
- // create the ray 'into the screen' at the selected cursor position3 a# O4 _7 o+ V4 U) d* N
- NXOpen::Matrix3x3 vmx = myView->Matrix();% Y! P! c" }+ d8 x$ `! I/ j
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);' @, v- B2 k j% ^# W8 B
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
+ m& {' d$ f; E/ k - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
. ?/ _+ I8 y* i% t - lineRay->SetName("Ray");
! Z% v5 }0 e9 \ \1 w! i1 o" c - ' x5 L0 p% ]' ]" w1 `
- // create the plane from the view to intersect with the ray* ~( g, g9 M: T( ]1 _2 [' d
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);" v1 O+ b: i \% p7 T
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
$ u2 v- `# |4 e' Z2 P( E/ }* b - planeView->SetName("ViewPlane");( Y2 g/ y! |8 B1 j( h r# X$ J
: r8 B, x! a$ T- Q7 i- // now create the intersection point6 O a! _/ `5 o3 m* j7 L% O& B
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);7 z! P& E/ q5 m6 W5 @1 p
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);& w; n! o+ w, \5 U( J$ ?- \8 c1 m
- pntInterSect->SeTColor(10);. S4 K+ f- G' R4 B$ H
- pntInterSect->SetName("Intersection");: f K% p% Q C
- . {- z- I2 \- p5 B" O
- pos = pntInterSect->Coordinates();9 u- |- H2 G( V5 C
- print("\nPMI Position:", pos);. |$ _2 q' b, q" Y: r8 X
$ F! n5 u* p( c @- // clean up - comment to see intermediate objects/ {4 h) M) S/ C+ Q5 ?8 Q
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");+ R5 K3 c( M y8 m. a4 w$ Z
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
" T6 X: y# V3 G# Y( ~6 K - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
- q2 M% a+ m K0 M" p9 n1 L. s - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay); h# h/ y/ s; N" V
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);: l, D8 P l4 _0 X
- m_session->DeleteUndoMark(markDel, NULL);
: y% l' T% K* `5 M! \6 V
4 Q+ P) N( K$ M: J/ \ j- return true;
: m9 e' J, _/ b3 X - }2 A7 V1 B5 ? `2 Q& m
! h! `( K3 v; C- return false;
3 M% ?" k$ e/ `5 s- i; s3 D - }
复制代码 2 A* f3 ~+ Q5 H% |& O
4 P* r) y, V0 A' ~3 U# M |
|