diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 9355ac74369cc3c26e79ea8b7fd990ea2f5aabc4..ee8f28bf3ea5d64dbe4c972590e82ecb0c44d635 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1,4 +1,4 @@ -// $Id: GModel.cpp,v 1.90 2008-06-12 09:31:36 geuzaine Exp $ +// $Id: GModel.cpp,v 1.91 2008-07-01 15:11:38 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -397,14 +397,17 @@ int GModel::mesh(int dimension) int GModel::getMeshStatus(bool countDiscrete) { for(riter it = firstRegion(); it != lastRegion(); ++it) - if((countDiscrete || (*it)->geomType() != GEntity::DiscreteVolume) && + if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteVolume && + (*it)->meshAttributes.Method != MESH_NONE)) && ((*it)->tetrahedra.size() ||(*it)->hexahedra.size() || (*it)->prisms.size() || (*it)->pyramids.size())) return 3; for(fiter it = firstFace(); it != lastFace(); ++it) - if((countDiscrete || (*it)->geomType() != GEntity::DiscreteSurface) && + if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteSurface && + (*it)->meshAttributes.Method != MESH_NONE)) && ((*it)->triangles.size() || (*it)->quadrangles.size())) return 2; for(eiter it = firstEdge(); it != lastEdge(); ++it) - if((countDiscrete || (*it)->geomType() != GEntity::DiscreteCurve) && + if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteCurve && + (*it)->meshAttributes.Method != MESH_NONE)) && (*it)->lines.size()) return 1; for(viter it = firstVertex(); it != lastVertex(); ++it) if((*it)->mesh_vertices.size()) return 0; diff --git a/Geo/GModel.h b/Geo/GModel.h index 434a56723b103843d9cdf3969d4457563f55e4ee..b064de5ed889b36286fd96b5302a2c308bc9e478 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -237,7 +237,7 @@ class GModel int readOCCBREP(const std::string &name); int readOCCIGES(const std::string &name); int readOCCSTEP(const std::string &name); - int importOCCShape(const void *shape, const void *options=0); + int importOCCShape(const void *shape, const void *meshConstraints=0); // Gmsh mesh file format int readMSH(const std::string &name); diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp index 93e97128608f2c3dde7f7955e43a4c1883217cf1..391287ee25123dbd73be1de81645e1f36a522fea 100644 --- a/Geo/GModelIO_OCC.cpp +++ b/Geo/GModelIO_OCC.cpp @@ -1,4 +1,4 @@ -// $Id: GModelIO_OCC.cpp,v 1.37 2008-07-01 14:24:07 geuzaine Exp $ +// $Id: GModelIO_OCC.cpp,v 1.38 2008-07-01 15:11:38 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -26,6 +26,7 @@ #include "OCCEdge.h" #include "OCCFace.h" #include "OCCRegion.h" +#include "MElement.h" #if defined(HAVE_OCC_MESH_CONSTRAINTS) #include "MeshGmsh_Constrain.hxx" @@ -442,97 +443,11 @@ void OCC_Internals::buildGModel(GModel *model) } } -void GModel::_deleteOCCInternals() -{ - if(_occ_internals) delete _occ_internals; - _occ_internals = 0; -} - -int GModel::readOCCBREP(const std::string &fn) -{ - _occ_internals = new OCC_Internals; - _occ_internals->loadBREP(fn.c_str()); - _occ_internals->buildGModel(this); - snapVertices(); - return 1; -} - -int GModel::readOCCIGES(const std::string &fn) -{ - _occ_internals = new OCC_Internals; - _occ_internals->loadIGES(fn.c_str()); - _occ_internals->buildGModel(this); - return 1; -} - -int GModel::readOCCSTEP(const std::string &fn) -{ - _occ_internals = new OCC_Internals; - _occ_internals->loadSTEP(fn.c_str()); - _occ_internals->buildGModel(this); - return 1; -} - -int GModel::importOCCShape(const void *shape, const void *options) -{ - extern void SetBoundingBox(); - - _occ_internals = new OCC_Internals; - _occ_internals->loadShape((TopoDS_Shape*)shape); - _occ_internals->buildGModel(this); - snapVertices(); - SetBoundingBox(); - - if(!options) return 1; - -#if defined(HAVE_OCC_MESH_CONSTRAINTS) - MeshGmsh_Constrain *c = (MeshGmsh_Constrain*)options; - MeshGmsh_DataMapOfShapeOfEdgeConstrain ecmap; - c->GetEdgeConstrain(ecmap); - - // iterate on all the edges of the model and set constraints (if - // any) - for(eiter it = firstEdge(); it != lastEdge(); ++it){ - GEdge *ge = *it; - TopoDS_Shape *shape = (TopoDS_Shape*)ge->getNativePtr(); - if(ecmap.IsBound(*shape)) { - Msg::Debug("Got meshing contraints for edge %d", ge->tag()); - const MeshGmsh_EdgeConstrain &ec(ecmap.Find(*shape)); - if(ec.IsMeshImposed() == Standard_True){ - TColStd_SequenceOfInteger num; - ec.GetNodesNumber(num); - TColStd_SequenceOfReal par; - ec.GetParameters(par); - int n = num.Length(); - if(par.Length() != n){ - Msg::Error("Wrong number of parameters in edge constraint: %d != %d", - num.Length(), par.Length()); - } - else{ - // set the mesh on this edge... - for(int i = 0; i < n; i++){ - printf("node %d param %g\n", num.Value(i), par.Value(i)); - } - // ...and never change it - ge->meshAttributes.Method == MESH_NONE; - } - } - } - } -#endif - - return 1; -} - -// This function has been inspired from SALOME It removes all -// duplicates from the geometry, starting from vertices, edges, faces, -// shells and solids This - void OCC_Internals::removeAllDuplicates(const double &tolerance) { } -void AddSimpleShapes(TopoDS_Shape theShape, TopTools_ListOfShape &theList) +static void addSimpleShapes(TopoDS_Shape theShape, TopTools_ListOfShape &theList) { if (theShape.ShapeType() != TopAbs_COMPOUND && theShape.ShapeType() != TopAbs_COMPSOLID) { @@ -548,7 +463,7 @@ void AddSimpleShapes(TopoDS_Shape theShape, TopTools_ListOfShape &theList) if (mapShape.Add(aShape_i)) { if (aShape_i.ShapeType() == TopAbs_COMPOUND || aShape_i.ShapeType() == TopAbs_COMPSOLID) { - AddSimpleShapes(aShape_i, theList); + addSimpleShapes(aShape_i, theList); } else { theList.Append(aShape_i); @@ -557,7 +472,7 @@ void AddSimpleShapes(TopoDS_Shape theShape, TopTools_ListOfShape &theList) } } -void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperator & op) +void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperator &op) { if (tool.IsNull()) return; if (shape.IsNull()) shape = tool; @@ -570,8 +485,8 @@ void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperat TopoDS_Compound C; B.MakeCompound(C); TopTools_ListOfShape listShape1, listShape2; - AddSimpleShapes(shape, listShape1); - AddSimpleShapes(tool, listShape2); + addSimpleShapes(shape, listShape1); + addSimpleShapes(tool, listShape2); Standard_Boolean isCompound = (listShape1.Extent() > 1 || listShape2.Extent() > 1); @@ -603,7 +518,7 @@ void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperat } if (isCompound) { TopTools_ListOfShape listShapeC; - AddSimpleShapes(C, listShapeC); + addSimpleShapes(C, listShapeC); TopTools_ListIteratorOfListOfShape itSubC (listShapeC); bool isOnlySolids = true; for (; itSubC.More(); itSubC.Next()) { @@ -627,15 +542,114 @@ void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperat } } -void OCC_Internals::Sphere(const SPoint3 & center, const double & radius, - const BooleanOperator & op) +void OCC_Internals::Sphere(const SPoint3 ¢er, const double &radius, + const BooleanOperator &op) { // build a sphere gp_Pnt aP(center.x(), center.y(), center.z()); TopoDS_Shape aShape = BRepPrimAPI_MakeSphere(aP, radius).Shape(); // either add it to the current shape, or use it as a tool and remove the // sphere from the current shape - applyBooleanOperator(aShape, op); + applyBooleanOperator(aShape, op); +} + +void GModel::_deleteOCCInternals() +{ + if(_occ_internals) delete _occ_internals; + _occ_internals = 0; +} + +int GModel::readOCCBREP(const std::string &fn) +{ + _occ_internals = new OCC_Internals; + _occ_internals->loadBREP(fn.c_str()); + _occ_internals->buildGModel(this); + snapVertices(); + return 1; +} + +int GModel::readOCCIGES(const std::string &fn) +{ + _occ_internals = new OCC_Internals; + _occ_internals->loadIGES(fn.c_str()); + _occ_internals->buildGModel(this); + return 1; +} + +int GModel::readOCCSTEP(const std::string &fn) +{ + _occ_internals = new OCC_Internals; + _occ_internals->loadSTEP(fn.c_str()); + _occ_internals->buildGModel(this); + return 1; +} + +static void applyOCCMeshConstraints(GModel *m, const void *constraints) +{ +#if defined(HAVE_OCC_MESH_CONSTRAINTS) + MeshGmsh_Constrain *meshConstraints = (MeshGmsh_Constrain*)constraints; + + // treat mesh constraints (if any) on model edges + MeshGmsh_DataMapOfShapeOfEdgeConstrain edgeConstraints; + meshConstraints->GetEdgeConstrain(edgeConstraints); + for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){ + GEdge *ge = *it; + TopoDS_Shape *shape = (TopoDS_Shape*)ge->getNativePtr(); + if(edgeConstraints.IsBound(*shape)) { + Msg::Debug("Applying mesh contraints on edge %d", ge->tag()); + const MeshGmsh_EdgeConstrain &c(edgeConstraints.Find(*shape)); + if(c.IsMeshImposed() == Standard_True){ + TColStd_SequenceOfInteger nodeNum; + c.GetNodesNumber(nodeNum); + TColStd_SequenceOfReal nodePar; + c.GetParameters(nodePar); + int n = nodeNum.Length(); + if(n < 2){ + Msg::Error("We need at least two points in the edge constraint"); + } + else if(nodePar.Length() != n){ + Msg::Error("Wrong number of parameters in edge constraint: %d != %d", + nodeNum.Length(), nodePar.Length()); + } + else{ + // set the mesh as immutable + ge->meshAttributes.Method == MESH_NONE; + // set the correct tags on the boundary vertices + ge->getBeginVertex()->mesh_vertices[0]->setNum(nodeNum(0)); + ge->getEndVertex()->mesh_vertices[0]->setNum(nodeNum(n - 1)); + // set the mesh on the edge + for(int i = 1; i < n - 1; i++){ + double u = nodePar.Value(i); + GPoint p = ge->point(u); + MEdgeVertex *v = new MEdgeVertex(p.x(), p.y(), p.z(), ge, u); + v->setNum(nodeNum.Value(i)); + ge->mesh_vertices.push_back(v); + } + for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){ + MVertex *v0 = (i == 0) ? + ge->getBeginVertex()->mesh_vertices[0] : ge->mesh_vertices[i - 1]; + MVertex *v1 = (i == ge->mesh_vertices.size()) ? + ge->getEndVertex()->mesh_vertices[0] : ge->mesh_vertices[i]; + ge->lines.push_back(new MLine(v0, v1)); + } + } + } + } + } +#endif + +} + +int GModel::importOCCShape(const void *shape, const void *meshConstraints) +{ + _occ_internals = new OCC_Internals; + _occ_internals->loadShape((TopoDS_Shape*)shape); + _occ_internals->buildGModel(this); + snapVertices(); + extern void SetBoundingBox(); + SetBoundingBox(); + if(meshConstraints) applyOCCMeshConstraints(this, meshConstraints); + return 1; } #else diff --git a/Geo/Makefile b/Geo/Makefile index cba91cb51a420682d984cfd47596ffaae2e8168c..ddee1cbd9a2b9dac7c5d3e4c86db1871e28e45b5 100644 --- a/Geo/Makefile +++ b/Geo/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.214 2008-06-20 05:51:36 geuzaine Exp $ +# $Id: Makefile,v 1.215 2008-07-01 15:11:38 geuzaine Exp $ # # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle # @@ -219,7 +219,8 @@ GModelIO_OCC.o: GModelIO_OCC.cpp GModelIO_OCC.h GModel.h GVertex.h \ GEntity.h Range.h SPoint3.h SBoundingBox3d.h GPoint.h SPoint2.h GEdge.h \ SVector3.h GFace.h GEdgeLoop.h Pair.h GRegion.h OCCIncludes.h \ ../Common/Message.h ../Common/Context.h OCCVertex.h MVertex.h OCCEdge.h \ - OCCFace.h OCCRegion.h + OCCFace.h OCCRegion.h MElement.h ../Common/GmshDefines.h MEdge.h \ + MFace.h GModelIO_Fourier.o: GModelIO_Fourier.cpp GModel.h GVertex.h GEntity.h \ Range.h SPoint3.h SBoundingBox3d.h GPoint.h SPoint2.h GEdge.h \ SVector3.h GFace.h GEdgeLoop.h Pair.h GRegion.h ../Common/Message.h \ diff --git a/Post/Makefile b/Post/Makefile index c82c7c8aa058e8b4e269b2ad83c996d57093b987..2bfe282cb389add33e86ca81e083f22ba8b3cffe 100644 --- a/Post/Makefile +++ b/Post/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.51 2008-06-07 17:20:57 geuzaine Exp $ +# $Id: Makefile,v 1.52 2008-07-01 15:11:38 geuzaine Exp $ # # Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle # @@ -94,7 +94,7 @@ PViewDataList.o: PViewDataList.cpp PViewDataList.h PViewData.h \ PViewDataListIO.o: PViewDataListIO.cpp PViewDataList.h PViewData.h \ ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/ListUtils.h \ ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h ../Common/Message.h \ - ../Common/Context.h + ../Common/Context.h adaptiveData.h ../Common/GmshMatrix.h PViewDataGModel.o: PViewDataGModel.cpp PViewDataGModel.h PViewData.h \ ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Geo/GModel.h \ ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \