2016-07-06 09:22:56 +00:00
|
|
|
#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
|
2019-03-15 13:09:42 +00:00
|
|
|
* Copyright (C) 2016-2019 KiCad Developers, see change_log.txt for contributors.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <memory>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_io_mgr.h>
|
2018-05-09 09:15:00 +00:00
|
|
|
#include <stack>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2016-07-11 19:48:46 +00:00
|
|
|
class SCH_FIELD;
|
2016-07-06 09:22:56 +00:00
|
|
|
class PROPERTIES;
|
2016-08-18 23:23:10 +00:00
|
|
|
class SCH_LEGACY_PLUGIN_CACHE;
|
|
|
|
class LIB_PART;
|
|
|
|
class PART_LIB;
|
2016-09-03 18:28:17 +00:00
|
|
|
class LIB_ALIAS;
|
2019-03-11 21:32:05 +00:00
|
|
|
class BUS_ALIAS;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-02 18:12:50 +00:00
|
|
|
* A #SCH_PLUGIN derivation for loading schematic files created before the new s-expression
|
|
|
|
* file format.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_LEGACY_PLUGIN();
|
2017-01-28 04:30:13 +00:00
|
|
|
virtual ~SCH_LEGACY_PLUGIN();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
const wxString GetName() const override
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
return wxT( "Eeschema-Legacy" );
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
const wxString GetFileExtension() const override
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
return wxT( "sch" );
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
/**
|
|
|
|
* const char* PropBuffering
|
|
|
|
*
|
|
|
|
* is a property used internally by the plugin to enable cache buffering which prevents
|
|
|
|
* the library file from being written every time the cache is changed. This is useful
|
|
|
|
* when writing the schematic cache library file or saving a library to a new file name.
|
|
|
|
*/
|
|
|
|
static const char* PropBuffering;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* const char* PropBuffering
|
|
|
|
*
|
|
|
|
* is a property used internally by the plugin to disable writing the library
|
|
|
|
* documentation (.dcm) file when saving the library cache.
|
|
|
|
*/
|
|
|
|
static const char* PropNoDocFile;
|
|
|
|
|
2016-10-24 23:18:50 +00:00
|
|
|
int GetModifyHash() const override;
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
|
2016-09-25 17:06:49 +00:00
|
|
|
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
void Save( const wxString& aFileName, SCH_SCREEN* aScreen, KIWAY* aKiway,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
void Format( SCH_SCREEN* aScreen );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
size_t GetSymbolLibCount( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-08-18 23:23:10 +00:00
|
|
|
void EnumerateSymbolLib( wxArrayString& aAliasNameList,
|
|
|
|
const wxString& aLibraryPath,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2017-02-24 16:09:27 +00:00
|
|
|
void EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
|
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-09-03 18:28:17 +00:00
|
|
|
LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-09-17 17:31:58 +00:00
|
|
|
void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-09-23 17:28:38 +00:00
|
|
|
void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-09-29 22:31:43 +00:00
|
|
|
void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-10-05 23:28:56 +00:00
|
|
|
void CreateSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2016-10-09 12:29:44 +00:00
|
|
|
bool DeleteSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2017-01-27 15:56:36 +00:00
|
|
|
void SaveLibrary( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ) override;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2017-06-26 11:13:43 +00:00
|
|
|
bool CheckHeader( const wxString& aFileName ) override;
|
2017-10-06 18:07:43 +00:00
|
|
|
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
|
2017-06-21 12:41:00 +00:00
|
|
|
|
2017-12-07 00:10:45 +00:00
|
|
|
const wxString& GetError() const override { return m_error; }
|
2019-03-15 13:09:42 +00:00
|
|
|
|
|
|
|
static LIB_PART * ParsePart( LINE_READER& reader, int aMajorVersion = 0,
|
|
|
|
int aMinorVersion = 0 );
|
|
|
|
static void FormatPart( LIB_PART* part, OUTPUTFORMATTER& formatter );
|
2017-12-07 00:10:45 +00:00
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
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 );
|
2019-03-11 21:32:05 +00:00
|
|
|
std::shared_ptr< BUS_ALIAS > loadBusAlias( FILE_LINE_READER& aReader, SCH_SCREEN* aScreen );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
void saveComponent( SCH_COMPONENT* aComponent );
|
|
|
|
void saveField( SCH_FIELD* aField );
|
|
|
|
void saveBitmap( SCH_BITMAP* aBitmap );
|
|
|
|
void saveSheet( SCH_SHEET* aSheet );
|
|
|
|
void saveJunction( SCH_JUNCTION* aJunction );
|
|
|
|
void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
|
|
|
|
void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
|
|
|
|
void saveLine( SCH_LINE* aLine );
|
|
|
|
void saveText( SCH_TEXT* aText );
|
2019-03-11 21:32:05 +00:00
|
|
|
void saveBusAlias( std::shared_ptr< BUS_ALIAS > aAlias );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
void cacheLib( const wxString& aLibraryFileName );
|
2017-01-27 15:56:36 +00:00
|
|
|
bool writeDocFile( const PROPERTIES* aProperties );
|
|
|
|
bool isBuffering( const PROPERTIES* aProperties );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
protected:
|
2016-07-06 09:22:56 +00:00
|
|
|
int m_version; ///< Version of file being loaded.
|
2017-12-07 00:10:45 +00:00
|
|
|
|
|
|
|
/** For throwing exceptions or errors on partial schematic loads. */
|
|
|
|
wxString m_error;
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
wxString m_path; ///< Root project path for loading child sheets.
|
2018-05-09 09:15:00 +00:00
|
|
|
std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths
|
2016-07-06 09:22:56 +00:00
|
|
|
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..
|
2016-07-11 19:48:46 +00:00
|
|
|
FILE_OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_LEGACY_PLUGIN_CACHE* m_cache;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
/// initialize PLUGIN like a constructor would.
|
|
|
|
void init( KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _SCH_LEGACY_PLUGIN_H_
|