diff --git a/Applications/DataExplorer/DataView/Layers2GridDialog.cpp b/Applications/DataExplorer/DataView/Layers2GridDialog.cpp index 92e041be1e6f3aefcbb4ed76c038015e685d688a..d290e95e22af2988d4df755bce79b6a1127865ff 100644 --- a/Applications/DataExplorer/DataView/Layers2GridDialog.cpp +++ b/Applications/DataExplorer/DataView/Layers2GridDialog.cpp @@ -34,18 +34,16 @@ std::vector<std::string> getSelectedObjects(QStringList const& list) } } // namespace -Layers2GridDialog::Layers2GridDialog(MeshModel* mesh_model, QDialog* parent) +Layers2GridDialog::Layers2GridDialog(MeshModel& mesh_model, QDialog* parent) : QDialog(parent), _mesh_model(mesh_model) { setupUi(this); - assert(_mesh_model != nullptr); QStringList MeshList; - for (int model_index = 0; model_index < mesh_model->rowCount(); + for (int model_index = 0; model_index < mesh_model.rowCount(); ++model_index) { - auto const* mesh = - mesh_model->getMesh(mesh_model->index(model_index, 0)); + auto const* mesh = mesh_model.getMesh(mesh_model.index(model_index, 0)); MeshList.append(QString::fromStdString(mesh->getName())); } @@ -108,18 +106,20 @@ void Layers2GridDialog::on_downOrderButton_pressed() void Layers2GridDialog::updateExpectedVoxel() { - QString const xinput = this->xlineEdit->text(); - QString const yinput = this->ylineEdit->text(); - QString const zinput = this->zlineEdit->text(); + QString const xin = this->xlineEdit->text(); + QString const yin = this->ylineEdit->text(); + QString const zin = this->zlineEdit->text(); + bool ok; + double const xinput = xin.toDouble(); + double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xin.toDouble(); + double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xin.toDouble(); if (_layeredMeshes.stringList()[0] == "[No Mesh available.]") { this->expectedVoxelLabel->setText("approximated Voxel: undefined"); return; } - if (xinput.isEmpty() || yinput.isEmpty() || zinput.isEmpty() || - xinput.toDouble() == 0 || yinput.toDouble() == 0 || - zinput.toDouble() == 0) + if (xin.isEmpty() || xinput == 0) { this->expectedVoxelLabel->setText("approximated Voxel: undefined"); return; @@ -127,8 +127,8 @@ void Layers2GridDialog::updateExpectedVoxel() std::vector<std::string> layered_meshes = getSelectedObjects(_layeredMeshes.stringList()); - auto* const mesh_top = _mesh_model->getMesh(layered_meshes.front()); - auto* const mesh_bottom = _mesh_model->getMesh(layered_meshes.back()); + auto* const mesh_top = _mesh_model.getMesh(layered_meshes.front()); + auto* const mesh_bottom = _mesh_model.getMesh(layered_meshes.back()); auto const& nodes_top = mesh_top->getNodes(); GeoLib::AABB const aabb_top(nodes_top.cbegin(), nodes_top.cend()); @@ -137,9 +137,9 @@ void Layers2GridDialog::updateExpectedVoxel() auto const min_b = aabb_bottom.getMinPoint(); auto const max_b = aabb_bottom.getMaxPoint(); auto const max_t = aabb_top.getMaxPoint(); - double const expectedVoxel = (max_b[0] - min_b[0]) * (max_b[1] - min_b[0]) * - (max_t[2] - min_b[2]) / xinput.toDouble() / - yinput.toDouble() / zinput.toDouble(); + double const expectedVoxel = (max_b[0] - min_b[0]) * (max_b[1] - min_b[1]) * + (max_t[2] - min_b[2]) / xinput / yinput / + zinput; int const exponent = std::floor(std::log10(abs(expectedVoxel))); this->expectedVoxelLabel->setText( @@ -200,7 +200,7 @@ void Layers2GridDialog::accept() for (auto const& layer : layered_meshes) { - auto mesh(_mesh_model->getMesh(layer)); + auto mesh(_mesh_model.getMesh(layer)); if (mesh == nullptr) { OGSError::box( @@ -227,6 +227,6 @@ void Layers2GridDialog::accept() } OGSError::box("The VoxelGrid is fine"); - _mesh_model->addMesh(mesh.release()); + _mesh_model.addMesh(mesh.release()); this->done(QDialog::Accepted); } diff --git a/Applications/DataExplorer/DataView/Layers2GridDialog.h b/Applications/DataExplorer/DataView/Layers2GridDialog.h index 14f4f245af37071c0d7d9b0329fb940872137869..f922cb67345eaa3abbfbf1b43bcaecdf6d14a575 100644 --- a/Applications/DataExplorer/DataView/Layers2GridDialog.h +++ b/Applications/DataExplorer/DataView/Layers2GridDialog.h @@ -31,11 +31,11 @@ class Layers2GridDialog : public QDialog, private Ui_Layers2Grid Q_OBJECT public: - explicit Layers2GridDialog(MeshModel* mesh_model, + explicit Layers2GridDialog(MeshModel& mesh_model, QDialog* parent = nullptr); private: - MeshModel* _mesh_model; + MeshModel& _mesh_model; QStringListModel _layeredMeshes; QStringListModel _neglectedMeshes; diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 7ae5448b4f98c4b7dd894f40a2a3a4ff105dfc10..b1c04ad9c8f1a3a99238b3ac1e6208d2fc6e70fc 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -1355,7 +1355,12 @@ void MainWindow::showTranslateDataDialog() void MainWindow::showLayers2GridDialog() { - auto dlg = Layers2GridDialog(_meshModel.get()); + if (_meshModel == nullptr) + { + OGSError::box("The supplied mesh_model is not existing."); + } + + auto dlg = Layers2GridDialog(*_meshModel); dlg.exec(); }