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