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