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 (C) 1992-2024 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/*
25 * @file design_block_info.h
26 */
27
28#ifndef DESIGN_BLOCK_INFO_H_
29#define DESIGN_BLOCK_INFO_H_
30
31
32#include <kicommon.h>
33#include <boost/ptr_container/ptr_vector.hpp>
34#include <import_export.h>
35#include <ki_exception.h>
36#include <core/sync_queue.h>
37#include <lib_tree_item.h>
38#include <atomic>
39#include <functional>
40#include <memory>
41
42
47class wxTopLevelWindow;
48class KIWAY;
49class wxTextFile;
50
51
52/*
53 * Helper class to handle the list of design blocks available in libraries. It stores
54 * design block names, doc and keywords.
55 *
56 * This is a virtual class; its implementation lives in common/design_block_info_impl.cpp.
57 * To get instances of these classes, see DESIGN_BLOCK_LIST::GetInstance().
58 */
60{
61public:
62 virtual ~DESIGN_BLOCK_INFO() {}
63
64 // These two accessors do not have to call ensure_loaded(), because constructor
65 // fills in these fields:
66
67 const wxString& GetDesignBlockName() const { return m_dbname; }
68
69 wxString GetLibNickname() const override { return m_nickname; }
70
71 wxString GetName() const override { return m_dbname; }
72
73 LIB_ID GetLIB_ID() const override { return LIB_ID( m_nickname, m_dbname ); }
74
75 wxString GetDesc() override
76 {
77 ensure_loaded();
78 return m_doc;
79 }
80
81 void SetDesc( const wxString& aDesc ) { m_doc = aDesc; }
82
83 wxString GetKeywords()
84 {
85 ensure_loaded();
86 return m_keywords;
87 }
88
89 std::vector<SEARCH_TERM> GetSearchTerms() override;
90
92 {
93 ensure_loaded();
94 return m_num;
95 }
96
105 bool InLibrary( const wxString& aLibrary ) const;
106
110 friend bool operator<( const DESIGN_BLOCK_INFO& lhs, const DESIGN_BLOCK_INFO& rhs );
111
112protected:
114 {
115 if( !m_loaded )
116 load();
117 }
118
120 virtual void load(){};
121
123
125
126 wxString m_nickname;
127 wxString m_dbname;
128 int m_num;
129 wxString m_doc;
130 wxString m_keywords;
131};
132
133
142{
143public:
144 typedef std::vector<std::unique_ptr<DESIGN_BLOCK_INFO>> DBILIST;
146
147 DESIGN_BLOCK_LIST() : m_lib_table( nullptr ) {}
148
150
154 unsigned GetCount() const { return m_list.size(); }
155
157 const DBILIST& GetList() const { return m_list; }
158
162 void Clear() { m_list.clear(); }
163
167 DESIGN_BLOCK_INFO* GetDesignBlockInfo( const wxString& aDesignBlockName );
168
172 DESIGN_BLOCK_INFO* GetDesignBlockInfo( const wxString& aLibNickname,
173 const wxString& aDesignBlockName );
174
181 DESIGN_BLOCK_INFO& GetItem( unsigned aIdx ) const { return *m_list[aIdx]; }
182
183 unsigned GetErrorCount() const { return m_errors.size(); }
184
185 std::unique_ptr<IO_ERROR> PopError()
186 {
187 std::unique_ptr<IO_ERROR> error;
188
189 m_errors.pop( error );
190 return error;
191 }
192
206 const wxString* aNickname = nullptr,
207 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
208
209 DESIGN_BLOCK_LIB_TABLE* GetTable() const { return m_lib_table; }
210
211protected:
212 DESIGN_BLOCK_LIB_TABLE* m_lib_table = nullptr;
213
216};
217
218#endif // DESIGN_BLOCK_INFO_H_
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()
std::vector< std::unique_ptr< DESIGN_BLOCK_INFO > > DBILIST
const DBILIST & GetList() const
Was forced to add this by modview_frame.cpp.
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.
DESIGN_BLOCK_INFO & GetItem(unsigned aIdx) const
Get info for a design block by index.
virtual ~DESIGN_BLOCK_LIST()
ERRLIST m_errors
some can be PARSE_ERRORs also
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
unsigned GetErrorCount() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
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