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