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.

168 lines
4.1 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-2017 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. /**
  25. * @file sch_marker.cpp
  26. * @brief Class SCH_MARKER implementation
  27. */
  28. #include <fctsys.h>
  29. #include <sch_draw_panel.h>
  30. #include <trigo.h>
  31. #include <msgpanel.h>
  32. #include <bitmaps.h>
  33. #include <sch_marker.h>
  34. #include <erc.h>
  35. SCH_MARKER::SCH_MARKER() : SCH_ITEM( NULL, SCH_MARKER_T ), MARKER_BASE()
  36. {
  37. m_ScalingFactor = 8;
  38. }
  39. SCH_MARKER::SCH_MARKER( const wxPoint& pos, const wxString& text ) :
  40. SCH_ITEM( NULL, SCH_MARKER_T ),
  41. MARKER_BASE( 0, pos, text, pos )
  42. {
  43. m_ScalingFactor = 8;
  44. }
  45. EDA_ITEM* SCH_MARKER::Clone() const
  46. {
  47. return new SCH_MARKER( *this );
  48. }
  49. #if defined(DEBUG)
  50. void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
  51. {
  52. // for now, make it look like XML:
  53. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
  54. << GetPos() << "/>\n";
  55. }
  56. #endif
  57. void SCH_MARKER::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  58. const wxPoint& aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor )
  59. {
  60. COLOR4D color = m_Color;
  61. COLOR4D tmp = color;
  62. if( GetMarkerType() == MARKER_BASE::MARKER_ERC )
  63. {
  64. color = ( GetErrorLevel() == MARKER_BASE::MARKER_SEVERITY_ERROR ) ?
  65. GetLayerColor( LAYER_ERC_ERR ) : GetLayerColor( LAYER_ERC_WARN );
  66. }
  67. if( aColor == COLOR4D::UNSPECIFIED )
  68. m_Color = color;
  69. else
  70. m_Color = aColor;
  71. DrawMarker( aPanel, aDC, aDrawMode, aOffset );
  72. m_Color = tmp;
  73. }
  74. bool SCH_MARKER::Matches( wxFindReplaceData& aSearchData, void* aAuxData,
  75. wxPoint * aFindLocation )
  76. {
  77. if( SCH_ITEM::Matches( m_drc.GetErrorText(), aSearchData ) ||
  78. SCH_ITEM::Matches( m_drc.GetMainText(), aSearchData ) ||
  79. SCH_ITEM::Matches( m_drc.GetAuxiliaryText(), aSearchData ) )
  80. {
  81. if( aFindLocation )
  82. *aFindLocation = m_Pos;
  83. return true;
  84. }
  85. return false;
  86. }
  87. const EDA_RECT SCH_MARKER::GetBoundingBox() const
  88. {
  89. return GetBoundingBoxMarker();
  90. }
  91. void SCH_MARKER::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
  92. {
  93. aList.push_back( MSG_PANEL_ITEM( _( "Electronics Rule Check Error" ),
  94. GetReporter().GetErrorText(), DARKRED ) );
  95. }
  96. BITMAP_DEF SCH_MARKER::GetMenuImage() const
  97. {
  98. return erc_xpm;
  99. }
  100. void SCH_MARKER::Rotate( wxPoint aPosition )
  101. {
  102. RotatePoint( &m_Pos, aPosition, 900 );
  103. }
  104. void SCH_MARKER::MirrorX( int aXaxis_position )
  105. {
  106. m_Pos.y -= aXaxis_position;
  107. m_Pos.y = -m_Pos.y;
  108. m_Pos.y += aXaxis_position;
  109. }
  110. void SCH_MARKER::MirrorY( int aYaxis_position )
  111. {
  112. m_Pos.x -= aYaxis_position;
  113. m_Pos.x = -m_Pos.x;
  114. m_Pos.x += aYaxis_position;
  115. }
  116. bool SCH_MARKER::IsSelectStateChanged( const wxRect& aRect )
  117. {
  118. bool previousState = IsSelected();
  119. if( aRect.Contains( m_Pos ) )
  120. SetFlags( SELECTED );
  121. else
  122. ClearFlags( SELECTED );
  123. return previousState != IsSelected();
  124. }
  125. bool SCH_MARKER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  126. {
  127. return HitTestMarker( aPosition );
  128. }