|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
% p7 O# S7 k5 w3 w% i: y
: ^& Y. ?5 m/ l) p+ K. s! I9 v
如何获取选择点映射到视图空间中?源码分享
$ o* q1 P7 x# G: J* t5 |) H& ]9 f* Y! c! h( v5 ~0 n. o
- //------------------------------------------------------------------------------
' X' l' ]0 W$ K* `7 m) K - // Select Screen Position and map to Modeling View Plane
0 K. J) R, r8 O - //------------------------------------------------------------------------------
7 E$ j. I! O( f - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)6 H d- y1 |# E, F* T
- {" ^ R0 X1 k8 m+ ]8 \. W4 Z
- NXOpen::View* myView = NULL;8 N% w4 x" F) |5 z: K$ O. n
- NXOpen::Point3d myCursor(0, 0, 0);
8 H) w# P+ Z8 D7 r* j - ) N2 O6 U6 z1 ]* }. i
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
M9 G, k' E P: e - if (myResponse == NXOpen::Selection::DialogResponsePick)3 r) u) i$ t( e( c& Q8 [
- {
4 `) _0 k$ n5 H6 F" y - // obtain the current default annotation plane where PMIs are placed on6 I% n/ n6 n! M6 _0 a
- NXOpen::Xform *xform1;/ a( d, D- B1 f
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
0 v6 D J( n, H' N - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();9 ~! C& Z8 o& L& X& @6 F O1 R4 B
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();6 T; P2 j5 m. Y! H
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
) J: p+ y/ c7 _% I3 _3 B - . D( m. K u# H" C& Z0 T# W8 D, Z+ B
- // create the ray 'into the screen' at the selected cursor position
E" ~' t8 P& `$ z5 M- x5 W - NXOpen::Matrix3x3 vmx = myView->Matrix();
" v& D4 p1 F5 Z& t' Y - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
9 n% g* C0 B% h/ G0 e& Y$ e - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
) q0 o5 p7 z. r - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
! `6 f9 W" J2 G; o" f; R K+ x- ~ - lineRay->SetName("Ray");$ B$ y6 u/ j/ x# B
- 9 ]& c2 H& J7 p, r3 m* e
- // create the plane from the view to intersect with the ray
, ~, B. h6 _' | j+ w - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
+ V v3 Z" ^. N+ P2 \' E - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 l& t" K$ g; `5 ?: V( n
- planeView->SetName("ViewPlane");
# i% q7 T9 \) }% g - ( ^# G$ Z4 n; u3 S k
- // now create the intersection point
1 r% |, L' U, | - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
9 t4 s/ a: h! K - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);2 u$ M) i; k. X3 L9 T2 ?1 X. q
- pntInterSect->SeTColor(10);
! j8 N" ]! s9 F8 S - pntInterSect->SetName("Intersection");0 l5 @, ?; D/ M- u) i8 _
. s" B% E: Y8 Y* f# c- pos = pntInterSect->Coordinates();" L/ G1 l( ^# e0 f' q. ]3 B5 f
- print("\nPMI Position:", pos);% [9 X2 R. {/ [
- / t2 d+ X( f$ S: L% z) d% m
- // clean up - comment to see intermediate objects
! ~- C7 L1 a( k" u0 R - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");. [9 r' e- S* W! ^4 a, E- }8 J
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
3 q4 ]3 C+ H4 b$ d/ ] - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);0 A& s( X+ d" _* d3 ^$ b$ Z
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
& }, ] ?, p) u4 s - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
7 k1 G4 ^ q; A5 x H8 H6 F- D - m_session->DeleteUndoMark(markDel, NULL);( P7 |6 _4 x: U \' d1 A$ j
9 Z9 ?. R" j6 ]: c- return true;
3 Y |9 S$ `; f, l2 q* ~ - }; a' k; m: p8 H+ Q
9 w$ e7 d* f7 q( w" F' x- return false;
9 g. a% X" _0 Q B7 j- ^, ]9 d - }
复制代码
8 g7 W3 O/ T5 h2 f; o6 n0 V& K4 R k! O) C* c4 J; k
|
|