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