|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点
& d/ S2 _) R7 k3 k- D通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。7 {+ H2 p: V: O
8 I9 l5 C" E# }: J- R" B H/ v" R* I( K/ _% b1 k; v; c# ^( A) r1 Y
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
2 J% F! B2 e& e$ J8 J: j0 N, E \4 T{
1 z' V, w% S3 C5 Z! D/ P. W // Add your code here5 Y# [' |2 e# }4 P: t5 N
CreatePointCmd *createPoint = new CreatePointCmd();
7 j7 A- z w t$ }8 @}
3 w9 F0 i+ D8 y" R! ^
f! W( C$ s% S; W新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
+ y+ x/ k# y1 i ~: S3 C- g ?" W1 q8 a- w2 D; n' K
CATBoolean CreatePointCmd::ActionOne( void *data )/ N# k* u4 w6 V3 W. Q0 L# W
{9 i$ D% ?/ ]) A7 l7 m, Z8 g
// TODO: Define the action associated with the transition $ ^' D3 ]5 ]7 e7 r
// ------------------------------------------------------2 P9 B5 o( c9 W \4 {! t4 j; i) A
CATMathPoint2D point2D = _Indication->GetValue();# A5 |7 A! Z3 t m) r' S. c
CATMathPlane plane = _Indication->GetMathPlane();
3 h( }# z# X- ?! J9 O* v5 X CATMathPoint point3D;1 c; C3 P! ~8 M/ F" R1 P
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);! ^. O6 f n, ^" {% {2 [3 m
7 P" b1 `8 Q8 M1 @6 V. ~$ {6 M7 M
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
7 |0 ~7 z* c9 p/ t ; Q- c6 H$ j/ _6 s @! L3 `4 Z9 P
//设置Container(非根节点)
M- x6 _, k( v6 n //获得Editor
. X: P7 J$ ~9 B' e) p CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
5 b+ w& t8 ]) E4 g# S //得到当前对象的文档
- d8 _- G8 _$ z3 W8 Y8 I CATDocument * pDocument = NULL ;% V* O- v1 d$ K
//取得当前活动对象
7 H1 H% C( P( o& w x% W/ G CATPathElement activePath = pEditor->GetUIActiveObject();; q( _5 I5 h. F y [# Q
//取得当前活动的product
7 _. o4 |" z6 w# C3 a% d CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());3 a+ L( M* E& s: u4 b$ p, `
//当前活动对象不存在' s8 |' x( T. _$ ?5 J
if (pActiveProduct == NULL)
0 s3 @+ @ ]/ S+ R8 W' } {2 {& I0 t2 M" ]% i
pDocument = pEditor->GetDocument();
! M0 i. i1 s- T; g+ A% Y. G }
/ R$ e+ O$ ]0 h: d else
3 `+ `- }& D- Z" |/ Z+ o {
. d; R( J. o2 g2 W* c. A CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();) s; [# i7 J* S4 J! B3 S* A
//当前对象的引用对象是否存在
: T% V" f; u" D8 J { if ( NULL_var == spRef )
9 u* V9 k) j/ U3 n, _4 [' s {
* B9 t" T2 d+ }$ c: {7 e return FALSE;$ |; m) R% n( T9 y9 F
}
+ z. T* M% }" {: E/ X //当前对象的链接对象8 T, m1 B; B% g6 K( c- ^5 P" @# o& w
CATILinkableObject * piLinkableObject = NULL;5 b8 {& Q. U# {$ ^6 D
HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject ); q: I5 n( v v8 ~ _
if ( FAILED(rc) )' J7 K: _4 ^ p! E7 t
{
8 d3 [3 p3 q* ]8 y* O$ ~/ i piLinkableObject->Release();0 q8 u! U! E; R3 [4 T/ T
piLinkableObject = NULL ;
: O7 t( e3 J0 d& U! ^- N e) { return FALSE;
+ t3 I$ y2 z9 y }
0 t6 i% p0 d" ? //得到当前对象的文档' t" [* |, A; @) A
pDocument = piLinkableObject->GetDocument();2 R- Z- H# r2 O- L7 g
piLinkableObject->Release();2 p* n" ^1 P$ G7 z0 U' {/ h
piLinkableObject = NULL ;; T# V" M6 H( F7 S/ R' `) _
if ( NULL == pDocument)
; z+ y# V, z% e' r {
% s# ?. r" G1 i7 Z" C$ q n. r- s return FALSE;
* Q( |8 z% x0 y0 T* o. r5 U }
9 P' ^7 _7 @! t9 Z6 Y; ^ }' m) q0 g4 y6 D( r
//得到文档容器集
" |1 [8 s! D' u! c& D: L CATIContainerOfDocument * pIContainerOfDocument = NULL;
4 i, ?/ V# w. i1 _ HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
1 P& n* T, @; T4 o) N if (FAILED(rc))
2 g3 t1 G( K. M2 p& t. Y$ b {) B+ {" @. d( j5 O! l
//pIContainerOfDocument->Release();! G4 r" T; J5 X+ J" L, ?8 w
pIContainerOfDocument = NULL ;
& P1 Y: a7 m+ h) C1 c. b1 s return FALSE;% N7 |5 B+ w/ J+ B
}
" T, Q9 Q' D2 X% H& m 7 k4 S' X5 c' H w: p" l* m3 ^( s8 O' w
//获得Document% X- x6 h) ]# \! l3 o
CATIContainer* _pContainer = NULL; . n/ }+ f1 M/ Z3 U/ {1 r
//获得SpecContainer
$ b7 u% w' V, N, b8 c HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);& p$ l5 w6 p* e* `* V5 Z m7 A7 z- k
; v5 K3 l* n& c# c7 C. f( S //GSM工厂
9 A/ r# g0 A5 Y/ o3 L CATIGSMFactory_var spGSMFactory = NULL_var;
: l: ]+ y t' z" j3 l3 q9 R //设置工厂 1 ^) g7 x# n! ~9 L* v
spGSMFactory = _pContainer; 4 e7 s7 J7 n( W' O, G- N$ X0 H
CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);! j% ~3 z3 q. i8 B" N& p$ M6 f9 \. s
CATISpecObject_var spSpecPoint= spPoint; * q9 e2 u) H0 l, X& A4 n5 {" k/ \
CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
7 q# `: H7 M$ K1 P9 c; n4 z; v1 P+ U) G2 ^& D B
//*将点显示在屏幕上
& n+ A8 R+ A: a7 l6 c) [$ N0 d spSndPntObj->InsertInProceduralView();$ ?' @+ r1 S- I' p
//更新点对象' b: i! o; m- I0 Q6 ^7 L
spSpecPoint->Update();3 I8 _; Z( F5 V* Z! P
* H6 J: v! o, g; V; W: f
return TRUE;
9 a7 Z$ ] _: m0 I}
) e% v4 s, ^9 o
) ~ g4 b l/ E& m& m! }) r. d& t
9 v2 F7 m' {) W5 @效果如下:4 p$ h) x6 G! { w; Q1 q0 F& L
" K9 d" K0 i/ y
9 f# U- H$ _, F) Y7 b8 c9 \) U5 b% Y$ ?4 G1 m$ W
|
|