Salome HOME
This commit was generated by cvs2git to create branch 'WPdev'.
[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/
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_ChildIterator_i.hxx"
31 #include "SALOMEDS_Driver_i.hxx"
32 #include "SALOMEDS.hxx"
33
34 #include "SALOMEDSImpl_SObject.hxx"
35 #include "SALOMEDSImpl_SComponent.hxx"
36 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
37 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
38 #include "SALOMEDSImpl_ChildIterator.hxx"
39
40 #include <TColStd_SequenceOfExtendedString.hxx>
41 #include <TColStd_HSequenceOfAsciiString.hxx>
42 #include <TColStd_HSequenceOfTransient.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TCollection_ExtendedString.hxx>
45
46 #include <TDF_Label.hxx>
47 #include <TDF_Attribute.hxx>
48
49 #ifdef WIN32
50 #include <process.h>
51 #else
52 #include <sys/types.h>
53 #include <unistd.h>
54 #endif
55
56 #include "OpUtil.hxx"
57
58 using namespace std;
59
60 //============================================================================
61 /*! Function : SALOMEDS_Study_i
62  *  Purpose  : SALOMEDS_Study_i constructor
63  */
64 //============================================================================
65 SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(SALOMEDSImpl_Study) theImpl,
66                                    CORBA::ORB_ptr orb)
67 {
68   _orb = CORBA::ORB::_duplicate(orb);
69   _impl = theImpl;
70
71   _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);  
72 }
73   
74 //============================================================================
75 /*! Function : ~SALOMEDS_Study_i
76  *  Purpose  : SALOMEDS_Study_i destructor
77  */
78 //============================================================================
79 SALOMEDS_Study_i::~SALOMEDS_Study_i()
80 {
81 }  
82
83 //============================================================================
84 /*! Function : GetPersistentReference
85  *  Purpose  : Get persistent reference of study (idem URL())
86  */
87 //============================================================================
88 char* SALOMEDS_Study_i::GetPersistentReference()
89 {
90   SALOMEDS::Locker lock; 
91   return CORBA::string_dup(_impl->GetPersistentReference().ToCString());
92 }
93 //============================================================================
94 /*! Function : GetTransientReference
95  *  Purpose  : Get IOR of the Study (registred in OCAF document in doc->Root)
96  */
97 //============================================================================
98 char* SALOMEDS_Study_i::GetTransientReference()
99 {
100   SALOMEDS::Locker lock; 
101   return CORBA::string_dup(_impl->GetTransientReference().ToCString()); 
102 }
103
104 //============================================================================
105 /*! Function : IsEmpty
106  *  Purpose  : Detect if study is empty
107  */
108 //============================================================================
109 CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
110 {
111   SALOMEDS::Locker lock; 
112   return _impl->IsEmpty();
113 }
114
115 //============================================================================
116 /*! Function : FindComponent
117  *  Purpose  : Find a Component with ComponentDataType = aComponentName
118  */
119 //============================================================================
120 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
121 {
122   SALOMEDS::Locker lock; 
123   
124   Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponent(TCollection_AsciiString((char*)aComponentName));
125   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
126
127   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
128   return sco._retn();
129 }
130
131 //============================================================================
132 /*! Function : FindComponentID
133  *  Purpose  : Find a Component from it's ID
134  */
135 //============================================================================
136 SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID)
137 {
138   SALOMEDS::Locker lock; 
139   
140   Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponentID(TCollection_AsciiString((char*)aComponentID));
141   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
142
143   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
144   return sco._retn();
145 }
146
147 //============================================================================
148 /*! Function : FindObject
149  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
150  */
151 //============================================================================
152 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
153 {
154   SALOMEDS::Locker lock; 
155
156   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObject(TCollection_AsciiString((char*)anObjectName));
157   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
158
159   if(aSO->DynamicType() == STANDARD_TYPE(SALOMEDSImpl_SComponent)) {
160     Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO);
161     SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
162     return sco._retn();
163   }
164    
165   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
166  
167  return so._retn();
168 }
169
170 //============================================================================
171 /*! Function : FindObjectID
172  *  Purpose  : Find an Object with ID = anObjectID
173  */
174 //============================================================================
175 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
176 {
177   SALOMEDS::Locker lock; 
178
179   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectID(TCollection_AsciiString((char*)anObjectID));
180   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
181   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
182   return so._retn();
183 }
184
185 //============================================================================
186 /*! Function : CreateObjectID
187  *  Purpose  : Creates an Object with ID = anObjectID
188  */
189 //============================================================================
190 SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
191 {
192   SALOMEDS::Locker lock; 
193
194   Handle(SALOMEDSImpl_SObject) aSO = _impl->CreateObjectID((char*)anObjectID);
195   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
196
197   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
198   return so._retn();
199 }
200
201 //============================================================================
202 /*! Function : FindObjectByName
203  *  Purpose  : Find Objects with SALOMEDS::Name = anObjectName in a Component
204  *           : with ComponentDataType = aComponentName
205  */
206 //============================================================================
207 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
208                                                                     const char* aComponentName )
209 {
210   SALOMEDS::Locker lock; 
211
212   Handle(TColStd_HSequenceOfTransient) aSeq = _impl->FindObjectByName(TCollection_AsciiString((char*)anObjectName),
213                                                                       TCollection_AsciiString((char*)aComponentName));
214   int aLength = aSeq->Length();
215   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
216   listSO->length(aLength);
217   for(int i = 1; i<=aLength; i++) {
218     Handle(SALOMEDSImpl_SObject) aSO = Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i));
219     SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
220     listSO[i-1] = so ;
221   }
222   return listSO._retn() ;
223 }
224
225 //============================================================================
226 /*! Function : FindObjectIOR
227  *  Purpose  : Find an Object with IOR = anObjectIOR
228  */
229 //============================================================================
230 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
231 {
232   SALOMEDS::Locker lock; 
233
234   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectIOR(TCollection_AsciiString((char*)anObjectIOR));
235   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
236
237   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
238   return so._retn();
239 }
240
241 //============================================================================
242 /*! Function : FindObjectByPath
243  *  Purpose  : Find an Object by its path = thePath
244  */
245 //============================================================================
246 SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
247 {
248   SALOMEDS::Locker lock; 
249
250   Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectByPath(TCollection_AsciiString((char*)thePath));
251   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
252
253   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
254   return so._retn();
255 }
256
257 //============================================================================
258 /*! Function : GetObjectPath
259  *  Purpose  : 
260  */
261 //============================================================================
262 char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
263 {
264   SALOMEDS::Locker lock; 
265
266   TCollection_AsciiString aPath("");
267   if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.ToCString());
268   Handle(SALOMEDSImpl_SObject) aSO;
269   SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
270
271   if(!CORBA::is_nil(aSObj)) {
272     aSO = _impl->FindObjectID(aSObj->GetID());
273   }
274   else {
275     aSO  = _impl->FindObjectIOR(_orb->object_to_string(theObject));
276   }
277    
278   if(aSO.IsNull()) return CORBA::string_dup(aPath.ToCString());
279   
280   aPath = _impl->GetObjectPath(aSO);
281   return  CORBA::string_dup(aPath.ToCString());
282 }
283
284
285 //============================================================================
286 /*! Function : SetContext
287  *  Purpose  : Sets the current context
288  */
289 //============================================================================
290 void SALOMEDS_Study_i::SetContext(const char* thePath) 
291 {
292   SALOMEDS::Locker lock; 
293
294   _impl->SetContext(TCollection_AsciiString((char*)thePath));
295   if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
296     throw SALOMEDS::Study::StudyInvalidContext();  
297 }
298
299 //============================================================================
300 /*! Function : GetContext
301  *  Purpose  : Gets the current context
302  */
303 //============================================================================
304 char* SALOMEDS_Study_i::GetContext() 
305 {
306   SALOMEDS::Locker lock; 
307
308   if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
309   return CORBA::string_dup(_impl->GetContext().ToCString());
310 }
311
312 //============================================================================
313 /*! Function : GetObjectNames
314  *  Purpose  : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
315  */
316 //============================================================================
317 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) 
318 {
319   SALOMEDS::Locker lock; 
320
321   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
322   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
323   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetObjectNames(TCollection_AsciiString((char*)theContext));
324   int aLength = aSeq->Length();
325   aResult->length(aLength);
326   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
327     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
328   }
329   return aResult._retn();
330 }
331
332 //============================================================================
333 /*! Function : GetDirectoryNames
334  *  Purpose  : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
335  */
336 //============================================================================
337 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) 
338 {
339   SALOMEDS::Locker lock; 
340
341   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
342   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
343   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetDirectoryNames(TCollection_AsciiString((char*)theContext));
344   int aLength = aSeq->Length();
345   aResult->length(aLength);
346   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
347     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
348   }
349   return aResult._retn();
350 }
351
352 //============================================================================
353 /*! Function : GetFileNames
354  *  Purpose  : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
355  */
356 //============================================================================
357 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) 
358 {
359   SALOMEDS::Locker lock; 
360
361   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
362   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
363   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetFileNames(TCollection_AsciiString((char*)theContext));
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   return aResult._retn();
370 }
371
372 //============================================================================
373 /*! Function : GetComponentNames
374  *  Purpose  : method to get all components names
375  */
376 //============================================================================
377 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
378 {
379   SALOMEDS::Locker lock; 
380
381   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
382   if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
383   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetComponentNames(TCollection_AsciiString((char*)theContext));
384   int aLength = aSeq->Length();
385   aResult->length(aLength);
386   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
387     aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
388   }
389   return aResult._retn();
390 }
391
392 //============================================================================
393 /*! Function : NewChildIterator
394  *  Purpose  : Create a ChildIterator from an SObject
395  */
396 //============================================================================
397 SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO)
398 {
399   SALOMEDS::Locker lock; 
400
401   Handle(SALOMEDSImpl_SObject) aSO = _impl->GetSObject(theSO->GetID());
402   Handle(SALOMEDSImpl_ChildIterator) anItr = new SALOMEDSImpl_ChildIterator(aSO);
403
404   //Create iterator
405   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
406   SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); 
407
408   return it;
409 }
410
411
412 //============================================================================
413 /*! Function : NewComponentIterator
414  *  Purpose  : Create a SComponentIterator
415  */
416 //============================================================================
417 SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
418 {
419   SALOMEDS::Locker lock; 
420   SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb);
421   _it->Init();
422   return _it->_this();
423 }
424
425
426 //============================================================================
427 /*! Function : NewBuilder
428  *  Purpose  : Create a StudyBuilder
429  */
430 //============================================================================
431 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
432 {
433   SALOMEDS::Locker lock; 
434   return _builder->_this();
435 }
436  
437 //============================================================================
438 /*! Function : Name
439  *  Purpose  : get study name
440  */
441 //============================================================================
442 char* SALOMEDS_Study_i::Name()
443 {
444   SALOMEDS::Locker lock; 
445   return CORBA::string_dup(_impl->Name().ToCString());
446 }
447
448 //============================================================================
449 /*! Function : Name
450  *  Purpose  : set study name
451  */
452 //============================================================================
453 void SALOMEDS_Study_i::Name(const char* name)
454 {
455   SALOMEDS::Locker lock;  
456   _impl->Name(TCollection_AsciiString((char*)name));
457 }
458
459 //============================================================================
460 /*! Function : IsSaved
461  *  Purpose  : get if study has been saved
462  */
463 //============================================================================
464 CORBA::Boolean  SALOMEDS_Study_i::IsSaved()
465 {
466   SALOMEDS::Locker lock; 
467   return _impl->IsSaved();
468 }
469
470 //============================================================================
471 /*! Function : IsSaved
472  *  Purpose  : set if study has been saved
473  */
474 //============================================================================
475 void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save)
476 {
477   SALOMEDS::Locker lock; 
478   _impl->IsSaved(save);
479 }
480
481 //============================================================================
482 /*! Function : IsModified
483  *  Purpose  : Detect if a Study has been modified since it has been saved
484  */
485 //============================================================================
486 CORBA::Boolean  SALOMEDS_Study_i::IsModified()
487 {
488   SALOMEDS::Locker lock; 
489   return _impl->IsModified();
490 }
491
492 //============================================================================
493 /*! Function : URL
494  *  Purpose  : get URL of the study (persistent reference of the study)
495  */
496 //============================================================================
497 char* SALOMEDS_Study_i::URL()
498 {
499   SALOMEDS::Locker lock; 
500   return CORBA::string_dup(_impl->URL().ToCString());
501 }
502
503 //============================================================================
504 /*! Function : URL
505  *  Purpose  : set URL of the study (persistent reference of the study)
506  */
507 //============================================================================
508 void SALOMEDS_Study_i::URL(const char* url)
509 {
510   SALOMEDS::Locker lock; 
511   _impl->URL(TCollection_AsciiString((char*)url));
512 }
513
514
515 CORBA::Short SALOMEDS_Study_i::StudyId()
516 {
517   SALOMEDS::Locker lock; 
518   return _impl->StudyId();
519 }
520
521 void SALOMEDS_Study_i::StudyId(CORBA::Short id)
522
523   SALOMEDS::Locker lock; 
524   _impl->StudyId(id);
525 }
526
527 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) 
528 {
529   SALOMEDS::Locker lock; 
530   _impl->UpdateIORLabelMap(TCollection_AsciiString((char*)anIOR), TCollection_AsciiString((char*)anEntry));
531 }
532
533 SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb) 
534 {
535   SALOMEDS::Locker lock; 
536
537   Handle(SALOMEDSImpl_AttributeIOR) Att;
538   if (theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),Att)){
539     char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Value()).ToCString());
540     CORBA::Object_var obj = orb->string_to_object(IOR);
541     SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
542     ASSERT(!CORBA::is_nil(aStudy));
543     return SALOMEDS::Study::_duplicate(aStudy);
544   } else {
545     MESSAGE("GetStudy: Problem to get study");
546   }
547   return SALOMEDS::Study::_nil();
548 }
549
550 void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR) theAttribute) 
551 {
552   SALOMEDS::Locker lock; 
553   SALOMEDSImpl_Study::IORUpdated(theAttribute);
554 }
555
556 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) 
557 {
558   SALOMEDS::Locker lock; 
559
560   SALOMEDS::GenericAttribute_ptr aTarget;
561   if (anObject->FindAttribute(aTarget,"AttributeTarget")) {
562     return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get();
563   }
564   SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject;
565   aList->length(0);
566   return aList;
567 }
568
569
570 SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() 
571 {
572   SALOMEDS::Locker lock; 
573   
574   Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr = _impl->GetProperties();
575   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
576   return SP->AttributeStudyProperties::_this();
577 }
578
579 char* SALOMEDS_Study_i::GetLastModificationDate() 
580 {
581   SALOMEDS::Locker lock; 
582   return CORBA::string_dup(_impl->GetLastModificationDate().ToCString());
583 }
584
585 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
586 {
587   SALOMEDS::Locker lock; 
588   
589   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetModificationsDate();
590   int aLength = aSeq->Length();
591   SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
592   aDates->length(aLength);
593
594   for(int anIndex = 1; anIndex <= aLength; anIndex++) {
595     aDates[anIndex-1] = CORBA::string_dup(aSeq->Value(anIndex).ToCString());
596   }
597   return aDates._retn();
598 }
599
600
601
602 //============================================================================
603 /*! Function : GetUseCaseBuilder
604  *  Purpose  : Returns a UseCase builder
605  */
606 //============================================================================
607 SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() 
608 {
609   SALOMEDS::Locker lock; 
610   SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb);
611   return UCBuilder->_this();
612 }
613
614
615 //============================================================================
616 /*! Function : Close
617  *  Purpose  : 
618  */
619 //============================================================================
620 void SALOMEDS_Study_i::Close()
621 {
622   SALOMEDS::Locker lock; 
623   
624   RemovePostponed(-1);
625
626   SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
627
628   for (; itcomponent->More(); itcomponent->Next()) {
629     SALOMEDS::SComponent_var sco = itcomponent->Value();
630           
631     MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType());
632     // if there is an associated Engine call its method for closing
633     CORBA::String_var IOREngine;
634     if (sco->ComponentIOR(IOREngine)) {
635       // we have found the associated engine to write the data 
636       MESSAGE ( "We have found an engine for data type :"<< sco->ComponentDataType());
637       CORBA::Object_var obj = _orb->string_to_object(IOREngine);
638       if (!CORBA::is_nil(obj)) {
639         SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
640
641         if (!anEngine->_is_nil()) { 
642           SALOMEDS::unlock();
643           anEngine->Close(sco);
644           SALOMEDS::lock();
645         }
646       }
647     }
648   }
649   _impl->Close();
650 }
651
652 //============================================================================
653 /*! Function : AddPostponed
654  *  Purpose  : 
655  */
656  //============================================================================
657 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
658 {
659   SALOMEDS::Locker lock; 
660  
661   CORBA::Object_var obj = _orb->string_to_object(theIOR);
662   if (!CORBA::is_nil(obj)) {
663     SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
664     if (!CORBA::is_nil(aGeneric)) _impl->AddPostponed((char*)theIOR);     
665   }
666 }
667
668 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
669 {
670   SALOMEDS::Locker lock; 
671
672   CORBA::Object_var obj = _orb->string_to_object(theIOR);
673   if (!CORBA::is_nil(obj)) {
674     SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
675     if (!CORBA::is_nil(aGeneric)) _impl->AddCreatedPostponed((char*)theIOR);
676   }
677 }
678
679 //============================================================================
680 /*! Function : RemovePostponed
681  *  Purpose  : 
682  */
683 //============================================================================
684 #ifndef WNT
685 void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) 
686 #else
687 void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit) 
688 #endif
689 {  
690   SALOMEDS::Locker lock; 
691
692   Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->RemovePostponed(theUndoLimit);
693   int aLegth = aSeq->Length();
694   for(int i = 1; i <= aLegth; i++) {
695     TCollection_AsciiString anIOR = aSeq->Value(i);
696     //mkr : fix for bug IPAL9408 : check the length of anIOR
697     //                             before take value from it
698     if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'c') {
699       CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
700       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
701       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
702     }
703     else if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'd') {
704       CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
705       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
706       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
707     }
708     else {
709       try {
710         CORBA::Object_var obj = _orb->string_to_object(anIOR.ToCString());
711         SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
712         if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
713       } catch (...) {}
714     }
715   }
716 }
717
718 //============================================================================
719 /*! Function : UndoPostponed
720  *  Purpose  : 
721  */
722 //============================================================================
723 #ifndef WNT
724 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) 
725 #else
726 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
727 #endif
728 {
729   SALOMEDS::Locker lock; 
730
731   _impl->UndoPostponed(theWay);
732 }
733
734
735 //============================================================================
736 /*! Function : DumpStudy
737  *  Purpose  : 
738  */
739 //============================================================================
740 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished)
741 {
742   SALOMEDS::Locker lock; 
743
744   TCollection_AsciiString aPath((char*)thePath), aBaseName((char*)theBaseName);
745   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
746   CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
747   delete factory;
748   return ret;
749 }
750
751 //===========================================================================
752 //   PRIVATE FUNCTIONS
753 //===========================================================================
754 long SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
755 {
756 #ifdef WIN32
757   long pid = (long)_getpid();
758 #else
759   long pid = (long)getpid();
760 #endif  
761   isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
762   SALOMEDSImpl_Study* local_impl = _impl.operator->();
763   return ((long)local_impl);
764 }