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