5 #include "../canvas/MapDisplay.h"
6 #include "../canvas/Canvas.h"
9 #include <QtCore/QPropertyAnimation>
10 #include <QtGui/QPainter>
11 #include <QtCore/QVector>
12 #include <QtCore/QFile>
13 #include <QtCore/QMutex>
22 m_forwardColor(Qt::blue),
23 m_backwardColor(Qt::magenta),
30 if(file.isEmpty() ==
false)
37 QPainter painter(&pp);
38 painter.drawPixmap(pp.rect(), p, p.rect());
47 pix.fill(Qt::transparent);
48 QPainter painter(&pix);
53 painter.drawEllipse(QRect(1, 1, 18, 18));
68 if(m_animationRoute.empty())
79 if(rm.contains(m_pos) ==
false)
83 QPointF c = r.center();
84 QPointF dif = m_pos - c;
85 double dw = fabs(dif.x());
86 double dh = fabs(dif.y());
90 mw = (dw - w / 2) + w * m_panFactor;
92 mh = (dh - h / 2) + h * m_panFactor;
95 if(dif.x() >= 0 && dif.y() >= 0)
96 cc = c + QPointF(mw, mh);
97 else if(dif.x() >= 0 && dif.y() < 0)
98 cc = c + QPointF(mw, -mh);
99 else if(dif.x() < 0 && dif.y() >= 0)
100 cc = c + QPointF(-mw, mh);
101 else if(dif.x() < 0 && dif.y() < 0)
102 cc = c + QPointF(-mw, -mh);
105 if(r.contains(m_pos) ==
false)
111 e.
m_ury = r.bottom();
112 m_display->setExtent(e);
117 unsigned int curTime = m_animation->currentTime();
118 if(m_curTimeDuration == curTime)
124 if(m_animation->direction() == QAbstractAnimation::Forward)
126 if(curTime < m_curTimeDuration)
131 if(curTime > m_curTimeDuration)
143 this->erase(curTime);
146 drawForward(curTime);
154 if (m_display->getSRID() !=
TE_UNKNOWN_SRS && m_display->getSRID() != m_SRID)
156 size_t size = vec.count();
158 for (
size_t i = 0; i < size; ++i)
159 line.
setPoint(i, vec[(
int)i].x(), vec[(int)i].y());
163 for (
size_t i = 0; i < size; ++i)
170 if(m_animationRoute.empty())
173 int indold = m_animation->getAnimationDataIndex((
double)m_curTimeDuration / (
double)m_duration);
174 int ind = m_animation->getAnimationDataIndex((
double)curTime / (
double)m_duration);
175 m_curTimeDuration = curTime;
176 if (ind == -1 || indold == -1)
179 QVector<QPointF> vec;
183 vec.push_back(m_posOld);
184 vec.push_back(m_pos);
186 else if(m_animation->direction() == QAbstractAnimation::Forward)
189 vec.push_back(m_animationRoute[indold++]);
190 if(vec.isEmpty() ==
false && vec.last() != m_pos)
191 vec.push_back(m_pos);
196 vec.push_back(m_animationRoute[indold--]);
197 if(vec.isEmpty() ==
false && vec.last() != m_pos)
198 vec.push_back(m_pos);
201 size_t size = vec.count();
204 transformToDisplayProjection(vec);
207 QPolygon pol = m_matrix.map(polf).toPolygon();
209 QPen pen(Qt::NoBrush, 2);
211 if(m_animation->direction() == QAbstractAnimation::Forward)
212 trailColor = m_forwardColor;
214 trailColor = m_backwardColor;
215 pen.setColor(trailColor);
220 QPainter painter(scenePixmap);
222 painter.setBrush(Qt::NoBrush);
223 painter.drawPolyline(pol);
231 if(m_animationRoute.empty())
234 int indold = m_animation->getAnimationDataIndex((
double)m_curTimeDuration / (
double)m_duration);
235 int ind = m_animation->getAnimationDataIndex((
double)curTime / (
double)m_duration);
236 m_curTimeDuration = curTime;
237 if (ind == -1 || indold == -1)
240 QVector<QPointF> vec;
243 vec.push_back(m_posOld);
244 vec.push_back(m_pos);
246 else if(m_animation->direction() == QAbstractAnimation::Backward)
248 vec.push_back(m_posOld);
250 vec.push_back(m_animationRoute[indold++]);
251 vec.push_back(m_pos);
255 vec.push_back(m_posOld);
257 vec.push_back(m_animationRoute[indold--]);
258 vec.push_back(m_pos);
261 size_t size = vec.count();
264 transformToDisplayProjection(vec);
267 QPolygon pol = m_matrix.map(polf).toPolygon();
269 QPen pen(Qt::NoBrush, 2);
270 QColor trailColor(Qt::white);
271 pen.setColor(trailColor);
276 QPainter painter(scenePixmap);
278 painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
279 painter.setBrush(Qt::NoBrush);
280 painter.drawPolyline(pol);
288 if (m_animationRoute.empty())
291 int ind = m_animation->getAnimationDataIndex((
double)m_curTimeDuration / (
double)m_duration);
295 int w = m_display->getDisplayPixmap()->width();
296 int h = m_display->getDisplayPixmap()->height();
303 int count = m_animationRoute.size();
305 QVector<QPointF> vec;
306 if (m_animation->direction() == QAbstractAnimation::Forward)
312 vec.push_back(m_animationRoute[i++]);
313 if (vec.isEmpty() ==
false && vec.last() != m_pos)
314 vec.push_back(m_pos);
321 vec.push_back(m_animationRoute[i--]);
322 if (m_curTimeDuration != m_duration)
324 if (vec.isEmpty() ==
false && vec.last() != m_pos)
325 vec.push_back(m_pos);
329 size_t size = vec.count();
332 transformToDisplayProjection(vec);
335 QPolygon pol = m_matrix.map(polf).toPolygon();
337 QPen pen(Qt::NoBrush, 2);
339 if (m_animation->direction() == QAbstractAnimation::Forward)
340 trailColor = m_forwardColor;
342 trailColor = m_backwardColor;
344 pen.setColor(trailColor);
349 QPainter painter(scenePixmap);
351 painter.setBrush(Qt::NoBrush);
352 painter.drawPolyline(pol);
361 QPoint pos = getPosInDeviceCoordinate();
368 int ind = m_animation->getAnimationDataIndex((
double)m_curTimeDuration / (
double)m_duration);
373 QVector<QPointF> vec;
374 if (m_animation->direction() == QAbstractAnimation::Forward)
378 vec.push_back(m_animationRoute[ind - 1]);
379 vec.push_back(m_animationRoute[ind]);
380 transformToDisplayProjection(vec);
385 if (ind < (m_animationRoute.count() - 1))
387 vec.push_back(m_animationRoute[ind]);
388 vec.push_back(m_animationRoute[ind + 1]);
389 transformToDisplayProjection(vec);
392 if (vec.isEmpty() ==
false)
394 double PI = 3.14159265;
395 QPointF p = vec[1] - vec[0];
415 angle = atan(p.y() / p.x());
428 painter->translate(pos);
429 painter->scale(xScale, yScale);
432 painter->rotate(-angle);
433 painter->translate(-pos);
436 QRect r = pixmap().rect();
438 QRect dr = m_display->rect();
439 if (dr.intersects(r))
441 if (m_opacity == 255)
442 painter->drawPixmap(r, pixmap());
445 QSize size = pixmap().size();
446 int width = size.width();
447 int height = size.height();
448 QImage ima = pixmap().toImage();
450 if (ima.format() == QImage::Format_ARGB32)
452 for (
int i = 0; i < height; ++i)
454 unsigned char* u = ima.scanLine(i);
455 for (
int j = 0; j < width; ++j)
457 QRgb* v = (QRgb*)(u + (j << 2));
459 *v = qRgba(255, 255, 255, 0);
461 *v = qRgba(qRed(*v), qGreen(*v), qBlue(*v), m_opacity);
464 painter->drawImage(r, ima);
468 QImage img(size, QImage::Format_ARGB32);
469 for (
int i = 0; i < height; ++i)
471 unsigned char* u = ima.scanLine(i);
472 unsigned char* uu = img.scanLine(i);
474 for (
int j = 0; j < width; ++j)
476 QRgb* v = (QRgb*)(u + (j << 2));
477 QRgb* uv = (QRgb*)(uu + (j << 2));
479 *uv = qRgba(255, 255, 255, 0);
481 *uv = qRgba(qRed(*v), qGreen(*v), qBlue(*v), m_opacity);
484 painter->drawImage(r, img);
Point * getPointN(std::size_t i) const
It returns the specified point in this LineString.
double m_urx
Upper right corner x-coordinate.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
double getWidth() const
It returns the envelope width.
double m_llx
Lower left corner x-coordinate.
This file defines a class for a Animation Scene.
LineString is a curve with linear interpolation between points.
const double & getY() const
It returns the Point y-coordinate value.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
double m_lly
Lower left corner y-coordinate.
This file defines a class for a Trajectory Animation.
double m_ury
Upper right corner y-coordinate.
This file defines a class for a Trajectory Item.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
double getHeight() const
It returns the envelope height.
const double & getX() const
It returns the Point x-coordinate value.
void transform(int srid)
It converts the coordinate values of the linestring to the new spatial reference system.