KiCad PCB EDA Suite
Loading...
Searching...
No Matches
erc_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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef ERC_ITEM_H
21#define ERC_ITEM_H
22
23#include <optional>
24#include <unordered_map>
25
26#include <rc_item.h>
27#include <sch_sheet_path.h>
28
29
37{
38public:
39 ERC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aView ) :
40 RC_TREE_MODEL( aParentFrame, aView )
41 {
42 }
43
45
51 void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
52 unsigned int aCol ) const override;
53};
54
55class ERC_ITEM : public RC_ITEM
56{
57public:
62 static std::shared_ptr<ERC_ITEM> Create( int aErrorCode );
63
64 static std::shared_ptr<ERC_ITEM> Create( const wxString& aErrorKey )
65 {
66 for( const std::reference_wrapper<RC_ITEM>& item : allItemTypes )
67 {
68 if( aErrorKey == item.get().GetSettingsKey() )
69 return std::make_shared<ERC_ITEM>( static_cast<const ERC_ITEM&>( item.get() ) );
70 }
71
72 return nullptr;
73 }
74
75 static std::vector<std::reference_wrapper<RC_ITEM>> GetItemsWithSeverities()
76 {
77 static std::vector<std::reference_wrapper<RC_ITEM>> itemsWithSeverities;
78
79 if( itemsWithSeverities.empty() )
80 {
81 for( std::reference_wrapper<RC_ITEM>& item : allItemTypes )
82 {
83 if( &item.get() == &heading_internal )
84 break;
85
86 itemsWithSeverities.push_back( item );
87 }
88 }
89
90 return itemsWithSeverities;
91 }
92
99 bool IsSheetSpecific() const { return m_sheetSpecificPath.has_value(); }
100
105 void SetSheetSpecificPath( const SCH_SHEET_PATH& aSpecificSheet )
106 {
107 m_sheetSpecificPath = aSpecificSheet;
108 }
109
116 {
117 wxASSERT( m_sheetSpecificPath.has_value() );
118 return m_sheetSpecificPath.value();
119 }
120
127 void SetItemsSheetPaths( const SCH_SHEET_PATH& mainItemSheet )
128 {
129 m_mainItemSheet = mainItemSheet;
130 }
131
139 void SetItemsSheetPaths( const SCH_SHEET_PATH& mainItemSheet, const SCH_SHEET_PATH& auxItemSheet )
140 {
141 m_mainItemSheet = mainItemSheet;
142 m_auxItemSheet = auxItemSheet;
143 }
144
150 {
151 wxASSERT( MainItemHasSheetPath() );
152 return m_mainItemSheet.value();
153 }
154
160 {
161 wxASSERT( AuxItemHasSheetPath() );
162 return m_auxItemSheet.value();
163 }
164
170 bool MainItemHasSheetPath() { return m_mainItemSheet.has_value(); }
171
177 bool AuxItemHasSheetPath() { return m_auxItemSheet.has_value(); }
178
179protected:
185 wxString getItemDescription( EDA_ITEM* aItem, int aIndex, UNITS_PROVIDER* aUnitsProvider ) const override;
186
187private:
188 ERC_ITEM( int aErrorCode = 0, const wxString& aTitle = "", const wxString& aSettingsKey = "" )
189 {
190 m_errorCode = aErrorCode;
191 m_errorTitle = aTitle;
192 m_settingsKey = aSettingsKey;
193 }
194
195 std::optional<SCH_SHEET_PATH> m_mainItemSheet;
196 std::optional<SCH_SHEET_PATH> m_auxItemSheet;
197
199 static std::vector<std::reference_wrapper<RC_ITEM>> allItemTypes;
200
205
266
268 std::optional<SCH_SHEET_PATH> m_sheetSpecificPath;
269};
270
271
276{
277public:
278 explicit SCH_RC_ITEM_RESOLVER( const SCH_SHEET_LIST& aSheetList ) :
279 m_sheetList( aSheetList )
280 {
281 }
282
283 EDA_ITEM* doResolveItemById( const KIID& aKiid ) const override;
284
285private:
287
288 // Unlike PCBs, schematics (currently) do not have an item ID index.
289 // So we cache the resolved items in a map for lookup here.
290 mutable std::unordered_map<KIID, EDA_ITEM*> m_items;
291 mutable bool m_itemsBuilt = false;
292};
293
294#endif // ERC_ITEM_H
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:98
static ERC_ITEM differentUnitValue
Definition erc_item.h:260
std::optional< SCH_SHEET_PATH > m_mainItemSheet
Definition erc_item.h:195
static ERC_ITEM busToBusConflict
Definition erc_item.h:235
static ERC_ITEM labelMultipleWires
Definition erc_item.h:220
static ERC_ITEM pinTableWarning
Definition erc_item.h:213
static std::shared_ptr< ERC_ITEM > Create(const wxString &aErrorKey)
Definition erc_item.h:64
static ERC_ITEM footprintLinkIssues
Definition erc_item.h:252
const SCH_SHEET_PATH & GetSpecificSheetPath() const
Gets the SCH_SHEET_PATH this ERC item is bound to.
Definition erc_item.h:115
static ERC_ITEM emptyLabelName
Definition erc_item.h:240
static ERC_ITEM unresolvedVariable
Definition erc_item.h:246
static ERC_ITEM duplicateSheetName
Definition erc_item.h:206
static ERC_ITEM noConnectDangling
Definition erc_item.h:221
static ERC_ITEM busDefinitionConflict
Definition erc_item.h:232
static ERC_ITEM fourWayJunction
Definition erc_item.h:219
static ERC_ITEM genericError
Definition erc_item.h:216
static ERC_ITEM libSymbolIssues
Definition erc_item.h:250
static ERC_ITEM emptyPowerValue
Definition erc_item.h:241
static ERC_ITEM variantSymbolIncompatible
Definition erc_item.h:265
SCH_SHEET_PATH & GetMainItemSheetPath()
Gets the SCH_SHEET_PATH of the main item causing this ERC violation.
Definition erc_item.h:149
static ERC_ITEM pinNotDriven
Definition erc_item.h:209
wxString getItemDescription(EDA_ITEM *aItem, int aIndex, UNITS_PROVIDER *aUnitsProvider) const override
Resolve the affected-item description in the per-instance SCH_SHEET_PATH context stored on this marke...
Definition erc_item.cpp:510
static ERC_ITEM undefinedNetclass
Definition erc_item.h:247
static ERC_ITEM extraUnits
Definition erc_item.h:255
static ERC_ITEM pinMapUnmappedPin
Definition erc_item.h:243
bool AuxItemHasSheetPath()
Determines whether the auxiliary item causing this ERC violation has a specific SCH_SHEET_PATH bindin...
Definition erc_item.h:177
static ERC_ITEM variantSymbolInvalid
Definition erc_item.h:264
static ERC_ITEM heading_conflicts
Definition erc_item.h:202
void SetSheetSpecificPath(const SCH_SHEET_PATH &aSpecificSheet)
Sets the SCH_SHEET_PATH this ERC item is bound to.
Definition erc_item.h:105
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition erc_item.cpp:312
static ERC_ITEM noConnectConnected
Definition erc_item.h:218
static ERC_ITEM heading_misc
Definition erc_item.h:203
static ERC_ITEM endpointOffGrid
Definition erc_item.h:207
static ERC_ITEM isolatedPinLabel
Definition erc_item.h:223
static ERC_ITEM busToNetConflict
Definition erc_item.h:236
static ERC_ITEM differentUnitFootprint
Definition erc_item.h:230
bool MainItemHasSheetPath()
Determines whether the main item causing this ERC violation has a specific SCH_SHEET_PATH binding.
Definition erc_item.h:170
static ERC_ITEM sameLocalGlobalLabel
Definition erc_item.h:225
static ERC_ITEM hierLabelMismatch
Definition erc_item.h:217
static ERC_ITEM heading_connections
Definition erc_item.h:201
static ERC_ITEM missingUnits
Definition erc_item.h:256
static ERC_ITEM similarLabels
Definition erc_item.h:227
static ERC_ITEM unconnectedWireEndpoint
Definition erc_item.h:263
static ERC_ITEM heading_internal
Definition erc_item.h:204
static std::vector< std::reference_wrapper< RC_ITEM > > allItemTypes
A list of all ERC_ITEM types which are valid error codes.
Definition erc_item.h:199
void SetItemsSheetPaths(const SCH_SHEET_PATH &mainItemSheet)
Sets the SCH_SHEET_PATH of the main item causing this ERC violation to (e.g.
Definition erc_item.h:127
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition erc_item.h:75
static ERC_ITEM labelDangling
Definition erc_item.h:222
static ERC_ITEM pinMapStalePin
Definition erc_item.h:245
static ERC_ITEM differentUnitNet
Definition erc_item.h:231
static ERC_ITEM pinMapDuplicatePad
Definition erc_item.h:244
static ERC_ITEM pinTableError
Definition erc_item.h:214
static ERC_ITEM similarLabelAndPower
Definition erc_item.h:229
static ERC_ITEM groundPinNotGround
Definition erc_item.h:237
static ERC_ITEM genericWarning
Definition erc_item.h:215
static ERC_ITEM footprintFilters
Definition erc_item.h:253
static ERC_ITEM fieldNameWhitespace
Definition erc_item.h:239
static ERC_ITEM netNotBusMember
Definition erc_item.h:234
static ERC_ITEM wireDangling
Definition erc_item.h:249
ERC_ITEM(int aErrorCode=0, const wxString &aTitle="", const wxString &aSettingsKey="")
Definition erc_item.h:188
static ERC_ITEM powerpinNotDriven
Definition erc_item.h:210
static ERC_ITEM missingPowerInputPin
Definition erc_item.h:259
std::optional< SCH_SHEET_PATH > m_sheetSpecificPath
True if this item is specific to a sheet instance (as opposed to applying to all instances)
Definition erc_item.h:268
static ERC_ITEM missingBidiPin
Definition erc_item.h:258
bool IsSheetSpecific() const
Determines whether the ERC item is bound to a specific sheet, or is common across multiple sheets (e....
Definition erc_item.h:99
static ERC_ITEM unannotated
Definition erc_item.h:254
void SetItemsSheetPaths(const SCH_SHEET_PATH &mainItemSheet, const SCH_SHEET_PATH &auxItemSheet)
Set the SCH_SHEET PATHs of the main and auxiliary items causing this ERC violation to (e....
Definition erc_item.h:139
static ERC_ITEM missingInputPin
Definition erc_item.h:257
static ERC_ITEM wiredImplicitPower
Definition erc_item.h:211
static ERC_ITEM singleGlobalLabel
Definition erc_item.h:224
static ERC_ITEM sameLocalGlobalPower
Definition erc_item.h:226
static ERC_ITEM busEntryNeeded
Definition erc_item.h:262
static ERC_ITEM simulationModelIssues
Definition erc_item.h:248
std::optional< SCH_SHEET_PATH > m_auxItemSheet
Definition erc_item.h:196
SCH_SHEET_PATH & GetAuxItemSheetPath()
Gets the SCH_SHEET_PATH of the auxiliary item causing this ERC violation.
Definition erc_item.h:159
static ERC_ITEM pinMapBadPad
Definition erc_item.h:242
static ERC_ITEM multipleNetNames
Definition erc_item.h:233
static ERC_ITEM similarPower
Definition erc_item.h:228
static ERC_ITEM pinNotConnected
Definition erc_item.h:208
static ERC_ITEM stackedPinName
Definition erc_item.h:238
static ERC_ITEM libSymbolMismatch
Definition erc_item.h:251
static ERC_ITEM duplicateReference
Definition erc_item.h:261
static ERC_ITEM duplicatePinError
Definition erc_item.h:212
ERC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition erc_item.h:39
void GetValue(wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
Override of RC_TREE_MODEL::GetValue which returns item descriptions in a specific SCH_SHEET_PATH cont...
Definition erc_item.cpp:390
Definition kiid.h:46
Interface for resolving EDA_ITEM instances by the KIID from an RC_ITEM.
Definition rc_item.h:87
wxString m_settingsKey
The key used to describe this type of error in settings.
Definition rc_item.h:263
int m_errorCode
The error code's numeric value.
Definition rc_item.h:260
wxString m_errorTitle
The string describing the type of error.
Definition rc_item.h:262
RC_ITEM()
Definition rc_item.h:140
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition rc_item.cpp:232
SCH_RC_ITEM_RESOLVER(const SCH_SHEET_LIST &aSheetList)
Definition erc_item.h:278
EDA_ITEM * doResolveItemById(const KIID &aKiid) const override
The actual resolution logic for an item by its KIID, must be implemented against the actual item stor...
Definition erc_item.cpp:547
std::unordered_map< KIID, EDA_ITEM * > m_items
Definition erc_item.h:290
const SCH_SHEET_LIST & m_sheetList
Definition erc_item.h:286
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.