|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]& o4 m4 P: H G& Y( j$ i {
//8 g1 h+ I1 V% D+ K% s7 z
//7 - retrieving and displaying current faces colors, q' x: Y+ a7 D) K# P, |* Y
//
. d, u" T1 |1 [5 V3 `! T5 ~ cout<<"--------------------------"<<endl;
9 `. G; B3 u @% _, v3 Y; O$ H- y% S cout<<"Retrieving current colors"<<endl;
" X. d( j7 l. l0 W/ U CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;) E: p& {$ `- j
+ a) x2 c% G8 s3 `* h
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
9 t. e0 H/ |& K$ h if (E_FAIL == rc )
& u) L* @2 `. Z+ _" Z {
- S7 Y7 Y0 `8 E cout<<"Error, an error occured while retrieving current part colors"<<endl;
/ J% Z2 z K* d- X return 1;
; Q$ e% J: T5 y$ v }. Q" M& } o& y1 b+ G4 I
% h. x( J4 j. N* H for (compt =1;compt<=nbfaces;compt++)9 M/ }3 ]# f% v( Z* H
{" T* s& B$ n5 H8 t
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
- ^7 T/ j S0 ]* ?1 q& l' x, @ }1 s+ b+ g3 T4 j- v% n5 Q p6 B8 p
7 `% y; L! X: x" D
//
k8 A; {6 I# n6 Z% R2 c //8 - Setting a new Color on all faces/ J% q- {2 O3 N; ^$ E+ z( |+ u
//
0 T1 Y; j; ~2 e$ @2 b, q1 |
$ W! q' K! M% u( P/ n //we are to color the faces with different color according their position : three by three will have the same color
! j5 `# g5 I; S( \! X5 K0 Y1 v: i cout<<"--------------------------"<<endl;
5 N. w$ c5 D. s cout<<"Setting new colors"<<endl;7 d4 J1 s* G2 V9 b. r7 H, C7 r
" U( ] M' T x) e# |; ]
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
! U# k9 \2 e2 o. b1 ~ int x=0;8 D, I8 c* z7 w
for (compt = 1;compt<= nbfaces;compt++)4 p1 {6 W2 f5 |
{
" g0 o' f" [7 U. J7 o, P. Y x = compt%3;! ]4 m! u8 d. u6 _5 g. @/ I5 _
int red(0),green(0),blue(0);3 g* s7 c3 u' O* G- x9 H
if (1 == x)9 G' E- r. m; U
red = 255;
2 B+ V' o3 I2 v9 B8 r! k. C if (2 == x) ?* Y# ]0 Y9 k: |/ F& I- W- q
green = 255;: J0 h* j$ i8 T& T! F) ?% E- o0 \
if (0 == x)
4 |5 U( `& n/ x blue = 255;
" [! N! A0 m. i9 v/ X( V2 u& @ newRed.Append(red);
! d } E1 z& r) x newGreen.Append(green);
2 L3 _" ]1 e, L) M" q9 G) d: P newBlue.Append (blue);
1 O" U' ^8 [& \. O. I! |6 E cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;; u4 r' I! D* _, t
}
+ A, D3 \* Y" n. p$ u# _% r
+ S% F+ O' c) Z$ E rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
r* e, B) \7 \8 y if (E_FAIL == rc)
2 C8 |- \' O; q$ v' v0 S: F0 v8 ` {4 U8 M7 M. b) }# g- U; o
cout<<"Error, setting new color on faces failed for all faces"<<endl;
* j3 i* L* X3 r! ]7 _1 V) u+ U return 1;. G& H4 w/ o( t% g1 T
}
8 e1 @! ^. |; e; c1 B- e$ \* I else if (S_FALSE == rc )+ c( X+ V( n ]. D. d, E. n
{
. q/ D2 |3 {3 E& A: w8 Y( G; N int nberrors = FailedIndex.Size();
8 J5 u1 | w# G0 k; o V2 Z cout<<"Error, setting new color on faces fails for faces :";
0 ^4 D7 Z& H0 Y1 m for (compt = 1;compt<= FailedIndex.Size(); compt++)* |( Z/ L+ a; x
{% X$ c$ T3 `6 M6 d9 [5 g
cout<<" "<<FailedIndex[compt];
) K9 c2 j, N1 l G }
- C' H7 e9 e4 z7 D1 h# t cout<<endl;8 ^7 g# y/ [, c. d( M4 g0 O
}
! j* d: G3 R1 ~. ]+ ` else
+ \ H: f. F$ e9 y cout<<"Colors successfully set on every faces"<<endl;
7 \6 P$ m0 m# u2 s //
7 d, U3 q6 S- L1 a //9 - retrieving colors we have just set. Z' w9 s& G3 v0 c
//3 [# a# S7 |6 g: x. X
cout<<"--------------------------"<<endl;6 @+ \, G6 ? V. C4 O
cout<<"Retrieving new colors"<<endl;
. r" w8 P1 b) c% K" Q( _" W) ~ rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);2 x: \" \" p$ N0 a7 K
if (E_FAIL == rc )$ j% i/ D5 N7 [0 M+ Y+ V1 `
{
$ m7 [( ^ [* ^+ P7 U" G, }/ P& ? cout<<"Error, an error occured while retrieving current part colors"<<endl;
8 R4 X+ L& Y; \# a return 1;4 X! A& ^# z4 L
}# B# Y7 m7 [% }4 {! f
1 \& c) ~1 @; g4 v- ^
for (compt =1;compt<=nbfaces;compt++)$ x( F: v) @+ i8 ?" b
{8 \2 E* F8 n% @$ o2 G7 ?8 B
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;0 f! t* u! s9 L) \! e
}
2 \; ~3 m& O& N# i& A; I! o' s
- \& N( x3 b) V, Y! n //7 w! \, t& H( v4 o3 E% H
//10 - Setting Applicative Attributes. v6 |* W4 A% P
//8 n6 ?4 u( |, v8 N% d( C) P, D* p
. _. g/ a/ O) j% \
//4 C: B$ [# O, p. g5 N- |" Z
//10 - 1 creating new attributes
0 {: l; O9 P# l# p; R/ P3 o cout<<"--------------------------"<<endl;% n/ H) q5 H7 R% r2 c5 K& {& t
cout<<"Creating applicative attributes for different faces"<<endl;6 h, z4 O# d: F, W! ?
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
1 T9 N9 m# z# f$ d; j% l CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];3 L5 ?4 W* i/ \1 w# s1 e
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();- x+ O& q9 r' _+ S l3 s
for (compt = 1;compt<= nbfaces;compt++)
A6 d( ]+ Y; W' {7 A+ Y0 J1 w: Y) | {6 l+ J9 H2 X7 y- k0 a* s
cout<<"Creating ";' H" b" g1 `3 S5 [' ]3 D
x = compt%3;4 e4 Z$ k) v7 v2 k1 G
//for each face we create a new list of apllicative attributes
) n) e- N& Q; G/ y% n( ? W //an applicative attribute is made of a Name and a value
4 r- [4 R& f( G if (1 == x)
% z* o- j; E7 Y { K$ R6 u: [! P3 j# E! d7 Y
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
1 F( l# F- q u% C AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);; X0 N. R6 W' x9 q0 s, ?4 E: U
# i/ }' x: t9 Y U) M
//The first attribute will be the number of the face
. x' N+ `! T9 D' E2 D/ P& | AttrNameListToSet [compt-1]->Append("FACE_NUMBER"); T, {, `; P- V% O. M. f0 a
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
7 }3 S, ?' \- N# H9 x% r AttrValueListToSet[compt-1]->Append(tempcke1);
1 W6 r+ v+ ?4 x, v; B7 D5 p
! l4 B. ~3 `/ R! t( A9 C; } cout<<" FACE_NUMBER with value "<<compt; 4 K. q/ `" }4 d4 J' R$ x% O
9 U1 C% o# {, u9 u, \ //the second will be the color
3 S7 `* x8 N0 [( K AttrNameListToSet [compt-1]->Append("COLOR");
# O( }' } q$ c% a CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");2 y2 S3 Z! \6 H# M! k# }2 W
AttrValueListToSet[compt-1]->Append(tempcke2);; a) l( q9 s! j# j# c
' P% S/ H' c Q# t0 |
cout<<" COLOR with value Red";
$ P3 L1 J. r5 @ M$ \
1 K5 J* f$ Y9 r) g+ E //the third is x q: l7 Z C. k# h( c: Q% Z' f
AttrNameListToSet [compt-1]->Append("X");
; F6 A5 X( S, \/ L0 K CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
* s' u' L, S6 g* L) Y; r; c AttrValueListToSet[compt-1]->Append(tempcke3);
! Y3 X, z' R; l& A5 C! h/ j* f8 u: @
# V p0 L. v; ?# \ cout<<" X with value "<<x;7 S7 q7 C+ G9 X8 W
cout<<" for face nb "<<compt<<endl;2 k+ a" \$ `' `1 m7 D- k8 u4 l
}
( t* x' ]+ I* M3 @ else
! D9 P5 J# }! }; M //just to show you you can have different size of list
7 O6 U) X, H0 Z1 H* S! z. } {
+ Q8 S* j9 U9 W2 }9 t AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
9 ]$ i. V6 q4 B$ S7 { AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);) ~8 p! j! Z5 J3 f
' n5 m9 r4 b) H* \" D3 `3 G" N* `2 m //The first attribute will be the number of the face4 j7 N7 a0 X2 _& ?
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");; I& [/ G9 p8 B9 c; a
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
9 D. c. ?3 p" }! I; I3 K AttrValueListToSet[compt-1]->Append(tempcke1);& I9 y9 h0 S( ^6 l& U
0 A" F3 A; c7 V+ P/ C* E) r+ o
cout<<" FACE_NUMBER with value "<<compt;
; l) [: B! S t B9 Z; l) E! w h& q
//the second will be the color
0 j9 D5 Q6 Z& B7 d+ B6 I/ f/ A n AttrNameListToSet [compt-1]->Append("COLOR");0 X# }" z! j, h6 ?+ ?
if (2 == x)
+ ?: _% H$ s& S( n0 r {
) K. j' p( @4 F" Y! ]+ j CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");, K, P- L* T- y+ i0 H/ R
AttrValueListToSet[compt-1]->Append(tempcke2);; Q, K$ b1 L# S" ?
5 J; R" B6 @6 x1 o
cout<<" COLOR with value Green";7 x, k7 G: O1 v C& v2 ?
}
- o# H5 F& Y5 L' y( Z% q8 ? if (0 == x)
) n" Z2 r- @1 p9 ^" j {
1 u$ M, q7 a, R CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");& t. P1 A5 {+ p
AttrValueListToSet[compt-1]->Append(tempcke2);
4 B/ H- f( g @2 k! F " u5 G4 t U( u) g1 W7 k4 C
cout<<" COLOR with value Blue";. W6 H/ K) H* j( M( z$ _9 F
}, s, b1 @% x u I7 J: G" T c
: ^3 r2 u# D0 R' h cout<<" on face nb "<<compt<<endl; T# r- @+ S& y: D
- q; ], r) T# d7 A4 M1 S2 V }
$ r9 z. `+ m& O2 J, p. E0 t: W( A% \( Y }
8 ^% G4 a" T. b; k4 X5 m- c, m# S$ T; O
//10 - 2 Setting the applicative attributes
3 _1 u+ ^3 X3 M+ x cout<<endl<<"Setting applicative attributes on different faces"<<endl;
3 p/ p2 s# P+ P8 D' @. _% F6 G FailedIndex.RemoveAll();# n2 b/ b6 p! p3 h
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);3 K% z1 ~" d, S, V" h0 q
if (E_FAIL == rc)7 }( t5 `$ P8 l5 ~! T; g: N
{& G1 k G) l5 @' S9 v5 X9 i
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;1 ^* l6 `8 N w7 ?- l( J3 e
}- a2 f* J& S+ \
else if (S_FALSE == rc); ]8 z. b k5 J, ? D7 P
{! p' o9 g" d- f* P. N
int nberrors = FailedIndex.Size();# D- W, I2 H' U& _2 D3 V7 h
cout<<"Error, setting applicative attriutes on faces fails for faces :";
/ ~- I% F/ t/ m A' l9 p for (compt = 1;compt<= FailedIndex.Size(); compt++)
. `: ^6 I8 i5 ^5 V$ W5 }* g* a {
: ~. ~1 x- U8 ~* q cout<<" "<<FailedIndex[compt];
% ~& F {; _# X }" c; S4 ?# _" l9 X/ O. I% j
cout<<endl;$ E/ d! \5 f f
}6 L: b( B1 Q2 y. e7 e! p
else6 M, G9 g1 S; r
{
5 b+ N# {" s- n# O cout<<"Applicative attributes successfully set"<<endl;- z) Z3 d% q$ G6 D1 h. s9 d
}/ \: L6 g$ ^6 e7 T! M: \+ o
]! @, y6 z1 i% {! _. [ {8 t/ C
//10 - 3 cleaning
7 I" a# _" d! _, q% l, l* s; z" M for (compt=1; compt<=nbfaces;compt++)
% v* g7 q- h0 \! d3 Z" E {
$ T; O! _2 e( p1 e/ D9 A AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;8 B3 x7 V9 c* [9 s" n& l1 ]# c
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL; Z) B- p1 `* q5 ~% O
}, T# L4 `% W* N& ], O5 `
( Y2 M; i* G# E" H6 q! v- T delete [] AttrNameListToSet; AttrNameListToSet = NULL;7 m2 |" b2 [8 Q, J% j- k
delete [] AttrValueListToSet;AttrValueListToSet = NULL;8 H6 N( B" i6 J) W8 ^% b
; V N' N$ l7 L* r: b- A4 @6 | //
/ m3 @( @. W$ ^* n8 N& N' J( h //11 - Retrieving the applicative attributes we have just set
( J3 G- R) r' x; k //; A3 `6 |4 f. V, O
cout<<"--------------------------"<<endl;1 d- E! H/ S- ]; K& h, O
cout<<"Getting applicative attributes on faces"<<endl;1 p+ l4 f6 G: m) i
//
7 F; @1 [9 ^: l! |& a/ C //11 - 1 Getting attributes: R# o5 T* G; J! S# E/ E( S+ y
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
$ V1 H5 O9 ?0 o CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];$ N+ H {7 O9 W0 w ^
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
{0 j" J# {/ A7 Z3 D7 z) Z if (SUCCEEDED(rc))9 t) W$ z; e$ r# Y& c4 p
{
) H- }" I' g1 A8 J- U4 } CATListOfCATUnicodeString templiststring;( j% Z/ m2 `8 h I. w' B
CATListValCATBaseUnknown_var tempCke;0 ?; y$ o4 J" m; i
for (compt=1;compt<=nbfaces;compt++)
7 p5 p0 O" h- `0 S+ r/ | {/ J$ a z3 ~# A( t" o9 x% C
//retrieve a list a position k (arrays start at position zero).! }" T h0 Y9 E& K1 c [
templiststring = (AttributNameList)[compt-1];
% G% D2 U( V- L5 D: [8 K+ G8 ^' l tempCke = (AttrValList)[compt-1]; Q4 A; o5 F' o+ C
0 t* m; o7 Q0 O2 B/ N
int nbAttributes = templiststring.Size();, C! i" w( X* [- V
int nbValues = tempCke.Size();3 R6 a% g5 f2 x; t% S2 W Q
: p6 z: ~: Q6 X# ]& U' r
//the list must have the same size! If not, we jump to the next face
; W J7 g1 q; d8 k8 }$ E k if (nbAttributes != nbValues)
' a( v% A& V9 ]0 u {' `3 ]3 ?0 y+ e! k! i( M3 Q- u
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;( L1 O1 _5 h( z" |
continue;: U- u5 p& e2 s# _7 H5 L$ c
}
8 o6 g8 v+ K6 {" H2 X6 t' d7 ~ else
& | W7 m9 n7 V9 W. X {- U. e* L; u/ e$ V+ h- N- G
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;# r6 |' [ E1 @: U! m
}. a6 ~3 K4 T6 H, r' f
for (int i=1;i<=nbAttributes;i++)9 d# e& B, I' v7 @; \4 \5 v
{
6 ]9 V4 \6 t, [( u0 m1 i cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
( f; c$ o4 e" y) z( c8 s- g }! L1 `' W8 H( g* c! k
templiststring.RemoveAll();6 S" E- \7 k% X/ f; {
tempCke.RemoveAll();# I- B) h3 ^8 d( d" w
0 p* {+ G5 N% b/ N4 {% c: G8 x }
+ f4 T( ]; l7 \* M* T' }+ j6 C0 ` }
: z" N' o$ g5 V& U0 c5 P else if (E_FAIL == rc)
! c7 V( ~* a% p$ a* ~, A {
) ]6 g: S0 _$ o: X( u cout<<"Error, applicative attributes couldn't be retrieved"<<endl;2 Y7 p* d7 i/ W5 {% {5 O
return 1;
8 x# R9 l# r& [* Y. t4 \( v: N }
7 [; @+ X% L' N3 Y; h8 [9 I //
8 _0 d9 S; Q1 Q( ?; n; V //11 - 2 Cleaning List:
0 N. N) }( D& S( ]& x+ R* N9 m int i = 0;
7 A$ [4 V5 X" e# C. e7 z) h for (i=0; i < nbfaces;i++)
9 @' |# Q ]$ @5 C: ] {2 V# T$ |3 E% w
AttributNameList.RemoveAll();4 u9 U. c3 B9 @4 n% i W4 a9 S
AttrValList.RemoveAll();
3 k6 @4 E X3 d7 b; a5 [# x; O- k }/ g& Z+ S3 o; P
delete [] AttributNameList; AttributNameList = NULL;
+ M+ I# W6 @# ]) E( D delete [] AttrValList; AttrValList = NULL;! n! O" N# j! ]4 x! H- b# Q
/ D/ [% u( F) K4 N7 X* h% ]: R for (i = 1;i<= nbfaces;i++)0 E6 L0 L1 H0 _' ~' r, T/ g% O
{. m5 D' |- j b/ x$ k% K' ^, I
Brep = ListBreps ;4 L4 Z, F& l& @5 F2 p) [
if (NULL != Brep)+ U; m, G) A# ^. P+ j0 `
{8 v+ z# B; s& n. r2 C
Brep->Release();
: z) S- q8 Z z- k* X }
. x0 M! l# s9 T& @; x1 K }
* M. o) t0 o h g& s7 P% R; ? ListBreps.RemoveAll();[/mw_shl_code]
7 [9 F: Z' O$ g/ L |
|