Salome HOME
Fix for problem with table of contents resizing.
[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/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "OCCViewer_VService.h"
21 #include <V3d_Viewer.hxx>
22 #include <V3d_View.hxx>
23 #include <Viewer_Viewer.hxx>
24
25 #include <V2d_Viewer.hxx>
26 #include <V2d_View.hxx>
27 #include <Viewer_Viewer.hxx>
28
29 #ifdef WNT
30 #include <WNT_Window.hxx>
31 #include <Graphic3d_WNTGraphicDevice.hxx>
32 #include <WNT_GraphicDevice.hxx>
33 #include <WNT_GraphicDevice.hxx>
34 #include <WNT_WDriver.hxx>
35 #else
36 #include <Xw_Window.hxx>
37 #include <Graphic3d_GraphicDevice.hxx>
38 #include <Xw_Driver.hxx>
39 //#include <Xdps_Driver.hxx>
40 #include <Xw_TypeOfMapping.hxx>
41 #endif
42
43 // For 2d
44 #define LOPTIM
45 #ifdef WNT
46 #ifndef LOPTIM
47 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
48 static Handle(WNT_GraphicDevice) XServiceImageDevice;
49 #else
50 static Handle(WNT_GraphicDevice)& _XServiceDefault2dDevice() {
51 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
52 return XServiceDefault2dDevice;
53 }
54 #define XServiceDefault2dDevice _XServiceDefault2dDevice()
55
56 static Handle(WNT_GraphicDevice)& _XServiceImageDevice() {
57 static Handle(WNT_GraphicDevice) XServiceImageDevice;
58 return XServiceImageDevice;
59 }
60 #define XServiceImageDevice _XServiceImageDevice()
61 #endif // LOPTIM
62 #else
63 #ifndef LOPTIM
64 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
65 static Handle(Xw_GraphicDevice) XServiceImageDevice;
66 #else
67 static Handle(Xw_GraphicDevice)& _XServiceDefault2dDevice() {
68 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
69 return XServiceDefault2dDevice;
70 }
71 #define XServiceDefault2dDevice _XServiceImageDevice()
72
73 static Handle(Xw_GraphicDevice)& _XServiceImageDevice() {
74 static Handle(Xw_GraphicDevice) XServiceImageDevice;
75 return XServiceImageDevice;
76 }
77 #define XServiceImageDevice _XServiceImageDevice()
78 #endif // LOPTIM
79 #endif // WNT
80
81 /*!
82     Maps CasCade view to the window [ static ]
83 */
84 void OCCViewer_VService::SetWindow( const Handle(V3d_View)& view,
85                                   const Standard_Integer hiwin,
86                                   const Standard_Integer lowin,
87                                   const Xw_WindowQuality quality )
88 {
89 #ifdef WNT
90   Handle(WNT_Window) w =
91       new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
92 #else
93   Handle(Xw_Window) w =
94       new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, quality );
95 #endif
96   view->SetWindow( w );
97 }
98
99 /*!
100     Magnifies 'view' based on previous view [ static ]
101 */
102 void OCCViewer_VService::SetMagnify( const Handle(V3d_View)& view,
103                                    const Standard_Integer hiwin,
104                                    const Standard_Integer lowin,
105                                    const Handle(V3d_View)& prevView,
106                                    const Standard_Integer x1,
107                                    const Standard_Integer y1,
108                                    const Standard_Integer x2,
109                                    const Standard_Integer y2,
110                                const Xw_WindowQuality aQuality )
111 {
112 #ifdef WNT
113   Handle(WNT_Window) w =
114       new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
115 #else
116   Handle(Xw_Window) w =
117       new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, aQuality );
118 #endif
119   view->SetMagnify( w, prevView, x1, y1, x2, y2 );
120 }
121
122 /*!
123     Creates viewer 3d [ static ]
124 */
125 Handle(V3d_Viewer) OCCViewer_VService::Viewer3d( const Standard_CString aDisplay,
126                                            const Standard_ExtString aName,
127                                            const Standard_CString aDomain,
128                                            const Standard_Real ViewSize ,
129                                            const V3d_TypeOfOrientation ViewProj,
130                                            const Standard_Boolean ComputedMode,
131                                            const Standard_Boolean aDefaultComputedMode )
132 {
133 #ifndef WNT
134     static Handle(Graphic3d_GraphicDevice) defaultdevice;
135     if ( defaultdevice.IsNull() )
136         defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
137     return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
138                            Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
139                            ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
140 #else
141     static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
142     if ( defaultdevice.IsNull() )
143         defaultdevice = new Graphic3d_WNTGraphicDevice();
144     return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
145                            Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
146                            ComputedMode, aDefaultComputedMode, V3d_TEX_NONE);
147 #endif  // WNT
148 }
149
150 /*!
151     Creates view 2D and maps it to the window [ static ]
152 */
153 /*Handle(V2d_View) OCCViewer_VService::View2d( const Handle(V2d_Viewer)& aViewer,
154                                                            const Standard_Integer hiwin,
155                                                            const Standard_Integer lowin,
156                                                            const Xw_WindowQuality aQuality,
157                                                            const Standard_Boolean Update,
158                                                            const Quantity_NameOfColor BackColor )
159 {
160 #ifdef WNT
161     Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
162     Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
163     Handle(WNT_WDriver) D = new WNT_WDriver( W );
164 #else
165     Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
166     Handle(Xw_Window) W = new Xw_Window( GD, hiwin, lowin, aQuality, BackColor );
167     Handle(Xw_Driver) D = new Xw_Driver( W );
168 #endif
169     Handle(V2d_View)  V = new V2d_View( D, aViewer );
170     if ( Update )
171         V->Update();
172     return V;
173 }*/
174
175 /*!
176     Creates view 2D and maps it to the window [ static ]
177 */
178 /*Handle(V2d_View) OCCViewer_VService::dpsView2d( const Handle(V2d_Viewer)& aViewer,
179                                                               const Standard_Integer hiwin,
180                                                               const Standard_Integer lowin,
181                                                               const Xw_WindowQuality aQuality,
182                                                               const Standard_Boolean Update,
183                                                               const Quantity_NameOfColor BackColor )
184 {
185 #ifdef WNT
186     Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
187     Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
188     W->SetBackground( BackColor );
189     Handle(WNT_WDriver) D = new WNT_WDriver( W );
190 #else
191     Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
192     Handle(Xw_Window) W = new Xw_Window( GD,  hiwin, lowin, aQuality, BackColor );
193     Handle(Xdps_Driver) D = new Xdps_Driver( W );
194 #endif
195     Handle(V2d_View)  V = new V2d_View( D, aViewer );
196     if ( Update )
197         V->Update();
198     return V;
199 }*/
200
201 /*!
202     Creates viewer 2D [ static ]
203 */
204 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
205                                                            const Standard_ExtString aName,
206                                                            const Standard_CString aDomain )
207 {
208 #ifdef WNT
209     if ( XServiceDefault2dDevice.IsNull() )
210         XServiceDefault2dDevice = new WNT_GraphicDevice();
211 #else
212     if ( XServiceDefault2dDevice.IsNull() )
213         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
214 #endif
215     return new V2d_Viewer( XServiceDefault2dDevice, aName, aDomain );
216 }*/
217
218 /*!
219     Creates viewer 2D [ static ]
220 */
221 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
222                                                            const Handle(Graphic2d_View)& aView,
223                                                            const Standard_ExtString aName,
224                                                            const Standard_CString aDomain )
225 {
226 #ifdef WNT
227     if ( XServiceDefault2dDevice.IsNull() )
228         XServiceDefault2dDevice = new WNT_GraphicDevice();
229 #else
230     if ( XServiceDefault2dDevice.IsNull() )
231         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
232 #endif
233     return new V2d_Viewer( XServiceDefault2dDevice, aView, aName, aDomain );
234 }*/
235
236 /*!
237     Creates window driver [ static ]
238 */
239 Handle(Aspect_WindowDriver) OCCViewer_VService::WindowDriver( const Standard_CString aDisplay,
240                                                         const Standard_Integer ahiwin,
241                                                         const Standard_Integer alowin,
242                                                         const Quantity_NameOfColor aColor )
243 {
244 #ifdef WNT
245     if ( XServiceDefault2dDevice.IsNull() )
246         XServiceDefault2dDevice = new WNT_GraphicDevice();
247     Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
248     return new WNT_WDriver( W );
249 #else
250     if ( XServiceDefault2dDevice.IsNull() )
251         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
252     Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin, Xw_WQ_DRAWINGQUALITY , aColor );
253     return new Xw_Driver( W );
254 #endif
255 }
256
257 /*!
258     Creates Xdps window driver [ static ]
259     On Win32 the same as OCCViewer_VService::WindowDriver()
260 */
261 /*
262 Handle(Aspect_WindowDriver) OCCViewer_VService::XdpsDriver( const Standard_CString aDisplay,
263                                                       const Standard_Integer ahiwin,
264                                                       const Standard_Integer alowin,
265                                                       const Quantity_NameOfColor aColor )
266 {
267 #ifdef WNT
268     if ( XServiceDefault2dDevice.IsNull() )
269         XServiceDefault2dDevice = new WNT_GraphicDevice();
270     Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
271     return new WNT_WDriver( W );
272 #else
273     if ( XServiceDefault2dDevice.IsNull() )
274         XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
275     Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin,
276                                          Xw_WQ_DRAWINGQUALITY, aColor );
277     return new Xdps_Driver( W );
278 #endif
279 }
280 */
281 /*!
282     Creates Xw window driver [ static ]
283     On Win32 the same as OCCViewer_VService::WindowDriver()
284 */
285 Handle(Aspect_WindowDriver) OCCViewer_VService::ImageDriver( const Standard_CString aDisplay,
286                                                        const Standard_Integer ahiwin,
287                                                        const Standard_Integer alowin,
288                                                        const Quantity_NameOfColor aColor )
289 {
290 #ifdef WNT
291     if ( XServiceImageDevice.IsNull() )
292         XServiceImageDevice = new WNT_GraphicDevice();
293     Handle(WNT_Window) W = new WNT_Window( XServiceImageDevice, ahiwin, alowin, aColor );
294     return new WNT_WDriver( W );
295 #else
296     if ( XServiceImageDevice.IsNull() )
297         XServiceImageDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
298     Handle(Xw_Window) W = new Xw_Window( XServiceImageDevice, ahiwin, alowin,
299                                          Xw_WQ_PICTUREQUALITY, aColor );
300     return new Xw_Driver( W );
301 #endif
302 }