1 // SALOME VTKViewer : build VTK 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 #include "VVTK_ViewWindow.h"
30 #include "VVTK_ViewModel.h"
31 #include "VVTK_MainWindow.h"
32 #include "SVTK_View.h"
34 #include "SUIT_Session.h"
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"
42 #include <qsplitter.h>
46 //----------------------------------------------------------------------------
48 ::VVTK_ViewWindow(SUIT_Desktop* theDesktop):
49 SVTK_ViewWindow(theDesktop),
55 //----------------------------------------------------------------------------
56 void VVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
58 if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
59 QWidget* aWidget = new QWidget(this);
60 setCentralWidget(aWidget);
62 QBoxLayout* aLayout = new QVBoxLayout(aWidget);
63 aLayout->setAutoAdd(true);
64 QSplitter* aSplitter = new QSplitter(Qt::Vertical,aWidget);
65 //aSplitter->setChildrenCollapsible(true);
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();
73 myMainWindow1 = new VVTK_MainWindow1(aSplitter,
78 anInsideCursorSettings = myMainWindow1->GetInsideCursorSettings();
79 anOutsideCursorSettings = myMainWindow1->GetOutsideCursorSettings();
80 aPickingSettings = myMainWindow1->GetPickingSettings();
82 SVTK_RenderWindowInteractor* anIteractor =
83 new SVTK_RenderWindowInteractor(myMainWindow1,"SVTK_RenderWindowInteractor1");
85 SVTK_GenericRenderWindowInteractor* aDevice =
86 SVTK_GenericRenderWindowInteractor::New();
87 aDevice->SetRenderWidget(anIteractor);
88 aDevice->SetSelector(aSelector);
90 VVTK_Renderer1* aRenderer = VVTK_Renderer1::New();
91 aRenderer->Initialize(aDevice,aSelector);
93 aWidgetCtrl = aRenderer->GetWidgetCtrl();
95 aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
96 aRenderer->SetOutsideCursorSettings(anOutsideCursorSettings);
97 aRenderer->SetPickingSettings(aPickingSettings);
99 anIteractor->Initialize(aDevice,aRenderer,aSelector);
101 SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
102 anIteractor->PushInteractorStyle(aStyle);
108 myMainWindow1->Initialize(anIteractor,aRenderer);
110 myView1 = new SVTK_View(myMainWindow1);
111 SVTK_ViewWindow::Initialize(myView1,theModel);
114 myMainWindow2 = myMainWindow1->CreateMainWindow2(aSplitter,
115 "VVTK_SegmantationWindow",
118 SVTK_RenderWindowInteractor* anIteractor =
119 new SVTK_RenderWindowInteractor(myMainWindow2,"SVTK_RenderWindowInteractor1");
121 SVTK_GenericRenderWindowInteractor* aDevice =
122 SVTK_GenericRenderWindowInteractor::New();
123 aDevice->SetRenderWidget(anIteractor);
124 aDevice->SetSelector(aSelector);
126 VVTK_Renderer2* aRenderer = VVTK_Renderer2::New();
127 aRenderer->Initialize(aDevice,aSelector);
129 aRenderer->SetWidgetCtrl(aWidgetCtrl);
131 aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
132 aRenderer->SetPickingSettings(aPickingSettings);
134 anIteractor->Initialize(aDevice,aRenderer,aSelector);
136 SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
137 anIteractor->PushInteractorStyle(aStyle);
143 myMainWindow2->Initialize(anIteractor);
145 myView2 = new SVTK_View(myMainWindow2);
146 SVTK_ViewWindow::Initialize(myView2,theModel);
150 int h = height() / 2;
151 QValueList<int> aSizes;
154 aSplitter->setSizes( aSizes );
155 myMainWindow2->hide();
157 myMainWindow = myMainWindow1;
162 //----------------------------------------------------------------------------
168 //----------------------------------------------------------------------------
173 return myMainWindow1;
180 return myMainWindow2;
184 //----------------------------------------------------------------------------
187 ::AddActor(VTKViewer_Actor* theActor,
190 myMainWindow1->AddActor(theActor,theIsUpdate);
191 myMainWindow2->AddActor(theActor,theIsUpdate);
194 //----------------------------------------------------------------------------
197 ::RemoveActor(VTKViewer_Actor* theActor,
200 myMainWindow1->RemoveActor(theActor,theIsUpdate);
201 myMainWindow2->RemoveActor(theActor,theIsUpdate);
204 //----------------------------------------------------------------------------
207 ::Repaint(bool theUpdateTrihedron)
209 myMainWindow1->Repaint(theUpdateTrihedron);
210 myMainWindow2->Repaint(theUpdateTrihedron);
213 //----------------------------------------------------------------
218 myView1->unHighlightAll();
219 myView2->unHighlightAll();
222 //----------------------------------------------------------------
225 ::highlight(const Handle(SALOME_InteractiveObject)& theIO,
229 myView1->highlight( theIO, theIsHighlight, theIsUpdate );
230 myView2->highlight( theIO, theIsHighlight, theIsUpdate );
233 //----------------------------------------------------------------
236 ::onSelectionChanged()
238 myView1->onSelectionChanged();
239 myView2->onSelectionChanged();
242 //----------------------------------------------------------------------------
247 myMainWindow1->onResetView();
248 myMainWindow2->onResetView();
251 //----------------------------------------------------------------------------
256 myMainWindow1->onFitAll();
257 myMainWindow2->onFitAll();
260 //----------------------------------------------------------------------------
263 ::action( const int accelAction )
265 if ( myMainWindow1->hasFocus() )
266 myMainWindow1->action( accelAction );
267 else if ( myMainWindow2->hasFocus() )
268 myMainWindow2->action( accelAction );
274 //----------------------------------------------------------------------------
279 if( myMainWindow1->GetInteractor()->hasFocus() )
280 return myMainWindow1->dumpView();
282 if( myMainWindow2->GetInteractor()->hasFocus() )
283 return myMainWindow2->dumpView();
288 //----------------------------------------------------------------------------
291 ::setBackgroundColor( const QColor& theColor )
293 myMainWindow1->SetBackgroundColor( theColor );
294 myMainWindow2->SetBackgroundColor( theColor );