Salome HOME
9e076e6f9c838140ce1129adb3af7f80bdaaf0a3
[modules/shaper.git] / src / GeomAPI / GeomAPI_DataMapOfShapeMapOfShapes.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_DataMapOfShapeMapOfShapes.cpp
4 // Created:     4 September 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
8
9 #include <NCollection_DataMap.hxx>
10 #include <NCollection_Map.hxx>
11 #include <TopoDS_Shape.hxx>
12
13 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
14
15 //=================================================================================================
16 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
17 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
18 {}
19
20 //=================================================================================================
21 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
22                                              const ListOfShape& theItems)
23 {
24   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
25   for(ListOfShape::const_iterator anIt = theItems.cbegin(); anIt != theItems.cend(); anIt++) {
26     const TopoDS_Shape& anItem = (*anIt)->impl<TopoDS_Shape>();
27     if(MY_MAP->IsBound(aKey)) {
28       MY_MAP->ChangeFind(aKey).Add(anItem);
29     } else {
30       NCollection_Map<TopoDS_Shape> anItems;
31       anItems.Add(anItem);
32       MY_MAP->Bind(aKey, anItems);
33     }
34   }
35
36   return true;
37 }
38
39 //=================================================================================================
40 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
41                                             const std::shared_ptr<GeomAPI_Shape> theItem)
42 {
43   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
44   const TopoDS_Shape& anItem = theItem->impl<TopoDS_Shape>();
45   if(MY_MAP->IsBound(aKey)) {
46     return MY_MAP->ChangeFind(aKey).Add(anItem) == Standard_True;
47   } else {
48     NCollection_Map<TopoDS_Shape> anItems;
49     anItems.Add(anItem);
50     return MY_MAP->Bind(aKey, anItems) == Standard_True;
51   }
52 }
53
54 //=================================================================================================
55 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
56 {
57   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
58   return MY_MAP->IsBound(aKey) == Standard_True;
59 }
60
61 //=================================================================================================
62 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
63                                              ListOfShape& theItems) const
64 {
65   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
66
67   if(MY_MAP->IsBound(aKey) == Standard_False) {
68     return false;
69   }
70
71   const NCollection_Map<TopoDS_Shape>& aMap = MY_MAP->Find(aKey);
72   for(NCollection_Map<TopoDS_Shape>::Iterator anIt(aMap); anIt.More(); anIt.Next()) {
73     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
74     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
75     theItems.push_back(aShape);
76   }
77
78   return true;
79 }
80
81 //=================================================================================================
82 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
83 {
84   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
85   return MY_MAP->UnBind(aKey) == Standard_True;
86 }
87
88 //=================================================================================================
89 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
90 {
91   return MY_MAP->Size();
92 }