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