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 
155  virtual wxString GetViolatingRuleDesc() const
156  {
157  return wxEmptyString;
158  }
159 
163  static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
164 
165 protected:
167  wxString m_errorMessage;
168  wxString m_errorTitle;
169  wxString m_settingsKey;
171 
173 
174 };
175 
176 
178 {
179 public:
181 
182  RC_TREE_NODE( RC_TREE_NODE* aParent, std::shared_ptr<RC_ITEM> aRcItem, NODE_TYPE aType ) :
183  m_Type( aType ),
184  m_RcItem( aRcItem ),
185  m_Parent( aParent )
186  {}
187 
189  {
190  for( RC_TREE_NODE* child : m_Children )
191  delete child;
192  }
193 
195  std::shared_ptr<RC_ITEM> m_RcItem;
196 
198  std::vector<RC_TREE_NODE*> m_Children;
199 };
200 
201 
202 class RC_TREE_MODEL : public wxDataViewModel, wxEvtHandler
203 {
204 public:
205  static wxDataViewItem ToItem( RC_TREE_NODE const* aNode )
206  {
207  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
208  }
209 
210  static RC_TREE_NODE* ToNode( wxDataViewItem aItem )
211  {
212  return static_cast<RC_TREE_NODE*>( aItem.GetID() );
213  }
214 
215  static KIID ToUUID( wxDataViewItem aItem );
216 
217  RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView );
218 
219  ~RC_TREE_MODEL();
220 
221  void SetProvider( RC_ITEMS_PROVIDER* aProvider );
222  void SetSeverities( int aSeverities );
223 
224  int GetDRCItemCount() const { return m_tree.size(); }
225 
226  void ExpandAll();
227 
228  void PrevMarker();
229  void NextMarker();
230 
231  bool IsContainer( wxDataViewItem const& aItem ) const override;
232 
233  wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
234 
235  unsigned int GetChildren( wxDataViewItem const& aItem,
236  wxDataViewItemArray& aChildren ) const override;
237 
238  // Simple, single-text-column model
239  unsigned int GetColumnCount() const override { return 1; }
240  wxString GetColumnType( unsigned int aCol ) const override { return "string"; }
241  bool HasContainerColumns( wxDataViewItem const& aItem ) const override { return true; }
242 
246  void GetValue( wxVariant& aVariant,
247  wxDataViewItem const& aItem,
248  unsigned int aCol ) const override;
249 
253  bool SetValue( wxVariant const& aVariant,
254  wxDataViewItem const& aItem,
255  unsigned int aCol ) override
256  {
257  // Editing not supported
258  return false;
259  }
260 
265  bool GetAttr( wxDataViewItem const& aItem,
266  unsigned int aCol,
267  wxDataViewItemAttr& aAttr ) const override;
268 
269  void ValueChanged( const RC_TREE_NODE* aNode );
270 
271  void DeleteCurrentItem( bool aDeep );
272 
277  void DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, bool aDeep );
278 
279 private:
280  void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
281  void onSizeView( wxSizeEvent& aEvent );
282 
284  wxDataViewCtrl* m_view;
286  RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
287 
288  std::vector<RC_TREE_NODE*> m_tree; // I own this
289 };
290 
291 #endif // RC_ITEM_H
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:459
unsigned int GetColumnCount() const override
Definition: rc_item.h:239
KIIDS m_ids
Definition: rc_item.h:172
void NextMarker()
Definition: rc_item.cpp:569
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:205
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:292
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition: rc_item.h:169
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:403
RC_TREE_NODE * m_Parent
Definition: rc_item.h:197
std::vector< KIID > KIIDS
Definition: rc_item.h:77
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:147
wxDataViewCtrl * m_view
Definition: rc_item.h:284
bool HasContainerColumns(wxDataViewItem const &aItem) const override
Definition: rc_item.h:241
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:253
wxString GetColumnType(unsigned int aCol) const override
Definition: rc_item.h:240
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:453
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:298
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:198
virtual wxString GetViolatingRuleDesc() const
Definition: rc_item.h:155
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:286
Definition: kiid.h:44
int GetDRCItemCount() const
Definition: rc_item.h:224
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
int m_errorCode
The error code's numeric value.
Definition: rc_item.h:166
void ExpandAll()
Definition: rc_item.cpp:304
void rebuildModel(RC_ITEMS_PROVIDER *aProvider, int aSeverities)
Definition: rc_item.cpp:197
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
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:176
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:283
wxString m_errorMessage
A message describing the details of this specific error.
Definition: rc_item.h:167
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:597
SEVERITY
void PrevMarker()
Definition: rc_item.cpp:548
virtual void SetSeverities(int aSeverities)=0
unsigned int GetChildren(wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
Definition: rc_item.cpp:326
void AddItem(EDA_ITEM *aItem)
Definition: rc_item.cpp:55
NODE_TYPE m_Type
Definition: rc_item.h:194
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:182
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:288
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:170
int m_severities
Definition: rc_item.h:285
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:436
~RC_TREE_NODE()
Definition: rc_item.h:188
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:311
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:320
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:168