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.

180 lines
5.4 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, jp.charras at wanadoo.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-2020 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. #include <bitmaps.h>
  27. #include <board.h>
  28. #include <board_design_settings.h>
  29. #include <pcb_target.h>
  30. #include <base_units.h>
  31. #include <settings/color_settings.h>
  32. #include <settings/settings_manager.h>
  33. #include <trigo.h>
  34. #include <i18n_utility.h>
  35. #include <geometry/shape_circle.h>
  36. #include <eda_draw_frame.h>
  37. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
  38. BOARD_ITEM( aParent, PCB_TARGET_T )
  39. {
  40. m_shape = 0;
  41. m_size = Millimeter2iu( 5 ); // Gives a decent size
  42. m_lineWidth = Millimeter2iu( DEFAULT_COPPER_LINE_WIDTH );
  43. m_layer = Edge_Cuts; // a target is on all layers
  44. }
  45. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
  46. const wxPoint& aPos, int aSize, int aWidth ) :
  47. BOARD_ITEM( aParent, PCB_TARGET_T )
  48. {
  49. m_shape = aShape;
  50. m_layer = aLayer;
  51. m_pos = aPos;
  52. m_size = aSize;
  53. m_lineWidth = aWidth;
  54. }
  55. PCB_TARGET::~PCB_TARGET()
  56. {
  57. }
  58. bool PCB_TARGET::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  59. {
  60. int dX = aPosition.x - m_pos.x;
  61. int dY = aPosition.y - m_pos.y;
  62. int radius = aAccuracy + ( m_size / 2 );
  63. return abs( dX ) <= radius && abs( dY ) <= radius;
  64. }
  65. bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  66. {
  67. EDA_RECT arect = aRect;
  68. arect.Inflate( aAccuracy );
  69. if( aContained )
  70. return arect.Contains( GetBoundingBox() );
  71. else
  72. return GetBoundingBox().Intersects( arect );
  73. }
  74. void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
  75. {
  76. RotatePoint( &m_pos, aRotCentre, aAngle );
  77. }
  78. void PCB_TARGET::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
  79. {
  80. if( aFlipLeftRight )
  81. m_pos.x = aCentre.x - ( m_pos.x - aCentre.x );
  82. else
  83. m_pos.y = aCentre.y - ( m_pos.y - aCentre.y );
  84. SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
  85. }
  86. const EDA_RECT PCB_TARGET::GetBoundingBox() const
  87. {
  88. EDA_RECT bBox;
  89. bBox.SetX( m_pos.x - m_size / 2 );
  90. bBox.SetY( m_pos.y - m_size / 2 );
  91. bBox.SetWidth( m_size );
  92. bBox.SetHeight( m_size );
  93. return bBox;
  94. }
  95. std::shared_ptr<SHAPE> PCB_TARGET::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
  96. {
  97. return std::make_shared<SHAPE_CIRCLE>( m_pos, m_size / 2 );
  98. }
  99. wxString PCB_TARGET::GetSelectMenuText( EDA_UNITS aUnits ) const
  100. {
  101. // Targets are on *every* layer by definition
  102. return _( "Target" );
  103. }
  104. BITMAPS PCB_TARGET::GetMenuImage() const
  105. {
  106. return BITMAPS::add_pcb_target;
  107. }
  108. EDA_ITEM* PCB_TARGET::Clone() const
  109. {
  110. return new PCB_TARGET( *this );
  111. }
  112. void PCB_TARGET::SwapData( BOARD_ITEM* aImage )
  113. {
  114. assert( aImage->Type() == PCB_TARGET_T );
  115. std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) );
  116. }
  117. void PCB_TARGET::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  118. {
  119. EDA_UNITS units = aFrame->GetUserUnits();
  120. aList.emplace_back( _( "PCB Target" ), wxEmptyString );
  121. aList.emplace_back( _( "Layer" ), GetLayerName() );
  122. aList.emplace_back( _( "Size" ), MessageTextFromValue( units, GetSize() ) );
  123. aList.emplace_back( _( "Width" ), MessageTextFromValue( units, GetWidth() ) );
  124. aList.emplace_back( _( "Shape" ), GetShape() == 0 ? "+" : "X" );
  125. }
  126. static struct PCB_TARGET_DESC
  127. {
  128. PCB_TARGET_DESC()
  129. {
  130. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  131. REGISTER_TYPE( PCB_TARGET );
  132. propMgr.InheritsAfter( TYPE_HASH( PCB_TARGET ), TYPE_HASH( BOARD_ITEM ) );
  133. propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _HKI( "Size" ),
  134. &PCB_TARGET::SetSize, &PCB_TARGET::GetSize, PROPERTY_DISPLAY::DISTANCE ) );
  135. propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _HKI( "Width" ),
  136. &PCB_TARGET::SetWidth, &PCB_TARGET::GetWidth, PROPERTY_DISPLAY::DISTANCE ) );
  137. auto shape = new PROPERTY<PCB_TARGET, int>( _HKI( "Shape" ),
  138. &PCB_TARGET::SetShape, &PCB_TARGET::GetShape );
  139. // TODO change the integer to an enum?
  140. //shape->SetValues( { { 0, _HKI( "Cross" ) }, { 1, ( "Plus" ) } } );
  141. propMgr.AddProperty( shape );
  142. }
  143. } _PCB_TARGET_DESC;