Salome HOME
d8a537c9584fcfeb161d8326defd4a826c8174af
[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   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 = Kernel_Utils::encode_s(_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(Kernel_Utils::decode_s(theName));
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 {
507           wchar_t* wurl = _corba_impl->URL();
508
509           // Converts unicode url to encoded version
510           setlocale(LC_ALL, "");
511           size_t urlLen = std::wcslen(wurl);
512           char url[urlLen+1];
513           memset( url, 0, urlLen+1);
514           wcstombs(url, wurl, sizeof(url));
515
516           aURL = std::string(url);
517   }
518   return aURL;
519 }
520
521 void SALOMEDS_Study::URL(const std::string& url)
522 {
523   if (_isLocal) {
524     SALOMEDS::Locker lock;
525     _local_impl->URL(url);
526   }
527   else {
528           setlocale(LC_ALL, "");
529           size_t urlLen = url.size();
530           wchar_t wurl[urlLen+1];
531           memset( wurl, 0, urlLen+1);
532           mbstowcs(wurl, url.c_str(), sizeof(wurl));
533
534           _corba_impl->URL(wurl);
535   }
536 }
537
538 int SALOMEDS_Study::StudyId()
539 {
540   int anID;
541   if (_isLocal) {
542     SALOMEDS::Locker lock;
543     anID = _local_impl->StudyId();
544   }
545   else anID = _corba_impl->StudyId();
546   return anID;
547 }
548  
549 void SALOMEDS_Study::StudyId(int id) 
550 {
551   if (_isLocal) {
552     SALOMEDS::Locker lock;
553     _local_impl->StudyId(id);
554   }
555   else _corba_impl->StudyId(id);  
556 }
557
558 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
559 {
560   std::vector<_PTR(SObject)> aVector;
561   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
562   int aLength, i;
563   if (_isLocal) {
564     SALOMEDS::Locker lock;
565
566     std::vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindDependances(*(aSO->GetLocalImpl()));
567     if (aSeq.size()) {
568       aLength = aSeq.size();
569       for (i = 0; i < aLength; i++) 
570         aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
571     }
572   }
573   else {
574     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindDependances(aSO->GetCORBAImpl());
575     aLength = aSeq->length();
576     for (i = 0; i < aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
577   }
578   return aVector;
579 }
580  
581 _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties()
582 {
583   SALOMEDSClient_AttributeStudyProperties* aProp;
584   if (_isLocal) {
585     SALOMEDS::Locker lock;
586     aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties());
587   }
588   else aProp = new SALOMEDS_AttributeStudyProperties((SALOMEDS::AttributeStudyProperties_var)_corba_impl->GetProperties());
589   return _PTR(AttributeStudyProperties)(aProp);
590 }
591  
592 std::string SALOMEDS_Study::GetLastModificationDate() 
593 {
594   std::string aDate;
595   if (_isLocal) {
596     SALOMEDS::Locker lock;
597     aDate = _local_impl->GetLastModificationDate();
598   }
599   else aDate = _corba_impl->GetLastModificationDate();
600   return aDate;
601 }
602
603 std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
604 {
605   std::vector<std::string> aVector;
606   int aLength, i;
607   if (_isLocal) {
608     SALOMEDS::Locker lock;
609     aVector = _local_impl->GetModificationsDate();
610   }
611   else {
612     SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
613     aLength = aSeq->length();
614     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
615   }
616   return aVector;
617 }
618
619 _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
620 {
621   SALOMEDSClient_UseCaseBuilder* aUB = NULL;
622   if (_isLocal) {
623     SALOMEDS::Locker lock;
624
625     SALOMEDSImpl_UseCaseBuilder* aUBimpl = _local_impl->GetUseCaseBuilder();
626     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
627   }
628   else {
629     SALOMEDS::UseCaseBuilder_var aUBimpl = _corba_impl->GetUseCaseBuilder();
630     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
631   }
632
633   return _PTR(UseCaseBuilder)(aUB);
634 }
635
636 void SALOMEDS_Study::Close()
637 {
638   if (_isLocal) {
639     SALOMEDS::Locker lock;
640     _local_impl->Close();
641   }
642   else _corba_impl->Close();
643 }
644
645 void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
646 {
647   if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
648   else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
649 }
650
651 bool SALOMEDS_Study::DumpStudy(const std::string& thePath,
652                                const std::string& theBaseName,
653                                bool isPublished,
654                                bool isMultiFile)
655 {
656   //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one
657   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
658   bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished, isMultiFile);
659   return ret;
660 }     
661
662 void SALOMEDS_Study::SetStudyLock(const std::string& theLockerID)
663 {
664   if (_isLocal) {
665     SALOMEDS::Locker lock;
666     _local_impl->SetStudyLock(theLockerID.c_str());
667   }
668   else _corba_impl->SetStudyLock((char*)theLockerID.c_str());
669 }
670  
671 bool SALOMEDS_Study::IsStudyLocked()
672 {
673   bool isLocked;
674   if (_isLocal) {
675     SALOMEDS::Locker lock;
676     isLocked = _local_impl->IsStudyLocked();
677   }
678   else isLocked = _corba_impl->IsStudyLocked();
679   return isLocked;
680 }
681  
682 void SALOMEDS_Study::UnLockStudy(const std::string& theLockerID)
683 {
684   if(_isLocal) _local_impl->UnLockStudy(theLockerID.c_str());
685   else _corba_impl->UnLockStudy((char*)theLockerID.c_str());
686 }
687
688 std::vector<std::string> SALOMEDS_Study::GetLockerID()
689 {
690   std::vector<std::string> aVector;
691   int aLength, i;
692   if (_isLocal) {
693     SALOMEDS::Locker lock;
694     aVector = _local_impl->GetLockerID();
695   }
696   else {
697     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
698     aLength = aSeq->length();
699     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
700   }
701   return aVector;
702 }
703
704
705 void SALOMEDS_Study::SetReal(const std::string& theVarName, const double theValue)
706 {
707   if (_isLocal) {
708     SALOMEDS::Locker lock;
709     _local_impl->SetVariable(theVarName,
710                              theValue,
711                              SALOMEDSImpl_GenericVariable::REAL_VAR);
712   }
713   else 
714     _corba_impl->SetReal((char*)theVarName.c_str(),theValue);
715 }
716
717 void SALOMEDS_Study::SetInteger(const std::string& theVarName, const int theValue)
718 {
719   if (_isLocal) {
720     SALOMEDS::Locker lock;
721     _local_impl->SetVariable(theVarName,
722                              theValue,
723                              SALOMEDSImpl_GenericVariable::INTEGER_VAR);
724   }
725   else 
726     _corba_impl->SetInteger((char*)theVarName.c_str(),theValue);
727 }
728
729 void SALOMEDS_Study::SetBoolean(const std::string& theVarName, const bool theValue)
730 {
731   if (_isLocal) {
732     SALOMEDS::Locker lock;
733     _local_impl->SetVariable(theVarName,
734                              theValue,
735                              SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
736   }
737   else 
738     _corba_impl->SetBoolean((char*)theVarName.c_str(),theValue);
739 }
740
741 void SALOMEDS_Study::SetString(const std::string& theVarName, const std::string& theValue)
742 {
743   if (_isLocal) {
744     SALOMEDS::Locker lock;
745     _local_impl->SetStringVariable(theVarName,
746                                    theValue,
747                                    SALOMEDSImpl_GenericVariable::STRING_VAR);
748   }
749   else 
750     _corba_impl->SetString((char*)theVarName.c_str(),(char*)theValue.c_str());
751 }
752
753 void SALOMEDS_Study::SetStringAsDouble(const std::string& theVarName, const double theValue)
754 {
755   if (_isLocal) {
756     SALOMEDS::Locker lock;
757     _local_impl->SetStringVariableAsDouble(theVarName,
758                                            theValue,
759                                            SALOMEDSImpl_GenericVariable::STRING_VAR);
760   }
761   else 
762     _corba_impl->SetStringAsDouble((char*)theVarName.c_str(),theValue);
763 }
764
765 double SALOMEDS_Study::GetReal(const std::string& theVarName)
766 {
767   double aResult;
768   if (_isLocal) {
769     SALOMEDS::Locker lock;
770     aResult = _local_impl->GetVariableValue(theVarName);
771   }
772   else 
773     aResult = _corba_impl->GetReal((char*)theVarName.c_str());
774   return aResult;
775 }
776
777 int SALOMEDS_Study::GetInteger(const std::string& theVarName)
778 {
779   int aResult;  
780   if (_isLocal) {
781     SALOMEDS::Locker lock;
782     aResult = (int) _local_impl->GetVariableValue(theVarName);
783   }
784   else 
785     aResult = _corba_impl->GetInteger((char*)theVarName.c_str());
786   return aResult;
787 }
788
789 bool SALOMEDS_Study::GetBoolean(const std::string& theVarName)
790 {
791   bool aResult;
792   if (_isLocal) {
793     SALOMEDS::Locker lock;
794     aResult = (bool) _local_impl->GetVariableValue(theVarName);
795   }
796   else 
797     aResult = _corba_impl->GetBoolean((char*)theVarName.c_str());
798   return aResult;
799 }
800
801 std::string SALOMEDS_Study::GetString(const std::string& theVarName)
802 {
803   std::string aResult;
804   if (_isLocal) {
805     SALOMEDS::Locker lock;
806     aResult = _local_impl->GetStringVariableValue(theVarName);
807   }
808   else 
809     aResult = _corba_impl->GetString((char*)theVarName.c_str());
810   return aResult;
811 }
812
813 bool SALOMEDS_Study::IsReal(const std::string& theVarName)
814 {
815   bool aResult;
816   if (_isLocal) {
817     SALOMEDS::Locker lock;
818     aResult = _local_impl->IsTypeOf(theVarName, 
819                                    SALOMEDSImpl_GenericVariable::REAL_VAR);
820   }
821   else
822     aResult = _corba_impl->IsReal((char*)theVarName.c_str());
823   return aResult;
824 }
825
826 bool SALOMEDS_Study::IsInteger(const std::string& theVarName)
827 {
828   bool aResult;
829   if (_isLocal) {
830     SALOMEDS::Locker lock;
831     aResult = _local_impl->IsTypeOf(theVarName, 
832                                    SALOMEDSImpl_GenericVariable::INTEGER_VAR);
833   }
834   else
835     aResult = _corba_impl->IsInteger((char*)theVarName.c_str());
836   return aResult;
837 }
838
839 bool SALOMEDS_Study::IsBoolean(const std::string& theVarName)
840 {
841   bool aResult;
842   if (_isLocal) {
843     SALOMEDS::Locker lock;
844     aResult = _local_impl->IsTypeOf(theVarName, 
845                                    SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
846   }
847   else
848     aResult = _corba_impl->IsBoolean((char*)theVarName.c_str());
849   return aResult;
850 }
851
852 bool SALOMEDS_Study::IsString(const std::string& theVarName)
853 {
854   bool aResult;
855   if (_isLocal) {
856     SALOMEDS::Locker lock;
857     aResult = _local_impl->IsTypeOf(theVarName, 
858                                     SALOMEDSImpl_GenericVariable::STRING_VAR);
859   }
860   else
861     aResult = _corba_impl->IsString((char*)theVarName.c_str());
862   return aResult;
863 }
864
865 bool SALOMEDS_Study::IsVariable(const std::string& theVarName)
866 {
867   bool aResult;
868   if (_isLocal) {
869     SALOMEDS::Locker lock;
870     aResult = _local_impl->IsVariable(theVarName);
871   }
872   else
873     aResult = _corba_impl->IsVariable((char*)theVarName.c_str());
874   return aResult;
875 }
876
877 std::vector<std::string> SALOMEDS_Study::GetVariableNames()
878 {
879   std::vector<std::string> aVector;
880   if (_isLocal) {
881     SALOMEDS::Locker lock;
882     aVector = _local_impl->GetVariableNames();
883   }
884   else {
885     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
886     int aLength = aSeq->length();
887     for (int i = 0; i < aLength; i++) 
888       aVector.push_back( std::string(aSeq[i].in()) );
889   }
890   return aVector;
891 }
892
893 bool SALOMEDS_Study::RemoveVariable(const std::string& theVarName)
894 {
895   bool aResult;
896   if (_isLocal) {
897     SALOMEDS::Locker lock;
898     aResult = _local_impl->RemoveVariable(theVarName);
899   }
900   else
901     aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str());
902   return aResult;
903 }
904
905 bool SALOMEDS_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
906 {
907   bool aResult;
908   if (_isLocal) {
909     SALOMEDS::Locker lock;
910     aResult = _local_impl->RenameVariable(theVarName, theNewVarName);
911   }
912   else
913     aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str());
914   return aResult;
915 }
916
917 bool SALOMEDS_Study::IsVariableUsed(const std::string& theVarName)
918 {
919   bool aResult;
920   if (_isLocal) {
921     SALOMEDS::Locker lock;
922     aResult = _local_impl->IsVariableUsed(theVarName);
923   }
924   else
925     aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str());
926   return aResult;
927 }
928
929 std::vector< std::vector<std::string> > SALOMEDS_Study::ParseVariables(const std::string& theVars)
930 {
931   std::vector< std::vector<std::string> > aResult;
932   if (_isLocal) {
933     SALOMEDS::Locker lock;
934     aResult = _local_impl->ParseVariables(theVars);
935   }
936   else {
937     SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
938     for (int i = 0, n = aSeq->length(); i < n; i++) {
939       std::vector<std::string> aVector;
940       SALOMEDS::ListOfStrings aSection = aSeq[i];
941       for (int j = 0, m = aSection.length(); j < m; j++) {
942         aVector.push_back( std::string(aSection[j].in()) );
943       }
944       aResult.push_back( aVector );
945     }
946   }
947   return aResult;
948 }
949
950 std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
951 {
952   return _orb->object_to_string(theObject); 
953 }
954
955 CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) 
956
957   return _orb->string_to_object(theIOR.c_str()); 
958
959
960 void SALOMEDS_Study::init_orb()
961 {
962   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
963   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); 
964   _orb = init(0 , 0 ) ;     
965 }
966
967 SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
968 {
969   if (_isLocal) {
970     SALOMEDS::Locker lock;
971
972     if (!CORBA::is_nil(_corba_impl)) return SALOMEDS::Study::_duplicate(_corba_impl);
973     std::string anIOR = _local_impl->GetTransientReference();
974     SALOMEDS::Study_var aStudy;
975     if (!_local_impl->IsError() && anIOR != "") {
976       aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str()));
977     }
978     else {
979       SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb);
980       aStudy = aStudy_servant->_this();
981       _local_impl->SetTransientReference(_orb->object_to_string(aStudy));
982     }
983     _corba_impl = SALOMEDS::Study::_duplicate(aStudy);
984     return aStudy._retn();
985   }
986   else {
987     return SALOMEDS::Study::_duplicate(_corba_impl);
988   }
989
990   return SALOMEDS::Study::_nil();
991 }
992
993
994 _PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const std::string& theID, int theSavePoint)
995 {
996   SALOMEDSClient_AttributeParameter* AP = NULL;
997   if(theSavePoint >= 0) {
998     if (_isLocal) {
999       SALOMEDS::Locker lock;
1000       AP = new SALOMEDS_AttributeParameter(_local_impl->GetCommonParameters(theID.c_str(), theSavePoint));
1001     }
1002     else {
1003       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetCommonParameters(theID.c_str(), theSavePoint));
1004     }
1005   }
1006   return _PTR(AttributeParameter)(AP);
1007 }
1008
1009 _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const std::string& theID, 
1010                                                              const std::string& theModuleName, int theSavePoint)
1011 {
1012   SALOMEDSClient_AttributeParameter* AP = NULL;
1013   if(theSavePoint > 0) {
1014     if (_isLocal) {
1015       SALOMEDS::Locker lock;
1016       AP = new SALOMEDS_AttributeParameter(_local_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
1017     }
1018     else {
1019       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
1020     }
1021   }
1022   return _PTR(AttributeParameter)(AP);
1023 }
1024
1025 void SALOMEDS_Study::attach(SALOMEDS::Observer_ptr theObserver,bool modify)
1026 {
1027   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
1028   _corba_impl->attach(theObserver,modify);
1029 }
1030
1031 void SALOMEDS_Study::detach(SALOMEDS::Observer_ptr theObserver)
1032 {
1033   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
1034   _corba_impl->detach(theObserver);
1035 }