|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]) I; ], n8 X N1 P
//3 u+ S+ @' @ y% F& v. ?
//7 - retrieving and displaying current faces colors+ q. H4 t" a9 x( O/ ?8 I& t2 V
//
2 z( J/ e9 P6 x/ @2 Z cout<<"--------------------------"<<endl;
8 \0 \4 f/ V6 U$ {" { cout<<"Retrieving current colors"<<endl;
7 t6 S g& _! O6 C9 J$ y2 W' _0 X, U CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;% o1 @5 c9 l9 J% I
" i# {; R2 A- C/ `$ d8 s# p
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);, g0 [' |& V4 {+ Q; p) T
if (E_FAIL == rc )
. ~5 [5 X( G) ^* A7 @! C7 Y, Z {
$ Y0 s5 n$ v( x) x cout<<"Error, an error occured while retrieving current part colors"<<endl;
' U9 C9 Z/ s$ `( j( w5 q0 _ return 1;1 l2 C" `* @- R0 Y: ?9 d J
}
5 k# _9 S A, d2 K; J: v) d8 s* L' }$ m* ~9 O# m# n# U
for (compt =1;compt<=nbfaces;compt++)9 _6 c+ [" m# Y7 K
{0 J) H0 V( k9 w9 u' M
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! k: ^) [+ f4 U0 ^, W1 _: @5 ?6 t }- }3 _9 ^# [5 r' @6 a9 ^
3 k6 P J. W# `" y
//5 s$ {0 B1 l9 v9 H4 @9 _" K
//8 - Setting a new Color on all faces
+ r3 L6 H( H4 C& g j' L //
8 ] a' ]! N2 @) N, H4 P3 n# E4 v) O
//we are to color the faces with different color according their position : three by three will have the same color/ b5 L% ` m0 O5 s- i. A6 b. f% l
cout<<"--------------------------"<<endl;8 n' m/ u: s+ O7 E8 @3 @& k" ^2 M. R
cout<<"Setting new colors"<<endl;6 @; t4 f M9 h, R( C# w; T( N$ }
3 z( T- D z1 a: q4 z: A8 t CATListOfInt newRed,newGreen,newBlue,FailedIndex;! m* `# d* ^' x, Z' p5 g, K
int x=0;8 K4 b7 N* w0 `' z4 U
for (compt = 1;compt<= nbfaces;compt++), [: \8 U+ D8 g G% d( B! X
{, N7 m6 q3 {5 y8 \
x = compt%3;
& i* j2 \, X W- B9 B+ o$ l int red(0),green(0),blue(0);
& y" u5 Y# e) x$ g) p) l if (1 == x). g7 t& j, _' c" ^3 E- K1 u
red = 255;( ~4 f7 [7 t$ M/ Q: o0 U0 Y
if (2 == x)* M I# n6 w- |9 v! o0 x
green = 255;
$ j: o' }6 z4 W' e4 B1 ` if (0 == x); q9 \" W* ^; J: i! D3 B$ |
blue = 255;# t/ Q- Z7 d9 s- K9 K. i
newRed.Append(red);
- P6 w' C+ z1 e, n/ c+ C9 E w newGreen.Append(green);
. I! e3 m; r' J% I2 P( P6 O newBlue.Append (blue);- z# g) f. s K5 W; ?1 p8 s9 ~
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl; k3 D: `. e3 P% x, U
}% d ?: c2 }. i; p3 S
2 i" O5 f5 M* A8 L8 X
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
( S$ a5 B+ D$ w! A if (E_FAIL == rc)& i: R$ J- s* c' \) M
{
2 Q1 m$ _2 F: M cout<<"Error, setting new color on faces failed for all faces"<<endl;) c0 o L5 J% i1 d( M& A) [
return 1;5 N0 M& x% T9 \1 ]5 D1 E9 H, E! ?
}$ ~1 f. `% b2 `4 j3 h
else if (S_FALSE == rc )
: q7 N g" V' Z* | {/ b6 W+ T5 _- M% ^
int nberrors = FailedIndex.Size();
# S) V" s# ~1 D) t cout<<"Error, setting new color on faces fails for faces :";" m8 W0 j; s4 |* P# j$ }
for (compt = 1;compt<= FailedIndex.Size(); compt++)0 u# @7 [# y4 a3 `
{
3 e, N7 M% F2 E& {, w) { cout<<" "<<FailedIndex[compt];
; J9 P1 S6 N" O( g: |" E }
6 X1 K# g% b4 B9 {4 v* t cout<<endl;) x( ]6 P( n3 g5 L! [
}
1 p @$ J( s4 B* m else
' {6 C9 o8 i: s2 R cout<<"Colors successfully set on every faces"<<endl;
6 z) m( W& _9 {/ C' G //
& [3 T: Y3 w6 m1 l: _8 } //9 - retrieving colors we have just set
3 V; o$ H; _9 o8 b3 J //1 j' q7 [, ?1 Z" o
cout<<"--------------------------"<<endl;6 q; v% p, B" ?3 f- J! d
cout<<"Retrieving new colors"<<endl;) C* q4 H' s6 p3 `
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
) r5 z' T' @6 Q- ^5 d2 ^. Q if (E_FAIL == rc ). c y$ q; T4 `' v& e9 d0 I2 G4 I
{
3 M+ R4 y, a& A cout<<"Error, an error occured while retrieving current part colors"<<endl;, Q9 f2 e: c5 v0 J
return 1;
$ W4 v# D% l3 n6 Q" k" A3 ?& a& [ }. f2 I. n% Z( d$ H
5 B5 _# Q0 q% E% S5 O for (compt =1;compt<=nbfaces;compt++)- g! X8 k& L2 `4 i
{+ Y$ {; B& c7 ?' H& Q
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;7 k3 i( _4 `: W
}5 p. B- N) r7 Q
0 K: n$ T& z5 ?$ b) K4 ` N
//
& z0 R6 e- X! A ]; T //10 - Setting Applicative Attributes
2 _6 b" I* p# J" J //+ V" M8 j& K/ \
/ {* z. [5 m, `( Z9 S$ ^' U" r //
0 O `- M9 B/ C/ c8 \2 t+ P //10 - 1 creating new attributes
) M/ U( Y9 Q" L' L0 u7 G |+ ~0 w cout<<"--------------------------"<<endl;9 ^3 J) R. j6 B7 E
cout<<"Creating applicative attributes for different faces"<<endl;
7 n1 U& X( l& q! G CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];, N* {( Z& O/ k* t3 J1 b% Y4 c
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
; f9 D3 |- B, p) I# T. L. O5 L# _ CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
. `) _+ a. n( v, c2 \+ f for (compt = 1;compt<= nbfaces;compt++)
3 D/ ?- G2 n% M# r* k9 i# |4 p( E {) \! M( K1 c7 |
cout<<"Creating ";2 n7 }* A" x9 [8 a0 C" I0 U: H
x = compt%3;/ P+ r$ `, o( g j% H. H
//for each face we create a new list of apllicative attributes
- @: J8 L7 ~; |6 i( }* I6 t! \ //an applicative attribute is made of a Name and a value$ D% w4 B% } Q( U( y. ]+ \3 S: T
if (1 == x)+ v/ Q5 l5 F. p) M* I* p/ v
{
1 ^$ ]) h% w5 ~6 u9 S s* u AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);* ?4 k, x# j. _4 Q$ @" T: n
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);- L8 F! w/ t) q# E; \3 }8 A- M/ G
- Z) A- m5 N k6 x0 V
//The first attribute will be the number of the face
, w5 L, P: z% w3 \% f AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
# ~# D- P6 O0 V' C- c2 m; l0 T: Q CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);4 J* P" h4 p- |% N" c; A& R
AttrValueListToSet[compt-1]->Append(tempcke1);
% K: s( B# U* A2 |
- V3 `# U* a2 Q5 p9 k% X cout<<" FACE_NUMBER with value "<<compt; - }$ \' u. e, F: x: N0 n1 o0 B
& u! `+ }6 _: f& P7 a6 Q/ R //the second will be the color
1 Q5 F+ x6 j( W+ ? AttrNameListToSet [compt-1]->Append("COLOR");/ H8 B1 _& C/ U% l2 h; K
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
6 r! N! ^& c' m) u5 z9 F AttrValueListToSet[compt-1]->Append(tempcke2);! |) f; A8 u, ?+ E1 [. c
( l3 J1 r# H+ i+ E1 c' W cout<<" COLOR with value Red";
$ b- i( \; M8 V% \1 C) T0 D 4 z3 b6 z; j( Q, r( ~. V
//the third is x
9 `- v! _1 m" O! r/ W9 S1 F, v AttrNameListToSet [compt-1]->Append("X");
/ m. d, S6 x; A' J CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
5 t# d H1 s2 H+ m5 m9 z AttrValueListToSet[compt-1]->Append(tempcke3);0 p8 y0 e5 M+ y9 x3 v! f$ ~3 m) r
' H8 [ s) N; T) M- |4 R; G cout<<" X with value "<<x;
* r1 p7 h: i3 Y7 }$ U! {( Q cout<<" for face nb "<<compt<<endl;
9 N% U- N0 H# A }! h i N- y d" H$ c! a0 O
else
9 s: R# |& J5 l: t+ S //just to show you you can have different size of list
! i! V$ x5 t" }* o5 \' r {
& `* L8 j* B! G7 n( M. V& U AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
8 F5 K1 O% Q5 ]& S AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
6 `- c' b4 p; T' M7 h9 w1 [+ S+ X$ {1 {% _6 O7 F u6 t; j8 |
//The first attribute will be the number of the face
2 S0 |7 q* \/ Y, f7 h" O' r AttrNameListToSet [compt-1]->Append("FACE_NUMBER");1 m4 B3 x% ^1 y. ~% C( ~
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);# E9 u4 k8 a& h6 u% X, J$ A, R
AttrValueListToSet[compt-1]->Append(tempcke1);6 |9 {% W/ B" V2 i6 h
; F( L4 F+ h" r4 q3 _# ]
cout<<" FACE_NUMBER with value "<<compt;
" U4 }. L M3 `# d2 D7 A0 K0 _% X# Q6 j x
//the second will be the color8 G p; ^ ^$ k2 R o8 p0 h8 o9 C
AttrNameListToSet [compt-1]->Append("COLOR");: K( A" B8 `4 U
if (2 == x)7 d$ c' w! V% r# f
{4 G4 G8 I( Y( b# o0 j, V G
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
% t: s. a9 j0 E* U# _ ~7 q1 @ AttrValueListToSet[compt-1]->Append(tempcke2);' j6 N1 ~( ?" q# I3 ^
$ c! b8 m+ d- L( X: b' H cout<<" COLOR with value Green";4 l0 h8 y. K; k9 p9 N8 @
}* j4 p1 }: n. O1 c& H
if (0 == x)$ S1 x2 K6 I; a& E; w
{, T# E' R1 Q4 N0 g% e
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
1 i, a( L3 |; J r# J0 V5 O AttrValueListToSet[compt-1]->Append(tempcke2);
# `$ P8 M% s5 {, m- z& t9 l 2 r0 z' h- ?' I+ r3 i: y$ l+ c
cout<<" COLOR with value Blue";; u1 u4 T% _* p
}
) h, z: z* L1 W% K& _! D% S8 ~1 s4 j8 D4 k; F
cout<<" on face nb "<<compt<<endl;
2 ~% c4 @8 l& i# H# [0 D+ y0 N* u
; ~7 _; t( `9 O6 O/ [ }
[$ w, _/ }, s; G/ ~+ J: Z' j$ ] }
+ f, M) x. Q% ?( I* r; Q2 s( M8 D( N0 n2 `
//10 - 2 Setting the applicative attributes9 a# _ J4 m; K1 B# s; w
cout<<endl<<"Setting applicative attributes on different faces"<<endl;$ s2 N9 u* |) _9 J% n
FailedIndex.RemoveAll();
% K8 h2 [. j# } ? T- E8 Z/ a rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
# b: [. B% \- G8 l3 t; O4 I, w+ D if (E_FAIL == rc)
$ J3 d5 U( R/ _3 }+ P# f {
) G" B) G. b: V# T cout<<"Error, we failed to set applicative attributes on all faces"<<endl;/ }- j0 e) V' r4 p( x6 H w/ g3 v7 C
}7 w \. f7 d, W# Q$ ?. u% s
else if (S_FALSE == rc)1 Z0 {1 X3 B9 a5 L5 S' @) k* S
{
9 s% g3 K" {9 J! n0 Y' Q int nberrors = FailedIndex.Size();& m4 `0 b+ v/ }. c. i7 H
cout<<"Error, setting applicative attriutes on faces fails for faces :";
8 |* z/ e& X8 q for (compt = 1;compt<= FailedIndex.Size(); compt++)
_, w, d, U) ]; _$ C5 j8 Z0 i/ V { S* h3 F1 X% Z
cout<<" "<<FailedIndex[compt];) E/ s8 B" g% O* s
}. G) \4 ]7 ^; }+ o- g2 H" I
cout<<endl;
4 Z5 {, h$ m5 K2 ~' d }
$ @: ^9 R, Q, @! D8 t+ y# G else
! w7 f0 g; S5 H' [* [8 U3 I; Z {
4 j9 l9 p; n9 W1 J cout<<"Applicative attributes successfully set"<<endl;
" V. k/ e; G: N; d) o, v0 X }
( v* n! H) r. W* z- W; E* T0 G& N( V5 T
. x8 a5 U) `; [, ?, q //10 - 3 cleaning
9 d% b4 T7 j! y, l: Y3 ] for (compt=1; compt<=nbfaces;compt++)
4 S2 [" l" f- X {
; ~" s$ [4 I9 a; x+ z, I w5 O AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;1 j) t' b9 j3 s( `
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
9 W! I; o+ I( g }
+ e# V( y% L. w$ f+ |5 ]( c$ }+ u; Q+ Q) @4 |3 m3 O
delete [] AttrNameListToSet; AttrNameListToSet = NULL;5 o" ~$ d7 v5 ?
delete [] AttrValueListToSet;AttrValueListToSet = NULL;7 B0 ^/ e. E2 Y+ ^8 U
4 W( s1 x7 \) F/ p0 o/ F' n9 ^ //
- H% J9 g! g1 S //11 - Retrieving the applicative attributes we have just set; T0 O' P4 }4 f# H2 L6 x0 r
//7 d& b" g8 E, f" I9 x
cout<<"--------------------------"<<endl;
& g% @6 @, N8 Y2 f g- t9 c+ n, R cout<<"Getting applicative attributes on faces"<<endl;
/ q. u% w/ [" @+ V7 E, D //6 o8 |# Q2 ]$ M' a7 R
//11 - 1 Getting attributes
: O1 Q$ S/ | T, I+ V3 ~ CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];, ], `3 k. w F7 F. i9 o
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
+ i5 G) j5 \0 `+ x" m( F rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );, C+ B" n5 ?+ U+ F% g5 P! `
if (SUCCEEDED(rc))9 A# S- e1 C8 t( ?4 u
{3 J( n( V6 c W
CATListOfCATUnicodeString templiststring;, ~$ Q( v4 Y9 c3 Z5 y
CATListValCATBaseUnknown_var tempCke;
; B6 D1 T8 j+ q2 m for (compt=1;compt<=nbfaces;compt++)$ z* B5 E: v( _
{! y! v- ^. M- N! n& O
//retrieve a list a position k (arrays start at position zero).
* k F' B/ j. V$ s9 I4 @ templiststring = (AttributNameList)[compt-1];
) z6 A# M5 S# L7 G3 E4 c tempCke = (AttrValList)[compt-1];/ g. b( I5 P9 t& h. I
* ] m. C2 Q' p; e; s
int nbAttributes = templiststring.Size();
8 w( G$ I2 i# ~8 B6 M int nbValues = tempCke.Size();8 f7 U; l0 _1 A7 y
- u$ Q2 ~8 w! p$ Z0 y( h //the list must have the same size! If not, we jump to the next face
: D% D# e# O/ A/ w if (nbAttributes != nbValues)
4 |" M* `+ l4 F7 Y- S- P$ l {; k+ B( o$ q! _% I: ~
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
: q) o" e5 m/ l% M6 J- `8 f continue;$ y4 ^3 ?2 Q* H, u/ T9 {
}3 n2 M7 Y u; R7 ~! p! w( T
else) e( ~* p0 n- v9 W$ ?5 a
{! L8 O" q$ s i8 ^
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
& U7 _# m$ X/ |: x3 Z+ q6 u4 e }
% c! g8 ` h" s; z/ ~ for (int i=1;i<=nbAttributes;i++)$ L5 j7 ]" C6 ^$ Z/ o$ H5 F4 I' Q* g, z
{) a" b# P; y8 \+ ^- l; V' p8 U
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;9 D1 X" a3 Q" [# W3 u% R0 S
}+ I6 y, W6 J; z# x5 V4 v
templiststring.RemoveAll();
, H0 q, h: N8 j& S" S/ w tempCke.RemoveAll();9 }2 c3 ^0 R" q
$ T8 D2 |1 W1 v4 v t. S$ T
}! w2 M: j, f/ M+ Y. b k1 j) u
}
6 p. b$ b+ s4 j9 _3 n! j' E: }5 ]8 ` else if (E_FAIL == rc), q# ]+ E! b# Y( P- K
{
1 e8 j2 W- @/ L& N+ B$ t4 q: z cout<<"Error, applicative attributes couldn't be retrieved"<<endl; z4 q0 G5 P5 H
return 1;
* J+ L: r3 F l8 W( p }
+ ^8 V/ V9 Z" D# b y //4 S* ^# }4 T7 c+ P5 ?' l# V1 B
//11 - 2 Cleaning List:: Q1 l! j- Y; | [
int i = 0;) c3 K( a6 R5 I0 Q( ~4 `
for (i=0; i < nbfaces;i++)
+ }) D7 N2 g( ?. V2 ] {
. j! _2 O4 p8 j AttributNameList.RemoveAll();' h6 t3 J8 d, U9 g: k) U
AttrValList.RemoveAll();
5 B( x3 c3 D% b$ n3 ]2 s8 s }- |( }2 y0 X: X8 B
delete [] AttributNameList; AttributNameList = NULL;* j6 Z3 [5 ~% W
delete [] AttrValList; AttrValList = NULL;
' v* \% v4 [) p( T& a! i7 q! M. h5 L
for (i = 1;i<= nbfaces;i++)5 b# A- ~% K( m+ j
{4 y. M% c7 Y( b# A
Brep = ListBreps ;
4 P! f$ f3 g& l' ?! t, o- |2 o0 } if (NULL != Brep)
! P% y: K3 ?8 f H" q) ^ {$ Y5 l& F9 z' T% g; \+ W) n; V
Brep->Release();3 N/ }: n3 G( r% l
} t% p3 x' e) E8 ]/ |0 e. t J
}
' @1 x" @/ V6 L3 \% k" t+ [ ListBreps.RemoveAll();[/mw_shl_code]
# d1 q. x3 M" X. y( K$ ]* u |
|