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