+
+//============================================================================
+/*! Function : AddPostponed
+ * Purpose :
+ */
+ //============================================================================
+void SALOMEDS_Study_i::AddPostponed(const char* theIOR) {
+ if (!GetBuilder()->HasOpenCommand()) return;
+ try {
+ CORBA::Object_var obj = GetORB()->string_to_object(theIOR);
+ if (!CORBA::is_nil(obj)) {
+ SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
+ if (!CORBA::is_nil(aGeneric)) {
+ TCollection_AsciiString anIOR(const_cast<char*>(theIOR));
+ anIOR.Prepend("d");
+ myPostponedIORs.Append(anIOR); // add prefix: deleted
+ myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
+ }
+ }
+ } catch(...) {}
+}
+
+void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) {
+ if (!GetBuilder()->HasOpenCommand()) return;
+ try {
+ CORBA::Object_var obj = GetORB()->string_to_object(theIOR);
+ if (!CORBA::is_nil(obj)) {
+ SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
+ if (!CORBA::is_nil(aGeneric)) {
+ TCollection_AsciiString anIOR(const_cast<char*>(theIOR));
+ anIOR.Prepend("c");
+ myPostponedIORs.Append(anIOR); // add prefix: created
+ myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1);
+ }
+ }
+ } catch(...) {}
+}
+
+//============================================================================
+/*! Function : RemovePostponed
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) {
+ int anIndex;
+ int anOld;
+
+ int aUndoLimit = theUndoLimit;
+ if (theUndoLimit < 0) aUndoLimit = 0;
+
+ const CORBA::ORB_var& anORB = GetORB();
+ if (myNbUndos > 0) { // remove undone
+ anOld = 0;
+ for(anIndex = 1; anIndex < myNbPostponed.Length() - myNbUndos; anIndex++)
+ anOld += myNbPostponed(anIndex);
+ int aNew = myPostponedIORs.Length() - myNbPostponed.Last();
+
+ for(anIndex = anOld + 1; anIndex <= aNew; anIndex++) {
+ TCollection_AsciiString anIOR = myPostponedIORs(anIndex);
+ if (anIOR.Value(1) == 'c') {
+ CORBA::Object_var obj = anORB->string_to_object(anIOR.Split(1).ToCString());
+ SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
+ if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
+ }
+ }
+ if (anOld < aNew) myPostponedIORs.Remove(anOld + 1, aNew);
+ if (myNbPostponed.Length() > 0) myNbPostponed.Remove(myNbPostponed.Length() - myNbUndos, myNbPostponed.Length() - 1);
+
+ myNbUndos = 0;
+ }
+
+ if (myNbPostponed.Length() > aUndoLimit) { // remove objects, that can not be undone
+ anOld = 0;
+ for(anIndex = myNbPostponed.Length() - aUndoLimit; anIndex >= 1; anIndex--)
+ anOld += myNbPostponed(anIndex);
+ for(anIndex = 1; anIndex <= anOld; anIndex++) {
+ TCollection_AsciiString anIOR = myPostponedIORs(anIndex);
+ if (anIOR.Value(1) == 'd') {
+ CORBA::Object_var obj = anORB->string_to_object(anIOR.Split(1).ToCString());
+ SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
+ if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
+ }
+ }
+ if (anOld > 0) myPostponedIORs.Remove(1, anOld);
+ myNbPostponed.Remove(1, myNbPostponed.Length() - aUndoLimit);
+ }
+
+ if (theUndoLimit == -1) { // remove all IORs from the study on the study close
+ TDF_ChildIDIterator anIter(_doc->GetData()->Root(), SALOMEDS_IORAttribute::GetID(), Standard_True);
+ for(; anIter.More(); anIter.Next()) {
+ Handle(SALOMEDS_IORAttribute) anAttr = Handle(SALOMEDS_IORAttribute)::DownCast(anIter.Value());
+ CORBA::String_var anIOR = CORBA::string_dup(TCollection_AsciiString(anAttr->Get()).ToCString());
+ try {
+ CORBA::Object_var obj = anORB->string_to_object(anIOR);
+ SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
+ if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
+ } catch (...) {}
+ }
+ } else myNbPostponed.Append(0);
+}
+
+//============================================================================
+/*! Function : UndoPostponed
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) {
+ myNbUndos += theWay;
+ // remove current postponed
+ if (myNbPostponed.Last() > 0)
+ myPostponedIORs.Remove(myPostponedIORs.Length() - myNbPostponed.Last() + 1, myPostponedIORs.Length());
+ myNbPostponed(myNbPostponed.Length()) = 0;
+}