|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ ?$ P i2 l( c( w
* t$ L) C1 |. n6 n( I6 s' t! ]
如何获取选择点映射到视图空间中?源码分享
- |/ M- v: u" T0 H8 l) N
@! ^* q, ^3 U! |( N9 b; \- //------------------------------------------------------------------------------
, l' P' j* J$ Z' P% g5 U - // Select Screen Position and map to Modeling View Plane4 q. O7 V7 j* @! c: n+ r8 P
- //------------------------------------------------------------------------------$ Z% h. j) U$ b: y! ]4 F1 ^: L
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)1 t6 n0 i7 `7 Q& o
- {, b3 ^0 f ]/ f; r
- NXOpen::View* myView = NULL;" `' d' J( A4 O" a6 n0 T4 |
- NXOpen::Point3d myCursor(0, 0, 0);
' p; N4 X- Z1 [) r+ l3 j. N; {+ D6 |
B Z1 u/ |; [- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);2 u9 i3 J+ ?0 h0 I* D- A
- if (myResponse == NXOpen::Selection::DialogResponsePick)
& e% b) W B6 c - {9 N# E/ ~9 Y! [0 c
- // obtain the current default annotation plane where PMIs are placed on
3 b0 z/ O4 P" M; e* C0 w - NXOpen::Xform *xform1;
& I+ i3 [2 }& S8 t) _2 @: d - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
2 ?4 h* V5 c- ~! e, z) ^ - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
1 C3 U y. D4 @8 ]* @. T2 ? - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
7 Z: K+ q( J9 F' g: I. q" o - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
8 n* e+ C8 t+ P+ a, c! `/ a9 f
, ~$ o. Y& L% g; U- // create the ray 'into the screen' at the selected cursor position6 r1 m8 M. ` A3 k# P c! x
- NXOpen::Matrix3x3 vmx = myView->Matrix();' C1 R9 w5 g* T0 j) ^: ]
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
! [6 f% O- t& Z. V4 W - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
, t; A! C6 X* P& j - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);$ B" A V9 ]! t- A! e
- lineRay->SetName("Ray");
9 A) V9 |7 W9 A0 E$ q
& U% p) ~/ e0 h& s0 F) ^- // create the plane from the view to intersect with the ray
0 ]" L* }! A K - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);- w7 ^8 Z3 K8 j+ ^; r1 K9 {$ X% v
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
5 \9 n/ d! j- j% ^. f9 n - planeView->SetName("ViewPlane");
3 c' z5 W, l2 \1 H
5 x3 k+ _, O1 [9 J h- // now create the intersection point
$ `9 w; p) c) L) {. O - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
3 B/ u( E5 @2 z4 m7 b3 H - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
3 d( H2 u. l _' g - pntInterSect->SeTColor(10);
/ s$ v, ^9 r& Z$ j - pntInterSect->SetName("Intersection");7 ~1 [" w" f* J! F) i
- 4 E# [( q6 C& |9 F- W+ }# s, M& j
- pos = pntInterSect->Coordinates();! t7 F4 h- ]+ E; u% Z( x
- print("\nPMI Position:", pos);
5 V& I6 n0 T7 T4 f L9 y - 2 g" X8 b" N# X4 @
- // clean up - comment to see intermediate objects
3 u1 O4 D/ s5 ~- @% B# Q# O - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");$ d5 p; A `) D
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
# O, r9 h" N- P! }" j. q, f - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& Y1 c) q5 m5 g' A B! M1 p
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
) r/ ]& X- k. u9 @+ c' ?5 l. _& ] - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
& |1 w" L/ X- r5 h8 T' ~+ F/ a - m_session->DeleteUndoMark(markDel, NULL);
! ~) j8 L( I/ N- N! `( x; W/ J - 7 k* @( p, B% N9 U
- return true;) o, U& f5 f+ Z: b1 f5 B
- }
. K& _& C' d# E& S" W) a1 ]
: M/ h$ t I+ `* x8 P; @4 c0 G& c( i- return false;) w9 A, o3 c+ N. y {
- }
复制代码 ; i* n* l& k0 n( J
; j& y/ E* E5 U* y& U
|
|