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