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_StudyManager_i.hxx"
31 #include "SALOMEDS_UseCaseIterator_i.hxx"
32 #include "SALOMEDS_GenericAttribute_i.hxx"
33 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
34 #include "SALOMEDS_AttributeParameter_i.hxx"
35 #include "SALOMEDS_ChildIterator_i.hxx"
36 #include "SALOMEDS_Driver_i.hxx"
37 #include "SALOMEDS.hxx"
39 #include "SALOMEDSImpl_SObject.hxx"
40 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
42 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
43 #include "SALOMEDSImpl_AttributeParameter.hxx"
44 #include "SALOMEDSImpl_ChildIterator.hxx"
45 #include "SALOMEDSImpl_IParameters.hxx"
46 #include "SALOMEDSImpl_Callback.hxx"
48 #include "DF_Label.hxx"
49 #include "DF_Attribute.hxx"
51 #include "Basics_Utils.hxx"
52 #include "SALOME_KernelServices.hxx"
57 #include <sys/types.h>
63 class Notifier: public SALOMEDSImpl_AbstractCallback
66 Notifier(CORBA::ORB_ptr orb)
68 _orb = CORBA::ORB::_duplicate(orb);
71 //============================================================================
72 /*! Function : addSO_Notification
73 * Purpose : This function tells all the observers that a SO has been added
75 //============================================================================
77 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
79 std::string anID=theSObject.GetID();
80 const char* cID=anID.c_str();
81 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
83 it->first->notifyObserverID(cID,1);
85 return true; // NGE return always true but can be modified if needed
88 //============================================================================
89 /*! Function : removeSO_Notification
90 * Purpose : This function tells all the observers that a SO has been removed
92 //============================================================================
94 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
96 std::string anID=theSObject.GetID();
97 const char* cID=anID.c_str();
98 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
100 it->first->notifyObserverID(cID,2);
102 return true; // NGE return always true but can be modified if needed
105 //============================================================================
106 /*! Function : modifySO_Notification
107 * Purpose : This function tells all the observers that a SO has been modified
109 //============================================================================
111 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
113 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
117 std::string anID=theSObject.GetID();
118 const char* cID=anID.c_str();
119 it->first->notifyObserverID(cID,reason);
122 return true; // NGE return always true but can be modified if needed
125 //============================================================================
126 /*! Function : modifyNB_Notification
127 * Purpose : This function tells all the observers that
128 * a NoteBook variable has been added/modified/removed.
130 //============================================================================
132 virtual bool modifyNB_Notification(const char* theVarName)
134 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
136 it->first->notifyObserverID(theVarName,6);
138 return true; // NGE return always true but can be modified if needed
141 //============================================================================
142 /*! Function : attach
143 * Purpose : register an Observer
145 //============================================================================
147 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
149 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
152 //============================================================================
153 /*! Function : detach
154 * Purpose : unregister an Observer
156 //============================================================================
158 virtual void detach(SALOMEDS::Observer_ptr theObs)
160 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
162 if ( it->first->_is_equivalent(theObs) ) {
163 myObservers.erase( it );
170 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
171 typedef ObsList::iterator ObsListIter;
176 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
179 GenObjRegister(CORBA::ORB_ptr orb)
181 _orb = CORBA::ORB::_duplicate(orb);
183 virtual void RegisterGenObj (const std::string& theIOR)
187 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
188 if ( obj->_non_existent() ) return;
189 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
190 if(! CORBA::is_nil(gobj) )
195 catch(const CORBA::Exception& e)
199 virtual void UnRegisterGenObj(const std::string& theIOR)
203 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
204 if ( obj->_non_existent() ) return;
205 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
206 if(! CORBA::is_nil(gobj) )
211 catch(const CORBA::Exception& e)
220 } // namespace SALOMEDS
222 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
224 //============================================================================
225 /*! Function : SALOMEDS_Study_i
226 * Purpose : SALOMEDS_Study_i constructor
228 //============================================================================
229 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
232 _orb = CORBA::ORB::_duplicate(orb);
234 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
235 _notifier = new SALOMEDS::Notifier(_orb);
236 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
239 theImpl->setNotifier(_notifier);
240 theImpl->setGenObjRegister( _genObjRegister );
242 // Notify GUI that study was created
243 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
244 CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
245 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
246 if ( !CORBA::is_nil(aSession) ) {
247 std::stringstream ss;
248 ss << "studyCreated:" << theImpl->StudyId();
249 std::string str = ss.str();
251 aSession->emitMessageOneWay(str.c_str());
256 //============================================================================
257 /*! Function : ~SALOMEDS_Study_i
258 * Purpose : SALOMEDS_Study_i destructor
260 //============================================================================
261 SALOMEDS_Study_i::~SALOMEDS_Study_i()
263 //delete the builder servant
264 PortableServer::POA_var poa=_builder->_default_POA();
265 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
266 poa->deactivate_object(anObjectId.in());
267 _builder->_remove_ref();
269 _impl->setNotifier(0);
271 delete _genObjRegister;
272 //delete implementation
274 _mapOfStudies.erase(_impl);
277 //============================================================================
279 \brief Get default POA for the servant object.
281 This function is implicitly called from "_this()" function.
282 Default POA can be set via the constructor.
284 \return reference to the default POA for the servant
286 //============================================================================
287 PortableServer::POA_ptr SALOMEDS_Study_i::_default_POA()
289 PortableServer::POA_ptr poa = SALOMEDS_StudyManager_i::GetThePOA();
290 MESSAGE("SALOMEDS_Study_i::_default_POA: " << poa);
291 return PortableServer::POA::_duplicate(poa);
294 //============================================================================
295 /*! Function : GetPersistentReference
296 * Purpose : Get persistent reference of study (idem URL())
298 //============================================================================
299 char* SALOMEDS_Study_i::GetPersistentReference()
301 SALOMEDS::Locker lock;
303 throw SALOMEDS::Study::StudyInvalidReference();
304 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
306 //============================================================================
307 /*! Function : GetTransientReference
308 * Purpose : Get IOR of the Study (registered in OCAF document in doc->Root)
310 //============================================================================
311 char* SALOMEDS_Study_i::GetTransientReference()
313 SALOMEDS::Locker lock;
315 throw SALOMEDS::Study::StudyInvalidReference();
316 return CORBA::string_dup(_impl->GetTransientReference().c_str());
319 //============================================================================
320 /*! Function : IsEmpty
321 * Purpose : Detect if study is empty
323 //============================================================================
324 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
326 SALOMEDS::Locker lock;
328 throw SALOMEDS::Study::StudyInvalidReference();
329 return _impl->IsEmpty();
332 //============================================================================
333 /*! Function : FindComponent
334 * Purpose : Find a Component with ComponentDataType = aComponentName
336 //============================================================================
337 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
339 SALOMEDS::Locker lock;
342 throw SALOMEDS::Study::StudyInvalidReference();
344 SALOMEDS::SComponent_var sco;
346 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
347 if (!aCompImpl.IsNull())
348 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
353 //============================================================================
354 /*! Function : FindComponentID
355 * Purpose : Find a Component from it's ID
357 //============================================================================
358 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
360 SALOMEDS::Locker lock;
363 throw SALOMEDS::Study::StudyInvalidReference();
365 SALOMEDS::SComponent_var sco;
367 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
368 if (!aCompImpl.IsNull())
369 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
374 //============================================================================
375 /*! Function : FindObject
376 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
378 //============================================================================
379 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
381 SALOMEDS::Locker lock;
384 throw SALOMEDS::Study::StudyInvalidReference();
386 SALOMEDS::SObject_var so;
388 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
390 if (aSO.IsComponent()) {
391 SALOMEDSImpl_SComponent aSCO = aSO;
392 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
395 so = SALOMEDS_SObject_i::New(aSO, _orb);
402 //============================================================================
403 /*! Function : FindObjectID
404 * Purpose : Find an Object with ID = anObjectID
406 //============================================================================
407 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
409 SALOMEDS::Locker lock;
412 throw SALOMEDS::Study::StudyInvalidReference();
414 SALOMEDS::SObject_var so;
416 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
418 so = SALOMEDS_SObject_i::New(aSO, _orb);
423 //============================================================================
424 /*! Function : CreateObjectID
425 * Purpose : Creates an Object with ID = anObjectID
427 //============================================================================
428 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
430 SALOMEDS::Locker lock;
433 throw SALOMEDS::Study::StudyInvalidReference();
435 SALOMEDS::SObject_var so;
437 if (anObjectID && strlen(anObjectID) > 0) {
438 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
440 so = SALOMEDS_SObject_i::New(aSO, _orb);
446 //============================================================================
447 /*! Function : FindObjectByName
448 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
449 * : with ComponentDataType = aComponentName
451 //============================================================================
452 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
453 const char* aComponentName )
455 SALOMEDS::Locker lock;
458 throw SALOMEDS::Study::StudyInvalidReference();
460 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
461 std::string((char*)aComponentName));
463 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
464 int aLength = aSeq.size();
465 listSO->length(aLength);
466 for (int i = 0; i < aLength; i++) {
467 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
471 return listSO._retn();
474 //============================================================================
475 /*! Function : FindObjectIOR
476 * Purpose : Find an Object with IOR = anObjectIOR
478 //============================================================================
479 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
481 SALOMEDS::Locker lock;
484 throw SALOMEDS::Study::StudyInvalidReference();
486 SALOMEDS::SObject_var so;
488 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
490 so = SALOMEDS_SObject_i::New(aSO, _orb);
495 //============================================================================
496 /*! Function : FindObjectByPath
497 * Purpose : Find an Object by its path = thePath
499 //============================================================================
500 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
502 SALOMEDS::Locker lock;
505 throw SALOMEDS::Study::StudyInvalidReference();
507 SALOMEDS::SObject_var so;
509 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
511 so = SALOMEDS_SObject_i::New (aSO, _orb);
516 //============================================================================
517 /*! Function : GetObjectPath
520 //============================================================================
521 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
523 SALOMEDS::Locker lock;
526 throw SALOMEDS::Study::StudyInvalidReference();
528 std::string aPath = "";
530 if (!CORBA::is_nil(theObject)) {
531 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
532 SALOMEDSImpl_SObject aSO;
534 if (!CORBA::is_nil(aSObj)) {
535 aSO = _impl->FindObjectID(aSObj->GetID());
538 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
542 aPath = _impl->GetObjectPath(aSO);
546 return CORBA::string_dup(aPath.c_str());
550 //============================================================================
551 /*! Function : SetContext
552 * Purpose : Sets the current context
554 //============================================================================
555 void SALOMEDS_Study_i::SetContext(const char* thePath)
557 SALOMEDS::Locker lock;
560 throw SALOMEDS::Study::StudyInvalidReference();
562 _impl->SetContext(std::string((char*)thePath));
563 if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
564 throw SALOMEDS::Study::StudyInvalidContext();
567 //============================================================================
568 /*! Function : GetContext
569 * Purpose : Gets the current context
571 //============================================================================
572 char* SALOMEDS_Study_i::GetContext()
574 SALOMEDS::Locker lock;
577 throw SALOMEDS::Study::StudyInvalidReference();
579 if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
581 return CORBA::string_dup(_impl->GetContext().c_str());
584 //============================================================================
585 /*! Function : GetObjectNames
586 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
588 //============================================================================
589 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
591 SALOMEDS::Locker lock;
594 throw SALOMEDS::Study::StudyInvalidReference();
596 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
598 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
599 throw SALOMEDS::Study::StudyInvalidContext();
601 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
602 if (_impl->GetErrorCode() == "InvalidContext")
603 throw SALOMEDS::Study::StudyInvalidContext();
605 int aLength = aSeq.size();
606 aResult->length(aLength);
607 for (int anIndex = 0; anIndex < aLength; anIndex++) {
608 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
611 return aResult._retn();
614 //============================================================================
615 /*! Function : GetDirectoryNames
616 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
618 //============================================================================
619 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
621 SALOMEDS::Locker lock;
624 throw SALOMEDS::Study::StudyInvalidReference();
626 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
628 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
629 throw SALOMEDS::Study::StudyInvalidContext();
631 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
632 if (_impl->GetErrorCode() == "InvalidContext")
633 throw SALOMEDS::Study::StudyInvalidContext();
635 int aLength = aSeq.size();
636 aResult->length(aLength);
637 for (int anIndex = 0; anIndex < aLength; anIndex++) {
638 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
641 return aResult._retn();
644 //============================================================================
645 /*! Function : GetFileNames
646 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
648 //============================================================================
649 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
651 SALOMEDS::Locker lock;
654 throw SALOMEDS::Study::StudyInvalidReference();
656 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
658 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
659 throw SALOMEDS::Study::StudyInvalidContext();
661 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
662 if (_impl->GetErrorCode() == "InvalidContext")
663 throw SALOMEDS::Study::StudyInvalidContext();
665 int aLength = aSeq.size();
666 aResult->length(aLength);
667 for (int anIndex = 0; anIndex < aLength; anIndex++) {
668 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
671 return aResult._retn();
674 //============================================================================
675 /*! Function : GetComponentNames
676 * Purpose : method to get all components names
677 * SRN: Note, theContext can be any, it doesn't matter
679 //============================================================================
680 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
682 SALOMEDS::Locker lock;
685 throw SALOMEDS::Study::StudyInvalidReference();
687 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
689 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
691 int aLength = aSeq.size();
692 aResult->length(aLength);
693 for(int anIndex = 0; anIndex < aLength; anIndex++) {
694 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
697 return aResult._retn();
700 //============================================================================
701 /*! Function : NewChildIterator
702 * Purpose : Create a ChildIterator from an SObject
704 //============================================================================
705 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
707 SALOMEDS::Locker lock;
710 throw SALOMEDS::Study::StudyInvalidReference();
712 CORBA::String_var anID = theSO->GetID();
713 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
714 SALOMEDSImpl_ChildIterator anItr(aSO);
715 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
716 SALOMEDS::ChildIterator_var it = it_servant->_this();
722 //============================================================================
723 /*! Function : NewComponentIterator
724 * Purpose : Create a SComponentIterator
726 //============================================================================
727 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
729 SALOMEDS::Locker lock;
732 throw SALOMEDS::Study::StudyInvalidReference();
734 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
736 SALOMEDS::SComponentIterator_var it = it_servant->_this();
742 //============================================================================
743 /*! Function : NewBuilder
744 * Purpose : Create a StudyBuilder
746 //============================================================================
747 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
749 SALOMEDS::Locker lock;
752 throw SALOMEDS::Study::StudyInvalidReference();
754 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
759 //============================================================================
761 * Purpose : get study name
763 //============================================================================
764 char* SALOMEDS_Study_i::Name()
766 SALOMEDS::Locker lock;
767 // Name is specified as IDL attribute: user exception cannot be raised
768 return CORBA::string_dup(_impl->Name().c_str());
771 //============================================================================
773 * Purpose : set study name
775 //============================================================================
776 void SALOMEDS_Study_i::Name(const char* name)
778 SALOMEDS::Locker lock;
779 // Name is specified as IDL attribute: user exception cannot be raised
780 _impl->Name(std::string(name));
783 //============================================================================
784 /*! Function : IsSaved
785 * Purpose : get if study has been saved
787 //============================================================================
788 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
790 SALOMEDS::Locker lock;
791 // IsSaved is specified as IDL attribute: user exception cannot be raised
792 return (!_closed) ? _impl->IsSaved() : false;
795 //============================================================================
796 /*! Function : IsSaved
797 * Purpose : set if study has been saved
799 //============================================================================
800 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
802 SALOMEDS::Locker lock;
803 // IsSaved is specified as IDL attribute: user exception cannot be raised
805 _impl->IsSaved(save);
808 //============================================================================
809 /*! Function : IsModified
810 * Purpose : Detect if a Study has been modified since it has been saved
812 //============================================================================
813 CORBA::Boolean SALOMEDS_Study_i::IsModified()
815 SALOMEDS::Locker lock;
818 throw SALOMEDS::Study::StudyInvalidReference();
820 return _impl->IsModified();
823 //============================================================================
824 /*! Function : Modified
825 * Purpose : Sets a Modified flag of a Study to True
827 //============================================================================
828 void SALOMEDS_Study_i::Modified()
830 SALOMEDS::Locker lock;
833 throw SALOMEDS::Study::StudyInvalidReference();
838 //============================================================================
840 * Purpose : get URL of the study (persistent reference of the study)
842 //============================================================================
843 char* SALOMEDS_Study_i::URL()
845 SALOMEDS::Locker lock;
846 // URL is specified as IDL attribute: user exception cannot be raised
847 return CORBA::string_dup(_impl->URL().c_str());
850 //============================================================================
852 * Purpose : set URL of the study (persistent reference of the study)
854 //============================================================================
855 void SALOMEDS_Study_i::URL(const char* url)
857 SALOMEDS::Locker lock;
858 // URL is specified as IDL attribute: user exception cannot be raised
859 _impl->URL(std::string((char*)url));
862 CORBA::Short SALOMEDS_Study_i::StudyId()
864 SALOMEDS::Locker lock;
865 // StudyId is specified as IDL attribute: user exception cannot be raised
866 return _impl->StudyId();
869 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
871 SALOMEDS::Locker lock;
872 // StudyId is specified as IDL attribute: user exception cannot be raised
876 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
878 SALOMEDS::Locker lock;
881 throw SALOMEDS::Study::StudyInvalidReference();
883 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
886 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
888 SALOMEDS::Locker lock;
890 SALOMEDSImpl_AttributeIOR* Att = NULL;
891 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
892 char* IOR = CORBA::string_dup(Att->Value().c_str());
893 CORBA::Object_var obj = orb->string_to_object(IOR);
894 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
895 ASSERT(!CORBA::is_nil(aStudy));
896 return SALOMEDS::Study::_duplicate(aStudy);
898 MESSAGE("GetStudy: Problem to get study");
900 return SALOMEDS::Study::_nil();
903 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
905 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
906 return _mapOfStudies[aStudyImpl];
909 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
910 _mapOfStudies[aStudyImpl]=Study_servant;
911 return Study_servant;
915 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
917 SALOMEDS::Locker lock;
918 SALOMEDSImpl_Study::IORUpdated(theAttribute);
921 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
923 SALOMEDS::Locker lock;
926 throw SALOMEDS::Study::StudyInvalidReference();
928 SALOMEDS::GenericAttribute_ptr aTarget;
929 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
930 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
932 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
938 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
940 SALOMEDS::Locker lock;
943 throw SALOMEDS::Study::StudyInvalidReference();
945 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
946 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
947 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
948 return aProp._retn();
951 char* SALOMEDS_Study_i::GetLastModificationDate()
953 SALOMEDS::Locker lock;
956 throw SALOMEDS::Study::StudyInvalidReference();
958 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
961 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
963 SALOMEDS::Locker lock;
966 throw SALOMEDS::Study::StudyInvalidReference();
968 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
970 std::vector<std::string> aSeq = _impl->GetModificationsDate();
972 int aLength = aSeq.size();
973 aDates->length(aLength);
974 for (int anIndex = 0; anIndex < aLength; anIndex++) {
975 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
978 return aDates._retn();
981 //============================================================================
982 /*! Function : GetUseCaseBuilder
983 * Purpose : Returns a UseCase builder
985 //============================================================================
986 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
988 SALOMEDS::Locker lock;
991 throw SALOMEDS::Study::StudyInvalidReference();
993 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
994 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
999 //============================================================================
1000 /*! Function : Close
1003 //============================================================================
1004 void SALOMEDS_Study_i::Close()
1006 SALOMEDS::Locker lock;
1009 throw SALOMEDS::Study::StudyInvalidReference();
1011 RemovePostponed(-1);
1013 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
1014 for (; itcomponent->More(); itcomponent->Next()) {
1015 SALOMEDS::SComponent_var sco = itcomponent->Value();
1016 CORBA::String_var compodatatype=sco->ComponentDataType();
1017 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
1018 // if there is an associated Engine call its method for closing
1019 CORBA::String_var IOREngine;
1020 if (sco->ComponentIOR(IOREngine)) {
1021 // we have found the associated engine to write the data
1022 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
1023 //_narrow can throw a corba exception
1025 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
1026 if (!CORBA::is_nil(obj)) {
1027 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
1028 if (!anEngine->_is_nil()) {
1030 anEngine->Close(sco);
1035 catch (CORBA::Exception&) {
1041 //Does not need any more this iterator
1042 itcomponent->UnRegister();
1044 // Notify GUI that study is closed
1045 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1046 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
1047 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1048 if ( !CORBA::is_nil(aSession) ) {
1049 std::stringstream ss;
1050 ss << "studyClosed:" << _impl->StudyId();
1051 std::string str = ss.str();
1053 aSession->emitMessageOneWay(str.c_str());
1061 //============================================================================
1062 /*! Function : AddPostponed
1065 //============================================================================
1066 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1068 SALOMEDS::Locker lock;
1072 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1074 SALOMEDS::Locker lock;
1078 //============================================================================
1079 /*! Function : RemovePostponed
1082 //============================================================================
1083 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1085 SALOMEDS::Locker lock;
1088 throw SALOMEDS::Study::StudyInvalidReference();
1090 std::vector<std::string> anIORs = _impl->GetIORs();
1091 int i, aSize = (int)anIORs.size();
1093 for (i = 0; i < aSize; i++) {
1095 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1096 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1097 //rnv: To avoid double deletion of the Salome Generic Objects:
1098 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1099 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1100 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1107 //============================================================================
1108 /*! Function : UndoPostponed
1111 //============================================================================
1112 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1114 SALOMEDS::Locker lock;
1119 //============================================================================
1120 /*! Function : DumpStudy
1123 //============================================================================
1124 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1125 const char* theBaseName,
1126 CORBA::Boolean isPublished,
1127 CORBA::Boolean isMultiFile)
1129 SALOMEDS::Locker lock;
1132 throw SALOMEDS::Study::StudyInvalidReference();
1134 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1135 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1136 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1142 //============================================================================
1143 /*! Function : GetCommonParameters
1146 //============================================================================
1147 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1149 SALOMEDS::Locker lock;
1152 throw SALOMEDS::Study::StudyInvalidReference();
1154 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1155 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1156 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1158 return aParam._retn();
1161 //============================================================================
1162 /*! Function : GetCommonModuleParameters
1165 //============================================================================
1166 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1167 const char* theModuleName,
1168 CORBA::Long theSavePoint)
1170 SALOMEDS::Locker lock;
1173 throw SALOMEDS::Study::StudyInvalidReference();
1175 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1176 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1177 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1179 return aParam._retn();
1182 //============================================================================
1183 /*! Function : SetStudyLock
1186 //============================================================================
1187 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1189 SALOMEDS::Locker lock;
1192 throw SALOMEDS::Study::StudyInvalidReference();
1194 _impl->SetStudyLock(theLockerID);
1197 //============================================================================
1198 /*! Function : IsStudyLocked
1201 //============================================================================
1202 bool SALOMEDS_Study_i::IsStudyLocked()
1204 SALOMEDS::Locker lock;
1207 throw SALOMEDS::Study::StudyInvalidReference();
1209 return _impl->IsStudyLocked();
1212 //============================================================================
1213 /*! Function : UnLockStudy
1216 //============================================================================
1217 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1219 SALOMEDS::Locker lock;
1222 throw SALOMEDS::Study::StudyInvalidReference();
1224 _impl->UnLockStudy(theLockerID);
1227 //============================================================================
1228 /*! Function : GetLockerID
1231 //============================================================================
1232 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1234 SALOMEDS::Locker lock;
1237 throw SALOMEDS::Study::StudyInvalidReference();
1239 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1241 std::vector<std::string> aSeq = _impl->GetLockerID();
1243 int aLength = aSeq.size();
1244 aResult->length(aLength);
1245 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1246 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1249 return aResult._retn();
1251 //============================================================================
1252 /*! Function : SetReal
1255 //============================================================================
1256 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1259 throw SALOMEDS::Study::StudyInvalidReference();
1262 _impl->SetVariable(std::string(theVarName),
1264 SALOMEDSImpl_GenericVariable::REAL_VAR);
1266 _notifier->modifyNB_Notification(theVarName);
1269 //============================================================================
1270 /*! Function : SetInteger
1273 //============================================================================
1274 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1277 throw SALOMEDS::Study::StudyInvalidReference();
1279 _impl->SetVariable(std::string(theVarName),
1281 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1283 _notifier->modifyNB_Notification(theVarName);
1286 //============================================================================
1287 /*! Function : SetBoolean
1290 //============================================================================
1291 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1294 throw SALOMEDS::Study::StudyInvalidReference();
1296 _impl->SetVariable(std::string(theVarName),
1298 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1300 _notifier->modifyNB_Notification(theVarName);
1303 //============================================================================
1304 /*! Function : SetString
1307 //============================================================================
1308 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1311 throw SALOMEDS::Study::StudyInvalidReference();
1313 _impl->SetStringVariable(std::string(theVarName),
1315 SALOMEDSImpl_GenericVariable::STRING_VAR);
1317 _notifier->modifyNB_Notification(theVarName);
1320 //============================================================================
1321 /*! Function : SetStringAsDouble
1324 //============================================================================
1325 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1328 throw SALOMEDS::Study::StudyInvalidReference();
1330 _impl->SetStringVariableAsDouble(std::string(theVarName),
1332 SALOMEDSImpl_GenericVariable::STRING_VAR);
1335 //============================================================================
1336 /*! Function : GetReal
1339 //============================================================================
1340 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1343 throw SALOMEDS::Study::StudyInvalidReference();
1345 return _impl->GetVariableValue(std::string(theVarName));
1348 //============================================================================
1349 /*! Function : GetInteger
1352 //============================================================================
1353 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1356 throw SALOMEDS::Study::StudyInvalidReference();
1358 return (long)_impl->GetVariableValue(std::string(theVarName));
1361 //============================================================================
1362 /*! Function : GetBoolean
1365 //============================================================================
1366 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1369 throw SALOMEDS::Study::StudyInvalidReference();
1371 return (bool)_impl->GetVariableValue(std::string(theVarName));
1374 //============================================================================
1375 /*! Function : GetString
1378 //============================================================================
1379 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1382 throw SALOMEDS::Study::StudyInvalidReference();
1384 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1387 //============================================================================
1388 /*! Function : IsReal
1391 //============================================================================
1392 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1395 throw SALOMEDS::Study::StudyInvalidReference();
1397 return _impl->IsTypeOf(std::string(theVarName),
1398 SALOMEDSImpl_GenericVariable::REAL_VAR);
1401 //============================================================================
1402 /*! Function : IsInteger
1405 //============================================================================
1406 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1409 throw SALOMEDS::Study::StudyInvalidReference();
1411 return _impl->IsTypeOf(std::string(theVarName),
1412 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1415 //============================================================================
1416 /*! Function : IsBoolean
1419 //============================================================================
1420 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1423 throw SALOMEDS::Study::StudyInvalidReference();
1425 return _impl->IsTypeOf(std::string(theVarName),
1426 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1429 //============================================================================
1430 /*! Function : IsString
1433 //============================================================================
1434 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1437 throw SALOMEDS::Study::StudyInvalidReference();
1439 return _impl->IsTypeOf(std::string(theVarName),
1440 SALOMEDSImpl_GenericVariable::STRING_VAR);
1443 //============================================================================
1444 /*! Function : IsVariable
1447 //============================================================================
1448 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1451 throw SALOMEDS::Study::StudyInvalidReference();
1453 return _impl->IsVariable(std::string(theVarName));
1456 //============================================================================
1457 /*! Function : GetVariableNames
1460 //============================================================================
1461 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1464 throw SALOMEDS::Study::StudyInvalidReference();
1466 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1468 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1470 int aLen = aVarNames.size();
1471 aResult->length(aLen);
1472 for (int anInd = 0; anInd < aLen; anInd++)
1473 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1475 return aResult._retn();
1478 //============================================================================
1479 /*! Function : RemoveVariable
1482 //============================================================================
1483 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1486 throw SALOMEDS::Study::StudyInvalidReference();
1488 bool res = _impl->RemoveVariable(std::string(theVarName));
1489 if (res && _notifier)
1490 _notifier->modifyNB_Notification(theVarName);
1495 //============================================================================
1496 /*! Function : RenameVariable
1499 //============================================================================
1500 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1503 throw SALOMEDS::Study::StudyInvalidReference();
1505 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1506 if (res && _notifier)
1507 _notifier->modifyNB_Notification(theVarName);
1512 //============================================================================
1513 /*! Function : IsVariableUsed
1516 //============================================================================
1517 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1520 throw SALOMEDS::Study::StudyInvalidReference();
1522 return _impl->IsVariableUsed(std::string(theVarName));
1526 //============================================================================
1527 /*! Function : ParseVariables
1530 //============================================================================
1531 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1534 throw SALOMEDS::Study::StudyInvalidReference();
1536 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1538 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1540 int aSectionsLen = aSections.size();
1541 aResult->length(aSectionsLen);
1543 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1544 std::vector<std::string> aVarNames = aSections[aSectionInd];
1546 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1548 int aLen = aVarNames.size();
1549 aList->length(aLen);
1551 for (int anInd = 0; anInd < aLen; anInd++)
1552 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1554 aResult[aSectionInd] = aList;
1557 return aResult._retn();
1560 //============================================================================
1561 /*! Function : GetDefaultScript
1564 //============================================================================
1565 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1567 SALOMEDS::Locker lock;
1570 throw SALOMEDS::Study::StudyInvalidReference();
1572 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1573 return CORBA::string_dup(script.c_str());
1576 //============================================================================
1577 /*! Function : EnableUseCaseAutoFilling
1580 //============================================================================
1581 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1584 throw SALOMEDS::Study::StudyInvalidReference();
1586 _impl->EnableUseCaseAutoFilling(isEnabled);
1587 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1590 builder->SetOnAddSObject(_impl->GetCallback());
1591 builder->SetOnRemoveSObject(_impl->GetCallback());
1594 builder->SetOnAddSObject(NULL);
1595 builder->SetOnRemoveSObject(NULL);
1600 //============================================================================
1601 /*! Function : attach
1602 * Purpose : This function attach an observer to the study
1604 //============================================================================
1605 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1608 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1612 //============================================================================
1613 /*! Function : detach
1614 * Purpose : This function detaches an observer from the study
1616 //============================================================================
1617 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1620 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1623 //===========================================================================
1624 // PRIVATE FUNCTIONS
1625 //===========================================================================
1626 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1629 long pid = (long)_getpid();
1631 long pid = (long)getpid();
1633 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1634 return reinterpret_cast<CORBA::LongLong>(_impl);