All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
43 {
44  static boost::uuids::basic_random_generator<boost::mt19937> gen;
45  boost::uuids::uuid u = gen();
46  std::string id = boost::uuids::to_string(u);
47  std::string title = dataType->getTitle().empty() ? dataType->getName() : dataType->getTitle();
48 
49  te::st::TimeSeriesDataSetLayerPtr timeSeriesLayer = new te::st::TimeSeriesDataSetLayer(id, title, parent, timeSeriesInfo);
50  timeSeriesLayer->setVisibility(te::map::NOT_VISIBLE);
51  timeSeriesLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
52 
54  std::auto_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataType->getName(), gp->getName(), dataInfo->getId()));
55  timeSeriesLayer->setSRID(gp->getSRID());
56  timeSeriesLayer->setExtent(*mbr);
57  timeSeriesLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
58  return timeSeriesLayer;
59 }
60 
61 te::qt::widgets::TimeSeriesWizard::TimeSeriesWizard(QWidget* parent, Qt::WindowFlags f)
62  : QWizard(parent, f),
63  m_ui(new Ui::TimeSeriesWizardForm)
64 {
65 // setup controls
66  m_ui->setupUi(this);
67 
68  // add pages
69 
70  //DataSource
72  m_datasourceSelectorPage->setTitle(tr("Data Source Selection"));
73  m_datasourceSelectorPage->setSubTitle(tr("Please, select the data source where the data is stored"));
74  m_datasourceSelectorPage->getSelectorWidget()->setSelectionMode(QAbstractItemView::SingleSelection);
75  m_datasourceSelectorPage->getSelectorWidget()->showDataSourceWithRasterSupport(false);
77 
78  //DataSet
80  m_datasetSelectorPage->setTitle(tr("Dataset Selection"));
81  m_datasetSelectorPage->setSubTitle(tr("Please, select the datasets you want to transfer to another data source"));
83 
84  // TimeSeries Properties
87 
88  // connect signals and slots
89  connect(this->button(QWizard::NextButton), SIGNAL(pressed()), this, SLOT(next()));
90  connect(this->button(QWizard::BackButton), SIGNAL(pressed()), this, SLOT(back()));
91  connect(this->button(QWizard::FinishButton), SIGNAL(pressed()), this, SLOT(finish()));
92 
94  this->setButton(QWizard::HelpButton, helpButton);
95  //helpButton->setPageReference("widgets/exchanger_all/exchanger_all.html");
96 }
97 
99 {
100 }
101 
103 {
104  std::list<te::da::DataSourceInfoPtr> datasources = m_datasourceSelectorPage->getSelectorWidget()->getSelecteds();
105 
106  if(datasources.empty())
107  return te::da::DataSourceInfoPtr();
108  else
109  return datasources.front();
110 }
111 
113 {
114  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
115 
116  if(dataTypes.empty())
117  return te::da::DataSetTypePtr();
118  else
119  return dataTypes.front();
120 }
121 
123 {
124  return m_timeSeriesLayer;
125 }
126 
128 {
129  QWizard::back();
130 }
131 
133 {
134  if(currentId() == PAGE_DATASOURCE_SELECTION)
135  {
136  m_datasetSelectorPage->set(getDataSource(), true);
137  }
138  else if (currentId() == PAGE_DATASET_SELECTION)
139  {
140  m_PropWidgetPage->set(getDatasetType());
141  }
142  QWizard::next();
143 }
144 
146 {
147  QApplication::setOverrideCursor(Qt::WaitCursor);
148  te::da::DataSourceInfoPtr dataInfo = getDataSource();
149  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
150  try
151  {
152  te::st::TimeSeriesDataSetInfo* info = m_PropWidgetPage->getInfo(dataInfo);
153  m_timeSeriesLayer = generateLayer(dataTypes.front(), info, dataInfo);
154 
155  }
156  catch(const te::common::Exception& e)
157  {
158  std::cout << std::endl << "Failed to create a new layer and insert it into the application: " << e.what() << std::endl;
159  QWizard::finished(1);
160  }
161  catch(...)
162  {
163  std::cout << std::endl << "Failed to create a new layer and insert it into the application: unknown exception!" << std::endl;
164  QWizard::finished(1);
165  }
166 
167  QApplication::restoreOverrideCursor();
168  QWizard::finished(0);
169 }
te::da::DataSourceInfoPtr getDataSource() const
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
Definition: Utils.cpp:136
std::auto_ptr< Ui::TimeSeriesWizardForm > m_ui
The wizard's form.
A layer with reference to a dataset that contains trajectories.
te::st::TimeSeriesDataSetLayerPtr generateLayer(te::da::DataSetTypePtr dataType, te::st::TimeSeriesDataSetInfo *timeSeriesInfo, te::da::DataSourceInfoPtr dataInfo, te::map::AbstractLayer *parent=0)
std::auto_ptr< DataSetSelectorWizardPage > m_datasetSelectorPage
The wizard page used to select the dataset.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
This is the base class for layers.
Definition: AbstractLayer.h:76
virtual const char * what() const
It outputs the exception message.
Definition: Exception.cpp:58
std::auto_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.
Definition: Utils.cpp:284
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)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
std::auto_ptr< TimeSeriesPropertiesWizardPage > m_PropWidgetPage
The widget used to configure the properties of the new TimeSeriesLayer.
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)
Definition: Utils.cpp:557
boost::intrusive_ptr< TimeSeriesDataSetLayer > TimeSeriesDataSetLayerPtr
te::da::DataSetTypePtr getDatasetType() const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127