Eeschema: initial schematic I/O plugin.

* Factor out PROPERTIES object from the PCB plugin code and move it into
  common so it can be used by both the Pcbnew and Eeschema plugins.

* Add schematic I/O plugin manager for loading and saving schematic and
  component library files.

* Add initial attempt at a parser for current schematic file format.  This
  parser will be infinitely more strict than the current parser which is very
  forgiving in what it parses.

* Make minor changes to the base bitmap class to support the new parser.

* Add find root sheet support to sheet object to allow fetching the root
  sheet from any sheet in the stack.
This commit is contained in:
Wayne Stambaugh 2016-07-06 05:22:56 -04:00
parent 78bc3c65de
commit 4ed346ea64
24 changed files with 2492 additions and 54 deletions

View File

@ -41,6 +41,10 @@ option( KICAD_SCRIPTING_WXPYTHON
"Build wxPython implementation for wx interface building in Python and py.shell (default OFF)."
)
option( USE_SCH_IO_MANAGER
"Build Eeschema with the I/O manager for handling schematic and symbol library I/O. (default OFF)"
)
# when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
# PYTHON_EXECUTABLE can be defined when invoking cmake
# ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )

View File

@ -69,6 +69,9 @@
/// When defined, build the GITHUB_PLUGIN for pcbnew.
#cmakedefine BUILD_GITHUB_PLUGIN
/// When defined, Eeschema is built with I/O manager plugin.
#cmakedefine USE_SCH_IO_MANAGER
/// A file extension with a leading '.' is a suffix, and this one is used on
/// top level program modules which implement the KIFACE.
#define KIFACE_SUFFIX wxT( "@KIFACE_SUFFIX@" )

View File

@ -241,6 +241,7 @@ set( COMMON_SRCS
netlist_keywords.cpp
prependpath.cpp
project.cpp
properties.cpp
ptree.cpp
reporter.cpp
richio.cpp

37
common/properties.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2016 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <properties.h>
bool PROPERTIES::Value( const char* aName, UTF8* aFetchedValue ) const
{
PROPERTIES::const_iterator it = find( aName );
if( it != end() )
{
if( aFetchedValue )
*aFetchedValue = it->second;
return true;
}
return false;
}

View File

@ -145,11 +145,14 @@ set( EESCHEMA_SRCS
sch_collectors.cpp
sch_component.cpp
sch_field.cpp
sch_io_mgr.cpp
sch_item_struct.cpp
sch_junction.cpp
sch_legacy_plugin.cpp
sch_line.cpp
sch_marker.cpp
sch_no_connect.cpp
sch_plugin.cpp
sch_screen.cpp
sch_sheet.cpp
sch_sheet_path.cpp

View File

@ -2,9 +2,9 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -45,9 +45,14 @@
#include <wildcards_and_files_ext.h>
#include <project_rescue.h>
#include <eeschema_config.h>
#include <sch_legacy_plugin.h>
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName, bool aCreateBackupFile )
//#define USE_SCH_LEGACY_IO_PLUGIN
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName,
bool aCreateBackupFile )
{
wxString msg;
wxFileName schematicFileName;
@ -204,7 +209,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
return false;
}
// save any currently open and modified project files.
// Save any currently open and modified project files.
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
{
if( screen->IsModify() )
@ -295,13 +300,39 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
}
else
{
#ifdef USE_SCH_IO_MANAGER
delete g_RootSheet; // Delete the current project.
g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure.
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
try
{
g_RootSheet = pi->Load( fullFileName, &Kiway() );
m_CurrentSheet->clear();
m_CurrentSheet->push_back( g_RootSheet );
}
catch( const IO_ERROR& ioe )
{
msg.Printf( _( "Error loading schematic file '%s'.\n%s" ),
GetChars( fullFileName ), GetChars( ioe.errorText ) );
DisplayError( this, msg );
msg.Printf( _( "Failed to load '%s'" ), GetChars( fullFileName ) );
AppendMsgPanel( wxEmptyString, msg, CYAN );
Zoom_Automatique( false );
return false;
}
#else
g_RootSheet->SetScreen( NULL );
DBG( printf( "%s: loading schematic %s\n", __func__, TO_UTF8( fullFileName ) );)
bool diag = g_RootSheet->Load( this );
(void) diag;
#endif
SetScreen( m_CurrentSheet->LastScreen() );
GetScreen()->ClrModify();
@ -327,7 +358,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
Zoom_Automatique( false );
SetSheetNumberAndCount();
m_canvas->Refresh( true );
return true;

View File

@ -47,6 +47,7 @@ class NETLIST_OBJECT_LIST;
class LIB_PART;
class PART_LIBS;
class SCH_COLLECTOR;
class SCH_SCREEN;
/// A container for several SCH_FIELD items
@ -189,6 +190,8 @@ public:
wxString GetPrefix() const { return m_prefix; }
void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; }
TRANSFORM& GetTransform() const { return const_cast< TRANSFORM& >( m_transform ); }
void SetTransform( const TRANSFORM& aTransform );

162
eeschema/sch_io_mgr.cpp Normal file
View File

@ -0,0 +1,162 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2016 KiCad Developers, see change_log.txt for contributors.
*
* @author Wayne Stambaugh <stambaughw@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/filename.h>
#include <wx/uri.h>
#include <sch_io_mgr.h>
#include <sch_legacy_plugin.h>
#include <wildcards_and_files_ext.h>
#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )
#define FMT_NOTFOUND _( "Plugin type '%s' is not found." )
// Some day plugins might be in separate DLL/DSOs, simply because of numbers of them
// and code size. Until then, use the simplest method:
// This implementation is one of two which could be done.
// The other one would cater to DLL/DSO's. But since it would be nearly
// impossible to link a KICAD type DLL/DSO right now without pulling in all
// ::Draw() functions, I forgo that option temporarily.
// Some day it may be possible to have some built in AND some DLL/DSO
// plugins coexisting.
SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
{
// This implementation is subject to change, any magic is allowed here.
// The public SCH_IO_MGR API is the only pertinent public information.
switch( aFileType )
{
case SCH_LEGACY:
return new SCH_LEGACY_PLUGIN();
}
return NULL;
}
void SCH_IO_MGR::ReleasePlugin( SCH_PLUGIN* aPlugin )
{
// This function is a place holder for a future point in time where
// the plugin is a DLL/DSO. It could do reference counting, and then
// unload the DLL/DSO when count goes to zero.
delete aPlugin;
}
const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
{
// keep this function in sync with EnumFromStr() relative to the
// text spellings. If you change the spellings, you will obsolete
// library tables, so don't do change, only additions are ok.
switch( aType )
{
default:
return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ), aType );
case SCH_LEGACY:
return wxString( wxT( "Legacy" ) );
}
}
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
{
// keep this function in sync with ShowType() relative to the
// text spellings. If you change the spellings, you will obsolete
// library tables, so don't do change, only additions are ok.
if( aType == wxT( "Legacy" ) )
return SCH_LEGACY;
// wxASSERT( blow up here )
return SCH_FILE_T( -1 );
}
const wxString SCH_IO_MGR::GetFileExtension( SCH_FILE_T aFileType )
{
wxString ext = wxEmptyString;
SCH_PLUGIN* plugin = FindPlugin( aFileType );
if( plugin != NULL )
{
ext = plugin->GetFileExtension();
ReleasePlugin( plugin );
}
return ext;
}
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath )
{
SCH_FILE_T ret = SCH_LEGACY; // default guess, unless detected otherwise.
wxFileName fn( aLibPath );
if( fn.GetExt() == SchematicFileWildcard )
{
ret = SCH_LEGACY;
}
return ret;
}
SCH_SHEET* SCH_IO_MGR::Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
{
// release the SCH_PLUGIN even if an exception is thrown.
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
if( (SCH_PLUGIN*) pi ) // test pi->plugin
{
return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual
}
THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
}
void SCH_IO_MGR::Save( SCH_FILE_T aFileType, const wxString& aFileName,
SCH_SHEET* aSchematic, const PROPERTIES* aProperties )
{
// release the SCH_PLUGIN even if an exception is thrown.
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
if( (SCH_PLUGIN*) pi ) // test pi->plugin
{
pi->Save( aFileName, aSchematic, aProperties ); // virtual
return;
}
THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
}

487
eeschema/sch_io_mgr.h Normal file
View File

@ -0,0 +1,487 @@
#ifndef _SCH_IO_MGR_H_
#define _SCH_IO_MGR_H_
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2016 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* @author Wayne Stambaugh <stambaughw@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <richio.h>
#include <map>
class SCH_SHEET;
class SCH_PLUGIN;
class KIWAY;
class LIB_PART;
class PROPERTIES;
/**
* Class SCH_IO_MGR
* is a factory which returns an instance of a SCH_PLUGIN.
*/
class SCH_IO_MGR
{
public:
/**
* Enum SCH_FILE_T
* is a set of file types that the SCH_IO_MGR knows about, and for which there
* has been a plugin written.
*/
enum SCH_FILE_T
{
SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression.
SCH_KICAD, ///< The s-expression version of the schematic file formats.
// Add your schematic type here.
// ALTIUM,
// etc.
};
/**
* Function FindPlugin
* returns a SCH_PLUGIN which the caller can use to import, export, save, or load
* design documents. The returned SCH_PLUGIN, may be reference counted, so please
* call PluginRelease() when you are done using the returned SCH_PLUGIN. It may or
* may not be code running from a DLL/DSO.
*
* @param aFileType is from SCH_FILE_T and tells which plugin to find.
*
* @return SCH_PLUGIN* - the plugin corresponding to aFileType or NULL if not found.
* Caller owns the returned object, and must call PluginRelease when done using it.
*/
static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
/**
* Function PluginRelease
* releases a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory.
*
* @param aPlugin is the one to be released, and which is no longer usable
* after calling this.
*/
static void ReleasePlugin( SCH_PLUGIN* aPlugin );
/**
* Function ShowType
* returns a brief name for a plugin, given aFileType enum.
*/
static const wxString ShowType( SCH_FILE_T aFileType );
/**
* Function EnumFromStr
* returns the SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
*/
static SCH_FILE_T EnumFromStr( const wxString& aFileType );
/**
* Function GetFileExtension
* returns the file extension for \a aFileType.
*
* @param aFileType The #SCH_FILE_T type.
* @return A wxString object containing the file extension for \a aFileType or an empty
* string if \a aFileType is invalid.
*/
static const wxString GetFileExtension( SCH_FILE_T aFileType );
/**
* Function GuessPluginTypeFromLibPath
* returns a plugin type given a footprint library's libPath.
*/
static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
/**
* Function Load
* finds the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) funtion
* on it using the arguments passed to this function. After the SCH_PLUGIN->Load()
* function returns, the SCH_PLUGIN is Released() as part of this call.
*
* @param aFileType is the SCH_FILE_T of file to load.
* @param aFileName is the name of the file to load.
* @param aKiway is the #KIWAY object used to access the component libraries loaded
* by the project.
* @param aAppendToMe is an existing #SCHEMATIC to append to, use NULL if a new
* #SCHEMATIC load is wanted.
* @param aProperties is an associative array that allows the caller to pass additional
* tuning parameters to the SCH_PLUGIN.
*
* @return SCHEMATIC* - caller owns it, never NULL because exception thrown if error.
*
* @throw IO_ERROR if the SCH_PLUGIN cannot be found, file cannot be found,
* or file cannot be loaded.
*/
static SCH_SHEET* Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
/**
* Function Save
* will write either a full aSchematic to a storage file in a format that this
* implementation knows about, or it can be used to write a portion of
* aSchematic to a special kind of export file.
*
* @param aFileType is the SCH_FILE_T of file to save.
*
* @param aFileName is the name of a file to save to on disk.
* @param aSchematic is the SCHEMATIC document (data tree) to save or export to disk.
*
* @param aSchematic is the in memory document tree from which to extract information
* when writing to \a aFileName. The caller continues to own the SCHEMATIC, and
* the plugin should refrain from modifying the SCHEMATIC if possible.
*
* @param aProperties is an associative array that can be used to tell the
* saver how to save the file, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem saving or exporting.
*/
static void Save( SCH_FILE_T aFileType, const wxString& aFileName,
SCH_SHEET* aSchematic, const PROPERTIES* aProperties = NULL );
};
/**
* Class SCH_PLUGIN
* is a base class that SCHEMATIC loading and saving plugins should derive from.
* Implementations can provide either Load() or Save() functions, or both.
* SCH_PLUGINs throw exceptions, so it is best that you wrap your calls to these
* functions in a try catch block. Plugins throw exceptions because it is illegal
* for them to have any user interface calls in them whatsoever, i.e. no windowing
* or screen printing at all.
*
* <pre>
* try
* {
* SCH_IO_MGR::Load(...);
* or
* SCH_IO_MGR::Save(...);
* }
* catch( const IO_ERROR& ioe )
* {
* // grab text from ioe, show in error window.
* }
* </pre>
*/
class SCH_PLUGIN
{
public:
//-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
/**
* Function GetName
* returns a brief hard coded name for this SCH_PLUGIN.
*/
virtual const wxString GetName() const = 0;
/**
* Function GetFileExtension
* returns the file extension for the SCH_PLUGIN.
*/
virtual const wxString GetFileExtension() const = 0;
/**
* Function Load
* loads information from some input file format that this SCH_PLUGIN implementation
* knows about, into either a new SCHEMATIC or an existing one. This may be used to load an
* entire new SCHEMATIC, or to augment an existing one if @a aAppendToMe is not NULL.
*
* @param aFileName is the name of the file to use as input and may be foreign in
* nature or native in nature.
*
* @param aAppendToMe is an existing SCHEMATIC to append to, but if NULL then
* this means "do not append, rather load anew".
*
* @param aProperties is an associative array that can be used to tell the
* loader how to load the file, because it can take any number of
* additional named arguments that the plugin is known to support. These are
* tuning parameters for the import or load. The caller continues to own
* this object (plugin may not delete it), and plugins should expect it to
* be optionally NULL.
*
* @return SCHEMATIC* - the successfully loaded schematic, or the same one as \a aAppendToMe
* if \a aAppendToMe was not NULL, and the caller owns it.
*
* @throw IO_ERROR if there is a problem loading, and its contents should
* say what went wrong, using line number and character offsets of the
* input file if possible.
*/
virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
/**
* Function Save
* will write @a aSchematic to a storage file in a format that this
* SCH_PLUGIN implementation knows about, or it can be used to write a portion of
* aSchematic to a special kind of export file.
*
* @param aFileName is the name of a file to save to on disk.
*
* @param aSchematic is the class SCHEMATIC in memory document tree from which to
* extract information when writing to \a aFileName. The caller continues to
* own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
*
* @param aProperties is an associative array that can be used to tell the
* saver how to save the file, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it),
* and plugins should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem saving or exporting.
*/
virtual void Save( const wxString& aFileName, SCH_SHEET* aSchematic,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolEnumerate
* returns a list of symbol names contained within the library at @a aLibraryPath.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @param aProperties is an associative array that can be used to tell the
* plugin anything needed about how to perform with respect to @a aLibraryPath.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @return wxArrayString - is the array of available footprint names inside
* a library
*
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
*/
virtual wxArrayString SymbolEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolLoad
* loads a footprint having @a aSymbolName from the @a aLibraryPath containing
* a library format that this SCH_PLUGIN knows about.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @param aSymbolName is the name of the footprint to load.
*
* @param aProperties is an associative array that can be used to tell the
* loader implementation to do something special, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @return MODULE* - if found caller owns it, else NULL if not found.
*
* @throw IO_ERROR if the library cannot be found or read. No exception
* is thrown in the case where aSymbolName cannot be found.
*/
virtual LIB_PART* SymbolLoad( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolSave
* will write @a aModule to an existing library located at @a aLibraryPath.
* If a footprint by the same name already exists, it is replaced.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @param aSymbol is what to store in the library. The caller continues
* to own the footprint after this call.
*
* @param aProperties is an associative array that can be used to tell the
* saver how to save the footprint, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem saving.
*/
virtual void SymbolSave( const wxString& aLibraryPath, const LIB_PART* aSymbol,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolDelete
* deletes @a aSymbolName from the library at @a aLibraryPath.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @param aSymbolName is the name of a footprint to delete from the specified library.
*
* @param aProperties is an associative array that can be used to tell the
* library delete function anything special, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
*/
virtual void SymbolDelete( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolLibCreate
* creates a new empty footprint library at @a aLibraryPath empty. It is an
* error to attempt to create an existing library or to attempt to create
* on a "read only" location.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @param aProperties is an associative array that can be used to tell the
* library create function anything special, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem finding the library, or creating it.
*/
virtual void SymbolLibCreate( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolLibDelete
* deletes an existing footprint library and returns true, or if library does not
* exist returns false, or throws an exception if library exists but is read only or
* cannot be deleted for some other reason.
*
* @param aLibraryPath is a locator for the "library", usually a directory
* or file which will contain footprints.
*
* @param aProperties is an associative array that can be used to tell the
* library delete implementation function anything special, because it can
* take any number of additional named tuning arguments that the plugin is
* known to support. The caller continues to own this object (plugin may
* not delete it), and plugins should expect it to be optionally NULL.
*
* @return bool - true if library deleted, false if library did not exist.
*
* @throw IO_ERROR if there is a problem deleting an existing library.
*/
virtual bool SymbolLibDelete( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
/**
* Function IsSymbolLibWritable
* returns true iff the library at @a aLibraryPath is writable. (Often
* system libraries are read only because of where they are installed.)
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
*
* @throw IO_ERROR if no library at aLibraryPath exists.
*/
virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
/**
* Function SymbolLibOptions
* appends supported SCH_PLUGIN options to @a aListToAppenTo along with
* internationalized descriptions. Options are typically appended so
* that a derived SCH_PLUGIN can call its base class
* function by the same name first, thus inheriting options declared there.
* (Some base class options could pertain to all Symbol*() functions
* in all derived SCH_PLUGINs.) Note that since aListToAppendTo is a PROPERTIES
* object, all options will be unique and last guy wins.
*
* @param aListToAppendTo holds a tuple of
* <dl>
* <dt>option</dt>
* <dd>This eventually is what shows up into the fp-lib-table "options"
* field, possibly combined with others.</dd>
* <dt>internationalized description</dt>
* <dd>The internationalized description is displayed in DIALOG_FP_SCH_PLUGIN_OPTIONS.
* It may be multi-line and be quite explanatory of the option.</dd>
* </dl>
* <br>
* In the future perhaps @a aListToAppendTo evolves to something capable of also
* holding a wxValidator for the cells in said dialog:
* http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180.
* This would require a 3 column list, and introducing wx GUI knowledge to
* SCH_PLUGIN, which has been avoided to date.
*/
virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
//-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
/* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
automatically if you do not provide one. If you decide you need to
provide a zero argument constructor of your own design, that is allowed.
It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
API functions which take one.
*/
virtual ~SCH_PLUGIN() { }
/**
* Class SCH_PLUGIN_RELEASER
* releases a SCH_PLUGIN in the context of a potential thrown exception, through
* its destructor.
*/
class SCH_PLUGIN_RELEASER
{
SCH_PLUGIN* plugin;
// private assignment operator so it's illegal
SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
// private copy constructor so it's illegal
SCH_PLUGIN_RELEASER( const SCH_PLUGIN_RELEASER& aOther ) {}
public:
SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = NULL ) :
plugin( aPlugin )
{
}
~SCH_PLUGIN_RELEASER()
{
if( plugin )
release();
}
void release()
{
SCH_IO_MGR::ReleasePlugin( plugin );
plugin = NULL;
}
void set( SCH_PLUGIN* aPlugin )
{
if( plugin )
release();
plugin = aPlugin;
}
operator SCH_PLUGIN* () const
{
return plugin;
}
SCH_PLUGIN* operator -> () const
{
return plugin;
}
};
};
#endif // _SCH_IO_MGR_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,108 @@
#ifndef _SCH_LEGACY_PLUGIN_H_
#define _SCH_LEGACY_PLUGIN_H_
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2016 KiCad Developers, see change_log.txt for contributors.
*
* @author Wayne Stambaugh <stambaughw@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sch_io_mgr.h>
class KIWAY;
class LINE_READER;
class SCH_SCREEN;
class SCH_SHEET;
class SCH_BITMAP;
class SCH_JUNCTION;
class SCH_NO_CONNECT;
class SCH_LINE;
class SCH_BUS_ENTRY_BASE;
class SCH_TEXT;
class SCH_COMPONENT;
class PROPERTIES;
/**
* Class SCH_LEGACY_PLUGIN
*
* is a #SCH_PLUGIN derivation for loading schematic files created before the new
* s-expression file format.
*
* The legacy parser and formatter attempt to be compatible with the legacy file format.
* The original parser was very forgiving in that it would parse only part of a keyword.
* So "$C", "$Co", and "$Com" could be used for "$Comp" and the old parser would allow
* this. This parser is not that forgiving and sticks to the legacy file format document.
*
* As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.
*/
class SCH_LEGACY_PLUGIN : public SCH_PLUGIN
{
public:
const wxString GetName() const
{
return wxT( "Eeschema-Legacy" );
}
const wxString GetFileExtension() const
{
return wxT( "sch" );
}
SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
void Save( const wxString& aFileName, SCH_SHEET* aSheet,
const PROPERTIES* aProperties = NULL ) {}
//-----</PLUGIN IMPLEMENTATION>---------------------------------------------
SCH_LEGACY_PLUGIN();
virtual ~SCH_LEGACY_PLUGIN() {}
private:
void loadHierarchy( SCH_SHEET* aSheet );
void loadHeader( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );
void loadPageSettings( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );
void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
SCH_SHEET* loadSheet( FILE_LINE_READER& aReader );
SCH_BITMAP* loadBitmap( FILE_LINE_READER& aReader );
SCH_JUNCTION* loadJunction( FILE_LINE_READER& aReader );
SCH_NO_CONNECT* loadNoConnect( FILE_LINE_READER& aReader );
SCH_LINE* loadWire( FILE_LINE_READER& aReader );
SCH_BUS_ENTRY_BASE* loadBusEntry( FILE_LINE_READER& aReader );
SCH_TEXT* loadText( FILE_LINE_READER& aReader );
SCH_COMPONENT* loadComponent( FILE_LINE_READER& aReader );
protected:
int m_version; ///< Version of file being loaded.
wxString m_error; ///< For throwing exceptions
wxString m_path; ///< Root project path for loading child sheets.
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be NULL.
KIWAY* m_kiway; ///< Required for path to legacy component libraries.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
/// initialize PLUGIN like a constructor would.
void init( KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
};
#endif // _SCH_LEGACY_PLUGIN_H_

152
eeschema/sch_plugin.cpp Normal file
View File

@ -0,0 +1,152 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2016 KiCad Developers, see change_log.txt for contributors.
*
* @author Wayne Stambaugh <stambaughw@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <properties.h>
#include <sch_io_mgr.h>
#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )
/**
* Function not_implemented
* throws an IO_ERROR and complains of an API function not being implemented.
*
* @param aPlugin is a SCH_PLUGIN instance
* @param aCaller is the name of the unimplemented API function.
*/
static void not_implemented( SCH_PLUGIN* aPlugin, const char* aCaller )
{
THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED,
aPlugin->GetName().GetData(),
wxString::FromUTF8( aCaller ).GetData() )
);
}
SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCH_SHEET* aAppendToMe,
const PROPERTIES* aProperties )
{
not_implemented( this, __FUNCTION__ );
return NULL;
}
void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSchematic,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
}
wxArrayString SCH_PLUGIN::SymbolEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return wxArrayString();
}
LIB_PART* SCH_PLUGIN::SymbolLoad( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return NULL;
}
void SCH_PLUGIN::SymbolSave( const wxString& aLibraryPath, const LIB_PART* aSymbol,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
}
void SCH_PLUGIN::SymbolDelete( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
}
void SCH_PLUGIN::SymbolLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
}
bool SCH_PLUGIN::SymbolLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return false;
}
bool SCH_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return false;
}
void SCH_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
{
// disable all these in another couple of months, after everyone has seen them:
#if 1
(*aListToAppendTo)["debug_level"] = UTF8( _(
"Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
));
(*aListToAppendTo)["read_filter_regex"] = UTF8( _(
"Regular expression <b>symbol name</b> filter."
));
(*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
"Enable transaction logging. The mere presence of this option turns on the "
"logging, no need to set a Value."
));
(*aListToAppendTo)["username"] = UTF8( _(
"User name for <b>login</b> to some special library server."
));
(*aListToAppendTo)["password"] = UTF8( _(
"Password for <b>login</b> to some special library server."
));
#endif
#if 1
// Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
// if and when implemented.
(*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
"Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
));
#endif
}

View File

@ -134,6 +134,18 @@ int SCH_SHEET::GetScreenCount() const
}
SCH_SHEET* SCH_SHEET::GetRootSheet()
{
SCH_SHEET* sheet = dynamic_cast< SCH_SHEET* >( GetParent() );
if( sheet == NULL )
return this;
// Recurse until a sheet is found with no parent which is the root sheet.
return sheet->GetRootSheet();
}
bool SCH_SHEET::Save( FILE* aFile ) const
{
if( fprintf( aFile, "$Sheet\n" ) == EOF
@ -765,6 +777,7 @@ bool SCH_SHEET::Load( SCH_EDIT_FRAME* aFrame )
bool success = true;
SCH_SCREEN* screen = NULL;
if( !m_screen )
{
g_RootSheet->SearchHierarchy( m_fileName, &screen );
@ -789,9 +802,16 @@ bool SCH_SHEET::Load( SCH_EDIT_FRAME* aFrame )
{
if( bs->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheetstruct = (SCH_SHEET*) bs;
SCH_SHEET* sheet = (SCH_SHEET*) bs;
if( !sheetstruct->Load( aFrame ) )
// Set the parent to this sheet. This effectively creates a method
// to find the root sheet from any sheet so a pointer to the root
// sheet does not need to be stored globally. Note: this is not the
// same as a hierarchy. Complex hierarchies can have multiple copies
// of a sheet. This only provides a simple tree to find the root sheet.
sheet->SetParent( this );
if( !sheet->Load( aFrame ) )
success = false;
}

View File

@ -61,12 +61,7 @@ class NETLIST_OBJECT_LIST;
*/
class SCH_SHEET_PIN : public SCH_HIERLABEL
{
private:
int m_number; ///< Label number use for saving sheet label to file.
///< Sheet label numbering begins at 2.
///< 0 is reserved for the sheet name.
///< 1 is reserve for the sheet file name.
public:
/**
* Defines the edge of the sheet that the sheet pin is positioned
* SHEET_LEFT_SIDE = 0: pin on left side
@ -84,6 +79,13 @@ private:
SHEET_BOTTOM_SIDE,
SHEET_UNDEFINED_SIDE
};
private:
int m_number; ///< Label number use for saving sheet label to file.
///< Sheet label numbering begins at 2.
///< 0 is reserved for the sheet name.
///< 1 is reserve for the sheet file name.
SHEET_SIDE m_edge;
public:
@ -287,6 +289,19 @@ public:
void SetSize( const wxSize& aSize ) { m_size = aSize; }
/**
* Function GetRootSheet
*
* returns the root sheet of this SCH_SHEET object.
*
* The root (top level) sheet can be found by walking up the parent links until the only
* sheet that has no parent is found. The root sheet can be found from any sheet without
* having to maintain a global root sheet pointer.
*
* @return a SCH_SHEET pointer to the root sheet.
*/
SCH_SHEET* GetRootSheet();
/**
* Function SetScreen
* sets the screen associated with this sheet to \a aScreen.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 jean-pierre.charras jp.charras at wanadoo.fr
* Copyright (C) 2013 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2013-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -56,7 +56,8 @@ private:
int m_ppi; // the bitmap definition. the default is 300PPI
public: BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
public:
BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
@ -73,6 +74,11 @@ public: BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
double GetPixelScaleFactor() { return m_pixelScaleFactor; }
void SetPixelScaleFactor( double aSF ) { m_pixelScaleFactor = aSF; }
wxImage* GetImageData() { return m_image; }
void SetImage( wxImage* aImage )
{
delete m_image;
m_image = aImage;
}
/*
* Function RebuildBitmap
@ -81,6 +87,12 @@ public: BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
*/
void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
void SetBitmap( wxBitmap* aBitMap )
{
delete m_bitmap;
m_bitmap = aBitMap;
}
/**
* Function ImportData
* Copy aItem image to me and update m_bitmap

View File

@ -31,6 +31,7 @@
#include <map>
#include <io_mgr.h>
#include <project.h>
#include <properties.h>
#include <boost/interprocess/exceptions.hpp>
#define FP_LATE_ENVVAR 1 ///< late=1/early=0 environment variable expansion

52
include/properties.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef _PROPERTIES_H_
#define _PROPERTIES_H_
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2016 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <map>
#include <utf8.h>
/**
* Class PROPERTIES
* is a name/value tuple with unique names and optional values. The names
* may be iterated alphabetically.
*/
class PROPERTIES : public std::map< std::string, UTF8 >
{
// alphabetical tuple of name and value hereby defined.
public:
/**
* Function Value
* fetches a property by aName and returns true if that property was found, else false.
* If not found, aFetchedValue is not touched.
* @param aName is the property or option to look for.
* @param aFetchedValue is where to put the value of the property if it
* exists and aFetchedValue is not NULL.
* @return bool - true if property is found, else false.
*/
bool Value( const char* aName, UTF8* aFetchedValue = NULL ) const;
};
#endif // _PROPERTIES_H_

View File

@ -29,6 +29,7 @@
#include <fctsys.h>
#include <confirm.h>
#include <properties.h>
#include <wxPcbStruct.h>
#include <pcbnew.h>
#include <io_mgr.h>

View File

@ -65,6 +65,7 @@ Load() TODO's
#include <trigo.h>
#include <macros.h>
#include <kicad_string.h>
#include <properties.h>
#include <wx/filename.h>
#include <class_board.h>

View File

@ -43,21 +43,6 @@
#define FMT_NOTFOUND _( "Plugin type '%s' is not found." )
// is there a better place for this function?
bool PROPERTIES::Value( const char* aName, UTF8* aFetchedValue ) const
{
PROPERTIES::const_iterator it = find( aName );
if( it != end() )
{
if( aFetchedValue )
*aFetchedValue = it->second;
return true;
}
return false;
}
// Some day plugins might be in separate DLL/DSOs, simply because of numbers of them
// and code size. Until then, use the simplest method:

View File

@ -32,29 +32,7 @@
class BOARD;
class PLUGIN;
class MODULE;
/**
* Class PROPERTIES
* is a name/value tuple with unique names and optional values. The names
* may be iterated alphabetically.
*/
class PROPERTIES : public std::map< std::string, UTF8 >
{
// alphabetical tuple of name and value hereby defined.
public:
/**
* Function Value
* fetches a property by aName and returns true if that property was found, else false.
* If not found, aFetchedValue is not touched.
* @param aName is the property or option to look for.
* @param aFetchedValue is where to put the value of the property if it
* exists and aFetchedValue is not NULL.
* @return bool - true if property is found, else false.
*/
bool Value( const char* aName, UTF8* aFetchedValue = NULL ) const;
};
class PROPERTIES;
/**

View File

@ -68,6 +68,7 @@
#include <kicad_string.h>
#include <macros.h>
#include <properties.h>
#include <zones.h>
#include <class_board.h>

View File

@ -23,6 +23,8 @@
*/
#include <io_mgr.h>
#include <properties.h>
#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )

View File

@ -36,6 +36,7 @@
#include <confirm.h>
#include <hotkeys_basic.h>
#include <properties.h>
#include <io_mgr.h>
#include <pcbnew_id.h>