|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]+ q5 e0 J$ S6 W. _
//
/ r1 ~. r! d$ R7 Z: j6 R# O8 F v //7 - retrieving and displaying current faces colors/ D7 e, x1 f" I9 Y8 M* j$ _7 {
//
" M* Y2 G6 D. h8 h cout<<"--------------------------"<<endl;- A% ^! Q& x/ r! u
cout<<"Retrieving current colors"<<endl;
5 U" }5 \9 s5 W' O CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;( I3 l9 {, O9 B
; B5 P5 w5 Z. ~. T/ C" T rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);8 E0 ^( s1 P+ y" F! A; n( w
if (E_FAIL == rc ), c5 a& q* e. K- l
{! c3 D* f" M4 U: j2 N
cout<<"Error, an error occured while retrieving current part colors"<<endl; E: }- [2 s0 u; j8 ]
return 1;) a2 m j4 C8 O+ J m
}
9 v, |. F# s( R0 {6 |; }
! t( W% }' A# i$ f m3 |! ~ for (compt =1;compt<=nbfaces;compt++)
# ^/ R7 E6 N7 V7 o7 ` {
9 |; }) k, I q1 t9 J9 T cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
" `7 _) E( P0 f: K }, E O4 K' I5 u0 Y! s# @
# u0 Q. }- Y9 ^ //
# o' |( e2 p4 [6 g8 `$ g //8 - Setting a new Color on all faces
% u4 d( I6 c1 h& o- g2 t //
) L# N/ N k' V7 g- O* B4 ?1 k( g% r2 P9 S
//we are to color the faces with different color according their position : three by three will have the same color
6 v* j& K4 R% A } cout<<"--------------------------"<<endl;
& \& L+ b, t. J% }6 X( E cout<<"Setting new colors"<<endl;8 o! L+ ~1 ?! L8 @
& x* X3 M/ f) |0 P( r
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
2 j1 Z1 D) E- \: V int x=0;, ]) t9 q. Z$ J N. l( ~/ p
for (compt = 1;compt<= nbfaces;compt++)# q' o% L" o- [, r0 Z, x% C# A
{
+ T1 c% o5 t5 S8 p' q9 y& a/ | x = compt%3;: p" ]' M2 i' M3 k: p }
int red(0),green(0),blue(0);
* k* B' P+ F8 q. z V! |& E$ Y if (1 == x)5 T) F: m+ Y% L2 l! a7 W/ j
red = 255;8 S- V- i" T: E7 R8 U
if (2 == x)
! W" q; v+ |' v3 g: w# u green = 255;5 E$ I# [+ ]3 r# f
if (0 == x)
+ x1 o' c8 B: r* p$ G" \ m9 l! ? blue = 255;
3 d! W3 @7 _1 u* o+ Q newRed.Append(red);' B" W: ^& W" J$ Z5 F5 X
newGreen.Append(green);9 b; b( \) n @( L
newBlue.Append (blue);/ D0 U5 m4 i1 m. A: Y& ?$ q
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
8 J: c. \3 q+ W) a3 F9 L, @ }
+ v% K9 D: D$ \/ [. \, ~7 I4 W
& o% Q- _3 W, w7 l( T rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);, r* H: j* ]& _9 q1 K
if (E_FAIL == rc)7 x8 z; O- t7 y+ t1 W$ X% t
{
9 i) k9 s* X6 _3 s cout<<"Error, setting new color on faces failed for all faces"<<endl; {. Z) r# Q6 l/ g7 {4 c* L5 W
return 1;- k- G( E4 b4 _- }% L' O
}! S1 ?3 c& t5 |
else if (S_FALSE == rc )
: }5 T; G6 g' G6 ]! Q0 Q {
+ x4 c1 _6 z8 j( H, Y8 |% C int nberrors = FailedIndex.Size();
- @/ Y1 h D9 n( E2 t/ d cout<<"Error, setting new color on faces fails for faces :";
+ z. M3 [: ]) | for (compt = 1;compt<= FailedIndex.Size(); compt++)
6 \% `8 b, Y* Y4 { n+ x {
9 z# f! P- D; p' w cout<<" "<<FailedIndex[compt]; R% U% W0 T- w9 b7 p
}
8 v* Y9 L. y6 J" n" y6 q cout<<endl;
_; ~5 e- V. v/ G% Z }
) {) S( C4 m$ l- ~* k else + W. ?, I# d( x; J( Z* P% B; ^( I$ ~
cout<<"Colors successfully set on every faces"<<endl;
# h+ b; p8 b) W3 m; V3 n //, m; Y+ G; {* y- {
//9 - retrieving colors we have just set
: N; @1 J* I* U) K //% N/ ~4 x3 p9 ?) {
cout<<"--------------------------"<<endl;
. H& w& X: L+ M5 b5 I cout<<"Retrieving new colors"<<endl;
# b) Z4 X: z; V rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
& S- _7 o9 r- z# v if (E_FAIL == rc )
2 i, n: t& y1 s; k/ `) L7 B {
" E* D2 H3 Z2 c cout<<"Error, an error occured while retrieving current part colors"<<endl;, G: V. m9 I+ j) P' J9 Q" S
return 1;
6 A# w1 G S, B }
" \7 ?: i! s; y4 {1 W! K9 ?' A% x1 q
9 U! s" L) n8 Z# B3 k% ~ for (compt =1;compt<=nbfaces;compt++)2 I0 L) p$ {9 M/ D' g$ b" H- k
{
4 Z$ J0 m- }* R5 ?! Z2 J cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
3 G7 D1 a/ B/ R$ D0 \1 h" @ }, \: U8 Q; m8 O7 T% @' N2 E
6 m* Y; o, b$ t) g$ i% m' e# ? //9 _- h3 q! r% K: r: p2 F
//10 - Setting Applicative Attributes! I: I9 J, I' M& R3 N+ g
/// _: `1 K% b( l5 N' Q
0 K3 @* L' w; k8 ?. F9 p \8 c //
6 r: F. N% t* s4 ]4 k1 R //10 - 1 creating new attributes
3 x4 A" i9 ?2 [, \ cout<<"--------------------------"<<endl;
; O9 e0 R. X0 s1 c3 u cout<<"Creating applicative attributes for different faces"<<endl;$ }9 s9 B. {! @
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
* X6 p% J! w5 v" V5 i# ]8 g8 W CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
# }; I6 a+ x; {2 y2 m CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
c- e! t9 A; F6 e" V' R for (compt = 1;compt<= nbfaces;compt++)
" [- g# U7 t" V; l4 B {7 ?; O; o& ^! j( h M
cout<<"Creating ";& P6 W3 u" P: | `7 |9 X8 a/ t3 L% K
x = compt%3;; O$ w# U! K' _3 ^4 L6 G! T
//for each face we create a new list of apllicative attributes+ A; Z1 \' B' o n$ D' z
//an applicative attribute is made of a Name and a value$ a6 P9 c6 \' ]
if (1 == x)' `( a$ p- G5 u$ ~, F: }% l1 K/ D9 s
{% u% n# _2 o7 _7 {
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);$ |$ \' D& Z; i1 y" ]" E
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3); X) W5 {+ G! w9 V2 ]; Y1 A
# l. ?' w! P, x, U& d
//The first attribute will be the number of the face) p/ Y$ J% Z- _) a; L4 x, z
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
0 Q- N' z/ o8 P6 Z2 c CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
6 {5 K7 P& z' I) \) Z AttrValueListToSet[compt-1]->Append(tempcke1);
/ p7 _4 ]+ F/ r( B" s9 Z) v7 Q. p " l. S/ o* A" g" ?5 S
cout<<" FACE_NUMBER with value "<<compt;
7 K/ I* f8 X) m( c9 Z( v' L8 p5 V/ Z. m8 m3 N# `, D. g: D+ J9 l
//the second will be the color
6 N9 V+ P5 z$ Q% ]( h8 v* {% X AttrNameListToSet [compt-1]->Append("COLOR");
( z H2 ]$ U8 e+ k4 h CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");5 v' ]- \$ r+ m t1 H8 x& U
AttrValueListToSet[compt-1]->Append(tempcke2);
! G+ [. B q4 h2 o2 k4 ` ]' G* M6 G, C) w# z- U" R
cout<<" COLOR with value Red";
! a: N3 N0 W& [
6 k, C6 X. |8 ~ j! F //the third is x9 r0 o+ |. W* C8 c6 l% w: i8 S1 u
AttrNameListToSet [compt-1]->Append("X");; n- A7 T. g) O7 b7 Q( U
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);5 j( Q6 @, Z) T" f" T/ g
AttrValueListToSet[compt-1]->Append(tempcke3);, r! g: V& S; G
?* M7 }; |0 ~; v8 m* X8 \# U cout<<" X with value "<<x;1 @' P) `( h, W0 f$ D7 W
cout<<" for face nb "<<compt<<endl;$ F7 b6 l) R0 @2 G
}
# Z( C0 I+ s( |9 { else ; q1 X! D# e, H R& f
//just to show you you can have different size of list
- }/ J! o2 i* C! ]" G! y {
' ?& k5 n: W" O' v# ]0 u AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
6 g/ l, U( n+ d* s7 f0 D AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
- H! s b/ ?4 ^$ F6 X- g. ]" v0 p/ t' D7 X
//The first attribute will be the number of the face" `: x1 q: }; B4 O7 d9 f* n. D4 b
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
0 b7 r& ^# P& u CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);( p. \& A2 S5 q% N! t
AttrValueListToSet[compt-1]->Append(tempcke1);
# I- e' C" X2 o+ o/ c4 D$ s9 Z: G' a# ?. |6 B, O6 ~/ L
cout<<" FACE_NUMBER with value "<<compt; ; l1 a6 f# Q; s" N
3 V) c2 m' Z$ \" ]! h& B) P1 A+ u //the second will be the color- E+ o+ V$ ]0 P& B
AttrNameListToSet [compt-1]->Append("COLOR");
/ {2 u0 X, N6 ?: a: A if (2 == x)' g& T0 A6 f: r& E) \
{# s( Q, L8 Z8 b* t1 q# K( N9 k$ I
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");0 ` g& t1 V% ]& {0 l. {3 z/ W: F
AttrValueListToSet[compt-1]->Append(tempcke2);; [1 a" e2 ?5 }; l: S
8 f- I; |1 G1 R+ b6 \" H cout<<" COLOR with value Green";4 \) }+ }4 P r* o
}
6 V7 N8 Y9 |, [2 a3 A4 X7 H if (0 == x)
1 T4 w9 I; A( y! s: A7 M, x9 ], d6 k( J. H {
2 @) r) p ~8 z7 e: V* r/ T6 Z6 \: [ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
, Q7 c ]. V/ W AttrValueListToSet[compt-1]->Append(tempcke2);
& z' }( ?( c$ g 4 s; x1 i; O* k* p: j6 K
cout<<" COLOR with value Blue";
4 _# l4 q! K, u6 z9 P. K }9 A5 k$ U0 @5 g/ G/ W: d5 _6 B
2 f% \9 r6 m) v7 Q/ g; S
cout<<" on face nb "<<compt<<endl;
1 X9 [. v) P. ?( T# C7 {4 L B8 r! x ^9 y: ^
}
( B* W( M2 W) @ }
F3 X6 v4 `- ^7 z1 x4 Y7 N& ?! { t9 A* {2 Y" T+ H. O8 Q
//10 - 2 Setting the applicative attributes- Y9 s& X, J7 v+ S; D, d( Y
cout<<endl<<"Setting applicative attributes on different faces"<<endl;" T" K6 S& m( b' E
FailedIndex.RemoveAll();: m% j1 `1 s, d% d
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);1 N1 p: @" Z& w
if (E_FAIL == rc)
) j6 M) L( u w5 ] {$ h, h' q- G0 u1 h. G
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
9 q2 n! N$ j3 D' _ J }1 P4 m4 J- j, E" y; N$ f
else if (S_FALSE == rc)5 W$ T/ P S/ g' M; W3 d) Q
{& s: S9 v( ?, A8 @
int nberrors = FailedIndex.Size();8 g# ^ \: l2 k
cout<<"Error, setting applicative attriutes on faces fails for faces :";
+ B8 h* m; o+ d+ L; y for (compt = 1;compt<= FailedIndex.Size(); compt++); I6 h8 J8 U. B/ V7 W; z9 H. ?
{' j* f/ I4 G3 u8 A- X
cout<<" "<<FailedIndex[compt];' G1 m3 p% L- C/ i& i, A
}; F" ]; i) [6 {. e8 p1 s
cout<<endl;
S: ~7 U7 _0 H }
4 ^9 d. Y( e7 d4 S7 ~" F else4 ^2 N+ E, D4 F |- O( ], F9 T' k
{) ]2 t# W- v* d3 }8 P0 z( d' \* g
cout<<"Applicative attributes successfully set"<<endl;+ o& S( G+ o) K0 x) [7 c# X! t
}
9 \" S8 @! X( g( w! G) f- @! Y( b9 d) `; [5 v
//10 - 3 cleaning0 ~: F/ C3 u2 J* d
for (compt=1; compt<=nbfaces;compt++)
6 a9 p. M: m# K) e2 ], t {9 b7 I8 m* Z c
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;, U! O# n+ V( ?/ Q6 ^# _0 w
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;* P0 B! I# g+ i8 L
}
/ Y1 L4 u5 d- s1 }" I
9 P2 W3 @- A* W2 x delete [] AttrNameListToSet; AttrNameListToSet = NULL;, a( G0 U; S9 _' m# W7 G N5 F9 l
delete [] AttrValueListToSet;AttrValueListToSet = NULL;1 R* L3 C; c, Z. w& _! j5 Y% p
5 v0 y. W- ]0 }# X% f
//" r0 X2 z( W; j- t) [! e, |
//11 - Retrieving the applicative attributes we have just set
. W* e$ [* |1 {9 x2 i //6 [( b0 D7 \( g. I
cout<<"--------------------------"<<endl;' H2 D# l6 H2 F8 l0 z* Y$ @
cout<<"Getting applicative attributes on faces"<<endl;
7 _# W6 p8 O: U8 B4 ]$ Y //
) z" V' A; X1 l" `1 H( { //11 - 1 Getting attributes
- Q+ {2 p% P8 l$ w CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
F" v( ?/ j; b; b/ f& ?+ n( z CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];# R* _. P" d+ R0 Q7 q4 m! ?: f6 z
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );2 x) l& ^6 l" Q2 {' u* d
if (SUCCEEDED(rc))/ J8 x! \* a- S9 u8 @, x
{
- o# f. S6 G/ i- F2 {/ z+ x& z% \ CATListOfCATUnicodeString templiststring;, q6 G4 b( C. a7 P) h& O2 e
CATListValCATBaseUnknown_var tempCke;/ g q H( ~3 V& d! X2 }+ G% X: s
for (compt=1;compt<=nbfaces;compt++)# y; p; f6 w" Z4 ~3 e% b1 \
{7 g: J0 T, s% q; A% U3 h$ l5 o' f
//retrieve a list a position k (arrays start at position zero).
1 w! i3 f/ h8 D0 C templiststring = (AttributNameList)[compt-1];
, I+ t# @& q/ g A7 R tempCke = (AttrValList)[compt-1];. c8 d, R3 `- @# x/ J# O
6 \/ ?7 n7 h% Q- L6 S int nbAttributes = templiststring.Size();
' t9 g+ d$ L4 K int nbValues = tempCke.Size();
+ ?$ |/ B& b8 e3 O+ O( j
3 d2 q& j( P0 q8 @% ]& P //the list must have the same size! If not, we jump to the next face
% Q. r. d) D2 e5 ? if (nbAttributes != nbValues)
& p5 w: u, u2 W0 g- Q$ a3 x {
- e; e6 X# P5 s& A7 u cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
" d |* e( J3 @9 Y continue;1 z8 v3 ^8 G; U8 T) Y
}
5 T) \5 Y, c* }8 F8 [' t. w, d# q else
2 n' Y1 O2 T) C; x! | {7 J' J& C0 X H$ u5 x
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
9 F! D. m& F/ @6 V }& G1 E, R v; ^. m
for (int i=1;i<=nbAttributes;i++)
, h+ W- [6 n" e% d) ]& C0 X {$ W0 n6 R+ x, A/ f# U7 g l
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
" ^. k) F" ^' i7 L }
9 g) I* Y( y: e- G: G- U2 { templiststring.RemoveAll();1 V1 ]; A5 M/ o! r
tempCke.RemoveAll();
4 _5 N5 q; a8 _) j, X9 {! A, s" T9 O9 I
}
4 i j* {% P2 G$ V, e6 k1 d }6 |2 d' [2 p8 b* u9 n, @6 E( I
else if (E_FAIL == rc)6 |2 k+ i) h) O. e) k# T3 \; m
{, N- ~2 h' _# f7 z6 b
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
1 _. G! c! @- X7 P Y return 1;
1 D a. K I9 z1 e }# @1 u$ T, O6 ~& d( ?5 S( G
//
( C$ n2 z t4 h; s2 O h //11 - 2 Cleaning List:
: A6 s( X% |9 D8 |( Y2 U int i = 0;/ d( {0 H+ x2 z& [
for (i=0; i < nbfaces;i++)
& d( u; H/ b: P. _8 u {
3 {- U, r0 D( ?, \% L0 S7 W AttributNameList.RemoveAll();8 H R0 ?4 E) n9 G2 Y
AttrValList.RemoveAll();: h' B1 N' ?! r
}
1 M. {1 @# u3 D( d5 R- m delete [] AttributNameList; AttributNameList = NULL;
4 W3 Q: A* ]9 c delete [] AttrValList; AttrValList = NULL;
/ H2 v& l$ V8 ~1 C2 k; K' w% i/ B, v2 Q& O7 W# J+ a# n& O
for (i = 1;i<= nbfaces;i++)2 O8 T, { Y3 P- l9 E8 z6 f
{
2 ?8 d; x, D7 z1 d3 I+ s) ^ Brep = ListBreps ;: G1 X( F% H9 a) h7 w0 H- N3 }
if (NULL != Brep)( u2 |6 P; C0 M1 X0 `
{& y! a# v% y) f. L0 }
Brep->Release();1 n+ i$ v# B% h. L- U
}% \( u! G& I. _+ u: L, `& s9 p: l: ]+ H8 _
}
! N0 z: o- L# f' K7 J/ v ListBreps.RemoveAll();[/mw_shl_code], p( U* d: j2 v g' Y/ N- c8 |
|
|