|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" w3 d1 t0 B8 S. u- }' a/ n1 }9 @! Z$ o; p2 `& O
如何获取选择点映射到视图空间中?源码分享
- R9 L% h$ E& C0 X+ \3 g0 U, w4 c
+ d2 i- m6 Y' K3 H$ Y: W- //------------------------------------------------------------------------------
0 h* q) z- y6 R3 n. f4 Q E8 p. G - // Select Screen Position and map to Modeling View Plane3 [$ h5 v! c* H! A* j1 e. n
- //------------------------------------------------------------------------------/ L1 B/ K9 z4 w, H" r5 z
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
" y! G9 M7 w$ |0 W& w% ` - {
6 e! Q) L- \; Y" w) ~ - NXOpen::View* myView = NULL;
. G: ?2 d T: J8 J. } - NXOpen::Point3d myCursor(0, 0, 0);; x9 R( ` H, m, `2 Q1 B$ ^) S% ?
- ) J ^1 `& B$ `" o7 {4 y
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);' r* U( ]/ z8 P1 ]/ P3 ~, O
- if (myResponse == NXOpen::Selection::DialogResponsePick); @4 j. [ e; ~, [7 z# C
- {
5 {* d: o( }, L' n8 z7 j0 k - // obtain the current default annotation plane where PMIs are placed on
8 D: Y# V) v3 e. R6 A - NXOpen::Xform *xform1;
" ~1 [! } I7 j# y. H/ d - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
) I7 ]& s" ?' g/ u3 d2 ? - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
( h; s# R4 w' \9 ]3 q. D5 H% { - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
9 X( k% O' ]5 B) Y3 Y9 ^8 H - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);% a% N/ b2 N7 s! M3 m% |
9 V% T* E' V& z+ L+ K6 L- // create the ray 'into the screen' at the selected cursor position7 |' p% ?7 Z" i* s6 {
- NXOpen::Matrix3x3 vmx = myView->Matrix();
4 q2 c& n9 e! ?4 D - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
/ h" U: i+ }# N3 u# i - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);: S, p/ E1 @# |- L
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
3 s& Q0 L6 u1 v" Z" v - lineRay->SetName("Ray");
2 _3 Y' V' B; [/ E - 9 X- U% i' c% t. E4 o' P, c
- // create the plane from the view to intersect with the ray
% N" X; g' u/ _5 O4 m1 g2 X3 @% f9 M - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);# P; `7 S' G2 b! V Z: T( l# W
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
/ V7 s: a# ^" f* i - planeView->SetName("ViewPlane"); C X% v5 L; N* F9 F
- ; V# d2 I, H" j) P: B0 J# s0 `* ?
- // now create the intersection point8 Q k3 `) W/ l( d4 p! U* P! _
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
5 v3 S# ]! D0 i4 D S/ { - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; R" l& x! b5 H, B& e3 ? - pntInterSect->SeTColor(10);
8 B" }% F2 v3 [: W - pntInterSect->SetName("Intersection");8 y" }5 l5 t4 ?) `$ F/ Z! }
- 9 Y, ]# k* r* j" B+ L2 G; A
- pos = pntInterSect->Coordinates();2 Z1 v' {/ K; U
- print("\nPMI Position:", pos);: ^2 r8 K4 O) J2 @3 h
3 b- `& g7 y* ^' r' |- // clean up - comment to see intermediate objects
5 \# V+ A8 m4 N$ q6 O" X - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");8 |: _* Q' B) q0 V/ k( ]( I1 G: h- Z
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);9 L" `' ?( s. f4 R/ d
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);5 y' O" o! m) f
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
7 J0 T0 d8 Y& [6 Y# n2 T - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);8 \2 [6 ]# {; X: a1 s K
- m_session->DeleteUndoMark(markDel, NULL);! V0 s5 F+ ? w1 e; B2 X' N# I, Z
- 7 X9 K6 s# p1 L2 o6 b: r
- return true;+ N8 x" m, h+ q4 _% E _, |: K
- }" `: Z5 a; Q8 a) v( u' B8 Y
$ l) o& M. x1 N1 H' D8 u- return false;
, V k3 D- e$ l/ C" N* G7 ~ - }
复制代码
' n% Z) F6 c1 o6 }* g, v7 b
# P% `* u8 |) I* K6 p" ] |
|