|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]* C6 W& t+ z) l
//
1 S* F ?$ d" R //7 - retrieving and displaying current faces colors
; ~ J6 B" j, q8 V3 }! N4 }8 } //
% H( e) O( i: b u9 Y cout<<"--------------------------"<<endl;/ q0 {8 r& Y, y0 U( u
cout<<"Retrieving current colors"<<endl;3 d2 ?) V4 j$ ~- `8 g1 f4 D
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;0 q2 E9 [& R @
% @ A4 C) l) t1 y5 D3 V, I
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
0 v$ _9 E$ C. E& }0 c if (E_FAIL == rc )+ a- b- @# ~& K; W2 F* Z
{
/ E; K5 ?, E, g$ l* c- J! Z" H cout<<"Error, an error occured while retrieving current part colors"<<endl;
! \( l+ s/ `- d# e0 ]9 R return 1;+ T. _9 ~( g( b9 o" M
}
/ ]; }8 c/ S* a) ?+ F0 G6 a# }! l4 a: q2 {( Z1 ~
for (compt =1;compt<=nbfaces;compt++)
$ h: z" \( O% A @4 A {
; m h6 ~4 Y" F6 K* j# _) f" r1 i0 o cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;0 M4 Y4 x8 ~! ^9 o' f
}; w' f% H0 l: T
2 j7 {: E. W! w* `; X //
7 U- J$ y+ Z2 i( T+ j //8 - Setting a new Color on all faces
5 T' ^5 L) d B" J9 t9 Q //
1 ]; \- u3 k4 `& e( z9 F' S6 m2 U9 M# q
//we are to color the faces with different color according their position : three by three will have the same color$ D0 D+ P/ c9 ~6 {7 K2 h0 K
cout<<"--------------------------"<<endl;# L( L I6 H# k
cout<<"Setting new colors"<<endl;
" W6 W7 l$ n4 ^8 C+ q
% V8 B8 |% P6 h! g2 m3 Z& \ CATListOfInt newRed,newGreen,newBlue,FailedIndex;
* e% q4 M& N1 t/ G$ L7 s$ U int x=0;6 G! p8 F Q3 X! M2 M( _3 ` }/ T4 S1 ~
for (compt = 1;compt<= nbfaces;compt++)
4 n- N5 y. P4 F1 f/ b {
+ S6 J- `( @' E( @ x = compt%3;
6 u9 n8 A+ i3 J2 r" l' F7 I int red(0),green(0),blue(0);
L. f# L9 \, f if (1 == x)" q' U* [0 U" d% B0 p
red = 255;
8 x& v- s @6 }7 m if (2 == x)
1 W! n. G1 L/ w6 e2 M; l green = 255;+ B+ Y3 S3 S2 `( m7 h+ X* R
if (0 == x)
# {! U) q$ w/ F% L9 H8 P blue = 255;1 U2 e9 h" s, E) s+ ~
newRed.Append(red);
* N& x# w+ |+ t" @7 G8 U. k4 \ newGreen.Append(green);- y% V" b0 }8 b. x1 I# g
newBlue.Append (blue);8 x3 i0 W+ A9 \: M& R# Y* O& @
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;3 T0 _* x: V5 W# ?5 c: V& K
}
6 f0 G, U- {2 f: G( D* D9 A4 R9 a, w' [: j
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);# H2 G1 _- ~4 W1 b0 O
if (E_FAIL == rc)) x1 f* ]6 y7 q3 R1 C" r
{
/ T3 b" K0 K' K/ Y/ | cout<<"Error, setting new color on faces failed for all faces"<<endl;
0 d' Z+ C% c/ c3 q& R) s return 1;
; D$ T6 O$ N. N# ^ }& A/ m% R; M0 y7 N$ X# j
else if (S_FALSE == rc )
$ _: q6 q4 ]: r0 x {
+ P B) z3 X$ O/ N) c int nberrors = FailedIndex.Size();
; j) |$ a) w$ l8 d8 G$ F, W cout<<"Error, setting new color on faces fails for faces :";
, _" s! z5 H2 |/ {9 ^ for (compt = 1;compt<= FailedIndex.Size(); compt++)
0 A" Y! o: P6 V k J& M3 q: o {
% F" ~" F+ C$ o, g. c4 g cout<<" "<<FailedIndex[compt];
' ]# R; s2 i& s) A0 b3 u }! G# o6 A1 Q d, _: ^
cout<<endl;/ M. y& w% Z; A
}. V3 ^: g: A7 s) G
else
: z5 `+ S: F( K% d# w: r cout<<"Colors successfully set on every faces"<<endl;$ y% G. B1 A" r" ~# g. q: w
//
8 r, z6 V- e9 V; S) Z) a //9 - retrieving colors we have just set
2 J' \/ K% q2 X) E //
! n- Y9 {# Y' A0 H& s/ H cout<<"--------------------------"<<endl;
, x8 h) e3 g( l0 j$ B5 @ cout<<"Retrieving new colors"<<endl;3 r- S( V+ t3 q
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);0 a+ ~# p! R% z8 o6 m" {' A
if (E_FAIL == rc )
/ o# ]! X6 a% F5 n) G1 j" M, I9 t+ [2 ] {) {& Z/ n1 D1 y% o% ^& Q* c
cout<<"Error, an error occured while retrieving current part colors"<<endl;" o, t' s4 A+ J: g2 [4 o" h
return 1;% k6 a. w& [) E. I$ R
}( N: i6 Y. X! C6 }4 |* t
9 Q6 }7 F9 f; Z
for (compt =1;compt<=nbfaces;compt++)
$ t5 Z$ h+ L8 I/ u. g% d& |& k {
2 f- n$ A1 C8 J# ^- e; N2 b$ u' S cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl; `! Z# f ^4 q& d: { ]9 j7 k
}
" w+ `2 _4 g/ R4 n+ P4 ?$ E: l2 ~2 G8 f8 W+ m0 k9 ^
//6 j* o" f0 `" }: Y0 g
//10 - Setting Applicative Attributes# N5 z; o7 t' L& F) T) [
//0 B0 S, _4 O+ `+ G8 p% S8 B
' y2 Z/ `/ C7 M2 d8 J- w* t //. x& p5 z. [& L7 j; a
//10 - 1 creating new attributes
* k! A, h0 S& u& d! s cout<<"--------------------------"<<endl;' E; E$ b1 D4 x9 S X
cout<<"Creating applicative attributes for different faces"<<endl;4 h( z4 _ c1 O0 |" n$ v; H
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];, S1 w: n' e; Z2 i. m! G3 U1 g
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];# |* S; l# i7 ]9 c7 G
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
! q. }4 k$ E6 K, y for (compt = 1;compt<= nbfaces;compt++)
) c" ?& @9 F' t* J9 R! ? {
2 Z) e6 r2 e' _/ Q. v! l$ M cout<<"Creating ";
. ]) Y4 K& x+ C9 P O6 U2 A3 K( o x = compt%3;! L9 v1 t' k$ I% W8 u
//for each face we create a new list of apllicative attributes L: l p$ s% C; t9 h
//an applicative attribute is made of a Name and a value) D7 v, @; J6 a$ c W
if (1 == x)
: X+ @$ ?! ~3 ] {
! O. P$ c7 A! O" `' X AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);& U, @' f/ q# Q4 I
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);; O& L" l9 q& J3 S2 Y
8 u! u" i1 o6 Z1 P. q) x1 z
//The first attribute will be the number of the face7 v+ G; ]3 i% k) s! ?4 J
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
8 Z9 [' l" G% O% a! D- k: | CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
& F( H: V' x2 |! J! l AttrValueListToSet[compt-1]->Append(tempcke1);, `( H( f! D' ~( T9 \7 c9 f
1 `1 Q1 T3 ^( B* d6 H. m
cout<<" FACE_NUMBER with value "<<compt; 7 c1 H6 T( r: E8 D7 U. A8 m
+ @; c! J c; m4 M; Q1 |) O; N
//the second will be the color) b% j7 f, K! a* ~
AttrNameListToSet [compt-1]->Append("COLOR");
% _8 B/ R5 A7 N- h7 ?% p CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red"); n8 h) A( h7 D g
AttrValueListToSet[compt-1]->Append(tempcke2);
" [7 @ T, ^: D( ~) e 8 i; Z( \+ L' k, e& e Z F
cout<<" COLOR with value Red";& }3 ?: i& D G3 O& Q8 y, ^
/ \& x4 i! h& Z1 h* `* O/ @
//the third is x
, G0 V% Z5 q1 D AttrNameListToSet [compt-1]->Append("X");
$ q2 a' x* F2 ~2 H9 D# F CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);' I! Y, Q0 x/ W4 i, y/ o
AttrValueListToSet[compt-1]->Append(tempcke3);0 T- @7 @5 H* \3 _4 Q
3 j+ B7 `* S6 h' Z. }6 U/ L* Q# ]2 c cout<<" X with value "<<x;1 p4 Y" M$ f: f
cout<<" for face nb "<<compt<<endl;
& [! z+ s7 F* F: W4 ?- t2 X! J }5 b3 Y& w: B0 `; W: V( F5 q6 _3 i: Q
else 6 W' q' `' p* r* ]9 J/ ~0 F" U* A
//just to show you you can have different size of list B8 m9 @2 s. y$ ~
{
2 g8 t# k7 S# q, ?$ T AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
9 z" k! q9 `" N AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
! W) F% D) D* G1 N5 N5 a- e% E% y; u
//The first attribute will be the number of the face0 @# P! _) I, e2 g5 B
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
* M, n Y J/ @& w CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);- ^' D- a" Y9 G3 Z" q9 ?6 J5 U
AttrValueListToSet[compt-1]->Append(tempcke1);
) I) O& f# j, m9 Z2 U* j1 G# c' K
- P* F$ h7 G7 J; F+ X2 L cout<<" FACE_NUMBER with value "<<compt; 6 [3 I0 d! n& ^4 ^, T5 ]6 T1 l
$ r3 R" M' K w$ x. {$ ^
//the second will be the color+ A: }4 h4 J! q# U$ I7 n
AttrNameListToSet [compt-1]->Append("COLOR");/ I0 M: t% w' a5 ?
if (2 == x)
7 |- m2 y& V; k* ^7 B1 B* P {. g1 y5 Y9 {: ]! ]
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
- R, A1 A# [; ` AttrValueListToSet[compt-1]->Append(tempcke2);, c5 r1 B5 `6 v% ~( g8 z( R, a5 ?
6 t" J/ l2 _$ d1 n; }8 Z
cout<<" COLOR with value Green"; ?, _9 }: [$ ~& n
}5 S+ Q$ t/ F! _" s
if (0 == x)
4 O$ O" W* f$ F* k! I5 o {
$ U9 c! _' K" d# E& m CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");% D3 u: P5 P7 Y' {; B
AttrValueListToSet[compt-1]->Append(tempcke2);( x( F! Y4 m$ m2 z% h
2 K, k( Z/ m- {- I' u3 B
cout<<" COLOR with value Blue";
& u) G1 f6 a) h. _/ T }
: t, g! P/ Y7 u$ \$ p1 h" F x3 o6 d
cout<<" on face nb "<<compt<<endl;8 v8 n) `& A6 [, r; g
) z: T; a% c( c" z. i
}5 l- `, n$ K k" R! K+ F
}7 \2 G4 x) d" e, R" v, ^
3 J/ |. m6 } z p3 }# s/ V2 o
//10 - 2 Setting the applicative attributes
: \7 @6 V, j; ~0 d) \/ K cout<<endl<<"Setting applicative attributes on different faces"<<endl;
5 y/ N1 L% V- e" T9 q FailedIndex.RemoveAll();
& v2 S: o1 q8 v6 B rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);9 [$ @9 b( s: l: v! W
if (E_FAIL == rc)7 ~3 k/ t8 K2 k2 a9 } |
{
4 J6 U) m) q; ], {+ a6 B1 a cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
, f! Q3 j# P" I; `9 v4 ? }2 Z0 _6 c2 Q$ l
else if (S_FALSE == rc)" g3 J3 e F. ^
{" Q: ^0 Q2 {' @: g3 z( W$ @
int nberrors = FailedIndex.Size();
) t5 v* j* c8 D( |0 d7 C, z; Y: E cout<<"Error, setting applicative attriutes on faces fails for faces :";
/ y8 r) K3 A2 i5 `- {# X for (compt = 1;compt<= FailedIndex.Size(); compt++)1 g4 m0 A, t# @+ H1 P; k
{# v& j! G3 A0 S, _3 D
cout<<" "<<FailedIndex[compt];) \& f) H' |! Q0 u- F7 g
}7 ?) d9 R: p8 W- b, F
cout<<endl;
6 N2 {2 ]3 _) Y K3 n/ ] }
# w* ?. h( V. U( e; \4 u( L( u else
6 E0 D$ m+ l" @ c4 d {
6 O' U! [( ~ s* n2 o9 b cout<<"Applicative attributes successfully set"<<endl;
, L' C" I g n) Z. m$ i! A# K }
' j$ d' [3 U$ T% ?' _" M8 ]$ i8 Z$ s8 P' e0 Q# C
//10 - 3 cleaning5 N2 g6 \; Z- x0 [% D
for (compt=1; compt<=nbfaces;compt++)
- E7 f5 ? Z4 W3 L( o {1 J3 E1 w m, M1 {8 A: S
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;8 h" \( |$ Z, {
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;% g# V) D* h; X
}
( z9 j: x0 u0 T! c! Y1 w3 ]
6 C1 }! C! M9 d# Z+ S4 Z delete [] AttrNameListToSet; AttrNameListToSet = NULL;8 X1 V" s" b0 n3 x
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
) Q2 u! Z" n ^+ P
6 n5 g$ z }4 D8 J% r& A+ v //! v, o1 [- M% g; [& l% s. m2 W* ?
//11 - Retrieving the applicative attributes we have just set
2 F( y- G# N9 i5 ~ h //
% P" E+ E5 \! q+ ? cout<<"--------------------------"<<endl;
1 v2 ?) y/ E) D* S. C$ @6 ~ cout<<"Getting applicative attributes on faces"<<endl;
+ [ v/ ]/ l' Q- J9 D+ T //
7 ?; \4 H5 E x1 {2 y/ V+ v //11 - 1 Getting attributes& e$ G1 }. Z0 n% k- B8 a* j; \
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
, ? [" a5 l0 t1 W/ T: x; z CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];3 H/ b* }$ V0 Y# c
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
- N7 d/ Y% B& |4 T5 a8 a if (SUCCEEDED(rc))
$ |% J$ b2 j: t {
% r( ]0 Y9 \$ E. G$ y CATListOfCATUnicodeString templiststring;
1 O) p3 q4 ^& z1 H" c' E5 \& Z CATListValCATBaseUnknown_var tempCke;( |: H2 h2 y/ B
for (compt=1;compt<=nbfaces;compt++)* r' w3 q7 I; P. }* X& ?
{
0 j1 E5 P& x8 |) f% D" t //retrieve a list a position k (arrays start at position zero).* `) ?+ J# U3 Q: D3 h T
templiststring = (AttributNameList)[compt-1];
3 A j+ M! W& w% x tempCke = (AttrValList)[compt-1];% o! M" `4 u. i& G2 h/ n5 I
+ @ B( B, @0 H6 d& b$ T6 q3 |5 M
int nbAttributes = templiststring.Size();
; Z4 h% P) h' X6 j( V9 d2 P$ Z int nbValues = tempCke.Size();0 G1 v7 }" O5 V; l$ w, Y& e
: ~. D. F. o6 | //the list must have the same size! If not, we jump to the next face
! W4 U- \% }0 N- Q/ w' s5 M. | if (nbAttributes != nbValues)
0 l+ }1 T2 f9 P' G5 P8 E- c {
0 @9 |$ b) e5 W9 a cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;) t" ^4 H* Q8 {: U! {- X/ C( p
continue;
. q4 P; p6 I0 Z& H3 Z. ^: { }
8 p$ o1 o$ r, f$ A2 s* @( a6 A, ~ else
( y+ _* E0 o7 P9 s' |# _! ~/ o {% @* t p; m; J5 i6 I* l5 v
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;, O; L! G# l3 c7 O7 i0 G4 \# s8 p
}3 l) _" \; f0 k6 Q5 F* r
for (int i=1;i<=nbAttributes;i++), Q/ s* z- p9 p9 \ U% Q" P
{
' @- w8 V1 t3 T cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;5 h5 u) U) p' g
}+ a" A4 A6 H- x4 ~; F( M
templiststring.RemoveAll();
$ x4 @5 i2 v& c' u# Z tempCke.RemoveAll();
+ h" m9 b$ E9 h
# j1 s8 ~) d( F: ]$ T4 h }5 G B, U9 j4 j2 B
}
2 Y4 S; ~( ~7 w a' D else if (E_FAIL == rc)- ]" h; h+ D3 }. S+ s
{
* A1 C7 n3 Z4 v# t/ x p1 K cout<<"Error, applicative attributes couldn't be retrieved"<<endl;: l) L/ D$ ]: D0 X; R
return 1;
9 U" u R+ F: g+ W' L1 r }
( W& C( N; R+ [ //+ M; [- n& t$ F9 _1 f2 e, z8 T: o% r
//11 - 2 Cleaning List:& F. n$ P5 ], F, f7 `$ }1 N) N; }
int i = 0;# U) U. n' c' [4 h# P% n
for (i=0; i < nbfaces;i++)) V% U: T8 w$ O+ J0 v( W# z
{
: _! U3 J2 D3 z AttributNameList.RemoveAll();. T( n% Z- v& ]" A- R5 i: }
AttrValList.RemoveAll();
# `$ C7 e1 u7 ^, t* E: t/ R! h }9 R }6 _3 w) F# J0 n
delete [] AttributNameList; AttributNameList = NULL;' E$ a( C2 ?' G8 M k. X' L
delete [] AttrValList; AttrValList = NULL;
. a- o7 ]6 ^1 ?7 y. N
# h& P% x9 ^; a: a: W# [ for (i = 1;i<= nbfaces;i++)& {2 H4 v" l& ^ y: R y
{2 Z$ r: K$ W& S+ j: m3 D
Brep = ListBreps ;
4 N9 \8 h' {1 e% W% q5 @ if (NULL != Brep)7 b0 o* n* t* v @
{
+ p% I2 c6 U9 Y( G7 n# ^2 z Brep->Release();+ q, T; Z* o- K% e& K3 Z0 q9 O
}
0 P/ I) W9 j2 w- o }
( e. O! g( B( Q+ j+ {& e- P ListBreps.RemoveAll();[/mw_shl_code]) f- ], _: W$ Z3 F0 z D' G
|
|