|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
2 x4 H3 y3 N: J5 T# T7 e //! x$ O3 S; U/ y# O$ D" K% N" e
//7 - retrieving and displaying current faces colors. }; ]: p% U5 A3 f* O4 I& L
//
, o$ K1 }# ~. ? cout<<"--------------------------"<<endl;. G% P: ^) ?$ `5 E. H5 N! P6 B' n* s
cout<<"Retrieving current colors"<<endl;8 `$ b) L5 X% o- R
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;4 y% s8 M0 E# A! \
* [: K2 P; f+ D. z! v. W |
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
* }$ n% q/ N" K* \2 F if (E_FAIL == rc )
( J2 U( g; s3 m {+ f3 o1 T2 k1 \$ v
cout<<"Error, an error occured while retrieving current part colors"<<endl; L+ j- o: z4 Q7 R% H5 f
return 1;
1 \" y% b# H0 E- M( f }
: g" S f9 p' T+ k( J" h+ a" m
. N3 z7 v6 C! Y6 W" w* S' [: n for (compt =1;compt<=nbfaces;compt++)
0 x+ \4 V+ Y2 |# V' I( o {
E0 b6 L$ `* o" g7 ] cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;2 O( r1 a1 R# q( ~ l. Y
}
+ U* I D/ u3 o! Z# b2 x! B/ D7 N; p4 _9 u8 g& a* m' g3 B+ ~
/// R& H& V$ \/ d4 |, n; e- @- ^2 c
//8 - Setting a new Color on all faces
- A" j# l; q* ]5 a% k: o' ]7 [ //
! W9 C, y* U) M' k# w
& O Q9 \! ^0 P: K3 t2 O //we are to color the faces with different color according their position : three by three will have the same color
4 h- j2 Q# M3 h5 W. P cout<<"--------------------------"<<endl;: b( l+ I3 \/ n+ {- w/ j Z& L" A
cout<<"Setting new colors"<<endl;
3 V# @2 {% V* n& L- ^; d' S
7 ^/ i5 _( H D4 e7 V* ] CATListOfInt newRed,newGreen,newBlue,FailedIndex;* ~ P0 a9 L' j% @9 K
int x=0;3 f& R+ A" ]0 \
for (compt = 1;compt<= nbfaces;compt++)
* A# U+ [8 e+ b0 Y v {
; ?; c2 K5 X) F/ A6 W) i) k& f) M x = compt%3;( ?% q9 m8 d' [1 v; ]- u
int red(0),green(0),blue(0);4 W2 e7 C! f4 y% i& K/ e/ w# C8 |
if (1 == x)
, \4 w+ Z. S; S red = 255;
8 o. w4 G* Z- P4 ~4 } if (2 == x)
3 n9 g5 N# O* W( m! Q green = 255;
/ _4 N( d( {; ]4 i9 z H if (0 == x)
' u" b% E. v: ^% [, ~ M5 s; g blue = 255;/ m& q% O5 [* T! d- I9 Q2 P4 \
newRed.Append(red);) t& k# L9 g9 X( o( Y& P* |( u
newGreen.Append(green);
) A8 f u6 |& n' Z( [( s3 B c newBlue.Append (blue);
' w4 I( r/ V% K4 y cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
! J4 c1 @0 \/ O& J }% M5 q5 s2 ^* |& |9 t# K
2 ~1 E3 S N- r3 l: S rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);: i7 w& b, Z1 J
if (E_FAIL == rc)& Q/ n* p. K4 }3 @( n) h! q
{
' S* x' l- B# g, v' t cout<<"Error, setting new color on faces failed for all faces"<<endl;& J5 ]- D7 L5 v3 ~
return 1;
4 O. V6 Q3 c% A3 E0 R4 a% F) X- Q }: n. q- u; x* I0 V8 E/ V
else if (S_FALSE == rc )* q- Q3 b' F/ s# _* g
{
3 H J& a& x& J) @ int nberrors = FailedIndex.Size();# J3 W7 i7 h( T3 |6 Y8 z% _
cout<<"Error, setting new color on faces fails for faces :";
) Q. X ], T0 }/ E for (compt = 1;compt<= FailedIndex.Size(); compt++)! ?5 r# V, t& Y, ~3 f: ~+ l; p
{
* ^5 _; E9 X g! }) O; _3 B" Q cout<<" "<<FailedIndex[compt];
' E+ S) d; ?3 t5 l2 j1 q }* E6 V9 y8 U; A5 A
cout<<endl;
/ ]3 Z& h% ^0 X6 U; @% H) C1 ~ }
" @# i1 ^: j$ B# f. U! S4 X else 4 k6 {4 G3 T5 x# e @ W" m
cout<<"Colors successfully set on every faces"<<endl;+ W2 |6 ~* q. l9 p2 Y# m5 W( j
//
* _, u/ z9 X% [ N //9 - retrieving colors we have just set' D( l8 m9 u2 D' ^; h
//
9 |8 e2 R3 B# y/ A j; q9 @ cout<<"--------------------------"<<endl;. ?/ C9 y" L3 Z% I' i: B, K9 {& g- Y
cout<<"Retrieving new colors"<<endl;2 T- z- k5 L: q9 u7 m
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);( s* n& L% T5 n5 Z9 ~7 N
if (E_FAIL == rc )% y: `4 B" d7 t5 S) d! D( D% i! ~
{
9 c: b! f! l3 Z) w cout<<"Error, an error occured while retrieving current part colors"<<endl;
9 s; t6 h/ r5 F# R/ X Q2 w return 1;4 k& e6 g1 `* h9 ?0 V2 ?
}
6 i# l/ H+ @$ G R/ n& q* b) s0 C! P) P
for (compt =1;compt<=nbfaces;compt++); Z9 b- y# p3 _. e' D- ~& f" S
{
) l0 Y. N9 `$ k6 f cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
6 M3 A5 b6 D! g0 u4 a) G$ n }
( n- o+ E/ V) ~. K/ E4 J$ u8 d$ \- }2 [
//6 ?% e- f' f, j% u0 S
//10 - Setting Applicative Attributes3 a, i7 |7 z! ~5 Z0 p
//
" i/ c& F5 b' g6 u
5 e8 n7 N3 L" e9 o //# h; ?$ A8 h' i+ S" m! V
//10 - 1 creating new attributes
% x( h* ?& y" V cout<<"--------------------------"<<endl;! t! e5 }. V6 I$ ~. i7 T* M* m
cout<<"Creating applicative attributes for different faces"<<endl;
& s3 R- N& C4 t* ~0 y; ]3 \% {9 i7 F CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
! {/ m4 B1 X- {$ C" b q% } CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];& u8 d$ ~- L; R
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();$ c( |" Y: Y+ c& v& e7 H( o
for (compt = 1;compt<= nbfaces;compt++)$ `/ S. O4 Y! G u# c
{
0 `0 S) Z6 d1 _9 F+ { cout<<"Creating ";& [% k/ G& f& N/ E
x = compt%3;& g4 A2 P- y: j* |/ K; j4 o
//for each face we create a new list of apllicative attributes7 U% t% K9 D" F
//an applicative attribute is made of a Name and a value8 S% l# Q0 q, B: @0 z
if (1 == x)
& t. X9 k/ K8 `9 l( G5 I {0 e) d% G4 s. ?& S: F
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
' } |6 ]& u0 m1 u AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
+ |2 W0 d5 ], @8 h: S0 Q. N) r$ ~8 G3 J0 I5 z0 W, f3 }# N
//The first attribute will be the number of the face
) `. E; _6 @! ?0 r5 [2 q8 j AttrNameListToSet [compt-1]->Append("FACE_NUMBER");( f/ V9 P' U& Y# k
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
' G7 `3 i- u |" w. t AttrValueListToSet[compt-1]->Append(tempcke1);
+ `- ~: m0 E' C/ W
7 {8 H" Y1 K1 @# u% u/ _ cout<<" FACE_NUMBER with value "<<compt; 4 @) \. @; C: B
X9 f! C& [0 a6 |6 @3 T4 B, g. {
//the second will be the color8 T& v1 u, B* n
AttrNameListToSet [compt-1]->Append("COLOR");
; n' D% F J2 C7 q1 V CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
* I4 Y" U3 k( F2 a7 ~( H0 [8 w AttrValueListToSet[compt-1]->Append(tempcke2);
/ M3 b" d: P( K! E4 e% y- B
; p' t0 I& x. X1 A cout<<" COLOR with value Red";7 \6 a: {2 R7 c: U3 a
3 n2 N: T# L! M8 e1 U) B2 E //the third is x
/ J6 V! m0 K9 |* s3 L AttrNameListToSet [compt-1]->Append("X");* r3 p9 v% o$ i* M
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
2 |+ Q! g8 o4 m2 M& u; g7 r AttrValueListToSet[compt-1]->Append(tempcke3);
) Q8 x. t; D! k& {( w/ ]( _
, e# T; y" d" R" s: | _ cout<<" X with value "<<x;2 J: u1 }; i, X7 t( w
cout<<" for face nb "<<compt<<endl;" |3 `$ r4 Q( {+ z {
}
1 F' l5 o) o! Q W8 ^ else
& a4 ~( B! T$ O //just to show you you can have different size of list! J: r" ?2 ?! a6 k3 @/ B
{
$ }6 [8 w, g0 G9 D AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
( h! p: \5 y! \8 K AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);) M' j0 x% d6 n9 z
0 b- F2 D2 {' F, _% A //The first attribute will be the number of the face( N! O4 S6 w- ~: J$ G6 Z
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
- g1 K' l: c$ V0 U# a8 d. O$ ] CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);1 S( v) \; \$ E' \6 i" G1 @
AttrValueListToSet[compt-1]->Append(tempcke1);
9 z7 i. W: F9 j/ w& d5 |
" S' N7 s) M$ m! j cout<<" FACE_NUMBER with value "<<compt; ' G- ]+ Z2 b- Y. L& @7 ?3 R# g
4 j8 d: L/ T0 o2 Y9 J //the second will be the color% y/ I* [; O. [( e7 h4 ?# I1 Y' g- z% N
AttrNameListToSet [compt-1]->Append("COLOR");
$ y5 M: p% P0 a# k$ ^$ b) A if (2 == x)
$ _6 _' t; U$ |2 F+ z! G {
/ _, z$ c" y' j* t% ^. ~ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
3 F; `( V) G& o( _( B9 w AttrValueListToSet[compt-1]->Append(tempcke2);, k% j$ [$ a1 r5 c: j7 u& U1 y$ z
; ]# \# x L0 r( o/ q* V cout<<" COLOR with value Green";; U% }3 i: b( s1 d4 c1 y
}- L) y- x4 _+ Y M' o
if (0 == x)
9 r4 u; q& @0 F- _; H; T0 a9 w {
9 D7 [7 v) I. Z- W- v CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");( h+ x5 ?' c, a* @0 }' n
AttrValueListToSet[compt-1]->Append(tempcke2);+ D- W; I9 b! p5 K, N
& ] j- E: i! z cout<<" COLOR with value Blue";
7 X& [* V' ]% R6 @4 c# g1 C# _ }
1 z, z6 B) @$ _" g0 U, B# e, U" j3 z5 i9 P5 ^
cout<<" on face nb "<<compt<<endl;
, i/ h9 d0 Z$ l j/ {0 l/ I7 z4 X" C' |4 e4 i+ H0 I
}% M/ n* W: {0 u' u- R4 p
}
4 Y3 s. g7 G+ `7 t; z" S" n
8 O5 ~/ _7 u6 {# _+ W5 o //10 - 2 Setting the applicative attributes
, F: Z, K. F+ u cout<<endl<<"Setting applicative attributes on different faces"<<endl;. |( h7 w3 |# k" o" T
FailedIndex.RemoveAll();, A% X! {& t4 m0 p( B, D6 b% X
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);) |/ B9 A0 q9 H2 N$ Q2 l% @4 m
if (E_FAIL == rc)
2 T# f9 h7 p4 ~( r- ~" O {
1 V/ M$ e8 E) A cout<<"Error, we failed to set applicative attributes on all faces"<<endl;! l, F. e4 }. R+ U! F
}: r* _9 Q/ }" f3 R" S; Y6 E! e
else if (S_FALSE == rc)( V+ G4 R4 D: @1 N* B
{
4 O( T9 p& n5 w/ T2 T, h# o& z) v int nberrors = FailedIndex.Size();
/ R. c, R9 L) y, l8 S$ u4 B& S* f cout<<"Error, setting applicative attriutes on faces fails for faces :";
/ x) h2 O) j0 T, r0 t7 @ t for (compt = 1;compt<= FailedIndex.Size(); compt++)
3 K. \5 _2 D& U: |8 Q {9 J. Z, ]( s5 X
cout<<" "<<FailedIndex[compt];
3 e4 n+ r5 \% @+ b" Y }
$ h: R+ h! E1 }2 G9 B9 d, B9 J cout<<endl; `+ {* a2 r6 {
}; F7 s# {& s, [" s7 a9 h+ p7 g
else: a# @+ _4 Q) c& X
{
, P- l! ^# H; e cout<<"Applicative attributes successfully set"<<endl;
G. K3 x* j n A, i }. d" |$ M* a; u- D9 g
. j9 c8 U' r$ j0 J+ i; r
//10 - 3 cleaning3 {/ z3 J- Z6 G
for (compt=1; compt<=nbfaces;compt++)
8 S1 m7 v; X/ K) A0 m, ]1 |% m {+ \) V2 f' i+ z3 t
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;; l% e8 |" |; N& C) }) K/ J
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;# A$ C7 c, Z S3 R" |
}
! F2 s: m0 B' A
% ]% i+ C3 L+ |1 { e T4 X delete [] AttrNameListToSet; AttrNameListToSet = NULL;1 M, d+ ^3 ?) e6 t" G
delete [] AttrValueListToSet;AttrValueListToSet = NULL;" v3 v# R0 k, p# r& j
. I0 k9 T! n" u* P8 a# y //0 l) h4 V+ C+ F4 F8 [- a0 N8 \8 q2 d
//11 - Retrieving the applicative attributes we have just set% U( v1 Y8 o# C1 z, }
//( \5 o9 u. ~% d3 Y/ Y9 t7 W% e
cout<<"--------------------------"<<endl;; _1 t+ t4 y6 f$ E; }8 L1 G; v3 Z
cout<<"Getting applicative attributes on faces"<<endl;+ f6 X: V) e( w0 R9 B
//
7 x* w, P! u0 O //11 - 1 Getting attributes
% W2 L1 o2 b2 O5 Q2 S$ h6 y CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
+ o- h% ?9 @. K8 z. Y8 u, i+ g CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];6 e, h# I: c ?
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
) n% Z" h( P7 A! D* E, r& `6 } if (SUCCEEDED(rc))& h" ^! M x0 s
{! |7 X7 X8 V) w9 z! Y* r! |
CATListOfCATUnicodeString templiststring;
# r- Z0 s- c4 B7 I3 b0 j: t CATListValCATBaseUnknown_var tempCke;( E- A# {* J6 O t5 U
for (compt=1;compt<=nbfaces;compt++)
8 @8 C: ?7 w* c# x1 e$ d) O {
" D5 S: I, F/ Q+ t; t6 E //retrieve a list a position k (arrays start at position zero).% ?4 }& L2 u. g2 i- ] f
templiststring = (AttributNameList)[compt-1];
4 O/ K4 o" v: @& M8 U& L tempCke = (AttrValList)[compt-1];
% k/ [& B; v* r) j! o. J0 P% h1 I W8 i! A/ A- W& Z4 o
int nbAttributes = templiststring.Size();
, u! E; ^. ~1 Z& a$ I# } int nbValues = tempCke.Size();
4 V! B/ W v2 T* N6 A# d
`& }% ?* @) t3 V& I2 u5 V8 V, w //the list must have the same size! If not, we jump to the next face
& [" |; Q# u2 I7 F2 l3 e! j8 k6 R if (nbAttributes != nbValues)
" ^2 R* F+ x i* { b( I! [ {
# ?) z' S" i! D# O9 u! ~ E2 k cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
3 K1 V! v4 K8 o k& @% G: h continue;
1 |8 m% y3 t* w3 E }
, `6 k- s0 T# P( X; u( Y" P4 Z else3 q, z7 A" ^# D" p3 j0 n( C8 m# U
{% q3 ?5 }1 W8 ~( R% C! T7 P, o
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;4 X; r9 y! x4 _5 j+ Y0 B+ Y2 A
}4 A9 H; v1 @ P; a
for (int i=1;i<=nbAttributes;i++)* l8 R! \: J" G; c; ^
{: R* N4 v% @, y5 [8 F
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
2 _3 u. G- W& V( d g6 X& R, i/ O }
, d) l/ w! }, @ templiststring.RemoveAll();
m' I% W1 C3 P; E tempCke.RemoveAll();2 _2 U5 i* ?* j6 ~
; R4 k! s7 g* L; ]: D2 k }
8 |' U" z& ]9 M3 m }
% g3 w$ \. d1 W5 ]% M3 S else if (E_FAIL == rc)
( V* N: D H7 e+ z2 H P2 ^ {( A, _6 d' j1 u( S q7 x9 n z+ E
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;( b. Q' R+ u/ Z7 j- @ f
return 1;
) G Q2 I9 z8 p8 g' Q7 ~ }! v: o9 _+ s# v7 d
//
3 S) A& o% |( D5 w/ T' ~% j //11 - 2 Cleaning List:
6 N% s4 X, X1 h% z int i = 0;8 N. J' m% M7 M$ \: ]9 M! h# O
for (i=0; i < nbfaces;i++)
6 x8 R2 u3 U7 e1 N5 z/ n, G {
" \; c! @" `: n8 D$ W/ d* u% Z AttributNameList.RemoveAll();
8 y* m l6 v8 S AttrValList.RemoveAll();8 D8 q+ b0 W) F; l) W1 r8 o: N" h
}4 T) [# M# g% h4 w
delete [] AttributNameList; AttributNameList = NULL;
6 z) I2 p# O1 { delete [] AttrValList; AttrValList = NULL;
4 M' K. x( }2 X% H( O3 M' a) g2 b7 i
, F* q5 Z# d# v for (i = 1;i<= nbfaces;i++)
0 T7 l; H0 x% s5 n {
/ a) @* t9 Q \) ^) A Brep = ListBreps ;9 `$ t) Q2 o' j* d9 Q
if (NULL != Brep)6 B1 F7 `' H1 f& F7 x) I
{; T0 d$ Q w/ G7 m4 V
Brep->Release();
`! Z4 |% [8 ?% y3 Y }
L6 C. e4 i2 C/ V. h }3 C# ?, h: |- K
ListBreps.RemoveAll();[/mw_shl_code]! C8 o. }) Y" ?( p I
|
|