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