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.

116 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 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. #ifndef KICAD_TRACKS_CLEANER_H
  24. #define KICAD_TRACKS_CLEANER_H
  25. #include <class_track.h>
  26. class BOARD;
  27. class BOARD_COMMIT;
  28. // Helper class used to clean tracks and vias
  29. class TRACKS_CLEANER
  30. {
  31. public:
  32. TRACKS_CLEANER( EDA_UNITS_T aUnits, BOARD* aPcb, BOARD_COMMIT& aCommit );
  33. /**
  34. * the cleanup function.
  35. * return true if some item was modified
  36. * @param aCleanVias = true to remove superimposed vias
  37. * @param aRemoveMisConnected = true to remove segments connecting 2 different nets
  38. * @param aMergeSegments = true to merge collinear segmenst and remove 0 len segm
  39. * @param aDeleteUnconnected = true to remove dangling tracks
  40. * @param aDeleteTracksinPad = true to remove tracks fully inside pads
  41. * (short circuits)
  42. */
  43. bool CleanupBoard( bool aDryRun, DRC_LIST* aItemsList, bool aCleanVias,
  44. bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected,
  45. bool aDeleteTracksinPad );
  46. private:
  47. /* finds and remove all track segments which are connected to more than one net.
  48. * (short circuits)
  49. */
  50. bool removeBadTrackSegments();
  51. /**
  52. * Checks whether the track is connected to a pad
  53. * @param aTrack pointer to the track
  54. * @return true if the track has a pad
  55. */
  56. bool testTrackHasPad( const TRACK* aTrack ) const;
  57. /**
  58. * Removes redundant vias like vias at same location
  59. * or on pad through
  60. */
  61. bool cleanupVias();
  62. /**
  63. * Removes dangling tracks
  64. */
  65. bool deleteDanglingTracks();
  66. /**
  67. * Removes tracks that are fully inside pads
  68. */
  69. bool deleteTracksInPads();
  70. /// Delete null length track segments
  71. bool deleteNullSegments( TRACKS& aTracks );
  72. /**
  73. * Merge collinear segments and remove duplicated and null len segments
  74. */
  75. bool cleanupSegments();
  76. /**
  77. * helper function
  78. * Rebuild list of tracks, and connected tracks
  79. * this info must be rebuilt when tracks are erased
  80. */
  81. void buildTrackConnectionInfo();
  82. /**
  83. * helper function
  84. * merge aTrackRef and aCandidate, when possible,
  85. * i.e. when they are colinear, same width, and obviously same layer
  86. */
  87. bool mergeCollinearSegments( TRACK* aSeg1, TRACK* aSeg2 );
  88. bool testTrackEndpointDangling( TRACK* aTrack );
  89. EDA_UNITS_T m_units;
  90. BOARD* m_brd;
  91. BOARD_COMMIT& m_commit;
  92. bool m_dryRun;
  93. DRC_LIST* m_itemsList;
  94. bool removeItems( std::set<BOARD_ITEM*>& aItems );
  95. };
  96. #endif //KICAD_TRACKS_CLEANER_H