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
65template<typename ResultType>
66using LIBRARY_RESULT = tl::expected<ResultType, LIBRARY_ERROR>;
67
68
70{
71public:
72 friend class LIBRARY_TABLE;
73
74 static const wxString TABLE_TYPE_NAME;
75
76 LIBRARY_TABLE_ROW() = default;
77
78 bool operator==( const LIBRARY_TABLE_ROW& aOther ) const;
79
80 void SetNickname( const wxString& aNickname ) { m_nickname = aNickname; }
81 const wxString& Nickname() const { return m_nickname; }
82
83 void SetURI( const wxString& aUri ) { m_uri = aUri; }
84 const wxString& URI() const { return m_uri; }
85
86 void SetType( const wxString& aType ) { m_type = aType; }
87 const wxString& Type() const { return m_type; }
88
89 void SetOptions( const wxString& aOptions ) { m_options = aOptions; }
90 const wxString& Options() const { return m_options; }
91
92 void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
93 const wxString& Description() const { return m_description; }
94
95 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
96 LIBRARY_TABLE_SCOPE Scope() const { return m_scope; }
97
98 void SetDisabled( bool aDisabled = true ) { m_disabled = aDisabled; }
99 bool Disabled() const { return m_disabled; }
100
101 void SetHidden( bool aHidden = true ) { m_hidden = aHidden; }
102 bool Hidden() const { return m_hidden; }
103
104 std::map<std::string, UTF8> GetOptionsMap() const;
105
106 void SetOk( bool aOk = true ) { m_ok = aOk; }
107 bool IsOk() const { return m_ok; }
108
109 void SetErrorDescription( const wxString& aDescription ) { m_errorDescription = aDescription; }
110 const wxString& ErrorDescription() const { return m_errorDescription; }
111
112private:
113 wxString m_nickname;
114 wxString m_uri;
115 wxString m_type;
116 wxString m_options;
118 bool m_disabled = false;
119 bool m_hidden = false;
120
121 bool m_ok = false;
124};
125
126
127typedef std::vector<LIBRARY_TABLE_ROW>::iterator LIBRARY_TABLE_ROWS_ITER;
128typedef std::vector<LIBRARY_TABLE_ROW>::const_iterator LIBRARY_TABLE_ROWS_CITER;
129
130
132{
133public:
139 LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScope );
140
146 LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope );
147
148 ~LIBRARY_TABLE() = default;
149
150 bool operator==( const LIBRARY_TABLE& aOther ) const;
151
154
157
158 const wxString& Path() const { return m_path; }
159 void SetPath( const wxString &aPath ) { m_path = aPath; }
160
161 LIBRARY_TABLE_TYPE Type() const { return m_type; }
162 void SetType( const LIBRARY_TABLE_TYPE aType ) { m_type = aType; }
163
164 void SetScope( LIBRARY_TABLE_SCOPE aScope ) { m_scope = aScope; }
166
167 std::optional<int> Version() const{ return m_version; }
168 void SetVersion( const std::optional<int> &aVersion ) { m_version = aVersion; }
169
170 bool IsOk() const { return m_ok; }
171 const wxString& ErrorDescription() const { return m_errorDescription; }
172
173 const std::vector<LIBRARY_TABLE_ROW>& Rows() const { return m_rows; }
174 std::vector<LIBRARY_TABLE_ROW>& Rows() { return m_rows; }
175
176 void Format( OUTPUTFORMATTER* aOutput ) const;
177
178 bool HasRow( const wxString& aNickname ) const;
179
185 bool HasRowWithURI( const wxString& aUri, const PROJECT& aProject,
186 bool aSubstituted = false ) const;
187
188 std::optional<LIBRARY_TABLE_ROW*> Row( const wxString& aNickname );
189 std::optional<const LIBRARY_TABLE_ROW*> Row( const wxString& aNickname ) const;
190
192
193 static std::map<std::string, UTF8> ParseOptions( const std::string& aOptionsList );
194 static UTF8 FormatOptions( const std::map<std::string, UTF8>* aProperties );
195
196private:
197 bool initFromIR( const LIBRARY_TABLE_IR& aIR );
198 bool addRowFromIR( const LIBRARY_TABLE_ROW_IR& aIR );
199
201 wxString m_path;
202
204
207
209 std::optional<int> m_version;
210
211 bool m_ok = false;
213
214 std::vector<LIBRARY_TABLE_ROW> m_rows;
215};
216
217#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
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:72
#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.