X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeTools.cpp;h=39b06f92723b9cfe1ed4c8082a617234fd75ce5d;hb=580f1752efd9d3e8c2890c4016b04dafd639bab7;hp=aa5486888a6bb5bb3fb7adbd64d9bf06dc2ee896;hpb=65bd7c71b6eda2cad73adcc3be6c6ad725c26b94;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index aa5486888..39b06f927 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -8,15 +8,23 @@ #include +#include + #include +#include #include #include +#include +#include #include #include #include #include +#include #include #include +#include + //================================================================================================= double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr theShape) @@ -50,31 +58,37 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::centreOfMass(std::shared_pt } //================================================================================================= -void GeomAlgoAPI_ShapeTools::combineFacesToShells(const ListOfShape& theFacesList, - ListOfShape& theShells, - ListOfShape& theFreeFaces) +void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr theCompound, + const GeomAPI_Shape::ShapeType theType, + ListOfShape& theCombinedShapes, + ListOfShape& theFreeShapes) { - if(theFacesList.empty()) { + if(!theCompound.get()) { return; } - // Adding all faces to compoud. - std::shared_ptr aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(theFacesList); - if(!aFacesCompound.get()) { + if(theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) { return; } - // Map edges and faces. - const TopoDS_Shape& aFacesComp = aFacesCompound->impl(); + TopAbs_ShapeEnum aTS = TopAbs_EDGE; + TopAbs_ShapeEnum aTA = TopAbs_FACE; + if(theType == GeomAPI_Shape::COMPSOLID) { + aTS = TopAbs_FACE; + aTA = TopAbs_SOLID; + } + + // Map subshapes and shapes. + const TopoDS_Shape& aShapesComp = theCompound->impl(); BOPCol_IndexedDataMapOfShapeListOfShape aMapEF; - BOPTools::MapShapesAndAncestors(aFacesComp, TopAbs_EDGE, TopAbs_FACE, aMapEF); + BOPTools::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapEF); if(aMapEF.IsEmpty()) { return; } - // Get all faces with common edges and free faces. - NCollection_Map aFreeFaces; - NCollection_Vector> aFacesWithCommonEdges; + // Get all shapes with common subshapes and free shapes. + NCollection_Map aFreeShapes; + NCollection_Vector> aShapesWithCommonSubshapes; for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) { const TopoDS_Shape& aShape = anIter.Key(); BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue(); @@ -82,16 +96,22 @@ void GeomAlgoAPI_ShapeTools::combineFacesToShells(const ListOfShape& theFacesLis continue; } else if(aListOfShape.Size() == 1) { - aFreeFaces.Add(aListOfShape.First()); + const TopoDS_Shape& aF = aListOfShape.First(); + aFreeShapes.Add(aF); aListOfShape.Clear(); } else { + NCollection_List aTempList; NCollection_Map aTempMap; - aTempMap.Add(aListOfShape.First()); - aTempMap.Add(aListOfShape.Last()); - aFreeFaces.Remove(aListOfShape.First()); - aFreeFaces.Remove(aListOfShape.Last()); + const TopoDS_Shape& aF = aListOfShape.First(); + const TopoDS_Shape& aL = aListOfShape.Last(); + aTempList.Append(aF); + aTempList.Append(aL); + aTempMap.Add(aF); + aTempMap.Add(aL); + aFreeShapes.Remove(aF); + aFreeShapes.Remove(aL); aListOfShape.Clear(); - for(NCollection_Map::Iterator aTempIter(aTempMap); aTempIter.More(); aTempIter.Next()) { + for(NCollection_List::Iterator aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) { const TopoDS_Shape& aTempShape = aTempIter.Value(); for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) { BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue(); @@ -101,42 +121,71 @@ void GeomAlgoAPI_ShapeTools::combineFacesToShells(const ListOfShape& theFacesLis aTempListOfShape.Clear(); } else if(aTempListOfShape.Size() > 1) { if(aTempListOfShape.First() == aTempShape) { - aTempMap.Add(aTempListOfShape.Last()); - aFreeFaces.Remove(aTempListOfShape.Last()); + const TopoDS_Shape& aTL = aTempListOfShape.Last(); + if(aTempMap.Add(aTL)) { + aTempList.Append(aTL); + aFreeShapes.Remove(aTL); + } aTempListOfShape.Clear(); } else if(aTempListOfShape.Last() == aTempShape) { - aTempMap.Add(aTempListOfShape.First()); - aFreeFaces.Remove(aTempListOfShape.First()); + const TopoDS_Shape& aTF = aTempListOfShape.First(); + if(aTempMap.Add(aTF)) { + aTempList.Append(aTF); + aFreeShapes.Remove(aTF); + } aTempListOfShape.Clear(); } } } } - aFacesWithCommonEdges.Append(aTempMap); + aShapesWithCommonSubshapes.Append(aTempMap); } } - // Make shells from faces with common edges. - NCollection_Vector aShells; - for(NCollection_Vector>::Iterator anIter(aFacesWithCommonEdges); anIter.More(); anIter.Next()) { + // Combine shapes with common subshapes. + for(NCollection_Vector>::Iterator anIter(aShapesWithCommonSubshapes); anIter.More(); anIter.Next()) { TopoDS_Shell aShell; + TopoDS_CompSolid aCSolid; TopoDS_Builder aBuilder; - aBuilder.MakeShell(aShell); + theType == GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell); const NCollection_Map& aShapesMap = anIter.Value(); for(NCollection_Map::Iterator aShIter(aShapesMap); aShIter.More(); aShIter.Next()) { - const TopoDS_Shape& aFace = aShIter.Value(); - aBuilder.Add(aShell, aFace); + const TopoDS_Shape& aShape = aShIter.Value(); + theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape); } - std::shared_ptr aGeomShell(std::make_shared()); - aGeomShell->setImpl(new TopoDS_Shape(aShell)); - theShells.push_back(aGeomShell); + std::shared_ptr aGeomShape(new GeomAPI_Shape); + TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell); + aGeomShape->setImpl(aSh); + theCombinedShapes.push_back(aGeomShape); } - // Adding free faces. - for(NCollection_Map::Iterator aShIter(aFreeFaces); aShIter.More(); aShIter.Next()) { - const TopoDS_Shape& aFace = aShIter.Value(); - std::shared_ptr aGeomFace(std::make_shared()); - aGeomFace->setImpl(new TopoDS_Shape(aFace)); - theFreeFaces.push_back(aGeomFace); + // Adding free shapes. + for(NCollection_Map::Iterator aShIter(aFreeShapes); aShIter.More(); aShIter.Next()) { + const TopoDS_Shape& aShape = aShIter.Value(); + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); + theFreeShapes.push_back(aGeomShape); } } + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr& theFace) +{ + if (!theFace.get()) + return std::shared_ptr(); + + TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl()); + if (aPlaneFace.IsNull()) + return std::shared_ptr(); + + Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace)); + if (aPlane.IsNull()) + return std::shared_ptr(); + + // make an infinity face on the plane + TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape(); + + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(anInfiniteFace)); + return aResult; +}