|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]4 ^1 l! ?/ o& P8 s6 `
//3 e/ ~: j/ k1 v* z0 w
//7 - retrieving and displaying current faces colors, g5 _! ~) z5 b# K7 W9 S* p
//
7 K" g: `5 H2 V2 a6 x7 k/ ] cout<<"--------------------------"<<endl;, _# ?2 {, c; L' r* s
cout<<"Retrieving current colors"<<endl;
; y( ^& q+ n$ J* f0 y7 Z6 i CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
; d, F9 H3 d7 u8 E/ l
" Z. ~+ U) V0 r- I9 j9 L) d rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);: J) v) s! r* M- }5 g
if (E_FAIL == rc )8 J( f6 o9 ]' K* I2 p8 y' t( m
{; _$ K3 K' J# q' |9 d8 p: S2 n" k
cout<<"Error, an error occured while retrieving current part colors"<<endl;: N, J6 ^* T$ } \, f
return 1;: s. k. h6 A7 S) X6 B
}$ j6 v8 y) c7 P
0 ], H' E- g# f; O# }( }7 V) S% z: o
for (compt =1;compt<=nbfaces;compt++)
: J( c: U+ V" [, A) C {
, u' e- b% z4 R5 U cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
' a7 F ~6 t" q% Y6 q' w- d }
% I) Q* S" n0 A6 ~: c3 y4 D6 E" S: e2 K+ l1 w( {, Q3 J
//2 M7 V; B9 B9 L% z- R8 s; T/ G
//8 - Setting a new Color on all faces
" q6 A) F* D7 d //, p b0 F9 m3 K5 D
- R8 ]& I1 @, \8 N. B7 B //we are to color the faces with different color according their position : three by three will have the same color
6 `, P, K1 U+ o$ r0 X cout<<"--------------------------"<<endl;2 _5 u4 u: j" } s; p: C! l
cout<<"Setting new colors"<<endl;
# l6 v$ o2 F3 W% t F+ H- z 4 ~2 U# R4 v: Z
CATListOfInt newRed,newGreen,newBlue,FailedIndex;1 @. i, j) \" n/ i
int x=0;) e! Z& o$ I1 M
for (compt = 1;compt<= nbfaces;compt++)- s+ v, I# p' m
{
) R% l) t0 i0 ` x = compt%3;5 d* K0 a( f& @- L6 }% t
int red(0),green(0),blue(0);% K2 U# P( `+ X' w1 M
if (1 == x)8 y4 `3 h3 k w; o+ C
red = 255;& B2 `. Z0 `5 ^! Z1 O
if (2 == x); f* t3 r1 Y: D
green = 255;
$ j' G# A' _2 B# L& K if (0 == x): o6 k' A# q8 H; `
blue = 255;' y/ A, j0 j! h P, F7 ^
newRed.Append(red);
* @) F6 }8 o! _0 { newGreen.Append(green);
. k3 j: o! K* N0 g- f newBlue.Append (blue);
2 s, W6 Y! _9 ?0 A) L: E) p$ `6 f) X cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
$ B, ~ w& p& f }
7 A" g ^$ {* y' q# f( G+ Y2 x$ Q& T# ^
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
1 X6 X) w$ b- j7 D% Q' X if (E_FAIL == rc)
7 D4 N+ W$ r# C* y2 h9 z; \ {0 f0 h; m7 I5 O# L7 X
cout<<"Error, setting new color on faces failed for all faces"<<endl;
+ p) e, H p1 b" w return 1;1 K% b7 k5 U) A5 P4 a
}
+ [" P2 d. W: _3 L else if (S_FALSE == rc )
* h2 P, f8 V. Q {
: n* W7 m( q: D3 J& u2 |2 g int nberrors = FailedIndex.Size();0 y$ L9 t3 i2 M% M0 l
cout<<"Error, setting new color on faces fails for faces :";" L. k' ^! j: E8 R2 w4 o; _' [6 O
for (compt = 1;compt<= FailedIndex.Size(); compt++)
1 Y6 u; {3 T1 a3 @6 U C$ W1 l0 M {! }( R. t( Q# y8 o1 F. J" M/ i% x
cout<<" "<<FailedIndex[compt]; [# W' ?; o, k: m+ W% ?* N1 P
}# V: M' Q$ D/ Z9 ~9 X
cout<<endl;
; n+ N+ u5 Y. Z; _ }
, N- ]0 n% K% H& D4 z; l2 G else
& X! S8 C8 K J cout<<"Colors successfully set on every faces"<<endl;
+ F) S& [" K( m7 w- d% F- [ //
9 c( W2 d1 a# I" ^7 a; W+ I9 n, T //9 - retrieving colors we have just set9 I5 _3 E$ Y& t+ o. j
//
: J* O5 r# ?# L+ M* a cout<<"--------------------------"<<endl;' l* Q# S9 P$ [3 u
cout<<"Retrieving new colors"<<endl;
3 E9 \# B4 Y6 S: v, k rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
* r8 D$ }0 I6 Y9 a if (E_FAIL == rc )% r% j4 @' x6 {6 O! P
{
* G3 p+ U4 n# [* l% \ cout<<"Error, an error occured while retrieving current part colors"<<endl;
/ B# {! }/ D# G; w8 t2 d5 D& \# t return 1; a) J% E& p0 {5 F" F
}
! D& G6 s1 }% R# z
* E2 v/ P* s% ^+ P for (compt =1;compt<=nbfaces;compt++)
L& ]3 g( k( I/ ~# f2 o7 @8 f6 f& g4 b {
v& J8 b' `# w3 Y3 f: D I. a cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! `3 U+ M5 w0 y2 r- I, \$ E6 o7 z0 d }
/ L6 m# x: E9 j
_: ~9 ]8 n7 O! N/ D; W //
3 B3 h; G! s+ V+ J: c ^# z //10 - Setting Applicative Attributes' ?6 @! O5 @, C% ~% l% H6 ~
//
0 \% c& R. E( @% H1 m* c6 O1 i* a3 B
//
% f1 K' c$ Z. L2 |8 v //10 - 1 creating new attributes # r6 }5 T7 k1 _& G; ?6 j- h v
cout<<"--------------------------"<<endl;
5 l- E B* g! g0 ?, y8 g7 B cout<<"Creating applicative attributes for different faces"<<endl;
% P/ D2 _ V0 K" b CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
7 T I) H- n+ ^5 e+ _8 y+ g& q& ] CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];! y3 P0 @. c+ V% Y" @4 ~7 \7 }* ^
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();3 b0 z! N/ e# Q$ Y" _8 M' v
for (compt = 1;compt<= nbfaces;compt++)
1 M" Z! \ M4 q4 [8 G( h0 c {
( p/ t) \# I+ w/ w$ ?2 O7 O5 p0 ^ cout<<"Creating ";; @ K/ G: K( _9 o3 s
x = compt%3; x1 E2 W$ |' `7 n& ], k! `* w
//for each face we create a new list of apllicative attributes
9 {+ D c$ j9 c //an applicative attribute is made of a Name and a value
; U, ?2 n; ^2 S# B" R% @7 f: Z2 E5 i: J if (1 == x); P! ^2 h, q, }7 F4 @2 j/ t
{+ u$ R8 }( x$ d" L2 K
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);! l1 q# @2 z n% ^# J K- g: q
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);' R' q3 c$ r- r5 m: y3 p7 A( M" R$ C
! V4 Q( f4 b/ G' R+ ~: A# C! B. u% i
//The first attribute will be the number of the face
/ k7 C: K7 p( f# G( z" a: w' R1 B AttrNameListToSet [compt-1]->Append("FACE_NUMBER");5 Q8 o0 d2 p) W' M: L/ N7 P
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
s& ]" l" ]- r" } AttrValueListToSet[compt-1]->Append(tempcke1);
4 [9 v* h1 O: H5 f) m2 @& @0 A . [0 a; c: W v1 ^) V
cout<<" FACE_NUMBER with value "<<compt;
2 F) s! @% z, M) ~" d% q0 _$ e
- m8 _2 A& |6 `6 \9 S" z //the second will be the color
- J5 C0 {) `- X AttrNameListToSet [compt-1]->Append("COLOR");: d' X9 W. ^+ D" s& C
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");9 u. j! ^ S( i1 V! |2 \5 G
AttrValueListToSet[compt-1]->Append(tempcke2);! I/ @9 V$ k( {# Z
: M0 P4 `" i" J( w! |
cout<<" COLOR with value Red";
: M$ Q2 \! ?- X3 A
3 \5 e: k5 u* p //the third is x# I$ D* ]4 G& }1 v. w$ n
AttrNameListToSet [compt-1]->Append("X");8 P5 K) V [0 g& `1 S3 |# t
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);' p. [1 b! @- n5 v$ c
AttrValueListToSet[compt-1]->Append(tempcke3);0 m$ U% P0 C7 T. P" X' I
; D1 y* M/ [ H
cout<<" X with value "<<x;& L, i, t g$ w( ]
cout<<" for face nb "<<compt<<endl;5 ~6 B, P* r' O2 c2 l
}# J" r8 W) X+ _9 ?/ z
else $ b" g$ d( K; f* @7 W3 Z2 B
//just to show you you can have different size of list2 z% T* ~8 W7 |
{
6 ^6 F1 E. ~1 }' O. R( b AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
: }1 [. o, {! O) d AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);. k2 l% y& X" C; m( i$ z& w/ h
9 z! y1 o4 h! D. |$ V2 J
//The first attribute will be the number of the face4 J% p0 ~8 ~) s' J) |. g" U$ D; x- y5 M
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");0 A r5 `. P# Z! Y
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);) K0 m6 c8 K, c0 X/ m
AttrValueListToSet[compt-1]->Append(tempcke1);9 @0 ?, Z9 X7 i$ C5 M3 X. z
5 B8 U* V, Y& m, K9 b
cout<<" FACE_NUMBER with value "<<compt; 6 U: j h2 w b6 E0 z, g
: L9 K7 J# j9 e" e) z& F9 J" F% | //the second will be the color; f8 [- u7 c8 B! } i( A
AttrNameListToSet [compt-1]->Append("COLOR");; ^6 A" k1 ]2 {
if (2 == x)& \* Z( }; b- p
{
3 Y& D5 } {' t* b4 N CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");7 ~! T) J: Z3 k p7 ?0 n6 P
AttrValueListToSet[compt-1]->Append(tempcke2);# o% @+ _. d9 Q
5 @$ Q' m% W, c0 E/ ^/ s1 e: V
cout<<" COLOR with value Green";+ n4 w2 f$ S- X& m$ j
}
G& z) {! u. c4 Y w1 S if (0 == x)# K$ z: M2 o+ p4 [( A
{
$ m ]. V/ ]+ ~$ { CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
0 i# i/ f; g5 P- K/ m# b AttrValueListToSet[compt-1]->Append(tempcke2);1 h! r' A0 O- r3 N" H; A
. ^/ u* y3 [ |3 o2 W7 z
cout<<" COLOR with value Blue";
. Q" B% q" s2 ^/ W) h }
0 s% o9 B1 z( U1 P/ w, L( |5 Y+ _
5 v" q0 r6 E( {2 C/ e cout<<" on face nb "<<compt<<endl;
! Z: [$ g0 A4 r+ ^! Y
9 F$ K$ x) a5 C' `2 U }" i4 k# o; e3 ]/ ~) T* m Q. g5 i
}) v& @) O5 g9 }3 B C4 r, R6 o
' t$ {# [3 T+ u7 H$ E2 k) r9 {
//10 - 2 Setting the applicative attributes
) O' B# Z' E. D. E cout<<endl<<"Setting applicative attributes on different faces"<<endl;' B" X+ j a# T3 s2 v8 r
FailedIndex.RemoveAll(); ^% P8 g0 O% x" r: ~, A& E
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
) j9 |& T" X# P3 Z if (E_FAIL == rc)
1 }- ?+ H7 R; U! n2 O4 h {$ v- N& F; @# ]
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;- h( h% A/ ?' Z7 K9 A2 O2 _, W/ j
}( z2 ]3 K$ c" n/ v
else if (S_FALSE == rc), z# w5 {- r c5 g% A7 v
{8 N, d. u/ m4 P6 f7 D4 D8 n
int nberrors = FailedIndex.Size();; o! F- S! l3 ^
cout<<"Error, setting applicative attriutes on faces fails for faces :";
( b- E& J" a* y- m. \ for (compt = 1;compt<= FailedIndex.Size(); compt++)7 p4 J6 p5 o0 m6 F$ H
{
! N3 K0 I! G' \) c cout<<" "<<FailedIndex[compt];% _% `* m) Z( B% S* [ ?1 X5 K
}
8 b# e e ^! k- Y$ f0 P cout<<endl;
# [, Z- d4 _$ K6 x# j0 |# P4 L }" v$ H+ V& ^* r
else: D8 `6 v4 {3 z5 k" [. }8 C3 M
{
9 S# x1 S& E7 P7 ]/ i cout<<"Applicative attributes successfully set"<<endl;
& C# N3 K" q V- L0 \* B. C }
9 f* j# `5 Y9 E5 B. C: F# e) f# o4 U o# Q% l6 E \+ C
//10 - 3 cleaning, |8 B2 {2 u- C
for (compt=1; compt<=nbfaces;compt++) _5 T1 N* J6 ^5 E- K
{
0 j# }# k! Z$ \& E- W1 f0 v AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;6 e: K' I7 h- U1 }' F5 H
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;8 t) u N4 s: _" b. ~
}
) }+ \4 @2 @2 w3 Y. ^/ F$ f
1 w& K3 o* C6 q& M3 u delete [] AttrNameListToSet; AttrNameListToSet = NULL;
8 w! l1 [2 N0 s% U3 x delete [] AttrValueListToSet;AttrValueListToSet = NULL;7 M6 S a J! H, j" N
( l B7 Z( ~4 n* W
//
/ N1 j: r7 B% I6 O5 q9 K2 w //11 - Retrieving the applicative attributes we have just set
; {3 l/ @% a* U. g //+ z- j. q& c4 Z8 a9 f! `
cout<<"--------------------------"<<endl;
0 L0 A7 ?7 v1 u c7 | cout<<"Getting applicative attributes on faces"<<endl;& T% P7 r. O/ h+ |' d4 c7 v
//
( E" E8 e+ {- o% q3 e //11 - 1 Getting attributes
( ^7 g7 I0 }/ x CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];4 `" P- w. u' e. B# v
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];0 S0 b+ x9 X: o% f; {. d
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
7 b6 ]- g# m% s; j if (SUCCEEDED(rc))2 g1 A% B3 a: g6 B3 G0 J
{9 m6 E& |( D" e9 e( A
CATListOfCATUnicodeString templiststring;- {3 P! n/ l+ m5 B$ C4 g7 ^
CATListValCATBaseUnknown_var tempCke;
5 J8 |" L" l( J, ^1 T8 I8 e1 m for (compt=1;compt<=nbfaces;compt++)
9 B; m- `; Z3 a8 s* f) G7 p5 [ {& ?0 c1 X5 v4 C# {
//retrieve a list a position k (arrays start at position zero).
+ c; c! N/ a' B, Z J4 \& ~ templiststring = (AttributNameList)[compt-1];9 Y; ~: \4 V' f% [' R, e% q
tempCke = (AttrValList)[compt-1];. Z% h9 r3 y2 [" a/ D* E7 d
9 n4 u; o w0 O, P1 w
int nbAttributes = templiststring.Size();
9 V7 e! Z! F* n- ?' x5 t2 e$ G9 s int nbValues = tempCke.Size();, T3 L S5 ^6 S: Z
/ M; W7 z) b: \- K1 X* {
//the list must have the same size! If not, we jump to the next face
* y0 z5 _" M$ X6 l5 e/ P if (nbAttributes != nbValues)
5 W. N* K* g7 C1 B5 [) g9 B# [ {3 P% w& G! }1 ? h7 e( C; `$ K8 F: A
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;! T4 r. |3 Z) E3 D
continue;
, C8 ]- u- r% ^* U" Q }/ \0 a: p3 h( o; v4 ~' E; x
else0 w O! `7 {1 N" O' P4 |
{4 N# H5 H2 K8 ]4 m
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
. X1 U$ P4 h8 i- h9 |7 c% P5 T, f }
( N& w% |) i+ H; Z8 M for (int i=1;i<=nbAttributes;i++)( b; F( I' i/ q8 t
{ g/ X G7 {8 n" }
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
( w4 n! Z3 z# m }
+ ^, H) k8 ~% n$ I. f4 q( g7 d1 g1 h templiststring.RemoveAll();
8 ?" e! x1 y; x+ e1 x/ e tempCke.RemoveAll();1 Q4 e1 W: k2 F( z# V$ C% x
: i: ^& Q0 _0 v
}8 H8 e2 t" ]: d0 l) @1 I0 w, i
}+ x* g+ s+ ?: X1 J3 e7 B+ m# m
else if (E_FAIL == rc)
# I9 {/ J+ O' s! O$ q {
9 K- N+ G' K$ u |/ N9 ^; A, @: j cout<<"Error, applicative attributes couldn't be retrieved"<<endl;; R8 x( `/ t! |! ?" g" |
return 1;. Q% s- o2 c& G" `
}2 V, G- C3 @! r# [# n
//
* Y& P" ^. j/ F: }+ v //11 - 2 Cleaning List:
; L$ ]8 U0 S* F1 {5 q9 b5 J int i = 0;
! I! `. X2 [5 H m' |: ] for (i=0; i < nbfaces;i++)+ v% E. b* M4 O
{, ~+ F7 I: N1 \/ o! ~% m9 H7 `
AttributNameList.RemoveAll();0 \, x. O1 v( I0 Z
AttrValList.RemoveAll();3 j# X+ z4 K3 m, V" B/ ?
}
' A6 ^0 h( {( y2 k; N% o delete [] AttributNameList; AttributNameList = NULL;0 {" T P, }( Y7 w3 E) D
delete [] AttrValList; AttrValList = NULL;' A( I* |! p7 r4 J1 H9 B: p
& k+ Y* y! [5 L4 r8 M
for (i = 1;i<= nbfaces;i++)6 _7 u) x. a9 h
{& z _$ Z5 _* L8 s+ w8 S% O2 J- p
Brep = ListBreps ;& z2 n4 V7 r" d4 U0 L2 h4 e+ e
if (NULL != Brep)
: G0 H' W5 ?5 k { k( S F: j+ G& o% n3 E" l
Brep->Release();/ ?" j6 ^2 z% g$ F0 r! Y( G: i5 \
}
, L+ b: d! \: s }
' l8 V- @: c0 G9 R( e! ` ListBreps.RemoveAll();[/mw_shl_code]
% d/ C' J: H& T( C. m" K. G' Q3 H* z |
|