From 3f12b65db443395d96b24d52952e48f839de8167 Mon Sep 17 00:00:00 2001
From: Jingyan Ling <jingyanling2018@u.northwestern.edu>
Date: Mon, 12 Aug 2019 14:21:39 -0700
Subject: [PATCH] update joranl,structrue

---
 README.md                                     |   5 +-
 .../__pycache__/paperbot_draw.cpython-36.pyc  | Bin 5970 -> 5982 bytes
 paperbot_ee_autoroute/fab_drawing.py          |   3 +-
 paperbot_ee_autoroute/paperbot_draw.py        | 135 +---------------
 .../roco_ee_dwg_processing.py                 | 153 ++++++++++++++++++
 5 files changed, 161 insertions(+), 135 deletions(-)
 create mode 100644 paperbot_ee_autoroute/roco_ee_dwg_processing.py

diff --git a/README.md b/README.md
index 3cb9229..c2a5605 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,10 @@
   - 3. Offset original path based on given width
   - 4. find intersect between paths with offset and angle bisectors
   - 5. connect intersect points and 4 end-points
-- 
+
+- Separate file `paperbot_draw` to a general useful file `roco_ee_dwg_processing.py` and operations specifically for paperbot `paperbot_draw.py`
+  - functions and classes in `roco_ee_dwg_processing.py` will be useful for future foldable robot project.
+  
 ### 08/09/2019
 
 - Potential problem:
diff --git a/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc b/paperbot_ee_autoroute/__pycache__/paperbot_draw.cpython-36.pyc
index 5d7a6291f4b167c9ce2b62597dc32a8dfe7c9259..5a079a0f65bd77fc2378e2165cb2526a0871b0f2 100644
GIT binary patch
delta 1643
zcmZ`)&2Jk;6yKTs@Ou4`k2a}I+QuO%#3He311bar4K#s@stExhSV*mvcav<e*Us#Q
z*k~6Y%0E!ekvmePRu#$xi6eI;0;f6j!WE9(d2j4C!Gg8sw{L#)K4#u~vp%gnsm#Be
z%UKJ*eYpMOWkvZzIrpd_--Ho<`e1%DXS(Tc729&jM@rfHq5Byjf}fI8a|$$$6*hbF
zkdBd+37FYN)9HCE6l&ldl~r~HIZJZ&z-f8xc_7&AGbo`n&Hq;W8@6`m_T4q6BV!?G
z0A-zB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Wq4@`tdP08d*o|?p=8Zn4L3#34D@aBm|_D5RH
zD6Y0xvlc{A>8$-xtDmY}TuQnqxjYkx2EzZ9l+#;MYxp<TvrwaYDAZark{iJupkfu_
zwCXOWSC+n8_v6iqzG-`n_1)tl<krBH&OQeNJ~#0Ed`~@o4E!_x&p@|pvJcQHmLj`_
zP()ZlSVoW&!rxE!?^u#`eH#>2XpseA60_gbO~V{z$h(%%!=3F`J3XIR^ul0X=r^~8
uwv8tmE<NrHnTvNp#qe-QyZ;I#%<J1tf2R@Lz>6|MUl0vm2bxB6pS=Q6>ri0;

diff --git a/paperbot_ee_autoroute/fab_drawing.py b/paperbot_ee_autoroute/fab_drawing.py
index 09e4b83..bd64282 100644
--- a/paperbot_ee_autoroute/fab_drawing.py
+++ b/paperbot_ee_autoroute/fab_drawing.py
@@ -23,6 +23,7 @@ import sys
 import subprocess
 sys.path.insert(1,dsnwritier_dir)
 from sesreader import *
+from roco_ee_dwg_processing import *
 
 #########for paperbot only########
 import paperbot_dsn
@@ -33,4 +34,4 @@ paperbot_dsn.brd_design(dwg_path,0,module_libpath,save_name)
 unrouted_dsn_file=save_name+'.dsn'
 subprocess.call(['java','-jar','freeRouting.jar','-de',unrouted_dsn_file,'-white','-s'])
 wiring_path=find_wire(save_name)
-paperbot_draw.post_process(dwg_path,wiring_path)
+post_process(dwg_path,wiring_path)
diff --git a/paperbot_ee_autoroute/paperbot_draw.py b/paperbot_ee_autoroute/paperbot_draw.py
index cdfc168..7a1ec41 100644
--- a/paperbot_ee_autoroute/paperbot_draw.py
+++ b/paperbot_ee_autoroute/paperbot_draw.py
@@ -4,6 +4,7 @@ import ezdxf
 import random
 from math import sqrt
 import copy
+from roco_ee_dwg_processing import *
 unit_convert=10000 #ses to dxf
 
 class pre_process():
@@ -24,7 +25,7 @@ class pre_process():
         self.remove_wheels() ##remove wheel drawings for this design, no need to call for other designs
         self.center_arr=self.find_pin()
         
-        self.cross_cut(2,self.center_arr)
+        cross_cut(self.msp,2,self.center_arr)
         
         self.dwg.saveas(self.save_name)
     
@@ -73,135 +74,3 @@ class pre_process():
         center_arr=np.unique(center_arr,axis=0)
         center_arr=center_arr[1:]
         return center_arr
-
-    def cross_cut(self,cross_size,pin_loc):
-        """
-        cross_size= lenght of bounding box of the cross cut
-        """
-        tipat=cross_size/2
-        for pt in pin_loc:
-            x=pt[0]
-            y=pt[1]
-            cross_s1=(x-tipat,y-tipat)
-            cross_e1=(x+tipat,y+tipat)
-            cross_s2=(x-tipat,y+tipat)
-            cross_e2=(x+tipat,y-tipat)
-            self.msp.add_line(cross_s1,cross_e1,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'})       
-            self.msp.add_line(cross_s2,cross_e2,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'})  
-    
-    # def line_to_path(self)
-
-
-class post_process():
-    def __init__(self,dxf_file,wiring_path):
-        if not dxf_file.endswith('.dxf'):
-            dxf_file+='.dxf'
-        self.dxf_file=dxf_file
-        self._wiring=wiring_path
-        self.wiring=[]
-        self.dwg=ezdxf.readfile(dxf_file)
-        self.msp=self.dwg.modelspace()
-
-        self.convert_unit()
-        self.draw_wires()
-        self.parallel_trace(1)
-
-        self.dwg.saveas('route_text.dxf')
-
-    def convert_unit(self):
-        for path in self._wiring:
-            p=np.array(path)/unit_convert
-            p[:,1]*=-1
-            self.wiring.append(p.tolist())         
-    def draw_wires(self):
-        for path in self.wiring:
-            for i in range(len(path)-1):
-                self.msp.add_line(path[i],path[i+1],dxfattribs={
-                    'layer':'Circuit',
-                    'linetype':'DASHDOT'})
-    def find_lind_eq(self,pt1,pt2):
-        """
-        input: two points on a line
-        pt1:[x1,y1]
-        pt2:[x2,y2]
-        return: a,b,theta in terms of cy=ax+b
-        """
-        x1,y1=pt1[0],pt1[1]
-        x2,y2=pt2[1],pt2[1]
-
-        if x1==x2:
-            theta=-np.pi/2
-            #x= number
-            a=1
-            b=-x1
-            c=0
-        else:
-            theta=np.arctan((y2-y1)/(x2-x1))
-            A=np.array([[x1,1],[x2,1]])
-            k=np.array([y1,y2])
-            sol=np.linalg.solve(A,k)
-            a,b=sol[0],sol[1]
-            c=1
-        return a,b,c,theta
-
-
-    def parallel_trace(self,width):
-        halfw=width/2
-        for path in self.wiring:
-            for i in range(len(path)-1):
-                start_x,start_y=path[i][0],path[i][1]
-                end_x,end_y=path[i+1][0],path[i+1][1]
-                
-                theta=self.find_lind_eq(path[i],path[i+1])[3]
-                sinw=np.sin(theta)*halfw
-                cosw=np.cos(theta)*halfw
-                s1i=[start_x-sinw,start_y+cosw]
-                s1o=[start_x+sinw,start_y-cosw]                
-                e1i=[end_x-sinw,end_y+cosw]
-                e1o=[end_x+sinw,end_y-cosw]
-
-                line1i=self.find_lind_eq(s1i,e1i)
-                line1o=self.find_lind_eq(s1o,e1o)
-
-                if i==0:
-                    s1=s1i
-                    s2=s1o
-                else:
-                    s1=e1
-                    s2=e2 
-                
-                if i<len(path)-2:
-                    next_x,next_y=path[i+2][0],path[i+2][1]
-                    theta2=self.find_lind_eq(path[i+1],path[i+2])[3]
-                   
-                    sinw2=np.sin(theta2)*halfw
-                    cosw2=np.cos(theta2)*halfw
-
-                    s2i=[end_x-sinw2,end_y+cosw2]
-                    s2o=[end_x+sinw2,end_y-cosw2]
-                    e2i=[next_x-sinw2,next_y+cosw2]
-                    e2o=[next_x+sinw2,next_y-cosw2]
-
-                    line2i=self.find_lind_eq(s2i,e2i)
-                    line2o=self.find_lind_eq(s2o,e2o)
-
-                    Ainteri=np.array([[line1i[0],-line1i[2]],[line2i[0],-line2i[2]]])
-                    binteri=np.array([-line1i[1],-line2i[1]])
-                    Aintero=np.array([[line1o[0],-line1o[2]],[line2o[0],-line2o[2]]])
-                    bintero=np.array([-line1o[1],-line2o[1]])
-                    
-                    e1=np.linalg.solve(Ainteri,binteri)
-                    e2=np.linalg.solve(Aintero,bintero)
-
-                else:
-                    #from last end point to this end
-                    e1=[end_x-sinw,end_y+cosw]
-                    e2=[end_x+sinw,end_y-cosw]
-                
-
-                self.msp.add_line(s1i,e1i,dxfattribs={
-                    'layer':'Circuit',
-                    'linetype':'DASHDOT'})
-                self.msp.add_line(s1o,e1o,dxfattribs={
-                    'layer':'Circuit',
-                    'linetype':'DASHDOT'})
diff --git a/paperbot_ee_autoroute/roco_ee_dwg_processing.py b/paperbot_ee_autoroute/roco_ee_dwg_processing.py
new file mode 100644
index 0000000..761b58d
--- /dev/null
+++ b/paperbot_ee_autoroute/roco_ee_dwg_processing.py
@@ -0,0 +1,153 @@
+#!/usr/bin/env python3
+
+import numpy as np
+import ezdxf 
+import random
+from math import sqrt
+import copy
+unit_convert=10000 #ses to dxf
+
+
+def cross_cut(msp,cross_size,pin_loc):
+    """
+    cross_size= lenght of bounding box of the cross cut
+    """
+    tipat=cross_size/2
+    for pt in pin_loc:
+        x=pt[0]
+        y=pt[1]
+        cross_s1=(x-tipat,y-tipat)
+        cross_e1=(x+tipat,y+tipat)
+        cross_s2=(x-tipat,y+tipat)
+        cross_e2=(x+tipat,y-tipat)
+        msp.add_line(cross_s1,cross_e1,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'})       
+        msp.add_line(cross_s2,cross_e2,dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'})
+    
+# def line_to_path()
+
+class post_process():
+    def __init__(self,dxf_file,wiring_path):
+        if not dxf_file.endswith('.dxf'):
+            dxf_file+='.dxf'
+        self.dxf_file=dxf_file
+        self._wiring=wiring_path
+        self.wiring=[]
+        self.dwg=ezdxf.readfile(dxf_file)
+        self.msp=self.dwg.modelspace()
+
+        self.convert_unitfrom_ses()
+        # self.draw_wires()
+        self.parallel_trace(1)
+
+        self.dwg.saveas('route_text.dxf')
+
+    def convert_unitfrom_ses(self):
+        for path in self._wiring:
+            p=np.array(path)/unit_convert
+            p[:,1]*=-1
+            self.wiring.append(p.tolist())         
+    def draw_wires(self):
+        for path in self.wiring:
+            for i in range(len(path)-1):
+                self.msp.add_line(path[i],path[i+1],dxfattribs={
+                    'layer':'Circuit',
+                    'linetype':'DASHDOT'})
+
+    def parallel_trace(self,width):
+        halfw=width/2
+        for path in self.wiring:
+            for i in range(len(path)-1):
+                start_x,start_y=path[i][0],path[i][1]
+                end_x,end_y=path[i+1][0],path[i+1][1]
+                
+                theta=self.find_lind_eq(path[i],path[i+1])[3]
+                sinw=np.sin(theta)*halfw
+                cosw=np.cos(theta)*halfw
+                s1i=[start_x-sinw,start_y+cosw]
+                s1o=[start_x+sinw,start_y-cosw]                
+                e1i=[end_x-sinw,end_y+cosw]
+                e1o=[end_x+sinw,end_y-cosw]
+
+                line1i=self.find_lind_eq(s1i,e1i)
+                line1o=self.find_lind_eq(s1o,e1o)
+
+                if i==0:
+                    s1=s1i
+                    s2=s1o
+                else:
+                    s1=e1
+                    s2=e2 
+                
+                if i<len(path)-2:
+                    next_x,next_y=path[i+2][0],path[i+2][1]
+                    theta2=self.find_lind_eq(path[i+1],path[i+2])[3]
+                   
+                    sinw2=np.sin(theta2)*halfw
+                    cosw2=np.cos(theta2)*halfw
+
+                    s2i=[end_x-sinw2,end_y+cosw2]
+                    s2o=[end_x+sinw2,end_y-cosw2]
+                    e2i=[next_x-sinw2,next_y+cosw2]
+                    e2o=[next_x+sinw2,next_y-cosw2]
+
+                    line2i=find_lind_eq(s2i,e2i)
+                    line2o=find_lind_eq(s2o,e2o)
+
+                    Ainteri=np.array([[line1i[0],-line1i[2]],[line2i[0],-line2i[2]]])
+                    binteri=np.array([-line1i[1],-line2i[1]])
+                    Aintero=np.array([[line1o[0],-line1o[2]],[line2o[0],-line2o[2]]])
+                    bintero=np.array([-line1o[1],-line2o[1]])
+                    
+                    e1=np.linalg.solve(Ainteri,binteri)
+                    e2=np.linalg.solve(Aintero,bintero)
+
+                else:
+                    #from last end point to this end
+                    e1=[end_x-sinw,end_y+cosw]
+                    e2=[end_x+sinw,end_y-cosw]
+                
+
+                self.msp.add_line(s1i,e1i,dxfattribs={
+                    'layer':'Circuit',
+                    'linetype':'DASHDOT'})
+                self.msp.add_line(s1o,e1o,dxfattribs={
+                    'layer':'Circuit',
+                    'linetype':'DASHDOT'})
+
+def find_line_eq(pt1,pt2):
+    """
+    input: two points on a line
+    pt1:[x1,y1]
+    pt2:[x2,y2]
+    return: a,b,theta in terms of cy=ax+b
+    """
+    
+    x1,y1=pt1[0],pt1[1]
+    x2,y2=pt2[0],pt2[1]
+    if x1>x2:
+        x1,y1=pt2[0],pt2[1]
+        x2,y2=pt1[0],pt1[1]
+
+    if x1==x2:
+        theta=-np.pi/2
+        #x= number
+        a=1
+        b=-x1
+        c=0
+    else:
+        theta=np.arctan((y2-y1)/(x2-x1))
+        A=np.array([[x1,1],[x2,1]])
+        k=np.array([y1,y2])
+        sol=np.linalg.solve(A,k)
+        a,b=sol[0],sol[1]
+        c=1
+
+    return a,b,c,theta
+
+def find_angle_bisector(line_eq1,line_eq2):
+    """
+    line_equation follows same pattern as find_line_eq()
+    eq=[a,b,c,theta]
+    which refers to cy=ax+b
+    """
+    
\ No newline at end of file
-- 
GitLab