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