KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rc_item.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) 2020-2022 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 RC_ITEM_H
25#define RC_ITEM_H
26
27#include <wx/dataview.h>
28#include <units_provider.h>
29#include <kiid.h>
30#include <reporter.h>
31#include <math/vector2d.h>
32
33class MARKER_BASE;
34class EDA_BASE_FRAME;
35class RC_ITEM;
36class EDA_ITEM;
37class EDA_DRAW_FRAME;
38
39namespace RC_JSON
40{
41struct VIOLATION;
42}
43
52{
53public:
54 virtual void SetSeverities( int aSeverities ) = 0;
55
56 virtual int GetCount( int aSeverity = -1 ) const = 0;
57
61 virtual std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const = 0;
62
67 virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
68
69 virtual ~RC_ITEMS_PROVIDER() { }
70};
71
72
79{
80public:
81 typedef std::vector<KIID> KIIDS;
82
84 m_errorCode( 0 ),
85 m_parent( nullptr )
86 {
87 }
88
89 RC_ITEM( const std::shared_ptr<RC_ITEM>& aItem )
90 {
91 m_errorCode = aItem->m_errorCode;
92 m_errorMessage = aItem->m_errorMessage;
93 m_errorTitle = aItem->m_errorTitle;
94 m_settingsKey = aItem->m_settingsKey;
95 m_parent = aItem->m_parent;
96 m_ids = aItem->m_ids;
97 }
98
99 virtual ~RC_ITEM() { }
100
101 void SetErrorMessage( const wxString& aMessage ) { m_errorMessage = aMessage; }
102
103 void SetItems( const KIIDS& aIds ) { m_ids = aIds; }
104
105 void AddItem( EDA_ITEM* aItem );
106
107 void SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem = nullptr,
108 const EDA_ITEM* cItem = nullptr, const EDA_ITEM* dItem = nullptr );
109
110 void SetItems( const KIID& aItem, const KIID& bItem = niluuid, const KIID& cItem = niluuid,
111 const KIID& dItem = niluuid )
112 {
113 m_ids.clear();
114
115 m_ids.push_back( aItem );
116 m_ids.push_back( bItem );
117 m_ids.push_back( cItem );
118 m_ids.push_back( dItem );
119 }
120
121 virtual KIID GetMainItemID() const { return m_ids.size() > 0 ? m_ids[0] : niluuid; }
122 virtual KIID GetAuxItemID() const { return m_ids.size() > 1 ? m_ids[1] : niluuid; }
123 virtual KIID GetAuxItem2ID() const { return m_ids.size() > 2 ? m_ids[2] : niluuid; }
124 virtual KIID GetAuxItem3ID() const { return m_ids.size() > 3 ? m_ids[3] : niluuid; }
125
126 std::vector<KIID> GetIDs() const { return m_ids; }
127
128 void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
129 MARKER_BASE* GetParent() const { return m_parent; }
130
131
137 virtual wxString ShowReport( UNITS_PROVIDER* aUnitsProvider, SEVERITY aSeverity,
138 const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
139
150 virtual void GetJsonViolation( RC_JSON::VIOLATION& aViolation, UNITS_PROVIDER* aUnitsProvider,
151 SEVERITY aSeverity, const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
152
153 int GetErrorCode() const { return m_errorCode; }
154 void SetErrorCode( int aCode ) { m_errorCode = aCode; }
155
160 virtual wxString GetErrorMessage() const;
161
166 wxString GetErrorText() const
167 {
168 return wxGetTranslation( m_errorTitle );
169 }
170
171 wxString GetSettingsKey() const
172 {
173 return m_settingsKey;
174 }
175
176 virtual wxString GetViolatingRuleDesc() const
177 {
178 return wxEmptyString;
179 }
180
181protected:
182 static wxString getSeverityString( SEVERITY aSeverity );
183
185 wxString m_errorMessage;
186 wxString m_errorTitle;
187 wxString m_settingsKey;
189
191
192};
193
194
196{
197public:
199
200 RC_TREE_NODE( RC_TREE_NODE* aParent, const std::shared_ptr<RC_ITEM>& aRcItem, NODE_TYPE aType ) :
201 m_Type( aType ),
202 m_RcItem( aRcItem ),
203 m_Parent( aParent )
204 {}
205
207 {
208 for( RC_TREE_NODE* child : m_Children )
209 delete child;
210 }
211
213 std::shared_ptr<RC_ITEM> m_RcItem;
214
216 std::vector<RC_TREE_NODE*> m_Children;
217};
218
219
220class RC_TREE_MODEL : public wxDataViewModel, public wxEvtHandler
221{
222public:
223 static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
224 {
225 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
226 }
227
228 static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
229 {
230 return static_cast<RC_TREE_NODE*>( aItem.GetID() );
231 }
232
233 static KIID ToUUID( wxDataViewItem aItem );
234
235 RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
236
238
239 void Update( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
240
241 void ExpandAll();
242
243 void PrevMarker();
244 void NextMarker();
245 void SelectMarker( const MARKER_BASE* aMarker );
246 void CenterMarker( const MARKER_BASE* aMarker );
247
248 bool IsContainer( wxDataViewItem const& aItem ) const override;
249
250 wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
251
252 unsigned int GetChildren( wxDataViewItem const& aItem,
253 wxDataViewItemArray& aChildren ) const override;
254
255 // Simple, single-text-column model
256 unsigned int GetColumnCount() const override { return 1; }
257 wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
258 bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
259
263 void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
264 unsigned int aCol ) const override;
265
269 bool SetValue( wxVariant const& aVariant, wxDataViewItem const& aItem,
270 unsigned int aCol ) override
271 {
272 // Editing not supported
273 return false;
274 }
275
280 bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
281 wxDataViewItemAttr& aAttr ) const override;
282
283 void ValueChanged( const RC_TREE_NODE* aNode );
284
285 void DeleteCurrentItem( bool aDeep );
286
291 void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
292
293protected:
294 void rebuildModel( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
295
297 wxDataViewCtrl* m_view;
299 std::shared_ptr<RC_ITEMS_PROVIDER> m_rcItemsProvider;
300
301 std::vector<RC_TREE_NODE*> m_tree; // I own this
302};
303
304#endif // RC_ITEM_H
The base frame for deriving all KiCad main window classes.
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
Definition: kiid.h:49
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:52
virtual void SetSeverities(int aSeverities)=0
virtual void DeleteItem(int aIndex, bool aDeep)=0
Remove (and optionally deletes) the indexed item from the list.
virtual ~RC_ITEMS_PROVIDER()
Definition: rc_item.h:69
virtual int GetCount(int aSeverity=-1) const =0
virtual std::shared_ptr< RC_ITEM > GetItem(int aIndex) const =0
Retrieve a RC_ITEM by index.
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:79
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition: rc_item.h:187
void SetItems(const KIID &aItem, const KIID &bItem=niluuid, const KIID &cItem=niluuid, const KIID &dItem=niluuid)
Definition: rc_item.h:110
int GetErrorCode() const
Definition: rc_item.h:153
int m_errorCode
The error code's numeric value.
Definition: rc_item.h:184
virtual ~RC_ITEM()
Definition: rc_item.h:99
virtual void GetJsonViolation(RC_JSON::VIOLATION &aViolation, UNITS_PROVIDER *aUnitsProvider, SEVERITY aSeverity, const std::map< KIID, EDA_ITEM * > &aItemMap) const
Translate this object into an RC_JSON::VIOLATION object.
Definition: rc_item.cpp:159
static wxString getSeverityString(SEVERITY aSeverity)
Definition: rc_item.cpp:81
MARKER_BASE * GetParent() const
Definition: rc_item.h:129
std::vector< KIID > KIIDS
Definition: rc_item.h:81
void AddItem(EDA_ITEM *aItem)
Definition: rc_item.cpp:56
MARKER_BASE * m_parent
The marker this item belongs to, if any.
Definition: rc_item.h:188
KIIDS m_ids
Definition: rc_item.h:190
virtual KIID GetAuxItem3ID() const
Definition: rc_item.h:124
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:101
virtual KIID GetAuxItem2ID() const
Definition: rc_item.h:123
virtual KIID GetMainItemID() const
Definition: rc_item.h:121
virtual KIID GetAuxItemID() const
Definition: rc_item.h:122
wxString GetErrorText() const
Definition: rc_item.h:166
virtual wxString ShowReport(UNITS_PROVIDER *aUnitsProvider, SEVERITY aSeverity, const std::map< KIID, EDA_ITEM * > &aItemMap) const
Translate this object into a text string suitable for saving to disk in a report.
Definition: rc_item.cpp:100
virtual wxString GetErrorMessage() const
Definition: rc_item.cpp:39
wxString m_errorMessage
A message describing the details of this specific error.
Definition: rc_item.h:185
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:128
RC_ITEM(const std::shared_ptr< RC_ITEM > &aItem)
Definition: rc_item.h:89
void SetErrorCode(int aCode)
Definition: rc_item.h:154
wxString GetSettingsKey() const
Definition: rc_item.h:171
std::vector< KIID > GetIDs() const
Definition: rc_item.h:126
wxString m_errorTitle
The string describing the type of error.
Definition: rc_item.h:186
RC_ITEM()
Definition: rc_item.h:83
virtual wxString GetViolatingRuleDesc() const
Definition: rc_item.h:176
void SetItems(const KIIDS &aIds)
Definition: rc_item.h:103
void ExpandAll()
Definition: rc_item.cpp:356
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:257
void PrevMarker()
Definition: rc_item.cpp:637
int m_severities
Definition: rc_item.h:298
void GetValue(wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
Called by the wxDataView to fetch an item's value.
Definition: rc_item.cpp:391
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:301
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:378
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:258
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:296
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:223
bool SetValue(wxVariant const &aVariant, wxDataViewItem const &aItem, unsigned int aCol) override
Called by the wxDataView to edit an item's content.
Definition: rc_item.h:269
void SelectMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:686
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:228
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:350
bool GetAttr(wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
Called by the wxDataView to fetch an item's formatting.
Definition: rc_item.cpp:457
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:520
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:514
unsigned int GetColumnCount() const override
Definition: rc_item.h:256
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:372
void CenterMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:699
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:213
wxDataViewCtrl * m_view
Definition: rc_item.h:297
std::shared_ptr< RC_ITEMS_PROVIDER > m_rcItemsProvider
Definition: rc_item.h:299
void NextMarker()
Definition: rc_item.cpp:658
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:497
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:363
void rebuildModel(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:258
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:213
RC_TREE_NODE * m_Parent
Definition: rc_item.h:215
RC_TREE_NODE(RC_TREE_NODE *aParent, const std::shared_ptr< RC_ITEM > &aRcItem, NODE_TYPE aType)
Definition: rc_item.h:200
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:216
~RC_TREE_NODE()
Definition: rc_item.h:206
NODE_TYPE m_Type
Definition: rc_item.h:212
KIID niluuid(0)
Contains the json serialization structs for DRC and ERC reports If you are trying to change the outpu...
Definition: rc_item.h:40
SEVERITY