Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISU_I / VISU_Gen_i.cc
index 000c07f615883b526b12b3fe10b2d84556ab2f22..c5a950cc427b8c7462ddfb5d9f007d1ba927e70d 100644 (file)
-using namespace std;
-// File :      VISU_Gen_i.cc file 
-// Created :   
-// Author :    Alexey Petrov
-// Project :   SALOME
-// Copyright : OPEN CASCADE
-// $Header: 
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//  File   : VISU_Gen_i.cc
+//  Author : Alexey PETROV
+//  Module : VISU
 
 #include "VISU_Gen_i.hh"
 #include "VISU_Result_i.hh"
-#include "VISU_Convertor.hxx"
 #include "VISU_PrsObject_i.hh"
 #include "VISU_ViewManager_i.hh"
+
+#include "VISU_Prs3d_i.hh"
+#include "VISU_Mesh_i.hh"
+#include "VISU_ScalarMap_i.hh"
+#include "VISU_IsoSurfaces_i.hh"
+#include "VISU_DeformedShape_i.hh"
+#include "VISU_CutPlanes_i.hh"
+#include "VISU_CutLines_i.hh"
+#include "VISU_Vectors_i.hh"
+#include "VISU_StreamLines_i.hh"
+#include "VISU_GaussPoints_i.hh"
+#include "VISU_Plot3D_i.hh"
 #include "VISU_Table_i.hh"
+#include "VISU_TimeAnimation.h"
+#include "VISU_ScalarMapOnDeformedShape_i.hh"
+
+#include "VISU_Actor.h"
 
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
-#include "QAD_Study.h"
+#include "HDFascii.hxx"
 #include "SALOMEDS_Tool.hxx"
-#include <strstream>   
-#include <TCollection_AsciiString.hxx>
-#include <TColStd_SequenceOfAsciiString.hxx>
-#include <vtkUnstructuredGridReader.h>
-#include <vtkUnstructuredGridWriter.h>
 
-#include <omnithread.h>        
+#include "SALOMEDSClient_AttributeName.hxx"
+#include "SALOMEDSClient_AttributePixMap.hxx"
+
+#include "SUIT_Session.h"
+#include "SalomeApp_Study.h"
+#include "SalomeApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SVTK_ViewModel.h"
+#include "SVTK_ViewWindow.h"
+#include "SALOME_Event.hxx"
+#include "SALOME_ListIO.hxx"
+#include "SALOME_ListIteratorOfListIO.hxx"
+
+#include "utilities.h"
+
+// IDL Headers
+#include <omnithread.h>
 #include CORBA_SERVER_HEADER(SALOME_Session)
+#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
 
+// QT Includes
 #include <qstring.h>
 #include <qfileinfo.h>
+
+// VTK Includes
+#include <vtkRenderer.h>
+#include <vtkActorCollection.h>
+
+// OCCT Includes
+#include <TCollection_AsciiString.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
+
+// STL Includes
+#include <strstream>
+
+#include "Utils_ExceptHandlers.hxx"
+#include "CASCatch.hxx"
+
+using namespace std;
+
 static QFileInfo aFileInfo;
 
-#ifdef DEBUG
-static int MYDEBUG = 1;
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+//#define _DEXCEPT_
 #else
 static int MYDEBUG = 0;
 #endif
 
-#include <utilities.h>
+UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
+
+extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
+                                     PortableServer::POA_ptr thePOA,
+                                     SALOME_NamingService* theNamingService,
+                                     QMutex* theMutex)
+{
+  if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
+  VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
+  //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
+  return aVISU_Gen->_this();
+}
 
-//static int IS_LOADED = (cout<<"\n----------------- VisuEngine_factory is loaded -----------------\n", 1);
-extern "C" {
-  PortableServer::ObjectId * 
-  VISUEngine_factory(CORBA::ORB_ptr orb,
-                    PortableServer::POA_ptr poa, 
-                    PortableServer::ObjectId * contId,
-                    const char *instanceName, 
-                    const char *interfaceName)
-  {
-    if(MYDEBUG) MESSAGE("VisuEngine_factory : "<<interfaceName);
-    VISU::VISU_Gen_i * pVISU_Gen = new VISU::VISU_Gen_i(orb, poa, contId, instanceName, interfaceName);
-    return pVISU_Gen->getId() ;
-  }
+namespace VISU
+{
+  static string VisuTmpDir;
 
-  //    VISU::VISU_Gen_ptr  
-  //    GetVisuGen(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex* theMutex){
-  //      if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen");
-  //      VISU::VISU_Gen_i * aVISU_Gen = new VISU::VISU_Gen_i(orb,poa,theMutex);
-  //      return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this()); 
-  //    }
-  
-  Engines::Component_ptr GetVisuGen(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, QMutex* theMutex){
-    if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen");
-    VISU::VISU_Gen_i * aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theMutex);
-    VISU::VISU_Gen_var aVisuGen = VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
-    return Engines::Component::_narrow( aVisuGen );
-  }
-}
+  static CORBA::Boolean myIsMultiFile;
+  const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
 
-namespace VISU{
   //===========================================================================
-  QMutex* Base_i::myMutex = NULL;
-  CORBA::ORB_var Base_i::myOrb;
-  PortableServer::POA_var Base_i::myPOA;
-  Base_i::~Base_i() {}
-  char* Base_i::GetID(){ 
-    //CORBA::Object_var anObject = _this();
-    //return CORBA::string_dup(myOrb->object_to_string(anObject));
-    return CORBA::string_dup(myOrb->object_to_string(_this()));
-  }
-  //===========================================================================
-  static int mySCnt = 0;
-  static int myQCnt = 0;
-  Mutex::Mutex(QMutex* theMutex, QApplication* theQApp) :
-    myQApp(theQApp), isQAppLocked(theQApp->locked()), 
-    myMutex(theMutex), isSessionLocked(theMutex->locked())
+  _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
   {
-    if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<!isQAppLocked<<" "<<!isSessionLocked);
-    if(!isSessionLocked) { myMutex->lock(); mySCnt++; }
-    if(!isQAppLocked) { myQApp->lock(); myQCnt++; }
-    //myQApp->syncX();
-    //if(MYDEBUG) MESSAGE("Mutex::Mutex - "<<myQCnt<<" "<<mySCnt);
-  }
-  Mutex::~Mutex(){
-    if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<!isQAppLocked<<" "<<!isSessionLocked);
-    //myQApp->syncX();
-    if(!isQAppLocked) { myQApp->unlock(); myQCnt--; }
-    if(!isSessionLocked) { myMutex->unlock(); mySCnt--; }
-    //if(MYDEBUG) MESSAGE("Mutex::~Mutex - "<<myQCnt<<" "<<mySCnt);
-    // myQApp->processEvents(); myQApp->processEvents(); myQApp->processEvents();
-  }
-  //===========================================================================
-  static Storable::TCallbackMap VisuStoreMap;
-  const char* Storable::ToString(){
-    ostrstream strOut;
-    Storable::DataToStream( strOut, "myComment", GetComment() );
-    ToStream(strOut);
-    strOut<<ends;
-    if(MYDEBUG) MESSAGE("Storable::ToString - "<<strOut.str());
-    return strOut.str(); 
-  }
-  void Storable::Registry(const char* theComment, TStorableEngine theEngine)
-    throw(std::logic_error&)
-      {
-       if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){
-         if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!");
-         throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
-       }
-      }
-  void RegistryStorable() throw(std::logic_error&) {
-    //Storable::Registry(View3D_i::myComment.c_str(),&View3DRestore);
-    Storable::Registry(Result_i::myComment.c_str(),&ResultRestore);
-    Storable::Registry(Mesh_i::myComment.c_str(),&MeshRestore);
-    Storable::Registry(ScalarMap_i::myComment.c_str(),&ScalarMapRestore);
-    Storable::Registry(DeformedShape_i::myComment.c_str(),&DeformedShapeRestore);
-    Storable::Registry(CutPlanes_i::myComment.c_str(),&CutPlanesRestore);
-    Storable::Registry(IsoSurfaces_i::myComment.c_str(),&IsoSurfacesRestore);
-    Storable::Registry(StreamLines_i::myComment.c_str(),&StreamLinesRestore);
-    Storable::Registry(Vectors_i::myComment.c_str(),&VectorsRestore);
-    Storable::Registry(Table_i::myComment.c_str(),&TableRestore);
-    Storable::Registry(Curve_i::myComment.c_str(),&CurveRestore);
-    Storable::Registry(Container_i::myComment.c_str(),&ContainerRestore);
-  }
-
-  SALOMEDS::SObject_ptr Storable::GetResultSO(SALOMEDS::SObject_ptr theSObject) {
-    CORBA::String_var aComponentID(theSObject->GetFatherComponent()->GetID());
-    SALOMEDS::SObject_var aResult = SALOMEDS::SObject::_duplicate(theSObject);
-    CORBA::String_var aFatherID(aResult->GetFather()->GetID());
-    while(strcmp(aComponentID, aFatherID)) {
-      aResult = aResult->GetFather();
-      aFatherID = aResult->GetFather()->GetID();
-      if (strlen(aFatherID) < 3) break;
-    }
-    return aResult._retn();
-  }
+    _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
+    if (!aSComponent) {
+      _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
+      aStudyBuilder->NewCommand();
+      int aLocked = theStudyDocument->GetProperties()->IsLocked();
+      if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
+      aSComponent = aStudyBuilder->NewComponent("VISU");
+      _PTR(GenericAttribute) anAttr =
+       aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
+      _PTR(AttributeName) aName (anAttr);
 
-  void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){
-    if(MYDEBUG) MESSAGE("Storable::StrToMap : string="<<theStr);
-    QStringList strList = QStringList::split( ";", theStr, false );
-    for ( int i = 0; i < strList.count(); i++ ) {
-      QString next = strList[ i ];
-      int pos = next.find("=");
-      QString aName, aValue;
-      if ( pos < 0 ) {
-       aName = next.stripWhiteSpace();
-       aValue = "";
-      }
-      else {
-       aName = next.left( pos ).stripWhiteSpace();
-       aValue = next.mid( pos+1 );
-       if ( aValue.isNull() )
-         aValue = "";
-      }
-      if ( !aName.isEmpty() )
-       theMap.insert( TRestoringMap::value_type( aName.latin1(), aValue ) );   
-    }
-  }
-  void Storable::DataToStream(ostrstream& theStr, const QString& theName, const QString& theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
-                  + ( !theVal.isNull()  ? theVal  : QString("") );
-    theStr<<output.latin1()<<";";
-  }
-  void Storable::DataToStream(ostrstream& theStr, const QString& theName, const int theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
-                  + QString::number( theVal );
-    theStr<<output.latin1()<<";";
-  }
-  void Storable::DataToStream(ostrstream& theStr, const QString& theName, const double theVal) {
-    QString output = ( !theName.isNull() ? theName : QString("") ) 
-                   + QString( "=" ) 
-                  + QString::number( theVal );
-    theStr<<output.latin1()<<";";
-  }
-  Storable* Storable::Create(SALOMEDS::SObject_ptr theSObject,
-                            const string& thePrefix, const string& theLocalPersistentID) 
-    throw (std::runtime_error&)
-      {
-       try{
-         QString strIn( theLocalPersistentID.c_str() );
-         TRestoringMap aMap;
-         StrToMap(strIn,aMap);
-         //CORBA::String_var aResultID(GetResultSO(theSObject)->GetID());
-         //aMap.insert(TRestoringMap::value_type("ResultID", strdup(aResultID)));
-         bool isExist;
-         QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist);
-         if ( isExist ) {
-           TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1());
-           if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.latin1()<<" "<<(i != VisuStoreMap.end()));
-           if(i == VisuStoreMap.end()) return NULL;
-           return (i->second)(theSObject,thePrefix,aMap);
-         }
-       }catch(std::logic_error& exc){
-         MESSAGE("Follow exception was accured :\n"<<exc.what());
-       }catch(...){
-         MESSAGE("Unknown exception was accured!");
-       }
-       return NULL;
-      }
-  const QString& Storable::FindValue(const TRestoringMap& theMap, const string& theArg, bool* isFind)
-    throw(std::logic_error&)
-      {
-       TRestoringMap::const_iterator i = theMap.find(theArg);
-       if(i == theMap.end()) {
-         if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
-         if(isFind != NULL) *isFind = false;
-         //throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
-         static QString BAD_VALUE("NULL");
-         return BAD_VALUE;
-       }
-       if(isFind != NULL) *isFind = true;
-       return i->second;
+      CORBA::ORB_var anORB = Base_i::GetORB();
+      SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
+      CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
+      SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
+       SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
+      SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
+      if (!Comp->_is_nil()) {
+       aName->SetValue(Comp->componentusername());
       }
 
-  //===========================================================================
-  PortableServer::Servant GetServant(CORBA::Object_ptr theObject){
-    PortableServer::POA_var aPOA = GetPOA();
-    if(CORBA::is_nil(theObject)) 
-      if(MYDEBUG) MESSAGE("GetServant - CORBA::is_nil(theObject)");
-    return aPOA->reference_to_servant(theObject);
-  }
-  //===========================================================================
-  CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){
-    SALOMEDS::GenericAttribute_var anAttr;
-    CORBA::Object_var anObj;
-    if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
-      SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow(anAttr);
-      CORBA::String_var aValue = anIOR->Value();
-      CORBA::ORB_var anORB = GetORB();
-      if(strcmp(aValue,"") != 0)
-       anObj = anORB->string_to_object(aValue);
+      anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
+      _PTR(AttributePixMap) aPixmap (anAttr);
+      aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
+
+      VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
+      aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
+      if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
+      aStudyBuilder->CommitCommand();
     }
-    return anObj;
+    return aSComponent;
   }
-  //===========================================================================
+
   SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
     SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
     if (aSComponent->_is_nil()) {
@@ -251,12 +161,12 @@ namespace VISU{
       aStudyBuilder->NewCommand();
       int aLocked = theStudyDocument->GetProperties()->IsLocked();
       if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
-      aSComponent = aStudyBuilder->NewComponent("VISU"); 
+      aSComponent = aStudyBuilder->NewComponent("VISU");
       SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      //NRI      aName->SetValue("Visu");
 
-      CORBA::ORB_var anORB = GetORB();
+      //NRI      aName->SetValue("Visu");
+      CORBA::ORB_var anORB = Base_i::GetORB();
       SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
       CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
       SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
@@ -268,541 +178,643 @@ namespace VISU{
       anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
       SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
       aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
-      
-      VISU_Gen_var aVisuGen = GetVisu();
+
+      VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
       aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
       if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
       aStudyBuilder->CommitCommand();
     }
     return aSComponent;
   }
+
+  void RegistryStorable() {
+    Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
+    Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
+    Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
+    Storable::Registry(GaussPoints_i::myComment.c_str(),&(Restore<GaussPoints_i>));
+    Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
+    Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
+    Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
+    Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
+    Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
+    Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore<Plot3D_i>));
+    Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
+    Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
+    Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
+    Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
+    Storable::Registry(ScalarMapOnDeformedShape_i::myComment.c_str(),&(Restore<ScalarMapOnDeformedShape_i>));
+  }
+
+
   //===========================================================================
-  string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
-                                  const char* theComment, int IsAllLevels)
-    {
-      if(MYDEBUG) MESSAGE("FindEntryWithComment - '"<<theComment<<"'");
-      SALOMEDS::ChildIterator_var anIter = 
-       theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
-      anIter->InitEx(IsAllLevels);
-      SALOMEDS::SObject_var aFieldSO;
-      for(;anIter->More();anIter->Next()) {
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) {
-         SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
-         CORBA::String_var aString = aCmnt->Value();
-         string aValue(aString);
-         if (aValue == theComment) {
-           aFieldSO = anIter->Value();
-           aString = aFieldSO->GetID();
-           aValue = aString;
-           return aValue;
-         }
-       }
-      }
-      return "";
-    }
-  //===========================================================================
-  string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument, 
-                              const char* theFatherEntry, const char* theRefFatherEntry,
-                              const char* theIOR, const char* theName, 
-                              const char* thePersistentRef, const char* theComment,
-                              CORBA::Boolean theCreateNew)
-    {
-      if(MYDEBUG) 
-       MESSAGE("CreateAttributes - theName = "<<theName<<"; theComment = '"<<theComment<<
-               "'; theFatherEntry = "<<theFatherEntry);
-      SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
-      SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry);
-      SALOMEDS::SObject_var newObj;
-      if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather);
-      else newObj = aFather;
-      SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
-      SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-      anIOR->SetValue(theIOR); 
-      anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
-      SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      aName->SetValue(theName); 
-      anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
-      SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
-      aPRef->SetValue(thePersistentRef); 
-      anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
-      SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
-      aCmnt->SetValue(theComment);
-      if(strcmp(theRefFatherEntry,"") != 0){
-       SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
-       SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather);
-       aStudyBuilder->Addreference(anObj,newObj);
+  VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
+                        SALOME_NamingService* theNamingService, QMutex* theMutex) :
+    Engines_Component_i()
+  {
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
+    Base_i::myMutex = theMutex;  //apo
+    Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
+    Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
+    Base_i::myNamingService = theNamingService;
+    static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
+    Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
+    Base_i::myVisuGenImpl = this;
+    RegistryStorable();
+
+    CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
+    SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
+    SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
+    if(aListOfOpenStudies->length() > 0) {
+      CORBA::String_var aStudyName = aListOfOpenStudies[0];
+      //aFileInfo.setFile(aStudyName.in());
+      myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
+    }else
+      if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
+  }
+
+  bool
+  CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
+                   const char* theMeshName, 
+                   VISU::Entity theEntity,
+                   const char* theFieldName, 
+                   CORBA::Double theIteration)
+  {
+    CASCatch_TRY{       
+#ifndef _DEXCEPT_
+      try{
+#endif
+       if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration)))
+         return true;
+#ifndef _DEXCEPT_
+      }catch(std::exception& exc){
+       INFOS("Follow exception was occured :\n"<<exc.what());
+      }catch(...){
+       INFOS("Unknown exception was occured!");
       }
-      CORBA::String_var anEntry = newObj->GetID();
-      string aRet(anEntry);
-      if(MYDEBUG) MESSAGE("CreateAttributes - anEntry = "<<aRet<<"; IOR = "<<theIOR);
-      return aRet;
+#endif
+    }CASCatch_CATCH(Standard_Failure) {
+      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+      INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
     }
-  //===========================================================================
-  static CORBA::ORB_var VisuORB;
-  static PortableServer::POA_var VisuPOA;
-  static SALOMEDS::SComponent_var VisuSComponent;
-  static string VisuTmpDir;
-  static VISU_Gen_i* VisuGen;
-  static CORBA::Boolean myIsMultiFile;
-  CORBA::ORB_var GetORB() { return VisuORB;}
-  PortableServer::POA_var GetPOA() { return VisuPOA;}
-  VISU_Gen_var GetVisu() { 
-    return VISU_Gen::_duplicate(VisuGen->_this());
-    //return VisuGen->_this();
+    return false;
+  }
+
+  VISU_Gen_i::~VISU_Gen_i(){
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
   }
-  const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
   //===========================================================================
-  bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
-                     const SALOMEDS::TMPFile & theStream,
-                     const char* theURL,
-                     bool isMultiFile)
+  CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
+                                 const SALOMEDS::TMPFile & theStream,
+                                 const char* theURL,
+                                 bool isMultiFile)
   {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      SALOMEDS::Study_var aStudy = theComponent->GetStudy(); 
-      SALOMEDS::StudyBuilder_var  aStudyBuilder = aStudy->NewBuilder(); 
-      TCollection_AsciiString aTmpDir =
-       isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
-      VisuSComponent = SALOMEDS::SComponent::_duplicate(theComponent);
-      VisuTmpDir = aTmpDir.ToCString();
-      SALOMEDS::ListOfFileNames_var aSeq =
-       SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
-      myIsMultiFile = isMultiFile;
-      return true;
-    }
-    return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
+    Mutex mt(myMutex);
+    SALOMEDS::Study_var aStudy = theComponent->GetStudy();
+    SALOMEDS::StudyBuilder_var  aStudyBuilder = aStudy->NewBuilder();
+    string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
+    TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
+    VisuTmpDir = aTmpDir.ToCString();
+    SALOMEDS::ListOfFileNames_var aSeq =
+      SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
+    myIsMultiFile = isMultiFile;
+    return true;
+  }
+
+  CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
+                                      const SALOMEDS::TMPFile & theStream,
+                                      const char* theURL,
+                                      bool isMultiFile)
+  {
+    return Load(theComponent, theStream, theURL, isMultiFile);
   }
 
   char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
                                           const char* aLocalPersistentID,
-                                          CORBA::Boolean isMultiFile) {
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      CORBA::String_var aString("");
-      if(strcmp(aLocalPersistentID,"") != 0) {
-       Storable* aStorable =
-         Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
-       if(aStorable != NULL) aString = aStorable->GetID();
-      }
-      return aString._retn();
+                                          CORBA::Boolean isMultiFile,
+                                          CORBA::Boolean isASCII)
+  {
+    CORBA::String_var aString("");
+    if(strcmp(aLocalPersistentID,"") != 0) {
+      Mutex mt(myMutex);
+      Storable* aStorable =
+       Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
+      if(aStorable != NULL) aString = aStorable->GetID();
     }
-    return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile);
+    return aString._retn();
   }
   //===========================================================================
   SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
-                                   const char* theURL,
-                                   bool isMultiFile)
+                                     const char* theURL,
+                                     bool theIsMultiFile)
   {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      TCollection_AsciiString aTmpDir =
-       (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
-      if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
-      int aCounter = 0;
-      TColStd_SequenceOfAsciiString aFileNames;
-      SALOMEDS::Study_var aStudy = theComponent->GetStudy(); 
-      SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
-      for (; itBig->More(); itBig->Next()) {
-       SALOMEDS::SObject_var gotBranch = itBig->Value();
-       CORBA::Object_var anObj = SObjectToObject(gotBranch);
-       if(CORBA::is_nil(anObj)) continue;
-       Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
-       if(pResult){
+    Mutex mt(myMutex);
+    string aTmpDir = theURL;
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
+    
+    typedef std::vector<std::string> TFileNames;
+    TFileNames aFileNames;
+    TFileNames aFiles;
+
+    SALOMEDS::Study_var aStudy = theComponent->GetStudy();
+    SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
+    for (; anIter->More(); anIter->Next()) {
+      SALOMEDS::SObject_var gotBranch = anIter->Value();
+      CORBA::Object_var anObj = SObjectToObject(gotBranch);
+      if(CORBA::is_nil(anObj)) continue;
+      if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
+       switch(aResult->GetCreationId()){
+       case Result_i::eImportFile:
+       case Result_i::eCopyAndImportFile: {
+         const QFileInfo& aFileInfo = aResult->GetFileInfo();
+         const std::string& aName = aResult->GetName();
+         std::string aFileName = std::string("_") + aName;
+         std::string aFile = aFileInfo.filePath().latin1();
+         if(theIsMultiFile){
+           aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()) + aFileName;
+
+           std::ostringstream aStream;
+           aStream<<"cp "<<aFile<<" "<<aTmpDir<<aFileName;
+           std::string aCommand = aStream.str();
+           if(system(aCommand.c_str()) != 0){
+             INFOS("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
+             continue;
+           }
+         }
+         aFileNames.push_back(aFileName);
+         aFiles.push_back(aFile);
+       }}
+      }
+    }
+
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
+
+    SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
+    if(!aFileNames.empty()){
+      aListOfFileNames->length(aFileNames.size());
+      for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
+       aListOfFileNames[aCounter-1] = aFileNames[aCounter-1].c_str();
+    }
+
+    SALOMEDS::ListOfFileNames_var aListOfFiles = new SALOMEDS::ListOfFileNames;
+    aListOfFiles->length(aFiles.size());
+    if(!aFiles.empty()){
+      for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
+       aListOfFiles[aCounter-1] = aFiles[aCounter-1].c_str();
+    }
+
+    SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
+    if(theIsMultiFile)
+      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFiles.in(), theIsMultiFile);
+    else
+      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
+
+    return aStreamFile._retn();
+  }
+
+  SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
+                                          const char* theURL,
+                                          bool isMultiFile)
+  {
+    Mutex mt(myMutex);
+    string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
+    TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
+    int aCounter = 0;
+    TColStd_SequenceOfAsciiString aFileNames;
+    SALOMEDS::Study_var aStudy = theComponent->GetStudy();
+    SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
+    for (; itBig->More(); itBig->Next()) {
+      SALOMEDS::SObject_var gotBranch = itBig->Value();
+      CORBA::Object_var anObj = SObjectToObject(gotBranch);
+      if(CORBA::is_nil(anObj)) continue;
+      if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
+       switch(pResult->GetCreationId()){
+       case Result_i::eImportFile:
+       case Result_i::eCopyAndImportFile: {
          const QFileInfo& aFileInfo = pResult->GetFileInfo();
-         QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
-         QString aFileName = aPrefix + "_" + pResult->GetName();
+         QString aPrefix("");
+         if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
+         QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
          static QString aCommand;
          aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
-         if(system(aCommand) == -1){
-           if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
+
+         int aRes = system(aCommand);
+         if(aRes){
+           if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
            continue;
          }else
            if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
+
          TCollection_AsciiString aString(strdup(aFileName.latin1()));
+
+         HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
+
          aFileNames.Append(aString);
-       }
+       }}
       }
-      SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
-      if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
-      if(aFileNames.Length() > 0){
-       SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
-       aSeq->length(aFileNames.Length());
-       for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
-         aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
-       aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
-       if(!isMultiFile)
-         SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
-      }
-      return aStreamFile._retn();
     }
-    return myVisuGen->Save(theComponent,theURL,isMultiFile);
+    SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
+    if(aFileNames.Length() > 0){
+      SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
+      aSeq->length(aFileNames.Length());
+      for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
+       aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
+      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
+      if(!isMultiFile)
+       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
+    }
+    return aStreamFile._retn();
   }
 
   char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                                           const char* IORString,
-                                          CORBA::Boolean isMultiFile) {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      CORBA::ORB_var anORB = GetORB();
-      CORBA::String_var aString(IORString);
-      if(strcmp(IORString,"") != 0){ 
-       CORBA::Object_var anObj = anORB->string_to_object(aString);
-       if(!CORBA::is_nil(anObj)){
-         Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj));
-         if(pStorable != NULL){
-           aString = pStorable->ToString();
-           return aString._retn();
-         }
+                                          CORBA::Boolean isMultiFile,
+                                          CORBA::Boolean isASCII)
+  {
+    CORBA::String_var aString(IORString);
+    if(strcmp(IORString,"") != 0){
+      CORBA::ORB_ptr anORB = GetORB();
+      CORBA::Object_var anObj = anORB->string_to_object(aString);
+      if(!CORBA::is_nil(anObj)){
+       if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
+         Mutex mt(myMutex);
+         aString = pStorable->ToString().c_str();
+         return aString._retn();
        }
       }
-      return aString._retn();
     }
-    return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile);
+    return aString._retn();
   }
 
-  //===========================================================================
-  VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
-                        PortableServer::POA_ptr poa,
-                        PortableServer::ObjectId * contId, 
-                        const char *instanceName, 
-                        const char *interfaceName) :
-    Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
-  {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
-    _thisObj = this ;
-    _id = _poa->activate_object(_thisObj);
-    SALOME_NamingService aNamingService(orb);
-    CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
-    SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
-    //aSession->GetInterface(); 
-    //myVisuGen = aSession->GetVisuGen();
-    myVisuGen = VISU::VISU_Gen::_narrow( aSession->GetVisuComponent() );
-  }
-  VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, QMutex* theMutex) :
-    Engines_Component_i()
-  {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
-    Base_i::myMutex = theMutex;
-    Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
-    Base_i::myPOA = PortableServer::POA::_duplicate(thePOA);
-    Mutex mt(myMutex,qApp);
-    VisuORB = theORB;
-    VisuPOA = thePOA;
-    VisuGen = this;
-    VisuPOA->activate_object(this);
-    RegistryStorable();
-    if(!QAD_Application::getDesktop()->getActiveStudy())
-      QAD_Application::getDesktop()->createStudy();
-    myStudyDocument = 
-      QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+  char* VISU_Gen_i::GetID(){
+    return Base_i::GetID();
   }
-  VISU_Gen_i::~VISU_Gen_i(){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
-  }
-  void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
-    //if(MYDEBUG) MESSAGE("VISU_Gen_i::SetCurrentStudy : "<<(!theStudy->_is_nil()));
-    if(myMutex)
+
+  void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
+  {
+    class TEvent: public SALOME_Event {
+      std::string myStudyName;
+    public:
+      TEvent(const std::string theStudyName):myStudyName(theStudyName)
+       {}
+      virtual void Execute()
+       {
+         bool isActive = false;
+         SUIT_Session* aSession = SUIT_Session::session();
+         QPtrList<SUIT_Application> anApplications = aSession->applications();
+         QPtrListIterator<SUIT_Application> anIter (anApplications);
+         SUIT_Application* aFirstApp = anIter.current();
+         while (SUIT_Application* anApp = anIter.current()) {
+           ++anIter;
+           if (SUIT_Study* aSStudy = anApp->activeStudy()) {
+             if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
+                if (_PTR(Study) aCStudy = aStudy->studyDS()) {
+                 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
+                                     << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
+                 if (myStudyName == aCStudy->Name()) {
+                   isActive = true;
+                   break;
+                 }
+               }
+             }
+           }
+         }
+         if (!isActive) {
+           MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
+           // Has to be loaded in an empty or in a new application
+           SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
+           anApp->onLoadDoc(myStudyName.c_str());
+         }
+       }
+    };
+
+    if (!CORBA::is_nil(theStudy))
+    {
+      CORBA::String_var aName = theStudy->Name();
+      std::string aStudyName (aName.in());
+      if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
       myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
-    else
-      myVisuGen->SetCurrentStudy(theStudy);
+
+      ProcessVoidEvent(new TEvent(aStudyName));
+    } else {
+      INFOS("CORBA::is_nil(theStudy)");
+    }
   }
+
   SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::GetCurrentStudy : "<<myMutex);
-    if(myMutex)
-      return SALOMEDS::Study::_duplicate(myStudyDocument);
-    return myVisuGen->GetCurrentStudy();
+    return SALOMEDS::Study::_duplicate(myStudyDocument);
   }
+
   ViewManager_ptr VISU_Gen_i::GetViewManager(){
-    //omni_mutex aMutex;
-    //omni_mutex_lock aMutexLock(aMutex);
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
-      return ViewManager::_duplicate(aViewManager->_this());
-    }
-    return myVisuGen->GetViewManager();
+    Mutex mt(myMutex);
+    ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
+    return ViewManager::_duplicate(aViewManager->_this());
   }
 
   SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
-      Mutex mt(myMutex,qApp);
-      SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
-      return aRes._retn();
-    }
-    return myVisuGen->ImportTables(theFileName);
+    if(myStudyDocument->GetProperties()->IsLocked())
+      return SALOMEDS::SObject::_nil();
+    Mutex mt(myMutex);
+    SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
+    return aRes._retn();
+  }
+
+  CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
+                                              const char* theFileName)
+  {
+    return VISU::ExportTableToFile(theTable, theFileName);
   }
 
   Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
-      Mutex mt(myMutex,qApp);
-      aFileInfo.setFile(theFileName);
-      Result_i* pResult = new Result_i(myStudyDocument);
-      if(pResult->Create(theFileName) != NULL) 
-       return Result::_duplicate(pResult->_this());
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Result::_nil();
+    Mutex mt(myMutex);
+    aFileInfo.setFile(theFileName);
+    Result_i* pResult = new Result_i(myStudyDocument,
+                                    Result_i::eFile,
+                                    Result_i::eImportFile);
+    if(pResult->Create(theFileName) != NULL)
+      return pResult->_this();
+    else{
+      pResult->_remove_ref();
+      return VISU::Result::_nil();
     }
-    return myVisuGen->ImportFile(theFileName);
-  }
-  Result_ptr VISU_Gen_i::ImportMed(SALOME_MED::FIELD_ptr theField){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = new Result_i(myStudyDocument);
-      if(pResult->Create(theField) != NULL) 
-       return Result::_duplicate(pResult->_this());
+  }
+
+  Result_ptr VISU_Gen_i::CreateResult(const char* theFileName){
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Result::_nil();
-    }
-    return myVisuGen->ImportMed(theField);
-  }
-  Result_ptr VISU_Gen_i::ImportMedMesh(SALOME_MED::MESH_ptr theMesh){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedMesh : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = new Result_i(myStudyDocument);
-      if(pResult->Create(theMesh) != NULL) 
-       return Result::_duplicate(pResult->_this());
+    Mutex mt(myMutex);
+    aFileInfo.setFile(theFileName);
+    Result_i* pResult = new Result_i(myStudyDocument,
+                                    Result_i::eFile,
+                                    Result_i::eImportFile,
+                                    false);
+    if(pResult->Create(theFileName) != NULL)
+      return pResult->_this();
+    else{
+      pResult->_remove_ref();
+      return VISU::Result::_nil();
+    }
+  }
+
+  Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Result::_nil();
-    }
-    return myVisuGen->ImportMedMesh(theMesh);
+    Mutex mt(myMutex);
+    VISU::Result_var aResult;
+    aFileInfo.setFile(theFileName);
+    Result_i* pResult = new Result_i(myStudyDocument,
+                                    Result_i::eRestoredFile,
+                                    Result_i::eCopyAndImportFile);
+    if(pResult->Create(theFileName) != NULL)
+      aResult = pResult->_this();
+    return aResult._retn();
   }
-  
-  Result_ptr VISU_Gen_i::ImportMedSupport(SALOME_MED::SUPPORT_ptr theSupport){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedSupport : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = new Result_i(myStudyDocument);
-      if(pResult->Create(theSupport) != NULL) 
-       return Result::_duplicate(pResult->_this());
+
+  Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject)
+  {
+    if (myStudyDocument->GetProperties()->IsLocked())
       return Result::_nil();
+    Mutex mt(myMutex);
+    Result_i* pResult = new Result_i(myStudyDocument,
+                                    Result_i::eComponent,
+                                    Result_i::eImportMed);
+    if (pResult->Create(theMedSObject) != NULL) {
+      return pResult->_this();
+    } else {
+      pResult->_remove_ref();
+      return VISU::Result::_nil();
     }
-    return myVisuGen->ImportMedSupport(theSupport);
   }
 
-  Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      Mesh_i* aPresent = new Mesh_i(pResult);
-      if(aPresent->Create(theMeshName,theEntity) != NULL) 
-        return Mesh::_duplicate(aPresent->_this());
-      return Mesh::_nil();
+  Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField)
+  {
+    if (myStudyDocument->GetProperties()->IsLocked())
+      return Result::_nil();
+    Mutex mt(myMutex);
+    Result_i* pResult = new Result_i(myStudyDocument,
+                                    Result_i::eComponent,
+                                    Result_i::eImportMedField);
+    if (pResult->Create(theField) != NULL) {
+      return pResult->_this();
+    } else {
+      pResult->_remove_ref();
+      return VISU::Result::_nil();
     }
-    return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
   }
 
-  Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName, 
-                                         VISU::Entity theEntity, 
-                                         const char* theFamilyName){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      Mesh_i* aPresent = new Mesh_i(pResult);
-      if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL) 
-        return Mesh::_duplicate(aPresent->_this());
+  Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
+                                   const char* theMeshName,
+                                   VISU::Entity theEntity)
+  {
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Mesh::_nil();
+    Mutex mt(myMutex);
+    if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
+      Mesh_i* aPresent = new Mesh_i(pResult);
+      if(aPresent->Create(theMeshName,theEntity) != NULL)
+       return aPresent->_this();
+      else{
+       aPresent->_remove_ref();
+      }
     }
-    return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
+    return VISU::Mesh::_nil();
   }
 
-  Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName, 
-                                const char* theGroupName){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      Mesh_i* aPresent = new Mesh_i(pResult);
-      if(aPresent->Create(theMeshName,theGroupName) != NULL) 
-        return Mesh::_duplicate(aPresent->_this());
+  Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
+                                         const char* theMeshName,
+                                         VISU::Entity theEntity,
+                                         const char* theFamilyName)
+  {
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Mesh::_nil();
-    }
-    return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
-  }
-
-  ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                            const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return ScalarMap::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(ScalarMap_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       ScalarMap_i* aPresent = new ScalarMap_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return ScalarMap::_duplicate(aPresent->_this());
-      }
-      return ScalarMap::_nil();
-    }
-    return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
-  }
-
-  DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                                    const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return DeformedShape::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(DeformedShape_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       DeformedShape_i* aPresent = new DeformedShape_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return DeformedShape::_duplicate(aPresent->_this());
-      }
-      return DeformedShape::_nil();
-    }
-    return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
-  }
-
-  Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                                    const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Vectors::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(Vectors_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       Vectors_i* aPresent = new Vectors_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return Vectors::_duplicate(aPresent->_this());
-      }
-      return Vectors::_nil();
-    }
-    return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
-  }
-
-  IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                                    const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return IsoSurfaces::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(IsoSurfaces_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       IsoSurfaces_i* aPresent = new IsoSurfaces_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return IsoSurfaces::_duplicate(aPresent->_this());
-      }
-      return IsoSurfaces::_nil();
-    }
-    return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
-  }
-
-  StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                                    const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return StreamLines::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(StreamLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       StreamLines_i* aPresent = new StreamLines_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return StreamLines::_duplicate(aPresent->_this());
+    Mutex mt(myMutex);
+    if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
+      Mesh_i* aPresent = new Mesh_i(pResult);
+      if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
+       return aPresent->_this();
+      else{
+       aPresent->_remove_ref();
       }
-      return StreamLines::_nil();
     }
-    return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
-  }
-
-  CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, 
-                                                    const char* theFieldName, CORBA::Double theIteration){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return CutPlanes::_nil();
-      Mutex mt(myMutex,qApp);
-      Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
-      if(CutPlanes_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
-       CutPlanes_i* aPresent = new CutPlanes_i(pResult);
-       if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) 
-         return CutPlanes::_duplicate(aPresent->_this());
+    return VISU::Mesh::_nil();
+  }
+
+  Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
+                                const char* theMeshName,
+                                const char* theGroupName)
+  {
+    if(myStudyDocument->GetProperties()->IsLocked())
+      return Mesh::_nil();
+    Mutex mt(myMutex);
+    if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
+      Mesh_i* aPresent = new Mesh_i(pResult);
+      if(aPresent->Create(theMeshName,theGroupName) != NULL)
+       return aPresent->_this();
+      else{
+       aPresent->_remove_ref();
       }
-      return CutPlanes::_nil();
     }
-    return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
+    return VISU::Mesh::_nil();
+  }
+
+  ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
+                                            const char* theMeshName,
+                                            VISU::Entity theEntity,
+                                            const char* theFieldName,
+                                            CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
+  }
+
+  GaussPoints_ptr VISU_Gen_i::GaussPointsOnField(Result_ptr theResult,
+                                                const char* theMeshName,
+                                                VISU::Entity theEntity,
+                                                const char* theFieldName,
+                                                CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::GaussPoints_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
+  }
+
+  DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
+                                                    const char* theMeshName,
+                                                    VISU::Entity theEntity,
+                                                    const char* theFieldName,
+                                                    CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  ScalarMapOnDeformedShape_ptr VISU_Gen_i::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
+                                                                          const char* theMeshName,
+                                                                          VISU::Entity theEntity,
+                                                                          const char* theFieldName,
+                                                                          CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::ScalarMapOnDeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+  
+  Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
+                                        const char* theMeshName,
+                                        VISU::Entity theEntity,
+                                        const char* theFieldName,
+                                        CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
+                                                const char* theMeshName,
+                                                VISU::Entity theEntity,
+                                                const char* theFieldName,
+                                                CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
+                                                const char* theMeshName,
+                                                VISU::Entity theEntity,
+                                                const char* theFieldName,
+                                                CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult,
+                                      const char* theMeshName,
+                                      VISU::Entity theEntity,
+                                      const char* theFieldName,
+                                      CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::Plot3D_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
+                                            const char* theMeshName,
+                                            VISU::Entity theEntity,
+                                            const char* theFieldName,
+                                            CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
+  }
+
+  CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
+                                          const char* theMeshName,
+                                          VISU::Entity theEntity,
+                                          const char* theFieldName,
+                                          CORBA::Double theIteration)
+  {
+    return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
   }
 
   Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
-      Mutex mt(myMutex,qApp);
-      Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry);
-      if(aPresent->Create() != NULL) 
-       return Table::_duplicate(aPresent->_this());
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Table::_nil();
+    Mutex mt(myMutex);
+    Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
+    if(pPresent->Create() != NULL)
+      return pPresent->_this();
+    else{
+      pPresent->_remove_ref();
+      return VISU::Table::_nil();
     }
-    return myVisuGen->CreateTable(theTableEntry);
-  }
-
-  Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
-      Mutex mt(myMutex,qApp);
-      PortableServer::POA_var aPOA = GetPOA();
-      Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
-      Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
-      if(aPresent->Create() != NULL) { 
-       return Curve::_duplicate(aPresent->_this());
-      }
+  }
+
+  Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
+                                   CORBA::Long theHRow,
+                                   CORBA::Long theVRow)
+  {
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Curve::_nil();
+    Mutex mt(myMutex);
+    PortableServer::POA_ptr aPOA = GetPOA();
+    Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
+    Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
+    if(pPresent->Create() != NULL)
+      return pPresent->_this();
+    else{
+      pPresent->_remove_ref();
+      return VISU::Curve::_nil();
     }
-    return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
   }
+
   Container_ptr VISU_Gen_i::CreateContainer(){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
-    if(myMutex){
-      if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
-      Mutex mt(myMutex,qApp);
-      Container_i* aPresent = new Container_i(myStudyDocument);
-      if(aPresent->Create() != NULL) {
-       return Container::_duplicate(aPresent->_this());
-      }
+    if(myStudyDocument->GetProperties()->IsLocked())
       return Container::_nil();
+    Mutex mt(myMutex);
+    Container_i* pPresent = new Container_i(myStudyDocument);
+    if(pPresent->Create() != NULL)
+      return pPresent->_this();
+    else{
+      pPresent->_remove_ref();
+      return VISU::Container::_nil();
     }
-    return myVisuGen->CreateContainer();
+  }
+
+  Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
+    if(myStudyDocument->GetProperties()->IsLocked())
+      return Animation::_nil();
+    Mutex mt(myMutex);
+    if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
+      return anAnim->_this();
+    }else
+      return VISU::Animation::_nil();
+  }
+
+  void VISU_Gen_i::DeleteResult (Result_ptr theResult)
+  {
+    theResult->RemoveFromStudy();
+  }
+
+  void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d)
+  {
+    thePrs3d->RemoveFromStudy();
   }
 
   void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      SALOMEDS::Study_var aStudy = theComponent->GetStudy(); 
-      if(!aStudy->_is_nil()){
-       SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
-       for (int i = 0; itBig->More(); itBig->Next(),i++) {
-         SALOMEDS::SObject_var gotBranch = itBig->Value();
-         if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<<i);
-         CORBA::Object_var anObj = SObjectToObject(gotBranch);
-         if(CORBA::is_nil(anObj)) continue;
-         Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
-         if(pResult->IsRestored()){ //Try remove its file and directory
-           const QFileInfo& aFileInfo = pResult->GetFileInfo();
-           static QString aCommand;
-           aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
-           if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
-           aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
-           if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
-         }
-       }
-      }
-      return;
-    }
-    myVisuGen->Close(theComponent);
   }
 
   char* VISU_Gen_i::ComponentDataType(){
@@ -817,176 +829,181 @@ namespace VISU{
   SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
                                                   SALOMEDS::SObject_ptr theSObject,
                                                   CORBA::Object_ptr theObject,
-                                                  const char* theName) 
-  throw (SALOME::SALOME_Exception) 
+                                                  const char* theName)
+    throw (SALOME::SALOME_Exception)
   {
+    Unexpect aCatch(SalomeException);
     if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      SALOMEDS::SObject_var aResultSO;
-      PortableServer::POA_var aPOA = GetPOA();
-      Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(theObject));
-      if (!aResultObj) return aResultSO._retn();
-
-      CORBA::String_var anEntry;
-      const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
-      anEntry = strdup(aResultObj->Create(aFileInfo.filePath().latin1())->GetID());
-//       if (CORBA::is_nil(theSObject)) {
-//     anEntry = strdup(aResultObj->Create(SALOMEDS::SObject::_nil(), theName));
-//       } else {
-//     if (!theSObject->ReferencedObject(aResultSO)) 
-//       THROW_SALOME_CORBA_EXCEPTION("Publish error: bad referenced SObject",SALOME::BAD_PARAM);
-//     anEntry = strdup(aResultObj->Create(aResultSO, (const char *)theName));
-//       }
-      aResultSO = theStudy->FindObjectID(anEntry);
-      return aResultSO._retn();
-    }
-    return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
+    Mutex mt(myMutex);
+    SALOMEDS::SObject_var aResultSO;
+    Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
+    if (!aResultObj) return aResultSO._retn();
+    const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
+    CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
+    aResultSO = theStudy->FindObjectID(anEntry);
+    return aResultSO._retn();
   }
-    
+
   CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
-    if(myMutex){
-      //Mutex mt(myMutex,qApp);
-      SALOMEDS::GenericAttribute_var anAttr;
-      if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
-      try {
-       CORBA::Object_var anObj = GetORB()->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
-       if (CORBA::is_nil(anObj)) return false;
-       else {
+    Mutex mt(myMutex);
+    SALOMEDS::GenericAttribute_var anAttr;
+    if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
+    try {
+      SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
+      CORBA::String_var aValue = anIOR->Value();
+      if(strcmp(aValue,"") != 0){
+       CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
+       if (!CORBA::is_nil(anObj)){
          Result_var aResultObj = Result::_narrow(anObj);
-         if (aResultObj->_is_nil()) return false;
+         if(!aResultObj->_is_nil()){
+           if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
+             switch(pResult->GetCreationId()){
+             case Result_i::eImportFile:
+             case Result_i::eCopyAndImportFile:
+               return true;
+             }
+           }
+         }
        }
-      } catch (...) {
-       return false;
       }
-      return true;
+    }catch(std::exception& exc){
+      INFOS("Follow exception was occured :\n"<<exc.what());
+    }catch (...){
+      INFOS("Unknown exception was occured!");
     }
-    return myVisuGen->CanCopy(theObject);
+    return false;
   }
 
   SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
+    Mutex mt(myMutex);
+    theObjectID = 0;
+    SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
+    SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
 
-      theObjectID = 0;
-      SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
-      SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
+    PortableServer::POA_ptr aPOA = GetPOA();
 
-      PortableServer::POA_var aPOA = GetPOA();
-      
-      SALOMEDS::GenericAttribute_var anAttr;
-      if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
-      SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
-      CORBA::Object_var aCorbaObj;
-      try {
-       aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
-      } catch(...) {
-       aStreamFile->length(1);
-       aStreamFile[0] = strdup("E")[0];
-       return aStreamFile._retn();
-      }
-      if (CORBA::is_nil(aCorbaObj)) {
-       return NULL;
-      }
+    SALOMEDS::GenericAttribute_var anAttr;
+    if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
+    SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
+    CORBA::Object_var aCorbaObj;
+    try {
+      aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
+    } catch(...) {
+      aStreamFile->length(1);
+      aStreamFile[0] = strdup("E")[0];
+      return aStreamFile._retn();
+    }
+    if (CORBA::is_nil(aCorbaObj)) {
+      return NULL;
+    }
+
+    Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
+    if (!pStorable) {
+      return NULL;
+    }
+
+    string aTmpDir = SALOMEDS_Tool::GetTmpDir();
+    string aCopyPersist =  aTmpDir + "copy_persistent";
+
+    ofstream stmOut2(aCopyPersist.c_str(),ios::out);
+    string aStr = pStorable->ToString().c_str();
+    stmOut2<<aStr<<endl;
+    stmOut2.close();
 
-      Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj));
-      if (!pStorable) {
+    if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
+      string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
+      if(strlen(aFileName.c_str()) == 1) aFileName="";
+      const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
+      aFileName += aFileInfo.fileName().latin1();
+      static QString aCommand;
+      string aFullFileName =  aTmpDir + aFileName;
+      aCommand.sprintf("cp %s %s",
+                      aFileInfo.filePath().latin1(),
+                      aFullFileName.c_str());
+      if(system(aCommand) == -1) {
+       if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
        return NULL;
       }
-      CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
-
-      char* aStr = strdup(pStorable->ToString());
-      ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
-      stmOut2<<aStr<<endl;
-      stmOut2.close();
-
-      Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
-      if (aResultObj) {
-       string aStudyPrefix = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + string("_");
-
-       const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
-       static QString aCommand;
-       aCommand.sprintf("cp %s %s",
-                        aFileInfo.filePath().latin1(),
-                        (string(aTmpDir)+aStudyPrefix + string(aResultObj->GetName())).c_str());
-       if(system(aCommand) == -1) {
-         if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
-         return NULL;
-       }
+      aSeq->length(2);
+      aSeq[0] = "copy_persistent";
+      aSeq[1] = aFileName.c_str();
+    } else {
+      aSeq->length(1);
+      aSeq[0] = "copy_persistent";
+    }
 
-       aSeq->length(2);
-       aSeq[0] = "copy_persistent";
-       aSeq[1] = (aStudyPrefix + string(aResultObj->GetName())).c_str();
-      } else {
-       aSeq->length(1);
-       aSeq[0] = "copy_persistent";
-      }
-      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
-      SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
+    aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
+    SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
 
-      // Assign an ID = 1 the the type VISU::Result
-      theObjectID = 1;
-      return aStreamFile._retn();
-    }
-    return myVisuGen->CopyFrom(theObject, theObjectID);
+    // Assign an ID = 1 the the type VISU::Result
+    theObjectID = 1;
+
+
+    SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
+    return aStreamFile._retn();
   }
 
   CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
     // The VISU component can paste only objects copied by VISU component
     // and with the object type = 1
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
-    if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
+    if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
+      return false;
     return true;
   }
 
   SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
                                              CORBA::Long theObjectID,
-                                             SALOMEDS::SObject_ptr theObject) {
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
-    if(myMutex){
-      Mutex mt(myMutex,qApp);
-      SALOMEDS::SObject_var aResultSO;
-      if (theObjectID != 1) return aResultSO._retn();
-      
-      CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
-      SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
-
-      SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
-      SALOMEDS::Study_var aStudy = theObject->GetStudy();
-      SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-      CORBA::ORB_var anORB = GetORB();
-
-      ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
-//        ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str(),ios::in);
-      stmIn.seekg(0, ios::end);
-      int aLength = stmIn.tellg();
-      stmIn.seekg(0, ios::beg);
-      char* aString = new char[aLength+1];
-      stmIn.read(aString, aLength);
-      aString[aLength] = 0;
-      myIsMultiFile = true;
-      Storable* aStorable = Storable::Create(theObject,aTmpDir.in(),aString);
-
-      SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
-      aSeqToRm->length(1);
-      aSeqToRm[0] = "copy_persistent";
-      SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
-
-      CORBA::String_var aComponentIDString(aComponent->GetID());
-      if (strcmp(aComponentIDString, theObject->GetID()) == 0) {
-       // create the new result SObject
-       aResultSO = aStudyBuilder->NewObject(aComponent);
-      } else {
-       aResultSO = SALOMEDS::SObject::_duplicate(theObject);
-      }
-      SALOMEDS::AttributeIOR_var anIOR =
-       SALOMEDS::AttributeIOR::_narrow(aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
-      anIOR->SetValue(aStorable->GetID());
+                                             SALOMEDS::SObject_ptr theObject)
+  {
+    Mutex mt(myMutex);
+    SALOMEDS::SObject_var aResultSO;
+    if (theObjectID != 1)
       return aResultSO._retn();
+
+    string aTmpDir = SALOMEDS_Tool::GetTmpDir();
+    SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
+
+    ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
+    stmIn.seekg(0, ios::end);
+    int aLength = stmIn.tellg();
+    stmIn.seekg(0, ios::beg);
+    char* aString = new char[aLength+1];
+    stmIn.read(aString, aLength);
+    aString[aLength] = 0;
+    myIsMultiFile = false;
+
+    string aFileName(aTmpDir);
+    string aBasicFileName;
+    if(aSeq->length() > 1) {
+      aBasicFileName = aSeq[1].in();
+      aFileName += aBasicFileName;
     }
-    return myVisuGen->PasteInto(theStream,theObjectID,theObject);
-  }
 
-};
+    SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
+    SALOMEDS::Study_var aStudy = theObject->GetStudy();
+    SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+    CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
+
+    if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
+      aResultSO = aStudyBuilder->NewObject(aComponent);
+    else
+      aResultSO = SALOMEDS::SObject::_duplicate(theObject);
+
+    //Just for Result::Restore to find the Comment attribute :(
+    SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
+
+    Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
+
+    SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
+    aSeqToRm->length(1);
+    aSeqToRm[0] = "copy_persistent";
+
+    SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
+
+    anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
+    SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
+    CORBA::String_var anIORValue(aStorable->GetID());
+    anIOR->SetValue(anIORValue);
+    return aResultSO._retn();
+  }
+}