|
|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]- n1 u. n2 H3 w8 ?# a) L
//
6 P8 [7 G; y1 D; o) T0 u //7 - retrieving and displaying current faces colors0 W3 d3 M e9 z* z
//
$ Z9 P& l i2 G+ |: D cout<<"--------------------------"<<endl;9 ]" l4 K; S5 E/ y. B
cout<<"Retrieving current colors"<<endl;
# G" Q6 t7 G0 ^$ h. |6 X: a CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
5 W+ c: M4 [$ f5 B * G2 M' p1 D4 X3 h& u" E! Z
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
8 q2 J# r- J+ u1 K1 A- \$ x+ r if (E_FAIL == rc )9 L( \/ }3 k) s( l! l% v7 U0 H
{
+ a3 O5 t8 j5 \" p cout<<"Error, an error occured while retrieving current part colors"<<endl;! r; O( \/ c J$ T; v$ Q; A" }
return 1;$ b& a; L# g: u" }7 O6 x
}
6 N; ~* Z; c6 ^. s, |1 a
& j s9 T- A* q0 c5 o. R2 @8 E for (compt =1;compt<=nbfaces;compt++)# z' W1 ~( F- s4 U9 i
{
7 p9 G) F* [1 W' J2 E r3 Y/ {& V cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;. f8 u( ~4 I1 B4 \) C6 \) p8 U
}
3 l& R! P& l9 R, r3 J |& a7 @6 k- P7 I/ _' x$ s
//
" q# }$ E$ C/ \) R% W; @ //8 - Setting a new Color on all faces
9 A9 _; i9 {+ n! K2 G /// M5 F5 |# q7 S7 L( L' Y: j6 i
$ V$ k9 u. m [! ]$ T$ b4 T //we are to color the faces with different color according their position : three by three will have the same color
2 M7 t! w7 S9 c' | cout<<"--------------------------"<<endl;" ?! _0 H0 V0 k8 B+ g( K
cout<<"Setting new colors"<<endl;
$ Q- F# ~. m/ j' A- ?
8 E3 U* |( b! w$ @* Y. K* e CATListOfInt newRed,newGreen,newBlue,FailedIndex;
! @0 T6 {% D5 u int x=0;& m! U" o) L6 J4 G
for (compt = 1;compt<= nbfaces;compt++)
) ]1 V- X. e. ^ {' F. p6 t7 l& P$ d) @& }" S
x = compt%3;
J9 Q) q7 O- A7 Y: w+ z int red(0),green(0),blue(0);( u, G; ~& a4 {% Q
if (1 == x)# I2 u$ K+ F3 C# u5 y
red = 255;
! |1 o; h6 J! ~- v D if (2 == x)$ K# r9 H2 q3 l
green = 255;: s4 b; Y/ h/ C6 ?4 j2 a- F
if (0 == x)
' u" \5 n h( K blue = 255;! d+ ~ M4 f5 l5 y$ b
newRed.Append(red);+ T$ a3 A+ G+ ^+ ~$ f9 e
newGreen.Append(green);
6 k# N" a) z2 s# E) ~/ Q, o newBlue.Append (blue);# E0 X* F2 K7 V8 x0 K
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
9 R/ y+ l. o3 U5 e4 m }7 Q6 V* n0 J. F1 j" V( w
t0 e y3 k: R7 b' t
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);2 a% D8 `; m/ d5 L0 Y* t
if (E_FAIL == rc)1 ^! r, x5 l; n8 G0 l! ~* z" p4 o, [
{) @& }& N5 F9 n
cout<<"Error, setting new color on faces failed for all faces"<<endl;
5 N- t0 V2 ~* F return 1;
' D7 @" M2 A. {0 Q: } }5 ?7 Y+ O5 o3 ~" l5 `. p' v
else if (S_FALSE == rc ) o" T9 ]4 }- c0 g8 Z% ?% h$ i
{
& h6 H5 Y) ^" \4 L. |3 |2 D int nberrors = FailedIndex.Size();
w* x G2 ~* c% v cout<<"Error, setting new color on faces fails for faces :";
. ?9 _2 d7 E8 u- n k for (compt = 1;compt<= FailedIndex.Size(); compt++)" i# e B& ?$ a$ @
{
! }. D" x6 _- B) b/ i cout<<" "<<FailedIndex[compt];
5 f3 }% l7 ]7 ~, y# A, ^" | }! s0 P$ S2 s' s: o, j5 o
cout<<endl;
9 k( u+ ]0 ]# V! G I }
- m3 c% x0 ]$ k9 ?4 W else ! P& t5 n; a2 h8 S. U1 u
cout<<"Colors successfully set on every faces"<<endl;! h1 j8 t$ k2 N0 Y) D
//
. W) W4 p3 q: p/ P; Q1 h //9 - retrieving colors we have just set* {9 X I, {; Q/ K* Z! j
//
' D$ u) \/ Y; G cout<<"--------------------------"<<endl;1 Z" \( O+ W7 x* N- v1 B6 s2 Z+ q
cout<<"Retrieving new colors"<<endl;! N# L4 j ^" I; D; ^ ^2 `4 U% j
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
& W v6 g4 O7 P+ | if (E_FAIL == rc )9 z$ n3 d9 u- j) B. s) Y( y2 s+ R
{6 \! V" J0 R1 b. q4 q6 I' X
cout<<"Error, an error occured while retrieving current part colors"<<endl;2 F/ ]2 s1 F. q' s8 R6 S
return 1;8 A$ @ R* A% N; r" X" {9 L" Q
}
. s' T8 V0 a( K* Q7 E3 S5 K3 G+ a, I2 `: x5 l
for (compt =1;compt<=nbfaces;compt++)9 \5 V% `5 o) o, U s
{. ^/ @; S! z! }
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;+ m( T( C1 d2 n4 P6 h6 J
}
# f0 r- ^6 Y, s: r6 B* {: Q7 z2 U1 \- d# c/ k
//4 z. X" G# ~% P X% u0 y! l; h4 ~, Y( Y
//10 - Setting Applicative Attributes9 z9 B' U5 a3 M
//
/ q1 B5 r; C5 G% _% I, |
7 p, ^) ~; T O% d //
0 f( r6 k4 H0 [6 }( Z$ x) E //10 - 1 creating new attributes
3 U. P4 ^) I' |0 K+ W cout<<"--------------------------"<<endl;
# @ Y& n7 q6 P cout<<"Creating applicative attributes for different faces"<<endl;' k. {# _+ u# _& m
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
# }! c; j% q. s! Z* E9 ? CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];5 F8 `$ m4 f7 i7 {2 d; E+ N
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();# Y0 K/ Q5 d" }1 m
for (compt = 1;compt<= nbfaces;compt++)
( s& S! N& X8 C0 A9 J% g; h {" _4 b0 ~( s' \$ Z
cout<<"Creating ";7 j; ^6 X2 I; C7 s
x = compt%3;! t6 }$ l5 v0 P- k8 {) f
//for each face we create a new list of apllicative attributes
% }; \/ ^/ } T9 x, w //an applicative attribute is made of a Name and a value
' Z" G; e2 d" d" e8 O' ]( M if (1 == x)
% _+ v* A! g/ D) v6 }( J {& J; P9 e& X1 r6 ^: _. R, {/ h/ V# ?
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
, P2 f& U+ T5 G) j AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);, P- ]; k5 E* Q
: S4 z, w% {* G1 \ //The first attribute will be the number of the face" E) \( v- {! V
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
, u0 J; U# k: n0 @ CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);/ x( x7 G4 P; w- G# v; S: B
AttrValueListToSet[compt-1]->Append(tempcke1);
8 ?; }6 d1 d. J5 A5 q0 ^: E2 ~4 b
2 j9 ^: c/ O: F cout<<" FACE_NUMBER with value "<<compt;
2 I3 z/ c# z4 e3 Z4 t& I3 t( z5 R# a& q( I9 z0 F5 T7 _
//the second will be the color
7 i" U/ r3 z( C1 b AttrNameListToSet [compt-1]->Append("COLOR");
% R( B( K3 z$ r0 m0 W/ l CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");5 ^# l7 ?; n0 V* j* X8 L
AttrValueListToSet[compt-1]->Append(tempcke2);& s' F% F0 ~/ c* _
4 j, j# T2 R, M- |: B i cout<<" COLOR with value Red";. n) U9 Z# z, q% D3 z
" W3 T4 R, c; O& t
//the third is x6 e! z! |# y9 {2 V' q2 z
AttrNameListToSet [compt-1]->Append("X");, J& I7 A8 c1 R8 N t0 W
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
2 B. {0 I! c8 T. ] AttrValueListToSet[compt-1]->Append(tempcke3);
& w% B0 k9 Y7 T( b+ l! d . n7 O9 K! E. j' r6 d- m+ ?- c5 f
cout<<" X with value "<<x;
1 W8 @7 ~* f( ~5 y! k9 j+ B% F cout<<" for face nb "<<compt<<endl;
3 A! @1 L4 v/ S) g' g! p+ D: x }
/ Q' T% Q1 d" X9 j3 k/ ^5 a9 p else
9 b: ?( h2 c% Y, s //just to show you you can have different size of list
# Z$ `$ b; h/ }5 W3 H1 b {7 ]$ O' N4 n8 d2 I7 k! {2 h" `
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
: t3 m$ Y* D* k AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);. [6 h2 z6 @3 u; |
5 P" P. j( k/ o# S& C* d6 C4 V( d
//The first attribute will be the number of the face# h* o! E% ^' g- ~# c7 t
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");4 H5 ? ?4 q! z/ ]7 ~
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);8 R: z! ^" k# r L! X/ U
AttrValueListToSet[compt-1]->Append(tempcke1);
, f& I, C* w2 U1 y( H9 G7 o( i, ?& R
cout<<" FACE_NUMBER with value "<<compt;
: ]/ O' a- C8 j) u! \1 A! O7 z/ `+ L# k" L
//the second will be the color( {8 m/ l. k, o3 A! m2 `+ p$ W
AttrNameListToSet [compt-1]->Append("COLOR");
! i6 _ H# o. A' ` ^) s if (2 == x). F5 ?6 |; f4 ]% P& ?
{6 Z) ~' y' [7 v; p F" q9 h$ P6 f
CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
9 ]+ G$ n+ f( L' ]" M# F7 d2 H/ o AttrValueListToSet[compt-1]->Append(tempcke2);7 _ m- {; T, y0 b
l5 _7 e3 s! e/ S! ` cout<<" COLOR with value Green";
2 l+ @# y2 G+ K* B }
+ z. ]9 v& [; f) R6 x+ o if (0 == x)
g3 `- f7 F( D) Y5 y1 ]% n {
6 P1 X' W2 w4 j" x2 G3 E CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
: x6 Z# t$ h. A$ r) H AttrValueListToSet[compt-1]->Append(tempcke2);
; ~% c8 g! K/ G$ \: @
; Z1 `$ ^3 e% J cout<<" COLOR with value Blue";
5 n/ @( B4 A0 ]% b3 ?% b) i }
5 S9 n$ a; L: k/ N8 }' h3 t1 N, ^% N( J, I3 \7 ]
cout<<" on face nb "<<compt<<endl;
1 y& c3 G" Z, ?0 f* Y. Y2 O0 Q9 Y7 O. I! R, ?$ i
}* W# R1 y( z4 T' l* V
}
1 N9 H# i v% |! B. P* b4 H' y& c C
//10 - 2 Setting the applicative attributes
1 e8 y" S. I& P: V cout<<endl<<"Setting applicative attributes on different faces"<<endl;( z6 s, F6 L* S5 s
FailedIndex.RemoveAll();% g6 R, ]" A/ r' l& e1 N
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
% _; z5 [, `4 t4 ^ if (E_FAIL == rc)
; Y0 ~7 ^/ Q a( ]4 N {
3 B+ i j4 A8 y y cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
* _7 ~* @. C0 T# k( ?" {6 \" V } s; o5 r. L7 d3 r
else if (S_FALSE == rc)# k% _' k( ?& P9 [6 b* O
{- c' P% e; {+ s8 h% f. R: a' o
int nberrors = FailedIndex.Size();
# v: b) y! ^: c: x1 K8 A cout<<"Error, setting applicative attriutes on faces fails for faces :";
8 N0 N# k& v* O; F' `& t for (compt = 1;compt<= FailedIndex.Size(); compt++)% ?. c# D2 E4 ]0 W
{- T1 q9 O. B6 f2 u. C
cout<<" "<<FailedIndex[compt];
9 D9 C8 ^9 B' q }
+ A; S0 n( }1 b) c R) K cout<<endl;
* _& H* @' ?3 e8 c y, _8 V }
' i7 ?6 w, n$ l8 ?5 E else7 R+ l+ A3 D; y& `$ _- J
{8 f9 i5 y- P8 N1 H7 ]1 V
cout<<"Applicative attributes successfully set"<<endl;
- l( E3 Q& q7 t) d# a$ B }
9 c2 m; G3 T! ~6 Z) i. r
$ s8 D l4 {& g& t1 E. h; T //10 - 3 cleaning
4 b% i# j7 g, I/ O9 W) O' ~ for (compt=1; compt<=nbfaces;compt++); g. X+ x2 y4 ?- ^) J
{: O3 J( Q/ c# R6 q8 S7 n
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;$ X9 C# r9 G/ h" b
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
% b7 i' n& N# U5 Y- x: `' _ }& y2 S7 G0 ]. B( `: ^1 A E* i
' C3 D6 r5 y L delete [] AttrNameListToSet; AttrNameListToSet = NULL;1 J1 q; W; x$ [% T# q* m3 ~3 B; f
delete [] AttrValueListToSet;AttrValueListToSet = NULL;
- c! A; C2 m" x7 S e: @) I3 R P2 _2 U6 W
//
% t0 ?+ J6 H n9 b( k" x9 K //11 - Retrieving the applicative attributes we have just set
9 F y0 R: L0 x$ p% S2 o7 x4 V //1 y! A8 V; L! a2 b/ E( ?0 t( v \
cout<<"--------------------------"<<endl;
- Y) v. V& E4 V" H0 j- M5 p) s" | cout<<"Getting applicative attributes on faces"<<endl;/ C3 x; @# ~7 \/ H) w( @7 z
//$ \3 o8 \) a" I( _- j
//11 - 1 Getting attributes
6 C# |9 j; `# G( D% n CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
- ], I. M3 R5 \9 k) y3 R; i CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];5 p( ?, }5 H& I0 p; R
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );8 G Z. t7 H6 N5 P) ~- [5 y
if (SUCCEEDED(rc))7 T: S+ U( k8 B R1 e* D
{6 p5 E i6 |2 d) L
CATListOfCATUnicodeString templiststring;
/ r/ z% E. m7 P' l CATListValCATBaseUnknown_var tempCke;. x" u! I* {. C. ~
for (compt=1;compt<=nbfaces;compt++)
+ h" j) F( ^5 [6 {! d0 I {: e$ h+ _# H+ e$ b5 \; X
//retrieve a list a position k (arrays start at position zero).
7 U5 J r: W% t: M' B5 T templiststring = (AttributNameList)[compt-1];
0 D- r ]4 b7 D* w7 P tempCke = (AttrValList)[compt-1];
8 o/ v# }* p/ w8 h+ A/ b
$ [ ?# k$ C! _4 Y% y9 P int nbAttributes = templiststring.Size();, @. }' f @0 ~5 [
int nbValues = tempCke.Size();
, ?3 R+ X4 d( C4 i; N# n# [* _. R7 N
//the list must have the same size! If not, we jump to the next face
# u( F7 v+ _' }( o s if (nbAttributes != nbValues)
+ L9 d+ j7 M& s Y/ }5 I7 a' N {
0 N3 I" @9 k) N cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
6 Z; Z/ i3 F; ?) w3 R! @1 b7 W continue;, I- M1 R5 {3 ?% f
}- u9 T9 j8 t: r) U r4 W
else4 \) \$ G% \' D4 K! @8 j! _
{
; W! @" j( O- Q! N0 T- D, X9 f cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
; Z# X* Q7 g6 [7 n) V }* \$ P/ G* w+ e4 O& n+ X, H* v- C
for (int i=1;i<=nbAttributes;i++), G! t! X4 e- S% p* ^4 @- c+ s) a
{
) v1 l% X" H0 K( b8 G cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;* o9 q% n1 \, M% d. U
}
+ x7 h, s( `/ }' B2 P templiststring.RemoveAll();
" h' Q V! A; v8 A3 C tempCke.RemoveAll();$ L' }3 H% X _# ]; i
6 _* c3 X3 h1 l( a7 {) T1 A0 z }+ J6 \8 C) p( g% H6 Z* b
}% Z/ O6 G9 d, z3 p' {2 v
else if (E_FAIL == rc)
8 R S. e% z6 u8 t T1 ^, q {/ C: a2 P. L0 A/ e* u8 T; f
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;4 \& B) U' q' t% S6 F" U, ^7 x
return 1;6 c2 ?2 i/ e! K W4 X3 O
}& U3 h1 z7 |' Q; j- \5 y6 c
//
" J8 y" ^4 f$ l5 } //11 - 2 Cleaning List:) X, ?1 P8 M" H& W: D8 t; p1 z
int i = 0;0 I. G6 Z+ `1 c- x8 N
for (i=0; i < nbfaces;i++)) [6 T+ g0 @4 S* z# O \! J" O" x
{
+ U% g. ]# v& K. A# ?; \ AttributNameList.RemoveAll();
0 k+ s5 Q8 u9 w8 `; ^* q AttrValList.RemoveAll();) g7 |% C+ x' Y( h! ?8 H; b4 B
}
$ k/ e- H! |: F8 U- p* O delete [] AttributNameList; AttributNameList = NULL;8 _4 E% D' d( m# w
delete [] AttrValList; AttrValList = NULL;
8 g7 P& V: C6 f8 c: x" W# W- q; H2 S0 F9 h6 @8 A1 M4 G/ ]
for (i = 1;i<= nbfaces;i++)6 C$ c4 O2 C% h
{
9 m. W$ J" s- X! c; y' @; Q3 o Brep = ListBreps ;; v3 p3 Q% Z3 M; q6 S2 v! u# j& f; R
if (NULL != Brep)
7 A0 h8 M( C) w; V/ \; F# ~- C {
" E- V) b; j3 i% v, ] Brep->Release();2 {* F0 X2 m9 c! f5 F+ b# @/ y# J
}
% n8 ~. R) E, u }
/ X9 v5 T$ C) O. d+ W ListBreps.RemoveAll();[/mw_shl_code]2 z) [2 f5 I! e. h
|
|