1 // Copyright (C) 2007-2010 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"
46 #include "DF_Label.hxx"
47 #include "DF_Attribute.hxx"
49 #include "Basics_Utils.hxx"
54 #include <sys/types.h>
58 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
60 //============================================================================
61 /*! Function : SALOMEDS_Study_i
62 * Purpose : SALOMEDS_Study_i constructor
64 //============================================================================
65 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
68 _orb = CORBA::ORB::_duplicate(orb);
71 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
74 //============================================================================
75 /*! Function : ~SALOMEDS_Study_i
76 * Purpose : SALOMEDS_Study_i destructor
78 //============================================================================
79 SALOMEDS_Study_i::~SALOMEDS_Study_i()
81 //delete the builder servant
82 PortableServer::POA_var poa=_builder->_default_POA();
83 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
84 poa->deactivate_object(anObjectId.in());
85 _builder->_remove_ref();
87 //delete implementation
89 _mapOfStudies.erase(_impl);
92 //============================================================================
93 /*! Function : GetPersistentReference
94 * Purpose : Get persistent reference of study (idem URL())
96 //============================================================================
97 char* SALOMEDS_Study_i::GetPersistentReference()
99 SALOMEDS::Locker lock;
100 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
102 //============================================================================
103 /*! Function : GetTransientReference
104 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
106 //============================================================================
107 char* SALOMEDS_Study_i::GetTransientReference()
109 SALOMEDS::Locker lock;
110 return CORBA::string_dup(_impl->GetTransientReference().c_str());
113 //============================================================================
114 /*! Function : IsEmpty
115 * Purpose : Detect if study is empty
117 //============================================================================
118 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
120 SALOMEDS::Locker lock;
121 return _impl->IsEmpty();
124 //============================================================================
125 /*! Function : FindComponent
126 * Purpose : Find a Component with ComponentDataType = aComponentName
128 //============================================================================
129 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
131 SALOMEDS::Locker lock;
133 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
134 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
136 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
140 //============================================================================
141 /*! Function : FindComponentID
142 * Purpose : Find a Component from it's ID
144 //============================================================================
145 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
147 SALOMEDS::Locker lock;
149 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
150 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
152 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
156 //============================================================================
157 /*! Function : FindObject
158 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
160 //============================================================================
161 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
163 SALOMEDS::Locker lock;
165 SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
166 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
168 if(aSO.IsComponent()) {
169 SALOMEDSImpl_SComponent aSCO = aSO;
170 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
174 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
179 //============================================================================
180 /*! Function : FindObjectID
181 * Purpose : Find an Object with ID = anObjectID
183 //============================================================================
184 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
186 SALOMEDS::Locker lock;
188 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
189 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
190 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
194 //============================================================================
195 /*! Function : CreateObjectID
196 * Purpose : Creates an Object with ID = anObjectID
198 //============================================================================
199 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
201 SALOMEDS::Locker lock;
203 if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
205 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
206 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
208 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
212 //============================================================================
213 /*! Function : FindObjectByName
214 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
215 * : with ComponentDataType = aComponentName
217 //============================================================================
218 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
219 const char* aComponentName )
221 SALOMEDS::Locker lock;
223 std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
224 std::string((char*)aComponentName));
225 int aLength = aSeq.size();
226 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
227 listSO->length(aLength);
228 for(int i = 0; i<aLength; i++) {
229 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
232 return listSO._retn() ;
235 //============================================================================
236 /*! Function : FindObjectIOR
237 * Purpose : Find an Object with IOR = anObjectIOR
239 //============================================================================
240 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
242 SALOMEDS::Locker lock;
244 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
245 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
247 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
251 //============================================================================
252 /*! Function : FindObjectByPath
253 * Purpose : Find an Object by its path = thePath
255 //============================================================================
256 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
258 SALOMEDS::Locker lock;
260 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
261 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
263 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
267 //============================================================================
268 /*! Function : GetObjectPath
271 //============================================================================
272 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
274 SALOMEDS::Locker lock;
276 std::string aPath("");
277 if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
278 SALOMEDSImpl_SObject aSO;
279 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
281 if(!CORBA::is_nil(aSObj)) {
282 aSO = _impl->FindObjectID(aSObj->GetID());
285 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
288 if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
290 aPath = _impl->GetObjectPath(aSO);
291 return CORBA::string_dup(aPath.c_str());
295 //============================================================================
296 /*! Function : SetContext
297 * Purpose : Sets the current context
299 //============================================================================
300 void SALOMEDS_Study_i::SetContext(const char* thePath)
302 SALOMEDS::Locker lock;
304 _impl->SetContext(std::string((char*)thePath));
305 if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
306 throw SALOMEDS::Study::StudyInvalidContext();
309 //============================================================================
310 /*! Function : GetContext
311 * Purpose : Gets the current context
313 //============================================================================
314 char* SALOMEDS_Study_i::GetContext()
316 SALOMEDS::Locker lock;
318 if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
319 return CORBA::string_dup(_impl->GetContext().c_str());
322 //============================================================================
323 /*! Function : GetObjectNames
324 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
326 //============================================================================
327 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
329 SALOMEDS::Locker lock;
331 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
333 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
334 throw SALOMEDS::Study::StudyInvalidContext();
336 std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
337 if (_impl->GetErrorCode() == "InvalidContext")
338 throw SALOMEDS::Study::StudyInvalidContext();
340 int aLength = aSeq.size();
341 aResult->length(aLength);
342 for (int anIndex = 0; anIndex < aLength; anIndex++) {
343 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
346 return aResult._retn();
349 //============================================================================
350 /*! Function : GetDirectoryNames
351 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
353 //============================================================================
354 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
356 SALOMEDS::Locker lock;
358 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
360 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
361 throw SALOMEDS::Study::StudyInvalidContext();
363 std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
364 if (_impl->GetErrorCode() == "InvalidContext")
365 throw SALOMEDS::Study::StudyInvalidContext();
367 int aLength = aSeq.size();
368 aResult->length(aLength);
369 for (int anIndex = 0; anIndex < aLength; anIndex++) {
370 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
373 return aResult._retn();
376 //============================================================================
377 /*! Function : GetFileNames
378 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
380 //============================================================================
381 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
383 SALOMEDS::Locker lock;
385 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
387 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
388 throw SALOMEDS::Study::StudyInvalidContext();
390 std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
391 if (_impl->GetErrorCode() == "InvalidContext")
392 throw SALOMEDS::Study::StudyInvalidContext();
394 int aLength = aSeq.size();
395 aResult->length(aLength);
396 for (int anIndex = 0; anIndex < aLength; anIndex++) {
397 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
400 return aResult._retn();
403 //============================================================================
404 /*! Function : GetComponentNames
405 * Purpose : method to get all components names
406 * SRN: Note, theContext can be any, it doesn't matter
408 //============================================================================
409 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
411 SALOMEDS::Locker lock;
413 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
415 std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
417 int aLength = aSeq.size();
418 aResult->length(aLength);
419 for(int anIndex = 0; anIndex < aLength; anIndex++) {
420 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
423 return aResult._retn();
426 //============================================================================
427 /*! Function : NewChildIterator
428 * Purpose : Create a ChildIterator from an SObject
430 //============================================================================
431 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
433 SALOMEDS::Locker lock;
435 CORBA::String_var anID=theSO->GetID();
436 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
437 SALOMEDSImpl_ChildIterator anItr(aSO);
440 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
442 return it_servant->_this();
446 //============================================================================
447 /*! Function : NewComponentIterator
448 * Purpose : Create a SComponentIterator
450 //============================================================================
451 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
453 SALOMEDS::Locker lock;
454 SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
460 //============================================================================
461 /*! Function : NewBuilder
462 * Purpose : Create a StudyBuilder
464 //============================================================================
465 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
467 SALOMEDS::Locker lock;
468 return _builder->_this();
471 //============================================================================
473 * Purpose : get study name
475 //============================================================================
476 char* SALOMEDS_Study_i::Name()
478 SALOMEDS::Locker lock;
479 return CORBA::string_dup(_impl->Name().c_str());
482 //============================================================================
484 * Purpose : set study name
486 //============================================================================
487 void SALOMEDS_Study_i::Name(const char* name)
489 SALOMEDS::Locker lock;
490 _impl->Name(std::string((char*)name));
493 //============================================================================
494 /*! Function : IsSaved
495 * Purpose : get if study has been saved
497 //============================================================================
498 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
500 SALOMEDS::Locker lock;
501 return _impl->IsSaved();
504 //============================================================================
505 /*! Function : IsSaved
506 * Purpose : set if study has been saved
508 //============================================================================
509 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
511 SALOMEDS::Locker lock;
512 _impl->IsSaved(save);
515 //============================================================================
516 /*! Function : IsModified
517 * Purpose : Detect if a Study has been modified since it has been saved
519 //============================================================================
520 CORBA::Boolean SALOMEDS_Study_i::IsModified()
522 SALOMEDS::Locker lock;
523 return _impl->IsModified();
526 //============================================================================
527 /*! Function : Modified
528 * Purpose : Sets a Modified flag of a Study to True
530 //============================================================================
531 void SALOMEDS_Study_i::Modified()
533 SALOMEDS::Locker lock;
534 return _impl->Modify();
538 //============================================================================
540 * Purpose : get URL of the study (persistent reference of the study)
542 //============================================================================
543 char* SALOMEDS_Study_i::URL()
545 SALOMEDS::Locker lock;
546 return CORBA::string_dup(_impl->URL().c_str());
549 //============================================================================
551 * Purpose : set URL of the study (persistent reference of the study)
553 //============================================================================
554 void SALOMEDS_Study_i::URL(const char* url)
556 SALOMEDS::Locker lock;
557 _impl->URL(std::string((char*)url));
561 CORBA::Short SALOMEDS_Study_i::StudyId()
563 SALOMEDS::Locker lock;
564 return _impl->StudyId();
567 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
569 SALOMEDS::Locker lock;
573 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
575 SALOMEDS::Locker lock;
576 _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
579 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
581 SALOMEDS::Locker lock;
583 SALOMEDSImpl_AttributeIOR* Att = NULL;
584 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
585 char* IOR = CORBA::string_dup(Att->Value().c_str());
586 CORBA::Object_var obj = orb->string_to_object(IOR);
587 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
588 ASSERT(!CORBA::is_nil(aStudy));
589 return SALOMEDS::Study::_duplicate(aStudy);
591 MESSAGE("GetStudy: Problem to get study");
593 return SALOMEDS::Study::_nil();
596 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
598 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
599 return _mapOfStudies[aStudyImpl];
602 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
603 _mapOfStudies[aStudyImpl]=Study_servant;
604 return Study_servant;
608 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
610 SALOMEDS::Locker lock;
611 SALOMEDSImpl_Study::IORUpdated(theAttribute);
614 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
616 SALOMEDS::Locker lock;
618 SALOMEDS::GenericAttribute_ptr aTarget;
619 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
620 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
622 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
628 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
630 SALOMEDS::Locker lock;
632 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
633 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
634 return SP->AttributeStudyProperties::_this();
637 char* SALOMEDS_Study_i::GetLastModificationDate()
639 SALOMEDS::Locker lock;
640 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
643 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
645 SALOMEDS::Locker lock;
647 std::vector<std::string> aSeq = _impl->GetModificationsDate();
648 int aLength = aSeq.size();
649 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
650 aDates->length(aLength);
652 for(int anIndex = 0; anIndex < aLength; anIndex++) {
653 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
655 return aDates._retn();
660 //============================================================================
661 /*! Function : GetUseCaseBuilder
662 * Purpose : Returns a UseCase builder
664 //============================================================================
665 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
667 SALOMEDS::Locker lock;
668 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
669 return UCBuilder->_this();
673 //============================================================================
677 //============================================================================
678 void SALOMEDS_Study_i::Close()
680 SALOMEDS::Locker lock;
684 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
685 for (; itcomponent->More(); itcomponent->Next()) {
686 SALOMEDS::SComponent_var sco = itcomponent->Value();
687 CORBA::String_var compodatatype=sco->ComponentDataType();
688 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
689 // if there is an associated Engine call its method for closing
690 CORBA::String_var IOREngine;
691 if (sco->ComponentIOR(IOREngine)) {
692 // we have found the associated engine to write the data
693 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
694 //_narrow can throw a corba exception
697 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
698 if (!CORBA::is_nil(obj))
700 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
701 if (!anEngine->_is_nil())
704 anEngine->Close(sco);
709 catch (CORBA::Exception&)
715 //Does not need any more this iterator
716 itcomponent->Destroy();
722 //============================================================================
723 /*! Function : AddPostponed
726 //============================================================================
727 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
729 SALOMEDS::Locker lock;
733 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
735 SALOMEDS::Locker lock;
739 //============================================================================
740 /*! Function : RemovePostponed
743 //============================================================================
745 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/)
747 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
750 SALOMEDS::Locker lock;
752 std::vector<std::string> anIORs = _impl->GetIORs();
753 int i, aSize = (int)anIORs.size();
755 for(i = 0; i < aSize; i++) {
757 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
758 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
759 //rnv: To avoid double deletion of the Salome Generic Objects:
760 //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
761 //rnv: 2. Second decrement of the reference count in the next string : aGeneric->Destroy();
762 //if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
769 //============================================================================
770 /*! Function : UndoPostponed
773 //============================================================================
775 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay)
777 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
780 SALOMEDS::Locker lock;
785 //============================================================================
786 /*! Function : DumpStudy
789 //============================================================================
790 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
791 const char* theBaseName,
792 CORBA::Boolean isPublished)
794 SALOMEDS::Locker lock;
796 std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
797 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
798 CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
803 //============================================================================
804 /*! Function : GetCommonParameters
807 //============================================================================
808 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
810 SALOMEDS::Locker lock;
812 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
813 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
814 return SP->AttributeParameter::_this();
817 //============================================================================
818 /*! Function : GetCommonModuleParameters
821 //============================================================================
822 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
823 const char* theModuleName,
824 CORBA::Long theSavePoint)
826 SALOMEDS::Locker lock;
828 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
829 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
830 return SP->AttributeParameter::_this();
833 //============================================================================
834 /*! Function : SetStudyLock
837 //============================================================================
838 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
840 SALOMEDS::Locker lock;
841 _impl->SetStudyLock(theLockerID);
844 //============================================================================
845 /*! Function : IsStudyLocked
848 //============================================================================
849 bool SALOMEDS_Study_i::IsStudyLocked()
851 SALOMEDS::Locker lock;
852 return _impl->IsStudyLocked();
855 //============================================================================
856 /*! Function : UnLockStudy
859 //============================================================================
860 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
862 SALOMEDS::Locker lock;
863 _impl->UnLockStudy(theLockerID);
866 //============================================================================
867 /*! Function : GetLockerID
870 //============================================================================
871 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
873 SALOMEDS::Locker lock;
875 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
877 std::vector<std::string> aSeq = _impl->GetLockerID();
879 int aLength = aSeq.size();
880 aResult->length(aLength);
881 for(int anIndex = 0; anIndex < aLength; anIndex++) {
882 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
884 return aResult._retn();
886 //============================================================================
887 /*! Function : SetReal
890 //============================================================================
891 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
893 _impl->SetVariable(std::string(theVarName),
895 SALOMEDSImpl_GenericVariable::REAL_VAR);
898 //============================================================================
899 /*! Function : SetInteger
902 //============================================================================
903 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
905 _impl->SetVariable(std::string(theVarName),
907 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
910 //============================================================================
911 /*! Function : SetBoolean
914 //============================================================================
915 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
917 _impl->SetVariable(std::string(theVarName),
919 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
922 //============================================================================
923 /*! Function : SetString
926 //============================================================================
927 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
929 _impl->SetStringVariable(std::string(theVarName),
931 SALOMEDSImpl_GenericVariable::STRING_VAR);
934 //============================================================================
935 /*! Function : SetStringAsDouble
938 //============================================================================
939 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
941 _impl->SetStringVariableAsDouble(std::string(theVarName),
943 SALOMEDSImpl_GenericVariable::STRING_VAR);
946 //============================================================================
947 /*! Function : GetReal
950 //============================================================================
951 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
953 return _impl->GetVariableValue(std::string(theVarName));
956 //============================================================================
957 /*! Function : GetInteger
960 //============================================================================
961 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
963 return (int)_impl->GetVariableValue(std::string(theVarName));
966 //============================================================================
967 /*! Function : GetBoolean
970 //============================================================================
971 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
973 return (bool)_impl->GetVariableValue(std::string(theVarName));
976 //============================================================================
977 /*! Function : GetString
980 //============================================================================
981 char* SALOMEDS_Study_i::GetString(const char* theVarName)
983 return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
986 //============================================================================
987 /*! Function : IsReal
990 //============================================================================
991 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
993 return _impl->IsTypeOf(std::string(theVarName),
994 SALOMEDSImpl_GenericVariable::REAL_VAR);
997 //============================================================================
998 /*! Function : IsInteger
1001 //============================================================================
1002 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1004 return _impl->IsTypeOf(std::string(theVarName),
1005 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1008 //============================================================================
1009 /*! Function : IsBoolean
1012 //============================================================================
1013 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1015 return _impl->IsTypeOf(std::string(theVarName),
1016 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1019 //============================================================================
1020 /*! Function : IsString
1023 //============================================================================
1024 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1026 return _impl->IsTypeOf(std::string(theVarName),
1027 SALOMEDSImpl_GenericVariable::STRING_VAR);
1030 //============================================================================
1031 /*! Function : IsVariable
1034 //============================================================================
1035 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1037 return _impl->IsVariable(std::string(theVarName));
1040 //============================================================================
1041 /*! Function : GetVariableNames
1044 //============================================================================
1045 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1047 std::vector<std::string> aVarNames = _impl->GetVariableNames();
1048 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1050 int aLen = aVarNames.size();
1051 aResult->length(aLen);
1053 for (int anInd = 0; anInd < aLen; anInd++)
1054 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1056 return aResult._retn();
1059 //============================================================================
1060 /*! Function : RemoveVariable
1063 //============================================================================
1064 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1066 return _impl->RemoveVariable(std::string(theVarName));
1069 //============================================================================
1070 /*! Function : RenameVariable
1073 //============================================================================
1074 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1076 return _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1079 //============================================================================
1080 /*! Function : IsVariableUsed
1083 //============================================================================
1084 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1086 return _impl->IsVariableUsed(std::string(theVarName));
1090 //============================================================================
1091 /*! Function : ParseVariables
1094 //============================================================================
1095 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1097 std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1099 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1101 int aSectionsLen = aSections.size();
1102 aResult->length(aSectionsLen);
1104 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1105 std::vector<std::string> aVarNames = aSections[aSectionInd];
1107 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1109 int aLen = aVarNames.size();
1110 aList->length(aLen);
1112 for (int anInd = 0; anInd < aLen; anInd++)
1113 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1115 aResult[aSectionInd] = aList;
1118 return aResult._retn();
1121 //============================================================================
1122 /*! Function : GetDefaultScript
1125 //============================================================================
1126 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1128 SALOMEDS::Locker lock;
1130 std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1131 return CORBA::string_dup(script.c_str());
1134 //============================================================================
1135 /*! Function : EnableUseCaseAutoFilling
1138 //============================================================================
1139 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1141 _impl->EnableUseCaseAutoFilling(isEnabled);
1142 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1145 builder->SetOnAddSObject(_impl->GetCallback());
1146 builder->SetOnRemoveSObject(_impl->GetCallback());
1149 builder->SetOnAddSObject(NULL);
1150 builder->SetOnRemoveSObject(NULL);
1155 //===========================================================================
1156 // PRIVATE FUNCTIONS
1157 //===========================================================================
1158 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1161 long pid = (long)_getpid();
1163 long pid = (long)getpid();
1165 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1166 return reinterpret_cast<CORBA::LongLong>(_impl);