2020-08-23 19:01:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
2024-01-30 23:06:58 +00:00
|
|
|
* Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-08-23 19:01:08 +00:00
|
|
|
*
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#ifndef _SCH_IO_ALTIUM_H_
|
|
|
|
#define _SCH_IO_ALTIUM_H_
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2023-09-04 21:46:25 +00:00
|
|
|
#include <vector>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <sch_io/sch_io.h>
|
|
|
|
#include <sch_io/sch_io_mgr.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <wx/filename.h>
|
2020-10-17 13:35:22 +00:00
|
|
|
#include <wx/gdicmn.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-23 15:02:56 +00:00
|
|
|
#include "altium_parser_sch.h"
|
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
class SCH_SYMBOL;
|
2020-10-27 14:51:19 +00:00
|
|
|
class SCH_SHEET;
|
2020-10-26 17:26:49 +00:00
|
|
|
class TITLE_BLOCK;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-01-06 15:27:09 +00:00
|
|
|
class ALTIUM_COMPOUND_FILE;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
/**
|
2023-12-24 00:31:24 +00:00
|
|
|
* SCH_IO_ALTIUM
|
2023-12-19 17:39:26 +00:00
|
|
|
* is a #SCH_IO derivation for loading Altium .SchDoc schematic files.
|
2020-08-23 19:01:08 +00:00
|
|
|
*
|
2023-12-19 17:39:26 +00:00
|
|
|
* As with all SCH_IO there is no UI dependencies i.e. windowing calls allowed.
|
2020-08-23 19:01:08 +00:00
|
|
|
*/
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
static std::vector<LIB_SYMBOL*> nullsym;
|
2023-09-06 17:10:54 +00:00
|
|
|
static std::vector<int> nullint;
|
2023-12-19 17:39:26 +00:00
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
class SCH_IO_ALTIUM : public SCH_IO
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_ALTIUM();
|
|
|
|
~SCH_IO_ALTIUM();
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
|
2023-08-26 19:28:53 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
|
2023-08-26 19:28:53 +00:00
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
|
2023-08-26 19:28:53 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "Altium Schematic Library or Integrated Library" ),
|
|
|
|
{ "SchLib", "IntLib" } );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-10-01 11:58:38 +00:00
|
|
|
bool CanReadSchematicFile( const wxString& aFileName ) const override;
|
|
|
|
bool CanReadLibrary( const wxString& aFileName ) const override;
|
|
|
|
|
2020-08-23 19:01:08 +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;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// unimplemented functions. Will trigger a not_implemented IO error.
|
|
|
|
//void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
|
|
|
|
|
|
|
|
//void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
|
|
|
|
// const PROPERTIES* aProperties = NULL ) override;
|
|
|
|
|
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
|
|
|
const wxString& aLibraryPath,
|
2023-08-28 21:50:56 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
|
|
|
|
|
|
|
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
|
|
|
const wxString& aLibraryPath,
|
2023-09-05 21:01:27 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath,
|
|
|
|
const wxString& aAliasName,
|
2023-08-28 21:50:56 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
//void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
|
2020-08-23 19:01:08 +00:00
|
|
|
// const PROPERTIES* aProperties = NULL ) override;
|
|
|
|
|
|
|
|
//void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
|
|
|
|
// const PROPERTIES* aProperties = NULL ) override;
|
|
|
|
|
|
|
|
//void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
|
|
|
// const PROPERTIES* aProperties = NULL ) override;
|
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
wxString getLibName();
|
|
|
|
wxFileName getLibFileName();
|
|
|
|
|
|
|
|
void ParseAltiumSch( const wxString& aFileName );
|
2022-01-06 15:27:09 +00:00
|
|
|
void ParseStorage( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
|
2022-08-09 11:39:13 +00:00
|
|
|
void ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
|
2022-01-06 15:27:09 +00:00
|
|
|
void ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
void ParseASCIISchematic( const wxString& aFileName );
|
|
|
|
|
|
|
|
void ParseRecord( int index, std::map<wxString, wxString>& properties,
|
|
|
|
const wxString& aSectionName );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
private:
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* getCurrentScreen();
|
|
|
|
SCH_SHEET* getCurrentSheet();
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
bool ShouldPutItemOnSheet( int aOwnerindex );
|
2024-02-05 19:10:26 +00:00
|
|
|
bool IsComponentPartVisible( const ASCH_OWNER_INTERFACE& aElem ) const;
|
2021-04-10 19:45:36 +00:00
|
|
|
const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
|
2022-08-16 14:45:11 +00:00
|
|
|
void AddTextBox( const ASCH_TEXT_FRAME* aElem );
|
2023-09-06 18:36:27 +00:00
|
|
|
void AddLibTextBox( const ASCH_TEXT_FRAME* aElem, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
|
2020-10-23 15:02:56 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
|
2024-01-30 23:06:58 +00:00
|
|
|
void ParseTemplate( int aIndex, const std::map<wxString, wxString>& aProperties );
|
2023-09-04 21:46:25 +00:00
|
|
|
void ParsePin( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
2023-09-06 18:36:27 +00:00
|
|
|
void ParseLabel( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
|
|
|
|
void ParseTextFrame( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
|
2021-07-05 22:57:58 +00:00
|
|
|
void ParseNote( const std::map<wxString, wxString>& aProperties );
|
2023-09-04 21:46:25 +00:00
|
|
|
void ParseBezier( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParsePolyline( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParsePolygon( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParseArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
2023-09-05 21:01:27 +00:00
|
|
|
void ParseEllipticalArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
2023-09-04 21:46:25 +00:00
|
|
|
void ParseEllipse( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParseCircle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParseLine( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
2022-08-09 11:39:13 +00:00
|
|
|
void ParseSignalHarness( const std::map<wxString, wxString>& aProperties );
|
2022-08-09 12:00:45 +00:00
|
|
|
void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
|
2022-08-09 12:15:42 +00:00
|
|
|
void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
|
2022-08-09 12:32:41 +00:00
|
|
|
void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
|
2022-08-09 19:21:36 +00:00
|
|
|
void ParseHarnessPort( const ASCH_PORT& aElem );
|
2023-09-04 21:46:25 +00:00
|
|
|
void ParseHyperlink( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
|
|
|
void ParseRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
|
2020-10-27 14:51:19 +00:00
|
|
|
void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
|
2020-10-24 16:40:16 +00:00
|
|
|
void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
|
2020-10-27 13:07:42 +00:00
|
|
|
void ParsePort( const ASCH_PORT& aElem );
|
2020-10-14 19:23:36 +00:00
|
|
|
void ParseNoERC( const std::map<wxString, wxString>& aProperties );
|
2020-08-23 19:01:08 +00:00
|
|
|
void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseBus( const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseWire( const std::map<wxString, wxString>& aProperties );
|
2020-10-09 15:21:27 +00:00
|
|
|
void ParseJunction( const std::map<wxString, wxString>& aProperties );
|
2021-04-10 19:45:36 +00:00
|
|
|
void ParseImage( const std::map<wxString, wxString>& aProperties );
|
2020-10-17 12:33:30 +00:00
|
|
|
void ParseSheet( const std::map<wxString, wxString>& aProperties );
|
2020-10-27 14:51:19 +00:00
|
|
|
void ParseSheetName( const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseFileName( const std::map<wxString, wxString>& aProperties );
|
2023-09-06 18:36:27 +00:00
|
|
|
void ParseDesignator( const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseLibDesignator( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
|
2020-10-17 14:03:46 +00:00
|
|
|
void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
|
2023-09-06 18:36:27 +00:00
|
|
|
void ParseParameter( const std::map<wxString, wxString>& aProperties );
|
|
|
|
void ParseLibParameter( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
|
2021-07-07 19:01:49 +00:00
|
|
|
void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
|
2023-09-05 21:01:27 +00:00
|
|
|
void ParseImplementation( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
void ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile, std::vector<int>& aFontSizes );
|
2023-08-28 21:50:56 +00:00
|
|
|
std::map<wxString,LIB_SYMBOL*> ParseLibFile( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
|
2023-09-04 21:46:25 +00:00
|
|
|
std::vector<LIB_SYMBOL*> ParseLibComponent( const std::map<wxString, wxString>& aProperties );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
private:
|
2020-11-05 23:19:47 +00:00
|
|
|
SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SHEET_PATH m_sheetPath;
|
2020-11-05 23:19:47 +00:00
|
|
|
SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
|
|
|
|
wxString m_libName; // Library name to save symbols
|
2023-11-17 04:20:15 +00:00
|
|
|
bool m_isIntLib; // Flag to indicate Integrated Library
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-12-27 20:39:29 +00:00
|
|
|
IO_RELEASER<SCH_IO> m_pi; // Plugin to create KiCad symbol library.
|
|
|
|
std::unique_ptr<STRING_UTF8_MAP> m_properties; // Library plugin properties.
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-11-05 23:19:47 +00:00
|
|
|
std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
|
|
|
|
// a sheet
|
2020-10-26 17:26:49 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I m_sheetOffset;
|
2020-11-05 23:19:47 +00:00
|
|
|
std::unique_ptr<ASCH_SHEET> m_altiumSheet;
|
2021-07-05 09:51:15 +00:00
|
|
|
std::map<int, SCH_SYMBOL*> m_symbols;
|
2020-11-05 23:19:47 +00:00
|
|
|
std::map<int, SCH_SHEET*> m_sheets;
|
2021-07-05 09:51:15 +00:00
|
|
|
std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
|
2020-10-23 15:02:56 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
|
2021-04-10 19:45:36 +00:00
|
|
|
std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
|
2022-08-09 11:39:13 +00:00
|
|
|
std::vector<ASCH_ADDITIONAL_FILE> m_altiumAdditional;
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
std::map<int, ASCH_SYMBOL> m_altiumComponents;
|
2024-01-30 23:06:58 +00:00
|
|
|
std::map<int, ASCH_TEMPLATE> m_altiumTemplates;
|
2021-07-07 19:01:49 +00:00
|
|
|
std::map<int, int> m_altiumImplementationList;
|
2020-11-05 23:19:47 +00:00
|
|
|
std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
// parse harness ports after "FileHeader" was parsed, in 2nd run.
|
|
|
|
std::vector<ASCH_PORT> m_altiumHarnessPortsCurrentSheet;
|
|
|
|
|
|
|
|
// Add offset to all harness ownerIndex'es after parsing FileHeader.
|
|
|
|
int m_harnessOwnerIndexOffset;
|
2022-08-09 12:00:45 +00:00
|
|
|
int m_harnessEntryParent; // used to identify harness connector for harness entry element
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
// Symbol caching
|
|
|
|
void ensureLoadedLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties );
|
|
|
|
long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
static bool isBinaryFile( const wxString& aFileName );
|
|
|
|
static bool isASCIIFile( const wxString& aFileName );
|
2023-10-01 11:58:38 +00:00
|
|
|
static bool checkFileHeader( const wxString& aFileName );
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
std::map<wxString, long long> m_timestamps;
|
|
|
|
std::map<wxString, std::map<wxString, LIB_SYMBOL*>> m_libCache;
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
// List of available fonts with font name and font size in pt
|
|
|
|
std::vector<std::pair<wxString, int>> m_fonts;
|
2020-08-23 19:01:08 +00:00
|
|
|
};
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#endif // _SCH_IO_ALTIUM_H_
|