Salome HOME
Showing of animation, stored in study, is available now through popup-menu
[modules/visu.git] / src / VISU_I / VISU_TimeAnimation.h
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VISU_TimeAnimation.h
6 //  Author : Vitaly SMETANNIKOV
7 //  Module : VISU
8
9 #ifndef VISU_TIMEANIMATION_H
10 #define VISU_TIMEANIMATION_H
11
12 #include "VISUConfig.hh"
13
14 #include <vector>
15
16 #include <qobject.h>
17 #include <qvaluelist.h>
18 #include <qthread.h>
19
20 class SVTK_ViewWindow;
21 class VISU_Actor;
22
23 namespace VISU{
24   class Result_i;
25   class ScalarMap_i;
26 }
27
28 struct FieldData
29 {
30   VISU::VISUType myPrsType;
31   _PTR(SObject) myField; // field label
32   long myNbTimes;        // number of Timestamps
33   long myNbFrames;       // number of created Frames
34   std::vector<VISU::ScalarMap_i*> myPrs;     // Presentations
35   std::vector<VISU_Actor*> myActors;         // Actors
36   std::vector<double> myTiming;              // time values
37   float myOffset[3];
38 };
39
40
41 class VISU_TimeAnimation: public QObject, public QThread
42 {
43   Q_OBJECT;
44  public:
45   //static VISU::Result_i* createPresent (SALOMEDS::SObject_var theField);
46   //static VISU::Storable::TRestoringMap getMapOfValue (SALOMEDS::SObject_var theSObject);
47   //static double getTimeValue (SALOMEDS::SObject_var theTimestamp);
48
49   static VISU::Result_i* createPresent (_PTR(SObject) theField);
50   static VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject);
51   static double getTimeValue (_PTR(SObject) theTimestamp);
52
53   VISU_TimeAnimation(_PTR(Study) theStudy,
54                      VISU::View3D_ptr theView3D = VISU::View3D::_nil());
55   ~VISU_TimeAnimation();
56
57   virtual VISU::VISUType GetType() { return VISU::TNONE;};
58
59   void addField (_PTR(SObject) theField);
60   void addField (SALOMEDS::SObject_ptr theField);
61   FieldData& getFieldData (int theNum) { return myFieldsLst[theNum]; }
62
63   CORBA::Boolean generateFrames();
64   void generatePresentations(CORBA::Long theFieldNum);
65   void setViewer(SVTK_ViewWindow* theView) { myView = theView; }
66   SVTK_ViewWindow* getViewer() { return myView; }
67   void clearView();
68   void clearData(FieldData& theData);
69
70   void stopAnimation();
71   void startAnimation();
72   void nextFrame();
73   void prevFrame();
74   void firstFrame();
75   void lastFrame();
76   void gotoFrame(CORBA::Long theFrame);
77
78   CORBA::Long getNbFields() { return myFieldsLst.size(); }
79   CORBA::Long getNbFrames();
80   CORBA::Boolean isRunning() { return myIsActive; }
81   CORBA::Long getCurrentFrame() { return myFrame; }
82
83   VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
84
85   void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType)
86     { myFieldsLst[theFieldNum].myPrsType = theType; }
87   VISU::VISUType getPresentationType(CORBA::Long theFieldNum)
88     { return myFieldsLst[theFieldNum].myPrsType; }
89
90   void setSpeed(CORBA::Long theSpeed);
91   CORBA::Long getSpeed() { return mySpeed; }
92
93   CORBA::Boolean isProportional() { return myProportional; }
94
95   void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax)
96     { myMaxVal = theMax; myMinVal = theMin; }
97
98   CORBA::Double getMinRange() { return myMinVal; }
99   CORBA::Double getMaxRange() { return myMaxVal; }
100   CORBA::Boolean isRangeDefined() { return !((myMaxVal==0) && (myMinVal == myMaxVal)); }
101
102   void dumpTo(const char* thePath) { myDumpPath = thePath; }
103
104   QString getLastErrorMsg() { return myLastError; }
105
106   CORBA::Boolean isCycling() { return myCycling; }
107
108   CORBA::Double getMinTime() { return myTimeMin;}
109   CORBA::Double getMaxTime() { return myTimeMax;}
110
111   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
112   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
113
114   SALOMEDS::SObject_ptr publishInStudy();
115   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
116   void restoreFromStudy(_PTR(SObject) theField);
117   void saveAnimation();
118   bool isSavedInStudy() const { return !myAnimEntry.isEmpty(); }
119
120  public slots:
121   void setProportionalSlot(bool theProp) { myProportional = theProp; }
122   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
123
124  signals:
125   void frameChanged(long theNewFrame, double theTime);
126   void stopped();
127
128  protected:
129   void run();
130   QString GenerateName();
131
132  private:
133   QString myLastError;
134
135   QValueList<FieldData> myFieldsLst;
136   bool myIsActive;
137   long myFrame;
138   int mySpeed;
139   bool myProportional;
140   bool myCycling;
141   _PTR(Study) myStudy;
142
143   double myMaxVal, myMinVal;
144   double myTimeMin, myTimeMax;
145   QString myDumpPath;
146   SVTK_ViewWindow* myView;
147
148   QString myAnimEntry;
149
150   static int myNBAnimations;
151 };
152
153
154 class VISU_TimeAnimation_i: public virtual POA_VISU::Animation,
155                             public virtual VISU::Base_i
156 {
157   VISU_TimeAnimation* myAnim;
158 public:
159   VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy,
160                        VISU::View3D_ptr theView3D = VISU::View3D::_nil());
161   ~VISU_TimeAnimation_i();
162
163   virtual VISU::VISUType GetType() { return VISU::TANIMATION; }
164   //virtual VISU::VISUType GetType() { return VISU::TNONE; }
165
166   virtual void addField(SALOMEDS::SObject_ptr theField);
167
168   virtual CORBA::Boolean generateFrames();
169   virtual void generatePresentations(CORBA::Long theFieldNum);
170
171   virtual void clearView();
172
173   virtual void stopAnimation();
174   virtual void startAnimation();
175   virtual void nextFrame();
176   virtual void prevFrame();
177   virtual void firstFrame();
178   virtual void lastFrame();
179   virtual void gotoFrame(CORBA::Long theFrame);
180
181   virtual CORBA::Long getNbFields();
182   virtual CORBA::Long getNbFrames();
183   virtual CORBA::Boolean isRunning();
184   virtual CORBA::Long getCurrentFrame();
185
186   virtual VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
187
188   virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
189   virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
190
191   virtual void setSpeed(CORBA::Long theSpeed);
192   virtual CORBA::Long getSpeed();
193
194   virtual CORBA::Boolean isProportional();
195
196   virtual void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax);
197
198   virtual CORBA::Double getMinRange();
199   virtual CORBA::Double getMaxRange();
200   virtual CORBA::Boolean isRangeDefined();
201
202   virtual void dumpTo(const char* thePath);
203
204   virtual CORBA::Boolean isCycling();
205
206   virtual CORBA::Double getMinTime();
207   virtual CORBA::Double getMaxTime();
208
209   virtual void setProportional(CORBA::Boolean theProp);
210   virtual void setCycling(CORBA::Boolean theCycle);
211
212   virtual SALOMEDS::SObject_ptr publishInStudy();
213   virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);
214   virtual CORBA::Boolean isSavedInStudy();
215   virtual void saveAnimation();
216 };
217
218 #endif  //VISU_TIMEANIMATION_H