|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ {) Z# H4 d/ a
U; s1 N/ B/ j+ h
如何获取选择点映射到视图空间中?源码分享& j" o# N4 M6 W
3 U5 u& a# j' _" b- //------------------------------------------------------------------------------" j& D- B* R q) ?2 q% k9 N
- // Select Screen Position and map to Modeling View Plane
; Q# V! g( {# u! ^3 ]- K4 `9 y - //------------------------------------------------------------------------------
5 F+ b* k$ s: p9 {9 p% { - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)8 C/ ?, R5 E G% h' }
- {
$ ]: Z/ M& G- c5 q4 h0 I$ C - NXOpen::View* myView = NULL;
% z! B( O, Y8 `0 y - NXOpen::Point3d myCursor(0, 0, 0);
) _; `+ i/ G7 M6 D - 9 O5 q) I4 K( `! m
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
* n( F+ b7 e7 h. r1 F/ f* _ - if (myResponse == NXOpen::Selection::DialogResponsePick)
7 Q B1 v' [+ r! Q6 J& R - {
! ~3 o6 g3 C) [' L+ h - // obtain the current default annotation plane where PMIs are placed on
! W0 @, j8 s: _: a% f - NXOpen::Xform *xform1;
4 `: a- X& z; x7 I - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);, o& m' g. b# N
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();; G& F3 D+ [; \* P
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();4 Y$ F0 S3 M( P4 T( h4 p7 x
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
4 P/ v* Q5 v! U5 ?
) ?3 N/ m6 p E% I- // create the ray 'into the screen' at the selected cursor position! q4 W7 n2 F ^& ?4 S) e$ `. i! z
- NXOpen::Matrix3x3 vmx = myView->Matrix();
" C2 ^! f: o' u( h4 I! h2 M - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
% K# Q+ s2 d* t - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
; N/ U$ k T$ {2 b& J - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);- {1 _4 i, j2 K5 \, {
- lineRay->SetName("Ray");
1 A4 ~) A* H$ h& ^
- u# }3 |. W; v# W' y; ^3 `- // create the plane from the view to intersect with the ray2 S8 ?& L2 D. y
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);1 `6 y/ V9 v0 Z& w2 h) Y
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
+ J# @# U* }+ Q0 I5 x. x- W - planeView->SetName("ViewPlane");
& o) b' X- x' o9 u1 b/ f4 S - 7 B5 @5 e" q7 h4 C2 [* k
- // now create the intersection point
. K$ |" q4 Q' \( x+ Z7 U- @ - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);( V# }1 B7 S4 A8 Z: Z
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
% ~0 W% Y+ z2 Y0 p6 V - pntInterSect->SeTColor(10);1 z2 Y* q- [$ O* o/ U
- pntInterSect->SetName("Intersection");9 {* P( ]* O& J8 X
2 Z( X+ y& v. O- pos = pntInterSect->Coordinates();
# i8 h" k- Q" x. ~2 P4 V - print("\nPMI Position:", pos);, P1 Q3 q& d/ G6 i( K5 F/ L# h" `
. @5 B+ F5 Y4 W. o, [0 ?- // clean up - comment to see intermediate objects
) r7 {8 J$ f9 j' N5 ` - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" { ^: {3 n1 ]1 E, N" [$ s
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);" Y8 d# E3 `% e$ c6 s# b( S
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& q/ f" v4 R7 m3 v) e* _
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
9 b, h3 \( \1 J; V* U9 c5 E - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
~" h! J' J8 M - m_session->DeleteUndoMark(markDel, NULL);( C' @ o' H4 B
! P/ D. [( z; h2 n- return true;' p9 r" z0 K) K2 n/ L. J
- }
; y/ B5 z- p+ P$ T
. @" o% H: m2 I' W/ l8 a+ A; B' U- return false;
# k# L4 S) a, C& m+ V* ]' B. E - }
复制代码 " [1 S9 B0 G8 d8 ]6 `( F9 @9 C
) T( }% d7 P% Y) _, C1 n
|
|