27 #include "../../common/progress/ProgressManager.h" 28 #include "../../core/filesystem/FileSystem.h" 29 #include "../../core/logger/Logger.h" 30 #include "../../core/translator/Translator.h" 31 #include "../../common/STLUtils.h" 32 #include "../../dataaccess/dataset/DataSetType.h" 33 #include "../../dataaccess/dataset/ObjectIdSet.h" 34 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 35 #include "../../dataaccess/datasource/DataSourceInfo.h" 36 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 37 #include "../../dataaccess/datasource/DataSourceFactory.h" 38 #include "../../dataaccess/datasource/DataSourceManager.h" 39 #include "../../dataaccess/utils/Utils.h" 40 #include "../../datatype/Enums.h" 41 #include "../../datatype/Property.h" 42 #include "../../maptools/AbstractLayer.h" 43 #include "../../qt/af/Utils.h" 44 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 45 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 46 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 47 #include "../../qt/widgets/utils/FileDialog.h" 48 #include "../../statistics/core/Utils.h" 49 #include "../Config.h" 50 #include "../Exception.h" 51 #include "../MultipartToSinglepart.h" 53 #include "ui_MultipartToSinglepartDialogForm.h" 57 #include <QFileDialog> 59 #include <QListWidget> 60 #include <QListWidgetItem> 61 #include <QMessageBox> 62 #include <QTreeWidget> 65 #include <boost/algorithm/string.hpp> 66 #include <boost/filesystem.hpp> 67 #include <boost/uuid/random_generator.hpp> 68 #include <boost/uuid/uuid_io.hpp> 72 te::vp::MultipartToSinglepartDialog::MultipartToSinglepartDialog(
QWidget* parent, Qt::WindowFlags f)
74 m_ui(new
Ui::MultipartToSinglepartDialogForm),
76 m_selectedLayer(
nullptr),
83 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-multiparttosinglepart-hint").pixmap(112,48));
84 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
86 connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onLayerComboBoxChanged(
int)));
87 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
88 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
89 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
90 connect(m_ui->m_cancelPushButton, SIGNAL(clicked()),
this, SLOT(onCancelPushButtonClicked()));
92 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
93 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_multiparttosinglepart.html");
96 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
105 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
109 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
110 if(dsType->hasGeom())
111 m_ui->m_layersComboBox->addItem(it->get()->getTitle().c_str(), QVariant(QVariant::fromValue(*it)));
124 QVariant varLayer =
m_ui->m_layersComboBox->itemData(index, Qt::UserRole);
132 m_ui->m_newLayerNameLineEdit->clear();
133 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
137 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
139 if(dsPtrList.empty())
142 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
144 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
153 m_ui->m_newLayerNameLineEdit->clear();
154 m_ui->m_repositoryLineEdit->clear();
162 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
166 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
167 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
170 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
175 if(
m_ui->m_layersComboBox->count() == 0)
177 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Select an input layer."));
185 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Can not execute this operation on this type of layer."));
191 if(
m_ui->m_onlySelectedCheckBox->isChecked())
196 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"None selected object!"));
202 if (!inDataSource.get())
204 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"The selected input data source can not be accessed."));
208 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
210 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
212 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Define a repository for the result."));
216 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
218 QMessageBox::information(
this, tr(
"Multipart To Singlepart"),
"Define a name for the resulting layer.");
231 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
235 QMessageBox::information(
this, tr(
"Multipart To Singlepart"),
"Output file already exists. Remove it or select a new name and try again.");
239 std::size_t idx = outputdataset.find(
".");
240 if (idx != std::string::npos)
241 outputdataset=outputdataset.substr(0,idx);
243 std::string dsinfo(
"file://");
244 dsinfo += uri.string();
248 if (dsOGR->dataSetExists(outputdataset))
250 QMessageBox::information(
this, tr(
"Multipart To Singlepart"),
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
254 this->setCursor(Qt::WaitCursor);
265 this->setCursor(Qt::ArrowCursor);
267 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Error: could not operate."));
275 boost::uuids::basic_random_generator<boost::mt19937> gen;
276 boost::uuids::uuid u = gen();
277 std::string id_ds = boost::uuids::to_string(u);
280 ds->setConnInfo(dsinfo);
281 ds->setTitle(uri.stem().string());
282 ds->setAccessDriver(
"OGR");
284 ds->setDescription(uri.string());
297 QMessageBox::information(
this, tr(
"Multipart To Singlepart"),
"The selected output datasource can not be accessed.");
301 if (aux->dataSetExists(outputdataset))
303 QMessageBox::information(
this, tr(
"Multipart To Singlepart"),
"Dataset already exists. Remove it or select a new name and try again.");
306 this->setCursor(Qt::WaitCursor);
319 this->setCursor(Qt::ArrowCursor);
320 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Error: could not operate."));
333 catch(
const std::exception& e)
335 this->setCursor(Qt::ArrowCursor);
337 QMessageBox::information(
this, tr(
"Multipart To Singlepart"), e.what());
339 std::string str =
"Vector Processing - Multipart To Singlepart - ";
346 this->setCursor(Qt::ArrowCursor);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
A Multipart to Singlepart operation dialog.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
void onLayerComboBoxChanged(int index)
boost::shared_ptr< DataSource > DataSourcePtr
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
virtual const char * what() const
It outputs the exception message.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
static te::dt::Date ds(2010, 01, 01)
~MultipartToSinglepartDialog()
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void setOutput(te::da::DataSourcePtr outDsrc, std::string outDsName)
void onOkPushButtonClicked()
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsName, std::unique_ptr< te::da::DataSetType > inDsType, const te::da::ObjectIdSet *oidSet=0)
te::map::AbstractLayerPtr m_layer
Generated Layer.
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void onTargetDatasourceToolButtonPressed()
const std::string & getDataSetName() const
void onTargetFileToolButtonPressed()
std::unique_ptr< Ui::MultipartToSinglepartDialogForm > m_ui
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
A class that represents a data source component.
te::map::AbstractLayerPtr m_selectedLayer
Layer used for operation.
A layer with reference to a dataset.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual const std::string & getDataSourceId() const
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void onCancelPushButtonClicked()