KiCad PCB EDA Suite
Loading...
Searching...
No Matches
library_table.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIBRARY_TABLE_H
22#define LIBRARY_TABLE_H
23
24#include <map>
25#include <optional>
26#include <wx/filename.h>
27
28#include <kicommon.h>
29#include <core/utf8.h>
30
31
39
47
48struct LIBRARY_TABLE_IR;
50struct LIBRARY_TABLE_INTERNALS;
51class OUTPUTFORMATTER;
52class PROJECT;
53
54
56{
57public:
58 friend class LIBRARY_TABLE;
59
60 static const wxString TABLE_TYPE_NAME;
61
62 LIBRARY_TABLE_ROW() = default;
63
64 bool operator==( const LIBRARY_TABLE_ROW& aOther ) const;
65
66 void SetNickname( const wxString& aNickname ) { m_nickname = aNickname; }
67 const wxString& Nickname() const { return m_nickname; }
68
69 void SetURI( const wxString& aUri ) { m_uri = aUri; }
70 const wxString& URI() const { return m_uri; }
71
72 void SetType( const wxString& aType ) { m_type = aType; }
73 const wxString& Type() const { return m_type; }
74
75 void SetOptions( const wxString& aOptions ) { m_options = aOptions; }
76 const wxString& Options() const { return m_options; }
77
78 void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
79 const wxString& Description() const { return m_description; }
80
81 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
82 LIBRARY_TABLE_SCOPE Scope() const { return m_scope; }
83
84 void SetDisabled( bool aDisabled = true ) { m_disabled = aDisabled; }
85 bool Disabled() const { return m_disabled; }
86
87 void SetHidden( bool aHidden = true ) { m_hidden = aHidden; }
88 bool Hidden() const { return m_hidden; }
89
90 std::map<std::string, UTF8> GetOptionsMap() const;
91
92 void SetOk( bool aOk = true ) { m_ok = aOk; }
93 bool IsOk() const { return m_ok; }
94
95 void SetErrorDescription( const wxString& aDescription ) { m_errorDescription = aDescription; }
96 const wxString& ErrorDescription() const { return m_errorDescription; }
97
98private:
99 wxString m_nickname;
100 wxString m_uri;
101 wxString m_type;
102 wxString m_options;
104 bool m_disabled = false;
105 bool m_hidden = false;
106
107 bool m_ok = false;
110};
111
112
113typedef std::vector<LIBRARY_TABLE_ROW>::iterator LIBRARY_TABLE_ROWS_ITER;
114typedef std::vector<LIBRARY_TABLE_ROW>::const_iterator LIBRARY_TABLE_ROWS_CITER;
115
116
118{
119public:
125 LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScope );
126
132 LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope );
133
134 ~LIBRARY_TABLE() = default;
135
136 bool operator==( const LIBRARY_TABLE& aOther ) const;
137
140
143
144 const wxString& Path() const { return m_path; }
145 void SetPath( const wxString &aPath ) { m_path = aPath; }
146
147 LIBRARY_TABLE_TYPE Type() const { return m_type; }
148 void SetType( const LIBRARY_TABLE_TYPE aType ) { m_type = aType; }
149
150 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
152
153 std::optional<int> Version() const{ return m_version; }
154 void SetVersion( const std::optional<int> &aVersion ) { m_version = aVersion; }
155
156 bool IsOk() const { return m_ok; }
157 const wxString& ErrorDescription() const { return m_errorDescription; }
158
159 const std::vector<LIBRARY_TABLE_ROW>& Rows() const { return m_rows; }
160 std::vector<LIBRARY_TABLE_ROW>& Rows() { return m_rows; }
161
162 void Format( OUTPUTFORMATTER* aOutput ) const;
163
164 bool HasRow( const wxString& aNickname ) const;
165
171 bool HasRowWithURI( const wxString& aUri, const PROJECT& aProject,
172 bool aSubstituted = false ) const;
173
174 std::optional<LIBRARY_TABLE_ROW*> Row( const wxString& aNickname );
175 std::optional<const LIBRARY_TABLE_ROW*> Row( const wxString& aNickname ) const;
176
177private:
178 bool initFromIR( const LIBRARY_TABLE_IR& aIR );
179 bool addRowFromIR( const LIBRARY_TABLE_ROW_IR& aIR );
180
182 wxString m_path;
183
185
188
190 std::optional<int> m_version;
191
192 bool m_ok = false;
194
195 std::vector<LIBRARY_TABLE_ROW> m_rows;
196};
197
198#endif //LIBRARY_TABLE_H
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
void SetOptions(const wxString &aOptions)
LIBRARY_TABLE_ROW()=default
LIBRARY_TABLE_SCOPE Scope() const
void SetNickname(const wxString &aNickname)
void SetOk(bool aOk=true)
void SetType(const wxString &aType)
bool Disabled() const
void SetErrorDescription(const wxString &aDescription)
const wxString & ErrorDescription() const
wxString m_errorDescription
void SetDescription(const wxString &aDescription)
const wxString & Type() const
static const wxString TABLE_TYPE_NAME
void SetURI(const wxString &aUri)
const wxString & Description() const
void SetDisabled(bool aDisabled=true)
bool Hidden() const
void SetScope(LIBRARY_TABLE_SCOPE aScope)
LIBRARY_TABLE_SCOPE m_scope
void SetHidden(bool aHidden=true)
bool IsOk() const
const wxString & URI() const
const wxString & Nickname() const
const wxString & Options() const
friend class LIBRARY_TABLE
void SetScope(LIBRARY_TABLE_SCOPE aScope)
LIBRARY_TABLE_TYPE Type() const
LIBRARY_TABLE_TYPE m_type
What type of content this table contains (footprint, symbol, design block, etc)
void SetType(const LIBRARY_TABLE_TYPE aType)
void SetPath(const wxString &aPath)
std::vector< LIBRARY_TABLE_ROW > m_rows
LIBRARY_TABLE_ROW & InsertRow()
Builds a new row and inserts it at the end of the table; returning a reference to the row.
~LIBRARY_TABLE()=default
const wxString & Path() const
wxString m_path
The full path to the file this table was parsed from, if any.
wxString m_errorDescription
LIBRARY_TABLE_SCOPE Scope() const
LIBRARY_TABLE_ROW MakeRow() const
Builds a new row that is suitable for this table (does not insert it)
std::optional< int > Version() const
LIBRARY_TABLE(const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScope)
Creates a library table from a file on disk.
const wxString & ErrorDescription() const
std::vector< LIBRARY_TABLE_ROW > & Rows()
std::optional< int > m_version
The format version, if present in the parsed file.
bool IsOk() const
const std::vector< LIBRARY_TABLE_ROW > & Rows() const
LIBRARY_TABLE_SCOPE m_scope
void SetVersion(const std::optional< int > &aVersion)
An interface used to output 8 bit text in a convenient way.
Definition richio.h:323
Container for project specific data.
Definition project.h:65
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:63
#define KICOMMON_API
Definition kicommon.h:28
LIBRARY_TABLE_TYPE
std::vector< LIBRARY_TABLE_ROW >::iterator LIBRARY_TABLE_ROWS_ITER
LIBRARY_TABLE_SCOPE
std::vector< LIBRARY_TABLE_ROW >::const_iterator LIBRARY_TABLE_ROWS_CITER
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:198
The intermediate representation that a library table is parsed into.