|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]: U$ D3 S: J5 ?4 X' @1 l
//
- B' V- q9 M- a G, } //7 - retrieving and displaying current faces colors; W1 H/ O' }) m* D* L/ Q
//0 E T8 N( _; o: l/ O. N. y
cout<<"--------------------------"<<endl;
% }, z$ a* d* Y+ S; p cout<<"Retrieving current colors"<<endl;
6 `) U; Z$ a0 ~+ N CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
% G3 w4 G9 g: M # F( i9 _+ I& f. v* r
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);6 @5 }9 M- |8 o2 P6 q
if (E_FAIL == rc )1 T- f, P7 f( n% ?& V+ \- Q, m
{
( T# I* d. R7 q4 q cout<<"Error, an error occured while retrieving current part colors"<<endl;
8 ^% t4 R2 W; K: n! a return 1;, S, e& b [! [2 k$ l8 k3 h
}* c$ d5 `, b# D5 v: S8 o0 }; I
$ A% i$ T& k7 A/ g! m
for (compt =1;compt<=nbfaces;compt++)2 a2 w8 Y* r$ b; J2 t/ o
{
7 b2 [5 w5 ?: d% B cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl; W1 V: Q4 s2 [: ?1 F+ r$ l
}+ t2 a4 |- v$ r9 y7 Y* }7 @- }+ n
( v9 p# R+ r5 o5 }9 L0 _& d1 O# n3 i
//
3 ^; u' J$ \5 ]; D0 }: D% { //8 - Setting a new Color on all faces- f4 n Y4 j: y# @) Z6 k& O
//2 f0 R; E$ z+ @( P! Q! j
7 W e, k3 c: {; t o; e5 y. e
//we are to color the faces with different color according their position : three by three will have the same color
; r6 ?$ ~7 |3 K cout<<"--------------------------"<<endl;" F9 x/ p" T% j$ N0 L9 C, J
cout<<"Setting new colors"<<endl;0 g+ _4 Z, k% B& M) `$ m4 v8 ~
: Q: `2 E G) b1 n. I; ?# T" l" R
CATListOfInt newRed,newGreen,newBlue,FailedIndex;" [' ~) ]! y4 @/ `2 |; H* t
int x=0;' L y7 o) N% ?
for (compt = 1;compt<= nbfaces;compt++)# j& k% U$ T) o: ~1 U s9 W
{
{) N9 B) P4 ~0 e! m# I x = compt%3;
' y3 ]- ]2 M9 U8 H6 b# c" C int red(0),green(0),blue(0);. I; M8 |) w0 P: y$ y7 G
if (1 == x)- B% K# I7 }6 z4 d. m+ @ g* m# \
red = 255;, g+ U; ]* y% I9 S
if (2 == x)! X) Q7 ?% q+ F$ ]8 H
green = 255;
7 L9 H7 |0 B+ d& ` if (0 == x)1 n& l+ Z: y$ ]2 Z8 ~: ^0 `
blue = 255;6 d. i+ w2 s2 @8 ~4 z' {
newRed.Append(red);
- f! q8 E( `# A) [3 y/ n& A newGreen.Append(green);
6 L7 A& {6 J2 v* a" t newBlue.Append (blue);& W, u7 X7 j3 j, c2 x) G- A/ B
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
% w0 M) d9 C! \( | H7 T- ~9 J }# t' d/ ]" L4 R. L+ d* A! c2 q: q6 R
$ ~& Q0 v# j/ Q3 E0 e) {3 e4 s
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
5 b6 f; x# l, ]. X/ H w5 @, @* L if (E_FAIL == rc)$ }# T3 I8 y. n5 L
{4 _ \+ S! I* }$ ~( I! X* ]( N p
cout<<"Error, setting new color on faces failed for all faces"<<endl;: P/ q! f" b" q% T% Z" E
return 1;
4 a8 {: k* }" p }) V+ {) ?5 M4 _2 }9 n1 E
else if (S_FALSE == rc )0 a9 K G- e5 O# G& ^; n, V& q4 N
{
L4 w1 H# ~: A0 V7 m int nberrors = FailedIndex.Size();' C- Y! f' J/ q8 I0 ^/ M
cout<<"Error, setting new color on faces fails for faces :";% {. {9 j7 {' X+ j5 Y8 [
for (compt = 1;compt<= FailedIndex.Size(); compt++)
+ b% L% a; u7 \) ~: c0 l1 l% k {
2 r# A6 J5 d) {5 x4 w# a cout<<" "<<FailedIndex[compt];
3 ^' J. A# U3 _6 Z$ ~+ ? }
, r( H0 p* b& d& u$ n- | O cout<<endl;* l3 v2 @- _1 {6 ^8 s# P2 D+ ]
}
, R* }: _! z. A/ q* \5 B else 6 {% \6 H$ [4 M# b
cout<<"Colors successfully set on every faces"<<endl;
) L7 G' y6 J8 M1 ^! | //
8 M) R" ~) `% X3 ?* v //9 - retrieving colors we have just set
. _1 q4 n7 n" k r) Q0 l9 W //
% S$ Z2 V3 j% R5 b cout<<"--------------------------"<<endl;
* ]# s/ y; |( g# r- |& D9 S/ ^ cout<<"Retrieving new colors"<<endl;
7 ]* U; }+ U2 A- a rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
: U" [) p9 t; L1 B/ u0 t4 L8 \! Y if (E_FAIL == rc )& W o; d/ Q2 O$ T; A' J
{
% C. K% ^/ b( c. d2 s cout<<"Error, an error occured while retrieving current part colors"<<endl;4 b/ M/ J+ B9 T1 u7 b3 f9 {
return 1;( o3 p& ~. [6 t- e3 J; L- z0 G; ]
}
! G! O# F8 G3 c1 `
1 g6 u& ?7 T* P6 @- Q% P4 l for (compt =1;compt<=nbfaces;compt++)
* y' d" k3 @) H9 r7 R) G) z4 | {
3 X5 S8 K, ?; _8 \, C+ R cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;% x; z+ j' X& j% A, U8 |0 h0 h8 w; s$ @
}2 K( v5 q0 o8 t6 U
; V7 p! N8 F+ U" p) v6 e0 g //
, s" ~" V. H6 \ Z' l //10 - Setting Applicative Attributes
' K5 h* E1 D; x* q //
$ T9 n1 V ^6 a0 E+ n0 j7 m. R- O, f, z& a2 p/ _/ [/ ?
//
. a9 }- m+ q5 ~/ ?5 N5 p //10 - 1 creating new attributes : J# D$ f% J( e# ^6 G4 [
cout<<"--------------------------"<<endl;
: a$ t/ S' K, l$ j; t cout<<"Creating applicative attributes for different faces"<<endl;; Z" G8 }' q6 R$ @: L
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
" V/ F% ]+ H3 k! n }0 c% d J CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];$ |. ?/ M. s8 P1 z; P; l' F9 N. b
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();; L7 a, C8 S; X, w, A; p
for (compt = 1;compt<= nbfaces;compt++)
. C! s, q2 Z8 V) \$ _4 M2 D {# n# y4 @$ Y* I) L3 }
cout<<"Creating ";: A9 U- w. S% O' {, B/ x
x = compt%3;
% H9 Y2 v: y: v4 m- q! l //for each face we create a new list of apllicative attributes& y; C7 ~+ m' }
//an applicative attribute is made of a Name and a value" b/ N6 ^8 i. q7 ]# h1 Z$ P+ y2 z
if (1 == x)7 u, P( ^5 ?# [
{
' r, E9 t/ h! k ] AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);4 a& S( N4 \+ F8 d8 ~
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);0 h' q( F" q' d
; n5 r# k9 E9 w, R4 n7 k/ Y8 \ //The first attribute will be the number of the face+ i" }' f% ~+ \. S4 ^% `
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");9 s8 d. U5 r" A3 q# @
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
. v: {+ @- `5 O, W AttrValueListToSet[compt-1]->Append(tempcke1);- }2 z& D+ ^$ b- _+ T9 T% D8 _, H
% Y! c3 Z2 x& L# M) j5 v' T8 P5 ?
cout<<" FACE_NUMBER with value "<<compt;
, W) X- `8 U7 h: H
3 N. D( ~7 R% c7 E //the second will be the color3 {* b8 g2 e# s8 M) w3 [% Z
AttrNameListToSet [compt-1]->Append("COLOR");
4 _2 p6 V4 @/ B2 ~! ~; _% C CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");: U/ D, k1 H7 E; M
AttrValueListToSet[compt-1]->Append(tempcke2);
0 H! z: s7 T- [! n& V
8 ?# a! k2 A- n6 g Z cout<<" COLOR with value Red";( M; _0 c5 }6 ]: ^, n& _# j
- O2 P0 b. ]" [: \) c
//the third is x- T+ C. T" I/ b2 R" I" a( J. n* ~
AttrNameListToSet [compt-1]->Append("X");
: G2 r* H& ^ W( A5 J, y3 o$ \ CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x); M) z8 r; {& U) T/ T! U. C
AttrValueListToSet[compt-1]->Append(tempcke3);
3 q; U' ]: Y1 c( l
: L& ^; {5 g1 u. ` cout<<" X with value "<<x;. ?! ?% N2 A# @/ H4 m4 t8 [
cout<<" for face nb "<<compt<<endl;0 x4 m: w1 o! Y% j
}
( L, \# S7 J( x% z" Z2 Y, i else " h7 e3 h& _% i2 z+ k) g
//just to show you you can have different size of list
. X+ L- S5 [0 D' u* ] {$ D0 W4 Y; b" u! |7 s
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);7 G2 N" Z! A1 y( t5 Q
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
/ C) Y& {4 y Q. x& @2 ] H, j/ @5 V, |3 H
//The first attribute will be the number of the face
* P* W4 K% Y9 C* L4 F AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
+ @4 I! I9 Y4 a/ Z& p+ h( X CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);5 L) t& |0 C: v# S+ o& X
AttrValueListToSet[compt-1]->Append(tempcke1);$ T8 s: f9 q a- Q6 T) ?
2 G. G2 ]& Q" D' `3 G- G cout<<" FACE_NUMBER with value "<<compt; " B$ T( b' h \
& z! d% F$ |6 L
//the second will be the color! Z4 }4 k3 A h+ @* q7 h
AttrNameListToSet [compt-1]->Append("COLOR");
; H& Y2 z( l* X, f if (2 == x)
+ n) P& U. {0 ]4 \ {
; `6 ^( K0 [8 g) R5 I CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");% O# Q1 M2 h4 g: w9 a
AttrValueListToSet[compt-1]->Append(tempcke2);: h0 N/ X& h+ V1 A
- |/ k- a: ?& a# o
cout<<" COLOR with value Green";: j$ S4 A+ g3 ]7 x% g
}& ] |* u2 b5 x9 G7 L' X6 W
if (0 == x): Q& I2 g6 T, U1 U. h
{
' D# Q% }6 O. W5 t' e6 L: M$ E9 L CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
- J/ |5 c. D6 T2 W0 H( o" P& k/ h5 N AttrValueListToSet[compt-1]->Append(tempcke2);
+ `$ b# ?6 V/ b! K. ^: Y ' D1 M+ R5 `' z+ a% k. j
cout<<" COLOR with value Blue";- ?. y, q" d& D( h$ F
} ^; T; d0 d. e+ ~! r' F, U$ g }
9 P" ^0 \) P+ T" u Y+ f1 D
cout<<" on face nb "<<compt<<endl;
: [) N) h1 A' ~8 z: [' l0 Z
4 |! \0 Y6 a" {+ ~* l( Q* L4 a }
' z$ i* V' o4 V# t3 x( J, {" [ }
5 m! X4 \/ |& B# [( g: h% z( h0 _- r6 j
//10 - 2 Setting the applicative attributes6 A4 T9 r) V3 ~! M% G7 a
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
7 v5 Q; _" A: P# v4 E: T FailedIndex.RemoveAll();
9 _: X; Q! j$ X! f; Y5 `* G! t5 Z rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);5 }6 Q) a3 g- ]5 s) E0 p& u
if (E_FAIL == rc)
9 ~2 Z) h- I6 V, z) m" p6 y {. m0 Y# d( d7 x0 @& k
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;+ ~- Z+ T* e1 z V
}
0 ~' l; ^ v9 Z0 s) E& x: i: M else if (S_FALSE == rc)
L0 D2 R3 M9 o# i {
1 ?0 M, n3 f7 V# Q K2 N int nberrors = FailedIndex.Size();' z- L5 o: D. ` y5 v
cout<<"Error, setting applicative attriutes on faces fails for faces :";% }) l) I( g- ]3 X
for (compt = 1;compt<= FailedIndex.Size(); compt++)- q$ p+ \9 V" D: _4 {' X! Z
{# d3 @0 V4 t5 `2 e: H L6 J
cout<<" "<<FailedIndex[compt];
) G/ Y% n6 M; L P- U/ s# c }
! a6 u+ l7 M" w4 ? n1 R8 z cout<<endl;
) u2 G0 o2 E- q* L }( j# z, | A( T N
else6 q/ r& L1 ]) t5 x( k. t
{( e( u/ z8 j3 D, K( E
cout<<"Applicative attributes successfully set"<<endl;. y J7 {" T5 I% M
}9 D- ?6 W6 P; Q" X1 @, U
. O0 v: A# C. G; K: N //10 - 3 cleaning
7 K) z# |8 H# T: C. _ for (compt=1; compt<=nbfaces;compt++)
( L: ?# |) ^" _) ?% w4 b/ o {7 ~. E5 B$ k L9 j3 S# o. p3 E
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
! Q. j* X2 _% {: r9 \+ f: u AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;, f, l. e4 {& g( S; ~
}
6 p8 l6 l: s$ N& l0 s; x- ]" s; `) ^& D5 V8 K! N- ]1 E
delete [] AttrNameListToSet; AttrNameListToSet = NULL;/ m! w0 A, }$ a
delete [] AttrValueListToSet;AttrValueListToSet = NULL;0 n8 {& O& q* \
- p* I# _9 Q; T9 X
//, y6 X' T- C" r d Q Z* _
//11 - Retrieving the applicative attributes we have just set
1 B! t( p/ x. }; o //! C. N# ~, r& p3 G
cout<<"--------------------------"<<endl;$ i2 P$ ^* V; n. u2 x. q9 T
cout<<"Getting applicative attributes on faces"<<endl;* s0 |0 k7 W# l$ R! y9 ^8 F
//$ ^- F" }( _* x3 p9 ?4 F! _
//11 - 1 Getting attributes6 X; x* E- q2 U0 m H2 j" B
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
' Q6 `/ A9 n0 J9 q1 C. x% ? CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
, T9 o( A3 v3 [" N- L8 y- }$ x3 G rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
+ R1 u( P- p% o) R' Z9 M- i if (SUCCEEDED(rc)): \3 E/ x5 b) w% j
{; X% d6 G& S# Q2 Y6 a
CATListOfCATUnicodeString templiststring;# J* Q- `% f& R- L1 P
CATListValCATBaseUnknown_var tempCke;
: {( Q; P' f4 g* Y, I4 g# b9 a for (compt=1;compt<=nbfaces;compt++) _" d% N6 Z+ D! _
{
. F) _+ N, C: w* l- q7 \! A; O1 u //retrieve a list a position k (arrays start at position zero).' r& [1 e; X5 S+ F) N
templiststring = (AttributNameList)[compt-1];
+ q9 y) [/ Q3 @* D& x6 q. K& i& u tempCke = (AttrValList)[compt-1];( a9 x' M6 g+ r( m
7 g# A% I4 e) x0 R
int nbAttributes = templiststring.Size();! n/ r- B+ N q' J3 r+ y
int nbValues = tempCke.Size();
$ I9 g& D% n/ ^$ E. m5 _$ \ C: |. O% S- G& `
//the list must have the same size! If not, we jump to the next face( K- R2 _* Z: l) v1 S
if (nbAttributes != nbValues)$ h' j+ M: d/ N0 G+ Q1 g" _& E+ u
{) N/ A/ a4 T# d! o$ k! P
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;3 P& M2 S: q4 b* Q/ ?3 |% p o
continue;% ?3 i0 o% j9 m
}
" \5 C5 D! G$ f" b. b# g+ ^ else
|; J0 g. u9 u {
' h7 t7 [2 ]! f% n# W; U cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
& |) L$ P6 o3 f }
) T7 x$ f% f7 B j for (int i=1;i<=nbAttributes;i++)# u1 ? h. M% e' n( a+ S! p) W. Y* v4 R
{ L. @' F6 |% q( x6 o2 b
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;4 n' s' J2 ?! F+ f+ J$ n
}
0 T0 b# o/ i# o% d; T templiststring.RemoveAll();$ K6 y% _& c) U( ]
tempCke.RemoveAll();
( C4 g+ q' @- \6 z6 f6 h5 I0 L# s9 M( f5 s! R. T' E3 ]9 C
}
- W" d3 F( j* R g: @7 Y( V( R }8 B6 p! c1 G$ p6 o8 V6 _' P6 ~0 P
else if (E_FAIL == rc)
6 L3 w' F0 e- w+ P. s3 { {; _3 d, |# ~; f9 w5 R
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
) g- _% Y) b( D/ r" S return 1;# n! I3 U/ y( {: q
}
; R8 U M$ A1 A1 _4 V. s //" U3 k& ~3 U7 o; [# ]# N) {
//11 - 2 Cleaning List:: E; W: q8 q: K) C+ {: M$ _
int i = 0;
, w: s1 }4 U6 H9 x for (i=0; i < nbfaces;i++)2 {' S2 T0 C' ^: x5 ~
{
# J; }% g/ A1 j- k+ S AttributNameList.RemoveAll();8 B. `1 X& R6 R: k6 w& _/ i. f' s- I
AttrValList.RemoveAll();
' w$ H! e' r# K6 M5 I }7 g- F" g8 Y; m) D ^
delete [] AttributNameList; AttributNameList = NULL;* t1 M8 }5 g% S0 |1 Q
delete [] AttrValList; AttrValList = NULL;1 N$ H- f0 ^* l! e
$ ] ^: x$ p* K5 n4 Q- w4 s
for (i = 1;i<= nbfaces;i++), O, M4 d& t; p+ ]: ]% ~
{
3 ~- p5 S; Q! }2 V0 w7 n& A Brep = ListBreps ;
. K! `& M, P0 H6 B if (NULL != Brep)
5 D; q1 ?4 y8 @* N% | {6 ^" N$ I; e; A0 k) k
Brep->Release();
y. ]! T( q! |, { }+ P6 o: d, |: C( v6 F1 P* b; u1 {
}8 A3 b+ O# |1 } n# m
ListBreps.RemoveAll();[/mw_shl_code]$ u9 L5 m ^9 Q0 o9 [
|
|