|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]# {: |# k- j& @
//
$ v1 F( v1 v) o' M ^4 s //7 - retrieving and displaying current faces colors
1 ]! E2 C. u- [6 C; i1 q8 y //
R2 I2 P ~: z( _- N2 S1 H z cout<<"--------------------------"<<endl;
/ w( J7 v& N5 p$ u* E# ]# } M cout<<"Retrieving current colors"<<endl;: k9 e* s E R0 K$ r
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;, k7 u- Z/ l' }: N
4 B% R2 ^* R7 \0 w
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);% Q; ^- m, W5 x3 a8 {# [
if (E_FAIL == rc )
; b% Z% A6 a0 J& m {
; q8 ?% P* P5 O6 o. S cout<<"Error, an error occured while retrieving current part colors"<<endl;
; P$ g2 H4 `' s R: O return 1;" l; \% Q3 x! n$ C2 I# ^! a" U
}
' {1 a, r" Z% v0 R, c
- ^6 K& C6 q8 X \- O for (compt =1;compt<=nbfaces;compt++)& X5 h* a/ ^+ `6 Y [4 j! l$ Q
{% p; E- K6 B d+ O4 u9 T4 m
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;! a0 y: `4 C& i; L/ O- M/ Q
}
; B- {8 G/ k- n! d, V! B' K" _8 A7 J8 l) K7 J* P" {5 ]
//
# X0 b2 ^( `1 s- c5 H //8 - Setting a new Color on all faces
, C: c+ [' P5 }$ F$ R# y; S3 j //
! @9 v& A. `) j! _! s0 N, C5 j+ v# d# _$ p0 c6 u6 j
//we are to color the faces with different color according their position : three by three will have the same color
" q3 G) u! q7 G u4 Q: [, t cout<<"--------------------------"<<endl;+ _& U: d6 O C1 c+ H
cout<<"Setting new colors"<<endl;
4 \& O# D1 \' c9 i6 x
3 G8 R2 U# w8 v CATListOfInt newRed,newGreen,newBlue,FailedIndex;
& j& c# T5 G# q: W int x=0;
6 e# H$ R: [" s* j6 k( p for (compt = 1;compt<= nbfaces;compt++)$ x9 c- V3 L; k. _& o
{; w9 d( R6 w; |3 J: m* A) B
x = compt%3;7 z. F6 a! v3 r7 W5 x: M
int red(0),green(0),blue(0);
0 t6 }: w) H5 p9 b if (1 == x)& n2 f' X2 ~; [7 P0 P+ k' J
red = 255;
8 I" w& l7 b% d, }+ S* p2 O if (2 == x)- T0 H7 {6 n/ H1 j& o
green = 255;# f. I/ z/ p. j9 T6 }5 k2 h; d6 P
if (0 == x)1 l: n4 i- S0 _4 e
blue = 255;/ m( U* F! _, H/ g3 ?
newRed.Append(red);
; \8 i9 b1 F, w9 h% a3 J newGreen.Append(green);
/ v" \% P# e* s& m newBlue.Append (blue);) ~8 {6 g" }% r. N0 X+ t
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
& ?! @) ^! ^/ q1 A' e" j9 {2 Y9 v }
1 V, x4 W& _; m" l
. V5 c# R9 B$ ~ v9 Q- w rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
- S$ O8 M" G+ {0 ?; J if (E_FAIL == rc)
& n- B# g; j, K7 R5 q7 J {8 R: N$ z! u+ t% r
cout<<"Error, setting new color on faces failed for all faces"<<endl;- p' b6 C2 d) Q( e. ~0 m. c
return 1;' O+ V/ [; p: q8 t" v
}
4 c) C% [3 n* _: b8 B else if (S_FALSE == rc ). j* Q) q. e# `" j @4 \
{ v% C* h! H- {! K
int nberrors = FailedIndex.Size();4 m( e; `1 M& h/ @: g- d
cout<<"Error, setting new color on faces fails for faces :";8 N; e/ a- e6 M d) C
for (compt = 1;compt<= FailedIndex.Size(); compt++)
7 [( H% z) V1 g2 O1 I( w( W {- q. o8 f5 a9 V+ I
cout<<" "<<FailedIndex[compt];
?5 G- S. P, d1 ], e9 i& y }: \) S' ]+ W* L3 `3 ^
cout<<endl;* m7 |4 V: z/ B2 X' P* a
}6 {5 i1 t% F* E9 @4 U8 ?
else . F; G. W* I) f# }) ?+ N2 @% E2 e
cout<<"Colors successfully set on every faces"<<endl;
0 O Q9 O4 O! }( G% e //
5 Y O2 Q q" M7 K$ @9 b' k //9 - retrieving colors we have just set
, ^ v0 C" r9 r0 { //
: I- s C' N2 d6 Z7 T( P9 g, { cout<<"--------------------------"<<endl;; v# j' @$ z" F3 g- x
cout<<"Retrieving new colors"<<endl;9 [4 \+ J3 Z3 d! u& O
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
) ^: p* s$ z8 Y( M! O9 p s if (E_FAIL == rc )9 H8 K" b9 q/ _5 j( |
{
( e' I% g! U' @7 w% R cout<<"Error, an error occured while retrieving current part colors"<<endl;- Q% y, Y, Z1 [: }
return 1;! |4 g2 W+ v4 K5 ?
}
+ P3 ?! }6 F+ {5 T+ _' u E `* F, P% R2 ?- M
for (compt =1;compt<=nbfaces;compt++)
2 Q5 b9 T, R9 p& m% H K" e {- P# a/ u' H% G% j# Q7 e
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
& |+ I3 C6 i& \7 W. M1 W6 B }
$ w/ U% |, K' \
/ q' O6 L' E4 ^; s4 O //) N3 Z5 x6 ^; h/ }, V' s. U+ g- k2 z
//10 - Setting Applicative Attributes
+ E- F9 ]; [% G //
' m- r" y3 k+ `3 Q( x. V9 G/ A" E v: A8 o2 J g
//9 y; v6 T( S$ f1 T" u% l
//10 - 1 creating new attributes
0 `- r, ?6 w+ Y+ S5 ]3 A cout<<"--------------------------"<<endl;. z3 _* f* _# |; j6 i- Q
cout<<"Creating applicative attributes for different faces"<<endl;7 K+ s5 u8 z, d6 } \# Y, w
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
# b* \; H- |1 E8 P$ y CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];1 \0 X8 I% N/ d* Z
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();4 t& b& s t; |) x) ], c# d
for (compt = 1;compt<= nbfaces;compt++)
5 Z% X, @- k& `- J8 W# T& t" M {4 w- q% y$ M2 ?) f8 J$ M
cout<<"Creating ";; F. P% B6 t+ p+ v" J% \8 N+ d/ j+ u& e
x = compt%3;
; s0 k/ ?$ f k0 s% \- o1 s4 C+ j, u //for each face we create a new list of apllicative attributes& @ P# l/ K# G8 V
//an applicative attribute is made of a Name and a value
% b7 K1 A# b. I( W" R' v if (1 == x)) M4 a- h5 J4 ?* T% f
{. Y: L7 B* W/ F
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);. Z8 q6 b" `% C2 A$ ~- f- M
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);7 C. p( K/ j5 Q3 F- C
" n( p T3 b5 b+ M5 K b
//The first attribute will be the number of the face0 a1 A" l' t! ]: P& E
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
A* ?4 l' [! U2 t$ g CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
5 o; a! `4 P9 f! J% A3 U2 W0 Q* Q AttrValueListToSet[compt-1]->Append(tempcke1);6 e# G8 p$ B! S; J2 w) ~
, A" B& j- o) I p' F0 d6 D9 L cout<<" FACE_NUMBER with value "<<compt; ' a3 A5 E$ D8 B0 I# s& d
' L; o' u: A, K# y* Z$ o //the second will be the color
% T7 Y7 S4 K; B- U' { AttrNameListToSet [compt-1]->Append("COLOR");' C v# c) Y7 v3 u4 x4 _8 y+ z
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");% V% Z- j( X: L- _$ k
AttrValueListToSet[compt-1]->Append(tempcke2);1 J0 N2 K- H- [+ |" |$ L6 j2 Y
& g# N8 _8 h2 r% y* R cout<<" COLOR with value Red";+ Z" R. @$ t, T# S
- K$ b1 @. g( _$ }7 ]8 K //the third is x
. x; p# c( C( A& w: b AttrNameListToSet [compt-1]->Append("X");
4 D' [! }# D9 {) T3 _ `. s CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
, I/ }. s& c% Q" I AttrValueListToSet[compt-1]->Append(tempcke3);4 c, ]8 Y2 ~( w4 p0 n$ ~+ f
+ j/ A" t' h3 w* H# D# t6 T" |: T cout<<" X with value "<<x;
6 J6 x& w* ~' f cout<<" for face nb "<<compt<<endl;: i5 C' L2 t& _) U
}& F: f9 S! ~! s+ a
else
" K9 g0 q! U$ L% v2 r2 C. O1 i! V" y //just to show you you can have different size of list' \, D# T9 T+ @: l {% I7 l5 I2 z
{; N! g3 p2 {6 E% B2 p
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
- I5 e% S |3 s AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
# C7 h5 x3 u( W, y: W; h
* r# S1 ~# O/ E+ n& s! L7 F% } //The first attribute will be the number of the face
& j1 h. y4 Z8 `' ~+ g AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
. M! O& M7 ~0 D( H0 k$ K2 g% ^5 _: K CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
3 K. @! r( Y. j2 E0 C AttrValueListToSet[compt-1]->Append(tempcke1);: M9 T' P3 W3 g( @* R' v
. S( V- O2 t& l5 H cout<<" FACE_NUMBER with value "<<compt; ; k5 j5 l! f3 f+ T+ J" c I6 B
$ W0 H! j2 H/ i! K: q: q
//the second will be the color' c/ A3 n& t$ I8 r% G( A4 Y, C
AttrNameListToSet [compt-1]->Append("COLOR");
- c. p: F# l( d- z& X if (2 == x)
, K# z+ O5 |: }% m7 M {, |* j, B, ^! t
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
0 ^! `$ \) L" r0 d0 X$ u AttrValueListToSet[compt-1]->Append(tempcke2);9 ?2 u2 M, |1 x% r n7 ~: x# I
2 P5 s" f& ~3 I, c3 b2 a) D* E cout<<" COLOR with value Green";" t8 ^1 X7 c) Z) e
}7 T" M! y9 }( p8 W
if (0 == x)' a% O: H. {% i0 I9 M
{+ m; o+ U4 b+ |9 o: O
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");0 ?- Y" p4 k j# O7 U, g
AttrValueListToSet[compt-1]->Append(tempcke2);
- P) p* t" K" b3 ?0 O
7 y' W& S7 h- o, b/ e cout<<" COLOR with value Blue";
: f# F( Y* k8 E6 p$ l }% B- y8 \8 Q) L' r1 q- N$ ?: U
/ s: Z- Q" [8 M. J5 {3 V cout<<" on face nb "<<compt<<endl;
' m: E1 p, |! L x E* S' [+ ` t5 b/ k
}' V! P1 z8 q- A
}
% U& k$ I2 z" F f% L8 J& J* g! G
- O# w* {; e5 z# r* @2 M //10 - 2 Setting the applicative attributes/ ]4 r" D% K4 g- D+ S+ U% U
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
9 o9 s) C5 d% s+ T- F FailedIndex.RemoveAll();' D7 k' G# C, W) ^! U! ]! W# {
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
- P& U! B' f. A% t* n# L if (E_FAIL == rc)/ ?0 ?# ~0 u5 m7 {
{
+ V- Q4 W; D$ p4 R cout<<"Error, we failed to set applicative attributes on all faces"<<endl;) F* g4 J) ^0 S( |' a2 w% P
}
2 D1 g1 a" _2 I( ~ else if (S_FALSE == rc)3 s9 |, p; @; M7 j( \8 x
{
9 o4 K4 L2 a% N int nberrors = FailedIndex.Size();
/ o" l. S5 B- @* S cout<<"Error, setting applicative attriutes on faces fails for faces :";
- ?! ^5 U# s' I; j' x# i/ B2 Q( X for (compt = 1;compt<= FailedIndex.Size(); compt++)
4 {% V& Q' Q& @) { {
' o1 t1 s/ T2 ? cout<<" "<<FailedIndex[compt];
% c: c) |6 w: c: G7 Y% |. \ }
) V% X" W3 n6 z* L. o, A cout<<endl;
! F$ V- F2 p: L, y }2 J& {& Z7 E/ c
else
1 m/ v. J' [2 e; H- P {! k: a& b. u1 W- t" O
cout<<"Applicative attributes successfully set"<<endl;
( g6 l0 l, H5 j. O9 H/ q }- s& T0 [3 d) V( Q7 l
2 Q, t' N$ r, Z. I$ O0 Z6 F //10 - 3 cleaning
, W6 O8 R9 ]0 J6 d" r' D0 o0 n7 x for (compt=1; compt<=nbfaces;compt++), j* ^5 y8 G s. c+ ~) f0 O
{- c9 X8 R7 g8 j3 b3 T! ^9 B" H" F9 E
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;' v3 N/ G+ {6 ?, \6 V7 v0 [/ {5 X
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
1 J) F$ v; D2 @ T# v }
- S9 H0 P+ `" W$ x/ j
/ D) x" o8 O- }9 p! F5 @ delete [] AttrNameListToSet; AttrNameListToSet = NULL;) ^. g0 m! k( d# I J/ |
delete [] AttrValueListToSet;AttrValueListToSet = NULL;: d* ?% s6 e: d
" a. R8 J: ? Q
// J" H& l4 G% h
//11 - Retrieving the applicative attributes we have just set
& f8 C) Q) Z: r$ j //. d8 Z: i% v( J
cout<<"--------------------------"<<endl;
+ ^/ O1 f( o8 k- O: U" p) D cout<<"Getting applicative attributes on faces"<<endl;
# ]8 J: w5 P: ?+ O //5 m: c$ \; T% S7 Z
//11 - 1 Getting attributes+ O* Q7 }9 N, s1 f( ^# I& N% z
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];5 X1 I, B$ s$ Y; s; \* d- `% ?* z
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];) u( g- u9 R% p( g) x( @
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
9 _( f& g! U. n1 n7 m0 c: t if (SUCCEEDED(rc))& Q6 O8 W- N4 h4 z
{
6 E2 F" S9 `/ C CATListOfCATUnicodeString templiststring;
4 Z7 o/ A( f) Z CATListValCATBaseUnknown_var tempCke;
% r2 l) `$ D0 }5 J2 v+ L for (compt=1;compt<=nbfaces;compt++)$ d& z1 F1 T1 F% n7 P5 M3 C
{
6 k% h- @. h ^1 V& e' @ //retrieve a list a position k (arrays start at position zero).
; b3 [) G2 j" S. I5 U$ |7 O/ H1 X+ F' V, J templiststring = (AttributNameList)[compt-1];
8 N! M' _3 q4 S/ A! Y4 _/ Y# |6 e. S# T5 T tempCke = (AttrValList)[compt-1];
# R& L" P$ t0 m
( u9 M" }- ?) X int nbAttributes = templiststring.Size();
% J, y! }& a8 g4 A, y int nbValues = tempCke.Size();
0 {9 G; {! G5 O+ a# _+ ]1 m7 d; H$ \
//the list must have the same size! If not, we jump to the next face' I V) |, j ]9 f# n# @* M
if (nbAttributes != nbValues)- @$ h C$ m/ l; f
{" D3 T4 u V6 a8 p
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl; I; _6 Y8 ~, c' w# A6 w( _( K
continue;
% k4 q( y& b; x5 P) p }5 _- q# E1 _: y/ o/ ~0 }3 L: h
else' g# l0 c7 \: K7 R7 \0 b
{( E0 e+ i) U$ P( X4 h& z4 ~$ {* C
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
3 X$ ]- l9 l8 _6 E% ~0 C; K9 s }
! ~6 p3 J9 |# n/ y for (int i=1;i<=nbAttributes;i++)
n8 }, ]. ~3 s& w' W {
6 L+ `1 v& m# w9 `4 W cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
3 a. e, @: q3 I; {. i; r }5 t, V% J. W1 `
templiststring.RemoveAll();& p, p4 x% K. d* ]; C' |, E5 Z
tempCke.RemoveAll();7 c" [! u2 A7 |/ D+ C
( D& _# e: k) _8 `% G }
1 E% d/ M2 q- q }1 l4 y- |) q" y! s
else if (E_FAIL == rc)+ i1 a; }1 D/ A: ~* p" C$ t
{
4 o! p6 v1 Q$ X5 t0 }3 K4 i/ e4 M+ V cout<<"Error, applicative attributes couldn't be retrieved"<<endl;0 r$ d; z p4 m- w( P0 b
return 1;
% U& \0 N. q5 N& j% \ }
2 k, m; l) b1 G4 N) c& V4 l; Z2 ?! I //
x! x1 E: V! j6 r2 o2 A //11 - 2 Cleaning List:- v W! j: j; C; o8 T V( _
int i = 0;) e6 C9 R# l6 z: u+ O8 o
for (i=0; i < nbfaces;i++)6 w1 X$ |2 F1 R; t$ ?
{
8 z/ |- y# F6 h1 o$ |' { AttributNameList.RemoveAll();8 h; @4 f9 U7 t. z! L9 F& e
AttrValList.RemoveAll();$ f# c! r$ u2 o% Y5 R, R0 x
}% N+ q3 z" g$ b, [
delete [] AttributNameList; AttributNameList = NULL;
2 G. `" v7 e9 \# y3 | delete [] AttrValList; AttrValList = NULL;
0 r/ b# O% j6 x0 L+ ^7 K% |" C! A5 O5 O. _' j8 J' V. [; t% n
for (i = 1;i<= nbfaces;i++)8 j2 U% u k( `. d0 W! Q. W
{
* G4 X$ F* n. [0 g Brep = ListBreps ;
4 d+ V: w8 E2 B' D' h( l if (NULL != Brep)
9 l/ R9 O/ ~9 b {. T8 R; p8 S/ T7 Q( X5 T; ]" [# l2 I
Brep->Release();
% W0 h n. Q# G }, |* {$ ?/ T! D% Z
}+ o& Z$ G8 K; [
ListBreps.RemoveAll();[/mw_shl_code]
8 P5 I- C5 W& |6 w8 N |
|