1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // File : VisuGUI_EvolutionDlg.cxx
23 // Author : Oleg UVAROV
26 #include "VisuGUI_EvolutionDlg.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_ViewTools.h"
32 #include <VISU_Evolution.h>
34 #include <VISU_Gen_i.hh>
35 #include <VISU_Result_i.hh>
37 #include <VISU_Convertor.hxx>
39 #include <SALOME_InteractiveObject.hxx>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_Desktop.h>
45 #include <LightApp_SelectionMgr.h>
47 #include <SPlot2d_ViewModel.h>
48 #include <Plot2d_ViewFrame.h>
52 #include <QIntValidator>
58 #include <vtkDataSetMapper.h>
60 VisuGUI_EvolutionDlg::VisuGUI_EvolutionDlg( VisuGUI* theModule, _PTR(Study) theStudy ) :
61 QtxDialog( VISU::GetDesktop( theModule ), false, false, QtxDialog::Standard, Qt::Dialog ),
62 myModule( theModule ),
64 myPreviewActor( NULL )
66 setWindowTitle( tr( "TITLE" ) );
67 setAttribute( Qt::WA_DeleteOnClose, true );
69 myEngine = new VISU_Evolution( theStudy );
71 QFrame* aMainFrame = mainFrame();
74 QGroupBox* aParamGrp = new QGroupBox( tr( "PARAMETERS" ), aMainFrame );
76 QLabel* aFieldLabel = new QLabel( tr( "FIELD" ), aParamGrp );
77 myFieldLE = new QLineEdit( aParamGrp );
78 myFieldLE->setReadOnly( true );
80 QLabel* aPointLabel = new QLabel( tr( "POINT" ) );
81 myPointLE = new QLineEdit( aParamGrp );
83 myPointValidator = new QIntValidator( this );
84 myPointLE->setValidator( myPointValidator );
86 QLabel* aComponentLabel = new QLabel( tr( "COMPONENT" ) );
87 myComponentCB = new QComboBox( aParamGrp );
88 myComponentCB->setEditable( false );
90 QGridLayout* aParamLayout = new QGridLayout( aParamGrp );
91 aParamLayout->setMargin( 11 );
92 aParamLayout->setSpacing( 6 );
93 aParamLayout->addWidget( aFieldLabel, 0, 0 );
94 aParamLayout->addWidget( myFieldLE, 0, 1 );
95 aParamLayout->addWidget( aPointLabel, 1, 0 );
96 aParamLayout->addWidget( myPointLE, 1, 1 );
97 aParamLayout->addWidget( aComponentLabel, 2, 0 );
98 aParamLayout->addWidget( myComponentCB, 2, 1 );
101 QBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame );
102 aMainLayout->setMargin( 0 );
103 aMainLayout->setSpacing( 0 );
104 aMainLayout->addWidget( aParamGrp );
106 connect( myPointLE, SIGNAL( textEdited( const QString& ) ),
107 this, SLOT( onPointEdited( const QString& ) ) );
109 connect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
110 this, SLOT( onSelectionEvent() ) );
112 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
114 myStoredSelectionMode = ActorSelection;
116 myViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myModule );
119 connect( myViewWindow, SIGNAL( destroyed() ), this, SLOT( onViewWindowClosed() ) );
120 connect( myViewWindow, SIGNAL( closing( SUIT_ViewWindow* ) ), this, SLOT( onViewWindowClosed() ) );
124 //------------------------------------------------------------------------
125 VisuGUI_EvolutionDlg::~VisuGUI_EvolutionDlg()
127 if( myEngine != NULL )
134 //------------------------------------------------------------------------
135 bool VisuGUI_EvolutionDlg::setField( _PTR(SObject) theField )
137 if( myEngine->setField( theField ) )
145 //------------------------------------------------------------------------
146 void VisuGUI_EvolutionDlg::updateFromEngine()
148 std::string aFieldName = myEngine->getFieldName();
149 myFieldLE->setText( QString( aFieldName.c_str() ) );
151 int aNbPoints = myEngine->getNbPoints();
152 myPointValidator->setRange( 0, aNbPoints-1 );
154 QStringList aComponentList;
155 VISU::ComponentDataList aComponentDataList = myEngine->getComponentDataList();
156 int aNbComp = aComponentDataList.size();
159 int aComponentId = 0;
160 VISU::ComponentDataListIterator anIter( aComponentDataList );
161 while( anIter.hasNext() )
163 VISU::ComponentData aComponentData = anIter.next();
164 QString aComponent = aComponentData.first;
165 QString anUnit = aComponentData.second;
167 isModulus = aNbComp > 1 && aComponentId == 0;
170 aComponent = "[" + QString::number( aComponentId ) + "] " + aComponent;
171 if( anUnit.isEmpty() )
173 aComponent = aComponent + ", " + anUnit;
176 aComponentList << aComponent;
180 myComponentCB->clear();
181 myComponentCB->addItems( aComponentList );
183 bool isScalarMode = ( aNbComp > 1 );
184 myComponentCB->setCurrentIndex( isScalarMode ? 0 : 1 );
185 myComponentCB->setEnabled( isScalarMode );
188 //------------------------------------------------------------------------
189 void VisuGUI_EvolutionDlg::accept()
191 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
192 if( VISU::IsStudyLocked( aStudy ) )
194 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
195 tr( "WRN_VISU_WARNING" ),
196 tr( "WRN_STUDY_LOCKED" ) );
201 int aPointId = myPointLE->text().toInt( &ok );
204 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
205 tr( "WRN_VISU_WARNING" ),
206 tr( "ERR_INVALID_SELECTION" ) );
209 myEngine->setPointId( aPointId );
211 int aComponentId = myComponentCB->currentIndex();
212 myEngine->setComponentId( aComponentId );
214 // create or get a Plot2d view
215 SPlot2d_Viewer* aView = VISU::GetPlot2dViewer( myModule, true );
218 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
219 myEngine->setViewer( aPlot );
222 if( !myEngine->showEvolution() )
224 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
225 tr( "WRN_VISU_WARNING" ),
226 tr( "ERR_EXTRACTION_OF_DATA_FAILED" ) );
230 std::string anEvolutionEntry = myEngine->getEvolutionEntry();
231 if( anEvolutionEntry != "" )
233 _PTR(SObject) anEvolutionObject = aStudy->FindObjectID( anEvolutionEntry.c_str() );
234 VISU::UpdateObjBrowser( myModule, true, anEvolutionObject );
240 //------------------------------------------------------------------------
241 void VisuGUI_EvolutionDlg::setVisible( bool theIsVisible )
243 QtxDialog::setVisible( theIsVisible );
248 VISU::Result_i* aResult = myEngine->getResult();
252 if( theIsVisible && !myPreviewActor )
254 // get an id of the pre-selected point
255 // it should be done before changing of selection mode because
256 // that operation forces onSelectionEvent() and clears myPointLE
257 bool hasPreSelection = false;
258 int aPointId = myPointLE->text().toInt( &hasPreSelection );
260 // store current selection mode and switch to point selection
261 myStoredSelectionMode = myViewWindow->SelectionMode();
262 myViewWindow->SetSelectionMode( NodeSelection );
264 // create preview actor and display it in the view
265 VISU::PNamedIDMapper aMapper = aResult->GetInput()->GetMeshOnEntity( myEngine->getMeshName(), myEngine->getEntity() );
267 vtkDataSetMapper* aPreviewMapper = vtkDataSetMapper::New();
268 aPreviewMapper->SetInput( aMapper->GetOutput() );
270 vtkProperty* aProperty = vtkProperty::New();
271 aProperty->SetColor( 1, 1, 1 );
272 aProperty->SetPointSize( SALOME_POINT_SIZE );
273 aProperty->SetRepresentationToPoints();
275 myPreviewActor = SALOME_Actor::New();
276 myPreviewActor->PickableOn();
277 myPreviewActor->SetMapper( aPreviewMapper );
278 myPreviewActor->SetProperty( aProperty );
281 aPreviewMapper->Delete();
283 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject( myEngine->getFieldEntry().c_str(), "", "" );
284 myPreviewActor->setIO( anIO );
286 myViewWindow->AddActor(myPreviewActor);
288 if( hasPreSelection )
290 myPointLE->setText( QString::number( aPointId ) );
292 SVTK_Selector* aSelector = myViewWindow->GetSelector();
293 aSelector->ClearIObjects();
294 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
295 aSelector->AddIObject( anIO );
297 myPreviewActor->Highlight( true );
300 myViewWindow->onFitAll();
302 else if( !theIsVisible && myPreviewActor )
304 SVTK_Selector* aSelector = myViewWindow->GetSelector();
305 aSelector->ClearIObjects();
307 // restore selection mode
308 myViewWindow->SetSelectionMode( myStoredSelectionMode );
310 // remove preview actor from the view and delete it
311 myViewWindow->RemoveActor( myPreviewActor );
312 myPreviewActor->Delete();
317 //------------------------------------------------------------------------
318 void VisuGUI_EvolutionDlg::restoreFromStudy( _PTR(SObject) theEvolution )
320 myEngine->restoreFromStudy( theEvolution );
324 myPointLE->setText( QString::number( myEngine->getPointId() ) );
325 myComponentCB->setCurrentIndex( myEngine->getComponentId() );
328 //------------------------------------------------------------------------
329 void VisuGUI_EvolutionDlg::onPointEdited( const QString& theText )
334 if( !myPreviewActor || !myPreviewActor->hasIO() )
338 int aPointId = theText.toInt( &ok );
342 Handle(SALOME_InteractiveObject) anIO = myPreviewActor->getIO();
344 SVTK_Selector* aSelector = myViewWindow->GetSelector();
345 aSelector->ClearIObjects();
346 aSelector->AddOrRemoveIndex( anIO, aPointId, false );
347 aSelector->AddIObject( anIO );
349 myPreviewActor->Highlight( true );
351 myViewWindow->Repaint();
354 //------------------------------------------------------------------------
355 void VisuGUI_EvolutionDlg::onSelectionEvent()
359 if( !myViewWindow || myViewWindow->SelectionMode() != NodeSelection )
362 if( !myPreviewActor || !myPreviewActor->hasIO() )
365 SVTK_Selector* aSelector = myViewWindow->GetSelector();
366 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr( myModule );
367 SALOME_ListIO aListIO;
368 aSelectionMgr->selectedObjects( aListIO );
369 SALOME_ListIteratorOfListIO anIter( aListIO );
370 while( anIter.More() )
372 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
373 if( !anIO.IsNull() && strcmp( anIO->getEntry(), myPreviewActor->getIO()->getEntry() ) == 0 )
375 TColStd_IndexedMapOfInteger aMapIndex;
376 aSelector->GetIndex( anIO, aMapIndex );
377 if( aMapIndex.Extent() == 1 )
379 int anId = aMapIndex( 1 );
380 myPointLE->setText( QString::number( anId ) );
388 //------------------------------------------------------------------------
389 void VisuGUI_EvolutionDlg::onViewWindowClosed()
395 myPreviewActor->Delete();
402 //------------------------------------------------------------------------
403 void VisuGUI_EvolutionDlg::onHelp()
405 QString aHelpFileName = "evolution_page.html";
406 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
408 app->onHelpContextModule( myModule ? app->moduleName( myModule->moduleName() ) : QString( "" ), aHelpFileName );
413 platform = "winapplication";
415 platform = "application";
417 SUIT_MessageBox::warning( VISU::GetDesktop( myModule ),
419 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
420 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
425 //------------------------------------------------------------------------
426 void VisuGUI_EvolutionDlg::keyPressEvent( QKeyEvent* e )
428 QDialog::keyPressEvent( e );
429 if ( e->isAccepted() )
432 if ( e->key() == Qt::Key_F1 )