|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 U- W4 O% D, m9 r+ o4 G/ Y! {8 w" y& T! t; w0 B
如何获取选择点映射到视图空间中?源码分享* k6 m' v. ^4 t& K; P1 t5 _
4 ?8 x4 l; O! k8 Y3 P# i8 K4 x. I- //------------------------------------------------------------------------------' f: h3 A1 V0 M: b4 t B; \5 c* [( {
- // Select Screen Position and map to Modeling View Plane
$ [+ L- I7 y/ v5 @ - //------------------------------------------------------------------------------
" x- R7 z+ g, w& b( ? - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
" g" U5 p u* p; k0 Y* @ - {$ O1 e3 L; b2 A% X: W" ]# I& ~
- NXOpen::View* myView = NULL;
5 @- R/ j0 F) H# z# \ - NXOpen::Point3d myCursor(0, 0, 0);
* f% M# \* k( ?9 Q$ r: V - 4 |6 L5 i2 z8 f* x4 V m1 d1 m/ L5 Q
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
3 H. w) D$ @! @# s0 v - if (myResponse == NXOpen::Selection::DialogResponsePick)7 l9 n* c9 s4 o/ e5 x* b5 y
- {
/ [* E+ [: M' Z9 x! |, I - // obtain the current default annotation plane where PMIs are placed on
) c6 E8 e3 D m8 n, a - NXOpen::Xform *xform1;
, m) a$ b" W" ? - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
) w" T4 Q. a# O& K) d8 D - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
3 B9 v1 X9 i- M - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
2 y' R# y; \7 T" a' y - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
' X+ {" T" V+ Z# y - ! Z X# W- { b* G
- // create the ray 'into the screen' at the selected cursor position
K! L: N6 k: F1 d$ j4 F - NXOpen::Matrix3x3 vmx = myView->Matrix();
& [$ w: c& i0 _: }# }4 B$ P1 r - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000); S# H6 Z* g. a6 L3 N! Y2 e1 m5 @
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);4 y, |& c2 h$ w/ d- A _
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
. H5 a! ~; p+ n& L* ` - lineRay->SetName("Ray");
6 S# \* [- q* w9 B& Y& Y, U+ ]$ Y
, J8 R0 R3 E) d; M4 T9 b. k" v- // create the plane from the view to intersect with the ray
( z! I3 }3 {8 i, ?. T0 i - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
' Q$ Q! b' l( X: x4 v; ]" K - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);' _7 ^" u/ R+ Y0 @. @
- planeView->SetName("ViewPlane");$ f- Y! y- X9 I9 B# H* N8 p6 y1 T
- # `8 m! d- e* o& f
- // now create the intersection point& a, {/ c. B3 ]+ y
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& h2 { t8 D8 @! Y
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
+ [" b; a8 ^: _- T+ J6 [ - pntInterSect->SeTColor(10);
0 P$ y. Z. @# k9 N Y - pntInterSect->SetName("Intersection");
o( D" u" L% z/ K
; k( D0 ^6 p! ~- M8 y. v. A- pos = pntInterSect->Coordinates();
7 @. V- L- {8 W2 e$ W/ A - print("\nPMI Position:", pos);
9 J3 _0 X/ F# O- e; n$ L ?* w
9 a, V! x7 I t- // clean up - comment to see intermediate objects
% O9 X+ S" P5 N2 J! Z5 _ - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
' X- V; Y% r( [! E+ I - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);: L& ^6 V. T; G6 R9 j$ k8 s
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- Q: y$ I5 `7 N: C. T
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);& A& X) l; s, A3 e9 o
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);3 s% m+ c$ k G5 D2 q4 D
- m_session->DeleteUndoMark(markDel, NULL);8 g. Y) Z$ b! t$ y; O
- ' d# E* b$ ^ a" K/ o8 B5 z& x
- return true;
2 _4 S9 R7 e$ T/ I* }6 j; v8 b7 H+ l - }+ v' V( K4 q. {2 Z# o q" s! Z
- ! o. C) D5 g! o! ^, p+ V- A0 }
- return false;4 J- f: N/ g& J: c& j
- }
复制代码 R3 m; ]+ T6 q4 t) T
1 h- q0 { B8 G U7 x1 J |
|