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