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),
56 //----------------------------------------------------------------------------
57 void VVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
59 if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
60 QWidget* aWidget = new QWidget(this);
61 setCentralWidget(aWidget);
63 QBoxLayout* aLayout = new QVBoxLayout(aWidget);
64 aLayout->setAutoAdd(true);
65 QSplitter* aSplitter = new QSplitter(Qt::Vertical,aWidget);
66 //aSplitter->setChildrenCollapsible(true);
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();
74 myMainWindow1 = new VVTK_MainWindow1(aSplitter,
79 anInsideCursorSettings = myMainWindow1->GetInsideCursorSettings();
80 anOutsideCursorSettings = myMainWindow1->GetOutsideCursorSettings();
81 aPickingSettings = myMainWindow1->GetPickingSettings();
83 SVTK_RenderWindowInteractor* anIteractor =
84 new SVTK_RenderWindowInteractor(myMainWindow1,"SVTK_RenderWindowInteractor1");
86 SVTK_GenericRenderWindowInteractor* aDevice =
87 SVTK_GenericRenderWindowInteractor::New();
88 aDevice->SetRenderWidget(anIteractor);
89 aDevice->SetSelector(aSelector);
91 VVTK_Renderer1* aRenderer = VVTK_Renderer1::New();
92 aRenderer->Initialize(aDevice,aSelector);
94 aWidgetCtrl = aRenderer->GetWidgetCtrl();
96 aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
97 aRenderer->SetOutsideCursorSettings(anOutsideCursorSettings);
98 aRenderer->SetPickingSettings(aPickingSettings);
100 anIteractor->Initialize(aDevice,aRenderer,aSelector);
102 SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
103 anIteractor->PushInteractorStyle(aStyle);
109 myMainWindow1->Initialize(anIteractor,aRenderer);
111 myView1 = new SVTK_View(myMainWindow1);
112 SVTK_ViewWindow::Initialize(myView1,theModel);
115 myMainWindow2 = myMainWindow1->CreateMainWindow2(aSplitter,
116 "VVTK_SegmantationWindow",
119 SVTK_RenderWindowInteractor* anIteractor =
120 new SVTK_RenderWindowInteractor(myMainWindow2,"SVTK_RenderWindowInteractor1");
122 SVTK_GenericRenderWindowInteractor* aDevice =
123 SVTK_GenericRenderWindowInteractor::New();
124 aDevice->SetRenderWidget(anIteractor);
125 aDevice->SetSelector(aSelector);
127 VVTK_Renderer2* aRenderer = VVTK_Renderer2::New();
128 aRenderer->Initialize(aDevice,aSelector);
130 aRenderer->SetWidgetCtrl(aWidgetCtrl);
132 aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
133 aRenderer->SetPickingSettings(aPickingSettings);
135 anIteractor->Initialize(aDevice,aRenderer,aSelector);
137 SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
138 anIteractor->PushInteractorStyle(aStyle);
144 myMainWindow2->Initialize(anIteractor);
146 myView2 = new SVTK_View(myMainWindow2);
147 SVTK_ViewWindow::Initialize(myView2,theModel);
151 int h = height() / 2;
152 QValueList<int> aSizes;
155 aSplitter->setSizes( aSizes );
156 myMainWindow2->hide();
158 myMainWindow = myMainWindow1;
163 //----------------------------------------------------------------------------
169 //----------------------------------------------------------------------------
174 return myMainWindow1;
181 return myMainWindow2;
185 //----------------------------------------------------------------------------
188 ::AddActor(VTKViewer_Actor* theActor,
191 myMainWindow1->AddActor(theActor,theIsUpdate);
192 myMainWindow2->AddActor(theActor,theIsUpdate);
195 //----------------------------------------------------------------------------
198 ::RemoveActor(VTKViewer_Actor* theActor,
201 myMainWindow1->RemoveActor(theActor,theIsUpdate);
202 myMainWindow2->RemoveActor(theActor,theIsUpdate);
205 //----------------------------------------------------------------------------
208 ::Repaint(bool theUpdateTrihedron)
210 myMainWindow1->Repaint(theUpdateTrihedron);
211 myMainWindow2->Repaint(theUpdateTrihedron);
214 //----------------------------------------------------------------
219 myView1->unHighlightAll();
220 myView2->unHighlightAll();
223 //----------------------------------------------------------------
226 ::highlight(const Handle(SALOME_InteractiveObject)& theIO,
230 if(GetSelector()->AddIObject(theIO))
231 GetSelector()->EndPickCallback();
232 myView1->highlight( theIO, theIsHighlight, theIsUpdate );
233 myView2->highlight( theIO, theIsHighlight, theIsUpdate );
236 //----------------------------------------------------------------
239 ::onSelectionChanged()
241 myView1->onSelectionChanged();
242 myView2->onSelectionChanged();
245 //----------------------------------------------------------------------------
250 myMainWindow1->onResetView();
251 myMainWindow2->onResetView();
254 //----------------------------------------------------------------------------
259 myMainWindow1->onFitAll();
260 myMainWindow2->onFitAll();
263 //----------------------------------------------------------------------------
266 ::action( const int accelAction )
268 if ( myMainWindow1->hasFocus() )
269 myMainWindow1->action( accelAction );
270 else if ( myMainWindow2->hasFocus() )
271 myMainWindow2->action( accelAction );
277 //----------------------------------------------------------------------------
282 if( myMainWindow1->GetInteractor()->hasFocus() )
284 if ( myMainWindow1->getToolBar()->hasMouse() || myDumpImage.isNull() )
285 return myMainWindow1->dumpView();
290 if( myMainWindow2->GetInteractor()->hasFocus() )
292 if ( myMainWindow1->getToolBar()->hasMouse() || myDumpImage.isNull() )
293 return myMainWindow2->dumpView();
301 //----------------------------------------------------------------------------
304 ::setBackgroundColor( const QColor& theColor )
306 myMainWindow1->SetBackgroundColor( theColor );
307 myMainWindow2->SetBackgroundColor( theColor );
311 //----------------------------------------------------------------------------
316 if( myMainWindow1->GetInteractor()->hasFocus() )
317 myDumpImage = myMainWindow1->dumpView();
318 else if ( myMainWindow2->GetInteractor()->hasFocus() )
319 myDumpImage = myMainWindow2->dumpView();