Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_TimeAnimation.h
1 // Copyright (C) 2007-2012  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.h
24 //  Author : Vitaly SMETANNIKOV
25 //  Module : VISU
26 //
27 #ifndef VISU_TIMEANIMATION_H
28 #define VISU_TIMEANIMATION_H
29
30 #include "VISUConfig.hh"
31
32 #include "VISU_Result_i.hh"
33 #include "SALOME_GenericObjPointer.hh"
34
35 #include <vector>
36
37 #include <QObject>
38 #include <QList>
39 #include <QThread>
40
41 class SVTK_ViewWindow;
42 class VISU_Actor;
43
44 namespace VISU
45 {
46   //class Result_i;
47   class ColoredPrs3d_i;
48   class ExecutionState;
49   class DumpPath;
50 }
51
52 struct FieldData
53 {
54   VISU::VISUType myPrsType;
55   _PTR(SObject) myField; // field label
56   long myNbTimes;        // number of Timestamps
57   long myNbFrames;       // number of created Frames
58   std::vector<VISU::ColoredPrs3d_i*> myPrs;     // Presentations
59   std::vector<VISU_Actor*> myActors;         // Actors
60   std::vector<double> myTiming;              // time values
61   CORBA::Float myOffset[3];
62   typedef SALOME::GenericObjPtr<VISU::Result_i> TResultPtr;
63   TResultPtr myResult;
64 };
65
66
67 class VISU_I_EXPORT VISU_TimeAnimation: public QThread
68 {
69   Q_OBJECT;
70
71  public:
72   enum DumpMode { DM_None = 0, DM_Picture, DM_Video };
73
74  protected:
75   CORBA::Boolean _generateFrames();
76   void _connectView();
77   void _visibilityOff(int num_field, int num_frame);
78   void _clearView();
79   void _clearData(FieldData& theData);
80   void _startAnimation();
81   void _nextFrame();
82   void _prevFrame();
83   void _firstFrame();
84   void _lastFrame();
85   void _gotoFrame(CORBA::Long theFrame);
86
87   void _emitFrameChanged(long theNewFrame, double theTime);
88   void _emitStopped();
89
90   void parallelAnimation( bool& theIsDumping, QList<int>& theIndexList );
91   void successiveAnimation( bool& theIsDumping, QList<int>& theIndexList );
92   void saveImages( int theFieldId, double& theOneVal, int& theNbFiles, QList<int>& theIndexList );
93
94  public:
95   //static VISU::Result_i* createPresent (SALOMEDS::SObject_var theField);
96   //static VISU::Storable::TRestoringMap getMapOfValue (SALOMEDS::SObject_var theSObject);
97   //static double getTimeValue (SALOMEDS::SObject_var theTimestamp);
98
99   static VISU::Result_i* createPresent (_PTR(SObject) theField);
100   static double getTimeValue (_PTR(SObject) theTimestamp);
101
102   VISU_TimeAnimation(_PTR(Study) theStudy,
103                      VISU::View3D_ptr theView3D = VISU::View3D::_nil());
104   ~VISU_TimeAnimation();
105
106   virtual VISU::VISUType GetType() { return VISU::TNONE;};
107
108   bool addField (_PTR(SObject) theField);
109   bool addField (SALOMEDS::SObject_ptr theField);
110   FieldData& getFieldData (int theNum) { return myFieldsLst[theNum]; }
111
112   CORBA::Boolean generateFrames();
113   void generatePresentations(CORBA::Long theFieldNum);
114   void setViewer(SVTK_ViewWindow* theView) { myView = theView; _connectView(); }
115   SVTK_ViewWindow* getViewer() { return myView; }
116   void clearView();
117   void clearData(FieldData& theData);
118   void clearFieldData() { myFieldsLst.clear();};
119
120   void visibilityOff(int num_field, int num_frame);
121   void stopAnimation();
122   void startAnimation();
123   void nextFrame();
124   void prevFrame();
125   void firstFrame();
126   void lastFrame();
127   void gotoFrame(CORBA::Long theFrame);
128
129   CORBA::Long getNbFields() { return myFieldsLst.size(); }
130   CORBA::Long getNbFrames();
131   CORBA::Long getCurrentFrame() { return myFrame; }
132
133   long getAbsoluteFrameNumber(std::pair<int,long> theFieldTimeStamp);
134   std::pair<int,long> getRelativeFrameNumber(long theFrame);
135
136   VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
137
138   void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
139   VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
140
141   void setSpeed(CORBA::Long theSpeed);
142   CORBA::Long getSpeed() { return mySpeed; }
143
144   CORBA::Boolean isProportional() { return myProportional; }
145
146   void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax)
147     { myTimeMinVal = theMin; myTimeMaxVal = theMax; }
148
149   CORBA::Double getMinRange() { return myTimeMinVal; }
150   CORBA::Double getMaxRange() { return myTimeMaxVal; }
151   CORBA::Boolean isRangeDefined() { return !((myTimeMaxVal == 0) && (myTimeMinVal == myTimeMaxVal)); }
152
153   void setAnimationSequence(const char* theSequence);
154   char* getAnimationSequence();
155   CORBA::Boolean isSequenceDefined();
156
157   bool getIndicesFromSequence( QString theSequence, QList<long>& theIndices );
158
159   void dumpTo(const char* thePath);
160   std::string setDumpFormat(const char* theFormat);
161
162   void setTimeStampFrequency(CORBA::Long theFrequency);
163   CORBA::Long getTimeStampFrequency() { return myTimeStampFrequency; }
164
165   int getDumpMode() const { return myDumpMode; }
166
167   bool checkAVIMaker() const;
168
169   QString getLastErrorMsg() { return myLastError; }
170
171   CORBA::Boolean isCycling() { return myCycling; }
172   CORBA::Boolean isCleaningMemoryAtEachFrame() { return myCleaningMemoryAtEachFrame; }
173
174   CORBA::Double getMinTime() { return myTimeMin;}
175   CORBA::Double getMaxTime() { return myTimeMax;}
176
177   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
178   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
179   void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
180
181   SALOMEDS::SObject_ptr publishInStudy();
182   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
183   void restoreFromStudy(_PTR(SObject) theField);
184   void saveAnimation();
185   bool isSavedInStudy() const { return !myAnimEntry.isEmpty(); }
186   _PTR(Study) getStudy() const { return myStudy; }
187
188   void setAnimationMode(VISU::Animation::AnimationMode theMode) { myAnimationMode = theMode; }
189   VISU::Animation::AnimationMode  getAnimationMode() { return myAnimationMode; }
190
191   void ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs) throw (SALOME::SALOME_Exception);
192
193  public slots:
194   void setProportionalSlot(bool theProp) { myProportional = theProp; }
195   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
196   void setCleaningMemoryAtEachFrameSlot(bool theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
197
198  signals:
199   void frameChanged(long theNewFrame, double theTime);
200   void stopped();
201
202  protected:
203   void run();
204   QString GenerateName();
205
206  private slots:
207    void onViewDeleted();
208
209  private:
210   QString myLastError;
211
212   QList<FieldData> myFieldsLst;
213   VISU::ExecutionState* myExecutionState;
214   long myFrame;
215   std::vector<long> myFieldsAbsFrames;
216   int mySpeed;
217   bool myProportional;
218   bool myCycling;
219   bool myCleaningMemoryAtEachFrame;
220   _PTR(Study) myStudy;
221
222   VISU::DumpPath* myDumpPath;
223
224   VISU::Animation::AnimationMode myAnimationMode;
225   double myTimeMinVal, myTimeMaxVal; //!< Range of time stams, set by user
226   double myTimeMin   , myTimeMax   ; //!< Range of time stams, available for animation
227   QString mySequence;
228   QString myDumpFormat;
229   QString myAVIMaker;
230   long myFileIndex;
231   SVTK_ViewWindow* myView;
232
233   int myDumpMode;
234   int myTimeStampFrequency;
235
236   QString myAnimEntry;
237
238   static int myNBAnimations;
239 };
240
241
242 class VISU_I_EXPORT VISU_TimeAnimation_i: public virtual POA_VISU::Animation,
243                             public virtual VISU::Base_i
244 {
245   VISU_TimeAnimation* myAnim;
246 public:
247   VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy,
248                        VISU::View3D_ptr theView3D = VISU::View3D::_nil());
249   ~VISU_TimeAnimation_i();
250
251   virtual VISU::VISUType GetType() { return VISU::TANIMATION; }
252   //virtual VISU::VISUType GetType() { return VISU::TNONE; }
253
254   virtual bool addField(SALOMEDS::SObject_ptr theField);
255   virtual void clearFields();
256
257   virtual CORBA::Boolean generateFrames();
258   virtual void generatePresentations(CORBA::Long theFieldNum);
259
260   virtual void clearView();
261
262   virtual void stopAnimation();
263   virtual void startAnimation();
264   virtual void nextFrame();
265   virtual void prevFrame();
266   virtual void firstFrame();
267   virtual void lastFrame();
268   virtual void gotoFrame(CORBA::Long theFrame);
269
270   virtual CORBA::Long getNbFields();
271   virtual CORBA::Long getNbFrames();
272   virtual CORBA::Boolean isRunning();
273   virtual CORBA::Long getCurrentFrame();
274
275   virtual VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
276
277   virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
278   virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
279
280   virtual void setSpeed(CORBA::Long theSpeed);
281   virtual CORBA::Long getSpeed();
282
283   virtual CORBA::Boolean isProportional();
284
285   virtual void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax);
286
287   virtual CORBA::Double getMinRange();
288   virtual CORBA::Double getMaxRange();
289   virtual CORBA::Boolean isRangeDefined();
290
291   virtual void setAnimationSequence(const char* theSequence);
292   virtual char* getAnimationSequence();
293   virtual CORBA::Boolean isSequenceDefined();
294
295   virtual void dumpTo(const char* thePath);
296   virtual char* setDumpFormat(const char* theFormat);
297
298   virtual void setTimeStampFrequency(CORBA::Long theFrequency);
299   virtual CORBA::Long getTimeStampFrequency();
300
301   virtual CORBA::Boolean isCycling();
302   virtual CORBA::Boolean isCleaningMemoryAtEachFrame();
303
304   virtual CORBA::Double getMinTime();
305   virtual CORBA::Double getMaxTime();
306
307   virtual void setProportional(CORBA::Boolean theProp);
308   virtual void setCycling(CORBA::Boolean theCycle);
309   virtual void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle);
310
311   virtual SALOMEDS::SObject_ptr publishInStudy();
312   virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);
313   virtual CORBA::Boolean isSavedInStudy();
314   virtual void saveAnimation();
315
316   virtual void setAnimationMode(VISU::Animation::AnimationMode theMode);
317   virtual VISU::Animation::AnimationMode getAnimationMode();
318
319   virtual void ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs) throw (SALOME::SALOME_Exception);
320 };
321
322 #endif  //VISU_TIMEANIMATION_H