Salome HOME
Merging with WPDev
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_Study.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25
26 #include "utilities.h" 
27
28 #include "SALOMEDS_Study.hxx"
29
30 #include "SALOMEDS.hxx"
31 #include "SALOMEDS_SComponent.hxx"
32 #include "SALOMEDS_SObject.hxx"
33 #include "SALOMEDS_StudyBuilder.hxx"
34 #include "SALOMEDS_ChildIterator.hxx"
35 #include "SALOMEDS_SComponentIterator.hxx"
36 #include "SALOMEDS_AttributeStudyProperties.hxx"
37 #include "SALOMEDS_AttributeParameter.hxx"
38 #include "SALOMEDS_UseCaseBuilder.hxx"
39
40 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "SALOMEDSImpl_SObject.hxx"
42 #include "SALOMEDSImpl_StudyBuilder.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_SComponentIterator.hxx"
45 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
46 #include "SALOMEDSImpl_AttributeParameter.hxx"
47 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
48
49 #include "SALOMEDS_Driver_i.hxx"
50 #include "SALOMEDS_Study_i.hxx"
51
52 #include <TCollection_AsciiString.hxx> 
53 #include <TColStd_HSequenceOfAsciiString.hxx>
54 #include <TColStd_HSequenceOfTransient.hxx>
55
56 #include "Utils_ORB_INIT.hxx" 
57 #include "Utils_SINGLETON.hxx" 
58
59 #ifdef WIN32
60 #include <process.h>
61 #else
62 #include <sys/types.h>
63 #include <unistd.h>
64 #endif
65
66 #include "OpUtil.hxx"
67
68 using namespace std; 
69
70 SALOMEDS_Study::SALOMEDS_Study(const Handle(SALOMEDSImpl_Study)& theStudy)
71 {
72   _isLocal = true;
73   _local_impl = theStudy;
74   _corba_impl = SALOMEDS::Study::_nil();
75   init_orb();
76 }
77
78 SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
79 {
80 #ifdef WIN32
81   long pid =  (long)_getpid();
82 #else
83   long pid =  (long)getpid();
84 #endif  
85
86   CORBA::LongLong addr =  // mpv: fix for IPAL13534: for 64 bit platform use 8-bytes long for pointer storage
87     theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
88
89   if(_isLocal) {
90     _local_impl = ((SALOMEDSImpl_Study*)(addr));
91     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
92   }
93   else {
94     _local_impl = NULL;
95     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
96   }
97
98   init_orb();
99 }
100
101 SALOMEDS_Study::~SALOMEDS_Study()
102 {
103 }
104
105 std::string SALOMEDS_Study::GetPersistentReference()
106 {
107   std::string aRef;
108   if (_isLocal) {
109     SALOMEDS::Locker lock;
110     aRef = _local_impl->GetPersistentReference().ToCString();
111   }
112   else aRef = _corba_impl->GetPersistentReference();
113   return aRef;
114 }
115
116 std::string SALOMEDS_Study::GetTransientReference()
117 {
118   std::string aRef;
119   if (_isLocal) {
120     SALOMEDS::Locker lock;
121     aRef = _local_impl->GetTransientReference().ToCString();
122   }
123   else aRef = _corba_impl->GetTransientReference();
124   return aRef;
125 }
126  
127 bool SALOMEDS_Study::IsEmpty()
128 {
129   bool ret;
130   if (_isLocal) {
131     SALOMEDS::Locker lock;
132     ret = _local_impl->IsEmpty();
133   }
134   else ret = _corba_impl->IsEmpty();
135   return ret;
136 }
137
138 _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentName)
139 {
140   SALOMEDSClient_SComponent* aSCO = NULL;
141   if (_isLocal) {
142     SALOMEDS::Locker lock;
143
144     Handle(SALOMEDSImpl_SComponent) aSCO_impl =
145       _local_impl->FindComponent((char*)aComponentName.c_str());
146     if (aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
147     aSCO = new SALOMEDS_SComponent(aSCO_impl);
148   }
149   else {
150     SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponent((char*)aComponentName.c_str());
151     if (CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
152     aSCO = new SALOMEDS_SComponent(aSCO_impl);
153   }
154   return _PTR(SComponent)(aSCO);
155 }
156  
157 _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID)
158 {  
159   SALOMEDSClient_SComponent* aSCO = NULL;
160   if (_isLocal) {
161     SALOMEDS::Locker lock;
162
163     Handle(SALOMEDSImpl_SComponent) aSCO_impl =
164       _local_impl->FindComponentID((char*)aComponentID.c_str());
165     if (aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
166     aSCO = new SALOMEDS_SComponent(aSCO_impl);
167   }
168   else {
169     SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponentID((char*)aComponentID.c_str());
170     if(CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
171     aSCO = new SALOMEDS_SComponent(aSCO_impl);
172   }
173   return _PTR(SComponent)(aSCO);
174 }
175  
176 _PTR(SObject) SALOMEDS_Study::FindObject(const std::string& anObjectName)
177 {
178   SALOMEDSClient_SObject* aSO = NULL;
179
180   if (_isLocal) {
181     SALOMEDS::Locker lock;
182
183     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObject((char*)anObjectName.c_str());
184     if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
185     Handle(SALOMEDSImpl_SComponent) aSCO_impl = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO_impl);
186     if (!aSCO_impl.IsNull()) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
187     aSO = new SALOMEDS_SObject(aSO_impl);
188   }
189   else { 
190     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str());
191     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
192     SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl);
193     if (!CORBA::is_nil(aSCO_impl)) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
194     aSO = new SALOMEDS_SObject(aSO_impl);
195   }
196
197   return _PTR(SObject)(aSO);
198 }
199
200 std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& anObjectName, 
201                                                             const std::string& aComponentName)   
202 {
203   std::vector<_PTR(SObject)> aVector;
204   int i, aLength = 0;
205
206   if (_isLocal) {
207     SALOMEDS::Locker lock;
208
209     Handle(TColStd_HSequenceOfTransient) aSeq =
210       _local_impl->FindObjectByName((char*)anObjectName.c_str(), (char*)aComponentName.c_str());
211     aLength = aSeq->Length();
212     for (i = 1; i<= aLength; i++) 
213       aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject
214                                       (Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
215   }
216   else {
217     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindObjectByName((char*)anObjectName.c_str(), 
218                                                                             (char*)aComponentName.c_str());
219     aLength = aSeq->length();
220     for (i = 0; i< aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
221   }
222
223   return aVector;
224 }
225
226 _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID)
227 {
228   SALOMEDSClient_SObject* aSO = NULL;
229   if (_isLocal) {
230     SALOMEDS::Locker lock;
231
232     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str());
233     if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
234     return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
235   }
236   else { 
237     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectID((char*)anObjectID.c_str());
238     if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
239     return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
240   }
241   return _PTR(SObject)(aSO);
242 }
243  
244 _PTR(SObject) SALOMEDS_Study::CreateObjectID(const std::string& anObjectID)
245 {
246   SALOMEDSClient_SObject* aSO = NULL;
247   if (_isLocal) {
248     SALOMEDS::Locker lock;
249     aSO = new SALOMEDS_SObject(_local_impl->CreateObjectID((char*)anObjectID.c_str()));
250   }
251   else aSO = new SALOMEDS_SObject(_corba_impl->CreateObjectID((char*)anObjectID.c_str())); 
252   return _PTR(SObject)(aSO);
253 }
254
255 _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR)
256 {
257   SALOMEDSClient_SObject* aSO = NULL;
258   if (_isLocal) {
259     SALOMEDS::Locker lock;
260
261     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectIOR((char*)anObjectIOR.c_str());
262     if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
263     aSO = new SALOMEDS_SObject(aSO_impl);
264   }
265   else { 
266     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectIOR((char*)anObjectIOR.c_str());
267     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
268     aSO = new SALOMEDS_SObject(aSO_impl);
269   }
270   return _PTR(SObject)(aSO);
271 }
272
273 _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath)
274 {
275   SALOMEDSClient_SObject* aSO = NULL;
276   if (_isLocal) {
277     SALOMEDS::Locker lock;
278
279     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectByPath((char*)thePath.c_str());
280     if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
281     aSO = new SALOMEDS_SObject(aSO_impl);
282   }
283   else {
284     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectByPath((char*)thePath.c_str());
285     if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
286     aSO = new SALOMEDS_SObject(aSO_impl);
287   }
288   return _PTR(SObject)(aSO);
289 }
290
291 std::string SALOMEDS_Study::GetObjectPath(const _PTR(SObject)& theSO)
292 {
293   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
294   std::string aPath;
295   if (_isLocal) {
296     SALOMEDS::Locker lock;
297     aPath = _local_impl->GetObjectPath(aSO->GetLocalImpl()).ToCString();
298   }
299   else aPath = _corba_impl->GetObjectPath(aSO->GetCORBAImpl());
300   return aPath;
301 }
302
303 void SALOMEDS_Study::SetContext(const std::string& thePath)
304 {
305   if (_isLocal) {
306     SALOMEDS::Locker lock;
307     _local_impl->SetContext((char*)thePath.c_str());
308   }
309   else _corba_impl->SetContext((char*)thePath.c_str());
310 }
311
312 std::string SALOMEDS_Study::GetContext()  
313 {
314   std::string aPath;
315   if (_isLocal) {
316     SALOMEDS::Locker lock;
317     aPath = _local_impl->GetContext().ToCString();
318   }
319   else aPath = _corba_impl->GetContext();
320   return aPath;
321 }
322
323 std::vector<std::string> SALOMEDS_Study::GetObjectNames(const std::string& theContext)
324 {
325   std::vector<std::string> aVector;
326   int aLength, i;
327   if (_isLocal) {
328     SALOMEDS::Locker lock;
329
330     Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetObjectNames((char*)theContext.c_str());
331     aLength = aSeq->Length();
332     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
333   }
334   else {
335     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
336     aLength = aSeq->length();
337     for (i = 0; i < aLength; i++) aVector.push_back(std::string((std::string)aSeq[i].in()));
338   }
339   return aVector;
340 }
341  
342 std::vector<std::string> SALOMEDS_Study::GetDirectoryNames(const std::string& theContext)
343 {
344   std::vector<std::string> aVector;
345   int aLength, i;
346   if (_isLocal) {
347     SALOMEDS::Locker lock;
348
349     Handle(TColStd_HSequenceOfAsciiString) aSeq =
350       _local_impl->GetDirectoryNames((char*)theContext.c_str());
351     aLength = aSeq->Length();
352     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
353   }
354   else {
355     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
356     aLength = aSeq->length();
357     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
358   }
359   return aVector;
360 }
361  
362 std::vector<std::string> SALOMEDS_Study::GetFileNames(const std::string& theContext)
363 {
364   std::vector<std::string> aVector;
365   int aLength, i;
366   if (_isLocal) {
367     SALOMEDS::Locker lock;
368
369     Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetFileNames((char*)theContext.c_str());
370     aLength = aSeq->Length();
371     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
372   }
373   else {
374     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
375     aLength = aSeq->length();
376
377     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
378   }
379   return aVector;
380 }
381  
382 std::vector<std::string> SALOMEDS_Study::GetComponentNames(const std::string& theContext)
383 {
384   std::vector<std::string> aVector;
385   int aLength, i;
386   if (_isLocal) {
387     SALOMEDS::Locker lock;
388
389     Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetComponentNames((char*)theContext.c_str());
390     aLength = aSeq->Length();
391     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
392   }
393   else {
394     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
395     aLength = aSeq->length();
396     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
397   }
398   return aVector;
399 }
400
401 _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO)
402 {
403   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
404   SALOMEDSClient_ChildIterator* aCI = NULL; 
405   if (_isLocal) {
406     SALOMEDS::Locker lock;
407
408     Handle(SALOMEDSImpl_ChildIterator) aCIimpl = _local_impl->NewChildIterator(aSO->GetLocalImpl());
409     aCI = new SALOMEDS_ChildIterator(aCIimpl);
410   }
411   else {
412     SALOMEDS::ChildIterator_var aCIimpl = _corba_impl->NewChildIterator(aSO->GetCORBAImpl());
413     aCI = new SALOMEDS_ChildIterator(aCIimpl);
414   }
415
416   return _PTR(ChildIterator)(aCI);
417 }
418
419 _PTR(SComponentIterator) SALOMEDS_Study::NewComponentIterator()
420 {
421   SALOMEDSClient_SComponentIterator* aCI = NULL; 
422   if (_isLocal) {
423     SALOMEDS::Locker lock;
424
425     SALOMEDSImpl_SComponentIterator aCIimpl = _local_impl->NewComponentIterator();
426     aCI = new SALOMEDS_SComponentIterator(aCIimpl);
427   }
428   else {
429     SALOMEDS::SComponentIterator_var aCIimpl = _corba_impl->NewComponentIterator();
430     aCI = new SALOMEDS_SComponentIterator(aCIimpl);
431   }
432
433   return _PTR(SComponentIterator)(aCI);
434 }
435
436 _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder()
437 {
438   SALOMEDSClient_StudyBuilder* aSB = NULL; 
439   if (_isLocal) {
440     SALOMEDS::Locker lock;
441
442     Handle(SALOMEDSImpl_StudyBuilder) aSBimpl = _local_impl->NewBuilder();
443     aSB = new SALOMEDS_StudyBuilder(aSBimpl);
444   }
445   else {
446     SALOMEDS::StudyBuilder_var aSBimpl = _corba_impl->NewBuilder();
447     aSB = new SALOMEDS_StudyBuilder(aSBimpl);
448   }
449
450   return _PTR(StudyBuilder)(aSB);
451 }
452
453 std::string SALOMEDS_Study::Name()
454 {
455   std::string aName;
456   if (_isLocal) {
457     SALOMEDS::Locker lock;
458     aName = _local_impl->Name().ToCString();
459   }
460   else aName = _corba_impl->Name();
461   return aName;
462 }
463
464 void SALOMEDS_Study::Name(const std::string& theName)
465 {
466   if (_isLocal) {
467     SALOMEDS::Locker lock;
468     _local_impl->Name((char*)theName.c_str());
469   }
470   else _corba_impl->Name((char*)theName.c_str());
471 }
472
473 bool SALOMEDS_Study::IsSaved()
474 {
475   bool isSaved;
476   if (_isLocal) {
477     SALOMEDS::Locker lock;
478     isSaved = _local_impl->IsSaved();
479   }
480   else isSaved = _corba_impl->IsSaved();
481   return isSaved;
482 }
483
484 void SALOMEDS_Study::IsSaved(bool save)
485 {
486   if (_isLocal) {
487     SALOMEDS::Locker lock;
488     _local_impl->IsSaved(save);
489   }
490   else _corba_impl->IsSaved(save);
491 }
492
493 bool SALOMEDS_Study::IsModified()
494 {
495   bool isModified;
496   if (_isLocal) {
497     SALOMEDS::Locker lock;
498     isModified = _local_impl->IsModified();
499   }
500   else isModified = _corba_impl->IsModified();
501   return isModified;
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().ToCString();
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((char*)url.c_str());
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     Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->FindDependances(aSO->GetLocalImpl());
553     if (!aSeq.IsNull()) {
554       aLength = aSeq->Length();
555       for (i = 1; i <= aLength; i++) 
556         aVector.push_back(_PTR(SObject)(
557           new SALOMEDS_SObject(Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
558     }
559   }
560   else {
561     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindDependances(aSO->GetCORBAImpl());
562     aLength = aSeq->length();
563     for (i = 0; i < aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
564   }
565   return aVector;
566 }
567  
568 _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties()
569 {
570   SALOMEDSClient_AttributeStudyProperties* aProp;
571   if (_isLocal) {
572     SALOMEDS::Locker lock;
573     aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties());
574   }
575   else aProp = new SALOMEDS_AttributeStudyProperties(_corba_impl->GetProperties());
576   return _PTR(AttributeStudyProperties)(aProp);
577 }
578  
579 std::string SALOMEDS_Study::GetLastModificationDate() 
580 {
581   std::string aDate;
582   if (_isLocal) {
583     SALOMEDS::Locker lock;
584     aDate = _local_impl->GetLastModificationDate().ToCString();
585   }
586   else aDate = _corba_impl->GetLastModificationDate();
587   return aDate;
588 }
589
590 std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
591 {
592   std::vector<std::string> aVector;
593   int aLength, i;
594   if (_isLocal) {
595     SALOMEDS::Locker lock;
596
597     Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetModificationsDate();
598     aLength = aSeq->Length();
599     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
600   }
601   else {
602     SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
603     aLength = aSeq->length();
604     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
605   }
606   return aVector;
607 }
608
609 _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
610 {
611   SALOMEDSClient_UseCaseBuilder* aUB = NULL;
612   if (_isLocal) {
613     SALOMEDS::Locker lock;
614
615     Handle(SALOMEDSImpl_UseCaseBuilder) aUBimpl = _local_impl->GetUseCaseBuilder();
616     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
617   }
618   else {
619     SALOMEDS::UseCaseBuilder_var aUBimpl = _corba_impl->GetUseCaseBuilder();
620     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
621   }
622
623   return _PTR(UseCaseBuilder)(aUB);
624 }
625
626 void SALOMEDS_Study::Close()
627 {
628   if (_isLocal) {
629     SALOMEDS::Locker lock;
630     _local_impl->Close();
631   }
632   else _corba_impl->Close();
633 }
634
635 void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
636 {
637   if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
638   else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
639 }
640
641 bool SALOMEDS_Study::DumpStudy(const string& thePath, const string& theBaseName, bool isPublished)
642 {
643   //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one
644   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
645   bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished);
646   return ret;
647 }     
648
649 void SALOMEDS_Study::SetStudyLock(const string& theLockerID)
650 {
651   if (_isLocal) {
652     SALOMEDS::Locker lock;
653     _local_impl->SetStudyLock((char*)theLockerID.c_str());
654   }
655   else _corba_impl->SetStudyLock((char*)theLockerID.c_str());
656 }
657  
658 bool SALOMEDS_Study::IsStudyLocked()
659 {
660   bool isLocked;
661   if (_isLocal) {
662     SALOMEDS::Locker lock;
663     isLocked = _local_impl->IsStudyLocked();
664   }
665   else isLocked = _corba_impl->IsStudyLocked();
666   return isLocked;
667 }
668  
669 void SALOMEDS_Study::UnLockStudy(const string& theLockerID)
670 {
671   if(_isLocal) _local_impl->UnLockStudy((char*)theLockerID.c_str());
672   else _corba_impl->UnLockStudy((char*)theLockerID.c_str());
673 }
674
675 vector<string> SALOMEDS_Study::GetLockerID()
676 {
677   std::vector<std::string> aVector;
678   int aLength, i;
679   if (_isLocal) {
680     SALOMEDS::Locker lock;
681
682     Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetLockerID();
683     aLength = aSeq->Length();
684     for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
685   }
686   else {
687     SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
688     aLength = aSeq->length();
689     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
690   }
691   return aVector;
692 }
693
694 std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
695 {
696   CORBA::String_var objStr = _orb->object_to_string(theObject);
697   return string( objStr.in() );
698 }
699
700 CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) 
701
702   return _orb->string_to_object(theIOR.c_str()); 
703
704
705 void SALOMEDS_Study::init_orb()
706 {
707   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
708   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); 
709   _orb = init(0 , 0 ) ;     
710 }
711
712 SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
713 {
714   if (_isLocal) {
715     SALOMEDS::Locker lock;
716
717     if (!CORBA::is_nil(_corba_impl)) return SALOMEDS::Study::_duplicate(_corba_impl);
718     std::string anIOR = _local_impl->GetTransientReference().ToCString();
719     SALOMEDS::Study_var aStudy;
720     if (!_local_impl->IsError() && anIOR != "") {
721       aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str()));
722     }
723     else {
724       SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb);
725       aStudy = aStudy_servant->_this();
726       _local_impl->SetTransientReference(_orb->object_to_string(aStudy));
727     }
728     _corba_impl = SALOMEDS::Study::_duplicate(aStudy);
729     return aStudy._retn();
730   }
731   else {
732     return SALOMEDS::Study::_duplicate(_corba_impl);
733   }
734
735   return SALOMEDS::Study::_nil();
736 }
737
738
739 _PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const string& theID, int theSavePoint)
740 {
741   SALOMEDSClient_AttributeParameter* AP = NULL;
742   if(theSavePoint >= 0) {
743     if (_isLocal) {
744       SALOMEDS::Locker lock;
745       AP = new SALOMEDS_AttributeParameter(_local_impl->GetCommonParameters(theID.c_str(), theSavePoint));
746     }
747     else {
748       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetCommonParameters(theID.c_str(), theSavePoint));
749     }
750   }
751   return _PTR(AttributeParameter)(AP);
752 }
753
754 _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const string& theID, 
755                                                              const string& theModuleName, int theSavePoint)
756 {
757   SALOMEDSClient_AttributeParameter* AP = NULL;
758   if(theSavePoint > 0) {
759     if (_isLocal) {
760       SALOMEDS::Locker lock;
761       AP = new SALOMEDS_AttributeParameter(_local_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
762     }
763     else {
764       AP = new SALOMEDS_AttributeParameter(_corba_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint));
765     }
766   }
767   return _PTR(AttributeParameter)(AP);
768 }