Salome HOME
CCAR: remove memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOMEDS_Study.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "utilities.h" 
27
28 #include "SALOMEDS_Study.hxx"
29
30 #include "SALOMEDS.hxx"
31 #include "SALOMEDS_SComponent.hxx"
32 #include "SALOMEDS_SObject.hxx"
33 #include "SALOMEDS_StudyBuilder.hxx"
34 #include "SALOMEDS_ChildIterator.hxx"
35 #include "SALOMEDS_SComponentIterator.hxx"
36 #include "SALOMEDS_AttributeStudyProperties.hxx"
37 #include "SALOMEDS_AttributeParameter.hxx"
38 #include "SALOMEDS_UseCaseBuilder.hxx"
39
40 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "SALOMEDSImpl_SObject.hxx"
42 #include "SALOMEDSImpl_StudyBuilder.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_SComponentIterator.hxx"
45 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
46 #include "SALOMEDSImpl_AttributeParameter.hxx"
47 #include "SALOMEDSImpl_GenericVariable.hxx"
48 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
49
50 #include "SALOMEDS_Driver_i.hxx"
51 #include "SALOMEDS_Study_i.hxx"
52
53 #include "Utils_ORB_INIT.hxx" 
54 #include "Utils_SINGLETON.hxx" 
55
56 #include "Basics_Utils.hxx"
57
58 #ifdef WIN32
59 #include <process.h>
60 #else
61 #include <sys/types.h>
62 #include <unistd.h>
63 #endif
64
65 using namespace std; 
66
67 SALOMEDS_Study::SALOMEDS_Study(SALOMEDSImpl_Study* theStudy)
68 {
69   _isLocal = true;
70   _local_impl = theStudy;
71   _corba_impl = SALOMEDS::Study::_nil();
72   init_orb();
73 }
74
75 SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
76 {
77 #ifdef WIN32
78   long pid =  (long)_getpid();
79 #else
80   long pid =  (long)getpid();
81 #endif  
82
83   long addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
84   if(_isLocal) {
85     _local_impl = reinterpret_cast<SALOMEDSImpl_Study*>(addr);
86     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
87   }
88   else {
89     _local_impl = NULL;
90     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
91   }
92
93   init_orb();
94 }
95
96 SALOMEDS_Study::~SALOMEDS_Study()
97 {
98 }
99
100 std::string SALOMEDS_Study::GetPersistentReference()
101 {
102   std::string aRef;
103   if (_isLocal) {
104     SALOMEDS::Locker lock;
105     aRef = _local_impl->GetPersistentReference();
106   }
107   else aRef = (CORBA::String_var)_corba_impl->GetPersistentReference();
108   return aRef;
109 }
110
111 std::string SALOMEDS_Study::GetTransientReference()
112 {
113   std::string aRef;
114   if (_isLocal) {
115     SALOMEDS::Locker lock;
116     aRef = _local_impl->GetTransientReference();
117   }
118   else aRef = _corba_impl->GetTransientReference();
119   return aRef;
120 }
121  
122 bool SALOMEDS_Study::IsEmpty()
123 {
124   bool ret;
125   if (_isLocal) {
126     SALOMEDS::Locker lock;
127     ret = _local_impl->IsEmpty();
128   }
129   else ret = _corba_impl->IsEmpty();
130   return ret;
131 }
132
133 _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentName)
134 {
135   SALOMEDSClient_SComponent* aSCO = NULL;
136   if (_isLocal) {
137     SALOMEDS::Locker lock;
138
139     SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponent(aComponentName);
140     if (!aSCO_impl) return _PTR(SComponent)(aSCO);
141     aSCO = new SALOMEDS_SComponent(aSCO_impl);
142   }
143   else {
144     SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponent((char*)aComponentName.c_str());
145     if (CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
146     aSCO = new SALOMEDS_SComponent(aSCO_impl);
147   }
148   return _PTR(SComponent)(aSCO);
149 }
150  
151 _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID)
152 {  
153   SALOMEDSClient_SComponent* aSCO = NULL;
154   if (_isLocal) {
155     SALOMEDS::Locker lock;
156
157     SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponentID(aComponentID);
158     if (!aSCO_impl) return _PTR(SComponent)(aSCO);
159     aSCO = new SALOMEDS_SComponent(aSCO_impl);
160   }
161   else {
162     SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponentID((char*)aComponentID.c_str());
163     if(CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
164     aSCO = new SALOMEDS_SComponent(aSCO_impl);
165   }
166   return _PTR(SComponent)(aSCO);
167 }
168  
169 _PTR(SObject) SALOMEDS_Study::FindObject(const std::string& anObjectName)
170 {
171   SALOMEDSClient_SObject* aSO = NULL;
172
173   if (_isLocal) {
174     SALOMEDS::Locker lock;
175
176     SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObject(anObjectName);
177     if (!aSO_impl) return _PTR(SObject)(aSO);
178     if(aSO_impl.IsComponent()) {
179         SALOMEDSImpl_SComponent aSCO_impl = aSO_impl;
180         return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
181     }   
182     aSO = new SALOMEDS_SObject(aSO_impl);
183   }
184   else { 
185     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str());
186     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
187     SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl);
188     if (!CORBA::is_nil(aSCO_impl)) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
189     aSO = new SALOMEDS_SObject(aSO_impl);
190   }
191
192   return _PTR(SObject)(aSO);
193 }
194
195 std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& anObjectName, 
196                                                             const std::string& aComponentName)   
197 {
198   std::vector<_PTR(SObject)> aVector;
199   int i, aLength = 0;
200
201   if (_isLocal) {
202     SALOMEDS::Locker lock;
203
204     vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindObjectByName(anObjectName, aComponentName);
205     aLength = aSeq.size();
206     for (i = 0; i< aLength; i++) 
207       aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
208   }
209   else {
210     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindObjectByName((char*)anObjectName.c_str(), 
211                                                                             (char*)aComponentName.c_str());
212     aLength = aSeq->length();
213     for (i = 0; i< aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
214   }
215
216   return aVector;
217 }
218
219 _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID)
220 {
221   SALOMEDSClient_SObject* aSO = NULL;
222   if (_isLocal) {
223     SALOMEDS::Locker lock;
224
225     SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectID(anObjectID);
226     if(!aSO_impl) return _PTR(SObject)(aSO);
227     return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
228   }
229   else { 
230     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectID((char*)anObjectID.c_str());
231     if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
232     return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
233   }
234   return _PTR(SObject)(aSO);
235 }
236  
237 _PTR(SObject) SALOMEDS_Study::CreateObjectID(const std::string& anObjectID)
238 {
239   SALOMEDSClient_SObject* aSO = NULL;
240   if (_isLocal) {
241     SALOMEDS::Locker lock;
242     SALOMEDSImpl_SObject aSO_impl = _local_impl->CreateObjectID(anObjectID);
243     if(!aSO_impl) return _PTR(SObject)(aSO);
244     aSO = new SALOMEDS_SObject(aSO_impl);
245   }
246   else { 
247     SALOMEDS::SObject_var aSO_impl = _corba_impl->CreateObjectID((char*)anObjectID.c_str());
248     if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
249     aSO = new SALOMEDS_SObject(aSO_impl);
250   }
251   return _PTR(SObject)(aSO);
252 }
253
254 _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR)
255 {
256   SALOMEDSClient_SObject* aSO = NULL;
257   if (_isLocal) {
258     SALOMEDS::Locker lock;
259
260     SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectIOR(anObjectIOR);
261     if (!aSO_impl) return _PTR(SObject)(aSO);
262     aSO = new SALOMEDS_SObject(aSO_impl);
263   }
264   else { 
265     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectIOR((char*)anObjectIOR.c_str());
266     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
267     aSO = new SALOMEDS_SObject(aSO_impl);
268   }
269   return _PTR(SObject)(aSO);
270 }
271
272 _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath)
273 {
274   SALOMEDSClient_SObject* aSO = NULL;
275   if (_isLocal) {
276     SALOMEDS::Locker lock;
277
278     SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectByPath(thePath);
279     if (!aSO_impl) return _PTR(SObject)(aSO);
280     aSO = new SALOMEDS_SObject(aSO_impl);
281   }
282   else {
283     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectByPath((char*)thePath.c_str());
284     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
285     aSO = new SALOMEDS_SObject(aSO_impl);
286   }
287   return _PTR(SObject)(aSO);
288 }
289
290 std::string SALOMEDS_Study::GetObjectPath(const _PTR(SObject)& theSO)
291 {
292   if(!theSO) return "";
293   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
294   std::string aPath;
295   if (_isLocal) {
296     SALOMEDS::Locker lock;
297     aPath = _local_impl->GetObjectPath(*(aSO->GetLocalImpl()));
298   }
299   else aPath = _corba_impl->GetObjectPath(aSO->GetCORBAImpl());
300   return aPath;
301 }
302
303 void SALOMEDS_Study::SetContext(const std::string& thePath)
304 {
305   if (_isLocal) {
306     SALOMEDS::Locker lock;
307     _local_impl->SetContext(thePath);
308   }
309   else _corba_impl->SetContext((char*)thePath.c_str());
310 }
311
312 std::string SALOMEDS_Study::GetContext()  
313 {
314   std::string aPath;
315   if (_isLocal) {
316     SALOMEDS::Locker lock;
317     aPath = _local_impl->GetContext();
318   }
319   else aPath = _corba_impl->GetContext();
320   return aPath;
321 }
322
323 std::vector<std::string> SALOMEDS_Study::GetObjectNames(const std::string& theContext)
324 {
325   std::vector<std::string> aVector;
326   int aLength, i;
327   if (_isLocal) {
328     SALOMEDS::Locker lock;
329     aVector = _local_impl->GetObjectNames(theContext);
330   }
331   else {
332     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
333     aLength = aSeq->length();
334     for (i = 0; i < aLength; i++) aVector.push_back(std::string((std::string)aSeq[i].in()));
335   }
336   return aVector;
337 }
338  
339 std::vector<std::string> SALOMEDS_Study::GetDirectoryNames(const std::string& theContext)
340 {
341   std::vector<std::string> aVector;
342   int aLength, i;
343   if (_isLocal) {
344     SALOMEDS::Locker lock;
345     aVector = _local_impl->GetDirectoryNames(theContext);
346   }
347   else {
348     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
349     aLength = aSeq->length();
350     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
351   }
352   return aVector;
353 }
354  
355 std::vector<std::string> SALOMEDS_Study::GetFileNames(const std::string& theContext)
356 {
357   std::vector<std::string> aVector;
358   int aLength, i;
359   if (_isLocal) {
360     SALOMEDS::Locker lock;
361     aVector = _local_impl->GetFileNames(theContext);
362   }
363   else {
364     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
365     aLength = aSeq->length();
366
367     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
368   }
369   return aVector;
370 }
371  
372 std::vector<std::string> SALOMEDS_Study::GetComponentNames(const std::string& theContext)
373 {
374   std::vector<std::string> aVector;
375   int aLength, i;
376   if (_isLocal) {
377     SALOMEDS::Locker lock;
378     aVector = _local_impl->GetComponentNames(theContext);
379   }
380   else {
381     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
382     aLength = aSeq->length();
383     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
384   }
385   return aVector;
386 }
387
388 _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO)
389 {
390   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
391   SALOMEDSClient_ChildIterator* aCI = NULL; 
392   if (_isLocal) {
393     SALOMEDS::Locker lock;
394     SALOMEDSImpl_ChildIterator aCIimpl = _local_impl->NewChildIterator(*(aSO->GetLocalImpl()));
395     aCI = new SALOMEDS_ChildIterator(aCIimpl);
396   }
397   else {
398     SALOMEDS::ChildIterator_var aCIimpl = _corba_impl->NewChildIterator(aSO->GetCORBAImpl());
399     aCI = new SALOMEDS_ChildIterator(aCIimpl);
400   }
401
402   return _PTR(ChildIterator)(aCI);
403 }
404
405 _PTR(SComponentIterator) SALOMEDS_Study::NewComponentIterator()
406 {
407   SALOMEDSClient_SComponentIterator* aCI = NULL; 
408   if (_isLocal) {
409     SALOMEDS::Locker lock;
410
411     SALOMEDSImpl_SComponentIterator aCIimpl = _local_impl->NewComponentIterator();
412     aCI = new SALOMEDS_SComponentIterator(aCIimpl);
413   }
414   else {
415     SALOMEDS::SComponentIterator_var aCIimpl = _corba_impl->NewComponentIterator();
416     aCI = new SALOMEDS_SComponentIterator(aCIimpl);
417   }
418
419   return _PTR(SComponentIterator)(aCI);
420 }
421
422 _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder()
423 {
424   SALOMEDSClient_StudyBuilder* aSB = NULL; 
425   if (_isLocal) {
426     SALOMEDS::Locker lock;
427
428     SALOMEDSImpl_StudyBuilder* aSBimpl = _local_impl->NewBuilder();
429     aSB = new SALOMEDS_StudyBuilder(aSBimpl);
430   }
431   else {
432     SALOMEDS::StudyBuilder_var aSBimpl = _corba_impl->NewBuilder();
433     aSB = new SALOMEDS_StudyBuilder(aSBimpl);
434   }
435
436   return _PTR(StudyBuilder)(aSB);
437 }
438
439 std::string SALOMEDS_Study::Name()
440 {
441   std::string aName;
442   if (_isLocal) {
443     SALOMEDS::Locker lock;
444     aName = _local_impl->Name();
445   }
446   else aName = _corba_impl->Name();
447   return aName;
448 }
449
450 void SALOMEDS_Study::Name(const std::string& theName)
451 {
452   if (_isLocal) {
453     SALOMEDS::Locker lock;
454     _local_impl->Name(theName);
455   }
456   else _corba_impl->Name((char*)theName.c_str());
457 }
458
459 bool SALOMEDS_Study::IsSaved()
460 {
461   bool isSaved;
462   if (_isLocal) {
463     SALOMEDS::Locker lock;
464     isSaved = _local_impl->IsSaved();
465   }
466   else isSaved = _corba_impl->IsSaved();
467   return isSaved;
468 }
469
470 void SALOMEDS_Study::IsSaved(bool save)
471 {
472   if (_isLocal) {
473     SALOMEDS::Locker lock;
474     _local_impl->IsSaved(save);
475   }
476   else _corba_impl->IsSaved(save);
477 }
478
479 bool SALOMEDS_Study::IsModified()
480 {
481   bool isModified;
482   if (_isLocal) {
483     SALOMEDS::Locker lock;
484     isModified = _local_impl->IsModified();
485   }
486   else isModified = _corba_impl->IsModified();
487   return isModified;
488 }
489
490 void SALOMEDS_Study::Modified()
491 {
492   if (_isLocal) {
493     SALOMEDS::Locker lock;
494     _local_impl->Modify();
495   }
496   else _corba_impl->Modified();
497 }
498
499  
500 std::string SALOMEDS_Study::URL()
501 {
502   std::string aURL;
503   if (_isLocal) {
504     SALOMEDS::Locker lock;
505     aURL = _local_impl->URL();
506   }
507   else aURL = _corba_impl->URL();
508   return aURL;
509 }
510
511 void SALOMEDS_Study::URL(const std::string& url)
512 {
513   if (_isLocal) {
514     SALOMEDS::Locker lock;
515     _local_impl->URL(url);
516   }
517   else _corba_impl->URL((char*)url.c_str());
518 }
519
520 int SALOMEDS_Study::StudyId()
521 {
522   int anID;
523   if (_isLocal) {
524     SALOMEDS::Locker lock;
525     anID = _local_impl->StudyId();
526   }
527   else anID = _corba_impl->StudyId();
528   return anID;
529 }
530  
531 void SALOMEDS_Study::StudyId(int id) 
532 {
533   if (_isLocal) {
534     SALOMEDS::Locker lock;
535     _local_impl->StudyId(id);
536   }
537   else _corba_impl->StudyId(id);  
538 }
539
540 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
541 {
542   std::vector<_PTR(SObject)> aVector;
543   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
544   int aLength, i;
545   if (_isLocal) {
546     SALOMEDS::Locker lock;
547
548     vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindDependances(*(aSO->GetLocalImpl()));
549     if (aSeq.size()) {
550       aLength = aSeq.size();
551       for (i = 0; i < aLength; i++) 
552         aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
553     }
554   }
555   else {
556     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindDependances(aSO->GetCORBAImpl());
557     aLength = aSeq->length();
558     for (i = 0; i < aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
559   }
560   return aVector;
561 }
562  
563 _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties()
564 {
565   SALOMEDSClient_AttributeStudyProperties* aProp;
566   if (_isLocal) {
567     SALOMEDS::Locker lock;
568     aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties());
569   }
570   else aProp = new SALOMEDS_AttributeStudyProperties((SALOMEDS::AttributeStudyProperties_var)_corba_impl->GetProperties());
571   return _PTR(AttributeStudyProperties)(aProp);
572 }
573  
574 std::string SALOMEDS_Study::GetLastModificationDate() 
575 {
576   std::string aDate;
577   if (_isLocal) {
578     SALOMEDS::Locker lock;
579     aDate = _local_impl->GetLastModificationDate();
580   }
581   else aDate = _corba_impl->GetLastModificationDate();
582   return aDate;
583 }
584
585 std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
586 {
587   std::vector<std::string> aVector;
588   int aLength, i;
589   if (_isLocal) {
590     SALOMEDS::Locker lock;
591     aVector = _local_impl->GetModificationsDate();
592   }
593   else {
594     SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
595     aLength = aSeq->length();
596     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
597   }
598   return aVector;
599 }
600
601 _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
602 {
603   SALOMEDSClient_UseCaseBuilder* aUB = NULL;
604   if (_isLocal) {
605     SALOMEDS::Locker lock;
606
607     SALOMEDSImpl_UseCaseBuilder* aUBimpl = _local_impl->GetUseCaseBuilder();
608     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
609   }
610   else {
611     SALOMEDS::UseCaseBuilder_var aUBimpl = _corba_impl->GetUseCaseBuilder();
612     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
613   }
614
615   return _PTR(UseCaseBuilder)(aUB);
616 }
617
618 void SALOMEDS_Study::Close()
619 {
620   if (_isLocal) {
621     SALOMEDS::Locker lock;
622     _local_impl->Close();
623   }
624   else _corba_impl->Close();
625 }
626
627 void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
628 {
629   if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
630   else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
631 }
632
633 bool SALOMEDS_Study::DumpStudy(const string& thePath, const string& theBaseName, bool isPublished)
634 {
635   //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one
636   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
637   bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished);
638   return ret;
639 }     
640
641 void SALOMEDS_Study::SetStudyLock(const string& theLockerID)
642 {
643   if (_isLocal) {
644     SALOMEDS::Locker lock;
645     _local_impl->SetStudyLock(theLockerID.c_str());
646   }
647   else _corba_impl->SetStudyLock((char*)theLockerID.c_str());
648 }
649  
650 bool SALOMEDS_Study::IsStudyLocked()
651 {
652   bool isLocked;
653   if (_isLocal) {
654     SALOMEDS::Locker lock;
655     isLocked = _local_impl->IsStudyLocked();
656   }
657   else isLocked = _corba_impl->IsStudyLocked();
658   return isLocked;
659 }
660  
661 void SALOMEDS_Study::UnLockStudy(const string& theLockerID)
662 {
663   if(_isLocal) _local_impl->UnLockStudy(theLockerID.c_str());
664   else _corba_impl->UnLockStudy((char*)theLockerID.c_str());
665 }
666
667 vector<string> SALOMEDS_Study::GetLockerID()
668 {
669   std::vector<std::string> aVector;
670   int aLength, i;
671   if (_isLocal) {
672     SALOMEDS::Locker lock;
673     aVector = _local_impl->GetLockerID();
674   }
675   else {
676     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
677     aLength = aSeq->length();
678     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
679   }
680   return aVector;
681 }
682
683
684 void SALOMEDS_Study::SetReal(const string& theVarName, const double theValue)
685 {
686   if (_isLocal) {
687     SALOMEDS::Locker lock;
688     _local_impl->SetVariable(theVarName,
689                              theValue,
690                              SALOMEDSImpl_GenericVariable::REAL_VAR);
691   }
692   else 
693     _corba_impl->SetReal((char*)theVarName.c_str(),theValue);
694 }
695
696 void SALOMEDS_Study::SetInteger(const string& theVarName, const int theValue)
697 {
698   if (_isLocal) {
699     SALOMEDS::Locker lock;
700     _local_impl->SetVariable(theVarName,
701                              theValue,
702                              SALOMEDSImpl_GenericVariable::INTEGER_VAR);
703   }
704   else 
705     _corba_impl->SetInteger((char*)theVarName.c_str(),theValue);
706 }
707
708 void SALOMEDS_Study::SetBoolean(const string& theVarName, const bool theValue)
709 {
710   if (_isLocal) {
711     SALOMEDS::Locker lock;
712     _local_impl->SetVariable(theVarName,
713                              theValue,
714                              SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
715   }
716   else 
717     _corba_impl->SetBoolean((char*)theVarName.c_str(),theValue);
718 }
719
720 double SALOMEDS_Study::GetReal(const string& theVarName)
721 {
722   double aResult;
723   if (_isLocal) {
724     SALOMEDS::Locker lock;
725     aResult = _local_impl->GetVariableValue(theVarName);
726   }
727   else 
728     aResult = _corba_impl->GetReal((char*)theVarName.c_str());
729   return aResult;
730 }
731
732 int SALOMEDS_Study::GetInteger(const string& theVarName)
733 {
734   int aResult;  
735   if (_isLocal) {
736     SALOMEDS::Locker lock;
737     aResult = (int) _local_impl->GetVariableValue(theVarName);
738   }
739   else 
740     aResult = _corba_impl->GetInteger((char*)theVarName.c_str());
741   return aResult;
742 }
743
744 bool SALOMEDS_Study::GetBoolean(const string& theVarName)
745 {
746   bool aResult;
747   if (_isLocal) {
748     SALOMEDS::Locker lock;
749     aResult = (bool) _local_impl->GetVariableValue(theVarName);
750   }
751   else 
752     aResult = _corba_impl->GetBoolean((char*)theVarName.c_str());
753   return aResult;
754 }
755
756 bool SALOMEDS_Study::IsReal(const string& theVarName)
757 {
758   bool aResult;
759   if (_isLocal) {
760     SALOMEDS::Locker lock;
761     aResult = _local_impl->IsTypeOf(theVarName, 
762                                    SALOMEDSImpl_GenericVariable::REAL_VAR);
763   }
764   else
765     aResult = _corba_impl->IsReal((char*)theVarName.c_str());
766   return aResult;
767 }
768
769 bool SALOMEDS_Study::IsInteger(const string& theVarName)
770 {
771   bool aResult;
772   if (_isLocal) {
773     SALOMEDS::Locker lock;
774     aResult = _local_impl->IsTypeOf(theVarName, 
775                                    SALOMEDSImpl_GenericVariable::INTEGER_VAR);
776   }
777   else
778     aResult = _corba_impl->IsInteger((char*)theVarName.c_str());
779   return aResult;
780 }
781
782 bool SALOMEDS_Study::IsBoolean(const string& theVarName)
783 {
784   bool aResult;
785   if (_isLocal) {
786     SALOMEDS::Locker lock;
787     aResult = _local_impl->IsTypeOf(theVarName, 
788                                    SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
789   }
790   else
791     aResult = _corba_impl->IsBoolean((char*)theVarName.c_str());
792   return aResult;
793 }
794
795 bool SALOMEDS_Study::IsVariable(const string& theVarName)
796 {
797   bool aResult;
798   if (_isLocal) {
799     SALOMEDS::Locker lock;
800     aResult = _local_impl->IsVariable(theVarName);
801   }
802   else
803     aResult = _corba_impl->IsVariable((char*)theVarName.c_str());
804   return aResult;
805 }
806
807 vector<string> SALOMEDS_Study::GetVariableNames()
808 {
809   vector<string> aVector;
810   if (_isLocal) {
811     SALOMEDS::Locker lock;
812     aVector = _local_impl->GetVariableNames();
813   }
814   else {
815     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
816     int aLength = aSeq->length();
817     for (int i = 0; i < aLength; i++) 
818       aVector.push_back( string(aSeq[i].in()) );
819   }
820   return aVector;
821 }
822
823 bool SALOMEDS_Study::RemoveVariable(const string& theVarName)
824 {
825   bool aResult;
826   if (_isLocal) {
827     SALOMEDS::Locker lock;
828     aResult = _local_impl->RemoveVariable(theVarName);
829   }
830   else
831     aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str());
832   return aResult;
833 }
834
835 bool SALOMEDS_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
836 {
837   bool aResult;
838   if (_isLocal) {
839     SALOMEDS::Locker lock;
840     aResult = _local_impl->RenameVariable(theVarName, theNewVarName);
841   }
842   else
843     aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str());
844   return aResult;
845 }
846
847 bool SALOMEDS_Study::IsVariableUsed(const string& theVarName)
848 {
849   bool aResult;
850   if (_isLocal) {
851     SALOMEDS::Locker lock;
852     aResult = _local_impl->IsVariableUsed(theVarName);
853   }
854   else
855     aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str());
856   return aResult;
857 }
858
859 vector< vector<string> > SALOMEDS_Study::ParseVariables(const string& theVars)
860 {
861   vector< vector<string> > aResult;
862   if (_isLocal) {
863     SALOMEDS::Locker lock;
864     aResult = _local_impl->ParseVariables(theVars);
865   }
866   else {
867     SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
868     for (int i = 0, n = aSeq->length(); i < n; i++) {
869       vector<string> aVector;
870       SALOMEDS::ListOfStrings aSection = aSeq[i];
871       for (int j = 0, m = aSection.length(); j < m; j++) {
872         aVector.push_back( string(aSection[j].in()) );
873       }
874       aResult.push_back( aVector );
875     }
876   }
877   return aResult;
878 }
879
880 std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
881 {
882   return _orb->object_to_string(theObject); 
883 }
884
885 CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) 
886
887   return _orb->string_to_object(theIOR.c_str()); 
888
889
890 void SALOMEDS_Study::init_orb()
891 {
892   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
893   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); 
894   _orb = init(0 , 0 ) ;     
895 }
896
897 SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
898 {
899   if (_isLocal) {
900     SALOMEDS::Locker lock;
901
902     if (!CORBA::is_nil(_corba_impl)) return SALOMEDS::Study::_duplicate(_corba_impl);
903     std::string anIOR = _local_impl->GetTransientReference();
904     SALOMEDS::Study_var aStudy;
905     if (!_local_impl->IsError() && anIOR != "") {
906       aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str()));
907     }
908     else {
909       SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb);
910       aStudy = aStudy_servant->_this();
911       _local_impl->SetTransientReference(_orb->object_to_string(aStudy));
912     }
913     _corba_impl = SALOMEDS::Study::_duplicate(aStudy);
914     return aStudy._retn();
915   }
916   else {
917     return SALOMEDS::Study::_duplicate(_corba_impl);
918   }
919
920   return SALOMEDS::Study::_nil();
921 }
922
923
924 _PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const string& theID, int theSavePoint)
925 {
926   SALOMEDSClient_AttributeParameter* AP = NULL;
927   if(theSavePoint >= 0) {
928     if (_isLocal) {
929       SALOMEDS::Locker lock;
930       AP = new SALOMEDS_AttributeParameter(_local_impl->GetCommonParameters(theID.c_str(), theSavePoint));
931     }
932     else {
933       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetCommonParameters(theID.c_str(), theSavePoint));
934     }
935   }
936   return _PTR(AttributeParameter)(AP);
937 }
938
939 _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const string& theID, 
940                                                              const string& theModuleName, int theSavePoint)
941 {
942   SALOMEDSClient_AttributeParameter* AP = NULL;
943   if(theSavePoint > 0) {
944     if (_isLocal) {
945       SALOMEDS::Locker lock;
946       AP = new SALOMEDS_AttributeParameter(_local_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
947     }
948     else {
949       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
950     }
951   }
952   return _PTR(AttributeParameter)(AP);
953 }