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 <kiid.h>
29 #include <reporter.h>
30 
31 class MARKER_BASE;
32 class EDA_BASE_FRAME;
33 class RC_ITEM;
34 class EDA_ITEM;
35 class EDA_DRAW_FRAME;
36 
37 
46 {
47 public:
48  virtual void SetSeverities( int aSeverities ) = 0;
49 
50  virtual int GetCount( int aSeverity = -1 ) const = 0;
51 
55  virtual std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const = 0;
56 
61  virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
62 
63  virtual void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) = 0;
64 
65  virtual ~RC_ITEMS_PROVIDER() { }
66 };
67 
68 
74 class RC_ITEM
75 {
76 public:
77  typedef std::vector<KIID> KIIDS;
78 
79  RC_ITEM() :
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 )
100  {
101  m_ids = aIds;
102  }
103 
104  void AddItem( EDA_ITEM* aItem );
105 
106  void SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem = nullptr,
107  const EDA_ITEM* cItem = nullptr, const EDA_ITEM* dItem = nullptr );
108 
109  void SetItems( const KIID& aItem, const KIID& bItem = niluuid, const KIID& cItem = niluuid,
110  const KIID& dItem = niluuid )
111  {
112  m_ids.clear();
113 
114  m_ids.push_back( aItem );
115  m_ids.push_back( bItem );
116  m_ids.push_back( cItem );
117  m_ids.push_back( dItem );
118  }
119 
120  KIID GetMainItemID() const { return m_ids.size() > 0 ? m_ids[0] : niluuid; }
121  KIID GetAuxItemID() const { return m_ids.size() > 1 ? m_ids[1] : niluuid;; }
122  KIID GetAuxItem2ID() const { return m_ids.size() > 2 ? m_ids[2] : niluuid;; }
123  KIID GetAuxItem3ID() const { return m_ids.size() > 3 ? m_ids[3] : niluuid;; }
124 
125  void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
126  MARKER_BASE* GetParent() const { return m_parent; }
127 
128 
134  virtual wxString ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity,
135  const std::map<KIID, EDA_ITEM*>& aItemMap ) const;
136 
137  int GetErrorCode() const { return m_errorCode; }
138  void SetErrorCode( int aCode ) { m_errorCode = aCode; }
139 
143  virtual wxString GetErrorMessage() const;
144 
145  wxString GetErrorText() const
146  {
147  return wxGetTranslation( m_errorTitle );
148  }
149 
150  wxString GetSettingsKey() const
151  {
152  return m_settingsKey;
153  }
154 
158  static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
159 
160 protected:
162  wxString m_errorMessage;
163  wxString m_errorTitle;
164  wxString m_settingsKey;
166 
168 
169 };
170 
171 
173 {
174 public:
176 
177  RC_TREE_NODE( RC_TREE_NODE* aParent, std::shared_ptr<RC_ITEM> aRcItem, NODE_TYPE aType ) :
178  m_Type( aType ),
179  m_RcItem( aRcItem ),
180  m_Parent( aParent )
181  {}
182 
184  {
185  for( RC_TREE_NODE* child : m_Children )
186  delete child;
187  }
188 
190  std::shared_ptr<RC_ITEM> m_RcItem;
191 
193  std::vector<RC_TREE_NODE*> m_Children;
194 };
195 
196 
197 class RC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
198 {
199 public:
200  static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
201  {
202  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
203  }
204 
205  static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
206  {
207  return static_cast<RC_TREE_NODE*>( aItem.GetID() );
208  }
209 
210  static KIID ToUUID( wxDataViewItem aItem );
211 
212  RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
213 
214  ~RC_TREE_MODEL();
215 
216  void SetProvider( RC_ITEMS_PROVIDER* aProvider );
217  void SetSeverities( int aSeverities );
218 
219  int GetDRCItemCount() const { return m_tree.size(); }
220 
221  void ExpandAll();
222 
223  void PrevMarker();
224  void NextMarker();
225 
226  bool IsContainer( wxDataViewItem const& aItem ) const override;
227 
228  wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
229 
230  unsigned int GetChildren( wxDataViewItem const& aItem,
231  wxDataViewItemArray& aChildren ) const override;
232 
233  // Simple, single-text-column model
234  unsigned int GetColumnCount() const override { return 1; }
235  wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
236  bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
237 
241  void GetValue( wxVariant& aVariant,
242  wxDataViewItem const& aItem,
243  unsigned int aCol ) const override;
244 
248  bool SetValue( wxVariant const& aVariant,
249  wxDataViewItem const& aItem,
250  unsigned int aCol ) override
251  {
252  // Editing not supported
253  return false;
254  }
255 
260  bool GetAttr( wxDataViewItem const& aItem,
261  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 
274 private:
275  void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
276  void onSizeView( wxSizeEvent& aEvent );
277 
279  wxDataViewCtrl* m_view;
281  RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
282 
283  std::vector<RC_TREE_NODE*> m_tree; // I own this
284 };
285 
286 #endif // RC_ITEM_H
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:463
unsigned int GetColumnCount() const override
Definition: rc_item.h:234
KIIDS m_ids
Definition: rc_item.h:167
void NextMarker()
Definition: rc_item.cpp:573
virtual void DeleteAllItems(bool aIncludeExclusions, bool aDeep)=0
KIID GetAuxItem2ID() const
Definition: rc_item.h:122
KIID niluuid(0)
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:289
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition: rc_item.h:164
SEVERITY
Definition: ui_common.h:83
RC_ITEM()
Definition: rc_item.h:79
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:74
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:407
RC_TREE_NODE * m_Parent
Definition: rc_item.h:192
std::vector< KIID > KIIDS
Definition: rc_item.h:77
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:144
wxDataViewCtrl * m_view
Definition: rc_item.h:279
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:236
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:125
virtual int GetCount(int aSeverity=-1) const =0
The base class for create windows for drawing purpose.
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:248
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:235
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:457
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:295
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:45
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:339
wxString GetErrorText() const
Definition: rc_item.h:145
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:193
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:281
Definition: kiid.h:44
int GetDRCItemCount() const
Definition: rc_item.h:219
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:190
int m_errorCode
The error code's numeric value.
Definition: rc_item.h:161
void ExpandAll()
Definition: rc_item.cpp:301
void rebuildModel(RC_ITEMS_PROVIDER *aProvider, int aSeverities)
Definition: rc_item.cpp:194
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
static wxString ShowCoord(EDA_UNITS aUnits, const wxPoint &aPos)
Format a coordinate or position to text.
Definition: rc_item.cpp:47
KIID GetAuxItemID() const
Definition: rc_item.h:121
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition: rc_item.cpp:173
int GetErrorCode() const
Definition: rc_item.h:137
virtual ~RC_ITEM()
Definition: rc_item.h:95
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:278
wxString m_errorMessage
A message describing the details of this specific error.
Definition: rc_item.h:162
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:601
void PrevMarker()
Definition: rc_item.cpp:552
virtual void SetSeverities(int aSeverities)=0
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:323
void AddItem(EDA_ITEM *aItem)
Definition: rc_item.cpp:55
NODE_TYPE m_Type
Definition: rc_item.h:189
EDA_UNITS
Definition: eda_units.h:38
RC_TREE_NODE(RC_TREE_NODE *aParent, std::shared_ptr< RC_ITEM > aRcItem, NODE_TYPE aType)
Definition: rc_item.h:177
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283
virtual ~RC_ITEMS_PROVIDER()
Definition: rc_item.h:65
virtual wxString ShowReport(EDA_UNITS aUnits, 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 std::shared_ptr< RC_ITEM > GetItem(int aIndex) const =0
Retrieve a RC_ITEM by index.
MARKER_BASE * m_parent
The marker this item belongs to, if any.
Definition: rc_item.h:165
int m_severities
Definition: rc_item.h:280
void SetItems(const KIIDS &aIds)
Definition: rc_item.h:99
The base frame for deriving all KiCad main window classes.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
wxString GetSettingsKey() const
Definition: rc_item.h:150
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:97
KIID GetMainItemID() const
Definition: rc_item.h:120
MARKER_BASE * GetParent() const
Definition: rc_item.h:126
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:440
~RC_TREE_NODE()
Definition: rc_item.h:183
RC_ITEM(std::shared_ptr< RC_ITEM > aItem)
Definition: rc_item.h:85
void SetItems(const KIID &aItem, const KIID &bItem=niluuid, const KIID &cItem=niluuid, const KIID &dItem=niluuid)
Definition: rc_item.h:109
bool IsContainer(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:308
KIID GetAuxItem3ID() const
Definition: rc_item.h:123
void SetErrorCode(int aCode)
Definition: rc_item.h:138
wxDataViewItem GetParent(wxDataViewItem const &aItem) const override
Definition: rc_item.cpp:317
virtual wxString GetErrorMessage() const
Return the error message of a RC_ITEM.
Definition: rc_item.cpp:38
virtual void DeleteItem(int aIndex, bool aDeep)=0
Remove (and optionally deletes) the indexed item from the list.
wxString m_errorTitle
The string describing the type of error.
Definition: rc_item.h:163