#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>
static int MYDEBUG = 0;
#endif
-using namespace std;
-
#define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
typedef SMESH_HypoFilter THypType;
_myMeshDS = theDocument->GetMesh(_idDoc);
_isShapeToMesh = false;
_isAutoColor = false;
+ _shapeDiagonal = 0.0;
_myMeshDS->ShapeToMesh( PseudoShape() );
}
{
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() )
{
// clear SMESHDS
TopoDS_Shape aNullShape;
_myMeshDS->ShapeToMesh( aNullShape );
+
+ _shapeDiagonal = 0.0;
}
// set a new geometry
else
{
_isShapeToMesh = false;
+ _shapeDiagonal = 0.0;
_myMeshDS->ShapeToMesh( 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
// }
}
+//=======================================================================
+/*!
+ * \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 :
{
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;
+}
+
// File : SMESH_Mesh.hxx
// Author : Paul RASCLE, EDF
// Module : SMESH
-// $Header$
//
#ifndef _SMESH_MESH_HXX_
#define _SMESH_MESH_HXX_
* \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
*/
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
void RemoveGroup (const int theGroupID);
+ SMESH_Group* ConvertToStandalone ( int theGroupID );
SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
SMESH_Gen * _gen;
bool _isAutoColor;
+
+ double _shapeDiagonal; //!< diagonal size of bounding box of shape to mesh
TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;