|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
5 G# d# K$ l) S0 T. W //
& p+ h8 e& c+ k$ F //7 - retrieving and displaying current faces colors
5 b& o; n' _" N: l( V //' U( B/ }8 h4 o# B1 h- G& k4 o
cout<<"--------------------------"<<endl;
. g8 H# ~8 S+ o6 w9 j cout<<"Retrieving current colors"<<endl;
3 \2 U/ z$ Z: y* ]1 v8 V CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
' z8 W1 l% S2 G; x& h8 ` V
3 ]/ A$ n% R) G) E5 H rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);# G; R) S1 d# ~" `4 c6 S* n
if (E_FAIL == rc )
' v$ j, ?) j9 G3 o {
( S5 R* t( T6 N6 F9 M cout<<"Error, an error occured while retrieving current part colors"<<endl;5 U# D# `% k/ L# u3 f% o' o/ v
return 1;
2 w" h# w5 k7 R$ f" K }
9 Y6 U' O( f5 q! j' Y" F, v3 T0 f7 a4 B# u
for (compt =1;compt<=nbfaces;compt++)
k" Y5 n+ k9 P0 V O' f% R { }, d4 z& y/ t
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
n6 z' h/ r; v% E! M } K8 v, Y6 l4 m8 `, ]" B
7 N& M H6 k" B# }0 L8 T s7 n //$ }! ~9 v) ]9 d4 [/ y: n& B
//8 - Setting a new Color on all faces
, N* u% u# Q+ b5 S0 u, V$ O* | //
5 r* h1 ~; C( B6 }! B) l
5 s: r* v+ ~0 V2 d/ Q //we are to color the faces with different color according their position : three by three will have the same color
* d, p: l2 e3 ^2 O3 q3 U cout<<"--------------------------"<<endl;; ~5 ]# V E9 {( m* L' N9 y
cout<<"Setting new colors"<<endl;6 I! f& `/ G8 _3 P& y! l
: T1 P) a% a; e' [
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
* i, [7 e- @4 |& O/ Q. E d' W6 ?( O( E int x=0;- w3 X; m& w3 W& } Q% a
for (compt = 1;compt<= nbfaces;compt++)( v2 `( Z) W' {/ ]; }
{/ O, `: J- |# @" N1 z7 N/ i
x = compt%3;4 }3 K; O3 p, X+ r! W
int red(0),green(0),blue(0);7 Y: f T5 ?. `. o: `
if (1 == x)/ S% O2 o& L2 Y: \
red = 255;
; B3 ~3 H" B# ], j9 e) P; x if (2 == x)) @- H% R' f; P& B" i' {: {
green = 255;1 M# Q6 \$ `6 i9 i/ m: _1 i2 Y
if (0 == x)6 K4 |3 e% z3 Q8 G
blue = 255;
, I% }# Y! ]+ K newRed.Append(red);
) Q( ?! G) D. s! H4 d3 g newGreen.Append(green);
0 q% G6 L4 s& C8 Z( U% b newBlue.Append (blue);
' N: k2 n- K8 F. s( s1 h! {; ^ cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;/ n9 R+ W4 J( z! c. a
}
V& G: D; D2 l4 f" j7 r9 F, i2 E S: |, u( ]
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
: N Z) N- n2 b, K" {# n7 m if (E_FAIL == rc)
5 S# K1 N: n6 Y8 X {: I" V9 v h/ e& T5 C" {" x3 T, o
cout<<"Error, setting new color on faces failed for all faces"<<endl;$ A5 A) _) m/ |* k
return 1;. K5 S5 _- [$ D9 j) H: c& L
}; M7 q2 N% G0 T. V2 {
else if (S_FALSE == rc )
$ x. e4 L- ?8 R( [' N: ]1 ] B- n- P {; N, ^9 L/ R/ r$ T9 }; u& L8 X( b2 m
int nberrors = FailedIndex.Size();
6 B: Q2 o) ~. q! X j/ D cout<<"Error, setting new color on faces fails for faces :";& I3 n1 x9 S$ s* G& J. z" c. f1 L
for (compt = 1;compt<= FailedIndex.Size(); compt++)
7 E. c) N1 L) I' ~& z p {8 j1 B8 r5 @$ {0 `/ u; B+ e* Y/ R+ H0 F+ N
cout<<" "<<FailedIndex[compt];. y, |6 E& e+ ]6 o S- K, v
}
& w0 d+ W( q6 [ cout<<endl;) K+ b: }4 Z, R8 J& j4 z9 m
}
1 _4 z& c* `9 n! j8 ~2 q else
! u. Q7 N$ b/ H! s5 v cout<<"Colors successfully set on every faces"<<endl;3 K, y% f3 d% n1 n; J6 J* j$ z
//* R# {( Y! Q, d! K
//9 - retrieving colors we have just set, i f0 \/ |3 X* @8 d5 {
//
8 s, U' R0 S5 v3 M. H/ x+ V' N cout<<"--------------------------"<<endl;
^% b) q$ k$ H0 c5 J3 a5 D cout<<"Retrieving new colors"<<endl;" n$ [; r/ f% `5 G$ K X
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
5 X5 i' C- j; C9 E, @ if (E_FAIL == rc )
- ?' a4 J8 `1 Q {
" r/ U% p# ]: I cout<<"Error, an error occured while retrieving current part colors"<<endl;3 j7 U# a& C( A9 T
return 1;
! \0 Y3 Q, R- F$ @8 c/ O$ u }1 y0 C' Z3 P6 i+ k9 r* H
4 Q$ p# B7 F6 S$ Z! ~ for (compt =1;compt<=nbfaces;compt++)5 I7 U6 n7 U% @9 e K* o
{
Q. Y# X5 z5 K cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;* d! r v+ a) ?
}
6 y7 {8 [/ W7 t
6 }+ h0 w7 u. }0 W* F //
+ @) n8 P6 r& ] //10 - Setting Applicative Attributes
) p3 y. |, ^" @6 x //
1 D& k6 q# F f! d( N; u
4 l; d7 b, ~% k' C4 w- f. U //
; e) T% M' q3 c //10 - 1 creating new attributes
2 {, a: Q! U- H+ F cout<<"--------------------------"<<endl;2 V& c8 q. t e+ Y7 i9 z7 U( p1 E" ^/ E
cout<<"Creating applicative attributes for different faces"<<endl;! c6 Y- V( j! R
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
2 R& F6 v+ g* g. W5 ] CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
3 @3 O A* U! P) F& p' |3 z CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();( p/ x+ O3 `8 B: z0 e" d1 g
for (compt = 1;compt<= nbfaces;compt++)$ J5 l" r4 n- l1 Z' a) t$ p
{8 {. r1 q5 @; p f/ }
cout<<"Creating ";
1 A( \5 z0 ^/ y x* f- }! N/ @( k8 I x = compt%3;; e8 { W) v6 Q: o
//for each face we create a new list of apllicative attributes
4 @6 v# T+ p# x" ^6 {8 f T) o: Q //an applicative attribute is made of a Name and a value
+ h& K; R4 |/ p3 W) |5 ]! D. r( d4 m if (1 == x)
' `0 V1 j- v$ ~5 C {$ N; J* H. C w% j1 B& o
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
& A4 H, j% _* O0 O7 B, \9 k# S AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);; Z, ]: Q: k7 y+ l" v b' C
) M- N- d2 q, s! N! w //The first attribute will be the number of the face
6 N/ [; c: ?3 v5 O AttrNameListToSet [compt-1]->Append("FACE_NUMBER");; a/ R2 s; f# I4 k% |0 ?
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
7 e$ m" ^; V* c& z AttrValueListToSet[compt-1]->Append(tempcke1);
+ @! j1 v$ O4 I& z, b: G* q
/ R# N4 u+ j% a5 Z1 H, @3 u cout<<" FACE_NUMBER with value "<<compt; 8 X" U9 ^ Q# `3 ~! [! @" `0 b! S8 R/ G6 |
, }+ c- s1 l- N. M+ Y* H //the second will be the color! j# R% v+ Y1 y# Y: [( ]# n3 P
AttrNameListToSet [compt-1]->Append("COLOR");
4 l7 g, }. E' Y& W; C% V8 [ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
5 ?& ]& h3 k8 h' a% p; w9 n9 | AttrValueListToSet[compt-1]->Append(tempcke2);* T$ R6 u( W$ K; j0 H0 A# {+ r
5 G. l! ]2 g; L) l. |2 f# P
cout<<" COLOR with value Red";. m/ M+ {( Y8 V5 Y( f* v! W
' C/ h. q- e& y: N
//the third is x( j3 U, r+ g- \. G# M* Z4 w/ x
AttrNameListToSet [compt-1]->Append("X");
7 m) s/ p x3 D8 _& q' X: ` CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);, V- A* M, _$ a% l1 N5 h4 ^, g" h
AttrValueListToSet[compt-1]->Append(tempcke3);# A# s" @# t' B7 B$ c2 B, Y8 o
5 v; V( h" r5 y: b# y cout<<" X with value "<<x;: E6 }3 f& r" u' G& \3 O: P
cout<<" for face nb "<<compt<<endl;
6 k6 }/ c1 F: ]- e" i( m0 v }
! m# d" m8 ?* Z- N9 e, m else ; c" ~; K3 @9 Y/ f0 D% S6 h
//just to show you you can have different size of list
7 a8 F5 k( Z6 A* P. b {
. S1 _0 E8 r9 a AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);/ c1 |' N7 l9 W
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
% |- [" T/ V7 W$ H$ O/ e- U
6 ~4 Q( @6 D6 k( E7 Z, w5 N //The first attribute will be the number of the face1 w1 J" K7 S* R
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");" ]. t, N7 Q" H& h% e
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);+ Q* {% d- u Q
AttrValueListToSet[compt-1]->Append(tempcke1);5 r; C% g5 T. U$ Q! L# z
; O0 V* j. ]. x9 @* |
cout<<" FACE_NUMBER with value "<<compt;
" Z, [) s& v, f+ l' T ?6 m( I$ R& x- N' \% L* u
//the second will be the color
, Q, v$ l0 D; z* G AttrNameListToSet [compt-1]->Append("COLOR");/ O l4 L; T3 o+ i% v
if (2 == x)
( ]' Q9 i( U! g2 T" E {
2 s# E1 Z# {& |# \+ X1 y CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");7 L. y+ G1 m5 @# W+ c& K
AttrValueListToSet[compt-1]->Append(tempcke2);
7 h% o' j3 Y: X
& V0 o/ Z' ]9 z7 A cout<<" COLOR with value Green";
( G' m" x/ `) \ }7 k+ P3 Y$ ~; n2 F, x
if (0 == x)
3 p1 o/ ?, A+ P( V0 S. r1 \, x {' p3 `9 }# D( D N# h
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");3 v! Q" V. l* G2 L$ w
AttrValueListToSet[compt-1]->Append(tempcke2);2 {" ^/ V8 j: y% O; W
5 @# q) P% l9 _" X: u# V E
cout<<" COLOR with value Blue";& s8 C1 g5 X, m2 D( e
}
/ z! n: S+ K/ ~5 S7 f1 |5 g3 A( B. D8 @) n
cout<<" on face nb "<<compt<<endl;
$ @3 Z4 P2 r- r2 V( n5 I( u2 p- p. G" k7 q/ E4 T
}8 @9 R: v0 X) a7 ^- a# J; r
}+ \/ {7 r4 I. m! ^
" V* G7 n( D) J- V: s4 f5 K; v$ a //10 - 2 Setting the applicative attributes+ L$ ^$ F2 R$ Q1 `$ w8 A9 u
cout<<endl<<"Setting applicative attributes on different faces"<<endl; x9 i( d# x0 D2 M
FailedIndex.RemoveAll();: G6 p3 e: \. f% d Z
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
- }2 M9 U' T6 x& ]. H if (E_FAIL == rc)
8 Y6 }3 y4 [# j) w {# z7 g1 D$ d* @" V! D4 l
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;: m* d1 }1 h: d8 J( A
}
' X: Y e; M* H ]" V5 U4 V else if (S_FALSE == rc)
- v5 @8 n5 g% e0 r+ n {# \8 Z9 n* ]: d! T
int nberrors = FailedIndex.Size();
" {/ F# U$ E" m9 J; h cout<<"Error, setting applicative attriutes on faces fails for faces :";
t( Z. y0 E4 S4 Q5 O, q, x for (compt = 1;compt<= FailedIndex.Size(); compt++)( _) I2 w9 h0 v2 R& j4 K! E6 d
{$ Q$ F3 `# W6 I
cout<<" "<<FailedIndex[compt];3 O0 z! A! H! w- P7 M$ H9 b' f
}8 H K4 w' e: F) x! Q
cout<<endl;5 L, Z9 o* S# p: h- c `- h
}9 _0 y& v+ K$ X; h8 q. D
else
# h+ g: y8 d: w% x8 [* } {; p9 [/ C$ N" t* u0 W
cout<<"Applicative attributes successfully set"<<endl;
6 `( C. F! Y+ h7 V4 o }' b! D# @( ?0 k! n& X
, a ^ A# W7 l/ A
//10 - 3 cleaning
7 @% a1 k% o) [ for (compt=1; compt<=nbfaces;compt++)8 i0 T( W1 }% O" V8 Z o
{) T$ v3 a, m( C0 ]1 P J( ?5 g
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;' Z; J1 _% b' r' n+ o
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;1 U( w0 e' k& |5 ]7 U# O6 D
}
' S t- x: p/ g$ L, i# J& h' |7 c% O: S! x+ O6 o0 j, ^+ g Y
delete [] AttrNameListToSet; AttrNameListToSet = NULL;! D' C7 q# Z$ Y6 `
delete [] AttrValueListToSet;AttrValueListToSet = NULL;# Z* H4 M' f* e
' t# ~6 [- W5 [
//- |+ g6 c% t: D8 x; y
//11 - Retrieving the applicative attributes we have just set
" G) i) ^( |& l1 y I //
( w6 R @) u( O0 m6 r cout<<"--------------------------"<<endl;
5 i1 q0 M! P2 L2 H: }8 F cout<<"Getting applicative attributes on faces"<<endl;
W. b( w( V- O- n7 x3 X7 m //
/ {' N, S/ w1 T# X //11 - 1 Getting attributes# X ~) c+ Q, S
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];. @* ^/ Y9 `+ D+ d4 {* T# b' `
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];8 p! Z2 Z7 c5 P5 Z6 c1 K
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList ); d' F' s7 E( D- }3 a7 h1 f! n! _
if (SUCCEEDED(rc))% _! ~* C. j& }4 I
{8 c8 w+ C0 x/ b( }4 w" }, }6 }0 X, A! Q
CATListOfCATUnicodeString templiststring;0 ^1 n! X# m! _( d- S U& \
CATListValCATBaseUnknown_var tempCke;% e" L1 t. U. u/ y! ]
for (compt=1;compt<=nbfaces;compt++)
$ V2 {9 k6 Z% f3 t: v6 Z {& U& B7 U) ]3 }$ S
//retrieve a list a position k (arrays start at position zero)." y0 x6 V. h B @. T1 q" L
templiststring = (AttributNameList)[compt-1];, h! `. }* e( ^/ f0 n
tempCke = (AttrValList)[compt-1];3 ?4 k t. ?% ^/ } C
# ?9 G k/ \# O) k- k1 L int nbAttributes = templiststring.Size();
1 N% V$ [1 \4 ]* l7 _+ [6 W' ? int nbValues = tempCke.Size();5 ~, |, |& ~' E6 n+ F) u
5 K2 D' K; Q6 m8 M- K
//the list must have the same size! If not, we jump to the next face# W9 U9 S* f( H4 n: W# p% L, _
if (nbAttributes != nbValues)0 w# X7 D9 h. J& f3 \- K
{7 T* e( B4 X1 I \ o" }; a
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;: L. k6 z# U5 {4 g9 r4 ?: v% g
continue;% y! s. X3 N) [( R _% f0 S$ E
}5 Z" m- W/ @# [5 O
else
* e: k. v+ @) I: O S {) ]: z* _. Z$ c& a% A2 A
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;% B( ~# L% H2 f% J% \
}) P; z& E4 I- v- ]7 D, H
for (int i=1;i<=nbAttributes;i++)
% ]. l) z$ r9 z# { {
8 G( `7 ~8 {1 M cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
& E, v: ]4 K2 [% L }. E! w) v: Y I& e, L) W) [
templiststring.RemoveAll();
# Z% J5 b3 P/ M3 f6 E/ ^$ z0 w tempCke.RemoveAll();
0 [/ q0 [: L; S1 n. X( W P. S6 S+ w
& j7 Y" {; T G4 i# T }! ]1 Z1 n/ t4 F/ H
}
, e; d# t( j v1 A: n else if (E_FAIL == rc)
! |0 d& w: X- A w* x! D6 [ {+ c. U# m& a, x. g7 K: e0 E5 J A
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
9 p7 l' I# A0 ~ return 1;
1 A9 z% F' D n: F* d: j; W( | }8 o1 z" m N0 C4 V1 X0 A
//
8 L9 b* d* S# X0 `' ^ o //11 - 2 Cleaning List:+ g; Q/ F3 D1 f) B3 b
int i = 0;8 A3 y! K9 t: a* Q
for (i=0; i < nbfaces;i++)
( |7 D& t, x. E4 _- @ {0 r% Z( N2 @, `) h: b
AttributNameList.RemoveAll();
, X( s. l9 T. |; ~9 N2 u AttrValList.RemoveAll();+ [5 w. ~$ V, i
}
* H6 x3 w% p* \6 J3 ] delete [] AttributNameList; AttributNameList = NULL;
: o: F4 x2 _* U# w delete [] AttrValList; AttrValList = NULL;( A- j) g% m. Q" i/ t
# X* c: K% w+ k) q8 h. }
for (i = 1;i<= nbfaces;i++)' n* x; Z$ C! x5 \- l% O
{0 |% ^& D- o7 W: j( H3 O& p. S
Brep = ListBreps ;
; S& ^$ V4 B4 X9 F if (NULL != Brep)9 |* W) J7 g/ Z _
{, m& M# W- w! m b$ D% d: }; ^
Brep->Release();$ b: t( E' {/ v. C; l
}; \ N3 _' F: N/ D% @9 C* I z
}, r _ t1 n" Z5 @ D/ A9 i2 o l
ListBreps.RemoveAll();[/mw_shl_code]
, L: E) @* Z5 N0 ~% G |
|