|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
! q- e( h0 S, ^ //
/ g0 o$ j& v7 W% f //7 - retrieving and displaying current faces colors
6 x" A. M2 [8 s3 M //3 e, h1 a2 t. r
cout<<"--------------------------"<<endl;
; o, }+ T5 X* F0 }. ?8 Z cout<<"Retrieving current colors"<<endl;4 ^( u2 g% D X" }
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
' S- @" N$ K9 D0 }/ }8 w ) ^8 d3 H W7 I5 k% ~
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
' e& p9 t- T/ T if (E_FAIL == rc )
5 I2 Q$ _3 f0 G h1 ?2 @5 h {
6 }3 p' B4 L- W; s9 w4 i) P( Y cout<<"Error, an error occured while retrieving current part colors"<<endl;: E" Z$ o! v9 k" Z
return 1;* D9 D# {! w8 i0 ^# t" x1 G8 @
}% o& _2 a; i% }
+ O- X+ r: f5 U& Q, p
for (compt =1;compt<=nbfaces;compt++)( @" a3 n" [8 A
{% _. S+ q* b5 p9 [5 H/ x
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;3 e; V. Q0 B1 j3 P* g
}6 g. z% d1 ^, s0 v* T' y
4 s" Y9 Z5 P' u //
/ X1 w$ f5 F' b6 _7 t- j* B } //8 - Setting a new Color on all faces2 t! U7 }# y9 g; [; D7 M
//3 n. q5 u2 u/ H2 h+ K U
7 D# h5 u7 g1 V. u6 I6 t- D
//we are to color the faces with different color according their position : three by three will have the same color! D$ V" o- O e, P$ y8 k
cout<<"--------------------------"<<endl;$ _+ x) ~% [8 j
cout<<"Setting new colors"<<endl;
+ t: Z" G. b8 s5 l ?
# @9 x4 B1 E& x2 {8 w CATListOfInt newRed,newGreen,newBlue,FailedIndex;
. q4 y2 _! K; T int x=0;
) ]8 y$ m& R8 l F9 h0 W" v: i2 ^! C for (compt = 1;compt<= nbfaces;compt++)* |: B. D- Q, I' j& c1 C2 C
{
9 r$ K/ E1 g5 d4 W( L9 A- ^6 ?1 W: J x = compt%3;
5 s3 V* |2 R7 C$ v7 V int red(0),green(0),blue(0);* O* O6 J. V9 [" _* ?8 @/ R, W
if (1 == x)% [4 ]( R" k! q% r0 ~* @
red = 255;! P2 W- q1 d9 s4 Q' ]% y
if (2 == x): a0 s9 s, Y) t' b- ?4 _' {
green = 255;
/ d% Z# O, V1 l3 B% q; s if (0 == x)
! K5 l6 P+ f# ~; p/ b; M# o blue = 255;$ C ?, I0 @8 D! F( }) F) c: a
newRed.Append(red);
2 t* a5 s3 i3 K newGreen.Append(green);$ W* O. ~& I7 \, W3 N
newBlue.Append (blue);2 Z5 C8 E( Y9 S- \0 n# T% [
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;7 g1 w+ Z8 n& W/ [3 o) s( Q
}
4 B# N* Q8 a0 m+ W8 C4 g7 y" b* j5 {& X( w9 b% D7 g) y
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
9 |: e) T% {( x& L' E! p if (E_FAIL == rc)
& L8 r* T& U7 ^* J: ^! A' U {3 @9 E6 `0 b+ e5 Z' P0 X1 J/ w6 e
cout<<"Error, setting new color on faces failed for all faces"<<endl;
1 k8 `) m: ~& B4 r return 1;) N" `! X/ R1 N5 W0 S
}
9 u) M' i( I2 J else if (S_FALSE == rc )% M5 S4 T- L1 C
{# P W0 a; C f9 l' K& Z- k
int nberrors = FailedIndex.Size();
' C+ u: B, h/ U1 M cout<<"Error, setting new color on faces fails for faces :";
9 [, `7 C8 H u, ?* b/ g6 h; a for (compt = 1;compt<= FailedIndex.Size(); compt++)! V4 f* X+ q# T1 _8 L V4 Y8 C+ U
{ U# [0 n( L8 C" v/ s, d
cout<<" "<<FailedIndex[compt];% P# q$ z8 U+ ?9 c
}6 `: N; M% w0 N# U# W8 q
cout<<endl;2 v5 F! {+ t& f
}
, O4 k8 g* G; O2 [; Z4 D else " z, U7 N0 `) l* M# P. D- u) o
cout<<"Colors successfully set on every faces"<<endl;
4 F5 n# ^ H S% x! L* B5 i //# I8 b6 o3 G& q; N& G
//9 - retrieving colors we have just set1 I) a8 v) `6 s9 C% D. O
//
{0 n# _/ A2 t w+ K- d7 ~ cout<<"--------------------------"<<endl;
0 _8 a3 u: B6 T& V" [4 k1 S cout<<"Retrieving new colors"<<endl;9 b# m& s; j; t* a' i
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);; v& ^) j. ] C$ w0 U4 _% X1 k
if (E_FAIL == rc )
0 \# w9 l( K2 l' ?3 s( Q% P {
/ Q) A" e1 N: r cout<<"Error, an error occured while retrieving current part colors"<<endl;* G V% N, A$ e
return 1;" v% A6 y) K$ S0 I" M5 d5 _% s4 Z
} F+ W5 K; b5 ^7 Z
0 T8 V* X' }5 w' z% q
for (compt =1;compt<=nbfaces;compt++). T$ e1 n- a$ b7 N2 V
{: J2 M+ P, X0 g9 _, L6 }2 F
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;% B+ j( O; w9 W- R3 t+ F; X
}4 u, u' i4 n2 m" |/ h6 r
: u% R5 n% R; \6 U3 r7 P5 d3 j! c' ]
//
3 V# Q: l. }8 O4 r; k% N6 E4 w) B //10 - Setting Applicative Attributes
: L( p& G! M: ^8 w- o( d& T" U //
1 i2 z/ p2 n/ e `2 I& ]" x1 {1 Y- I0 j6 \$ {! b5 @% _
//+ f. b2 i% R( P: }. j7 [
//10 - 1 creating new attributes 0 x( _7 B% g C3 F) I$ @
cout<<"--------------------------"<<endl;
& K, F$ e/ G a6 v# N3 k+ U cout<<"Creating applicative attributes for different faces"<<endl;
$ V) B' R& c8 S C* J CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
- }5 { }. g( L+ g CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces]; e1 K5 |$ M6 a$ r$ [
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
z& z9 H' F9 X' }+ s" g4 u0 A for (compt = 1;compt<= nbfaces;compt++)
1 n) g4 B- Y/ {( Z- ^, I# H5 F {
7 G, N' i* y8 E# P) ]5 M" _ cout<<"Creating ";: Y7 Z6 W( w6 C, t- U, U
x = compt%3;+ U3 B' t7 g3 n& \0 |
//for each face we create a new list of apllicative attributes; s- b5 g. a, a, L
//an applicative attribute is made of a Name and a value7 X$ y$ Q/ N& O2 k6 O- d, P
if (1 == x)
* J* {) s& U+ d V; U, V1 Z {
1 [9 w# k" _. S% r# R& d AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);; s9 E! r4 O( b6 \0 M( p: I
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);" ]+ B% h* r: f! q( r8 r
+ T2 f2 ~! a) P
//The first attribute will be the number of the face
# w3 q, H2 ~, j/ u2 V( `' ^ AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
- ~' o9 f# x+ s3 E CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);5 L. i) H0 g9 y; a
AttrValueListToSet[compt-1]->Append(tempcke1);" C# S6 N8 U$ b+ M" i1 x
+ e9 F4 ~! O- i cout<<" FACE_NUMBER with value "<<compt; 5 l f% O' v8 ~$ W2 u: q3 Q
4 I) r! x6 L0 C1 G8 v
//the second will be the color0 {% d$ ^0 N& x3 E& z* N1 e# P
AttrNameListToSet [compt-1]->Append("COLOR");6 Y3 L6 ]! k0 p; `3 r3 C4 w
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");1 o# ~. C( j0 [3 t) j" ]! k
AttrValueListToSet[compt-1]->Append(tempcke2);: t. k$ p8 ?; ~. b0 C2 e
) |/ h0 ^/ A& [ cout<<" COLOR with value Red";* {! H6 M& H; w: N/ s
+ F+ G6 O i% ^/ L$ v/ L
//the third is x& I5 b$ a* Y: r* e& D
AttrNameListToSet [compt-1]->Append("X");
6 q$ N6 i% j0 |' k: S# I CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);3 [7 N2 M# @; h5 d) @# r [4 X
AttrValueListToSet[compt-1]->Append(tempcke3);
+ D- {7 M+ U& ^# r6 o
7 _2 B8 A3 P3 e! Q9 l+ U cout<<" X with value "<<x;! h; k( ~& }) r8 r" K- j! I
cout<<" for face nb "<<compt<<endl;& h( V" `7 K0 d6 {! {* u
}
4 Q. h4 e: {8 h6 Q+ N2 H else
* i3 E3 B8 \) m) e //just to show you you can have different size of list
0 Z. f( o% p K- g! E, I8 |2 S {6 ^- T! o+ ^* F4 x3 C0 N
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);5 I# a- Z0 i, a! I% t$ C4 z% [
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);& E- a* n0 h* J3 f0 V
* v6 V5 d) M, Q0 ` //The first attribute will be the number of the face
& c2 q% J. J2 I7 t AttrNameListToSet [compt-1]->Append("FACE_NUMBER");. \2 q- Q8 \% Q4 {9 N8 f$ ~
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
( v5 p4 z) Q* j AttrValueListToSet[compt-1]->Append(tempcke1); ~7 w$ s1 \, s" R/ z
* O# q" ^- H8 \9 e2 _5 ` cout<<" FACE_NUMBER with value "<<compt; 2 p7 P: h. ^! p5 A" R
. s; \% Q+ `) P' k
//the second will be the color; T% H% `. @' z+ f
AttrNameListToSet [compt-1]->Append("COLOR");3 {" \6 Z" _7 ^$ V/ I: @9 H$ E3 R
if (2 == x)
8 S& k: u5 o3 h# c, ]$ q8 O2 L4 J5 S {
: v/ u9 w) Z" n& O8 t8 Q9 o/ K CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
5 c/ M0 w/ k5 }9 N AttrValueListToSet[compt-1]->Append(tempcke2);
/ b0 n/ q1 ^0 Y H
" r) z3 ~2 ^* {. R, k$ B4 f, o4 F cout<<" COLOR with value Green";
9 P2 ^* q2 X8 t) P" _ }
: P3 Q, a$ n+ } t if (0 == x)
$ e4 L9 A9 k9 Q. b( h {
4 H+ v& u5 m/ R0 x1 i. B* P+ t CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
* C8 T' V+ [' ^$ R) p$ s I AttrValueListToSet[compt-1]->Append(tempcke2);
5 m# y5 q! K( X# M" \3 h" k 5 d$ N/ D0 b" O0 E9 T" Z
cout<<" COLOR with value Blue";8 e6 }, z1 Q2 M# W
}
* k4 n4 h* a8 `4 N2 ?& d9 B
' a3 W+ @# g$ t cout<<" on face nb "<<compt<<endl;
. g8 k! @. q. } D9 ?' b$ v- ` p* ]) m8 o' z) P9 a
}& T9 {# y2 r/ O3 C1 U! X$ d I0 s
}2 Q ^* u/ D; V# A: Z- c8 q, r) o
4 C$ r* T2 Q4 E# d( V G, i
//10 - 2 Setting the applicative attributes
- D! z+ H: ]8 p% g6 h8 ?9 n/ C! C cout<<endl<<"Setting applicative attributes on different faces"<<endl;5 \" N/ R c/ d6 a
FailedIndex.RemoveAll();
; t5 z r5 x6 ?; x+ m rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);2 e8 h& w: T* O! ]% D
if (E_FAIL == rc)3 p0 z7 o% f4 M$ B& R6 t) T
{& u/ s3 N# z8 @0 X: Q/ S# |
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;6 n* U" X$ u' r2 J! k
}* C& f. L$ L G& P$ Z
else if (S_FALSE == rc)! [ n( @/ p, a$ _ B' Y( ~5 A* U
{0 ^' R5 l# O2 \5 W* U
int nberrors = FailedIndex.Size();: t/ G, p$ y c' x
cout<<"Error, setting applicative attriutes on faces fails for faces :";7 L. w1 L1 g8 `
for (compt = 1;compt<= FailedIndex.Size(); compt++)
% |9 x" b+ t8 S; Z/ M {9 @' J! d7 p" `5 U+ K. A0 I I
cout<<" "<<FailedIndex[compt];, @# r+ K& e- r
}
; a& ~2 D9 e+ X cout<<endl;+ I, u! ]/ l) ] @+ [
}
$ ?% y$ Z: V/ |" r4 `" c" c5 R; @ O else( o" a/ f! g! b; ?+ _1 O
{
) l1 C$ ?( @$ b5 s, s1 k cout<<"Applicative attributes successfully set"<<endl;3 x% |9 m) [, J
}
( Z! {# O; _% j9 z) W. I' z' G$ t: ^. F2 x& ^
//10 - 3 cleaning
4 b' {; `0 |7 f- Q: H G for (compt=1; compt<=nbfaces;compt++)
! t9 J1 k& L+ W {
5 H" `; x# u) ?6 A) F2 `+ t AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;0 [& D4 n8 Q8 M+ i
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;' u9 L' X: x; z% B, N
}$ t. Q) P# n8 t
* q2 |9 C' M( |1 D
delete [] AttrNameListToSet; AttrNameListToSet = NULL;
: T2 y+ I; |3 B, f3 g delete [] AttrValueListToSet;AttrValueListToSet = NULL;
7 q& |4 }9 U. A6 O( ^! o9 ~, q
0 ]1 K6 k* t: K- k0 Y //( n, Y3 i; r' B! T
//11 - Retrieving the applicative attributes we have just set& s' J5 m8 Y* s
//$ s( @9 H4 S6 \
cout<<"--------------------------"<<endl;
/ o6 B- N5 F+ _% u" T) O cout<<"Getting applicative attributes on faces"<<endl;
* c0 q+ B" C* J3 A2 s7 V3 J //
+ |! R2 N: H) p. j //11 - 1 Getting attributes. S* E {! z, u# x+ W- q- v! r
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
4 d- ~5 m1 Q S9 v, c- P4 T4 Q) W CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];- L7 ^9 C, w, Z8 w- c! m
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
! L# l( i6 `) O2 ?: X if (SUCCEEDED(rc))
& i) Q1 h/ o+ \% `3 c0 s$ Q$ c {) r+ Y+ b9 O! P& Z+ s$ ?+ `
CATListOfCATUnicodeString templiststring; { W5 n0 G( S/ n: R$ Y/ }9 O3 J
CATListValCATBaseUnknown_var tempCke;
2 E. t3 b/ `# m* Y; T; e- P/ |9 w/ N for (compt=1;compt<=nbfaces;compt++)# |7 Z- V: `. q3 Q
{! X$ W# U) z: y0 }
//retrieve a list a position k (arrays start at position zero).6 m. W8 | p: J9 O, L
templiststring = (AttributNameList)[compt-1];
7 B! ]. h2 T5 e tempCke = (AttrValList)[compt-1];4 G' m, E3 p; c) v* \
# q- ~ ?7 G( b0 n8 E3 h
int nbAttributes = templiststring.Size();
3 a3 \2 U- U5 u3 x int nbValues = tempCke.Size();
' N/ \- E$ {$ G: {5 P4 n/ G0 k
//the list must have the same size! If not, we jump to the next face
' ^& w! R K* a if (nbAttributes != nbValues)) m+ ]/ c. a& e
{( f$ ? b. m/ _% D, Y" G9 E
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;- T0 ^- H1 s+ N* P8 d( T i
continue;2 E: l+ l, g- P
}
: ]$ }. m+ j* m! U6 J9 Y else
2 S6 o2 j3 M# x/ p; X$ K5 F {
# C1 d: y+ K9 M- N, k: z3 u cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
9 ?8 U" g3 G/ j" O; W7 v, Y H }
, Z/ g! P& ~7 w- [" B% U. {3 d ^ for (int i=1;i<=nbAttributes;i++)
. m7 f: K9 G5 E; f- Y" L {
& |9 o# |6 U. _) i. Q# u% W; z) ~ cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
4 E" R# e( b o3 }# t }
( p7 @2 E4 M6 r. j+ X" J templiststring.RemoveAll();
" `' k8 H( C% V# E6 B+ ]! g V tempCke.RemoveAll();
0 c9 o; e! T/ Q5 y; @$ m" { G( D1 w2 G1 x
}
1 P; k7 x: h0 R' L7 K }6 m7 y, t9 H/ o2 h" l1 y' d
else if (E_FAIL == rc)" q7 k; O+ G# [; }5 W8 E' A0 u2 ~
{" ?. k# I$ @2 o/ i, x' R
cout<<"Error, applicative attributes couldn't be retrieved"<<endl; v1 P1 d7 V: s- X' ^
return 1;
, X! x) B: Y# Z9 T3 ] }; N y( }6 l' @9 } {5 J
//
1 _" R" G: g8 k5 r* a6 e! M1 | //11 - 2 Cleaning List:' L+ X# W, ?" H' I9 C3 [
int i = 0;/ h$ A1 ~& S8 L+ k9 y; S, N
for (i=0; i < nbfaces;i++)7 W4 @: T% _: u- }% x. b9 ]
{
2 e2 }2 a- b# N3 G* F% g AttributNameList.RemoveAll();
$ Z$ ?8 {, t# H/ K1 f& |4 L AttrValList.RemoveAll();
5 K9 q' z0 U0 U+ [- T$ O) N }( s/ d" t+ P7 u9 H
delete [] AttributNameList; AttributNameList = NULL;! g1 a. M4 a! U" q; g8 q; C
delete [] AttrValList; AttrValList = NULL;
" c" }" [1 e. d+ W8 V
& i' k! ^# _4 `1 I" ^1 J for (i = 1;i<= nbfaces;i++)
% X9 O0 u3 A6 E# G* `0 K' j- J {! L: ~: V `7 T2 G- Q
Brep = ListBreps ;
& g, \: u& `7 u0 z if (NULL != Brep)/ N B1 x0 O% L& o
{
- j9 [3 v2 Q% N% y: n Brep->Release();/ ~6 K9 d+ y5 B: ^
}! [5 G7 ]0 Y; ^$ X7 }
}! }- ?" P+ P: d1 {
ListBreps.RemoveAll();[/mw_shl_code]2 X @+ C( g) {6 W. ]/ l% `1 u
|
|