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