|
|
请使用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- //------------------------------------------------------------------------------ W) R- K: A% D9 v4 L" N
- // Select Screen Position and map to Modeling View Plane
3 D$ n* l/ g8 @! C7 e - //------------------------------------------------------------------------------
% L# s+ T" X: m: a: `& J - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)- n& H- C1 P/ x2 G& Y/ P& P
- {
) B! ~0 z0 ?) U4 W$ b V - NXOpen::View* myView = NULL;
3 s9 P5 @! z0 w. z! l* l - NXOpen::Point3d myCursor(0, 0, 0);
/ m. [$ L, M! {. l
' E/ w4 Y) N$ X' j& D! r- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
5 |: X5 Y- E, E/ C, e: \' ~ - if (myResponse == NXOpen::Selection::DialogResponsePick)! k3 y$ W; z+ x1 H# u; q3 [- ]
- {0 N0 U2 U+ p! `( ? l' w) b
- // obtain the current default annotation plane where PMIs are placed on7 @3 y1 [/ ?( s, A
- NXOpen::Xform *xform1;' [* c( K- |0 p: e2 C
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);1 r0 l; d8 Y. ? i
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
j6 q; J3 b8 p* r' \ - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
! G* T* x s9 h) q- q! w* e6 A6 c' J - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);; p6 S/ }& M, E/ e, ?' a
% y2 C" @# {# o( ~% J- i- // create the ray 'into the screen' at the selected cursor position
3 d9 a }3 j! P0 {7 Z1 X$ c - NXOpen::Matrix3x3 vmx = myView->Matrix();3 M. q0 S% o+ X* c: A5 ^4 i
- 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 - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);% _3 l4 e5 L+ @# [
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
9 X; I- t1 x+ S1 e2 k$ ?1 n - lineRay->SetName("Ray");" N$ L e; T# z
- " F! A7 p/ c' g# K( k# T
- // create the plane from the view to intersect with the ray
! \9 Y2 \ O! F% b* c - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
* ]# n0 D% `- q# i - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# `+ F7 H Z4 F+ |7 ?) O
- planeView->SetName("ViewPlane");& W6 Y- `) {) Q, _
- / `2 H* S4 e& S8 T$ l) `8 |' H( G
- // now create the intersection point
4 v$ a3 H, U; X6 b0 ]4 R - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& r& Y# l+ T+ _) v7 r$ e
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
6 P. u( F, A6 s8 \ - pntInterSect->SeTColor(10);
0 j% _, }! \9 O0 g6 w7 K - pntInterSect->SetName("Intersection");
9 G: V3 |. A. S: |5 Y+ f( }( N
5 }7 T' p% v8 J- i' N3 q- pos = pntInterSect->Coordinates();
0 s# \$ v; F$ i H0 I9 |9 O - print("\nPMI Position:", pos);
" E4 ]- g/ v6 \ - 8 R& Q- D3 M) n$ r
- // clean up - comment to see intermediate objects" Y8 R, }) j( Z+ U
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");, Q$ A& o. b6 @7 c" b4 [
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
$ q! {, _- M9 ?' F( n - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
|# B* t) \& \) } W- W1 x# [) I - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);+ S9 U. D3 O" `) X2 {: c
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
8 s( h7 r; l, p! U0 F9 r2 q - m_session->DeleteUndoMark(markDel, NULL);" M9 _0 ~ j0 P1 A- {, W( i6 C, c& Z, ^
- 7 w- \6 m1 K1 Q) R9 h9 c: p
- return true;
( a! z6 `' F& G( w - }% r! x! l2 w2 W* F$ |5 k; d9 v
- ' A" a3 Q7 a* y3 _- B f
- return false;1 f+ O! W. A; B& P
- }
复制代码
5 @. f6 ?+ @/ `! ^4 x9 v* \0 J/ @/ A( L Q8 g3 w! ^
|
|