[sub-PCB] Avoided saving the PCB before separate

- Now isn't needed because we filter stuff after it
This commit is contained in:
Salvador E. Tropea 2022-12-27 09:07:33 -03:00
parent 1dbe58aab1
commit 41c5701d33
3 changed files with 11 additions and 19 deletions

View File

@ -211,8 +211,8 @@ def add_extra_options(cmd):
return cmd, video_remove return cmd, video_remove
def load_board(pcb_file=None): def load_board(pcb_file=None, forced=False):
if GS.board is not None: if GS.board is not None and not forced:
# Already loaded # Already loaded
return GS.board return GS.board
import pcbnew import pcbnew

View File

@ -389,9 +389,8 @@ class QR_LibOptions(BaseOptions):
f.write('\n') f.write('\n')
tmp_pcb = f.name tmp_pcb = f.name
# Reload it # Reload it
GS.board = None
logger.debug('- Loading the temporal PCB') logger.debug('- Loading the temporal PCB')
load_board(tmp_pcb) load_board(tmp_pcb, forced=True)
# Create a back-up and save it in the original place # Create a back-up and save it in the original place
logger.debug('- Replacing the old PCB') logger.debug('- Replacing the old PCB')
os.remove(tmp_pcb) os.remove(tmp_pcb)

View File

@ -4,14 +4,14 @@
# License: GPL-3.0 # License: GPL-3.0
# Project: KiBot (formerly KiPlot) # Project: KiBot (formerly KiPlot)
import os import os
from tempfile import NamedTemporaryFile, TemporaryDirectory from tempfile import TemporaryDirectory
from .registrable import RegVariant from .registrable import RegVariant
from .optionable import Optionable, PanelOptions from .optionable import Optionable, PanelOptions
from .fil_base import apply_exclude_filter, apply_fitted_filter, apply_fixed_filter, apply_pre_transform from .fil_base import apply_exclude_filter, apply_fitted_filter, apply_fixed_filter, apply_pre_transform
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
from .misc import KIKIT_UNIT_ALIASES from .misc import KIKIT_UNIT_ALIASES
from .gs import GS from .gs import GS
from .kiplot import load_board, run_command from .kiplot import run_command
from .macros import macros, document # noqa: F401 from .macros import macros, document # noqa: F401
from . import log from . import log
@ -71,28 +71,21 @@ class SubPCBOptions(PanelOptions):
return "annotation; ref: {}".format(self.reference) return "annotation; ref: {}".format(self.reference)
return "rectangle; tlx: {}; tly: {}; brx: {}; bry: {}".format(self.tlx, self.tly, self.brx, self.bry) return "rectangle; tlx: {}; tly: {}; brx: {}; bry: {}".format(self.tlx, self.tly, self.brx, self.bry)
def load_board(self, comps_hash): def separate_board(self, comps_hash):
""" Apply the sub-PCB using an external tool and load it into memory """ """ Apply the sub-PCB using an external tool and load it into memory """
# Make sure kikit is available # Make sure kikit is available
command = GS.ensure_tool('global', 'KiKit') command = GS.ensure_tool('global', 'KiKit')
with TemporaryDirectory(prefix='kibot-separate') as d: with TemporaryDirectory(prefix='kibot-separate') as d:
dest = os.path.join(d, os.path.basename(GS.pcb_file)) dest = os.path.join(d, os.path.basename(GS.pcb_file))
# Save the current PCB, with any changes applied
with NamedTemporaryFile(mode='w', suffix='.kicad_pcb', delete=False) as f:
pcb_file = f.name
GS.board.Save(pcb_file)
if comps_hash: if comps_hash:
# Memorize the used modules # Memorize the used modules
old_modules = {m.GetReference() for m in GS.get_modules()} old_modules = {m.GetReference() for m in GS.get_modules()}
# Now do the separation # Now do the separation
cmd = [command, 'separate', '-s', self.get_separate_source(), pcb_file, dest] cmd = [command, 'separate', '-s', self.get_separate_source(), GS.pcb_file, dest]
# Execute the separate # Execute the separate
run_command(cmd) run_command(cmd)
# Load this board # Load this board
GS.board = None GS.load_board(dest, forced=True)
load_board(dest)
# Remove the temporal PCB
os.remove(pcb_file)
self._excl_by_sub_pcb = set() self._excl_by_sub_pcb = set()
# Now reflect the changes in the list of components # Now reflect the changes in the list of components
if comps_hash: if comps_hash:
@ -112,12 +105,12 @@ class SubPCBOptions(PanelOptions):
def apply(self, comps_hash): def apply(self, comps_hash):
if True: if True:
self.load_board(comps_hash) self.separate_board(comps_hash)
def unload_board(self, comps_hash): def unload_board(self, comps_hash):
# Undo the sub-PCB: just reload the PCB # Undo the sub-PCB: just reload the PCB
GS.board = None GS.load_board(forced=True)
load_board() # Restore excluded components
for c in self._excl_by_sub_pcb: for c in self._excl_by_sub_pcb:
comps_hash[c].included = True comps_hash[c].included = True