TrajectoryWizard.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/TrajectoryWizard.cpp
22 
23  \brief A wizard used to generate a new Trajectorylayer.
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/trajectory/TrajectoryDataSetInfo.h"
35 #include "TrajectoryWizard.h"
36 #include "ui_TrajectoryWizardForm.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::TrajectoryDataSetLayerPtr trajectoryLayer = new te::st::TrajectoryDataSetLayer(id, title, parent, trajInfo);
53  trajectoryLayer->setVisibility(te::map::NOT_VISIBLE);
54  trajectoryLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
55 
57  std::unique_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataType->getName(), gp->getName(), dataInfo->getId()));
58  trajectoryLayer->setSRID(gp->getSRID());
59  trajectoryLayer->setExtent(*mbr);
60  trajectoryLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
61  return trajectoryLayer;
62 }
63 
65  : QWizard(parent, f),
66  m_ui(new Ui::TrajectoryWizardForm)
67 {
68  m_ui->setupUi(this);
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  //Trajectory Properties
86  m_PropWidgetPage->setTitle(tr("Trajectory Properties"));
87  m_PropWidgetPage->setSubTitle(tr("Please, adjust the temporal properties of the new Trajectory Layer"));
89 
90  // connect signals and slots
91  connect(this->button(QWizard::NextButton), SIGNAL(pressed()), this, SLOT(next()));
92  connect(this->button(QWizard::BackButton), SIGNAL(pressed()), this, SLOT(back()));
93  connect(this->button(QWizard::FinishButton), SIGNAL(pressed()), this, SLOT(finish()));
94 
96  this->setButton(QWizard::HelpButton, helpButton);
97  //helpButton->setPageReference("widgets/exchanger_all/exchanger_all.html");
98 }
99 
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::TrajectoryDataSetLayerPtr> te::qt::widgets::TrajectoryWizard::getTrajectoryLayers()
113 {
114  return m_trajectoryLayers;
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);
139  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
140 
141  try
142  {
143  std::list<te::st::TrajectoryDataSetInfo*> infos = m_PropWidgetPage->getInfo(dataInfo);
144  std::list<te::st::TrajectoryDataSetInfo*>::const_iterator infosBegin = infos.begin();
145  std::list<te::st::TrajectoryDataSetInfo*>::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_trajectoryLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
151  }
152  else
153  {
154  while(infosBegin != infosEnd)
155  {
156  m_trajectoryLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
157  infosBegin++;
158  typesItBegin++;
159  }
160  }
161  }
162  catch(const te::common::Exception& e)
163  {
164  std::cout << std::endl << "Failed to create a new layer and insert it into the application: " << e.what() << std::endl;
165  QWizard::finished(1);
166  }
167  catch(...)
168  {
169  std::cout << std::endl << "Failed to create a new layer and insert it into the application: unknown exception!" << std::endl;
170  QWizard::finished(1);
171  }
172 
173  QApplication::restoreOverrideCursor();
174  QWizard::finished(0);
175 }
Geometric property.
boost::intrusive_ptr< TrajectoryDataSetLayer > TrajectoryDataSetLayerPtr
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
This is the base class for layers.
Definition: AbstractLayer.h:77
virtual const char * what() const
It outputs the exception message.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
std::unique_ptr< TrajectoryPropertiesWizardPage > m_PropWidgetPage
The widget used to configure the properties of the new TrajectoryLayer.
A wizard used to generate a new Trajectorylayer.
std::unique_ptr< Ui::TrajectoryWizardForm > m_ui
The wizard&#39;s form.
te::st::TrajectoryDataSetLayerPtr generateLayer(te::da::DataSetTypePtr dataType, te::st::TrajectoryDataSetInfo *trajInfo, te::da::DataSourceInfoPtr dataInfo, te::map::AbstractLayer *parent=nullptr)
A WizardPage used to configure the general properties of a new spatio-temporal layer.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
std::unique_ptr< DataSetSelectorWizardPage > m_datasetSelectorPage
The wizard page used to select the dataset.
std::list< te::st::TrajectoryDataSetLayerPtr > getTrajectoryLayers()
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
te::da::DataSourceInfoPtr getDataSource() const
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A class that contains infos about a DataSet that contains observations of one or more trajectories...
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
A layer with reference to a dataset that contains trajectories.
std::unique_ptr< DataSourceSelectorWizardPage > m_datasourceSelectorPage
The wizard page used to select the datasource.
std::list< te::st::TrajectoryDataSetLayerPtr > m_trajectoryLayers
The new Trajectory Layer(s);.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TrajectoryWizard(QWidget *parent=0, Qt::WindowFlags f=0)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127