|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
. k2 s* G) u: _8 {- X" h1 F //9 Y3 e7 p. y! X* B, }" a1 l2 G
//7 - retrieving and displaying current faces colors
& R# K" H- c( s9 ]4 W- w$ L% Z //0 M/ w+ o3 b0 W, x) d
cout<<"--------------------------"<<endl;
3 f; Q! U+ x* @( B( r8 ?6 Q7 y+ [ cout<<"Retrieving current colors"<<endl;% s; f6 U3 ]# M- U
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;. B c) l9 ?) r6 c# n
+ b! b; L- U; z2 A2 _# g( q' e2 E6 |
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
! u- I( h/ K: K5 U+ h if (E_FAIL == rc )( F, g! f$ a7 b2 y' h
{
; w1 U) M4 k* J) V7 p% z cout<<"Error, an error occured while retrieving current part colors"<<endl;
& x1 ^& e( O$ q; h# e/ z return 1;
0 W2 h$ A' H6 h7 Z }
3 f8 `6 d/ {2 j6 d; T
x0 ^$ ]" g* S/ w) p6 _& [4 V for (compt =1;compt<=nbfaces;compt++)/ Y' I5 A# N6 `. z# ]& E: f
{
1 T& \0 t' s$ `6 d2 w cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;+ q$ Q8 j3 M, J; ^3 x9 P
}- l, j/ u& R( B
. V' _* _8 B; T. {( V! B( r
//. @" e, |5 c5 E' f# [, G8 i
//8 - Setting a new Color on all faces2 A( m& }# d7 P4 s4 d% ~
//
' {7 R7 J) O; [7 L( g) w0 L2 _1 E& T$ w4 N
//we are to color the faces with different color according their position : three by three will have the same color% \. i3 }/ C6 K9 N- }, Z9 G
cout<<"--------------------------"<<endl;
. E" P B% I$ t5 ?$ i cout<<"Setting new colors"<<endl;
; \- V8 I/ q [; M% Q1 Q8 X2 S: t ; I" a0 ^# D( A+ ?7 i, t& |8 j7 [* p" f- p
CATListOfInt newRed,newGreen,newBlue,FailedIndex;8 u" V- F( O3 Y4 x
int x=0;" b* Y& B5 Z, z5 s4 i( }
for (compt = 1;compt<= nbfaces;compt++)
! `; |$ e; F. E( a {1 K3 q- { S; p( O# O
x = compt%3;
3 W- G- B6 {- v. {- `" s int red(0),green(0),blue(0);8 O% U) S5 R( Y$ a% u0 A
if (1 == x), m. R1 d- \5 A3 y7 i6 F* d$ y
red = 255; g; d' M* e/ M1 V* [
if (2 == x)$ X$ m1 ~0 g5 Q, B
green = 255;
2 H0 J/ S% W5 W {8 D# H7 a if (0 == x)
6 @4 D3 m8 T/ ?1 @- G# Y blue = 255;0 e7 S+ o5 c+ h" ]/ P
newRed.Append(red);
1 Y9 H7 D2 T2 S* f* x7 ]+ x4 @. d: A newGreen.Append(green);$ }' b5 R! K4 k7 v1 v, T8 w
newBlue.Append (blue);
) B! U# ?4 B q2 Y9 M cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
! }8 |. L i# w1 G+ |; x }
6 O' d1 X& {! y) y W' b+ n. o b) D+ F
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
) D, b% D0 I7 S6 O% t: Q: }" O if (E_FAIL == rc)" Y3 s9 x$ @5 p$ [
{
4 O( ?# v1 l/ f& I$ n cout<<"Error, setting new color on faces failed for all faces"<<endl;, V5 b, X. C! \& _+ q
return 1;
3 p+ C! N5 ?+ K8 O( r* [6 ~ }
& {% L( v! n! b6 W5 I, w else if (S_FALSE == rc )
( M' c. j6 w M( v {" W) J5 k' ~ j- {
int nberrors = FailedIndex.Size();
) |% C% \8 ?, d& O* U$ | cout<<"Error, setting new color on faces fails for faces :";- W2 v; c0 G" I; N5 g5 A4 I
for (compt = 1;compt<= FailedIndex.Size(); compt++)" }/ M% V0 ?7 i+ @2 Q7 T
{% }: y4 \4 `- V! H* N
cout<<" "<<FailedIndex[compt];
4 e- U! I0 V3 J }* |) g s; @, {7 Y, H
cout<<endl;" R; ?" \ o4 J2 v
}
' E. b$ m4 g8 } else
* o+ j! i' ]3 _, { cout<<"Colors successfully set on every faces"<<endl;
" B. c0 e8 C, P) W5 B //; D* t i5 M) R" Q
//9 - retrieving colors we have just set
* A' `$ K8 Q8 ^$ V; Z5 _% i1 r5 z //
3 f& a3 S6 a& I% u1 G cout<<"--------------------------"<<endl;
" k! o' G# K' i l0 m4 ? cout<<"Retrieving new colors"<<endl;# K, L/ \* @+ Y+ N2 t
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);0 s/ `. m2 C+ K c2 V
if (E_FAIL == rc )$ F9 `' j& v$ t) Y& [
{
0 y* ?1 f! J) s5 \4 G9 `0 a7 ?& m! M cout<<"Error, an error occured while retrieving current part colors"<<endl;
8 T" |% F/ R) Y& b. g return 1;
0 S1 e3 D4 Q3 G6 H: ]( S }7 { R% T/ X4 O
3 u3 e: q% x# m# N$ H for (compt =1;compt<=nbfaces;compt++)4 S' ]0 k6 R0 {" U# O
{ U! q D/ s6 [( [: [
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
2 F4 Z- U) B, G% q# ~* Q; A# u: L M# a }7 G/ Q A( F( Y/ N. Y: R
; n% L4 C% r5 H
//
# P; V, x5 [2 s; y9 u //10 - Setting Applicative Attributes) v0 l {, m7 Y9 k0 R& C$ @
//
" e) T4 { U1 B# \8 C% \: E
/ F) \+ m+ T; N/ G //5 w$ Y0 D5 `7 N5 [, y
//10 - 1 creating new attributes
4 j1 t: p, H' `% h; p! u5 @; U5 { cout<<"--------------------------"<<endl;$ ], \5 e5 y& {, O6 D0 N
cout<<"Creating applicative attributes for different faces"<<endl;
$ m6 ?& M7 w3 r0 Z CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];1 q x: q0 K+ j6 n9 }) k# o6 p
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];# L j7 b ]2 G Y
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
Z- E) g/ R% `+ W for (compt = 1;compt<= nbfaces;compt++)
4 X9 d: b6 G5 \8 A% A5 {* Q {6 J1 v4 T I# v, F
cout<<"Creating ";
, ?# X5 c4 p2 X, h' x x = compt%3;# I" @, u: K" C" {2 p- } {
//for each face we create a new list of apllicative attributes
4 F. [ R9 J% A* o1 |! W //an applicative attribute is made of a Name and a value
+ C" Y- `. E' Q1 G5 N# N if (1 == x)
6 A; J* N" _' U {
- g' H. e, O4 `5 P1 J. h AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);8 e3 u$ F; e- C' l
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
: i0 u7 X5 U+ T' O# o) n. ], A6 h0 |: j! x- D
//The first attribute will be the number of the face
6 t6 v& l; f! p* r- m8 X* l5 G AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
" O; H3 h4 |/ `/ w! T9 y CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
' T3 S, y, s/ b( a9 R2 C& ~2 X AttrValueListToSet[compt-1]->Append(tempcke1);
4 x4 | g' d, Y7 c( @ o! o6 G& N
& r; V% `8 X% K0 }2 F" Q2 j cout<<" FACE_NUMBER with value "<<compt;
! S8 ]; b( t$ l( r* a
% e, I. _# F8 O; C- Y& { //the second will be the color) j/ {2 b) ^4 m8 }! k7 `
AttrNameListToSet [compt-1]->Append("COLOR");% U# j, R) Z2 o! l' N6 N
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");+ U9 u3 m1 h/ X Y. V
AttrValueListToSet[compt-1]->Append(tempcke2);
# L) P/ y1 F4 U* j1 x " Z, Y% G! |. @- F) J! E
cout<<" COLOR with value Red";8 q8 j% p0 ?& l! s3 G! E
{" P U, a& K2 z2 z- q //the third is x
, G1 A; ], p9 t' ?! V3 ~8 ?% ? AttrNameListToSet [compt-1]->Append("X");
9 z. w) i0 k- r; e CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
5 y# U; a" R. c$ R& g AttrValueListToSet[compt-1]->Append(tempcke3);, a# O, ^* p/ D, B7 e |
; g0 G8 D: b( i' K& O, ]. w cout<<" X with value "<<x;
! P- e$ R( ~; l& g: g% P cout<<" for face nb "<<compt<<endl;
" U) y! x+ y3 e8 Z }
+ P; b5 ^: G) R- V3 G7 K else - P4 I, E. D, N, C6 n
//just to show you you can have different size of list
! L. d X1 K6 G3 [+ d2 K* y2 x {4 \- T' l( o1 e! `( _
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
; F7 Y0 `0 w% q AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
: F; G' `2 e8 |
" h1 j: h0 V7 C4 m+ g% M2 g //The first attribute will be the number of the face( ?0 C: X$ J, Y5 b7 |' h
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
, P7 K+ W$ N1 f7 t# j( \( H7 ~ CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
! w9 v1 ~" Y" J7 h) {8 U# t AttrValueListToSet[compt-1]->Append(tempcke1);
. R; x3 I* x8 m. z" D7 u8 Z( _ `* Z& T# M0 M; s* k
cout<<" FACE_NUMBER with value "<<compt;
% J- k* G1 n, f0 ^
: ^/ ^" k0 ^* c1 p //the second will be the color6 I: A) B! D, g9 i
AttrNameListToSet [compt-1]->Append("COLOR");1 x/ w3 ?+ c8 s2 T" Z" u
if (2 == x)1 i7 V- D, Q! l* K2 ~1 @
{
6 l! |# e& B/ E CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");! d, F8 `0 V6 `2 }
AttrValueListToSet[compt-1]->Append(tempcke2);1 X+ \2 U3 F2 U( `7 K6 @( S
# h3 | C3 m/ j9 X0 c
cout<<" COLOR with value Green";: I, s# o/ j2 U E0 X7 J) l
}
& b* Q# W6 E" R0 Y& |* Y, B! j7 K0 Y. P if (0 == x)8 e( ~ v& ]' z' ~. W" F- ]' \3 J
{# ~* Q [2 v' S: \0 q+ v
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
6 m& g! Z& e2 k$ F& A# Y0 O AttrValueListToSet[compt-1]->Append(tempcke2);
4 ^( K7 {3 @$ l1 ~ 3 z8 `( j- g' \5 ]: t& f! H( Z
cout<<" COLOR with value Blue"; A |$ C* J* M; S
}! B N6 x+ P; s9 f# r& z/ \* C3 i, y
- e' y4 Z* s/ \9 O/ x# W
cout<<" on face nb "<<compt<<endl;. B* t1 C: ?" A2 T4 R7 O
* C4 [- T3 | o) m( R! Z2 Z
}
* K- v7 a' Q" G# b) U }4 q) L3 ~# S7 g( K" k, `
$ m/ A2 Z- i' @/ h Y
//10 - 2 Setting the applicative attributes9 ^% S# B. v* x
cout<<endl<<"Setting applicative attributes on different faces"<<endl;3 B: m1 O' e R' H8 U$ M& V
FailedIndex.RemoveAll();
. p$ n9 _3 {% b/ L rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);3 F7 H' E7 W `" _$ R( g
if (E_FAIL == rc)
; [ P( z9 I$ l6 C* H3 \; a9 t8 `" Q {; ? X$ p3 N' s
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;+ X+ _+ A H/ l9 p
}0 |( b; D! S6 `# G6 Z; w7 w+ _
else if (S_FALSE == rc)3 D/ `( w& ?1 S1 c. W6 X& R
{
8 c, U2 b! ^ t. X" m% Q int nberrors = FailedIndex.Size();, J6 Z! y7 h( ^; S+ X" ?0 _
cout<<"Error, setting applicative attriutes on faces fails for faces :";
. q- N1 R' v" v% _7 z for (compt = 1;compt<= FailedIndex.Size(); compt++)
# m. h# J* o" |4 ]6 C2 v$ B {/ P) V0 [9 J, t7 m1 [
cout<<" "<<FailedIndex[compt];
# J8 [% Z# ^1 d' f% S }+ L0 Q. }6 \: M; N8 z
cout<<endl;/ F% A; J- X5 O$ j) ^8 u: U7 N7 l
}4 V- x0 V) A) i- v6 N( x
else
* S' {) L3 _" r5 j2 M% { ^ {& [6 x4 t% O, d t# \( c: l: ]) f
cout<<"Applicative attributes successfully set"<<endl;
9 H! \% C9 [0 h) [ }/ _* p; J2 K& I; \5 ]
( @3 X# b; N5 X5 I+ o. z //10 - 3 cleaning
; V2 D- S. h. H for (compt=1; compt<=nbfaces;compt++)) Z4 u M, f: j5 Z
{
0 h0 N% }$ B* I- \1 l AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL; y3 p- H, C" }2 }, u
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;' c% y- [- g1 e$ ]; Z. T
}
' R# r* z1 J" X. V: k, e' f' \6 {' E+ k! B# i
delete [] AttrNameListToSet; AttrNameListToSet = NULL;" L9 T! K9 E4 z% X
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
. K i! f' r2 v. s9 O( _# o# h$ C& ]+ n) h0 o
//. W) k( n9 `1 y% [" k7 J
//11 - Retrieving the applicative attributes we have just set
) H6 |1 l7 K& l+ X //3 Q) J8 J9 H6 O/ n( c/ h. i
cout<<"--------------------------"<<endl;/ X# e) ]: C! @5 R" ~' ]
cout<<"Getting applicative attributes on faces"<<endl;
5 V! ?( Y% l+ h) l* A+ q //
6 ~! b/ [# L' H3 {0 c5 y //11 - 1 Getting attributes
$ h p3 J, L1 F' i/ L! W/ y CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];$ N$ {% c- Y+ {! _/ |) B
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];4 |; K% B8 e/ u! ~- S
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
" q! r4 [9 d, @7 Q% O if (SUCCEEDED(rc))
" @! l& s. L9 U; |1 d {) P& v) D) T l0 \+ x8 S+ v$ ?
CATListOfCATUnicodeString templiststring;% C' i0 B% R; L' U, P6 C
CATListValCATBaseUnknown_var tempCke;
; g8 p& b" |( V4 @; A for (compt=1;compt<=nbfaces;compt++)! D J5 n8 Y' \+ \- m, Y2 b6 A2 P
{
& o( W* B9 N" H$ m b6 d //retrieve a list a position k (arrays start at position zero).
& O# D. `1 A: q2 ~6 n' d templiststring = (AttributNameList)[compt-1];
& `* h, z. V" n e# Z tempCke = (AttrValList)[compt-1];
5 ^1 \9 t) h( n/ ^) M/ x2 c8 D
0 p% i" z6 {! u; H; l int nbAttributes = templiststring.Size();/ }! j& S8 B/ d8 V9 \* s1 ~
int nbValues = tempCke.Size();
9 x0 r/ A; u( P! M% p
$ |2 `2 E2 \3 p& a4 O! I1 ? //the list must have the same size! If not, we jump to the next face
4 m v9 z; q" |; R3 \ if (nbAttributes != nbValues)
4 f) ~6 e% q Q. a# R. q) l {; F4 Y: Z, D: E( g
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
8 Q2 W6 S% R2 {. A9 N0 O continue;+ [. A5 J! i- Z! K* x
}8 K7 h' C- R1 @6 K
else
2 K3 J. S& E1 f {! U/ U" N9 Y& {- O0 A* Q
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;% ~. E- ^+ A1 O) G* t& l9 H" j- d; y
}
+ [- r( }- h8 V1 F for (int i=1;i<=nbAttributes;i++)! j2 X" P4 l5 H+ D7 Z( e) z% ^
{+ C+ ?7 U+ s8 s' ^9 J
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;* J: n* A& \% s. q
}0 }4 t/ @" W2 m, f% {4 Z) |8 m
templiststring.RemoveAll();6 c" v+ x. \( \" X3 d% g
tempCke.RemoveAll();; n, N" _, l- e( ^6 c! l) }$ b
7 A8 X; \4 a, f* |9 Y! Y2 l' X }
5 _; b, x6 f2 c2 t: }! G }
; q- [# b* h8 }( } else if (E_FAIL == rc)( D( e( o+ \7 ~9 {: K" Y- D
{5 J0 D5 [/ I1 ?) ]5 Y9 T7 e
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
& M0 s2 z5 ?' L! G! E6 b return 1;4 C( L# y3 {/ }; M9 H! V
}
- R8 D8 y& o+ E2 E //
5 y0 }7 V& a1 ^* v6 X6 W //11 - 2 Cleaning List:+ B# A0 R1 O8 I& Q) r4 o* `4 _
int i = 0;7 ?2 V) t# z* l2 q" c: m9 ]
for (i=0; i < nbfaces;i++)7 P. c; l7 ?$ d$ t4 e# L$ B" s9 }0 q
{
' [) }# q8 i3 V5 V6 `5 v# M AttributNameList.RemoveAll();8 l! v5 y9 U4 ?7 |- _# h. x
AttrValList.RemoveAll();
" g7 r; i) y# e L1 f- U% J* @ }
5 n$ \/ l5 T" m: v delete [] AttributNameList; AttributNameList = NULL;
; z7 y& W! I, y, w+ v4 v& d3 [- n+ d delete [] AttrValList; AttrValList = NULL; U' H# k! \) Q( q G, @( z
3 I7 a! Q, O/ C7 c7 c. Z# } for (i = 1;i<= nbfaces;i++)9 n4 A3 V2 @" S1 \+ ]- k
{
1 A, K/ [9 X3 p/ a! V) O; G( r Brep = ListBreps ;
- v' V' R# a: C if (NULL != Brep)
7 s6 Q- x% a; }; B" p3 ?$ { {
" v) [3 Q2 J4 n3 b6 Z. b* l8 V. R Brep->Release();
8 c, d4 c' ~. i; A6 t5 U" H }
2 Y5 l' j4 o1 Y. Y. {# x% H: i }
* W- k. ?/ y5 o# {; l% S: u ListBreps.RemoveAll();[/mw_shl_code]
- \ p3 {0 j9 U |
|