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()
262 if ( !_impl->GetDocument() )
266 throw SALOMEDS::Study::StudyInvalidReference();
268 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
269 _notifier = new SALOMEDS::Notifier(_orb);
270 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
273 _impl->setNotifier(_notifier);
274 _impl->setGenObjRegister( _genObjRegister );
276 // update desktop title with new study name
279 // Notify GUI that study was created
280 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
281 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
282 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
283 if ( !CORBA::is_nil(aSession) ) {
284 std::stringstream ss;
285 ss << "studyCreated";
286 std::string str = ss.str();
288 aSession->emitMessageOneWay(str.c_str());
293 //============================================================================
295 * Purpose : Clear study components
297 //============================================================================
298 void SALOMEDS_Study_i::Clear()
300 SALOMEDS::Locker lock;
303 //delete the builder servant
304 PortableServer::POA_var poa=_builder->_default_POA();
305 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
306 poa->deactivate_object(anObjectId.in());
307 _builder->_remove_ref();
311 if (_impl->GetDocument()) {
312 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
313 for (; itcomponent->More(); itcomponent->Next()) {
314 SALOMEDS::SComponent_var sco = itcomponent->Value();
315 CORBA::String_var compodatatype=sco->ComponentDataType();
316 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
317 // if there is an associated Engine call its method for closing
318 CORBA::String_var IOREngine;
319 if (sco->ComponentIOR(IOREngine)) {
320 // we have found the associated engine to write the data
321 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
322 //_narrow can throw a corba exception
324 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
325 if (!CORBA::is_nil(obj)) {
326 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
327 if (!anEngine->_is_nil()) {
329 anEngine->Close(sco);
334 catch (CORBA::Exception&) {
340 //Does not need any more this iterator
341 itcomponent->UnRegister();
344 // Notify GUI that study is cleared
345 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
346 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
347 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
348 if ( !CORBA::is_nil(aSession) ) {
349 std::stringstream ss;
350 ss << "studyCleared";
351 std::string str = ss.str();
353 aSession->emitMessageOneWay(str.c_str());
358 _impl->setNotifier(0);
360 delete _genObjRegister;
366 //============================================================================
368 * Purpose : Open a Study from it's persistent reference
370 //============================================================================
371 bool SALOMEDS_Study_i::Open(const char* aUrl)
372 throw(SALOME::SALOME_Exception)
377 SALOMEDS::Locker lock;
379 Unexpect aCatch(SalomeException);
380 MESSAGE("Begin of SALOMEDS_Study_i::Open");
382 bool res = _impl->Open(std::string(aUrl));
384 // update desktop title with new study name
388 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
392 //============================================================================
394 * Purpose : Save a Study to it's persistent reference
396 //============================================================================
397 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
399 SALOMEDS::Locker lock;
401 throw SALOMEDS::Study::StudyInvalidReference();
402 return _impl->Save(_factory, theMultiFile, theASCII);
405 //=============================================================================
406 /*! Function : SaveAs
407 * Purpose : Save a study to the persistent reference aUrl
409 //============================================================================
410 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
412 SALOMEDS::Locker lock;
414 throw SALOMEDS::Study::StudyInvalidReference();
415 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
418 //============================================================================
419 /*! Function : CanCopy
422 //============================================================================
423 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
425 SALOMEDS::Locker lock;
427 throw SALOMEDS::Study::StudyInvalidReference();
429 CORBA::String_var anID = theObject->GetID();
430 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
432 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
433 bool ret = _impl->CanCopy(anObject, aDriver);
438 //============================================================================
442 //============================================================================
443 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
445 SALOMEDS::Locker lock;
447 throw SALOMEDS::Study::StudyInvalidReference();
449 CORBA::String_var anID = theObject->GetID();
450 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
452 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
453 bool ret = _impl->Copy(anObject, aDriver);
458 //============================================================================
459 /*! Function : CanPaste
462 //============================================================================
463 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
465 SALOMEDS::Locker lock;
467 throw SALOMEDS::Study::StudyInvalidReference();
469 CORBA::String_var anID = theObject->GetID();
470 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
472 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
473 bool ret = _impl->CanPaste(anObject, aDriver);
478 //============================================================================
482 //============================================================================
483 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
484 throw(SALOMEDS::StudyBuilder::LockProtection)
486 SALOMEDS::Locker lock;
488 Unexpect aCatch(LockProtection);
490 CORBA::String_var anID = theObject->GetID();
491 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
492 SALOMEDSImpl_SObject aNewSO;
495 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
496 aNewSO = _impl->Paste(anObject, aDriver);
500 throw SALOMEDS::StudyBuilder::LockProtection();
503 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
507 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
509 SALOMEDS_Driver_i* driver = NULL;
511 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
513 std::string IOREngine = aSCO.GetIOR();
514 if(!IOREngine.empty()) {
515 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
516 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
517 driver = new SALOMEDS_Driver_i(Engine, orb);
524 //============================================================================
525 /*! Function : GetPersistentReference
526 * Purpose : Get persistent reference of study (idem URL())
528 //============================================================================
529 char* SALOMEDS_Study_i::GetPersistentReference()
531 SALOMEDS::Locker lock;
533 throw SALOMEDS::Study::StudyInvalidReference();
534 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
537 //============================================================================
538 /*! Function : IsEmpty
539 * Purpose : Detect if study is empty
541 //============================================================================
542 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
544 SALOMEDS::Locker lock;
546 throw SALOMEDS::Study::StudyInvalidReference();
547 return _impl->IsEmpty();
550 //============================================================================
551 /*! Function : FindComponent
552 * Purpose : Find a Component with ComponentDataType = aComponentName
554 //============================================================================
555 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
557 SALOMEDS::Locker lock;
560 throw SALOMEDS::Study::StudyInvalidReference();
562 SALOMEDS::SComponent_var sco;
564 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
565 if (!aCompImpl.IsNull())
566 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
571 //============================================================================
572 /*! Function : FindComponentID
573 * Purpose : Find a Component from it's ID
575 //============================================================================
576 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
578 SALOMEDS::Locker lock;
581 throw SALOMEDS::Study::StudyInvalidReference();
583 SALOMEDS::SComponent_var sco;
585 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
586 if (!aCompImpl.IsNull())
587 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
592 //============================================================================
593 /*! Function : FindObject
594 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
596 //============================================================================
597 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
599 SALOMEDS::Locker lock;
602 throw SALOMEDS::Study::StudyInvalidReference();
604 SALOMEDS::SObject_var so;
606 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
608 if (aSO.IsComponent()) {
609 SALOMEDSImpl_SComponent aSCO = aSO;
610 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
613 so = SALOMEDS_SObject_i::New(aSO, _orb);
620 //============================================================================
621 /*! Function : FindObjectID
622 * Purpose : Find an Object with ID = anObjectID
624 //============================================================================
625 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
627 SALOMEDS::Locker lock;
630 throw SALOMEDS::Study::StudyInvalidReference();
632 SALOMEDS::SObject_var so;
634 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
636 so = SALOMEDS_SObject_i::New(aSO, _orb);
641 //============================================================================
642 /*! Function : CreateObjectID
643 * Purpose : Creates an Object with ID = anObjectID
645 //============================================================================
646 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
648 SALOMEDS::Locker lock;
651 throw SALOMEDS::Study::StudyInvalidReference();
653 SALOMEDS::SObject_var so;
655 if (anObjectID && strlen(anObjectID) > 0) {
656 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
658 so = SALOMEDS_SObject_i::New(aSO, _orb);
664 //============================================================================
665 /*! Function : FindObjectByName
666 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
667 * : with ComponentDataType = aComponentName
669 //============================================================================
670 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
671 const char* aComponentName )
673 SALOMEDS::Locker lock;
676 throw SALOMEDS::Study::StudyInvalidReference();
678 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
679 std::string((char*)aComponentName));
681 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
682 int aLength = aSeq.size();
683 listSO->length(aLength);
684 for (int i = 0; i < aLength; i++) {
685 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
689 return listSO._retn();
692 //============================================================================
693 /*! Function : FindObjectIOR
694 * Purpose : Find an Object with IOR = anObjectIOR
696 //============================================================================
697 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
699 SALOMEDS::Locker lock;
702 throw SALOMEDS::Study::StudyInvalidReference();
704 SALOMEDS::SObject_var so;
706 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
708 so = SALOMEDS_SObject_i::New(aSO, _orb);
713 //============================================================================
714 /*! Function : FindObjectByPath
715 * Purpose : Find an Object by its path = thePath
717 //============================================================================
718 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
720 SALOMEDS::Locker lock;
723 throw SALOMEDS::Study::StudyInvalidReference();
725 SALOMEDS::SObject_var so;
727 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
729 so = SALOMEDS_SObject_i::New (aSO, _orb);
734 //============================================================================
735 /*! Function : GetObjectPath
738 //============================================================================
739 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
741 SALOMEDS::Locker lock;
744 throw SALOMEDS::Study::StudyInvalidReference();
746 std::string aPath = "";
748 if (!CORBA::is_nil(theObject)) {
749 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
750 SALOMEDSImpl_SObject aSO;
752 if (!CORBA::is_nil(aSObj)) {
753 aSO = _impl->FindObjectID(aSObj->GetID());
756 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
760 aPath = _impl->GetObjectPath(aSO);
764 return CORBA::string_dup(aPath.c_str());
767 //============================================================================
768 /*! Function : NewChildIterator
769 * Purpose : Create a ChildIterator from an SObject
771 //============================================================================
772 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
774 SALOMEDS::Locker lock;
777 throw SALOMEDS::Study::StudyInvalidReference();
779 CORBA::String_var anID = theSO->GetID();
780 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
781 SALOMEDSImpl_ChildIterator anItr(aSO);
782 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
783 SALOMEDS::ChildIterator_var it = it_servant->_this();
789 //============================================================================
790 /*! Function : NewComponentIterator
791 * Purpose : Create a SComponentIterator
793 //============================================================================
794 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
796 SALOMEDS::Locker lock;
799 throw SALOMEDS::Study::StudyInvalidReference();
801 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
803 SALOMEDS::SComponentIterator_var it = it_servant->_this();
809 //============================================================================
810 /*! Function : NewBuilder
811 * Purpose : Create a StudyBuilder
813 //============================================================================
814 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
816 SALOMEDS::Locker lock;
819 throw SALOMEDS::Study::StudyInvalidReference();
821 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
826 //============================================================================
828 * Purpose : get study name
830 //============================================================================
831 char* SALOMEDS_Study_i::Name()
833 SALOMEDS::Locker lock;
834 // Name is specified as IDL attribute: user exception cannot be raised
835 return CORBA::string_dup(_impl->Name().c_str());
838 //============================================================================
839 /*! Function : IsSaved
840 * Purpose : get if study has been saved
842 //============================================================================
843 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
845 SALOMEDS::Locker lock;
846 // IsSaved is specified as IDL attribute: user exception cannot be raised
847 return (!_closed) ? _impl->IsSaved() : false;
850 //============================================================================
851 /*! Function : IsSaved
852 * Purpose : set if study has been saved
854 //============================================================================
855 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
857 SALOMEDS::Locker lock;
858 // IsSaved is specified as IDL attribute: user exception cannot be raised
860 _impl->IsSaved(save);
863 //============================================================================
864 /*! Function : IsModified
865 * Purpose : Detect if a Study has been modified since it has been saved
867 //============================================================================
868 CORBA::Boolean SALOMEDS_Study_i::IsModified()
870 SALOMEDS::Locker lock;
873 throw SALOMEDS::Study::StudyInvalidReference();
875 return _impl->IsModified();
878 //============================================================================
879 /*! Function : Modified
880 * Purpose : Sets a Modified flag of a Study to True
882 //============================================================================
883 void SALOMEDS_Study_i::Modified()
885 SALOMEDS::Locker lock;
888 throw SALOMEDS::Study::StudyInvalidReference();
893 //============================================================================
895 * Purpose : get URL of the study (persistent reference of the study)
897 //============================================================================
898 char* SALOMEDS_Study_i::URL()
900 SALOMEDS::Locker lock;
901 // URL is specified as IDL attribute: user exception cannot be raised
902 return CORBA::string_dup(_impl->URL().c_str());
905 //============================================================================
907 * Purpose : set URL of the study (persistent reference of the study)
909 //============================================================================
910 void SALOMEDS_Study_i::URL(const char* url)
912 SALOMEDS::Locker lock;
913 // URL is specified as IDL attribute: user exception cannot be raised
914 _impl->URL(std::string((char*)url));
916 // update desktop title with new study name
920 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
922 SALOMEDS::Locker lock;
925 throw SALOMEDS::Study::StudyInvalidReference();
927 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
930 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
932 SALOMEDS::Locker lock;
933 SALOMEDSImpl_Study::IORUpdated(theAttribute);
936 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
938 SALOMEDS::Locker lock;
941 throw SALOMEDS::Study::StudyInvalidReference();
943 SALOMEDS::GenericAttribute_ptr aTarget;
944 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
945 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
947 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
953 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
955 SALOMEDS::Locker lock;
958 throw SALOMEDS::Study::StudyInvalidReference();
960 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
961 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
962 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
963 return aProp._retn();
966 char* SALOMEDS_Study_i::GetLastModificationDate()
968 SALOMEDS::Locker lock;
971 throw SALOMEDS::Study::StudyInvalidReference();
973 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
976 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
978 SALOMEDS::Locker lock;
981 throw SALOMEDS::Study::StudyInvalidReference();
983 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
985 std::vector<std::string> aSeq = _impl->GetModificationsDate();
987 int aLength = aSeq.size();
988 aDates->length(aLength);
989 for (int anIndex = 0; anIndex < aLength; anIndex++) {
990 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
993 return aDates._retn();
996 //============================================================================
997 /*! Function : GetUseCaseBuilder
998 * Purpose : Returns a UseCase builder
1000 //============================================================================
1001 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1003 SALOMEDS::Locker lock;
1006 throw SALOMEDS::Study::StudyInvalidReference();
1008 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1009 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1013 //============================================================================
1014 /*! Function : AddPostponed
1017 //============================================================================
1018 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1020 SALOMEDS::Locker lock;
1024 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1026 SALOMEDS::Locker lock;
1030 //============================================================================
1031 /*! Function : RemovePostponed
1034 //============================================================================
1035 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1037 SALOMEDS::Locker lock;
1040 throw SALOMEDS::Study::StudyInvalidReference();
1042 std::vector<std::string> anIORs = _impl->GetIORs();
1043 int i, aSize = (int)anIORs.size();
1045 for (i = 0; i < aSize; i++) {
1047 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1048 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1049 //rnv: To avoid double deletion of the Salome Generic Objects:
1050 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1051 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1052 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1059 //============================================================================
1060 /*! Function : UndoPostponed
1063 //============================================================================
1064 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1066 SALOMEDS::Locker lock;
1071 //============================================================================
1072 /*! Function : DumpStudy
1075 //============================================================================
1076 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1077 const char* theBaseName,
1078 CORBA::Boolean isPublished,
1079 CORBA::Boolean isMultiFile)
1081 SALOMEDS::Locker lock;
1084 throw SALOMEDS::Study::StudyInvalidReference();
1086 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1087 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1088 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1094 //============================================================================
1095 /*! Function : GetCommonParameters
1098 //============================================================================
1099 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1101 SALOMEDS::Locker lock;
1104 throw SALOMEDS::Study::StudyInvalidReference();
1106 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1107 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1108 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1110 return aParam._retn();
1113 //============================================================================
1114 /*! Function : GetCommonModuleParameters
1117 //============================================================================
1118 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1119 const char* theModuleName,
1120 CORBA::Long theSavePoint)
1122 SALOMEDS::Locker lock;
1125 throw SALOMEDS::Study::StudyInvalidReference();
1127 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1128 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1129 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1131 return aParam._retn();
1134 //============================================================================
1135 /*! Function : SetStudyLock
1138 //============================================================================
1139 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1141 SALOMEDS::Locker lock;
1144 throw SALOMEDS::Study::StudyInvalidReference();
1146 _impl->SetStudyLock(theLockerID);
1149 //============================================================================
1150 /*! Function : IsStudyLocked
1153 //============================================================================
1154 bool SALOMEDS_Study_i::IsStudyLocked()
1156 SALOMEDS::Locker lock;
1159 throw SALOMEDS::Study::StudyInvalidReference();
1161 return _impl->IsStudyLocked();
1164 //============================================================================
1165 /*! Function : UnLockStudy
1168 //============================================================================
1169 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1171 SALOMEDS::Locker lock;
1174 throw SALOMEDS::Study::StudyInvalidReference();
1176 _impl->UnLockStudy(theLockerID);
1179 //============================================================================
1180 /*! Function : GetLockerID
1183 //============================================================================
1184 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1186 SALOMEDS::Locker lock;
1189 throw SALOMEDS::Study::StudyInvalidReference();
1191 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1193 std::vector<std::string> aSeq = _impl->GetLockerID();
1195 int aLength = aSeq.size();
1196 aResult->length(aLength);
1197 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1198 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1201 return aResult._retn();
1203 //============================================================================
1204 /*! Function : SetReal
1207 //============================================================================
1208 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1211 throw SALOMEDS::Study::StudyInvalidReference();
1214 _impl->SetVariable(std::string(theVarName),
1216 SALOMEDSImpl_GenericVariable::REAL_VAR);
1218 _notifier->modifyNB_Notification(theVarName);
1221 //============================================================================
1222 /*! Function : SetInteger
1225 //============================================================================
1226 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1229 throw SALOMEDS::Study::StudyInvalidReference();
1231 _impl->SetVariable(std::string(theVarName),
1233 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1235 _notifier->modifyNB_Notification(theVarName);
1238 //============================================================================
1239 /*! Function : SetBoolean
1242 //============================================================================
1243 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1246 throw SALOMEDS::Study::StudyInvalidReference();
1248 _impl->SetVariable(std::string(theVarName),
1250 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1252 _notifier->modifyNB_Notification(theVarName);
1255 //============================================================================
1256 /*! Function : SetString
1259 //============================================================================
1260 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1263 throw SALOMEDS::Study::StudyInvalidReference();
1265 _impl->SetStringVariable(std::string(theVarName),
1267 SALOMEDSImpl_GenericVariable::STRING_VAR);
1269 _notifier->modifyNB_Notification(theVarName);
1272 //============================================================================
1273 /*! Function : SetStringAsDouble
1276 //============================================================================
1277 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1280 throw SALOMEDS::Study::StudyInvalidReference();
1282 _impl->SetStringVariableAsDouble(std::string(theVarName),
1284 SALOMEDSImpl_GenericVariable::STRING_VAR);
1287 //============================================================================
1288 /*! Function : GetReal
1291 //============================================================================
1292 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1295 throw SALOMEDS::Study::StudyInvalidReference();
1297 return _impl->GetVariableValue(std::string(theVarName));
1300 //============================================================================
1301 /*! Function : GetInteger
1304 //============================================================================
1305 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1308 throw SALOMEDS::Study::StudyInvalidReference();
1310 return (long)_impl->GetVariableValue(std::string(theVarName));
1313 //============================================================================
1314 /*! Function : GetBoolean
1317 //============================================================================
1318 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1321 throw SALOMEDS::Study::StudyInvalidReference();
1323 return (bool)_impl->GetVariableValue(std::string(theVarName));
1326 //============================================================================
1327 /*! Function : GetString
1330 //============================================================================
1331 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1334 throw SALOMEDS::Study::StudyInvalidReference();
1336 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1339 //============================================================================
1340 /*! Function : IsReal
1343 //============================================================================
1344 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1347 throw SALOMEDS::Study::StudyInvalidReference();
1349 return _impl->IsTypeOf(std::string(theVarName),
1350 SALOMEDSImpl_GenericVariable::REAL_VAR);
1353 //============================================================================
1354 /*! Function : IsInteger
1357 //============================================================================
1358 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1361 throw SALOMEDS::Study::StudyInvalidReference();
1363 return _impl->IsTypeOf(std::string(theVarName),
1364 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1367 //============================================================================
1368 /*! Function : IsBoolean
1371 //============================================================================
1372 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1375 throw SALOMEDS::Study::StudyInvalidReference();
1377 return _impl->IsTypeOf(std::string(theVarName),
1378 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1381 //============================================================================
1382 /*! Function : IsString
1385 //============================================================================
1386 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1389 throw SALOMEDS::Study::StudyInvalidReference();
1391 return _impl->IsTypeOf(std::string(theVarName),
1392 SALOMEDSImpl_GenericVariable::STRING_VAR);
1395 //============================================================================
1396 /*! Function : IsVariable
1399 //============================================================================
1400 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1403 throw SALOMEDS::Study::StudyInvalidReference();
1405 return _impl->IsVariable(std::string(theVarName));
1408 //============================================================================
1409 /*! Function : GetVariableNames
1412 //============================================================================
1413 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1416 throw SALOMEDS::Study::StudyInvalidReference();
1418 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1420 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1422 int aLen = aVarNames.size();
1423 aResult->length(aLen);
1424 for (int anInd = 0; anInd < aLen; anInd++)
1425 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1427 return aResult._retn();
1430 //============================================================================
1431 /*! Function : RemoveVariable
1434 //============================================================================
1435 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1438 throw SALOMEDS::Study::StudyInvalidReference();
1440 bool res = _impl->RemoveVariable(std::string(theVarName));
1441 if (res && _notifier)
1442 _notifier->modifyNB_Notification(theVarName);
1447 //============================================================================
1448 /*! Function : RenameVariable
1451 //============================================================================
1452 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1455 throw SALOMEDS::Study::StudyInvalidReference();
1457 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1458 if (res && _notifier)
1459 _notifier->modifyNB_Notification(theVarName);
1464 //============================================================================
1465 /*! Function : IsVariableUsed
1468 //============================================================================
1469 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1472 throw SALOMEDS::Study::StudyInvalidReference();
1474 return _impl->IsVariableUsed(std::string(theVarName));
1478 //============================================================================
1479 /*! Function : ParseVariables
1482 //============================================================================
1483 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1486 throw SALOMEDS::Study::StudyInvalidReference();
1488 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1490 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1492 int aSectionsLen = aSections.size();
1493 aResult->length(aSectionsLen);
1495 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1496 std::vector<std::string> aVarNames = aSections[aSectionInd];
1498 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1500 int aLen = aVarNames.size();
1501 aList->length(aLen);
1503 for (int anInd = 0; anInd < aLen; anInd++)
1504 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1506 aResult[aSectionInd] = aList;
1509 return aResult._retn();
1512 //============================================================================
1513 /*! Function : GetDefaultScript
1516 //============================================================================
1517 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1519 SALOMEDS::Locker lock;
1522 throw SALOMEDS::Study::StudyInvalidReference();
1524 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1525 return CORBA::string_dup(script.c_str());
1528 //============================================================================
1529 /*! Function : EnableUseCaseAutoFilling
1532 //============================================================================
1533 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1536 throw SALOMEDS::Study::StudyInvalidReference();
1538 _impl->EnableUseCaseAutoFilling(isEnabled);
1539 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1542 builder->SetOnAddSObject(_impl->GetCallback());
1543 builder->SetOnRemoveSObject(_impl->GetCallback());
1546 builder->SetOnAddSObject(NULL);
1547 builder->SetOnRemoveSObject(NULL);
1553 CORBA::Long SALOMEDS_Study_i::getPID()
1556 return (CORBA::Long)_getpid();
1558 return (CORBA::Long)getpid();
1562 void SALOMEDS_Study_i::ShutdownWithExit()
1564 exit( EXIT_SUCCESS );
1567 void SALOMEDS_Study_i::Shutdown()
1569 if(!CORBA::is_nil(_orb))
1573 //============================================================================
1574 /*! Function : attach
1575 * Purpose : This function attach an observer to the study
1577 //============================================================================
1578 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1581 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1585 //============================================================================
1586 /*! Function : detach
1587 * Purpose : This function detaches an observer from the study
1589 //============================================================================
1590 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1593 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1596 //===========================================================================
1597 // PRIVATE FUNCTIONS
1598 //===========================================================================
1599 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1602 long pid = (long)_getpid();
1604 long pid = (long)getpid();
1606 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1607 return reinterpret_cast<CORBA::LongLong>(_impl);
1610 void SALOMEDS_Study_i::NameChanged()
1612 // Notify GUI that the name of study was changed
1613 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1614 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
1615 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1616 if ( !CORBA::is_nil(aSession) ) {
1617 std::stringstream ss;
1618 ss << "studyNameChanged";
1619 std::string str = ss.str();
1621 aSession->emitMessageOneWay(str.c_str());