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.

208 lines
5.7 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-2012 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 <class_drawpanel.h>
  34. #include <kicad_string.h>
  35. #include <trigo.h>
  36. #include <macros.h>
  37. #include <richio.h>
  38. #include <bitmaps.h>
  39. #include <pcb_edit_frame.h>
  40. #include <class_board.h>
  41. #include <class_pcb_target.h>
  42. #include <base_units.h>
  43. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
  44. BOARD_ITEM( aParent, PCB_TARGET_T )
  45. {
  46. m_Shape = 0;
  47. m_Size = Millimeter2iu( 5 ); // Gives a decent size
  48. m_Width = Millimeter2iu( 0.15 ); // Gives a decent width
  49. m_Layer = Edge_Cuts; // a target is on all layers
  50. }
  51. PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
  52. const wxPoint& aPos, int aSize, int aWidth ) :
  53. BOARD_ITEM( aParent, PCB_TARGET_T )
  54. {
  55. m_Shape = aShape;
  56. m_Layer = aLayer;
  57. m_Pos = aPos;
  58. m_Size = aSize;
  59. m_Width = aWidth;
  60. }
  61. PCB_TARGET::~PCB_TARGET()
  62. {
  63. }
  64. /* Draw PCB_TARGET object: 2 segments + 1 circle
  65. * The circle radius is half the radius of the target
  66. * 2 lines have length the diameter of the target
  67. */
  68. void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
  69. const wxPoint& offset )
  70. {
  71. int radius, ox, oy, width;
  72. int dx1, dx2, dy1, dy2;
  73. ox = m_Pos.x + offset.x;
  74. oy = m_Pos.y + offset.y;
  75. BOARD * brd = GetBoard( );
  76. if( brd->IsLayerVisible( m_Layer ) == false )
  77. return;
  78. auto frame = static_cast<PCB_EDIT_FRAME*> ( panel->GetParent() );
  79. auto gcolor = frame->Settings().Colors().GetLayerColor( m_Layer );
  80. GRSetDrawMode( DC, mode_color );
  81. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
  82. bool filled = displ_opts ? displ_opts->m_DisplayDrawItemsFill : FILLED;
  83. width = m_Width;
  84. radius = m_Size / 3;
  85. if( GetShape() ) // shape X
  86. radius = m_Size / 2;
  87. if( filled )
  88. GRCircle( panel->GetClipBox(), DC, ox, oy, radius, width, gcolor );
  89. else
  90. {
  91. GRCircle( panel->GetClipBox(), DC, ox, oy, radius + (width / 2), gcolor );
  92. GRCircle( panel->GetClipBox(), DC, ox, oy, radius - (width / 2), gcolor );
  93. }
  94. radius = m_Size / 2;
  95. dx1 = radius;
  96. dy1 = 0;
  97. dx2 = 0;
  98. dy2 = radius;
  99. if( GetShape() ) // shape X
  100. {
  101. dx1 = dy1 = radius;
  102. dx2 = dx1;
  103. dy2 = -dy1;
  104. }
  105. if( filled )
  106. {
  107. GRLine( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
  108. GRLine( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
  109. }
  110. else
  111. {
  112. GRCSegm( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
  113. GRCSegm( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
  114. }
  115. }
  116. bool PCB_TARGET::HitTest( const wxPoint& aPosition ) const
  117. {
  118. int dX = aPosition.x - m_Pos.x;
  119. int dY = aPosition.y - m_Pos.y;
  120. int radius = m_Size / 2;
  121. return abs( dX ) <= radius && abs( dY ) <= radius;
  122. }
  123. bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  124. {
  125. EDA_RECT arect = aRect;
  126. arect.Inflate( aAccuracy );
  127. if( aContained )
  128. return arect.Contains( GetBoundingBox() );
  129. else
  130. return GetBoundingBox().Intersects( arect );
  131. }
  132. void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
  133. {
  134. RotatePoint( &m_Pos, aRotCentre, aAngle );
  135. }
  136. void PCB_TARGET::Flip(const wxPoint& aCentre )
  137. {
  138. m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
  139. SetLayer( FlipLayer( GetLayer() ) );
  140. }
  141. const EDA_RECT PCB_TARGET::GetBoundingBox() const
  142. {
  143. EDA_RECT bBox;
  144. bBox.SetX( m_Pos.x - m_Size/2 );
  145. bBox.SetY( m_Pos.y - m_Size/2 );
  146. bBox.SetWidth( m_Size );
  147. bBox.SetHeight( m_Size );
  148. return bBox;
  149. }
  150. wxString PCB_TARGET::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  151. {
  152. // Targets are on *every* layer by definition
  153. return wxString::Format( _( "Target size %s" ), MessageTextFromValue( aUnits, m_Size ) );
  154. }
  155. BITMAP_DEF PCB_TARGET::GetMenuImage() const
  156. {
  157. return add_pcb_target_xpm;
  158. }
  159. EDA_ITEM* PCB_TARGET::Clone() const
  160. {
  161. return new PCB_TARGET( *this );
  162. }
  163. void PCB_TARGET::SwapData( BOARD_ITEM* aImage )
  164. {
  165. assert( aImage->Type() == PCB_TARGET_T );
  166. std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) );
  167. }