|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ H" U0 l* K0 i/ I& ^3 A6 K& f" u0 g& E# E2 V( C7 I' \2 S
如何获取选择点映射到视图空间中?源码分享7 i# {. u" \* l$ c1 G
p; B! w" w. V9 Z- //------------------------------------------------------------------------------
* Q8 u9 z/ `. m$ q5 z4 G' f - // Select Screen Position and map to Modeling View Plane+ t z+ s: V# n. V6 l/ Q
- //------------------------------------------------------------------------------
6 J" W; X- l& R1 }, i- u5 v - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
' \+ A6 k4 i! w' H - {+ `) d: U; W6 F$ {, w! ]3 x; Y
- NXOpen::View* myView = NULL;3 ^( z9 p3 ]+ [3 c- c; Z
- NXOpen::Point3d myCursor(0, 0, 0);
5 ?( o9 E* h( i. m4 ]3 N% c: D% r% k9 A
?$ d) M) T7 ^- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- C. d+ I# b* B. h6 y
- if (myResponse == NXOpen::Selection::DialogResponsePick)
8 W* R3 e1 J3 u8 a/ h - {
# l8 k6 J8 z0 v& l+ t9 ] - // obtain the current default annotation plane where PMIs are placed on
, u1 v& u' \$ J" z - NXOpen::Xform *xform1;
- p$ y' y/ h% H+ j' ^* S - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% D* B F* B! D9 l/ J
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();% ]+ F/ N5 ?' u( T! C2 J
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();! l8 b* Y( h/ S1 T- |. F
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 d ]& S2 Y4 p. Z
- 1 R: ?: u6 M) R) \& N& I
- // create the ray 'into the screen' at the selected cursor position
( j6 `# |6 x4 g, t" d Q+ Q - NXOpen::Matrix3x3 vmx = myView->Matrix();
; T+ l/ r, i9 Z, {8 R - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);8 y/ A# v; w8 n8 v" K
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000); |# ?9 l3 o* b
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
8 Z Z4 O% d. s! Q0 f( C - lineRay->SetName("Ray");2 n3 k$ Y4 G m) H9 q/ e
- ) f3 U; U6 o! x$ A) ]
- // create the plane from the view to intersect with the ray
9 N4 A) h. u. u) Z7 r! m8 ` - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);8 {+ s$ X& ]* Q8 O$ A* G
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);" G8 a) @" i5 S; s
- planeView->SetName("ViewPlane");( q7 n- {/ Q3 `
( k* q5 z H9 z: W- // now create the intersection point7 i5 _$ w( V& ?+ k( b
- NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
" ~$ x- t, `; ?5 P+ L5 Q7 O0 y3 i; X - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# e! v$ O$ A% b/ i7 Z
- pntInterSect->SeTColor(10);: [8 |7 G0 E! L$ C& C% O" v
- pntInterSect->SetName("Intersection"); K. f0 f- ?$ Z/ x: \% d! h4 v* h
. s+ w, W) q, A# V: p* e' D" g- pos = pntInterSect->Coordinates();4 y1 {* j% K8 M/ D% \6 K
- print("\nPMI Position:", pos);$ p$ x+ `7 u( A% C
9 }- j; E0 k1 _7 y- // clean up - comment to see intermediate objects9 b# V9 }% g; H9 Q, D$ T
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
. ~9 P- s1 f* {$ N - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
3 q) o7 Q, i* m: g! S3 o4 l3 d G# y - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);1 q3 i2 R F) ?* i. `1 B# w
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);4 Y4 R* E5 e& y
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
5 \( v. x- f+ E- K5 L1 f - m_session->DeleteUndoMark(markDel, NULL);
1 \. _ s) e: J' p+ B - ; N& O2 ~4 Y: t3 S
- return true;3 H2 L6 ~# `$ }* h, l
- }
1 g3 z- n- ~0 h - 3 P8 ~% H' I8 u' i& t f
- return false;4 \# L8 ?7 e; {9 Y1 b6 L
- }
复制代码
8 Y* C# ]$ U4 V3 M
" W d4 h# ~" ` |
|