Salome HOME
0020523: String notebook support
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  File   : SALOMEDS_Study_i.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "utilities.h"
27 #include "SALOMEDS_Study_i.hxx"
28 #include "SALOMEDS_StudyManager_i.hxx"
29 #include "SALOMEDS_UseCaseIterator_i.hxx"
30 #include "SALOMEDS_GenericAttribute_i.hxx"
31 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
32 #include "SALOMEDS_AttributeParameter_i.hxx"
33 #include "SALOMEDS_ChildIterator_i.hxx"
34 #include "SALOMEDS_Driver_i.hxx"
35 #include "SALOMEDS.hxx"
36
37 #include "SALOMEDSImpl_SObject.hxx"
38 #include "SALOMEDSImpl_SComponent.hxx"
39 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
40 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
41 #include "SALOMEDSImpl_AttributeParameter.hxx"
42 #include "SALOMEDSImpl_ChildIterator.hxx"
43 #include "SALOMEDSImpl_IParameters.hxx"
44
45 #include "DF_Label.hxx"
46 #include "DF_Attribute.hxx"
47
48 #include "Basics_Utils.hxx"
49
50 #ifdef WIN32
51 #include <process.h>
52 #else
53 #include <sys/types.h>
54 #include <unistd.h>
55 #endif
56
57 using namespace std;
58
59 std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
60
61 //============================================================================
62 /*! Function : SALOMEDS_Study_i
63  *  Purpose  : SALOMEDS_Study_i constructor
64  */
65 //============================================================================
66 SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
67                                    CORBA::ORB_ptr orb)
68 {
69   _orb = CORBA::ORB::_duplicate(orb);
70   _impl = theImpl;
71
72   _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);  
73 }
74   
75 //============================================================================
76 /*! Function : ~SALOMEDS_Study_i
77  *  Purpose  : SALOMEDS_Study_i destructor
78  */
79 //============================================================================
80 SALOMEDS_Study_i::~SALOMEDS_Study_i()
81 {
82   //delete the builder servant
83   PortableServer::POA_var poa=_builder->_default_POA();
84   PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
85   poa->deactivate_object(anObjectId.in());
86   _builder->_remove_ref();
87   
88   //delete implementation
89   delete _impl;
90   _mapOfStudies.erase(_impl);
91 }  
92
93 //============================================================================
94 /*! Function : GetPersistentReference
95  *  Purpose  : Get persistent reference of study (idem URL())
96  */
97 //============================================================================
98 char* SALOMEDS_Study_i::GetPersistentReference()
99 {
100   SALOMEDS::Locker lock; 
101   return CORBA::string_dup(_impl->GetPersistentReference().c_str());
102 }
103 //============================================================================
104 /*! Function : GetTransientReference
105  *  Purpose  : Get IOR of the Study (registred in OCAF document in doc->Root)
106  */
107 //============================================================================
108 char* SALOMEDS_Study_i::GetTransientReference()
109 {
110   SALOMEDS::Locker lock; 
111   return CORBA::string_dup(_impl->GetTransientReference().c_str()); 
112 }
113
114 //============================================================================
115 /*! Function : IsEmpty
116  *  Purpose  : Detect if study is empty
117  */
118 //============================================================================
119 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
120 {
121   SALOMEDS::Locker lock; 
122   return _impl->IsEmpty();
123 }
124
125 //============================================================================
126 /*! Function : FindComponent
127  *  Purpose  : Find a Component with ComponentDataType = aComponentName
128  */
129 //============================================================================
130 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
131 {
132   SALOMEDS::Locker lock; 
133   
134   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(string(aComponentName));
135   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
136
137   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
138   return sco._retn();
139 }
140
141 //============================================================================
142 /*! Function : FindComponentID
143  *  Purpose  : Find a Component from it's ID
144  */
145 //============================================================================
146 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
147 {
148   SALOMEDS::Locker lock; 
149   
150   SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(string((char*)aComponentID));
151   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
152
153   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
154   return sco._retn();
155 }
156
157 //============================================================================
158 /*! Function : FindObject
159  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
160  */
161 //============================================================================
162 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
163 {
164   SALOMEDS::Locker lock; 
165
166   SALOMEDSImpl_SObject aSO = _impl->FindObject(string((char*)anObjectName));
167   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
168
169   if(aSO.IsComponent()) {
170     SALOMEDSImpl_SComponent aSCO = aSO;
171     SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
172     return sco._retn();
173   }
174    
175   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
176  
177  return so._retn();
178 }
179
180 //============================================================================
181 /*! Function : FindObjectID
182  *  Purpose  : Find an Object with ID = anObjectID
183  */
184 //============================================================================
185 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
186 {
187   SALOMEDS::Locker lock; 
188
189   SALOMEDSImpl_SObject aSO = _impl->FindObjectID(string((char*)anObjectID));
190   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
191   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
192   return so._retn();
193 }
194
195 //============================================================================
196 /*! Function : CreateObjectID
197  *  Purpose  : Creates an Object with ID = anObjectID
198  */
199 //============================================================================
200 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
201 {
202   SALOMEDS::Locker lock; 
203
204   if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
205
206   SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
207   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
208
209   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
210   return so._retn();
211 }
212
213 //============================================================================
214 /*! Function : FindObjectByName
215  *  Purpose  : Find Objects with SALOMEDS::Name = anObjectName in a Component
216  *           : with ComponentDataType = aComponentName
217  */
218 //============================================================================
219 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
220                                                                     const char* aComponentName )
221 {
222   SALOMEDS::Locker lock; 
223
224   vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(string((char*)anObjectName),
225                                                                string((char*)aComponentName));
226   int aLength = aSeq.size();
227   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
228   listSO->length(aLength);
229   for(int i = 0; i<aLength; i++) {
230     SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
231     listSO[i] = so ;
232   }
233   return listSO._retn() ;
234 }
235
236 //============================================================================
237 /*! Function : FindObjectIOR
238  *  Purpose  : Find an Object with IOR = anObjectIOR
239  */
240 //============================================================================
241 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
242 {
243   SALOMEDS::Locker lock; 
244
245   SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(string((char*)anObjectIOR));
246   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
247
248   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
249   return so._retn();
250 }
251
252 //============================================================================
253 /*! Function : FindObjectByPath
254  *  Purpose  : Find an Object by its path = thePath
255  */
256 //============================================================================
257 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
258 {
259   SALOMEDS::Locker lock; 
260
261   SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(string((char*)thePath));
262   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
263
264   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
265   return so._retn();
266 }
267
268 //============================================================================
269 /*! Function : GetObjectPath
270  *  Purpose  : 
271  */
272 //============================================================================
273 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
274 {
275   SALOMEDS::Locker lock; 
276
277   string aPath("");
278   if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
279   SALOMEDSImpl_SObject aSO;
280   SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
281
282   if(!CORBA::is_nil(aSObj)) {
283     aSO = _impl->FindObjectID(aSObj->GetID());
284   }
285   else {
286     aSO  = _impl->FindObjectIOR(_orb->object_to_string(theObject));
287   }
288    
289   if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
290   
291   aPath = _impl->GetObjectPath(aSO);
292   return  CORBA::string_dup(aPath.c_str());
293 }
294
295
296 //============================================================================
297 /*! Function : SetContext
298  *  Purpose  : Sets the current context
299  */
300 //============================================================================
301 void SALOMEDS_Study_i::SetContext(const char* thePath) 
302 {
303   SALOMEDS::Locker lock; 
304
305   _impl->SetContext(string((char*)thePath));
306   if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
307     throw SALOMEDS::Study::StudyInvalidContext();  
308 }
309
310 //============================================================================
311 /*! Function : GetContext
312  *  Purpose  : Gets the current context
313  */
314 //============================================================================
315 char* SALOMEDS_Study_i::GetContext() 
316 {
317   SALOMEDS::Locker lock; 
318   
319   if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
320   return CORBA::string_dup(_impl->GetContext().c_str());
321 }
322
323 //============================================================================
324 /*! Function : GetObjectNames
325  *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
326  */
327 //============================================================================
328 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) 
329 {
330   SALOMEDS::Locker lock; 
331
332   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
333
334   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
335     throw SALOMEDS::Study::StudyInvalidContext();
336
337   vector<string> aSeq = _impl->GetObjectNames(string((char*)theContext));
338   if (_impl->GetErrorCode() == "InvalidContext")
339     throw SALOMEDS::Study::StudyInvalidContext();
340
341   int aLength = aSeq.size();
342   aResult->length(aLength);
343   for (int anIndex = 0; anIndex < aLength; anIndex++) {
344     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
345   }
346
347   return aResult._retn();
348 }
349
350 //============================================================================
351 /*! Function : GetDirectoryNames
352  *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
353  */
354 //============================================================================
355 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) 
356 {
357   SALOMEDS::Locker lock; 
358
359   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
360
361   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
362     throw SALOMEDS::Study::StudyInvalidContext();
363
364   vector<string> aSeq = _impl->GetDirectoryNames(string((char*)theContext));
365   if (_impl->GetErrorCode() == "InvalidContext")
366     throw SALOMEDS::Study::StudyInvalidContext();
367
368   int aLength = aSeq.size();
369   aResult->length(aLength);
370   for (int anIndex = 0; anIndex < aLength; anIndex++) {
371     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
372   }
373
374   return aResult._retn();
375 }
376
377 //============================================================================
378 /*! Function : GetFileNames
379  *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
380  */
381 //============================================================================
382 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) 
383 {
384   SALOMEDS::Locker lock; 
385
386   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
387
388   if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
389     throw SALOMEDS::Study::StudyInvalidContext();
390
391   vector<string> aSeq = _impl->GetFileNames(string((char*)theContext));
392   if (_impl->GetErrorCode() == "InvalidContext")
393     throw SALOMEDS::Study::StudyInvalidContext();
394
395   int aLength = aSeq.size();
396   aResult->length(aLength);
397   for (int anIndex = 0; anIndex < aLength; anIndex++) {
398     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
399   }
400
401   return aResult._retn();
402 }
403
404 //============================================================================
405 /*! Function : GetComponentNames
406  *  Purpose  : method to get all components names
407  *  SRN:       Note, theContext can be any, it doesn't matter
408  */
409 //============================================================================
410 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
411 {
412   SALOMEDS::Locker lock; 
413
414   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
415
416   vector<string> aSeq = _impl->GetComponentNames(string((char*)theContext));
417
418   int aLength = aSeq.size();
419   aResult->length(aLength);
420   for(int anIndex = 0; anIndex < aLength; anIndex++) {
421     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
422   }
423
424   return aResult._retn();
425 }
426
427 //============================================================================
428 /*! Function : NewChildIterator
429  *  Purpose  : Create a ChildIterator from an SObject
430  */
431 //============================================================================
432 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
433 {
434   SALOMEDS::Locker lock; 
435
436   CORBA::String_var anID=theSO->GetID();
437   SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
438   SALOMEDSImpl_ChildIterator anItr(aSO);
439
440   //Create iterator
441   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
442
443   return it_servant->_this();
444 }
445
446
447 //============================================================================
448 /*! Function : NewComponentIterator
449  *  Purpose  : Create a SComponentIterator
450  */
451 //============================================================================
452 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
453 {
454   SALOMEDS::Locker lock; 
455   SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
456   _it->Init();
457   return _it->_this();
458 }
459
460
461 //============================================================================
462 /*! Function : NewBuilder
463  *  Purpose  : Create a StudyBuilder
464  */
465 //============================================================================
466 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
467 {
468   SALOMEDS::Locker lock; 
469   return _builder->_this();
470 }
471  
472 //============================================================================
473 /*! Function : Name
474  *  Purpose  : get study name
475  */
476 //============================================================================
477 char* SALOMEDS_Study_i::Name()
478 {
479   SALOMEDS::Locker lock; 
480   return CORBA::string_dup(_impl->Name().c_str());
481 }
482
483 //============================================================================
484 /*! Function : Name
485  *  Purpose  : set study name
486  */
487 //============================================================================
488 void SALOMEDS_Study_i::Name(const char* name)
489 {
490   SALOMEDS::Locker lock;  
491   _impl->Name(string((char*)name));
492 }
493
494 //============================================================================
495 /*! Function : IsSaved
496  *  Purpose  : get if study has been saved
497  */
498 //============================================================================
499 CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
500 {
501   SALOMEDS::Locker lock; 
502   return _impl->IsSaved();
503 }
504
505 //============================================================================
506 /*! Function : IsSaved
507  *  Purpose  : set if study has been saved
508  */
509 //============================================================================
510 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
511 {
512   SALOMEDS::Locker lock; 
513   _impl->IsSaved(save);
514 }
515
516 //============================================================================
517 /*! Function : IsModified
518  *  Purpose  : Detect if a Study has been modified since it has been saved
519  */
520 //============================================================================
521 CORBA::Boolean  SALOMEDS_Study_i::IsModified()
522 {
523   SALOMEDS::Locker lock; 
524   return _impl->IsModified();
525 }
526
527 //============================================================================
528 /*! Function : Modified
529  *  Purpose  : Sets a Modified flag of a Study to True
530  */
531 //============================================================================
532 void  SALOMEDS_Study_i::Modified()
533 {
534   SALOMEDS::Locker lock; 
535   return _impl->Modify();
536 }
537
538
539 //============================================================================
540 /*! Function : URL
541  *  Purpose  : get URL of the study (persistent reference of the study)
542  */
543 //============================================================================
544 char* SALOMEDS_Study_i::URL()
545 {
546   SALOMEDS::Locker lock; 
547   return CORBA::string_dup(_impl->URL().c_str());
548 }
549
550 //============================================================================
551 /*! Function : URL
552  *  Purpose  : set URL of the study (persistent reference of the study)
553  */
554 //============================================================================
555 void SALOMEDS_Study_i::URL(const char* url)
556 {
557   SALOMEDS::Locker lock; 
558   _impl->URL(string((char*)url));
559 }
560
561
562 CORBA::Short SALOMEDS_Study_i::StudyId()
563 {
564   SALOMEDS::Locker lock; 
565   return _impl->StudyId();
566 }
567
568 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
569
570   SALOMEDS::Locker lock; 
571   _impl->StudyId(id);
572 }
573
574 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) 
575 {
576   SALOMEDS::Locker lock; 
577   _impl->UpdateIORLabelMap(string((char*)anIOR), string((char*)anEntry));
578 }
579
580 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) 
581 {
582   SALOMEDS::Locker lock; 
583
584   SALOMEDSImpl_AttributeIOR* Att = NULL;
585   if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
586     char* IOR = CORBA::string_dup(Att->Value().c_str());
587     CORBA::Object_var obj = orb->string_to_object(IOR);
588     SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
589     ASSERT(!CORBA::is_nil(aStudy));
590     return SALOMEDS::Study::_duplicate(aStudy);
591   } else {
592     MESSAGE("GetStudy: Problem to get study");
593   }
594   return SALOMEDS::Study::_nil();
595 }
596
597 SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
598 {
599   if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end()) 
600     return _mapOfStudies[aStudyImpl];
601   else
602     {
603       SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
604       _mapOfStudies[aStudyImpl]=Study_servant;
605       return Study_servant;
606     }
607 }
608
609 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
610 {
611   SALOMEDS::Locker lock; 
612   SALOMEDSImpl_Study::IORUpdated(theAttribute);
613 }
614
615 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) 
616 {
617   SALOMEDS::Locker lock; 
618
619   SALOMEDS::GenericAttribute_ptr aTarget;
620   if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
621     return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
622   }
623   SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
624   aList->length(0);
625   return aList;
626 }
627
628
629 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() 
630 {
631   SALOMEDS::Locker lock; 
632   
633   SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
634   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
635   return SP->AttributeStudyProperties::_this();
636 }
637
638 char* SALOMEDS_Study_i::GetLastModificationDate() 
639 {
640   SALOMEDS::Locker lock; 
641   return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
642 }
643
644 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
645 {
646   SALOMEDS::Locker lock; 
647   
648   vector<string> aSeq = _impl->GetModificationsDate();
649   int aLength = aSeq.size();
650   SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
651   aDates->length(aLength);
652
653   for(int anIndex = 0; anIndex < aLength; anIndex++) {
654     aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
655   }
656   return aDates._retn();
657 }
658
659
660
661 //============================================================================
662 /*! Function : GetUseCaseBuilder
663  *  Purpose  : Returns a UseCase builder
664  */
665 //============================================================================
666 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
667 {
668   SALOMEDS::Locker lock; 
669   SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
670   return UCBuilder->_this();
671 }
672
673
674 //============================================================================
675 /*! Function : Close
676  *  Purpose  : 
677  */
678 //============================================================================
679 void SALOMEDS_Study_i::Close()
680 {
681   SALOMEDS::Locker lock; 
682
683   RemovePostponed(-1);
684
685   SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
686   for (; itcomponent->More(); itcomponent->Next()) {
687     SALOMEDS::SComponent_var sco = itcomponent->Value();
688     CORBA::String_var compodatatype=sco->ComponentDataType();
689     MESSAGE ( "Look for an engine for data type :"<< compodatatype);
690     // if there is an associated Engine call its method for closing
691     CORBA::String_var IOREngine;
692     if (sco->ComponentIOR(IOREngine)) {
693       // we have found the associated engine to write the data 
694       MESSAGE ( "We have found an engine for data type :"<< compodatatype);
695       //_narrow can throw a corba exception
696       try
697         {
698           CORBA::Object_var obj = _orb->string_to_object(IOREngine);
699           if (!CORBA::is_nil(obj)) 
700             {
701               SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
702               if (!anEngine->_is_nil()) 
703                 { 
704                   SALOMEDS::unlock();
705                   anEngine->Close(sco);
706                   SALOMEDS::lock();
707                 }
708             }
709         } 
710       catch (CORBA::Exception&) 
711         {/*pass*/ }
712     }
713     sco->Destroy();
714   }
715
716   //Does not need any more this iterator
717   itcomponent->Destroy();
718
719
720   _impl->Close();
721 }
722
723 //============================================================================
724 /*! Function : AddPostponed
725  *  Purpose  : 
726  */
727  //============================================================================
728 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
729 {
730   SALOMEDS::Locker lock; 
731   //Not implemented
732 }
733
734 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
735 {
736   SALOMEDS::Locker lock; 
737   //Not implemented
738 }
739
740 //============================================================================
741 /*! Function : RemovePostponed
742  *  Purpose  : 
743  */
744 //============================================================================
745 #ifndef WIN32
746 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/) 
747 #else
748 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) 
749 #endif
750 {  
751   SALOMEDS::Locker lock; 
752
753   vector<string> anIORs = _impl->GetIORs();
754   int i, aSize = (int)anIORs.size();
755
756   for(i = 0; i < aSize; i++) {
757     try {
758       CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
759       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
760       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
761     } catch (...) {}
762   }
763
764   //Not implemented
765 }
766
767 //============================================================================
768 /*! Function : UndoPostponed
769  *  Purpose  : 
770  */
771 //============================================================================
772 #ifndef WIN32
773 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) 
774 #else
775 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
776 #endif
777 {
778   SALOMEDS::Locker lock; 
779   //Not implemented
780 }
781
782
783 //============================================================================
784 /*! Function : DumpStudy
785  *  Purpose  : 
786  */
787 //============================================================================
788 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
789                                            const char* theBaseName, 
790                                            CORBA::Boolean isPublished)
791 {
792   SALOMEDS::Locker lock; 
793
794   string aPath((char*)thePath), aBaseName((char*)theBaseName);
795   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
796   CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
797   delete factory;
798   return ret;
799 }
800
801 //============================================================================
802 /*! Function : GetCommonParameters
803  *  Purpose  : 
804  */
805 //============================================================================
806 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
807 {
808   SALOMEDS::Locker lock; 
809   
810   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
811   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
812   return SP->AttributeParameter::_this();
813 }
814  
815 //============================================================================
816 /*! Function : GetCommonModuleParameters
817  *  Purpose  : 
818  */
819 //============================================================================
820 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, 
821                                                                        const char* theModuleName, 
822                                                                        CORBA::Long theSavePoint)
823 {
824   SALOMEDS::Locker lock; 
825   
826   SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
827   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
828   return SP->AttributeParameter::_this();
829 }
830
831 //============================================================================
832 /*! Function : SetStudyLock
833  *  Purpose  : 
834  */
835 //============================================================================
836 void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
837 {
838   SALOMEDS::Locker lock; 
839   _impl->SetStudyLock(theLockerID);
840 }
841
842 //============================================================================
843 /*! Function : IsStudyLocked
844  *  Purpose  : 
845  */
846 //============================================================================
847 bool SALOMEDS_Study_i::IsStudyLocked()
848 {
849   SALOMEDS::Locker lock; 
850   return _impl->IsStudyLocked();
851 }
852
853 //============================================================================
854 /*! Function : UnLockStudy
855  *  Purpose  : 
856  */
857 //============================================================================
858 void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
859 {
860   SALOMEDS::Locker lock; 
861   _impl->UnLockStudy(theLockerID);
862 }
863
864 //============================================================================
865 /*! Function : GetLockerID
866  *  Purpose  : 
867  */
868 //============================================================================
869 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
870 {
871   SALOMEDS::Locker lock; 
872
873   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
874
875   vector<string> aSeq = _impl->GetLockerID();
876
877   int aLength = aSeq.size();
878   aResult->length(aLength);
879   for(int anIndex = 0; anIndex < aLength; anIndex++) {
880     aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
881   }
882   return aResult._retn();
883 }
884 //============================================================================
885 /*! Function : SetReal
886  *  Purpose  : 
887  */
888 //============================================================================
889 void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
890 {
891   _impl->SetVariable(string(theVarName), 
892                      theValue,
893                      SALOMEDSImpl_GenericVariable::REAL_VAR);
894 }
895
896 //============================================================================
897 /*! Function : SetInteger
898  *  Purpose  : 
899  */
900 //============================================================================
901 void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
902 {
903   _impl->SetVariable(string(theVarName), 
904                      theValue,
905                      SALOMEDSImpl_GenericVariable::INTEGER_VAR);
906 }
907
908 //============================================================================
909 /*! Function : SetBoolean
910  *  Purpose  : 
911  */
912 //============================================================================
913 void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
914 {
915   _impl->SetVariable(string(theVarName), 
916                      theValue,
917                      SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
918 }
919
920 //============================================================================
921 /*! Function : SetString
922  *  Purpose  : 
923  */
924 //============================================================================
925 void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue)
926 {
927   _impl->SetStringVariable(string(theVarName), 
928                            theValue,
929                            SALOMEDSImpl_GenericVariable::STRING_VAR);
930 }
931
932 //============================================================================
933 /*! Function : SetStringAsDouble
934  *  Purpose  : 
935  */
936 //============================================================================
937 void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue)
938 {
939   _impl->SetStringVariableAsDouble(string(theVarName), 
940                                    theValue,
941                                    SALOMEDSImpl_GenericVariable::STRING_VAR);
942 }
943
944 //============================================================================
945 /*! Function : GetReal
946  *  Purpose  : 
947  */
948 //============================================================================
949 CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
950 {
951   return _impl->GetVariableValue(string(theVarName));
952 }
953
954 //============================================================================
955 /*! Function : GetInteger
956  *  Purpose  : 
957  */
958 //============================================================================
959 CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
960 {
961   return (int)_impl->GetVariableValue(string(theVarName));
962 }
963
964 //============================================================================
965 /*! Function : GetBoolean
966  *  Purpose  : 
967  */
968 //============================================================================
969 CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
970 {
971   return (bool)_impl->GetVariableValue(string(theVarName));
972 }
973
974 //============================================================================
975 /*! Function : GetString
976  *  Purpose  : 
977  */
978 //============================================================================
979 char* SALOMEDS_Study_i::GetString(const char* theVarName)
980 {
981   return CORBA::string_dup(_impl->GetStringVariableValue(string(theVarName)).c_str());
982 }
983
984 //============================================================================
985 /*! Function : IsReal
986  *  Purpose  : 
987  */
988 //============================================================================
989 CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
990 {
991   return _impl->IsTypeOf(string(theVarName),
992                          SALOMEDSImpl_GenericVariable::REAL_VAR);
993 }
994
995 //============================================================================
996 /*! Function : IsInteger
997  *  Purpose  : 
998  */
999 //============================================================================
1000 CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
1001 {
1002   return _impl->IsTypeOf(string(theVarName),
1003                          SALOMEDSImpl_GenericVariable::INTEGER_VAR);
1004 }
1005
1006 //============================================================================
1007 /*! Function : IsBoolean
1008  *  Purpose  : 
1009  */
1010 //============================================================================
1011 CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
1012 {
1013   return _impl->IsTypeOf(string(theVarName),
1014                          SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
1015 }
1016
1017 //============================================================================
1018 /*! Function : IsString
1019  *  Purpose  : 
1020  */
1021 //============================================================================
1022 CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName)
1023 {
1024   return _impl->IsTypeOf(string(theVarName),
1025                          SALOMEDSImpl_GenericVariable::STRING_VAR);
1026 }
1027
1028 //============================================================================
1029 /*! Function : IsVariable
1030  *  Purpose  : 
1031  */
1032 //============================================================================
1033 CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
1034 {
1035   return _impl->IsVariable(string(theVarName));
1036 }
1037
1038 //============================================================================
1039 /*! Function : GetVariableNames
1040  *  Purpose  : 
1041  */
1042 //============================================================================
1043 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
1044 {
1045   vector<string> aVarNames = _impl->GetVariableNames();
1046   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
1047   
1048   int aLen = aVarNames.size();
1049   aResult->length(aLen);
1050   
1051   for (int anInd = 0; anInd < aLen; anInd++)
1052     aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1053   
1054   return aResult._retn();
1055 }
1056
1057 //============================================================================
1058 /*! Function : RemoveVariable
1059  *  Purpose  : 
1060  */
1061 //============================================================================
1062 CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
1063 {
1064   return _impl->RemoveVariable(string(theVarName));
1065 }
1066
1067 //============================================================================
1068 /*! Function : RenameVariable
1069  *  Purpose  : 
1070  */
1071 //============================================================================
1072 CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
1073 {
1074   return _impl->RenameVariable(string(theVarName), string(theNewVarName));
1075 }
1076
1077 //============================================================================
1078 /*! Function : IsVariableUsed
1079  *  Purpose  : 
1080  */
1081 //============================================================================
1082 CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
1083 {
1084   return _impl->IsVariableUsed(string(theVarName));
1085 }
1086
1087
1088 //============================================================================
1089 /*! Function : ParseVariables
1090  *  Purpose  : 
1091  */
1092 //============================================================================
1093 SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
1094 {
1095   vector< vector<string> > aSections = _impl->ParseVariables(string(theVarName));
1096
1097   SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
1098
1099   int aSectionsLen = aSections.size();
1100   aResult->length(aSectionsLen);
1101
1102   for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
1103     vector<string> aVarNames = aSections[aSectionInd];
1104
1105     SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
1106
1107     int aLen = aVarNames.size();
1108     aList->length(aLen);
1109
1110     for (int anInd = 0; anInd < aLen; anInd++)
1111       aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
1112
1113     aResult[aSectionInd] = aList;
1114   }
1115
1116   return aResult._retn();
1117 }
1118
1119 //============================================================================
1120 /*! Function : GetDefaultScript
1121  *  Purpose  : 
1122  */
1123 //============================================================================
1124 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
1125 {
1126   SALOMEDS::Locker lock; 
1127
1128   string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
1129   return CORBA::string_dup(script.c_str());
1130 }
1131
1132 //============================================================================
1133 /*! Function : EnableUseCaseAutoFilling
1134  *  Purpose  : 
1135  */
1136 //============================================================================
1137 void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) 
1138
1139   _impl->EnableUseCaseAutoFilling(isEnabled); 
1140   SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
1141   if(builder) {
1142     if(isEnabled) {
1143       builder->SetOnAddSObject(_impl->GetCallback());
1144       builder->SetOnRemoveSObject(_impl->GetCallback());
1145     }
1146     else {
1147       builder->SetOnAddSObject(NULL);
1148       builder->SetOnRemoveSObject(NULL);
1149     }
1150   }
1151 }
1152
1153 //===========================================================================
1154 //   PRIVATE FUNCTIONS
1155 //===========================================================================
1156 CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
1157 {
1158 #ifdef WIN32
1159   long pid = (long)_getpid();
1160 #else
1161   long pid = (long)getpid();
1162 #endif  
1163   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
1164   return reinterpret_cast<CORBA::LongLong>(_impl);
1165 }