|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
4 U) g2 M7 `1 _& f( x; F( T //
4 C: j# s3 b' T) K& F! f* S( {7 ? //7 - retrieving and displaying current faces colors5 z9 L6 n/ ~0 e
//! [' t& i6 j; Q7 l
cout<<"--------------------------"<<endl;
4 p7 d7 j0 y- V' `) l8 | cout<<"Retrieving current colors"<<endl;
6 b9 s, L, d z CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;9 v% y8 t5 G( |2 n/ z' e+ Q; f
9 T' x9 X( X8 Y5 M rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);6 F9 e( v3 g" v/ m+ J) @
if (E_FAIL == rc )
/ m2 [& `8 ?; R1 C" }, Y {
7 o9 Y& A/ O: ] cout<<"Error, an error occured while retrieving current part colors"<<endl;
6 T( {4 L/ M6 B$ @2 g8 v return 1;
* j( |( i+ ~ x }- ?. M/ B. x; q6 _3 e1 M) j8 E
$ d+ i) k7 u( T
for (compt =1;compt<=nbfaces;compt++)
( o, E! J& H" l5 A- K- J {; y3 ]* V/ \7 F- U/ l) M
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;6 q3 a9 Q% ?- t+ q% i, z2 S
}
( `( \) h8 p, f% X, s, {. _) M- G$ R% R0 f2 g7 k
//0 I8 U* L, B% c
//8 - Setting a new Color on all faces
5 I% j" o! H% `" P0 v+ Y //7 r' r2 v, i2 T- \" u+ v7 N
& ^# A+ @% [" p+ }' |% }5 c+ {, c
//we are to color the faces with different color according their position : three by three will have the same color: T0 \- A0 Q+ E) C: _( {# c, s: D( S% c
cout<<"--------------------------"<<endl;6 K# t/ Q5 V3 M
cout<<"Setting new colors"<<endl;
, V0 Z1 x3 a2 a3 z5 F7 e ! F2 ^+ F: a: s& q
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
7 t& v- H9 A- L! K" @ int x=0;
0 Y$ p( p- y* U& d for (compt = 1;compt<= nbfaces;compt++)
5 D( A# S5 n$ o9 T( G {
% t5 b1 s. B. I& ]* \% m; M2 ~ x = compt%3;
. f8 t: C+ K& ~5 j/ m( l int red(0),green(0),blue(0);: p3 V O6 t4 s# [6 Q' [' U. E
if (1 == x)% \4 Z v. n# C5 M# |
red = 255;% V" h& F; N: c- v7 W3 _% D1 X- y
if (2 == x)! c% r( Z$ x3 z2 O. [0 T2 h2 a8 r$ x
green = 255;4 _# ?5 {: L7 G6 x0 `& v
if (0 == x)) c) y$ J4 j9 }7 a6 C/ r6 d- [- x
blue = 255;
4 b/ c3 P, p0 o$ z$ n2 |% o8 E newRed.Append(red);
" ?$ E: H" D1 K, g2 f( w! O0 @: _ newGreen.Append(green);
6 j0 q2 ]' n- c8 Q. u: N. g# G newBlue.Append (blue);
) L7 Z3 i7 x, R9 _* N5 P cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;. A/ T+ P+ O# h
}
: w# _! M) a$ a) l' f; x5 T' \( J6 g
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
$ M H: U& k3 }2 Q- B+ d/ q if (E_FAIL == rc)
! x9 S* ~! W% T' W( j }) c: N {9 S( N- Q& M; x7 ?2 T% q5 B0 f8 ^
cout<<"Error, setting new color on faces failed for all faces"<<endl;0 ~& n- a1 t5 G" \0 |
return 1;
( Y$ _* S( i8 l+ ]7 |/ q }
7 g" n0 ]; E8 ?) v/ W9 X2 G2 E else if (S_FALSE == rc )" l1 I0 `- x. K7 j0 x9 l
{
( j) c2 K" Y& `% t% [2 y( B int nberrors = FailedIndex.Size();# Q/ Y, M' f! t6 ?3 i
cout<<"Error, setting new color on faces fails for faces :";
0 |1 G% Y0 g' o" M- T for (compt = 1;compt<= FailedIndex.Size(); compt++)8 `6 m2 A* ~4 @
{8 B W/ e+ ]6 z& l
cout<<" "<<FailedIndex[compt];/ v3 h) L1 L8 G7 w" z
}; b2 H( t% ^3 `; U! I, e$ [( A
cout<<endl;
0 u; E4 W" C8 T d @7 u }- t# _. y F8 d' s6 i: n
else 9 K! q T! H4 h
cout<<"Colors successfully set on every faces"<<endl;1 ]: l3 Z) R# u5 |
//
8 u' l/ }! c! x4 y2 ?5 D- q; n //9 - retrieving colors we have just set
+ I6 U j! J3 a //
: h3 z4 _7 F9 T! e- e cout<<"--------------------------"<<endl;3 H$ L6 ~$ c$ |1 Q, R4 n
cout<<"Retrieving new colors"<<endl;
( \' _0 l0 x5 N" I- n( o8 E rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);- e' D6 O& m2 f ?! ^) }+ u' r
if (E_FAIL == rc )
0 ~! V2 }( c' }$ g: B% n! t {( u4 X% W- `( B/ l0 X6 z$ C# t
cout<<"Error, an error occured while retrieving current part colors"<<endl;; f- ~4 _. e9 q* ]
return 1;7 Z3 S( S8 w. ]( {* }
}9 r) f& i1 V5 ?0 L! G
+ C0 c' N8 O7 Y3 h
for (compt =1;compt<=nbfaces;compt++)' x; r3 ~6 h# v
{
2 @& I: f3 l d2 \/ c- N1 ?* r, t( o: R, x cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;# q+ l- _8 U9 i0 ?+ d8 S
}1 F4 H* G' L+ x& D2 n$ A& B; X
& r) T) h$ V9 @8 K$ [& _: M( u6 F //5 t( ~1 v- Q; m
//10 - Setting Applicative Attributes0 b- s, \( g' b/ T( \) m) s- Y& f# g
/// [6 D; N" |5 T0 {6 ~% Z% I
+ a8 }+ p& c, x7 ]0 u9 l0 \
//
d* `9 D0 ^0 I* @ //10 - 1 creating new attributes x4 e1 @. K; M8 V% [& W: O9 g
cout<<"--------------------------"<<endl;
% x* R4 v$ M: v' N' W" f: f7 X' g+ H cout<<"Creating applicative attributes for different faces"<<endl;
/ G" H* q3 T* Y, r$ m CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
7 o0 g! w; ~5 p; C5 N% a: J CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];" ?8 }/ c( u6 C
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();6 J4 I+ w8 p, E, V! f
for (compt = 1;compt<= nbfaces;compt++)) i! a/ S2 K- S' ]+ ~) A- Z0 |
{
j o0 L) Q6 `! V. J1 G6 L$ o cout<<"Creating ";
$ g. g( y) F4 Y) D; O/ F2 m x = compt%3;: N" ~% q, Q$ n; P* E. K) S
//for each face we create a new list of apllicative attributes
- E1 O5 L7 C! ?$ c //an applicative attribute is made of a Name and a value
6 [6 i' X h# k% B% z/ }( y% c if (1 == x)$ R2 A- h2 L- y7 v( W7 Q
{
`! L! }3 W4 F AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
- [) c( @* j- L! L# ]1 p AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
8 u% v9 r, c0 j Y) Z" K9 Y6 G2 w y- }4 \) {! A1 ~8 ~0 C
//The first attribute will be the number of the face w( l3 K) F0 t8 h- L
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");+ k4 B9 y+ [3 B
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
, j9 H( f b' U Q- M- \$ O AttrValueListToSet[compt-1]->Append(tempcke1);4 Q2 e7 S; V& A- s
+ Z2 _* Q ?6 @2 m
cout<<" FACE_NUMBER with value "<<compt; & J$ g; W8 O3 b# r1 F
; i* R. [- H" ` X //the second will be the color6 F; [6 w& v' |, {& @) }" }
AttrNameListToSet [compt-1]->Append("COLOR");1 ?7 L. g; S1 ?" X) i! l( g
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
1 o, p, o+ z! _, W. S1 W# b AttrValueListToSet[compt-1]->Append(tempcke2);
7 }- {' o& o. v. V: ^ / K/ R8 p$ l* Q) V7 @# A) k
cout<<" COLOR with value Red";$ |, n, g% G/ Z" ?4 ]
# F5 A, [' h& k6 m; k: Y- S3 f
//the third is x
0 Z) ]4 {$ H! K. c. t" H AttrNameListToSet [compt-1]->Append("X");; N2 t% E* ?% `: w
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
) h, V& G n7 a/ u) Q6 `) s8 u( \9 q AttrValueListToSet[compt-1]->Append(tempcke3);/ K; l) d2 e7 f. f
: r& N C! ?2 p7 P! i cout<<" X with value "<<x;
2 l1 u: }1 B/ I4 L* i' A B. t6 i cout<<" for face nb "<<compt<<endl;
. j, I* m! X8 B5 q, _/ k1 ~, H }
5 ?$ N, B* w( z: N9 Y: S else
! u- u( ` Z; b$ ^. F5 Y //just to show you you can have different size of list
( r. d6 z9 c# r- B/ b {0 B* U" c/ |9 i8 g+ O3 \' n6 ?' A
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);4 X' d+ p/ \1 d; U( P% p
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
1 `0 ?% O% l/ _+ x, L
. k" h( o$ L3 v! Y- j; R, R" B //The first attribute will be the number of the face
% f) ]$ e# \/ E) A AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
( E) _+ F) y& L! H% e# t4 ? CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
4 C$ T7 Y( T& i7 x) l5 Z) u AttrValueListToSet[compt-1]->Append(tempcke1);
" t( i4 n( f" Q
: u, `6 \1 ~$ \8 V/ J cout<<" FACE_NUMBER with value "<<compt;
$ Q4 c& Y! R( m, N0 E. h0 l6 Z$ d, F7 r8 m; T
//the second will be the color
% ~! i8 v, D" f8 r AttrNameListToSet [compt-1]->Append("COLOR");1 s+ Q o( @! G
if (2 == x)
l3 r6 J& I& Q {
* |" \( Z8 ^: J% ?! ~8 b CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
. t+ P* I8 S4 ]- N E AttrValueListToSet[compt-1]->Append(tempcke2);; W- J, y7 \7 a& E
# M, C/ i! l8 s' G [9 _
cout<<" COLOR with value Green";' u9 ^8 w+ X" V" }
}9 Z! [; V& ^7 T* ?4 T
if (0 == x)
. E- x- ?4 K; Q {
7 w. @3 c1 A2 f- W CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
8 X% }3 b4 Q, k4 Z0 G AttrValueListToSet[compt-1]->Append(tempcke2);
8 E) u) ]8 C* y) {+ q
* c- W/ P z. _. K* H) I' A5 e cout<<" COLOR with value Blue";) Z x3 X0 u, m; G+ T$ I
}
: X* f( G* s( V# T% G% b" I. r, H; C. m8 E+ h* c2 r( j8 L$ D
cout<<" on face nb "<<compt<<endl;
# E d7 p- M5 T8 G9 n6 M
6 [1 @2 ]% v5 J: z- W8 F' w }$ B- m( E4 S5 l2 ^; C) x
}& L! V' U4 E5 A9 \/ e
, P3 ^5 r2 V% s
//10 - 2 Setting the applicative attributes
1 A* b# p& ?. b8 y d8 ~; H" \ cout<<endl<<"Setting applicative attributes on different faces"<<endl;
9 Z' j/ E1 y5 H. |" b FailedIndex.RemoveAll();
, ~& b. X" @% S; W3 Y( S( D0 w& n rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
$ w' b! ~/ n2 O) X4 G. \+ N1 U7 }4 } if (E_FAIL == rc): F6 _7 V& @0 e' A5 i$ F# a$ A; W* A
{
, q8 x8 S/ \' m" X! K' ] cout<<"Error, we failed to set applicative attributes on all faces"<<endl;1 m6 N- o% q* j. {
}
" J3 X1 ]) x0 g, l* _2 V else if (S_FALSE == rc)
, k1 M$ j9 b$ {$ ?9 ?/ G. J% z {
' g8 A+ u2 G: N% k2 ` int nberrors = FailedIndex.Size();
. S1 p; C8 b9 q% F cout<<"Error, setting applicative attriutes on faces fails for faces :";6 Y) ]+ q2 R* z& Z
for (compt = 1;compt<= FailedIndex.Size(); compt++)
7 W7 M5 F7 N8 u) y0 w; A- V5 b0 C' C {
) e# {5 V5 M5 I' W cout<<" "<<FailedIndex[compt];
, l4 V/ E D& I8 _ }
, g6 I ?. D% l- w9 Z- d4 N9 k& H cout<<endl;
% F6 s- f: f: o8 s' W }6 C5 _4 B2 y( ~$ [
else; P8 b* {3 X, D4 ^9 J
{
6 L n' p% T% j; T& |3 G cout<<"Applicative attributes successfully set"<<endl;: X$ O1 F0 o$ y8 c3 B: v
}) y+ L1 i* B" ]& ?! v: @6 a
+ t& x' w6 s- f7 j2 ?
//10 - 3 cleaning5 L- q$ y( h' o
for (compt=1; compt<=nbfaces;compt++)* F; U9 _+ e; S- q6 ?3 j- P: I
{0 M2 A" V' m0 J M0 I
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
2 [' H9 p" K- q2 U9 ~% R2 e3 z# o AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;+ l5 B7 Z$ s8 S X
}* M2 l( M* q/ d) W: k
. v3 _( R- A, H* F" Y- E# ]" ~
delete [] AttrNameListToSet; AttrNameListToSet = NULL;- E' w* b5 d/ G9 n. G: C- A
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
9 f) Z$ {# }7 B; W8 [6 _" P' M0 m3 q
//
; L. r$ h* [' U //11 - Retrieving the applicative attributes we have just set
) K* I2 z# |/ v4 \5 {& B //
- y/ C9 S" J# F N$ |+ v cout<<"--------------------------"<<endl;
; E1 F. Y! U" U* f cout<<"Getting applicative attributes on faces"<<endl;
: N% j( ]( k; Z' _. p //$ i6 b( F9 h8 ~0 T2 \- [1 ~
//11 - 1 Getting attributes1 ^: V; x) ^$ A1 d4 W6 U
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
3 w. i4 G& a9 G5 `( ~ CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];6 x4 b; L( E# _! ?
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
X" Y( R/ t& x R3 o B if (SUCCEEDED(rc))
$ ^# t7 K% ~ _0 w {
6 |4 _5 L9 N( v0 m CATListOfCATUnicodeString templiststring;2 e( A/ \$ I6 ?( F, t
CATListValCATBaseUnknown_var tempCke;
4 B0 F% ^* L1 V! w3 O for (compt=1;compt<=nbfaces;compt++)- Z$ F- e+ [( c! Y% [: ~; @ Q
{( o: O% S; I. d
//retrieve a list a position k (arrays start at position zero).3 d( g; x+ O% p8 d: H9 B
templiststring = (AttributNameList)[compt-1];/ \4 f S1 {' }: M
tempCke = (AttrValList)[compt-1];, q6 m( V5 k* y5 P8 l. W2 j
% \* s! ^( B4 b! _+ T6 w1 @. I
int nbAttributes = templiststring.Size();
* u: o& n: g6 P- `/ p+ V9 N& {: } int nbValues = tempCke.Size();5 R2 L- E1 z8 U
8 V) W5 P" v% { //the list must have the same size! If not, we jump to the next face
# \+ U: D }# C3 i$ g if (nbAttributes != nbValues)
% l* W) z) m* b# }2 z {& o7 h5 [+ Y4 {; \
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
" m" n' w, ^8 t+ i( @9 b! g% m: a continue;) Q9 w; \2 e& S# s$ @1 T% L& D7 E
}; n/ ?7 e0 W8 D" S; O( b
else% w' L4 N2 t% I: i) W8 q4 O7 J' C
{
9 J, l+ ]0 y& ~7 P5 x cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
$ A. G! X' ]8 [- J }
; E% u$ P' v6 F! j7 {% g9 f for (int i=1;i<=nbAttributes;i++)
1 {+ X. q7 y7 P% }: I& K; L {, P+ y. G$ U$ B+ e* o. h
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;% A0 ?0 g" p$ l9 R! t V- |
}3 ]* `/ G8 U# K% T/ [
templiststring.RemoveAll();# H/ h6 k3 W( ~& t
tempCke.RemoveAll();* P) i: l) N$ J. G6 b/ N( H3 x- {+ q
$ i1 Q3 e* E5 Q4 @8 y
}3 r7 Q4 K. x* B% n1 I! |
}
7 ~/ X `6 w: k( p0 R4 a else if (E_FAIL == rc)
+ s" e* E1 J: _+ b {7 L8 G: v- ~+ n' ]
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;4 \1 [7 [# ]* q, O" K
return 1;+ N) h( {9 q6 g! W
}
# O o7 S7 u- D, | //- W6 c2 e+ A( y: O
//11 - 2 Cleaning List:) l6 g9 N7 Y) z8 _( ]5 {
int i = 0;
' U' n4 D. H: h1 a( s for (i=0; i < nbfaces;i++)- `5 i% p. w! X
{% G! {' l% G6 n0 A
AttributNameList.RemoveAll();9 b- z: z( L3 s |! g6 p3 [
AttrValList.RemoveAll();
( J: n8 p; }' o X) F }
4 w3 L- d+ I9 b3 Q% Y delete [] AttributNameList; AttributNameList = NULL;: t8 h/ j9 S2 y: B+ ~' T9 R
delete [] AttrValList; AttrValList = NULL;
" I7 A$ `5 z# Y$ T1 g! E: o2 b/ K r; p; [( c0 |% Z0 U' P: o
for (i = 1;i<= nbfaces;i++)! ~4 s3 d: K+ l2 _
{
: O* l: e2 Y; W* M8 ]/ L( D7 U Brep = ListBreps ; [1 U- }4 M! E6 s
if (NULL != Brep)! H& [! Z0 ~; N
{
! o' ~0 ^; o8 x8 H& U9 t Brep->Release();
$ e7 @2 S d+ }& H8 e }. T% |% `9 k& W+ N
}
) w) \. E( t% B5 `1 \- G8 Q! y ListBreps.RemoveAll();[/mw_shl_code]' r8 W, k* h" `5 W
|
|