|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]% `* G0 X' f% }# u4 v0 g
//
" X: p. L8 u9 t- W' g //7 - retrieving and displaying current faces colors
3 L% ~& j8 N* Q: w/ \% C& ~ //" d: C8 h' S# p0 p1 l) m5 x* M
cout<<"--------------------------"<<endl;
2 I5 w8 E5 u4 r+ N3 g, [ cout<<"Retrieving current colors"<<endl;
9 c8 Z2 A m* ?: ^, H CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
; H; R/ {1 y) z6 {4 {/ g 9 @) Q1 W& G5 M) A4 x9 z' F
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
2 _. I! M: ?. Z& m6 S if (E_FAIL == rc )& K4 m+ h. f& K+ W$ x! L5 o2 W
{0 U$ H$ P: q* h5 P( W
cout<<"Error, an error occured while retrieving current part colors"<<endl;
+ D5 V' x& y' c8 C return 1;
& @, h: W5 Z: }4 ` }
( ~! S( q4 ~: C. ^4 ~1 O8 M
/ L/ o2 Z& C0 ^ for (compt =1;compt<=nbfaces;compt++)
9 e+ b3 K( n; d9 S) W$ o {
! x1 T0 _" X9 P2 O6 I cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
$ D" v+ Z& [6 M! y$ D }- H; d9 e2 |% c) l
& U0 v2 D: {2 }1 Z //8 H3 e: O' V2 w
//8 - Setting a new Color on all faces0 J( ?7 a3 h1 D+ F
//
& u: I$ s5 x9 h* {5 C% N: x% {* e
! D8 V1 `$ z0 |! z2 B% e$ z //we are to color the faces with different color according their position : three by three will have the same color4 Q: I. b0 ^: f: x3 ^ |
cout<<"--------------------------"<<endl;
( W" n6 U( E4 E/ W cout<<"Setting new colors"<<endl;' Y% ]$ Z+ ^. A" w* |
# c5 P0 y) F9 I! A* x* y CATListOfInt newRed,newGreen,newBlue,FailedIndex;2 ~" i8 |1 W5 x9 b* E0 p
int x=0;
4 H4 U8 Y: k' F2 \3 X+ m for (compt = 1;compt<= nbfaces;compt++)' Y( ~$ P/ J6 e5 g5 J, [
{5 V I* R1 _' M7 I4 k
x = compt%3;9 `) y/ a: }; f: ^
int red(0),green(0),blue(0);; I6 e3 E) X' C3 z* K! u
if (1 == x)- n* v$ k! Q" T# f
red = 255;
, |! I5 D: a5 w# J. L) G if (2 == x)
# s6 C+ ?. ]1 Z8 Z- E1 p. f- G" U* V green = 255;
! r* S; w' Q& G9 v$ i3 Q$ I5 s if (0 == x)9 g$ W( R0 V% t k. n4 d6 L
blue = 255;
+ }! n6 ]: j; }7 O+ e newRed.Append(red);1 c' E: Z/ r2 `( Z8 l( Z4 l$ f) d% y
newGreen.Append(green);
& h8 i/ `0 ~6 t; Z4 y newBlue.Append (blue);8 p) E1 O. F4 g: d
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
8 V4 m* D; r! i- m: i" s" i }
5 y( j1 H$ J, d8 J; H. k8 j% g( ]: I4 H* S3 X
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex); E, ~$ t+ X. A! i& B" [+ J* n
if (E_FAIL == rc)
) D5 {# g" m! D' O# Q) {' P {( W& I! A2 e1 M, q3 F- p: @- [- b3 {
cout<<"Error, setting new color on faces failed for all faces"<<endl;
/ Q) j; W8 \! T3 O return 1;5 V3 ]; G: q. D3 T! E1 \. Z& Q
}" j+ W: d' b) ?! X$ x
else if (S_FALSE == rc )/ V+ S* p& H; M
{& Z% W9 c+ k; \. }
int nberrors = FailedIndex.Size();! U0 F: ?" h" W: c! I( }7 m7 B- `
cout<<"Error, setting new color on faces fails for faces :"; V& @$ X W; f) _! L
for (compt = 1;compt<= FailedIndex.Size(); compt++)
$ _' k4 _- d" F: w2 B' ` {
* q* Q5 s+ B5 q) q cout<<" "<<FailedIndex[compt];* Y. z! R. T! B$ M: g( x
}+ U$ D0 N$ X4 @: C) h# C
cout<<endl;
/ v7 [& c( Q, d' g) T3 R2 C }
" e! x9 q" x$ b7 |7 e else
/ Z/ w: H2 d3 m4 [ cout<<"Colors successfully set on every faces"<<endl;
5 Y8 [4 ?8 s, u: |' F: o8 {( K //
: }! H ]3 U" g" N* i, \ Y //9 - retrieving colors we have just set$ }+ Z0 q+ h, ~ j) e
//
/ c& _2 W7 p0 Z cout<<"--------------------------"<<endl;( e# C$ Z3 W3 }9 f+ q
cout<<"Retrieving new colors"<<endl;
0 N& n" H( n" `5 o0 {5 L" y0 q rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
* ^4 q g& t4 I! [1 y if (E_FAIL == rc )& v% u7 M3 L" m( T( ] r
{
' n# i( t4 X: C: } cout<<"Error, an error occured while retrieving current part colors"<<endl;
" W$ U+ Q; ^5 Q6 ^2 ]1 M" O5 M3 x return 1;
, p# W" L4 w2 _; A! D6 y }: V% H- v& p9 {3 d5 X* ]. H& n
8 _$ @8 u1 d3 Y$ L. ^' _
for (compt =1;compt<=nbfaces;compt++); f* D1 s7 K' ?5 ]; f+ n: ?
{1 \, C% P! ^; A1 B
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;7 d$ ?- k: d7 ^ X3 s
}1 p) p: }4 K. z, R% F
+ H: b0 C( z) s% s# U5 h* A
//
- N; S$ R" f8 H8 G z# n0 T# S //10 - Setting Applicative Attributes
0 O8 B% I4 t4 {* i! A0 y4 Q' y //: {2 B" h3 V" M& a
! y0 ?% c5 g6 ]) ? //. S, i+ z8 F0 k
//10 - 1 creating new attributes
J3 F4 J. v, u# ^0 @+ t8 o) d- I' T cout<<"--------------------------"<<endl;
; y5 R, G3 {3 j2 M, Q cout<<"Creating applicative attributes for different faces"<<endl;
, e% W. B0 l9 h CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];' ^7 o- e& P8 f/ \* R/ @
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
7 O* F; E0 Y3 B0 t* e6 H& b: c Q7 p- d CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
/ m" w0 D/ {8 k2 w for (compt = 1;compt<= nbfaces;compt++)
5 v+ {. B3 {/ J4 B" |- Q+ [$ Q {9 v+ W+ b2 N2 n0 r. V. ?
cout<<"Creating ";
0 y7 k1 [( d- w+ D( O x = compt%3; V" w+ N8 N$ G/ {
//for each face we create a new list of apllicative attributes& m. J) D, E- Q h
//an applicative attribute is made of a Name and a value
9 t4 N o: x2 {8 g2 _ if (1 == x)+ h& P& Q6 G% x+ C
{
9 z1 ~! a: h( T7 } AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);8 }! \* w% f' e. `: u
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
* C) ]! C6 |3 n& X+ r+ _6 w) v0 Y2 }6 _/ O$ @+ T6 v% t
//The first attribute will be the number of the face
" T, _7 X. ~& m6 \$ \! M AttrNameListToSet [compt-1]->Append("FACE_NUMBER");0 o1 M2 ]3 O/ b$ L1 t7 @
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
/ y5 _. ~( d6 Q0 I AttrValueListToSet[compt-1]->Append(tempcke1);
' O; e6 P; D! G: D
% l" j& z4 {% _! `( |0 G cout<<" FACE_NUMBER with value "<<compt; ) X7 b( o3 A1 G0 F/ f" K
4 l+ |# h" l" d; Q //the second will be the color
M% { u2 {2 K {. }/ Z3 Z' J AttrNameListToSet [compt-1]->Append("COLOR");
" [2 s4 F" A+ A+ t" U( @8 W/ }5 \ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");% D" k, h, w: b9 W2 H1 n3 E
AttrValueListToSet[compt-1]->Append(tempcke2);
' v# m6 Q! o* F* ?$ W+ N8 }% x# x' T 1 b `( i8 }. ]
cout<<" COLOR with value Red";
% W+ O, H* F4 ?' v! J. R
" j5 w! {$ d8 r U' [% s //the third is x4 W5 m/ q; G. v- Y! e' [1 b/ q
AttrNameListToSet [compt-1]->Append("X");/ b1 h3 f/ r4 f5 M8 R1 w7 }5 @
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);/ E; ~7 v3 O* c8 Z8 e# B! C
AttrValueListToSet[compt-1]->Append(tempcke3);9 x, R6 f) H) \
: v* @9 V @6 I7 y8 d9 C3 \6 L
cout<<" X with value "<<x;/ ^) Q6 n# s) X4 r" g! E% Q$ p
cout<<" for face nb "<<compt<<endl;) d v: E2 I7 p3 u
}% Z C0 Y$ k i' A" t p
else
/ Y( V+ w5 e4 w7 ]: W O. S, d //just to show you you can have different size of list7 R( D; E$ H" e9 M
{( | k) P: ]1 C9 `5 f
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);5 \7 A0 y" K* U3 [1 Y
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);3 V S2 D, _$ {
- v& M: T1 H' y& o- w //The first attribute will be the number of the face
! ]4 K' H$ W% y( r9 f* ^( J AttrNameListToSet [compt-1]->Append("FACE_NUMBER");" |3 U) g3 r+ i U2 U5 o
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
2 c- @* T- Q% E AttrValueListToSet[compt-1]->Append(tempcke1);. u) O# P8 p) p e
0 W* `6 _) G6 c3 }3 c @9 C
cout<<" FACE_NUMBER with value "<<compt;
, m F3 [4 K7 |
8 A9 c7 K+ s# A T2 d8 @ //the second will be the color6 \) o5 y1 h; h+ r. K% R
AttrNameListToSet [compt-1]->Append("COLOR");
' i2 w" }4 @& i% e" Z) v. _ if (2 == x)1 D/ I' e' B9 l3 b% b
{3 D1 t0 f+ Y, h3 X( @
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
/ W- a) [! Q! y* t5 { AttrValueListToSet[compt-1]->Append(tempcke2);2 E/ Y2 R$ ]! M& z! n6 N
& J7 x; t& o5 T1 `
cout<<" COLOR with value Green";+ {5 e# N5 r3 n* _- \
}5 N2 o$ y* L, R( ^ E
if (0 == x)
" e2 I g- t- t! o% p9 _- Q: O {% v, u: J, p" Y- ?
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");6 T; b8 X0 L: k! W6 _% E p
AttrValueListToSet[compt-1]->Append(tempcke2);# T2 X) O- J: _0 r/ C+ m
) _ m1 y d& [ cout<<" COLOR with value Blue";* @" e+ M( @5 W' K* B0 V$ I# `1 L
}; V3 s$ q8 T# T' }
# H: A5 b4 @3 e* W cout<<" on face nb "<<compt<<endl;5 Q/ s# u! c8 z) F
$ I" o: x( i% f/ f! W2 x }
! l! \# |$ ]* M5 V% Z* a }
8 M) Z3 m, v. Z/ C8 Z) R( E, J# s) g# h- @: L4 H
//10 - 2 Setting the applicative attributes2 g8 {& \. U: N
cout<<endl<<"Setting applicative attributes on different faces"<<endl;5 o2 {1 `, d" I3 C: H) h5 L
FailedIndex.RemoveAll();
4 W* Q0 A; n- Q0 C' J) B* F rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
: V- I, p7 h6 y/ ~* L" V" l if (E_FAIL == rc)* D, a d6 r& F7 J' L: G& d
{1 S" e. T$ d; o! u
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;4 A% A7 ` D/ l r {
}# l3 B' x9 @' w' F
else if (S_FALSE == rc)6 q6 W+ \" `5 i
{
! ^) m4 n/ Z' Y% H5 B$ i int nberrors = FailedIndex.Size();
# r; R6 E' r& l: h$ }2 _' X cout<<"Error, setting applicative attriutes on faces fails for faces :";
" Q$ H* ~& V3 E! o- k2 c for (compt = 1;compt<= FailedIndex.Size(); compt++)( w, n1 @: K7 x' ]- j( }
{* [* P- l" s) ~9 h/ N0 D! k2 ~
cout<<" "<<FailedIndex[compt];
! W5 |; P3 Z/ `; V7 w }
8 ]& B u( v8 G Z. `% z9 |) @ cout<<endl;/ a3 k0 U& O; ?& c0 y3 j- M
}
1 z. x6 _- C5 V, l# e else7 Q; M5 O( s* X2 v* v* d5 z
{4 ~- F. C, ~; Q1 e$ Q$ k8 ]3 J ]3 u& A
cout<<"Applicative attributes successfully set"<<endl;$ F: |& |' ^" o
}
1 ?# |( l# l2 i
# S* m* u( X8 X# _( k //10 - 3 cleaning' q$ z2 y) E- ? U
for (compt=1; compt<=nbfaces;compt++)
+ z/ o0 _, x4 ` {' ~/ {' E) R$ Q S; i( p6 }
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;+ M5 |/ i9 Q. [( p
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;3 r9 r# {0 o" _2 q: G
}
/ u7 B! Y, t1 d& O. x+ G8 h& G. h& b2 B* V' R+ e$ G) f( a
delete [] AttrNameListToSet; AttrNameListToSet = NULL;6 h) F2 g& Q, J+ R2 H
delete [] AttrValueListToSet;AttrValueListToSet = NULL;3 D9 q$ i& D" u4 w# [9 q- _! g
( M6 t7 F% t# |% ?8 ~
//7 M9 Y f) D$ N. o" o
//11 - Retrieving the applicative attributes we have just set/ E m- D6 F3 H$ a; d& N
//
- l3 n# M$ l8 J7 `% y- k cout<<"--------------------------"<<endl;! }9 K. t/ [- q+ V
cout<<"Getting applicative attributes on faces"<<endl;. q) K7 a# [9 u8 L
//
. O& l1 P+ t7 h1 ]/ F( b( V //11 - 1 Getting attributes
, F7 v- p8 m4 z' e9 i6 ~ CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];. x: E, A( _( l* r1 g. a* p
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
6 Z, @1 q$ u- h* t+ z; ?' p rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );. H% R/ F+ n: X2 x, ?0 ~& z! x
if (SUCCEEDED(rc))
' t0 \$ [3 r6 K( u: [' C- T. c {
1 Z0 ^7 l2 Z! p7 u% J CATListOfCATUnicodeString templiststring;$ F2 `* T( @4 m2 t& d+ `
CATListValCATBaseUnknown_var tempCke;
& {) b% Y& q7 m3 U for (compt=1;compt<=nbfaces;compt++)
# a4 g: q5 Z( b2 u Y {
% }4 I4 u4 j4 a4 Z1 x! D //retrieve a list a position k (arrays start at position zero).
/ C; y6 w3 F5 d/ {' X' K6 [& M templiststring = (AttributNameList)[compt-1];2 p/ p1 U4 w' k, f2 i9 s
tempCke = (AttrValList)[compt-1];
4 |: w0 v/ ~. A7 Q
3 w, z- u F1 W, \% }: Z int nbAttributes = templiststring.Size();! ]0 q6 K0 {3 \% t$ m
int nbValues = tempCke.Size();
; c+ X$ [9 O4 c0 P8 z8 k% ?2 |/ `# r# k% S2 n5 X F) P' p% m$ ?# X
//the list must have the same size! If not, we jump to the next face6 J) R/ u1 i! H( @& M% T2 Y
if (nbAttributes != nbValues)
' b, x- @# y! C# M- J, l {- M: p0 c" q7 C. m, W& t; m1 q6 u
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;! J6 L8 l5 ? K+ I4 o3 K
continue;
! b' P6 K: M; z, w }
: j! P0 p& G. _; O) @. j, ]5 c: t else
7 r8 s X# ?3 U0 L. u {
4 r' Z; v9 m' W( O* }2 T cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;' A* L, R8 F2 K o8 r; L
}- T7 s) E/ o) a8 Z, p
for (int i=1;i<=nbAttributes;i++)+ j$ U% ^ S3 U
{
: l4 w( { z3 J# q; Z5 ? cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
1 S$ Q& y& y7 N }
# d6 G9 H% [. j, n2 T templiststring.RemoveAll();
, y. s, G- J& {- K- G5 \ tempCke.RemoveAll();
# Y" f2 G/ W" ?1 G8 }- s5 n: ~( V! b/ Y/ K$ }2 U
}' `/ ]4 j: t; u
}
2 Z/ ]& Q5 z6 C$ o6 O) V else if (E_FAIL == rc)% o/ F+ W- L2 i q
{# [$ J; H- j7 B. | I
cout<<"Error, applicative attributes couldn't be retrieved"<<endl; ?$ }6 T$ ]+ e
return 1;' J8 m& _( A: Y. u6 R6 r
}
+ D5 k! m, n7 O+ R2 m3 l1 W. k- _ //
9 S4 L! [% |# H" b/ l7 J' V6 n //11 - 2 Cleaning List:1 H. C/ t Y% }5 Y0 M
int i = 0;
7 i/ r/ w5 ^, h( M/ |! l& k for (i=0; i < nbfaces;i++)% ?) `, m3 Q" }- Z3 P8 u
{
d6 l0 P* I3 F) C( N; F' v' p5 q8 J AttributNameList.RemoveAll();: g ]. L$ n7 q. Z# z9 I
AttrValList.RemoveAll();+ c3 y& U) W6 U- A
}
( |9 k* Q7 Q# G, C j, Q* u delete [] AttributNameList; AttributNameList = NULL;
- @0 x" [( Y# h% N6 B& K delete [] AttrValList; AttrValList = NULL;! }7 L( S/ Z0 O) l( Q
* p# z: c7 B0 W M
for (i = 1;i<= nbfaces;i++)3 B4 O( |+ |1 [% R
{9 X0 N+ t8 A$ N8 T) @
Brep = ListBreps ;0 p- f+ }+ W; r
if (NULL != Brep)
0 {3 P) W0 R$ u% [& k3 p {! F8 [; ?" R3 O; @/ q. V1 I0 ?
Brep->Release();3 A9 Y. T; J" |$ h
}9 Z8 M+ c1 J( [/ G
}
$ O; K4 s7 n5 @8 H3 A ListBreps.RemoveAll();[/mw_shl_code]
1 `$ g& z, Y9 {" \: h: P |
|