|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]" y- N! t9 c4 e5 ~% [6 |) w
//4 z" m1 ^) X" b; D2 L
//7 - retrieving and displaying current faces colors
( v W' `6 H2 L$ e' b( v //
" ?) ]% `1 }5 G: W$ p3 L& Y cout<<"--------------------------"<<endl;! G2 g( Y L: j
cout<<"Retrieving current colors"<<endl; ^7 l2 ?( \6 o& n! s" p N0 I+ r
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;* u- I$ B+ R- z& H, ~% i2 e
1 l/ s. r! r F; o! I
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
, O8 D4 Z8 p6 r if (E_FAIL == rc )" J5 h3 g- g I# i2 {
{- p8 Q& |, Y9 `6 _- I% w$ K
cout<<"Error, an error occured while retrieving current part colors"<<endl;6 ^5 t- A$ \0 B- |* J6 k; @" A
return 1;/ G! E) _/ L! r
}; `& T# v# A+ D( C" v. ]
1 O' z' P5 L: B' B" n6 ?# h
for (compt =1;compt<=nbfaces;compt++)' U, u1 f( W$ o1 j. Y# D: w
{
: D1 F+ B$ z0 e5 X* g( q cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;( h4 ?: f; a. x. H& K& a
}
, {+ Y, t5 `2 z# F9 b @* D' g; y
//
' h! f. V5 z, E/ ? //8 - Setting a new Color on all faces6 J) p* H) H! x8 @6 z
/// A, t# J2 i4 ]0 J9 m
0 E* C/ M1 i# F Q' j! c
//we are to color the faces with different color according their position : three by three will have the same color
- d1 q; w0 \$ [ cout<<"--------------------------"<<endl;& X7 {* J4 g% }/ }- h& k
cout<<"Setting new colors"<<endl;
! X! q& H& V: ~# m3 X _ 9 Y6 [5 u$ ?, v' c, W
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
5 e6 i9 r! V) b1 {% k4 Y- s int x=0;; J& Y. u' k; A. V& v) W& Q
for (compt = 1;compt<= nbfaces;compt++)
. n/ v% h: o I {
Y( }6 y0 I! u: x! z x = compt%3;" Q6 M! g- I0 g+ S) f9 m
int red(0),green(0),blue(0);
& _# p2 P7 e1 E( z; b% H if (1 == x)$ o4 y! H, r! T0 p% \, O& ~
red = 255;
5 Y, G& I' w/ ^( ]+ v7 W* r if (2 == x)4 y: K( I5 ?, O& C" Y% Z: R+ W
green = 255;
- F7 n$ [" ]0 C* X/ ~8 T; L if (0 == x)
7 O( c2 S& W/ \: Q blue = 255;0 A& b) h3 v( b$ q+ m: U
newRed.Append(red);
?9 z: F0 N5 `7 h7 r4 z newGreen.Append(green);
; Y3 S, e6 m9 _1 g' ] newBlue.Append (blue);5 Z. ^! k ~5 S9 Y0 f' J+ Z
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
% J" s5 _+ \! B, ] }/ I% d6 t& Y" @
6 S: P5 m+ [2 @, z, F% c
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
' }3 O0 x4 K3 c2 B& [ if (E_FAIL == rc); s- l+ n3 u: l4 g/ O
{5 T' x( p: E+ @
cout<<"Error, setting new color on faces failed for all faces"<<endl;
3 a5 \( `7 z+ M return 1;
( @7 a" N; |5 d3 p, n. O }
! D# y& ]0 f8 D) l) k else if (S_FALSE == rc )
# d% o' k1 \ ]7 R {. n) R8 }# ~: Z x
int nberrors = FailedIndex.Size();
, m5 c0 {. s5 A cout<<"Error, setting new color on faces fails for faces :";
' [* k+ R; A4 y/ ?, v* R* Y for (compt = 1;compt<= FailedIndex.Size(); compt++)
3 G: K) ]- `* i6 n) X' m9 f {2 j+ Q: e& R; t
cout<<" "<<FailedIndex[compt];& S# D, u0 D+ d. U/ B6 {
}& |/ T: P- a+ y, s L C
cout<<endl;
V% x! ^0 {* z2 j }
6 L5 A( l5 q3 k% O% n* G) W& o A# K else
4 L' ~- b2 F- K1 @ cout<<"Colors successfully set on every faces"<<endl;! T; {- ?: B* M: R7 e
//! r* P; E0 o" V4 V' C @
//9 - retrieving colors we have just set
f& i- w- i" F! P1 }) W //7 ]5 v# o; b: _' Y1 {
cout<<"--------------------------"<<endl;. |0 N; S* E7 M- y
cout<<"Retrieving new colors"<<endl;# T7 l: x3 Q$ y# o4 M6 M: n0 b
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
& X0 w0 M' ?7 K9 @: i if (E_FAIL == rc )
- Z6 Q7 U+ d* p% `. V7 }4 l8 B {
4 T: f- h1 i0 |. E% ?5 R$ a9 Y( R& l cout<<"Error, an error occured while retrieving current part colors"<<endl;
4 r5 d; Q* a9 w. @. n# i; { return 1;8 P& y9 y7 _) y/ q0 z/ Z s
}2 Z- h4 h% z5 z1 r( `& @7 ^9 I' h" h
6 s( C" {, i& b9 E; s for (compt =1;compt<=nbfaces;compt++)/ S7 Z$ F- F0 `4 O8 Y+ @$ \) c
{2 Z. n; A/ @1 ]* x
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;7 d1 I$ M" ~% j" P" d' s; D) ?
}8 x% {- p& x6 z# u5 n3 {
9 i* a+ F5 v7 \$ W* U
//& W% `6 I: \6 Q# j
//10 - Setting Applicative Attributes* \) j2 I" O- i6 Q
//
+ p5 k- g: t5 g; T8 I
0 R" T) {5 l* ^6 w* ? //( d" H8 f2 P, s+ c
//10 - 1 creating new attributes
& r* J4 K; w; B6 ]7 ~; Q cout<<"--------------------------"<<endl;
2 F* E" P' v# Y( l cout<<"Creating applicative attributes for different faces"<<endl;, X% a( {# {3 \- ?
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
) L3 \8 x o- ~. r CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
5 o, j6 {& z5 j! r9 P8 [ CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
' [. ?! K& T' y, C# V+ h' Z9 N for (compt = 1;compt<= nbfaces;compt++)( d E& O2 N3 {- j- o' O4 g
{# _& I" M: m: `
cout<<"Creating ";% t0 ` U( [4 x4 P$ `
x = compt%3;
8 d9 P# \% T' N( F/ T //for each face we create a new list of apllicative attributes0 q, R R1 A: s- ?7 t
//an applicative attribute is made of a Name and a value
+ {0 Y, {) G3 \0 l if (1 == x)
2 V% D! V+ N: `) }4 q M8 s {4 H" j: n' b6 V9 J S
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);6 M2 A! b# D! ]* l2 f' \. j
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);; ~2 I" w5 j. x4 F" R- C) a2 H
2 [. \: f) {+ r4 Q+ Q% h
//The first attribute will be the number of the face1 @( c: @: f$ W% ?
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");3 [1 Q! j' ?4 F% o7 X( V
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);+ _8 a% ]% f& i6 Z
AttrValueListToSet[compt-1]->Append(tempcke1);7 ~2 l0 o% [9 O3 ]
5 V$ M V9 }/ o$ P& Z* p; M
cout<<" FACE_NUMBER with value "<<compt;
/ G9 H2 H+ k( _! q! p# a
$ G. Z/ m3 r( L9 C' O" g //the second will be the color
6 ]& \) a% F2 Q8 \2 }' e, v% q! a AttrNameListToSet [compt-1]->Append("COLOR");1 y; M, u2 Z+ M7 ]6 z. L f; X
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
$ o; a8 V( s J9 n1 s2 s AttrValueListToSet[compt-1]->Append(tempcke2);( x1 `0 Z1 V* i4 }' l7 ]
7 U2 S' c' J0 v a$ X( K8 ?" O4 ^ cout<<" COLOR with value Red";$ N) e: N ]8 ]* `
$ |; C5 w. Q% D, u* e
//the third is x5 y9 H ^3 h1 A* q2 @
AttrNameListToSet [compt-1]->Append("X");
0 O) Y4 f. y& }/ h. E h CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
, P2 t4 S1 g( Z8 r+ G AttrValueListToSet[compt-1]->Append(tempcke3);
/ d i8 P* D6 x2 X/ w( ? 6 I2 n8 X3 o4 d
cout<<" X with value "<<x;
0 ?8 ]6 G. |% L4 l" b0 w7 x cout<<" for face nb "<<compt<<endl;
, R" o- B: r7 J4 F4 w' i% G }9 G) a/ v' [+ E! s
else / w* q" Y7 N4 S$ `) U, W& G
//just to show you you can have different size of list% e; H& c- A' |- l3 a6 B
{' i2 |- j! b2 K# t5 P
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
) C, h% }5 ~: t8 S% H' j AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);* h$ l0 [7 E5 \6 P( R" m
2 G* @; d% L! D* F8 A
//The first attribute will be the number of the face; q u0 j! [" \' c$ f1 ]6 T, D
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");5 n. \4 a# R/ E& N0 N2 G
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);" g8 y( S2 |# m) x! c. I
AttrValueListToSet[compt-1]->Append(tempcke1);; |# Z% x/ n$ m
3 H1 J" \9 Z+ I( y/ w cout<<" FACE_NUMBER with value "<<compt;
9 R8 y" Q5 V3 ?1 {$ h5 ] n: O& z6 O' O5 m, q$ t, T
//the second will be the color
' M. u q _( V5 | AttrNameListToSet [compt-1]->Append("COLOR");
$ K( D! Z2 `, a4 Q if (2 == x)# P% a4 K( Q* \- J
{
$ n) U0 }; \; N% D1 \( H# [ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
8 v: V" {" {- X6 x+ N AttrValueListToSet[compt-1]->Append(tempcke2);9 d1 \) d: ?( w) F
2 E1 G9 j1 _% k% O: `: z
cout<<" COLOR with value Green";( P8 G+ @' J4 T- @' b
}3 k, n2 m0 A% R- w- A6 x
if (0 == x)9 [4 d0 s; K' V6 Q* U
{( h% d$ z& D8 y+ F
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");$ c0 x8 o- D" T! j
AttrValueListToSet[compt-1]->Append(tempcke2);+ m. H6 y$ {+ j
3 g2 ?: j+ u. u6 S* H0 b cout<<" COLOR with value Blue";
# |& q/ j; a7 u/ [0 s }
: g) _ J2 N% }1 V( k
, z5 ~. R3 @! A cout<<" on face nb "<<compt<<endl;, T- A, a9 h1 U& F$ O
1 R- B& @" Y: d }. b) H) j/ T* |) W
} o0 ~- D5 H- S, }' Z& w
/ I$ H9 G4 M3 C. B, o; E" `9 ^ //10 - 2 Setting the applicative attributes
5 Z3 q4 [; K" E8 v4 u" B- r cout<<endl<<"Setting applicative attributes on different faces"<<endl;/ Y" p H; W2 E
FailedIndex.RemoveAll();9 E! ?3 P' ?% C
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
5 ^7 f m9 F2 J9 S' h# ? if (E_FAIL == rc)
$ I9 f/ e; J( @% U1 B; `& @ {
# w: r% ]2 O" ^! R8 H cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
" y0 _2 c5 b9 L( A }( t" {* y* \2 t! Z! g K. q
else if (S_FALSE == rc)
; ?$ M4 z+ d6 ]+ L, P5 a2 M5 K {
4 t& K6 l4 ~5 o int nberrors = FailedIndex.Size();- \% @4 s! _( Q& B' m; B' e
cout<<"Error, setting applicative attriutes on faces fails for faces :";$ _* ]6 s( ?* C8 H9 F7 f z
for (compt = 1;compt<= FailedIndex.Size(); compt++)& n* E5 ^ }4 @) h
{& X+ _0 d) q5 ]1 D C; Z8 A l
cout<<" "<<FailedIndex[compt];
2 _% |' V/ q! w, N* {( K3 |; H& h9 S }* B4 V% l0 o' A) K& h- P! \+ S2 `
cout<<endl;
- z0 H4 f% T" n9 C) K$ g+ s$ J: U } G$ J- M# o4 o/ f l$ ~, L
else" A' R8 F1 l$ G& a
{
8 s* S- D( x3 ]+ m cout<<"Applicative attributes successfully set"<<endl;
, O5 X @6 @% E9 }( o6 [ }2 e$ V4 c+ _# Y) w3 p0 b6 W
$ b3 o0 T1 b+ T* ^3 Y //10 - 3 cleaning
F. ~' B- y: j: k/ U3 M: B; p for (compt=1; compt<=nbfaces;compt++)
2 z, f+ s" d, Q. G0 U v8 L {
: p. l, c: g+ j. f7 a AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
* \" ~3 ^- e( X. Y2 [2 ^) C AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;) Q8 W; U5 V5 d* ]( J; U3 p
}
8 G) y6 K! ]: [% t- N4 c! o8 O5 t, n: X% w
delete [] AttrNameListToSet; AttrNameListToSet = NULL;: e) U( E% I# X O$ M
delete [] AttrValueListToSet;AttrValueListToSet = NULL;7 @9 C/ [; B/ [1 O
4 U+ {7 J! Q9 f S @
//5 ~# a' K% C# t
//11 - Retrieving the applicative attributes we have just set
3 n( S `9 z" d; i //
" _4 ?" d1 J* T: R. k) |& }9 R cout<<"--------------------------"<<endl;
: v# e- D5 o% o; Q7 | cout<<"Getting applicative attributes on faces"<<endl;9 P4 b1 V+ [; d8 [- I, t$ a
//
" j" Q2 R( Z! o$ e g0 v5 T //11 - 1 Getting attributes
$ I. s0 h& F) z( P& f0 R' H- b CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
2 A) z5 |# j) U! z CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
! f- G. ?) T4 P* b2 |' V rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );" }! ?1 H- i, S+ m: M
if (SUCCEEDED(rc))
q) D7 r4 ^3 d2 C* ^' o6 F {, v" \: h" t- T! {5 ]3 T: z: m
CATListOfCATUnicodeString templiststring;
8 v4 R% }, J! ]) E) u9 E4 z) F CATListValCATBaseUnknown_var tempCke;% O3 V Q7 P( y7 J+ Z' B
for (compt=1;compt<=nbfaces;compt++)' `( e' y& M# |; u, }
{
" Z) t. ]' e) X+ ^5 M& p$ L* s/ ?1 N% e //retrieve a list a position k (arrays start at position zero).0 I3 s, e% b, x+ A5 `1 x: T6 i% g9 L
templiststring = (AttributNameList)[compt-1];& q) Y" L5 S$ _8 [* m+ ~# Z8 a" b
tempCke = (AttrValList)[compt-1];! c7 g* s+ N& J$ j7 V. v
. V% x7 c. W' ?) ?% M& D
int nbAttributes = templiststring.Size();2 \: U5 `4 u6 r
int nbValues = tempCke.Size();8 p! I- a6 W4 V! y% P& h$ L& S$ r
: g; p* p6 L9 z4 ~% D
//the list must have the same size! If not, we jump to the next face
$ U7 Z I$ _, |+ m if (nbAttributes != nbValues)
) x4 S3 S0 p' l( B, ? {& A1 {3 Y6 M9 c2 v( `! ]0 v
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
5 K, J' _8 D' J% E7 X7 p; L: x. Z+ G continue;
/ J8 J, p2 a" Z' { }" L' e! q4 z) v7 Q% S: s w
else4 i/ ^0 J% G+ {) m+ t V
{( m; S# `- w% c2 G# J& T6 u
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
* R: I( w) A6 I+ P x2 q" @ }
9 k& z! o3 W1 E* i+ m for (int i=1;i<=nbAttributes;i++)$ k" Z& e+ {% Z; O
{
0 H4 @- [9 o7 _' V' E cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;( \. N" B, n- e* H0 h3 m# S
}
* k# T8 y- c! K+ ? r* B templiststring.RemoveAll();
2 t; H+ Y$ _6 p6 u2 s tempCke.RemoveAll();
) x/ h6 I8 \, Q' I
. A0 _: o2 k4 h! g" Q }0 ^1 q6 z8 I* F0 o
}
3 y9 H) \/ r! O& E! p. {$ I else if (E_FAIL == rc)
( G% K/ b% v6 g2 @) Z: d {! W, w! ~" I- {5 Q2 i, I
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
3 F4 l7 C0 r5 f- s4 c* f- q& H return 1;
3 d0 i) f; H$ @6 v2 \* f }" k" O" t& V) x4 ~8 `
//
7 {( L8 c' z4 ]$ i8 B //11 - 2 Cleaning List:0 L: E' Z `2 p) h
int i = 0; }" `2 Y& C o# ?2 K8 }
for (i=0; i < nbfaces;i++)
0 F( O9 `" V$ K2 X5 r {4 Z7 B* x! @% D( o( a
AttributNameList.RemoveAll();0 c, M+ d7 A9 k0 r, C. f1 B0 b
AttrValList.RemoveAll();' F# C7 O9 b2 [. |( t8 g n! {: _# y4 q
}4 R5 k1 b0 Z# H
delete [] AttributNameList; AttributNameList = NULL;$ K9 q! Y3 g5 O; T/ ^
delete [] AttrValList; AttrValList = NULL;
+ r9 ~% B8 ^$ o: p9 Q& \% x! F8 N
for (i = 1;i<= nbfaces;i++)" h+ {) h; B L9 F/ V0 Y c
{1 [4 |" w: q: a# d/ ^
Brep = ListBreps ;8 X% f* x g5 d$ `1 g/ h
if (NULL != Brep); ]. ^& e* c0 g
{9 T7 R6 h# S9 z# t- M" L
Brep->Release();
3 Q: X/ W3 I* p6 U" e8 k }! _- c+ Y4 b0 u4 `8 m' i
}
! p9 v+ @& R4 m5 B ListBreps.RemoveAll();[/mw_shl_code]
) k; w& H; E+ |, K |
|