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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式$ m4 M- E8 A' ?" W4 e& C
5 x$ Z' D) K4 z3 u/ N8 y
7 t& I' _6 @8 k4 m3 {1 j; S% K+ _3 j
1 变量声明
6 ]4 J- L% G# |# }6 C3 a* s8 E' C7 @- y% V0 g7 G
0 P! J; h) N( x* ]. d
o Old way! T0 C: g9 u4 k5 i2 g
// Declare pointers for an Item, Form and vector of ModelObjects
2 M& w1 b: J' N4 h7 r1 [# z// initialize to NULL' ?3 {% t9 X# c1 B. R& b7 V( l7 x( Z6 A! ]
Item *theItem = NULL;
" @2 h2 ^" Z2 h! @4 o) b/ IForm *theForm = NULL;. J$ m5 w+ j4 {% U' c% f. J0 ?
vector< ModelObject *> objects;
% m1 d( @: h, s1 \4 G7 y...
5 n+ N3 b/ }; H- n3 R6 Y// Use the Item
7 O- H8 f" }# w' q9 y2 ntheForm = theItem->get_item_master_tag();1 ^( I* x, J/ e  O7 f
objects = theItem->get_revision_list();7 Q# o: v( U- o" K5 n5 r, Y
o New way6 R7 }: A  h0 c5 E! K
// Declare AutoPtr for an Item, Form and vector of ModelObjects
; r( F$ [2 |7 B9 Z+ S7 S: Q// all AutoPtrs are instantiated as NULL
. d: d: D) @7 |: |! Y$ ]1 Z* PTeamcenter::Soa::Common::AutoPtr<Item> theItem;
; ~2 S& p2 v4 wTeamcenter::Soa::Common::AutoPtr<Form> theForm;
4 E9 ~5 [5 Q% vvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;2 a6 v  Q5 k; e( w- h( V3 Q
// Use of the ModelObject variables remains unchanged1 }$ x2 N; n5 k; z9 X' m1 o
theForm = theItem->get_item_master_tag();* j; U  {! g6 c$ S2 Z) d0 y
objects = theItem->get_revision_list();
7 @) X1 Z, K) Y- w) G/ @3 t6 X5 k% n
5 `8 X! v6 F$ Y' b
2 类型转换 ! C/ y) j# o6 \- C& S$ T2 ?

% g0 H- m( C" m* j$ K! n+ N$ M/ Wo Old way( Y9 X) ?6 i3 |' E, i- K
// Declare the variables, X! y) K2 ?0 f
User *user;8 y: i5 E8 j9 ?7 h) J- F  z
ModelObject *anObj;
0 j/ f$ m7 ?* N) z& ]Folder *folder;
' r1 U2 i' I2 r: Vuser = sessionService->login(name,pass, “”,””, descrim ).user;
; K" V( |5 X# M4 k3 E& u// Cast to the base ModelObject class: j0 `3 \2 M& H: e2 ]
anObj = (ModelObject*)user;$ Z& A9 x! M9 G& u
// Cast to a speicfic sub-type, if not NULL8 h( H% r9 `1 b8 i4 ]  u
// do something with the new pointer
2 ^2 Q) ~( I1 y, F' R1 Y* Ruser = dynamic_cast<User*>(anObj);
, v! J" R5 E# k% ^, iif(user != NULL)
% H0 I/ l/ U3 W2 n( C- z9 ~- m2 Y{* j# U4 H; r% Z. F, \
folder = user->get_home_folder();
3 l$ E5 k# h- }}7 H2 X8 s& ?; r' C* t) s
o New way  Q7 b( z+ O/ y
// Declare the variables9 L9 x/ G2 G: j2 t2 o
Teamcenter::Soa::Common::AutoPtr<User> user;
- U6 U3 W$ F( g9 X6 t* UTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
; ]5 ?' s4 K$ VTeamcenter::Soa::Common::AutoPtr<Folder> folder;
! i7 a8 G' ^; Y1 A& Vuser = sessionService->login(name,pass, “”,””, descrim ).user;
$ M( P1 R4 ^1 w& ^$ p// Cast to the base ModelObject class$ _# q% A# q+ K) [
anObj = user.cast<ModelObject>();2 w) N. v" S4 m6 }! [
// Put the cast to a speicfic sub-type, in a try/caTCh block
! P3 {8 V" N! j; o9 G1 U2 P// if std::bad_cast not thrown, then cast was successful# m, H. K1 j5 a% z  h% f
try! x5 v3 `% L7 o4 F. W; S$ D9 ^
{3 k' S, y/ x) R/ @8 `+ l
user = anObj.dyn_cast< User >();
0 S8 r7 a; ]* j; _folder = user->get_home_folder();
  w) K0 m: j) s# o% r+ p}6 l5 ]+ W% ?$ |* @
catch(std::bad_cast&){}) L2 n, L' c+ N0 a, F

; _+ Y. q& M9 [+ w, I# u% H
$ T( ?" W2 Y- x3 关于NULL 赋值8 m# ~2 s5 `+ T

& F% Z9 l& C$ J. Uo Old way
+ G$ A( `# m6 z2 E// Declare the variables+ H5 D" N/ w7 h4 i4 l
LoginResponse response;' ^1 d$ C  \+ M. Z
User * user;
* a- y( C3 J5 t2 w% E1 _: y- u2 `// Call a service that returns a ModelObject (User)2 N, |- i0 [5 Z7 U2 {3 u
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );8 \$ b, j! M6 J$ {
user = response.user;
* E- D! e8 W% K4 _3 s' _// Test that instnace against NULL
6 D$ ?# Y: J, I* fif( user == NULL)
5 O& ]; `! ^* X2 X" L( t7 x; J{9 ], d& V- l5 s$ ?5 L
...
3 N5 J% B$ f' v/ S4 w}$ I, Y1 }/ \+ e
else
/ ?- S: M2 U( Y' L" k5 n{2 S% c8 V2 ?8 r5 v" E- H
// Assign NULL to the pointer
8 }7 \. a$ P, k. |7 @user = NULL;% P" i8 s7 a* ?1 s& t
}. `5 g0 p* z+ U3 [
o New way$ Y0 L7 |. b+ K& T
// Declare the variables5 d1 K4 P$ D% p: @
// The service data structures do not change, only' Q; }0 |2 I, Q' H! O5 E" g
// references to ModelObjects
' o7 L. m: S6 ?6 f) h" pLoginResponse response;' W5 E7 V4 Q, x* c& O  E- Z! R) g
Teamcenter::Soa::Common::AutoPtr<User> user;# W! w/ Q5 ^( }3 }
// Call a service that returns a ModelObject (User)! Y) T- M% \0 o2 j) C
response = sessionService->login(name,pass, “”,””, descrim );/ c8 _# W' ~0 o( O* V3 o# J
user = response.user;" N6 v5 Q& C& M, ?! u' j: D
// Since we are not dealing directly with pointers,4 M9 c, y3 C8 s# P
// NULL does not make sense here, use the isNull method from the6 x8 L' x8 w2 W7 w/ i, S/ Y
// AutoPtr template class.
8 O) o& \+ Q+ D- V: r3 _  r' N2 vif( user.isNull())3 I. w$ H# a6 I$ X" {5 R+ c
{
: d4 e& W! f0 r" S/ f8 E...' `4 b& t0 a- c
}7 R# W# j( ], X2 l- P9 Q# D
else
; R; l0 w& B/ {6 s  y{
- m$ F; ^0 d8 Q. Z// Release the instance and
+ v6 k( m2 I! Z* g: S) @) g- X0 \7 Uuser.release();& @; O2 N6 R( F( o' @
}
* i( `+ L8 {6 {! X. N2 B) E- O8 |: L# @# x
- ]' D4 }% C  r, p8 g4 m% b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了