|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]4 h2 \$ O1 F8 n0 V( k( p, g
//
1 k8 I0 B1 O7 t3 Z$ k, C+ \ //7 - retrieving and displaying current faces colors
3 o* ~+ K; n e0 T% ~ //
# ]& e! V: ]3 Z: Y3 P6 v. E; A cout<<"--------------------------"<<endl;
+ N0 h$ m0 s! z z) G8 } cout<<"Retrieving current colors"<<endl; t! |2 L4 [# O
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
, {( w; {0 v8 {5 N5 ?
1 M8 I; ]( V% j1 O& F: X1 r rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
: U+ {( M \1 ^' c; i* S4 Y if (E_FAIL == rc )* {5 s$ y' k" G1 c
{/ y* ]9 ^# W" E+ S3 U
cout<<"Error, an error occured while retrieving current part colors"<<endl;6 E- [. N( Y1 V% I+ V8 B% t$ j) q
return 1;
. J/ K3 C9 d0 r. S7 } D }
2 r/ R" n; v# O1 R! ?7 Z
! k. |% {8 }5 F3 g for (compt =1;compt<=nbfaces;compt++)
3 o7 f# w$ R. q, T4 e B {# c) A% c% q5 \( Y( g2 S# I
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl; `' g8 q, a; ~ e- ]" C/ B
}4 M$ [7 w/ X5 e4 b" Q
: k0 _+ E* k0 e4 J2 c( A
//
" A0 j, _! P9 X: e" I/ v6 K //8 - Setting a new Color on all faces4 q% p, S7 C3 Z/ i
//6 d9 d1 }# L0 z% S0 o" k
9 U, K8 |* d! d3 }; b% u% _/ A
//we are to color the faces with different color according their position : three by three will have the same color5 e" D/ Z+ o# v& J/ _
cout<<"--------------------------"<<endl; L; _, B |* j9 f
cout<<"Setting new colors"<<endl;
j' g0 b- g& P
" p+ w o1 A4 }6 i; { CATListOfInt newRed,newGreen,newBlue,FailedIndex;
* C$ O S8 l) y3 W! x int x=0;4 a2 A2 d8 } [
for (compt = 1;compt<= nbfaces;compt++)
& E$ s, c1 ?( [4 E, Y+ d {
" `9 y3 S' K4 C B# y% r, z x = compt%3;
7 ?0 _8 z/ H/ I) V% N) k( ?: b W) h int red(0),green(0),blue(0);
( n/ Q, U9 T) B0 F( j( q7 F if (1 == x); I k+ h y' M) z; |1 r
red = 255;
+ c/ ~/ D* F) P; } O if (2 == x)( @+ m7 r" I& z) P2 A9 h
green = 255;
( {. C! E9 P/ M$ S$ M* U if (0 == x)( s$ m& M- W- q8 v0 C5 L
blue = 255;2 C) V* n/ v6 `5 O' B
newRed.Append(red);
- a4 O4 F5 T0 }- `& b newGreen.Append(green);' _3 s8 c8 w% W# [( u
newBlue.Append (blue);
& z' `9 a' {: T( ` v8 A) v7 I; M# L cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;2 N8 s$ N1 A x
}
1 w ?2 c+ l) ]# A) h8 {
6 Y& m1 |1 {% T rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
% I$ k1 M9 U: W% a9 `- K* @ if (E_FAIL == rc), [. w* l- p5 ?% b
{
! w' ]' W% F3 v3 y/ Q3 K cout<<"Error, setting new color on faces failed for all faces"<<endl;
! s( t1 p- I2 q return 1;( _+ b5 q5 F- {0 x! k2 S
}; @: |( N; q% }. C: ~" z" ~9 O
else if (S_FALSE == rc )$ |' h" R3 ?+ L u
{5 u; V" `, y3 C' m5 F( v
int nberrors = FailedIndex.Size();
7 g; \) ?: S9 n" m' q/ x cout<<"Error, setting new color on faces fails for faces :";
1 ^& H$ t7 U" Q$ m+ k3 R: n for (compt = 1;compt<= FailedIndex.Size(); compt++)
/ x: V9 q: Q3 {, s {5 P: B! {( X& k: F, _" ^
cout<<" "<<FailedIndex[compt];# E5 ?" {0 @2 T* x
}
. L( d' H+ Q% G+ _ B* w cout<<endl;
8 U* V2 X0 u% I/ e( u7 } }$ W v" m9 w- L0 L6 G" {- c
else
0 j. U3 z- d' k3 ^* Y cout<<"Colors successfully set on every faces"<<endl;
) q/ ^+ ^- Q3 _7 f3 l, K //! Q. i5 I0 [2 \- z
//9 - retrieving colors we have just set
7 L3 ?$ R& _) }0 x /// z# Z4 m6 [* N0 E
cout<<"--------------------------"<<endl;
- p4 w9 Q' y* h cout<<"Retrieving new colors"<<endl;+ G0 R0 O5 x9 P
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);$ B: b n, ]9 T/ H
if (E_FAIL == rc )5 \6 ]( w! s8 Z
{! m' q" i/ o: Y/ H. Y3 k3 g
cout<<"Error, an error occured while retrieving current part colors"<<endl;
4 e+ P0 e: y! O1 X' p return 1;" r, e1 n1 Z3 x3 b2 k4 U) g
}
% [! r& \7 e# Z) x% L1 A) C( p7 D
for (compt =1;compt<=nbfaces;compt++). M: \! H" J3 F# t, t& u: z3 o
{' s5 U* j* i# }( V, R
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;' e# H E2 @9 ^* @/ |1 i
}2 i( z# z4 L. i0 k! w
+ W% |1 ~- o# S% y& E2 u
//$ Y6 \3 ?3 n: n, Q
//10 - Setting Applicative Attributes4 i9 h7 {. ]$ `
//
% a/ J# w! u8 Q- ]5 b7 m b; ^, @8 o; d- a; r
//
4 m! i1 J9 }3 V; @* l/ G7 g //10 - 1 creating new attributes
+ |. P- ]4 F1 T) h. Q7 E cout<<"--------------------------"<<endl;6 u8 K( m& q4 k. }/ T, ?0 ]4 X
cout<<"Creating applicative attributes for different faces"<<endl;
4 }+ _% s8 y9 G9 s CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];4 \7 Q0 K# C# i
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
7 y' e4 s/ K; C1 ] CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();7 n9 L% l( K, R7 w! r
for (compt = 1;compt<= nbfaces;compt++)& r9 Q: k; \6 U" P3 Z
{; X. }$ b& }7 O2 o# }
cout<<"Creating ";7 f8 C# n- v2 @" Z: U
x = compt%3;- Q( F0 _9 m, c, b& b. v1 K! j' w# @
//for each face we create a new list of apllicative attributes$ ?! l9 H* j6 E# m
//an applicative attribute is made of a Name and a value
) Y9 l7 M2 [- \+ |/ J1 F2 q; f8 t if (1 == x)" n2 m8 \% x+ e$ | U, C* k; H
{" H/ Q. o/ q" i& Y
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
$ r q; ]/ H6 O$ D( Y& {2 E( x( m0 l AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
1 _1 w7 e: V7 o( B- e( U* [
# }1 [* R4 s8 I/ o% K* [; f //The first attribute will be the number of the face7 u3 @# K) u& Z
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");. m: g' p/ i" Q& l
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
& R0 i# d" q7 L9 ~$ s' U2 f" S/ b AttrValueListToSet[compt-1]->Append(tempcke1);
' ?- S# b! D3 I( ^( Z! {
+ T7 m" ~1 h4 a5 @& P; R cout<<" FACE_NUMBER with value "<<compt; 8 L `( f5 c& F
; O( @2 k6 Z' w" P/ f: [1 E" T: n! k
//the second will be the color' }# }1 ]5 [) b$ f6 Z+ C0 M L" G+ P
AttrNameListToSet [compt-1]->Append("COLOR");
- e# n m& e0 n8 l CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
& G, o. }2 a5 a AttrValueListToSet[compt-1]->Append(tempcke2);" d' v" ~" p2 i& j3 S
" A1 }1 R9 S% Z2 `7 v4 \8 ? cout<<" COLOR with value Red";* m6 q- m' q' Q" J: @8 H
- k' }, ]* F2 i0 C4 w f2 W* { //the third is x8 }) O% H1 u3 j# |
AttrNameListToSet [compt-1]->Append("X");2 y5 y n% T# S3 H
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
3 c0 T7 `7 l! Z8 d% v; n AttrValueListToSet[compt-1]->Append(tempcke3);
1 |, `% c7 V, G- ^( A6 y : [2 F0 o$ y8 o; g. |
cout<<" X with value "<<x;
: c) c# o* e3 u" o, r cout<<" for face nb "<<compt<<endl;
4 _ l! E* k' q" f: I, }( u! ~ }
/ e5 E- N4 Q* U else 0 u) I" i& y+ t1 Y
//just to show you you can have different size of list5 ~2 S3 m M# i3 d
{3 g9 I& y+ T( t' q
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
; F6 j( W: I; q' A6 t8 G% G5 c+ A AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);0 U+ x8 {& e3 Y" Z2 S5 U
* J( d& G2 |8 n& ?! _; o4 K //The first attribute will be the number of the face* c0 O- J- m. M, m D$ o3 I
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
# O0 P4 O1 M) S) i CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt); \# ^; [: Z1 q* T. l" M( V, A, e
AttrValueListToSet[compt-1]->Append(tempcke1);* w, b/ d% B7 X- R& ?/ g7 E( p
1 {. M4 t5 N2 s- B
cout<<" FACE_NUMBER with value "<<compt;
" x$ s7 |' R2 l$ h
- Y- F3 ?+ ~; m# q- T! W5 O/ V //the second will be the color" `/ Z& R+ U; M7 S0 h
AttrNameListToSet [compt-1]->Append("COLOR");
; s) x. [; q7 }* { q! p4 ~ if (2 == x)
6 q2 {2 O2 m" S2 c9 d ^, I {
9 H/ I) ?2 a, F/ \0 v; } CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
: _$ ~0 d, j2 W) v" W- l AttrValueListToSet[compt-1]->Append(tempcke2);( H, I( p- ]" c6 Y6 X1 b8 z
; n) K3 ?4 }* C! U2 W% p) q( `8 F cout<<" COLOR with value Green";
# b7 Q& X3 a9 U# I }
' I% r8 {1 V4 `# y7 h$ ~# ~) j3 f if (0 == x)9 \9 Q# {8 D+ c2 O. L
{- c: c! w3 @. d- j5 s+ H
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
. V! s3 N2 C* P8 L% L AttrValueListToSet[compt-1]->Append(tempcke2); D: O0 B& w5 u& |1 ~; I) N
7 K5 x7 [; |/ Y6 X: D7 r cout<<" COLOR with value Blue";
0 @5 \" h" \" B ~: D" ] }
# l3 v3 Q; ^4 ` Z9 G; |) l+ J
9 `( m( Z( u5 }# h3 q1 q+ ~8 b4 o cout<<" on face nb "<<compt<<endl;: B" u4 e+ I/ @
* O/ ?/ b7 [( |$ g8 [ }9 \3 A/ y8 E( w' ~+ r( I: T" i
}
/ x5 I: `; j% n: U
) k+ y- k. @! g5 d //10 - 2 Setting the applicative attributes
! p' A1 B9 G# y- W: h cout<<endl<<"Setting applicative attributes on different faces"<<endl;/ q1 o! `4 S, I7 [8 W
FailedIndex.RemoveAll();
& a+ n! I: Z/ z) i8 {! [ rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);1 [5 ?6 I2 x; b4 j8 q4 X
if (E_FAIL == rc)
, `( {4 }7 j7 Y5 h! u0 Y" n) B {
0 K. W) `; f6 \5 a% b cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
( y/ t6 a1 N' w! H7 C }9 M9 Q& i H+ E
else if (S_FALSE == rc)+ V9 \0 H2 Q5 Z3 o) n5 @& h
{1 X, F0 {, {/ A" O9 C. B# r# V9 B
int nberrors = FailedIndex.Size();& w% X# v$ J2 C- o
cout<<"Error, setting applicative attriutes on faces fails for faces :";* \5 K6 g3 w7 C! z+ i2 f
for (compt = 1;compt<= FailedIndex.Size(); compt++)1 e% z) J, `: W7 c [8 R: O
{
3 E+ }2 D$ O. N! q5 \% l cout<<" "<<FailedIndex[compt];
c- S# d+ J- \4 j; \ }9 E5 ]- h' r: L) q( I6 o
cout<<endl;7 p% l9 R7 a# G5 J' u
}7 N5 V( R; ~4 C6 F0 c
else
: V+ Q* [ x% h; | {6 i2 }1 |" w; r' N
cout<<"Applicative attributes successfully set"<<endl;3 J2 F* i% U; ^8 L" ^
}7 I; b5 y" h1 |# ~
8 R- \. {( a! T( e7 J9 ]( G
//10 - 3 cleaning
( r3 G% D1 [$ L6 g P& d- R for (compt=1; compt<=nbfaces;compt++)
% l+ |. Q+ {. F, ^" v: t' e( Y4 H {
" e/ [8 [& X7 p) P" h1 S AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;1 Z3 o6 I8 V/ b% e# Z
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
: W( t) u* N# q7 m, s4 L9 D }
- o! ]# N* S; A. g4 v: x' ^" a6 ^, V+ y9 v2 J% m
delete [] AttrNameListToSet; AttrNameListToSet = NULL;
% V7 T/ t$ D- T+ J: ?7 g3 e delete [] AttrValueListToSet;AttrValueListToSet = NULL;: m. ^# l2 K; e' ]' q3 Z- _
8 y; `4 \. F- i3 |, s
//& s9 w& ~3 V) Q9 o7 k. `0 ?# C: k9 Q1 z# s
//11 - Retrieving the applicative attributes we have just set
( n" B0 i8 k) G7 p! k. q7 [9 n //
) ~- v: e& o* Y) B4 `. S cout<<"--------------------------"<<endl;1 F' @8 m& v6 Z" \& ?% t% |
cout<<"Getting applicative attributes on faces"<<endl;
8 Y9 i' u1 q F# M& K. Q6 C //
5 k! I0 b/ t' S, j* c6 P; O //11 - 1 Getting attributes1 D+ n1 m9 a' k+ C3 p/ K6 h
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
" X$ j+ w l. w, C' ` CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
8 u. g k0 a+ R$ w2 C+ } rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );! [9 i6 l7 s: }: [; @; n
if (SUCCEEDED(rc))
5 M9 P$ F6 Q7 C8 ` {
9 w8 }/ k4 ~8 t% Z! u CATListOfCATUnicodeString templiststring;
5 P- c9 f" t! ~+ A: A CATListValCATBaseUnknown_var tempCke;
9 f; C' m( t2 v) e& \# k5 ^6 R7 Y for (compt=1;compt<=nbfaces;compt++), B3 m9 w2 o0 Z# } G) `! b+ o
{: U) ^% }( W2 r4 H# \/ H8 |& o0 m
//retrieve a list a position k (arrays start at position zero).+ b+ Y, o. ~2 o/ ?4 W
templiststring = (AttributNameList)[compt-1];; ?3 X8 Q9 L$ }' Z
tempCke = (AttrValList)[compt-1];
: b2 d- N; i# [$ G
( X3 ?8 u0 X4 G- X/ n2 v9 h int nbAttributes = templiststring.Size();
, `; I* f8 G$ l5 d2 }6 y# U: N int nbValues = tempCke.Size();5 X& B+ _: G+ ?9 i' A& W
2 D* d( ~1 K( Y0 R/ c+ ~% Z, P //the list must have the same size! If not, we jump to the next face
5 ?+ N+ n$ A7 V% l if (nbAttributes != nbValues); c7 l) \2 Y c. R+ J, y: o
{
0 K4 _, ]1 T& B9 O6 y5 c cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
/ k/ F, T1 \) n0 Y continue;( R$ y# b" V+ W
}( t( V! K( K2 r$ I- u4 A- o1 e
else
4 l9 ^5 L7 j$ f' n, q' G {0 h* u) ^/ z: o9 |7 |/ t
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
8 o9 B M6 Q$ l7 T }
' C L; r2 k: _- {' E) n5 v2 n' y for (int i=1;i<=nbAttributes;i++)
0 e* b8 J) k" ]4 d8 u0 k {9 x% t+ W4 A% n& Y
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
- q, w4 m' \) k) w6 Q! Q+ p9 C/ e8 h }: D' U8 I! F. y6 h) l
templiststring.RemoveAll();- D, z2 A7 P5 D. g6 }
tempCke.RemoveAll();
$ B( ]2 w3 _9 ]2 P# ^+ e. J3 G) ?- b% H/ r' w6 R6 W4 }" A
}
& n/ x5 B! z) _/ n& U: G0 ]* D9 Y) v, I0 z }
6 g$ a% ?/ E' D4 F# k else if (E_FAIL == rc)8 N/ u) Z+ x+ u
{ z4 P% f z# J& x/ A: Q n9 S; y
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;" N; y' Q2 P. i) k' I- n5 S& R
return 1;8 c( x; f( z. r, ]/ y C" P2 H
}
2 C, l; m$ t* { //! m# y# a0 C; N) l1 H# }
//11 - 2 Cleaning List:2 b3 z) [$ R: a9 `% c' ~
int i = 0;; d! ]: k- u& y- V7 g G# E1 ~
for (i=0; i < nbfaces;i++)
( y9 [. v" m" y% z7 q6 @; _4 i* B {4 \: d* o+ g: i2 D* M+ `
AttributNameList.RemoveAll();
1 a5 U1 k9 J4 B. y4 x$ G AttrValList.RemoveAll();
" l1 o* ~9 S0 C! ? `5 t( `0 V& z }
, r7 l& c, ]( n. Q delete [] AttributNameList; AttributNameList = NULL;
7 ] t! n; @6 b' U4 C: z" m. v delete [] AttrValList; AttrValList = NULL;
, q1 C& G- x4 ?9 L: R
% N% u3 ]3 e) R! D' g& k5 [ for (i = 1;i<= nbfaces;i++)4 G1 ~* d4 k1 k4 E0 `6 H: F
{
1 l* q+ o8 d' f& G" K) _1 H Brep = ListBreps ;
; F. n9 Y, Z. _) ? if (NULL != Brep)/ B) m! R6 r9 O
{1 c2 `5 k! W6 A& W+ z" l, V* f( g
Brep->Release();
3 ]) a1 Q: a0 y) [ }
: J+ X1 o6 T1 v- b- A0 ]- F }
7 z5 f, x6 j, _$ X. ~" |1 e2 O; C ListBreps.RemoveAll();[/mw_shl_code]# M1 F0 \- B2 k- y" [3 U1 q2 q1 \* s
|
|