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.

144 lines
4.7 KiB

8 years ago
  1. /**
  2. * @file drc_marker_functions.cpp
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2010 Dick Hollenbeck, dick@softplc.com
  8. * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  9. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. /* Methods of class DRC to initialize drc markers with messages
  29. * according to items and error code
  30. */
  31. #include <fctsys.h>
  32. #include <common.h>
  33. #include <pcbnew.h>
  34. #include <board_design_settings.h>
  35. #include <geometry/geometry_utils.h>
  36. #include <pcb_edit_frame.h>
  37. #include <drc.h>
  38. #include <class_pad.h>
  39. #include <class_track.h>
  40. #include <class_zone.h>
  41. #include <class_marker_pcb.h>
  42. #include <class_pcb_text.h>
  43. #include <class_text_mod.h>
  44. #include <class_edge_mod.h>
  45. #include <class_board_item.h>
  46. const int EPSILON = Mils2iu( 5 );
  47. MARKER_PCB* DRC::newMarker( TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode )
  48. {
  49. auto conflictOutline = const_cast<SHAPE_POLY_SET*>( &aConflictZone->GetFilledPolysList() );
  50. wxPoint markerPos;
  51. wxPoint pt1 = aTrack->GetPosition();
  52. wxPoint pt2 = aTrack->GetEnd();
  53. // If the mid-point is in the zone, then that's a fine place for the marker
  54. if( conflictOutline->Distance( ( pt1 + pt2 ) / 2 ) == 0 )
  55. markerPos = ( pt1 + pt2 ) / 2;
  56. // Otherwise do a binary search for a "good enough" marker location
  57. else
  58. {
  59. while( GetLineLength( pt1, pt2 ) > EPSILON )
  60. {
  61. if( conflictOutline->Distance( pt1 ) < conflictOutline->Distance( pt2 ) )
  62. pt2 = ( pt1 + pt2 ) / 2;
  63. else
  64. pt1 = ( pt1 + pt2 ) / 2;
  65. }
  66. // Once we're within EPSILON pt1 and pt2 are "equivalent"
  67. markerPos = pt1;
  68. }
  69. return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
  70. aTrack, aTrack->GetPosition(),
  71. aConflictZone, aConflictZone->GetPosition() );
  72. }
  73. MARKER_PCB* DRC::newMarker( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg,
  74. int aErrorCode )
  75. {
  76. wxPoint markerPos;
  77. wxPoint pt1 = aTrack->GetPosition();
  78. wxPoint pt2 = aTrack->GetEnd();
  79. // Do a binary search along the track for a "good enough" marker location
  80. while( GetLineLength( pt1, pt2 ) > EPSILON )
  81. {
  82. if( aConflictSeg.Distance( pt1 ) < aConflictSeg.Distance( pt2 ) )
  83. pt2 = ( pt1 + pt2 ) / 2;
  84. else
  85. pt1 = ( pt1 + pt2 ) / 2;
  86. }
  87. // Once we're within EPSILON pt1 and pt2 are "equivalent"
  88. markerPos = pt1;
  89. return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
  90. aTrack, aTrack->GetPosition(),
  91. aConflitItem, aConflitItem->GetPosition() );
  92. }
  93. MARKER_PCB* DRC::newMarker( D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode )
  94. {
  95. return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPad->GetPosition(),
  96. aPad, aPad->GetPosition(),
  97. aConflictItem, aConflictItem->GetPosition() );
  98. }
  99. MARKER_PCB* DRC::newMarker(const wxPoint &aPos, BOARD_ITEM *aItem, int aErrorCode )
  100. {
  101. return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
  102. aItem, aItem->GetPosition(), nullptr, wxPoint() );
  103. }
  104. MARKER_PCB* DRC::newMarker( const wxPoint &aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
  105. int aErrorCode )
  106. {
  107. return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
  108. aItem, aItem->GetPosition(), bItem, bItem->GetPosition() );
  109. }
  110. MARKER_PCB* DRC::newMarker( int aErrorCode, const wxString& aMessage )
  111. {
  112. MARKER_PCB* marker = new MARKER_PCB( aErrorCode, wxPoint(), aMessage, wxPoint() );
  113. marker->SetShowNoCoordinate();
  114. return marker;
  115. }