-// Copyright (C) 2007-2008 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
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// 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.
+// 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, 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
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// File : SALOMEDSImpl_StudyBuilder.cxx
// Author : Sergey RUIN
// Module : SALOME
#include <HDFOI.hxx>
#include <stdlib.h>
-
-using namespace std;
+#include <string.h>
#define USE_CASE_LABEL_TAG 2
#define DIRECTORYID 16661
* 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();
SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const SALOMEDSImpl_SComponent& aComponent,
- const string& IOR)
+ const std::string& IOR)
{
_errorCode = "";
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
return so;
*/
//============================================================================
SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject,
- const int theTag)
+ const int theTag)
{
_errorCode = "";
CheckLocked();
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
return so;
SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
+ _study->DeleteIORLabelMapItem(anAttr->Value());
}
Lab.ForgetAllAttributes();
_doc->SetModified(true);
+ _study->removeSO_Notification(anObject);
return true;
}
}
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);
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());
}
}
Lab.ForgetAllAttributes(true);
_doc->SetModified(true);
+ _study->removeSO_Notification(anObject);
return true;
}
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;
DefineComponentInstance (anSCO, aDriver->GetIOR());
- string aHDFUrl;
+ std::string aHDFUrl;
bool isASCII = false;
if (HDFascii::isASCII(aHDFPath.c_str())) {
isASCII = true;
//Open the Study HDF file
HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
- char aMultifileState[2];
- char ASCIIfileState[2];
+ char aMultifileState[2] = { '0','0' };
+ char ASCIIfileState[2] = { '0','0' };
+ 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;
- HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
- multifile_hdf_dataset->OpenOnDisk();
- multifile_hdf_dataset->ReadFromDisk(aMultifileState);
+ if (hdf_sco_group->ExistInternalObject("MULTIFILE_STATE")) {
+ HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
+ multifile_hdf_dataset->OpenOnDisk();
+ multifile_hdf_dataset->ReadFromDisk(aMultifileState);
+ multifile_hdf_dataset->CloseOnDisk();
+ multifile_hdf_dataset = 0;
+ }
- HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
- ascii_hdf_dataset->OpenOnDisk();
- ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
+ if (hdf_sco_group->ExistInternalObject("ASCII_STATE")) {
+ HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
+ ascii_hdf_dataset->OpenOnDisk();
+ ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
+ ascii_hdf_dataset->CloseOnDisk();
+ ascii_hdf_dataset = 0;
+ }
- 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');
+ 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;
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;
- multifile_hdf_dataset->CloseOnDisk();
- multifile_hdf_dataset = 0;
- ascii_hdf_dataset->CloseOnDisk();
- ascii_hdf_dataset = 0;
-
hdf_sco_group->CloseOnDisk();
hdf_sco_group = 0;
hdf_group->CloseOnDisk();
delete hdf_file;
if (isASCII) {
- vector<string> aFilesToRemove;
- aFilesToRemove.push_back("hdf_from_ascii.hdf");
- SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
+ std::vector<std::string> aFilesToRemove;
+ aFilesToRemove.push_back("hdf_from_ascii.hdf");
+ SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
aFilesToRemove, true);
}
}
delete hdf_file;
if (isASCII) {
- vector<string> aFilesToRemove;
- aFilesToRemove.push_back(aHDFUrl);
- SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
+ 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;
}
*/
//============================================================================
DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
- const string& aTypeOfAttribute)
+ const std::string& aTypeOfAttribute)
{
_errorCode = "";
if(!anObject) {
//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 {
//============================================================================
bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
- DF_Attribute*& anAttribute,
- const string& aTypeOfAttribute)
+ DF_Attribute*& anAttribute,
+ const std::string& aTypeOfAttribute)
{
_errorCode = "";
if(!anObject) {
//============================================================================
bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
- const string& aTypeOfAttribute)
+ const std::string& aTypeOfAttribute)
{
_errorCode = "";
CheckLocked();
}
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());
}
}
Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
_doc->SetModified(true);
+ _study->modifySO_Notification(anObject,0);
return true;
}
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
- const SALOMEDSImpl_SObject& theReferencedObject)
+ const SALOMEDSImpl_SObject& theReferencedObject)
{
_errorCode = "";
if(!me || !theReferencedObject) {
* 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();
return false;
}
- string aPath(thePath), aContext(""), aFatherPath;
+ std::string aPath(thePath), aContext(""), aFatherPath;
DF_Label aLabel;
SALOMEDSImpl_SObject anObject;
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 {
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
- const string& theGUID)
+ const std::string& theGUID)
{
_errorCode = "";
CheckLocked();
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
- const string& theGUID)
+ const std::string& theGUID)
{
_errorCode = "";
if(!anObject) {
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
- const string& theValue)
+ const std::string& theValue)
{
_errorCode = "";
CheckLocked();
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
- const string& theValue)
+ const std::string& theValue)
{
_errorCode = "";
CheckLocked();
*/
//============================================================================
bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
- const string& theValue)
+ const std::string& theValue)
{
_errorCode = "";
CheckLocked();
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);
- SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
-
+ std::string ior_string = driver->LocalPersistentIDToIOR(so,
+ persist_ref,
+ isMultiFile,
+ isASCII);
+ SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
}
Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);
}
}
-