|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]5 p2 @; R7 K3 \
//
L) t* J- R; h. u+ ~$ F) ^' r //7 - retrieving and displaying current faces colors
$ Z6 z. d3 ^' [7 j //5 U' z" T& n0 G |! c9 M; Z
cout<<"--------------------------"<<endl;. a# u& U5 F) B' |
cout<<"Retrieving current colors"<<endl;! e; a& P" p# ^2 g, L7 f, N' y
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;5 J; P4 m: G( p% _5 h
6 F# \# J. |2 k4 P4 y! x rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);$ g/ e* A5 k% g1 E: L1 Q' {3 N5 U/ G
if (E_FAIL == rc )8 p+ J4 q2 W( Y, Z1 S j
{$ z% {$ E1 E, `8 i& _8 j
cout<<"Error, an error occured while retrieving current part colors"<<endl;
) w+ X }# B5 E/ E9 `4 E return 1;/ O/ v& u h" e# m P* ]$ Z
}
* c5 l# a7 ^+ q: Q$ X
( C8 ?. Z: ` x for (compt =1;compt<=nbfaces;compt++)
2 t5 W4 Y1 u: I! I& s% O# I( I {
/ _4 A9 C6 c* u5 x3 U' O& D cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;. f ~: B# v9 ~( H' t. Q* x
}
4 _. R) N& y% K" q" B% R0 C2 ]7 f! L' K8 O
//
0 y3 B( P4 ?1 d3 ? //8 - Setting a new Color on all faces1 {% F; y6 C4 @7 v) L; q" C( |
//
) D$ ? {8 R: x# \, [' T, X& F( |9 G ~
//we are to color the faces with different color according their position : three by three will have the same color
9 N0 \0 J) ^% E cout<<"--------------------------"<<endl;
* O- J- \) L- i, `+ c5 X3 [/ f cout<<"Setting new colors"<<endl;" h( p Y! T% _. S8 W3 @" o/ y; L4 R
7 J u- W! v* E, m- ~. R# b0 c CATListOfInt newRed,newGreen,newBlue,FailedIndex;3 ?$ g/ A$ O* G8 ?
int x=0; ~9 T7 T; r6 d2 V7 \1 m
for (compt = 1;compt<= nbfaces;compt++)
$ v. m8 w, S7 E) e3 N/ ] {
; @. z/ p# g$ Z( x( a% h x = compt%3;0 n5 Z2 l' `& G' Y G J: t: W' P
int red(0),green(0),blue(0);
$ a5 |) X$ t% ?$ n6 `, o- r if (1 == x)
' y0 h. g1 ]' _5 O+ }8 V red = 255;& H1 U4 F8 r/ d. `$ W; _
if (2 == x)
6 u! G" l( D9 d6 S) s; @. r green = 255;0 p! M& t# t t; Z2 L( g4 r# a
if (0 == x)) n3 O8 z, @! U6 q; B
blue = 255;* y. E+ `8 e5 [% r* Z# Z- c9 q2 N
newRed.Append(red);
6 \. d3 v) I* C1 _% x; ? F+ g) y newGreen.Append(green);7 a$ L4 M# V* g
newBlue.Append (blue);# m( J r! f5 P% y, D( X% k
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
' T5 x8 j* V& C8 ]* N }; ~3 v: f# ]) f0 m, a
3 i0 {1 B( f3 V1 h9 {5 {
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
, M, R6 a6 l) }! |; {: R: x9 v if (E_FAIL == rc)+ P( ^2 j& O" `5 X" n8 H6 [
{& ^ l5 D5 h8 h& I. r
cout<<"Error, setting new color on faces failed for all faces"<<endl;7 V! x6 F4 B4 M r9 A2 `
return 1;
" `' F0 M4 U H) P( A0 }& f }; j7 k z+ i3 Q
else if (S_FALSE == rc ): a5 Z8 Z2 ~ H! C9 t5 x
{
( o- t r/ E, H1 O: k int nberrors = FailedIndex.Size();
: r: T+ i! z7 Z* o. B cout<<"Error, setting new color on faces fails for faces :";# g4 Q" J5 ]* t2 r& u$ F( A
for (compt = 1;compt<= FailedIndex.Size(); compt++)7 f* l3 L$ J' I
{+ r+ U" b9 K% j! G3 x
cout<<" "<<FailedIndex[compt];# q4 \- m9 Z, ^) u8 L3 R
}. u" j: j4 n4 s9 K
cout<<endl;& [2 `. j0 s0 r) Z
}4 \5 B* ?: X2 P' e5 j
else + y# a6 Z* T3 L- \
cout<<"Colors successfully set on every faces"<<endl;
6 G: H: K4 Z' w9 L" R: j6 X5 P //
4 ^$ f7 V* R' C7 M) p( F- f; k //9 - retrieving colors we have just set
& ~9 t4 T v; b4 H. X+ C //& p, M4 w, n f9 J1 \; T
cout<<"--------------------------"<<endl;) B1 X5 {/ Y! r! \/ z' X
cout<<"Retrieving new colors"<<endl;/ Q) ?; \0 }2 @) ^
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);) l7 _5 J& F8 b S% T5 Y
if (E_FAIL == rc )
8 Y& f5 C6 i$ J5 a) S$ v$ r3 |3 _ {
% }+ G& A; _5 H cout<<"Error, an error occured while retrieving current part colors"<<endl;
, Y. W0 J/ |4 Q$ O( p4 `/ t; A return 1;
2 e2 @- x7 E7 v @9 m0 x }
_# ]$ ?- k! }$ l3 ?+ f/ t9 G
4 A: w7 ^' z7 y# J7 f' P( [ for (compt =1;compt<=nbfaces;compt++)
$ w( @ `5 H6 S {
: M7 E& E: `! e# c8 X ~& [5 F) q cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;! H1 ~, q% N: d$ K5 @
}
, a6 o# i+ o A% w7 r" @5 X" P1 k1 G; Y" S7 \) ^) a0 q
//
2 {/ s; z; Z0 b$ h4 V( ?, m# \ //10 - Setting Applicative Attributes9 d/ q2 {# X" Q4 u& H4 U
//
& A; Q1 q$ s/ q" r
0 C+ w: p- h' _! ] ^) f //
) t, T2 X! ?' S" N. L //10 - 1 creating new attributes
' X0 U* ~0 Y, [7 E* A9 s" l2 M7 Z cout<<"--------------------------"<<endl;" d( K. J6 j# c5 q9 u
cout<<"Creating applicative attributes for different faces"<<endl;8 P3 _2 f5 c/ `0 h" L; d }9 M
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];- e( \/ x4 N7 d& w
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
' C5 o# a4 [7 I7 E% p3 d CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();. v2 p) R" s B# J2 Z' ]
for (compt = 1;compt<= nbfaces;compt++)
* R' [* Q2 N) J) O {: L& z) r) [ O& a3 w
cout<<"Creating ";
4 W2 N8 |9 w( b( Y0 u( [ x = compt%3; {" O( W6 f! w5 e; J
//for each face we create a new list of apllicative attributes
+ Q4 b2 f- {% ^0 o- R( N3 R# {8 i //an applicative attribute is made of a Name and a value
, Y( H: U) l" g/ @" P if (1 == x)
* d; x& B! \6 e1 x7 i {! P) k- s7 X6 U4 p- t9 w! b3 G
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
) |) K5 F. ]& y/ } ^ AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
1 B# z% b5 z1 D3 E. B6 Q* `- s+ d- H* S* `4 i
//The first attribute will be the number of the face4 @! |% |7 l# ] J- x) h# d
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");- w" ]3 Q- D# d
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
1 z4 {, v1 L/ V- @1 ^8 Q/ [9 N AttrValueListToSet[compt-1]->Append(tempcke1);* u. Z# |/ I) O7 R
9 h& u4 f3 O, N2 s! P
cout<<" FACE_NUMBER with value "<<compt;
4 V* q9 q' \% y R P" k! n0 I0 n" l% A2 M$ `4 B
//the second will be the color( i4 [8 [- d; P4 t# g
AttrNameListToSet [compt-1]->Append("COLOR");$ C7 q2 o; e# n& f! H! a/ c6 } z
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");% E% L. e: `1 p5 N) |, N- o
AttrValueListToSet[compt-1]->Append(tempcke2);9 |0 ]0 R, r$ D1 ]
1 e( _& N- m# z( ~! Q cout<<" COLOR with value Red";
@! B4 G2 x( ~; Z1 M6 b
& ]* `* k. d* B9 u //the third is x
- f9 r9 c# H1 W& h- s: } AttrNameListToSet [compt-1]->Append("X");
2 O$ F6 a7 F; e1 O3 e8 D3 W: [& a CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);' W5 v& ]5 G) r3 V
AttrValueListToSet[compt-1]->Append(tempcke3);6 U3 f: t) `1 A5 r& ~8 n: ~
; ? P1 h) |0 ^% G
cout<<" X with value "<<x;
. v, s3 P- _' ~7 l3 R' ]- O cout<<" for face nb "<<compt<<endl;8 L3 p! J- M+ w9 Z; L
}
2 z7 i' W Z! w; }% K else
. M8 x1 v* A, J //just to show you you can have different size of list
- C6 V. {4 k8 R: F {
# c+ G7 O( {8 i6 F' \8 \+ m' A( G AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
3 x5 B+ b$ t1 z+ N! o8 }) C AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);' _" I7 |8 Z1 x5 ]; L8 N2 S
7 I6 P3 x3 T4 h( G$ D* U
//The first attribute will be the number of the face- i. n: b# U& r! \0 }. `- m8 M" p7 A
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
' b ^' a& D& c% h CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
/ |. d- ]! x( {% ~ AttrValueListToSet[compt-1]->Append(tempcke1);$ K; X7 d/ U& n
! H" M& ]2 P' ?" O! w, o3 { cout<<" FACE_NUMBER with value "<<compt;
0 `, }9 C' L' h ^1 m" ^
7 Z3 U: V! C) [0 ^1 v6 o //the second will be the color7 X: b* S- I5 U" s) V4 `
AttrNameListToSet [compt-1]->Append("COLOR");
2 ~) U5 @- J1 |8 s& S/ M; j if (2 == x)' R' z y3 t+ u
{
- i: v) x3 S& A9 \" h: W) k CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
6 {0 h& A7 U, G z AttrValueListToSet[compt-1]->Append(tempcke2);
. S: h8 \. }) b; S) v& S
7 ]- P( R8 s/ ~+ z0 {% ]- v cout<<" COLOR with value Green";$ x# {7 U1 O( O8 P* S* q; A$ l& N
}
9 Z1 k- m0 f# r9 e if (0 == x)+ @- | P# O0 o5 m8 W, u
{* j6 q' c0 j" ^5 ^! B8 U. o% d
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");5 v( r# H8 ^. H: s" K
AttrValueListToSet[compt-1]->Append(tempcke2);
& H) M8 D; D9 f7 k3 g8 d
7 E' F# j1 j/ N' t. _. H cout<<" COLOR with value Blue";
0 d: U3 G/ X8 \8 W S; g7 x }
7 Z# Z( g9 w) Q9 k5 @4 \! \3 |8 T- J" J
cout<<" on face nb "<<compt<<endl;
- {4 r0 d% x' V# `4 E, ~8 b$ M. Y6 y
}. B, v- {6 g. a
}
$ A- @) y) h0 @ }9 ?. I' W( e; j6 N g8 u7 q/ W
//10 - 2 Setting the applicative attributes
$ T/ g2 H5 w& M- S: j( ? cout<<endl<<"Setting applicative attributes on different faces"<<endl;
+ }# G; t3 G" d. j7 ~9 e FailedIndex.RemoveAll();
$ K: R! I2 G7 m P- c rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
$ c1 B2 p. M0 C2 b: p/ ^8 F if (E_FAIL == rc)
7 l* }! U- y" z+ b {" F+ {* Q5 W9 y7 I2 e3 \5 d
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
# U" j# D3 ^5 C! _9 z }
' R/ G7 @% R2 l/ i' f9 ]3 l2 b3 i else if (S_FALSE == rc)2 t% t% P1 {8 d ]* h7 p% w4 i" k. q! [
{* O" y+ ? H, X. v
int nberrors = FailedIndex.Size();( Q) `, e3 ?% j# M( J
cout<<"Error, setting applicative attriutes on faces fails for faces :";; w5 |6 b/ J/ ]
for (compt = 1;compt<= FailedIndex.Size(); compt++)* ]. C$ K4 N0 f: q* b1 N
{
& l8 d" E! `9 ^ cout<<" "<<FailedIndex[compt];$ Y7 X9 n* V8 P6 j* W6 v
}
- O' d) @; V$ s3 w. h1 g4 u" r' d2 | cout<<endl;3 I! Z5 E) ~2 q! t! a% i
}
6 v/ N4 S( z2 ]2 e2 U else
/ ]' C2 q! {3 z# Q" K9 D {% t8 P+ D6 S- Y2 Z# V" }9 h: \8 V
cout<<"Applicative attributes successfully set"<<endl;9 b0 @: y& V. V4 Q" ~- e
}( J O) b6 P9 w1 E5 k& c' a/ I/ r
7 N2 a1 L: B7 l3 C& H //10 - 3 cleaning; i1 P3 X, o% h! ^
for (compt=1; compt<=nbfaces;compt++)
$ F c' E. o! i: r9 `- }) A {; O/ c; v: x4 c7 T2 U# b" ]8 F
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
% H. g B/ J$ M, M. g AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;& K. f4 [) S) Q% x
}; a A/ Y$ F- c& J
4 a7 T/ X1 H2 p& O delete [] AttrNameListToSet; AttrNameListToSet = NULL;
8 Q/ A( `; i7 L, K delete [] AttrValueListToSet;AttrValueListToSet = NULL;. R4 w& f) t5 {1 T/ h) V
( q: _, d2 M! v& z: Y: _ // U& Y1 i+ Z) g' V* \ z
//11 - Retrieving the applicative attributes we have just set
& \" }5 v2 D' o: W1 x3 g //
2 k. ^+ i, C) S; H7 d T( i8 h: J cout<<"--------------------------"<<endl;" _8 F' m" H5 r3 x
cout<<"Getting applicative attributes on faces"<<endl;' o/ V4 { V" N2 I
//) j$ q ?4 a* e g
//11 - 1 Getting attributes8 j" i& q( u8 ~2 p- i
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];1 H9 S% y- J4 J& y$ C) R- U9 `# R
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
" z- @" [* K! Q3 U% B, A. F- H! W rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
! }' `! Q: u! c# f! M3 T5 K0 J if (SUCCEEDED(rc)). R# o# J1 Q& M$ p! I( `( X
{
1 r: ]& j6 |, o# a CATListOfCATUnicodeString templiststring;
8 M! u" n( ^0 B) i CATListValCATBaseUnknown_var tempCke;
' p5 Z0 m# G6 Q! T* |4 j for (compt=1;compt<=nbfaces;compt++)1 q, W# E! Q. R4 A# B
{
& [' K! M! x) S) t I- P" j //retrieve a list a position k (arrays start at position zero).
% I/ u/ ]: _8 O2 h9 k1 ~0 ` templiststring = (AttributNameList)[compt-1];( u' y, ~1 q* U7 ~! Q
tempCke = (AttrValList)[compt-1];
6 s- m9 Y1 U8 h$ e) u# B1 P `+ K$ P2 J/ u
int nbAttributes = templiststring.Size();
J9 C2 G; R/ h- e# x* k% y( K int nbValues = tempCke.Size();
f9 n) C& g$ W
) p% c: q& ?8 m8 x3 T c. l //the list must have the same size! If not, we jump to the next face
: K6 w M" G/ k( F6 `/ Z if (nbAttributes != nbValues)1 M1 N: C& e, S
{' ~% F9 x; ~8 N! h y/ h
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
9 K8 i* d7 l; n! z8 T continue;* I9 \6 Q; W7 ~
}3 c$ A3 O: I' y4 H* }
else
3 @8 G& c6 B% M4 R8 h- m. q3 Q6 ? {& d3 d' h @) b0 ^; t/ m, @
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;1 P5 [" A, H6 l7 r6 C/ p
}( a/ t6 v! V) ?$ E
for (int i=1;i<=nbAttributes;i++). _9 s2 X# f4 m
{$ J# ?+ G8 D% T+ M% v n# q$ q& U& A2 k
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
8 u+ k$ N5 _$ `. o }
% Y# F& u4 C9 t! w9 f: r* x templiststring.RemoveAll();
! A7 Y1 l: e9 J# h tempCke.RemoveAll();
' G- q7 b1 q# d3 L6 n3 @% B9 j5 T( M5 u: n8 n: z
}
, ?- F2 U, E9 F! n5 t) C' _ }
# k8 R$ e8 i8 j! g: {' S else if (E_FAIL == rc)
, w- U0 @0 Y) K3 a! j {
( l( ~8 `' j2 k* A: Z cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
- y3 [6 T" U9 @1 u) q+ t2 M7 I return 1;) m( @% q- [3 S! H$ c: y
}2 Z1 Q8 F( Q( V9 X5 G
// x+ s' e1 h$ E
//11 - 2 Cleaning List:
, A0 C! o4 r6 `+ @) N: O int i = 0; E: \* {( M" P
for (i=0; i < nbfaces;i++)! t9 ?1 Z% J4 k4 \5 k) _& ?* l+ |
{
" P4 {- F; D7 S% Y4 n! Z- [ AttributNameList.RemoveAll();
& @6 X# ?1 u% W& k% G" e8 d9 U) X AttrValList.RemoveAll();2 M ] Z! d, D t m" j/ h
}
6 y. l# i1 z' H delete [] AttributNameList; AttributNameList = NULL;
3 u' ?- K3 n3 Q9 ]+ H delete [] AttrValList; AttrValList = NULL;6 p0 E+ }0 e+ w% h& Q9 _4 J$ h* s
1 s/ \5 v# l( s* d1 P* `
for (i = 1;i<= nbfaces;i++)- V. r2 {6 d8 L; Q5 \
{" z5 f4 J/ |5 J1 j, t
Brep = ListBreps ;
6 q! v2 h0 d1 E% J, ~ if (NULL != Brep)
& V. ^7 S3 n( @! G% C$ s1 R/ a {
7 \7 j: G$ c7 j3 r# D Brep->Release();0 w- \# {0 e8 V/ w; ?% [1 }
}
# m- C$ S% m4 Y4 H: M5 Q' }+ T2 n }
9 n" P) m/ a$ s ListBreps.RemoveAll();[/mw_shl_code]* H* j3 d, K1 K' c2 a Y8 F
|
|