|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 Q F1 I0 r1 \7 J
/ t& U& w. Z, |( I0 M* a如何获取选择点映射到视图空间中?源码分享$ @, Y% Q5 }7 I9 g* p9 y1 q6 j1 |
3 \7 r! A' l! m. c% v( ?" I- //------------------------------------------------------------------------------ U1 ?! ? e. @; J0 S
- // Select Screen Position and map to Modeling View Plane
3 N/ f+ c( E9 ^ e7 X - //------------------------------------------------------------------------------8 H+ D) p C1 y/ W5 ^8 `7 y
- bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
% f# N/ e3 t* g: _9 O* j+ p - {9 w% C5 R# U9 G/ o q& p* x, q% W
- NXOpen::View* myView = NULL;
8 ~/ t! Z8 _% S; e( Q) x - NXOpen::Point3d myCursor(0, 0, 0);
6 x5 A- m( |; f5 @! S$ R# x
3 P8 c$ t0 [* r: K0 u* ]) _- NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
; j5 t4 a) C% S+ b3 l - if (myResponse == NXOpen::Selection::DialogResponsePick)/ ?- o8 S/ W2 g: f
- {# N/ [" n% e' ]; R. s1 c+ y: g: h
- // obtain the current default annotation plane where PMIs are placed on9 W; r4 [ t( {6 B9 I, }, M$ {
- NXOpen::Xform *xform1;/ V* `3 d/ N7 J: L% |
- xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
3 S6 w& D4 J2 { i" k - NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();# X9 v4 Z) W2 C ~1 Y
- NXOpen::Point3d ptDefaultPlane = xform1->Origin();
2 V# y8 j6 j6 S! T6 h - NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);9 ]6 T1 `& g. A i1 s
- 5 N2 V" [5 t' b, u' V
- // create the ray 'into the screen' at the selected cursor position8 S( E" _2 i9 h$ V2 A+ J5 Q4 l
- NXOpen::Matrix3x3 vmx = myView->Matrix();
# l' N. Z; [6 V - NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);$ u( N1 {5 S8 h6 ~& n+ x ^3 D. c
- NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
% S% P+ E4 `1 L; j3 Y - NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
9 J, B1 F# Y0 |2 W! h+ d - lineRay->SetName("Ray");' ]0 D, s6 {1 |# ~
- * A6 p2 b U7 j' z' S& a5 D
- // create the plane from the view to intersect with the ray
4 w9 i A$ v. L* ?/ @* T& u/ j' u - NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
# I7 q. j! O+ @8 | - planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
; v/ |& X5 L6 x2 \$ o - planeView->SetName("ViewPlane");
6 u9 i/ y! X k0 f* P - # D6 o( A" Y, y* p2 z7 X
- // now create the intersection point
5 V1 {1 x" M9 H- a; N - NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 ], y$ {' L" N" l! A
- pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 q ~. j, X2 l5 Q% U6 h: n+ r
- pntInterSect->SeTColor(10);; h5 F! M8 r4 D/ k! N: r6 `
- pntInterSect->SetName("Intersection");
0 V/ _( J0 ]% i4 S& ~7 C
+ l% {) M z1 j3 v5 t- pos = pntInterSect->Coordinates();
2 B$ g. }6 K" H8 q( ?; ^ - print("\nPMI Position:", pos);
' q3 j4 ~+ U5 i5 h4 G - . f) Q5 J# u% h
- // clean up - comment to see intermediate objects
& o0 ^' g* J) P - NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
& q2 K, h7 h; }) b( d4 n - int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' l& h0 E$ B* z6 ?
- int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
8 c$ l* A5 W' i- a% D: u - int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 u4 Y9 I- @5 z+ c8 l
- int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);# w4 ?& T3 p4 @! D4 ~) R
- m_session->DeleteUndoMark(markDel, NULL);
! j& u$ Y. ~% \$ X+ D J/ O6 p+ x, v0 L
4 Q W4 V0 F R t' N1 k7 b- return true;% k5 K$ [" q! F7 l3 b. c; _
- }7 V# ?5 y* R6 @5 @; E& q
- 1 I: W( W1 {2 V$ s
- return false;
% K1 ^5 O% I/ t" d - }
复制代码 % k% Q' Y% C+ j
& \* q! U& W! F$ H. W$ U9 v
|
|