From 7e6154d9e9ae3bcb9cf337d54b0df4268a7d5f91 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 26 Jun 2023 09:33:08 -0300 Subject: [PATCH] [Position][Added] quote_all option - To quote all columns in the CSV output Closes #456 --- CHANGELOG.md | 2 ++ README.md | 1 + docs/samples/generic_plot.kibot.yaml | 2 ++ kibot/out_position.py | 12 ++++++++---- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d14c701a..fd2af2186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `skip_not_run`: used to skip outputs not generated in default runs. - Compress: - `skip_not_run`: used to skip outputs not generated in default runs. +- Position: + - `quote_all`: forces quotes to all values in the CSV output. (See #456) ### Changed - Command line: diff --git a/README.md b/README.md index e5c0f9617..cc10d07ab 100644 --- a/README.md +++ b/README.md @@ -4233,6 +4233,7 @@ Notes: For KiCad 6+ we replace this concept by the option to exclude from position file. - `pre_transform`: [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. A short-cut to use for simple cases where a variant is an overkill. + - `quote_all`: [boolean=false] When generating the CSV quote all values, even numbers. - `right_digits`: [number=4] number of digits for mantissa part of coordinates (0 is auto). - `use_aux_axis_as_origin`: [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default). - `variant`: [string=''] Board variant to apply. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 65989314a..1ed502ee3 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -2729,6 +2729,8 @@ outputs: # [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. # A short-cut to use for simple cases where a variant is an overkill pre_transform: '_none' + # [boolean=false] When generating the CSV quote all values, even numbers + quote_all: false # [number=4] number of digits for mantissa part of coordinates (0 is auto) right_digits: 4 # [boolean=true] Generate two separated files, one for the top and another for the bottom diff --git a/kibot/out_position.py b/kibot/out_position.py index d5d53b9ef..9a9a9769f 100644 --- a/kibot/out_position.py +++ b/kibot/out_position.py @@ -83,6 +83,8 @@ def __init__(self): """ Include virtual components. For special purposes, not pick & place. Note that virtual components is a KiCad 5 concept. For KiCad 6+ we replace this concept by the option to exclude from position file """ + self.quote_all = False + """ When generating the CSV quote all values, even numbers """ super().__init__() self._expand_id = 'position' @@ -234,6 +236,7 @@ def run(self, fname): modules_side = [] is_pure_smd, is_not_virtual = self.get_attr_tests() quote_char = '"' if self.format == 'CSV' else '' + quote_char_extra = quote_char if self.quote_all else '' x_origin = 0.0 y_origin = 0.0 if self.use_aux_axis_as_origin: @@ -285,13 +288,14 @@ def run(self, fname): pos_x = (center_x - x_origin) * conv if self.bottom_negative_x and is_bottom: pos_x = -pos_x - row.append(float_format.format(pos_x, rd=self.right_digits)) + row.append(quote_char_extra+float_format.format(pos_x, rd=self.right_digits)+quote_char_extra) elif k == 'PosY': - row.append(float_format.format(-(center_y - y_origin) * conv, rd=self.right_digits)) + row.append(quote_char_extra+float_format.format(-(center_y - y_origin) * conv, rd=self.right_digits) + + quote_char_extra) elif k == 'Rot': - row.append(float_format.format(rotation, rd=self.right_digits)) + row.append(quote_char_extra+float_format.format(rotation, rd=self.right_digits)+quote_char_extra) elif k == 'Side': - row.append("bottom" if is_bottom else "top") + row.append(quote_char_extra+("bottom" if is_bottom else "top")+quote_char_extra) modules.append(row) modules_side.append(is_bottom) else: