1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDS_Study_i.cxx
24 // Author : Sergey RUIN
27 #include "utilities.h"
29 #include "SALOMEDS_Study_i.hxx"
30 #include "SALOMEDS_UseCaseIterator_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
33 #include "SALOMEDS_AttributeParameter_i.hxx"
34 #include "SALOMEDS_ChildIterator_i.hxx"
35 #include "SALOMEDS_Driver_i.hxx"
36 #include "SALOMEDS.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
41 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
42 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "SALOMEDSImpl_Callback.hxx"
47 #include "DF_Label.hxx"
48 #include "DF_Attribute.hxx"
50 #include "Utils_ExceptHandlers.hxx"
52 #include "Basics_Utils.hxx"
53 #include "SALOME_KernelServices.hxx"
58 #include <sys/types.h>
62 UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
63 UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
65 static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
69 class Notifier: public SALOMEDSImpl_AbstractCallback
72 Notifier(CORBA::ORB_ptr orb)
74 _orb = CORBA::ORB::_duplicate(orb);
77 //============================================================================
78 /*! Function : addSO_Notification
79 * Purpose : This function tells all the observers that a SO has been added
81 //============================================================================
83 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
85 std::string anID=theSObject.GetID();
86 const char* cID=anID.c_str();
87 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
89 it->first->notifyObserverID(cID,1);
91 return true; // NGE return always true but can be modified if needed
94 //============================================================================
95 /*! Function : removeSO_Notification
96 * Purpose : This function tells all the observers that a SO has been removed
98 //============================================================================
100 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
102 std::string anID=theSObject.GetID();
103 const char* cID=anID.c_str();
104 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
106 it->first->notifyObserverID(cID,2);
108 return true; // NGE return always true but can be modified if needed
111 //============================================================================
112 /*! Function : modifySO_Notification
113 * Purpose : This function tells all the observers that a SO has been modified
115 //============================================================================
117 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
119 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
123 std::string anID=theSObject.GetID();
124 const char* cID=anID.c_str();
125 it->first->notifyObserverID(cID,reason);
128 return true; // NGE return always true but can be modified if needed
131 //============================================================================
132 /*! Function : modifyNB_Notification
133 * Purpose : This function tells all the observers that
134 * a NoteBook variable has been added/modified/removed.
136 //============================================================================
138 virtual bool modifyNB_Notification(const char* theVarName)
140 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
142 it->first->notifyObserverID(theVarName,6);
144 return true; // NGE return always true but can be modified if needed
147 //============================================================================
148 /*! Function : attach
149 * Purpose : register an Observer
151 //============================================================================
153 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
155 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
158 //============================================================================
159 /*! Function : detach
160 * Purpose : unregister an Observer
162 //============================================================================
164 virtual void detach(SALOMEDS::Observer_ptr theObs)
166 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
168 if ( it->first->_is_equivalent(theObs) ) {
169 myObservers.erase( it );
176 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
177 typedef ObsList::iterator ObsListIter;
182 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
185 GenObjRegister(CORBA::ORB_ptr orb)
187 _orb = CORBA::ORB::_duplicate(orb);
189 virtual void RegisterGenObj (const std::string& theIOR)
193 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
194 if ( obj->_non_existent() ) return;
195 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
196 if(! CORBA::is_nil(gobj) )
201 catch(const CORBA::Exception& e)
205 virtual void UnRegisterGenObj(const std::string& theIOR)
209 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
210 if ( obj->_non_existent() ) return;
211 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
212 if(! CORBA::is_nil(gobj) )
217 catch(const CORBA::Exception& e)
226 } // namespace SALOMEDS
228 //============================================================================
229 /*! Function : SALOMEDS_Study_i
230 * Purpose : SALOMEDS_Study_i constructor
232 //============================================================================
233 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
235 _orb = CORBA::ORB::_duplicate(orb);
236 _impl = new SALOMEDSImpl_Study();
237 _factory = new SALOMEDS_DriverFactory_i(_orb);
243 //============================================================================
244 /*! Function : ~SALOMEDS_Study_i
245 * Purpose : SALOMEDS_Study_i destructor
247 //============================================================================
248 SALOMEDS_Study_i::~SALOMEDS_Study_i()
255 //============================================================================
257 * Purpose : Initialize study components
259 //============================================================================
260 void SALOMEDS_Study_i::Init()
263 throw SALOMEDS::Study::StudyInvalidReference();
265 SALOMEDS::Locker lock;
267 if ( !_impl->GetDocument() )
270 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
271 _notifier = new SALOMEDS::Notifier(_orb);
272 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
275 _impl->setNotifier(_notifier);
276 _impl->setGenObjRegister( _genObjRegister );
278 // update desktop title with new study name
281 // Notify GUI that study was created
282 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
283 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
284 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
285 if ( !CORBA::is_nil(aSession) ) {
286 std::stringstream ss;
287 ss << "studyCreated";
288 std::string str = ss.str();
290 aSession->emitMessageOneWay(str.c_str());
295 //============================================================================
297 * Purpose : Clear study components
299 //============================================================================
300 void SALOMEDS_Study_i::Clear()
305 SALOMEDS::Locker lock;
307 //delete the builder servant
308 PortableServer::POA_var poa=_builder->_default_POA();
309 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
310 poa->deactivate_object(anObjectId.in());
311 _builder->_remove_ref();
315 if (_impl->GetDocument()) {
316 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
317 for (; itcomponent->More(); itcomponent->Next()) {
318 SALOMEDS::SComponent_var sco = itcomponent->Value();
319 CORBA::String_var compodatatype=sco->ComponentDataType();
320 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
321 // if there is an associated Engine call its method for closing
322 CORBA::String_var IOREngine;
323 if (sco->ComponentIOR(IOREngine)) {
324 // we have found the associated engine to write the data
325 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
326 //_narrow can throw a corba exception
328 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
329 if (!CORBA::is_nil(obj)) {
330 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
331 if (!anEngine->_is_nil()) {
333 anEngine->Close(sco);
338 catch (CORBA::Exception&) {
344 //Does not need any more this iterator
345 itcomponent->UnRegister();
348 // Notify GUI that study is cleared
349 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
350 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
351 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
352 if ( !CORBA::is_nil(aSession) ) {
353 std::stringstream ss;
354 ss << "studyCleared";
355 std::string str = ss.str();
357 aSession->emitMessageOneWay(str.c_str());
362 _impl->setNotifier(0);
364 delete _genObjRegister;
370 //============================================================================
372 * Purpose : Open a Study from it's persistent reference
374 //============================================================================
375 bool SALOMEDS_Study_i::Open(const char* aUrl)
376 throw(SALOME::SALOME_Exception)
381 SALOMEDS::Locker lock;
383 Unexpect aCatch(SalomeException);
384 MESSAGE("Begin of SALOMEDS_Study_i::Open");
386 bool res = _impl->Open(std::string(aUrl));
388 // update desktop title with new study name
392 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
396 //============================================================================
398 * Purpose : Save a Study to it's persistent reference
400 //============================================================================
401 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
403 SALOMEDS::Locker lock;
405 throw SALOMEDS::Study::StudyInvalidReference();
406 return _impl->Save(_factory, theMultiFile, theASCII);
409 //=============================================================================
410 /*! Function : SaveAs
411 * Purpose : Save a study to the persistent reference aUrl
413 //============================================================================
414 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
416 SALOMEDS::Locker lock;
418 throw SALOMEDS::Study::StudyInvalidReference();
419 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
422 //============================================================================
423 /*! Function : CanCopy
426 //============================================================================
427 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
429 SALOMEDS::Locker lock;
431 throw SALOMEDS::Study::StudyInvalidReference();
433 CORBA::String_var anID = theObject->GetID();
434 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
436 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
437 bool ret = _impl->CanCopy(anObject, aDriver);
442 //============================================================================
446 //============================================================================
447 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
449 SALOMEDS::Locker lock;
451 throw SALOMEDS::Study::StudyInvalidReference();
453 CORBA::String_var anID = theObject->GetID();
454 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
456 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
457 bool ret = _impl->Copy(anObject, aDriver);
462 //============================================================================
463 /*! Function : CanPaste
466 //============================================================================
467 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
469 SALOMEDS::Locker lock;
471 throw SALOMEDS::Study::StudyInvalidReference();
473 CORBA::String_var anID = theObject->GetID();
474 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
476 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
477 bool ret = _impl->CanPaste(anObject, aDriver);
482 //============================================================================
486 //============================================================================
487 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
488 throw(SALOMEDS::StudyBuilder::LockProtection)
490 SALOMEDS::Locker lock;
492 Unexpect aCatch(LockProtection);
494 CORBA::String_var anID = theObject->GetID();
495 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
496 SALOMEDSImpl_SObject aNewSO;
499 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
500 aNewSO = _impl->Paste(anObject, aDriver);
504 throw SALOMEDS::StudyBuilder::LockProtection();
507 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
511 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
513 SALOMEDS_Driver_i* driver = NULL;
515 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
517 std::string IOREngine = aSCO.GetIOR();
518 if(!IOREngine.empty()) {
519 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
520 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
521 driver = new SALOMEDS_Driver_i(Engine, orb);
528 //============================================================================
529 /*! Function : GetPersistentReference
530 * Purpose : Get persistent reference of study (idem URL())
532 //============================================================================
533 char* SALOMEDS_Study_i::GetPersistentReference()
535 SALOMEDS::Locker lock;
537 throw SALOMEDS::Study::StudyInvalidReference();
538 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
541 //============================================================================
542 /*! Function : IsEmpty
543 * Purpose : Detect if study is empty
545 //============================================================================
546 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
548 SALOMEDS::Locker lock;
550 throw SALOMEDS::Study::StudyInvalidReference();
551 return _impl->IsEmpty();
554 //============================================================================
555 /*! Function : FindComponent
556 * Purpose : Find a Component with ComponentDataType = aComponentName
558 //============================================================================
559 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
561 SALOMEDS::Locker lock;
564 throw SALOMEDS::Study::StudyInvalidReference();
566 SALOMEDS::SComponent_var sco;
568 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
569 if (!aCompImpl.IsNull())
570 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
575 //============================================================================
576 /*! Function : FindComponentID
577 * Purpose : Find a Component from it's ID
579 //============================================================================
580 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
582 SALOMEDS::Locker lock;
585 throw SALOMEDS::Study::StudyInvalidReference();
587 SALOMEDS::SComponent_var sco;
589 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
590 if (!aCompImpl.IsNull())
591 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
596 //============================================================================
597 /*! Function : FindObject
598 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
600 //============================================================================
601 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
603 SALOMEDS::Locker lock;
606 throw SALOMEDS::Study::StudyInvalidReference();
608 SALOMEDS::SObject_var so;
610 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
612 if (aSO.IsComponent()) {
613 SALOMEDSImpl_SComponent aSCO = aSO;
614 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
617 so = SALOMEDS_SObject_i::New(aSO, _orb);
624 //============================================================================
625 /*! Function : FindObjectID
626 * Purpose : Find an Object with ID = anObjectID
628 //============================================================================
629 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
631 SALOMEDS::Locker lock;
634 throw SALOMEDS::Study::StudyInvalidReference();
636 SALOMEDS::SObject_var so;
638 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
640 so = SALOMEDS_SObject_i::New(aSO, _orb);
645 //============================================================================
646 /*! Function : CreateObjectID
647 * Purpose : Creates an Object with ID = anObjectID
649 //============================================================================
650 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
652 SALOMEDS::Locker lock;
655 throw SALOMEDS::Study::StudyInvalidReference();
657 SALOMEDS::SObject_var so;
659 if (anObjectID && strlen(anObjectID) > 0) {
660 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
662 so = SALOMEDS_SObject_i::New(aSO, _orb);
668 //============================================================================
669 /*! Function : FindObjectByName
670 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
671 * : with ComponentDataType = aComponentName
673 //============================================================================
674 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
675 const char* aComponentName )
677 SALOMEDS::Locker lock;
680 throw SALOMEDS::Study::StudyInvalidReference();
682 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
683 std::string((char*)aComponentName));
685 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
686 int aLength = aSeq.size();
687 listSO->length(aLength);
688 for (int i = 0; i < aLength; i++) {
689 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
693 return listSO._retn();
696 //============================================================================
697 /*! Function : FindObjectIOR
698 * Purpose : Find an Object with IOR = anObjectIOR
700 //============================================================================
701 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
703 SALOMEDS::Locker lock;
706 throw SALOMEDS::Study::StudyInvalidReference();
708 SALOMEDS::SObject_var so;
710 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
712 so = SALOMEDS_SObject_i::New(aSO, _orb);
717 //============================================================================
718 /*! Function : FindObjectByPath
719 * Purpose : Find an Object by its path = thePath
721 //============================================================================
722 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
724 SALOMEDS::Locker lock;
727 throw SALOMEDS::Study::StudyInvalidReference();
729 SALOMEDS::SObject_var so;
731 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
733 so = SALOMEDS_SObject_i::New (aSO, _orb);
738 //============================================================================
739 /*! Function : GetObjectPath
742 //============================================================================
743 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
745 SALOMEDS::Locker lock;
748 throw SALOMEDS::Study::StudyInvalidReference();
750 std::string aPath = "";
752 if (!CORBA::is_nil(theObject)) {
753 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
754 SALOMEDSImpl_SObject aSO;
756 if (!CORBA::is_nil(aSObj)) {
757 aSO = _impl->FindObjectID(aSObj->GetID());
760 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
764 aPath = _impl->GetObjectPath(aSO);
768 return CORBA::string_dup(aPath.c_str());
771 //============================================================================
772 /*! Function : NewChildIterator
773 * Purpose : Create a ChildIterator from an SObject
775 //============================================================================
776 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
778 SALOMEDS::Locker lock;
781 throw SALOMEDS::Study::StudyInvalidReference();
783 CORBA::String_var anID = theSO->GetID();
784 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
785 SALOMEDSImpl_ChildIterator anItr(aSO);
786 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
787 SALOMEDS::ChildIterator_var it = it_servant->_this();
793 //============================================================================
794 /*! Function : NewComponentIterator
795 * Purpose : Create a SComponentIterator
797 //============================================================================
798 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
800 SALOMEDS::Locker lock;
803 throw SALOMEDS::Study::StudyInvalidReference();
805 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
807 SALOMEDS::SComponentIterator_var it = it_servant->_this();
813 //============================================================================
814 /*! Function : NewBuilder
815 * Purpose : Create a StudyBuilder
817 //============================================================================
818 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
820 SALOMEDS::Locker lock;
823 throw SALOMEDS::Study::StudyInvalidReference();
825 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
830 //============================================================================
832 * Purpose : get study name
834 //============================================================================
835 char* SALOMEDS_Study_i::Name()
837 SALOMEDS::Locker lock;
838 // Name is specified as IDL attribute: user exception cannot be raised
839 return CORBA::string_dup(_impl->Name().c_str());
842 //============================================================================
843 /*! Function : IsSaved
844 * Purpose : get if study has been saved
846 //============================================================================
847 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
849 SALOMEDS::Locker lock;
850 // IsSaved is specified as IDL attribute: user exception cannot be raised
851 return (!_closed) ? _impl->IsSaved() : false;
854 //============================================================================
855 /*! Function : IsSaved
856 * Purpose : set if study has been saved
858 //============================================================================
859 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
861 SALOMEDS::Locker lock;
862 // IsSaved is specified as IDL attribute: user exception cannot be raised
864 _impl->IsSaved(save);
867 //============================================================================
868 /*! Function : IsModified
869 * Purpose : Detect if a Study has been modified since it has been saved
871 //============================================================================
872 CORBA::Boolean SALOMEDS_Study_i::IsModified()
874 SALOMEDS::Locker lock;
877 throw SALOMEDS::Study::StudyInvalidReference();
879 return _impl->IsModified();
882 //============================================================================
883 /*! Function : Modified
884 * Purpose : Sets a Modified flag of a Study to True
886 //============================================================================
887 void SALOMEDS_Study_i::Modified()
889 SALOMEDS::Locker lock;
892 throw SALOMEDS::Study::StudyInvalidReference();
897 //============================================================================
899 * Purpose : get URL of the study (persistent reference of the study)
901 //============================================================================
902 char* SALOMEDS_Study_i::URL()
904 SALOMEDS::Locker lock;
905 // URL is specified as IDL attribute: user exception cannot be raised
906 return CORBA::string_dup(_impl->URL().c_str());
909 //============================================================================
911 * Purpose : set URL of the study (persistent reference of the study)
913 //============================================================================
914 void SALOMEDS_Study_i::URL(const char* url)
916 SALOMEDS::Locker lock;
917 // URL is specified as IDL attribute: user exception cannot be raised
918 _impl->URL(std::string((char*)url));
920 // update desktop title with new study name
924 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
926 SALOMEDS::Locker lock;
929 throw SALOMEDS::Study::StudyInvalidReference();
931 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
934 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
936 SALOMEDS::Locker lock;
937 SALOMEDSImpl_Study::IORUpdated(theAttribute);
940 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
942 SALOMEDS::Locker lock;
945 throw SALOMEDS::Study::StudyInvalidReference();
947 SALOMEDS::GenericAttribute_ptr aTarget;
948 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
949 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
951 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
957 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
959 SALOMEDS::Locker lock;
962 throw SALOMEDS::Study::StudyInvalidReference();
964 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
965 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
966 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
967 return aProp._retn();
970 char* SALOMEDS_Study_i::GetLastModificationDate()
972 SALOMEDS::Locker lock;
975 throw SALOMEDS::Study::StudyInvalidReference();
977 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
980 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
982 SALOMEDS::Locker lock;
985 throw SALOMEDS::Study::StudyInvalidReference();
987 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
989 std::vector<std::string> aSeq = _impl->GetModificationsDate();
991 int aLength = aSeq.size();
992 aDates->length(aLength);
993 for (int anIndex = 0; anIndex < aLength; anIndex++) {
994 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
997 return aDates._retn();
1000 //============================================================================
1001 /*! Function : GetUseCaseBuilder
1002 * Purpose : Returns a UseCase builder
1004 //============================================================================
1005 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1007 SALOMEDS::Locker lock;
1010 throw SALOMEDS::Study::StudyInvalidReference();
1012 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1013 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1017 //============================================================================
1018 /*! Function : AddPostponed
1021 //============================================================================
1022 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1024 SALOMEDS::Locker lock;
1028 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1030 SALOMEDS::Locker lock;
1034 //============================================================================
1035 /*! Function : RemovePostponed
1038 //============================================================================
1039 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1041 SALOMEDS::Locker lock;
1044 throw SALOMEDS::Study::StudyInvalidReference();
1046 std::vector<std::string> anIORs = _impl->GetIORs();
1047 int i, aSize = (int)anIORs.size();
1049 for (i = 0; i < aSize; i++) {
1051 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1052 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1053 //rnv: To avoid double deletion of the Salome Generic Objects:
1054 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1055 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1056 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1063 //============================================================================
1064 /*! Function : UndoPostponed
1067 //============================================================================
1068 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1070 SALOMEDS::Locker lock;
1075 //============================================================================
1076 /*! Function : DumpStudy
1079 //============================================================================
1080 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1081 const char* theBaseName,
1082 CORBA::Boolean isPublished,
1083 CORBA::Boolean isMultiFile)
1085 SALOMEDS::Locker lock;
1088 throw SALOMEDS::Study::StudyInvalidReference();
1090 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1091 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1092 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1098 //============================================================================
1099 /*! Function : GetCommonParameters
1102 //============================================================================
1103 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1105 SALOMEDS::Locker lock;
1108 throw SALOMEDS::Study::StudyInvalidReference();
1110 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1111 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1112 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1114 return aParam._retn();
1117 //============================================================================
1118 /*! Function : GetCommonModuleParameters
1121 //============================================================================
1122 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1123 const char* theModuleName,
1124 CORBA::Long theSavePoint)
1126 SALOMEDS::Locker lock;
1129 throw SALOMEDS::Study::StudyInvalidReference();
1131 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1132 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1133 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1135 return aParam._retn();
1138 //============================================================================
1139 /*! Function : SetStudyLock
1142 //============================================================================
1143 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1145 SALOMEDS::Locker lock;
1148 throw SALOMEDS::Study::StudyInvalidReference();
1150 _impl->SetStudyLock(theLockerID);
1153 //============================================================================
1154 /*! Function : IsStudyLocked
1157 //============================================================================
1158 bool SALOMEDS_Study_i::IsStudyLocked()
1160 SALOMEDS::Locker lock;
1163 throw SALOMEDS::Study::StudyInvalidReference();
1165 return _impl->IsStudyLocked();
1168 //============================================================================
1169 /*! Function : UnLockStudy
1172 //============================================================================
1173 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1175 SALOMEDS::Locker lock;
1178 throw SALOMEDS::Study::StudyInvalidReference();
1180 _impl->UnLockStudy(theLockerID);
1183 //============================================================================
1184 /*! Function : GetLockerID
1187 //============================================================================
1188 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1190 SALOMEDS::Locker lock;
1193 throw SALOMEDS::Study::StudyInvalidReference();
1195 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1197 std::vector<std::string> aSeq = _impl->GetLockerID();
1199 int aLength = aSeq.size();
1200 aResult->length(aLength);
1201 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1202 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1205 return aResult._retn();
1207 //============================================================================
1208 /*! Function : SetReal
1211 //============================================================================
1212 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1215 throw SALOMEDS::Study::StudyInvalidReference();
1218 _impl->SetVariable(std::string(theVarName),
1220 SALOMEDSImpl_GenericVariable::REAL_VAR);
1222 _notifier->modifyNB_Notification(theVarName);
1225 //============================================================================
1226 /*! Function : SetInteger
1229 //============================================================================
1230 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1233 throw SALOMEDS::Study::StudyInvalidReference();
1235 _impl->SetVariable(std::string(theVarName),
1237 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1239 _notifier->modifyNB_Notification(theVarName);
1242 //============================================================================
1243 /*! Function : SetBoolean
1246 //============================================================================
1247 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1250 throw SALOMEDS::Study::StudyInvalidReference();
1252 _impl->SetVariable(std::string(theVarName),
1254 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1256 _notifier->modifyNB_Notification(theVarName);
1259 //============================================================================
1260 /*! Function : SetString
1263 //============================================================================
1264 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1267 throw SALOMEDS::Study::StudyInvalidReference();
1269 _impl->SetStringVariable(std::string(theVarName),
1271 SALOMEDSImpl_GenericVariable::STRING_VAR);
1273 _notifier->modifyNB_Notification(theVarName);
1276 //============================================================================
1277 /*! Function : SetStringAsDouble
1280 //============================================================================
1281 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1284 throw SALOMEDS::Study::StudyInvalidReference();
1286 _impl->SetStringVariableAsDouble(std::string(theVarName),
1288 SALOMEDSImpl_GenericVariable::STRING_VAR);
1291 //============================================================================
1292 /*! Function : GetReal
1295 //============================================================================
1296 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1299 throw SALOMEDS::Study::StudyInvalidReference();
1301 return _impl->GetVariableValue(std::string(theVarName));
1304 //============================================================================
1305 /*! Function : GetInteger
1308 //============================================================================
1309 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1312 throw SALOMEDS::Study::StudyInvalidReference();
1314 return (long)_impl->GetVariableValue(std::string(theVarName));
1317 //============================================================================
1318 /*! Function : GetBoolean
1321 //============================================================================
1322 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1325 throw SALOMEDS::Study::StudyInvalidReference();
1327 return (bool)_impl->GetVariableValue(std::string(theVarName));
1330 //============================================================================
1331 /*! Function : GetString
1334 //============================================================================
1335 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1338 throw SALOMEDS::Study::StudyInvalidReference();
1340 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1343 //============================================================================
1344 /*! Function : IsReal
1347 //============================================================================
1348 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1351 throw SALOMEDS::Study::StudyInvalidReference();
1353 return _impl->IsTypeOf(std::string(theVarName),
1354 SALOMEDSImpl_GenericVariable::REAL_VAR);
1357 //============================================================================
1358 /*! Function : IsInteger
1361 //============================================================================
1362 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1365 throw SALOMEDS::Study::StudyInvalidReference();
1367 return _impl->IsTypeOf(std::string(theVarName),
1368 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1371 //============================================================================
1372 /*! Function : IsBoolean
1375 //============================================================================
1376 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1379 throw SALOMEDS::Study::StudyInvalidReference();
1381 return _impl->IsTypeOf(std::string(theVarName),
1382 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1385 //============================================================================
1386 /*! Function : IsString
1389 //============================================================================
1390 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1393 throw SALOMEDS::Study::StudyInvalidReference();
1395 return _impl->IsTypeOf(std::string(theVarName),
1396 SALOMEDSImpl_GenericVariable::STRING_VAR);
1399 //============================================================================
1400 /*! Function : IsVariable
1403 //============================================================================
1404 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1407 throw SALOMEDS::Study::StudyInvalidReference();
1409 return _impl->IsVariable(std::string(theVarName));
1412 //============================================================================
1413 /*! Function : GetVariableNames
1416 //============================================================================
1417 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1420 throw SALOMEDS::Study::StudyInvalidReference();
1422 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1424 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1426 int aLen = aVarNames.size();
1427 aResult->length(aLen);
1428 for (int anInd = 0; anInd < aLen; anInd++)
1429 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1431 return aResult._retn();
1434 //============================================================================
1435 /*! Function : RemoveVariable
1438 //============================================================================
1439 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1442 throw SALOMEDS::Study::StudyInvalidReference();
1444 bool res = _impl->RemoveVariable(std::string(theVarName));
1445 if (res && _notifier)
1446 _notifier->modifyNB_Notification(theVarName);
1451 //============================================================================
1452 /*! Function : RenameVariable
1455 //============================================================================
1456 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1459 throw SALOMEDS::Study::StudyInvalidReference();
1461 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1462 if (res && _notifier)
1463 _notifier->modifyNB_Notification(theVarName);
1468 //============================================================================
1469 /*! Function : IsVariableUsed
1472 //============================================================================
1473 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1476 throw SALOMEDS::Study::StudyInvalidReference();
1478 return _impl->IsVariableUsed(std::string(theVarName));
1482 //============================================================================
1483 /*! Function : ParseVariables
1486 //============================================================================
1487 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1490 throw SALOMEDS::Study::StudyInvalidReference();
1492 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1494 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1496 int aSectionsLen = aSections.size();
1497 aResult->length(aSectionsLen);
1499 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1500 std::vector<std::string> aVarNames = aSections[aSectionInd];
1502 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1504 int aLen = aVarNames.size();
1505 aList->length(aLen);
1507 for (int anInd = 0; anInd < aLen; anInd++)
1508 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1510 aResult[aSectionInd] = aList;
1513 return aResult._retn();
1516 //============================================================================
1517 /*! Function : GetDefaultScript
1520 //============================================================================
1521 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1523 SALOMEDS::Locker lock;
1526 throw SALOMEDS::Study::StudyInvalidReference();
1528 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1529 return CORBA::string_dup(script.c_str());
1532 //============================================================================
1533 /*! Function : EnableUseCaseAutoFilling
1536 //============================================================================
1537 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1540 throw SALOMEDS::Study::StudyInvalidReference();
1542 _impl->EnableUseCaseAutoFilling(isEnabled);
1543 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1546 builder->SetOnAddSObject(_impl->GetCallback());
1547 builder->SetOnRemoveSObject(_impl->GetCallback());
1550 builder->SetOnAddSObject(NULL);
1551 builder->SetOnRemoveSObject(NULL);
1557 CORBA::Long SALOMEDS_Study_i::getPID()
1560 return (CORBA::Long)_getpid();
1562 return (CORBA::Long)getpid();
1566 void SALOMEDS_Study_i::ShutdownWithExit()
1568 exit( EXIT_SUCCESS );
1571 void SALOMEDS_Study_i::Shutdown()
1573 if(!CORBA::is_nil(_orb))
1577 //============================================================================
1578 /*! Function : attach
1579 * Purpose : This function attach an observer to the study
1581 //============================================================================
1582 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1585 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1589 //============================================================================
1590 /*! Function : detach
1591 * Purpose : This function detaches an observer from the study
1593 //============================================================================
1594 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1597 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1600 //===========================================================================
1601 // PRIVATE FUNCTIONS
1602 //===========================================================================
1603 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1606 long pid = (long)_getpid();
1608 long pid = (long)getpid();
1610 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1611 return reinterpret_cast<CORBA::LongLong>(_impl);
1614 void SALOMEDS_Study_i::NameChanged()
1616 // Notify GUI that the name of study was changed
1617 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1618 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
1619 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1620 if ( !CORBA::is_nil(aSession) ) {
1621 std::stringstream ss;
1622 ss << "studyNameChanged";
1623 std::string str = ss.str();
1625 aSession->emitMessageOneWay(str.c_str());