From f4230bbd70f7d10ae4feb4851eb5d85efbf5562f Mon Sep 17 00:00:00 2001 From: CGrassin <42406777+CGrassin@users.noreply.github.com> Date: Tue, 14 Feb 2023 11:38:28 +0100 Subject: [PATCH 1/7] Added checkbox to ignore areas on other layers (implement #40) --- ViaStitching/FillArea.py | 10 ++- ViaStitching/FillAreaAction.py | 1 + ViaStitching/FillAreaDialog.py | 10 ++- ViaStitching/FillAreaTpl.fbp | 125 +++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 3 deletions(-) diff --git a/ViaStitching/FillArea.py b/ViaStitching/FillArea.py index 78d295e..d58d957 100644 --- a/ViaStitching/FillArea.py +++ b/ViaStitching/FillArea.py @@ -63,6 +63,7 @@ FillArea.FillArea().SetDebug().SetNetname("GND").SetStepMM(1.27).SetSizeMM(0.6). # with # SetDebug: Activate debug mode (print evolution of the board in ascii art) +# SetViaThroughAreas: Ignores areas on other layers # SetNetname: Change the netname to consider for the filling # (default is /GND or fallback to GND) # SetStepMM: Change step between Via (in mm) @@ -129,6 +130,7 @@ class FillArea: self.SetClearanceMM(0.2) self.only_selected_area = False self.delete_vias = False + self.via_through_areas = False if self.pcb is not None: for lnet in ["GND", "/GND"]: if self.pcb.FindNet(lnet) is not None: @@ -161,6 +163,10 @@ class FillArea: self.random = r return self + def SetViaThroughAreas(self, r): + self.via_through_areas = r + return self + def SetType(self, type): self.fill_type = type return self @@ -305,11 +311,11 @@ STEP = '-' if is_rule_exclude_via_area and (hit_test_area or hit_test_edge or hit_test_zone): return self.REASON_KEEPOUT # Collides with keepout/rules - elif (hit_test_area or hit_test_edge) and not is_rules_area: + elif (not self.via_through_areas) and (hit_test_area or hit_test_edge) and not is_rules_area: # Collides with another signal (e.g. on another layer) but not a rule zone return self.REASON_OTHER_SIGNAL - elif hit_test_zone and not is_rules_area: + elif (not self.via_through_areas) and hit_test_zone and not is_rules_area: # Check if the zone is higher priority than other zones of the target net in the same point # target_areas_on_same_layer = filter(lambda x: ((x.GetPriority() > area_priority) and (x.GetLayer() == area_layer) and (x.GetNetname().upper() == self.netname)), all_areas) target_areas_on_same_layer = filter(lambda x: ((x.GetPriority() > area_priority) and ( diff --git a/ViaStitching/FillAreaAction.py b/ViaStitching/FillAreaAction.py index 802d7de..8de119f 100644 --- a/ViaStitching/FillAreaAction.py +++ b/ViaStitching/FillAreaAction.py @@ -81,6 +81,7 @@ class FillAreaAction(pcbnew.ActionPlugin): if a.m_Debug.IsChecked(): fill.SetDebug() fill.SetRandom(a.m_Random.IsChecked()) + fill.SetViaThroughAreas(a.m_viaThroughAreas.IsChecked()) fill.SetType(a.m_cbFillType.GetStringSelection()) if a.m_only_selected.IsChecked(): fill.OnlyOnSelectedArea() diff --git a/ViaStitching/FillAreaDialog.py b/ViaStitching/FillAreaDialog.py index 1347fa1..e0a4d1c 100644 --- a/ViaStitching/FillAreaDialog.py +++ b/ViaStitching/FillAreaDialog.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ########################################################################### -## Python code generated with wxFormBuilder (version 3.10.1) +## Python code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) ## http://www.wxformbuilder.org/ ## ## PLEASE DO *NOT* EDIT THIS FILE! @@ -102,6 +102,14 @@ class FillAreaDialog ( wx.Dialog ): self.m_only_selected = wx.CheckBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) fgSizer1.Add( self.m_only_selected, 0, wx.ALL, 5 ) + self.m_staticText71 = wx.StaticText( self, wx.ID_ANY, u"Ignore areas on other layers", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText71.Wrap( -1 ) + + fgSizer1.Add( self.m_staticText71, 0, wx.ALL, 5 ) + + self.m_viaThroughAreas = wx.CheckBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer1.Add( self.m_viaThroughAreas, 0, wx.ALL, 5 ) + self.m_staticText7 = wx.StaticText( self, wx.ID_ANY, u"Debug mode", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText7.Wrap( -1 ) diff --git a/ViaStitching/FillAreaTpl.fbp b/ViaStitching/FillAreaTpl.fbp index d11834f..be8e59e 100644 --- a/ViaStitching/FillAreaTpl.fbp +++ b/ViaStitching/FillAreaTpl.fbp @@ -1147,6 +1147,131 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Ignore areas on other layers + 0 + + 0 + + + 0 + + 1 + m_staticText71 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + + 0 + + + 0 + + 1 + m_viaThroughAreas + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 wxALL|wxEXPAND From 04cca510363e8cf71144ef9b1ff07585c3084484 Mon Sep 17 00:00:00 2001 From: Jean-Samuel Reynaud Date: Tue, 21 Feb 2023 13:29:12 +0100 Subject: [PATCH 2/7] Adding v6.0 and v7.0 details branches --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index df50b71..d3fa651 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Please select the right branch according your KiCad version: - master for development version of KiCad - master for KiCad V6 (until python API changes in dev version of KiCad) - V5.1 for KiCad version 5.1.* + - v6.0 for KiCad version 6.0.* + - v7.0 for KiCad version 7.0.* # Know issues From ee90dca5ec9d5c8597ea2db4e54ea94bf861fbfc Mon Sep 17 00:00:00 2001 From: Jean-Samuel Reynaud Date: Tue, 21 Feb 2023 13:31:54 +0100 Subject: [PATCH 3/7] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3fa651..72ce31d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Please select the right branch according your KiCad version: - master for development version of KiCad - master for KiCad V6 (until python API changes in dev version of KiCad) - - V5.1 for KiCad version 5.1.* + - v5.1 for KiCad version 5.1.* - v6.0 for KiCad version 6.0.* - v7.0 for KiCad version 7.0.* From 088629418008272b451adff8770d5fe3b194b22f Mon Sep 17 00:00:00 2001 From: CGrassin <42406777+CGrassin@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:04:31 +0100 Subject: [PATCH 4/7] Fix issue #56 with safe random offset bound --- ViaStitching/FillArea.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ViaStitching/FillArea.py b/ViaStitching/FillArea.py index 3ff9fdf..6c5f8e2 100644 --- a/ViaStitching/FillArea.py +++ b/ViaStitching/FillArea.py @@ -764,8 +764,9 @@ STEP = '-' ran_y = 0 if self.random: - ran_x = (random.random() * l_clearance / 2.0) - (l_clearance / 4.0) - ran_y = (random.random() * l_clearance / 2.0) - (l_clearance / 4.0) + max_offset = max(self.step - (self.clearance + self.size), 0) / 2.0 + ran_x = (random.random() * max_offset) - (max_offset / 2.0) + ran_y = (random.random() * max_offset) - (max_offset / 2.0) self.AddVia(wxPoint(via.PosX + ran_x, via.PosY + ran_y), via.X, via.Y) via_placed += 1 From be7d2bce252e6d77d08a3b671ea8b0a3bd9dc060 Mon Sep 17 00:00:00 2001 From: CGrassin <42406777+CGrassin@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:59:24 +0100 Subject: [PATCH 5/7] Changed call to get tracks/pad clearance --- ViaStitching/FillArea.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ViaStitching/FillArea.py b/ViaStitching/FillArea.py index f472947..4512a02 100644 --- a/ViaStitching/FillArea.py +++ b/ViaStitching/FillArea.py @@ -645,7 +645,7 @@ STEP = '-' if self.debug: print("%s: Line %u" % (time.time(), currentframe().f_lineno)) for pad in all_pads: - local_offset = max(pad.GetLocalClearance(), self.clearance, max_target_area_clearance) + (self.size / 2) + local_offset = max(pad.GetOwnClearance(UNDEFINED_LAYER,""), self.clearance, max_target_area_clearance) + (self.size / 2) max_size = max(pad.GetSize().x, pad.GetSize().y) start_x = int(floor(((pad.GetPosition().x - (max_size / 2.0 + local_offset)) - origin.x) / l_clearance)) @@ -706,7 +706,7 @@ STEP = '-' opx = stop_x opy = stop_y - clearance = max(track.GetLocalClearance(""), self.clearance, max_target_area_clearance) + \ + clearance = max(track.GetOwnClearance(UNDEFINED_LAYER,""), self.clearance, max_target_area_clearance) + \ (self.size / 2) + (track.GetWidth() / 2) start_x = int(floor(((start_x - clearance) - origin.x) / l_clearance)) From 438f38c3a6491cdf6471b5033c549d84914d8998 Mon Sep 17 00:00:00 2001 From: Huang Rui Date: Thu, 6 Apr 2023 19:57:07 +0800 Subject: [PATCH 6/7] ViaStitching/FillArea.py: fix no vias placed under KiCad 7.0 - Call the API corresponding to kicad according to different versions Closes: https://github.com/jsreynaud/kicad-action-scripts/issues/62 Signed-off-by: Huang Rui --- ViaStitching/FillArea.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/ViaStitching/FillArea.py b/ViaStitching/FillArea.py index 4512a02..574f506 100644 --- a/ViaStitching/FillArea.py +++ b/ViaStitching/FillArea.py @@ -300,8 +300,17 @@ STEP = '-' point_to_test = wxPoint(via.PosX + dx, via.PosY + dy) hit_test_area = False - for layer_id in area.GetLayerSet().CuStack(): - hit_test_area = hit_test_area or area.HitTestFilledArea(layer_id, VECTOR2I(point_to_test)) # Collides with a filled area + if pcbnew.Version() < '7': + # below 7.0.0 + for layer_id in area.GetLayerSet().CuStack(): + hit_test_area = hit_test_area or area.HitTestFilledArea(layer_id, VECTOR2I(point_to_test)) # Collides with a filled area + else: + # 7.0.0 and above + for layer_id in area.GetLayerSet().CuStack(): + for i in range(0, area.Outline().OutlineCount()): + area_outline = area.Outline().Outline(i) + if area.GetLayerSet().Contains(layer_id) and (layer_id != Edge_Cuts): + hit_test_area = hit_test_area or area_outline.PointInside(VECTOR2I(point_to_test)) hit_test_edge = area.HitTestForEdge(VECTOR2I(point_to_test), 1) # Collides with an edge/corner try: hit_test_zone = area.HitTestInsideZone(VECTOR2I(point_to_test)) # Is inside a zone (e.g. KeepOut/Rules) @@ -423,7 +432,12 @@ STEP = '-' for zone in zones: if zone.IsOnLayer(layer_id): if poly_set is not None or not self.only_selected_area or zone.IsSelected(): - poly_set_layer.Append(zone.RawPolysList(layer_id)) + if pcbnew.Version() < '7': + # below 7.0.0 + poly_set_layer.Append(zone.RawPolysList(layer_id)) + else: + # 7.0.0 and above + poly_set_layer.Append(zone.Outline()) if poly_set is None: poly_set = poly_set_layer @@ -608,8 +622,16 @@ STEP = '-' # Offset is half the size of the via plus the clearance of the via or the area offset = 0 # Use an exact zone match point_to_test = wxPoint(int(current_x), int(current_y)) - hit_test_area = area.HitTestFilledArea( - area.GetLayer(), VECTOR2I(point_to_test), int(offset)) # Collides with a filled area + hit_test_area = False + if pcbnew.Version() < '7': + # below 7.0.0 + hit_test_area = area.HitTestFilledArea( + area.GetLayer(), VECTOR2I(point_to_test), int(offset)) # Collides with a filled area + else: + # 7.0.0 and above + for i in range(0, area.Outline().OutlineCount()): + area_outline = area.Outline().Outline(i) + hit_test_area = hit_test_area or area_outline.PointInside(VECTOR2I(point_to_test)) # Collides with an edge/corner hit_test_edge = area.HitTestForEdge(VECTOR2I(point_to_test), int(max(area_clearance, offset))) # test_result only remains true if the via is inside an area and not on an edge From bacdd3b4ab3590c6ca527306daa280c22914a5db Mon Sep 17 00:00:00 2001 From: Huang Rui Date: Thu, 6 Apr 2023 20:12:44 +0800 Subject: [PATCH 7/7] ViaStitching/FillArea.py: fix error on kicad version Signed-off-by: Huang Rui --- ViaStitching/FillArea.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ViaStitching/FillArea.py b/ViaStitching/FillArea.py index 574f506..614c182 100644 --- a/ViaStitching/FillArea.py +++ b/ViaStitching/FillArea.py @@ -300,7 +300,7 @@ STEP = '-' point_to_test = wxPoint(via.PosX + dx, via.PosY + dy) hit_test_area = False - if pcbnew.Version() < '7': + if Version() < '7': # below 7.0.0 for layer_id in area.GetLayerSet().CuStack(): hit_test_area = hit_test_area or area.HitTestFilledArea(layer_id, VECTOR2I(point_to_test)) # Collides with a filled area @@ -432,7 +432,7 @@ STEP = '-' for zone in zones: if zone.IsOnLayer(layer_id): if poly_set is not None or not self.only_selected_area or zone.IsSelected(): - if pcbnew.Version() < '7': + if Version() < '7': # below 7.0.0 poly_set_layer.Append(zone.RawPolysList(layer_id)) else: @@ -623,7 +623,7 @@ STEP = '-' offset = 0 # Use an exact zone match point_to_test = wxPoint(int(current_x), int(current_y)) hit_test_area = False - if pcbnew.Version() < '7': + if Version() < '7': # below 7.0.0 hit_test_area = area.HitTestFilledArea( area.GetLayer(), VECTOR2I(point_to_test), int(offset)) # Collides with a filled area