{
for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
{
- if ( it->first->_is_equivalent(theObs) ) {
- myObservers.erase( it );
- break;
- }
+ if ( it->first->_is_equivalent(theObs) ) {
+ myObservers.erase( it );
+ break;
+ }
}
}
_orb = CORBA::ORB::_duplicate(orb);
_impl = new SALOMEDSImpl_Study();
_factory = new SALOMEDS_DriverFactory_i(_orb);
+ _closed = true;
Init();
}
//============================================================================
void SALOMEDS_Study_i::Init()
{
+ if ( !_impl->GetDocument() )
+ _impl->Init();
+
+ if (!_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
+
_builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
_notifier = new SALOMEDS::Notifier(_orb);
_genObjRegister = new SALOMEDS::GenObjRegister(_orb);
_impl->setNotifier(_notifier);
_impl->setGenObjRegister( _genObjRegister );
+ // update desktop title with new study name
+ NameChanged();
+
// Notify GUI that study was created
SALOME_NamingService *aNamingService = KERNEL::getNamingService();
CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
//============================================================================
void SALOMEDS_Study_i::Clear()
{
+ SALOMEDS::Locker lock;
+ if (_closed)
+ return;
//delete the builder servant
PortableServer::POA_var poa=_builder->_default_POA();
PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
poa->deactivate_object(anObjectId.in());
_builder->_remove_ref();
-
- _impl->Clear();
- _impl->setNotifier(0);
- delete _notifier;
- delete _genObjRegister;
-
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
RemovePostponed(-1);
- SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
- for (; itcomponent->More(); itcomponent->Next()) {
- SALOMEDS::SComponent_var sco = itcomponent->Value();
- CORBA::String_var compodatatype=sco->ComponentDataType();
- MESSAGE ( "Look for an engine for data type :"<< compodatatype);
- // if there is an associated Engine call its method for closing
- CORBA::String_var IOREngine;
- if (sco->ComponentIOR(IOREngine)) {
- // we have found the associated engine to write the data
- MESSAGE ( "We have found an engine for data type :"<< compodatatype);
- //_narrow can throw a corba exception
- try {
- CORBA::Object_var obj = _orb->string_to_object(IOREngine);
- if (!CORBA::is_nil(obj)) {
- SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
- if (!anEngine->_is_nil()) {
- SALOMEDS::unlock();
- anEngine->Close(sco);
- SALOMEDS::lock();
+ if (_impl->GetDocument()) {
+ SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
+ for (; itcomponent->More(); itcomponent->Next()) {
+ SALOMEDS::SComponent_var sco = itcomponent->Value();
+ CORBA::String_var compodatatype=sco->ComponentDataType();
+ MESSAGE ( "Look for an engine for data type :"<< compodatatype);
+ // if there is an associated Engine call its method for closing
+ CORBA::String_var IOREngine;
+ if (sco->ComponentIOR(IOREngine)) {
+ // we have found the associated engine to write the data
+ MESSAGE ( "We have found an engine for data type :"<< compodatatype);
+ //_narrow can throw a corba exception
+ try {
+ CORBA::Object_var obj = _orb->string_to_object(IOREngine);
+ if (!CORBA::is_nil(obj)) {
+ SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
+ if (!anEngine->_is_nil()) {
+ SALOMEDS::unlock();
+ anEngine->Close(sco);
+ SALOMEDS::lock();
+ }
}
- }
- }
- catch (CORBA::Exception&) {
+ }
+ catch (CORBA::Exception&) {
+ }
}
+ sco->UnRegister();
}
- sco->UnRegister();
- }
- //Does not need any more this iterator
- itcomponent->UnRegister();
+ //Does not need any more this iterator
+ itcomponent->UnRegister();
+ }
// Notify GUI that study is cleared
SALOME_NamingService *aNamingService = KERNEL::getNamingService();
SALOMEDS::lock();
}
+ _impl->Clear();
+ _impl->setNotifier(0);
+ delete _notifier;
+ delete _genObjRegister;
+ _notifier = NULL;
+
_closed = true;
}
bool SALOMEDS_Study_i::Open(const char* aUrl)
throw(SALOME::SALOME_Exception)
{
+ if (!_closed)
+ Clear();
+ Init();
SALOMEDS::Locker lock;
Unexpect aCatch(SalomeException);
bool res = _impl->Open(std::string(aUrl));
+ // update desktop title with new study name
+ NameChanged();
+
if ( !res )
THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
return res;
* Purpose : Save a Study to it's persistent reference
*/
//============================================================================
-CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile)
-{
- SALOMEDS::Locker lock;
- return _impl->Save(_factory, theMultiFile);
-}
-
-CORBA::Boolean SALOMEDS_Study_i::SaveASCII(CORBA::Boolean theMultiFile)
+CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
{
SALOMEDS::Locker lock;
- return _impl->SaveASCII(_factory, theMultiFile);
+ if (_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
+ return _impl->Save(_factory, theMultiFile, theASCII);
}
//=============================================================================
* Purpose : Save a study to the persistent reference aUrl
*/
//============================================================================
-CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile)
-{
- SALOMEDS::Locker lock;
- return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile);
-}
-
-CORBA::Boolean SALOMEDS_Study_i::SaveAsASCII(const char* aUrl, CORBA::Boolean theMultiFile)
+CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
{
SALOMEDS::Locker lock;
- return _impl->SaveAsASCII(std::string(aUrl), _factory, theMultiFile);
+ if (_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
+ return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
}
//============================================================================
CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
+ if (_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
CORBA::String_var anID = theObject->GetID();
SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
+ if (_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
CORBA::String_var anID = theObject->GetID();
SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
+ if (_closed)
+ throw SALOMEDS::Study::StudyInvalidReference();
CORBA::String_var anID = theObject->GetID();
SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
throw SALOMEDS::Study::StudyInvalidReference();
return CORBA::string_dup(_impl->GetPersistentReference().c_str());
}
-//============================================================================
-/*! Function : GetTransientReference
- * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
- */
-//============================================================================
-char* SALOMEDS_Study_i::GetTransientReference()
-{
- SALOMEDS::Locker lock;
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
- return CORBA::string_dup(_impl->GetTransientReference().c_str());
-}
//============================================================================
/*! Function : IsEmpty
return CORBA::string_dup(aPath.c_str());
}
-
-//============================================================================
-/*! Function : SetContext
- * Purpose : Sets the current context
- */
-//============================================================================
-void SALOMEDS_Study_i::SetContext(const char* thePath)
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- _impl->SetContext(std::string((char*)thePath));
- if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
- throw SALOMEDS::Study::StudyInvalidContext();
-}
-
-//============================================================================
-/*! Function : GetContext
- * Purpose : Gets the current context
- */
-//============================================================================
-char* SALOMEDS_Study_i::GetContext()
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
-
- return CORBA::string_dup(_impl->GetContext().c_str());
-}
-
-//============================================================================
-/*! Function : GetObjectNames
- * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
- */
-//============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-
- if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
- throw SALOMEDS::Study::StudyInvalidContext();
-
- std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
- if (_impl->GetErrorCode() == "InvalidContext")
- throw SALOMEDS::Study::StudyInvalidContext();
-
- int aLength = aSeq.size();
- aResult->length(aLength);
- for (int anIndex = 0; anIndex < aLength; anIndex++) {
- aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
- }
-
- return aResult._retn();
-}
-
-//============================================================================
-/*! Function : GetDirectoryNames
- * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
- */
-//============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-
- if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
- throw SALOMEDS::Study::StudyInvalidContext();
-
- std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
- if (_impl->GetErrorCode() == "InvalidContext")
- throw SALOMEDS::Study::StudyInvalidContext();
-
- int aLength = aSeq.size();
- aResult->length(aLength);
- for (int anIndex = 0; anIndex < aLength; anIndex++) {
- aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
- }
-
- return aResult._retn();
-}
-
-//============================================================================
-/*! Function : GetFileNames
- * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
- */
-//============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-
- if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
- throw SALOMEDS::Study::StudyInvalidContext();
-
- std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
- if (_impl->GetErrorCode() == "InvalidContext")
- throw SALOMEDS::Study::StudyInvalidContext();
-
- int aLength = aSeq.size();
- aResult->length(aLength);
- for (int anIndex = 0; anIndex < aLength; anIndex++) {
- aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
- }
-
- return aResult._retn();
-}
-
-//============================================================================
-/*! Function : GetComponentNames
- * Purpose : method to get all components names
- * SRN: Note, theContext can be any, it doesn't matter
- */
-//============================================================================
-SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
-{
- SALOMEDS::Locker lock;
-
- if (_closed)
- throw SALOMEDS::Study::StudyInvalidReference();
-
- SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-
- std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
-
- int aLength = aSeq.size();
- aResult->length(aLength);
- for(int anIndex = 0; anIndex < aLength; anIndex++) {
- aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
- }
-
- return aResult._retn();
-}
-
//============================================================================
/*! Function : NewChildIterator
* Purpose : Create a ChildIterator from an SObject
SALOMEDS::Locker lock;
// URL is specified as IDL attribute: user exception cannot be raised
_impl->URL(std::string((char*)url));
+
+ // update desktop title with new study name
+ NameChanged();
}
void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
_impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
}
-SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
-{
- SALOMEDS::Locker lock;
-
- SALOMEDSImpl_AttributeIOR* Att = NULL;
- if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
- char* IOR = CORBA::string_dup(Att->Value().c_str());
- CORBA::Object_var obj = orb->string_to_object(IOR);
- SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
- ASSERT(!CORBA::is_nil(aStudy));
- return SALOMEDS::Study::_duplicate(aStudy);
- } else {
- MESSAGE("GetStudy: Problem to get study");
- }
- return SALOMEDS::Study::_nil();
-}
-
void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
{
SALOMEDS::Locker lock;
isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
return reinterpret_cast<CORBA::LongLong>(_impl);
}
+
+void SALOMEDS_Study_i::NameChanged()
+{
+ // Notify GUI that the name of study was changed
+ SALOME_NamingService *aNamingService = KERNEL::getNamingService();
+ CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+ SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
+ if ( !CORBA::is_nil(aSession) ) {
+ std::stringstream ss;
+ ss << "studyNameChanged";
+ std::string str = ss.str();
+ SALOMEDS::unlock();
+ aSession->emitMessageOneWay(str.c_str());
+ SALOMEDS::lock();
+ }
+}