KiCad PCB EDA Suite
erc_item.cpp
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
25#include "wx/html/m_templ.h"
26#include "wx/html/styleparams.h"
27#include <erc.h>
28#include <eda_draw_frame.h>
29#include <marker_base.h>
30#include <sch_edit_frame.h>
31
32
33// These, being statically-defined, require specialized I18N handling. We continue to
34// use the _() macro so that string harvesting by the I18N framework doesn't have to be
35// specialized, but we don't translate on initialization and instead do it in the getters.
36
37#undef _
38#define _(s) s
39
40// NOTE: Avoid changing the settings key for an ERC item after it has been created
41
42ERC_ITEM ERC_ITEM::heading_connections( 0, _( "Connections" ), "" );
43ERC_ITEM ERC_ITEM::heading_conflicts( 0, _( "Conflicts" ), "" );
44ERC_ITEM ERC_ITEM::heading_misc( 0, _( "Miscellaneous" ), "" );
45
47 _( "Duplicate sheet names within a given sheet" ),
48 wxT( "duplicate_sheet_names" ) );
49
51 _( "Symbol pin or wire end off grid" ),
52 wxT( "endpoint_off_grid" ) );
53
55 _( "Pin not connected" ),
56 wxT( "pin_not_connected" ) );
57
59 _( "Input pin not driven by any Output pins" ),
60 wxT( "pin_not_driven" ) );
61
63 _( "Input Power pin not driven by any Output Power pins" ),
64 wxT( "power_pin_not_driven" ) );
65
67 _( "Conflict problem between pins" ),
68 wxT( "pin_to_pin" ) );
69
71 _( "Conflict problem between pins" ),
72 wxT( "pin_to_pin" ) );
73
75 _( "Mismatch between hierarchical labels and sheet pins" ),
76 wxT( "hier_label_mismatch" ) );
77
79 _( "A pin with a \"no connection\" flag is connected" ),
80 wxT( "no_connect_connected" ) );
81
83 _( "Unconnected \"no connection\" flag" ),
84 wxT( "no_connect_dangling" ) );
85
87 _( "Label not connected to anything" ),
88 wxT( "label_dangling" ) );
89
91 _( "Global label not connected anywhere else in the schematic" ),
92 wxT( "global_label_dangling" ) );
93
95 _( "Labels are similar (lower/upper case difference only)"),
96 wxT( "similar_labels" ) );
97
99 _( "Different footprint assigned in another unit of the symbol" ),
100 wxT( "different_unit_footprint" ) );
101
103 _( "Different net assigned to a shared pin in another unit of the symbol" ),
104 wxT( "different_unit_net" ) );
105
107 _( "Conflict between bus alias definitions across schematic sheets" ),
108 wxT( "bus_definition_conflict" ) );
109
111 _( "More than one name given to this bus or net" ),
112 wxT( "multiple_net_names" ) );
113
115 _( "Conflicting netclass assignments" ),
116 wxT( "conflicting_netclasses" ) );
117
119 _( "Net is graphically connected to a bus but not a bus member" ),
120 wxT( "net_not_bus_member" ) );
121
123 _( "Label attached to bus item does not describe a bus" ),
124 wxT( "bus_label_syntax" ) );
125
127 _( "Buses are graphically connected but share no bus members" ),
128 wxT( "bus_to_bus_conflict" ) );
129
131 _( "Invalid connection between bus and net items" ),
132 wxT( "bus_to_net_conflict" ) );
133
135 _( "Unresolved text variable" ),
136 wxT( "unresolved_variable" ) );
137
139 _( "SPICE model issue" ),
140 wxT( "simulation_model_issue" ) );
141
143 _( "Wires not connected to anything" ),
144 wxT( "wire_dangling" ) );
145
147 _( "Library symbol issue" ),
148 wxT( "lib_symbol_issues" ) );
149
151 _( "Symbol is not annotated" ),
152 wxT( "unannotated" ) );
153
155 _( "Symbol has more units than are defined" ),
156 wxT( "extra_units" ) );
157
159 _( "Symbol has units that are not placed" ),
160 wxT( "missing_unit" ) );
161
163 _( "Symbol has input pins that are not placed" ),
164 wxT( "missing_input_pin" ) );
165
167 _( "Symbol has bidirectional pins that are not placed" ),
168 wxT( "missing_bidi_pin" ) );
169
171 _( "Symbol has power input pins that are not placed" ),
172 wxT( "missing_power_pin" ) );
173
175 _( "Units of same symbol have different values" ),
176 wxT( "unit_value_mismatch" ) );
177
179 _( "Duplicate reference designators" ),
180 wxT( "duplicate_reference" ) );
181
183 _( "Bus Entry needed" ),
184 wxT( "bus_entry_needed" ) );
185
186std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
198
213
219 // Commented out until the logic for this element is coded
220 // TODO: Add bus label syntax checking
221// ERC_ITEM::busLabelSyntax,
228 } );
229
230
231
232std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
233{
234 switch( aErrorCode )
235 {
236 case ERCE_DUPLICATE_SHEET_NAME: return std::make_shared<ERC_ITEM>( duplicateSheetName );
237 case ERCE_ENDPOINT_OFF_GRID: return std::make_shared<ERC_ITEM>( endpointOffGrid );
238 case ERCE_PIN_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( pinNotConnected );
239 case ERCE_PIN_NOT_DRIVEN: return std::make_shared<ERC_ITEM>( pinNotDriven );
240 case ERCE_POWERPIN_NOT_DRIVEN: return std::make_shared<ERC_ITEM>( powerpinNotDriven );
241 case ERCE_PIN_TO_PIN_WARNING: return std::make_shared<ERC_ITEM>( pinTableWarning );
242 case ERCE_PIN_TO_PIN_ERROR: return std::make_shared<ERC_ITEM>( pinTableError );
243 case ERCE_HIERACHICAL_LABEL: return std::make_shared<ERC_ITEM>( hierLabelMismatch );
244 case ERCE_NOCONNECT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectConnected );
245 case ERCE_NOCONNECT_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectDangling );
246 case ERCE_LABEL_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( labelDangling );
247 case ERCE_SIMILAR_LABELS: return std::make_shared<ERC_ITEM>( similarLabels );
248 case ERCE_DIFFERENT_UNIT_FP: return std::make_shared<ERC_ITEM>( differentUnitFootprint );
249 case ERCE_DIFFERENT_UNIT_NET: return std::make_shared<ERC_ITEM>( differentUnitNet );
250 case ERCE_BUS_ALIAS_CONFLICT: return std::make_shared<ERC_ITEM>( busDefinitionConflict );
251 case ERCE_DRIVER_CONFLICT: return std::make_shared<ERC_ITEM>( multipleNetNames );
252 case ERCE_BUS_ENTRY_CONFLICT: return std::make_shared<ERC_ITEM>( netNotBusMember );
253 case ERCE_BUS_LABEL_ERROR: return std::make_shared<ERC_ITEM>( busLabelSyntax );
254 case ERCE_BUS_TO_BUS_CONFLICT: return std::make_shared<ERC_ITEM>( busToBusConflict );
255 case ERCE_BUS_TO_NET_CONFLICT: return std::make_shared<ERC_ITEM>( busToNetConflict );
256 case ERCE_NETCLASS_CONFLICT: return std::make_shared<ERC_ITEM>( netclassConflict );
257 case ERCE_GLOBLABEL: return std::make_shared<ERC_ITEM>( globalLabelDangling );
258 case ERCE_UNRESOLVED_VARIABLE: return std::make_shared<ERC_ITEM>( unresolvedVariable );
259 case ERCE_SIMULATION_MODEL: return std::make_shared<ERC_ITEM>( simulationModelIssues );
260 case ERCE_WIRE_DANGLING: return std::make_shared<ERC_ITEM>( wireDangling );
261 case ERCE_LIB_SYMBOL_ISSUES: return std::make_shared<ERC_ITEM>( libSymbolIssues );
262 case ERCE_UNANNOTATED: return std::make_shared<ERC_ITEM>( unannotated );
263 case ERCE_EXTRA_UNITS: return std::make_shared<ERC_ITEM>( extraUnits );
264 case ERCE_DIFFERENT_UNIT_VALUE: return std::make_shared<ERC_ITEM>( differentUnitValue );
265 case ERCE_DUPLICATE_REFERENCE: return std::make_shared<ERC_ITEM>( duplicateReference );
266 case ERCE_BUS_ENTRY_NEEDED: return std::make_shared<ERC_ITEM>( busEntryNeeded );
267 case ERCE_MISSING_UNIT: return std::make_shared<ERC_ITEM>( missingUnits );
268 case ERCE_MISSING_INPUT_PIN: return std::make_shared<ERC_ITEM>( missingInputPin );
269 case ERCE_MISSING_POWER_INPUT_PIN: return std::make_shared<ERC_ITEM>( missingPowerInputPin );
270 case ERCE_MISSING_BIDI_PIN: return std::make_shared<ERC_ITEM>( missingBidiPin );
271 case ERCE_UNSPECIFIED:
272 default:
273 wxFAIL_MSG( wxS( "Unknown ERC error code" ) );
274 return nullptr;
275 }
276
277 return nullptr;
278}
279
285void ERC_TREE_MODEL::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
286 unsigned int aCol ) const
287{
288 const RC_TREE_NODE* node = ToNode( aItem );
289 const std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
290
291 switch( node->m_Type )
292 {
294 {
295 wxString prefix;
296
297 if( rcItem->GetParent() )
298 {
299 SEVERITY severity = rcItem->GetParent()->GetSeverity();
300
301 if( severity == RPT_SEVERITY_EXCLUSION )
302 {
303 if( m_editFrame->GetSeverity( rcItem->GetErrorCode() ) == RPT_SEVERITY_WARNING )
304 prefix = _( "Excluded warning: " );
305 else
306 prefix = _( "Excluded error: " );
307 }
308 else if( severity == RPT_SEVERITY_WARNING )
309 {
310 prefix = _( "Warning: " );
311 }
312 else
313 {
314 prefix = _( "Error: " );
315 }
316 }
317
318 aVariant = prefix + rcItem->GetErrorMessage();
319 }
320 break;
321
323 if( rcItem->GetParent()
324 && rcItem->GetParent()->GetMarkerType() == MARKER_BASE::MARKER_DRAWING_SHEET )
325 {
326 aVariant = _( "Drawing Sheet" );
327 break;
328 }
329 else
330 {
331 std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( rcItem );
332 SCH_EDIT_FRAME* schEditFrame = static_cast<SCH_EDIT_FRAME*>( m_editFrame );
333 SCH_SHEET_PATH curPath;
334
335 // Update the target ERC item reference field to a specific sheet context if present
336 curPath = schEditFrame->GetCurrentSheet();
337
338 if( ercItem->MainItemHasSheetPath() )
339 ercItem->GetMainItemSheetPath().UpdateAllScreenReferences();
340
341 EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetMainItemID() );
342 aVariant = item->GetItemDescription( m_editFrame );
343
344 // Reset reference fields to current visible sheet
345 if( ercItem->MainItemHasSheetPath() )
347 }
348
349 break;
350
352 {
353 std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( rcItem );
354 SCH_EDIT_FRAME* schEditFrame = static_cast<SCH_EDIT_FRAME*>( m_editFrame );
355 SCH_SHEET_PATH curPath;
356
357 // Update the target ERC item reference field to a specific sheet context if present
358 curPath = schEditFrame->GetCurrentSheet();
359
360 if( ercItem->AuxItemHasSheetPath() )
361 ercItem->GetAuxItemSheetPath().UpdateAllScreenReferences();
362
363 EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItemID() );
364 aVariant = item->GetItemDescription( m_editFrame );
365
366 // Reset reference fields to current visible sheet
367 if( ercItem->AuxItemHasSheetPath() )
369 }
370 break;
371
373 {
374 EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem2ID() );
375 aVariant = item->GetItemDescription( m_editFrame );
376 }
377 break;
378
380 {
381 EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem3ID() );
382 aVariant = item->GetItemDescription( m_editFrame );
383 }
384 break;
385 }
386}
virtual SEVERITY GetSeverity(int aErrorCode) const
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:108
static ERC_ITEM differentUnitValue
Definition: erc_item.h:218
static ERC_ITEM busToBusConflict
Definition: erc_item.h:206
static ERC_ITEM pinTableWarning
Definition: erc_item.h:191
static ERC_ITEM unresolvedVariable
Definition: erc_item.h:208
static ERC_ITEM duplicateSheetName
Definition: erc_item.h:186
static ERC_ITEM noConnectDangling
Definition: erc_item.h:195
static ERC_ITEM busDefinitionConflict
Definition: erc_item.h:201
static ERC_ITEM libSymbolIssues
Definition: erc_item.h:211
static ERC_ITEM pinNotDriven
Definition: erc_item.h:189
static ERC_ITEM extraUnits
Definition: erc_item.h:213
static ERC_ITEM heading_conflicts
Definition: erc_item.h:183
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:232
static ERC_ITEM noConnectConnected
Definition: erc_item.h:194
static ERC_ITEM heading_misc
Definition: erc_item.h:184
static ERC_ITEM endpointOffGrid
Definition: erc_item.h:187
static ERC_ITEM busToNetConflict
Definition: erc_item.h:207
static ERC_ITEM differentUnitFootprint
Definition: erc_item.h:199
static ERC_ITEM hierLabelMismatch
Definition: erc_item.h:193
static ERC_ITEM heading_connections
Definition: erc_item.h:182
static ERC_ITEM missingUnits
Definition: erc_item.h:214
static ERC_ITEM similarLabels
Definition: erc_item.h:198
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:180
static ERC_ITEM globalLabelDangling
Definition: erc_item.h:197
static ERC_ITEM labelDangling
Definition: erc_item.h:196
static ERC_ITEM differentUnitNet
Definition: erc_item.h:200
static ERC_ITEM pinTableError
Definition: erc_item.h:192
static ERC_ITEM netNotBusMember
Definition: erc_item.h:204
static ERC_ITEM wireDangling
Definition: erc_item.h:210
static ERC_ITEM busLabelSyntax
Definition: erc_item.h:205
static ERC_ITEM powerpinNotDriven
Definition: erc_item.h:190
static ERC_ITEM missingPowerInputPin
Definition: erc_item.h:217
static ERC_ITEM missingBidiPin
Definition: erc_item.h:216
static ERC_ITEM unannotated
Definition: erc_item.h:212
static ERC_ITEM missingInputPin
Definition: erc_item.h:215
static ERC_ITEM netclassConflict
Definition: erc_item.h:203
static ERC_ITEM busEntryNeeded
Definition: erc_item.h:220
static ERC_ITEM simulationModelIssues
Definition: erc_item.h:209
static ERC_ITEM multipleNetNames
Definition: erc_item.h:202
static ERC_ITEM pinNotConnected
Definition: erc_item.h:188
static ERC_ITEM duplicateReference
Definition: erc_item.h:219
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:285
@ MARKER_DRAWING_SHEET
Definition: marker_base.h:55
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:278
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:209
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:194
NODE_TYPE m_Type
Definition: rc_item.h:193
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
#define _(s)
Definition: erc_item.cpp:38
@ ERCE_UNSPECIFIED
Definition: erc_settings.h:38
@ ERCE_UNANNOTATED
Symbol has not been annotated.
Definition: erc_settings.h:75
@ ERCE_POWERPIN_NOT_DRIVEN
Power input pin connected to some others pins but no power out pin to drive it.
Definition: erc_settings.h:45
@ ERCE_DRIVER_CONFLICT
Conflicting drivers (labels, etc) on a subgraph.
Definition: erc_settings.h:61
@ ERCE_MISSING_POWER_INPUT_PIN
Symbol has power input pins that are not placed on the schematic.
Definition: erc_settings.h:54
@ ERCE_SIMILAR_LABELS
2 labels are equal for case insensitive comparisons.
Definition: erc_settings.h:51
@ ERCE_LABEL_NOT_CONNECTED
Label not connected to anything.
Definition: erc_settings.h:50
@ ERCE_ENDPOINT_OFF_GRID
Pin or wire-end off grid.
Definition: erc_settings.h:41
@ ERCE_DUPLICATE_REFERENCE
More than one symbol with the same reference.
Definition: erc_settings.h:78
@ ERCE_EXTRA_UNITS
Symbol has more units than are defined.
Definition: erc_settings.h:76
@ ERCE_BUS_TO_BUS_CONFLICT
A connection between bus objects doesn't share at least one net.
Definition: erc_settings.h:64
@ ERCE_BUS_LABEL_ERROR
A label attached to a bus isn't in bus format.
Definition: erc_settings.h:63
@ ERCE_BUS_ENTRY_CONFLICT
A wire connected to a bus doesn't match the bus.
Definition: erc_settings.h:62
@ ERCE_NETCLASS_CONFLICT
Multiple labels assign different netclasses to same net.
Definition: erc_settings.h:68
@ ERCE_GLOBLABEL
A global label is unique.
Definition: erc_settings.h:69
@ ERCE_BUS_TO_NET_CONFLICT
A bus wire is graphically connected to a net port/pin (or vice versa).
Definition: erc_settings.h:66
@ ERCE_NOCONNECT_NOT_CONNECTED
A no connect symbol is not connected to anything.
Definition: erc_settings.h:49
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
Definition: erc_settings.h:58
@ ERCE_PIN_NOT_CONNECTED
Pin not connected and not no connect symbol.
Definition: erc_settings.h:42
@ ERCE_BUS_ENTRY_NEEDED
Importer failed to auto-place a bus entry.
Definition: erc_settings.h:79
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
Definition: erc_settings.h:70
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
Definition: erc_settings.h:71
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
Definition: erc_settings.h:52
@ ERCE_NOCONNECT_CONNECTED
A no connect symbol is connected to more than 1 pin.
Definition: erc_settings.h:48
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:85
@ ERCE_PIN_NOT_DRIVEN
Pin connected to some others pins but no pin to drive it.
Definition: erc_settings.h:43
@ ERCE_MISSING_INPUT_PIN
Symbol has input pins that are not placed.
Definition: erc_settings.h:55
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
Definition: erc_settings.h:57
@ ERCE_DUPLICATE_SHEET_NAME
Duplicate sheet names within a given sheet.
Definition: erc_settings.h:40
@ ERCE_MISSING_BIDI_PIN
Symbol has bi-directional pins that are not placed.
Definition: erc_settings.h:56
@ ERCE_LIB_SYMBOL_ISSUES
Library symbol changed from current symbol in schematic or the library symbol link no longer valid.
Definition: erc_settings.h:73
@ ERCE_HIERACHICAL_LABEL
Mismatch between hierarchical labels and pins sheets.
Definition: erc_settings.h:47
@ ERCE_WIRE_DANGLING
Some wires are not connected to anything else.
Definition: erc_settings.h:72
@ ERCE_BUS_ALIAS_CONFLICT
Conflicting bus alias definitions across sheets.
Definition: erc_settings.h:60
@ ERCE_DIFFERENT_UNIT_VALUE
Units of same symbol have different values.
Definition: erc_settings.h:77
@ ERCE_PIN_TO_PIN_ERROR
Definition: erc_settings.h:86
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_EXCLUSION