All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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::TrajectoryDataSetLayerPtr trajectoryLayer = new te::st::TrajectoryDataSetLayer(id, title, parent, trajInfo);
50  trajectoryLayer->setVisibility(te::map::NOT_VISIBLE);
51  trajectoryLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
52 
54  std::auto_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataType->getName(), gp->getName(), dataInfo->getId()));
55  trajectoryLayer->setSRID(gp->getSRID());
56  trajectoryLayer->setExtent(*mbr);
57  trajectoryLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
58  return trajectoryLayer;
59 }
60 
61 te::qt::widgets::TrajectoryWizard::TrajectoryWizard(QWidget* parent, Qt::WindowFlags f)
62  : QWizard(parent, f),
63  m_ui(new Ui::TrajectoryWizardForm)
64 {
65  m_ui->setupUi(this);
66 
67  //DataSource
69  m_datasourceSelectorPage->setTitle(tr("Data Source Selection"));
70  m_datasourceSelectorPage->setSubTitle(tr("Please, select the data source where the data is stored"));
71  m_datasourceSelectorPage->getSelectorWidget()->setSelectionMode(QAbstractItemView::SingleSelection);
72  m_datasourceSelectorPage->getSelectorWidget()->showDataSourceWithRasterSupport(false);
74 
75  //DataSet
77  m_datasetSelectorPage->setTitle(tr("Dataset Selection"));
78  m_datasetSelectorPage->setSubTitle(tr("Please, select the datasets you want to transfer to another data source"));
80 
81  //Trajectory Properties
83  m_PropWidgetPage->setTitle(tr("Trajectory Properties"));
84  m_PropWidgetPage->setSubTitle(tr("Please, adjust the temporal properties of the new Trajectory Layer"));
86 
87  // connect signals and slots
88  connect(this->button(QWizard::NextButton), SIGNAL(pressed()), this, SLOT(next()));
89  connect(this->button(QWizard::BackButton), SIGNAL(pressed()), this, SLOT(back()));
90  connect(this->button(QWizard::FinishButton), SIGNAL(pressed()), this, SLOT(finish()));
91 
93  this->setButton(QWizard::HelpButton, helpButton);
94  //helpButton->setPageReference("widgets/exchanger_all/exchanger_all.html");
95 }
96 
98 {
99 }
100 
102 {
103  std::list<te::da::DataSourceInfoPtr> datasources = m_datasourceSelectorPage->getSelectorWidget()->getSelecteds();
104 
105  if(datasources.empty())
106  return te::da::DataSourceInfoPtr();
107  else
108  return datasources.front();
109 }
110 
111 std::list<te::st::TrajectoryDataSetLayerPtr> te::qt::widgets::TrajectoryWizard::getTrajectoryLayers()
112 {
113  return m_trajectoryLayers;
114 }
115 
117 {
118  QWizard::back();
119 }
120 
122 {
123  if(currentId() == PAGE_DATASOURCE_SELECTION)
124  {
125  m_datasetSelectorPage->set(getDataSource(), true);
126  }
127  else if (currentId() == PAGE_DATASET_SELECTION)
128  {
129  m_PropWidgetPage->set(m_datasetSelectorPage->getCheckedDataSets());
130  }
131  QWizard::next();
132 }
133 
135 {
136  QApplication::setOverrideCursor(Qt::WaitCursor);
137  te::da::DataSourceInfoPtr dataInfo = getDataSource();
138  std::list<te::da::DataSetTypePtr> dataTypes = m_datasetSelectorPage->getCheckedDataSets();
139 
140  try
141  {
142  std::list<te::st::TrajectoryDataSetInfo*> infos = m_PropWidgetPage->getInfo(dataInfo);
143  std::list<te::st::TrajectoryDataSetInfo*>::const_iterator infosBegin = infos.begin();
144  std::list<te::st::TrajectoryDataSetInfo*>::const_iterator infosEnd = infos.end();
145  std::list<te::da::DataSetTypePtr>::const_iterator typesItBegin = dataTypes.begin();
146 
147  if (infos.size() == 1)
148  {
149  m_trajectoryLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
150  }
151  else
152  {
153  while(infosBegin != infosEnd)
154  {
155  m_trajectoryLayers.push_back(generateLayer(*typesItBegin, *infosBegin, dataInfo));
156  infosBegin++;
157  typesItBegin++;
158  }
159  }
160  }
161  catch(const te::common::Exception& e)
162  {
163  std::cout << std::endl << "Failed to create a new layer and insert it into the application: " << e.what() << std::endl;
164  QWizard::finished(1);
165  }
166  catch(...)
167  {
168  std::cout << std::endl << "Failed to create a new layer and insert it into the application: unknown exception!" << std::endl;
169  QWizard::finished(1);
170  }
171 
172  QApplication::restoreOverrideCursor();
173  QWizard::finished(0);
174 }
Geometric property.
boost::intrusive_ptr< TrajectoryDataSetLayer > TrajectoryDataSetLayerPtr
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
This is the base class for layers.
Definition: AbstractLayer.h:76
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::st::TrajectoryDataSetLayerPtr generateLayer(te::da::DataSetTypePtr dataType, te::st::TrajectoryDataSetInfo *trajInfo, te::da::DataSourceInfoPtr dataInfo, te::map::AbstractLayer *parent=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
A wizard used to generate a new Trajectorylayer.
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::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. ...
Definition: Exception.h:58
std::auto_ptr< Ui::TrajectoryWizardForm > m_ui
The wizard's form.
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.
std::auto_ptr< TrajectoryPropertiesWizardPage > m_PropWidgetPage
The widget used to configure the properties of the new TrajectoryLayer.
A layer with reference to a dataset that contains trajectories.
std::auto_ptr< DataSetSelectorWizardPage > m_datasetSelectorPage
The wizard page used to select the dataset.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:557
A wizardPage used to configure the generaç properties of a new trajectory layer.
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