|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]0 W# u0 ~1 \" n) G
//, Q3 E8 f* ~* h& ~9 ^& T
//7 - retrieving and displaying current faces colors
$ I* E8 m3 ?1 g& O/ W //% K& M1 h0 B- b( u& a+ H; @( {3 }
cout<<"--------------------------"<<endl;: O5 R' o3 J5 ]* i/ V
cout<<"Retrieving current colors"<<endl;
: \8 o4 A! g/ v0 P# Z } CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;1 x8 g$ x( L+ I, e
9 Y" E6 t' I/ X8 s. q
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
; n* f0 ]- u4 r! p if (E_FAIL == rc )) u0 o/ x+ V1 W! t; L" `" y
{- a0 e; Y" Z/ Q) B
cout<<"Error, an error occured while retrieving current part colors"<<endl;- y( G' c; e4 b: \8 N: G, V
return 1;9 Y1 Y/ b$ r0 v5 N
}+ z; x( a, A2 {7 ?
; O9 z, x* |7 |- P; |* ~
for (compt =1;compt<=nbfaces;compt++)
, T" r: n# Q/ ?; g2 t0 q @ {+ j: c! x6 g. I
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;5 j( T& b( c/ U' i, K; t% j8 A, q3 B3 f
}
3 G/ y; E: C+ d6 {- x& O$ M* O/ y/ V, D3 r
/// m. f$ p9 d& G( p: L
//8 - Setting a new Color on all faces- w) ~; I% r+ \; n1 l8 P( W
//
* E5 H3 X$ i1 `- H* h
% u7 ?; t8 D/ N; l6 V7 e //we are to color the faces with different color according their position : three by three will have the same color8 K: l" a; B# J/ v( U
cout<<"--------------------------"<<endl; U# V3 h1 J7 c4 U( u
cout<<"Setting new colors"<<endl;
& i* u" ~4 a1 g$ a& Y 9 R7 Z: h( O9 V" i+ r* T* T
CATListOfInt newRed,newGreen,newBlue,FailedIndex;) [4 d/ i+ Y8 R j: @
int x=0;
; l. k5 r: [- @4 b for (compt = 1;compt<= nbfaces;compt++)
( t) w2 G9 e* s N8 } {' C1 `; o9 V2 h" P: M4 T0 ]( f
x = compt%3;# |% h8 c$ O; p4 U! c
int red(0),green(0),blue(0);
+ N; Y2 B4 v p; ]% \6 f if (1 == x)
7 J1 s" c( P% L2 ` red = 255;
( ^2 p' H, o& k U$ { if (2 == x)0 z+ l2 Z/ P; F# w* ^+ A. P, ~
green = 255;
/ r7 B9 l# N6 N$ {& j( @ if (0 == x)
0 t$ g6 y% t2 v3 j+ J& k blue = 255;1 J4 n4 B; _9 y6 ?# e
newRed.Append(red);
" f/ e& |. Z+ X! a! q newGreen.Append(green);
4 ^* x1 x9 z, y) }; K newBlue.Append (blue);
. [ g, I- ]( I/ L! T cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;' a# g. `% _; A, S" I. g* \, J
}$ |% i. I! a7 g0 s; X- X
& N2 P( Y) t6 k- ]
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);9 L7 B C. M7 ?3 _
if (E_FAIL == rc)( }$ l0 a, L |
{% R, c2 h4 z/ U, h" H7 o. d+ Y
cout<<"Error, setting new color on faces failed for all faces"<<endl;# Y: G( O8 f/ n9 x
return 1;
% T3 [; F( P+ y2 u0 D }2 _ n/ ]$ p& w5 D \) j+ t
else if (S_FALSE == rc )% ]5 z. i+ ? N( F1 T
{
- \4 l) c" H% J% w5 t int nberrors = FailedIndex.Size();1 f) w* a% }. q# j U- L- ^5 d8 ~
cout<<"Error, setting new color on faces fails for faces :";
% U$ M2 B: d0 M- a. s for (compt = 1;compt<= FailedIndex.Size(); compt++)7 K& R% S( p6 U
{! R# L" r" K7 P+ Q2 S- z( I
cout<<" "<<FailedIndex[compt];, O) s: Y) Q# v) C. g* F* e. S9 J
}
% H5 k& x, {2 Q, f1 ^ cout<<endl;
/ F$ [. ?" o1 x }) ?) m7 n& T2 V, E/ _# A4 l1 J
else 3 K9 V' _+ M9 o3 Z/ F* q
cout<<"Colors successfully set on every faces"<<endl;
; h4 s6 |5 `- H. S7 s5 X //5 P) R: S: }/ |$ h8 U) ~# C
//9 - retrieving colors we have just set
* P# {- @, q* J4 f" j //7 R" M" W: i) e3 ^8 ^# z
cout<<"--------------------------"<<endl;2 [! P z( t8 r+ W
cout<<"Retrieving new colors"<<endl;$ I% _7 O4 v6 w# h! B8 R
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);
# }8 q' o" j; y if (E_FAIL == rc ): u2 U5 P* }9 W! v# J6 V4 f4 }
{
9 N! E6 q2 M+ p: P( U+ r cout<<"Error, an error occured while retrieving current part colors"<<endl;
, n" r6 b/ f1 ]# E+ g; l return 1;, Y1 F8 l1 ]$ _- o7 E
}
J; D5 R% _3 ~1 |
! ^2 s( I7 a# o' t$ m+ }" ` for (compt =1;compt<=nbfaces;compt++)
, w0 l$ E/ N# }& O9 B {
6 M* t& @! E8 T1 [ cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! n# \9 A4 `6 b+ [* _ }8 b! ?7 @3 i. k W& ]9 L
3 p' | D& Y# ]$ R5 r
//. G& u) Z' ~7 ]: B/ l P% n' K7 C
//10 - Setting Applicative Attributes3 Q8 X S9 R; G5 S2 Z
//! G8 Y4 e+ {: v4 @$ j& r5 j
4 l2 A+ F1 A0 X' }' E1 U" J) V! g //
; B/ n' X# N' p; E( ~ X //10 - 1 creating new attributes
6 c9 Q& @5 ?# I6 B cout<<"--------------------------"<<endl;
4 `/ ~% \/ P: | cout<<"Creating applicative attributes for different faces"<<endl;
8 ^% Z/ n5 z( U$ E0 H CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];# I$ ^1 h: O) I$ `& E" G8 T0 i
CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
# V& G9 c* } P* m+ k5 L( \# E CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();5 F$ I! U# m" _- X* y- s B
for (compt = 1;compt<= nbfaces;compt++)
" k8 t& B+ r+ A3 B' `# Q1 a" N {: S& h) @; F% y; g
cout<<"Creating "; r/ L" M4 H( `4 E7 Z% t9 {- q
x = compt%3;( h* a* J3 C7 C- a
//for each face we create a new list of apllicative attributes
( H' G; a1 S, |: F9 Q //an applicative attribute is made of a Name and a value x- {5 @& ^3 L9 l2 B
if (1 == x)
2 X7 N! S& R5 f4 n5 g: f {- @ W6 r6 f, d
AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
3 E1 m0 Q0 }* [& Q7 c; X$ P3 c# G/ s9 V AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);
$ U3 v" B- X$ S. e; _: E5 e+ M7 a r
" x! k8 W/ b q. } //The first attribute will be the number of the face
# M! o6 Q+ z1 l! y+ S* G$ w' s AttrNameListToSet [compt-1]->Append("FACE_NUMBER");! [( [! o- [: y3 l' k( c9 E2 w/ _
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);1 P. B F5 Z% ~6 D" n
AttrValueListToSet[compt-1]->Append(tempcke1);( }( C* i+ G) K! D
. i+ \; P& ^( P cout<<" FACE_NUMBER with value "<<compt; $ }0 ^2 c3 z: `4 S; l, a2 t1 x
" D& }7 G& m# R+ J1 W( @ //the second will be the color
+ G" Z' M, d! M# F AttrNameListToSet [compt-1]->Append("COLOR");
) S/ v8 E" d6 G6 F9 M* r' J3 k9 j CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
, r' B9 i- t; P- m. D AttrValueListToSet[compt-1]->Append(tempcke2);
, v9 `8 U5 b, U/ {6 n, ^ & |, O% l5 k4 E0 X& A3 s6 v1 @ {
cout<<" COLOR with value Red";
& }/ v0 g0 `$ M8 y8 n0 r' r9 T
+ k- C, J# ?' A# g6 K1 a7 p //the third is x$ {$ o, N8 R- {$ Y: h; d1 p. d% w
AttrNameListToSet [compt-1]->Append("X");
+ {# x4 m) Q- q CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
& u9 [) V. ?, t* G; L4 V& _/ O$ o" E AttrValueListToSet[compt-1]->Append(tempcke3);% C( s2 e l3 Y
' W2 l9 Q2 H$ W" i- A- g- I cout<<" X with value "<<x;6 ^: W# m% I. M
cout<<" for face nb "<<compt<<endl;6 b4 }- v0 M1 M1 P+ f. T( ]% v
}
; B% Y9 X) }( j2 j else , w! r5 e1 v; S! }" M: W
//just to show you you can have different size of list
: }/ a% `/ [; S* E0 }2 Z {
+ M* [( d* ]/ v$ \7 m AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);, w( Q' p- g9 Y& Q: k
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);5 S' V! |4 r v. P. ] v& F
" K, y+ l8 r) v
//The first attribute will be the number of the face
5 Q! T- B, \4 j# y% e AttrNameListToSet [compt-1]->Append("FACE_NUMBER");3 V5 r9 s( Z2 j7 K8 I; C
CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);. S2 u1 ?. y6 S/ S
AttrValueListToSet[compt-1]->Append(tempcke1);
% l( X, @% \! T2 o1 v9 R
" q8 d7 K/ }; k* n; N) e; i cout<<" FACE_NUMBER with value "<<compt; : _$ l5 l V' [( N6 M' V
/ a0 `5 h+ b6 E: Q) q. b( y7 w: m9 t! _
//the second will be the color7 ~. O2 N( H" X3 b
AttrNameListToSet [compt-1]->Append("COLOR");
# U" W" ^# \5 A) ?8 o6 d, k# N if (2 == x)
7 V! u" _8 B5 E) e7 P% y! S) c( S {
& \/ l' ]% f: H' O* | CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");5 b/ ?% m5 S a+ N* u
AttrValueListToSet[compt-1]->Append(tempcke2);
1 x% \+ P/ u3 k+ D* ^3 P9 Y ) [) c$ {4 A/ J* e3 Q
cout<<" COLOR with value Green";
" C6 B. ?& Y6 h9 ` }
4 }, R& L, R& S if (0 == x)
7 S, X& s' k5 g# q R {
& g, d) k6 Y) M' x' _ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
" ?0 c; f4 L0 m8 } AttrValueListToSet[compt-1]->Append(tempcke2);
* f" G* W: Q' N' |5 ] 0 D* c% c4 k- M
cout<<" COLOR with value Blue";
9 U% u R8 q9 e9 D }
8 G% Z4 J$ T% G& s5 X8 h9 Y4 c. l" Q
cout<<" on face nb "<<compt<<endl;
2 [/ y, \" _- `
7 x/ x; q5 {3 q }6 _% M7 P5 ?7 b, L1 ]8 J$ k# c+ e
}! n2 ?) |/ e3 _! ], u
( e# u, z, o! `& l9 e% Q. s //10 - 2 Setting the applicative attributes
! [) c' V! w5 l, _& I# U2 E cout<<endl<<"Setting applicative attributes on different faces"<<endl;
$ {* c" y$ I% Y( M& S: ^5 I+ l FailedIndex.RemoveAll();- U$ i" m L- h) `
rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
/ n9 O0 B- r& f( P4 E if (E_FAIL == rc)% l- [7 ~" J: b) R, j
{
) `& @% l# p4 V2 G: Z8 h cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
/ h0 o8 t+ D$ A! E }- A5 ?- m3 c9 V! V
else if (S_FALSE == rc)
( A* W A0 n1 w {; G; z4 n+ k5 j' H: f7 ]6 @' Z
int nberrors = FailedIndex.Size();* k: ^( O5 ?: D5 \5 |* Q$ Q0 p
cout<<"Error, setting applicative attriutes on faces fails for faces :";! S* @' @3 C0 |+ p8 _# m" N* d
for (compt = 1;compt<= FailedIndex.Size(); compt++)
9 k- ^: I& N! Y- q {: J% H% J c6 T% N" f1 h. \3 N& ]
cout<<" "<<FailedIndex[compt];0 T) p3 e3 }. X4 b. v
}8 N+ }( p2 P/ |! u z- F! G
cout<<endl;
% X. P2 r0 M1 I: ^$ C0 k; g }
$ f; O, h5 J+ @ U$ c0 ^" g else6 O7 O; y5 z& S. p
{4 X, S2 t2 w9 R6 m: H
cout<<"Applicative attributes successfully set"<<endl;. t8 u0 C! N7 E4 F. l& J$ E. t
}
- r- t- r8 ]" w7 a! ^: N
8 X% {' ~$ I6 t* A //10 - 3 cleaning
- ?; F! ^0 }- O. ` for (compt=1; compt<=nbfaces;compt++)2 z* A3 N' {& _4 c
{8 g; v: d$ S' v$ G. b
AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
7 q4 ?$ c; L- b/ _% r AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;$ j2 l' m4 m. I, o
}
6 [. ~$ y7 [7 N1 U, p; x- T. v5 t0 b3 P4 @" A
delete [] AttrNameListToSet; AttrNameListToSet = NULL;
$ @" u- Z% X: I) [ delete [] AttrValueListToSet;AttrValueListToSet = NULL;
! m( S+ r Z4 o4 X% j* k5 r$ u6 O `7 E5 X0 w+ [
//8 {3 h b' X7 u- Y
//11 - Retrieving the applicative attributes we have just set8 p! Q$ u+ W( h; J/ h- R
//
* U# R& h3 z0 @: w) a$ S cout<<"--------------------------"<<endl;
- g+ z3 Q; x9 K6 D0 ?4 d _ cout<<"Getting applicative attributes on faces"<<endl;
! o. J( `8 k" R" f4 W/ J1 @- S6 q //
0 [4 G b( H: ^1 M, x //11 - 1 Getting attributes
% O5 e9 m2 b3 L$ F! k% }3 a+ H CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];: [0 U5 r, K2 J6 p# I; b3 Q+ @% b% t
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];, V* A$ V; Y: T; ]4 d
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );$ `/ v' ?- Y' K8 F
if (SUCCEEDED(rc))
' p- |$ N. r9 O& E: S {; l. y& R' y X- a
CATListOfCATUnicodeString templiststring;9 k2 I+ P& o1 ]+ ^/ R: X7 C
CATListValCATBaseUnknown_var tempCke;( u7 P0 p5 M Y( A8 a4 ]5 T' u
for (compt=1;compt<=nbfaces;compt++)
# G/ p6 V# ~: l' V5 ] {
: O: j9 c- E% ] //retrieve a list a position k (arrays start at position zero).5 z$ O( Y) {& O Z$ @9 z" X
templiststring = (AttributNameList)[compt-1];4 E+ E6 ^& R9 J" t
tempCke = (AttrValList)[compt-1];( F. ~# Z& p1 j% N1 j' U. ~
$ {+ O G6 r0 i# B: K- z7 }
int nbAttributes = templiststring.Size();
$ Q; A/ |" I. q6 L* h int nbValues = tempCke.Size();
( Y/ v& v5 I4 q6 ]7 z! {6 p1 j1 o# a
//the list must have the same size! If not, we jump to the next face$ T% I% b+ C8 w
if (nbAttributes != nbValues)# b: e% _: L8 b: t6 j+ Q8 a
{
& ]$ j. H! ]8 d; ?6 O) Q cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;9 v8 [' r& W6 b
continue;/ g% ~4 c9 L5 O9 L+ u1 O
}% v8 ^& O3 e# c7 y
else
3 I! w$ D. P' E$ j+ i2 A [ {
& G- t2 `5 q1 B- f- l cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;
) b( G' q% h- I- g/ D3 m8 R }3 T2 S" a4 }7 `! n. E; E
for (int i=1;i<=nbAttributes;i++)8 r) o) x: ?% X! D
{" k; J8 ~7 T8 E* I2 n* Q
cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;8 e3 @* {5 s' l, Q+ C% ^* `
}
V5 U5 f9 ^3 b0 U% v templiststring.RemoveAll();
; o) g x, _0 I. K2 I! h tempCke.RemoveAll();9 p# w) k! {8 `* k8 X
* J- Z5 \- \5 K: X }
9 Q: [7 ?& }2 t9 x }& d2 y% L+ N+ c, w" g* l: i
else if (E_FAIL == rc): x' L9 w9 S( T& z
{9 u& @* p+ `$ Z4 K- S& U% z( S
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;% t! p4 b4 ]1 J6 d! @8 G: d& m
return 1;
2 g, y9 x+ P) X% [7 S }
& U8 T( j* m' Q( D2 N7 Y5 y //
, D% T- j; ^/ K' {. s z //11 - 2 Cleaning List:
9 r- ?1 U4 a9 i, G4 b1 Y" F int i = 0;
W) z8 ]4 q+ V! M for (i=0; i < nbfaces;i++)" l' Q+ e' v& I2 Z1 z
{
: L2 R$ i! X, N9 u/ v% d AttributNameList.RemoveAll();' A0 k! o9 _2 a& w$ i1 B$ z
AttrValList.RemoveAll();
: c0 o( A C3 m }/ O9 _" Q6 ^/ {8 m
delete [] AttributNameList; AttributNameList = NULL;
# t# d' }; b0 A. I1 g: V delete [] AttrValList; AttrValList = NULL;; |# q( K8 ]8 {1 Y/ {: [
" ~& ]" y# q$ r, B: P$ N6 k4 z8 H
for (i = 1;i<= nbfaces;i++)% E( m9 R8 R0 A" x9 X
{
3 s5 {7 S# k* i: k3 Z! c4 t) g Brep = ListBreps ;/ `( f3 R7 R3 s2 L8 A+ \8 J
if (NULL != Brep)
) T, `3 _& D8 j9 d) K& B {4 O8 W; F) P$ e* @0 C- G
Brep->Release();
0 z' _9 Y/ T0 A/ c, i d- b0 l/ L; r% f }
2 S% X. { c$ u7 q }
# e/ f5 E: n- u$ L( } ListBreps.RemoveAll();[/mw_shl_code]
8 L0 A% U- o; a+ U3 o j [- i |
|