1 // SALOME OCCViewer : build OCC Viewer into Salome desktop
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OCCViewer_VService.cxx
25 // Author : GG, FMN, Nicolas REJNERI
30 #include "OCCViewer_VService.h"
32 // Open CASCADE Includes
33 #include <V3d_Viewer.hxx>
34 #include <V3d_View.hxx>
35 #include <Viewer_Viewer.hxx>
37 #include <V2d_Viewer.hxx>
38 #include <V2d_View.hxx>
39 #include <Viewer_Viewer.hxx>
42 #include <WNT_Window.hxx>
43 #include <Graphic3d_WNTGraphicDevice.hxx>
44 #include <WNT_GraphicDevice.hxx>
45 #include <WNT_GraphicDevice.hxx>
46 #include <WNT_WDriver.hxx>
48 #include <Xw_Window.hxx>
49 #include <Graphic3d_GraphicDevice.hxx>
50 #include <Xw_Driver.hxx>
51 #include <Xdps_Driver.hxx>
52 #include <Xw_TypeOfMapping.hxx>
59 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
60 static Handle(WNT_GraphicDevice) XServiceImageDevice;
62 static Handle(WNT_GraphicDevice)& _XServiceDefault2dDevice() {
63 static Handle(WNT_GraphicDevice) XServiceDefault2dDevice;
64 return XServiceDefault2dDevice;
66 #define XServiceDefault2dDevice _XServiceDefault2dDevice()
68 static Handle(WNT_GraphicDevice)& _XServiceImageDevice() {
69 static Handle(WNT_GraphicDevice) XServiceImageDevice;
70 return XServiceImageDevice;
72 #define XServiceImageDevice _XServiceImageDevice()
76 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
77 static Handle(Xw_GraphicDevice) XServiceImageDevice;
79 static Handle(Xw_GraphicDevice)& _XServiceDefault2dDevice() {
80 static Handle(Xw_GraphicDevice) XServiceDefault2dDevice;
81 return XServiceDefault2dDevice;
83 #define XServiceDefault2dDevice _XServiceImageDevice()
85 static Handle(Xw_GraphicDevice)& _XServiceImageDevice() {
86 static Handle(Xw_GraphicDevice) XServiceImageDevice;
87 return XServiceImageDevice;
89 #define XServiceImageDevice _XServiceImageDevice()
94 // ==================================== 3D ================================================================
95 /*----------------------------------------------------------------------*/
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)
103 Handle(WNT_Window) w = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin);
105 Handle(Xw_Window) w = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin,aQuality);
108 // aView->SetShadingModel(V3d_GOURAUD);
111 /*----------------------------------------------------------------------*/
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)
124 Handle(WNT_Window) w = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin);
126 Handle(Xw_Window) w = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device()),hiwin,lowin,aQuality);
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);
135 /*----------------------------------------------------------------------*/
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 )
146 static Handle(Graphic3d_GraphicDevice) defaultdevice;
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);
153 static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
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);
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)
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);
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);
181 Handle(V2d_View) V = new V2d_View(D,aViewer);
182 if(Update) V->Update();
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)
194 Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
195 Handle(WNT_Window) W = new WNT_Window(GD,hiwin,lowin,BackColor);
197 W->SetBackground(BackColor);
199 Handle(WNT_WDriver) D = new WNT_WDriver(W);
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);
205 Handle(V2d_View) V = new V2d_View(D,aViewer);
206 if(Update) V->Update();
210 Handle(V2d_Viewer) OCCViewer_VService::Viewer( const Standard_CString aDisplay,
211 const Standard_ExtString aName,
212 const Standard_CString aDomain)
215 if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
217 if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
219 return new V2d_Viewer(XServiceDefault2dDevice,aName,aDomain);
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)
228 if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new WNT_GraphicDevice();
230 if(XServiceDefault2dDevice.IsNull()) XServiceDefault2dDevice = new Xw_GraphicDevice(aDisplay,Xw_TOM_READONLY);
232 return new V2d_Viewer(XServiceDefault2dDevice,aView,aName,aDomain);
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)
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);
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);
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)
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);
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);
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)
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);
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);