Salome HOME
01de4065dbb2f9767086998e5618a55145b99e30
[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 VTKViewer_ViewFrame;
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   SALOMEDS::SObject_var 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 };
38
39
40 class VISU_TimeAnimation: public QObject, public QThread
41 {
42   Q_OBJECT;
43  public:
44   static VISU::Result_i* createPresent(SALOMEDS::SObject_var theField);
45   static VISU::Storable::TRestoringMap getMapOfValue(SALOMEDS::SObject_var theSObject);
46   static double getTimeValue(SALOMEDS::SObject_var theTimestamp);
47   
48   VISU_TimeAnimation(SALOMEDS::Study_ptr theStudy, VISU::View3D_ptr theView3D = VISU::View3D::_nil());
49   ~VISU_TimeAnimation();
50   
51   virtual VISU::VISUType GetType() { return VISU::TNONE;};
52   
53   void addField(SALOMEDS::SObject_ptr theField);
54   FieldData& getFieldData(int theNum) { return myFieldsLst[theNum]; }
55
56   CORBA::Boolean generateFrames();
57   void generatePresentations(CORBA::Long theFieldNum);
58   void setViewer(VTKViewer_ViewFrame* theView) { myView = theView; }
59   VTKViewer_ViewFrame* getViewer() { return myView; }
60   void clearView();
61   void clearData(FieldData& theData);
62
63   void stopAnimation();
64   void startAnimation();
65   void nextFrame();
66   void prevFrame();
67   void firstFrame();
68   void lastFrame();
69   void gotoFrame(CORBA::Long theFrame);
70
71   CORBA::Long getNbFields() { return myFieldsLst.size(); }
72   CORBA::Long getNbFrames();
73   CORBA::Boolean isRunning() { return myIsActive; }
74   CORBA::Long getCurrentFrame() { return myFrame; }
75
76   VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
77
78   void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType) { myFieldsLst[theFieldNum].myPrsType = theType; }
79   VISU::VISUType getPresentationType(CORBA::Long theFieldNum) { return myFieldsLst[theFieldNum].myPrsType; }
80
81   void setSpeed(CORBA::Long theSpeed);
82   CORBA::Long getSpeed() { return mySpeed; }
83
84   CORBA::Boolean isProportional() { return myProportional; }
85
86   void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax)
87     { myMaxVal = theMax; myMinVal = theMin; }
88
89   CORBA::Double getMinRange() { return myMinVal; }
90   CORBA::Double getMaxRange() { return myMaxVal; } 
91   CORBA::Boolean isRangeDefined() { return !((myMaxVal==0) && (myMinVal == myMaxVal)); }
92
93   void dumpTo(const char* thePath) { myDumpPath = thePath; }
94
95   QString getLastErrorMsg() { return myLastError; }
96
97   CORBA::Boolean isCycling() { return myCycling; }
98
99   CORBA::Double getMinTime() { return myTimeMin;}
100   CORBA::Double getMaxTime() { return myTimeMax;}
101
102   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
103   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
104
105  public slots:
106   void setProportionalSlot(bool theProp) { myProportional = theProp; }
107   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
108
109  signals:
110   void frameChanged(long theNewFrame, double theTime);
111   void stopped();
112
113  protected:
114   void run();
115
116  private:
117   QString myLastError;
118
119   QValueList<FieldData> myFieldsLst;
120   bool myIsActive;
121   long myFrame;
122   int mySpeed;
123   bool myProportional;
124   bool myCycling;
125   SALOMEDS::Study_var myStudy;
126
127   double myMaxVal, myMinVal;
128   double myTimeMin, myTimeMax;
129   QString myDumpPath;
130   VTKViewer_ViewFrame* myView;
131 };
132
133
134 class VISU_TimeAnimation_i: public virtual POA_VISU::Animation,
135                             public virtual VISU::Base_i
136 {
137   VISU_TimeAnimation* myAnim;
138 public:
139   VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy, 
140                        VISU::View3D_ptr theView3D = VISU::View3D::_nil());
141   ~VISU_TimeAnimation_i();
142
143   virtual VISU::VISUType GetType(){ return VISU::TNONE;}
144
145   virtual void addField(SALOMEDS::SObject_ptr theField);
146
147   virtual CORBA::Boolean generateFrames();
148   virtual void generatePresentations(CORBA::Long theFieldNum);
149   
150   virtual void clearView();
151
152   virtual void stopAnimation();
153   virtual void startAnimation();
154   virtual void nextFrame();
155   virtual void prevFrame();
156   virtual void firstFrame();
157   virtual void lastFrame();
158   virtual void gotoFrame(CORBA::Long theFrame);
159
160   virtual CORBA::Long getNbFields();
161   virtual CORBA::Long getNbFrames();
162   virtual CORBA::Boolean isRunning();
163   virtual CORBA::Long getCurrentFrame();
164
165   virtual VISU::ScalarMap_ptr getPresentation(CORBA::Long theField, CORBA::Long theFrame);
166
167   virtual void setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType);
168   virtual VISU::VISUType getPresentationType(CORBA::Long theFieldNum);
169
170   virtual void setSpeed(CORBA::Long theSpeed);
171   virtual CORBA::Long getSpeed();
172
173   virtual CORBA::Boolean isProportional();
174
175   virtual void setAnimationRange(CORBA::Double theMin, CORBA::Double theMax);
176
177   virtual CORBA::Double getMinRange();
178   virtual CORBA::Double getMaxRange();
179   virtual CORBA::Boolean isRangeDefined();
180
181   virtual void dumpTo(const char* thePath);
182
183   virtual CORBA::Boolean isCycling();
184
185   virtual CORBA::Double getMinTime();
186   virtual CORBA::Double getMaxTime();
187
188   virtual void setProportional(CORBA::Boolean theProp);
189   virtual void setCycling(CORBA::Boolean theCycle);
190 };
191
192
193 #endif  //VISU_TIMEANIMATION_H