|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
0 }2 z& P; o2 d9 _$ }0 G- C. n6 }" J //6 p) a% g& N' ~$ M" A
//7 - retrieving and displaying current faces colors
; \7 x: S# E1 ?8 K/ X7 H2 } //% F# I5 P# T1 M! [ P0 ?" ^
cout<<"--------------------------"<<endl;+ A# x; I# N+ z( \; {) R( B
cout<<"Retrieving current colors"<<endl;* a8 Q9 R. R/ e) h
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
2 z) Q8 k8 B0 k. L/ Y 4 S) a/ x4 `! G/ |! v c$ |
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
7 Z5 X& Z6 V5 ~/ c1 }3 Z if (E_FAIL == rc )
- O- e: P) ^# w5 o4 S# G {! I4 {: `5 w+ u+ B0 u( s
cout<<"Error, an error occured while retrieving current part colors"<<endl;! }+ b" W+ |5 M: M2 I
return 1;
) E0 Y( J7 {% @& x% K1 R! ~8 n3 ] }
* E% w8 i, E0 S6 i& s$ p' \1 f# z& `
for (compt =1;compt<=nbfaces;compt++)% B( ?' Z8 z( b' @$ V
{
% F- p( r2 e: y cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;0 V+ r( d8 Y6 V( N" O3 K
}/ r! N3 K! p$ q/ Q
( @0 R. O9 f; u9 N' \6 M" A7 h' S* | //# c v$ j. T/ d6 u$ |& p8 D
//8 - Setting a new Color on all faces- @) a; s9 h/ R9 B7 ?# W
//
7 ~8 y6 O5 K1 _
: ], w8 F- d( z% q5 f //we are to color the faces with different color according their position : three by three will have the same color8 n }/ f( f2 l0 I
cout<<"--------------------------"<<endl;
( F4 _% M! ]3 F, {8 @% f cout<<"Setting new colors"<<endl;+ p9 a" L, B) ? E9 l! k9 d
9 h, D, n7 i4 {" |6 r
CATListOfInt newRed,newGreen,newBlue,FailedIndex;& ^% k; _# T, Y+ \/ `3 W9 t
int x=0;: J! ^; G1 i* C. e* l" J( d
for (compt = 1;compt<= nbfaces;compt++)& ]7 Z0 _' o. e- D1 r
{) r6 R o/ v6 @& v. [2 l; o
x = compt%3;9 `8 g9 _2 U" S9 W4 A
int red(0),green(0),blue(0);
% Y$ [& x$ F+ L9 _6 I8 P6 i8 e: p if (1 == x)
; I0 O6 W( J& K2 [- W: A ? red = 255;: e5 \1 ^3 q0 B2 Z
if (2 == x)" H0 A' g* |3 r
green = 255;
8 Y7 n$ S- c- q9 f( T" h if (0 == x)2 v e' p% g; v# a* g" @+ |/ k
blue = 255;
0 \4 U; B) z; v- a h: @! Q! E. P newRed.Append(red);
+ p) m. h3 s H5 y8 L newGreen.Append(green);3 _" i3 b+ [. d8 o$ L) {, i4 s
newBlue.Append (blue);
' o* C9 ^1 I2 R cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
* C- b3 d* d& w4 o) e% R- r# X: P( K- R }/ h* A) _/ T" J4 N3 ^0 ^3 X3 i
, b$ a. R2 i9 P9 |& F3 \. i
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);: g! F) j5 h. X3 T/ y* F& i
if (E_FAIL == rc)
1 B7 u$ ~% ?8 w6 ^6 A5 D9 q) m6 I {% R" k! Z+ Q: p+ x
cout<<"Error, setting new color on faces failed for all faces"<<endl;- d# N8 a, ]" s7 m6 B; H8 `3 j
return 1;
8 D- `/ J2 ~. q$ i }; ?# T' F' ?' F Y, I3 t
else if (S_FALSE == rc )$ i2 b2 w/ `0 A) f( W! u" Z7 j" I
{
" m# | @. L1 f# }* {5 W int nberrors = FailedIndex.Size();! a2 B; c8 U' w: B' O- y
cout<<"Error, setting new color on faces fails for faces :";
$ i- w/ ]4 d/ P9 W' y4 K' x: y for (compt = 1;compt<= FailedIndex.Size(); compt++)
, i! m- U2 ]. e {
' h" E: ]0 o* S cout<<" "<<FailedIndex[compt];
+ m8 y8 I$ G0 M+ `# h! E }: L# i4 y0 f: I3 }
cout<<endl;
( z7 m `0 g1 r6 [. N' T% _8 h }
4 L( n( w$ ~: a% p. | else
+ i: d: r5 r+ M0 o. k cout<<"Colors successfully set on every faces"<<endl;
. Y. T$ @. S2 Y0 e! v9 c. a! B4 j //% V0 T9 z7 W) U( h: a* }% l. N
//9 - retrieving colors we have just set" `1 y' g1 L- `0 U, V* C) b
//
# O }' x0 p. T' q; S% T cout<<"--------------------------"<<endl;4 m% f- u+ m$ k6 p! w$ k$ ]
cout<<"Retrieving new colors"<<endl; o( n: \- ~( o! U1 l: b
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
! Z" ^% {) A/ `( j( ~7 o6 } if (E_FAIL == rc )
5 n5 R# f9 s4 u8 E$ h {
8 X* {& I) L1 l0 V. ^5 j/ F cout<<"Error, an error occured while retrieving current part colors"<<endl;
8 {2 Y1 {; X- ?- L% F return 1;5 [$ q! O' Y+ p# Q
}+ k; P8 @$ l# P7 `5 s- D
: y( z4 O! j8 l0 w7 \
for (compt =1;compt<=nbfaces;compt++)/ N; s) g6 e7 a7 Z
{9 w3 J6 C D+ B, i
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;4 n% q) T2 I [$ U+ M# d
}
- e7 u5 ]+ o/ S- q, o/ h
. t4 H7 o; V; [ j+ e' b/ S, e //
! i' z3 w; Y7 H; N //10 - Setting Applicative Attributes
! i& k- ~! q2 I) V //
% C5 Q8 F( t3 R
5 u6 \5 T$ H. f# d //. c# [$ `# U ?7 [$ ~1 f7 u
//10 - 1 creating new attributes 0 {; a7 b/ m& \8 ^) |2 W
cout<<"--------------------------"<<endl;* z( ~5 ~1 @( E& y' n
cout<<"Creating applicative attributes for different faces"<<endl;. X0 E! p, c3 N: ~) y/ Z
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
9 T9 h1 r6 b8 l3 F CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];- U0 _, U, T$ S8 N' t4 r
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();( o: @( }$ b/ [; J' L
for (compt = 1;compt<= nbfaces;compt++)
8 H1 {( H0 {+ i% F9 W3 h {0 ?/ {" P* E7 D" z- {
cout<<"Creating ";
0 Z' u0 W6 \3 @8 u+ }! {6 Q x = compt%3;! y3 u3 |8 e2 |; G4 L6 o
//for each face we create a new list of apllicative attributes
, Q3 c$ z; ~6 h7 d1 a7 l //an applicative attribute is made of a Name and a value! m: A% @% `* `' b% u% B" ~2 Q
if (1 == x)& E2 j$ G: Z( \8 @2 S, D% R3 ~ l
{1 b; X1 y( f# ~
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
8 t( i9 U3 M2 |# e* c AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
: f. ]' {4 r" l: p7 R( O6 l* ~/ s+ e# \4 @
//The first attribute will be the number of the face8 S& P& F- R& @# w8 K- b! _
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
; p ^. m N: h9 U9 @ CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);3 P( K! e, J. e# m" X# k& e! h
AttrValueListToSet[compt-1]->Append(tempcke1);% ?. \! @6 z3 u: D
5 v2 ]1 j* S, c; ~ J
cout<<" FACE_NUMBER with value "<<compt;
; H0 {1 d" x- I, b( f3 W) i4 l- Q
8 B3 q( E- y! \ //the second will be the color3 f3 D; k( H4 ?. t) B6 y! {1 c
AttrNameListToSet [compt-1]->Append("COLOR");
$ D9 M: O& ~" p( \2 H& c CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");4 \' k- ]1 l) P- z! y) ?5 w6 b
AttrValueListToSet[compt-1]->Append(tempcke2);
! E' N8 |. O% |5 @7 M 0 a9 u1 f; F+ m+ B
cout<<" COLOR with value Red";
0 m( Z# f3 b1 e4 z$ z
5 t- e. V; \- k: ~ //the third is x
& @8 C6 O4 O$ f/ G. f5 H AttrNameListToSet [compt-1]->Append("X");) n+ q# F$ z& I8 R; C
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
! P3 A3 X# L" g6 A+ v" L AttrValueListToSet[compt-1]->Append(tempcke3);: K7 `/ N) Y5 r0 U
1 m1 B6 ]: G5 `- S( n8 b$ L/ M cout<<" X with value "<<x;0 {/ }4 i" P7 I- w1 S- y" y; Y
cout<<" for face nb "<<compt<<endl;
6 R1 O% X {2 H. o. B* ~ }& k6 G0 L8 N, N" N
else " ?, e' S- `% r3 E' c, h8 m7 c/ y
//just to show you you can have different size of list2 R) L' l. d; @! I0 }- ~
{
# @' y. I8 u* ^$ I( o* w AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);9 [- ]* H$ n0 s
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);! I" h& C! y8 B7 `( D
5 \7 X2 c& s) ]6 h' `' ~8 [ //The first attribute will be the number of the face
0 E. T/ y/ k6 ~. v% P, Q1 g AttrNameListToSet [compt-1]->Append("FACE_NUMBER");6 \2 A% y- O. c# A1 r$ ]+ v# H
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);/ Q- `( H( D. R6 b8 z, O8 K8 O9 N
AttrValueListToSet[compt-1]->Append(tempcke1);
$ t1 [4 U6 F* D$ C$ J' N
& l: M1 }1 S, u4 e& e3 f% d cout<<" FACE_NUMBER with value "<<compt;
J9 V" T& @" r. _; I+ f8 [5 H$ s. X' d2 ^. o
//the second will be the color2 X! y$ a0 v7 m" L, Q& V7 e
AttrNameListToSet [compt-1]->Append("COLOR");
0 S+ F2 a' {: J9 }) Z if (2 == x)/ j# ]) O5 v. w! H- i2 I9 i; y% }
{" N4 Q9 j4 y6 E* X
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
- x$ x1 V* Y5 j2 @ AttrValueListToSet[compt-1]->Append(tempcke2);0 A# Z) a% b6 A9 q# H4 A3 }8 X' j
( y3 D1 b! M# ?6 G5 a9 J cout<<" COLOR with value Green";+ U8 [0 H0 y' R& h
}3 S0 M3 q2 g8 k" Q: d1 x
if (0 == x)
! j) X( o7 H( H; w( B7 l {' q S) `: d/ ~5 x7 l) w
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue"); C" N" h+ h# a' @$ q! m$ d3 J
AttrValueListToSet[compt-1]->Append(tempcke2);# m. i. ]! X8 r# \& |
, o7 u1 } {' x( l/ e/ g( R* D9 ?
cout<<" COLOR with value Blue";. a4 H. ]" h, ` \, {5 Y
}
* D, ^' [2 X% h8 D% l+ C, _- C7 f0 A3 O' e
cout<<" on face nb "<<compt<<endl;
! o4 ?1 f. `/ H' S
7 {$ Q& @6 Y: S0 [4 ? }
4 s: ]% q* \, j$ z }
& d; G% @% Z0 n; t& [( t7 V# |6 c3 D! d `7 Q! [1 b4 Y% ]3 S
//10 - 2 Setting the applicative attributes
6 i+ i# X$ N3 k: x cout<<endl<<"Setting applicative attributes on different faces"<<endl;7 D% m- B3 d9 \' C$ b! x
FailedIndex.RemoveAll();
* f2 o# o% B$ g+ X( w rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);1 F3 f- e9 [+ o" y" M# s3 p% ]
if (E_FAIL == rc)6 k T! E% J2 d6 c
{0 w, c+ `# v* V1 R' d+ R9 C
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
$ m# H) S' Y6 _2 S6 L3 t }
8 _- L# y1 C. E1 ~7 J else if (S_FALSE == rc)
V5 s3 c# d" O3 H/ \ {+ W' z) E# f0 r; @: s8 w! U
int nberrors = FailedIndex.Size();
6 K5 X, f6 Z) y$ \, j e9 {5 ~ cout<<"Error, setting applicative attriutes on faces fails for faces :";( x; M, C) P+ j1 m# Q7 ?8 r
for (compt = 1;compt<= FailedIndex.Size(); compt++)+ x. ~" n" V4 W# F! O3 B
{
9 ?1 {7 X! c/ U5 ~3 T cout<<" "<<FailedIndex[compt];& |, E2 L2 ~ l. h1 N
}( ~' ?5 u3 I/ y- }, c
cout<<endl;3 w* i+ T: M9 P
}
3 Z, {3 p: `& H$ _ else
4 H2 i& Y: Y6 g3 m1 \4 b {
9 V" |/ ^- ]) k* s cout<<"Applicative attributes successfully set"<<endl;
1 u! R) ^5 h0 G: g }- M3 Q0 R* P* U2 ^. H+ o9 V( ?
' }3 v4 k, w: {! b, V //10 - 3 cleaning
5 L2 }% ]. e5 x/ Q/ M9 W for (compt=1; compt<=nbfaces;compt++)
" Y. v" i6 Y2 }8 F3 h {
f+ N V2 d5 @& V/ g% Q9 p AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;9 {0 S O6 `7 V/ Y
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
# ]5 x" C+ u# X' A- V0 [9 E6 A0 K$ r2 J p }
* R# J P# o9 L: L3 K- M9 R4 d
, y. U0 Q9 B7 H; ~" ]( d delete [] AttrNameListToSet; AttrNameListToSet = NULL;" o2 R+ Z0 w: Z: P8 o
delete [] AttrValueListToSet;AttrValueListToSet = NULL;1 U- Y P% L7 D8 E* M
% z' ]) Y' _% U; w& c
//8 Q0 u& r; L3 b) _2 j
//11 - Retrieving the applicative attributes we have just set
$ Q5 `; u9 C% \. G! g4 b) x9 Z //7 k) W& t! y' l' F7 c
cout<<"--------------------------"<<endl;4 t) i3 Q6 e: A5 |
cout<<"Getting applicative attributes on faces"<<endl;' ^- k( ?4 d5 b# F- `
//
/ z' h+ h6 `7 S //11 - 1 Getting attributes
) s" z7 @/ F- p7 P: u( i CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
1 S+ \- R4 U- g' R/ x CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];: i0 W6 r7 a! w5 d* Z: D' b
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
! Z5 I8 s9 |5 ? if (SUCCEEDED(rc))
2 _3 l7 P5 T; e8 w7 Q X; G1 z {3 A R* |" Q& F% G; M
CATListOfCATUnicodeString templiststring;8 C$ p6 H2 L+ e7 `: i) h
CATListValCATBaseUnknown_var tempCke;
; m6 x# v% | D( m for (compt=1;compt<=nbfaces;compt++)% b& ~: q+ U$ r' ^! f
{
' h& y+ H0 i4 F9 O //retrieve a list a position k (arrays start at position zero).5 N$ q! I( |1 f2 T& r2 U; u" x* n* @
templiststring = (AttributNameList)[compt-1];
: T9 X( m: |( f( v" y2 x! [9 n v tempCke = (AttrValList)[compt-1];
' D# `9 ^" ]3 V' }* _, {
0 `" d% S! C( P4 m0 y: o% P7 u int nbAttributes = templiststring.Size();6 a- ]% k: z! G! S$ f' U+ e1 N
int nbValues = tempCke.Size();: `! \; Q+ m. U, B }
; L; |/ [' _) T9 G //the list must have the same size! If not, we jump to the next face# I; Y; x2 E+ _7 o* S2 S% r* j
if (nbAttributes != nbValues)
5 @+ A( D3 i% e; @) v {
2 w% ~% N$ r) @8 G/ { cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;' {" T. B8 A3 a' S! b% J) r `
continue;; l' \0 X; F* R
}
5 K& \' p& j; ?% W- f( k6 o else
% P. h( a4 H* w0 G {5 Y* z1 A% F( G- [3 O7 m. }
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;2 k1 x f- Q# H+ T: o, D
}
% e$ G' `- I5 U for (int i=1;i<=nbAttributes;i++)' i) f$ N5 ?' N: W
{
. l: e( J4 n5 q3 p% @ cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;$ j5 \. p9 i$ D' c
} g: {7 r2 ^* ~0 t
templiststring.RemoveAll();4 T3 l& j8 F, n* H; L' H6 e6 N
tempCke.RemoveAll();6 M, w9 y3 a, }2 v1 f
c. p0 t1 l6 v4 A- M/ _& g }% K* ^: B% k) n# e. j
}
1 W& h7 _$ F/ q6 Z" d7 I else if (E_FAIL == rc)
0 @ x. ^7 O# x$ u8 `( c S' w5 A {3 C1 ]5 c. t" O4 V$ r7 D- O5 W
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
/ C7 P1 j/ O; j; p; E4 G return 1;* F; c/ U, q6 O* A/ F9 B8 a
}
9 D4 c0 i. B- ^( } //8 k+ O. r$ V! v- V1 `" z
//11 - 2 Cleaning List:
w2 b) f# E" m* e' n8 a# ^; V int i = 0;
7 g" U& ?* u# l5 L, a9 [2 S for (i=0; i < nbfaces;i++)
t& V6 V l6 @ {
6 {6 q4 F" q. ]3 p. c+ }: B AttributNameList.RemoveAll();
9 w! ?' f0 z$ @ z" Z' C! m# e AttrValList.RemoveAll(); T( n$ x0 F( a/ [0 Z
}
/ l' i4 z' e% I3 Y# w: C! K delete [] AttributNameList; AttributNameList = NULL;8 }6 S2 p& k3 ]7 f& v4 K/ c
delete [] AttrValList; AttrValList = NULL;+ h& u4 d. J3 Z4 b6 k3 @
" z! M2 m& ~: @- C z" c; ]/ @
for (i = 1;i<= nbfaces;i++)
1 @7 H; G, z7 @3 Q9 ` {
8 p8 O; i5 |2 _: p- ?# X Brep = ListBreps ;# [7 K; r. x6 B2 T9 e% Z) V' h' g% B
if (NULL != Brep), u6 n- m4 D2 _+ Z0 n7 [2 G
{& T" i' v8 s6 {) G/ b) w! t
Brep->Release();) ?, i9 a( m, k* `3 I6 i
}/ K% N0 B) [% F5 O! t
}
6 u, J9 q, q7 ^6 U ListBreps.RemoveAll();[/mw_shl_code]0 r" K9 L* f* ^
|
|