TimeSeriesWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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/st/ TimeSeriesWizard.cpp
22 
23  \brief A wizard used to generate a new TimeSerieslayer.
24 */
25 
26 //Terralib
27 #include "../../../geometry/GeometryProperty.h"
28 #include "../../../qt/widgets/dataset/selector/DataSetSelectorWizardPage.h"
29 #include "../../../qt/widgets/datasource/selector/DataSourceSelectorWidget.h"
30 #include "../../../qt/widgets/datasource/selector/DataSourceSelectorWizardPage.h"
31 #include "../../../qt/widgets/help/HelpPushButton.h"
32 #include "../../../se/Utils.h"
33 #include "../../../st/core/timeseries/TimeSeriesDataSetInfo.h"
35 #include "TimeSeriesWizard.h"
36 #include "ui_TimeSeriesWizardForm.h"
37 
38 //Boost
39 #include <boost/uuid/random_generator.hpp>
40 #include <boost/uuid/uuid_io.hpp>
41 
42 //STL
43 #include <iostream>
44 
46 {
47  static boost::uuids::basic_random_generator<boost::mt19937> gen;
48  boost::uuids::uuid u = gen();
49  std::string id = boost::uuids::to_string(u);
50  std::string title = dataType->getTitle().empty() ? dataType->getName() : dataType->getTitle();
51 
52  te::st::TimeSeriesDataSetLayerPtr timeSeriesLayer = new te::st::TimeSeriesDataSetLayer(id, title, parent, timeSeriesInfo);
53  timeSeriesLayer->setVisibility(te::map::NOT_VISIBLE);
54  timeSeriesLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
55 
57  std::unique_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataType->getName(), gp->getName(), dataInfo->getId()));
58  timeSeriesLayer->setSRID(gp->getSRID());
59  timeSeriesLayer->setExtent(*mbr);
60  timeSeriesLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
61  return timeSeriesLayer;
62 }
63 
65  : QWizard(parent, f),
66  m_ui(new Ui::TimeSeriesWizardForm)
67 {
68 // setup controls
69  m_ui->setupUi(this);
70 
71  // add pages
72 
73  //DataSource
75  m_datasourceSelectorPage->setTitle(tr("Data Source Selection"));
76  m_datasourceSelectorPage->setSubTitle(tr("Please, select the data source where the data is stored"));
77  m_datasourceSelectorPage->getSelectorWidget()->setSelectionMode(QAbstractItemView::SingleSelection);
78  m_datasourceSelectorPage->getSelectorWidget()->showDataSourceWithRasterSupport(false);
80 
81  //DataSet
83  m_datasetSelectorPage->setTitle(tr("Dataset Selection"));
84  m_datasetSelectorPage->setSubTitle(tr("Please, select the datasets you want to transfer to another data source"));
86 
87  // TimeSeries Properties
90 
91  // connect signals and slots
92  connect(this->button(QWizard::NextButton), SIGNAL(pressed()), this, SLOT(next()));
93  connect(this->button(QWizard::BackButton), SIGNAL(pressed()), this, SLOT(back()));
94  connect(this->button(QWizard::FinishButton), SIGNAL(pressed()), this, SLOT(finish()));
95 
97  this->setButton(QWizard::HelpButton, helpButton);
98  //helpButton->setPageReference("widgets/exchanger_all/exchanger_all.html");
99 }
100 
102 
104 {
105  std::list<te::da::DataSourceInfoPtr> datasources = m_datasourceSelectorPage->getSelectorWidget()->getSelecteds();
106 
107  if(datasources.empty())
108  return te::da::DataSourceInfoPtr();
109  else
110  return datasources.front();
111 }
112 
114 {
115  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
116 
117  if(dataTypes.empty())
118  return te::da::DataSetTypePtr();
119  else
120  return dataTypes.front();
121 }
122 
124 {
125  return m_timeSeriesLayer;
126 }
127 
129 {
130  QWizard::back();
131 }
132 
134 {
135  if(currentId() == PAGE_DATASOURCE_SELECTION)
136  {
137  m_datasetSelectorPage->set(getDataSource(), true);
138  }
139  else if (currentId() == PAGE_DATASET_SELECTION)
140  {
142  }
143  QWizard::next();
144 }
145 
147 {
148  QApplication::setOverrideCursor(Qt::WaitCursor);
150  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
151  try
152  {
153  te::st::TimeSeriesDataSetInfo* info = m_PropWidgetPage->getInfo(dataInfo);
154  m_timeSeriesLayer = generateLayer(dataTypes.front(), info, dataInfo);
155 
156  }
157  catch(const te::common::Exception& e)
158  {
159  std::cout << std::endl << "Failed to create a new layer and insert it into the application: " << e.what() << std::endl;
160  QWizard::finished(1);
161  }
162  catch(...)
163  {
164  std::cout << std::endl << "Failed to create a new layer and insert it into the application: unknown exception!" << std::endl;
165  QWizard::finished(1);
166  }
167 
168  QApplication::restoreOverrideCursor();
169  QWizard::finished(0);
170 }
te::da::DataSourceInfoPtr getDataSource() const
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
A layer with reference to a dataset that contains trajectories.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
This is the base class for layers.
Definition: AbstractLayer.h:77
std::unique_ptr< TimeSeriesPropertiesWizardPage > m_PropWidgetPage
The widget used to configure the properties of the new TimeSeriesLayer.
virtual const char * what() const
It outputs the exception message.
std::unique_ptr< Ui::TimeSeriesWizardForm > m_ui
The wizard&#39;s form.
te::st::TimeSeriesDataSetLayerPtr generateLayer(te::da::DataSetTypePtr dataType, te::st::TimeSeriesDataSetInfo *timeSeriesInfo, te::da::DataSourceInfoPtr dataInfo, te::map::AbstractLayer *parent=nullptr)
std::unique_ptr< DataSourceSelectorWizardPage > m_datasourceSelectorPage
The wizard page used to select the datasource.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
te::st::TimeSeriesDataSetLayerPtr getTimeSeriesLayer()
TimeSeriesWizard(QWidget *parent=0, Qt::WindowFlags f=0)
te::st::TimeSeriesDataSetLayerPtr m_timeSeriesLayer
The new Trajectory Layer(s);.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A WizardPage used to configure the general properties of a new spatio-temporal layer.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
A class that contains infos about a DataSet that contains observations of one or more time series...
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< TimeSeriesDataSetLayer > TimeSeriesDataSetLayerPtr
std::unique_ptr< DataSetSelectorWizardPage > m_datasetSelectorPage
The wizard page used to select the dataset.
te::da::DataSetTypePtr getDatasetType() const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127