2020-11-20 08:10:53 +00:00
|
|
|
#!/usr/bin/env python
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Test the KiCad plugin regarding some expected features.
|
|
|
|
|
|
|
|
# 1) Build target _pcbnew after enabling scripting in cmake.
|
|
|
|
# $ make _pcbnew
|
|
|
|
|
|
|
|
# 2) Changed dir to pcbnew
|
|
|
|
# $ cd pcbnew
|
|
|
|
# $ pwd
|
|
|
|
# build/pcbnew
|
|
|
|
|
|
|
|
# 3) Entered following command line, script takes no arguments
|
|
|
|
# $ PYTHONPATH=. <path_to>/test_kicad_plugin.py
|
|
|
|
|
2020-11-20 08:10:53 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
from pcbnew import IO_MGR, BOARD, FOOTPRINT, LIB_ID, UTF8
|
2014-10-18 15:11:25 +00:00
|
|
|
from os import rename as mv
|
2013-12-03 18:37:21 +00:00
|
|
|
|
2014-10-18 15:11:25 +00:00
|
|
|
tmp_path = '/tmp'
|
|
|
|
lib_path1 = "%s/lib1.pretty" % tmp_path
|
|
|
|
lib_path2 = "%s/lib2.pretty" % tmp_path
|
2013-12-03 18:37:21 +00:00
|
|
|
|
2020-11-20 08:10:53 +00:00
|
|
|
plugin = IO_MGR.PluginFind( IO_MGR.KICAD_SEXP )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Expecting "KiCad":
|
2014-10-18 15:11:25 +00:00
|
|
|
print( "Plugin Type: %s" % plugin.PluginName() )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
try:
|
2023-12-27 00:25:41 +00:00
|
|
|
plugin.DeleteLibrary( lib_path1 )
|
2013-12-03 18:37:21 +00:00
|
|
|
except:
|
2014-10-18 15:11:25 +00:00
|
|
|
pass # ignore, new may not exist if first run
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
try:
|
2023-12-27 00:25:41 +00:00
|
|
|
plugin.DeleteLibrary( lib_path2 )
|
2013-12-03 18:37:21 +00:00
|
|
|
except:
|
2014-10-18 15:11:25 +00:00
|
|
|
pass # ignore, new may not exist if first run
|
2013-12-03 18:37:21 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
plugin.CreateLibrary( lib_path1 )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Verify that the same plugin instance can edge trigger on a lib_path change
|
2023-12-27 00:25:41 +00:00
|
|
|
# for a CreateLibrary()
|
|
|
|
plugin.CreateLibrary( lib_path2 )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
board = BOARD()
|
|
|
|
|
2020-11-13 23:10:45 +00:00
|
|
|
# The only way to construct a FOOTPRINT is to pass it a BOARD? Yep.
|
|
|
|
module = FOOTPRINT( board )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
2020-11-20 08:10:53 +00:00
|
|
|
fpid = LIB_ID( '', 'mine' )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
module.SetFPID( fpid )
|
|
|
|
|
|
|
|
plugin.FootprintSave( lib_path2, module )
|
|
|
|
|
|
|
|
# Verify that the same plugin instance can edge trigger on a lib_path change
|
|
|
|
# for a FootprintSave()
|
|
|
|
plugin.FootprintSave( lib_path1, module )
|
|
|
|
|
|
|
|
# create a disparity between the library's name ("footprint"),
|
|
|
|
# and the module's internal useless name ("mine"). Module is officially named "footprint" now
|
|
|
|
# but has (module mine ...) internally:
|
2014-10-18 15:11:25 +00:00
|
|
|
mv( "%s/mine.kicad_mod" % lib_path2, "%s/footprint.kicad_mod" % lib_path2 )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
2014-10-18 15:11:25 +00:00
|
|
|
footprint = plugin.FootprintLoad( lib_path2, 'footprint' )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
fpid = footprint.GetFPID()
|
2014-10-18 08:18:14 +00:00
|
|
|
fpid.SetLibNickname( UTF8( 'mylib' ) )
|
2020-11-20 08:10:53 +00:00
|
|
|
name = fpid.Format( fpid ).GetChars() # example to get the UTF8 char buffer
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Always after a FootprintLoad() the internal name should match the one used to load it.
|
2014-10-18 15:11:25 +00:00
|
|
|
print( "Internal name should be 'footprint': '%s'" % name )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Verify that the same plugin instance can edge trigger on a lib_path change
|
|
|
|
# for FootprintLoad()
|
2014-10-18 15:11:25 +00:00
|
|
|
footprint = plugin.FootprintLoad( lib_path1, 'mine' )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
fpid = footprint.GetFPID()
|
2014-10-18 08:18:14 +00:00
|
|
|
fpid.SetLibNickname( UTF8( 'other_mylib' ) )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# Always after a FootprintLoad() the internal name should match the one used to load it.
|
2014-10-21 16:34:51 +00:00
|
|
|
# Example to print an UTF8 string
|
2020-11-20 08:10:53 +00:00
|
|
|
print( "Internal name should be 'mine': '%s'" % fpid.Format( fpid ) )
|
2013-12-03 18:37:21 +00:00
|
|
|
|
|
|
|
# As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy!
|
|
|
|
|