1 // Copyright (C) 2007-2008 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
22 // File : SALOMEDS_Study_i.cxx
23 // Author : Sergey RUIN
26 #include "utilities.h"
27 #include "SALOMEDS_Study_i.hxx"
28 #include "SALOMEDS_StudyManager_i.hxx"
29 #include "SALOMEDS_UseCaseIterator_i.hxx"
30 #include "SALOMEDS_GenericAttribute_i.hxx"
31 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
32 #include "SALOMEDS_AttributeParameter_i.hxx"
33 #include "SALOMEDS_ChildIterator_i.hxx"
34 #include "SALOMEDS_Driver_i.hxx"
35 #include "SALOMEDS.hxx"
37 #include "SALOMEDSImpl_SObject.hxx"
38 #include "SALOMEDSImpl_SComponent.hxx"
39 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
40 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
41 #include "SALOMEDSImpl_AttributeParameter.hxx"
42 #include "SALOMEDSImpl_ChildIterator.hxx"
43 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "DF_Label.hxx"
46 #include "DF_Attribute.hxx"
48 #include "Basics_Utils.hxx"
53 #include <sys/types.h>
59 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
61 //============================================================================
62 /*! Function : SALOMEDS_Study_i
63 * Purpose : SALOMEDS_Study_i constructor
65 //============================================================================
66 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
69 _orb = CORBA::ORB::_duplicate(orb);
72 _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
75 //============================================================================
76 /*! Function : ~SALOMEDS_Study_i
77 * Purpose : SALOMEDS_Study_i destructor
79 //============================================================================
80 SALOMEDS_Study_i::~SALOMEDS_Study_i()
82 //delete the builder servant
83 PortableServer::POA_var poa=_builder->_default_POA();
84 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
85 poa->deactivate_object(anObjectId.in());
86 _builder->_remove_ref();
88 //delete implementation
90 _mapOfStudies.erase(_impl);
93 //============================================================================
94 /*! Function : GetPersistentReference
95 * Purpose : Get persistent reference of study (idem URL())
97 //============================================================================
98 char* SALOMEDS_Study_i::GetPersistentReference()
100 SALOMEDS::Locker lock;
101 return CORBA::string_dup(_impl->GetPersistentReference().c_str());
103 //============================================================================
104 /*! Function : GetTransientReference
105 * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root)
107 //============================================================================
108 char* SALOMEDS_Study_i::GetTransientReference()
110 SALOMEDS::Locker lock;
111 return CORBA::string_dup(_impl->GetTransientReference().c_str());
114 //============================================================================
115 /*! Function : IsEmpty
116 * Purpose : Detect if study is empty
118 //============================================================================
119 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
121 SALOMEDS::Locker lock;
122 return _impl->IsEmpty();
125 //============================================================================
126 /*! Function : FindComponent
127 * Purpose : Find a Component with ComponentDataType = aComponentName
129 //============================================================================
130 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
132 SALOMEDS::Locker lock;
134 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(string(aComponentName));
135 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
137 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
141 //============================================================================
142 /*! Function : FindComponentID
143 * Purpose : Find a Component from it's ID
145 //============================================================================
146 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
148 SALOMEDS::Locker lock;
150 SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(string((char*)aComponentID));
151 if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
153 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
157 //============================================================================
158 /*! Function : FindObject
159 * Purpose : Find an Object with SALOMEDS::Name = anObjectName
161 //============================================================================
162 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
164 SALOMEDS::Locker lock;
166 SALOMEDSImpl_SObject aSO = _impl->FindObject(string((char*)anObjectName));
167 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
169 if(aSO.IsComponent()) {
170 SALOMEDSImpl_SComponent aSCO = aSO;
171 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
175 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
180 //============================================================================
181 /*! Function : FindObjectID
182 * Purpose : Find an Object with ID = anObjectID
184 //============================================================================
185 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
187 SALOMEDS::Locker lock;
189 SALOMEDSImpl_SObject aSO = _impl->FindObjectID(string((char*)anObjectID));
190 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
191 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
195 //============================================================================
196 /*! Function : CreateObjectID
197 * Purpose : Creates an Object with ID = anObjectID
199 //============================================================================
200 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
202 SALOMEDS::Locker lock;
204 if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
206 SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
207 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
209 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
213 //============================================================================
214 /*! Function : FindObjectByName
215 * Purpose : Find Objects with SALOMEDS::Name = anObjectName in a Component
216 * : with ComponentDataType = aComponentName
218 //============================================================================
219 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
220 const char* aComponentName )
222 SALOMEDS::Locker lock;
224 vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(string((char*)anObjectName),
225 string((char*)aComponentName));
226 int aLength = aSeq.size();
227 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
228 listSO->length(aLength);
229 for(int i = 0; i<aLength; i++) {
230 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
233 return listSO._retn() ;
236 //============================================================================
237 /*! Function : FindObjectIOR
238 * Purpose : Find an Object with IOR = anObjectIOR
240 //============================================================================
241 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
243 SALOMEDS::Locker lock;
245 SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(string((char*)anObjectIOR));
246 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
248 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
252 //============================================================================
253 /*! Function : FindObjectByPath
254 * Purpose : Find an Object by its path = thePath
256 //============================================================================
257 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
259 SALOMEDS::Locker lock;
261 SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(string((char*)thePath));
262 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
264 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
268 //============================================================================
269 /*! Function : GetObjectPath
272 //============================================================================
273 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
275 SALOMEDS::Locker lock;
278 if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
279 SALOMEDSImpl_SObject aSO;
280 SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
282 if(!CORBA::is_nil(aSObj)) {
283 aSO = _impl->FindObjectID(aSObj->GetID());
286 aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
289 if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
291 aPath = _impl->GetObjectPath(aSO);
292 return CORBA::string_dup(aPath.c_str());
296 //============================================================================
297 /*! Function : SetContext
298 * Purpose : Sets the current context
300 //============================================================================
301 void SALOMEDS_Study_i::SetContext(const char* thePath)
303 SALOMEDS::Locker lock;
305 _impl->SetContext(string((char*)thePath));
306 if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext")
307 throw SALOMEDS::Study::StudyInvalidContext();
310 //============================================================================
311 /*! Function : GetContext
312 * Purpose : Gets the current context
314 //============================================================================
315 char* SALOMEDS_Study_i::GetContext()
317 SALOMEDS::Locker lock;
319 if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
320 return CORBA::string_dup(_impl->GetContext().c_str());
323 //============================================================================
324 /*! Function : GetObjectNames
325 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
327 //============================================================================
328 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext)
330 SALOMEDS::Locker lock;
332 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
334 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
335 throw SALOMEDS::Study::StudyInvalidContext();
337 vector<string> aSeq = _impl->GetObjectNames(string((char*)theContext));
338 if (_impl->GetErrorCode() == "InvalidContext")
339 throw SALOMEDS::Study::StudyInvalidContext();
341 int aLength = aSeq.size();
342 aResult->length(aLength);
343 for (int anIndex = 0; anIndex < aLength; anIndex++) {
344 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
347 return aResult._retn();
350 //============================================================================
351 /*! Function : GetDirectoryNames
352 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
354 //============================================================================
355 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext)
357 SALOMEDS::Locker lock;
359 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
361 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
362 throw SALOMEDS::Study::StudyInvalidContext();
364 vector<string> aSeq = _impl->GetDirectoryNames(string((char*)theContext));
365 if (_impl->GetErrorCode() == "InvalidContext")
366 throw SALOMEDS::Study::StudyInvalidContext();
368 int aLength = aSeq.size();
369 aResult->length(aLength);
370 for (int anIndex = 0; anIndex < aLength; anIndex++) {
371 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
374 return aResult._retn();
377 //============================================================================
378 /*! Function : GetFileNames
379 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
381 //============================================================================
382 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
384 SALOMEDS::Locker lock;
386 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
388 if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
389 throw SALOMEDS::Study::StudyInvalidContext();
391 vector<string> aSeq = _impl->GetFileNames(string((char*)theContext));
392 if (_impl->GetErrorCode() == "InvalidContext")
393 throw SALOMEDS::Study::StudyInvalidContext();
395 int aLength = aSeq.size();
396 aResult->length(aLength);
397 for (int anIndex = 0; anIndex < aLength; anIndex++) {
398 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
401 return aResult._retn();
404 //============================================================================
405 /*! Function : GetComponentNames
406 * Purpose : method to get all components names
407 * SRN: Note, theContext can be any, it doesn't matter
409 //============================================================================
410 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext)
412 SALOMEDS::Locker lock;
414 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
416 vector<string> aSeq = _impl->GetComponentNames(string((char*)theContext));
418 int aLength = aSeq.size();
419 aResult->length(aLength);
420 for(int anIndex = 0; anIndex < aLength; anIndex++) {
421 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
424 return aResult._retn();
427 //============================================================================
428 /*! Function : NewChildIterator
429 * Purpose : Create a ChildIterator from an SObject
431 //============================================================================
432 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
434 SALOMEDS::Locker lock;
436 CORBA::String_var anID=theSO->GetID();
437 SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
438 SALOMEDSImpl_ChildIterator anItr(aSO);
441 SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
443 return it_servant->_this();
447 //============================================================================
448 /*! Function : NewComponentIterator
449 * Purpose : Create a SComponentIterator
451 //============================================================================
452 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
454 SALOMEDS::Locker lock;
455 SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
461 //============================================================================
462 /*! Function : NewBuilder
463 * Purpose : Create a StudyBuilder
465 //============================================================================
466 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
468 SALOMEDS::Locker lock;
469 return _builder->_this();
472 //============================================================================
474 * Purpose : get study name
476 //============================================================================
477 char* SALOMEDS_Study_i::Name()
479 SALOMEDS::Locker lock;
480 return CORBA::string_dup(_impl->Name().c_str());
483 //============================================================================
485 * Purpose : set study name
487 //============================================================================
488 void SALOMEDS_Study_i::Name(const char* name)
490 SALOMEDS::Locker lock;
491 _impl->Name(string((char*)name));
494 //============================================================================
495 /*! Function : IsSaved
496 * Purpose : get if study has been saved
498 //============================================================================
499 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
501 SALOMEDS::Locker lock;
502 return _impl->IsSaved();
505 //============================================================================
506 /*! Function : IsSaved
507 * Purpose : set if study has been saved
509 //============================================================================
510 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
512 SALOMEDS::Locker lock;
513 _impl->IsSaved(save);
516 //============================================================================
517 /*! Function : IsModified
518 * Purpose : Detect if a Study has been modified since it has been saved
520 //============================================================================
521 CORBA::Boolean SALOMEDS_Study_i::IsModified()
523 SALOMEDS::Locker lock;
524 return _impl->IsModified();
527 //============================================================================
528 /*! Function : Modified
529 * Purpose : Sets a Modified flag of a Study to True
531 //============================================================================
532 void SALOMEDS_Study_i::Modified()
534 SALOMEDS::Locker lock;
535 return _impl->Modify();
539 //============================================================================
541 * Purpose : get URL of the study (persistent reference of the study)
543 //============================================================================
544 char* SALOMEDS_Study_i::URL()
546 SALOMEDS::Locker lock;
547 return CORBA::string_dup(_impl->URL().c_str());
550 //============================================================================
552 * Purpose : set URL of the study (persistent reference of the study)
554 //============================================================================
555 void SALOMEDS_Study_i::URL(const char* url)
557 SALOMEDS::Locker lock;
558 _impl->URL(string((char*)url));
562 CORBA::Short SALOMEDS_Study_i::StudyId()
564 SALOMEDS::Locker lock;
565 return _impl->StudyId();
568 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
570 SALOMEDS::Locker lock;
574 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
576 SALOMEDS::Locker lock;
577 _impl->UpdateIORLabelMap(string((char*)anIOR), string((char*)anEntry));
580 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
582 SALOMEDS::Locker lock;
584 SALOMEDSImpl_AttributeIOR* Att = NULL;
585 if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
586 char* IOR = CORBA::string_dup(Att->Value().c_str());
587 CORBA::Object_var obj = orb->string_to_object(IOR);
588 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
589 ASSERT(!CORBA::is_nil(aStudy));
590 return SALOMEDS::Study::_duplicate(aStudy);
592 MESSAGE("GetStudy: Problem to get study");
594 return SALOMEDS::Study::_nil();
597 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
599 if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end())
600 return _mapOfStudies[aStudyImpl];
603 SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
604 _mapOfStudies[aStudyImpl]=Study_servant;
605 return Study_servant;
609 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute)
611 SALOMEDS::Locker lock;
612 SALOMEDSImpl_Study::IORUpdated(theAttribute);
615 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject)
617 SALOMEDS::Locker lock;
619 SALOMEDS::GenericAttribute_ptr aTarget;
620 if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
621 return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
623 SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
629 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
631 SALOMEDS::Locker lock;
633 SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
634 SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
635 return SP->AttributeStudyProperties::_this();
638 char* SALOMEDS_Study_i::GetLastModificationDate()
640 SALOMEDS::Locker lock;
641 return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
644 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate()
646 SALOMEDS::Locker lock;
648 vector<string> aSeq = _impl->GetModificationsDate();
649 int aLength = aSeq.size();
650 SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
651 aDates->length(aLength);
653 for(int anIndex = 0; anIndex < aLength; anIndex++) {
654 aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
656 return aDates._retn();
661 //============================================================================
662 /*! Function : GetUseCaseBuilder
663 * Purpose : Returns a UseCase builder
665 //============================================================================
666 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
668 SALOMEDS::Locker lock;
669 SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
670 return UCBuilder->_this();
674 //============================================================================
678 //============================================================================
679 void SALOMEDS_Study_i::Close()
681 SALOMEDS::Locker lock;
685 SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
686 for (; itcomponent->More(); itcomponent->Next()) {
687 SALOMEDS::SComponent_var sco = itcomponent->Value();
688 CORBA::String_var compodatatype=sco->ComponentDataType();
689 MESSAGE ( "Look for an engine for data type :"<< compodatatype);
690 // if there is an associated Engine call its method for closing
691 CORBA::String_var IOREngine;
692 if (sco->ComponentIOR(IOREngine)) {
693 // we have found the associated engine to write the data
694 MESSAGE ( "We have found an engine for data type :"<< compodatatype);
695 //_narrow can throw a corba exception
698 CORBA::Object_var obj = _orb->string_to_object(IOREngine);
699 if (!CORBA::is_nil(obj))
701 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
702 if (!anEngine->_is_nil())
705 anEngine->Close(sco);
710 catch (CORBA::Exception&)
716 //Does not need any more this iterator
717 itcomponent->Destroy();
723 //============================================================================
724 /*! Function : AddPostponed
727 //============================================================================
728 void SALOMEDS_Study_i::AddPostponed(const char* theIOR)
730 SALOMEDS::Locker lock;
734 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
736 SALOMEDS::Locker lock;
740 //============================================================================
741 /*! Function : RemovePostponed
744 //============================================================================
746 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/)
748 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
751 SALOMEDS::Locker lock;
753 vector<string> anIORs = _impl->GetIORs();
754 int i, aSize = (int)anIORs.size();
756 for(i = 0; i < aSize; i++) {
758 CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
759 SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
760 if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
767 //============================================================================
768 /*! Function : UndoPostponed
771 //============================================================================
773 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay)
775 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
778 SALOMEDS::Locker lock;
783 //============================================================================
784 /*! Function : DumpStudy
787 //============================================================================
788 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
789 const char* theBaseName,
790 CORBA::Boolean isPublished)
792 SALOMEDS::Locker lock;
794 string aPath((char*)thePath), aBaseName((char*)theBaseName);
795 SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
796 CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
801 //============================================================================
802 /*! Function : GetCommonParameters
805 //============================================================================
806 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
808 SALOMEDS::Locker lock;
810 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
811 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
812 return SP->AttributeParameter::_this();
815 //============================================================================
816 /*! Function : GetCommonModuleParameters
819 //============================================================================
820 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID,
821 const char* theModuleName,
822 CORBA::Long theSavePoint)
824 SALOMEDS::Locker lock;
826 SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
827 SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
828 return SP->AttributeParameter::_this();
831 //============================================================================
832 /*! Function : SetStudyLock
835 //============================================================================
836 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
838 SALOMEDS::Locker lock;
839 _impl->SetStudyLock(theLockerID);
842 //============================================================================
843 /*! Function : IsStudyLocked
846 //============================================================================
847 bool SALOMEDS_Study_i::IsStudyLocked()
849 SALOMEDS::Locker lock;
850 return _impl->IsStudyLocked();
853 //============================================================================
854 /*! Function : UnLockStudy
857 //============================================================================
858 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
860 SALOMEDS::Locker lock;
861 _impl->UnLockStudy(theLockerID);
864 //============================================================================
865 /*! Function : GetLockerID
868 //============================================================================
869 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
871 SALOMEDS::Locker lock;
873 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
875 vector<string> aSeq = _impl->GetLockerID();
877 int aLength = aSeq.size();
878 aResult->length(aLength);
879 for(int anIndex = 0; anIndex < aLength; anIndex++) {
880 aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
882 return aResult._retn();
884 //============================================================================
885 /*! Function : SetReal
888 //============================================================================
889 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
891 _impl->SetVariable(string(theVarName),
893 SALOMEDSImpl_GenericVariable::REAL_VAR);
896 //============================================================================
897 /*! Function : SetInteger
900 //============================================================================
901 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
903 _impl->SetVariable(string(theVarName),
905 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
908 //============================================================================
909 /*! Function : SetBoolean
912 //============================================================================
913 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
915 _impl->SetVariable(string(theVarName),
917 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
920 //============================================================================
921 /*! Function : SetString
924 //============================================================================
925 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
927 _impl->SetStringVariable(string(theVarName),
929 SALOMEDSImpl_GenericVariable::STRING_VAR);
932 //============================================================================
933 /*! Function : SetStringAsDouble
936 //============================================================================
937 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
939 _impl->SetStringVariableAsDouble(string(theVarName),
941 SALOMEDSImpl_GenericVariable::STRING_VAR);
944 //============================================================================
945 /*! Function : GetReal
948 //============================================================================
949 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
951 return _impl->GetVariableValue(string(theVarName));
954 //============================================================================
955 /*! Function : GetInteger
958 //============================================================================
959 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
961 return (int)_impl->GetVariableValue(string(theVarName));
964 //============================================================================
965 /*! Function : GetBoolean
968 //============================================================================
969 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
971 return (bool)_impl->GetVariableValue(string(theVarName));
974 //============================================================================
975 /*! Function : GetString
978 //============================================================================
979 char* SALOMEDS_Study_i::GetString(const char* theVarName)
981 return CORBA::string_dup(_impl->GetStringVariableValue(string(theVarName)).c_str());
984 //============================================================================
985 /*! Function : IsReal
988 //============================================================================
989 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
991 return _impl->IsTypeOf(string(theVarName),
992 SALOMEDSImpl_GenericVariable::REAL_VAR);
995 //============================================================================
996 /*! Function : IsInteger
999 //============================================================================
1000 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1002 return _impl->IsTypeOf(string(theVarName),
1003 SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1006 //============================================================================
1007 /*! Function : IsBoolean
1010 //============================================================================
1011 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1013 return _impl->IsTypeOf(string(theVarName),
1014 SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1017 //============================================================================
1018 /*! Function : IsString
1021 //============================================================================
1022 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1024 return _impl->IsTypeOf(string(theVarName),
1025 SALOMEDSImpl_GenericVariable::STRING_VAR);
1028 //============================================================================
1029 /*! Function : IsVariable
1032 //============================================================================
1033 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1035 return _impl->IsVariable(string(theVarName));
1038 //============================================================================
1039 /*! Function : GetVariableNames
1042 //============================================================================
1043 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1045 vector<string> aVarNames = _impl->GetVariableNames();
1046 SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1048 int aLen = aVarNames.size();
1049 aResult->length(aLen);
1051 for (int anInd = 0; anInd < aLen; anInd++)
1052 aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1054 return aResult._retn();
1057 //============================================================================
1058 /*! Function : RemoveVariable
1061 //============================================================================
1062 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1064 return _impl->RemoveVariable(string(theVarName));
1067 //============================================================================
1068 /*! Function : RenameVariable
1071 //============================================================================
1072 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1074 return _impl->RenameVariable(string(theVarName), string(theNewVarName));
1077 //============================================================================
1078 /*! Function : IsVariableUsed
1081 //============================================================================
1082 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1084 return _impl->IsVariableUsed(string(theVarName));
1088 //============================================================================
1089 /*! Function : ParseVariables
1092 //============================================================================
1093 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1095 vector< vector<string> > aSections = _impl->ParseVariables(string(theVarName));
1097 SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1099 int aSectionsLen = aSections.size();
1100 aResult->length(aSectionsLen);
1102 for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1103 vector<string> aVarNames = aSections[aSectionInd];
1105 SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1107 int aLen = aVarNames.size();
1108 aList->length(aLen);
1110 for (int anInd = 0; anInd < aLen; anInd++)
1111 aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1113 aResult[aSectionInd] = aList;
1116 return aResult._retn();
1119 //============================================================================
1120 /*! Function : GetDefaultScript
1123 //============================================================================
1124 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1126 SALOMEDS::Locker lock;
1128 string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1129 return CORBA::string_dup(script.c_str());
1132 //============================================================================
1133 /*! Function : EnableUseCaseAutoFilling
1136 //============================================================================
1137 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled)
1139 _impl->EnableUseCaseAutoFilling(isEnabled);
1140 SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1143 builder->SetOnAddSObject(_impl->GetCallback());
1144 builder->SetOnRemoveSObject(_impl->GetCallback());
1147 builder->SetOnAddSObject(NULL);
1148 builder->SetOnRemoveSObject(NULL);
1153 //===========================================================================
1154 // PRIVATE FUNCTIONS
1155 //===========================================================================
1156 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1159 long pid = (long)_getpid();
1161 long pid = (long)getpid();
1163 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1164 return reinterpret_cast<CORBA::LongLong>(_impl);