From fa26adf1aaac27aff7816ca274579f895bb1bb3e Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Mon, 12 Nov 2018 10:56:32 +0100 Subject: [PATCH] [A/DE] Use new {exists,get}PropertyVector. This versions check if the PropertyVector is assigned to the requested mesh item type and has the required number of components. --- .../DataView/DirectConditionGenerator.cpp | 19 ++++++++++--------- .../DataView/ElementTreeModel.cpp | 8 +++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp index c6e5f3f8032..04fde580329 100644 --- a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp +++ b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp @@ -97,22 +97,23 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di const std::size_t nNodes(surface_mesh->getNumberOfNodes()); const double no_data(raster->getHeader().no_data); - auto const* const node_id_pv = - surface_mesh->getProperties().getPropertyVector<int>(prop_name); - if (!node_id_pv) + MeshLib::PropertyVector<int> const* node_id_pv = nullptr; + try { - ERR( - "Need subsurface node ids, but the property \"%s\" is not " - "available.", - prop_name.c_str()); + node_id_pv = surface_mesh->getProperties().getPropertyVector<int>( + prop_name, MeshLib::MeshItemType::Node, 1); + } + catch (std::runtime_error const& e) + { + WARN("%s", e.what()); return _direct_values; } _direct_values.reserve(nNodes); - for (std::size_t i=0; i<nNodes; ++i) + for (std::size_t i = 0; i < nNodes; ++i) { double val(raster->getValueAtPoint(*surface_nodes[i])); - val = (val == no_data) ? 0 : ((val*node_area_vec[i])/scaling); + val = (val == no_data) ? 0 : ((val * node_area_vec[i]) / scaling); _direct_values.emplace_back((*node_id_pv)[i], val); } diff --git a/Applications/DataExplorer/DataView/ElementTreeModel.cpp b/Applications/DataExplorer/DataView/ElementTreeModel.cpp index 9f3efbd8272..bc407df5d31 100644 --- a/Applications/DataExplorer/DataView/ElementTreeModel.cpp +++ b/Applications/DataExplorer/DataView/ElementTreeModel.cpp @@ -65,9 +65,11 @@ void ElementTreeModel::setElement(vtkUnstructuredGridAlgorithm const*const grid, auto* typeItem = new TreeItem(typeData, elemItem); elemItem->appendChild(typeItem); - MeshLib::PropertyVector<int> const*const mat_ids = - mesh->getProperties().existsPropertyVector<int>("MaterialIDs") - ? mesh->getProperties().getPropertyVector<int>("MaterialIDs") + MeshLib::PropertyVector<int> const* const mat_ids = + mesh->getProperties().existsPropertyVector<int>( + "MaterialIDs", MeshLib::MeshItemType::Cell, 1) + ? mesh->getProperties().getPropertyVector<int>( + "MaterialIDs", MeshLib::MeshItemType::Cell, 1) : nullptr; QString matIdString = !mat_ids ? QString("not defined") : QString::number((*mat_ids)[elem->getID()]); QList<QVariant> materialData; -- GitLab