1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #define PRO7349 //GG_11/04/97
20 // Modification de la methode PixelOfColor
21 // qui renvoie maintenant un numero de pixel negatif
22 // lorsqu'il correspond a une couleur approximee.
24 #define PRO10676 //GG_151297
25 // Permettre de reserver un index de couleur modifiable
28 #include <Xw_ColorMap.ixx>
29 #include <Quantity_Color.hxx>
30 #include <Standard_ShortReal.hxx>
31 #include <Standard_PCharacter.hxx>
33 // Routines C a declarer en extern
35 #include <Xw_Cextern.hxx>
38 //-Static data definitions
40 static XW_STATUS status ;
42 void Xw_ColorMap::PrintError() {
43 Standard_CString ErrorMessag ;
44 Standard_Integer ErrorNumber ;
45 Standard_Integer ErrorGravity ;
48 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
49 if( ErrorGravity > 2 ) Aspect_ColorMapDefinitionError::Raise (ErrorMessag) ;
50 else Xw_print_error() ;
53 Xw_ColorMap::Xw_ColorMap () {
56 Xw_ColorMap::Xw_ColorMap (const Standard_CString Connexion, const Xw_TypeOfVisual Visual, const Xw_TypeOfMapping Mapping, const Standard_Integer Ncolors, const Standard_Boolean UseDefault) {
57 Aspect_Handle BaseMap = 0 ;
59 MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ;
61 if( !MyExtendedDisplay ) PrintError() ;
64 Aspect_Handle *display,root ;
65 Xw_TypeOfVisual vclass ;
68 status = Xw_get_display_info (MyExtendedDisplay,
69 &display,&root,&BaseMap,&vclass,&depth);
70 if( Visual != vclass ) BaseMap = 0;
73 MyExtendedColorMap = Xw_def_colormap(MyExtendedDisplay,
74 Visual,Ncolors,BaseMap,Mapping) ;
76 if( !Xw_isdefine_colormap(MyExtendedColorMap) ) PrintError() ;
78 MyExtendedOverlayColorMap = Xw_def_colormap(MyExtendedDisplay,
79 Xw_TOV_OVERLAY,0,0,Xw_TOM_READONLY) ;
81 SetHighlightColor(Quantity_NOC_WHITESMOKE) ;
86 void Xw_ColorMap::SetEntry (const Standard_Integer Index,const Standard_Real Red, const Standard_Real Green, const Standard_Real Blue) {
89 switch ( MyMapping ) {
92 case Xw_TOM_SIMPLERAMP:
94 status = Xw_def_color(MyExtendedColorMap,
95 (int)Index,(float)Red,(float)Green,(float)Blue) ;
97 if( !status ) PrintError() ;
100 case Xw_TOM_COLORCUBE:
101 case Xw_TOM_READONLY:
102 Aspect_BadAccess::Raise ("Try to write in a READ ONLY colormap");
107 void Xw_ColorMap::SetEntry (const Aspect_ColorMapEntry& Entry) {
108 Standard_Real r,g,b ;
110 (Entry.Color()).Values(r,g,b,Quantity_TOC_RGB) ;
112 SetEntry(Entry.Index(),r,g,b) ;
116 void Xw_ColorMap::SetEntries (const Handle(Aspect_ColorMap)& Colormap) {
117 Standard_Integer size = Colormap->Size() ;
120 for( i=1 ; i<=size ; i++ ) {
121 SetEntry(Colormap->Entry(i)) ;
125 void Xw_ColorMap::SetHighlightColor ( const Quantity_Color& aColor) {
126 Standard_Real r,g,b ;
128 aColor.Values(r,g,b,Quantity_TOC_RGB) ;
130 status = Xw_def_highlight_color(MyExtendedColorMap,
131 (float)r,(float)g,(float)b) ;
132 if( !status ) PrintError() ;
134 if( MyExtendedOverlayColorMap ) {
135 status = Xw_def_highlight_color(MyExtendedOverlayColorMap,
136 (float)r,(float)g,(float)b) ;
137 if( !status ) PrintError() ;
141 void Xw_ColorMap::Destroy() {
143 if( MyExtendedColorMap ) {
144 Xw_close_colormap(MyExtendedColorMap) ;
145 MyExtendedColorMap = NULL ;
148 if( MyExtendedOverlayColorMap ) {
149 Xw_close_colormap(MyExtendedOverlayColorMap) ;
150 MyExtendedOverlayColorMap = NULL ;
154 Quantity_Color Xw_ColorMap::HighlightColor ( ) const {
157 status = Xw_get_highlight_color (MyExtendedColorMap,&r,&g,&b);
159 Standard_Real Red = r;
160 Standard_Real Green = g;
161 Standard_Real Blue = b;
163 return Quantity_Color(Red,Green,Blue,Quantity_TOC_RGB) ;
166 Standard_Integer Xw_ColorMap::HighlightPixel ( ) const {
167 unsigned long pixel ;
169 status = Xw_get_highlight_pixel(MyExtendedColorMap,&pixel) ;
171 if( !status ) PrintError() ;
173 return (Standard_Integer(pixel)) ;
176 Standard_Integer Xw_ColorMap::PixelOfColor ( const Quantity_Color &aColor ) const {
177 Standard_Real Red,Green,Blue ;
178 unsigned long pixel ;
179 Standard_Integer isapproximate;
181 aColor.Values(Red,Green,Blue,Quantity_TOC_RGB) ;
184 status = Xw_get_color_pixel(MyExtendedColorMap,
185 (float)Red,(float)Green,(float)Blue,&pixel,&isapproximate) ;
186 if( !status ) PrintError() ;
188 if( isapproximate ) return (-Standard_Integer(pixel));
190 else return (Standard_Integer(pixel)) ;
192 status = Xw_get_color_pixel(MyExtendedColorMap,
193 (float)Red,(float)Green,(float)Blue,&pixel) ;
195 if( !status ) PrintError() ;
197 return (Standard_Integer(pixel)) ;
202 Standard_Integer Xw_ColorMap::AllocatesPixelOfColor ( ) const {
204 if( Xw_alloc_pixel(MyExtendedColorMap,&pixel) )
205 return Standard_Integer(pixel);
212 void Xw_ColorMap::FreePixelOfColor ( const Standard_Integer aPixel ) const {
213 unsigned long pixel = aPixel;
214 Xw_free_pixel(MyExtendedColorMap,pixel);
217 Standard_Boolean Xw_ColorMap::SetColorOfPixel ( const Standard_Integer aPixel,
218 const Quantity_Color &aColor ) const {
219 Standard_Real Red,Green,Blue ;
220 aColor.Values(Red,Green,Blue,Quantity_TOC_RGB) ;
221 Standard_ShortReal r = Red,g = Green,b = Blue;
222 unsigned long pixel = aPixel;
223 return Xw_set_pixel(MyExtendedColorMap,pixel,r,g,b);
227 Standard_Integer Xw_ColorMap::Entry ( const Standard_Integer Index, Standard_Real &Red, Standard_Real &Green, Standard_Real &Blue ) const {
228 unsigned long pixel = 0 ;
229 float red,green,blue ;
231 status = Xw_get_color(MyExtendedColorMap,Index,
232 &red,&green,&blue,&pixel) ;
234 if( !status ) PrintError() ;
236 Red = red; Green = green; Blue = blue;
238 return (Standard_Integer(pixel)) ;
241 Xw_TypeOfVisual Xw_ColorMap::VisualClass( ) const {
242 Xw_TypeOfVisual vclass ;
244 vclass = Xw_get_colormap_visual(MyExtendedColorMap) ;
246 if( vclass == Xw_TOV_DEFAULT ) PrintError() ;
251 Xw_TypeOfVisual Xw_ColorMap::OverlayVisualClass( ) const {
252 Xw_TypeOfVisual vclass = Xw_TOV_DEFAULT;
254 if( MyExtendedOverlayColorMap ) {
255 vclass = Xw_get_colormap_visual(MyExtendedOverlayColorMap) ;
261 Standard_Integer Xw_ColorMap::VisualID( ) const {
262 Aspect_Handle *VisualInfo ;
263 Xw_TypeOfVisual VisualClass ;
264 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid = 0 ;
266 status = Xw_get_colormap_info(MyExtendedColorMap,&VisualInfo,
267 &VisualClass,&visualid,&MaxColor,&BasePixel,
268 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
270 if( !status ) Xw_print_error();
275 Standard_Integer Xw_ColorMap::OverlayVisualID( ) const {
276 Aspect_Handle *VisualInfo ;
277 Xw_TypeOfVisual VisualClass ;
278 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid = 0;
280 if( MyExtendedOverlayColorMap ) {
281 status = Xw_get_colormap_info(MyExtendedOverlayColorMap,&VisualInfo,
282 &VisualClass,&visualid,&MaxColor,&BasePixel,
283 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
285 if( !status ) Xw_print_error() ;
290 Standard_Integer Xw_ColorMap::MaxColors( ) const {
291 Aspect_Handle *VisualInfo ;
292 Xw_TypeOfVisual VisualClass ;
293 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid ;
295 status = Xw_get_colormap_info(MyExtendedColorMap,&VisualInfo,
296 &VisualClass,&visualid,&MaxColor,&BasePixel,
297 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
300 if( VisualClass == Xw_TOV_TRUECOLOR ) return MaxColor ;
301 else return MaxUserColor;
308 Standard_Integer Xw_ColorMap::MaxOverlayColors( ) const {
309 Aspect_Handle *VisualInfo ;
310 Xw_TypeOfVisual VisualClass ;
311 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid ;
314 if( MyExtendedOverlayColorMap ) {
315 status = Xw_get_colormap_info(MyExtendedOverlayColorMap,&VisualInfo,
316 &VisualClass,&visualid,&MaxColor,&BasePixel,
317 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
318 if( !status ) Xw_print_error() ;
321 return (status) ? MaxUserColor : 0;
324 Standard_Address Xw_ColorMap::XVisual( ) const {
325 Aspect_Handle *VisualInfo ;
326 Xw_TypeOfVisual VisualClass ;
327 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid ;
329 status = Xw_get_colormap_info(MyExtendedColorMap,&VisualInfo,
330 &VisualClass,&visualid,&MaxColor,&BasePixel,
331 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
333 if( !status ) PrintError() ;
335 return (VisualInfo) ;
338 Standard_Address Xw_ColorMap::XOverlayVisual( ) const {
339 Aspect_Handle *VisualInfo = NULL ;
340 Xw_TypeOfVisual VisualClass ;
341 int MaxColor,BasePixel,MaxUserColor,MaxDefineColor,FirstFreeColorIndex,visualid ;
344 if( MyExtendedOverlayColorMap ) {
345 status = Xw_get_colormap_info(MyExtendedOverlayColorMap,&VisualInfo,
346 &VisualClass,&visualid,&MaxColor,&BasePixel,
347 &MaxUserColor,&MaxDefineColor,&FirstFreeColorIndex) ;
348 if( !status ) Xw_print_error() ;
351 return (status) ? VisualInfo : NULL ;
354 Aspect_Handle Xw_ColorMap::XColorMap( ) const {
355 Aspect_Handle colormap ;
357 colormap = Xw_get_colormap_xid(MyExtendedColorMap) ;
359 if( !colormap ) PrintError() ;
364 Aspect_Handle Xw_ColorMap::XOverlayColorMap( ) const {
365 Aspect_Handle colormap = 0;
367 if( MyExtendedOverlayColorMap ) {
368 colormap = Xw_get_colormap_xid(MyExtendedOverlayColorMap) ;
374 Standard_Address Xw_ColorMap::ExtendedColorMap () const {
376 return (MyExtendedColorMap);
380 Standard_Address Xw_ColorMap::ExtendedOverlayColorMap () const {
382 return (MyExtendedOverlayColorMap);
386 Standard_Boolean Xw_ColorMap::XColorCube ( Aspect_Handle &ColormapID,
387 Standard_Integer &VisualID,
388 Standard_Integer &BasePixel,
389 Standard_Integer &RedMax,
390 Standard_Integer &RedMult,
391 Standard_Integer &GreenMax,
392 Standard_Integer &GreenMult,
393 Standard_Integer &BlueMax,
394 Standard_Integer &BlueMult ) const
397 status = Xw_get_colormap_colorcube(MyExtendedColorMap,
398 &ColormapID,&VisualID,&BasePixel,
399 &RedMax,&RedMult,&GreenMax,&GreenMult,&BlueMax,&BlueMult);
405 Standard_Boolean Xw_ColorMap::XGrayRamp ( Aspect_Handle &ColormapID,
406 Standard_Integer &VisualID,
407 Standard_Integer &BasePixel,
408 Standard_Integer &GrayMax,
409 Standard_Integer &GrayMult) const
412 status = Xw_get_colormap_grayramp(MyExtendedColorMap,
413 &ColormapID,&VisualID,&BasePixel,&GrayMax,&GrayMult);