All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/datasource/selector/DataSourceSelectorDialog.h"
26 #include "ui_VectorizationWizardPageForm.h"
27 
28 // Qt
29 #include <QCheckBox>
30 #include <QFileDialog>
31 #include <QIntValidator>
32 
33 // BOOST
34 #include <boost/algorithm/string.hpp>
35 #include <boost/filesystem.hpp>
36 #include <boost/lexical_cast.hpp>
37 
39  QWizardPage(parent)
40 {
41  m_ui.reset(new Ui::VectorizationWizardPageForm);
42 
43  m_ui->setupUi(this);
44 
45 //configure page
46  this->setTitle(tr("Vectorization"));
47  this->setSubTitle(tr("Define the vectorization parameters."));
48 
49  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
50 
51  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
52  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
53 
54  m_ui->m_maxGeomLineEdit->setValidator(new QIntValidator(this));
55 }
56 
58 {
59 
60 }
61 
63 {
64  return true;
65 }
66 
68 {
69  m_layer = layer;
70 
71  m_ui->m_layerLineEdit->setText(m_layer->getTitle().c_str());
72 
73  //list bands
74  m_ui->m_bandComboBox->clear();
75 
76  //get input raster
77  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
78 
79  if(ds.get())
80  {
81  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
82 
83  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
84 
85  if(inputRst.get())
86  {
87  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
88  {
89  m_ui->m_bandComboBox->addItem(QString::number(i));
90  }
91  }
92  }
93 }
94 
96 {
97  assert(m_layer.get());
98 
99  //get input raster
100  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
101 
102  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
103 
104  return ds->getRaster(rpos);
105 }
106 
108 {
109  return m_ui->m_bandComboBox->currentText().toUInt();
110 }
111 
113 {
114  if(!m_ui->m_maxGeomLineEdit->text().isEmpty())
115  maxGeom = m_ui->m_maxGeomLineEdit->text().toInt();
116 
117  return m_ui->m_maxGeomCheckBox->isChecked();
118 }
119 
121 {
122  return m_toFile;
123 }
124 
126 {
127  return m_outputDatasource;
128 }
129 
131 {
132  if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
133  return "";
134 
135  return m_ui->m_newLayerNameLineEdit->text().toStdString();
136 }
137 
139 {
140  if(m_ui->m_repositoryLineEdit->text().isEmpty())
141  return "";
142 
143  return m_ui->m_repositoryLineEdit->text().toStdString();
144 }
145 
147 {
148  m_ui->m_newLayerNameLineEdit->clear();
149  m_ui->m_newLayerNameLineEdit->setEnabled(true);
151  dlg.exec();
152 
153  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
154 
155  if(dsPtrList.size() <= 0)
156  return;
157 
158  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
159 
160  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
161 
162  m_outputDatasource = *it;
163 
164  m_toFile = false;
165 }
166 
168 {
169  m_ui->m_newLayerNameLineEdit->clear();
170  m_ui->m_repositoryLineEdit->clear();
171 
172  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
173  QString(), tr("Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
174 
175  if(fileName.isEmpty())
176  return;
177 
178  boost::filesystem::path outfile(fileName.toStdString());
179  std::string aux = outfile.leaf().string();
180  m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
181  aux = outfile.string();
182  m_ui->m_repositoryLineEdit->setText(aux.c_str());
183 
184  m_toFile = true;
185  m_ui->m_newLayerNameLineEdit->setEnabled(false);
186 }
187 
188 
void setLayer(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for vectorization operation.
std::auto_ptr< te::rst::Raster > getRaster()
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
std::auto_ptr< Ui::VectorizationWizardPageForm > m_ui
A dialog for selecting a data source.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr