|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点
: F& q$ j( t, t: `通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
) T! ]3 X% c2 n, B6 m* b( X0 y ?- _
0 {, d- e& ~8 {2 E# w/ J8 M8 r* p2 B
1 g' y, S8 Q" r" ]8 [void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)% E0 j9 G' Y% b) }$ M
{ m! H. N% x( D/ g/ [" }
// Add your code here7 H; J) P6 _, v$ { W/ f$ N
CreatePointCmd *createPoint = new CreatePointCmd();# d7 u( W4 M5 k/ E8 `
}
' i# a. z0 p' k+ P9 Y" T& C* \' ?, f: o# {) D6 U- R, J
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:9 p9 @+ x/ D- Y2 [, E& v: Q
" s0 H, x+ ^, @" JCATBoolean CreatePointCmd::ActionOne( void *data )) U7 @9 `: y& U; a
{3 M, R0 r6 b5 a
// TODO: Define the action associated with the transition 6 ?! R% @; [1 T& ~# _3 d6 I% Z
// ------------------------------------------------------' P' ?/ X! _! G6 N5 Q
CATMathPoint2D point2D = _Indication->GetValue();
1 L ~3 {) d1 [, r( S2 t6 ] CATMathPlane plane = _Indication->GetMathPlane();
6 b( U4 T m' |3 {, ?# B CATMathPoint point3D;2 ?5 O9 J/ _- ?# o# E8 `
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
& d( @% F# M. A: u
+ P! W7 n, F' V: } cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;. G( Y& s+ o4 V2 t
5 y; M* ]( J9 z" S& B //设置Container(非根节点)
" @% ~: p7 _' q //获得Editor
+ ^' @7 `" X5 `. J; ^$ ` CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();. o* S5 {, P4 {
//得到当前对象的文档
& v2 ~4 X7 o, ]# H, d* B CATDocument * pDocument = NULL ;/ e5 w0 K/ @0 e8 f
//取得当前活动对象
+ U) o8 E3 g- }, ?/ M, Z CATPathElement activePath = pEditor->GetUIActiveObject();4 }8 [! `+ d* W
//取得当前活动的product
' e8 U( s1 n) \5 {/ o CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
' j& a1 y1 b. O) e, @" l( N //当前活动对象不存在& d2 s6 D2 d0 W0 ~0 W" t' Z
if (pActiveProduct == NULL)$ @3 r# z$ W3 N0 y' w) M; J) K7 L4 W1 t
{3 I. k! T: h9 t2 L4 a% ]0 a
pDocument = pEditor->GetDocument();
/ o/ f' p. D1 C }$ Y5 }1 E+ C0 z; b( N
else& f0 w. C4 Y5 `9 t$ z- T
{* y! F4 z, M* J& ~
CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
+ T( Z2 m b: D/ z f9 U //当前对象的引用对象是否存在9 ?1 |0 r! l" W% ^
if ( NULL_var == spRef )3 o! T s- S* P* K+ c8 D
{
2 J2 v: M8 w! C, H6 w, G return FALSE;
4 p) f3 t9 o8 k) h# K }$ Z9 x! S; s/ J- L5 x0 v: U3 a
//当前对象的链接对象8 m5 d( z, }- q' S/ \( n
CATILinkableObject * piLinkableObject = NULL;$ I) s" i; E6 A2 n/ ~: ]* P9 C
HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject ); 4 g+ D; q" O5 Y& \
if ( FAILED(rc) )
3 f5 V7 _2 B) ]9 ^ {
0 m- G+ w# i C+ @* m$ z piLinkableObject->Release();" i, c3 o7 c+ u, ?0 S+ o
piLinkableObject = NULL ;
) A. `# n4 H4 _ _4 a4 Q return FALSE;
& w( h7 J) G" m: h% }4 Z) d% T! x2 e }. q. r- r9 q+ b" `( f
//得到当前对象的文档# g. e% Q1 H0 |& ~0 S
pDocument = piLinkableObject->GetDocument();
" U0 n8 l$ B' f9 a* Q2 i piLinkableObject->Release();9 X6 K' R) J0 s% U; B) k# A; }
piLinkableObject = NULL ;
9 w, g3 O; x: o! K9 [ if ( NULL == pDocument)! L T4 `, Z1 R1 j) a: v
{* B0 b2 L4 }: r2 y; w8 \9 B
return FALSE;$ h& [% V2 m' B1 d0 g3 H
}: t( z e' I5 T% I9 ^4 S
}
8 d. Q. A C% t' h //得到文档容器集; L8 W: g/ d; w) N0 d
CATIContainerOfDocument * pIContainerOfDocument = NULL;4 m. k* J- Z( Z7 ?. \; z$ v
HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
/ `- W9 M! {0 B& t" N7 A if (FAILED(rc))
% B: x# A# @) w' u) R {
, Y/ u2 W+ R4 i3 B. b //pIContainerOfDocument->Release();
' D! N+ Y/ E9 C! ]5 T2 Y pIContainerOfDocument = NULL ;& j) _* k0 [& V+ d4 O3 |9 V7 B
return FALSE;5 X- X2 t/ g, d( i& t" `
}
, c+ W9 @3 c* k3 r; e' u
9 `* ~& i8 Y+ I //获得Document
8 }) l3 i: v, p4 J3 |5 q2 q CATIContainer* _pContainer = NULL;
2 [3 s* P& |" Y0 _% O0 U //获得SpecContainer( N4 y& i5 Y" D8 l- F, C
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
- z& ~/ f0 i* T$ O3 b- W
9 \7 @- d$ b! I //GSM工厂1 O2 i7 [6 Z+ c, W1 B% f6 H, i( c
CATIGSMFactory_var spGSMFactory = NULL_var;9 Z7 N8 n3 C8 M/ Y
//设置工厂
( I; Q- v% [+ @& m spGSMFactory = _pContainer;
$ J0 I. {1 n' ~$ F0 y6 ~, j+ ] CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
6 ^( ]- W; `0 I CATISpecObject_var spSpecPoint= spPoint;
8 G* ` q( w, [$ e L; y M4 G P$ C CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
- i# S3 R- K: p+ e4 {. @
4 T! ~7 |2 c. g! h //*将点显示在屏幕上: ~! ]! c0 T% E$ _
spSndPntObj->InsertInProceduralView();0 ]% U( Z2 }( I" O1 F/ ^" h
//更新点对象
# _" j' r8 D4 l: ?+ X spSpecPoint->Update();
8 a9 L: J, A/ V; I1 {, ?2 [ X
# c9 U) |& e8 r4 { return TRUE;7 {8 }: R# \/ o3 `& p( m- k
}! l. R) a- G% U) F2 g4 J* H( j
& @. v7 D8 E! g1 F" K7 q3 W+ V i# E. o( x8 Y
效果如下:9 f+ R) W) S8 I: e/ V( q
" i. b0 T* j4 p- V( W- G
a9 z; S: h$ {9 n$ e8 e
: |& A n' Z/ C. M |
|