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