-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlabgen-module-make-production
executable file
·173 lines (126 loc) · 4.06 KB
/
mlabgen-module-make-production
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
import pcbnew
from pcbnew import FromMM, wxPoint
from pcbnew import PLOT_FORMAT_GERBER, PLOT_FORMAT_SVG, PLOT_FORMAT_PDF, PLOT_CONTROLLER, EXCELLON_WRITER
from pcbnew import F_Cu, B_Cu, B_SilkS, F_SilkS, B_Mask, F_Mask, Edge_Cuts, B_Paste, F_Paste
import mlabgen
import kicad_netlist_reader
import csv
import sys
import sqlite3
import numpy as np
import csv, json
## Pouze pro vyvoj!!!!!
#os.chdir("/home/roman/repos/Modules/sensors/LIGHTNING01A/")
localpath = os.getcwd()
rootpath, project = os.path.split(localpath)
if not os.path.exists('doc/src/'): # create the build directory if not existing
os.makedirs('doc/src')
filename= os.path.join(localpath, 'hw', 'sch_pcb', project+'.kicad_pcb')
print("soucastna cesta:", localpath)
print("Soubor projektu:", filename)
plotDir = "../cam_profi/"
board = pcbnew.LoadBoard(filename)
pctl = pcbnew.PLOT_CONTROLLER(board)
popt = pctl.GetPlotOptions()
popt.SetOutputDirectory(plotDir)
popt.SetPlotFrameRef(False)
popt.SetLineWidth(FromMM(0.35))
popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
popt.SetUseGerberAttributes(True)
popt.SetUseGerberProtelExtensions(False)
popt.SetExcludeEdgeLayer(True);
popt.SetScale(1)
popt.SetUseAuxOrigin(True)
popt.SetSubtractMaskFromSilk(False)
plot_plan = [
( "F.Cu", F_Cu, "Top layer" ),
( "B.Cu", B_Cu, "Bottom layer" ),
( "F.SilkS", F_SilkS, "Silk top" ),
( "B.Mask", B_Mask, "Mask bottom" ),
( "F.Mask", F_Mask, "Mask top" ),
( "Edge.Cuts", Edge_Cuts, "Edges" ),
]
print("zacatek generovani")
for layer_info in plot_plan:
pctl.SetLayer(layer_info[1])
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
pctl.PlotLayer()
drlwriter = EXCELLON_WRITER( board )
drlwriter.SetMapFileFormat( PLOT_FORMAT_GERBER )
mirror = False
minimalHeader = False
offset = wxPoint(0,0)
mergeNPTH = False
drlwriter.SetOptions( mirror, minimalHeader, offset, mergeNPTH)
metricFmt = True
drlwriter.SetFormat( metricFmt )
genDrl = True
genMap = False
drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap );
popt = pctl.GetPlotOptions()
popt.SetOutputDirectory("../../doc/src/")
popt.SetPlotFrameRef(False)
popt.SetLineWidth(FromMM(0.2))
popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
popt.SetUseGerberAttributes(True)
popt.SetExcludeEdgeLayer(False);
popt.SetUseAuxOrigin(False)
popt.SetSubtractMaskFromSilk(False)
pctl.OpenPlotfile("top", PLOT_FORMAT_PDF, "MLAB A")
pctl.SetLayer(F_SilkS)
pctl.PlotLayer()
#pctl.SetLayer(F_Mask)
#pctl.PlotLayer()
popt.SetMirror(True)
pctl.OpenPlotfile("bottom", PLOT_FORMAT_PDF, "MLAB A")
pctl.SetLayer(B_SilkS)
pctl.PlotLayer()
pctl.ClosePlot()
'''
filename= os.path.join(localpath, 'hw', 'sch_pcb', project+'.sch')
sch = open(filename, 'r').read()
sch_parts = sch.split("$")
comp = {}
for area in sch_parts:
#print(area)
if area[:4] == 'Comp':
lines = area.split('\n')
print(lines)
compo=lines[1].split(" ")[1]
label=lines[1].split(" ")[2]
value=lines[5].split('"')[1]
packa=lines[6].split('"')[1]
if '#' not in label:
print(label)
try:
packa = packa.split(":")[1]
except Exception as e:
pass
if not compo in comp:
comp[compo] = {}
if not packa in comp[compo]:
comp[compo][packa] = {}
if not value in comp[compo][packa]:
comp[compo][packa][value] = []
comp[compo][packa][value] += [label]
import csv
with open('hw/bom_base.csv', "wb") as csv_file:
writer = csv.writer(csv_file, delimiter=';')
for c in comp:
for p in comp[c]:
for v in comp[c][p]:
print(c, p, v, comp[c][p][v])
writer.writerow([c, p, v, comp[c][p][v]])
'''
filename= os.path.join(localpath, 'hw', 'sch_pcb', project+'.sch')
filenout= os.path.join(localpath, 'hw', 'sch_pcb', project+'.bom_ust')
bom = mlabgen.BOM_ust(filename, filenout)