#include "SALOMEDS_SObject_i.hxx"
#include "SALOMEDS_SComponent_i.hxx"
+#include "SALOMEDS_ChildIterator_i.hxx"
#include "SALOMEDS_TargetAttribute.hxx"
#include "SALOMEDS_IORAttribute.hxx"
TDataStd_Comment::Set(NL,Standard_CString(DataType));
// TDataStd_Comment::Set(NL,Standard_CString(CORBA::string_dup(DataType)));
- SALOMEDS_SComponent_i* aServant = SALOMEDS_SComponent_i::New(_study,NL);
- SALOMEDS::SComponent_var aSComponent = aServant->_this();
+ SALOMEDS::SComponent_var aSComponent = SALOMEDS_SComponent_i::NewRef(_study,NL);
OnAddSObject(aSComponent);
//add theObject definition
aString = GetORB()->object_to_string(theObject);
- SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),GetORB());
+ SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),_study);
}
//============================================================================
imax++;
TDF_Label aNewLabel = aLabel.FindChild(imax);
- SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,aNewLabel);
- SALOMEDS::SObject_var aSObject = aServant->_this();
+ SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLabel);
OnAddSObject(aSObject);
//Create or find label
TDF_Label aNewLab = Lab.FindChild(theTag,1);
- SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,aNewLab);
- SALOMEDS::SObject_var aSObject = aServant->_this();
+ SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLab);
OnAddSObject(aSObject);
//============================================================================
void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr theSObject)
{
- CheckLocked();
-
- if(CORBA::is_nil(theSObject))
- return;
-
- OnRemoveSObject(theSObject);
-
- TDF_Label Lab;
- CORBA::String_var aString(theSObject->GetID());
- TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
+ RemoveSObject(theSObject);
+}
- 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);
- }
+SALOMEDS_SObject_i*
+SALOMEDS_StudyBuilder_i::RemoveSObject(SALOMEDS::SObject_ptr theSObject,
+ bool theIsForgetAllAttributes)
+{
+ CheckLocked();
- Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
- if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)){
- SALOMEDS::Study_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
- aStudy->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+ if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theSObject)){
+ OnRemoveSObject(theSObject);
+ aSObject->OnRemove();
+ if(theIsForgetAllAttributes){
+ TDF_Label aLabel = aSObject->GetLabel();
+ aLabel.ForgetAllAttributes();
+ }
+ return aSObject;
}
- Lab.ForgetAllAttributes();
+ return NULL;
}
//============================================================================
//============================================================================
void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr theSObject)
{
- CheckLocked();
-
- if(CORBA::is_nil(theSObject))
- return;
-
- OnRemoveSObject(theSObject);
-
- TDF_Label Lab;
- CORBA::String_var aString(theSObject->GetID());
- TDF_Tool::Label(_doc->GetData(),aString,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_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
- aStudy->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_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
- aStudy->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+ if(SALOMEDS_SObject_i* aSObject = RemoveSObject(theSObject,false)){
+ SALOMEDS_ChildIterator_i aChildIter(_study,aSObject->GetLabel(),true);
+ for(; aChildIter.More(); aChildIter.Next()){
+ if(SALOMEDS_SObject_i* aSObj = aChildIter.GetValue())
+ aSObj->OnRemove();
}
+ TDF_Label aLabel = aSObject->GetLabel();
+ aLabel.ForgetAllAttributes(Standard_True);
}
-
- Lab.ForgetAllAttributes(Standard_True);
}
//============================================================================
//============================================================================
static void Translate_persistentID_to_IOR(TDF_Label theLabel,
SALOMEDS::Driver_ptr theDriver,
- CORBA::ORB_ptr theORB,
SALOMEDS_Study_i* theStudy,
CORBA::Boolean theIsMultiFile,
CORBA::Boolean theIsASCII)
TCollection_ExtendedString res = Handle(TDataStd_Comment)::DownCast(anAttr)->Get();
TCollection_AsciiString ch(res);
- SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(theStudy,aCurrentLabel);
- SALOMEDS::SObject_var aSObject = aServant->_this();
+ SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(theStudy,aCurrentLabel);
CORBA::String_var anIOR =
theDriver->LocalPersistentIDToIOR(aSObject,ch.ToCString(),theIsMultiFile,theIsASCII);
- SALOMEDS_IORAttribute::Set (aCurrentLabel,const_cast<char*>(anIOR.in()),theORB);
+ SALOMEDS_IORAttribute::Set(aCurrentLabel,const_cast<char*>(anIOR.in()),theStudy);
}
- Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theORB,theStudy,theIsMultiFile,theIsASCII);
+ Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theStudy,theIsMultiFile,theIsASCII);
}
}
if(CORBA::is_nil(theDriver))
return;
- int aLocked = theSComponent->GetStudy()->GetProperties()->IsLocked();
+ int aLocked = _study->GetProperties()->IsLocked();
if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(false);
+ _study->GetProperties()->SetLocked(false);
// 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)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+ _study->GetProperties()->SetLocked(true);
return;
}
DefineComponentInstance (theSComponent,theDriver);
// set path without file name from URL
std::string aDir(aHDFPath.ToCString());
- aDir.substr(0,aDir.find('/'));
+ aDir = aDir.substr(0,aDir.rfind('/') + 1);
CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
theDriver->LoadASCII(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M'):
SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
}
if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+ _study->GetProperties()->SetLocked(true);
THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM);
}
try {
- Translate_persistentID_to_IOR(Lab,theDriver,GetORB(),_study, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
+ Translate_persistentID_to_IOR(Lab,theDriver,_study,aMultifileState[0]=='M',ASCIIfileState[0] == 'A');
} catch (SALOME::SALOME_Exception) {
INFOS("Can't translate PersRef to IOR");
if (aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+ _study->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)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+ _study->GetProperties()->SetLocked(true);
} else
MESSAGE("No persistent file Name");
}
SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr theObject,
const char* theTypeOfAttribute)
{
- if(!CORBA::is_nil(theObject)){
- PortableServer::POA_var aPOA = GetPOA();
- PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theObject,aPOA);
- if(aServant.in() != NULL){
- if(SALOMEDS_SObject_i* anSObject = dynamic_cast<SALOMEDS_SObject_i*>(aServant.in())){
- return anSObject->FindOrCreateAttribute(theTypeOfAttribute);
- }
- }
- }
+ if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
+ return aSObject->FindOrCreateAttribute(theTypeOfAttribute);
+
return SALOMEDS::GenericAttribute::_nil();
}
SALOMEDS::GenericAttribute_out theAttr,
const char* theTypeOfAttribute)
{
- if(!CORBA::is_nil(theObject)){
- PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theObject,GetPOA());
- if(aServant.in() != NULL){
- if(SALOMEDS_SObject_i* anSObject = dynamic_cast<SALOMEDS_SObject_i*>(aServant.in())){
- return anSObject->FindAttribute(theAttr,theTypeOfAttribute);
- }
- }
- }
+ if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
+ return aSObject->FindAttribute(theAttr,theTypeOfAttribute);
+
return Standard_False;
}
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(),GetORB())->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
- else return;
+ _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+ else
+ return;
}
Lab.ForgetAttribute(SALOMEDS::GetGUID(aTypeOfAttribute));
TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
Handle(TDataStd_Name) aName;
TDF_Label aLabel;
- SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,_doc->Main());
- SALOMEDS::SObject_var anObject = aServant->_this();
- SALOMEDS::Study_var aStudy = anObject->GetStudy();
+ SALOMEDS::SObject_var anObject = SALOMEDS_SObject_i::NewRef(_study,_doc->Main());
try {
- anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
+ anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
}
catch(...) { }
if(aPath.Value(1) != '/') { //Relative path
aPath.Prepend('/');
- aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
+ aPath = TCollection_AsciiString(_study->GetContext()) + aPath;
}
TCollection_AsciiString aToken = aPath.Token("/", 1);
anObject = SALOMEDS::SObject::_nil();
try {
- anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
+ anObject = _study->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
}
catch(...) { ; }
if(anObject->_is_nil())
AbortCommand();
throw SALOMEDS::StudyBuilder::LockProtection();
} else {
- SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->RemovePostponed(_doc->GetUndoLimit());
+ _study->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
//============================================================================
void SALOMEDS_StudyBuilder_i::AbortCommand()
{
- SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(0);
+ _study->UndoPostponed(0);
_doc->AbortCommand();
}
MESSAGE("Locked document modification !!!");
throw SALOMEDS::StudyBuilder::LockProtection();
} else {
- SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(1);
+ _study->UndoPostponed(1);
_doc->Undo();
anAttr->SetModified(anAttr->GetModified()-1);
}
throw SALOMEDS::StudyBuilder::LockProtection();
} else {
_doc->Redo();
- SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(-1);
+ _study->UndoPostponed(-1);
anAttr->SetModified(anAttr->GetModified()+1);
}
}
TDF_Label aLabel;
CORBA::String_var aSOID = theSO->GetID();
TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
- SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),GetORB());
+ SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),_study);
}