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.

166 lines
4.8 KiB

8 years ago
14 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 <drc.h>
  36. #include <class_pad.h>
  37. #include <class_track.h>
  38. #include <class_zone.h>
  39. #include <class_marker_pcb.h>
  40. #include <class_pcb_text.h>
  41. #include <class_board_item.h>
  42. MARKER_PCB* DRC::fillMarker( TRACK* aTrack, BOARD_ITEM* bItem, int aErrorCode, MARKER_PCB* fillMe )
  43. {
  44. wxPoint posA;
  45. wxPoint posB = wxPoint();
  46. if( bItem ) // aItem might be NULL
  47. {
  48. if( bItem->Type() == PCB_PAD_T )
  49. {
  50. posB = posA = ((D_PAD*)bItem)->GetPosition();
  51. }
  52. else if( bItem->Type() == PCB_VIA_T )
  53. {
  54. posB = posA = ((VIA*)bItem)->GetPosition();
  55. }
  56. else if( bItem->Type() == PCB_TRACE_T )
  57. {
  58. TRACK* track = (TRACK*) bItem;
  59. posB = track->GetPosition();
  60. wxPoint endPos = track->GetEnd();
  61. // either of aItem's start or end will be used for the marker position
  62. // first assume start, then switch at end if needed. decision made on
  63. // distance from end of aTrack.
  64. posA = track->GetStart();
  65. double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
  66. double dToStart = GetLineLength( posA, aTrack->GetEnd() );
  67. if( dToEnd < dToStart )
  68. posA = endPos;
  69. }
  70. else if( bItem->Type() == PCB_TEXT_T )
  71. {
  72. posA = aTrack->GetPosition();
  73. posB = ((TEXTE_PCB*) bItem)->GetPosition();
  74. }
  75. }
  76. else
  77. posA = aTrack->GetPosition();
  78. if( fillMe )
  79. fillMe->SetData( m_units, aErrorCode, posA, aTrack, aTrack->GetPosition(), bItem, posB );
  80. else
  81. fillMe = new MARKER_PCB( m_units, aErrorCode, posA, aTrack, aTrack->GetPosition(), bItem, posB );
  82. return fillMe;
  83. }
  84. MARKER_PCB* DRC::fillMarker( D_PAD* aPad, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe )
  85. {
  86. wxPoint posA = aPad->GetPosition();
  87. wxPoint posB;
  88. if( aItem )
  89. {
  90. switch( aItem->Type() )
  91. {
  92. case PCB_PAD_T:
  93. posB = ((D_PAD*)aItem)->GetPosition();
  94. break;
  95. case PCB_TEXT_T:
  96. posB = ((TEXTE_PCB*)aItem)->GetPosition();
  97. break;
  98. default:
  99. wxLogDebug( wxT("fillMarker: unsupported item") );
  100. break;
  101. }
  102. }
  103. if( fillMe )
  104. fillMe->SetData( m_units, aErrorCode, posA, aPad, posA, aItem, posB );
  105. else
  106. fillMe = new MARKER_PCB( m_units, aErrorCode, posA, aPad, posA, aItem, posB );
  107. return fillMe;
  108. }
  109. MARKER_PCB* DRC::fillMarker(BOARD_ITEM *aItem, const wxPoint &aPos, int aErrorCode,
  110. MARKER_PCB *fillMe)
  111. {
  112. return fillMarker(aPos, aItem, nullptr, aErrorCode, fillMe );
  113. }
  114. MARKER_PCB* DRC::fillMarker( const wxPoint& aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
  115. int aErrorCode, MARKER_PCB* fillMe )
  116. {
  117. if( fillMe )
  118. fillMe->SetData( m_units, aErrorCode, aPos, aItem, aPos, bItem, aPos );
  119. else
  120. fillMe = new MARKER_PCB( m_units, aErrorCode, aPos, aItem, aPos, bItem, aPos );
  121. return fillMe;
  122. }
  123. MARKER_PCB* DRC::fillMarker( int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe )
  124. {
  125. wxPoint posA; // not displayed
  126. if( fillMe )
  127. fillMe->SetData( aErrorCode, posA, aMessage, posA );
  128. else
  129. fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );
  130. fillMe->SetShowNoCoordinate();
  131. return fillMe;
  132. }