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.

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