|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, A2 d* c' h6 b6 P
! z( q+ x. O8 h如何获取选择点映射到视图空间中?源码分享$ [4 F+ z3 n2 n
; F+ J( x2 p% i) M- //------------------------------------------------------------------------------
" v' `6 x4 `0 p7 p& d - // Select Screen Position and map to Modeling View Plane
- q2 x/ w0 h5 T - //------------------------------------------------------------------------------5 ^5 N7 C5 r2 q$ c; V
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)) K7 x! l7 P S8 n ~7 P+ {
- {* w/ C# U/ @0 Z4 l( z1 m
- NXOpen::View* myView = NULL;6 |- g6 D/ l9 Z' D& K( q' G, B8 I1 T
- NXOpen::Point3d myCursor(0, 0, 0);
L! L. E# y9 b+ q
+ W9 |8 r. K! p- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);2 [& h0 M7 `" J% F" `3 r
- if (myResponse == NXOpen::Selection::DialogResponsePick)
" L( p7 g& L. _( e8 b8 Q# o - {
* ~0 }4 F. {' ]& ?0 ^5 k, | - // obtain the current default annotation plane where PMIs are placed on6 C) `0 w7 T9 o4 b" E% l. A7 U6 `
- NXOpen::Xform *xform1;
r+ U4 t! f7 p. O; V - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);# O' a7 p* _- v, |' X: Q8 l
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
; q6 D6 A J; U6 A9 e - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
1 |7 E& G0 q0 Q$ s2 s1 h - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
$ ]% g; W3 V- Y$ Z% ^, c+ T - 0 y+ A$ Q8 Z8 K6 f+ b
- // create the ray 'into the screen' at the selected cursor position
. {# [" r2 z5 |. n/ T - NXOpen::Matrix3x3 vmx = myView->Matrix();4 D: {1 a. p3 e$ r! z+ j
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
9 H9 Q3 Y. C: q - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
: n# d$ _1 ^" a7 j; Q - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
; d+ D5 x3 v5 Y& r+ s- Z - lineRay->SetName("Ray");3 O2 V' P8 {% e4 N
- 3 E' b: K& N( i7 n% o G+ ^5 R/ J1 t
- // create the plane from the view to intersect with the ray
" \. Q: Y1 `; _* Z- @/ E J& l - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);$ {! |' [& V+ K+ ]) t
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
8 C! k& C! l1 Y- T9 h - planeView->SetName("ViewPlane");6 j3 m% c. j; B. P, a7 J# n5 a! t
6 k5 B" L+ C# \( _/ ^- // now create the intersection point/ Q; v/ \2 H3 t
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
: O) q5 X' U' x1 |+ V - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
: `$ R. Y$ K& E# G" R" W - pntInterSect->SeTColor(10);
# K3 [2 O, {2 k - pntInterSect->SetName("Intersection"); y) Z C$ k1 @, s
- $ {/ P* T" G. c. l9 Y5 W
- pos = pntInterSect->Coordinates();
# f: t2 q4 T: f5 e+ [ u - print("\nPMI Position:", pos);& Z8 n( N1 r+ t2 T
- , I7 [. H& U9 `4 G
- // clean up - comment to see intermediate objects
7 I& G/ r; o( o+ f; f+ ^ - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
, J; v+ l" S/ Q9 u# L0 N - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);# I$ h( |: P1 g v, B) h
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- k! I% Y* }+ V1 G2 M( B6 D
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
9 i: w; n) a6 ~9 p, C5 F - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);+ X0 S. Q6 ^' [3 q' p& ~$ ^& }: H
- m_session->DeleteUndoMark(markDel, NULL);
( e0 r. a1 N# J% O7 H" {( V' h# b - 5 j `% u) R* A
- return true;$ W: e0 U3 C/ ]1 b( f+ J
- }6 ]& p) r9 W, e3 v) c" ?
- 1 J" M: |" ^# l9 V
- return false;6 Q5 Y8 ^* u% k5 D; z8 w' ?
- }
复制代码
6 Q! z% C! ]- T5 [" [, @
# g' g+ L0 D0 C2 C: T2 K/ | |
|