|
admin
发表于 2018-1-10 16:50:30
[mw_shl_code=c,true]0 U$ {! ?/ X4 M' S x' O
//6 Y9 v0 y$ k' H
//7 - retrieving and displaying current faces colors% ^" ^0 o+ V& ~2 J: ?
//% y5 }2 q+ A. t: b# B* n
cout<<"--------------------------"<<endl;
) e* s m# a# m; g! ?( b* i3 @" z cout<<"Retrieving current colors"<<endl; l/ w5 O+ U' a F
CATListOfInt retrieveRed,retrieveGreen,retrieveBlue;
0 ^$ X5 r3 Q2 J2 o" _ 9 A/ x! t0 K0 N
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);3 @" C8 m Z) p1 d8 z, n+ `
if (E_FAIL == rc )5 N6 J8 ]9 u( Q+ D+ z) p- y
{) c, b! e: ?: B1 p" p# P/ S# C
cout<<"Error, an error occured while retrieving current part colors"<<endl;
& T1 y5 y S& Z/ D return 1;+ y9 H. I* M& X# H: t# c% l
}9 C. L; {, j/ i
& E/ h' M+ w# P' y- j7 N for (compt =1;compt<=nbfaces;compt++)- }9 m- a; Z7 ` O
{2 y- Z \. v; v3 Q, q8 z/ a, R
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
% J3 f5 l, e* H! z9 W: m. y' V }
$ x0 g/ w7 F5 u& X# q9 g8 {" d8 K+ }2 }1 D5 @& m
//
7 l @* q# m6 m- I //8 - Setting a new Color on all faces
0 N: a* ]' x7 p$ x //
# _5 y0 b" X+ n0 q* s! s2 g( W
4 O( |/ N! {/ E7 W5 F! A( R7 { //we are to color the faces with different color according their position : three by three will have the same color
4 o$ `5 e3 ?- \! }4 ?( e cout<<"--------------------------"<<endl;
' I, r9 L. Q/ v/ _9 J- {- q# k cout<<"Setting new colors"<<endl;
6 m4 c3 x, u& i9 j* z8 p& d3 _
* j, v7 k# T: b0 F# Y CATListOfInt newRed,newGreen,newBlue,FailedIndex;2 ~' q. ?( Q: O( ~& i b# h
int x=0;' x" s% B- _7 Z, s9 v6 V7 G
for (compt = 1;compt<= nbfaces;compt++)6 p. Q3 x3 }. J/ c; ]# [9 S* D
{
! ^: x! ?( D! Y/ l) F0 y x = compt%3;9 N" K' h( D% _# g; h* f
int red(0),green(0),blue(0);
; F- s" R$ `1 d7 T( G2 P) `! P if (1 == x)5 O6 B& b/ J# A" v8 l9 ]4 I
red = 255;
! ?3 b* O$ r1 ^3 { if (2 == x)# ]' l1 y+ R& R* U
green = 255;
/ ?1 Z W# k4 ~' w, @& M# y if (0 == x)
4 s) I% l& a1 b6 u/ u9 l blue = 255;
1 n- k A' |3 Z newRed.Append(red);
4 @6 O1 S; o6 V+ T9 X' k, m! g4 M newGreen.Append(green);
7 ?9 f9 S! f3 E$ U% W newBlue.Append (blue);
/ V4 c/ k; G+ T" \4 t3 h+ M. x7 _ cout<<"Setting R "<<red<<" G "<<green<<" B "<<blue<<" on the "<<compt<<" face"<<endl;
/ `7 N+ s! r: \$ W, d* G0 A }
5 P5 j- ^* J5 P! z6 n: K+ q+ F- K8 H6 U& `4 |, j4 S/ o
rc = CATMmrApplicativeAttributes::SetColorsOnFaces(ListBreps,newRed,newGreen,newBlue,FailedIndex);) u' ?! V) h# c# J
if (E_FAIL == rc)+ R; E F$ s: o) y
{
: i9 `% x; G# y- h0 c4 `" ~ cout<<"Error, setting new color on faces failed for all faces"<<endl;; ~$ P# a$ W$ B# y
return 1;
, o' \( x) B7 f }
9 m- J9 L/ c! n5 e else if (S_FALSE == rc )
( i; }5 Z0 |! x {
0 ? x; I6 k x7 R. {$ T int nberrors = FailedIndex.Size();
) x8 n" \/ N2 J' D% j& X cout<<"Error, setting new color on faces fails for faces :";; x5 D& U1 X& |& |. ?
for (compt = 1;compt<= FailedIndex.Size(); compt++)4 x' |0 M+ n% E
{1 A% C/ p# c- z
cout<<" "<<FailedIndex[compt];
3 {& o" d J" I& \9 v& s& k' o5 l% B }$ P7 ^5 `7 p0 w* R+ K7 R) D; D& z
cout<<endl;
$ C8 S5 U8 }$ q. O! d- ` }
/ J$ v0 \2 l* }7 ` else
8 S3 g, ^. _& S: U cout<<"Colors successfully set on every faces"<<endl;
( a$ l9 n) P7 ^( z% g1 x //
: E6 G: @- E2 a0 j% u: D$ L //9 - retrieving colors we have just set
5 W6 x6 x, g6 B; g1 C8 e //% X7 Q4 j! L T( i
cout<<"--------------------------"<<endl;4 `0 z$ u: }. Y
cout<<"Retrieving new colors"<<endl;9 A' V* A& f/ P2 v# h4 o
rc = CATMmrApplicativeAttributes::GetColorsOnFaces( ListBreps, retrieveRed,retrieveGreen,retrieveBlue);6 g) `( n5 y: b w7 m) u/ C
if (E_FAIL == rc ). Q3 B, d1 z0 i2 \+ }4 }
{
5 W; L2 G4 `0 n" k cout<<"Error, an error occured while retrieving current part colors"<<endl;
* i' e7 q: l, U) L8 `, c0 ]) Z- I4 I return 1;: M! K0 a* \( E; I& q3 e
}- m( C; _4 S/ l, r7 D
& u0 n& z6 t6 r( z' P( C for (compt =1;compt<=nbfaces;compt++)
+ \, U3 s* S, ?/ `4 S {) G& O7 C1 j- g6 Z! N% `- o( K
cout<<"for the "<<compt<<" face, associated color components are : R "<<retrieveRed[compt]<<" G "<<retrieveGreen[compt]<<" B "<<retrieveBlue[compt]<<endl;
! X3 n+ P$ ?1 m- \3 @2 s3 k& ^ }$ x# _, C4 B, t2 S n
5 x+ a2 C6 k S0 A5 k# H //. z$ {3 ?1 A Z. D- r8 n# g
//10 - Setting Applicative Attributes. K9 Z8 {2 w% P$ C1 }: o1 a# Y* e% Y( }
//
2 V4 p+ E+ @2 y$ [0 n1 f9 S& d& a4 U
//
% N' n; l0 _2 b0 N4 m //10 - 1 creating new attributes & P5 [8 l2 T1 u x" l
cout<<"--------------------------"<<endl;0 q ?* {' i* V7 h
cout<<"Creating applicative attributes for different faces"<<endl;+ `! V7 ~ v6 { l D! R* v U* K
CATListOfCATUnicodeString **AttrNameListToSet = new CATListOfCATUnicodeString*[nbfaces];
' @8 E( C. t V# S) D CATCkeListOfParm *AttrValueListToSet = new CATCkeListOfParm[nbfaces];: q1 Z# M4 Z8 ^
CATICkeParmFactory_var factory = CATCkeGlobalFunctions::GetVolatileFactory();4 j" _! n( v' k* ]% y3 ~
for (compt = 1;compt<= nbfaces;compt++)
8 u' W b$ F' {' U8 A {2 w E0 H/ t' j
cout<<"Creating ";+ |4 e: d& g# ?' z
x = compt%3;
" }, d0 L: u- H0 K9 X7 ` S //for each face we create a new list of apllicative attributes
) `, i: a' e7 F( r% g1 s //an applicative attribute is made of a Name and a value2 Z" r( L/ J5 O2 K- B) _
if (1 == x)
, Y, H6 m; Q1 J) r& } {
& R7 k9 z4 e8 J& i AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (3);
0 i' o3 D2 L0 T. Q7 |, Y* n AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(3);$ K% ]% L3 @! @7 o. s
6 p; T/ `+ E2 M' q- A. w3 O //The first attribute will be the number of the face( ?% {4 B3 j% \
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
" I& Q2 q* j% y7 R# { CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);( C' e; L2 S2 @/ W5 g0 V$ T. L# s4 C
AttrValueListToSet[compt-1]->Append(tempcke1);
( w6 N4 N/ n8 G# U+ T7 P6 J 0 I0 R. N: y1 ?5 G9 i
cout<<" FACE_NUMBER with value "<<compt;
7 Z: W/ S$ P! s/ n- b, f6 ]1 m& ]8 A6 J) d& z, v
//the second will be the color
4 M V" j @9 L# x2 m: V8 I AttrNameListToSet [compt-1]->Append("COLOR");
$ n, M; S4 ~3 a+ \. N, _ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Red");
3 O& F2 \1 Y7 r0 K. u AttrValueListToSet[compt-1]->Append(tempcke2);
0 {) L( T3 E% a, n9 [: ]* B! a3 v
9 ~1 D# j1 m& L2 e3 A cout<<" COLOR with value Red";
$ h7 o2 B! s* r$ o
5 b0 g9 R Z! c //the third is x! o0 H% F) v, T3 [+ W( W
AttrNameListToSet [compt-1]->Append("X"); B. ~. R* |" p$ t+ M; C
CATICkeParm_var tempcke3 = factory -> CreateReal ("X",x);
7 f ^/ T5 a# c7 J, O) A/ }. R2 h AttrValueListToSet[compt-1]->Append(tempcke3);
$ s" m% p; }! F; V& N6 \9 p" R
( x$ m7 G6 n/ G2 h O cout<<" X with value "<<x;
8 |5 i4 d: z7 H% V5 P cout<<" for face nb "<<compt<<endl;. f0 T, v7 W+ H' o
} G5 ]! h! W% O1 P3 O7 r# g
else
7 F! L8 v6 a" [, G q9 b //just to show you you can have different size of list
1 h; [+ ?2 ^0 H/ }- @. d% q3 r {
% V" L: w) R" K; c: I* e9 ^ AttrNameListToSet [compt-1] = new CATListOfCATUnicodeString (2);) ]% j# b+ ?: x, z' l j! ^
AttrValueListToSet[compt-1] = new CATLISTV(CATBaseUnknown_var)(2);. J3 |9 R. L7 g6 w* d
' p5 l6 d5 k: u2 [6 w //The first attribute will be the number of the face4 f# d) J# Q, P6 a6 b9 q( T+ c* `
AttrNameListToSet [compt-1]->Append("FACE_NUMBER");
0 w% D" C% ~; R3 w CATICkeParm_var tempcke1 = factory -> CreateInteger ("FACE_NUMBER",compt);4 U( u! S' R, B& h+ T6 }* R
AttrValueListToSet[compt-1]->Append(tempcke1);' G7 R- Q) O* D7 ~5 n7 {0 N* r
* `! B) a+ z: ]) }& b
cout<<" FACE_NUMBER with value "<<compt;
8 r3 D3 @; t, ]
3 {- S) M& T W: O4 [# i //the second will be the color, @& d9 y2 f8 r' r6 T
AttrNameListToSet [compt-1]->Append("COLOR");
3 @) W: r. Y1 W! {% {# \0 S; O! B& K if (2 == x)
. n% h c! x2 H* t1 F+ B {
i2 T# y( P9 C" S CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Green");
" o: j6 Y/ y) r1 b8 M) [ AttrValueListToSet[compt-1]->Append(tempcke2);7 p8 H2 C. A6 Y9 T3 b6 Y1 N
( j/ H4 V, a- W U. Q: ]
cout<<" COLOR with value Green";
. y6 K- J6 u, L r! i, Y }
- i4 N2 t7 o; C( p; `) V- D if (0 == x)/ D& G$ \1 ~, M* y4 {" m( z
{
( T2 P# z4 M" D7 K6 a' M" \ CATICkeParm_var tempcke2 = factory -> CreateString ("COLOR","Blue");2 M& w& A5 q3 s
AttrValueListToSet[compt-1]->Append(tempcke2);* L% b3 ~3 [& e" L, N( B+ `
/ J5 w' \1 L( c; e* T cout<<" COLOR with value Blue";" ~8 W' f) ?7 b
}- Q1 K) i. _7 i. S0 @8 L0 A
' m/ ^; |' a3 u; B; G9 R. _& h
cout<<" on face nb "<<compt<<endl;
2 j: |$ M* |3 B+ |. a* s) R; j6 W% f
% q8 V$ ?* J0 M! [& |8 a }
' {1 h. K# b0 ^2 H7 H }* |% N: j" s. t
0 J9 B# ]% `9 e2 O' Y" Q% ~" Q
//10 - 2 Setting the applicative attributes
( {3 q1 c5 ^( L$ M7 W1 [ cout<<endl<<"Setting applicative attributes on different faces"<<endl;7 Y& g: {" S$ E- @4 f
FailedIndex.RemoveAll();
( n0 {- s0 E) j$ j/ L% D rc=CATMmrApplicativeAttributes::SetAttributesOnFaces(ListBreps, AttrNameListToSet,AttrValueListToSet,FailedIndex);
' V, l! k% M% j* U4 H. n1 K4 N if (E_FAIL == rc)
; D' E' ~% X2 |5 [: p ]% M: J' O6 u5 [+ t {
e) s" Q* ]; G J6 D9 P$ z cout<<"Error, we failed to set applicative attributes on all faces"<<endl;
$ ~+ ~. Z( n4 o$ t; ?* H }
0 {- }( R) Z: A& Q9 d. F! T* A else if (S_FALSE == rc)- e1 n0 x" I# c9 K
{
* A# A+ n7 A4 ^+ m* |! |! T7 d int nberrors = FailedIndex.Size();0 R% I6 ?) e; I# K/ o
cout<<"Error, setting applicative attriutes on faces fails for faces :";
# w4 f% `! [- H( D8 E' I# n for (compt = 1;compt<= FailedIndex.Size(); compt++): o( f5 {5 n+ V7 V; }
{1 u! C1 S! u! {2 }3 Z' ^9 f, l
cout<<" "<<FailedIndex[compt]; m, g* a! [$ W! A) I. z1 W# @
}
* w$ j. K5 |3 ~ cout<<endl;. B- A) c) M! u6 p4 o" R) c7 T( Z
}
3 ~& ]5 s5 a" o Y/ e+ @ else
1 X# V2 j3 |: k% o {" a3 T* [: d' `0 B! P' d5 W
cout<<"Applicative attributes successfully set"<<endl;
& ]+ f& q$ L) u, h# R) r& @ }$ }& b6 t0 J' g. q( ]$ \* l4 X
# A3 z, J1 |8 g6 q4 M( P# H //10 - 3 cleaning$ Y! ^+ \3 Z, m& X/ |' _- r# `
for (compt=1; compt<=nbfaces;compt++)) X% Q2 j3 O% J9 f$ d
{
3 F I* Q+ [& _- b8 N AttrNameListToSet[compt-1]->RemoveAll(); delete AttrNameListToSet[compt-1]; AttrNameListToSet[compt-1] = NULL;4 Q/ T5 b, l( n
AttrValueListToSet[compt-1]->RemoveAll();delete AttrValueListToSet[compt-1]; AttrValueListToSet[compt-1] = NULL;
; ~% m. V% I+ F4 n' X g% e }) g4 Z# w4 d9 `/ G6 d+ b, `" x
' | E2 D8 M+ n0 p. C
delete [] AttrNameListToSet; AttrNameListToSet = NULL;# [% ]. V! j! |8 i: M9 q; Q
delete [] AttrValueListToSet;AttrValueListToSet = NULL;( A8 |+ f, f8 K/ ?2 @
, M1 p$ l+ K5 ^3 a$ q7 y) p! K9 ~ //0 N7 ?7 g; D1 Z& _* X
//11 - Retrieving the applicative attributes we have just set
' C: x( W/ J5 F6 G* |3 ^/ Y //8 O7 ?# i5 M4 A7 l
cout<<"--------------------------"<<endl;; O( M/ ]% ` T. v& o! c4 S
cout<<"Getting applicative attributes on faces"<<endl;
8 |; G6 C; s: b3 Y" X //
% V( ]; [6 [& a" h$ t- X! O y //11 - 1 Getting attributes
2 ^0 B$ ?/ a0 u1 _5 P, Y CATListOfCATUnicodeString * AttributNameList = new CATListOfCATUnicodeString[nbfaces];, q" C1 w" Q/ I1 P
CATCkeListOfParm AttrValList = new CATListValCATBaseUnknown_var[nbfaces];
2 @; D u: _, w9 f0 C6 ~5 q rc = CATMmrApplicativeAttributes::GetAttributesOnFaces(ListBreps, AttributNameList, AttrValList );' W- T2 Y: M' [6 W; j
if (SUCCEEDED(rc))
! O2 [5 B# o1 W) g+ q: v* ? {
8 D8 L" q) v8 ~$ A Y CATListOfCATUnicodeString templiststring;
2 K+ e+ D- D7 V2 h CATListValCATBaseUnknown_var tempCke;
9 v" ]% Z1 ~0 `1 [1 c/ ] for (compt=1;compt<=nbfaces;compt++)! A# t# ^/ x* h# I% y. Y* X
{
9 J* j; m4 O/ ` D8 E //retrieve a list a position k (arrays start at position zero).- ^' |+ O% ]2 U& [
templiststring = (AttributNameList)[compt-1];! _6 ~# {; [& }" y
tempCke = (AttrValList)[compt-1];
1 |9 n+ o5 D [& _
) K% b% `' c9 o' O% l7 Y3 L int nbAttributes = templiststring.Size();* P+ p" R% |: v# R' t' W
int nbValues = tempCke.Size();- L" q/ f+ z8 i8 {2 e2 S1 j
' L! m7 a* n: G: A# [ //the list must have the same size! If not, we jump to the next face. ]& f# P6 `: J$ f8 T
if (nbAttributes != nbValues)
0 o' [, k' g% K! J' K. w' y) [ {% s7 y0 S! x. Q# a5 N5 }2 z1 s; v
cout<<"Error on face "<<compt<<" : nbAttributes and nbValues are different"<<endl;
% X3 V. {) z1 b) x7 C continue;
+ j6 x- D) j& d! r7 o% m }
" Q5 h! |: ^+ Y6 a8 P else
2 R2 \/ _/ ~3 Y5 s2 v {
0 N- s! I) I3 G' c! U cout<<"For face "<<compt<<" there is(are) "<<nbAttributes<<" attribute(s) that is(are) : "<<endl;, {6 r F& M$ G% u2 l# B
}
* x `! n& [+ r for (int i=1;i<=nbAttributes;i++)
( A8 T( k" M/ a9 A2 @9 L2 D {
/ n5 H B; v7 l4 J+ k# i cout<<" - "<<templiststring.ConvertToChar()<<" = "<<((CATICkeParm_var)( tempCke ))->Content().ConvertToChar()<<endl;% |% w3 @/ O- l
}# _. @: P- d9 ~) c( R+ Z
templiststring.RemoveAll();
: b: e) }) C; D. H2 a8 h tempCke.RemoveAll();* m a$ K" J: E' c' i/ ?3 C8 O
& B5 K: D: w: H3 O. W) F
}8 P) o, L' i- u# ~6 _
}- C7 l6 z; w8 t7 h; ^( q* r/ O
else if (E_FAIL == rc)" f7 e4 L( X2 O) b3 v
{ V+ v5 }. q" R( l/ C# a
cout<<"Error, applicative attributes couldn't be retrieved"<<endl;
% F2 V. h# P) q return 1;; w. Z+ R( Z8 B' ?% g$ A+ j2 ?
}
' o+ Q. Q- L) j! u: w! Z, S //- Q' ?7 y/ ]3 R5 H$ W0 L
//11 - 2 Cleaning List:2 v# m# w3 v8 l$ A8 g
int i = 0;
. |' z- j. ^! {2 M" L. ` for (i=0; i < nbfaces;i++), t2 B. F" w- O- k4 R3 ]
{% c6 r* ^9 s) z
AttributNameList.RemoveAll();5 t6 F) Q( o3 X% Q7 E% f$ m
AttrValList.RemoveAll();
& ~/ @& d: j* K) \$ S5 J }
2 B2 B2 P ^- B, d' B }* Y delete [] AttributNameList; AttributNameList = NULL;
- O, J/ L& B# ]2 b2 _$ a' j1 z# B delete [] AttrValList; AttrValList = NULL;) }3 P) [6 A O9 j5 [& y; e
3 ]! H9 d {6 {1 J9 Z3 l6 Z/ p; ~( }
for (i = 1;i<= nbfaces;i++)
e3 }1 j$ m6 n7 \- X" h, W( k {: r8 I0 k$ B1 b- R( }' j1 [& z7 r3 d
Brep = ListBreps ;
/ t( |; l8 G. K4 _5 Y if (NULL != Brep)- ]# g+ e4 T5 G6 }; b9 ?6 K
{, s! K4 E. i# z2 |) i/ r9 x4 Z& Q& r
Brep->Release();" W- G- p/ C- q5 q6 A% B4 [3 ^
}0 h: s3 Q/ @4 ~& w( |
}
! ^2 Q$ V) m, d8 W4 P ListBreps.RemoveAll();[/mw_shl_code]
) O5 }/ e$ F4 `6 ^4 c4 {7 d |
|