diff --git a/README.md b/README.md index 20a19fdb..ee857690 100644 --- a/README.md +++ b/README.md @@ -763,10 +763,13 @@ Next time you need this list just use an alias, like this: - `field`: [string=''] Name of the field. - `text`: [string=''] Text to use instead of a field. This option is incompatible with the `field` option. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `text_after`: [string=''] Text to add after the field content. Will be added only if the field isn't empty. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `text_before`: [string=''] Text to add before the field content. Will be added only if the field isn't empty. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `level`: [number=0] Used to group columns. The XLSX output uses it to collapse columns. - `name`: [string=''] Name to display in the header. The field is used when empty. - `component_aliases`: [list(list(string))] A series of values which are considered to be equivalent for the part name. @@ -789,10 +792,13 @@ Next time you need this list just use an alias, like this: - `field`: [string=''] Name of the field. - `text`: [string=''] Text to use instead of a field. This option is incompatible with the `field` option. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `text_after`: [string=''] Text to add after the field content. Will be added only if the field isn't empty. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `text_before`: [string=''] Text to add before the field content. Will be added only if the field isn't empty. Any space to separate it should be added in the text. + Use \n for newline and \t for tab. - `level`: [number=0] Used to group columns. The XLSX output uses it to collapse columns. - `name`: [string=''] Name to display in the header. The field is used when empty. - `count_smd_tht`: [boolean=false] Show the stats about how many of the components are SMD/THT. You must provide the PCB. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index f612e654..a8a69a2e 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -94,13 +94,16 @@ outputs: # [string=''] Name of the field - field: 'Voltage' # [string=''] Text to use instead of a field. This option is incompatible with the `field` option. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text: '' # [string=''] Text to add after the field content. Will be added only if the field isn't empty. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text_after: '' # [string=''] Text to add before the field content. Will be added only if the field isn't empty. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text_before: '' # [number=0] Used to group columns. The XLSX output uses it to collapse columns level: 0 @@ -129,13 +132,16 @@ outputs: # [string=''] Name of the field - field: 'Voltage' # [string=''] Text to use instead of a field. This option is incompatible with the `field` option. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text: '' # [string=''] Text to add after the field content. Will be added only if the field isn't empty. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text_after: '' # [string=''] Text to add before the field content. Will be added only if the field isn't empty. - # Any space to separate it should be added in the text + # Any space to separate it should be added in the text. + # Use \n for newline and \t for tab text_before: '' # [number=0] Used to group columns. The XLSX output uses it to collapse columns level: 0 diff --git a/kibot/out_bom.py b/kibot/out_bom.py index d94734f2..b0652a80 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -8,6 +8,7 @@ Internal BoM (Bill of Materials) output for KiBot. This is somehow compatible with KiBoM. """ import os +import re from .gs import GS from .misc import W_BADFIELD, W_NEEDSPCB from .optionable import Optionable, BaseOptions @@ -52,14 +53,24 @@ class BoMJoinField(Optionable): """ Name of the field """ self.text = '' """ Text to use instead of a field. This option is incompatible with the `field` option. - Any space to separate it should be added in the text """ + Any space to separate it should be added in the text. + Use \\n for newline and \\t for tab """ self.text_before = '' """ Text to add before the field content. Will be added only if the field isn't empty. - Any space to separate it should be added in the text """ + Any space to separate it should be added in the text. + Use \\n for newline and \\t for tab """ self.text_after = '' """ Text to add after the field content. Will be added only if the field isn't empty. - Any space to separate it should be added in the text """ + Any space to separate it should be added in the text. + Use \\n for newline and \\t for tab """ self._field_example = 'Voltage' + self._nl = re.compile(r'([^\\]|^)\\n') + self._tab = re.compile(r'([^\\]|^)\\t') + + def unescape(self, text): + text = self._nl.sub(r'\1\n', text) + text = self._tab.sub(r'\1\t', text) + return text def config(self, parent): super().config(parent) @@ -73,6 +84,9 @@ class BoMJoinField(Optionable): self.text_before = '' if self.text_after is None: self.text_after = '' + self.text = self.unescape(self.text) + self.text_before = self.unescape(self.text_before) + self.text_after = self.unescape(self.text_after) def get_text(self, field_getter): if self.text: diff --git a/tests/board_samples/kicad_5/join.sch b/tests/board_samples/kicad_5/join.sch index d3b4a856..1958b6c9 100644 --- a/tests/board_samples/kicad_5/join.sch +++ b/tests/board_samples/kicad_5/join.sch @@ -71,6 +71,7 @@ F 5 "C0805C102K5RACTU" H 3750 2500 50 0001 C CNN "manf#" F 6 "10%" H 3750 2500 50 0001 C CNN "Tolerance" F 7 "KEMET" H 3750 2500 50 0001 C CNN "manf" F 8 "50V" H 3750 2500 50 0001 C CNN "Voltage" +F 9 "Alternative" H 3750 2500 50 0001 C CNN "SMN1" 1 3750 2500 1 0 0 -1 $EndComp diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index 91936ea4..88dc0fb4 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -651,7 +651,7 @@ def test_int_bom_join_2(test_dir): value_column = header.index('Value') check_kibom_test_netlist(rows, ref_column, LINKS_GROUPS+1, [], LINKS_EXCLUDE+LINKS_COMPONENTS) assert rows[0][ref_column] == 'C1' - assert rows[0][value_column] == '1nF 10% - (50V)' + assert rows[0][value_column] == '1nF 10% - (50V)\nAlternative' assert rows[0][manf_column] == 'KEMET C0805C102K5RACTU' assert rows[1][ref_column] == 'J1 J2' assert rows[1][value_column] == 'Molex KK -' diff --git a/tests/yaml_samples/int_bom_join_2.kibot.yaml b/tests/yaml_samples/int_bom_join_2.kibot.yaml index 0ba1bf38..27bf0cdd 100644 --- a/tests/yaml_samples/int_bom_join_2.kibot.yaml +++ b/tests/yaml_samples/int_bom_join_2.kibot.yaml @@ -19,6 +19,8 @@ outputs: - field: 'Voltage' text_before: ' (' text_after: ')' + - field: 'SMN1' + text_before: '\n' - field: manf join: manf# - field: digikey#