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 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);
30 NCollection_Map<TopoDS_Shape> anItems;
32 MY_MAP->Bind(aKey, anItems);
39 //=================================================================================================
40 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
41 const std::shared_ptr<GeomAPI_Shape> theItem)
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;
48 NCollection_Map<TopoDS_Shape> anItems;
50 return MY_MAP->Bind(aKey, anItems) == Standard_True;
54 //=================================================================================================
55 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
57 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
58 return MY_MAP->IsBound(aKey) == Standard_True;
61 //=================================================================================================
62 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
63 ListOfShape& theItems) const
65 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
67 if(MY_MAP->IsBound(aKey) == Standard_False) {
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);
81 //=================================================================================================
82 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
84 const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
85 return MY_MAP->UnBind(aKey) == Standard_True;
88 //=================================================================================================
89 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
91 return MY_MAP->Size();