PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
( w% R4 ~5 A4 z- x- m0 J# H" x; S* V; {1 B
6 s) O+ I0 A& F( E) m/ \
1 变量声明
- ]% E( T% K) `( `  ~3 g$ {* C& x" Z9 Z. d0 {4 `$ s* \
7 `* H; p: L" G
o Old way
7 t) m) m0 y- D2 O5 |// Declare pointers for an Item, Form and vector of ModelObjects
, R* _: g7 j! Z. B$ ], L// initialize to NULL
) n* I9 t8 g1 xItem *theItem = NULL;
) z& N/ p: K$ f+ [: E$ fForm *theForm = NULL;
/ E/ j) p$ V/ q6 q" D7 Vvector< ModelObject *> objects;0 d0 q( D0 w6 A$ C1 z4 ]6 c
...
+ i4 C4 q4 f1 {2 d// Use the Item
7 W. u1 Q" O+ O' a6 I& ]0 QtheForm = theItem->get_item_master_tag();6 t% z6 V: b' ?/ a3 Y
objects = theItem->get_revision_list();* i" w; S' W4 i! X3 ?
o New way0 {' V% P) k. y8 R* d7 T
// Declare AutoPtr for an Item, Form and vector of ModelObjects
4 I; j( @$ k0 J4 f. E4 p// all AutoPtrs are instantiated as NULL1 J! S2 B! |2 q9 W$ L2 {* x5 s: v
Teamcenter::Soa::Common::AutoPtr<Item> theItem;, w8 A4 X* U. g8 R
Teamcenter::Soa::Common::AutoPtr<Form> theForm;6 @, |* q! v/ q& o( h, o' A
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;. |* s9 |  I7 _+ `, o4 j
// Use of the ModelObject variables remains unchanged8 y8 g( \1 j$ u/ V" v1 Z0 W$ ?& i
theForm = theItem->get_item_master_tag();
) Y3 [- i; H6 q8 Mobjects = theItem->get_revision_list();7 Q& c5 I: Y3 N  p/ z; V

1 s; Q4 y6 X( i4 o" T  w3 V
) ?6 n1 |9 ], T: ]. c) i# o/ a2 类型转换 2 t: V( A3 B/ }& r

0 p: D) B. ?" b, E. ~' po Old way
) P$ L' y7 Z1 Y+ e// Declare the variables
  F6 O4 D) g: JUser *user;$ v/ P% a+ z5 `8 L( j' \6 x
ModelObject *anObj;- K/ ]  x; g, C9 ]
Folder *folder;
# F" k& T- ]1 _" S! A$ }! U7 L% o9 Wuser = sessionService->login(name,pass, “”,””, descrim ).user;
$ n5 ?0 }9 P4 Q; X5 D9 P1 x- D: c// Cast to the base ModelObject class+ P3 l* d/ O  H$ |: h( d0 N' P
anObj = (ModelObject*)user;
* I  @  Y/ ]; E; S2 h+ S" r1 @// Cast to a speicfic sub-type, if not NULL2 k5 m- M& b- [5 z% f
// do something with the new pointer! p8 f! J/ `) m! D6 m
user = dynamic_cast<User*>(anObj);
1 t% n9 }- U' ^1 q& b2 ?9 Fif(user != NULL)5 Z, }& V; T- w( ]
{
' m" W3 z: a" E. s7 A7 Y! Ifolder = user->get_home_folder();
8 f0 _* T. U. Q: O6 U}8 b& U5 d( w5 b- g; |
o New way; M6 ?% M+ n2 R! @& A' N/ ^
// Declare the variables! h9 K: p  M4 i( J% O
Teamcenter::Soa::Common::AutoPtr<User> user;% K- u8 [- X2 H( O, Y; a
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
' F& X8 t8 o* b5 O$ z5 U3 oTeamcenter::Soa::Common::AutoPtr<Folder> folder;, r% ^! x- N! M  _( W
user = sessionService->login(name,pass, “”,””, descrim ).user;( i. ?0 h0 C- H/ M  m$ j
// Cast to the base ModelObject class
0 }* x% }/ ]! }anObj = user.cast<ModelObject>();
( n' N+ f8 J8 t7 t/ u- X// Put the cast to a speicfic sub-type, in a try/caTCh block
6 N) o& m( A; E8 M// if std::bad_cast not thrown, then cast was successful/ ]8 g, ]4 C# p6 t' y1 c
try, H$ X; X& K. }! e/ l3 p
{" t" P5 T$ r! b- c  u$ n; [) N( l
user = anObj.dyn_cast< User >();( X. L% \# s( k8 o0 z% r2 x, A
folder = user->get_home_folder();
# x) o; s5 _1 x  R}" }& y5 `  M) t/ C" j+ v$ ^0 e
catch(std::bad_cast&){}
) I7 G; ]1 w- E( z3 p* F. l" ]6 \9 m  I
) X0 y2 F6 k9 Z9 Y9 g& w3 V+ V2 v3 v; W
3 关于NULL 赋值
- k( O  }4 Z0 D5 C1 r1 u& C: ]+ A4 `) ?) p
o Old way
# J: L% i/ s7 _5 T1 t" q" P+ k// Declare the variables
. q; @+ `/ m; _+ K+ wLoginResponse response;. Q) c, r5 x9 U1 c1 q5 G
User * user;+ }* x, |! @. D
// Call a service that returns a ModelObject (User). y) L% Z& o# ?- ~
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );3 B7 f5 y& @& k0 t7 Z
user = response.user;
2 w' {, V. q: u4 B# t" d% k. t// Test that instnace against NULL9 x- x5 ]/ z3 w; P' u. ^
if( user == NULL)% q2 C) z% P+ k( ?' v; z% i3 b
{4 m1 C" \; p9 M. V
...0 ~) B3 v) m* x* t; L# @, f0 l
}
, i% j9 A2 e0 q) x: Eelse
6 @9 ^6 w, v4 P{, e0 F8 A+ O0 Y; w# [1 r) Y) w
// Assign NULL to the pointer2 p$ q; l2 o4 m
user = NULL;
: M) F* B6 e1 Q) r# y}% [/ ^  }) I0 V& d+ t; A: n
o New way
* \  _1 G: _3 J, y2 A// Declare the variables3 z8 G- V/ W- I4 @% s
// The service data structures do not change, only
7 {5 E* U+ t- v// references to ModelObjects7 w* x: p# H) K) }
LoginResponse response;
7 K; ?2 Q4 E8 d/ z# p  {Teamcenter::Soa::Common::AutoPtr<User> user;
  |$ e2 ^3 h9 P! K) o4 p5 w8 Q; r// Call a service that returns a ModelObject (User)
( g. u+ ?4 u  a/ Zresponse = sessionService->login(name,pass, “”,””, descrim );+ c" J8 Y$ `# S- U
user = response.user;/ ^/ D+ B. P. `+ x0 g* a9 T
// Since we are not dealing directly with pointers,
8 j* [1 Q# ]# k// NULL does not make sense here, use the isNull method from the
: K+ J9 t5 G7 s8 y, z5 W// AutoPtr template class.1 h- H, F" _2 n0 t1 `
if( user.isNull())- C/ s! I% O2 M/ j
{" O& C) M! Z& o9 M# d
..." S1 W2 O; I9 u+ k  [2 K+ D
}  i+ }% O0 }6 j, p) [8 X4 Q; u
else5 g/ h. A1 Z0 ^
{: a  r# y) B9 e! l: i3 }
// Release the instance and0 C& c) m# {1 ~
user.release();# v, V, l. U% g' C. h; x
}
# U% ?. \! Y2 _3 p  {: ]  }$ K* M5 U& e/ o. h, n

6 l& H. A% q- I! O7 ^! g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了