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