|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 ]: E% j% e3 V5 }2 C' L
: q* N2 C" a8 z9 b! z: G6 h& q: X如何获取选择点映射到视图空间中?源码分享2 T* a* ]( ^( O, l! e; q" @ Q
6 w' T' @% O3 M6 R. K6 Q5 _* ?
- //------------------------------------------------------------------------------
3 W/ ^; c9 D( T9 W! h- [$ k - // Select Screen Position and map to Modeling View Plane
8 k6 ]0 Z3 `5 d) C1 ^$ ^1 k" l - //------------------------------------------------------------------------------
0 a, N3 Q3 A7 c- @ - bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)7 o8 q$ d2 Y& Y3 N
- {- I9 J/ W1 J- U7 V8 n& S0 R2 k$ s( L6 M
- NXOpen::View* myView = NULL;
0 X4 ?* f8 i% v" s - NXOpen::Point3d myCursor(0, 0, 0);% b0 | J! x/ q8 j1 V- X M; {& B9 g
! n. p6 t) E6 |- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
7 s0 J$ k+ _. U/ j - if (myResponse == NXOpen::Selection::DialogResponsePick)
6 E3 b) B6 z& q5 |* K8 L - {! _- y) }* ?& g
- // obtain the current default annotation plane where PMIs are placed on
7 Z D3 z' ]; ?: Y' ^; d9 j9 i - NXOpen::Xform *xform1;
. W _, L) M) d3 j - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);3 F/ p0 e' ^) \. b6 {, |
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
( g! \3 s+ N, Z; G - NXOpen::Point3d ptDefaultPlane = xform1->Origin();
c, |# Z) x9 |$ f! V# t - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 m5 O8 X0 e+ V* [# W# N1 { U
- , ^5 [. D; p& d5 d1 Z
- // create the ray 'into the screen' at the selected cursor position
4 J8 g+ N+ X( s. k7 { - NXOpen::Matrix3x3 vmx = myView->Matrix();* }% h! h: T3 E) X* f
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
^3 J3 X) m$ O: E - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
' z5 r) G9 h/ P" j0 C- c- D, s0 a! g - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);9 y7 Z) Z" n( [: A
- lineRay->SetName("Ray"); e) d% I8 l7 V# G0 a
' Y! t1 F8 C0 S" h: o' ^/ ?" K7 |- // create the plane from the view to intersect with the ray
- {* P* i7 I! w7 Y) _ - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);1 @5 L1 d1 \8 \6 z' K
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
( u6 }( }! s p& S5 f - planeView->SetName("ViewPlane");0 O! ~- |, h0 o4 g) `
: {; Q2 a. n0 ~6 S- // now create the intersection point
. Y4 I: G2 }3 P% J. k9 `! a - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
2 j6 d+ a% w& [2 F - pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; ?0 w0 r% @& h i8 D: B - pntInterSect->SeTColor(10);! q0 C& D" {/ B' w x
- pntInterSect->SetName("Intersection");: Y) d: E3 O- C6 C
- P' k' K4 v$ ~5 } `, C* v- pos = pntInterSect->Coordinates();
; z$ h6 {0 l' P/ @7 B* z8 D - print("\nPMI Position:", pos);
' M, u- l( B7 |9 Q4 m
: ^/ {& ?( B1 [9 l" a3 X- // clean up - comment to see intermediate objects. U: X0 r/ P3 P
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");6 M; H2 n4 Z7 X2 ]" o0 G
- int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);0 I- P z4 v4 J. I; p* R
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);. o7 L% R( i7 {& D; v2 R3 ~
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);. K) D2 g; c1 ~1 P
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);" I; T: x: X# A* G9 N* L' {
- m_session->DeleteUndoMark(markDel, NULL);
3 \) t! t9 ?1 L7 D6 ?8 g - 4 s3 U, x7 [1 s( w d' c
- return true;% _; |/ l5 }" @* i+ J3 Z6 A/ q6 ~$ b
- }
7 e/ i% w$ u) i0 p9 }
" `$ o% b$ \! o! N5 S- return false;6 K& U& P) ~. R$ Q: R
- }
复制代码 ) w/ H; s+ p! }" E) x+ H% d. U A
5 ~+ Q/ `: d4 w) H2 [# g: u/ K e, W- S: _
|
|