|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. l9 C' c/ r/ _4 {1 S- l
( y W3 v* l6 P$ |5 n
如何获取选择点映射到视图空间中?源码分享
! Z, d A4 |; b' |/ P- h% T% U$ V: n( g3 ?7 P2 c! c6 z4 Q7 A* D
- //------------------------------------------------------------------------------. s1 k8 ^5 ]% i1 N- S0 S0 Y! Y
- // Select Screen Position and map to Modeling View Plane0 l* ]. Y6 Q. ^0 m, B
- //------------------------------------------------------------------------------
, I, K, N- X2 S - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)6 P& f3 P8 a0 j8 |1 v/ L
- {
R5 G+ o: r! H- @& Z/ j - NXOpen::View* myView = NULL;0 X: q& d4 O: L. `0 p& z
- NXOpen::Point3d myCursor(0, 0, 0);* R) i9 A6 B" I8 G: P( t$ _& A ~" h
- - R7 H+ @# s# k$ e
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
" D) Z6 @3 x ^ - if (myResponse == NXOpen::Selection::DialogResponsePick)/ w, `! I; \) [- z; f
- {3 Y7 w/ | Y/ y
- // obtain the current default annotation plane where PMIs are placed on Z0 b9 i0 B! U3 x) L5 @
- NXOpen::Xform *xform1;
! t0 [; x& k. W/ u6 F - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% L. A7 N9 f q2 k w1 u( K
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();1 q4 j9 \3 l6 k: q/ `
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();0 i$ F9 v2 d4 v3 w1 R: S
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
' ~* Y3 k& z6 ^2 @" k* u
# z5 |6 ~, e9 I/ ~- // create the ray 'into the screen' at the selected cursor position6 ?0 C: h9 e& e4 J" {$ Z
- NXOpen::Matrix3x3 vmx = myView->Matrix();3 \+ w# ]: u& b x/ L7 q
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
$ o+ u9 h' a5 @. g - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
* @/ U& l5 C S( P9 B9 I# s& U# ^ - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);% O2 L- S& i' }0 g, V- P
- lineRay->SetName("Ray");7 k! r% ~. ]# i* s2 l$ J4 d
- 0 B6 Z" c3 e0 c
- // create the plane from the view to intersect with the ray
; m9 M) n/ w& f/ l6 D - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
1 y: r R7 J3 T; J$ B; { - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; L! S5 I' J* \$ E* K - planeView->SetName("ViewPlane");% f% @/ Q9 B4 f1 c' O
9 g, [+ J2 W$ |+ L7 S& N- // now create the intersection point
) @/ {' g# P! \( Y: n3 G - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);, ]) @0 }# X/ r4 E# E9 T
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
/ @) }3 k z+ i! z+ c& [0 G - pntInterSect->SeTColor(10);/ X# T" @) V+ f; g
- pntInterSect->SetName("Intersection");
: G7 D0 z* g3 S5 I+ f! Q - . z" |4 {) m" D/ }
- pos = pntInterSect->Coordinates();$ U2 o$ M. F) P/ f/ m
- print("\nPMI Position:", pos); y" ]. g: q( V4 P
f+ t- o/ d( a+ L- // clean up - comment to see intermediate objects
2 S% U v1 ?& i& h - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");6 v5 U& h0 a5 a
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
K% c' {* r4 c: F" L& a* m - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
9 Q, `, d4 k5 N/ I0 h - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);3 p( m7 J) M0 c! F/ ?0 h: @
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
' |# F, Z6 n0 g" M# \ - m_session->DeleteUndoMark(markDel, NULL);
5 E6 D6 z m2 g* J - 9 B+ g! ?& ^% Q+ [& v8 H9 v
- return true;! X! ~0 w3 k5 r5 E0 G* P! y; K
- }
" A3 u) k: p/ ]: ?( E2 F - ' R. t5 [6 M: `: {
- return false;
8 S$ \4 [4 l9 U& s - }
复制代码
7 ]% d" k* I* u) E+ {4 P
: }2 P$ E6 p8 V. x |
|