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