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