diff --git a/README.md b/README.md index 0ea952fd8a2b086d33ef59bc54bb9e19c3b665a2..c75ccc78be94eff65e398845a3664d1f1dc4ff3f 100644 --- a/README.md +++ b/README.md @@ -130,4 +130,19 @@ - Resolution problem: single point does not represented as a pixel in `png` - TODO: - create an empty matrix and fill in numbers with the information of each lines' start and end point - \ No newline at end of file +### 07/03/2019 (Wed) +- dxf processing completed + +- Convert dxf to matrix with resolution (270X210) (mm) + - Potential issue: + - the `pathfinding` package is based on pixel + - When round up the line's start and end point, the accuracy of pin position is low + +- Apply single point to point path finding + - Able to draw the path on matrix + - Able to draw the path on original dxf file + +- TODO: + - Write out algorithm for muli-node path finding + - break single circuit trace to parallel traces + - solve the accuracy problem \ No newline at end of file diff --git a/analyze_dxf.py b/analyze_dxf.py index 61a19288b434eb07d2d5ea78b642cca68ba52a70..bf086b164452ec9ec06494eb232b92c1517bd71c 100644 --- a/analyze_dxf.py +++ b/analyze_dxf.py @@ -6,6 +6,9 @@ import random from math import sqrt import cv2 import os +from pathfinding.core.diagonal_movement import DiagonalMovement +from pathfinding.core.grid import Grid +from pathfinding.finder.a_star import AStarFinder class dxf_editor: def __init__(self,path,dxf_file): @@ -28,9 +31,17 @@ class dxf_editor: isolength=2.6 #mm self.draw_on_pin(isolength) - self.matrix_shape=(210,270) + self.matrix_shape=(270,210) self.read_dxf_as_matrix() + start_point_arr=np.rint(self.center_arr[0]) + end_point_arr=np.rint(self.center_arr[-30]) + start_point=[int(start_point_arr[0]),int(start_point_arr[1])] + end_point=[int(end_point_arr[0]),int(end_point_arr[1])] + + self.path=self.find_a_path(start_point,end_point) + + self.draw_a_path(self.path) self.dwg.saveas(self.dxf_name) @@ -115,24 +126,42 @@ class dxf_editor: 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 + self.matrix[j,i]=0 while i!=end[0]: if i<end[0]: i+=1 else: i-=1 - self.matrix[i,j]=0 + self.matrix[j,i]=0 elif i==end[0]: #this line is a vertical line - self.matrix[i,j]=0 + self.matrix[j,i]=0 while j!=end[1]: if j<end[1]: j+=1 else: j-=1 - self.matrix[i,j]=0 + self.matrix[j,i]=0 + + def find_a_path(self,start_point,end_point): + + grid = Grid(matrix=self.matrix) + start=grid.node(start_point[0],start_point[1]) + end=grid.node(end_point[0],end_point[1]) + finder = AStarFinder(diagonal_movement=DiagonalMovement.always) + path, runs = finder.find_path(start, end, grid) + + return path + def draw_a_path(self,path): + #draw on matrix: + for point in path: + self.matrix[point[1],point[0]]=-1 + #draw on dxf: + for i in range(len(path)-1): + self.msp.add_line(path[i],path[i+1],dxfattribs={ + 'layer':'Circuit', + 'linetype':'DASHDOT'}) + - - diff --git a/silhouette_ele.dxf b/silhouette_ele.dxf index fe7cff33928be44f779aa74f50c82404c2420877..eacd1b41f284f321067660edb698a17937050e4e 100644 --- a/silhouette_ele.dxf +++ b/silhouette_ele.dxf @@ -53,11 +53,11 @@ $HANDLING 9 $TDUPDATE 40 -2458668.61425 +2458668.67993 9 $HANDSEED 5 -30B +322 9 $DWGCODEPAGE 3 @@ -10513,6 +10513,420 @@ ISO_BLK 67 0 0 +LINE + 5 +30B + 8 +Circuit + 10 +86.0 + 20 +35.0 + 11 +86.0 + 21 +36.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +30C + 8 +Circuit + 10 +86.0 + 20 +36.0 + 11 +86.0 + 21 +37.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +30D + 8 +Circuit + 10 +86.0 + 20 +37.0 + 11 +87.0 + 21 +38.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +30E + 8 +Circuit + 10 +87.0 + 20 +38.0 + 11 +88.0 + 21 +39.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +30F + 8 +Circuit + 10 +88.0 + 20 +39.0 + 11 +88.0 + 21 +40.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +310 + 8 +Circuit + 10 +88.0 + 20 +40.0 + 11 +89.0 + 21 +41.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +311 + 8 +Circuit + 10 +89.0 + 20 +41.0 + 11 +89.0 + 21 +42.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +312 + 8 +Circuit + 10 +89.0 + 20 +42.0 + 11 +89.0 + 21 +43.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +313 + 8 +Circuit + 10 +89.0 + 20 +43.0 + 11 +89.0 + 21 +44.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +314 + 8 +Circuit + 10 +89.0 + 20 +44.0 + 11 +89.0 + 21 +45.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +315 + 8 +Circuit + 10 +89.0 + 20 +45.0 + 11 +90.0 + 21 +46.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +316 + 8 +Circuit + 10 +90.0 + 20 +46.0 + 11 +91.0 + 21 +47.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +317 + 8 +Circuit + 10 +91.0 + 20 +47.0 + 11 +92.0 + 21 +48.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +318 + 8 +Circuit + 10 +92.0 + 20 +48.0 + 11 +93.0 + 21 +49.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +319 + 8 +Circuit + 10 +93.0 + 20 +49.0 + 11 +94.0 + 21 +50.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31A + 8 +Circuit + 10 +94.0 + 20 +50.0 + 11 +95.0 + 21 +51.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31B + 8 +Circuit + 10 +95.0 + 20 +51.0 + 11 +95.0 + 21 +52.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31C + 8 +Circuit + 10 +95.0 + 20 +52.0 + 11 +96.0 + 21 +53.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31D + 8 +Circuit + 10 +96.0 + 20 +53.0 + 11 +97.0 + 21 +54.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31E + 8 +Circuit + 10 +97.0 + 20 +54.0 + 11 +98.0 + 21 +55.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +31F + 8 +Circuit + 10 +98.0 + 20 +55.0 + 11 +99.0 + 21 +56.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +320 + 8 +Circuit + 10 +99.0 + 20 +56.0 + 11 +100.0 + 21 +57.0 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +321 + 8 +Circuit + 10 +100.0 + 20 +57.0 + 11 +101.0 + 21 +58.0 + 6 +DASHDOT + 67 +0 + 0 VIEWPORT 5 27