From 95032bd4872db732454ad10db57c06e3714caa72 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 14 Oct 2023 20:46:39 +0100 Subject: [PATCH] Make ERC off-grid check user-configurable. Fixes https://gitlab.com/kicad/code/kicad/-/issues/14110 --- eeschema/dialogs/panel_setup_formatting.cpp | 16 +- eeschema/dialogs/panel_setup_formatting.h | 3 +- .../dialogs/panel_setup_formatting_base.cpp | 25 +- .../dialogs/panel_setup_formatting_base.fbp | 229 +++++++++++++++++- .../dialogs/panel_setup_formatting_base.h | 4 + eeschema/erc.cpp | 27 +-- eeschema/erc.h | 8 +- eeschema/schematic_settings.cpp | 19 +- eeschema/schematic_settings.h | 11 + 9 files changed, 290 insertions(+), 52 deletions(-) diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index 0052b46a09..27c6db7c97 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -37,7 +37,8 @@ PANEL_SETUP_FORMATTING::PANEL_SETUP_FORMATTING( wxWindow* aWindow, SCH_EDIT_FRAM m_frame( aFrame ), m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ), m_lineWidth( aFrame, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ), - m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits ) + m_pinSymbolSize( aFrame, m_pinSymbolSizeLabel, m_pinSymbolSizeCtrl, m_pinSymbolSizeUnits ), + m_connectionGridSize( aFrame, m_connectionGridLabel, m_connectionGridCtrl, m_connectionGridUnits ) { wxSize minSize = m_dashLengthCtrl->GetMinSize(); int minWidth = m_dashLengthCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth(); @@ -84,11 +85,13 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow() m_textSize.SetUnits( EDA_UNITS::MILS ); m_lineWidth.SetUnits( EDA_UNITS::MILS ); m_pinSymbolSize.SetUnits( EDA_UNITS::MILS ); + m_connectionGridSize.SetUnits( EDA_UNITS::MILS ); m_textSize.SetValue( settings.m_DefaultTextSize ); m_lineWidth.SetValue( settings.m_DefaultLineWidth ); m_pinSymbolSize.SetValue( settings.m_PinSymbolSize ); m_choiceJunctionDotSize->SetSelection( settings.m_JunctionSizeChoice ); + m_connectionGridSize.SetValue( settings.m_ConnectionGridSize ); m_showIntersheetsReferences->SetValue( settings.m_IntersheetRefsShow ); @@ -128,6 +131,9 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow() bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() { + if( !m_connectionGridSize.Validate( MIN_CONNECTION_GRID_MILS, 10000, EDA_UNITS::MILS ) ) + return false; + SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings(); // Reference style one of: "A" ".A" "-A" "_A" ".1" "-1" "_1" @@ -151,9 +157,10 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() LIB_SYMBOL::SetSubpartIdNotation( refSeparator, firstRefId ); } - settings.m_DefaultTextSize = (int) m_textSize.GetValue(); - settings.m_DefaultLineWidth = (int) m_lineWidth.GetValue(); - settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue(); + settings.m_DefaultTextSize = m_textSize.GetIntValue(); + settings.m_DefaultLineWidth = m_lineWidth.GetIntValue(); + settings.m_PinSymbolSize = m_pinSymbolSize.GetIntValue(); + settings.m_ConnectionGridSize = m_connectionGridSize.GetIntValue(); if( m_choiceJunctionDotSize->GetSelection() != wxNOT_FOUND ) settings.m_JunctionSizeChoice = m_choiceJunctionDotSize->GetSelection(); @@ -197,6 +204,7 @@ void PANEL_SETUP_FORMATTING::ImportSettingsFrom( SCHEMATIC_SETTINGS& aSettings ) m_textSize.SetValue( aSettings.m_DefaultTextSize ); m_lineWidth.SetValue( aSettings.m_DefaultLineWidth ); m_pinSymbolSize.SetValue( aSettings.m_PinSymbolSize ); + m_connectionGridSize.SetValue( aSettings.m_ConnectionGridSize ); m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetRefsShow ); m_radioFormatStandard->SetValue( aSettings.m_IntersheetRefsFormatShort ); diff --git a/eeschema/dialogs/panel_setup_formatting.h b/eeschema/dialogs/panel_setup_formatting.h index 11a49172bc..41038cf0fa 100644 --- a/eeschema/dialogs/panel_setup_formatting.h +++ b/eeschema/dialogs/panel_setup_formatting.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -48,6 +48,7 @@ private: UNIT_BINDER m_lineWidth; UNIT_BINDER m_pinSymbolSize; + UNIT_BINDER m_connectionGridSize; }; diff --git a/eeschema/dialogs/panel_setup_formatting_base.cpp b/eeschema/dialogs/panel_setup_formatting_base.cpp index be1b879cba..9c089aeb43 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.cpp +++ b/eeschema/dialogs/panel_setup_formatting_base.cpp @@ -150,21 +150,36 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi wxStaticBoxSizer* sbSizer2; sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Connections") ), wxVERTICAL ); - wxBoxSizer* bSizer61; - bSizer61 = new wxBoxSizer( wxHORIZONTAL ); + wxGridBagSizer* gbSizer1; + gbSizer1 = new wxGridBagSizer( 5, 5 ); + gbSizer1->SetFlexibleDirection( wxBOTH ); + gbSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_staticText261 = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("Junction dot size:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText261->Wrap( -1 ); - bSizer61->Add( m_staticText261, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( m_staticText261, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); wxString m_choiceJunctionDotSizeChoices[] = { _("None"), _("Smallest"), _("Small"), _("Default"), _("Large"), _("Largest") }; int m_choiceJunctionDotSizeNChoices = sizeof( m_choiceJunctionDotSizeChoices ) / sizeof( wxString ); m_choiceJunctionDotSize = new wxChoice( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceJunctionDotSizeNChoices, m_choiceJunctionDotSizeChoices, 0 ); m_choiceJunctionDotSize->SetSelection( 3 ); - bSizer61->Add( m_choiceJunctionDotSize, 1, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( m_choiceJunctionDotSize, wxGBPosition( 0, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + + m_connectionGridLabel = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("Connection grid:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_connectionGridLabel->Wrap( -1 ); + gbSizer1->Add( m_connectionGridLabel, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_connectionGridCtrl = new wxTextCtrl( sbSizer2->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_connectionGridCtrl, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + + m_connectionGridUnits = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 ); + m_connectionGridUnits->Wrap( -1 ); + gbSizer1->Add( m_connectionGridUnits, wxGBPosition( 1, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); - sbSizer2->Add( bSizer61, 0, wxEXPAND|wxBOTTOM|wxRIGHT, 5 ); + gbSizer1->AddGrowableCol( 1 ); + + sbSizer2->Add( gbSizer1, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); bLeftColumn->Add( sbSizer2, 1, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); diff --git a/eeschema/dialogs/panel_setup_formatting_base.fbp b/eeschema/dialogs/panel_setup_formatting_base.fbp index 72b9bc8a05..950e56fd95 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.fbp +++ b/eeschema/dialogs/panel_setup_formatting_base.fbp @@ -1410,17 +1410,26 @@ none 5 - wxEXPAND|wxBOTTOM|wxRIGHT - 0 - + wxEXPAND|wxRIGHT|wxLEFT + 1 + + + wxBOTH + 1 + + 5 - bSizer61 - wxHORIZONTAL + gbSizer1 + wxFLEX_GROWMODE_SPECIFIED none - + 5 + 5 - wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL - 0 + 1 + 0 + wxALIGN_CENTER_VERTICAL + 0 + 1 1 1 @@ -1478,10 +1487,13 @@ -1 - + 5 - wxRIGHT|wxALIGN_CENTER_VERTICAL - 1 + 2 + 1 + wxALIGN_CENTER_VERTICAL|wxEXPAND + 0 + 1 1 1 @@ -1542,6 +1554,201 @@ + + 5 + 1 + 0 + wxALIGN_CENTER_VERTICAL + 1 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Connection grid: + 0 + + 0 + + + 0 + + 1 + m_connectionGridLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + 1 + 1 + wxALIGN_CENTER_VERTICAL|wxEXPAND + 1 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_connectionGridCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + 1 + 2 + wxALIGN_CENTER_VERTICAL + 1 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + mils + 0 + + 0 + + + 0 + + 1 + m_connectionGridUnits + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + diff --git a/eeschema/dialogs/panel_setup_formatting_base.h b/eeschema/dialogs/panel_setup_formatting_base.h index e9f1e6ef83..d573f1f88e 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.h +++ b/eeschema/dialogs/panel_setup_formatting_base.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,9 @@ class PANEL_SETUP_FORMATTING_BASE : public wxPanel wxStaticText* m_pinSymbolSizeUnits; wxStaticText* m_staticText261; wxChoice* m_choiceJunctionDotSize; + wxStaticText* m_connectionGridLabel; + wxTextCtrl* m_connectionGridCtrl; + wxStaticText* m_connectionGridUnits; wxCheckBox* m_showIntersheetsReferences; wxCheckBox* m_listOwnPage; wxRadioButton* m_radioFormatStandard; diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 47b651ff06..884037b911 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -978,15 +978,9 @@ int ERC_TESTER::TestLibSymbolIssues() } -int ERC_TESTER::TestOffGridEndpoints( int aGridSize ) +int ERC_TESTER::TestOffGridEndpoints() { - // The minimal grid size allowed to place a pin is 25 mils - // the best grid size is 50 mils, but 25 mils is still usable - // this is because all symbols are using a 50 mils grid to place pins, and therefore - // the wires must be on the 50 mils grid - // So raise an error if a pin is not on a 25 mil (or bigger: 50 mil or 100 mil) grid - const int min_grid_size = schIUScale.MilsToIU( 25 ); - const int clamped_grid_size = ( aGridSize < min_grid_size ) ? min_grid_size : aGridSize; + const int gridSize = m_schematic->Settings().m_ConnectionGridSize; SCH_SCREENS screens( m_schematic->Root() ); int err_count = 0; @@ -1001,16 +995,16 @@ int ERC_TESTER::TestOffGridEndpoints( int aGridSize ) { SCH_LINE* line = static_cast( item ); - if( ( line->GetStartPoint().x % clamped_grid_size ) != 0 - || ( line->GetStartPoint().y % clamped_grid_size) != 0 ) + if( ( line->GetStartPoint().x % gridSize ) != 0 + || ( line->GetStartPoint().y % gridSize ) != 0 ) { std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID ); ercItem->SetItems( line ); markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) ); } - else if( ( line->GetEndPoint().x % clamped_grid_size ) != 0 - || ( line->GetEndPoint().y % clamped_grid_size) != 0 ) + else if( ( line->GetEndPoint().x % gridSize ) != 0 + || ( line->GetEndPoint().y % gridSize ) != 0 ) { std::shared_ptr ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID ); ercItem->SetItems( line ); @@ -1026,11 +1020,9 @@ int ERC_TESTER::TestOffGridEndpoints( int aGridSize ) { VECTOR2I pinPos = pin->GetTransformedPosition(); - if( ( pinPos.x % clamped_grid_size ) != 0 - || ( pinPos.y % clamped_grid_size) != 0 ) + if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 ) { - std::shared_ptr ercItem = - ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID ); + auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID ); ercItem->SetItems( pin ); markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) ); @@ -1221,8 +1213,7 @@ void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aE if( aProgressReporter ) aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) ); - if( aEditFrame ) - TestOffGridEndpoints( aEditFrame->GetCanvas()->GetView()->GetGAL()->GetGridSize().x ); + TestOffGridEndpoints(); } m_schematic->ResolveERCExclusionsPostUpdate(); diff --git a/eeschema/erc.h b/eeschema/erc.h index 7f9203e0b7..2f7855bca3 100644 --- a/eeschema/erc.h +++ b/eeschema/erc.h @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2009-2020 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2009-2023 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file erc.h - */ - #ifndef _ERC_H #define _ERC_H @@ -134,7 +130,7 @@ public: * Test pins and wire ends for being off grid. * @return the error count */ - int TestOffGridEndpoints( int aGridSize ); + int TestOffGridEndpoints(); /** * Test SPICE models for various issues. diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index 1c9c87b5e7..13deb9dd02 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -45,6 +45,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_PinSymbolSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS / 2 ), m_JunctionSizeChoice( 3 ), m_JunctionSize( DEFAULT_JUNCTION_DIAM * schIUScale.IU_PER_MILS ), + m_ConnectionGridSize( DEFAULT_CONNECTION_GRID_MILS * schIUScale.IU_PER_MILS ), m_AnnotateStartNum( 0 ), m_IntersheetRefsShow( false ), m_IntersheetRefsListOwnPage( true ), @@ -119,12 +120,12 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin &m_OPO_IRange, wxS( "~A" ) ) ); m_params.emplace_back( new PARAM_SCALED( "drawing.default_line_thickness", - &m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ), schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), - 1 / schIUScale.IU_PER_MILS ) ); + &m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ), + schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) ); m_params.emplace_back( new PARAM_SCALED( "drawing.default_text_size", - &m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ), schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), - 1 / schIUScale.IU_PER_MILS ) ); + &m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ), + schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) ); m_params.emplace_back( new PARAM( "drawing.text_offset_ratio", &m_TextOffsetRatio, DEFAULT_TEXT_OFFSET_RATIO, 0.0, 2.0 ) ); @@ -136,15 +137,19 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin &m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) ); m_params.emplace_back( new PARAM_SCALED( "drawing.pin_symbol_size", - &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ), schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ), + &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ), + schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) ); + + m_params.emplace_back( new PARAM_SCALED( "connection_grid_size", + &m_ConnectionGridSize, schIUScale.MilsToIU( DEFAULT_CONNECTION_GRID_MILS ), + schIUScale.MilsToIU( MIN_CONNECTION_GRID_MILS ), schIUScale.MilsToIU( 10000 ), 1 / schIUScale.IU_PER_MILS ) ); // m_JunctionSize is only a run-time cache of the calculated size. Do not save it. // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc ) m_params.emplace_back( new PARAM( "drawing.junction_size_choice", - &m_JunctionSizeChoice, - defaultJunctionSizeChoice ) ); + &m_JunctionSizeChoice, defaultJunctionSizeChoice ) ); m_params.emplace_back( new PARAM_LAMBDA( "drawing.field_names", [&]() -> nlohmann::json diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index c682f880a9..38c14f0936 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -28,6 +28,15 @@ class NGSPICE_SETTINGS; + +// The minimal grid size allowed to place a pin is 25 mils. Tthe best grid size is 50 mils, +// but 25 mils is still usable. +// This is because all symbols are using a 50 mils grid to place pins, and therefore the wires +// must be on the 50 mils grid. +#define MIN_CONNECTION_GRID_MILS 25 +#define DEFAULT_CONNECTION_GRID_MILS 50 + + /** * These settings were stored in SCH_BASE_FRAME previously. * The backing store is currently the project file. @@ -54,6 +63,8 @@ public: int m_JunctionSizeChoice; // none = 0, smallest = 1, small = 2, etc. int m_JunctionSize; // a runtime cache of the calculated size + int m_ConnectionGridSize; // usually 50mils (IU internally; mils in the JSON file) + int m_AnnotateStartNum; // Starting value for annotation bool m_IntersheetRefsShow;