All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ClippingWizardPage.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  \file terralib/qt/widgets/rp/ClippingWizardPage.cpp
22 
23  \brief This file defines a class for a Clipping Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../raster/Grid.h"
31 #include "../../../raster/Raster.h"
32 #include "RasterNavigatorWidget.h"
33 #include "ClippingWizardPage.h"
34 #include "ui_ClippingWizardPageForm.h"
35 
36 // Qt
37 #include <QGridLayout>
38 #include <QCheckBox>
39 #include <QDoubleValidator>
40 #include <QIntValidator>
41 #include <QMessageBox>
42 
43 // STL
44 #include <memory>
45 
47 
49  : QWizardPage(parent),
50  m_ui(new Ui::ClippingWizardPageForm),
51  m_layer(0)
52 {
53 // setup controls
54  m_ui->setupUi(this);
55 
57 
58 //build form
59  QGridLayout* displayLayout = new QGridLayout(m_ui->m_frame);
61  m_navigator->showAsPreview(false, true);
62  m_navigator->hideColorCompositionTool(true);
63  m_navigator->hideGeomTool(true);
64  m_navigator->hideInfoTool(true);
65  m_navigator->hidePickerTool(true);
66  displayLayout->addWidget(m_navigator.get());
67  displayLayout->setContentsMargins(0,0,0,0);
68 
69  connect(m_navigator.get(), SIGNAL(envelopeAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
70 
71 //configure page
72  this->setTitle(tr("Clipping"));
73  this->setSubTitle(tr("Select the type of clipping and set their specific parameters."));
74 
75  m_ui->m_llxLineEdit->setValidator(new QDoubleValidator(this));
76  m_ui->m_llyLineEdit->setValidator(new QDoubleValidator(this));
77  m_ui->m_urxLineEdit->setValidator(new QDoubleValidator(this));
78  m_ui->m_uryLineEdit->setValidator(new QDoubleValidator(this));
79 
80  m_ui->m_startRowLineEdit->setValidator(new QIntValidator(this));
81  m_ui->m_startColumnLineEdit->setValidator(new QIntValidator(this));
82  m_ui->m_widthLineEdit->setValidator(new QIntValidator(this));
83  m_ui->m_heightLineEdit->setValidator(new QIntValidator(this));
84 
85 //connects
86  connect(m_ui->m_strategyTypeComboBox, SIGNAL(activated(int)), this, SLOT(onStrategyTypeComboBoxActivated(int)));
87  connect(m_ui->m_layerComboBox, SIGNAL(activated(int)), this, SLOT(onLayerComboBoxActivated(int)));
88 
89  connect(m_ui->m_llxLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
90  connect(m_ui->m_llyLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
91  connect(m_ui->m_urxLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
92  connect(m_ui->m_uryLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
93 
94  connect(m_ui->m_startRowLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
95  connect(m_ui->m_startColumnLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
96  connect(m_ui->m_widthLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
97  connect(m_ui->m_heightLineEdit, SIGNAL(editingFinished()), this, SIGNAL(completeChanged()));
98 }
99 
101 {
102 }
103 
105 {
106  int index = m_ui->m_strategyTypeComboBox->currentIndex();
107  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
108 
109  if(type == CLIPPING_EXTENT)
110  {
111  if(m_ui->m_llxLineEdit->text().isEmpty() ||
112  m_ui->m_llyLineEdit->text().isEmpty() ||
113  m_ui->m_urxLineEdit->text().isEmpty() ||
114  m_ui->m_uryLineEdit->text().isEmpty()
115  )
116  return false;
117 
118  return true;
119  }
120  else if(type == CLIPPING_DIMENSION)
121  {
122  if(m_ui->m_startRowLineEdit->text().isEmpty() ||
123  m_ui->m_startColumnLineEdit->text().isEmpty() ||
124  m_ui->m_widthLineEdit->text().isEmpty() ||
125  m_ui->m_heightLineEdit->text().isEmpty()
126  )
127  return false;
128 
129  return true;
130  }
131  else if(type == CLIPPING_LAYER)
132  {
133  return true;
134  }
135 
136  return false;
137 }
138 
140 {
141  m_layer = layer;
142 
143  std::list<te::map::AbstractLayerPtr> list;
144 
145  list.push_back(m_layer);
146 
147  m_navigator->set(m_layer);
148 }
149 
150 void te::qt::widgets::ClippingWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
151 {
152  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
153 
154  while(it != layerList.end())
155  {
157 
158  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
159 
160  if(dsType->hasGeom())
161  m_ui->m_layerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
162 
163  ++it;
164  }
165 
166  if(m_ui->m_layerComboBox->count() > 0)
167  onLayerComboBoxActivated(0);
168 }
169 
171 {
172  return m_layer;
173 }
174 
176 {
177  int index = m_ui->m_strategyTypeComboBox->currentIndex();
178  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
179 
180  return type == CLIPPING_EXTENT;
181 }
182 
184 {
185  int index = m_ui->m_strategyTypeComboBox->currentIndex();
186  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
187 
188  return type == CLIPPING_DIMENSION;
189 }
190 
192 {
193  int index = m_ui->m_strategyTypeComboBox->currentIndex();
194  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
195 
196  return type == CLIPPING_LAYER;
197 }
198 
200 {
201  env.m_llx = m_ui->m_llxLineEdit->text().toDouble();
202  env.m_lly = m_ui->m_llyLineEdit->text().toDouble();
203  env.m_urx = m_ui->m_urxLineEdit->text().toDouble();
204  env.m_ury = m_ui->m_uryLineEdit->text().toDouble();
205 }
206 
207 void te::qt::widgets::ClippingWizardPage::getDimensionClipping(int& x, int& y, int& width, int& height)
208 {
209  x = m_ui->m_startColumnLineEdit->text().toInt();
210  y = m_ui->m_startRowLineEdit->text().toInt();
211  width = m_ui->m_widthLineEdit->text().toInt();
212  height = m_ui->m_heightLineEdit->text().toInt();
213 }
214 
216 {
217  emit completeChanged();
218 }
219 
221 {
222  m_ui->m_layerAttrComboBox->clear();
223 
224  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
226 
227  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
228 
229  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
230  {
231  m_ui->m_layerAttrComboBox->addItem(dsType->getProperties()[t]->getName().c_str());
232  }
233 }
234 
236 {
237  if(!env.isValid())
238  return;
239 
240  int index = m_ui->m_strategyTypeComboBox->currentIndex();
241  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
242 
243  if(type == CLIPPING_EXTENT)
244  {
245  m_ui->m_llxLineEdit->setText(QString::number(env.getLowerLeftX(), 'f', 5));
246  m_ui->m_llyLineEdit->setText(QString::number(env.getLowerLeftY(), 'f', 5));
247  m_ui->m_urxLineEdit->setText(QString::number(env.getUpperRightX(), 'f', 5));
248  m_ui->m_uryLineEdit->setText(QString::number(env.getUpperRightY(), 'f', 5));
249 
250  m_navigator->setExtent(env);
251  }
252  else if(type == CLIPPING_DIMENSION)
253  {
254  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
255 
256  if(ds.get())
257  {
258  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
259  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
260 
261  if(inputRst.get())
262  {
263  // find the envelope coords in grid coordenates
264  te::gm::Coord2D ul = inputRst->getGrid()->geoToGrid((double) env.getLowerLeftX(), (double) env.getUpperRightY());
265  te::gm::Coord2D lr = inputRst->getGrid()->geoToGrid((double) env.getUpperRightX(), (double) env.getLowerLeftY());
266 
267  m_ui->m_startRowLineEdit->setText(QString::number((int)ul.y));
268  m_ui->m_startColumnLineEdit->setText(QString::number((int)ul.x));
269  m_ui->m_heightLineEdit->setText(QString::number((int)(lr.y - ul.y)));
270  m_ui->m_widthLineEdit->setText(QString::number((int)(lr.x - ul.x)));
271  }
272  }
273  }
274 
275  emit completeChanged();
276 }
277 
279 {
280  m_ui->m_strategyTypeComboBox->clear();
281 
282  m_ui->m_strategyTypeComboBox->addItem(tr("Extent"), CLIPPING_EXTENT);
283  m_ui->m_strategyTypeComboBox->addItem(tr("Dimension"), CLIPPING_DIMENSION);
284  //m_ui->m_strategyTypeComboBox->addItem(tr("Layer"), CLIPPING_LAYER);
285 }
void onEnvelopeAcquired(te::gm::Envelope env)
std::auto_ptr< Ui::ClippingWizardPageForm > m_ui
double y
y-coordinate.
Definition: Coord2D.h:87
double x
x-coordinate.
Definition: Coord2D.h:86
void getExtentClipping(te::gm::Envelope &env)
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This file defines a class for a Clipping Wizard page.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for clipping operation.
This file has the RasterNavigatorWidget class.
std::auto_ptr< te::qt::widgets::RasterNavigatorWidget > m_navigator
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:432
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void getDimensionClipping(int &x, int &y, int &width, int &height)
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438