Salome HOME
Issue #1865: Create a field
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Dumper.cpp
index b43241e367a254033c4d852f3380cfe77b58e68c..1ea7a1f828e4610628a38eba8d95e4238f50a1f4 100644 (file)
@@ -28,6 +28,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Entity.h>
@@ -230,13 +231,14 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theD
     CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIt);
     if (aCompFeat) // iteratively process composite features
       isOk = process(aCompFeat) && isOk;
-    else if (!isDumped(*aFeatIt)) // dump common feature 
+    else if (!isDumped(*aFeatIt)) // dump common feature
       dumpFeature(*aFeatIt);
   }
   return isOk;
 }
 
-bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool isForce)
+bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
+                                  bool isForce)
 {
   // increase composite features stack
   ++gCompositeStackDepth;
@@ -279,8 +281,9 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
   return isOk;
 }
 
-bool ModelHighAPI_Dumper::processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
-                                      bool theDumpModelDo)
+bool ModelHighAPI_Dumper::processSubs(
+  const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
+  bool theDumpModelDo)
 {
   bool isOk = true;
   // dump all sub-features;
@@ -349,7 +352,7 @@ bool ModelHighAPI_Dumper::exportTo(const std::string& theFileName)
   for (ModulesMap::const_iterator aModIt = myModules.begin();
        aModIt != myModules.end(); ++aModIt) {
     aFile << "from " << aModIt->first << " import ";
-    if (aModIt->second.empty() || 
+    if (aModIt->second.empty() ||
         aModIt->second.find(std::string()) != aModIt->second.end())
       aFile << "*"; // import whole module
     else {
@@ -424,7 +427,8 @@ void ModelHighAPI_Dumper::dumpEntitySetName()
     }
     // set result deflection
     if (!isDefaultDeflection(*aResIt)) {
-      AttributeDoublePtr aDeflectionAttr = (*aResIt)->data()->real(ModelAPI_Result::DEFLECTION_ID());
+      AttributeDoublePtr aDeflectionAttr =
+        (*aResIt)->data()->real(ModelAPI_Result::DEFLECTION_ID());
       if(aDeflectionAttr.get() && aDeflectionAttr->isInitialized()) {
         *this << *aResIt;
         myDumpBuffer << ".setDeflection(" << aDeflectionAttr->value() << ")" << std::endl;
@@ -643,12 +647,19 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
   FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
   int anIndex = 0;
   std::list<ResultPtr> aResults = aFeature->results();
-  for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin(); anIt != aResults.cend(); ++anIt, ++anIndex) {
+  for(std::list<ResultPtr>::const_iterator
+      anIt = aResults.cbegin(); anIt != aResults.cend(); ++anIt, ++anIndex) {
     if(theResult->isSame(*anIt)) {
       break;
     }
   }
-  myDumpBuffer << name(aFeature) << ".result()[" << anIndex << "]";
+
+  myDumpBuffer << name(aFeature);
+  if(anIndex == 0) {
+    myDumpBuffer << ".result()";
+  } else {
+    myDumpBuffer << ".results()[" << anIndex << "]";
+  }
   return *this;
 }
 
@@ -784,7 +795,8 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     return *this;
   }
 
-  myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" << theAttrSelect->namingName() << "\")";
+  myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" <<
+    theAttrSelect->namingName() << "\")";
   return *this;
 }
 
@@ -814,15 +826,30 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     } else {
       isAdded = true;
     }
-    myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
+    myDumpBuffer << "model.selection(\"" <<
+      aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
   }
 
   myDumpBuffer << "]";
   return *this;
 }
 
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+  const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray)
+{
+  myDumpBuffer<<"[";
+  for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) {
+    if (anIndex != 0)
+      myDumpBuffer<<", ";
+
+    myDumpBuffer<<"\""<<theArray->value(anIndex)<<"\"";
+  }
+
+  myDumpBuffer<<"]";
+  return *this;
+}
+
 /// Dump std::endl
-MODELHIGHAPI_EXPORT
 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
                                 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
 {