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