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