|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. H( a) H# b. O/ k0 k
2 r* ^# G) g8 |2 j& w+ @% A
如何获取选择点映射到视图空间中?源码分享& t) o! @- g( x+ S$ D! o U2 l
$ I5 w$ l! Y' |2 T1 ~# l' O
- //------------------------------------------------------------------------------
4 v* ~& ]5 b. C: g- c - // Select Screen Position and map to Modeling View Plane/ C8 n/ O: C3 q% t" X1 H) q6 ?/ V4 \
- //------------------------------------------------------------------------------% }2 U2 U. ]2 a& B6 J' g
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)5 ]: ~% a9 `( ?( ?5 x% L7 l
- {) r4 B% \4 X7 a
- NXOpen::View* myView = NULL;
3 r- R5 G1 P. s1 d5 }( d - NXOpen::Point3d myCursor(0, 0, 0);
8 h, P" y7 h! g, l- _- d
" J0 ~1 Y/ I- q- N4 Q- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
5 Z7 |( g& d3 b - if (myResponse == NXOpen::Selection::DialogResponsePick)
9 [* \2 a$ D- d' i) k - {
% v0 B& A1 H& r - // obtain the current default annotation plane where PMIs are placed on# K5 J7 y7 h) R5 p b6 b
- NXOpen::Xform *xform1;
! Y! l1 L9 j3 A7 P, l6 M3 M$ s - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
2 {5 G9 r# r% ?1 |& Y5 Z' G& E: l - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();' ~# n8 ~, T) b4 \
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();! x. d& @' _) f. m: w3 Y
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);4 c- \- R3 \2 X) X" k
# b. l0 `$ V% w. \1 p3 ]- // create the ray 'into the screen' at the selected cursor position! A% A8 G5 t2 M, h! Y4 B+ e
- NXOpen::Matrix3x3 vmx = myView->Matrix();
, O+ f% v0 j) n/ B9 \. w - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);- u ?7 o. b. R5 s- X: L
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
) C l/ W' f3 b2 Z - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);% A: v7 x$ W; }' O( t9 e- j9 E
- lineRay->SetName("Ray");
; @0 t0 Q; b) ^
3 S Y& F( s( ?8 P4 |5 D; @- // create the plane from the view to intersect with the ray7 a8 o; h* c- Q+ T( I* E5 P, |9 |/ [
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
* l) d1 w. I& c2 w$ G/ \ - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);$ n; R- n- Q7 q5 q g/ L
- planeView->SetName("ViewPlane");& q/ b( I+ ~1 E2 f
|, B1 d" o* Y9 ?- // now create the intersection point
* \ S: Q* a. ~9 K3 E - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);6 v( ^' Y0 a7 K% W5 E3 `, m# J- v: ]
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);6 \! H9 y8 h+ W9 I7 B. [1 M
- pntInterSect->SeTColor(10);
0 u, J# B8 M( {: }/ D - pntInterSect->SetName("Intersection");
9 `! R9 q5 W, P" i
@: n# X- e" _/ w; W- pos = pntInterSect->Coordinates();
. N8 k$ ^! B, m* A9 C - print("\nPMI Position:", pos);# ~# s) N; |' Q3 A
" [4 c+ z: r9 {+ P J% G. N- // clean up - comment to see intermediate objects
0 ^* y$ k' K/ H% { - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
+ a. h6 ?- E1 w { p4 t/ W; V - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
2 R/ o# o3 Z1 N. @# @ - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
) W6 t# b7 f& `# s: U% `4 U1 ~- N - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
8 ?: b! s# m3 d, e8 A& q9 F4 x - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
G4 i8 \1 S% X7 p7 U% C D1 w3 | - m_session->DeleteUndoMark(markDel, NULL);/ p% x9 M3 ^6 q. Z5 u* k
, w$ h& U* P1 ]2 \$ r- p- return true;
; N5 U% K# Q/ ?* N3 d - }
& i3 b& e( z) |( w& V6 p- o# G3 ^ - + f* w% u m- n! G
- return false;; q( i) c( t5 @) e; {! m+ V
- }
复制代码 9 B0 n9 H D0 s3 q! [5 r
+ y% }/ E {# C |
|