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