Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_Evolution.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VISU_Evolution.cxx
21 //  Author : Oleg UVAROV
22 //  Module : VISU
23 //
24 #include "VISU_Evolution.h"
25
26 #include "VISU_Tools.h"
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Table_i.hh"
30 #include "VISU_View_i.hh"
31
32 #include <VISU_MeshValue.hxx>
33 #include <VISU_Structures_impl.hxx>
34 #include <VISU_VTKTypeList.hxx>
35
36 #include <SUIT_Session.h>
37
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
40
41 #include <SALOME_Event.h>
42
43 //------------------------------------------------------------------------
44 template<int EDataType> bool ProcessValForTime( VISU::PValForTimeImpl theValForTime,
45                                                 VISU::Elem2Comp2Value& theElem2Comp2Value )
46 {
47   theElem2Comp2Value.clear();
48
49   typedef typename VISU::TL::TEnum2VTKBasicType< EDataType >::TResult TVTKBasicType;
50   typedef VISU::TTMeshValue< TVTKBasicType > TMeshValue;
51   typedef MED::SharedPtr< TMeshValue > TMeshValuePtr;
52
53   const TMeshValuePtr aMeshValue = theValForTime->GetMeshValue( VISU::ePOINT1 );
54   if( !aMeshValue )
55     return false;
56
57   vtkIdType aNbElem = aMeshValue->GetNbElem();
58   vtkIdType aNbComp = aMeshValue->GetNbComp();
59   vtkIdType aNbGauss = aMeshValue->GetNbGauss();
60
61   for( vtkIdType iElem = 0; iElem < aNbElem; iElem++ )
62   {
63     typename TMeshValue::TCValueSliceArr aMValueSliceArr = aMeshValue->GetCompValueSliceArr( iElem );
64     VISU::Comp2Value& aComp2Value = theElem2Comp2Value[ iElem ];
65
66     vtkFloatingPointType& aModulusValue = aComp2Value[ 0 ];
67     aModulusValue = 0.0;
68
69     for( vtkIdType iComp = 0; iComp < aNbComp; iComp++ )
70     {
71       const typename TMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[ iComp ];
72
73       vtkFloatingPointType& aValue = aComp2Value[ iComp+1 ];
74       aValue = 0.0;
75
76       for(vtkIdType iGauss = 0; iGauss < aNbGauss; iGauss++)
77       {
78         const vtkFloatingPointType& aVal = aMValueSlice[iGauss];
79         aValue += aVal;
80       }
81       if( aNbGauss != 0 )
82         aValue /= aNbGauss;
83
84       aModulusValue += aValue * aValue;
85     }
86     aModulusValue = sqrt( aModulusValue );
87   }
88
89   return true;
90 }
91
92 //------------------------------------------------------------------------
93 template<int EDataType> int GetNbPoints( VISU::PValForTimeImpl theValForTime )
94 {
95   typedef typename VISU::TL::TEnum2VTKBasicType< EDataType >::TResult TVTKBasicType;
96   typedef VISU::TTMeshValue< TVTKBasicType > TMeshValue;
97   typedef MED::SharedPtr< TMeshValue > TMeshValuePtr;
98
99   const TMeshValuePtr aMeshValue = theValForTime->GetMeshValue( VISU::ePOINT1 );
100   if( !aMeshValue )
101     return 0;
102
103   return aMeshValue->GetNbElem();
104 }
105
106 //------------------------------------------------------------------------
107 VISU_Evolution::VISU_Evolution( _PTR(Study) theStudy,
108                                 VISU::XYPlot_ptr theXYPlot )
109 {
110   myStudy = theStudy;
111   myView = 0;
112
113   if( !CORBA::is_nil( theXYPlot ) )
114   {
115     VISU::XYPlot_i* pPlot = dynamic_cast<VISU::XYPlot_i*>( GetServant( theXYPlot ).in() );
116     Plot2d_ViewFrame* aVF = pPlot->GetView();
117     setViewer( aVF );
118   }
119
120   myFieldEntry = "";
121   myEvolutionEntry = "";
122   myMeshName = "";
123   myEntity = VISU::NODE_ENTITY;
124   myFieldName = "";
125
126   myPointId = 0;
127   myComponentId = 0;
128 }
129
130 //------------------------------------------------------------------------
131 VISU_Evolution::~VISU_Evolution()
132 {
133 }
134
135 //------------------------------------------------------------------------
136 bool VISU_Evolution::setField( _PTR(SObject) theField )
137 {
138   myField = theField;
139   if( !theField )
140     return false;
141
142   myFieldEntry = theField->GetID();
143
144   VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap( theField );
145   if( aRestoringMap.empty() )
146     return false;
147
148   VISU::VISUType aType = VISU::Storable::RestoringMap2Type( aRestoringMap );
149   if( aType != VISU::TFIELD )
150     return false;
151
152   myMeshName = aRestoringMap["myMeshName"].toStdString();
153   myEntity = VISU::TEntity( aRestoringMap["myEntityId"].toInt() );
154   myFieldName = aRestoringMap["myName"].toStdString();
155
156   if( myEntity != VISU::NODE_ENTITY )
157     return false;
158
159   VISU::Result_var aResult = VISU::FindResult( VISU::GetSObject( theField ).in() );
160   if( CORBA::is_nil( aResult.in() ) )
161     return false;
162
163   myResult = dynamic_cast<VISU::Result_i*>( VISU::GetServant( aResult ).in() );
164   if( !myResult )
165     return false;
166
167   const VISU::TMeshMap& aMeshMap = myResult->GetInput()->GetMeshMap();
168   if( aMeshMap.empty() )
169     return false;
170
171   VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find( myMeshName );
172   if( aMeshIter == aMeshMap.end() )
173     return false;
174   
175   const VISU::PMesh& aMesh = aMeshIter->second;
176   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
177   if( aMeshOnEntityMap.empty() )
178     return false;
179
180   VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.find( myEntity );
181   if( aMeshOnEntityIter == aMeshOnEntityMap.end() )
182     return false;
183
184   const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
185   const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
186   if( aFieldMap.empty() )
187     return false;
188
189   VISU::TFieldMap::const_iterator aFieldIter = aFieldMap.find( myFieldName );
190   if( aFieldIter == aFieldMap.end() )
191     return false;
192
193   myFieldImpl = aFieldIter->second;
194   const VISU::TNames& aCompNames = myFieldImpl->myCompNames;
195   const VISU::TNames& aUnitNames = myFieldImpl->myUnitNames;
196   int aNbComp = myFieldImpl->myNbComp;
197
198   // fill myComponentDataList
199   myComponentDataList.clear();
200
201   QString aModulusComponent( "<Modulus>" );
202   myComponentDataList.append( VISU::ComponentData( aModulusComponent, "" ) );
203   for( int i = 0; i < aNbComp; i++ )
204   {
205     QString aComponent = QString( aCompNames[i].c_str() ).simplified();
206     if( aComponent.isEmpty() )
207       aComponent = "Component " + QString::number( i+1 );
208
209     QString anUnit = QString( aUnitNames[i].c_str() ).simplified();
210
211     myComponentDataList.append( VISU::ComponentData( aComponent, anUnit ) );
212   }
213
214   return true;
215 }
216
217 //------------------------------------------------------------------------
218 bool VISU_Evolution::setField( SALOMEDS::SObject_ptr theField )
219 {
220   SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate( theField );
221   _PTR(SObject) aField = VISU::GetClientSObject( theFieldDup, myStudy );
222   return setField( aField );
223 }
224
225 //------------------------------------------------------------------------
226 void VISU_Evolution::setPointId( int thePointId )
227 {
228   myPointId = thePointId;
229 }
230
231 //------------------------------------------------------------------------
232 void VISU_Evolution::setComponentId( int theComponentId )
233 {
234   myComponentId = theComponentId;
235 }
236
237 //------------------------------------------------------------------------
238 int VISU_Evolution::getNbPoints() const
239 {
240   if( !myFieldImpl )
241     return 0;
242
243   vtkIdType aDataType = myFieldImpl->GetDataType();
244   const VISU::TValField& aValField = myFieldImpl->myValField;
245   if( aValField.empty() )
246     return 0;
247
248   VISU::TValField::const_iterator aValFieldIter = aValField.begin();
249   for( ; aValFieldIter != aValField.end(); aValFieldIter++ )
250   {
251     const vtkIdType& aTimeStamp = aValFieldIter->first;
252     VISU::PValForTimeImpl aValForTime = aValFieldIter->second;
253
254     // to force method VISU::MedConvertor::FillValForTime() to be called
255     myResult->GetInput()->GetTimeStampOnMesh( myMeshName, myEntity, myFieldName, aTimeStamp );
256
257     switch( aDataType )
258     {
259       case VTK_DOUBLE : return GetNbPoints<VTK_DOUBLE>( aValForTime );
260       case VTK_FLOAT : return GetNbPoints<VTK_FLOAT>( aValForTime );
261       case VTK_INT : return GetNbPoints<VTK_INT>( aValForTime );
262       case VTK_LONG: return GetNbPoints<VTK_LONG>( aValForTime );
263       default: return 0;
264     }
265   }
266
267   return 0;
268 }
269
270 //------------------------------------------------------------------------
271 bool VISU_Evolution::extractData( int thePointId,
272                                   int theComponentId,
273                                   VISU::TimeStampValueList& theTimeStampValueList )
274 {
275   theTimeStampValueList.clear();
276   myTimeStampDataList.clear();
277
278   if( !myFieldImpl )
279     return false;
280
281   vtkIdType aDataType = myFieldImpl->GetDataType();
282   const VISU::TValField& aValField = myFieldImpl->myValField;
283   if( aValField.empty() )
284     return false;
285
286   typedef QList< VISU::Elem2Comp2Value >         TimeStamp2Elem2Comp2Value;
287   typedef QListIterator< VISU::Elem2Comp2Value > TimeStamp2Elem2Comp2ValueIterator;
288   TimeStamp2Elem2Comp2Value aData;
289
290   VISU::TValField::const_iterator aValFieldIter = aValField.begin();
291   for( ; aValFieldIter != aValField.end(); aValFieldIter++ )
292   {
293     const vtkIdType& aTimeStamp = aValFieldIter->first;
294     VISU::PValForTimeImpl aValForTime = aValFieldIter->second;
295     VISU::TTime aTime = aValForTime->myTime;
296     double aTimeValue = aTime.first;
297     std::string aTimeUnits = aTime.second;
298
299     // to force method VISU::MedConvertor::FillValForTime() to be called
300     // (we need data of all timestamps of the result)
301     myResult->GetInput()->GetTimeStampOnMesh( myMeshName, myEntity, myFieldName, aTimeStamp );
302
303     // data should be sorted by time value
304     int anOrder = 0;
305     VISU::TimeStampDataListIterator anIter( myTimeStampDataList );
306     while( anIter.hasNext() )
307     {
308       VISU::TimeStampData aTimeStampData = anIter.next();
309       if( aTimeValue > aTimeStampData.first )
310         anOrder++;
311     }
312
313     VISU::Elem2Comp2Value anElem2Comp2Value;
314
315     bool ok = false;
316     switch( aDataType )
317     {
318       case VTK_DOUBLE : ok = ProcessValForTime<VTK_DOUBLE>( aValForTime, anElem2Comp2Value ); break;
319       case VTK_FLOAT : ok = ProcessValForTime<VTK_FLOAT>( aValForTime, anElem2Comp2Value ); break;
320       case VTK_INT : ok = ProcessValForTime<VTK_INT>( aValForTime, anElem2Comp2Value ); break;
321       case VTK_LONG: ok = ProcessValForTime<VTK_LONG>( aValForTime, anElem2Comp2Value ); break;
322       default: break;
323     }
324
325     if( !ok )
326       return false;
327
328     aData.insert( anOrder, anElem2Comp2Value );
329     myTimeStampDataList.insert( anOrder, VISU::TimeStampData( aTimeValue, aTimeUnits ) );
330   }
331
332   if( theComponentId < 0 || theComponentId >= myComponentDataList.size() )
333     return false;
334
335   int aTimeStamp = 0;
336   TimeStamp2Elem2Comp2ValueIterator it1( aData );
337   while( it1.hasNext() )
338   {
339     VISU::Elem2Comp2Value anElem2Comp2Value = it1.next();
340     VISU::Elem2Comp2Value::const_iterator it2 = anElem2Comp2Value.find( thePointId );
341     if( it2 != anElem2Comp2Value.end() )
342     {
343       VISU::Comp2Value aComp2Value = it2.value();
344       VISU::Comp2Value::const_iterator it3 = aComp2Value.find( theComponentId );
345       if( it3 != aComp2Value.end() )
346       {
347         vtkFloatingPointType aValue = it3.value();
348         theTimeStampValueList.append( aValue );
349       }
350     }
351     aTimeStamp++;
352   }
353
354   if( theTimeStampValueList.size() != myTimeStampDataList.size() )
355     return false;
356
357   return true;
358 }
359
360 //------------------------------------------------------------------------
361 bool VISU_Evolution::showEvolution()
362 {
363   return ProcessEvent(new TMemFunEvent<VISU_Evolution,bool>
364                       (this,&VISU_Evolution::_showEvolution));
365 }
366
367 //------------------------------------------------------------------------
368 bool VISU_Evolution::_showEvolution()
369 {
370   bool isEdit = ( myEvolutionEntry != "" );
371
372   // 1) extract data
373   VISU::TimeStampValueList aTimeStampValueList;
374   if( !extractData( myPointId, myComponentId, aTimeStampValueList ) )
375     return false;
376
377   // 2) publish new objects in study (or edit them)
378   _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
379   aStudyBuilder->NewCommand(); // open transaction
380
381   QString anEvolutionComment;
382   anEvolutionComment.sprintf( "myComment=EVOLUTION;myPointId=%d;myComponentId=%d",
383                               myPointId,
384                               myComponentId );
385
386   _PTR(SObject) anEvolutionObject, aFieldRefObject, aTableObject;
387   if( !isEdit ) // creation mode
388   {
389     _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent( myStudy );
390     std::string aSComponentEntry = aSComponent->GetID();
391
392     // create an evolution object
393     myEvolutionEntry = VISU::CreateAttributes( myStudy,
394                                                aSComponentEntry.c_str(),
395                                                VISU::NO_ICON,
396                                                VISU::NO_IOR,
397                                                VISU::GenerateName( "Evolution", 0 ).toLatin1().constData(),
398                                                VISU::NO_PERFSITENT_REF,
399                                                anEvolutionComment.toLatin1().constData(),
400                                                true );
401     anEvolutionObject = myStudy->FindObjectID( myEvolutionEntry.c_str() );
402
403     // create a reference to the field object
404     aFieldRefObject = aStudyBuilder->NewObject( anEvolutionObject );
405     aStudyBuilder->Addreference( aFieldRefObject, myField );
406
407     // create a table object
408     std::string aTableEntry = VISU::CreateAttributes( myStudy,
409                                                       aFieldRefObject->GetID().c_str(),
410                                                       VISU::NO_ICON,
411                                                       VISU::NO_IOR,
412                                                       VISU::GenerateName( "Table", 0 ).toLatin1().constData(),
413                                                       VISU::NO_PERFSITENT_REF,
414                                                       "myComment=TABLE",
415                                                       true );
416     aTableObject = myStudy->FindObjectID( aTableEntry.c_str() );
417   }
418   else // edition mode
419   {
420     // edit an evolution object
421     anEvolutionObject = myStudy->FindObjectID( myEvolutionEntry.c_str() );
422     _PTR(GenericAttribute) anAttr;
423     anAttr = aStudyBuilder->FindOrCreateAttribute( anEvolutionObject, "AttributeString" );
424     _PTR(AttributeString) aComment( anAttr );
425     aComment->SetValue( anEvolutionComment.toLatin1().constData() );
426
427     // get a reference to the field object
428     _PTR(ChildIterator) anIter = myStudy->NewChildIterator( anEvolutionObject );
429     anIter->Init();
430     if( anIter->More() )
431       aFieldRefObject = anIter->Value();
432
433     // get a table object
434     anIter = myStudy->NewChildIterator( aFieldRefObject );
435     anIter->Init();
436     if( anIter->More() )
437       aTableObject = anIter->Value();
438   }
439
440   aStudyBuilder->CommitCommand(); // commit transaction
441
442   // 3) update table attribute of the table object
443   _PTR(GenericAttribute) anAttr = aStudyBuilder->FindOrCreateAttribute( aTableObject, "AttributeTableOfReal" );
444   _PTR(AttributeTableOfReal) aTableOfReal( anAttr );
445
446   aTableOfReal->SetNbColumns( aTimeStampValueList.size() );
447
448   QString aTimeRowUnits;
449   int aTimeStamp = 0;
450   VISU::TimeStampValueListIterator it( aTimeStampValueList );
451   while( it.hasNext() )
452   {
453     vtkFloatingPointType aValue = it.next();
454
455     VISU::TimeStampData aTimeStampData = myTimeStampDataList[ aTimeStamp ];
456     double aTimeValue = aTimeStampData.first;
457     std::string aTimeUnits = aTimeStampData.second;
458
459     if( aTimeRowUnits.isEmpty() )
460       aTimeRowUnits = QString( aTimeUnits.c_str() ).simplified();
461
462     aTableOfReal->SetColumnTitle( aTimeStamp+1, QString::number( aTimeStamp+1 ).toLatin1().constData() );
463     aTableOfReal->PutValue( aTimeValue, 1, aTimeStamp+1 );
464     aTableOfReal->PutValue( aValue, 2, aTimeStamp+1 );
465
466     aTimeStamp++;
467   }
468
469   if( aTimeRowUnits.isEmpty() )
470     aTimeRowUnits = "s";
471
472   aTableOfReal->SetRowTitle( 1, "Time" );
473   aTableOfReal->SetRowUnit( 1, aTimeRowUnits.toLatin1().constData() );
474
475   const VISU::ComponentData& aComponentData = myComponentDataList[ myComponentId ];
476   QString aValueTitle = QString( "Point %1" ).arg( myPointId );
477   aTableOfReal->SetRowTitle( 2, aValueTitle.toLatin1().constData() );
478   aTableOfReal->SetRowUnit( 2, aComponentData.second.toLatin1().constData() );
479
480   QString aTitle = QString( "%1, %2" ).arg( myFieldName.c_str() ).arg( aComponentData.first );
481   aTableOfReal->SetTitle( aTitle.toLatin1().constData() );
482
483   // 4) get active study
484   SalomeApp_Study* aSalomeStudy = NULL;
485   SUIT_Session* aSession = SUIT_Session::session();
486   QList<SUIT_Application*> anApplications = aSession->applications();
487   QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
488   while ( anIter !=  anApplications.end() ) {
489     SUIT_Application* anApp = *anIter;
490     if (SUIT_Study* aSStudy = anApp->activeStudy()) {
491       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
492         if (_PTR(Study) aCStudy = aStudy->studyDS()) {
493           if (aCStudy->Name() == myStudy->Name()) {
494             aSalomeStudy = aStudy;
495             break;
496           }
497         }
498       }
499       anIter++;
500     }
501   }
502
503   // 5) create curves and plot
504   if( aSalomeStudy )
505   {
506     // 5.1) remove old curves (edition mode)
507     if( isEdit ) {
508       _PTR(GenericAttribute) anAttr;
509       if(aTableObject->FindAttribute( anAttr, "AttributeName" ) ) {
510         _PTR(ChildIterator) aChildIter = myStudy->NewChildIterator( aTableObject );
511         for( aChildIter->InitEx( false ); aChildIter->More(); aChildIter->Next() ) {
512           aSalomeStudy->deleteReferencesTo( aChildIter->Value() );
513           _PTR(SObject) aCurveObject = aChildIter->Value();
514           if(aCurveObject) {
515             VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aCurveObject);
516             if (aRestoringMap["myComment"] == "CURVE") {
517               CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aCurveObject);
518               if(!CORBA::is_nil(aCORBAObject)) {
519                 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
520                 if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aServant.in())){
521                   if(SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSalomeStudy->application()))
522                     VISU::PlotRemoveCurve(anApp, aCurve);
523                 }
524               }
525             }
526             aStudyBuilder->RemoveObject( aCurveObject );
527           }
528         }
529       }
530     }
531
532     // 5.2) create new curves
533     VISU::VISU_Gen_i* aVisuGen = VISU::VISU_Gen_i::GetVisuGenImpl();
534     aVisuGen->CreateTable( aTableObject->GetID().c_str() );
535
536     // 5.3) create plot
537     VISU::CreatePlot( aVisuGen, getViewer(), aTableObject );
538   }
539
540   return true;
541 }
542
543 //------------------------------------------------------------------------
544 void VISU_Evolution::restoreFromStudy( SALOMEDS::SObject_ptr theObj )
545 {
546   _PTR(SObject) anEvolutionObject = VISU::GetClientSObject( theObj, myStudy );
547   restoreFromStudy( anEvolutionObject );
548 }
549
550 //------------------------------------------------------------------------
551 void VISU_Evolution::restoreFromStudy( _PTR(SObject) theObj )
552 {
553   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap( theObj );
554   if( aMap.empty() )
555     return;
556
557   bool isExist;
558   myPointId     = VISU::Storable::FindValue( aMap, "myPointId",     &isExist ).toInt();
559   myComponentId = VISU::Storable::FindValue( aMap, "myComponentId", &isExist ).toInt();
560
561   _PTR(ChildIterator) anIter = myStudy->NewChildIterator( theObj );
562   for( anIter->Init(); anIter->More(); anIter->Next() )
563   {
564     _PTR(SObject) aRefObj = anIter->Value();
565     _PTR(SObject) aFieldObj;
566
567     if( !aRefObj->ReferencedObject( aFieldObj ) ) 
568       continue;
569
570     int nbAttr = aFieldObj->GetAllAttributes().size();
571     if( nbAttr < 1 )
572       continue;
573
574     setField( aFieldObj );
575     break;
576   }
577
578   myEvolutionEntry = theObj->GetID();
579 }
580
581 //------------------------------------------------------------------------
582 struct TNewEvolutionEvent: public SALOME_Event
583 {
584   std::string myStudyName;
585   VISU::XYPlot_ptr myXYPlot;
586
587   typedef VISU_Evolution* TResult;
588   TResult myResult;
589
590   TNewEvolutionEvent (std::string theStudyName, VISU::XYPlot_ptr theXYPlot):
591     myStudyName(theStudyName),
592     myXYPlot(VISU::XYPlot::_duplicate(theXYPlot)),
593     myResult(NULL)
594   {}
595
596   virtual
597   void
598   Execute()
599   {
600     SUIT_Session* aSession = SUIT_Session::session();
601     QList<SUIT_Application*> anApplications = aSession->applications();
602     QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
603     while ( anIter !=  anApplications.end() ) {
604       SUIT_Application* anApp = *anIter;
605       if (SUIT_Study* aSStudy = anApp->activeStudy()) {
606         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
607           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
608             if (myStudyName == aCStudy->Name()) {
609               myResult = new VISU_Evolution (aCStudy, myXYPlot);
610               break;
611             }
612           }
613         }
614       }
615       anIter++;
616     }
617   }
618 };
619
620 //------------------------------------------------------------------------
621 VISU_Evolution_i::VISU_Evolution_i( SALOMEDS::Study_ptr theStudy,
622                                     VISU::XYPlot_ptr theXYPlot )
623 {
624   std::string aStudyName = theStudy->Name();
625   myEngine = ProcessEvent( new TNewEvolutionEvent( aStudyName, theXYPlot ) );
626 }
627
628 //------------------------------------------------------------------------
629 VISU_Evolution_i::~VISU_Evolution_i()
630 {
631   delete myEngine;
632 }
633
634 //------------------------------------------------------------------------
635 bool VISU_Evolution_i::setField( SALOMEDS::SObject_ptr theField )
636 {
637   return myEngine->setField( theField );
638 }
639
640 //------------------------------------------------------------------------
641 void VISU_Evolution_i::setPointId( CORBA::Long thePointId )
642 {
643   myEngine->setPointId( thePointId );
644 }
645
646 //------------------------------------------------------------------------
647 void VISU_Evolution_i::setComponentId( CORBA::Long theComponentId )
648 {
649   myEngine->setComponentId( theComponentId );
650 }
651
652 //------------------------------------------------------------------------
653 CORBA::Boolean VISU_Evolution_i::showEvolution()
654 {
655   return myEngine->showEvolution();
656 }
657
658 //------------------------------------------------------------------------
659 void VISU_Evolution_i::restoreFromStudy( SALOMEDS::SObject_ptr theObj )
660 {
661   myEngine->restoreFromStudy( theObj );
662 }