0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_open_pixmap.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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <Xw_Extension.h>
23
24 #ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H
25 # include <X11/extensions/multibuf.h>
26 #endif
27
28         /* ifdef then trace on */
29 #ifdef TRACE
30 #define TRACE_OPEN_PIXMAP
31 #define TRACE_OPEN_BACKGROUND_PIXMAP
32 #define TRACE_CLOSE_PIXMAP
33 #define TRACE_CLOSE_BACKGROUND_PIXMAP
34 #endif
35
36 /*
37    XW_STATUS Xw_open_pixmap (awindow)
38    XW_EXT_WINDOW *awindow
39
40         Open a DoubleBuffer PIXMAP depending of the Window size
41
42         returns ERROR if NO More PIXMAP is available on this Window
43         returns SUCCESS if successful
44
45    XW_STATUS Xw_open_background_pixmap (awindow)
46    XW_EXT_WINDOW *awindow
47
48         Open a Background PIXMAP depending of the Window size
49
50         returns ERROR if NO More PIXMAP is available on this Window
51         returns SUCCESS if successful
52
53    XW_STATUS Xw_close_pixmap (awindow)
54    XW_EXT_WINDOW *awindow
55
56         Close the DoubleBuffer PIXMAP attached to this Window
57
58         returns ERROR if NO More PIXMAP exist
59         returns SUCCESS if successful
60
61    XW_STATUS Xw_close_background_pixmap (awindow)
62    XW_EXT_WINDOW *awindow
63
64         Close the Background PIXMAP attached to this Window
65
66         returns ERROR if NO More PIXMAP exist
67         returns SUCCESS if successful
68 */
69
70 static char SetDoubleBuffer = '\0' ;
71
72 #ifdef XW_PROTOTYPE
73 XW_STATUS Xw_open_pixmap (void *awindow)
74 #else
75 XW_STATUS Xw_open_pixmap (awindow)
76 void *awindow;
77 #endif /*XW_PROTOTYPE*/
78 {
79 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
80 XW_EXT_DISPLAY *pdisplay = pwindow->connexion;
81 int error,gravity ;
82 char svalue[4] ;
83 XW_STATUS status = XW_ERROR;
84
85     if( !Xw_isdefine_window(pwindow) ) {
86         /*ERROR*Bad EXT_WINDOW Address*/
87         Xw_set_error(24,"Xw_open_pixmap",pwindow) ;
88         return (XW_ERROR) ;
89     }
90
91     if( SetDoubleBuffer == '\0' ) {
92         SetDoubleBuffer = 'U' ;
93         if( Xw_get_env("Xw_SET_DOUBLE_BUFFER",svalue,sizeof(svalue)) ) {
94             if( strlen(svalue) ) {
95                 SetDoubleBuffer = svalue[0] ;
96             }
97             printf(" Xw_SET_DOUBLE_BUFFER is '%c'\n",SetDoubleBuffer) ;
98         }
99     }
100
101     if( (SetDoubleBuffer == 'B') && 
102                 (pdisplay->server == XW_SERVER_IS_SUN) && (_DEPTH != 24) ) {
103         SetDoubleBuffer = 'P';  /* BUG sur SUN */
104         /*WARNING*MultiBufferingExtension is not accessible here*/
105         Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
106     }
107
108 #ifndef HAVE_X11_EXTENSIONS_MULTIBUF_H
109     if( SetDoubleBuffer == 'B' ) {
110         SetDoubleBuffer = 'P';  /* MULTIBUF unavailable under SGI IRIX 6.5 */
111         /*WARNING*MultiBufferingExtension is not accessible here*/
112         Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
113     }
114 #else
115     if( SetDoubleBuffer == 'B' ) {
116       if( _NWBUFFER == 0 ) {
117         int mOptCode,fEvent,fError,maxmono,maxstereo ;
118         XmbufBufferInfo *pmono,*pstereo ;
119         if( XQueryExtension(_DISPLAY,"Multi-Buffering",
120                                 &mOptCode,&fEvent,&fError) && 
121                 XmbufGetScreenInfo(_DISPLAY,_WINDOW,
122                                 &maxmono,&pmono,&maxstereo,&pstereo) ) {
123           _NWBUFFER = XmbufCreateBuffers(_DISPLAY,_WINDOW,2,
124                                         MultibufferUpdateActionUntouched,
125                                         MultibufferUpdateHintFrequent,
126                                         &_FWBUFFER) ;
127         } 
128         if( _NWBUFFER == 2 ) {
129           XFillRectangle(_DISPLAY,_BWBUFFER,pwindow->qgwind.gcclear,
130                                                 0,0,_WIDTH,_HEIGHT) ;
131         } else {
132           if( _NWBUFFER > 0 ) XmbufDestroyBuffers(_DISPLAY,_WINDOW) ;
133           _NWBUFFER = 0 ;
134           _BWBUFFER = 0 ;
135           _FWBUFFER = 0 ;
136         }
137         SetDoubleBuffer = 'P';
138         /*WARNING*MultiBufferingExtension is not accessible here*/
139         Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
140       }
141     }
142 #endif
143  
144     if( (SetDoubleBuffer == 'U') || 
145                 (SetDoubleBuffer == 'Y') || 
146                         (SetDoubleBuffer == 'P') ) { 
147       if( !_PIXMAP ) {
148         Xw_print_error();
149         if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,True) ;
150         _PIXMAP = XCreatePixmap(_DISPLAY,_WINDOW,_WIDTH,_HEIGHT,_DEPTH) ;
151         if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,False) ;
152
153         Xw_get_error(&error,&gravity);
154         if( _PIXMAP && (error < 1000) ) {
155           XFillRectangle(_DISPLAY,_PIXMAP,pwindow->qgwind.gcclear,
156                                                 0,0,_WIDTH,_HEIGHT) ;
157         } else {
158           /*ERROR*DISABLE Double Buffer*/
159           _PIXMAP = 0 ;
160           Xw_set_error(71,"Xw_open_pixmap",0) ;
161         }
162       }
163     } 
164
165     if( _PIXMAP || _NWBUFFER ) status = XW_SUCCESS;
166
167 #ifdef TRACE_OPEN_PIXMAP
168 if( Xw_get_trace() ) {
169     printf(" %d = Xw_open_pixmap(%lx)\n",status,(long ) pwindow) ;
170 }
171 #endif
172         
173     return (status);
174 }
175
176 #ifdef XW_PROTOTYPE
177 XW_STATUS Xw_close_pixmap (void *awindow)
178 #else
179 XW_STATUS Xw_close_pixmap (awindow)
180 void *awindow;
181 #endif /*XW_PROTOTYPE*/
182 {
183 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
184
185     if( !Xw_isdefine_window(pwindow) ) {
186         /*ERROR*Bad EXT_WINDOW Address*/
187         Xw_set_error(24,"Xw_open_pixmap",pwindow) ;
188         return (XW_ERROR) ;
189     }
190
191 #ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H 
192     if( _NWBUFFER > 0 ) XmbufDestroyBuffers(_DISPLAY,_WINDOW) ;
193 #endif
194     if( _PIXMAP ) XFreePixmap(_DISPLAY,_PIXMAP) ;
195     XFlush(_DISPLAY) ;
196     _PIXMAP = 0 ;
197     _NWBUFFER = 0 ;
198     _BWBUFFER = 0 ;
199     _FWBUFFER = 0 ;
200     _DRAWABLE = _WINDOW ;
201  
202 #ifdef TRACE_CLOSE_PIXMAP
203 if( Xw_get_trace() ) {
204     printf(" Xw_close_pixmap(%lx)\n",(long ) pwindow) ;
205 }
206 #endif
207
208     return XW_SUCCESS ;
209 }
210
211 #ifdef XW_PROTOTYPE
212 XW_STATUS Xw_open_background_pixmap (void *awindow)
213 #else
214 XW_STATUS Xw_open_background_pixmap (awindow)
215 void *awindow;
216 #endif /*XW_PROTOTYPE*/
217 {
218 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
219 int error,gravity ;
220
221     if( !Xw_isdefine_window(pwindow) ) {
222         /*ERROR*Bad EXT_WINDOW Address*/
223         Xw_set_error(24,"Xw_open_background_pixmap",pwindow) ;
224         return (XW_ERROR) ;
225     }
226
227     if( _BPIXMAP ) Xw_close_background_pixmap(awindow) ; 
228
229     Xw_print_error();
230     if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,True) ;
231     _BPIXMAP = XCreatePixmap(_DISPLAY,_WINDOW,_WIDTH,_HEIGHT,_DEPTH) ;
232     if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,False) ;
233
234     Xw_get_error(&error,&gravity);
235     if( !_BPIXMAP || (error >= 1000) ) {
236         /*ERROR*DISABLE Double Buffer*/
237         _BPIXMAP = 0 ;
238         Xw_set_error(71,"Xw_open_background_pixmap",0) ;
239         return (XW_ERROR) ;
240     }
241
242     XFillRectangle(_DISPLAY,_BPIXMAP,pwindow->qgwind.gcclear,0,0,_WIDTH,_HEIGHT);
243
244 #ifdef TRACE_OPEN_BACKGROUND_PIXMAP
245 if( Xw_get_trace() ) {
246     printf(" Xw_open_background_pixmap(%lx)\n",(long ) pwindow) ;
247 }
248 #endif
249         
250     return (XW_SUCCESS);
251 }
252
253 #ifdef XW_PROTOTYPE
254 XW_STATUS Xw_close_background_pixmap (void *awindow)
255 #else
256 XW_STATUS Xw_close_background_pixmap (awindow)
257 void *awindow;
258 #endif /*XW_PROTOTYPE*/
259 {
260 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
261
262     if( !Xw_isdefine_window(pwindow) ) {
263         /*ERROR*Bad EXT_WINDOW Address*/
264         Xw_set_error(24,"Xw_close_background_pixmap",pwindow) ;
265         return (XW_ERROR) ;
266     }
267
268     if( _BPIXMAP ) {
269         XFreePixmap(_DISPLAY,_BPIXMAP) ;
270         XFlush(_DISPLAY) ;
271         _BPIXMAP = 0 ;
272     } else {
273         return (XW_ERROR) ;
274     }
275  
276 #ifdef TRACE_CLOSE_BACKGROUND_PIXMAP
277 if( Xw_get_trace() ) {
278     printf(" Xw_close_background_pixmap(%lx)\n",(long ) pwindow) ;
279 }
280 #endif
281 return (XW_SUCCESS) ;
282 }