X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Gen.cxx;h=ec40c71ff9a7d3335fdee3cb5a09e6687dd55897;hp=a3fb26ab3d9d1c586261de0c5622dcdb090e5ac6;hb=ef932e4d05a45b9a3034423e30519d15e664f2bc;hpb=789d7f7415a1e465aee36232e7633eea548ff1fb diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index a3fb26ab3..ec40c71ff 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -26,14 +26,8 @@ // Module : SMESH // $Header$ -using namespace std; -using namespace std; #include "SMESH_Gen.hxx" - #include "SMESH_subMesh.hxx" - -#include "SMESHDS_ListOfPtrHypothesis.hxx" -#include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -51,9 +45,9 @@ using namespace std; SMESH_Gen::SMESH_Gen() { - MESSAGE("SMESH_Gen::SMESH_Gen"); - _localId = 0; - _hypothesisFactory.SetGen(this); + MESSAGE("SMESH_Gen::SMESH_Gen"); + _localId = 0; + _hypothesisFactory.SetGen(this); } //============================================================================= @@ -64,7 +58,7 @@ 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, - int studyId) - throw (SALOME_Exception) +SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId) + throw(SALOME_Exception) { - MESSAGE("SMESH_Gen::CreateHypothesis"); - // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document + MESSAGE("CreateHypothesis("<GetID(); - myStudyContext->mapHypothesis[hypId] = myHypothesis; - SCRUTE(studyId); - SCRUTE(hypId); + SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId); + int hypId = myHypothesis->GetID(); + myStudyContext->mapHypothesis[hypId] = myHypothesis; + SCRUTE(studyId); + 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) - throw (SALOME_Exception) +SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape) +throw(SALOME_Exception) { - MESSAGE("SMESH_Gen::Init"); + MESSAGE("SMESH_Gen::Init"); // if (aShape.ShapeType() == TopAbs_COMPOUND) // { // INFOS("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++, - studyId, - this, - myStudyContext->myDocument); - myStudyContext->mapMesh[_localId] = mesh; + SMESH_Mesh *mesh = new SMESH_Mesh(_localId++, + studyId, + this, + myStudyContext->myDocument); + myStudyContext->mapMesh[_localId] = mesh; - // associate a TopoDS_Shape to the mesh + // associate a TopoDS_Shape to the mesh - mesh->ShapeToMesh(aShape); - return mesh; + mesh->ShapeToMesh(aShape); + 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) - throw (SALOME_Exception) +bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) +throw(SALOME_Exception) { - MESSAGE("SMESH_Gen::Compute"); + MESSAGE("SMESH_Gen::Compute"); // bool isDone = false; /* Algo : s'appuie ou non sur une geometrie @@ -150,49 +144,46 @@ Face, Shell, collection de Face et Shells : 2D Solid, Collection de Solid : 3D */ // *** corriger commentaires - // check hypothesis associated to the mesh : - // - only one algo : type compatible with the type of the shape - // - hypothesis = compatible with algo - // - check if hypothesis are applicable to this algo - // - check contradictions within hypothesis - // (test if enough hypothesis is done further) + // check hypothesis associated to the mesh : + // - only one algo : type compatible with the type of the shape + // - hypothesis = compatible with algo + // - check if hypothesis are applicable to this algo + // - check contradictions within hypothesis + // (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); - SMESH_subMesh* smToCompute = sm->GetFirstToCompute(); - while (smToCompute) - { - TopoDS_Shape subShape = smToCompute->GetSubShape(); - int dim = GetShapeDim(subShape); - //SCRUTE(dim); - if (dim > 0) - { - bool ret1 = smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE); - ret = ret && ret1; - } - else + SMESH_subMesh *smToCompute = sm->GetFirstToCompute(); + while (smToCompute) { - 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 "<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); + TopoDS_Shape subShape = smToCompute->GetSubShape(); + int dim = GetShapeDim(subShape); + //SCRUTE(dim); + if (dim > 0) + { + bool ret1 = smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE); + ret = ret && ret1; + } + else + { + ASSERT(dim == 0); + ASSERT(smToCompute->_vertexSet == false); + TopoDS_Vertex V1 = TopoDS::Vertex(subShape); + gp_Pnt P1 = BRep_Tool::Pnt(V1); + SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); + //MESSAGE("point "<AddNode(P1.X(), P1.Y(), P1.Z()); + meshDS->SetNodeOnVertex(node, V1); + smToCompute->GetSubMeshDS(); + smToCompute->_vertexSet = true; + smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE); + } + smToCompute = sm->GetFirstToCompute(); } - smToCompute = sm->GetFirstToCompute(); - } - return ret; + return ret; } //============================================================================= @@ -201,83 +192,90 @@ Solid, Collection de Solid : 3D */ //============================================================================= -SMESH_Algo* SMESH_Gen::GetAlgo(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape) +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; + //MESSAGE("SMESH_Gen::GetAlgo"); - // try shape first, then main shape + const SMESHDS_Hypothesis *theHyp = NULL; + SMESH_Algo *algo = NULL; + const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); + int hypType; + int hypId; + int algoDim; - TopoDS_Shape mainShape = meshDS->ShapeToMesh(); - const TopoDS_Shape* shapeToTry[2] = {&aShape, &mainShape}; + // try shape first, then main shape - for (int iShape=0; iShape<2; iShape++) - { - TopoDS_Shape tryShape = (*shapeToTry[iShape]); + TopoDS_Shape mainShape = meshDS->ShapeToMesh(); + const TopoDS_Shape *shapeToTry[2] = { &aShape, &mainShape }; - const SMESHDS_ListOfPtrHypothesis& listHyp - = meshDS->GetHypothesis(tryShape); - SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp); + for (int iShape = 0; iShape < 2; iShape++) + { + TopoDS_Shape tryShape = (*shapeToTry[iShape]); - int nb_algo = 0; - int shapeDim = GetShapeDim(aShape); - int typeOfShape = aShape.ShapeType(); + const list& listHyp = + meshDS->GetHypothesis(tryShape); + list::const_iterator it=listHyp.begin(); + + 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) + while (it!=listHyp.end()) { - 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; + 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++; } -// 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.Next(); + if (nb_algo == 1) // one algo found : OK + break; // do not try a parent shape } - if (nb_algo == 1) // one algo found : OK - break; // do not try a parent shape - } - if (!theHyp) return NULL; // no algo found + if (!theHyp) + return NULL; // no algo found - hypType = theHyp->GetType(); - hypId = theHyp->GetID(); + 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; + ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end()); + algo = _mapAlgo[hypId]; + //MESSAGE("Algo found " << algo->GetName() << " Id " << hypId); + return algo; } //============================================================================= @@ -286,18 +284,18 @@ SMESH_Algo* SMESH_Gen::GetAlgo(SMESH_Mesh& aMesh, */ //============================================================================= -StudyContextStruct* SMESH_Gen::GetStudyContext(int studyId) +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]; + // 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()); - 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) { -} +} //============================================================================= /*! @@ -329,26 +327,25 @@ void SMESH_Gen::Load(int studyId, const char *aUrlOfFile) void SMESH_Gen::Close(int studyId) { } - + //============================================================================= /*! * */ //============================================================================= -const char* SMESH_Gen::ComponentDataType() +const char *SMESH_Gen::ComponentDataType() { } - //============================================================================= /*! * */ //============================================================================= -const char* SMESH_Gen::IORToLocalPersistentID(const char* IORString, - bool& IsAFile) +const char *SMESH_Gen::IORToLocalPersistentID(const char *IORString, + bool & IsAFile) { } @@ -358,7 +355,7 @@ const char* SMESH_Gen::IORToLocalPersistentID(const char* IORString, */ //============================================================================= -const char* SMESH_Gen::LocalPersistentIDToIOR(const char* aLocalPersistentID) +const char *SMESH_Gen::LocalPersistentIDToIOR(const char *aLocalPersistentID) { } @@ -368,42 +365,42 @@ const char* SMESH_Gen::LocalPersistentIDToIOR(const char* aLocalPersistentID) */ //============================================================================= -int SMESH_Gen::GetShapeDim(const TopoDS_Shape& aShape) +int SMESH_Gen::GetShapeDim(const TopoDS_Shape & aShape) { - int shapeDim = -1; // Shape dimension: 0D, 1D, 2D, 3D - int type = aShape.ShapeType(); - switch (type) - { + int shapeDim = -1; // Shape dimension: 0D, 1D, 2D, 3D + int type = aShape.ShapeType(); + switch (type) + { // case TopAbs_COMPOUND: // { -// break; +// break; // } - case TopAbs_COMPOUND: - case TopAbs_COMPSOLID: - case TopAbs_SOLID: - case TopAbs_SHELL: - { - shapeDim = 3; - break; - } - // case TopAbs_SHELL: - case TopAbs_FACE: - { - shapeDim = 2; - break; - } - case TopAbs_WIRE: - case TopAbs_EDGE: - { - shapeDim = 1; - break; - } - case TopAbs_VERTEX: - { - shapeDim = 0; - break; - } - } + case TopAbs_COMPOUND: + case TopAbs_COMPSOLID: + case TopAbs_SOLID: + case TopAbs_SHELL: + { + shapeDim = 3; + break; + } + // case TopAbs_SHELL: + case TopAbs_FACE: + { + shapeDim = 2; + break; + } + case TopAbs_WIRE: + case TopAbs_EDGE: + { + shapeDim = 1; + break; + } + case TopAbs_VERTEX: + { + shapeDim = 0; + break; + } + } // SCRUTE(shapeDim); - return shapeDim; + return shapeDim; }