|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]5 T6 H2 T) v, l" h
//
- P' H. ?( y2 T- b" O# u' [ //7 - retrieving and displaying current faces colors
( m0 Q9 m$ `# x1 y5 } //
2 K' `3 d* f2 {2 W( [" K5 R% \2 ^! s cout<<"--------------------------"<<endl;' c; x, }& c- B! j0 `
cout<<"Retrieving current colors"<<endl;
0 D. I6 ?, O: k) p% F' [( B CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
1 y! s. L% o: _' s! d. P. c$ ]
* \ D) s8 J! g! }+ b rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);! N- W' `; |6 o# Q
if (E_FAIL == rc ) v2 I# C7 z* h3 X$ K/ \1 V
{: X" s/ ~4 D7 h" w# h9 |
cout<<"Error, an error occured while retrieving current part colors"<<endl;$ `, A2 p8 l! h
return 1;
1 A) z4 f/ Q) X, L2 h }
/ W' v6 q3 G$ B# a/ F+ z$ W8 O
' B9 z* |+ k V6 j! `* P. R: ] for (compt =1;compt<=nbfaces;compt++)
; Z% e' m. I1 j5 A$ z/ y {2 e4 _/ j$ g! k1 k3 c% W) D
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
' ]) j! d, V* ?; n( c }/ M; m& I: b3 i" T. S
0 y" y8 _ K+ i' H; {, h8 _: ^1 c. k
//
% a* x( J! v }, L- [3 Q; E+ ? //8 - Setting a new Color on all faces [2 H' y L3 }- T* Q& P, V) T
//
: R G& t, A! b# G' t1 X) H j& g
/ X) T& f. X# Z$ y //we are to color the faces with different color according their position : three by three will have the same color
) x3 Z6 s8 Z/ O; H& N cout<<"--------------------------"<<endl;
# M' _& d. Z$ m: i cout<<"Setting new colors"<<endl;
9 Q7 }( L) K: q b6 s " [9 S0 k3 d( |% b( Z( v
CATListOfInt newRed,newGreen,newBlue,FailedIndex;5 h) ^5 A! _ U. J" a; x
int x=0;6 V6 A# V4 v' ]& a9 j
for (compt = 1;compt<= nbfaces;compt++), }/ A# f5 |* `
{
7 [2 }. b* Q( E4 q Y2 [) ~, G x = compt%3;
3 c- A( l& w+ g' U+ W% _ int red(0),green(0),blue(0);1 [9 i, J5 t5 m
if (1 == x)
3 d7 E( k7 R) k6 n' _, m! } red = 255;2 [- X8 u2 P+ X
if (2 == x)
6 p# k, x g# q3 C: w8 g green = 255;) w! m4 L$ F" r" b' a: C3 w3 N
if (0 == x)
- v" s( \6 F! P7 G @ blue = 255;
/ G1 U' T' [( w newRed.Append(red);
) V6 ]6 C/ e3 j' B% }. I newGreen.Append(green);2 s' u: k$ q9 d, I- p4 l$ u
newBlue.Append (blue);* [7 i# [9 n6 i: ?$ J& v$ L# T |
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;; A* G2 n' M* E' A: _6 t
}) [/ l6 f, b9 _6 Z! u
( ]9 Y/ V6 K* E
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);. o( h9 [2 \2 b2 _$ O$ D
if (E_FAIL == rc)
" b' P. K) r# L* t' p% M {+ q$ k: |4 _1 i. e7 i" d8 W l
cout<<"Error, setting new color on faces failed for all faces"<<endl;) q2 b7 S7 v. l
return 1;& G3 R+ L' e: ?: A( i
}
; r2 Q. T- V; W( i: L e else if (S_FALSE == rc )
3 M6 [4 W/ i! q- k0 m {
. y/ O- L+ i' W5 F int nberrors = FailedIndex.Size();
( Z* u2 \; v4 d# `; M cout<<"Error, setting new color on faces fails for faces :";
# S$ T/ ~2 v9 M K7 j for (compt = 1;compt<= FailedIndex.Size(); compt++), u9 }- D* A9 T) A/ G6 l
{
2 ?3 E2 ]0 o& X+ f" Y8 K cout<<" "<<FailedIndex[compt];
4 K! { i* L# E. C- @ }1 q0 [4 g b" r' a8 {
cout<<endl;" ^ c. G) n6 T$ @
}8 q6 u) f D* O6 f3 C
else $ S8 A, E, M) Q& s @
cout<<"Colors successfully set on every faces"<<endl;; |+ u: q6 k6 d' Z/ K4 P
//; r+ t$ @# J% m' I; W1 M( K
//9 - retrieving colors we have just set3 L0 b Y$ v; N+ }$ ^5 v
//7 f6 o4 O* Q$ E: |* k2 c
cout<<"--------------------------"<<endl;2 R) J! a+ D4 r% {- ~1 Z
cout<<"Retrieving new colors"<<endl;
+ }( ~" Y: n/ l rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
2 i& g5 J$ d% I7 d if (E_FAIL == rc )
$ M# S: K, @( { {
7 |, x+ m) r0 p# M- V0 V8 u# ]) v+ c' G cout<<"Error, an error occured while retrieving current part colors"<<endl;# ~ w, c( z( ]" A
return 1;( `7 a% y: N& C
}( j, o* B9 Q Q5 {3 K4 ]
0 o0 _% y" b3 N; @# A% }, K/ f" d- y for (compt =1;compt<=nbfaces;compt++). [- ?; [+ b& F2 u' Z
{
1 v* i" O. s- g; B! s9 N cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
+ ?* N9 G4 l/ {0 N, _' i% [ }: d# S7 ]& w6 {; s& H
- O4 t( B0 r/ X. a1 P
//( q9 p9 ~) L# `7 X
//10 - Setting Applicative Attributes/ x5 j9 H2 C4 N9 p% ]% u* s
//
2 c$ u `6 F2 }8 L+ Y
3 ^2 o7 ^; e. Q7 z8 R, d L //, u" A" N1 J, h" U
//10 - 1 creating new attributes
4 x$ g) _! y4 Q4 g cout<<"--------------------------"<<endl;
7 s! [6 t/ j7 o" W7 F6 Z cout<<"Creating applicative attributes for different faces"<<endl;0 r- ^$ D, H/ L2 v1 f
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
; O" J) x3 g1 e7 S9 x CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
3 P2 q- u, K7 H& ]9 k) i" s) Q, f CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
; f z, d0 G0 l$ k T for (compt = 1;compt<= nbfaces;compt++)/ e- f& B9 s5 O
{
/ \/ E# h/ { J, }# y0 Y cout<<"Creating ";1 ~: z- @% g$ D7 |5 H
x = compt%3;+ O* R3 @8 V: S& |2 y
//for each face we create a new list of apllicative attributes% }/ J" i8 Z# Y+ h
//an applicative attribute is made of a Name and a value4 [# U5 {& X( l( U# F( ]7 W
if (1 == x)- k$ L& ] `; n( I
{
, I# k3 [ c/ [& ]. D! d4 s5 V9 b AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);/ p* b7 ]9 E( p
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
" C/ g3 w2 F0 s* v- _
" e( U l# t7 c7 I0 a6 O: [; D9 q //The first attribute will be the number of the face
/ S. @) \% |9 ]/ ]# D& v2 d" K AttrNameListToSet [compt-1]->Append("FACE_NUMBER");9 D, b; a U' v$ _% @- m) I
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
. s8 }9 a6 F' m& t' J5 C: o AttrValueListToSet[compt-1]->Append(tempcke1);% ^6 f; x" G) t/ V1 @: P7 ^
! {2 ]) O; O7 x* u) ~ cout<<" FACE_NUMBER with value "<<compt;
- N* t2 @; V" U- c
% r- N( n2 c& T+ d/ R8 p P //the second will be the color
- H% ~; Y( e/ P2 d AttrNameListToSet [compt-1]->Append("COLOR");
1 T4 g8 K" K% U( x CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");6 `; Y. y V, u. J) s
AttrValueListToSet[compt-1]->Append(tempcke2);
7 Z& h+ y0 A9 T' b0 c; _ " F3 a) c3 \4 N" Z' r/ n
cout<<" COLOR with value Red";
8 h9 i6 y b: r+ v( E* [$ E
% f% E: h+ q' f1 a2 X$ b //the third is x
9 O% ~' I5 ~/ c& s F0 r AttrNameListToSet [compt-1]->Append("X");8 g' }! Z2 c/ Y
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);7 D4 W* ?- B9 h I# I4 `
AttrValueListToSet[compt-1]->Append(tempcke3);
& K: P" l% k0 ^+ L+ E : ]! ]0 f+ V, q2 b
cout<<" X with value "<<x;
7 d. t4 J( M$ n3 E+ v5 g" e B cout<<" for face nb "<<compt<<endl;
6 w; Z. \& T- w7 V }4 W: O- f% b: w8 {
else
/ Y8 [0 k+ p) J6 \3 i0 o4 S //just to show you you can have different size of list
7 M6 Q( K. @& V- m/ S6 f$ n {
- D1 q, Q! B0 I+ |& @ AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);7 y+ D0 p: I2 z" @' W8 G
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
9 W" M' E& a7 C I6 }; B$ f5 H
//The first attribute will be the number of the face1 ]; ~# q% v# ~
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
( x( d- V; ?% G2 l; Q( V# E CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
: I# q/ D5 V J; n T7 s% h AttrValueListToSet[compt-1]->Append(tempcke1);
. L5 Z) T! z3 j8 D( o* R+ T2 I2 ~1 U: a- `1 Z! E* P/ b' s
cout<<" FACE_NUMBER with value "<<compt;
, |. _5 _9 e% r5 r& F
4 @. y. }7 ]5 e" t3 I: v* ^ //the second will be the color3 `" z" n3 S% c8 c5 H' l
AttrNameListToSet [compt-1]->Append("COLOR");" v2 R2 `) e6 b% W- ]
if (2 == x)2 I" k2 z3 e4 N t( _' R
{5 m% ? v& d/ }; s
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");' i; B% @) x* t4 k( t+ n6 c
AttrValueListToSet[compt-1]->Append(tempcke2);- C- E7 S; n! f: x8 o' u! L
6 ]' y/ P) t, P% D/ P cout<<" COLOR with value Green";: T4 S, _& t% A- `' D7 H' y
}
6 ~- P1 H: m. k; ~# z1 n k; c% C if (0 == x)4 g, g7 l. L2 v! R, u
{8 S( W" t" P5 A/ [0 A* h
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
& U7 X; M ?2 v7 U, q% H s AttrValueListToSet[compt-1]->Append(tempcke2);
% O; R+ L4 ~* M6 F0 L . K5 }4 E8 d8 K, {
cout<<" COLOR with value Blue";% I- X$ U3 D# s3 j
}! f- m) _9 r6 T' b! p. z
' z! B. K; |5 D) S cout<<" on face nb "<<compt<<endl;
+ x2 X" k' x0 ?# y- a# W: Q; w: |( [' H6 h" n
}
$ p' O5 F6 ~; @! n& ^ S2 ~# ^ }
9 k" k- O( f* O3 m1 O2 [9 u, K! t# M5 R0 E$ M
//10 - 2 Setting the applicative attributes
7 g2 p/ l# b2 K( c8 }/ f cout<<endl<<"Setting applicative attributes on different faces"<<endl;
: V0 b3 P& {$ j; u. ` FailedIndex.RemoveAll();
* q Z# F# @, x5 \8 U rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
+ a4 W' a+ P5 H! |' z0 e if (E_FAIL == rc)$ M! {$ N2 I5 W, ?1 m8 j. G
{) q: r5 d, h, n
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
! y2 } C" k' W3 h1 ^ }
% |) F) y% ` O4 e else if (S_FALSE == rc)7 j/ [- j+ l* V
{
$ i W0 @& s# D int nberrors = FailedIndex.Size();
! O5 k, p; C$ J; T! d* l cout<<"Error, setting applicative attriutes on faces fails for faces :";
4 j- H! o- a# [9 g% ~ n for (compt = 1;compt<= FailedIndex.Size(); compt++)/ g5 J/ I4 \- e5 [
{
" _6 R4 ?, i8 ]5 L4 P5 { cout<<" "<<FailedIndex[compt];3 p% v2 O0 n3 G: t% A% s- S! T8 L
}- Z1 [/ G. b ?. t9 ]. ~
cout<<endl;
6 c3 g3 A' D( d7 }7 |; ~' C( F }
9 e( ?4 ^/ z( I! g2 y- x else
7 D+ h) y9 ]' x& S/ S8 a$ T {
! h0 o6 D) h% D7 `5 K% ] cout<<"Applicative attributes successfully set"<<endl;( E* m" x/ ~: o$ _
}
* } }/ L3 q. t; |4 A# V2 v" O" Y9 R( `. _
//10 - 3 cleaning$ w, E0 h: _5 p7 m
for (compt=1; compt<=nbfaces;compt++); \. C0 Y& k4 K# S4 o, i' l1 q/ ]* q
{
3 a# U! O3 y( q( B AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
8 D2 Q" X' H5 v7 m- l o* k AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
; O6 O$ U/ C A1 S }
: o# X) r9 r$ x! }6 q: {* S7 ~
; C3 C/ r2 q# Z9 Y' X2 X delete [] AttrNameListToSet; AttrNameListToSet = NULL;! l7 @) F. q, a7 D1 |
delete [] AttrValueListToSet;AttrValueListToSet = NULL;$ f5 u" J$ }& W$ [) e- t8 X
& l( }$ P/ O; }2 y1 T6 z
//
* a" T; V9 f1 j' M //11 - Retrieving the applicative attributes we have just set# {" [$ A1 Z& O% C
//
6 L5 q9 `& F6 Q6 D! W' s cout<<"--------------------------"<<endl;
3 j9 }( R: d, A4 m cout<<"Getting applicative attributes on faces"<<endl;0 J8 k# |/ }5 M L, x: i
//# U" }+ N$ L3 s7 W. n5 w
//11 - 1 Getting attributes) K9 M; l5 }5 r* ~ x$ w
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];6 c8 ?* s; A0 y& W9 I
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
- O' H* z6 Q/ A @" u6 s rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );8 R9 K) c+ p0 `$ l' M
if (SUCCEEDED(rc))/ ]5 ~6 s# [7 k7 m3 P, i
{
: z* M% {! Q# q8 o CATListOfCATUnicodeString templiststring;" C1 d" S% i/ p) v0 _) h: O
CATListValCATBaseUnknown_var tempCke;
1 x: q0 p! I+ |+ [9 Q for (compt=1;compt<=nbfaces;compt++)( C ?+ a# I$ q. }, i
{
2 }2 T$ U) [/ D' n1 x& D8 T //retrieve a list a position k (arrays start at position zero).. \3 l+ q( Q. f0 d; k; Y
templiststring = (AttributNameList)[compt-1];( Q# A; ?$ t" a: ~) e
tempCke = (AttrValList)[compt-1];
* V, E+ y3 ?" M. e* {
. s% v' y, |2 b int nbAttributes = templiststring.Size();
3 D5 x m" Q J5 b int nbValues = tempCke.Size();% V8 n, P: l6 M. `6 S
7 Q: p G9 ]7 @8 i
//the list must have the same size! If not, we jump to the next face/ B* b7 L9 l3 V. i1 a6 L
if (nbAttributes != nbValues)
9 A0 o. m$ W6 h {
& H: P {! j5 d3 w: z, j cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
' c- A6 m- [0 g continue;5 Y5 ~* P& u, {( g
}* G2 _1 j' ?) F. V
else6 E1 f% G( g; f
{% T% O1 Q8 p9 v* T, X/ w
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;, Y6 O4 Q+ J; W7 U' ^) U8 ]
}
) S# |' j) Z* {+ S7 v1 d- h8 J$ v for (int i=1;i<=nbAttributes;i++)
: [' L1 d0 X3 a2 e, I6 _ {
0 T$ O2 k+ y4 |! n9 _ cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
. j9 a5 E3 }1 V/ X }$ g* f+ j3 c+ C* y8 z: G# b6 q
templiststring.RemoveAll();
8 y, L: K9 C* o' q tempCke.RemoveAll();
0 b* d: ` W! k
- X5 |6 x7 m6 b: t }
9 h0 Y% f, D% u6 \! m9 F }
- r' e, {5 y/ M# z7 i else if (E_FAIL == rc)
# Y4 a/ ?; {4 } {
3 I" _0 a/ z% l/ t4 ~& G cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
/ u' @9 i* h% a' d$ X! `5 e* k- j return 1;* Z8 O+ F/ d6 D* b$ y( G
}
& E/ w4 t% g4 J, j //0 a2 h3 }" f: P# o
//11 - 2 Cleaning List:3 z/ {4 |9 V( V) V5 U- C" H
int i = 0;' w5 ~7 s3 S/ h+ F0 G% {
for (i=0; i < nbfaces;i++)3 P' o. c T+ y8 U9 ~
{
?3 Q/ o* J X" I' a7 R. Q4 \ AttributNameList.RemoveAll();# c- T& h$ ~4 J( U
AttrValList.RemoveAll();+ \! z( W4 }! ]: K) O
}! d) j' \3 r0 X( V; {
delete [] AttributNameList; AttributNameList = NULL;
/ w$ }* Q g: H delete [] AttrValList; AttrValList = NULL;: m8 T8 B5 j- R
) i) N% h% x. l7 c- v# Y for (i = 1;i<= nbfaces;i++)
$ a: W+ `6 K: N; a) f" B% P {+ b) v1 K! A# O& O- r g
Brep = ListBreps ;
/ \% \. J1 p+ C if (NULL != Brep)% `0 t# m5 s/ ^
{
' `3 Q* |+ c, B4 K$ I! V8 c8 q/ r Brep->Release();! j: m X: T: n3 P9 F& X+ N2 z
}
5 q% K4 K- @- n7 m# q, ^ }
7 ^! E$ y/ e8 j0 _ ListBreps.RemoveAll();[/mw_shl_code]
! t1 H3 {) S+ R, K2 U |
|