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