DirectExchangerDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/exchanger/DirectExchangerDialog.h
22 
23  \brief A direct exchanger dialog for ADO, POSTGIS and SHP data sources
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSetAdapter.h"
29 #include "../../../dataaccess/dataset/PrimaryKey.h"
30 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../../../dataaccess/datasource/DataSourceFactory.h"
32 #include "../../../dataaccess/datasource/DataSourceInfo.h"
33 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
34 #include "../../../dataaccess/datasource/DataSourceManager.h"
35 #include "../../../dataaccess/datasource/DataSourceTransactor.h"
36 #include "../../../dataaccess/utils/Utils.h"
37 #include "../../../geometry/GeometryProperty.h"
38 #include "../../../maptools/DataSetLayer.h"
39 #include "../../../srs/Config.h"
40 #include "../../widgets/datasource/selector/DataSourceExplorerDialog.h"
41 #include "../../widgets/datasource/core/DataSourceType.h"
42 #include "../../widgets/datasource/core/DataSourceTypeManager.h"
43 #include "../../widgets/srs/SRSManagerDialog.h"
44 #include "DirectExchangerDialog.h"
45 #include "ui_DirectExchangerDialogForm.h"
46 
47 // Qt
48 #include <QFileDialog>
49 #include <QMessageBox>
50 
51 // Boost
52 #include <boost/algorithm/string/replace.hpp>
53 #include <boost/filesystem.hpp>
54 #include <boost/lexical_cast.hpp>
55 #include <boost/uuid/random_generator.hpp>
56 #include <boost/uuid/uuid_io.hpp>
57 
58 
61 
63  : QDialog(parent, f),
64  m_ui(new Ui::DirectExchangerDialogForm)
65 {
66 // setup widget
67  m_ui->setupUi(this);
68 
69 // add icons
70  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme("data-exchange-direct-hint").pixmap(112,48));
71  m_ui->m_dsToolButton->setIcon(QIcon::fromTheme("datasource"));
72 
73 //connectors
74  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
75  connect(m_ui->m_dirToolButton, SIGNAL(clicked()), this, SLOT(onDirToolButtonClicked()));
76  connect(m_ui->m_dsToolButton, SIGNAL(clicked()), this, SLOT(onDataSoruceToolButtonClicked()));
77  connect(m_ui->m_dsTypeComboBox, SIGNAL(activated(int)), this, SLOT(onDataSourceTypeActivated(int)));
78  connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(QString)), this, SLOT(onInputLayerActivated(QString)));
79  connect(m_ui->m_outputSRIDToolButton, SIGNAL(clicked()), SLOT(onOutputLayerSRSTriggered()));
80 
81  m_ui->m_outputSRIDToolButton->setIcon(QIcon::fromTheme("srs"));
82  m_ui->m_helpPushButton->setPageReference("widgets/exchanger_direct/exchanger_direct.html");
83 
84  //starup interface
86  m_exchangeToFile = false;
87  m_lastDsType = "";
88 
90 }
91 
93 {
94 }
95 
96 void te::qt::widgets::DirectExchangerDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
97 {
98  m_layers = layers;
99 
100  m_ui->m_inputLayerComboBox->clear();
101 
102  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
103 
104  while(it != m_layers.end())
105  {
107 
108  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
109 
110  if(dsType.get() && !dsType->hasRaster())
111  m_ui->m_inputLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
112 
113  ++it;
114  }
115 
116  if(m_ui->m_inputLayerComboBox->count() > 0)
117  {
118  QString s = m_ui->m_inputLayerComboBox->currentText();
119 
120  onInputLayerActivated(s);
121  }
122 
123  if(m_ui->m_inputLayerComboBox->count() > 1)
124  m_ui->m_inputLayerComboBox->setEnabled(true);
125 }
126 
128 {
129  m_lastDsType = dataSource;
130 }
131 
133 {
134  m_ui->m_outputDataSourceComboBox->clear();
135 
136  std::vector<te::da::DataSourceInfoPtr> datasources;
137 
138  te::da::DataSourceInfoManager::getInstance().getByType(m_outputDataSourceType, datasources);
139 
140  for(std::size_t i = 0; i < datasources.size(); ++i)
141  {
142  const te::da::DataSourceInfoPtr& datasource = datasources[i];
143 
144  if(datasource.get() == 0)
145  continue;
146 
147  const std::string& title = datasource->getTitle();
148 
149  m_ui->m_outputDataSourceComboBox->addItem(title.c_str(), QVariant::fromValue(datasource));
150  }
151 }
152 
154 {
155  int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
156 
157  if(idxLayer == -1)
158  {
159  QMessageBox::warning(this, tr("Warning"), tr("Input layer not selected."));
160  return false;
161  }
162 
163  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
164  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
165 
166  if(!layer.get())
167  {
168  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
169  return false;
170  }
171 
172  if(m_ui->m_dataSetLineEdit->text().isEmpty())
173  {
174  QMessageBox::warning(this, tr("Warning"), tr("Output File Name not defined."));
175  return false;
176  }
177 
178  //get srid information
179  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
180 
181  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
182 
183  try
184  {
185  //create adapter
186  std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
187 
188  //create data source
189  std::map<std::string, std::string> connInfo;
190  connInfo["URI"] = m_ui->m_dataSetLineEdit->text().toStdString();
191 
192  std::auto_ptr<te::da::DataSource> dsOGR = te::da::DataSourceFactory::make(m_outputDataSourceType);
193  dsOGR->setConnectionInfo(connInfo);
194  dsOGR->open();
195 
196  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(dsType.get(), dsOGR->getCapabilities(), dsOGR->getEncoding());
197 
198  te::da::AssociateDataSetTypeConverterSRID(converter, inputSRID, outputSRID);
199 
200  te::da::DataSetType* dsTypeResult = converter->getResult();
201 
202  boost::filesystem::path uri(m_ui->m_dataSetLineEdit->text().toStdString());
203 
204  std::string val = uri.stem().string();
205 
206  dsTypeResult->setName(val);
207 
208  // Check dataset name
209  if(!dsOGR->isDataSetNameValid(dsTypeResult->getName()))
210  {
211  int r = QMessageBox::question(this, tr("Exchanger"), tr("Layer name invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
212 
213  if(r == QMessageBox::Yes)
214  {
215  bool aux;
216  std::string newName = te::common::ReplaceSpecialChars(dsTypeResult->getName(), aux);
217  dsTypeResult->setName(newName);
218  }
219  else
220  {
221  throw te::common::Exception(tr("Layer name invalid for output datasource!").toStdString());
222  }
223  }
224 
225  // Check properties names
226  std::vector<te::dt::Property* > props = dsTypeResult->getProperties();
227  std::map<std::size_t, std::string> invalidNames;
228  for(std::size_t i = 0; i < props.size(); ++i)
229  {
230  if(!dsOGR->isPropertyNameValid(props[i]->getName()))
231  {
232  invalidNames[i] = props[i]->getName();
233  }
234  }
235 
236  if(!invalidNames.empty())
237  {
238  int r = QMessageBox::question(this, tr("Exchanger"), tr("Some property name is invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
239 
240  if(r == QMessageBox::Yes)
241  {
242  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
243 
244  while(it != invalidNames.end())
245  {
246  bool aux;
247  std::string newName = te::common::ReplaceSpecialChars(it->second, aux);
248 
249  props[it->first]->setName(newName);
250 
251  ++it;
252  }
253  }
254  else
255  {
256  QString err(tr("Some property name is invalid for output datasource:\n\n"));
257 
258  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
259 
260  while(it != invalidNames.end())
261  {
262  err.append(" - ");
263  err.append(it->second.c_str());
264 
265  ++it;
266  }
267 
268  throw te::common::Exception(err.toStdString());
269  }
270  }
271 
272  //exchange
273  std::map<std::string,std::string> nopt;
274 
275  std::auto_ptr<te::da::DataSet> dataset = layer->getData();
276 
277  dsOGR->createDataSet(dsTypeResult, nopt);
278 
279  std::auto_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(dataset.get(), converter));
280 
281  if(dataset->moveBeforeFirst())
282  dsOGR->add(dsTypeResult->getName(), dsAdapter.get(), dsOGR->getConnectionInfo());
283 
284  dsOGR->close();
285 
286  QMessageBox::information(this, tr("Exchanger"), tr("Layer exported successfully."));
287  }
288  catch(const std::exception& e)
289  {
290  QString errMsg(tr("Error during exchanger. The reported error is: %1"));
291 
292  errMsg = errMsg.arg(e.what());
293 
294  QMessageBox::information(this, tr("Exchanger"), errMsg);
295 
296  return false;
297  }
298 
299  return true;
300 }
301 
303 {
304  int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
305 
306  if(idxLayer == -1)
307  {
308  QMessageBox::warning(this, tr("Warning"), tr("Input layer not selected."));
309  return false;
310  }
311 
312  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
313  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
314 
315  if(!layer.get())
316  {
317  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
318  return false;
319  }
320 
321  int idxDataSource = m_ui->m_outputDataSourceComboBox->currentIndex();
322 
323  if(idxLayer == -1)
324  {
325  QMessageBox::warning(this, tr("Warning"), tr("Output data source not selected."));
326  return false;
327  }
328 
329  QVariant varDataSource = m_ui->m_outputDataSourceComboBox->itemData(idxDataSource, Qt::UserRole);
330  te::da::DataSourceInfoPtr dsInfo = varDataSource.value<te::da::DataSourceInfoPtr>();
331 
332  if(!dsInfo.get())
333  {
334  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected data source."));
335  return false;
336  }
337 
338  if(m_ui->m_dataSetLineEdit->text().isEmpty())
339  {
340  QMessageBox::warning(this, tr("Warning"), tr("Data Set name not defined."));
341  return false;
342  }
343 
344  //get srid information
345  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
346 
347  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
348 
349  std::auto_ptr<te::da::DataSourceTransactor> transactor;
350 
351  try
352  {
353  setCursor(Qt::WaitCursor);
354 
355  //create adapter
356  std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
357 
358  bool isLinked = te::da::HasLinkedTable(dsType.get());
359 
360  if (isLinked)
361  {
362  te::da::PrimaryKey* pk = dsType->getPrimaryKey();
363 
364  if (pk)
365  {
366  std::vector<te::dt::Property*> props = pk->getProperties();
367 
368  for (size_t t = 0; t < props.size(); ++t)
369  {
370  te::dt::SimpleProperty* p = dynamic_cast<te::dt::SimpleProperty*>(props[t]);
371 
372  if (p)
373  {
374  p->setRequired(false);
375  p->setAutoNumber(false);
376  p->setDefaultValue(0);
377  }
378  }
379 
380  dsType->setPrimaryKey(0);
381  }
382  }
383 
384  te::da::DataSourcePtr targetDSPtr = te::da::DataSourceManager::getInstance().get(dsInfo->getId(), dsInfo->getType(), dsInfo->getConnInfo());
385 
386  transactor = targetDSPtr->getTransactor();
387 
388  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(dsType.get(), targetDSPtr->getCapabilities(), targetDSPtr->getEncoding());
389 
390  te::da::AssociateDataSetTypeConverterSRID(converter, inputSRID, outputSRID);
391 
392  te::da::DataSetType* dsTypeResult = converter->getResult();
393 
394  dsTypeResult->setName(m_ui->m_dataSetLineEdit->text().toStdString());
395 
396  // Check dataset name
397  if(!targetDSPtr->isDataSetNameValid(dsTypeResult->getName()))
398  {
399  int r = QMessageBox::question(this, tr("Exchanger"), tr("Layer name invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
400 
401  if(r == QMessageBox::Yes)
402  {
403  bool aux;
404  std::string newName = te::common::ReplaceSpecialChars(dsTypeResult->getName(), aux);
405  dsTypeResult->setName(newName);
406  }
407  else
408  {
409  throw te::common::Exception(tr("Layer name invalid for output datasource!").toStdString());
410  }
411  }
412 
413  // Check properties names
414  std::vector<te::dt::Property* > props = dsTypeResult->getProperties();
415  std::map<std::size_t, std::string> invalidNames;
416  for(std::size_t i = 0; i < props.size(); ++i)
417  {
418  if(!targetDSPtr->isPropertyNameValid(props[i]->getName()))
419  {
420  invalidNames[i] = props[i]->getName();
421  }
422  }
423 
424  if(!invalidNames.empty())
425  {
426  int r = QMessageBox::question(this, tr("Exchanger"), tr("Some property name is invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
427 
428  if(r == QMessageBox::Yes)
429  {
430  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
431 
432  while(it != invalidNames.end())
433  {
434  bool aux;
435  std::string newName = te::common::ReplaceSpecialChars(it->second, aux);
436 
437  props[it->first]->setName(newName);
438 
439  ++it;
440  }
441  }
442  else
443  {
444  QString err(tr("Some property name is invalid for output datasource:\n\n"));
445 
446  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
447 
448  while(it != invalidNames.end())
449  {
450  err.append(" - ");
451  err.append(it->second.c_str());
452 
453  ++it;
454  }
455 
456  throw te::common::Exception(err.toStdString());
457  }
458  }
459 
460  //fix repeated names
461  std::set<std::string> names;
462 
463  props = dsTypeResult->getProperties();
464 
465  for (std::size_t i = 0; i < props.size(); ++i)
466  {
467  //check if the property name its duplicated
468  std::string propName = props[i]->getName();
469 
470  int count = 1;
471  while (names.find(te::common::Convert2UCase(propName)) != names.end())
472  {
473  propName += "_";
474  propName += te::common::Convert2String(count);
475  }
476 
477  names.insert(te::common::Convert2UCase(propName));
478 
479  props[i]->setName(propName);
480  }
481 
482  //create index
483  if(m_ui->m_spatialIndexCheckBox->isChecked())
484  {
486 
487  if(p)
488  {
489  te::da::Index* idx = new te::da::Index(dsTypeResult);
490 
491  std::string name = m_ui->m_dataSetLineEdit->text().toStdString() + "_" + p->getName() + "_idx";
492 
493  boost::replace_all(name, ".", "_");
494 
495  idx->setName(name);
497 
498  te::dt::Property* pClone = p->clone();
499 
500  idx->add(pClone);
501  }
502  }
503 
504  if (!isLinked)
505  {
506  //create primary key
507  if (dsType->getPrimaryKey())
508  {
509  te::da::PrimaryKey* pk = new te::da::PrimaryKey(dsTypeResult);
510 
511  std::string name = m_ui->m_dataSetLineEdit->text().toStdString() + "_" + dsType->getPrimaryKey()->getName() + "_pk";
512 
513  boost::replace_all(name, ".", "_");
514 
515  pk->setName(name);
516 
517  std::vector<te::dt::Property*> props = dsType->getPrimaryKey()->getProperties();
518 
519  for (size_t t = 0; t < props.size(); ++t)
520  {
521  te::dt::Property* p = props[t]->clone();
522 
523  pk->add(p);
524  }
525  }
526  }
527 
528  //exchange
529  std::map<std::string,std::string> nopt;
530 
531  std::auto_ptr<te::da::DataSet> dataset = layer->getData();
532 
533  transactor->begin();
534 
535  transactor->createDataSet(dsTypeResult, nopt);
536 
537  std::auto_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(dataset.get(), converter));
538 
539  if(dataset->moveBeforeFirst())
540  transactor->add(dsTypeResult->getName(), dsAdapter.get(), targetDSPtr->getConnectionInfo());
541 
542  if (isLinked)
543  {
544  std::string name = m_ui->m_dataSetLineEdit->text().toStdString() + "_id";
545 
547  p->setAutoNumber(true);
548 
549  transactor->addProperty(dsTypeResult->getName(), p);
550 
551  te::da::PrimaryKey* pk = new te::da::PrimaryKey(dsTypeResult);
552 
553  name += "_pk";
554 
555  boost::replace_all(name, ".", "_");
556 
557  pk->setName(name);
558 
559  pk->add(p);
560 
561  transactor->addPrimaryKey(dsTypeResult->getName(), pk);
562  }
563 
564  transactor->commit();
565 
566  setCursor(Qt::ArrowCursor);
567  QMessageBox::information(this, tr("Exchanger"), tr("Layer exported successfully."));
568  }
569  catch(const std::exception& e)
570  {
571  setCursor(Qt::ArrowCursor);
572 
573  transactor->rollBack();
574 
575  QString errMsg(tr("Error during exchanger. The reported error is: %1"));
576 
577  errMsg = errMsg.arg(e.what());
578 
579  QMessageBox::information(this, tr("Exchanger"), errMsg);
580 
581  return false;
582  }
583 
584  return true;
585 }
586 
588 {
589  QString value = m_ui->m_dsTypeComboBox->itemData(index).toString();
590 
591  m_outputDataSourceType = value.toStdString();
592 
593  if(m_outputDataSourceType == "POSTGIS")
594  {
595  m_exchangeToFile = false;
596 
597  m_ui->m_outputDataSourceComboBox->setEnabled(true);
598  m_ui->m_dsToolButton->setEnabled(true);
599  m_ui->m_dataSetLineEdit->clear();
600  m_ui->m_dataSetLineEdit->setEnabled(true);
601  m_ui->m_dirToolButton->setEnabled(false);
602  m_ui->m_spatialIndexCheckBox->setEnabled(true);
603  m_ui->m_spatialIndexCheckBox->setChecked(true);
604 
605  setDataSources();
606  }
607  else if(m_outputDataSourceType == "ADO")
608  {
609  m_exchangeToFile = false;
610 
611  m_ui->m_outputDataSourceComboBox->setEnabled(true);
612  m_ui->m_dsToolButton->setEnabled(true);
613  m_ui->m_dataSetLineEdit->clear();
614  m_ui->m_dataSetLineEdit->setEnabled(true);
615  m_ui->m_dirToolButton->setEnabled(false);
616  m_ui->m_spatialIndexCheckBox->setEnabled(false);
617  m_ui->m_spatialIndexCheckBox->setChecked(false);
618 
619  setDataSources();
620  }
621  else if(m_outputDataSourceType == "OGR")
622  {
623  m_exchangeToFile = true;
624 
625  m_ui->m_outputDataSourceComboBox->clear();
626  m_ui->m_outputDataSourceComboBox->setEnabled(false);
627  m_ui->m_dsToolButton->setEnabled(false);
628  m_ui->m_dataSetLineEdit->clear();
629  m_ui->m_dataSetLineEdit->setEnabled(false);
630  m_ui->m_dirToolButton->setEnabled(true);
631  m_ui->m_spatialIndexCheckBox->setEnabled(false);
632  m_ui->m_spatialIndexCheckBox->setChecked(false);
633  }
634 }
635 
637 {
638  onDataSourceTypeActivated(m_ui->m_dsTypeComboBox->currentIndex());
639 
640  if(m_ui->m_dataSetLineEdit->isEnabled())
641  m_ui->m_dataSetLineEdit->setText(value);
642 
643  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
644  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
645 
646  if (!layer.get())
647  {
648  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
649  return;
650  }
651 
652  int inputSRID = layer->getSRID();
653 
654  m_ui->m_inputSRIDLineEdit->setText(QString::number(inputSRID));
655  m_ui->m_outputSRIDLineEdit->setText(QString::number(inputSRID));
656 
657  if (inputSRID == TE_UNKNOWN_SRS)
658  {
659  m_ui->m_outputSRIDLineEdit->setEnabled(false);
660  m_ui->m_outputSRIDToolButton->setEnabled(false);
661  }
662  else
663  {
664  m_ui->m_outputSRIDLineEdit->setEnabled(true);
665  m_ui->m_outputSRIDToolButton->setEnabled(true);
666  }
667 }
668 
670 {
671  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
672  QString(), tr("Shapefile (*.shp *.SHP);;Mapinfo File (*.mif *.MIF);;KML (*.kml *.KML);;GeoJSON (*.geojson *.GEOJSON);;GML (*.gml *.GML);;DXF (*.dxf *.DXF);;DGN (*.dgn *.DGN);;"),0, QFileDialog::DontConfirmOverwrite);
673 
674  if (fileName.isEmpty())
675  return;
676 
677  m_ui->m_dataSetLineEdit->setText(fileName);
678 }
679 
681 {
682  std::auto_ptr<te::qt::widgets::DataSourceExplorerDialog> dExplorer(new te::qt::widgets::DataSourceExplorerDialog(this));
683 
684  if(!m_lastDsType.empty())
685  dExplorer->setDataSourceToUse(m_lastDsType.c_str());
686 
687  dExplorer->exec();
688 
689  setDataSources();
690 }
691 
693 {
694  if (m_ui->m_outputSRIDLineEdit->text().isEmpty())
695  {
696  QMessageBox::warning(this, tr("Warning"), tr("Output Layer SRID not defined."));
697  return;
698  }
699 
700  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
701  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
702 
703  if (inputSRID != outputSRID && outputSRID == TE_UNKNOWN_SRS)
704  {
705  QMessageBox::warning(this, tr("Warning"), tr("Invalid output Layer SRID."));
706  return;
707  }
708 
709  if (inputSRID != outputSRID && inputSRID == TE_UNKNOWN_SRS)
710  {
711  QMessageBox::warning(this, tr("Warning"), tr("Invalid input Layer SRID."));
712  return;
713  }
714 
715  bool res = false;
716 
717  if(m_exchangeToFile)
718  res = exchangeToFile();
719  else
720  res = exchangeToDatabase();
721 
722  if(res)
723  accept();
724 }
725 
727 {
728  m_ui->m_dsTypeComboBox->clear();
729 
730  // add the list of data sources available in the system
731  std::map<std::string, DataSourceType*>::const_iterator it = DataSourceTypeManager::getInstance().begin();
732  std::map<std::string, DataSourceType*>::const_iterator itend = DataSourceTypeManager::getInstance().end();
733 
734  while (it != itend)
735  {
736  std::string dataSourceName = it->first;
737 
738  if (dataSourceName == "POSTGIS" || dataSourceName == "ADO" || dataSourceName == "OGR")
739  {
740  QIcon icon = it->second->getIcon(DataSourceType::ICON_DATASOURCE_SMALL);
741  QString title = QString::fromStdString(it->second->getTitle());
742 
743  m_ui->m_dsTypeComboBox->addItem(icon, title, QVariant(dataSourceName.c_str()));
744  }
745 
746  ++it;
747  }
748 }
749 
751 {
752  te::qt::widgets::SRSManagerDialog srsDialog(this);
753  srsDialog.setWindowTitle(tr("Choose the SRS"));
754 
755  if (srsDialog.exec() == QDialog::Rejected)
756  return;
757 
758  std::pair<int, std::string> srid = srsDialog.getSelectedSRS();
759 
760  m_ui->m_outputSRIDLineEdit->setText(QString::number(srid.first));
761 }
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
void setDataSources()
Set the list of data sources that can be used.
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
A dialog for selecting a data source.
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
Definition: Utils.cpp:670
TEDATAACCESSEXPORT bool HasLinkedTable(te::da::DataSetType *type)
It checks if the datasettype has a linked table.
Definition: Utils.cpp:1213
A class that models the description of a dataset.
Definition: DataSetType.h:72
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
virtual Property * clone() const =0
It returns a clone of the object.
void setIndexType(IndexType t)
It sets the index type.
Definition: Index.h:176
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:166
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
Definition: Index.h:197
te::dt::Property * clone() const
It returns a clone of the object.
TECOMMONEXPORT std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
It models a property definition.
Definition: Property.h:59
DirectExchangerDialog(QWidget *parent=0, Qt::WindowFlags f=0)
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
void setDefaultValue(std::string *d)
It sets the default value associated to the property, or NULL if none is associated.
An converter for DataSetType.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:41
static std::auto_ptr< DataSource > make(const std::string &dsType)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
std::auto_ptr< Ui::DirectExchangerDialogForm > m_ui
A direct exchanger dialog for ADO, POSTGIS and SHP data sources.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
void setLastDataSource(std::string dataSource)
Function used to set the last data source used.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setRequired(bool r)
It tells if the property is required or not.
void setName(const std::string &name)
It sets the index name.
Definition: Index.h:162
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:54
A dialog used to build a SRSManagerDialog element.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:557
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
Definition: Utils.cpp:644
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
It describes an index associated to a DataSetType.
Definition: Index.h:54
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127