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