Salome HOME
0020145: EDF 666 SMESH: Modifications of GEOM groups are not taken into account
authoreap <eap@opencascade.com>
Mon, 25 May 2009 11:23:23 +0000 (11:23 +0000)
committereap <eap@opencascade.com>
Mon, 25 May 2009 11:23:23 +0000 (11:23 +0000)
   1) allow changing shape to mesh in case of shape being group
   2) merge with V5

src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx

index 00defb418e0b1ee50b988d70763105285cb8de6e..88bb601e023b2a0599a62ffdf21268902761c01f 100644 (file)
@@ -49,7 +49,9 @@
 #include "DriverSTL_R_SMDS_Mesh.h"
 
 #undef _Precision_HeaderFile
+#include <BRepBndLib.hxx>
 #include <BRepPrimAPI_MakeBox.hxx>
+#include <Bnd_Box.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
@@ -68,8 +70,6 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
-using namespace std;
-
 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
 
 typedef SMESH_HypoFilter THypType;
@@ -96,6 +96,7 @@ SMESH_Mesh::SMESH_Mesh(int               theLocalId,
   _myMeshDS      = theDocument->GetMesh(_idDoc);
   _isShapeToMesh = false;
   _isAutoColor   = false;
+  _shapeDiagonal = 0.0;
   _myMeshDS->ShapeToMesh( PseudoShape() );
 }
 
@@ -133,9 +134,11 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
 {
   if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
 
-  if ( !aShape.IsNull() && _isShapeToMesh )
-    throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
-
+  if ( !aShape.IsNull() && _isShapeToMesh ) {
+    if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
+         _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
+      throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
+  }
   // clear current data
   if ( !_myMeshDS->ShapeToMesh().IsNull() )
   {
@@ -161,6 +164,8 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
     // clear SMESHDS
     TopoDS_Shape aNullShape;
     _myMeshDS->ShapeToMesh( aNullShape );
+
+    _shapeDiagonal = 0.0;
   }
 
   // set a new geometry
@@ -182,6 +187,7 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
   else
   {
     _isShapeToMesh = false;
+    _shapeDiagonal = 0.0;
     _myMeshDS->ShapeToMesh( PseudoShape() );
   }
 }
@@ -214,6 +220,36 @@ const TopoDS_Solid& SMESH_Mesh::PseudoShape()
   return aSolid;
 }
 
+//=======================================================================
+/*!
+ * \brief Return diagonal size of bounding box of a shape
+ */
+//=======================================================================
+
+double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
+{
+  if ( !aShape.IsNull() ) {
+    Bnd_Box Box;
+    BRepBndLib::Add(aShape, Box);
+    return sqrt( Box.SquareExtent() );
+  }
+  return 0;
+}
+
+//=======================================================================
+/*!
+ * \brief Return diagonal size of bounding box of shape to mesh
+ */
+//=======================================================================
+
+double SMESH_Mesh::GetShapeDiagonalSize() const
+{
+  if ( _shapeDiagonal == 0. && _isShapeToMesh )
+    const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
+
+  return _shapeDiagonal;
+}
+
 //=======================================================================
 /*!
  * \brief Remove all nodes and elements
@@ -277,6 +313,32 @@ void SMESH_Mesh::Clear()
 //   }
 }
 
+//=======================================================================
+/*!
+ * \brief Remove all nodes and elements of indicated shape
+ */
+//=======================================================================
+
+void SMESH_Mesh::ClearSubMesh(const int theShapeId)
+{
+  // clear sub-meshes; get ready to re-compute as a side-effect 
+  if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
+  {
+    SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
+                                                            /*complexShapeFirst=*/false);
+    while ( smIt->more() )
+    {
+      sm = smIt->next();
+      TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();      
+      if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
+       // all other shapes depends on vertices so they are already cleaned
+       sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
+      // to recompute even if failed
+      sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+    }
+  }
+}
+
 //=======================================================================
 //function : UNVToMesh
 //purpose  : 
@@ -1465,3 +1527,41 @@ SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem
 {
   return _myMeshDS->GetElementType( id, iselem );
 }
+
+//=============================================================================
+/*!
+ *  \brief Convert group on geometry into standalone group
+ */
+//=============================================================================
+
+SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
+{
+  SMESH_Group* aGroup = 0;
+  std::map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
+  if ( itg == _mapGroup.end() )
+    return aGroup;
+
+  SMESH_Group* anOldGrp = (*itg).second;
+  SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
+  if ( !anOldGrp || !anOldGrpDS )
+    return aGroup;
+
+  // create new standalone group
+  aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
+  _mapGroup[theGroupID] = aGroup;
+
+  SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
+  GetMeshDS()->RemoveGroup( anOldGrpDS );
+  GetMeshDS()->AddGroup( aNewGrpDS );
+
+  // add elements (or nodes) into new created group
+  SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
+  while ( anItr->more() )
+    aNewGrpDS->Add( (anItr->next())->GetID() );
+
+  // remove old group
+  delete anOldGrp;
+
+  return aGroup;
+}
+
index 7ba1203d6796c3235910417cf89da0ba72710ace..0ece936c246c73656dc27852498d702e45ff4119 100644 (file)
@@ -23,7 +23,6 @@
 //  File   : SMESH_Mesh.hxx
 //  Author : Paul RASCLE, EDF
 //  Module : SMESH
-//  $Header$
 //
 #ifndef _SMESH_MESH_HXX_
 #define _SMESH_MESH_HXX_
@@ -75,6 +74,14 @@ public:
    * \brief Return true if there is a geometry to be meshed, not PseudoShape()
    */
   bool HasShapeToMesh() const { return _isShapeToMesh; }
+  /*!
+   * \brief Return diagonal size of bounding box of shape to mesh.
+   */
+  double GetShapeDiagonalSize() const;
+  /*!
+   * \brief Return diagonal size of bounding box of a shape.
+   */
+  static double GetShapeDiagonalSize(const TopoDS_Shape & aShape);
   /*!
    * \brief Return a solid which is returned by GetShapeToMesh() if
    *        a real geometry to be meshed was not set
@@ -86,6 +93,11 @@ public:
    */
   void Clear();
 
+  /*!
+   * \brief Remove all nodes and elements of indicated shape
+   */
+  void ClearSubMesh(const int theShapeId);
+
   int UNVToMesh(const char* theFileName);
   /*!
    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
@@ -230,6 +242,7 @@ public:
 
   void RemoveGroup (const int theGroupID);
 
+  SMESH_Group* ConvertToStandalone ( int theGroupID );
 
   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
 
@@ -254,6 +267,8 @@ protected:
   SMESH_Gen *                _gen;
 
   bool                       _isAutoColor;
+
+  double                     _shapeDiagonal; //!< diagonal size of bounding box of shape to mesh
   
   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;