const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
// poly elements are not supported by med-2.1
- bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
+ bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
// nodes on VERTEXes where 0D elements are absent
namespace
{
- int dependsOnMapKey( const SMESH_subMesh* sm )
+ int dependsOnMapKey( TopAbs_ShapeEnum type, int shapeID )
{
- int type = sm->GetSubShape().ShapeType();
- int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
- int cle = sm->GetId();
+ int ordType = 9 - int(type); // 2 = Vertex, 8 = CompSolid
+ int cle = shapeID;
cle += 10000000 * ordType; // sort map by ordType then index
return cle;
}
+ int dependsOnMapKey( const SMESH_subMesh* sm )
+ {
+ return dependsOnMapKey( sm->GetSubShape().ShapeType(), sm->GetId() );
+ }
}
//=============================================================================
return other ? _mapDepend.count( dependsOnMapKey( other )) : false;
}
+//================================================================================
+/*!
+ * \brief Return \c true if \a this sub-mesh depends on a \a shape
+ */
+//================================================================================
+
+bool SMESH_subMesh::DependsOn( const int shapeID ) const
+{
+ return DependsOn( _father->GetSubMeshContaining( shapeID ));
+}
+
//=============================================================================
/*!
* Return a shape of \a this sub-mesh
const std::map < int, SMESH_subMesh * >& DependsOn();
bool DependsOn( const SMESH_subMesh* other ) const;
+ bool DependsOn( const int shapeID ) const;
/*!
* \brief Return iterator on the sub-meshes this one depends on. By default
* most simple sub-meshes go first.
MESSAGE("add element in subshape already belonging to that subshape "
<< ME->GetID() << " " << oldShapeId << " " << idInSubShape);
// check if ok: do nothing if ok
- if (idInSubShape >= myElements.size())
+ if (idInSubShape >= (int)myElements.size())
{
throw SALOME_Exception(LOCALIZED("out of bounds"));
}
SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
elem->setShapeId(0);
elem->setIdInShape(-1);
- if ((idInSubShape >= 0) && (idInSubShape < myElements.size()))
+ if ((idInSubShape >= 0) && (idInSubShape < (int) myElements.size()))
{
myElements[idInSubShape] = 0; // this vector entry is no more used
if ( ++myUnusedIdElements == (int) myElements.size() )
if ( shapeId != myIndex )
throw SALOME_Exception
(LOCALIZED("a node being in sub-mesh is added to another sub-mesh"));
- if ( idInSubShape >= myNodes.size() || myNodes[ idInSubShape ] != N )
+ if ( idInSubShape >= (int)myNodes.size() || myNodes[ idInSubShape ] != N )
throw SALOME_Exception
(LOCALIZED("a node with wrong idInSubShape is re-added to the same sub-mesh"));
return; // already in
SMDS_MeshNode* node = (SMDS_MeshNode*) (N);
node->setShapeId(0);
node->setIdInShape(-1);
- if ((idInSubShape >= 0) && (idInSubShape < myNodes.size()))
+ if ((idInSubShape >= 0) && (idInSubShape < (int) myNodes.size()))
{
myNodes[idInSubShape] = 0; // this vector entry is no more used
if ( ++myUnusedIdNodes == (int) myNodes.size() )
{
public:
MyIterator (const set<const SMESHDS_SubMesh*>& theSubMeshes)
- : mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() ), myMore(false)
+ : myMore(false), mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() )
{}
bool more()
{
if (ME->GetType() == SMDSAbs_Node)
{
int idInShape = ME->getIdInShape();
- if ((idInShape >= 0) && (idInShape < myNodes.size()))
+ if ((idInShape >= 0) && (idInShape < (int) myNodes.size()))
if (myNodes[idInShape] == ME)
return true;
}
else
{
int idInShape = ME->getIdInShape();
- if ((idInShape >= 0) && (idInShape < myElements.size()))
+ if ((idInShape >= 0) && (idInShape < (int) myElements.size()))
if (myElements[idInShape] == ME)
return true;
}
myUnusedIdNodes = 0;
}
}
+
+//=======================================================================
+//function : GetElement
+//purpose : Return an element by its IdInShape
+//=======================================================================
+
+const SMDS_MeshElement* SMESHDS_SubMesh::GetElement( size_t idInShape ) const
+{
+ return ( !IsComplexSubmesh() && idInShape < myElements.size() ) ? myElements[idInShape] : 0;
+}
+
+//=======================================================================
+//function : GetElement
+//purpose : Return a node by its IdInShape
+//=======================================================================
+
+const SMDS_MeshNode* SMESHDS_SubMesh::GetNode( size_t idInShape ) const
+{
+ return ( !IsComplexSubmesh() && idInShape < myNodes.size() ) ? myNodes[idInShape] : 0;
+}
virtual bool RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted); // ret true if ME was in
virtual void AddNode(const SMDS_MeshNode * ME);
virtual bool RemoveNode(const SMDS_MeshNode * ME, bool isNodeDeleted); // ret true if ME was in
+ virtual const SMDS_MeshElement* GetElement( size_t idInShape ) const;
+ virtual const SMDS_MeshNode* GetNode ( size_t idInShape ) const;
// if IsComplexSubmesh()
void AddSubMesh( const SMESHDS_SubMesh* theSubMesh );
*/
//=======================================================================
-double SMESH_MeshAlgos::GetDistance( const SMDS_MeshEdge* edge, const gp_Pnt& point )
+double SMESH_MeshAlgos::GetDistance( const SMDS_MeshEdge* seg, const gp_Pnt& point )
{
- throw SALOME_Exception(LOCALIZED("not implemented so far"));
+ double dist = Precision::Infinite();
+ if ( !seg ) return dist;
+
+ int i = 0, nbNodes = seg->NbNodes();
+
+ vector< SMESH_TNodeXYZ > xyz( nbNodes );
+ SMDS_ElemIteratorPtr nodeIt = seg->interlacedNodesElemIterator();
+ while ( nodeIt->more() )
+ xyz[ i++ ].Set( nodeIt->next() );
+
+ for ( i = 1; i < nbNodes; ++i )
+ {
+ gp_Vec edge( xyz[i-1], xyz[i] );
+ gp_Vec n1p ( xyz[i-1], point );
+ double u = ( edge * n1p ) / edge.SquareMagnitude(); // param [0,1] on the edge
+ if ( u <= 0. ) {
+ dist = Min( dist, n1p.SquareMagnitude() );
+ }
+ else if ( u >= 1. ) {
+ dist = Min( dist, point.SquareDistance( xyz[i] ));
+ }
+ else {
+ gp_XYZ proj = ( 1. - u ) * xyz[i-1] + u * xyz[i]; // projection of the point on the edge
+ dist = Min( dist, point.SquareDistance( proj ));
+ }
+ }
+ return Sqrt( dist );
}
//=======================================================================