1 // Copyright (C) 2007-2011 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->SetInput( aMapper->GetOutput() );
268 vtkProperty* aProperty = vtkProperty::New();
269 aProperty->SetColor( 1, 1, 1 );
270 aProperty->SetPointSize( SALOME_POINT_SIZE );
271 aProperty->SetRepresentationToPoints();
273 myPreviewActor = SALOME_Actor::New();
274 myPreviewActor->PickableOn();
275 myPreviewActor->SetMapper( aPreviewMapper );
276 myPreviewActor->SetProperty( aProperty );
279 aPreviewMapper->Delete();
281 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( myEngine->getFieldEntry().c_str(), "", "" );
282 myPreviewActor->setIO( anIO );
284 myViewWindow->AddActor(myPreviewActor);
286 if( hasPreSelection )
288 myPointLE->setText( QString::number( aPointId ) );
290 SVTK_Selector* aSelector = myViewWindow->GetSelector();
291 aSelector->ClearIObjects();
292 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
293 aSelector->AddIObject( anIO );
295 myPreviewActor->Highlight( true );
298 myViewWindow->onFitAll();
300 else if( !theIsVisible && myPreviewActor )
302 SVTK_Selector* aSelector = myViewWindow->GetSelector();
303 aSelector->ClearIObjects();
305 // restore selection mode
306 myViewWindow->SetSelectionMode( myStoredSelectionMode );
308 // remove preview actor from the view and delete it
309 myViewWindow->RemoveActor( myPreviewActor );
310 myPreviewActor->Delete();
315 //------------------------------------------------------------------------
316 void VisuGUI_EvolutionDlg::restoreFromStudy( _PTR(SObject) theEvolution )
318 myEngine->restoreFromStudy( theEvolution );
322 myPointLE->setText( QString::number( myEngine->getPointId() ) );
323 myComponentCB->setCurrentIndex( myEngine->getComponentId() );
326 //------------------------------------------------------------------------
327 void VisuGUI_EvolutionDlg::onPointEdited( const QString& theText )
332 if( !myPreviewActor || !myPreviewActor->hasIO() )
336 int aPointId = theText.toInt( &ok );
340 Handle(SALOME_InteractiveObject) anIO = myPreviewActor->getIO();
342 SVTK_Selector* aSelector = myViewWindow->GetSelector();
343 aSelector->ClearIObjects();
344 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
345 aSelector->AddIObject( anIO );
347 myPreviewActor->Highlight( true );
349 myViewWindow->Repaint();
352 //------------------------------------------------------------------------
353 void VisuGUI_EvolutionDlg::onSelectionEvent()
357 if( !myViewWindow || myViewWindow->SelectionMode() != NodeSelection )
360 if( !myPreviewActor || !myPreviewActor->hasIO() )
363 SVTK_Selector* aSelector = myViewWindow->GetSelector();
364 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr( myModule );
365 SALOME_ListIO aListIO;
366 aSelectionMgr->selectedObjects( aListIO );
367 SALOME_ListIteratorOfListIO anIter( aListIO );
368 while( anIter.More() )
370 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
371 if( !anIO.IsNull() && strcmp( anIO->getEntry(), myPreviewActor->getIO()->getEntry() ) == 0 )
373 TColStd_IndexedMapOfInteger aMapIndex;
374 aSelector->GetIndex( anIO, aMapIndex );
375 if( aMapIndex.Extent() == 1 )
377 int anId = aMapIndex( 1 );
378 myPointLE->setText( QString::number( anId ) );
386 //------------------------------------------------------------------------
387 void VisuGUI_EvolutionDlg::onViewWindowClosed()
393 myPreviewActor->Delete();
400 //------------------------------------------------------------------------
401 void VisuGUI_EvolutionDlg::onHelp()
403 QString aHelpFileName = "evolution_page.html";
404 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
406 app->onHelpContextModule( myModule ? app->moduleName( myModule->moduleName() ) : QString( "" ), aHelpFileName );
411 platform = "winapplication";
413 platform = "application";
415 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
417 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
418 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
423 //------------------------------------------------------------------------
424 void VisuGUI_EvolutionDlg::keyPressEvent( QKeyEvent* e )
426 QDialog::keyPressEvent( e );
427 if ( e->isAccepted() )
430 if ( e->key() == Qt::Key_F1 )