-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcb.c
64 lines (54 loc) · 2.14 KB
/
pcb.c
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
//
// SprintTrace: PCB representation
// Copyright 2022, Laminoid.com (Muessig & Muessig GbR).
// Licensed under the terms and conditions of the GPLv3.
//
#include "pcb.h"
#include "primitives.h"
#include "output.h"
#include "grid.h"
#include "elements.h"
#include "errors.h"
const char* SPRINT_PCB_FLAG_NAMES[] = {
"top fill",
"bottom fill",
"inner fill 1",
"inner fill 2",
"multilayer"
};
sprint_error sprint_pcb_flags_output(sprint_pcb_flags flags, sprint_output* output)
{
if (output == NULL) return SPRINT_ERROR_ARGUMENT_NULL;
bool first = true, found = false;
sprint_error error = SPRINT_ERROR_NONE;
for (int bit = 0; bit < sizeof(SPRINT_PCB_FLAG_NAMES) / sizeof(const char*); bit++) {
if (!((flags >> bit) & 1)) continue;
if (!first)
sprint_chain(error, sprint_output_put_chr(output, '|'));
else
first = false;
if (!sprint_chain(error, sprint_output_put_str(output, SPRINT_PCB_FLAG_NAMES[bit])))
break;
else
found |= true;
}
if (!found)
sprint_chain(error, sprint_output_put_str(output, flags == 0 ? "none" : "invalid"));
return sprint_rethrow(error);
}
sprint_error sprint_pcb_output(sprint_pcb* pcb, sprint_output* output)
{
if (pcb == NULL || output == NULL) return SPRINT_ERROR_ARGUMENT_NULL;
sprint_error error = SPRINT_ERROR_NONE;
sprint_chain(error, sprint_output_put_str(output, "sprint_pcb{width="));
sprint_chain(error, sprint_dist_output(pcb->width, output, SPRINT_PRIM_FORMAT_COOKED));
sprint_chain(error, sprint_output_put_str(output, ", height="));
sprint_chain(error, sprint_dist_output(pcb->height, output, SPRINT_PRIM_FORMAT_COOKED));
sprint_chain(error, sprint_output_put_str(output, ", grid="));
sprint_chain(error, sprint_grid_output(&pcb->grid, output));
sprint_chain(error, sprint_output_put_str(output, ", flags="));
sprint_chain(error, sprint_pcb_flags_output(pcb->flags, output));
sprint_chain(error, sprint_output_put_str(output, ", elements="));
sprint_chain(error, sprint_output_put_chr(output, '}'));
return sprint_rethrow(error);
}