From d79b5c222fef5ea1604d02b685a23a70274e7db9 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 9 Nov 2018 14:17:16 +0100
Subject: [PATCH] [MeL/MeshSearch] Use tests from getPropertyVector.

---
 MeshLib/MeshSearch/ElementSearch.h | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/MeshLib/MeshSearch/ElementSearch.h b/MeshLib/MeshSearch/ElementSearch.h
index d8631bf879e..cd163726ee2 100644
--- a/MeshLib/MeshSearch/ElementSearch.h
+++ b/MeshLib/MeshSearch/ElementSearch.h
@@ -72,24 +72,18 @@ public:
         PROPERTY_TYPE const max_property_value,
         bool outside_of)
     {
-        if (!_mesh.getProperties().existsPropertyVector<PROPERTY_TYPE>(property_name))
+        MeshLib::PropertyVector<PROPERTY_TYPE> const* pv = nullptr;
+        try
         {
-            WARN("Property \"%s\" not found in mesh.", property_name.c_str());
-            return 0;
-        }
-        auto const* const pv =
-            _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>(property_name);
-
-        if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell)
-        {
-            WARN("The property \"%s\" is not assigned to mesh elements.",
-                 property_name.c_str());
-            return 0;
+            pv = _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>(
+                property_name, MeshLib::MeshItemType::Cell, 1);
         }
-
-        if (pv->getNumberOfComponents() != 1)
+        catch (std::runtime_error const& e)
         {
-            WARN("Value-based element removal currently only works for scalars.");
+            ERR("%s", e.what());
+            WARN(
+                "Value-based element removal currently only works for "
+                "scalars.");
             return 0;
         }
 
@@ -99,7 +93,8 @@ public:
         {
             for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
             {
-                if ((*pv)[i] < min_property_value || (*pv)[i] > max_property_value)
+                if ((*pv)[i] < min_property_value ||
+                    (*pv)[i] > max_property_value)
                     matchedIDs.push_back(i);
             }
         }
@@ -107,7 +102,8 @@ public:
         {
             for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
             {
-                if ((*pv)[i] >= min_property_value && (*pv)[i] <= max_property_value)
+                if ((*pv)[i] >= min_property_value &&
+                    (*pv)[i] <= max_property_value)
                     matchedIDs.push_back(i);
             }
         }
-- 
GitLab