|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
1 k: D" s3 ?: }2 ^; h) S2 O y //
( h% ^# i) x _3 X6 C //7 - retrieving and displaying current faces colors- J, ~3 L: p! X* J6 S
//4 z. N/ h! s4 V2 ]- w* w/ x
cout<<"--------------------------"<<endl;) [! s+ B: E5 n- I+ }1 N7 L/ A
cout<<"Retrieving current colors"<<endl;
: B9 U+ R. n5 v+ \4 ]; N5 O- X CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;* ~9 V5 V' Q; X4 N1 |
- B- I, Z, R; [! d8 O* R
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);. ^4 l {4 r: n$ ^) p
if (E_FAIL == rc )
6 F. ?$ _+ T. I {
8 F% Z2 x' W8 M: j8 s cout<<"Error, an error occured while retrieving current part colors"<<endl;- W8 ]" A! M* d/ e# N9 W' P
return 1;
7 O, b! b7 d+ [2 X, N8 e0 v }
8 `9 _4 f: `/ Y7 Z: R* N5 x+ t* g% _+ y! Y( \! b
for (compt =1;compt<=nbfaces;compt++)1 T9 x5 Z' R- P/ u
{, C2 R- d, s' b- U5 W; f
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;( o0 {* D! l: V
}
! i/ J- ~9 O% l- L* r5 g$ O8 s5 g7 x% g3 k, d( R$ L
//
% W9 S+ Q2 H; S% N+ k+ p7 y/ p6 C/ V //8 - Setting a new Color on all faces
7 r; E& o0 y; @# O( Z9 V //; M* c: W9 n+ V
& t% W! o( D+ d' v; P
//we are to color the faces with different color according their position : three by three will have the same color
, L5 W- T' w& t6 H7 A r0 A) C cout<<"--------------------------"<<endl;
6 h: j1 S! }+ e* _' w2 O1 ^5 E cout<<"Setting new colors"<<endl;
- V8 `& g" h- p$ P ; g& f/ n9 ?3 K
CATListOfInt newRed,newGreen,newBlue,FailedIndex;1 ~3 L/ e, X$ E& T
int x=0;$ {& `' W; z- ~9 o) r y* }
for (compt = 1;compt<= nbfaces;compt++)7 U6 M6 n' s% T7 s5 U$ Q
{% V/ ^8 v0 q( B$ ]0 D
x = compt%3; ~2 A# y% H+ y
int red(0),green(0),blue(0);
z0 z) w5 r( H" H7 ~9 R if (1 == x)
4 [* S; m! x* e red = 255;
3 N, t( [" t) I; V/ X a& M* s if (2 == x): F! r' b/ V) F( v6 ~$ ^* ]. I' V
green = 255;9 d4 A( s. I* c0 ^ K
if (0 == x)0 T2 G5 a+ x' o: Y
blue = 255;
( V5 f/ j8 o) H% \$ E6 A) w newRed.Append(red);
$ D! g7 r: S4 q3 O newGreen.Append(green);
" ]; S% l6 k$ a newBlue.Append (blue);
0 z; h7 r- T; A6 w5 ~9 \# m cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;! S" v2 @! z$ y# ?" [. T) C
}
% @* V% X( l6 k K7 g3 l) A, ]. Z2 L$ u0 x) o" Y
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
9 V) U: Y' O, O' L! h if (E_FAIL == rc). X+ Q. s& a/ y3 x2 K. g
{
' D I* }5 F/ z0 B9 N; {" e! x' D( b cout<<"Error, setting new color on faces failed for all faces"<<endl;# K: K; k% ?* j- y
return 1;
2 A, J; n- B1 o5 a% ^ }+ j7 K$ ^( s* \6 i
else if (S_FALSE == rc )+ i' C2 ^* m8 U6 ^& F
{
" D5 ^. T5 Q- M8 @ int nberrors = FailedIndex.Size();6 @4 ]7 k0 ]8 Z+ d* u+ _+ W! R0 B
cout<<"Error, setting new color on faces fails for faces :";
8 g' {% q- U! u, n$ N for (compt = 1;compt<= FailedIndex.Size(); compt++): O8 c: [7 |. M- |( \! {/ l
{( w, U C' u% l: z, e/ R% z$ K0 b
cout<<" "<<FailedIndex[compt];
/ r! C- x4 v- N% s4 `- \ }0 V5 n7 l, R+ p4 ?* ~9 |
cout<<endl;& z: G& D+ _) D3 W
}
+ }* U0 {6 F2 B# H+ _/ G else
2 E# d: }' z; c cout<<"Colors successfully set on every faces"<<endl;
- r ?1 V/ I2 S // `% h) C2 Y5 X6 ]; H
//9 - retrieving colors we have just set9 Q; R' H' J- d1 M
//4 A, `# W( I1 @8 ?, B0 u/ V
cout<<"--------------------------"<<endl;
! _% d& w$ u- A0 K) [! ` cout<<"Retrieving new colors"<<endl;6 {2 v9 D# E; H, [. t4 j/ ~
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);* [8 R. h9 j* T# Q R
if (E_FAIL == rc )
0 h2 ^2 l% L/ o# i {) f7 l a9 X |% Q+ M r1 E1 V3 o
cout<<"Error, an error occured while retrieving current part colors"<<endl;9 a, `# i/ E1 h# ?1 Q
return 1;( s; T1 Z3 e0 M
}7 D* _% A+ O" n9 w- Q# G
- ]' t6 J2 s5 g) S6 N6 X for (compt =1;compt<=nbfaces;compt++)4 {1 H8 p( Y8 B
{+ f1 f8 z& o$ Q' _9 {
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
. m v! p9 @6 X q }/ n& _! v8 m' {8 Z) |6 g3 _ @
! {' v) P, J8 D% r* {& B //
1 x; M" n9 h/ U6 Z2 `# t- I //10 - Setting Applicative Attributes/ b5 m' C2 e8 o d! X
//
; c, [7 t ^) _! R5 o! G* P9 n- H5 {& S4 g, C7 R& m, r) t
//9 h2 Y" \1 @# b% O. I7 S$ ~: }4 s
//10 - 1 creating new attributes 5 Y" ]; W" Z) x$ z' |
cout<<"--------------------------"<<endl;9 n* g% P3 ~9 F4 }' w' l1 l
cout<<"Creating applicative attributes for different faces"<<endl;
$ i% {9 y3 i: L7 Q3 ^ CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
1 u+ I8 S0 C: o CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
5 x: N6 u8 g# ]' U! Y9 `7 W: \8 a) u CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();2 W) k9 I# Z* p4 M
for (compt = 1;compt<= nbfaces;compt++)
( ^) ~% u; e) j2 j# P2 q8 O; Z2 A {
. A' [( u/ d3 j7 G" _6 g; M9 X, s cout<<"Creating ";
4 z) C' S1 j1 h- m x = compt%3;
0 N0 O8 q' q0 ]. b0 _) p9 `1 F //for each face we create a new list of apllicative attributes# X6 R& r6 S7 ?& k, f/ c% n: j" S
//an applicative attribute is made of a Name and a value- `# ]- [! k. ~% |( l; m
if (1 == x)9 z; b9 ]4 b0 z# M0 F# S9 f) A
{
$ F. g" V, s: }8 A' g8 r2 H AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);( ?8 K+ l3 J) g# ^3 p
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);) G- F9 W. I8 K* _ e) W7 r
2 V0 h* J( |9 Z f5 Y //The first attribute will be the number of the face) q L8 }% }% r* c% L2 d; K! W
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");7 V7 e4 ], t3 |5 r8 _( I2 F( j
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);0 t6 v9 M: k' e
AttrValueListToSet[compt-1]->Append(tempcke1);
, q* o6 I# ]' [; x4 B+ ~* Z+ ]0 I' f
2 y( x& N( Q/ n3 U- j- @; j cout<<" FACE_NUMBER with value "<<compt;
' {# }4 o$ _0 F: S, y4 W* V7 F, z/ @& A) m, \1 g
//the second will be the color: h( P8 M8 z/ ~+ o6 W+ _$ d- I
AttrNameListToSet [compt-1]->Append("COLOR");
1 J4 s* y) v$ h+ v3 r, L CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");# S7 m: @. X; x5 I
AttrValueListToSet[compt-1]->Append(tempcke2);) v8 \: j- o; N# ]. i/ m
! h/ c: F0 h4 m6 k2 ~
cout<<" COLOR with value Red";) K l# W0 }- Q& B
' O; a, u7 J! ^# U //the third is x
# O# Q* p2 U7 \ AttrNameListToSet [compt-1]->Append("X");' t3 F: y+ o" P+ n$ u- n; U
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
z6 I2 x5 y6 Z- H/ F6 G* H$ [ AttrValueListToSet[compt-1]->Append(tempcke3);
) ?3 w4 u; W+ @% L$ Q# C
1 j( h _1 y ~$ J4 m cout<<" X with value "<<x;
- ^; p8 Y' A* X" U1 ]- G9 } cout<<" for face nb "<<compt<<endl;
/ H7 t4 c& M. n0 X }0 h. [; S* l# W8 k- W' d
else
/ C# x D; o8 { //just to show you you can have different size of list
0 s9 u4 m7 S* l( _6 q5 F {7 U- j. S; n& J8 [
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);/ Z/ V- c4 a- ~8 l4 |! d
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);9 g9 ?3 s q, r) e. P$ D
' o: ~- n- a! ~ //The first attribute will be the number of the face, i5 F- U2 f* @! v0 i8 ^4 f
AttrNameListToSet [compt-1]->Append("FACE_NUMBER"); v: u5 @. P! y ]
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);5 S( o% x. ^; @/ S
AttrValueListToSet[compt-1]->Append(tempcke1); Z: W( Z$ Q; G9 ~' Y" j- J
' k9 q! p$ q% A
cout<<" FACE_NUMBER with value "<<compt;
, r/ R3 B: x) e- A% z4 ?3 M: ]: O* W# L6 d
//the second will be the color7 P. S. [/ z' [4 t: W
AttrNameListToSet [compt-1]->Append("COLOR");
0 d* `" K/ S0 Y6 h) a0 z- R, a$ J if (2 == x)) K- N s2 y4 q" P
{
; N2 T8 a) x4 N+ U9 `, w$ X4 U CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
7 G# t9 T3 x& ?2 Y3 f, U i2 J! \) j AttrValueListToSet[compt-1]->Append(tempcke2);
* c; N; M) @6 U( w; r
% u$ d; ~6 D/ r+ @ cout<<" COLOR with value Green";7 R+ `, n. d2 Y/ f* H Y: v0 Z" e7 D2 O
}; ?$ G; t- K/ f& I6 D) b
if (0 == x)
" I- L1 p, U( i2 \1 `8 x$ a: c+ S {
9 i4 l& j- C! y# ~- l; V) N/ Y! D CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
5 C7 t$ C1 v' u+ U$ K# X AttrValueListToSet[compt-1]->Append(tempcke2);
9 j, P- c9 |) y # n& C% H8 R8 x3 {+ Y- ]
cout<<" COLOR with value Blue";
1 _9 J1 K- t6 { O9 D }
; {" H$ S6 O3 h7 F. y# L5 S4 s4 |! ]; E, S
cout<<" on face nb "<<compt<<endl;
0 G, ]8 u( r' W5 G6 ~! i2 a
$ V) E) k) n! c }
) R( ]: l7 W2 Z' j1 x6 U- r, s }
, D9 h3 z9 o6 m4 |: P
6 I2 I: f% v: o7 x9 T Y //10 - 2 Setting the applicative attributes# b; C4 {+ {( U7 H9 I
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
3 A( N, @8 O0 P @& }! T# Y FailedIndex.RemoveAll();% C+ o$ l( j; l# Y$ K
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
/ S- J( W- A4 I: c. @/ J' S1 K if (E_FAIL == rc). P/ W' q8 p. o) I
{
/ h, b! ?( q0 s6 b; R cout<<"Error, we failed to set applicative attributes on all faces"<<endl;2 M1 M5 }* I$ Z/ l F
}
$ V9 w) A. w8 |3 w0 x5 x+ X8 _9 c; ` else if (S_FALSE == rc)
1 Y+ X0 J$ ~$ |: ]2 J# {+ W8 D {
: y, }* _- H, l! q# l% ] int nberrors = FailedIndex.Size();
' c) b1 w, L3 @7 I. L ?" x) Z cout<<"Error, setting applicative attriutes on faces fails for faces :";
! J1 }% ^1 `8 [3 G: r, ^ for (compt = 1;compt<= FailedIndex.Size(); compt++)
9 v5 h! z" o/ z+ \# H. t; Q$ r {5 ]' i' Q! k# f; C! L$ K
cout<<" "<<FailedIndex[compt];
! T5 [( _4 ?) d$ a l }; ^' p6 M' g1 ^+ x A
cout<<endl;, F# E5 ?2 A% }$ G
}0 q3 k |! [9 X
else
6 M% m$ H0 s M5 a n* a4 f4 c! {7 _ {
6 n E, e9 f7 t0 i1 Y0 h, y$ s/ q1 o cout<<"Applicative attributes successfully set"<<endl;
3 \- k- e/ Q% s% Y" y2 L) R- k, [& Q }) L; T6 H) o3 j0 w J2 P) ^8 d: @) g
* j! h4 X- I& C
//10 - 3 cleaning% Q, b' I, j2 d& ]# J
for (compt=1; compt<=nbfaces;compt++)
& Y* v Z1 k* S! W0 L- U& K8 v {7 Y: ?& ~6 x, `
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
$ H }: K5 B# o AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;- f+ Z8 t6 j! Q4 c$ O
}
- W, U- Q+ R1 S) |6 T6 W- J2 a8 ~0 c, v, L
delete [] AttrNameListToSet; AttrNameListToSet = NULL;9 |8 N& y m" F/ Y7 v! f) i
delete [] AttrValueListToSet;AttrValueListToSet = NULL;5 T, q5 A/ e) Q# d! @1 q: h
2 I6 a2 x9 a3 d" A& d, G
//
7 _) {% x5 [/ x k //11 - Retrieving the applicative attributes we have just set
' |2 p: N% N0 N6 _; [ //
$ c3 x g! q$ j7 ^0 S7 k5 @/ e cout<<"--------------------------"<<endl;
( C" y- r4 p( b7 I" d cout<<"Getting applicative attributes on faces"<<endl;
. g2 a! J% ~9 @4 m& X/ Q9 D( F //& H. C3 P4 a P* n$ ]8 z* _6 b
//11 - 1 Getting attributes* d( C. T% e+ H0 Y% H, U' L. f
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];8 q- o& V1 _) x' u8 P4 _" J/ s- R6 y* g
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
& w* K( Q: @8 m( ?8 X% B6 J rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
. V# a9 i4 x' U* h; s* [% q if (SUCCEEDED(rc))1 F; G" f& z, Q' e
{& R# W" s+ o9 E4 I+ C
CATListOfCATUnicodeString templiststring;4 r* X* b2 C2 L/ A, W) P6 a
CATListValCATBaseUnknown_var tempCke;" D' e+ y ^3 l- O
for (compt=1;compt<=nbfaces;compt++): ?0 j- H" \* a/ ~$ O
{6 i& C. h7 W/ u o$ M! O- X
//retrieve a list a position k (arrays start at position zero).
) u# R( R2 Y( E templiststring = (AttributNameList)[compt-1];
5 I9 e" r. J# t. v+ Y( I tempCke = (AttrValList)[compt-1];: K3 D. P1 @( s) C5 e* H
2 d& j# i& J) J int nbAttributes = templiststring.Size();, z6 v$ M2 M9 V6 h7 ]; o
int nbValues = tempCke.Size();5 S) e8 t/ I, O+ y5 Z
# C, Y* o1 c* N! k9 E
//the list must have the same size! If not, we jump to the next face
( W/ j! n( T! }' F; N- M if (nbAttributes != nbValues)
5 }# ~8 i% V2 `7 O {" b% l: X g, J4 E
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
! I5 Z0 i H: o: n continue;
! @7 ~) Q3 |% O% L }! |% O5 Y8 E6 q) k) M
else, @7 ?5 \1 d4 B
{
6 o+ B1 p0 N$ l; u cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
. h: e0 P9 h& Z( L4 S }% s, q9 O, ]: i6 x
for (int i=1;i<=nbAttributes;i++)& x5 n9 @( H, ^
{5 v) i) n% X/ v% t" k
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;5 |" P# n' P+ e, V L$ o
}
4 \0 ~ {/ A' @) W templiststring.RemoveAll();5 u2 s( |1 T9 V7 `2 _9 K7 y3 Z
tempCke.RemoveAll();
9 J2 h* A. E9 B( c4 K5 h3 J' g, k/ U" Z3 r u+ P- g* F
}! r, L$ p& I6 j) a& h y4 n4 H0 Y8 G
} B9 E: t* g% d
else if (E_FAIL == rc), T' x. N9 S/ s' M+ J& j+ a
{- B4 i% S+ n& L# n0 P" X! G
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
% V: k ^& T# ? return 1;0 q; x6 \" Y# n
}9 I5 T- _ L" ?* r
//
: w0 o# m- O8 R. N- d% W //11 - 2 Cleaning List:+ D5 v: W1 o. {" K2 d; E4 ^; `! U
int i = 0;
/ P) f( B8 C: }4 q for (i=0; i < nbfaces;i++)
6 K3 K" Y& B* |/ z+ U( X% N {9 |! Q7 I! q) R0 j& V5 O
AttributNameList.RemoveAll();8 Y2 R9 I5 E. B1 ]7 J7 ], W
AttrValList.RemoveAll();/ Y) v3 D9 I1 k4 n, X" B
}
. T1 {- j% B% ]6 g: \$ r delete [] AttributNameList; AttributNameList = NULL;8 n" f' P( _) @% I
delete [] AttrValList; AttrValList = NULL;
6 x9 E1 N& d# I% j+ ]/ h1 }: c
for (i = 1;i<= nbfaces;i++)
+ R9 R* o) `- l& r0 Q9 U* N" u {. s/ V; I# N: J4 y) }$ i7 V4 I
Brep = ListBreps ;
) V% z4 R$ S% N) c; O, z8 S3 t if (NULL != Brep)
9 V( A4 D9 k! @1 Q {
) r" N7 k8 J9 f Brep->Release();( z8 e5 m; D8 c# V6 f5 A" Y
}8 E; A6 N3 J& H# Q3 ?
}* k) m* |: y; a
ListBreps.RemoveAll();[/mw_shl_code]2 c4 _( O1 Q+ v; \# o1 H- F- I$ O+ }& _
|
|