|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
& W7 g% v: X; D, h1 }2 b" \: C //
) i+ c) G" _6 V9 Z3 ^ //7 - retrieving and displaying current faces colors
1 r1 D8 ]) [* _ y/ s" w //
$ s* m" ]- H3 b- ^, I cout<<"--------------------------"<<endl;. u; e! Q d+ ?. q8 m
cout<<"Retrieving current colors"<<endl;5 B# ~+ e" V! j- _4 X
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;2 U; i n7 t0 V9 G1 X- `9 ^
4 V' ~: V: F* t, ~' Q0 \ F. T
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
0 P" H6 D( {. I, U+ N if (E_FAIL == rc )7 o$ y- g* Y N0 g# x
{' d# z* s/ J$ C
cout<<"Error, an error occured while retrieving current part colors"<<endl;! K, m! l3 k6 k3 u" Q: F% v
return 1;! T- X0 }, B5 i: T
}( U& X) t+ p& @0 x2 q
& B1 T9 m) }7 D% X for (compt =1;compt<=nbfaces;compt++)
4 t" d, m; a! [8 _( ? {$ Y# z& g: ]1 X3 L8 `4 Y# m0 e7 e
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! Q, X2 M( F4 l3 ^0 l$ n# u }
# F7 l% K1 L6 w# u+ e/ E9 B/ n
- P( D! y' v" E //- f, H( D0 W' d; b$ T
//8 - Setting a new Color on all faces
4 p5 Z8 S1 V2 F //) D$ V3 Q/ M9 ?9 f- \! k
& X$ \& R( Q3 r% I d9 n //we are to color the faces with different color according their position : three by three will have the same color
/ Y( A/ T4 f% q( R! S' m cout<<"--------------------------"<<endl;. C8 e! X6 S& q
cout<<"Setting new colors"<<endl;
* A5 B W% |( g: i. V V
3 }8 p: M- X9 B- p CATListOfInt newRed,newGreen,newBlue,FailedIndex;7 V+ [2 t# C; k/ v" V
int x=0;5 x$ i- @' }. N* `) s
for (compt = 1;compt<= nbfaces;compt++)
- G* Z( m, h4 [/ p o0 r( T {
/ m# H6 U) c" H8 a; u' z. z x = compt%3;
. [$ B' `7 s7 j/ O int red(0),green(0),blue(0);
7 ?+ x7 @" v* x7 T' W& ]# M! J if (1 == x)" M4 l: |; b7 i2 `
red = 255;
# |' Q% [ f6 f5 D/ J; m0 f if (2 == x)$ K! r3 \) s; t/ n6 Y4 y4 F7 z# q0 ^
green = 255;
- Z/ ^+ U/ C! g+ z if (0 == x)
" O+ ` w* A; m3 w8 d6 ^0 n blue = 255;0 R% _( G) Z/ z; s9 t/ t- G% X
newRed.Append(red);. Y( S# {! N! v# H& k6 D7 M
newGreen.Append(green);; p' ~* h' I* @
newBlue.Append (blue);
: T& v% \: Q. k4 g F" c# I8 [ cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
0 C( X* T) u& ^# s' z9 V, j }: c1 E$ _8 W" F. P& {- F4 p/ w0 f% N
9 {, \" g: F% w* P0 R- {9 B
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);+ c' t/ ~5 V9 S/ s3 _- |: P9 L
if (E_FAIL == rc)
2 g" Z8 J9 x& P) G0 o {
% s# k! ~' m, }5 R6 ] cout<<"Error, setting new color on faces failed for all faces"<<endl;; P9 s3 _0 g* H4 X: _
return 1;
) B: b* M: j1 x6 S }
1 M9 k* Z/ {) p/ n else if (S_FALSE == rc )+ L: }: ^0 E1 u
{
/ S$ x, ?& c2 f8 X0 g int nberrors = FailedIndex.Size();
, o/ @2 d+ R9 Z6 n1 D+ K# s; W cout<<"Error, setting new color on faces fails for faces :";
+ ]/ b5 i( Z' ? for (compt = 1;compt<= FailedIndex.Size(); compt++)6 G: L$ F9 D `6 J8 i: S- r" C
{
7 x$ O: _ K4 L1 q3 ` cout<<" "<<FailedIndex[compt];
/ m0 T* e; ?# O2 i3 w) I, @5 K }
7 o7 _1 H' Q3 w: b \ cout<<endl;
3 L- q0 \4 W. \3 W7 H5 X }# V5 u* X- c# k: Y$ C9 _
else
) R9 I. Q4 F' d& x cout<<"Colors successfully set on every faces"<<endl;
4 _0 [" U6 z: U$ ]- a //
7 C& v% u+ g) j: g9 A //9 - retrieving colors we have just set
, W7 T. H" C4 U //5 H9 y/ ~+ [8 |! g
cout<<"--------------------------"<<endl;
% S2 n& g! Y4 z* w cout<<"Retrieving new colors"<<endl;* }1 M4 `# o. S2 Q
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
% z+ O% h! c1 c9 x% G8 m3 U3 p. r if (E_FAIL == rc )7 Z, t1 H5 F0 R0 L! Q
{
' ?- X `. i" P. L+ Y! h; r cout<<"Error, an error occured while retrieving current part colors"<<endl;
( d4 p- B5 a: l3 e: R2 ^ return 1;
: B$ a/ R7 a" I( N+ }) P& D. p }
2 ?# o; `: P3 f9 R& I6 s# {) s" L1 h" M6 w+ ]
for (compt =1;compt<=nbfaces;compt++)6 q4 L& y/ y2 B! E
{
3 C$ l# [' H% ]0 |! | cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;! ~( L" q i8 ?* M' o* l+ d
}; u( G& F T1 f- b: U( F
Y: K+ g7 G5 o9 w //: I+ o% ^; ]8 e; Q0 l
//10 - Setting Applicative Attributes% I8 y& S: Z$ m* R' V
//0 ~4 O0 x! K! b `
1 e/ ~1 b( C0 D6 M4 {
//% \: \! |: r; W
//10 - 1 creating new attributes
9 y% d4 x8 e7 q% D6 V cout<<"--------------------------"<<endl;
1 [4 G% P6 E( S$ c1 g0 n3 w cout<<"Creating applicative attributes for different faces"<<endl;# {/ J- A. W" }9 D: L' x5 h" u4 Q
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];4 |% X) I4 s2 l2 U) U
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];7 S6 b, M+ C# n3 c; ^
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();* C R5 @8 i J: z( V c5 S6 d: j2 k
for (compt = 1;compt<= nbfaces;compt++)) ~1 ? R3 X5 L5 u4 Z+ E, R$ q7 O
{) j) y! |; T; |/ j0 P2 Z
cout<<"Creating ";+ b7 h0 h; h0 [! s2 v
x = compt%3;9 z! f( `* L h8 _$ u
//for each face we create a new list of apllicative attributes
9 i. f. Z$ m* \) r* H //an applicative attribute is made of a Name and a value& \, Y2 ?8 ]! m, H
if (1 == x)
+ ?8 C9 z d. g& s8 o {
) K+ V( T6 H# [( O. Z, n AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);' y9 H( O& D4 Y% Z4 I, C
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);6 _6 L9 e2 v; ?9 |8 a3 e1 c' l. l; B
+ m8 i' |+ F* B' U- I
//The first attribute will be the number of the face8 C' V, j1 U2 r: k
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");/ ^6 \# y( h4 g) u" |" m/ L3 o
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
& a9 r& k3 L0 W. T0 k AttrValueListToSet[compt-1]->Append(tempcke1);
+ X5 a9 s+ P5 E. J 5 U0 C+ \- o7 j% \
cout<<" FACE_NUMBER with value "<<compt; 9 X! j, h+ K6 L1 K
, p+ z" U% e" }1 C* y
//the second will be the color
0 Y/ Q, N3 u% n% ~9 C( U$ m, B AttrNameListToSet [compt-1]->Append("COLOR");
9 [& T! S. [* v CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
7 G1 e: U4 g! G9 b+ y2 | AttrValueListToSet[compt-1]->Append(tempcke2);
* a" |( z2 i5 G7 z0 n# J
! A1 H! I+ M8 Z7 ` cout<<" COLOR with value Red";
' N6 \' Y* q. _4 S5 x! q ' @" S' P9 n. U8 B8 u
//the third is x% X" G/ _6 F- \, o q( s
AttrNameListToSet [compt-1]->Append("X");
9 y% q* |0 a% J+ m CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
; r9 x% a, P u; r/ a AttrValueListToSet[compt-1]->Append(tempcke3);! V: U( b$ g+ R% J1 S# e1 X+ u
- j3 [4 q Y. c' l
cout<<" X with value "<<x;6 O$ @" Y( ~% N1 _. D% a9 C& U
cout<<" for face nb "<<compt<<endl;
, h# a- x T: A6 d+ Z$ I& g }
, }% m- z2 r" x else
2 h* s& \; ?( f //just to show you you can have different size of list- |: m4 u+ {9 Q$ U
{
- G" S& S! J3 n% ~- I6 |: o# s; ^ AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
, d: [) b2 |* x C8 [2 }1 n AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
9 R: f8 V6 r& V) z, @
/ l# D6 G; j) r& A5 h. y4 C //The first attribute will be the number of the face, P5 ^9 z b: `. T
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");: c/ c& \! }, r, s) t3 J! V
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
9 K: |/ `* ]3 h. I# y4 _+ | @" Z AttrValueListToSet[compt-1]->Append(tempcke1);/ I( _2 F% W9 _
: J2 a9 ^: T4 R5 E
cout<<" FACE_NUMBER with value "<<compt;
/ Q" B" k8 I0 ]' X k
$ P0 ^; X) C5 S- [/ V4 [+ M0 z //the second will be the color
5 o7 ]6 m% n+ I AttrNameListToSet [compt-1]->Append("COLOR");
; V( |* b0 H# ?. E& M6 Z) I if (2 == x)4 @3 c, }9 }! f9 b: [6 y& `
{$ y/ s! E& V( z4 j; Z6 t
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
. ], t0 ]+ A/ ]) }: k9 G AttrValueListToSet[compt-1]->Append(tempcke2);
9 K( z2 H' } z% m% N/ i, s9 k% k + R$ ~+ y8 Z. n6 Z0 ~# c* h5 b. V
cout<<" COLOR with value Green";5 a3 ^ j" `; c; `+ U/ c+ o, i* P# [
}/ z, r) A5 b) l$ Y3 R0 w$ e5 k
if (0 == x)
2 r/ C: v. M- u b {. y1 w, ~! n: n8 Q5 h/ M
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");5 z1 E0 {6 v# E% r7 a
AttrValueListToSet[compt-1]->Append(tempcke2);
* l$ n9 U. ^+ o3 @# _, i+ w2 ]
" L: P/ M4 m: q+ G# M" V* P& O; T$ v cout<<" COLOR with value Blue";/ _2 R5 r% ^* D5 x# g; S/ R8 _' u1 y
}9 z6 C0 n$ o- R( H$ P+ o0 O
% r& i4 A. _: ~2 A; b
cout<<" on face nb "<<compt<<endl;
. O/ {* J/ \$ V* C5 V, l
, A# ]" d' G, J# C }
; V' r- P5 b6 |0 F }
/ t$ B6 Q) x j' |1 r/ P6 C9 j7 i% P; s$ ^
//10 - 2 Setting the applicative attributes( M9 R" y2 G5 f( }, E" d* K8 _
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
: X/ l/ P2 _+ M1 u FailedIndex.RemoveAll();
% N( C/ Y6 {0 Y5 T# J& x8 r rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
% e6 Z* @" U/ r9 J: w/ q( F if (E_FAIL == rc)
' v$ L$ I7 v& z# B {
9 P* G: N. v; Q cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
5 W5 h7 x- F- k9 i }
+ |1 X; X2 s+ K# L+ _ else if (S_FALSE == rc)
k4 I3 A( a) E7 Q {
' B; E2 N$ g+ I4 H& a5 a( b int nberrors = FailedIndex.Size();: j' u1 D8 \/ C* t! V, \* S
cout<<"Error, setting applicative attriutes on faces fails for faces :";
! H8 N! F% v4 S8 U5 ] for (compt = 1;compt<= FailedIndex.Size(); compt++) A" z, E: B5 f& \- {! u8 [+ e
{" L6 P) ?* g* C) i% K
cout<<" "<<FailedIndex[compt];0 x; B. e. d& {8 e) G! @
}8 L6 ?( m, X4 m
cout<<endl;
. ^* f$ {: M! |! w2 U: V4 C' e& y }
( J8 X- J8 c5 n- z# X/ f$ `) ^ else+ \# u1 G3 Y6 G6 Z; K9 ^9 o
{% _6 g/ u9 b& a$ s9 q# f
cout<<"Applicative attributes successfully set"<<endl;
1 X! R1 Y$ Z8 { }8 c* X, V- v0 d7 i6 q% s5 Y
. d) a0 K$ j' z8 ?" m! A8 U/ A
//10 - 3 cleaning5 k& c# \+ b, V; O8 w2 c) a6 B6 N
for (compt=1; compt<=nbfaces;compt++)- s2 N$ u0 V2 J, I
{9 t2 a n; g6 i4 F/ H; L
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
9 a. F3 s* ]! t$ `& Y- k1 H2 H AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
z" R4 r/ f- q( g, d- ] }) E5 |7 G8 Y* A) f) t. `0 A! W
, V3 h7 b* v: \0 _1 }# p" X
delete [] AttrNameListToSet; AttrNameListToSet = NULL;
7 e" O9 U' L2 \6 j! Y% P delete [] AttrValueListToSet;AttrValueListToSet = NULL;6 { E: T2 y( u* q& Z$ [. W5 g
8 q. n$ O4 V8 `' e6 i( R
//$ V8 ^) a; P+ g
//11 - Retrieving the applicative attributes we have just set6 ?# h; Z. ]0 y
//
3 M% q$ g) r; k cout<<"--------------------------"<<endl; d$ [0 U7 k/ v. Y0 b5 N* d/ G0 k
cout<<"Getting applicative attributes on faces"<<endl;7 H. I6 I' l, z0 Y, U3 ~
//: W, I- Z6 O9 k6 l; ]
//11 - 1 Getting attributes- r9 i* Z5 K/ W$ a
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
. O! Q A( }$ z8 N& z% E CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];) O+ \ @9 v! k0 U J0 Z
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );* b6 t9 I& M5 {7 o4 a" d3 p
if (SUCCEEDED(rc))
' u* b( M& u6 C: X l& o" r* N {( J+ G5 M2 R/ _0 L/ ?1 B: @0 O0 }
CATListOfCATUnicodeString templiststring;
( M. L" O1 E4 a0 {- |/ E CATListValCATBaseUnknown_var tempCke;
9 J* r( v8 M) x. H5 b for (compt=1;compt<=nbfaces;compt++)7 b5 k! Q8 H7 ~! Y
{' G0 R3 u: ? `8 ?0 q2 ?+ N0 K- O
//retrieve a list a position k (arrays start at position zero).
* W! e# l, g( o3 S. L- p, Z5 ] templiststring = (AttributNameList)[compt-1]; W8 a+ Y' m) }% g! ?/ c' |" _
tempCke = (AttrValList)[compt-1];
+ K- {2 G& l0 `! H
) g4 Z' a! T% ~ int nbAttributes = templiststring.Size();
$ m. M+ [ ], G$ K C0 B int nbValues = tempCke.Size();
. B$ C6 g/ G7 i; p( R$ \1 T* c, e y' k8 f: Z0 _3 O
//the list must have the same size! If not, we jump to the next face
( W6 M' w! [$ N4 L( N if (nbAttributes != nbValues)
9 p5 Z) ?) A& Z {3 Y# G4 }# _$ p% I# L, b
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;: r0 g! u/ n& x' f
continue;+ h5 P J# ~! T# A7 v. v
}
8 O) V& {) [7 w2 B# P1 E' q* P else
4 ]7 N7 Y9 `2 ?! ^4 V& r$ j) r {
$ p3 k0 H+ f" U5 c! y4 | cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;; B5 u/ y9 K- C$ T' Y( v
}1 ^$ n5 b! X2 i. U9 x, A' Z
for (int i=1;i<=nbAttributes;i++)
& E+ B! o0 a4 D- Z8 s7 ~1 T {
1 D/ Y O( v2 q/ o( a cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
( s! Y8 t2 T1 {; k }
8 ?" m. C6 W1 J8 M: _: Q, v' m templiststring.RemoveAll();8 J9 ?, w; j- \9 L" H% N& H; x
tempCke.RemoveAll();
- E0 B0 ^# L+ D
, p4 m3 g# s& Q0 R }6 h0 m, c& u1 E* y4 C* R. u
}# e; o; e( J- S" X/ p
else if (E_FAIL == rc)
3 f" x! s) q6 q7 |! o {
8 U. ], d7 J6 { cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
0 u3 s3 b8 R& p3 q6 b return 1;
) V( ]: I$ }8 X" f7 t( V }
. E) ?. X* ]" h3 f0 H0 O //
3 t, [# e6 E9 {: g6 J5 ? //11 - 2 Cleaning List:/ ?$ V4 |, I. s) Q5 F/ N X7 W
int i = 0;
, \! O% X4 B" G. k d for (i=0; i < nbfaces;i++)
# J, q3 ^. E- Q) y# x* ~ {- g& ^ n2 s5 J4 v2 Z. F1 q$ J
AttributNameList.RemoveAll();- L4 Z7 d. _$ \, y) A; b: L* m
AttrValList.RemoveAll();
5 Z8 G( Y) f0 R p* \. G1 G }% W; l+ E! N! V2 G+ f- O
delete [] AttributNameList; AttributNameList = NULL;' ?, M$ Q: \- K: F" j3 ]( b
delete [] AttrValList; AttrValList = NULL;
. Z6 {5 E4 F- I; r, l- M7 C S0 _0 T# h
for (i = 1;i<= nbfaces;i++)
" @1 u$ Q7 G) Y5 g6 L {/ h$ w8 h2 A0 ^" I9 E
Brep = ListBreps ;
( l `* M; t, @- p. y) ? if (NULL != Brep)1 { c, X$ i% D# i1 u9 i" r' F
{
$ u& c# U/ w9 D3 h Brep->Release();
% Y8 u2 y) I6 L }
; Q& {2 A* X6 \9 Y }
/ s8 A- K" E; g9 b/ C7 D( _ ListBreps.RemoveAll();[/mw_shl_code]
: S6 P; r$ a' x3 _% N$ W |
|