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