1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "OCCViewer_VService.h"
24 #include <V3d_Viewer.hxx>
25 #include <V3d_View.hxx>
26 #include <Viewer_Viewer.hxx>
28 #include <V2d_Viewer.hxx>
29 #include <V2d_View.hxx>
30 #include <Viewer_Viewer.hxx>
33 #include <WNT_Window.hxx>
34 #include <Graphic3d_WNTGraphicDevice.hxx>
35 #include <WNT_GraphicDevice.hxx>
36 #include <WNT_WDriver.hxx>
37 #include <InterfaceGraphic_WNT.hxx>
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>
50 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
51 static Handle(WNT_GraphicDevice) XServiceImageDevice;
53 static Handle(WNT_GraphicDevice)& _XServiceDefault2dDevice() {
54 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
55 return XServiceDefault2dDevice;
57 #define XServiceDefault2dDevice _XServiceDefault2dDevice()
59 static Handle(WNT_GraphicDevice)& _XServiceImageDevice() {
60 static Handle(WNT_GraphicDevice) XServiceImageDevice;
61 return XServiceImageDevice;
63 #define XServiceImageDevice _XServiceImageDevice()
67 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
68 static Handle(Xw_GraphicDevice) XServiceImageDevice;
70 static Handle(Xw_GraphicDevice)& _XServiceDefault2dDevice() {
71 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
72 return XServiceDefault2dDevice;
74 #define XServiceDefault2dDevice _XServiceImageDevice()
76 static Handle(Xw_GraphicDevice)& _XServiceImageDevice() {
77 static Handle(Xw_GraphicDevice) XServiceImageDevice;
78 return XServiceImageDevice;
80 #define XServiceImageDevice _XServiceImageDevice()
85 Create native view window for CasCade view [ static ]
87 Handle(Aspect_Window) OCCViewer_VService::CreateWindow( const Handle(V3d_View)& view,
88 const Standard_Integer hiwin,
89 const Standard_Integer lowin,
90 const Xw_WindowQuality quality )
93 Handle(WNT_Window) viewWindow = new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
95 viewWindow->SetFlags( WDF_NOERASEBKGRND );
97 Handle(Xw_Window) viewWindow = new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, quality );
103 Maps CasCade view to the window [ static ]
105 void OCCViewer_VService::SetWindow( const Handle(V3d_View)& view,
106 const Standard_Integer hiwin,
107 const Standard_Integer lowin,
108 const Xw_WindowQuality quality )
110 view->SetWindow( OCCViewer_VService::CreateWindow( view, hiwin, lowin, quality ) );
114 Magnifies 'view' based on previous view [ static ]
116 void OCCViewer_VService::SetMagnify( const Handle(V3d_View)& view,
117 const Standard_Integer hiwin,
118 const Standard_Integer lowin,
119 const Handle(V3d_View)& prevView,
120 const Standard_Integer x1,
121 const Standard_Integer y1,
122 const Standard_Integer x2,
123 const Standard_Integer y2,
124 const Xw_WindowQuality aQuality )
127 Handle(WNT_Window) w =
128 new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
130 Handle(Xw_Window) w =
131 new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, aQuality );
133 view->SetMagnify( w, prevView, x1, y1, x2, y2 );
137 Creates viewer 3d [ static ]
139 Handle(V3d_Viewer) OCCViewer_VService::Viewer3d( const Standard_CString aDisplay,
140 const Standard_ExtString aName,
141 const Standard_CString aDomain,
142 const Standard_Real ViewSize ,
143 const V3d_TypeOfOrientation ViewProj,
144 const Standard_Boolean ComputedMode,
145 const Standard_Boolean aDefaultComputedMode )
148 static Handle(Graphic3d_GraphicDevice) defaultdevice;
149 if ( defaultdevice.IsNull() )
150 defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
151 return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
152 Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
153 ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
155 static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
156 if ( defaultdevice.IsNull() )
157 defaultdevice = new Graphic3d_WNTGraphicDevice();
158 return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
159 Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
160 ComputedMode, aDefaultComputedMode, V3d_TEX_NONE);
165 Creates view 2D and maps it to the window [ static ]
167 /*Handle(V2d_View) OCCViewer_VService::View2d( const Handle(V2d_Viewer)& aViewer,
168 const Standard_Integer hiwin,
169 const Standard_Integer lowin,
170 const Xw_WindowQuality aQuality,
171 const Standard_Boolean Update,
172 const Quantity_NameOfColor BackColor )
175 Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
176 Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
177 Handle(WNT_WDriver) D = new WNT_WDriver( W );
179 Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
180 Handle(Xw_Window) W = new Xw_Window( GD, hiwin, lowin, aQuality, BackColor );
181 Handle(Xw_Driver) D = new Xw_Driver( W );
183 Handle(V2d_View) V = new V2d_View( D, aViewer );
190 Creates view 2D and maps it to the window [ static ]
192 /*Handle(V2d_View) OCCViewer_VService::dpsView2d( const Handle(V2d_Viewer)& aViewer,
193 const Standard_Integer hiwin,
194 const Standard_Integer lowin,
195 const Xw_WindowQuality aQuality,
196 const Standard_Boolean Update,
197 const Quantity_NameOfColor BackColor )
200 Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
201 Handle(WNT_Window) W = new WNT_Window( GD, hiwin, lowin, BackColor );
202 W->SetBackground( BackColor );
203 Handle(WNT_WDriver) D = new WNT_WDriver( W );
205 Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
206 Handle(Xw_Window) W = new Xw_Window( GD, hiwin, lowin, aQuality, BackColor );
207 Handle(Xdps_Driver) D = new Xdps_Driver( W );
209 Handle(V2d_View) V = new V2d_View( D, aViewer );
216 Creates viewer 2D [ static ]
218 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
219 const Standard_ExtString aName,
220 const Standard_CString aDomain )
223 if ( XServiceDefault2dDevice.IsNull() )
224 XServiceDefault2dDevice = new WNT_GraphicDevice();
226 if ( XServiceDefault2dDevice.IsNull() )
227 XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
229 return new V2d_Viewer( XServiceDefault2dDevice, aName, aDomain );
233 Creates viewer 2D [ static ]
235 /*Handle(V2d_Viewer) OCCViewer_VService::Viewer2d( const Standard_CString aDisplay,
236 const Handle(Graphic2d_View)& aView,
237 const Standard_ExtString aName,
238 const Standard_CString aDomain )
241 if ( XServiceDefault2dDevice.IsNull() )
242 XServiceDefault2dDevice = new WNT_GraphicDevice();
244 if ( XServiceDefault2dDevice.IsNull() )
245 XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
247 return new V2d_Viewer( XServiceDefault2dDevice, aView, aName, aDomain );
251 Creates window driver [ static ]
253 Handle(Aspect_WindowDriver) OCCViewer_VService::WindowDriver( const Standard_CString aDisplay,
254 const Standard_Integer ahiwin,
255 const Standard_Integer alowin,
256 const Quantity_NameOfColor aColor )
259 if ( XServiceDefault2dDevice.IsNull() )
260 XServiceDefault2dDevice = new WNT_GraphicDevice();
261 Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
262 return new WNT_WDriver( W );
264 if ( XServiceDefault2dDevice.IsNull() )
265 XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
266 Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin, Xw_WQ_DRAWINGQUALITY , aColor );
267 return new Xw_Driver( W );
272 Creates Xdps window driver [ static ]
273 On Win32 the same as OCCViewer_VService::WindowDriver()
276 Handle(Aspect_WindowDriver) OCCViewer_VService::XdpsDriver( const Standard_CString aDisplay,
277 const Standard_Integer ahiwin,
278 const Standard_Integer alowin,
279 const Quantity_NameOfColor aColor )
282 if ( XServiceDefault2dDevice.IsNull() )
283 XServiceDefault2dDevice = new WNT_GraphicDevice();
284 Handle(WNT_Window) W = new WNT_Window( XServiceDefault2dDevice, ahiwin, alowin, aColor );
285 return new WNT_WDriver( W );
287 if ( XServiceDefault2dDevice.IsNull() )
288 XServiceDefault2dDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
289 Handle(Xw_Window) W = new Xw_Window( XServiceDefault2dDevice, ahiwin, alowin,
290 Xw_WQ_DRAWINGQUALITY, aColor );
291 return new Xdps_Driver( W );
296 Creates Xw window driver [ static ]
297 On Win32 the same as OCCViewer_VService::WindowDriver()
299 Handle(Aspect_WindowDriver) OCCViewer_VService::ImageDriver( const Standard_CString aDisplay,
300 const Standard_Integer ahiwin,
301 const Standard_Integer alowin,
302 const Quantity_NameOfColor aColor )
305 if ( XServiceImageDevice.IsNull() )
306 XServiceImageDevice = new WNT_GraphicDevice();
307 Handle(WNT_Window) W = new WNT_Window( XServiceImageDevice, ahiwin, alowin, aColor );
308 return new WNT_WDriver( W );
310 if ( XServiceImageDevice.IsNull() )
311 XServiceImageDevice = new Xw_GraphicDevice( aDisplay, Xw_TOM_READONLY );
312 Handle(Xw_Window) W = new Xw_Window( XServiceImageDevice, ahiwin, alowin,
313 Xw_WQ_PICTUREQUALITY, aColor );
314 return new Xw_Driver( W );