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 {
205 COMMENT
206 };
207
208 RC_TREE_NODE( RC_TREE_NODE* aParent, const std::shared_ptr<RC_ITEM>& aRcItem, NODE_TYPE aType ) :
209 m_Type( aType ),
210 m_RcItem( aRcItem ),
211 m_Parent( aParent )
212 {}
213
215 {
216 for( RC_TREE_NODE* child : m_Children )
217 delete child;
218 }
219
221 std::shared_ptr<RC_ITEM> m_RcItem;
222
224 std::vector<RC_TREE_NODE*> m_Children;
225};
226
227
228class RC_TREE_MODEL : public wxDataViewModel, public wxEvtHandler
229{
230public:
231 static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
232 {
233 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
234 }
235
236 static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
237 {
238 return static_cast<RC_TREE_NODE*>( aItem.GetID() );
239 }
240
241 static KIID ToUUID( wxDataViewItem aItem );
242
243 RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
244
246
247 void Update( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
248
249 void ExpandAll();
250
251 void PrevMarker();
252 void NextMarker();
253 void SelectMarker( const MARKER_BASE* aMarker );
254 void CenterMarker( const MARKER_BASE* aMarker );
255
256 bool IsContainer( wxDataViewItem const& aItem ) const override;
257
258 wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
259
260 unsigned int GetChildren( wxDataViewItem const& aItem,
261 wxDataViewItemArray& aChildren ) const override;
262
263 // Simple, single-text-column model
264 unsigned int GetColumnCount() const override { return 1; }
265 wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
266 bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
267
271 void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
272 unsigned int aCol ) const override;
273
277 bool SetValue( wxVariant const& aVariant, wxDataViewItem const& aItem,
278 unsigned int aCol ) override
279 {
280 // Editing not supported
281 return false;
282 }
283
288 bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
289 wxDataViewItemAttr& aAttr ) const override;
290
291 void ValueChanged( RC_TREE_NODE* aNode );
292
293 void DeleteCurrentItem( bool aDeep );
294
299 void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
300
301protected:
302 void rebuildModel( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
303
305 wxDataViewCtrl* m_view;
307 std::shared_ptr<RC_ITEMS_PROVIDER> m_rcItemsProvider;
308
309 std::vector<RC_TREE_NODE*> m_tree; // I own this
310};
311
312#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:89
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:166
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:370
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:265
void PrevMarker()
Definition: rc_item.cpp:689
int m_severities
Definition: rc_item.h:306
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:405
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:309
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:392
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:266
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:304
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:231
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:277
void SelectMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:738
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:236
void ValueChanged(RC_TREE_NODE *aNode)
Definition: rc_item.cpp:517
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:364
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:477
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:572
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:566
unsigned int GetColumnCount() const override
Definition: rc_item.h:264
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:386
void CenterMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:751
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:220
wxDataViewCtrl * m_view
Definition: rc_item.h:305
std::shared_ptr< RC_ITEMS_PROVIDER > m_rcItemsProvider
Definition: rc_item.h:307
void NextMarker()
Definition: rc_item.cpp:710
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:377
void rebuildModel(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:266
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:221
RC_TREE_NODE * m_Parent
Definition: rc_item.h:223
RC_TREE_NODE(RC_TREE_NODE *aParent, const std::shared_ptr< RC_ITEM > &aRcItem, NODE_TYPE aType)
Definition: rc_item.h:208
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:224
~RC_TREE_NODE()
Definition: rc_item.h:214
NODE_TYPE m_Type
Definition: rc_item.h:220
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