Skip to content

Commit ebdc6ca

Browse files
committed
[Export_3D][Added] center option to origin
Closes #871
1 parent 69e1d64 commit ebdc6ca

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Navigate Results, PCB Print, PcbDraw: Support for big SVGs (#851)
2929
- PCB Print: Workaround for KiCad 9.0.5 change in how holes are plotted when
3030
a layer is not included (black instead of white).
31+
- Export_3D: `center` option to `origin` (#871)
3132

3233
### Fixed
3334
- User.N layer numbering. I.e. pcb_print issues with their numbering (#808)

docs/samples/generic_plot.kibot.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,9 +1421,10 @@ outputs:
14211421
no_optimize_step: false
14221422
# [boolean=false] Used to exclude 3D models for components with 'virtual' attribute
14231423
no_virtual: false
1424-
# [string='grid'] [grid,drill,*] Determines the coordinates origin. Using grid the coordinates are the same as you have in the
1425-
# design sheet.
1426-
# The drill option uses the auxiliary reference defined by the user.
1424+
# [string='grid'] [grid,drill,center,*] Determines the coordinates origin.
1425+
# Using `grid` the coordinates are the same as you have in the design sheet.
1426+
# The `drill` option uses the auxiliary reference defined by the user.
1427+
# Using `center` you'll get the center of the board as origin.
14271428
# You can define any other origin using the format 'X,Y', i.e. '3.2,-10'. Don't put units here.
14281429
# The units used here are the ones specified by the `units` option
14291430
origin: 'grid'

docs/source/Changelog.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Added
5252
- Navigate Results, PCB Print, PcbDraw: Support for big SVGs (#851)
5353
- PCB Print: Workaround for KiCad 9.0.5 change in how holes are plotted
5454
when a layer is not included (black instead of white).
55+
- Export_3D: ``center`` option to ``origin`` (#871)
5556

5657
Fixed
5758
~~~~~
@@ -511,7 +512,7 @@ Fixed:
511512

512513
- Problems with filters that change fields for components that are
513514
only in the PCB. (#628)
514-
- Use of ’_none’ filter in lists of filters and \_kf()
515+
- Use of ’\_none’ filter in lists of filters and \_kf()
515516

516517
- Variants:
517518

@@ -710,7 +711,7 @@ Changed
710711
- KiRi: continue even on corrupted schematics (#583)
711712
- Variants: avoid W045 on nameless pads. Assuming they are on purpose
712713
and not real pads. (See #584)
713-
- BoardView: Skip footprints with no pads (not just REF**)
714+
- BoardView: Skip footprints with no pads (not just REF*\*)
714715
(whitequark/kicad-boardview#14)
715716

716717
.. _fixed-7:

docs/source/configuration/outputs/Export_3DOptions.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Export_3DOptions parameters
2020
- XAO: XAO (SALOME/Gmsh) format, used for FEM and simulations. |br|
2121
- BRep: Part of Open CASCADE Technology (OCCT).
2222
- **no_virtual** :index:`: <pair: output - export_3d - options; no_virtual>` [:ref:`boolean <boolean>`] (default: ``false``) Used to exclude 3D models for components with 'virtual' attribute.
23-
- **origin** :index:`: <pair: output - export_3d - options; origin>` [:ref:`string <string>`] (default: ``'grid'``) (choices: "grid", "drill") (also accepts any string) Determines the coordinates origin. Using grid the coordinates are the same as you have in the
24-
design sheet. |br|
25-
The drill option uses the auxiliary reference defined by the user. |br|
23+
- **origin** :index:`: <pair: output - export_3d - options; origin>` [:ref:`string <string>`] (default: ``'grid'``) (choices: "grid", "drill", "center") (also accepts any string) Determines the coordinates origin.
24+
Using `grid` the coordinates are the same as you have in the design sheet. |br|
25+
The `drill` option uses the auxiliary reference defined by the user. |br|
26+
Using `center` you'll get the center of the board as origin. |br|
2627
You can define any other origin using the format 'X,Y', i.e. '3.2,-10'. Don't put units here. |br|
2728
The units used here are the ones specified by the `units` option.
2829
- **output** :index:`: <pair: output - export_3d - options; output>` [:ref:`string <string>`] (default: ``'%f-%i%I%v.%x'``) Name for the generated 3D file (%i='3D' %x='step/glb/stl/xao/brep'). Affected by global options.

kibot/out_export_3d.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ def __init__(self):
3333
- BRep: Part of Open CASCADE Technology (OCCT) """
3434
# - PLY: Polygon File Format or the Stanford Triangle Format.
3535
self.origin = 'grid'
36-
""" *[grid,drill,*] Determines the coordinates origin. Using grid the coordinates are the same as you have in the
37-
design sheet.
38-
The drill option uses the auxiliary reference defined by the user.
36+
""" *[grid,drill,center,*] Determines the coordinates origin.
37+
Using `grid` the coordinates are the same as you have in the design sheet.
38+
The `drill` option uses the auxiliary reference defined by the user.
39+
Using `center` you'll get the center of the board as origin.
3940
You can define any other origin using the format 'X,Y', i.e. '3.2,-10'. Don't put units here.
4041
The units used here are the ones specified by the `units` option """
4142
self.units = 'millimeters'
@@ -82,13 +83,21 @@ def config(self, parent):
8283
# Validate and parse the origin
8384
val = self.origin
8485
if (val not in ['grid', 'drill']):
85-
user_origin = re.match(r'([-\d\.]+)\s*,\s*([-\d\.]+)\s*$', val)
86-
if user_origin is None:
87-
raise KiPlotConfigurationError('Origin must be `grid` or `drill` or `X,Y` (no units here)')
88-
self._user_x = float(user_origin.group(1))
89-
self._user_y = float(user_origin.group(2))
86+
if val == 'center':
87+
bb = GS.board.ComputeBoundingBox(True)
88+
center = bb.GetCenter()
89+
self._user_x = GS.to_mm(center.x)
90+
self._user_y = GS.to_mm(center.y)
91+
self._units = 'mm'
92+
else:
93+
user_origin = re.match(r'([-\d\.]+)\s*,\s*([-\d\.]+)\s*$', val)
94+
if user_origin is None:
95+
raise KiPlotConfigurationError('Origin must be `grid` or `drill` or `X,Y` (no units here)')
96+
self._user_x = float(user_origin.group(1))
97+
self._user_y = float(user_origin.group(2))
9098
# Adjust the units
91-
self._units = UNITS_2_KICAD[self.units]
99+
if self.origin != 'center':
100+
self._units = UNITS_2_KICAD[self.units]
92101
if self._units == 'mils':
93102
self._units = 'in'
94103
self._scale = 0.001

0 commit comments

Comments
 (0)