|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
CATIA二次开发入门教程---15 通过点击屏幕创建点
# }' l0 ? a9 C8 I* i' X通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
5 y. O* s+ a& B% L. N9 k* j9 _6 ?3 P
3 r8 O0 u! Z# U% l( U
) \ b0 z8 P- B* wvoid DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
4 h/ [: T* q2 o; c4 S: W4 B, {: F{
2 Y5 _+ [7 o- M. q" m // Add your code here
e+ t6 x9 {& @ CreatePointCmd *createPoint = new CreatePointCmd();
: T3 ^& Z& C. m: ]" L$ c7 Z1 U}
2 g( a' n5 c) J$ i/ ^0 I! t. F" J! L6 b0 O5 O
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
9 Y% y' P1 ?. ?8 `& B# }+ t3 ?" |! C( F5 v1 N* {# h
CATBoolean CreatePointCmd::ActionOne( void *data )
* v$ a2 R+ H( @9 w! C{
3 W. X* P% z; ~$ W9 M) s // TODO: Define the action associated with the transition
; b v$ N3 S, ?3 B // ------------------------------------------------------: T" N* s- U$ j* H# j
CATMathPoint2D point2D = _Indication->GetValue();& R' ~1 u& W: H, |7 Q5 q; y4 s
CATMathPlane plane = _Indication->GetMathPlane();
* w1 _; y; ]; N k: J CATMathPoint point3D;9 M0 G$ _6 \4 U$ N( z+ K
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);1 s; m3 i# {/ o2 o5 M7 }+ [
( Y X3 Z# r: l
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
1 C* [7 m: Q, Y. G0 c% \
4 x( l0 l4 f9 f0 |$ m( X1 |6 _ //设置Container(非根节点)
: C- l! G7 g, u/ J( F7 N0 y, e9 F& k //获得Editor
( U) U7 O( ~& b8 |: E* B6 s: f CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();! `$ W/ R. g- K
//得到当前对象的文档
& r* i$ Z3 [8 [% M4 M9 f, v# X CATDocument * pDocument = NULL ;& z o+ z! Q8 y0 ?- [0 f
//取得当前活动对象
5 {, ^ A9 \) a& g4 |/ f: p4 n1 F CATPathElement activePath = pEditor->GetUIActiveObject();
% K6 p2 \1 Y" ~ //取得当前活动的product6 C8 Q* V: T! s x( y
CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
& G8 e$ c# e! o5 E" x9 z# Y3 d //当前活动对象不存在* _; J& \- \( [3 R2 A
if (pActiveProduct == NULL)
/ R e3 J. Y7 a: Y' b* o' x% U {$ p7 V* V/ n+ e. h! V
pDocument = pEditor->GetDocument();
5 x* W, n# W' H/ B7 d* R/ q$ C/ u: R }! ]; M) }# o* K
else2 G% w+ j& u T4 Q' b. j: U
{
' r( L8 o9 H' X) T, f/ J) [/ B! d CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();/ L6 z& @" m! o
//当前对象的引用对象是否存在0 E( q8 P& E( _( L3 t7 r; {5 U7 g# X; C
if ( NULL_var == spRef )* u/ o5 h b) P+ @ Z: D* X8 @
{" ^) B* F& _ j: h0 K8 F# W
return FALSE;
+ w, a2 c7 P3 S c }4 y' B# M1 H$ o& ]$ n& V
//当前对象的链接对象1 D. A, X9 q' I- V: W' b8 i6 {
CATILinkableObject * piLinkableObject = NULL;
, n# i" x0 i1 m HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject ); 8 o4 k/ o, w- g$ M- k8 L
if ( FAILED(rc) )& |% \" q( W9 F% p9 b
{/ Z5 c) O. w9 ^. L1 P! J
piLinkableObject->Release();7 ]7 G& n: p5 [" Q# y) {
piLinkableObject = NULL ;# I: r0 q5 C4 d: }0 t- Q6 n' P) ?
return FALSE;- t3 }2 J, `7 }" ^0 F( D
}
. Z/ H, P" ^2 z$ H8 A) Q$ s5 j+ t //得到当前对象的文档
$ x3 z, Y% w2 ^: ? C/ m8 m1 l/ p pDocument = piLinkableObject->GetDocument();
6 \5 j% v- f' @ n4 C$ _0 ~6 h piLinkableObject->Release();
. K) Y4 |) ^6 l' R& } piLinkableObject = NULL ;, I" m. l" K2 ]2 m, z
if ( NULL == pDocument)
9 o- e7 o; K9 o8 T6 Q. G8 d* z" I9 z {& K! m! V! L7 U& `, v9 S7 q
return FALSE;
6 k' D: m, G, a2 V! ? }# {9 B* J& X6 d% ?3 \7 k3 W
}
- [+ x. G1 G% W* @( v4 u# K //得到文档容器集
4 I* U: k3 Q0 ?4 _: {; F CATIContainerOfDocument * pIContainerOfDocument = NULL;
$ z1 J7 r4 p# V/ f HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
& M- |4 R% R+ l if (FAILED(rc))7 d5 }* A E# x
{
4 i2 U, K4 H$ o" ~% n //pIContainerOfDocument->Release();: H$ D. P7 ]# t- m9 |
pIContainerOfDocument = NULL ;
( l' B* O/ c( h return FALSE;, d$ _, V6 D) g- M: |
}& j; I% M% O0 D( `# z
, T V& {" o- a
//获得Document
+ E1 Y$ ~' e% Z CATIContainer* _pContainer = NULL; 2 k; q" Z$ |9 s+ z
//获得SpecContainer; j" k. c, o) ~& Q. `1 `
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);! ?$ g( f4 Z z) z
! d- U# l4 c% E
//GSM工厂. |) h# U* T9 a: ~$ R: c3 ~2 K; v5 [* ~
CATIGSMFactory_var spGSMFactory = NULL_var;1 j8 k) S0 _9 y
//设置工厂
w2 M3 n5 m3 ?, R spGSMFactory = _pContainer; * v- z: `+ o; `
CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);& o: x8 Q7 u3 V( g3 L
CATISpecObject_var spSpecPoint= spPoint; # w8 U0 W% } s6 [; i
CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
0 y$ j2 ?, o0 [( w9 P1 f" o; z9 Q# z* K
//*将点显示在屏幕上9 D: P5 D5 B7 `5 s! [
spSndPntObj->InsertInProceduralView();/ U Q9 i& p+ h Q" X2 C9 V% N
//更新点对象3 q% \( d# p* n- q
spSpecPoint->Update();
2 X/ O" I9 `# D9 X# P# j) s, r ' d+ j3 p+ T& Y+ l
return TRUE;7 D: T3 G% [5 z$ P
}
" M7 u5 O6 l1 c& ~- X3 g* ~ ]2 b9 D
4 }/ F. a# ?( `# l- j5 w1 S, U! Q! P% c8 K. p3 a! ~6 b
效果如下:
. w& R( s3 d' b& q9 w9 y* f& @: q/ `6 u
/ X2 G; @# w# ^6 M$ J
/ d& [% Q3 ?8 ^/ H' L |
|