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

update pin detection,draw isolation

parent ada3eaf4
Branches
No related merge requests found
......@@ -90,7 +90,7 @@
- All lines on paper space`layer0`
### 07/01/2019 (Mon)
- Continue dxf processing with `'graph-silhouette.dxf'`
- Continue the dxf processing with `'graph-silhouette.dxf'`
##### Record of tips:
- Put circuit design on a new layer of dxf drawing
- [check doc about layers here](https://ezdxf.readthedocs.io/en/latest/tutorials/layers.html)
......@@ -104,4 +104,12 @@
- Test fabrication with different drawing settings
- Layers can be cut separately but toggling visibility
- Set cuts with same `intensity` and `feedrate` on same layer
- Entities' layer can be changed through `Entity.dxf.layer`
\ No newline at end of file
- Entities' layer can be changed through `Entity.dxf.layer`
### 07/02/2019 (Tue)
- Continue the dxf processing
- Following tasks can be completed by running the code:
- Able to detect pin center coordinate
- Able to draw arbitrary shape around the pin center
- ![isolation_circuit.png](journal_media/isolation_circuit.gif)
\ No newline at end of file
......@@ -3,65 +3,157 @@
import numpy as np
import ezdxf
import random
# class dxf_editor:
# def __init__(self,path,dxf_file):
# self.dwg=ezdxf.readfile(path+dxf_file)
from math import sqrt
class dxf_editor:
def __init__(self,path,dxf_file):
self.dwg=ezdxf.readfile(path+dxf_file)
self.msp=self.dwg.modelspace()
self.create_layer('Cut',5)
self.create_layer('Circuit',1)
self.create_layer('Label',3)
self.create_layer('Fold',4)
self.create_layer('Pin_temp',6)
self.layer_rearrange() ## reagrrange cut and fold lines to corresponding layers
self.find_pin()
isolength=2.6 #mm
self.draw_on_pin(isolength)
self.dwg.saveas('silhouette_ele.dxf')
def create_layer(self,layer_name,color):
if not layer_name in self.dwg.layers:
self.dwg.layers.new(name=layer_name,dxfattribs={'color':color})
def layer_rearrange(self):
# put fold lines to the new layer 'Fold'
# put cut lines to the new layer 'Cut
for e in self.msp.query('LINE'):
if e.dxf.color!=5:
e.dxf.layer='Fold'
else:
e.dxf.layer='Cut'
def find_pin(self):
tolerance=0.05 #mm
pincutsize=1 #mm
pin_edge_arr=np.array([[0,0],[0,0]]).reshape(1,2,2)
self.center_arr=np.array([[0,0]])
for e in self.msp.query('LINE[layer=="Cut"]'):
length= sqrt((e.dxf.start[0]-e.dxf.end[0])**2+(e.dxf.start[1]-e.dxf.end[1])**2)
if length > pincutsize-tolerance and length < pincutsize + tolerance:
e.dxf.layer='Pin_temp'
if e.dxf.start[1]==e.dxf.end[1]: ##this line is horizontal
pin_edge=np.array([e.dxf.start,e.dxf.end])[:,:2]
pin_edge_arr=np.concatenate((pin_edge_arr,pin_edge.reshape(1,2,2)),axis=0)
pin_edge_arr=pin_edge_arr[1:]
# print(pin_edge_arr)
for i in range(len(pin_edge_arr)):
for e in np.delete(pin_edge_arr,i,axis=0):
if pin_edge_arr[i][0,1]-e[0,1]==1.0:
center_x=pin_edge_arr[i][0,0]-0.5
center_y=pin_edge_arr[i][0,1]-0.5
center=np.array([center_x,center_y]).reshape(1,2)
self.center_arr=np.append(self.center_arr,center,axis=0)
self.center_arr=np.unique(self.center_arr,axis=0)
self.center_arr=self.center_arr[1:]
def draw_on_pin(self,fulllength): #isolation
iso=self.dwg.blocks.new(name='ISO_BLK')
isolength=fulllength/2
iso.add_line((-isolength,isolength),(isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,-isolength),(isolength,-isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((-isolength,-isolength),(-isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
iso.add_line((isolength,-isolength),(isolength,isolength),dxfattribs={'linetype':'DASHDOT'})
for center_point in self.center_arr:
self.msp.add_blockref('ISO_BLK',center_point,dxfattribs={'layer':'Circuit'})
# if e.dxf.start[1]==e.dxf.end[1]: ##this line is horizontal
# midpoint_x=min(e.dxf.start[0],e.dxf.end[0])+length/2
# elif e.dxf.start[0]==e.dxf.end[0]: #This line is vertical
# midpoint_y=min(e.dxf.start[1],e.dxf.end[1])+length/2
# # print(midpoint)
# self.midpoint_arr=np.concatenate((self.midpoint_arr,np.array([midpoint])),axis=0)
# self.midpoint_arr=self.midpoint_arr[1:]
# self.midpoint_arr=np.unique(self.midpoint_arr,axis=0)
# print(self.midpoint_arr)
def main():
path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
edit=dxf_editor(path,dxf_file)
# def main():
# path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
# dxf_file='graph-silhouette.dxf'
# edit=dxf_editor(path,dxf_file)
if __name__ == '__main__':
main()
# if __name__ == '__main__':
# main()
path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
dwg=ezdxf.readfile(path+dxf_file)
# iterate over all entities in model space
def print_entity(e):
print("LINE on layer: %s\n" % e.dxf.layer)
print("start point:",e.dxf.start)
print("end point:" , e.dxf.end)
print("color:", e.dxf.color)
msp = dwg.modelspace()
# for e in msp:
# if e.dxftype() == 'LINE':
# print_entity(e)
i=0
# entity query for all LINE entities in model space
for e in msp.query('LINE[color==1]'):
i+=1
print_entity(e)
# path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
# dxf_file='graph-silhouette.dxf'
# dwg=ezdxf.readfile(path+dxf_file)
# # iterate over all entities in model space
# def print_entity(e):
# print("LINE on layer: %s\n" % e.dxf.layer)
# print("start point:",e.dxf.start)
# print("end point:" , e.dxf.end)
# print("color:", e.dxf.color)
# msp = dwg.modelspace()
# # for e in msp:
# # if e.dxftype() == 'LINE':
# # print_entity(e)
# i=0
# # entity query for all LINE entities in model space
# for e in msp.query('LINE[color==1]'):
# i+=1
# print_entity(e)
print(i)
# for z in msp.query('CIRCLE'):
# print(z)
if not 'Isolation' in dwg.layers:
dwg.layers.new(name='Isolation',dxfattribs={'linetype':'DASHED','color':2})
# # print(i)
# # # for z in msp.query('CIRCLE'):
# # # print(z)
# if not 'Isolation' in dwg.layers:
# dwg.layers.new(name='Isolation',dxfattribs={'linetype':'DASHED','color':2})
msp.add_line((0,0),(50,50),dxfattribs={'layer':'Isolation'})
# msp.add_line((0,0),(50,50),dxfattribs={'layer':'Isolation'})
def get_random_point():
"""Creates random x, y coordinates."""
x = random.randint(-100, 100)
y = random.randint(-100, 100)
return x, y
# def get_random_point():
# """Creates random x, y coordinates."""
# x = random.randint(-100, 100)
# y = random.randint(-100, 100)
# return x, y
# Create a block with the name 'FLAG'
flag = dwg.blocks.new(name='FLAG')
# # Create a block with the name 'FLAG'
# flag = dwg.blocks.new(name='FLAG')
# Add DXF entities to the block 'FLAG'.
# The default base point (= insertion point) of the block is (0, 0).
# flag.add_polyline2d([(0, 0), (0, 5), (4, 3), (0, 3)]) # the flag as 2D polyline
flag.add_circle((0, 0), .4, dxfattribs={'color': 5}) # mark the base point with a circle
# # Add DXF entities to the block 'FLAG'.
# # The default base point (= insertion point) of the block is (0, 0).
# # flag.add_polyline2d([(0, 0), (0, 5), (4, 3), (0, 3)]) # the flag as 2D polyline
# flag.add_circle((0, 0), .4, dxfattribs={'color': 5}) # mark the base point with a circle
msp.add_blockref('FLAG',(40,40))
# msp.add_blockref('FLAG',(40,40))
dwg.save()
\ No newline at end of file
# dwg.save()
\ No newline at end of file
This diff is collapsed.
journal_media/isolation_circuit.gif

207 KiB

journal_media/isolation_circuit.png

23.3 KiB

This diff is collapsed.
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