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