Salome HOME
22261: EDF 2698 SMESH: Memory leak when displaying 2D quadratic elements as arcs
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index e01f4a48a52e5ba997bb0cdebd690b6259c245be..411b111ee4c6616d82b11f8c1ee11b6e71e36445 100644 (file)
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_version.h"
 
+#include "DriverMED_W_SMESHDS_Mesh.h"
+#include "DriverMED_R_SMESHDS_Mesh.h"
+#ifdef WITH_CGNS
+#include "DriverCGNS_Read.hxx"
+#endif
+#include "MED_Factory.hxx"
 #include "SMDS_EdgePosition.hxx"
 #include "SMDS_FacePosition.hxx"
 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_PreMeshInfo.hxx"
 #include "SMESH_PythonDump.hxx"
+#include "memoire.h"
 
 #include CORBA_SERVER_HEADER(SMESH_Group)
 #include CORBA_SERVER_HEADER(SMESH_Filter)
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
 
-#include "DriverMED_W_SMESHDS_Mesh.h"
-#include "DriverMED_R_SMESHDS_Mesh.h"
-#ifdef WITH_CGNS
-#include "DriverCGNS_Read.hxx"
-#endif
-#include "memoire.h"
 
 #include <GEOM_Client.hxx>
 
 #include <map>
 #include <fstream>
 #include <cstdio>
-#include <stdlib.h>
+#include <cstdlib>
 
 using namespace std;
 using SMESH::TPythonDump;
@@ -473,7 +474,8 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
   // activate the CORBA servant of hypothesis
   hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
   int nextId = RegisterObject( hypothesis_i );
-  if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
+  if(MYDEBUG) { MESSAGE( "Add hypo to map with id = "<< nextId ); }
+  else        { nextId = 0; } // avoid "unused variable" warning in release mode
 
   return hypothesis_i._retn();
 }
@@ -502,7 +504,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
     // activate the CORBA servant of Mesh
     SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
     int nextId = RegisterObject( mesh );
-    if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
+    if(MYDEBUG) { MESSAGE( "Add mesh to map with id = "<< nextId); }
+    else        { nextId = 0; } // avoid "unused variable" warning in release mode
     return mesh._retn();
   }
   catch (SALOME_Exception& S_ex) {
@@ -1441,7 +1444,6 @@ SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr
   return error_array._retn();
 }
 
-//
 //================================================================================
 /*!
  * \brief Return mesh elements preventing computation of a subshape
@@ -1527,6 +1529,40 @@ SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
   return result._retn();
 }
 
+//================================================================================
+/*!
+ * \brief Create a group of elements preventing computation of a sub-shape
+ */
+//================================================================================
+
+SMESH::ListOfGroups*
+SMESH_Gen_i::MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
+                                           CORBA::Short          theSubShapeID,
+                                           const char*           theGroupName )
+  throw ( SALOME::SALOME_Exception )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+
+  SMESH::ListOfGroups_var groups;
+
+  if ( CORBA::is_nil( theMesh ) )
+    THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
+
+  try {
+    if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
+    {
+      groups = meshServant->MakeGroupsOfBadInputElements( theSubShapeID, theGroupName );
+      TPythonDump() << groups << " = " << this
+                    << ".MakeGroupsOfBadInputElements( "
+                    << theMesh << ", " << theSubShapeID << ", '" << theGroupName << "' )";
+    }
+  }
+  catch ( SALOME_Exception& S_ex ) {
+    INFOS( "catch exception "<< S_ex.what() );
+  }
+  return groups._retn();
+}
+
 //================================================================================
 /*!
  * \brief Returns errors of hypotheses definintion
@@ -1797,7 +1833,7 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
       ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
       TSetOfInt shapeIds;
       ::MeshDimension aDim = (MeshDimension)theDimension;
-      if ( myGen.Compute( myLocMesh, myLocShape, false, aDim, &shapeIds ) )
+      if ( myGen.Compute( myLocMesh, myLocShape, false, false, aDim, &shapeIds ) )
       {
         int nbShapeId = shapeIds.size();
         theShapesId.length( nbShapeId );
@@ -4639,8 +4675,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
 
               if ( SMESH_GroupOnFilter_i* aFilterGroup =
                    dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
+              {
                 aFilterGroup->SetFilter( filter );
-
+                filter->UnRegister();
+              }
               SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
               if ( !aGroupBaseDS )
                 continue;
@@ -4754,6 +4792,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
   }
   pd << ""; // prevent optimizing pd out
 
+  // creation of tree nodes for all data objects in the study
+  // to support tree representation customization and drag-n-drop:
+  SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theComponent->GetStudy()->GetUseCaseBuilder();
+  if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
+    useCaseBuilder->SetRootCurrent();
+    useCaseBuilder->Append( theComponent ); // component object is added as the top level item
+    SALOMEDS::ChildIterator_wrap it = theComponent->GetStudy()->NewChildIterator( theComponent ); 
+    for (it->InitEx(true); it->More(); it->Next()) {
+      useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
+    }
+  }
+
   INFOS( "SMESH_Gen_i::Load completed" );
   return true;
 }
@@ -4961,6 +5011,46 @@ char* SMESH_Gen_i::getVersion()
 #endif
 }
 
+//=================================================================================
+// function : Move()
+// purpose  : Moves objects to the specified position. 
+//            Is used in the drag-n-drop functionality.
+//=================================================================================
+void SMESH_Gen_i::Move( const SMESH::sobject_list& what,
+                        SALOMEDS::SObject_ptr where,
+                        CORBA::Long row )
+{
+  if ( CORBA::is_nil( where ) ) return;
+
+  SALOMEDS::Study_var study = where->GetStudy();
+  SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
+  SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
+  SALOMEDS::SComponent_var father = where->GetFatherComponent();
+  std::string dataType = father->ComponentDataType();
+  if ( dataType != "SMESH" ) return; // not a SMESH component
+  
+  SALOMEDS::SObject_var objAfter;
+  if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
+    // insert at given row -> find insertion position
+    SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
+    int i;
+    for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
+    if ( i == row && useCaseIt->More() ) {
+      objAfter = useCaseIt->Value();
+    }
+  }
+  
+  for ( int i = 0; i < what.length(); i++ ) {
+    SALOMEDS::SObject_var sobj = what[i];
+    if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
+    // insert the object to the use case tree
+    if ( !CORBA::is_nil( objAfter ) )
+      useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
+    else
+      useCaseBuilder->AppendTo( where, sobj );        // append to the end of list
+  }
+}
+
 //=============================================================================
 /*!
  *  SMESHEngine_factory