Salome HOME
Issue #1865: Model Widget for fields
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Tools.cpp
index 23f65ebc61497dc1e3c0066451243f2feb610068..119a0a1ebe7419fde56a05551a71a9065197b255 100644 (file)
@@ -1,5 +1,6 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 // Name   : ModelHighAPI_Tools.cpp
-// Purpose: 
+// Purpose:
 //
 // History:
 // 07/06/16 - Sergey POKHODENKO - Creation of the file
@@ -28,6 +29,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_AttributeDoubleArray.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
@@ -193,18 +195,43 @@ void fillAttribute(const std::string & theValue,
 {
   theAttribute->setValue(theValue);
 }
+
+//--------------------------------------------------------------------------------------
 void fillAttribute(const char * theValue,
                    const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
 {
   theAttribute->setValue(theValue);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<std::string> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeStringArray> & theAttribute)
+{
+  theAttribute->setSize(int(theValue.size()));
+
+  int anIndex = 0;
+  for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
+    theAttribute->setValue(anIndex, *it); 
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<ModelHighAPI_Integer> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeIntArray> & theAttribute)
+{
+  theAttribute->setSize(int(theValue.size()));
+
+  int anIndex = 0;
+  for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
+    theAttribute->setValue(anIndex, it->intValue()); // use only values, no text support in array
+}
+
 //==================================================================================================
 GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr)
 {
   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
 
-  std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(), ::tolower);
+  std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(),
+                 theShapeTypeStr.begin(), ::tolower);
 
   if(theShapeTypeStr == "compound") {
     aShapeType = GeomAPI_Shape::COMPOUND;
@@ -258,6 +285,32 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection
   return aShapeType;
 }
 
+//--------------------------------------------------------------------------------------
+ModelAPI_AttributeTables::ValueType valueTypeByStr(const std::string& theValueTypeStr)
+{
+  std::string aType = theValueTypeStr;
+  std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower);
+  if (aType == "boolean")
+    return ModelAPI_AttributeTables::BOOLEAN;
+  else if (aType == "integer")
+    return ModelAPI_AttributeTables::INTEGER;
+  else if (aType == "string")
+    return ModelAPI_AttributeTables::STRING;
+  return ModelAPI_AttributeTables::DOUBLE; // default
+}
+
+//--------------------------------------------------------------------------------------
+std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType)
+{
+  switch(theType) {
+  case ModelAPI_AttributeTables::BOOLEAN: return "BOOLEAN";
+  case ModelAPI_AttributeTables::INTEGER: return "INTEGER";
+  case ModelAPI_AttributeTables::DOUBLE: return "DOUBLE";
+  case ModelAPI_AttributeTables::STRING: return "STRING";
+  }
+  return ""; // bad case
+}
+
 /// stores the features information, recoursively stores sub-documetns features
 std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
   std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> >& theStore,
@@ -278,7 +331,7 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
   for(; allIter != allFeatures.end(); allIter++) {
     FeaturePtr aFeat = *allIter;
     if (theCompare) {
-      std::map<std::string, ModelHighAPI_FeatureStore>::iterator 
+      std::map<std::string, ModelHighAPI_FeatureStore>::iterator
         aFeatFind = aDocFind->second.find(aFeat->name());
       if (aFeatFind == aDocFind->second.end()) {
         return "Document '" + theDocName + "' feature '" + aFeat->name() + "' not found";
@@ -297,7 +350,8 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
     ModelAPI_Tools::allResults(aFeat, allResults);
     std::list<ResultPtr>::iterator aRes = allResults.begin();
     for(; aRes != allResults.end(); aRes++) {
-      if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // recoursively store features of sub-documents
+      // recoursively store features of sub-documents
+      if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) {
         DocumentPtr aDoc = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes)->partDoc();
         if (aDoc.get()) {
           std::string anError = storeFeatures((*aRes)->data()->name(), aDoc, theStore, theCompare);
@@ -318,7 +372,7 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
           aLostName = aLostIter->first;
         }
       }
-      return "For document '" + theDocName + 
+      return "For document '" + theDocName +
         "' the number of features is decreased, there is no feature '" + aLostName + "'";
     }
   }