Salome HOME
Issue #1865 : Implementation and test python interface for the field feature
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_FeatureStore.cpp
index bf32bdbbd7b50d68d4341300beadd07261baff7b..c42072510617eaa52e828893798bc993e3092c8b 100644 (file)
@@ -21,7 +21,9 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeTables.h>
 #include <ModelAPI_Validator.h>
 
 #include <GeomDataAPI_Dir.h>
@@ -64,7 +66,7 @@ std::string ModelHighAPI_FeatureStore::compare(FeaturePtr theFeature) {
   for(; aRes != allResults.end() && aResIter != myRes.end(); aRes++, aResIter++) {
     anError = compareData((*aRes)->data(), *aResIter);
     if (!anError.empty())
-      return "Results of feature '" + theFeature->name() + "' '" + (*aRes)->data()->name() + 
+      return "Results of feature '" + theFeature->name() + "' '" + (*aRes)->data()->name() +
       "' differ:" + anError;
   }
   if (aRes != allResults.end()) {
@@ -76,10 +78,11 @@ std::string ModelHighAPI_FeatureStore::compare(FeaturePtr theFeature) {
   return ""; // ok
 }
 
-void ModelHighAPI_FeatureStore::storeData(std::shared_ptr<ModelAPI_Data> theData, 
+void ModelHighAPI_FeatureStore::storeData(std::shared_ptr<ModelAPI_Data> theData,
   std::map<std::string, std::string>& theAttrs)
 {
-  theAttrs["__name__"] = theData->name(); // store name to keep also this information and output if needed
+  // store name to keep also this information and output if needed
+  theAttrs["__name__"] = theData->name();
   std::list<std::shared_ptr<ModelAPI_Attribute> > allAttrs = theData->attributes("");
   std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = allAttrs.begin();
   for(; anAttr != allAttrs.end(); anAttr++) {
@@ -92,7 +95,7 @@ void ModelHighAPI_FeatureStore::storeData(std::shared_ptr<ModelAPI_Data> theData
   }
 }
 
-std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data> theData, 
+std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data> theData,
   std::map<std::string, std::string>& theAttrs)
 {
   std::map<std::string, std::string> aThis;
@@ -103,7 +106,7 @@ std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data
       return "original model had no attribute '" + aThisIter->first + "'";
     }
     if (theAttrs[aThisIter->first] != aThisIter->second) {
-      return "attribute '" + aThisIter->first + "' is different (original != current) '" + 
+      return "attribute '" + aThisIter->first + "' is different (original != current) '" +
         theAttrs[aThisIter->first] + "' != '" + aThisIter->second + "'";
     }
   }
@@ -117,7 +120,8 @@ std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data
   return "";
 }
 
-static void dumpArray(std::ostringstream& theOutput, const double theArray[], int theSize, int thePrecision = PRECISION)
+static void dumpArray(std::ostringstream& theOutput, const double theArray[],
+                      int theSize, int thePrecision = PRECISION)
 {
   for (int i = 0; i < theSize; ++i) {
     if (i > 0)
@@ -142,7 +146,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       return aResult.str();
     } else if (aType == ModelAPI_AttributeString::typeId()) {
       // special case for attribute "SolverError"
-      if (theAttr->id() == "SolverError" && 
+      if (theAttr->id() == "SolverError" &&
           std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner())->getKind() == "Sketch")
         return "";
     }
@@ -193,11 +197,11 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       aResult<<"__empty__";
     }
   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
-    AttributeSelectionPtr anAttr = 
+    AttributeSelectionPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttr);
     aResult<<anAttr->namingName();
   } else if (aType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr anAttr = 
+    AttributeSelectionListPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttr);
     for(int a = 0; a < anAttr->size(); a++) {
       if (a != 0)
@@ -205,7 +209,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       aResult<<anAttr->value(a)->namingName();
     }
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
-    AttributeRefAttrPtr anAttr = 
+    AttributeRefAttrPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttr);
     ObjectPtr anObj = anAttr->isObject() ? anAttr->object() : anAttr->attr()->owner();
     if (anObj.get()) {
@@ -217,10 +221,10 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       aResult<<"__empty__";
     }
   } else if (aType == ModelAPI_AttributeRefList::typeId()) {
-    AttributeRefListPtr anAttr = 
+    AttributeRefListPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttr);
     // for sketch sub-features the empty values may be skipped and order is not important
-    bool isSketchFeatures = anAttr->id() == "Features" && 
+    bool isSketchFeatures = anAttr->id() == "Features" &&
       std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner())->getKind() == "Sketch";
     std::list<ObjectPtr> aList = anAttr->list();
     std::list<std::string> aResList; // list of resulting strings
@@ -237,7 +241,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       aResult<<*aR<<" ";
     }
   } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    AttributeRefAttrListPtr anAttr = 
+    AttributeRefAttrListPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttr);
     std::list<std::pair<ObjectPtr, AttributePtr> > aList = anAttr->list();
     std::list<std::pair<ObjectPtr, AttributePtr> >::iterator aL = aList.begin();
@@ -255,15 +259,44 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       }
     }
   } else if (aType == ModelAPI_AttributeIntArray::typeId()) {
-    AttributeIntArrayPtr anAttr = 
+    AttributeIntArrayPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeIntArray>(theAttr);
     for(int a = 0; a < anAttr->size(); a++)
       aResult<<anAttr->value(a)<<" ";
   } else if (aType == ModelAPI_AttributeDoubleArray::typeId()) {
-    AttributeDoubleArrayPtr anAttr = 
+    AttributeDoubleArrayPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(theAttr);
     for(int a = 0; a < anAttr->size(); a++)
       aResult<<anAttr->value(a)<<" ";
+  } else if (aType == ModelAPI_AttributeStringArray::typeId()) {
+    AttributeStringArrayPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeStringArray>(theAttr);
+    for(int a = 0; a < anAttr->size(); a++)
+      aResult<<"'"<<anAttr->value(a)<<"'"<<" ";
+  } else if (aType == ModelAPI_AttributeTables::typeId()) {
+    AttributeTablesPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeTables>(theAttr);
+    aResult<<anAttr->tables()<<"x"<<anAttr->rows()<<"x"<<anAttr->columns()<<" ";
+    for(int aTab = 0; aTab < anAttr->tables(); aTab++) {
+      for(int aRow = 0; aRow < anAttr->rows(); aRow++) {
+        for( int aCol = 0; aCol < anAttr->columns(); aCol++) {
+          switch(anAttr->type()) {
+          case ModelAPI_AttributeTables::BOOLEAN:
+            aResult<<anAttr->value(aRow, aCol, aTab).myBool<<" ";
+            break;
+          case ModelAPI_AttributeTables::INTEGER:
+            aResult<<anAttr->value(aRow, aCol, aTab).myInt<<" ";
+            break;
+          case ModelAPI_AttributeTables::DOUBLE:
+            aResult<<anAttr->value(aRow, aCol, aTab).myDouble<<" ";
+            break;
+          case ModelAPI_AttributeTables::STRING:
+            aResult<<"'"<<anAttr->value(aRow, aCol, aTab).myStr.c_str()<<"' ";
+            break;
+          }
+        }
+      }
+    }
   } else if (aType == GeomDataAPI_Point::typeId()) {
     AttributePointPtr anAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttr);
     double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()};
@@ -302,7 +335,8 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>&
   }
   // output the main characteristics
   if (GeomAlgoAPI_ShapeTools::volume(theShape) > 1.e-7) {
-    aResult<<"Volume: "<<std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+    aResult<<"Volume: "<<
+      std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
   }
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
   aResult<<"Center of mass: ";