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 
66  virtual void DeleteAllItems() = 0;
67 
68  virtual ~RC_ITEMS_PROVIDER() { }
69 };
70 
71 
77 class RC_ITEM
78 {
79 protected:
80  int m_errorCode; // the error code's numeric value
81  wxString m_errorMessage;
82  MARKER_BASE* m_parent; // The marker this item belongs to, if any
85 
86 public:
87 
89  {
90  m_errorCode = 0;
91  m_parent = nullptr;
94  }
95 
96  RC_ITEM( RC_ITEM* aItem )
97  {
98  m_errorCode = aItem->m_errorCode;
100  m_parent = aItem->m_parent;
102  m_auxItemUuid = aItem->m_auxItemUuid;
103  }
104 
105  virtual ~RC_ITEM() { }
106 
107  void SetErrorMessage( const wxString& aMessage ) { m_errorMessage = aMessage; }
108 
109  void SetItems( EDA_ITEM* aItem, EDA_ITEM* bItem = nullptr )
110  {
111  m_mainItemUuid = aItem->m_Uuid;
112 
113  if( bItem )
114  m_auxItemUuid = bItem->m_Uuid;
115  }
116 
117  void SetItems( const KIID& aItem, const KIID& bItem = niluuid )
118  {
119  m_mainItemUuid = aItem;
120  m_auxItemUuid = bItem;
121  }
122 
123  KIID GetMainItemID() const { return m_mainItemUuid; }
124  KIID GetAuxItemID() const { return m_auxItemUuid; }
125 
126  void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
127  MARKER_BASE* GetParent() const { return m_parent; }
128 
129 
135  virtual wxString ShowReport( EDA_UNITS aUnits,
136  const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
137 
138  int GetErrorCode() const { return m_errorCode; }
139  void SetErrorCode( int aCode ) { m_errorCode = aCode; }
140 
145  virtual wxString GetErrorText( int aCode = -1, bool aTranslate = true ) const = 0;
146 
151  virtual wxString GetErrorMessage() const;
152 
157  static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
158 };
159 
160 
162 {
163 public:
165 
166  RC_TREE_NODE( RC_TREE_NODE* aParent, RC_ITEM* aRcItem, NODE_TYPE aType ) :
167  m_Type( aType ),
168  m_RcItem( aRcItem ),
169  m_Parent( aParent )
170  {}
171 
173  {
174  for( RC_TREE_NODE* child : m_Children )
175  delete child;
176  }
177 
180 
182  std::vector<RC_TREE_NODE*> m_Children;
183 };
184 
185 
186 class RC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
187 {
188 public:
189  static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
190  {
191  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
192  }
193 
194  static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
195  {
196  return static_cast<RC_TREE_NODE*>( aItem.GetID() );
197  }
198 
199  static KIID ToUUID( wxDataViewItem aItem );
200 
201 
202 public:
203  RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
204 
205  ~RC_TREE_MODEL();
206 
207  void SetProvider( RC_ITEMS_PROVIDER* aProvider );
208  void SetSeverities( int aSeverities );
209 
210  int GetDRCItemCount() const { return m_tree.size(); }
211 
212  void ExpandAll();
213 
214  bool IsContainer( wxDataViewItem const& aItem ) const override;
215 
216  wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
217 
218  unsigned int GetChildren( wxDataViewItem const& aItem,
219  wxDataViewItemArray& aChildren ) const override;
220 
221  // Simple, single-text-column model
222  unsigned int GetColumnCount() const override { return 1; }
223  wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
224  bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
225 
229  void GetValue( wxVariant& aVariant,
230  wxDataViewItem const& aItem,
231  unsigned int aCol ) const override;
232 
236  bool SetValue( wxVariant const& aVariant,
237  wxDataViewItem const& aItem,
238  unsigned int aCol ) override
239  {
240  // Editing not supported
241  return false;
242  }
243 
248  bool GetAttr( wxDataViewItem const& aItem,
249  unsigned int aCol,
250  wxDataViewItemAttr& aAttr ) const override;
251 
252  void ValueChanged( RC_TREE_NODE* aNode );
253 
254  void DeleteCurrentItem( bool aDeep );
255  void DeleteAllItems();
256 
257 private:
258  void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
259  void onSizeView( wxSizeEvent& aEvent );
260 
261 private:
263  wxDataViewCtrl* m_view;
265  RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
266 
267  std::vector<RC_TREE_NODE*> m_tree; // I own this
268 };
269 
270 
271 
272 #endif // RC_ITEM_H
EDA_UNITS
Definition: common.h:196
unsigned int GetColumnCount() const override
Definition: rc_item.h:222
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:189
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:198
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
RC_ITEM()
Definition: rc_item.h:88
void SetItems(const KIID &aItem, const KIID &bItem=niluuid)
Definition: rc_item.h:117
RC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: rc_item.h:77
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:298
RC_TREE_NODE * m_Parent
Definition: rc_item.h:181
KIID m_auxItemUuid
Definition: rc_item.h:84
virtual int GetCount(int aSeverity=-1)=0
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:91
wxDataViewCtrl * m_view
Definition: rc_item.h:263
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:224
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:126
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:236
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:223
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:348
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:204
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:96
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:248
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:182
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:265
Definition: common.h:68
int GetDRCItemCount() const
Definition: rc_item.h:210
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:80
void ExpandAll()
Definition: rc_item.cpp:210
void rebuildModel(RC_ITEMS_PROVIDER *aProvider, int aSeverities)
Definition: rc_item.cpp:139
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:194
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:124
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition: rc_item.cpp:118
int GetErrorCode() const
Definition: rc_item.h:138
virtual ~RC_ITEM()
Definition: rc_item.h:105
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:262
wxString m_errorMessage
Definition: rc_item.h:81
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:399
virtual void SetSeverities(int aSeverities)=0
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:232
const KIID m_Uuid
Definition: base_struct.h:166
NODE_TYPE m_Type
Definition: rc_item.h:178
void DeleteAllItems()
Definition: rc_item.cpp:387
virtual wxString GetErrorText(int aCode=-1, bool aTranslate=true) const =0
Function GetErrorText returns the string form of a RC error code.
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:267
virtual ~RC_ITEMS_PROVIDER()
Definition: rc_item.h:68
RC_ITEM * m_RcItem
Definition: rc_item.h:179
MARKER_BASE * m_parent
Definition: rc_item.h:82
int m_severities
Definition: rc_item.h:264
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:163
RC_TREE_NODE(RC_TREE_NODE *aParent, RC_ITEM *aRcItem, NODE_TYPE aType)
Definition: rc_item.h:166
KIID m_mainItemUuid
Definition: rc_item.h:83
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:107
KIID GetMainItemID() const
Definition: rc_item.h:123
MARKER_BASE * GetParent() const
Definition: rc_item.h:127
~RC_TREE_NODE()
Definition: rc_item.h:172
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr)
Definition: rc_item.h:109
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:217
void SetErrorCode(int aCode)
Definition: rc_item.h:139
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:226
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.
void ValueChanged(RC_TREE_NODE *aNode)
Definition: rc_item.cpp:331