1 // VISU VISUGUI : GUI of VISU component
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
24 // File : VisuGUI_Slider.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_Slider.h"
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_Study.h"
36 #include "LightApp_SelectionMgr.h"
38 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "VISU_PipeLine.hxx"
42 #include "VISU_Actor.h"
44 #include "VVTK_MainWindow.h"
45 #include "VVTK_ViewWindow.h"
47 #include "VISU_Gen_i.hh"
48 #include "VisuGUI_Module.h"
49 #include "VisuGUI_Tools.h"
50 #include "VisuGUI_Prs3dTools.h"
52 #include "VTKViewer_Algorithm.h"
53 #include "SVTK_Functor.h"
55 #include <vtkActorCollection.h>
56 #include <vtkRenderer.h>
58 #include <qcombobox.h>
62 #include <qlineedit.h>
63 #include <qtoolbutton.h>
72 VisuGUI_Slider::VisuGUI_Slider( VisuGUI_Module* theModule,
73 VVTK_ViewWindow* theViewWindow,
74 LightApp_SelectionMgr* theSelectionMgr )
75 : QtxToolBar( InDock, theViewWindow->getMainWindow1() ),
76 myModule( theModule ),
77 myMainWindow( theViewWindow->getMainWindow1() ),
78 mySelectionMgr( theSelectionMgr )
80 setLabel(tr("TOOLBAR_TITLE"));
81 setCloseMode(QDockWindow::Undocked);
83 VISU::ViewManager_var aViewManager = VISU::GetVisuGen( myModule )->GetViewManager();
84 VISU::View_var aView = aViewManager->GetCurrentView();
85 if(!CORBA::is_nil(aView.in()))
86 myView3D = VISU::View3D::_narrow(aView);
88 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
90 setHorizontallyStretchable( true );
92 QWidget* aWidget = new QWidget( this );
93 aWidget->setFocusPolicy(StrongFocus);
96 QGridLayout* aLayout = new QGridLayout( aWidget, 2, 13, 11, 6 );
98 // Slider and time stamps
99 myFirstTimeStamp = new QLabel( aWidget );
100 myFirstTimeStamp->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
101 aLayout->addWidget( myFirstTimeStamp, 0, 0, Qt::AlignHCenter );
103 mySlider = new QSlider( aWidget );
104 mySlider->setMinValue( 0 );
105 mySlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
106 mySlider->setOrientation( QSlider::Horizontal );
107 mySlider->setTracking( false );
108 mySlider->setFocusPolicy(StrongFocus);
109 aLayout->addMultiCellWidget( mySlider, 0, 0, 1, 8 );
111 myLastTimeStamp = new QLabel( aWidget );
112 myLastTimeStamp->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
113 aLayout->addWidget( myLastTimeStamp, 0, 9, Qt::AlignHCenter );
115 myTimeStampsNumber = new QLabel( aWidget );
116 myTimeStampsNumber->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
117 aLayout->addWidget( myTimeStampsNumber, 0, 10, Qt::AlignHCenter );
119 QLabel* aCacheMemoryLabel = new QLabel( tr( "CACHE_MEMORY" ), aWidget );
120 aCacheMemoryLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
121 aLayout->addWidget( aCacheMemoryLabel, 0, 11 );
123 myCacheMemory = new QLabel( aWidget );
124 myCacheMemory->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
125 QFontMetrics fm( myCacheMemory->font() );
126 myCacheMemory->setFixedWidth( fm.width( "9.99E+99 Mb" ) );
128 aLayout->addWidget( myCacheMemory, 0, 12 );
131 #ifdef ENABLE_AVI_AND_MORE_BUTTONS
132 myMoreButton = new QToolButton( aWidget );
133 myMoreButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
134 myMoreButton->setEnabled( false );
135 myMoreButton->setToggleButton( true );
136 myMoreButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_MORE" ) ) );
137 QToolTip::add( myMoreButton, tr( "MORE" ) );
138 aLayout->addWidget( myMoreButton, 1, 0 );
140 myAVIButton = new QToolButton( aWidget );
141 myAVIButton->setEnabled( false );
142 myAVIButton->setToggleButton( true );
143 myAVIButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_AVI" ) ) );
144 QToolTip::add( myAVIButton, tr( "AVI" ) );
145 aLayout->addWidget( myAVIButton, 1, 1 );
148 aLayout->addItem( new QSpacerItem( 24, 24, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 2 );
150 myFirstButton = new QToolButton( aWidget );
151 myFirstButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_FIRST" ) ) );
152 aLayout->addWidget( myFirstButton, 1, 3 );
154 myPreviousButton = new QToolButton( aWidget );
155 myPreviousButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PREVIOUS" ) ) );
156 aLayout->addWidget( myPreviousButton, 1, 4 );
158 myPlayButton = new QToolButton( aWidget );
159 myPlayButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
160 myPlayButton->setToggleButton( true );
161 aLayout->addWidget( myPlayButton, 1, 5 );
163 myNextButton = new QToolButton( aWidget );
164 myNextButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_NEXT" ) ) );
165 aLayout->addWidget( myNextButton, 1, 6 );
167 myLastButton = new QToolButton( aWidget );
168 myLastButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_LAST" ) ) );
169 aLayout->addWidget( myLastButton, 1, 7 );
171 aLayout->addItem( new QSpacerItem( 24, 24, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 8 );
173 myTimeStampStrings = new QComboBox( aWidget );
174 myTimeStampStrings->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
175 myTimeStampStrings->setFocusPolicy(StrongFocus);
176 aLayout->addWidget( myTimeStampStrings, 1, 9 );
178 myTimeStampIndices = new QComboBox( aWidget );
179 myTimeStampIndices->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
180 myTimeStampIndices->setFocusPolicy(StrongFocus);
181 aLayout->addWidget( myTimeStampIndices, 1, 10 );
184 QLabel* aSpeedLabel = new QLabel( tr( "SPEED" ), aWidget );
185 aSpeedLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
186 aLayout->addWidget( aSpeedLabel, 1, 11 );
188 mySpeedBox = new QSpinBox( 1, 100, 1, aWidget );
189 mySpeedBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
190 mySpeedBox->setFocusPolicy(StrongFocus);
191 mySpeedBox->setValue( 50 );
192 aLayout->addWidget( mySpeedBox, 1, 12 );
194 myTimer = new QTimer( this );
197 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionChanged() ) );
199 connect( myTimeStampStrings, SIGNAL( activated( int ) ), SLOT( onTimeStampActivated( int ) ) );
200 connect( myTimeStampIndices, SIGNAL( activated( int ) ), SLOT( onTimeStampActivated( int ) ) );
202 connect( myFirstButton, SIGNAL( clicked() ), SLOT( onFirst() ) );
203 connect( myPreviousButton, SIGNAL( clicked() ), SLOT( onPrevious() ) );
204 connect( myPlayButton, SIGNAL( toggled( bool ) ), SLOT( onPlay( bool ) ) );
205 connect( myNextButton, SIGNAL( clicked() ), SLOT( onNext() ) );
206 connect( myLastButton, SIGNAL( clicked() ), SLOT( onLast() ) );
208 connect( mySlider, SIGNAL( valueChanged( int ) ), SLOT( onValueChanged( int ) ) );
210 connect( mySpeedBox, SIGNAL( valueChanged( int ) ), SLOT( onSpeedChanged( int ) ) );
212 connect( myTimer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
214 enableControls( false );
216 myMainWindow->addDockWindow( this, Qt::DockBottom );
222 VisuGUI_Slider::~VisuGUI_Slider()
226 bool VisuGUI_Slider::checkHolderList()
228 THolderList aHolderList;
229 THolderList::const_iterator anIter = myHolderList.begin();
230 THolderList::const_iterator anIterEnd = myHolderList.end();
231 for(; anIter != anIterEnd; anIter++){
232 VISU::ColoredPrs3dHolder_var aHolder = *anIter;
233 if(!aHolder->_non_existent())
234 aHolderList.push_back(aHolder);
236 myHolderList.swap(aHolderList);
237 return myHolderList.empty();
240 void VisuGUI_Slider::enableControls( bool on )
242 widget()->setEnabled( on );
245 if( checkHolderList() )
248 myTimeStampStrings->clear();
249 myTimeStampIndices->clear();
251 VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
253 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = aHolder->GetTimeStampsRange();
254 CORBA::Long aLength = aTimeStampsRange->length();
256 VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
257 CORBA::Long aTimeStampNumber = anInput->myTimeStampNumber;
259 myFirstTimeStamp->setText( aTimeStampsRange[0].myTime.in() );
260 myLastTimeStamp->setText( aTimeStampsRange[aLength-1].myTime.in() );
261 myTimeStampsNumber->setText( QString("(") + QString::number( aLength ) + ")" );
263 int aPageStep = aLength / 10;
264 aPageStep = std::max(aPageStep, 1);
265 mySlider->setPageStep(aPageStep);
267 CORBA::Long a_current_index = 0;
268 for( CORBA::Long an_index = 0; an_index < aLength; an_index++ )
270 VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ an_index ];
271 CORBA::Long aNumber = anInfo.myNumber;
272 QString aTime = anInfo.myTime.in();
274 myTimeStampStrings->insertItem( aTime );
275 myTimeStampIndices->insertItem( QString::number( aNumber ) );
277 if( aNumber == aTimeStampNumber )
278 a_current_index = an_index;
280 // work around - to update controls' sizes
281 myTimeStampStrings->setFont(myTimeStampStrings->font());
282 myTimeStampStrings->updateGeometry();
284 myTimeStampIndices->setFont(myTimeStampStrings->font());
285 myTimeStampIndices->updateGeometry();
287 if( a_current_index > mySlider->maxValue() )
288 mySlider->setMaxValue( aLength-1 );
290 myTimeStampStrings->setCurrentItem( a_current_index );
291 myTimeStampIndices->setCurrentItem( a_current_index );
292 mySlider->setValue( a_current_index );
294 if( a_current_index <= mySlider->maxValue() )
295 mySlider->setMaxValue( aLength-1 );
299 myPlayButton->setOn( false );
304 void VisuGUI_Slider::updateMemoryState()
306 if( checkHolderList() )
309 VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
311 VISU::ColoredPrs3dCache_var aCache = aHolder->GetCache();
312 CORBA::Float aCacheMemory = aCache->GetMemorySize();
313 myCacheMemory->setText( QString::number( double( aCacheMemory ), 'E', 2 ) + " Mb" );
316 void VisuGUI_Slider::onSelectionChanged()
318 //cout << "VisuGUI_Slider::onSelectionChanged()" << endl;
319 myHolderList.clear();
321 _PTR(SObject) aSObject;
323 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
324 (SUIT_Session::session()->activeApplication());
326 SALOME_ListIO aListIO;
327 mySelectionMgr->selectedObjects(aListIO);
328 SALOME_ListIteratorOfListIO anIter(aListIO);
329 for(; anIter.More(); anIter.Next() ){
330 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
331 if (anIO->hasEntry()) {
332 SalomeApp_Study* theStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
333 _PTR(Study) aStudy = theStudy->studyDS();
334 aSObject = aStudy->FindObjectID(anIO->getEntry());
337 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
338 if (!CORBA::is_nil(anObject)) {
339 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
341 if(!CORBA::is_nil(aHolder))
343 //cout << "ColoredPrs3dHolder" << endl;
344 myHolderList.push_back(aHolder);
351 enableControls( !checkHolderList() );
355 void VisuGUI_Slider::onTimeStampActivated( int value )
357 mySlider->setValue( value );
358 onValueChanged( value );
361 void VisuGUI_Slider::onFirst()
363 int value = mySlider->minValue();
364 mySlider->setValue( value );
367 void VisuGUI_Slider::onPrevious()
369 int value = mySlider->value() - 1;
370 if( value >= mySlider->minValue() )
371 mySlider->setValue( value );
374 void VisuGUI_Slider::onPlay( bool on )
376 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
379 myPlayButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PAUSE" ) ) );
381 int delay = int(5000.0 / double(mySpeedBox->value()));
382 myTimer->start( delay );
387 myPlayButton->setIconSet( aResourceMgr->loadPixmap( "VISU", tr( "ICON_SLIDER_PLAY" ) ) );
391 void VisuGUI_Slider::onNext()
393 int value = mySlider->value() + 1;
394 if( value <= mySlider->maxValue() )
395 mySlider->setValue( value );
398 void VisuGUI_Slider::onLast()
400 int value = mySlider->maxValue();
401 mySlider->setValue( value );
404 void VisuGUI_Slider::onValueChanged( int value )
406 if( checkHolderList() ){
407 enableControls( false );
411 myTimeStampStrings->setCurrentItem( value );
412 myTimeStampIndices->setCurrentItem( value );
414 VISU::ColoredPrs3dHolder_var aHolder = myHolderList.front();
416 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = aHolder->GetTimeStampsRange();
417 CORBA::Long aLength = aTimeStampsRange->length();
418 if(value < 0 || aLength <= value)
421 VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
422 CORBA::Long aTimeStampNumber = anInput->myTimeStampNumber;
423 CORBA::Long aNumber = aTimeStampsRange[ value ].myNumber;
424 if(aNumber == aTimeStampNumber)
427 THolderList::const_iterator anIter = myHolderList.begin();
428 THolderList::const_iterator anIterEnd = myHolderList.end();
429 for( ; anIter != anIterEnd; anIter++ )
431 VISU::ColoredPrs3dHolder_var aHolder = *anIter;
432 if( CORBA::is_nil( aHolder.in() ) )
435 VISU::ColoredPrs3d_var aPrs3d = aHolder->GetDevice();
436 VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
437 anInput->myTimeStampNumber = aNumber;
439 QApplication::setOverrideCursor(Qt::waitCursor);
441 aHolder->Apply( aPrs3d, anInput, myView3D );
443 QApplication::restoreOverrideCursor();
449 void VisuGUI_Slider::onSpeedChanged( int value )
451 if(myPlayButton->isOn()){
452 int delay = int(5000.0 / double(mySpeedBox->value()));
453 myTimer->start( delay );
457 void VisuGUI_Slider::onTimeout()
459 int value = mySlider->value();
460 if( value < mySlider->maxValue() )
463 myPlayButton->setOn( false );