|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]. B+ Y) e+ _ I& C: V& \
//9 l- S6 {/ e& b1 f4 y, \' F6 u
//7 - retrieving and displaying current faces colors K# y% A/ @. ~- [4 L9 ~
//( j/ Y# S0 _8 p5 ]! f# k6 s
cout<<"--------------------------"<<endl; g% h0 T! z1 J4 _1 y3 X" |/ U8 S
cout<<"Retrieving current colors"<<endl;4 q0 Z0 r1 v2 ^' J" g$ n
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
( R& k/ A- l- C1 L7 V& `+ f, R * ~/ @; ?4 N9 t* G2 N
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
. }: [2 T$ r; }0 f if (E_FAIL == rc )8 M4 d0 C& Q0 i. O
{9 a0 k6 X1 u9 n
cout<<"Error, an error occured while retrieving current part colors"<<endl;
) j/ |5 d. u( o& z$ F return 1;1 b3 s2 v( H r9 A9 v
}
( {) a% K( i1 R7 ?
+ a: }3 ]% k! v; ^& p7 ^8 u" b" E8 m for (compt =1;compt<=nbfaces;compt++)
" l8 m' G6 Z1 I( t: { {
& k8 h8 w C& U1 ? cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;0 t1 g2 s* ]! S! W: K" \
}0 L# Y* [1 ~) c
, Q8 Y. Z' H; i
//
7 v G% S' l4 E* s //8 - Setting a new Color on all faces
. @9 m9 R) J9 R //) T: ?3 R7 `+ V6 q( V/ Y1 P4 g) m
5 B( j) p4 T( F" K d8 ]
//we are to color the faces with different color according their position : three by three will have the same color
+ ^& G) h. s# i6 u cout<<"--------------------------"<<endl;- i* _7 o. n& r1 _: r4 {7 ]% B! p
cout<<"Setting new colors"<<endl;
! b, q% D% |: k: L
. K, p9 |: z( E CATListOfInt newRed,newGreen,newBlue,FailedIndex; M- ~8 X3 s# k+ p7 y
int x=0;: \8 d k5 u+ {% @4 ^/ n. ]
for (compt = 1;compt<= nbfaces;compt++)
9 e& N' t0 W1 l- N {: ]; x$ C* z, M+ |0 f/ M" n8 n
x = compt%3;- Y# x, b' w; x
int red(0),green(0),blue(0);
+ |) A6 l' _( ^) ~ if (1 == x)+ B& m- V2 R" M* K, N& }8 F
red = 255;
5 u) h$ c# p- P s if (2 == x)4 ^1 S% P8 w/ h6 q1 o
green = 255;
: E0 G/ | I t if (0 == x)6 `( r5 m% q$ I; M
blue = 255;2 k. a0 O& ?5 f4 k3 n: z5 v7 F
newRed.Append(red);
" c; ^) l% r' K" l8 F! f/ C newGreen.Append(green);) d* ] W/ N: U0 d# o
newBlue.Append (blue);
9 I( j9 F9 c5 } cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;. H& q/ h1 D$ O4 L
}( h. _3 U! d: M
* g/ B+ Z3 w* ?( C rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);
' j3 c3 T U$ X* d if (E_FAIL == rc)1 P7 h$ k/ d6 B$ }, k
{
, Y3 F0 D/ v4 s cout<<"Error, setting new color on faces failed for all faces"<<endl;
" s4 ]* g5 _; t% v return 1;
8 w+ V6 c! \+ N! i7 O* D0 e }+ _& J( P- Q- Y$ p/ p7 X& i
else if (S_FALSE == rc )& I: P8 }/ k& l9 Q5 Z! l5 U5 I
{
0 s8 d; t) r6 R9 n, F- Q1 I* V0 M5 H8 I int nberrors = FailedIndex.Size();- w! S h& Q$ J. V7 M1 s. F
cout<<"Error, setting new color on faces fails for faces :";
# ]/ F$ y6 T: @ for (compt = 1;compt<= FailedIndex.Size(); compt++)( X3 f5 b" m4 A, w5 b" J
{
# V% }7 N/ A, e" _8 |* Z8 I cout<<" "<<FailedIndex[compt];" `/ B, n( Q) @7 \# D* W0 ~* p0 n
}4 w- J! T( x- ?" n
cout<<endl;8 L2 D; @" Q# i/ ^# X( `
}
( f9 d4 @& J7 d5 x, k1 ~: Y D else ) q. b$ j1 e+ N( G- `6 {9 d
cout<<"Colors successfully set on every faces"<<endl;
' s% ^, j; z7 d1 j //
* c t( D4 U+ U; I. i3 c //9 - retrieving colors we have just set- y4 N4 M8 w9 x" v
//: @! A( D; ~0 K0 i
cout<<"--------------------------"<<endl;% Z8 [/ H8 m6 ?3 H, K7 U n" N% K
cout<<"Retrieving new colors"<<endl;
5 K4 B* n# @* X/ T rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);2 u# l- O0 \- o8 Y) g
if (E_FAIL == rc )5 o9 B! B0 E& |
{" H$ E( U+ y S0 y+ i; n
cout<<"Error, an error occured while retrieving current part colors"<<endl;6 t+ M" N4 g4 G9 V/ U5 C9 A) f
return 1;, B. M( _0 z+ [& v. [ `3 w
}
" D! }0 Q9 t& q# e1 i6 p4 R/ P4 ^" J5 Z l( Z `0 h- }9 s9 G
for (compt =1;compt<=nbfaces;compt++)
' J$ M/ N6 l: A8 J" p ? {
; E& j4 L% o8 u cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;! b* }2 K. x% i. S
}$ _0 a2 d) Q/ ?- f4 a/ x9 N& }
* a) F/ Y0 k$ s3 _+ j //
6 ~3 n5 {# x, D* _! r3 ?& t //10 - Setting Applicative Attributes2 \* J5 j0 P u o$ X- e$ G
//* @9 B' m3 `; H- K6 ~
4 \/ X U- W1 u: i- A* t
//
: c9 q# p* _9 O' G //10 - 1 creating new attributes
$ ?+ ^6 R1 n" l2 w9 s4 h- ` cout<<"--------------------------"<<endl;
9 M7 \0 U) x# k cout<<"Creating applicative attributes for different faces"<<endl;" ], Z L- `& ~4 m; @5 P! t
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
* \7 {; V( v' }- W CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
. x& Q3 t) f# t* V Z" U! Q/ P CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();9 n/ A! p! ~: T# C9 [6 u& e3 i
for (compt = 1;compt<= nbfaces;compt++)
5 |# ]% j0 V ?2 T/ K: J) x {
; T3 H7 q1 m" v+ f8 {4 ]- B0 Z cout<<"Creating ";. M" B( `5 _. R1 u$ w- e9 t
x = compt%3;
. L, g% ?0 q) K" ]. [ //for each face we create a new list of apllicative attributes1 b0 S7 T* [2 f4 n0 ^9 Z! z
//an applicative attribute is made of a Name and a value* z8 t$ b( K8 f- n
if (1 == x)
. ?/ u4 @0 D0 ? {
6 f; |! E: r8 s2 b" E# O; n3 s AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);2 F3 A0 z2 N# L9 Z L" h( |' W8 H! }
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
% E( S# x& d2 e% r r: c
( T3 F, u8 {+ V# J# { //The first attribute will be the number of the face
$ R6 |) i0 [7 s# P AttrNameListToSet [compt-1]->Append("FACE_NUMBER");* ~' S& S# Q: p4 ]5 C
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);0 I3 H( u6 A9 x# k& @. d- _$ x
AttrValueListToSet[compt-1]->Append(tempcke1);3 N" D; O3 x$ u v1 v+ c
8 N+ r+ C- g* a! J
cout<<" FACE_NUMBER with value "<<compt;
9 c0 M, k2 W9 J" ? Y' I" m( Y- M' F0 ^8 i
//the second will be the color
' M4 T3 K" P' u" n/ j AttrNameListToSet [compt-1]->Append("COLOR");/ [& }+ @, `4 R* A& k8 Q/ a+ m/ }
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");( b1 Q( k1 D5 e, v! O
AttrValueListToSet[compt-1]->Append(tempcke2);
# S# U+ r4 I+ Z; Y. W% b ) e" ~1 @9 x0 i; L! M7 i
cout<<" COLOR with value Red";" l# n9 I3 c% d
; O& ^% W7 I, V. Y; T //the third is x
$ k# ^6 C# c B* v1 h AttrNameListToSet [compt-1]->Append("X");& l6 g8 v6 q* R
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);$ z2 L- F9 v& X
AttrValueListToSet[compt-1]->Append(tempcke3);: d! [0 z9 X0 E/ D: L* E' a
( ?$ Z' K8 W' X* `
cout<<" X with value "<<x;
" {+ _, ?, O* N7 B0 A8 Q cout<<" for face nb "<<compt<<endl;% H* j. d' j* y9 T- P
}( l! Y* E; X9 g, N
else $ r' ]0 v+ D$ V
//just to show you you can have different size of list( J, y8 }! }- G& E
{9 C# z3 r7 V9 b( i; B
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
$ p1 i. A4 V& _: D AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);7 R* f, v. j5 I- g
$ p, g' C9 Q. Y# F9 G* Y- Z //The first attribute will be the number of the face& s: l% W$ Y6 P2 R5 N1 J) [ U% y
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");; y3 S$ X6 V4 ?1 P! I
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
' ]5 Z. ~" L- v4 y x' X8 e AttrValueListToSet[compt-1]->Append(tempcke1);1 S* k3 w' ~/ V8 |5 z
1 T" @9 @( |$ L' T, K% M cout<<" FACE_NUMBER with value "<<compt; & H3 S V, x8 l5 ~, J# U" Z8 d+ d5 ]
' d0 `1 ]" _, c( d
//the second will be the color1 F+ g; U) u8 K5 n, h' b% O7 i
AttrNameListToSet [compt-1]->Append("COLOR");% S' P5 }! M3 x) k
if (2 == x)2 z# s0 w8 F6 G
{" T* S4 r. ^" ?) S# T
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
: j, V8 G m$ o# n4 m6 [# m S AttrValueListToSet[compt-1]->Append(tempcke2);
& l9 X( W" ^5 o. {0 e
- g% E1 [$ {) X1 }. P! p cout<<" COLOR with value Green";
! F' d2 x- o' d% U. i }
1 O" x; M$ {- X3 E( g- W; n if (0 == x) p X5 ^! ]2 k4 w* g3 Q: W R
{& l7 e4 B( W8 T0 I
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
. q4 h( B! a( w+ }+ s* U( P( i1 f AttrValueListToSet[compt-1]->Append(tempcke2);
) u. f+ }9 K! _! G q# I4 x! |
6 O7 e8 @1 z- Y3 N cout<<" COLOR with value Blue";
+ \6 R6 ?; Z2 j( U. f% a- @0 B }, V' i: C$ ?# f4 l# L$ x i
7 u0 a, U. K* N% J- G/ D* m) I
cout<<" on face nb "<<compt<<endl;; R& P; M. e6 n7 D9 R$ K3 e
* E. g3 F3 @7 h( M' v
}
y0 w4 L: p4 j' e) [ }1 q/ \, b8 i9 ^. E' Q3 H
1 Y& y# a" g, [3 k1 `$ T4 ? s& R
//10 - 2 Setting the applicative attributes
7 X# B& P5 w2 ^, p9 E7 j* J# p) c cout<<endl<<"Setting applicative attributes on different faces"<<endl;
5 J& ~( ]+ C* G( Y( `8 k7 g& _ FailedIndex.RemoveAll();
' l a* u: i9 B N( W& n rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);" O9 N0 O5 K _# V" e- E0 @! S, s
if (E_FAIL == rc)
4 p' G1 j+ N9 [7 @/ h! o e! Q {: R2 C% Q" @* i5 E9 ~! h2 w
cout<<"Error, we failed to set applicative attributes on all faces"<<endl;7 W. F4 q% g: y/ K3 ?2 |
}
$ V5 M j# a+ C else if (S_FALSE == rc)0 Q2 [% @ W% M- `" Q5 ~1 H
{
+ ~( N/ x; Q$ X+ N int nberrors = FailedIndex.Size();
/ l% M2 ~& {2 y2 Z cout<<"Error, setting applicative attriutes on faces fails for faces :";
! J5 m3 m k t" Y5 K7 p for (compt = 1;compt<= FailedIndex.Size(); compt++)
]1 {4 C2 Z% w$ F9 U {3 I$ I' A& C, s1 a
cout<<" "<<FailedIndex[compt];: ~+ o5 {4 _ Q
}0 k9 K/ P: V5 @6 j5 c
cout<<endl;
6 R8 X, p( L5 ~4 p3 s1 `4 h }
& W1 O" A2 l' j8 n; L; |. q else6 \- a& Y8 R4 |2 H+ |
{
8 v b: T& Z# T6 L8 p, C cout<<"Applicative attributes successfully set"<<endl;
% Q" h1 t% ~3 D }5 U m" L% ]* a' `4 `5 c
0 ~) K# w& A _7 N7 q //10 - 3 cleaning
1 A0 u$ |6 t4 d' s" M for (compt=1; compt<=nbfaces;compt++); b) c- U2 K) _4 |2 m/ L
{7 B" b- W3 l2 y
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;9 B# k" R% i$ s: E0 u" b
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
+ f! h+ [ ?! A w7 P; X }
) o' \4 k4 E1 |: m; v* i _8 J1 w6 ~5 ^/ ?6 J4 R# A. x
delete [] AttrNameListToSet; AttrNameListToSet = NULL;
, f/ l. m. G; t delete [] AttrValueListToSet;AttrValueListToSet = NULL;6 r* r' \5 _. z# A& ]/ H
& ^6 ^: |( Q7 N( W) h% D //6 Q2 F# G2 N3 ]+ T5 g
//11 - Retrieving the applicative attributes we have just set5 `; A2 \) n4 U" v, V; o
//4 K- j% A5 O, S9 Q' \5 i1 G
cout<<"--------------------------"<<endl;
/ T/ y$ g# Y% T cout<<"Getting applicative attributes on faces"<<endl;
; G: {: F) j, I; q( v //7 U( d0 N/ _0 O; T6 M
//11 - 1 Getting attributes9 @, l+ A- K( X0 Z7 M7 u9 W& F
CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];# k- b$ \0 z$ [- P& W6 m
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
0 a! x" O% v' n6 Q6 l rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );$ s; x7 S8 w, W% i' H! D
if (SUCCEEDED(rc))# i/ {) g B/ H1 H3 s1 {
{( M1 T( t/ B w8 j4 w& C) y i# O
CATListOfCATUnicodeString templiststring;5 Q; `* L) j5 L$ ?+ y
CATListValCATBaseUnknown_var tempCke;2 ]0 R/ o3 o7 w0 I6 ^ @) @
for (compt=1;compt<=nbfaces;compt++)
; P. q0 T: b; A6 [ {
1 W8 |# g5 ]( G5 D* @ //retrieve a list a position k (arrays start at position zero).' ?& H2 v* Q6 O/ z7 u* j
templiststring = (AttributNameList)[compt-1];
& e1 C% y2 G4 L tempCke = (AttrValList)[compt-1];
# O. |3 E; o1 _# p) G( @1 \
0 p0 V w+ ?3 n& j! f int nbAttributes = templiststring.Size();
: |' n1 B, ^; S3 c: u4 w7 E: E0 M int nbValues = tempCke.Size();
, ^( [% ]: Z, f9 g* Z6 N% X: c" s7 D
//the list must have the same size! If not, we jump to the next face+ {( s6 Y- p: @
if (nbAttributes != nbValues)
/ D( m" V5 u( a k {
3 e% \3 U6 p. l7 d) f" ]7 v: y cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
: Q6 @9 V& }; t- h continue;0 \# y4 K. ] R p, v
}/ |6 E5 [ }) l" H8 ^- S4 B
else4 @( c/ w3 z" F, a. h
{! l+ Y' n. Q$ b' B" X
cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;- ?9 k' u9 j- u; k8 G4 S
}8 z" d, u8 ?" E- S
for (int i=1;i<=nbAttributes;i++) g! G5 I9 n& f/ g8 w5 G+ w
{8 }5 u6 a. ]! J
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;5 m7 Y7 X* Z9 k* X5 }$ c" S
}1 S! B. e+ Q( C0 {7 q/ p
templiststring.RemoveAll();" ?: Q' G* J; Q- f$ d/ t! O
tempCke.RemoveAll();
* Q7 X0 u% q# ?; l2 h: |! [7 r+ B/ o9 p+ D/ e
}6 y- j9 \0 Y6 K+ }. E$ h# L
}
* g [1 m5 i- m7 t g: J9 T else if (E_FAIL == rc)
$ @5 s& O% {$ J/ P. v5 [4 v8 M {: A$ g) ^1 Y2 I5 Q. R* ?. l
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;6 R, z4 h# ^+ A5 z. D! r. T6 R
return 1;( y! p; ~' |7 h. } F% p
}
% T }& l" t; _) W; q' }( j, y( p //4 h$ Z" u( t4 Q* y w
//11 - 2 Cleaning List:! n9 s6 d* l# v3 _3 @
int i = 0;! ^6 F0 E$ o! i) o2 O3 M- a
for (i=0; i < nbfaces;i++), F9 S( M' q% h% p" C* E; c
{! {( C4 ] U: Y: n. k: J
AttributNameList.RemoveAll();1 r. |- h& T; P# w5 M& a
AttrValList.RemoveAll();
2 o- L5 V' F2 @) T# y5 E, ] }
# a. y% I8 v# y delete [] AttributNameList; AttributNameList = NULL;
. ^/ F" w6 ~6 I e6 i. p3 N6 b/ d* k delete [] AttrValList; AttrValList = NULL;0 [; y* x. S/ z
2 f7 q* i$ n: J) x9 b* G8 q
for (i = 1;i<= nbfaces;i++)
9 y& K2 m1 Y8 q! C {
% n# X2 @# r/ d' ?5 x Brep = ListBreps ;
6 e4 x" c9 C" h1 y1 R; _ ] if (NULL != Brep)8 v% q8 E# r! v$ O+ Z; E
{
! d+ h5 C1 U# ?$ X Brep->Release();
7 C$ L! W" L- L5 U* a; q" J G }( J5 p4 N2 w w, c6 |
}
5 C5 L1 V- g; g. C8 N ListBreps.RemoveAll();[/mw_shl_code]
- J$ @6 J* o& z; x { |
|