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

update matrix read

parent ffb6b38e
No related merge requests found
...@@ -22,7 +22,7 @@ class dxf_editor: ...@@ -22,7 +22,7 @@ class dxf_editor:
self.create_layer('Pin_temp',6) self.create_layer('Pin_temp',6)
self.layer_rearrange() ## reagrrange cut and fold lines to corresponding layers self.layer_rearrange() ## reagrrange cut and fold lines to corresponding layers
self.remove_wheels() ##remove wheel drawings for this design, no need to call for other designs
self.find_pin() self.find_pin()
isolength=2.6 #mm isolength=2.6 #mm
...@@ -59,8 +59,6 @@ class dxf_editor: ...@@ -59,8 +59,6 @@ class dxf_editor:
pin_edge_arr=np.array([[0,0],[0,0]]).reshape(1,2,2) pin_edge_arr=np.array([[0,0],[0,0]]).reshape(1,2,2)
self.center_arr=np.array([[0,0]]) self.center_arr=np.array([[0,0]])
for e in self.msp.query('LINE[layer=="Cut"]'): 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) 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: if length > pincutsize-tolerance and length < pincutsize + tolerance:
...@@ -83,7 +81,11 @@ class dxf_editor: ...@@ -83,7 +81,11 @@ class dxf_editor:
self.center_arr=self.center_arr[1:] self.center_arr=self.center_arr[1:]
# print(self.center_arr) # print(self.center_arr)
def remove_wheels(self): def remove_wheels(self):
#no need to call th #no need to call this function for other design
for e in self.msp.query('Arc LINE[layer=="Cut"]'):
if e.dxf.start[0]>=179:
self.msp.delete_entity(e)
def draw_on_pin(self,fulllength): #isolation def draw_on_pin(self,fulllength): #isolation
iso=self.dwg.blocks.new(name='ISO_BLK') iso=self.dwg.blocks.new(name='ISO_BLK')
...@@ -104,12 +106,35 @@ class dxf_editor: ...@@ -104,12 +106,35 @@ class dxf_editor:
"""unit: mm """unit: mm
accuracy issue expected atm (mm round up) accuracy issue expected atm (mm round up)
""" """
self.matrix=np.zeros(self.matrix_shape) self.matrix=np.ones(self.matrix_shape)
for line in self.msp.query('LINE[layer!="Fold"]'): for line in self.msp.query('LINE[layer!="Fold" & layer!="Label" & layer!="Pin_temp"]'):
start=np.rint(line.dxf.start) start=np.rint(line.dxf.start)
end=np.rint(line.dxf.end) end=np.rint(line.dxf.end)
self.matrix[int(start[0]),int(start[1])]=1 i=int(start[0])
j=int(start[1])
#can draw horizontal or vertical lines only
if j==end[1]: #this line is a horizontal line
self.matrix[i,j]=0
while i!=end[0]:
if i<end[0]:
i+=1
else:
i-=1
self.matrix[i,j]=0
elif i==end[0]: #this line is a vertical line
self.matrix[i,j]=0
while j!=end[1]:
if j<end[1]:
j+=1
else:
j-=1
self.matrix[i,j]=0
# print(self.matrix) # print(self.matrix)
...@@ -131,51 +156,3 @@ edit=dxf_editor(path,dxf_file) ...@@ -131,51 +156,3 @@ edit=dxf_editor(path,dxf_file)
# if __name__ == '__main__': # if __name__ == '__main__':
# 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)
# # 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'})
# 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')
# # 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))
# dwg.save()
\ No newline at end of file
journal_media/matrix_to_img.png

18.7 KiB

This diff is collapsed.
...@@ -489,11 +489,11 @@ $SKPOLY ...@@ -489,11 +489,11 @@ $SKPOLY
9 9
$TDCREATE $TDCREATE
40 40
2458668.49543 2458668.59635
9 9
$TDUPDATE $TDUPDATE
40 40
2458668.49543 2458668.59635
9 9
$TDINDWG $TDINDWG
40 40
...@@ -921,11 +921,11 @@ $PSTYLEMODE ...@@ -921,11 +921,11 @@ $PSTYLEMODE
9 9
$FINGERPRINTGUID $FINGERPRINTGUID
2 2
D647F2AC-9DC3-11E9-8B04-7470FDECECE4 24217DCC-9DD8-11E9-8B04-7470FDECECE4
9 9
$VERSIONGUID $VERSIONGUID
2 2
D647F2AE-9DC3-11E9-8B04-7470FDECECE4 24217DCE-9DD8-11E9-8B04-7470FDECECE4
9 9
$EXTNAMES $EXTNAMES
290 290
...@@ -2815,7 +2815,7 @@ AcDbLine ...@@ -2815,7 +2815,7 @@ AcDbLine
11 11
40.5 40.5
21 21
40.2 0.6
0 0
INSERT INSERT
5 5
......
import ezdxf import ezdxf
import random # needed for random placing points import random # needed for random placing points
import numpy as np
def get_random_point(): def get_random_point():
"""Creates random x, y coordinates.""" """Creates random x, y coordinates."""
...@@ -24,7 +24,7 @@ flag.add_circle((0, 0), 5, dxfattribs={'color': 5}) # mark the base point with ...@@ -24,7 +24,7 @@ flag.add_circle((0, 0), 5, dxfattribs={'color': 5}) # mark the base point with
# Get the modelspace of the drawing. # Get the modelspace of the drawing.
modelspace = dwg.modelspace() modelspace = dwg.modelspace()
modelspace.add_line((0.3,0.6),(40.5,40.2)) modelspace.add_line((0.3,0.6),(40.5,0.6))
# Get 50 random placing points. # Get 50 random placing points.
placing_points = [get_random_point() for _ in range(50)] placing_points = [get_random_point() for _ in range(50)]
...@@ -40,5 +40,33 @@ modelspace.add_text("TEST").set_pos((10,285),align="MIDDLE_RIGHT") ...@@ -40,5 +40,33 @@ modelspace.add_text("TEST").set_pos((10,285),align="MIDDLE_RIGHT")
for e in modelspace.query('LINE'): for e in modelspace.query('LINE'):
print(e.dxf.start) print(e.dxf.start)
index_i=[]
index_j=[]
for line in modelspace.query('LINE'):
start=np.rint(line.dxf.start)
end=np.rint(line.dxf.end)
i=start[0]
j=start[1]
# index_i.append(i)
# index_j.append(j)
#can draw horizontal or vertical lines only
if j==end[1]: #this line is a horizontal line
index_i.append(i)
while i!=end[0]:
if i<end[0]:
i+=1
else:
i-=1
index_i.append(i)
elif i==end[0]: #this line is a vertical line
index_j.append(j)
while j!=end[1]:
if j<end[1]:
j+=1
else:
j-=1
index_j.append(j)
# Save the drawing. # Save the drawing.
dwg.saveas("testline.dxf") dwg.saveas("testline.dxf")
\ No newline at end of file
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