|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, F7 P4 {# }" J: p4 |
8 K: ?4 ^' t# M* d2 D" Y
如何获取选择点映射到视图空间中?源码分享! f2 |; _0 v/ F+ \5 v
6 ?' Y9 ?& E* d" g! V/ H4 V5 Q- //------------------------------------------------------------------------------
' h/ [7 w7 n7 q+ d8 \$ D2 R - // Select Screen Position and map to Modeling View Plane9 T0 A9 b: H9 |* k7 @) S
- //------------------------------------------------------------------------------/ @* J! L/ P8 O' k6 W
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
* e, d' L! |4 U7 `& U1 w - {
2 e# W, W! b' d, m, v6 @ - NXOpen::View* myView = NULL;
" o9 z! ^4 Y) H( O, O4 R( E - NXOpen::Point3d myCursor(0, 0, 0);
& c: |7 S6 e9 D - - M" y7 S1 h% J& }5 f _: V! ?
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);, z9 [) O$ }, m. s5 d
- if (myResponse == NXOpen::Selection::DialogResponsePick)
7 _3 ]5 Q6 j' M0 |. c - {
! c* x: r1 i: J" q - // obtain the current default annotation plane where PMIs are placed on
% z7 _* T3 c) \- q: r7 R - NXOpen::Xform *xform1;3 e0 w0 ~ x8 K |3 N) u! Q" W* i7 O
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
% {; [) `0 E( y R0 { - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
2 M+ O1 Z" h, c' S% h: t3 i - NXOpen::Point3d ptDefaultPlane = xform1->Origin();, m, [: @ X# u* V# y# u+ ^
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
; d8 i* s) Y4 P* S! Y - 2 `0 P$ b$ f6 y/ k7 _
- // create the ray 'into the screen' at the selected cursor position
' w5 _, Q8 Z. d2 B5 w - NXOpen::Matrix3x3 vmx = myView->Matrix();6 B2 a: t7 I( k0 a
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);9 U2 P) m0 i3 v8 F5 G
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);# X, x3 T' Z* T4 x8 m
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
$ T7 s; j3 B- h) X( A - lineRay->SetName("Ray");
+ x, Y4 }+ s3 `" N# p7 r% n8 F - 1 T; g/ {3 [# m4 ]: N# n7 m' K7 M
- // create the plane from the view to intersect with the ray
- O4 S% P K0 s. a4 c% T - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);) Y5 G9 _1 C/ E5 F4 s
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% u* V2 R6 H) F v, b: ^6 e$ _' [
- planeView->SetName("ViewPlane");
5 Z0 k8 ^8 W7 L5 U# t1 B: @
- C! t5 g% o! P! n% U6 f- // now create the intersection point. Q+ Z& {- }$ [1 t% o6 q
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
% l! p8 F- t' @. ~) _# z) @ - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
: { s7 X( y" x8 }% c p1 t6 G, {! I - pntInterSect->SeTColor(10);" G, ~1 \" E3 I% X0 d
- pntInterSect->SetName("Intersection");
# d; s$ I Y- `7 |% @% x" Q. q" |
) t! p9 j& P3 p p3 D. O! x- pos = pntInterSect->Coordinates();
" y0 j Z. j# `! u0 {6 o3 l; g - print("\nPMI Position:", pos);! d$ Y$ e s- q3 [) f9 e; Y
. I6 U! J3 k! j; |, r- // clean up - comment to see intermediate objects
3 W/ z- A" c' I0 p# h7 M* D- J - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
) h, u$ d8 Z' p+ z; x J. _ - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' c, X, c: u4 A; r+ M9 f
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) O% G8 b$ {; a. m' h* p/ z* @' c
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
0 v% S; Y; Z4 \ - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
. J) D6 I) G7 H5 [4 }- {% s/ ~* { - m_session->DeleteUndoMark(markDel, NULL);( y& ]. k7 R4 E+ j
- ; y. ^( R& p; r$ S
- return true;
+ [4 ` T5 ?, g8 Y" f% y5 ^ - }
/ A# Z% B) B8 J5 V q; l
# m( y) F" p7 O- return false;; W- ^/ A3 m* ~: p
- }
复制代码
$ y" \" @1 B7 s- o( H8 B/ L2 T2 b2 N7 ^7 q- F
|
|