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