|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点1 t# R* C. X0 @# C$ k
通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。2 q% p- a& l* |$ s$ t5 D& w
! r/ R! s; [6 H2 H0 v4 y2 O: G* } o' G# _
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)( T! I/ b! m. ]
{0 C! ?4 ^, H: f$ s& X. l. f
// Add your code here
; h: h( }: o% {- n5 |5 M; a. N" z CreatePointCmd *createPoint = new CreatePointCmd();- U( _) `( m! h: d; \/ I, l4 D
}
- }$ K8 o! J( a8 F- {3 A- u. u& U) M8 u+ q, I
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
. U! N' j5 f k7 C, n' }
2 u" M- [+ \$ V! gCATBoolean CreatePointCmd::ActionOne( void *data )3 b6 ~2 _* @0 m7 T, t
{
6 A$ ?8 N" u" b! S X- j) R2 o // TODO: Define the action associated with the transition
' P# \: n$ i5 E& s" G4 T // ------------------------------------------------------. H/ c; O6 Y! P2 {! {& h
CATMathPoint2D point2D = _Indication->GetValue();* c) x. I" c' ?, W- g+ D
CATMathPlane plane = _Indication->GetMathPlane();
1 A9 `8 g; \0 F# g CATMathPoint point3D;
. P: Y0 B9 _. T- U. c plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
4 C& F( ]' O9 q; O( z; @5 Z! q) o
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;0 |/ Y' U3 A6 V' S- f
. H' f, W8 W9 W% x9 A( v/ b5 ~/ I //设置Container(非根节点), [& E! A: @- Y* C" _6 q& j+ J
//获得Editor3 c7 `7 n' v! o
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
7 ^& C' `, ?. v //得到当前对象的文档- W* {: T# K: I5 ?0 \$ Q
CATDocument * pDocument = NULL ;
8 _& H3 Q1 y" e6 \1 R //取得当前活动对象
% O4 W1 Y8 _0 a6 o0 g CATPathElement activePath = pEditor->GetUIActiveObject();
; t( t7 H$ C8 E: n2 \8 b9 L //取得当前活动的product* L B# s" n, s' p
CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
5 r. C& |7 k7 x1 H7 D //当前活动对象不存在& _0 R" X, N! Y6 y2 W+ Z- U4 a
if (pActiveProduct == NULL)8 h" R/ W/ K+ w! E' z3 [5 g3 x+ Z
{9 A0 D# f! M- p+ a! H8 j6 _
pDocument = pEditor->GetDocument();
( F$ `' k( ? Z3 G }! M" D5 L2 N& T) o" o# p2 l* ~* }
else9 u1 k d( Q0 q' s K2 O5 n; D8 {
{
7 v: b: d" p+ H: ?0 Q2 k; p w CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
& ^' Z) F/ Y& D3 l; V( O: }4 d% a //当前对象的引用对象是否存在
! c1 l; |! ~! |; Q3 o, N9 g( V if ( NULL_var == spRef )
4 u) F E- d$ {! @) ^, H8 X9 Q: T {
3 D7 [7 @3 E9 g$ X, B return FALSE;, d$ q( Y' L7 T
}1 B! E6 }. i- C. r; y V
//当前对象的链接对象
3 V- e, N6 c7 n2 j9 J CATILinkableObject * piLinkableObject = NULL;5 [) {7 I8 E/ d: p: I6 p+ ~/ j
HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject ); 9 }% b- A4 x( @. d# c$ J# m2 ~
if ( FAILED(rc) )
" c* t' Z% d* c% p2 i {" j7 T" T6 P2 P, k# O; U8 R
piLinkableObject->Release();* T' A% [9 k o
piLinkableObject = NULL ; `/ a# E; e& _! H; Z+ K, y
return FALSE;
3 q, c" m0 d/ l+ d }
2 j8 D$ _: r7 V$ a //得到当前对象的文档' T- }; _0 t1 P7 P0 \" P
pDocument = piLinkableObject->GetDocument();
3 X1 k3 J0 C& g# R6 H piLinkableObject->Release();
* T, ~. X6 h7 I piLinkableObject = NULL ;+ s7 \/ p' ~1 T- L1 ?
if ( NULL == pDocument)
$ m) v" y8 p/ m: b' j3 A$ L {
, @' r6 @) A8 Q. Y' _. o return FALSE;+ \8 x4 f0 [+ R9 f: A
}
) z& g" o- \6 g8 Q }& \7 t5 j8 e6 G' f Y* \
//得到文档容器集
& c# ? c; }7 v) k0 |+ P CATIContainerOfDocument * pIContainerOfDocument = NULL;
. x! m+ S$ p9 o HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
% R' M8 ], f( }% Z' A2 P& x if (FAILED(rc))
; ^. y( r! W2 T* g6 y {
5 y! R/ N* ? }3 G4 g9 r& U# ~ Q8 U //pIContainerOfDocument->Release();
# X8 G+ Z4 z* m: p5 S; i( Z pIContainerOfDocument = NULL ;: ^/ Q% T, y: Q6 j
return FALSE;
2 q" w* a, s; p+ _0 y }
5 v! J9 |* `- a- I/ h% I9 B
2 P6 B0 i4 U+ ? R! F //获得Document
4 {8 w4 T$ @% z! z8 O0 O' k CATIContainer* _pContainer = NULL; 2 q# D `7 g" e% j
//获得SpecContainer3 ^, V( {: g$ V3 h5 W8 [* f
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);0 H, d Q* l$ @
) d2 o" w+ i i& E! T- z //GSM工厂% f( Z! x. r; w+ [/ @
CATIGSMFactory_var spGSMFactory = NULL_var;) ~- g0 f- q. a% c1 f
//设置工厂
) Y( o% ^* J# [4 W spGSMFactory = _pContainer;
. G9 d5 m) [# j6 H1 b6 q; k4 o& i% S CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);0 C$ g( A6 d$ B( X- ^) ]
CATISpecObject_var spSpecPoint= spPoint; $ d- r: V+ k, \* ^+ Z
CATIGSMProceduralView_var spSndPntObj = spSpecPoint;5 x) m4 I3 M3 ~3 h: @; ~3 U) q
$ H8 Q* L- U9 v; }3 L% L! v w //*将点显示在屏幕上1 U9 j1 d+ P6 }; h
spSndPntObj->InsertInProceduralView();* j J0 T3 e6 E% G
//更新点对象" S- N) Z" C& j- L
spSpecPoint->Update();
6 |3 H5 H5 E& u3 @# l% g
- q& s4 F/ ~8 P, R return TRUE;
! y0 Z7 @5 g/ J) A$ m {}
# K. N/ S, \9 [' O9 Q. |( u9 s3 o( T u9 k3 \; O
( e3 g" O: X E: r7 O效果如下:
5 ?$ [1 z" F+ _; o: l$ S0 n* P8 p( R f( K, ]. a
$ W+ h$ l. J( G; L g2 n# P( b. }9 a, F) {+ W
|
|