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.

134 lines
4.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @brief Implement a very basic GAL used to draw, plot and convert texts in segments
  26. * for DRC functions, using the common GAL functions.
  27. * Draw functions use wxDC.
  28. * Plot functions use a PLOTTER
  29. * Convert texts in segments use a callback function created by the caller
  30. * @file basic_gal.cpp
  31. */
  32. #include <gr_basic.h>
  33. #include <plotter.h>
  34. #include <trigo.h>
  35. #include <basic_gal.h>
  36. using namespace KIGFX;
  37. KIGFX::GAL_DISPLAY_OPTIONS basic_displayOptions;
  38. // the basic GAL doesn't get an external display option object
  39. BASIC_GAL basic_gal( basic_displayOptions );
  40. const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const
  41. {
  42. VECTOR2D point = aPoint + m_transform.m_moveOffset - m_transform.m_rotCenter;
  43. point = point.Rotate( m_transform.m_rotAngle ) + m_transform.m_rotCenter;
  44. return point;
  45. }
  46. void BASIC_GAL::DrawPolyline( const std::deque<VECTOR2D>& aPointList )
  47. {
  48. if( aPointList.empty() )
  49. return;
  50. std::deque<VECTOR2D>::const_iterator it = aPointList.begin();
  51. std::vector <wxPoint> polyline_corners;
  52. for( ; it != aPointList.end(); ++it )
  53. {
  54. VECTOR2D corner = transform(*it);
  55. polyline_corners.push_back( wxPoint( corner.x, corner.y ) );
  56. }
  57. if( m_DC )
  58. {
  59. if( isFillEnabled )
  60. {
  61. GRPoly( m_isClipped ? &m_clipBox : NULL, m_DC, polyline_corners.size(),
  62. &polyline_corners[0], 0, GetLineWidth(), m_Color, m_Color );
  63. }
  64. else
  65. {
  66. for( unsigned ii = 1; ii < polyline_corners.size(); ++ii )
  67. {
  68. GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, polyline_corners[ii-1],
  69. polyline_corners[ii], GetLineWidth(), m_Color );
  70. }
  71. }
  72. }
  73. else if( m_plotter )
  74. {
  75. m_plotter->MoveTo( polyline_corners[0] );
  76. for( unsigned ii = 1; ii < polyline_corners.size(); ii++ )
  77. {
  78. m_plotter->LineTo( polyline_corners[ii] );
  79. }
  80. m_plotter->PenFinish();
  81. }
  82. else if( m_callback )
  83. {
  84. for( unsigned ii = 1; ii < polyline_corners.size(); ii++ )
  85. {
  86. m_callback( polyline_corners[ii-1].x, polyline_corners[ii-1].y,
  87. polyline_corners[ii].x, polyline_corners[ii].y );
  88. }
  89. }
  90. }
  91. void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
  92. {
  93. VECTOR2D startVector = transform( aStartPoint );
  94. VECTOR2D endVector = transform( aEndPoint );
  95. if( m_DC )
  96. {
  97. if( isFillEnabled )
  98. {
  99. GRLine( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
  100. endVector.x, endVector.y, GetLineWidth(), m_Color );
  101. }
  102. else
  103. {
  104. GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
  105. endVector.x, endVector.y, GetLineWidth(), 0, m_Color );
  106. }
  107. }
  108. else if( m_plotter )
  109. {
  110. m_plotter->MoveTo( wxPoint( startVector.x, startVector.y ) );
  111. m_plotter->LineTo( wxPoint( endVector.x, endVector.y ) );
  112. m_plotter->PenFinish();
  113. }
  114. else if( m_callback )
  115. {
  116. m_callback( startVector.x, startVector.y,
  117. endVector.x, endVector.y );
  118. }
  119. }