2016-07-06 09:22:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2023-08-26 19:28:53 +00:00
|
|
|
* Copyright (C) 2016-2023 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/>.
|
|
|
|
*/
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#ifndef SCH_IO_KICAD_LEGACY_H_
|
|
|
|
#define SCH_IO_KICAD_LEGACY_H_
|
2023-08-26 19:28:53 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <memory>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <sch_io/sch_io.h>
|
|
|
|
#include <sch_io/sch_io_mgr.h>
|
2018-05-09 09:15:00 +00:00
|
|
|
#include <stack>
|
2020-04-14 18:11:50 +00:00
|
|
|
#include <general.h> // for EESCHEMA_VERSION definition
|
2023-08-26 19:28:53 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
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;
|
2021-06-10 14:10:55 +00:00
|
|
|
class SCH_SYMBOL;
|
2016-07-11 19:48:46 +00:00
|
|
|
class SCH_FIELD;
|
2022-11-06 16:51:52 +00:00
|
|
|
class STRING_UTF8_MAP;
|
2019-04-28 16:36:31 +00:00
|
|
|
class SELECTION;
|
2023-12-24 00:31:24 +00:00
|
|
|
class SCH_IO_KICAD_LEGACY_LIB_CACHE;
|
2021-06-10 18:51:46 +00:00
|
|
|
class LIB_SYMBOL;
|
2021-06-15 12:31:28 +00:00
|
|
|
class SYMBOL_LIB;
|
2019-03-11 21:32:05 +00:00
|
|
|
class BUS_ALIAS;
|
2023-09-08 02:29:40 +00:00
|
|
|
class OUTPUTFORMATTER;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-12-19 17:39:26 +00:00
|
|
|
* A #SCH_IO derivation for loading schematic files created before the new s-expression
|
2017-09-02 18:12:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2023-12-19 17:39:26 +00:00
|
|
|
* As with all SCH_IO there is no UI dependencies i.e. windowing calls allowed.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2023-12-24 00:31:24 +00:00
|
|
|
class SCH_IO_KICAD_LEGACY : public SCH_IO
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_KICAD_LEGACY();
|
|
|
|
virtual ~SCH_IO_KICAD_LEGACY();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy schematic files" ),
|
2023-12-28 02:10:01 +00:00
|
|
|
{ FILEEXT::LegacySchematicFileExtension } );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
|
2020-02-28 14:03:09 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy symbol library files" ),
|
2023-12-28 02:10:01 +00:00
|
|
|
{ FILEEXT::LegacySymbolLibFileExtension } );
|
2020-02-28 14:03:09 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
bool CanReadSchematicFile( const wxString& aFileName ) const override;
|
|
|
|
|
|
|
|
bool CanReadLibrary( const wxString& aFileName ) const override;
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
/**
|
2019-11-06 19:15:42 +00:00
|
|
|
* The property used internally by the plugin to enable cache buffering which prevents
|
2017-01-27 15:56:36 +00:00
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
2019-11-06 19:15:42 +00:00
|
|
|
* The property used internally by the plugin to disable writing the library
|
2017-01-27 15:56:36 +00:00
|
|
|
* documentation (.dcm) file when saving the library cache.
|
|
|
|
*/
|
|
|
|
static const char* PropNoDocFile;
|
|
|
|
|
2016-10-24 23:18:50 +00:00
|
|
|
int GetModifyHash() const override;
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
|
|
|
SCH_SHEET* aAppendToMe = nullptr,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2019-04-28 16:36:31 +00:00
|
|
|
|
|
|
|
void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
|
|
|
|
int version = EESCHEMA_VERSION );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-03-22 12:19:47 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
void Format( SCH_SHEET* aSheet );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
2016-08-18 23:23:10 +00:00
|
|
|
const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
2017-02-24 16:09:27 +00:00
|
|
|
const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-03-22 12:19:47 +00:00
|
|
|
void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2023-12-27 00:25:41 +00:00
|
|
|
void CreateLibrary( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
|
|
|
bool DeleteLibrary( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2021-03-22 12:19:47 +00:00
|
|
|
void SaveLibrary( const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2023-09-08 02:29:40 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool IsLibraryWritable( 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
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
static LIB_SYMBOL* ParsePart( LINE_READER& aReader, int majorVersion = 0,
|
|
|
|
int minorVersion = 0 );
|
|
|
|
static void FormatPart( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter );
|
2017-12-07 00:10:45 +00:00
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
private:
|
2021-06-23 22:53:08 +00:00
|
|
|
void checkpoint();
|
2016-07-06 09:22:56 +00:00
|
|
|
void loadHierarchy( SCH_SHEET* aSheet );
|
2019-04-28 16:36:31 +00:00
|
|
|
void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
|
|
|
|
void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
|
2016-07-06 09:22:56 +00:00
|
|
|
void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_SHEET* loadSheet( LINE_READER& aReader );
|
|
|
|
SCH_BITMAP* loadBitmap( LINE_READER& aReader );
|
|
|
|
SCH_JUNCTION* loadJunction( LINE_READER& aReader );
|
|
|
|
SCH_NO_CONNECT* loadNoConnect( LINE_READER& aReader );
|
|
|
|
SCH_LINE* loadWire( LINE_READER& aReader );
|
|
|
|
SCH_BUS_ENTRY_BASE* loadBusEntry( LINE_READER& aReader );
|
|
|
|
SCH_TEXT* loadText( LINE_READER& aReader );
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* loadSymbol( LINE_READER& aReader );
|
2019-04-28 16:36:31 +00:00
|
|
|
std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void saveSymbol( SCH_SYMBOL* aSymbol );
|
2021-03-22 12:19:47 +00:00
|
|
|
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 );
|
|
|
|
void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
|
|
|
|
bool writeDocFile( const STRING_UTF8_MAP* aProperties );
|
|
|
|
bool isBuffering( const STRING_UTF8_MAP* aProperties );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
protected:
|
2021-06-23 22:53:08 +00:00
|
|
|
int m_version; ///< Version of file being loaded.
|
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
///< Indicate if we are appending the loaded schemitic or loading a full project.
|
|
|
|
bool m_appending;
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
wxString m_error; ///< For throwing exceptions or errors on partial
|
|
|
|
///< schematic loads.
|
|
|
|
LINE_READER* m_lineReader; ///< for progress reporting
|
|
|
|
unsigned m_lastProgressLine;
|
|
|
|
unsigned m_lineCount; ///< for progress reporting
|
|
|
|
|
|
|
|
wxString m_path; ///< Root project path for loading child sheets.
|
|
|
|
std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths
|
|
|
|
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.
|
2022-10-15 18:15:51 +00:00
|
|
|
SCH_SHEET* m_currentSheet; ///< The sheet currently being loaded.
|
2021-06-23 22:53:08 +00:00
|
|
|
OUTPUTFORMATTER* m_out; ///< The formatter for saving SCH_SCREEN objects.
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_KICAD_LEGACY_LIB_CACHE* m_cache;
|
2021-06-23 22:53:08 +00:00
|
|
|
SCHEMATIC* m_schematic;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
/// initialize PLUGIN like a constructor would.
|
2022-11-06 16:51:52 +00:00
|
|
|
void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
};
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#endif // SCH_IO_KICAD_LEGACY_H_
|