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