Salome HOME
Implementation of the "20830: EDF 1357 GUI : Hide/Show Icon"
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_StudyBuilder.cxx
index d09c10e259b3fba754b490e75b2fdfcf6d889b2d..f02b2bd946bea9b8c8e2ffaf8c0cf0473cce4249 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  File   : SALOMEDSImpl_StudyBuilder.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
@@ -38,8 +39,6 @@
 #include <stdlib.h> 
 #include <string.h> 
 
-using namespace std;
-
 #define USE_CASE_LABEL_TAG            2
 #define DIRECTORYID                   16661
 #define FILELOCALID                   26662 
@@ -73,7 +72,7 @@ SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
  *  Purpose  : Create a new component (Scomponent)
  */
 //============================================================================
-SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const string& DataType)
+SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const std::string& DataType)
 {
   _errorCode = "";
   CheckLocked();
@@ -92,6 +91,7 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const string& Da
   SALOMEDSImpl_SComponent so =  _study->GetSComponent (NL);
 
   if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+  _study->addSO_Notification(so);
 
   _doc->SetModified(true);
 
@@ -104,7 +104,7 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const string& Da
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const SALOMEDSImpl_SComponent& aComponent,
-                                                        const string& IOR)
+                                                        const std::string& IOR)
 {
    _errorCode = "";
 
@@ -149,6 +149,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SOb
   
   SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
   if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+  _study->addSO_Notification(so);
 
   _doc->SetModified(true);  
   return so;
@@ -173,6 +174,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImp
   SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
 
   if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+  _study->addSO_Notification(so);
 
   _doc->SetModified(true);  
   return so;
@@ -211,6 +213,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObjec
   Lab.ForgetAllAttributes();
  
   _doc->SetModified(true);  
+  _study->removeSO_Notification(anObject);
     
   return true;
 }
@@ -261,6 +264,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj
   Lab.ForgetAllAttributes(true);
 
   _doc->SetModified(true);  
+  _study->removeSO_Notification(anObject);
   
   return true;
 }
@@ -284,7 +288,7 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
     if (aLocked) _study->GetProperties()->SetLocked(false);
 
     std::string Res(Att->Value());
-    string aHDFPath(Res);
+    std::string aHDFPath(Res);
 
     SALOMEDSImpl_AttributeComment* type = NULL;
     std::string DataType;
@@ -306,7 +310,7 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
 
     DefineComponentInstance (anSCO, aDriver->GetIOR());
 
-    string aHDFUrl;
+    std::string aHDFUrl;
     bool isASCII = false;
     if (HDFascii::isASCII(aHDFPath.c_str())) {
       isASCII = true;
@@ -321,13 +325,15 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
 
     char aMultifileState[2];
     char ASCIIfileState[2];
+    bool hasModuleData = false;
     try {
-      string scoid = anSCO.GetID();
+      std::string scoid = anSCO.GetID();
       hdf_file->OpenOnDisk(HDF_RDONLY);
       HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
       hdf_group->OpenOnDisk();
       HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
       hdf_sco_group->OpenOnDisk();
+      hasModuleData = true;
 
       unsigned char* aStreamFile = NULL;
       int aStreamSize = 0;
@@ -352,11 +358,14 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
       ascii_hdf_dataset->OpenOnDisk();
       ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
 
-      string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
+      std::string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
 
-      bool aResult = (ASCIIfileState[0]=='A')?
+      bool aResult = true;
+      if(aStreamFile && aStreamSize > 0 ) {
+        aResult = (ASCIIfileState[0]=='A')?
         aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
         aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
+      }
 
       if(aStreamFile != NULL) delete []aStreamFile; 
 
@@ -382,7 +391,7 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
       delete hdf_file;
 
       if (isASCII) {
-        vector<string> aFilesToRemove;
+        std::vector<std::string> aFilesToRemove;
         aFilesToRemove.push_back("hdf_from_ascii.hdf");
         SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
                                                 aFilesToRemove, true);
@@ -392,12 +401,16 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
       delete hdf_file;
 
       if (isASCII) {
-        vector<string> aFilesToRemove;
+        std::vector<std::string> aFilesToRemove;
         aFilesToRemove.push_back(aHDFUrl);
         SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
       }
 
       if (aLocked) _study->GetProperties()->SetLocked(true);
+
+      if (!hasModuleData)
+       return true;
+
       _errorCode = "No persistent file";   
       return false;
     }
@@ -436,7 +449,7 @@ bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
  */
 //============================================================================
 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject, 
-                                                               const string& aTypeOfAttribute)
+                                                               const std::string& aTypeOfAttribute)
 {
   _errorCode = "";
   if(!anObject) {
@@ -459,7 +472,7 @@ DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImp
   //Add checks for TreeNode and UserID attributes  
   if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
     
-    string aTreeNodeGUID;
+    std::string aTreeNodeGUID;
     if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
       aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
     } else {
@@ -500,7 +513,7 @@ DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImp
 
 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject, 
                                               DF_Attribute*& anAttribute, 
-                                              const string& aTypeOfAttribute)
+                                              const std::string& aTypeOfAttribute)
 {
   _errorCode = "";
   if(!anObject) {
@@ -523,7 +536,7 @@ bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObje
 //============================================================================
 
 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject, 
-                                                const string& aTypeOfAttribute)
+                                                const std::string& aTypeOfAttribute)
 {
   _errorCode = "";
   CheckLocked();
@@ -533,7 +546,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anOb
   }
   DF_Label Lab = anObject.GetLabel();
   
-  if (aTypeOfAttribute == string("AttributeIOR")) { // Remove from IORLabel map
+  if (aTypeOfAttribute == std::string("AttributeIOR")) { // Remove from IORLabel map
     SALOMEDSImpl_AttributeIOR* anAttr = NULL;
     if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
       _study->DeleteIORLabelMapItem(anAttr->Value());
@@ -543,6 +556,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anOb
   Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
     
   _doc->SetModified(true);  
+  _study->modifySO_Notification(anObject,0);
     
   return true;
 }
@@ -610,7 +624,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
  *  Purpose  : adds a new directory with a path = thePath
  */
 //============================================================================
-bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath) 
+bool SALOMEDSImpl_StudyBuilder::AddDirectory(const std::string& thePath) 
 {
   _errorCode = "";
   CheckLocked();
@@ -619,7 +633,7 @@ bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
     return false;
   }
 
-  string aPath(thePath), aContext(""), aFatherPath;
+  std::string aPath(thePath), aContext(""), aFatherPath;
   DF_Label aLabel;
   SALOMEDSImpl_SObject anObject;
 
@@ -638,7 +652,7 @@ bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
     aPath = _study->GetContext() + aPath;
   }
 
-  vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
+  std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
   if(vs.size() == 1) 
     aFatherPath = "/";
   else {
@@ -681,7 +695,7 @@ bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject, 
-                                        const string& theGUID)
+                                        const std::string& theGUID)
 {
   _errorCode = "";
   CheckLocked();
@@ -704,7 +718,7 @@ bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject, 
-                                       const string& theGUID)
+                                       const std::string& theGUID)
 {
   _errorCode = "";
   if(!anObject) {
@@ -914,7 +928,7 @@ void SALOMEDSImpl_StudyBuilder::CheckLocked()
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO, 
-                                        const string& theValue)
+                                        const std::string& theValue)
 {
   _errorCode = "";
   CheckLocked();
@@ -935,7 +949,7 @@ bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO, 
-                                           const string& theValue)
+                                           const std::string& theValue)
 {
   _errorCode = "";
   CheckLocked();
@@ -956,7 +970,7 @@ bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
  */
 //============================================================================
 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO, 
-                                       const string& theValue)
+                                       const std::string& theValue)
 {
   _errorCode = "";
   CheckLocked();
@@ -991,9 +1005,9 @@ static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* dr
       if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) 
         if (anID->Value() == FILELOCALID) continue;   //SRN: This attribute store a file name, skip it 
 
-      string persist_ref = Att->Value();
+      std::string persist_ref = Att->Value();
       SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
-      string ior_string = driver->LocalPersistentIDToIOR(so, 
+      std::string ior_string = driver->LocalPersistentIDToIOR(so, 
                                                          persist_ref, 
                                                          isMultiFile, 
                                                          isASCII);