1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDS_Study_i.cxx
24 // Author : Sergey RUIN
27 #include "utilities.h"
29 #include "SALOMEDS_Study_i.hxx"
30 #include "SALOMEDS_UseCaseIterator_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
33 #include "SALOMEDS_AttributeParameter_i.hxx"
34 #include "SALOMEDS_ChildIterator_i.hxx"
35 #include "SALOMEDS_Driver_i.hxx"
36 #include "SALOMEDS.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
41 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
42 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "SALOMEDSImpl_Callback.hxx"
47 #include "DF_Label.hxx"
48 #include "DF_Attribute.hxx"
50 #include "Utils_ExceptHandlers.hxx"
52 #include "Basics_Utils.hxx"
53 #include "SALOME_KernelServices.hxx"
58 #include <sys/types.h>
62 UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
63 UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
65 static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
69 class Notifier: public SALOMEDSImpl_AbstractCallback
72 Notifier(CORBA::ORB_ptr orb)
74 _orb = CORBA::ORB::_duplicate(orb);
77 //============================================================================
78 /*! Function : addSO_Notification
79 * Purpose : This function tells all the observers that a SO has been added
81 //============================================================================
83 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
85 std::string anID=theSObject.GetID();
86 const char* cID=anID.c_str();
87 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
89 it->first->notifyObserverID(cID,1);
91 return true; // NGE return always true but can be modified if needed
94 //============================================================================
95 /*! Function : removeSO_Notification
96 * Purpose : This function tells all the observers that a SO has been removed
98 //============================================================================
100 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
102 std::string anID=theSObject.GetID();
103 const char* cID=anID.c_str();
104 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
106 it->first->notifyObserverID(cID,2);
108 return true; // NGE return always true but can be modified if needed
111 //============================================================================
112 /*! Function : modifySO_Notification
113 * Purpose : This function tells all the observers that a SO has been modified
115 //============================================================================
117 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
119 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
123 std::string anID=theSObject.GetID();
124 const char* cID=anID.c_str();
125 it->first->notifyObserverID(cID,reason);
128 return true; // NGE return always true but can be modified if needed
131 //============================================================================
132 /*! Function : modifyNB_Notification
133 * Purpose : This function tells all the observers that
134 * a NoteBook variable has been added/modified/removed.
136 //============================================================================
138 virtual bool modifyNB_Notification(const char* theVarName)
140 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
142 it->first->notifyObserverID(theVarName,6);
144 return true; // NGE return always true but can be modified if needed
147 //============================================================================
148 /*! Function : attach
149 * Purpose : register an Observer
151 //============================================================================
153 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
155 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
158 //============================================================================
159 /*! Function : detach
160 * Purpose : unregister an Observer
162 //============================================================================
164 virtual void detach(SALOMEDS::Observer_ptr theObs)
166 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
168 if ( it->first->_is_equivalent(theObs) ) {
169 myObservers.erase( it );
176 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
177 typedef ObsList::iterator ObsListIter;
182 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
185 GenObjRegister(CORBA::ORB_ptr orb)
187 _orb = CORBA::ORB::_duplicate(orb);
189 virtual void RegisterGenObj (const std::string& theIOR)
193 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
194 if ( obj->_non_existent() ) return;
195 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
196 if(! CORBA::is_nil(gobj) )
201 catch(const CORBA::Exception& e)
205 virtual void UnRegisterGenObj(const std::string& theIOR)
209 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
210 if ( obj->_non_existent() ) return;
211 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
212 if(! CORBA::is_nil(gobj) )
217 catch(const CORBA::Exception& e)
226 } // namespace SALOMEDS
228 //============================================================================
229 /*! Function : SALOMEDS_Study_i
230 * Purpose : SALOMEDS_Study_i constructor
232 //============================================================================
233 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
235 _orb = CORBA::ORB::_duplicate(orb);
236 _impl = new SALOMEDSImpl_Study();
237 _factory = new SALOMEDS_DriverFactory_i(_orb);
243 //============================================================================
244 /*! Function : ~SALOMEDS_Study_i
245 * Purpose : SALOMEDS_Study_i destructor
247 //============================================================================
248 SALOMEDS_Study_i::~SALOMEDS_Study_i()
255 //============================================================================
257 * Purpose : Initialize study components
259 //============================================================================
260 void SALOMEDS_Study_i::Init()
262 if ( !_impl->GetDocument() )
266 throw SALOMEDS::Study::StudyInvalidReference();
268 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
269 _notifier = new SALOMEDS::Notifier(_orb);
270 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
273 _impl->setNotifier(_notifier);
274 _impl->setGenObjRegister( _genObjRegister );
276 // update desktop title with new study name
279 // Notify GUI that study was created
280 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
281 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
282 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
283 if ( !CORBA::is_nil(aSession) ) {
284 std::stringstream ss;
285 ss << "studyCreated";
286 std::string str = ss.str();
288 aSession->emitMessageOneWay(str.c_str());
292 std::string anIOR = _impl->GetTransientReference();
293 if ( anIOR.empty() ) {
294 CORBA::Object_var obj = aNamingService->Resolve("/Study");
295 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( obj );
296 CORBA::String_var IORStudy = _orb->object_to_string(aStudy);
297 _impl->SetTransientReference((char*)IORStudy.in());
299 _impl->GetDocument()->SetModified(false);
303 //============================================================================
305 * Purpose : Clear study components
307 //============================================================================
308 void SALOMEDS_Study_i::Clear()
310 SALOMEDS::Locker lock;
313 //delete the builder servant
314 PortableServer::POA_var poa=_builder->_default_POA();
315 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
316 poa->deactivate_object(anObjectId.in());
317 _builder->_remove_ref();
321 if (_impl->GetDocument()) {
322 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
323 for (; itcomponent->More(); itcomponent->Next()) {
324 SALOMEDS::SComponent_var sco = itcomponent->Value();
325 CORBA::String_var compodatatype=sco->ComponentDataType();
326 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
327 // if there is an associated Engine call its method for closing
328 CORBA::String_var IOREngine;
329 if (sco->ComponentIOR(IOREngine)) {
330 // we have found the associated engine to write the data
331 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
332 //_narrow can throw a corba exception
334 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
335 if (!CORBA::is_nil(obj)) {
336 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
337 if (!anEngine->_is_nil()) {
339 anEngine->Close(sco);
344 catch (CORBA::Exception&) {
350 //Does not need any more this iterator
351 itcomponent->UnRegister();
354 // Notify GUI that study is cleared
355 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
356 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
357 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
358 if ( !CORBA::is_nil(aSession) ) {
359 std::stringstream ss;
360 ss << "studyCleared";
361 std::string str = ss.str();
363 aSession->emitMessageOneWay(str.c_str());
368 _impl->setNotifier(0);
370 delete _genObjRegister;
376 //============================================================================
378 * Purpose : Open a Study from it's persistent reference
380 //============================================================================
381 bool SALOMEDS_Study_i::Open(const char* aUrl)
382 throw(SALOME::SALOME_Exception)
387 SALOMEDS::Locker lock;
389 Unexpect aCatch(SalomeException);
390 MESSAGE("Begin of SALOMEDS_Study_i::Open");
392 bool res = _impl->Open(std::string(aUrl));
394 // update desktop title with new study name
398 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
402 //============================================================================
404 * Purpose : Save a Study to it's persistent reference
406 //============================================================================
407 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
409 SALOMEDS::Locker lock;
411 throw SALOMEDS::Study::StudyInvalidReference();
412 return _impl->Save(_factory, theMultiFile, theASCII);
415 //=============================================================================
416 /*! Function : SaveAs
417 * Purpose : Save a study to the persistent reference aUrl
419 //============================================================================
420 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
422 SALOMEDS::Locker lock;
424 throw SALOMEDS::Study::StudyInvalidReference();
425 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
428 //============================================================================
429 /*! Function : CanCopy
432 //============================================================================
433 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
435 SALOMEDS::Locker lock;
437 throw SALOMEDS::Study::StudyInvalidReference();
439 CORBA::String_var anID = theObject->GetID();
440 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
442 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
443 bool ret = _impl->CanCopy(anObject, aDriver);
448 //============================================================================
452 //============================================================================
453 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
455 SALOMEDS::Locker lock;
457 throw SALOMEDS::Study::StudyInvalidReference();
459 CORBA::String_var anID = theObject->GetID();
460 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
462 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
463 bool ret = _impl->Copy(anObject, aDriver);
468 //============================================================================
469 /*! Function : CanPaste
472 //============================================================================
473 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
475 SALOMEDS::Locker lock;
477 throw SALOMEDS::Study::StudyInvalidReference();
479 CORBA::String_var anID = theObject->GetID();
480 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
482 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
483 bool ret = _impl->CanPaste(anObject, aDriver);
488 //============================================================================
492 //============================================================================
493 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
494 throw(SALOMEDS::StudyBuilder::LockProtection)
496 SALOMEDS::Locker lock;
498 Unexpect aCatch(LockProtection);
500 CORBA::String_var anID = theObject->GetID();
501 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
502 SALOMEDSImpl_SObject aNewSO;
505 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
506 aNewSO = _impl->Paste(anObject, aDriver);
510 throw SALOMEDS::StudyBuilder::LockProtection();
513 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
517 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
519 SALOMEDS_Driver_i* driver = NULL;
521 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
523 std::string IOREngine = aSCO.GetIOR();
524 if(!IOREngine.empty()) {
525 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
526 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
527 driver = new SALOMEDS_Driver_i(Engine, orb);
534 //============================================================================
535 /*! Function : GetPersistentReference
536 * Purpose : Get persistent reference of study (idem URL())
538 //============================================================================
539 char* SALOMEDS_Study_i::GetPersistentReference()
541 SALOMEDS::Locker lock;
543 throw SALOMEDS::Study::StudyInvalidReference();
544 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
546 //============================================================================
547 /*! Function : GetTransientReference
548 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
550 //============================================================================
551 char* SALOMEDS_Study_i::GetTransientReference()
553 SALOMEDS::Locker lock;
555 throw SALOMEDS::Study::StudyInvalidReference();
556 return CORBA::string_dup(_impl->GetTransientReference().c_str());
559 //============================================================================
560 /*! Function : IsEmpty
561 * Purpose : Detect if study is empty
563 //============================================================================
564 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
566 SALOMEDS::Locker lock;
568 throw SALOMEDS::Study::StudyInvalidReference();
569 return _impl->IsEmpty();
572 //============================================================================
573 /*! Function : FindComponent
574 * Purpose : Find a Component with ComponentDataType = aComponentName
576 //============================================================================
577 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
579 SALOMEDS::Locker lock;
582 throw SALOMEDS::Study::StudyInvalidReference();
584 SALOMEDS::SComponent_var sco;
586 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
587 if (!aCompImpl.IsNull())
588 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
593 //============================================================================
594 /*! Function : FindComponentID
595 * Purpose : Find a Component from it's ID
597 //============================================================================
598 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
600 SALOMEDS::Locker lock;
603 throw SALOMEDS::Study::StudyInvalidReference();
605 SALOMEDS::SComponent_var sco;
607 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
608 if (!aCompImpl.IsNull())
609 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
614 //============================================================================
615 /*! Function : FindObject
616 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
618 //============================================================================
619 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
621 SALOMEDS::Locker lock;
624 throw SALOMEDS::Study::StudyInvalidReference();
626 SALOMEDS::SObject_var so;
628 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
630 if (aSO.IsComponent()) {
631 SALOMEDSImpl_SComponent aSCO = aSO;
632 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
635 so = SALOMEDS_SObject_i::New(aSO, _orb);
642 //============================================================================
643 /*! Function : FindObjectID
644 * Purpose : Find an Object with ID = anObjectID
646 //============================================================================
647 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
649 SALOMEDS::Locker lock;
652 throw SALOMEDS::Study::StudyInvalidReference();
654 SALOMEDS::SObject_var so;
656 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
658 so = SALOMEDS_SObject_i::New(aSO, _orb);
663 //============================================================================
664 /*! Function : CreateObjectID
665 * Purpose : Creates an Object with ID = anObjectID
667 //============================================================================
668 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
670 SALOMEDS::Locker lock;
673 throw SALOMEDS::Study::StudyInvalidReference();
675 SALOMEDS::SObject_var so;
677 if (anObjectID && strlen(anObjectID) > 0) {
678 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
680 so = SALOMEDS_SObject_i::New(aSO, _orb);
686 //============================================================================
687 /*! Function : FindObjectByName
688 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
689 * : with ComponentDataType = aComponentName
691 //============================================================================
692 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
693 const char* aComponentName )
695 SALOMEDS::Locker lock;
698 throw SALOMEDS::Study::StudyInvalidReference();
700 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
701 std::string((char*)aComponentName));
703 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
704 int aLength = aSeq.size();
705 listSO->length(aLength);
706 for (int i = 0; i < aLength; i++) {
707 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
711 return listSO._retn();
714 //============================================================================
715 /*! Function : FindObjectIOR
716 * Purpose : Find an Object with IOR = anObjectIOR
718 //============================================================================
719 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
721 SALOMEDS::Locker lock;
724 throw SALOMEDS::Study::StudyInvalidReference();
726 SALOMEDS::SObject_var so;
728 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
730 so = SALOMEDS_SObject_i::New(aSO, _orb);
735 //============================================================================
736 /*! Function : FindObjectByPath
737 * Purpose : Find an Object by its path = thePath
739 //============================================================================
740 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
742 SALOMEDS::Locker lock;
745 throw SALOMEDS::Study::StudyInvalidReference();
747 SALOMEDS::SObject_var so;
749 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
751 so = SALOMEDS_SObject_i::New (aSO, _orb);
756 //============================================================================
757 /*! Function : GetObjectPath
760 //============================================================================
761 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
763 SALOMEDS::Locker lock;
766 throw SALOMEDS::Study::StudyInvalidReference();
768 std::string aPath = "";
770 if (!CORBA::is_nil(theObject)) {
771 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
772 SALOMEDSImpl_SObject aSO;
774 if (!CORBA::is_nil(aSObj)) {
775 aSO = _impl->FindObjectID(aSObj->GetID());
778 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
782 aPath = _impl->GetObjectPath(aSO);
786 return CORBA::string_dup(aPath.c_str());
789 //============================================================================
790 /*! Function : NewChildIterator
791 * Purpose : Create a ChildIterator from an SObject
793 //============================================================================
794 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
796 SALOMEDS::Locker lock;
799 throw SALOMEDS::Study::StudyInvalidReference();
801 CORBA::String_var anID = theSO->GetID();
802 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
803 SALOMEDSImpl_ChildIterator anItr(aSO);
804 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
805 SALOMEDS::ChildIterator_var it = it_servant->_this();
811 //============================================================================
812 /*! Function : NewComponentIterator
813 * Purpose : Create a SComponentIterator
815 //============================================================================
816 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
818 SALOMEDS::Locker lock;
821 throw SALOMEDS::Study::StudyInvalidReference();
823 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
825 SALOMEDS::SComponentIterator_var it = it_servant->_this();
831 //============================================================================
832 /*! Function : NewBuilder
833 * Purpose : Create a StudyBuilder
835 //============================================================================
836 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
838 SALOMEDS::Locker lock;
841 throw SALOMEDS::Study::StudyInvalidReference();
843 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
848 //============================================================================
850 * Purpose : get study name
852 //============================================================================
853 char* SALOMEDS_Study_i::Name()
855 SALOMEDS::Locker lock;
856 // Name is specified as IDL attribute: user exception cannot be raised
857 return CORBA::string_dup(_impl->Name().c_str());
860 //============================================================================
861 /*! Function : IsSaved
862 * Purpose : get if study has been saved
864 //============================================================================
865 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
867 SALOMEDS::Locker lock;
868 // IsSaved is specified as IDL attribute: user exception cannot be raised
869 return (!_closed) ? _impl->IsSaved() : false;
872 //============================================================================
873 /*! Function : IsSaved
874 * Purpose : set if study has been saved
876 //============================================================================
877 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
879 SALOMEDS::Locker lock;
880 // IsSaved is specified as IDL attribute: user exception cannot be raised
882 _impl->IsSaved(save);
885 //============================================================================
886 /*! Function : IsModified
887 * Purpose : Detect if a Study has been modified since it has been saved
889 //============================================================================
890 CORBA::Boolean SALOMEDS_Study_i::IsModified()
892 SALOMEDS::Locker lock;
895 throw SALOMEDS::Study::StudyInvalidReference();
897 return _impl->IsModified();
900 //============================================================================
901 /*! Function : Modified
902 * Purpose : Sets a Modified flag of a Study to True
904 //============================================================================
905 void SALOMEDS_Study_i::Modified()
907 SALOMEDS::Locker lock;
910 throw SALOMEDS::Study::StudyInvalidReference();
915 //============================================================================
917 * Purpose : get URL of the study (persistent reference of the study)
919 //============================================================================
920 char* SALOMEDS_Study_i::URL()
922 SALOMEDS::Locker lock;
923 // URL is specified as IDL attribute: user exception cannot be raised
924 return CORBA::string_dup(_impl->URL().c_str());
927 //============================================================================
929 * Purpose : set URL of the study (persistent reference of the study)
931 //============================================================================
932 void SALOMEDS_Study_i::URL(const char* url)
934 SALOMEDS::Locker lock;
935 // URL is specified as IDL attribute: user exception cannot be raised
936 _impl->URL(std::string((char*)url));
938 // update desktop title with new study name
942 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
944 SALOMEDS::Locker lock;
947 throw SALOMEDS::Study::StudyInvalidReference();
949 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
952 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
954 SALOMEDS::Locker lock;
956 SALOMEDSImpl_AttributeIOR* Att = NULL;
957 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
958 char* IOR = CORBA::string_dup(Att->Value().c_str());
959 CORBA::Object_var obj = orb->string_to_object(IOR);
960 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
961 ASSERT(!CORBA::is_nil(aStudy));
962 return SALOMEDS::Study::_duplicate(aStudy);
964 MESSAGE("GetStudy: Problem to get study");
966 return SALOMEDS::Study::_nil();
969 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
971 SALOMEDS::Locker lock;
972 SALOMEDSImpl_Study::IORUpdated(theAttribute);
975 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
977 SALOMEDS::Locker lock;
980 throw SALOMEDS::Study::StudyInvalidReference();
982 SALOMEDS::GenericAttribute_ptr aTarget;
983 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
984 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
986 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
992 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
994 SALOMEDS::Locker lock;
997 throw SALOMEDS::Study::StudyInvalidReference();
999 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
1000 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
1001 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
1002 return aProp._retn();
1005 char* SALOMEDS_Study_i::GetLastModificationDate()
1007 SALOMEDS::Locker lock;
1010 throw SALOMEDS::Study::StudyInvalidReference();
1012 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
1015 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
1017 SALOMEDS::Locker lock;
1020 throw SALOMEDS::Study::StudyInvalidReference();
1022 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
1024 std::vector<std::string> aSeq = _impl->GetModificationsDate();
1026 int aLength = aSeq.size();
1027 aDates->length(aLength);
1028 for (int anIndex = 0; anIndex < aLength; anIndex++) {
1029 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1032 return aDates._retn();
1035 //============================================================================
1036 /*! Function : GetUseCaseBuilder
1037 * Purpose : Returns a UseCase builder
1039 //============================================================================
1040 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1042 SALOMEDS::Locker lock;
1045 throw SALOMEDS::Study::StudyInvalidReference();
1047 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1048 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1052 //============================================================================
1053 /*! Function : AddPostponed
1056 //============================================================================
1057 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1059 SALOMEDS::Locker lock;
1063 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1065 SALOMEDS::Locker lock;
1069 //============================================================================
1070 /*! Function : RemovePostponed
1073 //============================================================================
1074 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1076 SALOMEDS::Locker lock;
1079 throw SALOMEDS::Study::StudyInvalidReference();
1081 std::vector<std::string> anIORs = _impl->GetIORs();
1082 int i, aSize = (int)anIORs.size();
1084 for (i = 0; i < aSize; i++) {
1086 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1087 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1088 //rnv: To avoid double deletion of the Salome Generic Objects:
1089 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1090 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1091 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1098 //============================================================================
1099 /*! Function : UndoPostponed
1102 //============================================================================
1103 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1105 SALOMEDS::Locker lock;
1110 //============================================================================
1111 /*! Function : DumpStudy
1114 //============================================================================
1115 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1116 const char* theBaseName,
1117 CORBA::Boolean isPublished,
1118 CORBA::Boolean isMultiFile)
1120 SALOMEDS::Locker lock;
1123 throw SALOMEDS::Study::StudyInvalidReference();
1125 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1126 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1127 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1133 //============================================================================
1134 /*! Function : GetCommonParameters
1137 //============================================================================
1138 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1140 SALOMEDS::Locker lock;
1143 throw SALOMEDS::Study::StudyInvalidReference();
1145 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1146 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1147 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1149 return aParam._retn();
1152 //============================================================================
1153 /*! Function : GetCommonModuleParameters
1156 //============================================================================
1157 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1158 const char* theModuleName,
1159 CORBA::Long theSavePoint)
1161 SALOMEDS::Locker lock;
1164 throw SALOMEDS::Study::StudyInvalidReference();
1166 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1167 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1168 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1170 return aParam._retn();
1173 //============================================================================
1174 /*! Function : SetStudyLock
1177 //============================================================================
1178 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1180 SALOMEDS::Locker lock;
1183 throw SALOMEDS::Study::StudyInvalidReference();
1185 _impl->SetStudyLock(theLockerID);
1188 //============================================================================
1189 /*! Function : IsStudyLocked
1192 //============================================================================
1193 bool SALOMEDS_Study_i::IsStudyLocked()
1195 SALOMEDS::Locker lock;
1198 throw SALOMEDS::Study::StudyInvalidReference();
1200 return _impl->IsStudyLocked();
1203 //============================================================================
1204 /*! Function : UnLockStudy
1207 //============================================================================
1208 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1210 SALOMEDS::Locker lock;
1213 throw SALOMEDS::Study::StudyInvalidReference();
1215 _impl->UnLockStudy(theLockerID);
1218 //============================================================================
1219 /*! Function : GetLockerID
1222 //============================================================================
1223 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1225 SALOMEDS::Locker lock;
1228 throw SALOMEDS::Study::StudyInvalidReference();
1230 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1232 std::vector<std::string> aSeq = _impl->GetLockerID();
1234 int aLength = aSeq.size();
1235 aResult->length(aLength);
1236 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1237 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1240 return aResult._retn();
1242 //============================================================================
1243 /*! Function : SetReal
1246 //============================================================================
1247 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1250 throw SALOMEDS::Study::StudyInvalidReference();
1253 _impl->SetVariable(std::string(theVarName),
1255 SALOMEDSImpl_GenericVariable::REAL_VAR);
1257 _notifier->modifyNB_Notification(theVarName);
1260 //============================================================================
1261 /*! Function : SetInteger
1264 //============================================================================
1265 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1268 throw SALOMEDS::Study::StudyInvalidReference();
1270 _impl->SetVariable(std::string(theVarName),
1272 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1274 _notifier->modifyNB_Notification(theVarName);
1277 //============================================================================
1278 /*! Function : SetBoolean
1281 //============================================================================
1282 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1285 throw SALOMEDS::Study::StudyInvalidReference();
1287 _impl->SetVariable(std::string(theVarName),
1289 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1291 _notifier->modifyNB_Notification(theVarName);
1294 //============================================================================
1295 /*! Function : SetString
1298 //============================================================================
1299 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1302 throw SALOMEDS::Study::StudyInvalidReference();
1304 _impl->SetStringVariable(std::string(theVarName),
1306 SALOMEDSImpl_GenericVariable::STRING_VAR);
1308 _notifier->modifyNB_Notification(theVarName);
1311 //============================================================================
1312 /*! Function : SetStringAsDouble
1315 //============================================================================
1316 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1319 throw SALOMEDS::Study::StudyInvalidReference();
1321 _impl->SetStringVariableAsDouble(std::string(theVarName),
1323 SALOMEDSImpl_GenericVariable::STRING_VAR);
1326 //============================================================================
1327 /*! Function : GetReal
1330 //============================================================================
1331 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1334 throw SALOMEDS::Study::StudyInvalidReference();
1336 return _impl->GetVariableValue(std::string(theVarName));
1339 //============================================================================
1340 /*! Function : GetInteger
1343 //============================================================================
1344 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1347 throw SALOMEDS::Study::StudyInvalidReference();
1349 return (long)_impl->GetVariableValue(std::string(theVarName));
1352 //============================================================================
1353 /*! Function : GetBoolean
1356 //============================================================================
1357 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1360 throw SALOMEDS::Study::StudyInvalidReference();
1362 return (bool)_impl->GetVariableValue(std::string(theVarName));
1365 //============================================================================
1366 /*! Function : GetString
1369 //============================================================================
1370 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1373 throw SALOMEDS::Study::StudyInvalidReference();
1375 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1378 //============================================================================
1379 /*! Function : IsReal
1382 //============================================================================
1383 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1386 throw SALOMEDS::Study::StudyInvalidReference();
1388 return _impl->IsTypeOf(std::string(theVarName),
1389 SALOMEDSImpl_GenericVariable::REAL_VAR);
1392 //============================================================================
1393 /*! Function : IsInteger
1396 //============================================================================
1397 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1400 throw SALOMEDS::Study::StudyInvalidReference();
1402 return _impl->IsTypeOf(std::string(theVarName),
1403 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1406 //============================================================================
1407 /*! Function : IsBoolean
1410 //============================================================================
1411 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1414 throw SALOMEDS::Study::StudyInvalidReference();
1416 return _impl->IsTypeOf(std::string(theVarName),
1417 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1420 //============================================================================
1421 /*! Function : IsString
1424 //============================================================================
1425 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1428 throw SALOMEDS::Study::StudyInvalidReference();
1430 return _impl->IsTypeOf(std::string(theVarName),
1431 SALOMEDSImpl_GenericVariable::STRING_VAR);
1434 //============================================================================
1435 /*! Function : IsVariable
1438 //============================================================================
1439 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1442 throw SALOMEDS::Study::StudyInvalidReference();
1444 return _impl->IsVariable(std::string(theVarName));
1447 //============================================================================
1448 /*! Function : GetVariableNames
1451 //============================================================================
1452 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1455 throw SALOMEDS::Study::StudyInvalidReference();
1457 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1459 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1461 int aLen = aVarNames.size();
1462 aResult->length(aLen);
1463 for (int anInd = 0; anInd < aLen; anInd++)
1464 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1466 return aResult._retn();
1469 //============================================================================
1470 /*! Function : RemoveVariable
1473 //============================================================================
1474 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1477 throw SALOMEDS::Study::StudyInvalidReference();
1479 bool res = _impl->RemoveVariable(std::string(theVarName));
1480 if (res && _notifier)
1481 _notifier->modifyNB_Notification(theVarName);
1486 //============================================================================
1487 /*! Function : RenameVariable
1490 //============================================================================
1491 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1494 throw SALOMEDS::Study::StudyInvalidReference();
1496 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1497 if (res && _notifier)
1498 _notifier->modifyNB_Notification(theVarName);
1503 //============================================================================
1504 /*! Function : IsVariableUsed
1507 //============================================================================
1508 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1511 throw SALOMEDS::Study::StudyInvalidReference();
1513 return _impl->IsVariableUsed(std::string(theVarName));
1517 //============================================================================
1518 /*! Function : ParseVariables
1521 //============================================================================
1522 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1525 throw SALOMEDS::Study::StudyInvalidReference();
1527 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1529 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1531 int aSectionsLen = aSections.size();
1532 aResult->length(aSectionsLen);
1534 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1535 std::vector<std::string> aVarNames = aSections[aSectionInd];
1537 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1539 int aLen = aVarNames.size();
1540 aList->length(aLen);
1542 for (int anInd = 0; anInd < aLen; anInd++)
1543 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1545 aResult[aSectionInd] = aList;
1548 return aResult._retn();
1551 //============================================================================
1552 /*! Function : GetDefaultScript
1555 //============================================================================
1556 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1558 SALOMEDS::Locker lock;
1561 throw SALOMEDS::Study::StudyInvalidReference();
1563 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1564 return CORBA::string_dup(script.c_str());
1567 //============================================================================
1568 /*! Function : EnableUseCaseAutoFilling
1571 //============================================================================
1572 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1575 throw SALOMEDS::Study::StudyInvalidReference();
1577 _impl->EnableUseCaseAutoFilling(isEnabled);
1578 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1581 builder->SetOnAddSObject(_impl->GetCallback());
1582 builder->SetOnRemoveSObject(_impl->GetCallback());
1585 builder->SetOnAddSObject(NULL);
1586 builder->SetOnRemoveSObject(NULL);
1592 CORBA::Long SALOMEDS_Study_i::getPID()
1595 return (CORBA::Long)_getpid();
1597 return (CORBA::Long)getpid();
1601 void SALOMEDS_Study_i::ShutdownWithExit()
1603 exit( EXIT_SUCCESS );
1606 void SALOMEDS_Study_i::Shutdown()
1608 if(!CORBA::is_nil(_orb))
1612 //============================================================================
1613 /*! Function : attach
1614 * Purpose : This function attach an observer to the study
1616 //============================================================================
1617 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1620 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1624 //============================================================================
1625 /*! Function : detach
1626 * Purpose : This function detaches an observer from the study
1628 //============================================================================
1629 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1632 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1635 //===========================================================================
1636 // PRIVATE FUNCTIONS
1637 //===========================================================================
1638 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1641 long pid = (long)_getpid();
1643 long pid = (long)getpid();
1645 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1646 return reinterpret_cast<CORBA::LongLong>(_impl);
1649 void SALOMEDS_Study_i::NameChanged()
1651 // Notify GUI that the name of study was changed
1652 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1653 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
1654 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1655 if ( !CORBA::is_nil(aSession) ) {
1656 std::stringstream ss;
1657 ss << "studyNameChanged";
1658 std::string str = ss.str();
1660 aSession->emitMessageOneWay(str.c_str());