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