27 #include "../../../common/PlatformUtils.h" 28 #include "../../../common/StringUtils.h" 29 #include "../../../core/utils/Platform.h" 30 #include "../../../core/translator/Translator.h" 31 #include "../../../dataaccess/dataset/DataSet.h" 32 #include "../../../dataaccess/utils/Utils.h" 34 #include "ui_LoadArithmeticOpDialogForm.h" 37 #include <boost/algorithm/string.hpp> 38 #include <boost/property_tree/json_parser.hpp> 41 #include <QApplication> 42 #include <QGridLayout> 43 #include <QMessageBox> 46 #include <QTextStream> 53 te::qt::widgets::LoadArithmeticOpDialog::LoadArithmeticOpDialog(
QWidget* parent, Qt::WindowFlags f)
55 m_ui(new
Ui::LoadArithmeticOpDialogForm)
60 m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
63 connect(m_ui->m_operationComboBox, SIGNAL(activated(QString)),
this, SLOT(onOperationComboBoxActivated(QString)));
64 connect(m_ui->m_removeToolButton, SIGNAL(clicked()),
this, SLOT(onRemoveOperation()));
65 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
72 m_ui->m_layersTableWidget->clear();
73 m_ui->m_operationComboBox->clear();
75 m_ui->m_layersTableWidget->setRowCount(0);
78 list.append(tr(
"Layer"));
79 list.append(tr(
"Band"));
81 m_ui->m_layersTableWidget->setHorizontalHeaderLabels(list);
82 m_ui->m_layersTableWidget->setColumnCount(2);
84 std::string jsonfile =
m_userPath +
"/arithmeticOperations.json";
92 boost::property_tree::ptree pt;
94 boost::property_tree::json_parser::read_json(jsonfile, pt);
96 for(boost::property_tree::ptree::value_type &v: pt.get_child(
"operations"))
98 std::string op = v.second.get<std::string>(
"operation");
99 m_ui->m_operationComboBox->addItem(op.c_str());
102 catch(boost::property_tree::json_parser::json_parser_error& e)
104 std::string msg =
"Error parsing: " + e.filename() +
": " + e.message();
108 catch(boost::property_tree::ptree_error& e)
149 m_ui->m_layersTableWidget->setRowCount(0);
151 m_ui->m_gainLineEdit->setEnabled(
false);
152 m_ui->m_offsetLineEdit->setEnabled(
false);
153 m_ui->m_gainLineEdit->setText(
"");
154 m_ui->m_offsetLineEdit->setText(
"");
156 std::string op = operation.toUtf8().data();
158 std::vector<std::string> arithExpVec;
159 boost::split(arithExpVec, op, boost::is_any_of(
" "));
161 for (
size_t i = 0; i < arithExpVec.size(); i++)
163 if (arithExpVec[i].find(
":") != std::string::npos)
165 std::vector<std::string> rasterVec;
166 boost::split(rasterVec, arithExpVec[i], boost::is_any_of(
":"));
169 for (
int j = 0; j <
m_ui->m_layersTableWidget->rowCount(); j++)
171 std::string header =
m_ui->m_layersTableWidget->verticalHeaderItem(j)->text().toUtf8().data();
172 if (rasterVec[0] == header)
178 m_ui->m_layersTableWidget->setRowCount(r + 1);
180 QTableWidgetItem* item =
new QTableWidgetItem(rasterVec[0].c_str());
181 m_ui->m_layersTableWidget->setVerticalHeaderItem(r, item);
183 QComboBox* layerComboBox =
new QComboBox(
m_ui->m_layersTableWidget);
186 QComboBox* bandComboBox =
new QComboBox(
m_ui->m_layersTableWidget);
196 m_ui->m_gainLineEdit->setEnabled(
true);
197 m_ui->m_gainLineEdit->setText(
"1");
201 m_ui->m_offsetLineEdit->setEnabled(
true);
202 m_ui->m_offsetLineEdit->setText(
"0");
206 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layerList.begin();
216 std::unique_ptr<te::da::DataSet>
ds = l->getData();
217 std::unique_ptr<te::da::DataSetType> dst = l->getSchema();
219 if (dst.get() && dst->hasRaster())
224 std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
226 int nbands =
static_cast<int>(inputRst->getNumberOfBands());
230 for (
int b = 0;
b < nbands;
b++)
239 m_layersComboBox[i]->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
254 m_ui->m_layersTableWidget->resizeColumnsToContents();
261 int nrows =
m_ui->m_layersTableWidget->rowCount();
262 for (
int i = 0; i < nrows; i++)
273 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
274 std::unique_ptr<te::da::DataSetType> dst = layer->getSchema();
276 if (dst.get() && dst->hasRaster())
279 std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
283 int nbands =
static_cast<int>(inputRst->getNumberOfBands());
285 for (
int i = 0; i < nbands; i++)
294 int index =
m_ui->m_operationComboBox->currentIndex();
296 std::string selectedOperation =
m_ui->m_operationComboBox->itemText(index).toUtf8().data();
298 int reply = QMessageBox::question(
this, tr(
"Arithmetic Operations"),
299 tr(
"The operation ") + QString::fromStdString(selectedOperation) + (
" will be removed from the list, are you certain?"),
300 QMessageBox::Yes | QMessageBox::No);
302 if(reply == QMessageBox::No)
309 QMessageBox::warning(
this, tr(
"Warning"), tr(
"The default operation can not be removed from the list."));
313 QString path = QString::fromStdString(
m_userPath) +
"/arithmeticOperations.json";
319 QMessageBox::warning(
this, tr(
"Warning"), tr(
"File not found."));
323 boost::property_tree::ptree pt;
325 boost::property_tree::json_parser::read_json(path.toUtf8().data(), pt);
327 for(boost::property_tree::ptree::value_type &v: pt.get_child(
"operations"))
329 std::string op = v.second.get<std::string>(
"operation");
332 pt.get_child(
"operations").erase(v.first);
335 boost::property_tree::write_json(path.toUtf8().data(), pt);
339 QMessageBox::information(
this, tr(
"Arithmetic Operation"), tr(
"The operation was deleted sucessfully."));
343 QMessageBox::warning(
this, tr(
"Warning"), tr(e.
what()));
348 QMessageBox::warning(
this, tr(
"Arithmetic Operations"), tr(
"An error has occurred."));
355 if (
m_ui->m_gainLineEdit->isEnabled() &&
m_ui->m_gainLineEdit->text().isEmpty())
357 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Gain value is not defined."));
361 if (
m_ui->m_offsetLineEdit->isEnabled() &&
m_ui->m_offsetLineEdit->text().isEmpty())
363 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Offset value is not defined."));
367 if(
m_ui->m_layersTableWidget->rowCount() != 0)
372 std::string operation =
m_ui->m_operationComboBox->currentText().toUtf8().data();
374 std::vector<std::string> arithExpVec;
375 boost::split(arithExpVec, operation, boost::is_any_of(
" "));
377 for (
int i = 0; i < static_cast<int>(arithExpVec.size()); i++)
382 m_operation +=
" " + std::string(
m_ui->m_gainLineEdit->text().toUtf8().data());
387 m_operation +=
" " + std::string(
m_ui->m_offsetLineEdit->text().toUtf8().data());
391 std::vector<std::string> layerVec;
392 boost::split(layerVec, arithExpVec[i], boost::is_any_of(
":"));
394 if (layerVec.size() == 1)
401 int nrows =
m_ui->m_layersTableWidget->rowCount();
403 for (
int j = 0; j < nrows; j++)
405 std::string header =
m_ui->m_layersTableWidget->verticalHeaderItem(j)->text().toUtf8().data();
407 if (header == layerVec[0])
410 m_mapLayer.insert(std::map<std::string, te::map::AbstractLayer*>::value_type(header,
m_layers[index].
get()));
413 m_operation +=
" " + std::string(
m_ui->m_layersTableWidget->verticalHeaderItem(j)->text().toUtf8().data()) +
":" +
m_bandsComboBox[j]->currentText().toUtf8().data();
429 QFile
file(QString::fromStdString(path));
434 bool isDefaultOperation =
false;
436 boost::property_tree::ptree pt;
438 boost::property_tree::json_parser::read_json(path, pt);
440 for(boost::property_tree::ptree::value_type &v: pt.get_child(
"operations"))
442 std::string op = v.second.get<std::string>(
"operation");
445 isDefaultOperation =
true;
448 return isDefaultOperation;
This file defines a class for a ArithmeticOp Dialog.
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
virtual const char * what() const
It outputs the exception message.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $