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.

160 lines
5.0 KiB

18 years ago
18 years ago
18 years ago
18 years ago
14 years ago
  1. /**
  2. * @file class_marker_pcb.cpp
  3. * @brief Functions to handle markers used to show something (usually a drc problem)
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  9. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  10. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, you may find one here:
  24. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. * or you may search the http://www.gnu.org website for the version 2 license,
  26. * or you may write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <class_drawpanel.h>
  32. #include <trigo.h>
  33. #include <msgpanel.h>
  34. #include <bitmaps.h>
  35. #include <base_units.h>
  36. #include <pcbnew.h>
  37. #include <class_marker_pcb.h>
  38. #include <layers_id_colors_and_visibility.h>
  39. /// Factor to convert the maker unit shape to internal units:
  40. #define SCALING_FACTOR Millimeter2iu( 0.1 )
  41. MARKER_PCB::MARKER_PCB( BOARD_ITEM* aParent ) :
  42. BOARD_ITEM( aParent, PCB_MARKER_T ),
  43. MARKER_BASE( SCALING_FACTOR ), m_item( nullptr )
  44. {
  45. m_Color = WHITE;
  46. }
  47. MARKER_PCB::MARKER_PCB( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
  48. BOARD_ITEM* aItem, const wxPoint& aPos,
  49. BOARD_ITEM* bItem, const wxPoint& bPos ) :
  50. BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
  51. MARKER_BASE( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos, SCALING_FACTOR ), m_item( nullptr )
  52. {
  53. m_Color = WHITE;
  54. }
  55. MARKER_PCB::MARKER_PCB( int aErrorCode, const wxPoint& aMarkerPos,
  56. const wxString& aText, const wxPoint& aPos,
  57. const wxString& bText, const wxPoint& bPos ) :
  58. BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
  59. MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos, bText, bPos, SCALING_FACTOR ), m_item( nullptr )
  60. {
  61. m_Color = WHITE;
  62. }
  63. /* destructor */
  64. MARKER_PCB::~MARKER_PCB()
  65. {
  66. }
  67. /* tests to see if this object is on the given layer.
  68. * DRC markers are not really on a copper layer, but
  69. * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
  70. * because this test is often used to locad a marker
  71. * param aLayer The layer to test for.
  72. * return bool - true if on given layer, else false.
  73. */
  74. bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
  75. {
  76. return IsCopperLayer( aLayer );
  77. }
  78. void MARKER_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
  79. {
  80. wxString errorTxt, txtA, txtB;
  81. aList.emplace_back( MSG_PANEL_ITEM( _( "Type" ), _( "Marker" ), DARKCYAN ) );
  82. errorTxt.Printf( _( "ErrType (%d)- %s:" ), m_drc.GetErrorCode(), m_drc.GetErrorText() );
  83. aList.emplace_back( MSG_PANEL_ITEM( errorTxt, wxEmptyString, RED ) );
  84. txtA.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointA() ), m_drc.GetTextA() );
  85. if( m_drc.HasSecondItem() )
  86. txtB.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointB() ), m_drc.GetTextB() );
  87. aList.emplace_back( MSG_PANEL_ITEM( txtA, txtB, DARKBROWN ) );
  88. }
  89. void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
  90. {
  91. RotatePoint( &m_Pos, aRotCentre, aAngle );
  92. }
  93. void MARKER_PCB::Flip(const wxPoint& aCentre )
  94. {
  95. m_Pos.y = aCentre.y - (m_Pos.y - aCentre.y);
  96. }
  97. wxString MARKER_PCB::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  98. {
  99. return wxString::Format( _( "Marker @(%s, %s)" ),
  100. MessageTextFromValue( aUnits, m_Pos.x ),
  101. MessageTextFromValue( aUnits, m_Pos.y ) );
  102. }
  103. BITMAP_DEF MARKER_PCB::GetMenuImage() const
  104. {
  105. return drc_xpm;
  106. }
  107. void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
  108. {
  109. aCount = 1;
  110. aLayers[0] = LAYER_DRC;
  111. }
  112. const EDA_RECT MARKER_PCB::GetBoundingBox() const
  113. {
  114. EDA_RECT bbox = m_ShapeBoundingBox;
  115. wxPoint pos = m_Pos;
  116. pos.x += int( bbox.GetOrigin().x * MarkerScale() );
  117. pos.y += int( bbox.GetOrigin().y * MarkerScale() );
  118. return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
  119. int( bbox.GetHeight() * MarkerScale() ) ) );
  120. }
  121. const BOX2I MARKER_PCB::ViewBBox() const
  122. {
  123. EDA_RECT bbox = GetBoundingBox();
  124. return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
  125. }