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 <tl/expected.hpp>
27#include <wx/filename.h>
28
29#include <kicommon.h>
30#include <core/utf8.h>
31
32
40
48
49struct LIBRARY_TABLE_IR;
51struct LIBRARY_TABLE_INTERNALS;
52class OUTPUTFORMATTER;
53class PROJECT;
54
55
57{
58 LIBRARY_ERROR( const wxString& aMessage ) :
59 message( aMessage )
60 {};
61
62 wxString message;
63};
64
65
67{
69 LIBRARY_ERROR( wxT( "Table_OK" ) )
70 {}
71};
72
73
74template<typename ResultType>
75using LIBRARY_RESULT = tl::expected<ResultType, LIBRARY_ERROR>;
76
77
79{
80public:
81 friend class LIBRARY_TABLE;
82
83 static const wxString TABLE_TYPE_NAME;
84
85 LIBRARY_TABLE_ROW() = default;
86
87 bool operator==( const LIBRARY_TABLE_ROW& aOther ) const;
88
89 void SetNickname( const wxString& aNickname ) { m_nickname = aNickname; }
90 const wxString& Nickname() const { return m_nickname; }
91
92 void SetURI( const wxString& aUri ) { m_uri = aUri; }
93 const wxString& URI() const { return m_uri; }
94
95 void SetType( const wxString& aType ) { m_type = aType; }
96 const wxString& Type() const { return m_type; }
97
98 void SetOptions( const wxString& aOptions ) { m_options = aOptions; }
99 const wxString& Options() const { return m_options; }
100
101 void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
102 const wxString& Description() const { return m_description; }
103
104 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
106
107 void SetDisabled( bool aDisabled = true ) { m_disabled = aDisabled; }
108 bool Disabled() const { return m_disabled; }
109
110 void SetHidden( bool aHidden = true ) { m_hidden = aHidden; }
111 bool Hidden() const { return m_hidden; }
112
113 std::map<std::string, UTF8> GetOptionsMap() const;
114
115 void SetOk( bool aOk = true ) { m_ok = aOk; }
116 bool IsOk() const { return m_ok; }
117
118 void SetErrorDescription( const wxString& aDescription ) { m_errorDescription = aDescription; }
119 const wxString& ErrorDescription() const { return m_errorDescription; }
120
121private:
122 wxString m_nickname;
123 wxString m_uri;
124 wxString m_type;
125 wxString m_options;
127 bool m_disabled = false;
128 bool m_hidden = false;
129
130 bool m_ok = false;
133};
134
135
136typedef std::vector<LIBRARY_TABLE_ROW>::iterator LIBRARY_TABLE_ROWS_ITER;
137typedef std::vector<LIBRARY_TABLE_ROW>::const_iterator LIBRARY_TABLE_ROWS_CITER;
138
139
141{
142public:
148 LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScope );
149
157 LIBRARY_TABLE( bool aFromClipboard, const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope );
158
159 ~LIBRARY_TABLE() = default;
160
161 bool operator==( const LIBRARY_TABLE& aOther ) const;
162
165
168
169 const wxString& Path() const { return m_path; }
170 void SetPath( const wxString &aPath ) { m_path = aPath; }
171
172 LIBRARY_TABLE_TYPE Type() const { return m_type; }
173 void SetType( const LIBRARY_TABLE_TYPE aType ) { m_type = aType; }
174
175 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
177
178 std::optional<int> Version() const{ return m_version; }
179 void SetVersion( const std::optional<int> &aVersion ) { m_version = aVersion; }
180
181 bool IsOk() const { return m_ok; }
182 const wxString& ErrorDescription() const { return m_errorDescription; }
183
184 const std::vector<LIBRARY_TABLE_ROW>& Rows() const { return m_rows; }
185 std::vector<LIBRARY_TABLE_ROW>& Rows() { return m_rows; }
186
187 void Format( OUTPUTFORMATTER* aOutput ) const;
188
189 bool HasRow( const wxString& aNickname ) const;
190
196 bool HasRowWithURI( const wxString& aUri, const PROJECT& aProject,
197 bool aSubstituted = false ) const;
198
199 std::optional<LIBRARY_TABLE_ROW*> Row( const wxString& aNickname );
200 std::optional<const LIBRARY_TABLE_ROW*> Row( const wxString& aNickname ) const;
201
203
204 static std::map<std::string, UTF8> ParseOptions( const std::string& aOptionsList );
205 static UTF8 FormatOptions( const std::map<std::string, UTF8>* aProperties );
206
207private:
208 bool initFromIR( const LIBRARY_TABLE_IR& aIR );
209 bool addRowFromIR( const LIBRARY_TABLE_ROW_IR& aIR );
210
212 wxString m_path;
213
215
218
220 std::optional<int> m_version;
221
222 bool m_ok = false;
224
225 std::vector<LIBRARY_TABLE_ROW> m_rows;
226};
227
228#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:295
Container for project specific data.
Definition project.h:65
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:63
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:71
#define KICOMMON_API
Definition kicommon.h:28
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
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
wxString message
LIBRARY_ERROR(const wxString &aMessage)
The intermediate representation that a library table is parsed into.