//! Exception indicating that this feature hasn't been implemented in %SALOME application.
exception NotImplemented {};
+//! Enumeration that describes modifications of the %Study
+ enum DeltaType { DT_NONE, DT_ADDED, DT_REMOVED, DT_MODIFIED };
+
+//! Structure that describes a atomic delta on modification of the %Study
+ struct StudyDelta {
+ string m_father;
+ string m_entry;
+ DeltaType m_type;
+ };
+
+//! A sequence of modification deltas
+ typedef sequence<StudyDelta> ListOfDeltas;
//===========================================================================
/*! \brief %Study Interface
*/
ListOfStrings GetLockerID();
+/*! \brief Enable or disable logging of modifications in this Study
+ \param isLogged is a Boolean flag that tells whether modification of the Study is logged.
+*/
+ void SetIsDeltaLogged(in boolean isLogged);
+
+/*! \brief Returns a list of modification deltas of this Study. Each call of GetLoggedDeltas clears
+ modification deltas stored in this Study.
+*/
+ ListOfDeltas GetLoggedDeltas();
+
/*! \brief Create real variable with Name theVarName and value theValue
(or set if variable value into theValue already exists)
std::vector<std::string> SALOMEDS_Study::GetObjectNames(const std::string& theContext)
{
- std::vector<std::string> aVector;
+
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetObjectNames(theContext);
- }
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
- aLength = aSeq->length();
- for (i = 0; i < aLength; i++) aVector.push_back(std::string((std::string)aSeq[i].in()));
+ return _local_impl->GetObjectNames(theContext);
}
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+ for (i = 0; i < aLength; i++) aVector[i] = std::string((std::string)aSeq[i].in());
return aVector;
}
std::vector<std::string> SALOMEDS_Study::GetDirectoryNames(const std::string& theContext)
{
- std::vector<std::string> aVector;
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetDirectoryNames(theContext);
- }
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
- aLength = aSeq->length();
- for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
+ return _local_impl->GetDirectoryNames(theContext);
}
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+ for (i = 0; i < aLength; i++) aVector[i] = (char*)aSeq[i].in();
+
return aVector;
}
std::vector<std::string> SALOMEDS_Study::GetFileNames(const std::string& theContext)
{
- std::vector<std::string> aVector;
+
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetFileNames(theContext);
+ return _local_impl->GetFileNames(theContext);
}
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
- aLength = aSeq->length();
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+
+ for (i = 0; i < aLength; i++) aVector[i] = (char*)aSeq[i].in();
- for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
- }
return aVector;
}
std::vector<std::string> SALOMEDS_Study::GetComponentNames(const std::string& theContext)
{
- std::vector<std::string> aVector;
+
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetComponentNames(theContext);
- }
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
- aLength = aSeq->length();
- for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
+ return _local_impl->GetComponentNames(theContext);
}
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+
+ for (i = 0; i < aLength; i++) aVector[i] = (char*)aSeq[i].in();
+
return aVector;
}
std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
{
- std::vector<std::string> aVector;
+
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetModificationsDate();
- }
- else {
- SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
- aLength = aSeq->length();
- for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
+ return _local_impl->GetModificationsDate();
}
+
+ SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+
+ for (i = 0; i < aLength; i++) aVector[i] = (char*)aSeq[i].in();
+
return aVector;
}
vector<string> SALOMEDS_Study::GetLockerID()
{
- std::vector<std::string> aVector;
int aLength, i;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetLockerID();
- }
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
- aLength = aSeq->length();
- for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
+ return _local_impl->GetLockerID();
}
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
+ aLength = aSeq->length();
+ std::vector<std::string> aVector(aLength);
+ for (i = 0; i < aLength; i++) aVector[i] = (char*)aSeq[i].in();
+
return aVector;
}
+void SALOMEDS_Study::SetIsDeltaLogged(bool isLogged)
+{
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ _local_impl->SetIsDeltaLogged(isLogged);
+ }
+ else _corba_impl->SetIsDeltaLogged(isLogged);
+}
+
+std::vector< StudyDelta > SALOMEDS_Study::GetLoggedDeltas()
+{
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ return _local_impl->GetLoggedDeltas();
+ }
+
+ SALOMEDS::ListOfDeltas_var aSeq = _corba_impl->GetLoggedDeltas();
+ int aLength = aSeq->length();
+ std::vector< StudyDelta > aVector(aLength);
+ for(int i = 0; i<aLength; i++) {
+
+ const SALOMEDS::StudyDelta& aDelta = aSeq[i];
+ aVector[i] = StudyDelta(aDelta.m_father.in(), aDelta.m_entry.in(), (DeltaOperationType)aDelta.m_type);
+
+ }
+
+ return aVector;
+}
void SALOMEDS_Study::SetReal(const string& theVarName, const double theValue)
{
vector<string> SALOMEDS_Study::GetVariableNames()
{
- vector<string> aVector;
if (_isLocal) {
SALOMEDS::Locker lock;
- aVector = _local_impl->GetVariableNames();
- }
- else {
- SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
- int aLength = aSeq->length();
- for (int i = 0; i < aLength; i++)
- aVector.push_back( string(aSeq[i].in()) );
+ return _local_impl->GetVariableNames();
}
+
+ SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
+ int aLength = aSeq->length();
+ vector<string> aVector(aLength);
+ for (int i = 0; i < aLength; i++)
+ aVector[i] = string(aSeq[i].in());
+
return aVector;
}
vector< vector<string> > SALOMEDS_Study::ParseVariables(const string& theVars)
{
- vector< vector<string> > aResult;
if (_isLocal) {
SALOMEDS::Locker lock;
- aResult = _local_impl->ParseVariables(theVars);
+ return _local_impl->ParseVariables(theVars);
}
- else {
- SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
- for (int i = 0, n = aSeq->length(); i < n; i++) {
- vector<string> aVector;
- SALOMEDS::ListOfStrings aSection = aSeq[i];
- for (int j = 0, m = aSection.length(); j < m; j++) {
- aVector.push_back( string(aSection[j].in()) );
- }
- aResult.push_back( aVector );
+
+ SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
+ vector< vector<string> > aResult(aSeq->length());
+ for (int i = 0, n = aSeq->length(); i < n; i++) {
+
+ SALOMEDS::ListOfStrings aSection = aSeq[i];
+ vector<string> aVector(aSection.length());
+
+ for (int j = 0, m = aSection.length(); j < m; j++) {
+ aVector[j] = string(aSection[j].in());
}
+ aResult[i] = aVector;
}
+
return aResult;
}
virtual void UnLockStudy(const std::string& theLockerID);
virtual std::vector<std::string> GetLockerID();
+ virtual void SetIsDeltaLogged(bool isLogged);
+ virtual std::vector< StudyDelta > GetLoggedDeltas();
+
virtual void SetReal(const std::string& theVarName, const double theValue);
virtual void SetInteger(const std::string& theVarName, const int theValue);
virtual void SetBoolean(const std::string& theVarName, const bool theValue);
}
return aResult._retn();
}
+
+//============================================================================
+/*! Function : SetIsDeltaLogged
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetIsDeltaLogged(CORBA::Boolean isLogged)
+{
+ if(isLogged) _impl->SetIsDeltaLogged(true);
+ else _impl->SetIsDeltaLogged(false);
+}
+
+//============================================================================
+/*! Function : GetLoggedDeltas
+ * Purpose :
+ */
+//============================================================================
+SALOMEDS::ListOfDeltas* SALOMEDS_Study_i::GetLoggedDeltas()
+{
+ const vector< StudyDelta >& aList = _impl->GetLoggedDeltas();
+ SALOMEDS::ListOfDeltas_var aDeltas = new SALOMEDS::ListOfDeltas();
+
+ aDeltas->length(aList.size());
+ for(size_t i = 0, aSize = aList.size(); i<aSize; i++) {
+ const StudyDelta& aD = aList[i];
+
+ SALOMEDS::StudyDelta aDelta;
+ aDelta.m_father = CORBA::string_dup(aD.m_father.c_str());
+ aDelta.m_entry = CORBA::string_dup(aD.m_entry.c_str());
+ aDelta.m_type = (SALOMEDS::DeltaType)aD.m_type;
+
+ aDeltas[i] = aDelta;
+ }
+
+ return aDeltas._retn();
+}
+
//============================================================================
/*! Function : SetReal
* Purpose :
virtual SALOMEDS::ListOfStrings* GetLockerID();
+ virtual void SetIsDeltaLogged(CORBA::Boolean isLogged);
+
+ virtual SALOMEDS::ListOfDeltas* GetLoggedDeltas();
+
virtual void SetReal(const char* theVarName, CORBA::Double theValue);
virtual void SetInteger(const char* theVarName, CORBA::Long theValue);
virtual void UnLockStudy(const std::string& theLockerID) = 0;
virtual std::vector<std::string> GetLockerID() = 0;
+ virtual void SetIsDeltaLogged(bool isLogged) = 0;
+ virtual std::vector< StudyDelta > GetLoggedDeltas() = 0;
+
virtual void SetReal(const std::string& theVarName, const double theValue) = 0;
virtual void SetInteger(const std::string& theVarName, const int theValue) = 0;
virtual void SetBoolean(const std::string& theVarName, const bool theValue) = 0;
double B;
};
+enum DeltaOperationType { DOT_NONE, DOT_SO_ADDED, DOT_SO_REMOVED, DOT_MODIFIED };
+
+#include <string>
+
+struct StudyDelta {
+ StudyDelta() { m_father = ""; m_entry = ""; m_type = DOT_NONE; }
+ StudyDelta(const std::string& theFather,
+ const std::string& theEntry,
+ DeltaOperationType theOperation)
+ {
+ m_father = theFather;
+ m_entry = theEntry;
+ m_type = theOperation;
+ }
+
+ std::string m_father; //Entry of a father SObject
+ std::string m_entry; //Entry of modified SObject
+ DeltaOperationType m_type; //What operation is performed
+};
+
+
#endif
-I$(srcdir)/../HDFPersist \
-I$(srcdir)/../DF \
-I$(srcdir)/../GenericObj \
+ -I$(srcdir)/../SALOMEDSClient \
-I$(top_builddir)/idl \
@HDF5_INCLUDES@ \
@BOOST_CPPFLAGS@ @CORBA_CXXFLAGS@ @CORBA_INCLUDES@
SALOMEDSImpl_Study* aStudy = SALOMEDSImpl_Study::GetStudy(aLabel);
if(aStudy) aStudy->Modify();
+ else return;
+
+ if(aStudy->IsDeltaLogged()) { //It's necessary to store in the Study about attributes' modifications
+ aStudy->AddDelta(DF_Label(), aLabel, DOT_MODIFIED);
+ }
}
return aStr;
}
-
+//============================================================================
+/*! Function : GetGUID
+ * Purpose :
+ */
+//============================================================================
std::string SALOMEDSImpl_SObject::GetGUID(const string& theType)
{
__AttributeTypeToGUIDForSObject
return "";
}
+//============================================================================
+/*! Function : OnAddition
+ * Purpose : The method is called after when this SObject is added to the Study
+ */
+//============================================================================
+void SALOMEDSImpl_SObject::OnAddition() const
+{
+ if(_lab.IsNull()) return;
+
+ SALOMEDSImpl_Study* aStudy = GetStudy();
+ if(!aStudy || !aStudy->IsDeltaLogged()) return;
+
+ DF_Label aFather;
+ if(!IsComponent()) aFather = _lab.Father();
+
+ aStudy->AddDelta(aFather, _lab, DOT_SO_ADDED);
+}
+
+//============================================================================
+/*! Function : OnRemove
+ * Purpose : The method is called before when this SObject is removed from the Study
+ */
+//============================================================================
+void SALOMEDSImpl_SObject::OnRemove() const
+{
+ if(_lab.IsNull()) return;
+
+ SALOMEDSImpl_Study* aStudy = GetStudy();
+ if(!aStudy || !aStudy->IsDeltaLogged()) return;
+
+ DF_Label aFather;
+ if(!IsComponent()) aFather = _lab.Father();
+
+ aStudy->AddDelta(aFather, _lab, DOT_SO_REMOVED);
+}
+
//============================================================================
/*! Function : SALOMEDSImpl_SComponent
* Purpose :
virtual DF_Label GetLabel() const { return _lab; }
+ virtual void OnAddition() const;
+ virtual void OnRemove() const;
+
bool IsNull() const { return _lab.IsNull(); }
bool IsComponent() const;
_useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
_builder = new SALOMEDSImpl_StudyBuilder(this);
_cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
+ _isDelta = false;
//Put on the root label a StudyHandle attribute to store the address of this object
//It will be used to retrieve the study object by DF_Label that belongs to the study
SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
return anIORs;
}
+
+//============================================================================
+/*! Function : IsDeltaLogged
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsDeltaLogged() const
+{
+ return _isDelta;
+}
+
+//============================================================================
+/*! Function : GetLoggedDeltas
+ * Purpose :
+ */
+//============================================================================
+vector< StudyDelta > SALOMEDSImpl_Study::GetLoggedDeltas()
+{
+ vector< StudyDelta > aDeltas(_deltas.size());
+
+ map<string, StudyDelta>::const_iterator p = _deltas.begin();
+
+ for(size_t i = 0; p != _deltas.end(); i++, p++) {
+ aDeltas[i] = p->second;
+ }
+
+ _deltas.clear();
+
+ return aDeltas;
+}
+
+
+//============================================================================
+/*! Function : AddDelta
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::AddDelta(const DF_Label& theFather,
+ const DF_Label& theObject,
+ DeltaOperationType theOperation)
+{
+ if(theObject.IsNull()) return;
+ const string& entry = theObject.Entry();
+
+ if(_deltas.find(entry) != _deltas.end()) { //Check whether the object was already modified in any way
+ StudyDelta& aDelta = _deltas[entry];
+
+ switch(aDelta.m_type) {
+ case DOT_SO_ADDED: {
+ switch(theOperation) {
+ case DOT_SO_REMOVED: { _deltas.erase(_deltas.find(entry)); } //Remove delta as the object which has been added is removed
+ default:
+ return;
+ }
+ break;
+ }
+ case DOT_SO_REMOVED: {
+ switch(theOperation) {
+ case DOT_SO_ADDED: { //The previously removed is again added, modify the delta to MODIFIED
+ aDelta.m_type = DOT_MODIFIED;
+ aDelta.m_father = "";
+ }
+ default:
+ return;
+ }
+ break;
+ }
+ case DOT_MODIFIED: {
+ switch(theOperation) {
+ case DOT_SO_REMOVED: { //The previously modified object is removed, keep only the removal delta
+ aDelta.m_type = DOT_SO_REMOVED;
+ aDelta.m_father = theObject.Father().Entry();
+ }
+ default:
+ return;
+ }
+ break;
+ }
+ default: return;
+ }
+ }
+ else {
+ _deltas[entry] = StudyDelta(theFather.Entry(), theObject.Entry(), theOperation);
+ }
+}
#include "DF_Label.hxx"
#include <stdio.h>
+//SALOMEDSClient headers
+#include "SALOMEDSClient_definitions.hxx"
+
//SALOMEDSImpl headers
#include "SALOMEDSImpl_Defines.hxx"
#include "SALOMEDSImpl_SComponentIterator.hxx"
class SALOMEDSImpl_StudyManager;
class SALOMEDSImpl_GenericAttribute;
-
class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study
{
private:
SALOMEDSImpl_Callback* _cb;
SALOMEDSImpl_StudyBuilder* _builder;
SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
+ bool _isDelta;
+ std::map<std::string, StudyDelta> _deltas;
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
//Returns a callback
SALOMEDSImpl_Callback* GetCallback() { return _cb; }
+ //Enables logging of modifications in SALOME data structure.
+ //Default value is 'false'
+ void SetIsDeltaLogged(bool isLogged) { _isDelta = isLogged; }
+
+ //Returns true if the study stores a list of modifications related to the SObjects and Attributes
+ bool IsDeltaLogged() const;
+
+ //Returns a list of deltas on modifications that happend after the last request of deltas
+ //Note: The request for deltas clears all stored information, so only returned list will contain
+ // information about modifications
+ std::vector< StudyDelta > GetLoggedDeltas();
+
//Returns a list of IOR's stored in the study
std::vector<std::string> GetIORs();
+protected:
+
+ //Adds a new Delta to the list of modifications
+ void AddDelta(const DF_Label& theFather, const DF_Label& theObject, DeltaOperationType theOperation);
+
friend class SALOMEDSImpl_StudyManager;
friend class SALOMEDSImpl_GenericAttribute;
friend class SALOMEDSImpl_GenericVariable;
+ friend class SALOMEDSImpl_SObject;
};
#endif
DF_Label NL = L.NewChild();
- SALOMEDSImpl_AttributeComment::Set(NL, DataType);
-
SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
+ so.OnAddition();
+
+ SALOMEDSImpl_AttributeComment::Set(NL, DataType);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
DF_Label NewLab = Lab.NewChild();
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
+ so.OnAddition();
+
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
_doc->SetModified(true);
DF_Label NewLab = Lab.FindChild(theTag, 1);
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
+ so.OnAddition();
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
_errorCode = "Null object";
return false;
}
-
+
+ anObject.OnRemove();
if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
DF_Label Lab = anObject.GetLabel();
return false;
}
+ anObject.OnRemove();
if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
DF_Label Lab = anObject.GetLabel();
DF_ChildIterator it(Lab, true);
for(;it.More();it.Next()) {
DF_Label aLabel = it.Value();
+
+ SALOMEDSImpl_SObject so(aLabel);
+ so.OnRemove();
+
if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
SALOMEDSImpl_AttributeTarget* aTarget = NULL;
if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
-I$(srcdir)/$(RPATH)/ResourcesManager \
-I$(srcdir)/$(RPATH)/LifeCycleCORBA \
-I$(srcdir)/$(RPATH)/DF \
+ -I$(srcdir)/$(RPATH)/SALOMEDSClient \
-I$(srcdir)/$(RPATH)/SALOMEDSImpl \
-I$(top_builddir)/idl \
@CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @BOOST_CPPFLAGS@