0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_get_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_GET_HIGHLIGHT_COLOR
24 #define TRACE_GET_HIGHLIGHT_PIXEL
25 #endif
26
27 /*
28    XW_STATUS Xw_get_highlight_color(acolormap,r,g,b):
29    XW_EXT_COLORMAP *acolormap   Colormap extension structure
30    float *r,*g,*b ;             Returns Red,Green,Blue color value 0. >= x <= 1.
31
32         Get R,G,B Highlight Color values from Default index .
33
34         Returns ERROR if Extended Colormap Address is badly defined
35         Returns SUCCESS if Successful      
36
37    XW_STATUS Xw_get_highlight_pixel(acolormap,pixel):
38    XW_EXT_COLORMAP *acolormap   Colormap extension structure
39    unsigned long *pixel;        Returns HighLight pixel
40
41 */
42
43 #ifdef XW_PROTOTYPE
44 XW_STATUS Xw_get_highlight_color (void* acolormap,
45                                         float* r,float* g,float* b)
46 #else
47 XW_STATUS Xw_get_highlight_color (acolormap,r,g,b)
48 void *acolormap;
49 float *r,*g,*b ;
50 #endif /*XW_PROTOTYPE*/
51 {
52 XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
53 XColor color ;
54
55         if ( !Xw_isdefine_colormap(pcolormap) ) {
56             /*ERROR*Bad EXTENDED Colormap ADDRESS*/
57             Xw_set_error(42,"Xw_get_highlight_color",pcolormap) ;
58             return (XW_ERROR) ;
59         }
60
61         switch ( _CCLASS ) {
62
63           case PseudoColor :
64           case StaticColor :
65             color.pixel = pcolormap->highpixel ;
66             XQueryColor(_CDISPLAY,_CINFO.colormap,&color) ;
67             *r = (float)color.red/0xFFFF ;
68             *g = (float)color.green/0xFFFF ;
69             *b = (float)color.blue/0xFFFF ;
70             break ;
71
72           case TrueColor :
73             { unsigned long mask = _CVISUAL->map_entries-1 ;
74               unsigned long red,green,blue ;
75               unsigned long rmask = _CVISUAL->red_mask ;
76               unsigned long gmask = _CVISUAL->green_mask ;
77               unsigned long bmask = _CVISUAL->blue_mask ;
78
79               color.pixel = pcolormap->highpixel ;
80               red = color.pixel & rmask ;
81               while ( !(rmask & 0x01) ) { rmask >>= 1; red >>= 1; }
82  
83               green = color.pixel & gmask ;
84               while ( !(gmask & 0x01) ) { gmask >>= 1; green >>= 1; }
85  
86               blue = color.pixel & bmask ;
87               while ( !(bmask & 0x01) ) { bmask >>= 1; blue >>= 1; }
88  
89               *r = (float)red/mask ;
90               *g = (float)green/mask ;
91               *b = (float)blue/mask ;
92             }
93             break ;
94
95             default :
96               /*Unmatchable Visual class*/
97               Xw_set_error(67,"Xw_get_highlight_color",&_CCLASS) ;
98               return (XW_ERROR) ;
99         }
100
101
102
103 #ifdef TRACE_GET_HIGHLIGHT_COLOR
104 if( Xw_get_trace() > 1 ) {
105     printf(" Xw_get_highlight_color(%lx,%f,%f,%f)\n",(long ) pcolormap,*r,*g,*b) ;
106 }
107 #endif
108
109         return (XW_SUCCESS);
110 }
111
112 #ifdef XW_PROTOTYPE
113 XW_STATUS Xw_get_highlight_pixel (void* acolormap,unsigned long *pixel)
114 #else
115 XW_STATUS Xw_get_highlight_pixel (acolormap,pixel)
116 void *acolormap;
117 unsigned long *pixel;
118 #endif /*XW_PROTOTYPE*/
119 {
120 XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
121 //XColor color ;
122
123         if ( !Xw_isdefine_colormap(pcolormap) ) {
124             /*ERROR*Bad EXTENDED Colormap ADDRESS*/
125             Xw_set_error(42,"Xw_get_highlight_pixel",pcolormap) ;
126             return (XW_ERROR) ;
127         }
128
129         *pixel = pcolormap->highpixel ;
130
131 #ifdef TRACE_GET_HIGHLIGHT_PIXEL
132 if( Xw_get_trace() > 1 ) {
133     printf(" Xw_get_highlight_pixel(%lx,%lx)\n",(long ) pcolormap,*pixel) ;
134 }
135 #endif
136
137         return (XW_SUCCESS);
138 }