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) 2011-2012 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  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
50  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
51 
52  m_ui->m_maxGeomLineEdit->setValidator(new QIntValidator(this));
53 }
54 
56 {
57 
58 }
59 
61 {
62  return true;
63 }
64 
66 {
67  m_layer = layer;
68 
69  m_ui->m_layerLineEdit->setText(m_layer->getTitle().c_str());
70 
71  //list bands
72  m_ui->m_bandComboBox->clear();
73 
74  //get input raster
75  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
76 
77  if(ds.get())
78  {
79  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
80 
81  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
82 
83  if(inputRst.get())
84  {
85  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
86  {
87  m_ui->m_bandComboBox->addItem(QString::number(i));
88  }
89  }
90  }
91 }
92 
94 {
95  assert(m_layer.get());
96 
97  //get input raster
98  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
99 
100  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
101 
102  return ds->getRaster(rpos);
103 }
104 
106 {
107  return m_ui->m_bandComboBox->currentText().toUInt();
108 }
109 
111 {
112  if(!m_ui->m_maxGeomLineEdit->text().isEmpty())
113  maxGeom = m_ui->m_maxGeomLineEdit->text().toInt();
114 
115  return m_ui->m_maxGeomCheckBox->isChecked();
116 }
117 
119 {
120  return m_toFile;
121 }
122 
124 {
125  return m_outputDatasource;
126 }
127 
129 {
130  return m_ui->m_newLayerNameLineEdit->text().toStdString();
131 }
132 
134 {
135  return m_ui->m_repositoryLineEdit->text().toStdString();
136 }
137 
139 {
140  m_ui->m_newLayerNameLineEdit->clear();
141  m_ui->m_newLayerNameLineEdit->setEnabled(true);
143  dlg.exec();
144 
145  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
146 
147  if(dsPtrList.size() <= 0)
148  return;
149 
150  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
151 
152  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
153 
154  m_outputDatasource = *it;
155 
156  m_toFile = false;
157 }
158 
160 {
161  m_ui->m_newLayerNameLineEdit->clear();
162  m_ui->m_repositoryLineEdit->clear();
163 
164  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
165  QString(), tr("Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
166 
167  if(fileName.isEmpty())
168  return;
169 
170  boost::filesystem::path outfile(fileName.toStdString());
171  std::string aux = outfile.leaf().string();
172  m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
173  aux = outfile.string();
174  m_ui->m_repositoryLineEdit->setText(aux.c_str());
175 
176  m_toFile = true;
177  m_ui->m_newLayerNameLineEdit->setEnabled(false);
178 }
179 
180 
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:432
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr