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