PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式

[复制链接]

2015-2-3 09:18:14 3551 0

admin 发表于 2015-2-3 09:18:14 |阅读模式

admin 楼主

2015-2-3 09:18:14

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
" f9 P' f/ G8 j3 k+ e# n: s' g1 r- d5 [  F9 J5 N, ]3 s
- W. C7 N& h- D0 b: l" b# O
1 变量声明
. I" b/ M/ D7 p0 J( J2 A; @! h  b5 T6 A$ L

. b2 h- E2 e, W+ x9 @o Old way9 K) ^7 l. V$ [1 C
// Declare pointers for an Item, Form and vector of ModelObjects. @5 i! c  w" A8 n
// initialize to NULL
4 R: m) `  M- d- p  k% Z4 q$ iItem *theItem = NULL;
+ ^0 t9 a4 W1 H! I, R4 V) jForm *theForm = NULL;
* i2 |# a3 }4 S8 M& c0 I+ n- }vector< ModelObject *> objects;' i- u, K8 t( K% L6 g% e
...
5 Z# U% F  s8 I, z2 g; w// Use the Item( J; \+ B2 x% W, U# S& O
theForm = theItem->get_item_master_tag();# I0 _$ V' e2 `5 Q
objects = theItem->get_revision_list();
" G0 |6 s: L  P/ Bo New way
1 [. W+ M4 q( c& `9 s2 X// Declare AutoPtr for an Item, Form and vector of ModelObjects7 Q8 U0 v5 q: T
// all AutoPtrs are instantiated as NULL' \. C  b0 M/ e4 }6 t" b
Teamcenter::Soa::Common::AutoPtr<Item> theItem;
- a0 r: G, h0 JTeamcenter::Soa::Common::AutoPtr<Form> theForm;
+ N0 H( }- B1 z/ A6 ^& F( A$ Lvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
& E7 `. b& F' f# l/ T3 p+ K5 T6 e// Use of the ModelObject variables remains unchanged( s4 E: J+ G  P4 P
theForm = theItem->get_item_master_tag();  f; E3 J4 Y1 _, ^& W0 d, z2 g8 [1 B- a
objects = theItem->get_revision_list();2 z6 C$ Q, _  W/ f

9 J% X1 Y* U! \9 a0 N. V' h5 L2 j9 D1 O
2 类型转换
5 j* G& z8 w1 d) X0 z& e: M( ]/ _, j2 X- e5 M! h8 O# s
o Old way
  y; _1 j$ }8 i- k& D4 m+ W// Declare the variables8 F6 \" U3 h  A) ]! j
User *user;4 ]3 G2 L& @) R1 j) H, `5 o
ModelObject *anObj;6 c. Q! e! z0 T& Y' }( l, I
Folder *folder;% v- C, A" W2 j1 t- |) \  y* Q
user = sessionService->login(name,pass, “”,””, descrim ).user;7 Z0 Y! l( A; M$ T8 a+ x7 i0 _
// Cast to the base ModelObject class8 b6 l/ w. w8 R* |4 Z( v/ Y
anObj = (ModelObject*)user;  I% |6 }2 B3 }0 w$ Z4 f
// Cast to a speicfic sub-type, if not NULL
5 ]7 A3 W. o/ a+ c// do something with the new pointer
( N) V' R) F: A! M% t5 ^0 Tuser = dynamic_cast<User*>(anObj);
0 _' o3 j0 M; H/ N; b5 k5 f/ U( n, }/ gif(user != NULL)6 [2 L6 r( u) R2 C
{
5 P3 H8 A& n0 o6 Mfolder = user->get_home_folder();
( ^2 u( S8 {$ G1 T}
, s7 p) O- C5 D" S4 Z& eo New way: b/ ?" k1 G1 F( _
// Declare the variables
. e7 f# O" ^8 n8 k; lTeamcenter::Soa::Common::AutoPtr<User> user;! u4 U% k0 E) {* M$ _
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
* f% q7 v- [2 `, c, LTeamcenter::Soa::Common::AutoPtr<Folder> folder;9 N& J& [. q1 f4 A9 `; _+ t. x2 r
user = sessionService->login(name,pass, “”,””, descrim ).user;
' T' E" f" W( S0 b# e* E// Cast to the base ModelObject class  k- u  y! W# B
anObj = user.cast<ModelObject>();
  W/ T/ U; x5 `* u( K& M7 B; w// Put the cast to a speicfic sub-type, in a try/caTCh block
! }4 e" W( y! Z4 [& t// if std::bad_cast not thrown, then cast was successful
% C* {6 e" |% W. ]7 p$ V: S6 htry" y. m$ Y: }; B$ c) ?
{6 ^: P% d; E: |9 M
user = anObj.dyn_cast< User >();, \- U. W5 @7 D% F3 i
folder = user->get_home_folder();
' f0 D+ D/ G" L; h6 G. x' K}
* k+ m1 w0 G% d5 k- F2 @! lcatch(std::bad_cast&){}, a& i9 h& E* Y) n4 `0 `+ b

  R( z4 J7 M6 F! `( @
- ]1 d9 I! F5 X2 Z+ c6 _+ u4 M2 u3 关于NULL 赋值- d7 d% s) C5 `; ~- f. |4 c

+ z5 s9 z" m1 \6 v% xo Old way
# B+ R" |8 \# k// Declare the variables
4 R2 K# W) p' [3 vLoginResponse response;
/ r: m' u8 n: `+ g, TUser * user;' _, [( n) x. b' N1 p. D
// Call a service that returns a ModelObject (User)4 r2 H4 d$ I7 V; V, Q# R/ ~
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
( x! V6 y- M( Puser = response.user;+ W3 x; P# l4 p4 q# Q
// Test that instnace against NULL
7 J$ ?: y' O8 T" a% m' d! Sif( user == NULL)* Z: i! w& e! @/ ~5 M; J; i
{
. L/ a# I$ a$ P9 ]1 w...
! h, N) Y& z0 N* ]}  X* O5 |- B5 [6 q) d
else
, h) H1 q) ^* c$ H! r) f{
' l; h6 b& X8 b; R// Assign NULL to the pointer
3 c& Z: _* R1 Z/ h! p5 `  Kuser = NULL;8 }1 a7 p7 ]! L2 _
}
3 A( E2 d; P  n  U. Mo New way
8 U* H5 T8 s3 R. k. d+ o/ `// Declare the variables
5 q5 E4 _9 Y/ p. B3 K4 T8 w& \// The service data structures do not change, only
' X  y/ U& j# X1 C# V// references to ModelObjects& h% Y2 w5 @  o7 X1 W3 m; s
LoginResponse response;
1 O8 a' m* o, [3 c8 xTeamcenter::Soa::Common::AutoPtr<User> user;
  \( S& D8 H7 u+ W// Call a service that returns a ModelObject (User)
% t* _$ |4 ]! P3 y2 jresponse = sessionService->login(name,pass, “”,””, descrim );! y* y: |* N0 `% A0 w$ o! P
user = response.user;
4 J. d+ }6 p4 A6 V) H* i0 n// Since we are not dealing directly with pointers,; l8 _  \4 `0 v) x
// NULL does not make sense here, use the isNull method from the
9 \! H; a& `' Z# `( N% Z8 p( y9 ]// AutoPtr template class.- y- W- s, ^- t4 p$ C& q9 t
if( user.isNull())# Q4 P' b( w  n5 K( \
{/ ?7 p7 j! F; }8 W2 g% J
...4 r5 W. k. @  H8 c
}# B, d5 {; K3 ~
else
7 w! q+ h" \. M. ~( H7 ~{% B9 R$ Z) [3 e
// Release the instance and
  Y) e* `9 D8 b) Guser.release();
, Z; @( E+ i9 `1 V, E  T7 A6 o}
. L) G7 X1 b7 @) Q1 P. Z/ _% u  u7 {* K; c% U

* u! N- {  E1 k1 U5 K
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了