]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_TimeAnimation.cxx
Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / VISU_I / VISU_TimeAnimation.cxx
1 //  Copyright (C) 2007-2010  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
23 //  File   : VISU_TimeAnimation.cxx
24 //  Author : Vitaly SMETANNIKOV
25 //  Module : VISU
26 //
27 #include "VISU_TimeAnimation.h"
28
29 #ifdef WNT
30 #include <windows.h>
31 #include <vfw.h>
32 #include <QMessageBox>
33 #endif
34
35 #include "VISUConfig.hh"
36
37 #include "VISU_Result_i.hh"
38 #include "VISU_Prs3d_i.hh"
39 #include "VISU_Mesh_i.hh"
40 #include "VISU_IsoSurfaces_i.hh"
41 #include "VISU_DeformedShape_i.hh"
42 #include "VISU_DeformedShapeAndScalarMap_i.hh"
43 #include "VISU_CutPlanes_i.hh"
44 #include "VISU_Plot3D_i.hh"
45 #include "VISU_CutLines_i.hh"
46 #include "VISU_CutSegment_i.hh"
47 #include "VISU_Vectors_i.hh"
48 #include "VISU_StreamLines_i.hh"
49 #include "VISU_GaussPoints_i.hh"
50 #include "VISU_ViewManager_i.hh"
51 #include "VISU_View_i.hh"
52
53 #include "VISU_ScalarBarActor.hxx"
54 #include "VISU_Actor.h"
55
56 #include "SalomeApp_Study.h"
57
58 #include "SVTK_ViewWindow.h"
59
60 #include "SALOME_Event.h"
61
62 #include "SUIT_ResourceMgr.h"
63 #include "SUIT_Application.h"
64 #include "SUIT_Session.h"
65 #include "SUIT_Study.h"
66 #include "SUIT_MessageBox.h"
67
68 #include "SALOMEDSClient_AttributeString.hxx"
69 #include "SALOMEDSClient_AttributeName.hxx"
70
71 #include "Utils_ExceptHandlers.hxx"
72
73 #include <QPixmap>
74 #include <QImage>
75 #include <QImageWriter>
76 #include <QStringList>
77 #include <QDir>
78
79 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
80 #define NO_CAS_CATCH
81 #endif
82
83 #include <Standard_Failure.hxx>
84
85 #ifdef NO_CAS_CATCH
86 #include <Standard_ErrorHandler.hxx>
87 #endif
88
89 using namespace std;
90
91 //------------------------------------------------------------------------
92 namespace VISU 
93 {
94   //------------------------------------------------------------------------
95   class ExecutionState 
96   {
97     bool myIsActive;
98     QMutex myIsActiveMutex;
99   public:
100     ExecutionState(bool isActive = false)
101       : myIsActive(isActive) {}
102
103     bool IsActive() {
104       bool state;
105       myIsActiveMutex.lock();
106       state = myIsActive;
107       myIsActiveMutex.unlock();
108       return state;
109     }
110     bool SetActive(bool isActive) {
111       bool state;
112       myIsActiveMutex.lock();
113       state = myIsActive;
114       myIsActive = isActive;
115       myIsActiveMutex.unlock();
116       return state;
117     }
118   };
119
120
121   //------------------------------------------------------------------------
122   struct TCompositeMinMaxController : virtual TVTKMinMaxController
123   {
124     typedef ColoredPrs3d_i* TKey;
125     typedef std::map< TKey, VISU::PMinMaxController > TMinMaxContainer;
126     TMinMaxContainer myMinMaxContainer;    
127
128     void
129     AddController(ColoredPrs3d_i* theReference, 
130                   VISU::PMinMaxController theMinMaxController)
131     {
132       myMinMaxContainer[ TKey( theReference ) ] = theMinMaxController;
133     }
134
135     virtual
136     void
137     UpdateReference(ColoredPrs3d_i* theFromPrs3, ColoredPrs3d_i* theToPrs3d)
138     {
139       TMinMaxContainer::iterator anIter = myMinMaxContainer.find( TKey( theFromPrs3 ) );
140       if ( anIter != myMinMaxContainer.end() ) {
141         myMinMaxContainer.erase( anIter );
142         myMinMaxContainer[ TKey( theToPrs3d ) ] = VISU::CreateDefaultMinMaxController( theToPrs3d );      
143       }
144     }
145
146     virtual
147     vtkFloatingPointType
148     GetComponentMin(vtkIdType theCompID)
149     {
150       vtkFloatingPointType aMin = TMinMaxController::GetComponentMin(theCompID);
151       if ( !myMinMaxContainer.empty() ) {
152         TMinMaxContainer::const_iterator anIter = myMinMaxContainer.begin();
153         for(; anIter != myMinMaxContainer.end(); anIter++){
154           VISU::PMinMaxController aMinMaxController = anIter->second;
155           aMin = std::min(aMin, aMinMaxController->GetComponentMin(theCompID));
156         }
157       }
158       return aMin;
159     }
160
161     virtual
162     vtkFloatingPointType
163     GetComponentMax(vtkIdType theCompID)
164     {
165       vtkFloatingPointType aMax = TMinMaxController::GetComponentMax(theCompID);
166       if ( !myMinMaxContainer.empty() ) {
167         TMinMaxContainer::const_iterator anIter = myMinMaxContainer.begin();
168         for(; anIter != myMinMaxContainer.end(); anIter++){
169           VISU::PMinMaxController aMinMaxController = anIter->second;
170           aMax = std::max(aMax, aMinMaxController->GetComponentMax(theCompID));
171         }
172       }
173       return aMax;
174     }
175   };
176
177   typedef SALOME::GenericObjPtr<TCompositeMinMaxController> PCompositeMinMaxController;
178 }
179
180 //------------------------------------------------------------------------
181 VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
182                                         VISU::View3D_ptr theView3D)
183 {
184   myStudy = theStudy;
185   myExecutionState = new VISU::ExecutionState(false);
186   myFrame = 0;
187   mySpeed = VISU::GetResourceMgr()->integerValue("VISU", "speed", 1);
188   myProportional = VISU::GetResourceMgr()->booleanValue("VISU", "use_proportional_timing", false);
189   myView = 0;
190
191   if (!CORBA::is_nil(theView3D)) {
192     VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
193     SUIT_ViewWindow* aVW = pView->GetViewWindow();
194     setViewer( dynamic_cast<SVTK_ViewWindow*>(aVW) );
195   }
196
197   myAnimationMode = VISU::Animation::PARALLEL;
198   myTimeMinVal = 0;
199   myTimeMaxVal = 0;
200   myTimeMin = 0;
201   myTimeMax = 0;
202   myLastError = "";
203   myCycling = VISU::GetResourceMgr()->booleanValue("VISU", "cycled_animation", false);
204   myCleaningMemoryAtEachFrame = VISU::GetResourceMgr()->booleanValue("VISU", "clean_memory_at_each_frame", false);
205
206   myAnimEntry = "";
207
208   myDumpPath = "";
209   myAVIMaker = "jpeg2yuv";
210
211   myDumpMode = VISU::GetResourceMgr()->integerValue("VISU", "dump_mode", 0);
212   myTimeStampFrequency = VISU::GetResourceMgr()->integerValue("VISU", "time_stamp_frequency", 1);
213 }
214
215
216 //------------------------------------------------------------------------
217 VISU_TimeAnimation::~VISU_TimeAnimation()
218 {
219   if (QThread::isRunning() && !QThread::isFinished()) {
220     stopAnimation();
221     QThread::wait(500);
222     if (QThread::isRunning() && !QThread::isFinished()) {
223       QThread::terminate();
224     }
225   }
226
227   for (int i = 0; i < getNbFields() && myView; i++) {
228     clearData(myFieldsLst[i]);
229   }
230   clearFieldData();
231
232   delete myExecutionState;
233
234   myDumpPath = "";
235
236   /* Terminates the execution of the thread. 
237    * The thread may or may not be terminated immediately, 
238    * depending on the operating system's scheduling policies. 
239    *  
240    * Use QThread::wait() after terminate() for synchronous termination.
241    *
242    * When the thread is terminated, all threads waiting for the the thread to finish will be woken up.
243    * 
244    * Warning: This function is dangerous, and its use is discouraged. 
245    * The thread can be terminated at any point in its code path. 
246    * Threads can be terminated while modifying data. 
247    * There is no chance for the thread to cleanup after itself, 
248    * unlock any held mutexes, etc. In short, use this function only if absolutely necessary. 
249    */
250   //QThread::wait(100);
251   //QThread::terminate();
252   //QThread::wait(400);
253 }
254
255
256 //------------------------------------------------------------------------
257 void VISU_TimeAnimation::_connectView()
258 {
259   connect( myView, SIGNAL( destroyed() ), this, SLOT( onViewDeleted() ) );
260 }
261
262 //------------------------------------------------------------------------
263 bool VISU_TimeAnimation::addField (_PTR(SObject) theField)
264 {
265   if (!theField) return false;
266
267   FieldData aNewData;
268   aNewData.myField = theField;
269   aNewData.myNbFrames = 0;
270   aNewData.myPrsType = VISU::TSCALARMAP;
271   aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
272
273   // initialize myResult in aNewData
274   _PTR(SObject) aSObj = theField->GetFather();
275   aSObj = aSObj->GetFather();
276   aSObj = aSObj->GetFather();
277   CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
278   if (CORBA::is_nil(anObject)) return false;
279   aNewData.myResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
280
281   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aNewData.myField);
282   if(VISU::Storable::FindValue(aMap,"myComment") != "FIELD")
283     return false;
284
285   aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
286
287   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
288     if ( aNewData.myNbTimes < 2 )
289       return false;
290     if ( !myFieldsLst.isEmpty() && myFieldsLst.first().myNbTimes != aNewData.myNbTimes )
291       return false;
292     if ( myFieldsLst.isEmpty() )
293       myFieldsAbsFrames.push_back(aNewData.myNbTimes);
294   }
295   else { // successive animation mode
296     if ( aNewData.myNbTimes < 1 )
297       return false;
298
299     long aNumCompCurr = VISU::Storable::FindValue(aMap, "myNumComponent").toLong();
300     if ( !myFieldsLst.isEmpty() ) {
301       VISU::Storable::TRestoringMap aFMap = VISU::Storable::GetStorableMap(myFieldsLst.first().myField);
302       long aNumComp = VISU::Storable::FindValue(aFMap, "myNumComponent").toLong();
303       if ( aNumCompCurr != aNumComp )
304         return false;
305     }
306
307     if ( !myFieldsLst.isEmpty() )
308       myFieldsAbsFrames.push_back(myFieldsAbsFrames.back() + aNewData.myNbTimes);
309     else
310       myFieldsAbsFrames.push_back(aNewData.myNbTimes);
311   }
312     
313   myFieldsLst.append(aNewData);
314   
315   //find Min/Max timestamps
316   _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
317   anIter->Next(); // First is reference on support
318   if ( myFieldsLst.size() == 1 ) { // the first field
319     myTimeMin = getTimeValue(anIter->Value());
320     myTimeMax = getTimeValue(anIter->Value());
321   }
322   for(; anIter->More(); anIter->Next()) {
323     if ( myTimeMin > getTimeValue(anIter->Value()) )
324       myTimeMin = getTimeValue(anIter->Value());
325     if ( myTimeMax < getTimeValue(anIter->Value()) )
326       myTimeMax = getTimeValue(anIter->Value());
327   }
328   
329   return true;
330 }
331
332 //------------------------------------------------------------------------
333 bool VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
334 {
335   SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
336   _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
337   return addField(aField);
338 }
339
340
341 //------------------------------------------------------------------------
342 void VISU_TimeAnimation::_clearData(FieldData& theData) {
343   if (!myView) {
344     MESSAGE("Viewer is not defined for animation");
345     return;
346   }
347   theData.myTiming.clear();
348   vtkRenderer* aRen = myView->getRenderer();
349   if (!theData.myActors.empty()) {
350     for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
351       if (theData.myActors[i] != 0) {
352         theData.myActors[i]->RemoveFromRender(aRen);
353       }
354     }
355     theData.myActors.clear();
356   }
357   if (!theData.myPrs.empty()) {
358     for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
359       if (theData.myPrs[i] != 0) {
360         theData.myPrs[i]->_remove_ref();
361       }
362     theData.myPrs.clear();
363   }
364   theData.myNbFrames = 0;
365   myView->update();
366 }
367
368 //------------------------------------------------------------------------
369 void VISU_TimeAnimation::clearData(FieldData& theData) {
370   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,FieldData&>
371                    (this,&VISU_TimeAnimation::_clearData,theData));
372 }
373
374 namespace
375 {
376   //------------------------------------------------------------------------
377   template<class TPrs3d>
378   void
379   GeneratePresentations(_PTR(Study) theStudy,
380                         FieldData& theData,
381                         VISU::Result_i* theResult,
382                         bool theIsRangeDefined,
383                         CORBA::Double theTimeMin,
384                         CORBA::Double theTimeMax,
385                         QList<long> theSequence)
386   {
387     _PTR(ChildIterator) anIter = theStudy->NewChildIterator(theData.myField);
388     anIter->Next(); // First is reference on support
389
390     long aSequenceLength = theSequence.count();
391     bool isSequenceDefined = aSequenceLength > 0;
392     if (isSequenceDefined)
393       theData.myPrs.resize(aSequenceLength,NULL);
394
395     long aFrameId = 0;
396     long aSequenceIndex = 1;
397     for(; anIter->More(); anIter->Next(), aSequenceIndex++){
398       if (aFrameId == theData.myNbTimes) {
399         MESSAGE("There are extra timestamps in field");
400         return;
401       }
402       _PTR(SObject) aTimeStamp = anIter->Value();
403       if(!aTimeStamp) 
404         continue;
405
406       long aSequenceId = -1;
407
408       theData.myTiming[aFrameId] = VISU_TimeAnimation::getTimeValue(aTimeStamp);
409       if (theIsRangeDefined) {
410         if (theData.myTiming[aFrameId] < theTimeMin) 
411           continue;
412         if (theData.myTiming[aFrameId] > theTimeMax) 
413           break;
414       }
415       else if (isSequenceDefined) {
416         aSequenceId = theSequence.indexOf( aSequenceIndex );
417         if( aSequenceId == -1 )
418           continue;
419       }
420
421       VISU::Storable::TRestoringMap aTimeMap = VISU::Storable::GetStorableMap(aTimeStamp);
422       QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
423       VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
424       QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
425       int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
426       
427       bool anIsCreated = false;
428       TPrs3d* aPresent = new TPrs3d(VISU::ColoredPrs3d_i::EDoNotPublish);
429       aPresent->SetCResult(theResult);
430       aPresent->SetMeshName(aMeshName.toLatin1().data());
431       aPresent->SetEntity(anEntity);
432       aPresent->SetFieldName(aFieldName.toLatin1().data());
433       aPresent->SetTimeStampNumber(aTimeStampId);
434       try{       
435 #ifdef NO_CAS_CATCH
436         OCC_CATCH_SIGNALS;
437 #endif
438         if(aPresent->Apply(false)){
439           /*
440             if(isSequenceDefined)
441             {
442               theData.myPrs[aSequenceId] = aPresent;
443               aFrameId++;
444             }
445             else
446           */
447           theData.myPrs[aFrameId++] = aPresent;
448           anIsCreated = true;
449         }
450       }catch(Standard_Failure) {
451         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
452         INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
453       }catch(std::exception& exc){
454         INFOS("Follow exception was occured :\n"<<exc.what());
455       }catch(...){
456         INFOS("Unknown exception was occured!");
457       }
458       if(!anIsCreated)
459         aPresent->_remove_ref();
460     }
461
462     theData.myNbFrames = aFrameId;
463
464     if (theData.myPrsType != VISU::TGAUSSPOINTS) {
465       for(long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++) {
466         if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(theData.myPrs[aFrameId])){
467           aPrs->SetOffset(theData.myOffset);
468         }
469       }
470     }
471   }
472 }
473
474 double getMinFieldsValue( QList<FieldData>& theFieldsLst )
475 {
476   // for successive animation mode only
477   double aRes;
478   for (int i = 0; i < theFieldsLst.count(); i++) {
479     if ( theFieldsLst[i].myPrs[0] ) {
480       aRes = theFieldsLst[i].myPrs[0]->GetMin();
481       break;
482     }
483   }
484
485   for (int i = 1; i < theFieldsLst.count() && theFieldsLst[i].myPrs[0]; i++) {
486     if ( aRes > theFieldsLst[i].myPrs[0]->GetMin() )
487       aRes = theFieldsLst[i].myPrs[0]->GetMin();    
488   }
489   return aRes;
490 }
491
492 double getMaxFieldsValue( QList<FieldData>& theFieldsLst )
493 {
494   // for successive animation mode only
495   double aRes;
496   for (int i = 0; i < theFieldsLst.count(); i++) {
497     if ( theFieldsLst[i].myPrs[0] ) {
498       aRes = theFieldsLst[i].myPrs[0]->GetMax();
499       break;
500     }
501   }
502
503   for (int i = 1; i < theFieldsLst.count() && theFieldsLst[i].myPrs[0]; i++) {
504     if ( aRes < theFieldsLst[i].myPrs[0]->GetMax() )
505       aRes = theFieldsLst[i].myPrs[0]->GetMax();    
506   }
507   return aRes;
508 }
509
510 void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum)
511 {
512   int nbf = myFieldsLst.size();
513   if( theFieldNum<0 || theFieldNum>nbf-1 )
514     return;
515
516   FieldData& aData = myFieldsLst[theFieldNum];
517
518   // Delete previous presentations
519   clearData(aData);
520
521   VISU::Result_i* aResult = createPresent(aData.myField);
522   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aData.myField);
523   aData.myNbFrames = aData.myNbTimes;
524   //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
525
526   aData.myPrs.resize(aData.myNbTimes,NULL);
527   aData.myTiming.resize(aData.myNbTimes);
528
529   QList<long> aSequence;
530   if( isSequenceDefined() )
531   {
532     bool ok = getIndicesFromSequence( mySequence, aSequence );
533     if( !ok )
534       return;
535   }
536
537   using namespace VISU;
538   switch (aData.myPrsType) {
539   case VISU::TSCALARMAP:
540     GeneratePresentations<ScalarMap_i>(myStudy,
541                                        aData,
542                                        aResult,
543                                        isRangeDefined(),
544                                        myTimeMinVal,
545                                        myTimeMaxVal,
546                                        aSequence);
547     break;
548   case VISU::TISOSURFACES: // Iso Surfaces
549     GeneratePresentations<IsoSurfaces_i>(myStudy,
550                                          aData,
551                                          aResult,
552                                          isRangeDefined(),
553                                          myTimeMinVal,
554                                          myTimeMaxVal,
555                                          aSequence);
556     break;
557   case VISU::TCUTPLANES: // Cut Planes
558     GeneratePresentations<CutPlanes_i>(myStudy,
559                                        aData,
560                                        aResult,
561                                        isRangeDefined(),
562                                        myTimeMinVal,
563                                        myTimeMaxVal,
564                                        aSequence);
565     break;
566   case VISU::TCUTLINES: // Cut Lines
567     GeneratePresentations<CutLines_i>(myStudy,
568                                       aData,
569                                       aResult,
570                                       isRangeDefined(),
571                                       myTimeMinVal,
572                                       myTimeMaxVal,
573                                       aSequence);
574     break;
575   case VISU::TCUTSEGMENT: // Cut Segment
576     GeneratePresentations<CutSegment_i>(myStudy,
577                                         aData,
578                                         aResult,
579                                         isRangeDefined(),
580                                         myTimeMinVal,
581                                         myTimeMaxVal,
582                                         aSequence);
583     break;
584   case VISU::TPLOT3D: // Plot3d
585     GeneratePresentations<Plot3D_i>(myStudy,
586                                     aData,
587                                     aResult,
588                                     isRangeDefined(),
589                                     myTimeMinVal,
590                                     myTimeMaxVal,
591                                     aSequence);
592     break;
593   case VISU::TDEFORMEDSHAPE: // Deformed Shape
594     GeneratePresentations<DeformedShape_i>(myStudy,
595                                            aData,
596                                            aResult,
597                                            isRangeDefined(),
598                                            myTimeMinVal,
599                                            myTimeMaxVal,
600                                            aSequence);
601     break;
602   case VISU::TVECTORS: // Vectors
603     GeneratePresentations<Vectors_i>(myStudy,
604                                      aData,
605                                      aResult,
606                                      isRangeDefined(),
607                                      myTimeMinVal,
608                                      myTimeMaxVal,
609                                      aSequence);
610     break;
611   case VISU::TSTREAMLINES: // Stream Lines
612     GeneratePresentations<StreamLines_i>(myStudy,
613                                          aData,
614                                          aResult,
615                                          isRangeDefined(),
616                                          myTimeMinVal,
617                                          myTimeMaxVal,
618                                          aSequence);
619     break;
620   case VISU::TGAUSSPOINTS: // Gauss Points
621     GeneratePresentations<GaussPoints_i>(myStudy,
622                                          aData,
623                                          aResult,
624                                          isRangeDefined(),
625                                          myTimeMinVal,
626                                          myTimeMaxVal,
627                                          aSequence);
628     break;
629   case VISU::TSCALARMAPONDEFORMEDSHAPE: // Scalar map on deformed shape
630   case VISU::TDEFORMEDSHAPEANDSCALARMAP:
631     GeneratePresentations<DeformedShapeAndScalarMap_i>(myStudy,
632                                                        aData,
633                                                        aResult,
634                                                        isRangeDefined(),
635                                                        myTimeMinVal,
636                                                        myTimeMaxVal,
637                                                        aSequence);
638     break;
639   default:
640     MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
641     return;
642   }
643   
644   if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) { // successive animation mode
645     if ( myFieldsAbsFrames.size() == getNbFields() ) 
646       myFieldsAbsFrames.clear();
647     if ( theFieldNum > 0 )
648       myFieldsAbsFrames.push_back(myFieldsAbsFrames.back() + aData.myNbFrames);      
649     else
650       myFieldsAbsFrames.push_back(aData.myNbFrames);
651
652     if (theFieldNum == getNbFields() - 1) {
653       if ( aData.myPrsType != VISU::TGAUSSPOINTS && aData.myPrsType != TDEFORMEDSHAPEANDSCALARMAP && aData.myPrsType != TSCALARMAPONDEFORMEDSHAPE) {
654
655         // Initialize the MinMax controller
656         VISU::PCompositeMinMaxController aMinMaxController(new VISU::TCompositeMinMaxController());
657         if ( myAnimationMode == VISU::Animation::PARALLEL ) {
658           FieldData& aFieldData = getFieldData(theFieldNum);
659           VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[0];
660           aMinMaxController->AddController( aPrs3d, VISU::CreateDefaultMinMaxController( aPrs3d ) );
661         } else {
662           for (int aFieldId = 0; aFieldId < getNbFields(); aFieldId++) {
663             FieldData& aFieldData = getFieldData(aFieldId);
664             VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[0];
665             aMinMaxController->AddController( aPrs3d, VISU::CreateDefaultMinMaxController( aPrs3d ) );
666           }
667         }
668
669         double aMin = getMinFieldsValue(myFieldsLst);
670         double aMax = getMaxFieldsValue(myFieldsLst);
671
672         for (int aFieldId = 0; aFieldId < getNbFields(); aFieldId++) {
673           FieldData& aFieldData = getFieldData(aFieldId);
674           for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
675             VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[aFrameId];
676             aPrs3d->SetMinMaxController(aMinMaxController);
677             if (VISU::IsoSurfaces_i* anIsoSurfaces = dynamic_cast<VISU::IsoSurfaces_i*>(aPrs3d))
678               anIsoSurfaces->SetSubRange(aMin, aMax);
679           }
680         }
681       }
682     }
683   }
684 }
685
686
687 //------------------------------------------------------------------------
688 CORBA::Boolean VISU_TimeAnimation::_generateFrames() {
689   if (!myView) {
690     MESSAGE("Viewer is not defined for animation");
691     return false;
692   }
693
694   myLastError = QString("Frame(s) for ");
695   bool aNoError = true;
696
697   clearView();
698
699   for (int i = 0; i < getNbFields(); i++) {
700     FieldData& aData = myFieldsLst[i];
701     aData.myActors.resize(aData.myNbFrames,NULL);
702     for (long j = 0; j < aData.myNbFrames; j++) {
703       VISU_Actor* aActor = NULL;
704       try{
705         aData.myPrs[j]->SetOffset(aData.myOffset);
706         aActor = aData.myPrs[j]->CreateActor();
707         myView->AddActor(aActor);
708         bool condition = ( myAnimationMode == VISU::Animation::PARALLEL ) ? (j == 0) : (j == 0 && i == 0);
709         if(condition)
710           aActor->VisibilityOn();
711         else
712           aActor->VisibilityOff();
713       }catch(...){ //catch(std::runtime_error& exc){
714         aNoError = false;
715         myLastError += QString("%1 ").arg(aData.myTiming[j]);
716       }
717       aData.myActors[j] = aActor;
718     }
719   }
720   myFrame = 0;
721   myLastError += QString(" timestamp(s) cannot be created.");
722   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
723                                                                             myFrame, myFieldsLst[0].myTiming[myFrame]));
724   myView->Repaint();
725   return aNoError;
726 }
727
728 //------------------------------------------------------------------------
729 CORBA::Boolean VISU_TimeAnimation::generateFrames()
730 {
731   return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
732                       (this,&VISU_TimeAnimation::_generateFrames));
733 }
734
735 //------------------------------------------------------------------------
736 void VISU_TimeAnimation::_clearView() {
737   if (!myView) {
738     MESSAGE("Viewer is not defined for animation");
739     return;
740   }
741   vtkRenderer* aRen = myView->getRenderer();
742   for (int i = 0; i < getNbFields(); i++) {
743     FieldData& aData = myFieldsLst[i];
744     if (!aData.myActors.empty()) {
745       for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
746         if (aData.myActors[i] != 0) {
747           aData.myActors[i]->RemoveFromRender(aRen);
748         }
749       }
750       aData.myActors.clear();
751     }
752   }
753   VISU::RepaintView(myView);
754 }
755
756 //------------------------------------------------------------------------
757 void VISU_TimeAnimation::clearView()
758 {
759   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
760                    (this,&VISU_TimeAnimation::_clearView));
761 }
762
763 //------------------------------------------------------------------------
764 void VISU_TimeAnimation::_visibilityOff(int num_field, int num_frame) {
765   if (!myView) {
766     MESSAGE("Viewer is not defined for animation");
767     return;
768   }
769   if ( num_field < 0 || num_frame < 0 ) return;
770   FieldData& aData = myFieldsLst[num_field];
771   if ( aData.myActors.empty() ) return;
772   VISU_Actor* aActor = aData.myActors[num_frame];
773   if (! myCleaningMemoryAtEachFrame) {
774     //
775     // Usual behaviour : VisibilityOff()
776     // Problem : It don't clean the memory so if there is
777     //           a lot of frames, the memory grows dramatically
778     //
779     aActor->VisibilityOff();
780   } else {
781     //
782     // myCleaningMemoryAtEachFrame behaviour:
783     // Delete the actor and re-creation it with VisibilityOff()
784     // since it takes memory only at VisibilityOn()
785     //
786     // Delete the actor
787     aActor->RemoveFromRender(myView->getRenderer());
788     // Re-create the actor
789     aActor = aData.myPrs[num_frame]->CreateActor();
790     myView->AddActor(aActor);
791     aActor->VisibilityOff();
792     aData.myActors[num_frame] = aActor;
793   }
794 }
795
796 //------------------------------------------------------------------------
797 void VISU_TimeAnimation::visibilityOff(int num_field, int num_frame)
798 {
799   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,int,int>
800                    (this,&VISU_TimeAnimation::_visibilityOff,num_field,num_frame));
801 }
802
803 //------------------------------------------------------------------------
804 void VISU_TimeAnimation::stopAnimation()
805 {
806   myExecutionState->SetActive(false);
807 }
808
809 //------------------------------------------------------------------------
810 void VISU_TimeAnimation::_startAnimation() {
811   if (!myExecutionState->IsActive()) {
812     myExecutionState->SetActive(true);
813     QThread::start();
814   }
815 }
816
817 //------------------------------------------------------------------------
818 void VISU_TimeAnimation::startAnimation()
819 {
820   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
821                    (this,&VISU_TimeAnimation::_startAnimation));
822 }
823
824 //------------------------------------------------------------------------
825 void VISU_TimeAnimation::_nextFrame() {
826   if (!myView) {
827     MESSAGE("Viewer is not defined for animation");
828     return;
829   }
830   stopAnimation();
831   if (myFrame < getNbFrames() - 1 ) { //(myFieldsLst[0].myNbFrames-1)) {
832     int i;
833     std::pair<int,long> aPair;
834     int aFieldId;
835     long aFrameId;
836
837     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
838       for (i = 0; i < getNbFields(); i++)
839         if (myFieldsLst[i].myActors[myFrame] != 0)
840           visibilityOff(i, myFrame);
841     }
842     else { //successive animation mode
843       aPair = getRelativeFrameNumber(myFrame);
844       aFieldId = aPair.first;
845       aFrameId = aPair.second;
846       if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
847         visibilityOff(aFieldId, aFrameId);
848     }
849
850     myFrame++;
851
852     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
853       for (i = 0; i < getNbFields(); i++)
854         if (myFieldsLst[i].myActors[myFrame] != 0)
855           myFieldsLst[i].myActors[myFrame]->VisibilityOn();
856
857       ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
858                                                                                 myFrame, myFieldsLst[0].myTiming[myFrame]));
859     }
860     else { //successive animation mode
861       aPair = getRelativeFrameNumber(myFrame);
862       aFieldId = aPair.first;
863       aFrameId = aPair.second;
864       if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
865         myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
866
867       ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
868                                                                                 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
869     }
870     myView->Repaint();
871   }
872 }
873
874 //------------------------------------------------------------------------
875 void VISU_TimeAnimation::nextFrame()
876 {
877   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
878                    (this,&VISU_TimeAnimation::_nextFrame));
879 }
880
881 //------------------------------------------------------------------------
882 void VISU_TimeAnimation::_prevFrame() {
883   if (!myView) {
884     MESSAGE("Viewer is not defined for animation");
885     return;
886   }
887   stopAnimation();
888   if (myFrame > 0) {
889     int i;
890     std::pair<int,long> aPair;
891     int aFieldId;
892     long aFrameId;
893
894     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
895       for (i = 0; i < getNbFields(); i++)
896         if (myFieldsLst[i].myActors[myFrame] != 0)
897           visibilityOff(i, myFrame);
898     }
899     else { //successive animation mode
900       aPair = getRelativeFrameNumber(myFrame);
901       aFieldId = aPair.first;
902       aFrameId = aPair.second;
903       if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
904           visibilityOff(aFieldId, aFrameId);
905     }
906
907     myFrame--;
908
909     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
910       for (i = 0; i < getNbFields(); i++)
911         if (myFieldsLst[i].myActors[myFrame] != 0)
912           myFieldsLst[i].myActors[myFrame]->VisibilityOn();
913
914       ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
915                                                                                 myFrame, myFieldsLst[0].myTiming[myFrame]));
916     }
917     else { //successive animation mode
918       aPair = getRelativeFrameNumber(myFrame);
919       aFieldId = aPair.first;
920       aFrameId = aPair.second;
921       if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
922           myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
923
924       ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
925                                                                                 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
926     }
927     myView->Repaint();
928   }
929 }
930
931 //------------------------------------------------------------------------
932 void VISU_TimeAnimation::prevFrame()
933 {
934   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
935                    (this,&VISU_TimeAnimation::_prevFrame));
936 }
937
938 //------------------------------------------------------------------------
939 void VISU_TimeAnimation::_firstFrame() {
940   if (!myView) {
941     MESSAGE("Viewer is not defined for animation");
942     return;
943   }
944   stopAnimation();
945   int i;
946   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
947     for (i = 0; i < getNbFields(); i++)
948       if(!myFieldsLst[i].myActors.empty())
949         if (myFieldsLst[i].myActors[myFrame] != 0)
950           visibilityOff(i, myFrame);
951     }
952   else { //successive animation mode
953     std::pair<int,long> aPair = getRelativeFrameNumber(myFrame);
954     int aFieldId = aPair.first;
955     long aFrameId = aPair.second;
956     if(!myFieldsLst[aFieldId].myActors.empty())
957       if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
958         visibilityOff(aFieldId, aFrameId);
959   }
960   myFrame = 0;
961
962   int imax;
963   if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode 
964     imax = getNbFields();
965   else //successive animation mode
966     imax = 1;
967
968   for (i = 0; i < imax; i++)
969     if(!myFieldsLst[i].myActors.empty())
970       if (myFieldsLst[i].myActors[myFrame] != 0)
971         myFieldsLst[i].myActors[myFrame]->VisibilityOn();
972
973   if(!myFieldsLst[0].myTiming.empty()){
974     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
975                                                                               myFrame, myFieldsLst[0].myTiming[myFrame]));
976     myView->Repaint();
977   }
978 }
979
980 //------------------------------------------------------------------------
981 void VISU_TimeAnimation::firstFrame()
982 {
983   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
984                    (this,&VISU_TimeAnimation::_firstFrame));
985 }
986
987 //------------------------------------------------------------------------
988 void VISU_TimeAnimation::_lastFrame() {
989   if (!myView) {
990     MESSAGE("Viewer is not defined for animation");
991     return;
992   }
993   stopAnimation();
994   int i;
995   std::pair<int,long> aPair;
996   int aFieldId;
997   long aFrameId;
998
999   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1000     for (i = 0; i < getNbFields(); i++)
1001       if (myFieldsLst[i].myActors[myFrame] != 0)
1002         visibilityOff(i, myFrame);
1003   }
1004   else { //successive animation mode
1005     aPair = getRelativeFrameNumber(myFrame);
1006     aFieldId = aPair.first;
1007     aFrameId = aPair.second;
1008     if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1009       visibilityOff(aFieldId, aFrameId);
1010   }
1011
1012   myFrame = getNbFrames() - 1; //myFieldsLst[0].myNbFrames-1;
1013
1014   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1015     for (i = 0; i < getNbFields(); i++)
1016       if (myFieldsLst[i].myActors[myFrame] != 0)
1017         myFieldsLst[i].myActors[myFrame]->VisibilityOn();
1018     
1019     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1020                                                                               myFrame, myFieldsLst[0].myTiming[myFrame]));
1021   }
1022   else { //successive animation mode
1023     aPair = getRelativeFrameNumber(myFrame);
1024     aFieldId = aPair.first;
1025     aFrameId = aPair.second;
1026     if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1027         myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
1028
1029     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1030                                                                               myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
1031   }
1032
1033   myView->Repaint();
1034 }
1035
1036 //------------------------------------------------------------------------
1037 void VISU_TimeAnimation::lastFrame()
1038 {
1039   ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1040                    (this,&VISU_TimeAnimation::_lastFrame));
1041 }
1042
1043
1044 //------------------------------------------------------------------------
1045 // For Batchmode using
1046 void VISU_TimeAnimation::_gotoFrame(CORBA::Long theFrame) {
1047   if (!myView) {
1048     MESSAGE("Viewer is not defined for animation");
1049     return;
1050   }
1051   if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
1052     return;
1053   stopAnimation();
1054   int i;
1055   std::pair<int,long> aPair;
1056   int aFieldId;
1057   long aFrameId;
1058   
1059   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1060     for (i = 0; i < getNbFields(); i++)
1061       if (myFieldsLst[i].myActors[myFrame] != 0)
1062         visibilityOff(i, myFrame);
1063   }
1064   else { //successive animation mode
1065     aPair = getRelativeFrameNumber(myFrame);
1066     aFieldId = aPair.first;
1067     aFrameId = aPair.second;
1068     if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1069         visibilityOff(aFieldId, aFrameId);
1070   }
1071
1072   myFrame = theFrame;
1073
1074   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1075     for (i = 0; i < getNbFields(); i++)
1076       if (myFieldsLst[i].myActors[myFrame] != 0)
1077         myFieldsLst[i].myActors[myFrame]->VisibilityOn();
1078
1079     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1080                                                                               myFrame, myFieldsLst[0].myTiming[myFrame]));
1081   }
1082   else { //successive animation mode
1083     aPair = getRelativeFrameNumber(myFrame);
1084     aFieldId = aPair.first;
1085     aFrameId = aPair.second;
1086     if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1087         myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
1088
1089     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1090                                                                               myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
1091   }
1092
1093   myView->Repaint();
1094 }
1095
1096 //------------------------------------------------------------------------
1097 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame)
1098 {
1099   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
1100                    (this,&VISU_TimeAnimation::_gotoFrame,theFrame));
1101 }
1102
1103 //------------------------------------------------------------------------
1104 void VISU_TimeAnimation::_emitFrameChanged(long theNewFrame, double theTime)
1105 {
1106   emit frameChanged(theNewFrame, theTime);
1107 }
1108
1109 //------------------------------------------------------------------------
1110 void VISU_TimeAnimation::_emitStopped()
1111 {
1112   emit stopped();
1113 }
1114
1115 //------------------------------------------------------------------------
1116 VISU::ColoredPrs3d_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
1117   if ((theField > getNbFields()) || (theField < 0))
1118     return VISU::ColoredPrs3d::_nil();
1119   if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
1120     return VISU::ColoredPrs3d::_nil();
1121   return myFieldsLst[theField].myPrs[theFrame]->_this();
1122 }
1123
1124 //------------------------------------------------------------------------
1125 void VISU_TimeAnimation::setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType) {
1126   if ( theFieldNum < 0 || theFieldNum >= myFieldsLst.size() )
1127     return;
1128
1129   myFieldsLst[theFieldNum].myPrsType = theType;
1130 }
1131
1132 //------------------------------------------------------------------------
1133 VISU::VISUType VISU_TimeAnimation::getPresentationType(CORBA::Long theFieldNum) {
1134   if ( theFieldNum < 0 || theFieldNum >= myFieldsLst.size() )
1135     return VISU::TNONE;
1136   
1137   return myFieldsLst[theFieldNum].myPrsType;
1138 }
1139
1140 //------------------------------------------------------------------------
1141 CORBA::Long VISU_TimeAnimation::getNbFrames() {
1142   if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
1143     return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
1144   else //successive animation mode
1145     return (getNbFields() > 0 && !myFieldsAbsFrames.empty()) ? myFieldsAbsFrames[myFieldsAbsFrames.size()-1] : 0;
1146 }
1147
1148 //------------------------------------------------------------------------
1149 long VISU_TimeAnimation::getAbsoluteFrameNumber(std::pair<int,long> theFieldTimeStamp)
1150 {
1151   long aRes = -1;
1152   if ( getNbFields() > 0 ) {
1153     int aFieldId = theFieldTimeStamp.first;
1154     long aFrameNum = theFieldTimeStamp.second + 1;
1155     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1156       if ( aFrameNum <= myFieldsAbsFrames[0] )
1157         aRes = aFrameNum;
1158     }
1159     else { //successive animation mode
1160       if ( aFieldId == 0 && aFrameNum <= myFieldsAbsFrames[aFieldId] )
1161         aRes = aFrameNum;
1162       else if ( aFieldId && aFrameNum <= myFieldsAbsFrames[aFieldId] - myFieldsAbsFrames[aFieldId-1] )
1163         aRes = myFieldsAbsFrames[aFieldId-1] + aFrameNum;
1164     }
1165   }
1166   return aRes - 1;
1167 }
1168
1169 //------------------------------------------------------------------------
1170 std::pair<int,long> VISU_TimeAnimation::getRelativeFrameNumber(long theFrame)
1171 {
1172   std::pair<int,long> aRes;
1173   if ( getNbFields() > 0 && theFrame < getNbFrames() ) {
1174     theFrame = theFrame + 1;
1175     if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1176       aRes.first = 0;
1177       aRes.second = theFrame - 1;
1178     }
1179     else { //successive animation mode
1180       for (int i = 0, iEnd = myFieldsAbsFrames.size(); i < iEnd; i++)
1181         if ( myFieldsAbsFrames[i] >= theFrame ) {
1182           aRes.first = i;
1183           if ( i == 0 )
1184             aRes.second = theFrame - 1;
1185           else
1186             aRes.second = theFrame-myFieldsAbsFrames[i-1] - 1;
1187           break;
1188         }
1189     }
1190   }
1191   return aRes;
1192 }
1193
1194 //------------------------------------------------------------------------
1195 void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QList<int>& theIndexList )
1196 {
1197   double k = 1;
1198   double aOneVal = 1;
1199   FieldData& aFirstFieldData = myFieldsLst[0];
1200   if (aFirstFieldData.myNbFrames > 2)
1201     aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames();
1202   int aNbFiles = 0;
1203
1204   bool aHasNextFrame = aFirstFieldData.myField && aFirstFieldData.myNbFrames > 0;
1205   while (aHasNextFrame && myExecutionState->IsActive()) {
1206     ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
1207                      (this, &VISU_TimeAnimation::_emitFrameChanged,
1208                       myFrame, aFirstFieldData.myTiming[myFrame]));
1209     if (myExecutionState->IsActive()) {
1210       for (int i = 0; i < getNbFields(); i++) {
1211         FieldData& aData = myFieldsLst[i];
1212         if (aData.myNbFrames == 0)
1213           continue;
1214         if (myFrame > 0) {
1215           if (aData.myActors[myFrame-1] != 0)
1216             visibilityOff(i, myFrame-1);
1217         } else {
1218           if (aData.myActors[aData.myNbFrames-1] != 0)
1219             visibilityOff(i, aData.myNbFrames-1);
1220         }
1221         if (aData.myActors[myFrame] != 0 && myView) {
1222           ProcessVoidEvent(new TVoidMemFunEvent<VISU_Actor>(aData.myActors[myFrame],
1223                                                             &VISU_Actor::VisibilityOn));
1224         }
1225       }
1226       if (!myView)
1227         return;
1228       bool repainArg = false;
1229       ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
1230                                                                       &SVTK_ViewWindow::Repaint,
1231                                                                       repainArg));
1232     }
1233
1234     k = 1;
1235     if (myProportional) {
1236       switch (myFrame) {
1237       case 0:
1238         break;
1239       case 1:
1240         if (aFirstFieldData.myNbFrames > 2)
1241           k = (aFirstFieldData.myTiming[myFrame+1] -
1242                aFirstFieldData.myTiming[myFrame]) / aOneVal;
1243         break;
1244       default:
1245         if (myFrame < (aFirstFieldData.myNbFrames - 1))
1246           k = (aFirstFieldData.myTiming[myFrame+1] -
1247                aFirstFieldData.myTiming[myFrame]) / aOneVal;
1248       }
1249     }
1250     int delay = (int)(1000. * k / mySpeed);
1251     theIsDumping = !myDumpPath.isEmpty();
1252     if (delay < 1 && theIsDumping) {
1253       // We must unlock mutex for some time before grabbing to allow view updating
1254       delay = 1;
1255     }
1256     msleep(delay);
1257     if (!myExecutionState->IsActive()) 
1258       return;
1259
1260     if (theIsDumping) {
1261       // We must unlock mutex for some time before grabbing to allow view updating
1262       msleep(delay);
1263       if (!myExecutionState->IsActive()) 
1264         return;
1265
1266       if (!(aFirstFieldData.myField)) // break, if field was deleted.
1267         break;
1268
1269       saveImages( 0, aOneVal, aNbFiles, theIndexList );
1270     }
1271
1272     if (!myExecutionState->IsActive()) 
1273       break;
1274
1275     myFrame++;
1276     if (myFrame == aFirstFieldData.myNbFrames) {
1277       if (!myCycling) {
1278         aHasNextFrame = false;
1279         myFrame--;
1280       }
1281       else
1282         myFrame = 0;
1283     }
1284   } // while (aHasNextFrame && myExecutionState->IsActive())
1285 }
1286
1287 //------------------------------------------------------------------------
1288 void VISU_TimeAnimation::successiveAnimation( bool& theIsDumping, QList<int>& theIndexList )
1289 {
1290   if (myFrame >= getNbFrames() - 1)
1291   {
1292     myExecutionState->SetActive(false);
1293     return;
1294   }
1295
1296   double k = 1;
1297   double aOneVal = 1;
1298   FieldData& aFirstFieldData = myFieldsLst[0];
1299   if (aFirstFieldData.myNbFrames > 2)
1300     aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames();
1301   int aNbFiles = 0;
1302   long aFrame = myFrame;
1303
1304   bool aHasNextFrame = true;
1305   while (aHasNextFrame && myExecutionState->IsActive())
1306   {
1307     for (int aFieldId = 0;
1308          (aFieldId < getNbFields()) && (myFieldsLst[aFieldId].myField);
1309          aFieldId++, aFrame = 0)
1310     {
1311       if (!myExecutionState->IsActive()) break;
1312
1313       FieldData& aData = myFieldsLst[aFieldId];
1314       if ( !aData.myPrs[0] ) continue;
1315       for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++)
1316       {
1317         ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
1318                          (this, &VISU_TimeAnimation::_emitFrameChanged,
1319                           myFrame, myFieldsLst[aFieldId].myTiming[aFrame]));
1320
1321         if (myExecutionState->IsActive()) {
1322           if (aFrame > 0) {
1323             if (aData.myActors[aFrame-1] != 0)
1324               visibilityOff(aFieldId, aFrame-1);
1325           } else if ( myFrame > 0) {
1326             if (myFieldsLst[aFieldId-1].myActors[myFieldsLst[aFieldId-1].myNbFrames-1] != 0)
1327               visibilityOff(aFieldId-1, myFieldsLst[aFieldId-1].myNbFrames-1);
1328           } else if ( myCycling ) {
1329             if (myFieldsLst[getNbFields()-1].myActors[myFieldsLst[getNbFields()-1].myNbFrames-1] != 0)
1330               visibilityOff(getNbFields()-1, myFieldsLst[getNbFields()-1].myNbFrames-1);
1331           } else {
1332             if (aData.myActors[aData.myNbFrames-1] != 0)
1333               visibilityOff(aFieldId, aData.myNbFrames-1);
1334           }
1335           if (aData.myActors[aFrame] != 0 && myView) {
1336             ProcessVoidEvent(new TVoidMemFunEvent<VISU_Actor>(aData.myActors[aFrame],
1337                                                               &VISU_Actor::VisibilityOn));
1338           }
1339
1340           if (!myView)
1341             return;
1342           bool repainArg = false;
1343           ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
1344                                                                           &SVTK_ViewWindow::Repaint,
1345                                                                           repainArg));
1346         }
1347
1348         k = 1;
1349         if (myProportional) {
1350           switch (aFrame) {
1351           case 0:
1352             break;
1353           case 1:
1354             if (aFirstFieldData.myNbFrames > 2)
1355               k = (aFirstFieldData.myTiming[aFrame+1] -
1356                    aFirstFieldData.myTiming[aFrame]) / aOneVal;
1357             break;
1358           default:
1359             if (aFrame < (aFirstFieldData.myNbFrames - 1))
1360               k = (aFirstFieldData.myTiming[aFrame+1] -
1361                    aFirstFieldData.myTiming[aFrame]) / aOneVal;
1362           }
1363         }
1364         int delay = (int)(1000. * k / mySpeed);
1365         theIsDumping = !myDumpPath.isEmpty();
1366         if (delay < 1 && theIsDumping) {
1367           // We must unlock mutex for some time before grabbing to allow view updating
1368           delay = 1;
1369         }
1370         msleep(delay);
1371
1372         if (!myExecutionState->IsActive()) return;
1373
1374         if (theIsDumping) {
1375           // We must unlock mutex for some time before grabbing to allow view updating
1376           msleep(delay);
1377           if (!myExecutionState->IsActive()) return;
1378
1379           if (!(myFieldsLst[aFieldId].myField)) // break, if field was deleted.
1380             break;
1381
1382           saveImages( aFieldId, aOneVal, aNbFiles, theIndexList );
1383         }
1384       } // for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++)
1385     } // for (int aFieldId = 0;
1386
1387     if (!myCycling) {
1388       aHasNextFrame = false;
1389       myFrame--;
1390     }
1391     else {
1392       myFrame = 0;
1393       aFrame = myFrame;
1394     }
1395   } // while (aHasNextFrame && myExecutionState->IsActive())
1396 }
1397
1398 //------------------------------------------------------------------------
1399 void VISU_TimeAnimation::saveImages( int theFieldId, 
1400                                      double& theOneVal, int& theNbFiles, 
1401                                      QList<int>& theIndexList )
1402 {
1403   if (myDumpFormat.compare("AVI") != 0) {
1404     QString aFile(myDumpPath);
1405
1406     int aFrameNb = myFrame; // parallel animation mode
1407     if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) // successive animation mode
1408       aFrameNb = getRelativeFrameNumber(myFrame).second;
1409
1410     int aMaxNb = myFieldsLst[theFieldId].myTiming.size();
1411     int nbDigits = QString("%1").arg(aMaxNb).length();
1412     QString aFormat = QString("%.%1d_").arg(nbDigits);
1413
1414     QString aName;
1415     aName.sprintf(aFormat.toLatin1().data(), aFrameNb);
1416     aName += QString("%1").arg(myFieldsLst[theFieldId].myTiming[aFrameNb]);
1417
1418     int aPos = -1;
1419     while ((aPos = aName.indexOf(".")) > -1 )
1420       aName.replace(aPos, 1, "_");
1421     aFile += aName;
1422     aFile += ".";
1423     aFile += myDumpFormat.toLower();
1424     ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1425                      (myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
1426     ProcessEvent(new TMemFun2ArgEvent<SUIT_ViewWindow,bool,const QString&,const QString&>
1427                  (myView,&SUIT_ViewWindow::dumpViewToFormat,aFile,myDumpFormat));
1428   } else {
1429     QFileInfo aFileInfo(myDumpPath);
1430     QString aDirPath = aFileInfo.absolutePath();
1431     QString aBaseName = aFileInfo.fileName();
1432     
1433     if( myTimeStampFrequency > 1 && myFrame % myTimeStampFrequency != 0 )
1434       return;
1435
1436     switch (myFrame) {
1437     case 0: 
1438       break;
1439     case 1:
1440       myFileIndex += 5;
1441       break;
1442     default:
1443       if (myProportional) {
1444         FieldData& aFirstFieldData = myFieldsLst[0];
1445         double p = (aFirstFieldData.myTiming[myFrame] -
1446                     aFirstFieldData.myTiming[myFrame-1]) / theOneVal;
1447         myFileIndex += (long) (5*p);
1448       } else {
1449         myFileIndex += 5;
1450       }
1451     }
1452     
1453     QString aFile = aDirPath + QDir::separator() + aBaseName;
1454     aFile += "_";
1455     aFile += QString("%1").arg(myFileIndex).rightJustified(8, '0');
1456     aFile += ".jpeg";
1457     
1458     /* check image size is divisable 16
1459        myView->dumpViewToFormat(aFile,"JPEG");
1460     */
1461     SUIT_ViewWindow* aView = myView;
1462     ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>(myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
1463     QImage img = ProcessEvent(new TMemFunEvent<SUIT_ViewWindow,QImage>(aView,&SUIT_ViewWindow::dumpView));
1464     if (!img.isNull()) {
1465       int width = img.width(); width = (width/16)*16;
1466       int height = img.height(); height = (height/16)*16;
1467       QImage copy = img.copy(0, 0, width, height);
1468       if (copy.save(aFile, "JPEG")) {
1469         theIndexList.append(myFileIndex);
1470         theNbFiles++;
1471       }
1472     }
1473   }
1474 }
1475
1476 //------------------------------------------------------------------------
1477 void VISU_TimeAnimation::run()
1478 {
1479   if (!myView) {
1480     MESSAGE("Viewer is not defined for animation");
1481     return;
1482   }
1483
1484   bool isDumping = !myDumpPath.isEmpty();
1485   myFileIndex = 0;
1486   QList<int> anIndexList;
1487
1488   if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
1489     parallelAnimation( isDumping, anIndexList );
1490   else //successive animation mode
1491     successiveAnimation( isDumping, anIndexList );
1492
1493   // make AVI file if need
1494   if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) {
1495     double aFPS = 17.3 * mySpeed / myTimeStampFrequency;
1496
1497     QFileInfo aFileInfo(myDumpPath);
1498     QString aDirPath = aFileInfo.absolutePath();
1499     QString aBaseName = aFileInfo.fileName();
1500
1501     // add missing files
1502     if (anIndexList.count() > 1) {
1503       QString aFFile = aDirPath + "/" + aBaseName;
1504       aFFile += QString("_%1.jpeg");
1505       int aStartIndex = anIndexList[0], anEndIndex;
1506       for (int i = 1; i < anIndexList.count(); i++) {
1507         anEndIndex = anIndexList[i];
1508         QString aCurFile = aFFile.arg(QString::number(aStartIndex).rightJustified(8, '0'));
1509         QStringList aCommands;
1510         QString aSeparator;
1511         for (int j = aStartIndex+1; j < anEndIndex; j++) {
1512           QString aFile = aFFile.arg(QString::number(j).rightJustified(8, '0'));
1513 #ifndef WIN32
1514           aCommands.append(QString("ln -s %1 %2").arg(aCurFile).arg(aFile));
1515           aSeparator = QString(" ; \\\n");
1516 #else
1517           aCommands.append(QString("COPY /Y %1 %2 > NUL").arg(QString(aCurFile).replace("/","\\\\")).arg(QString(aFile).replace("/","\\\\")));
1518           aSeparator = QString(" & ");
1519 #endif
1520         }
1521         system(aCommands.join(aSeparator).toLatin1().data());
1522         aStartIndex = anEndIndex;
1523       }
1524     }
1525
1526     // make AVI file
1527     QString aPattern = aDirPath + "/" + aBaseName;
1528     aPattern += "_\%08d.jpeg";
1529
1530     QString aCmd = myAVIMaker;
1531     aCmd += " -I p";
1532     aCmd += " -v 0";
1533     aCmd += QString(" -f %1").arg(aFPS);
1534     // aCmd += QString(" -n %1").arg(aNbFiles);
1535     aCmd += QString(" -n %1").arg(myFileIndex+1);
1536     aCmd += QString(" -j \"%1\"").arg(aPattern);
1537     aCmd += " | yuv2lav";
1538     aCmd += QString(" -o \"%1\"").arg(myDumpPath);
1539   #ifdef WIN32
1540     aCmd += " -f aA";   
1541   #endif
1542     system(aCmd.toLatin1().data());
1543
1544     // remove temporary jpeg files
1545 #ifndef WIN32
1546     aCmd = "( ";
1547     aCmd += QString("cd %1").arg(aDirPath);
1548     aCmd += "; ls";
1549     aCmd += QString(" | egrep '%1_[0-9]*.jpeg'").arg(aBaseName);
1550     aCmd += " | xargs rm";
1551     aCmd += " )";
1552 #else
1553   QString tmpFile = QString("_") + aBaseName + "_tempfile";
1554   QString diskName = aDirPath.split("/")[0];
1555   aCmd = diskName + " && (cd " + aDirPath.replace("/","\\\\") + 
1556     " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile + 
1557     ") & (for /f %i in (" + tmpFile + ") do (del \"%i\")) & (del " + tmpFile + "))) > NUL";
1558 #endif
1559     system(aCmd.toLatin1().data());
1560   }
1561
1562   if (myExecutionState->IsActive())
1563     ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
1564   myExecutionState->SetActive(false);
1565 }
1566
1567 //------------------------------------------------------------------------
1568 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
1569 {
1570   _PTR(SObject) aSObj = theField->GetFather();
1571   aSObj = aSObj->GetFather();
1572   aSObj = aSObj->GetFather();
1573   CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
1574   if (CORBA::is_nil(anObject)) return NULL;
1575   return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
1576 }
1577
1578 //------------------------------------------------------------------------
1579 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
1580 {
1581   _PTR(GenericAttribute) anAttr;
1582   if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
1583     _PTR(AttributeName) aName (anAttr);
1584     QString aNameString (aName->Value().c_str());
1585     int time_len = aNameString.indexOf(',');
1586     if (time_len > -1)
1587       return aNameString.left(time_len).toDouble();
1588     else
1589       return aNameString.toDouble();
1590   }
1591   return -1.0;
1592 }
1593
1594 //------------------------------------------------------------------------
1595 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
1596 {
1597   mySpeed = (theSpeed<1)? 1 : theSpeed;
1598 }
1599
1600 //------------------------------------------------------------------------
1601 void VISU_TimeAnimation::setAnimationSequence(const char* theSequence)
1602 {
1603   mySequence = QString( theSequence );
1604 }
1605
1606 //------------------------------------------------------------------------
1607 char* VISU_TimeAnimation::getAnimationSequence()
1608 {
1609   return strdup( mySequence.toLatin1().data() );
1610 }
1611
1612 //------------------------------------------------------------------------
1613 CORBA::Boolean VISU_TimeAnimation::isSequenceDefined()
1614 {
1615   return !mySequence.isEmpty();
1616 }
1617
1618 //------------------------------------------------------------------------
1619 bool VISU_TimeAnimation::getIndicesFromSequence( QString theSequence, QList<long>& theIndices )
1620 {
1621   bool isCorrect = true;
1622
1623   theIndices.clear();
1624
1625   QStringList aList = theSequence.split( ",", QString::SkipEmptyParts );
1626   QStringList::iterator it = aList.begin();
1627   QStringList::iterator itEnd = aList.end();
1628   for( ; it != itEnd; ++it )
1629   {
1630     if( !isCorrect )
1631       break;
1632
1633     isCorrect = false;
1634
1635     QString aString = *it;
1636     if( aString.isEmpty() )
1637       continue;
1638
1639     bool ok = false;
1640     int aSingleIndex = aString.toLong( &ok );
1641     if( ok )
1642     {
1643       theIndices.append( aSingleIndex );
1644       isCorrect = true;
1645     }
1646     else if( aString.contains( '-' ) == 1 )
1647     {
1648       QString aLeftIndexStr = aString.section( '-', 0, 0 );
1649       QString aRightIndexStr = aString.section( '-', -1 );
1650
1651       ok = false;
1652       int aLeftIndex = aLeftIndexStr.toLong( &ok );
1653       if( !ok )
1654         continue;
1655
1656       ok = false;
1657       int aRightIndex = aRightIndexStr.toLong( &ok );
1658       if( !ok )
1659         continue;
1660
1661       if( aLeftIndex >= aRightIndex )
1662         continue;
1663
1664       for( int i = aLeftIndex; i <= aRightIndex; i++ )
1665         theIndices.append( i );
1666
1667       isCorrect = true;
1668     }
1669   }
1670
1671   return isCorrect;
1672 }
1673
1674 //------------------------------------------------------------------------
1675 std::string VISU_TimeAnimation::setDumpFormat(const char* theFormat)
1676 {
1677   myDumpFormat = theFormat;
1678   QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
1679   if (myDumpFormat.isEmpty() || 
1680       (aDumpFormats.indexOf(theFormat) < 0 && myDumpFormat.compare("AVI") != 0)) {
1681     if (aDumpFormats.indexOf("JPEG") >= 0 ||
1682         aDumpFormats.indexOf("jpeg") >= 0)
1683       myDumpFormat = "JPEG";
1684     else
1685       myDumpFormat = aDumpFormats.at(0);
1686   }
1687   return myDumpFormat.toLatin1().data();
1688 }
1689
1690 //------------------------------------------------------------------------
1691 void VISU_TimeAnimation::setTimeStampFrequency(CORBA::Long theFrequency)
1692 {
1693   myTimeStampFrequency = theFrequency;
1694 }
1695
1696 //------------------------------------------------------------------------
1697 bool VISU_TimeAnimation::checkAVIMaker() const
1698 {
1699   QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
1700   if (aDumpFormats.indexOf("JPEG") < 0 &&
1701       aDumpFormats.indexOf("jpeg") < 0)
1702     return false;
1703
1704   QString aCmd;
1705 #ifndef WIN32
1706   aCmd = "which " + myAVIMaker + " 2> /dev/null";
1707 #else
1708   aCmd = "setlocal & set P2=.;%PATH% & (for %e in (%PATHEXT%) do @for %i in (" + myAVIMaker + "%e) do @if NOT \"%~$P2:i\"==\"\" exit /b 0) & exit /b 1";
1709 #endif
1710   int iErr = system(aCmd.toLatin1().data());
1711   return (iErr == 0);
1712 }
1713
1714 //************************************************************************
1715 int VISU_TimeAnimation::myNBAnimations = 0;
1716 QString VISU_TimeAnimation::GenerateName()
1717 {
1718   return VISU::GenerateName("Animation", myNBAnimations++);
1719 }
1720
1721 //------------------------------------------------------------------------
1722 std::string GetPresentationComment (VISU::VISUType thePrsType)
1723 {
1724   std::string aPrsCmt;
1725   switch (thePrsType) {
1726   case VISU::TSCALARMAP:
1727     aPrsCmt = VISU::ScalarMap_i::myComment;
1728     break;
1729   case VISU::TISOSURFACES:
1730     aPrsCmt = VISU::IsoSurfaces_i::myComment;
1731     break;
1732   case VISU::TCUTPLANES:
1733     aPrsCmt = VISU::CutPlanes_i::myComment;
1734     break;
1735   case VISU::TCUTLINES:
1736     aPrsCmt = VISU::CutLines_i::myComment;
1737     break;
1738   case VISU::TCUTSEGMENT:
1739     aPrsCmt = VISU::CutSegment_i::myComment;
1740     break;
1741   case VISU::TPLOT3D:
1742     aPrsCmt = VISU::Plot3D_i::myComment;
1743     break;
1744   case VISU::TDEFORMEDSHAPE:
1745     aPrsCmt = VISU::DeformedShape_i::myComment;
1746     break;
1747   case VISU::TVECTORS:
1748     aPrsCmt = VISU::Vectors_i::myComment;
1749     break;
1750   case VISU::TSTREAMLINES:
1751     aPrsCmt = VISU::StreamLines_i::myComment;
1752     break;
1753   case VISU::TGAUSSPOINTS:
1754     aPrsCmt = VISU::GaussPoints_i::myComment;
1755     break;
1756   case VISU::TSCALARMAPONDEFORMEDSHAPE:
1757   case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1758     aPrsCmt = VISU::DeformedShapeAndScalarMap_i::myComment;
1759     break;
1760   default:
1761     aPrsCmt = "Unknown presentation";
1762     break;
1763   }
1764   return aPrsCmt;
1765 }
1766
1767 //------------------------------------------------------------------------
1768 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
1769 {
1770   if (myStudy->GetProperties()->IsLocked()) {
1771     SUIT_MessageBox::warning(0,
1772                              QObject::tr("WRN_VISU_WARNING"),
1773                              QObject::tr("WRN_STUDY_LOCKED"),
1774                              QObject::tr("BUT_OK"));
1775     return SALOMEDS::SObject::_nil();
1776   }
1777
1778   _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
1779   aStudyBuilder->NewCommand();  // There is a transaction
1780   _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
1781   std::string aSComponentEntry = aSComponent->GetID();
1782
1783   QString aComment;
1784   aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
1785                    myTimeMinVal,
1786                    myTimeMaxVal,
1787                    mySequence.toLatin1().data(),
1788                    myAnimationMode);
1789
1790   string anEntry = VISU::CreateAttributes(myStudy,
1791                                           aSComponentEntry.c_str(),
1792                                           VISU::NO_ICON,
1793                                           VISU::NO_IOR,
1794                                           GenerateName().toLatin1().data(),
1795                                           VISU::NO_PERFSITENT_REF,
1796                                           aComment.toLatin1().data(),
1797                                           true);
1798   myAnimEntry = anEntry.c_str();
1799   _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
1800
1801   for (int i = 0; i < getNbFields(); i++) {
1802     FieldData& aData = myFieldsLst[i];
1803     if (aData.myPrs.empty()) {
1804       generatePresentations(i);
1805     }
1806     if ( !aData.myPrs.empty() ) {
1807       _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
1808       aStudyBuilder->Addreference(newObj, aData.myField);
1809       
1810       ostringstream strOut;
1811       aData.myPrs[0]->ToStream(strOut);
1812       string aPrsComment = strOut.str();
1813       string aPrsMyComment = aData.myPrs[0]->GetComment();
1814       if(aPrsMyComment == "PRSMERGER")
1815         aPrsMyComment = "SCALARMAP";
1816       VISU::CreateAttributes(myStudy, 
1817                              newObj->GetID().c_str(),
1818                              VISU::NO_ICON,
1819                              VISU::NO_IOR,
1820                              aPrsMyComment.c_str(),
1821                              VISU::NO_PERFSITENT_REF,
1822                              aPrsComment.c_str(),
1823                              true);
1824     }
1825   }
1826   aStudyBuilder->CommitCommand();
1827
1828   return VISU::GetSObject(aAnimSObject)._retn();
1829 }
1830
1831 //------------------------------------------------------------------------
1832 void VISU_TimeAnimation::saveAnimation()
1833 {
1834   if (myStudy->GetProperties()->IsLocked()) return;
1835   if (myAnimEntry.isEmpty()) return;
1836
1837   _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.toLatin1().data());
1838   if (!aAnimSObject) return;
1839
1840   _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
1841   aStudyBuilder->NewCommand();  // There is a transaction
1842   _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
1843   std::string aSComponentEntry = aSComponent->GetID();
1844
1845   QString aComment;
1846   aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
1847                    myTimeMinVal,
1848                    myTimeMaxVal,
1849                    mySequence.toLatin1().data(),
1850                    myAnimationMode);
1851
1852   _PTR(GenericAttribute) anAttr;
1853   anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeString");
1854   _PTR(AttributeString) aCmnt (anAttr);
1855   aCmnt->SetValue(aComment.toLatin1().data());
1856
1857   _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
1858   int i = 0, nbf = getNbFields();
1859   for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
1860     if (i >= nbf) break; // it must not be
1861     FieldData& aData = myFieldsLst[i];
1862
1863     // Get presentation name and comment
1864     if (aData.myPrs.empty()) {
1865       generatePresentations(i);
1866     }
1867     ostringstream strOut;
1868     aData.myPrs[0]->ToStream(strOut);
1869     string aPrsComment = strOut.str();
1870     string aPrsNameTxt = aData.myPrs[0]->GetComment();
1871     if(aPrsNameTxt == "PRSMERGER")
1872       aPrsNameTxt = "SCALARMAP";
1873     // Save in study
1874     _PTR(SObject) aRefObj = anIter->Value();
1875     _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
1876     anPrsIter->Init();
1877
1878     if (anPrsIter->More()) {
1879       _PTR(SObject) aPrsObj = anPrsIter->Value();
1880       anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeString");
1881       aCmnt = _PTR(AttributeString)(anAttr);
1882       aCmnt->SetValue(aPrsComment.c_str());
1883
1884       anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
1885       _PTR(AttributeName) aPrsName (anAttr);
1886       aPrsName->SetValue(aPrsNameTxt);
1887
1888     } else {
1889       VISU::CreateAttributes(myStudy, 
1890                              aRefObj->GetID().c_str(),
1891                              VISU::NO_ICON,
1892                              VISU::NO_IOR,
1893                              aPrsNameTxt.c_str(),
1894                              VISU::NO_PERFSITENT_REF,
1895                              aPrsComment.c_str(),
1896                              true);
1897     }
1898   }
1899   aStudyBuilder->CommitCommand();
1900 }
1901
1902 //------------------------------------------------------------------------
1903 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
1904 {
1905   _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
1906   restoreFromStudy(aAnimSObject);
1907 }
1908
1909 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
1910 {
1911   _PTR(SObject) aAnimSObject = theField;
1912
1913   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aAnimSObject);
1914   if (aMap.empty()) 
1915     return;
1916
1917   bool isExist;
1918   myTimeMinVal = VISU::Storable::FindValue(aMap,"myTimeMinVal",&isExist).toDouble();
1919   myTimeMaxVal = VISU::Storable::FindValue(aMap,"myTimeMaxVal",&isExist).toDouble();
1920   mySequence = VISU::Storable::FindValue(aMap,"mySequence",&isExist);
1921   myAnimationMode = VISU::Animation::AnimationMode(VISU::Storable::FindValue(aMap,"myMode",&isExist).toInt());
1922
1923   _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
1924   for (anIter->Init(); anIter->More(); anIter->Next()) {
1925     _PTR(SObject) aRefObj = anIter->Value();
1926     _PTR(SObject) aFieldObj;
1927
1928     if (!aRefObj->ReferencedObject(aFieldObj) ) 
1929       continue;
1930
1931     int nbAttr = aFieldObj->GetAllAttributes().size();
1932     //std::string name1 = aFieldObj->GetName();
1933     if(nbAttr<1)
1934       continue;
1935
1936     addField(aFieldObj);
1937     if ( isRangeDefined() || isSequenceDefined() ) 
1938       myFieldsAbsFrames.pop_back();
1939
1940     FieldData& aData = getFieldData(getNbFields()-1);
1941     
1942     // Get Presentation object
1943     _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
1944     anPrsIter->Init();
1945     if (!anPrsIter->More()) 
1946       continue;
1947     _PTR(SObject) aPrsObj = anPrsIter->Value();
1948     _PTR(GenericAttribute) anAttr;
1949     if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) 
1950       continue;
1951     _PTR(AttributeName) aName (anAttr);
1952     string aStr = aName->Value();
1953     QString strName (aStr.c_str());
1954
1955     if (strName == VISU::ScalarMap_i::myComment.c_str())
1956       aData.myPrsType = VISU::TSCALARMAP;
1957     else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
1958       aData.myPrsType = VISU::TISOSURFACES;
1959     else if (strName == VISU::CutPlanes_i::myComment.c_str())
1960       aData.myPrsType = VISU::TCUTPLANES;
1961     else if (strName == VISU::CutLines_i::myComment.c_str())
1962       aData.myPrsType = VISU::TCUTLINES;
1963     else if (strName == VISU::CutSegment_i::myComment.c_str())
1964       aData.myPrsType = VISU::TCUTSEGMENT;
1965     else if (strName == VISU::Plot3D_i::myComment.c_str())
1966       aData.myPrsType = VISU::TPLOT3D;
1967     else if (strName == VISU::DeformedShape_i::myComment.c_str())
1968       aData.myPrsType = VISU::TDEFORMEDSHAPE;
1969     else if (strName == VISU::Vectors_i::myComment.c_str())
1970       aData.myPrsType = VISU::TVECTORS;
1971     else if (strName == VISU::StreamLines_i::myComment.c_str())
1972       aData.myPrsType = VISU::TSTREAMLINES;
1973     else if (strName == VISU::GaussPoints_i::myComment.c_str())
1974       aData.myPrsType = VISU::TGAUSSPOINTS;
1975     else if (strName == VISU::DeformedShapeAndScalarMap_i::myComment.c_str())
1976       aData.myPrsType = VISU::TDEFORMEDSHAPEANDSCALARMAP;
1977     else
1978       continue;
1979     generatePresentations(getNbFields()-1);
1980
1981     VISU::Storable::TRestoringMap aPrsMap = VISU::Storable::GetStorableMap(aPrsObj);
1982     if (aPrsMap.empty())
1983       continue;
1984     if (aData.myPrs[0]) {
1985       aData.myPrs[0]->Restore(VISU::GetSObject(aData.myField), aPrsMap);
1986       aData.myPrs[0]->GetOffset(aData.myOffset);
1987     }
1988     for (int i = 1; i < aData.myNbFrames; i++) {
1989       if (!aData.myPrs[0])
1990         continue;
1991       bool anIsFixedRange = false;
1992       if (aData.myPrsType != VISU::TGAUSSPOINTS) {
1993         if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(aData.myPrs[i]))
1994           anIsFixedRange = aPrs->IsRangeFixed();
1995       }
1996       if (aData.myPrsType == VISU::TDEFORMEDSHAPEANDSCALARMAP) {
1997         if (VISU::DeformedShapeAndScalarMap_i* aDeformedPrs =
1998             dynamic_cast<VISU::DeformedShapeAndScalarMap_i*>(aData.myPrs[i])) {
1999           //Set correct time stamp number
2000           int aTimeStampNum = aDeformedPrs->GetScalarTimeStampNumber();
2001           aDeformedPrs->SameAs(aData.myPrs[0]);
2002           aDeformedPrs->SetScalarField(aDeformedPrs->GetScalarEntity(),
2003                                        aDeformedPrs->GetScalarFieldName(),
2004                                        aTimeStampNum);
2005         }
2006       }
2007       else
2008         aData.myPrs[i]->SameAs(aData.myPrs[0]);
2009     }
2010   }
2011   string aStr = aAnimSObject->GetID();
2012   myAnimEntry = aStr.c_str();
2013 }
2014
2015 void VISU_TimeAnimation::onViewDeleted()
2016 {
2017   myView = 0;
2018   stopAnimation();
2019 }
2020
2021 void VISU_TimeAnimation::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs)
2022   throw (SALOME::SALOME_Exception)
2023 {
2024   Unexpect aCatch(SALOME_SalomeException);
2025
2026   VISU::ColoredPrs3d_i* aPrs_i = dynamic_cast<VISU::ColoredPrs3d_i*>(GetServant(thePrs).in());
2027
2028   if ( !aPrs_i ) 
2029     THROW_SALOME_CORBA_EXCEPTION("Error : invalid dynamic cast of the given presentation to VISU::ColoredPrs3d_i",
2030                                  SALOME::INTERNAL_ERROR);
2031   
2032   if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
2033     FieldData& aData = myFieldsLst[theFieldNum];
2034     
2035     if ( aData.myPrs.empty() )
2036       THROW_SALOME_CORBA_EXCEPTION("Error : presentations for the given field is not yet created!",
2037                                    SALOME::INTERNAL_ERROR);
2038     
2039     if ( aPrs_i->GetCResult() != aData.myPrs[0]->GetCResult() )
2040       THROW_SALOME_CORBA_EXCEPTION("Error : the MED file is not the same!",
2041                                    SALOME::INTERNAL_ERROR);
2042     
2043     for (int i = 0; i < aData.myNbFrames; i++) {
2044       bool anIsFixedRange = false;
2045       if (aData.myPrsType != VISU::TGAUSSPOINTS) {
2046         if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(aData.myPrs[i]))
2047           anIsFixedRange = aPrs->IsRangeFixed();
2048       }
2049       aData.myPrs[i]->SameAs(aPrs_i);
2050     }
2051   }
2052   else if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) { // successive animation mode
2053     for (int f = 0; f < getNbFields(); f++) {
2054       FieldData& aData = myFieldsLst[f];
2055       
2056       if ( aData.myPrs.empty() )
2057         THROW_SALOME_CORBA_EXCEPTION("Error : presentations for the given field is not yet created!",
2058                                      SALOME::INTERNAL_ERROR);
2059       
2060       for (int i = 0; i < aData.myNbFrames; i++) {
2061         aData.myPrs[i]->SameAs(aPrs_i);
2062       }
2063     }
2064   }
2065 }
2066
2067 //========================================================================
2068 //========================================================================
2069 //========================================================================
2070 struct TNewAnimationEvent: public SALOME_Event
2071 {
2072   std::string myStudyName;
2073   VISU::View3D_ptr myView3D;
2074
2075   typedef VISU_TimeAnimation* TResult;
2076   TResult myResult;
2077
2078   TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
2079     myStudyName(theStudyName),
2080     myView3D(VISU::View3D::_duplicate(theView3D)),
2081     myResult(NULL)
2082   {}
2083
2084   virtual
2085   void
2086   Execute()
2087   {
2088     SUIT_Session* aSession = SUIT_Session::session();
2089     QList<SUIT_Application*> anApplications = aSession->applications();
2090     QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
2091     while ( anIter !=  anApplications.end() ) {
2092       SUIT_Application* anApp = *anIter;
2093       if (SUIT_Study* aSStudy = anApp->activeStudy()) {
2094         if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
2095           if (_PTR(Study) aCStudy = aStudy->studyDS()) {
2096             if (myStudyName == aCStudy->Name()) {
2097               myResult = new VISU_TimeAnimation (aCStudy, myView3D);
2098               break;
2099             }
2100           }
2101         }
2102       }
2103       anIter++;
2104     }
2105   }
2106 };
2107
2108 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
2109                                             VISU::View3D_ptr theView3D)
2110 {
2111   std::string aStudyName = theStudy->Name();
2112   myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
2113 }
2114
2115 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
2116 {
2117   delete myAnim;
2118 }
2119
2120 bool VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
2121 {
2122   return myAnim->addField(theField);
2123 }
2124
2125 void VISU_TimeAnimation_i::clearFields ()
2126 {
2127   for (int i = 0; i < myAnim->getNbFields(); i++) {
2128     myAnim->clearData(myAnim->getFieldData(i));
2129   }
2130   myAnim->clearFieldData();
2131 }
2132
2133 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
2134 {
2135   //return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
2136   //                    (myAnim,&VISU_TimeAnimation::generateFrames));
2137   return myAnim->generateFrames();
2138 }
2139
2140 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
2141 {
2142   myAnim->generatePresentations(theFieldNum);
2143 }
2144
2145 void VISU_TimeAnimation_i::clearView()
2146 {
2147   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2148   //                 (myAnim,&VISU_TimeAnimation::clearView));
2149   myAnim->clearView();
2150 }
2151
2152 void VISU_TimeAnimation_i::stopAnimation()
2153 {
2154   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2155   //                 (myAnim,&VISU_TimeAnimation::stopAnimation));
2156   myAnim->stopAnimation();
2157 }
2158
2159 void VISU_TimeAnimation_i::startAnimation()
2160 {
2161   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2162   //                 (myAnim,&VISU_TimeAnimation::startAnimation));
2163   myAnim->startAnimation();
2164 }
2165
2166 void VISU_TimeAnimation_i::nextFrame()
2167 {
2168   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2169   //                 (myAnim,&VISU_TimeAnimation::nextFrame));
2170   myAnim->nextFrame();
2171 }
2172
2173 void VISU_TimeAnimation_i::prevFrame()
2174 {
2175   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2176   //                 (myAnim,&VISU_TimeAnimation::prevFrame));
2177   myAnim->prevFrame();
2178 }
2179
2180 void VISU_TimeAnimation_i::firstFrame()
2181 {
2182   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2183   //                 (myAnim,&VISU_TimeAnimation::firstFrame));
2184   myAnim->firstFrame();
2185 }
2186
2187 void VISU_TimeAnimation_i::lastFrame()
2188 {
2189   //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2190   //                 (myAnim,&VISU_TimeAnimation::lastFrame));
2191   myAnim->lastFrame();
2192 }
2193
2194 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
2195 {
2196   //ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
2197   //                 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
2198   myAnim->gotoFrame(theFrame);
2199 }
2200
2201 CORBA::Long VISU_TimeAnimation_i::getNbFields()
2202 {
2203   return myAnim->getNbFields();
2204 }
2205
2206 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
2207 {
2208   return myAnim->getNbFrames();
2209 }
2210
2211 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
2212 {
2213   return myAnim->isRunning();
2214 }
2215
2216 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
2217 {
2218   return myAnim->getCurrentFrame();
2219 }
2220
2221 VISU::ColoredPrs3d_ptr VISU_TimeAnimation_i::getPresentation
2222                     (CORBA::Long theField, CORBA::Long theFrame)
2223 {
2224   return myAnim->getPresentation(theField,theFrame);
2225 }
2226
2227 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
2228                                                 VISU::VISUType theType)
2229 {
2230   myAnim->setPresentationType(theFieldNum,theType);
2231 }
2232
2233 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
2234 {
2235   return myAnim->getPresentationType(theFieldNum);
2236 }
2237
2238 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
2239 {
2240   myAnim->setSpeed(theSpeed);
2241 }
2242
2243 CORBA::Long VISU_TimeAnimation_i::getSpeed()
2244 {
2245   return myAnim->getSpeed();
2246 }
2247
2248 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
2249 {
2250   return myAnim->isProportional();
2251 }
2252
2253 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
2254                                               CORBA::Double theMax)
2255 {
2256   myAnim->setAnimationRange(theMin,theMax);
2257 }
2258
2259 CORBA::Double VISU_TimeAnimation_i::getMinRange()
2260 {
2261   return myAnim->getMinRange();
2262 }
2263
2264 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
2265 {
2266   return myAnim->getMaxRange();
2267 }
2268
2269 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
2270 {
2271   return myAnim->isRangeDefined();
2272 }
2273
2274 void VISU_TimeAnimation_i::setAnimationSequence (const char* theSequence)
2275 {
2276   myAnim->setAnimationSequence(theSequence);
2277 }
2278
2279 char* VISU_TimeAnimation_i::getAnimationSequence()
2280 {
2281   return myAnim->getAnimationSequence();
2282 }
2283
2284 CORBA::Boolean VISU_TimeAnimation_i::isSequenceDefined()
2285 {
2286   return myAnim->isSequenceDefined();
2287 }
2288
2289 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
2290 {
2291   myAnim->dumpTo(thePath);
2292 }
2293
2294 char* VISU_TimeAnimation_i::setDumpFormat (const char* theFormat)
2295 {
2296   string aDumpFormat = myAnim->setDumpFormat(theFormat);
2297   return CORBA::string_dup(aDumpFormat.c_str());
2298 }
2299
2300 void VISU_TimeAnimation_i::setTimeStampFrequency(CORBA::Long theFrequency)
2301 {
2302   myAnim->setTimeStampFrequency(theFrequency);
2303 }
2304
2305 CORBA::Long VISU_TimeAnimation_i::getTimeStampFrequency()
2306 {
2307   return myAnim->getTimeStampFrequency();
2308 }
2309
2310 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
2311 {
2312   return myAnim->isCycling();
2313 }
2314
2315 CORBA::Boolean VISU_TimeAnimation_i::isCleaningMemoryAtEachFrame(){
2316   return myAnim->isCleaningMemoryAtEachFrame();
2317 }
2318
2319 CORBA::Double VISU_TimeAnimation_i::getMinTime()
2320 {
2321   return myAnim->getMinTime();
2322 }
2323
2324 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
2325 {
2326   return myAnim->getMaxTime();
2327 }
2328
2329 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
2330 {
2331   myAnim->setProportional(theProp);
2332 }
2333
2334 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
2335 {
2336   myAnim->setCycling(theCycle);
2337 }
2338
2339 void VISU_TimeAnimation_i::setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle){
2340   myAnim->setCleaningMemoryAtEachFrame(theCycle);
2341 }
2342
2343 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
2344 {
2345   return myAnim->publishInStudy();
2346 }
2347
2348 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
2349 {
2350   myAnim->restoreFromStudy(theObj);
2351 }
2352
2353 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
2354 {
2355   return myAnim->isSavedInStudy();
2356 }
2357
2358 void VISU_TimeAnimation_i::saveAnimation()
2359 {
2360   myAnim->saveAnimation();
2361 }
2362
2363 void VISU_TimeAnimation_i::setAnimationMode(VISU::Animation::AnimationMode theMode)
2364 {
2365   myAnim->setAnimationMode(theMode);
2366 }
2367
2368 VISU::Animation::AnimationMode VISU_TimeAnimation_i::getAnimationMode()
2369 {
2370   return VISU::Animation::AnimationMode(myAnim->getAnimationMode());
2371 }
2372
2373 void VISU_TimeAnimation_i::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs)
2374   throw (SALOME::SALOME_Exception)
2375 {
2376   myAnim->ApplyProperties(theFieldNum, thePrs);
2377 }