Update to match the change of SMDS (new DS).

This commit is contained in:
jrt 2003-09-04 09:21:41 +00:00
parent 0273fe09c6
commit bb2c60c2b6
13 changed files with 3695 additions and 3736 deletions

View File

@ -32,9 +32,6 @@ using namespace std;
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESHDS_ListOfPtrHypothesis.hxx"
#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
#include <GeomAdaptor_Curve.hxx> #include <GeomAdaptor_Curve.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <GCPnts_AbscissaPoint.hxx> #include <GCPnts_AbscissaPoint.hxx>
@ -49,12 +46,12 @@ using namespace std;
*/ */
//============================================================================= //=============================================================================
SMESH_Algo::SMESH_Algo(int hypId, int studyId, SMESH_Gen* gen) SMESH_Algo::SMESH_Algo(int hypId, int studyId,
: SMESH_Hypothesis(hypId, studyId, gen) SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
{ {
// _compatibleHypothesis.push_back("hypothese_bidon"); // _compatibleHypothesis.push_back("hypothese_bidon");
_type = ALGO; _type = ALGO;
gen->_mapAlgo[hypId] = this; gen->_mapAlgo[hypId] = this;
} }
//============================================================================= //=============================================================================
@ -73,9 +70,9 @@ SMESH_Algo::~SMESH_Algo()
*/ */
//============================================================================= //=============================================================================
const vector<string> & SMESH_Algo::GetCompatibleHypothesis() const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
{ {
return _compatibleHypothesis; return _compatibleHypothesis;
} }
//============================================================================= //=============================================================================
@ -86,7 +83,7 @@ const vector<string> & SMESH_Algo::GetCompatibleHypothesis()
ostream & SMESH_Algo::SaveTo(ostream & save) ostream & SMESH_Algo::SaveTo(ostream & save)
{ {
return save << this; return save << this;
} }
//============================================================================= //=============================================================================
@ -97,7 +94,7 @@ ostream & SMESH_Algo::SaveTo(ostream & save)
istream & SMESH_Algo::LoadFrom(istream & load) istream & SMESH_Algo::LoadFrom(istream & load)
{ {
return load >> (*this); return load >> (*this);
} }
//============================================================================= //=============================================================================
@ -106,9 +103,9 @@ istream & SMESH_Algo::LoadFrom(istream & load)
*/ */
//============================================================================= //=============================================================================
ostream& operator << (ostream & save, SMESH_Algo & hyp) ostream & operator <<(ostream & save, SMESH_Algo & hyp)
{ {
return save; return save;
} }
//============================================================================= //=============================================================================
@ -117,9 +114,9 @@ ostream& operator << (ostream & save, SMESH_Algo & hyp)
*/ */
//============================================================================= //=============================================================================
istream& operator >> (istream & load, SMESH_Algo & hyp) istream & operator >>(istream & load, SMESH_Algo & hyp)
{ {
return load; return load;
} }
//============================================================================= //=============================================================================
@ -128,12 +125,12 @@ istream& operator >> (istream & load, SMESH_Algo & hyp)
*/ */
//============================================================================= //=============================================================================
bool SMESH_Algo::CheckHypothesis(SMESH_Mesh& aMesh, bool SMESH_Algo::CheckHypothesis(SMESH_Mesh & aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape & aShape)
{ {
MESSAGE("SMESH_Algo::CheckHypothesis"); MESSAGE("SMESH_Algo::CheckHypothesis");
ASSERT(0); // use method from derived classes ASSERT(0); // use method from derived classes
return false; return false;
} }
//============================================================================= //=============================================================================
@ -142,12 +139,11 @@ bool SMESH_Algo::CheckHypothesis(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
bool SMESH_Algo::Compute(SMESH_Mesh& aMesh, bool SMESH_Algo::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
const TopoDS_Shape& aShape)
{ {
MESSAGE("SMESH_Algo::Compute"); MESSAGE("SMESH_Algo::Compute");
ASSERT(0); // use method from derived classes ASSERT(0); // use method from derived classes
return false; return false;
} }
//============================================================================= //=============================================================================
@ -160,24 +156,24 @@ bool SMESH_Algo::Compute(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
const list<SMESHDS_Hypothesis*>& const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
SMESH_Algo::GetUsedHypothesis(SMESH_Mesh& aMesh, SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
const TopoDS_Shape& aShape)
{ {
_usedHypList.clear(); _usedHypList.clear();
_usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
int nbHyp = _usedHypList.size(); int nbHyp = _usedHypList.size();
if (nbHyp == 0) if (nbHyp == 0)
{
TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
if (!mainShape.IsSame(aShape))
{ {
_usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
nbHyp = _usedHypList.size(); if (!mainShape.IsSame(aShape))
{
_usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy
nbHyp = _usedHypList.size();
}
} }
} if (nbHyp > 1)
if (nbHyp > 1) _usedHypList.clear(); //only one compatible hypothesis allowed _usedHypList.clear(); //only one compatible hypothesis allowed
return _usedHypList; return _usedHypList;
} }
//============================================================================= //=============================================================================
@ -188,56 +184,54 @@ SMESH_Algo::GetUsedHypothesis(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
const list<SMESHDS_Hypothesis*>& const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh& aMesh, SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
const TopoDS_Shape& aShape)
{ {
const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS(); const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
const SMESHDS_ListOfPtrHypothesis& listHyp = meshDS->GetHypothesis(aShape); const list<const SMESHDS_Hypothesis*> & listHyp = meshDS->GetHypothesis(aShape);
SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp); list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
int hypType; int hypType;
string hypName; string hypName;
_appliedHypList.clear(); _appliedHypList.clear();
while (it.More()) while (it!=listHyp.end())
{
SMESHDS_Hypothesis* anHyp = it.Value();
hypType = anHyp->GetType();
//SCRUTE(hypType);
if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
{ {
hypName = anHyp->GetName(); const SMESHDS_Hypothesis *anHyp = *it;
vector<string>::iterator ith = find(_compatibleHypothesis.begin(), hypType = anHyp->GetType();
_compatibleHypothesis.end(), //SCRUTE(hypType);
hypName); if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
if (ith != _compatibleHypothesis.end()) // count only relevant {
{ hypName = anHyp->GetName();
_appliedHypList.push_back(anHyp); vector < string >::iterator ith =
//SCRUTE(hypName); find(_compatibleHypothesis.begin(), _compatibleHypothesis.end(),
} hypName);
if (ith != _compatibleHypothesis.end()) // count only relevant
{
_appliedHypList.push_back(anHyp);
//SCRUTE(hypName);
}
}
it++;
} }
it.Next(); return _appliedHypList;
}
return _appliedHypList;
} }
//============================================================================= //=============================================================================
/*! /*!
* Compute length of an edge * Compute length of an edge
*/ */
//============================================================================= //=============================================================================
double SMESH_Algo::EdgeLength(const TopoDS_Edge& E) double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
{ {
double UMin = 0, UMax = 0; double UMin = 0, UMax = 0;
TopLoc_Location L; TopLoc_Location L;
if (BRep_Tool::Degenerated(E)) return 0; if (BRep_Tool::Degenerated(E))
Handle (Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); return 0;
GeomAdaptor_Curve AdaptCurve(C); Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
GCPnts_AbscissaPoint gabs; GeomAdaptor_Curve AdaptCurve(C);
double length = gabs.Length(AdaptCurve, UMin, UMax); GCPnts_AbscissaPoint gabs;
return length; double length = gabs.Length(AdaptCurve, UMin, UMax);
return length;
} }

View File

@ -37,43 +37,40 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <list> #include <list>
using namespace std;
class SMESH_gen; class SMESH_gen;
class SMESH_Mesh; class SMESH_Mesh;
class SMESH_Algo: class SMESH_Algo:public SMESH_Hypothesis
public SMESH_Hypothesis
{ {
public: public:
SMESH_Algo(int hypId, int studyId, SMESH_Gen* gen); SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
virtual ~SMESH_Algo(); virtual ~ SMESH_Algo();
const vector<string> & GetCompatibleHypothesis(); const vector < string > &GetCompatibleHypothesis();
virtual bool CheckHypothesis(SMESH_Mesh& aMesh, virtual bool CheckHypothesis(SMESH_Mesh & aMesh,
const TopoDS_Shape& aShape); const TopoDS_Shape & aShape);
virtual bool Compute(SMESH_Mesh& aMesh, virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
const TopoDS_Shape& aShape);
virtual const list<SMESHDS_Hypothesis*>& virtual const list <const SMESHDS_Hypothesis *> &
GetUsedHypothesis(SMESH_Mesh& aMesh, GetUsedHypothesis(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
const TopoDS_Shape& aShape);
const list<SMESHDS_Hypothesis*>& const list <const SMESHDS_Hypothesis *> &
GetAppliedHypothesis(SMESH_Mesh& aMesh, GetAppliedHypothesis(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
const TopoDS_Shape& aShape);
static double EdgeLength(const TopoDS_Edge& E); static double EdgeLength(const TopoDS_Edge & E);
virtual ostream & SaveTo(ostream & save); virtual ostream & SaveTo(ostream & save);
virtual istream & LoadFrom(istream & load); virtual istream & LoadFrom(istream & load);
friend ostream& operator << (ostream & save, SMESH_Algo & hyp); friend ostream & operator <<(ostream & save, SMESH_Algo & hyp);
friend istream& operator >> (istream & load, SMESH_Algo & hyp); friend istream & operator >>(istream & load, SMESH_Algo & hyp);
protected: protected:
vector<string> _compatibleHypothesis; vector<string> _compatibleHypothesis;
list<SMESHDS_Hypothesis*> _appliedHypList; list<const SMESHDS_Hypothesis *> _appliedHypList;
list<SMESHDS_Hypothesis*> _usedHypList; list<const SMESHDS_Hypothesis *> _usedHypList;
}; };
#endif #endif

View File

@ -26,14 +26,8 @@
// Module : SMESH // Module : SMESH
// $Header$ // $Header$
using namespace std;
using namespace std;
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_subMesh.hxx" #include "SMESH_subMesh.hxx"
#include "SMESHDS_ListOfPtrHypothesis.hxx"
#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
#include "SMDS_MeshElement.hxx" #include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
@ -51,9 +45,9 @@ using namespace std;
SMESH_Gen::SMESH_Gen() SMESH_Gen::SMESH_Gen()
{ {
MESSAGE("SMESH_Gen::SMESH_Gen"); MESSAGE("SMESH_Gen::SMESH_Gen");
_localId = 0; _localId = 0;
_hypothesisFactory.SetGen(this); _hypothesisFactory.SetGen(this);
} }
//============================================================================= //=============================================================================
@ -64,7 +58,7 @@ SMESH_Gen::SMESH_Gen()
SMESH_Gen::~SMESH_Gen() SMESH_Gen::~SMESH_Gen()
{ {
MESSAGE("SMESH_Gen::~SMESH_Gen"); MESSAGE("SMESH_Gen::~SMESH_Gen");
} }
//============================================================================= //=============================================================================
@ -73,27 +67,27 @@ SMESH_Gen::~SMESH_Gen()
*/ */
//============================================================================= //=============================================================================
SMESH_Hypothesis* SMESH_Gen::CreateHypothesis(const char* anHyp, SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
int studyId) throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
MESSAGE("SMESH_Gen::CreateHypothesis");
// Get studyContext, create it if it does'nt exist, with a SMESHDS_Document MESSAGE("CreateHypothesis("<<anHyp<<","<<studyId<<")");
// Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
StudyContextStruct* myStudyContext = GetStudyContext(studyId); StudyContextStruct *myStudyContext = GetStudyContext(studyId);
// create a new hypothesis object, store its ref. in studyContext // create a new hypothesis object, store its ref. in studyContext
SMESH_Hypothesis* myHypothesis = _hypothesisFactory.Create(anHyp, studyId); SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId);
int hypId = myHypothesis->GetID(); int hypId = myHypothesis->GetID();
myStudyContext->mapHypothesis[hypId] = myHypothesis; myStudyContext->mapHypothesis[hypId] = myHypothesis;
SCRUTE(studyId); SCRUTE(studyId);
SCRUTE(hypId); SCRUTE(hypId);
// store hypothesis in SMESHDS document // store hypothesis in SMESHDS document
myStudyContext->myDocument->AddHypothesis(myHypothesis); myStudyContext->myDocument->AddHypothesis(myHypothesis);
return myHypothesis;
} }
//============================================================================= //=============================================================================
@ -102,32 +96,32 @@ SMESH_Hypothesis* SMESH_Gen::CreateHypothesis(const char* anHyp,
*/ */
//============================================================================= //=============================================================================
SMESH_Mesh* SMESH_Gen::Init(int studyId, const TopoDS_Shape& aShape) SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Gen::Init"); MESSAGE("SMESH_Gen::Init");
// if (aShape.ShapeType() == TopAbs_COMPOUND) // if (aShape.ShapeType() == TopAbs_COMPOUND)
// { // {
// INFOS("Mesh Compound not yet implemented!"); // INFOS("Mesh Compound not yet implemented!");
// throw(SALOME_Exception(LOCALIZED("Mesh Compound not yet implemented!"))); // throw(SALOME_Exception(LOCALIZED("Mesh Compound not yet implemented!")));
// } // }
// Get studyContext, create it if it does'nt exist, with a SMESHDS_Document // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
StudyContextStruct* myStudyContext = GetStudyContext(studyId); StudyContextStruct *myStudyContext = GetStudyContext(studyId);
// create a new SMESH_mesh object // create a new SMESH_mesh object
SMESH_Mesh* mesh = new SMESH_Mesh(_localId++, SMESH_Mesh *mesh = new SMESH_Mesh(_localId++,
studyId, studyId,
this, this,
myStudyContext->myDocument); myStudyContext->myDocument);
myStudyContext->mapMesh[_localId] = mesh; myStudyContext->mapMesh[_localId] = mesh;
// associate a TopoDS_Shape to the mesh // associate a TopoDS_Shape to the mesh
mesh->ShapeToMesh(aShape); mesh->ShapeToMesh(aShape);
return mesh; return mesh;
} }
//============================================================================= //=============================================================================
@ -136,10 +130,10 @@ SMESH_Mesh* SMESH_Gen::Init(int studyId, const TopoDS_Shape& aShape)
*/ */
//============================================================================= //=============================================================================
bool SMESH_Gen::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Gen::Compute"); MESSAGE("SMESH_Gen::Compute");
// bool isDone = false; // bool isDone = false;
/* /*
Algo : s'appuie ou non sur une geometrie Algo : s'appuie ou non sur une geometrie
@ -150,134 +144,46 @@ Face, Shell, collection de Face et Shells : 2D
Solid, Collection de Solid : 3D Solid, Collection de Solid : 3D
*/ */
// *** corriger commentaires // *** corriger commentaires
// check hypothesis associated to the mesh : // check hypothesis associated to the mesh :
// - only one algo : type compatible with the type of the shape // - only one algo : type compatible with the type of the shape
// - hypothesis = compatible with algo // - hypothesis = compatible with algo
// - check if hypothesis are applicable to this algo // - check if hypothesis are applicable to this algo
// - check contradictions within hypothesis // - check contradictions within hypothesis
// (test if enough hypothesis is done further) // (test if enough hypothesis is done further)
bool ret = true; bool ret = true;
SMESH_subMesh* sm = aMesh.GetSubMesh(aShape); SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
// SCRUTE(sm); // SCRUTE(sm);
SMESH_subMesh* smToCompute = sm->GetFirstToCompute(); SMESH_subMesh *smToCompute = sm->GetFirstToCompute();
while (smToCompute) while (smToCompute)
{
TopoDS_Shape subShape = smToCompute->GetSubShape();
int dim = GetShapeDim(subShape);
//SCRUTE(dim);
if (dim > 0)
{ {
bool ret1 = smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE); TopoDS_Shape subShape = smToCompute->GetSubShape();
ret = ret && ret1; int dim = GetShapeDim(subShape);
} //SCRUTE(dim);
else if (dim > 0)
{
ASSERT(dim == 0);
ASSERT(smToCompute->_vertexSet == false);
TopoDS_Vertex V1 = TopoDS::Vertex(subShape);
gp_Pnt P1 = BRep_Tool::Pnt(V1);
const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
int nodeId = meshDS->AddNode(P1.X(), P1.Y(), P1.Z());
//MESSAGE("point "<<nodeId<<" "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z());
Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
meshDS->SetNodeOnVertex(node, V1);
const Handle(SMESHDS_SubMesh)& subMeshDS
= smToCompute->GetSubMeshDS();
smToCompute->_vertexSet = true;
bool ret1 = smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE);
}
smToCompute = sm->GetFirstToCompute();
}
return ret;
}
//=============================================================================
/*!
*
*/
//=============================================================================
SMESH_Algo* SMESH_Gen::GetAlgo(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
{
//MESSAGE("SMESH_Gen::GetAlgo");
SMESHDS_Hypothesis* theHyp = NULL;
SMESH_Algo* algo = NULL;
const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
int hypType;
int hypId;
int algoDim;
// try shape first, then main shape
TopoDS_Shape mainShape = meshDS->ShapeToMesh();
const TopoDS_Shape* shapeToTry[2] = {&aShape, &mainShape};
for (int iShape=0; iShape<2; iShape++)
{
TopoDS_Shape tryShape = (*shapeToTry[iShape]);
const SMESHDS_ListOfPtrHypothesis& listHyp
= meshDS->GetHypothesis(tryShape);
SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp);
int nb_algo = 0;
int shapeDim = GetShapeDim(aShape);
int typeOfShape = aShape.ShapeType();
while (it.More())
{
SMESHDS_Hypothesis* anHyp = it.Value();
hypType = anHyp->GetType();
// SCRUTE(hypType);
if (hypType > SMESHDS_Hypothesis::PARAM_ALGO)
{
switch (hypType)
{ {
case SMESHDS_Hypothesis::ALGO_1D: algoDim=1; break; bool ret1 = smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE);
case SMESHDS_Hypothesis::ALGO_2D: algoDim=2; break; ret = ret && ret1;
case SMESHDS_Hypothesis::ALGO_3D: algoDim=3; break;
default: algoDim=0; break;
} }
// SCRUTE(algoDim); else
// SCRUTE(shapeDim); {
// SCRUTE(typeOfShape); ASSERT(dim == 0);
if (shapeDim == algoDim) // count only algos of shape dim. ASSERT(smToCompute->_vertexSet == false);
{ // discard algos for subshapes TopoDS_Vertex V1 = TopoDS::Vertex(subShape);
hypId = anHyp->GetID(); // (of lower dim.) gp_Pnt P1 = BRep_Tool::Pnt(V1);
ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end()); SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
SMESH_Algo* anAlgo = _mapAlgo[hypId]; //MESSAGE("point "<<nodeId<<" "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z());
//SCRUTE(anAlgo->GetShapeType()); SMDS_MeshNode * node = meshDS->AddNode(P1.X(), P1.Y(), P1.Z());
// if (anAlgo->GetShapeType() == typeOfShape) meshDS->SetNodeOnVertex(node, V1);
if ((anAlgo->GetShapeType()) & (1 << typeOfShape)) smToCompute->GetSubMeshDS();
{ // only specific TopoDS_Shape smToCompute->_vertexSet = true;
nb_algo++; smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE);
theHyp = anHyp;
}
} }
} smToCompute = sm->GetFirstToCompute();
if (nb_algo > 1) return NULL; // more than one algo
it.Next();
} }
if (nb_algo == 1) // one algo found : OK
break; // do not try a parent shape
}
if (!theHyp) return NULL; // no algo found return ret;
hypType = theHyp->GetType();
hypId = theHyp->GetID();
ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end());
algo = _mapAlgo[hypId];
const char* algoName = algo->GetName();
//MESSAGE("Algo found " << algoName << " Id " << hypId);
return algo;
} }
//============================================================================= //=============================================================================
@ -286,18 +192,110 @@ SMESH_Algo* SMESH_Gen::GetAlgo(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
StudyContextStruct* SMESH_Gen::GetStudyContext(int studyId) SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
{ {
// Get studyContext, create it if it does'nt exist, with a SMESHDS_Document //MESSAGE("SMESH_Gen::GetAlgo");
if (_mapStudyContext.find(studyId) == _mapStudyContext.end()) const SMESHDS_Hypothesis *theHyp = NULL;
{ SMESH_Algo *algo = NULL;
_mapStudyContext[studyId] = new StudyContextStruct; const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
_mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId); int hypType;
} int hypId;
StudyContextStruct* myStudyContext = _mapStudyContext[studyId]; int algoDim;
// try shape first, then main shape
TopoDS_Shape mainShape = meshDS->ShapeToMesh();
const TopoDS_Shape *shapeToTry[2] = { &aShape, &mainShape };
for (int iShape = 0; iShape < 2; iShape++)
{
TopoDS_Shape tryShape = (*shapeToTry[iShape]);
const list<const SMESHDS_Hypothesis*>& listHyp =
meshDS->GetHypothesis(tryShape);
list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
int nb_algo = 0;
int shapeDim = GetShapeDim(aShape);
int typeOfShape = aShape.ShapeType();
while (it!=listHyp.end())
{
const SMESHDS_Hypothesis *anHyp = *it;
hypType = anHyp->GetType();
//SCRUTE(hypType);
if (hypType > SMESHDS_Hypothesis::PARAM_ALGO)
{
switch (hypType)
{
case SMESHDS_Hypothesis::ALGO_1D:
algoDim = 1;
break;
case SMESHDS_Hypothesis::ALGO_2D:
algoDim = 2;
break;
case SMESHDS_Hypothesis::ALGO_3D:
algoDim = 3;
break;
default:
algoDim = 0;
break;
}
//SCRUTE(algoDim);
//SCRUTE(shapeDim);
//SCRUTE(typeOfShape);
if (shapeDim == algoDim) // count only algos of shape dim.
{ // discard algos for subshapes
hypId = anHyp->GetID(); // (of lower dim.)
ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end());
SMESH_Algo *anAlgo = _mapAlgo[hypId];
//SCRUTE(anAlgo->GetShapeType());
//if (anAlgo->GetShapeType() == typeOfShape)
if ((anAlgo->GetShapeType()) & (1 << typeOfShape))
{ // only specific TopoDS_Shape
nb_algo++;
theHyp = anHyp;
}
}
}
if (nb_algo > 1) return NULL; // more than one algo
it++;
}
if (nb_algo == 1) // one algo found : OK
break; // do not try a parent shape
}
if (!theHyp)
return NULL; // no algo found
hypType = theHyp->GetType();
hypId = theHyp->GetID();
ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end());
algo = _mapAlgo[hypId];
//MESSAGE("Algo found " << algo->GetName() << " Id " << hypId);
return algo;
}
//=============================================================================
/*!
*
*/
//=============================================================================
StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
{
// Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
{
_mapStudyContext[studyId] = new StudyContextStruct;
_mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
}
StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
// ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end()); // ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
return myStudyContext; return myStudyContext;
} }
//============================================================================= //=============================================================================
@ -318,7 +316,7 @@ void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
void SMESH_Gen::Load(int studyId, const char *aUrlOfFile) void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
{ {
} }
//============================================================================= //=============================================================================
/*! /*!
@ -329,17 +327,6 @@ void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
void SMESH_Gen::Close(int studyId) void SMESH_Gen::Close(int studyId)
{ {
} }
//=============================================================================
/*!
*
*/
//=============================================================================
const char* SMESH_Gen::ComponentDataType()
{
}
//============================================================================= //=============================================================================
/*! /*!
@ -347,8 +334,7 @@ const char* SMESH_Gen::ComponentDataType()
*/ */
//============================================================================= //=============================================================================
const char* SMESH_Gen::IORToLocalPersistentID(const char* IORString, const char *SMESH_Gen::ComponentDataType()
bool& IsAFile)
{ {
} }
@ -358,7 +344,8 @@ const char* SMESH_Gen::IORToLocalPersistentID(const char* IORString,
*/ */
//============================================================================= //=============================================================================
const char* SMESH_Gen::LocalPersistentIDToIOR(const char* aLocalPersistentID) const char *SMESH_Gen::IORToLocalPersistentID(const char *IORString,
bool & IsAFile)
{ {
} }
@ -368,42 +355,52 @@ const char* SMESH_Gen::LocalPersistentIDToIOR(const char* aLocalPersistentID)
*/ */
//============================================================================= //=============================================================================
int SMESH_Gen::GetShapeDim(const TopoDS_Shape& aShape) const char *SMESH_Gen::LocalPersistentIDToIOR(const char *aLocalPersistentID)
{ {
int shapeDim = -1; // Shape dimension: 0D, 1D, 2D, 3D }
int type = aShape.ShapeType();
switch (type) //=============================================================================
{ /*!
*
*/
//=============================================================================
int SMESH_Gen::GetShapeDim(const TopoDS_Shape & aShape)
{
int shapeDim = -1; // Shape dimension: 0D, 1D, 2D, 3D
int type = aShape.ShapeType();
switch (type)
{
// case TopAbs_COMPOUND: // case TopAbs_COMPOUND:
// { // {
// break; // break;
// } // }
case TopAbs_COMPOUND: case TopAbs_COMPOUND:
case TopAbs_COMPSOLID: case TopAbs_COMPSOLID:
case TopAbs_SOLID: case TopAbs_SOLID:
case TopAbs_SHELL: case TopAbs_SHELL:
{ {
shapeDim = 3; shapeDim = 3;
break; break;
} }
// case TopAbs_SHELL: // case TopAbs_SHELL:
case TopAbs_FACE: case TopAbs_FACE:
{ {
shapeDim = 2; shapeDim = 2;
break; break;
} }
case TopAbs_WIRE: case TopAbs_WIRE:
case TopAbs_EDGE: case TopAbs_EDGE:
{ {
shapeDim = 1; shapeDim = 1;
break; break;
} }
case TopAbs_VERTEX: case TopAbs_VERTEX:
{ {
shapeDim = 0; shapeDim = 0;
break; break;
} }
} }
// SCRUTE(shapeDim); // SCRUTE(shapeDim);
return shapeDim; return shapeDim;
} }

View File

@ -44,52 +44,53 @@
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <map> #include <map>
using namespace std;
typedef struct studyContextStruct typedef struct studyContextStruct
{ {
map<int, SMESH_Hypothesis*> mapHypothesis; map < int, SMESH_Hypothesis * >mapHypothesis;
map<int, SMESH_Mesh*> mapMesh; map < int, SMESH_Mesh * >mapMesh;
Handle (SMESHDS_Document) myDocument; SMESHDS_Document * myDocument;
} StudyContextStruct ; } StudyContextStruct;
class SMESH_Gen class SMESH_Gen
{ {
public: public:
SMESH_Gen(); SMESH_Gen();
~SMESH_Gen(); ~SMESH_Gen();
SMESH_Hypothesis* CreateHypothesis(const char* anHyp, int studyId) SMESH_Hypothesis *CreateHypothesis(const char *anHyp, int studyId)
throw (SALOME_Exception); throw(SALOME_Exception);
SMESH_Mesh* Init(int studyId, const TopoDS_Shape& aShape) SMESH_Mesh *Init(int studyId, const TopoDS_Shape & aShape)
throw (SALOME_Exception); throw(SALOME_Exception);
bool Compute(::SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) bool Compute(::SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
throw (SALOME_Exception); throw(SALOME_Exception);
StudyContextStruct* GetStudyContext(int studyId); StudyContextStruct *GetStudyContext(int studyId);
static int GetShapeDim(const TopoDS_Shape& aShape); static int GetShapeDim(const TopoDS_Shape & aShape);
SMESH_Algo* GetAlgo(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); SMESH_Algo *GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
// inherited methods from SALOMEDS::Driver // inherited methods from SALOMEDS::Driver
void Save(int studyId, const char *aUrlOfFile); void Save(int studyId, const char *aUrlOfFile);
void Load(int studyId, const char *aUrlOfFile); void Load(int studyId, const char *aUrlOfFile);
void Close(int studyId); void Close(int studyId);
const char* ComponentDataType(); const char *ComponentDataType();
const char* IORToLocalPersistentID(const char* IORString, bool& IsAFile); const char *IORToLocalPersistentID(const char *IORString, bool & IsAFile);
const char* LocalPersistentIDToIOR(const char* aLocalPersistentID); const char *LocalPersistentIDToIOR(const char *aLocalPersistentID);
SMESH_HypothesisFactory _hypothesisFactory; SMESH_HypothesisFactory _hypothesisFactory;
map<int, SMESH_Algo*> _mapAlgo; map < int, SMESH_Algo * >_mapAlgo;
map<int, SMESH_1D_Algo*> _map1D_Algo; map < int, SMESH_1D_Algo * >_map1D_Algo;
map<int, SMESH_2D_Algo*> _map2D_Algo; map < int, SMESH_2D_Algo * >_map2D_Algo;
map<int, SMESH_3D_Algo*> _map3D_Algo; map < int, SMESH_3D_Algo * >_map3D_Algo;
private: private:
int _localId; // unique Id of created objects, within SMESH_Gen entity int _localId; // unique Id of created objects, within SMESH_Gen entity
map<int, StudyContextStruct*> _mapStudyContext; map < int, StudyContextStruct * >_mapStudyContext;
map<int, SMESH_Hypothesis*> _mapHypothesis; map < int, SMESH_Hypothesis * >_mapHypothesis;
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@
// Module : SMESH // Module : SMESH
// $Header$ // $Header$
using namespace std;
using namespace std; using namespace std;
#include "SMESH_MEFISTO_2D.hxx" #include "SMESH_MEFISTO_2D.hxx"
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
@ -38,8 +37,6 @@ using namespace std;
#include "Rn.h" #include "Rn.h"
#include "aptrte.h" #include "aptrte.h"
#include "SMESHDS_ListOfPtrHypothesis.hxx"
#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
#include "SMDS_MeshElement.hxx" #include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
#include "SMDS_EdgePosition.hxx" #include "SMDS_EdgePosition.hxx"
@ -70,20 +67,20 @@ using namespace std;
*/ */
//============================================================================= //=============================================================================
SMESH_MEFISTO_2D::SMESH_MEFISTO_2D(int hypId, int studyId, SMESH_Gen* gen) SMESH_MEFISTO_2D::SMESH_MEFISTO_2D(int hypId, int studyId,
: SMESH_2D_Algo(hypId, studyId, gen) SMESH_Gen * gen):SMESH_2D_Algo(hypId, studyId, gen)
{ {
MESSAGE("SMESH_MEFISTO_2D::SMESH_MEFISTO_2D"); MESSAGE("SMESH_MEFISTO_2D::SMESH_MEFISTO_2D");
_name = "MEFISTO_2D"; _name = "MEFISTO_2D";
// _shapeType = TopAbs_FACE; // _shapeType = TopAbs_FACE;
_shapeType = (1<<TopAbs_FACE); _shapeType = (1 << TopAbs_FACE);
_compatibleHypothesis.push_back("MaxElementArea"); _compatibleHypothesis.push_back("MaxElementArea");
_compatibleHypothesis.push_back("LengthFromEdges"); _compatibleHypothesis.push_back("LengthFromEdges");
_edgeLength = 0; _edgeLength = 0;
_maxElementArea = 0; _maxElementArea = 0;
_hypMaxElementArea = NULL; _hypMaxElementArea = NULL;
_hypLengthFromEdges = NULL; _hypLengthFromEdges = NULL;
} }
//============================================================================= //=============================================================================
@ -94,7 +91,7 @@ SMESH_MEFISTO_2D::SMESH_MEFISTO_2D(int hypId, int studyId, SMESH_Gen* gen)
SMESH_MEFISTO_2D::~SMESH_MEFISTO_2D() SMESH_MEFISTO_2D::~SMESH_MEFISTO_2D()
{ {
MESSAGE("SMESH_MEFISTO_2D::~SMESH_MEFISTO_2D"); MESSAGE("SMESH_MEFISTO_2D::~SMESH_MEFISTO_2D");
} }
//============================================================================= //=============================================================================
@ -103,147 +100,145 @@ SMESH_MEFISTO_2D::~SMESH_MEFISTO_2D()
*/ */
//============================================================================= //=============================================================================
bool SMESH_MEFISTO_2D::CheckHypothesis(SMESH_Mesh& aMesh, bool SMESH_MEFISTO_2D::CheckHypothesis(SMESH_Mesh & aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape & aShape)
{ {
//MESSAGE("SMESH_MEFISTO_2D::CheckHypothesis"); //MESSAGE("SMESH_MEFISTO_2D::CheckHypothesis");
_hypMaxElementArea = NULL; _hypMaxElementArea = NULL;
_hypLengthFromEdges = NULL; _hypLengthFromEdges = NULL;
list<SMESHDS_Hypothesis*>::const_iterator itl; list <const SMESHDS_Hypothesis * >::const_iterator itl;
SMESHDS_Hypothesis* theHyp; const SMESHDS_Hypothesis *theHyp;
const list<SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape); const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
int nbHyp = hyps.size(); int nbHyp = hyps.size();
if (nbHyp != 1) return false; // only one compatible hypothesis allowed if (nbHyp != 1) return false;// only one compatible hypothesis allowed
itl = hyps.begin(); itl = hyps.begin();
theHyp = (*itl); theHyp = (*itl);
string hypName = theHyp->GetName(); string hypName = theHyp->GetName();
int hypId = theHyp->GetID(); int hypId = theHyp->GetID();
//SCRUTE(hypName); //SCRUTE(hypName);
bool isOk = false; bool isOk = false;
if (hypName == "MaxElementArea") if (hypName == "MaxElementArea")
{
_hypMaxElementArea = dynamic_cast<SMESH_MaxElementArea*> (theHyp);
ASSERT(_hypMaxElementArea);
_maxElementArea = _hypMaxElementArea->GetMaxArea();
_edgeLength = 0;
isOk =true;
}
if (hypName == "LengthFromEdges")
{
_hypLengthFromEdges = dynamic_cast<SMESH_LengthFromEdges*> (theHyp);
ASSERT(_hypLengthFromEdges);
_edgeLength = 0;
_maxElementArea = 0;
isOk =true;
}
if (isOk)
{
isOk = false;
if (_maxElementArea > 0)
{ {
_edgeLength = 2*sqrt(_maxElementArea); // triangles : minorant _hypMaxElementArea = static_cast<const SMESH_MaxElementArea *>(theHyp);
isOk = true; ASSERT(_hypMaxElementArea);
_maxElementArea = _hypMaxElementArea->GetMaxArea();
_edgeLength = 0;
isOk = true;
} }
else isOk = (_hypLengthFromEdges != NULL); // **** check mode
}
//SCRUTE(_edgeLength); if (hypName == "LengthFromEdges")
//SCRUTE(_maxElementArea); {
return isOk; _hypLengthFromEdges = static_cast<const SMESH_LengthFromEdges *>(theHyp);
ASSERT(_hypLengthFromEdges);
_edgeLength = 0;
_maxElementArea = 0;
isOk = true;
}
if (isOk)
{
isOk = false;
if (_maxElementArea > 0)
{
_edgeLength = 2 * sqrt(_maxElementArea); // triangles : minorant
isOk = true;
}
else
isOk = (_hypLengthFromEdges != NULL); // **** check mode
}
//SCRUTE(_edgeLength);
//SCRUTE(_maxElementArea);
return isOk;
} }
//============================================================================= //=============================================================================
/*! /*!
* *
*/ */
//============================================================================= //=============================================================================
bool SMESH_MEFISTO_2D::Compute(SMESH_Mesh& aMesh, bool SMESH_MEFISTO_2D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
const TopoDS_Shape& aShape)
{ {
MESSAGE("SMESH_MEFISTO_2D::Compute"); MESSAGE("SMESH_MEFISTO_2D::Compute");
if (_hypLengthFromEdges) if (_hypLengthFromEdges)
_edgeLength = ComputeEdgeElementLength(aMesh, aShape); _edgeLength = ComputeEdgeElementLength(aMesh, aShape);
bool isOk = false; bool isOk = false;
const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS(); const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
SMESH_subMesh* theSubMesh = aMesh.GetSubMesh(aShape); SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
const TopoDS_Face& FF = TopoDS::Face(aShape); const TopoDS_Face & FF = TopoDS::Face(aShape);
bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD); bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD);
TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD));
Z nblf; //nombre de lignes fermees (enveloppe en tete) Z nblf; //nombre de lignes fermees (enveloppe en tete)
Z *nudslf=NULL; //numero du dernier sommet de chaque ligne fermee Z *nudslf = NULL; //numero du dernier sommet de chaque ligne fermee
R2 *uvslf=NULL; R2 *uvslf = NULL;
Z nbpti=0; //nombre points internes futurs sommets de la triangulation Z nbpti = 0; //nombre points internes futurs sommets de la triangulation
R2 *uvpti=NULL; R2 *uvpti = NULL;
Z nbst;
R2 *uvst=NULL;
Z nbt;
Z *nust=NULL;
Z ierr=0;
Z nutysu=1; // 1: il existe un fonction areteideale_()
// Z nutysu=0; // 0: on utilise aretmx
R aretmx=_edgeLength; // longueur max aretes future triangulation
//SCRUTE(aretmx);
nblf = NumberOfWires(F); Z nbst;
//SCRUTE(nblf); R2 *uvst = NULL;
Z nbt;
Z *nust = NULL;
Z ierr = 0;
nudslf = new Z[1+nblf]; Z nutysu = 1; // 1: il existe un fonction areteideale_()
nudslf[0] = 0; // Z nutysu=0; // 0: on utilise aretmx
int iw = 1; R aretmx = _edgeLength; // longueur max aretes future triangulation
int nbpnt = 0; //SCRUTE(aretmx);
const TopoDS_Wire OW1 = BRepTools::OuterWire(F); nblf = NumberOfWires(F);
nbpnt += NumberOfPoints (aMesh, OW1); //SCRUTE(nblf);
nudslf [iw++] = nbpnt;
//SCRUTE(nbpnt);
for (TopExp_Explorer exp (F, TopAbs_WIRE); exp.More(); exp.Next()) nudslf = new Z[1 + nblf];
{ nudslf[0] = 0;
const TopoDS_Wire& W = TopoDS::Wire(exp.Current()); int iw = 1;
if (!OW1.IsSame(W)) int nbpnt = 0;
const TopoDS_Wire OW1 = BRepTools::OuterWire(F);
nbpnt += NumberOfPoints(aMesh, OW1);
nudslf[iw++] = nbpnt;
//SCRUTE(nbpnt);
for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next())
{ {
nbpnt += NumberOfPoints (aMesh, W); const TopoDS_Wire & W = TopoDS::Wire(exp.Current());
nudslf [iw++] = nbpnt; if (!OW1.IsSame(W))
//SCRUTE(nbpnt); {
nbpnt += NumberOfPoints(aMesh, W);
nudslf[iw++] = nbpnt;
//SCRUTE(nbpnt);
}
} }
}
uvslf = new R2[nudslf[nblf]]; uvslf = new R2[nudslf[nblf]];
//SCRUTE(nudslf[nblf]); //SCRUTE(nudslf[nblf]);
int m = 0; int m = 0;
map<int,int> mefistoToDS; // correspondence mefisto index--> points IDNodes map < int, int >mefistoToDS; // correspondence mefisto index--> points IDNodes
TopoDS_Wire OW = BRepTools::OuterWire(F); TopoDS_Wire OW = BRepTools::OuterWire(F);
LoadPoints (aMesh, F, OW, uvslf, m, mefistoToDS); LoadPoints(aMesh, F, OW, uvslf, m, mefistoToDS);
//SCRUTE(m); //SCRUTE(m);
for (TopExp_Explorer exp (F, TopAbs_WIRE); exp.More(); exp.Next()) for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next())
{
const TopoDS_Wire& W = TopoDS::Wire(exp.Current());
if (!OW.IsSame(W))
{ {
LoadPoints (aMesh, F, W, uvslf, m, mefistoToDS); const TopoDS_Wire & W = TopoDS::Wire(exp.Current());
//SCRUTE(m); if (!OW.IsSame(W))
{
LoadPoints(aMesh, F, W, uvslf, m, mefistoToDS);
//SCRUTE(m);
}
} }
}
// SCRUTE(nudslf[nblf]); // SCRUTE(nudslf[nblf]);
// for (int i=0; i<=nblf; i++) // for (int i=0; i<=nblf; i++)
// { // {
@ -257,34 +252,35 @@ bool SMESH_MEFISTO_2D::Compute(SMESH_Mesh& aMesh,
// SCRUTE(aretmx); // SCRUTE(aretmx);
// SCRUTE(nblf); // SCRUTE(nblf);
MESSAGE("MEFISTO triangulation ..."); MESSAGE("MEFISTO triangulation ...");
uvst = NULL; uvst = NULL;
nust = NULL; nust = NULL;
aptrte( nutysu, aretmx, aptrte(nutysu, aretmx,
nblf, nudslf, uvslf, nblf, nudslf, uvslf, nbpti, uvpti, nbst, uvst, nbt, nust, ierr);
nbpti, uvpti,
nbst, uvst, nbt, nust,
ierr );
if( ierr == 0 ) if (ierr == 0)
{ {
MESSAGE("... End Triangulation"); MESSAGE("... End Triangulation");
//SCRUTE(nbst); //SCRUTE(nbst);
//SCRUTE(nbt); //SCRUTE(nbt);
StoreResult (aMesh, nbst, uvst, nbt, nust, F, StoreResult(aMesh, nbst, uvst, nbt, nust, F,
faceIsForward, mefistoToDS); faceIsForward, mefistoToDS);
isOk = true; isOk = true;
} }
else else
{ {
MESSAGE("Error in Triangulation"); MESSAGE("Error in Triangulation");
isOk = false; isOk = false;
} }
if (nudslf != NULL) delete [] nudslf; if (nudslf != NULL)
if (uvslf != NULL) delete [] uvslf; delete[]nudslf;
if (uvst != NULL) delete [] uvst; if (uvslf != NULL)
if (nust != NULL) delete [] nust; delete[]uvslf;
return isOk; if (uvst != NULL)
delete[]uvst;
if (nust != NULL)
delete[]nust;
return isOk;
} }
//============================================================================= //=============================================================================
@ -293,125 +289,118 @@ bool SMESH_MEFISTO_2D::Compute(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
void SMESH_MEFISTO_2D::LoadPoints(SMESH_Mesh& aMesh, void SMESH_MEFISTO_2D::LoadPoints(SMESH_Mesh & aMesh,
const TopoDS_Face& FF, const TopoDS_Face & FF,
const TopoDS_Wire& WW, const TopoDS_Wire & WW, R2 * uvslf, int &m, map < int, int >&mefistoToDS)
R2* uvslf,
int& m,
map<int,int>& mefistoToDS)
{ {
MESSAGE("SMESH_MEFISTO_2D::LoadPoints"); MESSAGE("SMESH_MEFISTO_2D::LoadPoints");
Handle (SMDS_Mesh) meshDS = aMesh.GetMeshDS(); SMDS_Mesh * meshDS = aMesh.GetMeshDS();
double scalex; double scalex;
double scaley; double scaley;
TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD));
ComputeScaleOnFace(aMesh, F, scalex, scaley); ComputeScaleOnFace(aMesh, F, scalex, scaley);
TopoDS_Wire W = TopoDS::Wire(WW.Oriented(TopAbs_FORWARD)); TopoDS_Wire W = TopoDS::Wire(WW.Oriented(TopAbs_FORWARD));
BRepTools_WireExplorer wexp(W,F); BRepTools_WireExplorer wexp(W, F);
for (wexp.Init(W,F);wexp.More(); wexp.Next()) for (wexp.Init(W, F); wexp.More(); wexp.Next())
{ {
const TopoDS_Edge& E = wexp.Current(); const TopoDS_Edge & E = wexp.Current();
// --- IDNodes of first and last Vertex // --- IDNodes of first and last Vertex
TopoDS_Vertex VFirst, VLast; TopoDS_Vertex VFirst, VLast;
TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
ASSERT(!VFirst.IsNull()); ASSERT(!VFirst.IsNull());
SMESH_subMesh* firstSubMesh = aMesh.GetSubMesh(VFirst); SMESH_subMesh *firstSubMesh = aMesh.GetSubMesh(VFirst);
const TColStd_ListOfInteger& lidf const vector<int> & lidf
= firstSubMesh->GetSubMeshDS()->GetIDNodes(); = firstSubMesh->GetSubMeshDS()->GetIDNodes();
int idFirst= lidf.First(); int idFirst = lidf[0];
// SCRUTE(idFirst); // SCRUTE(idFirst);
ASSERT(!VLast.IsNull()); ASSERT(!VLast.IsNull());
SMESH_subMesh* lastSubMesh = aMesh.GetSubMesh(VLast); SMESH_subMesh *lastSubMesh = aMesh.GetSubMesh(VLast);
const TColStd_ListOfInteger& lidl const vector<int> & lidl
= lastSubMesh->GetSubMeshDS()->GetIDNodes(); = lastSubMesh->GetSubMeshDS()->GetIDNodes();
int idLast= lidl.First(); int idLast = lidl[0];
// SCRUTE(idLast); // SCRUTE(idLast);
// --- edge internal IDNodes (relies on good order storage, not checked) // --- edge internal IDNodes (relies on good order storage, not checked)
int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
//SCRUTE(nbPoints); //SCRUTE(nbPoints);
Standard_Real f,l;
Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
const TColStd_ListOfInteger& indElt
= aMesh.GetSubMesh(E)->GetSubMeshDS()->GetIDNodes();
TColStd_ListIteratorOfListOfInteger ite(indElt);
//SCRUTE(nbPoints);
//SCRUTE(indElt.Extent());
ASSERT(nbPoints == indElt.Extent());
bool isForward = (E.Orientation() == TopAbs_FORWARD);
map<double,int> params;
for (; ite.More(); ite.Next())
{
int nodeId = ite.Value();
Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
Handle (SMDS_EdgePosition) epos
= Handle (SMDS_EdgePosition)::DownCast(node->GetPosition());
double param = epos->GetUParameter();
params[param] = nodeId;
// MESSAGE(" " << param << " " << params[param]);
}
// --- load 2D values into MEFISTO structure, double f, l;
// add IDNodes in mefistoToDS map Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
if (E.Orientation() == TopAbs_FORWARD) const vector<int> & indElt
{ = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetIDNodes();
gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
uvslf [m].x = scalex * p.X(); ASSERT(nbPoints == indElt.size());
uvslf [m].y = scaley * p.Y(); bool isForward = (E.Orientation() == TopAbs_FORWARD);
mefistoToDS[m+1] = idFirst; map < double, int >params;
//MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]); for (int ite=0; ite<indElt.size(); ite++)
//MESSAGE("__ f "<<f<<" "<<uvslf[m].x <<" "<<uvslf[m].y); {
m++; int nodeId = indElt[ite];
map<double,int>::iterator itp = params.begin(); const SMDS_MeshNode * node = meshDS->FindNode(nodeId);
for (Standard_Integer i = 1; i<=nbPoints; i++) // nbPoints internal const SMDS_EdgePosition* epos
{ = static_cast<const SMDS_EdgePosition*>(node->GetPosition());
double param = (*itp).first; double param = epos->GetUParameter();
gp_Pnt2d p = C2d->Value(param); params[param] = nodeId;
uvslf [m].x = scalex * p.X(); }
uvslf [m].y = scaley * p.Y();
mefistoToDS[m+1] = (*itp).second; // --- load 2D values into MEFISTO structure,
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]); // add IDNodes in mefistoToDS map
// MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++; if (E.Orientation() == TopAbs_FORWARD)
itp++; {
} gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
uvslf[m].x = scalex * p.X();
uvslf[m].y = scaley * p.Y();
mefistoToDS[m + 1] = idFirst;
//MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
//MESSAGE("__ f "<<f<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
map < double, int >::iterator itp = params.begin();
for (int i = 1; i <= nbPoints; i++) // nbPoints internal
{
double param = (*itp).first;
gp_Pnt2d p = C2d->Value(param);
uvslf[m].x = scalex * p.X();
uvslf[m].y = scaley * p.Y();
mefistoToDS[m + 1] = (*itp).second;
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
// MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
itp++;
}
}
else
{
gp_Pnt2d p = C2d->Value(l); // last point = Vertex Reversed
uvslf[m].x = scalex * p.X();
uvslf[m].y = scaley * p.Y();
mefistoToDS[m + 1] = idLast;
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
// MESSAGE("__ l "<<l<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
map < double, int >::reverse_iterator itp = params.rbegin();
for (int i = nbPoints; i >= 1; i--)
{
double param = (*itp).first;
gp_Pnt2d p = C2d->Value(param);
uvslf[m].x = scalex * p.X();
uvslf[m].y = scaley * p.Y();
mefistoToDS[m + 1] = (*itp).second;
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
// MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
itp++;
}
}
} }
else
{
gp_Pnt2d p = C2d->Value(l); // last point = Vertex Reversed
uvslf [m].x = scalex * p.X();
uvslf [m].y = scaley * p.Y();
mefistoToDS[m+1] = idLast;
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
// MESSAGE("__ l "<<l<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
map<double,int>::reverse_iterator itp = params.rbegin();
for (Standard_Integer i = nbPoints ; i >= 1; i--)
{
double param = (*itp).first;
gp_Pnt2d p = C2d->Value(param);
uvslf [m].x = scalex * p.X();
uvslf [m].y = scaley * p.Y();
mefistoToDS[m+1] = (*itp).second;
// MESSAGE(" "<<m<<" "<<mefistoToDS[m+1]);
// MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[m].x <<" "<<uvslf[m].y);
m++;
itp++;
}
}
}
} }
//============================================================================= //=============================================================================
@ -422,72 +411,74 @@ void SMESH_MEFISTO_2D::LoadPoints(SMESH_Mesh& aMesh,
// **** a mettre dans SMESH_Algo ou SMESH_2D_Algo // **** a mettre dans SMESH_Algo ou SMESH_2D_Algo
void SMESH_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh& aMesh, void SMESH_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh,
const TopoDS_Face& aFace, const TopoDS_Face & aFace, double &scalex, double &scaley)
double& scalex,
double& scaley)
{ {
//MESSAGE("SMESH_MEFISTO_2D::ComputeScaleOnFace"); //MESSAGE("SMESH_MEFISTO_2D::ComputeScaleOnFace");
TopoDS_Face F = TopoDS::Face(aFace.Oriented(TopAbs_FORWARD)); TopoDS_Face F = TopoDS::Face(aFace.Oriented(TopAbs_FORWARD));
TopoDS_Wire W = BRepTools::OuterWire(F); TopoDS_Wire W = BRepTools::OuterWire(F);
BRepTools_WireExplorer wexp(W,F); BRepTools_WireExplorer wexp(W, F);
double xmin = 1.e300; // min & max of face 2D parametric coord. double xmin = 1.e300; // min & max of face 2D parametric coord.
double xmax = -1.e300; double xmax = -1.e300;
double ymin = 1.e300; double ymin = 1.e300;
double ymax = -1.e300; double ymax = -1.e300;
int nbp = 50; int nbp = 50;
scalex = 1; scalex = 1;
scaley = 1; scaley = 1;
for (wexp.Init(W,F);wexp.More(); wexp.Next()) for (wexp.Init(W, F); wexp.More(); wexp.Next())
{
const TopoDS_Edge& E = wexp.Current();
double f,l;
Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
for (int i = 0; i<= nbp; i++)
{ {
double param = f + (double(i)/double(nbp))*(l-f); const TopoDS_Edge & E = wexp.Current();
gp_Pnt2d p = C2d->Value(param); double f, l;
if (p.X() < xmin) xmin = p.X(); Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
if (p.X() > xmax) xmax = p.X(); for (int i = 0; i <= nbp; i++)
if (p.Y() < ymin) ymin = p.Y(); {
if (p.Y() > ymax) ymax = p.Y(); double param = f + (double (i) / double (nbp))*(l - f);
// MESSAGE(" "<< f<<" "<<l<<" "<<param<<" "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax); gp_Pnt2d p = C2d->Value(param);
if (p.X() < xmin)
xmin = p.X();
if (p.X() > xmax)
xmax = p.X();
if (p.Y() < ymin)
ymin = p.Y();
if (p.Y() > ymax)
ymax = p.Y();
// MESSAGE(" "<< f<<" "<<l<<" "<<param<<" "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax);
}
} }
}
// SCRUTE(xmin); // SCRUTE(xmin);
// SCRUTE(xmax); // SCRUTE(xmax);
// SCRUTE(ymin); // SCRUTE(ymin);
// SCRUTE(ymax); // SCRUTE(ymax);
double xmoy = (xmax + xmin)/2.; double xmoy = (xmax + xmin) / 2.;
double ymoy = (ymax + ymin)/2.; double ymoy = (ymax + ymin) / 2.;
Handle(Geom_Surface) S = BRep_Tool::Surface(F); // 3D surface Handle(Geom_Surface) S = BRep_Tool::Surface(F); // 3D surface
double length_x = 0; double length_x = 0;
double length_y = 0; double length_y = 0;
gp_Pnt PX0 = S->Value(xmin, ymoy); gp_Pnt PX0 = S->Value(xmin, ymoy);
gp_Pnt PY0 = S->Value(xmoy, ymin); gp_Pnt PY0 = S->Value(xmoy, ymin);
for (Standard_Integer i = 1; i<= nbp; i++) for (int i = 1; i <= nbp; i++)
{ {
double x = xmin + (double(i)/double(nbp))*(xmax-xmin); double x = xmin + (double (i) / double (nbp))*(xmax - xmin);
gp_Pnt PX = S->Value(x,ymoy); gp_Pnt PX = S->Value(x, ymoy);
double y = ymin + (double(i)/double(nbp))*(ymax-ymin); double y = ymin + (double (i) / double (nbp))*(ymax - ymin);
gp_Pnt PY = S->Value(xmoy,y); gp_Pnt PY = S->Value(xmoy, y);
length_x += PX.Distance(PX0); length_x += PX.Distance(PX0);
length_y += PY.Distance(PY0); length_y += PY.Distance(PY0);
PX0.SetCoord(PX.X(),PX.Y(),PX.Z()); PX0.SetCoord(PX.X(), PX.Y(), PX.Z());
PY0.SetCoord(PY.X(),PY.Y(),PY.Z()); PY0.SetCoord(PY.X(), PY.Y(), PY.Z());
} }
// SCRUTE(length_x); // SCRUTE(length_x);
// SCRUTE(length_y); // SCRUTE(length_y);
scalex = length_x/(xmax - xmin); scalex = length_x / (xmax - xmin);
scaley = length_y/(ymax - ymin); scaley = length_y / (ymax - ymin);
// SCRUTE(scalex); // SCRUTE(scalex);
// SCRUTE(scaley); // SCRUTE(scaley);
ASSERT(scalex); ASSERT(scalex);
ASSERT(scaley); ASSERT(scaley);
} }
//============================================================================= //=============================================================================
@ -496,75 +487,69 @@ void SMESH_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
void SMESH_MEFISTO_2D::StoreResult (SMESH_Mesh& aMesh, void SMESH_MEFISTO_2D::StoreResult(SMESH_Mesh & aMesh,
Z nbst, R2* uvst, Z nbt, Z* nust, Z nbst, R2 * uvst, Z nbt, Z * nust,
const TopoDS_Face& F, bool faceIsForward, const TopoDS_Face & F, bool faceIsForward, map < int, int >&mefistoToDS)
map<int,int>& mefistoToDS)
{ {
double scalex; double scalex;
double scaley; double scaley;
ComputeScaleOnFace(aMesh, F, scalex, scaley); ComputeScaleOnFace(aMesh, F, scalex, scaley);
Handle (SMESHDS_Mesh) meshDS = aMesh.GetMeshDS(); SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
Z n,m; Z n, m;
Handle(Geom_Surface) S = BRep_Tool::Surface(F); Handle(Geom_Surface) S = BRep_Tool::Surface(F);
for ( n=0; n<nbst; n++ ) for (n = 0; n < nbst; n++)
{
double u = uvst[n][0]/scalex;
double v = uvst[n][1]/scaley;
gp_Pnt P = S->Value(u,v);
if (mefistoToDS.find(n+1) == mefistoToDS.end())
{ {
int nodeId = meshDS->AddNode(P.X(), P.Y(), P.Z()); double u = uvst[n][0] / scalex;
Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId); double v = uvst[n][1] / scaley;
Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt); gp_Pnt P = S->Value(u, v);
meshDS->SetNodeOnFace(node, F);
//MESSAGE(nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z());
mefistoToDS[n+1] = nodeId;
//MESSAGE(" "<<n<<" "<<mefistoToDS[n+1]);
Handle (SMDS_FacePosition) fpos
= Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
fpos->SetUParameter(u);
fpos->SetVParameter(v);
}
}
m=0;
int mt=0;
//SCRUTE(faceIsForward); if (mefistoToDS.find(n + 1) == mefistoToDS.end())
for ( n=1; n<=nbt; n++ ) {
{ SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
int inode1 = nust[m++]; meshDS->SetNodeOnFace(node, F);
int inode2 = nust[m++];
int inode3 = nust[m++];
int nodeId1 = mefistoToDS[inode1]; //MESSAGE(nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z());
int nodeId2 = mefistoToDS[inode2]; mefistoToDS[n + 1] = node->GetID();
int nodeId3 = mefistoToDS[inode3]; //MESSAGE(" "<<n<<" "<<mefistoToDS[n+1]);
//MESSAGE("-- "<<inode1<<" "<<inode2<<" "<<inode3<<" ++ "<<nodeId1<<" "<<nodeId2<<" "<<nodeId3); SMDS_FacePosition* fpos
= static_cast<SMDS_FacePosition*>(node->GetPosition());
// triangle points must be in trigonometric order if face is Forward fpos->SetUParameter(u);
// else they must be put clockwise fpos->SetVParameter(v);
}
bool triangleIsWellOriented = faceIsForward;
int faceId;
if (triangleIsWellOriented)
{
faceId = meshDS->AddFace(nodeId1, nodeId2, nodeId3);
} }
else
m = 0;
int mt = 0;
//SCRUTE(faceIsForward);
for (n = 1; n <= nbt; n++)
{ {
faceId = meshDS->AddFace(nodeId1, nodeId3, nodeId2); int inode1 = nust[m++];
int inode2 = nust[m++];
int inode3 = nust[m++];
int nodeId1 = mefistoToDS[inode1];
int nodeId2 = mefistoToDS[inode2];
int nodeId3 = mefistoToDS[inode3];
//MESSAGE("-- "<<inode1<<" "<<inode2<<" "<<inode3<<" ++ "<<nodeId1<<" "<<nodeId2<<" "<<nodeId3);
// triangle points must be in trigonometric order if face is Forward
// else they must be put clockwise
bool triangleIsWellOriented = faceIsForward;
SMDS_MeshElement * elt;
if (triangleIsWellOriented)
elt = meshDS->AddFace(nodeId1, nodeId2, nodeId3);
else
elt = meshDS->AddFace(nodeId1, nodeId3, nodeId2);
meshDS->SetMeshElementOnShape(elt, F);
m++;
} }
Handle (SMDS_MeshElement) elt = meshDS->FindElement(faceId);
meshDS->SetMeshElementOnShape(elt, F);
m++;
}
} }
//============================================================================= //=============================================================================
@ -573,35 +558,35 @@ void SMESH_MEFISTO_2D::StoreResult (SMESH_Mesh& aMesh,
*/ */
//============================================================================= //=============================================================================
double SMESH_MEFISTO_2D::ComputeEdgeElementLength(SMESH_Mesh& aMesh, double SMESH_MEFISTO_2D::ComputeEdgeElementLength(SMESH_Mesh & aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape & aShape)
{ {
MESSAGE("SMESH_MEFISTO_2D::ComputeEdgeElementLength"); MESSAGE("SMESH_MEFISTO_2D::ComputeEdgeElementLength");
// **** a mettre dans SMESH_2D_Algo ? // **** a mettre dans SMESH_2D_Algo ?
const TopoDS_Face& FF = TopoDS::Face(aShape); const TopoDS_Face & FF = TopoDS::Face(aShape);
bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD); bool faceIsForward = (FF.Orientation() == TopAbs_FORWARD);
TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD));
double meanElementLength = 100; double meanElementLength = 100;
double wireLength =0; double wireLength = 0;
int wireElementsNumber =0; int wireElementsNumber = 0;
for (TopExp_Explorer exp (F, TopAbs_WIRE); exp.More(); exp.Next()) for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next())
{
const TopoDS_Wire& W = TopoDS::Wire(exp.Current());
for (TopExp_Explorer expe(W,TopAbs_EDGE); expe.More(); expe.Next())
{ {
const TopoDS_Edge& E = TopoDS::Edge(expe.Current()); const TopoDS_Wire & W = TopoDS::Wire(exp.Current());
int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); for (TopExp_Explorer expe(W, TopAbs_EDGE); expe.More(); expe.Next())
double length = EdgeLength(E); {
wireLength += length; const TopoDS_Edge & E = TopoDS::Edge(expe.Current());
wireElementsNumber += nb; int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
double length = EdgeLength(E);
wireLength += length;
wireElementsNumber += nb;
}
} }
} if (wireElementsNumber)
if (wireElementsNumber) meanElementLength = wireLength / wireElementsNumber;
meanElementLength = wireLength/wireElementsNumber; //SCRUTE(meanElementLength);
//SCRUTE(meanElementLength); return meanElementLength;
return meanElementLength;
} }
//============================================================================= //=============================================================================
@ -612,7 +597,7 @@ double SMESH_MEFISTO_2D::ComputeEdgeElementLength(SMESH_Mesh& aMesh,
ostream & SMESH_MEFISTO_2D::SaveTo(ostream & save) ostream & SMESH_MEFISTO_2D::SaveTo(ostream & save)
{ {
return save << this; return save << this;
} }
//============================================================================= //=============================================================================
@ -623,7 +608,7 @@ ostream & SMESH_MEFISTO_2D::SaveTo(ostream & save)
istream & SMESH_MEFISTO_2D::LoadFrom(istream & load) istream & SMESH_MEFISTO_2D::LoadFrom(istream & load)
{ {
return load >> (*this); return load >> (*this);
} }
//============================================================================= //=============================================================================
@ -632,9 +617,9 @@ istream & SMESH_MEFISTO_2D::LoadFrom(istream & load)
*/ */
//============================================================================= //=============================================================================
ostream & operator << (ostream & save, SMESH_MEFISTO_2D & hyp) ostream & operator <<(ostream & save, SMESH_MEFISTO_2D & hyp)
{ {
return save; return save;
} }
//============================================================================= //=============================================================================
@ -643,8 +628,7 @@ ostream & operator << (ostream & save, SMESH_MEFISTO_2D & hyp)
*/ */
//============================================================================= //=============================================================================
istream & operator >> (istream & load, SMESH_MEFISTO_2D & hyp) istream & operator >>(istream & load, SMESH_MEFISTO_2D & hyp)
{ {
return load; return load;
} }

View File

@ -32,25 +32,23 @@
#include "SMESH_Hypothesis.hxx" #include "SMESH_Hypothesis.hxx"
#include "Utils_SALOME_Exception.hxx" #include "Utils_SALOME_Exception.hxx"
class SMESH_MaxElementArea: class SMESH_MaxElementArea:public SMESH_Hypothesis
public SMESH_Hypothesis
{ {
public: public:
SMESH_MaxElementArea(int hypId, int studyId, SMESH_Gen* gen); SMESH_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen);
virtual ~SMESH_MaxElementArea(); virtual ~ SMESH_MaxElementArea();
void SetMaxArea(double maxArea) void SetMaxArea(double maxArea) throw(SALOME_Exception);
throw (SALOME_Exception);
double GetMaxArea(); double GetMaxArea() const;
virtual ostream & SaveTo(ostream & save); virtual ostream & SaveTo(ostream & save);
virtual istream & LoadFrom(istream & load); virtual istream & LoadFrom(istream & load);
friend ostream & operator << (ostream & save, SMESH_MaxElementArea & hyp); friend ostream & operator <<(ostream & save, SMESH_MaxElementArea & hyp);
friend istream & operator >> (istream & load, SMESH_MaxElementArea & hyp); friend istream & operator >>(istream & load, SMESH_MaxElementArea & hyp);
protected: protected:
double _maxArea; double _maxArea;
}; };
#endif #endif

View File

@ -26,21 +26,12 @@
// Module : SMESH // Module : SMESH
// $Header$ // $Header$
using namespace std;
using namespace std;
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_subMesh.hxx" #include "SMESH_subMesh.hxx"
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_Hypothesis.hxx" #include "SMESH_Hypothesis.hxx"
#include "SMESHDS_Script.hxx" #include "SMESHDS_Script.hxx"
//#include "SMESHDS_ListOfAsciiString.hxx" #include "SMDS_MeshVolume.hxx"
//#include "SMESHDS_ListIteratorOfListOfAsciiString.hxx"
#include "SMESHDS_ListOfPtrHypothesis.hxx"
#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
#include "SMDS_MeshElement.hxx"
#include "SMDS_MeshFacesIterator.hxx"
#include "SMDS_MeshVolumesIterator.hxx"
#include "TCollection_AsciiString.hxx"
#include "utilities.h" #include "utilities.h"
@ -49,6 +40,8 @@ using namespace std;
#include "DriverDAT_W_SMESHDS_Mesh.h" #include "DriverDAT_W_SMESHDS_Mesh.h"
#include "DriverUNV_W_SMESHDS_Mesh.h" #include "DriverUNV_W_SMESHDS_Mesh.h"
#include <TCollection_AsciiString.hxx>
//============================================================================= //=============================================================================
/*! /*!
* *
@ -57,9 +50,9 @@ using namespace std;
SMESH_Mesh::SMESH_Mesh() SMESH_Mesh::SMESH_Mesh()
{ {
MESSAGE("SMESH_Mesh::SMESH_Mesh"); MESSAGE("SMESH_Mesh::SMESH_Mesh");
_id = -1; _id = -1;
ASSERT(0); ASSERT(0);
} }
//============================================================================= //=============================================================================
@ -69,18 +62,16 @@ SMESH_Mesh::SMESH_Mesh()
//============================================================================= //=============================================================================
SMESH_Mesh::SMESH_Mesh(int localId, SMESH_Mesh::SMESH_Mesh(int localId,
int studyId, int studyId, SMESH_Gen * gen, SMESHDS_Document * myDocument)
SMESH_Gen* gen,
const Handle(SMESHDS_Document)& myDocument)
{ {
MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)"); MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
_id = localId; _id = localId;
_studyId = studyId; _studyId = studyId;
_gen = gen; _gen = gen;
_myDocument = myDocument; _myDocument = myDocument;
_idDoc = _myDocument->NewMesh(); _idDoc = _myDocument->NewMesh();
_myMeshDS = _myDocument->GetMesh(_idDoc); _myMeshDS = _myDocument->GetMesh(_idDoc);
_isShapeToMesh = false; _isShapeToMesh = false;
} }
//============================================================================= //=============================================================================
@ -91,7 +82,7 @@ SMESH_Mesh::SMESH_Mesh(int localId,
SMESH_Mesh::~SMESH_Mesh() SMESH_Mesh::~SMESH_Mesh()
{ {
MESSAGE("SMESH_Mesh::~SMESH_Mesh"); MESSAGE("SMESH_Mesh::~SMESH_Mesh");
} }
//============================================================================= //=============================================================================
@ -100,17 +91,19 @@ SMESH_Mesh::~SMESH_Mesh()
*/ */
//============================================================================= //=============================================================================
void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape& aShape) void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::ShapeToMesh"); MESSAGE("SMESH_Mesh::ShapeToMesh");
if (_isShapeToMesh) if (_isShapeToMesh)
throw SALOME_Exception(LOCALIZED("a shape to mesh as already been defined")); throw
_isShapeToMesh = true; SALOME_Exception(LOCALIZED
_myMeshDS->ShapeToMesh(aShape); ("a shape to mesh as already been defined"));
_isShapeToMesh = true;
_myMeshDS->ShapeToMesh(aShape);
// NRI : 24/02/03 // NRI : 24/02/03
TopExp::MapShapes(aShape,_subShapes); TopExp::MapShapes(aShape, _subShapes);
} }
//============================================================================= //=============================================================================
@ -119,47 +112,46 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape& aShape)
*/ */
//============================================================================= //=============================================================================
bool SMESH_Mesh::AddHypothesis(const TopoDS_Shape& aSubShape, bool SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
int anHypId) int anHypId) throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::AddHypothesis"); MESSAGE("SMESH_Mesh::AddHypothesis");
StudyContextStruct* sc = _gen->GetStudyContext(_studyId); StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end()) if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
{ {
MESSAGE("Hypothesis ID does not give an hypothesis"); MESSAGE("Hypothesis ID does not give an hypothesis");
SCRUTE(_studyId); SCRUTE(_studyId);
SCRUTE(anHypId); SCRUTE(anHypId);
throw SALOME_Exception(LOCALIZED("hypothesis does not exist")); throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
} }
SMESH_subMesh* subMesh = GetSubMesh(aSubShape); SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
SMESH_Hypothesis* anHyp = sc->mapHypothesis[anHypId]; SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
int event; int event;
// shape // shape
if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
event = SMESH_subMesh::ADD_HYP; event = SMESH_subMesh::ADD_HYP;
else else
event = SMESH_subMesh::ADD_ALGO; event = SMESH_subMesh::ADD_ALGO;
int ret = subMesh->AlgoStateEngine(event, anHyp); int ret = subMesh->AlgoStateEngine(event, anHyp);
// subShapes (only when shape is mainShape) // subShapes (only when shape is mainShape)
TopoDS_Shape mainShape = _myMeshDS->ShapeToMesh(); TopoDS_Shape mainShape = _myMeshDS->ShapeToMesh();
if (aSubShape.IsSame(mainShape)) if (aSubShape.IsSame(mainShape))
{ {
if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
event = SMESH_subMesh::ADD_FATHER_HYP; event = SMESH_subMesh::ADD_FATHER_HYP;
else else
event = SMESH_subMesh::ADD_FATHER_ALGO; event = SMESH_subMesh::ADD_FATHER_ALGO;
subMesh->SubMeshesAlgoStateEngine(event, anHyp); subMesh->SubMeshesAlgoStateEngine(event, anHyp);
} }
subMesh->DumpAlgoState(true); subMesh->DumpAlgoState(true);
//SCRUTE(ret); //SCRUTE(ret);
return ret; return ret;
} }
//============================================================================= //=============================================================================
@ -168,45 +160,44 @@ bool SMESH_Mesh::AddHypothesis(const TopoDS_Shape& aSubShape,
*/ */
//============================================================================= //=============================================================================
bool SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape& aSubShape, bool SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
int anHypId) int anHypId)throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::RemoveHypothesis"); MESSAGE("SMESH_Mesh::RemoveHypothesis");
StudyContextStruct* sc = _gen->GetStudyContext(_studyId); StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end()) if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
throw SALOME_Exception(LOCALIZED("hypothesis does not exist")); throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
SMESH_subMesh* subMesh = GetSubMesh(aSubShape); SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
SMESH_Hypothesis* anHyp = sc->mapHypothesis[anHypId]; SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
int hypType = anHyp->GetType(); int hypType = anHyp->GetType();
SCRUTE(hypType); SCRUTE(hypType);
int event; int event;
// shape // shape
if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
event = SMESH_subMesh::REMOVE_HYP; event = SMESH_subMesh::REMOVE_HYP;
else else
event = SMESH_subMesh::REMOVE_ALGO; event = SMESH_subMesh::REMOVE_ALGO;
int ret = subMesh->AlgoStateEngine(event, anHyp); int ret = subMesh->AlgoStateEngine(event, anHyp);
// subShapes (only when shape is mainShape) // subShapes (only when shape is mainShape)
TopoDS_Shape mainShape = _myMeshDS->ShapeToMesh(); TopoDS_Shape mainShape = _myMeshDS->ShapeToMesh();
if (aSubShape.IsSame(mainShape)) if (aSubShape.IsSame(mainShape))
{ {
if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
event = SMESH_subMesh::REMOVE_FATHER_HYP; event = SMESH_subMesh::REMOVE_FATHER_HYP;
else else
event = SMESH_subMesh::REMOVE_FATHER_ALGO; event = SMESH_subMesh::REMOVE_FATHER_ALGO;
subMesh->SubMeshesAlgoStateEngine(event, anHyp); subMesh->SubMeshesAlgoStateEngine(event, anHyp);
} }
subMesh->DumpAlgoState(true); subMesh->DumpAlgoState(true);
SCRUTE(ret); SCRUTE(ret);
return ret; return ret;
} }
//============================================================================= //=============================================================================
@ -215,34 +206,9 @@ bool SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape& aSubShape,
*/ */
//============================================================================= //=============================================================================
const Handle(SMESHDS_Mesh)& SMESH_Mesh::GetMeshDS() SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
{ {
return _myMeshDS; return _myMeshDS;
}
//=============================================================================
/*!
*
*/
//=============================================================================
const list<SMESHDS_Hypothesis*>&
SMESH_Mesh::GetHypothesisList(const TopoDS_Shape& aSubShape)
throw (SALOME_Exception)
{
MESSAGE("SMESH_Mesh::GetHypothesisList");
_subShapeHypothesisList.clear();
const SMESHDS_ListOfPtrHypothesis& listHyp
= _myMeshDS->GetHypothesis(aSubShape);
SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp);
while (it.More())
{
SMESHDS_Hypothesis* anHyp = it.Value();
_subShapeHypothesisList.push_back(anHyp);
it.Next();
}
return _subShapeHypothesisList;
} }
//============================================================================= //=============================================================================
@ -251,20 +217,23 @@ SMESH_Mesh::GetHypothesisList(const TopoDS_Shape& aSubShape)
*/ */
//============================================================================= //=============================================================================
const SMESHDS_ListOfCommand& SMESH_Mesh::GetLog() const list<const SMESHDS_Hypothesis*>&
throw (SALOME_Exception) SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape)
throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::GetLog"); MESSAGE("SMESH_Mesh::GetHypothesisList");
Handle (SMESHDS_Script) scriptDS = _myMeshDS->GetScript(); _subShapeHypothesisList.clear();
const SMESHDS_ListOfCommand& logDS = scriptDS->GetCommands(); const list<const SMESHDS_Hypothesis*>& listHyp =
// SMESHDS_ListIteratorOfListOfCommand its; _myMeshDS->GetHypothesis(aSubShape);
// const SMESHDS_ListOfAsciiString& logDS = scriptDS->GetCommands();
// SMESHDS_ListIteratorOfListOfAsciiString its; list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
// for (its.Initialize(logDS); its.More(); its.Next()) while (it!=listHyp.end())
// { {
// SCRUTE(its.Value().ToCString()); const SMESHDS_Hypothesis *anHyp = *it;
// } _subShapeHypothesisList.push_back(anHyp);
return logDS; it++;
}
return _subShapeHypothesisList;
} }
//============================================================================= //=============================================================================
@ -272,12 +241,22 @@ const SMESHDS_ListOfCommand& SMESH_Mesh::GetLog()
* *
*/ */
//============================================================================= //=============================================================================
void SMESH_Mesh::ClearLog()
throw (SALOME_Exception) const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::ClearLog"); MESSAGE("SMESH_Mesh::GetLog");
Handle (SMESHDS_Script) scriptDS = _myMeshDS->GetScript(); return _myMeshDS->GetScript()->GetCommands();
scriptDS->Clear(); }
//=============================================================================
/*!
*
*/
//=============================================================================
void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
{
MESSAGE("SMESH_Mesh::ClearLog");
_myMeshDS->GetScript()->Clear();
} }
//============================================================================= //=============================================================================
@ -288,8 +267,8 @@ void SMESH_Mesh::ClearLog()
int SMESH_Mesh::GetId() int SMESH_Mesh::GetId()
{ {
MESSAGE("SMESH_Mesh::GetId"); MESSAGE("SMESH_Mesh::GetId");
return _id; return _id;
} }
//============================================================================= //=============================================================================
@ -298,9 +277,9 @@ int SMESH_Mesh::GetId()
*/ */
//============================================================================= //=============================================================================
SMESH_Gen* SMESH_Mesh::GetGen() SMESH_Gen *SMESH_Mesh::GetGen()
{ {
return _gen; return _gen;
} }
//============================================================================= //=============================================================================
@ -309,37 +288,40 @@ SMESH_Gen* SMESH_Mesh::GetGen()
*/ */
//============================================================================= //=============================================================================
SMESH_subMesh* SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape) SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
//MESSAGE("SMESH_Mesh::GetSubMesh"); //MESSAGE("SMESH_Mesh::GetSubMesh");
SMESH_subMesh* aSubMesh; SMESH_subMesh *aSubMesh;
int index = _subShapes.FindIndex(aSubShape); int index = _subShapes.FindIndex(aSubShape);
if ( _mapSubMesh.find(index) != _mapSubMesh.end() ) { if (_mapSubMesh.find(index) != _mapSubMesh.end())
aSubMesh = _mapSubMesh[index]; {
} else { aSubMesh = _mapSubMesh[index];
aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape); }
_mapSubMesh[index] = aSubMesh; else
} {
aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
_mapSubMesh[index] = aSubMesh;
}
/* NRI 24/02/2003 /* NRI 24/02/2003
int index = -1; * int index = -1;
if (_subShapes.Contains(aSubShape)) * if (_subShapes.Contains(aSubShape))
{ * {
index = _subShapes.FindIndex(aSubShape); * index = _subShapes.FindIndex(aSubShape);
ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end()); * ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end());
aSubMesh = _mapSubMesh[index]; * aSubMesh = _mapSubMesh[index];
//MESSAGE("found submesh " << index); * //MESSAGE("found submesh " << index);
} * }
else * else
{ * {
index = _subShapes.Add(aSubShape); * index = _subShapes.Add(aSubShape);
aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape); * aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
_mapSubMesh[index] = aSubMesh; * _mapSubMesh[index] = aSubMesh;
//MESSAGE("created submesh " << index); * //MESSAGE("created submesh " << index);
} * }
*/ */
return aSubMesh; return aSubMesh;
} }
//============================================================================= //=============================================================================
@ -358,30 +340,31 @@ SMESH_subMesh* SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
// * returns first created submesh of the two. // * returns first created submesh of the two.
// * subMesh is not created, return may be NULL. // * subMesh is not created, return may be NULL.
SMESH_subMesh* SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
//MESSAGE("SMESH_Mesh::GetSubMeshContaining"); //MESSAGE("SMESH_Mesh::GetSubMeshContaining");
bool isFound = false; bool isFound = false;
SMESH_subMesh* aSubMesh = NULL; SMESH_subMesh *aSubMesh = NULL;
int index = _subShapes.FindIndex(aSubShape); int index = _subShapes.FindIndex(aSubShape);
if ( _mapSubMesh.find(index) != _mapSubMesh.end() ) { if (_mapSubMesh.find(index) != _mapSubMesh.end())
aSubMesh = _mapSubMesh[index]; {
isFound = true; aSubMesh = _mapSubMesh[index];
} isFound = true;
}
/* NRI 24/02/2003 /* NRI 24/02/2003
int index = -1; * int index = -1;
if (_subShapes.Contains(aSubShape)) * if (_subShapes.Contains(aSubShape))
{ * {
index = _subShapes.FindIndex(aSubShape); * index = _subShapes.FindIndex(aSubShape);
ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end()); * ASSERT(_mapSubMesh.find(index) != _mapSubMesh.end());
aSubMesh = _mapSubMesh[index]; * aSubMesh = _mapSubMesh[index];
isFound = true; * isFound = true;
//MESSAGE("found submesh " << index); * //MESSAGE("found submesh " << index);
} * }
*/ */
// map<int, SMESH_subMesh*>::iterator itsm; // map<int, SMESH_subMesh*>::iterator itsm;
// for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) // for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
@ -391,8 +374,9 @@ SMESH_subMesh* SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
// if (isFound) break; // if (isFound) break;
// } // }
if (! isFound) aSubMesh = NULL; if (!isFound)
return aSubMesh; aSubMesh = NULL;
return aSubMesh;
} }
//============================================================================= //=============================================================================
@ -401,33 +385,34 @@ SMESH_subMesh* SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
*/ */
//============================================================================= //=============================================================================
const list <SMESH_subMesh*>& const list < SMESH_subMesh * >&
SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis* anHyp) SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
throw (SALOME_Exception) throw(SALOME_Exception)
{ {
MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis"); MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
map<int, SMESH_subMesh*>::iterator itsm; map < int, SMESH_subMesh * >::iterator itsm;
_subMeshesUsingHypothesisList.clear(); _subMeshesUsingHypothesisList.clear();
for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
{
SMESH_subMesh* aSubMesh = (*itsm).second;
bool usesHyp = false;
SMESH_Algo* algo = _gen->GetAlgo(*this, aSubMesh->GetSubShape());
if (algo != NULL)
{ {
const list<SMESHDS_Hypothesis*>& usedHyps SMESH_subMesh *aSubMesh = (*itsm).second;
= algo->GetUsedHypothesis(*this, aSubMesh->GetSubShape()); bool usesHyp = false;
list<SMESHDS_Hypothesis*>::const_iterator itl; SMESH_Algo *algo = _gen->GetAlgo(*this, aSubMesh->GetSubShape());
for(itl=usedHyps.begin(); itl != usedHyps.end(); itl++) if (algo != NULL)
if (anHyp == (*itl)) {
{ const list <const SMESHDS_Hypothesis * >&usedHyps
usesHyp = true; = algo->GetUsedHypothesis(*this, aSubMesh->GetSubShape());
break; list <const SMESHDS_Hypothesis * >::const_iterator itl;
} for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
if (anHyp == (*itl))
{
usesHyp = true;
break;
}
}
if (usesHyp)
_subMeshesUsingHypothesisList.push_back(aSubMesh);
} }
if (usesHyp) _subMeshesUsingHypothesisList.push_back(aSubMesh); return _subMeshesUsingHypothesisList;
}
return _subMeshesUsingHypothesisList;
} }
//============================================================================= //=============================================================================
@ -436,35 +421,31 @@ SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis* anHyp)
*/ */
//============================================================================= //=============================================================================
void SMESH_Mesh::ExportMED( const char* file ) void SMESH_Mesh::ExportMED(const char *file) throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
Mesh_Writer* myWriter = new DriverMED_W_SMESHDS_Mesh; Mesh_Writer *myWriter = new DriverMED_W_SMESHDS_Mesh;
myWriter->SetFile( string(file) ); myWriter->SetFile(string(file));
myWriter->SetMesh( _myMeshDS ); myWriter->SetMesh(_myMeshDS);
MESSAGE ( " _idDoc " << _idDoc ) MESSAGE(" _idDoc " << _idDoc) myWriter->SetMeshId(_idDoc);
myWriter->SetMeshId( _idDoc ); myWriter->Add();
myWriter->Add();
} }
void SMESH_Mesh::ExportDAT( const char* file ) void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
Mesh_Writer* myWriter = new DriverDAT_W_SMESHDS_Mesh; Mesh_Writer *myWriter = new DriverDAT_W_SMESHDS_Mesh;
myWriter->SetFile( string(file) ); myWriter->SetFile(string(file));
myWriter->SetMesh( _myMeshDS ); myWriter->SetMesh(_myMeshDS);
myWriter->SetMeshId( _idDoc ); myWriter->SetMeshId(_idDoc);
myWriter->Add(); myWriter->Add();
} }
void SMESH_Mesh::ExportUNV( const char* file ) void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
Mesh_Writer* myWriter = new DriverUNV_W_SMESHDS_Mesh; Mesh_Writer *myWriter = new DriverUNV_W_SMESHDS_Mesh;
myWriter->SetFile( string(file) ); myWriter->SetFile(string(file));
myWriter->SetMesh( _myMeshDS ); myWriter->SetMesh(_myMeshDS);
myWriter->SetMeshId( _idDoc ); myWriter->SetMeshId(_idDoc);
myWriter->Add(); myWriter->Add();
} }
//============================================================================= //=============================================================================
@ -472,10 +453,9 @@ void SMESH_Mesh::ExportUNV( const char* file )
* *
*/ */
//============================================================================= //=============================================================================
int SMESH_Mesh::NbNodes() int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
return _myMeshDS->NbNodes(); return _myMeshDS->NbNodes();
} }
//============================================================================= //=============================================================================
@ -483,10 +463,9 @@ int SMESH_Mesh::NbNodes()
* *
*/ */
//============================================================================= //=============================================================================
int SMESH_Mesh::NbEdges() int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
return _myMeshDS->NbEdges(); return _myMeshDS->NbEdges();
} }
//============================================================================= //=============================================================================
@ -494,44 +473,35 @@ int SMESH_Mesh::NbEdges()
* *
*/ */
//============================================================================= //=============================================================================
int SMESH_Mesh::NbFaces() int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
return _myMeshDS->NbFaces(); return _myMeshDS->NbFaces();
} }
int SMESH_Mesh::NbTriangles()
throw (SALOME_Exception)
{
SMDS_MeshFacesIterator itFaces(_myMeshDS);
int Nb = 0;
for (;itFaces.More();itFaces.Next()) {
const Handle(SMDS_MeshElement)& elem = itFaces.Value();
switch (elem->NbNodes()) { ///////////////////////////////////////////////////////////////////////////////
case 3 : { /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
Nb++; ///////////////////////////////////////////////////////////////////////////////
break; int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
}
}
}
return Nb;
}
int SMESH_Mesh::NbQuadrangles()
throw (SALOME_Exception)
{ {
SMDS_MeshFacesIterator itFaces(_myMeshDS); int Nb = 0;
int Nb = 0;
for (;itFaces.More();itFaces.Next()) { SMDS_Iterator<const SMDS_MeshFace*> * itFaces=_myMeshDS->facesIterator();
const Handle(SMDS_MeshElement)& elem = itFaces.Value(); while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
delete itFaces;
switch (elem->NbNodes()) { return Nb;
case 4 : { }
Nb++;
break; ///////////////////////////////////////////////////////////////////////////////
} /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
} ///////////////////////////////////////////////////////////////////////////////
} int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
return Nb; {
int Nb = 0;
SMDS_Iterator<const SMDS_MeshFace*> * itFaces=_myMeshDS->facesIterator();
while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
delete itFaces;
return Nb;
} }
//============================================================================= //=============================================================================
@ -539,44 +509,27 @@ int SMESH_Mesh::NbQuadrangles()
* *
*/ */
//============================================================================= //=============================================================================
int SMESH_Mesh::NbVolumes() int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
return _myMeshDS->NbVolumes(); return _myMeshDS->NbVolumes();
} }
int SMESH_Mesh::NbTetras()
throw (SALOME_Exception)
{
int Nb = 0;
SMDS_MeshVolumesIterator itVolumes(_myMeshDS);
for (;itVolumes.More();itVolumes.Next()) {
const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
switch (elem->NbNodes()) { int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
case 4 : { {
Nb++; int Nb = 0;
break; SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=_myMeshDS->volumesIterator();
} while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
} delete itVolumes;
} return Nb;
return Nb;
} }
int SMESH_Mesh::NbHexas()
throw (SALOME_Exception)
{
int Nb = 0;
SMDS_MeshVolumesIterator itVolumes(_myMeshDS);
for (;itVolumes.More();itVolumes.Next()) {
const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
switch (elem->NbNodes()) { int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
case 8 : { {
Nb++; int Nb = 0;
break; SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=_myMeshDS->volumesIterator();
} while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
} delete itVolumes;
} return Nb;
return Nb;
} }
//============================================================================= //=============================================================================
@ -584,8 +537,7 @@ int SMESH_Mesh::NbHexas()
* *
*/ */
//============================================================================= //=============================================================================
int SMESH_Mesh::NbSubMesh() int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
throw (SALOME_Exception)
{ {
return _myMeshDS->NbSubMesh(); return _myMeshDS->NbSubMesh();
} }

View File

@ -31,13 +31,9 @@
#include "SMESHDS_Document.hxx" #include "SMESHDS_Document.hxx"
#include "SMESHDS_Mesh.hxx" #include "SMESHDS_Mesh.hxx"
#include "SMESHDS_Command.hxx"
#include "SMESH_Hypothesis.hxx" #include "SMESH_Hypothesis.hxx"
#include "SMESH_subMesh.hxx" #include "SMESH_subMesh.hxx"
#include "SMESHDS_ListOfCommand.hxx"
//#include "SMESHDS_ListOfAsciiString.hxx"
//#include "SMESHDS_ListIteratorOfListOfAsciiString.hxx"
#include "Utils_SALOME_Exception.hxx" #include "Utils_SALOME_Exception.hxx"
#include <TopExp.hxx> #include <TopExp.hxx>
@ -63,103 +59,83 @@ class SMESH_Gen;
class SMESH_Mesh class SMESH_Mesh
{ {
public: public:
SMESH_Mesh(); SMESH_Mesh();
SMESH_Mesh(int localId, SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen,
int studyId, SMESHDS_Document * myDocument);
SMESH_Gen* gen,
const Handle(SMESHDS_Document)& myDocument);
virtual ~SMESH_Mesh(); virtual ~ SMESH_Mesh();
void ShapeToMesh(const TopoDS_Shape& aShape) void ShapeToMesh(const TopoDS_Shape & aShape) throw(SALOME_Exception);
throw (SALOME_Exception);
bool AddHypothesis(const TopoDS_Shape& aSubShape, bool AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
int anHypId) throw(SALOME_Exception);
throw (SALOME_Exception);
bool RemoveHypothesis(const TopoDS_Shape& aSubShape, bool RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
int anHypId) throw(SALOME_Exception);
throw (SALOME_Exception);
const list<SMESHDS_Hypothesis*>& const list <const SMESHDS_Hypothesis * >&
GetHypothesisList(const TopoDS_Shape& aSubShape) GetHypothesisList(const TopoDS_Shape & aSubShape)
throw (SALOME_Exception); throw(SALOME_Exception);
const SMESHDS_ListOfCommand& GetLog() const list<SMESHDS_Command*> & GetLog() throw(SALOME_Exception);
throw (SALOME_Exception);
// const SMESHDS_ListOfAsciiString& GetLog() // const SMESHDS_ListOfAsciiString& GetLog()
// throw (SALOME_Exception); // throw (SALOME_Exception);
void ClearLog() void ClearLog() throw(SALOME_Exception);
throw (SALOME_Exception);
int GetId(); int GetId();
const Handle(SMESHDS_Mesh)& GetMeshDS();
SMESH_Gen* GetGen(); SMESHDS_Mesh * GetMeshDS();
SMESH_subMesh* GetSubMesh(const TopoDS_Shape & aSubShape) SMESH_Gen *GetGen();
throw (SALOME_Exception);
SMESH_subMesh* GetSubMeshContaining(const TopoDS_Shape & aSubShape) SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape)
throw (SALOME_Exception); throw(SALOME_Exception);
const list <SMESH_subMesh*>& SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape)
GetSubMeshUsingHypothesis(SMESHDS_Hypothesis* anHyp) throw(SALOME_Exception);
throw (SALOME_Exception);
void ExportDAT( const char* file ) const list < SMESH_subMesh * >&
throw (SALOME_Exception); GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
void ExportMED( const char* file ) throw(SALOME_Exception);
throw (SALOME_Exception);
void ExportUNV( const char* file )
throw (SALOME_Exception);
int NbNodes()
throw (SALOME_Exception);
int NbEdges()
throw (SALOME_Exception);
int NbFaces()
throw (SALOME_Exception);
int NbTriangles() void ExportDAT(const char *file) throw(SALOME_Exception);
throw (SALOME_Exception); void ExportMED(const char *file) throw(SALOME_Exception);
void ExportUNV(const char *file) throw(SALOME_Exception);
int NbQuadrangles() int NbNodes() throw(SALOME_Exception);
throw (SALOME_Exception);
int NbVolumes()
throw (SALOME_Exception);
int NbTetras() int NbEdges() throw(SALOME_Exception);
throw (SALOME_Exception);
int NbHexas() int NbFaces() throw(SALOME_Exception);
throw (SALOME_Exception);
int NbSubMesh()
throw (SALOME_Exception);
private: int NbTriangles() throw(SALOME_Exception);
int _id; // id given by creator (unique within the creator instance) int NbQuadrangles() throw(SALOME_Exception);
int _studyId;
int _idDoc; // id given by SMESHDS_Document int NbVolumes() throw(SALOME_Exception);
bool _isShapeToMesh; // set to true when a shape is given (only once)
list<SMESHDS_Hypothesis*> _subShapeHypothesisList; int NbTetras() throw(SALOME_Exception);
list<SMESH_subMesh*> _subMeshesUsingHypothesisList;
Handle (SMESHDS_Document) _myDocument; int NbHexas() throw(SALOME_Exception);
Handle (SMESHDS_Mesh) _myMeshDS;
TopTools_IndexedMapOfShape _subShapes; int NbSubMesh() throw(SALOME_Exception);
map<int, SMESH_subMesh*> _mapSubMesh;
SMESH_Gen* _gen; private:
int _id; // id given by creator (unique within the creator instance)
int _studyId;
int _idDoc; // id given by SMESHDS_Document
bool _isShapeToMesh; // set to true when a shape is given (only once)
list<const SMESHDS_Hypothesis *> _subShapeHypothesisList;
list <SMESH_subMesh *> _subMeshesUsingHypothesisList;
SMESHDS_Document * _myDocument;
SMESHDS_Mesh * _myMeshDS;
TopTools_IndexedMapOfShape _subShapes;
map <int, SMESH_subMesh *>_mapSubMesh;
SMESH_Gen *_gen;
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@
// $Header$ // $Header$
using namespace std; using namespace std;
using namespace std;
#include "SMESH_Regular_1D.hxx" #include "SMESH_Regular_1D.hxx"
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
@ -35,8 +35,6 @@ using namespace std;
#include "SMESH_LocalLength.hxx" #include "SMESH_LocalLength.hxx"
#include "SMESH_NumberOfSegments.hxx" #include "SMESH_NumberOfSegments.hxx"
#include "SMESHDS_ListOfPtrHypothesis.hxx"
#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
#include "SMDS_MeshElement.hxx" #include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
#include "SMDS_EdgePosition.hxx" #include "SMDS_EdgePosition.hxx"
@ -59,20 +57,20 @@ using namespace std;
*/ */
//============================================================================= //=============================================================================
SMESH_Regular_1D::SMESH_Regular_1D(int hypId, int studyId, SMESH_Gen* gen) SMESH_Regular_1D::SMESH_Regular_1D(int hypId, int studyId,
: SMESH_1D_Algo(hypId, studyId, gen) SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen)
{ {
MESSAGE("SMESH_Regular_1D::SMESH_Regular_1D"); MESSAGE("SMESH_Regular_1D::SMESH_Regular_1D");
_name = "Regular_1D"; _name = "Regular_1D";
// _shapeType = TopAbs_EDGE; // _shapeType = TopAbs_EDGE;
_shapeType = (1<<TopAbs_EDGE); _shapeType = (1 << TopAbs_EDGE);
_compatibleHypothesis.push_back("LocalLength"); _compatibleHypothesis.push_back("LocalLength");
_compatibleHypothesis.push_back("NumberOfSegments"); _compatibleHypothesis.push_back("NumberOfSegments");
_localLength = 0; _localLength = 0;
_numberOfSegments = 0; _numberOfSegments = 0;
_hypLocalLength = NULL; _hypLocalLength = NULL;
_hypNumberOfSegments = NULL; _hypNumberOfSegments = NULL;
} }
//============================================================================= //=============================================================================
@ -93,7 +91,7 @@ SMESH_Regular_1D::~SMESH_Regular_1D()
ostream & SMESH_Regular_1D::SaveTo(ostream & save) ostream & SMESH_Regular_1D::SaveTo(ostream & save)
{ {
return save << this; return save << this;
} }
//============================================================================= //=============================================================================
@ -104,7 +102,7 @@ ostream & SMESH_Regular_1D::SaveTo(ostream & save)
istream & SMESH_Regular_1D::LoadFrom(istream & load) istream & SMESH_Regular_1D::LoadFrom(istream & load)
{ {
return load >> (*this); return load >> (*this);
} }
//============================================================================= //=============================================================================
@ -113,9 +111,9 @@ istream & SMESH_Regular_1D::LoadFrom(istream & load)
*/ */
//============================================================================= //=============================================================================
ostream& operator << (ostream & save, SMESH_Regular_1D & hyp) ostream & operator <<(ostream & save, SMESH_Regular_1D & hyp)
{ {
return save; return save;
} }
//============================================================================= //=============================================================================
@ -124,9 +122,9 @@ ostream& operator << (ostream & save, SMESH_Regular_1D & hyp)
*/ */
//============================================================================= //=============================================================================
istream& operator >> (istream & load, SMESH_Regular_1D & hyp) istream & operator >>(istream & load, SMESH_Regular_1D & hyp)
{ {
return load; return load;
} }
//============================================================================= //=============================================================================
@ -135,203 +133,193 @@ istream& operator >> (istream & load, SMESH_Regular_1D & hyp)
*/ */
//============================================================================= //=============================================================================
bool SMESH_Regular_1D::CheckHypothesis(SMESH_Mesh& aMesh, bool SMESH_Regular_1D::CheckHypothesis(SMESH_Mesh & aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape & aShape)
{ {
//MESSAGE("SMESH_Regular_1D::CheckHypothesis"); //MESSAGE("SMESH_Regular_1D::CheckHypothesis");
list<SMESHDS_Hypothesis*>::const_iterator itl; list <const SMESHDS_Hypothesis * >::const_iterator itl;
SMESHDS_Hypothesis* theHyp; const SMESHDS_Hypothesis *theHyp;
const list<SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape); const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
int nbHyp = hyps.size(); int nbHyp = hyps.size();
if (nbHyp != 1) return false; // only one compatible hypothesis allowed if (nbHyp != 1) return false; // only one compatible hypothesis allowed
itl = hyps.begin(); itl = hyps.begin();
theHyp = (*itl); theHyp = (*itl);
string hypName = theHyp->GetName(); string hypName = theHyp->GetName();
int hypId = theHyp->GetID(); int hypId = theHyp->GetID();
//SCRUTE(hypName); //SCRUTE(hypName);
bool isOk = false; bool isOk = false;
if (hypName == "LocalLength") if (hypName == "LocalLength")
{
_hypLocalLength = dynamic_cast<SMESH_LocalLength*> (theHyp);
ASSERT(_hypLocalLength);
_localLength = _hypLocalLength->GetLength();
_numberOfSegments = 0;
isOk =true;
}
if (hypName == "NumberOfSegments")
{
_hypNumberOfSegments = dynamic_cast<SMESH_NumberOfSegments*> (theHyp);
ASSERT(_hypNumberOfSegments);
_numberOfSegments = _hypNumberOfSegments->GetNumberOfSegments();
_scaleFactor = _hypNumberOfSegments->GetScaleFactor();
_localLength = 0;
isOk = true;
}
//SCRUTE(_localLength);
//SCRUTE(_numberOfSegments);
return isOk;
}
//=============================================================================
/*!
*
*/
//=============================================================================
bool SMESH_Regular_1D::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
{
//MESSAGE("SMESH_Regular_1D::Compute");
const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
SMESH_subMesh* theSubMesh = aMesh.GetSubMesh(aShape);
const TopoDS_Edge& EE = TopoDS::Edge(aShape);
TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
double f,l;
Handle(Geom_Curve) Curve = BRep_Tool::Curve(E,f,l);
TopoDS_Vertex VFirst, VLast;
TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
double length = EdgeLength(E);
//SCRUTE(length);
double eltSize = 1;
// if (_localLength > 0) eltSize = _localLength;
if (_localLength > 0)
{
double nbseg = ceil(length/_localLength); // integer sup
if (nbseg <=0) nbseg = 1; // degenerated edge
eltSize = length/nbseg;
}
else
{
ASSERT(_numberOfSegments> 0);
eltSize = length/_numberOfSegments;
}
ASSERT(!VFirst.IsNull());
SMESH_subMesh* firstSubMesh = aMesh.GetSubMesh(VFirst);
const TColStd_ListOfInteger& lidf
= firstSubMesh->GetSubMeshDS()->GetIDNodes();
int idFirst= lidf.First();
//SCRUTE(idFirst);
ASSERT(!VLast.IsNull());
SMESH_subMesh* lastSubMesh = aMesh.GetSubMesh(VLast);
const TColStd_ListOfInteger& lidl
= lastSubMesh->GetSubMeshDS()->GetIDNodes();
int idLast= lidl.First();
//SCRUTE(idLast);
if (!Curve.IsNull())
{
GeomAdaptor_Curve C3d(Curve);
GCPnts_UniformAbscissa Discret(C3d,eltSize,f,l);
int NbPoints = Discret.NbPoints();
//MESSAGE("nb points on edge : "<<NbPoints);
// edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
// only internal nodes receive an edge position with param on curve
int idPrev = idFirst;
for (int i=2; i<NbPoints; i++)
{ {
double param = Discret.Parameter(i); _hypLocalLength = dynamic_cast <const SMESH_LocalLength * >(theHyp);
ASSERT(_hypLocalLength);
if(_numberOfSegments > 1) _localLength = _hypLocalLength->GetLength();
{ _numberOfSegments = 0;
double epsilon = 0.001; isOk = true;
if( fabs(_scaleFactor-1.0) > epsilon )
{
double alpha = pow(_scaleFactor, 1.0/(_numberOfSegments-1) );
double d = length*(1-pow(alpha,i-1))/(1-pow(alpha,_numberOfSegments));
param = d;
}
}
gp_Pnt P = Curve->Value(param);
//Add the Node in the DataStructure
int nodeId = meshDS->AddNode(P.X(), P.Y(), P.Z());
//MESSAGE("point "<<nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" - "<<i<<" "<<param);
Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
meshDS->SetNodeOnEdge(node, E);
// **** edgePosition associe au point = param.
// Handle (SMDS_EdgePosition) epos
// = new SMDS_EdgePosition(theSubMesh->GetId(),param); // non, deja cree
// node->SetPosition(epos);
Handle (SMDS_EdgePosition) epos
= Handle (SMDS_EdgePosition)::DownCast(node->GetPosition());
epos->SetUParameter(param);
int edgeId = meshDS->AddEdge(idPrev, nodeId);
elt = meshDS->FindElement(edgeId);
meshDS->SetMeshElementOnShape(elt, E);
idPrev = nodeId;
} }
int edgeId = meshDS->AddEdge(idPrev, idLast);
Handle (SMDS_MeshElement) elt = meshDS->FindElement(edgeId); if (hypName == "NumberOfSegments")
meshDS->SetMeshElementOnShape(elt, E); {
} _hypNumberOfSegments =
else dynamic_cast <const SMESH_NumberOfSegments * >(theHyp);
{ ASSERT(_hypNumberOfSegments);
_numberOfSegments = _hypNumberOfSegments->GetNumberOfSegments();
_scaleFactor = _hypNumberOfSegments->GetScaleFactor();
_localLength = 0;
isOk = true;
}
//SCRUTE(_localLength);
//SCRUTE(_numberOfSegments);
return isOk;
}
//=============================================================================
/*!
*
*/
//=============================================================================
bool SMESH_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
{
MESSAGE("SMESH_Regular_1D::Compute");
SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
const TopoDS_Edge & EE = TopoDS::Edge(aShape);
TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
double f, l;
Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
TopoDS_Vertex VFirst, VLast;
TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
double length = EdgeLength(E);
//SCRUTE(length);
double eltSize = 1;
// if (_localLength > 0) eltSize = _localLength;
if (_localLength > 0)
{
double nbseg = ceil(length / _localLength); // integer sup
if (nbseg <= 0)
nbseg = 1; // degenerated edge
eltSize = length / nbseg;
}
else
{
ASSERT(_numberOfSegments > 0);
eltSize = length / _numberOfSegments;
}
ASSERT(!VFirst.IsNull());
SMESH_subMesh *firstSubMesh = aMesh.GetSubMesh(VFirst);
const vector<int> & lidf
= firstSubMesh->GetSubMeshDS()->GetIDNodes();
int idFirst = lidf[0];
//SCRUTE(idFirst);
ASSERT(!VLast.IsNull());
SMESH_subMesh *lastSubMesh = aMesh.GetSubMesh(VLast);
const vector<int> & lidl
= lastSubMesh->GetSubMeshDS()->GetIDNodes();
int idLast = lidl[0];
//SCRUTE(idLast);
if (!Curve.IsNull())
{
GeomAdaptor_Curve C3d(Curve);
GCPnts_UniformAbscissa Discret(C3d, eltSize, f, l);
int NbPoints = Discret.NbPoints();
//MESSAGE("nb points on edge : "<<NbPoints);
// edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
// only internal nodes receive an edge position with param on curve
int idPrev = idFirst;
for (int i = 2; i < NbPoints; i++)
{
double param = Discret.Parameter(i);
if (_numberOfSegments > 1)
{
double epsilon = 0.001;
if (fabs(_scaleFactor - 1.0) > epsilon)
{
double alpha =
pow(_scaleFactor, 1.0 / (_numberOfSegments - 1));
double d =
length * (1 - pow(alpha, i - 1)) / (1 - pow(alpha,
_numberOfSegments));
param = d;
}
}
gp_Pnt P = Curve->Value(param);
//Add the Node in the DataStructure
//MESSAGE("point "<<nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" - "<<i<<" "<<param);
SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
meshDS->SetNodeOnEdge(node, E);
// **** edgePosition associe au point = param.
SMDS_EdgePosition* epos=dynamic_cast<SMDS_EdgePosition *>(node->GetPosition());
epos->SetUParameter(param);
SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node->GetID());
meshDS->SetMeshElementOnShape(edge, E);
idPrev = node->GetID();
}
SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
meshDS->SetMeshElementOnShape(edge, E);
}
else
{
// MESSAGE ("Edge Degeneree non traitee --- arret"); // MESSAGE ("Edge Degeneree non traitee --- arret");
// ASSERT(0); // ASSERT(0);
if (BRep_Tool::Degenerated(E)) if (BRep_Tool::Degenerated(E))
{ {
// Edge is a degenerated Edge : We put n = 5 points on the edge. // Edge is a degenerated Edge : We put n = 5 points on the edge.
int NbPoints = 5; int NbPoints = 5;
BRep_Tool::Range(E,f,l); BRep_Tool::Range(E, f, l);
double du = (l-f)/(NbPoints-1); double du = (l - f) / (NbPoints - 1);
MESSAGE("************* Degenerated edge! *****************"); MESSAGE("************* Degenerated edge! *****************");
TopoDS_Vertex V1,V2;
TopExp::Vertices (E,V1,V2);
gp_Pnt P = BRep_Tool::Pnt(V1);
int idPrev = idFirst;
for (int i=2; i<NbPoints; i++)
{
double param = f + (i-1)*du;
//Add the Node in the DataStructure
int nodeId = meshDS->AddNode(P.X(), P.Y(), P.Z());
//MESSAGE("point "<<nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" - "<<i<<" "<<param);
Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId); TopoDS_Vertex V1, V2;
Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt); TopExp::Vertices(E, V1, V2);
meshDS->SetNodeOnEdge(node, E); gp_Pnt P = BRep_Tool::Pnt(V1);
// Handle (SMDS_EdgePosition) epos int idPrev = idFirst;
// = new SMDS_EdgePosition(theSubMesh->GetId(),param); for (int i = 2; i < NbPoints; i++)
// node->SetPosition(epos); {
Handle (SMDS_EdgePosition) epos double param = f + (i - 1) * du;
= Handle (SMDS_EdgePosition)::DownCast(node->GetPosition()); SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
epos->SetUParameter(param); meshDS->SetNodeOnEdge(node, E);
int edgeId = meshDS->AddEdge(idPrev, nodeId); // Handle (SMDS_EdgePosition) epos
elt = meshDS->FindElement(edgeId); // = new SMDS_EdgePosition(theSubMesh->GetId(),param);
meshDS->SetMeshElementOnShape(elt, E); // node->SetPosition(epos);
idPrev = nodeId; SMDS_EdgePosition* epos
} = dynamic_cast<SMDS_EdgePosition*>(node->GetPosition());
int edgeId = meshDS->AddEdge(idPrev, idLast); epos->SetUParameter(param);
Handle (SMDS_MeshElement) elt = meshDS->FindElement(edgeId);
meshDS->SetMeshElementOnShape(elt, E); SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node->GetID());
meshDS->SetMeshElementOnShape(edge, E);
idPrev = node->GetID();
}
SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
meshDS->SetMeshElementOnShape(edge, E);
}
else
ASSERT(0);
} }
else ASSERT(0); return true;
}
return true;
} }

File diff suppressed because it is too large Load Diff

View File

@ -45,83 +45,87 @@ class SMESH_Hypothesis;
class SMESH_subMesh class SMESH_subMesh
{ {
public: public:
SMESH_subMesh(int Id, SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
SMESH_Mesh* father,
const Handle(SMESHDS_Mesh)& meshDS,
const TopoDS_Shape & aSubShape); const TopoDS_Shape & aSubShape);
virtual ~SMESH_subMesh(); virtual ~ SMESH_subMesh();
int GetId(); int GetId();
// bool Contains(const TopoDS_Shape & aSubShape) // bool Contains(const TopoDS_Shape & aSubShape)
// throw (SALOME_Exception); // throw (SALOME_Exception);
const Handle(SMESHDS_SubMesh)& GetSubMeshDS() SMESHDS_SubMesh * GetSubMeshDS() throw(SALOME_Exception);
throw (SALOME_Exception);
SMESH_subMesh* GetFirstToCompute() SMESH_subMesh *GetFirstToCompute() throw(SALOME_Exception);
throw (SALOME_Exception);
const map<int, SMESH_subMesh*>& DependsOn(); const map < int, SMESH_subMesh * >&DependsOn();
const map<int, SMESH_subMesh*>& Dependants(); const map < int, SMESH_subMesh * >&Dependants();
const TopoDS_Shape& GetSubShape(); const TopoDS_Shape & GetSubShape();
bool _vertexSet; // only for vertex subMesh, set to false for dim > 0 bool _vertexSet; // only for vertex subMesh, set to false for dim > 0
enum compute_state { NOT_READY, READY_TO_COMPUTE, enum compute_state
COMPUTE_OK, FAILED_TO_COMPUTE }; { NOT_READY, READY_TO_COMPUTE,
enum algo_state { NO_ALGO, MISSING_HYP, HYP_OK }; COMPUTE_OK, FAILED_TO_COMPUTE
enum algo_event {ADD_HYP, ADD_ALGO, };
REMOVE_HYP, REMOVE_ALGO, enum algo_state
ADD_FATHER_HYP, ADD_FATHER_ALGO, { NO_ALGO, MISSING_HYP, HYP_OK };
REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO}; enum algo_event
enum compute_event {MODIF_HYP, MODIF_ALGO_STATE, COMPUTE, { ADD_HYP, ADD_ALGO,
CLEAN, CLEANDEP, SUBMESH_COMPUTED}; REMOVE_HYP, REMOVE_ALGO,
ADD_FATHER_HYP, ADD_FATHER_ALGO,
REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO
};
enum compute_event
{ MODIF_HYP, MODIF_ALGO_STATE, COMPUTE,
CLEAN, CLEANDEP, SUBMESH_COMPUTED
};
bool AlgoStateEngine(int event, SMESH_Hypothesis* anHyp) bool AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
throw (SALOME_Exception); throw(SALOME_Exception);
void SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis* anHyp) void SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
throw (SALOME_Exception); throw(SALOME_Exception);
void DumpAlgoState(bool isMain); void DumpAlgoState(bool isMain);
bool ComputeStateEngine(int event) bool ComputeStateEngine(int event) throw(SALOME_Exception);
throw (SALOME_Exception);
int GetComputeState() {return _computeState;}; int GetComputeState()
{
return _computeState;
};
protected: protected:
void InsertDependence(const TopoDS_Shape aSubShape); void InsertDependence(const TopoDS_Shape aSubShape);
// void FinalizeDependence(list<TopoDS_Shape>& shapeList); // void FinalizeDependence(list<TopoDS_Shape>& shapeList);
bool SubMeshesComputed() bool SubMeshesComputed() throw(SALOME_Exception);
throw (SALOME_Exception);
bool SubMeshesReady(); bool SubMeshesReady();
void RemoveSubMeshElementsAndNodes(); void RemoveSubMeshElementsAndNodes();
void UpdateDependantsState(); void UpdateDependantsState();
void CleanDependants(); void CleanDependants();
void ExtractDependants(const TopTools_IndexedDataMapOfShapeListOfShape& M, void ExtractDependants(const TopTools_IndexedDataMapOfShapeListOfShape & M,
const TopAbs_ShapeEnum etype); const TopAbs_ShapeEnum etype);
void SetAlgoState(int state); void SetAlgoState(int state);
TopoDS_Shape _subShape; TopoDS_Shape _subShape;
Handle (SMESHDS_Mesh) _meshDS; SMESHDS_Mesh * _meshDS;
Handle (SMESHDS_SubMesh) _subMeshDS; SMESHDS_SubMesh * _subMeshDS;
int _Id; int _Id;
SMESH_Mesh* _father; SMESH_Mesh *_father;
map<int, SMESH_subMesh*> _mapDepend; map < int, SMESH_subMesh * >_mapDepend;
map<int, SMESH_subMesh*> _mapDependants; map < int, SMESH_subMesh * >_mapDependants;
bool _dependenceAnalysed; bool _dependenceAnalysed;
bool _dependantsFound; bool _dependantsFound;
int _algoState; int _algoState;
int _oldAlgoState; int _oldAlgoState;
int _computeState; int _computeState;
}; };