|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* M: V! q3 K! Q: S8 c2 k
+ W3 E9 U3 I+ M2 [- q. ^* W+ V如何获取选择点映射到视图空间中?源码分享
$ Z. V: ` ^# e+ w$ F3 I4 W; R* g: R
- //------------------------------------------------------------------------------
* q, d+ {2 j8 s$ O - // Select Screen Position and map to Modeling View Plane
) Z, ?, O; J* `8 p6 p; p" x - //------------------------------------------------------------------------------' R% q" u3 f& I' w/ [% e% r7 j
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
9 j5 M/ n' F7 P& X9 Y7 Q - {
! `2 |1 q9 [9 G8 B6 H - NXOpen::View* myView = NULL;) z& V9 j a4 i9 T8 T
- NXOpen::Point3d myCursor(0, 0, 0);, ]2 ^. D, u; a# y9 m G* y
) F, t+ B( F) v: V* f: l: |* L" d- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
/ q. d. B4 R1 f* f3 t5 V! U - if (myResponse == NXOpen::Selection::DialogResponsePick)
4 u; `; N% r- H- @ - {
- S w7 I: h9 U* }2 s - // obtain the current default annotation plane where PMIs are placed on I; y2 ]. a+ J# N' |' B4 A% g
- NXOpen::Xform *xform1;6 }2 ?& I! d7 {4 H1 z
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);; Y' o) b/ o* Z1 X* l' T
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();, }9 g9 G3 M6 \$ S M2 w- e4 _+ y
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();$ Q1 P7 v# e, u) g' `, F
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
" g% o( r. M, d$ B; D4 Y - ! D. I1 Y# c3 Z% m7 L
- // create the ray 'into the screen' at the selected cursor position
# o7 B- Z1 o& [1 J, k - NXOpen::Matrix3x3 vmx = myView->Matrix();
, c" n* d/ M: U7 i - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);# G5 a! @% ~: E
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);9 z% @- ] P% R. a6 l
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);+ h2 R5 x& ~9 p# K; A
- lineRay->SetName("Ray");' w3 l3 Q) }' ?, K' l C
- * E5 d7 S w8 G. v a# f1 w; ?
- // create the plane from the view to intersect with the ray3 O3 q C d7 v' e* |( d. v
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
$ | I& m+ K5 `, ` - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. j" p0 r* ^1 n2 I/ }$ Q6 A0 m+ J
- planeView->SetName("ViewPlane");
# `0 P; p3 U, u# S8 m - 4 C2 h- }2 {0 C- r4 P
- // now create the intersection point
& f1 @) E. I$ ^! X k7 A5 I( Z7 ` - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);) k; @( n6 X6 H
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* L+ F) r7 r% I& M' ^
- pntInterSect->SeTColor(10);
! s0 G/ C y2 y; p7 Z - pntInterSect->SetName("Intersection");+ Y: ~+ \ Z: U, V4 P! A# G, J3 w$ W
- - D9 G, H& Q6 h( s+ }- U0 j, n
- pos = pntInterSect->Coordinates();5 E: ~ ]# |# i& h/ {! i
- print("\nPMI Position:", pos);. H9 m+ [9 X, a4 G
- 0 _- }( \5 N) P. u
- // clean up - comment to see intermediate objects1 c, L3 r, u/ z0 R6 ^' h. x
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");3 |; P+ ?, M7 w. p7 D
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
3 z$ a6 E; p; S- ? - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);' Z. N9 w/ W, \9 [" {' S
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);* L4 ?2 j+ C. K% D9 ~' p' k
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);% T: ~3 E' y" Z% {9 L# T
- m_session->DeleteUndoMark(markDel, NULL);
, U( J- Q" ^, \9 M% L" C* o S
: \+ q# Q5 q( m9 @: |- return true;$ Z5 c( l9 L5 | q
- }- Y5 q5 c3 z2 F! h/ S7 J v5 \3 C
& f% @7 [1 `) E; a; {2 z. G$ k; I3 B- return false;9 y! Z" i9 F0 W$ [! ]; z& T
- }
复制代码
4 O2 g4 U8 Z H3 e( T% j
U' Y; e* B3 b) k) Q |
|