|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点
, X2 O3 _4 W% M( e) \通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
! B# F% }* C" l+ [% ~4 {" u
: t0 b" _ I: S* Z- G# e# A
2 l. z" H. D" h; C7 G3 _void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
2 I# K z0 W8 V{
3 y$ C. l4 W+ @. [: B // Add your code here
0 j+ k$ ~5 r! }* W) l& o CreatePointCmd *createPoint = new CreatePointCmd();
; x9 r6 i C7 {- [}& B5 r y$ u) H
3 O* ~* S1 ]3 `新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
" b- N/ u: y4 E3 o5 e. a
. k$ S, ~+ O& {% c2 A' _( sCATBoolean CreatePointCmd::ActionOne( void *data )
/ r; P G# @ j* C( U{5 c: d) e3 K3 o: {% I( u
// TODO: Define the action associated with the transition 3 R6 A6 o6 E$ ^* ^5 S/ ^ O
// ------------------------------------------------------. f6 {' R3 I" \. j! y5 P
CATMathPoint2D point2D = _Indication->GetValue();" i% f& [/ I) Y- o1 M2 t
CATMathPlane plane = _Indication->GetMathPlane();: |" F6 b' e$ V5 M3 k. s$ z7 `
CATMathPoint point3D;
) a( R- ~$ F& E: w plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
2 Q2 R/ H2 c. J! k$ [* g! o) Y7 Q) k0 B7 I
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
o/ n: t2 l2 n
& e' `3 U' U- ]! y* }! v //设置Container(非根节点). V6 D( P% |8 Z7 u5 E. L
//获得Editor
( `. Q/ V" s$ e" f# T CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();: f) y& ?/ Y% w1 e: V5 ? n
//得到当前对象的文档
$ e, Q" y$ O( i9 o8 \8 j6 s$ ]( H0 { CATDocument * pDocument = NULL ;% O4 n8 W$ A; h6 ]7 `
//取得当前活动对象& H8 o8 C4 t' @' `
CATPathElement activePath = pEditor->GetUIActiveObject();
; e! R, |% t4 L7 W* ]: w' Y. Q //取得当前活动的product0 Q2 i0 \& \+ I# W
CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
6 c7 i! n- V' k8 F( b) a9 {9 q/ D: { //当前活动对象不存在
* i& U9 x6 W# J R2 Y8 R/ U) w if (pActiveProduct == NULL)2 F9 W) O* R! P
{/ I3 D3 p0 R/ f# i: e0 g
pDocument = pEditor->GetDocument();' l7 H. S- m9 O
}
( ^' C2 v( I, D% Q2 J& a( R: R4 M else8 e5 P9 L$ i6 W, m1 [$ e! _1 I
{
/ k' Y" f6 i* \2 i( q CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
0 a9 \+ R' z' J. ^! X ~' F' o //当前对象的引用对象是否存在
! p: o3 e; I& _1 I1 P* q" \ if ( NULL_var == spRef )% s* x1 e1 Q1 G5 V6 k* j4 f
{
- v% W5 f3 t+ S9 e( @ return FALSE;, I( j6 n; o# t( S3 w: T
}) }; E: n9 d6 y5 x1 @3 x
//当前对象的链接对象5 K M, l+ u; A" I
CATILinkableObject * piLinkableObject = NULL;
+ W' Q- b8 ]1 n$ v- {3 G! V6 A HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );
& A7 _3 D1 l! L& g- } if ( FAILED(rc) )
9 V# r, e' B1 a! F8 K {
" Q3 o4 \. J; c4 H' u' ?3 ]' c piLinkableObject->Release();
& P! \6 K+ a+ ]1 z piLinkableObject = NULL ;/ z* N/ | l6 V( S! W8 i! a5 m- o
return FALSE;& n; Y7 x# L7 O, K5 U
}
' W# V2 A' B9 }5 C* w //得到当前对象的文档
" Q# k; B, C" m; U( Q pDocument = piLinkableObject->GetDocument();
: D: F8 Y$ g! a$ r0 s& O7 B piLinkableObject->Release();
, u, ]4 l3 X* X9 K( K piLinkableObject = NULL ;# r4 [* W% Y, _9 w6 K: v% w
if ( NULL == pDocument)
# o: Y i0 e6 h. k: A4 g/ J/ [ C/ k {- J. S3 O9 K- S: V3 e8 m# P
return FALSE;2 x. s3 S/ p# o. A
}
( S# P' o1 t; }5 P$ q# m5 p }7 @; Y/ v( {, \
//得到文档容器集
# R- n4 U$ x# V CATIContainerOfDocument * pIContainerOfDocument = NULL; P D# M9 |! r& Z3 w
HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);% e& N' C& @% v; ?& B% Y( ]+ {
if (FAILED(rc)) V5 y6 z# J2 ^' @4 T. d' f0 | Y
{
# @7 Q) u& a) h5 D$ @2 \& j3 ? //pIContainerOfDocument->Release();6 I9 t& m7 q, Y4 [; |' d
pIContainerOfDocument = NULL ;
r: t5 V V% Z! X( z# L return FALSE;
2 d/ \( h. ~0 c: F }; Q: Q7 \2 @* u0 W
/ Y/ u, _; a% s X //获得Document
7 S( a) X% Z4 R, p0 a, a1 O+ _; s CATIContainer* _pContainer = NULL; ' ]/ y5 T. {9 g! e) C
//获得SpecContainer* @# O/ C2 E7 V, _9 J& w( N
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);1 T7 g8 ~# S, k: Z1 t
/ P6 \0 N3 z8 J$ D# C //GSM工厂
8 G. T- C/ x0 U, s; `4 t; K CATIGSMFactory_var spGSMFactory = NULL_var;
: y6 _5 S3 M; k' y, `0 d- v' l; l2 P //设置工厂 0 ~6 G% W& @, b
spGSMFactory = _pContainer;
+ T# e7 @' Z+ h" `- P9 ] [, j CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
3 z9 b8 ], M5 w% ] \- K CATISpecObject_var spSpecPoint= spPoint; 7 H* H1 B0 [* x, A
CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
" \: s6 p9 q4 Y) V s! _
9 d& w5 l4 j U( O //*将点显示在屏幕上
7 Z& n7 I" `! d; U spSndPntObj->InsertInProceduralView();
7 w6 P+ Z# V% v8 ~ //更新点对象
6 a- Z; e4 [% r: S5 r6 H spSpecPoint->Update();- U L& g7 q8 P$ J! t
& q* t! q* [, E% S( g return TRUE;3 Q+ f) Q4 C6 o) D% |3 g. W
}
- V8 O' Q% @/ ?, e
( A- f$ x% G& k: w# ?' j4 R
- ~) T. v. n7 o3 G7 i* b效果如下:
) S9 c9 D2 y4 a( D; g
$ u( X7 d8 l! |$ @' j1 d; a( p, {& H# C7 y- V6 A4 @8 q$ V# ?
/ T* \* J, D" m* a W, q4 q |
|