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