1 // Copyright (C) 2007-2019 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);
67 static PortableServer::POA_ptr _poa;
71 class Notifier: public SALOMEDSImpl_AbstractCallback
74 Notifier(CORBA::ORB_ptr orb)
76 _orb = CORBA::ORB::_duplicate(orb);
79 //============================================================================
80 /*! Function : addSO_Notification
81 * Purpose : This function tells all the observers that a SO has been added
83 //============================================================================
85 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
87 std::string anID=theSObject.GetID();
88 const char* cID=anID.c_str();
89 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
91 it->first->notifyObserverID(cID,1);
93 return true; // NGE return always true but can be modified if needed
96 //============================================================================
97 /*! Function : removeSO_Notification
98 * Purpose : This function tells all the observers that a SO has been removed
100 //============================================================================
102 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
104 std::string anID=theSObject.GetID();
105 const char* cID=anID.c_str();
106 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
108 it->first->notifyObserverID(cID,2);
110 return true; // NGE return always true but can be modified if needed
113 //============================================================================
114 /*! Function : modifySO_Notification
115 * Purpose : This function tells all the observers that a SO has been modified
117 //============================================================================
119 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
121 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
125 std::string anID=theSObject.GetID();
126 const char* cID=anID.c_str();
127 it->first->notifyObserverID(cID,reason);
130 return true; // NGE return always true but can be modified if needed
133 //============================================================================
134 /*! Function : modifyNB_Notification
135 * Purpose : This function tells all the observers that
136 * a NoteBook variable has been added/modified/removed.
138 //============================================================================
140 virtual bool modifyNB_Notification(const char* theVarName)
142 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
144 it->first->notifyObserverID(theVarName,6);
146 return true; // NGE return always true but can be modified if needed
149 //============================================================================
150 /*! Function : attach
151 * Purpose : register an Observer
153 //============================================================================
155 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
157 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
160 //============================================================================
161 /*! Function : detach
162 * Purpose : unregister an Observer
164 //============================================================================
166 virtual void detach(SALOMEDS::Observer_ptr theObs)
168 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
170 if ( it->first->_is_equivalent(theObs) ) {
171 myObservers.erase( it );
178 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
179 typedef ObsList::iterator ObsListIter;
184 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
187 GenObjRegister(CORBA::ORB_ptr orb)
189 _orb = CORBA::ORB::_duplicate(orb);
191 virtual void RegisterGenObj (const std::string& theIOR)
195 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
196 if ( obj->_non_existent() ) return;
197 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
198 if(! CORBA::is_nil(gobj) )
203 catch(const CORBA::Exception& e)
207 virtual void UnRegisterGenObj(const std::string& theIOR)
211 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
212 if ( obj->_non_existent() ) return;
213 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
214 if(! CORBA::is_nil(gobj) )
219 catch(const CORBA::Exception& e)
229 //================================================================================
231 * \brief emitMessageOneWay to SALOME::Session
233 //================================================================================
235 void sendMessageToGUI(const char* msg )
237 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
238 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
239 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
240 if ( !CORBA::is_nil(aSession) ) {
242 aSession->emitMessageOneWay( msg );
247 } // namespace SALOMEDS
249 //============================================================================
250 /*! Function : SALOMEDS_Study_i
251 * Purpose : SALOMEDS_Study_i constructor
253 //============================================================================
254 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
256 _orb = CORBA::ORB::_duplicate(orb);
257 _impl = new SALOMEDSImpl_Study();
258 _factory = new SALOMEDS_DriverFactory_i(_orb);
264 //============================================================================
265 /*! Function : ~SALOMEDS_Study_i
266 * Purpose : SALOMEDS_Study_i destructor
268 //============================================================================
269 SALOMEDS_Study_i::~SALOMEDS_Study_i()
276 //============================================================================
278 * Purpose : Initialize study components
280 //============================================================================
281 void SALOMEDS_Study_i::Init()
284 //throw SALOMEDS::Study::StudyInvalidReference();
287 SALOMEDS::Locker lock;
289 if ( !_impl->GetDocument() )
292 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
293 _notifier = new SALOMEDS::Notifier(_orb);
294 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
297 _impl->setNotifier(_notifier);
298 _impl->setGenObjRegister( _genObjRegister );
300 // Notify GUI that study was created
301 SALOMEDS::sendMessageToGUI( "studyCreated" );
303 // update desktop title with new study name
307 //============================================================================
309 * Purpose : Clear study components
311 //============================================================================
312 void SALOMEDS_Study_i::Clear()
317 SALOMEDS::Locker lock;
319 //delete the builder servant
320 PortableServer::POA_var poa=_default_POA();
321 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
322 poa->deactivate_object(anObjectId.in());
323 _builder->_remove_ref();
327 if (_impl->GetDocument()) {
328 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
329 for (; itcomponent->More(); itcomponent->Next()) {
330 SALOMEDS::SComponent_var sco = itcomponent->Value();
331 CORBA::String_var compodatatype=sco->ComponentDataType();
332 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
333 // if there is an associated Engine call its method for closing
334 CORBA::String_var IOREngine;
335 if (sco->ComponentIOR(IOREngine)) {
336 // we have found the associated engine to write the data
337 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
338 //_narrow can throw a corba exception
340 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
341 if (!CORBA::is_nil(obj)) {
342 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
343 if (!anEngine->_is_nil()) {
345 anEngine->Close(sco);
350 catch (CORBA::Exception&) {
356 //Does not need any more this iterator
357 itcomponent->UnRegister();
360 // Notify GUI that study is cleared
361 SALOMEDS::sendMessageToGUI( "studyCleared" );
364 _impl->setNotifier(0);
366 delete _genObjRegister;
372 //============================================================================
374 \brief Get default POA for the servant object.
376 This function is implicitly called from "_this()" function.
377 Default POA can be set via the constructor.
379 \return reference to the default POA for the servant
381 //============================================================================
382 PortableServer::POA_ptr SALOMEDS_Study_i::_default_POA()
384 PortableServer::POA_ptr poa = GetThePOA();
385 MESSAGE("SALOMEDS_Study_i::_default_POA: " << poa);
386 return PortableServer::POA::_duplicate(poa);
389 //============================================================================
391 * Purpose : Open a Study from it's persistent reference
393 //============================================================================
394 bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl)
395 throw(SALOME::SALOME_Exception)
400 SALOMEDS::Locker lock;
402 Unexpect aCatch(SalomeException);
403 MESSAGE("Begin of SALOMEDS_Study_i::Open");
404 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
405 bool res = _impl->Open( aUrl );
407 // update desktop title with new study name
409 SALOMEDS::sendMessageToGUI( "connect_to_study" );
412 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
416 //============================================================================
417 /*! Function : CanOpen
418 * Purpose : Check that a Study can be opened
420 //============================================================================
421 bool SALOMEDS_Study_i::CanOpen(const wchar_t* aWUrl)
423 SALOMEDS::Locker lock;
425 Unexpect aCatch(SalomeException);
426 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
428 return SALOMEDSImpl_Study().Open( aUrl );
431 PortableServer::POA_ptr SALOMEDS_Study_i::GetThePOA()
436 void SALOMEDS_Study_i::SetThePOA(PortableServer::POA_ptr thePOA)
438 _poa = PortableServer::POA::_duplicate(thePOA);
441 //============================================================================
443 * Purpose : Save a Study to it's persistent reference
445 //============================================================================
446 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
448 SALOMEDS::Locker lock;
450 throw SALOMEDS::Study::StudyInvalidReference();
451 return _impl->Save(_factory, theMultiFile, theASCII);
454 //=============================================================================
455 /*! Function : SaveAs
456 * Purpose : Save a study to the persistent reference aUrl
458 //============================================================================
459 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const wchar_t* aWUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
461 SALOMEDS::Locker lock;
463 throw SALOMEDS::Study::StudyInvalidReference();
465 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
466 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
469 //============================================================================
470 /*! Function : CanCopy
473 //============================================================================
474 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
476 SALOMEDS::Locker lock;
478 throw SALOMEDS::Study::StudyInvalidReference();
480 CORBA::String_var anID = theObject->GetID();
481 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
483 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
484 bool ret = _impl->CanCopy(anObject, aDriver);
489 //============================================================================
493 //============================================================================
494 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
496 SALOMEDS::Locker lock;
498 throw SALOMEDS::Study::StudyInvalidReference();
500 CORBA::String_var anID = theObject->GetID();
501 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
503 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
504 bool ret = _impl->Copy(anObject, aDriver);
509 //============================================================================
510 /*! Function : CanPaste
513 //============================================================================
514 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
516 SALOMEDS::Locker lock;
518 throw SALOMEDS::Study::StudyInvalidReference();
520 CORBA::String_var anID = theObject->GetID();
521 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
523 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
524 bool ret = _impl->CanPaste(anObject, aDriver);
529 //============================================================================
533 //============================================================================
534 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
535 throw(SALOMEDS::StudyBuilder::LockProtection)
537 SALOMEDS::Locker lock;
539 Unexpect aCatch(LockProtection);
541 CORBA::String_var anID = theObject->GetID();
542 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
543 SALOMEDSImpl_SObject aNewSO;
546 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
547 aNewSO = _impl->Paste(anObject, aDriver);
551 throw SALOMEDS::StudyBuilder::LockProtection();
554 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
558 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
560 SALOMEDS_Driver_i* driver = NULL;
562 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
564 std::string IOREngine = aSCO.GetIOR();
565 if(!IOREngine.empty()) {
566 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
567 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
568 driver = new SALOMEDS_Driver_i(Engine, orb);
575 //============================================================================
576 /*! Function : GetPersistentReference
577 * Purpose : Get persistent reference of study (idem URL())
579 //============================================================================
580 char* SALOMEDS_Study_i::GetPersistentReference()
582 SALOMEDS::Locker lock;
584 throw SALOMEDS::Study::StudyInvalidReference();
585 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
588 //============================================================================
589 /*! Function : IsEmpty
590 * Purpose : Detect if study is empty
592 //============================================================================
593 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
595 SALOMEDS::Locker lock;
597 throw SALOMEDS::Study::StudyInvalidReference();
598 return _impl->IsEmpty();
601 //============================================================================
602 /*! Function : FindComponent
603 * Purpose : Find a Component with ComponentDataType = aComponentName
605 //============================================================================
606 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
608 SALOMEDS::Locker lock;
611 throw SALOMEDS::Study::StudyInvalidReference();
613 SALOMEDS::SComponent_var sco;
615 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
616 if (!aCompImpl.IsNull())
617 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
622 //============================================================================
623 /*! Function : FindComponentID
624 * Purpose : Find a Component from it's ID
626 //============================================================================
627 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
629 SALOMEDS::Locker lock;
632 throw SALOMEDS::Study::StudyInvalidReference();
634 SALOMEDS::SComponent_var sco;
636 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
637 if (!aCompImpl.IsNull())
638 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
643 //============================================================================
644 /*! Function : FindObject
645 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
647 //============================================================================
648 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
650 SALOMEDS::Locker lock;
653 throw SALOMEDS::Study::StudyInvalidReference();
655 SALOMEDS::SObject_var so;
657 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
659 if (aSO.IsComponent()) {
660 SALOMEDSImpl_SComponent aSCO = aSO;
661 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
664 so = SALOMEDS_SObject_i::New(aSO, _orb);
671 //============================================================================
672 /*! Function : FindObjectID
673 * Purpose : Find an Object with ID = anObjectID
675 //============================================================================
676 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
678 SALOMEDS::Locker lock;
681 throw SALOMEDS::Study::StudyInvalidReference();
683 SALOMEDS::SObject_var so;
685 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
687 so = SALOMEDS_SObject_i::New(aSO, _orb);
692 //============================================================================
693 /*! Function : CreateObjectID
694 * Purpose : Creates an Object with ID = anObjectID
696 //============================================================================
697 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
699 SALOMEDS::Locker lock;
702 throw SALOMEDS::Study::StudyInvalidReference();
704 SALOMEDS::SObject_var so;
706 if (anObjectID && strlen(anObjectID) > 0) {
707 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
709 so = SALOMEDS_SObject_i::New(aSO, _orb);
715 //============================================================================
716 /*! Function : FindObjectByName
717 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
718 * : with ComponentDataType = aComponentName
720 //============================================================================
721 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
722 const char* aComponentName )
724 SALOMEDS::Locker lock;
727 throw SALOMEDS::Study::StudyInvalidReference();
729 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
730 std::string((char*)aComponentName));
732 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
733 int aLength = aSeq.size();
734 listSO->length(aLength);
735 for (int i = 0; i < aLength; i++) {
736 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
740 return listSO._retn();
743 //============================================================================
744 /*! Function : FindObjectIOR
745 * Purpose : Find an Object with IOR = anObjectIOR
747 //============================================================================
748 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
750 SALOMEDS::Locker lock;
753 throw SALOMEDS::Study::StudyInvalidReference();
755 SALOMEDS::SObject_var so;
757 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
759 so = SALOMEDS_SObject_i::New(aSO, _orb);
764 //============================================================================
765 /*! Function : FindObjectByPath
766 * Purpose : Find an Object by its path = thePath
768 //============================================================================
769 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
771 SALOMEDS::Locker lock;
774 throw SALOMEDS::Study::StudyInvalidReference();
776 SALOMEDS::SObject_var so;
778 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
780 so = SALOMEDS_SObject_i::New (aSO, _orb);
785 //============================================================================
786 /*! Function : GetObjectPath
789 //============================================================================
790 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
792 SALOMEDS::Locker lock;
795 throw SALOMEDS::Study::StudyInvalidReference();
797 std::string aPath = "";
799 if (!CORBA::is_nil(theObject)) {
800 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
801 SALOMEDSImpl_SObject aSO;
803 if (!CORBA::is_nil(aSObj)) {
804 aSO = _impl->FindObjectID(aSObj->GetID());
807 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
811 aPath = _impl->GetObjectPath(aSO);
815 return CORBA::string_dup(aPath.c_str());
818 //============================================================================
819 /*! Function : NewChildIterator
820 * Purpose : Create a ChildIterator from an SObject
822 //============================================================================
823 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
825 SALOMEDS::Locker lock;
828 throw SALOMEDS::Study::StudyInvalidReference();
830 CORBA::String_var anID = theSO->GetID();
831 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
832 SALOMEDSImpl_ChildIterator anItr(aSO);
833 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
834 SALOMEDS::ChildIterator_var it = it_servant->_this();
840 //============================================================================
841 /*! Function : NewComponentIterator
842 * Purpose : Create a SComponentIterator
844 //============================================================================
845 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
847 SALOMEDS::Locker lock;
850 throw SALOMEDS::Study::StudyInvalidReference();
852 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
854 SALOMEDS::SComponentIterator_var it = it_servant->_this();
860 //============================================================================
861 /*! Function : NewBuilder
862 * Purpose : Create a StudyBuilder
864 //============================================================================
865 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
867 SALOMEDS::Locker lock;
870 throw SALOMEDS::Study::StudyInvalidReference();
872 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
877 //============================================================================
879 * Purpose : get study name
881 //============================================================================
882 wchar_t* SALOMEDS_Study_i::Name()
884 SALOMEDS::Locker lock;
885 // Name is specified as IDL attribute: user exception cannot be raised
886 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->Name()));
889 //============================================================================
891 * Purpose : set study name
893 //============================================================================
894 void SALOMEDS_Study_i::Name(const wchar_t* wname)
896 SALOMEDS::Locker lock;
897 // Name is specified as IDL attribute: user exception cannot be raised
898 _impl->Name(Kernel_Utils::encode_s(wname));
901 //============================================================================
902 /*! Function : IsSaved
903 * Purpose : get if study has been saved
905 //============================================================================
906 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
908 SALOMEDS::Locker lock;
909 // IsSaved is specified as IDL attribute: user exception cannot be raised
910 return (!_closed) ? _impl->IsSaved() : false;
913 //============================================================================
914 /*! Function : IsSaved
915 * Purpose : set if study has been saved
917 //============================================================================
918 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
920 SALOMEDS::Locker lock;
921 // IsSaved is specified as IDL attribute: user exception cannot be raised
923 _impl->IsSaved(save);
926 //============================================================================
927 /*! Function : IsModified
928 * Purpose : Detect if a Study has been modified since it has been saved
930 //============================================================================
931 CORBA::Boolean SALOMEDS_Study_i::IsModified()
933 SALOMEDS::Locker lock;
936 throw SALOMEDS::Study::StudyInvalidReference();
938 return _impl->IsModified();
941 //============================================================================
942 /*! Function : Modified
943 * Purpose : Sets a Modified flag of a Study to True
945 //============================================================================
946 void SALOMEDS_Study_i::Modified()
948 SALOMEDS::Locker lock;
951 throw SALOMEDS::Study::StudyInvalidReference();
956 //============================================================================
958 * Purpose : get URL of the study (persistent reference of the study)
960 //============================================================================
961 wchar_t* SALOMEDS_Study_i::URL()
963 SALOMEDS::Locker lock;
964 // URL is specified as IDL attribute: user exception cannot be raised
965 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->URL()));
968 //============================================================================
970 * Purpose : set URL of the study (persistent reference of the study)
972 //============================================================================
973 void SALOMEDS_Study_i::URL(const wchar_t* wurl)
975 SALOMEDS::Locker lock;
976 // URL is specified as IDL attribute: user exception cannot be raised
977 _impl->URL(Kernel_Utils::encode_s(wurl));
979 // update desktop title with new study name
983 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
985 SALOMEDS::Locker lock;
988 throw SALOMEDS::Study::StudyInvalidReference();
990 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
993 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
995 SALOMEDS::Locker lock;
996 SALOMEDSImpl_Study::IORUpdated(theAttribute);
999 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
1001 SALOMEDS::Locker lock;
1004 throw SALOMEDS::Study::StudyInvalidReference();
1006 SALOMEDS::GenericAttribute_ptr aTarget;
1007 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
1008 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
1010 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
1016 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
1018 SALOMEDS::Locker lock;
1021 throw SALOMEDS::Study::StudyInvalidReference();
1023 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
1024 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
1025 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
1026 return aProp._retn();
1029 char* SALOMEDS_Study_i::GetLastModificationDate()
1031 SALOMEDS::Locker lock;
1034 throw SALOMEDS::Study::StudyInvalidReference();
1036 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
1039 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
1041 SALOMEDS::Locker lock;
1044 throw SALOMEDS::Study::StudyInvalidReference();
1046 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
1048 std::vector<std::string> aSeq = _impl->GetModificationsDate();
1050 int aLength = aSeq.size();
1051 aDates->length(aLength);
1052 for (int anIndex = 0; anIndex < aLength; anIndex++) {
1053 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1056 return aDates._retn();
1059 //============================================================================
1060 /*! Function : GetUseCaseBuilder
1061 * Purpose : Returns a UseCase builder
1063 //============================================================================
1064 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1066 SALOMEDS::Locker lock;
1069 throw SALOMEDS::Study::StudyInvalidReference();
1071 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1072 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1076 //============================================================================
1077 /*! Function : AddPostponed
1080 //============================================================================
1081 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1083 SALOMEDS::Locker lock;
1087 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1089 SALOMEDS::Locker lock;
1093 //============================================================================
1094 /*! Function : RemovePostponed
1097 //============================================================================
1098 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1100 SALOMEDS::Locker lock;
1103 throw SALOMEDS::Study::StudyInvalidReference();
1105 std::vector<std::string> anIORs = _impl->GetIORs();
1106 int i, aSize = (int)anIORs.size();
1108 for (i = 0; i < aSize; i++) {
1110 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1111 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1112 //rnv: To avoid double deletion of the Salome Generic Objects:
1113 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1114 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1115 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1122 //============================================================================
1123 /*! Function : UndoPostponed
1126 //============================================================================
1127 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1129 SALOMEDS::Locker lock;
1134 //============================================================================
1135 /*! Function : DumpStudy
1138 //============================================================================
1139 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1140 const char* theBaseName,
1141 CORBA::Boolean isPublished,
1142 CORBA::Boolean isMultiFile)
1144 SALOMEDS::Locker lock;
1147 throw SALOMEDS::Study::StudyInvalidReference();
1149 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1150 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1151 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1157 //============================================================================
1158 /*! Function : GetDumpPath
1161 //============================================================================
1162 char* SALOMEDS_Study_i::GetDumpPath()
1164 return CORBA::string_dup(_impl->GetDumpPath().c_str());
1167 //============================================================================
1168 /*! Function : GetCommonParameters
1171 //============================================================================
1172 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1174 SALOMEDS::Locker lock;
1177 throw SALOMEDS::Study::StudyInvalidReference();
1179 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1180 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1181 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1183 return aParam._retn();
1186 //============================================================================
1187 /*! Function : GetCommonModuleParameters
1190 //============================================================================
1191 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1192 const char* theModuleName,
1193 CORBA::Long theSavePoint)
1195 SALOMEDS::Locker lock;
1198 throw SALOMEDS::Study::StudyInvalidReference();
1200 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1201 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1202 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1204 return aParam._retn();
1207 //============================================================================
1208 /*! Function : SetStudyLock
1211 //============================================================================
1212 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1214 SALOMEDS::Locker lock;
1217 throw SALOMEDS::Study::StudyInvalidReference();
1219 _impl->SetStudyLock(theLockerID);
1222 //============================================================================
1223 /*! Function : IsStudyLocked
1226 //============================================================================
1227 bool SALOMEDS_Study_i::IsStudyLocked()
1229 SALOMEDS::Locker lock;
1232 throw SALOMEDS::Study::StudyInvalidReference();
1234 return _impl->IsStudyLocked();
1237 //============================================================================
1238 /*! Function : UnLockStudy
1241 //============================================================================
1242 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1244 SALOMEDS::Locker lock;
1247 throw SALOMEDS::Study::StudyInvalidReference();
1249 _impl->UnLockStudy(theLockerID);
1252 //============================================================================
1253 /*! Function : GetLockerID
1256 //============================================================================
1257 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1259 SALOMEDS::Locker lock;
1262 throw SALOMEDS::Study::StudyInvalidReference();
1264 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1266 std::vector<std::string> aSeq = _impl->GetLockerID();
1268 int aLength = aSeq.size();
1269 aResult->length(aLength);
1270 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1271 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1274 return aResult._retn();
1276 //============================================================================
1277 /*! Function : SetReal
1280 //============================================================================
1281 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1284 throw SALOMEDS::Study::StudyInvalidReference();
1287 _impl->SetVariable(std::string(theVarName),
1289 SALOMEDSImpl_GenericVariable::REAL_VAR);
1291 _notifier->modifyNB_Notification(theVarName);
1294 //============================================================================
1295 /*! Function : SetInteger
1298 //============================================================================
1299 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1302 throw SALOMEDS::Study::StudyInvalidReference();
1304 _impl->SetVariable(std::string(theVarName),
1306 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1308 _notifier->modifyNB_Notification(theVarName);
1311 //============================================================================
1312 /*! Function : SetBoolean
1315 //============================================================================
1316 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1319 throw SALOMEDS::Study::StudyInvalidReference();
1321 _impl->SetVariable(std::string(theVarName),
1323 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1325 _notifier->modifyNB_Notification(theVarName);
1328 //============================================================================
1329 /*! Function : SetString
1332 //============================================================================
1333 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1336 throw SALOMEDS::Study::StudyInvalidReference();
1338 _impl->SetStringVariable(std::string(theVarName),
1340 SALOMEDSImpl_GenericVariable::STRING_VAR);
1342 _notifier->modifyNB_Notification(theVarName);
1345 //============================================================================
1346 /*! Function : SetStringAsDouble
1349 //============================================================================
1350 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1353 throw SALOMEDS::Study::StudyInvalidReference();
1355 _impl->SetStringVariableAsDouble(std::string(theVarName),
1357 SALOMEDSImpl_GenericVariable::STRING_VAR);
1360 //============================================================================
1361 /*! Function : GetReal
1364 //============================================================================
1365 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1368 throw SALOMEDS::Study::StudyInvalidReference();
1370 return _impl->GetVariableValue(std::string(theVarName));
1373 //============================================================================
1374 /*! Function : GetInteger
1377 //============================================================================
1378 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1381 throw SALOMEDS::Study::StudyInvalidReference();
1383 return (long)_impl->GetVariableValue(std::string(theVarName));
1386 //============================================================================
1387 /*! Function : GetBoolean
1390 //============================================================================
1391 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1394 throw SALOMEDS::Study::StudyInvalidReference();
1396 return (bool)_impl->GetVariableValue(std::string(theVarName));
1399 //============================================================================
1400 /*! Function : GetString
1403 //============================================================================
1404 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1407 throw SALOMEDS::Study::StudyInvalidReference();
1409 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1412 //============================================================================
1413 /*! Function : IsReal
1416 //============================================================================
1417 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1420 throw SALOMEDS::Study::StudyInvalidReference();
1422 return _impl->IsTypeOf(std::string(theVarName),
1423 SALOMEDSImpl_GenericVariable::REAL_VAR);
1426 //============================================================================
1427 /*! Function : IsInteger
1430 //============================================================================
1431 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1434 throw SALOMEDS::Study::StudyInvalidReference();
1436 return _impl->IsTypeOf(std::string(theVarName),
1437 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1440 //============================================================================
1441 /*! Function : IsBoolean
1444 //============================================================================
1445 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1448 throw SALOMEDS::Study::StudyInvalidReference();
1450 return _impl->IsTypeOf(std::string(theVarName),
1451 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1454 //============================================================================
1455 /*! Function : IsString
1458 //============================================================================
1459 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1462 throw SALOMEDS::Study::StudyInvalidReference();
1464 return _impl->IsTypeOf(std::string(theVarName),
1465 SALOMEDSImpl_GenericVariable::STRING_VAR);
1468 //============================================================================
1469 /*! Function : IsVariable
1472 //============================================================================
1473 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1476 throw SALOMEDS::Study::StudyInvalidReference();
1478 return _impl->IsVariable(std::string(theVarName));
1481 //============================================================================
1482 /*! Function : GetVariableNames
1485 //============================================================================
1486 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1489 throw SALOMEDS::Study::StudyInvalidReference();
1491 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1493 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1495 int aLen = aVarNames.size();
1496 aResult->length(aLen);
1497 for (int anInd = 0; anInd < aLen; anInd++)
1498 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1500 return aResult._retn();
1503 //============================================================================
1504 /*! Function : RemoveVariable
1507 //============================================================================
1508 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1511 throw SALOMEDS::Study::StudyInvalidReference();
1513 bool res = _impl->RemoveVariable(std::string(theVarName));
1514 if (res && _notifier)
1515 _notifier->modifyNB_Notification(theVarName);
1520 //============================================================================
1521 /*! Function : RenameVariable
1524 //============================================================================
1525 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1528 throw SALOMEDS::Study::StudyInvalidReference();
1530 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1531 if (res && _notifier)
1532 _notifier->modifyNB_Notification(theVarName);
1537 //============================================================================
1538 /*! Function : IsVariableUsed
1541 //============================================================================
1542 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1545 throw SALOMEDS::Study::StudyInvalidReference();
1547 return _impl->IsVariableUsed(std::string(theVarName));
1551 //============================================================================
1552 /*! Function : ParseVariables
1555 //============================================================================
1556 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1559 throw SALOMEDS::Study::StudyInvalidReference();
1561 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1563 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1565 int aSectionsLen = aSections.size();
1566 aResult->length(aSectionsLen);
1568 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1569 std::vector<std::string> aVarNames = aSections[aSectionInd];
1571 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1573 int aLen = aVarNames.size();
1574 aList->length(aLen);
1576 for (int anInd = 0; anInd < aLen; anInd++)
1577 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1579 aResult[aSectionInd] = aList;
1582 return aResult._retn();
1585 //============================================================================
1586 /*! Function : GetDefaultScript
1589 //============================================================================
1590 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1592 SALOMEDS::Locker lock;
1595 throw SALOMEDS::Study::StudyInvalidReference();
1597 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1598 return CORBA::string_dup(script.c_str());
1601 //============================================================================
1602 /*! Function : EnableUseCaseAutoFilling
1605 //============================================================================
1606 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1609 throw SALOMEDS::Study::StudyInvalidReference();
1611 _impl->EnableUseCaseAutoFilling(isEnabled);
1612 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1615 builder->SetOnAddSObject(_impl->GetCallback());
1616 builder->SetOnRemoveSObject(_impl->GetCallback());
1619 builder->SetOnAddSObject(NULL);
1620 builder->SetOnRemoveSObject(NULL);
1626 CORBA::Long SALOMEDS_Study_i::getPID()
1629 return (CORBA::Long)_getpid();
1631 return (CORBA::Long)getpid();
1635 void SALOMEDS_Study_i::ShutdownWithExit()
1637 exit( EXIT_SUCCESS );
1640 void SALOMEDS_Study_i::Shutdown()
1642 if(!CORBA::is_nil(_orb))
1644 _closed = true; // force 'closed' flag to avoid terminating
1647 //============================================================================
1648 /*! Function : attach
1649 * Purpose : This function attach an observer to the study
1651 //============================================================================
1652 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1655 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1659 //============================================================================
1660 /*! Function : detach
1661 * Purpose : This function detaches an observer from the study
1663 //============================================================================
1664 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1667 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1670 //===========================================================================
1671 // PRIVATE FUNCTIONS
1672 //===========================================================================
1673 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1676 long pid = (long)_getpid();
1678 long pid = (long)getpid();
1680 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1681 return reinterpret_cast<CORBA::LongLong>(_impl);
1684 void SALOMEDS_Study_i::NameChanged()
1686 SALOMEDS::sendMessageToGUI( "studyNameChanged" );