Skip to content

Commit

Permalink
[Diff][Added] New mode where we can control the added/removed colors
Browse files Browse the repository at this point in the history
Also fixed the "zones" options help message, altered while creating
a base class
Closes #551
  • Loading branch information
set-soft committed Jan 10, 2024
1 parent 58c54a1 commit 2ccb54b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Explain about wrong dir/output separation (#493)
- Diff:
- Added option to un/fill zones before doing the comparison (See #391)
- Added a new mode where we can control the added/removed colors (#551)

### Changed
- Documentation:
Expand Down
9 changes: 7 additions & 2 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,17 @@ outputs:
always_fail_if_missing: false
# [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache
cache_dir: ''
# [string='#00FF00'] Color used for the added stuff in the '2color' mode
color_added: '#00FF00'
# [string='#FF0000'] Color used for the removed stuff in the '2color' mode
color_removed: '#FF0000'
# [boolean=false] Modifies the behavior of `add_link_id` to create a copy of the file instead of a
# symlink. Useful for some Windows setups
copy_instead_of_link: false
# [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
# [string='red_green'] [red_green,stats,2color] In the `red_green` mode added stuff is green and red when removed.
# The `stats` mode is used to measure the amount of difference. In this mode all
# changes are red, but you can abort if the difference is bigger than certain threshold
# changes are red, but you can abort if the difference is bigger than certain threshold.
# The '2color' mode is like 'red_green', but you can customize the colors
diff_mode: 'red_green'
# [string|list(string)='_none'] Name of the filter to mark components as not fitted.
# A short-cut to use for simple cases where a variant is an overkill
Expand Down
5 changes: 4 additions & 1 deletion docs/source/configuration/outputs/diff.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ Parameters:
So if you refer to a repo point where the file wasn't created KiBot will use an empty file.
Enabling this option KiBot will report an error.
- ``cache_dir`` :index:`: <pair: output - diff - options; cache_dir>` [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache.
- ``color_added`` :index:`: <pair: output - diff - options; color_added>` [string='#00FF00'] Color used for the added stuff in the '2color' mode.
- ``color_removed`` :index:`: <pair: output - diff - options; color_removed>` [string='#FF0000'] Color used for the removed stuff in the '2color' mode.
- ``copy_instead_of_link`` :index:`: <pair: output - diff - options; copy_instead_of_link>` [boolean=false] Modifies the behavior of `add_link_id` to create a copy of the file instead of a
symlink. Useful for some Windows setups.
- ``diff_mode`` :index:`: <pair: output - diff - options; diff_mode>` [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
- ``diff_mode`` :index:`: <pair: output - diff - options; diff_mode>` [string='red_green'] [red_green,stats,2color] In the `red_green` mode added stuff is green and red when removed.
The `stats` mode is used to measure the amount of difference. In this mode all
changes are red, but you can abort if the difference is bigger than certain threshold.
The '2color' mode is like 'red_green', but you can customize the colors.
- ``dnf_filter`` :index:`: <pair: output - diff - options; dnf_filter>` [string|list(string)='_none'] Name of the filter to mark components as not fitted.
A short-cut to use for simple cases where a variant is an overkill.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- Optional to separate multiboard projects for general use
- Note: Official 1.3.0 release does not work, use my fork if 1.3.0 is the latest

`KiCad PCB/SCH Diff <https://github.com/INTI-CMNB/KiDiff>`__ :index:`: <pair: dependency; KiCad PCB/SCH Diff>` v2.5.1 |image12| |Auto-download|
`KiCad PCB/SCH Diff <https://github.com/INTI-CMNB/KiDiff>`__ :index:`: <pair: dependency; KiCad PCB/SCH Diff>` v2.5.3 |image12| |Auto-download|

- Mandatory for: `diff`, `kiri`

Expand Down
3 changes: 1 addition & 2 deletions kibot/out_any_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def __init__(self):
self.zones = 'global'
""" [global,fill,unfill,none] How to handle PCB zones. The default is *global* and means that we
fill zones if the *check_zone_fills* preflight is enabled. The *fill* option always forces
a refill, *unfill* forces a zone removal and *none* lets the zones unchanged.
Be careful with the *keep_generated* option when changing this setting """
a refill, *unfill* forces a zone removal and *none* lets the zones unchanged """
super().__init__()
self._expand_id = 'diff'
self._expand_ext = 'pdf'
Expand Down
16 changes: 12 additions & 4 deletions kibot/out_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
Dependencies:
- name: KiCad PCB/SCH Diff
version: 2.5.1
version: 2.5.3
role: mandatory
github: INTI-CMNB/KiDiff
command: kicad-diff.py
Expand Down Expand Up @@ -74,9 +74,10 @@ def __init__(self):
self.cache_dir = ''
""" Directory to cache the intermediate files. Leave it blank to disable the cache """
self.diff_mode = 'red_green'
""" [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
""" [red_green,stats,2color] In the `red_green` mode added stuff is green and red when removed.
The `stats` mode is used to measure the amount of difference. In this mode all
changes are red, but you can abort if the difference is bigger than certain threshold """
changes are red, but you can abort if the difference is bigger than certain threshold.
The '2color' mode is like 'red_green', but you can customize the colors """
self.fuzz = 5
""" [0,100] Color tolerance (fuzzyness) for the `stats` mode """
self.threshold = 0
Expand Down Expand Up @@ -108,7 +109,12 @@ def __init__(self):
""" Always fail if the old/new file doesn't exist. Currently we don't fail if they are from a repo.
So if you refer to a repo point where the file wasn't created KiBot will use an empty file.
Enabling this option KiBot will report an error """
self.color_added = '#00FF00'
""" Color used for the added stuff in the '2color' mode """
self.color_removed = '#FF0000'
""" Color used for the removed stuff in the '2color' mode """
super().__init__()
self.add_to_doc("zones", "Be careful with the cache when changing this setting")

def config(self, parent):
super().config(parent)
Expand All @@ -123,6 +129,7 @@ def config(self, parent):
raise KiPlotConfigurationError('`new` must be a single string for `{}` type'.format(self.new_type))
if self.old_type == 'multivar' and self.new_type != 'multivar':
raise KiPlotConfigurationError("`old_type` can't be `multivar` when `new_type` isn't (`{}`)".format(self.new_type))
self.validate_colors(['color_added', 'color_removed'])

def get_targets(self, out_dir):
return [self._parent.expand_filename(out_dir, self.output)]
Expand Down Expand Up @@ -457,7 +464,8 @@ def do_compare(self, old, old_type, new, new_type, name, name_ori):
# Compute the diff using the cache
cmd = [self.command, '--no_reader', '--new_file_hash', new_hash, '--old_file_hash', old_hash,
'--cache_dir', self.cache_dir, '--output_dir', dir_name, '--output_name', file_name,
'--diff_mode', self.diff_mode, '--fuzz', str(self.fuzz), '--no_exist_check']
'--diff_mode', self.diff_mode, '--fuzz', str(self.fuzz), '--no_exist_check',
'--added_2color', self.color_added, '--removed_2color', self.color_removed]
self.add_zones_ops(cmd)
if self.incl_file:
cmd.extend(['--layers', self.incl_file])
Expand Down
1 change: 1 addition & 0 deletions kibot/out_kiri.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self):
self.keep_generated = False
""" *Avoid PCB and SCH images regeneration. Useful for incremental usage """
super().__init__()
self.add_to_doc("zones", "Be careful with the *keep_generated* option when changing this setting")
self._kiri_mode = True

def config(self, parent):
Expand Down
2 changes: 1 addition & 1 deletion src/kibot-check
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ deps = '{\
"version": [\
2,\
5,\
1\
3\
]\
},\
{\
Expand Down

0 comments on commit 2ccb54b

Please sign in to comment.