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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
23 #include <NCollection_DataMap.hxx>
24 #include <NCollection_Map.hxx>
25 #include <TopoDS_Shape.hxx>
27 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
29 //=================================================================================================
30 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
31 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
34 //=================================================================================================
35 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
36 const ListOfShape& theItems)
38 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
39 if(MY_MAP->IsBound(aKey)) {
40 MY_MAP->ChangeFind(aKey).Clear();
42 for(ListOfShape::const_iterator anIt = theItems.cbegin(); anIt != theItems.cend(); anIt++) {
43 const TopoDS_Shape& anItem = (*anIt)->impl<TopoDS_Shape>();
44 if(MY_MAP->IsBound(aKey)) {
45 MY_MAP->ChangeFind(aKey).Add(anItem);
47 NCollection_Map<TopoDS_Shape> anItems;
49 MY_MAP->Bind(aKey, anItems);
56 //=================================================================================================
57 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
58 const std::shared_ptr<GeomAPI_Shape> theItem)
60 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
61 const TopoDS_Shape& anItem = theItem->impl<TopoDS_Shape>();
62 if(MY_MAP->IsBound(aKey)) {
63 return MY_MAP->ChangeFind(aKey).Add(anItem) == Standard_True;
65 NCollection_Map<TopoDS_Shape> anItems;
67 return MY_MAP->Bind(aKey, anItems) == Standard_True;
71 //=================================================================================================
72 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
74 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
75 return MY_MAP->IsBound(aKey) == Standard_True;
78 //=================================================================================================
79 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
80 ListOfShape& theItems) const
82 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
84 if(MY_MAP->IsBound(aKey) == Standard_False) {
88 const NCollection_Map<TopoDS_Shape>& aMap = MY_MAP->Find(aKey);
89 for(NCollection_Map<TopoDS_Shape>::Iterator anIt(aMap); anIt.More(); anIt.Next()) {
90 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
91 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
92 theItems.push_back(aShape);
98 //=================================================================================================
99 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
101 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
102 return MY_MAP->UnBind(aKey) == Standard_True;
105 //=================================================================================================
106 void GeomAPI_DataMapOfShapeMapOfShapes::clear()
108 return MY_MAP->Clear();
111 //=================================================================================================
112 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
114 return MY_MAP->Size();