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