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