|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 X& P0 f' P% q
. e4 Q# ]( z# A: T如何获取选择点映射到视图空间中?源码分享
0 G5 T4 `; u* R
3 P+ l, A4 R: n0 D% G; d2 R- //------------------------------------------------------------------------------2 f" n- V6 |# j; Z3 i( B
- // Select Screen Position and map to Modeling View Plane" G& f- r* C& y9 \% v1 V) ?
- //------------------------------------------------------------------------------$ Q3 q- \ y1 B. N& }: a0 d
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
$ s+ V; s& H/ D0 |, Y - {8 ]2 l2 `' w0 I* {) q: V* t4 T
- NXOpen::View* myView = NULL;
# `2 t0 u' v) m E, e9 X7 G [ - NXOpen::Point3d myCursor(0, 0, 0);1 d2 `6 A, z, r) y
- 1 P( l! U5 Y/ G9 W
- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);( G2 t9 [( ~1 J7 E! N6 |" W
- if (myResponse == NXOpen::Selection::DialogResponsePick)) d: u9 \& m) ^# Z
- {
7 }! F! n( Z( w8 L* l* x5 q5 E - // obtain the current default annotation plane where PMIs are placed on% B; o9 h' [' B' V+ ^
- NXOpen::Xform *xform1;
9 K; P+ o; j- J5 b- ~1 v! K8 n - xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);1 \# }) s3 g {9 ^0 c* K
- NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation(); M% ^- i6 m0 r5 W1 x
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();/ ]+ A/ K! v/ @( P& J# M' ^
- NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);8 t9 x. j* T" @- w+ V# T5 m" R
- - p( @: u4 t3 } w0 [7 H
- // create the ray 'into the screen' at the selected cursor position, q$ b) B; N9 {- e1 `
- NXOpen::Matrix3x3 vmx = myView->Matrix();* N# b, V* z6 V8 l' s
- NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
) S/ _- g" V7 ?6 W7 R! r - NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);5 z8 ^/ ~7 M! Z! L" A8 D# C
- NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
~3 [. Y9 P; M' |% D - lineRay->SetName("Ray");+ G1 v! @' n! k- x
$ B% O1 z' l+ o6 x- ^: n- // create the plane from the view to intersect with the ray; u+ B- O& r6 ~) E* y9 D: _, e [; e
- NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);" E6 D% Z4 s) p8 r
- planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, \ h$ V3 g, L! o( Y
- planeView->SetName("ViewPlane");
6 I$ P) U; @8 K4 S) f' L
g; k3 E! T" s. r3 E3 J$ c- // now create the intersection point
) J d6 A j) A6 J5 p( q - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);0 Z* J- j7 U! Z. |* Z7 b
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);# O( ^; v+ ~2 A
- pntInterSect->SeTColor(10);
3 T( d( L' N+ E \0 d! q - pntInterSect->SetName("Intersection");9 W. z) g/ h2 s# O: C
7 I( k/ v' E* Z+ G+ g+ I+ B- pos = pntInterSect->Coordinates();& V. V2 f; I8 N+ r9 V# v
- print("\nPMI Position:", pos);' f. ~; v3 x" r" |, b9 m. W
h n8 g* b0 M- // clean up - comment to see intermediate objects. O8 `6 A' f9 n0 e! F6 G
- NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
( v7 M1 z% L2 n - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
2 X9 g" J( q6 P' o9 T# b. @* F - int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);' m' Y. ~5 K* [! T0 U
- int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
6 t# g8 n i3 Z6 R! S - int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
9 L0 R! z; F0 g7 A, C" o5 \9 s - m_session->DeleteUndoMark(markDel, NULL);
6 i5 l4 O2 I$ f$ ]
' K, ?& L+ v( ~2 p9 _$ b6 }. y- return true;
6 C _- U6 v- h b* A" f - }) o; C+ D) S% D
4 F1 O4 B5 ^% ]- return false;! f/ }- [% D6 k0 N! I0 @
- }
复制代码
9 H, m: Q; e( F7 S& q/ j
- \/ q9 X" f/ D5 {, ]5 L. } |
|