]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_TimeAnimation.h
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISU_I / VISU_TimeAnimation.h
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VISU_TimeAnimation.h
21 //  Author : Vitaly SMETANNIKOV
22 //  Module : VISU
23
24 #ifndef VISU_TIMEANIMATION_H
25 #define VISU_TIMEANIMATION_H
26
27 #include "VISUConfig.hh"
28
29 #include <vector>
30
31 #include <qobject.h>
32 #include <qvaluelist.h>
33 #include <qthread.h>
34
35 class SVTK_ViewWindow;
36 class VISU_Actor;
37
38 namespace VISU
39 {
40   class Result_i;
41   class ColoredPrs3d_i;
42   class ExecutionState;
43 }
44
45 struct FieldData
46 {
47   VISU::VISUType myPrsType;
48   _PTR(SObject) myField; // field label
49   long myNbTimes;        // number of Timestamps
50   long myNbFrames;       // number of created Frames
51   std::vector<VISU::ColoredPrs3d_i*> myPrs;     // Presentations
52   std::vector<VISU_Actor*> myActors;         // Actors
53   std::vector<double> myTiming;              // time values
54   CORBA::Float myOffset[3];
55 };
56
57
58 class VISU_I_EXPORT VISU_TimeAnimation: public QObject, public QThread
59 {
60   Q_OBJECT;
61
62  protected:
63   CORBA::Boolean _generateFrames();
64   void _visibilityOff(int num_field, int num_frame);
65   void _clearView();
66   void _clearData(FieldData& theData);
67   void _startAnimation();
68   void _nextFrame();
69   void _prevFrame();
70   void _firstFrame();
71   void _lastFrame();
72   void _gotoFrame(CORBA::Long theFrame);
73
74   void _emitFrameChanged(long theNewFrame, double theTime);
75   void _emitStopped();
76
77   void parallelAnimation( bool& theIsDumping, QValueList<int>& theIndexList );
78   void successiveAnimation( bool& theIsDumping, QValueList<int>& theIndexList );
79   void saveImages( int theFieldId, double& theOneVal, int& theNbFiles, QValueList<int>& theIndexList );
80
81  public:
82   //static VISU::Result_i* createPresent (SALOMEDS::SObject_var theField);
83   //static VISU::Storable::TRestoringMap getMapOfValue (SALOMEDS::SObject_var theSObject);
84   //static double getTimeValue (SALOMEDS::SObject_var theTimestamp);
85
86   static VISU::Result_i* createPresent (_PTR(SObject) theField);
87   static double getTimeValue (_PTR(SObject) theTimestamp);
88
89   VISU_TimeAnimation(_PTR(Study) theStudy,
90                      VISU::View3D_ptr theView3D = VISU::View3D::_nil());
91   ~VISU_TimeAnimation();
92
93   virtual VISU::VISUType GetType() { return VISU::TNONE;};
94
95   bool addField (_PTR(SObject) theField);
96   bool addField (SALOMEDS::SObject_ptr theField);
97   FieldData& getFieldData (int theNum) { return myFieldsLst[theNum]; }
98
99   CORBA::Boolean generateFrames();
100   void generatePresentations(CORBA::Long theFieldNum);
101   void setViewer(SVTK_ViewWindow* theView) { myView = theView; }
102   SVTK_ViewWindow* getViewer() { return myView; }
103   void clearView();
104   void clearData(FieldData& theData);
105   void clearFieldData() { myFieldsLst.clear();};
106
107   void visibilityOff(int num_field, int num_frame);
108   void stopAnimation();
109   void startAnimation();
110   void nextFrame();
111   void prevFrame();
112   void firstFrame();
113   void lastFrame();
114   void gotoFrame(CORBA::Long theFrame);
115
116   CORBA::Long getNbFields() { return myFieldsLst.size(); }
117   CORBA::Long getNbFrames();
118   CORBA::Boolean isRunning();
119   CORBA::Long getCurrentFrame() { return myFrame; }
120
121   long getAbsoluteFrameNumber(std::pair<int,long> theFieldTimeStamp);
122   std::pair<int,long> getRelativeFrameNumber(long theFrame);
123
124   VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
125
126   void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType)
127     { myFieldsLst[theFieldNum].myPrsType = theType; }
128   VISU::VISUType getPresentationType(CORBA::Long theFieldNum)
129     { return myFieldsLst[theFieldNum].myPrsType; }
130
131   void setSpeed(CORBA::Long theSpeed);
132   CORBA::Long getSpeed() { return mySpeed; }
133
134   CORBA::Boolean isProportional() { return myProportional; }
135
136   void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax)
137     { myTimeMinVal = theMin; myTimeMaxVal = theMax; }
138
139   CORBA::Double getMinRange() { return myTimeMinVal; }
140   CORBA::Double getMaxRange() { return myTimeMaxVal; }
141   CORBA::Boolean isRangeDefined() { return !((myTimeMaxVal == 0) && (myTimeMinVal == myTimeMaxVal)); }
142
143   void setAnimationSequence(const char* theSequence);
144   char* getAnimationSequence();
145   CORBA::Boolean isSequenceDefined();
146
147   bool getIndicesFromSequence( QString theSequence, QValueList<long>& theIndices );
148
149   void dumpTo(const char* thePath) { myDumpPath = thePath; }
150   std::string setDumpFormat(const char* theFormat);
151   bool checkAVIMaker() const;
152
153   QString getLastErrorMsg() { return myLastError; }
154
155   CORBA::Boolean isCycling() { return myCycling; }
156   CORBA::Boolean isCleaningMemoryAtEachFrame() { return myCleaningMemoryAtEachFrame; }
157
158   CORBA::Double getMinTime() { return myTimeMin;}
159   CORBA::Double getMaxTime() { return myTimeMax;}
160
161   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
162   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
163   void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
164
165   SALOMEDS::SObject_ptr publishInStudy();
166   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
167   void restoreFromStudy(_PTR(SObject) theField);
168   void saveAnimation();
169   bool isSavedInStudy() const { return !myAnimEntry.isEmpty(); }
170   _PTR(Study) getStudy() const { return myStudy; }
171
172   void setAnimationMode(VISU::Animation::AnimationMode theMode) { myAnimationMode = theMode; }
173   VISU::Animation::AnimationMode  getAnimationMode() { return myAnimationMode; }
174
175   void ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs) throw (SALOME::SALOME_Exception);
176
177  public slots:
178   void setProportionalSlot(bool theProp) { myProportional = theProp; }
179   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
180   void setCleaningMemoryAtEachFrameSlot(bool theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
181
182  signals:
183   void frameChanged(long theNewFrame, double theTime);
184   void stopped();
185
186  protected:
187   void run();
188   QString GenerateName();
189
190  private slots:
191    void onViewDeleted();
192
193  private:
194   QString myLastError;
195
196   QValueList<FieldData> myFieldsLst;
197   VISU::ExecutionState* myExecutionState;
198   long myFrame;
199   std::vector<long> myFieldsAbsFrames;
200   int mySpeed;
201   bool myProportional;
202   bool myCycling;
203   bool myCleaningMemoryAtEachFrame;
204   _PTR(Study) myStudy;
205
206   VISU::Animation::AnimationMode myAnimationMode;
207   double myTimeMinVal, myTimeMaxVal; //!< Range of time stams, set by user
208   double myTimeMin   , myTimeMax   ; //!< Range of time stams, available for animation
209   QString mySequence;
210   QString myDumpPath;
211   QString myDumpFormat;
212   QString myAVIMaker;
213   long myFileIndex;
214   SVTK_ViewWindow* myView;
215
216   QString myAnimEntry;
217
218   static int myNBAnimations;
219 };
220
221
222 class VISU_I_EXPORT VISU_TimeAnimation_i: public virtual POA_VISU::Animation,
223                             public virtual VISU::Base_i
224 {
225   VISU_TimeAnimation* myAnim;
226 public:
227   VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy,
228                        VISU::View3D_ptr theView3D = VISU::View3D::_nil());
229   ~VISU_TimeAnimation_i();
230
231   virtual VISU::VISUType GetType() { return VISU::TANIMATION; }
232   //virtual VISU::VISUType GetType() { return VISU::TNONE; }
233
234   virtual bool addField(SALOMEDS::SObject_ptr theField);
235   virtual void clearFields();
236
237   virtual CORBA::Boolean generateFrames();
238   virtual void generatePresentations(CORBA::Long theFieldNum);
239
240   virtual void clearView();
241
242   virtual void stopAnimation();
243   virtual void startAnimation();
244   virtual void nextFrame();
245   virtual void prevFrame();
246   virtual void firstFrame();
247   virtual void lastFrame();
248   virtual void gotoFrame(CORBA::Long theFrame);
249
250   virtual CORBA::Long getNbFields();
251   virtual CORBA::Long getNbFrames();
252   virtual CORBA::Boolean isRunning();
253   virtual CORBA::Long getCurrentFrame();
254
255   virtual VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
256
257   virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
258   virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
259
260   virtual void setSpeed(CORBA::Long theSpeed);
261   virtual CORBA::Long getSpeed();
262
263   virtual CORBA::Boolean isProportional();
264
265   virtual void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax);
266
267   virtual CORBA::Double getMinRange();
268   virtual CORBA::Double getMaxRange();
269   virtual CORBA::Boolean isRangeDefined();
270
271   virtual void setAnimationSequence(const char* theSequence);
272   virtual char* getAnimationSequence();
273   virtual CORBA::Boolean isSequenceDefined();
274
275   virtual void dumpTo(const char* thePath);
276   virtual char* setDumpFormat(const char* theFormat);
277
278   virtual CORBA::Boolean isCycling();
279   virtual CORBA::Boolean isCleaningMemoryAtEachFrame();
280
281   virtual CORBA::Double getMinTime();
282   virtual CORBA::Double getMaxTime();
283
284   virtual void setProportional(CORBA::Boolean theProp);
285   virtual void setCycling(CORBA::Boolean theCycle);
286   virtual void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle);
287
288   virtual SALOMEDS::SObject_ptr publishInStudy();
289   virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);
290   virtual CORBA::Boolean isSavedInStudy();
291   virtual void saveAnimation();
292
293   virtual void setAnimationMode(VISU::Animation::AnimationMode theMode);
294   virtual VISU::Animation::AnimationMode getAnimationMode();
295
296   virtual void ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs) throw (SALOME::SALOME_Exception);
297 };
298
299 #endif  //VISU_TIMEANIMATION_H