You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 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. #include <drc/drc_engine.h>
  24. #include <drc/drc_item.h>
  25. #include <drc/drc_test_provider.h>
  26. #include <footprint.h>
  27. #include <pad.h>
  28. /*
  29. Footprint tests:
  30. - DRCE_FOOTPRINT_TYPE_MISMATCH,
  31. - DRCE_OVERLAPPING_PADS,
  32. - DRCE_PAD_TH_WITH_NO_HOLE,
  33. - DRCE_PADSTACK,
  34. - DRCE_FOOTPRINT (unknown or duplicate pads in net-tie pad groups),
  35. - DRCE_SHORTING_ITEMS
  36. */
  37. class DRC_TEST_PROVIDER_FOOTPRINT_CHECKS : public DRC_TEST_PROVIDER
  38. {
  39. public:
  40. DRC_TEST_PROVIDER_FOOTPRINT_CHECKS()
  41. {
  42. m_isRuleDriven = false;
  43. }
  44. virtual ~DRC_TEST_PROVIDER_FOOTPRINT_CHECKS()
  45. {
  46. }
  47. virtual bool Run() override;
  48. virtual const wxString GetName() const override
  49. {
  50. return wxT( "footprint checks" );
  51. };
  52. virtual const wxString GetDescription() const override
  53. {
  54. return wxT( "Check for common footprint pad and component type errors" );
  55. }
  56. };
  57. bool DRC_TEST_PROVIDER_FOOTPRINT_CHECKS::Run()
  58. {
  59. if( !reportPhase( _( "Checking footprints..." ) ) )
  60. return false; // DRC cancelled
  61. auto errorHandler =
  62. [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB, const BOARD_ITEM* aItemC,
  63. int aErrorCode, const wxString& aMsg, const VECTOR2I& aPt, PCB_LAYER_ID aLayer )
  64. {
  65. std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( aErrorCode );
  66. if( !aMsg.IsEmpty() )
  67. drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + aMsg );
  68. drcItem->SetItems( aItemA, aItemB, aItemC );
  69. reportViolation( drcItem, aPt, aLayer );
  70. };
  71. for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
  72. {
  73. if( !m_drcEngine->IsErrorLimitExceeded( DRCE_FOOTPRINT_TYPE_MISMATCH ) )
  74. {
  75. footprint->CheckFootprintAttributes(
  76. [&]( const wxString& aMsg )
  77. {
  78. errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_TYPE_MISMATCH,
  79. aMsg, footprint->GetPosition(), footprint->GetLayer() );
  80. } );
  81. }
  82. if( !m_drcEngine->IsErrorLimitExceeded( DRCE_PAD_TH_WITH_NO_HOLE )
  83. || !m_drcEngine->IsErrorLimitExceeded( DRCE_PADSTACK ) )
  84. {
  85. footprint->CheckPads(
  86. [&]( const PAD* aPad, int aErrorCode, const wxString& aMsg )
  87. {
  88. if( !m_drcEngine->IsErrorLimitExceeded( aErrorCode ) )
  89. {
  90. errorHandler( aPad, nullptr, nullptr, aErrorCode, aMsg,
  91. aPad->GetPosition(), aPad->GetPrincipalLayer() );
  92. }
  93. } );
  94. }
  95. // Don't call footprint->CheckShortingPads(). At the board level we know about nets,
  96. // and the pads may have the same net even though they're distinct pads.
  97. if( footprint->IsNetTie() )
  98. {
  99. if( !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS ) )
  100. {
  101. footprint->CheckNetTies(
  102. [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
  103. const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
  104. {
  105. errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
  106. wxEmptyString, aPosition, footprint->GetLayer() );
  107. } );
  108. }
  109. footprint->CheckNetTiePadGroups(
  110. [&]( const wxString& aMsg )
  111. {
  112. errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
  113. footprint->GetPosition(), footprint->GetLayer() );
  114. } );
  115. }
  116. }
  117. return !m_drcEngine->IsCancelled();
  118. }
  119. namespace detail
  120. {
  121. static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_FOOTPRINT_CHECKS> dummy;
  122. }