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