1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_DataMapOfShapeMapOfShapes.cpp
4 // Created: 4 September 2015
5 // Author: Dmitry Bobylev
7 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
9 #include <NCollection_DataMap.hxx>
10 #include <NCollection_Map.hxx>
11 #include <TopoDS_Shape.hxx>
13 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
15 //=================================================================================================
16 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
17 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
20 //=================================================================================================
21 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
22 const ListOfShape& theItems)
24 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
25 if(MY_MAP->IsBound(aKey)) {
26 MY_MAP->ChangeFind(aKey).Clear();
28 for(ListOfShape::const_iterator anIt = theItems.cbegin(); anIt != theItems.cend(); anIt++) {
29 const TopoDS_Shape& anItem = (*anIt)->impl<TopoDS_Shape>();
30 if(MY_MAP->IsBound(aKey)) {
31 MY_MAP->ChangeFind(aKey).Add(anItem);
33 NCollection_Map<TopoDS_Shape> anItems;
35 MY_MAP->Bind(aKey, anItems);
42 //=================================================================================================
43 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
44 const std::shared_ptr<GeomAPI_Shape> theItem)
46 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
47 const TopoDS_Shape& anItem = theItem->impl<TopoDS_Shape>();
48 if(MY_MAP->IsBound(aKey)) {
49 return MY_MAP->ChangeFind(aKey).Add(anItem) == Standard_True;
51 NCollection_Map<TopoDS_Shape> anItems;
53 return MY_MAP->Bind(aKey, anItems) == Standard_True;
57 //=================================================================================================
58 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
60 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
61 return MY_MAP->IsBound(aKey) == Standard_True;
64 //=================================================================================================
65 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
66 ListOfShape& theItems) const
68 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
70 if(MY_MAP->IsBound(aKey) == Standard_False) {
74 const NCollection_Map<TopoDS_Shape>& aMap = MY_MAP->Find(aKey);
75 for(NCollection_Map<TopoDS_Shape>::Iterator anIt(aMap); anIt.More(); anIt.Next()) {
76 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
77 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
78 theItems.push_back(aShape);
84 //=================================================================================================
85 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
87 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
88 return MY_MAP->UnBind(aKey) == Standard_True;
91 //=================================================================================================
92 void GeomAPI_DataMapOfShapeMapOfShapes::clear()
94 return MY_MAP->Clear();
97 //=================================================================================================
98 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
100 return MY_MAP->Size();