Ophidian
 All Classes Namespaces Functions
floorplan.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef ophidian_FLOORPLAN_H
22 #define ophidian_FLOORPLAN_H
23 
24 #include <boost/geometry/index/rtree.hpp>
25 #include <entity_system.h>
26 #include "rows.h"
27 #include "sites.h"
28 #include <unordered_map>
29 
30 namespace ophidian {
32  namespace floorplan {
34 
37  class floorplan {
38  using point = geometry::point<double>;
39  using box = geometry::box<point>;
40  using rtree_node = std::pair<box, entity_system::entity>;
41  using rtree = boost::geometry::index::rtree<rtree_node, boost::geometry::index::rstar<16>>;
42 
43  entity_system::entity_system m_sites_system;
44  entity_system::entity_system m_rows_system;
45 
46  sites m_sites;
47  rows m_rows;
48 
49  point m_chip_origin;
50  point m_chip_boundaries;
51 
52  std::unordered_map<std::string, entity_system::entity> m_name2site;
53  rtree m_rows_rtree;
54 
55  public:
56  floorplan();
57 
58  point chip_origin() const {
59  return m_chip_origin;
60  }
61  void chip_origin(point chip_origin);
63 
67  point chip_boundaries() const {
68  return m_chip_boundaries;
69  }
70  void chip_boundaries(point chip_boundaries);
71 
72  // sites
74 
80  entity_system::entity site_insert(std::string name, point dimensions);
82 
86  void site_destroy(entity_system::entity site);
87 
89 
93  std::size_t site_count() const {
94  return m_sites_system.size();
95  }
96 
98 
103  std::string site_name(entity_system::entity site) const {
104  return m_sites.name(site);
105  }
107 
112  point site_dimensions(entity_system::entity site) const {
113  return m_sites.dimensions(site);
114  }
116 
120  const sites & sites_properties() const {
121  return m_sites;
122  }
123 
124  // rows
126 
133  entity_system::entity row_insert(entity_system::entity site, unsigned number_of_sites, point origin);
134  entity_system::entity row_insert(std::string site, unsigned number_of_sites, point origin);
135 
137 
141  void row_destroy(entity_system::entity row);
142 
144 
149  entity_system::entity find_row(point point);
150 
152 
157  entity_system::entity find_closest_row(point point);
158 
160 
164  std::size_t row_count() const {
165  return m_rows_system.size();
166  }
167 
169 
174  entity_system::entity row_site(entity_system::entity row) const {
175  return m_rows.site(row);
176  }
178 
183  unsigned row_number_of_sites(entity_system::entity row) const {
184  return m_rows.number_of_sites(row);
185  }
187 
192  point row_origin(entity_system::entity row) const {
193  return m_rows.origin(row);
194  }
196 
201  point row_dimensions(entity_system::entity row) const;
203 
207  const rows & rows_properties() const {
208  return m_rows;
209  }
210 
211  const entity_system::entity_system & rows_system() const {
212  return m_rows_system;
213  };
214  };
215 
216  class row_not_found : public std::exception {
217  public:
218  const char * what() const throw() {
219  return "No row found in the given coordinate";
220  }
221  };
222  }
223 }
224 
225 
226 
227 #endif //ophidian_FLOORPLAN_H
const sites & sites_properties() const
Sites properties getter.
Definition: floorplan.h:120
point dimensions(entity_system::entity site) const
Dimensions getter.
Definition: sites.h:66
unsigned number_of_sites(entity_system::entity row) const
Number of sites getter.
Definition: rows.h:66
void row_destroy(entity_system::entity row)
Destroys a row.
Definition: floorplan.cpp:64
entity_system::entity row_insert(entity_system::entity site, unsigned number_of_sites, point origin)
Inserts a new row.
Definition: floorplan.cpp:52
std::size_t site_count() const
Returns the number of sites.
Definition: floorplan.h:93
std::string name(entity_system::entity site) const
Name getter.
Definition: sites.h:56
point chip_boundaries() const
Chip boundaries getter.
Definition: floorplan.h:67
std::string site_name(entity_system::entity site) const
Site name getter.
Definition: floorplan.h:103
const rows & rows_properties() const
Rows properties getter.
Definition: floorplan.h:207
Rows class.
Definition: rows.h:34
Definition: floorplan.h:216
void site_destroy(entity_system::entity site)
Destroys a site.
Definition: floorplan.cpp:43
Sites class.
Definition: sites.h:34
point site_dimensions(entity_system::entity site) const
Site dimensions getter.
Definition: floorplan.h:112
point row_origin(entity_system::entity row) const
Row origin getter.
Definition: floorplan.h:192
entity_system::entity site_insert(std::string name, point dimensions)
Inserts a new site.
Definition: floorplan.cpp:31
std::size_t row_count() const
Returns the number of rows.
Definition: floorplan.h:164
entity_system::entity find_row(point point)
Finds a row.
Definition: floorplan.cpp:72
entity_system::entity row_site(entity_system::entity row) const
Row site getter.
Definition: floorplan.h:174
point row_dimensions(entity_system::entity row) const
Row dimensions getter.
Definition: floorplan.cpp:91
point origin(entity_system::entity row) const
Row origin getter.
Definition: rows.h:75
entity_system::entity site(entity_system::entity row) const
Site getter.
Definition: rows.h:57
entity_system class.
Definition: entity_system.h:40
entity_system::entity find_closest_row(point point)
Finds closest row to a point.
Definition: floorplan.cpp:83
std::size_t size() const
Returns the size of the system.
Definition: entity_system.h:82
Floorplan class.
Definition: floorplan.h:37
unsigned row_number_of_sites(entity_system::entity row) const
Row number of sites getter.
Definition: floorplan.h:183