|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]4 M8 I2 ]* c9 N! ^+ n% O( U
//0 C. A5 ]! P+ A
//7 - retrieving and displaying current faces colors
! Q6 f6 {% ~* S" Z //
8 o# e+ S% W! N% Q cout<<"--------------------------"<<endl;" i" ]: m# X0 W' Q# F% c2 a4 P
cout<<"Retrieving current colors"<<endl;. V8 C" ?: a ^
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;; A" }( y' t5 S
& E- ^, ^3 b }, h0 q! c |, c, k9 x- h rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);1 M/ a7 v3 @+ t1 [/ v
if (E_FAIL == rc )
. ]4 k& k5 J! d {% a& y K2 f# K) X8 T# [- ?
cout<<"Error, an error occured while retrieving current part colors"<<endl;% G( b, D- u, F/ G: \* _- I
return 1;) I( d+ c: p0 @, J; e! Q5 h
}+ D) c3 L7 `+ @: \: G
' P, A7 x7 g% D
for (compt =1;compt<=nbfaces;compt++)
; m) x+ _9 a4 Q" z {0 g0 @7 O' v) L" e, z
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;1 }' S) ~2 e5 R7 u
}4 D0 C, P1 J+ E+ }& Z- x3 P
) m( j, m6 n; i- C8 D //1 ?; j7 K m9 t2 x1 L% n
//8 - Setting a new Color on all faces" N+ t! E) R4 n% I7 E: X
//
5 U9 S q4 ^9 h, _+ d9 h' d( o; J3 y) G ~5 e
//we are to color the faces with different color according their position : three by three will have the same color
* L6 o# m: W0 z3 j7 C% g cout<<"--------------------------"<<endl;3 Z3 r0 _2 |# x/ d, @
cout<<"Setting new colors"<<endl;$ h1 T/ |! G- W6 T# O [" V0 y
4 M- [: o7 q0 Y% S! F p2 O5 r CATListOfInt newRed,newGreen,newBlue,FailedIndex;0 @+ w# t& T8 z1 |, y2 _, {
int x=0;1 F4 |! b8 ?9 W" q, F
for (compt = 1;compt<= nbfaces;compt++)1 P) g( h9 ?" K; j2 _
{
- m$ s! x' l" X. Y* m0 D x = compt%3;
4 x W. Q9 X# R. P# C2 g int red(0),green(0),blue(0);
1 a) q' f# R+ ?! { if (1 == x)
& t1 k( H; B' ?' `0 O6 Z. c; o red = 255;
+ l0 m' z5 @ A+ u9 p6 { if (2 == x)8 a$ K; G. J% s5 p8 C# y
green = 255;, Q( U# @8 j$ |- N" }# c. @
if (0 == x)3 t# t6 R" @# g5 f) d1 d
blue = 255;
3 j$ \7 \" B2 D& @" J newRed.Append(red);
: r# x2 k; E4 c k+ m newGreen.Append(green);
2 { E$ A& f& H( n+ n9 l- M! T newBlue.Append (blue);) Z9 {0 w# n$ x1 B% j L! S& X" Q4 s
cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
, ]3 p% E8 {* X0 m7 C1 M/ m! t5 q* [6 O }
6 e [9 }8 U6 n1 p4 S; ~5 Z0 A. g( Y- m r9 P
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);* T9 p+ y$ p8 _( o. `2 C
if (E_FAIL == rc)% S; D2 h/ E6 v3 L; {$ ~" m4 @7 T
{7 @* N* _* `+ @$ i# ]9 Z
cout<<"Error, setting new color on faces failed for all faces"<<endl;1 i; X& }5 S5 J, j- k
return 1;
! |4 k+ u' F4 i. b- h }# v5 [ u8 r. R# J8 r0 f
else if (S_FALSE == rc )
1 n2 D6 S6 z5 R+ O# x {! n6 O3 b9 r8 g# `
int nberrors = FailedIndex.Size();3 Z/ v0 e' l2 _! B# \6 t
cout<<"Error, setting new color on faces fails for faces :"; u* _" i; D3 x9 S
for (compt = 1;compt<= FailedIndex.Size(); compt++)+ p p, C% r& ]* B' C7 ^( w
{+ ^0 y0 H2 `2 q! s: n' t) c
cout<<" "<<FailedIndex[compt];3 t0 W1 j3 V1 E' V5 _* m) B$ e7 j1 J
}% K4 y: S. ?+ {9 |
cout<<endl;
2 x) k& g# B" X+ \5 q) Z0 z }
0 M% j0 Q7 e# }( Q w( @/ p1 d else % P. D3 J! r/ m
cout<<"Colors successfully set on every faces"<<endl;. L! d6 I& O! ]9 d% \
//
. B6 h" L Z. P1 C* }; Q //9 - retrieving colors we have just set& y* f% \# E4 w
//
. s- l6 o6 G+ q' i cout<<"--------------------------"<<endl;% k* ~1 x& ?: { N/ t/ f
cout<<"Retrieving new colors"<<endl;- H5 x# h7 {9 w/ m" c
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);$ J3 A) y1 C# h4 ^3 F; ?, N. g# y
if (E_FAIL == rc )
) H+ W1 K" T6 z) V5 X8 U& W8 A {/ p( G" H3 m- \8 o' {
cout<<"Error, an error occured while retrieving current part colors"<<endl;
9 X7 o& n/ D+ d$ h+ D( I return 1;% P7 z# O: p, K0 N8 y
}
( u0 j( f: \# U. u3 R+ B0 v9 N, b2 v2 W+ ^
for (compt =1;compt<=nbfaces;compt++)
$ _6 S! V9 ^/ ~" }/ y {
* }( b' F4 j! |8 J cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
0 z& t% ~8 [7 i b }
* e: |- j4 j- P" k9 ?6 A' u( v
" d% i! ~$ K& z! u& B# g( H1 a& f6 L //2 V; f! Z: ?- N; g
//10 - Setting Applicative Attributes
8 b# x7 F) O/ Y( L$ B9 f; u //
: c9 T( s4 H' v8 _! B1 d: X/ B
" T) m# l" p$ z* ]8 z //
8 S; [7 h, R( B7 H9 r, i7 _ //10 - 1 creating new attributes 6 z6 W! Y; h5 K: X! C+ y
cout<<"--------------------------"<<endl;
! i3 p2 _( K6 U" e3 U cout<<"Creating applicative attributes for different faces"<<endl;
+ A# d6 m- f3 v: Y CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
5 v5 Q9 G' N! w/ P7 X2 w, [ CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];
0 B& b& Z/ J$ U( c- }2 J: u1 _ CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();* c: |9 a4 Q5 }+ [) v) G. S
for (compt = 1;compt<= nbfaces;compt++)
9 D( q. L7 D0 f; S& q7 l+ V9 T {
- x* g( A- f0 B: H, e cout<<"Creating ";+ d/ N& g5 ?" o
x = compt%3;
( b+ N8 [) |- @* a* R ?: P //for each face we create a new list of apllicative attributes
% R& q7 A$ c9 \# e( D //an applicative attribute is made of a Name and a value
/ O" ^2 c+ h6 O" W7 q6 c. ~ if (1 == x)0 K# M% S$ i0 C5 [
{
4 a( _& Z; F; F AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);' e' _- X+ A- z' Q) j, @
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);: d+ D: \( m+ {8 }
' O" L! q; i+ Q' f% S //The first attribute will be the number of the face+ y" y0 Y- n5 s
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
% T3 g3 G/ f# U0 p* V* p, L( n ^ CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);9 V. D7 Z6 y+ i7 w) k& b5 n
AttrValueListToSet[compt-1]->Append(tempcke1);
+ l/ a ^- y0 ?# K- ?& z$ I - Q) K! E2 \8 X
cout<<" FACE_NUMBER with value "<<compt;
2 u8 d& {% ?/ |* I2 B5 R
4 j% S# p! m; |% h. W' y+ t //the second will be the color& d& W- D1 j2 r
AttrNameListToSet [compt-1]->Append("COLOR");
$ S6 [2 C0 t0 C9 a CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
! R6 Z' P; g- i/ t$ x AttrValueListToSet[compt-1]->Append(tempcke2);
2 A* S# b. V( I: ~9 r5 ~4 e
1 B# ]+ j8 v. Y3 d1 f cout<<" COLOR with value Red";
- j& @9 Z5 T. Z) o f 4 H' n8 S) @! g9 I
//the third is x
" ^3 W7 M3 w& z- n9 f+ ~' m1 j AttrNameListToSet [compt-1]->Append("X");
- b/ Y' f7 Q8 x; N% `$ O8 h CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
. H( n2 v, I k. C( S4 y b AttrValueListToSet[compt-1]->Append(tempcke3);. j H# J" n+ n; a
$ X8 H2 F( _2 O
cout<<" X with value "<<x;" c+ m& C- d: b" L) N' m
cout<<" for face nb "<<compt<<endl;: d0 E3 V+ y8 N, l5 H
}% A+ x8 [1 c `4 ?
else 4 j" d$ \# H8 i% A3 s. p
//just to show you you can have different size of list
& m! r( a/ `: X: A' A6 g {
+ V' K5 f" K; E( w AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);
4 @8 e7 [4 k( e, L- P5 ~4 B AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);
+ G* F7 D. j+ X/ p: a: K* J
e# m/ K2 o! M3 C: \& x, ^ //The first attribute will be the number of the face
$ N6 d& ~3 j) @ AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
; N2 P# g: U% Q; ~) x0 q. n CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);
U5 b2 x- J f4 D0 N AttrValueListToSet[compt-1]->Append(tempcke1);
# H' l$ [" @" ^+ _- ~) ` L7 G, r" Z$ ?
cout<<" FACE_NUMBER with value "<<compt;
6 X' } |6 K8 ~# O( ? Q
% z4 D4 @0 [' N& S8 Q, n# n/ k! R //the second will be the color! [/ B E; [* X5 T. F2 n
AttrNameListToSet [compt-1]->Append("COLOR");
5 l; ~0 i; i# \9 {0 l8 H* _ if (2 == x)
B! v% i* w# Z B X {
) X- Y8 Q3 S' e) @ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
# H* U* R: O: }/ _ AttrValueListToSet[compt-1]->Append(tempcke2);
, o" J) E9 N8 J# A( q# p4 j5 `3 h) e
" e0 {* Q1 F% ]3 Z cout<<" COLOR with value Green";( | W1 s2 \4 `
}( [5 e+ C1 D5 l5 I
if (0 == x)
7 G7 i5 O+ I9 o {
" n" v5 b) O$ r, Y' ]4 ^ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");
# [ W' N* N0 H$ s, d- L$ n4 [ AttrValueListToSet[compt-1]->Append(tempcke2);
E: H+ z3 |" d1 z5 `' \3 n) }
2 H1 i& a& ]& p+ I cout<<" COLOR with value Blue";
" k7 R9 K9 R4 \# A) m: D w+ V" O! D6 q }9 y; e6 u! T. c! ` Y) t
8 C j2 A' {% g5 R; V! b, J5 J7 j cout<<" on face nb "<<compt<<endl;
, ^) d7 }- Y+ Y8 m* x1 o% z: p7 K; G! h; x
}; l! \8 ^* `8 _
}
; \3 E( }" Q5 s( I% T; w, m/ M# U" `6 D! a% R& B/ c( L
//10 - 2 Setting the applicative attributes1 o0 d4 g6 v' x2 a
cout<<endl<<"Setting applicative attributes on different faces"<<endl;
2 J( P: I3 \' u FailedIndex.RemoveAll();
+ q! D8 Z, |" W1 M( D: Z rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);/ _) s$ t0 n0 i; [* X
if (E_FAIL == rc)
. g7 t$ ~8 \ N: s. w, t( d {
) o7 u7 I4 \# q0 P6 J u cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
; ^8 \: [$ p* _6 l }
! }& T- @3 w& o ~- _- @ else if (S_FALSE == rc)
) s: o& w$ v/ V, q {
3 a9 M, i! ^; X Q/ a int nberrors = FailedIndex.Size();
7 G; e q$ W1 `' z/ E cout<<"Error, setting applicative attriutes on faces fails for faces :";4 h' s6 n6 k# h. `& @2 M
for (compt = 1;compt<= FailedIndex.Size(); compt++)
- L# Y2 f% ]% |6 ]* B+ Y# T C# q {
- R( d3 T# V$ L$ T( @ cout<<" "<<FailedIndex[compt];
+ Z/ ?9 R; Q4 k5 \+ | }2 I: [' E# J1 c" J, A
cout<<endl;+ ]) Q$ k1 r$ d7 p* w8 Q- I* J- J
}
: [9 j3 i/ \" n/ n) q else2 V7 @- {$ \3 W3 S
{
7 e9 K9 h7 m) h: B- H0 `3 \/ X% E t cout<<"Applicative attributes successfully set"<<endl;% k5 y# f+ @8 N v0 l* Y) S
}: Y# j% Z( b8 c/ X6 F6 @8 m v2 j
! `- z% b* m4 R; Q //10 - 3 cleaning
8 k4 M" T6 C/ V# | for (compt=1; compt<=nbfaces;compt++)+ s4 [; Q: n7 k/ ?' H5 M# X$ d
{
& B' j6 R$ y/ o2 n AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;
4 [6 [+ r! i6 f! P8 ^- k) v AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
" C) K7 T. J/ A4 Y }
4 v1 k* D# S1 D. \. S
0 L3 k3 J" M" W7 l% O" w/ A" H& ?/ g delete [] AttrNameListToSet; AttrNameListToSet = NULL;
" _6 I- E2 R9 M( ^" M O2 q# J delete [] AttrValueListToSet;AttrValueListToSet = NULL;# w# }( v: E- X% H# y2 z
" o8 s; G. F6 ]) b1 z% X7 ?' [" F //+ F4 r; M/ N" z) S
//11 - Retrieving the applicative attributes we have just set# N4 u# ]8 Q! f- W) d
//
8 i# v: E, T5 c# y, R, M cout<<"--------------------------"<<endl;% x5 c. K# C! w" X3 t& F
cout<<"Getting applicative attributes on faces"<<endl;( u" h; J j! p4 n1 H8 I
//
6 J; s4 R3 D, M //11 - 1 Getting attributes
' H! A/ j" ^3 v- @ F CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];
' U+ W3 d/ Y$ C7 s CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];. G+ p v' |* y! w6 C" I6 j* s! f5 A
rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );
+ F+ T4 T4 y6 C7 V. w, B0 | if (SUCCEEDED(rc))
6 h, P+ S I. x1 J% c {8 C5 J. H- A0 e1 t3 _) I
CATListOfCATUnicodeString templiststring;
8 `0 h S8 Z8 S4 N ` CATListValCATBaseUnknown_var tempCke;
5 c, l5 C* H' r/ c0 { for (compt=1;compt<=nbfaces;compt++)9 k5 e1 w4 [- m* \4 U G
{8 ^6 `3 L0 t1 {! B2 i) }( `! m! U
//retrieve a list a position k (arrays start at position zero)." F& U( w4 B' |, O
templiststring = (AttributNameList)[compt-1];
: b% F5 `; d0 A D tempCke = (AttrValList)[compt-1];, Q, j p! O0 `2 E/ a" c# \) R( D
* C4 [2 V. |4 r# n" `8 T0 a" S. O: _
int nbAttributes = templiststring.Size();
3 r! e4 P# |) R int nbValues = tempCke.Size();
% h9 l; o0 _ p5 _; `* N1 v) H3 w( k3 `
P C% {; N$ u6 v, y) O: v //the list must have the same size! If not, we jump to the next face
+ a+ u8 a4 [. L) V T" G if (nbAttributes != nbValues): _0 l2 ~. M' t( M; ?
{" A% S( V' `8 i% t; j) o
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;1 c) e; x# N8 ~" _ O4 C H: Y& W
continue;; m1 O. C3 _* x
}
~: K3 z0 ^. W9 L else
$ ?& `0 o9 T4 a/ m i {
2 B, M4 R* u3 G4 H cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;4 k( D/ d% ]2 e3 \4 M
}
6 `% Q# Q2 ?/ V8 M8 @0 Z+ f for (int i=1;i<=nbAttributes;i++)# L" `: g/ r) u- _! s
{
# s; A! T+ y- m3 L3 Q cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;
' J2 U& I/ g* g0 [: y# h }
6 @9 e/ O% C# l1 E3 z) Q templiststring.RemoveAll();
- c3 N3 ? m0 `! m: |& V8 x tempCke.RemoveAll();
. B6 B+ Y! W, x- e5 }0 E; C$ X. K. M
}2 m' h7 P& t; A. |! E5 h
}
. P+ m3 _: R' B$ L2 y8 j- ] else if (E_FAIL == rc)2 d% B9 Y" d5 E; T/ l9 ]$ _" f
{
5 N( S4 }8 M9 Y; p cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
4 x( H8 Q# o* d) ?+ L" @* C return 1;
* O/ M/ S8 n; a! ?4 M; w9 q4 k }' q6 s: F9 H9 s1 t+ c3 M6 ?
//% C: f/ P- O2 L) ^
//11 - 2 Cleaning List:* T% S, @1 ^6 K0 L' l
int i = 0;
: c7 N$ ~7 x* t' u' }. l! z for (i=0; i < nbfaces;i++)
: ?( }% T4 @! @ f9 o {- K4 s+ ~+ v3 {/ g) M& r
AttributNameList.RemoveAll();2 r' @. l0 B, B4 C
AttrValList.RemoveAll();1 j+ z5 i- E9 j+ Y2 ?3 d
}! y1 q& s) Z; J# m5 b
delete [] AttributNameList; AttributNameList = NULL;* y9 r% T+ R; A' H
delete [] AttrValList; AttrValList = NULL;, y5 c! m7 W2 z6 M0 r! C
2 x* J3 K! X5 j6 y for (i = 1;i<= nbfaces;i++)
( m1 s2 f& H" I v, o. X: i {
, c: p3 o- c; H& R1 o Brep = ListBreps ;
# Z' F5 t# v/ m v- C2 O% [( t+ S8 { if (NULL != Brep)
" O" x, h( t# q* A" k: v {6 ]2 G- C( e0 |3 Q2 f2 F) Y5 {9 G
Brep->Release();
1 A/ O7 h; Z: {( X8 f }2 l9 W }) ]. V# R6 @$ Y* y' p& ^
}! K C+ H: l+ k9 e* X( ~6 p
ListBreps.RemoveAll();[/mw_shl_code]
# D8 o" z* \2 x8 R- r2 X |
|