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 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 <macros.h>
29 #include <base_struct.h>
30 
31 class MARKER_BASE;
32 class EDA_BASE_FRAME;
33 class RC_ITEM;
34 
35 
43 {
44 public:
45  virtual void SetSeverities( int aSeverities ) = 0;
46 
47  virtual int GetCount( int aSeverity = -1 ) = 0;
48 
53  virtual RC_ITEM* GetItem( int aIndex ) = 0;
54 
60  virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
61 
62  virtual void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) = 0;
63 
64  virtual ~RC_ITEMS_PROVIDER() { }
65 };
66 
67 
73 class RC_ITEM
74 {
75 protected:
76  int m_errorCode; // the error code's numeric value
77  wxString m_errorMessage;
78  wxString m_errorTitle;
79  wxString m_settingsKey;
80  MARKER_BASE* m_parent; // The marker this item belongs to, if any
85 
86 public:
87 
88  RC_ITEM() :
89  m_errorCode( 0 ),
90  m_parent( nullptr ),
95  {
96  }
97 
98  RC_ITEM( RC_ITEM* aItem )
99  {
100  m_errorCode = aItem->m_errorCode;
102  m_errorTitle = aItem->m_errorTitle;
103  m_settingsKey = aItem->m_settingsKey;
104  m_parent = aItem->m_parent;
106  m_auxItemUuid = aItem->m_auxItemUuid;
109  }
110 
111  virtual ~RC_ITEM() { }
112 
113  void SetErrorMessage( const wxString& aMessage ) { m_errorMessage = aMessage; }
114 
115  void SetItems( EDA_ITEM* aItem, EDA_ITEM* bItem = nullptr, EDA_ITEM* cItem = nullptr,
116  EDA_ITEM* dItem = nullptr )
117  {
118  m_mainItemUuid = aItem->m_Uuid;
119 
120  if( bItem )
121  m_auxItemUuid = bItem->m_Uuid;
122 
123  if( cItem )
124  m_auxItem2Uuid = cItem->m_Uuid;
125 
126  if( dItem )
127  m_auxItem3Uuid = dItem->m_Uuid;
128  }
129 
130  void SetItems( const KIID& aItem, const KIID& bItem = niluuid, const KIID& cItem = niluuid,
131  const KIID& dItem = niluuid )
132  {
133  m_mainItemUuid = aItem;
134  m_auxItemUuid = bItem;
135  m_auxItem2Uuid = cItem;
136  m_auxItem3Uuid = dItem;
137  }
138 
139  KIID GetMainItemID() const { return m_mainItemUuid; }
140  KIID GetAuxItemID() const { return m_auxItemUuid; }
141  KIID GetAuxItem2ID() const { return m_auxItem2Uuid; }
142  KIID GetAuxItem3ID() const { return m_auxItem3Uuid; }
143 
144  void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
145  MARKER_BASE* GetParent() const { return m_parent; }
146 
147 
153  virtual wxString ShowReport( EDA_UNITS aUnits,
154  const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
155 
156  int GetErrorCode() const { return m_errorCode; }
157  void SetErrorCode( int aCode ) { m_errorCode = aCode; }
158 
163  virtual wxString GetErrorMessage() const;
164 
165  wxString GetErrorText() const
166  {
167  return wxGetTranslation( m_errorTitle );
168  }
169 
170  wxString GetSettingsKey() const
171  {
172  return m_settingsKey;
173  }
174 
179  static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
180 };
181 
182 
184 {
185 public:
187 
188  RC_TREE_NODE( RC_TREE_NODE* aParent, RC_ITEM* aRcItem, NODE_TYPE aType ) :
189  m_Type( aType ),
190  m_RcItem( aRcItem ),
191  m_Parent( aParent )
192  {}
193 
195  {
196  for( RC_TREE_NODE* child : m_Children )
197  delete child;
198  }
199 
202 
204  std::vector<RC_TREE_NODE*> m_Children;
205 };
206 
207 
208 class RC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
209 {
210 public:
211  static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
212  {
213  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
214  }
215 
216  static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
217  {
218  return static_cast<RC_TREE_NODE*>( aItem.GetID() );
219  }
220 
221  static KIID ToUUID( wxDataViewItem aItem );
222 
223 
224 public:
225  RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
226 
227  ~RC_TREE_MODEL();
228 
229  void SetProvider( RC_ITEMS_PROVIDER* aProvider );
230  void SetSeverities( int aSeverities );
231 
232  int GetDRCItemCount() const { return m_tree.size(); }
233 
234  void ExpandAll();
235 
236  bool IsContainer( wxDataViewItem const& aItem ) const override;
237 
238  wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
239 
240  unsigned int GetChildren( wxDataViewItem const& aItem,
241  wxDataViewItemArray& aChildren ) const override;
242 
243  // Simple, single-text-column model
244  unsigned int GetColumnCount() const override { return 1; }
245  wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
246  bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
247 
251  void GetValue( wxVariant& aVariant,
252  wxDataViewItem const& aItem,
253  unsigned int aCol ) const override;
254 
258  bool SetValue( wxVariant const& aVariant,
259  wxDataViewItem const& aItem,
260  unsigned int aCol ) override
261  {
262  // Editing not supported
263  return false;
264  }
265 
270  bool GetAttr( wxDataViewItem const& aItem,
271  unsigned int aCol,
272  wxDataViewItemAttr& aAttr ) const override;
273 
274  void ValueChanged( RC_TREE_NODE* aNode );
275 
276  void DeleteCurrentItem( bool aDeep );
277 
282  void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
283 
284 private:
285  void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
286  void onSizeView( wxSizeEvent& aEvent );
287 
288 private:
290  wxDataViewCtrl* m_view;
292  RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
293 
294  std::vector<RC_TREE_NODE*> m_tree; // I own this
295 };
296 
297 
298 
299 #endif // RC_ITEM_H
EDA_UNITS
Definition: common.h:198
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:394
unsigned int GetColumnCount() const override
Definition: rc_item.h:244
virtual void DeleteAllItems(bool aIncludeExclusions, bool aDeep)=0
KIID GetAuxItem2ID() const
Definition: rc_item.h:141
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:211
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:227
KIID & NilUuid()
Definition: common.cpp:57
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition: rc_item.h:79
RC_ITEM()
Definition: rc_item.h:88
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
RC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: rc_item.h:73
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:338
RC_TREE_NODE * m_Parent
Definition: rc_item.h:203
KIID m_auxItemUuid
Definition: rc_item.h:82
virtual int GetCount(int aSeverity=-1)=0
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:91
wxDataViewCtrl * m_view
Definition: rc_item.h:290
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:246
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:144
The base class for create windows for drawing purpose.
virtual RC_ITEM * GetItem(int aIndex)=0
Function GetItem retrieves a RC_ITEM by index.
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:258
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:245
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:388
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:233
This file contains miscellaneous commonly used macros and functions.
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
RC_ITEM(RC_ITEM *aItem)
Definition: rc_item.h:98
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:277
wxString GetErrorText() const
Definition: rc_item.h:165
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:204
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:292
Definition: common.h:68
int GetDRCItemCount() const
Definition: rc_item.h:232
virtual wxString ShowReport(EDA_UNITS aUnits, const std::map< KIID, EDA_ITEM * > &aItemMap) const
Function ShowReport translates this object into a text string suitable for saving to disk in a report...
Definition: rc_item.cpp:53
int m_errorCode
Definition: rc_item.h:76
void ExpandAll()
Definition: rc_item.cpp:239
void rebuildModel(RC_ITEMS_PROVIDER *aProvider, int aSeverities)
Definition: rc_item.cpp:141
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:216
static wxString ShowCoord(EDA_UNITS aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: rc_item.cpp:45
KIID niluuid(0)
KIID GetAuxItemID() const
Definition: rc_item.h:140
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition: rc_item.cpp:120
int GetErrorCode() const
Definition: rc_item.h:156
virtual ~RC_ITEM()
Definition: rc_item.h:111
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:289
wxString m_errorMessage
A message describing the details of this specific error.
Definition: rc_item.h:77
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:446
virtual void SetSeverities(int aSeverities)=0
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:261
const KIID m_Uuid
Definition: base_struct.h:162
NODE_TYPE m_Type
Definition: rc_item.h:200
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:294
virtual ~RC_ITEMS_PROVIDER()
Definition: rc_item.h:64
RC_ITEM * m_RcItem
Definition: rc_item.h:201
MARKER_BASE * m_parent
Definition: rc_item.h:80
int m_severities
Definition: rc_item.h:291
KIID m_auxItem3Uuid
Definition: rc_item.h:84
The base frame for deriving all KiCad main window classes.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
wxString GetSettingsKey() const
Definition: rc_item.h:170
RC_TREE_NODE(RC_TREE_NODE *aParent, RC_ITEM *aRcItem, NODE_TYPE aType)
Definition: rc_item.h:188
KIID m_mainItemUuid
Definition: rc_item.h:81
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:113
KIID GetMainItemID() const
Definition: rc_item.h:139
MARKER_BASE * GetParent() const
Definition: rc_item.h:145
~RC_TREE_NODE()
Definition: rc_item.h:194
void SetItems(const KIID &aItem, const KIID &bItem=niluuid, const KIID &cItem=niluuid, const KIID &dItem=niluuid)
Definition: rc_item.h:130
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:246
KIID GetAuxItem3ID() const
Definition: rc_item.h:142
void SetErrorCode(int aCode)
Definition: rc_item.h:157
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:255
virtual wxString GetErrorMessage() const
Function GetErrorMessage returns the error message of a RC_ITEM.
Definition: rc_item.cpp:36
virtual void DeleteItem(int aIndex, bool aDeep)=0
Function DeleteItem removes (and optionally deletes) the indexed item from the list.
KIID m_auxItem2Uuid
Definition: rc_item.h:83
void ValueChanged(RC_TREE_NODE *aNode)
Definition: rc_item.cpp:371
wxString m_errorTitle
The string describing the type of error.
Definition: rc_item.h:78