Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 650ff36bb6aa4eb1890f11a42bf54d1328fcc94f..e37e9212ccb31347aaeb3c67e5eefe1117f69585 100644 (file)
 //  Module : SMESH
 //  $Header$
 
-using namespace std;
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_subMesh_i.hxx"
 #include "SMESH_MEDMesh_i.hxx"
 #include "SMESH_Group_i.hxx"
+#include "SMESH_Filter_i.hxx"
 
 #include "Utils_CorbaException.hxx"
 #include "Utils_ExceptHandlers.hxx"
@@ -41,6 +41,9 @@ using namespace std;
 #include "OpUtil.hxx"
 
 #include "TCollection_AsciiString.hxx"
+#include <TColStd_MapOfInteger.hxx>
+#include <TColStd_MapIteratorOfMapOfInteger.hxx>
+#include <TColStd_SequenceOfInteger.hxx>
 #include "SMESHDS_Command.hxx"
 #include "SMESHDS_CommandType.hxx"
 #include "SMESH_MeshEditor_i.hxx"
@@ -52,24 +55,16 @@ using namespace std;
 // _CS_gbo_050504 Ajout explicite du sstream pour ostringstream 
 #include <sstream>
 
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
 
-//**** SMESHDS en champ
+using namespace std;
 
 int SMESH_Mesh_i::myIdGenerator = 0;
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-
-SMESH_Mesh_i::SMESH_Mesh_i()
-     : SALOME::GenericObj_i( PortableServer::POA::_nil() )
-{
-       MESSAGE("SMESH_Mesh_i: default constructor, not for use");
-       ASSERT(0);
-}
-
 //=============================================================================
 /*!
  *  Constructor
@@ -81,23 +76,13 @@ SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
                            CORBA::Long studyId )
 : SALOME::GenericObj_i( thePOA )
 {
-  MESSAGE("SMESH_Mesh_i");
+  INFOS("SMESH_Mesh_i");
   _gen_i = gen_i;
   _id = myIdGenerator++;
   _studyId = studyId;
   thePOA->activate_object( this );
 }
-/*
-SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
-                          CORBA::Long studyId, 
-                          int localId)
-{
-  MESSAGE("SMESH_Mesh_i");
-  _gen_i = gen_i;
-  _id = localId;
-  _studyId = studyId;
-}
-*/
+
 //=============================================================================
 /*!
  *  Destructor
@@ -106,12 +91,15 @@ SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
 
 SMESH_Mesh_i::~SMESH_Mesh_i()
 {
-  MESSAGE("~SMESH_Mesh_i");
+  INFOS("~SMESH_Mesh_i");
   map<int, SMESH::SMESH_Group_ptr>::iterator it;
   for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
     SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
     if ( aGroup ) {
-      _impl->RemoveGroup( aGroup->GetLocalID() );
+
+      // this method is colled from destructor of group (PAL6331)
+      //_impl->RemoveGroup( aGroup->GetLocalID() );
+      
       aGroup->Destroy();
     }
   }
@@ -128,12 +116,12 @@ SMESH_Mesh_i::~SMESH_Mesh_i()
  */
 //=============================================================================
 
-void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
+void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
     throw (SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
   try {
-    setShape( theShape );
+    setShape( theShapeObject );
   }
   catch(SALOME_Exception & S_ex) {
     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
@@ -145,7 +133,7 @@ void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
 
   // Create a reference to <theShape> 
   SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
-  SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theShape ) );
+  SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theShapeObject ) );
   
   SALOMEDS::SObject_var          anObj, aRef;
   SALOMEDS::GenericAttribute_var anAttr;
@@ -175,9 +163,12 @@ void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
  */
 //=============================================================================
 
-bool SMESH_Mesh_i::setShape( GEOM::GEOM_Shape_ptr theShape )
+bool SMESH_Mesh_i::setShape( GEOM::GEOM_Object_ptr theShapeObject )
 {
-  TopoDS_Shape aLocShape  = _gen_i->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theShape );
+  if ( theShapeObject->_is_nil() )
+    return false;
+
+  TopoDS_Shape aLocShape  = _gen_i->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theShapeObject );
   _impl->ShapeToMesh( aLocShape );
   return true;
 }
@@ -217,8 +208,8 @@ static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
 //=============================================================================
 
 SMESH::DriverMED_ReadStatus
-  SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
-     throw ( SALOME::SALOME_Exception )
+SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
+  throw ( SALOME::SALOME_Exception )
 {
   Unexpect aCatch(SALOME_SalomeException);
   int status;
@@ -249,6 +240,39 @@ SMESH::DriverMED_ReadStatus
   return ConvertDriverMEDReadStatus(status);
 }
 
+//=============================================================================
+/*!
+ *  ImportUNVFile
+ *
+ *  Imports mesh data from MED file
+ */
+//=============================================================================
+
+int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
+  throw ( SALOME::SALOME_Exception )
+{
+  // Read mesh with name = <theMeshName> into SMESH_Mesh
+  _impl->UNVToMesh( theFileName );
+
+  return 1;
+}
+
+//=============================================================================
+/*!
+ *  ImportSTLFile
+ *
+ *  Imports mesh data from STL file
+ */
+//=============================================================================
+int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
+  throw ( SALOME::SALOME_Exception )
+{
+  // Read mesh with name = <theMeshName> into SMESH_Mesh
+  _impl->STLToMesh( theFileName );
+
+  return 1;
+}
+
 //=============================================================================
 /*!
  *  importMEDFile
@@ -273,7 +297,7 @@ int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshNam
     StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
     string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
     int nextId = myStudyContext->addObject( iorString );
-    MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
+    if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
   }
 
   return status;
@@ -323,12 +347,12 @@ static SMESH::Hypothesis_Status ConvertHypothesisStatus
  */
 //=============================================================================
 
-SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
+SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
                                                      SMESH::SMESH_Hypothesis_ptr anHyp)
   throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-  SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp );
+  SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
 
   if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
     SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
@@ -338,8 +362,13 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubSh
       SALOMEDS::GenericAttribute_var anAttr;
       SALOMEDS::AttributeIOR_var     anIOR;
       SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
+      if ( aMeshSO->_is_nil() ) {
+        SCRUTE( SMESH_Gen_i::GetORB()->object_to_string( _this() ));
+        removeHypothesis( aSubShapeObject, anHyp );
+       return SMESH::HYP_UNKNOWN_FATAL;
+      }
       SALOMEDS::SObject_var aMorSM, aRef;
-      CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
+      CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShapeObject ) );
       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
 
       for ( it->InitEx( true ); it->More(); it->Next() ) {
@@ -384,6 +413,7 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubSh
       }
     }
   }
+  if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
 
   return ConvertHypothesisStatus(status);
 }
@@ -395,14 +425,13 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubSh
 //=============================================================================
 
 SMESH_Hypothesis::Hypothesis_Status
-  SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
+  SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
                               SMESH::SMESH_Hypothesis_ptr anHyp)
 {
-       MESSAGE("addHypothesis");
+       if(MYDEBUG) MESSAGE("addHypothesis");
        // **** proposer liste de subShape (selection multiple)
 
-       GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
-       if (CORBA::is_nil(mySubShape))
+       if (CORBA::is_nil(aSubShapeObject))
                THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
                        SALOME::BAD_PARAM);
 
@@ -415,7 +444,7 @@ SMESH_Hypothesis::Hypothesis_Status
        try
        {
                TopoDS_Shape myLocSubShape =
-                       _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
+                       _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), aSubShapeObject);
                int hypId = myHyp->GetId();
                status = _impl->AddHypothesis(myLocSubShape, hypId);
                 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
@@ -434,12 +463,12 @@ SMESH_Hypothesis::Hypothesis_Status
  */
 //=============================================================================
 
-SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
+SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
                                                         SMESH::SMESH_Hypothesis_ptr anHyp)
      throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-  SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShape, anHyp );
+  SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
 
   if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
     SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
@@ -449,11 +478,13 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSu
       SALOMEDS::GenericAttribute_var anAttr;
       SALOMEDS::AttributeIOR_var     anIOR;
       SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
-      if ( aMeshSO->_is_nil() )
+      if ( aMeshSO->_is_nil() ) {
+        SCRUTE( SMESH_Gen_i::GetORB()->object_to_string( _this() ));
+        addHypothesis( aSubShapeObject, anHyp );
        return SMESH::HYP_UNKNOWN_FATAL;
-
+      }
       SALOMEDS::SObject_var aMorSM, aRef;
-      CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
+      CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShapeObject ) );
       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
 
       for ( it->InitEx( true ); it->More(); it->Next() ) {
@@ -510,15 +541,13 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSu
  */
 //=============================================================================
 
-SMESH_Hypothesis::Hypothesis_Status
-  SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
+SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
                                  SMESH::SMESH_Hypothesis_ptr anHyp)
 {
-       MESSAGE("removeHypothesis()");
+       if(MYDEBUG) MESSAGE("removeHypothesis()");
        // **** proposer liste de subShape (selection multiple)
 
-       GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
-       if (CORBA::is_nil(mySubShape))
+       if (CORBA::is_nil(aSubShapeObject))
                THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
                        SALOME::BAD_PARAM);
 
@@ -531,7 +560,7 @@ SMESH_Hypothesis::Hypothesis_Status
        try
        {
                TopoDS_Shape myLocSubShape =
-                       _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
+                       _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), aSubShapeObject);
                int hypId = myHyp->GetId();
                status = _impl->RemoveHypothesis(myLocSubShape, hypId);
                 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
@@ -551,13 +580,12 @@ SMESH_Hypothesis::Hypothesis_Status
 //=============================================================================
 
 SMESH::ListOfHypothesis *
-       SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
+       SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
 throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
   MESSAGE("GetHypothesisList");
-  GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
-  if (CORBA::is_nil(mySubShape))
+  if (CORBA::is_nil(aSubShapeObject))
     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
                                 SALOME::BAD_PARAM);
   
@@ -565,7 +593,7 @@ throw(SALOME::SALOME_Exception)
 
   try {
     TopoDS_Shape myLocSubShape
-      = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
+      = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), aSubShapeObject);
     
     const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
     int i = 0, n = aLocalList.size();
@@ -591,21 +619,20 @@ throw(SALOME::SALOME_Exception)
  *  
  */
 //=============================================================================
-SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape,
+SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
                                                  const char*          theName ) 
      throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-  MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
-  GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
-  if (CORBA::is_nil(mySubShape))
+  MESSAGE("SMESH_Mesh_i::GetSubMesh");
+  if (CORBA::is_nil(aSubShapeObject))
     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
                                 SALOME::BAD_PARAM);
   
   int subMeshId = 0;
   try {
     TopoDS_Shape myLocSubShape
-      = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
+      = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), aSubShapeObject);
     
     //Get or Create the SMESH_subMesh object implementation
     
@@ -615,7 +642,7 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape
     // create a new subMesh object servant if there is none for the shape
     
     if (_mapSubMesh.find(subMeshId) == _mapSubMesh.end()) {
-      SMESH::SMESH_subMesh_var subMesh = createSubMesh( aSubShape );
+      SMESH::SMESH_subMesh_var subMesh = createSubMesh( aSubShapeObject );
       if ( _gen_i->CanPublishInStudy( subMesh ) ) {
        SALOMEDS::SObject_var aSubmeshSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(), 
                                                                   SALOMEDS::SObject::_nil(),
@@ -624,13 +651,13 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape
          
        // Add reference to <aSubShape> to the study
        SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
-       SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
+       SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( aSubShapeObject ) );
        if ( !aSubmeshSO->_is_nil() && !aShapeSO->_is_nil() ) {
-         MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): adding shape reference..." )
+         if(MYDEBUG) MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): adding shape reference..." )
          SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
          SALOMEDS::SObject_var SO = aBuilder->NewObjectToTag( aSubmeshSO, SMESH_Gen_i::GetRefOnShapeTag() );
          aBuilder->Addreference( SO, aShapeSO );
-         MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): shape reference added" )
+         if(MYDEBUG) MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): shape reference added" )
        }
       }
     }
@@ -653,11 +680,11 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape
 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
      throw (SALOME::SALOME_Exception)
 {
-  MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
   if ( theSubMesh->_is_nil() )
     return;
 
-  GEOM::GEOM_Shape_var aSubShape;
+  GEOM::GEOM_Object_var aSubShapeObject;
   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() )  {
     // Remove submesh's SObject
@@ -666,13 +693,13 @@ void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
       long aTag = SMESH_Gen_i::GetRefOnShapeTag(); 
       SALOMEDS::SObject_var anObj, aRef;
       if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
-       aSubShape = GEOM::GEOM_Shape::_narrow( aRef->GetObject() );
+       aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
 
       aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
     }
   }
 
-  removeSubMesh( theSubMesh, aSubShape.in() );
+  removeSubMesh( theSubMesh, aSubShapeObject.in() );
 }
 
 
@@ -683,7 +710,7 @@ void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
 //=============================================================================
 
 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
-                                                 const char*        theName )
+                                             const char* theName )
      throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
@@ -701,6 +728,107 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType
 }
 
 
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroupFromGEOM( SMESH::ElementType theElemType,
+                                                         const char* theName,
+                                                         GEOM::GEOM_Object_ptr theGEOMGroup)
+     throw(SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  
+  SMESH::SMESH_Group_var aNewGroup = createGroup( theElemType, theName );
+  
+  if ( CORBA::is_nil(theGEOMGroup) || theGEOMGroup->GetType() != 37 || CORBA::is_nil(aNewGroup))
+    return aNewGroup._retn();
+  
+  GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH_Gen_i::GetGeomEngine()->GetIGroupOperations(_studyId);
+  SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+  
+  // Check if group constructed on the same shape as a mesh or on its child:
+  GEOM::GEOM_Object_var aGroupMainShape = aGroupOp->GetMainShape( theGEOMGroup );
+  SALOMEDS::SObject_var aGroupMainShapeSO =
+    SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string(aGroupMainShape) ) );
+  SALOMEDS::SObject_var aMeshSO  = 
+    SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
+  
+  SALOMEDS::SObject_var anObj, aRef;
+  bool isRefOrSubShape = false;
+  
+  if ( aMeshSO->FindSubObject( 1, anObj ) &&  anObj->ReferencedObject( aRef )) {
+    if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
+      isRefOrSubShape = true;
+    else
+      {
+       SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
+       SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
+       while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
+         {
+           if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
+             isRefOrSubShape = true;
+           else
+             aFather = aFather->GetFather();
+         }
+      }
+    if ( !isRefOrSubShape ) 
+      return aNewGroup._retn();
+  }
+  
+  // Detect type of the geometry group
+  SMESH::ElementType aGEOMGroupType;
+  
+  SMESH::ElementType aGroupType = SMESH::ALL;
+  switch(aGroupOp->GetType(theGEOMGroup)) 
+    {
+    case 7: aGEOMGroupType = SMESH::NODE; break;
+    case 6: aGEOMGroupType = SMESH::EDGE; break;
+    case 4: aGEOMGroupType = SMESH::FACE; break;
+    case 2: aGEOMGroupType = SMESH::VOLUME; break;
+    }
+    
+  if ( aGEOMGroupType == theElemType )
+    {
+      if ( !aStudy->_is_nil() ) 
+       {
+         SALOMEDS::SObject_var aGEOMGroupSO =
+           SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string(theGEOMGroup) ) );
+         
+         if ( !aGEOMGroupSO->_is_nil() ) {
+           // Construct filter
+           SMESH::FilterManager_var aFilterMgr = _gen_i->CreateFilterManager();
+           SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
+           SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
+           aBelongToGeom->SetGeom( theGEOMGroup );
+           aBelongToGeom->SetShapeName( aGEOMGroupSO->GetName() );
+           aBelongToGeom->SetElementType( theElemType );
+           aFilter->SetPredicate( aBelongToGeom );
+           SMESH::long_array_var anElements = aFilter->GetElementsId( _this() );
+           aNewGroup->Add( anElements );
+           
+           // Groups should be put under separate roots according to their type (nodes, edges, faces, volumes)
+           if ( _gen_i->CanPublishInStudy( aNewGroup ) )
+             {
+               SALOMEDS::SObject_var aGroupSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(), 
+                                                                        SALOMEDS::SObject::_nil(),
+                                                                        aNewGroup,
+                                                                        theName );
+               if ( !aGroupSO->_is_nil() )
+                 {
+                   //Add reference to geometry group
+                   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+                   SALOMEDS::SObject_var aReference = aStudyBuilder->NewObject(aGroupSO);
+                   aStudyBuilder->Addreference(aReference, aGEOMGroupSO);
+                 }
+             }
+         }
+       }
+    }
+  
+  return aNewGroup._retn();
+}
 //=============================================================================
 /*!
  *  
@@ -729,6 +857,175 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_Group_ptr theGroup )
   removeGroup( aGroup->GetLocalID() );
 }
 
+//=============================================================================
+/*! RemoveGroupWithContents
+ *  Remove group with its contents
+ */ 
+//=============================================================================
+void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_Group_ptr theGroup )
+  throw (SALOME::SALOME_Exception)
+{
+  if ( theGroup->_is_nil() )
+    return;
+
+  SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
+  if ( !aGroup )
+    return;
+  
+  SMESH::long_array_var anIds = aGroup->GetListOfID();
+  SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
+    
+  if ( aGroup->GetType() == SMESH::NODE )
+    aMeshEditor->RemoveNodes( anIds );
+  else
+    aMeshEditor->RemoveElements( anIds );
+  
+  RemoveGroup( theGroup );
+}
+
+//=============================================================================
+/*! UnionGroups
+ *  New group is created. All mesh elements that are 
+ *  present in initial groups are added to the new one
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_Group_ptr theGroup1, 
+                                                  SMESH::SMESH_Group_ptr theGroup2, 
+                                                  const char* theName )
+  throw (SALOME::SALOME_Exception)
+{
+  try
+  {
+    SMESH::SMESH_Group_var aResGrp;
+
+    if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+         theGroup1->GetType() != theGroup2->GetType() )
+      return SMESH::SMESH_Group::_nil();
+
+    aResGrp = CreateGroup( theGroup1->GetType(), theName );
+    if ( aResGrp->_is_nil() )
+      return SMESH::SMESH_Group::_nil();
+
+    SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+    SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+    TColStd_MapOfInteger aResMap;
+
+    for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+      aResMap.Add( anIds1[ i1 ] );
+
+    for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+      aResMap.Add( anIds2[ i2 ] );
+
+    SMESH::long_array_var aResIds = new SMESH::long_array;
+    aResIds->length( aResMap.Extent() );
+
+    int resI = 0;
+    TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
+    for( ; anIter.More(); anIter.Next() )
+      aResIds[ resI++ ] = anIter.Key();
+
+    aResGrp->Add( aResIds );
+
+    return aResGrp._retn();
+  }
+  catch( ... )
+  {
+    return SMESH::SMESH_Group::_nil();
+  }
+}
+  
+//=============================================================================
+/*! IntersectGroups
+ *  New group is created. All mesh elements that are 
+ *  present in both initial groups are added to the new one.
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_Group_ptr theGroup1, 
+                                                      SMESH::SMESH_Group_ptr theGroup2, 
+                                                      const char* theName )
+  throw (SALOME::SALOME_Exception)
+{
+  SMESH::SMESH_Group_var aResGrp;
+  
+  if ( theGroup1->_is_nil() || theGroup2->_is_nil() || 
+       theGroup1->GetType() != theGroup2->GetType() )
+    return aResGrp;
+  
+  aResGrp = CreateGroup( theGroup1->GetType(), theName );
+  if ( aResGrp->_is_nil() )
+    return aResGrp;
+  
+  SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+  SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+  
+  TColStd_MapOfInteger aMap1;
+  
+  for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+    aMap1.Add( anIds1[ i1 ] );
+
+  TColStd_SequenceOfInteger aSeq;
+
+  for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+    if ( aMap1.Contains( anIds2[ i2 ] ) )
+      aSeq.Append( anIds2[ i2 ] );
+  
+  SMESH::long_array_var aResIds = new SMESH::long_array;
+  aResIds->length( aSeq.Length() );
+  
+  for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+    aResIds[ resI ] = aSeq( resI + 1 );
+  
+  aResGrp->Add( aResIds );
+  
+  return aResGrp._retn();
+}
+
+//=============================================================================
+/*! CutGroups
+ *  New group is created. All mesh elements that are present in 
+ *  main group but do not present in tool group are added to the new one 
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_Group_ptr theGroup1, 
+                                                SMESH::SMESH_Group_ptr theGroup2, 
+                                                const char* theName )
+  throw (SALOME::SALOME_Exception)
+{
+  SMESH::SMESH_Group_var aResGrp;
+  
+  if ( theGroup1->_is_nil() || theGroup2->_is_nil() || 
+       theGroup1->GetType() != theGroup2->GetType() )
+    return aResGrp;
+  
+  aResGrp = CreateGroup( theGroup1->GetType(), theName );
+  if ( aResGrp->_is_nil() )
+    return aResGrp;
+  
+  SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+  SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+  
+  TColStd_MapOfInteger aMap2;
+  
+  for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+    aMap2.Add( anIds2[ i2 ] );
+
+
+  TColStd_SequenceOfInteger aSeq;
+  for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+    if ( !aMap2.Contains( anIds1[ i1 ] ) )
+      aSeq.Append( anIds1[ i1 ] );
+
+  SMESH::long_array_var aResIds = new SMESH::long_array;
+  aResIds->length( aSeq.Length() );
+
+  for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+    aResIds[ resI ] = aSeq( resI + 1 );  
+  
+  aResGrp->Add( aResIds );
+  
+  return aResGrp._retn();
+}
 
 //=============================================================================
 /*!
@@ -736,9 +1033,9 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_Group_ptr theGroup )
  */
 //=============================================================================
 
-SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSubShape ) {
-  TopoDS_Shape myLocSubShape = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), theSubShape);
+SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
+{
+  TopoDS_Shape myLocSubShape = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), theSubShapeObject);
 
   ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
   int subMeshId = mySubMesh->GetId();
@@ -755,7 +1052,7 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSu
   StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
   string iorString = SMESH_Gen_i::GetORB()->object_to_string( subMesh );
   int nextId = myStudyContext->addObject( iorString );
-  MESSAGE( "Add submesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
+  if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
 
   return subMesh._retn(); 
 }
@@ -767,20 +1064,20 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSu
  */
 //=============================================================================
 
-void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEOM_Shape_ptr theSubShape )
+void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEOM_Object_ptr theSubShapeObject )
 {
   MESSAGE("SMESH_Mesh_i::removeSubMesh()");
-  if ( theSubMesh->_is_nil() || theSubShape->_is_nil() )
+  if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
     return;
 
   try {
-    SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShape );
+    SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
     for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
-      removeHypothesis( theSubShape, aHypList[i] );
+      removeHypothesis( theSubShapeObject, aHypList[i] );
     }
   }
   catch( const SALOME::SALOME_Exception& ) {
-    MESSAGE("SMESH_Mesh_i::removeSubMesh(): exception caught!");
+    INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
   }
 
   int subMeshId = theSubMesh->GetId();
@@ -788,7 +1085,7 @@ void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEO
   _mapSubMesh.erase(subMeshId);
   _mapSubMesh_i.erase(subMeshId);
   _mapSubMeshIor.erase(subMeshId);
-  MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
 }
 
 //=============================================================================
@@ -810,7 +1107,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::createGroup( SMESH::ElementType theElemType
     StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
     string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
     int nextId = myStudyContext->addObject( iorString );
-    MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
+    if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
   }
   return aGroup._retn();
 }
@@ -826,7 +1123,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::createGroup( SMESH::ElementType theElemType
 
 void SMESH_Mesh_i::removeGroup( const int theId )
 {
-  MESSAGE("SMESH_Mesh_i::removeGroup()" );  
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );  
   if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
     _mapGroups.erase( theId );
     _impl->RemoveGroup( theId );
@@ -843,179 +1140,57 @@ void SMESH_Mesh_i::removeGroup( const int theId )
 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
 throw(SALOME::SALOME_Exception)
 {
-       MESSAGE("SMESH_Mesh_i::GetLog");
-
-       SMESH::log_array_var aLog;
-       try
-       {
-               list < SMESHDS_Command * >logDS = _impl->GetLog();
-               aLog = new SMESH::log_array;
-               int indexLog = 0;
-               int lg = logDS.size();
-               SCRUTE(lg);
-               aLog->length(lg);
-               list < SMESHDS_Command * >::iterator its = logDS.begin();
-               while (its != logDS.end())
-               {
-                       SMESHDS_Command *com = *its;
-                       int comType = com->GetType();
-                       //SCRUTE(comType);
-                       int lgcom = com->GetNumber();
-                       //SCRUTE(lgcom);
-                       const list < int >&intList = com->GetIndexes();
-                       int inum = intList.size();
-                       //SCRUTE(inum);
-                       list < int >::const_iterator ii = intList.begin();
-                       const list < double >&coordList = com->GetCoords();
-                       int rnum = coordList.size();
-                       //SCRUTE(rnum);
-                       list < double >::const_iterator ir = coordList.begin();
-                       aLog[indexLog].commandType = comType;
-                       aLog[indexLog].number = lgcom;
-                       aLog[indexLog].coords.length(rnum);
-                       aLog[indexLog].indexes.length(inum);
-                       for (int i = 0; i < rnum; i++)
-                       {
-                               aLog[indexLog].coords[i] = *ir;
-                               //MESSAGE(" "<<i<<" "<<ir.Value());
-                               ir++;
-                       }
-                       for (int i = 0; i < inum; i++)
-                       {
-                               aLog[indexLog].indexes[i] = *ii;
-                               //MESSAGE(" "<<i<<" "<<ii.Value());
-                               ii++;
-                       }
-                       indexLog++;
-                       its++;
-               }
-               if (clearAfterGet)
-                       _impl->ClearLog();
-       }
-       catch(SALOME_Exception & S_ex)
-       {
-               THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
-       }
-       return aLog._retn();
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
+  
+  SMESH::log_array_var aLog;
+  try{
+    list < SMESHDS_Command * >logDS = _impl->GetLog();
+    aLog = new SMESH::log_array;
+    int indexLog = 0;
+    int lg = logDS.size();
+    SCRUTE(lg);
+    aLog->length(lg);
+    list < SMESHDS_Command * >::iterator its = logDS.begin();
+    while(its != logDS.end()){
+      SMESHDS_Command *com = *its;
+      int comType = com->GetType();
+      //SCRUTE(comType);
+      int lgcom = com->GetNumber();
+      //SCRUTE(lgcom);
+      const list < int >&intList = com->GetIndexes();
+      int inum = intList.size();
+      //SCRUTE(inum);
+      list < int >::const_iterator ii = intList.begin();
+      const list < double >&coordList = com->GetCoords();
+      int rnum = coordList.size();
+      //SCRUTE(rnum);
+      list < double >::const_iterator ir = coordList.begin();
+      aLog[indexLog].commandType = comType;
+      aLog[indexLog].number = lgcom;
+      aLog[indexLog].coords.length(rnum);
+      aLog[indexLog].indexes.length(inum);
+      for(int i = 0; i < rnum; i++){
+       aLog[indexLog].coords[i] = *ir;
+       //MESSAGE(" "<<i<<" "<<ir.Value());
+       ir++;
+      }
+      for(int i = 0; i < inum; i++){
+       aLog[indexLog].indexes[i] = *ii;
+       //MESSAGE(" "<<i<<" "<<ii.Value());
+       ii++;
+      }
+      indexLog++;
+      its++;
+    }
+    if(clearAfterGet)
+      _impl->ClearLog();
+  }
+  catch(SALOME_Exception & S_ex){
+    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+  }
+  return aLog._retn();
 }
 
-//  SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
-//    throw (SALOME::SALOME_Exception)
-//  {
-//    MESSAGE("SMESH_Mesh_i::GetLog");
-
-//    SMESH::string_array_var aLog;
-//    try
-//      {
-//        const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
-//        aLog = new SMESH::string_array;
-//        int logSize = 0;
-//        int indexLog = 0;
-//        int lg = logDS.Extent();
-//        SCRUTE(lg);
-//        SMESHDS_ListIteratorOfListOfCommand its(logDS);
-//        while(its.More())
-//        {
-//      Handle(SMESHDS_Command) com = its.Value();
-//      int comType = com->GetType();
-//      SCRUTE(comType);
-//      int lgcom = com->GetNumber();
-//      SCRUTE(lgcom);
-//      logSize += lgcom;
-//      aLog->length(logSize);
-//      SCRUTE(logSize);
-//      const TColStd_ListOfInteger& intList = com->GetIndexes();
-//      TColStd_ListIteratorOfListOfInteger ii(intList);
-//      const TColStd_ListOfReal& coordList = com->GetCoords();
-//      TColStd_ListIteratorOfListOfReal ir(coordList);
-//      for (int icom = 1; icom <= lgcom; icom++)
-//        {
-//          ostringstream S;
-//          switch (comType)
-//            {
-//            case SMESHDS_AddNode:
-//          S << "AddNode " << ii.Value(); ii.Next();
-//          S << " " << ir.Value(); ir.Next(); 
-//          S << " " << ir.Value(); ir.Next();
-//          S << " " << ir.Value(); ir.Next();
-//          break;
-//            case SMESHDS_AddEdge:
-//          S << "AddEdge " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddTriangle:
-//          S << "AddFace " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddQuadrangle:
-//          S << "AddFace " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddTetrahedron:
-//          S << "AddVolume " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddPyramid:
-//          S << "AddVolume " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddPrism:
-//          S << "AddVolume " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_AddHexahedron:
-//          S << "AddVolume " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          S << " " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_RemoveNode:
-//          S << "RemoveNode " << ii.Value(); ii.Next();
-//          break;
-//            case SMESHDS_RemoveElement:
-//          S << "RemoveElement " << ii.Value(); ii.Next();
-//          break;
-//            default:
-//          ASSERT(0);
-//          break;
-//            }
-//          string ch = S.str();
-//          SCRUTE(ch);
-//          aLog[indexLog++] = CORBA::string_dup(ch.c_str());
-//        }
-//      its.Next();
-//        }
-//        if (clearAfterGet) _impl->ClearLog();
-//      }
-//    catch (SALOME_Exception& S_ex)
-//      {
-//        THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
-//      }
-//    return aLog._retn();
-//  }
 
 //=============================================================================
 /*!
@@ -1025,8 +1200,8 @@ throw(SALOME::SALOME_Exception)
 
 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
 {
-       MESSAGE("SMESH_Mesh_i::ClearLog");
-       // ****
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
+  // ****
 }
 
 //=============================================================================
@@ -1037,8 +1212,8 @@ void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
 
 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
 {
-       MESSAGE("SMESH_Mesh_i::GetId");
-       return _id;
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
+  return _id;
 }
 
 //=============================================================================
@@ -1049,7 +1224,7 @@ CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
 
 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
 {
-       return _studyId;
+  return _studyId;
 }
 
 //=============================================================================
@@ -1060,8 +1235,8 @@ CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
 
 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
 {
-       MESSAGE("SMESH_Mesh_i::SetImpl");
-       _impl = impl;
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
+  _impl = impl;
 }
 
 //=============================================================================
@@ -1072,8 +1247,8 @@ void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
 
 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
 {
-       MESSAGE("SMESH_Mesh_i::GetImpl()");
-       return *_impl;
+  if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
+  return *_impl;
 }
 
 
@@ -1085,8 +1260,7 @@ void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
 
 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
 {
-       SMESH_MeshEditor_i *aMeshEditor =
-               new SMESH_MeshEditor_i(_impl->GetMeshDS());
+       SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
        SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
        return aMesh._retn();
 }
@@ -1131,12 +1305,18 @@ void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw
 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       _impl->ExportDAT(file);
+  _impl->ExportDAT(file);
 }
 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       _impl->ExportUNV(file);
+  _impl->ExportUNV(file);
+}
+
+void SMESH_Mesh_i::ExportSTL(const char *file, const bool isascii) throw(SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  _impl->ExportSTL(file, isascii);
 }
 
 //=============================================================================
@@ -1148,9 +1328,9 @@ void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
-       SALOME_MED::MESH_var aMesh = aMedMesh->_this();
-       return aMesh._retn();
+  SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
+  SALOME_MED::MESH_var aMesh = aMedMesh->_this();
+  return aMesh._retn();
 }
 
 //=============================================================================
@@ -1161,7 +1341,7 @@ SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbNodes();
+  return _impl->NbNodes();
 }
 
 //=============================================================================
@@ -1172,7 +1352,7 @@ CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbEdges();
+  return _impl->NbEdges();
 }
 
 //=============================================================================
@@ -1183,19 +1363,19 @@ CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbFaces();
+  return _impl->NbFaces();
 }
 
 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbTriangles();
+  return _impl->NbTriangles();
 }
 
 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbQuadrangles();
+  return _impl->NbQuadrangles();
 }
 
 //=============================================================================
@@ -1206,31 +1386,31 @@ CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbVolumes();
+  return _impl->NbVolumes();
 }
 
 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbTetras();
+  return _impl->NbTetras();
 }
 
 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbHexas();
+  return _impl->NbHexas();
 }
 
 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbPyramids();
+  return _impl->NbPyramids();
 }
 
 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbPrisms();
+  return _impl->NbPrisms();
 }
 
 //=============================================================================
@@ -1241,7 +1421,7 @@ CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-       return _impl->NbSubMesh();
+  return _impl->NbSubMesh();
 }
 
 //=============================================================================