]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_Gen_i.cc
Salome HOME
Merge from V6_2_BR 23/12/2010
[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
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_Gen_i.cc
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_Gen_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_PrsObject_i.hh"
31 #include "VISU_ViewManager_i.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::Component_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     return aRes._retn();
845   }
846
847
848   //----------------------------------------------------------------------------
849   CORBA::Boolean 
850   VISU_Gen_i
851   ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
852                       const char* theFileName)
853   {
854     return VISU::ExportTableToFile(theTable, theFileName);
855   }
856
857
858   //----------------------------------------------------------------------------
859   Result_ptr
860   VISU_Gen_i
861   ::ImportFile(const char* theFileName)
862   {
863     if(myStudyDocument->GetProperties()->IsLocked())
864       return Result::_nil();
865
866     Result_i* aResult = Result_i::New(myStudyDocument,
867                                       Result_i::eFile,
868                                       Result_i::eImportFile,
869                                       true,
870                                       true,
871                                       true,
872                                       true);
873
874     if(aResult->Create(theFileName) != NULL)
875       return aResult->_this();
876     else
877       aResult->_remove_ref();
878
879     return VISU::Result::_nil();
880   }
881
882
883   //----------------------------------------------------------------------------
884   Result_ptr
885   VISU_Gen_i
886   ::CreateResult(const char* theFileName)
887   {
888     if(myStudyDocument->GetProperties()->IsLocked())
889       return Result::_nil();
890
891     Result_i* aResult = Result_i::New(myStudyDocument,
892                                       Result_i::eFile,
893                                       Result_i::eImportFile,
894                                       false,
895                                       true,
896                                       true,
897                                       true);
898
899     if(aResult->Create(theFileName) != NULL)
900       return aResult->_this();
901     else
902       aResult->_remove_ref();
903
904     return VISU::Result::_nil();
905   }
906
907
908   //----------------------------------------------------------------------------
909   Result_ptr
910   VISU_Gen_i
911   ::CopyAndImportFile(const char* theFileName)
912   {
913     if(myStudyDocument->GetProperties()->IsLocked())
914       return Result::_nil();
915
916     Result_i* aResult = Result_i::New(myStudyDocument,
917                                       Result_i::eRestoredFile,
918                                       Result_i::eCopyAndImportFile,
919                                       true,
920                                       true,
921                                       true,
922                                       true);
923     if(aResult->Create(theFileName) != NULL)
924       return aResult->_this();
925     else
926       aResult->_remove_ref();
927
928     return VISU::Result::_nil();
929   }
930
931
932   //----------------------------------------------------------------------------
933   Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
934   {
935     if (myStudyDocument->GetProperties()->IsLocked())
936       return Result::_nil();
937
938     Result_i* aResult = Result_i::New(myStudyDocument,
939                                       Result_i::eComponent,
940                                       Result_i::eImportMed,
941                                       true,
942                                       true,
943                                       true,
944                                       true);
945     if (aResult->Create(theMedSObject) != NULL)
946     {
947       return aResult->_this();
948     }
949     else
950       aResult->_remove_ref();
951     
952     return VISU::Result::_nil();
953   }
954
955
956   //----------------------------------------------------------------------------
957   Result_ptr
958   VISU_Gen_i
959   ::ImportMedField (SALOME_MED::FIELD_ptr theField)
960   {
961     if (myStudyDocument->GetProperties()->IsLocked())
962       return Result::_nil();
963
964     Result_i* aResult = Result_i::New(myStudyDocument,
965                                       Result_i::eComponent,
966                                       Result_i::eImportMedField,
967                                       true,
968                                       true,
969                                       true,
970                                       true);
971
972     if (aResult->Create(theField) != NULL)
973       return aResult->_this();
974     else
975       aResult->_remove_ref();
976     
977     return VISU::Result::_nil();
978   }
979
980   void
981   VISU_Gen_i
982   ::RenameMeshInStudy(Result_ptr theResult,
983                       const std::string& theMeshName,
984                       int theEntity, // -1 for group indication
985                       const std::string& theSubMeshName, // Family or Group name
986                       const std::string& theNewName)
987   {
988     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
989     if (!aResult) 
990       return;
991
992     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
993     if (aStudyDocument->GetProperties()->IsLocked()) 
994       return;
995
996
997     QString aComment;
998     VISU::VISUType aType;
999     if (theEntity >= 0)
1000       if (theSubMeshName == "")
1001         aType = VISU::TENTITY;
1002       else
1003         aType = VISU::TFAMILY;
1004     else
1005       aType = VISU::TGROUP;
1006
1007     VISU::Storable::TRestoringMap aRestoringMap;
1008     aRestoringMap["myMeshName"] = theMeshName.c_str();
1009
1010     switch (aType) {
1011     case VISU::TENTITY:
1012       aRestoringMap["myComment"] = "ENTITY";
1013       aRestoringMap["myId"] = QString::number(theEntity);
1014       break;
1015     case VISU::TFAMILY:
1016       aRestoringMap["myComment"] = "FAMILY";
1017       aRestoringMap["myEntityId"] = QString::number(theEntity);
1018       aRestoringMap["myName"] = theSubMeshName.c_str();
1019       break;
1020     case VISU::TGROUP:
1021       aRestoringMap["myComment"] = "GROUP";
1022       aRestoringMap["myName"] = theSubMeshName.c_str();
1023       break;
1024     }
1025
1026     string anEntry = aResult->GetEntry(aRestoringMap);
1027     if (anEntry == "") 
1028       return;
1029
1030     SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1031
1032     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1033     aStudyBuilder->NewCommand(); // There is a transaction
1034
1035     SALOMEDS::GenericAttribute_var anAttr =
1036       aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1037     SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1038     aNameAttr->SetValue(theNewName.c_str());
1039
1040     aStudyBuilder->CommitCommand();
1041   }
1042
1043
1044   //----------------------------------------------------------------------------
1045   void
1046   VISU_Gen_i
1047   ::RenameEntityInStudy(Result_ptr   theResult,
1048                         const char*  theMeshName,
1049                         VISU::Entity theEntity,
1050                         const char*  theNewName)
1051   {
1052     RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1053   }
1054
1055
1056   //----------------------------------------------------------------------------
1057   void
1058   VISU_Gen_i
1059   ::RenameFamilyInStudy(Result_ptr   theResult,
1060                         const char*  theMeshName,
1061                         VISU::Entity theEntity,
1062                         const char*  theFamilyName,
1063                         const char*  theNewName)
1064   {
1065     RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1066   }
1067
1068
1069   //----------------------------------------------------------------------------
1070   void 
1071   VISU_Gen_i
1072   ::RenameGroupInStudy(Result_ptr  theResult,
1073                        const char*  theMeshName,
1074                        const char* theGroupName,
1075                        const char* theNewName)
1076   {
1077     RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1078   }
1079
1080
1081   //----------------------------------------------------------------------------
1082   Mesh_ptr
1083   VISU_Gen_i
1084   ::MeshOnEntity(Result_ptr theResult,
1085                  const char* theMeshName,
1086                  VISU::Entity theEntity)
1087   {
1088     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1089     if (!aResult) 
1090       return VISU::Mesh::_nil();
1091
1092     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1093     if (aStudyDocument->GetProperties()->IsLocked()) 
1094       return VISU::Mesh::_nil();
1095
1096     Mesh_i* aPresent = new Mesh_i();
1097     if(aPresent->Create(aResult, theMeshName, theEntity))
1098       return aPresent->_this();
1099     else
1100       aPresent->_remove_ref();
1101
1102     return VISU::Mesh::_nil();
1103   }
1104
1105
1106   //----------------------------------------------------------------------------
1107   Mesh_ptr 
1108   VISU_Gen_i
1109   ::FamilyMeshOnEntity(Result_ptr theResult,
1110                        const char* theMeshName,
1111                        VISU::Entity theEntity,
1112                        const char* theFamilyName)
1113   {
1114     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1115     if (!aResult) 
1116       return VISU::Mesh::_nil();
1117
1118     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1119     if (aStudyDocument->GetProperties()->IsLocked()) 
1120       return VISU::Mesh::_nil();
1121
1122     Mesh_i* aPresent = new Mesh_i();
1123     if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1124       return aPresent->_this();
1125     else
1126       aPresent->_remove_ref();
1127
1128     return VISU::Mesh::_nil();
1129   }
1130
1131
1132   //----------------------------------------------------------------------------
1133   Mesh_ptr
1134   VISU_Gen_i
1135   ::GroupMesh(Result_ptr theResult,
1136               const char* theMeshName,
1137               const char* theGroupName)
1138   {
1139     Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1140     if (!aResult) 
1141       return VISU::Mesh::_nil();
1142
1143     SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1144     if (aStudyDocument->GetProperties()->IsLocked()) 
1145       return VISU::Mesh::_nil();
1146
1147     Mesh_i* aPresent = new Mesh_i();
1148     if(aPresent->Create(aResult, theMeshName, theGroupName))
1149       return aPresent->_this();
1150     else
1151       aPresent->_remove_ref();
1152
1153     return VISU::Mesh::_nil();
1154   }
1155
1156
1157   //----------------------------------------------------------------------------
1158   ScalarMap_ptr 
1159   VISU_Gen_i
1160   ::ScalarMapOnField(Result_ptr theResult,
1161                      const char* theMeshName,
1162                      VISU::Entity theEntity,
1163                      const char* theFieldName,
1164                      CORBA::Long theIteration)
1165   {
1166     return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1167                                            theMeshName,
1168                                            theEntity,
1169                                            theFieldName,
1170                                            theIteration)._retn();
1171   }
1172
1173
1174   //----------------------------------------------------------------------------
1175   GaussPoints_ptr
1176   VISU_Gen_i
1177   ::GaussPointsOnField(Result_ptr theResult,
1178                        const char* theMeshName,
1179                        VISU::Entity theEntity,
1180                        const char* theFieldName,
1181                        CORBA::Long theIteration)
1182   {
1183     return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1184                                              theMeshName,
1185                                              theEntity,
1186                                              theFieldName,
1187                                              theIteration)._retn();
1188   }
1189
1190
1191   //---------------------------------------------------------------
1192   DeformedShape_ptr 
1193   VISU_Gen_i
1194   ::DeformedShapeOnField(Result_ptr theResult,
1195                          const char* theMeshName,
1196                          VISU::Entity theEntity,
1197                          const char* theFieldName,
1198                          CORBA::Long theIteration)
1199   {
1200     return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1201                                                theMeshName,
1202                                                theEntity,
1203                                                theFieldName,
1204                                                theIteration)._retn();
1205   }
1206
1207
1208   //---------------------------------------------------------------
1209   DeformedShapeAndScalarMap_ptr 
1210   VISU_Gen_i
1211   ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1212                                     const char* theMeshName,
1213                                     VISU::Entity theEntity,
1214                                     const char* theFieldName,
1215                                     CORBA::Long theIteration)
1216   {
1217     return DeformedShapeAndScalarMapOnField(theResult,
1218                                             theMeshName,
1219                                             theEntity,
1220                                             theFieldName,
1221                                             theIteration);
1222   }
1223   
1224
1225 //---------------------------------------------------------------
1226   DeformedShapeAndScalarMap_ptr 
1227   VISU_Gen_i
1228   ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1229                                      const char* theMeshName,
1230                                      VISU::Entity theEntity,
1231                                      const char* theFieldName,
1232                                      CORBA::Long theIteration)
1233   {
1234     return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1235                                                            theMeshName,
1236                                                            theEntity,
1237                                                            theFieldName,
1238                                                            theIteration)._retn();
1239   }
1240   
1241
1242   //---------------------------------------------------------------
1243   Vectors_ptr 
1244   VISU_Gen_i
1245   ::VectorsOnField(Result_ptr theResult,
1246                    const char* theMeshName,
1247                    VISU::Entity theEntity,
1248                    const char* theFieldName,
1249                    CORBA::Long theIteration)
1250   {
1251     return Prs3dOnField<VISU::Vectors_i>(theResult,
1252                                          theMeshName,
1253                                          theEntity,
1254                                          theFieldName,
1255                                          theIteration)._retn();
1256   }
1257
1258
1259   //---------------------------------------------------------------
1260   IsoSurfaces_ptr 
1261   VISU_Gen_i
1262   ::IsoSurfacesOnField(Result_ptr theResult,
1263                        const char* theMeshName,
1264                        VISU::Entity theEntity,
1265                        const char* theFieldName,
1266                        CORBA::Long theIteration)
1267   {
1268     return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1269                                              theMeshName,
1270                                              theEntity,
1271                                              theFieldName,
1272                                              theIteration)._retn();
1273   }
1274
1275
1276   //---------------------------------------------------------------
1277   StreamLines_ptr 
1278   VISU_Gen_i
1279   ::StreamLinesOnField(Result_ptr theResult,
1280                        const char* theMeshName,
1281                        VISU::Entity theEntity,
1282                        const char* theFieldName,
1283                        CORBA::Long theIteration)
1284   {
1285     return Prs3dOnField<VISU::StreamLines_i>(theResult,
1286                                              theMeshName,
1287                                              theEntity,
1288                                              theFieldName,
1289                                              theIteration)._retn();
1290   }
1291
1292
1293   //---------------------------------------------------------------
1294   Plot3D_ptr 
1295   VISU_Gen_i
1296   ::Plot3DOnField(Result_ptr theResult,
1297                   const char* theMeshName,
1298                   VISU::Entity theEntity,
1299                   const char* theFieldName,
1300                   CORBA::Long theIteration)
1301   {
1302     return Prs3dOnField<VISU::Plot3D_i>(theResult,
1303                                         theMeshName,
1304                                         theEntity,
1305                                         theFieldName,
1306                                         theIteration)._retn();
1307   }
1308
1309
1310   //---------------------------------------------------------------
1311   CutPlanes_ptr
1312   VISU_Gen_i
1313   ::CutPlanesOnField(Result_ptr theResult,
1314                      const char* theMeshName,
1315                      VISU::Entity theEntity,
1316                      const char* theFieldName,
1317                      CORBA::Long theIteration)
1318   {
1319     return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1320                                            theMeshName,
1321                                            theEntity,
1322                                            theFieldName,
1323                                            theIteration)._retn();
1324   }
1325
1326
1327   //---------------------------------------------------------------
1328   CutLines_ptr
1329   VISU_Gen_i
1330   ::CutLinesOnField(Result_ptr theResult,
1331                     const char* theMeshName,
1332                     VISU::Entity theEntity,
1333                     const char* theFieldName,
1334                     CORBA::Long theIteration)
1335   {
1336     return Prs3dOnField<VISU::CutLines_i>(theResult,
1337                                           theMeshName,
1338                                           theEntity,
1339                                           theFieldName,
1340                                           theIteration)._retn();
1341   }
1342
1343   //---------------------------------------------------------------
1344   CutSegment_ptr
1345   VISU_Gen_i
1346   ::CutSegmentOnField(Result_ptr theResult,
1347                       const char* theMeshName,
1348                       VISU::Entity theEntity,
1349                       const char* theFieldName,
1350                       CORBA::Long theIteration)
1351   {
1352     return Prs3dOnField<VISU::CutSegment_i>(theResult,
1353                                             theMeshName,
1354                                             theEntity,
1355                                             theFieldName,
1356                                             theIteration)._retn();
1357   }
1358
1359   //---------------------------------------------------------------
1360   struct CreateTableEvent: public SALOME_Event
1361   {
1362     SALOMEDS::Study_var myStudyDocument;
1363     const char* myTableEntry;
1364     typedef Table_ptr TResult;
1365     TResult myResult;
1366     
1367     CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1368     {
1369       myStudyDocument = theStudy;
1370       myTableEntry = theTableEntry;
1371       myResult = Table::_nil();
1372     }
1373     
1374     virtual
1375     void
1376     Execute()
1377     {
1378       SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1379       SALOMEDS::GenericAttribute_var anAttr;
1380       if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1381         SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1382         if ( isSparseMatrix( aTableOfReal ) ) {
1383           PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1384           if(pPresent->Create() != NULL)
1385             myResult = pPresent->_this();
1386           else {
1387             pPresent->_remove_ref();
1388             myResult = VISU::Table::_nil();
1389           }
1390           return;
1391         }
1392       }
1393       Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1394       if(pPresent->Create() != NULL)
1395         myResult = pPresent->_this();
1396       else {
1397         pPresent->_remove_ref();
1398         myResult = VISU::Table::_nil();
1399       }
1400     }
1401
1402     virtual
1403     bool
1404     isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1405     {
1406       int aCols = theTableOfReal->GetNbColumns();
1407       int aRows = theTableOfReal->GetNbRows();
1408       
1409       for (int i=1; i<=aCols; i++) {
1410         for (int j=1; j<=aRows; j++) {
1411           if ( !(theTableOfReal->HasValue(j, i)) )
1412             return false;
1413         }
1414       }
1415       return true;
1416     }
1417   };
1418
1419   //---------------------------------------------------------------
1420   Table_ptr
1421   VISU_Gen_i
1422   ::CreateTable(const char* theTableEntry)
1423   {
1424     TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1425     if( myStudyDocument->GetProperties()->IsLocked() ||
1426         tmp.Length()==0 )
1427       return Table::_nil();
1428
1429     return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1430   }
1431
1432   //---------------------------------------------------------------
1433   Curve_ptr
1434   VISU_Gen_i
1435   ::CreateCurve(Table_ptr theTable,
1436                 CORBA::Long theHRow,
1437                 CORBA::Long theVRow)
1438   {
1439     return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1440   }
1441
1442
1443   //---------------------------------------------------------------
1444   Curve_ptr
1445   VISU_Gen_i
1446   ::CreateCurveWithZ(Table_ptr theTable,
1447                      CORBA::Long theHRow,
1448                      CORBA::Long theVRow,
1449                      CORBA::Long theZRow)
1450   {
1451     return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1452   }
1453
1454
1455   //---------------------------------------------------------------
1456   Curve_ptr
1457   VISU_Gen_i
1458   ::CreateCurveWithZExt(Table_ptr theTable,
1459                         CORBA::Long theHRow,
1460                         CORBA::Long theVRow,
1461                         CORBA::Long theZRow,
1462                         CORBA::Boolean theIsV2)
1463   {
1464     if(myStudyDocument->GetProperties()->IsLocked())
1465       return Curve::_nil();
1466     Mutex mt(myMutex);
1467     PortableServer::POA_ptr aPOA = GetPOA();
1468     Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1469     Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1470     if(pPresent->Create() != NULL)
1471       return pPresent->_this();
1472     else{
1473       pPresent->_remove_ref();
1474       return VISU::Curve::_nil();
1475     }
1476   }
1477
1478
1479   //---------------------------------------------------------------
1480   Container_ptr
1481   VISU_Gen_i
1482   ::CreateContainer()
1483   {
1484     if(myStudyDocument->GetProperties()->IsLocked())
1485       return Container::_nil();
1486     Mutex mt(myMutex);
1487     Container_i* pPresent = new Container_i(myStudyDocument);
1488     if(pPresent->Create() != NULL)
1489       return pPresent->_this();
1490     else{
1491       pPresent->_remove_ref();
1492       return VISU::Container::_nil();
1493     }
1494   }
1495
1496
1497   //---------------------------------------------------------------
1498   Animation_ptr
1499   VISU_Gen_i
1500   ::CreateAnimation(View3D_ptr theView3D)
1501   {
1502     if(myStudyDocument->GetProperties()->IsLocked())
1503       return Animation::_nil();
1504     Mutex mt(myMutex);
1505     if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1506       return anAnim->_this();
1507     }else
1508       return VISU::Animation::_nil();
1509   }
1510
1511
1512   //---------------------------------------------------------------
1513   Evolution_ptr
1514   VISU_Gen_i
1515   ::CreateEvolution(XYPlot_ptr theXYPlot)
1516   {
1517     if(myStudyDocument->GetProperties()->IsLocked())
1518       return Evolution::_nil();
1519     Mutex mt(myMutex);
1520     if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1521       return anEvolution->_this();
1522     }else
1523       return VISU::Evolution::_nil();
1524   }
1525
1526
1527   //---------------------------------------------------------------
1528   void
1529   VISU_Gen_i
1530   ::DeleteResult (Result_ptr theResult)
1531   {
1532     theResult->RemoveFromStudy();
1533   }
1534
1535
1536   //---------------------------------------------------------------
1537   void
1538   VISU_Gen_i
1539   ::DeletePrs3d(Prs3d_ptr thePrs3d)
1540   {
1541     thePrs3d->RemoveFromStudy();
1542   }
1543
1544
1545   //---------------------------------------------------------------
1546   void
1547   VISU_Gen_i
1548   ::Close(SALOMEDS::SComponent_ptr theComponent)
1549   {
1550     if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( theComponent ) && 
1551          myStudyDocument->StudyId() == theComponent->GetStudy()->StudyId())
1552       myStudyDocument = SALOMEDS::Study::_nil();
1553   }
1554
1555
1556   //---------------------------------------------------------------
1557   char* 
1558   VISU_Gen_i
1559   ::ComponentDataType()
1560   {
1561     return CORBA::string_dup("VISU");
1562   }
1563
1564
1565   //---------------------------------------------------------------
1566   bool
1567   VISU_Gen_i
1568   ::CanPublishInStudy(CORBA::Object_ptr theIOR) 
1569   {
1570     Result_var aResultObj = Result::_narrow(theIOR);
1571     return !(aResultObj->_is_nil());
1572   }
1573
1574
1575   //---------------------------------------------------------------
1576   SALOMEDS::SObject_ptr
1577   VISU_Gen_i
1578   ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1579                    SALOMEDS::SObject_ptr theSObject,
1580                    CORBA::Object_ptr theObject,
1581                    const char* theName)
1582     throw (SALOME::SALOME_Exception)
1583   {
1584     Unexpect aCatch(SalomeException);
1585     if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1586     Mutex mt(myMutex);
1587     SALOMEDS::SObject_var aResultSO;
1588     Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1589     if (!aResultObj) 
1590       return aResultSO._retn();
1591     const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1592     CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1593     aResultSO = theStudy->FindObjectID(anEntry);
1594     return aResultSO._retn();
1595   }
1596
1597
1598   //---------------------------------------------------------------
1599   CORBA::Boolean 
1600   VISU_Gen_i
1601   ::CanCopy(SALOMEDS::SObject_ptr theObject) 
1602   {
1603     CORBA::Object_var anObj = SObjectToObject(theObject);
1604     if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1605       return aStorable->CanCopy(theObject);
1606
1607     return false;
1608   }
1609
1610
1611   //---------------------------------------------------------------
1612   SALOMEDS::TMPFile* 
1613   VISU_Gen_i
1614   ::CopyFrom(SALOMEDS::SObject_ptr theObject, 
1615              CORBA::Long& theObjectID) 
1616   {
1617     theObjectID = 0;
1618     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1619
1620     CORBA::Object_var anObj = SObjectToObject(theObject);
1621     if (CORBA::is_nil(anObj)) {
1622       aStreamFile->length(1);
1623       aStreamFile[0] = CORBA::string_dup("E")[0];
1624     } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1625       std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1626       Storable::TFileNames aFileNames;
1627       bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1628
1629       SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1630       aListOfFileNames->length(aFileNames.size());
1631       for(size_t anId = 0; anId < aFileNames.size(); anId++)
1632         aListOfFileNames[anId] = aFileNames[anId].c_str();
1633
1634       if(anIsDone)
1635         aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1636
1637       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1638     }
1639     return aStreamFile._retn();
1640   }
1641
1642
1643   //---------------------------------------------------------------
1644   CORBA::Boolean 
1645   VISU_Gen_i
1646   ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1647     // The VISU component can paste only objects copied by VISU component
1648     CORBA::String_var aString = ComponentDataType();
1649     if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1650       return true;
1651     return false;
1652   }
1653
1654
1655   //---------------------------------------------------------------
1656   SALOMEDS::SObject_ptr
1657   VISU_Gen_i
1658   ::PasteInto(const SALOMEDS::TMPFile& theStream,
1659               CORBA::Long theObjectID,
1660               SALOMEDS::SObject_ptr theSObject)
1661   {
1662     if (theObjectID != 1)
1663       return SALOMEDS::SObject::_nil();
1664
1665     SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1666     SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1667     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1668     CORBA::String_var aComponentID(aComponent->GetID());
1669     CORBA::String_var aSObjectID(theSObject->GetID());
1670     
1671     SALOMEDS::SObject_var aSObject;
1672     if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1673       aSObject = aStudyBuilder->NewObject(aComponent);
1674     else
1675       aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1676     
1677     std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1678     SALOMEDS::ListOfFileNames_var aListOfFileNames = 
1679       SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1680     if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1681     
1682     std::ostringstream aLocalPersistentID;
1683     {
1684       std::string aCopyPersist =  aTmpDir + "copy_persistent";
1685       std::ifstream anInputFileStream( aCopyPersist.c_str() );
1686       anInputFileStream >> aLocalPersistentID.rdbuf();
1687     }
1688     
1689     //Just for Result::Restore to find the Comment attribute :(
1690     SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1691     
1692     std::string aFileName(aTmpDir);
1693     if(aListOfFileNames->length() > 1)
1694       aFileName += aListOfFileNames[1].in();
1695     Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1696     
1697     SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1698     aFilesToRemove->length(1);
1699     aFilesToRemove[0] = aListOfFileNames[0];
1700     SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1701     
1702     anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1703     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1704     CORBA::String_var anIORValue(aStorable->GetID());
1705     anIOR->SetValue(anIORValue);
1706     
1707     return aSObject._retn();
1708   }
1709
1710
1711   //---------------------------------------------------------------
1712   VISU::ColoredPrs3dCache_ptr
1713   VISU_Gen_i
1714   ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1715   {
1716     return ColoredPrs3dCache_i::GetInstance(theStudy);
1717   }
1718
1719     
1720   CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double  Y, CORBA::Double Z, 
1721                                               CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, 
1722                                               CORBA::Boolean isAuto, const char* name)
1723   {
1724     return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1725   }
1726
1727     
1728   void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double  Y, CORBA::Double Z, 
1729                                      CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, 
1730                                      CORBA::Boolean isAuto, const char* name)
1731   {
1732     myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1733   }
1734   
1735     /* Returns clipping plane by its Id */
1736   VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1737   {
1738     VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1739     
1740     if (aPlane != NULL) {
1741       double aOrigin[3];
1742       double aDir[3];
1743       aPlane->GetOrigin(aOrigin);
1744       aPlane->GetNormal(aDir);
1745
1746       VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1747       aRetPlane->X = aOrigin[0];
1748       aRetPlane->Y = aOrigin[1];
1749       aRetPlane->Z = aOrigin[2];
1750       aRetPlane->dX = aDir[0];
1751       aRetPlane->dY = aDir[1];
1752       aRetPlane->dZ = aDir[2];
1753       aRetPlane->isAuto = aPlane->isAuto();
1754
1755       aRetPlane->name = aPlane->getName().c_str();
1756       return aRetPlane;
1757     }
1758     return NULL;
1759   }
1760     
1761     /* Deletes clipping plane by its Id */
1762   CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1763   {
1764     return myClippingPlaneMgr.DeleteClippingPlane(id);
1765   }
1766     
1767     /* Applyes a clipping plane with Id to presentation thePrs */
1768   CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1769   {
1770     VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1771     return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1772   }
1773
1774     /* Detaches a clipping plane with Id from presentation thePrs */
1775   CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1776   {
1777     VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1778     return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1779   }
1780     
1781     /* Get number of clipping planes */
1782   CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1783   {
1784     return myClippingPlaneMgr.GetClippingPlanesNb();
1785   }
1786
1787   /*!
1788   \brief Converts set of VTK files to the one MED-file
1789   \param theVTKFiles sequence of VTK files
1790   \param theMEDFile MED-file
1791   \param theMeshName mesh name. This parameter can be empty. In this case name
1792          of mesh is equal vtk2med
1793   \param theTStamps values of time stamps. This array can be empty, in
1794          this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1795   \return TRUE if operation has been completed successfully, FALSE otherwise
1796   */
1797   CORBA::Boolean
1798   VISU_Gen_i
1799   ::VTK2MED( const VISU::string_array& theVTKFiles,
1800              const char* theMEDFile,
1801              const char* theMeshName,
1802              const VISU::double_array& theTStamps )
1803   {
1804     if ( !theMEDFile || !theVTKFiles.length() )
1805       return false;
1806
1807     VISU_Vtk2MedConvertor aConvertor;
1808     aConvertor.setMEDFileName( theMEDFile );
1809     // std::string aFirstFile = theVTKFiles[ 0 ];
1810     char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1811     aConvertor.setFirstVTKFileName( aFirstFile );
1812     if ( theVTKFiles.length() > 1 )
1813     {
1814       VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1815       for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1816         aFiles[ i - 1 ] = theVTKFiles[ i ];
1817       aConvertor.setDataVTKFileNames( aFiles );
1818     }
1819     if ( theTStamps.length() > 0 )
1820     {
1821       VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1822       for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1823         aTStamps[ i ] = theTStamps[ i ];
1824       aConvertor.setTimeStamps( aTStamps );
1825     }
1826
1827     if ( theMeshName && strlen( theMeshName ) > 0 )
1828       aConvertor.setMeshName( theMeshName );
1829
1830     aConvertor.addToIgnoringFieldList("cellID");
1831     aConvertor.setCellDataFieldNameIDS("cellID");
1832
1833     int res = aConvertor.Execute();
1834
1835     return res == 0;
1836   }
1837
1838   CORBA::Long
1839   VISU_Gen_i
1840   ::LoadTexture(const char* theTextureFile)
1841   {
1842     if( CORBA::is_nil( myStudyDocument ) )
1843       return 0;
1844
1845     int aStudyId = myStudyDocument->StudyId();
1846
1847     VTK::MarkerTexture aMarkerTexture;
1848     if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1849       return 0;
1850
1851     VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1852     int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1853
1854     VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1855     aMarkerData.first = theTextureFile;
1856     aMarkerData.second = aMarkerTexture;
1857
1858     return aMarkerId;
1859   }
1860 }