|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* j! C( g8 L3 t, }
0 `6 b9 k& @5 x4 B4 ^* O, ]如何获取选择点映射到视图空间中?源码分享
' S$ J. J. y* `( L% v
& k) {7 b9 A, [) j: {' G- //------------------------------------------------------------------------------4 T! _ ?: {3 p
- // Select Screen Position and map to Modeling View Plane
* U" Z5 F( p3 S2 d& S - //------------------------------------------------------------------------------2 K6 X$ g9 z5 @9 t. k" F6 ~
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
; \+ ?9 b$ I0 t6 d: S - {
4 y' f- a) Y2 B8 E. f - NXOpen::View* myView = NULL;+ d J3 [( Z6 M- j
- NXOpen::Point3d myCursor(0, 0, 0);, D8 k, _& J) g3 Y/ {9 L& W1 g" P
3 [4 @9 P+ Q8 S- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
7 M% o: X1 b" J( t/ S - if (myResponse == NXOpen::Selection::DialogResponsePick)6 D( `& `' U, z1 r# g8 h3 ^
- {
$ C+ P& _ ]5 E - // obtain the current default annotation plane where PMIs are placed on7 H: i5 Z* ?$ ^
- NXOpen::Xform *xform1;9 u& M/ ~! q1 c* K
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
! y A/ n( f8 E% P5 }3 _; F6 U - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();# G/ Y3 U: P0 T* R( q6 C0 G( B
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
: q0 k! ]3 z8 B& A: Z - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);' ^6 K$ y" \+ }0 V0 Y' J( ~; d
. Q3 J3 B" ^/ a) m) d- // create the ray 'into the screen' at the selected cursor position
4 w# f1 I# r$ [! c - NXOpen::Matrix3x3 vmx = myView->Matrix();
; k2 F3 X& [: H1 a - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
1 q% B8 A" j* B; U' d( A) } - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
4 l5 K5 d; h% N; K2 c - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
- x& P0 K" `( p! T - lineRay->SetName("Ray");6 t3 Y0 e+ t" t V
( r& o/ M( e5 |; ]. u& u2 M$ b- // create the plane from the view to intersect with the ray
1 Q4 d% B2 G% j0 X - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
$ A9 l8 R, }2 y - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
3 N$ x! i, s3 Z' \, T - planeView->SetName("ViewPlane");* l) D: F! f+ w5 F0 `* q, R
6 U% U L# s; s6 T2 ^- // now create the intersection point2 m! P* l# z* o$ k! p3 e
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);/ |* e5 e$ Z! f0 W: Y
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);- M- E5 ~- x! P" `+ I: Q
- pntInterSect->SeTColor(10);3 r" T* _& [. ]* ?
- pntInterSect->SetName("Intersection");
y; M5 W2 R9 ^; Y4 T- I# F - . [# G2 K6 s: T: U9 a
- pos = pntInterSect->Coordinates();8 \, \# s2 \/ C9 w5 u: t3 O* Q
- print("\nPMI Position:", pos);
. G) ]1 d) l& F2 s - ' K9 x2 z8 A1 ~
- // clean up - comment to see intermediate objects
0 r: ^+ {7 H/ @ Y - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" Z2 ?$ }' ^- x; K8 i4 ?- x
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
3 g5 n/ N( N. x! {" T - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);% |! u8 P. e3 @3 a* d
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);( [* v# a, u: Y; h( G7 a" o
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
/ H0 x4 V6 \5 u - m_session->DeleteUndoMark(markDel, NULL);
- [" t" e V5 X - 7 J9 u2 d* {! e3 H8 u- Q7 D: k
- return true;2 \( g: k4 X) @( \4 W0 j2 H9 w& T( F
- }
; g) r: P" L& b) `2 j) d - ( Q X3 h0 k* c# `
- return false;
$ V9 }* ?' d r# s7 S - }
复制代码 / V8 r1 h$ m9 t: { Z% e
+ P) d2 e+ k: L& H. c5 V( j
|
|