KiCad PCB EDA Suite
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
39
48{
49public:
50 virtual void SetSeverities( int aSeverities ) = 0;
51
52 virtual int GetCount( int aSeverity = -1 ) const = 0;
53
57 virtual std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const = 0;
58
63 virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
64
65 virtual ~RC_ITEMS_PROVIDER() { }
66};
67
68
75{
76public:
77 typedef std::vector<KIID> KIIDS;
78
80 m_errorCode( 0 ),
81 m_parent( nullptr )
82 {
83 }
84
85 RC_ITEM( std::shared_ptr<RC_ITEM> aItem )
86 {
87 m_errorCode = aItem->m_errorCode;
88 m_errorMessage = aItem->m_errorMessage;
89 m_errorTitle = aItem->m_errorTitle;
90 m_settingsKey = aItem->m_settingsKey;
91 m_parent = aItem->m_parent;
92 m_ids = aItem->m_ids;
93 }
94
95 virtual ~RC_ITEM() { }
96
97 void SetErrorMessage( const wxString& aMessage ) { m_errorMessage = aMessage; }
98
99 void SetItems( const KIIDS& aIds ) { m_ids = aIds; }
100
101 void AddItem( EDA_ITEM* aItem );
102
103 void SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem = nullptr,
104 const EDA_ITEM* cItem = nullptr, const EDA_ITEM* dItem = nullptr );
105
106 void SetItems( const KIID& aItem, const KIID& bItem = niluuid, const KIID& cItem = niluuid,
107 const KIID& dItem = niluuid )
108 {
109 m_ids.clear();
110
111 m_ids.push_back( aItem );
112 m_ids.push_back( bItem );
113 m_ids.push_back( cItem );
114 m_ids.push_back( dItem );
115 }
116
117 virtual KIID GetMainItemID() const { return m_ids.size() > 0 ? m_ids[0] : niluuid; }
118 virtual KIID GetAuxItemID() const { return m_ids.size() > 1 ? m_ids[1] : niluuid; }
119 virtual KIID GetAuxItem2ID() const { return m_ids.size() > 2 ? m_ids[2] : niluuid; }
120 virtual KIID GetAuxItem3ID() const { return m_ids.size() > 3 ? m_ids[3] : niluuid; }
121
122 std::vector<KIID> GetIDs() const { return m_ids; }
123
124 void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
125 MARKER_BASE* GetParent() const { return m_parent; }
126
127
133 virtual wxString ShowReport( UNITS_PROVIDER* aUnitsProvider, SEVERITY aSeverity,
134 const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
135
136 int GetErrorCode() const { return m_errorCode; }
137 void SetErrorCode( int aCode ) { m_errorCode = aCode; }
138
143 virtual wxString GetErrorMessage() const;
144
149 wxString GetErrorText() const
150 {
151 return wxGetTranslation( m_errorTitle );
152 }
153
154 wxString GetSettingsKey() const
155 {
156 return m_settingsKey;
157 }
158
159 virtual wxString GetViolatingRuleDesc() const
160 {
161 return wxEmptyString;
162 }
163
164protected:
166 wxString m_errorMessage;
167 wxString m_errorTitle;
168 wxString m_settingsKey;
170
172
173};
174
175
177{
178public:
180
181 RC_TREE_NODE( RC_TREE_NODE* aParent, std::shared_ptr<RC_ITEM> aRcItem, NODE_TYPE aType ) :
182 m_Type( aType ),
183 m_RcItem( aRcItem ),
184 m_Parent( aParent )
185 {}
186
188 {
189 for( RC_TREE_NODE* child : m_Children )
190 delete child;
191 }
192
194 std::shared_ptr<RC_ITEM> m_RcItem;
195
197 std::vector<RC_TREE_NODE*> m_Children;
198};
199
200
201class RC_TREE_MODEL : public wxDataViewModel, public wxEvtHandler
202{
203public:
204 static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
205 {
206 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
207 }
208
209 static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
210 {
211 return static_cast<RC_TREE_NODE*>( aItem.GetID() );
212 }
213
214 static KIID ToUUID( wxDataViewItem aItem );
215
216 RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
217
219
220 void Update( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
221
222 void ExpandAll();
223
224 void PrevMarker();
225 void NextMarker();
226 void SelectMarker( const MARKER_BASE* aMarker );
227 void CenterMarker( const MARKER_BASE* aMarker );
228
229 bool IsContainer( wxDataViewItem const& aItem ) const override;
230
231 wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
232
233 unsigned int GetChildren( wxDataViewItem const& aItem,
234 wxDataViewItemArray& aChildren ) const override;
235
236 // Simple, single-text-column model
237 unsigned int GetColumnCount() const override { return 1; }
238 wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
239 bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
240
244 void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
245 unsigned int aCol ) const override;
246
250 bool SetValue( wxVariant const& aVariant, wxDataViewItem const& aItem,
251 unsigned int aCol ) override
252 {
253 // Editing not supported
254 return false;
255 }
256
261 bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
262 wxDataViewItemAttr& aAttr ) const override;
263
264 void ValueChanged( const RC_TREE_NODE* aNode );
265
266 void DeleteCurrentItem( bool aDeep );
267
272 void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
273
274private:
275 void rebuildModel( std::shared_ptr<RC_ITEMS_PROVIDER> aProvider, int aSeverities );
276 void onSizeView( wxSizeEvent& aEvent );
277
279 wxDataViewCtrl* m_view;
281 std::shared_ptr<RC_ITEMS_PROVIDER> m_rcItemsProvider;
282
283 std::vector<RC_TREE_NODE*> m_tree; // I own this
284};
285
286#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:48
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:48
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:65
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:75
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition: rc_item.h:168
void SetItems(const KIID &aItem, const KIID &bItem=niluuid, const KIID &cItem=niluuid, const KIID &dItem=niluuid)
Definition: rc_item.h:106
int GetErrorCode() const
Definition: rc_item.h:136
int m_errorCode
The error code's numeric value.
Definition: rc_item.h:165
virtual ~RC_ITEM()
Definition: rc_item.h:95
RC_ITEM(std::shared_ptr< RC_ITEM > aItem)
Definition: rc_item.h:85
MARKER_BASE * GetParent() const
Definition: rc_item.h:125
std::vector< KIID > KIIDS
Definition: rc_item.h:77
void AddItem(EDA_ITEM *aItem)
Definition: rc_item.cpp:55
MARKER_BASE * m_parent
The marker this item belongs to, if any.
Definition: rc_item.h:169
KIIDS m_ids
Definition: rc_item.h:171
virtual KIID GetAuxItem3ID() const
Definition: rc_item.h:120
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:97
virtual KIID GetAuxItem2ID() const
Definition: rc_item.h:119
virtual KIID GetMainItemID() const
Definition: rc_item.h:117
virtual KIID GetAuxItemID() const
Definition: rc_item.h:118
wxString GetErrorText() const
Definition: rc_item.h:149
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:79
virtual wxString GetErrorMessage() const
Definition: rc_item.cpp:38
wxString m_errorMessage
A message describing the details of this specific error.
Definition: rc_item.h:166
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:124
void SetErrorCode(int aCode)
Definition: rc_item.h:137
wxString GetSettingsKey() const
Definition: rc_item.h:154
std::vector< KIID > GetIDs() const
Definition: rc_item.h:122
wxString m_errorTitle
The string describing the type of error.
Definition: rc_item.h:167
RC_ITEM()
Definition: rc_item.h:79
virtual wxString GetViolatingRuleDesc() const
Definition: rc_item.h:159
void SetItems(const KIIDS &aIds)
Definition: rc_item.h:99
void ExpandAll()
Definition: rc_item.cpp:295
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:238
void PrevMarker()
Definition: rc_item.cpp:558
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:633
int m_severities
Definition: rc_item.h:280
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:330
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:317
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:239
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:278
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:204
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:250
void SelectMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:607
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition: rc_item.cpp:178
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:209
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:289
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:406
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:469
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:463
unsigned int GetColumnCount() const override
Definition: rc_item.h:237
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:311
void CenterMarker(const MARKER_BASE *aMarker)
Definition: rc_item.cpp:620
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:149
wxDataViewCtrl * m_view
Definition: rc_item.h:279
std::shared_ptr< RC_ITEMS_PROVIDER > m_rcItemsProvider
Definition: rc_item.h:281
void NextMarker()
Definition: rc_item.cpp:579
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:446
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:302
void rebuildModel(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:196
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:194
RC_TREE_NODE * m_Parent
Definition: rc_item.h:196
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:197
RC_TREE_NODE(RC_TREE_NODE *aParent, std::shared_ptr< RC_ITEM > aRcItem, NODE_TYPE aType)
Definition: rc_item.h:181
~RC_TREE_NODE()
Definition: rc_item.h:187
NODE_TYPE m_Type
Definition: rc_item.h:193
KIID niluuid(0)
SEVERITY