|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* d9 b' t! F. l `& e( t4 J3 Z5 ?5 o3 {$ P3 S( q* s& [
如何获取选择点映射到视图空间中?源码分享
* Z% m& Q+ t( m1 U" p% q" _6 z ^5 _, k9 e6 U5 ^
- //------------------------------------------------------------------------------
- w& `! Y) b) s - // Select Screen Position and map to Modeling View Plane5 ?4 u. |0 x+ T4 R& ]
- //------------------------------------------------------------------------------
9 d K- ?2 t" B' V - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
7 @8 b5 b0 x6 l - {) b+ A4 Z& f9 s6 V) n3 R2 H, \' W
- NXOpen::View* myView = NULL;
/ V, L- n' u8 n - NXOpen::Point3d myCursor(0, 0, 0);( |5 M* k8 ?% S' d( Z
1 d9 B: J0 k4 W* v- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
) G0 D+ G; w8 |8 Y - if (myResponse == NXOpen::Selection::DialogResponsePick)
/ c6 V9 L0 w4 ~& V% f - {
t' z( \, m0 R; e, j - // obtain the current default annotation plane where PMIs are placed on. l9 S3 b6 i9 s7 E* R
- NXOpen::Xform *xform1;
# q' `8 t6 J- r$ S. G; I/ A8 D% h; x# n - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);' r- Y7 Y1 p& C+ ]# f' i1 ~1 l
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();; W5 h$ a' n2 K: x7 b% F# s
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
! W6 L- ^9 N* `0 V - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
+ s4 @, k: E4 f( }# D5 G
/ u+ o' r2 I4 I5 q6 l- // create the ray 'into the screen' at the selected cursor position8 q L+ Q, s* D7 {$ E
- NXOpen::Matrix3x3 vmx = myView->Matrix();" q9 W+ s+ N# N0 E; r- e
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);( z0 {: \" F6 [+ O$ p
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
8 _& k$ u: G4 J/ P- S3 o: a/ F - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
; k% D: \) P$ Q9 y8 a - lineRay->SetName("Ray");
6 j; C. s/ N2 s, O
4 ]& u6 c/ Y; m$ f- // create the plane from the view to intersect with the ray( l/ C! {2 p7 ~+ o: Q# P/ ]
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
$ v0 N2 N- \# W2 v - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
$ v4 s) n* W+ i' @/ x8 g - planeView->SetName("ViewPlane");
8 @1 R9 L9 w, B i6 Q' t6 G
& L+ u$ x* d5 L0 Z$ c2 i- // now create the intersection point
6 \; k7 \5 ?+ {# h4 Z - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
e/ {) B' k7 Z) F. | - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. k, O2 v1 H+ V& o4 [7 O
- pntInterSect->SeTColor(10); q G! o& A8 x# V8 s+ T {
- pntInterSect->SetName("Intersection");. W. [4 D+ K7 J7 j3 M4 |$ q
: l+ @8 @' y: U9 t' _! s, L- pos = pntInterSect->Coordinates();
8 V- ^, k8 h' Z0 Y2 @ - print("\nPMI Position:", pos);9 o" ]& t2 A( }
- . w) s7 `4 a2 n
- // clean up - comment to see intermediate objects
9 C( N( @8 C' Z/ I9 T0 J - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
9 ` s3 {3 L8 ~5 h+ Y3 d - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
( ~, v$ j$ T( S1 b, S/ R0 h$ p. T - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
h( J. A4 U K- a - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);3 u _3 e, b& J( t
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
# W s# S) o( y _- w8 f! q- s - m_session->DeleteUndoMark(markDel, NULL);. l+ z0 ~( P* g% M
" B! B. W* p, p. p: }- return true;$ L$ A" r1 y( S! C& B3 W
- }
4 u0 x/ |# C! n1 d
/ J* ~! v$ Y. f: K- Y, a% Y- return false;' n# v7 g* W( s. w E0 D
- }
复制代码 + A' u8 |( G& e! g
, G O& F+ ]8 E# I2 ^
|
|