diff options
-rw-r--r-- | plugin/main_dialog.fbp | 199 | ||||
-rw-r--r-- | plugin/mesh_dialog.py | 27 | ||||
-rw-r--r-- | plugin/mesh_plugin_dialog.py | 21 |
3 files changed, 237 insertions, 10 deletions
diff --git a/plugin/main_dialog.fbp b/plugin/main_dialog.fbp index fa89819..a2c9594 100644 --- a/plugin/main_dialog.fbp +++ b/plugin/main_dialog.fbp @@ -45,7 +45,7 @@ <property name="minimum_size"></property>
<property name="name">MainDialog</property>
<property name="pos"></property>
- <property name="size">765,659</property>
+ <property name="size">809,762</property>
<property name="style">wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSTAY_ON_TOP</property>
<property name="subclass">; ; forward_declare</property>
<property name="title">Security Mesh Generator Plugin</property>
@@ -2447,6 +2447,203 @@ <property name="window_style"></property>
</object>
</object>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
+ <property name="flag">wxALL</property>
+ <property name="proportion">0</property>
+ <object class="wxStaticText" expanded="1">
+ <property name="BottomDockable">1</property>
+ <property name="LeftDockable">1</property>
+ <property name="RightDockable">1</property>
+ <property name="TopDockable">1</property>
+ <property name="aui_layer"></property>
+ <property name="aui_name"></property>
+ <property name="aui_position"></property>
+ <property name="aui_row"></property>
+ <property name="best_size"></property>
+ <property name="bg"></property>
+ <property name="caption"></property>
+ <property name="caption_visible">1</property>
+ <property name="center_pane">0</property>
+ <property name="close_button">1</property>
+ <property name="context_help"></property>
+ <property name="context_menu">1</property>
+ <property name="default_pane">0</property>
+ <property name="dock">Dock</property>
+ <property name="dock_fixed">0</property>
+ <property name="docking">Left</property>
+ <property name="enabled">1</property>
+ <property name="fg"></property>
+ <property name="floatable">1</property>
+ <property name="font"></property>
+ <property name="gripper">0</property>
+ <property name="hidden">0</property>
+ <property name="id">wxID_ANY</property>
+ <property name="label">Routing randomness</property>
+ <property name="markup">0</property>
+ <property name="max_size"></property>
+ <property name="maximize_button">0</property>
+ <property name="maximum_size"></property>
+ <property name="min_size"></property>
+ <property name="minimize_button">0</property>
+ <property name="minimum_size"></property>
+ <property name="moveable">1</property>
+ <property name="name">m_staticText28</property>
+ <property name="pane_border">1</property>
+ <property name="pane_position"></property>
+ <property name="pane_size"></property>
+ <property name="permission">protected</property>
+ <property name="pin_button">1</property>
+ <property name="pos"></property>
+ <property name="resize">Resizable</property>
+ <property name="show">1</property>
+ <property name="size"></property>
+ <property name="style"></property>
+ <property name="subclass">; ; forward_declare</property>
+ <property name="toolbar_pane">0</property>
+ <property name="tooltip"></property>
+ <property name="window_extra_style"></property>
+ <property name="window_name"></property>
+ <property name="window_style"></property>
+ <property name="wrap">-1</property>
+ </object>
+ </object>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
+ <property name="flag">wxEXPAND</property>
+ <property name="proportion">1</property>
+ <object class="wxBoxSizer" expanded="1">
+ <property name="minimum_size"></property>
+ <property name="name">bSizer12</property>
+ <property name="orient">wxHORIZONTAL</property>
+ <property name="permission">none</property>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
+ <property name="flag">wxALL</property>
+ <property name="proportion">0</property>
+ <object class="wxSpinCtrlDouble" expanded="1">
+ <property name="BottomDockable">1</property>
+ <property name="LeftDockable">1</property>
+ <property name="RightDockable">1</property>
+ <property name="TopDockable">1</property>
+ <property name="aui_layer"></property>
+ <property name="aui_name"></property>
+ <property name="aui_position"></property>
+ <property name="aui_row"></property>
+ <property name="best_size"></property>
+ <property name="bg"></property>
+ <property name="caption"></property>
+ <property name="caption_visible">1</property>
+ <property name="center_pane">0</property>
+ <property name="close_button">1</property>
+ <property name="context_help"></property>
+ <property name="context_menu">1</property>
+ <property name="default_pane">0</property>
+ <property name="digits">0</property>
+ <property name="dock">Dock</property>
+ <property name="dock_fixed">0</property>
+ <property name="docking">Left</property>
+ <property name="enabled">1</property>
+ <property name="fg"></property>
+ <property name="floatable">1</property>
+ <property name="font"></property>
+ <property name="gripper">0</property>
+ <property name="hidden">0</property>
+ <property name="id">wxID_ANY</property>
+ <property name="inc">25</property>
+ <property name="initial">25</property>
+ <property name="max">100</property>
+ <property name="max_size"></property>
+ <property name="maximize_button">0</property>
+ <property name="maximum_size"></property>
+ <property name="min">0</property>
+ <property name="min_size"></property>
+ <property name="minimize_button">0</property>
+ <property name="minimum_size"></property>
+ <property name="moveable">1</property>
+ <property name="name">m_randomnessSpin</property>
+ <property name="pane_border">1</property>
+ <property name="pane_position"></property>
+ <property name="pane_size"></property>
+ <property name="permission">protected</property>
+ <property name="pin_button">1</property>
+ <property name="pos"></property>
+ <property name="resize">Resizable</property>
+ <property name="show">1</property>
+ <property name="size"></property>
+ <property name="style">wxSP_ARROW_KEYS</property>
+ <property name="subclass">; ; forward_declare</property>
+ <property name="toolbar_pane">0</property>
+ <property name="tooltip"></property>
+ <property name="value"></property>
+ <property name="window_extra_style"></property>
+ <property name="window_name"></property>
+ <property name="window_style"></property>
+ </object>
+ </object>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
+ <property name="flag">wxALL</property>
+ <property name="proportion">0</property>
+ <object class="wxStaticText" expanded="1">
+ <property name="BottomDockable">1</property>
+ <property name="LeftDockable">1</property>
+ <property name="RightDockable">1</property>
+ <property name="TopDockable">1</property>
+ <property name="aui_layer"></property>
+ <property name="aui_name"></property>
+ <property name="aui_position"></property>
+ <property name="aui_row"></property>
+ <property name="best_size"></property>
+ <property name="bg"></property>
+ <property name="caption"></property>
+ <property name="caption_visible">1</property>
+ <property name="center_pane">0</property>
+ <property name="close_button">1</property>
+ <property name="context_help"></property>
+ <property name="context_menu">1</property>
+ <property name="default_pane">0</property>
+ <property name="dock">Dock</property>
+ <property name="dock_fixed">0</property>
+ <property name="docking">Left</property>
+ <property name="enabled">1</property>
+ <property name="fg"></property>
+ <property name="floatable">1</property>
+ <property name="font"></property>
+ <property name="gripper">0</property>
+ <property name="hidden">0</property>
+ <property name="id">wxID_ANY</property>
+ <property name="label">% (percent)</property>
+ <property name="markup">0</property>
+ <property name="max_size"></property>
+ <property name="maximize_button">0</property>
+ <property name="maximum_size"></property>
+ <property name="min_size"></property>
+ <property name="minimize_button">0</property>
+ <property name="minimum_size"></property>
+ <property name="moveable">1</property>
+ <property name="name">m_staticText211</property>
+ <property name="pane_border">1</property>
+ <property name="pane_position"></property>
+ <property name="pane_size"></property>
+ <property name="permission">protected</property>
+ <property name="pin_button">1</property>
+ <property name="pos"></property>
+ <property name="resize">Resizable</property>
+ <property name="show">1</property>
+ <property name="size"></property>
+ <property name="style"></property>
+ <property name="subclass">; ; forward_declare</property>
+ <property name="toolbar_pane">0</property>
+ <property name="tooltip"></property>
+ <property name="window_extra_style"></property>
+ <property name="window_name"></property>
+ <property name="window_style"></property>
+ <property name="wrap">-1</property>
+ </object>
+ </object>
+ </object>
+ </object>
</object>
</object>
</object>
diff --git a/plugin/mesh_dialog.py b/plugin/mesh_dialog.py index 25c5b54..5e6dd9f 100644 --- a/plugin/mesh_dialog.py +++ b/plugin/mesh_dialog.py @@ -38,6 +38,7 @@ class GeneratorSettings: target_layer_id:int = 0 # kicad layer id, populated later mask_layer_id: int = 0 # kicad layer id, populated later random_seed: str = None + randomness: float = 1.0 class MeshPluginMainDialog(mesh_plugin_dialog.MainDialog): def __init__(self, board): @@ -129,7 +130,8 @@ class MeshPluginMainDialog(mesh_plugin_dialog.MainDialog): chamfer = float(self.m_chamferSpin.Value)/100.0, target_layer_id = self.m_layerChoice.GetSelection(), mask_layer_id = self.m_maskLayerChoice.GetSelection(), - random_seed = str(self.m_seedInput.Value) or None) + random_seed = str(self.m_seedInput.Value) or None, + randomness = float(self.m_randomnessSpin.Value)/100.0) except ValueError as e: return wx.MessageDialog(self, "Invalid input value: {}.".format(e), "Invalid input").ShowModal() @@ -268,12 +270,19 @@ class MeshPluginMainDialog(mesh_plugin_dialog.MainDialog): 0b0001: 0b0100, 0b0010: 0b1000, 0b0100: 0b0001, - 0b1000: 0b0010 + 0b1000: 0b0010, + 0b0000: 0b0000 }[mask] rnd_state = random.Random(settings.random_seed) - def random_iter(it): + def skewed_random_iter(it, mask, randomness): l = list(it) + if rnd_state.random() < 1.0 - randomness: + for x, y, m in l: + if m == mask: + yield x, y, m + break + l.remove((x, y, m)) rnd_state.shuffle(l) yield from l @@ -300,21 +309,23 @@ class MeshPluginMainDialog(mesh_plugin_dialog.MainDialog): x, y = exit_cell[1] visited = 0 key = 0 + entry_dir = 0 stack = [] while not_visited or stack: - for n_x, n_y, mask in random_iter(iter_neighbors(x, y)): + for n_x, n_y, bmask in skewed_random_iter(iter_neighbors(x, y), entry_dir, settings.randomness): if (n_x, n_y) in not_visited: dbg.add(grid[n_y][n_x], color=virihex(visited, max=num_to_visit), opacity=0.2) - key |= mask - stack.append((x, y, key)) + key |= bmask + stack.append((x, y, key, bmask)) not_visited.remove((n_x, n_y)) visited += 1 - x, y, key = n_x, n_y, reciprocal(mask) + x, y, key, entry_dir = n_x, n_y, reciprocal(bmask), bmask break else: for segment in Pattern.render(key, settings.num_traces, settings.chamfer): segment = affinity.scale(segment, grid_cell_width, grid_cell_width, origin=(0, 0)) segment = affinity.translate(segment, grid_origin[0] + x*grid_cell_width, grid_origin[1] + y*grid_cell_width) + segment = affinity.rotate(segment, settings.mesh_angle, origin=mask.centroid) stroke_color = { 0b0000: '#ff00ff80', 0b0001: '#ff000080', @@ -338,7 +349,7 @@ class MeshPluginMainDialog(mesh_plugin_dialog.MainDialog): track_count += 1 if not stack: break - *stack, (x, y, key) = stack + *stack, (x, y, key, entry_dir) = stack for foo in anchor_outlines: dbg.add(foo, color='#0000ff00', stroke_width=0.05, stroke_color='#000000ff') diff --git a/plugin/mesh_plugin_dialog.py b/plugin/mesh_plugin_dialog.py index ce11fd7..e83f6ca 100644 --- a/plugin/mesh_plugin_dialog.py +++ b/plugin/mesh_plugin_dialog.py @@ -17,7 +17,7 @@ import wx.xrc class MainDialog ( wx.Dialog ): def __init__( self, parent ): - wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Security Mesh Generator Plugin", pos = wx.DefaultPosition, size = wx.Size( 765,659 ), style = wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX|wx.RESIZE_BORDER|wx.STAY_ON_TOP ) + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Security Mesh Generator Plugin", pos = wx.DefaultPosition, size = wx.Size( 809,762 ), style = wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX|wx.RESIZE_BORDER|wx.STAY_ON_TOP ) self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) @@ -233,6 +233,25 @@ class MainDialog ( wx.Dialog ): self.m_anchorInput = wx.TextCtrl( self.m_scrolledWindow1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) fgSizer1.Add( self.m_anchorInput, 0, wx.ALL, 5 ) + self.m_staticText28 = wx.StaticText( self.m_scrolledWindow1, wx.ID_ANY, u"Routing randomness", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText28.Wrap( -1 ) + + fgSizer1.Add( self.m_staticText28, 0, wx.ALL, 5 ) + + bSizer12 = wx.BoxSizer( wx.HORIZONTAL ) + + self.m_randomnessSpin = wx.SpinCtrlDouble( self.m_scrolledWindow1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 100, 25, 25 ) + self.m_randomnessSpin.SetDigits( 0 ) + bSizer12.Add( self.m_randomnessSpin, 0, wx.ALL, 5 ) + + self.m_staticText211 = wx.StaticText( self.m_scrolledWindow1, wx.ID_ANY, u"% (percent)", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText211.Wrap( -1 ) + + bSizer12.Add( self.m_staticText211, 0, wx.ALL, 5 ) + + + fgSizer1.Add( bSizer12, 1, wx.EXPAND, 5 ) + self.m_scrolledWindow1.SetSizer( fgSizer1 ) self.m_scrolledWindow1.Layout() |