//============================================================================
/*! Function : SALOMEDS_StudyManager_i
- * Purpose : SALOMEDS_StudyManager_i constructor
+ * Purpose : SALOMEDS_StudyManager_i constructor
*/
//============================================================================
-SALOMEDS_StudyManager_i::SALOMEDS_StudyManager_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr thePOA)
-{
+SALOMEDS_StudyManager_i::SALOMEDS_StudyManager_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr thePOA)
+{
_orb = CORBA::ORB::_duplicate(orb);
_poa = PortableServer::POA::_duplicate(thePOA);
_name_service = new SALOME_NamingService(_orb);
// Study directory creation in the naming service : to register all
// open studies in the session
_name_service->Create_Directory("/Study");
- _impl = new SALOMEDSImpl_StudyManager;
- _factory = new SALOMEDS_DriverFactory_i(_orb);
+ _impl = new SALOMEDSImpl_StudyManager;
+ _factory = new SALOMEDS_DriverFactory_i(_orb);
}
//============================================================================
//============================================================================
/*! Function : register_name
- * Purpose : Register the study Manager in the naming service under the
+ * Purpose : Register the study Manager in the naming service under the
* context name
*/
//============================================================================
-void SALOMEDS_StudyManager_i::register_name(char * name)
+void SALOMEDS_StudyManager_i::register_name(char * name)
{
SALOMEDS::StudyManager_var aManager(_this());
_name_service->Register(aManager.in(), name);
* Purpose : Create a New Study of name study_name
*/
//============================================================================
-SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* study_name)
+SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* study_name)
{
SALOMEDS::Locker lock;
MESSAGE("NewStudy : Creating the CORBA servant holding it... ");
- SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
+ SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
// Register study in the naming service
// Path to acces the study
- if(!_name_service->Change_Directory("/Study"))
+ if(!_name_service->Change_Directory("/Study"))
MESSAGE( "Unable to access the study directory" )
else
_name_service->Register(Study, study_name);
throw(SALOME::SALOME_Exception)
{
SALOMEDS::Locker lock;
-
+
Unexpect aCatch(SalomeException);
MESSAGE("Begin of SALOMEDS_StudyManager_i::Open");
MESSAGE("Open : Creating the CORBA servant holding it... ");
// Temporary aStudyUrl in place of study name
- SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
+ SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
+ SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
// Assign the value of the IOR in the study->root
CORBA::String_var IORStudy = _orb->object_to_string(Study);
aStudyImpl->SetTransientReference((char*)IORStudy);
-
+
// Register study in the naming service
// Path to acces the study
if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" )
/*! Function : Close
* Purpose : Close a study.
* If the study hasn't been saved, ask the user to confirm the
- * close action without saving
+ * close action without saving
*/
//============================================================================
void SALOMEDS_StudyManager_i::Close(SALOMEDS::Study_ptr aStudy)
SALOMEDS::Locker lock;
if(aStudy->_is_nil()) return;
-
+
// Destroy study name in the naming service
if(_name_service->Change_Directory("/Study")){
CORBA::String_var aString(aStudy->Name());
_name_service->Destroy_Name(aString.in());
- }
+ }
SALOMEDS::unlock();
aStudy->Close();
SALOMEDS::ListOfOpenStudies* SALOMEDS_StudyManager_i::GetOpenStudies()
{
SALOMEDS::Locker lock;
-
+
Handle(TColStd_HSequenceOfTransient) anOpened = _impl->GetOpenStudies();
int aLength = anOpened->Length();
* Purpose : Get a study from its name
*/
//============================================================================
-SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByName(const char* aStudyName)
+SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByName(const char* aStudyName)
{
SALOMEDS::Locker lock;
-
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByName(TCollection_AsciiString((char*)aStudyName));
- if(aStudyImpl.IsNull())
- {
- MESSAGE("No active study in this session");
- ASSERT(false); // Stop here...
- }
-
- SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
-
- return Study;
+ Handle(SALOMEDSImpl_Study) aStudyImpl =
+ _impl->GetStudyByName(TCollection_AsciiString((char*)aStudyName));
+
+ if (aStudyImpl.IsNull())
+ {
+ MESSAGE(_impl->GetErrorCode().ToCString());
+ return SALOMEDS::Study::_nil();
+ }
+
+ SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
+ SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudy_servant->_this());
+
+ return aStudy._retn();
}
//============================================================================
* Purpose : Get a study from its ID
*/
//============================================================================
-SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByID(CORBA::Short aStudyID)
+SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByID(CORBA::Short aStudyID)
{
SALOMEDS::Locker lock;
-
+
Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudyID);
- if(aStudyImpl.IsNull())
- {
- MESSAGE("No active study in this session");
- ASSERT(false); // Stop here...
- }
-
- SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
-
- return Study;
+ if (aStudyImpl.IsNull())
+ {
+ MESSAGE(_impl->GetErrorCode().ToCString());
+ return SALOMEDS::Study::_nil();
+ }
+
+ SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
+ SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudy_servant->_this());
+
+ return aStudy._retn();
}
//============================================================================
/*! Function : CanCopy
- * Purpose :
+ * Purpose :
*/
//============================================================================
-CORBA::Boolean SALOMEDS_StudyManager_i::CanCopy(SALOMEDS::SObject_ptr theObject)
+CORBA::Boolean SALOMEDS_StudyManager_i::CanCopy(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
* Purpose :
*/
//============================================================================
-CORBA::Boolean SALOMEDS_StudyManager_i::Copy(SALOMEDS::SObject_ptr theObject)
+CORBA::Boolean SALOMEDS_StudyManager_i::Copy(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
* Purpose :
*/
//============================================================================
-CORBA::Boolean SALOMEDS_StudyManager_i::CanPaste(SALOMEDS::SObject_ptr theObject)
+CORBA::Boolean SALOMEDS_StudyManager_i::CanPaste(SALOMEDS::SObject_ptr theObject)
{
SALOMEDS::Locker lock;
Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID());
Handle(SALOMEDSImpl_SObject) aNewSO;
-
+
try {
SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
aNewSO = _impl->Paste(anObject, aDriver);
SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb)
{
SALOMEDS_Driver_i* driver = NULL;
-
+
Handle(SALOMEDSImpl_SComponent) aSCO = theObject->GetFatherComponent();
if(!aSCO.IsNull()) {
TCollection_AsciiString IOREngine = aSCO->GetIOR();
SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
driver = new SALOMEDS_Driver_i(Engine, orb);
}
- }
+ }
return driver;
}
long pid = (long)_getpid();
#else
long pid = (long)getpid();
-#endif
+#endif
isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
SALOMEDSImpl_StudyManager* aManager = _impl.operator->();
return ((long)aManager);
}
-//===========================================================================
+//===========================================================================
* Purpose : Get a study from its name
*/
//============================================================================
-Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::GetStudyByName(const TCollection_AsciiString& aStudyName)
+Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::GetStudyByName
+ (const TCollection_AsciiString& aStudyName)
{
_errorCode = "";
-
- Handle(SALOMEDSImpl_Study) aStudy;
int nbDocs = _OCAFApp->NbDocuments();
- if(nbDocs == 0) {
+ if (nbDocs == 0) {
_errorCode = "No active study in this session";
- return aStudy;
+ return NULL;
}
else {
+ Handle(SALOMEDSImpl_Study) aStudy;
Handle(CDF_Session) S = CDF_Session::CurrentSession();
CDF_DirectoryIterator it (S->Directory());
- for (;it.MoreDocument();it.NextDocument()) {
+ for (; it.MoreDocument(); it.NextDocument()) {
Handle(TDocStd_Document) D = Handle(TDocStd_Document)::DownCast(it.Document());
- if(D == _clipboard) continue;
+ if (D == _clipboard) continue;
aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
- if(aStudy.IsNull()) continue;
- if(aStudy->Name() == aStudyName) return aStudy;
+ if (aStudy.IsNull()) continue;
+ if (aStudy->Name() == aStudyName) return aStudy;
}
}
- _errorCode = TCollection_AsciiString("Found no study with the name ")+aStudyName;
- return aStudy;
+ _errorCode = TCollection_AsciiString("Found no study with the name ") + aStudyName;
+ return NULL;
}
//============================================================================
Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
{
_errorCode = "";
- Handle(SALOMEDSImpl_Study) aStudy;
int nbDocs = _OCAFApp->NbDocuments();
- if(nbDocs == 0) {
+ if (nbDocs == 0) {
_errorCode = "No active study in this session";
- return aStudy;
+ return NULL;
}
else {
+ Handle(SALOMEDSImpl_Study) aStudy;
Handle(CDF_Session) S = CDF_Session::CurrentSession();
CDF_DirectoryIterator it (S->Directory());
- for (;it.MoreDocument();it.NextDocument()) {
+ for (; it.MoreDocument(); it.NextDocument()) {
Handle(TDocStd_Document) D = Handle(TDocStd_Document)::DownCast(it.Document());
- if(D == _clipboard) continue;
+ if (D == _clipboard) continue;
aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
- if(aStudy.IsNull()) continue;
- if(aStudy->StudyId() == aStudyID) return aStudy;
+ if (aStudy.IsNull()) continue;
+ if (aStudy->StudyId() == aStudyID) return aStudy;
}
}
_errorCode = "Found no study with the given ID";
- return aStudy;
+ return NULL;
}
//=============================================================================