Salome HOME
updated copyright message
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_Dump.cpp
index 30f4169614983a4ef26c11f1eaa67fed7f5b0b15..7ac28dd096373d52564a54019ff13fc72df88183 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Validator.h>
 
 #include <ModelHighAPI_Dumper.h>
 
 #include <Config_ModuleReader.h>
 
+#include <GeomAlgoAPI_Tools.h>
+
+#ifdef EXCHANGEPLUGIN_DUMP_NAMING
+static const bool THE_DUMP_NAMING = true;
+#else
+static const bool THE_DUMP_NAMING = false;
+#endif
+
+#ifdef EXCHANGEPLUGIN_DUMP_GEO
+static const bool THE_DUMP_GEO = true;
+#else
+static const bool THE_DUMP_GEO = false;
+#endif
+
+#ifdef EXCHANGEPLUGIN_DUMP_WEAK
+static const bool THE_DUMP_WEAK = true;
+#else
+static const bool THE_DUMP_WEAK = false;
+#endif
+
 
 ExchangePlugin_Dump::ExchangePlugin_Dump()
 {
@@ -43,8 +64,21 @@ void ExchangePlugin_Dump::initAttributes()
   data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
 
-  data()->addAttribute(SELECTION_TYPE_ID(), ModelAPI_AttributeString::typeId());
-  //string(SELECTION_TYPE_ID())->setValue(TOPOLOGICAL_NAMING_DUMP_ID()); // default value
+  data()->addAttribute(TOPOLOGICAL_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(GEOMETRIC_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(WEAK_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(EXPORT_VARIABLES_ID(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(DUMP_DIR_ID(), ModelAPI_AttributeString::typeId());
+
+  // default values
+  boolean(TOPOLOGICAL_NAMING_DUMP_ID())->setValue(THE_DUMP_NAMING);
+  boolean(GEOMETRIC_DUMP_ID())->setValue(THE_DUMP_GEO);
+  boolean(WEAK_NAMING_DUMP_ID())->setValue(THE_DUMP_WEAK);
+  boolean(EXPORT_VARIABLES_ID())->setValue(false);
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DUMP_DIR_ID());
 }
 
 void ExchangePlugin_Dump::execute()
@@ -63,11 +97,6 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName)
   // load DumpAssistant from Python side
   Config_ModuleReader::loadScript("salome.shaper.model.dump");
 
-  ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
-  aDumper->clear();
-  aDumper->setSelectionByGeometry(string(SELECTION_TYPE_ID())->value() == GEOMETRIC_DUMP_ID());
-  aDumper->setSelectionWeakNaming(string(SELECTION_TYPE_ID())->value() == WEAK_NAMING_DUMP_ID());
-
   DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
 
   int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
@@ -86,8 +115,8 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName)
     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;
+      setError("Dump cannot be done. Please move the history line to the end before dumping.");
+      return;
     }
   }
 
@@ -105,6 +134,59 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName)
     }
   }
 
-  if (!aDumper || !aDumper->process(aDoc, theFileName))
+  // process selected types of the dump
+  ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
+  if (!aDumper)
     setError("An error occured while dumping to " + theFileName);
+
+  static const int THE_TYPES_SIZE = 3;
+  bool aTypes[THE_TYPES_SIZE] = {
+    boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value(),
+    boolean(GEOMETRIC_DUMP_ID())->value(),
+    boolean(WEAK_NAMING_DUMP_ID())->value()
+  };
+  int aNbSelectedTypes = 0;
+  for (int i = 0; i < THE_TYPES_SIZE; ++i)
+    if (aTypes[i])
+      ++aNbSelectedTypes;
+
+  if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) {
+    ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage);
+    aDumper->addCustomStorage(aTopoNameStorage);
+  }
+  if (boolean(GEOMETRIC_DUMP_ID())->value()) {
+    ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage(
+        new ModelHighAPI_Dumper::DumpStorageGeom);
+    if (aNbSelectedTypes > 1)
+      aGeomSelectionStorage->setFilenameSuffix("_geo");
+    aDumper->addCustomStorage(aGeomSelectionStorage);
+  }
+  if (boolean(WEAK_NAMING_DUMP_ID())->value()) {
+    ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage(
+        new ModelHighAPI_Dumper::DumpStorageWeak);
+    if (aNbSelectedTypes > 1)
+      aWeakNamingStorage->setFilenameSuffix("_weak");
+    aDumper->addCustomStorage(aWeakNamingStorage);
+  }
+
+  // pass dump directory to the dumper
+  AttributeStringPtr aDumpDirAttr =
+    this->string(ExchangePlugin_Dump::DUMP_DIR_ID());
+  std::string aDumpDir;
+  if (aDumpDirAttr.get() && aDumpDirAttr->isInitialized())
+    aDumpDir = aDumpDirAttr->value();
+  else
+    aDumpDir = GeomAlgoAPI_Tools::File_Tools::path(theFileName);
+  aDumper->setDumpDir(aDumpDir);
+
+  if (!aDumper->process(aDoc, theFileName)) {
+    setError("An error occurred while dumping to " + theFileName);
+  } else {
+    if (boolean(EXPORT_VARIABLES_ID())->value()) {
+      aDumper->exportVariables();
+    }
+  }
+  // clear cashed data after export variables was performed
+  aDumper->clearCustomStorage();
+
 }