|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
$ n& Q/ G1 ^/ l# m- Q //
) y7 W* r$ Z5 y, w. v- ]5 a3 v //7 - retrieving and displaying current faces colors
/ m/ A! }( T& ~ //
S0 O$ X7 b! q$ t8 i7 H6 [ u cout<<"--------------------------"<<endl;
- w( b# O0 V" O" w- M cout<<"Retrieving current colors"<<endl;
# j* U0 c2 `" `& Z0 z) ]0 J( o+ d CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;1 Q; ?5 i6 ~/ u+ T1 J# t
" p7 O/ T$ a' ` x! ]9 S rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
4 [1 \0 H/ j" C: J8 @! }7 u: Q) j" p if (E_FAIL == rc ): S0 S! O5 c. {0 C: S
{
5 G) p& W; ?2 K( [1 M1 U0 J cout<<"Error, an error occured while retrieving current part colors"<<endl;
, y( U5 y+ K* t1 M) O0 b return 1;2 c P5 Z3 T- O5 P- g+ ]9 J
}( u# X0 h: p& p% \5 W) _, z2 R. f
* b' n" {3 a7 A4 W- @
for (compt =1;compt<=nbfaces;compt++)9 g% h: C' U5 {1 \
{, q7 v: i! N$ O' Q) a* o: p5 x6 B
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;7 b0 r4 {( ?: p9 Z) v0 I
}
0 _) {1 ^. c8 r# v0 Y8 H+ Q) y. u' Z' t' f& {8 t5 ?# x2 P
//
; A) F' d! x# V& k" S: n6 j( t //8 - Setting a new Color on all faces) Q* r3 E+ i3 u$ n! S
//: B' l2 ?" W2 U
/ P6 G7 Y# B. v //we are to color the faces with different color according their position : three by three will have the same color
\: G6 L$ K; t' t* a0 b cout<<"--------------------------"<<endl;
6 F m6 q- x% C. W# x( A1 s cout<<"Setting new colors"<<endl;; T" X: D9 Y) P+ t# B1 Q
- [$ C3 d, k; L
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
. }$ j5 \1 z& F' G2 p int x=0;* O9 i7 S4 f6 ]
for (compt = 1;compt<= nbfaces;compt++)
) E( W4 V. N; N) h5 r7 j X {- E( c. C6 v$ x% i
x = compt%3;/ ]6 B: m. ]9 t7 e- \) y/ |+ I# k# K
int red(0),green(0),blue(0);
% o& g3 d [0 L if (1 == x)# ~3 y* O: J; e7 d9 _
red = 255;
h2 W/ M f; j1 ^ if (2 == x)
: Q3 X$ N: _( l green = 255;
5 O) b" y1 T3 b9 A' b) h if (0 == x); j* H; @2 [# k# s
blue = 255;% _. v0 ^7 f* [0 ^# A) J
newRed.Append(red);
. m0 t1 r- U5 w5 _. N0 L newGreen.Append(green);
7 r4 [, N3 Q! K T& O! V newBlue.Append (blue);: `$ I ], R6 q, [- Y0 c4 L4 e/ G
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;; F' ~/ m( w8 l( F, R# C' p
}0 v0 o# \9 \7 A3 I
5 p* Y Z+ F4 i; W rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);8 [' T R7 \5 P
if (E_FAIL == rc)
! u% }: [7 `5 U! k {
, o. r1 s. Y) e& b cout<<"Error, setting new color on faces failed for all faces"<<endl;( w$ c8 g# k- {" s4 n& n
return 1;
& Z, d: I9 V$ ?8 M$ ` }' ]/ U2 c5 k+ f: Y, K+ M; F. M
else if (S_FALSE == rc )
$ Z, f {% n! R! v0 g" D* v {7 N1 O# H9 ]( `3 T- p- M
int nberrors = FailedIndex.Size();
8 m$ R% [7 z" ]/ T2 U cout<<"Error, setting new color on faces fails for faces :";7 M/ D" Q3 h- e$ X! n# b9 u* J# q
for (compt = 1;compt<= FailedIndex.Size(); compt++)1 H' Z9 x: S* B5 y8 ]0 l* o3 g9 ]
{; b$ ?' }4 g* x! }5 O. `
cout<<" "<<FailedIndex[compt];
2 B2 G4 E- I# a$ M }' I1 E+ C* _3 ]" o) S+ U
cout<<endl;5 f7 y# d+ [) p- t8 C+ Y% y- f; {( I
}) u# |+ |5 @4 o) S# X9 P, S5 W( H
else
, p6 d, o. M5 ~+ V `0 s! b cout<<"Colors successfully set on every faces"<<endl;
" k9 X9 x% q' j //% n G0 _4 `9 B
//9 - retrieving colors we have just set3 h3 [, w* g4 |# w! P B% Y
//
# n; l+ I! _; Y% T4 _5 Y cout<<"--------------------------"<<endl;3 G7 t% B$ g/ \; n
cout<<"Retrieving new colors"<<endl;1 a, p% d7 p' t5 M6 u
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);" a7 i) c: \) X7 {2 ]
if (E_FAIL == rc )8 G( p+ f1 I/ L+ ?+ t# s2 T
{
. N! T7 a/ p$ z8 K. e& [ cout<<"Error, an error occured while retrieving current part colors"<<endl;
( a9 Q4 e" i$ l& O* p( c5 L. @ return 1;
$ p7 {; x8 y- p* ~3 ?! h }8 O# {3 u$ ?& T) [
; a% w2 r7 ^3 X! ?$ m0 _1 w for (compt =1;compt<=nbfaces;compt++)& Y( R4 _- E R: f
{
* g! V& h# n$ Y7 Z: j7 h% H cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
- L4 F1 a q& V( p1 p O }% t2 C0 ~, e: \/ i* e3 ^' u' ?' A8 ^
: T* d* G( ~& u+ `5 b; m8 D! _- b
//
$ d2 y* t+ l3 V+ M) } U //10 - Setting Applicative Attributes
+ |/ R+ P7 u% L/ \- y //
9 e ^ F' u3 p* | W2 A A( c V
! L! o' H. D" _6 W6 U# p# v' ] J //, H( P5 r, v+ e" a' `6 ?/ P6 x, n# D
//10 - 1 creating new attributes
, V$ W/ L) j' V cout<<"--------------------------"<<endl;! w. I$ j8 q- C9 {# f* l
cout<<"Creating applicative attributes for different faces"<<endl;
! m; s3 `% {* h+ g. O) O, o7 ^9 E CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];8 s5 B0 I* g. `* u9 d j$ [
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
`% L$ [) a, ]1 N CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
- O& M- |* a: \, S% ^: J for (compt = 1;compt<= nbfaces;compt++)
& o6 O& I9 H/ p) } {% J/ f- Y; A6 I2 U1 q5 Z! J
cout<<"Creating ";
0 K' O6 O, @1 i7 k4 e x = compt%3;
- \8 S% M; a ?- X$ b% M$ R( g& v //for each face we create a new list of apllicative attributes% q/ F0 B3 P: k
//an applicative attribute is made of a Name and a value
& y! H$ n+ r9 ^ if (1 == x)
0 m; I |' r. } {
% Z# c1 N) d; \/ e AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);' K0 }# e7 M2 U. r) {( {
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
& d. J/ J! b# c
$ V' k4 P3 E; X: m: e( m ]# \ W" Y$ C //The first attribute will be the number of the face! {! K0 e; `1 Q7 S
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
8 q" |- C! {$ p CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
/ m: w2 s# I6 \ C AttrValueListToSet[compt-1]->Append(tempcke1);9 k6 e7 v0 c+ p6 `- m2 {2 K( b
% Z( }( E# E8 P" U3 y7 Z! J. T
cout<<" FACE_NUMBER with value "<<compt; 7 m- D' d7 D* `/ H: R3 y& T$ w
( K5 h+ e+ R. @! F7 d* f0 w! G
//the second will be the color
( y0 k9 ?1 w, ]! Z2 b4 v+ q) z6 ` AttrNameListToSet [compt-1]->Append("COLOR");$ u. t* {! ], ?) f8 O
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");& b$ q" x% S# j, z- j
AttrValueListToSet[compt-1]->Append(tempcke2);
% {. V* W3 E5 f2 Z
8 e7 L, @/ }: b5 l6 q cout<<" COLOR with value Red";9 K; P; @' N: t' R
: i/ n9 `, M, F
//the third is x
! f" F5 \( s2 L2 B1 a& @ AttrNameListToSet [compt-1]->Append("X");
6 I S* F2 S, ? CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
$ |2 ?- R) N) o) a2 e; c AttrValueListToSet[compt-1]->Append(tempcke3);6 ~! m: J& X0 F6 R5 G) @0 j* g
2 j, S6 B. W, q L: f( y( O cout<<" X with value "<<x;/ J# r$ L& S! {; [) u; I& O+ u
cout<<" for face nb "<<compt<<endl;
& Y, u( O6 L$ ?; @, U5 ~ } D5 |: m. @% \. k6 e1 D
else 0 S1 ]* f6 m! r( y3 F/ I
//just to show you you can have different size of list* L3 I" ?3 U G$ ^
{
$ v/ n3 r& T! v1 u$ Y+ I9 H AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
" i- h/ p& T: c5 k' P* |/ Z R5 e AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);. ?- D8 c4 L5 `. d" @ [' }1 p
$ U3 g6 D% F7 J
//The first attribute will be the number of the face4 b p1 j! d! f
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
, U! R7 `; c9 U$ l& I$ [% X( T# o1 W CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);0 ~0 U. P+ i9 t( Y5 ^4 N
AttrValueListToSet[compt-1]->Append(tempcke1);
$ B1 X, r" D; a: C& ~( l) t% e% k( h
; k* L8 {8 I3 Y' u. @0 l7 a cout<<" FACE_NUMBER with value "<<compt;
Q4 Y* \( T B/ d1 Y: H, E2 H4 t
, j& }4 C) Q0 @* o K0 A" L. c //the second will be the color
- @0 ]+ I3 u8 e: y; N0 n* U8 w AttrNameListToSet [compt-1]->Append("COLOR");3 v) n7 h( ~' v$ P: f: P9 J2 I
if (2 == x); a5 L- t$ [3 ~: r6 Y% ^* T5 S
{# I: D' I% a Z. f2 g: a0 i) u1 s
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
$ T) U) u6 K6 s3 k; a AttrValueListToSet[compt-1]->Append(tempcke2);: Q' b/ a: n( S/ F: ]
$ e; F7 N* N2 k8 E8 j cout<<" COLOR with value Green";
9 o4 J" {/ |2 L% u" N2 O. V }' I6 R+ b- f: i& r! L2 Q
if (0 == x)
' K5 f, q6 A+ t$ @: O3 X2 a5 j9 F' g {
! d; X z8 X7 t* O+ b CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");3 Q3 \6 j5 z9 u V0 W* n
AttrValueListToSet[compt-1]->Append(tempcke2);
/ C1 b3 Y8 b. |" @7 ^0 r. F
D6 U$ P0 h6 \) s6 M cout<<" COLOR with value Blue";) A# p! ^1 K% U
}. f6 H% P. E' x, Y, N k* K
1 j& @- B5 T# F1 d
cout<<" on face nb "<<compt<<endl;
6 x, ]! l; f( U8 H6 P" f
) Z/ Y) Q% `2 @7 n, L+ q6 b6 B8 Q }
( {7 J W1 S% W/ T5 M }
3 @; w$ s( d0 j# K V) r% H4 P s" I1 u9 t
//10 - 2 Setting the applicative attributes
( @' h! {" {* u9 M% C# O1 ^ cout<<endl<<"Setting applicative attributes on different faces"<<endl;) M0 y: R# Q0 t# E* x: H
FailedIndex.RemoveAll();
: K/ F) ~$ G7 w4 a& L, s rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
2 L. }2 }- M. _0 r8 t if (E_FAIL == rc)7 s$ l E3 V9 k4 W: B. J. R7 Y
{
' F3 E+ j/ ?. _/ S cout<<"Error, we failed to set applicative attributes on all faces"<<endl;1 @1 [! ~# A, _; m% b, V* U3 _
}8 M/ I* H4 V; n% p* h" T
else if (S_FALSE == rc)4 D0 j; }. d% o. k( L5 G' c: I
{- f! i/ Z/ L% }( A
int nberrors = FailedIndex.Size();
5 F( C4 C5 i# F2 X6 m' f cout<<"Error, setting applicative attriutes on faces fails for faces :";' P( U! q$ z. L$ s' d
for (compt = 1;compt<= FailedIndex.Size(); compt++)
4 p8 n$ @& d# O( E {
# q; D4 ^, m/ ]; I& P cout<<" "<<FailedIndex[compt];
$ Y- M8 I& @/ k1 H: |$ b! o( i }
2 M+ t8 s$ v2 `% e; d; } cout<<endl;7 P8 q( z+ e. B% w
}" p* c {' R4 F& ~$ `5 a
else& M$ |. ^) s# z3 H; a
{
% r& q5 A) v/ |+ _- O. h6 v/ j cout<<"Applicative attributes successfully set"<<endl;
3 `* U9 w* J0 C# P) c }
1 c, ^. m* R8 T7 y4 |* } Q
" e F, l a( A+ k( e //10 - 3 cleaning
, _, G% v" b' i7 s6 p( h4 g4 | for (compt=1; compt<=nbfaces;compt++)+ E) g& s$ J, j
{
1 P6 Q; Y7 ^4 m5 A( }. h) w- ^" M AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
7 H, N& l3 m% z AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;& A4 j# a, y, E# l( u
}9 f' t0 o) c) H$ Z( j
3 d& i; t8 p! Y/ u8 [. A
delete [] AttrNameListToSet; AttrNameListToSet = NULL;- P4 C/ y5 t& u$ N1 Y4 p
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
* N+ V0 C: J) s2 ^( a% ~/ b$ Y6 _; G9 a6 K- _
//4 _0 l x( l3 v# p" ^* `, U
//11 - Retrieving the applicative attributes we have just set
4 }9 h0 ?# {1 u% h8 n //
6 e, A; E% Y) T4 W2 } cout<<"--------------------------"<<endl;
/ I) v& q d( M' y( z& M- W# P cout<<"Getting applicative attributes on faces"<<endl;
! X5 M. n* e. P: Z, i7 B8 t // Z6 A1 G# \! ~/ K: {. {
//11 - 1 Getting attributes* \/ s7 o* [* Q l! u
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];; C# g0 @5 ] r2 q3 n
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];/ n: q8 n. \$ G3 H; W% P) g5 J
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
* l- H% @1 m, l if (SUCCEEDED(rc)), R9 q1 q# o7 m7 x' U& I
{! i' x6 g* l7 p3 }' u( y* D* s
CATListOfCATUnicodeString templiststring;
3 [3 C5 C+ w- g6 X/ `5 L. i* H CATListValCATBaseUnknown_var tempCke;" L8 ]2 K+ E0 h2 n! e5 @' d
for (compt=1;compt<=nbfaces;compt++); H8 h) O) K& k; N- ]
{
, D( X3 a: m/ @; I( x! A: ^) o //retrieve a list a position k (arrays start at position zero).* A8 ~0 p% g( z; Y+ f
templiststring = (AttributNameList)[compt-1];
& \- D& F$ z8 h0 k tempCke = (AttrValList)[compt-1];" ~1 n* t) e% y+ e4 v/ ]3 X
( A3 `! r: H. v+ d int nbAttributes = templiststring.Size();& R5 F0 T6 ^0 _9 l
int nbValues = tempCke.Size();
, y/ u" S1 t! m2 V: w/ S& U2 X/ i) r- B# W2 b$ i2 ^
//the list must have the same size! If not, we jump to the next face
: d+ V9 J. |0 A$ B if (nbAttributes != nbValues)
+ l9 A2 L# R' ?6 y3 [ {
( j4 S- W; I$ E( o9 E' Q cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;% ~- u( D9 L. c! n
continue;
0 V9 h R/ j( i& |/ Z }% }; j3 K& [3 R/ ]
else
) V. e4 ]% j- S! r7 e; }, Z2 V {
# F- E1 X9 ~6 T( N2 M! T5 [9 i- S cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
q6 i, `, H* E2 t; `$ A }
/ n% i3 n# m: C* \9 ^5 K6 d for (int i=1;i<=nbAttributes;i++): ~2 v% |4 R6 A6 [
{
4 q. e6 {6 r* {* o cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
1 `7 \" b& g$ Z! m5 |* ^4 Z5 Q }* l% v: |4 m1 X7 U( ?! G" ^
templiststring.RemoveAll();( U7 d+ Z/ F8 M1 O* p; c! D; f5 j) f
tempCke.RemoveAll();
" g$ b! p$ Q+ C0 W; F
/ u; |) ?# U, m1 |" P, v( Q }
9 D* q) {9 Q% B3 n$ r } C& ]7 i3 _$ N* A: { M
else if (E_FAIL == rc)0 P7 a/ g0 `0 { c+ @$ p9 p" g6 t
{6 |- f; ]0 D9 N2 F9 N. w
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;* n) Y$ r3 @$ W. E( y
return 1;
8 k7 m% G; Y% l8 L }; M$ Q3 p% v' C' X5 w; E8 D. J6 V
//8 _1 b# Z9 |2 e
//11 - 2 Cleaning List:" b' Q+ H2 S+ H
int i = 0;
/ {3 {( C* s5 S1 K7 x& _+ m0 _2 R for (i=0; i < nbfaces;i++)# W5 w$ |6 e5 U
{! ^0 @; y. u! p# G" p6 x6 z0 q, N
AttributNameList.RemoveAll();! i1 n: y6 w8 f
AttrValList.RemoveAll();
2 M# m& F8 w! c2 N5 o7 _ }
0 n* O& `' b# s/ e( G delete [] AttributNameList; AttributNameList = NULL; m* E4 x/ [& Z6 a
delete [] AttrValList; AttrValList = NULL;
% w6 L$ Z* ]# K1 F
' C2 o1 ?- H1 V: l4 }$ d for (i = 1;i<= nbfaces;i++)
- a- d' G. B, A" c4 y& a Y3 N7 E" _ {. ]& |* b) b$ V
Brep = ListBreps ;
! X! ~7 W0 F) h if (NULL != Brep)3 Z. f0 C$ B$ H) H2 S
{+ {/ m, l+ Q2 ?) {9 B
Brep->Release();0 B. F8 _+ e" m+ o4 s
}
1 o6 ~$ [4 ^( a7 \5 ]7 x }* n+ x3 i5 z6 ?8 n8 D3 S
ListBreps.RemoveAll();[/mw_shl_code]5 W8 H" Z, ?4 t
|
|