|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点
! T1 o# t3 l. R# [/ ?通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。7 D' O, z' z, m) g9 X# `5 b
1 o9 ]3 b* A4 o; S. F! [. D4 F6 o: g; d8 F+ s A$ N
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)9 L4 w5 G0 l* m; [/ L5 k3 I2 ^
{
: u8 R4 ]! m! a$ W! l& F/ d // Add your code here
4 n3 _! a, o9 N3 ~! R$ s/ G; L CreatePointCmd *createPoint = new CreatePointCmd();
7 z" N4 s8 {) P$ c}9 t8 |' J8 l+ V8 F) \% m! V7 R
2 h- T4 @2 N. H9 n. b新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:* ^ ]& P7 p( X# k" {9 v
9 d7 r5 Y7 d9 `6 {: F+ F: t& ICATBoolean CreatePointCmd::ActionOne( void *data )# g& y# P5 n9 V% ?+ {
{
) j w. k+ ]0 S) F // TODO: Define the action associated with the transition 3 h" W/ X. S, Z
// ------------------------------------------------------ Z h- y- n ?
CATMathPoint2D point2D = _Indication->GetValue();* P( V" u) J) Q' s) O }
CATMathPlane plane = _Indication->GetMathPlane();8 A; R U m. V) W
CATMathPoint point3D;( b. N& k( G9 p, }
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);# e4 z8 M b8 a) o
$ \9 q5 x" g2 t* B' n& b cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;8 U7 M7 h8 w! N$ p
; Y& o: W, x# `- I+ L0 p0 V( g
//设置Container(非根节点)
4 D$ k( I& F& {2 G' }! w6 ]" X8 U //获得Editor
$ ?+ G% I+ W7 P+ b/ k% @0 J l CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
2 H+ I- y2 l1 R' L+ G //得到当前对象的文档* K' \, H8 {! y4 d- n- B
CATDocument * pDocument = NULL ;1 U& @( P4 X8 B& t$ I6 ?
//取得当前活动对象, R: g( g# G6 ^( \! K. z
CATPathElement activePath = pEditor->GetUIActiveObject();
& z$ f% y. F5 P4 y8 P& p //取得当前活动的product( ~+ O7 Z; D( H
CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());9 A6 \7 A2 T7 r$ ]5 x! _" q
//当前活动对象不存在) D# l- u1 n: A5 W
if (pActiveProduct == NULL)
& @ w O0 q$ P- r1 { {
6 H5 w, U0 a Y' z pDocument = pEditor->GetDocument();
) ]- S/ k; V( R }
% S/ e. K; m7 H' @ else1 h' o/ Y9 u( u8 f5 O5 z8 w j
{( O" K" u9 y1 n. s2 i, c
CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();& e8 [. p. P% }7 V2 }
//当前对象的引用对象是否存在& @& h8 v% [8 S3 i
if ( NULL_var == spRef )
. v. g# X) K% k; \5 C: l& K" r {: A3 p" |$ W8 \+ K4 C
return FALSE;
& ?- y$ x+ O: h2 h! p. y }9 V$ F G+ h2 ~$ s U; E
//当前对象的链接对象1 c3 \+ o; r: k0 F
CATILinkableObject * piLinkableObject = NULL;' I& v7 {5 L Z- f0 l; A* r
HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject ); : Z: }3 a0 C) @ r% Q
if ( FAILED(rc) )4 B: u; R# ?, H4 N$ Y
{# J, C' J' s" b9 A; \9 n. M) c
piLinkableObject->Release();
9 G! ~4 v6 O4 p; f piLinkableObject = NULL ;
5 j1 T5 w2 w( }" X return FALSE;0 u* D, x8 z' {: Z7 O, x
}
7 J2 _5 r# d/ U: @" e //得到当前对象的文档
o; n( t8 Y! O* t: s- \; {0 d pDocument = piLinkableObject->GetDocument();5 K3 o% x- t) B6 l6 L# {( P
piLinkableObject->Release();
3 m( Q9 a, m. I piLinkableObject = NULL ;, R9 ] ?9 b2 C/ l( ?
if ( NULL == pDocument): V- k& W w J; x9 o$ s
{
3 f0 c( w( E) D4 V; [ return FALSE;' q8 |4 t8 P% }: f' V) h) G1 ]
}
! h' G, Y# O# u8 d }
! A, Q) z, p+ n5 P8 ^; [( ]0 ` //得到文档容器集
5 p! E8 y! c) h. n0 t CATIContainerOfDocument * pIContainerOfDocument = NULL;* y, |2 O. r: ~, q9 |& z S6 u
HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);2 W( z& R: [: a! W d* e0 ?
if (FAILED(rc))8 }7 X/ C8 j( O/ k. c9 g
{) O" ~9 c& s/ O3 ^
//pIContainerOfDocument->Release();5 r2 c0 |" q. ?: M
pIContainerOfDocument = NULL ;
7 g# l- D+ r5 a$ h J return FALSE;6 Z7 O+ {+ W- F+ q
}7 ?/ l1 {+ r# p, i7 n$ V& s
$ f" o/ a. I5 ^4 @( {$ {
//获得Document# r( i7 `8 k6 N
CATIContainer* _pContainer = NULL; " `6 O' K- Y. {* h
//获得SpecContainer! }" Q7 ~5 A5 I/ E& H$ Y/ g
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
- `6 O% M. ]6 M3 G+ i
. A" C7 [ D3 F6 |: ]9 ]5 Z //GSM工厂
* V/ `7 Z7 `) y. @" Y- A CATIGSMFactory_var spGSMFactory = NULL_var;/ Q: ]: R5 H6 l2 Y# G' s( {3 }
//设置工厂 1 L8 ?1 v5 l& E1 W) {$ A2 [
spGSMFactory = _pContainer;
' I1 k. ]" C4 F, ]; P5 i. d CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);1 [* M1 B2 z& ] b- Z
CATISpecObject_var spSpecPoint= spPoint;
2 t' Y4 l6 q3 D1 | CATIGSMProceduralView_var spSndPntObj = spSpecPoint;7 c# P$ @9 V, e# @; ?3 K, l% T! n
" j' \! b$ R) Y% N
//*将点显示在屏幕上
- p! g, q- i) C. X: W# X spSndPntObj->InsertInProceduralView();
$ @6 A, D- d" a9 s //更新点对象
) ^$ V/ i1 O" @) y6 C spSpecPoint->Update();
|( m. I' i" T6 ^* S ) R2 O( B; V1 ]- c9 ~# ^
return TRUE;
) G+ v% k! ?' j, d. i f: w}
9 v1 V `9 }' P d5 w6 [
$ y' W: c$ R! b$ g7 K# A
7 [# o5 v( h) r2 d9 f; b效果如下:& m, N) ~6 D7 r, {2 w. y
. v* {+ B2 i" v* ]% n9 a5 d1 l3 ]8 l$ I% C7 A5 S* u% ]
( f4 q4 @* |0 Y3 t |
|