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.

112 lines
3.7 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 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, std::vector<DRC_ITEM*>* 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. * Removes redundant vias like vias at same location
  53. * or on pad through
  54. */
  55. bool cleanupVias();
  56. /**
  57. * Removes dangling tracks
  58. */
  59. bool deleteDanglingTracks();
  60. /**
  61. * Removes tracks that are fully inside pads
  62. */
  63. bool deleteTracksInPads();
  64. /// Delete null length track segments
  65. bool deleteNullSegments( TRACKS& aTracks );
  66. /**
  67. * Merge collinear segments and remove duplicated and null len segments
  68. */
  69. bool cleanupSegments();
  70. /**
  71. * helper function
  72. * merge aTrackRef and aCandidate, when possible,
  73. * i.e. when they are colinear, same width, and obviously same layer
  74. * @return true if the segments are merged, false if not
  75. * @param aSeg1 is the reference
  76. * @param aSeg2 is the candidate, and after merging, the removed segment
  77. */
  78. bool mergeCollinearSegments( TRACK* aSeg1, TRACK* aSeg2 );
  79. /**
  80. * @return true if a track end position is a node, i.e. a end connected
  81. * to more than one item.
  82. * @param aTrack is the track to test.
  83. * @param aTstStart = true ot test the start point of the track, and false to
  84. * test the end point
  85. */
  86. bool testTrackEndpointIsNode( TRACK* aTrack, bool aTstStart );
  87. EDA_UNITS m_units;
  88. BOARD* m_brd;
  89. BOARD_COMMIT& m_commit;
  90. bool m_dryRun;
  91. std::vector<DRC_ITEM*>* m_itemsList;
  92. bool removeItems( std::set<BOARD_ITEM*>& aItems );
  93. };
  94. #endif //KICAD_TRACKS_CLEANER_H