diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index f6e8cc64d0..77fa491615 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -172,6 +172,12 @@ MODULE* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString& // having to copy the FPID and its two strings, twice each. FPID& fpid = (FPID&) ret->GetFPID(); + // Catch any misbehaving plugin, which should be setting internal footprint name properly: + wxASSERT( aFootprintName == FROM_UTF8( fpid.GetFootprintName().c_str() ) ); + + // and clearing nickname + wxASSERT( !fpid.GetLibNickname().size() ); + fpid.SetLibNickname( row->GetNickName() ); } diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp index 8b2d31ca92..b552669381 100644 --- a/pcbnew/github/github_plugin.cpp +++ b/pcbnew/github/github_plugin.cpp @@ -157,9 +157,14 @@ MODULE* GITHUB_PLUGIN::FootprintLoad( const wxString& aLibraryPath, MODULE* local = PCB_IO::FootprintLoad( m_pretty_dir, aFootprintName, aProperties ); if( local ) - return local; - } + { + // It has worked, see /scripts/test_kicad_plugin.py. So this was not firing: + // wxASSERT( aFootprintName == FROM_UTF8( local->GetFPID().GetFootprintName().c_str() ) ); + // Moving it to higher API layer FP_LIB_TABLE::FootprintLoad(). + return local; + } + } string fp_name = TO_UTF8( aFootprintName ); @@ -178,13 +183,21 @@ MODULE* GITHUB_PLUGIN::FootprintLoad( const wxString& aLibraryPath, if( zis.OpenEntry( *entry ) ) { INPUTSTREAM_LINE_READER reader( &zis ); +#if 1 + // I am a PCB_IO derivative with my own PCB_PARSER + m_parser->SetLineReader( &reader ); // ownership not passed + + MODULE* ret = (MODULE*) m_parser->Parse(); +#else PCB_PARSER parser( &reader ); MODULE* ret = (MODULE*) parser.Parse(); +#endif // Dude, the footprint name comes from the file name in // a github library. Zero out the library name, we don't know it here. - // Caller always has to set the library nickname if it knows it. + // Some caller may set the library nickname, one such instance is + // FP_LIB_TABLE::FootprintLoad(). ret->SetFPID( fp_name ); return ret; diff --git a/scripts/test_kicad_plugin.py b/scripts/test_kicad_plugin.py new file mode 100755 index 0000000000..fc2934cebb --- /dev/null +++ b/scripts/test_kicad_plugin.py @@ -0,0 +1,87 @@ +#!/usr/bin/python + +# 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=. /test_kicad_plugin.py + + +from __future__ import print_function +from pcbnew import * +import sys +import os + + +lib_path1='/tmp/lib1.pretty' +lib_path2='/tmp/lib2.pretty' + + +plugin = IO_MGR.PluginFind( IO_MGR.KICAD ) + +# Expecting "KiCad": +print( "Plugin Type", plugin.PluginName() ) + +try: + plugin.FootprintLibDelete( lib_path1 ) +except: + None # ignore, new may not exist if first run + +try: + plugin.FootprintLibDelete( lib_path2 ) +except: + None # ignore, new may not exist if first run + + +plugin.FootprintLibCreate( lib_path1 ) + +# Verify that the same plugin instance can edge trigger on a lib_path change +# for a FootprintLibCreate() +plugin.FootprintLibCreate( lib_path2 ) + + +board = BOARD() + +# The only way to construct a MODULE is to pass it a BOARD? Yep. +module = MODULE( board ) + +fpid=FPID( 'mine' ) + +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: +os.rename( '/tmp/lib2.pretty/mine.kicad_mod', '/tmp/lib2.pretty/footprint.kicad_mod' ) + +footprint=plugin.FootprintLoad( lib_path2, 'footprint' ) + +fpid = footprint.GetFPID() + +# Always after a FootprintLoad() the internal name should match the one used to load it. +print( "internal name should be 'footprint':", fpid.GetFootprintName() ) + +# Verify that the same plugin instance can edge trigger on a lib_path change +# for FootprintLoad() +footprint=plugin.FootprintLoad( lib_path1, 'mine' ) + +fpid = footprint.GetFPID() + +# Always after a FootprintLoad() the internal name should match the one used to load it. +print( "internal name should be 'mine':", fpid.GetFootprintName() ) + +# As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy! +