Skip to content

v0.2.54..v0.2.55 changeset ConflatableElementCriterion.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/criterion/ConflatableElementCriterion.cpp b/hoot-core/src/main/cpp/hoot/core/criterion/ConflatableElementCriterion.cpp
index 2fdde2e..b355981 100644
--- a/hoot-core/src/main/cpp/hoot/core/criterion/ConflatableElementCriterion.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/criterion/ConflatableElementCriterion.cpp
@@ -93,54 +93,77 @@ void ConflatableElementCriterion::_createConflatableCriteria()
 }
 
 QStringList ConflatableElementCriterion::getConflatableCriteriaForElement(
-  const ConstElementPtr& e, ConstOsmMapPtr map, const bool ignoreGenericConflators)
+  const ConstElementPtr& e, ConstOsmMapPtr map)
 {
   const QMap<QString, ElementCriterionPtr> conflatableCriteria = getConflatableCriteria();
 
   QStringList conflatableCriteriaForElement;
+  QMap<QString, std::shared_ptr<ConflatableElementCriterion>> genericConflatableCriteria;
+
+  // first go through and mark only with those crits that support specific conflation
+
   for (QMap<QString, ElementCriterionPtr>::const_iterator itr = conflatableCriteria.begin();
        itr != conflatableCriteria.end(); ++itr)
   {
     LOG_VART(itr.key());
     ElementCriterionPtr crit = itr.value();
 
-    if (ignoreGenericConflators)
-    {
-      std::shared_ptr<ConflatableElementCriterion> conflatableCrit =
-        std::dynamic_pointer_cast<ConflatableElementCriterion>(crit);
-      assert(conflatableCrit);
-      if (!conflatableCrit->supportsSpecificConflation())
-      {
-        continue;
-      }
-    }
-
     ConstOsmMapConsumer* mapConsumer = dynamic_cast<ConstOsmMapConsumer*>(crit.get());
     if (mapConsumer != 0)
     {
       mapConsumer->setOsmMap(map.get());
     }
 
+    std::shared_ptr<ConflatableElementCriterion> conflatableCrit =
+      std::dynamic_pointer_cast<ConflatableElementCriterion>(crit);
+    assert(conflatableCrit);
+    if (!conflatableCrit->supportsSpecificConflation())
+    {
+      genericConflatableCriteria[itr.key()] = conflatableCrit;
+      continue;
+    }
+
     if (crit->isSatisfied(e))
     {
-      // It is something we can conflate?
       conflatableCriteriaForElement.append(itr.key());
     }
   }
   LOG_VART(conflatableCriteriaForElement);
+
+  // if no specific conflate crit was available, then try to add a generic one
+
+  if (conflatableCriteriaForElement.size() == 0)
+  {
+    for (QMap<QString, std::shared_ptr<ConflatableElementCriterion>>::const_iterator itr =
+           genericConflatableCriteria.begin();
+         itr != genericConflatableCriteria.end(); ++itr)
+    {
+      LOG_VART(itr.key());
+      std::shared_ptr<ConflatableElementCriterion> crit = itr.value();
+
+      if (crit->isSatisfied(e))
+      {
+        // It is something we can conflate?
+        conflatableCriteriaForElement.append(itr.key());
+      }
+    }
+    LOG_VART(conflatableCriteriaForElement);
+  }
+
   return conflatableCriteriaForElement;
 }
 
-QStringList ConflatableElementCriterion::getCriterionClassNamesByGeometryType(const GeometryType& type)
+QStringList ConflatableElementCriterion::getCriterionClassNamesByGeometryType(
+  const GeometryType& type)
 {
   QStringList classNamesByType;
   std::vector<std::string> classNames =
     Factory::getInstance().getObjectNamesByBase("hoot::ElementCriterion");
-  LOG_VARD(classNamesByType);
+  LOG_VART(classNamesByType);
   for (size_t i = 0; i < classNames.size(); i++)
   {
     const std::string className = classNames[i];
-    LOG_VARD(className);
+    LOG_VART(className);
 
     ElementCriterionPtr crit(
       Factory::getInstance().constructObject<ElementCriterion>(className));
@@ -148,12 +171,12 @@ QStringList ConflatableElementCriterion::getCriterionClassNamesByGeometryType(co
       std::dynamic_pointer_cast<ConflatableElementCriterion>(crit);
     if (conflatableCrit)
     {
-      LOG_DEBUG("is conflatable: " << className);
+      LOG_TRACE("is conflatable: " << className);
       std::shared_ptr<GeometryTypeCriterion> geometryTypeCrit =
         std::dynamic_pointer_cast<GeometryTypeCriterion>(crit);
       if (geometryTypeCrit && geometryTypeCrit->getGeometryType() == type)
       {
-        LOG_DEBUG("is same geometry: " << className);
+        LOG_TRACE("is same geometry: " << className);
         classNamesByType.append(QString::fromStdString(className));
       }
     }
Clone this wiki locally