Salome HOME
Issue #1369: Wire feature draft implementation.
[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
13 //=================================================================================================
14 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_WireBuilder::wire(const ListOfShape& theShapes)
15 {
16   BRepBuilderAPI_MakeWire aWireBuilder;
17
18   for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
19     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
20     switch(aShape.ShapeType()) {
21       case TopAbs_EDGE: {
22         aWireBuilder.Add(TopoDS::Edge(aShape));
23         break;
24       }
25       case TopAbs_WIRE: {
26         aWireBuilder.Add(TopoDS::Wire(aShape));
27         break;
28       }
29       default: {
30         return GeomShapePtr();
31       }
32     }
33   }
34
35   if(aWireBuilder.Error() != BRepBuilderAPI_WireDone) {
36     return GeomShapePtr();
37   }
38
39   GeomShapePtr aResultShape(new GeomAPI_Shape());
40   aResultShape->setImpl(new TopoDS_Shape(aWireBuilder.Wire()));
41   return aResultShape;
42 }