1 // Copyright (C) 2007-2012 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.
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>
59 class Notifier: public SALOMEDSImpl_AbstractCallback
62 Notifier(CORBA::ORB_ptr orb)
64 _orb = CORBA::ORB::_duplicate(orb);
67 //============================================================================
68 /*! Function : addSO_Notification
69 * Purpose : This function tells all the observers that a SO has been added
71 //============================================================================
73 virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
75 std::string anID=theSObject.GetID();
76 const char* cID=anID.c_str();
77 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
79 it->first->notifyObserverID(cID,1);
81 return true; // NGE return always true but can be modified if needed
84 //============================================================================
85 /*! Function : removeSO_Notification
86 * Purpose : This function tells all the observers that a SO has been removed
88 //============================================================================
90 virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
92 std::string anID=theSObject.GetID();
93 const char* cID=anID.c_str();
94 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
96 it->first->notifyObserverID(cID,2);
98 return true; // NGE return always true but can be modified if needed
101 //============================================================================
102 /*! Function : modifySO_Notification
103 * Purpose : This function tells all the observers that a SO has been modified
105 //============================================================================
107 virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
109 for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
113 std::string anID=theSObject.GetID();
114 const char* cID=anID.c_str();
115 it->first->notifyObserverID(cID,reason);
118 return true; // NGE return always true but can be modified if needed
121 //============================================================================
122 /*! Function : attach
123 * Purpose : register an Observer
125 //============================================================================
127 virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
129 myObservers.push_back(std::pair< SALOMEDS::Observer_var, bool > (SALOMEDS::Observer::_duplicate(theObs),modify));
133 typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
134 typedef ObsList::iterator ObsListIter;
140 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
142 //============================================================================
143 /*! Function : SALOMEDS_Study_i
144 * Purpose : SALOMEDS_Study_i constructor
146 //============================================================================
147 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
150 _orb = CORBA::ORB::_duplicate(orb);
152 _notifier = new Notifier(_orb);
153 theImpl->setNotifier(_notifier);
155 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
158 //============================================================================
159 /*! Function : ~SALOMEDS_Study_i
160 * Purpose : SALOMEDS_Study_i destructor
162 //============================================================================
163 SALOMEDS_Study_i::~SALOMEDS_Study_i()
165 //delete the builder servant
166 PortableServer::POA_var poa=_builder->_default_POA();
167 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
168 poa->deactivate_object(anObjectId.in());
169 _builder->_remove_ref();
171 //delete implementation
173 _mapOfStudies.erase(_impl);
176 //============================================================================
177 /*! Function : GetPersistentReference
178 * Purpose : Get persistent reference of study (idem URL())
180 //============================================================================
181 char* SALOMEDS_Study_i::GetPersistentReference()
183 SALOMEDS::Locker lock;
184 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
186 //============================================================================
187 /*! Function : GetTransientReference
188 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
190 //============================================================================
191 char* SALOMEDS_Study_i::GetTransientReference()
193 SALOMEDS::Locker lock;
194 return CORBA::string_dup(_impl->GetTransientReference().c_str());
197 //============================================================================
198 /*! Function : IsEmpty
199 * Purpose : Detect if study is empty
201 //============================================================================
202 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
204 SALOMEDS::Locker lock;
205 return _impl->IsEmpty();
208 //============================================================================
209 /*! Function : FindComponent
210 * Purpose : Find a Component with ComponentDataType = aComponentName
212 //============================================================================
213 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
215 SALOMEDS::Locker lock;
217 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
218 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
220 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
224 //============================================================================
225 /*! Function : FindComponentID
226 * Purpose : Find a Component from it's ID
228 //============================================================================
229 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
231 SALOMEDS::Locker lock;
233 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
234 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
236 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
240 //============================================================================
241 /*! Function : FindObject
242 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
244 //============================================================================
245 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
247 SALOMEDS::Locker lock;
249 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
250 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
252 if(aSO.IsComponent()) {
253 SALOMEDSImpl_SComponent aSCO = aSO;
254 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
258 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
263 //============================================================================
264 /*! Function : FindObjectID
265 * Purpose : Find an Object with ID = anObjectID
267 //============================================================================
268 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
270 SALOMEDS::Locker lock;
272 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
273 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
274 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
278 //============================================================================
279 /*! Function : CreateObjectID
280 * Purpose : Creates an Object with ID = anObjectID
282 //============================================================================
283 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
285 SALOMEDS::Locker lock;
287 if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
289 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
290 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
292 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
296 //============================================================================
297 /*! Function : FindObjectByName
298 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
299 * : with ComponentDataType = aComponentName
301 //============================================================================
302 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
303 const char* aComponentName )
305 SALOMEDS::Locker lock;
307 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
308 std::string((char*)aComponentName));
309 int aLength = aSeq.size();
310 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
311 listSO->length(aLength);
312 for(int i = 0; i<aLength; i++) {
313 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
316 return listSO._retn() ;
319 //============================================================================
320 /*! Function : FindObjectIOR
321 * Purpose : Find an Object with IOR = anObjectIOR
323 //============================================================================
324 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
326 SALOMEDS::Locker lock;
328 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
329 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
331 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
335 //============================================================================
336 /*! Function : FindObjectByPath
337 * Purpose : Find an Object by its path = thePath
339 //============================================================================
340 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
342 SALOMEDS::Locker lock;
344 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
345 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
347 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
351 //============================================================================
352 /*! Function : GetObjectPath
355 //============================================================================
356 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
358 SALOMEDS::Locker lock;
360 std::string aPath("");
361 if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
362 SALOMEDSImpl_SObject aSO;
363 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
365 if(!CORBA::is_nil(aSObj)) {
366 aSO = _impl->FindObjectID(aSObj->GetID());
369 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
372 if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
374 aPath = _impl->GetObjectPath(aSO);
375 return CORBA::string_dup(aPath.c_str());
379 //============================================================================
380 /*! Function : SetContext
381 * Purpose : Sets the current context
383 //============================================================================
384 void SALOMEDS_Study_i::SetContext(const char* thePath)
386 SALOMEDS::Locker lock;
388 _impl->SetContext(std::string((char*)thePath));
389 if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
390 throw SALOMEDS::Study::StudyInvalidContext();
393 //============================================================================
394 /*! Function : GetContext
395 * Purpose : Gets the current context
397 //============================================================================
398 char* SALOMEDS_Study_i::GetContext()
400 SALOMEDS::Locker lock;
402 if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
403 return CORBA::string_dup(_impl->GetContext().c_str());
406 //============================================================================
407 /*! Function : GetObjectNames
408 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
410 //============================================================================
411 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
413 SALOMEDS::Locker lock;
415 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
417 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
418 throw SALOMEDS::Study::StudyInvalidContext();
420 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
421 if (_impl->GetErrorCode() == "InvalidContext")
422 throw SALOMEDS::Study::StudyInvalidContext();
424 int aLength = aSeq.size();
425 aResult->length(aLength);
426 for (int anIndex = 0; anIndex < aLength; anIndex++) {
427 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
430 return aResult._retn();
433 //============================================================================
434 /*! Function : GetDirectoryNames
435 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
437 //============================================================================
438 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
440 SALOMEDS::Locker lock;
442 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
444 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
445 throw SALOMEDS::Study::StudyInvalidContext();
447 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
448 if (_impl->GetErrorCode() == "InvalidContext")
449 throw SALOMEDS::Study::StudyInvalidContext();
451 int aLength = aSeq.size();
452 aResult->length(aLength);
453 for (int anIndex = 0; anIndex < aLength; anIndex++) {
454 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
457 return aResult._retn();
460 //============================================================================
461 /*! Function : GetFileNames
462 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
464 //============================================================================
465 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
467 SALOMEDS::Locker lock;
469 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
471 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
472 throw SALOMEDS::Study::StudyInvalidContext();
474 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
475 if (_impl->GetErrorCode() == "InvalidContext")
476 throw SALOMEDS::Study::StudyInvalidContext();
478 int aLength = aSeq.size();
479 aResult->length(aLength);
480 for (int anIndex = 0; anIndex < aLength; anIndex++) {
481 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
484 return aResult._retn();
487 //============================================================================
488 /*! Function : GetComponentNames
489 * Purpose : method to get all components names
490 * SRN: Note, theContext can be any, it doesn't matter
492 //============================================================================
493 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
495 SALOMEDS::Locker lock;
497 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
499 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
501 int aLength = aSeq.size();
502 aResult->length(aLength);
503 for(int anIndex = 0; anIndex < aLength; anIndex++) {
504 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
507 return aResult._retn();
510 //============================================================================
511 /*! Function : NewChildIterator
512 * Purpose : Create a ChildIterator from an SObject
514 //============================================================================
515 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
517 SALOMEDS::Locker lock;
519 CORBA::String_var anID=theSO->GetID();
520 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
521 SALOMEDSImpl_ChildIterator anItr(aSO);
524 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
526 return it_servant->_this();
530 //============================================================================
531 /*! Function : NewComponentIterator
532 * Purpose : Create a SComponentIterator
534 //============================================================================
535 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
537 SALOMEDS::Locker lock;
538 SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
544 //============================================================================
545 /*! Function : NewBuilder
546 * Purpose : Create a StudyBuilder
548 //============================================================================
549 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
551 SALOMEDS::Locker lock;
552 return _builder->_this();
555 //============================================================================
557 * Purpose : get study name
559 //============================================================================
560 char* SALOMEDS_Study_i::Name()
562 SALOMEDS::Locker lock;
563 return CORBA::string_dup(_impl->Name().c_str());
566 //============================================================================
568 * Purpose : set study name
570 //============================================================================
571 void SALOMEDS_Study_i::Name(const char* name)
573 SALOMEDS::Locker lock;
574 _impl->Name(std::string((char*)name));
577 //============================================================================
578 /*! Function : IsSaved
579 * Purpose : get if study has been saved
581 //============================================================================
582 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
584 SALOMEDS::Locker lock;
585 return _impl->IsSaved();
588 //============================================================================
589 /*! Function : IsSaved
590 * Purpose : set if study has been saved
592 //============================================================================
593 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
595 SALOMEDS::Locker lock;
596 _impl->IsSaved(save);
599 //============================================================================
600 /*! Function : IsModified
601 * Purpose : Detect if a Study has been modified since it has been saved
603 //============================================================================
604 CORBA::Boolean SALOMEDS_Study_i::IsModified()
606 SALOMEDS::Locker lock;
607 return _impl->IsModified();
610 //============================================================================
611 /*! Function : Modified
612 * Purpose : Sets a Modified flag of a Study to True
614 //============================================================================
615 void SALOMEDS_Study_i::Modified()
617 SALOMEDS::Locker lock;
618 return _impl->Modify();
622 //============================================================================
624 * Purpose : get URL of the study (persistent reference of the study)
626 //============================================================================
627 char* SALOMEDS_Study_i::URL()
629 SALOMEDS::Locker lock;
630 return CORBA::string_dup(_impl->URL().c_str());
633 //============================================================================
635 * Purpose : set URL of the study (persistent reference of the study)
637 //============================================================================
638 void SALOMEDS_Study_i::URL(const char* url)
640 SALOMEDS::Locker lock;
641 _impl->URL(std::string((char*)url));
645 CORBA::Short SALOMEDS_Study_i::StudyId()
647 SALOMEDS::Locker lock;
648 return _impl->StudyId();
651 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
653 SALOMEDS::Locker lock;
657 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
659 SALOMEDS::Locker lock;
660 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
663 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
665 SALOMEDS::Locker lock;
667 SALOMEDSImpl_AttributeIOR* Att = NULL;
668 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
669 char* IOR = CORBA::string_dup(Att->Value().c_str());
670 CORBA::Object_var obj = orb->string_to_object(IOR);
671 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
672 ASSERT(!CORBA::is_nil(aStudy));
673 return SALOMEDS::Study::_duplicate(aStudy);
675 MESSAGE("GetStudy: Problem to get study");
677 return SALOMEDS::Study::_nil();
680 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
682 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
683 return _mapOfStudies[aStudyImpl];
686 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
687 _mapOfStudies[aStudyImpl]=Study_servant;
688 return Study_servant;
692 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
694 SALOMEDS::Locker lock;
695 SALOMEDSImpl_Study::IORUpdated(theAttribute);
698 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
700 SALOMEDS::Locker lock;
702 SALOMEDS::GenericAttribute_ptr aTarget;
703 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
704 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
706 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
712 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
714 SALOMEDS::Locker lock;
716 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
717 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
718 return SP->AttributeStudyProperties::_this();
721 char* SALOMEDS_Study_i::GetLastModificationDate()
723 SALOMEDS::Locker lock;
724 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
727 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
729 SALOMEDS::Locker lock;
731 std::vector<std::string> aSeq = _impl->GetModificationsDate();
732 int aLength = aSeq.size();
733 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
734 aDates->length(aLength);
736 for(int anIndex = 0; anIndex < aLength; anIndex++) {
737 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
739 return aDates._retn();
744 //============================================================================
745 /*! Function : GetUseCaseBuilder
746 * Purpose : Returns a UseCase builder
748 //============================================================================
749 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
751 SALOMEDS::Locker lock;
752 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
753 return UCBuilder->_this();
757 //============================================================================
761 //============================================================================
762 void SALOMEDS_Study_i::Close()
764 SALOMEDS::Locker lock;
768 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
769 for (; itcomponent->More(); itcomponent->Next()) {
770 SALOMEDS::SComponent_var sco = itcomponent->Value();
771 CORBA::String_var compodatatype=sco->ComponentDataType();
772 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
773 // if there is an associated Engine call its method for closing
774 CORBA::String_var IOREngine;
775 if (sco->ComponentIOR(IOREngine)) {
776 // we have found the associated engine to write the data
777 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
778 //_narrow can throw a corba exception
781 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
782 if (!CORBA::is_nil(obj))
784 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
785 if (!anEngine->_is_nil())
788 anEngine->Close(sco);
793 catch (CORBA::Exception&)
799 //Does not need any more this iterator
800 itcomponent->UnRegister();
806 //============================================================================
807 /*! Function : AddPostponed
810 //============================================================================
811 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
813 SALOMEDS::Locker lock;
817 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
819 SALOMEDS::Locker lock;
823 //============================================================================
824 /*! Function : RemovePostponed
827 //============================================================================
829 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/)
831 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
834 SALOMEDS::Locker lock;
836 std::vector<std::string> anIORs = _impl->GetIORs();
837 int i, aSize = (int)anIORs.size();
839 for(i = 0; i < aSize; i++) {
841 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
842 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
843 //rnv: To avoid double deletion of the Salome Generic Objects:
844 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
845 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
846 //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
853 //============================================================================
854 /*! Function : UndoPostponed
857 //============================================================================
859 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay)
861 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
864 SALOMEDS::Locker lock;
869 //============================================================================
870 /*! Function : DumpStudy
873 //============================================================================
874 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
875 const char* theBaseName,
876 CORBA::Boolean isPublished,
877 CORBA::Boolean isMultiFile)
879 SALOMEDS::Locker lock;
881 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
882 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
883 CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
888 //============================================================================
889 /*! Function : GetCommonParameters
892 //============================================================================
893 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
895 SALOMEDS::Locker lock;
897 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
898 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
899 return SP->AttributeParameter::_this();
902 //============================================================================
903 /*! Function : GetCommonModuleParameters
906 //============================================================================
907 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
908 const char* theModuleName,
909 CORBA::Long theSavePoint)
911 SALOMEDS::Locker lock;
913 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
914 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
915 return SP->AttributeParameter::_this();
918 //============================================================================
919 /*! Function : SetStudyLock
922 //============================================================================
923 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
925 SALOMEDS::Locker lock;
926 _impl->SetStudyLock(theLockerID);
929 //============================================================================
930 /*! Function : IsStudyLocked
933 //============================================================================
934 bool SALOMEDS_Study_i::IsStudyLocked()
936 SALOMEDS::Locker lock;
937 return _impl->IsStudyLocked();
940 //============================================================================
941 /*! Function : UnLockStudy
944 //============================================================================
945 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
947 SALOMEDS::Locker lock;
948 _impl->UnLockStudy(theLockerID);
951 //============================================================================
952 /*! Function : GetLockerID
955 //============================================================================
956 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
958 SALOMEDS::Locker lock;
960 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
962 std::vector<std::string> aSeq = _impl->GetLockerID();
964 int aLength = aSeq.size();
965 aResult->length(aLength);
966 for(int anIndex = 0; anIndex < aLength; anIndex++) {
967 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
969 return aResult._retn();
971 //============================================================================
972 /*! Function : SetReal
975 //============================================================================
976 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
978 _impl->SetVariable(std::string(theVarName),
980 SALOMEDSImpl_GenericVariable::REAL_VAR);
983 //============================================================================
984 /*! Function : SetInteger
987 //============================================================================
988 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
990 _impl->SetVariable(std::string(theVarName),
992 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
995 //============================================================================
996 /*! Function : SetBoolean
999 //============================================================================
1000 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1002 _impl->SetVariable(std::string(theVarName),
1004 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1007 //============================================================================
1008 /*! Function : SetString
1011 //============================================================================
1012 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1014 _impl->SetStringVariable(std::string(theVarName),
1016 SALOMEDSImpl_GenericVariable::STRING_VAR);
1019 //============================================================================
1020 /*! Function : SetStringAsDouble
1023 //============================================================================
1024 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1026 _impl->SetStringVariableAsDouble(std::string(theVarName),
1028 SALOMEDSImpl_GenericVariable::STRING_VAR);
1031 //============================================================================
1032 /*! Function : GetReal
1035 //============================================================================
1036 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1038 return _impl->GetVariableValue(std::string(theVarName));
1041 //============================================================================
1042 /*! Function : GetInteger
1045 //============================================================================
1046 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1048 return (int)_impl->GetVariableValue(std::string(theVarName));
1051 //============================================================================
1052 /*! Function : GetBoolean
1055 //============================================================================
1056 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1058 return (bool)_impl->GetVariableValue(std::string(theVarName));
1061 //============================================================================
1062 /*! Function : GetString
1065 //============================================================================
1066 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1068 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1071 //============================================================================
1072 /*! Function : IsReal
1075 //============================================================================
1076 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1078 return _impl->IsTypeOf(std::string(theVarName),
1079 SALOMEDSImpl_GenericVariable::REAL_VAR);
1082 //============================================================================
1083 /*! Function : IsInteger
1086 //============================================================================
1087 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1089 return _impl->IsTypeOf(std::string(theVarName),
1090 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1093 //============================================================================
1094 /*! Function : IsBoolean
1097 //============================================================================
1098 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1100 return _impl->IsTypeOf(std::string(theVarName),
1101 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1104 //============================================================================
1105 /*! Function : IsString
1108 //============================================================================
1109 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1111 return _impl->IsTypeOf(std::string(theVarName),
1112 SALOMEDSImpl_GenericVariable::STRING_VAR);
1115 //============================================================================
1116 /*! Function : IsVariable
1119 //============================================================================
1120 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1122 return _impl->IsVariable(std::string(theVarName));
1125 //============================================================================
1126 /*! Function : GetVariableNames
1129 //============================================================================
1130 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1132 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1133 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1135 int aLen = aVarNames.size();
1136 aResult->length(aLen);
1138 for (int anInd = 0; anInd < aLen; anInd++)
1139 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1141 return aResult._retn();
1144 //============================================================================
1145 /*! Function : RemoveVariable
1148 //============================================================================
1149 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1151 return _impl->RemoveVariable(std::string(theVarName));
1154 //============================================================================
1155 /*! Function : RenameVariable
1158 //============================================================================
1159 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1161 return _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1164 //============================================================================
1165 /*! Function : IsVariableUsed
1168 //============================================================================
1169 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1171 return _impl->IsVariableUsed(std::string(theVarName));
1175 //============================================================================
1176 /*! Function : ParseVariables
1179 //============================================================================
1180 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1182 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1184 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1186 int aSectionsLen = aSections.size();
1187 aResult->length(aSectionsLen);
1189 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1190 std::vector<std::string> aVarNames = aSections[aSectionInd];
1192 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1194 int aLen = aVarNames.size();
1195 aList->length(aLen);
1197 for (int anInd = 0; anInd < aLen; anInd++)
1198 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1200 aResult[aSectionInd] = aList;
1203 return aResult._retn();
1206 //============================================================================
1207 /*! Function : GetDefaultScript
1210 //============================================================================
1211 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1213 SALOMEDS::Locker lock;
1215 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1216 return CORBA::string_dup(script.c_str());
1219 //============================================================================
1220 /*! Function : EnableUseCaseAutoFilling
1223 //============================================================================
1224 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1226 _impl->EnableUseCaseAutoFilling(isEnabled);
1227 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1230 builder->SetOnAddSObject(_impl->GetCallback());
1231 builder->SetOnRemoveSObject(_impl->GetCallback());
1234 builder->SetOnAddSObject(NULL);
1235 builder->SetOnRemoveSObject(NULL);
1240 //============================================================================
1241 /*! Function : attach
1242 * Purpose : This function attach an observer to the study
1244 //============================================================================
1245 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modify)
1248 _notifier->attach(theObs,modify);
1251 //===========================================================================
1252 // PRIVATE FUNCTIONS
1253 //===========================================================================
1254 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1257 long pid = (long)_getpid();
1259 long pid = (long)getpid();
1261 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1262 return reinterpret_cast<CORBA::LongLong>(_impl);