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"
28 #include "SALOMEDS_Study_i.hxx"
29 #include "SALOMEDS_StudyManager_i.hxx"
30 #include "SALOMEDS_UseCaseIterator_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
33 #include "SALOMEDS_AttributeParameter_i.hxx"
34 #include "SALOMEDS_ChildIterator_i.hxx"
35 #include "SALOMEDS_Driver_i.hxx"
36 #include "SALOMEDS.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
41 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
42 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "SALOMEDSImpl_Callback.hxx"
47 #include "DF_Label.hxx"
48 #include "DF_Attribute.hxx"
50 #include "Basics_Utils.hxx"
55 #include <sys/types.h>
61 class Notifier: public SALOMEDSImpl_AbstractCallback
64 Notifier(CORBA::ORB_ptr orb)
66 _orb = CORBA::ORB::_duplicate(orb);
69 //============================================================================
70 /*! Function : addSO_Notification
71 * Purpose : This function tells all the observers that a SO has been added
73 //============================================================================
75 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
77 std::string anID=theSObject.GetID();
78 const char* cID=anID.c_str();
79 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
81 it->first->notifyObserverID(cID,1);
83 return true; // NGE return always true but can be modified if needed
86 //============================================================================
87 /*! Function : removeSO_Notification
88 * Purpose : This function tells all the observers that a SO has been removed
90 //============================================================================
92 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
94 std::string anID=theSObject.GetID();
95 const char* cID=anID.c_str();
96 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
98 it->first->notifyObserverID(cID,2);
100 return true; // NGE return always true but can be modified if needed
103 //============================================================================
104 /*! Function : modifySO_Notification
105 * Purpose : This function tells all the observers that a SO has been modified
107 //============================================================================
109 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
111 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
115 std::string anID=theSObject.GetID();
116 const char* cID=anID.c_str();
117 it->first->notifyObserverID(cID,reason);
120 return true; // NGE return always true but can be modified if needed
123 //============================================================================
124 /*! Function : modifyNB_Notification
125 * Purpose : This function tells all the observers that
126 * a NoteBook variable has been added/modified/removed.
128 //============================================================================
130 virtual bool modifyNB_Notification(const char* theVarName)
132 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
134 it->first->notifyObserverID(theVarName,6);
136 return true; // NGE return always true but can be modified if needed
139 //============================================================================
140 /*! Function : attach
141 * Purpose : register an Observer
143 //============================================================================
145 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
147 myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
150 //============================================================================
151 /*! Function : detach
152 * Purpose : unregister an Observer
154 //============================================================================
156 virtual void detach(SALOMEDS::Observer_ptr theObs)
158 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
160 if ( it->first->_is_equivalent(theObs) ) {
161 myObservers.erase( it );
168 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
169 typedef ObsList::iterator ObsListIter;
174 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
177 GenObjRegister(CORBA::ORB_ptr orb)
179 _orb = CORBA::ORB::_duplicate(orb);
181 virtual void RegisterGenObj (const std::string& theIOR)
185 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
186 if ( obj->_non_existent() ) return;
187 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
188 if(! CORBA::is_nil(gobj) )
193 catch(const CORBA::Exception& e)
197 virtual void UnRegisterGenObj(const std::string& theIOR)
201 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
202 if ( obj->_non_existent() ) return;
203 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
204 if(! CORBA::is_nil(gobj) )
209 catch(const CORBA::Exception& e)
218 } // namespace SALOMEDS
220 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
222 //============================================================================
223 /*! Function : SALOMEDS_Study_i
224 * Purpose : SALOMEDS_Study_i constructor
226 //============================================================================
227 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
230 _orb = CORBA::ORB::_duplicate(orb);
232 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
233 _notifier = new SALOMEDS::Notifier(_orb);
234 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
236 theImpl->setNotifier(_notifier);
237 theImpl->setGenObjRegister( _genObjRegister );
240 //============================================================================
241 /*! Function : ~SALOMEDS_Study_i
242 * Purpose : SALOMEDS_Study_i destructor
244 //============================================================================
245 SALOMEDS_Study_i::~SALOMEDS_Study_i()
247 //delete the builder servant
248 PortableServer::POA_var poa=_builder->_default_POA();
249 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
250 poa->deactivate_object(anObjectId.in());
251 _builder->_remove_ref();
253 _impl->setNotifier(0);
255 delete _genObjRegister;
256 //delete implementation
258 _mapOfStudies.erase(_impl);
261 //============================================================================
262 /*! Function : GetPersistentReference
263 * Purpose : Get persistent reference of study (idem URL())
265 //============================================================================
266 char* SALOMEDS_Study_i::GetPersistentReference()
268 SALOMEDS::Locker lock;
269 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
271 //============================================================================
272 /*! Function : GetTransientReference
273 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
275 //============================================================================
276 char* SALOMEDS_Study_i::GetTransientReference()
278 SALOMEDS::Locker lock;
279 return CORBA::string_dup(_impl->GetTransientReference().c_str());
282 //============================================================================
283 /*! Function : IsEmpty
284 * Purpose : Detect if study is empty
286 //============================================================================
287 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
289 SALOMEDS::Locker lock;
290 return _impl->IsEmpty();
293 //============================================================================
294 /*! Function : FindComponent
295 * Purpose : Find a Component with ComponentDataType = aComponentName
297 //============================================================================
298 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
300 SALOMEDS::Locker lock;
302 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
303 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
305 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
309 //============================================================================
310 /*! Function : FindComponentID
311 * Purpose : Find a Component from it's ID
313 //============================================================================
314 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
316 SALOMEDS::Locker lock;
318 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
319 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
321 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
325 //============================================================================
326 /*! Function : FindObject
327 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
329 //============================================================================
330 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
332 SALOMEDS::Locker lock;
334 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
335 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
337 if(aSO.IsComponent()) {
338 SALOMEDSImpl_SComponent aSCO = aSO;
339 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
343 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
348 //============================================================================
349 /*! Function : FindObjectID
350 * Purpose : Find an Object with ID = anObjectID
352 //============================================================================
353 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
355 SALOMEDS::Locker lock;
357 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
358 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
359 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
363 //============================================================================
364 /*! Function : CreateObjectID
365 * Purpose : Creates an Object with ID = anObjectID
367 //============================================================================
368 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
370 SALOMEDS::Locker lock;
372 if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
374 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
375 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
377 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
381 //============================================================================
382 /*! Function : FindObjectByName
383 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
384 * : with ComponentDataType = aComponentName
386 //============================================================================
387 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
388 const char* aComponentName )
390 SALOMEDS::Locker lock;
392 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
393 std::string((char*)aComponentName));
394 int aLength = aSeq.size();
395 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
396 listSO->length(aLength);
397 for(int i = 0; i<aLength; i++) {
398 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
401 return listSO._retn() ;
404 //============================================================================
405 /*! Function : FindObjectIOR
406 * Purpose : Find an Object with IOR = anObjectIOR
408 //============================================================================
409 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
411 SALOMEDS::Locker lock;
413 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
414 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
416 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
420 //============================================================================
421 /*! Function : FindObjectByPath
422 * Purpose : Find an Object by its path = thePath
424 //============================================================================
425 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
427 SALOMEDS::Locker lock;
429 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
430 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
432 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
436 //============================================================================
437 /*! Function : GetObjectPath
440 //============================================================================
441 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
443 SALOMEDS::Locker lock;
445 std::string aPath("");
446 if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
447 SALOMEDSImpl_SObject aSO;
448 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
450 if(!CORBA::is_nil(aSObj)) {
451 aSO = _impl->FindObjectID(aSObj->GetID());
454 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
457 if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
459 aPath = _impl->GetObjectPath(aSO);
460 return CORBA::string_dup(aPath.c_str());
464 //============================================================================
465 /*! Function : SetContext
466 * Purpose : Sets the current context
468 //============================================================================
469 void SALOMEDS_Study_i::SetContext(const char* thePath)
471 SALOMEDS::Locker lock;
473 _impl->SetContext(std::string((char*)thePath));
474 if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
475 throw SALOMEDS::Study::StudyInvalidContext();
478 //============================================================================
479 /*! Function : GetContext
480 * Purpose : Gets the current context
482 //============================================================================
483 char* SALOMEDS_Study_i::GetContext()
485 SALOMEDS::Locker lock;
487 if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
488 return CORBA::string_dup(_impl->GetContext().c_str());
491 //============================================================================
492 /*! Function : GetObjectNames
493 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
495 //============================================================================
496 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
498 SALOMEDS::Locker lock;
500 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
502 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
503 throw SALOMEDS::Study::StudyInvalidContext();
505 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
506 if (_impl->GetErrorCode() == "InvalidContext")
507 throw SALOMEDS::Study::StudyInvalidContext();
509 int aLength = aSeq.size();
510 aResult->length(aLength);
511 for (int anIndex = 0; anIndex < aLength; anIndex++) {
512 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
515 return aResult._retn();
518 //============================================================================
519 /*! Function : GetDirectoryNames
520 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
522 //============================================================================
523 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
525 SALOMEDS::Locker lock;
527 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
529 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
530 throw SALOMEDS::Study::StudyInvalidContext();
532 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
533 if (_impl->GetErrorCode() == "InvalidContext")
534 throw SALOMEDS::Study::StudyInvalidContext();
536 int aLength = aSeq.size();
537 aResult->length(aLength);
538 for (int anIndex = 0; anIndex < aLength; anIndex++) {
539 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
542 return aResult._retn();
545 //============================================================================
546 /*! Function : GetFileNames
547 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
549 //============================================================================
550 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
552 SALOMEDS::Locker lock;
554 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
556 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
557 throw SALOMEDS::Study::StudyInvalidContext();
559 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
560 if (_impl->GetErrorCode() == "InvalidContext")
561 throw SALOMEDS::Study::StudyInvalidContext();
563 int aLength = aSeq.size();
564 aResult->length(aLength);
565 for (int anIndex = 0; anIndex < aLength; anIndex++) {
566 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
569 return aResult._retn();
572 //============================================================================
573 /*! Function : GetComponentNames
574 * Purpose : method to get all components names
575 * SRN: Note, theContext can be any, it doesn't matter
577 //============================================================================
578 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
580 SALOMEDS::Locker lock;
582 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
584 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
586 int aLength = aSeq.size();
587 aResult->length(aLength);
588 for(int anIndex = 0; anIndex < aLength; anIndex++) {
589 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
592 return aResult._retn();
595 //============================================================================
596 /*! Function : NewChildIterator
597 * Purpose : Create a ChildIterator from an SObject
599 //============================================================================
600 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
602 SALOMEDS::Locker lock;
604 CORBA::String_var anID=theSO->GetID();
605 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
606 SALOMEDSImpl_ChildIterator anItr(aSO);
609 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
611 return it_servant->_this();
615 //============================================================================
616 /*! Function : NewComponentIterator
617 * Purpose : Create a SComponentIterator
619 //============================================================================
620 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
622 SALOMEDS::Locker lock;
623 SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
629 //============================================================================
630 /*! Function : NewBuilder
631 * Purpose : Create a StudyBuilder
633 //============================================================================
634 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
636 SALOMEDS::Locker lock;
637 return _builder->_this();
640 //============================================================================
642 * Purpose : get study name
644 //============================================================================
645 char* SALOMEDS_Study_i::Name()
647 SALOMEDS::Locker lock;
648 return CORBA::string_dup(_impl->Name().c_str());
651 //============================================================================
653 * Purpose : set study name
655 //============================================================================
656 void SALOMEDS_Study_i::Name(const char* name)
658 SALOMEDS::Locker lock;
659 _impl->Name(std::string(name));
662 //============================================================================
663 /*! Function : IsSaved
664 * Purpose : get if study has been saved
666 //============================================================================
667 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
669 SALOMEDS::Locker lock;
670 return _impl->IsSaved();
673 //============================================================================
674 /*! Function : IsSaved
675 * Purpose : set if study has been saved
677 //============================================================================
678 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
680 SALOMEDS::Locker lock;
681 _impl->IsSaved(save);
684 //============================================================================
685 /*! Function : IsModified
686 * Purpose : Detect if a Study has been modified since it has been saved
688 //============================================================================
689 CORBA::Boolean SALOMEDS_Study_i::IsModified()
691 SALOMEDS::Locker lock;
692 return _impl->IsModified();
695 //============================================================================
696 /*! Function : Modified
697 * Purpose : Sets a Modified flag of a Study to True
699 //============================================================================
700 void SALOMEDS_Study_i::Modified()
702 SALOMEDS::Locker lock;
703 return _impl->Modify();
707 //============================================================================
709 * Purpose : get URL of the study (persistent reference of the study)
711 //============================================================================
712 char* SALOMEDS_Study_i::URL()
714 SALOMEDS::Locker lock;
715 return CORBA::string_dup(_impl->URL().c_str());
718 //============================================================================
720 * Purpose : set URL of the study (persistent reference of the study)
722 //============================================================================
723 void SALOMEDS_Study_i::URL(const char* url)
725 SALOMEDS::Locker lock;
726 _impl->URL(std::string((char*)url));
730 CORBA::Short SALOMEDS_Study_i::StudyId()
732 SALOMEDS::Locker lock;
733 return _impl->StudyId();
736 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
738 SALOMEDS::Locker lock;
742 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
744 SALOMEDS::Locker lock;
745 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
748 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
750 SALOMEDS::Locker lock;
752 SALOMEDSImpl_AttributeIOR* Att = NULL;
753 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
754 char* IOR = CORBA::string_dup(Att->Value().c_str());
755 CORBA::Object_var obj = orb->string_to_object(IOR);
756 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
757 ASSERT(!CORBA::is_nil(aStudy));
758 return SALOMEDS::Study::_duplicate(aStudy);
760 MESSAGE("GetStudy: Problem to get study");
762 return SALOMEDS::Study::_nil();
765 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
767 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
768 return _mapOfStudies[aStudyImpl];
771 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
772 _mapOfStudies[aStudyImpl]=Study_servant;
773 return Study_servant;
777 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
779 SALOMEDS::Locker lock;
780 SALOMEDSImpl_Study::IORUpdated(theAttribute);
783 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
785 SALOMEDS::Locker lock;
787 SALOMEDS::GenericAttribute_ptr aTarget;
788 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
789 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
791 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
797 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
799 SALOMEDS::Locker lock;
801 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
802 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
803 return SP->AttributeStudyProperties::_this();
806 char* SALOMEDS_Study_i::GetLastModificationDate()
808 SALOMEDS::Locker lock;
809 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
812 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
814 SALOMEDS::Locker lock;
816 std::vector<std::string> aSeq = _impl->GetModificationsDate();
817 int aLength = aSeq.size();
818 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
819 aDates->length(aLength);
821 for(int anIndex = 0; anIndex < aLength; anIndex++) {
822 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
824 return aDates._retn();
829 //============================================================================
830 /*! Function : GetUseCaseBuilder
831 * Purpose : Returns a UseCase builder
833 //============================================================================
834 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
836 SALOMEDS::Locker lock;
837 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
838 return UCBuilder->_this();
842 //============================================================================
846 //============================================================================
847 void SALOMEDS_Study_i::Close()
849 SALOMEDS::Locker lock;
853 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
854 for (; itcomponent->More(); itcomponent->Next()) {
855 SALOMEDS::SComponent_var sco = itcomponent->Value();
856 CORBA::String_var compodatatype=sco->ComponentDataType();
857 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
858 // if there is an associated Engine call its method for closing
859 CORBA::String_var IOREngine;
860 if (sco->ComponentIOR(IOREngine)) {
861 // we have found the associated engine to write the data
862 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
863 //_narrow can throw a corba exception
866 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
867 if (!CORBA::is_nil(obj))
869 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
870 if (!anEngine->_is_nil())
873 anEngine->Close(sco);
878 catch (CORBA::Exception&)
884 //Does not need any more this iterator
885 itcomponent->UnRegister();
891 //============================================================================
892 /*! Function : AddPostponed
895 //============================================================================
896 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
898 SALOMEDS::Locker lock;
902 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
904 SALOMEDS::Locker lock;
908 //============================================================================
909 /*! Function : RemovePostponed
912 //============================================================================
914 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/)
916 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
919 SALOMEDS::Locker lock;
921 std::vector<std::string> anIORs = _impl->GetIORs();
922 int i, aSize = (int)anIORs.size();
924 for(i = 0; i < aSize; i++) {
926 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
927 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
928 //rnv: To avoid double deletion of the Salome Generic Objects:
929 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
930 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
931 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
938 //============================================================================
939 /*! Function : UndoPostponed
942 //============================================================================
944 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay)
946 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
949 SALOMEDS::Locker lock;
954 //============================================================================
955 /*! Function : DumpStudy
958 //============================================================================
959 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
960 const char* theBaseName,
961 CORBA::Boolean isPublished,
962 CORBA::Boolean isMultiFile)
964 SALOMEDS::Locker lock;
966 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
967 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
968 CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
973 //============================================================================
974 /*! Function : GetCommonParameters
977 //============================================================================
978 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
980 SALOMEDS::Locker lock;
982 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
983 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
984 return SP->AttributeParameter::_this();
987 //============================================================================
988 /*! Function : GetCommonModuleParameters
991 //============================================================================
992 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
993 const char* theModuleName,
994 CORBA::Long theSavePoint)
996 SALOMEDS::Locker lock;
998 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
999 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1000 return SP->AttributeParameter::_this();
1003 //============================================================================
1004 /*! Function : SetStudyLock
1007 //============================================================================
1008 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1010 SALOMEDS::Locker lock;
1011 _impl->SetStudyLock(theLockerID);
1014 //============================================================================
1015 /*! Function : IsStudyLocked
1018 //============================================================================
1019 bool SALOMEDS_Study_i::IsStudyLocked()
1021 SALOMEDS::Locker lock;
1022 return _impl->IsStudyLocked();
1025 //============================================================================
1026 /*! Function : UnLockStudy
1029 //============================================================================
1030 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1032 SALOMEDS::Locker lock;
1033 _impl->UnLockStudy(theLockerID);
1036 //============================================================================
1037 /*! Function : GetLockerID
1040 //============================================================================
1041 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1043 SALOMEDS::Locker lock;
1045 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1047 std::vector<std::string> aSeq = _impl->GetLockerID();
1049 int aLength = aSeq.size();
1050 aResult->length(aLength);
1051 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1052 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1054 return aResult._retn();
1056 //============================================================================
1057 /*! Function : SetReal
1060 //============================================================================
1061 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1063 _impl->SetVariable(std::string(theVarName),
1065 SALOMEDSImpl_GenericVariable::REAL_VAR);
1067 _notifier->modifyNB_Notification(theVarName);
1070 //============================================================================
1071 /*! Function : SetInteger
1074 //============================================================================
1075 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1077 _impl->SetVariable(std::string(theVarName),
1079 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1081 _notifier->modifyNB_Notification(theVarName);
1084 //============================================================================
1085 /*! Function : SetBoolean
1088 //============================================================================
1089 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1091 _impl->SetVariable(std::string(theVarName),
1093 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1095 _notifier->modifyNB_Notification(theVarName);
1098 //============================================================================
1099 /*! Function : SetString
1102 //============================================================================
1103 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1105 _impl->SetStringVariable(std::string(theVarName),
1107 SALOMEDSImpl_GenericVariable::STRING_VAR);
1109 _notifier->modifyNB_Notification(theVarName);
1112 //============================================================================
1113 /*! Function : SetStringAsDouble
1116 //============================================================================
1117 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1119 _impl->SetStringVariableAsDouble(std::string(theVarName),
1121 SALOMEDSImpl_GenericVariable::STRING_VAR);
1124 //============================================================================
1125 /*! Function : GetReal
1128 //============================================================================
1129 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1131 return _impl->GetVariableValue(std::string(theVarName));
1134 //============================================================================
1135 /*! Function : GetInteger
1138 //============================================================================
1139 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1141 return (int)_impl->GetVariableValue(std::string(theVarName));
1144 //============================================================================
1145 /*! Function : GetBoolean
1148 //============================================================================
1149 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1151 return (bool)_impl->GetVariableValue(std::string(theVarName));
1154 //============================================================================
1155 /*! Function : GetString
1158 //============================================================================
1159 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1161 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1164 //============================================================================
1165 /*! Function : IsReal
1168 //============================================================================
1169 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1171 return _impl->IsTypeOf(std::string(theVarName),
1172 SALOMEDSImpl_GenericVariable::REAL_VAR);
1175 //============================================================================
1176 /*! Function : IsInteger
1179 //============================================================================
1180 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1182 return _impl->IsTypeOf(std::string(theVarName),
1183 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1186 //============================================================================
1187 /*! Function : IsBoolean
1190 //============================================================================
1191 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1193 return _impl->IsTypeOf(std::string(theVarName),
1194 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1197 //============================================================================
1198 /*! Function : IsString
1201 //============================================================================
1202 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1204 return _impl->IsTypeOf(std::string(theVarName),
1205 SALOMEDSImpl_GenericVariable::STRING_VAR);
1208 //============================================================================
1209 /*! Function : IsVariable
1212 //============================================================================
1213 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1215 return _impl->IsVariable(std::string(theVarName));
1218 //============================================================================
1219 /*! Function : GetVariableNames
1222 //============================================================================
1223 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1225 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1226 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1228 int aLen = aVarNames.size();
1229 aResult->length(aLen);
1231 for (int anInd = 0; anInd < aLen; anInd++)
1232 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1234 return aResult._retn();
1237 //============================================================================
1238 /*! Function : RemoveVariable
1241 //============================================================================
1242 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1244 CORBA::Boolean res = _impl->RemoveVariable(std::string(theVarName));
1245 if(res && _notifier)
1246 _notifier->modifyNB_Notification(theVarName);
1250 //============================================================================
1251 /*! Function : RenameVariable
1254 //============================================================================
1255 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1257 CORBA::Boolean res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1258 if(res && _notifier)
1259 _notifier->modifyNB_Notification(theVarName);
1263 //============================================================================
1264 /*! Function : IsVariableUsed
1267 //============================================================================
1268 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1270 return _impl->IsVariableUsed(std::string(theVarName));
1274 //============================================================================
1275 /*! Function : ParseVariables
1278 //============================================================================
1279 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1281 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1283 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1285 int aSectionsLen = aSections.size();
1286 aResult->length(aSectionsLen);
1288 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1289 std::vector<std::string> aVarNames = aSections[aSectionInd];
1291 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1293 int aLen = aVarNames.size();
1294 aList->length(aLen);
1296 for (int anInd = 0; anInd < aLen; anInd++)
1297 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1299 aResult[aSectionInd] = aList;
1302 return aResult._retn();
1305 //============================================================================
1306 /*! Function : GetDefaultScript
1309 //============================================================================
1310 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1312 SALOMEDS::Locker lock;
1314 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1315 return CORBA::string_dup(script.c_str());
1318 //============================================================================
1319 /*! Function : EnableUseCaseAutoFilling
1322 //============================================================================
1323 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1325 _impl->EnableUseCaseAutoFilling(isEnabled);
1326 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1329 builder->SetOnAddSObject(_impl->GetCallback());
1330 builder->SetOnRemoveSObject(_impl->GetCallback());
1333 builder->SetOnAddSObject(NULL);
1334 builder->SetOnRemoveSObject(NULL);
1339 //============================================================================
1340 /*! Function : attach
1341 * Purpose : This function attach an observer to the study
1343 //============================================================================
1344 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modify)
1347 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs,modify);
1351 //============================================================================
1352 /*! Function : detach
1353 * Purpose : This function detaches an observer from the study
1355 //============================================================================
1356 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1359 static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1362 //===========================================================================
1363 // PRIVATE FUNCTIONS
1364 //===========================================================================
1365 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1368 long pid = (long)_getpid();
1370 long pid = (long)getpid();
1372 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1373 return reinterpret_cast<CORBA::LongLong>(_impl);