|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
_* l/ [. r0 g6 Z7 c, n* c% ? /// @9 o+ N: N2 m# |
//7 - retrieving and displaying current faces colors7 P3 I6 l" p' p% \! w# F1 Z4 b
//
+ ^: A* F+ A5 Q T' L cout<<"--------------------------"<<endl;
. g7 p1 y% c, ]2 E4 p" q3 c cout<<"Retrieving current colors"<<endl;
: P" e( T0 R4 V3 A) t CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;! i: }7 {) }* Z
4 b3 o. U5 f* L+ w2 U
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
! N8 W8 O8 _3 [* L- d# K: n t1 {# m if (E_FAIL == rc )
2 P8 ^) l# i/ j% k {
. y9 z# N8 j: u, C; ` cout<<"Error, an error occured while retrieving current part colors"<<endl; W" n" J( Y( o2 a9 l: E- ~( h9 {
return 1;
$ C5 u' U( e2 m$ N2 P }6 i) S/ G9 J* ]4 Y. d
+ R+ H+ x$ C6 N) x* f* V- E for (compt =1;compt<=nbfaces;compt++)
2 l: K# \, P+ Z3 _7 a5 X {
6 z9 r1 P. s) `" L; l; R cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
9 B# }; B" K0 d8 F9 Q, f }
/ Q7 @% S9 C$ s% I6 t6 g/ [, a; y0 @" d8 Y' Y* x; x: z, o. e
//
0 A1 X# P' f3 F //8 - Setting a new Color on all faces( k! k, g/ o6 d2 R' m
//- U# K" U, h- \7 L2 F, T
+ a8 y1 e# r0 \+ b
//we are to color the faces with different color according their position : three by three will have the same color
; `- L" M! h5 T( b cout<<"--------------------------"<<endl;
2 R4 r" K0 [8 ]9 l* K) ^ cout<<"Setting new colors"<<endl;$ f3 }: v! `" ?5 i; \5 w
+ `8 D/ r$ m' s CATListOfInt newRed,newGreen,newBlue,FailedIndex;
' A; k& h7 I# [0 \ int x=0;, M& C- K; ?- M' L" l6 b
for (compt = 1;compt<= nbfaces;compt++)9 m) T" z+ k6 N2 p
{
1 e2 f+ e( r( ?) z+ Q9 ] x = compt%3; I: g9 X! @% w5 M2 t
int red(0),green(0),blue(0);) e& z* T( G; O& p2 q) w8 `. V
if (1 == x)5 a# B0 o' I+ b& \ B9 B
red = 255;' m0 B0 _: R& R7 ]3 f' }" b Y
if (2 == x)
7 d% y* }, {# @1 R green = 255;
5 m! j' [+ W! y+ T. U; O if (0 == x)( [& a$ a9 e$ {3 d6 `1 j) a
blue = 255;
3 F8 O# l2 x' ~# x* v# S7 e newRed.Append(red);
( z8 y$ \% q' }& E newGreen.Append(green);
6 L! [ B5 T" [/ m9 `5 }! o newBlue.Append (blue);
+ f% e3 a" p* D! ^9 W" I, b# S cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;3 _* V, y0 y9 `1 P3 A) w* ?
}. E* x& C8 v# l' \2 {, Y5 l
' B8 q& T0 U& ~5 N3 M rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
1 W. p" M2 T. L% c9 c6 Z2 _' j' e3 S if (E_FAIL == rc)
4 ^7 x9 D9 g" X {
, u6 t# [# k1 i5 X6 ^7 f cout<<"Error, setting new color on faces failed for all faces"<<endl;
$ k2 m+ K0 w/ x% }6 Z- w0 a return 1;
( f1 _6 {7 e* _4 H- R }
9 x& L4 ]/ U6 X2 u* | else if (S_FALSE == rc )
4 ~/ K( E0 @: o: J$ Z8 P {) k, \- [% _' C- t) L4 C$ {. e7 @3 k# W
int nberrors = FailedIndex.Size();* C/ G, j6 w2 R2 R6 d
cout<<"Error, setting new color on faces fails for faces :"; I; o* d8 P1 D( p
for (compt = 1;compt<= FailedIndex.Size(); compt++). a( f7 j7 y, }2 m( |
{- N+ w0 U! }& j4 e8 i
cout<<" "<<FailedIndex[compt];
( M% }: u! ?% p r }
# g) Z* Q- N4 p3 }7 ]& q5 w% U) S cout<<endl;9 L, Q5 A/ l% L& R, ~4 v
}
9 t* N2 B8 n6 m8 { else
! l* ~0 z5 u- @' P% B5 z cout<<"Colors successfully set on every faces"<<endl;3 }+ f% l. a Q0 T: g" U
//
& q& `5 S; e. q; a1 ? //9 - retrieving colors we have just set
! o/ H7 ]# _- I //8 P* o4 ]% \# {' ~* C5 B& y
cout<<"--------------------------"<<endl;6 \" u. L/ d+ A" B0 O* |/ W% U
cout<<"Retrieving new colors"<<endl;# d: i4 A0 z- H6 B: ^
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);1 H( f% s9 B0 {8 I5 n" m# Y* Z
if (E_FAIL == rc )% |% g8 f/ O% s5 A3 H
{& j1 y9 ^+ |+ S+ C5 @" C u; m5 J
cout<<"Error, an error occured while retrieving current part colors"<<endl;
9 h! ?- ^, @% D0 C return 1;
* F6 R) w8 P) r5 p* B) S }* L. q2 X2 o& b3 ^! \2 b
. h5 M% f. j) @/ i4 C# O& }( o. }" b for (compt =1;compt<=nbfaces;compt++)
# F- B" d$ x: x/ U' F) L6 [ {
, @% i! N0 O! Z# f" B0 N cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;' \# F0 V& ?. \
}& u H3 Z- k0 n% S' E' c I' O) x
6 ?7 ?/ X. r- A5 N$ p9 o& ^
//
7 i. w1 P m4 v2 h- X' M2 L //10 - Setting Applicative Attributes$ n1 J; {7 u4 X4 K+ |( t
//
& M4 D& u* u+ @8 I5 x& y3 ~' n+ D+ e5 ]# {8 J9 s' J% y& S( w
//
c% B1 m9 R7 Z: M0 P) T2 A3 M! a //10 - 1 creating new attributes
7 Q) s5 j6 g9 L; u7 o+ n* c cout<<"--------------------------"<<endl;
' G5 f5 a. y, Z5 u- W2 F' m4 M cout<<"Creating applicative attributes for different faces"<<endl;
6 p0 l7 N* i# ]8 u# X: m CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
9 u4 J8 s( \ k- |3 d CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];6 J2 r1 C: }3 h5 O2 k
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();9 |: V! c* ^2 G1 y( H* K# E, @
for (compt = 1;compt<= nbfaces;compt++)
- ?. i( x; p- z {
9 B; i l( R- L6 a: r- l cout<<"Creating ";
( S' S. Y4 {8 Z# D9 x2 M x = compt%3;; t' b7 O2 G( y2 C
//for each face we create a new list of apllicative attributes" Z% Q5 n; ?- O! K p" y% Q! Q
//an applicative attribute is made of a Name and a value
# F& s N: F% L if (1 == x)
- ~* W5 V2 P/ g8 w# M5 Z8 K+ w {
. k: {/ }8 E7 S& ^% g F( W# T# } AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);8 X; @/ W" C: Y: p3 Y0 o
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
# j9 L+ i. H$ j* W3 P6 S# F3 L# a6 g9 n! l! {6 O, a0 u* c' j8 F; X
//The first attribute will be the number of the face, R b/ ?$ D1 D2 B: P1 O% x$ w
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
" M1 P9 z$ h9 }' c CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
1 g9 ~- D$ |5 \8 @ AttrValueListToSet[compt-1]->Append(tempcke1);# m$ l3 B7 ^ a- W
( c- R; A3 s9 u( G( k; | cout<<" FACE_NUMBER with value "<<compt; " I9 b" J* q8 O' ?3 M8 v4 w
2 O2 k5 j& d' J' u, u //the second will be the color
8 }+ R, u, h& w9 a3 ? AttrNameListToSet [compt-1]->Append("COLOR");" c* l' q" s% Y/ T
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
/ r: ]$ w: Q9 j( s l AttrValueListToSet[compt-1]->Append(tempcke2);: B- b* M/ F# y: j* F D7 r, b
( p7 i7 u S; c; ?6 h* D
cout<<" COLOR with value Red";
) J A7 ?. |- H* i7 r4 _" h/ x3 ^ ' _7 \ x( C, z M- T. n$ @
//the third is x5 B" h0 |5 c: E, g4 ]
AttrNameListToSet [compt-1]->Append("X");. }! R8 v4 M* Z
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
: T* z. j+ h9 N6 v# V AttrValueListToSet[compt-1]->Append(tempcke3);* v+ [$ q4 Y- s! l" U
8 y z3 ~' [7 r+ N cout<<" X with value "<<x;
3 U2 O7 ?8 ?6 C0 L. p8 p cout<<" for face nb "<<compt<<endl;9 L# y1 ]5 h/ ^
}
$ \$ t! A6 y+ } else ! C4 _+ y# ]7 v& X% [5 N; _
//just to show you you can have different size of list
B! v$ [& y) k {2 r' P( Q* U6 X# T1 S5 c' N
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
4 Z" q/ P O( L3 ]4 r, l% | AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);: k& W; r9 ?" L4 W9 N6 |
, Q( f# m, ]& G0 T9 {$ n
//The first attribute will be the number of the face
) }' m. \, I+ q: g& u" U. r AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
+ h$ q$ |- w8 y- J+ z CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);$ _+ w) q. b2 ?( L3 m0 o3 x! K
AttrValueListToSet[compt-1]->Append(tempcke1);, P, |1 z. q( Y; s
8 M6 {8 q; Z; S$ f, V8 w
cout<<" FACE_NUMBER with value "<<compt; 9 C# H2 S* r5 l. r) p- |/ S4 G
0 s) ]6 u) J! [0 i u* ` //the second will be the color$ y& X6 R$ S7 u5 d# P+ d3 m
AttrNameListToSet [compt-1]->Append("COLOR"); }, S) o [( A2 f
if (2 == x)/ H& R& l# `! @4 w( Y
{8 u' z; g! _7 R: w0 Z
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");! q8 Q" V% h* @9 `/ u4 h$ u+ l3 o
AttrValueListToSet[compt-1]->Append(tempcke2);# o C0 [4 Z" Q5 {" i
! @6 K! d: b& b2 U7 N8 u. D
cout<<" COLOR with value Green";/ R! ~$ [( E6 e. ]
}
& S) b9 Y, ]0 D1 | if (0 == x)
3 h6 Z6 A: T' G {1 X4 O+ i9 B" t8 _9 Q
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
+ f6 |1 g7 T9 z* w1 K AttrValueListToSet[compt-1]->Append(tempcke2);
0 Q2 G8 Z3 O' n1 n7 }
& |, o o/ j% x2 ~9 t3 Q7 s cout<<" COLOR with value Blue";
$ M% C0 `* p, D* Y5 D }: k7 R$ y# D6 h) j% h7 I" W
4 U! ?' @# d7 A8 W' l
cout<<" on face nb "<<compt<<endl; n6 N. q" H* a# r4 Z5 C9 b" M
) n& Q) K# l/ D! O1 [ }
: X! o% k7 g) t }: c R" h+ ]4 x D! y" e1 C2 G5 k
; P, ^( C5 N& H; Q$ V8 f+ }
//10 - 2 Setting the applicative attributes
+ i% h# n" K9 e9 q cout<<endl<<"Setting applicative attributes on different faces"<<endl;
5 Y4 S4 S5 v& E. q- `/ M' a3 o FailedIndex.RemoveAll();
6 m+ l o7 A& G) d rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
9 L/ D* T' n9 @5 | if (E_FAIL == rc). V% A0 e9 C! j) J% Z: h
{, r7 Z% q2 n3 N* m& f
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
* `/ B6 h4 x# d: i( I } q) X9 U0 z& ^9 z* Q
else if (S_FALSE == rc)% [; V( x/ A7 j4 W
{
5 u5 u5 n. k) ~$ {7 j& |3 Q int nberrors = FailedIndex.Size();
6 N! [# z, O$ C cout<<"Error, setting applicative attriutes on faces fails for faces :"; @! V# w: ?) D
for (compt = 1;compt<= FailedIndex.Size(); compt++)6 R/ M1 n& p! ^, {) p* c
{9 T8 K+ V3 z3 F A; h6 n# Q5 Q( [
cout<<" "<<FailedIndex[compt];
% p. _9 I, n/ ?7 G w+ X }- R+ c+ n( n2 T8 p; R6 n0 Y
cout<<endl;
$ y) ?( J& T; N7 F# f: ?: v' L' s }
" o; \7 U& D3 E else K# N! s) A8 \3 b- a
{1 m1 m& o! D4 M+ p5 I O
cout<<"Applicative attributes successfully set"<<endl; B5 p G6 p& G
}: H# D" ^# O4 ]* l- _' O
4 {3 r7 r, z U9 m5 V% N' Y
//10 - 3 cleaning
$ L0 R3 u/ F8 E& h5 s3 o for (compt=1; compt<=nbfaces;compt++)
- G! Q% w* f p! A5 W( g2 C {; H) U& I% f( _8 k4 O
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
* j# [- G# w4 ]# r6 T. M AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
- t: I0 L* ^( T }- }# [( t& U0 S7 q$ n0 d
7 B' R! }0 \2 N2 |$ P7 X
delete [] AttrNameListToSet; AttrNameListToSet = NULL;+ M8 L2 J" B7 \
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
* a. L/ X9 K) b8 Q$ h& L. Z6 f& y8 d5 F: q8 G2 j0 ?" B9 p n0 r
//; P o4 S& ]2 Q0 V- Q
//11 - Retrieving the applicative attributes we have just set, Q9 F8 b9 V- f2 _% X" o# F
//0 J* L) \1 L4 Y# I6 a9 W( P
cout<<"--------------------------"<<endl; H6 o Q: C9 p$ i V) \+ m) f
cout<<"Getting applicative attributes on faces"<<endl;1 |9 A% P, L" ^; o( F! F
//
. f7 m, A7 x$ \( ]% M1 p //11 - 1 Getting attributes
4 Z5 @9 d; f' z9 ?0 C3 n CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];/ q5 B& I) {0 i- Q3 s# f$ M8 j
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
' W9 D4 f2 p: d% V6 ?0 s5 C: W rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );, ` \% Q$ }; E. v
if (SUCCEEDED(rc))
/ y1 q3 N: e, T. V& S! D1 r7 h {+ } d# j% J' x, c5 K
CATListOfCATUnicodeString templiststring;
8 I, K& _" F- X; o CATListValCATBaseUnknown_var tempCke;
, d& J, b0 @! @! I c4 j8 i- d' m for (compt=1;compt<=nbfaces;compt++)
# y7 g. d }1 M" r {; K$ s7 Y1 |+ h6 U: K2 A- {) }
//retrieve a list a position k (arrays start at position zero).3 w6 ?7 R7 y8 Z, |; o1 T
templiststring = (AttributNameList)[compt-1];
9 b: \# x- `: Y. q* Z) ^) Q# x* `, G tempCke = (AttrValList)[compt-1];
( Y* K! r' f# a5 g* t# Q
4 @1 h/ V6 H+ c2 v5 [ int nbAttributes = templiststring.Size(); Q# T+ K: |& D9 P' X8 s3 k
int nbValues = tempCke.Size();
, w$ R' [; |5 g* }# Q. T! N
3 G( O( o- ?( y //the list must have the same size! If not, we jump to the next face4 I1 |6 t; [, d; M1 I* ~1 J
if (nbAttributes != nbValues)
+ l% ~- B7 `5 y' V/ t! J {# _" d- s1 B" x% R& h0 a$ J# a
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;; S' J# s: I Q4 n5 s1 m
continue;
- _- F+ l: t8 m4 g& a }' \2 O5 A) s8 r# F
else
+ w% H/ [; X# e" P) z0 E' t {
0 |2 e9 i# P" w7 p cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;- X n6 Z9 M. L* P: M, k& K7 D
}* g9 C9 {/ | V/ H! \1 S+ w: V
for (int i=1;i<=nbAttributes;i++)" I g! W) k4 [9 _- S9 e
{
9 J0 ~7 K7 K8 j. g# d3 q( E; p cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
, q$ _# ^; b, }, Y. z }
$ }9 H7 i+ W w* Q" U7 T templiststring.RemoveAll();! e9 j- A0 W3 ^3 M5 ?! f8 S, [' J
tempCke.RemoveAll();
# c) V8 k, U5 w( t! Y# }' J) j" i$ W3 b2 ]* ]7 j: D6 N7 Q4 ^
}
; a9 b$ s2 k9 R5 L0 P& o5 o8 N$ C }
7 Z' \& z; ?6 [ else if (E_FAIL == rc)% T- n! N2 S' A# O) b
{5 T: O% B' x% Q
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
+ j8 t! Z& u: K4 K! q( j return 1;
6 A7 x6 F; v( [# R }
! N$ g) D. H, }' G5 P //
( m4 t' ?9 |2 S" e# I5 X //11 - 2 Cleaning List:- b; u7 N* m. G& Z& w+ T0 N3 n
int i = 0;/ F0 F0 y( I: P* X& j1 N) p7 E
for (i=0; i < nbfaces;i++)! q% d" Z9 ^( j
{
' t8 L/ X/ a8 V$ d. e w AttributNameList.RemoveAll();/ |. s9 |5 l$ b
AttrValList.RemoveAll();: G# N' ?9 Z. m6 u3 J
}( V% K+ H! q) m* Y! l$ x- g. P
delete [] AttributNameList; AttributNameList = NULL;
" N1 [+ u& P2 X4 d delete [] AttrValList; AttrValList = NULL;
' ]6 }( i: [9 P8 `' ]- a0 e; v
$ X$ b% V# T( k% D2 D6 N0 D for (i = 1;i<= nbfaces;i++)
2 E* Z9 h- Z2 f% h) Q3 V! W {
1 @, R& ~2 d* v, @) y7 f, o) O* D Brep = ListBreps ;+ g$ g/ A( b/ b" B- H
if (NULL != Brep)
- w7 k: X/ z C& J {
6 y& G7 x+ l! A5 D: U4 r( q Brep->Release();
- U3 O% C+ W: N# B$ r: A# ] }
$ z9 j% a: |' `! o# s }
/ y4 w1 m/ [0 P ListBreps.RemoveAll();[/mw_shl_code]$ j5 |4 R$ c0 U( e' N- T$ o& a
|
|