Salome HOME
Merge from V6_main 01/04/2013
[modules/gui.git] / src / OCCViewer / OCCViewer_VService.cxx
1 // Copyright (C) 2007-2013  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 #include <Basics_OCCTVersion.hxx>
29
30 #if OCC_VERSION_LARGE > 0x06050500
31
32 //
33 // new code, changed in OCCT v6.6.0
34 //
35
36 #include <Aspect_DisplayConnection.hxx>
37 #include <Graphic3d.hxx>
38 #include <Graphic3d_GraphicDriver.hxx>
39 #ifdef WNT
40 #include <WNT_Window.hxx>
41 #else
42 #include <Xw_Window.hxx>
43 #endif
44
45 #else // #if OCC_VERSION_LARGE > 0x06050500
46
47 //
48 // obsolete code (before OCCT v6.6.0); to be removed
49 //
50
51 #ifdef WNT
52 #include <WNT_Window.hxx>
53 #include <Graphic3d_WNTGraphicDevice.hxx>
54 #else
55 #include <Xw_Window.hxx>
56 #include <Graphic3d_GraphicDevice.hxx>
57 #endif
58
59 #endif // #if OCC_VERSION_LARGE > 0x06050500
60
61 /*!
62     Create native view window for CasCade view [ static ]
63 */
64 Handle(Aspect_Window) OCCViewer_VService::CreateWindow( const Handle(V3d_View)& view,
65                                                         WId winId )
66 {
67 #if OCC_VERSION_LARGE > 0x06050500
68
69 //
70 // new code, changed in OCCT v6.6.0
71 //
72   Aspect_Handle aWindowHandle = (Aspect_Handle)winId;
73 #ifdef WNT
74   Handle(WNT_Window) viewWindow = new WNT_Window( aWindowHandle );
75 #else
76   Handle(Aspect_DisplayConnection) aDispConnection = view->Viewer()->Driver()->GetDisplayConnection();
77   Handle(Xw_Window) viewWindow = new Xw_Window( aDispConnection, aWindowHandle );
78 #endif
79   return viewWindow;
80
81 #else // #if OCC_VERSION_LARGE > 0x06050500
82
83 //
84 // obsolete code (before OCCT v6.6.0); to be removed
85 //
86   int hwnd = (int)winId;
87   short lowin = (short)hwnd;
88   short hiwin = (short)( hwnd >> 16 );
89
90 #ifdef WNT
91   Handle(WNT_Window) viewWindow = new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
92   // Prevent flickering
93   viewWindow->SetFlags( WDF_NOERASEBKGRND );
94 #else
95   Handle(Xw_Window) viewWindow = new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, Xw_WQ_SAMEQUALITY );
96 #endif
97   return viewWindow;
98
99 #endif // #if OCC_VERSION_LARGE > 0x06050500
100 }
101
102 /*!
103     Maps CasCade view to the window [ static ]
104 */
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 )
109 // {
110 //   view->SetWindow( OCCViewer_VService::CreateWindow( view, hiwin, lowin, quality ) );
111 // }
112
113 /*!
114     Magnifies 'view' based on previous view [ static ]
115 */
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 )
125 // {
126 // #ifdef WNT
127 //   Handle(WNT_Window) w =
128 //     new WNT_Window( Handle(Graphic3d_WNTGraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin );
129 // #else
130 //   Handle(Xw_Window) w =
131 //     new Xw_Window( Handle(Graphic3d_GraphicDevice)::DownCast(view->Viewer()->Device()), hiwin, lowin, aQuality );
132 // #endif
133 //   view->SetMagnify( w, prevView, x1, y1, x2, y2 );
134 // }
135
136 /*!
137     Creates viewer 3d [ static ]
138 */
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 )
146 {
147 #if OCC_VERSION_LARGE > 0x06050500
148
149 //
150 // new code, changed in OCCT v6.6.0
151 //
152
153   static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
154   if (aGraphicDriver.IsNull())
155   {
156     Handle(Aspect_DisplayConnection) aDisplayConnection;
157 #ifndef WNT
158     aDisplayConnection = new Aspect_DisplayConnection( aDisplay );
159 #endif
160     aGraphicDriver = Graphic3d::InitGraphicDriver( aDisplayConnection );
161   }
162
163   return new V3d_Viewer( aGraphicDriver, aName, aDomain, ViewSize, ViewProj,
164                          Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
165                          ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
166   
167 #else // #if OCC_VERSION_LARGE > 0x06050500
168
169 //
170 // obsolete code (before OCCT v6.6.0); to be removed
171 //
172
173 #ifndef WNT
174   static Handle(Graphic3d_GraphicDevice) defaultdevice;
175   if ( defaultdevice.IsNull() )
176     defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
177   return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
178                          Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
179                          ComputedMode, aDefaultComputedMode, V3d_TEX_NONE );
180 #else
181   static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
182   if ( defaultdevice.IsNull() )
183     defaultdevice = new Graphic3d_WNTGraphicDevice();
184   return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize, ViewProj,
185                          Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
186                          ComputedMode, aDefaultComputedMode, V3d_TEX_NONE);
187 #endif  // WNT
188
189 #endif // #if OCC_VERSION_LARGE > 0x06050500
190 }