ProfileDialog.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/mnt/qt/ProfileDialog.cpp
22 
23  \brief Tool to generates graphic with dtm data profiles
24 */
25 //TerraLib
26 
27 #include "../../core/logger/Logger.h"
28 #include "../../edit/qt/Renderer.h"
29 #include "../../edit/qt/tools/CreateLineTool.h"
30 #include "../../edit/qt/tools/VertexTool.h"
31 #include "../../edit/Feature.h"
32 #include "../../edit/Repository.h"
33 #include "../../edit/RepositoryManager.h"
34 #include "../../qt/af/events/MapEvents.h"
35 #include "../../qt/widgets/Utils.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
38 #include "../../dataaccess/datasource/DataSourceManager.h"
39 #include "../../dataaccess/utils/Utils.h"
40 #include "../../geometry/GeometryProperty.h"
41 #include "../../mnt/core/Profile.h"
42 #include "../../qt/af/ApplicationController.h"
43 #include "../../qt/af/BaseApplication.h"
44 #include "../../qt/af/connectors/MapDisplay.h"
45 #include "../../qt/widgets/canvas/Canvas.h"
46 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
47 #include "../../qt/widgets/layer/explorer/LayerItemView.h"
48 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
49 #include "../../qt/widgets/canvas/MapDisplay.h"
50 #include "../../raster.h"
51 #include "../../statistics/core/Utils.h"
52 
53 #include "../core/Utils.h"
54 
55 #include "LayerSearchDialog.h"
56 #include "ProfileDialog.h"
57 #include "ProfileResultDialog.h"
58 #include "ui_ProfileDialogForm.h"
59 
60 // Qt
61 #include <QFileDialog>
62 #include <QFileInfo>
63 #include <QMessageBox>
64 #include <QValidator>
65 
66 // STL
67 #include <memory>
68 
69 // Boost
70 #include <boost/filesystem.hpp>
71 
73 
74 te::mnt::ProfileDialog::ProfileDialog(QWidget* parent, Qt::WindowFlags f)
75  : QDialog(parent, f),
76  m_ui(new Ui::ProfileDialogForm),
77  m_tooltype(ToolNone),
78  m_tool(nullptr),
79  m_app(nullptr)
80 {
81 // add controls
82  m_ui->setupUi(this);
83 
84 // add icons
85  m_ui->m_addPointMousePushButton->setIcon(QIcon::fromTheme("mnt-profile-line create"));
86  m_ui->m_changePointPushButton->setIcon(QIcon::fromTheme("mnt-profile-vertex move"));
87  m_ui->m_addPointPushButton->setIcon(QIcon::fromTheme("mnt-profile-vertex create"));
88  m_ui->m_deletePointPushButton->setIcon(QIcon::fromTheme("mnt-profile-vertex delete"));
89  m_ui->m_deletePathPushButton->setIcon(QIcon::fromTheme("mnt-profile-delete"));
90  m_ui->m_invertPushButton->setIcon(QIcon::fromTheme("mnt-profile-invert"));
91 
92 // connectors
93  connect(m_ui->m_layerSearchToolButton, SIGNAL(clicked()), this, SLOT(onInputLayerToolButtonClicked()));
94  connect(m_ui->m_inputLayersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onInputComboBoxChanged(int)));
95 
96  connect(m_ui->m_dummycheckBox, SIGNAL(toggled(bool)), m_ui->m_dummylineEdit, SLOT(setEnabled(bool)));
97 
98  connect(m_ui->m_editionradioButton, SIGNAL(toggled(bool)), this, SLOT(oneditionEnabled(bool)));
99  connect(m_ui->m_selectionradioButton, SIGNAL(toggled(bool)), this, SLOT(onselectionEnabled(bool)));
100 
101  connect(m_ui->m_vectorlayersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onVectorInputComboBoxChanged(int)));
102 
103  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
104 
105  connect(m_ui->m_addPointMousePushButton, SIGNAL(toggled(bool)), SLOT(onaddPointMouseToggled(bool)));
106  connect(m_ui->m_changePointPushButton, SIGNAL(toggled(bool)), SLOT(onchangePointToggled(bool)));
107  connect(m_ui->m_addPointPushButton, SIGNAL(toggled(bool)), SLOT(onaddPointToggled(bool)));
108  connect(m_ui->m_deletePointPushButton, SIGNAL(toggled(bool)), SLOT(ondeletePointToggled(bool)));
109  connect(m_ui->m_deletePathPushButton, SIGNAL(toggled(bool)), SLOT(ondeletePathToggled(bool)));
110  connect(m_ui->m_invertPushButton, SIGNAL(toggled(bool)), SLOT(oninvertToggled(bool)));
111 
112  m_color.push_back(te::color::RGBAColor(255, 0, 0, 255));
113  m_color.push_back(te::color::RGBAColor(255, 0, 255, 255));
114  m_color.push_back(te::color::RGBAColor(0, 255, 255, 255));
115  m_color.push_back(te::color::RGBAColor(37, 127, 0, 255));
116  m_color.push_back(te::color::RGBAColor(0, 0, 255, 255));
117 
118  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
119  m_ui->m_helpPushButton->setPageReference("plugins/mnt/DTM_Profile.html");
120 
121  m_vertex = true;
122 
123  setDefaultInterface();
124 }
125 
127 
129 {
130  return m_outputLayer;
131 }
132 
133 void te::mnt::ProfileDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
134 {
135  m_layers = layers;
136  m_ui->m_vectorlayersComboBox->clear();
137  m_ui->m_inputLayersComboBox->clear();
138 
139  m_ui->m_vectorlayersComboBox->addItem(QString(""), QVariant(""));
140 
141  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
142 
143  while (it != m_layers.end())
144  {
145  if (it->get())
146  {
147  if (it->get()->isValid())
148  {
149  std::unique_ptr<te::da::DataSetType> dsType(it->get()->getSchema());
150  if (dsType.get())
151  {
152  if (dsType->hasGeom())
153  {
154  te::gm::GeomType gmType = te::da::GetFirstGeomProperty(dsType.get())->getGeometryType();
155  switch (gmType)
156  {
165  m_ui->m_vectorlayersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
166  case te::gm::TINType:
169  case te::gm::PolygonType:
170  case te::gm::TINZType:
175  m_ui->m_inputLayersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
176  break;
177  default:
178  break;
179  }
180 
181  }
182  if (dsType->hasRaster())
183  m_ui->m_inputLayersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
184  }
185  }
186  }
187  ++it;
188  }
189 
191 }
192 
194 {
195  m_ui->m_selectionradioButton->setChecked(true);
196  m_ui->m_trajectorystackedWidget->setCurrentIndex(1);
197 }
198 
200 {
201  m_viewed.clear();
202  DrawSelected(m_viewed, 1, false);
203  if (m_tool)
204  {
205  m_app->getMapDisplay()->setCurrentTool(nullptr);
206  m_tool = nullptr;
207  }
209 
210  if (m_inputLayer)
211  {
212  te::edit::Repository* repository = te::edit::RepositoryManager::getInstance().getRepository(m_inputLayer->getId());
213  if (repository)
214  repository->clear();
215  }
216 
217  if (m_app)
218  connect(m_app->getMapDisplay(), SIGNAL(drawLayersFinished(const QMap<QString, QString>&)), SLOT(onDrawLayersFinished(const QMap<QString, QString>&)));
219 
221  window->onDrawTriggered();
222 
224 
225 }
226 
228 {
229  LayerSearchDialog search(this->parentWidget());
230  search.setLayers(m_layers);
231  QList<mntType> types;
232  types << TIN << GRID << ISOLINE;
233  search.setActive(types);
234 
235  if (search.exec() != QDialog::Accepted)
236  {
237  return;
238  }
239 
240  int index = m_ui->m_inputLayersComboBox->findText(search.getLayer().get()->getTitle().c_str());
241  m_ui->m_inputLayersComboBox->setCurrentIndex(index);
242 }
243 
245 {
246  m_inputLayer = nullptr;
247  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
248  std::string layerID = m_ui->m_inputLayersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
249  while (it != m_layers.end())
250  {
251  if(layerID == it->get()->getId())
252  {
253  m_inputLayer = it->get();
254  std::unique_ptr<te::da::DataSetType> dsType = m_inputLayer->getSchema();
255  te::map::DataSetLayer* indsLayer = dynamic_cast<te::map::DataSetLayer*>(m_inputLayer.get());
256  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(indsLayer->getDataSourceId(), true);
257  m_ui->m_ZcomboBox->clear();
258 
259  m_inputType = getMNTType(dsType.get());
260 
261  if (m_inputType != GRID)
262  {
263  m_ui->m_inputstackedWidget->setCurrentIndex(1);
264 
265  if (m_inputType == SAMPLE || m_inputType == ISOLINE)
266  {
267  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(m_inputLayer->getDataSourceId(), true);
268  std::string inSetName = m_inputLayer->getDataSetName();
269 
270  if (!inDataSource.get())
271  return;
272 
273  std::unique_ptr<te::da::DataSet> inDset(inDataSource->getDataSet(inSetName));
274  std::size_t geo_pos = te::da::GetFirstPropertyPos(inDset.get(), te::dt::GEOMETRY_TYPE);
275  inDset->moveFirst();
276  std::unique_ptr<te::gm::Geometry> gin(inDset->getGeometry(geo_pos));
277  if (gin->is3D())
278  {
279  m_ui->m_ZcomboBox->hide();
280  m_ui->m_Zlabel->hide();
281  return;
282  }
283 
284  m_ui->m_ZcomboBox->show();
285  m_ui->m_Zlabel->show();
286  std::vector<te::dt::Property*> props = dsType->getProperties();
287  for (std::size_t i = 0; i < props.size(); ++i)
288  {
289  switch (props[i]->getType())
290  {
291  case te::dt::FLOAT_TYPE:
292  case te::dt::DOUBLE_TYPE:
293  case te::dt::INT16_TYPE:
294  case te::dt::INT32_TYPE:
295  case te::dt::INT64_TYPE:
296  case te::dt::UINT16_TYPE:
297  case te::dt::UINT32_TYPE:
298  case te::dt::UINT64_TYPE:
300  m_ui->m_ZcomboBox->addItem(QString(props[i]->getName().c_str()), QVariant(props[i]->getName().c_str()));
301  break;
302  default:
303  break;
304  }
305  }
306  }
307  else //TIN
308  {
309  m_ui->m_ZcomboBox->hide();
310  m_ui->m_Zlabel->hide();
311  }
312  }
313  else
314  {
315  m_ui->m_inputstackedWidget->setCurrentIndex(0);
316  std::unique_ptr<te::da::DataSet> dsRaster = inDataSource->getDataSet(indsLayer->getDataSetName());
317 
318  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
319  std::unique_ptr<te::rst::Raster> in_raster = dsRaster->getRaster(rasterProp->getName());
320  m_ui->m_dummylineEdit->setText(QString::number(in_raster->getBand(0)->getProperty()->m_noDataValue));
321  m_tol = in_raster->getResolutionX() * 3;
322  }
323  m_srid = m_inputLayer->getSRID();
324  }
325  ++it;
326  }
327 
328 }
329 
331 {
332  if (!checked)
333  return;
334 
335  m_ui->m_trajectorystackedWidget->setCurrentIndex(0);
336 
338  m_app->onSelectionToggled(false);
339  m_app->onPanToggled(false);
340  m_app->onZoomInToggled(false);
341  m_app->onZoomOutToggled(false);
342 
343  connect(m_app->getMapDisplay(), SIGNAL(drawLayersFinished(const QMap<QString, QString>&)), SLOT(onDrawTrajectories(const QMap<QString, QString>&)));
344 
345  m_ui->m_addPointMousePushButton->setChecked(true);
346 
347  m_ui->m_vectorlayersComboBox->setCurrentIndex(0);
348  m_viewed.clear();
349 }
350 
352 {
353  if (!checked)
354  return;
355 
356  release();
357 
358  m_ui->m_trajectorystackedWidget->setCurrentIndex(1);
359  m_ui->m_vectorlayersComboBox->setCurrentIndex(0);
360 }
361 
362 
364 {
365  m_trajectoryLayer = nullptr;
366 
367  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
368  std::string layerID = m_ui->m_vectorlayersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
369  while (it != m_layers.end())
370  {
371  if(layerID == it->get()->getId())
372  {
373  m_trajectoryLayer = it->get();
375  {
376  m_ui->m_vectorlayersComboBox->setCurrentIndex(0);
377  m_trajectoryLayer = nullptr;
378  throw te::common::Exception(TE_TR("Trajectory layer must be different from input layer!"));
379  }
380  break;
381  }
382  ++it;
383  }
384 }
385 
387 {
388  if (!checked && m_tool)
389  return;
390 
391  if (!m_app)
392  return;
393 
394  if (!m_inputLayer)
395  return;
396 
397  m_app->getLayerExplorer()->clearSelection();
398 
399  if (m_tooltype != CreateLine || !m_tool)
400  {
401  if (m_inputLayer->getSRID() != m_app->getMapDisplay()->getSRID())
402  {
403  QMessageBox::information(this, tr("Profile "), tr("SRID Input Layer different from SRID Display"));
404  return;
405  }
407  m_app->getMapDisplay()->setCurrentTool(nullptr);
408 
409  m_tool = new te::edit::CreateLineTool(m_app->getMapDisplay(), m_inputLayer, Qt::ArrowCursor, nullptr);
411 
412  connect(m_tool, SIGNAL(geometriesEdited()), SLOT(onGeometriesChanged()));
413  connect(m_tool, SIGNAL(toolDeleted()), SLOT(onToolDeleted()));
414 
415  m_vertex = true;
416  }
417 
418  m_ui->m_addPointMousePushButton->setChecked(true);
419  m_ui->m_changePointPushButton->setChecked(false);
420  m_ui->m_addPointPushButton->setChecked(false);
421  m_ui->m_deletePointPushButton->setChecked(false);
422  m_ui->m_deletePathPushButton->setChecked(false);
423  m_ui->m_invertPushButton->setChecked(false);
425 }
426 
428 {
429  if (!checked && m_tool)
430  return;
431 
432  if (!m_inputLayer)
433  return;
434 
435  if (!setVertexEdition())
436  return;
437 
439 
440  m_vertex = true;
441  m_ui->m_changePointPushButton->setChecked(true);
442  m_ui->m_addPointMousePushButton->setChecked(false);
443  m_ui->m_addPointPushButton->setChecked(false);
444  m_ui->m_deletePointPushButton->setChecked(false);
445  m_ui->m_deletePathPushButton->setChecked(false);
446  m_ui->m_invertPushButton->setChecked(false);
448 }
449 
451 {
452  if (!checked && m_tool)
453  return;
454 
455  if (!m_inputLayer)
456  return;
457 
458  if (!setVertexEdition())
459  return;
460 
462 
463  m_vertex = true;
464  m_ui->m_addPointPushButton->setChecked(true);
465  m_ui->m_addPointMousePushButton->setChecked(false);
466  m_ui->m_changePointPushButton->setChecked(false);
467  m_ui->m_deletePointPushButton->setChecked(false);
468  m_ui->m_deletePathPushButton->setChecked(false);
469  m_ui->m_invertPushButton->setChecked(false);
471 }
472 
474 {
475  if (!checked && m_tool)
476  return;
477 
478  if (!m_inputLayer)
479  return;
480 
481  if (!setVertexEdition())
482  return;
483 
485 
486  m_vertex = true;
487  m_ui->m_deletePointPushButton->setChecked(true);
488  m_ui->m_addPointMousePushButton->setChecked(false);
489  m_ui->m_changePointPushButton->setChecked(false);
490  m_ui->m_addPointPushButton->setChecked(false);
491  m_ui->m_deletePathPushButton->setChecked(false);
492  m_ui->m_invertPushButton->setChecked(false);
494 }
495 
497 {
498  if (!checked && m_tool)
499  return;
500 
501  if (!m_inputLayer)
502  return;
503 
504  if (!setVertexEdition())
505  return;
506 
508  connect(m_tool, SIGNAL(geometriesEdited()), SLOT(onGeometriesChanged()));
509  connect(m_tool, SIGNAL(toolDeleted()), SLOT(onToolDeleted()));
510 
511  m_app->getMapDisplay()->setCursor(Qt::ArrowCursor);
512  m_vertex = false;
513  m_ui->m_deletePathPushButton->setChecked(true);
514  m_ui->m_addPointMousePushButton->setChecked(false);
515  m_ui->m_changePointPushButton->setChecked(false);
516  m_ui->m_addPointPushButton->setChecked(false);
517  m_ui->m_deletePointPushButton->setChecked(false);
518  m_ui->m_invertPushButton->setChecked(false);
520 }
521 
523 {
524  if (!checked && m_tool)
525  return;
526 
527  if (!m_inputLayer)
528  return;
529 
530  if (!setVertexEdition())
531  return;
532 
534  connect(m_tool, SIGNAL(geometriesEdited()), SLOT(onGeometriesChanged()));
535 
536  m_vertex = false;
537  m_ui->m_invertPushButton->setChecked(true);
538  m_ui->m_addPointMousePushButton->setChecked(false);
539  m_ui->m_changePointPushButton->setChecked(false);
540  m_ui->m_addPointPushButton->setChecked(false);
541  m_ui->m_deletePointPushButton->setChecked(false);
542  m_ui->m_deletePathPushButton->setChecked(false);
544 }
545 
546 void te::mnt::ProfileDialog::onDrawTrajectories(const QMap<QString, QString>&)
547 {
548  DrawSelected(m_viewed, 1, m_vertex, false);
549 
550 }
551 
553 {
554  m_ui->m_addPointMousePushButton->setChecked(false);
555  m_ui->m_changePointPushButton->setChecked(false);
556  m_ui->m_addPointPushButton->setChecked(false);
557  m_ui->m_deletePointPushButton->setChecked(false);
558  m_ui->m_deletePathPushButton->setChecked(false);
559  m_ui->m_invertPushButton->setChecked(false);
560  m_tool = nullptr;
561 }
562 
564 {
565  if (!m_inputLayer)
566  return;
567 
568  if (m_tooltype == CreateLine)
569  {
571  te::gm::LineString *ls = dynamic_cast<te::gm::LineString*>(ct->buildLine());
572  if (ls->getNPoints() < 2)
573  {
574  delete ls;
575  return;
576  }
577 
578  m_viewed.push_back(ls);
579  }
580  else if (((te::mnt::ProfileTools*)m_tool)->getType() != te::mnt::VERTEX_ADD)
581  {
582  m_viewed.clear();
583  m_viewed = ((te::mnt::ProfileTools*)m_tool)->getLines();
584  }
585 
586  testGeometries();
587 
589 
590 }
591 
593 {
595  if (m_trajectoryLayer)
596  visibility = m_trajectoryLayer->getVisibility();
597 
598  std::string attrZ;
599  try
600  {
601  QApplication::setOverrideCursor(Qt::WaitCursor);
602 
603  if (!m_tool)
604  {
605  if (!m_inputLayer)
606  throw te::common::Exception(TE_TR("Select an input layer!"));
607 
608  if (m_trajectoryLayer)
609  {
610  if (m_inputLayer->getSRID() != m_trajectoryLayer->getSRID())
611  throw te::common::Exception(TE_TR("Can not execute this operation with different SRIDs geometries!"));
612  }
613  }
614 
615  m_dummy = m_ui->m_dummylineEdit->text().toDouble();
616 
617  te::map::DataSetLayer* indsLayer = dynamic_cast<te::map::DataSetLayer*>(m_inputLayer.get());
618  if (!indsLayer)
619  throw te::common::Exception(TE_TR("Can not execute this operation on this type of layer!"));
620 
621  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(indsLayer->getDataSourceId(), true);
622  if (!inDataSource.get())
623  throw te::common::Exception(TE_TR("The selected input data source can not be accessed!"));
624 
625  std::string inDsetName = indsLayer->getDataSetName();
626 
627  std::unique_ptr<te::da::DataSet> inDset = inDataSource->getDataSet(inDsetName);
628  std::size_t geo_pos = te::da::GetFirstPropertyPos(inDset.get(), te::dt::GEOMETRY_TYPE);
629  inDset->moveFirst();
630  std::unique_ptr<te::gm::Geometry> gin = inDset->getGeometry(geo_pos);
631  if (gin.get())
632  if (!gin.get()->is3D())
633  {
634  attrZ = m_ui->m_ZcomboBox->currentText().toUtf8().data();
635  if (attrZ.empty())
636  {
637  std::stringstream msg;
638  msg << "'" << inDsetName << "' " << TE_TR("Sets Quote Attribute!");
639  throw te::common::Exception(msg.str());
640  }
641  }
642 
643  std::unique_ptr<te::da::DataSetType> inDsetType(inDataSource->getDataSetType(inDsetName));
644 
645  std::unique_ptr<Profile> profile(new Profile());
646  profile->setInput(inDataSource, inDsetName, std::move(inDsetType), m_dummy, attrZ);
647  profile->setSRID(m_inputLayer->getSRID());
648 
649  std::string geostype;
650 
651  if (m_ui->m_selectionradioButton->isChecked())
652  {
653  if (!m_trajectoryLayer)
654  throw te::common::Exception(TE_TR("Select an vector layer!"));
655  std::unique_ptr<te::da::DataSet> inDset;
656 
657  if (m_ui->m_selectCheckBox->isChecked())
658  {
659  const te::da::ObjectIdSet* objSet = m_trajectoryLayer->getSelected();
660  inDset = m_trajectoryLayer->getData(objSet);
661  }
662  else
663  inDset = te::da::GetDataSource(m_trajectoryLayer->getDataSourceId(), true)->getDataSet(m_trajectoryLayer->getDataSetName());
664 
665  std::size_t geo_pos = te::da::GetFirstPropertyPos(inDset.get(), te::dt::GEOMETRY_TYPE);
666 
667  inDset->moveBeforeFirst();
668 
669  m_viewed.clear();
670 
671  while (inDset->moveNext())
672  {
673  std::unique_ptr<te::gm::Geometry> gin = inDset->getGeometry(geo_pos);
674  gin->setSRID(m_srid);
675  geostype = gin.get()->getGeometryType();
676 
677  if (geostype == "LineString")
678  {
679  te::gm::LineString *l = dynamic_cast<te::gm::LineString*>(gin.get()->clone());
680  m_viewed.push_back(l);
681  }
682  if (geostype == "MultiLineString")
683  {
684  te::gm::MultiLineString *g = dynamic_cast<te::gm::MultiLineString*>(gin.get());
685  std::size_t np = g->getNumGeometries();
686  for (std::size_t i = 0; i < np; ++i)
687  {
688  te::gm::LineString *l = dynamic_cast<te::gm::LineString*>(g->getGeometryN(i)->clone());
689  m_viewed.push_back(l);
690  }
691  }
692  }
693 
694  if (visibility == te::map::VISIBLE)
695  m_trajectoryLayer->setVisibility(te::map::NOT_VISIBLE);
696  }
697  else
698  {
699  if (!m_viewed.size())
700  throw te::common::Exception(TE_TR("No trajectory selected!"));
701  }
702 
703  std::string msg = "Profile - Start.";
704 #ifdef TERRALIB_LOGGER_ENABLED
705  TE_CORE_LOG_DEBUG("mnt", msg);
706 #endif
707  // Principal function calling
708  std::vector<te::gm::LineString*> profileSet;
709  std::unique_ptr<te::da::DataSetType> dsType = m_inputLayer->getSchema();
710  if (dsType->hasRaster())
711  {
712  profile->runRasterProfile(m_viewed, profileSet);
713  }
714  if (dsType->hasGeom())
715  {
716  std::unique_ptr<te::gm::GeometryProperty>geomProp(te::da::GetFirstGeomProperty(dsType.get()));
717  te::gm::GeomType gmType = geomProp->getGeometryType();
718  if (gmType == te::gm::LineStringType || gmType == te::gm::MultiLineStringType ||
719  gmType == te::gm::LineStringZType || gmType == te::gm::MultiLineStringZType ||
720  gmType == te::gm::LineStringMType || gmType == te::gm::MultiLineStringMType ||
722  {
723  profile->runIsolinesProfile(m_viewed, profileSet);
724  }
725  else if (gmType == te::gm::TINType || gmType == te::gm::MultiPolygonType || gmType == te::gm::PolyhedralSurfaceType || gmType == te::gm::PolygonType ||
726  gmType == te::gm::TINZType || gmType == te::gm::MultiPolygonZType || gmType == te::gm::PolyhedralSurfaceZType || gmType == te::gm::PolygonZType ||
727  gmType == te::gm::GeometryType)//TIN
728  {
729  profile->runTINProfile(m_viewed, profileSet);
730  }
731  else
732  throw te::common::Exception(TE_TR("Input layer type is invalid!"));
733  }
734 
735  msg = "Profile - End.";
736 #ifdef TERRALIB_LOGGER_ENABLED
737  TE_CORE_LOG_DEBUG("mnt", msg);
738 #endif
739 
740  DrawSelected(m_viewed, 2, false);
741 
742 
743  if (!profileSet.size())
744  throw te::common::Exception(TE_TR("No profile calculated!"));
745 
746  te::mnt::ProfileResultDialog result(m_ui->m_titleLineEdit->text(), m_ui->m_yAxisLineEdit->text(), profileSet, m_color, this->parentWidget());
747 
748  QApplication::restoreOverrideCursor();
749  if (result.exec() != QDialog::Accepted)
750  {
751  if (m_trajectoryLayer)
752  {
753  m_trajectoryLayer->setVisibility(visibility);
754  m_viewed.clear();
755  }
756 
757  DrawSelected(m_viewed, 1, false);
758 
759  return;
760  }
761  }
762  catch (const std::exception& e)
763  {
764  QApplication::restoreOverrideCursor();
765  QMessageBox::information(this, tr("Profile "), e.what());
766 
767  if (m_trajectoryLayer)
768  m_trajectoryLayer->setVisibility(visibility);
769  release();
770 
771  return;
772  }
773 
774  if (m_trajectoryLayer)
775  m_trajectoryLayer->setVisibility(visibility);
776  release();
777 
778  QApplication::restoreOverrideCursor();
779  accept();
780 
781 }
782 
783 void te::mnt::ProfileDialog::DrawSelected(const std::vector<te::gm::LineString*> visadas, int width, bool vertex, bool draw)
784 {
786  if (draw)
787  window->onDrawTriggered();
788 
789  const te::gm::Envelope& displayExtent = window->getMapDisplay()->getExtent();
791  if (!canvas.getDevice())
792  return;
793 
794  canvas.setWindow(displayExtent.m_llx, displayExtent.m_lly, displayExtent.m_urx, displayExtent.m_ury);
795  canvas.setLineWidth(width);
796  canvas.setLineDashStyle(te::map::SolidLine);
797  te::qt::widgets::Config2DrawPoints(&canvas, "circle", 8, Qt::red, Qt::red, 1);
798 
799  for (unsigned int v = 0; v < visadas.size(); ++v)
800  {
801  canvas.setLineColor(m_color[v%m_color.size()]);
802  canvas.setPointColor(m_color[v%m_color.size()]);
803  if (visadas[v]->getSRID() != window->getMapDisplay()->getSRID())
804  {
805 #ifdef TERRALIB_LOGGER_ENABLED
806  TE_CORE_LOG_DEBUG("mnt", tr("SRID InputLayer different from SRID Display").toUtf8().data());
807 #endif
808  }
809  canvas.draw(visadas[v]);
810  if (vertex)
811  {
812  for (size_t p = 0; p < visadas[v]->getNPoints(); p++)
813  {
814  std::unique_ptr<te::gm::Point> point(visadas[v]->getPointN(p));
815  canvas.draw(point.get());
816  }
817  }
818 
819  }
820  window->getMapDisplay()->repaint();
821  if (m_app)
822  m_app->getMapDisplay()->setCursor(Qt::ArrowCursor);
823 
824 }
825 
827 {
828  bool changed = false;
829  for (size_t i = 0; i < m_viewed.size(); i++)
830  {
831  if (m_viewed[i]->getNPoints() < 2)
832  {
833  m_viewed.erase(m_viewed.begin() + i);
834  i--;
835  changed = true;
836  }
837  }
838  if (changed)
839  ((te::mnt::ProfileTools*)m_tool)->setLines(m_viewed);
840 
841 }
842 
844 {
845  if (!m_viewed.size()){
846  QMessageBox::information(this, tr("Profile "), TE_TR("No trajectories!"));
847  return false;
848  }
849 
850  if (m_tooltype != EditVertex || !m_tool)
851  {
853 
854  m_app->getMapDisplay()->setCurrentTool(nullptr);
855 
857  connect(m_tool, SIGNAL(geometriesEdited()), SLOT(onGeometriesChanged()));
858  connect(m_tool, SIGNAL(toolDeleted()), SLOT(onToolDeleted()));
859 
861  ((te::mnt::ProfileTools*)m_tool)->setLines(m_viewed);
862  }
863 
864  m_app->getMapDisplay()->setCursor(Qt::ArrowCursor);
865  return true;
866 }
867 
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
virtual void setCurrentTool(te::qt::widgets::AbstractTool *tool, const bool &delPrevious=true)
Updates the current tool being used on te::qt::widgets::MapDisplay.
te::qt::af::BaseApplication * m_app
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
std::list< te::map::AbstractLayerPtr > m_layers
LINE_INVERT
Definition: ProfileTools.h:44
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void onZoomInToggled(bool checked)
VERTEX_ADD
Definition: ProfileTools.h:44
void onPanToggled(bool checked)
boost::shared_ptr< DataSource > DataSourcePtr
void ondeletePointToggled(bool checked)
std::vector< te::gm::LineString * > m_viewed
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
Definition: Logger.h:225
void ondeletePathToggled(bool checked)
This class implements a concrete tool to create lines.
void onDrawTrajectories(const QMap< QString, QString > &)
VERTEX_DELETE
Definition: ProfileTools.h:44
double m_urx
Upper right corner x-coordinate.
void onchangePointToggled(bool checked)
A dialog Layer Search.
te::qt::widgets::AbstractTool * m_tool
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
VERTEX_MOVE
Definition: ProfileTools.h:44
te::map::AbstractLayerPtr m_outputLayer
std::unique_ptr< Ui::ProfileDialogForm > m_ui
Raster property.
void onaddPointMouseToggled(bool checked)
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
std::size_t getNPoints() const
it returns the number of points (vertexes) in the geometry.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
static RepositoryManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
te::map::AbstractLayerPtr getLayer()
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
void onSelectionToggled(bool checked)
URI C++ Library.
Definition: Attributes.h:37
te::map::AbstractLayerPtr getLayer()
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
te::qt::widgets::LayerItemView * getLayerExplorer()
te::gm::Polygon * p
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
virtual AbstractData * clone() const =0
It returns a clone of this object.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw points.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
double m_lly
Lower left corner y-coordinate.
void oninvertToggled(bool checked)
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
void DrawSelected(const std::vector< te::gm::LineString * > visadas, int width=1, bool vertex=true, bool draw=true)
MultiLineString is a MultiCurve whose elements are LineStrings.
const std::string & getDataSetName() const
te::map::AbstractLayerPtr m_inputLayer
double m_ury
Upper right corner y-coordinate.
te::qt::widgets::MapDisplay * getMapDisplay()
void onInputComboBoxChanged(int index)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setActive(const QList< mntType > &types)
te::da::DataSet * getDataSet(te::da::DataSource *ds)
void onZoomOutToggled(bool checked)
std::vector< te::color::RGBAColor > m_color
This class represents a repository of geometries and features.
Definition: Repository.h:63
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
A dialog Show Profile Graphic Result.
mntType m_inputType
Input type (TIN, GRID)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void onVectorInputComboBoxChanged(int index)
TEMNTEXPORT te::mnt::mntType getMNTType(const te::da::DataSetType *dt)
LINE_DELETE
Definition: ProfileTools.h:44
te::map::AbstractLayerPtr m_trajectoryLayer
Visibility
Each layer can have three states of visibility.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::gm::Geometry * buildLine()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
void onaddPointToggled(bool checked)
virtual const std::string & getDataSourceId() const
virtual QPixmap * getDisplayPixmap() const
It returns the map display pixmap.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127