|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]* G+ W; d& x6 `- e# \; E5 X
//5 _' z# O. z* `
//7 - retrieving and displaying current faces colors1 Y' g7 ]7 X# K1 [( f) F. h( t
//$ j0 h0 [0 @+ x7 l$ R
cout<<"--------------------------"<<endl;
$ E# }; h4 A. {) @+ O cout<<"Retrieving current colors"<<endl;
" s& z# Y+ z6 R9 \/ U" n CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
& [* n4 S8 x/ O" G. m0 C * e, O4 V7 y) T9 e8 q* U
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);# d2 Y* ^* h+ r, O {
if (E_FAIL == rc )
I( o# O. W4 S5 ]4 A0 \; M# u {
) o( I/ ]' v+ D, w3 l cout<<"Error, an error occured while retrieving current part colors"<<endl;
/ L M- R: ^3 P, N5 z return 1;, g7 t% B4 E$ D* M$ H- k1 S
}3 B- H" u5 Z" T; H
# \$ q% z# N2 W. f8 N* L for (compt =1;compt<=nbfaces;compt++)
# X" n- J3 Q/ G' T {1 H/ S2 W, z; e7 d1 u; Y# R
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
% c" a& ]: I) n* g* D" K0 z- q }- }5 B/ C! N' [5 B* u/ ~( G
1 F8 P, ^; P* d" o4 ?1 u3 Q, p" @ //
! D& n1 y- p+ ] //8 - Setting a new Color on all faces0 i" Y# O$ O) k6 b l! x; L
//
% ?8 a7 b) W* y c" o
1 p/ W5 I; C B3 ^0 ` F, H' P //we are to color the faces with different color according their position : three by three will have the same color
% o! r! j" F! | P2 O" { cout<<"--------------------------"<<endl;' o1 o, B( Q# A/ z: y1 ]
cout<<"Setting new colors"<<endl;
4 w7 a+ U8 V- d - Z. n: i2 {: o0 _1 R# y. e
CATListOfInt newRed,newGreen,newBlue,FailedIndex;
9 Y' n- m' O% m, Z, y; Z7 u0 } int x=0;- z+ i9 b6 @* |
for (compt = 1;compt<= nbfaces;compt++)
2 }) l( u8 a' A9 m& Q2 F& { {
9 ^: `& E8 S2 n+ Y: J- O x = compt%3;# x3 D% V3 [# y+ F M) }
int red(0),green(0),blue(0);
% l6 }9 V9 ~% L# m3 @& Q* J, ~6 o if (1 == x)7 p2 A0 F$ z% v; z
red = 255;6 J4 F4 ~; b7 {4 r
if (2 == x)
2 g+ q7 U! N: Q ?: S green = 255;
4 {1 K; d, e9 E9 Q if (0 == x)+ w# W! V- d" G, Q9 O* l% c
blue = 255;
, X8 u0 P1 N& L; X# \8 o) Y newRed.Append(red);
7 H) R$ b4 ?: v$ N; J. D newGreen.Append(green);
8 N& B* X4 ?6 O! z# U' X newBlue.Append (blue);
# ` E4 a8 J' X; l8 y cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
7 _6 K3 k) V# J$ I0 ]+ [ }
9 s, J& ^9 B& x9 k' a0 t
, c, [4 A7 i4 K5 p0 B rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);6 C7 z2 V& r1 |! e q
if (E_FAIL == rc)
! c- ]& z% ^( k' A8 r1 \! b" I {
) l6 h" ]" j X: u Z cout<<"Error, setting new color on faces failed for all faces"<<endl;+ x: [. E, [4 s+ c
return 1;
* |, p6 V2 U& ^7 P2 J }
9 q7 ?4 e; ~/ y5 R7 F else if (S_FALSE == rc )4 e. O4 `- c7 B0 P# E* W9 F
{
- Z; u+ y |+ \' p: e& i int nberrors = FailedIndex.Size();
! P1 d0 n6 d9 e. c6 P9 p cout<<"Error, setting new color on faces fails for faces :";% y# C7 o3 g) y" J9 }
for (compt = 1;compt<= FailedIndex.Size(); compt++)& L* R. D4 o# \( L n
{* v2 o2 b. [2 |5 y
cout<<" "<<FailedIndex[compt];
. T3 V, ~# d$ S2 h }
) @- e2 V! V9 @4 k# |4 M cout<<endl;
2 a9 r* d" F4 \3 q4 h }
" D1 w5 ?6 M% ~' v+ b else
# a6 f- Q5 B; {. R( ^# y: o) H cout<<"Colors successfully set on every faces"<<endl;
6 N. _/ y" j- K3 l6 E* j //
; G/ m# G" l" p+ U1 D! f& z //9 - retrieving colors we have just set
7 E( i6 @/ g$ x8 z5 \9 v# i' X: { //
5 r; I. K, g1 M5 t0 h" v cout<<"--------------------------"<<endl;( @- R4 ^; x7 Y
cout<<"Retrieving new colors"<<endl;
0 l7 n; V. i3 t1 }# b5 L; ]7 X rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);8 x' T1 `" X/ `, K0 l
if (E_FAIL == rc )3 ]9 n3 o3 R4 C
{
& V4 f& q0 ~4 {* b1 e8 U cout<<"Error, an error occured while retrieving current part colors"<<endl;
( h& x3 }. t. ?* d% R return 1;/ E1 P# n& a' R
}/ U6 j e- y) I4 Z6 j
- M. J# r$ v8 c/ R0 |
for (compt =1;compt<=nbfaces;compt++)2 W; `4 T1 b& Z9 J1 ]" F& T7 W
{
D) Q' Z K: _. X3 C. L- d cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;9 {6 A/ x! l/ B
}
: P2 Q: J7 H/ n5 j& S9 g8 j4 D& F. y e
//
+ y. S3 f8 {/ W //10 - Setting Applicative Attributes
2 m; v y; y% N' ?1 Q0 Q$ i/ r7 Z //
( |- n9 D( {5 V$ u
9 x. O# c! v/ Q; T1 l# C8 t //; h3 ]) M {7 P
//10 - 1 creating new attributes
: ~; ^7 i* l0 T+ v, r i8 T" g9 D cout<<"--------------------------"<<endl;- V+ T# S, b) u$ p9 Y _8 s
cout<<"Creating applicative attributes for different faces"<<endl;# w7 I, |! b; ]2 ^6 q# U" ^
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];) ^) L% _( b- w; r0 G
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
) S! x9 g1 K+ Z CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();6 l! a( g3 L$ ~
for (compt = 1;compt<= nbfaces;compt++)0 H' P: o" _; d( ?' W& F" U" M7 }/ ], z
{
: U/ g) W4 T6 g( q8 N. q6 x cout<<"Creating ";
- b( d! n) |+ H x = compt%3;0 e9 F0 T% V8 [% q8 O% u
//for each face we create a new list of apllicative attributes: _$ S; i- l" D' A3 Z' z
//an applicative attribute is made of a Name and a value* E) Q A8 ~" ~+ c' a2 b8 I+ q
if (1 == x)4 T2 |, w, r ]6 ~% p
{
" b# I4 T/ W; o W H% G AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
" |- B2 }( i- C2 @ AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);8 ~2 p1 \9 ~ ^% [: ~1 z
2 h- @1 f) C2 [0 S& ^ g* m
//The first attribute will be the number of the face
* c! m9 T) v: B2 J0 D AttrNameListToSet [compt-1]->Append("FACE_NUMBER");: B' \8 H, }% j" Z7 L1 c
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);) W/ `! [/ f# f
AttrValueListToSet[compt-1]->Append(tempcke1);
7 s2 i/ a9 z' Z( u1 b 2 K) Q2 d/ ~& l
cout<<" FACE_NUMBER with value "<<compt;
# t" y9 N* x; Y' G
% t1 _ q: W+ Z' { Z# Z/ u. m7 _2 V# w+ T0 G //the second will be the color( S( Y- y9 p# `1 X* q3 o6 S9 Y' U
AttrNameListToSet [compt-1]->Append("COLOR");& I9 c" B5 v# J3 w8 ]$ I, n
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");0 O* a+ ?, Z! c, i
AttrValueListToSet[compt-1]->Append(tempcke2);
3 H/ Q$ ]) i' j% n8 P- e
1 E( o1 u& B2 c2 n0 z/ g' m cout<<" COLOR with value Red";- c7 t- J) A, S; p3 R
' m) w) \$ \7 f# ?5 }6 e9 D
//the third is x& i6 L$ V. G; n' |0 R3 k
AttrNameListToSet [compt-1]->Append("X");
2 G- U2 i6 P6 e k8 w$ K CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);2 V/ I7 z u' w3 n6 N* D: e
AttrValueListToSet[compt-1]->Append(tempcke3);) \$ m/ ]- D- g' W" f* | d
6 S v$ z% L/ ]* r" T2 s cout<<" X with value "<<x;
' Q% A: ?1 b) L8 ? cout<<" for face nb "<<compt<<endl;
" X7 g( s$ k0 n6 V4 ?# N8 _8 O- ~ }
/ Y" [* L/ O- I, o else & I1 G$ B% d4 K% J) q
//just to show you you can have different size of list& B8 W( P; c) }4 R0 j
{7 y6 k5 v, Z) h4 } }
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);0 Q U. S8 d7 ~. Y
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
3 e8 _6 n C( D& B& |
& S/ A' R8 T/ \% B$ ] //The first attribute will be the number of the face
' @0 M* ^+ b& _! d6 k0 t AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
+ a3 ]7 Q- \- f% B- ~1 X* G" G CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
9 @8 l1 E7 e2 x2 V AttrValueListToSet[compt-1]->Append(tempcke1);
( b) t+ s, E& ^3 x" w |5 T1 [
; T; d; L- d: W$ p7 P0 u9 { cout<<" FACE_NUMBER with value "<<compt;
7 D0 Q( n; r/ k% ^ m3 Q- c c6 a
//the second will be the color
+ ~* @/ \" Y9 O* V, c6 f, q+ F AttrNameListToSet [compt-1]->Append("COLOR");
: [& |" r" j* m7 @ if (2 == x)+ m/ k/ y- \* n- a. L
{
8 i5 e; }8 I' [7 _) M5 Y CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");4 V/ `! ^4 U+ ]# u8 Y& B8 N
AttrValueListToSet[compt-1]->Append(tempcke2);% w9 `2 d- ?7 A3 R1 l
. s; `2 M# k$ H6 f7 { Q
cout<<" COLOR with value Green";3 t( }) l3 G) i( Q5 D* Z
}
7 c' p1 T+ B$ Z( b" h if (0 == x). m# h+ X( M5 p% Q2 @: }+ D9 b" J- b
{4 d# V8 M: Y3 m9 N8 d( R/ \
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
$ Z3 I: H9 K2 j b4 K# A+ ~. H AttrValueListToSet[compt-1]->Append(tempcke2);
# X- l2 K& u: u+ t5 j @% ]+ ^3 ]3 n 4 w" g$ v/ ^& T# P$ A# y% W1 a
cout<<" COLOR with value Blue";) a2 F1 ` F" m; t1 i- z
}
& D+ ?: j% ], I1 M0 e4 B0 G! S& H; q4 l0 O$ A- j+ X$ v+ o
cout<<" on face nb "<<compt<<endl;
! A7 [5 ]* T6 z) ^; D# R* q% B! g, `1 D& E- b
}& I2 |3 l; F3 t# r9 x* G9 i
}
3 y2 {+ C* \% L5 }7 @0 l) d* a0 y' u2 d$ P
//10 - 2 Setting the applicative attributes
# ?1 L! M4 m+ v7 D- Y cout<<endl<<"Setting applicative attributes on different faces"<<endl;2 G% {( ~, w" s$ J
FailedIndex.RemoveAll();
, L' x- E C6 m. l: E7 g9 X rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);1 _3 Z+ _+ Q/ M* R* ]. h- p
if (E_FAIL == rc)
. Q5 I% u# }1 A {+ r& l4 T5 \+ v
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
5 _3 S1 j0 c! ?1 H5 ]% z' w* v }: A) S" V' Y7 c( q! E3 w0 S2 D
else if (S_FALSE == rc)* O! e0 C! }# C K% |. d; D
{: G5 F4 R% R4 D! {7 ~- T9 v- D
int nberrors = FailedIndex.Size();% T3 O5 }% @% ^3 g* i
cout<<"Error, setting applicative attriutes on faces fails for faces :";
& D9 U- J# H# h% I- P; Q for (compt = 1;compt<= FailedIndex.Size(); compt++)
( M- ^3 v# j, w {
! ? G1 ^ \; M8 |) O8 ~ cout<<" "<<FailedIndex[compt];
- n" |& y7 W: Z8 e: i- B- S }& n3 P" g& s2 b; b: ]: l
cout<<endl;
* c* D% L, ~+ q: }3 \3 \: Z }
4 G6 j' G1 o$ o else: S% |; C/ r2 E% @5 f
{- `- \5 |/ N" @4 X
cout<<"Applicative attributes successfully set"<<endl;7 o2 Z8 _ j( z
}% i3 ~- }8 V! h9 j
) V+ Y4 h/ h! l% W) @! E9 `
//10 - 3 cleaning
3 v" Q0 b I% M% i: Q# | for (compt=1; compt<=nbfaces;compt++)
1 }$ y. K+ _2 y$ O+ e1 L/ I5 N {
& g4 }4 l& p% Q AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;5 R v* P/ q" Q7 H
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;: I+ G, V6 P1 n5 e$ s& @ |
}& `# ?# e2 J R
9 X. P3 d/ E' F1 K delete [] AttrNameListToSet; AttrNameListToSet = NULL;) F x/ k: r" Q- ^6 y+ w* K$ l% }
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
, v$ `8 O9 P! _9 @* J! S6 |+ L
$ }/ I" S. [3 M3 I1 [ //% X3 c7 S! J: t1 F
//11 - Retrieving the applicative attributes we have just set' ^9 S1 ~! k2 G/ t
//0 ?7 ~" {# m" P
cout<<"--------------------------"<<endl;
/ L# `+ E( L$ B cout<<"Getting applicative attributes on faces"<<endl;
; v+ \, k* o; V- r# I //
* {/ s1 X3 i' W( v //11 - 1 Getting attributes, ~! K4 H9 n/ d; \+ I
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
4 b2 J9 g. N* q- u/ M' |5 Q CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
' U. r( x1 l& A; i rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
+ @: r) x3 z1 o9 n1 }" I if (SUCCEEDED(rc))0 d3 W/ N' e8 ] B8 V( Z! ]# B- ^
{0 o& J6 {! l3 Y
CATListOfCATUnicodeString templiststring;& ^( |+ `8 _5 w) q$ ^7 s# ]
CATListValCATBaseUnknown_var tempCke;, R* k1 O B- U5 R9 n. c
for (compt=1;compt<=nbfaces;compt++)
0 v0 S9 [6 o, L% o {
/ a+ E0 L) S. B0 T; t6 V* a" ] //retrieve a list a position k (arrays start at position zero).9 X1 o6 ~5 J# w4 i
templiststring = (AttributNameList)[compt-1];
% r# L o: I: c5 j9 \ tempCke = (AttrValList)[compt-1];5 T- c. S' r$ p( l, e2 O" C
J( Q8 y5 U& @( i8 n0 O/ v int nbAttributes = templiststring.Size();
5 a* o" u6 ]; D" F* ? int nbValues = tempCke.Size();
* S z2 i. n2 m. O2 \. Z" _( m) F* \# T( p1 g
//the list must have the same size! If not, we jump to the next face3 t7 b% a' u- [
if (nbAttributes != nbValues)
; |' L* V% Q# N2 F o {
+ ^7 O0 J R, P/ i/ V* O cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;/ I, R) t4 @ N
continue;
4 l" ]' k: G4 K }. ~# n2 o" b2 V5 |; }. z
else0 s' I6 m) v. ~- T1 C( U! J$ M2 `
{ k5 W7 }5 P& q$ X9 u* X- o- p
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;' q g$ n" G1 W& V( o9 L: @
}. B; Z) \) N$ v
for (int i=1;i<=nbAttributes;i++)
+ j& G# T/ ?/ o5 U {
9 b4 r' ^) m7 y- X9 G3 L/ n cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;* G' L8 K. M* E
}* t& v1 X" L- X3 k
templiststring.RemoveAll();) o% V- j8 l2 f, F: F0 [
tempCke.RemoveAll();
' H: [; _7 B5 I# O" d% f
1 _+ ?1 M# t* h8 Y, A }( D% u X& u2 a; l, R
} {3 l2 Z! e4 d! B, g9 h4 p
else if (E_FAIL == rc)
) [" j$ x& [5 ]0 v* A {0 Q1 ]$ x) ?1 I% J- S
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;5 K) W; ?0 b% k1 Y6 H; }; D$ j( s% m
return 1;
! y! `8 H& w$ t }
8 {9 X+ p! Q6 K4 g //
* a8 J! D/ f0 k! J* b //11 - 2 Cleaning List:
" d, x/ ?4 D1 s2 A9 @2 I4 ` int i = 0;- e: t" f3 Y/ D7 R
for (i=0; i < nbfaces;i++)
8 a/ O- u# z" i% |3 [) \) z { m% h0 R3 S: B U g4 s
AttributNameList.RemoveAll();
% L* `- b9 D4 l$ D: ? AttrValList.RemoveAll();! A; I0 T( X) L O* |3 ]. O9 G
}
) L6 r& q0 k1 b( d+ y' E1 `$ M$ z delete [] AttributNameList; AttributNameList = NULL;
7 O- ]2 J" r. | delete [] AttrValList; AttrValList = NULL;/ M5 f7 f3 r. J5 `: V
. J- `9 t! x# r. @, ]7 Q. H
for (i = 1;i<= nbfaces;i++)
3 D' L. }) o: ~9 U- Q8 q: g7 [ {
, }. k3 u1 u# N* V; n* ? Brep = ListBreps ;& `- l h$ n" k9 n
if (NULL != Brep)' o. i1 i, t. N' D
{
- }: C1 ^+ M4 E( z( ]* \ Brep->Release();! l: \2 x5 W1 q" y% m0 G
}5 n L$ ^" M, c. J
}: }& ~2 }7 _/ r# p6 M( h
ListBreps.RemoveAll();[/mw_shl_code]. d2 ~$ o( L# X0 b) F! V( g0 `
|
|