VectorizationWizardPage.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 //Terralib
22 #include "../../../dataaccess/dataset/DataSet.h"
23 #include "../../../dataaccess/utils/Utils.h"
24 #include "../../widgets/utils/FileDialog.h"
25 #include "../../widgets/datasource/selector/DataSourceSelectorDialog.h"
27 #include "ui_VectorizationWizardPageForm.h"
28 
29 // Qt
30 #include <QCheckBox>
31 #include <QFileDialog>
32 #include <QIntValidator>
33 #include <QMessageBox>
34 
35 // BOOST
36 #include <boost/algorithm/string.hpp>
37 #include <boost/filesystem.hpp>
38 #include <boost/lexical_cast.hpp>
39 
41  QWizardPage(parent)
42 {
43  m_ui.reset(new Ui::VectorizationWizardPageForm);
44 
45  m_ui->setupUi(this);
46 
47 //configure page
48  this->setTitle(tr("Vectorization"));
49  this->setSubTitle(tr("Define the vectorization parameters."));
50 
51  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
52 
53  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
54  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
55 
56  m_ui->m_maxGeomLineEdit->setValidator(new QIntValidator(this));
57 }
58 
60 
62 {
63  return true;
64 }
65 
67 {
68  m_layer = layer;
69 
70  m_ui->m_layerLineEdit->setText(m_layer->getTitle().c_str());
71 
72  //list bands
73  m_ui->m_bandComboBox->clear();
74 
75  //get input raster
76  std::unique_ptr<te::da::DataSet> ds = m_layer->getData();
77 
78  if(ds.get())
79  {
80  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
81 
82  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
83 
84  if(inputRst.get())
85  {
86  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
87  {
88  m_ui->m_bandComboBox->addItem(QString::number(i));
89  }
90  }
91  }
92 }
93 
94 std::unique_ptr<te::rst::Raster> te::qt::widgets::VectorizationWizardPage::getRaster()
95 {
96  assert(m_layer.get());
97 
98  //get input raster
99  std::unique_ptr<te::da::DataSet> ds = m_layer->getData();
100 
101  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
102 
103  return ds->getRaster(rpos);
104 }
105 
107 {
108  return m_ui->m_bandComboBox->currentText().toUInt();
109 }
110 
112 {
113  if(!m_ui->m_maxGeomLineEdit->text().isEmpty())
114  maxGeom = m_ui->m_maxGeomLineEdit->text().toInt();
115 
116  return m_ui->m_maxGeomCheckBox->isChecked();
117 }
118 
120 {
121  return m_toFile;
122 }
123 
125 {
126  return m_outputDatasource;
127 }
128 
130 {
131  if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
132  return "";
133 
134  return m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
135 }
136 
138 {
139  if(m_ui->m_repositoryLineEdit->text().isEmpty())
140  return "";
141 
142  return m_ui->m_repositoryLineEdit->text().toUtf8().data();
143 }
144 
146 {
147  m_ui->m_newLayerNameLineEdit->clear();
148  m_ui->m_newLayerNameLineEdit->setEnabled(true);
150  dlg.exec();
151 
152  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
153 
154  if(dsPtrList.size() <= 0)
155  return;
156 
157  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
158 
159  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
160 
161  m_outputDatasource = *it;
162 
163  m_toFile = false;
164 }
165 
167 {
168  m_ui->m_newLayerNameLineEdit->clear();
169  m_ui->m_repositoryLineEdit->clear();
170 
172 
173  try
174  {
175  fileDialog.exec();
176  }
177  catch(te::common::Exception& ex)
178  {
179  QMessageBox::warning(this, tr("File information"), ex.what());
180  return;
181  }
182  catch(...)
183  {
184  QMessageBox::warning(this, tr("File information"), tr("Output layer is invalid."));
185  return;
186  }
187 
188  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
189  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
190 
191  m_toFile = true;
192  m_ui->m_newLayerNameLineEdit->setEnabled(false);
193 }
194 
195 
Defines a component for choose a file.
Definition: FileDialog.h:52
void setLayer(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for vectorization operation.
virtual const char * what() const
It outputs the exception message.
static te::dt::Date ds(2010, 01, 01)
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
A dialog for selecting a data source.
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
std::unique_ptr< te::rst::Raster > getRaster()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
std::unique_ptr< Ui::VectorizationWizardPageForm > m_ui
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.