|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
# {2 G4 ~# J' Q3 i# x. z" x, {! | //
G* Y5 A: {( S! t //7 - retrieving and displaying current faces colors& H" b! A1 e6 ~2 I( Z
//
8 R) O3 c$ G8 d8 }* F: H1 I% w* [ cout<<"--------------------------"<<endl;
3 [* V& F! P, R9 A cout<<"Retrieving current colors"<<endl;$ h/ O; E6 q( i* c( X) X
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
6 g8 n; V* ?2 g* J* E
# x, l! @5 }; ~! ^$ h" [ rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);. o& P, c, Y7 ?8 h# i+ ?/ J
if (E_FAIL == rc )
% K" L7 Z! V2 S/ j5 C {
, S0 D W) l" x1 C5 z cout<<"Error, an error occured while retrieving current part colors"<<endl;7 L( v2 y; T7 C4 @, ^/ p
return 1; t( `% a3 ?9 R% `( a' `
}) u% t q3 V% `) G4 \" h
' @! ]: `1 h1 R" a4 b; {* o9 P' Y for (compt =1;compt<=nbfaces;compt++). J: {* P# e1 z3 w
{: H0 ~+ e) b, {8 Z3 z N
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;" c, |' g" ^1 P9 O
} n5 w9 |, Q9 T) e' u
+ u/ ?) v& |6 u
//
' d3 R* y' o. }1 Y; g //8 - Setting a new Color on all faces
( w' M" V& Z9 e* R% b2 g" i //3 u0 C( L6 O/ z( I y: [. }
1 h' U* e1 e" j, v% L% t, q; {
//we are to color the faces with different color according their position : three by three will have the same color
& n+ I' t3 a; ^/ ?" U; j cout<<"--------------------------"<<endl;
2 D2 T. |/ u9 I( W- |9 w0 J y* [ cout<<"Setting new colors"<<endl;
0 b; ~* w- Y9 l, I) N& R / {3 H# L* W3 n+ }& _. v& n
CATListOfInt newRed,newGreen,newBlue,FailedIndex;2 [2 K# b2 u" X2 h0 `
int x=0;
. A5 V& _$ z3 C7 U h2 q for (compt = 1;compt<= nbfaces;compt++)
9 l' e% t5 T4 L" V* G0 i {
* r# Z. n& {& f# P! z7 v x = compt%3;$ V2 Y0 `. l1 f; H2 ~ L
int red(0),green(0),blue(0);; Y F1 s6 B; e, B N
if (1 == x)2 ^2 t8 h# [5 L9 Z, X! H+ A7 H
red = 255;! A: ^8 u ^5 Q2 S: [5 {- V
if (2 == x)
/ M( d, A9 V: K# v" o green = 255; K* X) U% K' M; F" h0 h
if (0 == x)$ D8 h H" j; b! Y
blue = 255;+ G) n6 t! `" ^9 O3 s5 U
newRed.Append(red);, S# _ ^, L& s0 Y4 @
newGreen.Append(green);8 k" ]4 d; @) x
newBlue.Append (blue);
% \) E1 w9 o* h# ~( D$ r% S- [ cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
& K; e/ b: o$ k w* l }
V0 k% G8 w! Q3 H5 v- P1 N1 @( N. A1 R* j# A' Y
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
2 D: N. |' g" } if (E_FAIL == rc)6 a; i* k2 g- M1 T' s
{! m( \7 ?( E8 a @; v) G2 N3 s! c7 X
cout<<"Error, setting new color on faces failed for all faces"<<endl;
0 A- R. u$ \) R6 M return 1;: [" `0 _0 e" j& o+ o! K1 y
}
* n t0 E$ Q: r- q" ~1 d* Y else if (S_FALSE == rc )2 B5 ^ X" G9 }
{% v1 R7 _8 G& h' j C* @
int nberrors = FailedIndex.Size();: K8 {" }) @( ^6 b* v) O4 s
cout<<"Error, setting new color on faces fails for faces :";
& }4 x- r. Z5 t2 m h7 Y5 G9 B5 N2 t for (compt = 1;compt<= FailedIndex.Size(); compt++)- k/ J# N! g: M- E: P/ H" m1 G
{
6 B" q6 p+ W* E) T0 K; v cout<<" "<<FailedIndex[compt];* U# P& L: P( v1 [
}! `8 i9 J. b3 v2 p& z! O' T3 I
cout<<endl;! f! Q4 U. i% W0 `" t# B, ~$ a
}
1 I- e- n! t3 C" B, _ else
6 W9 h8 V8 t2 g2 f: h cout<<"Colors successfully set on every faces"<<endl;8 J; t% h! N" L# ~" W: N3 D! @
//
4 B( S3 s3 @+ X, `8 ~& c //9 - retrieving colors we have just set) w# @( Q/ I2 `* m" o7 o
//' _0 `$ ~# F7 g; A
cout<<"--------------------------"<<endl;
+ y7 ?7 r/ e% C0 |# V; I- E/ D cout<<"Retrieving new colors"<<endl;
/ f( C D2 u0 s1 R2 W rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
+ b% J0 Q. u; X! i if (E_FAIL == rc )' z' s3 [% d- B1 k5 k
{
$ f* S! T" n- C) e1 e4 J cout<<"Error, an error occured while retrieving current part colors"<<endl;
+ @7 a/ t: G7 U" s* u# W1 l return 1;
- h* G! Y% U- y( A7 z: a3 c/ { }
; p4 v, f8 [$ n2 x; V) g( u4 I U8 h$ }/ A: G
for (compt =1;compt<=nbfaces;compt++)
+ a4 n9 C' V% s4 c; e {% C+ Z( k4 ^/ l8 C& P* k. _. u
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;7 r. D4 K u, ^$ K+ y- r' N) a
}
9 Q, r& b7 A; i5 u$ s) q! o* Z+ r* e. X# x) M( y8 C* k% h
//" C( B6 U* O- U; _- _0 [
//10 - Setting Applicative Attributes
4 L2 R/ r! k6 k0 Z1 s6 A //7 q# ?& B" f' o$ Q! M: G' K
1 j9 j* Q) }" { //4 b0 e+ g2 r. W6 r* b
//10 - 1 creating new attributes 8 D" v1 Q$ `& v& Y% B
cout<<"--------------------------"<<endl;
' u1 h% m: p* @% ] cout<<"Creating applicative attributes for different faces"<<endl;
, Q* I: o( @! Z: @; T9 W CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];, g3 v2 ]6 h( ]: H3 X- Y
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
, F/ u* l' k6 X$ |* b% j CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
# O0 m6 S. f+ ` G for (compt = 1;compt<= nbfaces;compt++)
$ ?& g7 W& C: _ {& K9 q J5 ]* K. p2 e) A# _
cout<<"Creating ";9 ?9 s8 _3 H p7 m
x = compt%3;
- d7 c! s. \2 b$ D" ? //for each face we create a new list of apllicative attributes/ |: f6 Y s; R( ~+ W( V
//an applicative attribute is made of a Name and a value
! p1 V$ i1 r0 ] if (1 == x)
0 ?8 ~7 w% F) U* M$ V y% e9 Q' x {
w) x4 N) q; B; b+ Q. X& j AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
# Q8 u0 O& Q0 u) q, e8 r AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);$ G" [& L9 P9 p6 [0 c- h
7 t0 u2 N5 ~6 Z# b: M& F2 ^# |
//The first attribute will be the number of the face
9 t k! |& X. ^9 W AttrNameListToSet [compt-1]->Append("FACE_NUMBER");& A! i) y [+ H9 X
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);+ [; p. J6 g! V& g
AttrValueListToSet[compt-1]->Append(tempcke1);
9 V4 J$ }/ f- L& i: s 0 g) T7 ~ Z$ n9 ~( ^! H
cout<<" FACE_NUMBER with value "<<compt;
( O3 N3 a j( M! x$ X, _6 L% l# t y) ~( v* y% a2 r) A
//the second will be the color1 U% ?0 ?$ \; |3 t: _
AttrNameListToSet [compt-1]->Append("COLOR");; i7 |9 x6 ^9 O: w @/ B; d
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
! O5 v/ p0 _8 i AttrValueListToSet[compt-1]->Append(tempcke2);$ e4 p8 I) R" a) U* F
' W) D8 j0 k) C. N8 _, r9 O M
cout<<" COLOR with value Red";
5 l" j4 W: k5 F/ A2 \ ?
& k, o( ^9 Q" S7 q# c //the third is x* H* R& O( z% b0 E
AttrNameListToSet [compt-1]->Append("X");0 R Z O; F! {$ \6 [, h
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);6 ^3 {& s& L5 g$ M2 r- c# h- Z
AttrValueListToSet[compt-1]->Append(tempcke3);8 W5 G6 y( u% h; q: t
) x( L3 z" n3 `3 r: m1 f4 R6 n cout<<" X with value "<<x;" p3 E3 J, O- c
cout<<" for face nb "<<compt<<endl;
+ y' P$ k2 q& Z* d! C* O }
& \. @4 r# A$ g! s8 H: M else
4 T8 ]6 E0 j# y6 Y8 I) k. a //just to show you you can have different size of list j! K# v& L `( F$ v
{
; f8 b# E% |- g' {7 h2 F: L- V AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
3 \ i/ z* N7 c) l; q AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
+ r q. L7 W0 e. Y' r6 T- _8 w) D: X1 ^/ Z+ c+ V. A- h
//The first attribute will be the number of the face
9 ~5 }$ R" w0 H5 t6 F2 C AttrNameListToSet [compt-1]->Append("FACE_NUMBER");: _# _' g3 y* l) G
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
2 a. G: @' l4 N7 _ AttrValueListToSet[compt-1]->Append(tempcke1);
( ~, r+ z& Z$ R3 u& F
6 [( Y# J1 G- ?& H& f cout<<" FACE_NUMBER with value "<<compt;
: z* E3 W6 W* x. S2 e) d( x3 e' B; j6 o" `: P+ H' U
//the second will be the color
, q N- ]( Q$ o/ P0 _2 J' z6 L AttrNameListToSet [compt-1]->Append("COLOR");5 H. W p! C; }6 ^
if (2 == x)
# W# e3 u5 s0 K/ N) x {
. B, a" y6 N) h7 c' Z CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");. e% _: v# U# _- M. {; t
AttrValueListToSet[compt-1]->Append(tempcke2); @0 L- E3 G3 A+ }' B1 }! L
7 G ?/ h f# n9 H. l( _1 O0 s cout<<" COLOR with value Green";
3 [# }: S# w. H5 Z }' g ]5 }" G( ~4 m2 G/ K( Q
if (0 == x)
& Y: a0 o& C1 [- ` {( }. x3 N% l; g9 j( N
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
; b$ _0 Y9 y( t1 ~ AttrValueListToSet[compt-1]->Append(tempcke2);2 Y1 _( p# D0 [9 p4 T* G/ q1 X; A
^% c2 @- d9 }! w: i# g1 [ cout<<" COLOR with value Blue";
: T/ y$ J5 c8 k, f }4 u# x0 B% a# l! A2 w. V0 B
E* V2 J# B' T8 H$ _8 }( R* R C cout<<" on face nb "<<compt<<endl;
* B/ W) R5 N9 V% f' W9 f6 K% e% Q" d
}
3 D+ q( B: L6 Q }1 v5 s' L" T8 F. d1 ^5 T
) H. R" o& @2 y1 q" q //10 - 2 Setting the applicative attributes6 E& H3 b% G( X0 I$ D# ]- ^ `
cout<<endl<<"Setting applicative attributes on different faces"<<endl;7 N2 C2 P6 w: `0 V7 Y
FailedIndex.RemoveAll();
' A+ `7 {6 m5 \1 } rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
4 R& V; V) _+ ?' y6 z, @- I if (E_FAIL == rc), p! |( r W5 H" V" m: `1 \2 p# j
{: p ~: S6 o, ]) A$ j$ q3 A0 g: u
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;* ?% u! }6 r6 |! |6 V( H
}
% `" I8 x, O: w A9 x3 N! W% I3 n else if (S_FALSE == rc)/ e" {5 ^2 q- ^2 R2 s
{
. t; x! s6 r- A, Z4 K int nberrors = FailedIndex.Size();; c6 s# t( N. T2 W
cout<<"Error, setting applicative attriutes on faces fails for faces :";( P7 C* X o3 t. e
for (compt = 1;compt<= FailedIndex.Size(); compt++); h& [; ?4 D l! E, h
{
& H9 N5 m7 m- y' e/ l cout<<" "<<FailedIndex[compt];0 J) C' t+ P+ I$ k4 [/ M) r" r
}
, R4 B p7 { |' u cout<<endl;0 a# S- h: i5 J2 F1 @
}% T& }7 |. h$ l5 h4 g
else
6 E0 ]" x8 N6 T( T$ O7 }' H {
( \, e9 Y0 J( o' l! S cout<<"Applicative attributes successfully set"<<endl;3 M2 r: ~3 `7 G- f$ Q
}8 T+ U' o* ?/ `0 K$ `- L5 e
7 ~+ W) ~8 h" U7 A; t
//10 - 3 cleaning( c) M; W3 I r9 S' f
for (compt=1; compt<=nbfaces;compt++)
7 }7 a# a3 w. f# C* w* a5 P' h3 J {
7 ]5 p' F! z' w1 M- {! _ AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;9 F6 e8 H6 v) {: J# t" M
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;4 F$ W" I! ]3 `8 k
}
7 Y2 ~6 d$ _- G3 Z. b+ s: z* I
8 f' R( P5 g: I- R j delete [] AttrNameListToSet; AttrNameListToSet = NULL;. i: X+ v4 u u3 D# c1 R; s$ E/ h
delete [] AttrValueListToSet;AttrValueListToSet = NULL;9 ^5 l- C0 j9 [3 m* K$ O4 A( x
+ C$ `' k _3 [* X
//
B$ t" c% i* Z: s. G* ^& P; S+ u //11 - Retrieving the applicative attributes we have just set
4 D% H6 q* M3 m5 ]3 W //
l7 v7 v% C/ s# L cout<<"--------------------------"<<endl;
. B, p/ e( M( Z* L, M) q cout<<"Getting applicative attributes on faces"<<endl;
! V& R) l* x1 [ w2 _ //: @' r/ V t# ^5 @- U" |
//11 - 1 Getting attributes. p0 A3 o/ i* r3 [
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
& A A5 Y9 _2 t( a0 c! d! z CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];. ]( o$ d/ k3 V$ C
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );, `- J) @* |$ M' ^' r3 T
if (SUCCEEDED(rc))
3 ]! R$ J) \4 Q1 I {2 p& t! ~: d0 T% y3 \0 T% A
CATListOfCATUnicodeString templiststring;
/ S! V# p$ o3 I& H CATListValCATBaseUnknown_var tempCke;8 S- Z/ \8 C; x# j0 ]. ]
for (compt=1;compt<=nbfaces;compt++)
1 v0 ~& j; ~( j( |9 O {
( M+ v: `; E, L k5 @ //retrieve a list a position k (arrays start at position zero).7 X- l0 P2 }' X6 i/ @. b' q1 I; D
templiststring = (AttributNameList)[compt-1];
% a2 O5 _, f7 Q' B% Y% L1 _: } tempCke = (AttrValList)[compt-1];' R1 _3 O1 ~3 ~9 k* v
7 o( {, X! g! F7 i4 O% q U
int nbAttributes = templiststring.Size();% s5 R7 |5 \& W/ b, v9 k7 {2 s6 M
int nbValues = tempCke.Size();9 b. N9 F' p' ?2 Y8 n
7 w3 Y( ]2 S+ `) r v //the list must have the same size! If not, we jump to the next face
. o9 F' X1 I7 U x) o) I0 D/ N if (nbAttributes != nbValues)4 B; K2 q( m! O0 F: R; g- m
{' K8 H- \# C! J% b# q
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
/ t4 j6 ]; b1 V! q+ z C3 ? continue;' L+ U7 l, P/ e
}; t) v3 Y& V% U5 y5 H7 {5 {
else
- A0 d$ |% g* V. S3 X3 e) X: P# m {) S$ F" X) S6 D' K7 { R
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
, D% u$ ~- }9 Z" ^; w }
3 | e6 _& T( b, I; w2 W7 j& ] for (int i=1;i<=nbAttributes;i++)
% s3 X/ m/ ]" ]* g X, q {
0 c- M0 T& Z( m5 K- \' D cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;7 ^" L2 m2 A+ j, `0 {! \, K* s: s
}
6 u* a7 j0 R# O templiststring.RemoveAll();
" L9 m" W. R6 m9 T1 b tempCke.RemoveAll();
0 A, v- n k3 X* C0 W
5 h* @9 z) o$ x& G }) s$ r# n) o3 {9 y9 n
}
9 c, [4 i7 |' X& J: H3 \+ y. ] else if (E_FAIL == rc)
! h M' Q0 d# e$ E* F) K3 { {. K$ ^ [" p% z- e. e4 H! u
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;- f" U2 R0 A5 H
return 1;+ T, @+ u5 K$ [5 D% d8 k
}7 ~ r7 f2 l1 G, s* i" I# c- G
//. I3 Y$ y6 h- _3 y
//11 - 2 Cleaning List:( z0 j6 `: e7 M- a( z9 N: J
int i = 0;
8 F: d) k; X/ W4 \' I0 c for (i=0; i < nbfaces;i++)
+ y. c' c' G/ @4 B E: B X- V; J {& o, K7 `8 n: z% c8 t2 X
AttributNameList.RemoveAll();7 L" |: S5 Q4 p V7 z, G
AttrValList.RemoveAll();% O1 n# M3 K1 X! x
}3 y4 I) f* }1 \2 h- C7 _5 B- c
delete [] AttributNameList; AttributNameList = NULL;6 n4 m. J- V' e' N" }8 U
delete [] AttrValList; AttrValList = NULL;8 i9 R4 \, |( j
- X1 U4 r2 O/ N- {
for (i = 1;i<= nbfaces;i++)' L F C& w( w6 ^
{
! H+ [5 N0 d4 p& ^3 R% i Brep = ListBreps ;# m7 y, B: `) l. z2 R: ^6 Y
if (NULL != Brep)1 m2 Z; A, ~& t0 R+ ?
{
7 W9 ]% ]; U: z. g! c8 L9 J Brep->Release();+ b5 c" q1 \5 \
}/ S% [: r" g: ^
}
# H, @% _9 ^( G( d8 I, F6 W ListBreps.RemoveAll();[/mw_shl_code]1 n/ @. u) j' L1 ^# X
|
|