1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VisuGUI_EvolutionDlg.cxx
21 // Author : Oleg UVAROV
24 #include "VisuGUI_EvolutionDlg.h"
27 #include "VisuGUI_Tools.h"
28 #include "VisuGUI_ViewTools.h"
30 #include <VISU_Evolution.h>
32 #include <VISU_Gen_i.hh>
33 #include <VISU_Result_i.hh>
35 #include <VISU_Convertor.hxx>
37 #include <SALOME_InteractiveObject.hxx>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_Desktop.h>
43 #include <LightApp_SelectionMgr.h>
45 #include <SPlot2d_ViewModel.h>
46 #include <Plot2d_ViewFrame.h>
50 #include <QIntValidator>
56 #include <vtkDataSetMapper.h>
58 VisuGUI_EvolutionDlg::VisuGUI_EvolutionDlg( VisuGUI* theModule, _PTR(Study) theStudy ) :
59 QtxDialog( VISU::GetDesktop( theModule ), false, false, QtxDialog::Standard, Qt::Dialog ),
60 myModule( theModule ),
62 myPreviewActor( NULL )
64 setWindowTitle( tr( "TITLE" ) );
65 setAttribute( Qt::WA_DeleteOnClose, true );
67 myEngine = new VISU_Evolution( theStudy );
69 QFrame* aMainFrame = mainFrame();
72 QGroupBox* aParamGrp = new QGroupBox( tr( "PARAMETERS" ), aMainFrame );
74 QLabel* aFieldLabel = new QLabel( tr( "FIELD" ), aParamGrp );
75 myFieldLE = new QLineEdit( aParamGrp );
76 myFieldLE->setReadOnly( true );
78 QLabel* aPointLabel = new QLabel( tr( "POINT" ) );
79 myPointLE = new QLineEdit( aParamGrp );
81 myPointValidator = new QIntValidator( this );
82 myPointLE->setValidator( myPointValidator );
84 QLabel* aComponentLabel = new QLabel( tr( "COMPONENT" ) );
85 myComponentCB = new QComboBox( aParamGrp );
86 myComponentCB->setEditable( false );
88 QGridLayout* aParamLayout = new QGridLayout( aParamGrp );
89 aParamLayout->setMargin( 11 );
90 aParamLayout->setSpacing( 6 );
91 aParamLayout->addWidget( aFieldLabel, 0, 0 );
92 aParamLayout->addWidget( myFieldLE, 0, 1 );
93 aParamLayout->addWidget( aPointLabel, 1, 0 );
94 aParamLayout->addWidget( myPointLE, 1, 1 );
95 aParamLayout->addWidget( aComponentLabel, 2, 0 );
96 aParamLayout->addWidget( myComponentCB, 2, 1 );
99 QBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame );
100 aMainLayout->setMargin( 0 );
101 aMainLayout->setSpacing( 0 );
102 aMainLayout->addWidget( aParamGrp );
104 connect( myPointLE, SIGNAL( textEdited( const QString& ) ),
105 this, SLOT( onPointEdited( const QString& ) ) );
107 connect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
108 this, SLOT( onSelectionEvent() ) );
110 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
112 myStoredSelectionMode = ActorSelection;
114 myViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myModule );
117 connect( myViewWindow, SIGNAL( destroyed() ), this, SLOT( onViewWindowClosed() ) );
118 connect( myViewWindow, SIGNAL( closing( SUIT_ViewWindow* ) ), this, SLOT( onViewWindowClosed() ) );
122 //------------------------------------------------------------------------
123 VisuGUI_EvolutionDlg::~VisuGUI_EvolutionDlg()
125 if( myEngine != NULL )
132 //------------------------------------------------------------------------
133 bool VisuGUI_EvolutionDlg::setField( _PTR(SObject) theField )
135 if( myEngine->setField( theField ) )
143 //------------------------------------------------------------------------
144 void VisuGUI_EvolutionDlg::updateFromEngine()
146 std::string aFieldName = myEngine->getFieldName();
147 myFieldLE->setText( QString( aFieldName.c_str() ) );
149 int aNbPoints = myEngine->getNbPoints();
150 myPointValidator->setRange( 0, aNbPoints-1 );
152 QStringList aComponentList;
153 VISU::ComponentDataList aComponentDataList = myEngine->getComponentDataList();
154 int aNbComp = aComponentDataList.size();
157 int aComponentId = 0;
158 VISU::ComponentDataListIterator anIter( aComponentDataList );
159 while( anIter.hasNext() )
161 VISU::ComponentData aComponentData = anIter.next();
162 QString aComponent = aComponentData.first;
163 QString anUnit = aComponentData.second;
165 isModulus = aNbComp > 1 && aComponentId == 0;
168 aComponent = "[" + QString::number( aComponentId ) + "] " + aComponent;
169 if( anUnit.isEmpty() )
171 aComponent = aComponent + ", " + anUnit;
174 aComponentList << aComponent;
178 myComponentCB->clear();
179 myComponentCB->addItems( aComponentList );
181 bool isScalarMode = ( aNbComp > 1 );
182 myComponentCB->setCurrentIndex( isScalarMode ? 0 : 1 );
183 myComponentCB->setEnabled( isScalarMode );
186 //------------------------------------------------------------------------
187 void VisuGUI_EvolutionDlg::accept()
189 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
190 if( VISU::IsStudyLocked( aStudy ) )
192 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
193 tr( "WRN_VISU_WARNING" ),
194 tr( "WRN_STUDY_LOCKED" ) );
199 int aPointId = myPointLE->text().toInt( &ok );
202 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
203 tr( "WRN_VISU_WARNING" ),
204 tr( "ERR_INVALID_SELECTION" ) );
207 myEngine->setPointId( aPointId );
209 int aComponentId = myComponentCB->currentIndex();
210 myEngine->setComponentId( aComponentId );
212 // create or get a Plot2d view
213 SPlot2d_Viewer* aView = VISU::GetPlot2dViewer( myModule, true );
216 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
217 myEngine->setViewer( aPlot );
220 if( !myEngine->showEvolution() )
222 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
223 tr( "WRN_VISU_WARNING" ),
224 tr( "ERR_EXTRACTION_OF_DATA_FAILED" ) );
228 std::string anEvolutionEntry = myEngine->getEvolutionEntry();
229 if( anEvolutionEntry != "" )
231 _PTR(SObject) anEvolutionObject = aStudy->FindObjectID( anEvolutionEntry.c_str() );
232 VISU::UpdateObjBrowser( myModule, true, anEvolutionObject );
238 //------------------------------------------------------------------------
239 void VisuGUI_EvolutionDlg::setVisible( bool theIsVisible )
241 QtxDialog::setVisible( theIsVisible );
246 VISU::Result_i* aResult = myEngine->getResult();
250 if( theIsVisible && !myPreviewActor )
252 // get an id of the pre-selected point
253 // it should be done before changing of selection mode because
254 // that operation forces onSelectionEvent() and clears myPointLE
255 bool hasPreSelection = false;
256 int aPointId = myPointLE->text().toInt( &hasPreSelection );
258 // store current selection mode and switch to point selection
259 myStoredSelectionMode = myViewWindow->SelectionMode();
260 myViewWindow->SetSelectionMode( NodeSelection );
262 // create preview actor and display it in the view
263 VISU::PNamedIDMapper aMapper = aResult->GetInput()->GetMeshOnEntity( myEngine->getMeshName(), myEngine->getEntity() );
265 vtkDataSetMapper* aPreviewMapper = vtkDataSetMapper::New();
266 aPreviewMapper->SetInputConnection( aMapper->GetOutputPort() );
267 aPreviewMapper->Update();
269 vtkProperty* aProperty = vtkProperty::New();
270 aProperty->SetColor( 1, 1, 1 );
271 aProperty->SetPointSize( SALOME_POINT_SIZE );
272 aProperty->SetRepresentationToPoints();
274 myPreviewActor = SALOME_Actor::New();
275 myPreviewActor->PickableOn();
276 myPreviewActor->SetMapper( aPreviewMapper );
277 myPreviewActor->SetProperty( aProperty );
280 aPreviewMapper->Delete();
282 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( myEngine->getFieldEntry().c_str(), "", "" );
283 myPreviewActor->setIO( anIO );
285 myViewWindow->AddActor(myPreviewActor);
287 if( hasPreSelection )
289 myPointLE->setText( QString::number( aPointId ) );
291 SVTK_Selector* aSelector = myViewWindow->GetSelector();
292 aSelector->ClearIObjects();
293 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
294 aSelector->AddIObject( anIO );
296 myPreviewActor->Highlight( true );
299 myViewWindow->onFitAll();
301 else if( !theIsVisible && myPreviewActor )
303 SVTK_Selector* aSelector = myViewWindow->GetSelector();
304 aSelector->ClearIObjects();
306 // restore selection mode
307 myViewWindow->SetSelectionMode( myStoredSelectionMode );
309 // remove preview actor from the view and delete it
310 myViewWindow->RemoveActor( myPreviewActor );
311 myPreviewActor->Delete();
316 //------------------------------------------------------------------------
317 void VisuGUI_EvolutionDlg::restoreFromStudy( _PTR(SObject) theEvolution )
319 myEngine->restoreFromStudy( theEvolution );
323 myPointLE->setText( QString::number( myEngine->getPointId() ) );
324 myComponentCB->setCurrentIndex( myEngine->getComponentId() );
327 //------------------------------------------------------------------------
328 void VisuGUI_EvolutionDlg::onPointEdited( const QString& theText )
333 if( !myPreviewActor || !myPreviewActor->hasIO() )
337 int aPointId = theText.toInt( &ok );
341 Handle(SALOME_InteractiveObject) anIO = myPreviewActor->getIO();
343 SVTK_Selector* aSelector = myViewWindow->GetSelector();
344 aSelector->ClearIObjects();
345 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
346 aSelector->AddIObject( anIO );
348 myPreviewActor->Highlight( true );
350 myViewWindow->Repaint();
353 //------------------------------------------------------------------------
354 void VisuGUI_EvolutionDlg::onSelectionEvent()
358 if( !myViewWindow || myViewWindow->SelectionMode() != NodeSelection )
361 if( !myPreviewActor || !myPreviewActor->hasIO() )
364 SVTK_Selector* aSelector = myViewWindow->GetSelector();
365 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr( myModule );
366 SALOME_ListIO aListIO;
367 aSelectionMgr->selectedObjects( aListIO );
368 SALOME_ListIteratorOfListIO anIter( aListIO );
369 while( anIter.More() )
371 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
372 if( !anIO.IsNull() && strcmp( anIO->getEntry(), myPreviewActor->getIO()->getEntry() ) == 0 )
374 TColStd_IndexedMapOfInteger aMapIndex;
375 aSelector->GetIndex( anIO, aMapIndex );
376 if( aMapIndex.Extent() == 1 )
378 int anId = aMapIndex( 1 );
379 myPointLE->setText( QString::number( anId ) );
387 //------------------------------------------------------------------------
388 void VisuGUI_EvolutionDlg::onViewWindowClosed()
394 myPreviewActor->Delete();
401 //------------------------------------------------------------------------
402 void VisuGUI_EvolutionDlg::onHelp()
404 QString aHelpFileName = "evolution_page.html";
405 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
407 app->onHelpContextModule( myModule ? app->moduleName( myModule->moduleName() ) : QString( "" ), aHelpFileName );
412 platform = "winapplication";
414 platform = "application";
416 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
418 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
419 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
424 //------------------------------------------------------------------------
425 void VisuGUI_EvolutionDlg::keyPressEvent( QKeyEvent* e )
427 QDialog::keyPressEvent( e );
428 if ( e->isAccepted() )
431 if ( e->key() == Qt::Key_F1 )