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