27 #include "../../common/progress/ProgressManager.h" 
   28 #include "../../common/Logger.h" 
   29 #include "../../common/Translator.h" 
   30 #include "../../common/STLUtils.h" 
   31 #include "../../dataaccess/dataset/DataSetType.h" 
   32 #include "../../dataaccess/dataset/ObjectIdSet.h" 
   33 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 
   34 #include "../../dataaccess/datasource/DataSourceInfo.h" 
   35 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 
   36 #include "../../dataaccess/datasource/DataSourceFactory.h" 
   37 #include "../../dataaccess/datasource/DataSourceManager.h" 
   38 #include "../../dataaccess/utils/Utils.h" 
   39 #include "../../datatype/Enums.h" 
   40 #include "../../datatype/Property.h" 
   41 #include "../../maptools/AbstractLayer.h" 
   42 #include "../../qt/af/Utils.h" 
   43 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 
   44 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 
   45 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 
   46 #include "../../statistics/core/Utils.h" 
   47 #include "../Config.h" 
   48 #include "../Exception.h" 
   49 #include "../MultipartToSinglepart.h" 
   51 #include "ui_MultipartToSinglepartDialogForm.h" 
   55 #include <QFileDialog> 
   57 #include <QListWidget> 
   58 #include <QListWidgetItem> 
   59 #include <QMessageBox> 
   60 #include <QTreeWidget> 
   63 #include <boost/algorithm/string.hpp> 
   64 #include <boost/filesystem.hpp> 
   65 #include <boost/uuid/random_generator.hpp> 
   66 #include <boost/uuid/uuid_io.hpp> 
   72     m_ui(new Ui::MultipartToSinglepartDialogForm),
 
   81   m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-multiparttosinglepart-hint").pixmap(112,48));
 
   82   m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
 
   90   m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins"); 
 
   91   m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_multiparttosinglepart.html");
 
   94   m_ui->m_newLayerNameLineEdit->setEnabled(
true);
 
  105   std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
 
  107   while(it != m_layers.end())
 
  109     std::auto_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);
 
  127   m_selectedLayer = layer;
 
  129   std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toStdString();
 
  134   m_ui->m_newLayerNameLineEdit->clear();
 
  135   m_ui->m_newLayerNameLineEdit->setEnabled(
true);
 
  139   std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
 
  141   if(dsPtrList.size() <= 0)
 
  144   std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
 
  146   m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
 
  148   m_outputDatasource = *it;
 
  155   m_ui->m_newLayerNameLineEdit->clear();
 
  156   m_ui->m_repositoryLineEdit->clear();
 
  158   QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
 
  159                                                         QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
 
  161   if (fileName.isEmpty())
 
  164   boost::filesystem::path outfile(fileName.toStdString());
 
  165   std::string aux = outfile.leaf().string();
 
  166   m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
 
  167   aux = outfile.string();
 
  168   m_ui->m_repositoryLineEdit->setText(aux.c_str());
 
  171   m_ui->m_newLayerNameLineEdit->setEnabled(
false);
 
  176   QMessageBox::information(
this, 
"Help", 
"Under development");
 
  181   if(m_ui->m_layersComboBox->count() == 0)
 
  183     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Select an input layer."));
 
  191     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Can not execute this operation on this type of layer."));
 
  197   if(m_ui->m_onlySelectedCheckBox->isChecked())
 
  199     oidSet = m_selectedLayer->getSelected();
 
  202       QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"None selected object!"));
 
  208   if (!inDataSource.get())
 
  210     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"The selected input data source can not be accessed."));
 
  214   std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
 
  216   if(m_ui->m_repositoryLineEdit->text().isEmpty())
 
  218     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Define a repository for the result."));
 
  222   if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
 
  224     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), 
"Define a name for the resulting layer.");
 
  238       boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
 
  240       if (boost::filesystem::exists(uri))
 
  242         QMessageBox::information(
this, tr(
"Multipart To Singlepart"), 
"Output file already exists. Remove it or select a new name and try again.");
 
  246       std::size_t idx = outputdataset.find(
".");
 
  247       if (idx != std::string::npos)
 
  248         outputdataset=outputdataset.substr(0,idx);
 
  250       std::map<std::string, std::string> dsinfo;
 
  251       dsinfo[
"URI"] = uri.string();
 
  254       dsOGR->setConnectionInfo(dsinfo);
 
  256       if (dsOGR->dataSetExists(outputdataset))
 
  258         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.");
 
  262       this->setCursor(Qt::WaitCursor);
 
  273         this->setCursor(Qt::ArrowCursor);
 
  275         QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Error: could not operate."));
 
  283       boost::uuids::basic_random_generator<boost::mt19937> gen;
 
  284       boost::uuids::uuid u = gen();
 
  285       std::string id_ds = boost::uuids::to_string(u);
 
  288       ds->setConnInfo(dsinfo);
 
  289       ds->setTitle(uri.stem().string());
 
  290       ds->setAccessDriver(
"OGR");
 
  292       ds->setDescription(uri.string());
 
  298       m_outputDatasource = ds;
 
  305         QMessageBox::information(
this, tr(
"Multipart To Singlepart"), 
"The selected output datasource can not be accessed.");
 
  309       if (aux->dataSetExists(outputdataset))
 
  311         QMessageBox::information(
this, tr(
"Multipart To Singlepart"), 
"Dataset already exists. Remove it or select a new name and try again.");
 
  314       this->setCursor(Qt::WaitCursor);
 
  327         this->setCursor(Qt::ArrowCursor);
 
  328         QMessageBox::information(
this, tr(
"Multipart To Singlepart"), tr(
"Error: could not operate."));
 
  339     m_layer = converter(dt);
 
  341   catch(
const std::exception& e)
 
  343     this->setCursor(Qt::ArrowCursor);
 
  345     QMessageBox::information(
this, tr(
"Multipart To Singlepart"), e.what());
 
  347 #ifdef TERRALIB_LOGGER_ENABLED 
  348     std::string str = 
"Multipart To Singlepart - ";
 
  350     te::common::Logger::logDebug(
"vp", str.c_str());
 
  358   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. 
 
Utility functions for the data access module. 
 
const std::string & getDataSetName() const 
 
boost::shared_ptr< DataSetType > DataSetTypePtr
 
void onLayerComboBoxChanged(int index)
 
boost::shared_ptr< DataSource > DataSourcePtr
 
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information. 
 
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used. 
 
std::auto_ptr< Ui::MultipartToSinglepartDialogForm > m_ui
 
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
 
~MultipartToSinglepartDialog()
 
void removeViewer(int viewerId)
Dettach a progress viewer. 
 
static ProgressManager & getInstance()
It returns a reference to the singleton instance. 
 
const std::string & getDataSourceId() const 
 
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...
 
static std::auto_ptr< DataSource > make(const std::string &dsType)
 
te::map::AbstractLayerPtr getLayer()
Get the generated layer. 
 
MultipartToSinglepartDialog(QWidget *parent=0, Qt::WindowFlags f=0)
 
void onHelpPushButtonClicked()
 
void onTargetDatasourceToolButtonPressed()
 
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer. 
 
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsName, std::auto_ptr< te::da::DataSetType > inDsType, const te::da::ObjectIdSet *oidSet=0)
 
void onTargetFileToolButtonPressed()
 
A class that represents a data source component. 
 
A layer with reference to a dataset. 
 
std::auto_ptr< LayerSchema > getSchema() const 
It returns the layer schema. 
 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
 
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
 
void onCancelPushButtonClicked()