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.

173 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <sch_draw_panel.h>
  25. #include <trigo.h>
  26. #include <widgets/msgpanel.h>
  27. #include <bitmaps.h>
  28. #include <base_units.h>
  29. #include <erc_settings.h>
  30. #include <sch_marker.h>
  31. #include <schematic.h>
  32. #include <widgets/ui_common.h>
  33. #include <pgm_base.h>
  34. #include <settings/settings_manager.h>
  35. #include <settings/color_settings.h>
  36. #include <erc_item.h>
  37. /// Factor to convert the maker unit shape to internal units:
  38. #define SCALING_FACTOR Millimeter2iu( 0.15 )
  39. SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const wxPoint& aPos ) :
  40. SCH_ITEM( nullptr, SCH_MARKER_T ),
  41. MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC )
  42. {
  43. if( m_rcItem )
  44. m_rcItem->SetParent( this );
  45. m_Pos = aPos;
  46. }
  47. EDA_ITEM* SCH_MARKER::Clone() const
  48. {
  49. return new SCH_MARKER( *this );
  50. }
  51. void SCH_MARKER::SwapData( SCH_ITEM* aItem )
  52. {
  53. std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
  54. }
  55. #if defined(DEBUG)
  56. void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
  57. {
  58. // for now, make it look like XML:
  59. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
  60. }
  61. #endif
  62. void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
  63. {
  64. aCount = 2;
  65. wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
  66. switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
  67. {
  68. default:
  69. case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
  70. case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
  71. }
  72. aLayers[1] = LAYER_SELECTION_SHADOWS;
  73. }
  74. SCH_LAYER_ID SCH_MARKER::GetColorLayer() const
  75. {
  76. if( IsExcluded() )
  77. return LAYER_HIDDEN;
  78. wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
  79. switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
  80. {
  81. default:
  82. case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_ERC_ERR;
  83. case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_ERC_WARN;
  84. }
  85. }
  86. KIGFX::COLOR4D SCH_MARKER::getColor() const
  87. {
  88. COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
  89. return colors->GetColor( GetColorLayer() );
  90. }
  91. void SCH_MARKER::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
  92. {
  93. PrintMarker( aSettings, aOffset );
  94. }
  95. bool SCH_MARKER::Matches( wxFindReplaceData& aSearchData, void* aAuxData )
  96. {
  97. return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
  98. }
  99. const EDA_RECT SCH_MARKER::GetBoundingBox() const
  100. {
  101. return GetBoundingBoxMarker();
  102. }
  103. void SCH_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
  104. {
  105. aList.push_back( MSG_PANEL_ITEM( _( "Electronics Rule Check Error" ),
  106. m_rcItem->GetErrorMessage(), DARKRED ) );
  107. }
  108. BITMAP_DEF SCH_MARKER::GetMenuImage() const
  109. {
  110. return erc_xpm;
  111. }
  112. void SCH_MARKER::Rotate( wxPoint aPosition )
  113. {
  114. RotatePoint( &m_Pos, aPosition, 900 );
  115. }
  116. void SCH_MARKER::MirrorX( int aXaxis_position )
  117. {
  118. m_Pos.y -= aXaxis_position;
  119. m_Pos.y = -m_Pos.y;
  120. m_Pos.y += aXaxis_position;
  121. }
  122. void SCH_MARKER::MirrorY( int aYaxis_position )
  123. {
  124. m_Pos.x -= aYaxis_position;
  125. m_Pos.x = -m_Pos.x;
  126. m_Pos.x += aYaxis_position;
  127. }
  128. bool SCH_MARKER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  129. {
  130. return HitTestMarker( aPosition, aAccuracy );
  131. }