Salome HOME
Merge from V6_main 11/02/2013
[modules/gui.git] / src / OCCViewer / OCCViewer_VService.cxx
1 // Copyright (C) 2007-2012  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
23 #include "OCCViewer_VService.h"
24
25 #include <V3d_Viewer.hxx>
26 #include <V3d_View.hxx>
27
28 #ifdef WNT
29 #include <WNT_Window.hxx>
30 #include <Graphic3d_WNTGraphicDevice.hxx>
31 #else
32 #include <Xw_Window.hxx>
33 #include <Graphic3d_GraphicDevice.hxx>
34 #endif
35
36 /*!
37     Create native view window for CasCade view [ static ]
38 */
39 Handle(Aspect_Window) OCCViewer_VService::CreateWindow( const Handle(V3d_View)& view,
40                                                         const Standard_Integer hiwin,
41                                                         const Standard_Integer lowin,
42                                                         const Xw_WindowQuality quality )
43 {
44 #ifdef WNT
45   Handle(WNT_Window) viewWindow = new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
46   // Prevent flickering
47   viewWindow->SetFlags( WDF_NOERASEBKGRND );
48 #else
49   Handle(Xw_Window) viewWindow = new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, quality );
50 #endif
51   return viewWindow;
52 }
53
54 /*!
55     Maps CasCade view to the window [ static ]
56 */
57 void OCCViewer_VService::SetWindow( const Handle(V3d_View)& view,
58                                     const Standard_Integer hiwin,
59                                     const Standard_Integer lowin,
60                                     const Xw_WindowQuality quality )
61 {
62   view->SetWindow( OCCViewer_VService::CreateWindow( view, hiwin, lowin, quality ) );
63 }
64
65 /*!
66     Magnifies 'view' based on previous view [ static ]
67 */
68 void OCCViewer_VService::SetMagnify( const Handle(V3d_View)& view,
69                                      const Standard_Integer hiwin,
70                                      const Standard_Integer lowin,
71                                      const Handle(V3d_View)& prevView,
72                                      const Standard_Integer x1,
73                                      const Standard_Integer y1,
74                                      const Standard_Integer x2,
75                                      const Standard_Integer y2,
76                                      const Xw_WindowQuality aQuality )
77 {
78 #ifdef WNT
79   Handle(WNT_Window) w =
80     new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
81 #else
82   Handle(Xw_Window) w =
83     new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, aQuality );
84 #endif
85   view->SetMagnify( w, prevView, x1, y1, x2, y2 );
86 }
87
88 /*!
89     Creates viewer 3d [ static ]
90 */
91 Handle(V3d_Viewer) OCCViewer_VService::Viewer3d( const Standard_CString aDisplay,
92                                                  const Standard_ExtString aName,
93                                                  const Standard_CString aDomain,
94                                                  const Standard_Real ViewSize ,
95                                                  const V3d_TypeOfOrientation ViewProj,
96                                                  const Standard_Boolean ComputedMode,
97                                                  const Standard_Boolean aDefaultComputedMode )
98 {
99 #ifndef WNT
100   static Handle(Graphic3d_GraphicDevice) defaultdevice;
101   if ( defaultdevice.IsNull() )
102     defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
103   return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
104                          Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
105                          ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
106 #else
107   static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
108   if ( defaultdevice.IsNull() )
109     defaultdevice = new Graphic3d_WNTGraphicDevice();
110   return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
111                          Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
112                          ComputedMode, aDefaultComputedMode, V3d_TEX_NONE);
113 #endif  // WNT
114 }