X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeTools.cpp;h=3a4f577ac27be670f7974e4f6a8d88c477b5c35f;hb=f5c7bb3100ed321392da42f61c2ab505833ec61a;hp=6955720e2f46bd3cfcc165f2a03fb673414020af;hpb=8fbee802bd4c0e7c7e2a1d23e4b800174373f932;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 6955720e2..3a4f577ac 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -8,15 +8,24 @@ #include +#include + #include +#include #include #include +#include +#include #include #include #include #include +#include #include #include +#include +#include + //================================================================================================= double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr theShape) @@ -88,16 +97,22 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr continue; } else if(aListOfShape.Size() == 1) { - aFreeShapes.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()); - aFreeShapes.Remove(aListOfShape.First()); - aFreeShapes.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(); @@ -107,12 +122,18 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr aTempListOfShape.Clear(); } else if(aTempListOfShape.Size() > 1) { if(aTempListOfShape.First() == aTempShape) { - aTempMap.Add(aTempListOfShape.Last()); - aFreeShapes.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()); - aFreeShapes.Remove(aTempListOfShape.First()); + const TopoDS_Shape& aTF = aTempListOfShape.First(); + if(aTempMap.Add(aTF)) { + aTempList.Append(aTF); + aFreeShapes.Remove(aTF); + } aTempListOfShape.Clear(); } } @@ -128,10 +149,13 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr TopoDS_CompSolid aCSolid; TopoDS_Builder aBuilder; 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& aShape = aShIter.Value(); - theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape); + NCollection_Map& aShapesMap = anIter.ChangeValue(); + for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) { + const TopoDS_Shape& aShape = anExp.Current(); + if(aShapesMap.Contains(aShape)) { + theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape); + aShapesMap.Remove(aShape); + } } std::shared_ptr aGeomShape(new GeomAPI_Shape); TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell); @@ -140,10 +164,34 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr } // 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); + for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) { + const TopoDS_Shape& aShape = anExp.Current(); + if(aFreeShapes.Contains(aShape)) { + 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; +}