Salome HOME
b36531420076f9da2bcf559004abcb31fcb631d3
[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   Handle(SALOMEDSImpl_SObject) aSO = _impl->CreateObjectID((char*)anObjectID);
198   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
199
200   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
201   return so._retn();
202 }
203
204 //============================================================================
205 /*! Function : FindObjectByName
206  *  Purpose  : Find Objects with SALOMEDS::Name = anObjectName in a Component
207  *           : with ComponentDataType = aComponentName
208  */
209 //============================================================================
210 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
211                                                                     const char* aComponentName )
212 {
213   SALOMEDS::Locker lock; 
214
215   Handle(TColStd_HSequenceOfTransient) aSeq = _impl->FindObjectByName(TCollection_AsciiString((char*)anObjectName),
216                                                                       TCollection_AsciiString((char*)aComponentName));
217   int aLength = aSeq->Length();
218   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
219   listSO->length(aLength);
220   for(int i = 1; i<=aLength; i++) {
221     Handle(SALOMEDSImpl_SObject) aSO = Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i));
222     SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
223     listSO[i-1] = so ;
224   }
225   return listSO._retn() ;
226 }
227
228 //============================================================================
229 /*! Function : FindObjectIOR
230  *  Purpose  : Find an Object with IOR = anObjectIOR
231  */
232 //============================================================================
233 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
234 {
235   SALOMEDS::Locker lock; 
236
237   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectIOR(TCollection_AsciiString((char*)anObjectIOR));
238   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
239
240   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
241   return so._retn();
242 }
243
244 //============================================================================
245 /*! Function : FindObjectByPath
246  *  Purpose  : Find an Object by its path = thePath
247  */
248 //============================================================================
249 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
250 {
251   SALOMEDS::Locker lock; 
252
253   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectByPath(TCollection_AsciiString((char*)thePath));
254   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
255
256   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
257   return so._retn();
258 }
259
260 //============================================================================
261 /*! Function : GetObjectPath
262  *  Purpose  : 
263  */
264 //============================================================================
265 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
266 {
267   SALOMEDS::Locker lock; 
268
269   TCollection_AsciiString aPath("");
270   if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.ToCString());
271   Handle(SALOMEDSImpl_SObject) aSO;
272   SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
273
274   if(!CORBA::is_nil(aSObj)) {
275     aSO = _impl->FindObjectID(aSObj->GetID());
276   }
277   else {
278     aSO  = _impl->FindObjectIOR(_orb->object_to_string(theObject));
279   }
280    
281   if(aSO.IsNull()) return CORBA::string_dup(aPath.ToCString());
282   
283   aPath = _impl->GetObjectPath(aSO);
284   return  CORBA::string_dup(aPath.ToCString());
285 }
286
287
288 //============================================================================
289 /*! Function : SetContext
290  *  Purpose  : Sets the current context
291  */
292 //============================================================================
293 void SALOMEDS_Study_i::SetContext(const char* thePath) 
294 {
295   SALOMEDS::Locker lock; 
296
297   _impl->SetContext(TCollection_AsciiString((char*)thePath));
298   if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
299     throw SALOMEDS::Study::StudyInvalidContext();  
300 }
301
302 //============================================================================
303 /*! Function : GetContext
304  *  Purpose  : Gets the current context
305  */
306 //============================================================================
307 char* SALOMEDS_Study_i::GetContext() 
308 {
309   SALOMEDS::Locker lock; 
310
311   if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
312   return CORBA::string_dup(_impl->GetContext().ToCString());
313 }
314
315 //============================================================================
316 /*! Function : GetObjectNames
317  *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
318  */
319 //============================================================================
320 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) 
321 {
322   SALOMEDS::Locker lock; 
323
324   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
325   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
326   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetObjectNames(TCollection_AsciiString((char*)theContext));
327   int aLength = aSeq->Length();
328   aResult->length(aLength);
329   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
330     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
331   }
332   return aResult._retn();
333 }
334
335 //============================================================================
336 /*! Function : GetDirectoryNames
337  *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
338  */
339 //============================================================================
340 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) 
341 {
342   SALOMEDS::Locker lock; 
343
344   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
345   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
346   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetDirectoryNames(TCollection_AsciiString((char*)theContext));
347   int aLength = aSeq->Length();
348   aResult->length(aLength);
349   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
350     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
351   }
352   return aResult._retn();
353 }
354
355 //============================================================================
356 /*! Function : GetFileNames
357  *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
358  */
359 //============================================================================
360 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) 
361 {
362   SALOMEDS::Locker lock; 
363
364   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
365   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
366   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetFileNames(TCollection_AsciiString((char*)theContext));
367   int aLength = aSeq->Length();
368   aResult->length(aLength);
369   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
370     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
371   }
372   return aResult._retn();
373 }
374
375 //============================================================================
376 /*! Function : GetComponentNames
377  *  Purpose  : method to get all components names
378  */
379 //============================================================================
380 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
381 {
382   SALOMEDS::Locker lock; 
383
384   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
385   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
386   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetComponentNames(TCollection_AsciiString((char*)theContext));
387   int aLength = aSeq->Length();
388   aResult->length(aLength);
389   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
390     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
391   }
392   return aResult._retn();
393 }
394
395 //============================================================================
396 /*! Function : NewChildIterator
397  *  Purpose  : Create a ChildIterator from an SObject
398  */
399 //============================================================================
400 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
401 {
402   SALOMEDS::Locker lock; 
403
404   Handle(SALOMEDSImpl_SObject) aSO = _impl->GetSObject(theSO->GetID());
405   Handle(SALOMEDSImpl_ChildIterator) anItr = new SALOMEDSImpl_ChildIterator(aSO);
406
407   //Create iterator
408   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
409   SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); 
410
411   return it;
412 }
413
414
415 //============================================================================
416 /*! Function : NewComponentIterator
417  *  Purpose  : Create a SComponentIterator
418  */
419 //============================================================================
420 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
421 {
422   SALOMEDS::Locker lock; 
423   SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
424   _it->Init();
425   return _it->_this();
426 }
427
428
429 //============================================================================
430 /*! Function : NewBuilder
431  *  Purpose  : Create a StudyBuilder
432  */
433 //============================================================================
434 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
435 {
436   SALOMEDS::Locker lock; 
437   return _builder->_this();
438 }
439  
440 //============================================================================
441 /*! Function : Name
442  *  Purpose  : get study name
443  */
444 //============================================================================
445 char* SALOMEDS_Study_i::Name()
446 {
447   SALOMEDS::Locker lock; 
448   return CORBA::string_dup(_impl->Name().ToCString());
449 }
450
451 //============================================================================
452 /*! Function : Name
453  *  Purpose  : set study name
454  */
455 //============================================================================
456 void SALOMEDS_Study_i::Name(const char* name)
457 {
458   SALOMEDS::Locker lock;  
459   _impl->Name(TCollection_AsciiString((char*)name));
460 }
461
462 //============================================================================
463 /*! Function : IsSaved
464  *  Purpose  : get if study has been saved
465  */
466 //============================================================================
467 CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
468 {
469   SALOMEDS::Locker lock; 
470   return _impl->IsSaved();
471 }
472
473 //============================================================================
474 /*! Function : IsSaved
475  *  Purpose  : set if study has been saved
476  */
477 //============================================================================
478 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
479 {
480   SALOMEDS::Locker lock; 
481   _impl->IsSaved(save);
482 }
483
484 //============================================================================
485 /*! Function : IsModified
486  *  Purpose  : Detect if a Study has been modified since it has been saved
487  */
488 //============================================================================
489 CORBA::Boolean  SALOMEDS_Study_i::IsModified()
490 {
491   SALOMEDS::Locker lock; 
492   return _impl->IsModified();
493 }
494
495 //============================================================================
496 /*! Function : URL
497  *  Purpose  : get URL of the study (persistent reference of the study)
498  */
499 //============================================================================
500 char* SALOMEDS_Study_i::URL()
501 {
502   SALOMEDS::Locker lock; 
503   return CORBA::string_dup(_impl->URL().ToCString());
504 }
505
506 //============================================================================
507 /*! Function : URL
508  *  Purpose  : set URL of the study (persistent reference of the study)
509  */
510 //============================================================================
511 void SALOMEDS_Study_i::URL(const char* url)
512 {
513   SALOMEDS::Locker lock; 
514   _impl->URL(TCollection_AsciiString((char*)url));
515 }
516
517
518 CORBA::Short SALOMEDS_Study_i::StudyId()
519 {
520   SALOMEDS::Locker lock; 
521   return _impl->StudyId();
522 }
523
524 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
525
526   SALOMEDS::Locker lock; 
527   _impl->StudyId(id);
528 }
529
530 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) 
531 {
532   SALOMEDS::Locker lock; 
533   _impl->UpdateIORLabelMap(TCollection_AsciiString((char*)anIOR), TCollection_AsciiString((char*)anEntry));
534 }
535
536 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb) 
537 {
538   SALOMEDS::Locker lock; 
539
540   Handle(SALOMEDSImpl_AttributeIOR) Att;
541   if (theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),Att)){
542     char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Value()).ToCString());
543     CORBA::Object_var obj = orb->string_to_object(IOR);
544     SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
545     ASSERT(!CORBA::is_nil(aStudy));
546     return SALOMEDS::Study::_duplicate(aStudy);
547   } else {
548     MESSAGE("GetStudy: Problem to get study");
549   }
550   return SALOMEDS::Study::_nil();
551 }
552
553 void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR) theAttribute) 
554 {
555   SALOMEDS::Locker lock; 
556   SALOMEDSImpl_Study::IORUpdated(theAttribute);
557 }
558
559 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) 
560 {
561   SALOMEDS::Locker lock; 
562
563   SALOMEDS::GenericAttribute_ptr aTarget;
564   if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
565     return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
566   }
567   SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
568   aList->length(0);
569   return aList;
570 }
571
572
573 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() 
574 {
575   SALOMEDS::Locker lock; 
576   
577   Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr = _impl->GetProperties();
578   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
579   return SP->AttributeStudyProperties::_this();
580 }
581
582 char* SALOMEDS_Study_i::GetLastModificationDate() 
583 {
584   SALOMEDS::Locker lock; 
585   return CORBA::string_dup(_impl->GetLastModificationDate().ToCString());
586 }
587
588 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
589 {
590   SALOMEDS::Locker lock; 
591   
592   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetModificationsDate();
593   int aLength = aSeq->Length();
594   SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
595   aDates->length(aLength);
596
597   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
598     aDates[anIndex-1] = CORBA::string_dup(aSeq->Value(anIndex).ToCString());
599   }
600   return aDates._retn();
601 }
602
603
604
605 //============================================================================
606 /*! Function : GetUseCaseBuilder
607  *  Purpose  : Returns a UseCase builder
608  */
609 //============================================================================
610 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
611 {
612   SALOMEDS::Locker lock; 
613   SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
614   return UCBuilder->_this();
615 }
616
617
618 //============================================================================
619 /*! Function : Close
620  *  Purpose  : 
621  */
622 //============================================================================
623 void SALOMEDS_Study_i::Close()
624 {
625   SALOMEDS::Locker lock; 
626   
627   RemovePostponed(-1);
628
629   SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
630
631   for (; itcomponent->More(); itcomponent->Next()) {
632     SALOMEDS::SComponent_var sco = itcomponent->Value();
633           
634     MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType());
635     // if there is an associated Engine call its method for closing
636     CORBA::String_var IOREngine;
637     if (sco->ComponentIOR(IOREngine)) {
638       // we have found the associated engine to write the data 
639       MESSAGE ( "We have found an engine for data type :"<< sco->ComponentDataType());
640       CORBA::Object_var obj = _orb->string_to_object(IOREngine);
641       if (!CORBA::is_nil(obj)) {
642         SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
643
644         if (!anEngine->_is_nil()) { 
645           SALOMEDS::unlock();
646           anEngine->Close(sco);
647           SALOMEDS::lock();
648         }
649       }
650     }
651   }
652   _impl->Close();
653 }
654
655 //============================================================================
656 /*! Function : AddPostponed
657  *  Purpose  : 
658  */
659  //============================================================================
660 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
661 {
662   SALOMEDS::Locker lock; 
663  
664   CORBA::Object_var obj = _orb->string_to_object(theIOR);
665   if (!CORBA::is_nil(obj)) {
666     SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
667     if (!CORBA::is_nil(aGeneric)) _impl->AddPostponed((char*)theIOR);     
668   }
669 }
670
671 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
672 {
673   SALOMEDS::Locker lock; 
674
675   CORBA::Object_var obj = _orb->string_to_object(theIOR);
676   if (!CORBA::is_nil(obj)) {
677     SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
678     if (!CORBA::is_nil(aGeneric)) _impl->AddCreatedPostponed((char*)theIOR);
679   }
680 }
681
682 //============================================================================
683 /*! Function : RemovePostponed
684  *  Purpose  : 
685  */
686 //============================================================================
687 #ifndef WNT
688 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) 
689 #else
690 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit) 
691 #endif
692 {  
693   SALOMEDS::Locker lock; 
694
695   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->RemovePostponed(theUndoLimit);
696   int aLegth = aSeq->Length();
697   for(int i = 1; i <= aLegth; i++) {
698     TCollection_AsciiString anIOR = aSeq->Value(i);
699     //mkr : fix for bug IPAL9408 : check the length of anIOR
700     //                             before take value from it
701     if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'c') {
702       CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
703       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
704       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
705     }
706     else if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'd') {
707       CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
708       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
709       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
710     }
711     else {
712       try {
713         CORBA::Object_var obj = _orb->string_to_object(anIOR.ToCString());
714         SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
715         if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
716       } catch (...) {}
717     }
718   }
719 }
720
721 //============================================================================
722 /*! Function : UndoPostponed
723  *  Purpose  : 
724  */
725 //============================================================================
726 #ifndef WNT
727 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) 
728 #else
729 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
730 #endif
731 {
732   SALOMEDS::Locker lock; 
733
734   _impl->UndoPostponed(theWay);
735 }
736
737
738 //============================================================================
739 /*! Function : DumpStudy
740  *  Purpose  : 
741  */
742 //============================================================================
743 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
744                                            const char* theBaseName, 
745                                            CORBA::Boolean isPublished)
746 {
747   SALOMEDS::Locker lock; 
748
749   TCollection_AsciiString aPath((char*)thePath), aBaseName((char*)theBaseName);
750   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
751   CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
752   delete factory;
753   return ret;
754 }
755
756 //============================================================================
757 /*! Function : GetCommonParameters
758  *  Purpose  : 
759  */
760 //============================================================================
761 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint)
762 {
763   SALOMEDS::Locker lock; 
764   
765   Handle(SALOMEDSImpl_AttributeParameter) anAttr = _impl->GetCommonParameters(theID, theSavePoint);
766   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
767   return SP->AttributeParameter::_this();
768 }
769  
770 //============================================================================
771 /*! Function : GetCommonModuleParameters
772  *  Purpose  : 
773  */
774 //============================================================================
775 SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, 
776                                                                        const char* theModuleName, 
777                                                                        CORBA::Long theSavePoint)
778 {
779   SALOMEDS::Locker lock; 
780   
781   Handle(SALOMEDSImpl_AttributeParameter) anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
782   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
783   return SP->AttributeParameter::_this();
784 }
785
786 //============================================================================
787 /*! Function : GetDefaultScript
788  *  Purpose  : 
789  */
790 //============================================================================
791 char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift)
792 {
793   SALOMEDS::Locker lock; 
794
795   string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift);
796   return CORBA::string_dup(script.c_str());
797 }
798
799 //===========================================================================
800 //   PRIVATE FUNCTIONS
801 //===========================================================================
802 CORBA::Long SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
803 {
804 #ifdef WIN32
805   long pid = (long)_getpid();
806 #else
807   long pid = (long)getpid();
808 #endif  
809   isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
810   SALOMEDSImpl_Study* local_impl = _impl.operator->();
811   return ((long)local_impl);
812 }