KiCad PCB EDA Suite
sch_altium_plugin.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Thomas Pointhuber <[email protected]>
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef _SCH_ALTIUM_PLUGIN_H_
26 #define _SCH_ALTIUM_PLUGIN_H_
27 
28 #include <memory>
29 #include <sch_io_mgr.h>
30 #include <wx/filename.h>
31 #include <wx/gdicmn.h>
32 
33 #include "altium_parser_sch.h"
34 
35 
36 class SCH_SYMBOL;
37 class SCH_SHEET;
38 class TITLE_BLOCK;
39 
40 namespace CFB
41 {
42 class CompoundFileReader;
43 }
44 
52 {
53 public:
56 
57  const wxString GetName() const override;
58 
59  void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
60 
61  const wxString GetFileExtension() const override;
62 
63  const wxString GetLibraryFileExtension() const override;
64 
65  int GetModifyHash() const override;
66 
67  SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
68  SCH_SHEET* aAppendToMe = nullptr,
69  const PROPERTIES* aProperties = nullptr ) override;
70 
71  bool CheckHeader( const wxString& aFileName ) override;
72 
73  // unimplemented functions. Will trigger a not_implemented IO error.
74  //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
75 
76  //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
77  // const PROPERTIES* aProperties = NULL ) override;
78 
79  //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath,
80  // const PROPERTIES* aProperties = NULL ) override;
81 
82  //LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
83  // const PROPERTIES* aProperties = NULL ) override;
84 
85  //void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
86  // const PROPERTIES* aProperties = NULL ) override;
87 
88  //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
89  // const PROPERTIES* aProperties = NULL ) override;
90 
91  //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
92  // const PROPERTIES* aProperties = NULL ) override;
93 
94  //void CreateSymbolLib( const wxString& aLibraryPath,
95  // const PROPERTIES* aProperties = NULL ) override;
96 
97  // bool DeleteSymbolLib( const wxString& aLibraryPath,
98  // const PROPERTIES* aProperties = NULL ) override;
99 
100  //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
101 
102  //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
103 
104  wxString getLibName();
105  wxFileName getLibFileName();
106 
107  void ParseAltiumSch( const wxString& aFileName );
108  void ParseStorage( const CFB::CompoundFileReader& aReader );
109  void ParseFileHeader( const CFB::CompoundFileReader& aReader );
110 
111 private:
112  bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const;
113  const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
114 
115  void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
116  void ParsePin( const std::map<wxString, wxString>& aProperties );
117  void ParseLabel( const std::map<wxString, wxString>& aProperties );
118  void ParseTextFrame( const std::map<wxString, wxString>& aProperties );
119  void ParseNote( const std::map<wxString, wxString>& aProperties );
120  void ParseBezier( const std::map<wxString, wxString>& aProperties );
121  void ParsePolyline( const std::map<wxString, wxString>& aProperties );
122  void ParsePolygon( const std::map<wxString, wxString>& aProperties );
123  void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties );
124  void ParseArc( const std::map<wxString, wxString>& aProperties );
125  void ParseLine( const std::map<wxString, wxString>& aProperties );
126  void ParseRectangle( const std::map<wxString, wxString>& aProperties );
127  void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
128  void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
129  void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
130  void ParsePort( const ASCH_PORT& aElem );
131  void ParseNoERC( const std::map<wxString, wxString>& aProperties );
132  void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
133  void ParseBus( const std::map<wxString, wxString>& aProperties );
134  void ParseWire( const std::map<wxString, wxString>& aProperties );
135  void ParseJunction( const std::map<wxString, wxString>& aProperties );
136  void ParseImage( const std::map<wxString, wxString>& aProperties );
137  void ParseSheet( const std::map<wxString, wxString>& aProperties );
138  void ParseSheetName( const std::map<wxString, wxString>& aProperties );
139  void ParseFileName( const std::map<wxString, wxString>& aProperties );
140  void ParseDesignator( const std::map<wxString, wxString>& aProperties );
141  void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
142  void ParseParameter( const std::map<wxString, wxString>& aProperties );
143  void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
144  void ParseImplementation( const std::map<wxString, wxString>& aProperties );
145 
146 private:
147  REPORTER* m_reporter; // current reporter for warnings/errors
148 
149  SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
150  SCH_SHEET* m_currentSheet; // The current sheet of the schematic being loaded..
151  SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
152  wxString m_libName; // Library name to save symbols
153 
154  SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; // Plugin to create KiCad symbol library.
155  std::unique_ptr<PROPERTIES> m_properties; // Library plugin properties.
156 
157  std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
158  // a sheet
159 
160  wxPoint m_sheetOffset;
161  std::unique_ptr<ASCH_SHEET> m_altiumSheet;
162  std::map<int, SCH_SYMBOL*> m_symbols;
163  std::map<int, SCH_SHEET*> m_sheets;
164  std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
165 
166  std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
167  std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
168 
169  std::map<int, ASCH_SYMBOL> m_altiumComponents;
170  std::map<int, int> m_altiumImplementationList;
171  std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
172 };
173 
174 #endif // _SCH_ALTIUM_PLUGIN_H_
void ParsePort(const ASCH_PORT &aElem)
std::unique_ptr< PROPERTIES > m_properties
void SetReporter(REPORTER *aReporter) override
Set an optional reporter for warnings/errors.
void ParseLabel(const std::map< wxString, wxString > &aProperties)
void ParseBezier(const std::map< wxString, wxString > &aProperties)
std::map< int, ASCH_SYMBOL > m_altiumComponents
std::vector< ASCH_STORAGE_FILE > m_altiumStorage
void ParsePowerPort(const std::map< wxString, wxString > &aProperties)
void ParseJunction(const std::map< wxString, wxString > &aProperties)
Holds all the data relating to one schematic.
Definition: schematic.h:59
void ParseImplementation(const std::map< wxString, wxString > &aProperties)
void ParseParameter(const std::map< wxString, wxString > &aProperties)
SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
void ParseRoundRectangle(const std::map< wxString, wxString > &aProperties)
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
std::map< wxString, LIB_SYMBOL * > m_powerSymbols
void ParseBusEntry(const std::map< wxString, wxString > &aProperties)
void ParseSheet(const std::map< wxString, wxString > &aProperties)
void ParsePolygon(const std::map< wxString, wxString > &aProperties)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
A name/value tuple with unique names and optional values.
Definition: properties.h:33
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
std::map< int, SCH_SHEET * > m_sheets
void ParseRectangle(const std::map< wxString, wxString > &aProperties)
void ParsePolyline(const std::map< wxString, wxString > &aProperties)
void ParseImage(const std::map< wxString, wxString > &aProperties)
std::vector< ASCH_PORT > m_altiumPortsCurrentSheet
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:152
void ParseLine(const std::map< wxString, wxString > &aProperties)
std::map< int, SCH_SYMBOL * > m_symbols
wxFileName getLibFileName()
std::unique_ptr< ASCH_SHEET > m_altiumSheet
void ParseSheetEntry(const std::map< wxString, wxString > &aProperties)
int GetModifyHash() const override
Return the modification hash from the library cache.
std::map< int, LIB_SYMBOL * > m_libSymbols
void ParseFileName(const std::map< wxString, wxString > &aProperties)
SCH_ALTIUM_PLUGIN is a SCH_PLUGIN derivation for loading Altium .SchDoc schematic files.
void ParseNoERC(const std::map< wxString, wxString > &aProperties)
const ASCH_STORAGE_FILE * GetFileFromStorage(const wxString &aFilename) const
SCH_SHEET * m_currentSheet
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:479
const wxString GetLibraryFileExtension() const override
Return the library file extension for the SCH_PLUGIN object.
void ParseComponent(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseFileHeader(const CFB::CompoundFileReader &aReader)
void ParseSheetSymbol(int aIndex, const std::map< wxString, wxString > &aProperties)
Schematic symbol object.
Definition: sch_symbol.h:78
void ParseNote(const std::map< wxString, wxString > &aProperties)
void ParseWire(const std::map< wxString, wxString > &aProperties)
void ParseSheetName(const std::map< wxString, wxString > &aProperties)
const wxString GetFileExtension() const override
Return the file extension for the SCH_PLUGIN.
void ParseArc(const std::map< wxString, wxString > &aProperties)
void ParseTextFrame(const std::map< wxString, wxString > &aProperties)
void ParseBus(const std::map< wxString, wxString > &aProperties)
void ParseImplementationList(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseAltiumSch(const wxString &aFileName)
void ParseDesignator(const std::map< wxString, wxString > &aProperties)
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
void ParsePin(const std::map< wxString, wxString > &aProperties)
std::map< int, int > m_altiumImplementationList
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
void ParseStorage(const CFB::CompoundFileReader &aReader)
void ParseNetLabel(const std::map< wxString, wxString > &aProperties)
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const
std::unique_ptr< TITLE_BLOCK > m_currentTitleBlock