|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]- x" a& }+ |6 i5 r: O
//
' v' P ^; W9 F; J //7 - retrieving and displaying current faces colors! u0 N4 G6 L: E
//- q! z+ r8 K: u( _2 g/ v- T4 R' z
cout<<"--------------------------"<<endl;
9 ~# B$ S3 H+ Q+ ^! l cout<<"Retrieving current colors"<<endl;
: s% b4 P9 Y4 T( D0 A$ [! X1 G CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
2 q1 @$ Z* b! ~" C' V $ V9 m' D, j# N5 r% o6 k
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
: E$ g: G% n6 W+ C% }9 { if (E_FAIL == rc )
6 S# e7 k! A; D0 o3 U2 R2 m {# \) g5 X; E8 _/ [' P% Z' ?2 T
cout<<"Error, an error occured while retrieving current part colors"<<endl;/ S8 _' ?6 q* D! `
return 1;
4 A) `* E, W. q8 H5 d }/ p8 e! V" C# L3 k( g2 U
7 l1 E& ~' \& P& r+ _5 t
for (compt =1;compt<=nbfaces;compt++)
$ [+ l$ W) B2 h4 Q+ S* D+ g {' G+ M% t+ p2 z8 ]$ O
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;8 n# ~* Y$ a; s- ^& L1 r
}* D* R6 g0 ?& C; i
; y; A- s" U3 Q* V //; _/ ]# S3 G$ U4 j3 _% r4 }
//8 - Setting a new Color on all faces' Z/ y7 \ B3 c4 G5 k$ p
//' M# \6 r+ ^% e2 h5 S& a
5 A1 u5 o2 V; ~5 i8 l; S //we are to color the faces with different color according their position : three by three will have the same color* A: ~* ?6 w: P" l, r" s( M, b& Z: F
cout<<"--------------------------"<<endl;# [9 C4 ^- Q Y- G1 \4 C# w
cout<<"Setting new colors"<<endl;( D8 I: p8 q: r" e9 U$ v' F; ^( A
6 F! x* C- ?3 {7 f8 I. k9 t
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
/ f! v! X9 |2 u! v2 U: `( V2 D int x=0;" n4 ~3 q4 V1 o% q+ A, K3 `
for (compt = 1;compt<= nbfaces;compt++)5 A$ `' S' @3 x5 Y
{
" y; r7 m3 r, `1 G6 Y: ^ x = compt%3;6 A' I$ ~' F' t) p) J2 s/ c0 L) P9 A
int red(0),green(0),blue(0);% R* a. b4 D: A6 v0 _, ]( c
if (1 == x)
: c' v: v- h$ j7 Y) G ?) l9 K red = 255;
, N6 ?% `. _0 Y0 ` g# L8 I if (2 == x)
2 {' d& h& h6 a) A6 }) ?3 B green = 255;
, F: s/ n* j- c) Y* Z( z2 d if (0 == x)2 v3 E" e7 V& Z% u
blue = 255;
0 `8 X+ `- p5 Q Z+ Q9 e$ P3 X# X newRed.Append(red);/ b3 e8 N- |8 ~
newGreen.Append(green); |0 n& i: U, ~$ s0 D
newBlue.Append (blue);1 \& X& n: J( H
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
! f, S N+ U+ [4 v/ ~ }
* D' N5 `1 O. o i& M/ q
: w, _9 M q6 g" M rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);" `6 b6 p7 p6 y7 ^( b8 S# s3 L3 m
if (E_FAIL == rc)# U& x, ]) c/ V9 u P: u
{
6 b; W4 u3 j' m cout<<"Error, setting new color on faces failed for all faces"<<endl;+ S0 }( N0 h+ Z/ }3 l! a
return 1;8 H7 f. s! C" W' N1 \/ B
}2 t5 [0 ~& I9 \- O. n
else if (S_FALSE == rc )
0 e* N3 k, j S {4 S/ O6 [$ R4 a: D4 W
int nberrors = FailedIndex.Size();6 z5 p( J" B m, u
cout<<"Error, setting new color on faces fails for faces :";
. T; }7 K$ t* D! T1 b! k: q& n for (compt = 1;compt<= FailedIndex.Size(); compt++)
* w4 f* H+ K1 T1 d( T, } {+ y3 I4 A \3 y( {6 W- ~! t
cout<<" "<<FailedIndex[compt];& G. C4 ?! }& ?: u
}
+ W: q$ i8 J$ E8 a0 N( I2 f; M cout<<endl;( i0 Y- b* l, W9 M% y
}$ F2 O; ~# d& B, A* e2 G
else + P2 K) y1 Z# L1 ]: }
cout<<"Colors successfully set on every faces"<<endl;
3 ~ |: ` E, x+ y //% O3 m0 y Q% M5 N, e! J N
//9 - retrieving colors we have just set
0 ^5 d2 G- F7 R9 ]# C //2 r3 Y. Y: C4 Z" N) y0 K
cout<<"--------------------------"<<endl;. _! _0 |" T& A4 q
cout<<"Retrieving new colors"<<endl;
/ B' c- R( e7 w rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);* N4 r1 V Z" j' \( }1 k' l& u. F
if (E_FAIL == rc )& i& `/ p6 o [8 `
{. T- z& q8 p& E9 c/ z
cout<<"Error, an error occured while retrieving current part colors"<<endl;
, c: ?4 v3 `3 ?2 Y8 T3 y. j2 k9 M. J) ` return 1;) \- y* ]% @: c1 \8 }+ z
}0 c8 U. U5 j2 ~% Z$ W- Z! S
+ W* i+ o7 l I0 Z9 D4 r. G for (compt =1;compt<=nbfaces;compt++)% _+ S) y' `6 W8 Q' ]
{
* Z9 W, M( h! E cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
1 j1 h! g# o: w6 m& \. h9 M }
* ?. N( s- n6 }9 q9 Y4 I% _4 N" A1 ?$ d/ h5 ~
//' s4 \+ f/ `) K" g+ A* C
//10 - Setting Applicative Attributes) X5 X7 _0 Y d) T
// ]) d2 F! u {5 o) {5 _
) ?, u" W% U' w
//1 F7 J; w" a4 d3 D/ z. r. B4 T. Y
//10 - 1 creating new attributes
+ {; E! A, G% E8 a cout<<"--------------------------"<<endl;; o$ I) v" H k" C! }3 w
cout<<"Creating applicative attributes for different faces"<<endl;2 @5 v5 G" e. K( [
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
& g7 J+ Y U$ g CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
/ s+ I- ~3 M; M4 r" R) A CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();+ q3 E. f8 K* z( J/ _( F0 u
for (compt = 1;compt<= nbfaces;compt++)
( t7 x% S& Z8 L k {7 ~: H/ h0 V5 U$ K
cout<<"Creating ";. m* X: N' W4 o8 d, |. G
x = compt%3;; [) \2 C, l9 P+ P* x% C
//for each face we create a new list of apllicative attributes
) o C+ p$ S& n0 _/ n5 f! d$ J //an applicative attribute is made of a Name and a value: S" j; ]( x, Y/ k! |# ~
if (1 == x)0 s! H1 {" t% N; a Z
{7 M$ N2 L; ~8 S4 j3 q
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
& ]4 N" u4 V+ o; \ AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
" R1 ?* b. ?( W: c6 G! J- [6 e
9 w' j9 w# A( U" V) q# v( g //The first attribute will be the number of the face
3 P# _# |" X+ E E6 F7 G0 _: `8 T AttrNameListToSet [compt-1]->Append("FACE_NUMBER");# H2 v. H) x7 e6 E6 c
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);% {3 ^, U! S6 U7 J. a$ z
AttrValueListToSet[compt-1]->Append(tempcke1);7 A% `( X* S5 x; R1 | x
1 G4 z. |* W" o( W( L* |3 H$ Y
cout<<" FACE_NUMBER with value "<<compt;
: E* t8 d# C4 F/ Y6 C& i+ B8 K, G! {% t( _8 ]& y( e
//the second will be the color
) K A! j: K4 U+ D$ k! Y, y AttrNameListToSet [compt-1]->Append("COLOR");' g- V( S. f& [4 B
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
8 k6 F1 O% G+ W& j7 D AttrValueListToSet[compt-1]->Append(tempcke2);4 x _ V7 W- r+ G
4 Z |4 S6 K; e o& f! k. m
cout<<" COLOR with value Red";7 {* u5 t( B6 a! G m" F
/ [* m' K$ ]0 X' B, Q5 ` //the third is x* y3 H, u3 l2 C
AttrNameListToSet [compt-1]->Append("X");5 X, N+ }' ~5 \* a
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);/ N9 y2 \& J$ M9 z) O# N) u7 ?8 M
AttrValueListToSet[compt-1]->Append(tempcke3);
; A3 j- g* s$ d$ h : {8 ?6 ~( j. i
cout<<" X with value "<<x;! v3 o. F6 @% N5 ~' E
cout<<" for face nb "<<compt<<endl;
, s+ G4 X: q. ]6 @" I) v }
* ~2 P7 q6 s* i/ Z8 S3 u else # Q& z" n* j, o5 K) c6 h
//just to show you you can have different size of list
7 p9 U1 o, d: [5 m y! K {) [: d1 ^ G, z5 A+ N: G5 ~4 z
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);' a3 }2 H V) T1 H# c
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
' b) P: M' G8 U5 g- v J; w9 P+ Y: F6 v/ G
//The first attribute will be the number of the face3 e; |) A8 Q& G, f4 e
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
( Q* }6 X% T, f- w9 [ J CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt); { Z, Y L0 k2 w
AttrValueListToSet[compt-1]->Append(tempcke1);
' i f& y% \# e9 b
4 |1 b8 L2 I% J. J cout<<" FACE_NUMBER with value "<<compt; . k! A& A, ~6 j& u, Q! M5 W8 I* a
9 @0 @- `7 \1 o
//the second will be the color
7 Y) _: @ G0 _7 g ?2 I AttrNameListToSet [compt-1]->Append("COLOR");. Q3 F# J0 p4 ^! \) J" \/ p
if (2 == x)
. c$ y# x6 H# I% B. I4 |4 `! a1 U2 f! @ {
1 U2 U0 h- a' Z* s" Z9 ^* l' | CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");" b( r* E: E- v' q
AttrValueListToSet[compt-1]->Append(tempcke2);6 b! n+ W8 u: t6 ^5 R2 h
& V/ O/ _; p9 E9 ]
cout<<" COLOR with value Green";
' B1 @' j2 r/ @2 O% r }
0 n+ q5 i* C% ~$ E+ @ if (0 == x)' [! v o" N7 n" t* j
{
! k& ]7 i" e5 [- _& P- a8 C CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
7 i( j3 z2 V( v AttrValueListToSet[compt-1]->Append(tempcke2);# m/ h. W: H! W3 I& P+ [6 P1 g
) F# R7 r+ u; G j# w cout<<" COLOR with value Blue";/ y6 Z# z# C* E3 ?; Y8 _
}
2 X' ]+ X+ n0 N6 a4 ~, O K
; _0 D8 f8 m. q" S# V' u; i cout<<" on face nb "<<compt<<endl;
3 X5 i- C$ ^! y! O
) p R+ f* X) {6 a4 `5 @1 S. y/ r2 g }& g6 `; y# m& Z) _) W. A
}
" ~3 [, ^; c& V# Q5 A9 R( K' p& q# c( \' _8 ~3 o3 o
//10 - 2 Setting the applicative attributes/ _9 \) c, `8 M
cout<<endl<<"Setting applicative attributes on different faces"<<endl;# J6 A8 l" S" a! F9 ^
FailedIndex.RemoveAll();9 I' S/ b) Z5 O, c
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
( w e( j. o; u* v if (E_FAIL == rc)9 l' b; _, O7 F' F5 l h
{
' W& b& R, S2 o/ R5 J cout<<"Error, we failed to set applicative attributes on all faces"<<endl;! ]0 l5 t* M& v/ G# u& m- k
}; e- \: c2 z5 T% B5 {" ]9 g
else if (S_FALSE == rc)& R! n5 \0 m% E* M3 U( t$ m
{4 g: n. V2 S; J4 {1 Z Y
int nberrors = FailedIndex.Size();; p6 U* o$ x+ ?/ y
cout<<"Error, setting applicative attriutes on faces fails for faces :";( T7 A6 y6 z: w0 M. H
for (compt = 1;compt<= FailedIndex.Size(); compt++)
r7 i: w3 i7 N$ N {
$ B0 i1 a% r6 H ] cout<<" "<<FailedIndex[compt];/ s3 v# M* x8 k( y
}7 {. P h% i3 |: v) [3 M/ R
cout<<endl;9 W. X6 X, S% E: A
}( s0 ^" ]5 f% b% k
else/ d% }# g2 T! }
{
: a& U+ ^0 [4 G cout<<"Applicative attributes successfully set"<<endl;
8 y+ a; I, q l7 @' M: I+ F }
' O- r) c) j, D$ N( A* p' Y# i' w
1 i3 l) O9 x6 [0 `, M1 l% Z //10 - 3 cleaning# L! d8 b; R, u2 \
for (compt=1; compt<=nbfaces;compt++)
6 b! Z( ]1 e0 A7 `9 ^ {% `) n4 K. |$ l# b4 \
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
8 c+ Z) e& H0 a- X& x7 B AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;: `' V7 b/ z' ~" }& t6 ?
}; @/ V" C3 d/ H) h0 P$ w
/ x" \' _7 e7 U0 |. T' I) P
delete [] AttrNameListToSet; AttrNameListToSet = NULL;* G( v& t: C$ o! P( V' y8 u1 _
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
+ J# T5 n8 M" i+ \. V" L0 g: ~" p; `
T0 @7 T' H& L4 G" w //
& z# e# r5 j) k1 M8 N. H3 Z //11 - Retrieving the applicative attributes we have just set
! D' z1 o$ D3 v0 O( ~* ?8 K //
, E; M& \3 n# H8 E9 G cout<<"--------------------------"<<endl;
3 K! N6 r! Z- [& [" s: [$ `( h1 P! N cout<<"Getting applicative attributes on faces"<<endl;6 B5 q9 I* q5 a' I, U& p! w ~" h. a( t* N
//
2 j$ h5 Q, q& _& @ //11 - 1 Getting attributes
+ t8 I! c/ i7 W2 m CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
2 L) O/ l d& Q5 ^; f9 i CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];+ ~: x, T# E( L9 Y9 U3 G
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );" B4 a+ Z) O: c. ]: H* U" k
if (SUCCEEDED(rc))
1 H9 D1 k! Y3 I0 d: W% o) _ {+ P, {7 ~7 R1 B- L
CATListOfCATUnicodeString templiststring;
1 h' N; j# k# @% R1 W: d3 L' \ CATListValCATBaseUnknown_var tempCke;0 t0 T9 d9 S$ V- E- O
for (compt=1;compt<=nbfaces;compt++)+ n! s2 b& O, v5 s) n
{' w0 m' u3 `9 k7 t. i1 w6 U) Z
//retrieve a list a position k (arrays start at position zero).. u# u- I3 e0 ]# O* m2 U. l/ a
templiststring = (AttributNameList)[compt-1];
8 O: d L: f+ J" c tempCke = (AttrValList)[compt-1];
4 w9 n2 N' I) U, `" j3 }$ \; G' I* p% y
int nbAttributes = templiststring.Size();
2 B. q$ b+ |. {* I2 x int nbValues = tempCke.Size();
: I, j: ~6 D5 r, e
' g* S4 a" W, p //the list must have the same size! If not, we jump to the next face
( L" n, P, y( n6 k if (nbAttributes != nbValues); F- o/ j7 C. K9 |
{+ Q2 n3 o5 D7 D0 ]( p6 {- o7 U9 z
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
4 n4 V' x- P E( r- E4 U" z( O continue;6 C2 P" x, l3 w" Y7 X
}
5 u% D1 C4 G% V; b: I$ S else" X* d0 G; }+ a g+ h2 R& L
{8 L" P* o. ~/ @8 C/ y8 X0 u
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
% C/ w0 r8 @2 \, e G }
9 Y1 ^ x: f2 N6 s7 C: | for (int i=1;i<=nbAttributes;i++)
_; a8 I4 S: ^$ l+ ?: Z8 y {& ~3 h( W8 Q s; t/ g% O6 S
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;& A( P3 r1 h/ k) ]- g# T# q
}! l/ k6 R' f* B& Q0 _' H# J
templiststring.RemoveAll();: \( `8 X2 ^" q! n
tempCke.RemoveAll();9 O' n; L" W0 x* B6 C) ]
+ b6 u5 y- X. H/ w5 } F }9 J" b. f9 g: b( N: X) G- l
}
( W" C. ]% Y0 G# f/ k% i else if (E_FAIL == rc)1 g1 g& B' b8 H$ t
{; L: W4 M/ F. O: p. }. J4 N/ R
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
' s# L6 O5 t% w( X. V return 1;
+ l- R6 \ u/ b1 u4 Y) n }2 n1 m$ |2 ^: G: ]
//
5 ~/ Z* w! U! E1 E6 \ //11 - 2 Cleaning List:1 Z F1 D$ S; S( C6 Y
int i = 0;
" R4 @9 f5 m' o% R& x* R for (i=0; i < nbfaces;i++)
& @' `/ y* N1 y3 q {
* F' Q5 ^! A% R f% s$ u' e AttributNameList.RemoveAll();
4 z* Y+ _# I# C+ t6 m3 \# u AttrValList.RemoveAll();
H" U% o3 G# J$ V9 V }
7 U% p, p; H& A3 O delete [] AttributNameList; AttributNameList = NULL;, E: u6 V% B) n" K; O- z& b2 W) S; B
delete [] AttrValList; AttrValList = NULL;
U6 ^( @! @* y$ h2 s$ h
1 C4 R2 T. w; ]! @% { for (i = 1;i<= nbfaces;i++)1 y9 R: p! R( y. ~0 e( f& f
{7 C; h: a7 e7 b& i: Z1 r, G
Brep = ListBreps ; R5 q: X1 h/ j: {6 p4 O6 }* |
if (NULL != Brep)
) {; p8 C% q3 C U {$ X) x, n1 X# D/ L# x* j
Brep->Release();
1 K! F _4 y9 b1 O! b5 D }" S9 Q# n3 a. U* H8 r
}
2 L2 ~1 S$ H' ^. L ListBreps.RemoveAll();[/mw_shl_code]
: {6 r g7 }% R" O& a2 S! m |
|