|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: P# a( ?# U2 Y! g u7 |9 J2 H
6 q% q3 Y7 r& j5 {, D如何获取选择点映射到视图空间中?源码分享3 P+ ^9 k7 g" ]# Q
; q# ^1 [. z6 m
- //------------------------------------------------------------------------------
3 V: l6 F& Y K) x - // Select Screen Position and map to Modeling View Plane2 A: o) r/ A) \' F6 J+ ?
- //------------------------------------------------------------------------------
+ l% d- {/ ]$ L* K* { n7 ^( M - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)% U5 h! U8 ^3 Z, V
- {: a L$ {/ Z% |% `: ?, V" W
- NXOpen::View* myView = NULL;( K0 j+ Z! H- n, p# H5 @3 B$ T
- NXOpen::Point3d myCursor(0, 0, 0);/ d1 l) k# H. s$ q* z
- # i- o9 Q) y" _" Z) h
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
% i$ Z- k. ~: a1 p, q - if (myResponse == NXOpen::Selection::DialogResponsePick)- R3 q b5 [- t$ v$ c! I
- {
) Q9 Z+ M! L1 Z* T. B - // obtain the current default annotation plane where PMIs are placed on5 v8 M1 P. Y- |
- NXOpen::Xform *xform1;
( Z/ q3 \/ ^) d( _$ R" u - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);1 [* A( ^1 e9 a9 }0 }! O- K2 n4 p6 j
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
/ u. R+ z" ~1 H8 y0 p, Q - NXOpen::Point3d ptDefaultPlane = xform1->Origin();' @- H2 v6 Z {' j* j' w. d
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);1 P" c$ U- q$ G1 s# {
- ' d! g/ M$ B- f% v
- // create the ray 'into the screen' at the selected cursor position. t) J4 o$ Y# T' h$ B+ {
- NXOpen::Matrix3x3 vmx = myView->Matrix(); l3 d, V, ~0 e* S2 t4 N; e/ p8 t% l7 q
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
. E7 ]& J: A9 N( i - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);+ ^- c5 g0 Q; X$ [2 ^: w8 f
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
) r4 U" h* R, c( A N, | - lineRay->SetName("Ray");6 h8 Z+ G' t$ i& e, W5 R% p5 B# a
( U& O' I$ }8 c) ?7 e- // create the plane from the view to intersect with the ray. ~# D" k$ O! L: T8 W: V
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
* {3 _* o+ T5 S - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* H' ~3 {* E+ M$ q0 ^" i
- planeView->SetName("ViewPlane");
( w7 H& q, ~$ D2 J$ O4 `9 L3 [
8 N( g2 ^% I% E, H4 n2 F: J- // now create the intersection point
* b) @' m: g+ S N' V. X - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);" e' c( Y/ C: b% [, @4 O
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);+ ?) e; |- m5 h$ Y' X, K8 w; Y
- pntInterSect->SeTColor(10);: a$ `, k& a3 A% }8 L* s
- pntInterSect->SetName("Intersection");
' }. ]* S/ Y5 }) \3 I
" X, o; w* x, L% V* D- pos = pntInterSect->Coordinates();2 T' J$ O0 c/ F$ d! P9 C& Z
- print("\nPMI Position:", pos);5 b% f( i, _# v7 |$ \
- 1 j, y9 {) Z% e( m0 [7 p
- // clean up - comment to see intermediate objects( r# `" N& B- t: | K
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
3 \ B# e; l; ]# ? - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
/ l8 M- L9 d$ w7 y - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
L# x3 o1 i2 H' K+ o; @ - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
7 S' |7 K; B" ?! E4 E! |1 p - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);& F2 K3 J+ p: K- g4 G1 u" j, u
- m_session->DeleteUndoMark(markDel, NULL);
" {8 e" n# C# A( i7 u4 n* ]: O' b9 @ - # l+ f1 u( h' C4 N: j9 [% A/ R
- return true;
4 G _7 d& c6 u( ?- ~5 o - }
) U# n- _+ u+ L, l! h3 [% d - & w- ^. ?2 d% f0 g ~1 X e0 f
- return false;$ n! I' K# L) @( q2 D. D, l
- }
复制代码
/ H. u* B, `5 M
* J7 t4 ?1 c1 ]: N8 k |
|