]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_CompoundBuilder.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_CompoundBuilder.cpp
4 // Created:     24 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include <GeomAlgoAPI_CompoundBuilder.h>
8 #include <BRep_Builder.hxx>
9 #include <TopoDS_Compound.hxx>
10 #include <TopTools_IndexedMapOfShape.hxx>
11 #include <TopExp.hxx>
12
13 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_CompoundBuilder::compound(
14     std::list<std::shared_ptr<GeomAPI_Shape> > theShapes)
15 {
16   BRep_Builder aBuilder;
17   TopoDS_Compound aComp;
18   aBuilder.MakeCompound(aComp);
19
20   std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = theShapes.begin(), aLast =
21       theShapes.end();
22   for (; anIt != aLast; anIt++) {
23     aBuilder.Add(aComp, (*anIt)->impl<TopoDS_Shape>());
24   }
25
26   std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
27   aRes->setImpl(new TopoDS_Shape(aComp));
28   return aRes;
29 }
30
31 int GeomAlgoAPI_CompoundBuilder::id(
32       std::shared_ptr<GeomAPI_Shape> theContext, std::shared_ptr<GeomAPI_Shape> theSub)
33 {
34   int anID = 0;
35   TopoDS_Shape aMainShape = theContext->impl<TopoDS_Shape>();
36   const TopoDS_Shape& aSubShape = theSub->impl<TopoDS_Shape>();
37   if (!aMainShape.IsNull() && !aSubShape.IsNull()) {
38     TopTools_IndexedMapOfShape aSubShapesMap;
39     TopExp::MapShapes(aMainShape, aSubShapesMap);
40     anID = aSubShapesMap.FindIndex(aSubShape);
41   }
42
43   return anID;
44 }