X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FSALOMEDSImpl_StudyBuilder.cxx;h=b42685c3f828f079f66e1526716262db8168f3b6;hb=080038e8020301ae9b2bca58b6c77146581d6b47;hp=7edbea0230ed7582e92736a42292c2c093cf82ac;hpb=23d6a7d209fbb67a164091e202a117cefef8d0ca;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx index 7edbea023..b42685c3f 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -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 #include -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(); @@ -104,7 +103,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 = ""; @@ -160,7 +159,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SOb */ //============================================================================ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject, - const int theTag) + const int theTag) { _errorCode = ""; CheckLocked(); @@ -205,6 +204,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObjec SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { + _study->DeleteIORLabelMapItem(anAttr->Value()); } Lab.ForgetAllAttributes(); @@ -240,6 +240,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj } SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { + _study->DeleteIORLabelMapItem(anAttr->Value()); } DF_ChildIterator it(Lab, true); @@ -248,10 +249,11 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) { SALOMEDSImpl_AttributeTarget* aTarget = NULL; if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) - aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel)); + aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel)); } SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { + _study->DeleteIORLabelMapItem(anAttr->Value()); } } @@ -281,7 +283,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; @@ -303,7 +305,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; @@ -318,26 +320,28 @@ 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; if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) { - HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group); - hdf_dataset->OpenOnDisk(); - aStreamSize = hdf_dataset->GetSize(); - aStreamFile = new unsigned char[aStreamSize]; - if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM"); - hdf_dataset->ReadFromDisk(aStreamFile); - hdf_dataset->CloseOnDisk(); - hdf_dataset = 0; + HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group); + hdf_dataset->OpenOnDisk(); + aStreamSize = hdf_dataset->GetSize(); + aStreamFile = new unsigned char[aStreamSize]; + if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM"); + hdf_dataset->ReadFromDisk(aStreamFile); + hdf_dataset->CloseOnDisk(); + hdf_dataset = 0; } else aStreamFile = NULL; @@ -349,19 +353,19 @@ 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')? - aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'): - aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'); + 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; if(!aResult) { - RemoveAttribute( anSCO, "AttributeIOR" ); + RemoveAttribute( anSCO, "AttributeIOR" ); - _errorCode = "Can't load component"; - throw HDFexception("Unable to load component"); + _errorCode = "Can't load component"; + throw HDFexception("Unable to load component"); } //if(aDir != NULL) delete []aDir; @@ -379,9 +383,9 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO, delete hdf_file; if (isASCII) { - vector aFilesToRemove; - aFilesToRemove.push_back("hdf_from_ascii.hdf"); - SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), + std::vector aFilesToRemove; + aFilesToRemove.push_back("hdf_from_ascii.hdf"); + SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); } } @@ -389,12 +393,16 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO, delete hdf_file; if (isASCII) { - vector aFilesToRemove; - aFilesToRemove.push_back(aHDFUrl); - SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); + std::vector 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; } @@ -433,7 +441,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) { @@ -456,7 +464,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 { @@ -496,8 +504,8 @@ DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImp //============================================================================ bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject, - DF_Attribute*& anAttribute, - const string& aTypeOfAttribute) + DF_Attribute*& anAttribute, + const std::string& aTypeOfAttribute) { _errorCode = ""; if(!anObject) { @@ -520,7 +528,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(); @@ -530,9 +538,10 @@ 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()); } } @@ -549,7 +558,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anOb */ //============================================================================ bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me, - const SALOMEDSImpl_SObject& theReferencedObject) + const SALOMEDSImpl_SObject& theReferencedObject) { _errorCode = ""; if(!me || !theReferencedObject) { @@ -606,7 +615,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(); @@ -615,7 +624,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; @@ -634,7 +643,7 @@ bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath) aPath = _study->GetContext() + aPath; } - vector vs = SALOMEDSImpl_Tool::splitString(aPath, '/'); + std::vector vs = SALOMEDSImpl_Tool::splitString(aPath, '/'); if(vs.size() == 1) aFatherPath = "/"; else { @@ -677,7 +686,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(); @@ -700,7 +709,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) { @@ -910,7 +919,7 @@ void SALOMEDSImpl_StudyBuilder::CheckLocked() */ //============================================================================ bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO, - const string& theValue) + const std::string& theValue) { _errorCode = ""; CheckLocked(); @@ -931,7 +940,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(); @@ -952,7 +961,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(); @@ -985,14 +994,14 @@ static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* dr SALOMEDSImpl_AttributeLocalID* anID = NULL; if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) - if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it + 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, - persist_ref, - isMultiFile, - isASCII); + std::string ior_string = driver->LocalPersistentIDToIOR(so, + persist_ref, + isMultiFile, + isASCII); SALOMEDSImpl_AttributeIOR::Set (current, ior_string); }