Skip to content

Commit

Permalink
[KiCanvas] Various fixes
Browse files Browse the repository at this point in the history
- Allow using it for PCB or SCH alone
- Load the PCB/SCH only when needed
- Adjust the category according to the needs
  • Loading branch information
set-soft committed Jan 30, 2024
1 parent 82532ff commit 263db4e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def copy_project(new_pcb_name, dry=False):
pro_name = GS.pro_file
if pro_name is None or not os.path.isfile(pro_name):
return None, None, None
pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext)
pro_copy = os.path.splitext(new_pcb_name)[0]+GS.pro_ext
if not dry:
logger.debug(f'Copying project `{pro_name}` to `{pro_copy}`')
copy2(pro_name, pro_copy)
Expand Down
50 changes: 38 additions & 12 deletions kibot/out_kicanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from .error import KiPlotConfigurationError
from .gs import GS
from .kiplot import load_sch, load_board
from .out_base import VariantOptions
from .macros import macros, document, output_class # noqa: F401
from . import log
Expand Down Expand Up @@ -56,12 +57,14 @@ def _get_targets(self, out_dir, only_index=False):
if self.local_script:
files.append(os.path.join(out_dir, SCRIPT_NAME))
for s in self.source:
if s == 'pcb':
if s == 'pcb' and GS.pcb_fname:
files.append(os.path.join(out_dir, GS.pcb_fname))
elif s == 'schematic':
elif s == 'schematic' and GS.sch_file:
files.extend(GS.sch.file_names_variant(out_dir))
else:
files.extend(GS.copy_project_names(GS.pcb_file))
elif s == 'project' and (GS.sch_file or GS.pcb_file):
prj_files = GS.copy_project_names(GS.sch_file or GS.pcb_file)
for f in prj_files:
files.append(os.path.join(out_dir, os.path.basename(f)))
return files

def get_targets(self, out_dir):
Expand Down Expand Up @@ -94,8 +97,19 @@ def save_sch(self, out_dir):
self.restore_title(sch=True)

def run(self, out_dir):
for f in self._get_targets(out_dir):
logger.error(f)
# We declare _none_related=True because we don't know if the PCB/SCH are needed until the output is configured.
# Now that we know it we can load the PCB and/or SCH.
for s in self.source:
if s == 'pcb':
load_board()
elif s == 'schematic':
load_sch()
else:
load_sch()
load_board()
GS.check_pro()
# Now that we loaded the needed stuff we can do the parent run
super().run(out_dir)
# Download KiCanvas
if self.local_script:
logger.debug(f'Downloading the script from `{self.url_script}`')
Expand All @@ -114,15 +128,10 @@ def run(self, out_dir):
for s in self.source:
# Save the PCB/SCH/Project
if s == 'pcb':
GS.check_pcb()
self.save_pcb(out_dir)
elif s == 'schematic':
GS.check_sch()
self.save_sch(out_dir)
else:
GS.check_sch()
GS.check_pcb()
GS.check_pro()
self.save_sch(out_dir)
GS.copy_project(self.save_pcb(out_dir))
# Create the HTML file
Expand Down Expand Up @@ -161,13 +170,30 @@ class KiCanvas(BaseOutput): # noqa: F821
def __init__(self):
super().__init__()
self._category = ['PCB/docs', 'Schematic/docs']
self._both_related = True
self._none_related = True
with document:
self.output = GS.def_global_output
""" *Filename for the output (%i=kicanvas, %x=html) """
self.options = KiCanvasOptions
""" *[dict] Options for the KiCanvas output """

def config(self, parent):
super().config(parent)
if self.get_user_defined('category'):
# The user specified a category, don't change it
return
# Adjust the category according to the selected output/s
cat = set()
for s in self.options.source:
if s == 'pcb':
cat.add('PCB/docs')
elif s == 'schematic':
cat.add('Schematic/docs')
else:
cat.add('PCB/docs')
cat.add('Schematic/docs')
self.category = list(cat)

@staticmethod
def get_conf_examples(name, layers):
# TODO: implement
Expand Down
16 changes: 16 additions & 0 deletions tests/yaml_samples/kicanvas_2.kibot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Example KiBot config file
kibot:
version: 1

outputs:
- name: 'KiCanvas'
comment: "Example of KiCanvas export"
type: kicanvas
dir: KiCanvas
# category: 'Una mia'
options:
source: 'schematic'
overlay: false

- name: 'Navigate'
type: navigate_results

0 comments on commit 263db4e

Please sign in to comment.