|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
8 N1 I& d( b; ? //
B/ ~- ], g) T0 `. J% g& V //7 - retrieving and displaying current faces colors
/ H s( Z; J4 C //
$ R2 a) T' v# @* w7 d2 _. b% U cout<<"--------------------------"<<endl;% O: ^5 X% T, ^4 |. W
cout<<"Retrieving current colors"<<endl;
: ~4 a" p$ X& |0 K- d) r CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;2 s+ x$ A* f9 t8 q! ?& L: Y7 q
. b4 ]3 k; g" i6 j$ Z rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
5 |1 S" R4 o) _/ F if (E_FAIL == rc )
7 ^, Y/ b2 F9 v' _( j {
1 b9 H1 _) Z% x5 O cout<<"Error, an error occured while retrieving current part colors"<<endl;
0 @( @: n) O6 E/ S9 j return 1;0 D/ n" }( T. [9 w3 C
}5 I% m# u6 f8 T( H
( b/ p* C p4 e# g for (compt =1;compt<=nbfaces;compt++)
- U* u/ A" X( n$ Y U {
/ p! w3 m: W! U- N: R, I cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
$ S; Z/ D4 E$ w7 J4 B }" ?' _, X* i/ M! O& |
4 }( \/ W4 s7 x& }0 F //( n v& h/ U+ R$ Q
//8 - Setting a new Color on all faces( a- g5 s: F# e+ x
//0 H9 N7 \4 y) e5 G; W
7 e, y2 X' p+ h5 `& X/ p6 T //we are to color the faces with different color according their position : three by three will have the same color) X1 [2 T1 |# K4 e9 v3 Y. N1 @
cout<<"--------------------------"<<endl;" d% X" n: V$ S, a6 T7 F- Q
cout<<"Setting new colors"<<endl;
% b9 g5 c! ?" x) n5 |# f( v # Y, L4 j! r( K* |
CATListOfInt newRed,newGreen,newBlue,FailedIndex;4 {+ i; h" v* K
int x=0;+ ?( ~1 T) M& w% m
for (compt = 1;compt<= nbfaces;compt++)$ j. x8 H! _# ^/ j. ^/ y
{# U& O! n3 `- R
x = compt%3;
9 z; X2 w6 J0 f$ x7 K7 m int red(0),green(0),blue(0);" k. n( @1 A8 a5 h7 ~5 v8 t
if (1 == x)0 R6 q5 D. Z: c0 d
red = 255;
- y1 t7 x6 \) Z- b; b2 k" A+ Y5 J if (2 == x)
A% E y- y+ ~* N6 O green = 255; ]0 N8 W9 b4 F
if (0 == x)
* R) I% ^* l( g3 s; U blue = 255;
. J8 Y. [' S" r0 L3 F newRed.Append(red);+ `4 Q/ t# k S4 ~# e {3 ]
newGreen.Append(green);8 ?4 J4 ]! v6 ?
newBlue.Append (blue);: w3 l- ]* @# U3 x
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;- p4 U& l( Q) I1 S8 p# b
}8 a8 E. Y& n9 ^* ~
5 \ A- w. T! T1 ^9 V" r) Z1 r
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);' U% W8 C" D8 m/ C. G* K
if (E_FAIL == rc)* \/ q. T% C+ K+ \7 ~" c1 j
{( l% x0 X2 d/ e9 N- f( Y
cout<<"Error, setting new color on faces failed for all faces"<<endl;3 [+ v, {( f' [& b; E! Q
return 1;
6 y1 ]* V7 `' U# j0 T8 g; O }: Z- Q- I9 Y. b
else if (S_FALSE == rc )9 Q3 H, D7 K! ~# Y" J5 g( ~
{
4 }$ h" K% `! g/ R int nberrors = FailedIndex.Size();+ y h& y, ]+ E& \9 h9 d0 \6 ], a
cout<<"Error, setting new color on faces fails for faces :";
7 E" y! `; t/ B6 A9 D3 A# T for (compt = 1;compt<= FailedIndex.Size(); compt++)
% y9 Y; i" S" v' x# L* V, @ {$ n4 c( h. ~- s" l
cout<<" "<<FailedIndex[compt];
$ k3 N* i: g% N! { }- i Z5 f e3 y( ~7 k
cout<<endl;- y* y q/ d Z2 z0 d
}% {2 Y- k* U$ L4 r0 o. u
else 4 C, M! [+ H! a5 p: o" X
cout<<"Colors successfully set on every faces"<<endl;* x0 z3 Y9 }4 y) Y. ^ F
//3 r; [: v. S8 B! E
//9 - retrieving colors we have just set2 T- k3 C, M5 e. Q
//
8 P1 D( e9 t& Q+ y$ Z cout<<"--------------------------"<<endl; v. R, t7 x" g7 t1 L
cout<<"Retrieving new colors"<<endl;* J* w% C0 N$ j1 i5 m
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);6 o1 T+ {5 G0 @8 T9 A% Y
if (E_FAIL == rc )
8 I( F8 e, n( D, _. y {
+ H- O7 s- T0 U! H cout<<"Error, an error occured while retrieving current part colors"<<endl;+ @: e' v- x- v s5 p
return 1;4 {$ {' f' C4 G2 y8 }* I
}
. u7 u2 A. b2 B4 g+ a
" W" L( Y' h! n for (compt =1;compt<=nbfaces;compt++)- o/ S$ ] E& D5 j, l
{/ N3 x, ]/ N3 y- Q* v
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;$ c* z6 l- ~1 Y1 U6 \! W! N* | U
}
; P) \- C; v/ x* k5 k1 ` i0 R* y" x4 Y! ?
//( `2 P3 ^' {) ~) B4 Q! @
//10 - Setting Applicative Attributes( K* c3 _. a0 }/ p$ z( z" |
//
) d$ n: }7 o5 k9 f$ ~6 f0 {4 p# d2 S7 f
//: V( X: ]( i+ f8 d- v' X; v
//10 - 1 creating new attributes 2 ?* [2 @1 @. X' B4 ^, K
cout<<"--------------------------"<<endl;
6 l% ~2 \$ w9 }4 `3 x! Z cout<<"Creating applicative attributes for different faces"<<endl;
7 o, Z( t; l i CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];: Q! ~0 j6 O; {
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
7 J4 q9 Y2 S# b% v( h% d% ] CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();4 w( a. y! q& i6 l; R9 H
for (compt = 1;compt<= nbfaces;compt++)( u b, q9 O7 s- ?5 ?6 @1 h3 H
{' o' w8 d- R# s. z; n/ \9 r6 x& W
cout<<"Creating ";
# n. p' R! X* T/ L/ m x = compt%3;
! r" |/ S. y+ E8 e! E" X //for each face we create a new list of apllicative attributes
6 Y' K4 z i. ~2 I" |) | //an applicative attribute is made of a Name and a value/ f; i9 r7 F8 z9 A7 ]
if (1 == x)
+ @. P4 N1 ~. X6 V1 N {
" U8 [$ Y6 g) d4 S2 e1 y; N- U AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);$ T M6 J& S' Q& c4 B0 A
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);4 L: A- J; {! ~
9 e& c( U$ d" ~
//The first attribute will be the number of the face9 I2 }) Q+ z, C3 R
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
. P4 M0 p0 l& {% l( t8 A' y- F CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
0 e/ ^* f: ?# W7 j2 ~ AttrValueListToSet[compt-1]->Append(tempcke1);9 R4 W, X( U1 K7 x! r* Q
' ], m2 I/ L4 a+ Y7 X7 G cout<<" FACE_NUMBER with value "<<compt;
@7 s% h3 z$ n
) E' p* z0 M b7 B$ [ //the second will be the color
8 x3 w. p% M4 L: C% t AttrNameListToSet [compt-1]->Append("COLOR");: g) k& m4 T7 v( ~2 U
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
& v6 @6 e7 B' f% V4 B& D8 u; @ AttrValueListToSet[compt-1]->Append(tempcke2);
" L( Q7 ~, ^9 S! {! X2 B5 {
% w" Z/ z$ I. D cout<<" COLOR with value Red";1 m0 I3 \9 x: L# [7 h0 J. S5 T2 W* p
?. R- K! D6 D; w
//the third is x8 h& o/ `' |5 ]9 a, l
AttrNameListToSet [compt-1]->Append("X");
8 D6 q% p) j% d0 ~' S& m' o CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);" L# y; p& g R& H0 w' k5 e9 X
AttrValueListToSet[compt-1]->Append(tempcke3);
d" c. \" l U" H
+ o" h ^5 g% |7 I& O cout<<" X with value "<<x;
. _7 O$ X" d, y7 |& e: {2 Y6 v, C cout<<" for face nb "<<compt<<endl;
. q6 m* T. R D3 o2 x% x& ` }5 `6 }- Z7 y) V% |2 c
else
. O' r3 p: E; D1 f0 w/ Q //just to show you you can have different size of list
1 f! {& Z f( y* g6 q( u {
1 y% o3 ~" v; d" i AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);8 e; B5 W/ D- Z4 I" }1 o4 `
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
) \7 X0 w* X) H6 L6 ^8 J9 L$ X+ |* x. e# ]/ \
//The first attribute will be the number of the face
* F8 g+ j5 \5 z! z9 E, y AttrNameListToSet [compt-1]->Append("FACE_NUMBER");; r( @! Q% a6 K2 E9 D! r
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
D9 C4 O1 ~& W- } AttrValueListToSet[compt-1]->Append(tempcke1);
N7 M1 {8 z0 S( [
8 @! Z+ X% s$ J @- q" X cout<<" FACE_NUMBER with value "<<compt; 1 g: B8 K% b I
$ O# e; K" q' ]/ X2 ^
//the second will be the color
' k0 F1 Q' Y2 H/ d! J+ m AttrNameListToSet [compt-1]->Append("COLOR");
$ l- S6 f3 ~5 U T8 y: W+ B! m c, j if (2 == x)6 W! B7 e9 r1 Z! C0 V9 l$ [+ r7 {
{: [; [& p7 ^3 B7 r( X
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");3 e0 K4 \8 W) y3 x4 v
AttrValueListToSet[compt-1]->Append(tempcke2);
( p- Q* s( {% E8 P( o' B
; P9 r2 ]* x! B3 w2 ^: H cout<<" COLOR with value Green";
- X1 Q; B1 K+ y; I }( K- q k' [5 b" \
if (0 == x)
7 ^9 j% F; y& Q. M0 W2 F+ j {# t% r1 d9 y, m1 c6 A- g
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");8 ?' m+ }: B& a5 q' y' v9 V5 T
AttrValueListToSet[compt-1]->Append(tempcke2);- v, H' D5 |/ l. e* b- g
, \0 o$ L% w3 |* r; N% D, O cout<<" COLOR with value Blue";+ }' K/ W+ K' l6 l, c5 L4 S
}& z) }9 R7 _% b( ?
" o1 K' W7 w- F3 ]' l2 j8 _. k cout<<" on face nb "<<compt<<endl;" m. q1 @1 H i% N4 j& A" e4 R s
4 c' z: ^# r. ~5 e" n' X/ g& D }) D; Y" \; M: G* y
}
" c3 b4 P! d9 f! ~* v
( y7 B" H# y* v' \ //10 - 2 Setting the applicative attributes
2 {; x+ ?6 H k2 ] cout<<endl<<"Setting applicative attributes on different faces"<<endl;0 l5 e( T" H1 y" p8 ? a1 Y* d" e
FailedIndex.RemoveAll();- {: `" X" T; O6 a
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);) V0 r5 r/ q- c: j6 B1 u$ n
if (E_FAIL == rc)4 L% Z# w" l5 X9 O* H8 G$ `
{2 ?" Y$ I& {" v4 f" z* B4 C
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;5 }4 m/ q( d7 ?7 c- j ~
}
/ t( c; K: @* V8 Q5 B2 M* H5 m9 ]+ ^. X else if (S_FALSE == rc); b N, G6 O3 P8 }
{
* n+ U! u; w$ U( g4 M, j int nberrors = FailedIndex.Size();7 \( y1 ~' |3 D ^6 g. ?
cout<<"Error, setting applicative attriutes on faces fails for faces :";- g; i0 a. K$ H, F( H7 y+ Z
for (compt = 1;compt<= FailedIndex.Size(); compt++)
' s. Q" @# b, _/ ~ {1 l, f/ |) S! y) x0 k0 I. R$ n1 t
cout<<" "<<FailedIndex[compt];; o2 K3 {1 k$ @& G# D
}
# z) [7 D# {& q/ C) P cout<<endl;
1 q# f; k$ e: T/ L }+ @6 K t5 Z' n& X V, t$ d
else n1 H5 N. z! V. {# I$ n+ ^
{* C4 ]* h( V$ b, C' c
cout<<"Applicative attributes successfully set"<<endl;) T( J9 f4 S I' E
}
3 Y( B) C, \. F% N8 A' x) Z' i* b5 L4 H4 ^9 K
//10 - 3 cleaning- a( H* R/ d. g
for (compt=1; compt<=nbfaces;compt++)
0 g# D5 g: O" X3 b8 l4 x! g {" l& _2 b& h3 T- i6 Z+ b( t+ {1 O3 i' O. ]
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;/ O3 |+ B0 [9 g- w! f* t. {' N t
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;$ q4 f }) F- ~; n1 C' \
}
. d k" U: J/ t" I
3 U0 r9 m5 d% D) `: n% Y6 V, ] delete [] AttrNameListToSet; AttrNameListToSet = NULL;! g; a& ?5 d/ _
delete [] AttrValueListToSet;AttrValueListToSet = NULL;# a8 C* g l8 D5 O/ D
& i4 x& l' K" [# ~ //; c4 f+ X F f$ J# m& N" ~9 Q/ x
//11 - Retrieving the applicative attributes we have just set
3 r% n$ h9 ^; p. C //3 a: H$ f) K7 I
cout<<"--------------------------"<<endl;
8 M5 q' ?& ?, a, z2 F cout<<"Getting applicative attributes on faces"<<endl;1 e$ H& O5 Y$ W& m& J4 U
//$ l- `; X+ B4 o6 ~4 T
//11 - 1 Getting attributes
, h; R3 F7 I$ [( E CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
$ C" Z+ k# i( E) M2 c CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];& x, J$ {' O/ l2 o7 q6 r
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
, r( S: }/ R# T. T* D& V if (SUCCEEDED(rc))# U( d5 w6 C6 g; U5 d1 v
{: R7 G1 v) R- Z) r g4 D C
CATListOfCATUnicodeString templiststring;
. @* i2 m L8 j5 Q1 g! U2 f CATListValCATBaseUnknown_var tempCke;
0 X+ ^2 h* E: `2 S0 G for (compt=1;compt<=nbfaces;compt++)
3 n; b; o B. h* g# G( j) U {0 K/ O& g7 g. m2 M& a4 z9 m
//retrieve a list a position k (arrays start at position zero).( T: { q, B! Q) J% k! ~: t
templiststring = (AttributNameList)[compt-1];8 |& c; Z5 C o+ Y; X
tempCke = (AttrValList)[compt-1];
& `* W" Y4 I# i& x8 @7 N$ a7 Z' C, F9 X7 Y# e& A
int nbAttributes = templiststring.Size();
/ g# _' ]1 B' r b int nbValues = tempCke.Size();
! N: t' i1 V+ n( T- Q& Z9 Z5 |& o0 g! a: P
//the list must have the same size! If not, we jump to the next face
, W% j5 i1 f* \8 k) J# C if (nbAttributes != nbValues)
% ]7 h1 d4 E/ m) B0 A2 Z { K6 V' h" M5 j7 |7 N
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
% A( I/ u% e5 B* x continue;! `: s/ x2 a; L' J
}" a3 b0 T" j% M9 @+ Y' c4 d% [
else
; n( P$ }) z, M6 U. E {. S5 C! R2 g7 H$ D+ ^
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
$ M5 O4 f9 B. U( h' ?- _ }
' M, n' \- r3 j# s% d for (int i=1;i<=nbAttributes;i++)+ A- k4 i5 ~0 G* ~/ [: G
{
8 V" [- ^) i1 W6 c2 n, A* i" _ cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
. H: w( {; ^5 u9 Y7 y }# `' @, A! U* f2 i' ^# h0 `
templiststring.RemoveAll();2 S! l9 [* b4 _/ S
tempCke.RemoveAll();8 ^5 O! c& ~3 m+ [7 D1 U0 F
% h. u! y2 k4 t q" n {, G
}
4 j5 {1 d! b! c2 O* V+ G }+ c9 _# H. T5 |4 H
else if (E_FAIL == rc)
4 l9 }8 S9 S5 {! `2 ^9 @ {4 X1 f7 z9 r. K$ b% t% i F y* x3 m
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
: `- A( e. K1 u$ f$ A5 ^ return 1;4 z& v; k0 ^* p9 G! y" e4 }$ ]2 d2 H% H
} ^1 s" B! o0 E* _. _0 V4 w
//4 v+ u% A; d3 n: Q$ _
//11 - 2 Cleaning List:7 t2 z" p" ^8 ^7 [, U# `) `# a
int i = 0;
" m' q0 f7 ^, g0 x% X$ t for (i=0; i < nbfaces;i++)
5 k8 u; i4 i( ?* ? {/ P8 F: y# J; R& S9 R$ O& [
AttributNameList.RemoveAll();
) C4 a6 J& r8 m; `& T3 A5 Y AttrValList.RemoveAll();: l+ P, `: }3 ~# G1 f
}" i( G" t+ ^+ Y0 v
delete [] AttributNameList; AttributNameList = NULL;5 M3 @6 t. H% p1 w. h2 b
delete [] AttrValList; AttrValList = NULL;0 u$ l6 ~" c0 I. G- j
4 s9 {9 u$ z5 S/ M8 K7 H) H0 K for (i = 1;i<= nbfaces;i++)
% F$ C7 B2 \" n- V/ @' Q' }/ K {9 i0 D) h/ s; }" g/ c0 m- y
Brep = ListBreps ;. o* b$ w. u) ~ t: h3 P: @
if (NULL != Brep)
( |4 C2 J5 P5 `& M7 \ {# o# m" ~- w/ ^; I
Brep->Release();
& h5 \$ J, T8 L5 n. L2 p2 V }' j4 R# Y2 |4 P
}! E& E# \/ j2 {3 S! h
ListBreps.RemoveAll();[/mw_shl_code] C8 {' z8 |* g" d
|
|