Salome HOME
Merge remote branch 'origin/V7_dev'
[modules/yacs.git] / src / SALOMEDSImpl / SALOMEDSImpl_Study.cxx
index d5a380a9ff0de8ccb72cbce148d1a9ac0cc976c0..d9dd02393ff83c7cd6bc284896e9295d4342b174 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -44,6 +44,7 @@
 
 #include <fstream>
 #include <sstream>
+#include <algorithm>
 
 // comment out the following define to enable \t symbols in in the python dump files
 #define WITHOUT_TABS
@@ -941,11 +942,10 @@ std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
  *  Purpose  :
  */
 //============================================================================
-std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
+std::string SALOMEDSImpl_Study::_GetNoteBookAccess(const std::string& theStudyVar)
 {
-  std::string accessor = _GetNoteBookAccessor();
   std::string notebook = "import salome_notebook\n";
-  notebook += accessor+" = salome_notebook."+accessor + "\n";
+  notebook += _GetNoteBookAccessor() + " = salome_notebook.NoteBook(" + theStudyVar + ")" ;
   return notebook;
 }
 
@@ -1227,12 +1227,31 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
   for (; itcomponent.More(); itcomponent.Next()) {
     SALOMEDSImpl_SComponent sco = itcomponent.Value();
     aCompType = sco.ComponentDataType();
-    //GEOM and MED are independent components
-    if (aCompType == "GEOM" || aCompType == "MED")
+   if (aCompType == "GEOM")
       aSeq.insert(aSeq.begin(), aCompType);
     else
       aSeq.push_back(aCompType);
   }
+  // re-arrange modules in the sequence, if specific order is given via SALOME_MODULES_ORDER environment variable.
+  if ( getenv("SALOME_MODULES_ORDER") != 0 ) {
+    std::string order = getenv("SALOME_MODULES_ORDER");
+    std::vector<std::string> mlist;
+    while ( !order.empty() ) {
+      size_t idx = order.find( "," );
+      std::string m = order.substr(0, idx);
+      order = order.substr( ( idx == std::string::npos ) ? order.size() : idx+1 );
+      if ( m.empty() || std::find( mlist.begin(), mlist.end(), m ) != mlist.end() ) continue;
+      mlist.push_back( m );
+    }
+
+    for ( std::vector<std::string>::reverse_iterator mit = mlist.rbegin(); mit != mlist.rend(); ++mit ) {
+      std::vector<std::string>::iterator it = std::find( aSeq.begin(), aSeq.end(), *mit );
+      if ( it != aSeq.end() ) {
+        aSeq.erase( it );
+        aSeq.insert( aSeq.begin(), *mit );
+      }
+    }
+  }
 
 #ifdef WIN32
   std::string aFileName =
@@ -1271,13 +1290,15 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
   sfp << "import sys" << std::endl;
   sfp << "import " << aBatchModeScript << std::endl << std::endl;
 
+  std::string aStudyVar = "salome.myStudy";
   // initialization function
   sfp << aBatchModeScript << ".salome_init()" << std::endl;
-  if ( !isMultiFile )
-    sfp << "theStudy = salome.myStudy" <<std::endl << std::endl;
-
+  if ( !isMultiFile ) {
+    sfp << "theStudy = " << aStudyVar << std::endl << std::endl;
+    aStudyVar = "theStudy";
+  }
   // notebook initialization
-  sfp << _GetNoteBookAccess();
+  sfp << _GetNoteBookAccess(aStudyVar) << std::endl;
 
   // extend sys.path with the directory where the script is being dumped to
   sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
@@ -1417,7 +1438,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
 {
   std::stringstream txt;
-  txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl;
+  txt << "# -*- coding: utf-8 -*-" << std::endl << std::endl;
   txt << "###" << std::endl;
   txt << "### This file is generated automatically by SALOME v"
       << KERNEL_VERSION_STR