Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
f9cca4501This file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import pcbnew
import logging
import sys
import os
from save_restore_layout import SaveLayout
from save_restore_layout import RestoreLayout
class TestRestore(unittest.TestCase):
@unittest.skip
def test_restore_shallow_same_level(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'test_shallow.json')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'R704'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow_same_level")
brd = restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_shallow_same.kicad_pcb"), board)
@unittest.skip
def test_restore_shallow_different_level(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'test_shallow.json')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'L401'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow, different level")
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_shallow_different.kicad_pcb"), board)
@unittest.skip
def test_restore_shallow_same_level_alt(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'test_shallow_alt.json')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'R704'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow_same_level_alt")
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_shallow_same_alt.kicad_pcb"), board)
def test_restore_deep(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'test_deep.json')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'R704' # C201
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, None)
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_deep.kicad_pcb"), board)
@unittest.skip
class TestSave(unittest.TestCase):
def test_save_shallow(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'L301' # R1005, R301
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 1
data_file = os.path.join(prj_dir, 'test_shallow.json')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, False)
def test_save_shallow_alt(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'L1001'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 2
data_file = os.path.join(prj_dir, 'test_shallow_alt.json')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, False)
def test_save_deep(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'L301'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 0
data_file = os.path.join(prj_dir, 'test_deep.json')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, False)
def test_save_shallow_remote(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'R1401'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 0
data_file = os.path.join(prj_dir, 'test_shallow_remote.json')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, False)
def test_save_remote_alt(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'R805'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 1
data_file = os.path.join(prj_dir, 'test_shallow_remote_alt.json')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, False)
if __name__ == "__main__":
file_handler = logging.FileHandler(filename='save_restore_layout.log', mode='w')
stdout_handler = logging.StreamHandler(sys.stdout)
handlers = [file_handler, stdout_handler]
logging_level = logging.INFO
logging.basicConfig(level=logging_level,
format='%(asctime)s %(name)s %(lineno)d:%(message)s',
datefmt='%m-%d %H:%M:%S',
handlers=handlers
)
logger = logging.getLogger(__name__)
logger.info("Plugin executed on: " + repr(sys.platform))
logger.info("Plugin executed with python version: " + repr(sys.version))
logger.info("KiCad build version: " + str(pcbnew.GetBuildVersion()))
unittest.main()