-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.py
More file actions
136 lines (117 loc) · 4.35 KB
/
Copy pathloader.py
File metadata and controls
136 lines (117 loc) · 4.35 KB
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
import json
from typing import Any, Dict, List
from pathlib import Path
class Loader:
"""
Handles loading data from JSON sent from MakeDevice
"""
def __init__(self, file_path: Path):
"""Initialize with a path to project file"""
self.file_path = file_path
self.data: Dict[str, Any] = {}
# TODO: not sure where this property is used, everything by default is from server, so will set to True
self.run_from_server = True # TODO: find out where this is necessary
# TODO: Default values, originally included in the legacy JSON format - move them into a separate place later
self.generation_software = {
"vendor": "Devices-Lab",
"application": "MakeDevice",
"version": "0.3"
}
self.origin = {'x': 0, 'y': 0}
self.debug = False
self.resolution = 0.25
self.allow_diagonal_traces = True
self.allow_overlap = False
self.algorithm = "a_star"
self.gerbersockets_layer_name = "GerberSockets.gbr"
self.layer_map = {
"F_Cu.gtl": {
"nets": [],
"fill": False,
"attributes": "Copper,L1,Top,Signal"
},
# "In1_Cu.g2": {
# "nets": [],
# "fill": False,
# "attributes": "Copper,L2,Inner,Signal"
# },
# "In2_Cu.g3": {
# "nets": [],
# "fill": False,
# "attributes": "Copper,L3,Inner,Signal"
# },
"B_Cu.gbl": {
"nets": [
"SWDIO~",
"SWDIO~^"
],
"fill": False,
"attributes": "Copper,L4,Bottom,Signal"
}
}
self.module_margin = 0
self.bus_width = 0.25
self.bus_spacing = 0.5
self.edge_clearance = 0.5
self.track_width = 0.125
self.via_diameter = 0.4
self.via_hole_diameter = 0.3
self._load()
def _load(self) -> None:
"""Load JSON data"""
try:
with open(self.file_path, 'r') as file:
self.data = json.load(file)
except FileNotFoundError:
raise FileNotFoundError(f"🔴 Project file could not be found: {self.file_path}")
except json.JSONDecodeError:
raise ValueError(f"🔴 File {self.file_path} is not a valid JSON (.MakeDevice file)")
# -------------------- PROJECT DATA (from main JSON) --------------------------
@property
def id(self) -> str:
"""Get the project ID"""
return self.data.get('id', '')
@property
def name(self) -> str:
"""Get the project name"""
return self.data.get('name', '')
@property
def size(self) -> Dict[str, float]:
"""Get the board size"""
return self.data.get('size', {})
@property
def width(self) -> float:
"""Get the board width"""
return self.data.get('size', {}).get('width', 0)
@property
def height(self) -> float:
"""Get the board height"""
return self.data.get('size', {}).get('height', 0)
@property
def fabrication_house(self) -> str:
"""Get fabrication house"""
return self.data.get('pcbOptions', {}).get('fabricationHouse', '')
@property
def rounded_corner_radius(self) -> float:
"""Get corner radius"""
return self.data.get('pcbOptions', {}).get('cornerRadius', 0)
@property
def connectors(self) -> Dict[str, bool]:
"""Get connector settings"""
return self.data.get('pcbOptions', {}).get('connectors', {})
@property
def connector_top(self) -> bool:
"""Get whether top connector is enabled"""
return bool(self.data.get('pcbOptions', {}).get('connectors', {}).get('top', False))
@property
def connector_bottom(self) -> bool:
"""Get whether bottom connector is enabled"""
return bool(self.data.get('pcbOptions', {}).get('connectors', {}).get('bottom', False))
@property
def modules(self) -> List[Dict[str, Any]]:
"""Get modules list"""
return self.data.get('modules', [])
@property
def graphics_svg(self) -> str:
"""Get composite graphics SVG used for silkscreen rendering"""
return self.data.get('graphicsSvg', '')