KiCad PCB EDA Suite
Loading...
Searching...
No Matches
design_block_info.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 *
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 DESIGN_BLOCK_INFO_H_
25#define DESIGN_BLOCK_INFO_H_
26
27
28#include <kicommon.h>
29#include <boost/ptr_container/ptr_vector.hpp>
30#include <import_export.h>
31#include <ki_exception.h>
32#include <core/sync_queue.h>
33#include <lib_tree_item.h>
34#include <atomic>
35#include <functional>
36#include <memory>
37
38
43class wxTopLevelWindow;
44class KIWAY;
45class wxTextFile;
46
47
56{
57public:
58 virtual ~DESIGN_BLOCK_INFO() {}
59
60 // These two accessors do not have to call ensure_loaded(), because constructor
61 // fills in these fields:
62
63 const wxString& GetDesignBlockName() const { return m_dbname; }
64
65 wxString GetLibNickname() const override { return m_nickname; }
66
67 wxString GetName() const override { return m_dbname; }
68
69 LIB_ID GetLIB_ID() const override { return LIB_ID( m_nickname, m_dbname ); }
70
71 wxString GetDesc() override
72 {
73 ensure_loaded();
74 return m_doc;
75 }
76
77 void SetDesc( const wxString& aDesc ) { m_doc = aDesc; }
78
79 wxString GetKeywords()
80 {
81 ensure_loaded();
82 return m_keywords;
83 }
84
85 std::vector<SEARCH_TERM> GetSearchTerms() override;
86
88 {
89 ensure_loaded();
90 return m_num;
91 }
92
101 bool InLibrary( const wxString& aLibrary ) const;
102
106 friend bool operator<( const DESIGN_BLOCK_INFO& lhs, const DESIGN_BLOCK_INFO& rhs );
107
108protected:
110 {
111 if( !m_loaded )
112 load();
113 }
114
116 virtual void load(){};
117
118protected:
120
122
123 wxString m_nickname;
124 wxString m_dbname;
125 int m_num;
126 wxString m_doc;
127 wxString m_keywords;
128};
129
130
139{
140public:
141 DESIGN_BLOCK_LIST() : m_lib_table( nullptr ) {}
142
144
148 unsigned GetCount() const { return m_list.size(); }
149
151 const std::vector<std::unique_ptr<DESIGN_BLOCK_INFO>>& GetList() const { return m_list; }
152
156 void Clear() { m_list.clear(); }
157
161 DESIGN_BLOCK_INFO* GetDesignBlockInfo( const wxString& aDesignBlockName );
162
166 DESIGN_BLOCK_INFO* GetDesignBlockInfo( const wxString& aLibNickname,
167 const wxString& aDesignBlockName );
168
175 DESIGN_BLOCK_INFO& GetItem( unsigned aIdx ) const { return *m_list[aIdx]; }
176
177 unsigned GetErrorCount() const { return m_errors.size(); }
178
179 std::unique_ptr<IO_ERROR> PopError()
180 {
181 std::unique_ptr<IO_ERROR> error;
182
183 m_errors.pop( error );
184 return error;
185 }
186
200 const wxString* aNickname = nullptr,
201 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
202
203 DESIGN_BLOCK_LIB_TABLE* GetTable() const { return m_lib_table; }
204
205protected:
206 DESIGN_BLOCK_LIB_TABLE* m_lib_table = nullptr;
207
208 std::vector<std::unique_ptr<DESIGN_BLOCK_INFO>> m_list;
210};
211
212#endif // DESIGN_BLOCK_INFO_H_
Helper class to handle the list of design blocks available in libraries.
DESIGN_BLOCK_LIST * m_owner
provides access to DESIGN_BLOCK_LIB_TABLE
wxString m_nickname
library as known in DESIGN_BLOCK_LIB_TABLE
void SetDesc(const wxString &aDesc)
virtual void load()
lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
wxString m_dbname
Module name.
wxString GetDesc() override
wxString m_keywords
Design block keywords.
virtual ~DESIGN_BLOCK_INFO()
LIB_ID GetLIB_ID() const override
wxString GetLibNickname() const override
const wxString & GetDesignBlockName() const
int m_num
Order number in the display list.
wxString GetName() const override
wxString m_doc
Design block description.
Holds a list of DESIGN_BLOCK_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were t...
std::unique_ptr< IO_ERROR > PopError()
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > m_errors
some can be PARSE_ERRORs also
std::vector< std::unique_ptr< DESIGN_BLOCK_INFO > > m_list
DESIGN_BLOCK_LIB_TABLE * GetTable() const
unsigned GetCount() const
virtual bool ReadDesignBlockFiles(DESIGN_BLOCK_LIB_TABLE *aTable, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)=0
Read all the design blocks provided by the combination of aTable and aNickname.
const std::vector< std::unique_ptr< DESIGN_BLOCK_INFO > > & GetList() const
Was forced to add this by modview_frame.cpp.
DESIGN_BLOCK_INFO & GetItem(unsigned aIdx) const
Get info for a design block by index.
virtual ~DESIGN_BLOCK_LIST()
unsigned GetErrorCount() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:41
virtual std::vector< SEARCH_TERM > GetSearchTerms()
Definition: lib_tree_item.h:59
A progress reporter interface for use in multi-threaded environments.
Synchronized, locking queue.
Definition: sync_queue.h:32
bool operator<(const DESIGN_BLOCK_INFO &lhs, const DESIGN_BLOCK_INFO &rhs)
#define KICOMMON_API
Definition: kicommon.h:28