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);
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");
405 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
406 bool res = _impl->Open(std::string(aUrl));
408 // update desktop title with new study name
410 SALOMEDS::sendMessageToGUI( "connect_to_study" );
413 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
417 PortableServer::POA_ptr SALOMEDS_Study_i::GetThePOA()
422 void SALOMEDS_Study_i::SetThePOA(PortableServer::POA_ptr thePOA)
424 _poa = PortableServer::POA::_duplicate(thePOA);
427 //============================================================================
429 * Purpose : Save a Study to it's persistent reference
431 //============================================================================
432 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
434 SALOMEDS::Locker lock;
436 throw SALOMEDS::Study::StudyInvalidReference();
437 return _impl->Save(_factory, theMultiFile, theASCII);
440 //=============================================================================
441 /*! Function : SaveAs
442 * Purpose : Save a study to the persistent reference aUrl
444 //============================================================================
445 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const wchar_t* aWUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
447 SALOMEDS::Locker lock;
449 throw SALOMEDS::Study::StudyInvalidReference();
451 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
452 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
455 //============================================================================
456 /*! Function : CanCopy
459 //============================================================================
460 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
462 SALOMEDS::Locker lock;
464 throw SALOMEDS::Study::StudyInvalidReference();
466 CORBA::String_var anID = theObject->GetID();
467 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
469 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
470 bool ret = _impl->CanCopy(anObject, aDriver);
475 //============================================================================
479 //============================================================================
480 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
482 SALOMEDS::Locker lock;
484 throw SALOMEDS::Study::StudyInvalidReference();
486 CORBA::String_var anID = theObject->GetID();
487 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
489 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
490 bool ret = _impl->Copy(anObject, aDriver);
495 //============================================================================
496 /*! Function : CanPaste
499 //============================================================================
500 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
502 SALOMEDS::Locker lock;
504 throw SALOMEDS::Study::StudyInvalidReference();
506 CORBA::String_var anID = theObject->GetID();
507 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
509 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
510 bool ret = _impl->CanPaste(anObject, aDriver);
515 //============================================================================
519 //============================================================================
520 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
521 throw(SALOMEDS::StudyBuilder::LockProtection)
523 SALOMEDS::Locker lock;
525 Unexpect aCatch(LockProtection);
527 CORBA::String_var anID = theObject->GetID();
528 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
529 SALOMEDSImpl_SObject aNewSO;
532 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
533 aNewSO = _impl->Paste(anObject, aDriver);
537 throw SALOMEDS::StudyBuilder::LockProtection();
540 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
544 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
546 SALOMEDS_Driver_i* driver = NULL;
548 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
550 std::string IOREngine = aSCO.GetIOR();
551 if(!IOREngine.empty()) {
552 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
553 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
554 driver = new SALOMEDS_Driver_i(Engine, orb);
561 //============================================================================
562 /*! Function : GetPersistentReference
563 * Purpose : Get persistent reference of study (idem URL())
565 //============================================================================
566 char* SALOMEDS_Study_i::GetPersistentReference()
568 SALOMEDS::Locker lock;
570 throw SALOMEDS::Study::StudyInvalidReference();
571 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
574 //============================================================================
575 /*! Function : IsEmpty
576 * Purpose : Detect if study is empty
578 //============================================================================
579 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
581 SALOMEDS::Locker lock;
583 throw SALOMEDS::Study::StudyInvalidReference();
584 return _impl->IsEmpty();
587 //============================================================================
588 /*! Function : FindComponent
589 * Purpose : Find a Component with ComponentDataType = aComponentName
591 //============================================================================
592 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
594 SALOMEDS::Locker lock;
597 throw SALOMEDS::Study::StudyInvalidReference();
599 SALOMEDS::SComponent_var sco;
601 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
602 if (!aCompImpl.IsNull())
603 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
608 //============================================================================
609 /*! Function : FindComponentID
610 * Purpose : Find a Component from it's ID
612 //============================================================================
613 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
615 SALOMEDS::Locker lock;
618 throw SALOMEDS::Study::StudyInvalidReference();
620 SALOMEDS::SComponent_var sco;
622 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
623 if (!aCompImpl.IsNull())
624 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
629 //============================================================================
630 /*! Function : FindObject
631 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
633 //============================================================================
634 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
636 SALOMEDS::Locker lock;
639 throw SALOMEDS::Study::StudyInvalidReference();
641 SALOMEDS::SObject_var so;
643 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
645 if (aSO.IsComponent()) {
646 SALOMEDSImpl_SComponent aSCO = aSO;
647 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
650 so = SALOMEDS_SObject_i::New(aSO, _orb);
657 //============================================================================
658 /*! Function : FindObjectID
659 * Purpose : Find an Object with ID = anObjectID
661 //============================================================================
662 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
664 SALOMEDS::Locker lock;
667 throw SALOMEDS::Study::StudyInvalidReference();
669 SALOMEDS::SObject_var so;
671 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
673 so = SALOMEDS_SObject_i::New(aSO, _orb);
678 //============================================================================
679 /*! Function : CreateObjectID
680 * Purpose : Creates an Object with ID = anObjectID
682 //============================================================================
683 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
685 SALOMEDS::Locker lock;
688 throw SALOMEDS::Study::StudyInvalidReference();
690 SALOMEDS::SObject_var so;
692 if (anObjectID && strlen(anObjectID) > 0) {
693 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
695 so = SALOMEDS_SObject_i::New(aSO, _orb);
701 //============================================================================
702 /*! Function : FindObjectByName
703 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
704 * : with ComponentDataType = aComponentName
706 //============================================================================
707 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
708 const char* aComponentName )
710 SALOMEDS::Locker lock;
713 throw SALOMEDS::Study::StudyInvalidReference();
715 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
716 std::string((char*)aComponentName));
718 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
719 int aLength = aSeq.size();
720 listSO->length(aLength);
721 for (int i = 0; i < aLength; i++) {
722 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
726 return listSO._retn();
729 //============================================================================
730 /*! Function : FindObjectIOR
731 * Purpose : Find an Object with IOR = anObjectIOR
733 //============================================================================
734 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
736 SALOMEDS::Locker lock;
739 throw SALOMEDS::Study::StudyInvalidReference();
741 SALOMEDS::SObject_var so;
743 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
745 so = SALOMEDS_SObject_i::New(aSO, _orb);
750 //============================================================================
751 /*! Function : FindObjectByPath
752 * Purpose : Find an Object by its path = thePath
754 //============================================================================
755 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
757 SALOMEDS::Locker lock;
760 throw SALOMEDS::Study::StudyInvalidReference();
762 SALOMEDS::SObject_var so;
764 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
766 so = SALOMEDS_SObject_i::New (aSO, _orb);
771 //============================================================================
772 /*! Function : GetObjectPath
775 //============================================================================
776 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
778 SALOMEDS::Locker lock;
781 throw SALOMEDS::Study::StudyInvalidReference();
783 std::string aPath = "";
785 if (!CORBA::is_nil(theObject)) {
786 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
787 SALOMEDSImpl_SObject aSO;
789 if (!CORBA::is_nil(aSObj)) {
790 aSO = _impl->FindObjectID(aSObj->GetID());
793 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
797 aPath = _impl->GetObjectPath(aSO);
801 return CORBA::string_dup(aPath.c_str());
804 //============================================================================
805 /*! Function : NewChildIterator
806 * Purpose : Create a ChildIterator from an SObject
808 //============================================================================
809 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
811 SALOMEDS::Locker lock;
814 throw SALOMEDS::Study::StudyInvalidReference();
816 CORBA::String_var anID = theSO->GetID();
817 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
818 SALOMEDSImpl_ChildIterator anItr(aSO);
819 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
820 SALOMEDS::ChildIterator_var it = it_servant->_this();
826 //============================================================================
827 /*! Function : NewComponentIterator
828 * Purpose : Create a SComponentIterator
830 //============================================================================
831 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
833 SALOMEDS::Locker lock;
836 throw SALOMEDS::Study::StudyInvalidReference();
838 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
840 SALOMEDS::SComponentIterator_var it = it_servant->_this();
846 //============================================================================
847 /*! Function : NewBuilder
848 * Purpose : Create a StudyBuilder
850 //============================================================================
851 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
853 SALOMEDS::Locker lock;
856 throw SALOMEDS::Study::StudyInvalidReference();
858 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
863 //============================================================================
865 * Purpose : get study name
867 //============================================================================
868 wchar_t* SALOMEDS_Study_i::Name()
870 SALOMEDS::Locker lock;
871 // Name is specified as IDL attribute: user exception cannot be raised
872 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->Name()));
875 //============================================================================
877 * Purpose : set study name
879 //============================================================================
880 void SALOMEDS_Study_i::Name(const wchar_t* wname)
882 SALOMEDS::Locker lock;
883 // Name is specified as IDL attribute: user exception cannot be raised
884 _impl->Name(Kernel_Utils::encode_s(wname));
887 //============================================================================
888 /*! Function : IsSaved
889 * Purpose : get if study has been saved
891 //============================================================================
892 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
894 SALOMEDS::Locker lock;
895 // IsSaved is specified as IDL attribute: user exception cannot be raised
896 return (!_closed) ? _impl->IsSaved() : false;
899 //============================================================================
900 /*! Function : IsSaved
901 * Purpose : set if study has been saved
903 //============================================================================
904 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
906 SALOMEDS::Locker lock;
907 // IsSaved is specified as IDL attribute: user exception cannot be raised
909 _impl->IsSaved(save);
912 //============================================================================
913 /*! Function : IsModified
914 * Purpose : Detect if a Study has been modified since it has been saved
916 //============================================================================
917 CORBA::Boolean SALOMEDS_Study_i::IsModified()
919 SALOMEDS::Locker lock;
922 throw SALOMEDS::Study::StudyInvalidReference();
924 return _impl->IsModified();
927 //============================================================================
928 /*! Function : Modified
929 * Purpose : Sets a Modified flag of a Study to True
931 //============================================================================
932 void SALOMEDS_Study_i::Modified()
934 SALOMEDS::Locker lock;
937 throw SALOMEDS::Study::StudyInvalidReference();
942 //============================================================================
944 * Purpose : get URL of the study (persistent reference of the study)
946 //============================================================================
947 wchar_t* SALOMEDS_Study_i::URL()
949 SALOMEDS::Locker lock;
950 // URL is specified as IDL attribute: user exception cannot be raised
951 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->URL()));
954 //============================================================================
956 * Purpose : set URL of the study (persistent reference of the study)
958 //============================================================================
959 void SALOMEDS_Study_i::URL(const wchar_t* wurl)
961 SALOMEDS::Locker lock;
962 // URL is specified as IDL attribute: user exception cannot be raised
963 _impl->URL(Kernel_Utils::encode_s(wurl));
965 // update desktop title with new study name
969 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
971 SALOMEDS::Locker lock;
974 throw SALOMEDS::Study::StudyInvalidReference();
976 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
979 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
981 SALOMEDS::Locker lock;
982 SALOMEDSImpl_Study::IORUpdated(theAttribute);
985 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
987 SALOMEDS::Locker lock;
990 throw SALOMEDS::Study::StudyInvalidReference();
992 SALOMEDS::GenericAttribute_ptr aTarget;
993 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
994 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
996 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
1002 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
1004 SALOMEDS::Locker lock;
1007 throw SALOMEDS::Study::StudyInvalidReference();
1009 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
1010 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
1011 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
1012 return aProp._retn();
1015 char* SALOMEDS_Study_i::GetLastModificationDate()
1017 SALOMEDS::Locker lock;
1020 throw SALOMEDS::Study::StudyInvalidReference();
1022 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
1025 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
1027 SALOMEDS::Locker lock;
1030 throw SALOMEDS::Study::StudyInvalidReference();
1032 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
1034 std::vector<std::string> aSeq = _impl->GetModificationsDate();
1036 int aLength = aSeq.size();
1037 aDates->length(aLength);
1038 for (int anIndex = 0; anIndex < aLength; anIndex++) {
1039 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1042 return aDates._retn();
1045 //============================================================================
1046 /*! Function : GetUseCaseBuilder
1047 * Purpose : Returns a UseCase builder
1049 //============================================================================
1050 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1052 SALOMEDS::Locker lock;
1055 throw SALOMEDS::Study::StudyInvalidReference();
1057 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1058 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1062 //============================================================================
1063 /*! Function : AddPostponed
1066 //============================================================================
1067 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1069 SALOMEDS::Locker lock;
1073 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1075 SALOMEDS::Locker lock;
1079 //============================================================================
1080 /*! Function : RemovePostponed
1083 //============================================================================
1084 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1086 SALOMEDS::Locker lock;
1089 throw SALOMEDS::Study::StudyInvalidReference();
1091 std::vector<std::string> anIORs = _impl->GetIORs();
1092 int i, aSize = (int)anIORs.size();
1094 for (i = 0; i < aSize; i++) {
1096 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1097 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1098 //rnv: To avoid double deletion of the Salome Generic Objects:
1099 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1100 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1101 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1108 //============================================================================
1109 /*! Function : UndoPostponed
1112 //============================================================================
1113 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1115 SALOMEDS::Locker lock;
1120 //============================================================================
1121 /*! Function : DumpStudy
1124 //============================================================================
1125 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1126 const char* theBaseName,
1127 CORBA::Boolean isPublished,
1128 CORBA::Boolean isMultiFile)
1130 SALOMEDS::Locker lock;
1133 throw SALOMEDS::Study::StudyInvalidReference();
1135 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1136 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1137 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1143 //============================================================================
1144 /*! Function : GetCommonParameters
1147 //============================================================================
1148 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1150 SALOMEDS::Locker lock;
1153 throw SALOMEDS::Study::StudyInvalidReference();
1155 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1156 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1157 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1159 return aParam._retn();
1162 //============================================================================
1163 /*! Function : GetCommonModuleParameters
1166 //============================================================================
1167 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1168 const char* theModuleName,
1169 CORBA::Long theSavePoint)
1171 SALOMEDS::Locker lock;
1174 throw SALOMEDS::Study::StudyInvalidReference();
1176 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1177 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1178 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1180 return aParam._retn();
1183 //============================================================================
1184 /*! Function : SetStudyLock
1187 //============================================================================
1188 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1190 SALOMEDS::Locker lock;
1193 throw SALOMEDS::Study::StudyInvalidReference();
1195 _impl->SetStudyLock(theLockerID);
1198 //============================================================================
1199 /*! Function : IsStudyLocked
1202 //============================================================================
1203 bool SALOMEDS_Study_i::IsStudyLocked()
1205 SALOMEDS::Locker lock;
1208 throw SALOMEDS::Study::StudyInvalidReference();
1210 return _impl->IsStudyLocked();
1213 //============================================================================
1214 /*! Function : UnLockStudy
1217 //============================================================================
1218 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1220 SALOMEDS::Locker lock;
1223 throw SALOMEDS::Study::StudyInvalidReference();
1225 _impl->UnLockStudy(theLockerID);
1228 //============================================================================
1229 /*! Function : GetLockerID
1232 //============================================================================
1233 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1235 SALOMEDS::Locker lock;
1238 throw SALOMEDS::Study::StudyInvalidReference();
1240 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1242 std::vector<std::string> aSeq = _impl->GetLockerID();
1244 int aLength = aSeq.size();
1245 aResult->length(aLength);
1246 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1247 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1250 return aResult._retn();
1252 //============================================================================
1253 /*! Function : SetReal
1256 //============================================================================
1257 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1260 throw SALOMEDS::Study::StudyInvalidReference();
1263 _impl->SetVariable(std::string(theVarName),
1265 SALOMEDSImpl_GenericVariable::REAL_VAR);
1267 _notifier->modifyNB_Notification(theVarName);
1270 //============================================================================
1271 /*! Function : SetInteger
1274 //============================================================================
1275 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1278 throw SALOMEDS::Study::StudyInvalidReference();
1280 _impl->SetVariable(std::string(theVarName),
1282 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1284 _notifier->modifyNB_Notification(theVarName);
1287 //============================================================================
1288 /*! Function : SetBoolean
1291 //============================================================================
1292 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1295 throw SALOMEDS::Study::StudyInvalidReference();
1297 _impl->SetVariable(std::string(theVarName),
1299 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1301 _notifier->modifyNB_Notification(theVarName);
1304 //============================================================================
1305 /*! Function : SetString
1308 //============================================================================
1309 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1312 throw SALOMEDS::Study::StudyInvalidReference();
1314 _impl->SetStringVariable(std::string(theVarName),
1316 SALOMEDSImpl_GenericVariable::STRING_VAR);
1318 _notifier->modifyNB_Notification(theVarName);
1321 //============================================================================
1322 /*! Function : SetStringAsDouble
1325 //============================================================================
1326 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1329 throw SALOMEDS::Study::StudyInvalidReference();
1331 _impl->SetStringVariableAsDouble(std::string(theVarName),
1333 SALOMEDSImpl_GenericVariable::STRING_VAR);
1336 //============================================================================
1337 /*! Function : GetReal
1340 //============================================================================
1341 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1344 throw SALOMEDS::Study::StudyInvalidReference();
1346 return _impl->GetVariableValue(std::string(theVarName));
1349 //============================================================================
1350 /*! Function : GetInteger
1353 //============================================================================
1354 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1357 throw SALOMEDS::Study::StudyInvalidReference();
1359 return (long)_impl->GetVariableValue(std::string(theVarName));
1362 //============================================================================
1363 /*! Function : GetBoolean
1366 //============================================================================
1367 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1370 throw SALOMEDS::Study::StudyInvalidReference();
1372 return (bool)_impl->GetVariableValue(std::string(theVarName));
1375 //============================================================================
1376 /*! Function : GetString
1379 //============================================================================
1380 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1383 throw SALOMEDS::Study::StudyInvalidReference();
1385 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1388 //============================================================================
1389 /*! Function : IsReal
1392 //============================================================================
1393 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1396 throw SALOMEDS::Study::StudyInvalidReference();
1398 return _impl->IsTypeOf(std::string(theVarName),
1399 SALOMEDSImpl_GenericVariable::REAL_VAR);
1402 //============================================================================
1403 /*! Function : IsInteger
1406 //============================================================================
1407 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1410 throw SALOMEDS::Study::StudyInvalidReference();
1412 return _impl->IsTypeOf(std::string(theVarName),
1413 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1416 //============================================================================
1417 /*! Function : IsBoolean
1420 //============================================================================
1421 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1424 throw SALOMEDS::Study::StudyInvalidReference();
1426 return _impl->IsTypeOf(std::string(theVarName),
1427 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1430 //============================================================================
1431 /*! Function : IsString
1434 //============================================================================
1435 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1438 throw SALOMEDS::Study::StudyInvalidReference();
1440 return _impl->IsTypeOf(std::string(theVarName),
1441 SALOMEDSImpl_GenericVariable::STRING_VAR);
1444 //============================================================================
1445 /*! Function : IsVariable
1448 //============================================================================
1449 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1452 throw SALOMEDS::Study::StudyInvalidReference();
1454 return _impl->IsVariable(std::string(theVarName));
1457 //============================================================================
1458 /*! Function : GetVariableNames
1461 //============================================================================
1462 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1465 throw SALOMEDS::Study::StudyInvalidReference();
1467 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1469 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1471 int aLen = aVarNames.size();
1472 aResult->length(aLen);
1473 for (int anInd = 0; anInd < aLen; anInd++)
1474 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1476 return aResult._retn();
1479 //============================================================================
1480 /*! Function : RemoveVariable
1483 //============================================================================
1484 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1487 throw SALOMEDS::Study::StudyInvalidReference();
1489 bool res = _impl->RemoveVariable(std::string(theVarName));
1490 if (res && _notifier)
1491 _notifier->modifyNB_Notification(theVarName);
1496 //============================================================================
1497 /*! Function : RenameVariable
1500 //============================================================================
1501 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1504 throw SALOMEDS::Study::StudyInvalidReference();
1506 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1507 if (res && _notifier)
1508 _notifier->modifyNB_Notification(theVarName);
1513 //============================================================================
1514 /*! Function : IsVariableUsed
1517 //============================================================================
1518 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1521 throw SALOMEDS::Study::StudyInvalidReference();
1523 return _impl->IsVariableUsed(std::string(theVarName));
1527 //============================================================================
1528 /*! Function : ParseVariables
1531 //============================================================================
1532 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1535 throw SALOMEDS::Study::StudyInvalidReference();
1537 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1539 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1541 int aSectionsLen = aSections.size();
1542 aResult->length(aSectionsLen);
1544 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1545 std::vector<std::string> aVarNames = aSections[aSectionInd];
1547 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1549 int aLen = aVarNames.size();
1550 aList->length(aLen);
1552 for (int anInd = 0; anInd < aLen; anInd++)
1553 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1555 aResult[aSectionInd] = aList;
1558 return aResult._retn();
1561 //============================================================================
1562 /*! Function : GetDefaultScript
1565 //============================================================================
1566 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1568 SALOMEDS::Locker lock;
1571 throw SALOMEDS::Study::StudyInvalidReference();
1573 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1574 return CORBA::string_dup(script.c_str());
1577 //============================================================================
1578 /*! Function : EnableUseCaseAutoFilling
1581 //============================================================================
1582 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1585 throw SALOMEDS::Study::StudyInvalidReference();
1587 _impl->EnableUseCaseAutoFilling(isEnabled);
1588 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1591 builder->SetOnAddSObject(_impl->GetCallback());
1592 builder->SetOnRemoveSObject(_impl->GetCallback());
1595 builder->SetOnAddSObject(NULL);
1596 builder->SetOnRemoveSObject(NULL);
1602 CORBA::Long SALOMEDS_Study_i::getPID()
1605 return (CORBA::Long)_getpid();
1607 return (CORBA::Long)getpid();
1611 void SALOMEDS_Study_i::ShutdownWithExit()
1613 exit( EXIT_SUCCESS );
1616 void SALOMEDS_Study_i::Shutdown()
1618 if(!CORBA::is_nil(_orb))
1622 //============================================================================
1623 /*! Function : attach
1624 * Purpose : This function attach an observer to the study
1626 //============================================================================
1627 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1630 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1634 //============================================================================
1635 /*! Function : detach
1636 * Purpose : This function detaches an observer from the study
1638 //============================================================================
1639 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1642 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1645 //===========================================================================
1646 // PRIVATE FUNCTIONS
1647 //===========================================================================
1648 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1651 long pid = (long)_getpid();
1653 long pid = (long)getpid();
1655 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1656 return reinterpret_cast<CORBA::LongLong>(_impl);
1659 void SALOMEDS_Study_i::NameChanged()
1661 SALOMEDS::sendMessageToGUI( "studyNameChanged" );