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