Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / OCCViewer / OCCViewer_VService.cxx
1 //  SALOME OCCViewer : build OCC Viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : OCCViewer_VService.cxx
25 //  Author : GG, FMN, Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #include "OCCViewer_VService.h"
30
31 // Open CASCADE Includes
32 #include <V3d_Viewer.hxx>
33 #include <V3d_View.hxx>
34 #include <Viewer_Viewer.hxx>
35
36 #include <V2d_Viewer.hxx>
37 #include <V2d_View.hxx>
38 #include <Viewer_Viewer.hxx>
39
40 #ifdef WNT
41 #include <WNT_Window.hxx>
42 #include <Graphic3d_WNTGraphicDevice.hxx>
43 #include <WNT_GraphicDevice.hxx>
44 #include <WNT_GraphicDevice.hxx>
45 #include <WNT_WDriver.hxx>
46 #else
47 #include <Xw_Window.hxx>
48 #include <Graphic3d_GraphicDevice.hxx>
49 #include <Xw_Driver.hxx>
50 #include <Xdps_Driver.hxx>
51 #include <Xw_TypeOfMapping.hxx>
52 #endif
53 using namespace std;
54
55 // For 2d
56 #define LOPTIM
57 #ifdef WNT
58 #ifndef LOPTIM
59 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
60 static Handle(WNT_GraphicDevice) XServiceImageDevice;
61 #else 
62 static Handle(WNT_GraphicDevice)& _XServiceDefault2dDevice() {
63 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
64 return XServiceDefault2dDevice;
65 }
66 #define XServiceDefault2dDevice _XServiceDefault2dDevice()
67
68 static Handle(WNT_GraphicDevice)& _XServiceImageDevice() {
69 static Handle(WNT_GraphicDevice) XServiceImageDevice;
70 return XServiceImageDevice;
71 }
72 #define XServiceImageDevice _XServiceImageDevice()
73 #endif // LOPTIM
74 #else
75 #ifndef LOPTIM
76 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
77 static Handle(Xw_GraphicDevice) XServiceImageDevice;
78 #else 
79 static Handle(Xw_GraphicDevice)& _XServiceDefault2dDevice() {
80 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
81 return XServiceDefault2dDevice;
82 }
83 #define XServiceDefault2dDevice _XServiceImageDevice()
84
85 static Handle(Xw_GraphicDevice)& _XServiceImageDevice() {
86 static Handle(Xw_GraphicDevice) XServiceImageDevice;
87 return XServiceImageDevice;
88 }
89 #define XServiceImageDevice _XServiceImageDevice()
90 #endif // LOPTIM
91 #endif // WNT
92
93
94 // ====================================  3D  ================================================================
95 /*----------------------------------------------------------------------*/
96
97 void OCCViewer_VService::SetWindow (const Handle(V3d_View)& aView,
98                                     const Standard_Integer hiwin,
99                                     const Standard_Integer lowin,
100                                     const Xw_WindowQuality aQuality) 
101 {
102 #ifdef WNT
103   Handle(WNT_Window) w = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin);
104 #else
105   Handle(Xw_Window) w = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin,aQuality);
106 #endif
107   aView->SetWindow(w);
108 //  aView->SetShadingModel(V3d_GOURAUD);
109 }
110
111 /*----------------------------------------------------------------------*/
112
113 void OCCViewer_VService::SetMagnify (const Handle(V3d_View)& aView,
114                                      const Standard_Integer hiwin,
115                                      const Standard_Integer lowin,
116                                      const Handle(V3d_View)& aPreviousView,
117                                      const Standard_Integer x1,
118                                      const Standard_Integer y1,
119                                      const Standard_Integer x2,
120                                      const Standard_Integer y2,
121                                      const Xw_WindowQuality aQuality) 
122 {
123 #ifdef WNT
124   Handle(WNT_Window) w = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin);
125 #else
126   Handle(Xw_Window) w = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin,aQuality);
127 #endif // WNT
128
129   aView->SetMagnify(w,aPreviousView,x1,y1,x2,y2);
130 //  aView->SetShadingModel(V3d_GOURAUD);
131 //  aView->SetSurfaceDetail(V3d_TEX_NONE);
132 //  aView->SetVisualization(V3d_WIREFRAME);
133 //  aView->SetVisualization(V3d_ZBUFFER);
134 }
135 /*----------------------------------------------------------------------*/
136
137 Handle(V3d_Viewer) OCCViewer_VService::Viewer( const Standard_CString aDisplay,
138                                                const Standard_ExtString aName,
139                                                const Standard_CString aDomain,
140                                                const Standard_Real ViewSize,
141                                                const V3d_TypeOfOrientation ViewProj,
142                                                const Standard_Boolean ComputedMode,
143                                                const Standard_Boolean aDefaultComputedMode )
144 {
145 #ifndef WNT
146 static Handle(Graphic3d_GraphicDevice) defaultdevice;
147     
148  if(defaultdevice.IsNull()) defaultdevice = new Graphic3d_GraphicDevice(aDisplay);
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 #else
153  static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
154  
155  if(defaultdevice.IsNull()) defaultdevice = new Graphic3d_WNTGraphicDevice();
156  return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
157                        Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
158                        ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
159 #endif  // WNT
160 }
161
162 /*----------------------------------------------------------------------*/
163 // ====================================  2D  ================================================================
164 Handle(V2d_View) OCCViewer_VService::XView( const Handle(V2d_Viewer)& aViewer,
165                                             const Standard_Integer hiwin,
166                                             const Standard_Integer lowin,
167                                             const Xw_WindowQuality aQuality,
168                                             const Standard_Boolean Update,
169                                             const Quantity_NameOfColor BackColor)
170 {
171 #ifdef WNT
172   Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
173   Handle(WNT_Window) W = new WNT_Window(GD,hiwin,lowin,BackColor);
174   Handle(WNT_WDriver) D = new WNT_WDriver(W);
175 #else
176   Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
177   Handle(Xw_Window) W = new Xw_Window(GD,hiwin,lowin,aQuality,BackColor);
178   Handle(Xw_Driver) D = new Xw_Driver(W);
179 #endif
180   
181   Handle(V2d_View)  V = new V2d_View(D,aViewer);
182   if(Update) V->Update();
183   return V;
184 }
185
186 Handle(V2d_View)  OCCViewer_VService::XdpsView( const Handle(V2d_Viewer)& aViewer,
187                                                 const Standard_Integer hiwin,
188                                                 const Standard_Integer lowin,
189                                                 const Xw_WindowQuality aQuality,
190                                                 const Standard_Boolean Update,
191                                                 const Quantity_NameOfColor BackColor) 
192 {
193 #ifdef WNT
194   Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());  
195   Handle(WNT_Window) W = new WNT_Window(GD,hiwin,lowin,BackColor);
196 //POP
197   W->SetBackground(BackColor);
198 //POP
199   Handle(WNT_WDriver) D = new WNT_WDriver(W);
200 #else
201   Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());  
202   Handle(Xw_Window) W = new Xw_Window(GD,hiwin,lowin,aQuality,BackColor);
203   Handle(Xdps_Driver) D = new Xdps_Driver(W);
204 #endif
205   Handle(V2d_View)  V = new V2d_View(D,aViewer);
206   if(Update) V->Update();
207   return V;
208 }
209
210 Handle(V2d_Viewer) OCCViewer_VService::Viewer( const Standard_CString aDisplay,
211                                                const Standard_ExtString aName,
212                                                const Standard_CString aDomain) 
213 {
214 #ifdef WNT
215   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
216 #else
217   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
218 #endif
219   return new V2d_Viewer(XServiceDefault2dDevice,aName,aDomain);
220 }
221
222 Handle(V2d_Viewer) OCCViewer_VService::Viewer( const Standard_CString aDisplay,
223                                                const Handle(Graphic2d_View)& aView,
224                                                const Standard_ExtString aName,
225                                                const Standard_CString aDomain) 
226 {
227 #ifdef WNT
228   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
229 #else
230   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
231 #endif
232   return new V2d_Viewer(XServiceDefault2dDevice,aView,aName,aDomain);
233 }
234
235 Handle(Aspect_WindowDriver) OCCViewer_VService::WindowDriver( const Standard_CString aDisplay,
236                                                               const Standard_Integer ahiwin,
237                                                               const Standard_Integer alowin,
238                                                               const Quantity_NameOfColor aColor) 
239 {
240 #ifdef WNT
241   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
242   Handle(WNT_Window) W = new WNT_Window(XServiceDefault2dDevice,ahiwin,alowin,aColor);
243   return new WNT_WDriver(W);
244 #else
245   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
246   Handle(Xw_Window) W = new Xw_Window(XServiceDefault2dDevice,ahiwin,alowin,Xw_WQ_DRAWINGQUALITY,aColor);
247   return new Xw_Driver(W);
248 #endif
249 }
250
251 Handle(Aspect_WindowDriver) OCCViewer_VService::XdpsDriver( const Standard_CString aDisplay, 
252                                                             const Standard_Integer ahiwin,
253                                                             const Standard_Integer alowin,
254                                                             const Quantity_NameOfColor aColor) 
255 {
256 #ifdef WNT
257   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
258   Handle(WNT_Window) W = new WNT_Window(XServiceDefault2dDevice,ahiwin,alowin,aColor);
259   return new WNT_WDriver(W);
260 #else
261   if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
262   Handle(Xw_Window) W = new Xw_Window(XServiceDefault2dDevice,ahiwin,alowin,Xw_WQ_DRAWINGQUALITY,aColor);
263   return new Xdps_Driver(W);
264 #endif
265 }
266
267 Handle(Aspect_WindowDriver) OCCViewer_VService::ImageDriver( 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(XServiceImageDevice.IsNull()) XServiceImageDevice = new WNT_GraphicDevice();
274   Handle(WNT_Window) W = new WNT_Window(XServiceImageDevice,ahiwin,alowin,aColor);
275   return new WNT_WDriver(W);
276 #else
277   if(XServiceImageDevice.IsNull()) XServiceImageDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
278   Handle(Xw_Window) W = new Xw_Window(XServiceImageDevice,ahiwin,alowin,Xw_WQ_PICTUREQUALITY,aColor);
279   return new Xw_Driver(W);
280 #endif
281 }