-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathgrouping.cpp
329 lines (270 loc) · 7.51 KB
/
grouping.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#include "hal_core/netlist/grouping.h"
#include "hal_core/netlist/event_system/event_handler.h"
#include "hal_core/netlist/gate.h"
#include "hal_core/netlist/module.h"
#include "hal_core/netlist/net.h"
#include "hal_core/netlist/netlist.h"
#include "hal_core/utilities/log.h"
namespace hal
{
Grouping::Grouping(NetlistInternalManager* internal_manager, EventHandler* event_handler, u32 id, std::string name)
{
m_id = id;
m_name = name;
m_color = next_color();
m_internal_manager = internal_manager;
m_event_handler = event_handler;
}
u32 Grouping::get_id() const
{
return m_id;
}
void Grouping::set_name(std::string name)
{
if (utils::trim(name).empty())
{
log_error("grouping", "grouping name cannot be empty.");
return;
}
if (name != m_name)
{
m_name = name;
m_event_handler->notify(GroupingEvent::event::name_changed, this);
}
}
std::string Grouping::get_name() const
{
return m_name;
}
utils::Color Grouping::get_color() const
{
return m_color;
}
void Grouping::set_color(utils::Color c)
{
m_color = c;
m_event_handler->notify(GroupingEvent::event::color_changed, this);
}
utils::Color Grouping::next_color()
{
int baseCol = (get_id() - 1) * 37;
return utils::Color(baseCol % 255, 200, std::max(250 - baseCol / 255 * 50, 50));
}
Netlist* Grouping::get_netlist() const
{
return m_internal_manager->m_netlist;
}
bool Grouping::assign_gate(Gate* gate, bool force)
{
return m_internal_manager->grouping_assign_gate(this, gate, force);
}
bool Grouping::assign_gate_by_id(const u32 gate_id, bool force)
{
Gate* gate = m_internal_manager->m_netlist->get_gate_by_id(gate_id);
if (gate == nullptr)
{
return false;
}
return assign_gate(gate, force);
}
const std::vector<Gate*>& Grouping::get_gates() const
{
return m_gates;
}
std::vector<Gate*> Grouping::get_gates(const std::function<bool(Gate*)>& filter) const
{
std::vector<Gate*> res;
if (!filter)
{
res = m_gates;
}
else
{
for (Gate* gate : m_gates)
{
if (!filter(gate))
{
continue;
}
res.push_back(gate);
}
}
return res;
}
std::vector<u32> Grouping::get_gate_ids(const std::function<bool(Gate*)>& filter) const
{
std::vector<u32> gate_ids;
for (const Gate* const gate : get_gates(filter))
{
gate_ids.push_back(gate->get_id());
}
return gate_ids;
}
bool Grouping::remove_gate(Gate* gate)
{
return m_internal_manager->grouping_remove_gate(this, gate);
}
bool Grouping::remove_gate_by_id(const u32 gate_id)
{
Gate* gate = m_internal_manager->m_netlist->get_gate_by_id(gate_id);
if (gate == nullptr)
{
return false;
}
return remove_gate(gate);
}
bool Grouping::contains_gate(Gate* gate) const
{
if (gate == nullptr)
{
return false;
}
return contains_gate_by_id(gate->get_id());
}
bool Grouping::contains_gate_by_id(const u32 gate_id) const
{
return m_gates_map.find(gate_id) != m_gates_map.end();
}
bool Grouping::assign_net(Net* net, bool force)
{
return m_internal_manager->grouping_assign_net(this, net, force);
}
bool Grouping::assign_net_by_id(const u32 net_id, bool force)
{
Net* net = m_internal_manager->m_netlist->get_net_by_id(net_id);
if (net == nullptr)
{
return false;
}
return assign_net(net, force);
}
const std::vector<Net*>& Grouping::get_nets() const
{
return m_nets;
}
std::vector<Net*> Grouping::get_nets(const std::function<bool(Net*)>& filter) const
{
std::vector<Net*> res;
if (!filter)
{
res = m_nets;
}
else
{
for (Net* net : m_nets)
{
if (!filter(net))
{
continue;
}
res.push_back(net);
}
}
return res;
}
std::vector<u32> Grouping::get_net_ids(const std::function<bool(Net*)>& filter) const
{
std::vector<u32> net_ids;
for (const Net* const net : get_nets(filter))
{
net_ids.push_back(net->get_id());
}
return net_ids;
}
bool Grouping::remove_net(Net* net)
{
return m_internal_manager->grouping_remove_net(this, net);
}
bool Grouping::remove_net_by_id(const u32 net_id)
{
Net* net = m_internal_manager->m_netlist->get_net_by_id(net_id);
if (net == nullptr)
{
return false;
}
return remove_net(net);
}
bool Grouping::contains_net(Net* net) const
{
if (net == nullptr)
{
return false;
}
return contains_net_by_id(net->get_id());
}
bool Grouping::contains_net_by_id(const u32 net_id) const
{
return m_nets_map.find(net_id) != m_nets_map.end();
}
bool Grouping::assign_module(Module* module, bool force)
{
return m_internal_manager->grouping_assign_module(this, module, force);
}
bool Grouping::assign_module_by_id(const u32 module_id, bool force)
{
Module* module = m_internal_manager->m_netlist->get_module_by_id(module_id);
if (module == nullptr)
{
return false;
}
return assign_module(module, force);
}
const std::vector<Module*>& Grouping::get_modules() const
{
return m_modules;
}
std::vector<Module*> Grouping::get_modules(const std::function<bool(Module*)>& filter) const
{
std::vector<Module*> res;
if (!filter)
{
res = m_modules;
}
else
{
for (Module* module : m_modules)
{
if (!filter(module))
{
continue;
}
res.push_back(module);
}
}
return res;
}
std::vector<u32> Grouping::get_module_ids(const std::function<bool(Module*)>& filter) const
{
std::vector<u32> module_ids;
for (const Module* const module : get_modules(filter))
{
module_ids.push_back(module->get_id());
}
return module_ids;
}
bool Grouping::remove_module(Module* module)
{
return m_internal_manager->grouping_remove_module(this, module);
}
bool Grouping::remove_module_by_id(const u32 module_id)
{
Module* module = m_internal_manager->m_netlist->get_module_by_id(module_id);
if (module == nullptr)
{
return false;
}
return remove_module(module);
}
bool Grouping::contains_module(Module* module) const
{
if (module == nullptr)
{
return false;
}
return contains_module_by_id(module->get_id());
}
bool Grouping::contains_module_by_id(const u32 module_id) const
{
return m_modules_map.find(module_id) != m_modules_map.end();
}
} // namespace hal