|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]& Z" g/ g' r# C7 V d! A% B; v& f
//
/ d4 C7 K' }, m s //7 - retrieving and displaying current faces colors+ q7 x4 g' i% W2 s9 g
//
7 A% B7 I; h5 s2 I& T& }2 P cout<<"--------------------------"<<endl;
, ~" E- G; c( w# [8 ?7 m cout<<"Retrieving current colors"<<endl;
4 U5 F& q8 m4 Q) N0 o: z x CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
]- D/ ~2 M+ e( ?# \4 ~ ) h3 z1 k4 _& g- G; F2 Y
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
6 Q9 Z$ y3 c+ C# Y7 W$ | if (E_FAIL == rc ): d& c0 g* P k! q" n
{
7 e% n3 r$ p H+ m) J cout<<"Error, an error occured while retrieving current part colors"<<endl;
$ Z0 k5 u4 e# h+ `) b$ q t return 1; Z% s& n& V0 Q" Y' n Z
}" @3 {9 f4 T. y" Q
- u, ]# @. F, m1 F
for (compt =1;compt<=nbfaces;compt++): W6 ]( N, f s! J* w( ^
{. ?: z- R, L' W) N! ~
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
" B' z7 a6 z$ X4 i* c4 E }7 B! P7 C+ R2 b9 a5 J8 @
k6 t" L$ ^$ y //
/ d" B8 [7 K+ [! I2 _) ] //8 - Setting a new Color on all faces9 r; h9 W o/ S: P/ r! O7 `
//
% L8 i; a5 W" p9 p' V
6 d9 M# a8 C9 ?' X( i" t //we are to color the faces with different color according their position : three by three will have the same color
2 |* I4 C/ ^/ ]5 s, G cout<<"--------------------------"<<endl;
( u- t5 I7 P* } cout<<"Setting new colors"<<endl;% y( u' U( S9 _% u# \8 w+ S) q
1 G+ u$ j1 K4 k2 [6 ] CATListOfInt newRed,newGreen,newBlue,FailedIndex;4 f1 p \* @7 c) I0 I( }# C
int x=0;) u5 y) I, G7 y9 O4 e- @
for (compt = 1;compt<= nbfaces;compt++)( b" J: s. H! f/ u1 O" N! d
{
$ w3 `- Z6 e) }( `- z' V1 s5 D t1 v x = compt%3;
3 Q6 V; A5 H$ V i8 L* a. O int red(0),green(0),blue(0);
7 Z/ g/ m7 x2 u6 \ if (1 == x)
E S% }7 V( q6 y$ [2 R5 F red = 255;
6 b \% |1 M8 U5 L0 h1 J/ } if (2 == x)
6 K- F) s8 Y( P green = 255;
3 O( g) c5 ] c% `4 I5 R; ]7 b if (0 == x)0 k# ?6 u8 D: G& T( @2 Y
blue = 255;
# ?: w; D0 U) {- Q newRed.Append(red);
2 |0 Y5 o' k8 _0 F7 x- d, I. u: s newGreen.Append(green);
$ d) M; |6 [, b" ]# ` newBlue.Append (blue);
8 @/ ` i# x9 A& n) F3 s cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
5 k3 o1 A% W# ?- b# V }! e* \+ X5 g" M, J6 }9 |# ~, G
5 y! x6 p5 }6 Y2 Q7 U
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
6 {8 L# n5 ?- h7 z) f3 Q/ B2 C if (E_FAIL == rc), F2 t1 X' R# Q* V/ h7 D1 k- p
{( V1 o9 B v5 V
cout<<"Error, setting new color on faces failed for all faces"<<endl;
! w# K# G3 |+ }# v0 F' V3 r4 v1 | return 1;0 Y3 @. f! ]6 J( v: A! [
}# \3 l5 j1 Z' |3 J& E) D' q
else if (S_FALSE == rc )
) a, y5 _6 f; {( a& Y. u0 z, N# S {
9 A3 v) S8 B3 E* U5 T i5 n int nberrors = FailedIndex.Size();
2 ~4 q2 Q4 x$ c2 \$ @6 X cout<<"Error, setting new color on faces fails for faces :";
! L7 ?" I$ A* E/ c for (compt = 1;compt<= FailedIndex.Size(); compt++)
% J8 t: o$ T5 ~( v$ t1 {. b: Z {
- d/ I0 F0 n- j$ y2 c cout<<" "<<FailedIndex[compt];
6 Z B% D- i8 K9 k }
/ E: a( z, a- {+ t3 z; S cout<<endl;* O( ^" [( j+ } P6 w5 q t7 [
}" m/ H0 }. l8 |2 e1 E: Y+ @
else 1 w+ y2 D6 A, T6 K' g
cout<<"Colors successfully set on every faces"<<endl;
5 ], k, r/ z3 P- @$ W! ] //
0 ~3 @+ P# j' L+ } ]2 o! b //9 - retrieving colors we have just set2 @4 w5 j- z) F6 D% w/ Z& i k# `
//
( u$ l6 M( n- A: [ cout<<"--------------------------"<<endl;) d- _) w# A% {4 {
cout<<"Retrieving new colors"<<endl;
" ~5 s9 w9 f } rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
4 v- u( X# ^ J: e, U if (E_FAIL == rc )
& \2 j7 p5 G( V5 s5 H5 H: E% L( x {( \- h' V7 D, y6 K
cout<<"Error, an error occured while retrieving current part colors"<<endl;
/ _3 X3 b z h, G7 e return 1;
) I+ {9 j2 K: f) v }7 q- _% M: n( M3 h1 ?; b
6 D$ q! _; b& z0 J! n$ \3 j
for (compt =1;compt<=nbfaces;compt++)% K) U. z( M3 O
{
$ b$ K. |- p$ R, p% q cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
: r1 ?+ P% n y& g/ P }
; k9 U% J. c- z4 E4 g S) I! S# k) a+ B9 G4 ~7 g
//
. {; n/ I( t# X8 F+ } //10 - Setting Applicative Attributes
9 v8 r6 m' v! l/ N1 P& Q //
( l; d9 h% i/ L! l
0 D4 A& s: |' p% m5 w. w //
0 A( u4 U8 i; s& n7 w //10 - 1 creating new attributes
2 L# U5 N4 P6 H; `; Z cout<<"--------------------------"<<endl;5 t0 H$ S, J4 W: s
cout<<"Creating applicative attributes for different faces"<<endl;$ F7 u, f, |/ S' l, i" H$ b
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];- M2 O& G E G3 w1 Z3 T6 b) }# K+ ^
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
4 {/ W' ~, M% h V CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();! x5 n0 p# e/ e: v9 Y
for (compt = 1;compt<= nbfaces;compt++)
4 V7 W1 P8 m# Y2 I9 w- X+ I4 H8 i, Z/ R {
* f# d# z' O: q4 T. T1 t* H& R8 V cout<<"Creating ";
: ~* J5 c+ i5 F8 j2 B, B3 r s x = compt%3;5 n' F- Q* t/ M) W9 h3 R7 K
//for each face we create a new list of apllicative attributes
" B9 h) p! b% N0 b //an applicative attribute is made of a Name and a value
' E1 E: Q/ Z/ E) j% t. E. g+ r: o if (1 == x) c4 N% ^& J3 ~& `0 E3 N6 d
{: e; g! N; S, v( D
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);* g/ k0 ~5 T; g7 B7 h0 ?+ J" ~
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
$ R' D9 L4 u' B6 [
" t8 t$ @0 x' t3 G# P5 K5 k //The first attribute will be the number of the face
1 C- g2 ?7 z7 Q9 w( `# p' ?- z' q AttrNameListToSet [compt-1]->Append("FACE_NUMBER");, y3 f8 i$ B( K# L; u9 B( d
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
u+ w0 `2 F, P6 I- T5 a. P2 R8 ?) O AttrValueListToSet[compt-1]->Append(tempcke1);
7 N: g0 m/ S9 N/ b4 [; u
} K* F" t2 h cout<<" FACE_NUMBER with value "<<compt;
' [4 B8 _* S5 |. b* Q( o) d7 V& V7 B, ^ b. e
//the second will be the color! K4 ?! D/ p, k4 ]
AttrNameListToSet [compt-1]->Append("COLOR");
6 E5 \3 O( S7 B0 j- J* ?, d CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");/ r' G# ?9 t4 l! P: D
AttrValueListToSet[compt-1]->Append(tempcke2);% ^. `% S4 R1 \% I
- f; H: ], j3 y0 c$ z
cout<<" COLOR with value Red";
% \ s) n! f1 Y ( E* m5 g( n0 z5 c- Q8 E7 Y0 a
//the third is x
4 ?4 ~: ]. M2 b) s+ ]6 F, y AttrNameListToSet [compt-1]->Append("X");: y- C$ u& j- v0 x- k2 a9 y
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
2 t: ?% N4 b3 g: q AttrValueListToSet[compt-1]->Append(tempcke3);
1 \ Z$ H0 V& Q; b1 g ' v0 i! R0 z# f: T3 [
cout<<" X with value "<<x;
# k a/ t- y) j8 }( \- Y, _- G cout<<" for face nb "<<compt<<endl;
) E! v3 @; X3 C$ v" h }& z! }' h6 L9 H" k+ }* b+ M
else
3 h6 \6 a M9 h5 I9 Z, N //just to show you you can have different size of list+ p$ H- y: H6 j. F' y( }! z
{
' b- A" W$ X! F8 u AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
. P% J! U+ ?+ Z! y$ i( m6 X AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);% [( ~; k" v7 C& w0 ^: k% v- ?' m
9 Z D" n, y! ?; @& O4 e
//The first attribute will be the number of the face
?$ ?3 f( E! k+ w! g; R/ `: s4 n/ } AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
) N2 d8 a' |+ A CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
" g2 \4 d6 ~8 z5 ~, c1 |+ C AttrValueListToSet[compt-1]->Append(tempcke1);
" [5 p% R& P4 [) ? Q \( l3 o, v9 I: S" U! E
cout<<" FACE_NUMBER with value "<<compt; L+ T( s# C3 H: b9 \/ _; E5 d
4 L) v% L" k4 `
//the second will be the color
9 @% _ Y, x1 L/ E' K) r1 J AttrNameListToSet [compt-1]->Append("COLOR");
: \5 O' H* M: U. n if (2 == x)3 T C ]* i# t* H
{# [' b- |. }) V% Q/ e+ \$ P
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
3 b7 [" Z m5 B AttrValueListToSet[compt-1]->Append(tempcke2);
8 x& Q( E" n- \3 ?' ^ / p7 \; d4 R. \. a; v! ]2 @- y
cout<<" COLOR with value Green";
9 E0 ` i# A" f0 d1 h5 I6 q }9 y _ k# \6 A/ O2 B, G) k
if (0 == x)' u# \5 _% Y; M U8 W0 F) n
{, k Q1 {+ y; \- A7 q
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
# w- ]7 ]1 c* V AttrValueListToSet[compt-1]->Append(tempcke2);
! N* c$ G4 }9 F
, R V' P; G9 m1 F+ B% Z3 y6 M. S cout<<" COLOR with value Blue";
4 S7 g$ k3 k0 k- D+ ^ }
. X7 b+ O# |" ~8 x+ N: K& z; P1 V
cout<<" on face nb "<<compt<<endl;7 n4 Z) R1 }- N
/ }7 r+ E# }" m1 }
}
. }- L: u9 y$ R0 w2 T8 j8 { }
( {8 T( g( R7 E3 T: |- e) @4 H' a; p* F6 f9 Z
//10 - 2 Setting the applicative attributes1 Q# H9 M& c* \# k% d q
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
9 |# [0 A, G2 H; i% w. }* [% a FailedIndex.RemoveAll();
: w& V- g" r4 T* E0 e+ e3 m rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);% i) E1 A2 L3 r# H# H1 |
if (E_FAIL == rc)% ?8 K3 b6 T W2 p, P% S
{
6 r/ x& B; @- {3 ]3 A- d* d cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
& S9 N9 ?( W+ q" f }
' o9 u' M+ l8 V U0 G else if (S_FALSE == rc)8 d4 W* x! T' B1 n& j6 V4 N, ^
{
7 C+ F7 _$ ?2 u int nberrors = FailedIndex.Size();1 v: E9 J1 G6 F
cout<<"Error, setting applicative attriutes on faces fails for faces :";! |7 X9 G( a1 ~( ~
for (compt = 1;compt<= FailedIndex.Size(); compt++)
7 G- M+ J' B& Q; G8 d' T {
. y4 ~' I( m u( k cout<<" "<<FailedIndex[compt];$ P1 f: i4 F0 O( m+ h
}
. c+ V5 k$ }7 }: r, K4 W cout<<endl;
0 B; t, E+ R% \" S9 T( c }: m3 s1 Z4 S3 H$ f; f
else
9 M; n% t; a- p0 I! v9 H8 h {! |" \. U, _) V; U5 |0 t& Q
cout<<"Applicative attributes successfully set"<<endl;* ?: s$ G# C. I k" x J
}
2 z1 U. N+ G! K& I" x
2 R+ c& ]/ S [3 z6 M- m" v4 P //10 - 3 cleaning
( ^% p, Z, ]* ^) E4 g- B for (compt=1; compt<=nbfaces;compt++)
, h$ z# `. D4 D, L {8 w+ l. J% A' T+ W- C
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
% l# o2 k" S* X AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
2 L: K' i: d( s; V& G: E }
, d/ v2 ]9 D1 f- j& i2 n" a' r, S. j
delete [] AttrNameListToSet; AttrNameListToSet = NULL;! S \0 [) c2 D- V
delete [] AttrValueListToSet;AttrValueListToSet = NULL;& Z( r. e0 N5 a1 m% O
9 h- @: |2 _- h Q* N) ]9 y6 [ //
4 I4 A! T* Z- g' E //11 - Retrieving the applicative attributes we have just set
* p' A% O, z" {' q // k4 t. l$ B. l/ @* Y
cout<<"--------------------------"<<endl;+ M y6 E, a4 s" s1 o U
cout<<"Getting applicative attributes on faces"<<endl;: a& l$ J$ ~( N" @: A6 x
//
& H7 a' W$ N& M5 c w' q //11 - 1 Getting attributes
, ~- `; J) [1 p( A CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];& ^1 r; M1 q/ {; C
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];6 f# p5 k& Y# S! z- z" i0 N: G
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );% j. j6 ?. Z4 u6 c) H+ ^, \
if (SUCCEEDED(rc))
- D5 O# m$ n- Q% ~9 [! e, _0 n {' k9 R% L" V5 L4 A0 j, k: t' j9 P
CATListOfCATUnicodeString templiststring;
6 j. g" e7 s( Z9 s' P* I9 q CATListValCATBaseUnknown_var tempCke;
" m/ U' W0 W3 T. K& J. }; f for (compt=1;compt<=nbfaces;compt++)
3 v" `/ o) ?4 f1 _2 G2 d {
; z* l# O( q& D: e- O% { //retrieve a list a position k (arrays start at position zero)." K4 s# `# P7 r$ R
templiststring = (AttributNameList)[compt-1];
- n: L1 G2 l7 a0 Z% X tempCke = (AttrValList)[compt-1];
6 J5 B' n6 p( f! N# M( z6 Z) S6 J
- l5 C$ |+ p! X3 k8 v% k int nbAttributes = templiststring.Size();9 N# G/ _ p+ r$ M: x9 [
int nbValues = tempCke.Size();
0 B1 W$ }6 K# S/ _" [& u2 e" a; m B! i( N$ n P
//the list must have the same size! If not, we jump to the next face
6 m J" v6 w: v if (nbAttributes != nbValues)/ F, {3 K" ?3 @
{& Z8 G* c" U) F; S
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
1 ^& F1 | u* w8 l. t0 [/ I continue;
% S9 i) M: Z" _( V8 y8 u }
$ s' l+ `% i: J0 _ else
* ^; O; ?0 m9 |0 S9 f3 O {# ^7 O7 H. A- b
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
6 o* k" [$ X# S }' {4 ]/ N! \# k4 L* T! U
for (int i=1;i<=nbAttributes;i++)6 ?$ s0 o: c3 K p8 u5 A1 Q/ @( T0 w
{4 {: p8 X& N+ z5 W# t
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;, G8 j3 k8 b% o" b
}
; k% G. W, m0 s1 X$ X4 W templiststring.RemoveAll();
8 @6 C8 ?8 F' |, r: i( C" k tempCke.RemoveAll();( C: i$ d7 S3 ]% S1 E3 `6 `
, N. e# M/ W2 i% e6 [ m( g6 S Z }) l% u+ T- H$ \ z6 G$ K+ @
}. @" W4 M3 r/ y$ K& P
else if (E_FAIL == rc)
9 i' \1 h9 s* m) f! X6 J6 ? {
& c2 L" B5 ]) B, ?1 E: s cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
, k" O+ p+ v ^1 p i/ c return 1;( M% R" w0 o3 Q
}
4 F: f2 Y6 @- {2 h3 t' p; } //
; j9 n) }. s& v) x' I //11 - 2 Cleaning List: T7 Z% \) R' y' {( d
int i = 0;
% z1 A. W$ Z" z4 K1 } for (i=0; i < nbfaces;i++)7 z; s5 y7 M @0 P& b+ r" m
{) m* m& G# M& E/ y6 \' } ?
AttributNameList.RemoveAll();7 z" J( {- u" s6 ~5 \& J' r- v5 U
AttrValList.RemoveAll();4 S$ C ^ o) E3 v# a. v
}5 k. j- T& r& {+ \5 j) c* I+ h% n
delete [] AttributNameList; AttributNameList = NULL;
* Z9 E6 v' z* G delete [] AttrValList; AttrValList = NULL;
/ _8 `9 {# i0 O8 L# N5 x% A7 @# N1 D c9 A+ f
for (i = 1;i<= nbfaces;i++)- s/ @3 D& R6 \1 y/ ~* \- s
{
4 u" Q0 L: ?8 ]' S8 n Brep = ListBreps ;* b9 L! i+ D) I+ h2 ^! @
if (NULL != Brep)
. j" }% N3 T( n" y; H( ]; [ {
, L6 N& m; ~0 c1 q0 M Brep->Release();/ f+ {9 B; _+ H, Y8 H1 W7 R, {
}
0 Q6 m; e t0 J$ p }
' E! ~- b# p% }7 N1 y) M$ M! o/ Y ListBreps.RemoveAll();[/mw_shl_code]
4 o4 s9 @& [0 B2 R |
|