0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_def_highlight_color.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18
19 #include <Xw_Extension.h>
20
21 /* ifdef then trace on */
22 #ifdef TRACE
23 #define TRACE_DEF_HIGHLIGHT_COLOR
24 #endif
25
26 /*
27    STATUS Xw_def_highlight_color(acolormap,r,g,b):
28    XW_EXT_COLORMAP *acolormap
29    float r,g,b ;        Red,Green,Blue color value 0. >= x <= 1.
30
31         Update Highlight Color index with the specified R,G,B values .
32         NOTE than highlight color is shared between all Windows
33
34         Returns ERROR if Extended Colormap is not properly defined
35         Returns SUCCESS if Successful      
36
37 */
38
39 #ifdef XW_PROTOTYPE
40 XW_STATUS Xw_def_highlight_color (void* acolormap,
41                                         float r,float g,float b)
42 #else
43 XW_STATUS Xw_def_highlight_color (acolormap,r,g,b)
44 void *acolormap;
45 float r,g,b ;
46 #endif /*XW_PROTOTYPE*/
47 {
48 XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap ;
49 XColor color ;
50 int i,cclass,index = -1,isapproximate ;
51 XW_STATUS status = XW_SUCCESS;
52 unsigned long highpixel;
53
54         if ( !Xw_isdefine_colormap(pcolormap) ) {
55              /*ERROR*Bad EXT_COLORMAP Address*/
56              Xw_set_error(42,"Xw_def_highlight_color",pcolormap) ;
57              return (XW_ERROR) ;
58         }
59
60         if( pcolormap->mapping == Xw_TOM_READONLY ) { 
61           cclass = StaticColor; 
62         } else { 
63           cclass = _CCLASS; 
64         }
65
66         switch ( cclass ) {
67             
68             case TrueColor :
69                 Xw_get_color_pixel(pcolormap,r,g,b,&highpixel,&isapproximate) ;
70                 break ;
71
72             case PseudoColor :
73                 if( pcolormap->mapping == Xw_TOM_COLORCUBE ) {
74                     if( (_CGINFO.red_mult > 0) && (fabs(r-g) < 0.01) && (fabs(r-b) < 0.01) ) {
75                       index = (int)(0.5+r*_CGINFO.red_max)*_CGINFO.red_mult;
76                       if( _CINFO.red_max > 0 ) 
77                                 index += (_CINFO.red_max+1)*(_CINFO.green_max+1)*(_CINFO.blue_max+1);
78                     } else if( _CINFO.red_mult > 0 ) {
79                       index = ((int)(0.5+r*_CINFO.red_max))*_CINFO.red_mult+
80                             ((int)(0.5+g*_CINFO.green_max))*_CINFO.green_mult+
81                             ((int)(0.5+b*_CINFO.blue_max))*_CINFO.blue_mult;
82                     } else if( _CGINFO.red_mult > 0 ) {
83                       float l = (r+g+b)/3.;
84                       index = (int)(0.5+l*_CGINFO.red_max)*_CGINFO.red_mult;
85                     } else {
86                       index = 0;
87                     }
88                     highpixel = _CINFO.base_pixel + index ;
89                 } else if( pcolormap->mapping == Xw_TOM_BESTRAMP ) {
90                     color.red   = (unsigned short) (r * 0xFFFF) ;
91                     color.green = (unsigned short) (g * 0xFFFF) ;
92                     color.blue  = (unsigned short) (b * 0xFFFF) ;
93                     color.flags = DoRed|DoGreen|DoBlue ;
94                     for( i=0 ; i<pcolormap->maxcolor ; i++ ) {
95                       if( (pcolormap->pixels[i] & 1) &&
96                             ((pcolormap->define[i] == FREECOLOR) ||
97                              (pcolormap->define[i] == HIGHCOLOR)) ) {
98                          pcolormap->define[i] = HIGHCOLOR ;
99                          color.pixel =  pcolormap->pixels[i] ;
100                          XStoreColor(_CDISPLAY,_CINFO.colormap,&color) ;
101                        }
102                     }
103                     highpixel = pcolormap->pixels[1];
104                 } else if( pcolormap->mapping == Xw_TOM_SIMPLERAMP ) {
105                     Xw_get_color_index(pcolormap,r,g,b,&index) ;
106                     highpixel = _CINFO.base_pixel + index ;
107                 }
108                 break ;
109
110             case StaticColor :
111                 status = Xw_alloc_color(pcolormap,r,g,b,&highpixel,&isapproximate) ;
112                 break ;
113         }
114
115         if( status ) {
116           if( index >= 0 ) {
117             pcolormap->define[index] = HIGHCOLOR ;
118           }
119           pcolormap->highpixel  = highpixel ;
120 #ifdef BUG_PRO3709
121           Xw_reset_attrib(NULL) ;
122 #endif
123         }
124
125 #ifdef TRACE_DEF_HIGHLIGHT_COLOR
126 if( Xw_get_trace() ) {
127     printf(" %d = Xw_def_highlight_color(%lx,%f,%f,%f)\n",status,(long ) pcolormap,r,g,b) ;
128 }
129 #endif
130         return (status);
131 }