2020-02-13 13:39:52 +00:00
|
|
|
#ifndef _SCH_SEXPR_PLUGIN_H_
|
|
|
|
#define _SCH_SEXPR_PLUGIN_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 CERN
|
2021-06-10 14:10:55 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-02-13 13:39:52 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <sch_io_mgr.h>
|
2020-05-13 21:58:30 +00:00
|
|
|
#include <sch_file_versions.h>
|
2020-02-13 13:39:52 +00:00
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
|
|
|
|
class KIWAY;
|
|
|
|
class LINE_READER;
|
|
|
|
class SCH_SCREEN;
|
|
|
|
class SCH_SHEET;
|
2021-04-12 19:08:02 +00:00
|
|
|
struct SCH_SHEET_INSTANCE;
|
|
|
|
class SCH_SHEET_PATH;
|
2020-02-13 13:39:52 +00:00
|
|
|
class SCH_BITMAP;
|
|
|
|
class SCH_JUNCTION;
|
|
|
|
class SCH_NO_CONNECT;
|
|
|
|
class SCH_LINE;
|
2021-07-17 19:56:18 +00:00
|
|
|
class SCH_SHAPE;
|
2020-02-13 13:39:52 +00:00
|
|
|
class SCH_BUS_ENTRY_BASE;
|
|
|
|
class SCH_TEXT;
|
2021-06-10 14:10:55 +00:00
|
|
|
class SCH_SYMBOL;
|
2020-02-13 13:39:52 +00:00
|
|
|
class SCH_FIELD;
|
2021-04-12 19:08:02 +00:00
|
|
|
struct SYMBOL_INSTANCE_REFERENCE;
|
2020-02-13 13:39:52 +00:00
|
|
|
class PROPERTIES;
|
2020-05-15 19:53:59 +00:00
|
|
|
class EE_SELECTION;
|
2020-02-13 13:39:52 +00:00
|
|
|
class SCH_SEXPR_PLUGIN_CACHE;
|
2021-06-10 18:51:46 +00:00
|
|
|
class LIB_SYMBOL;
|
2021-06-15 12:31:28 +00:00
|
|
|
class SYMBOL_LIB;
|
2020-02-13 13:39:52 +00:00
|
|
|
class BUS_ALIAS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A #SCH_PLUGIN derivation for loading schematic files using the new s-expression
|
|
|
|
* file format.
|
|
|
|
*
|
|
|
|
* As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.
|
|
|
|
*/
|
|
|
|
class SCH_SEXPR_PLUGIN : public SCH_PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SCH_SEXPR_PLUGIN();
|
|
|
|
virtual ~SCH_SEXPR_PLUGIN();
|
|
|
|
|
|
|
|
const wxString GetName() const override
|
|
|
|
{
|
2020-02-28 14:03:09 +00:00
|
|
|
return wxT( "Eeschema s-expression" );
|
2020-02-13 13:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const wxString GetFileExtension() const override
|
|
|
|
{
|
2020-02-28 14:03:09 +00:00
|
|
|
return wxT( "kicad_sch" );
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString GetLibraryFileExtension() const override
|
|
|
|
{
|
|
|
|
return wxT( "kicad_sym" );
|
2020-02-13 13:39:52 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
|
|
|
|
{
|
|
|
|
m_progressReporter = aReporter;
|
|
|
|
}
|
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
/**
|
|
|
|
* The 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;
|
|
|
|
|
|
|
|
int GetModifyHash() const override;
|
|
|
|
|
2020-05-21 03:00:23 +00:00
|
|
|
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
2020-02-13 13:39:52 +00:00
|
|
|
SCH_SHEET* aAppendToMe = nullptr,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet,
|
|
|
|
int aVersion = SEXPR_SCHEMATIC_FILE_VERSION );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2020-05-21 03:00:23 +00:00
|
|
|
void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
2020-02-13 13:39:52 +00:00
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
void Format( SCH_SHEET* aSheet );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
void Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath,
|
|
|
|
SCH_SHEET_LIST* aFullSheetHierarchy, OUTPUTFORMATTER* aFormatter );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
2021-06-10 18:51:46 +00:00
|
|
|
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
|
2020-02-13 13:39:52 +00:00
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
void CreateSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
bool DeleteSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
void SaveLibrary( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = nullptr ) override;
|
|
|
|
|
|
|
|
bool CheckHeader( const wxString& aFileName ) override;
|
|
|
|
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
|
|
|
|
|
|
|
|
const wxString& GetError() const override { return m_error; }
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
static LIB_SYMBOL* ParseLibSymbol( LINE_READER& aReader,
|
|
|
|
int aVersion = SEXPR_SCHEMATIC_FILE_VERSION );
|
|
|
|
static void FormatLibSymbol( LIB_SYMBOL* aPart, OUTPUTFORMATTER& aFormatter );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void loadHierarchy( SCH_SHEET* aSheet );
|
2020-04-26 20:53:29 +00:00
|
|
|
void loadFile( const wxString& aFileName, SCH_SHEET* aSheet );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath, int aNestLevel );
|
2020-03-16 13:04:50 +00:00
|
|
|
void saveField( SCH_FIELD* aField, int aNestLevel );
|
|
|
|
void saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel );
|
|
|
|
void saveSheet( SCH_SHEET* aSheet, int aNestLevel );
|
|
|
|
void saveJunction( SCH_JUNCTION* aJunction, int aNestLevel );
|
|
|
|
void saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel );
|
|
|
|
void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLevel );
|
|
|
|
void saveLine( SCH_LINE* aLine, int aNestLevel );
|
2021-07-17 19:56:18 +00:00
|
|
|
void saveShape( SCH_SHAPE* aShape, int aNestLevel );
|
2020-03-16 13:04:50 +00:00
|
|
|
void saveText( SCH_TEXT* aText, int aNestLevel );
|
|
|
|
void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel );
|
2021-04-12 19:08:02 +00:00
|
|
|
void saveInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheets,
|
|
|
|
const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbols, int aNestLevel );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-03-26 17:30:47 +00:00
|
|
|
void cacheLib( const wxString& aLibraryFileName, const PROPERTIES* aProperties );
|
2020-02-13 13:39:52 +00:00
|
|
|
bool isBuffering( const PROPERTIES* aProperties );
|
|
|
|
|
|
|
|
protected:
|
2021-06-23 22:53:08 +00:00
|
|
|
int m_version; ///< Version of file being loaded.
|
|
|
|
int m_nextFreeFieldId;
|
|
|
|
|
|
|
|
wxString m_error; ///< For throwing exceptions or errors on partial
|
|
|
|
///< loads.
|
|
|
|
PROGRESS_REPORTER* m_progressReporter;
|
|
|
|
|
|
|
|
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.
|
|
|
|
SCHEMATIC* m_schematic;
|
|
|
|
OUTPUTFORMATTER* m_out; ///< The formatter for saving SCH_SCREEN objects.
|
2020-02-13 13:39:52 +00:00
|
|
|
SCH_SEXPR_PLUGIN_CACHE* m_cache;
|
|
|
|
|
|
|
|
/// initialize PLUGIN like a constructor would.
|
2020-05-21 03:00:23 +00:00
|
|
|
void init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr );
|
2020-02-13 13:39:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _SCH_SEXPR_PLUGIN_H_
|