[3D Models] Added support to pass variables to download URL
Should help for #414
This commit is contained in:
parent
9f5618d995
commit
b1b798689f
|
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Added
|
||||
- General:
|
||||
- Support for time stamp in the date (i.e. 2023-04-02T09:22-03:00)
|
||||
- Support to pass variables to the 3D models download URL (#414)
|
||||
- Command line:
|
||||
- `--banner N` Option to display a banner
|
||||
- `--log FILE` Option to log to a file, in addition to the stderr
|
||||
|
|
|
|||
10
README.md
10
README.md
|
|
@ -1623,6 +1623,8 @@ Notes:
|
|||
- `highlight_on_top`: [boolean=false] Highlight over the component (not under).
|
||||
- `highlight_padding`: [number=1.5] [0,1000] How much the highlight extends around the component [mm].
|
||||
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
|
||||
- `kicad_3d_url_suffix`: [string=''] Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2.
|
||||
- `output`: [string='%f-%i%I%v.%x'] Name for the generated PCB3D file (%i='blender_export' %x='pcb3d'). Affected by global options.
|
||||
- `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.
|
||||
|
|
@ -2057,6 +2059,8 @@ Notes:
|
|||
A short-cut to use for simple cases where a variant is an overkill.
|
||||
- `follow_links`: [boolean=true] Store the file pointed by symlinks, not the symlink.
|
||||
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
|
||||
- `kicad_3d_url_suffix`: [string=''] Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2.
|
||||
- `link_no_copy`: [boolean=false] Create symlinks instead of copying files.
|
||||
- `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.
|
||||
|
|
@ -4263,6 +4267,8 @@ Notes:
|
|||
- `highlight_on_top`: [boolean=false] Highlight over the component (not under).
|
||||
- `highlight_padding`: [number=1.5] [0,1000] How much the highlight extends around the component [mm].
|
||||
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
|
||||
- `kicad_3d_url_suffix`: [string=''] Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2.
|
||||
- `no_smd`: [boolean=false] Used to exclude 3D models for surface mount components.
|
||||
- `no_tht`: [boolean=false] Used to exclude 3D models for through hole components.
|
||||
- `orthographic`: [boolean=false] Enable the orthographic projection mode (top view looks flat).
|
||||
|
|
@ -4515,6 +4521,8 @@ Notes:
|
|||
- `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.
|
||||
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
|
||||
- `kicad_3d_url_suffix`: [string=''] Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2.
|
||||
- `metric_units`: [boolean=true] Use metric units instead of inches.
|
||||
- `min_distance`: [number=-1] The minimum distance between points to treat them as separate ones (-1 is KiCad default: 0.01 mm).
|
||||
- `pre_transform`: [string|list(string)='_none'] Name of the filter to transform fields before applying other filters.
|
||||
|
|
@ -4755,6 +4763,8 @@ Notes:
|
|||
- `highlight_on_top`: [boolean=false] Highlight over the component (not under).
|
||||
- `highlight_padding`: [number=1.5] [0,1000] How much the highlight extends around the component [mm].
|
||||
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
|
||||
- `kicad_3d_url_suffix`: [string=''] Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2.
|
||||
- `model_units`: [string='millimeters'] [millimeters,meters,deciinches,inches] Units used for the VRML (1 deciinch = 0.1 inches).
|
||||
- `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.
|
||||
|
|
|
|||
|
|
@ -167,6 +167,9 @@ outputs:
|
|||
highlight_padding: 1.5
|
||||
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
|
||||
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
# [string=''] Text added to the end of the download URL.
|
||||
# Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2
|
||||
kicad_3d_url_suffix: ''
|
||||
# [boolean=false] Used to exclude 3D models for components with 'virtual' attribute
|
||||
no_virtual: false
|
||||
# [string='%f-%i%I%v.%x'] Name for the generated PCB3D file (%i='blender_export' %x='pcb3d'). Affected by global options
|
||||
|
|
@ -663,6 +666,9 @@ outputs:
|
|||
follow_links: true
|
||||
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
|
||||
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
# [string=''] Text added to the end of the download URL.
|
||||
# Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2
|
||||
kicad_3d_url_suffix: ''
|
||||
# [boolean=false] Create symlinks instead of copying files
|
||||
link_no_copy: false
|
||||
# [boolean=false] Used to exclude 3D models for components with 'virtual' attribute
|
||||
|
|
@ -2913,6 +2919,9 @@ outputs:
|
|||
highlight_padding: 1.5
|
||||
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
|
||||
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
# [string=''] Text added to the end of the download URL.
|
||||
# Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2
|
||||
kicad_3d_url_suffix: ''
|
||||
# [number=0] Steps to move in the X axis, positive is to the right.
|
||||
# Just like pressing the right arrow in the 3D viewer
|
||||
move_x: 0
|
||||
|
|
@ -3161,6 +3170,9 @@ outputs:
|
|||
download: true
|
||||
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
|
||||
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
# [string=''] Text added to the end of the download URL.
|
||||
# Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2
|
||||
kicad_3d_url_suffix: ''
|
||||
# [boolean=true] Use metric units instead of inches
|
||||
metric_units: true
|
||||
# [number=-1] The minimum distance between points to treat them as separate ones (-1 is KiCad default: 0.01 mm)
|
||||
|
|
@ -3392,6 +3404,9 @@ outputs:
|
|||
highlight_padding: 1.5
|
||||
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
|
||||
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
# [string=''] Text added to the end of the download URL.
|
||||
# Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2
|
||||
kicad_3d_url_suffix: ''
|
||||
# [string='millimeters'] [millimeters,meters,deciinches,inches] Units used for the VRML (1 deciinch = 0.1 inches)
|
||||
model_units: 'millimeters'
|
||||
# [boolean=false] Used to exclude 3D models for components with 'virtual' attribute
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from fnmatch import fnmatch
|
|||
import os
|
||||
import re
|
||||
import requests
|
||||
import urllib
|
||||
from shutil import copy2
|
||||
from .bom.units import comp_match
|
||||
from .EasyEDA.easyeda_3d import download_easyeda_3d_model
|
||||
|
|
@ -134,6 +135,9 @@ class Base3DOptions(VariantOptions):
|
|||
KIBOT_3D_MODELS environment variable """
|
||||
self.kicad_3d_url = 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
|
||||
""" Base URL for the KiCad 3D models """
|
||||
self.kicad_3d_url_suffix = ''
|
||||
""" Text added to the end of the download URL.
|
||||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2 """
|
||||
# Temporal dir used to store the downloaded files
|
||||
self._tmp_dir = None
|
||||
super().__init__()
|
||||
|
|
@ -144,6 +148,7 @@ class Base3DOptions(VariantOptions):
|
|||
self.no_virtual = ref.no_virtual
|
||||
self.download = ref.download
|
||||
self.kicad_3d_url = ref.kicad_3d_url
|
||||
self.kicad_3d_url_suffix = ref.kicad_3d_url_suffix
|
||||
|
||||
def download_model(self, url, fname, rel_dirs):
|
||||
""" Download the 3D model from the provided URL """
|
||||
|
|
@ -189,7 +194,7 @@ class Base3DOptions(VariantOptions):
|
|||
# Already downloaded
|
||||
return os.path.join(self._tmp_dir, fname)
|
||||
# Download the model
|
||||
url = self.kicad_3d_url+fname
|
||||
url = self.kicad_3d_url+urllib.parse.quote_plus(fname)+self.kicad_3d_url_suffix
|
||||
replace = self.download_model(url, fname, rel_dirs)
|
||||
if not replace:
|
||||
return None
|
||||
|
|
|
|||
Loading…
Reference in New Issue