1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_Map.hxx>
24 #include <TopoDS_Shape.hxx>
26 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
28 //=================================================================================================
29 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
30 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
33 //=================================================================================================
34 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
35 const ListOfShape& theItems)
37 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
38 if(MY_MAP->IsBound(aKey)) {
39 MY_MAP->ChangeFind(aKey).Clear();
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);
46 NCollection_Map<TopoDS_Shape> anItems;
48 MY_MAP->Bind(aKey, anItems);
55 //=================================================================================================
56 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
57 const std::shared_ptr<GeomAPI_Shape> theItem)
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;
64 NCollection_Map<TopoDS_Shape> anItems;
66 return MY_MAP->Bind(aKey, anItems) == Standard_True;
70 //=================================================================================================
71 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
73 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
74 return MY_MAP->IsBound(aKey) == Standard_True;
77 //=================================================================================================
78 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
79 ListOfShape& theItems) const
81 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
83 if(MY_MAP->IsBound(aKey) == Standard_False) {
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);
97 //=================================================================================================
98 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
100 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
101 return MY_MAP->UnBind(aKey) == Standard_True;
104 //=================================================================================================
105 void GeomAPI_DataMapOfShapeMapOfShapes::clear()
107 return MY_MAP->Clear();
110 //=================================================================================================
111 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
113 return MY_MAP->Size();