|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]5 u, T+ \ U: z) o- X1 t8 L& N
//
/ W( R* m/ B2 E5 ` //7 - retrieving and displaying current faces colors
5 p1 o2 O1 V: C //0 |4 j) S n" r
cout<<"--------------------------"<<endl;0 O3 U& H" R% ~( `: r0 P, d- k; Z
cout<<"Retrieving current colors"<<endl;; r# n) m6 X9 i" I1 z: C0 v
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;- K/ U, U6 x+ O& G! Z* `9 s+ s
$ t/ C3 \2 c; H) |6 ], \
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
) w [# p7 C* Q if (E_FAIL == rc )
+ G6 W; P% h# U1 h3 T( ? {3 ~0 W+ B( A4 G& U# @. a9 A
cout<<"Error, an error occured while retrieving current part colors"<<endl;! F9 P2 T# E- {8 x) Q- o d& W/ T, O
return 1;
- g7 I, z& X; ?. ^ O1 K }$ H. r' L: B- i4 ~" ^6 `
7 ^- v' s# Z7 w& Y: q* W
for (compt =1;compt<=nbfaces;compt++)9 N* A& Q4 }: ^ ?7 B4 q$ a
{8 r+ s0 S* d) z J% r0 m
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;( e. T' q: [4 g" h C
}
( ^. d& T- r! G) X6 S; i2 J: h
" z2 G) |6 O; F2 ` //
- x$ i0 @( J( l% K5 T //8 - Setting a new Color on all faces
* q8 D: ~" O: E% R) i' x1 S) P //. D+ P+ b4 L' ^. M! d7 F o8 n
6 ?3 F; Y3 c9 N9 s Q0 n
//we are to color the faces with different color according their position : three by three will have the same color
+ ?! s" V* a. H% [, j2 x cout<<"--------------------------"<<endl;2 J2 J" a4 V" E) w8 _
cout<<"Setting new colors"<<endl;
3 J5 W1 P' }% v( \! O- ? ! R9 c' w* ?& W7 ^$ d4 Z
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
* u, }# H* v/ o2 a+ c; }; g int x=0;3 M% x' J {4 V+ r$ V: o. x9 G
for (compt = 1;compt<= nbfaces;compt++)9 q& P1 T- `& W2 z. U& ~2 ~
{: h/ _& N: D3 y) k
x = compt%3;! h& T: h# e" A, ]6 C% W0 y( Q
int red(0),green(0),blue(0);" c$ R5 F1 t# h: I
if (1 == x)
3 F. m; H) m4 @7 p3 Q' }3 d red = 255;
& e1 V5 |0 e3 t6 j if (2 == x)
( u3 T F _& h6 | green = 255;
. S; C& W+ I2 M, O if (0 == x)
( E/ C% j& s' S$ ] blue = 255;
5 s% J; Y; H4 ?9 D6 H newRed.Append(red);
% P R( G+ F+ T r newGreen.Append(green);
, l# {6 t( W- Q: L- n( T5 o newBlue.Append (blue);
' g$ `# y( E4 B$ A& \3 [8 J J- v cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
* z& _; S- i5 ^' s; u5 h }
- p5 K/ ? a2 i0 ~4 j5 k) E) l- |$ T) _( Q0 h: i% Q' f' _$ T$ l
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
1 r J( Z% N+ p( t if (E_FAIL == rc)
& W( \- e& C! f' `3 F {( M h, R/ c5 \/ [% p
cout<<"Error, setting new color on faces failed for all faces"<<endl; i% b# P I8 `" c6 o
return 1;) X' c5 M( g( _. y
}) D" b, Y9 j) B& g- p
else if (S_FALSE == rc )
6 i7 Y4 M+ v1 H! [+ m {
9 E- B# ]* S: H. N int nberrors = FailedIndex.Size();
/ D" ?5 k7 K3 g( |2 { cout<<"Error, setting new color on faces fails for faces :";
6 t+ H2 r& N, o: F; B for (compt = 1;compt<= FailedIndex.Size(); compt++)7 e8 l/ }% P2 M
{
% a" \ [7 F/ z2 i, _8 {- W cout<<" "<<FailedIndex[compt];
& h) I- f2 t& {/ B; o" Z- h* L }% I1 Z6 n' T% C5 H
cout<<endl;; O9 F c. a: o0 `8 `5 e
}5 N; ~$ k0 Q* A; K
else
4 f% ]/ O: {! s" e cout<<"Colors successfully set on every faces"<<endl;
. C x0 O2 ]- g* I( c% J9 l2 Z4 M //' U! \* h5 D; v3 W/ ~! j+ f
//9 - retrieving colors we have just set
% {' N; b" W) x+ \ //' \6 j( F1 h( i- A: [9 p
cout<<"--------------------------"<<endl;2 t" j7 G, o1 _
cout<<"Retrieving new colors"<<endl;! s% q, `- d9 ~1 x; P5 t
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
! t: } d1 {! b- Z if (E_FAIL == rc )
4 ]8 A$ F* S; Z4 Q2 \ {
) q% F, l/ A, C& \% o cout<<"Error, an error occured while retrieving current part colors"<<endl;; t s' f* i$ ^% z# e1 H
return 1;
4 x v* w( E& Z; G }+ Q3 y7 D" k- b$ t
% a2 x) C8 ]9 W# r' ^. R' `
for (compt =1;compt<=nbfaces;compt++)
, g/ t, B f: |$ Q {6 ?+ t% M+ e s
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;, q2 ?4 J3 d0 _" L
}+ _9 s( |3 c1 s p( \% I5 e+ c
8 e' ]1 z# W3 f$ R. Z
//
+ R/ |& H: U1 T* l% U //10 - Setting Applicative Attributes: c# D4 f) Q! y0 `+ u/ Z% r3 t/ M
//, ^' }! ^9 s7 J9 ?- @6 p
2 E" i1 V j- _) c' t //
; C' [% s* {3 k4 G //10 - 1 creating new attributes , L+ H' e V; l3 K) y) S0 b* S
cout<<"--------------------------"<<endl;
) n. |7 n' ] U cout<<"Creating applicative attributes for different faces"<<endl;2 a4 N( ^7 |3 c; s0 v, c" ?2 ^$ \( o
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
! a P' p' Q: |4 _" @ CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];! M4 y0 `8 h& Z# M3 X& F1 T' b
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();# u% c9 D: s% q8 m
for (compt = 1;compt<= nbfaces;compt++)
$ s; }- F' R* n {
7 s# R, s% s2 P3 { cout<<"Creating ";
" R( L" k9 @2 F$ C9 q& h# E x = compt%3;
( {" K' U" p9 x! ]6 V7 m //for each face we create a new list of apllicative attributes/ q! x9 v# F& k' K2 {4 @+ r
//an applicative attribute is made of a Name and a value: [9 [: U. a; V9 i- T, x" L% D
if (1 == x)7 H7 ]4 c6 U6 c5 a, q& R. m3 r
{
% [; y5 J2 f$ e/ P, A, Z AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);$ V: |; J8 p) L' {* C2 P# z8 E( D$ u8 P
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3); x3 U R6 f; p: @7 V; C9 [
. @/ V* ^/ k% S. [! b% @6 P& A //The first attribute will be the number of the face6 i! ~3 V* s0 n0 T9 ^
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
. j& O& s% ^ ` O: b2 i2 v2 z% a4 {: ^ CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
$ V7 O1 b) o8 ~ AttrValueListToSet[compt-1]->Append(tempcke1); e8 j1 |( b1 b( x* e' `
; @* G! o3 x% ~$ O' F1 f cout<<" FACE_NUMBER with value "<<compt; 5 a7 i! u @8 w1 b, d) a3 p! J
$ ~3 m. `: F- z( Y- y& ]
//the second will be the color4 f6 z# p, A0 i, Z0 j& o7 o
AttrNameListToSet [compt-1]->Append("COLOR");
: m" k" ~- [( l+ `7 x% L CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");7 K: G" U$ b+ f. ?9 M/ C3 W
AttrValueListToSet[compt-1]->Append(tempcke2);3 z/ Z/ Y2 F- _/ P4 _. W; C4 @* @
5 H+ t$ k S7 J% p& P: A+ ~/ `+ k cout<<" COLOR with value Red";
5 s4 N, }( {0 S2 @0 O3 K! |
' b. J8 b$ |3 v //the third is x
" `/ M2 }* ~* u6 N9 m AttrNameListToSet [compt-1]->Append("X");% w7 j& O" Z& f. L
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
/ l4 }, V: Y# c* F AttrValueListToSet[compt-1]->Append(tempcke3);* I# B# `6 ]' I T$ r( `
2 J0 L- m6 R7 V* b
cout<<" X with value "<<x;1 T. \# {6 @! \. F& c
cout<<" for face nb "<<compt<<endl;
) x o+ ?2 h4 x7 u+ l5 w }
, O: F+ g! y6 H0 S& I/ O else
* r d4 f) S1 @6 \ //just to show you you can have different size of list
3 G# L: Y" M7 E; n: c {8 r7 Y: _- H/ s) H' X
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
0 ~% o* D, N1 d% h. ` AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
& P3 Y. }$ i: h9 [ R7 _0 p( V8 W2 Y( x+ h; f' X2 ~- K
//The first attribute will be the number of the face
1 t/ s% C4 W& a5 n2 S' V9 N. R AttrNameListToSet [compt-1]->Append("FACE_NUMBER");8 g; t. t1 o6 e, h3 Y8 \/ {! ~
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);; p# p( M7 P0 J4 h. w* J
AttrValueListToSet[compt-1]->Append(tempcke1);# X# J; h! U+ t: l
& L8 F6 @3 @: i1 L, u: ` cout<<" FACE_NUMBER with value "<<compt; 8 @+ x6 e4 b7 j% A, D, v8 T
8 d; z, B" R$ C9 C' r! Y
//the second will be the color0 n# Z8 w8 h, t5 ?
AttrNameListToSet [compt-1]->Append("COLOR");1 o: F1 {( s% z2 _3 p0 u4 i* _4 q5 c
if (2 == x)
8 l6 ?+ ]' v& X3 x" [3 ~ {
0 V; o- f/ ?6 Q4 P( Y& O/ K CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
- S1 d: A# R s& J& F: a AttrValueListToSet[compt-1]->Append(tempcke2);6 U8 P3 `2 G3 p+ p# D0 U; a" ?
- Z2 W# E) ] I1 n. N9 Y
cout<<" COLOR with value Green";: H. M3 f' ? _! [* E7 l
}" O7 C: Z% e+ C+ e7 s) y+ s
if (0 == x). o& r( `; @. }/ m
{
0 z+ v( C' c. V CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");; Z0 X8 ?9 i ?* e
AttrValueListToSet[compt-1]->Append(tempcke2);
1 |" z; ` i- Q4 T T1 v% V0 a5 G ) {1 z1 H/ N0 q! Y1 G' n8 A* U
cout<<" COLOR with value Blue";- x* u+ z8 S1 I8 v
}
. v) x8 r5 H: P; Z# C7 z& w/ A- h8 H, h
cout<<" on face nb "<<compt<<endl;
# \5 [2 Z1 W5 f) V& ?1 S1 r! H( j/ g+ M8 o: `! j6 J) B8 j2 s! v
}
' _; h" m! T9 m }
1 Z$ |/ _6 `! B3 A) @8 Q* s& L% c/ Q" }" [- Y' E) H0 v1 {
//10 - 2 Setting the applicative attributes
) \- B: S" c5 h: n- [& o7 s* l cout<<endl<<"Setting applicative attributes on different faces"<<endl;0 e$ p) ?& H$ h: n- o, a" `
FailedIndex.RemoveAll();5 |- B8 R; H8 S/ a
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);2 i! K, a9 X) O# a( ]" ?. N+ t
if (E_FAIL == rc)
. h" j$ G0 Z: b6 Y {# t" a1 T$ F* {6 Q( T6 s
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;) P4 Y) }+ `2 L2 A- G9 c' H, }3 M" \8 h& _
}. v N& K! V* L% m
else if (S_FALSE == rc); m6 S/ F$ q" \, w
{
8 @" a% \) R% t0 { int nberrors = FailedIndex.Size();
$ C: z& F, g0 ~; x4 t" _ cout<<"Error, setting applicative attriutes on faces fails for faces :";& D; ~6 q$ c9 c9 _: Q
for (compt = 1;compt<= FailedIndex.Size(); compt++)
2 r0 ~$ T. L' a9 F1 N {0 g; j d7 ?5 S$ a5 r
cout<<" "<<FailedIndex[compt];
9 s, d& t7 k; h2 z }; ]' |* y! D# A' g
cout<<endl;0 Y+ `: d- c5 f6 u0 Z) r6 T. s
}
8 J! L. K5 r9 I: ~: c D% Q else" M& f) R! j1 g/ p6 G! @! A
{
' H$ X* L2 y/ e3 g! S! r) w cout<<"Applicative attributes successfully set"<<endl;1 p7 H; _) T, B8 d u( a
}
' k7 I. u) ]4 u. l b' N9 j* D$ P& m2 C9 W8 j" \5 j- |
//10 - 3 cleaning
4 Y# N+ U. `; U! f/ K( g+ L- F" r e for (compt=1; compt<=nbfaces;compt++)9 E5 ?" h( Y) a+ @
{0 s u+ c1 p2 ?# S& z+ l. L
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
L4 n$ b3 ~2 J. V: N; V9 ~8 J AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
3 v" S, e4 a$ d7 E }- E& P1 V8 A* r" _( J+ L
* L1 H) q* M, o+ \ delete [] AttrNameListToSet; AttrNameListToSet = NULL;
* i. G1 g+ x4 g: ^! Y: f delete [] AttrValueListToSet;AttrValueListToSet = NULL;7 A* M: B+ ^/ c* ?5 _, @6 ?$ Q6 x
- n4 v) @: a$ s6 h5 o Y
//( k& b( p/ m3 P* V7 a& M3 D
//11 - Retrieving the applicative attributes we have just set" k& L1 z, g+ K$ ] d3 m1 v( q
//
9 Y& n* h J' N" Z$ n1 S+ e cout<<"--------------------------"<<endl;
5 G# ]- t5 s* g% X cout<<"Getting applicative attributes on faces"<<endl;
( r0 W# Y( i1 x8 p5 b/ N2 S- M //' s! y* Y z8 ~! n2 \: u
//11 - 1 Getting attributes9 ]4 Q" v3 J+ w1 Q0 t
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
+ i9 A) v4 n# @ CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
3 {- X6 R: o4 _/ _ rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );0 e, L* Z! P$ ^& f% B' w
if (SUCCEEDED(rc)); t8 Q z& [! R5 M5 n
{
. N" O" O# r. b: P6 u0 |- M7 ]2 j CATListOfCATUnicodeString templiststring;0 v! e% Y7 d4 H5 W
CATListValCATBaseUnknown_var tempCke;
" G( M9 A; F; I7 H- P for (compt=1;compt<=nbfaces;compt++)
) b3 I3 J, ]7 G9 Y, Z$ G) Q {
. n" ]9 v' }( z //retrieve a list a position k (arrays start at position zero).7 z! W) ^+ M' F8 f( I
templiststring = (AttributNameList)[compt-1];
, l8 u& {/ N# V3 O [9 |( u4 f tempCke = (AttrValList)[compt-1];% Q# ~$ [( }. ` s# a
2 ~' a2 v3 z9 J3 Y+ g
int nbAttributes = templiststring.Size();
, n; ?4 C- o* v7 O. [2 V5 q- T int nbValues = tempCke.Size(); t( ]9 c8 X+ `$ n3 ]% d
8 p4 P; P2 b# n9 L //the list must have the same size! If not, we jump to the next face& s5 h( |9 i( f" b( F
if (nbAttributes != nbValues)6 S. Z1 C! \1 q; |5 u+ M
{
' G7 R% R) [% I1 S/ s( Y cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
' _& |9 D( y* e/ H3 _ continue;
/ ]" Z& G1 o9 A5 Z5 C7 ^ }
( w6 K. B$ K7 g( S- W4 K+ L else5 T2 u# s# V( p3 e% H2 v
{
. X* H$ p" J9 e5 M8 F W8 T! o cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;2 K' ]! E/ B! J0 D% Q0 c4 @
}( ?7 f, Q$ q, p6 Z5 ]
for (int i=1;i<=nbAttributes;i++)3 {1 y+ r( u ^
{
) p0 z: R+ j6 P" @1 X$ k7 R cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
8 l! H7 q' w. X8 l5 o }
2 g5 y; J8 X; r1 L templiststring.RemoveAll();
' \5 Q( c- b! i# s/ b tempCke.RemoveAll();
, G& l2 i) m: C3 N
! m7 l Y: m* f }# p3 }) K7 h: ?5 G& {
}1 T8 t$ k' K9 F
else if (E_FAIL == rc)) U0 v5 n; p( K/ q
{, k5 F, n- h4 B* A1 s) z: L
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;0 z! H" I$ T. K4 ~9 o, K1 m
return 1;
, h& }0 A8 z& S- @$ P } N1 u; u3 m- E6 q# `/ s
//
& o3 O! S& g" @" ~; ~6 |; z //11 - 2 Cleaning List:
/ ^$ V- x- l! D) o* C# D4 ^$ L& X int i = 0;5 A5 a; ^ S9 M2 c5 a6 e
for (i=0; i < nbfaces;i++)2 f1 P% v$ e" u3 I' ]% ^
{
! V9 j& v) W4 r4 v" Q: |: G AttributNameList.RemoveAll();
/ A7 a+ }& K5 F, j% q3 C AttrValList.RemoveAll(); l- s! {+ W. P0 T4 G
}6 P- ~& Z7 V, |! p& T$ A: g
delete [] AttributNameList; AttributNameList = NULL;
# f- [2 G5 O& X# `' M8 q2 U delete [] AttrValList; AttrValList = NULL;& O* p: P3 d' o7 [3 d3 T9 r
Y6 L" F% b3 t% A j8 R7 v4 \ for (i = 1;i<= nbfaces;i++)
1 X! Z8 _; {# ~. v V {
- p/ P' O: n! A Brep = ListBreps ;
: U3 w* e5 T( s5 y2 X0 Q if (NULL != Brep)0 ~, T# k" }, B5 G* v& M- l
{
$ n9 \4 J, Q1 g9 ^: o; F( o Brep->Release();3 i5 @$ B) ~7 z4 }& ?' E/ `
}
: H+ ]4 c" x: |# ]9 K }" Q' `, I* a$ }* ~2 W# b; ]( F! u
ListBreps.RemoveAll();[/mw_shl_code]% c% ?+ M- B9 I) }' i
|
|