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.

150 lines
4.0 KiB

14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file class_pcb_target.cpp
  28. * PCB_TARGET class definition - targets for photo plots, formerly called MIRE (from French 'mire optique')
  29. */
  30. #include <fctsys.h>
  31. #include <gr_basic.h>
  32. #include <common.h>
  33. #include <kicad_string.h>
  34. #include <trigo.h>
  35. #include <macros.h>
  36. #include <richio.h>
  37. #include <bitmaps.h>
  38. #include <pcb_edit_frame.h>
  39. #include <class_board.h>
  40. #include <class_pcb_target.h>
  41. #include <base_units.h>
  42. #include <pgm_base.h>
  43. #include <settings/color_settings.h>
  44. #include <settings/settings_manager.h>
  45. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
  46. BOARD_ITEM( aParent, PCB_TARGET_T )
  47. {
  48. m_Shape = 0;
  49. m_Size = Millimeter2iu( 5 ); // Gives a decent size
  50. m_Width = Millimeter2iu( DEFAULT_COPPER_LINE_WIDTH );
  51. m_Layer = Edge_Cuts; // a target is on all layers
  52. }
  53. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
  54. const wxPoint& aPos, int aSize, int aWidth ) :
  55. BOARD_ITEM( aParent, PCB_TARGET_T )
  56. {
  57. m_Shape = aShape;
  58. m_Layer = aLayer;
  59. m_Pos = aPos;
  60. m_Size = aSize;
  61. m_Width = aWidth;
  62. }
  63. PCB_TARGET::~PCB_TARGET()
  64. {
  65. }
  66. bool PCB_TARGET::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  67. {
  68. int dX = aPosition.x - m_Pos.x;
  69. int dY = aPosition.y - m_Pos.y;
  70. int radius = aAccuracy + ( m_Size / 2 );
  71. return abs( dX ) <= radius && abs( dY ) <= radius;
  72. }
  73. bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  74. {
  75. EDA_RECT arect = aRect;
  76. arect.Inflate( aAccuracy );
  77. if( aContained )
  78. return arect.Contains( GetBoundingBox() );
  79. else
  80. return GetBoundingBox().Intersects( arect );
  81. }
  82. void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
  83. {
  84. RotatePoint( &m_Pos, aRotCentre, aAngle );
  85. }
  86. void PCB_TARGET::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
  87. {
  88. if( aFlipLeftRight )
  89. m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
  90. else
  91. m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
  92. SetLayer( FlipLayer( GetLayer() ) );
  93. }
  94. const EDA_RECT PCB_TARGET::GetBoundingBox() const
  95. {
  96. EDA_RECT bBox;
  97. bBox.SetX( m_Pos.x - m_Size/2 );
  98. bBox.SetY( m_Pos.y - m_Size/2 );
  99. bBox.SetWidth( m_Size );
  100. bBox.SetHeight( m_Size );
  101. return bBox;
  102. }
  103. wxString PCB_TARGET::GetSelectMenuText( EDA_UNITS aUnits ) const
  104. {
  105. // Targets are on *every* layer by definition
  106. return wxString::Format( _( "Target size %s" ), MessageTextFromValue( aUnits, m_Size ) );
  107. }
  108. BITMAP_DEF PCB_TARGET::GetMenuImage() const
  109. {
  110. return add_pcb_target_xpm;
  111. }
  112. EDA_ITEM* PCB_TARGET::Clone() const
  113. {
  114. return new PCB_TARGET( *this );
  115. }
  116. void PCB_TARGET::SwapData( BOARD_ITEM* aImage )
  117. {
  118. assert( aImage->Type() == PCB_TARGET_T );
  119. std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) );
  120. }