Salome HOME
Fix code formatting
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Dumper.cpp
index 2764c17982a162a8a6e7817010128dd8be516513..819d200c8b986b249ef270c18325eec642c4cfde 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>
@@ -366,7 +367,7 @@ bool ModelHighAPI_Dumper::exportTo(const std::string& theFileName)
   if (!myModules.empty())
     aFile << std::endl;
 
-  aFile << "import model" << std::endl << std::endl;
+  aFile << "from salome.shaper import model" << std::endl << std::endl;
   aFile << "model.begin()" << std::endl;
 
   // dump collected data
@@ -623,18 +624,23 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
 {
+  bool isFound = myNames.find(theEntity) != myNames.end();
   myDumpBuffer << name(theEntity);
 
-  bool isUserDefinedName = !myNames[theEntity].myIsDefault;
-  // store results if they have user-defined names or colors
-  std::list<ResultPtr> aResultsWithNameOrColor;
-  const std::list<ResultPtr>& aResults = theEntity->results();
-  std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
-  for (; aResIt != aResults.end(); ++aResIt)
-    if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt) || !isDefaultDeflection(*aResIt))
-      aResultsWithNameOrColor.push_back(*aResIt);
-  // store just dumped entity to stack
-  myEntitiesStack.push(LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor));
+  if (!isFound) {
+    bool isUserDefinedName = !myNames[theEntity].myIsDefault;
+    // store results if they have user-defined names or colors
+    std::list<ResultPtr> aResultsWithNameOrColor;
+    const std::list<ResultPtr>& aResults = theEntity->results();
+    std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
+    for (; aResIt != aResults.end(); ++aResIt)
+      if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt) ||
+          !isDefaultDeflection(*aResIt))
+        aResultsWithNameOrColor.push_back(*aResIt);
+    // store just dumped entity to stack
+    myEntitiesStack.push(
+        LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor));
+  }
 
   // remove entity from the list of not dumped items
   myNotDumpedEntities.erase(theEntity);
@@ -652,7 +658,13 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
       break;
     }
   }
-  myDumpBuffer << name(aFeature) << ".result()[" << anIndex << "]";
+
+  myDumpBuffer << name(aFeature);
+  if(anIndex == 0) {
+    myDumpBuffer << ".result()";
+  } else {
+    myDumpBuffer << ".results()[" << anIndex << "]";
+  }
   return *this;
 }
 
@@ -827,8 +839,22 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
   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>&))
 {