Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / GeomAPI / GeomAPI_DataMapOfShapeMapOfShapes.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
21
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_Map.hxx>
24 #include <TopoDS_Shape.hxx>
25
26 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
27
28 //=================================================================================================
29 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
30 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
31 {}
32
33 //=================================================================================================
34 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
35                                              const ListOfShape& theItems)
36 {
37   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
38   if(MY_MAP->IsBound(aKey)) {
39     MY_MAP->ChangeFind(aKey).Clear();
40   }
41   for(ListOfShape::const_iterator anIt = theItems.cbegin(); anIt != theItems.cend(); anIt++) {
42     const TopoDS_Shape& anItem = (*anIt)->impl<TopoDS_Shape>();
43     if(MY_MAP->IsBound(aKey)) {
44       MY_MAP->ChangeFind(aKey).Add(anItem);
45     } else {
46       NCollection_Map<TopoDS_Shape> anItems;
47       anItems.Add(anItem);
48       MY_MAP->Bind(aKey, anItems);
49     }
50   }
51
52   return true;
53 }
54
55 //=================================================================================================
56 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
57                                             const std::shared_ptr<GeomAPI_Shape> theItem)
58 {
59   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
60   const TopoDS_Shape& anItem = theItem->impl<TopoDS_Shape>();
61   if(MY_MAP->IsBound(aKey)) {
62     return MY_MAP->ChangeFind(aKey).Add(anItem) == Standard_True;
63   } else {
64     NCollection_Map<TopoDS_Shape> anItems;
65     anItems.Add(anItem);
66     return MY_MAP->Bind(aKey, anItems) == Standard_True;
67   }
68 }
69
70 //=================================================================================================
71 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
72 {
73   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
74   return MY_MAP->IsBound(aKey) == Standard_True;
75 }
76
77 //=================================================================================================
78 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
79                                              ListOfShape& theItems) const
80 {
81   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
82
83   if(MY_MAP->IsBound(aKey) == Standard_False) {
84     return false;
85   }
86
87   const NCollection_Map<TopoDS_Shape>& aMap = MY_MAP->Find(aKey);
88   for(NCollection_Map<TopoDS_Shape>::Iterator anIt(aMap); anIt.More(); anIt.Next()) {
89     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
90     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
91     theItems.push_back(aShape);
92   }
93
94   return true;
95 }
96
97 //=================================================================================================
98 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
99 {
100   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
101   return MY_MAP->UnBind(aKey) == Standard_True;
102 }
103
104 //=================================================================================================
105 void GeomAPI_DataMapOfShapeMapOfShapes::clear()
106 {
107   return MY_MAP->Clear();
108 }
109
110 //=================================================================================================
111 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
112 {
113   return MY_MAP->Size();
114 }