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