Salome HOME
Implement a way to re-arrange modules order in study dump
authorvsr <vsr@opencascade.com>
Tue, 29 Sep 2015 12:34:12 +0000 (15:34 +0300)
committervsr <vsr@opencascade.com>
Tue, 29 Sep 2015 12:34:12 +0000 (15:34 +0300)
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx

index 6fe45d9a7d115409a59e115a675c01bbf90eb71a..0fc9172e4e94adaab5538a6e829205c2b99af9da 100644 (file)
@@ -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
@@ -1226,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 =