|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true], b, m- {* X, g8 @3 b
/// t' S! N# g- |$ ~+ D
//7 - retrieving and displaying current faces colors5 K* h; B/ K& J6 X6 _# B; j+ S9 P# o
//; y0 r& b( `/ S
cout<<"--------------------------"<<endl;
* o# a) \0 |9 F4 L# p cout<<"Retrieving current colors"<<endl;
8 j( }0 u1 i: o5 N CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
: A5 S* h7 T7 \7 m/ ~- ^
! s8 k7 O* y6 P' F rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
1 e3 I5 _0 u2 P* q$ \ if (E_FAIL == rc )
; T% l+ T* q2 Y {
' g5 @; E, @; S Z. r) I3 F# } cout<<"Error, an error occured while retrieving current part colors"<<endl;1 j, q1 e7 U) M% }9 u4 r, W; e
return 1;
5 |6 C. c) Z K; }9 } }# s4 `0 \8 p& H) X" W
/ N4 ]- p5 F# P7 @
for (compt =1;compt<=nbfaces;compt++)
- ]7 W( i* p* s; q: \; Y {% d1 _$ `. h' a+ z! T, o6 i: c; H
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
9 t. o8 ]. d" k2 F9 Z6 ~* S }" \9 @( Y! p$ J# {, ^/ B
* z7 j' W. v) F. c //4 i9 ]( X3 f1 Y% Q' P) B1 j7 k8 D
//8 - Setting a new Color on all faces
, b! A5 B& M+ J+ U. t" g0 v //
- C# C, Z/ j; q) m" _! X0 F& f! I& W* U+ C
//we are to color the faces with different color according their position : three by three will have the same color5 h+ k. }: l* o' W$ k# d# s. F
cout<<"--------------------------"<<endl;
9 V% i9 ]; k' D; A# e' \1 r/ y) m* ` cout<<"Setting new colors"<<endl;
: m4 ?0 \' j. u& o' u. ~# _# f / H* w% `2 }& d+ H( p9 p
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
3 a) m* \. `1 p0 Q int x=0;
$ z, L7 o0 m% ]# e for (compt = 1;compt<= nbfaces;compt++)9 L! W& n* L: e6 p. S: ?! h
{
2 ^ r9 x9 d- r1 Z' [ x = compt%3;4 K1 O% H' f, R( v
int red(0),green(0),blue(0);$ K' u1 {- |2 \, l- p3 E: x9 a5 H
if (1 == x)
$ U5 }( }& P, f/ @+ W( J red = 255;8 B7 g/ I" N9 v; U& K% _
if (2 == x)
2 z' k6 J6 L% W v4 n' J! i green = 255;
. g1 |: w+ ?2 w+ o0 B# ] N( n; q if (0 == x)! s! i Q/ h& A
blue = 255;3 y h1 W$ }3 s% U+ \- K( S/ w
newRed.Append(red);5 o- \. l* u- t" z5 M, ], W
newGreen.Append(green);4 y7 e2 y+ \& G4 `6 J" J
newBlue.Append (blue);3 _/ z7 f$ J/ T4 x. G8 V$ C
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
2 ]( @( A, M; e. S) }1 G" e+ F }# P" I# F1 Y4 c T l! g) {
8 P2 ?7 K1 T6 k" y) q, v; D# q6 o rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);1 w! q6 \1 d' `
if (E_FAIL == rc)
1 Y6 ~4 M) z' y0 z6 [# `7 i+ X( d {3 ^+ r8 _7 r2 ^
cout<<"Error, setting new color on faces failed for all faces"<<endl;% }9 z7 G$ ~* O+ I
return 1;: y, D* v8 c6 a. V; q' S
}( Z1 N. P# }8 H7 {
else if (S_FALSE == rc )
2 U; i7 q4 P( m1 ~- F8 s {1 M5 }* @1 g& ]* \
int nberrors = FailedIndex.Size();" q5 T8 \" y4 T H8 g
cout<<"Error, setting new color on faces fails for faces :";) m( v. S a* O1 h% K7 \
for (compt = 1;compt<= FailedIndex.Size(); compt++)
, {4 q5 I' [* _, O7 o {
/ e/ F9 Q e5 m" V4 n cout<<" "<<FailedIndex[compt];
O# u" {8 F- x7 `2 ^! [6 n, Q }/ e+ f0 J+ l* A- b* s- {" j
cout<<endl;+ o y) o& a8 K O+ E
}
9 S, n x) E: @ else
M( @* V9 c+ ^8 v1 @ cout<<"Colors successfully set on every faces"<<endl;" T. q7 R+ \5 X$ A1 o% e# x5 s3 L( v
//
" [9 {- A! l0 ] //9 - retrieving colors we have just set) Y7 H: I, C7 _9 ]% J) [2 z
//
1 X$ \6 x5 p: q5 e cout<<"--------------------------"<<endl;
0 A, ^& z# `' B' J( x* {4 Y cout<<"Retrieving new colors"<<endl;8 S$ D3 C* m% N* a1 e; N
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
$ Q" g& x0 q' H: [7 [' l6 E/ d if (E_FAIL == rc )5 d. d* {9 G$ ]% x$ [7 M5 d
{
- x& O: `4 ]* t3 y' N; Z5 ] cout<<"Error, an error occured while retrieving current part colors"<<endl;! h8 ~3 {$ l# B" d# \9 q( N
return 1;9 _- `9 P0 U- r! |
}
/ k& y( a5 t7 e6 n0 b3 N" U j7 q8 i1 I
for (compt =1;compt<=nbfaces;compt++); |! K# w) d, D' I a1 P
{ M; B+ ~; h! b! ]% ]' @
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;2 C' K7 U4 _, V& G* `" b
}
& x% @# c- Y. |/ I
, ?1 l" l6 X) {2 r1 O //# E4 o: ] F- m4 B
//10 - Setting Applicative Attributes0 ^4 W9 r0 m9 ?
//
* e& @0 T7 a( s: T! m' \- @, S; K5 ^+ `! _ A
//
$ Q1 h! q$ B$ W! H" { //10 - 1 creating new attributes
: O$ ]( ~9 M; ^8 E' w cout<<"--------------------------"<<endl;& }7 F3 d& E( ^, n: G; _, b
cout<<"Creating applicative attributes for different faces"<<endl;2 R# Z4 u6 a$ g
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];. S/ i% ?* P- w7 K
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
5 O# |8 m5 c( u+ `; s! b CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
* Z" Y' W# }. U8 V8 a) ^ for (compt = 1;compt<= nbfaces;compt++)8 Y l7 j8 X9 d, \
{+ N8 h! q( T, z& _0 h
cout<<"Creating ";, \0 w* `& ]1 y6 P8 g6 j
x = compt%3;
) q; p! @8 {/ D' _- G* W //for each face we create a new list of apllicative attributes2 @5 E0 c% e. h
//an applicative attribute is made of a Name and a value/ h5 Q$ f8 M" k& U$ Z* ~" e/ B6 F
if (1 == x)1 U2 c: F# m( s; Y
{( E; q0 }$ M i4 Z/ y8 |4 G) V( m
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
+ _. T9 F# x$ ^ AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
& r) n+ U* v9 j, \ m+ I# z/ L% T' |5 q1 P# P
//The first attribute will be the number of the face
|, [6 l d) Q6 J; Y) k AttrNameListToSet [compt-1]->Append("FACE_NUMBER");; w' y: {3 [0 x0 Q, }. P
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);! R" U% `" r; M; ]
AttrValueListToSet[compt-1]->Append(tempcke1);
/ x4 M# F% ?+ Z5 f: {- ^6 n/ D
! C9 {0 j* c N cout<<" FACE_NUMBER with value "<<compt; ! s t' |# I( S+ P* O4 v& c
& s2 t/ ^" d# Z( a L
//the second will be the color
, R6 q& h: G. V( o" D2 e AttrNameListToSet [compt-1]->Append("COLOR");% D# B1 s$ U5 w/ ^
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
' `: z2 ?9 G' u; V! y AttrValueListToSet[compt-1]->Append(tempcke2);7 F& x' I0 h O
4 L& P1 |3 X' k8 }/ D cout<<" COLOR with value Red";
) h. |4 p0 i2 b9 c" i+ V3 {( V
: J% }' R) x; |0 s //the third is x) D& A; G( o. N: J, j9 p4 p9 u
AttrNameListToSet [compt-1]->Append("X");* l7 p5 s5 p% e. n+ P; d
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
: \$ G0 t: h2 I9 A' J4 x AttrValueListToSet[compt-1]->Append(tempcke3);' B3 I9 _8 J# w ~
! i* @ r [$ t
cout<<" X with value "<<x;
- c x& @; C6 X+ K, [8 P% Y cout<<" for face nb "<<compt<<endl;& U# v8 O: V' X" _7 Q# ^& P
}0 i- `! t1 h; K2 L+ M
else : l$ z8 B' G; D0 h# K s
//just to show you you can have different size of list
5 G( M# S% _5 S$ M" ] {" ^, g; Q7 s3 L! I1 x
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
2 U: X0 c, u" q% u# e; v* m AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);. O3 i" t, O# E9 ?# K' k
* ~& Q4 l' }/ W$ c' t! f& a //The first attribute will be the number of the face
/ i* m: p* ~. @4 i7 Y AttrNameListToSet [compt-1]->Append("FACE_NUMBER");8 L7 C) ]/ w' L+ |, u
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);& u! V9 v1 F7 m$ M+ q
AttrValueListToSet[compt-1]->Append(tempcke1);$ B' A$ ~* Q8 g& q6 Z2 M4 p7 j
- W1 F4 r) y9 O" K cout<<" FACE_NUMBER with value "<<compt; 4 B8 A5 u2 h: ]/ P2 |% O
% {0 ~. @4 O' D. @: @* X //the second will be the color
2 O% l( m, {$ C6 v AttrNameListToSet [compt-1]->Append("COLOR");( Z8 {7 S8 [7 }8 O. {! }
if (2 == x)* Y4 I) g# w c h' C6 z
{+ q3 {$ _- {9 w" N6 d
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");2 H6 Z( _3 }8 ]: z" b
AttrValueListToSet[compt-1]->Append(tempcke2);
# |" v9 s: k) }7 X, |5 X s6 e 2 V/ q6 z) I( U) r+ p; L
cout<<" COLOR with value Green";, O g4 h$ M6 m7 c( o: X, K$ _
}' g5 R# J, n3 V* U. Z: Z4 O- X
if (0 == x)
Q* F5 F! ?% a* g* l) V/ ] {" M% J5 t2 |' ~
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");/ ?- b8 t8 C, E5 q' d
AttrValueListToSet[compt-1]->Append(tempcke2);7 y' y# o' P/ P: M) s
4 F, e0 i- }/ A: O& \2 m- G
cout<<" COLOR with value Blue";
4 m6 f% F) E. d. C- n$ _( l& v' i }1 U* X# z1 ~/ O/ ~9 P7 p3 _
7 X3 n$ Q4 O% V cout<<" on face nb "<<compt<<endl;
# P) I3 H, i4 l( l. }4 p" c/ d+ |" ?7 z) `& i
}8 B8 M2 j- h" V! }
}
, I9 H5 E. a5 [+ }
0 I" E" V" K' n% ^2 G //10 - 2 Setting the applicative attributes$ t# ?0 R: c6 J% K
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
7 {7 L& @: H6 A/ A1 k5 Y FailedIndex.RemoveAll();
( P/ W4 T# u/ b rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
' ~ C* W( Q7 U+ i+ Y1 k if (E_FAIL == rc)
* N; k6 _3 j3 T( o {
: }, N# Q N% }, j cout<<"Error, we failed to set applicative attributes on all faces"<<endl;4 E# o, w: E0 Q1 }/ Z
}
( x9 Y6 O" ]$ P8 f1 W R else if (S_FALSE == rc)
& s7 h z! u: ]) n( G5 @" z& v4 I {
$ T" l, a1 i) K( z; N+ y( X$ o( f6 `) m int nberrors = FailedIndex.Size();: x2 _3 v) O: N0 p
cout<<"Error, setting applicative attriutes on faces fails for faces :";
- h, Q" h' U) P- w/ z0 ] for (compt = 1;compt<= FailedIndex.Size(); compt++)& _5 k5 x+ P: f4 ]& @/ |. p
{
0 u- i6 X- H9 v$ C* S* y D cout<<" "<<FailedIndex[compt];
# P7 P- Z9 \ w' t: p0 d# v }) n" h3 q: F9 C- {2 H7 h% \& R
cout<<endl;- |; ]( H& \: y. |* y% C. U
} {: `2 C0 t+ v) R& @+ }7 a, Q
else
: o; C P K8 ? {
$ V% D. U, B6 F; k# }, I* R6 S! \1 T3 H4 i cout<<"Applicative attributes successfully set"<<endl;
! n$ |. f x: L }( y k. U' ], a2 w
1 f) {7 m8 ~8 L/ Y //10 - 3 cleaning
( Z2 C' o, i; \% m for (compt=1; compt<=nbfaces;compt++) d4 t; m$ E7 F7 N: Y
{
6 u1 P! s3 }; ?! x# {0 Z& J4 {9 s3 ]* i AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL; `2 W9 a8 b* K4 S; v; }! e
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;. d: W2 n0 _6 O' X: n% r% q+ J
}
" W; `5 a( r7 z7 W
3 J9 ?; H. s) e3 l delete [] AttrNameListToSet; AttrNameListToSet = NULL;
. K& E/ }- }0 y% Y: t4 A delete [] AttrValueListToSet;AttrValueListToSet = NULL;) z8 l' s: m6 o! K, r; R, {
$ J3 K6 b1 k( v6 `: [2 G //
( @" f& _9 Z+ S2 r //11 - Retrieving the applicative attributes we have just set) Y( X' H4 N) w+ k8 @
//
2 E8 F! A( G* `( p4 R6 q! ] cout<<"--------------------------"<<endl;
5 o; w" p+ o2 y( l. _) Y7 o4 c& ^ cout<<"Getting applicative attributes on faces"<<endl;
7 ]5 L: _7 |# w //
( F- v$ I L3 [. ~ //11 - 1 Getting attributes
8 s2 t; V$ b3 z; Z- i- ~2 g CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
" x' I, P: J) S2 t: D CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];" y6 K4 m; Q2 g8 M. x
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );1 Z3 q2 u& }9 ^
if (SUCCEEDED(rc))( ?, W& ]+ ~) Y5 [
{) W# N7 {) I; V- p O4 H
CATListOfCATUnicodeString templiststring;/ V( Y1 X% s! r5 H* U( w' |, y& G# ]
CATListValCATBaseUnknown_var tempCke;
4 R/ r- Y" I) D$ D9 i- U& E) [& y3 Y1 ? for (compt=1;compt<=nbfaces;compt++)
8 j9 ?" v& v5 B( L {+ F1 F: N. c% O
//retrieve a list a position k (arrays start at position zero).
" i. E" [% m4 O5 |. A, V% z templiststring = (AttributNameList)[compt-1];
( S4 |8 Z7 o1 b7 M5 t tempCke = (AttrValList)[compt-1];+ G6 t+ g( u6 ^3 {, S. Z) _6 a
* X# }, Y' u" q! y6 q+ l int nbAttributes = templiststring.Size();' _1 L7 L2 F% A9 u9 y( \3 D* ^
int nbValues = tempCke.Size();
- P& j: u( p1 F( ~9 H: P, c5 v
; a: @( C4 T8 R% W; x- w //the list must have the same size! If not, we jump to the next face5 e9 n# s$ c7 ^0 @# y1 p( U0 y
if (nbAttributes != nbValues)6 M' v/ \9 L5 s) n; z
{
7 I O5 p1 O, a: g0 X+ G cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;! ?, \1 E( R, L5 s9 R2 f/ u8 R
continue;4 H. t1 |$ y# M
}2 k# N! H6 m0 Y- j+ j4 h5 C( z
else, o3 Z: }0 q( g# ^
{: u6 g3 @) l8 V* O
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
2 m: T+ x# G+ E7 K4 l( @* p* E! Y }" M1 A2 X" o/ _
for (int i=1;i<=nbAttributes;i++)3 \$ K) d. b6 a. V0 }
{
+ @% Q4 c% c; }" ? cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
; F9 C8 G/ ~4 S# O" r' J8 N }
7 ` Y% ?8 n( T4 g9 N4 B9 Q templiststring.RemoveAll();
, |0 ~4 S+ v6 y( o ?8 b tempCke.RemoveAll();+ ]. b' X$ k* H) W4 ?' [
$ u9 b7 C- s* ?% G6 M% l }
2 Q0 y, U" @: Q) i. i8 R P }
) q6 p, E' b# o: o else if (E_FAIL == rc)
( P8 }1 a" N- G' \1 { {: }* R3 K. u4 x- i& f2 G
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
+ o* L" |* o0 R" _0 z' Y return 1;& h& y/ [# i$ a" R/ @3 x. o3 F- M
}
. t4 K' B- M' A1 E //; f! f. i9 i# a. x
//11 - 2 Cleaning List:
8 K' M- b. r3 [; @' u. K! G, `, O int i = 0;; m; ~9 J# o) D
for (i=0; i < nbfaces;i++)
8 ]6 p' |2 m1 x% ^, ^0 b! [ {
7 E9 {1 u8 c& G0 N# e1 q0 X AttributNameList.RemoveAll();& i- |& |$ c8 {1 C3 r
AttrValList.RemoveAll();
* m8 V5 I( I& p- w9 | }
" V, @% j7 r1 L6 L5 F7 I4 I delete [] AttributNameList; AttributNameList = NULL;
/ K' O7 w4 C' }* `: D delete [] AttrValList; AttrValList = NULL;
% U2 P3 J! P( i: y
0 f$ @" z! i$ M for (i = 1;i<= nbfaces;i++), T3 _& B; I* f/ i: ^
{
9 N0 t! T* x0 H Brep = ListBreps ;
8 E. L$ O9 b) u5 r* ~/ m, w+ U if (NULL != Brep)
) I: [( b" y) \9 o) l1 ]9 v2 i {
/ _% e4 d& P/ O1 `. j+ x1 M Brep->Release();
$ X! u# r& e$ P, }, A2 R* |3 h }3 @/ n+ [6 l9 E/ F- l4 J. H
}( q5 d* ~% a& n! i" f7 I
ListBreps.RemoveAll();[/mw_shl_code]
: q7 S! c/ [" p4 ^* V, \2 X |
|