Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / VISU_I / VISU_Gen_i.cc
1 //  Copyright (C) 2007-2010  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_Gen_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_ViewManager_i.hh"
31 #include "VISU_ResultUtils.hh"
32
33 #include "VISU_Prs3d_i.hh"
34 #include "VISU_Mesh_i.hh"
35 #include "VISU_Table_i.hh"
36 #include "VISU_PointMap3d_i.hh"
37 #include "VISU_TimeAnimation.h"
38 #include "VISU_Evolution.h"
39
40 #include "VISU_ColoredPrs3dFactory.hh"
41 #include "VISU_ColoredPrs3dCache_i.hh"
42 #include "VISU_ColoredPrs3dHolder_i.hh"
43
44 #include <VISU_Vtk2MedConvertor.hxx>
45
46 #include "VISU_Actor.h"
47
48 #include "HDFOI.hxx"
49 #include "HDFascii.hxx"
50 #include "SALOMEDS_Tool.hxx"
51
52 #include "SALOMEDSClient_AttributeName.hxx"
53 #include "SALOMEDSClient_AttributePixMap.hxx"
54
55 #include "SUIT_Session.h"
56 #include "SalomeApp_Study.h"
57 #include "SalomeApp_Application.h"
58 #include "LightApp_SelectionMgr.h"
59 #include "VTKViewer_MarkerUtils.h"
60 #include "SVTK_ViewModel.h"
61 #include "SVTK_ViewWindow.h"
62 #include "SALOME_Event.h"
63 #include "SALOME_ListIO.hxx"
64 #include "SALOME_ListIteratorOfListIO.hxx"
65
66 #include "utilities.h"
67
68 // IDL Headers
69 #include <omnithread.h>
70 #include CORBA_SERVER_HEADER(SALOME_Session)
71 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
72 #include CORBA_SERVER_HEADER(MED_Gen)
73
74 // QT Includes
75 #include <QDir>
76 #include <QFileInfo>
77
78 // VTK Includes
79 #include <vtkRenderer.h>
80 #include <vtkActorCollection.h>
81
82 // OCCT Includes
83 #include <TCollection_AsciiString.hxx>
84 #include <TColStd_SequenceOfAsciiString.hxx>
85
86 #include "Utils_ExceptHandlers.hxx"
87 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
88
89 // STL Includes
90 #include <sstream>
91
92 #include <boost/filesystem/path.hpp>
93 #include <boost/filesystem/operations.hpp>
94 namespace filesystem = boost::filesystem;
95
96
97 #ifdef _DEBUG_
98 static int MYDEBUG = 0;
99 #else
100 static int MYDEBUG = 0;
101 #endif
102
103 using namespace std;
104
105 extern "C"
106 VISU_I_EXPORT VISU::VISU_Gen_ptr
107 GetImpl(CORBA::ORB_ptr theORB,
108         PortableServer::POA_ptr thePOA,
109         SALOME_NamingService* theNamingService,
110         QMutex* theMutex)
111 {
112   if(MYDEBUG) MESSAGE("extern 'C' GetImpl");
113   VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
114   //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
115   return aVISU_Gen->_this();
116 }
117
118 namespace VISU
119 {
120   //----------------------------------------------------------------------------
121   static std::string VISU_TMP_DIR;
122
123   static CORBA::Boolean myIsMultiFile;
124   const CORBA::Boolean IsMultiFile()
125   {
126     return myIsMultiFile;
127   }
128
129   //----------------------------------------------------------------------------
130   _PTR(SComponent)
131   ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
132   {
133     _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
134     if (!aSComponent) {
135       _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
136       aStudyBuilder->NewCommand();
137       int aLocked = theStudyDocument->GetProperties()->IsLocked();
138       if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
139       aSComponent = aStudyBuilder->NewComponent("VISU");
140       _PTR(GenericAttribute) anAttr =
141         aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
142       _PTR(AttributeName) aName (anAttr);
143
144       CORBA::ORB_var anORB = Base_i::GetORB();
145       SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
146       CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
147       SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
148         SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
149       SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
150       if (!Comp->_is_nil()) {
151         aName->SetValue(Comp->componentusername());
152       }
153
154       anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
155       _PTR(AttributePixMap) aPixmap (anAttr);
156       aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
157
158       VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
159       aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
160       if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
161       aStudyBuilder->CommitCommand();
162     }
163     return aSComponent;
164   }
165
166
167   //----------------------------------------------------------------------------
168   SALOMEDS::SComponent_var
169   FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument)
170   {
171     SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
172     if (aSComponent->_is_nil()) {
173       SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
174       aStudyBuilder->NewCommand();
175       int aLocked = theStudyDocument->GetProperties()->IsLocked();
176       if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
177       aSComponent = aStudyBuilder->NewComponent("VISU");
178       SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
179       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
180
181       //NRI      aName->SetValue("Visu");
182       CORBA::ORB_var anORB = Base_i::GetORB();
183       SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
184       CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
185       SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
186       SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
187       if ( !Comp->_is_nil() ) {
188         aName->SetValue( Comp->componentusername() );
189       }
190
191       anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
192       SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
193       aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
194
195       VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
196       aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
197       if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
198       aStudyBuilder->CommitCommand();
199     }
200     return aSComponent;
201   }
202
203
204   //----------------------------------------------------------------------------
205   void
206   RegistryStorable()
207   {
208     Storable::RegistryStorableEngine(Result_i::myComment.c_str(),&(Result_i::StorableEngine));
209
210     Storable::RegistryStorableEngine(Mesh_i::myComment.c_str(),&(Mesh_i::StorableEngine));
211
212     Storable::RegistryStorableEngine(ScalarMap_i::myComment.c_str(),&(StorableEngine<ScalarMap_i>));
213     Storable::RegistryStorableEngine(GaussPoints_i::myComment.c_str(),&(StorableEngine<GaussPoints_i>));
214     Storable::RegistryStorableEngine(DeformedShape_i::myComment.c_str(),&(StorableEngine<DeformedShape_i>));
215     Storable::RegistryStorableEngine(CutPlanes_i::myComment.c_str(),&(StorableEngine<CutPlanes_i>));
216     Storable::RegistryStorableEngine(CutLines_i::myComment.c_str(),&(StorableEngine<CutLines_i>));
217     Storable::RegistryStorableEngine(CutSegment_i::myComment.c_str(),&(StorableEngine<CutSegment_i>));
218     Storable::RegistryStorableEngine(IsoSurfaces_i::myComment.c_str(),&(StorableEngine<IsoSurfaces_i>));
219     Storable::RegistryStorableEngine(StreamLines_i::myComment.c_str(),&(StorableEngine<StreamLines_i>));
220     Storable::RegistryStorableEngine(Plot3D_i::myComment.c_str(),&(StorableEngine<Plot3D_i>));
221     Storable::RegistryStorableEngine(Vectors_i::myComment.c_str(),&(StorableEngine<Vectors_i>));
222     Storable::RegistryStorableEngine(DeformedShapeAndScalarMap_i::myComment.c_str(),&(StorableEngine<DeformedShapeAndScalarMap_i>));
223
224     Storable::RegistryStorableEngine(ColoredPrs3dHolder_i::myComment.c_str(),&(ColoredPrs3dHolder_i::StorableEngine));
225     Storable::RegistryStorableEngine(ColoredPrs3dCache_i::myComment.c_str(),&(ColoredPrs3dCache_i::StorableEngine));
226
227     Storable::RegistryStorableEngine(PointMap3d_i::myComment.c_str(),&(PointMap3d_i::StorableEngine));
228     Storable::RegistryStorableEngine(Table_i::myComment.c_str(),&(Table_i::StorableEngine));
229     Storable::RegistryStorableEngine(Curve_i::myComment.c_str(),&(Curve_i::StorableEngine));
230     Storable::RegistryStorableEngine(Container_i::myComment.c_str(),&(Container_i::StorableEngine));
231   }
232
233
234   //----------------------------------------------------------------------------
235   SALOMEDS::ListOfFileNames*
236   GetListOfFileNames(const Result_i::TFileNames& theFileNames)
237   {
238     SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
239     if(!theFileNames.empty()){
240       aListOfFileNames->length(theFileNames.size());
241       for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
242         aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
243     }
244     return aListOfFileNames._retn();
245   }
246
247
248   //----------------------------------------------------------------------------
249   bool
250   LoadMarkerMap(SALOMEDS::Study_ptr theStudy,
251                 const char* theURL,
252                 bool theIsMultiFile,
253                 bool theIsASCII,
254                 StudyId2MarkerMap& theStudyId2MarkerMap,
255                 std::string& theMarkerMapFileName,
256                 std::string& theMarkerMapFile)
257   {
258     std::string aPrefix;
259     if( theIsMultiFile ) {
260       CORBA::String_var anURL = theStudy->URL();
261       aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
262     }
263
264     theMarkerMapFileName = aPrefix + "_textures";
265     theMarkerMapFile = VISU_TMP_DIR + theMarkerMapFileName;
266
267     if( theIsASCII && !HDFascii::ConvertFromASCIIToHDF( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
268       return false;
269
270     HDFfile*    aFile;
271     HDFdataset* aDataset;
272     HDFgroup*   aTopGroup;
273     HDFgroup*   aGroup;
274     HDFgroup*   aSubGroup;
275     HDFgroup*   aSubSubGroup;
276     int         aSize;
277
278     aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
279     try {
280       aFile->OpenOnDisk( HDF_RDONLY );
281     }
282     catch ( HDFexception ) {
283       INFOS( "Load(): " << theMarkerMapFile << " not found!" );
284       return false;
285     }
286
287     VTK::MarkerMap& aMarkerMap = theStudyId2MarkerMap[ theStudy->StudyId() ];
288
289     for( int i = 0, n = aFile->nInternalObjects(); i < n; i++ ) {
290       char markerGrpName[ HDF_NAME_MAX_LEN+1 ];
291       aFile->InternalObjectIndentify( i, markerGrpName );
292
293       int aMarkerId = 0;
294       std::string aMarkerFile;
295       VTK::MarkerTexture aMarkerTexture;
296
297       if( string( markerGrpName ).substr( 0, 6 ) == string( "Marker" ) ) {
298         aTopGroup = new HDFgroup( markerGrpName, aFile );
299         aTopGroup->OpenOnDisk();
300
301         aMarkerId = atoi( string( markerGrpName ).substr( 6 ).c_str() );
302         if( aMarkerId < 1 )
303           continue;
304
305         if( aTopGroup->ExistInternalObject( "File" ) ) {
306           aDataset = new HDFdataset( "File", aTopGroup );
307           aDataset->OpenOnDisk();
308           aSize = aDataset->GetSize();
309           char* aFileName = new char[ aSize ];
310           aDataset->ReadFromDisk( aFileName );
311           aMarkerFile = aFileName;
312           delete [] aFileName;
313           aDataset->CloseOnDisk();
314         }
315
316         if( aTopGroup->ExistInternalObject( "Texture" ) ) {
317           aDataset = new HDFdataset( "Texture", aTopGroup );
318           aDataset->OpenOnDisk();
319           aSize = aDataset->GetSize();
320           int* aTextureData = new int[ aSize ];
321           aDataset->ReadFromDisk( aTextureData );
322           for( int j = 0; j < aSize; j++ )
323             aMarkerTexture.push_back( aTextureData[j] );
324           delete [] aTextureData;
325           aDataset->CloseOnDisk();
326         }
327
328         aTopGroup->CloseOnDisk();
329       }
330
331       if( aMarkerId > 0 )
332         aMarkerMap[ aMarkerId ] = VTK::MarkerData( aMarkerFile, aMarkerTexture );
333     }
334
335     aFile->CloseOnDisk();
336     delete aFile;
337
338     return true;
339   }
340
341   //----------------------------------------------------------------------------
342   bool
343   SaveMarkerMap(SALOMEDS::Study_ptr theStudy,
344                 const char* theURL,
345                 bool theIsMultiFile,
346                 bool theIsASCII,
347                 const StudyId2MarkerMap& theStudyId2MarkerMap,
348                 std::string& theMarkerMapFileName,
349                 std::string& theMarkerMapFile)
350   {
351     VISU::StudyId2MarkerMap::const_iterator aMainIter = theStudyId2MarkerMap.find( theStudy->StudyId() );
352     if( aMainIter == theStudyId2MarkerMap.end() )
353       return false;
354
355     const VTK::MarkerMap& aMarkerMap = aMainIter->second;
356     if( aMarkerMap.empty() )
357       return false;
358
359     std::string aPrefix;
360     if( theIsMultiFile ) {
361       CORBA::String_var anURL = theStudy->URL();
362       aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
363     }
364
365     theMarkerMapFileName = aPrefix + "_textures";
366     theMarkerMapFile = string( theURL ) + theMarkerMapFileName;
367
368     HDFfile*    aFile;
369     HDFdataset* aDataset;
370     HDFgroup*   aTopGroup;
371     HDFgroup*   aGroup;
372     HDFgroup*   aSubGroup;
373     HDFgroup*   aSubSubGroup;
374     hdf_size    aSize[ 1 ];
375
376     aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
377     aFile->CreateOnDisk();
378
379     VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
380     for( ; aMarkerIter != aMarkerMap.end(); aMarkerIter++ ) {
381       int aMarkerId = aMarkerIter->first;
382       const VTK::MarkerData& aMarkerData = aMarkerIter->second;
383       std::string aMarkerFile = aMarkerData.first;
384       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
385
386       char markerGrpName[30];
387       sprintf( markerGrpName, "Marker %d", aMarkerId );
388       aTopGroup = new HDFgroup( markerGrpName, aFile );
389
390       aTopGroup->CreateOnDisk();
391
392       aSize[ 0 ] = aMarkerFile.length() + 1;
393       aDataset = new HDFdataset( "File", aTopGroup, HDF_STRING, aSize, 1 );
394       aDataset->CreateOnDisk();
395       aDataset->WriteOnDisk( ( char* )( aMarkerFile.c_str() ) );
396       aDataset->CloseOnDisk();
397
398       int* aTextureData = new int[ aMarkerTexture.size() ];
399       VTK::MarkerTexture::const_iterator anIter = aMarkerTexture.begin();
400       for( int i = 0; anIter != aMarkerTexture.end(); anIter++, i++ )
401         aTextureData[i] = *anIter;
402
403       aSize[0] = aMarkerTexture.size();
404       aDataset = new HDFdataset( "Texture", aTopGroup, HDF_INT32, aSize, 1 );
405       aDataset->CreateOnDisk();
406       aDataset->WriteOnDisk( aTextureData );
407       aDataset->CloseOnDisk();
408       delete [] aTextureData;
409
410       aTopGroup->CloseOnDisk();
411     }
412
413     aFile->CloseOnDisk();
414     delete aFile;
415
416     if( theIsASCII && !HDFascii::ConvertFromHDFToASCII( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
417       return false;
418
419     return true;
420   }
421
422
423   //----------------------------------------------------------------------------
424   VISU_Gen_i
425   ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
426                SALOME_NamingService* theNamingService, QMutex* theMutex) :
427     Engines_Component_i()
428   {
429     if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
430     Base_i::myMutex = theMutex;  //apo
431     Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
432     Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
433     Base_i::myNamingService = theNamingService;
434     static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
435     Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
436     Base_i::myVisuGenImpl = this;
437     RegistryStorable();
438
439     CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
440     SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
441     SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
442     if(aListOfOpenStudies->length() > 0) {
443       CORBA::String_var aStudyName = aListOfOpenStudies[0];
444       //aFileInfo.setFile(aStudyName.in());
445       myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
446       myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
447     }else
448       if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
449   }
450
451
452   //----------------------------------------------------------------------------
453   Prs3d_ptr
454   VISU_Gen_i
455   ::CreatePrs3d(VISUType theType,
456                 SALOMEDS::Study_ptr theStudy)
457   {
458     if(ColoredPrs3d_i* aPrs3d = CreatePrs3d_i(theType, theStudy, ColoredPrs3d_i::EPublishIndependently))
459       return aPrs3d->_this();
460     return Prs3d::_nil();
461   }
462
463
464   //----------------------------------------------------------------------------
465   VISU_Gen_i
466   ::~VISU_Gen_i()
467   {
468     if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
469   }
470
471
472   //----------------------------------------------------------------------------
473   void
474   CorrectSObjectType(SALOMEDS::SObject_ptr theSObject,
475                      SALOMEDS::StudyBuilder_ptr theBuilder)
476   {
477     SALOMEDS::GenericAttribute_var anAttr;
478     bool isAttrStringFound = false;
479
480     if( theSObject->FindAttribute(anAttr, "AttributeComment") ) {
481       //SRN: Replace an AttributeComment with AttributeString
482       SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
483       string aValue = aComment->Value();
484       theBuilder->RemoveAttribute(theSObject, "AttributeComment");
485       anAttr = theBuilder->FindOrCreateAttribute(theSObject, "AttributeString");
486       SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
487       aStringAttr->SetValue(aValue.c_str());
488       isAttrStringFound = true;
489     }
490
491     if ( isAttrStringFound || theSObject->FindAttribute(anAttr, "AttributeString") ) {
492       SALOMEDS::AttributeString_var aAttComment = SALOMEDS::AttributeString::_narrow(anAttr);
493       if ( aAttComment ) {
494         CORBA::String_var aValue = aAttComment->Value();
495         std::string aString = Storable::CorrectPersistentString(aValue.in());
496         aAttComment->SetValue( aString.c_str() );
497       }
498     }
499   }
500
501
502   //----------------------------------------------------------------------------
503   CORBA::Boolean
504   LoadWithMarkerMap(SALOMEDS::SComponent_ptr theComponent,
505                     const SALOMEDS::TMPFile & theStream,
506                     const char* theURL,
507                     CORBA::Boolean theIsMultiFile,
508                     CORBA::Boolean theIsASCII,
509                     StudyId2MarkerMap& theStudyId2MarkerMap)
510   {
511     SALOMEDS::Study_var aStudy = theComponent->GetStudy();
512
513     SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
514     SALOMEDS::StudyBuilder_var  aStudyBuilder = aStudy->NewBuilder();
515
516     for (anIter->InitEx(true); anIter->More(); anIter->Next()) {
517       SALOMEDS::SObject_var aSObject = anIter->Value();
518       CorrectSObjectType(aSObject, aStudyBuilder);
519     }
520
521     VISU_TMP_DIR = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
522     SALOMEDS::ListOfFileNames_var aSeq =
523       SALOMEDS_Tool::PutStreamToFiles(theStream, VISU_TMP_DIR, theIsMultiFile);
524     myIsMultiFile = theIsMultiFile;
525
526     // load textures of custom point markers
527     Result_i::TFileNames aTMPFileNames;
528     std::string aMarkerMapFileName, aMarkerMapFile;
529     if( LoadMarkerMap( aStudy, theURL, theIsMultiFile, theIsASCII,
530                        theStudyId2MarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
531       aTMPFileNames.push_back( aMarkerMapFileName );
532     }
533
534     if(!theIsMultiFile && !aTMPFileNames.empty()) {
535       SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
536       SALOMEDS_Tool::RemoveTemporaryFiles(VISU_TMP_DIR, aListOfTMPFileNames, true );
537     }
538
539     return true;
540   }
541
542
543   //----------------------------------------------------------------------------
544   CORBA::Boolean
545   VISU_Gen_i
546   ::Load(SALOMEDS::SComponent_ptr theComponent,
547          const SALOMEDS::TMPFile & theStream,
548          const char* theURL,
549          CORBA::Boolean theIsMultiFile)
550   {
551     Mutex mt(myMutex);
552     return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, false, myMarkerMap);
553   }
554
555
556   //----------------------------------------------------------------------------
557   CORBA::Boolean
558   VISU_Gen_i
559   ::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
560               const SALOMEDS::TMPFile & theStream,
561               const char* theURL,
562               bool theIsMultiFile)
563   {
564     Mutex mt(myMutex);
565     return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, true, myMarkerMap);
566   }
567
568
569   //----------------------------------------------------------------------------
570   char*
571   VISU_Gen_i
572   ::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
573                            const char* theLocalPersistentID,
574                            CORBA::Boolean theIsMultiFile,
575                            CORBA::Boolean theIsASCII)
576   {
577     CORBA::String_var aString("");
578     if(strcmp(theLocalPersistentID,"") != 0) {
579       Storable* aStorable = Storable::Create(theSObject,
580                                              theLocalPersistentID,
581                                              VISU_TMP_DIR,
582                                              theIsMultiFile);
583       if(aStorable != NULL)
584         aString = aStorable->GetID();
585     }
586     return aString._retn();
587   }
588
589
590   //----------------------------------------------------------------------------
591   SALOMEDS::TMPFile*
592   VISU_Gen_i
593   ::Save(SALOMEDS::SComponent_ptr theComponent,
594          const char* theURL,
595          bool theIsMultiFile)
596   {
597     if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
598
599     Result_i::TFileNames aFileNames;
600     Result_i::TFileNames aFiles;
601
602     SALOMEDS::Study_var aStudy = theComponent->GetStudy();
603     SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
604     for (; anIter->More(); anIter->Next()) {
605       SALOMEDS::SObject_var aSObject = anIter->Value();
606       CORBA::Object_var anObj = SObjectToObject(aSObject);
607       if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
608         aResult->Save(theComponent,
609                       theURL,
610                       theIsMultiFile,
611                       false,
612                       aFileNames,
613                       aFiles);
614       }
615     }
616     if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
617
618     // save textures of custom point markers
619     Result_i::TFileNames aTMPFileNames;
620     std::string aMarkerMapFileName, aMarkerMapFile;
621     if( SaveMarkerMap( aStudy, theURL, theIsMultiFile, false,
622                        myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
623       aTMPFileNames.push_back( aMarkerMapFileName );
624       aFileNames.push_back( aMarkerMapFileName );
625       aFiles.push_back( aMarkerMapFile );
626     }
627
628     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
629     if(aFileNames.empty())
630       return aStreamFile._retn();
631
632     SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
633     SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
634
635     if(theIsMultiFile)
636       aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
637     else
638       aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
639
640     if(!theIsMultiFile && !aTMPFileNames.empty()) {
641       SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
642       SALOMEDS_Tool::RemoveTemporaryFiles(theURL, aListOfTMPFileNames, true);
643     }
644
645     return aStreamFile._retn();
646   }
647
648
649   //----------------------------------------------------------------------------
650   SALOMEDS::TMPFile*
651   VISU_Gen_i
652   ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
653               const char* theURL,
654               bool theIsMultiFile)
655   {
656     std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
657     if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
658
659     Result_i::TFileNames aFileNames;
660     Result_i::TFileNames aFiles;
661
662     SALOMEDS::Study_var aStudy = theComponent->GetStudy();
663     SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
664     for (; anIter->More(); anIter->Next()) {
665       SALOMEDS::SObject_var aSObject = anIter->Value();
666       CORBA::Object_var anObj = SObjectToObject(aSObject);
667       if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
668         aResult->Save(theComponent,
669                       anURL,
670                       theIsMultiFile,
671                       true,
672                       aFileNames,
673                       aFiles);
674       }
675     }
676     if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
677
678     // save textures of custom point markers
679     std::string aMarkerMapFileName, aMarkerMapFile;
680     if( SaveMarkerMap( aStudy, anURL.c_str(), theIsMultiFile, true,
681                        myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
682       aFileNames.push_back( aMarkerMapFileName );
683       aFiles.push_back( aMarkerMapFile );
684     }
685
686     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
687     if(aFileNames.empty())
688       return aStreamFile._retn();
689
690     SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
691     aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
692
693     if(!theIsMultiFile)
694       SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
695
696     return aStreamFile._retn();
697   }
698
699
700   //----------------------------------------------------------------------------
701   char*
702   VISU_Gen_i
703   ::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
704                            const char* theIORString,
705                            CORBA::Boolean theIsMultiFile,
706                            CORBA::Boolean theIsASCII)
707   {
708     CORBA::String_var aString("");
709     if(strcmp(theIORString, "") != 0){
710       CORBA::Object_var anObj = GetORB()->string_to_object(theIORString);
711       if(Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
712         aString = aStorable->ToString().c_str();
713         return aString._retn();
714       }
715     }
716     return aString._retn();
717   }
718
719
720   //----------------------------------------------------------------------------
721   char*
722   VISU_Gen_i
723   ::GetID()
724   {
725     return Base_i::GetID();
726   }
727
728
729   //----------------------------------------------------------------------------
730   void
731   VISU_Gen_i
732   ::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
733   {
734     class TEvent: public SALOME_Event {
735       std::string myStudyName;
736     public:
737       TEvent(const std::string theStudyName):myStudyName(theStudyName)
738         {}
739       virtual void Execute()
740         {
741           bool isActive = false;
742           SUIT_Session* aSession = SUIT_Session::session();
743           QList<SUIT_Application*> anApplications = aSession->applications();
744           QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
745           SUIT_Application* aFirstApp = *anIter;
746           while (anIter != anApplications.end()) {
747             SUIT_Application* anApp = *anIter;
748             if (SUIT_Study* aSStudy = anApp->activeStudy()) {
749               if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
750                 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
751                   if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
752                                       << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
753                   if (myStudyName == aCStudy->Name()) {
754                     isActive = true;
755                     break;
756                   }
757                 }
758               }
759             }
760             anIter++;
761           }
762           if (!isActive) {
763             MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
764             // Has to be loaded in an empty or in a new application
765             SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
766             anApp->onLoadDoc(myStudyName.c_str());
767           }
768         }
769     };
770
771     if (!CORBA::is_nil(theStudy))
772     {
773       CORBA::String_var aName = theStudy->Name();
774       std::string aStudyName (aName.in());
775       if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
776       myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
777       myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
778
779       ProcessVoidEvent(new TEvent(aStudyName));
780
781       // Load MED component if necessary
782       if(!myStudyDocument->FindComponent("MED")->_is_nil())
783         {
784           SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
785           Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
786           SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow(aComponent);
787
788           if(!CORBA::is_nil(aMedEngine))
789             {
790               SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
791               try {
792                 aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine );
793               }
794               catch( const SALOME::SALOME_Exception& ) {
795                 // Oops, something went wrong while loading
796                 // See also SalomeApp_Study::openDataModel()
797               }
798             }
799         }
800     } else {
801       INFOS("CORBA::is_nil(theStudy)");
802     }
803   }
804
805
806   //----------------------------------------------------------------------------
807   SALOMEDS::Study_ptr
808   VISU_Gen_i
809   ::GetCurrentStudy()
810   {
811     return SALOMEDS::Study::_duplicate(myStudyDocument);
812   }
813
814
815   //----------------------------------------------------------------------------
816   ViewManager_ptr
817   VISU_Gen_i
818   ::GetViewManager()
819   {
820     Mutex mt(myMutex);
821     ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
822     return ViewManager::_duplicate(aViewManager->_this());
823   }
824
825
826   //----------------------------------------------------------------------------
827   SALOMEDS::SObject_ptr
828   VISU_Gen_i
829   ::ImportTables(const char* theFileName, bool theFirstStrAsTitle)
830   {
831     if(myStudyDocument->GetProperties()->IsLocked())
832       return SALOMEDS::SObject::_nil();
833
834     SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument,
835                                                     theFirstStrAsTitle);
836
837     SALOMEDS::Study_var aStudy = aRes->GetStudy();
838     SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aRes);
839     for (; anIter->More(); anIter->Next()) {
840       SALOMEDS::SObject_var SO = anIter->Value();
841       CreateTable( SO->GetID() );
842     }
843
844     bool isDone;
845     ProcessVoidEvent(new TUpdateObjBrowser(aStudy->StudyId(),&isDone));
846
847     return aRes._retn();
848   }
849
850
851   //----------------------------------------------------------------------------
852   CORBA::Boolean
853   VISU_Gen_i
854   ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
855                       const char* theFileName)
856   {
857     return VISU::ExportTableToFile(theTable, theFileName);
858   }
859
860
861   //----------------------------------------------------------------------------
862   Result_ptr
863   VISU_Gen_i
864   ::ImportFile(const char* theFileName)
865   {
866     if(myStudyDocument->GetProperties()->IsLocked())
867       return Result::_nil();
868
869     Result_i* aResult = Result_i::New(myStudyDocument,
870                                       Result_i::eFile,
871                                       Result_i::eImportFile,
872                                       true,
873                                       true,
874                                       true,
875                                       true);
876
877     if(aResult->Create(theFileName) != NULL)
878       return aResult->_this();
879     else
880       aResult->_remove_ref();
881
882     return VISU::Result::_nil();
883   }
884
885
886   //----------------------------------------------------------------------------
887   Result_ptr
888   VISU_Gen_i
889   ::CreateResult(const char* theFileName)
890   {
891     if(myStudyDocument->GetProperties()->IsLocked())
892       return Result::_nil();
893
894     Result_i* aResult = Result_i::New(myStudyDocument,
895                                       Result_i::eFile,
896                                       Result_i::eImportFile,
897                                       false,
898                                       true,
899                                       true,
900                                       true);
901
902     if(aResult->Create(theFileName) != NULL)
903       return aResult->_this();
904     else
905       aResult->_remove_ref();
906
907     return VISU::Result::_nil();
908   }
909
910
911   //----------------------------------------------------------------------------
912   Result_ptr
913   VISU_Gen_i
914   ::CopyAndImportFile(const char* theFileName)
915   {
916     if(myStudyDocument->GetProperties()->IsLocked())
917       return Result::_nil();
918
919     Result_i* aResult = Result_i::New(myStudyDocument,
920                                       Result_i::eRestoredFile,
921                                       Result_i::eCopyAndImportFile,
922                                       true,
923                                       true,
924                                       true,
925                                       true);
926     if(aResult->Create(theFileName) != NULL)
927       return aResult->_this();
928     else
929       aResult->_remove_ref();
930
931     return VISU::Result::_nil();
932   }
933
934
935   //----------------------------------------------------------------------------
936   Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
937   {
938     if (myStudyDocument->GetProperties()->IsLocked())
939       return Result::_nil();
940
941     Result_i* aResult = Result_i::New(myStudyDocument,
942                                       Result_i::eComponent,
943                                       Result_i::eImportMed,
944                                       true,
945                                       true,
946                                       true,
947                                       true);
948     if (aResult->Create(theMedSObject) != NULL)
949     {
950       return aResult->_this();
951     }
952     else
953       aResult->_remove_ref();
954
955     return VISU::Result::_nil();
956   }
957
958
959   //----------------------------------------------------------------------------
960   Result_ptr
961   VISU_Gen_i
962   ::ImportMedField (SALOME_MED::FIELD_ptr theField)
963   {
964     if (myStudyDocument->GetProperties()->IsLocked())
965       return Result::_nil();
966
967     Result_i* aResult = Result_i::New(myStudyDocument,
968                                       Result_i::eComponent,
969                                       Result_i::eImportMedField,
970                                       true,
971                                       true,
972                                       true,
973                                       true);
974
975     if (aResult->Create(theField) != NULL)
976       return aResult->_this();
977     else
978       aResult->_remove_ref();
979
980     return VISU::Result::_nil();
981   }
982
983   void
984   VISU_Gen_i
985   ::RenameMeshInStudy(Result_ptr theResult,
986                       const std::string& theMeshName,
987                       int theEntity, // -1 for group indication
988                       const std::string& theSubMeshName, // Family or Group name
989                       const std::string& theNewName)
990   {
991     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
992     if (!aResult)
993       return;
994
995     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
996     if (aStudyDocument->GetProperties()->IsLocked())
997       return;
998
999
1000     QString aComment;
1001     VISU::VISUType aType;
1002     if (theEntity >= 0)
1003       if (theSubMeshName == "")
1004         aType = VISU::TENTITY;
1005       else
1006         aType = VISU::TFAMILY;
1007     else
1008       aType = VISU::TGROUP;
1009
1010     VISU::Storable::TRestoringMap aRestoringMap;
1011     aRestoringMap["myMeshName"] = theMeshName.c_str();
1012
1013     switch (aType) {
1014     case VISU::TENTITY:
1015       aRestoringMap["myComment"] = "ENTITY";
1016       aRestoringMap["myId"] = QString::number(theEntity);
1017       break;
1018     case VISU::TFAMILY:
1019       aRestoringMap["myComment"] = "FAMILY";
1020       aRestoringMap["myEntityId"] = QString::number(theEntity);
1021       aRestoringMap["myName"] = theSubMeshName.c_str();
1022       break;
1023     case VISU::TGROUP:
1024       aRestoringMap["myComment"] = "GROUP";
1025       aRestoringMap["myName"] = theSubMeshName.c_str();
1026       break;
1027     }
1028
1029     string anEntry = aResult->GetEntry(aRestoringMap);
1030     if (anEntry == "")
1031       return;
1032
1033     SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1034
1035     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1036     aStudyBuilder->NewCommand(); // There is a transaction
1037
1038     SALOMEDS::GenericAttribute_var anAttr =
1039       aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1040     SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1041     aNameAttr->SetValue(theNewName.c_str());
1042
1043     aStudyBuilder->CommitCommand();
1044   }
1045
1046
1047   //----------------------------------------------------------------------------
1048   void
1049   VISU_Gen_i
1050   ::RenameEntityInStudy(Result_ptr   theResult,
1051                         const char*  theMeshName,
1052                         VISU::Entity theEntity,
1053                         const char*  theNewName)
1054   {
1055     RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1056   }
1057
1058
1059   //----------------------------------------------------------------------------
1060   void
1061   VISU_Gen_i
1062   ::RenameFamilyInStudy(Result_ptr   theResult,
1063                         const char*  theMeshName,
1064                         VISU::Entity theEntity,
1065                         const char*  theFamilyName,
1066                         const char*  theNewName)
1067   {
1068     RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1069   }
1070
1071
1072   //----------------------------------------------------------------------------
1073   void
1074   VISU_Gen_i
1075   ::RenameGroupInStudy(Result_ptr  theResult,
1076                        const char*  theMeshName,
1077                        const char* theGroupName,
1078                        const char* theNewName)
1079   {
1080     RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1081   }
1082
1083
1084   //----------------------------------------------------------------------------
1085   Mesh_ptr
1086   VISU_Gen_i
1087   ::MeshOnEntity(Result_ptr theResult,
1088                  const char* theMeshName,
1089                  VISU::Entity theEntity)
1090   {
1091     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1092     if (!aResult)
1093       return VISU::Mesh::_nil();
1094
1095     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1096     if (aStudyDocument->GetProperties()->IsLocked())
1097       return VISU::Mesh::_nil();
1098
1099     Mesh_i* aPresent = new Mesh_i();
1100     if(aPresent->Create(aResult, theMeshName, theEntity))
1101       return aPresent->_this();
1102     else
1103       aPresent->_remove_ref();
1104
1105     return VISU::Mesh::_nil();
1106   }
1107
1108
1109   //----------------------------------------------------------------------------
1110   Mesh_ptr
1111   VISU_Gen_i
1112   ::FamilyMeshOnEntity(Result_ptr theResult,
1113                        const char* theMeshName,
1114                        VISU::Entity theEntity,
1115                        const char* theFamilyName)
1116   {
1117     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1118     if (!aResult)
1119       return VISU::Mesh::_nil();
1120
1121     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1122     if (aStudyDocument->GetProperties()->IsLocked())
1123       return VISU::Mesh::_nil();
1124
1125     Mesh_i* aPresent = new Mesh_i();
1126     if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1127       return aPresent->_this();
1128     else
1129       aPresent->_remove_ref();
1130
1131     return VISU::Mesh::_nil();
1132   }
1133
1134
1135   //----------------------------------------------------------------------------
1136   Mesh_ptr
1137   VISU_Gen_i
1138   ::GroupMesh(Result_ptr theResult,
1139               const char* theMeshName,
1140               const char* theGroupName)
1141   {
1142     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1143     if (!aResult)
1144       return VISU::Mesh::_nil();
1145
1146     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1147     if (aStudyDocument->GetProperties()->IsLocked())
1148       return VISU::Mesh::_nil();
1149
1150     Mesh_i* aPresent = new Mesh_i();
1151     if(aPresent->Create(aResult, theMeshName, theGroupName))
1152       return aPresent->_this();
1153     else
1154       aPresent->_remove_ref();
1155
1156     return VISU::Mesh::_nil();
1157   }
1158
1159
1160   //----------------------------------------------------------------------------
1161   ScalarMap_ptr
1162   VISU_Gen_i
1163   ::ScalarMapOnField(Result_ptr theResult,
1164                      const char* theMeshName,
1165                      VISU::Entity theEntity,
1166                      const char* theFieldName,
1167                      CORBA::Long theIteration)
1168   {
1169     return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1170                                            theMeshName,
1171                                            theEntity,
1172                                            theFieldName,
1173                                            theIteration)._retn();
1174   }
1175
1176
1177   //----------------------------------------------------------------------------
1178   GaussPoints_ptr
1179   VISU_Gen_i
1180   ::GaussPointsOnField(Result_ptr theResult,
1181                        const char* theMeshName,
1182                        VISU::Entity theEntity,
1183                        const char* theFieldName,
1184                        CORBA::Long theIteration)
1185   {
1186     return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1187                                              theMeshName,
1188                                              theEntity,
1189                                              theFieldName,
1190                                              theIteration)._retn();
1191   }
1192
1193
1194   //---------------------------------------------------------------
1195   DeformedShape_ptr
1196   VISU_Gen_i
1197   ::DeformedShapeOnField(Result_ptr theResult,
1198                          const char* theMeshName,
1199                          VISU::Entity theEntity,
1200                          const char* theFieldName,
1201                          CORBA::Long theIteration)
1202   {
1203     return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1204                                                theMeshName,
1205                                                theEntity,
1206                                                theFieldName,
1207                                                theIteration)._retn();
1208   }
1209
1210
1211   //---------------------------------------------------------------
1212   DeformedShapeAndScalarMap_ptr
1213   VISU_Gen_i
1214   ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1215                                     const char* theMeshName,
1216                                     VISU::Entity theEntity,
1217                                     const char* theFieldName,
1218                                     CORBA::Long theIteration)
1219   {
1220     return DeformedShapeAndScalarMapOnField(theResult,
1221                                             theMeshName,
1222                                             theEntity,
1223                                             theFieldName,
1224                                             theIteration);
1225   }
1226
1227
1228 //---------------------------------------------------------------
1229   DeformedShapeAndScalarMap_ptr
1230   VISU_Gen_i
1231   ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1232                                      const char* theMeshName,
1233                                      VISU::Entity theEntity,
1234                                      const char* theFieldName,
1235                                      CORBA::Long theIteration)
1236   {
1237     return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1238                                                            theMeshName,
1239                                                            theEntity,
1240                                                            theFieldName,
1241                                                            theIteration)._retn();
1242   }
1243
1244
1245   //---------------------------------------------------------------
1246   Vectors_ptr
1247   VISU_Gen_i
1248   ::VectorsOnField(Result_ptr theResult,
1249                    const char* theMeshName,
1250                    VISU::Entity theEntity,
1251                    const char* theFieldName,
1252                    CORBA::Long theIteration)
1253   {
1254     return Prs3dOnField<VISU::Vectors_i>(theResult,
1255                                          theMeshName,
1256                                          theEntity,
1257                                          theFieldName,
1258                                          theIteration)._retn();
1259   }
1260
1261
1262   //---------------------------------------------------------------
1263   IsoSurfaces_ptr
1264   VISU_Gen_i
1265   ::IsoSurfacesOnField(Result_ptr theResult,
1266                        const char* theMeshName,
1267                        VISU::Entity theEntity,
1268                        const char* theFieldName,
1269                        CORBA::Long theIteration)
1270   {
1271     return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1272                                              theMeshName,
1273                                              theEntity,
1274                                              theFieldName,
1275                                              theIteration)._retn();
1276   }
1277
1278
1279   //---------------------------------------------------------------
1280   StreamLines_ptr
1281   VISU_Gen_i
1282   ::StreamLinesOnField(Result_ptr theResult,
1283                        const char* theMeshName,
1284                        VISU::Entity theEntity,
1285                        const char* theFieldName,
1286                        CORBA::Long theIteration)
1287   {
1288     return Prs3dOnField<VISU::StreamLines_i>(theResult,
1289                                              theMeshName,
1290                                              theEntity,
1291                                              theFieldName,
1292                                              theIteration)._retn();
1293   }
1294
1295
1296   //---------------------------------------------------------------
1297   Plot3D_ptr
1298   VISU_Gen_i
1299   ::Plot3DOnField(Result_ptr theResult,
1300                   const char* theMeshName,
1301                   VISU::Entity theEntity,
1302                   const char* theFieldName,
1303                   CORBA::Long theIteration)
1304   {
1305     return Prs3dOnField<VISU::Plot3D_i>(theResult,
1306                                         theMeshName,
1307                                         theEntity,
1308                                         theFieldName,
1309                                         theIteration)._retn();
1310   }
1311
1312
1313   //---------------------------------------------------------------
1314   CutPlanes_ptr
1315   VISU_Gen_i
1316   ::CutPlanesOnField(Result_ptr theResult,
1317                      const char* theMeshName,
1318                      VISU::Entity theEntity,
1319                      const char* theFieldName,
1320                      CORBA::Long theIteration)
1321   {
1322     return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1323                                            theMeshName,
1324                                            theEntity,
1325                                            theFieldName,
1326                                            theIteration)._retn();
1327   }
1328
1329
1330   //---------------------------------------------------------------
1331   CutLines_ptr
1332   VISU_Gen_i
1333   ::CutLinesOnField(Result_ptr theResult,
1334                     const char* theMeshName,
1335                     VISU::Entity theEntity,
1336                     const char* theFieldName,
1337                     CORBA::Long theIteration)
1338   {
1339     return Prs3dOnField<VISU::CutLines_i>(theResult,
1340                                           theMeshName,
1341                                           theEntity,
1342                                           theFieldName,
1343                                           theIteration)._retn();
1344   }
1345
1346   //---------------------------------------------------------------
1347   CutSegment_ptr
1348   VISU_Gen_i
1349   ::CutSegmentOnField(Result_ptr theResult,
1350                       const char* theMeshName,
1351                       VISU::Entity theEntity,
1352                       const char* theFieldName,
1353                       CORBA::Long theIteration)
1354   {
1355     return Prs3dOnField<VISU::CutSegment_i>(theResult,
1356                                             theMeshName,
1357                                             theEntity,
1358                                             theFieldName,
1359                                             theIteration)._retn();
1360   }
1361
1362   //---------------------------------------------------------------
1363   struct CreateTableEvent: public SALOME_Event
1364   {
1365     SALOMEDS::Study_var myStudyDocument;
1366     const char* myTableEntry;
1367     typedef Table_ptr TResult;
1368     TResult myResult;
1369
1370     CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1371     {
1372       myStudyDocument = theStudy;
1373       myTableEntry = theTableEntry;
1374       myResult = Table::_nil();
1375     }
1376
1377     virtual
1378     void
1379     Execute()
1380     {
1381       SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1382       SALOMEDS::GenericAttribute_var anAttr;
1383       if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1384         SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1385         if ( isSparseMatrix( aTableOfReal ) ) {
1386           PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1387           if(pPresent->Create() != NULL)
1388             myResult = pPresent->_this();
1389           else {
1390             pPresent->_remove_ref();
1391             myResult = VISU::Table::_nil();
1392           }
1393           return;
1394         }
1395       }
1396       Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1397       if(pPresent->Create() != NULL)
1398         myResult = pPresent->_this();
1399       else {
1400         pPresent->_remove_ref();
1401         myResult = VISU::Table::_nil();
1402       }
1403     }
1404
1405     virtual
1406     bool
1407     isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1408     {
1409       int aCols = theTableOfReal->GetNbColumns();
1410       int aRows = theTableOfReal->GetNbRows();
1411
1412       for (int i=1; i<=aCols; i++) {
1413         for (int j=1; j<=aRows; j++) {
1414           if ( !(theTableOfReal->HasValue(j, i)) )
1415             return false;
1416         }
1417       }
1418       return true;
1419     }
1420   };
1421
1422   //---------------------------------------------------------------
1423   Table_ptr
1424   VISU_Gen_i
1425   ::CreateTable(const char* theTableEntry)
1426   {
1427     TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1428     if( myStudyDocument->GetProperties()->IsLocked() ||
1429         tmp.Length()==0 )
1430       return Table::_nil();
1431
1432     return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1433   }
1434
1435   //---------------------------------------------------------------
1436   Curve_ptr
1437   VISU_Gen_i
1438   ::CreateCurve(Table_ptr theTable,
1439                 CORBA::Long theHRow,
1440                 CORBA::Long theVRow)
1441   {
1442     return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1443   }
1444
1445
1446   //---------------------------------------------------------------
1447   Curve_ptr
1448   VISU_Gen_i
1449   ::CreateCurveWithZ(Table_ptr theTable,
1450                      CORBA::Long theHRow,
1451                      CORBA::Long theVRow,
1452                      CORBA::Long theZRow)
1453   {
1454     return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1455   }
1456
1457
1458   //---------------------------------------------------------------
1459   Curve_ptr
1460   VISU_Gen_i
1461   ::CreateCurveWithZExt(Table_ptr theTable,
1462                         CORBA::Long theHRow,
1463                         CORBA::Long theVRow,
1464                         CORBA::Long theZRow,
1465                         CORBA::Boolean theIsV2)
1466   {
1467     if(myStudyDocument->GetProperties()->IsLocked())
1468       return Curve::_nil();
1469     Mutex mt(myMutex);
1470     PortableServer::POA_ptr aPOA = GetPOA();
1471     Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1472     Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1473     if(pPresent->Create() != NULL)
1474       return pPresent->_this();
1475     else{
1476       pPresent->_remove_ref();
1477       return VISU::Curve::_nil();
1478     }
1479   }
1480
1481
1482   //---------------------------------------------------------------
1483   Container_ptr
1484   VISU_Gen_i
1485   ::CreateContainer()
1486   {
1487     if(myStudyDocument->GetProperties()->IsLocked())
1488       return Container::_nil();
1489     Mutex mt(myMutex);
1490     Container_i* pPresent = new Container_i(myStudyDocument);
1491     if(pPresent->Create() != NULL)
1492       return pPresent->_this();
1493     else{
1494       pPresent->_remove_ref();
1495       return VISU::Container::_nil();
1496     }
1497   }
1498
1499
1500   //---------------------------------------------------------------
1501   Animation_ptr
1502   VISU_Gen_i
1503   ::CreateAnimation(View3D_ptr theView3D)
1504   {
1505     if(myStudyDocument->GetProperties()->IsLocked())
1506       return Animation::_nil();
1507     Mutex mt(myMutex);
1508     if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1509       return anAnim->_this();
1510     }else
1511       return VISU::Animation::_nil();
1512   }
1513
1514
1515   //---------------------------------------------------------------
1516   Evolution_ptr
1517   VISU_Gen_i
1518   ::CreateEvolution(XYPlot_ptr theXYPlot)
1519   {
1520     if(myStudyDocument->GetProperties()->IsLocked())
1521       return Evolution::_nil();
1522     Mutex mt(myMutex);
1523     if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1524       return anEvolution->_this();
1525     }else
1526       return VISU::Evolution::_nil();
1527   }
1528
1529
1530   //---------------------------------------------------------------
1531   void
1532   VISU_Gen_i
1533   ::DeleteResult (Result_ptr theResult)
1534   {
1535     theResult->RemoveFromStudy();
1536   }
1537
1538
1539   //---------------------------------------------------------------
1540   void
1541   VISU_Gen_i
1542   ::DeletePrs3d(Prs3d_ptr thePrs3d)
1543   {
1544     thePrs3d->RemoveFromStudy();
1545   }
1546
1547
1548   //---------------------------------------------------------------
1549   void
1550   VISU_Gen_i
1551   ::Close(SALOMEDS::SComponent_ptr theComponent)
1552   {
1553     if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( theComponent ) &&
1554          myStudyDocument->StudyId() == theComponent->GetStudy()->StudyId())
1555       myStudyDocument = SALOMEDS::Study::_nil();
1556   }
1557
1558
1559   //---------------------------------------------------------------
1560   char*
1561   VISU_Gen_i
1562   ::ComponentDataType()
1563   {
1564     return CORBA::string_dup("VISU");
1565   }
1566
1567
1568   //---------------------------------------------------------------
1569   bool
1570   VISU_Gen_i
1571   ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1572   {
1573     Result_var aResultObj = Result::_narrow(theIOR);
1574     return !(aResultObj->_is_nil());
1575   }
1576
1577
1578   //---------------------------------------------------------------
1579   SALOMEDS::SObject_ptr
1580   VISU_Gen_i
1581   ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1582                    SALOMEDS::SObject_ptr theSObject,
1583                    CORBA::Object_ptr theObject,
1584                    const char* theName)
1585     throw (SALOME::SALOME_Exception)
1586   {
1587     Unexpect aCatch(SalomeException);
1588     if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1589     Mutex mt(myMutex);
1590     SALOMEDS::SObject_var aResultSO;
1591     Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1592     if (!aResultObj)
1593       return aResultSO._retn();
1594     const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1595     CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1596     aResultSO = theStudy->FindObjectID(anEntry);
1597     return aResultSO._retn();
1598   }
1599
1600
1601   //---------------------------------------------------------------
1602   CORBA::Boolean
1603   VISU_Gen_i
1604   ::CanCopy(SALOMEDS::SObject_ptr theObject)
1605   {
1606     CORBA::Object_var anObj = SObjectToObject(theObject);
1607     if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1608       return aStorable->CanCopy(theObject);
1609
1610     return false;
1611   }
1612
1613
1614   //---------------------------------------------------------------
1615   SALOMEDS::TMPFile*
1616   VISU_Gen_i
1617   ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1618              CORBA::Long& theObjectID)
1619   {
1620     theObjectID = 0;
1621     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1622
1623     CORBA::Object_var anObj = SObjectToObject(theObject);
1624     if (CORBA::is_nil(anObj)) {
1625       aStreamFile->length(1);
1626       aStreamFile[0] = CORBA::string_dup("E")[0];
1627     } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1628       std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1629       Storable::TFileNames aFileNames;
1630       bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1631
1632       SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1633       aListOfFileNames->length(aFileNames.size());
1634       for(size_t anId = 0; anId < aFileNames.size(); anId++)
1635         aListOfFileNames[anId] = aFileNames[anId].c_str();
1636
1637       if(anIsDone)
1638         aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1639
1640       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1641     }
1642     return aStreamFile._retn();
1643   }
1644
1645
1646   //---------------------------------------------------------------
1647   CORBA::Boolean
1648   VISU_Gen_i
1649   ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1650     // The VISU component can paste only objects copied by VISU component
1651     CORBA::String_var aString = ComponentDataType();
1652     if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1653       return true;
1654     return false;
1655   }
1656
1657
1658   //---------------------------------------------------------------
1659   SALOMEDS::SObject_ptr
1660   VISU_Gen_i
1661   ::PasteInto(const SALOMEDS::TMPFile& theStream,
1662               CORBA::Long theObjectID,
1663               SALOMEDS::SObject_ptr theSObject)
1664   {
1665     if (theObjectID != 1)
1666       return SALOMEDS::SObject::_nil();
1667
1668     SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1669     SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1670     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1671     CORBA::String_var aComponentID(aComponent->GetID());
1672     CORBA::String_var aSObjectID(theSObject->GetID());
1673
1674     SALOMEDS::SObject_var aSObject;
1675     if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1676       aSObject = aStudyBuilder->NewObject(aComponent);
1677     else
1678       aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1679
1680     std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1681     SALOMEDS::ListOfFileNames_var aListOfFileNames =
1682       SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1683     if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1684
1685     std::ostringstream aLocalPersistentID;
1686     {
1687       std::string aCopyPersist =  aTmpDir + "copy_persistent";
1688       std::ifstream anInputFileStream( aCopyPersist.c_str() );
1689       anInputFileStream >> aLocalPersistentID.rdbuf();
1690     }
1691
1692     //Just for Result::Restore to find the Comment attribute :(
1693     SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1694
1695     std::string aFileName(aTmpDir);
1696     if(aListOfFileNames->length() > 1)
1697       aFileName += aListOfFileNames[1].in();
1698     Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1699
1700     SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1701     aFilesToRemove->length(1);
1702     aFilesToRemove[0] = aListOfFileNames[0];
1703     SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1704
1705     anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1706     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1707     CORBA::String_var anIORValue(aStorable->GetID());
1708     anIOR->SetValue(anIORValue);
1709
1710     return aSObject._retn();
1711   }
1712
1713
1714   //---------------------------------------------------------------
1715   VISU::ColoredPrs3dCache_ptr
1716   VISU_Gen_i
1717   ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1718   {
1719     return ColoredPrs3dCache_i::GetInstance(theStudy);
1720   }
1721
1722
1723   CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double  Y, CORBA::Double Z,
1724                                               CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1725                                               CORBA::Boolean isAuto, const char* name)
1726   {
1727     return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1728   }
1729
1730
1731   void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double  Y, CORBA::Double Z,
1732                                      CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1733                                      CORBA::Boolean isAuto, const char* name)
1734   {
1735     myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1736   }
1737
1738     /* Returns clipping plane by its Id */
1739   VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1740   {
1741     VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1742
1743     if (aPlane != NULL) {
1744       double aOrigin[3];
1745       double aDir[3];
1746       aPlane->GetOrigin(aOrigin);
1747       aPlane->GetNormal(aDir);
1748
1749       VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1750       aRetPlane->X = aOrigin[0];
1751       aRetPlane->Y = aOrigin[1];
1752       aRetPlane->Z = aOrigin[2];
1753       aRetPlane->dX = aDir[0];
1754       aRetPlane->dY = aDir[1];
1755       aRetPlane->dZ = aDir[2];
1756       aRetPlane->isAuto = aPlane->isAuto();
1757
1758       aRetPlane->name = aPlane->getName().c_str();
1759       return aRetPlane;
1760     }
1761     return NULL;
1762   }
1763
1764     /* Deletes clipping plane by its Id */
1765   CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1766   {
1767     return myClippingPlaneMgr.DeleteClippingPlane(id);
1768   }
1769
1770     /* Applyes a clipping plane with Id to presentation thePrs */
1771   CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1772   {
1773     VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1774     return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1775   }
1776
1777     /* Detaches a clipping plane with Id from presentation thePrs */
1778   CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1779   {
1780     VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1781     return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1782   }
1783
1784     /* Get number of clipping planes */
1785   CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1786   {
1787     return myClippingPlaneMgr.GetClippingPlanesNb();
1788   }
1789
1790   /*!
1791   \brief Converts set of VTK files to the one MED-file
1792   \param theVTKFiles sequence of VTK files
1793   \param theMEDFile MED-file
1794   \param theMeshName mesh name. This parameter can be empty. In this case name
1795          of mesh is equal vtk2med
1796   \param theTStamps values of time stamps. This array can be empty, in
1797          this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1798   \return TRUE if operation has been completed successfully, FALSE otherwise
1799   */
1800   CORBA::Boolean
1801   VISU_Gen_i
1802   ::VTK2MED( const VISU::string_array& theVTKFiles,
1803              const char* theMEDFile,
1804              const char* theMeshName,
1805              const VISU::double_array& theTStamps )
1806   {
1807     if ( !theMEDFile || !theVTKFiles.length() )
1808       return false;
1809
1810     VISU_Vtk2MedConvertor aConvertor;
1811     aConvertor.setMEDFileName( theMEDFile );
1812     // std::string aFirstFile = theVTKFiles[ 0 ];
1813     char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1814     aConvertor.setFirstVTKFileName( aFirstFile );
1815     if ( theVTKFiles.length() > 1 )
1816     {
1817       VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1818       for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1819         aFiles[ i - 1 ] = theVTKFiles[ i ];
1820       aConvertor.setDataVTKFileNames( aFiles );
1821     }
1822     if ( theTStamps.length() > 0 )
1823     {
1824       VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1825       for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1826         aTStamps[ i ] = theTStamps[ i ];
1827       aConvertor.setTimeStamps( aTStamps );
1828     }
1829
1830     if ( theMeshName && strlen( theMeshName ) > 0 )
1831       aConvertor.setMeshName( theMeshName );
1832
1833     aConvertor.addToIgnoringFieldList("cellID");
1834     aConvertor.setCellDataFieldNameIDS("cellID");
1835
1836     int res = aConvertor.Execute();
1837
1838     return res == 0;
1839   }
1840
1841   CORBA::Long
1842   VISU_Gen_i
1843   ::LoadTexture(const char* theTextureFile)
1844   {
1845     if( CORBA::is_nil( myStudyDocument ) )
1846       return 0;
1847
1848     int aStudyId = myStudyDocument->StudyId();
1849
1850     VTK::MarkerTexture aMarkerTexture;
1851     if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1852       return 0;
1853
1854     VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1855     int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1856
1857     VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1858     aMarkerData.first = theTextureFile;
1859     aMarkerData.second = aMarkerTexture;
1860
1861     return aMarkerId;
1862   }
1863 }