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