Salome HOME
315415c80c20d44cadd54595cb05df77fb10f2c0
[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 ColoredPrs3d_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::ColoredPrs3d_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::ColoredPrs3d_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   std::string setDumpFormat(const char* theFormat);
104
105   QString getLastErrorMsg() { return myLastError; }
106
107   CORBA::Boolean isCycling() { return myCycling; }
108
109   CORBA::Double getMinTime() { return myTimeMin;}
110   CORBA::Double getMaxTime() { return myTimeMax;}
111
112   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
113   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
114
115   SALOMEDS::SObject_ptr publishInStudy();
116   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
117   void restoreFromStudy(_PTR(SObject) theField);
118   void saveAnimation();
119   bool isSavedInStudy() const { return !myAnimEntry.isEmpty(); }
120
121  public slots:
122   void setProportionalSlot(bool theProp) { myProportional = theProp; }
123   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
124
125  signals:
126   void frameChanged(long theNewFrame, double theTime);
127   void stopped();
128
129  protected:
130   void run();
131   QString GenerateName();
132
133  private slots:
134    void onViewDeleted();
135    
136  private:
137   QString myLastError;
138
139   QValueList<FieldData> myFieldsLst;
140   bool myIsActive;
141   long myFrame;
142   int mySpeed;
143   bool myProportional;
144   bool myCycling;
145   _PTR(Study) myStudy;
146
147   double myMaxVal, myMinVal;
148   double myTimeMin, myTimeMax;
149   QString myDumpPath;
150   QString myDumpFormat;
151   SVTK_ViewWindow* myView;
152
153   QString myAnimEntry;
154
155   static int myNBAnimations;
156 };
157
158
159 class VISU_TimeAnimation_i: public virtual POA_VISU::Animation,
160                             public virtual VISU::Base_i
161 {
162   VISU_TimeAnimation* myAnim;
163 public:
164   VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy,
165                        VISU::View3D_ptr theView3D = VISU::View3D::_nil());
166   ~VISU_TimeAnimation_i();
167
168   virtual VISU::VISUType GetType() { return VISU::TANIMATION; }
169   //virtual VISU::VISUType GetType() { return VISU::TNONE; }
170
171   virtual void addField(SALOMEDS::SObject_ptr theField);
172
173   virtual CORBA::Boolean generateFrames();
174   virtual void generatePresentations(CORBA::Long theFieldNum);
175
176   virtual void clearView();
177
178   virtual void stopAnimation();
179   virtual void startAnimation();
180   virtual void nextFrame();
181   virtual void prevFrame();
182   virtual void firstFrame();
183   virtual void lastFrame();
184   virtual void gotoFrame(CORBA::Long theFrame);
185
186   virtual CORBA::Long getNbFields();
187   virtual CORBA::Long getNbFrames();
188   virtual CORBA::Boolean isRunning();
189   virtual CORBA::Long getCurrentFrame();
190
191   virtual VISU::ColoredPrs3d_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
192
193   virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
194   virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
195
196   virtual void setSpeed(CORBA::Long theSpeed);
197   virtual CORBA::Long getSpeed();
198
199   virtual CORBA::Boolean isProportional();
200
201   virtual void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax);
202
203   virtual CORBA::Double getMinRange();
204   virtual CORBA::Double getMaxRange();
205   virtual CORBA::Boolean isRangeDefined();
206
207   virtual void dumpTo(const char* thePath);
208   virtual char* setDumpFormat(const char* theFormat);
209
210   virtual CORBA::Boolean isCycling();
211
212   virtual CORBA::Double getMinTime();
213   virtual CORBA::Double getMaxTime();
214
215   virtual void setProportional(CORBA::Boolean theProp);
216   virtual void setCycling(CORBA::Boolean theCycle);
217
218   virtual SALOMEDS::SObject_ptr publishInStudy();
219   virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);
220   virtual CORBA::Boolean isSavedInStudy();
221   virtual void saveAnimation();
222 };
223
224 #endif  //VISU_TIMEANIMATION_H