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.

282 lines
7.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <base_units.h>
  27. #include <eda_draw_frame.h>
  28. #include <board.h>
  29. #include <board_design_settings.h>
  30. #include <pcb_marker.h>
  31. #include <layer_ids.h>
  32. #include <settings/color_settings.h>
  33. #include <settings/settings_manager.h>
  34. #include <geometry/shape_null.h>
  35. #include <widgets/ui_common.h>
  36. #include <pgm_base.h>
  37. #include <drc/drc_item.h>
  38. #include <trigo.h>
  39. /// Factor to convert the maker unit shape to internal units:
  40. #define SCALING_FACTOR Millimeter2iu( 0.1625 )
  41. PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const VECTOR2I& aPosition,
  42. PCB_LAYER_ID aLayer ) :
  43. BOARD_ITEM( nullptr, PCB_MARKER_T, aLayer ), // parent set during BOARD::Add()
  44. MARKER_BASE( SCALING_FACTOR, aItem )
  45. {
  46. if( m_rcItem )
  47. {
  48. m_rcItem->SetParent( this );
  49. switch( m_rcItem->GetErrorCode() )
  50. {
  51. case DRCE_UNCONNECTED_ITEMS:
  52. SetMarkerType( MARKER_BASE::MARKER_RATSNEST );
  53. break;
  54. case DRCE_MISSING_FOOTPRINT:
  55. case DRCE_DUPLICATE_FOOTPRINT:
  56. case DRCE_EXTRA_FOOTPRINT:
  57. case DRCE_NET_CONFLICT:
  58. SetMarkerType( MARKER_BASE::MARKER_PARITY );
  59. break;
  60. default:
  61. SetMarkerType( MARKER_BASE::MARKER_DRC );
  62. break;
  63. }
  64. }
  65. m_Pos = aPosition;
  66. }
  67. /* destructor */
  68. PCB_MARKER::~PCB_MARKER()
  69. {
  70. if( m_rcItem )
  71. m_rcItem->SetParent( nullptr );
  72. }
  73. wxString PCB_MARKER::Serialize() const
  74. {
  75. wxString lastItem;
  76. if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
  77. lastItem = LayerName( m_layer );
  78. else
  79. lastItem = m_rcItem->GetAuxItemID().AsString();
  80. return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
  81. m_rcItem->GetSettingsKey(),
  82. m_Pos.x,
  83. m_Pos.y,
  84. m_rcItem->GetMainItemID().AsString(),
  85. lastItem );
  86. }
  87. PCB_MARKER* PCB_MARKER::Deserialize( const wxString& data )
  88. {
  89. wxArrayString props = wxSplit( data, '|' );
  90. PCB_LAYER_ID markerLayer = F_Cu;
  91. VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
  92. (int) strtol( props[2].c_str(), nullptr, 10 ) );
  93. std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
  94. if( !drcItem )
  95. return nullptr;
  96. if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
  97. {
  98. drcItem->SetItems( KIID( props[3] ) );
  99. for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
  100. {
  101. if( LayerName( ToLAYER_ID( layer ) ) == props[4] )
  102. {
  103. markerLayer = ToLAYER_ID( layer );
  104. break;
  105. }
  106. }
  107. }
  108. else
  109. {
  110. drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
  111. }
  112. return new PCB_MARKER( drcItem, markerPos, markerLayer );
  113. }
  114. void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  115. {
  116. aList.emplace_back( _( "Type" ), _( "Marker" ) );
  117. aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
  118. aList.emplace_back( _( "Severity" ), GetSeverity() == RPT_SEVERITY_ERROR ? _( "Error" )
  119. : _( "Warning" ) );
  120. wxString mainText;
  121. wxString auxText;
  122. EDA_ITEM* mainItem = nullptr;
  123. EDA_ITEM* auxItem = nullptr;
  124. if( m_rcItem->GetMainItemID() != niluuid )
  125. mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
  126. if( m_rcItem->GetAuxItemID() != niluuid )
  127. auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
  128. if( mainItem )
  129. mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
  130. if( auxItem )
  131. auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
  132. aList.emplace_back( mainText, auxText );
  133. }
  134. void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  135. {
  136. // Marker geometry isn't user-editable
  137. }
  138. void PCB_MARKER::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  139. {
  140. // Marker geometry isn't user-editable
  141. }
  142. std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  143. {
  144. // Markers do not participate in the board geometry space, and therefore have no
  145. // effectiven shape.
  146. return std::make_shared<SHAPE_NULL>();
  147. }
  148. wxString PCB_MARKER::GetSelectMenuText( EDA_UNITS aUnits ) const
  149. {
  150. // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
  151. // for menu duty.
  152. return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
  153. }
  154. BITMAPS PCB_MARKER::GetMenuImage() const
  155. {
  156. return BITMAPS::drc;
  157. }
  158. SEVERITY PCB_MARKER::GetSeverity() const
  159. {
  160. if( IsExcluded() )
  161. return RPT_SEVERITY_EXCLUSION;
  162. DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
  163. DRC_RULE* rule = item->GetViolatingRule();
  164. if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
  165. return rule->m_Severity;
  166. return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
  167. }
  168. void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
  169. {
  170. if( GetMarkerType() == MARKER_RATSNEST )
  171. {
  172. aCount = 0;
  173. return;
  174. }
  175. aCount = 2;
  176. aLayers[1] = LAYER_MARKER_SHADOWS;
  177. switch( GetSeverity() )
  178. {
  179. default:
  180. case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
  181. case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
  182. case SEVERITY::RPT_SEVERITY_EXCLUSION: aLayers[0] = LAYER_DRC_EXCLUSION; break;
  183. }
  184. }
  185. GAL_LAYER_ID PCB_MARKER::GetColorLayer() const
  186. {
  187. switch( GetSeverity() )
  188. {
  189. default:
  190. case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_DRC_ERROR;
  191. case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_DRC_WARNING;
  192. case SEVERITY::RPT_SEVERITY_EXCLUSION: return LAYER_DRC_EXCLUSION;
  193. }
  194. }
  195. KIGFX::COLOR4D PCB_MARKER::getColor() const
  196. {
  197. COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
  198. return colors->GetColor( GetColorLayer() );
  199. }
  200. void PCB_MARKER::SetZoom( double aZoomFactor )
  201. {
  202. SetMarkerScale( SCALING_FACTOR * aZoomFactor );
  203. }
  204. const EDA_RECT PCB_MARKER::GetBoundingBox() const
  205. {
  206. EDA_RECT bbox = m_shapeBoundingBox;
  207. VECTOR2I pos = m_Pos;
  208. pos.x += int( bbox.GetOrigin().x * MarkerScale() );
  209. pos.y += int( bbox.GetOrigin().y * MarkerScale() );
  210. return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
  211. int( bbox.GetHeight() * MarkerScale() ) ) );
  212. }
  213. const BOX2I PCB_MARKER::ViewBBox() const
  214. {
  215. EDA_RECT bbox = GetBoundingBox();
  216. return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
  217. }