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 3380 0

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
7 W- P; Z1 |  \/ {! y$ |( C6 E$ `$ w: h: }2 V8 j

  _$ M% Q6 s5 y1 变量声明
6 c/ {: K& {( m8 f5 ^% M' d6 Y
5 M" B4 X, t1 Z6 D" \. B" U

! P: d+ E- q5 s- c% U- u8 a% y( to Old way/ o  s) ~/ M6 b" [/ b
// Declare pointers for an Item, Form and vector of ModelObjects
7 C0 ~, j' h" v/ [  b6 p% x// initialize to NULL* U8 P9 I' r/ o$ x" E5 w
Item *theItem = NULL;0 c7 M; C, S$ q: v
Form *theForm = NULL;
, F. P9 y( T0 A" \' |  [vector< ModelObject *> objects;% D7 e5 L" Z6 f3 g* g% c  \( r# B- ^
...9 k2 _" E6 l- x! }8 j
// Use the Item. p8 V- W" Y4 H% Q. S8 P6 O/ ]
theForm = theItem->get_item_master_tag();0 v9 f: _- I+ m7 F% G% n: [
objects = theItem->get_revision_list();9 H' O" ]0 q8 N/ m# _
o New way/ O$ S4 B  T( H! G; l/ J6 J! b
// Declare AutoPtr for an Item, Form and vector of ModelObjects
0 y& `  R4 n7 @9 W  f% O' A// all AutoPtrs are instantiated as NULL
7 ~$ Z% F+ q( x  @1 g6 RTeamcenter::Soa::Common::AutoPtr<Item> theItem;
9 Q5 k! O! h) x+ s4 J  Y( iTeamcenter::Soa::Common::AutoPtr<Form> theForm;% {' J; q7 ?3 ]4 f# U4 o% z
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
3 U9 {9 |2 |) A, v6 H# p1 Q2 U// Use of the ModelObject variables remains unchanged8 Z' _' v9 S5 N6 w9 X
theForm = theItem->get_item_master_tag();* y/ [1 x% j* S- F; _
objects = theItem->get_revision_list();
; M6 ^: j5 o+ S' z+ g$ E0 ?" l) M8 Y
( W; b3 F2 D7 x: {
2 类型转换
0 e$ \3 G' M4 s7 W
1 `! c: i8 D' Z; N2 ro Old way2 {8 v% }8 W0 j6 G" V
// Declare the variables, P( g/ p& m0 `4 `  Z$ s& b( k
User *user;
$ |+ _% }# y1 XModelObject *anObj;, N' V6 X/ t: v0 P# Z$ ?& H( `0 a8 U
Folder *folder;
7 r: O5 _8 ^0 U( Zuser = sessionService->login(name,pass, “”,””, descrim ).user;8 T2 r- l, d3 @/ \8 x! g
// Cast to the base ModelObject class. s& N1 d. ~& C4 j1 T, }
anObj = (ModelObject*)user;! d0 [4 K6 H4 M9 m% g
// Cast to a speicfic sub-type, if not NULL$ t7 {& d6 V% H+ `+ s) h, ^
// do something with the new pointer' S1 S8 e: U) C( G! V# l, @% }, a* o
user = dynamic_cast<User*>(anObj);
" k9 k, q; s  L2 F) cif(user != NULL)
' q, L0 j0 |4 P( H; N0 K{( z. @8 `5 m6 T- ]  I
folder = user->get_home_folder();
/ B" d$ q+ O0 ?  ^; e}& m8 |, c. q, M  J' K8 Z& S, S! j
o New way" |' t5 o9 y* l% ]7 g& M
// Declare the variables, X& o/ }+ }% g6 X$ t& F7 v" s$ @
Teamcenter::Soa::Common::AutoPtr<User> user;
8 k, z4 L# x) S* A7 K. K* UTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;$ Q7 x8 a/ u2 Z
Teamcenter::Soa::Common::AutoPtr<Folder> folder;' a1 D; m7 J. b* L1 e3 ]' C
user = sessionService->login(name,pass, “”,””, descrim ).user;
0 O) q5 p8 p$ L6 }$ H# H9 K// Cast to the base ModelObject class
+ a5 s, R5 n% a, C! }4 u; AanObj = user.cast<ModelObject>();
) S' a% L+ ]5 a. F// Put the cast to a speicfic sub-type, in a try/caTCh block: ]7 K3 x/ L- n" ]
// if std::bad_cast not thrown, then cast was successful1 Q. X+ p0 W  O7 i) U
try
  E$ A7 S/ a% _8 K( m0 f* a{
+ u: [' ~" _* P& E( F# h6 zuser = anObj.dyn_cast< User >();
  ^" [% u0 E- R+ v# |+ Efolder = user->get_home_folder();
) v+ s- |' P  b, T0 F4 B3 B+ x8 |}" i! y; M+ r- _  ]) `
catch(std::bad_cast&){}
. V  s% w* T9 W  D: u% h# v9 I* ^# s) j& h' i- |/ Q' D' [1 N  l& t: X* o
: D$ m, k1 U. |4 d, u
3 关于NULL 赋值0 G, F  ?* N/ \* l
: z7 _5 ?; f, ]" y* F9 Z5 }
o Old way' M" P! ]; N/ o/ c
// Declare the variables
" v1 I$ @4 y$ `+ E( h& ~) ~9 ~1 _( `$ HLoginResponse response;
2 r' d' _; W3 AUser * user;$ u) g2 w/ O) T4 K% m& W
// Call a service that returns a ModelObject (User)
- o, w6 ~0 h: l% g# r4 {1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );( Y+ p& n6 |0 D8 E, E9 z" z+ Q
user = response.user;
, C3 I% }) p. I8 F// Test that instnace against NULL* X7 _9 k$ U8 c8 j7 D; c
if( user == NULL)& Q8 x$ V" [) ?- K; r+ }  L
{
9 T3 w6 P, r+ B; z# g! d& k.... ^+ |7 K: c1 Z) A+ B
}
3 h+ r& Q' E: z$ Lelse1 [/ f% a5 i+ C  F/ @4 J/ b1 [( I0 _
{
' Y9 T5 \1 B/ D// Assign NULL to the pointer5 E; U# ~/ F: I" h; f
user = NULL;
8 N0 a* E* s; y5 E! U: t}
8 q- o4 W4 Y0 n& w  eo New way
! e' n4 ~, l0 h// Declare the variables, y) u+ J) \, l3 L3 \  b0 P# v
// The service data structures do not change, only* M$ Q5 G# w' [6 n, m
// references to ModelObjects3 |9 K3 \; ^% q  w
LoginResponse response;
# }) P6 O7 h2 C) e5 N. V: CTeamcenter::Soa::Common::AutoPtr<User> user;7 l1 G5 D5 J1 Q8 \# }
// Call a service that returns a ModelObject (User)
: v# h5 Z1 C: T- Xresponse = sessionService->login(name,pass, “”,””, descrim );/ ]; k$ F8 h5 I2 t# j1 d# I* G$ S
user = response.user;: O+ [+ \8 ^; N: W! ~: |6 Y
// Since we are not dealing directly with pointers,. \) q, M5 ^- j3 N) x
// NULL does not make sense here, use the isNull method from the. z# w* x2 v5 _
// AutoPtr template class.% g+ T2 K6 w3 k# J" h" p
if( user.isNull())
5 w: |4 T/ I( Q1 G8 [5 i{
! H( i, f. ]% W' L. `. \...
5 k) L' ]0 E" y}- T" e/ J3 W. A" f( R+ k
else  _4 B: j& `" R: N$ @8 v$ h
{
8 B8 r) `8 s% o9 J) q/ ]2 U4 C// Release the instance and
, u. P) c8 S+ }" cuser.release();, _" n! }" F3 n
}
7 L, t0 `' F7 [9 R, O9 E: _6 [  _2 Y  Y- E; S( j+ \

) w+ a8 ^/ [* {) {( o0 V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了