0023414: Remove deprecated classes Xw_PixMap and WNT_PixMap
[occt.git] / src / Xw / Xw_GraphicDevice.cxx
1 // Created on: 1993-10-14
2 // Created by: GG
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 #define GG001   //GG_300197
22 //              Preferer utiliser le visual de la root window en mode
23 //              2D plutot que de prendre un visual PseudoColor alors que la root
24 //              est TrueColor.
25 //              Ceci corrige notamment les pb de colormap non intallees sur DEC
26 //              lorsque la station est bootee en TrueColor.
27
28
29
30 //-Version
31
32 //-Design       Creation d'une unite graphique
33
34 //-Warning
35
36 //-References
37
38 //-Language     C++ 2.0
39
40 //-Declarations
41
42 // for the class
43 #include <stdio.h>
44 #include <Xw.hxx>
45 #include <Xw_GraphicDevice.ixx>
46
47 // Routines C a declarer en extern
48 //extern "C" {
49 #include <Xw_Cextern.hxx>
50 //}
51
52 //-Static data definitions
53
54 //static char *ErrorMessag,LocalMessag[80] ;
55 static char LocalMessag[80] ;
56 //static int ErrorNumber ;
57 //static int ErrorGravity ;
58 static XW_STATUS status ;
59
60 //-Aliases
61
62 //-Global data definitions
63
64 //-Constructors
65
66 Xw_GraphicDevice::Xw_GraphicDevice () : Aspect_GraphicDevice() {
67   MyExtendedDisplay = NULL;
68 }
69
70 Xw_GraphicDevice::Xw_GraphicDevice (const Standard_CString Connexion, const Xw_TypeOfMapping Mapping, const Standard_Integer Ncolors, const Standard_Boolean UseDefault)  : Aspect_GraphicDevice() {
71
72         InitMaps(Connexion,Mapping,Ncolors,UseDefault) ;
73 }
74
75 void Xw_GraphicDevice::Destroy () {
76
77         if( MyColorMap2D != MyColorMap3D ) {
78           MyColorMap3D.Nullify();
79           MyColorMap2D.Nullify();
80         } else {
81           MyColorMap2D.Nullify();
82         }
83         MyTypeMap.Nullify();
84         MyWidthMap.Nullify();
85         MyFontMap.Nullify();
86         MyMarkMap.Nullify();
87
88         if( MyExtendedDisplay ) {
89           status = Xw_close_display(MyExtendedDisplay) ;
90
91           MyExtendedDisplay = NULL;
92         }
93 }
94
95 void Xw_GraphicDevice::InitMaps (const Standard_CString Connexion,const Xw_TypeOfMapping Mapping,const Standard_Integer Ncolors,const Standard_Boolean UseDefault) {
96 #ifdef GG001
97 Xw_TypeOfVisual v2d = Xw_TOV_DEFAULT ;
98 #else
99 Xw_TypeOfVisual v2d = Xw_TOV_PREFERRED_PSEUDOCOLOR ;
100 #endif
101 Xw_TypeOfVisual v3d = Xw_TOV_PREFERRED_TRUECOLOR ;
102
103         Xw_set_trace(Xw::TraceLevel(),Xw::ErrorLevel()) ;
104
105         if( Connexion ) {
106             MyDisplay = TCollection_AsciiString(Connexion) ;
107         } else {
108             MyDisplay = TCollection_AsciiString("") ;
109         }
110
111         MyExtendedDisplay = Xw_open_display((Standard_PCharacter)MyDisplay.ToCString()) ;
112
113         if( !MyExtendedDisplay ) {
114            sprintf(LocalMessag,"Cannot connect to server '%s'",
115                                                 MyDisplay.ToCString());
116            Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
117         }
118
119         v2d = Xw_get_display_visual(MyExtendedDisplay,v2d) ;
120         MyColorMap2D = new Xw_ColorMap(MyDisplay.ToCString(),
121                                         v2d,Mapping,Ncolors,UseDefault) ;
122
123         v3d = Xw_get_display_visual(MyExtendedDisplay,v3d) ;
124         if( v2d != v3d ) {
125             MyColorMap3D = new Xw_ColorMap(MyDisplay.ToCString(),
126                                         v3d,Mapping,Ncolors,UseDefault) ;
127         } else {
128             MyColorMap3D = MyColorMap2D ;
129         }
130
131         MyTypeMap = new Xw_TypeMap(MyDisplay.ToCString()) ;
132         MyWidthMap = new Xw_WidthMap(MyDisplay.ToCString()) ;
133         MyFontMap = new Xw_FontMap(MyDisplay.ToCString()) ;
134         MyMarkMap = new Xw_MarkMap(MyDisplay.ToCString()) ;
135
136 Standard_Address Bof;
137         Bof     = ExtendedColorMap2D();
138         Bof     = ExtendedColorMap3D();
139         Bof     = ExtendedTypeMap();
140         Bof     = ExtendedWidthMap();
141         Bof     = ExtendedFontMap();
142         Bof     = ExtendedMarkMap();
143
144         if( !ExtendedColorMap2D() ||
145             !ExtendedColorMap3D() ||
146             !ExtendedTypeMap() ||
147             !ExtendedWidthMap() ||
148             !ExtendedFontMap() ||
149             !ExtendedMarkMap() ) {
150            sprintf(LocalMessag,"Bad Graphic Device Attributs on '%s'",
151                                                                 Connexion);
152            Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
153         }
154 }
155
156 Handle(Xw_ColorMap) Xw_GraphicDevice::ColorMap2D () const {
157
158         return (MyColorMap2D) ;
159
160 }
161
162 Xw_TypeOfVisual Xw_GraphicDevice::VisualClass2D () const {
163
164         return (MyColorMap2D->VisualClass()) ;
165 }
166
167 Xw_TypeOfVisual Xw_GraphicDevice::OverlayVisualClass2D () const {
168
169         return (MyColorMap2D->OverlayVisualClass()) ;
170 }
171
172 Standard_Address Xw_GraphicDevice::ExtendedColorMap2D () const {
173
174         return (MyColorMap2D->ExtendedColorMap());
175 }
176
177 Standard_Address Xw_GraphicDevice::ExtendedOverlayColorMap2D () const {
178
179         return (MyColorMap2D->ExtendedOverlayColorMap());
180 }
181
182 Handle(Xw_ColorMap) Xw_GraphicDevice::ColorMap3D () const {
183
184         return (MyColorMap3D) ;
185 }
186
187 Xw_TypeOfVisual Xw_GraphicDevice::VisualClass3D () const {
188
189         return (MyColorMap3D->VisualClass()) ;
190 }
191
192 Xw_TypeOfVisual Xw_GraphicDevice::OverlayVisualClass3D () const {
193
194         return (MyColorMap3D->OverlayVisualClass()) ;
195 }
196
197 Standard_Address Xw_GraphicDevice::ExtendedColorMap3D () const {
198
199         return (MyColorMap3D->ExtendedColorMap());
200 }
201
202 Standard_Address Xw_GraphicDevice::ExtendedOverlayColorMap3D () const {
203
204         return (MyColorMap3D->ExtendedOverlayColorMap());
205 }
206
207 Handle(Xw_TypeMap) Xw_GraphicDevice::TypeMap () const {
208
209         return (MyTypeMap) ;
210 }
211
212 Standard_Address Xw_GraphicDevice::ExtendedTypeMap () const {
213
214         return (MyTypeMap->ExtendedTypeMap());
215 }
216
217 Handle(Xw_WidthMap) Xw_GraphicDevice::WidthMap () const {
218
219         return (MyWidthMap) ;
220 }
221
222 Standard_Address Xw_GraphicDevice::ExtendedWidthMap () const {
223
224         return (MyWidthMap->ExtendedWidthMap());
225 }
226
227 Handle(Xw_FontMap) Xw_GraphicDevice::FontMap () const {
228
229         return (MyFontMap) ;
230 }
231
232 Standard_Address Xw_GraphicDevice::ExtendedFontMap () const {
233
234         return (MyFontMap->ExtendedFontMap());
235 }
236
237 Handle(Xw_MarkMap) Xw_GraphicDevice::MarkMap () const {
238
239         return (MyMarkMap) ;
240 }
241
242 Standard_Address Xw_GraphicDevice::ExtendedMarkMap () const {
243
244         return (MyMarkMap->ExtendedMarkMap());
245 }
246
247 Standard_CString Xw_GraphicDevice::Display () const {
248
249         return (MyDisplay.ToCString());
250 }
251
252 Standard_Address Xw_GraphicDevice::XDisplay () const {
253 Aspect_Handle *display ;
254 Aspect_Handle root,colormap ;
255 Xw_TypeOfVisual pclass ;
256 int depth ;
257
258         status = Xw_get_display_info(MyExtendedDisplay,&display,
259                                 &root,&colormap,&pclass,&depth) ;
260
261         return (display);
262 }
263
264 Standard_Address Xw_GraphicDevice::ExtendedDisplay () const {
265
266         return (MyExtendedDisplay);
267 }
268
269 void Xw_GraphicDevice::DisplaySize (Standard_Integer &Width,Standard_Integer &Height) const {
270 int width,height ;
271
272         status = Xw_get_screen_size(MyExtendedDisplay,&width,&height) ;
273
274         Width = width ;
275         Height = height ;
276 }
277
278 void Xw_GraphicDevice::DisplaySize (Quantity_Length &Width,Quantity_Length &Height) const {
279 float width,height ;
280
281         status = Xw_get_mmscreen_size(MyExtendedDisplay,&width,&height) ;
282
283         Width = FROMMILLIMETER(width) ;
284         Height = FROMMILLIMETER(height) ;
285 }
286
287 Standard_Integer Xw_GraphicDevice::PlaneLayer (const Standard_Integer aVisualID) const {
288
289         return Xw_get_plane_layer(MyExtendedDisplay,aVisualID);
290 }
291
292 Handle(Aspect_GraphicDriver) Xw_GraphicDevice::GraphicDriver () const {
293
294 static Handle(Aspect_GraphicDriver) foo;
295
296         cout << "Xw_GraphicDevice::GraphicDriver returns foo\n" << flush;
297
298         return foo;
299
300 }