Added global *units* option
Solves the KiCad 6 dimensions issue. See #146
This commit is contained in:
parent
ccbb8a6060
commit
b2ab00f6cb
|
|
@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Generic filter: options to match if a field is/isn't defined.
|
||||
- Excellon drill: added `route_mode_for_oval_holes` option.
|
||||
- Default global `dir` option.
|
||||
- Default global `units` option.
|
||||
- Global option to specify `out_dir` (like -d command line option)
|
||||
- 3D view render
|
||||
- SCH PDF Print: monochrome and no frame options.
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -26,6 +26,7 @@
|
|||
* [Default *output* option](#default-output-option)
|
||||
* [Default *dir* option](#default-dir-option)
|
||||
* [Default *variant* option](#default-variant-option)
|
||||
* [Default *units* option](#default-units-option)
|
||||
* [Output directory option](#output-directory-option)
|
||||
* [Date format option](#date-format-option)
|
||||
* [PCB details options](#pcb-details-options)
|
||||
|
|
@ -308,6 +309,14 @@ global:
|
|||
variant: 'production'
|
||||
```
|
||||
|
||||
#### Default *units* option
|
||||
|
||||
This option controls the default value for the `position` and `bom` outputs.
|
||||
If you don't define it then the internal defaults of each output are applied. But when you define it the default is the defined value.
|
||||
|
||||
On KiCad 6 the dimensions has units. When you create a new dimension it uses *automatic* units. This means that KiCad uses the units currently selected.
|
||||
This selection isn't stored in the PCB file. The global `units` value is used by KiBot instead.
|
||||
|
||||
#### Output directory option
|
||||
|
||||
The `out_dir` option can define the base outut directory. This is the same as the `-d`/`--out-dir` command line option.
|
||||
|
|
@ -904,6 +913,7 @@ Next time you need this list just use an alias, like this:
|
|||
- `sort_style`: [string='type_value'] [type_value,type_value_ref,ref] Sorting criteria.
|
||||
- `source_by_id`: [boolean=false] Generate the `Source BoM` column using the reference ID instead of the project name.
|
||||
- `units`: [string='millimeters'] [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns).
|
||||
Affected by global options.
|
||||
- `use_alt`: [boolean=false] Print grouped references in the alternate compressed style eg: R1-R7,R18.
|
||||
- `use_aux_axis_as_origin`: [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default) (for XYRS).
|
||||
- `variant`: [string=''] Board variant, used to determine which components
|
||||
|
|
@ -1637,7 +1647,7 @@ Next time you need this list just use an alias, like this:
|
|||
- `only_smd`: [boolean=true] Only include the surface mount components.
|
||||
- `output`: [string='%f-%i%I%v.%x'] Output file name (%i='top_pos'|'bottom_pos'|'both_pos', %x='pos'|'csv'). Affected by global options.
|
||||
- `separate_files_for_front_and_back`: [boolean=true] Generate two separated files, one for the top and another for the bottom.
|
||||
- `units`: [string='millimeters'] [millimeters,inches] Units used for the positions.
|
||||
- `units`: [string='millimeters'] [millimeters,inches,mils] Units used for the positions. Affected by global options.
|
||||
- `use_aux_axis_as_origin`: [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default).
|
||||
- `variant`: [string=''] Board variant to apply.
|
||||
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
* [Default *output* option](#default-output-option)
|
||||
* [Default *dir* option](#default-dir-option)
|
||||
* [Default *variant* option](#default-variant-option)
|
||||
* [Default *units* option](#default-units-option)
|
||||
* [Output directory option](#output-directory-option)
|
||||
* [Date format option](#date-format-option)
|
||||
* [PCB details options](#pcb-details-options)
|
||||
|
|
@ -243,6 +244,14 @@ global:
|
|||
variant: 'production'
|
||||
```
|
||||
|
||||
#### Default *units* option
|
||||
|
||||
This option controls the default value for the `position` and `bom` outputs.
|
||||
If you don't define it then the internal defaults of each output are applied. But when you define it the default is the defined value.
|
||||
|
||||
On KiCad 6 the dimensions has units. When you create a new dimension it uses *automatic* units. This means that KiCad uses the units currently selected.
|
||||
This selection isn't stored in the PCB file. The global `units` value is used by KiBot instead.
|
||||
|
||||
#### Output directory option
|
||||
|
||||
The `out_dir` option can define the base outut directory. This is the same as the `-d`/`--out-dir` command line option.
|
||||
|
|
|
|||
|
|
@ -255,7 +255,8 @@ outputs:
|
|||
sort_style: 'type_value'
|
||||
# [boolean=false] Generate the `Source BoM` column using the reference ID instead of the project name
|
||||
source_by_id: false
|
||||
# [string='millimeters'] [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns)
|
||||
# [string='millimeters'] [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns).
|
||||
# Affected by global options
|
||||
units: 'millimeters'
|
||||
# [boolean=false] Print grouped references in the alternate compressed style eg: R1-R7,R18
|
||||
use_alt: false
|
||||
|
|
@ -1075,7 +1076,7 @@ outputs:
|
|||
output: '%f-%i%I%v.%x'
|
||||
# [boolean=true] Generate two separated files, one for the top and another for the bottom
|
||||
separate_files_for_front_and_back: true
|
||||
# [string='millimeters'] [millimeters,inches] Units used for the positions
|
||||
# [string='millimeters'] [millimeters,inches,mils] Units used for the positions. Affected by global options
|
||||
units: 'millimeters'
|
||||
# [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default)
|
||||
use_aux_axis_as_origin: true
|
||||
|
|
|
|||
|
|
@ -379,6 +379,7 @@ class CfgYamlReader(object):
|
|||
GS.global_output = GS.global_from_cli.get('output', None)
|
||||
GS.global_dir = GS.global_from_cli.get('dir', None)
|
||||
GS.global_variant = GS.global_from_cli.get('variant', None)
|
||||
GS.global_units = GS.global_from_cli.get('units', None)
|
||||
GS.global_date_time_format = GS.global_from_cli.get('date_time_format', None)
|
||||
GS.global_date_format = GS.global_from_cli.get('date_format', None)
|
||||
GS.global_time_format = GS.global_from_cli.get('time_format', None)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ class Globals(FiltersOptions):
|
|||
""" Base output dir, same as command line `--out-dir` """
|
||||
self.variant = ''
|
||||
""" Default variant to apply to all outputs """
|
||||
self.units = ''
|
||||
""" [millimeters,inches,mils] Default units. Affects `position` and `bom` outputs. Also KiCad 6 dimensions """
|
||||
self.kiauto_wait_start = 0
|
||||
""" Time to wait for KiCad in KiAuto operations """
|
||||
self.kiauto_time_out_scale = 0.0
|
||||
|
|
|
|||
|
|
@ -210,6 +210,15 @@ class GS(object):
|
|||
r = m.GetFpPadsLocalBbox()
|
||||
return (r.GetWidth(), r.GetHeight())
|
||||
|
||||
@staticmethod
|
||||
def unit_name_to_scale_factor(units):
|
||||
if units == 'millimeters':
|
||||
return 1.0/pcbnew.IU_PER_MM
|
||||
if units == 'mils':
|
||||
return 1.0/pcbnew.IU_PER_MILS
|
||||
# Inches
|
||||
return 0.001/pcbnew.IU_PER_MILS
|
||||
|
||||
@staticmethod
|
||||
def ki6():
|
||||
return GS.kicad_version_n >= KICAD_VERSION_5_99
|
||||
|
|
|
|||
|
|
@ -214,6 +214,19 @@ def load_board(pcb_file=None):
|
|||
board = pcbnew.LoadBoard(pcb_file)
|
||||
if BasePreFlight.get_option('check_zone_fills'):
|
||||
pcbnew.ZONE_FILLER(board).Fill(board.Zones())
|
||||
if GS.global_units and GS.ki6():
|
||||
# In KiCad 6 "dimensions" has units.
|
||||
# The default value is DIM_UNITS_MODE_AUTOMATIC.
|
||||
# But this has a meaning only in the GUI where you have default units.
|
||||
# So now we have global.units and here we patch the board.
|
||||
UNIT_NAME_TO_INDEX = {'millimeters': pcbnew.DIM_UNITS_MODE_MILLIMETRES,
|
||||
'inches': pcbnew.DIM_UNITS_MODE_INCHES,
|
||||
'mils': pcbnew.DIM_UNITS_MODE_MILS}
|
||||
forced_units = UNIT_NAME_TO_INDEX[GS.global_units]
|
||||
for dr in board.GetDrawings():
|
||||
if dr.GetClass().startswith('PCB_DIM_') and dr.GetUnitsMode() == pcbnew.DIM_UNITS_MODE_AUTOMATIC:
|
||||
dr.SetUnitsMode(forced_units)
|
||||
dr.Update()
|
||||
GS.board = board
|
||||
except OSError as e:
|
||||
logger.error('Error loading PCB file. Corrupted?')
|
||||
|
|
|
|||
|
|
@ -42,10 +42,12 @@ class Optionable(object):
|
|||
self._expand_id = ''
|
||||
self._expand_ext = ''
|
||||
super().__init__()
|
||||
if GS.global_output is not None and getattr(self, 'output', None):
|
||||
setattr(self, 'output', GS.global_output)
|
||||
if GS.global_variant is not None and hasattr(self, 'variant'):
|
||||
setattr(self, 'variant', GS.global_variant)
|
||||
for var in ['output', 'variant', 'units']:
|
||||
glb = getattr(GS, 'global_'+var)
|
||||
if glb is not None and hasattr(self, var):
|
||||
setattr(self, var, glb)
|
||||
if GS.debug_level > 2:
|
||||
logger.debug('Using global `{}`=`{}`'.format(var, glb))
|
||||
|
||||
@staticmethod
|
||||
def _check_str(key, val, doc):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ This is somehow compatible with KiBoM.
|
|||
"""
|
||||
import os
|
||||
import re
|
||||
from pcbnew import IU_PER_MM, IU_PER_MILS
|
||||
from .gs import GS
|
||||
from .misc import W_BADFIELD, W_NEEDSPCB
|
||||
from .optionable import Optionable, BaseOptions
|
||||
|
|
@ -387,7 +386,8 @@ class BoMOptions(BaseOptions):
|
|||
self.count_smd_tht = False
|
||||
""" Show the stats about how many of the components are SMD/THT. You must provide the PCB """
|
||||
self.units = 'millimeters'
|
||||
""" [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns) """
|
||||
""" [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns).
|
||||
Affected by global options """
|
||||
self.bottom_negative_x = False
|
||||
""" Use negative X coordinates for footprints on bottom layer (for XYRS) """
|
||||
self.use_aux_axis_as_origin = True
|
||||
|
|
@ -611,12 +611,7 @@ class BoMOptions(BaseOptions):
|
|||
self.revision = GS.sch_rev
|
||||
self.debug_level = GS.debug_level
|
||||
self.kicad_version = GS.kicad_version
|
||||
if self.units == 'millimeters':
|
||||
self.conv_units = 1.0/IU_PER_MM
|
||||
elif self.units == 'mils':
|
||||
self.conv_units = 1.0/IU_PER_MILS
|
||||
else: # Inches
|
||||
self.conv_units = 0.001/IU_PER_MILS
|
||||
self.conv_units = GS.unit_name_to_scale_factor(self.units)
|
||||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
get_board_comps_data(comps)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
import os
|
||||
from re import compile
|
||||
from datetime import datetime
|
||||
from pcbnew import IU_PER_MM, IU_PER_MILS
|
||||
from collections import OrderedDict
|
||||
from .gs import GS
|
||||
from .misc import UI_SMD, UI_VIRTUAL, MOD_THROUGH_HOLE, MOD_SMD, MOD_EXCLUDE_FROM_POS_FILES
|
||||
|
|
@ -63,7 +62,7 @@ class PositionOptions(VariantOptions):
|
|||
self.output = GS.def_global_output
|
||||
""" Output file name (%i='top_pos'|'bottom_pos'|'both_pos', %x='pos'|'csv') """
|
||||
self.units = 'millimeters'
|
||||
""" [millimeters,inches] Units used for the positions """
|
||||
""" [millimeters,inches,mils] Units used for the positions. Affected by global options """
|
||||
self.columns = PosColumns
|
||||
""" [list(dict)|list(string)] Which columns are included in the output """
|
||||
self.bottom_negative_x = False
|
||||
|
|
@ -108,7 +107,7 @@ class PositionOptions(VariantOptions):
|
|||
for f in files:
|
||||
f.write('### Module positions - created on {} ###\n'.format(datetime.now().strftime("%a %d %b %Y %X %Z")))
|
||||
f.write('### Printed by KiBot\n')
|
||||
unit = {'millimeters': 'mm', 'inches': 'in'}[self.units]
|
||||
unit = {'millimeters': 'mm', 'inches': 'in', 'mils': 'mils'}[self.units]
|
||||
f.write('## Unit = {}, Angle = deg.\n'.format(unit))
|
||||
|
||||
if topf is not None:
|
||||
|
|
@ -218,8 +217,7 @@ class PositionOptions(VariantOptions):
|
|||
super().run(fname)
|
||||
output_dir = os.path.dirname(fname)
|
||||
columns = self.columns.values()
|
||||
# Note: the parser already checked the units are milimeters or inches
|
||||
conv = 1.0/IU_PER_MM if self.units == 'millimeters' else 0.001/IU_PER_MILS
|
||||
conv = GS.unit_name_to_scale_factor(self.units)
|
||||
# Format all strings
|
||||
comps_hash = self.get_refs_hash()
|
||||
modules = []
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@
|
|||
(gr_text "0,6299 in" (at 140 107.2) (layer "Dwgs.User") (tstamp e5864fe6-2a71-47f0-90ce-38c3f8901580)
|
||||
(effects (font (size 1.5 1.5) (thickness 0.3)))
|
||||
)
|
||||
(format (units 0) (units_format 1) (precision 4))
|
||||
(format (units 3) (units_format 1) (precision 4))
|
||||
(style (thickness 0.2) (arrow_length 1.27) (text_position_mode 0) (extension_height 0.58642) (extension_offset 0.5) keep_text_aligned)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
kibot:
|
||||
version: 1
|
||||
|
||||
global:
|
||||
units: millimeters
|
||||
|
||||
outputs:
|
||||
|
||||
- name: 'gerbers'
|
||||
|
|
|
|||
Loading…
Reference in New Issue