X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_StudyBuilder_i.cxx;h=492a911dd43385eb76aaf23b481606c8624f3952;hb=f01a3911fa7b074af7e1ac958be5763aeed5d056;hp=125152fedbd1723d1ce998e1d2dfe8d6a8f7cb6d;hpb=89d8cdd476c5f4d65bc3fd1089f092af42e2841c;p=modules%2Fkernel.git diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx index 125152fed..492a911dd 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx @@ -1,104 +1,62 @@ -// SALOME SALOMEDS : data structure of SALOME and sources of Salome data server +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 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 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 -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + // File : SALOMEDS_StudyBuilder_i.cxx -// Author : Yves FRICAUD +// Author : Seregy RUIN // Module : SALOME -// $Header$ - +// #include "utilities.h" +#include "SALOMEDS_StudyBuilder_i.hxx" #include "SALOMEDS_Study_i.hxx" -//#include "SALOMEDS_StudyBuilder_i.hxx" #include "SALOMEDS_SObject_i.hxx" #include "SALOMEDS_SComponent_i.hxx" +#include "SALOMEDS_GenericAttribute_i.hxx" +#include "SALOMEDS_Driver_i.hxx" +#include "SALOMEDS.hxx" + +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_SComponent.hxx" -#include "SALOMEDS_IORAttribute.hxx" -#include "SALOMEDS_PersRefAttribute.hxx" -#include "SALOMEDS_TargetAttribute.hxx" -#include "SALOMEDS_StudyPropertiesAttribute.hxx" -#include "SALOMEDS_PythonObjectAttribute.hxx" -#include "SALOMEDS_ExternalFileDef.hxx" -#include "SALOMEDS_FileType.hxx" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "SALOMEDS_AttributePersistentRef_i.hxx" -#include "SALOMEDS_AttributeIOR_i.hxx" -#include "SALOMEDS_AttributeExternalFileDef_i.hxx" -#include "SALOMEDS_AttributeFileType_i.hxx" -#include "SALOMEDS_AttributeComment_i.hxx" -#include "SALOMEDS_AttributeName_i.hxx" -#include "SALOMEDS_AttributeSequenceOfInteger_i.hxx" -#include "SALOMEDS_AttributeSequenceOfReal_i.hxx" -#include "SALOMEDS_AttributeTableOfInteger_i.hxx" -#include "SALOMEDS_AttributeTableOfReal_i.hxx" -#include "SALOMEDS_AttributeTableOfString_i.hxx" -#include "SALOMEDS_AttributeInteger_i.hxx" -#include "SALOMEDS_AttributeReal_i.hxx" -#include "SALOMEDS_AttributeDrawable_i.hxx" -#include "SALOMEDS_AttributeSelectable_i.hxx" -#include "SALOMEDS_AttributeExpandable_i.hxx" -#include "SALOMEDS_AttributeOpened_i.hxx" -#include "SALOMEDS_AttributeTextColor_i.hxx" -#include "SALOMEDS_AttributeTextHighlightColor_i.hxx" -#include "SALOMEDS_AttributePixMap_i.hxx" -#include "SALOMEDS_AttributeTreeNode_i.hxx" -#include "SALOMEDS_AttributeTarget_i.hxx" -#include "SALOMEDS_AttributeLocalID_i.hxx" -#include "SALOMEDS_AttributeUserID_i.hxx" -#include "SALOMEDS_AttributeStudyProperties_i.hxx" -#include "SALOMEDS_AttributePythonObject_i.hxx" -#include "SALOMEDS_Tool.hxx" #include "Utils_CorbaException.hxx" #include "Utils_ExceptHandlers.hxx" -#include +#include +#include #include -using namespace std; - -#define USE_CASE_LABEL_TAG 2 -#define DIRECTORYID 16661 -#define FILELOCALID 26662 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception); UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection); + //============================================================================ /*! Function : constructor * Purpose : */ //============================================================================ -SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) doc, - CORBA::ORB_ptr orb) : _doc(doc) +SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDSImpl_StudyBuilder* theImpl, + CORBA::ORB_ptr orb) { _orb = CORBA::ORB::_duplicate(orb); + _impl = theImpl; } //============================================================================ @@ -107,41 +65,24 @@ SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) */ //============================================================================ SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i() -{ -} +{} //============================================================================ /*! Function : NewComponent * Purpose : Create a new component (Scomponent) */ //============================================================================ -SALOMEDS::SComponent_ptr -SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType) +SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType) { + SALOMEDS::Locker lock; CheckLocked(); - //Always create component under main label. - TDF_Label L = _doc->Main(); - - // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild(); - - Standard_Integer imax = 0; - for (TDF_ChildIterator it(L); it.More(); it.Next()) { - if (it.Value().Tag() > imax) - imax = it.Value().Tag(); - } - imax++; - TDF_Label NL = L.FindChild(imax); + //char* aDataType = CORBA::string_dup(DataType); + SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(std::string(DataType)); + //CORBA::free_string(aDataType); + if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil(); - TDataStd_Comment::Set(NL,Standard_CString(DataType)); - // TDataStd_Comment::Set(NL,Standard_CString(CORBA::string_dup(DataType))); - - SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (NL,_orb); - SALOMEDS::SComponent_var so; - so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this()); - - if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so); - - return so; + SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb); + return sco._retn(); } //============================================================================ @@ -150,20 +91,15 @@ SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType) */ //============================================================================ void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent, - CORBA::Object_ptr IOR) + CORBA::Object_ptr IOR) { + SALOMEDS::Locker lock; CheckLocked(); - //Find label - TDF_Label Lab; - ASSERT(!CORBA::is_nil(aComponent)); - CORBA::String_var compid = aComponent->GetID(); - TDF_Tool::Label(_doc->GetData(),compid,Lab); + CORBA::String_var anID=aComponent->GetID(); + SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in()); - //add IOR definition - ASSERT(!CORBA::is_nil(IOR)); CORBA::String_var iorstr = _orb->object_to_string(IOR); - SALOMEDS_IORAttribute::Set(Lab,(char*)iorstr,_orb); - + _impl->DefineComponentInstance(aSCO, (char*)iorstr.in()); } //============================================================================ @@ -171,12 +107,14 @@ void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr a * Purpose : Delete a Scomponent */ //============================================================================ -void -SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent) +void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent) { + SALOMEDS::Locker lock; CheckLocked(); ASSERT(!CORBA::is_nil(aComponent)); - RemoveObject(aComponent); + CORBA::String_var cid=aComponent->GetID(); + SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(cid.in()); + _impl->RemoveComponent(aSCO); } //============================================================================ @@ -184,35 +122,19 @@ SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent) * Purpose : Create a new SObject */ //============================================================================ -SALOMEDS::SObject_ptr -SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject) +SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject) { + SALOMEDS::Locker lock; CheckLocked(); - TCollection_AsciiString anEntry; - - //Find label of father - TDF_Label Lab; - - ASSERT(!CORBA::is_nil(theFatherObject)); - CORBA::String_var fatherid = theFatherObject->GetID(); - TDF_Tool::Label(_doc->GetData(),fatherid,Lab); - - //Create a new label - //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild(); - Standard_Integer imax = 0; - for (TDF_ChildIterator it(Lab); it.More(); it.Next()) { - if (it.Value().Tag() > imax) - imax = it.Value().Tag(); - } - imax++; - TDF_Label NewLab = Lab.FindChild(imax); - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb); - SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); + SALOMEDSImpl_SObject aFO, aSO; + CORBA::String_var anID=theFatherObject->GetID(); + aFO = _impl->GetOwner()->GetSObject(anID.in()); + aSO = _impl->NewObject(aFO); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb); - if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so); - - return so; + return so._retn(); } //============================================================================ @@ -220,26 +142,17 @@ SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject) * Purpose : */ //============================================================================ -SALOMEDS::SObject_ptr -SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject, - CORBA::Long atag) +SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject, + CORBA::Long atag) { + SALOMEDS::Locker lock; CheckLocked(); - //Find label of father - TDF_Label Lab; - - ASSERT(!CORBA::is_nil(theFatherObject)); - CORBA::String_var fatherid = theFatherObject->GetID(); - TDF_Tool::Label(_doc->GetData(),fatherid,Lab); - //Create or find label - TDF_Label NewLab = Lab.FindChild(atag,1); - - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb); - SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); - - if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so); - - return so; + SALOMEDSImpl_SObject aFO, aSO; + aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID()); + aSO = _impl->NewObjectToTag(aFO, atag); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + return so._retn(); } //============================================================================ @@ -249,25 +162,11 @@ SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject, //============================================================================ void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject) { + SALOMEDS::Locker lock; CheckLocked(); - if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject); - - TDF_Label Lab; - ASSERT(!CORBA::is_nil(anObject)); - TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab); - - Handle(TDF_Reference) aReference; - if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) { - Handle(SALOMEDS_TargetAttribute) aTarget; - if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget)) - aTarget->Remove(Lab); - } - - Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects - if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString()); - - Lab.ForgetAllAttributes(); + CORBA::String_var anID=anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->RemoveObject(aSO); } //============================================================================ @@ -277,81 +176,11 @@ void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject) //============================================================================ void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject) { + SALOMEDS::Locker lock; CheckLocked(); - if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject); - - TDF_Label Lab; - ASSERT(!CORBA::is_nil(anObject)); - TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab); - - Handle(TDF_Reference) aReference; - if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) { - Handle(SALOMEDS_TargetAttribute) aTarget; - if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget)) - aTarget->Remove(Lab); - } - Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects - if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString()); - - TDF_ChildIterator it(Lab, Standard_True); - for(;it.More();it.Next()) { - TDF_Label aLabel = it.Value(); - if (aLabel.FindAttribute(TDF_Reference::GetID(), aReference)) { - Handle(SALOMEDS_TargetAttribute) aTarget; - if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget)) - aTarget->Remove(aLabel); - } - Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects - if (aLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString()); - } - - Lab.ForgetAllAttributes(Standard_True); -} - -//============================================================================ -/*! Function : Translate_persistentID_to_IOR - * Purpose : - */ -//============================================================================ -static void Translate_persistentID_to_IOR(TDF_Label Lab, - SALOMEDS::Driver_ptr driver, - CORBA::ORB_ptr orb, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) -{ - TDF_ChildIterator itchild (Lab); - - for (; itchild.More(); itchild.Next()) { - TDF_Label current = itchild.Value(); - Handle(TDF_Attribute) Att; - if (current.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) { - - Handle(SALOMEDS_LocalIDAttribute) anID; - if (current.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID)) - if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it - - TCollection_ExtendedString res; - res = Handle(TDataStd_Comment)::DownCast(Att)->Get(); - TCollection_AsciiString ch(res); - - CORBA::String_var persistent_string = CORBA::string_dup(ch.ToCString()); - ASSERT(! CORBA::is_nil(driver)); - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (current,orb); - SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); - - CORBA::String_var ior_string = driver->LocalPersistentIDToIOR(so, persistent_string, isMultiFile, isASCII); - - TCollection_ExtendedString value(ior_string); - SALOMEDS_IORAttribute::Set (current,value,orb); - - //TCollection_AsciiString anEntry;TDF_Tool::Entry (current,anEntry); //SRN: No use here - //delete persistent_string; - //delete ior_string; - } - Translate_persistentID_to_IOR (current,driver,orb,isMultiFile, isASCII); - } + CORBA::String_var anID=anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->RemoveObjectWithChildren(aSO); } //============================================================================ @@ -359,156 +188,21 @@ static void Translate_persistentID_to_IOR(TDF_Label Lab, * Purpose : */ //============================================================================ - -//============================================================================ void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO, - SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception) + SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception) { + SALOMEDS::Locker lock; Unexpect aCatch(SBSalomeException); - TDF_Label Lab; - ASSERT(!CORBA::is_nil(anSCO)); - CORBA::String_var scoid = anSCO->GetID(); - TDF_Tool::Label(_doc->GetData(),scoid,Lab); - Handle(TDF_Attribute) Att; - - //Find the current Url of the study - if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) { - int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked(); - if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false); - - TCollection_ExtendedString Res = Handle(TDataStd_Comment)::DownCast(Att)->Get(); - - Handle(TDataStd_Comment) type; - TCollection_ExtendedString DataType; - if (Lab.FindAttribute(TDataStd_Comment::GetID(),type)) - DataType = type->Get(); - else - MESSAGE("No Data Type"); - - // associate the driver to the SComponent - ASSERT(!CORBA::is_nil(aDriver)); - // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again - if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) { - if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); - return; - } - DefineComponentInstance (anSCO, aDriver); - - TCollection_AsciiString aHDFPath(Res); - - char* aHDFUrl; - bool isASCII = false; - if (HDFascii::isASCII(aHDFPath.ToCString())) { - isASCII = true; - char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString()); - aHDFUrl = new char[strlen(aResultPath) + 19]; - sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath); - delete(aResultPath); - } else { - aHDFUrl = CORBA::string_dup(aHDFPath.ToCString()); - } - - //Open the Study HDF file - HDFfile *hdf_file = new HDFfile(aHDFUrl); - - char aMultifileState[2]; - char ASCIIfileState[2]; - try { - CORBA::String_var 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(scoid, hdf_group); - hdf_sco_group->OpenOnDisk(); - - SALOMEDS::TMPFile_var aStreamFile; - if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) { - HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group); - hdf_dataset->OpenOnDisk(); - int aStreamSize = hdf_dataset->GetSize(); - unsigned char* aBuffer = new unsigned char[aStreamSize]; - if(aBuffer == NULL) throw HDFexception("Unable to open dataset FILE_STREAM"); - hdf_dataset->ReadFromDisk(aBuffer); - aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1); - hdf_dataset->CloseOnDisk(); - hdf_dataset = 0; - } else aStreamFile = new SALOMEDS::TMPFile(0); - - HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group); - multifile_hdf_dataset->OpenOnDisk(); - multifile_hdf_dataset->ReadFromDisk(aMultifileState); - - HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group); - ascii_hdf_dataset->OpenOnDisk(); - ascii_hdf_dataset->ReadFromDisk(ASCIIfileState); - - // set path without file name from URL - int aFileNameSize = Res.Length(); - char* aDir = new char[aFileNameSize]; - memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize); - for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--) - if (aDir[aCounter] == '/') { - aDir[aCounter+1] = 0; - break; - } - - CORBA::Boolean aResult = (ASCIIfileState[0]=='A')? - aDriver->LoadASCII(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M'): - aDriver->Load(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M'); - if(!aResult) { - RemoveAttribute( anSCO, "AttributeIOR" ); - MESSAGE("Can't load component"); - //THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM); - throw HDFexception("Unable to load component"); - } - - delete(aDir); + CORBA::String_var anID=anSCO->GetID(); + SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in()); + SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb); + bool isDone = _impl->LoadWith(aSCO, driver); + delete driver; - 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(); - hdf_group = 0; - hdf_file->CloseOnDisk(); - delete hdf_file; - - if (isASCII) { - SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; - aFilesToRemove->length(1); - aFilesToRemove[0] = CORBA::string_dup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl).c_str())])); - SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl).c_str(), aFilesToRemove, true); - } - delete aHDFUrl; - } - catch (HDFexception) { - INFOS("No persistent file Name"); - delete hdf_file; - if (isASCII) { - SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; - aFilesToRemove->length(1); - aFilesToRemove[0] = CORBA::string_dup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl).c_str())])); - SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl).c_str(), aFilesToRemove, true); - } - delete aHDFUrl; - if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); - THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM); - } - - try { - Translate_persistentID_to_IOR (Lab,aDriver,_orb, aMultifileState[0]=='M', ASCIIfileState[0] == 'A'); - } catch (SALOME::SALOME_Exception) { - INFOS("Can't translate PersRef to IOR"); - if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); - THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM); - // throw HDFexception("Unable to load component data"); - } - if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); - } else - MESSAGE("No persistent file Name"); + if(!isDone && _impl->IsError()) { + THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM); + } } @@ -529,90 +223,47 @@ void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco) */ //============================================================================ SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject, - const char* aTypeOfAttribute) -{ - TDF_Label Lab; - ASSERT(!CORBA::is_nil(anObject)); - CORBA::String_var anobid = anObject->GetID(); - TDF_Tool::Label(_doc->GetData(),anobid,Lab); - - __FindOrCreateAttributeLocked(TDataStd_Real, AttributeReal) - __FindOrCreateAttributeLocked(TDataStd_Integer, AttributeInteger) - __FindOrCreateAttributeLocked(SALOMEDS_SequenceOfRealAttribute, AttributeSequenceOfReal) - __FindOrCreateAttributeLocked(SALOMEDS_SequenceOfIntegerAttribute, AttributeSequenceOfInteger) - __FindOrCreateAttributeLocked(TDataStd_Name, AttributeName) - __FindOrCreateAttributeLocked(TDataStd_Comment, AttributeComment) - __FindOrCreateAttributeLocked(SALOMEDS_IORAttribute, AttributeIOR) - __FindOrCreateAttributeLocked(SALOMEDS_PixMapAttribute, AttributePixMap) - __FindOrCreateAttributeLocked(SALOMEDS_LocalIDAttribute, AttributeLocalID) - __FindOrCreateAttributeLocked(SALOMEDS_TableOfIntegerAttribute, AttributeTableOfInteger) - __FindOrCreateAttributeLocked(SALOMEDS_TableOfRealAttribute, AttributeTableOfReal) - __FindOrCreateAttributeLocked(SALOMEDS_TableOfStringAttribute, AttributeTableOfString) - __FindOrCreateAttributeLocked(SALOMEDS_PythonObjectAttribute, AttributePythonObject) - - __FindOrCreateAttribute(SALOMEDS_PersRefAttribute, AttributePersistentRef) - __FindOrCreateAttribute(SALOMEDS_DrawableAttribute, AttributeDrawable) - __FindOrCreateAttribute(SALOMEDS_SelectableAttribute, AttributeSelectable) - __FindOrCreateAttribute(SALOMEDS_ExpandableAttribute, AttributeExpandable) - __FindOrCreateAttribute(SALOMEDS_OpenedAttribute, AttributeOpened) - __FindOrCreateAttribute(SALOMEDS_TextColorAttribute, AttributeTextColor) - __FindOrCreateAttribute(SALOMEDS_TextHighlightColorAttribute, AttributeTextHighlightColor) - __FindOrCreateAttribute(SALOMEDS_TargetAttribute, AttributeTarget) - __FindOrCreateAttribute(SALOMEDS_StudyPropertiesAttribute, AttributeStudyProperties) - __FindOrCreateAttribute(SALOMEDS_ExternalFileDef, AttributeExternalFileDef) - __FindOrCreateAttribute(SALOMEDS_FileType, AttributeFileType) - - if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) { - Standard_GUID aTreeNodeGUID; - if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0) { - aTreeNodeGUID = TDataStd_TreeNode::GetDefaultTreeID(); - } else { - char* aGUIDString = new char[40]; - sprintf(aGUIDString, &(aTypeOfAttribute[21])); - aTreeNodeGUID = Standard_GUID(aGUIDString); // create tree node GUID by name - delete(aGUIDString); - } - Handle(TDataStd_TreeNode) anAttr; - if (!Lab.FindAttribute(aTreeNodeGUID, anAttr)) { - CheckLocked(); - anAttr = TDataStd_TreeNode::Set(Lab, aTreeNodeGUID); - } - SALOMEDS_AttributeTreeNode_i* aTreeNodeAttr = new SALOMEDS_AttributeTreeNode_i(anAttr, _orb); - return aTreeNodeAttr->AttributeTreeNode::_this(); + const char* aTypeOfAttribute) +{ + SALOMEDS::Locker lock; + CORBA::String_var anID = anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout()); + DF_Attribute* anAttr; + try { + anAttr = _impl->FindOrCreateAttribute(aSO, std::string(aTypeOfAttribute)); } - - if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) { - Handle(TDataStd_UAttribute) anAttr; - if (!Lab.FindAttribute(SALOMEDS_AttributeUserID_i::DefaultID(), anAttr)) { - CheckLocked(); - anAttr = TDataStd_UAttribute::Set(Lab, SALOMEDS_AttributeUserID_i::DefaultID()); - } - SALOMEDS_AttributeUserID_i* aUAttr = new SALOMEDS_AttributeUserID_i(anAttr, _orb); - return aUAttr->AttributeUserID::_this(); + catch (...) { + throw SALOMEDS::StudyBuilder::LockProtection(); } - return SALOMEDS::GenericAttribute::_nil(); + + SALOMEDS::GenericAttribute_var anAttribute; + + if(anAttr) + anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb); + + return anAttribute._retn(); } //============================================================================ /*! Function : FindAttribute - * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found + * Purpose : Find attribute of given type assigned SObject, returns true if it is found */ //============================================================================ CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject, - SALOMEDS::GenericAttribute_out anAttribute, - const char* aTypeOfAttribute) + SALOMEDS::GenericAttribute_out anAttribute, + const char* aTypeOfAttribute) { - TDF_Label Lab; + SALOMEDS::Locker lock; ASSERT(!CORBA::is_nil(anObject)); - CORBA::String_var anobid = anObject->GetID(); - TDF_Tool::Label(_doc->GetData(),anobid,Lab); - Handle(TDF_Attribute) anAttr; - if (Lab.FindAttribute(SALOMEDS_GenericAttribute_i::GetGUID(aTypeOfAttribute), anAttr)) { - anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(_orb, anAttr)); - return Standard_True; - } - return Standard_False; + CORBA::String_var anID = anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + DF_Attribute* anAttr; + + if(!_impl->FindAttribute(aSO, anAttr, std::string(aTypeOfAttribute))) return false; + + anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb); + return true; } //============================================================================ @@ -622,22 +273,14 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anOb //============================================================================ void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject, - const char* aTypeOfAttribute) + const char* aTypeOfAttribute) { + SALOMEDS::Locker lock; CheckLocked(); - TDF_Label Lab; ASSERT(!CORBA::is_nil(anObject)); - CORBA::String_var anobid = anObject->GetID(); - TDF_Tool::Label(_doc->GetData(),anobid,Lab); - - if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0) { // postponed removing of CORBA objects - Handle(SALOMEDS_IORAttribute) anAttr; - if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString()); - else return; - } - - Lab.ForgetAttribute (SALOMEDS_GenericAttribute_i::GetGUID(aTypeOfAttribute)); + CORBA::String_var anID = anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->RemoveAttribute(aSO, std::string(aTypeOfAttribute)); } //============================================================================ @@ -645,24 +288,20 @@ void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject, * Purpose : */ //============================================================================ -void -SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me, - SALOMEDS::SObject_ptr theReferencedObject) +void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me, + SALOMEDS::SObject_ptr theReferencedObject) { + SALOMEDS::Locker lock; CheckLocked(); - TDF_Label Lab; ASSERT(!CORBA::is_nil(me)); - CORBA::String_var meid = me->GetID(); - TDF_Tool::Label(_doc->GetData(),meid,Lab); - TDF_Label RefLab; ASSERT(!CORBA::is_nil(theReferencedObject)); - CORBA::String_var roid = theReferencedObject->GetID(); - TDF_Tool::Label(_doc->GetData(),roid,RefLab); - TDF_Reference::Set(Lab,RefLab); - - SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab); - - if(!CORBA::is_nil(_callbackOnRemove) && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me); + + SALOMEDSImpl_SObject aSO, aRefSO; + CORBA::String_var anID = me->GetID(); + aSO = _impl->GetOwner()->GetSObject(anID.in()); + anID=theReferencedObject->GetID(); + aRefSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->Addreference(aSO, aRefSO); } //============================================================================ @@ -672,30 +311,15 @@ SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me, //============================================================================ void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me) { - SALOMEDS::SObject_var theReferencedObject; - if(!me->ReferencedObject(theReferencedObject)) return; //No reference is found - + SALOMEDS::Locker lock; CheckLocked(); - TDF_Label Lab; ASSERT(!CORBA::is_nil(me)); - CORBA::String_var meid = me->GetID(); - TDF_Tool::Label(_doc->GetData(),meid,Lab); - - Lab.ForgetAttribute(TDF_Reference::GetID()); - - //SRN: 30 Aug, 2004 : fix from Ecole l'ete version - - TDF_Label RefLab; - ASSERT(!CORBA::is_nil(theReferencedObject)); - CORBA::String_var roid = theReferencedObject->GetID(); - TDF_Tool::Label(_doc->GetData(),roid,RefLab); - - Handle(SALOMEDS_TargetAttribute) aTarget; - if(RefLab.FindAttribute(SALOMEDS_TargetAttribute::GetID(), aTarget)) aTarget->Remove(Lab); + CORBA::String_var anID = me->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->RemoveReference(aSO); } - //============================================================================ /*! Function : AddDirectory * Purpose : adds a new directory with a path = thePath @@ -703,63 +327,15 @@ void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me) //============================================================================ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath) { + SALOMEDS::Locker lock; CheckLocked(); if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory(); - - TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath; - TDF_ChildIterator anIterator(_doc->Main()); - Handle(TDataStd_Name) aName; - TDF_Label aLabel; - SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb); - SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(so_servant->_this()); - SALOMEDS::Study_var aStudy = anObject->GetStudy(); - - try { - anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists - } - catch(...) { } - - if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed(); - - if(aPath.Value(1) != '/') { //Relative path - aPath.Prepend('/'); - aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath; - } - - TCollection_AsciiString aToken = aPath.Token("/", 1); - if(aToken.Length() == 0) aFatherPath = "/"; - - int i = 1; - while(aToken.Length() != 0) { - if(aPath.Token("/", i+1).Length() > 0) { - aFatherPath += "/"; - aFatherPath += aToken; - } - aToken = aPath.Token("/", ++i); - } - - anObject = SALOMEDS::SObject::_nil(); - try { - anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists - } - catch(...) { ; } - if(anObject->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory(); - - SALOMEDS::SObject_var aNewObject = NewObject(anObject); - TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel); - if(aLabel.IsNull()) { - MESSAGE("### NULL label"); - throw SALOMEDS::Study::StudyInvalidComponent(); + if(!_impl->AddDirectory(std::string(thePath))) { + std::string anErrorCode = _impl->GetErrorCode(); + if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed(); + if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory(); + if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent(); } - - TDataStd_Name::Set(aLabel, aPath.Token("/", i-1)); - - //Set LocalID attribute to identify the directory object - SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID"); - SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr); - if(aPersRef->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory(); - - aPersRef->SetValue(DIRECTORYID); } @@ -770,12 +346,12 @@ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath) //============================================================================ void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID) { + SALOMEDS::Locker lock; CheckLocked(); - TDF_Label aLabel; ASSERT(!CORBA::is_nil(anObject)); - CORBA::String_var anEntry = anObject->GetID(); - TDF_Tool::Label(_doc->GetData(), anEntry, aLabel); - TDataStd_UAttribute::Set(aLabel, (char*)theGUID); + CORBA::String_var anID=anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->SetGUID(aSO, std::string(theGUID)); } //============================================================================ @@ -785,11 +361,11 @@ void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char //============================================================================ bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID) { - TDF_Label aLabel; + SALOMEDS::Locker lock; ASSERT(!CORBA::is_nil(anObject)); - CORBA::String_var anEntry = anObject->GetID(); - TDF_Tool::Label(_doc->GetData(), anEntry, aLabel); - return aLabel.IsAttribute((char*)theGUID); + CORBA::String_var anID=anObject->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + return _impl->IsGUID(aSO, std::string(theGUID)); } @@ -800,15 +376,8 @@ bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* //============================================================================ void SALOMEDS_StudyBuilder_i::NewCommand() { - // mpv: for SAL2114 - unset "lock changed" flag at the operation start - Handle(SALOMEDS_StudyPropertiesAttribute) anAttr; - if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) { - anAttr = new SALOMEDS_StudyPropertiesAttribute; - _doc->Main().AddAttribute(anAttr); - } - anAttr->IsLockChanged(true); - - _doc->NewCommand(); + SALOMEDS::Locker lock; + _impl->NewCommand(); } //============================================================================ @@ -818,23 +387,14 @@ void SALOMEDS_StudyBuilder_i::NewCommand() //============================================================================ void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); - Handle(SALOMEDS_StudyPropertiesAttribute) anAttr; - if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) { - anAttr = new SALOMEDS_StudyPropertiesAttribute; - _doc->Main().AddAttribute(anAttr); + try { + _impl->CommitCommand(); } - if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) { + catch(...) { MESSAGE("Locked document modification !!!"); - AbortCommand(); throw SALOMEDS::StudyBuilder::LockProtection(); - } else { - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->RemovePostponed(_doc->GetUndoLimit()); - - int aModif = anAttr->GetModified(); - if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero - anAttr->SetModified(aModif+1); - _doc->CommitCommand(); } } @@ -845,7 +405,8 @@ void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::Loc //============================================================================ CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand() { - return _doc->HasOpenCommand(); + SALOMEDS::Locker lock; + return _impl->HasOpenCommand(); } //============================================================================ @@ -855,9 +416,8 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand() //============================================================================ void SALOMEDS_StudyBuilder_i::AbortCommand() { - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(0); - - _doc->AbortCommand(); + SALOMEDS::Locker lock; + _impl->AbortCommand(); } //============================================================================ @@ -867,19 +427,14 @@ void SALOMEDS_StudyBuilder_i::AbortCommand() //============================================================================ void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); - Handle(SALOMEDS_StudyPropertiesAttribute) anAttr; - if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) { - anAttr = new SALOMEDS_StudyPropertiesAttribute; - _doc->Main().AddAttribute(anAttr); - } - if (anAttr->IsLocked()) { + try { + _impl->Undo(); + } + catch(...) { MESSAGE("Locked document modification !!!"); throw SALOMEDS::StudyBuilder::LockProtection(); - } else { - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(1); - _doc->Undo(); - anAttr->SetModified(anAttr->GetModified()-1); } } @@ -890,22 +445,16 @@ void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtecti //============================================================================ void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); - Handle(SALOMEDS_StudyPropertiesAttribute) anAttr; - if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) { - anAttr = new SALOMEDS_StudyPropertiesAttribute; - _doc->Main().AddAttribute(anAttr); + try { + _impl->Redo(); } - - if (anAttr->IsLocked()) { + catch(...) { MESSAGE("Locked document modification !!!"); throw SALOMEDS::StudyBuilder::LockProtection(); - } else { - _doc->Redo(); - SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(-1); - anAttr->SetModified(anAttr->GetModified()+1); } - } +} //============================================================================ /*! Function : GetAvailableUndos @@ -914,7 +463,8 @@ void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtecti //============================================================================ CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos() { - return _doc->GetAvailableUndos(); + SALOMEDS::Locker lock; + return _impl->GetAvailableUndos(); } //============================================================================ @@ -924,7 +474,8 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos() //============================================================================ CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos() { - return _doc->GetAvailableRedos(); + SALOMEDS::Locker lock; + return _impl->GetAvailableRedos(); } //============================================================================ @@ -934,7 +485,8 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos() //============================================================================ CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit() { - return _doc->GetUndoLimit(); + SALOMEDS::Locker lock; + return _impl->UndoLimit(); } //============================================================================ @@ -944,32 +496,9 @@ CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit() //============================================================================ void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n) { + SALOMEDS::Locker lock; CheckLocked(); - _doc->SetUndoLimit (n); -} - -//============================================================================ -/*! Function : SetOnAddSObject - * Purpose : - */ -//============================================================================ -SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback) -{ - SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnAdd))?NULL:_callbackOnAdd._retn(); - _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback); - return aRet; -} - -//============================================================================ -/*! Function : SetOnNewSObject - * Purpose : - */ -//============================================================================ -SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback) -{ - SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnRemove))?NULL:_callbackOnRemove._retn(); - _callbackOnRemove = SALOMEDS::Callback::_duplicate(theCallback); - return aRet; + _impl->UndoLimit(n); } //============================================================================ @@ -977,15 +506,16 @@ SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Cal * Purpose : */ //============================================================================ -void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) { +void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) +{ + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); - if (_doc->HasOpenCommand()) return; - Handle(SALOMEDS_StudyPropertiesAttribute) anAttr; - if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) { - anAttr = new SALOMEDS_StudyPropertiesAttribute; - _doc->Main().AddAttribute(anAttr); - } - if (anAttr->IsLocked()) throw SALOMEDS::StudyBuilder::LockProtection(); + try { + _impl->CheckLocked(); + } + catch(...) { + throw SALOMEDS::StudyBuilder::LockProtection(); + } } //============================================================================ @@ -996,14 +526,13 @@ void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockP void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue) throw(SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); CheckLocked(); - //Find label - TDF_Label aLabel; - ASSERT(!CORBA::is_nil(theSO)); - CORBA::String_var aSOID = theSO->GetID(); - TDF_Tool::Label(_doc->GetData(), aSOID, aLabel); - TDataStd_Name::Set(aLabel, (char*)theValue); + + CORBA::String_var anID=theSO->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->SetName(aSO, std::string(theValue)); } //============================================================================ @@ -1012,16 +541,15 @@ void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* t */ //============================================================================ void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue) - throw(SALOMEDS::StudyBuilder::LockProtection) + throw(SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); CheckLocked(); - //Find label - TDF_Label aLabel; - ASSERT(!CORBA::is_nil(theSO)); - CORBA::String_var aSOID = theSO->GetID(); - TDF_Tool::Label(_doc->GetData(), aSOID, aLabel); - TDataStd_Comment::Set(aLabel, (char*)theValue); + + CORBA::String_var anID=theSO->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->SetComment(aSO, std::string(theValue)); } //============================================================================ @@ -1032,12 +560,11 @@ void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue) throw(SALOMEDS::StudyBuilder::LockProtection) { + SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); CheckLocked(); - //Find label - TDF_Label aLabel; - ASSERT(!CORBA::is_nil(theSO)); - CORBA::String_var aSOID = theSO->GetID(); - TDF_Tool::Label(_doc->GetData(), aSOID, aLabel); - SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue), _orb); + + CORBA::String_var anID=theSO->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in()); + _impl->SetIOR(aSO, std::string(theValue)); }