ObservationWizard.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/ObservationWizard.cpp
22 
23  \brief A wizard used to generate a new Observationlayer.
24 */
25 
26 //Terralib
27 #include "../../../geometry/Envelope.h"
28 #include "../../../geometry/GeometryProperty.h"
29 #include "../../../qt/widgets/dataset/selector/DataSetSelectorWizardPage.h"
30 #include "../../../qt/widgets/datasource/selector/DataSourceSelectorWidget.h"
31 #include "../../../qt/widgets/datasource/selector/DataSourceSelectorWizardPage.h"
32 #include "../../../qt/widgets/help/HelpPushButton.h"
33 #include "../../../se/Utils.h"
34 #include "../../../st/core/observation/ObservationDataSetInfo.h"
36 #include "ObservationWizard.h"
37 #include "ui_ObservationWizardForm.h"
38 
39 //Boost
40 #include <boost/uuid/random_generator.hpp>
41 #include <boost/uuid/uuid_io.hpp>
42 
43 //STL
44 #include <iostream>
45 
47 {
48  static boost::uuids::basic_random_generator<boost::mt19937> gen;
49  boost::uuids::uuid u = gen();
50  std::string id = boost::uuids::to_string(u);
51  std::string title = dataType->getTitle().empty() ? dataType->getName() : dataType->getTitle();
52 
53  te::st::ObservationDataSetLayerPtr observationLayer = new te::st::ObservationDataSetLayer(id, title, parent, obsInfo);
54  observationLayer->setVisibility(te::map::NOT_VISIBLE);
55  observationLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
56 
58  std::unique_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataType->getName(), gp->getName(), dataInfo->getId()));
59  observationLayer->setSRID(gp->getSRID());
60  observationLayer->setExtent(*mbr);
61  observationLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
62  return observationLayer;
63 }
64 
66  : QWizard(parent, f),
67  m_ui(new Ui::ObservationWizardForm)
68 {
69  m_ui->setupUi(this);
70 
71  //DataSource
73  m_datasourceSelectorPage->setTitle(tr("Data Source Selection"));
74  m_datasourceSelectorPage->setSubTitle(tr("Please, select the data source where the data is stored"));
75  m_datasourceSelectorPage->getSelectorWidget()->setSelectionMode(QAbstractItemView::SingleSelection);
76  m_datasourceSelectorPage->getSelectorWidget()->showDataSourceWithRasterSupport(false);
78 
79  //DataSet
81  m_datasetSelectorPage->setTitle(tr("Dataset Selection"));
82  m_datasetSelectorPage->setSubTitle(tr("Please, select the datasets you want to transfer to another data source"));
84 
85  //Observation Properties
87  m_PropWidgetPage->setTitle(tr("Observation Properties"));
88  m_PropWidgetPage->setSubTitle(tr("Please, adjust the temporal properties of the new Observation Layer"));
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 
113 std::list<te::st::ObservationDataSetLayerPtr> te::qt::widgets::ObservationWizard::getObservationLayers()
114 {
115  return m_observationLayers;
116 }
117 
119 {
120  QWizard::back();
121 }
122 
124 {
125  if(currentId() == PAGE_DATASOURCE_SELECTION)
126  {
127  m_datasetSelectorPage->set(getDataSource(), true);
128  }
129  else if (currentId() == PAGE_DATASET_SELECTION)
130  {
131  m_PropWidgetPage->set(m_datasetSelectorPage->getCheckedDataSets());
132  }
133  QWizard::next();
134 }
135 
137 {
138  QApplication::setOverrideCursor(Qt::WaitCursor);
140  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
141 
142  try
143  {
144  std::list<te::st::ObservationDataSetInfo*> infos = m_PropWidgetPage->getInfo(dataInfo);
145  std::list<te::st::ObservationDataSetInfo*>::const_iterator infosBegin = infos.begin();
146  std::list<te::st::ObservationDataSetInfo*>::const_iterator infosEnd = infos.end();
147  std::list<te::da::DataSetTypePtr>::const_iterator typesItBegin = dataTypes.begin();
148 
149  if (infos.size() == 1)
150  {
151  m_observationLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
152  }
153  else
154  {
155  static boost::uuids::basic_random_generator<boost::mt19937> gen;
156  boost::uuids::uuid u = gen();
157  std::string id = boost::uuids::to_string(u);
158 
159  while(infosBegin != infosEnd)
160  {
161  m_observationLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
162  infosBegin++;
163  typesItBegin++;
164  }
165  }
166  }
167  catch(const te::common::Exception& e)
168  {
169  std::cout << std::endl << "Failed to create a new layer and insert it into the application: " << e.what() << std::endl;
170  QWizard::finished(1);
171  }
172  catch(...)
173  {
174  std::cout << std::endl << "Failed to create a new layer and insert it into the application: unknown exception!" << std::endl;
175  QWizard::finished(1);
176  }
177 
178  QApplication::restoreOverrideCursor();
179  QWizard::finished(0);
180 }
std::unique_ptr< DataSetSelectorWizardPage > m_datasetSelectorPage
The wizard page used to select the dataset.
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
A layer with reference to a dataset that contains observations.
This is the base class for layers.
Definition: AbstractLayer.h:77
A class that contains infos about a DataSet that contains observations.
boost::intrusive_ptr< ObservationDataSetLayer > ObservationDataSetLayerPtr
virtual const char * what() const
It outputs the exception message.
te::da::DataSourceInfoPtr getDataSource() const
ObservationWizard(QWidget *parent=0, Qt::WindowFlags f=0)
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.
A WizardPage used to configure the general properties of a new spatio-temporal layer.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::unique_ptr< ObservationPropertiesWizardPage > m_PropWidgetPage
The widget used to configure the properties of the new ObservationLayer.
te::st::ObservationDataSetLayerPtr generateLayer(te::da::DataSetTypePtr dataType, te::st::ObservationDataSetInfo *obsInfo, te::da::DataSourceInfoPtr dataInfo, te::map::AbstractLayer *parent=nullptr)
std::list< te::st::ObservationDataSetLayerPtr > getObservationLayers()
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
std::unique_ptr< DataSourceSelectorWizardPage > m_datasourceSelectorPage
The wizard page used to select the datasource.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::unique_ptr< Ui::ObservationWizardForm > m_ui
The wizard&#39;s form.
A wizard used to generate a new Observationlayer.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
std::list< te::st::ObservationDataSetLayerPtr > m_observationLayers
The new Observation Layer(s);.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127