27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/Translator.h"
30 #include "../../common/STLUtils.h"
31 #include "../../dataaccess/datasource/DataSource.h"
32 #include "../../dataaccess/utils/Utils.h"
33 #include "../../geometry/GeometryProperty.h"
34 #include "../../maptools/DataSetLayer.h"
35 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
36 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
37 #include "../core/BayesGlobalOperation.h"
38 #include "../core/BayesParams.h"
39 #include "../core/Utils.h"
40 #include "../Exception.h"
43 #include "ui_BayesGlobalDialogForm.h"
46 #include <QFileDialog>
48 #include <QMessageBox>
55 #include <boost/filesystem.hpp>
62 m_ui(new Ui::BayesGlobalDialogForm)
70 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-bayesglobal-hint").pixmap(112,48));
71 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
80 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
81 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_bayesglobal.html");
90 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
92 while(it != layers.end())
98 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
102 if(dsLayer && dsType->hasGeom())
103 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
110 if(m_ui->m_inputLayerComboBox->count() > 0)
111 onInputLayerComboBoxActivated(0);
116 return m_outputLayer;
121 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
125 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
127 std::vector<te::dt::Property*> propVec = dsType->getProperties();
129 m_ui->m_attrEventComboBox->clear();
130 m_ui->m_attrPopComboBox->clear();
132 for(std::size_t t = 0; t < propVec.size(); ++t)
134 int dataType = propVec[t]->getType();
141 m_ui->m_attrEventComboBox->addItem(propVec[t]->getName().c_str(), dataType);
142 m_ui->m_attrPopComboBox->addItem(propVec[t]->getName().c_str(), dataType);
150 if(m_ui->m_repositoryLineEdit->text().isEmpty())
152 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
156 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
158 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
163 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
166 std::auto_ptr<te::da::DataSetType> dataSetType = l->getSchema();
167 std::auto_ptr<te::da::DataSet> dataSet = l->getData();
170 std::string dataSetName = m_ui->m_newLayerNameLineEdit->text().toStdString();
172 std::size_t idx = dataSetName.find(
".");
173 if (idx != std::string::npos)
174 dataSetName=dataSetName.substr(0,idx);
189 inParams->
m_ds = dataSet;
191 inParams->
m_eventAttrName = m_ui->m_attrEventComboBox->currentText().toStdString();
193 inParams->
m_rate = m_ui->m_rateComboBox->currentText().toDouble();
197 outParams->
m_ds = outputDataSource;
204 QApplication::setOverrideCursor(Qt::WaitCursor);
214 catch(
const std::exception& e)
216 QMessageBox::warning(
this, tr(
"Warning"), e.what());
218 QApplication::restoreOverrideCursor();
226 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error.Global Bayes not calculated."));
228 QApplication::restoreOverrideCursor();
235 QApplication::restoreOverrideCursor();
250 m_ui->m_newLayerNameLineEdit->clear();
251 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
256 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
258 if(dsPtrList.size() <= 0)
261 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
263 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
265 m_outputDatasource = *it;
272 m_ui->m_newLayerNameLineEdit->clear();
273 m_ui->m_repositoryLineEdit->clear();
275 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
277 if (fileName.isEmpty())
280 boost::filesystem::path outfile(fileName.toStdString());
282 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
284 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
286 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
293 m_ui->m_rateComboBox->clear();
295 m_ui->m_rateComboBox->addItem(
"1");
296 m_ui->m_rateComboBox->addItem(
"10");
297 m_ui->m_rateComboBox->addItem(
"100");
298 m_ui->m_rateComboBox->addItem(
"1000");
299 m_ui->m_rateComboBox->addItem(
"10000");
300 m_ui->m_rateComboBox->addItem(
"100000");
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void fillRateCorrection()
Class that represents the Bayes output parameters.
Utility functions for the data access module.
void onTargetFileToolButtonPressed()
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
boost::shared_ptr< DataSource > DataSourcePtr
TESAEXPORT te::da::DataSourcePtr CreateOGRDataSource(std::string repository)
A dialog to calculate the global empirical bayes of a dataset.
void execute()
Function to execute the bayes operation.
te::map::AbstractLayerPtr getOutputLayer()
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
std::string m_outputDataSetName
Attribute that defines the output dataset name.
void onInputLayerComboBoxActivated(int index)
BayesGlobalDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
TESAEXPORT void CreateBayesGrouping(te::map::AbstractLayerPtr layer)
void onTargetDatasourceToolButtonPressed()
Class used to execute the bayes global operations.
te::da::DataSourcePtr m_ds
Pointer to the output datasource.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
void setParameters(te::sa::BayesInputParams *inParams, te::sa::BayesOutputParams *outParams)
void onOkPushButtonClicked()
A layer with reference to a dataset.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::auto_ptr< Ui::BayesGlobalDialogForm > m_ui