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