|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, x' }4 \: }* J& k) l* s; f
4 C2 P1 f. P8 l# \0 t
如何获取选择点映射到视图空间中?源码分享3 Z; C. ^9 u3 r! r' s5 `& k& V- U7 z
* L, P& k/ f z! ?* [7 E
- //------------------------------------------------------------------------------: B6 |( R$ H/ z# \% g/ p
- // Select Screen Position and map to Modeling View Plane, q' D' M6 E# l5 P% o: [
- //------------------------------------------------------------------------------
: {, v+ u, r/ @+ D5 N - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
8 b5 [3 R* c- f: O$ C6 G - {
: ~. q! [0 q, j3 G4 { - NXOpen::View* myView = NULL;' i! W' F' f @- i7 V0 m- J
- NXOpen::Point3d myCursor(0, 0, 0);8 V7 L2 k3 }5 N
" c7 X7 I# C0 m" H1 E e- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);$ ^2 U* A/ @) D3 b _: k8 P+ T
- if (myResponse == NXOpen::Selection::DialogResponsePick)
7 N, M* f( E# ]: z- K - {
% ^- n4 L; U! O: u$ K! _ - // obtain the current default annotation plane where PMIs are placed on
3 {- `# g2 M, [ - NXOpen::Xform *xform1;0 {6 ]8 n, I- j& H% `
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
! L1 }9 s B j" F7 @ - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();1 O/ V" x# x+ t
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
/ `6 C' d8 R( a0 O7 r - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);- d2 L8 }, y4 z8 N# u
- ( B8 Z7 z9 g7 t8 {3 p
- // create the ray 'into the screen' at the selected cursor position a8 j; U8 m5 f- T0 E" k3 }! u
- NXOpen::Matrix3x3 vmx = myView->Matrix();6 U% b" a$ z" m1 {
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
) @. {* a! Z0 E$ n. G0 Q - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);; {0 w1 M* v# f3 z) ~
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
- B. F6 s3 U+ D2 {% q - lineRay->SetName("Ray");& ]6 Z* y: b9 }
- 3 x; R: Z) b) G) q
- // create the plane from the view to intersect with the ray
/ O% S( ^, r8 c, A- l$ \+ Z1 X/ i - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
' ^4 h3 X- a. { - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
( {: G# v2 x/ h; p+ o0 Y; T - planeView->SetName("ViewPlane");
. U: }, U3 H9 N- L1 m - . N+ b2 N/ \& K! B) a
- // now create the intersection point& I( ~, c3 d, v4 F
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
4 \5 f9 w. _* r" a - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
* W7 ` T* R' m6 X2 g D# @ - pntInterSect->SeTColor(10);
+ _, `9 Q. l6 n' p" j7 R5 X - pntInterSect->SetName("Intersection");# g# { g/ f4 U+ E1 m2 ~
- * `# @4 D; E! |+ M& j( V* y
- pos = pntInterSect->Coordinates();
$ d/ u( D4 z3 l0 H/ O( z% b - print("\nPMI Position:", pos);. N: u; e, j% ?
- 4 N" @/ r: o, a4 `: [
- // clean up - comment to see intermediate objects
1 n, c$ p4 h4 {& I - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");4 X+ Y; z* \+ Z0 [3 |7 m/ E \
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);, C C& w; |1 p* L
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- J% |4 n/ T6 {9 X* v
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
% @9 D: k5 z! n- }0 c - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);" Q( n) M$ H& l, N w
- m_session->DeleteUndoMark(markDel, NULL);3 [+ r9 |+ E& U2 N
R; ~+ W1 s( Y' w# a9 w% M- return true;
. K0 W* S o* Y1 i - }
, t# p0 l# r J
4 D7 |/ Z$ k% X n1 N. j- return false;! _2 a2 U! }- R
- }
复制代码
/ N x! Y) ^0 Q( a! k
/ u0 y" e0 c5 c' ]! \ |
|