27 #include "../../../../common/Exception.h" 28 #include "../../../../common/StringUtils.h" 29 #include "../../../../common/progress/ProgressManager.h" 30 #include "../../../../common/progress/TaskProgress.h" 31 #include "../../../../core/filesystem/FileSystem.h" 32 #include "../../../../core/translator/Translator.h" 33 #include "../../../../dataaccess.h" 34 #include "../../../../geometry/GeometryProperty.h" 35 #include "../../../../maptools/DataSetLayer.h" 36 #include "../../../../qt/widgets/datasource/selector/DataSourceSelectorWidget.h" 37 #include "../../../../qt/widgets/datasource/selector/DataSourceSelectorWizardPage.h" 38 #include "../../../../qt/widgets/layer/utils/DataSet2Layer.h" 39 #include "../../../../qt/widgets/help/HelpPushButton.h" 40 #include "../../../../qt/widgets/progress/ProgressViewerDialog.h" 41 #include "../../../../qt/widgets/rp/Utils.h" 42 #include "../../../../qt/widgets/utils/ScopedCursor.h" 43 #include "../../../../qt/af/ApplicationController.h" 44 #include "../../../../qt/af/events/LayerEvents.h" 45 #include "../../../../raster/Utils.h" 46 #include "../../../../terralib4/DataSource.h" 47 #include "../../../../terralib4/ThemeInfo.h" 48 #include "../../../../se/ChannelSelection.h" 49 #include "../../../../se/ColorMap.h" 50 #include "../../../../se/FeatureTypeStyle.h" 51 #include "../../../../se/Fill.h" 52 #include "../../../../se/PolygonSymbolizer.h" 53 #include "../../../../se/RasterSymbolizer.h" 54 #include "../../../../se/Rule.h" 55 #include "../../../../se/SelectedChannel.h" 56 #include "../../../../se/Stroke.h" 57 #include "../../../../se/Style.h" 58 #include "../../../../se/Symbolizer.h" 59 #include "../../../../se/Utils.h" 67 #include "ui_TL4ConverterWizardForm.h" 68 #include "ui_TL4ConnectorWizardPageForm.h" 69 #include "ui_TL4LayerSelectionWizardPageForm.h" 70 #include "ui_TL4RasterFolderSelectionWizardPageForm.h" 71 #include "ui_TL4FinalPageWizardPageForm.h" 72 #include "ui_TL4ThemeSelectionWizardPageForm.h" 78 #include <boost/filesystem.hpp> 79 #include <boost/format.hpp> 80 #include <boost/lexical_cast.hpp> 84 #include <QMessageBox> 85 #include <QTableWidgetItem> 86 #include <QGridLayout> 89 #include <terralib4/kernel/TeLegendEntry.h> 90 #include <terralib4/kernel/TeRasterTransform.h> 91 #include <terralib4/kernel/TeTheme.h> 95 m_hasNonRaster(false),
98 m_ui(new
Ui::TL4ConverterWizardForm)
106 m_connectorPage->setSubTitle(tr(
"Connect to a TerraLib 4.x database."));
124 m_resolveNamePage->setSubTitle(tr(
"Some layer names clashes with target data source names. Please, give a new name for the layers showed below"));
130 displayLayout->setContentsMargins(0,0,0,0);
133 labels <<
"" << tr(
"Source Names") << tr(
"Target Names");
138 m_finalPage->setSubTitle(tr(
"Select the TerraLib 4.x Layer converted that you want to create a TerraLib 5 Project Layer."));
142 m_themeSelection->setSubTitle(tr(
"Select the TerraLib 4.x Theme of converted Layers that you want to create a TerraLib 5 Project Layer, with informations like Visual and Grouping."));
153 connect(this->button(QWizard::NextButton), SIGNAL(pressed()),
this, SLOT(
next()));
154 connect(this->button(QWizard::BackButton), SIGNAL(pressed()),
this, SLOT(
back()));
155 connect(this->button(QWizard::FinishButton), SIGNAL(pressed()),
this, SLOT(
finish()));
156 connect(this->button(QWizard::CommitButton), SIGNAL(pressed()),
this, SLOT(
commit()));
160 this->setButton(QWizard::HelpButton, helpButton);
207 int current_page_id = currentId();
216 std::vector<std::string> layers = tl4Ds->
getTL4Layers();
218 std::vector<std::string> tables = tl4Ds->
getTL4Tables();
258 bool hasConflicts =
false;
260 for(std::size_t i = 0; i < selectedLayerItems.size(); ++i)
262 std::string targetDatasetName = selectedLayerItems[i]->text().toUtf8().data();
265 std::unique_ptr<te::da::DataSetType> input_dataset_type(
m_tl4Database->getDataSetType(selectedLayerItems[i]->text().toUtf8().data()));
267 if(input_dataset_type->hasRaster())
269 QTableWidgetItem *conflictItem = 0;
275 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"delete"),
"");
279 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
282 conflictItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
288 QTableWidgetItem *conflictItem = 0;
290 std::string targetDatasetNameAux = targetDatasetName;
292 if(tl5ds->getType() ==
"POSTGIS")
297 if(tl5ds->dataSetExists(targetDatasetNameAux))
301 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"delete"),
"");
305 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
308 conflictItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
312 QTableWidgetItem *oldNameItem =
new QTableWidgetItem(selectedLayerItems[i]->text(), selectedLayerItems[i]->type());
313 oldNameItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
316 bool changed =
false;
320 targetDatasetName = strChanged;
322 QTableWidgetItem *newNameItem =
new QTableWidgetItem(targetDatasetName.c_str(), selectedLayerItems[i]->type());
332 m_resolveNamePage->setSubTitle(tr(
"Some layer names clash with target data source dataset names. Please, give a new name for the layers showed below"));
337 m_resolveNamePage->setSubTitle(tr(
"You can change the layer names in the target data source"));
341 catch(
const te::da::Exception& e)
343 QMessageBox::warning(
this, tr(
"Warning"), e.what());
348 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid this page!"));
357 setCursor(Qt::WaitCursor);
361 if (connInfo.empty())
363 setCursor(Qt::ArrowCursor);
364 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid connection parameters!"));
374 catch(
const te::da::Exception& e)
376 setCursor(Qt::ArrowCursor);
377 QMessageBox::warning(
this, tr(
"Warning"), e.what());
382 setCursor(Qt::ArrowCursor);
383 QMessageBox::warning(
this, tr(
"Warning"), tr(
"A connection to the informed Terralib 4.x database could not be established. Please, verify the informed parameters."));
386 setCursor(Qt::ArrowCursor);
396 QMessageBox::warning(
this,
398 tr(
"Please, select at least one layer for conversion!"));
412 for(std::size_t i = 0; i < layersNames.size(); ++i)
414 std::unique_ptr<te::da::DataSetType> dst(
m_tl4Database->getDataSetType(layersNames[i]));
422 catch(
const te::da::Exception& e)
424 QMessageBox::warning(
this, tr(
"Warning"), e.what());
429 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid layer selection!"));
438 bool hasConflict =
false;
448 catch(
const te::da::Exception& e)
450 QMessageBox::warning(
this, tr(
"Warning"), e.what());
455 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
461 for(
int i = 0; i != nrows; ++i)
469 std::string sourceName = item_source->text().toUtf8().data();
477 std::string targetName = item_target->text().toUtf8().data();
484 std::unique_ptr<te::da::DataSetType> input_dataset_type(
m_tl4Database->getDataSetType(sourceName));
486 if(input_dataset_type->hasRaster())
495 QTableWidgetItem *nonconflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
503 std::string targetDatasetNameAux = targetName;
505 if(tl5ds->getType() ==
"POSTGIS")
510 if(tl5ds->dataSetExists(targetDatasetNameAux))
516 QTableWidgetItem *nonconflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
522 catch(
const te::da::Exception& e)
524 QMessageBox::warning(
this, tr(
"Warning"), e.what());
529 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid layer names in target data source!"));
536 QString errMsg(tr(
"There still have name conflicts. Please, resolve the indicated conflicts before continue!"));
538 QMessageBox::warning(
this, tr(
"TerraLib 4.x Converter"), errMsg);
550 for(
int i = 0; i < rowCount; ++i)
555 std::string originalFromTable = originalNameInTable.toUtf8().data();
556 std::string targetFromTable = targetNameInTable.toUtf8().data();
558 if (targetFromTable == targetName)
559 return originalFromTable;
569 for(
int i = 0; i < rowCount; ++i)
573 std::string aux = oName.toUtf8().data();
575 if(originalName.c_str() == aux)
602 std::vector<std::pair<std::string, std::string> > problematicDatasets;
606 std::pair<std::string, std::string> dproblem;
610 problematicDatasets.push_back(dproblem);
615 std::vector<std::string> successfulDatasets;
624 catch(
const te::da::Exception& e)
627 QMessageBox::warning(
this, tr(
"Warning"), e.what());
633 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
647 for(
int i = 0; i != nrows; ++i)
658 std::string sourceName = item_source->text().toUtf8().data();
669 std::string targetName = item_target->text().toUtf8().data();
676 std::unique_ptr<te::da::DataSetType> input_dataset_type(
m_tl4Database->getDataSetType(sourceName));
678 if(input_dataset_type->hasRaster())
681 std::unique_ptr<te::da::DataSet>
ds =
m_tl4Database->getDataSet(sourceName);
683 std::unique_ptr<te::rst::Raster> raster = ds->getRaster(
"Raster");
689 successfulDatasets.push_back(targetName);
694 input_dataset_type->setName(targetName);
696 if (input_dataset_type->size() == 1 && input_dataset_type->getProperty(0)->getName() ==
"spatial_data")
698 std::pair<std::string, std::string> dproblem;
699 dproblem.first = sourceName;
700 dproblem.second =
TE_TR(
"Layer invalid: table without attributes!");
702 problematicDatasets.push_back(dproblem);
707 std::unique_ptr<te::da::DataSetTypeConverter> dt_adapter(
new te::da::DataSetTypeConverter(input_dataset_type.get(), tl5ds->getCapabilities()));
709 std::unique_ptr<te::da::DataSet>
ds(
m_tl4Database->getDataSet(sourceName));
713 const std::vector<std::vector<std::size_t> >& indexes = dt_adapter->getConvertedPropertyIndexes();
714 const std::vector<te::da::AttributeConverter>& funcs = dt_adapter->getConverters();
726 for(std::size_t i = 0; i < type->
size(); ++i)
730 ds_adapter->add(p->
getName(), p->
getType(), indexes[i], funcs[i]);
739 std::map<std::string, std::string> opt;
741 ds_adapter->moveBeforeFirst();
743 te::da::Create(tl5ds.get(), dt_adapter->getResult(), ds_adapter.get(), opt);
745 successfulDatasets.push_back(targetName);
750 std::pair<std::string, std::string> dproblem;
751 dproblem.first = sourceName;
752 dproblem.second = e.
what();
754 problematicDatasets.push_back(dproblem);
756 catch(std::exception& e)
758 std::pair<std::string, std::string> dproblem;
759 dproblem.first = sourceName;
760 dproblem.second = e.what();
762 problematicDatasets.push_back(dproblem);
766 std::pair<std::string, std::string> dproblem;
767 dproblem.first = sourceName;
768 dproblem.second =
TE_TR(
"unknown problem in conversion!");
770 problematicDatasets.push_back(dproblem);
783 if(!problematicDatasets.empty())
785 QString error(tr(
"Some TerraLib 4.x Layers could not be converted: \n\n"));
788 for(std::size_t i = 0; i < problematicDatasets.size(); ++i)
790 error.append(QString(
" - ") + problematicDatasets[i].first.c_str() + QString(
""));
791 details.append(problematicDatasets[i].first.c_str() + QString(
":\n"));
792 details.append(problematicDatasets[i].second.c_str() + QString(
"\n\n"));
795 QMessageBox message(QMessageBox::Warning, tr(
"TerraLib 4.x Converter"), error, QMessageBox::Ok,
this);
796 message.setDetailedText(details);
806 std::vector<::terralib4::ThemeInfo> themes = tl4Ds->
getTL4Themes();
808 std::vector<::terralib4::ThemeInfo> convertedThemes;
809 for (std::size_t i = 0; i < successfulDatasets.size(); ++i)
811 std::string originalLayerName =
getOriginalName(successfulDatasets[i]);
813 for (std::size_t j = 0; j < themes.size(); ++j)
815 std::string themeLayerName = themes[j].m_layerName;
817 if (themeLayerName == originalLayerName)
819 convertedThemes.push_back(themes[j]);
833 std::vector<std::string> selected =
m_finalPage->getSelected();
842 catch(
const te::da::Exception& e)
845 QMessageBox::warning(
this, tr(
"Warning"), e.what());
851 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
858 setCursor(Qt::WaitCursor);
860 for(std::size_t i = 0; i < selected.size(); ++i)
866 if(sourceDt->hasRaster())
868 std::map<std::string, std::string> connInfo;
877 std::unique_ptr<te::da::DataSetType> dsType = outDataSource->getDataSetType(selected[i]);
881 layer = converter(
dt);
891 for(std::size_t i = 0; i < themes.size(); ++i)
895 std::string newName =
getNewName(themes[i].m_layerName);
897 std::unique_ptr<te::da::DataSetType> sourceDt =
m_tl4Database->getDataSetType(themes[i].m_layerName);
905 if(sourceDt->hasRaster())
907 std::map<std::string, std::string> connInfo;
911 layer->setTitle(theme->name());
916 if(theme->grouping().groupMode_ != TeNoGrouping)
924 std::string
band =
"0";
948 std::unique_ptr<te::da::DataSetType> dst = outDataSource->getDataSetType(
getNewName(themes[i].m_layerName));
954 layer = converter(dstPtr);
963 if(theme->grouping().groupMode_ != TeNoGrouping)
967 layer->setStyle(style);
974 catch(
const te::da::Exception& e)
976 setCursor(Qt::ArrowCursor);
978 QMessageBox::warning(
this, tr(
"Warning"), e.what());
983 setCursor(Qt::ArrowCursor);
985 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Automatic layer creation failed!"));
989 setCursor(Qt::ArrowCursor);
994 QMessageBox::warning(
this,
995 tr(
"TerraLib 4.x Converter"),
996 tr(
"This option is not implemented yet!\nWe will provide it soon!"));
virtual void setName(const std::string &name)
It sets the constraint name.
Property * getProperty(std::size_t i) const
It returns the i-th property.
This event signals that a new layer was created.
te::map::Grouping * GetGrouping(TeTheme *theme, te::se::Style *style)
A selected channel to be display.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
std::unique_ptr< Ui::TL4ConverterWizardForm > m_ui
te::color::RGBAColor Convert2TerraLib5(TeColor color)
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
std::string getNewName(const std::string &originalName)
std::unique_ptr< TL4ConnectorWizardPage > m_connectorPage
boost::shared_ptr< DataSource > DataSourcePtr
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A class that models the description of a dataset.
virtual const char * what() const
It outputs the exception message.
void useTimer(bool flag)
Used to define if task use progress timer information.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster &rin, const std::string &uri, const std::string &rType=std::string("GDAL"))
Create a new raster from existing one.
std::vector< std::string > getTL4Rasters()
This class can be used to inform the progress of a task.
bool validateCurrentPage()
std::unique_ptr< TL4FinalPageWizardPage > m_finalPage
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
te::se::ChannelSelection * getChannelSelection() const
void setGrayChannel(SelectedChannel *c)
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
It models a property definition.
bool isActive() const
Verify if the task is active.
std::vector< std::pair< std::string, std::string > > m_rasterFiles
void setTotalSteps(int value)
Set the task total stepes.
An converter for DataSetType.
A wizard page that provides the capability of connecting to a TerraLib 4.x database.
std::string m_rasterFolderPath
void removeViewer(int viewerId)
Dettach a progress viewer (AbstractProgressViewer destructor calls this method).
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
void setColorCompositionType(ColorCompositionType cct)
std::unique_ptr< te::da::DataSource > m_tl4Database
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::unique_ptr< QWizardPage > m_resolveNamePage
void triggered(te::qt::af::evt::Event *e)
std::vector< std::pair< std::string, std::string > > getTL4RasterFiles()
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
te::da::DataSourceInfoPtr m_targetDataSource
std::size_t size() const
It returns the number of properties of the CompositeProperty.
std::vector< std::string > getTL4Tables()
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
int getType() const
It returns the property data type.
std::vector<::terralib4::ThemeInfo > getTL4Themes()
std::unique_ptr< te::qt::widgets::DataSourceSelectorWizardPage > m_datasourceSelectorPage
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
It describes a primary key (pk) constraint.
void setColorMap(ColorMap *c)
void setSourceChannelName(const std::string &name)
int getLayerSRID(const std::string &layerName)
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo &theme)
bool validTerraLib4Connection()
TL4ConverterWizard(QWidget *parent=0, Qt::WindowFlags f=0)
bool validLayerSelection()
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::se::ColorMap * GetRasterGrouping(TeTheme *theme)
std::unique_ptr< QTableWidget > m_resolveNameTableWidget
SelectedChannel * getGrayChannel() const
std::unique_ptr< TL4LayerSelectionWizardPage > m_layerSelectionPage
std::string getOriginalName(const std::string &targetName)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
std::unique_ptr< TL4RasterFolderSelectionWizardPage > m_rasterFolderSelectionPage
std::unique_ptr< TL4ThemeSelectionWizardPage > m_themeSelection
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...
std::vector< std::string > getTL4Layers()
const std::string & getName() const
It returns the property name.