1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDS_Study_i.cxx
24 // Author : Sergey RUIN
27 #include "utilities.h"
29 #include "SALOMEDS_Study_i.hxx"
30 #include "SALOMEDS_UseCaseIterator_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
33 #include "SALOMEDS_AttributeParameter_i.hxx"
34 #include "SALOMEDS_ChildIterator_i.hxx"
35 #include "SALOMEDS_Driver_i.hxx"
36 #include "SALOMEDS.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
41 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
42 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "SALOMEDSImpl_Callback.hxx"
47 #include "DF_Label.hxx"
48 #include "DF_Attribute.hxx"
50 #include "Utils_ExceptHandlers.hxx"
52 #include "Basics_Utils.hxx"
53 #include "SALOME_KernelServices.hxx"
58 #include <sys/types.h>
62 UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
63 UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
65 static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
69 class Notifier: public SALOMEDSImpl_AbstractCallback
72 Notifier(CORBA::ORB_ptr orb)
74 _orb = CORBA::ORB::_duplicate(orb);
77 //============================================================================
78 /*! Function : addSO_Notification
79 * Purpose : This function tells all the observers that a SO has been added
81 //============================================================================
83 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
85 std::string anID=theSObject.GetID();
86 const char* cID=anID.c_str();
87 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
89 it->first->notifyObserverID(cID,1);
91 return true; // NGE return always true but can be modified if needed
94 //============================================================================
95 /*! Function : removeSO_Notification
96 * Purpose : This function tells all the observers that a SO has been removed
98 //============================================================================
100 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
102 std::string anID=theSObject.GetID();
103 const char* cID=anID.c_str();
104 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
106 it->first->notifyObserverID(cID,2);
108 return true; // NGE return always true but can be modified if needed
111 //============================================================================
112 /*! Function : modifySO_Notification
113 * Purpose : This function tells all the observers that a SO has been modified
115 //============================================================================
117 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
119 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
123 std::string anID=theSObject.GetID();
124 const char* cID=anID.c_str();
125 it->first->notifyObserverID(cID,reason);
128 return true; // NGE return always true but can be modified if needed
131 //============================================================================
132 /*! Function : modifyNB_Notification
133 * Purpose : This function tells all the observers that
134 * a NoteBook variable has been added/modified/removed.
136 //============================================================================
138 virtual bool modifyNB_Notification(const char* theVarName)
140 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
142 it->first->notifyObserverID(theVarName,6);
144 return true; // NGE return always true but can be modified if needed
147 //============================================================================
148 /*! Function : attach
149 * Purpose : register an Observer
151 //============================================================================
153 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
155 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
158 //============================================================================
159 /*! Function : detach
160 * Purpose : unregister an Observer
162 //============================================================================
164 virtual void detach(SALOMEDS::Observer_ptr theObs)
166 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
168 if ( it->first->_is_equivalent(theObs) ) {
169 myObservers.erase( it );
176 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
177 typedef ObsList::iterator ObsListIter;
182 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
185 GenObjRegister(CORBA::ORB_ptr orb)
187 _orb = CORBA::ORB::_duplicate(orb);
189 virtual void RegisterGenObj (const std::string& theIOR)
193 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
194 if ( obj->_non_existent() ) return;
195 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
196 if(! CORBA::is_nil(gobj) )
201 catch(const CORBA::Exception& e)
205 virtual void UnRegisterGenObj(const std::string& theIOR)
209 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
210 if ( obj->_non_existent() ) return;
211 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
212 if(! CORBA::is_nil(gobj) )
217 catch(const CORBA::Exception& e)
226 } // namespace SALOMEDS
228 //============================================================================
229 /*! Function : SALOMEDS_Study_i
230 * Purpose : SALOMEDS_Study_i constructor
232 //============================================================================
233 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
235 _orb = CORBA::ORB::_duplicate(orb);
236 _impl = new SALOMEDSImpl_Study();
237 _factory = new SALOMEDS_DriverFactory_i(_orb);
243 //============================================================================
244 /*! Function : ~SALOMEDS_Study_i
245 * Purpose : SALOMEDS_Study_i destructor
247 //============================================================================
248 SALOMEDS_Study_i::~SALOMEDS_Study_i()
255 //============================================================================
257 * Purpose : Initialize study components
259 //============================================================================
260 void SALOMEDS_Study_i::Init()
263 throw SALOMEDS::Study::StudyInvalidReference();
265 SALOMEDS::Locker lock;
267 if ( !_impl->GetDocument() )
270 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
271 _notifier = new SALOMEDS::Notifier(_orb);
272 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
275 _impl->setNotifier(_notifier);
276 _impl->setGenObjRegister( _genObjRegister );
278 // update desktop title with new study name
281 // Notify GUI that study was created
282 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
283 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
284 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
285 if ( !CORBA::is_nil(aSession) ) {
286 std::stringstream ss;
287 ss << "studyCreated";
288 std::string str = ss.str();
290 aSession->emitMessageOneWay(str.c_str());
295 //============================================================================
297 * Purpose : Clear study components
299 //============================================================================
300 void SALOMEDS_Study_i::Clear()
305 SALOMEDS::Locker lock;
307 //delete the builder servant
308 PortableServer::POA_var poa=_builder->_default_POA();
309 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
310 poa->deactivate_object(anObjectId.in());
311 _builder->_remove_ref();
315 if (_impl->GetDocument()) {
316 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
317 for (; itcomponent->More(); itcomponent->Next()) {
318 SALOMEDS::SComponent_var sco = itcomponent->Value();
319 CORBA::String_var compodatatype=sco->ComponentDataType();
320 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
321 // if there is an associated Engine call its method for closing
322 CORBA::String_var IOREngine;
323 if (sco->ComponentIOR(IOREngine)) {
324 // we have found the associated engine to write the data
325 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
326 //_narrow can throw a corba exception
328 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
329 if (!CORBA::is_nil(obj)) {
330 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
331 if (!anEngine->_is_nil()) {
333 anEngine->Close(sco);
338 catch (CORBA::Exception&) {
344 //Does not need any more this iterator
345 itcomponent->UnRegister();
348 // Notify GUI that study is cleared
349 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
350 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
351 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
352 if ( !CORBA::is_nil(aSession) ) {
353 std::stringstream ss;
354 ss << "studyCleared";
355 std::string str = ss.str();
357 aSession->emitMessageOneWay(str.c_str());
362 _impl->setNotifier(0);
364 delete _genObjRegister;
370 //============================================================================
372 * Purpose : Open a Study from it's persistent reference
374 //============================================================================
375 bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl)
376 throw(SALOME::SALOME_Exception)
381 SALOMEDS::Locker lock;
383 Unexpect aCatch(SalomeException);
384 MESSAGE("Begin of SALOMEDS_Study_i::Open");
386 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
387 bool res = _impl->Open(std::string(aUrl));
389 // update desktop title with new study name
393 THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
397 //============================================================================
399 * Purpose : Save a Study to it's persistent reference
401 //============================================================================
402 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
404 SALOMEDS::Locker lock;
406 throw SALOMEDS::Study::StudyInvalidReference();
407 return _impl->Save(_factory, theMultiFile, theASCII);
410 //=============================================================================
411 /*! Function : SaveAs
412 * Purpose : Save a study to the persistent reference aUrl
414 //============================================================================
415 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const wchar_t* aWUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
417 SALOMEDS::Locker lock;
419 throw SALOMEDS::Study::StudyInvalidReference();
421 std::string aUrl = Kernel_Utils::encode_s(aWUrl);
422 return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
425 //============================================================================
426 /*! Function : CanCopy
429 //============================================================================
430 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
432 SALOMEDS::Locker lock;
434 throw SALOMEDS::Study::StudyInvalidReference();
436 CORBA::String_var anID = theObject->GetID();
437 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
439 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
440 bool ret = _impl->CanCopy(anObject, aDriver);
445 //============================================================================
449 //============================================================================
450 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
452 SALOMEDS::Locker lock;
454 throw SALOMEDS::Study::StudyInvalidReference();
456 CORBA::String_var anID = theObject->GetID();
457 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
459 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
460 bool ret = _impl->Copy(anObject, aDriver);
465 //============================================================================
466 /*! Function : CanPaste
469 //============================================================================
470 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
472 SALOMEDS::Locker lock;
474 throw SALOMEDS::Study::StudyInvalidReference();
476 CORBA::String_var anID = theObject->GetID();
477 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
479 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
480 bool ret = _impl->CanPaste(anObject, aDriver);
485 //============================================================================
489 //============================================================================
490 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
491 throw(SALOMEDS::StudyBuilder::LockProtection)
493 SALOMEDS::Locker lock;
495 Unexpect aCatch(LockProtection);
497 CORBA::String_var anID = theObject->GetID();
498 SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
499 SALOMEDSImpl_SObject aNewSO;
502 SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
503 aNewSO = _impl->Paste(anObject, aDriver);
507 throw SALOMEDS::StudyBuilder::LockProtection();
510 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
514 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
516 SALOMEDS_Driver_i* driver = NULL;
518 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
520 std::string IOREngine = aSCO.GetIOR();
521 if(!IOREngine.empty()) {
522 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
523 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
524 driver = new SALOMEDS_Driver_i(Engine, orb);
531 //============================================================================
532 /*! Function : GetPersistentReference
533 * Purpose : Get persistent reference of study (idem URL())
535 //============================================================================
536 char* SALOMEDS_Study_i::GetPersistentReference()
538 SALOMEDS::Locker lock;
540 throw SALOMEDS::Study::StudyInvalidReference();
541 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
544 //============================================================================
545 /*! Function : IsEmpty
546 * Purpose : Detect if study is empty
548 //============================================================================
549 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
551 SALOMEDS::Locker lock;
553 throw SALOMEDS::Study::StudyInvalidReference();
554 return _impl->IsEmpty();
557 //============================================================================
558 /*! Function : FindComponent
559 * Purpose : Find a Component with ComponentDataType = aComponentName
561 //============================================================================
562 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
564 SALOMEDS::Locker lock;
567 throw SALOMEDS::Study::StudyInvalidReference();
569 SALOMEDS::SComponent_var sco;
571 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
572 if (!aCompImpl.IsNull())
573 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
578 //============================================================================
579 /*! Function : FindComponentID
580 * Purpose : Find a Component from it's ID
582 //============================================================================
583 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
585 SALOMEDS::Locker lock;
588 throw SALOMEDS::Study::StudyInvalidReference();
590 SALOMEDS::SComponent_var sco;
592 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
593 if (!aCompImpl.IsNull())
594 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
599 //============================================================================
600 /*! Function : FindObject
601 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
603 //============================================================================
604 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
606 SALOMEDS::Locker lock;
609 throw SALOMEDS::Study::StudyInvalidReference();
611 SALOMEDS::SObject_var so;
613 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
615 if (aSO.IsComponent()) {
616 SALOMEDSImpl_SComponent aSCO = aSO;
617 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
620 so = SALOMEDS_SObject_i::New(aSO, _orb);
627 //============================================================================
628 /*! Function : FindObjectID
629 * Purpose : Find an Object with ID = anObjectID
631 //============================================================================
632 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
634 SALOMEDS::Locker lock;
637 throw SALOMEDS::Study::StudyInvalidReference();
639 SALOMEDS::SObject_var so;
641 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
643 so = SALOMEDS_SObject_i::New(aSO, _orb);
648 //============================================================================
649 /*! Function : CreateObjectID
650 * Purpose : Creates an Object with ID = anObjectID
652 //============================================================================
653 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
655 SALOMEDS::Locker lock;
658 throw SALOMEDS::Study::StudyInvalidReference();
660 SALOMEDS::SObject_var so;
662 if (anObjectID && strlen(anObjectID) > 0) {
663 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
665 so = SALOMEDS_SObject_i::New(aSO, _orb);
671 //============================================================================
672 /*! Function : FindObjectByName
673 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
674 * : with ComponentDataType = aComponentName
676 //============================================================================
677 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
678 const char* aComponentName )
680 SALOMEDS::Locker lock;
683 throw SALOMEDS::Study::StudyInvalidReference();
685 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
686 std::string((char*)aComponentName));
688 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
689 int aLength = aSeq.size();
690 listSO->length(aLength);
691 for (int i = 0; i < aLength; i++) {
692 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
696 return listSO._retn();
699 //============================================================================
700 /*! Function : FindObjectIOR
701 * Purpose : Find an Object with IOR = anObjectIOR
703 //============================================================================
704 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
706 SALOMEDS::Locker lock;
709 throw SALOMEDS::Study::StudyInvalidReference();
711 SALOMEDS::SObject_var so;
713 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
715 so = SALOMEDS_SObject_i::New(aSO, _orb);
720 //============================================================================
721 /*! Function : FindObjectByPath
722 * Purpose : Find an Object by its path = thePath
724 //============================================================================
725 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
727 SALOMEDS::Locker lock;
730 throw SALOMEDS::Study::StudyInvalidReference();
732 SALOMEDS::SObject_var so;
734 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
736 so = SALOMEDS_SObject_i::New (aSO, _orb);
741 //============================================================================
742 /*! Function : GetObjectPath
745 //============================================================================
746 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
748 SALOMEDS::Locker lock;
751 throw SALOMEDS::Study::StudyInvalidReference();
753 std::string aPath = "";
755 if (!CORBA::is_nil(theObject)) {
756 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
757 SALOMEDSImpl_SObject aSO;
759 if (!CORBA::is_nil(aSObj)) {
760 aSO = _impl->FindObjectID(aSObj->GetID());
763 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
767 aPath = _impl->GetObjectPath(aSO);
771 return CORBA::string_dup(aPath.c_str());
774 //============================================================================
775 /*! Function : NewChildIterator
776 * Purpose : Create a ChildIterator from an SObject
778 //============================================================================
779 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
781 SALOMEDS::Locker lock;
784 throw SALOMEDS::Study::StudyInvalidReference();
786 CORBA::String_var anID = theSO->GetID();
787 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
788 SALOMEDSImpl_ChildIterator anItr(aSO);
789 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
790 SALOMEDS::ChildIterator_var it = it_servant->_this();
796 //============================================================================
797 /*! Function : NewComponentIterator
798 * Purpose : Create a SComponentIterator
800 //============================================================================
801 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
803 SALOMEDS::Locker lock;
806 throw SALOMEDS::Study::StudyInvalidReference();
808 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
810 SALOMEDS::SComponentIterator_var it = it_servant->_this();
816 //============================================================================
817 /*! Function : NewBuilder
818 * Purpose : Create a StudyBuilder
820 //============================================================================
821 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
823 SALOMEDS::Locker lock;
826 throw SALOMEDS::Study::StudyInvalidReference();
828 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
833 //============================================================================
835 * Purpose : get study name
837 //============================================================================
838 wchar_t* SALOMEDS_Study_i::Name()
840 SALOMEDS::Locker lock;
841 // Name is specified as IDL attribute: user exception cannot be raised
842 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->Name()));
845 //============================================================================
847 * Purpose : set study name
849 //============================================================================
850 void SALOMEDS_Study_i::Name(const wchar_t* wname)
852 SALOMEDS::Locker lock;
853 // Name is specified as IDL attribute: user exception cannot be raised
854 _impl->Name(Kernel_Utils::encode_s(wname));
857 //============================================================================
858 /*! Function : IsSaved
859 * Purpose : get if study has been saved
861 //============================================================================
862 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
864 SALOMEDS::Locker lock;
865 // IsSaved is specified as IDL attribute: user exception cannot be raised
866 return (!_closed) ? _impl->IsSaved() : false;
869 //============================================================================
870 /*! Function : IsSaved
871 * Purpose : set if study has been saved
873 //============================================================================
874 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
876 SALOMEDS::Locker lock;
877 // IsSaved is specified as IDL attribute: user exception cannot be raised
879 _impl->IsSaved(save);
882 //============================================================================
883 /*! Function : IsModified
884 * Purpose : Detect if a Study has been modified since it has been saved
886 //============================================================================
887 CORBA::Boolean SALOMEDS_Study_i::IsModified()
889 SALOMEDS::Locker lock;
892 throw SALOMEDS::Study::StudyInvalidReference();
894 return _impl->IsModified();
897 //============================================================================
898 /*! Function : Modified
899 * Purpose : Sets a Modified flag of a Study to True
901 //============================================================================
902 void SALOMEDS_Study_i::Modified()
904 SALOMEDS::Locker lock;
907 throw SALOMEDS::Study::StudyInvalidReference();
912 //============================================================================
914 * Purpose : get URL of the study (persistent reference of the study)
916 //============================================================================
917 wchar_t* SALOMEDS_Study_i::URL()
919 SALOMEDS::Locker lock;
920 // URL is specified as IDL attribute: user exception cannot be raised
921 return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->URL()));
924 //============================================================================
926 * Purpose : set URL of the study (persistent reference of the study)
928 //============================================================================
929 void SALOMEDS_Study_i::URL(const wchar_t* wurl)
931 SALOMEDS::Locker lock;
932 // URL is specified as IDL attribute: user exception cannot be raised
933 _impl->URL(Kernel_Utils::encode_s(wurl));
935 // update desktop title with new study name
939 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
941 SALOMEDS::Locker lock;
944 throw SALOMEDS::Study::StudyInvalidReference();
946 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
949 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
951 SALOMEDS::Locker lock;
952 SALOMEDSImpl_Study::IORUpdated(theAttribute);
955 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
957 SALOMEDS::Locker lock;
960 throw SALOMEDS::Study::StudyInvalidReference();
962 SALOMEDS::GenericAttribute_ptr aTarget;
963 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
964 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
966 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
972 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
974 SALOMEDS::Locker lock;
977 throw SALOMEDS::Study::StudyInvalidReference();
979 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
980 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
981 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
982 return aProp._retn();
985 char* SALOMEDS_Study_i::GetLastModificationDate()
987 SALOMEDS::Locker lock;
990 throw SALOMEDS::Study::StudyInvalidReference();
992 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
995 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
997 SALOMEDS::Locker lock;
1000 throw SALOMEDS::Study::StudyInvalidReference();
1002 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
1004 std::vector<std::string> aSeq = _impl->GetModificationsDate();
1006 int aLength = aSeq.size();
1007 aDates->length(aLength);
1008 for (int anIndex = 0; anIndex < aLength; anIndex++) {
1009 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1012 return aDates._retn();
1015 //============================================================================
1016 /*! Function : GetUseCaseBuilder
1017 * Purpose : Returns a UseCase builder
1019 //============================================================================
1020 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
1022 SALOMEDS::Locker lock;
1025 throw SALOMEDS::Study::StudyInvalidReference();
1027 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1028 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1032 //============================================================================
1033 /*! Function : AddPostponed
1036 //============================================================================
1037 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1039 SALOMEDS::Locker lock;
1043 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1045 SALOMEDS::Locker lock;
1049 //============================================================================
1050 /*! Function : RemovePostponed
1053 //============================================================================
1054 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1056 SALOMEDS::Locker lock;
1059 throw SALOMEDS::Study::StudyInvalidReference();
1061 std::vector<std::string> anIORs = _impl->GetIORs();
1062 int i, aSize = (int)anIORs.size();
1064 for (i = 0; i < aSize; i++) {
1066 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1067 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1068 //rnv: To avoid double deletion of the Salome Generic Objects:
1069 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1070 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1071 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1078 //============================================================================
1079 /*! Function : UndoPostponed
1082 //============================================================================
1083 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1085 SALOMEDS::Locker lock;
1090 //============================================================================
1091 /*! Function : DumpStudy
1094 //============================================================================
1095 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1096 const char* theBaseName,
1097 CORBA::Boolean isPublished,
1098 CORBA::Boolean isMultiFile)
1100 SALOMEDS::Locker lock;
1103 throw SALOMEDS::Study::StudyInvalidReference();
1105 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1106 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1107 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1113 //============================================================================
1114 /*! Function : GetCommonParameters
1117 //============================================================================
1118 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1120 SALOMEDS::Locker lock;
1123 throw SALOMEDS::Study::StudyInvalidReference();
1125 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1126 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1127 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1129 return aParam._retn();
1132 //============================================================================
1133 /*! Function : GetCommonModuleParameters
1136 //============================================================================
1137 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1138 const char* theModuleName,
1139 CORBA::Long theSavePoint)
1141 SALOMEDS::Locker lock;
1144 throw SALOMEDS::Study::StudyInvalidReference();
1146 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1147 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1148 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1150 return aParam._retn();
1153 //============================================================================
1154 /*! Function : SetStudyLock
1157 //============================================================================
1158 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1160 SALOMEDS::Locker lock;
1163 throw SALOMEDS::Study::StudyInvalidReference();
1165 _impl->SetStudyLock(theLockerID);
1168 //============================================================================
1169 /*! Function : IsStudyLocked
1172 //============================================================================
1173 bool SALOMEDS_Study_i::IsStudyLocked()
1175 SALOMEDS::Locker lock;
1178 throw SALOMEDS::Study::StudyInvalidReference();
1180 return _impl->IsStudyLocked();
1183 //============================================================================
1184 /*! Function : UnLockStudy
1187 //============================================================================
1188 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1190 SALOMEDS::Locker lock;
1193 throw SALOMEDS::Study::StudyInvalidReference();
1195 _impl->UnLockStudy(theLockerID);
1198 //============================================================================
1199 /*! Function : GetLockerID
1202 //============================================================================
1203 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1205 SALOMEDS::Locker lock;
1208 throw SALOMEDS::Study::StudyInvalidReference();
1210 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1212 std::vector<std::string> aSeq = _impl->GetLockerID();
1214 int aLength = aSeq.size();
1215 aResult->length(aLength);
1216 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1217 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1220 return aResult._retn();
1222 //============================================================================
1223 /*! Function : SetReal
1226 //============================================================================
1227 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1230 throw SALOMEDS::Study::StudyInvalidReference();
1233 _impl->SetVariable(std::string(theVarName),
1235 SALOMEDSImpl_GenericVariable::REAL_VAR);
1237 _notifier->modifyNB_Notification(theVarName);
1240 //============================================================================
1241 /*! Function : SetInteger
1244 //============================================================================
1245 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1248 throw SALOMEDS::Study::StudyInvalidReference();
1250 _impl->SetVariable(std::string(theVarName),
1252 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1254 _notifier->modifyNB_Notification(theVarName);
1257 //============================================================================
1258 /*! Function : SetBoolean
1261 //============================================================================
1262 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1265 throw SALOMEDS::Study::StudyInvalidReference();
1267 _impl->SetVariable(std::string(theVarName),
1269 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1271 _notifier->modifyNB_Notification(theVarName);
1274 //============================================================================
1275 /*! Function : SetString
1278 //============================================================================
1279 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1282 throw SALOMEDS::Study::StudyInvalidReference();
1284 _impl->SetStringVariable(std::string(theVarName),
1286 SALOMEDSImpl_GenericVariable::STRING_VAR);
1288 _notifier->modifyNB_Notification(theVarName);
1291 //============================================================================
1292 /*! Function : SetStringAsDouble
1295 //============================================================================
1296 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1299 throw SALOMEDS::Study::StudyInvalidReference();
1301 _impl->SetStringVariableAsDouble(std::string(theVarName),
1303 SALOMEDSImpl_GenericVariable::STRING_VAR);
1306 //============================================================================
1307 /*! Function : GetReal
1310 //============================================================================
1311 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1314 throw SALOMEDS::Study::StudyInvalidReference();
1316 return _impl->GetVariableValue(std::string(theVarName));
1319 //============================================================================
1320 /*! Function : GetInteger
1323 //============================================================================
1324 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1327 throw SALOMEDS::Study::StudyInvalidReference();
1329 return (long)_impl->GetVariableValue(std::string(theVarName));
1332 //============================================================================
1333 /*! Function : GetBoolean
1336 //============================================================================
1337 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1340 throw SALOMEDS::Study::StudyInvalidReference();
1342 return (bool)_impl->GetVariableValue(std::string(theVarName));
1345 //============================================================================
1346 /*! Function : GetString
1349 //============================================================================
1350 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1353 throw SALOMEDS::Study::StudyInvalidReference();
1355 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1358 //============================================================================
1359 /*! Function : IsReal
1362 //============================================================================
1363 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1366 throw SALOMEDS::Study::StudyInvalidReference();
1368 return _impl->IsTypeOf(std::string(theVarName),
1369 SALOMEDSImpl_GenericVariable::REAL_VAR);
1372 //============================================================================
1373 /*! Function : IsInteger
1376 //============================================================================
1377 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1380 throw SALOMEDS::Study::StudyInvalidReference();
1382 return _impl->IsTypeOf(std::string(theVarName),
1383 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1386 //============================================================================
1387 /*! Function : IsBoolean
1390 //============================================================================
1391 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1394 throw SALOMEDS::Study::StudyInvalidReference();
1396 return _impl->IsTypeOf(std::string(theVarName),
1397 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1400 //============================================================================
1401 /*! Function : IsString
1404 //============================================================================
1405 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1408 throw SALOMEDS::Study::StudyInvalidReference();
1410 return _impl->IsTypeOf(std::string(theVarName),
1411 SALOMEDSImpl_GenericVariable::STRING_VAR);
1414 //============================================================================
1415 /*! Function : IsVariable
1418 //============================================================================
1419 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1422 throw SALOMEDS::Study::StudyInvalidReference();
1424 return _impl->IsVariable(std::string(theVarName));
1427 //============================================================================
1428 /*! Function : GetVariableNames
1431 //============================================================================
1432 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1435 throw SALOMEDS::Study::StudyInvalidReference();
1437 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1439 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1441 int aLen = aVarNames.size();
1442 aResult->length(aLen);
1443 for (int anInd = 0; anInd < aLen; anInd++)
1444 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1446 return aResult._retn();
1449 //============================================================================
1450 /*! Function : RemoveVariable
1453 //============================================================================
1454 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1457 throw SALOMEDS::Study::StudyInvalidReference();
1459 bool res = _impl->RemoveVariable(std::string(theVarName));
1460 if (res && _notifier)
1461 _notifier->modifyNB_Notification(theVarName);
1466 //============================================================================
1467 /*! Function : RenameVariable
1470 //============================================================================
1471 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1474 throw SALOMEDS::Study::StudyInvalidReference();
1476 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1477 if (res && _notifier)
1478 _notifier->modifyNB_Notification(theVarName);
1483 //============================================================================
1484 /*! Function : IsVariableUsed
1487 //============================================================================
1488 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1491 throw SALOMEDS::Study::StudyInvalidReference();
1493 return _impl->IsVariableUsed(std::string(theVarName));
1497 //============================================================================
1498 /*! Function : ParseVariables
1501 //============================================================================
1502 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1505 throw SALOMEDS::Study::StudyInvalidReference();
1507 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1509 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1511 int aSectionsLen = aSections.size();
1512 aResult->length(aSectionsLen);
1514 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1515 std::vector<std::string> aVarNames = aSections[aSectionInd];
1517 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1519 int aLen = aVarNames.size();
1520 aList->length(aLen);
1522 for (int anInd = 0; anInd < aLen; anInd++)
1523 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1525 aResult[aSectionInd] = aList;
1528 return aResult._retn();
1531 //============================================================================
1532 /*! Function : GetDefaultScript
1535 //============================================================================
1536 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1538 SALOMEDS::Locker lock;
1541 throw SALOMEDS::Study::StudyInvalidReference();
1543 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1544 return CORBA::string_dup(script.c_str());
1547 //============================================================================
1548 /*! Function : EnableUseCaseAutoFilling
1551 //============================================================================
1552 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1555 throw SALOMEDS::Study::StudyInvalidReference();
1557 _impl->EnableUseCaseAutoFilling(isEnabled);
1558 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1561 builder->SetOnAddSObject(_impl->GetCallback());
1562 builder->SetOnRemoveSObject(_impl->GetCallback());
1565 builder->SetOnAddSObject(NULL);
1566 builder->SetOnRemoveSObject(NULL);
1572 CORBA::Long SALOMEDS_Study_i::getPID()
1575 return (CORBA::Long)_getpid();
1577 return (CORBA::Long)getpid();
1581 void SALOMEDS_Study_i::ShutdownWithExit()
1583 exit( EXIT_SUCCESS );
1586 void SALOMEDS_Study_i::Shutdown()
1588 if(!CORBA::is_nil(_orb))
1592 //============================================================================
1593 /*! Function : attach
1594 * Purpose : This function attach an observer to the study
1596 //============================================================================
1597 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1600 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1604 //============================================================================
1605 /*! Function : detach
1606 * Purpose : This function detaches an observer from the study
1608 //============================================================================
1609 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1612 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1615 //===========================================================================
1616 // PRIVATE FUNCTIONS
1617 //===========================================================================
1618 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1621 long pid = (long)_getpid();
1623 long pid = (long)getpid();
1625 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1626 return reinterpret_cast<CORBA::LongLong>(_impl);
1629 void SALOMEDS_Study_i::NameChanged()
1631 // Notify GUI that the name of study was changed
1632 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1633 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
1634 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1635 if ( !CORBA::is_nil(aSession) ) {
1636 std::stringstream ss;
1637 ss << "studyNameChanged";
1638 std::string str = ss.str();
1640 aSession->emitMessageOneWay(str.c_str());