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));
151 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
152 typedef ObsList::iterator ObsListIter;
157 class GenObjRegister: public SALOMEDSImpl_AbstractCallback
160 GenObjRegister(CORBA::ORB_ptr orb)
162 _orb = CORBA::ORB::_duplicate(orb);
164 virtual void RegisterGenObj (const std::string& theIOR)
168 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
169 if ( obj->_non_existent() ) return;
170 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
171 if(! CORBA::is_nil(gobj) )
176 catch(const CORBA::Exception& e)
180 virtual void UnRegisterGenObj(const std::string& theIOR)
184 CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
185 if ( obj->_non_existent() ) return;
186 SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
187 if(! CORBA::is_nil(gobj) )
192 catch(const CORBA::Exception& e)
201 } // namespace SALOMEDS
203 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
205 //============================================================================
206 /*! Function : SALOMEDS_Study_i
207 * Purpose : SALOMEDS_Study_i constructor
209 //============================================================================
210 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
213 _orb = CORBA::ORB::_duplicate(orb);
215 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
216 _notifier = new SALOMEDS::Notifier(_orb);
217 _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
219 theImpl->setNotifier(_notifier);
220 theImpl->setGenObjRegister( _genObjRegister );
223 //============================================================================
224 /*! Function : ~SALOMEDS_Study_i
225 * Purpose : SALOMEDS_Study_i destructor
227 //============================================================================
228 SALOMEDS_Study_i::~SALOMEDS_Study_i()
230 //delete the builder servant
231 PortableServer::POA_var poa=_builder->_default_POA();
232 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
233 poa->deactivate_object(anObjectId.in());
234 _builder->_remove_ref();
236 _impl->setNotifier(0);
238 delete _genObjRegister;
239 //delete implementation
241 _mapOfStudies.erase(_impl);
244 //============================================================================
245 /*! Function : GetPersistentReference
246 * Purpose : Get persistent reference of study (idem URL())
248 //============================================================================
249 char* SALOMEDS_Study_i::GetPersistentReference()
251 SALOMEDS::Locker lock;
252 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
254 //============================================================================
255 /*! Function : GetTransientReference
256 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
258 //============================================================================
259 char* SALOMEDS_Study_i::GetTransientReference()
261 SALOMEDS::Locker lock;
262 return CORBA::string_dup(_impl->GetTransientReference().c_str());
265 //============================================================================
266 /*! Function : IsEmpty
267 * Purpose : Detect if study is empty
269 //============================================================================
270 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
272 SALOMEDS::Locker lock;
273 return _impl->IsEmpty();
276 //============================================================================
277 /*! Function : FindComponent
278 * Purpose : Find a Component with ComponentDataType = aComponentName
280 //============================================================================
281 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
283 SALOMEDS::Locker lock;
285 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
286 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
288 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
292 //============================================================================
293 /*! Function : FindComponentID
294 * Purpose : Find a Component from it's ID
296 //============================================================================
297 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
299 SALOMEDS::Locker lock;
301 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
302 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
304 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
308 //============================================================================
309 /*! Function : FindObject
310 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
312 //============================================================================
313 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
315 SALOMEDS::Locker lock;
317 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
318 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
320 if(aSO.IsComponent()) {
321 SALOMEDSImpl_SComponent aSCO = aSO;
322 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
326 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
331 //============================================================================
332 /*! Function : FindObjectID
333 * Purpose : Find an Object with ID = anObjectID
335 //============================================================================
336 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
338 SALOMEDS::Locker lock;
340 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
341 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
342 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
346 //============================================================================
347 /*! Function : CreateObjectID
348 * Purpose : Creates an Object with ID = anObjectID
350 //============================================================================
351 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
353 SALOMEDS::Locker lock;
355 if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
357 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
358 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
360 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
364 //============================================================================
365 /*! Function : FindObjectByName
366 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
367 * : with ComponentDataType = aComponentName
369 //============================================================================
370 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
371 const char* aComponentName )
373 SALOMEDS::Locker lock;
375 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
376 std::string((char*)aComponentName));
377 int aLength = aSeq.size();
378 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
379 listSO->length(aLength);
380 for(int i = 0; i<aLength; i++) {
381 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
384 return listSO._retn() ;
387 //============================================================================
388 /*! Function : FindObjectIOR
389 * Purpose : Find an Object with IOR = anObjectIOR
391 //============================================================================
392 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
394 SALOMEDS::Locker lock;
396 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
397 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
399 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
403 //============================================================================
404 /*! Function : FindObjectByPath
405 * Purpose : Find an Object by its path = thePath
407 //============================================================================
408 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
410 SALOMEDS::Locker lock;
412 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
413 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
415 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
419 //============================================================================
420 /*! Function : GetObjectPath
423 //============================================================================
424 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
426 SALOMEDS::Locker lock;
428 std::string aPath("");
429 if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
430 SALOMEDSImpl_SObject aSO;
431 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
433 if(!CORBA::is_nil(aSObj)) {
434 aSO = _impl->FindObjectID(aSObj->GetID());
437 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
440 if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
442 aPath = _impl->GetObjectPath(aSO);
443 return CORBA::string_dup(aPath.c_str());
447 //============================================================================
448 /*! Function : SetContext
449 * Purpose : Sets the current context
451 //============================================================================
452 void SALOMEDS_Study_i::SetContext(const char* thePath)
454 SALOMEDS::Locker lock;
456 _impl->SetContext(std::string((char*)thePath));
457 if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
458 throw SALOMEDS::Study::StudyInvalidContext();
461 //============================================================================
462 /*! Function : GetContext
463 * Purpose : Gets the current context
465 //============================================================================
466 char* SALOMEDS_Study_i::GetContext()
468 SALOMEDS::Locker lock;
470 if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
471 return CORBA::string_dup(_impl->GetContext().c_str());
474 //============================================================================
475 /*! Function : GetObjectNames
476 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
478 //============================================================================
479 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
481 SALOMEDS::Locker lock;
483 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
485 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
486 throw SALOMEDS::Study::StudyInvalidContext();
488 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
489 if (_impl->GetErrorCode() == "InvalidContext")
490 throw SALOMEDS::Study::StudyInvalidContext();
492 int aLength = aSeq.size();
493 aResult->length(aLength);
494 for (int anIndex = 0; anIndex < aLength; anIndex++) {
495 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
498 return aResult._retn();
501 //============================================================================
502 /*! Function : GetDirectoryNames
503 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
505 //============================================================================
506 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
508 SALOMEDS::Locker lock;
510 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
512 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
513 throw SALOMEDS::Study::StudyInvalidContext();
515 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
516 if (_impl->GetErrorCode() == "InvalidContext")
517 throw SALOMEDS::Study::StudyInvalidContext();
519 int aLength = aSeq.size();
520 aResult->length(aLength);
521 for (int anIndex = 0; anIndex < aLength; anIndex++) {
522 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
525 return aResult._retn();
528 //============================================================================
529 /*! Function : GetFileNames
530 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
532 //============================================================================
533 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
535 SALOMEDS::Locker lock;
537 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
539 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
540 throw SALOMEDS::Study::StudyInvalidContext();
542 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
543 if (_impl->GetErrorCode() == "InvalidContext")
544 throw SALOMEDS::Study::StudyInvalidContext();
546 int aLength = aSeq.size();
547 aResult->length(aLength);
548 for (int anIndex = 0; anIndex < aLength; anIndex++) {
549 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
552 return aResult._retn();
555 //============================================================================
556 /*! Function : GetComponentNames
557 * Purpose : method to get all components names
558 * SRN: Note, theContext can be any, it doesn't matter
560 //============================================================================
561 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
563 SALOMEDS::Locker lock;
565 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
567 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
569 int aLength = aSeq.size();
570 aResult->length(aLength);
571 for(int anIndex = 0; anIndex < aLength; anIndex++) {
572 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
575 return aResult._retn();
578 //============================================================================
579 /*! Function : NewChildIterator
580 * Purpose : Create a ChildIterator from an SObject
582 //============================================================================
583 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
585 SALOMEDS::Locker lock;
587 CORBA::String_var anID=theSO->GetID();
588 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
589 SALOMEDSImpl_ChildIterator anItr(aSO);
592 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
594 return it_servant->_this();
598 //============================================================================
599 /*! Function : NewComponentIterator
600 * Purpose : Create a SComponentIterator
602 //============================================================================
603 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
605 SALOMEDS::Locker lock;
606 SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
612 //============================================================================
613 /*! Function : NewBuilder
614 * Purpose : Create a StudyBuilder
616 //============================================================================
617 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
619 SALOMEDS::Locker lock;
620 return _builder->_this();
623 //============================================================================
625 * Purpose : get study name
627 //============================================================================
628 char* SALOMEDS_Study_i::Name()
630 SALOMEDS::Locker lock;
631 return CORBA::string_dup(_impl->Name().c_str());
634 //============================================================================
636 * Purpose : set study name
638 //============================================================================
639 void SALOMEDS_Study_i::Name(const char* name)
641 SALOMEDS::Locker lock;
642 _impl->Name(std::string(name));
645 //============================================================================
646 /*! Function : IsSaved
647 * Purpose : get if study has been saved
649 //============================================================================
650 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
652 SALOMEDS::Locker lock;
653 return _impl->IsSaved();
656 //============================================================================
657 /*! Function : IsSaved
658 * Purpose : set if study has been saved
660 //============================================================================
661 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
663 SALOMEDS::Locker lock;
664 _impl->IsSaved(save);
667 //============================================================================
668 /*! Function : IsModified
669 * Purpose : Detect if a Study has been modified since it has been saved
671 //============================================================================
672 CORBA::Boolean SALOMEDS_Study_i::IsModified()
674 SALOMEDS::Locker lock;
675 return _impl->IsModified();
678 //============================================================================
679 /*! Function : Modified
680 * Purpose : Sets a Modified flag of a Study to True
682 //============================================================================
683 void SALOMEDS_Study_i::Modified()
685 SALOMEDS::Locker lock;
686 return _impl->Modify();
690 //============================================================================
692 * Purpose : get URL of the study (persistent reference of the study)
694 //============================================================================
695 char* SALOMEDS_Study_i::URL()
697 SALOMEDS::Locker lock;
698 return CORBA::string_dup(_impl->URL().c_str());
701 //============================================================================
703 * Purpose : set URL of the study (persistent reference of the study)
705 //============================================================================
706 void SALOMEDS_Study_i::URL(const char* url)
708 SALOMEDS::Locker lock;
709 _impl->URL(std::string((char*)url));
713 CORBA::Short SALOMEDS_Study_i::StudyId()
715 SALOMEDS::Locker lock;
716 return _impl->StudyId();
719 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
721 SALOMEDS::Locker lock;
725 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
727 SALOMEDS::Locker lock;
728 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
731 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
733 SALOMEDS::Locker lock;
735 SALOMEDSImpl_AttributeIOR* Att = NULL;
736 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
737 char* IOR = CORBA::string_dup(Att->Value().c_str());
738 CORBA::Object_var obj = orb->string_to_object(IOR);
739 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
740 ASSERT(!CORBA::is_nil(aStudy));
741 return SALOMEDS::Study::_duplicate(aStudy);
743 MESSAGE("GetStudy: Problem to get study");
745 return SALOMEDS::Study::_nil();
748 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
750 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
751 return _mapOfStudies[aStudyImpl];
754 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
755 _mapOfStudies[aStudyImpl]=Study_servant;
756 return Study_servant;
760 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
762 SALOMEDS::Locker lock;
763 SALOMEDSImpl_Study::IORUpdated(theAttribute);
766 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
768 SALOMEDS::Locker lock;
770 SALOMEDS::GenericAttribute_ptr aTarget;
771 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
772 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
774 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
780 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
782 SALOMEDS::Locker lock;
784 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
785 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
786 return SP->AttributeStudyProperties::_this();
789 char* SALOMEDS_Study_i::GetLastModificationDate()
791 SALOMEDS::Locker lock;
792 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
795 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
797 SALOMEDS::Locker lock;
799 std::vector<std::string> aSeq = _impl->GetModificationsDate();
800 int aLength = aSeq.size();
801 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
802 aDates->length(aLength);
804 for(int anIndex = 0; anIndex < aLength; anIndex++) {
805 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
807 return aDates._retn();
812 //============================================================================
813 /*! Function : GetUseCaseBuilder
814 * Purpose : Returns a UseCase builder
816 //============================================================================
817 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
819 SALOMEDS::Locker lock;
820 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
821 return UCBuilder->_this();
825 //============================================================================
829 //============================================================================
830 void SALOMEDS_Study_i::Close()
832 SALOMEDS::Locker lock;
836 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
837 for (; itcomponent->More(); itcomponent->Next()) {
838 SALOMEDS::SComponent_var sco = itcomponent->Value();
839 CORBA::String_var compodatatype=sco->ComponentDataType();
840 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
841 // if there is an associated Engine call its method for closing
842 CORBA::String_var IOREngine;
843 if (sco->ComponentIOR(IOREngine)) {
844 // we have found the associated engine to write the data
845 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
846 //_narrow can throw a corba exception
849 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
850 if (!CORBA::is_nil(obj))
852 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
853 if (!anEngine->_is_nil())
856 anEngine->Close(sco);
861 catch (CORBA::Exception&)
867 //Does not need any more this iterator
868 itcomponent->UnRegister();
874 //============================================================================
875 /*! Function : AddPostponed
878 //============================================================================
879 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
881 SALOMEDS::Locker lock;
885 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
887 SALOMEDS::Locker lock;
891 //============================================================================
892 /*! Function : RemovePostponed
895 //============================================================================
897 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/)
899 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
902 SALOMEDS::Locker lock;
904 std::vector<std::string> anIORs = _impl->GetIORs();
905 int i, aSize = (int)anIORs.size();
907 for(i = 0; i < aSize; i++) {
909 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
910 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
911 //rnv: To avoid double deletion of the Salome Generic Objects:
912 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
913 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
914 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
921 //============================================================================
922 /*! Function : UndoPostponed
925 //============================================================================
927 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay)
929 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
932 SALOMEDS::Locker lock;
937 //============================================================================
938 /*! Function : DumpStudy
941 //============================================================================
942 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
943 const char* theBaseName,
944 CORBA::Boolean isPublished,
945 CORBA::Boolean isMultiFile)
947 SALOMEDS::Locker lock;
949 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
950 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
951 CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
956 //============================================================================
957 /*! Function : GetCommonParameters
960 //============================================================================
961 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
963 SALOMEDS::Locker lock;
965 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
966 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
967 return SP->AttributeParameter::_this();
970 //============================================================================
971 /*! Function : GetCommonModuleParameters
974 //============================================================================
975 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
976 const char* theModuleName,
977 CORBA::Long theSavePoint)
979 SALOMEDS::Locker lock;
981 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
982 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
983 return SP->AttributeParameter::_this();
986 //============================================================================
987 /*! Function : SetStudyLock
990 //============================================================================
991 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
993 SALOMEDS::Locker lock;
994 _impl->SetStudyLock(theLockerID);
997 //============================================================================
998 /*! Function : IsStudyLocked
1001 //============================================================================
1002 bool SALOMEDS_Study_i::IsStudyLocked()
1004 SALOMEDS::Locker lock;
1005 return _impl->IsStudyLocked();
1008 //============================================================================
1009 /*! Function : UnLockStudy
1012 //============================================================================
1013 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1015 SALOMEDS::Locker lock;
1016 _impl->UnLockStudy(theLockerID);
1019 //============================================================================
1020 /*! Function : GetLockerID
1023 //============================================================================
1024 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1026 SALOMEDS::Locker lock;
1028 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1030 std::vector<std::string> aSeq = _impl->GetLockerID();
1032 int aLength = aSeq.size();
1033 aResult->length(aLength);
1034 for(int anIndex = 0; anIndex < aLength; anIndex++) {
1035 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1037 return aResult._retn();
1039 //============================================================================
1040 /*! Function : SetReal
1043 //============================================================================
1044 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1046 _impl->SetVariable(std::string(theVarName),
1048 SALOMEDSImpl_GenericVariable::REAL_VAR);
1050 _notifier->modifyNB_Notification(theVarName);
1053 //============================================================================
1054 /*! Function : SetInteger
1057 //============================================================================
1058 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1060 _impl->SetVariable(std::string(theVarName),
1062 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1064 _notifier->modifyNB_Notification(theVarName);
1067 //============================================================================
1068 /*! Function : SetBoolean
1071 //============================================================================
1072 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1074 _impl->SetVariable(std::string(theVarName),
1076 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1078 _notifier->modifyNB_Notification(theVarName);
1081 //============================================================================
1082 /*! Function : SetString
1085 //============================================================================
1086 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1088 _impl->SetStringVariable(std::string(theVarName),
1090 SALOMEDSImpl_GenericVariable::STRING_VAR);
1092 _notifier->modifyNB_Notification(theVarName);
1095 //============================================================================
1096 /*! Function : SetStringAsDouble
1099 //============================================================================
1100 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1102 _impl->SetStringVariableAsDouble(std::string(theVarName),
1104 SALOMEDSImpl_GenericVariable::STRING_VAR);
1107 //============================================================================
1108 /*! Function : GetReal
1111 //============================================================================
1112 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1114 return _impl->GetVariableValue(std::string(theVarName));
1117 //============================================================================
1118 /*! Function : GetInteger
1121 //============================================================================
1122 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1124 return (int)_impl->GetVariableValue(std::string(theVarName));
1127 //============================================================================
1128 /*! Function : GetBoolean
1131 //============================================================================
1132 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1134 return (bool)_impl->GetVariableValue(std::string(theVarName));
1137 //============================================================================
1138 /*! Function : GetString
1141 //============================================================================
1142 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1144 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1147 //============================================================================
1148 /*! Function : IsReal
1151 //============================================================================
1152 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1154 return _impl->IsTypeOf(std::string(theVarName),
1155 SALOMEDSImpl_GenericVariable::REAL_VAR);
1158 //============================================================================
1159 /*! Function : IsInteger
1162 //============================================================================
1163 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1165 return _impl->IsTypeOf(std::string(theVarName),
1166 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1169 //============================================================================
1170 /*! Function : IsBoolean
1173 //============================================================================
1174 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1176 return _impl->IsTypeOf(std::string(theVarName),
1177 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1180 //============================================================================
1181 /*! Function : IsString
1184 //============================================================================
1185 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1187 return _impl->IsTypeOf(std::string(theVarName),
1188 SALOMEDSImpl_GenericVariable::STRING_VAR);
1191 //============================================================================
1192 /*! Function : IsVariable
1195 //============================================================================
1196 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1198 return _impl->IsVariable(std::string(theVarName));
1201 //============================================================================
1202 /*! Function : GetVariableNames
1205 //============================================================================
1206 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1208 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1209 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1211 int aLen = aVarNames.size();
1212 aResult->length(aLen);
1214 for (int anInd = 0; anInd < aLen; anInd++)
1215 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1217 return aResult._retn();
1220 //============================================================================
1221 /*! Function : RemoveVariable
1224 //============================================================================
1225 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1227 CORBA::Boolean res = _impl->RemoveVariable(std::string(theVarName));
1228 if(res && _notifier)
1229 _notifier->modifyNB_Notification(theVarName);
1233 //============================================================================
1234 /*! Function : RenameVariable
1237 //============================================================================
1238 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1240 CORBA::Boolean res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1241 if(res && _notifier)
1242 _notifier->modifyNB_Notification(theVarName);
1246 //============================================================================
1247 /*! Function : IsVariableUsed
1250 //============================================================================
1251 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1253 return _impl->IsVariableUsed(std::string(theVarName));
1257 //============================================================================
1258 /*! Function : ParseVariables
1261 //============================================================================
1262 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1264 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1266 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1268 int aSectionsLen = aSections.size();
1269 aResult->length(aSectionsLen);
1271 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1272 std::vector<std::string> aVarNames = aSections[aSectionInd];
1274 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1276 int aLen = aVarNames.size();
1277 aList->length(aLen);
1279 for (int anInd = 0; anInd < aLen; anInd++)
1280 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1282 aResult[aSectionInd] = aList;
1285 return aResult._retn();
1288 //============================================================================
1289 /*! Function : GetDefaultScript
1292 //============================================================================
1293 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1295 SALOMEDS::Locker lock;
1297 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1298 return CORBA::string_dup(script.c_str());
1301 //============================================================================
1302 /*! Function : EnableUseCaseAutoFilling
1305 //============================================================================
1306 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1308 _impl->EnableUseCaseAutoFilling(isEnabled);
1309 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1312 builder->SetOnAddSObject(_impl->GetCallback());
1313 builder->SetOnRemoveSObject(_impl->GetCallback());
1316 builder->SetOnAddSObject(NULL);
1317 builder->SetOnRemoveSObject(NULL);
1322 //============================================================================
1323 /*! Function : attach
1324 * Purpose : This function attach an observer to the study
1326 //============================================================================
1327 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modify)
1330 static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs,modify);
1333 //===========================================================================
1334 // PRIVATE FUNCTIONS
1335 //===========================================================================
1336 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1339 long pid = (long)_getpid();
1341 long pid = (long)getpid();
1343 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1344 return reinterpret_cast<CORBA::LongLong>(_impl);