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