|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]( z! I6 A1 c! U8 c! g, s$ `
//
6 a7 y7 G* K. e3 S: W% v1 n //7 - retrieving and displaying current faces colors
5 L$ R+ B( d9 ? //: S9 x" O3 F" ^6 z; z$ \6 P3 [
cout<<"--------------------------"<<endl;
9 }! w: x3 H/ O2 m* n cout<<"Retrieving current colors"<<endl;; T& B/ B6 {, ] R: W ~& l' m
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
* b8 H: Q1 U/ S0 J# T 4 Y# a* Y3 g; u% C; p9 V- q! W1 a. }
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);, a; B) ]0 `+ G8 y% r1 ]$ J$ t j
if (E_FAIL == rc )" e* g7 J9 O+ I% {
{
* U. x& T1 B0 e- l' b' O$ R$ N4 o' M cout<<"Error, an error occured while retrieving current part colors"<<endl;
6 b: ^) O6 b+ a" A# v return 1;8 @5 |) S5 } e
}/ i: A# u' ~0 |4 T
: F: w8 b% c: U
for (compt =1;compt<=nbfaces;compt++)
8 u5 @+ v+ a) f. ]5 Z {
" S, c/ G. F% U- ?4 Q; O5 I cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;$ ?4 i- [1 p( u4 P
}
' k& l V. k0 ~: K7 Z. y1 n# L* V" O& K
//
7 y# X# S/ R/ K& b6 N Y //8 - Setting a new Color on all faces
% D- Z7 U( C5 X //
5 ?' i9 S+ G( `# J$ N/ |( h* ^% R, y9 C" {
//we are to color the faces with different color according their position : three by three will have the same color
7 E4 t* |& k, D5 s7 s, k1 c3 Y cout<<"--------------------------"<<endl;
+ O# B( u4 M# |+ k* |- R" X cout<<"Setting new colors"<<endl;
' {8 W& x) T+ S6 N: P* p3 y. g
8 U+ i V9 X& U1 H7 J, U% S CATListOfInt newRed,newGreen,newBlue,FailedIndex;" z B0 ~0 t! i2 _+ Q2 m
int x=0;
- I& y# g0 F! l' L' |1 j for (compt = 1;compt<= nbfaces;compt++)
2 {$ T1 P" l% E7 [8 t9 X9 p, @0 F {
7 j! B$ k' b, Y x = compt%3; I; k" U- z. e
int red(0),green(0),blue(0);
+ q9 ^; X) z' K& b$ E4 W if (1 == x)
4 S$ M/ P% e2 `: V" E9 C) m red = 255;
: b4 e y- j+ [" s' j3 H if (2 == x)! V9 m6 W# v, ?) u% o& e* b
green = 255;
4 W8 ?& u7 ?1 t$ N if (0 == x)
( a5 F ]7 V4 [9 {$ ]" M+ n4 u, x blue = 255;
% h Z( l4 \- Y( P: B newRed.Append(red);4 ]/ @& \7 [9 Z
newGreen.Append(green);
' K; V3 k) D) w# \: u newBlue.Append (blue);( M3 m7 [+ K, S2 _4 M
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;/ N& a$ j; s5 \6 e
}
% h/ n+ i& _; P0 j$ I4 ~1 ~3 `5 S1 Q, f# k y) H7 M/ d; a8 }& h5 K7 t* C
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);9 H( F7 D* u$ \; \/ z/ C
if (E_FAIL == rc)
5 |' H7 ]' i% H9 C( b+ U' I+ { {
* p! Q& U$ f# A- J( i a! i cout<<"Error, setting new color on faces failed for all faces"<<endl;
# h9 ^+ i8 \5 q: H return 1;
( t$ f9 u5 Z' ], { }
" M& H- i4 |+ v$ E* M else if (S_FALSE == rc )
+ f2 W9 v1 U# Y7 L# n {
; Q* I& g" z; R" r t' ^" H int nberrors = FailedIndex.Size();
2 q5 y' @1 E9 _ g4 }3 Y! _0 T4 I cout<<"Error, setting new color on faces fails for faces :";
/ n. [: `- } N# }1 E9 I/ e/ s' R for (compt = 1;compt<= FailedIndex.Size(); compt++)
7 K. T9 ]$ ~% t' z2 v; g {
}, k- B l' I9 A* j& F+ {1 h S+ Y cout<<" "<<FailedIndex[compt];
% Z* y7 v9 Y6 h! X8 k }( Y0 q4 w( g0 Y
cout<<endl;
7 h) [8 C& R/ i% A" D0 N }+ o& m' h9 Q& q2 u
else ^0 s# t! s0 ~6 ]
cout<<"Colors successfully set on every faces"<<endl;2 Q+ H% s; G! G! Z; C
//
) W+ a G$ U% O2 N' V( ] //9 - retrieving colors we have just set
4 U" d) b/ W' Y" q" O //
5 P$ E1 ^3 v! P) }% m; q& U cout<<"--------------------------"<<endl;
9 P) N7 g c* D0 a/ E' [6 Q cout<<"Retrieving new colors"<<endl;
6 G* V1 u% j- W) Q0 W' j4 l' A rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
/ m! Q4 f) X3 E9 I5 {. B' l: `- k, } if (E_FAIL == rc )
( p7 l- i5 V& E% Y {- f) o5 W4 H- J8 X: W" F- E
cout<<"Error, an error occured while retrieving current part colors"<<endl;
0 k1 ^, C) S% N. J' T1 k3 K return 1;
0 ?; J6 R% O, Z# `7 K( r }7 e( W6 [4 K/ _. n4 P& v
+ D3 V' n: m3 a: Y' |% V+ d d4 N
for (compt =1;compt<=nbfaces;compt++)) D7 X2 p% J7 M: h
{( t& ?1 F. ~( g% l! U& z0 v
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
- y u- ]+ |& V2 W7 w" K }( q# X2 k2 }' E- B; |6 k X
8 n. a4 l2 y6 C //
7 G: q, b9 g* i$ y //10 - Setting Applicative Attributes
( z$ v5 @% a$ X' m& q8 F //) O6 w) Y U3 n: r$ U) H, @" { ~
. W i5 I; s' d( c O/ v
//, U4 l) z8 d8 o9 x
//10 - 1 creating new attributes % g4 k, r ^1 r `& G1 M
cout<<"--------------------------"<<endl;
3 x- K! O" T2 P3 Z9 j" a2 l* l cout<<"Creating applicative attributes for different faces"<<endl;: E, Y5 i" u' F G2 M! d& u- {5 [$ u
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];' {) j6 u* t) O
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
; [9 ?4 J. ?, z3 d8 _! Y9 l. k CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
' ]7 i( {" z/ M6 g for (compt = 1;compt<= nbfaces;compt++)
0 T+ i! D0 i, r5 h$ _& R% ?: e8 l {0 s. W( Z% e' v5 q8 `. |
cout<<"Creating ";) ]- \0 ?% A$ w4 U3 l
x = compt%3;9 A# L; {6 x: ?5 {# i$ K% m; Y
//for each face we create a new list of apllicative attributes) x' e* A4 n; C B
//an applicative attribute is made of a Name and a value! B, i6 V! l' v: I: U
if (1 == x)3 n: @; x: c& z) [' r% _, \6 E b4 i/ q
{; c* } \! \+ G
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
/ e x# r1 Q7 Z0 Z: X AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
7 j2 A% ]: {' c9 o
$ W+ M# c. p+ w //The first attribute will be the number of the face
9 B1 x m( Q/ O( r1 r0 L AttrNameListToSet [compt-1]->Append("FACE_NUMBER");* H8 a& W: z+ O6 Y- I) o
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt); T; l4 w& l1 o9 [2 a U: ^
AttrValueListToSet[compt-1]->Append(tempcke1);
" o6 u8 b# N( e" ]7 L3 _2 L R ; U! k. N) K6 {: J, b
cout<<" FACE_NUMBER with value "<<compt; & d0 K& b# D6 M- j3 y! R U
+ ?8 ? i) [7 N% d; S1 ], l //the second will be the color9 m, ^4 e( e& l7 x' e
AttrNameListToSet [compt-1]->Append("COLOR");
! u+ _6 w+ L& i V5 k( x2 d0 f8 Z CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
5 ` I% g/ ^2 L; E' C# Q( O AttrValueListToSet[compt-1]->Append(tempcke2);
! V5 Q& S: ?5 R V# T & u, w9 y: ^3 }8 J$ w, E8 P& R! V: Z, d
cout<<" COLOR with value Red";7 c$ A/ q$ F& x8 F. w$ }2 s/ N
0 h. f' V: U: l$ g+ R9 J
//the third is x
4 E4 t9 M, r) M t9 D% M; ]' \ AttrNameListToSet [compt-1]->Append("X");& F/ P+ \) v) S: d; |2 H
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);( w L6 T: p O: k" W; g6 I5 u( k
AttrValueListToSet[compt-1]->Append(tempcke3);
4 O+ A( l! J! k9 }6 ]
5 F/ s, {0 P$ n, H! \0 g g) B cout<<" X with value "<<x;9 t( \. H) j- N5 E& K
cout<<" for face nb "<<compt<<endl;) ?' M- F* A8 Q
}( _: ^# J0 I# w1 I) i
else
7 d( g j2 ?; |' @. _2 }+ y: N //just to show you you can have different size of list
- F# e5 I1 b5 D4 \ {. G: \$ k" X( _
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);" K1 O0 @5 W5 K
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);8 \$ P$ K9 T/ O4 ?* r" X2 }
, l% F% M0 M+ y0 L
//The first attribute will be the number of the face
9 j6 J1 } _- c AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
$ z3 a, t3 n; A0 X7 R CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
+ K" ~3 P, Y+ G AttrValueListToSet[compt-1]->Append(tempcke1);/ C' o3 k, v$ n1 e
% \4 t! q9 J8 W; J
cout<<" FACE_NUMBER with value "<<compt; ! n; z. @! w0 B7 R3 K4 N ^
" V' M5 s5 |; J$ l: l/ z& r
//the second will be the color/ S7 r+ }7 }. t" I) \ \
AttrNameListToSet [compt-1]->Append("COLOR");- q d9 u0 D# a
if (2 == x)5 p& |" F2 N! e5 J2 A: N
{, e& ^ F5 x' O% n4 Y# W5 }% P
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");2 @1 T) {5 W M8 y5 Y0 N
AttrValueListToSet[compt-1]->Append(tempcke2);5 m- d; ^7 ?, s& A% ?8 n2 ~
. ?) d9 q6 k" Y x* S
cout<<" COLOR with value Green";; Z' t2 d8 w' T* p9 {
}: B% d1 e6 l0 Z% p+ N, y
if (0 == x)
' F9 ~% B6 [ |9 E& w {
3 ^6 x; x. s) w1 H CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
8 F) w6 ]& p0 a$ W AttrValueListToSet[compt-1]->Append(tempcke2);7 v: n: `. g6 w! G, G$ v
8 B7 C. v4 W4 E9 }* j% K
cout<<" COLOR with value Blue";
6 L; t% l3 x- ^3 U4 V y9 a3 p- D }
% ]9 S! t- }( m1 X# X* j1 r
& [& a# r" D! p* x cout<<" on face nb "<<compt<<endl;
+ R3 f. q( Q) A8 P
0 y6 ^6 l: d: s* J$ a/ h }
3 C! h3 b J4 Y* \5 Z2 Y4 t }
$ `! Q2 I9 `' h# C, H5 c4 H& W R
* E: J. {- H( S: R# C) r5 f: c$ c( R //10 - 2 Setting the applicative attributes
+ g8 o+ n @ L# ?+ N cout<<endl<<"Setting applicative attributes on different faces"<<endl;! [9 z/ {6 L2 V4 m0 Q$ l: q' ?
FailedIndex.RemoveAll();$ D$ _% F3 j9 E0 W; E- J" [
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);5 u6 F" B5 _) ?" o$ s
if (E_FAIL == rc)$ E; r- j$ n0 }( c5 u8 M
{4 L! b* i5 W, H2 U: g& o
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
- x9 L G; X# a6 p; V }8 G* D: z+ h2 v
else if (S_FALSE == rc)
; p" y( g( s# e$ r9 s( l {
2 L. A3 L0 F4 E% @6 K$ {4 ~( T int nberrors = FailedIndex.Size();
1 K; O9 D$ [; W6 M# b) q cout<<"Error, setting applicative attriutes on faces fails for faces :"; V. ^" u9 G: V+ L
for (compt = 1;compt<= FailedIndex.Size(); compt++)# d: m t4 F: V5 m
{
: c5 i. O" U9 D% [ cout<<" "<<FailedIndex[compt];
3 x5 Z7 I, m2 d {" B: w }% K6 k+ k% Z" D# m8 k& m$ I
cout<<endl;7 x ?& l: X$ x _8 c
}
4 H% w* f0 o( r- X$ r' t else: @. k, M' D- n+ A
{
) o* ?+ t9 U0 S cout<<"Applicative attributes successfully set"<<endl;# G2 v$ t& h# V! V9 ~
}
7 M! F, ^' J, v5 i+ K: ~# M0 T, P' y& w: v4 K! Y
//10 - 3 cleaning, a; n3 \( g6 T, Q( {4 ?
for (compt=1; compt<=nbfaces;compt++)- H6 Q3 ?; j) C; Q0 |! T
{$ r1 g6 {; T. g- G/ [8 F; y. g
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;, o: _4 ?. A) F+ \5 U8 B) T
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;& X1 s& ] z4 r' _* r9 o2 {; x4 M
}
' o: X* K! |, Q* T" k# z* Q2 n p. P- z$ G
delete [] AttrNameListToSet; AttrNameListToSet = NULL;1 {, |8 c; I: Y; p
delete [] AttrValueListToSet;AttrValueListToSet = NULL;/ q& }7 ~, b5 k
! m, g& \7 ~( z6 R0 Z //
& D- t! e: u3 ]6 v/ o //11 - Retrieving the applicative attributes we have just set
7 F6 w# u0 D0 m" ~& v5 V! C! a //9 [( ~& q2 m' |. A/ ^
cout<<"--------------------------"<<endl;
- h p. ]- k, j% t' p cout<<"Getting applicative attributes on faces"<<endl;% a8 O' h3 G7 w
//
5 S8 T% N3 L8 m! f5 V, P //11 - 1 Getting attributes
7 D6 W' X, f! R8 C1 E, o CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
+ r' J$ Q* J% q CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];/ O1 V2 u( C! n+ J
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );# U& ^4 B, X/ e8 L' V% G0 N: X
if (SUCCEEDED(rc))( v" c5 x8 d" X9 k& ]- Y
{! J( _9 B/ ~' h; z i
CATListOfCATUnicodeString templiststring;
6 j" O' t. J+ M) p1 D8 ] CATListValCATBaseUnknown_var tempCke;$ U4 i& M; Y' D% t9 i
for (compt=1;compt<=nbfaces;compt++)
. H7 v" ?& Z2 j5 l( V, G5 m! Y0 d {8 g7 H2 }. }# ` V. d
//retrieve a list a position k (arrays start at position zero).
' w8 d6 u. @. } templiststring = (AttributNameList)[compt-1];2 c; {* \' H/ `% e1 |7 A
tempCke = (AttrValList)[compt-1];
( O7 C2 i9 |3 |; F# z
1 J6 y* k- y" \; R2 s$ @ int nbAttributes = templiststring.Size();
, t" H* e% M7 j7 j" n1 H int nbValues = tempCke.Size();
: Z! V7 K4 ]( j+ ?4 G2 v, z/ q! I9 x
//the list must have the same size! If not, we jump to the next face1 {0 d8 I, N0 _$ c( y. `$ J
if (nbAttributes != nbValues)' P) N' y0 \$ {' w& f" t4 e/ D- B/ y
{
, M, Q* r3 w( I- Z) A cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;) g6 b6 V* ? W
continue;7 B$ v( j, O, G& v" ~; \
}
# F- B5 R$ W; F/ T else
2 x4 e- l6 r1 i f+ N {
9 K( v2 u0 y9 \+ I! r4 \ cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
3 [6 O5 ]* o& ]( a t+ a }7 Q& h/ Y# y6 r5 m9 a* H4 F
for (int i=1;i<=nbAttributes;i++)
* M! u: H: Y9 g- \# z+ Z7 D6 q {
* Q# d+ v$ D2 W) ?1 T cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
. v# i* U& h* R# ^# k! q }# L( P. S( M m; Y
templiststring.RemoveAll();$ E( R: x0 d# U! B1 |
tempCke.RemoveAll();
+ e( N1 F4 n; F v/ d$ z" m% J0 u5 r8 S
}
]4 }) A! o; j }
5 `3 n' A1 w. _! }+ Y l0 ?, J else if (E_FAIL == rc)
( r1 n ?9 I9 b' P, |' _8 M4 @2 }/ z {
0 z, O \1 ~6 V6 R/ v cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
' N5 g7 n0 v5 ~1 @& b n1 W return 1;' r2 [- b. K0 w8 e, i0 o
}
. o$ k5 X6 a, [) \' W5 v // `7 ~0 c V" b% W3 A$ A9 X
//11 - 2 Cleaning List: p% E7 T B: S. H8 r
int i = 0;6 t: z3 d, A! c
for (i=0; i < nbfaces;i++) a0 \3 W0 C0 C* K' B" A0 T- h
{
6 v, D" H0 B2 Z! _* f AttributNameList.RemoveAll(); m U. k7 @, A) @: u9 z/ ]" J& P7 W
AttrValList.RemoveAll();1 P* A; J9 s+ i3 P: Q! k% A6 X$ f. Y* W
}$ N9 ^2 H' \5 u( f) H: ]8 L
delete [] AttributNameList; AttributNameList = NULL;
! } a3 w- `3 h' I5 k; p# H delete [] AttrValList; AttrValList = NULL;
7 b+ l+ ~3 v' |2 \5 h' X# V r7 V$ [1 ^1 {6 ?* v8 J
for (i = 1;i<= nbfaces;i++). v- B" {& y9 z5 m* o* n! y- D
{
3 u* q1 c; `2 E/ B Brep = ListBreps ;- P, J9 {- M( M( e3 |5 W+ V" ~8 Y' B/ g
if (NULL != Brep)9 k' B3 u; D* g5 F3 ]; \+ Z9 |0 F
{$ s4 r% d6 [- t# o5 y7 R- f
Brep->Release();+ r* t. p: H% u2 z/ X! O
}) A# P2 q _; o7 y" Q
}
$ \8 }2 V# g4 c ListBreps.RemoveAll();[/mw_shl_code]- x' z, B& D! @6 Q! V
|
|