]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_WireBuilder.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_WireBuilder.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_WireBuilder.cpp
4 // Created:     14 April 2016
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_WireBuilder.h"
8
9 #include <BRepBuilderAPI_MakeWire.hxx>
10 #include <TopoDS.hxx>
11 #include <TopoDS_Wire.hxx>
12 #include <TopExp_Explorer.hxx>
13
14 //=================================================================================================
15 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_WireBuilder::wire(const ListOfShape& theShapes)
16 {
17   TopTools_ListOfShape aListOfEdges;
18
19   for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
20     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
21     switch(aShape.ShapeType()) {
22       case TopAbs_EDGE: {
23         aListOfEdges.Append(aShape);
24         break;
25       }
26       case TopAbs_WIRE: {
27         for(TopExp_Explorer anExp(aShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
28           aListOfEdges.Append(anExp.Current());
29         }
30         break;
31       }
32       default: {
33         return GeomShapePtr();
34       }
35     }
36   }
37
38   BRepBuilderAPI_MakeWire aWireBuilder;
39   aWireBuilder.Add(aListOfEdges);
40   if(aWireBuilder.Error() != BRepBuilderAPI_WireDone) {
41     return GeomShapePtr();
42   }
43
44   GeomShapePtr aResultShape(new GeomAPI_Shape());
45   aResultShape->setImpl(new TopoDS_Shape(aWireBuilder.Wire()));
46   return aResultShape;
47 }