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