Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_Dump.cpp
index d89f6d98a7dfd8cb1eefcb0e1bf38fc3edfaf259..d9effab930aee2af11c5e5845650d4fc76184be0 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <ModelHighAPI_Dumper.h>
 
@@ -43,10 +44,47 @@ void ExchangePlugin_Dump::execute()
 void ExchangePlugin_Dump::dump(const std::string& theFileName)
 {
   // load DumpAssistant from Python side
-  Config_ModuleReader::loadScript("model.dump");
+  Config_ModuleReader::loadScript("salome.shaper.model.dump");
 
   ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
+  aDumper->clear();
   DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
+
+  int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
+  if(aFeaturesNb > 1) {
+    FeaturePtr aLastFeature =
+        ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
+    if(aDoc->currentFeature(true) != aLastFeature) {
+        setError("Dump cannot be done. Please move the history line to the end before dumping.");
+        return;
+    }
+  }
+
+  DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
+  aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
+  if(aFeaturesNb > 1) {
+    FeaturePtr aLastFeature =
+        ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
+    if(anActiveDoc->currentFeature(true) != aLastFeature) {
+        setError("Dump cannot be done. Please move the history line to the end before dumping.");
+        return;
+    }
+  }
+
+  std::list<FeaturePtr> aFeatures = aDoc->allFeatures();
+  for(std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
+      aFeatIt != aFeatures.end();
+      ++aFeatIt) {
+    ResultPartPtr aResultPart =
+      std::dynamic_pointer_cast<ModelAPI_ResultPart>((*aFeatIt)->firstResult());
+    if(aResultPart.get()) {
+      if(!aResultPart->isActivated()) {
+        setError("Error: Not all parts are loaded. Can not dump.");
+        return;
+      }
+    }
+  }
+
   if (!aDumper || !aDumper->process(aDoc, theFileName))
     setError("An error occured while dumping to " + theFileName);
 }