Salome HOME
Additional fix for the issue "16219: EDF PAL 469: "RemoveFromStudy" Function": dump...
[modules/geom.git] / src / GEOM_I / GEOM_DumpPython.cc
index a38ccc58d6c996546fbf8fc0b89a2c2c53ac8fcd..f91628a264c9bc215f3c805bb0638b175ca448c1 100644 (file)
 #include <vector>
 #include <string>
 
+//=======================================================================
+//function : RemoveTabulation
+//purpose  : 
+//=======================================================================
+void RemoveTabulation( TCollection_AsciiString& theScript )
+{
+  std::string aString( theScript.ToCString() );
+  std::string::size_type aPos = 0;
+  while( aPos < aString.length() )
+  {
+    aPos = aString.find( "\n\t", aPos );
+    if( aPos == std::string::npos )
+      break;
+    aString.replace( aPos, 2, "\n" );
+    aPos++;
+  }
+  theScript = aString.c_str();
+}
+
 //=======================================================================
 //function : DumpPython
 //purpose  : 
@@ -43,7 +62,8 @@
 
 Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy, 
                                         CORBA::Boolean isPublished, 
-                                        CORBA::Boolean& isValidScript)
+                                        CORBA::Boolean isMultiFile,
+                                         CORBA::Boolean& isValidScript)
 {
   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
   if(CORBA::is_nil(aStudy))
@@ -72,6 +92,16 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
         objData._name       = aName.in();
         objData._entry      = anEntry.in();
         objData._studyEntry = aStudyEntry.in();
+
+       //Find Drawable Attribute
+       SALOMEDS::GenericAttribute_var aGenAttr;
+       if(aValue->FindAttribute(aGenAttr, "AttributeDrawable") ) {
+         SALOMEDS::AttributeDrawable_var aDrw = SALOMEDS::AttributeDrawable::_narrow(aGenAttr);
+         objData._unpublished = !aDrw->IsDrawable();
+       } else {
+         objData._unpublished = false;
+       }
+
        objectDataVec.push_back( objData );
 
        //Find attribute with list of used notebook variables
@@ -98,7 +128,7 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
   }
   
   TCollection_AsciiString aScript;
-  aScript += _impl->DumpPython(aStudy->StudyId(), objectDataVec, aVariableMap, isPublished, isValidScript);
+  aScript += _impl->DumpPython(aStudy->StudyId(), objectDataVec, aVariableMap, isPublished, isMultiFile, isValidScript);
 
   if (isPublished)
   {
@@ -111,7 +141,12 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
     }
   }
 
-  aScript += "\n\tpass\n";
+  if( isMultiFile )
+    aScript += "\n\tpass";
+  aScript += "\n";
+
+  if( !isMultiFile ) // remove unnecessary tabulation
+    RemoveTabulation( aScript );
 
   int aLen = aScript.Length(); 
   unsigned char* aBuffer = new unsigned char[aLen+1];