1 // Created on: 2000-08-16
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 
17 #include <IGESCAFControl.hxx>
18 #include <Quantity_Color.hxx>
19 
20 //=======================================================================
21 //function : DecodeColor
22 //purpose  :
23 //=======================================================================
DecodeColor(const Standard_Integer color)24 Quantity_Color IGESCAFControl::DecodeColor (const Standard_Integer color)
25 {
26   switch ( color ) {
27   case 1: return Quantity_Color ( Quantity_NOC_BLACK );
28   case 2: return Quantity_Color ( Quantity_NOC_RED );
29   case 3: return Quantity_Color ( Quantity_NOC_GREEN );
30   case 4: return Quantity_Color ( Quantity_NOC_BLUE1 );
31   case 5: return Quantity_Color ( Quantity_NOC_YELLOW );
32   case 6: return Quantity_Color ( Quantity_NOC_MAGENTA1 );
33   case 7: return Quantity_Color ( Quantity_NOC_CYAN1 );
34   case 8:
35   default:return Quantity_Color ( Quantity_NOC_WHITE );
36   }
37 }
38 
39 //=======================================================================
40 //function : DecodeColor
41 //purpose  :
42 //=======================================================================
43 
EncodeColor(const Quantity_Color & col)44 Standard_Integer IGESCAFControl::EncodeColor (const Quantity_Color &col)
45 {
46   Standard_Integer code = 0;
47   if ( Abs ( col.Red() - 1. ) <= col.Epsilon() ) code |= 0x001;
48   else if ( Abs ( col.Red() ) > col.Epsilon() ) return 0;
49   if ( Abs ( col.Green() - 1. ) <= col.Epsilon() ) code |= 0x010;
50   else if ( Abs ( col.Green() ) > col.Epsilon() ) return 0;
51   if ( Abs ( col.Blue() - 1. ) <= col.Epsilon() ) code |= 0x100;
52   else if ( Abs ( col.Blue() ) > col.Epsilon() ) return 0;
53 
54   switch ( code ) {
55   case 0x000: return 1;
56   case 0x001: return 2;
57   case 0x010: return 3;
58   case 0x100: return 4;
59   case 0x011: return 5;
60   case 0x101: return 6;
61   case 0x110: return 7;
62   case 0x111:
63   default   : return 8;
64   }
65 }
66