Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. Correction of circle...
[modules/shaper.git] / src / GeomAPI / GeomAPI_DataMapOfShapeMapOfShapes.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_DataMapOfShapeMapOfShapes.cpp
4 // Created:     4 September 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomAPI_DataMapOfShapeMapOfShapes.h>
8
9 #include <NCollection_DataMap.hxx>
10 #include <NCollection_Map.hxx>
11 #include <TopoDS_Shape.hxx>
12
13 #define MY_MAP implPtr<NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> > >()
14
15 //=================================================================================================
16 GeomAPI_DataMapOfShapeMapOfShapes::GeomAPI_DataMapOfShapeMapOfShapes()
17 : GeomAPI_Interface(new NCollection_DataMap<TopoDS_Shape, NCollection_Map<TopoDS_Shape> >)
18 {}
19
20 //=================================================================================================
21 bool GeomAPI_DataMapOfShapeMapOfShapes::bind(const std::shared_ptr<GeomAPI_Shape> theKey,
22                                              const ListOfShape& theItems)
23 {
24   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
25   if(MY_MAP->IsBound(aKey)) {
26     MY_MAP->ChangeFind(aKey).Clear();
27   }
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);
32     } else {
33       NCollection_Map<TopoDS_Shape> anItems;
34       anItems.Add(anItem);
35       MY_MAP->Bind(aKey, anItems);
36     }
37   }
38
39   return true;
40 }
41
42 //=================================================================================================
43 bool GeomAPI_DataMapOfShapeMapOfShapes::add(const std::shared_ptr<GeomAPI_Shape> theKey,
44                                             const std::shared_ptr<GeomAPI_Shape> theItem)
45 {
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;
50   } else {
51     NCollection_Map<TopoDS_Shape> anItems;
52     anItems.Add(anItem);
53     return MY_MAP->Bind(aKey, anItems) == Standard_True;
54   }
55 }
56
57 //=================================================================================================
58 bool GeomAPI_DataMapOfShapeMapOfShapes::isBound(const std::shared_ptr<GeomAPI_Shape> theKey) const
59 {
60   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
61   return MY_MAP->IsBound(aKey) == Standard_True;
62 }
63
64 //=================================================================================================
65 bool GeomAPI_DataMapOfShapeMapOfShapes::find(const std::shared_ptr<GeomAPI_Shape> theKey,
66                                              ListOfShape& theItems) const
67 {
68   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
69
70   if(MY_MAP->IsBound(aKey) == Standard_False) {
71     return false;
72   }
73
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);
79   }
80
81   return true;
82 }
83
84 //=================================================================================================
85 bool GeomAPI_DataMapOfShapeMapOfShapes::unBind(const std::shared_ptr<GeomAPI_Shape> theKey)
86 {
87   const TopoDS_Shape& aKey = theKey->impl<TopoDS_Shape>();
88   return MY_MAP->UnBind(aKey) == Standard_True;
89 }
90
91 //=================================================================================================
92 void GeomAPI_DataMapOfShapeMapOfShapes::clear()
93 {
94   return MY_MAP->Clear();
95 }
96
97 //=================================================================================================
98 int GeomAPI_DataMapOfShapeMapOfShapes::size() const
99 {
100   return MY_MAP->Size();
101 }