Salome HOME
Merge from OCC_development_generic_2006
[modules/visu.git] / src / VVTK / VVTK_ViewWindow.cxx
1 //  SALOME VTKViewer : build VTK 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   : 
25 //  Author : 
26 //  Module : SALOME
27 //  $Header$
28
29 #include "VVTK_ViewWindow.h"
30 #include "VVTK_ViewModel.h"
31 #include "VVTK_MainWindow.h"
32 #include "SVTK_View.h"
33
34 #include "SUIT_Session.h"
35
36 #include "VVTK_Renderer.h"
37 #include "SVTK_Selector.h"
38 #include "SVTK_InteractorStyle.h"
39 #include "SVTK_RenderWindowInteractor.h"
40 #include "SVTK_GenericRenderWindowInteractor.h"
41
42 #include <qsplitter.h>
43 #include <qlayout.h>
44 #include <qimage.h>
45
46 //----------------------------------------------------------------------------
47 VVTK_ViewWindow
48 ::VVTK_ViewWindow(SUIT_Desktop* theDesktop):
49   SVTK_ViewWindow(theDesktop),
50   myMainWindow1(NULL),
51   myMainWindow2(NULL),
52   myView2(NULL)
53 {}
54
55 //----------------------------------------------------------------------------
56 void VVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
57 {
58   if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
59     QWidget* aWidget = new QWidget(this);
60     setCentralWidget(aWidget);
61     
62     QBoxLayout* aLayout = new QVBoxLayout(aWidget);
63     aLayout->setAutoAdd(true);
64     QSplitter* aSplitter = new QSplitter(Qt::Vertical,aWidget);
65     //aSplitter->setChildrenCollapsible(true);
66
67     VISU_WidgetCtrl* aWidgetCtrl = NULL;
68     VISU_InsideCursorSettings* anInsideCursorSettings = NULL;
69     VISU_OutsideCursorSettings* anOutsideCursorSettings = NULL;
70     VISU_PickingSettings* aPickingSettings = NULL;
71     SVTK_Selector* aSelector = SVTK_Selector::New();
72     {
73       myMainWindow1 = new VVTK_MainWindow1(aSplitter,
74                                            "VVTK_MainWindow",
75                                            aResourceMgr,
76                                            this);
77
78       anInsideCursorSettings = myMainWindow1->GetInsideCursorSettings();
79       anOutsideCursorSettings = myMainWindow1->GetOutsideCursorSettings();
80       aPickingSettings = myMainWindow1->GetPickingSettings();
81
82       SVTK_RenderWindowInteractor* anIteractor = 
83         new SVTK_RenderWindowInteractor(myMainWindow1,"SVTK_RenderWindowInteractor1");
84       
85       SVTK_GenericRenderWindowInteractor* aDevice = 
86         SVTK_GenericRenderWindowInteractor::New();
87       aDevice->SetRenderWidget(anIteractor);
88       aDevice->SetSelector(aSelector);
89     
90       VVTK_Renderer1* aRenderer = VVTK_Renderer1::New();
91       aRenderer->Initialize(aDevice,aSelector);
92
93       aWidgetCtrl = aRenderer->GetWidgetCtrl();
94
95       aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
96       aRenderer->SetOutsideCursorSettings(anOutsideCursorSettings);
97       aRenderer->SetPickingSettings(aPickingSettings);
98
99       anIteractor->Initialize(aDevice,aRenderer,aSelector);
100
101       SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
102       anIteractor->PushInteractorStyle(aStyle);
103       aStyle->Delete();
104
105       aDevice->Delete();
106       aRenderer->Delete();
107
108       myMainWindow1->Initialize(anIteractor,aRenderer);
109
110       myView1 = new SVTK_View(myMainWindow1);
111       SVTK_ViewWindow::Initialize(myView1,theModel);
112     }
113     {
114       myMainWindow2 = myMainWindow1->CreateMainWindow2(aSplitter,
115                                                        "VVTK_SegmantationWindow",
116                                                        aResourceMgr,
117                                                        this);
118       SVTK_RenderWindowInteractor* anIteractor = 
119         new SVTK_RenderWindowInteractor(myMainWindow2,"SVTK_RenderWindowInteractor1");
120       
121       SVTK_GenericRenderWindowInteractor* aDevice = 
122         SVTK_GenericRenderWindowInteractor::New();
123       aDevice->SetRenderWidget(anIteractor);
124       aDevice->SetSelector(aSelector);
125     
126       VVTK_Renderer2* aRenderer = VVTK_Renderer2::New();
127       aRenderer->Initialize(aDevice,aSelector);
128       
129       aRenderer->SetWidgetCtrl(aWidgetCtrl);
130       
131       aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
132       aRenderer->SetPickingSettings(aPickingSettings);
133       
134       anIteractor->Initialize(aDevice,aRenderer,aSelector);
135
136       SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
137       anIteractor->PushInteractorStyle(aStyle);
138       aStyle->Delete();
139
140       aDevice->Delete();
141       aRenderer->Delete();
142
143       myMainWindow2->Initialize(anIteractor);
144       
145       myView2 = new SVTK_View(myMainWindow2);
146       SVTK_ViewWindow::Initialize(myView2,theModel);
147     }
148     aSelector->Delete();
149
150     int h = height() / 2;
151     QValueList<int> aSizes;
152     aSizes.append( h );
153     aSizes.append( h );
154     aSplitter->setSizes( aSizes );
155     myMainWindow2->hide();
156
157     myMainWindow = myMainWindow1;
158     myView = myView1;
159   }
160 }
161
162 //----------------------------------------------------------------------------
163 VVTK_ViewWindow
164 ::~VVTK_ViewWindow()
165 {}
166
167
168 //----------------------------------------------------------------------------
169 VVTK_MainWindow1* 
170 VVTK_ViewWindow
171 ::getMainWindow1()
172 {
173   return myMainWindow1;
174 }
175
176 VVTK_MainWindow2* 
177 VVTK_ViewWindow
178 ::getMainWindow2()
179 {
180   return myMainWindow2;
181 }
182
183
184 //----------------------------------------------------------------------------
185 void
186 VVTK_ViewWindow
187 ::AddActor(VTKViewer_Actor* theActor, 
188            bool theIsUpdate)
189 {
190   myMainWindow1->AddActor(theActor,theIsUpdate);
191   myMainWindow2->AddActor(theActor,theIsUpdate);
192 }
193
194 //----------------------------------------------------------------------------
195 void
196 VVTK_ViewWindow
197 ::RemoveActor(VTKViewer_Actor* theActor, 
198               bool theIsUpdate)
199 {
200   myMainWindow1->RemoveActor(theActor,theIsUpdate);
201   myMainWindow2->RemoveActor(theActor,theIsUpdate);
202 }
203
204 //----------------------------------------------------------------------------
205 void
206 VVTK_ViewWindow
207 ::Repaint(bool theUpdateTrihedron)
208 {
209   myMainWindow1->Repaint(theUpdateTrihedron);
210   myMainWindow2->Repaint(theUpdateTrihedron);
211 }
212
213 //----------------------------------------------------------------
214 void 
215 VVTK_ViewWindow
216 ::unHighlightAll() 
217 {
218   myView1->unHighlightAll();
219   myView2->unHighlightAll();
220 }
221
222 //----------------------------------------------------------------
223 void
224 VVTK_ViewWindow
225 ::highlight(const Handle(SALOME_InteractiveObject)& theIO, 
226             bool theIsHighlight, 
227             bool theIsUpdate ) 
228 {
229   myView1->highlight( theIO, theIsHighlight, theIsUpdate );
230   myView2->highlight( theIO, theIsHighlight, theIsUpdate );
231 }
232
233 //----------------------------------------------------------------
234 void
235 VVTK_ViewWindow
236 ::onSelectionChanged()
237 {
238   myView1->onSelectionChanged();
239   myView2->onSelectionChanged();
240 }
241
242 //----------------------------------------------------------------------------
243 void
244 VVTK_ViewWindow
245 ::onResetView()
246 {
247   myMainWindow1->onResetView();
248   myMainWindow2->onResetView();
249 }
250
251 //----------------------------------------------------------------------------
252 void
253 VVTK_ViewWindow
254 ::onFitAll()
255 {
256   myMainWindow1->onFitAll();
257   myMainWindow2->onFitAll();
258 }
259
260 //----------------------------------------------------------------------------
261 void 
262 VVTK_ViewWindow
263 ::action( const int accelAction  )
264 {
265   if(myMainWindow1->hasFocus())
266     myMainWindow1->action(accelAction);
267   if(myMainWindow2->hasFocus())
268     myMainWindow2->action(accelAction);
269 }
270
271 //----------------------------------------------------------------------------
272 QImage
273 VVTK_ViewWindow
274 ::dumpView()
275 {
276   if( myMainWindow1->GetInteractor()->hasFocus() )
277     return myMainWindow1->dumpView();
278   
279   if( myMainWindow2->GetInteractor()->hasFocus() )
280     return myMainWindow2->dumpView();
281
282   return QImage();
283 }
284
285 //----------------------------------------------------------------------------
286 void
287 VVTK_ViewWindow
288 ::setBackgroundColor( const QColor& theColor )
289 {
290   if( myMainWindow1->GetInteractor()->hasFocus() )
291     myMainWindow1->SetBackgroundColor( theColor );
292   else if( myMainWindow2->GetInteractor()->hasFocus() )
293     myMainWindow2->SetBackgroundColor( theColor );
294   else
295     myMainWindow->SetBackgroundColor( theColor );
296 }
297