1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_ThroughAll.h"
22 #include <GeomAlgoAPI_Boolean.h>
23 #include <GeomAlgoAPI_ShapeTools.h>
25 #include <BRep_Builder.hxx>
26 #include <BOPAlgo_BOP.hxx>
27 #include <TopTools_ListOfShape.hxx>
28 #include <TopoDS_Compound.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopExp_Explorer.hxx>
32 //=================================================================================================
33 GeomAlgoAPI_ThroughAll::GeomAlgoAPI_ThroughAll(std::shared_ptr<GeomAlgoAPI_Prism> thePrismAlgo,
34 const ListOfShape& theObjects)
35 : GeomAlgoAPI_Boolean(thePrismAlgo->shape(), theObjects, GeomAlgoAPI_Tools::BOOL_CUT)
37 removeEnds(thePrismAlgo);
40 //=================================================================================================
41 void GeomAlgoAPI_ThroughAll::removeEnds(std::shared_ptr<GeomAlgoAPI_Prism> thePrismAlgo)
43 GeomShapePtr aCuttedTool = shape(); // result of BOP Cut (thePrismAlgo->shape() by theObjects)
45 // Simplify the result
46 ListOfShape aPieces = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aCuttedTool);
48 // Get end shapes of Prism
49 const ListOfShape& fromShapes = thePrismAlgo->fromShapes();
50 const ListOfShape& toShapes = thePrismAlgo->toShapes();
51 ListOfShape endShapes (fromShapes);
52 endShapes.insert(endShapes.end(), toShapes.begin(), toShapes.end());
54 // Throw away end pieces of cutted tools (containing endShapes)
55 TopTools_ListOfShape listTools;
56 for (ListOfShape::const_iterator
57 anIt = aPieces.begin(); anIt != aPieces.end(); anIt++) {
58 TopoDS_Shape aPiece = (*anIt)->impl<TopoDS_Shape>();
59 bool endPiece = false;
61 for (ListOfShape::const_iterator aBaseIt = endShapes.begin();
62 aBaseIt != endShapes.end() && !endPiece; aBaseIt++) {
63 // Check, if the piece contains aBase (one of endShapes)
64 TopoDS_Shape aBase = (*aBaseIt)->impl<TopoDS_Shape>();
65 TopExp_Explorer anExp (aPiece, aBase.ShapeType());
66 for (; anExp.More() && !endPiece; anExp.Next()) {
67 if (anExp.Current().IsSame(aBase))
73 listTools.Append(aPiece);
77 BRep_Builder aBuilder;
78 TopoDS_Compound aCompound;
79 aBuilder.MakeCompound(aCompound);
80 for (TopTools_ListOfShape::Iterator anIt(listTools); anIt.More(); anIt.Next()) {
81 aBuilder.Add(aCompound, anIt.Value());
84 std::shared_ptr<GeomAPI_Shape> aShape (new GeomAPI_Shape());
85 aShape->setImpl(new TopoDS_Shape(aCompound));
86 this->setShape(aShape);