|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]
- r: o6 i! L. A) h //
; A, }! R# J. n* m //7 - retrieving and displaying current faces colors, G6 S8 \, Y& t- `6 ]
//
4 W, H: `3 ~, q1 ^$ d& m) y2 ^ cout<<"--------------------------"<<endl;
9 U9 D0 i0 h$ u! I% q3 o cout<<"Retrieving current colors"<<endl;, o ?+ ^# \7 N: @; M2 U3 T1 D
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
$ R: M6 ^2 r6 h2 N
' g4 c$ t2 E: R$ C' ~ j rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
/ r5 m7 K" W5 Q2 k( ~7 P if (E_FAIL == rc )% _9 K! d0 ]9 r! a
{
: y1 L+ D9 c/ f9 b0 r cout<<"Error, an error occured while retrieving current part colors"<<endl;5 F1 m l* [, D8 A7 O# h
return 1;
- r2 G: P$ _: y. r }
+ e7 o' r8 Q8 X4 ?) _8 s
* L" R9 Q, k& Q. h/ b b for (compt =1;compt<=nbfaces;compt++)
) \& U( _- K5 o% ~5 w. w {
' e6 z0 h' N& j7 I# Z/ }* Y cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
: |# J% s, V! v }
( ?: D% ]! t N: _, C
' H) H( Q4 s- C. [. _- j //6 d& h, ]0 A9 V& D6 a) D. B; S; i; I
//8 - Setting a new Color on all faces
# I" \- i, r% t3 g4 ] //2 O8 Z! l; f( p: J
7 _& I. b f U( L& m+ d" O' k& a //we are to color the faces with different color according their position : three by three will have the same color
& v; Q- w: R/ m9 F cout<<"--------------------------"<<endl;
$ T5 z% E1 p: } cout<<"Setting new colors"<<endl;
" Q) U1 L9 @: e# P ; I) C' Y4 N$ Z+ k/ w
CATListOfInt newRed,newGreen,newBlue,FailedIndex;6 _0 |) {5 r# o8 y( p
int x=0;; Z5 A5 n8 ]& j% Z% J$ o
for (compt = 1;compt<= nbfaces;compt++)2 n) H( v$ B. ~# b0 M% J
{7 }& u t; G- ~, B8 z5 {! n' l
x = compt%3;
" W# h7 I" W, I7 B: a1 g int red(0),green(0),blue(0);& Z8 l( d5 S$ w. O( F& T
if (1 == x)
+ c1 D- l% {- {6 F8 ]* V I) L red = 255;
# f: I, p, @* x0 I2 ? if (2 == x)7 ]2 ~( j' d+ Z
green = 255;
( E5 q! U A1 t5 a" N if (0 == x)
; T( [; {6 M/ B& o# I6 T blue = 255;
3 R3 C- a7 y3 ^" y newRed.Append(red);# E/ T+ q! |. L6 x T# p& i
newGreen.Append(green);# G7 J+ S# {- f& D
newBlue.Append (blue);
1 L" n" t& ?# n5 ~( i6 Z cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
; a( m6 ~9 b/ e* ~ }, I. C" ~/ m% g$ d5 e
( ?* [3 e& k# `; I& A9 A; X
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
3 M7 K; n% G4 `2 \9 B8 s if (E_FAIL == rc)
5 B" H2 Z+ R+ p {+ L& m$ {/ r7 ~6 h: z( E4 S
cout<<"Error, setting new color on faces failed for all faces"<<endl;
! c! f5 q7 Z. p/ A3 ~ return 1;
2 @% F+ e- o) ` }' W8 a; l6 O# l
else if (S_FALSE == rc )
2 g, `, k! m1 y t* j {
1 r5 i# }" b7 e2 l! L- g3 X% Z D int nberrors = FailedIndex.Size();4 {! b: {' z+ l) o
cout<<"Error, setting new color on faces fails for faces :";
% ]: h0 `8 W& H X4 s( g% S for (compt = 1;compt<= FailedIndex.Size(); compt++)9 G. e0 m, z7 ]4 S
{" X3 K! d; h1 N5 ?9 E# m5 C
cout<<" "<<FailedIndex[compt];! l, ^/ q4 h7 x2 O
}
: Y% G, @" x7 E- o cout<<endl;
4 N& K6 \* h7 l% u9 _* |: b }
4 R) }: J) L3 \4 J3 } else 7 W8 W& \. S9 ]0 D$ T4 u9 E, [
cout<<"Colors successfully set on every faces"<<endl;
6 ^6 V; B2 [3 k k //
. m8 i0 C# \9 R6 M- @8 I6 \. m //9 - retrieving colors we have just set
) w6 f$ O& t3 G+ e' q' S1 s0 @+ i //: s% j: @1 a+ v- ^& ?
cout<<"--------------------------"<<endl;
8 P& F, {. o4 u- |8 O cout<<"Retrieving new colors"<<endl;
0 }/ j" z5 u& H4 {3 I; i" a rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);" L- i0 Z! f6 `
if (E_FAIL == rc )! l6 e! O' O( ~9 w0 m, h5 r
{
- G& {' R& Z' I cout<<"Error, an error occured while retrieving current part colors"<<endl;
, R; \: U1 r+ S! i, E3 L( o return 1;
: G/ C% `& u: F0 R8 |. n }
$ k; \: s i1 t; {$ P- G' E$ n' c6 L P# A7 X: U$ A1 t
for (compt =1;compt<=nbfaces;compt++). _& K! M- D) y3 n4 l! ?' o, x6 ?
{* z& ^) b; W- N9 Q8 O* f
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
+ b, |) q3 D8 A9 @+ H# c n }
# r- Q) H/ f5 y" {
( d: }: L7 A! z; C% ~) p //5 o5 S- g# }/ ^. h
//10 - Setting Applicative Attributes5 H2 G+ C9 J* `% ]: H8 E
//
" I, F. o; b# d3 J3 C2 ~" L' d7 D3 }9 M; ~6 h
//
! d0 T4 |9 v& \% y& ^, u, z& h //10 - 1 creating new attributes # n) v1 f6 j+ |8 Q0 `
cout<<"--------------------------"<<endl;
* r. Q" g- W- j U. y V$ U& C) x cout<<"Creating applicative attributes for different faces"<<endl;! X+ `: ~: R P! ]' ^
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];5 e7 P* i9 O+ D2 }. N/ Q
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
/ \/ Y, A8 k: U- X% I. K CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();
6 Y5 i% a; y9 R( C' Q7 @- l: i) S for (compt = 1;compt<= nbfaces;compt++) j( P& F3 ]- |; X/ Y
{ @8 h; R, k6 o9 w, Z
cout<<"Creating ";4 }/ T* Q I/ A$ ]
x = compt%3;
( d: G) ^3 x# {* q$ I& Q //for each face we create a new list of apllicative attributes
. Y, J t. K; x# B m //an applicative attribute is made of a Name and a value
b8 }# x. F4 p4 {, H5 v if (1 == x)
3 `' r* d8 E* e v7 h! H {
4 X8 ~ r% l4 `1 l AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);0 `# i2 `7 X* p# S4 M) c
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);" W$ L' }$ ^8 v2 U9 x& N
0 v# L& x3 r: m( h. Q
//The first attribute will be the number of the face
+ s7 h* s1 G3 T% I AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
( w- D/ W* E3 Q" p: V6 y CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
) B) F- R! P( r0 u+ r8 r AttrValueListToSet[compt-1]->Append(tempcke1);. X! ^0 O5 l& J
% a3 Q* e6 V8 I" Q u cout<<" FACE_NUMBER with value "<<compt; 8 {& `# x, p) O/ I+ `0 M+ V! \/ `
9 Z. r% Q, K$ c
//the second will be the color' I- {5 ]7 p$ i+ t: z* |/ F7 e# D
AttrNameListToSet [compt-1]->Append("COLOR");
9 B3 p7 ?+ ^7 R9 i' [# P CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");- L, n6 B3 c& N3 J1 r W4 Y$ p
AttrValueListToSet[compt-1]->Append(tempcke2);, `$ n0 U/ s# v* f
: z6 ? f# k9 Z5 X6 c9 A cout<<" COLOR with value Red";
: s1 W3 ]9 K1 R6 ~
* J: [% Y5 |( O! r: p3 `) } //the third is x
$ g/ ]+ w7 P- ? I) W0 m AttrNameListToSet [compt-1]->Append("X");
, P' n- [7 \2 V5 M s CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
7 B1 O) g# C7 Q5 M9 u AttrValueListToSet[compt-1]->Append(tempcke3);- z( S! n1 S8 q$ ~. t
5 r: i( S- {* m1 b: f% [, {
cout<<" X with value "<<x;
2 S8 Q9 K+ [9 z* t0 B cout<<" for face nb "<<compt<<endl;
. y; Y4 ~* \$ {6 D8 j3 y }
$ ]$ e( K5 r3 e9 W# s; ~: f else - j: y6 n {8 S+ ~$ C6 h$ z
//just to show you you can have different size of list
0 x- \: j6 T5 m+ J5 v {* x0 s5 T/ D1 `& S2 r( k: a
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
& y0 n( u+ A) J- b$ _( _; ?4 t AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2); e5 ^5 V' ? Z) r, }# ]
1 e* n a, k2 C2 U& o //The first attribute will be the number of the face
B+ q7 o; h- G AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
5 L- g h( D/ W4 {! y1 b CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);5 \9 q* P; P8 r! J: i+ t
AttrValueListToSet[compt-1]->Append(tempcke1);
& c7 [, g8 \- s& B- v6 p; e I& N
cout<<" FACE_NUMBER with value "<<compt; 7 W. a+ `: l3 ]( P) K% {
) S M7 m/ O+ z! A2 M9 m% { //the second will be the color4 N; x3 x: Y; U" B
AttrNameListToSet [compt-1]->Append("COLOR");3 V1 x& q# W! O5 f! h/ T9 u
if (2 == x)5 q3 d! M3 c6 D" N4 G) Y+ N' u
{
3 j; G" ]# C0 F3 g1 } CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");9 t" l, A; J! \# O# }) J
AttrValueListToSet[compt-1]->Append(tempcke2);. e' P; @1 _2 B! k
/ w# @4 f& z* {- b
cout<<" COLOR with value Green";
, P! `( ]0 \3 d3 E$ D' X2 h }3 u7 Y X2 v' [0 @
if (0 == x)4 K- O& z6 I4 {+ E9 h2 h1 O$ U
{
. M6 d8 e7 g# V r' w6 L- E0 u& f CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");7 C' [) H1 F3 }
AttrValueListToSet[compt-1]->Append(tempcke2);
: l8 I# _ p# ]- U: u 6 V5 p- x! t0 a- l: R
cout<<" COLOR with value Blue";
1 \' n+ O* ^: P) n1 i }
( Q! p' E/ H: K7 X+ B3 x6 ]" Z4 e; {; V: n1 k! s
cout<<" on face nb "<<compt<<endl;
: m% z0 r, q' p q! o: @
, ^. i! [, ?. g* d" D }
) N1 ~6 i, J" |( D }" N$ d. S, t; h: V3 b) J
5 o' a% Z% z$ f! M/ y1 E$ ^
//10 - 2 Setting the applicative attributes
. x8 H2 |, p9 }2 n cout<<endl<<"Setting applicative attributes on different faces"<<endl;
' y1 z( M/ R3 P9 H( Z( H FailedIndex.RemoveAll();- ]7 }2 x" B& c3 B9 d# T# J g
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
1 ~% c& b- K* W& n6 [ `# q if (E_FAIL == rc), W& d+ S, f2 w2 {! e c0 o! F0 }
{3 [5 _! o Q- P
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;% V: w7 y/ T, ~' m* L7 n* {) n
}
/ V3 Z1 Q- H+ E( b* U. v" w8 Q else if (S_FALSE == rc)! Z3 g2 V6 n& Q! h# k
{
) y( {% W/ B# T# f8 c: L2 D int nberrors = FailedIndex.Size();
& _8 a; \+ H" B$ F8 ^5 @6 w cout<<"Error, setting applicative attriutes on faces fails for faces :";
/ ~0 H9 U9 {0 ]. ` for (compt = 1;compt<= FailedIndex.Size(); compt++): i8 U) ] o; S( I5 O. f, d
{2 S% }% Y0 G+ i+ J6 i
cout<<" "<<FailedIndex[compt];. P4 V9 {: w8 t
}( T& F7 f- {7 h" t
cout<<endl;2 K2 J& K9 M" F4 w) l& B# j
}
8 n! _& A! S% F. `$ I else( |. ~2 I8 |! E4 C, l6 O
{
. H: V3 K q' L1 b5 P% S cout<<"Applicative attributes successfully set"<<endl;2 d6 i- c) G, o, |: h
}
1 C: R# E' _% h, |& ]3 [( n: p7 Z2 k# s" ~# t
//10 - 3 cleaning7 O, { r; ?% H, O1 o6 j8 }- N* W
for (compt=1; compt<=nbfaces;compt++)
% {7 ]5 J( a! U4 m8 c5 {$ k {0 d( ?& `" }& E& S4 t- Y% ]
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
* y( J2 {$ O4 i: }: l AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;0 y4 N/ J/ L- T, f. X/ g& |' U
}
7 P7 d1 X, b$ w2 R2 ]! i! c0 l: l/ V: V5 ]# n% Q
delete [] AttrNameListToSet; AttrNameListToSet = NULL;* E( l# p# a9 \8 s( _
delete [] AttrValueListToSet;AttrValueListToSet = NULL;1 |! T( C0 @+ S$ \$ G4 z' j' x7 p' _- G
' b( J C4 u1 U7 C. u) a7 p //
6 ]# t' I' Z* R( }$ R& L //11 - Retrieving the applicative attributes we have just set
/ V! @4 K/ n L3 r! ] //
1 c$ m% n3 N) X0 p" H1 C0 b cout<<"--------------------------"<<endl;# l: W) ?, D9 s0 y4 J) p3 M0 `. R
cout<<"Getting applicative attributes on faces"<<endl;1 A" `' O% i+ U8 d) G% Y+ j
//
+ M; U! r* Z: z) k. T/ a //11 - 1 Getting attributes
. d& o0 ^4 e$ ]3 m$ z# w CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
1 ] ^! O( p: c4 L8 K4 x CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];$ T' Q; V/ D, J7 u) @# Q
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );2 x" I' L9 `: z$ ]) _
if (SUCCEEDED(rc))
7 v. i) ~6 T! P! z0 F; ] {3 @) ?, V& s4 O; y: @
CATListOfCATUnicodeString templiststring;+ J# h; a% \- o- ~4 e
CATListValCATBaseUnknown_var tempCke;
" Y2 E. h% N/ T( F% t1 N$ R2 {2 x for (compt=1;compt<=nbfaces;compt++)% {* H. T ~% M5 K- d2 M" b
{
4 j- |# E$ l( K# P4 S //retrieve a list a position k (arrays start at position zero).; P- ?& \" x% b9 `
templiststring = (AttributNameList)[compt-1];
' T$ Z t9 m4 \6 C& _& p" y tempCke = (AttrValList)[compt-1];- q$ ], _4 Z: @
1 H G, G, E, ` T; C( m7 o
int nbAttributes = templiststring.Size();
( g. J/ G) v" y6 }' K& x: a5 @ int nbValues = tempCke.Size();
( k9 u, o# l7 X' N
: G3 H2 T+ S% E- @7 ?4 p //the list must have the same size! If not, we jump to the next face
. T9 r0 \2 N$ Y. _) L- w) \ if (nbAttributes != nbValues)& J# z' @% f V: S6 o
{
3 ~7 Z8 [4 `& B cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
8 S) E/ r" e/ h continue;' A$ h9 R7 p- A. E
}5 }" t: g8 `( M Q
else, u' t) I) Q7 ]8 y1 }7 j% ?6 ?# L
{
8 e- ~' x1 u4 `3 \0 K2 m cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
3 z7 z6 ~- |5 h- v. l+ U+ F" K3 n. S }0 u+ }9 n- k7 S7 ~7 D
for (int i=1;i<=nbAttributes;i++)
' J+ G/ K/ s( i9 G {
4 }1 Z4 U: ~( n* n: V6 d5 ^; {, v8 ?% B cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;% ]& u% x7 v" c* N
}- `; @- @4 {" ]) K+ b/ y" H
templiststring.RemoveAll();% Q* m; d# t( Q7 d" o! M! G$ E
tempCke.RemoveAll();
( W8 D7 |" X" \, I, C X4 i
* C/ R6 H+ R4 G+ O }
& J5 k- F) A0 G" M }( l1 t# `- t3 a+ U4 T7 `( m
else if (E_FAIL == rc)
$ M! v0 K3 U( M M5 B; k1 |3 O {
4 x& B1 {% C. \6 N5 y cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
* A( k9 _% l& R6 d* P4 m; u return 1;* o1 s- i5 J p) R! T
}2 I7 }& @# ^5 ^! G) ~
//
0 Z. Q6 y0 t/ K! \6 z //11 - 2 Cleaning List:9 Q. L! g# ^/ R9 S* ~- [& A
int i = 0;: Q1 ^8 R! n1 [. a8 [( m
for (i=0; i < nbfaces;i++)0 `; q% _+ q ^( ]$ \4 o
{' F% }# _ J% L. Z/ g* e i. O
AttributNameList.RemoveAll();
, s! K. R$ L1 F* ]6 Z' `/ }6 w AttrValList.RemoveAll();
+ b& P4 J% A- C( q7 w4 u; z }, R3 ]+ K5 F3 v
delete [] AttributNameList; AttributNameList = NULL;
n* ~- a5 @' w# Y- O* @ delete [] AttrValList; AttrValList = NULL;% h' `% C2 V9 ^
- ]( ~7 K7 b4 m1 C' X- W
for (i = 1;i<= nbfaces;i++) p. f, n p2 z; w: c9 I4 w) ]
{
" D! X0 X; z' ? Brep = ListBreps ;# I" H; E: q& A; [: a7 b
if (NULL != Brep)" [/ N' Q# A, p7 ?
{3 l$ g3 k. K7 K3 `) ?2 V
Brep->Release();6 H! l6 q+ Z+ [# n; ^5 _
}
; R( A5 W& Q$ r# i9 Q8 J% c }
1 h% A3 F$ H. O' H ListBreps.RemoveAll();[/mw_shl_code]
) g$ ~/ B Y% g. W1 o, Y' C |
|