Skip to content
Snippets Groups Projects
Commit b935307e authored by Jingyan Ling's avatar Jingyan Ling
Browse files

update dsnwritter, journal

parent ce7e9001
Branches
No related merge requests found
Showing
with 7247 additions and 78 deletions
......@@ -441,4 +441,45 @@
| | |-- ...
| |--wiring
| | |--wire
~~~
\ No newline at end of file
~~~
### 07/29/2019
- Was working on 'dsn_python' Python Library.
- Class tree:
~~~
|--dsnwritter.py (top and second level structure)
|--dsn_module.py
|--module class
|--load module functions
|--dsn_rule.py
|--dsn_geo.py
|--boudary class
|--keepout class
|--load drawing functions
|--dsn_net.py
|--net class
|--netclass class
|--load netlist functions
~~~
- Text tree structure is done.
- Documentation and notes for code needed
- Functions are needed to help user use library.
- Function that load `dxf` file
- Function that load `footprint` file
- Function that load `netlist` file
- For board outline/footprint/netlist not loaded from file but define through this library manually, it works very well for now.
- Pull out those information from low-level file and convert it to proper text for `dsn` file
- Record of Tips:
- `Freerouting` cannot take more than one boundary. (error: exact 1 bounding expected)
- Able to use functions to load `dxf` drawings
- "internal cut issue" solved
- Treat every line individually as polygon and labeled as keepout in `dsn` library
- ![](journal_media/keepout_load.png)
- ![](journal_media/dxf_in_freerouting.png)
- TODO: functions that load modules and footprints
This diff is collapsed.
# dsn_python
File added
File added
No preview for this file type
File added
No preview for this file type
from pykicad.sexpr import *
import numpy as np
class load_drawing():
def __init__(self,afile):
import ezdxf
self.dwg=ezdxf.readfile(afile)
self.msp=self.dwg.modelspace()
def load_all(self):
return [self.load_line,self.load_polygon]
def load_line(self):
startlist=[]
endlist=[]
line_list=[]
for e in self.msp.query('LINE'):
startlist.append(e.dxf.start[:2])
endlist.append(e.dxf.end[:2])
for i in range(len(startlist)):
line_list.append(startlist[i])
line_list.append(endlist[i])
line_list=np.array(line_list)
line_list[:,1]*=-1
line_list*=1000
line_list=line_list.flatten()
line_list=list(line_list)
return line_list
def load_polygon(self):
pts_list=[]
for e in self.msp.query('LWPOLYLINE'):
pts_list.append(np.array(e.get_points()))
for i in range(len(pts_list)):
pts_list[i]=pts_list[i][:,:2]
pts_list[i][:,1]*=-1
##Unit = um
pts_list[i]=pts_list[i]*1000
pts_list[i]=pts_list[i].flatten()
pts_list[i]=list(pts_list[i])
return pts_list
def load_line_as_polygon(self):
pts_list=self.load_polygon()
ply_list=[]
for i in range(len(pts_list)):
for j in range(len(pts_list[i])):
ply_list.append(pts_list[i][j])
return ply_list
class Boundary(AST):
tag='boundary'
schema={
'path pcb':{
'0':{
'_parser':integer,
'_attr':'brd_index'
},
'1':{
'_parser': number,
'_attr': 'path'
},
}
}
index_ctr=0
def __init__(self,path,brd_index=None):
brd_index=Boundary.index_ctr
Boundary.index_ctr+=1
super(Boundary,self).__init__(path=path,brd_index=brd_index)
class Keepout(AST):
tag='keepout'
schema={
'0':{
'0':{
'_parser':text,
'_attr':'name'
},
' ':{
'0': {
'_parser':text,
'_attr':'shape'
},
'1':{
'_parser':text,
'_attr':'typex'
},
'2':{
'_parser':integer,
'_attr':'brd_index'
},
'3':{
'_parser': number,
'_attr':'path'
},
},
},
}
def __init__(self,path,name='\"\"',brd_index=0,shape='polygon',typex='signal'):
super(Keepout,self).__init__(path=path,name=name,brd_index=brd_index,shape=shape,typex=typex)
\ No newline at end of file
File added
#!/usr/bin/env python3
from pykicad.sexpr import *
class Component(AST):
......@@ -80,6 +80,48 @@ class Pin(AST):
def __init__(self,pin_index=None,pin_at=None,pin_type='Round[A]Pad_1524_um'):
super(Pin,self).__init__(pin_type=pin_type,pin_index=pin_index,pin_at=pin_at)
class Shape(AST):
tag='shape'
schema={
' ':{
'0':{
'_parser': text,
'_attr':'shape'
},
'1':{
'_parser': text,
'_attr':'layer'
},
'2':{
'_parser': integer,
'_attr': 'size'
}
}
}
def __init__(self,shape='circle',layer=None,size=1524):
super(Shape,self).__init__(shape=shape,layer=layer,size=size)
class Padstack(AST):
tag='padstack'
schema={
'0':{
'_parser': text,
'_attr': 'pin_type'
},
'1':{
'shape':{
'_parser':Shape,
'_multiple':True
},
},
'attach':{
'_parser': text
}
}
def __init__(self,pin_type='Round[A]Pad_1524_um',shape=None,attach='off'):
shape=self.init_list(shape,[])
super(Padstack,self).__init__(pin_type=pin_type,shape=shape,attach=attach)
class Footprint(AST):
tag='image'
......
from pykicad.sexpr import *
class Net(AST):
tag='net'
schema={
'0':{
'_parser': text,
'_attr': 'net_name'
},
'1':{
'pins':{
'0':{
'_parser':text +text,
'_attr':'conn_pins'
},
}
}
}
def __init__(self,net_name,conn_pins=None):
super(Net,self).__init__(net_name=net_name,conn_pins=conn_pins)
class NetClass(AST):
tag='class'
schema={
'0':{
'0':{
'_parser':text,
'_attr':'net_class_name'
},
'1':{
'_parser':text+text,
'_attr':'nets_name'
},
},
'circuit':{
'0':{
'use_via':{
'_parser':text,
'_attr':'via_name'
}
}
},
'rule':{
'width':{
'_parser':integer
},
'clearance':{
'_parser': number
}
}
}
def __init__(self,net_class_name='default',nets_name=None,
via_name=None,width=1000,clearance=200.1):
super(NetClass,self).__init__(net_class_name=net_class_name,nets_name=nets_name,
via_name=via_name,width=width,clearance=clearance)
#!/usr/bin/env python3
from pykicad.sexpr import *
from dsn_rule import *
from dsn_module import Component,Footprint
from dsn_module import Component,Footprint, Padstack
import dsn_module as module
from dsn_net import *
from dsn_geo import *
class Parser(AST):
tag = 'parser'
......@@ -59,65 +61,6 @@ class Layer(AST):
Layer.index_ctr+=1
super(Layer,self).__init__(name=name,typex=typex,index=index)
class Boundary(AST):
tag='boundary'
schema={
'path pcb':{
'0':{
'_parser':integer,
'_attr':'brd_index'
},
'1':{
'_parser': number,
'_attr': 'path'
},
}
}
index_ctr=0
def __init__(self,path,brd_index=None):
brd_index=Boundary.index_ctr
Boundary.index_ctr+=1
super(Boundary,self).__init__(path=path,brd_index=brd_index)
class Keepout(AST):
tag='keepout'
schema={
'0':{
'0':{
'_parser':text,
'_attr':'name'
},
' ':{
'0': {
'_parser':text,
'_attr':'shape'
},
'1':{
'_parser':text,
'_attr':'typex'
},
'2':{
'_parser':integer,
'_attr':'brd_index'
},
'3':{
'_parser': number,
'_attr':'path'
},
},
},
}
def __init__(self,path,name='\"\"',brd_index=0,shape='polygon',typex='signal'):
super(Keepout,self).__init__(path=path,name=name,brd_index=brd_index,shape=shape,typex=typex)
class Dsn(AST):
tag = 'PCB "kicad_board"'
schema = {
......@@ -147,7 +90,7 @@ class Dsn(AST):
'1':{
'boundary':{
'_parser':Boundary,
'_multiple':True
'_multiple':False
},
},
'2':{
......@@ -187,13 +130,32 @@ class Dsn(AST):
'_parser': Footprint,
'_multiple': True
},
}
},
# 'padstack':{
# '_parser':Padstack,
# '_multiple': True
# }
'1':{
'_parser':Padstack,
'_multiple': True,
'_attr':'padstack'
}
}
},
'6':{
'network':{
'net':{
'_parser':Net,
'_multiple':True
},
'netclass':{
'_parser':NetClass,
'_multiple':True
}
}
},
'7':{
'wiring':{
'_parser':text, #not available before auto-routing, code can be modificed if want to set route from script manually
}
}
......@@ -211,7 +173,11 @@ class Dsn(AST):
via_txt='"Via[0-1]_800:400_um"',
rule=None,
component=None,
image=None
image=None,
padstack=None,
net=None,
netclass=None,
wiring= None
):
layers=self.init_list(layers,[])
......@@ -220,7 +186,9 @@ class Dsn(AST):
keepout=self.init_list(keepout,[])
component=self.init_list(component,[])
image=self.init_list(image,[])
padstack=self.init_list(padstack,[])
net=self.init_list(net,[])
net=self.init_list(netclass,[])
super(Dsn,self).__init__(
resolution=resolution,
......@@ -232,7 +200,11 @@ class Dsn(AST):
via_txt=via_txt,
rule=rule,
component=component,
image=image
image=image,
padstack=padstack,
net=net,
netclass=netclass,
wiring=wiring
)
def to_file(self, path):
......
(gui_defaults
(windows
(board_frame
visible
(bounds
351 29 1150 916
)
)
(color_manager
not_visible
(bounds
0 600 1110 134
)
)
(layer_visibility
not_visible
(bounds
0 450 369 162
)
)
(object_visibility
not_visible
(bounds
0 550 405 396
)
)
(display_miscellanious
not_visible
(bounds
0 350 241 333
)
)
(snapshots
not_visible
(bounds
0 250 230 255
)
)
(select_parameter
not_visible
(bounds
0 0 246 467
)
)
(route_parameter
not_visible
(bounds
0 100 261 542
)
)
(manual_rules
not_visible
(bounds
0 27 284 196
)
)
(route_details
not_visible
(bounds
0 27 263 240
)
)
(move_parameter
not_visible
(bounds
0 50 304 139
)
)
(clearance_matrix
not_visible
(bounds
0 150 470 257
)
)
(via_rules
not_visible
(bounds
50 150 335 450
)
)
(edit_vias
not_visible
(bounds
100 150 413 103
)
)
(edit_net_rules
not_visible
(bounds
100 200 913 103
)
)
(assign_net_rules
not_visible
(bounds
100 250 213 84
)
)
(padstack_info
not_visible
(bounds
100 30 0 0
)
)
(package_info
not_visible
(bounds
200 30 0 0
)
)
(component_info
not_visible
(bounds
300 30 0 0
)
)
(net_info
not_visible
(bounds
350 30 0 0
)
)
(incompletes_info
not_visible
(bounds
400 30 0 0
)
)
(violations_info
not_visible
(bounds
500 30 0 0
)
)
)
(colors
(background
204 204 204
)
(hilight 1.0
230 255 255
)
(incompletes 1.0
255 255 255
)
(outline
0 0 0
)
(component_front
0 0 255
)
(component_back
255 0 0
)
(violations
255 0 255
)
(length_matching 1.0
0 255 0
)
(traces 1.0
255 0 0
0 0 255
)
(fixed_traces 1.0
255 0 0
0 0 255
)
(vias 1.0
200 200 0
200 200 0
)
(fixed_vias 1.0
200 200 0
200 200 0
)
(pins 1.0
150 50 0
160 80 0
)
(conduction 1.0
0 150 0
100 100 0
)
(keepout 1.0
0 110 110
0 100 160
)
(via_keepout 1.0
100 100 100
100 100 100
)
)
(parameter
(selection_layers
all_visible
)
(selectable_items
TRACES VIAS PINS FIXED UNFIXED
)
(via_snap_to_smd_center
on
)
(route_mode
dynamic
)
(shove_enabled
on
)
(drag_components_enabled
on
)
(hilight_routing_obstacle
off
)
(pull_tight_region
2147483647
)
(pull_tight_accuracy
500
)
(clearance_compensation
off
)
(ignore_conduction_areas
on
)
(automatic_layer_dimming
0.7
)
(deselected_snapshot_attributes
)
)
)
\ No newline at end of file
(gui_defaults
(windows
(board_frame
visible
(bounds
120 27 1150 916
)
)
(color_manager
not_visible
(bounds
0 600 1110 134
)
)
(layer_visibility
not_visible
(bounds
0 450 369 162
)
)
(object_visibility
not_visible
(bounds
0 550 395 396
)
)
(display_miscellanious
not_visible
(bounds
0 350 241 333
)
)
(snapshots
not_visible
(bounds
0 250 230 255
)
)
(select_parameter
not_visible
(bounds
0 0 246 467
)
)
(route_parameter
not_visible
(bounds
0 100 261 542
)
)
(manual_rules
not_visible
(bounds
0 27 284 196
)
)
(route_details
not_visible
(bounds
0 27 263 240
)
)
(move_parameter
not_visible
(bounds
0 50 304 139
)
)
(clearance_matrix
not_visible
(bounds
0 150 470 257
)
)
(via_rules
not_visible
(bounds
50 150 335 450
)
)
(edit_vias
not_visible
(bounds
100 150 413 103
)
)
(edit_net_rules
not_visible
(bounds
100 200 913 103
)
)
(assign_net_rules
not_visible
(bounds
100 250 213 84
)
)
(padstack_info
not_visible
(bounds
100 30 0 0
)
)
(package_info
not_visible
(bounds
200 30 0 0
)
)
(component_info
not_visible
(bounds
300 30 0 0
)
)
(net_info
not_visible
(bounds
350 30 0 0
)
)
(incompletes_info
not_visible
(bounds
400 30 0 0
)
)
(violations_info
not_visible
(bounds
500 30 0 0
)
)
)
(colors
(background
255 255 255
)
(hilight 1.0
230 255 255
)
(incompletes 1.0
255 255 255
)
(outline
0 0 0
)
(component_front
0 0 255
)
(component_back
255 0 0
)
(violations
255 0 255
)
(length_matching 1.0
0 255 0
)
(traces 1.0
255 0 0
0 0 255
)
(fixed_traces 1.0
255 0 0
0 0 255
)
(vias 1.0
200 200 0
200 200 0
)
(fixed_vias 1.0
200 200 0
200 200 0
)
(pins 1.0
150 50 0
160 80 0
)
(conduction 1.0
0 150 0
100 100 0
)
(keepout 1.0
0 110 110
0 100 160
)
(via_keepout 1.0
100 100 100
100 100 100
)
)
(parameter
(selection_layers
all_visible
)
(selectable_items
TRACES VIAS PINS FIXED UNFIXED
)
(via_snap_to_smd_center
on
)
(route_mode
dynamic
)
(shove_enabled
on
)
(drag_components_enabled
on
)
(hilight_routing_obstacle
off
)
(pull_tight_region
2147483647
)
(pull_tight_accuracy
500
)
(clearance_compensation
off
)
(ignore_conduction_areas
on
)
(automatic_layer_dimming
0.7
)
(deselected_snapshot_attributes
)
)
)
\ No newline at end of file
......@@ -5,6 +5,7 @@ from pykicad import pcb
test=dsnwritier.Dsn()
###############################################################################
###manually
layers=[
dsnwritier.Layer('F.Cu'),
dsnwritier.Layer('B.Cu')
......@@ -21,6 +22,7 @@ bdata=[137735, -31864.8, 165736, -31864.8, 165736, -113335, 137735, -113335,
264.583, -31864.8, 78264.5, -31864.8, 78264.5, -264.632, 137735, -264.632,
137735, -31864.8]
kdata1=[138725, -221865, 138725, -244336, 150275, -244336, 150275, -221865,
138725, -221865]
kdata2=[98235.3, -224531, 98764.5, -224531, 98764.5, -219905, 103236, -224376,
......@@ -31,13 +33,34 @@ kdata2=[98235.3, -224531, 98764.5, -224531, 98764.5, -219905, 103236, -224376
98235.3, -224531]
#######################################################################################
###load from library
# drawingclass=dsnwritier.load_drawing('/home/jingyan/Documents/summer_intern_lemur/roco_electrical/kicad_test.dxf')
# bdata=drawingclass.load_polygon()[0]
drawingclass=dsnwritier.load_drawing('/home/jingyan/Documents/summer_intern_lemur/roco_electrical/dsn_line_test.dxf')
ddata=drawingclass.load_polygon()
bdata=ddata[0] #first element is boundary
keepout=[] #load all the rest as outline
for i in range(1,len(ddata)):
kdata=dsnwritier.Keepout(ddata[i])
keepout.append(kdata)
#######################################################################################
parsers= dsnwritier.Parser()
boundary=dsnwritier.Boundary(bdata)
#############
keepout=[
dsnwritier.Keepout(kdata1),
dsnwritier.Keepout(kdata2)]
#############
keepout=[] #load all the rest as outline
for i in range(1,len(ddata)):
kdata=dsnwritier.Keepout(ddata[i])
keepout.append(kdata)
rule=dsnwritier.Rule()
clearance=[
......@@ -45,11 +68,11 @@ clearance=[
dsnwritier.Clearance(200.1,'default_smd'),
dsnwritier.Clearance(50,'smd_smd')]
rule.clearance=clearance
##########
component=[dsnwritier.Component('U1',[103000,48000],name='"DEV"'),
dsnwritier.Component('J1',[103000,48000],name='"DEV"')]
###############
image1_outline=[
dsnwritier.module.Outline(width=120,outline_start=[-7620, 11430],outline_end=[7540, 11430]),
dsnwritier.module.Outline(width=120,outline_start=[-7620, 11430],outline_end=[7540, -13570]),
......@@ -62,6 +85,17 @@ image1_pin=[
image1=dsnwritier.Footprint('U1',image1_outline,image1_pin)
image=[image1]
###############
pin_shape1=[dsnwritier.module.Shape(layer='F.Cu'),
dsnwritier.module.Shape(layer='B.Cu')]
padstack1=dsnwritier.Padstack(shape=pin_shape1,attach='off')
pin_shape2=[dsnwritier.module.Shape(layer='F.Cu',size=800),
dsnwritier.module.Shape(layer='B.Cu',size=800)]
padstack2=dsnwritier.Padstack(pin_type='"Via[0-1]_800:400_um"',shape=pin_shape2,attach='off')
##############
net1=dsnwritier.Net('3v3',conn_pins=['U1-3','J1-1'])
net2=dsnwritier.Net('VIN',conn_pins='U1-1')
netclass1=dsnwritier.NetClass(net_class_name='default',nets_name=['3v3','GND','VIN'],via_name='Via[0-1]_800:400_um')
########################################################################################
test.parser=parsers
......@@ -71,5 +105,8 @@ test.keepout=keepout
test.rule=rule
test.component=component
test.image=image
test.padstack=[padstack1,padstack2]
test.net=[net1,net2]
test.netclass=netclass1
test.to_file('testdsn.dsn')
This diff is collapsed.
journal_media/dxf_in_freerouting.png

7.79 KiB

journal_media/keepout_load.png

115 KiB

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment