From 8a45c6d8d6e3650eae1de0afae362a9b8df60bf1 Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 6 Mar 2026 23:31:44 -0800 Subject: [PATCH] [tutorial] update pather and renderpather tutorials to new syntax --- examples/tutorial/pather.py | 45 +++++++++++++++---------------- examples/tutorial/renderpather.py | 22 +++++++-------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/examples/tutorial/pather.py b/examples/tutorial/pather.py index a9d9af9..f7bbdb2 100644 --- a/examples/tutorial/pather.py +++ b/examples/tutorial/pather.py @@ -106,7 +106,9 @@ def map_layer(layer: layer_t) -> layer_t: 'M2': (20, 0), 'V1': (30, 0), } - return layer_mapping.get(layer, layer) + if isinstance(layer, str): + return layer_mapping.get(layer, layer) + return layer def prepare_tools() -> tuple[Library, Tool, Tool]: @@ -224,19 +226,17 @@ def main() -> None: # Path VCC forward (in this case south) and turn clockwise 90 degrees (ccw=False) # The total distance forward (including the bend's forward component) must be 6um - pather.path('VCC', ccw=False, length=6_000) + pather.cw('VCC', 6_000) - # Now path VCC to x=0. This time, don't include any bend (ccw=None). + # Now path VCC to x=0. This time, don't include any bend. # Note that if we tried y=0 here, we would get an error since the VCC port is facing in the x-direction. - pather.path_to('VCC', ccw=None, x=0) + pather.straight('VCC', x=0) # Path GND forward by 5um, turning clockwise 90 degrees. - # This time we use shorthand (bool(0) == False) and omit the parameter labels - # Note that although ccw=0 is equivalent to ccw=False, ccw=None is not! - pather.path('GND', 0, 5_000) + pather.cw('GND', 5_000) # This time, path GND until it matches the current x-coordinate of VCC. Don't place a bend. - pather.path_to('GND', None, x=pather['VCC'].offset[0]) + pather.straight('GND', x=pather['VCC'].offset[0]) # Now, start using M1_tool for GND. # Since we have defined an M2-to-M1 transition for Pather, we don't need to place one ourselves. @@ -244,7 +244,7 @@ def main() -> None: # and achieve the same result without having to define any transitions in M1_tool. # Note that even though we have changed the tool used for GND, the via doesn't get placed until # the next time we draw a path on GND (the pather.mpath() statement below). - pather.retool(M1_tool, keys=['GND']) + pather.retool(M1_tool, keys='GND') # Bundle together GND and VCC, and path the bundle forward and counterclockwise. # Pick the distance so that the leading/outermost wire (in this case GND) ends up at x=-10_000. @@ -252,7 +252,7 @@ def main() -> None: # # Since we recently retooled GND, its path starts with a via down to M1 (included in the distance # calculation), and its straight segment and bend will be drawn using M1 while VCC's are drawn with M2. - pather.mpath(['GND', 'VCC'], ccw=True, xmax=-10_000, spacing=5_000) + pather.ccw(['GND', 'VCC'], xmax=-10_000, spacing=5_000) # Now use M1_tool as the default tool for all ports/signals. # Since VCC does not have an explicitly assigned tool, it will now transition down to M1. @@ -262,35 +262,34 @@ def main() -> None: # The total extension (travel distance along the forward direction) for the longest segment (in # this case the segment being added to GND) should be exactly 50um. # After turning, the wire pitch should be reduced only 1.2um. - pather.mpath(['GND', 'VCC'], ccw=True, emax=50_000, spacing=1_200) + pather.ccw(['GND', 'VCC'], emax=50_000, spacing=1_200) # Make a U-turn with the bundle and expand back out to 4.5um wire pitch. - # Here, emin specifies the travel distance for the shortest segment. For the first mpath() call - # that applies to VCC, and for teh second call, that applies to GND; the relative lengths of the + # Here, emin specifies the travel distance for the shortest segment. For the first call + # that applies to VCC, and for the second call, that applies to GND; the relative lengths of the # segments depend on their starting positions and their ordering within the bundle. - pather.mpath(['GND', 'VCC'], ccw=False, emin=1_000, spacing=1_200) - pather.mpath(['GND', 'VCC'], ccw=False, emin=2_000, spacing=4_500) + pather.cw(['GND', 'VCC'], emin=1_000, spacing=1_200) + pather.cw(['GND', 'VCC'], emin=2_000, spacing=4_500) # Now, set the default tool back to M2_tool. Note that GND remains on M1 since it has been - # explicitly assigned a tool. We could `del pather.tools['GND']` to force it to use the default. + # explicitly assigned a tool. pather.retool(M2_tool) # Now path both ports to x=-28_000. - # When ccw is not None, xmin constrains the trailing/innermost port to stop at the target x coordinate, - # However, with ccw=None, all ports stop at the same coordinate, and so specifying xmin= or xmax= is + # With ccw=None, all ports stop at the same coordinate, and so specifying xmin= or xmax= is # equivalent. - pather.mpath(['GND', 'VCC'], None, xmin=-28_000) + pather.straight(['GND', 'VCC'], xmin=-28_000) # Further extend VCC out to x=-50_000, and specify that we would like to get an output on M1. # This results in a via at the end of the wire (instead of having one at the start like we got # when using pather.retool(). - pather.path_to('VCC', None, -50_000, out_ptype='m1wire') + pather.straight('VCC', x=-50_000, out_ptype='m1wire') # Now extend GND out to x=-50_000, using M2 for a portion of the path. # We can use `pather.toolctx()` to temporarily retool, instead of calling `retool()` twice. - with pather.toolctx(M2_tool, keys=['GND']): - pather.path_to('GND', None, -40_000) - pather.path_to('GND', None, -50_000) + with pather.toolctx(M2_tool, keys='GND'): + pather.straight('GND', x=-40_000) + pather.straight('GND', x=-50_000) # Save the pather's pattern into our library library['Pather_and_AutoTool'] = pather.pattern diff --git a/examples/tutorial/renderpather.py b/examples/tutorial/renderpather.py index ecc8bc8..7b75f5d 100644 --- a/examples/tutorial/renderpather.py +++ b/examples/tutorial/renderpather.py @@ -48,28 +48,28 @@ def main() -> None: rpather.pattern.label(layer='M2', string='GND', offset=(18e3, 60e3)) # ...and start routing the signals. - rpather.path('VCC', ccw=False, length=6_000) - rpather.path_to('VCC', ccw=None, x=0) - rpather.path('GND', 0, 5_000) - rpather.path_to('GND', None, x=rpather['VCC'].x) + rpather.cw('VCC', 6_000) + rpather.straight('VCC', x=0) + rpather.cw('GND', 5_000) + rpather.straight('GND', x=rpather.pattern['VCC'].x) # `PathTool` doesn't know how to transition betwen metal layers, so we have to # `plug` the via into the GND wire ourselves. rpather.plug('v1_via', {'GND': 'top'}) - rpather.retool(M1_ptool, keys=['GND']) - rpather.mpath(['GND', 'VCC'], ccw=True, xmax=-10_000, spacing=5_000) + rpather.retool(M1_ptool, keys='GND') + rpather.ccw(['GND', 'VCC'], xmax=-10_000, spacing=5_000) # Same thing on the VCC wire when it goes down to M1. rpather.plug('v1_via', {'VCC': 'top'}) rpather.retool(M1_ptool) - rpather.mpath(['GND', 'VCC'], ccw=True, emax=50_000, spacing=1_200) - rpather.mpath(['GND', 'VCC'], ccw=False, emin=1_000, spacing=1_200) - rpather.mpath(['GND', 'VCC'], ccw=False, emin=2_000, spacing=4_500) + rpather.ccw(['GND', 'VCC'], emax=50_000, spacing=1_200) + rpather.cw(['GND', 'VCC'], emin=1_000, spacing=1_200) + rpather.cw(['GND', 'VCC'], emin=2_000, spacing=4_500) # And again when VCC goes back up to M2. rpather.plug('v1_via', {'VCC': 'bottom'}) rpather.retool(M2_ptool) - rpather.mpath(['GND', 'VCC'], None, xmin=-28_000) + rpather.straight(['GND', 'VCC'], xmin=-28_000) # Finally, since PathTool has no conception of transitions, we can't # just ask it to transition to an 'm1wire' port at the end of the final VCC segment. @@ -80,7 +80,7 @@ def main() -> None: # alternatively, via_size = v1pat.ports['top'].measure_travel(v1pat.ports['bottom'])[0][0] # would take into account the port orientations if we didn't already know they're along x - rpather.path_to('VCC', None, -50_000 + via_size) + rpather.straight('VCC', x=-50_000 + via_size) rpather.plug('v1_via', {'VCC': 'top'}) # Render the path we defined