All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Animation.cpp
Go to the documentation of this file.
1 #include "Animation.h"
2 #include "AnimationItem.h"
3 
4 te::qt::widgets::Animation::Animation(QObject* target, const QByteArray& propertyName, QObject* parent)
5  : QPropertyAnimation(target, propertyName, parent)
6 {
8  ai->m_animation = this;
9 }
10 
12 {
13 }
14 
16 {
17  if(m_temporalAnimationExtent != period)
18  m_temporalAnimationExtent = te::dt::TimePeriod(period.getInitialTimeInstant(), period.getFinalTimeInstant());
19 
20  AnimationItem* ai = (AnimationItem*)targetObject();
21 
22  // create route points in display projection
24 
25  setDataKeyValues();
26 }
27 
29 {
31 
32  // total time duration
33  boost::posix_time::ptime iTime = m_temporalAnimationExtent.getInitialTimeInstant().getTimeInstant();
34  boost::posix_time::ptime fTime = m_temporalAnimationExtent.getFinalTimeInstant().getTimeInstant();
35  boost::posix_time::time_duration diff = fTime - iTime;
36  double totalSeconds = diff.total_seconds();
37 
38  size_t size = ai->m_animationTime.size();
39 
40  // set first animation point
41  setStartValue(ai->m_animationRoute[0]);
42 
43  boost::posix_time::ptime itime = ai->m_animationTime[0].getTimeInstant();
44  boost::posix_time::ptime ftime = ai->m_animationTime[size-1].getTimeInstant();
45 
46  // if the initial time is greater than the total initial time,
47  // be stopped until the time be equal to the initial time this animation.
48  // To this add a key value.
49  ai->m_norInitialTime = 0;
50  if(itime > iTime)
51  {
52  // be stopped until the beginning of the animation time
53  diff = itime - iTime;
54  double seconds = diff.total_seconds();
55 
56  // normalizing the time
57  double t = seconds / totalSeconds;
58  ai->m_norInitialTime = t;
59  t *= .999999;
60  setKeyValueAt(t, ai->m_animationRoute[0]); // add a new key value
61  }
62 
63  for(size_t i = 1; i < size-1; ++i)
64  {
65  te::dt::TimeInstant tinstant = ai->m_animationTime[i]; // animation time instant
66  boost::posix_time::ptime time = tinstant.getTimeInstant();
67  diff = time - iTime;
68  double seconds = diff.total_seconds();
69 
70  // normalizing the time
71  double t = seconds / totalSeconds;
72  setKeyValueAt(t, ai->m_animationRoute[i]);
73  }
74 
75  // if the final time is shorter than the total final time,
76  // stop when reach the end of this animation
77  // To this add a key value.
78  ai->m_norFinalTime = 1;
79  if(ftime < fTime)
80  {
81  // be stopped when it reaches the end of its animation
82  diff = ftime - iTime;
83  double seconds = diff.total_seconds();
84 
85  // normalizing the time
86  double t = seconds / totalSeconds;
87  ai->m_norFinalTime = t;
88  setKeyValueAt(t, ai->m_animationRoute[size-1]); // add a new key value
89  }
90 
91  // set last animation point
92  setEndValue(ai->m_animationRoute[size-1]);
93 }
94 
96 {
97  AnimationItem* ai = (AnimationItem*)targetObject();
98  size_t count = ai->m_animationTime.count();
99 
100  // animation time duration
101  boost::posix_time::ptime aiTime = m_temporalExtent.getInitialTimeInstant().getTimeInstant();
102  boost::posix_time::ptime afTime = m_temporalExtent.getFinalTimeInstant().getTimeInstant();
103 
104  // total time duration
105  boost::posix_time::ptime iTime = m_temporalAnimationExtent.getInitialTimeInstant().getTimeInstant();
106  boost::posix_time::ptime fTime = m_temporalAnimationExtent.getFinalTimeInstant().getTimeInstant();
107  boost::posix_time::time_duration diff = fTime - iTime;
108  double totalSeconds = diff.total_seconds();
109 
110  diff = aiTime - iTime;
111  double aiSeconds = diff.total_seconds();
112  double itrel = aiSeconds / totalSeconds;
113  if(itrel > trel)
114  return 0;
115 
116  diff = afTime - iTime;
117  double afSeconds = diff.total_seconds();
118  double ftrel = afSeconds / totalSeconds;
119  if(trel > ftrel)
120  return count-1;
121 
122  size_t i;
123  for(i = 0; i < count; ++i)
124  {
125  te::dt::TimeInstant tinstant = ai->m_animationTime[i]; // animation time instant
126  boost::posix_time::ptime time = tinstant.getTimeInstant();
127  diff = time - iTime;
128  double seconds = diff.total_seconds();
129 
130  // normalizing the time
131  double t = seconds / totalSeconds;
132 
133  if(t >= trel)
134  {
135  if(direction() == QAbstractAnimation::Forward && i != 0)
136  return i - 1;
137  else
138  return i;
139  }
140  }
141  if(i == count)
142  return count - 1;
143  return 0;
144 }
virtual void createAnimationDataInDisplayProjection()
Create Animation Item making reprojection if necessary.
double m_norInitialTime
Normalized initial time (between 0 and 1).
int getAnimationDataIndex(const double &trel)
It It gets the animation data index. It is relative to temporal animation extent. ...
Definition: Animation.cpp:95
const boost::posix_time::ptime & getTimeInstant() const
It returns the boost time instant type.
Definition: TimeInstant.h:92
A class to represent time instant.
Definition: TimeInstant.h:55
Animation * m_animation
The animation this item.
void createAnimationDataInDisplayProjection(const te::dt::TimePeriod &period)
It creates animation data for a given period; /param period The temporal period.
Definition: Animation.cpp:15
double m_norFinalTime
Normalized final time (between 0 and 1).
This file defines a class for a Animation Item.
TimeInstant getFinalTimeInstant() const
It gets the final time instant.
Definition: TimePeriod.cpp:50
TimeInstant getInitialTimeInstant() const
It gets the initial time instant.
Definition: TimePeriod.cpp:45
void setDataKeyValues()
It It sets the data key values.
Definition: Animation.cpp:28
virtual ~Animation()
Destructor It destructs a Animation.
Definition: Animation.cpp:11
A class to represent time period.
Definition: TimePeriod.h:54
This file defines a class for a Trajectory Animation.
This class is a dialog for the Pixmap Item.
Definition: AnimationItem.h:57
QVector< te::dt::TimeInstant > m_animationTime
The animation time. It contains only the portions to be animated.
Animation(QObject *target, const QByteArray &propertyName, QObject *parent=0)
Constructor It constructs a Animation.
Definition: Animation.cpp:4
QVector< QPointF > m_animationRoute
The path coordenates in map display projection. It contains only the portions to be animated...