-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_device.cpp
52 lines (41 loc) · 1.49 KB
/
source_device.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
#include "device.h"
std::string SourceDevice::name(void) {
return "Source";
}
Rgb SourceDevice::color = Rgb(0xff, 0xff, 0xff);
Device *SourceDevice::create(void) {
return new SourceDevice();
}
bool SourceDevice::parse(AspngSurface *surface, Coord coord) {
this->patch = this->flood(surface, coord, SourceDevice::color);
return this->patch.size() == 1;
}
std::list<Patch *> SourceDevice::all_patches(void) {
std::list<Patch *> all_patches;
all_patches.push_back(&(this->patch));
return all_patches;
}
std::tuple<LinkResult, PortType, std::string> SourceDevice::prelink(Patch *, std::shared_ptr<Device> d) {
if (std::dynamic_pointer_cast<CopperDevice>(d))
return std::make_tuple(CanLink, NoSpecialMeaning, "");
if (std::dynamic_pointer_cast<BackgroundDevice>(d))
return std::make_tuple(CanTouch, NoSpecialMeaning, "");
return std::make_tuple(LinkError, NoSpecialMeaning, "must touch copper or background");
}
bool SourceDevice::link(void) {
return true;
}
std::list<std::shared_ptr<Port>> SourceDevice::propagate(std::shared_ptr<Port> port) {
std::list<std::shared_ptr<Port>> next_ports = this->all_ports();
next_ports.remove(port);
return next_ports;
}
ElectricalValue SourceDevice::get_value_at_port(std::shared_ptr<Port>) {
return HiElectricalValue;
}
void SourceDevice::apply_new_value(std::shared_ptr<Port>, ElectricalValue) {
// Deliberately empty.
}
Rgb SourceDevice::get_draw_color(Patch *) {
return SourceDevice::color;
}