-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic_block.cpp
111 lines (89 loc) · 3.15 KB
/
logic_block.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
#include "logic_block.h"
#include <exception>
float LogicBlock::block_draw_width;
const float LogicBlock::MIN_DRAW_WIDTH = 100;
LogicBlock::LogicBlock(int x_index, int y_index)
{
if (SegChannel::NUM_SEGMENTS == -1) throw exception("Initialize NUM_SEGMENTS before creating LogicBlocks");
this->x_index = x_index;
this->y_index = y_index;
this->channels = new SegChannel*[4];
}
void LogicBlock::addChannel(int direction, SegChannel* channel)
{
if (direction < 0 || direction > 3) throw std::exception("received out of bounds direction");
this->channels[direction] = channel;
}
SegChannel * LogicBlock::getTopCh()
{
return this->channels[LogicBlock::UP];
}
SegChannel * LogicBlock::getRightCh()
{
return this->channels[LogicBlock::RIGHT];
}
SegChannel * LogicBlock::getBottomCh()
{
return this->channels[LogicBlock::DOWN];
}
SegChannel * LogicBlock::getLeftCh()
{
return this->channels[LogicBlock::LEFT];
}
void LogicBlock::draw()
{
setcolor(LIGHTGREY);
float x_offset = this->x_index * (2 * LogicBlock::block_draw_width);
float y_offset = this->y_index * (2 * LogicBlock::block_draw_width);
fillrect(x_offset, y_offset, x_offset + LogicBlock::block_draw_width, y_offset + LogicBlock::block_draw_width);
setcolor(BLACK);
setlinestyle(SOLID);
string coords = to_string(this->x_index + 1) + " : " + to_string(this->y_index + 1);
drawtext(x_offset + (LogicBlock::block_draw_width / 2), y_offset + (LogicBlock::block_draw_width / 2), coords.c_str(), INT_MAX);
setcolor(DARKGREY);
drawrect(x_offset, y_offset, x_offset + LogicBlock::block_draw_width, y_offset + LogicBlock::block_draw_width);
for (int i = 0; i < 4; i++) {
if (this->pin_nets[i] != -1) {
int seg_i;
segment* seg = NULL;
for (int j = 0; j < this->channels[i]->segments.size(); j++) {
segment* s = this->channels[i]->segments[j];
if (s->net == this->pin_nets[i]) {
seg_i = j;
seg = s;
}
}
int seg_offset = this->channels[i]->getSegmentOffset(seg_i);
setlinestyle(SOLID);
setlinewidth(SegChannel::s_width);
setcolor((seg->net % 7) + 4);
if (i == LogicBlock::UP) {
drawline(
x_offset + (LogicBlock::block_draw_width / 3), y_offset + LogicBlock::block_draw_width,
x_offset + (LogicBlock::block_draw_width / 3), y_offset + LogicBlock::block_draw_width + seg_offset
);
}
else if (i == LogicBlock::DOWN) {
drawline(
x_offset + (2 * LogicBlock::block_draw_width / 3), y_offset,
x_offset + (2 * LogicBlock::block_draw_width / 3), y_offset - LogicBlock::block_draw_width + seg_offset
);
}
else if (i == LogicBlock::RIGHT) {
drawline(
x_offset + LogicBlock::block_draw_width, y_offset + (2 * LogicBlock::block_draw_width / 3),
x_offset + LogicBlock::block_draw_width + seg_offset, y_offset + (2 * LogicBlock::block_draw_width / 3)
);
}
else if (i == LogicBlock::LEFT) {
drawline(
x_offset, y_offset + (LogicBlock::block_draw_width / 3),
x_offset - LogicBlock::block_draw_width + seg_offset, y_offset + (LogicBlock::block_draw_width / 3)
);
}
}
}
}
LogicBlock::~LogicBlock()
{
}