|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
% [2 O; G2 e5 F; T //1 j+ q ~0 R }+ a4 x$ ~
//7 - retrieving and displaying current faces colors- K7 a$ m0 t" W
//+ l# G( e3 U4 \2 r }9 U
cout<<"--------------------------"<<endl;
. e3 |. {! P L6 { cout<<"Retrieving current colors"<<endl;$ y0 s* s/ k- v+ W! u2 L% g
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;7 J1 f$ t8 d4 M/ P3 x& U
4 U- J5 }8 l* D) i+ }0 [" l" z rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
2 n: |- ^! o* M8 ^3 E* E7 o/ E5 j if (E_FAIL == rc )( m; K2 M. I9 o0 B( e) m% `
{' D; O2 V& [. {5 ?
cout<<"Error, an error occured while retrieving current part colors"<<endl;! Z7 k0 b9 o8 u6 U7 r' k# _ x1 y5 q
return 1;; ]1 V7 z' S& E1 V. A
}
& Y: p, g% |, B2 X5 S8 x+ p1 Q9 x/ K& y% e" B
for (compt =1;compt<=nbfaces;compt++)
; k& P9 k' T% q1 o" J' C {
/ ^ B0 e9 F& D; T0 i cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! @0 G9 f( w* G, | f' V3 j }
$ Y5 h7 N9 @% q' V5 t' M2 }2 U3 @7 N) ^$ D
//
6 F. X$ X6 h- ]5 h3 h; T3 h //8 - Setting a new Color on all faces2 \* I2 L8 P3 R6 _0 F& J3 C! W9 B' m3 O
//0 b6 L' A. r( m' @
5 I- J3 E. Y2 \5 w1 l6 [ //we are to color the faces with different color according their position : three by three will have the same color
! ^* o: d0 E" Z$ L cout<<"--------------------------"<<endl;' G0 G# t$ a) f: q* R! p; X
cout<<"Setting new colors"<<endl;
! G9 z' ~! j. X/ z, i1 y , L$ C. q1 n3 Q, b! d3 @ J3 s
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
; y0 N, U3 Y* {, X& t) \2 U int x=0;; g' B' b6 C! B. @( J+ K3 A5 b0 ~
for (compt = 1;compt<= nbfaces;compt++)
C* M7 n1 w! _. ^9 A0 b' V- x {9 F- n2 Z K" J
x = compt%3;
! {& Y, P# u& @7 a8 b0 ?% V int red(0),green(0),blue(0);$ u! q! r+ L X& @6 R. @! ?5 r( D) |
if (1 == x)$ P% J' q, X, C- y% w
red = 255;
% ]2 \. d% w$ X8 a: T9 A if (2 == x)* M; z( X5 b% f3 k
green = 255;% [" d9 E; c, F8 S4 W1 l C
if (0 == x)7 `0 ~0 m) t# G/ [, O+ r6 R' b
blue = 255;' D1 Z9 c4 o# L
newRed.Append(red);' [ \4 F* z! }. _ _
newGreen.Append(green);3 Q$ o6 ~0 I, e/ Q
newBlue.Append (blue);, Q! F" _# h& O% P* [7 W7 q
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;% ^: G; ?0 U& ]& o; F4 @0 e
}
6 t$ t% A( j& o! c* {3 @
, A; k: Z5 I7 D# o1 U$ l* }) f% Q rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
- m! o D) g0 R if (E_FAIL == rc)* Y3 [5 w. o* f/ H
{) k4 {9 H) r! j# \
cout<<"Error, setting new color on faces failed for all faces"<<endl;
0 L) H# L$ \- z. Q! ^% u7 {; Q return 1;
9 J# f+ N. @+ v6 c9 A2 ~ }. W; h6 e$ s7 K7 @$ I9 _( E" d( }
else if (S_FALSE == rc )# a2 J% b7 p V! F
{
! M( ~! V/ H1 x int nberrors = FailedIndex.Size();
8 r+ q" f g Q$ E cout<<"Error, setting new color on faces fails for faces :";
9 u& `" g) p8 F4 z) E* e% h9 ]1 a8 M) f for (compt = 1;compt<= FailedIndex.Size(); compt++)& h L& I' ^. Z+ T; u& |
{
9 ?/ {, I. r% a) M* ~! D cout<<" "<<FailedIndex[compt];. Z4 h7 u U' z/ U
}9 u4 O: S9 t% |6 j+ N
cout<<endl;2 g- ~* X) @6 f9 U) P+ R
}
8 y% V# P: y3 b( o* f S else
2 A6 \( u* e P4 y) G: B cout<<"Colors successfully set on every faces"<<endl;
: I A: f" u, E( E! }1 i$ Q, P //4 ]4 O$ d9 i' f. F9 a' i4 M; m
//9 - retrieving colors we have just set
8 s% K" U3 l+ D+ T: ^ //
. p1 j7 \* Z6 S) Q3 b cout<<"--------------------------"<<endl;) s7 n/ k9 J( N& l3 h0 _' b1 z! ]
cout<<"Retrieving new colors"<<endl;3 |0 V1 {+ g5 }$ n
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue); J" L# u q; P/ h+ n) D
if (E_FAIL == rc ). ?+ j* t" d- G* T y
{
; _/ J' [# k3 ^- C% ? cout<<"Error, an error occured while retrieving current part colors"<<endl;
- r/ w) i% Q$ W8 h( g+ A return 1;$ i5 B9 E; O: A" d1 z
}6 I! n. e) V; M( u, E' }5 K
1 Z5 j, n5 w6 C' h- b
for (compt =1;compt<=nbfaces;compt++)
6 }% g3 @' Z9 A' Q9 f5 T2 R. ]4 m {
2 Y0 A6 d8 T* A9 _* m. d2 U' c1 J" B cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
- j _1 f, O% c2 f/ K5 }4 b! m& m) w }5 k( @* j7 a. h6 v& a5 M9 V" ]7 o
|4 m" h/ i9 O; o) z //
k0 O1 r( [) r! L. G! u/ @6 _- U, M //10 - Setting Applicative Attributes- `/ b# X* P6 e* C" j. ^
//
) Q# x) F. `, w8 c& t
2 \& P6 U% b4 ? //. [. \# X0 Q& }5 O( ]. } O
//10 - 1 creating new attributes
" v% [& P( ?0 } cout<<"--------------------------"<<endl;& X: N j- X5 ^! J" B" X
cout<<"Creating applicative attributes for different faces"<<endl;% N4 t7 M7 w# D8 t) U! K; h
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
$ u+ ]" _; p; D$ {" b* p4 W: O CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];0 l6 h" f8 u' n% k% g( o
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
5 @7 E: w' Z' E6 ]2 f! K. Y for (compt = 1;compt<= nbfaces;compt++). m" t* C1 l" {' m
{
, P1 G) B% K; ]3 r cout<<"Creating ";$ [9 d8 y1 B( D7 b: J$ F
x = compt%3;
\; B0 S3 H. h+ t" L( p- U //for each face we create a new list of apllicative attributes
3 Y: j' R7 Q6 y- A: {7 V Y" _ //an applicative attribute is made of a Name and a value7 U. i" G! a' _6 P8 e" L
if (1 == x)
7 H* U5 q! W8 C' K Q- S3 x. r, M {
& c: ~) _8 g3 m8 T. _ P AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);! g" k/ `, g s0 A& w3 U' ^7 Z5 i
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
% M7 R) q. e T$ h6 X( A6 }0 \( I* D) R& A
//The first attribute will be the number of the face: k9 _1 C5 {0 a J; W' C- X7 v
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");, ~# Z! I! B4 h5 s6 i) d; t$ \# U
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);6 Z, U2 O* \/ r7 _
AttrValueListToSet[compt-1]->Append(tempcke1);( h0 H3 i5 C' M) j% G
8 }- G' k G$ l& u. X, v
cout<<" FACE_NUMBER with value "<<compt;
4 K" u" J6 u: a; H0 s! t7 O' w/ u2 N8 ]4 [' t
//the second will be the color3 B. f3 n" n* A; W# T2 \% R
AttrNameListToSet [compt-1]->Append("COLOR");
. i8 | a# `/ r- M+ t' r( k CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");* e K5 j2 N+ A- b1 E# e: U, b( y: Z" O" ]
AttrValueListToSet[compt-1]->Append(tempcke2);4 [2 b; b% {4 ^0 S- S" _8 Y
4 o d& ^- `/ l% ?1 F5 k' f cout<<" COLOR with value Red";
- P4 n& z6 m# m# W3 c. [& ^4 {
( J9 o; q% |7 ?. z# N, n! U7 S //the third is x
/ {7 F$ ?1 n* B9 m& ~" L% v AttrNameListToSet [compt-1]->Append("X");2 I8 b5 r( V F8 @
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);% h+ _* c1 X3 l# i; ~- Q3 F
AttrValueListToSet[compt-1]->Append(tempcke3);
' t3 }6 ?0 `9 e; o - V& N: l5 G/ ]2 r
cout<<" X with value "<<x;$ V- z: d1 x" B B+ C% E0 ]8 r
cout<<" for face nb "<<compt<<endl;
" [7 n4 s: Z5 R0 _# w. Z5 g }
+ t' t& r- }: ?9 e/ x$ U& M5 ]1 V else
$ T$ H3 S( G# P //just to show you you can have different size of list) }5 z( n7 Q7 E Z' g/ A
{5 Q( m0 s1 z! H9 d
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
" q, [1 N' [8 R, D8 e AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2); r& ^# a3 s# [+ j2 q V
& ^& q; E5 Y& p3 C* s //The first attribute will be the number of the face1 ]1 ~9 C+ o- ]: B. d" b! d
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
) G& }/ p! D$ t4 v. ] CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
, }4 _1 P3 V8 C. g AttrValueListToSet[compt-1]->Append(tempcke1);3 r' B2 Z" R( _: k/ x n
3 F A" t4 X2 r' m
cout<<" FACE_NUMBER with value "<<compt;
' ]7 G8 i5 Z' A4 z7 y5 z
+ g4 V+ _9 L. R //the second will be the color
6 W. r' V6 e2 x: l+ N" p AttrNameListToSet [compt-1]->Append("COLOR");! }5 ~2 Z7 @- Y4 w1 o, m
if (2 == x)
0 Y2 p! S, ?$ U5 J9 x0 w7 W/ ^ { d$ n9 e9 n3 {7 q3 c4 P
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");8 I1 e# M A* i$ D B# M& A7 J
AttrValueListToSet[compt-1]->Append(tempcke2);
0 F5 ^1 I/ t R5 X( c1 k
( P" F- T, i9 ^. H cout<<" COLOR with value Green";2 X9 I% I' f% V
}* \. V# i$ G O
if (0 == x), T6 a9 B' L" T) b* M
{
) B$ P& G6 E/ D# d; B CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
! P6 \3 R2 k) m AttrValueListToSet[compt-1]->Append(tempcke2);
& @* z H, N. F* T2 T
+ @/ u: q# j5 s/ @ I1 o0 t cout<<" COLOR with value Blue";
@# }% W$ ^/ m d }
2 S0 ~ Z, ^' k* B, k, f' C# o9 ?
cout<<" on face nb "<<compt<<endl;
6 a/ f- C7 p/ W0 h: O" H- R+ \; T# G1 p" ?0 t' j+ ^
}5 B7 m B7 ?, O/ Z' j
}/ H. ~& T, L- }8 k( V, k7 S" z
" z0 [; A5 `+ j; }" j
//10 - 2 Setting the applicative attributes- U! [" y: U. k- o) f- K
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
! P) H& o+ v% F v3 B FailedIndex.RemoveAll();& ^# x7 c, s3 ~0 Q: |/ K
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
- p; E, N0 y" o- w if (E_FAIL == rc)+ d; b9 g3 G8 Q) I# J9 {0 h
{
1 ~; m# i5 i H u: x! [4 p O cout<<"Error, we failed to set applicative attributes on all faces"<<endl;3 t6 d, a; i( f( U. ~
}* K/ }) [- v& \' s- `; R
else if (S_FALSE == rc)' p4 u; H3 ?" d3 [( X: X5 o
{# r5 _1 {9 c3 I6 d) C
int nberrors = FailedIndex.Size();0 B L) [/ z& g" F9 H
cout<<"Error, setting applicative attriutes on faces fails for faces :";+ K0 J; D3 D. |5 V' P
for (compt = 1;compt<= FailedIndex.Size(); compt++), H, [, @( S+ Y, Y
{
( a1 }; w1 ?( \7 k cout<<" "<<FailedIndex[compt];
K2 ]1 @7 {+ F }* Q0 V9 F8 c" R7 }. { |
cout<<endl;! _- Z( x! c2 D
}9 h# ?8 i. Q* `) P0 w7 P9 p
else* u% q+ {4 a0 X- x* z4 _& ^% T
{) j& V1 [& Y; }' j' a
cout<<"Applicative attributes successfully set"<<endl;3 P' M8 }" _; S$ G
}: t8 W Y/ ^3 a% l) l2 D" N6 [4 C
. T1 R" o4 o) q5 c$ r9 P //10 - 3 cleaning" p1 }2 b: V$ z2 K+ G5 J9 L# R6 q( w3 B
for (compt=1; compt<=nbfaces;compt++)$ Z( C! c, |5 a8 t/ I1 ~6 H
{
% Q# S4 u# h- p* F( ?" s AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;! @% U3 `# |$ i6 h) _! x
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
5 u, I. |) `2 m: [0 l }
9 T* y, A& _* C2 K. q i! H4 a) A3 |
. T6 n4 |, x$ x9 ]' G z' n delete [] AttrNameListToSet; AttrNameListToSet = NULL;( z& ^7 u+ n3 w& M X$ V4 C
delete [] AttrValueListToSet;AttrValueListToSet = NULL;) O$ T: e# G( {! _# ~" @: h
! r9 O' L+ G. {, N //
" C% A. l8 p5 ? //11 - Retrieving the applicative attributes we have just set
- t4 R6 ]# Z5 ^- u //) [, ]+ t- v! `- o6 E% B
cout<<"--------------------------"<<endl;
1 N; C- ~) Q) }0 s+ g cout<<"Getting applicative attributes on faces"<<endl;! o* I2 r, g+ O, U
//- u/ L8 \. G _+ ?1 h$ \" ?' {# k
//11 - 1 Getting attributes
C! p! {. n: x5 Y9 n6 J CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
- B/ ]6 V$ }2 j" j) @ CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
) D! W# [$ L1 H, X* F8 [ rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );/ x$ _) m% e* E
if (SUCCEEDED(rc))
, k" ^/ I" B2 ` ?/ t. |8 h3 J# Q8 I {
) f. m; D# s- M CATListOfCATUnicodeString templiststring;
1 G# V0 ]5 W r* ?' { CATListValCATBaseUnknown_var tempCke;
" L3 z8 L r/ k3 u* m for (compt=1;compt<=nbfaces;compt++)3 {# E! u3 d3 Z. z( i. a6 D' R+ p
{( ^1 v/ p9 r* q+ b" I+ O
//retrieve a list a position k (arrays start at position zero).. q# u& i% }. O* X& z; ` J( b
templiststring = (AttributNameList)[compt-1];
( t7 r" ^6 {; [- K tempCke = (AttrValList)[compt-1];
, Z3 y) E, m Q; x+ z" H3 j4 R% M* [, Y, @! J; l$ {& y% @3 j
int nbAttributes = templiststring.Size();% u% e& p4 N C' c
int nbValues = tempCke.Size();
8 g2 u' M( ^7 h0 o- t5 ` ?
! R& M9 \3 O5 D" J5 l3 k //the list must have the same size! If not, we jump to the next face% k! S9 `$ b4 o
if (nbAttributes != nbValues)
5 A7 O# }/ s; b$ U: M4 O$ u {
. `9 d6 _! U/ t* s+ z/ c cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
5 v! c9 m0 i' m; Y continue;/ l4 Z5 r9 C" P" i5 H
}
, f/ F! {; d$ I else" i3 ~' F6 I) g. Z
{; @, A' L! P3 o6 Z
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;' }$ c# e2 Q' o# r$ y
}
e& N" M4 y- m8 P# w! c; ] for (int i=1;i<=nbAttributes;i++)
2 ^7 } D; t: |# T& J: P, D( G2 x {
: l4 J: G- ]/ ] q. W+ q; a cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
" M/ z1 x S! x1 s$ \6 J }: D. D" Z! s7 O
templiststring.RemoveAll();7 P% _6 J$ G8 b8 \/ o/ v$ o
tempCke.RemoveAll();
3 S7 V+ z6 S' o; g5 P( A3 b: x8 ]( k1 T; ?/ h/ z
}5 O' M( C# f* \7 i
}
7 R; N. @- |" I! |) v% ~ c) X else if (E_FAIL == rc)9 P+ C+ x+ q0 ^# W
{
( z8 J5 E* k, F; n6 J* Z cout<<"Error, applicative attributes couldn't be retrieved"<<endl;5 T# x4 N9 V- O. I
return 1;
* U: a8 w8 Y; {% |- s }: |3 R5 [+ c! B6 Y) c% n. Z
//* [* H0 v! F' i9 p/ H+ e0 ^( |
//11 - 2 Cleaning List:
- b0 j3 y. @6 H int i = 0;
0 P2 w, ^& s { Z) x! Q4 B for (i=0; i < nbfaces;i++)+ y* j B8 e, V# ?: |& L$ T& A; w \
{
8 w5 d' v/ }. X& m% `4 i9 h AttributNameList.RemoveAll();
% B+ F+ p! G$ c. L, I& I AttrValList.RemoveAll();
1 C8 V! z0 [4 |. t% {# A }
7 N" K2 P8 \3 l& J0 J1 _* ` delete [] AttributNameList; AttributNameList = NULL;
9 M" `- t3 d4 ?2 l3 J delete [] AttrValList; AttrValList = NULL;8 C0 V( l; J$ e3 B
" w! R: O [5 i _2 G for (i = 1;i<= nbfaces;i++)
" m2 S u. U2 [% ]0 b {+ i' [3 j. R2 X) m
Brep = ListBreps ;
5 q: n5 U3 Z" F# P if (NULL != Brep)
) t, Q& Y: g. \ d- v1 n6 X {
" F% T8 s# ?9 Y3 O Brep->Release();
$ E0 |: V: d2 x# n0 y! v }) h9 [# l$ ?) B& i8 c: A
}
7 I6 v" s) _9 z7 a: x3 ^ ListBreps.RemoveAll();[/mw_shl_code]9 v( |* Q8 F, ~+ w, u
|
|