|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
) ~ ^$ k; R* \' e //) H$ t8 B7 @" i
//7 - retrieving and displaying current faces colors
7 A1 k1 \" N) A D4 I8 k+ N //
3 ?6 J+ t. g* |+ K; m. H4 ?( x cout<<"--------------------------"<<endl;
2 ~4 w( U A' {% b. _( a cout<<"Retrieving current colors"<<endl;4 K: n$ X( S) l* }
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;' v. |0 L5 R$ E1 h& G- M& Y# ~8 N
+ _: k* k% v+ F( g rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);0 F' g& F, b9 E: c+ c
if (E_FAIL == rc )0 w# E! x# B4 o6 x) y
{
6 r: P/ [ P9 `! L, J cout<<"Error, an error occured while retrieving current part colors"<<endl;3 }$ i# C1 ~) j4 h$ N- J- h
return 1;4 r! y, J) b5 _4 C% K; T/ Y
}
/ S: r! z* v# }5 h- A, x+ k. M& `) ]1 @% H0 e
for (compt =1;compt<=nbfaces;compt++)/ t3 [7 e: ]4 `
{
7 ~$ Q$ \' K+ [/ `% ?4 \" H0 g% O0 d cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
2 B9 H0 g+ N) O0 |$ t }
Z0 y9 W9 E8 O* Y8 {; E. _
1 n' Y3 `& p) z5 P //
. y j5 Y) r6 ]9 }; { //8 - Setting a new Color on all faces
5 R) n( ~9 E/ [2 q. K8 g //. ~8 t6 t8 M# r2 t @% \" l3 r4 E
1 l/ ~6 y m& U% T: R* v% r& H //we are to color the faces with different color according their position : three by three will have the same color7 L$ O2 x. l c. h
cout<<"--------------------------"<<endl;6 h! x- ]; K/ Y: J9 I7 S2 w
cout<<"Setting new colors"<<endl;/ E6 `2 m7 ] s0 h
+ H M- b7 O* ` CATListOfInt newRed,newGreen,newBlue,FailedIndex;
3 U" `8 {- u& n/ s int x=0;
" m- r/ f( L" e% I0 J3 }8 x2 w. T for (compt = 1;compt<= nbfaces;compt++)
& y9 Z2 q3 G, b5 o9 ~* _9 S {
7 r7 U# s: S4 T6 }! S* _2 I9 V x = compt%3;9 b% m' s# v# n
int red(0),green(0),blue(0);7 x- ~1 V3 Z9 C+ @& W; p
if (1 == x)8 v9 t! c; r" J z% _+ A* v& o, Q
red = 255;, M i9 G! l8 ?$ o% Z2 b
if (2 == x)5 V, g4 [+ M6 x7 t: ?
green = 255;
; W6 @( j- l+ s# r if (0 == x)
2 T3 e6 k/ N6 K0 R8 h$ _ blue = 255;
- G3 @6 o: j8 e, i, h/ a; @ newRed.Append(red);/ p8 n- {& c$ e- [% @; x
newGreen.Append(green);
1 q5 U, C$ U- t. B! D. ] newBlue.Append (blue);7 p$ a0 y* \4 f8 K: F" V
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
+ G7 b. C) ~& y8 } }
& q: n, L0 t2 e7 K3 e1 j! z, x( G- I* u d6 } |
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);$ l3 M3 f( y5 g4 a5 k
if (E_FAIL == rc)' a7 e# k5 ]1 L& R# [2 q# d2 `/ j
{; m# {6 D& q2 @2 z: Y+ |
cout<<"Error, setting new color on faces failed for all faces"<<endl;8 D5 ?- W9 l# v
return 1;
" z5 b$ P& G0 h$ ~( P* o" W2 c }
6 q# s$ Q' Z/ N4 z8 z else if (S_FALSE == rc )( T5 @; F+ |6 z+ i4 y! Z8 T
{
7 Q9 @8 @/ X" I int nberrors = FailedIndex.Size();
% c3 P7 Q6 g6 P1 h cout<<"Error, setting new color on faces fails for faces :";7 {2 l6 X* `8 A5 b; b
for (compt = 1;compt<= FailedIndex.Size(); compt++)
2 k p' d8 e5 @) ~) {/ G {
2 O* x r2 o C4 D7 ]' O: v cout<<" "<<FailedIndex[compt];
* J+ k: o$ X1 D* U& @ }
% S9 b: r. i8 K% u cout<<endl;
, Y0 N" @: c3 y }9 P, G2 Q: ~+ P9 t4 _( }5 z
else
' H0 f8 O, J2 [' [6 h0 z9 t1 E cout<<"Colors successfully set on every faces"<<endl;
N& M3 r) r, z, b$ C6 ~0 q, I //
, E2 O: b* u# m% I( U //9 - retrieving colors we have just set% T; a: j7 s* u2 j) @
//
3 }5 A2 I: j! u g7 C" h$ L, \ cout<<"--------------------------"<<endl;
) l) c6 U7 z- H; Z2 F5 a2 a! P" [ cout<<"Retrieving new colors"<<endl;) I' Z4 G) z+ G* q$ ^# U/ S
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);# r9 D7 t2 S) W7 J% _7 y6 w
if (E_FAIL == rc )
1 M- k! _5 T! s6 X$ o {
& W6 s( `& G! ]4 f cout<<"Error, an error occured while retrieving current part colors"<<endl;
6 P/ s) [% Z* i! t& F/ F4 V& C; E return 1;( O& f' H. `7 \+ B. _5 B
}
# s7 v: T V$ o- x" @) u
( x: ^9 Q$ Y' m& h1 b for (compt =1;compt<=nbfaces;compt++). q& X8 i' S; i4 g. J3 i9 ^
{% e- X; i ?6 X0 n0 Q
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
" d. y5 \" ^9 J# ~, R0 V }
" B% V# y: y' T6 Y- ^
9 k% [' C' x1 Z+ o8 Z+ C //. b( W a' p' g& h5 W" Y% T
//10 - Setting Applicative Attributes H- z& S% N* H0 w
//
z! f! n: V9 E: T5 z3 V+ @4 U4 g! r+ Q8 z6 P, [& q6 U5 O/ K* |
//; t6 a4 H0 C' D
//10 - 1 creating new attributes ( T; L5 ^& J, O& Q/ Q$ \9 n9 n/ A6 v
cout<<"--------------------------"<<endl;
: ^4 {0 ~. y: k E' m2 _0 h cout<<"Creating applicative attributes for different faces"<<endl;( |8 A' R$ G8 o& a1 Q' N; x0 D. h3 S
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
4 j$ \; t }. _3 y! k/ K5 a- S CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
3 R t" _2 @3 H8 l& | CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();7 x# W2 |& i: ?
for (compt = 1;compt<= nbfaces;compt++)9 O* g/ I2 G9 q1 W0 v
{- i2 Z o6 O2 X- p! {* u9 d3 V
cout<<"Creating ";
& I% M- A# W) d3 R x = compt%3;# M8 q* e* R5 F6 t3 K& q
//for each face we create a new list of apllicative attributes: c$ p7 l5 d$ N Q7 n+ \3 r
//an applicative attribute is made of a Name and a value" ~( b: x* W: u" I
if (1 == x)/ C* t7 t2 G# f% {4 t# U N
{' B) m3 O5 O z* s9 W% R
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);1 T7 T Y; a, W% C3 l
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);# K) B) Q7 i% f. C, Y4 h
. J3 j4 _; K. m5 o //The first attribute will be the number of the face
6 i+ h/ E5 d( i/ R/ ` AttrNameListToSet [compt-1]->Append("FACE_NUMBER");% o1 B6 U( N: A( Y6 a4 b$ h
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
/ L- e- x" [! T- H4 r$ v9 Q6 q! Z% L AttrValueListToSet[compt-1]->Append(tempcke1);: M1 U! [2 X& G: o% ~, u! h
( R) f4 { f+ L6 U cout<<" FACE_NUMBER with value "<<compt;
5 q; ^& j/ x' l- f) z) i1 c+ t! U$ K9 q
//the second will be the color
! a1 D; d/ h* D- U- o9 p AttrNameListToSet [compt-1]->Append("COLOR");
# o [- O: J/ g CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
7 `1 i- y5 s7 \8 ` AttrValueListToSet[compt-1]->Append(tempcke2); n0 T) O A# |* J9 Q- A( t+ b
* G% T" x' k M' e# G5 M( W
cout<<" COLOR with value Red";" o4 v/ I! I: J5 w" H7 H# n
. U4 v) K$ f1 p. H& d //the third is x
: d U5 V. N: C" w; M; _* ?# V$ Q5 b AttrNameListToSet [compt-1]->Append("X");
0 n) s% m+ a0 Y2 S; Z CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);. t6 _8 g( C$ c) N
AttrValueListToSet[compt-1]->Append(tempcke3);
. f# S `4 m) w: Z
! \: }9 y, V4 x% {6 u( i8 s cout<<" X with value "<<x;: b8 ^7 X0 ]( ~
cout<<" for face nb "<<compt<<endl;' ^* |! Q& a3 ^ a
}4 O+ L4 {8 J& @# q) w2 L
else & i8 p- G( }9 }) a
//just to show you you can have different size of list# z: B1 A4 X2 ?
{9 m! d7 r5 V+ r8 w* K& o
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);% t! m2 `8 ~3 K
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
) {7 ~4 i3 i3 `( M4 T$ ^( \
9 i+ D' K. } t' [0 r //The first attribute will be the number of the face* b! ]' y9 A( q% B7 i; ~+ S
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");- Q$ x& Q" B$ G# a. F& J% y
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
7 t1 Z# q+ M' X AttrValueListToSet[compt-1]->Append(tempcke1);
( Y1 w; J) ?, B) p7 w8 Q
9 {' ]' Q, D2 e1 {; o6 r4 [ cout<<" FACE_NUMBER with value "<<compt; # T8 |2 W4 u6 R' B6 M2 H1 A
' ~9 P+ I; _( G+ t6 T) I, ^ //the second will be the color
* T. E6 m& U/ m1 d AttrNameListToSet [compt-1]->Append("COLOR");: e% ?# R4 n$ r; v( t0 S/ W
if (2 == x) n+ D1 E: q) d; x; S9 t( m
{
2 J% I. h6 I5 t/ m) _6 F1 R6 G CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
( d2 q8 u. j# N. ? AttrValueListToSet[compt-1]->Append(tempcke2);
/ f1 [! {3 V- j 4 {' U0 T: N: \' G6 V7 D' P! U+ |5 Q Y
cout<<" COLOR with value Green";
8 u5 K; w" _0 q- J8 ] }
! H3 A$ V. m9 f/ I9 |5 ~. Y" K! R; c if (0 == x)
4 E$ S C2 L- R; |, @0 E" |. Z {: N* X% `' r! Y
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");5 r# X4 S+ Q- a$ H& e7 y
AttrValueListToSet[compt-1]->Append(tempcke2);
6 k) I! u/ N7 b. a& c
1 H% p7 q8 {: L cout<<" COLOR with value Blue";
9 c4 B2 u4 q$ X: N P, L }( K. Q9 B4 ? U: ^
( W9 c/ f4 i. B' Q cout<<" on face nb "<<compt<<endl;' K2 W {. P* t0 X8 N
% v$ w$ }+ x8 b }* \3 j7 I$ e- U. d+ i, R
}! V9 |% ]# _1 J( U2 s
$ N. n! _ e& Y: V. @- ? //10 - 2 Setting the applicative attributes* M3 w* q" z) e" f# W
cout<<endl<<"Setting applicative attributes on different faces"<<endl;) J8 A* K [' b9 s
FailedIndex.RemoveAll();
( d& h: @/ U9 U: ` rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);* b1 S/ i t: d: H- ?& B* o( ?
if (E_FAIL == rc)7 }' r8 n, Z' b1 W$ L* y1 ]
{
: B- Y, | \9 {) w3 r3 G cout<<"Error, we failed to set applicative attributes on all faces"<<endl;# v& U F/ y6 X; v& I
}. l- |( v: u% F4 D5 D
else if (S_FALSE == rc)
! R% s" k9 N6 t/ x* D. D {
6 B; m5 t5 q5 ]. x% y7 Y) R int nberrors = FailedIndex.Size();3 f/ @: g' g6 r3 E, j, Y
cout<<"Error, setting applicative attriutes on faces fails for faces :";# N: R; k* k: l
for (compt = 1;compt<= FailedIndex.Size(); compt++)
0 E8 @$ u4 {2 j: `" N& l# B {1 M8 i p! K L
cout<<" "<<FailedIndex[compt];
" {# K- |% [# q9 v+ O }
, P$ n) T: g* ~* V0 [% W cout<<endl;0 K1 z/ n$ }3 N* ]5 ?3 z' _
}
" D3 r: T5 K& I else! A2 J- ?) b, {+ J; e3 P% d
{
: N4 _0 G/ X+ A cout<<"Applicative attributes successfully set"<<endl;5 i: g7 _ w h) D
}
/ V4 h0 `* V$ f0 ]' n
. ?/ @/ C- B* {5 P) x+ U7 U# R; c //10 - 3 cleaning
$ x1 j" _+ G4 V2 {) S% A for (compt=1; compt<=nbfaces;compt++). f; V6 Q/ M3 T- @
{
' P* {7 ?. ?% v |! Q" Z AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
% z6 F1 X1 E( }, W; N AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;2 M# I# R: D" |# f: h
}
) J2 g( H7 P1 X9 ]) B
* t' N: }! _! B6 A delete [] AttrNameListToSet; AttrNameListToSet = NULL;
6 z$ _% b) F, j) n9 T+ A, x delete [] AttrValueListToSet;AttrValueListToSet = NULL;% K } l7 T+ X+ a; r" w
% H, |5 O+ j! W //2 M1 n0 T* x" _2 c
//11 - Retrieving the applicative attributes we have just set
! K5 ?; ?: ]1 s- v //9 ?4 Z% W, ?9 b, h* R- H
cout<<"--------------------------"<<endl;- o8 ~7 }% X3 M# x5 I q0 N6 A
cout<<"Getting applicative attributes on faces"<<endl;
# q2 R6 \, A4 J8 L! e //
' G5 A, k9 s5 t. o //11 - 1 Getting attributes
4 {* O4 F9 W9 h, m CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];$ N# d+ [; e: P- C5 z+ M
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];1 v' X% v3 N* ?0 H
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
+ @8 q2 ^( ?% M& `, u) b if (SUCCEEDED(rc))4 t% ]& e7 M' {% e
{) L7 g2 l% r1 L7 Z" O. i9 z( {
CATListOfCATUnicodeString templiststring;$ Z) S g# L7 k: O
CATListValCATBaseUnknown_var tempCke;8 T) V$ S/ L$ E$ y( R; M& }
for (compt=1;compt<=nbfaces;compt++)
5 r5 Q' }$ ]7 [; j9 {% ]2 I {( p' k5 Z7 t% c1 z9 d
//retrieve a list a position k (arrays start at position zero).
4 H5 U4 L9 o4 R" F% R* _. P templiststring = (AttributNameList)[compt-1];: B# [6 i% W% h
tempCke = (AttrValList)[compt-1];' |7 K0 d: B& f1 _' B
3 R1 I9 U# V; \* E' s( c- d int nbAttributes = templiststring.Size();
- z5 K6 {! j- j, h$ O int nbValues = tempCke.Size();
- w S. ?( C6 A0 o8 \5 X3 e
0 T7 G- ^7 { e# ]; |- P //the list must have the same size! If not, we jump to the next face5 Y" {" J7 d3 }* H" {5 d+ ^; g
if (nbAttributes != nbValues)
- r( l6 {" \' F* p {% i5 s1 {5 L6 n+ g: V
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;1 y" Y: U4 ?, \7 d( Z' W |
continue;
2 R# H+ ^: Q N5 \ }- Q8 E2 ]1 f5 o5 r1 w
else3 m; S0 O$ P( c* R! {
{5 g3 x Y% p- N4 l( h) T/ Z, q
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;" D3 g2 U, ~& Z; I- a* {
}
$ U* [' j, [) u6 Y" p& R for (int i=1;i<=nbAttributes;i++)/ Z# x2 Y# A8 g0 S6 P* G* u+ x7 ~
{3 Z6 K3 z! t# e" S9 S
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;- x2 P* z4 {9 ^- y
}, j& p# e# a8 T9 l0 s
templiststring.RemoveAll();
" O; _$ R( b7 H$ H tempCke.RemoveAll();
" S: T, N, _4 ^; T1 v6 Y1 U% A$ X. b+ c
}
! Q3 V6 b; J9 q% P }2 u, v7 x+ c& [$ a
else if (E_FAIL == rc)* _6 m2 A2 P: ~! [8 }5 R
{
/ P" E2 M9 L9 q/ E cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
: m' \, S* N' v7 m, @) k: ] return 1; ~% ]- {7 R/ E3 K! z
}( z% g: F0 U& `
//
2 F3 ~. v# @- C //11 - 2 Cleaning List:
2 ]% N6 T# w* t; X int i = 0;
' ?& v' T: |2 C+ B5 x3 g for (i=0; i < nbfaces;i++)
! {. f! q) Q! A {
+ N2 X) F ^7 E i) J2 [4 j( O' D" n" G AttributNameList.RemoveAll();. h2 Q$ d1 V/ u+ k1 n% w
AttrValList.RemoveAll();8 Z: G4 L* ]% y5 E5 I/ p" i
}- w/ n2 I0 `& X x) }1 g& k& K
delete [] AttributNameList; AttributNameList = NULL;
1 s! O2 I5 C/ r' W" B3 F5 K delete [] AttrValList; AttrValList = NULL;9 v0 i: `( w: V+ q. P" t! ~# c3 w
* O" @6 V4 b- l2 [+ x/ Y" { for (i = 1;i<= nbfaces;i++)% B: t0 k( Q. K, }- W$ _
{( N1 i3 N* z5 n9 ? R
Brep = ListBreps ;8 x! E! a9 A' Y& X# x
if (NULL != Brep)( l2 ]; i5 o, b k9 }1 \0 Q
{
7 W: L3 u! F+ I' {: `: w, ` Brep->Release();
) B% w0 v# Q& j: l8 B1 d }
' Y9 s) k- E6 P: \9 C } S2 W9 U1 y; Y' K: ^
ListBreps.RemoveAll();[/mw_shl_code]& g& c( b% Q6 Q& l% F( J
|
|