Salome HOME
0c3deacf24689ba88bafc450ff2e6d2d053ac5c7
[modules/gui.git] / src / OCCViewer / OCCViewer_VService.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 /***********************************************************************
20
21      FONCTION :
22      ----------
23         Classe OCCViewer_VService :
24
25      HISTORIQUE DES MODIFICATIONS   :
26      --------------------------------
27       00-09-92 : GG  ; Creation.
28       25-02-98 : FMN ; PERF.27: Optimisation de la création d'une vue à partir d'une vue existante
29
30      REMARQUES :
31      -----------
32
33 ************************************************************************/
34
35 /*----------------------------------------------------------------------*/
36 /*
37  * Includes
38  */
39 //just to load the OpenGl shared library
40 //#include <OpenGl_GraphicDriver.hxx>
41
42 #include "OCCViewer_VService.h"
43 #include <V3d_Viewer.hxx>
44 #include <V3d_View.hxx>
45 #include <Viewer_Viewer.hxx>
46
47 #include <V2d_Viewer.hxx>
48 #include <V2d_View.hxx>
49 #include <Viewer_Viewer.hxx>
50
51 #ifdef WNT
52 #include <WNT_Window.hxx>
53 #include <Graphic3d_WNTGraphicDevice.hxx>
54 #include <WNT_GraphicDevice.hxx>
55 #include <WNT_GraphicDevice.hxx>
56 #include <WNT_WDriver.hxx>
57 #else
58 #include <Xw_Window.hxx>
59 #include <Graphic3d_GraphicDevice.hxx>
60 #include <Xw_Driver.hxx>
61 //#include <Xdps_Driver.hxx>
62 #include <Xw_TypeOfMapping.hxx>
63 #endif
64
65 // For 2d
66 #define LOPTIM
67 #ifdef WNT
68 #ifndef LOPTIM
69 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
70 static Handle(WNT_GraphicDevice) XServiceImageDevice;
71 #else
72 static Handle(WNT_GraphicDevice)& _XServiceDefault2dDevice() {
73 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
74 return XServiceDefault2dDevice;
75 }
76 #define XServiceDefault2dDevice _XServiceDefault2dDevice()
77
78 static Handle(WNT_GraphicDevice)& _XServiceImageDevice() {
79 static Handle(WNT_GraphicDevice) XServiceImageDevice;
80 return XServiceImageDevice;
81 }
82 #define XServiceImageDevice _XServiceImageDevice()
83 #endif // LOPTIM
84 #else
85 #ifndef LOPTIM
86 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
87 static Handle(Xw_GraphicDevice) XServiceImageDevice;
88 #else
89 static Handle(Xw_GraphicDevice)& _XServiceDefault2dDevice() {
90 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
91 return XServiceDefault2dDevice;
92 }
93 #define XServiceDefault2dDevice _XServiceImageDevice()
94
95 static Handle(Xw_GraphicDevice)& _XServiceImageDevice() {
96 static Handle(Xw_GraphicDevice) XServiceImageDevice;
97 return XServiceImageDevice;
98 }
99 #define XServiceImageDevice _XServiceImageDevice()
100 #endif // LOPTIM
101 #endif // WNT
102
103 /*!
104     Maps CasCade view to the window [ static ]
105 */
106 void OCCViewer_VService::SetWindow( const Handle(V3d_View)& view,
107                                   const Standard_Integer hiwin,
108                                   const Standard_Integer lowin,
109                                   const Xw_WindowQuality quality )
110 {
111 #ifdef WNT
112   Handle(WNT_Window) w =
113       new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
114 #else
115   Handle(Xw_Window) w =
116       new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, quality );
117 #endif
118   view->SetWindow( w );
119 }
120
121 /*!
122     Magnifies 'view' based on previous view [ static ]
123 */
124 void OCCViewer_VService::SetMagnify( const Handle(V3d_View)& view,
125                                    const Standard_Integer hiwin,
126                                    const Standard_Integer lowin,
127                                    const Handle(V3d_View)& prevView,
128                                    const Standard_Integer x1,
129                                    const Standard_Integer y1,
130                                    const Standard_Integer x2,
131                                    const Standard_Integer y2,
132                                const Xw_WindowQuality aQuality )
133 {
134 #ifdef WNT
135   Handle(WNT_Window) w =
136       new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
137 #else
138   Handle(Xw_Window) w =
139       new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, aQuality );
140 #endif
141   view->SetMagnify( w, prevView, x1, y1, x2, y2 );
142 }
143
144 /*!
145     Creates viewer 3d [ static ]
146 */
147 Handle(V3d_Viewer) OCCViewer_VService::Viewer3d( const Standard_CString aDisplay,
148                                            const Standard_ExtString aName,
149                                            const Standard_CString aDomain,
150                                            const Standard_Real ViewSize ,
151                                            const V3d_TypeOfOrientation ViewProj,
152                                            const Standard_Boolean ComputedMode,
153                                            const Standard_Boolean aDefaultComputedMode )
154 {
155 #ifndef WNT
156     static Handle(Graphic3d_GraphicDevice) defaultdevice;
157     if ( defaultdevice.IsNull() )
158         defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
159     return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
160                            Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
161                            ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
162 #else
163     static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
164     if ( defaultdevice.IsNull() )
165         defaultdevice = new Graphic3d_WNTGraphicDevice();
166     return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
167                            Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
168                            ComputedMode, aDefaultComputedMode, V3d_TEX_NONE);
169 #endif  // WNT
170 }
171
172 /*!
173     Creates view 2D and maps it to the window [ static ]
174 */
175 /*Handle(V2d_View) OCCViewer_VService::View2d( const Handle(V2d_Viewer)& aViewer,
176                                                            const Standard_Integer hiwin,
177                                                            const Standard_Integer lowin,
178                                                            const Xw_WindowQuality aQuality,
179                                                            const Standard_Boolean Update,
180                                                            const Quantity_NameOfColor BackColor )
181 {
182 #ifdef WNT
183     Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
184     Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
185     Handle(WNT_WDriver) D = new WNT_WDriver( W );
186 #else
187     Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
188     Handle(Xw_Window) W = new Xw_Window( GD, hiwin, lowin, aQuality, BackColor );
189     Handle(Xw_Driver) D = new Xw_Driver( W );
190 #endif
191     Handle(V2d_View)  V = new V2d_View( D, aViewer );
192     if ( Update )
193         V->Update();
194     return V;
195 }*/
196
197 /*!
198     Creates view 2D and maps it to the window [ static ]
199 */
200 /*Handle(V2d_View) OCCViewer_VService::dpsView2d( const Handle(V2d_Viewer)& aViewer,
201                                                               const Standard_Integer hiwin,
202                                                               const Standard_Integer lowin,
203                                                               const Xw_WindowQuality aQuality,
204                                                               const Standard_Boolean Update,
205                                                               const Quantity_NameOfColor BackColor )
206 {
207 #ifdef WNT
208     Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
209     Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
210     W->SetBackground( BackColor );
211     Handle(WNT_WDriver) D = new WNT_WDriver( W );
212 #else
213     Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
214     Handle(Xw_Window) W = new Xw_Window( GD,  hiwin, lowin, aQuality, BackColor );
215     Handle(Xdps_Driver) D = new Xdps_Driver( W );
216 #endif
217     Handle(V2d_View)  V = new V2d_View( D, aViewer );
218     if ( Update )
219         V->Update();
220     return V;
221 }*/
222
223 /*!
224     Creates viewer 2D [ static ]
225 */
226 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
227                                                            const Standard_ExtString aName,
228                                                            const Standard_CString aDomain )
229 {
230 #ifdef WNT
231     if ( XServiceDefault2dDevice.IsNull() )
232         XServiceDefault2dDevice = new WNT_GraphicDevice();
233 #else
234     if ( XServiceDefault2dDevice.IsNull() )
235         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
236 #endif
237     return new V2d_Viewer( XServiceDefault2dDevice, aName, aDomain );
238 }*/
239
240 /*!
241     Creates viewer 2D [ static ]
242 */
243 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
244                                                            const Handle(Graphic2d_View)& aView,
245                                                            const Standard_ExtString aName,
246                                                            const Standard_CString aDomain )
247 {
248 #ifdef WNT
249     if ( XServiceDefault2dDevice.IsNull() )
250         XServiceDefault2dDevice = new WNT_GraphicDevice();
251 #else
252     if ( XServiceDefault2dDevice.IsNull() )
253         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
254 #endif
255     return new V2d_Viewer( XServiceDefault2dDevice, aView, aName, aDomain );
256 }*/
257
258 /*!
259     Creates window driver [ static ]
260 */
261 Handle(Aspect_WindowDriver) OCCViewer_VService::WindowDriver( const Standard_CString aDisplay,
262                                                         const Standard_Integer ahiwin,
263                                                         const Standard_Integer alowin,
264                                                         const Quantity_NameOfColor aColor )
265 {
266 #ifdef WNT
267     if ( XServiceDefault2dDevice.IsNull() )
268         XServiceDefault2dDevice = new WNT_GraphicDevice();
269     Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
270     return new WNT_WDriver( W );
271 #else
272     if ( XServiceDefault2dDevice.IsNull() )
273         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
274     Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin, Xw_WQ_DRAWINGQUALITY , aColor );
275     return new Xw_Driver( W );
276 #endif
277 }
278
279 /*!
280     Creates Xdps window driver [ static ]
281     On Win32 the same as OCCViewer_VService::WindowDriver()
282 */
283 /*
284 Handle(Aspect_WindowDriver) OCCViewer_VService::XdpsDriver( const Standard_CString aDisplay,
285                                                       const Standard_Integer ahiwin,
286                                                       const Standard_Integer alowin,
287                                                       const Quantity_NameOfColor aColor )
288 {
289 #ifdef WNT
290     if ( XServiceDefault2dDevice.IsNull() )
291         XServiceDefault2dDevice = new WNT_GraphicDevice();
292     Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
293     return new WNT_WDriver( W );
294 #else
295     if ( XServiceDefault2dDevice.IsNull() )
296         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
297     Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin,
298                                          Xw_WQ_DRAWINGQUALITY, aColor );
299     return new Xdps_Driver( W );
300 #endif
301 }
302 */
303 /*!
304     Creates Xw window driver [ static ]
305     On Win32 the same as OCCViewer_VService::WindowDriver()
306 */
307 Handle(Aspect_WindowDriver) OCCViewer_VService::ImageDriver( const Standard_CString aDisplay,
308                                                        const Standard_Integer ahiwin,
309                                                        const Standard_Integer alowin,
310                                                        const Quantity_NameOfColor aColor )
311 {
312 #ifdef WNT
313     if ( XServiceImageDevice.IsNull() )
314         XServiceImageDevice = new WNT_GraphicDevice();
315     Handle(WNT_Window) W = new WNT_Window( XServiceImageDevice, ahiwin, alowin, aColor );
316     return new WNT_WDriver( W );
317 #else
318     if ( XServiceImageDevice.IsNull() )
319         XServiceImageDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
320     Handle(Xw_Window) W = new Xw_Window( XServiceImageDevice, ahiwin, alowin,
321                                          Xw_WQ_PICTUREQUALITY, aColor );
322     return new Xw_Driver( W );
323 #endif
324 }