]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_Study_i.cxx
Salome HOME
Fixed problem after execute python command "myStudy.Init()"
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.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_i.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "utilities.h"
28 #include <sstream>
29 #include "SALOMEDS_Study_i.hxx"
30 #include "SALOMEDS_UseCaseIterator_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
33 #include "SALOMEDS_AttributeParameter_i.hxx"
34 #include "SALOMEDS_ChildIterator_i.hxx"
35 #include "SALOMEDS_Driver_i.hxx"
36 #include "SALOMEDS.hxx"
37
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
41 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
42 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 #include "SALOMEDSImpl_ChildIterator.hxx"
44 #include "SALOMEDSImpl_IParameters.hxx"
45 #include "SALOMEDSImpl_Callback.hxx"
46
47 #include "DF_Label.hxx"
48 #include "DF_Attribute.hxx"
49
50 #include "Utils_ExceptHandlers.hxx"
51
52 #include "Basics_Utils.hxx"
53 #include "SALOME_KernelServices.hxx"
54
55 #ifdef WIN32
56 #include <process.h>
57 #else
58 #include <sys/types.h>
59 #include <unistd.h>
60 #endif
61
62 UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
63 UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
64
65 static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
66
67 namespace SALOMEDS
68 {
69   class Notifier: public SALOMEDSImpl_AbstractCallback
70   {
71   public:
72     Notifier(CORBA::ORB_ptr orb)
73     {
74       _orb = CORBA::ORB::_duplicate(orb);
75     }
76
77     //============================================================================
78     /*! Function : addSO_Notification
79      *  Purpose  : This function tells all the observers that a SO has been added
80      */
81     //============================================================================
82
83     virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
84     {
85       std::string anID=theSObject.GetID();
86       const char* cID=anID.c_str();
87       for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
88       {
89         it->first->notifyObserverID(cID,1);
90       }
91       return true; // NGE return always true but can be modified if needed
92     }
93
94     //============================================================================
95     /*! Function : removeSO_Notification
96      *  Purpose  : This function tells all the observers that a SO has been removed
97      */
98     //============================================================================
99
100     virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject)
101     {
102       std::string anID=theSObject.GetID();
103       const char* cID=anID.c_str();
104       for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
105       {
106         it->first->notifyObserverID(cID,2);
107       }
108       return true; // NGE return always true but can be modified if needed
109     }
110
111     //============================================================================
112     /*! Function : modifySO_Notification
113      *  Purpose  : This function tells all the observers that a SO has been modified
114      */
115     //============================================================================
116
117     virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason)
118     {
119       for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
120       {
121         if(it->second)
122         {
123           std::string anID=theSObject.GetID();
124           const char* cID=anID.c_str();
125           it->first->notifyObserverID(cID,reason);
126         }
127       }
128       return true; // NGE return always true but can be modified if needed
129     }
130
131     //============================================================================
132     /*! Function : modifyNB_Notification
133      *  Purpose  : This function tells all the observers that 
134      *             a NoteBook variable has been added/modified/removed.
135      */
136     //============================================================================
137     
138     virtual bool modifyNB_Notification(const char* theVarName)
139     {
140       for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
141         {
142           it->first->notifyObserverID(theVarName,6);
143         }
144       return true; // NGE return always true but can be modified if needed
145     }
146
147     //============================================================================
148     /*! Function : attach
149      *  Purpose  : register an Observer
150      */
151     //============================================================================
152
153     virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
154     {
155       myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
156     }
157
158     //============================================================================
159     /*! Function : detach
160      *  Purpose  : unregister an Observer
161      */
162     //============================================================================
163
164     virtual void detach(SALOMEDS::Observer_ptr theObs)
165     {
166       for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
167       {
168         if ( it->first->_is_equivalent(theObs) ) {
169           myObservers.erase( it );
170           break;
171         }
172       }
173     }
174
175   private:
176     typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList;
177     typedef ObsList::iterator ObsListIter;
178     ObsList myObservers;
179     CORBA::ORB_var                    _orb;
180   };
181
182   class GenObjRegister: public SALOMEDSImpl_AbstractCallback
183   {
184   public:
185     GenObjRegister(CORBA::ORB_ptr orb)
186     {
187       _orb = CORBA::ORB::_duplicate(orb);
188     }
189     virtual void RegisterGenObj  (const std::string& theIOR)
190     {
191       try
192       {
193         CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
194         if ( obj->_non_existent() ) return;
195         SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
196         if(! CORBA::is_nil(gobj) )
197         {
198           gobj->Register();
199         }
200       }
201       catch(const CORBA::Exception& e)
202       {
203       }
204     }
205     virtual void UnRegisterGenObj(const std::string& theIOR)
206     {
207       try
208       {
209         CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
210         if ( obj->_non_existent() ) return;
211         SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
212         if(! CORBA::is_nil(gobj) )
213         {
214           gobj->UnRegister();
215         }
216       }
217       catch(const CORBA::Exception& e)
218       {
219       }
220     }
221
222   private:
223     CORBA::ORB_var _orb;
224   };
225
226 } // namespace SALOMEDS
227
228 //============================================================================
229 /*! Function : SALOMEDS_Study_i
230  *  Purpose  : SALOMEDS_Study_i constructor
231  */
232 //============================================================================
233 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb)
234 {
235   _orb     = CORBA::ORB::_duplicate(orb);
236   _impl    = new SALOMEDSImpl_Study();
237   _factory = new SALOMEDS_DriverFactory_i(_orb);
238
239   Init();
240 }
241
242 //============================================================================
243 /*! Function : ~SALOMEDS_Study_i
244  *  Purpose  : SALOMEDS_Study_i destructor
245  */
246 //============================================================================
247 SALOMEDS_Study_i::~SALOMEDS_Study_i()
248 {
249   Clear();
250   delete _factory;
251   delete _impl;
252 }
253
254 //============================================================================
255 /*! Function : Init
256  *  Purpose  : Initialize study components
257  */
258 //============================================================================
259 void SALOMEDS_Study_i::Init()
260 {
261   if ( !_impl->GetDocument() )
262     _impl->Init();
263
264   _builder        = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);  
265   _notifier       = new SALOMEDS::Notifier(_orb);
266   _genObjRegister = new SALOMEDS::GenObjRegister(_orb);
267   _closed         = false;
268
269   _impl->setNotifier(_notifier);
270   _impl->setGenObjRegister( _genObjRegister );
271
272   // Notify GUI that study was created
273   SALOME_NamingService *aNamingService = KERNEL::getNamingService();
274   CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
275   SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
276   if ( !CORBA::is_nil(aSession) ) {
277     std::stringstream ss;
278     ss << "studyCreated";
279     std::string str = ss.str();
280     SALOMEDS::unlock();
281     aSession->emitMessageOneWay(str.c_str());
282     SALOMEDS::lock();
283   }
284 }
285
286 //============================================================================
287 /*! Function : Clear
288  *  Purpose  : Clear study components
289  */
290 //============================================================================
291 void SALOMEDS_Study_i::Clear()
292 {
293   //delete the builder servant
294   PortableServer::POA_var poa=_builder->_default_POA();
295   PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
296   poa->deactivate_object(anObjectId.in());
297   _builder->_remove_ref();
298
299   SALOMEDS::Locker lock;
300
301   if (_closed)
302     throw SALOMEDS::Study::StudyInvalidReference();
303
304   RemovePostponed(-1);
305   if (_impl->GetDocument()) {
306     SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
307     for (; itcomponent->More(); itcomponent->Next()) {
308       SALOMEDS::SComponent_var sco = itcomponent->Value();
309       CORBA::String_var compodatatype=sco->ComponentDataType();
310       MESSAGE ( "Look for an engine for data type :"<< compodatatype);
311       // if there is an associated Engine call its method for closing
312       CORBA::String_var IOREngine;
313       if (sco->ComponentIOR(IOREngine)) {
314         // we have found the associated engine to write the data
315         MESSAGE ( "We have found an engine for data type :"<< compodatatype);
316         //_narrow can throw a corba exception
317         try {
318               CORBA::Object_var obj = _orb->string_to_object(IOREngine);
319               if (!CORBA::is_nil(obj)) {
320                 SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
321                 if (!anEngine->_is_nil())  {
322                   SALOMEDS::unlock();
323                   anEngine->Close(sco);
324                   SALOMEDS::lock();
325                 }
326               }
327         }
328         catch (CORBA::Exception&) {
329         }
330       }
331       sco->UnRegister();
332     }
333
334     //Does not need any more this iterator
335     itcomponent->UnRegister();
336   }
337
338   // Notify GUI that study is cleared
339   SALOME_NamingService *aNamingService = KERNEL::getNamingService();
340   CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
341   SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
342   if ( !CORBA::is_nil(aSession) ) {
343     std::stringstream ss;
344     ss << "studyCleared";
345     std::string str = ss.str();
346     SALOMEDS::unlock();
347     aSession->emitMessageOneWay(str.c_str());
348     SALOMEDS::lock();
349   }
350
351   _impl->Clear();
352   _impl->setNotifier(0);
353   delete _notifier;
354   delete _genObjRegister;
355
356   _closed = true;
357 }
358
359 //============================================================================
360 /*! Function : Open
361  *  Purpose  : Open a Study from it's persistent reference
362  */
363 //============================================================================
364 bool SALOMEDS_Study_i::Open(const char* aUrl)
365   throw(SALOME::SALOME_Exception)
366 {
367   SALOMEDS::Locker lock;
368
369   Unexpect aCatch(SalomeException);
370   MESSAGE("Begin of SALOMEDS_Study_i::Open");
371
372   bool res = _impl->Open(std::string(aUrl));
373
374   if ( !res )
375     THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
376   return res;
377 }
378
379 //============================================================================
380 /*! Function : Save
381  *  Purpose  : Save a Study to it's persistent reference
382  */
383 //============================================================================
384 CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile)
385 {
386   SALOMEDS::Locker lock;
387   return _impl->Save(_factory, theMultiFile);
388 }
389
390 CORBA::Boolean SALOMEDS_Study_i::SaveASCII(CORBA::Boolean theMultiFile)
391 {
392   SALOMEDS::Locker lock;
393   return _impl->SaveASCII(_factory, theMultiFile);
394 }
395
396 //=============================================================================
397 /*! Function : SaveAs
398  *  Purpose  : Save a study to the persistent reference aUrl
399  */
400 //============================================================================
401 CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile)
402 {
403   SALOMEDS::Locker lock;
404   return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile);
405 }
406
407 CORBA::Boolean SALOMEDS_Study_i::SaveAsASCII(const char* aUrl, CORBA::Boolean theMultiFile)
408 {
409   SALOMEDS::Locker lock;
410   return _impl->SaveAsASCII(std::string(aUrl), _factory, theMultiFile);
411 }
412
413 //============================================================================
414 /*! Function : CanCopy
415  *  Purpose  :
416  */
417 //============================================================================
418 CORBA::Boolean SALOMEDS_Study_i::CanCopy(SALOMEDS::SObject_ptr theObject)
419 {
420   SALOMEDS::Locker lock;
421
422   CORBA::String_var anID = theObject->GetID();
423   SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
424
425   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
426   bool ret = _impl->CanCopy(anObject, aDriver);
427   delete aDriver;
428   return ret;
429 }
430
431 //============================================================================
432 /*! Function : Copy
433  *  Purpose  :
434  */
435 //============================================================================
436 CORBA::Boolean SALOMEDS_Study_i::Copy(SALOMEDS::SObject_ptr theObject)
437 {
438   SALOMEDS::Locker lock;
439
440   CORBA::String_var anID = theObject->GetID();
441   SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
442
443   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
444   bool ret = _impl->Copy(anObject, aDriver);
445   delete aDriver;
446   return ret;
447 }
448
449 //============================================================================
450 /*! Function : CanPaste
451  *  Purpose  :
452  */
453 //============================================================================
454 CORBA::Boolean SALOMEDS_Study_i::CanPaste(SALOMEDS::SObject_ptr theObject)
455 {
456   SALOMEDS::Locker lock;
457
458   CORBA::String_var anID = theObject->GetID();
459   SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
460
461   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
462   bool ret = _impl->CanPaste(anObject, aDriver);
463   delete aDriver;
464   return ret;
465 }
466
467 //============================================================================
468 /*! Function : Paste
469  *  Purpose  :
470  */
471 //============================================================================
472 SALOMEDS::SObject_ptr SALOMEDS_Study_i::Paste(SALOMEDS::SObject_ptr theObject)
473      throw(SALOMEDS::StudyBuilder::LockProtection)
474 {
475   SALOMEDS::Locker lock;
476
477   Unexpect aCatch(LockProtection);
478
479   CORBA::String_var anID = theObject->GetID();
480   SALOMEDSImpl_SObject anObject = _impl->GetSObject(anID.in());
481   SALOMEDSImpl_SObject aNewSO;
482
483   try {
484     SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
485     aNewSO =  _impl->Paste(anObject, aDriver);
486     delete aDriver;
487   }
488   catch (...) {
489     throw SALOMEDS::StudyBuilder::LockProtection();
490   }
491
492   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aNewSO, _orb);
493   return so._retn();
494 }
495
496 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
497 {
498   SALOMEDS_Driver_i* driver = NULL;
499
500   SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
501   if(!aSCO.IsNull()) {
502     std::string IOREngine = aSCO.GetIOR();
503     if(!IOREngine.empty()) {
504       CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
505       Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
506       driver = new SALOMEDS_Driver_i(Engine, orb);
507     }
508   }
509
510   return driver;
511 }
512
513 //============================================================================
514 /*! Function : GetPersistentReference
515  *  Purpose  : Get persistent reference of study (idem URL())
516  */
517 //============================================================================
518 char* SALOMEDS_Study_i::GetPersistentReference()
519 {
520   SALOMEDS::Locker lock; 
521   if (_closed)
522     throw SALOMEDS::Study::StudyInvalidReference();  
523   return CORBA::string_dup(_impl->GetPersistentReference().c_str());
524 }
525 //============================================================================
526 /*! Function : GetTransientReference
527  *  Purpose  : Get IOR of the Study (registred in OCAF document in doc->Root)
528  */
529 //============================================================================
530 char* SALOMEDS_Study_i::GetTransientReference()
531 {
532   SALOMEDS::Locker lock; 
533   if (_closed)
534     throw SALOMEDS::Study::StudyInvalidReference();  
535   return CORBA::string_dup(_impl->GetTransientReference().c_str());
536 }
537
538 //============================================================================
539 /*! Function : IsEmpty
540  *  Purpose  : Detect if study is empty
541  */
542 //============================================================================
543 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
544 {
545   SALOMEDS::Locker lock; 
546   if (_closed)
547     throw SALOMEDS::Study::StudyInvalidReference();  
548   return _impl->IsEmpty();
549 }
550
551 //============================================================================
552 /*! Function : FindComponent
553  *  Purpose  : Find a Component with ComponentDataType = aComponentName
554  */
555 //============================================================================
556 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
557 {
558   SALOMEDS::Locker lock; 
559   
560   if (_closed)
561     throw SALOMEDS::Study::StudyInvalidReference();  
562
563   SALOMEDS::SComponent_var sco;
564
565   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName));
566   if (!aCompImpl.IsNull())
567     sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
568
569   return sco._retn();
570 }
571
572 //============================================================================
573 /*! Function : FindComponentID
574  *  Purpose  : Find a Component from it's ID
575  */
576 //============================================================================
577 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
578 {
579   SALOMEDS::Locker lock; 
580   
581   if (_closed)
582     throw SALOMEDS::Study::StudyInvalidReference();  
583
584   SALOMEDS::SComponent_var sco;
585
586   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID));
587   if (!aCompImpl.IsNull())
588     sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb);
589
590   return sco._retn();
591 }
592
593 //============================================================================
594 /*! Function : FindObject
595  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
596  */
597 //============================================================================
598 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
599 {
600   SALOMEDS::Locker lock; 
601
602   if (_closed)
603     throw SALOMEDS::Study::StudyInvalidReference();  
604
605   SALOMEDS::SObject_var so;
606
607   SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName));
608   if (!aSO.IsNull()) {
609     if (aSO.IsComponent()) {
610       SALOMEDSImpl_SComponent aSCO = aSO;
611       so = SALOMEDS_SComponent_i::New(aSCO, _orb);
612     }
613     else {
614       so = SALOMEDS_SObject_i::New(aSO, _orb);
615     }
616   }
617
618   return so._retn();
619 }
620
621 //============================================================================
622 /*! Function : FindObjectID
623  *  Purpose  : Find an Object with ID = anObjectID
624  */
625 //============================================================================
626 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
627 {
628   SALOMEDS::Locker lock; 
629
630   if (_closed)
631     throw SALOMEDS::Study::StudyInvalidReference();  
632
633   SALOMEDS::SObject_var so;
634
635   SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID));
636   if (!aSO.IsNull())
637     so = SALOMEDS_SObject_i::New(aSO, _orb);
638
639   return so._retn();
640 }
641
642 //============================================================================
643 /*! Function : CreateObjectID
644  *  Purpose  : Creates an Object with ID = anObjectID
645  */
646 //============================================================================
647 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
648 {
649   SALOMEDS::Locker lock; 
650
651   if (_closed)
652     throw SALOMEDS::Study::StudyInvalidReference();  
653
654   SALOMEDS::SObject_var so;
655
656   if (anObjectID && strlen(anObjectID) > 0) {
657     SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
658     if (!aSO.IsNull())
659       so = SALOMEDS_SObject_i::New(aSO, _orb);
660   }
661
662   return so._retn();
663 }
664
665 //============================================================================
666 /*! Function : FindObjectByName
667  *  Purpose  : Find Objects with SALOMEDS::Name = anObjectName in a Component
668  *           : with ComponentDataType = aComponentName
669  */
670 //============================================================================
671 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
672                                                                     const char* aComponentName )
673 {
674   SALOMEDS::Locker lock; 
675
676   if (_closed)
677     throw SALOMEDS::Study::StudyInvalidReference();  
678
679   std::vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(std::string((char*)anObjectName),
680                                                                    std::string((char*)aComponentName));
681
682   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
683   int aLength = aSeq.size();
684   listSO->length(aLength);
685   for (int i = 0; i < aLength; i++) {
686     SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New(aSeq[i], _orb);
687     listSO[i] = so;
688   }
689   
690   return listSO._retn();
691 }
692
693 //============================================================================
694 /*! Function : FindObjectIOR
695  *  Purpose  : Find an Object with IOR = anObjectIOR
696  */
697 //============================================================================
698 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
699 {
700   SALOMEDS::Locker lock; 
701
702   if (_closed)
703     throw SALOMEDS::Study::StudyInvalidReference();  
704
705   SALOMEDS::SObject_var so;
706
707   SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR));
708   if (!aSO.IsNull())
709     so = SALOMEDS_SObject_i::New(aSO, _orb);
710
711   return so._retn();
712 }
713
714 //============================================================================
715 /*! Function : FindObjectByPath
716  *  Purpose  : Find an Object by its path = thePath
717  */
718 //============================================================================
719 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
720 {
721   SALOMEDS::Locker lock; 
722
723   if (_closed)
724     throw SALOMEDS::Study::StudyInvalidReference();  
725
726   SALOMEDS::SObject_var so;
727
728   SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath));
729   if (!aSO.IsNull())
730     so = SALOMEDS_SObject_i::New (aSO, _orb);
731
732   return so._retn();
733 }
734
735 //============================================================================
736 /*! Function : GetObjectPath
737  *  Purpose  : 
738  */
739 //============================================================================
740 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
741 {
742   SALOMEDS::Locker lock; 
743
744   if (_closed)
745     throw SALOMEDS::Study::StudyInvalidReference();  
746
747   std::string aPath = "";
748
749   if (!CORBA::is_nil(theObject)) {
750     SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
751     SALOMEDSImpl_SObject aSO;
752
753     if (!CORBA::is_nil(aSObj)) {
754       aSO = _impl->FindObjectID(aSObj->GetID());
755     }
756     else {
757       aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject));
758     }
759     
760     if (!aSO.IsNull()) {    
761       aPath = _impl->GetObjectPath(aSO);
762     }
763   }
764
765   return CORBA::string_dup(aPath.c_str());
766 }
767
768
769 //============================================================================
770 /*! Function : SetContext
771  *  Purpose  : Sets the current context
772  */
773 //============================================================================
774 void SALOMEDS_Study_i::SetContext(const char* thePath) 
775 {
776   SALOMEDS::Locker lock; 
777
778   if (_closed)
779     throw SALOMEDS::Study::StudyInvalidReference();  
780
781   _impl->SetContext(std::string((char*)thePath));
782   if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
783     throw SALOMEDS::Study::StudyInvalidContext();  
784 }
785
786 //============================================================================
787 /*! Function : GetContext
788  *  Purpose  : Gets the current context
789  */
790 //============================================================================
791 char* SALOMEDS_Study_i::GetContext() 
792 {
793   SALOMEDS::Locker lock; 
794   
795   if (_closed)
796     throw SALOMEDS::Study::StudyInvalidReference();  
797
798   if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();
799
800   return CORBA::string_dup(_impl->GetContext().c_str());
801 }
802
803 //============================================================================
804 /*! Function : GetObjectNames
805  *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
806  */
807 //============================================================================
808 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) 
809 {
810   SALOMEDS::Locker lock; 
811
812   if (_closed)
813     throw SALOMEDS::Study::StudyInvalidReference();  
814
815   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
816
817   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
818     throw SALOMEDS::Study::StudyInvalidContext();
819   
820   std::vector<std::string> aSeq = _impl->GetObjectNames(std::string((char*)theContext));
821   if (_impl->GetErrorCode() == "InvalidContext")
822     throw SALOMEDS::Study::StudyInvalidContext();
823
824   int aLength = aSeq.size();
825   aResult->length(aLength);
826   for (int anIndex = 0; anIndex < aLength; anIndex++) {
827     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
828   }
829
830   return aResult._retn();
831 }
832
833 //============================================================================
834 /*! Function : GetDirectoryNames
835  *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
836  */
837 //============================================================================
838 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) 
839 {
840   SALOMEDS::Locker lock; 
841
842   if (_closed)
843     throw SALOMEDS::Study::StudyInvalidReference();  
844
845   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
846
847   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
848     throw SALOMEDS::Study::StudyInvalidContext();
849   
850   std::vector<std::string> aSeq = _impl->GetDirectoryNames(std::string((char*)theContext));
851   if (_impl->GetErrorCode() == "InvalidContext")
852     throw SALOMEDS::Study::StudyInvalidContext();
853
854   int aLength = aSeq.size();
855   aResult->length(aLength);
856   for (int anIndex = 0; anIndex < aLength; anIndex++) {
857     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
858   }
859   
860   return aResult._retn();
861 }
862
863 //============================================================================
864 /*! Function : GetFileNames
865  *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
866  */
867 //============================================================================
868 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) 
869 {
870   SALOMEDS::Locker lock; 
871
872   if (_closed)
873     throw SALOMEDS::Study::StudyInvalidReference();  
874
875   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
876
877   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
878     throw SALOMEDS::Study::StudyInvalidContext();
879   
880   std::vector<std::string> aSeq = _impl->GetFileNames(std::string((char*)theContext));
881   if (_impl->GetErrorCode() == "InvalidContext")
882     throw SALOMEDS::Study::StudyInvalidContext();
883
884   int aLength = aSeq.size();
885   aResult->length(aLength);
886   for (int anIndex = 0; anIndex < aLength; anIndex++) {
887     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
888   }
889
890   return aResult._retn();
891 }
892
893 //============================================================================
894 /*! Function : GetComponentNames
895  *  Purpose  : method to get all components names
896  *  SRN:       Note, theContext can be any, it doesn't matter
897  */
898 //============================================================================
899 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
900 {
901   SALOMEDS::Locker lock; 
902
903   if (_closed)
904     throw SALOMEDS::Study::StudyInvalidReference();  
905
906   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
907
908   std::vector<std::string> aSeq = _impl->GetComponentNames(std::string((char*)theContext));
909
910   int aLength = aSeq.size();
911   aResult->length(aLength);
912   for(int anIndex = 0; anIndex < aLength; anIndex++) {
913     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
914   }
915
916   return aResult._retn();
917 }
918
919 //============================================================================
920 /*! Function : NewChildIterator
921  *  Purpose  : Create a ChildIterator from an SObject
922  */
923 //============================================================================
924 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
925 {
926   SALOMEDS::Locker lock; 
927
928   if (_closed)
929     throw SALOMEDS::Study::StudyInvalidReference();  
930
931   CORBA::String_var anID = theSO->GetID();
932   SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
933   SALOMEDSImpl_ChildIterator anItr(aSO);
934   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
935   SALOMEDS::ChildIterator_var it = it_servant->_this();
936
937   return it._retn();
938 }
939
940
941 //============================================================================
942 /*! Function : NewComponentIterator
943  *  Purpose  : Create a SComponentIterator
944  */
945 //============================================================================
946 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
947 {
948   SALOMEDS::Locker lock; 
949
950   if (_closed)
951     throw SALOMEDS::Study::StudyInvalidReference();  
952
953   SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
954   it_servant->Init();
955   SALOMEDS::SComponentIterator_var it = it_servant->_this();
956
957   return it._retn();
958 }
959
960
961 //============================================================================
962 /*! Function : NewBuilder
963  *  Purpose  : Create a StudyBuilder
964  */
965 //============================================================================
966 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
967 {
968   SALOMEDS::Locker lock; 
969
970   if (_closed)
971     throw SALOMEDS::Study::StudyInvalidReference();  
972
973   SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this());
974
975   return sb._retn();
976 }
977  
978 //============================================================================
979 /*! Function : Name
980  *  Purpose  : get study name
981  */
982 //============================================================================
983 char* SALOMEDS_Study_i::Name()
984 {
985   SALOMEDS::Locker lock; 
986   // Name is specified as IDL attribute: user exception cannot be raised
987   return CORBA::string_dup(_impl->Name().c_str());
988 }
989
990 //============================================================================
991 /*! Function : IsSaved
992  *  Purpose  : get if study has been saved
993  */
994 //============================================================================
995 CORBA::Boolean SALOMEDS_Study_i::IsSaved()
996 {
997   SALOMEDS::Locker lock; 
998   // IsSaved is specified as IDL attribute: user exception cannot be raised
999   return (!_closed) ? _impl->IsSaved() : false;
1000 }
1001
1002 //============================================================================
1003 /*! Function : IsSaved
1004  *  Purpose  : set if study has been saved
1005  */
1006 //============================================================================
1007 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
1008 {
1009   SALOMEDS::Locker lock; 
1010   // IsSaved is specified as IDL attribute: user exception cannot be raised
1011   if (!_closed)
1012     _impl->IsSaved(save);
1013 }
1014
1015 //============================================================================
1016 /*! Function : IsModified
1017  *  Purpose  : Detect if a Study has been modified since it has been saved
1018  */
1019 //============================================================================
1020 CORBA::Boolean SALOMEDS_Study_i::IsModified()
1021 {
1022   SALOMEDS::Locker lock; 
1023
1024   if (_closed)
1025     throw SALOMEDS::Study::StudyInvalidReference();  
1026
1027   return _impl->IsModified();
1028 }
1029
1030 //============================================================================
1031 /*! Function : Modified
1032  *  Purpose  : Sets a Modified flag of a Study to True
1033  */
1034 //============================================================================
1035 void SALOMEDS_Study_i::Modified()
1036 {
1037   SALOMEDS::Locker lock; 
1038
1039   if (_closed)
1040     throw SALOMEDS::Study::StudyInvalidReference();  
1041
1042   _impl->Modify();
1043 }
1044
1045 //============================================================================
1046 /*! Function : URL
1047  *  Purpose  : get URL of the study (persistent reference of the study)
1048  */
1049 //============================================================================
1050 char* SALOMEDS_Study_i::URL()
1051 {
1052   SALOMEDS::Locker lock; 
1053   // URL is specified as IDL attribute: user exception cannot be raised
1054   return CORBA::string_dup(_impl->URL().c_str());
1055 }
1056
1057 //============================================================================
1058 /*! Function : URL
1059  *  Purpose  : set URL of the study (persistent reference of the study)
1060  */
1061 //============================================================================
1062 void SALOMEDS_Study_i::URL(const char* url)
1063 {
1064   SALOMEDS::Locker lock; 
1065   // URL is specified as IDL attribute: user exception cannot be raised
1066   _impl->URL(std::string((char*)url));
1067 }
1068
1069 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) 
1070 {
1071   SALOMEDS::Locker lock; 
1072
1073   if (_closed)
1074     throw SALOMEDS::Study::StudyInvalidReference();  
1075
1076   _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry));
1077 }
1078
1079 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb)
1080 {
1081   SALOMEDS::Locker lock;
1082
1083   SALOMEDSImpl_AttributeIOR* Att = NULL;
1084   if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
1085     char* IOR = CORBA::string_dup(Att->Value().c_str());
1086     CORBA::Object_var obj = orb->string_to_object(IOR);
1087     SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
1088     ASSERT(!CORBA::is_nil(aStudy));
1089     return SALOMEDS::Study::_duplicate(aStudy);
1090   } else {
1091     MESSAGE("GetStudy: Problem to get study");
1092   }
1093   return SALOMEDS::Study::_nil();
1094 }
1095
1096 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
1097 {
1098   SALOMEDS::Locker lock; 
1099   SALOMEDSImpl_Study::IORUpdated(theAttribute);
1100 }
1101
1102 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) 
1103 {
1104   SALOMEDS::Locker lock; 
1105
1106   if (_closed)
1107     throw SALOMEDS::Study::StudyInvalidReference();  
1108
1109   SALOMEDS::GenericAttribute_ptr aTarget;
1110   if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
1111     return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
1112   }
1113   SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
1114   aList->length(0);
1115   return aList;
1116 }
1117
1118
1119 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() 
1120 {
1121   SALOMEDS::Locker lock; 
1122   
1123   if (_closed)
1124     throw SALOMEDS::Study::StudyInvalidReference();  
1125
1126   SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
1127   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
1128   SALOMEDS::AttributeStudyProperties_var aProp = SP->_this();
1129   return aProp._retn();
1130 }
1131
1132 char* SALOMEDS_Study_i::GetLastModificationDate() 
1133 {
1134   SALOMEDS::Locker lock; 
1135
1136   if (_closed)
1137     throw SALOMEDS::Study::StudyInvalidReference();  
1138
1139   return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
1140 }
1141
1142 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
1143 {
1144   SALOMEDS::Locker lock; 
1145   
1146   if (_closed)
1147     throw SALOMEDS::Study::StudyInvalidReference();  
1148
1149   SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
1150
1151   std::vector<std::string> aSeq = _impl->GetModificationsDate();
1152
1153   int aLength = aSeq.size();
1154   aDates->length(aLength);
1155   for (int anIndex = 0; anIndex < aLength; anIndex++) {
1156     aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1157   }
1158
1159   return aDates._retn();
1160 }
1161
1162 //============================================================================
1163 /*! Function : GetUseCaseBuilder
1164  *  Purpose  : Returns a UseCase builder
1165  */
1166 //============================================================================
1167 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
1168 {
1169   SALOMEDS::Locker lock; 
1170
1171   if (_closed)
1172     throw SALOMEDS::Study::StudyInvalidReference();  
1173
1174   SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
1175   SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this();
1176   return uc._retn();
1177 }
1178
1179 //============================================================================
1180 /*! Function : AddPostponed
1181  *  Purpose  : 
1182  */
1183  //============================================================================
1184 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
1185 {
1186   SALOMEDS::Locker lock; 
1187   //Not implemented
1188 }
1189
1190 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
1191 {
1192   SALOMEDS::Locker lock; 
1193   //Not implemented
1194 }
1195
1196 //============================================================================
1197 /*! Function : RemovePostponed
1198  *  Purpose  : 
1199  */
1200 //============================================================================
1201 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) 
1202 {  
1203   SALOMEDS::Locker lock; 
1204
1205   if (_closed)
1206     throw SALOMEDS::Study::StudyInvalidReference();  
1207
1208   std::vector<std::string> anIORs = _impl->GetIORs();
1209   int i, aSize = (int)anIORs.size();
1210   
1211   for (i = 0; i < aSize; i++) {
1212     try {
1213       CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
1214       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
1215       //rnv: To avoid double deletion of the Salome Generic Objects:
1216       //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR();
1217       //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
1218       //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
1219     } catch (...) {}
1220   }
1221
1222   //Not implemented
1223 }
1224
1225 //============================================================================
1226 /*! Function : UndoPostponed
1227  *  Purpose  : 
1228  */
1229 //============================================================================
1230 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
1231 {
1232   SALOMEDS::Locker lock; 
1233   //Not implemented
1234 }
1235
1236
1237 //============================================================================
1238 /*! Function : DumpStudy
1239  *  Purpose  : 
1240  */
1241 //============================================================================
1242 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
1243                                            const char* theBaseName, 
1244                                            CORBA::Boolean isPublished,
1245                                            CORBA::Boolean isMultiFile)
1246 {
1247   SALOMEDS::Locker lock; 
1248
1249   if (_closed)
1250     throw SALOMEDS::Study::StudyInvalidReference();  
1251
1252   std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
1253   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
1254   bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
1255   delete factory;
1256
1257   return ret;
1258 }
1259
1260 //============================================================================
1261 /*! Function : GetCommonParameters
1262  *  Purpose  : 
1263  */
1264 //============================================================================
1265 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
1266 {
1267   SALOMEDS::Locker lock; 
1268   
1269   if (_closed)
1270     throw SALOMEDS::Study::StudyInvalidReference();  
1271
1272   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
1273   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1274   SALOMEDS::AttributeParameter_var aParam = SP->_this();
1275
1276   return aParam._retn();
1277 }
1278  
1279 //============================================================================
1280 /*! Function : GetCommonModuleParameters
1281  *  Purpose  : 
1282  */
1283 //============================================================================
1284 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, 
1285                                                                        const char* theModuleName, 
1286                                                                        CORBA::Long theSavePoint)
1287 {
1288   SALOMEDS::Locker lock; 
1289   
1290   if (_closed)
1291     throw SALOMEDS::Study::StudyInvalidReference();  
1292
1293   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
1294   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
1295   SALOMEDS::AttributeParameter_var aParam = SP->_this();
1296
1297   return aParam._retn();
1298 }
1299
1300 //============================================================================
1301 /*! Function : SetStudyLock
1302  *  Purpose  : 
1303  */
1304 //============================================================================
1305 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
1306 {
1307   SALOMEDS::Locker lock; 
1308
1309   if (_closed)
1310     throw SALOMEDS::Study::StudyInvalidReference();  
1311
1312   _impl->SetStudyLock(theLockerID);
1313 }
1314
1315 //============================================================================
1316 /*! Function : IsStudyLocked
1317  *  Purpose  : 
1318  */
1319 //============================================================================
1320 bool SALOMEDS_Study_i::IsStudyLocked()
1321 {
1322   SALOMEDS::Locker lock; 
1323
1324   if (_closed)
1325     throw SALOMEDS::Study::StudyInvalidReference();  
1326
1327   return _impl->IsStudyLocked();
1328 }
1329
1330 //============================================================================
1331 /*! Function : UnLockStudy
1332  *  Purpose  : 
1333  */
1334 //============================================================================
1335 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
1336 {
1337   SALOMEDS::Locker lock; 
1338
1339   if (_closed)
1340     throw SALOMEDS::Study::StudyInvalidReference();  
1341
1342   _impl->UnLockStudy(theLockerID);
1343 }
1344
1345 //============================================================================
1346 /*! Function : GetLockerID
1347  *  Purpose  : 
1348  */
1349 //============================================================================
1350 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
1351 {
1352   SALOMEDS::Locker lock; 
1353
1354   if (_closed)
1355     throw SALOMEDS::Study::StudyInvalidReference();  
1356
1357   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1358
1359   std::vector<std::string> aSeq = _impl->GetLockerID();
1360
1361   int aLength = aSeq.size();
1362   aResult->length(aLength);
1363   for(int anIndex = 0; anIndex < aLength; anIndex++) {
1364     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
1365   }
1366
1367   return aResult._retn();
1368 }
1369 //============================================================================
1370 /*! Function : SetReal
1371  *  Purpose  : 
1372  */
1373 //============================================================================
1374 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
1375 {
1376   if (_closed)
1377     throw SALOMEDS::Study::StudyInvalidReference();  
1378
1379
1380   _impl->SetVariable(std::string(theVarName), 
1381                      theValue,
1382                      SALOMEDSImpl_GenericVariable::REAL_VAR);
1383   if (_notifier)
1384     _notifier->modifyNB_Notification(theVarName);
1385 }
1386
1387 //============================================================================
1388 /*! Function : SetInteger
1389  *  Purpose  : 
1390  */
1391 //============================================================================
1392 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
1393 {
1394   if (_closed)
1395     throw SALOMEDS::Study::StudyInvalidReference();  
1396
1397   _impl->SetVariable(std::string(theVarName), 
1398                      theValue,
1399                      SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1400   if (_notifier)
1401     _notifier->modifyNB_Notification(theVarName);
1402 }
1403
1404 //============================================================================
1405 /*! Function : SetBoolean
1406  *  Purpose  : 
1407  */
1408 //============================================================================
1409 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
1410 {
1411   if (_closed)
1412     throw SALOMEDS::Study::StudyInvalidReference();  
1413
1414   _impl->SetVariable(std::string(theVarName), 
1415                      theValue,
1416                      SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1417   if (_notifier)
1418     _notifier->modifyNB_Notification(theVarName);
1419 }
1420
1421 //============================================================================
1422 /*! Function : SetString
1423  *  Purpose  : 
1424  */
1425 //============================================================================
1426 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
1427 {
1428   if (_closed)
1429     throw SALOMEDS::Study::StudyInvalidReference();  
1430
1431   _impl->SetStringVariable(std::string(theVarName), 
1432                            theValue,
1433                            SALOMEDSImpl_GenericVariable::STRING_VAR);
1434   if (_notifier)
1435     _notifier->modifyNB_Notification(theVarName);
1436 }
1437
1438 //============================================================================
1439 /*! Function : SetStringAsDouble
1440  *  Purpose  : 
1441  */
1442 //============================================================================
1443 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
1444 {
1445   if (_closed)
1446     throw SALOMEDS::Study::StudyInvalidReference();  
1447
1448   _impl->SetStringVariableAsDouble(std::string(theVarName), 
1449                                    theValue,
1450                                    SALOMEDSImpl_GenericVariable::STRING_VAR);
1451 }
1452
1453 //============================================================================
1454 /*! Function : GetReal
1455  *  Purpose  : 
1456  */
1457 //============================================================================
1458 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
1459 {
1460   if (_closed)
1461     throw SALOMEDS::Study::StudyInvalidReference();  
1462
1463   return _impl->GetVariableValue(std::string(theVarName));
1464 }
1465
1466 //============================================================================
1467 /*! Function : GetInteger
1468  *  Purpose  : 
1469  */
1470 //============================================================================
1471 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
1472 {
1473   if (_closed)
1474     throw SALOMEDS::Study::StudyInvalidReference();  
1475
1476   return (long)_impl->GetVariableValue(std::string(theVarName));
1477 }
1478
1479 //============================================================================
1480 /*! Function : GetBoolean
1481  *  Purpose  : 
1482  */
1483 //============================================================================
1484 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
1485 {
1486   if (_closed)
1487     throw SALOMEDS::Study::StudyInvalidReference();  
1488
1489   return (bool)_impl->GetVariableValue(std::string(theVarName));
1490 }
1491
1492 //============================================================================
1493 /*! Function : GetString
1494  *  Purpose  : 
1495  */
1496 //============================================================================
1497 char* SALOMEDS_Study_i::GetString(const char* theVarName)
1498 {
1499   if (_closed)
1500     throw SALOMEDS::Study::StudyInvalidReference();  
1501
1502   return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str());
1503 }
1504
1505 //============================================================================
1506 /*! Function : IsReal
1507  *  Purpose  : 
1508  */
1509 //============================================================================
1510 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
1511 {
1512   if (_closed)
1513     throw SALOMEDS::Study::StudyInvalidReference();  
1514
1515   return _impl->IsTypeOf(std::string(theVarName),
1516                          SALOMEDSImpl_GenericVariable::REAL_VAR);
1517 }
1518
1519 //============================================================================
1520 /*! Function : IsInteger
1521  *  Purpose  : 
1522  */
1523 //============================================================================
1524 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1525 {
1526   if (_closed)
1527     throw SALOMEDS::Study::StudyInvalidReference();  
1528
1529   return _impl->IsTypeOf(std::string(theVarName),
1530                          SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1531 }
1532
1533 //============================================================================
1534 /*! Function : IsBoolean
1535  *  Purpose  : 
1536  */
1537 //============================================================================
1538 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1539 {
1540   if (_closed)
1541     throw SALOMEDS::Study::StudyInvalidReference();  
1542
1543   return _impl->IsTypeOf(std::string(theVarName),
1544                          SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1545 }
1546
1547 //============================================================================
1548 /*! Function : IsString
1549  *  Purpose  : 
1550  */
1551 //============================================================================
1552 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1553 {
1554   if (_closed)
1555     throw SALOMEDS::Study::StudyInvalidReference();  
1556
1557   return _impl->IsTypeOf(std::string(theVarName),
1558                          SALOMEDSImpl_GenericVariable::STRING_VAR);
1559 }
1560
1561 //============================================================================
1562 /*! Function : IsVariable
1563  *  Purpose  : 
1564  */
1565 //============================================================================
1566 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1567 {
1568   if (_closed)
1569     throw SALOMEDS::Study::StudyInvalidReference();  
1570
1571   return _impl->IsVariable(std::string(theVarName));
1572 }
1573
1574 //============================================================================
1575 /*! Function : GetVariableNames
1576  *  Purpose  : 
1577  */
1578 //============================================================================
1579 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1580 {
1581   if (_closed)
1582     throw SALOMEDS::Study::StudyInvalidReference();  
1583
1584   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1585
1586   std::vector<std::string> aVarNames = _impl->GetVariableNames();
1587
1588   int aLen = aVarNames.size();
1589   aResult->length(aLen);
1590   for (int anInd = 0; anInd < aLen; anInd++)
1591     aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1592   
1593   return aResult._retn();
1594 }
1595
1596 //============================================================================
1597 /*! Function : RemoveVariable
1598  *  Purpose  : 
1599  */
1600 //============================================================================
1601 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1602 {
1603   if (_closed)
1604     throw SALOMEDS::Study::StudyInvalidReference();  
1605
1606   bool res = _impl->RemoveVariable(std::string(theVarName));
1607   if (res && _notifier)
1608     _notifier->modifyNB_Notification(theVarName);
1609
1610   return res;
1611 }
1612
1613 //============================================================================
1614 /*! Function : RenameVariable
1615  *  Purpose  : 
1616  */
1617 //============================================================================
1618 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1619 {
1620   if (_closed)
1621     throw SALOMEDS::Study::StudyInvalidReference();  
1622
1623   bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName));
1624   if (res && _notifier)
1625     _notifier->modifyNB_Notification(theVarName);
1626
1627   return res;
1628 }
1629
1630 //============================================================================
1631 /*! Function : IsVariableUsed
1632  *  Purpose  : 
1633  */
1634 //============================================================================
1635 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1636 {
1637   if (_closed)
1638     throw SALOMEDS::Study::StudyInvalidReference();  
1639
1640   return _impl->IsVariableUsed(std::string(theVarName));
1641 }
1642
1643
1644 //============================================================================
1645 /*! Function : ParseVariables
1646  *  Purpose  : 
1647  */
1648 //============================================================================
1649 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1650 {
1651   if (_closed)
1652     throw SALOMEDS::Study::StudyInvalidReference();  
1653
1654   SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1655
1656   std::vector< std::vector<std::string> > aSections = _impl->ParseVariables(std::string(theVarName));
1657
1658   int aSectionsLen = aSections.size();
1659   aResult->length(aSectionsLen);
1660
1661   for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1662     std::vector<std::string> aVarNames = aSections[aSectionInd];
1663
1664     SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1665
1666     int aLen = aVarNames.size();
1667     aList->length(aLen);
1668
1669     for (int anInd = 0; anInd < aLen; anInd++)
1670       aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1671
1672     aResult[aSectionInd] = aList;
1673   }
1674
1675   return aResult._retn();
1676 }
1677
1678 //============================================================================
1679 /*! Function : GetDefaultScript
1680  *  Purpose  : 
1681  */
1682 //============================================================================
1683 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1684 {
1685   SALOMEDS::Locker lock; 
1686
1687   if (_closed)
1688     throw SALOMEDS::Study::StudyInvalidReference();  
1689
1690   std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1691   return CORBA::string_dup(script.c_str());
1692 }
1693
1694 //============================================================================
1695 /*! Function : EnableUseCaseAutoFilling
1696  *  Purpose  : 
1697  */
1698 //============================================================================
1699 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) 
1700
1701   if (_closed)
1702     throw SALOMEDS::Study::StudyInvalidReference();  
1703
1704   _impl->EnableUseCaseAutoFilling(isEnabled); 
1705   SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1706   if (builder) {
1707     if (isEnabled) {
1708       builder->SetOnAddSObject(_impl->GetCallback());
1709       builder->SetOnRemoveSObject(_impl->GetCallback());
1710     }
1711     else {
1712       builder->SetOnAddSObject(NULL);
1713       builder->SetOnRemoveSObject(NULL);
1714     }
1715   }
1716 }
1717
1718
1719 CORBA::Long SALOMEDS_Study_i::getPID()
1720 {
1721 #ifdef WIN32
1722   return (CORBA::Long)_getpid();
1723 #else
1724   return (CORBA::Long)getpid();
1725 #endif
1726 }
1727
1728 void SALOMEDS_Study_i::ShutdownWithExit()
1729 {
1730   exit( EXIT_SUCCESS );
1731 }
1732
1733 void SALOMEDS_Study_i::Shutdown()
1734 {
1735   if(!CORBA::is_nil(_orb))
1736     _orb->shutdown(0);
1737 }
1738
1739 //============================================================================
1740 /*! Function : attach
1741  *  Purpose  : This function attach an observer to the study
1742  */
1743 //============================================================================
1744 void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify)
1745 {
1746   if (_notifier)
1747     static_cast<SALOMEDS::Notifier*>(_notifier)->attach(theObs, modify);
1748 }
1749
1750
1751 //============================================================================
1752 /*! Function : detach
1753  *  Purpose  : This function detaches an observer from the study
1754  */
1755 //============================================================================
1756 void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs)
1757 {
1758   if (_notifier)
1759     static_cast<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
1760 }
1761
1762 //===========================================================================
1763 //   PRIVATE FUNCTIONS
1764 //===========================================================================
1765 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1766 {
1767 #ifdef WIN32
1768   long pid = (long)_getpid();
1769 #else
1770   long pid = (long)getpid();
1771 #endif  
1772   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1773   return reinterpret_cast<CORBA::LongLong>(_impl);
1774 }