1 // Copyright (C) 2007-2014 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 //============================================================================
278 /*! Function : GetPersistentReference
279 * Purpose : Get persistent reference of study (idem URL())
281 //============================================================================
282 char* SALOMEDS_Study_i::GetPersistentReference()
284 SALOMEDS::Locker lock;
286 throw SALOMEDS::Study::StudyInvalidReference();
287 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
289 //============================================================================
290 /*! Function : GetTransientReference
291 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
293 //============================================================================
294 char* SALOMEDS_Study_i::GetTransientReference()
296 SALOMEDS::Locker lock;
298 throw SALOMEDS::Study::StudyInvalidReference();
299 return CORBA::string_dup(_impl->GetTransientReference().c_str());
302 //============================================================================
303 /*! Function : IsEmpty
304 * Purpose : Detect if study is empty
306 //============================================================================
307 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
309 SALOMEDS::Locker lock;
311 throw SALOMEDS::Study::StudyInvalidReference();
312 return _impl->IsEmpty();
315 //============================================================================
316 /*! Function : FindComponent
317 * Purpose : Find a Component with ComponentDataType = aComponentName
319 //============================================================================
320 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
322 SALOMEDS::Locker lock;
325 throw SALOMEDS::Study::StudyInvalidReference();
327 SALOMEDS::SComponent_var sco;
329 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
330 if (!aCompImpl.IsNull())
331 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
336 //============================================================================
337 /*! Function : FindComponentID
338 * Purpose : Find a Component from it's ID
340 //============================================================================
341 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
343 SALOMEDS::Locker lock;
346 throw SALOMEDS::Study::StudyInvalidReference();
348 SALOMEDS::SComponent_var sco;
350 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
351 if (!aCompImpl.IsNull())
352 sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
357 //============================================================================
358 /*! Function : FindObject
359 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
361 //============================================================================
362 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
364 SALOMEDS::Locker lock;
367 throw SALOMEDS::Study::StudyInvalidReference();
369 SALOMEDS::SObject_var so;
371 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
373 if (aSO.IsComponent()) {
374 SALOMEDSImpl_SComponent aSCO = aSO;
375 so = SALOMEDS_SComponent_i::New(aSCO, _orb);
378 so = SALOMEDS_SObject_i::New(aSO, _orb);
385 //============================================================================
386 /*! Function : FindObjectID
387 * Purpose : Find an Object with ID = anObjectID
389 //============================================================================
390 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
392 SALOMEDS::Locker lock;
395 throw SALOMEDS::Study::StudyInvalidReference();
397 SALOMEDS::SObject_var so;
399 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
401 so = SALOMEDS_SObject_i::New(aSO, _orb);
406 //============================================================================
407 /*! Function : CreateObjectID
408 * Purpose : Creates an Object with ID = anObjectID
410 //============================================================================
411 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
413 SALOMEDS::Locker lock;
416 throw SALOMEDS::Study::StudyInvalidReference();
418 SALOMEDS::SObject_var so;
420 if (anObjectID && strlen(anObjectID) > 0) {
421 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
423 so = SALOMEDS_SObject_i::New(aSO, _orb);
429 //============================================================================
430 /*! Function : FindObjectByName
431 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
432 * : with ComponentDataType = aComponentName
434 //============================================================================
435 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
436 const char* aComponentName )
438 SALOMEDS::Locker lock;
441 throw SALOMEDS::Study::StudyInvalidReference();
443 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
444 std::string((char*)aComponentName));
446 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
447 int aLength = aSeq.size();
448 listSO->length(aLength);
449 for (int i = 0; i < aLength; i++) {
450 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
454 return listSO._retn();
457 //============================================================================
458 /*! Function : FindObjectIOR
459 * Purpose : Find an Object with IOR = anObjectIOR
461 //============================================================================
462 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
464 SALOMEDS::Locker lock;
467 throw SALOMEDS::Study::StudyInvalidReference();
469 SALOMEDS::SObject_var so;
471 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
473 so = SALOMEDS_SObject_i::New(aSO, _orb);
478 //============================================================================
479 /*! Function : FindObjectByPath
480 * Purpose : Find an Object by its path = thePath
482 //============================================================================
483 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
485 SALOMEDS::Locker lock;
488 throw SALOMEDS::Study::StudyInvalidReference();
490 SALOMEDS::SObject_var so;
492 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
494 so = SALOMEDS_SObject_i::New (aSO, _orb);
499 //============================================================================
500 /*! Function : GetObjectPath
503 //============================================================================
504 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
506 SALOMEDS::Locker lock;
509 throw SALOMEDS::Study::StudyInvalidReference();
511 std::string aPath = "";
513 if (!CORBA::is_nil(theObject)) {
514 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
515 SALOMEDSImpl_SObject aSO;
517 if (!CORBA::is_nil(aSObj)) {
518 aSO = _impl->FindObjectID(aSObj->GetID());
521 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
525 aPath = _impl->GetObjectPath(aSO);
529 return CORBA::string_dup(aPath.c_str());
533 //============================================================================
534 /*! Function : SetContext
535 * Purpose : Sets the current context
537 //============================================================================
538 void SALOMEDS_Study_i::SetContext(const char* thePath)
540 SALOMEDS::Locker lock;
543 throw SALOMEDS::Study::StudyInvalidReference();
545 _impl->SetContext(std::string((char*)thePath));
546 if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
547 throw SALOMEDS::Study::StudyInvalidContext();
550 //============================================================================
551 /*! Function : GetContext
552 * Purpose : Gets the current context
554 //============================================================================
555 char* SALOMEDS_Study_i::GetContext()
557 SALOMEDS::Locker lock;
560 throw SALOMEDS::Study::StudyInvalidReference();
562 if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
564 return CORBA::string_dup(_impl->GetContext().c_str());
567 //============================================================================
568 /*! Function : GetObjectNames
569 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
571 //============================================================================
572 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
574 SALOMEDS::Locker lock;
577 throw SALOMEDS::Study::StudyInvalidReference();
579 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
581 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
582 throw SALOMEDS::Study::StudyInvalidContext();
584 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
585 if (_impl->GetErrorCode() == "InvalidContext")
586 throw SALOMEDS::Study::StudyInvalidContext();
588 int aLength = aSeq.size();
589 aResult->length(aLength);
590 for (int anIndex = 0; anIndex < aLength; anIndex++) {
591 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
594 return aResult._retn();
597 //============================================================================
598 /*! Function : GetDirectoryNames
599 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
601 //============================================================================
602 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
604 SALOMEDS::Locker lock;
607 throw SALOMEDS::Study::StudyInvalidReference();
609 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
611 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
612 throw SALOMEDS::Study::StudyInvalidContext();
614 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
615 if (_impl->GetErrorCode() == "InvalidContext")
616 throw SALOMEDS::Study::StudyInvalidContext();
618 int aLength = aSeq.size();
619 aResult->length(aLength);
620 for (int anIndex = 0; anIndex < aLength; anIndex++) {
621 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
624 return aResult._retn();
627 //============================================================================
628 /*! Function : GetFileNames
629 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
631 //============================================================================
632 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
634 SALOMEDS::Locker lock;
637 throw SALOMEDS::Study::StudyInvalidReference();
639 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
641 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
642 throw SALOMEDS::Study::StudyInvalidContext();
644 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
645 if (_impl->GetErrorCode() == "InvalidContext")
646 throw SALOMEDS::Study::StudyInvalidContext();
648 int aLength = aSeq.size();
649 aResult->length(aLength);
650 for (int anIndex = 0; anIndex < aLength; anIndex++) {
651 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
654 return aResult._retn();
657 //============================================================================
658 /*! Function : GetComponentNames
659 * Purpose : method to get all components names
660 * SRN: Note, theContext can be any, it doesn't matter
662 //============================================================================
663 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
665 SALOMEDS::Locker lock;
668 throw SALOMEDS::Study::StudyInvalidReference();
670 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
672 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
674 int aLength = aSeq.size();
675 aResult->length(aLength);
676 for(int anIndex = 0; anIndex < aLength; anIndex++) {
677 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
680 return aResult._retn();
683 //============================================================================
684 /*! Function : NewChildIterator
685 * Purpose : Create a ChildIterator from an SObject
687 //============================================================================
688 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
690 SALOMEDS::Locker lock;
693 throw SALOMEDS::Study::StudyInvalidReference();
695 CORBA::String_var anID = theSO->GetID();
696 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
697 SALOMEDSImpl_ChildIterator anItr(aSO);
698 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
699 SALOMEDS::ChildIterator_var it = it_servant->_this();
705 //============================================================================
706 /*! Function : NewComponentIterator
707 * Purpose : Create a SComponentIterator
709 //============================================================================
710 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
712 SALOMEDS::Locker lock;
715 throw SALOMEDS::Study::StudyInvalidReference();
717 SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
719 SALOMEDS::SComponentIterator_var it = it_servant->_this();
725 //============================================================================
726 /*! Function : NewBuilder
727 * Purpose : Create a StudyBuilder
729 //============================================================================
730 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
732 SALOMEDS::Locker lock;
735 throw SALOMEDS::Study::StudyInvalidReference();
737 SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
742 //============================================================================
744 * Purpose : get study name
746 //============================================================================
747 char* SALOMEDS_Study_i::Name()
749 SALOMEDS::Locker lock;
750 // Name is specified as IDL attribute: user exception cannot be raised
751 return CORBA::string_dup(_impl->Name().c_str());
754 //============================================================================
756 * Purpose : set study name
758 //============================================================================
759 void SALOMEDS_Study_i::Name(const char* name)
761 SALOMEDS::Locker lock;
762 // Name is specified as IDL attribute: user exception cannot be raised
763 _impl->Name(std::string(name));
766 //============================================================================
767 /*! Function : IsSaved
768 * Purpose : get if study has been saved
770 //============================================================================
771 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
773 SALOMEDS::Locker lock;
774 // IsSaved is specified as IDL attribute: user exception cannot be raised
775 return (!_closed) ? _impl->IsSaved() : false;
778 //============================================================================
779 /*! Function : IsSaved
780 * Purpose : set if study has been saved
782 //============================================================================
783 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
785 SALOMEDS::Locker lock;
786 // IsSaved is specified as IDL attribute: user exception cannot be raised
788 _impl->IsSaved(save);
791 //============================================================================
792 /*! Function : IsModified
793 * Purpose : Detect if a Study has been modified since it has been saved
795 //============================================================================
796 CORBA::Boolean SALOMEDS_Study_i::IsModified()
798 SALOMEDS::Locker lock;
801 throw SALOMEDS::Study::StudyInvalidReference();
803 return _impl->IsModified();
806 //============================================================================
807 /*! Function : Modified
808 * Purpose : Sets a Modified flag of a Study to True
810 //============================================================================
811 void SALOMEDS_Study_i::Modified()
813 SALOMEDS::Locker lock;
816 throw SALOMEDS::Study::StudyInvalidReference();
821 //============================================================================
823 * Purpose : get URL of the study (persistent reference of the study)
825 //============================================================================
826 char* SALOMEDS_Study_i::URL()
828 SALOMEDS::Locker lock;
829 // URL is specified as IDL attribute: user exception cannot be raised
830 return CORBA::string_dup(_impl->URL().c_str());
833 //============================================================================
835 * Purpose : set URL of the study (persistent reference of the study)
837 //============================================================================
838 void SALOMEDS_Study_i::URL(const char* url)
840 SALOMEDS::Locker lock;
841 // URL is specified as IDL attribute: user exception cannot be raised
842 _impl->URL(std::string((char*)url));
845 CORBA::Short SALOMEDS_Study_i::StudyId()
847 SALOMEDS::Locker lock;
848 // StudyId is specified as IDL attribute: user exception cannot be raised
849 return _impl->StudyId();
852 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
854 SALOMEDS::Locker lock;
855 // StudyId is specified as IDL attribute: user exception cannot be raised
859 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry)
861 SALOMEDS::Locker lock;
864 throw SALOMEDS::Study::StudyInvalidReference();
866 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
869 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
871 SALOMEDS::Locker lock;
873 SALOMEDSImpl_AttributeIOR* Att = NULL;
874 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
875 char* IOR = CORBA::string_dup(Att->Value().c_str());
876 CORBA::Object_var obj = orb->string_to_object(IOR);
877 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
878 ASSERT(!CORBA::is_nil(aStudy));
879 return SALOMEDS::Study::_duplicate(aStudy);
881 MESSAGE("GetStudy: Problem to get study");
883 return SALOMEDS::Study::_nil();
886 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
888 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
889 return _mapOfStudies[aStudyImpl];
892 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
893 _mapOfStudies[aStudyImpl]=Study_servant;
894 return Study_servant;
898 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
900 SALOMEDS::Locker lock;
901 SALOMEDSImpl_Study::IORUpdated(theAttribute);
904 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
906 SALOMEDS::Locker lock;
909 throw SALOMEDS::Study::StudyInvalidReference();
911 SALOMEDS::GenericAttribute_ptr aTarget;
912 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
913 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
915 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
921 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
923 SALOMEDS::Locker lock;
926 throw SALOMEDS::Study::StudyInvalidReference();
928 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
929 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
930 SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
931 return aProp._retn();
934 char* SALOMEDS_Study_i::GetLastModificationDate()
936 SALOMEDS::Locker lock;
939 throw SALOMEDS::Study::StudyInvalidReference();
941 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
944 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
946 SALOMEDS::Locker lock;
949 throw SALOMEDS::Study::StudyInvalidReference();
951 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
953 std::vector<std::string> aSeq = _impl->GetModificationsDate();
955 int aLength = aSeq.size();
956 aDates->length(aLength);
957 for (int anIndex = 0; anIndex < aLength; anIndex++) {
958 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
961 return aDates._retn();
964 //============================================================================
965 /*! Function : GetUseCaseBuilder
966 * Purpose : Returns a UseCase builder
968 //============================================================================
969 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
971 SALOMEDS::Locker lock;
974 throw SALOMEDS::Study::StudyInvalidReference();
976 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
977 SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
982 //============================================================================
986 //============================================================================
987 void SALOMEDS_Study_i::Close()
989 SALOMEDS::Locker lock;
992 throw SALOMEDS::Study::StudyInvalidReference();
996 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
997 for (; itcomponent->More(); itcomponent->Next()) {
998 SALOMEDS::SComponent_var sco = itcomponent->Value();
999 CORBA::String_var compodatatype=sco->ComponentDataType();
1000 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
1001 // if there is an associated Engine call its method for closing
1002 CORBA::String_var IOREngine;
1003 if (sco->ComponentIOR(IOREngine)) {
1004 // we have found the associated engine to write the data
1005 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
1006 //_narrow can throw a corba exception
1008 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
1009 if (!CORBA::is_nil(obj)) {
1010 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
1011 if (!anEngine->_is_nil()) {
1013 anEngine->Close(sco);
1018 catch (CORBA::Exception&) {
1024 //Does not need any more this iterator
1025 itcomponent->UnRegister();
1027 // Notify GUI that study is closed
1028 SALOME_NamingService *aNamingService = KERNEL::getNamingService();
1029 CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
1030 SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
1031 if ( !CORBA::is_nil(aSession) ) {
1032 std::stringstream ss;
1033 ss << "studyClosed:" << _impl->StudyId();
1034 std::string str = ss.str();
1036 aSession->emitMessageOneWay(str.c_str());
1044 //============================================================================
1045 /*! Function : AddPostponed
1048 //============================================================================
1049 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
1051 SALOMEDS::Locker lock;
1055 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
1057 SALOMEDS::Locker lock;
1061 //============================================================================
1062 /*! Function : RemovePostponed
1065 //============================================================================
1066 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
1068 SALOMEDS::Locker lock;
1071 throw SALOMEDS::Study::StudyInvalidReference();
1073 std::vector<std::string> anIORs = _impl->GetIORs();
1074 int i, aSize = (int)anIORs.size();
1076 for (i = 0; i < aSize; i++) {
1078 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1079 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1080 //rnv: To avoid double deletion of the Salome Generic Objects:
1081 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1082 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1083 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1090 //============================================================================
1091 /*! Function : UndoPostponed
1094 //============================================================================
1095 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
1097 SALOMEDS::Locker lock;
1102 //============================================================================
1103 /*! Function : DumpStudy
1106 //============================================================================
1107 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
1108 const char* theBaseName,
1109 CORBA::Boolean isPublished,
1110 CORBA::Boolean isMultiFile)
1112 SALOMEDS::Locker lock;
1115 throw SALOMEDS::Study::StudyInvalidReference();
1117 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1118 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1119 bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1125 //============================================================================
1126 /*! Function : GetCommonParameters
1129 //============================================================================
1130 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1132 SALOMEDS::Locker lock;
1135 throw SALOMEDS::Study::StudyInvalidReference();
1137 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1138 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1139 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1141 return aParam._retn();
1144 //============================================================================
1145 /*! Function : GetCommonModuleParameters
1148 //============================================================================
1149 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
1150 const char* theModuleName,
1151 CORBA::Long theSavePoint)
1153 SALOMEDS::Locker lock;
1156 throw SALOMEDS::Study::StudyInvalidReference();
1158 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1159 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1160 SALOMEDS::AttributeParameter_var aParam = SP->_this();
1162 return aParam._retn();
1165 //============================================================================
1166 /*! Function : SetStudyLock
1169 //============================================================================
1170 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1172 SALOMEDS::Locker lock;
1175 throw SALOMEDS::Study::StudyInvalidReference();
1177 _impl->SetStudyLock(theLockerID);
1180 //============================================================================
1181 /*! Function : IsStudyLocked
1184 //============================================================================
1185 bool SALOMEDS_Study_i::IsStudyLocked()
1187 SALOMEDS::Locker lock;
1190 throw SALOMEDS::Study::StudyInvalidReference();
1192 return _impl->IsStudyLocked();
1195 //============================================================================
1196 /*! Function : UnLockStudy
1199 //============================================================================
1200 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1202 SALOMEDS::Locker lock;
1205 throw SALOMEDS::Study::StudyInvalidReference();
1207 _impl->UnLockStudy(theLockerID);
1210 //============================================================================
1211 /*! Function : GetLockerID
1214 //============================================================================
1215 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1217 SALOMEDS::Locker lock;
1220 throw SALOMEDS::Study::StudyInvalidReference();
1222 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1224 std::vector<std::string> aSeq = _impl->GetLockerID();
1226 int aLength = aSeq.size();
1227 aResult->length(aLength);
1228 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1229 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1232 return aResult._retn();
1234 //============================================================================
1235 /*! Function : SetReal
1238 //============================================================================
1239 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1242 throw SALOMEDS::Study::StudyInvalidReference();
1245 _impl->SetVariable(std::string(theVarName),
1247 SALOMEDSImpl_GenericVariable::REAL_VAR);
1249 _notifier->modifyNB_Notification(theVarName);
1252 //============================================================================
1253 /*! Function : SetInteger
1256 //============================================================================
1257 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1260 throw SALOMEDS::Study::StudyInvalidReference();
1262 _impl->SetVariable(std::string(theVarName),
1264 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1266 _notifier->modifyNB_Notification(theVarName);
1269 //============================================================================
1270 /*! Function : SetBoolean
1273 //============================================================================
1274 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1277 throw SALOMEDS::Study::StudyInvalidReference();
1279 _impl->SetVariable(std::string(theVarName),
1281 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1283 _notifier->modifyNB_Notification(theVarName);
1286 //============================================================================
1287 /*! Function : SetString
1290 //============================================================================
1291 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1294 throw SALOMEDS::Study::StudyInvalidReference();
1296 _impl->SetStringVariable(std::string(theVarName),
1298 SALOMEDSImpl_GenericVariable::STRING_VAR);
1300 _notifier->modifyNB_Notification(theVarName);
1303 //============================================================================
1304 /*! Function : SetStringAsDouble
1307 //============================================================================
1308 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1311 throw SALOMEDS::Study::StudyInvalidReference();
1313 _impl->SetStringVariableAsDouble(std::string(theVarName),
1315 SALOMEDSImpl_GenericVariable::STRING_VAR);
1318 //============================================================================
1319 /*! Function : GetReal
1322 //============================================================================
1323 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1326 throw SALOMEDS::Study::StudyInvalidReference();
1328 return _impl->GetVariableValue(std::string(theVarName));
1331 //============================================================================
1332 /*! Function : GetInteger
1335 //============================================================================
1336 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1339 throw SALOMEDS::Study::StudyInvalidReference();
1341 return (long)_impl->GetVariableValue(std::string(theVarName));
1344 //============================================================================
1345 /*! Function : GetBoolean
1348 //============================================================================
1349 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1352 throw SALOMEDS::Study::StudyInvalidReference();
1354 return (bool)_impl->GetVariableValue(std::string(theVarName));
1357 //============================================================================
1358 /*! Function : GetString
1361 //============================================================================
1362 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1365 throw SALOMEDS::Study::StudyInvalidReference();
1367 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1370 //============================================================================
1371 /*! Function : IsReal
1374 //============================================================================
1375 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1378 throw SALOMEDS::Study::StudyInvalidReference();
1380 return _impl->IsTypeOf(std::string(theVarName),
1381 SALOMEDSImpl_GenericVariable::REAL_VAR);
1384 //============================================================================
1385 /*! Function : IsInteger
1388 //============================================================================
1389 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1392 throw SALOMEDS::Study::StudyInvalidReference();
1394 return _impl->IsTypeOf(std::string(theVarName),
1395 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1398 //============================================================================
1399 /*! Function : IsBoolean
1402 //============================================================================
1403 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1406 throw SALOMEDS::Study::StudyInvalidReference();
1408 return _impl->IsTypeOf(std::string(theVarName),
1409 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1412 //============================================================================
1413 /*! Function : IsString
1416 //============================================================================
1417 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1420 throw SALOMEDS::Study::StudyInvalidReference();
1422 return _impl->IsTypeOf(std::string(theVarName),
1423 SALOMEDSImpl_GenericVariable::STRING_VAR);
1426 //============================================================================
1427 /*! Function : IsVariable
1430 //============================================================================
1431 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1434 throw SALOMEDS::Study::StudyInvalidReference();
1436 return _impl->IsVariable(std::string(theVarName));
1439 //============================================================================
1440 /*! Function : GetVariableNames
1443 //============================================================================
1444 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1447 throw SALOMEDS::Study::StudyInvalidReference();
1449 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1451 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1453 int aLen = aVarNames.size();
1454 aResult->length(aLen);
1455 for (int anInd = 0; anInd < aLen; anInd++)
1456 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1458 return aResult._retn();
1461 //============================================================================
1462 /*! Function : RemoveVariable
1465 //============================================================================
1466 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1469 throw SALOMEDS::Study::StudyInvalidReference();
1471 bool res = _impl->RemoveVariable(std::string(theVarName));
1472 if (res && _notifier)
1473 _notifier->modifyNB_Notification(theVarName);
1478 //============================================================================
1479 /*! Function : RenameVariable
1482 //============================================================================
1483 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1486 throw SALOMEDS::Study::StudyInvalidReference();
1488 bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1489 if (res && _notifier)
1490 _notifier->modifyNB_Notification(theVarName);
1495 //============================================================================
1496 /*! Function : IsVariableUsed
1499 //============================================================================
1500 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1503 throw SALOMEDS::Study::StudyInvalidReference();
1505 return _impl->IsVariableUsed(std::string(theVarName));
1509 //============================================================================
1510 /*! Function : ParseVariables
1513 //============================================================================
1514 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1517 throw SALOMEDS::Study::StudyInvalidReference();
1519 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1521 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1523 int aSectionsLen = aSections.size();
1524 aResult->length(aSectionsLen);
1526 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1527 std::vector<std::string> aVarNames = aSections[aSectionInd];
1529 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1531 int aLen = aVarNames.size();
1532 aList->length(aLen);
1534 for (int anInd = 0; anInd < aLen; anInd++)
1535 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1537 aResult[aSectionInd] = aList;
1540 return aResult._retn();
1543 //============================================================================
1544 /*! Function : GetDefaultScript
1547 //============================================================================
1548 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1550 SALOMEDS::Locker lock;
1553 throw SALOMEDS::Study::StudyInvalidReference();
1555 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1556 return CORBA::string_dup(script.c_str());
1559 //============================================================================
1560 /*! Function : EnableUseCaseAutoFilling
1563 //============================================================================
1564 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1567 throw SALOMEDS::Study::StudyInvalidReference();
1569 _impl->EnableUseCaseAutoFilling(isEnabled);
1570 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1573 builder->SetOnAddSObject(_impl->GetCallback());
1574 builder->SetOnRemoveSObject(_impl->GetCallback());
1577 builder->SetOnAddSObject(NULL);
1578 builder->SetOnRemoveSObject(NULL);
1583 //============================================================================
1584 /*! Function : attach
1585 * Purpose : This function attach an observer to the study
1587 //============================================================================
1588 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1591 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1595 //============================================================================
1596 /*! Function : detach
1597 * Purpose : This function detaches an observer from the study
1599 //============================================================================
1600 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1603 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1606 //===========================================================================
1607 // PRIVATE FUNCTIONS
1608 //===========================================================================
1609 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1612 long pid = (long)_getpid();
1614 long pid = (long)getpid();
1616 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1617 return reinterpret_cast<CORBA::LongLong>(_impl);