OGS
mainwindow.cpp
Go to the documentation of this file.
1 
15 #include "mainwindow.h"
16 
17 #include "BaseLib/Logging.h"
18 
19 // Qt includes
20 #include <QDate>
21 #include <QDesktopWidget>
22 #include <QFileDialog>
23 #include <QMessageBox>
24 #include <QObject>
25 #include <QScreen>
26 #include <QSettings>
27 #include <QSignalMapper>
28 #ifndef NDEBUG
29 #include <QElapsedTimer>
30 #endif // NDEBUG
31 
32 // VTK includes
33 #include <vtkImageAlgorithm.h>
34 #include <vtkImageData.h>
35 #include <vtkOBJExporter.h>
36 #include <vtkRenderer.h>
37 #include <vtkVRMLExporter.h>
38 
51 #include "BaseLib/FileTools.h"
52 #include "BaseLib/Histogram.h"
56 #include "GeoLib/Raster.h"
57 #include "InfoLib/GitInfo.h"
62 #include "MeshLib/Mesh.h"
65 #include "MeshLib/Node.h"
68 
69 // Dialogs
75 #include "DataView/LicenseDialog.h"
81 #ifdef OGS_USE_NETCDF
83 #endif // OGS_USE_NETCDF
85 #include "Base/OGSError.h"
86 #include "Base/RecentFiles.h"
87 #include "Base/TreeModelIterator.h"
88 #include "DataView/GeoTreeModel.h"
90 #include "DataView/SetNameDialog.h"
95 #include "VtkVis/VtkRaster.h"
97 
98 using namespace FileIO;
99 
100 MainWindow::MainWindow(QWidget* parent /* = 0*/) : QMainWindow(parent)
101 {
102  setupUi(this);
103 
104  // Setup various models
105  _geo_model = std::make_unique<GEOModels>(_project.getGEOObjects());
106  _meshModel = std::make_unique<MeshModel>(_project);
107  _elementModel = std::make_unique<ElementTreeModel>();
108  _processModel = std::make_unique<ProcessModel>(_project);
109  _conditionModel = std::make_unique<FemConditionModel>();
110 
111  geoTabWidget->treeView->setModel(_geo_model->getGeoModel());
112  stationTabWidget->treeView->setModel(_geo_model->getStationModel());
113  meshTabWidget->treeView->setModel(_meshModel.get());
114  meshTabWidget->elementView->setModel(_elementModel.get());
115  modellingTabWidget->treeView->setModel(_processModel.get());
116  modellingTabWidget->conditionView->setModel(_conditionModel.get());
117 
118  // vtk visualization pipeline
120  std::make_unique<VtkVisPipeline>(visualizationWidget->renderer());
121 
122  // station model connects
123  connect(stationTabWidget->treeView, SIGNAL(openStationListFile(int)), this,
124  SLOT(open(int)));
125  connect(stationTabWidget->treeView,
126  SIGNAL(stationListExportRequested(std::string, std::string)), this,
128  std::string, std::string))); // export Stationlist to GMS
129  connect(stationTabWidget->treeView, SIGNAL(stationListRemoved(std::string)),
130  _geo_model.get(),
131  SLOT(removeStationVec(
132  std::string))); // update model when stations are removed
133  connect(stationTabWidget->treeView,
134  SIGNAL(stationListSaved(QString, QString)), this,
135  SLOT(writeStationListToFile(QString,
136  QString))); // save Stationlist to File
137  connect(
138  _geo_model.get(),
139  SIGNAL(stationVectorRemoved(StationTreeModel*, std::string)), this,
140  SLOT(updateDataViews())); // update data view when stations are removed
141  connect(stationTabWidget->treeView,
142  SIGNAL(requestNameChangeDialog(const std::string&, std::size_t)),
143  this, SLOT(showStationNameDialog(const std::string&, std::size_t)));
144  connect(stationTabWidget->treeView,
145  SIGNAL(geometryMappingRequested(const std::string&)), this,
146  SLOT(mapGeometry(const std::string&)));
147  connect(stationTabWidget->treeView, SIGNAL(diagramRequested(QModelIndex&)),
148  this,
150  QModelIndex&))); // connect treeview to diagramview
151 
152  // geo model connects
153  connect(geoTabWidget->treeView, SIGNAL(openGeometryFile(int)), this,
154  SLOT(open(int)));
155  connect(geoTabWidget->treeView,
156  SIGNAL(listRemoved(std::string, GeoLib::GEOTYPE)), _geo_model.get(),
157  SLOT(removeGeometry(std::string, GeoLib::GEOTYPE)));
158  connect(geoTabWidget->treeView,
159  SIGNAL(geometryMappingRequested(const std::string&)), this,
160  SLOT(mapGeometry(const std::string&)));
161  connect(
162  geoTabWidget->treeView, SIGNAL(saveToFileRequested(QString, QString)),
163  this,
164  SLOT(writeGeometryToFile(QString, QString))); // save geometry to file
165  connect(geoTabWidget->treeView,
166  SIGNAL(requestPointToStationConversion(std::string const&)), this,
167  SLOT(convertPointsToStations(std::string const&)));
168  connect(
169  geoTabWidget->treeView,
170  SIGNAL(requestLineEditDialog(const std::string&)), this,
171  SLOT(showLineEditDialog(const std::string&))); // open line edit dialog
172  connect(geoTabWidget->treeView,
173  SIGNAL(requestNameChangeDialog(const std::string&,
174  const GeoLib::GEOTYPE, std::size_t)),
175  this,
176  SLOT(showGeoNameDialog(const std::string&, const GeoLib::GEOTYPE,
177  std::size_t)));
178  connect(_geo_model.get(),
179  SIGNAL(geoDataAdded(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
180  this, SLOT(updateDataViews()));
181  connect(_geo_model.get(),
182  SIGNAL(geoDataRemoved(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
183  this, SLOT(updateDataViews()));
184  connect(geoTabWidget->treeView,
185  SIGNAL(geoItemSelected(const vtkPolyDataAlgorithm*, int)),
186  _vtkVisPipeline.get(),
187  SLOT(highlightGeoObject(const vtkPolyDataAlgorithm*, int)));
188  connect(geoTabWidget->treeView, SIGNAL(removeGeoItemSelection()),
189  _vtkVisPipeline.get(), SLOT(removeHighlightedGeoObject()));
190  connect(stationTabWidget->treeView,
191  SIGNAL(geoItemSelected(const vtkPolyDataAlgorithm*, int)),
192  _vtkVisPipeline.get(),
193  SLOT(highlightGeoObject(const vtkPolyDataAlgorithm*, int)));
194  connect(stationTabWidget->treeView, SIGNAL(removeGeoItemSelection()),
195  _vtkVisPipeline.get(), SLOT(removeHighlightedGeoObject()));
196 
197  // Setup connections for mesh models to GUI
198  connect(meshTabWidget->treeView, SIGNAL(openMeshFile(int)), this,
199  SLOT(open(int)));
200  connect(meshTabWidget->treeView,
201  SIGNAL(requestMeshRemoval(const QModelIndex&)), _meshModel.get(),
202  SLOT(removeMesh(const QModelIndex&)));
203  connect(meshTabWidget->treeView,
204  SIGNAL(requestMeshRemoval(const QModelIndex&)), _elementModel.get(),
205  SLOT(clearView()));
206  connect(
207  meshTabWidget->treeView,
208  SIGNAL(qualityCheckRequested(MeshLib::VtkMappedMeshSource*)),
209  this,
211  connect(meshTabWidget->treeView,
212  SIGNAL(requestMeshToGeometryConversion(const MeshLib::Mesh*)), this,
213  SLOT(convertMeshToGeometry(const MeshLib::Mesh*)));
214  connect(meshTabWidget->treeView,
215  SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
216  unsigned, bool)),
217  _vtkVisPipeline.get(),
218  SLOT(highlightMeshComponent(
219  vtkUnstructuredGridAlgorithm const* const, unsigned, bool)));
220  connect(meshTabWidget->treeView, SIGNAL(meshSelected(MeshLib::Mesh const&)),
221  this->_elementModel.get(), SLOT(setMesh(MeshLib::Mesh const&)));
222  connect(meshTabWidget->treeView, SIGNAL(meshSelected(MeshLib::Mesh const&)),
223  meshTabWidget->elementView, SLOT(updateView()));
224  connect(
225  meshTabWidget->treeView,
226  SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
227  unsigned, bool)),
228  this->_elementModel.get(),
229  SLOT(setElement(vtkUnstructuredGridAlgorithm const* const, unsigned)));
230  connect(meshTabWidget->treeView,
231  SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
232  unsigned, bool)),
233  meshTabWidget->elementView, SLOT(updateView()));
234  connect(meshTabWidget->treeView,
235  SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
236  unsigned, bool)),
237  reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
238  SLOT(removeHighlightActor()));
239  connect(meshTabWidget->treeView, SIGNAL(removeSelectedMeshComponent()),
240  _vtkVisPipeline.get(), SLOT(removeHighlightedMeshComponent()));
241  connect(meshTabWidget->elementView,
242  SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const* const,
243  unsigned, bool)),
244  reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
245  SLOT(removeHighlightActor()));
246  connect(meshTabWidget->elementView,
247  SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const* const,
248  unsigned, bool)),
249  _vtkVisPipeline.get(),
250  SLOT(highlightMeshComponent(
251  vtkUnstructuredGridAlgorithm const* const, unsigned, bool)));
252  connect(meshTabWidget->elementView, SIGNAL(removeSelectedMeshComponent()),
253  _vtkVisPipeline.get(), SLOT(removeHighlightedMeshComponent()));
254 
255  // Connection for process model to GUI
256  connect(modellingTabWidget->treeView,
257  SIGNAL(processVarRemoved(QString const&)), _processModel.get(),
258  SLOT(removeProcessVariable(QString const&)));
259  connect(modellingTabWidget->treeView,
260  SIGNAL(conditionRemoved(QString const&, QString const&)),
261  _processModel.get(),
262  SLOT(removeCondition(QString const&, QString const&)));
263  connect(modellingTabWidget->treeView, SIGNAL(clearConditionView()),
264  _conditionModel.get(), SLOT(clearView()));
265  connect(modellingTabWidget->treeView,
266  SIGNAL(processVarSelected(DataHolderLib::FemCondition*)),
267  _conditionModel.get(),
268  SLOT(setProcessVariable(DataHolderLib::FemCondition*)));
269  connect(modellingTabWidget->treeView,
270  SIGNAL(conditionSelected(DataHolderLib::FemCondition*)),
271  _conditionModel.get(),
272  SLOT(setFemCondition(DataHolderLib::FemCondition*)));
273  connect(modellingTabWidget->treeView,
274  SIGNAL(processVarSelected(DataHolderLib::FemCondition*)),
275  modellingTabWidget->conditionView, SLOT(updateView()));
276  connect(modellingTabWidget->treeView,
277  SIGNAL(conditionSelected(DataHolderLib::FemCondition*)),
278  modellingTabWidget->conditionView, SLOT(updateView()));
279 
280  // VisPipeline Connects
281  connect(_geo_model.get(),
282  SIGNAL(geoDataAdded(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
283  _vtkVisPipeline.get(),
284  SLOT(addPipelineItem(GeoTreeModel*, std::string, GeoLib::GEOTYPE)));
285  connect(
286  _geo_model.get(),
287  SIGNAL(geoDataRemoved(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
288  _vtkVisPipeline.get(),
289  SLOT(removeSourceItem(GeoTreeModel*, std::string, GeoLib::GEOTYPE)));
290 
291  connect(_geo_model.get(),
292  SIGNAL(stationVectorAdded(StationTreeModel*, std::string)),
293  _vtkVisPipeline.get(),
294  SLOT(addPipelineItem(StationTreeModel*, std::string)));
295  connect(_geo_model.get(),
296  SIGNAL(stationVectorRemoved(StationTreeModel*, std::string)),
297  _vtkVisPipeline.get(),
298  SLOT(removeSourceItem(StationTreeModel*, std::string)));
299 
300  connect(_meshModel.get(), SIGNAL(meshAdded(MeshModel*, QModelIndex)),
301  _vtkVisPipeline.get(),
302  SLOT(addPipelineItem(MeshModel*, QModelIndex)));
303  connect(_meshModel.get(), SIGNAL(meshRemoved(MeshModel*, QModelIndex)),
304  _vtkVisPipeline.get(),
305  SLOT(removeSourceItem(MeshModel*, QModelIndex)));
306 
307  connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
308  visualizationWidget->vtkWidget, SLOT(update()));
309  connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
310  vtkVisTabWidget->vtkVisPipelineView, SLOT(expandAll()));
311  connect(_vtkVisPipeline.get(), SIGNAL(itemSelected(const QModelIndex&)),
312  vtkVisTabWidget->vtkVisPipelineView,
313  SLOT(selectItem(const QModelIndex&)));
314 
315  vtkVisTabWidget->vtkVisPipelineView->setModel(_vtkVisPipeline.get());
316  connect(vtkVisTabWidget->vtkVisPipelineView,
317  SIGNAL(requestRemovePipelineItem(QModelIndex)),
318  _vtkVisPipeline.get(), SLOT(removePipelineItem(QModelIndex)));
319  connect(vtkVisTabWidget->vtkVisPipelineView,
320  SIGNAL(requestAddPipelineFilterItem(QModelIndex)), this,
321  SLOT(showAddPipelineFilterItemDialog(QModelIndex)));
322  connect(vtkVisTabWidget, SIGNAL(requestViewUpdate()), visualizationWidget,
323  SLOT(updateView()));
324 
325  connect(vtkVisTabWidget->vtkVisPipelineView,
326  SIGNAL(actorSelected(vtkProp3D*)),
327  reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
328  SLOT(highlightActor(vtkProp3D*)));
329  connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
330  visualizationWidget, SLOT(updateView()));
331 
332  // Propagates selected vtk object in the pipeline to the pick interactor
333  connect(vtkVisTabWidget->vtkVisPipelineView,
334  SIGNAL(dataObjectSelected(vtkDataObject*)),
335  reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
336  SLOT(pickableDataObject(vtkDataObject*)));
337  connect(reinterpret_cast<QObject*>(visualizationWidget->vtkPickCallback()),
338  SIGNAL(actorPicked(vtkProp3D*)),
339  vtkVisTabWidget->vtkVisPipelineView, SLOT(selectItem(vtkProp3D*)));
340  connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
341  SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
342  const unsigned)),
343  this->_elementModel.get(),
344  SLOT(setElement(vtkUnstructuredGridAlgorithm const* const,
345  const unsigned)));
346  connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
347  SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
348  const unsigned)),
349  meshTabWidget->elementView, SLOT(updateView()));
350  connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
351  SIGNAL(clearElementView()), this->_elementModel.get(),
352  SLOT(clearView()));
353  connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
354  SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
355  const unsigned)),
356  this->_vtkVisPipeline.get(),
357  SLOT(removeHighlightedMeshComponent()));
358 
359  connect(vtkVisTabWidget->vtkVisPipelineView,
360  SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
361  SLOT(addMesh(MeshLib::Mesh*)));
362 
363  // Stack the data dock widgets together
364  tabifyDockWidget(geoDock, mshDock);
365  tabifyDockWidget(mshDock, modellingDock);
366  tabifyDockWidget(modellingDock, stationDock);
367 
368  // Restore window geometry
369  readSettings();
370 
371  // Get info on screens geometry(ies)
372  _vtkWidget.reset(visualizationWidget->vtkWidget);
373  for (auto const& screen : QGuiApplication::screens())
374  {
375  _screenGeometries.push_back(screen->availableGeometry());
376  }
377 
378  // Setup import files menu
379  QMenu* import_files_menu = createImportFilesMenu(); // owned by MainWindow
380  menu_File->insertMenu(action_Exit, import_files_menu);
381 
382  // Setup recent files menu
383  RecentFiles* recentFiles =
384  new RecentFiles(this, SLOT(openRecentFile()), "recentFileList");
385  connect(this, SIGNAL(fileUsed(QString)), recentFiles,
386  SLOT(setCurrentFile(QString)));
387  menu_File->insertMenu(action_Exit, recentFiles->menu());
388 
389  // Setup Windows menu
390  QAction* showGeoDockAction = geoDock->toggleViewAction();
391  showGeoDockAction->setStatusTip(tr("Shows / hides the geometry view"));
392  connect(showGeoDockAction, SIGNAL(triggered(bool)), this,
393  SLOT(showGeoDockWidget(bool)));
394  menuWindows->addAction(showGeoDockAction);
395 
396  QAction* showStationDockAction = stationDock->toggleViewAction();
397  showStationDockAction->setStatusTip(tr("Shows / hides the station view"));
398  connect(showStationDockAction, SIGNAL(triggered(bool)), this,
399  SLOT(showStationDockWidget(bool)));
400  menuWindows->addAction(showStationDockAction);
401 
402  QAction* showMshDockAction = mshDock->toggleViewAction();
403  showMshDockAction->setStatusTip(tr("Shows / hides the mesh view"));
404  connect(showMshDockAction, SIGNAL(triggered(bool)), this,
405  SLOT(showMshDockWidget(bool)));
406  menuWindows->addAction(showMshDockAction);
407 
408  QAction* showModellingDockAction = modellingDock->toggleViewAction();
409  showModellingDockAction->setStatusTip(tr("Shows / hides the Process view"));
410  connect(showModellingDockAction, SIGNAL(triggered(bool)), this,
411  SLOT(showConditionDockWidget(bool)));
412  menuWindows->addAction(showModellingDockAction);
413 
414  QAction* showVisDockAction = vtkVisDock->toggleViewAction();
415  showVisDockAction->setStatusTip(tr("Shows / hides the VTK Pipeline view"));
416  connect(showVisDockAction, SIGNAL(triggered(bool)), this,
417  SLOT(showVisDockWidget(bool)));
418  menuWindows->addAction(showVisDockAction);
419 
420  // Presentation mode
421  auto* presentationMenu = new QMenu(this);
422  presentationMenu->setTitle("Presentation on");
423  connect(presentationMenu, SIGNAL(aboutToShow()), this,
424  SLOT(createPresentationMenu()));
425  menuWindows->insertMenu(showVisDockAction, presentationMenu);
426 
427  _visPrefsDialog = std::make_unique<VisPrefsDialog>(*_vtkVisPipeline,
428  *visualizationWidget);
429 }
430 
431 void MainWindow::closeEvent(QCloseEvent* event)
432 {
433  writeSettings();
434  QWidget::closeEvent(event);
435 }
436 
438 {
439  if (show)
440  {
441  geoDock->show();
442  }
443  else
444  {
445  geoDock->hide();
446  }
447 }
448 
450 {
451  if (show)
452  {
453  stationDock->show();
454  }
455  else
456  {
457  stationDock->hide();
458  }
459 }
460 
462 {
463  if (show)
464  {
465  mshDock->show();
466  }
467  else
468  {
469  mshDock->hide();
470  }
471 }
472 
474 {
475  if (show)
476  {
477  modellingDock->show();
478  }
479  else
480  {
481  modellingDock->hide();
482  }
483 }
484 
486 {
487  if (show)
488  {
489  vtkVisDock->show();
490  }
491  else
492  {
493  vtkVisDock->hide();
494  }
495 }
496 
497 void MainWindow::open(int file_type)
498 {
499  QSettings settings;
500  auto t = static_cast<ImportFileType::type>(file_type);
501  QString type_str = QString::fromStdString(
503  QString fileName = QFileDialog::getOpenFileName(
504  this, "Select " + type_str + " file to import",
505  settings.value("lastOpenedFileDirectory").toString(),
506  QString::fromStdString(ImportFileType::getFileSuffixString(t)));
507  if (!fileName.isEmpty())
508  {
509  loadFile(t, fileName);
510  QDir dir = QDir(fileName);
511  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
512  }
513 }
514 
516 {
517  auto* action = qobject_cast<QAction*>(sender());
518  if (action)
519  {
520  loadFile(ImportFileType::OGS, action->data().toString());
521  }
522 }
523 
525 {
526  QString fileName = QFileDialog::getSaveFileName(
527  this,
528  "Save data as",
530  "GeoSys project (*.prj);;GMSH geometry files (*.geo)");
531 
532  if (fileName.isEmpty())
533  {
534  OGSError::box("No filename specified.");
535  return;
536  }
537 
538  QFileInfo fi(fileName);
540 
541  if (fi.suffix().toLower() == "prj")
542  {
545  fileName.toStdString());
546  }
547  else if (fi.suffix().toLower() == "geo")
548  {
549  auto const selected_geometries =
551 
552  // values necessary also for the adaptive meshing
553  const double point_density = 0;
554  const double station_density = point_density;
555  const int max_pnts_per_leaf = 0;
556 
558  _project.getGEOObjects(), true,
560  station_density, max_pnts_per_leaf, selected_geometries, false,
561  false);
562  bool const success = BaseLib::IO::writeStringToFile(
563  gmsh_io.writeToString(), fileName.toStdString());
564 
565  if (!success)
566  {
567  OGSError::box(" No geometry available\n to write to geo-file");
568  }
569  }
570 }
571 
572 void MainWindow::loadFile(ImportFileType::type t, const QString& fileName)
573 {
574  QFile file(fileName);
575  if (!file.exists())
576  {
577  QMessageBox::warning(this, tr("Application"),
578  tr("Cannot read file %1:\n%2.")
579  .arg(fileName)
580  .arg(file.errorString()));
581  return;
582  }
583 
584  QApplication::setOverrideCursor(Qt::WaitCursor);
585  QFileInfo fi(fileName);
586  QSettings settings;
587  QDir dir = QDir(fileName);
588  std::string base =
589  fi.absoluteDir().absoluteFilePath(fi.completeBaseName()).toStdString();
590 
591  if (t == ImportFileType::OGS || t == ImportFileType::OGS_GEO ||
593  {
594  if (fi.suffix().toLower() == "gli")
595  {
596  std::string unique_name;
597  std::vector<std::string> errors;
598  std::string const gmsh_path =
599  settings.value("DataExplorerGmshPath").toString().toStdString();
600  if (!FileIO::Legacy::readGLIFileV4(fileName.toStdString(),
602  unique_name, errors, gmsh_path))
603  {
604  for (auto& error : errors)
605  {
606  OGSError::box(QString::fromStdString(error));
607  }
608  }
609  }
610  else if (fi.suffix().toLower() == "prj")
611  {
613  if (xml.readFile(fileName))
614  {
615  _meshModel->updateModel();
616  _processModel->updateModel();
617  }
618  else
619  {
621  "Failed to load project file.\n Please see console for "
622  "details.");
623  }
624  }
625  else if (fi.suffix().toLower() == "gml")
626  {
628  try
629  {
630  if (!xml.readFile(fileName))
631  {
633  "Failed to load geometry.\n Please see console for "
634  "details.");
635  }
636  }
637  catch (std::runtime_error const& err)
638  {
639  OGSError::box(err.what(),
640  "Failed to read file `" + fileName + "'");
641  }
642  }
643  // OpenGeoSys observation station files (incl. boreholes)
644  else if (fi.suffix().toLower() == "stn")
645  {
647  if (!xml.readFile(fileName))
648  {
650  "Failed to load station data.\n Please see console for "
651  "details.");
652  }
653  }
654  // OpenGeoSys mesh files
655  else if (fi.suffix().toLower() == "msh" ||
656  fi.suffix().toLower() == "vtu" ||
657  fi.suffix().toLower() == "vtk")
658  {
659 #ifndef NDEBUG
660  QElapsedTimer myTimer;
661  myTimer.start();
662 #endif
663  std::unique_ptr<MeshLib::Mesh> mesh(
664  MeshLib::IO::readMeshFromFile(fileName.toStdString()));
665 #ifndef NDEBUG
666  INFO("Mesh loading time: {:d} ms.", myTimer.restart());
667 #endif
668  if (mesh)
669  {
670  _meshModel->addMesh(std::move(mesh));
671  }
672  else
673  {
674  OGSError::box("Failed to load mesh file.");
675  }
676 #ifndef NDEBUG
677  INFO("Mesh model setup time: {:d} ms.", myTimer.elapsed());
678 #endif
679  }
680 
681  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
682  emit fileUsed(fileName);
683  }
684  else if (t == ImportFileType::FEFLOW)
685  {
686  if (fi.suffix().toLower() == "fem") // FEFLOW model files
687  {
688  FileIO::FEFLOWMeshInterface feflowMeshIO;
689  std::unique_ptr<MeshLib::Mesh> mesh(
690  feflowMeshIO.readFEFLOWFile(fileName.toStdString()));
691  if (mesh)
692  {
693  _meshModel->addMesh(std::move(mesh));
694  }
695  else
696  {
697  OGSError::box("Failed to load a FEFLOW mesh.");
698  }
699  FileIO::FEFLOWGeoInterface feflowGeoIO;
700  feflowGeoIO.readFEFLOWFile(fileName.toStdString(),
702  }
703  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
704  }
705  else if (t == ImportFileType::GMS)
706  {
707  if (fi.suffix().toLower() == "txt") // GMS borehole files
708  {
709  auto boreholes = std::make_unique<std::vector<GeoLib::Point*>>();
710  std::string name = fi.baseName().toStdString();
711 
712  if (GMSInterface::readBoreholesFromGMS(boreholes.get(),
713  fileName.toStdString()))
714  {
715  _project.getGEOObjects().addStationVec(std::move(boreholes),
716  name);
717  }
718  else
719  {
720  OGSError::box("Error reading GMS file.");
721  }
722  }
723  else if (fi.suffix().toLower() == "3dm") // GMS mesh files
724  {
725  std::string name = fileName.toStdString();
726  std::unique_ptr<MeshLib::Mesh> mesh(
727  GMSInterface::readGMS3DMMesh(name));
728  if (mesh)
729  {
730  _meshModel->addMesh(std::move(mesh));
731  }
732  else
733  {
734  OGSError::box("Failed to load a GMS mesh.");
735  }
736  }
737  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
738  }
739  else if (t == ImportFileType::GMSH)
740  {
741  std::string msh_name(fileName.toStdString());
742  if (FileIO::GMSH::isGMSHMeshFile(msh_name))
743  {
744  std::unique_ptr<MeshLib::Mesh> mesh(
745  FileIO::GMSH::readGMSHMesh(msh_name));
746  if (mesh)
747  {
748  _meshModel->addMesh(std::move(mesh));
749  }
750  else
751  {
752  OGSError::box("Failed to load a GMSH mesh.");
753  }
754  }
755  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
756  }
757  else if (t == ImportFileType::GOCAD_TSURF)
758  {
759  std::string file_name(fileName.toStdString());
760  std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
761  if (FileIO::Gocad::GocadAsciiReader::readFile(file_name, meshes))
762  {
763  for (auto& mesh : meshes)
764  {
765  if (mesh != nullptr)
766  {
767  _meshModel->addMesh(std::move(mesh));
768  }
769  }
770  }
771  else
772  {
773  OGSError::box("Error reading file.");
774  }
775  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
776  }
777 #ifdef OGS_USE_NETCDF
778  else if (t == ImportFileType::NETCDF) // CH 01.2012
779  {
780  NetCdfConfigureDialog dlg(fileName.toStdString());
781  dlg.exec();
782  if (dlg.getMesh())
783  {
784  std::unique_ptr<MeshLib::Mesh> mesh(dlg.getMesh());
785  mesh->setName(dlg.getName());
786  _meshModel->addMesh(std::move(mesh));
787  }
788  if (dlg.getRaster())
789  _vtkVisPipeline->addPipelineItem(dlg.getRaster());
790 
791  settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
792  }
793 #endif // OGS_USE_NETCDF
794  else if (t == ImportFileType::RASTER)
795  {
797  if (geoImage->readImage(fileName))
798  {
799  _vtkVisPipeline->addPipelineItem(geoImage);
800  }
801  else
802  {
803  geoImage->Delete();
804  OGSError::box("Error reading raster.");
805  }
806  settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
807  }
808  else if (t == ImportFileType::POLYRASTER)
809  {
810  QImage raster;
811  vtkImageAlgorithm* img = VtkRaster::loadImage(fileName.toStdString());
813  double* origin = img->GetOutput()->GetOrigin();
814  bg->SetRaster(img, origin[0], origin[1],
815  img->GetOutput()->GetSpacing()[0]);
816  bg->SetName(fileName);
817  _vtkVisPipeline->addPipelineItem(bg);
818  settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
819  }
820  else if (t == ImportFileType::SHAPE)
821  {
822  SHPImportDialog dlg(
823  fileName.toStdString(), _project.getGEOObjects(),
824  settings.value("DataExplorerGmshPath").toString().toStdString());
825  dlg.exec();
826  QDir dir = QDir(fileName);
827  settings.setValue("lastOpenedShapeFileDirectory", dir.absolutePath());
828  }
829  else if (t == ImportFileType::TETGEN)
830  {
831  if (fi.suffix().toLower().compare("poly") == 0 ||
832  fi.suffix().toLower().compare("smesh") == 0)
833  {
835  tetgen.readTetGenGeometry(fileName.toStdString(),
837  }
838  else
839  {
840  settings.setValue("lastOpenedTetgenFileDirectory",
841  QFileInfo(fileName).absolutePath());
842  QString element_fname(fi.path() + "/" + fi.completeBaseName() +
843  ".ele");
844 
845  if (!fileName.isEmpty())
846  {
848  std::unique_ptr<MeshLib::Mesh> mesh(tetgen.readTetGenMesh(
849  fileName.toStdString(), element_fname.toStdString()));
850  if (mesh)
851  {
852  _meshModel->addMesh(std::move(mesh));
853  }
854  else
855  {
856  OGSError::box("Failed to load a TetGen mesh.");
857  }
858  }
859  }
860  }
861  else if (t == ImportFileType::VTK)
862  {
863  _vtkVisPipeline->loadFromFile(fileName);
864  settings.setValue("lastOpenedVtkFileDirectory", dir.absolutePath());
865  }
866 
867  QApplication::restoreOverrideCursor();
868  updateDataViews();
869 }
870 
872 {
873  visualizationWidget->updateViewOnLoad();
874  geoTabWidget->treeView->updateView();
875  stationTabWidget->treeView->updateView();
876  meshTabWidget->treeView->updateView();
877 }
878 
880 {
881  QSettings settings;
882 
883  restoreGeometry(settings.value("windowGeometry").toByteArray());
884  restoreState(settings.value("windowState").toByteArray());
885 }
886 
888 {
889  QSettings settings;
890 
891  settings.setValue("windowGeometry", saveGeometry());
892  settings.setValue("windowState", saveState());
893 }
894 
896 {
897  LicenseDialog dlg;
898  dlg.exec();
899 }
900 
902 {
903  QString about(
904  "<a href='https://www.opengeosys.org'>www.opengeosys.org</a><br /><br "
905  "/>");
906  about.append(
907  QString("Version: %1<br />")
908  .arg(QString::fromStdString(GitInfoLib::GitInfo::ogs_version)));
909 
910  about.append(
911  QString("Git commit: <a "
912  "href='https://github.com/ufz/ogs/commit/%1'>%1</a><br />")
913  .arg(QString::fromStdString(
915  about.append(QString("Built date: %1<br />")
916  .arg(QDate::currentDate().toString(Qt::ISODate)));
917 
918  QMessageBox::about(this, "About OpenGeoSys 6", about);
919 }
920 
922 {
923  QMenu* importFiles = new QMenu("&Import Files", this);
924  importFiles->addAction("&FEFLOW Files...",
925  [this] { open(ImportFileType::FEFLOW); });
926  importFiles->addAction("G&MS Files...",
927  [this] { open(ImportFileType::GMS); });
928  importFiles->addAction("&GMSH Files...",
929  [this] { open(ImportFileType::GMSH); });
930  importFiles->addAction("&Gocad TSurface...",
931  [this] { open(ImportFileType::GOCAD_TSURF); });
932 #ifdef OGS_USE_NETCDF
933  importFiles->addAction("&NetCDF Files...",
934  [this] { open(ImportFileType::NETCDF); });
935 #endif // OGS_USE_NETCDF
936  importFiles->addAction("&Petrel Files...", [this] { loadPetrelFiles(); });
937  importFiles->addAction("&Raster Files...",
938  [this] { open(ImportFileType::RASTER); });
939  importFiles->addAction("&Shape Files...",
940  [this] { open(ImportFileType::SHAPE); });
941  importFiles->addAction("&TetGen Files...",
942  [this] { open(ImportFileType::TETGEN); });
943  importFiles->addAction("&VTK Files...",
944  [this] { open(ImportFileType::VTK); });
945  return importFiles;
946 }
947 
949 {
950  QSettings settings;
951  QStringList sfc_file_names = QFileDialog::getOpenFileNames(
952  this, "Select surface data file(s) to import", "", "Petrel files (*)");
953  QStringList well_path_file_names = QFileDialog::getOpenFileNames(
954  this, "Select well path data file(s) to import", "",
955  "Petrel files (*)");
956  if (!sfc_file_names.empty() || !well_path_file_names.empty())
957  {
958  QStringList::const_iterator it = sfc_file_names.begin();
959  std::list<std::string> sfc_files;
960  while (it != sfc_file_names.end())
961  {
962  sfc_files.push_back((*it).toStdString());
963  ++it;
964  }
965 
966  it = well_path_file_names.begin();
967  std::list<std::string> well_path_files;
968  while (it != well_path_file_names.end())
969  {
970  well_path_files.push_back((*it).toStdString());
971  ++it;
972  }
973 
974  std::string unique_str(*(sfc_files.begin()));
975 
976  PetrelInterface(sfc_files, well_path_files, unique_str,
978 
979  QDir dir = QDir(sfc_file_names.at(0));
980  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
981  }
982 }
983 
984 void MainWindow::showAddPipelineFilterItemDialog(QModelIndex parentIndex)
985 {
986  VtkAddFilterDialog dlg(*_vtkVisPipeline, parentIndex);
987  dlg.exec();
988 }
989 
990 void MainWindow::writeGeometryToFile(QString gliName, QString fileName)
991 {
992 #ifndef NDEBUG
993  QFileInfo fi(fileName);
994  if (fi.suffix().toLower() == "gli")
995  {
996  FileIO::Legacy::writeAllDataToGLIFileV4(fileName.toStdString(),
998  return;
999  }
1000 #endif
1002  xml.export_name = gliName.toStdString();
1003  BaseLib::IO::writeStringToFile(xml.writeToString(), fileName.toStdString());
1004 }
1005 
1006 void MainWindow::writeStationListToFile(QString listName, QString fileName)
1007 {
1009  xml.export_name = listName.toStdString();
1010  BaseLib::IO::writeStringToFile(xml.writeToString(), fileName.toStdString());
1011 }
1012 
1013 void MainWindow::mapGeometry(const std::string& geo_name)
1014 {
1016  if (dlg.exec() != QDialog::Accepted)
1017  {
1018  return;
1019  }
1020 
1021  int choice(dlg.getDataSetChoice());
1022 
1023  QString file_name("");
1024  if (choice < 2) // load something from a file
1025  {
1026  QString file_type[2] = {"OpenGeoSys mesh files (*.vtu *.msh)",
1027  "Raster files(*.asc *.grd)"};
1028  QSettings settings;
1029  file_name = QFileDialog::getOpenFileName(
1030  this,
1031  "Select file for mapping",
1032  settings.value("lastOpenedFileDirectory").toString(),
1033  file_type[choice]);
1034  if (file_name.isEmpty())
1035  {
1036  return;
1037  }
1038  QDir dir = QDir(file_name);
1039  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
1040  }
1041 
1042  MeshGeoToolsLib::GeoMapper geo_mapper(_project.getGEOObjects(), geo_name);
1043  QFileInfo fi(file_name);
1044  if (choice == 1) // load raster from file
1045  {
1046  if (fi.suffix().toLower() == "asc" || fi.suffix().toLower() == "grd")
1047  {
1048  std::unique_ptr<GeoLib::Raster> raster(
1050  file_name.toStdString()));
1051  if (raster)
1052  {
1053  geo_mapper.mapOnDEM(std::move(raster));
1054  }
1055  else
1056  {
1057  OGSError::box("Error reading raster file.");
1058  }
1059  _geo_model->updateGeometry(geo_name);
1060  }
1061  else
1062  {
1063  OGSError::box("The selected file is no supported raster file.");
1064  }
1065  return;
1066  }
1067 
1068  MeshLib::Mesh* mesh(nullptr);
1069  if (choice == 0) // load mesh from file
1070  {
1071  if (fi.suffix().toLower() == "vtu" || fi.suffix().toLower() == "vtk" ||
1072  fi.suffix().toLower() == "msh")
1073  {
1074  mesh = MeshLib::IO::readMeshFromFile(file_name.toStdString());
1075  }
1076  else
1077  {
1078  OGSError::box("The selected file is no supported mesh file.");
1079  return;
1080  }
1081  }
1082  else
1083  { // use mesh from ProjectData
1084  mesh = _project.getMeshObjects()[choice - 2].get();
1085  }
1086 
1087  std::string new_geo_name = dlg.getNewGeoName();
1088 
1089  if (new_geo_name.empty())
1090  {
1091  geo_mapper.mapOnMesh(mesh);
1092  _geo_model->updateGeometry(geo_name);
1093  }
1094  else
1095  {
1097  new_geo_name);
1098  new_geo_name = dup.getFinalizedOutputName();
1100  new_geo_name);
1101  mapper.advancedMapOnMesh(*mesh);
1102  _geo_model->updateGeometry(new_geo_name);
1103  }
1104  if (choice == 0)
1105  {
1106  delete mesh;
1107  }
1108 }
1109 
1111 {
1113 }
1114 
1115 void MainWindow::exportBoreholesToGMS(std::string listName,
1116  std::string fileName)
1117 {
1118  const std::vector<GeoLib::Point*>* stations(
1119  _project.getGEOObjects().getStationVec(listName));
1120  GMSInterface::writeBoreholesToGMS(stations, fileName);
1121 }
1122 
1123 void MainWindow::callGMSH(std::vector<std::string>& selectedGeometries,
1124  unsigned param1, double param2, double param3,
1125  double param4, bool delete_geo_file)
1126 {
1127  if (!selectedGeometries.empty())
1128  {
1129  INFO("Start meshing ...");
1130 
1131  QString fileName("");
1132  QString dir_str = this->getLastUsedDir();
1133 
1134  if (!delete_geo_file)
1135  {
1136  fileName = QFileDialog::getSaveFileName(
1137  this, "Save GMSH-file as",
1138  LastSavedFileDirectory::getDir() + "tmp_gmsh.geo",
1139  "GMSH geometry files (*.geo)");
1140  }
1141  else
1142  {
1143  fileName = "tmp_gmsh.geo";
1144  }
1145 
1146  if (!fileName.isEmpty())
1147  {
1148  if (param4 == -1)
1149  { // adaptive meshing selected
1151  _project.getGEOObjects(), true,
1153  param2, param3, param1, selectedGeometries, false, false);
1155  fileName.toStdString());
1156  }
1157  else
1158  { // homogeneous meshing selected
1160  _project.getGEOObjects(), true,
1162  param4, param3, param1, selectedGeometries, false, false);
1164  fileName.toStdString());
1165  }
1166 
1167  if (system(nullptr) != 0) // command processor available
1168  {
1169  QSettings settings;
1170  std::string gmsh_path = settings.value("DataExplorerGmshPath")
1171  .toString()
1172  .toStdString();
1173 
1174  if (!gmsh_path.empty())
1175  {
1176  std::string fname(fileName.toStdString());
1177  std::string gmsh_command =
1178  "\"" + gmsh_path + "\" -2 -algo meshadapt " + fname;
1179  std::size_t pos(fname.rfind("."));
1180  if (pos != std::string::npos)
1181  {
1182  fname = fname.substr(0, pos);
1183  }
1184  gmsh_command += " -o " + fname + ".msh";
1185  // Newer gmsh versions write a newer file format for meshes
1186  // per default. At the moment we can't read this new format.
1187  // This is a switch for gmsh to write the 'old' file format.
1188  gmsh_command += " -format msh22";
1189  auto const return_value = std::system(gmsh_command.c_str());
1190  if (return_value != 0)
1191  {
1192  QString const message =
1193  "Execution of gmsh command returned non-zero "
1194  "status, " +
1195  QString::number(return_value);
1196  OGSError::box(message, "Error");
1197  }
1198  else
1199  {
1200  this->loadFile(
1202  fileName.left(fileName.length() - 3).append("msh"));
1203  }
1204  }
1205  else
1206  {
1207  OGSError::box("Location of GMSH not specified.", "Error");
1208  }
1209  }
1210  else
1211  {
1212  OGSError::box(
1213  "Error executing command gmsh - no command processor "
1214  "available",
1215  "Error");
1216  }
1217 
1218  if (delete_geo_file)
1219  {
1220  BaseLib::removeFile(fileName.toStdString());
1221  }
1222  }
1223  }
1224  else
1225  INFO("No geometry information selected.");
1226  QApplication::restoreOverrideCursor();
1227 }
1228 
1230 {
1231  QSettings settings;
1232  auto* dlg = new OGSFileConverter(
1233  settings.value("DataExplorerGmshPath").toString().toStdString(), this);
1234  dlg->setAttribute(Qt::WA_DeleteOnClose);
1235  dlg->show();
1236  dlg->raise();
1237 }
1238 
1239 void MainWindow::showDiagramPrefsDialog(QModelIndex& index)
1240 {
1241  QString listName;
1242  GeoLib::Station* stn =
1243  _geo_model->getStationModel()->stationFromIndex(index, listName);
1244 
1245  if (dynamic_cast<GeoLib::StationBorehole*>(stn))
1246  {
1247  OGSError::box("No time series data available for borehole.");
1248  }
1249  else if (dynamic_cast<GeoLib::Station*>(stn) && stn->getSensorData())
1250  {
1251  auto* prefs(new DiagramPrefsDialog(stn));
1252  prefs->setAttribute(Qt::WA_DeleteOnClose);
1253  prefs->show();
1254  }
1255 }
1256 
1258 {
1259  QSettings settings;
1260  QString fileName = QFileDialog::getOpenFileName(
1261  this, "Select data file to open",
1262  settings.value("lastOpenedFileDirectory").toString(),
1263  "Text files (*.txt);;All files (* *.*)");
1264  if (!fileName.isEmpty())
1265  {
1266  QDir dir = QDir(fileName);
1267  settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
1268  auto* prefs = new DiagramPrefsDialog(fileName);
1269  prefs->setAttribute(Qt::WA_DeleteOnClose);
1270  prefs->show();
1271  }
1272 }
1273 
1274 void MainWindow::showGeoNameDialog(const std::string& geometry_name,
1275  const GeoLib::GEOTYPE object_type,
1276  std::size_t id)
1277 {
1278  std::string old_name = _project.getGEOObjects().getElementNameByID(
1279  geometry_name, object_type, id);
1280  SetNameDialog dlg(GeoLib::convertGeoTypeToString(object_type), id,
1281  old_name);
1282  if (dlg.exec() != QDialog::Accepted)
1283  {
1284  return;
1285  }
1286 
1287  _geo_model->addNameForElement(geometry_name, object_type, id,
1288  dlg.getNewName());
1289  static_cast<GeoTreeModel*>(this->geoTabWidget->treeView->model())
1290  ->setNameForItem(geometry_name, object_type, id,
1292  geometry_name, object_type, id));
1293 }
1294 
1295 void MainWindow::showStationNameDialog(const std::string& stn_vec_name,
1296  std::size_t id)
1297 {
1298  std::vector<GeoLib::Point*> const* stations =
1299  _project.getGEOObjects().getStationVec(stn_vec_name);
1300  auto* const stn = static_cast<GeoLib::Station*>((*stations)[id]);
1301  SetNameDialog dlg("Station", id, stn->getName());
1302  if (dlg.exec() != QDialog::Accepted)
1303  {
1304  return;
1305  }
1306 
1307  stn->setName(dlg.getNewName());
1308  static_cast<StationTreeModel*>(this->stationTabWidget->treeView->model())
1309  ->setNameForItem(stn_vec_name, id, stn->getName());
1310 }
1311 
1313 {
1315  connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
1316  SLOT(addMesh(MeshLib::Mesh*)));
1317  dlg.exec();
1318 }
1319 
1321 {
1323  connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
1324  SLOT(addMesh(MeshLib::Mesh*)));
1325  dlg.exec();
1326 }
1327 
1329 {
1330  auto* dlg = new MeshAnalysisDialog(this->_project.getMeshObjects());
1331  dlg->exec();
1332 }
1333 
1334 void MainWindow::convertPointsToStations(std::string const& geo_name)
1335 {
1336  std::string stn_name = geo_name + " Stations";
1337  int ret = GeoLib::geoPointsToStations(_project.getGEOObjects(), geo_name,
1338  stn_name);
1339  if (ret == 1)
1340  {
1341  OGSError::box("No points found to convert.");
1342  }
1343 }
1344 
1345 void MainWindow::showLineEditDialog(const std::string& geoName)
1346 {
1347  LineEditDialog lineEdit(
1348  *(_project.getGEOObjects().getPolylineVecObj(geoName)));
1349  connect(
1350  &lineEdit,
1351  SIGNAL(connectPolylines(const std::string&, std::vector<std::size_t>,
1352  double, std::string, bool, bool)),
1353  _geo_model.get(),
1354  SLOT(connectPolylineSegments(const std::string&,
1355  std::vector<std::size_t>, double,
1356  std::string, bool, bool)));
1357  lineEdit.exec();
1358 }
1359 
1361 {
1363  connect(&dlg,
1364  SIGNAL(requestMeshing(std::vector<std::string>&, unsigned, double,
1365  double, double, bool)),
1366  this,
1367  SLOT(callGMSH(std::vector<std::string>&, unsigned, double, double,
1368  double, bool)));
1369  dlg.exec();
1370 }
1371 
1373 {
1375  if (dlg.exec() != QDialog::Accepted)
1376  {
1377  return;
1378  }
1379  std::string name(dlg.getGeometryName());
1381  name) < 0)
1382  {
1383  OGSError::box("Points are missing for\n at least one geometry.");
1384  }
1385 }
1386 
1388  MeshLib::VtkMappedMeshSource* mshSource)
1389 {
1390  if (mshSource == nullptr)
1391  {
1392  return;
1393  }
1394 
1396  if (dlg.exec() != QDialog::Accepted)
1397  {
1398  return;
1399  }
1400  MeshLib::MeshQualityType const type(dlg.getSelectedMetric());
1401  MeshLib::ElementQualityInterface quality_interface(*mshSource->GetMesh(),
1402  type);
1403  _vtkVisPipeline->showMeshElementQuality(
1404  mshSource, type, quality_interface.getQualityVector());
1405 
1406  if (dlg.getHistogram())
1407  {
1408  quality_interface.writeHistogram(dlg.getHistogramPath());
1409  }
1410 }
1411 
1413 {
1414  _visPrefsDialog->show();
1415 }
1416 
1418 {
1420  dlg.exec();
1421 }
1422 
1424 
1426 {
1427  this->show();
1428 }
1429 
1431 {
1432  this->hide();
1433 }
1434 
1435 void MainWindow::loadFileOnStartUp(const QString& fileName)
1436 {
1437  QString ext = QFileInfo(fileName).suffix();
1438  if (ext == "msh" || ext == "vtu" || ext == "gli" || ext == "gml")
1439  {
1440  this->loadFile(ImportFileType::OGS, fileName);
1441  }
1442 }
1443 
1444 void MainWindow::on_actionExportVTK_triggered(bool checked /*= false*/)
1445 {
1446  Q_UNUSED(checked)
1447  QSettings settings;
1448  int count = 0;
1449  QString const filename = QFileDialog::getSaveFileName(
1450  this,
1451  "Export object to vtk-files",
1452  settings.value("lastExportedFileDirectory").toString(),
1453  "VTK files (*.vtp *.vtu)");
1454  if (!filename.isEmpty())
1455  {
1456  QDir const dir = QDir(filename);
1457  settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1458 
1459  std::string const basename =
1460  QFileInfo(filename).path().toStdString() + "/" +
1461  QFileInfo(filename).baseName().toStdString();
1463  ++it;
1464  while (*it)
1465  {
1466  std::string const name = basename + std::to_string(++count) + "-" +
1467  (*it)->data(0).toString().toStdString();
1468  static_cast<VtkVisPipelineItem*>(*it)->writeToFile(name);
1469  ++it;
1470  }
1471  }
1472 }
1473 
1474 void MainWindow::on_actionExportVRML2_triggered(bool checked /*= false*/)
1475 {
1476  Q_UNUSED(checked)
1477  QSettings settings;
1478  QString fileName = QFileDialog::getSaveFileName(
1479  this, "Save scene to VRML file",
1480  settings.value("lastExportedFileDirectory").toString(),
1481  "VRML files (*.wrl);;");
1482  if (!fileName.isEmpty())
1483  {
1484  QDir dir = QDir(fileName);
1485  settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1486 
1487  vtkVRMLExporter* exporter = vtkVRMLExporter::New();
1488  exporter->SetFileName(fileName.toStdString().c_str());
1489  exporter->SetRenderWindow(
1490  visualizationWidget->vtkWidget->GetRenderWindow());
1491  exporter->Write();
1492  exporter->Delete();
1493  }
1494 }
1495 
1496 void MainWindow::on_actionExportObj_triggered(bool checked /*= false*/)
1497 {
1498  Q_UNUSED(checked)
1499  QSettings settings;
1500  QString fileName = QFileDialog::getSaveFileName(
1501  this, "Save scene to Wavefront OBJ files",
1502  settings.value("lastExportedFileDirectory").toString(), ";;");
1503  if (!fileName.isEmpty())
1504  {
1505  QDir dir = QDir(fileName);
1506  settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1507 
1508  vtkOBJExporter* exporter = vtkOBJExporter::New();
1509  exporter->SetFilePrefix(fileName.toStdString().c_str());
1510  exporter->SetRenderWindow(
1511  visualizationWidget->vtkWidget->GetRenderWindow());
1512  exporter->Write();
1513  exporter->Delete();
1514  }
1515 }
1516 
1518 {
1519  auto* menu = static_cast<QMenu*>(QObject::sender());
1520  menu->clear();
1521  if (!_vtkWidget->parent())
1522  {
1523  QAction* action = new QAction("Quit presentation mode", menu);
1524  connect(action, SIGNAL(triggered()), this,
1525  SLOT(quitPresentationMode()));
1526  action->setShortcutContext(Qt::WidgetShortcut);
1527  action->setShortcut(QKeySequence(Qt::Key_Escape));
1528  menu->addAction(action);
1529  }
1530  else
1531  {
1532  int count = 0;
1533  const int currentScreen =
1534  QApplication::desktop()->screenNumber(visualizationWidget);
1535  foreach (QRect screenGeo, _screenGeometries)
1536  {
1537  Q_UNUSED(screenGeo);
1538  QAction* action =
1539  new QAction(QString("On screen %1").arg(count), menu);
1540  connect(action, SIGNAL(triggered()), this,
1541  SLOT(startPresentationMode()));
1542  if (count == currentScreen)
1543  {
1544  action->setEnabled(false);
1545  }
1546  menu->addAction(action);
1547  ++count;
1548  }
1549  }
1550 }
1551 
1553 {
1554  // Save the QMainWindow state to restore when quitting presentation mode
1555  _windowState = this->saveState();
1556 
1557  // Get the screen number from the QAction which sent the signal
1558  QString actionText = static_cast<QAction*>(QObject::sender())->text();
1559  int screen = actionText.split(" ").back().toInt();
1560 
1561  // Move the widget to the screen and maximize it
1562  // Real fullscreen hides the menu
1563  _vtkWidget->setParent(nullptr, Qt::Window);
1564  _vtkWidget->move(
1565  QPoint(_screenGeometries[screen].x(), _screenGeometries[screen].y()));
1566  //_vtkWidget->showFullScreen();
1567  _vtkWidget->showMaximized();
1568 
1569  // Create an action which quits the presentation mode when pressing
1570  // ESCAPE when the the window has focus
1571  QAction* action = new QAction("Quit presentation mode", this);
1572  connect(action, SIGNAL(triggered()), this, SLOT(quitPresentationMode()));
1573  action->setShortcutContext(Qt::WidgetShortcut);
1574  action->setShortcut(QKeySequence(Qt::Key_Escape));
1575  _vtkWidget->addAction(action);
1576 
1577  // Hide the central widget to maximize the dock widgets
1578  QMainWindow::centralWidget()->hide();
1579 }
1580 
1582 {
1583  // Remove the quit action
1584  QAction* action = _vtkWidget->actions().back();
1585  _vtkWidget->removeAction(action);
1586  delete action;
1587 
1588  // Add the widget back to visualization widget
1589  visualizationWidget->layout()->addWidget(_vtkWidget.get());
1590 
1591  QMainWindow::centralWidget()->show();
1592 
1593  // Restore the previously saved QMainWindow state
1594  this->restoreState(_windowState);
1595 }
1596 
1598 {
1599  QSettings settings;
1600  QString fileName("");
1601  QStringList files = settings.value("recentFileList").toStringList();
1602  if (!files.empty())
1603  {
1604  return QFileInfo(files[0]).absolutePath();
1605  }
1606 
1607  return QDir::homePath();
1608 }
Definition of the AsciiRasterInterface class.
Definition of the CreateStructuredGridDialog class.
Definition of the DataExplorerSettingsDialog class.
Definition of the DiagramPrefsDialog class.
Definition of the ElementQualityInterface class.
Definition of the Element class.
Filename manipulation routines.
Definition of the GMSHPrefsDialog class.
Definition of the GMSInterface class.
Definition of the GeoMapper class.
Definition of the GeoOnMeshMappingDialog class.
Definition of the GeoTreeModel class.
Git information.
Implementation of Histogram class.
Manages the last directory used for saving a file.
Definition of the LicenseDialog class.
Definition of the LineEditDialog class.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
Definition of the MergeGeometriesDialog class.
Definition of the MeshAnalysisDialog class.
Definition of the MeshElementRemovalDialog class.
Definition of the MeshIO class.
Definition of the MshQualitySelectionDialog class.
Definition of the MeshSurfaceExtraction class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the OGSError class.
Definition of OGSFileConverter class.
Definition of the OGSIOVer4 class.
Definition of the PetrelInterface class.
Definition of the GeoLib::Raster class.
Definition of the RecentFiles class.
Definition of the SHPImportDialog class.
Definition of the SetNameDialog class.
Definition of the StationTreeModel class.
Definition of the TetGenInterface class.
Definition of the TreeModelIterator class.
Definition of the VtkAddFilterDialog class.
Definition of the VtkBGImageSource class.
Definition of the VtkGeoImageSource class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
Definition of the VtkRaster class.
Definition of the VtkVisPipelineItem class.
Definition of the XmlGmlInterface class.
Definition of the XmlStnInterface class.
std::string writeToString()
Writes the object to a string.
Definition: Writer.cpp:31
A dialog window for managing general Data Explorer settings.
A dialog window for managing general Data Explorer settings.
Base class for boundary conditions, initial conditions and source terms.
Definition: FemCondition.h:40
GeoLib::GEOObjects & getGEOObjects()
Returns the GEOObjects containing all points, polylines and surfaces.
Definition: Project.h:46
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects() const
Returns all the meshes with their respective names.
Definition: Project.h:57
A dialog that allows for setting preferences for a requested diagram.
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
void readFEFLOWFile(const std::string &filename, GeoLib::GEOObjects &geo_objects)
MeshLib::Mesh * readFEFLOWFile(const std::string &filename)
Reads and writes GMSH-files to and from OGS data structures.
Definition: GMSHInterface.h:46
MeshLib::Mesh * readTetGenMesh(std::string const &nodes_fname, std::string const &ele_fname)
bool readTetGenGeometry(std::string const &geo_fname, GeoLib::GEOObjects &geo_objects)
int readFile(const QString &fileName) override
Reads an xml-file containing a project.
A dialog window for setting preferences for GMSH.
std::string const & getFinalizedOutputName() const
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:122
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:435
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:131
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Definition: GEOObjects.cpp:414
Reads and writes GeoObjects to and from XML files.
int readFile(const QString &fileName) override
Reads an xml-file containing geometric object definitions into the GEOObjects used in the constructor...
Reads and writes Observation Sites to and from XML files.
int readFile(const QString &fileName) override
Reads an xml-file containing station object definitions into the GEOObjects used in the constructor (...
A borehole as a geometric object.
A Station (observation site) is basically a Point with some additional information.
Definition: Station.h:37
const SensorData * getSensorData() const
Returns all the sensor data for this observation site.
Definition: Station.h:83
A dialog window for creating DIRECT boundary conditions from raster files.
std::string const & getNewGeoName() const
A model for the GeoTreeView implementing a tree as a double-linked list.
Definition: GeoTreeModel.h:41
static std::string getFileSuffixString(ImportFileType::type t)
static std::string convertImportFileTypeToString(ImportFileType::type t)
static void setDir(const QString &path)
Sets the directory last used for saving a file.
static const QString getDir()
Returns the directory last used for saving a file.
A dialog window displaying the OGS license information.
Definition: LicenseDialog.h:24
A dialog window for manipulation of polylines. Currently included functionality is the concatenation ...
void showConditionDockWidget(bool show)
Definition: mainwindow.cpp:473
void closeEvent(QCloseEvent *event) override
Definition: mainwindow.cpp:431
void readSettings()
Definition: mainwindow.cpp:879
std::unique_ptr< MeshModel > _meshModel
Definition: mainwindow.h:127
void callGMSH(std::vector< std::string > &selectedGeometries, unsigned param1, double param2, double param3, double param4, bool delete_geo_file)
Function calls for generating GMSH files from the GUI.
void open(int file_type=0)
Function calls for opening files.
Definition: mainwindow.cpp:497
void FEMTestStart()
Testing functionality for connection to FEM lib.
QMenu * createImportFilesMenu()
Definition: mainwindow.cpp:921
void showGMSHPrefsDialog()
void quitPresentationMode()
void loadFile(ImportFileType::type t, const QString &fileName)
Definition: mainwindow.cpp:572
void on_actionExportObj_triggered(bool checked=false)
void showFileConverter()
Calls the OGSFileConverter as an external tool.
std::unique_ptr< ElementTreeModel > _elementModel
Definition: mainwindow.h:128
void showStationNameDialog(const std::string &stn_vec_name, std::size_t id)
Allows setting the name for a station.
void save()
Function calls for saving files.
Definition: mainwindow.cpp:524
void writeStationListToFile(QString listName, QString fileName)
void loadFileOnStartUp(const QString &fileName)
void showGeoDockWidget(bool show)
Definition: mainwindow.cpp:437
void writeSettings()
Definition: mainwindow.cpp:887
void showGeoNameDialog(const std::string &geometry_name, const GeoLib::GEOTYPE object_type, std::size_t id)
Allows setting the name for a geometric object.
void showLineEditDialog(const std::string &geoName)
void showStationDockWidget(bool show)
Definition: mainwindow.cpp:449
std::unique_ptr< VisPrefsDialog > _visPrefsDialog
Definition: mainwindow.h:136
void showLicense()
Definition: mainwindow.cpp:895
void convertMeshToGeometry(const MeshLib::Mesh *mesh)
void showDiagramPrefsDialog()
Calls the diagram prefs dialog from the Tools menu.
void showMshDockWidget(bool show)
Definition: mainwindow.cpp:461
QString getLastUsedDir()
void showMeshAnalysisDialog()
void showAddPipelineFilterItemDialog(QModelIndex parentIndex)
Definition: mainwindow.cpp:984
void showCreateStructuredGridDialog()
Creates a structured grid with user-specified parameters.
void about()
Definition: mainwindow.cpp:901
void ShowWindow()
void showMergeGeometriesDialog()
void showVisDockWidget(bool show)
Definition: mainwindow.cpp:485
void showMeshElementRemovalDialog()
Removal of mesh elements based on a number of criteria.
std::unique_ptr< ProcessModel > _processModel
Definition: mainwindow.h:129
void on_actionExportVRML2_triggered(bool checked=false)
void createPresentationMenu()
void openRecentFile()
Definition: mainwindow.cpp:515
DataHolderLib::Project _project
Definition: mainwindow.h:126
void writeGeometryToFile(QString gliName, QString fileName)
Definition: mainwindow.cpp:990
MainWindow(QWidget *parent=nullptr)
Definition: mainwindow.cpp:100
std::unique_ptr< GEOModels > _geo_model
Definition: mainwindow.h:138
void startPresentationMode()
std::unique_ptr< VtkVisPipeline > _vtkVisPipeline
Definition: mainwindow.h:131
void HideWindow()
void loadPetrelFiles()
Definition: mainwindow.cpp:948
void on_actionExportVTK_triggered(bool checked=false)
void showVisalizationPrefsDialog()
std::unique_ptr< QWidget > _vtkWidget
Definition: mainwindow.h:133
void mapGeometry(const std::string &geo_name)
void showMeshQualitySelectionDialog(MeshLib::VtkMappedMeshSource *mshSource)
QList< QRect > _screenGeometries
Definition: mainwindow.h:132
void fileUsed(QString filename)
QByteArray _windowState
Definition: mainwindow.h:134
std::unique_ptr< FemConditionModel > _conditionModel
Definition: mainwindow.h:130
void updateDataViews()
Definition: mainwindow.cpp:871
void showDataExplorerSettingsDialog()
void convertPointsToStations(std::string const &geo_name)
void exportBoreholesToGMS(std::string listName, std::string fileName)
Function calls for GMS export.
A dialog window for setting preferences for GMSH.
std::string getGeometryName() const
Returns the name of the new merged geometry.
std::vector< std::string > getSelectedGeometries() const
Returns a vector of selected geometries.
A dialog window for calling mesh analysis methods.
A dialog window for settung up a database connection.
A set of tools for mapping the elevation of geometric objects.
Definition: GeoMapper.h:40
void mapOnDEM(std::unique_ptr< GeoLib::Raster const > raster)
Maps geometry based on a raster file.
Definition: GeoMapper.cpp:52
void mapOnMesh(MeshLib::Mesh const *const mesh)
Definition: GeoMapper.cpp:73
void advancedMapOnMesh(MeshLib::Mesh const &mesh)
Definition: GeoMapper.cpp:617
int writeHistogram(std::string const &file_name, std::size_t n_bins=0) const
Writes a histogram of the quality vector to a specified file.
std::vector< double > const getQualityVector() const
Returns the vector containing a quality measure for each element.
const MeshLib::Mesh * GetMesh() const
Returns the mesh.
A dialog for selecting a mesh quality metric.
std::string getHistogramPath() const
Returns selected path for histogram (or empty string if no histogram is required)
bool getHistogram() const
Returns true if a histogram needs to be calculated.
MeshLib::MeshQualityType getSelectedMetric() const
Returns selected metric.
The dialog for converting data from NetCDF-files into OGS data structures. While NetCDF files can inc...
VtkGeoImageSource * getRaster()
static void box(const QString &e)
Definition: OGSError.cpp:23
QMenu * menu()
Returns the created menu. Add this menu to your QMainWindow menu.
Definition: RecentFiles.cpp:42
Dialog for selecting which information should be loaded from a shape file.
Small dialog for setting a name for an object.
Definition: SetNameDialog.h:29
std::string getNewName()
A model for the StationTreeView implementing a tree as a double-linked list.
TreeModelIterator provides a way to iterate over TreeItems in a TreeModel. Usage:
Dialog for selecting a filter to be applied to a VtkPipelineItem. The dialog lets you select filters ...
void SetName(QString name)
Sets the name.
Uses an image source to create a plane in the 3D with the given image texture mapped on it.
void SetRaster(vtkImageAlgorithm *img, double x0, double y0, double scalingFactor)
Sets the raster/image to be used as a texture map.
static VtkBGImageSource * New()
Create new objects with New() because of VTKs object reference counting.
The VtkVisPipeline source object of a geo-referenced image (file).
static VtkGeoImageSource * New()
Create new objects with New() because of VTKs reference counting.
bool readImage(const QString &filename)
Reads an image from file.
static vtkImageAlgorithm * loadImage(const std::string &fileName)
Loads an image- or raster-file into an vtkImageAlgorithm-Object.
Definition: VtkRaster.cpp:43
An item in the VtkVisPipeline containing a graphic object to be visualized.
int writeToFile(const std::string &filename) const
Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file.
Definition of mesh to geometry conversion.
GEOTYPE
Definition: GeoType.h:25
int writeStringToFile(std::string content, std::filesystem::path const &file_path)
Definition: Writer.cpp:45
void removeFile(std::string const &filename)
Definition: FileTools.cpp:236
@ AdaptiveMeshDensity
computing the mesh density employing a QuadTree
@ FixedMeshDensity
set the parameter with a fixed value
bool isGMSHMeshFile(const std::string &fname)
Definition: GmshReader.cpp:33
MeshLib::Mesh * readGMSHMesh(std::string const &fname)
Definition: GmshReader.cpp:166
bool readFile(std::string const &file_name, std::vector< std::unique_ptr< MeshLib::Mesh >> &meshes, DataType const export_type)
Reads the specified file and writes data into internal mesh vector.
bool readGLIFileV4(const std::string &fname, GeoLib::GEOObjects &geo, std::string &unique_name, std::vector< std::string > &errors, std::string const &gmsh_path)
Definition: OGSIOVer4.cpp:506
void writeAllDataToGLIFileV4(const std::string &fname, const GeoLib::GEOObjects &geo)
Definition: OGSIOVer4.cpp:711
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition: GeoType.cpp:23
int geoPointsToStations(GEOObjects &geo_objects, std::string const &geo_name, std::string &stn_name, bool const only_unused_pnts)
Constructs a station-vector based on the points of a given geometry.
Definition: GEOObjects.cpp:698
GITINFOLIB_EXPORT const std::string git_version_sha1_short
GITINFOLIB_EXPORT const std::string ogs_version
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)
Converts MGIS kinematic to a string representation.
Definition: MFront.cpp:103
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double const eps)
MeshQualityType
Describes a mesh quality metric.
Definition: MeshEnums.h:70
Definition of readMeshFromFile function.