KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_geda.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) 2012-2020 Wayne Stambaugh <[email protected]>
5 * Copyright The 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, see <https://www.gnu.org/licenses/>.
19 *
20 * This file contains file format knowledge derived from the gEDA/pcb project:
21 *
22 * gEDA/gaf - Copyright (C) 1998-2010 Ales Hvezda
23 * Copyright (C) 1998-2016 gEDA Contributors
24 * Lepton EDA - Copyright (C) 2017-2024 Lepton EDA Contributors
25 *
26 * Both projects are licensed under the GNU General Public License v2 or later.
27 * See https://github.com/lepton-eda/lepton-eda and
28 * https://github.com/rlutz/geda-gaf
29 */
30
35
36#ifndef PCB_IO_GEDA_H_
37#define PCB_IO_GEDA_H_
38
39#include <map>
40#include <string>
41#include <vector>
42
43#include <layer_ids.h>
44#include <pcb_io/pcb_io.h>
45#include <pcb_io/pcb_io_mgr.h>
46
47class BOARD;
48class FOOTPRINT;
49class GPCB_FPL_CACHE;
50class LINE_READER;
51class NETINFO_ITEM;
52
58class PCB_IO_GEDA : public PCB_IO
59{
60public:
61 // Board-level file support
63 {
64 return IO_BASE::IO_FILE_DESC( _HKI( "gEDA / Lepton EDA PCB board file" ), { "pcb" } );
65 }
66
67 bool CanReadBoard( const wxString& aFileName ) const override;
68
69 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
70
71 // Footprint library support
73 {
74 return IO_BASE::IO_FILE_DESC( _HKI( "gEDA / Lepton EDA PCB footprint file" ), { "fp" } );
75 }
76
78 {
79 return IO_BASE::IO_FILE_DESC( _HKI( "gEDA / Lepton EDA PCB footprint library directory" ), {}, { "fp" },
80 false );
81 }
82
83 std::unique_ptr<FOOTPRINT> ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
84 const std::map<std::string, UTF8>* aProperties ) override;
85
86 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
87 bool aBestEfforts,
88 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
89
90 std::unique_ptr<FOOTPRINT> FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
91 bool aKeepUUID = false,
92 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
93
94 void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
95 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
96
97 bool DeleteLibrary( const wxString& aLibraryPath,
98 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
99
100 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
101
102 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
103
104 //-----</PLUGIN API>--------------------------------------------------------
105
106 PCB_IO_GEDA();
107
108 PCB_IO_GEDA( int aControlFlags );
109
110 ~PCB_IO_GEDA() override;
111
112private:
113 void validateCache( const wxString& aLibraryPath, bool checkModified = true );
114
115 const FOOTPRINT* getFootprint( const wxString& aLibraryPath, const wxString& aFootprintName,
116 const std::map<std::string, UTF8>* aProperties, bool checkModified );
117
118 void init( const std::map<std::string, UTF8>* aProperties );
119
120 friend class GPCB_FPL_CACHE;
121
122 // Board parsing helpers
123 PCB_LAYER_ID mapLayer( int aGedaLayer, const wxString& aLayerName ) const;
124
125 void parseVia( wxArrayString& aParameters, double aConvUnit );
126 FOOTPRINT* parseElement( wxArrayString& aParameters, LINE_READER* aLineReader,
127 double aConvUnit );
128 void parseLayer( wxArrayString& aParameters, LINE_READER* aLineReader, double aConvUnit );
129 void parseNetList( LINE_READER* aLineReader );
130 void parseParameters( wxArrayString& aParameterList, LINE_READER* aLineReader );
131 bool testFlags( const wxString& aFlag, long aMask, const wxChar* aName );
132
133protected:
134 void loadBoard( const wxString& aFileName, BOARD& aBoard, bool aIsNewLoad,
135 const std::map<std::string, UTF8>* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
136
137 wxString m_error;
139 int m_ctl;
141 wxString m_filename;
142
143 // Board import state
144 std::vector<FOOTPRINT*> m_cachedFootprints;
145 std::map<wxString, NETINFO_ITEM*> m_netMap;
147};
148
149#endif // PCB_IO_GEDA_H_
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:65
Handle the data for a net.
Definition netinfo.h:50
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete aFootprintName from the library at aLibraryPath.
void parseVia(wxArrayString &aParameters, double aConvUnit)
const IO_BASE::IO_FILE_DESC GetLibraryFileDesc() const override
Get the descriptor for the individual library elements that this IO plugin operates on.
Definition pcb_io_geda.h:72
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
void parseNetList(LINE_READER *aLineReader)
std::unique_ptr< FOOTPRINT > FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
Definition pcb_io_geda.h:77
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
Definition pcb_io_geda.h:62
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
std::map< wxString, NETINFO_ITEM * > m_netMap
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
~PCB_IO_GEDA() override
int m_numCopperLayers
wxString m_filename
for saves only, name is in m_reader for loads
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void init(const std::map< std::string, UTF8 > *aProperties)
std::unique_ptr< FOOTPRINT > ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
GPCB_FPL_CACHE * m_cache
Footprint library cache.
bool testFlags(const wxString &aFlag, long aMask, const wxChar *aName)
FOOTPRINT * parseElement(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void parseParameters(wxArrayString &aParameterList, LINE_READER *aLineReader)
void parseLayer(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
std::vector< FOOTPRINT * > m_cachedFootprints
LINE_READER * m_reader
no ownership here.
friend class GPCB_FPL_CACHE
PCB_LAYER_ID mapLayer(int aGedaLayer, const wxString &aLayerName) const
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties, bool checkModified)
wxString m_error
for throwing exceptions
PCB_IO(const wxString &aName)
Definition pcb_io.h:351
Container for project specific data.
Definition project.h:63
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
#define _HKI(x)
Definition page_info.cpp:40
Container that describes file type info.
Definition io_base.h:43