diff --git a/README.md b/README.md index 5b8ef67f9aea58f396745d81d85dc5dc1dbfc015..ba0f20afd96bb0335bf8d39e71771e1d513d989e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ ## ENGINEERING JOURNAL ### Jingyan Ling +### 08/16/2019 + +- Record of Tips: + - changing the clearance defined in `dsn` file changes the rule of routing + - useful to change it according wire length and isolation box size + - This will output multiple path + - Redo `sesreader` so that it will merge paths those connect to each other + ### 08/15/2019 - Solving issue: Connection between isolation box and parallel traces @@ -30,12 +38,18 @@ for pin_loc in all pin locations: if not such point is inside of two contacts: draw_list.append(points) iso_boundary.remove(point) - - - + + draw draw_list in order + return contact_list ~~~ +- Connection between isolation and parallel traces solved!!! +-  +- TODO: + - Merge DXF to path code + - Issue exposed: after changing wire width, box still not quite correct + - `roco_ee_dwg_processing.py` line 132 ### 08/14/2019 - Preparing software demo diff --git a/dsn_python/__pycache__/sesreader.cpython-36.pyc b/dsn_python/__pycache__/sesreader.cpython-36.pyc index c738f121a2aac9b303413eae593043f38769331e..2836bb72188143581e8be270b6e41dda50ff45a4 100644 Binary files a/dsn_python/__pycache__/sesreader.cpython-36.pyc and b/dsn_python/__pycache__/sesreader.cpython-36.pyc differ diff --git a/dsn_python/sesreader.py b/dsn_python/sesreader.py index 134ec0b468b9e4f7731c04d268ffd078c1457d5b..f934a0308deba362811ca46eec6f228e0803dcc0 100644 --- a/dsn_python/sesreader.py +++ b/dsn_python/sesreader.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import copy def find_wire(file_path): if not file_path.endswith('.ses'): file_path+='.ses' @@ -22,4 +23,39 @@ def find_wire(file_path): pts=[ptstart,ptend] onepath.append(pts) path_list.append(onepath) - return path_list \ No newline at end of file + + merged_path_list=[] + while len(path_list)!=0: + merged_path=path_list[0] + path_list.remove(merged_path) + flag=True + while flag: + s=merged_path[0] + e=merged_path[-1] + flag=False + for restpath in path_list: + s_=restpath[0] + e_=restpath[-1] + if s==s_ or s==e_ or e==s_ or e==e_: + to_merge_copy=copy.deepcopy(restpath) + #update merge path + if s==s_: + merged_path.remove(s) + merged_path=list(reversed(merged_path))+(to_merge_copy) + if s==e_: + merged_path.remove(s) + merged_path=to_merge_copy+(merged_path) + if e==s_: + merged_path.remove(e) + merged_path=(merged_path)+(to_merge_copy) + if e==e_: + merged_path.remove(e) + merged_path=to_merge_copy+(list(reversed(merged_path))) + + + path_list.remove(restpath) + flag=True + + merged_path_list.append(merged_path) + + return merged_path_list \ No newline at end of file diff --git a/journal_media/autorouter_w_clearance.png b/journal_media/autorouter_w_clearance.png new file mode 100644 index 0000000000000000000000000000000000000000..1d98cf6abd42313d3959a2fe09cb86a492b5643c Binary files /dev/null and b/journal_media/autorouter_w_clearance.png differ diff --git a/journal_media/iso_with_para.png b/journal_media/iso_with_para.png new file mode 100644 index 0000000000000000000000000000000000000000..8444456f971b6b3ec5ccd3f8d018527ed6a8eec3 Binary files /dev/null and b/journal_media/iso_with_para.png differ diff --git a/paperbot_ee_autoroute/__pycache__/paperbot_dsn.cpython-36.pyc b/paperbot_ee_autoroute/__pycache__/paperbot_dsn.cpython-36.pyc index 93faac16b35a0380d4b269be8dc0029dd885863a..4eccaed5adcaba8d027085f6a8f98fffe9eaf5c1 100644 Binary files a/paperbot_ee_autoroute/__pycache__/paperbot_dsn.cpython-36.pyc and b/paperbot_ee_autoroute/__pycache__/paperbot_dsn.cpython-36.pyc differ diff --git a/paperbot_ee_autoroute/__pycache__/roco_ee_dwg_processing.cpython-36.pyc b/paperbot_ee_autoroute/__pycache__/roco_ee_dwg_processing.cpython-36.pyc index 8dbca55a2e2353ecebe4502833e0278752dd2ef4..4e52e1349c9a14812ff2e610a20b46057df7c66b 100644 Binary files a/paperbot_ee_autoroute/__pycache__/roco_ee_dwg_processing.cpython-36.pyc and b/paperbot_ee_autoroute/__pycache__/roco_ee_dwg_processing.cpython-36.pyc differ diff --git a/paperbot_ee_autoroute/dwg_w_circuit.dxf b/paperbot_ee_autoroute/dwg_w_circuit.dxf index bd660e770dcc2287ea9dce01a46a4f777176fa75..1ed620ef8227a85de78e3d13251db2a112abfdb0 100644 --- a/paperbot_ee_autoroute/dwg_w_circuit.dxf +++ b/paperbot_ee_autoroute/dwg_w_circuit.dxf @@ -53,11 +53,11 @@ $HANDLING 9 $TDUPDATE 40 -2458710.699386574 +2458712.703472222 9 $HANDSEED 5 -329 +32A 9 $DWGCODEPAGE 3 @@ -4355,15 +4355,15 @@ LINE 5 2CB 8 -Cut +Circuit 10 -112.41 +119.51 20 -80.9 +60.065 11 -112.41 +119.7324 21 -82.4 +59.8426 6 DASHDOT 67 @@ -4373,15 +4373,15 @@ LINE 5 2CC 8 -Cut +Circuit 10 -113.91 +119.7324 20 -80.9 +59.8426 11 -113.91 +119.7324 21 -82.4 +36.57 6 DASHDOT 67 @@ -4391,15 +4391,15 @@ LINE 5 2CD 8 -Cut +Circuit 10 -112.41 +119.7324 20 -80.9 +36.57 11 -113.91 +119.51 21 -80.9 +36.57 6 DASHDOT 67 @@ -4411,13 +4411,13 @@ LINE 8 Circuit 10 -112.41 +118.7324 20 -82.4 +59.065 11 -112.41 +118.51 21 -69.7379601717798 +59.065 6 DASHDOT 67 @@ -4429,13 +4429,13 @@ LINE 8 Circuit 10 -113.91 +118.51 20 -82.4 +59.065 11 -113.91 +118.51 21 -69.11663982822016 +61.065 6 DASHDOT 67 @@ -4447,13 +4447,13 @@ LINE 8 Circuit 10 -112.40999999999998 +118.51 20 -69.7379601717798 +61.065 11 -106.3227398282202 +120.51 21 -63.65069999999999 +61.065 6 DASHDOT 67 @@ -4465,13 +4465,13 @@ LINE 8 Circuit 10 -113.91 +120.51 20 -69.11663982822017 +61.065 11 -106.94406017177984 +120.7324 21 -62.150699999999986 +59.065 6 DASHDOT 67 @@ -4483,13 +4483,13 @@ LINE 8 Circuit 10 -106.32273982822016 +118.7324 20 -63.65070000000001 +59.065 11 -91.55503982822017 +118.51 21 -63.6507 +59.065 6 DASHDOT 67 @@ -4501,13 +4501,13 @@ LINE 8 Circuit 10 -106.94406017177981 +118.51 20 -62.15070000000001 +59.065 11 -92.17636017177982 +118.51 21 -62.1507 +61.065 6 DASHDOT 67 @@ -4517,15 +4517,15 @@ LINE 5 2D4 8 -Cut +Circuit 10 -88.28 +118.51 20 -60.815 +61.065 11 -89.78 +120.51 21 -60.815 +61.065 6 DASHDOT 67 @@ -4535,15 +4535,15 @@ LINE 5 2D5 8 -Cut +Circuit 10 -89.78 +120.51 20 -59.315 +61.065 11 -89.78 +120.7324 21 -60.815 +59.065 6 DASHDOT 67 @@ -4553,15 +4553,15 @@ LINE 5 2D6 8 -Cut +Circuit 10 -88.28 +118.7324 20 -59.315 +59.065 11 -89.78 +118.73239999999998 21 -59.315 +37.570000000000014 6 DASHDOT 67 @@ -4573,13 +4573,13 @@ LINE 8 Circuit 10 -91.55503982822017 +120.7324 20 -63.6507 +59.065 11 -88.28 +120.73239999999998 21 -59.315 +35.570000000000014 6 DASHDOT 67 @@ -4591,13 +4591,13 @@ LINE 8 Circuit 10 -92.17636017177982 +118.73239999999998 20 -62.1507 +37.570000000000014 11 -88.28 +118.73239999999998 21 -60.815 +37.570000000000014 6 DASHDOT 67 @@ -4607,6 +4607,24 @@ LINE 5 2D9 8 +Circuit + 10 +120.73240000000001 + 20 +35.569999999999986 + 11 +120.73239999999998 + 21 +35.570000000000014 + 6 +DASHDOT + 67 +0 + 0 +LINE + 5 +2DA + 8 Cut 10 112.66 @@ -4621,7 +4639,7 @@ Cut 0 LINE 5 -2DA +2DB 8 Cut 10 @@ -4637,7 +4655,7 @@ Cut 0 LINE 5 -2DB +2DC 8 Cut 10 @@ -4653,7 +4671,7 @@ Cut 0 LINE 5 -2DC +2DD 8 Cut 10 @@ -4669,7 +4687,7 @@ Cut 0 LINE 5 -2DD +2DE 8 Cut 10 @@ -4685,7 +4703,7 @@ Cut 0 LINE 5 -2DE +2DF 8 Cut 10 @@ -4701,7 +4719,7 @@ Cut 0 LINE 5 -2DF +2E0 8 Cut 10 @@ -4717,7 +4735,7 @@ Cut 0 LINE 5 -2E0 +2E1 8 Cut 10 @@ -4733,7 +4751,7 @@ Cut 0 LINE 5 -2E1 +2E2 8 Cut 10 @@ -4749,7 +4767,7 @@ Cut 0 LINE 5 -2E2 +2E3 8 Cut 10 @@ -4765,7 +4783,7 @@ Cut 0 LINE 5 -2E3 +2E4 8 Cut 10 @@ -4781,7 +4799,7 @@ Cut 0 LINE 5 -2E4 +2E5 8 Cut 10 @@ -4797,7 +4815,7 @@ Cut 0 LINE 5 -2E5 +2E6 8 Cut 10 @@ -4813,7 +4831,7 @@ Cut 0 LINE 5 -2E6 +2E7 8 Cut 10 @@ -4829,7 +4847,7 @@ Cut 0 LINE 5 -2E7 +2E8 8 Cut 10 @@ -4845,7 +4863,7 @@ Cut 0 LINE 5 -2E8 +2E9 8 Cut 10 @@ -4861,7 +4879,7 @@ Cut 0 LINE 5 -2E9 +2EA 8 Cut 10 @@ -4877,7 +4895,7 @@ Cut 0 LINE 5 -2EA +2EB 8 Cut 10 @@ -4893,7 +4911,7 @@ Cut 0 LINE 5 -2EB +2EC 8 Cut 10 @@ -4909,7 +4927,7 @@ Cut 0 LINE 5 -2EC +2ED 8 Cut 10 @@ -4925,7 +4943,7 @@ Cut 0 LINE 5 -2ED +2EE 8 Cut 10 @@ -4941,7 +4959,7 @@ Cut 0 LINE 5 -2EE +2EF 8 Cut 10 @@ -4957,7 +4975,7 @@ Cut 0 LINE 5 -2EF +2F0 8 Cut 10 @@ -4973,7 +4991,7 @@ Cut 0 LINE 5 -2F0 +2F1 8 Cut 10 @@ -4989,7 +5007,7 @@ Cut 0 LINE 5 -2F1 +2F2 8 Cut 10 @@ -5005,7 +5023,7 @@ Cut 0 LINE 5 -2F2 +2F3 8 Cut 10 @@ -5021,7 +5039,7 @@ Cut 0 LINE 5 -2F3 +2F4 8 Cut 10 @@ -5037,7 +5055,7 @@ Cut 0 LINE 5 -2F4 +2F5 8 Cut 10 @@ -5053,7 +5071,7 @@ Cut 0 LINE 5 -2F5 +2F6 8 Cut 10 @@ -5069,7 +5087,7 @@ Cut 0 LINE 5 -2F6 +2F7 8 Cut 10 @@ -5085,7 +5103,7 @@ Cut 0 LINE 5 -2F7 +2F8 8 Cut 10 @@ -5101,7 +5119,7 @@ Cut 0 LINE 5 -2F8 +2F9 8 Cut 10 @@ -5117,7 +5135,7 @@ Cut 0 LINE 5 -2F9 +2FA 8 Cut 10 @@ -5133,7 +5151,7 @@ Cut 0 LINE 5 -2FA +2FB 8 Cut 10 @@ -5149,7 +5167,7 @@ Cut 0 LINE 5 -2FB +2FC 8 Cut 10 @@ -5165,7 +5183,7 @@ Cut 0 LINE 5 -2FC +2FD 8 Cut 10 @@ -5181,7 +5199,7 @@ Cut 0 LINE 5 -2FD +2FE 8 Cut 10 @@ -5197,7 +5215,7 @@ Cut 0 LINE 5 -2FE +2FF 8 Cut 10 @@ -5213,7 +5231,7 @@ Cut 0 LINE 5 -2FF +300 8 Cut 10 @@ -5229,7 +5247,7 @@ Cut 0 LINE 5 -300 +301 8 Cut 10 @@ -5245,7 +5263,7 @@ Cut 0 LINE 5 -301 +302 8 Cut 10 @@ -5261,7 +5279,7 @@ Cut 0 LINE 5 -302 +303 8 Cut 10 @@ -5277,7 +5295,7 @@ Cut 0 LINE 5 -303 +304 8 Cut 10 @@ -5293,7 +5311,7 @@ Cut 0 LINE 5 -304 +305 8 Cut 10 @@ -5309,7 +5327,7 @@ Cut 0 LINE 5 -305 +306 8 Cut 10 @@ -5325,7 +5343,7 @@ Cut 0 LINE 5 -306 +307 8 Cut 10 @@ -5341,7 +5359,7 @@ Cut 0 LINE 5 -307 +308 8 Cut 10 @@ -5357,7 +5375,7 @@ Cut 0 LINE 5 -308 +309 8 Cut 10 @@ -5373,7 +5391,7 @@ Cut 0 LINE 5 -309 +30A 8 Cut 10 @@ -5389,7 +5407,7 @@ Cut 0 LINE 5 -30A +30B 8 Cut 10 @@ -5405,7 +5423,7 @@ Cut 0 LINE 5 -30B +30C 8 Cut 10 @@ -5421,7 +5439,7 @@ Cut 0 LINE 5 -30C +30D 8 Cut 10 @@ -5437,7 +5455,7 @@ Cut 0 LINE 5 -30D +30E 8 Cut 10 @@ -5453,7 +5471,7 @@ Cut 0 LINE 5 -30E +30F 8 Cut 10 @@ -5469,7 +5487,7 @@ Cut 0 LINE 5 -30F +310 8 Cut 10 @@ -5485,7 +5503,7 @@ Cut 0 LINE 5 -310 +311 8 Cut 10 @@ -5501,7 +5519,7 @@ Cut 0 LINE 5 -311 +312 8 Cut 10 @@ -5517,7 +5535,7 @@ Cut 0 LINE 5 -312 +313 8 Cut 10 @@ -5533,7 +5551,7 @@ Cut 0 LINE 5 -313 +314 8 Cut 10 @@ -5549,7 +5567,7 @@ Cut 0 LINE 5 -314 +315 8 Cut 10 @@ -5565,7 +5583,7 @@ Cut 0 LINE 5 -315 +316 8 Cut 10 @@ -5581,7 +5599,7 @@ Cut 0 LINE 5 -316 +317 8 Cut 10 @@ -5597,7 +5615,7 @@ Cut 0 LINE 5 -317 +318 8 Cut 10 @@ -5613,7 +5631,7 @@ Cut 0 LINE 5 -318 +319 8 Cut 10 @@ -5629,7 +5647,7 @@ Cut 0 LINE 5 -319 +31A 8 Cut 10 @@ -5645,7 +5663,7 @@ Cut 0 LINE 5 -31A +31B 8 Cut 10 @@ -5661,7 +5679,7 @@ Cut 0 LINE 5 -31B +31C 8 Cut 10 @@ -5677,7 +5695,7 @@ Cut 0 LINE 5 -31C +31D 8 Cut 10 @@ -5693,7 +5711,7 @@ Cut 0 LINE 5 -31D +31E 8 Cut 10 @@ -5709,7 +5727,7 @@ Cut 0 LINE 5 -31E +31F 8 Cut 10 @@ -5725,7 +5743,7 @@ Cut 0 LINE 5 -31F +320 8 Cut 10 @@ -5741,7 +5759,7 @@ Cut 0 LINE 5 -320 +321 8 Cut 10 @@ -5757,7 +5775,7 @@ Cut 0 LINE 5 -321 +322 8 Cut 10 @@ -5773,7 +5791,7 @@ Cut 0 LINE 5 -322 +323 8 Cut 10 @@ -5789,7 +5807,7 @@ Cut 0 LINE 5 -323 +324 8 Cut 10 @@ -5805,7 +5823,7 @@ Cut 0 LINE 5 -324 +325 8 Cut 10 @@ -5821,7 +5839,7 @@ Cut 0 LINE 5 -325 +326 8 Cut 10 @@ -5837,7 +5855,7 @@ Cut 0 LINE 5 -326 +327 8 Cut 10 @@ -5853,7 +5871,7 @@ Cut 0 LINE 5 -327 +328 8 Cut 10 @@ -5869,7 +5887,7 @@ Cut 0 LINE 5 -328 +329 8 Cut 10 diff --git a/paperbot_ee_autoroute/fab_drawing.py b/paperbot_ee_autoroute/fab_drawing.py index 9931ad52c8087bce14bd111b507a63fe4ca5814b..fa351338e8b5b7b01973176d5c1a436a8e4a8b76 100644 --- a/paperbot_ee_autoroute/fab_drawing.py +++ b/paperbot_ee_autoroute/fab_drawing.py @@ -40,4 +40,5 @@ post_process(old.savename,wiring_path,ee_design.pins_at) # draw for fabrication os.remove(old.savename) os.remove(ready_for_autorouter.savename) os.remove(ee_design.savename+'.dsn') -os.remove(ee_design.savename+'.ses') \ No newline at end of file +os.remove(ee_design.savename+'.ses') +os.remove(ee_design.savename+'.rules') \ No newline at end of file diff --git a/paperbot_ee_autoroute/paperbot_dsn.py b/paperbot_ee_autoroute/paperbot_dsn.py index c782fb14c606b09665d919c676fd3d69a86823de..2249d2ddb8b41ae817ccaeefbe2a5fa0f534fb95 100644 --- a/paperbot_ee_autoroute/paperbot_dsn.py +++ b/paperbot_ee_autoroute/paperbot_dsn.py @@ -3,7 +3,6 @@ # sys.path.insert(1,'/home/jingyan/Documents/summer_intern_lemur/roco_electrical/dsn_python') import dsnwritier - class brd_design(): def __init__(self,boundary_inx,libpath,savename='paperbot_ee',dwgfile='dwg_for_autorouter.dxf'): print('generating board desng file (dsn) ......') @@ -17,12 +16,12 @@ class brd_design(): ['ESP12F-Devkit-V3.kicad_mod','U1',[103000,48000],90], ] self.netlist=[ - ['3v3',['U1-3','J1-1']], - ['VIN',['U1-1']], - ['NET1',['U1-2','J1-5']] + ['3v3',['U1-3']], + ['VIN',['U1-15','U1-16']], + ['NET1',['U1-2']] ] self.netclass_list=[ - ['default',['3v3','VIN','NET1'],'',1000,200] + ['default',['3v3','VIN','NET1'],'',2000,1200] ] self.brd_general() @@ -47,9 +46,9 @@ class brd_design(): self.rule=dsnwritier.Rule() clearance=[ - dsnwritier.Clearance(200.1), - dsnwritier.Clearance(200.1,'default_smd'), - dsnwritier.Clearance(50,'smd_smd')] + dsnwritier.Clearance(1000.1), + dsnwritier.Clearance(1000.1,'default_smd'), + dsnwritier.Clearance(1200,'smd_smd')] self.rule.clearance=clearance diff --git a/paperbot_ee_autoroute/paperbot_ee.rules b/paperbot_ee_autoroute/paperbot_ee.rules deleted file mode 100644 index 8454b7c5dfaf3f9727d6b4991c74c883dffa7504..0000000000000000000000000000000000000000 --- a/paperbot_ee_autoroute/paperbot_ee.rules +++ /dev/null @@ -1,43 +0,0 @@ - -(rules PCB paperbot_ee - (snap_angle - fortyfive_degree - ) - (autoroute_settings - (fanout off) - (autoroute on) - (postroute on) - (vias on) - (via_costs 50) - (plane_via_costs 5) - (start_ripup_costs 100) - (start_pass_no 104) - (layer_rule F.Cu - (active on) - (preferred_direction vertical) - (preferred_direction_trace_costs 1.0) - (against_preferred_direction_trace_costs 2.3) - ) - ) - (rule - (width 1000.0) - (clear 200.0) - (clear 125.0 (type smd_to_turn_gap)) - (clear 200.2 (type default_smd)) - (clear 50.0 (type smd_smd)) - ) - (via_rule - default - ) - (class default - 3v3 VIN NET1 - (clearance_class default) - (via_rule default) - (rule - (width 1000.0) - ) - (circuit - (use_layer F.Cu) - ) - ) -) \ No newline at end of file diff --git a/paperbot_ee_autoroute/roco_ee_dwg_processing.py b/paperbot_ee_autoroute/roco_ee_dwg_processing.py index 58bffe25f3a62d35a01d36ffab5e26b0a7c19a1e..31873a0f01708952ea85955687c3eb787e2c076a 100644 --- a/paperbot_ee_autoroute/roco_ee_dwg_processing.py +++ b/paperbot_ee_autoroute/roco_ee_dwg_processing.py @@ -34,8 +34,8 @@ class post_process(): self.msp=self.dwg.modelspace() self.convert_unitfrom_ses() - # self.draw_wires() - self.parallel_trace(1.5) + self.draw_wires() + self.parallel_trace(2,2) self.draw_cross_cut(1) @@ -54,58 +54,64 @@ class post_process(): 'layer':'Circuit', 'linetype':'DASHDOT'}) - def parallel_trace(self,width): + def parallel_trace(self,width,iso_size): for path in self.wiring: - # path=self.wiring[0] + constrain=True + if distance_between_pts(path[0],path[1])<(iso_size/2)*sqrt(2): + path.pop(0) + path.pop(1) + constrain=False + if distance_between_pts(path[-1],path[-2])<(iso_size/2)*sqrt(2): + path.pop(-1) + path.pop(-2) + constrain=False for i in range(len(path)-1): pt1=path[i][0],path[i][1] pt2=path[i+1][0],path[i+1][1] l1=find_line_eq(pt1,pt2) - if i<len(path)-2: #before last line + if i<len(path)-3: #before last line pt3=path[i+2][0],path[i+2][1] l2=find_line_eq(pt2,pt3) - #filter bi-sector _bi=find_angle_bisector(l1,l2) for sector in _bi: if if_two_pt_on_diff_side(sector,pt1,pt3): bi=sector - - if i==0: # if the first point - s1,s2=self.find_iso_bry(width,pt1,pt2) - offl1_in,offl1_out=find_offset(l1,width) - # if l1[2]==0: - # s1=[pt1[0]-width/2,pt1[1]] - # s2=[pt1[0]+width/2,pt1[1]] - # else: - # s1=[pt1[0],offl1_in[0]*pt1[0]+offl1_in[1]] - # s2=[pt1[0],offl1_out[0]*pt1[0]+offl1_out[1]] - + print(i) + try: + s1 + s2 + except UnboundLocalError: + + if not self.find_iso_bry(pt1,pt2,iso_size,width,constrain)=='Invalid': + s1,s2=self.find_iso_bry(pt1,pt2,iso_size,width,constrain) + print(s1,s2) + offl1_in,offl1_out=find_offset(l1,width) + constrain=True + else: + print('invalid') + constrain=False + continue offl2_in,offl2_out=find_offset(l2,width) - + + e1=find_intersect(offl1_in,bi) e2=find_intersect(offl1_out,bi) else: - e1,e2=self.find_iso_bry(width,pt2,pt1) - # if l1[2]==0: - # e1=[pt2[0]-width/2,pt2[1]] - # e2=[pt2[0]+width/2,pt2[1]] - # else: - # e1=[pt2[0],offl1_in[0]*pt2[0]+offl1_in[1]] - # e2=[pt2[0],offl1_out[0]*pt2[0]+offl1_out[1]] + last_bry_invalid=self.find_iso_bry(pt2,pt1,iso_size,width,constrain) + + if type(last_bry_invalid)!=type(None) and last_bry_invalid!='Invalid': + e1,e2=last_bry_invalid[0],last_bry_invalid[1] - self.msp.add_line(s1,e1,dxfattribs={ 'layer':'Circuit', 'linetype':'DASHDOT'}) self.msp.add_line(s2,e2,dxfattribs={ 'layer':'Circuit', - 'linetype':'DASHDOT'}) - - + 'linetype':'DASHDOT'}) if i<len(path)-2: if list(e1)==list(find_intersect(offl2_out,bi)): offl1_out,offl1_in=find_offset(l2,width) @@ -113,37 +119,59 @@ class post_process(): offl1_in,offl1_out=find_offset(l2,width) s1=find_intersect(offl1_in,bi) s2=find_intersect(offl1_out,bi) - + def draw_cross_cut(self,size): for module_pin in self.pin_at: cross_cut(self.msp,size,module_pin) - def find_iso_bry(self,width,endpoint1,endpoint2): - tolerance=0.05 - ept=endpoint1 - l=find_line_eq(endpoint1,endpoint2) + def find_iso_bry(self,contact_ept,further_ept,size,width,constrain=True): + tolerance=(size/2)*sqrt(2) + contact_list=[] for module_pin in self.pin_at: for pin in module_pin: - if (sqrt((ept[0]-pin[0])**2+(ept[1]-pin[1])**2)) <= tolerance: - #endpoint 1 is connect to such pin - four_l_points=isolation_box_linepts(width,pin) - for line_pts in four_l_points: - pt1,pt2=line_pts[0],line_pts[1] - iso_line=find_line_eq(pt1,pt2) - inter=find_intersect(iso_line,l) - if type(inter)!=type(None): - if inter[0]>= pt1[0] and inter[0]<=pt2[0] and inter[1]>=pt1[1] and inter[1] <=pt2[1]: - #such edge intersect with the path - draw_pt1=pt1 - draw_pt2=pt2 - four_l_points.remove(line_pts) - break - for line_pts in four_l_points: - p1,p2=line_pts[0],line_pts[1] - self.msp.add_line(p1,p2,dxfattribs={'linetype':'DASHDOT', 'layer':'Cut'}) - return draw_pt1,draw_pt2 + if distance_between_pts(contact_ept,pin) <= tolerance: + l=find_line_eq(contact_ept,further_ept) + parallel_traces=find_offset(l,width) + four_l_points=isolation_box_linepts(size,pin) + iso_points=isolation_box_linepts(size,pin,False) + if point_is_in_two_pts(further_ept,iso_points[0],iso_points[2]): + return 'Invalid' + contact_list=[] + for pl in parallel_traces: + contact=find_contact_iso_trace(pl,four_l_points,further_ept,constrain) + contact_list.append(contact) + + draw_list=[contact_list[0]] + draw_temp=None + while len(iso_points)!=0: + dis_=[] + for point in iso_points: + dis=distance_between_pts(point,draw_list[-1]) + dis_.append(dis) + closest_pt=iso_points[np.argmin(dis_)] + + contact_l=np.round(find_line_eq(contact_list[0],contact_list[1])) + draw_l=np.round(find_line_eq(closest_pt,draw_list[-1])) + if tuple(contact_l)==tuple(draw_l) and point_is_in_two_pts(contact_list[1],closest_pt,draw_list[-1]): + draw_temp=closest_pt + else: + if not point_is_in_two_pts(closest_pt,contact_list[0],contact_list[1]): + draw_list.append(closest_pt) + iso_points.remove(closest_pt) + + if type(draw_temp)!=type(None): + draw_list.append(draw_temp) + + draw_list.append(contact_list[1]) + for i in range(len(draw_list)-1): + self.msp.add_line(draw_list[i],draw_list[i+1],dxfattribs={'linetype':'DASHDOT', 'layer':'Circuit'}) + + if len(contact_list)!=0: + return contact_list[0],contact_list[1] + else: + return None -def find_contact_iso_trace(trace_line,iso_l_pts,further_ept): +def find_contact_iso_trace(trace_line,iso_l_pts,further_ept,constrain=True): inter_temp=[] for l_pts in iso_l_pts: pt1=l_pts[0] @@ -151,22 +179,26 @@ def find_contact_iso_trace(trace_line,iso_l_pts,further_ept): l=find_line_eq(pt1,pt2) inter=find_intersect(l,trace_line) if type(inter)!=type(None): - if inter[0]>= pt1[0] and inter[0]<=pt2[0] and inter[1]>=pt1[1] and inter[1] <=pt2[1]: + if constrain: + if point_is_in_two_pts(inter,pt1,pt2): + inter_temp.append(inter) + else: inter_temp.append(inter) dis_arr=[] + for p in inter_temp: - dis=sqrt((p[0]-further_ept[0])**2+(p[1]-further_ept[1])**2) + dis=distance_between_pts(p,further_ept) dis_arr.append(dis) contact=inter_temp[np.argmin(dis_arr)] return contact -def isolation_box_linepts(box_size,pt): +def isolation_box_linepts(box_size,pin_loc,return_line=True): """ box_size= lenght of isoloation box """ tipat=box_size/2 - x=pt[0] - y=pt[1] + x=pin_loc[0] + y=pin_loc[1] a=(x-tipat,y-tipat) b=(x-tipat,y+tipat) c=(x+tipat,y+tipat) @@ -175,7 +207,10 @@ def isolation_box_linepts(box_size,pt): l2=[b,c] l3=[d,c] l4=[a,d] - return [l1,l2,l3,l4] + if return_line: + return [l1,l2,l3,l4] + else: + return [a,b,c,d] def cross_cut(msp,cross_size,pin_loc): """ cross_size= lenght of bounding box of the cross cut @@ -191,7 +226,23 @@ def cross_cut(msp,cross_size,pin_loc): msp.add_line(cross_s1,cross_e1,dxfattribs={'layer':'Cut'}) msp.add_line(cross_s2,cross_e2,dxfattribs={'layer':'Cut'}) - +def distance_between_pts(pt1,pt2): + x1,y1=pt1[0],pt1[1] + x2,y2=pt2[0],pt2[1] + dis= sqrt((x1-x2)**2+(y1-y2)**2) + return dis +def point_is_in_two_pts(pt,pt1,pt2,tolerance=0.05): + + x=pt[0] + y=pt[1] + x1=np.min([pt1[0],pt2[0]])-tolerance + x2=np.max([pt1[0],pt2[0]])+tolerance + y1=np.min([pt1[1],pt2[1]])-tolerance + y2=np.max([pt1[1],pt2[1]])+tolerance + if x>= x1 and x<=x2 and y>=y1 and y <=y2: + return True + else: + return False def find_line_eq(pt1,pt2): """ input: two points on a line @@ -231,7 +282,8 @@ def find_intersect(line_eq1,line_eq2): a2,b2,c2=line_eq2[0],line_eq2[1],line_eq2[2] if c1==0 and c2==0: return None - if a1==a2: + + if a1==a2 and c1!=0 and c2!=0: #parallel lines return None else: