All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimeSliderWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20  /*!
21  \file terralib/qt/widgets/slider/TimeSliderWidget.cpp
22 
23  \brief A widget used to alow the user to controle the visualization of temporal data
24 */
25 
26 //Terralib
27 //#include "TimePropertiesDialog.h"
28 #include "../canvas/MapDisplay.h"
29 #include "Animation.h"
30 #include "AnimationScene.h"
31 #include "TrajectoryItem.h"
32 #include "PixmapItem.h"
33 #include "TimeSliderWidget.h"
34 #include "ui_TimeSliderWidgetForm.h"
35 #include <terralib/dataaccess.h>
36 #include <terralib/stmemory.h>
37 #include <terralib/st.h>
39 #include <terralib/qt/widgets.h>
40 #include <terralib/maptools.h>
41 #include <terralib/dataaccess.h>
42 
43 //QT
44 #include <QGraphicsEffect>
45 #include <QSlider>
46 #include <QGraphicsView>
47 #include <QMimeData>
48 #include <QParallelAnimationGroup>
49 #include <QPropertyAnimation>
50 #include <QTimer>
51 #include <QThread>
52 #include <QTextStream>
53 #include <QContextMenuEvent>
54 #include <QMessageBox>
55 #include <QInputDialog>
56 #include <QDateTimeEdit>
57 #include <QColorDialog>
58 #include <QUrl>
59 
61  : QWidget(parent, f),
62  m_display(md),
63  m_erasePerfectly(false),
64  m_maxSliderValue(1000000000),
65  m_ui(new Ui::TimeSliderWidgetForm),
66  m_finished(false)
67 {
68  te::qt::widgets::ScopedCursor scopedCursor(Qt::WaitCursor);
69  m_ui->setupUi(this);
70  setFocusPolicy(Qt::StrongFocus);
71  setMouseTracking(true);
72  setAcceptDrops(true);
73 
74  showPropertySection(false);
75 
77  m_initialDisplayRect = QRectF(env.m_llx, env.m_lly, env.getWidth(), env.getHeight());
78 
79  // slider normalized between 0 and m_maxSliderValue
80  m_ui->m_TemporalHorizontalSlider->setMinimum(0);
81  m_ui->m_TemporalHorizontalSlider->setMaximum(m_maxSliderValue);
82 
83  m_ui->m_durationSpinBox->setMinimum(100);
84  m_ui->m_durationSpinBox->setMaximum(100000000);
85  m_ui->m_durationSpinBox->setValue(10000);
86  m_ui->m_durationSpinBox->setSingleStep(10000);
87 
88  m_ui->m_opacitySpinBox->setMinimum(0);
89  m_ui->m_opacitySpinBox->setMaximum(255);
90  m_ui->m_opacitySpinBox->setValue(255);
91  m_ui->m_opacitySpinBox->setSingleStep(5);
92 
93  //setAutoFillBackground(true);
94  //QPalette palette;
95  //palette.setColor(QPalette::Background, Qt::white);
96  //setPalette(palette);
97 
98  //The opacity used to fade the widget if the mouse is not over it
99  //QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect;
100  //opacityEffect->setOpacity(0.85);
101  //this->setGraphicsEffect(opacityEffect);
102 
103  //Adjusting the icons and the graphic effects
104  m_ui->m_settingsToolButton->setIcon(QIcon::fromTheme("preferences-system"));
105  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
106  m_ui->m_stopToolButton->setIcon(QIcon::fromTheme("media-playback-stop"));
107 
108  // connect signal and slots
109  connect(m_ui->m_addEtaPushButton, SIGNAL(clicked(bool) ), this, SLOT(onAddEtaPushButtonClicked(bool)));
110  connect(m_ui->m_addHidroPushButton, SIGNAL(clicked(bool) ), this, SLOT(onAddHidroPushButtonClicked(bool)));
111  connect(m_ui->m_autoPanCheckBox, SIGNAL(clicked(bool) ), this, SLOT(onAutoPanCheckBoxClicked(bool)));
112  connect(m_ui->m_forwardRadioButton, SIGNAL(clicked(bool) ), this, SLOT(onForwardRadioButtonClicked(bool)));
113  connect(m_ui->m_backwardRadioButton, SIGNAL(clicked(bool) ), this, SLOT(onBackwardRadioButtonClicked(bool)));
114  connect(m_ui->m_loopCheckBox, SIGNAL(clicked(bool) ), this, SLOT(onLoopCheckBoxClicked(bool)));
115  connect(m_ui->m_goAndBackCheckBox, SIGNAL(clicked(bool) ), this, SLOT(onGoAndBackCheckBoxClicked(bool)));
116  connect(m_ui->m_applyTimeIntervalPushButton, SIGNAL(clicked(bool) ), this, SLOT(onApplyTimeIntervalPushButtonClicked(bool)));
117  connect(m_ui->m_trajectoryColorComboBox, SIGNAL(activated(int) ), this, SLOT(onTrajectoryColorComboBoxActivated(int)));
118  //connect(m_ui->m_forwardColorPushButton, SIGNAL(clicked(bool) ), this, SLOT(onForwardColorPushButton(bool)));
119  //connect(m_ui->m_backwardColorPushButton, SIGNAL(clicked(bool) ), this, SLOT(onBackwardColorPushButton(bool)));
120  connect(m_ui->m_opacityComboBox, SIGNAL(activated(int) ), this, SLOT(onOpacityComboBoxActivated(int)));
121  connect(m_ui->m_dateTimeEdit, SIGNAL(dateTimeChanged(const QDateTime&) ), this, SLOT(onDateTimeEditChanged(const QDateTime&)));
122  connect(m_ui->m_durationSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onDurationValueChanged(int)));
123  connect(m_ui->m_opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(onOpacityValueChanged(int)));
124  connect(m_ui->m_settingsToolButton, SIGNAL(clicked()), this, SLOT(onSettingsToolButtonnClicked()));
125  connect(m_ui->m_playToolButton, SIGNAL(clicked()), this, SLOT(onPlayToolButtonnClicked()));
126  connect(m_ui->m_stopToolButton, SIGNAL(clicked()), this, SLOT(onStopToolButtonnClicked()));
127  connect(m_ui->m_TemporalHorizontalSlider, SIGNAL(sliderMoved (int)), this, SLOT(onSliderMoved(int)));
128  connect(m_ui->addPushButton, SIGNAL(clicked(bool)), this, SLOT(onAddPushButtonClicked(bool)));
129  connect(m_ui->removePushButton, SIGNAL(clicked(bool)), this, SLOT(onRemovePushButtonClicked(bool)));
130  connect(m_ui->frontPushButton, SIGNAL(clicked(bool)), this, SLOT(onFrontPushButtonClicked(bool)));
131  connect(m_ui->backPushButton, SIGNAL(clicked(bool)), this, SLOT(onBackPushButtonClicked(bool)));
132 
133  connect(m_ui->m_resetInitialTimePushButton, SIGNAL(clicked()), this, SLOT(onResetInitialTimePushButtonClicked()));
134  connect(m_ui->m_resetFinalTimePushButton, SIGNAL(clicked()), this, SLOT(onResetFinalTimePushButtonClicked()));
135 
136  setAttribute(Qt::WA_DeleteOnClose, true);
137 
138  m_loop = true; //By default, the animation not will be looping.
139  m_duration = 10000; //By default, the animation journey time will be 10000 miliseconds.
140  m_ui->m_durationSpinBox->setValue(m_duration);
141  m_direction = QAbstractAnimation::Forward; //By default, the animation direction will be forward.
142  setGoAndBack(true); //By default, the animation is forward and then backward.
143 
144  m_ui->m_forwardRadioButton->setCheckable(true);
145 
146  m_animationView = new QGraphicsView();
147  m_parallelAnimation = new QParallelAnimationGroup(m_animationView);
148  m_animationView->installEventFilter(this);
151  m_animationView->showMaximized();
152  m_animationView->move(5000, 5000);
153 
154  connect(m_display, SIGNAL(displaySridChanged()), this, SLOT(onSridChanged()));
155  connect(m_display, SIGNAL(extentChanged()), this, SLOT(onExtentChanged()));
156  connect(m_display, SIGNAL(displayPaintEvent(QPainter*)), this, SLOT(onDisplayPaintEvent(QPainter*)));
157  connect(m_parallelAnimation, SIGNAL(finished()), this, SLOT(onFinishAnimation()));
158 
159  installEventFilter(this);
160  m_ui->m_forwardColorPushButton->installEventFilter(this);
161  m_ui->m_backwardColorPushButton->installEventFilter(this);
162  m_ui->m_dateTimeEdit->installEventFilter(this);
163  m_ui->m_initialAnimationDateTimeEdit->installEventFilter(this);
164  m_ui->m_finalAnimationDateTimeEdit->installEventFilter(this);
165 
166  m_ui->m_dateTimeEdit->setDisplayFormat("dd/MMM/yyyy hh:mm:ss");
167  m_ui->m_initialAnimationDateTimeEdit->setDisplayFormat("dd/MMM/yyyy hh:mm:ss");
168  m_ui->m_finalAnimationDateTimeEdit->setDisplayFormat("dd/MMM/yyyy hh:mm:ss");
169 
170  //onAddHidroPushButtonClicked(true);
171 
172  //calculateSpatialExtent();
173  //calculateTemporalExtent();
174  //createAnimations();
175  //setDuration(m_duration);
176  //setDirection(m_direction);
177  //updateSliderPos();
178  //onStopToolButtonnClicked();
179 
180  if(m_animationScene->items().isEmpty())
181  {
182  m_ui->m_durationSpinBox->setEnabled(false);
183  m_ui->m_settingsToolButton->setEnabled(false);
184  m_ui->m_playToolButton->setEnabled(false);
185  m_ui->m_stopToolButton->setEnabled(false);
186  m_ui->m_dateTimeEdit->setEnabled(false);
187  showPropertySection(false);
188  }
189  else
190  {
191  m_ui->m_durationSpinBox->setEnabled(true);
192  m_ui->m_settingsToolButton->setEnabled(true);
193  m_ui->m_playToolButton->setEnabled(true);
194  m_ui->m_stopToolButton->setEnabled(true);
195  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
196  m_ui->m_dateTimeEdit->setEnabled(true);
197  else
198  m_ui->m_dateTimeEdit->setEnabled(false);
199  }
200 
201  if(m_display->getExtent().isValid() == false)
202  {
203  QRectF r = m_animationScene->sceneRect();
204  te::gm::Envelope e(r.left(), r.top(), r.right(), r.bottom());
205  m_display->setExtent(e);
206  }
207  if(m_display->getSRID() <= 0)
208  {
209  QList<QGraphicsItem*> list = m_animationScene->items();
210  QList<QGraphicsItem*>::iterator it = list.begin();
211  if(it != list.end())
212  {
213  AnimationItem* ai = (AnimationItem*)(*it);
214  int srid = ai->m_SRID;
215  m_display->setSRID(srid);
216  }
217  }
218 }
219 
221 {
222  m_parallelAnimation->stop(); // should be before clear
223  m_parallelAnimation->clear();
224  delete m_parallelAnimation;
225  delete m_animationScene;
226 
227  bool b = m_animationView->testAttribute(Qt::WA_DeleteOnClose);
228  m_animationView->close();
229  if(b == false)
230  delete m_animationView;
231 }
232 
234 {
235  const QMimeData* mdata = e->mimeData();
236  QList<QUrl> urls = mdata->urls();
237  if(urls.empty())
238  {
239  QByteArray ba = mdata->data("application/x-terralib;value=\"DraggedItems\"");
240  if(ba.count() != 0)
241  {
242  QString s(ba);
243  std::vector<te::qt::widgets::AbstractTreeItem*>* ditems = (std::vector<AbstractTreeItem*>*)s.toULongLong();
244  std::vector<te::qt::widgets::AbstractTreeItem*>::iterator it;
245  for(it = ditems->begin(); it != ditems->end(); ++it)
246  {
248  std::string ltype = ati->getLayer()->getType();
249  if(ltype == "DATASETLAYER")
250  {
252  te::map::DataSetLayer* layer = (te::map::DataSetLayer*)al.get();
253  std::string dsid = layer->getDataSourceId();
255  std::map<std::string, std::string> ci = ds->getConnectionInfo();
256  std::map<std::string, std::string>::iterator it = ci.find("URI");
257  if(it != ci.end())
258  {
259  std::string uri(it->second);
260  if(uri.find("kml") != std::string::npos)
261  {
262  if(layer->getDataSetName() == "40: locations" || layer->getDataSetName() == "41: locations")
263  {
264  e->setDropAction(Qt::LinkAction); // this line is necessary to not move items on the layer explorer
265  //e->setDropAction(Qt::CopyAction); // this line is necessary to not move items on the layer explorer
266  e->setAccepted(true);
267  }
268  }
269  }
270  }
271  }
272  }
273  else
274  e->setAccepted(false);
275  }
276  else
277  {
278  QString path = urls.begin()->path();
279  size_t pos = path.indexOf("/");
280  if(pos == 0)
281  path.remove(0, 1);
282  QDir dir(path);
283  QStringList nameFilter;
284  nameFilter.append("*.ctl");
285  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
286  if(files.empty() == false)
287  {
288  QString file(path + "/" + files.first());
289  FILE* fp = fopen(file.toStdString().c_str(), "r");
290  char buf[2000];
291  int c = fread(buf, sizeof(char), 2000, fp);
292  fclose(fp);
293  buf[c] = 0;
294  QString s(buf);
295  if(s.contains("undef", Qt::CaseInsensitive))
296  e->setAccepted(true);
297  else
298  e->setAccepted(false);
299  }
300  else
301  {
302  nameFilter.clear();
303  nameFilter.append("S1123*.jpg");
304  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
305  if(files.empty() == false && files.first().length() == 26)
306  e->setAccepted(true);
307  else
308  {
309  nameFilter.clear();
310  nameFilter.append("S1118*.jpg");
311  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
312  if(files.empty() == false && files.first().length() == 26)
313  e->setAccepted(true);
314  else
315  e->setAccepted(false);
316  }
317  }
318  }
319 }
320 
322 {
323  m_dropModifiers = e->keyboardModifiers();
324  const QMimeData* mdata = e->mimeData();
325  m_dropUrls = mdata->urls();
326  m_dropBA = mdata->data("application/x-terralib;value=\"DraggedItems\"");
327  QTimer::singleShot(10, this, SLOT(dropAction()));
328 }
329 
331 {
332  te::qt::widgets::ScopedCursor scopedCursor(Qt::WaitCursor);
333  int state = m_parallelAnimation->state();
334  if(state == QAbstractAnimation::Running)
335  onPlayToolButtonnClicked(); // put to paused state
336 
337  if(m_dropModifiers == Qt::NoModifier)
338  {
339  onStopToolButtonnClicked();
340  m_itemList.clear();
341  m_ui->m_opacityComboBox->clear();
342  m_ui->m_trajectoryColorComboBox->clear();
343  m_ui->m_TemporalHorizontalSlider->setValue(0);
344  m_parallelAnimation->setCurrentTime(0);
345  m_ui->m_settingsToolButton->setEnabled(false);
346  m_ui->m_playToolButton->setEnabled(false);
347  m_ui->m_stopToolButton->setEnabled(false);
348  m_ui->m_durationSpinBox->setEnabled(false);
349  m_ui->m_dateTimeEdit->setEnabled(false);
350  showPropertySection(false);
351 
352  QList<QGraphicsItem*> list = m_animationScene->items();
353  QList<QGraphicsItem*>::iterator it;
354  for(it = list.begin(); it != list.end(); ++it)
355  {
357  m_animationScene->removeItem(ai);
358  m_parallelAnimation->removeAnimation(ai->m_animation);
359  delete ai->m_animation;
360  delete ai;
361  }
362  m_display->update();
363  }
364 
365  if(m_dropUrls.empty())
366  {
367  if(m_dropBA.count() != 0)
368  {
369  QString s(m_dropBA);
370  std::vector<te::qt::widgets::AbstractTreeItem*>* ditems = (std::vector<AbstractTreeItem*>*)s.toULongLong();
371  std::vector<te::qt::widgets::AbstractTreeItem*>::iterator it;
372  for(it = ditems->begin(); it != ditems->end(); ++it)
373  {
375  std::string ltype = ati->getLayer()->getType();
376  if(ltype == "DATASETLAYER")
377  {
379  te::map::DataSetLayer* layer = (te::map::DataSetLayer*)al.get();
380  std::string dsid = layer->getDataSourceId();
382  std::map<std::string, std::string> ci = ds->getConnectionInfo();
383  std::map<std::string, std::string>::iterator it = ci.find("URI");
384  if(it != ci.end())
385  {
386  QString dsetname(layer->getDataSetName().c_str());
387  QString uri(it->second.c_str());
388  if(dsetname == "40: locations" || dsetname == "41: locations")
389  {
390  QPair<QString, QString> p(uri, dsetname);
391 
392  if(alreadyExists(p))
393  QMessageBox::information(this, dsetname + " alredy exists", "This item is already being animated!");
394  else
395  openTrajectory(uri, dsetname);
396  }
397  }
398  }
399  }
400  }
401  }
402  else
403  {
404  QString path = m_dropUrls.first().path();
405  path.remove(0, 1);
406 
407  QPair<QString, QString> p(path, "");
408 
409  if(alreadyExists(p))
410  QMessageBox::information(this, "animation alredy exists", "This item is already being animated!");
411  else
412  addTemporalImages(path);
413  }
414 
415  if(state == QAbstractAnimation::Running || m_dropModifiers == Qt::NoModifier)
416  onPlayToolButtonnClicked();
417 }
418 
419 bool te::qt::widgets::TimeSliderWidget::alreadyExists(QPair<QString, QString>& item)
420 {
421  QList<QPair<QString, QString> >::iterator it;
422  for(it = m_itemList.begin(); it != m_itemList.end(); ++it)
423  {
424  if(*it == item)
425  return true;
426  }
427  m_itemList.append(item);
428  return false;
429 }
430 
431 void te::qt::widgets::TimeSliderWidget::openTrajectory(const QString file, const QString& leao)
432 {
433  te::da::DataSourceInfo dsinfo;
434  std::map<std::string, std::string> connInfo;
435  connInfo["URI"] = file.toStdString();
436  dsinfo.setConnInfo(connInfo);
437  dsinfo.setType("OGR");
438  dsinfo.setId(file.toStdString());
439 
440  if(te::da::DataSourceManager::getInstance().find(file.toStdString()) == 0)
441  {
442  //Create the data source and put it into the manager
443  te::da::DataSourceManager::getInstance().open(dsinfo.getId(), dsinfo.getType(), dsinfo.getConnInfo());
444  }
445 
446  //Indicates how the trajectories are stored in the data source -> This structure is fixed for OGR driver
447  int phTimeIdx = 3; /* property name: timestamp */
448  int geomIdx = 12; /* property name: geom */
449 
450  //It initializes the st data loader support
452 
453  //Use the STDataLoader to create a TrajectoryDataSet with all observations
454 
455  if(leao == "40: locations")
456  {
457  te::st::TrajectoryDataSetInfo tjinfo40(dsinfo, "40: locations", phTimeIdx, geomIdx, -1, "40");
458  te::st::TrajectoryDataSet* tjDS40 = te::st::STDataLoader::getDataSet(tjinfo40).release();
459  addTrajectory(leao, "c:/lixo/helicopteroT2.png", tjDS40);
460  delete tjDS40;
461  }
462  else if(leao == "41: locations")
463  {
464  te::st::TrajectoryDataSetInfo tjinfo41(dsinfo, "41: locations", phTimeIdx, geomIdx, -1, "41");
465  te::st::TrajectoryDataSet* tjDS41 = te::st::STDataLoader::getDataSet(tjinfo41).release();
466  addTrajectory(leao, "c:/lixo/cachorro_correndo_31.gif", tjDS41);
467  delete tjDS41;
468  }
470 }
471 
472 void te::qt::widgets::TimeSliderWidget::addTrajectory(const QString& title, const QString& pixmapFile, te::st::TrajectoryDataSet* dset)
473 {
474  TrajectoryItem* ti = new TrajectoryItem(title, pixmapFile, m_display);
475  m_animationScene->addItem(ti);
476  Animation* animation = new Animation(ti, "pos");
477  animation->setEasingCurve(QEasingCurve::Linear);
478 
479  //Indicates how the trajectories are stored in the data source -> This structure is fixed for OGR driver
480  int phTimeIdx = 3; /* property name: timestamp */
481  int geomIdx = 12; /* property name: geom */
482 
483  if(title == "40: locations") // change default colors
484  {
485  ti->m_opacity = 120;
486  ti->m_forwardColor = Qt::green;
487  ti->m_forwardColor.setAlpha(ti->m_opacity);
488  ti->m_backwardColor = Qt::cyan;
489  ti->m_backwardColor.setAlpha(ti->m_opacity);
490  }
491 
492  animation->m_spatialExtent = dset->getSpatialExtent();
493  animation->m_temporalExtent = *static_cast<te::dt::TimePeriod*>(dset->getTemporalExtent());
494 
495  size_t size = dset->size();
496  //********************************************************************************************************
497  ti->m_SRID = 4326; // ver como obter SRID...
498  //********************************************************************************************************
499  QPointF pf;
500  if(size > 0)
501  {
502  te::dt::TimeInstant tiraRepetido;
504  size_t i = 0;
505  while(dset->moveNext())
506  {
507  std::auto_ptr<te::dt::DateTime> time = dset->getTime();
508  te::dt::DateTimeType type = time->getDateTimeType();
509  te::dt::TimeInstant* tinstant = static_cast<te::dt::TimeInstant*>(time.get());
510  if(tiraRepetido == *tinstant)
511  continue;
512  tiraRepetido = *tinstant;
513 
514  ti->m_time.push_back(te::dt::TimeInstant(tinstant->getTimeInstant()));
515 
516  std::auto_ptr<te::gm::Geometry> geom = dset->getGeometry();
517  const te::gm::Point* p = static_cast<const te::gm::Point*>(geom.get());
518  te::gm::Point pp(*p);
519  ti->m_route->setPointN(i++, pp);
520  }
521  }
522 
523  m_parallelAnimation->addAnimation(animation);
524  calculateSpatialExtent();
525  calculateTemporalExtent();
526  createAnimations();
527  setDuration(m_duration);
528  setDirection(m_direction);
529 
530  int state = m_parallelAnimation->state();
531  if(state == QAbstractAnimation::Running)
532  {
533  onPlayToolButtonnClicked();
534  m_parallelAnimation->setCurrentTime(m_currentTime);
535  }
536  if(m_animationScene->items().isEmpty() == false)
537  {
538  m_ui->m_durationSpinBox->setEnabled(true);
539  m_ui->m_settingsToolButton->setEnabled(true);
540  m_ui->m_playToolButton->setEnabled(true);
541  m_ui->m_stopToolButton->setEnabled(true);
542  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
543  m_ui->m_dateTimeEdit->setEnabled(true);
544  else
545  m_ui->m_dateTimeEdit->setEnabled(false);
546  }
547  initProperty();
548 
549  m_ui->m_trajectoryColorComboBox->addItem(title);
550  int count = m_ui->m_trajectoryColorComboBox->count();
551  m_ui->m_trajectoryColorComboBox->setCurrentIndex(count-1);
552  onTrajectoryColorComboBoxActivated(count-1);
553 
554  m_ui->m_opacityComboBox->addItem(title);
555  count = m_ui->m_opacityComboBox->count();
556  m_ui->m_opacityComboBox->setCurrentIndex(count-1);
557  onOpacityComboBoxActivated(count-1);
558 }
559 
561 {
562  if(m_animationScene->items().isEmpty())
563  m_ui->m_durationSpinBox->setValue(m_duration);
564 
565  int state = m_parallelAnimation->state();
566  m_currentTime = m_parallelAnimation->currentTime();
567  if(state == QAbstractAnimation::Running)
568  onPlayToolButtonnClicked();
569 
570  te::qt::widgets::PixmapItem* pi = getMetadata(filePath);
571  if(pi == 0)
572  {
573  QMessageBox::information(this, "Error", "Load error");
574  m_itemList.pop_back();
575  return;
576  }
577 
578  calculateSpatialExtent();
579  calculateTemporalExtent();
580  createAnimations();
581  setDuration(m_duration);
582  setDirection(m_direction);
583  if(state == QAbstractAnimation::Running)
584  {
585  onPlayToolButtonnClicked();
586  m_parallelAnimation->setCurrentTime(m_currentTime);
587  }
588  if(m_animationScene->items().isEmpty() == false)
589  {
590  m_ui->m_durationSpinBox->setEnabled(true);
591  m_ui->m_settingsToolButton->setEnabled(true);
592  m_ui->m_playToolButton->setEnabled(true);
593  m_ui->m_stopToolButton->setEnabled(true);
594  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
595  m_ui->m_dateTimeEdit->setEnabled(true);
596  else
597  m_ui->m_dateTimeEdit->setEnabled(false);
598  }
599  initProperty();
600 
601  QDir dir(filePath);
602  m_ui->m_opacityComboBox->addItem(dir.dirName());
603  int count = m_ui->m_opacityComboBox->count();
604  m_ui->m_opacityComboBox->setCurrentIndex(count-1);
605  onOpacityComboBoxActivated(count-1);
606 }
607 
609 {
610  PixmapItem* pi = getTemporalImageCtlParameters(path);
611  if(pi == 0)
612  return 0;
613 
614  m_animationScene->addItem(pi);
615  Animation* animation = new Animation(pi, "pos");
616  animation->m_spatialExtent = te::gm::Envelope(pi->m_imaRect.x(), pi->m_imaRect.y(), pi->m_imaRect.right(), pi->m_imaRect.bottom());
617  animation->setEasingCurve(QEasingCurve::Linear);
618  m_parallelAnimation->addAnimation(animation);
619 
620  QString suffix = "." + pi->m_suffix;
621  QStringList nameFilter;
622  nameFilter.append("*" + suffix);
623  QDir dir(path);
624  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
625  size_t count = files.count();
626 
627  // get time extent
628  te::dt::TimeInstant ti = getGoesTime(path + "/" + files.first());
629  te::dt::TimeInstant tf = getGoesTime(path + "/" + files.last());
630  animation->m_temporalExtent = te::dt::TimePeriod(ti, tf);
631 
632  // set data
634  for(size_t i = 0; i < count; ++i)
635  {
636  QString f = files[i];
637  t = getGoesTime(f);
638  pi->m_time.push_back(t);
639  pi->m_files.push_back(f);
640  }
641 
643 
644  // crie valores não repetitivos e nem muito grandes ou pequenos
645  QPointF pos(animation->m_spatialExtent.m_llx, animation->m_spatialExtent.m_lly);
646  double w = animation->m_spatialExtent.getWidth();
647  double h = animation->m_spatialExtent.getHeight();
648  for(size_t i = 0; i < count; ++i)
649  {
650  if(i & 1)
651  pos -= QPointF(w, h);
652  else
653  pos += QPointF(w, h);
654 
655  pi->m_route->setPoint(i, pos.x(), pos.y());
656  }
657 
658  return pi;
659 }
660 
662 {
663  int srid = -1;
664  m_spatialExtent = te::gm::Envelope();
665 
666  QList<QGraphicsItem*> list = m_animationScene->items();
667  QList<QGraphicsItem*>::iterator it;
668 
669  for(it = list.begin(); it != list.end(); ++it)
670  {
671  AnimationItem* ai = (AnimationItem*)(*it);
672  srid = ai->m_SRID;
673  if(m_display->getSRID() != TE_UNKNOWN_SRS && m_display->getSRID() != ai->m_SRID)
674  {
676  e.transform(ai->m_SRID, m_display->getSRID());
677  m_spatialExtent.Union(e);
678  }
679  else
680  m_spatialExtent.Union(ai->m_animation->m_spatialExtent);
681  }
682  QRect rect(m_spatialExtent.m_llx, m_spatialExtent.m_lly, m_spatialExtent.getWidth(), m_spatialExtent.getHeight());
683  m_animationScene->setSceneRect(rect);
684  m_animationView->setSceneRect(rect);
685 }
686 
688 {
689  te::dt::TimeInstant initial, final, t_initial, t_final;
690 
691  QList<QGraphicsItem*> list = m_animationScene->items();
692  QList<QGraphicsItem*>::iterator it = list.begin();
693  if(it != list.end())
694  {
695  AnimationItem* ai = (AnimationItem*)(*it);
698  ++it;
699  }
700 
701  while(it != list.end())
702  {
703  AnimationItem* ai = (AnimationItem*)(*it);
705  if(initial < t_initial)
706  t_initial = initial;
707 
709  if(final > t_final)
710  t_final = final;
711  ++it;
712  }
713 
714  m_temporalExtent = te::dt::TimePeriod(t_initial, t_final);
715  te::dt::TimePeriod tp(t_initial, t_final);
716  m_temporalAnimationExtent = tp;
717 
718  for(it = list.begin(); it != list.end(); ++it)
719  {
720  AnimationItem* ai = (AnimationItem*)(*it);
721  ai->m_animation->m_temporalAnimationExtent = m_temporalExtent;
722  }
723 
724  QDateTime minimum(QDate(t_initial.getDate().getYear(), t_initial.getDate().getMonth(), t_initial.getDate().getDay()),
725  QTime(t_initial.getTime().getHours(), t_initial.getTime().getMinutes(), t_initial.getTime().getSeconds()));
726  QDateTime maximum(QDate(t_final.getDate().getYear(), t_final.getDate().getMonth(), t_final.getDate().getDay()),
727  QTime(t_final.getTime().getHours(), t_final.getTime().getMinutes(), t_final.getTime().getSeconds()));
728 
729  m_ui->m_dateTimeEdit->setMinimumDateTime(minimum);
730  m_ui->m_dateTimeEdit->setMaximumDateTime(maximum);
731 }
732 
734 {
735  size_t i;
736  QVector<te::dt::TimePeriod> times;
737  QVector<te::gm::Envelope> envelopes;
738  QList<QGraphicsItem*> list = m_animationScene->items();
739  QList<QGraphicsItem*>::iterator it;
740  for(it = list.begin(); it != list.end(); ++it)
741  {
742  AnimationItem* ai = (AnimationItem*)(*it);
743  times.push_back(ai->m_animation->m_temporalExtent);
744  envelopes.push_back(ai->m_animation->m_spatialExtent);
745  }
746 
747  if(m_parallelAnimation->state() == QAbstractAnimation::Stopped)
748  m_parallelAnimation->clear();
749  else
750  {
751  int cur = m_parallelAnimation->currentTime();
752  m_parallelAnimation->stop();
753  m_parallelAnimation->clear();
754  m_parallelAnimation->setCurrentTime(cur);
755  }
756 
757  for(it = list.begin(), i = 0 ; it != list.end(); ++it, ++i)
758  {
759  AnimationItem* ai = (AnimationItem*)(*it);
761  a->m_spatialExtent = envelopes[i];
762  a->m_temporalExtent = times[i];
763  a->m_temporalAnimationExtent = m_temporalAnimationExtent;
764  a->createAnimationDataInDisplayProjection(m_temporalAnimationExtent);
765  m_parallelAnimation->addAnimation(a);
766  }
767 }
768 
770 {
771  boost::posix_time::ptime pTime = timeInstant.getTimeInstant();
772 
773  // total time duration
774  boost::posix_time::ptime iTime = m_temporalAnimationExtent.getInitialTimeInstant().getTimeInstant();
775  boost::posix_time::ptime fTime = m_temporalAnimationExtent.getFinalTimeInstant().getTimeInstant();
776  boost::posix_time::time_duration diff = fTime - iTime;
777  double totalSeconds = diff.total_seconds();
778 
779  diff = pTime - iTime;
780  double seconds = diff.total_seconds();
781  // normalizing the time
782  double t = seconds / totalSeconds;
783  t *= 1000;
784  int ret = (int)t;
785  return ret;
786 }
787 
789 {
790  double t = m_parallelAnimation->currentTime();
791  double trel = t / (double)m_duration;
792 
793  // total time duration
794  boost::posix_time::ptime iTime = m_temporalAnimationExtent.getInitialTimeInstant().getTimeInstant();
795  boost::posix_time::ptime fTime = m_temporalAnimationExtent.getFinalTimeInstant().getTimeInstant();
796  boost::posix_time::time_duration diff = fTime - iTime;
797  double totalSeconds = diff.total_seconds();
798 
799  int secs = qRound(totalSeconds * trel);
800  boost::posix_time::time_duration td = boost::posix_time::seconds(secs);
801  boost::posix_time::ptime time = iTime + td;
802  te::dt::TimeInstant timei(time);
803  return timei;
804 }
805 
807 {
808  te::gm::Envelope env = m_display->getExtent();
809  QRectF drect(env.m_llx, env.m_lly, env.getWidth(), env.getHeight());
810 
812  if(m_ui->m_dateTimeEdit->isEnabled() == false)
813  t = getTimeInstant();
814  else
815  {
816  QDateTime d = m_ui->m_dateTimeEdit->dateTime();
817  t = te::dt::TimeInstant(te::dt::Date(d.date().year(), d.date().month(), d.date().day()),
818  te::dt::TimeDuration(d.time().hour(), d.time().minute(), d.time().second(), 0));
819  }
820 
821  QList<QGraphicsItem*> list = m_animationScene->items();
822  QList<QGraphicsItem*>::iterator it;
823 
824  if(m_animationScene->m_numberOfPixmaps) // has images
825  {
826  // draw pixmap items
827  for(it = list.begin(); it != list.end(); ++it)
828  {
829  AnimationItem* ai = (AnimationItem*)(*it);
830  if(ai->pixmap().isNull())
831  {
832  // draw only the items that are within the time frame
833  te::dt::TimeInstant tini = ai->m_animationTime.first();
834  te::dt::TimeInstant tfim = ai->m_animationTime.last();
835  if(t < tini || t > tfim)
836  continue;
837 
838  // draw pixmap itens
839  PixmapItem* pi = (PixmapItem*)ai;
840  drawPixmapItem(pi, drect, painter);
841  }
842  }
843  }
844 
845  if(m_animationScene->m_numberOfTrajectories) // has trajectories
846  {
847  // draw trail trajectories
848  QPixmap* pixt = ((AnimationScene*)(m_animationScene))->m_trajectoryPixmap;
849  painter->drawPixmap(0, 0, *pixt);
850 
851  // draw icon trajectories
852  for(it = list.begin(); it != list.end(); ++it)
853  {
854  AnimationItem* ai = (AnimationItem*)(*it);
855  if(ai->pixmap().isNull() == false)
856  {
857  // draw only the items that are within the time frame
858  te::dt::TimeInstant tini = ai->m_animationTime.first();
859  te::dt::TimeInstant tfim = ai->m_animationTime.last();
860  if(t < tini || t > tfim)
861  continue;
862 
863  // draw trajectory icons
864  QPoint p = ai->getPosInDeviceCoordinate();
865  QRect r = ai->pixmap().rect();
866  r.moveCenter(p);
867  QRect dr = m_display->rect();
868  if(dr.intersects(r))
869  drawTrajectoryIcon((te::qt::widgets::TrajectoryItem*)ai, r.topLeft(), painter);
870  }
871  }
872  }
873 
874  updateSliderPos();
875 }
876 
878 {
879  m_goAndBack = v;
880  m_comingBack = !v;
881 }
882 
883 void te::qt::widgets::TimeSliderWidget::setDirection(const QAbstractAnimation::Direction& direction)
884 {
885  m_direction = direction;
886  m_parallelAnimation->setDirection(m_direction);
887 
888  unsigned int count = m_parallelAnimation->animationCount();
889  for(unsigned int i = 0; i < count; ++i)
890  {
891  QPropertyAnimation* a = (QPropertyAnimation*)m_parallelAnimation->animationAt(i);
892  AnimationItem* ai = (AnimationItem*)a->targetObject();
893  ai->setDirection(m_direction);
894  ai->setDuration(m_duration);
895  }
896 }
897 
898 void te::qt::widgets::TimeSliderWidget::setDuration(const unsigned int& duration)
899 {
900  m_animationScene->setDuration(duration);
901 }
902 
904 {
905  m_animationScene->createNewPixmap();
906 }
907 
909 {
910  m_animationScene->createNewPixmap();
911  m_animationScene->setMatrix();
912  m_animationScene->draw(m_currentTime);
913 }
914 
916 {
917  m_animationScene->setAutomaticPan(title);
918 }
919 
921 {
922  if(obj == m_ui->m_forwardColorPushButton)
923  {
924  if(e->type() == QEvent::Paint)
925  {
926  QPainter painter(m_ui->m_forwardColorPushButton);
927  QBrush brush(m_ui->m_forwardColorPushButton->palette().color(QPalette::Window));
928  painter.fillRect(m_ui->m_forwardColorPushButton->rect(), brush);
929  return true;
930  }
931  else if(e->type() == QEvent::MouseButtonPress)
932  {
933  QColor cor = QColorDialog::getColor(m_ui->m_forwardColorPushButton->palette().color(QPalette::Window), this, "Forward Color", QColorDialog::ShowAlphaChannel);
934  if(cor.isValid() == false)
935  return true;
936  else if(cor == m_ui->m_forwardColorPushButton->palette().color(QPalette::Window))
937  return true;
938 
939  m_ui->m_forwardColorPushButton->setPalette(QPalette(cor));
940 
941  QString titlecb = m_ui->m_trajectoryColorComboBox->currentText();
942 
943  QList<QGraphicsItem*> list = m_animationScene->items();
944  QList<QGraphicsItem*>::iterator it;
946 
947  for(it = list.begin(); it != list.end(); ++it)
948  {
949  ti = (te::qt::widgets::TrajectoryItem*)(*it);
950  QString title = ti->m_title;
951  if(title == titlecb)
952  break;
953  }
954  if(ti != 0)
955  ti->m_forwardColor = cor;
956 
957  return true;
958  }
959  }
960  else if(obj == m_ui->m_backwardColorPushButton)
961  {
962  if(e->type() == QEvent::Paint)
963  {
964  QPainter painter(m_ui->m_backwardColorPushButton);
965  QBrush brush(m_ui->m_backwardColorPushButton->palette().color(QPalette::Window));
966  painter.fillRect(m_ui->m_backwardColorPushButton->rect(), brush);
967  return true;
968  }
969  else if(e->type() == QEvent::MouseButtonPress)
970  {
971  QColor cor = QColorDialog::getColor(m_ui->m_backwardColorPushButton->palette().color(QPalette::Window), this, "Forward Color", QColorDialog::ShowAlphaChannel);
972  if(cor.isValid() == false)
973  return true;
974  else if(cor == m_ui->m_backwardColorPushButton->palette().color(QPalette::Window))
975  return true;
976 
977  m_ui->m_backwardColorPushButton->setPalette(QPalette(cor));
978 
979  QString titlecb = m_ui->m_trajectoryColorComboBox->currentText();
980 
981  QList<QGraphicsItem*> list = m_animationScene->items();
982  QList<QGraphicsItem*>::iterator it;
984 
985  for(it = list.begin(); it != list.end(); ++it)
986  {
987  ti = (te::qt::widgets::TrajectoryItem*)(*it);
988  QString title = ti->m_title;
989  if(title == titlecb)
990  break;
991  }
992  if(ti != 0)
993  ti->m_backwardColor = cor;
994 
995  return true;
996  }
997  }
998 
999  if(e->type() == QEvent::Close)
1000  {
1001  if(obj == this)
1002  {
1003  e->ignore();
1004  onStopToolButtonnClicked();
1005  m_display->update();
1006 
1007  hide();
1008  deleteMe();
1009  return true;
1010  }
1011  else if(obj == m_animationView)
1012  {
1013  e->ignore();
1014  return true;
1015  }
1016  }
1017  else if(e->type() == QEvent::Show)
1018  {
1019  if(obj == this)
1020  return true;
1021  }
1022  else if(e->type() == QEvent::Enter)
1023  {
1024  if(obj == this)
1025  {
1026  if(graphicsEffect())
1027  graphicsEffect()->setEnabled(false);
1028  return true;
1029  }
1030  }
1031  else if(e->type() == QEvent::Leave)
1032  {
1033  if(obj == this)
1034  {
1035  if(graphicsEffect())
1036  graphicsEffect()->setEnabled(true);
1037  return true;
1038  }
1039  }
1040  else if(e->type() == QEvent::MouseButtonRelease)
1041  {
1042  if(obj == m_ui->m_dateTimeEdit)
1043  {
1044  QDateTime d = m_ui->m_dateTimeEdit->dateTime();
1045  if(d == m_oldQDateTime)
1046  {
1047  d = fixDateTimeEdit(m_ui->m_dateTimeEdit, d);
1048  m_ui->m_dateTimeEdit->setDateTime(d);
1049  }
1050  m_oldQDateTime = d;
1051  return false;
1052  }
1053  else if(obj == m_ui->m_initialAnimationDateTimeEdit)
1054  {
1055  QDateTime d = m_ui->m_initialAnimationDateTimeEdit->dateTime();
1056  if(d == m_oldIQDateTime)
1057  {
1058  d = fixDateTimeEdit(m_ui->m_initialAnimationDateTimeEdit, d);
1059  m_ui->m_initialAnimationDateTimeEdit->setDateTime(d);
1060  }
1061  m_oldIQDateTime = d;
1062  return false;
1063  }
1064  else if(obj == m_ui->m_finalAnimationDateTimeEdit)
1065  {
1066  QDateTime d = m_ui->m_finalAnimationDateTimeEdit->dateTime();
1067  if(d == m_oldFQDateTime)
1068  {
1069  d = fixDateTimeEdit(m_ui->m_finalAnimationDateTimeEdit, d);
1070  m_ui->m_finalAnimationDateTimeEdit->setDateTime(d);
1071  }
1072  m_oldFQDateTime = d;
1073  return false;
1074  }
1075  }
1076 
1077  return QWidget::eventFilter(obj, e);
1078 }
1079 
1081 {
1082  if(m_ui->m_propertyWidget->isHidden())
1083  {
1084  showPropertySection(true);
1085  initProperty();
1086  }
1087  else
1088  showPropertySection(false);
1089 }
1090 
1092 {
1093  int state = m_parallelAnimation->state();
1094  if(state == QAbstractAnimation::Running)
1095  {
1096  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
1097  m_parallelAnimation->pause();
1098  m_ui->m_dateTimeEdit->setEnabled(true);
1099  }
1100  else
1101  {
1102  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-pause"));
1103  if(m_parallelAnimation->direction() == QAbstractAnimation::Forward)
1104  {
1105  if(m_ui->m_TemporalHorizontalSlider->value() == m_maxSliderValue)
1106  {
1107  m_parallelAnimation->setCurrentTime(0);
1108  m_ui->m_TemporalHorizontalSlider->setValue(0);
1109  }
1110  }
1111  else
1112  {
1113  if(m_ui->m_TemporalHorizontalSlider->value() == 0)
1114  {
1115  m_parallelAnimation->setCurrentTime(m_duration);
1116  m_ui->m_TemporalHorizontalSlider->setValue(m_maxSliderValue);
1117  }
1118  }
1119  m_ui->m_dateTimeEdit->setEnabled(false);
1120  play();
1121  }
1122 }
1123 
1125 {
1126  int state = m_parallelAnimation->state();
1127  m_parallelAnimation->stop();
1128  m_ui->m_dateTimeEdit->setEnabled(false);
1129  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
1130 
1131  if(m_goAndBack)
1132  {
1133  if(m_comingBack)
1134  {
1135  changeDirection();
1136  m_comingBack = false;
1137  }
1138  }
1139 
1140  if(m_finished == false)
1141  {
1142  if(m_parallelAnimation->direction() == QAbstractAnimation::Forward)
1143  {
1144  m_ui->m_TemporalHorizontalSlider->setValue(0);
1145  m_parallelAnimation->setCurrentTime(0);
1146  }
1147  else
1148  {
1149  m_ui->m_TemporalHorizontalSlider->setValue(m_maxSliderValue);
1150  m_parallelAnimation->setCurrentTime(m_parallelAnimation->duration());
1151  }
1152  updateSliderPos();
1153  m_display->update();
1154  }
1155  m_finished = false;
1156 }
1157 
1159 {
1160  int state = m_parallelAnimation->state();
1161  if(state == QAbstractAnimation::Running)
1162  {
1163  m_parallelAnimation->pause();
1164  createNewPixmap();
1165  draw();
1166  m_display->update();
1167  m_parallelAnimation->resume();
1168  }
1169  else
1170  {
1171  createNewPixmap();
1172  draw();
1173  m_display->update();
1174  }
1175 }
1176 
1178 {
1179  int state = m_parallelAnimation->state();
1180  if(state == QAbstractAnimation::Running)
1181  {
1182  createNewPixmap();
1183  calculateSpatialExtent();
1184  createAnimations();
1185  draw();
1186  m_display->update();
1187  m_parallelAnimation->start();
1188  }
1189  else
1190  {
1191  createNewPixmap();
1192  calculateSpatialExtent();
1193  createAnimations();
1194  draw();
1195  m_display->update();
1196  }
1197 }
1198 
1200 {
1201  int state = m_parallelAnimation->state();
1202  if(state == QAbstractAnimation::Stopped)
1203  {
1204  createNewPixmap();
1205  m_parallelAnimation->start();
1206  }
1207  else if(state == QAbstractAnimation::Paused)
1208  {
1209  m_parallelAnimation->resume();
1210  }
1211 }
1212 
1214 {
1215  int oldCurTime = m_parallelAnimation->currentTime();
1216 
1217  if(m_parallelAnimation->state() == QAbstractAnimation::Stopped)
1218  {
1219  onStopToolButtonnClicked();
1220  return;
1221  }
1222 
1223  double v = (double)value / (double)m_maxSliderValue;
1224 
1225  int curTime = qRound(v * (double)m_parallelAnimation->duration());
1226 
1227  if(curTime == 0)
1228  curTime = 1;
1229  else if(curTime == m_parallelAnimation->duration())
1230  curTime = m_parallelAnimation->duration() - 1;
1231 
1232  bool erase = false;
1233  if(m_goAndBack == true)
1234  {
1235  if(m_comingBack == false && m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1236  erase = true;
1237  else if(m_comingBack == false && m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1238  erase = true;
1239  else if(m_comingBack == true && m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1240  erase = true;
1241  else if(m_comingBack == true && m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1242  erase = true;
1243  }
1244  else
1245  {
1246  if(m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1247  erase = true;
1248  else if(m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1249  erase = true;
1250  }
1251 
1252  m_parallelAnimation->setCurrentTime(curTime);
1253  if(erase)
1254  this->erase(curTime);
1255 
1256  m_currentTime = curTime;
1257  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
1258  m_display->update();
1259 
1260  te::dt::TimeInstant tinstant = getTimeInstant();
1261  QDate qdate(tinstant.getDate().getYear(), tinstant.getDate().getMonth(), tinstant.getDate().getDay());
1262  QTime qtime(tinstant.getTime().getHours(), tinstant.getTime().getMinutes(), tinstant.getTime().getSeconds());
1263  QDateTime qdatetime(qdate, qtime);
1264  m_ui->m_dateTimeEdit->setDateTime(qdatetime);
1265 }
1266 
1268 {
1269  QAbstractAnimation::Direction direction = m_parallelAnimation->direction();
1270  if(direction == QAbstractAnimation::Forward)
1271  direction = QAbstractAnimation::Backward;
1272  else
1273  direction = QAbstractAnimation::Forward;
1274  setDirection(direction);
1275 }
1276 
1278 {
1279  m_finished = true;
1280  if(m_goAndBack)
1281  {
1282  changeDirection();
1283  m_comingBack = !m_comingBack;
1284  if(m_comingBack)
1285  {
1286  play();
1287  updateSliderPos();
1288  return;
1289  }
1290 
1291  if(m_loop)
1292  {
1293  play();
1294  }
1295  else
1296  {
1297  if(m_comingBack == false)
1298  onStopToolButtonnClicked();
1299  }
1300  }
1301  else
1302  {
1303  if(m_loop)
1304  {
1305  play();
1306  }
1307  else
1308  onStopToolButtonnClicked();
1309  }
1310 }
1311 
1313 {
1314  m_currentTime = m_parallelAnimation->currentTime();
1315  int v = qRound((double)m_maxSliderValue * (double)m_currentTime/(double)m_duration);
1316 
1317  m_ui->m_TemporalHorizontalSlider->setValue(v);
1318 
1319  updateTimeTextEdit();
1320 }
1321 
1323 {
1324  if(m_ui->m_dateTimeEdit->isEnabled() == false && m_animationScene->items().isEmpty() == false)
1325  {
1326  te::dt::TimeInstant tinstant = getTimeInstant();
1327  QDate qdate(tinstant.getDate().getYear(), tinstant.getDate().getMonth(), tinstant.getDate().getDay());
1328  QTime qtime(tinstant.getTime().getHours(), tinstant.getTime().getMinutes(), tinstant.getTime().getSeconds());
1329  QDateTime qdatetime(qdate, qtime);
1330  m_ui->m_dateTimeEdit->setDateTime(qdatetime);
1331  }
1332 }
1333 
1335 {
1336  emit deleteTimeSliderWidget();
1337 }
1338 
1340 {
1341  QString title = QInputDialog::getText(this, "Add Item", "title");
1342 
1343  if(title.isEmpty())
1344  return;
1345 
1346  te::qt::widgets::ScopedCursor scopedCursor(Qt::WaitCursor);
1347 
1348  QString path;
1349  if(title == "eta5km"|| title == "hidro")
1350  path = "C:/lixo/FORECAST/" + title;
1351  else
1352  path = "C:/lixo/TemporalImages/" + title;
1353 
1354  addTemporalImages(path);
1355 }
1356 
1357 //void te::qt::widgets::TimeSliderWidget::onAddPushButtonClicked(bool b)
1358 //{
1359 // QString title = QInputDialog::getText(this, "Add Item", "title");
1360 //
1361 // if(title.isEmpty())
1362 // return;
1363 //
1364 // te::qt::widgets::ScopedCursor scopedCursor(Qt::WaitCursor);
1365 //
1366 // if(title == "lm40" || title == "lm41")
1367 // {
1368 // if(m_animationScene->items().isEmpty())
1369 // m_ui->m_durationSpinBox->setValue(m_duration);
1370 //
1371 // int state = m_parallelAnimation->state();
1372 // m_currentTime = m_parallelAnimation->currentTime();
1373 // if(state == QAbstractAnimation::Running)
1374 // onPlayToolButtonnClicked();
1375 // openTrajectory(title);
1376 // calculateSpatialExtent();
1377 // calculateTemporalExtent();
1378 // createAnimations();
1379 // setDuration(m_duration);
1380 // setDirection(m_direction);
1381 // if(state == QAbstractAnimation::Running)
1382 // {
1383 // onPlayToolButtonnClicked();
1384 // m_parallelAnimation->setCurrentTime(m_currentTime);
1385 // }
1386 // m_ui->m_playToolButton->setEnabled(true);
1387 // }
1388 // else
1389 // {
1390 // QString path = "C:/lixo/TemporalImages/";
1391 // QString suffix = ".png";
1392 // bool meteorological = false;
1393 //
1394 // if(title == "NoDoubt")
1395 // {
1396 // title = "NoDoubt ";
1397 // path += "NoDoubt/";
1398 // suffix = ".jpg";
1399 // }
1400 // else if(title == "segredo")
1401 // {
1402 // title = "segredo ";
1403 // path += "segredo/";
1404 // suffix = ".jpg";
1405 // }
1406 // else if(title == "IR_high")
1407 // {
1408 // path += "IR_high/";
1409 // meteorological = true;
1410 // }
1411 // else if(title == "IR_low")
1412 // {
1413 // path += "IR_low/";
1414 // meteorological = true;
1415 // }
1416 // else if(title == "WV_high")
1417 // {
1418 // path += "WV_high/";
1419 // meteorological = true;
1420 // }
1421 // else if(title == "WV_low")
1422 // {
1423 // path += "WV_low/";
1424 // meteorological = true;
1425 // }
1426 // else if(title == "GOESColorfull_high")
1427 // {
1428 // path += "GOESColorfull_high/";
1429 // meteorological = true;
1430 // }
1431 // else if(title == "GOESColorfull_low")
1432 // {
1433 // path += "GOESColorfull_low/";
1434 // meteorological = true;
1435 // }
1436 // else if(title == "GOESRealce_high")
1437 // {
1438 // path += "GOESRealce_high/";
1439 // meteorological = true;
1440 // }
1441 // else if(title == "GOESRealce_low")
1442 // {
1443 // path += "GOESRealce_low/";
1444 // meteorological = true;
1445 // }
1446 // else if(title == "GOESRealce2_high")
1447 // {
1448 // path += "GOESRealce2_high/";
1449 // meteorological = true;
1450 // }
1451 // else if(title == "GOESRealce2_low")
1452 // {
1453 // path += "GOESRealce2_low/";
1454 // meteorological = true;
1455 // }
1456 // else if(title == "GMVapor_high")
1457 // {
1458 // path += "GMVapor_high/";
1459 // meteorological = true;
1460 // }
1461 // else if(title == "GMVapor_low")
1462 // {
1463 // path += "GMVapor_low/";
1464 // meteorological = true;
1465 // }
1466 //
1467 // if(meteorological)
1468 // {
1469 // if(m_animationScene->items().isEmpty())
1470 // m_ui->m_durationSpinBox->setValue(m_duration);
1471 //
1472 // int state = m_parallelAnimation->state();
1473 // m_currentTime = m_parallelAnimation->currentTime();
1474 // if(state == QAbstractAnimation::Running)
1475 // onPlayToolButtonnClicked();
1476 //
1477 // getGoesMetadata(path);
1478 // calculateSpatialExtent();
1479 // calculateTemporalExtent();
1480 // createAnimations();
1481 // setDuration(m_duration);
1482 // setDirection(m_direction);
1483 // if(state == QAbstractAnimation::Running)
1484 // {
1485 // onPlayToolButtonnClicked();
1486 // m_parallelAnimation->setCurrentTime(m_currentTime);
1487 // }
1488 // if(m_animationScene->items().isEmpty() == false)
1489 // {
1490 // m_ui->m_durationSpinBox->setEnabled(true);
1491 // m_ui->m_settingsToolButton->setEnabled(true);
1492 // m_ui->m_playToolButton->setEnabled(true);
1493 // m_ui->m_stopToolButton->setEnabled(true);
1494 // if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
1495 // m_ui->m_dateTimeEdit->setEnabled(true);
1496 // else
1497 // m_ui->m_dateTimeEdit->setEnabled(false);
1498 // }
1499 // initProperty();
1500 //
1501 // m_ui->m_opacityComboBox->addItem(title);
1502 // int count = m_ui->m_opacityComboBox->count();
1503 // m_ui->m_opacityComboBox->setCurrentIndex(count-1);
1504 // onOpacityComboBoxActivated(count-1);
1505 // return;
1506 // }
1507 //
1508 //
1509 // QString file = path + title + "000001" + suffix;
1510 // if(title.contains("fastfood"))
1511 // file = path + "fastfood000001.png";
1512 //
1513 // QFile qfile(file);
1514 // if(qfile.exists())
1515 // {
1516 // if(m_animationScene->items().isEmpty())
1517 // m_ui->m_durationSpinBox->setValue(m_duration);
1518 //
1519 // int state = m_parallelAnimation->state();
1520 // m_currentTime = m_parallelAnimation->currentTime();
1521 // if(state == QAbstractAnimation::Running)
1522 // onPlayToolButtonnClicked();
1523 //
1524 // addTemporalImages(path + title + suffix, true);
1525 // calculateSpatialExtent();
1526 // calculateTemporalExtent();
1527 // createAnimations();
1528 // setDuration(m_duration);
1529 // setDirection(m_direction);
1530 // if(state == QAbstractAnimation::Running)
1531 // {
1532 // onPlayToolButtonnClicked();
1533 // m_parallelAnimation->setCurrentTime(m_currentTime);
1534 // }
1535 // }
1536 // else
1537 // {
1538 // QMessageBox::information(this, "Not Added", "Invalid Animation item");
1539 // return;
1540 // }
1541 // }
1542 //
1543 // if(m_animationScene->items().isEmpty() == false)
1544 // {
1545 // m_ui->m_durationSpinBox->setEnabled(true);
1546 // m_ui->m_settingsToolButton->setEnabled(true);
1547 // m_ui->m_playToolButton->setEnabled(true);
1548 // m_ui->m_stopToolButton->setEnabled(true);
1549 // if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
1550 // m_ui->m_dateTimeEdit->setEnabled(true);
1551 // else
1552 // m_ui->m_dateTimeEdit->setEnabled(false);
1553 // }
1554 // initProperty();
1555 //
1556 // m_ui->m_opacityComboBox->addItem(title);
1557 // int count = m_ui->m_opacityComboBox->count();
1558 // m_ui->m_opacityComboBox->setCurrentIndex(count-1);
1559 // onOpacityComboBoxActivated(count-1);
1560 //}
1561 
1563 {
1564  QList<QGraphicsItem*> list = m_animationScene->items();
1565  QList<QGraphicsItem*>::iterator it;
1566 
1567  for(it = list.begin(); it != list.end(); ++it)
1568  {
1570  QString title = ai->m_title;
1571  int r = QMessageBox::question(this, "Remove Item", "Remove " + title, QMessageBox::Ok, QMessageBox::No);
1572  if(r == QMessageBox::Ok)
1573  {
1574  removeComboItem(ai);
1575  if(list.count() == 1)
1576  {
1577  onStopToolButtonnClicked();
1578  m_animationScene->removeItem(ai);
1579  m_parallelAnimation->removeAnimation(ai->m_animation);
1580  delete ai->m_animation;
1581  delete ai;
1582  m_ui->m_TemporalHorizontalSlider->setValue(0);
1583  m_parallelAnimation->setCurrentTime(0);
1584  m_ui->m_settingsToolButton->setEnabled(false);
1585  m_ui->m_playToolButton->setEnabled(false);
1586  m_ui->m_stopToolButton->setEnabled(false);
1587  m_ui->m_durationSpinBox->setEnabled(false);
1588  m_ui->m_dateTimeEdit->setEnabled(false);
1589  showPropertySection(false);
1590  m_display->update();
1591  initProperty();
1592  return;
1593  }
1594 
1595  bool running = false;
1596  int state = m_parallelAnimation->state();
1597  if(state == QAbstractAnimation::Running)
1598  {
1599  running = true;;
1600  onPlayToolButtonnClicked();
1601  }
1602 
1603  m_currentTime = m_parallelAnimation->currentTime();
1604  m_animationScene->removeItem(ai);
1605  m_parallelAnimation->removeAnimation(ai->m_animation);
1606  if(ai->pixmap().isNull() == false)
1607  {
1608  if(m_animationScene->m_numberOfTrajectories)
1609  {
1610  m_animationScene->m_trajectoryPixmap->fill(Qt::transparent);
1611  draw();
1612  }
1613  }
1614  delete ai->m_animation;
1615  delete ai;
1616 
1617  calculateSpatialExtent();
1618  calculateTemporalExtent();
1619  createAnimations();
1620  setDuration(m_duration);
1621  setDirection(m_direction);
1622 
1623  if(running)
1624  {
1625  onPlayToolButtonnClicked();
1626  m_parallelAnimation->setCurrentTime(m_currentTime);
1627  }
1628 
1629  break;
1630  }
1631  }
1632  initProperty();
1633 }
1634 
1636 {
1637  int state = m_parallelAnimation->state();
1638  if(state == QAbstractAnimation::Running)
1639  onPlayToolButtonnClicked();
1640 
1641  QList<QGraphicsItem*> list = m_animationScene->items();
1642  int i = list.indexOf(item);
1643  list.takeAt(i);
1644  list.prepend(item); // put to last item
1645 
1646  QList<QGraphicsItem*>::iterator it = list.begin();
1647  while(it != list.end())
1648  {
1650  m_animationScene->removeItem(ai);
1651  }
1652 
1653  while(list.isEmpty() == false)
1654  {
1656  m_animationScene->addItem(ai);
1657  }
1658 
1659  onPlayToolButtonnClicked();
1660 }
1661 
1663 {
1664  int state = m_parallelAnimation->state();
1665  if(state == QAbstractAnimation::Running)
1666  onPlayToolButtonnClicked();
1667 
1668  QList<QGraphicsItem*> list = m_animationScene->items();
1669  int i = list.indexOf(item);
1670  list.takeAt(i);
1671  list.append(item); // put to first item
1672 
1673  QList<QGraphicsItem*>::iterator it = list.begin();
1674  while(it != list.end())
1675  {
1677  m_animationScene->removeItem(ai);
1678  }
1679 
1680  while(list.isEmpty() == false)
1681  {
1683  m_animationScene->addItem(ai);
1684  }
1685 
1686  onPlayToolButtonnClicked();
1687 }
1688 
1690 {
1691  QList<QGraphicsItem*> list = m_animationScene->items();
1692  QList<QGraphicsItem*>::iterator it;
1693 
1694  for(it = list.begin(); it != list.end(); ++it)
1695  {
1697  QString title = ai->m_title;
1698  int r = QMessageBox::question(this, "Put To Front", "Animation Item: " + title, QMessageBox::Ok, QMessageBox::No);
1699  if(r == QMessageBox::Ok)
1700  {
1701  putToFront(ai);
1702  break;
1703  }
1704  }
1705 }
1706 
1708 {
1709  QList<QGraphicsItem*> list = m_animationScene->items();
1710  QList<QGraphicsItem*>::iterator it;
1711 
1712  for(it = list.begin(); it != list.end(); ++it)
1713  {
1715  QString title = ai->m_title;
1716  int r = QMessageBox::question(this, "Put To Back", "Animation Item: " + title, QMessageBox::Ok, QMessageBox::No);
1717  if(r == QMessageBox::Ok)
1718  {
1719  putToBack(ai);
1720  break;
1721  }
1722  }
1723 }
1724 
1725 void te::qt::widgets::TimeSliderWidget::erase(const unsigned int& curTime)
1726 {
1727  QList<QGraphicsItem*> list = m_animationScene->items();
1728  QList<QGraphicsItem*>::iterator it;
1729  for(it = list.begin(); it != list.end(); ++it)
1730  {
1732  if(ai->pixmap().isNull() == false)
1733  ((te::qt::widgets::TrajectoryItem*)ai)->m_erasePerfectly = m_erasePerfectly;
1734  }
1735 
1736  if(m_erasePerfectly)
1737  {
1738  m_parallelAnimation->setCurrentTime(curTime);
1739  draw();
1740  }
1741  else
1742  m_parallelAnimation->setCurrentTime(curTime);
1743 
1744  m_currentTime = curTime;
1745 }
1746 
1748 {
1749  if(val == m_duration)
1750  return;
1751 
1752  m_currentTime = m_parallelAnimation->currentTime();
1753  double f = double(m_currentTime) / (double)m_duration;
1754 
1755  int step = m_ui->m_durationSpinBox->singleStep();
1756  int v = val;
1757  if(v == 100)
1758  v = 0;
1759 
1760  if(v == 0 || v == m_duration + step || v == m_duration - step)
1761  {
1762  if(step == 100)
1763  {
1764  if(v < step/10)
1765  v = 100;
1766  else if(v > step*10)
1767  {
1768  step *= 10;
1769  v = m_duration + step;
1770  }
1771  }
1772  else if(step == 1000)
1773  {
1774  if(v < step/10)
1775  {
1776  step /= 10;
1777  v = m_duration - step;
1778  }
1779  else if(v > step*10)
1780  {
1781  step *= 10;
1782  v = m_duration + step;
1783  }
1784  }
1785  else if(step == 10000)
1786  {
1787  if(v < step/10)
1788  {
1789  step /= 10;
1790  v = m_duration - step;
1791  }
1792  else if(v > step*10)
1793  {
1794  step *= 10;
1795  v = m_duration + step;
1796  }
1797  }
1798  else if(step == 100000)
1799  {
1800  if(v < step/10)
1801  {
1802  step /= 10;
1803  v = m_duration - step;
1804  }
1805  else if(v > step*10)
1806  {
1807  step *= 10;
1808  v = m_duration + step;
1809  }
1810  }
1811  else if(step == 1000000)
1812  {
1813  if(v < step/10)
1814  {
1815  step /= 10;
1816  v = m_duration - step;
1817  }
1818  else if(v > step*10)
1819  {
1820  step *= 10;
1821  v = m_duration + step;
1822  }
1823  }
1824 
1825  m_duration = (v / step) * step;
1826  m_ui->m_durationSpinBox->setValue(m_duration);
1827  m_ui->m_durationSpinBox->setSingleStep(step);
1828  }
1829  else
1830  m_duration = val;
1831 
1832  bool running = false;
1833  if(m_parallelAnimation->state() == QAbstractAnimation::Running)
1834  {
1835  running = true;;
1836  onPlayToolButtonnClicked();
1837  }
1838 
1839  m_currentTime = qRound(f * (double)m_duration);
1840  m_animationScene->m_trajectoryPixmap->fill(Qt::transparent);
1841  setDuration(m_duration);
1842  m_parallelAnimation->setCurrentTime(m_currentTime);
1843  draw();
1844  if(running)
1845  onPlayToolButtonnClicked();
1846 }
1847 
1849 {
1850  if(m_ui->m_dateTimeEdit->isEnabled() == false)
1851  return;
1852 
1853  QDateTime t(qdt);
1854  int oldCurTime = m_parallelAnimation->currentTime();
1855 
1856  te::dt::TimeInstant tini = m_temporalAnimationExtent.getInitialTimeInstant();
1857  unsigned long totalSecs = m_temporalAnimationExtent.getTimePeriod().length().total_seconds();
1858 
1859  te::dt::Date date(t.date().year(), t.date().month(), t.date().day());
1860  te::dt::TimeDuration duration(t.time().hour(), t.time().minute(), t.time().second());
1861  te::dt::TimeInstant time(date, duration);
1862 
1863  te::dt::TimePeriod tp(tini, time);
1864  unsigned long secs = tp.getTimePeriod().length().total_seconds();
1865 
1866  double v = (double)secs / (double)totalSecs;
1867  int curTime = qRound(v * (double)m_parallelAnimation->duration());
1868 
1869  if(curTime == 0)
1870  curTime = 1;
1871  else if(curTime == m_parallelAnimation->duration())
1872  curTime = m_parallelAnimation->duration() - 1;
1873 
1874  bool erase = false;
1875  if(m_goAndBack == true)
1876  {
1877  if(m_comingBack == false && m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1878  erase = true;
1879  else if(m_comingBack == false && m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1880  erase = true;
1881  else if(m_comingBack == true && m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1882  erase = true;
1883  else if(m_comingBack == true && m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1884  erase = true;
1885  }
1886  else
1887  {
1888  if(m_direction == QAbstractAnimation::Forward && curTime < oldCurTime)
1889  erase = true;
1890  else if(m_direction == QAbstractAnimation::Backward && curTime > oldCurTime)
1891  erase = true;
1892  }
1893 
1894  m_currentTime = curTime;
1895  m_parallelAnimation->setCurrentTime(curTime);
1896  if(erase)
1897  this->erase(curTime);
1898 
1899  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
1900  m_display->update();
1901 }
1902 
1903 QDateTime te::qt::widgets::TimeSliderWidget::fixDateTimeEdit(QDateTimeEdit* dte, const QDateTime& qdt)
1904 {
1905  QDateTime t(qdt);
1906  QDateTimeEdit::Section section = dte->currentSection();
1907  if(section == QDateTimeEdit::SecondSection)
1908  {
1909  int sec = t.time().second();
1910  if(sec == 0)
1911  t = t.addSecs(-1);
1912  else
1913  t = t.addSecs(1);
1914  }
1915  else if(section == QDateTimeEdit::MinuteSection)
1916  {
1917  int min = t.time().minute();
1918  if(min == 0)
1919  t = t.addSecs(-60);
1920  else
1921  t = t.addSecs(60);
1922  }
1923  else if(section == QDateTimeEdit::HourSection)
1924  {
1925  int hour = t.time().hour();
1926  if(hour == 0)
1927  t = t.addSecs(-3600);
1928  else
1929  t = t.addSecs(3600);
1930  }
1931  else if(section == QDateTimeEdit::DaySection)
1932  {
1933  int day = t.date().day();
1934  if(day == 1)
1935  t = t.addDays(-1);
1936  else
1937  t = t.addDays(1);
1938  }
1939  else if(section == QDateTimeEdit::MonthSection)
1940  {
1941  int month = t.date().month();
1942  if(month == 1)
1943  t = t.addMonths(-1);
1944  else
1945  t = t.addMonths(1);
1946  }
1947 
1948  return t;
1949 }
1950 
1951 void te::qt::widgets::TimeSliderWidget::drawPixmapItem(te::qt::widgets::PixmapItem* pi, const QRectF& dwrect, QPainter* painter)
1952 {
1953  if(pi->m_currentImageFile.isEmpty())
1954  return;
1955 
1956  QRectF rec = pi->m_imaRect;
1957  if(dwrect.intersects(rec))
1958  {
1959  QRect r = pi->m_matrix.mapRect(rec).toRect();
1960  QImage* ima = getImage(pi);
1961 
1962  if(pi->m_opacity == 255)
1963  painter->drawImage(r, *ima);
1964  else
1965  {
1966  QSize size = ima->size();
1967  int width = size.width();
1968  int height = size.height();
1969 
1970  if(ima->format() == QImage::Format_ARGB32)
1971  {
1972  for(int i = 0; i < height; ++i)
1973  {
1974  unsigned char* u = ima->scanLine(i);
1975  for(int j = 0; j < width; ++j)
1976  {
1977  QRgb* v = (QRgb*)(u + (j << 2));
1978  if(qAlpha(*v) > 50)
1979  *v = qRgba(qRed(*v), qGreen(*v), qBlue(*v) , pi->m_opacity);
1980  }
1981  }
1982  painter->drawImage(r, *ima);
1983  }
1984  else
1985  {
1986  QImage img(size, QImage::Format_ARGB32);
1987  for(int i = 0; i < height; ++i)
1988  {
1989  unsigned char* u = ima->scanLine(i);
1990  unsigned char* uu = img.scanLine(i);
1991 
1992  for(int j = 0; j < width; ++j)
1993  {
1994  QRgb* v = (QRgb*)(u + (j << 2));
1995  QRgb* uv = (QRgb*)(uu + (j << 2));
1996  if(qAlpha(*v) > 50)
1997  *uv = qRgba(qRed(*v), qGreen(*v), qBlue(*v) , pi->m_opacity);
1998  }
1999  }
2000  painter->drawImage(r, img);
2001  }
2002  }
2003  delete ima;
2004  }
2005 }
2006 
2008 {
2009  if(t->m_opacity == 255)
2010  painter->drawPixmap(pos, t->pixmap());
2011  else
2012  {
2013  QSize size = t->pixmap().size();
2014  int width = size.width();
2015  int height = size.height();
2016  QImage ima = t->pixmap().toImage();
2017 
2018  if(ima.format() == QImage::Format_ARGB32)
2019  {
2020  for(int i = 0; i < height; ++i)
2021  {
2022  unsigned char* u = ima.scanLine(i);
2023  for(int j = 0; j < width; ++j)
2024  {
2025  QRgb* v = (QRgb*)(u + (j << 2));
2026  if(qAlpha(*v) < 50)
2027  *v = qRgba(255, 255, 255 , 0);
2028  else
2029  *v = qRgba(qRed(*v), qGreen(*v), qBlue(*v) , t->m_opacity);
2030  }
2031  }
2032  painter->drawImage(pos, ima);
2033  }
2034  else
2035  {
2036  QImage img(size, QImage::Format_ARGB32);
2037  for(int i = 0; i < height; ++i)
2038  {
2039  unsigned char* u = ima.scanLine(i);
2040  unsigned char* uu = img.scanLine(i);
2041 
2042  for(int j = 0; j < width; ++j)
2043  {
2044  QRgb* v = (QRgb*)(u + (j << 2));
2045  QRgb* uv = (QRgb*)(uu + (j << 2));
2046  if(qAlpha(*v) < 50)
2047  *uv = qRgba(255, 255, 255 , 0);
2048  else
2049  *uv = qRgba(qRed(*v), qGreen(*v), qBlue(*v) , t->m_opacity);
2050  }
2051  }
2052  painter->drawImage(pos, img);
2053  }
2054  }
2055 }
2056 
2058 {
2059  QString titlecb = m_ui->m_opacityComboBox->currentText();
2060 
2061  QList<QGraphicsItem*> list = m_animationScene->items();
2062  QList<QGraphicsItem*>::iterator it;
2063 
2064  for(it = list.begin(); it != list.end(); ++it)
2065  {
2067  QString title = ai->m_title;
2068  if(title.contains(titlecb))
2069  {
2070  ai->m_opacity = v;
2071  m_display->update();
2072  break;
2073  }
2074  }
2075 }
2076 
2078 {
2079  te::dt::TimeInstant ti = m_temporalAnimationExtent.getInitialTimeInstant();
2080  QDate qdatei(ti.getDate().getYear(), ti.getDate().getMonth(), ti.getDate().getDay());
2081  QTime qtimei(ti.getTime().getHours(), ti.getTime().getMinutes(), ti.getTime().getSeconds());
2082  QDateTime qdatetimei(qdatei, qtimei);
2083  m_ui->m_initialAnimationDateTimeEdit->setDateTime(qdatetimei);
2084 
2085  te::dt::TimeInstant tf = m_temporalAnimationExtent.getFinalTimeInstant();
2086  QDate qdatef(tf.getDate().getYear(), tf.getDate().getMonth(), tf.getDate().getDay());
2087  QTime qtimef(tf.getTime().getHours(), tf.getTime().getMinutes(), tf.getTime().getSeconds());
2088  QDateTime qdatetimef(qdatef, qtimef);
2089  m_ui->m_finalAnimationDateTimeEdit->setDateTime(qdatetimef);
2090 
2091  // set mimimum datetime
2092  te::dt::TimeInstant tmin = m_temporalExtent.getInitialTimeInstant();
2093  QDateTime minimum(QDate(tmin.getDate().getYear(), tmin.getDate().getMonth(), tmin.getDate().getDay()),
2094  QTime(tmin.getTime().getHours(), tmin.getTime().getMinutes(), tmin.getTime().getSeconds()));
2095  m_ui->m_initialAnimationDateTimeEdit->setMinimumDateTime(minimum);
2096 
2097  // set maximum datetime
2098  te::dt::TimeInstant tmax = m_temporalExtent.getFinalTimeInstant();
2099  QDateTime maximum(QDate(tmax.getDate().getYear(), tmax.getDate().getMonth(), tmax.getDate().getDay()),
2100  QTime(tmax.getTime().getHours(), tmax.getTime().getMinutes(), tmax.getTime().getSeconds()));
2101  m_ui->m_finalAnimationDateTimeEdit->setMaximumDateTime(maximum);
2102 
2103  if(m_direction == QAbstractAnimation::Forward)
2104  {
2105  if(m_ui->m_forwardRadioButton->isChecked() == false)
2106  m_ui->m_forwardRadioButton->toggle();
2107  }
2108 
2109  if(m_loop)
2110  m_ui->m_loopCheckBox->setChecked(true);
2111  if(m_goAndBack)
2112  m_ui->m_goAndBackCheckBox->setChecked(true);
2113 }
2114 
2115 //void te::qt::widgets::TimeSliderWidget::onOkPushButtonClicked()
2116 //{
2117 // te::dt::TimeInstant ti = getInitialTime();
2118 // te::dt::TimeInstant tf = getFinalTime();
2119 // if(ti > tf || ti == tf)
2120 // {
2121 // QMessageBox::warning(this, "Time Extent Error", "Initial time can not be larger than the end time!", QMessageBox::Ok);
2122 // return;
2123 // }
2124 //
2125 // QDateTime dt = m_ui->m_dateTimeEdit->dateTime();
2126 // te::dt::TimePeriod tp = m_temporalAnimationExtent;
2127 //
2128 // if(isSettingChanged())
2129 // {
2130 // m_currentTime = m_parallelAnimation->currentTime();
2131 // int state = m_parallelAnimation->state();
2132 // if(state == QAbstractAnimation::Running)
2133 // onPlayToolButtonnClicked();
2134 //
2135 // QAbstractAnimation::Direction direction = m_direction;
2136 //
2137 // if(m_ui->m_forwardRadioButton->isChecked())
2138 // m_direction = QAbstractAnimation::Forward;
2139 // else
2140 // m_direction = QAbstractAnimation::Backward;
2141 //
2142 // m_loop = m_ui->m_loopCheckBox->isChecked();
2143 // m_goAndBack = m_ui->m_forwardAndThenBackwardCheckBox->isChecked();
2144 //
2145 // m_temporalAnimationExtent = te::dt::TimePeriod(ti, tf);
2146 //
2147 // QDateTime minimum(QDate(ti.getDate().getYear(), ti.getDate().getMonth(), ti.getDate().getDay()),
2148 // QTime(ti.getTime().getHours(), ti.getTime().getMinutes(), ti.getTime().getSeconds()));
2149 // QDateTime maximum(QDate(tf.getDate().getYear(), tf.getDate().getMonth(), tf.getDate().getDay()),
2150 // QTime(tf.getTime().getHours(), tf.getTime().getMinutes(), tf.getTime().getSeconds()));
2151 //
2152 // m_ui->m_dateTimeEdit->setMinimumDateTime(minimum);
2153 // m_ui->m_dateTimeEdit->setMaximumDateTime(maximum);
2154 //
2155 // createNewPixmap();
2156 // calculateSpatialExtent();
2157 // createAnimations();
2158 // setDuration(m_duration);
2159 // setDirection(m_direction);
2160 //
2161 // if(state == QAbstractAnimation::Running)
2162 // {
2163 // onPlayToolButtonnClicked();
2164 // m_parallelAnimation->setCurrentTime(m_currentTime);
2165 // m_parallelAnimation->start();
2166 // }
2167 // else
2168 // {
2169 // m_parallelAnimation->setCurrentTime(m_currentTime);
2170 // m_parallelAnimation->start();
2171 // if(state == QAbstractAnimation::Paused)
2172 // m_parallelAnimation->pause();
2173 // }
2174 //
2175 // if(tp == m_temporalAnimationExtent)
2176 // onDateTimeEditChanged(dt);
2177 // }
2178 // showPropertySection(false);
2179 //}
2180 
2181 //void te::qt::widgets::TimeSliderWidget::onCancelPushButtonClicked()
2182 //{
2183 // showPropertySection(false);
2184 //}
2185 
2187 {
2188  QDateTime t = m_ui->m_initialAnimationDateTimeEdit->dateTime();
2189  te::dt::Date date(t.date().year(), t.date().month(), t.date().day());
2190  te::dt::TimeDuration duration(t.time().hour(), t.time().minute(), t.time().second());
2191  te::dt::TimeInstant time(date, duration);
2192  return time;
2193  //QString time = m_ui->m_initialTimeLineEdit->text();
2194  //QString s = simpleTimeString2IsoString(time);
2195  //if(s.isEmpty())
2196  // return te::dt::TimeInstant();
2197 
2198  //te::dt::TimeInstant t(s.toStdString());
2199  //return t;
2200 }
2201 
2203 {
2204  QDateTime t = m_ui->m_finalAnimationDateTimeEdit->dateTime();
2205  te::dt::Date date(t.date().year(), t.date().month(), t.date().day());
2206  te::dt::TimeDuration duration(t.time().hour(), t.time().minute(), t.time().second());
2207  te::dt::TimeInstant time(date, duration);
2208  return time;
2209 }
2210 
2211 //QString te::qt::widgets::TimeSliderWidget::simpleTimeString2IsoString(QString timeString)
2212 //{
2213 // QString timeIso;
2214 //
2215 // QString tt = timeString.toUpper();
2216 // tt.remove(" ");
2217 // std::string time = tt.toStdString();
2218 // if(time.size() != 19)
2219 // return timeIso;
2220 // std::string tIso = time.substr(0, 4);
2221 //
2222 // std::string s = time.substr(5, 3);
2223 // std::string mes;
2224 // if(s == "JAN")
2225 // mes = "01";
2226 // else if(s == "FEB")
2227 // mes = "02";
2228 // else if(s == "MAR")
2229 // mes = "03";
2230 // else if(s == "APR")
2231 // mes = "04";
2232 // else if(s == "MAY")
2233 // mes = "05";
2234 // else if(s == "JUN")
2235 // mes = "06";
2236 // else if(s == "JUL")
2237 // mes = "07";
2238 // else if(s == "AUG")
2239 // mes = "08";
2240 // else if(s == "SEP")
2241 // mes = "09";
2242 // else if(s == "OCT")
2243 // mes = "10";
2244 // else if(s == "NOV")
2245 // mes = "11";
2246 // else if(s == "DEC")
2247 // mes = "12";
2248 // if(mes.empty())
2249 // return timeIso;
2250 //
2251 // tIso += mes;
2252 //
2253 // tIso += time.substr(9, 2);
2254 // tIso += "T";
2255 // tIso += time.substr(11, 2);
2256 // tIso += time.substr(14, 2);
2257 // tIso += time.substr(17, 2);
2258 //
2259 // timeIso = tIso.c_str();
2260 // return timeIso;
2261 //}
2262 
2264 {
2265  te::dt::TimeInstant t = m_temporalExtent.getInitialTimeInstant();
2266  QDate qdate(t.getDate().getYear(), t.getDate().getMonth(), t.getDate().getDay());
2267  QTime qtime(t.getTime().getHours(), t.getTime().getMinutes(), t.getTime().getSeconds());
2268  QDateTime qdatetime(qdate, qtime);
2269  m_ui->m_initialAnimationDateTimeEdit->setDateTime(qdatetime);
2270 }
2271 
2273 {
2274  te::dt::TimeInstant t = m_temporalExtent.getFinalTimeInstant();
2275  QDate qdate(t.getDate().getYear(), t.getDate().getMonth(), t.getDate().getDay());
2276  QTime qtime(t.getTime().getHours(), t.getTime().getMinutes(), t.getTime().getSeconds());
2277  QDateTime qdatetime(qdate, qtime);
2278  m_ui->m_finalAnimationDateTimeEdit->setDateTime(qdatetime);
2279 }
2280 
2282 {
2283  if(b==false && m_ui->m_propertyWidget->isHidden())
2284  return;
2285  if(b==true && m_ui->m_propertyWidget->isHidden()==false)
2286  return;
2287 
2288  int h = m_ui->m_propertyWidget->height();
2289 
2290  if(b == false)
2291  {
2292  m_ui->m_propertyWidget->hide();
2293  resize(width(), height()-h);
2294  }
2295  else
2296  {
2297  m_ui->m_propertyWidget->show();
2298  resize(width(), height()+h);
2299  }
2300 }
2301 
2303 {
2304  te::dt::TimeInstant ti = m_temporalAnimationExtent.getInitialTimeInstant();
2305  QDate qdatei(ti.getDate().getYear(), ti.getDate().getMonth(), ti.getDate().getDay());
2306  QTime qtimei(ti.getTime().getHours(), ti.getTime().getMinutes(), ti.getTime().getSeconds());
2307  QDateTime qdatetimei(qdatei, qtimei);
2308  QDateTime qdi = m_ui->m_initialAnimationDateTimeEdit->dateTime();
2309  if(qdatetimei != qdi)
2310  return true;
2311 
2312  te::dt::TimeInstant tf = m_temporalAnimationExtent.getFinalTimeInstant();
2313  QDate qdatef(tf.getDate().getYear(), tf.getDate().getMonth(), tf.getDate().getDay());
2314  QTime qtimef(tf.getTime().getHours(), tf.getTime().getMinutes(), tf.getTime().getSeconds());
2315  QDateTime qdatetimef(qdatef, qtimef);
2316  QDateTime qdf = m_ui->m_finalAnimationDateTimeEdit->dateTime();
2317  if(qdatetimef != qdf)
2318  return true;
2319 
2320  if(m_ui->m_forwardRadioButton->isChecked() && m_direction != QAbstractAnimation::Forward)
2321  return true;
2322  if(m_ui->m_forwardRadioButton->isChecked() == false && m_direction != QAbstractAnimation::Backward)
2323  return true;
2324  if(m_ui->m_loopCheckBox->isChecked() != m_loop)
2325  return true;
2326  if(m_ui->m_goAndBackCheckBox->isChecked() != m_goAndBack)
2327  return true;
2328 
2329  return false;
2330 }
2331 
2333 {
2334  if(m_direction == QAbstractAnimation::Forward)
2335  {
2336  if(m_comingBack)
2337  m_comingBack = false;
2338  }
2339  else
2340  changeDirection();
2341 }
2342 
2344 {
2345  if(m_direction == QAbstractAnimation::Backward)
2346  {
2347  if(m_comingBack)
2348  m_comingBack = false;
2349  }
2350  else
2351  changeDirection();
2352 }
2353 
2355 {
2356  m_loop = b;
2357  //char buf[10];
2358  //te::dt::TimeInstant iTime = te::dt::TimeInstant(boost::posix_time::time_from_string("2008-05-01 00:00:00"));
2359  //boost::posix_time::time_duration td = boost::posix_time::seconds(3600);
2360 
2361  //QDir dir("C:/lixo/TemporalImages/TurmaDaMonicaBruxarias");
2362  //QStringList nameFilter;
2363  //nameFilter.append("TurmaDaMonicaBruxarias*");
2364  //QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
2365  //QStringList::iterator it;
2366 
2367  //for(it = files.begin(); it != files.end(); ++it)
2368  //{
2369  // QString s("C:/lixo/TemporalImages/TurmaDaMonicaBruxarias/");
2370  // QFile file(s+*it);
2371  // QString nfile = s + "TurmaDaMonicaBruxarias_";
2372 
2373  // nfile += s.setNum((short)iTime.getDate().getYear()) + "_";
2374 
2375  // sprintf(buf, "%02d_", iTime.getDate().getMonth());
2376  // buf[3] = 0;
2377  // nfile += buf;
2378 
2379  // sprintf(buf, "%02d_", iTime.getDate().getDay());
2380  // buf[3] = 0;
2381  // nfile += buf;
2382 
2383  // sprintf(buf, "%02d_", iTime.getTime().getHours());
2384  // buf[3] = 0;
2385  // nfile += buf;
2386 
2387  // sprintf(buf, "%02d_", iTime.getTime().getMinutes());
2388  // buf[3] = 0;
2389  // nfile += buf;
2390 
2391  // sprintf(buf, "%02d.jpg", iTime.getTime().getSeconds());
2392  // buf[6] = 0;
2393  // nfile += buf;
2394 
2395  // file.rename(nfile);
2396  // iTime = te::dt::TimeInstant(iTime.getTimeInstant() + td);
2397  //}
2398 }
2399 
2401 {
2402  if(m_goAndBack != b)
2403  {
2404  if(m_comingBack)
2405  {
2406  changeDirection();
2407  m_comingBack = false;
2408  }
2409  }
2410 
2411  m_goAndBack = b;
2412 }
2413 
2415 {
2416  te::dt::TimeInstant ti = getInitialTime();
2417  te::dt::TimeInstant tf = getFinalTime();
2418  if(ti > tf || ti == tf)
2419  {
2420  QMessageBox::warning(this, "Time Extent Error", "Initial time can not be larger than the end time!", QMessageBox::Ok);
2421  return;
2422  }
2423 
2424  te::dt::TimeInstant t = m_temporalAnimationExtent.getInitialTimeInstant();
2425  QDate qdatei(t.getDate().getYear(), t.getDate().getMonth(), t.getDate().getDay());
2426  QTime qtimei(t.getTime().getHours(), t.getTime().getMinutes(), t.getTime().getSeconds());
2427  QDateTime qdatetimei(qdatei, qtimei);
2428  QDateTime qdi = m_ui->m_initialAnimationDateTimeEdit->dateTime();
2429 
2430  t = m_temporalAnimationExtent.getFinalTimeInstant();
2431  QDate qdatef(t.getDate().getYear(), t.getDate().getMonth(), t.getDate().getDay());
2432  QTime qtimef(t.getTime().getHours(), t.getTime().getMinutes(), t.getTime().getSeconds());
2433  QDateTime qdatetimef(qdatef, qtimef);
2434  QDateTime qdf = m_ui->m_finalAnimationDateTimeEdit->dateTime();
2435  if(qdatetimei == qdi && qdatetimef == qdf)
2436  return;
2437 
2438  m_currentTime = m_parallelAnimation->currentTime();
2439  int state = m_parallelAnimation->state();
2440  if(state == QAbstractAnimation::Running)
2441  onPlayToolButtonnClicked();
2442 
2443  QDateTime dt = m_ui->m_dateTimeEdit->dateTime();
2444  te::dt::TimePeriod tp = m_temporalAnimationExtent;
2445 
2446  m_temporalAnimationExtent = te::dt::TimePeriod(ti, tf);
2447 
2448  QDateTime minimum(QDate(ti.getDate().getYear(), ti.getDate().getMonth(), ti.getDate().getDay()),
2449  QTime(ti.getTime().getHours(), ti.getTime().getMinutes(), ti.getTime().getSeconds()));
2450  QDateTime maximum(QDate(tf.getDate().getYear(), tf.getDate().getMonth(), tf.getDate().getDay()),
2451  QTime(tf.getTime().getHours(), tf.getTime().getMinutes(), tf.getTime().getSeconds()));
2452 
2453  m_ui->m_dateTimeEdit->setMinimumDateTime(minimum);
2454  m_ui->m_dateTimeEdit->setMaximumDateTime(maximum);
2455 
2456  createNewPixmap();
2457  calculateSpatialExtent();
2458  createAnimations();
2459  setDuration(m_duration);
2460  setDirection(m_direction);
2461 
2462  if(state == QAbstractAnimation::Running)
2463  {
2464  onPlayToolButtonnClicked();
2465  m_parallelAnimation->setCurrentTime(m_currentTime);
2466  m_parallelAnimation->start();
2467  }
2468  else
2469  {
2470  m_parallelAnimation->setCurrentTime(m_currentTime);
2471  m_parallelAnimation->start();
2472  if(state == QAbstractAnimation::Paused)
2473  m_parallelAnimation->pause();
2474  }
2475 
2476  if(tp == m_temporalAnimationExtent)
2477  onDateTimeEditChanged(dt);
2478 }
2479 
2481 {
2482  QString titlecb = m_ui->m_trajectoryColorComboBox->currentText();
2483 
2484  QList<QGraphicsItem*> list = m_animationScene->items();
2485  QList<QGraphicsItem*>::iterator it;
2487 
2488  for(it = list.begin(); it != list.end(); ++it)
2489  {
2490  ti = (te::qt::widgets::TrajectoryItem*)(*it);
2491  QString title = ti->m_title;
2492  if(title == titlecb)
2493  break;
2494  }
2495  if(ti == 0)
2496  return;
2497 
2498  m_ui->m_forwardColorPushButton->setPalette(QPalette(ti->m_forwardColor));
2499  m_ui->m_forwardColorPushButton->update();
2500  m_ui->m_backwardColorPushButton->setPalette(QPalette(ti->m_backwardColor));
2501  m_ui->m_backwardColorPushButton->update();
2502  m_ui->m_autoPanCheckBox->setChecked(ti->m_automaticPan);
2503 }
2504 
2506 {
2507  QString titlecb = m_ui->m_opacityComboBox->currentText();
2508 
2509  QList<QGraphicsItem*> list = m_animationScene->items();
2510  QList<QGraphicsItem*>::iterator it;
2511 
2512  for(it = list.begin(); it != list.end(); ++it)
2513  {
2515  QString title = ai->m_title;
2516  if(title.contains(titlecb))
2517  {
2518  int op = ai->m_opacity;
2519  m_ui->m_opacitySpinBox->setValue(op);
2520  break;
2521  }
2522  }
2523 }
2524 
2526 {
2527  QString title = ai->m_title;
2528  //if(title[title.length()-1] == ' ')
2529  // title = title.remove(title.length()-1, 1);
2530  int index = m_ui->m_opacityComboBox->findText(title);
2531  m_ui->m_opacityComboBox->removeItem(index);
2532  onOpacityComboBoxActivated(m_ui->m_opacityComboBox->currentIndex());
2533 
2534  index = m_ui->m_trajectoryColorComboBox->findText(title);
2535  m_ui->m_trajectoryColorComboBox->removeItem(index);
2536  onTrajectoryColorComboBoxActivated(m_ui->m_trajectoryColorComboBox->currentIndex());
2537 }
2538 
2540 {
2541  QString file(fileName);
2542  int ind = file.indexOf("_");
2543  if(file.indexOf("_", ind+1) != -1)
2544  ind = file.indexOf("_", ind+1);
2545  file.remove(0, ind+1);
2546  QString ano(file), mes(file), dia(file), hour(file), min(file);
2547  ano.remove(4, ano.length()-4);
2548  mes.remove(0, 4);
2549  mes.remove(2, mes.length()-2);
2550  dia.remove(0, 6);
2551  dia.remove(2, dia.length()-2);
2552  hour.remove(0, 8);
2553  hour.remove(2, hour.length()-2);
2554  min.remove(0, 10);
2555  min.remove(2, min.length()-2);
2556 
2557  te::dt::Date date(ano.toInt(), mes.toInt(), dia.toInt());
2558  te::dt::TimeDuration dur(hour.toInt(), min.toInt(), 0);
2559  return te::dt::TimeInstant(date, dur);
2560 }
2561 
2563 {
2564  if(m_animationScene->items().isEmpty())
2565  m_ui->m_durationSpinBox->setValue(m_duration);
2566 
2567  int state = m_parallelAnimation->state();
2568  m_currentTime = m_parallelAnimation->currentTime();
2569  if(state == QAbstractAnimation::Running)
2570  onPlayToolButtonnClicked();
2571 
2572  te::qt::widgets::PixmapItem* pi = getEtaMetadata("C:/lixo/FORECAST/eta5km");
2573  calculateSpatialExtent();
2574  calculateTemporalExtent();
2575  createAnimations();
2576  setDuration(m_duration);
2577  setDirection(m_direction);
2578  if(state == QAbstractAnimation::Running)
2579  {
2580  onPlayToolButtonnClicked();
2581  m_parallelAnimation->setCurrentTime(m_currentTime);
2582  }
2583  if(m_animationScene->items().isEmpty() == false)
2584  {
2585  m_ui->m_durationSpinBox->setEnabled(true);
2586  m_ui->m_settingsToolButton->setEnabled(true);
2587  m_ui->m_playToolButton->setEnabled(true);
2588  m_ui->m_stopToolButton->setEnabled(true);
2589  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
2590  m_ui->m_dateTimeEdit->setEnabled(true);
2591  else
2592  m_ui->m_dateTimeEdit->setEnabled(false);
2593  }
2594  initProperty();
2595 
2596  m_ui->m_opacityComboBox->addItem("eta5km");
2597  int count = m_ui->m_opacityComboBox->count();
2598  m_ui->m_opacityComboBox->setCurrentIndex(count-1);
2599  onOpacityComboBoxActivated(count-1);
2600 }
2601 
2603 {
2604  if(m_animationScene->items().isEmpty())
2605  m_ui->m_durationSpinBox->setValue(m_duration);
2606 
2607  int state = m_parallelAnimation->state();
2608  m_currentTime = m_parallelAnimation->currentTime();
2609  if(state == QAbstractAnimation::Running)
2610  onPlayToolButtonnClicked();
2611 
2612  te::qt::widgets::PixmapItem* pi = getHidroMetadata("C:/lixo/FORECAST/hidro");
2613  calculateSpatialExtent();
2614  calculateTemporalExtent();
2615  createAnimations();
2616  setDuration(m_duration);
2617  setDirection(m_direction);
2618  if(state == QAbstractAnimation::Running)
2619  {
2620  onPlayToolButtonnClicked();
2621  m_parallelAnimation->setCurrentTime(m_currentTime);
2622  }
2623  if(m_animationScene->items().isEmpty() == false)
2624  {
2625  m_ui->m_durationSpinBox->setEnabled(true);
2626  m_ui->m_settingsToolButton->setEnabled(true);
2627  m_ui->m_playToolButton->setEnabled(true);
2628  m_ui->m_stopToolButton->setEnabled(true);
2629  if(m_parallelAnimation->state() == QAbstractAnimation::Paused)
2630  m_ui->m_dateTimeEdit->setEnabled(true);
2631  else
2632  m_ui->m_dateTimeEdit->setEnabled(false);
2633  }
2634  initProperty();
2635 
2636  m_ui->m_opacityComboBox->addItem("hidro");
2637  int count = m_ui->m_opacityComboBox->count();
2638  m_ui->m_opacityComboBox->setCurrentIndex(count-1);
2639  onOpacityComboBoxActivated(count-1);
2640 
2641 }
2642 
2644 {
2645  QString title = m_ui->m_trajectoryColorComboBox->currentText();
2646  setAutomaticPan(title);
2647 }
2648 
2650 {
2651  char buf[2000];
2652  QString file(path + "/racc.ctl");
2653  FILE* fp = fopen(file.toStdString().c_str(), "r");
2654  if(fp == 0)
2655  return 0;
2656 
2657  fread(buf, 2000, sizeof(char), fp);
2658  fclose(fp);
2659  QString ss(QString(buf).simplified());
2660 
2661  // validation
2662  if(!(ss.contains("undef ", Qt::CaseInsensitive) && ss.contains("title", Qt::CaseInsensitive) &&
2663  ss.contains("xdef", Qt::CaseInsensitive) && ss.contains("ydef", Qt::CaseInsensitive) &&
2664  ss.contains("linear", Qt::CaseInsensitive) && ss.contains("zdef", Qt::CaseInsensitive)))
2665  return 0;
2666 
2667  QString s;
2668  QDir dir(path);
2669  te::qt::widgets::PixmapItem* pi = new PixmapItem(dir.dirName(), path, m_display);
2670 
2671  // CHUTE SRID 4326 WGS84
2672  pi->m_SRID = 4326;
2673 
2674  // get UNDEF value
2675  size_t pos = ss.indexOf("UNDEF ", Qt::CaseInsensitive) + strlen("UNDEF ");
2676  ss.remove(0, pos);
2677  pos = ss.indexOf("TITLE", Qt::CaseInsensitive);
2678  s = ss.left(pos);
2679  pi->m_undef = atoi(s.toStdString().c_str());
2680  ss.remove(0, pos);
2681 
2682  // get XDEF ulx and resX values
2683  pos = ss.indexOf("XDEF ", Qt::CaseInsensitive) + strlen("XDEF ");
2684  ss.remove(0, pos);
2685  pos = ss.indexOf(" ");
2686  s = ss.left(pos);
2687  pi->m_ncols = atoi(s.toStdString().c_str());
2688  ss.remove(0, pos);
2689 
2690  pos = ss.indexOf("LINEAR ", Qt::CaseInsensitive) + strlen("LINEAR ");
2691  ss.remove(0, pos);
2692  pos = ss.indexOf(" ");
2693  s = ss.left(pos);
2694  double llx = atof(s.toStdString().c_str()) - 360.;
2695  ss.remove(0, pos);
2696  pos = ss.indexOf("YDEF ", Qt::CaseInsensitive);
2697  s = ss.left(pos);
2698  double resX = atof(s.toStdString().c_str());
2699  ss.remove(0, pos);
2700 
2701  // get YDEF uly and resY values
2702  pos = ss.indexOf("YDEF ", Qt::CaseInsensitive) + strlen("YDEF ");
2703  ss.remove(0, pos);
2704  pos = ss.indexOf(" ");
2705  s = ss.left(pos);
2706  pi->m_nlines = atoi(s.toStdString().c_str());
2707  ss.remove(0, pos);
2708 
2709  pos = ss.indexOf("LINEAR ", Qt::CaseInsensitive) + strlen("LINEAR ");
2710  ss.remove(0, pos);
2711  pos = ss.indexOf(" ");
2712  s = ss.left(pos);
2713  double lly = atof(s.toStdString().c_str());
2714  ss.remove(0, pos);
2715  pos = ss.indexOf("ZDEF ", Qt::CaseInsensitive);
2716  s = ss.left(pos);
2717  double resY = atof(s.toStdString().c_str());
2718  ss.remove(0, pos);
2719 
2720  double w = (double)pi->m_ncols * resX;
2721  double h = (double)pi->m_nlines * resY;
2722  pi->m_imaRect = QRectF(llx, lly, w, h);
2723 
2724  return pi;
2725 }
2726 
2728 {
2729  std::vector<std::pair<int, QColor> > tab;
2730  int i = 0;
2731  tab.push_back(std::pair<int, QColor>(i+=3, QColor(2, 1, 201, 255)));
2732  tab.push_back(std::pair<int, QColor>(i+=3, QColor(1, 71, 254, 255)));
2733  tab.push_back(std::pair<int, QColor>(i+=3, QColor(3, 148, 250, 255)));
2734  tab.push_back(std::pair<int, QColor>(i+=3, QColor(5, 200, 251, 255)));
2735  tab.push_back(std::pair<int, QColor>(i+=3, QColor(2, 254, 233, 255)));
2736  tab.push_back(std::pair<int, QColor>(i+=3, QColor(1, 254, 151, 255)));
2737  tab.push_back(std::pair<int, QColor>(i+=3, QColor(2, 254, 4, 255)));
2738  tab.push_back(std::pair<int, QColor>(i+=3, QColor(99, 254, 2, 255)));
2739  tab.push_back(std::pair<int, QColor>(i+=3, QColor(200, 255, 1, 255)));
2740  tab.push_back(std::pair<int, QColor>(i+=3, QColor(237, 255, 0, 255)));
2741  tab.push_back(std::pair<int, QColor>(i+=3, QColor(251, 232, 2, 255)));
2742  tab.push_back(std::pair<int, QColor>(i+=3, QColor(254, 199, 2, 255)));
2743  tab.push_back(std::pair<int, QColor>(i+=3, QColor(252, 179, 2, 255)));
2744  tab.push_back(std::pair<int, QColor>(i+=3, QColor(254, 147, 4, 255)));
2745  tab.push_back(std::pair<int, QColor>(i+=3, QColor(253, 99, 2, 255)));
2746  tab.push_back(std::pair<int, QColor>(i+=3, QColor(254, 1, 2, 255)));
2747  tab.push_back(std::pair<int, QColor>(i+=3, QColor(254, 0, 49, 255)));
2748  tab.push_back(std::pair<int, QColor>(i+=3, QColor(255, 5, 1, 255)));
2749 
2750  pi->setLUT(tab);
2751 }
2752 
2754 {
2755  char buf[2000];
2756  QString file(path + "/Prec5km.ctl");
2757  FILE* fp = fopen(file.toStdString().c_str(), "r");
2758  if(fp == 0)
2759  return 0;
2760 
2761  fread(buf, 2000, sizeof(char), fp);
2762  fclose(fp);
2763  QString ss(QString(buf).simplified());
2764 
2765  // validation
2766  if(!(ss.contains("undef ", Qt::CaseInsensitive) && ss.contains("xdef", Qt::CaseInsensitive)
2767  && ss.contains("ydef", Qt::CaseInsensitive) && ss.contains("linear", Qt::CaseInsensitive)
2768  && ss.contains("zdef", Qt::CaseInsensitive)))
2769  return 0;
2770 
2771  QString s;
2772  QDir dir(path);
2773  te::qt::widgets::PixmapItem* pi = new PixmapItem(dir.dirName(), path, m_display);
2774 
2775  // CHUTE SRID 4326 WGS84
2776  pi->m_SRID = 4326;
2777 
2778  // get UNDEF value
2779  size_t pos = ss.indexOf("undef ", Qt::CaseInsensitive) + strlen("undef ");
2780  ss.remove(0, pos);
2781  pos = ss.indexOf("xdef", Qt::CaseInsensitive);
2782  s = ss.left(pos);
2783  pi->m_undef = atof(s.toStdString().c_str());
2784  ss.remove(0, pos);
2785 
2786  // get XDEF ulx and resX values
2787  pos = ss.indexOf("xdef ", Qt::CaseInsensitive) + strlen("xdef ");
2788  ss.remove(0, pos);
2789  pos = ss.indexOf(" ");
2790  s = ss.left(pos);
2791  pi->m_ncols = atoi(s.toStdString().c_str());
2792  ss.remove(0, pos);
2793 
2794  pos = ss.indexOf("linear ", Qt::CaseInsensitive) + strlen("linear ");
2795  ss.remove(0, pos);
2796  pos = ss.indexOf(" ");
2797  s = ss.left(pos);
2798  double llx = atof(s.toStdString().c_str());
2799  ss.remove(0, pos);
2800  pos = ss.indexOf("ydef ", Qt::CaseInsensitive);
2801  s = ss.left(pos);
2802  double resX = atof(s.toStdString().c_str());
2803  ss.remove(0, pos);
2804 
2805  // get YDEF uly and resY values
2806  pos = ss.indexOf("ydef ", Qt::CaseInsensitive) + strlen("ydef ");
2807  ss.remove(0, pos);
2808  pos = ss.indexOf(" ");
2809  s = ss.left(pos);
2810  pi->m_nlines = atoi(s.toStdString().c_str());
2811  ss.remove(0, pos);
2812 
2813  pos = ss.indexOf("linear ", Qt::CaseInsensitive) + strlen("linear ");
2814  ss.remove(0, pos);
2815  pos = ss.indexOf(" ");
2816  s = ss.left(pos);
2817  double lly = atof(s.toStdString().c_str());
2818  ss.remove(0, pos);
2819  pos = ss.indexOf("zdef ", Qt::CaseInsensitive);
2820  s = ss.left(pos);
2821  double resY = atof(s.toStdString().c_str());
2822  ss.remove(0, pos);
2823 
2824  double w = (double)pi->m_ncols * resX;
2825  double h = (double)pi->m_nlines * resY;
2826  pi->m_imaRect = QRectF(llx, lly, w, h);
2827 
2828  return pi;
2829 }
2830 
2832 {
2833  std::vector<std::pair<int, QColor> > tab;
2834  int i = 0;
2835  tab.push_back(std::pair<int, QColor>(i+=1, QColor(2, 1, 201, 255)));
2836  tab.push_back(std::pair<int, QColor>(i+=1, QColor(2, 18, 213, 255)));
2837  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 24, 220, 255)));
2838  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 36, 227, 255)));
2839  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 54, 240, 255)));
2840  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 71, 254, 255)));
2841  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 90, 252, 255)));
2842  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 106, 251, 255)));
2843  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 130, 253, 255)));
2844  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 148, 250, 255)));
2845  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 160, 250, 255)));
2846  tab.push_back(std::pair<int, QColor>(i+=1, QColor(4, 174, 250, 255)));
2847  tab.push_back(std::pair<int, QColor>(i+=1, QColor(4, 186, 250, 255)));
2848  tab.push_back(std::pair<int, QColor>(i+=1, QColor(5, 200, 251, 255)));
2849  tab.push_back(std::pair<int, QColor>(i+=1, QColor(5, 214, 246, 255)));
2850  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 227, 241, 255)));
2851  tab.push_back(std::pair<int, QColor>(i+=1, QColor(3, 240, 237, 255)));
2852  tab.push_back(std::pair<int, QColor>(i+=1, QColor(2, 254, 233, 255)));
2853  tab.push_back(std::pair<int, QColor>(i+=1, QColor(2, 254, 212, 255)));
2854  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 190, 255)));
2855  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 170, 255)));
2856  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 160, 255)));
2857  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 151, 255)));
2858  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 105, 255)));
2859  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 72, 255)));
2860  tab.push_back(std::pair<int, QColor>(i+=1, QColor(1, 254, 37, 255)));
2861  tab.push_back(std::pair<int, QColor>(i+=1, QColor(2, 254, 4, 255)));
2862  tab.push_back(std::pair<int, QColor>(i+=1, QColor(25, 254, 4, 255)));
2863  tab.push_back(std::pair<int, QColor>(i+=1, QColor(56, 254, 3, 255)));
2864  tab.push_back(std::pair<int, QColor>(i+=1, QColor(71, 254, 3, 255)));
2865  tab.push_back(std::pair<int, QColor>(i+=1, QColor(99, 254, 2, 255)));
2866  tab.push_back(std::pair<int, QColor>(i+=1, QColor(125, 254, 2, 255)));
2867  tab.push_back(std::pair<int, QColor>(i+=1, QColor(150, 254, 2, 255)));
2868  tab.push_back(std::pair<int, QColor>(i+=1, QColor(175, 254, 2, 255)));
2869  tab.push_back(std::pair<int, QColor>(i+=1, QColor(200, 255, 1, 255)));
2870  tab.push_back(std::pair<int, QColor>(i+=1, QColor(209, 255, 1, 255)));
2871  tab.push_back(std::pair<int, QColor>(i+=1, QColor(218, 255, 1, 255)));
2872  tab.push_back(std::pair<int, QColor>(i+=1, QColor(229, 255, 1, 255)));
2873  tab.push_back(std::pair<int, QColor>(i+=1, QColor(237, 255, 0, 255)));
2874  tab.push_back(std::pair<int, QColor>(i+=1, QColor(240, 248, 0, 255)));
2875  tab.push_back(std::pair<int, QColor>(i+=1, QColor(244, 241, 0, 255)));
2876  tab.push_back(std::pair<int, QColor>(i+=1, QColor(250, 237, 0, 255)));
2877  tab.push_back(std::pair<int, QColor>(i+=1, QColor(251, 232, 2, 255)));
2878  tab.push_back(std::pair<int, QColor>(i+=1, QColor(251, 226, 2, 255)));
2879  tab.push_back(std::pair<int, QColor>(i+=1, QColor(252, 215, 2, 255)));
2880  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 208, 2, 255)));
2881  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 199, 2, 255)));
2882  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 194, 2, 255)));
2883  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 190, 2, 255)));
2884  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 184, 2, 255)));
2885  tab.push_back(std::pair<int, QColor>(i+=1, QColor(252, 179, 2, 255)));
2886  tab.push_back(std::pair<int, QColor>(i+=1, QColor(252, 172, 2, 255)));
2887  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 164, 2, 255)));
2888  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 155, 2, 255)));
2889  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 147, 4, 255)));
2890  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 136, 4, 255)));
2891  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 125, 3, 255)));
2892  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 112, 3, 255)));
2893  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 99, 2, 255)));
2894  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 75, 2, 255)));
2895  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 50, 2, 255)));
2896  tab.push_back(std::pair<int, QColor>(i+=1, QColor(253, 25, 2, 255)));
2897  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 1, 2, 255)));
2898  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 1, 12, 255)));
2899  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 1, 25, 255)));
2900  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 1, 37, 255)));
2901  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 0, 49, 255)));
2902  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 2, 37, 255)));
2903  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 3, 25, 255)));
2904  tab.push_back(std::pair<int, QColor>(i+=1, QColor(254, 4, 12, 255)));
2905  tab.push_back(std::pair<int, QColor>(i+=1, QColor(255, 5, 1, 255)));
2906 
2907  pi->setLUT(tab);
2908 }
2909 
2911 {
2912  QString path = pi->m_dir.absolutePath() + "/";
2913  QString file = pi->m_currentImageFile;
2914  QFileInfo fi(file);
2915  QString baseName = fi.baseName();
2916  QImage* ima;
2917 
2918  if(pi->m_suffix == ".bin" && baseName == "racc")
2919  {
2920  size_t nchars = pi->m_ncols * 2;
2921  uchar* buf = new uchar[nchars];
2922  FILE* fp = fopen(file.toStdString().c_str(), "rb");
2923  ima = new QImage(pi->m_ncols, pi->m_nlines, QImage::Format_ARGB32);
2924  ima->fill(Qt::transparent);
2925 
2926  uchar uc[3];
2927  uc[2] = 0;
2928  for(size_t j = 0; j < pi->m_nlines; ++j)
2929  {
2930  uchar* u = ima->scanLine(j);
2931  fread(buf, nchars, sizeof(char), fp);
2932  for(size_t i = 0; i < pi->m_ncols; i++)
2933  {
2934  uc[0] = *(buf + (i<<1));
2935  uc[1] = *(buf + (1+(i<<1)));
2936  ushort b = *(ushort*)uc;
2937  if(b != pi->m_undef)
2938  {
2939  b = (b+5) / 10;
2940  QRgb* v = (QRgb*)(u + (i << 2));
2941  *v = qRgba(pi->m_lut[b].red(), pi->m_lut[b].green(), pi->m_lut[b].blue(), 255);
2942  }
2943  }
2944  }
2945  fclose(fp);
2946  delete []buf;
2947  }
2948  else if(pi->m_suffix == ".bin" && baseName.contains("Prec5km"))
2949  {
2950  QString auxFile(file);
2951  size_t pos = auxFile.indexOf(baseName);
2952  auxFile.remove(0, pos);
2953  pos = auxFile.indexOf("_");
2954  size_t pp = auxFile.indexOf(".bin");
2955  int offset = atoi(auxFile.mid(pos+1, pp-pos+1).toStdString().c_str());
2956  size_t fileSize = pi->m_nlines * pi->m_ncols * 4 + 8; // dado é float e desprepreza 4 bytes iniciais e 4 bytes finais
2957  offset *= fileSize;
2958  auxFile.remove(pos, auxFile.length()-pos);
2959  auxFile = path + auxFile + pi->m_suffix;
2960 
2961  size_t nchars = pi->m_ncols * 4;
2962  uchar* buf = new uchar[nchars];
2963  FILE* fp = fopen(auxFile.toStdString().c_str(), "rb");
2964  fseek(fp, offset, SEEK_SET);
2965  fseek(fp, 4, SEEK_CUR); // despreza 4 bytes da primeira linha
2966  ima = new QImage(pi->m_ncols, pi->m_nlines, QImage::Format_ARGB32);
2967  ima->fill(Qt::transparent);
2968 
2969  uchar uc[5];
2970  uc[4] = 0;
2971  for(size_t j = 0; j < pi->m_nlines; ++j)
2972  {
2973  uchar* u = ima->scanLine(pi->m_nlines-1-j); // origem bottom left
2974  fread(buf, nchars, sizeof(char), fp);
2975 
2976  for(size_t i = 0; i < pi->m_ncols; i++)
2977  {
2978  uc[0] = *(buf + (i<<2));
2979  uc[1] = *(buf + (1+(i<<2)));
2980  uc[2] = *(buf + (2+(i<<2)));
2981  uc[3] = *(buf + (3+(i<<2)));
2982  float b = *(float*)uc;
2983  if(b != pi->m_undef)
2984  {
2985  uchar a = (uchar) (b * 10000. + .5);
2986  QRgb* v = (QRgb*)(u + (i << 2));
2987  *v = qRgba(pi->m_lut[a].red(), pi->m_lut[a].green(), pi->m_lut[a].blue(), 255);
2988  }
2989  }
2990  }
2991  fclose(fp);
2992  delete []buf;
2993  }
2994  else
2995  ima = new QImage(file);
2996 
2997  return ima;
2998 }
2999 
3001 {
3003  QDir dir(path);
3004  QString d = dir.dirName();
3005  QStringList nameFilter;
3006  nameFilter.append("*.ctl");
3007  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
3008  QString ctlFile = files.first();
3009 
3010  if(ctlFile == "racc.ctl")
3011  pi = getHidroMetadata(path);
3012  else if(ctlFile == "Prec5km.ctl")
3013  pi = getEtaMetadata(path);
3014  else
3015  {
3016  nameFilter.clear();
3017  nameFilter.append("S11*.jpg");
3018  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
3019  if(files.empty() == false && files.first().length() == 26)
3020  pi = getGoesMetadata(path);
3021  else
3022  pi = getTemporalImageMetadata(path);
3023  }
3024 
3025  return pi;
3026 }
3027 
3029 {
3030  PixmapItem* pi = getHidroCtlParameters(path);
3031  if(pi == 0)
3032  return 0;
3033 
3034  m_animationScene->addItem(pi);
3035  Animation* animation = new Animation(pi, "pos");
3036  animation->m_spatialExtent = te::gm::Envelope(pi->m_imaRect.x(), pi->m_imaRect.y(), pi->m_imaRect.right(), pi->m_imaRect.bottom());
3037  animation->setEasingCurve(QEasingCurve::Linear);
3038  m_parallelAnimation->addAnimation(animation);
3039 
3040  QStringList nameFilter;
3041  nameFilter.append("*.bin");
3042  QDir dir(path);
3043  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
3044  size_t count = files.count();
3045 
3046  // get time extent
3047  te::dt::TimeInstant ti = getHidroTime(path + "/" + files.first());
3048  te::dt::TimeInstant tf = getHidroTime(path + "/" + files.last());
3049  animation->m_temporalExtent = te::dt::TimePeriod(ti, tf);
3050 
3051  // set data
3053  for(size_t i = 0; i < count; ++i)
3054  {
3055  QString f = files[i];
3056  t = getHidroTime(f);
3057  pi->m_time.push_back(t);
3058  pi->m_files.push_back(f);
3059  }
3060 
3062 
3063  // crie valores não repetitivos e nem muito grandes ou pequenos
3064  QPointF pos(animation->m_spatialExtent.m_llx, animation->m_spatialExtent.m_lly);
3065  double w = animation->m_spatialExtent.getWidth();
3066  double h = animation->m_spatialExtent.getHeight();
3067  double dw = w / 64;
3068  double dh = h / 64;
3069  for(size_t i = 0; i < count; ++i)
3070  {
3071  if(i & 64)
3072  pos -= QPointF(dw, dh);
3073  else
3074  pos += QPointF(dw, dh);
3075 
3076  pi->m_route->setPoint(i, pos.x(), pos.y());
3077  }
3078 
3079  setHidroLUT(pi);
3080  return pi;
3081 }
3082 
3084 {
3085  PixmapItem* pi = getEtaCtlParameters(path);
3086  if(pi == 0)
3087  return 0;
3088 
3089  m_animationScene->addItem(pi);
3090  Animation* animation = new Animation(pi, "pos");
3091  animation->m_spatialExtent = te::gm::Envelope(pi->m_imaRect.x(), pi->m_imaRect.y(), pi->m_imaRect.right(), pi->m_imaRect.bottom());
3092  animation->setEasingCurve(QEasingCurve::Linear);
3093  m_parallelAnimation->addAnimation(animation);
3094 
3095  QStringList nameFilter;
3096  nameFilter.append("*.bin");
3097  QDir dir(path);
3098  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
3099  size_t count = files.count();
3100 
3101  // get time extent
3102  te::dt::TimeInstant ti = getEtaTime(path + "/" + files.first());
3103  te::dt::TimeInstant tf = getEtaTime(path + "/" + files.last());
3104  // the file contains 3 days of data
3105  tf = te::dt::TimeInstant(tf.getTimeInstant() + boost::posix_time::seconds(60*60*24*3 - 3600));
3106  animation->m_temporalExtent = te::dt::TimePeriod(ti, tf);
3107 
3108  // set data
3109  te::dt::TimeInstant tnext, t;
3110  QString sn, fname;
3111  for(size_t i = 0; i < count; ++i)
3112  {
3113  QString f = files[i];
3114  QFileInfo fi(path + "/" + f);
3115  QString baseName = fi.baseName();
3116  t = getEtaTime(f);
3117 
3118  if(i != count-1)
3119  tnext = getEtaTime(files[i+1]);
3120  else
3121  tnext = te::dt::TimeInstant(t.getTimeInstant() + boost::posix_time::seconds(60*60*24*3));
3122 
3123  size_t n = 1;
3124  while((t < tnext || t == tnext) && n <= 72)
3125  {
3126  pi->m_time.push_back(t);
3127  t = te::dt::TimeInstant(t.getTimeInstant() + boost::posix_time::seconds(60*60));
3128  sn.setNum(n++);
3129  fname = path + "/" + baseName + "_" + sn + "." + fi.suffix();
3130  pi->m_files.push_back(fname);
3131  }
3132  }
3133 
3134  size_t tsize = pi->m_files.count();
3136 
3137  // crie valores não repetitivos e nem muito grandes ou pequenos
3138  QPointF pos(animation->m_spatialExtent.m_llx, animation->m_spatialExtent.m_lly);
3139  double w = animation->m_spatialExtent.getWidth();
3140  double h = animation->m_spatialExtent.getHeight();
3141  double dw = w / 64;
3142  double dh = h / 64;
3143  for(size_t i = 0; i < tsize; ++i)
3144  {
3145  if(i & 64)
3146  pos -= QPointF(dw, dh);
3147  else
3148  pos += QPointF(dw, dh);
3149 
3150  pi->m_route->setPoint(i, pos.x(), pos.y());
3151  }
3152 
3153  setEtaLUT(pi);
3154  return pi;
3155 }
3156 
3158 {
3159  QString file(fileName);
3160  int ind = file.indexOf("racc.") + strlen("racc.");
3161  file.remove(0, ind);
3162  QString ano = "20" + file.mid(0, 2);
3163  QString mes = file.mid(2, 2);
3164  QString dia = file.mid(4, 2);
3165  QString hour = file.mid(7, 2);
3166  QString min = file.mid(9, 2);
3167 
3168  te::dt::Date date(ano.toInt(), mes.toInt(), dia.toInt());
3169  te::dt::TimeDuration dur(hour.toInt(), min.toInt(), 0);
3170  return te::dt::TimeInstant(date, dur);
3171 }
3172 
3174 {
3175  QString file(fileName);
3176  int ind = file.indexOf("Prec5km") + strlen("Prec5km");
3177  file.remove(0, ind);
3178  QString ano = file.mid(0, 4);
3179  QString mes = file.mid(4, 2);
3180  QString dia = file.mid(6, 2);
3181  QString hour = file.mid(8, 2);
3182 
3183  te::dt::Date date(ano.toInt(), mes.toInt(), dia.toInt());
3184  te::dt::TimeDuration dur(hour.toInt() + 1, 0, 0); // tem deslocamento de 1 hora
3185  return te::dt::TimeInstant(date, dur);
3186 }
3187 
3189 {
3190  PixmapItem* pi = getTemporalImageCtlParameters(path);
3191  if(pi == 0)
3192  return 0;
3193 
3194  m_animationScene->addItem(pi);
3195  Animation* animation = new Animation(pi, "pos");
3196  animation->m_spatialExtent = te::gm::Envelope(pi->m_imaRect.x(), pi->m_imaRect.y(), pi->m_imaRect.right(), pi->m_imaRect.bottom());
3197  animation->setEasingCurve(QEasingCurve::Linear);
3198  m_parallelAnimation->addAnimation(animation);
3199 
3200  QString suffix = "." + pi->m_suffix;
3201  QStringList nameFilter;
3202  nameFilter.append("*" + suffix);
3203  QDir dir(path);
3204  QStringList files = dir.entryList(nameFilter, QDir::Files, QDir::Name);
3205  size_t count = files.count();
3206 
3207  // get time extent
3208  te::dt::TimeInstant ti = getTemporalImageTime(path + "/" + files.first());
3209  te::dt::TimeInstant tf = getTemporalImageTime(path + "/" + files.last());
3210  animation->m_temporalExtent = te::dt::TimePeriod(ti, tf);
3211 
3212  // set data
3214  for(size_t i = 0; i < count; ++i)
3215  {
3216  QString f = files[i];
3217  pi->m_files.push_back(f);
3218  t = getTemporalImageTime(f);
3219  pi->m_time.push_back(t);
3220  }
3221 
3223 
3224  // crie valores não repetitivos e nem muito grandes ou pequenos
3225  QPointF pos(animation->m_spatialExtent.m_llx, animation->m_spatialExtent.m_lly);
3226  double w = animation->m_spatialExtent.getWidth();
3227  double h = animation->m_spatialExtent.getHeight();
3228  for(size_t i = 0; i < count; ++i)
3229  {
3230  if(i & 1)
3231  pos -= QPointF(w, h);
3232  else
3233  pos += QPointF(w, h);
3234 
3235  pi->m_route->setPoint(i, pos.x(), pos.y());
3236  }
3237  return pi;
3238 }
3239 
3241 {
3242  char buf[2000];
3243  QString file(path + "/image.ctl");
3244  FILE* fp = fopen(file.toStdString().c_str(), "r");
3245  if(fp == 0)
3246  return 0;
3247 
3248  fread(buf, 2000, sizeof(char), fp);
3249  fclose(fp);
3250  QString ss(QString(buf).simplified());
3251 
3252  // validation
3253  if(!(ss.contains("suffix ", Qt::CaseInsensitive) && ss.contains("undef", Qt::CaseInsensitive) &&
3254  ss.contains("srid", Qt::CaseInsensitive) && ss.contains("llx", Qt::CaseInsensitive) &&
3255  ss.contains("lly", Qt::CaseInsensitive) && ss.contains("urx", Qt::CaseInsensitive) &&
3256  ss.contains("ury", Qt::CaseInsensitive)))
3257  return 0;
3258 
3259  QString s;
3260  QDir dir(path);
3261  te::qt::widgets::PixmapItem* pi = new PixmapItem(dir.dirName(), path, m_display);
3262 
3263  // get suffix
3264  size_t pos = ss.indexOf("suffix ", Qt::CaseInsensitive) + strlen("suffix ");
3265  ss.remove(0, pos);
3266  pos = ss.indexOf(" undef", Qt::CaseInsensitive);
3267  s = ss.left(pos);
3268  pi->m_suffix = s;
3269  ss.remove(0, pos);
3270 
3271  // get undef
3272  pos = ss.indexOf("undef ", Qt::CaseInsensitive) + strlen("undef ");
3273  ss.remove(0, pos);
3274  pos = ss.indexOf(" srid", Qt::CaseInsensitive);
3275  s = ss.left(pos);
3276  pi->m_undef = atof(s.toStdString().c_str());
3277  ss.remove(0, pos);
3278 
3279  // get srid
3280  pos = ss.indexOf("srid ", Qt::CaseInsensitive) + strlen("srid ");
3281  ss.remove(0, pos);
3282  pos = ss.indexOf(" llx", Qt::CaseInsensitive);
3283  s = ss.left(pos);
3284  pi->m_SRID = atoi(s.toStdString().c_str());
3285  ss.remove(0, pos);
3286 
3287  // get llx
3288  pos = ss.indexOf("llx ", Qt::CaseInsensitive) + strlen("llx ");
3289  ss.remove(0, pos);
3290  pos = ss.indexOf(" lly", Qt::CaseInsensitive);
3291  s = ss.left(pos);
3292  double llx = atof(s.toStdString().c_str());
3293  ss.remove(0, pos);
3294 
3295  // get lly
3296  pos = ss.indexOf("lly ", Qt::CaseInsensitive) + strlen("lly ");
3297  ss.remove(0, pos);
3298  pos = ss.indexOf(" urx", Qt::CaseInsensitive);
3299  s = ss.left(pos);
3300  double lly = atof(s.toStdString().c_str());
3301  ss.remove(0, pos);
3302 
3303  // get urx
3304  pos = ss.indexOf("urx ", Qt::CaseInsensitive) + strlen("urx ");
3305  ss.remove(0, pos);
3306  pos = ss.indexOf(" ury", Qt::CaseInsensitive);
3307  s = ss.left(pos);
3308  double urx = atof(s.toStdString().c_str());
3309  ss.remove(0, pos);
3310 
3311  // get ury
3312  pos = ss.indexOf("ury ", Qt::CaseInsensitive) + strlen("ury ");
3313  ss.remove(0, pos);
3314  double ury = atof(ss.toStdString().c_str());
3315 
3316  double w = urx - llx;
3317  double h = ury - lly;
3318  pi->m_imaRect = QRectF(llx, lly, w, h);
3319 
3320  return pi;
3321 }
3322 
3324 {
3325  QString file(fileName);
3326  int ind = file.indexOf("_") + strlen("_");
3327  file.remove(0, ind);
3328  QString ano = file.mid(0, 4);
3329  QString mes = file.mid(5, 2);
3330  QString dia = file.mid(8, 2);
3331  QString hour = file.mid(11, 2);
3332  QString min = file.mid(14, 2);
3333  QString sec = file.mid(17, 2);
3334 
3335  te::dt::Date date(ano.toInt(), mes.toInt(), dia.toInt());
3336  te::dt::TimeDuration dur(hour.toInt(), min.toInt(), sec.toInt());
3337  return te::dt::TimeInstant(date, dur);
3338 }
void addTemporalImages(const QString &filePath)
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Definition: Utils.cpp:259
te::qt::widgets::PixmapItem * getMetadata(const QString &path)
void onResetFinalTimePushButtonClicked()
Reset final time button clicked.
void onTrajectoryColorComboBoxActivated(int i)
Trajectory color combo box activated.
QParallelAnimationGroup * m_parallelAnimation
The parallel animation.
te::qt::widgets::PixmapItem * getEtaCtlParameters(const QString &path)
void onFinishAnimation()
It takes the necessary measures after the end of the trajectory.
std::auto_ptr< Ui::TimeSliderWidgetForm > m_ui
The widget form.
const std::string & getDataSetName() const
void onBackwardRadioButtonClicked(bool b)
Backward radio button clicked.
bool alreadyExists(QPair< QString, QString > &item)
void onDurationValueChanged(int v)
It takes the necessary steps after changing the duration.
void onDateTimeEditChanged(const QDateTime &t)
It takes the necessary steps after changing the current time of animation.
void onOpacityValueChanged(int v)
It takes the necessary steps after changing the duration.
void createAnimations()
Create animations.
void onSettingsToolButtonnClicked()
it opens the configuration window animation.
void draw()
Set transformation matrix and draw current animation.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
int getAnimationTime(const te::dt::TimeInstant &tinstant)
It it gets the animation time on a time instant. /param tinstant The time instant.
void setConnInfo(const std::map< std::string, std::string > &conninfo)
QVector< QString > m_files
The input files.
Definition: PixmapItem.h:140
void drawTrajectoryIcon(const TrajectoryItem *t, const QPoint &pos, QPainter *painter)
Draw the trajectory icon.
std::complex< double > times(std::complex< double > lhs, std::complex< double > rhs)
Definition: Band.cpp:522
void onApplyTimeIntervalPushButtonClicked(bool b)
Apply time interval push button clicked.
void onResetInitialTimePushButtonClicked()
Reset initial time button clicked.
QIcon getImage(int type)
QDir m_dir
The image data directory.
Definition: PixmapItem.h:136
QAbstractAnimation::Direction m_direction
QAbstractAnimation::Forward or QAbstractAnimation::Backward.
long getSeconds() const
It returns the seconds of a minute - from 0 to 59.
Definition: TimeDuration.h:105
te::dt::TimeInstant getEtaTime(const QString &file)
void addTrajectory(const QString &title, const QString &pixmapFile, te::st::TrajectoryDataSet *dset)
Add trajectory to animation scene.
size_t m_ncols
number of colunms.
Definition: PixmapItem.h:138
te::gm::Envelope m_spatialExtent
Spatial extent.
Definition: Animation.h:99
te::dt::TimeInstant getFinalTime()
It gets the final time.
boost::gregorian::greg_year getYear() const
It returns the gregorian year.
Definition: Date.h:111
This class is a dialog for the Trajectory Icon Item.
The class that represents an item in a LayerTreeModel.
void setLUT(const std::vector< std::pair< int, QColor > > &tab)
Sets the LUT. tab The LUT information.
Definition: PixmapItem.cpp:142
bool m_automaticPan
True if automatic pan over this item.
QGraphicsView * m_animationView
The animation graphics view.
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
void calculateSpatialExtent()
It calculates the spatial extent.
const std::map< std::string, std::string > & getConnInfo() const
boost::gregorian::greg_day getDay() const
It returns the gregorian day - from 1 to 31.
Definition: Date.h:97
int m_maxSliderValue
The max slider value.
QDateTime fixDateTimeEdit(QDateTimeEdit *dte, const QDateTime &t)
It corrects the edited date time.
A widget to control the display of a set of layers.
Definition: MapDisplay.h:65
void deleteMe()
It emits, indirectly, a sign for this widget is destroyed.
void onLoopCheckBoxClicked(bool b)
Loop check box clicked.
void onOpacityComboBoxActivated(int i)
Opacity combo box activated.
void onGoAndBackCheckBoxClicked(bool b)
Forward and then backward check box clicked.
const boost::posix_time::ptime & getTimeInstant() const
It returns the boost time instant type.
Definition: TimeInstant.h:92
void onExtentChanged()
It takes the necessary measures after the change of extent.
te::dt::TimeInstant getInitialTime()
It gets the initial time.
te::qt::widgets::PixmapItem * getTemporalImageMetadata(const QString &path)
A class to represent time instant.
Definition: TimeInstant.h:55
void setDirection(const QAbstractAnimation::Direction &direction)
Sets the animation direction.
QColor m_backwardColor
The backward trail color.
Animation * m_animation
The animation this item.
virtual te::map::AbstractLayerPtr getLayer() const =0
This file contains include headers for the TerraLib ST memory module.
void setType(const std::string &dsType)
void createAnimationDataInDisplayProjection(const te::dt::TimePeriod &period)
It creates animation data for a given period; /param period The temporal period.
Definition: Animation.cpp:15
te::qt::widgets::PixmapItem * getTemporalImageCtlParameters(const QString &path)
static void initialize()
It returns the spatial extent of the observations of a coverage series.
te::qt::widgets::PixmapItem * getEtaMetadata(const QString &path)
void updateTimeTextEdit()
Update animation time.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
void drawPixmapItem(PixmapItem *pi, const QRectF &dwrect, QPainter *painter)
Draw the pixmap item.
float m_undef
undef value.
Definition: PixmapItem.h:139
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
TimeSliderWidget(MapDisplay *d, QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
Date getDate() const
It returns the date associated to time instant.
Definition: TimeInstant.h:106
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
A point with x and y coordinate values.
Definition: Point.h:50
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:352
te::dt::TimeInstant getHidroTime(const QString &file)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
te::qt::widgets::PixmapItem * getGoesMetadata(const QString &path)
const std::string & getDataSourceId() const
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
A base class for date data types.
Definition: Date.h:53
std::auto_ptr< te::dt::DateTime > getTime() const
It returns the time pointed by the internal cursor.
TimeInstant getFinalTimeInstant() const
It gets the final time instant.
Definition: TimePeriod.cpp:50
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
Definition: MapDisplay.cpp:73
This file contains include headers for the TerraLib Qt widgets.
bool eventFilter(QObject *, QEvent *)
It converts simple time string to iso time string.
void setHidroLUT(te::qt::widgets::PixmapItem *pi)
TimeInstant getInitialTimeInstant() const
It gets the initial time instant.
Definition: TimePeriod.cpp:45
void onSliderMoved(int value)
It takes the necessary measures after slider move.
QColor m_forwardColor
The forward trail color.
void openTrajectory(const QString file, const QString &leao)
An object that when created shows a cursor during its scope.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
Definition: MapDisplay.cpp:63
void erase(const unsigned int &curTime)
It Erase trajectory piece.
MapDisplay * m_display
The map display.
void onDisplayPaintEvent(QPainter *)
it draw on display.
void onForwardRadioButtonClicked(bool b)
Ok button clicked.
void setId(const std::string &id)
void onSridChanged()
It takes the necessary measures after the change of extent.
QString m_currentImageFile
Image to be displayed on paint event animation.
Definition: PixmapItem.h:142
QRectF m_imaRect
Image location.
Definition: PixmapItem.h:145
void updateSliderPos()
Updates the position of the slider with respect to time animation.
QString m_title
The icon item title.
void putToBack(AnimationItem *item)
It puts graphic item to back.
te::dt::TimeInstant getTemporalImageTime(const QString &file)
std::auto_ptr< te::gm::Geometry > getGeometry() const
te::dt::TimeInstant getGoesTime(const QString &file)
void setDirection(const QAbstractAnimation::Direction &direction)
Sets the Animation Item direction.
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
A class that contains infos about a DataSet that contains observations of one or more trajectories...
A class to represent a trajectory data set.
const std::string & getId() const
A class to represent time period.
Definition: TimePeriod.h:54
QPoint getPosInDeviceCoordinate()
It returns the Animation Item position in device coordinate.
AnimationScene * m_animationScene
The animation scene.
std::map< uchar, QColor > m_lut
LUT.
Definition: PixmapItem.h:146
bool isSettingChanged()
Is Setting Changed.
void setAutomaticPan(const QString &title)
It configures automatic pan over a animation path. It toggles auto pan state.
te::dt::TimeInstant getTimeInstant()
It it gets the animation time instant.
QImage * getImage(te::qt::widgets::PixmapItem *pi)
void setDuration(const unsigned int &duration)
Sets the animation duration.
const boost::posix_time::time_period & getTimePeriod() const
Assignment operator.
Definition: TimePeriod.h:86
te::qt::widgets::PixmapItem * getHidroCtlParameters(const QString &path)
bool m_loop
This property holds whether the slider's animation is on loop.
te::dt::TimePeriod m_temporalExtent
Total temporal extent.
Definition: Animation.h:100
void changeDirection()
Change direction.
void setEtaLUT(te::qt::widgets::PixmapItem *pi)
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
TimeDuration getTime() const
It returns the time duration associated to time instant.
Definition: TimeInstant.cpp:49
This class is a dialog for the Pixmap Item.
Definition: AnimationItem.h:57
const std::string & getType() const
QVector< te::dt::TimeInstant > m_animationTime
The animation time. It contains only the portions to be animated.
A class that represents a data source component.
This file contains include headers for the TerraLib ST module.
DateTimeType
The subtype of date and time type.
Definition: Enums.h:38
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
Definition: LineString.cpp:338
const te::gm::Envelope & getSpatialExtent() const
It returns the spatial extent of the trajectory observations.
QString m_suffix
File suffix.
Definition: PixmapItem.h:144
void createNewPixmap()
create new pixmap.
void initProperty()
It initialize a property animation dialog.
This class is a dialog for the Animation.
void putToFront(AnimationItem *item)
It puts graphic item to front.
te::qt::widgets::PixmapItem * getHidroMetadata(const QString &path)
static std::auto_ptr< ObservationDataSet > getDataSet(const ObservationDataSetInfo &info, te::common::TraverseType travType=te::common::FORWARDONLY)
It returns a ObservationDataSet, that is, a DataSet that contains observations.
long getMinutes() const
It returns the minutes of a hour - from 0 to 59.
Definition: TimeDuration.h:98
This file contains include headers for the Data Access module of TerraLib.
void showPropertySection(bool b)
Show Property.
void onPlayToolButtonnClicked()
Play or pause the animation.
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
Definition: MapDisplay.cpp:215
te::gm::LineString * m_route
The input path in world coordenates.
This file contains include headers for the Map Tools module of TerraLib.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QMatrix m_matrix
The display transformation matrix.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
Definition: Envelope.cpp:90
void removeComboItem(te::qt::widgets::AnimationItem *ai)
Remove animation item from the opacity combo box and trajectory color combo box.
void setDuration(const unsigned int &duration)
Sets the Animation Item duration.
std::size_t size() const
It returns the size of the trajectory observation set.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
Definition: MapDisplay.cpp:154
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
int m_SRID
The input route srid.
boost::gregorian::greg_month getMonth() const
It returns the gregorian month - from 1 to 12.
Definition: Date.h:104
void calculateTemporalExtent()
It calculates the temporal extent.
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438
size_t m_nlines
number of lines.
Definition: PixmapItem.h:137
te::dt::TimePeriod m_temporalAnimationExtent
Temporal animation extent. It can be a portion of the total or greater than the total.
Definition: Animation.h:101
long getHours() const
It returns the hours of a day - from 0 to 23.
Definition: TimeDuration.h:91
te::dt::DateTimePeriod * getTemporalExtent() const
It returns the temporal extent of the trajectory observations.
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
void dragEnterEvent(QDragEnterEvent *)
static void finalize()
It finalize the STDataLoader.
QVector< te::dt::TimeInstant > m_time
The input time.
void onStopToolButtonnClicked()
Stop animation.
int m_duration
The animation's duration time in miliseconds.
void setGoAndBack(bool t)
Sets the mode of animation.