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 <thomas.pointhuber@gmx.at>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef _SCH_ALTIUM_PLUGIN_H_
25 #define _SCH_ALTIUM_PLUGIN_H_
26 
27 #include <memory>
28 #include <sch_io_mgr.h>
29 #include <wx/filename.h>
30 #include <wx/gdicmn.h>
31 
32 #include "altium_parser_sch.h"
33 
34 
35 class SCH_COMPONENT;
36 class SCH_SHEET;
37 class TITLE_BLOCK;
38 
39 namespace CFB
40 {
41 class CompoundFileReader;
42 }
43 
51 {
52 public:
55 
56  const wxString GetName() const override;
57 
58  void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
59 
60  const wxString GetFileExtension() const override;
61 
62  const wxString GetLibraryFileExtension() const override;
63 
64  int GetModifyHash() const override;
65 
66  SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
67  SCH_SHEET* aAppendToMe = nullptr,
68  const PROPERTIES* aProperties = nullptr ) override;
69 
70  bool CheckHeader( const wxString& aFileName ) override;
71 
72  // unimplemented functions. Will trigger a not_implemented IO error.
73  //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
74 
75  //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
76  // const PROPERTIES* aProperties = NULL ) override;
77 
78  //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath,
79  // const PROPERTIES* aProperties = NULL ) override;
80 
81  //LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
82  // const PROPERTIES* aProperties = NULL ) override;
83 
84  //void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
85  // const PROPERTIES* aProperties = NULL ) override;
86 
87  //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
88  // const PROPERTIES* aProperties = NULL ) override;
89 
90  //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
91  // const PROPERTIES* aProperties = NULL ) override;
92 
93  //void CreateSymbolLib( const wxString& aLibraryPath,
94  // const PROPERTIES* aProperties = NULL ) override;
95 
96  // bool DeleteSymbolLib( const wxString& aLibraryPath,
97  // const PROPERTIES* aProperties = NULL ) override;
98 
99  //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
100 
101  //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
102 
103  wxString getLibName();
104  wxFileName getLibFileName();
105 
106  void ParseAltiumSch( const wxString& aFileName );
107  void ParseStorage( const CFB::CompoundFileReader& aReader );
108  void ParseFileHeader( const CFB::CompoundFileReader& aReader );
109 
110 private:
111  bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const;
112  const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
113 
114  void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
115  void ParsePin( const std::map<wxString, wxString>& aProperties );
116  void ParseLabel( const std::map<wxString, wxString>& aProperties );
117  void ParseBezier( const std::map<wxString, wxString>& aProperties );
118  void ParsePolyline( const std::map<wxString, wxString>& aProperties );
119  void ParsePolygon( const std::map<wxString, wxString>& aProperties );
120  void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties );
121  void ParseArc( const std::map<wxString, wxString>& aProperties );
122  void ParseLine( const std::map<wxString, wxString>& aProperties );
123  void ParseRectangle( const std::map<wxString, wxString>& aProperties );
124  void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
125  void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
126  void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
127  void ParsePort( const ASCH_PORT& aElem );
128  void ParseNoERC( const std::map<wxString, wxString>& aProperties );
129  void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
130  void ParseBus( const std::map<wxString, wxString>& aProperties );
131  void ParseWire( const std::map<wxString, wxString>& aProperties );
132  void ParseJunction( const std::map<wxString, wxString>& aProperties );
133  void ParseImage( const std::map<wxString, wxString>& aProperties );
134  void ParseSheet( const std::map<wxString, wxString>& aProperties );
135  void ParseSheetName( const std::map<wxString, wxString>& aProperties );
136  void ParseFileName( const std::map<wxString, wxString>& aProperties );
137  void ParseDesignator( const std::map<wxString, wxString>& aProperties );
138  void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
139  void ParseParameter( const std::map<wxString, wxString>& aProperties );
140 
141 private:
142  REPORTER* m_reporter; // current reporter for warnings/errors
143 
144  SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
145  SCH_SHEET* m_currentSheet; // The current sheet of the schematic being loaded..
146  SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
147  wxString m_libName; // Library name to save symbols
148 
149  SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; // Plugin to create KiCad symbol library.
150  std::unique_ptr<PROPERTIES> m_properties; // Library plugin properties.
151 
152  std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
153  // a sheet
154 
155  wxPoint m_sheetOffset;
156  std::unique_ptr<ASCH_SHEET> m_altiumSheet;
157  std::map<int, SCH_COMPONENT*> m_components;
158  std::map<int, SCH_SHEET*> m_sheets;
159  std::map<int, LIB_PART*> m_symbols; // every component has its unique symbol
160 
161  std::map<wxString, LIB_PART*> m_powerSymbols;
162  std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
163 
164  std::map<int, ASCH_COMPONENT> m_altiumComponents;
165  std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
166 };
167 
168 #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::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 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.
void ParseBusEntry(const std::map< wxString, wxString > &aProperties)
void ParseSheet(const std::map< wxString, wxString > &aProperties)
void ParsePolygon(const std::map< wxString, wxString > &aProperties)
std::map< int, ASCH_COMPONENT > m_altiumComponents
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
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< wxString, LIB_PART * > m_powerSymbols
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:151
void ParseLine(const std::map< wxString, wxString > &aProperties)
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.
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:473
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)
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.
std::map< int, LIB_PART * > m_symbols
Schematic symbol object.
Definition: sch_symbol.h:78
void ParseArc(const std::map< wxString, wxString > &aProperties)
void ParseBus(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, SCH_COMPONENT * > m_components
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