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.

87 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * @author Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
  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. #include <eda_item.h>
  25. #include "graphics_importer_buffer.h"
  26. using namespace std;
  27. template <typename T, typename... Args>
  28. static std::unique_ptr<T> make_shape( const Args&... aArguments )
  29. {
  30. return std::make_unique<T>( aArguments... );
  31. }
  32. void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth )
  33. {
  34. m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
  35. }
  36. void GRAPHICS_IMPORTER_BUFFER::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled )
  37. {
  38. m_shapes.push_back( make_shape<IMPORTED_CIRCLE>( aCenter, aRadius, aWidth, aFilled ) );
  39. }
  40. void GRAPHICS_IMPORTER_BUFFER::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
  41. double aAngle, double aWidth )
  42. {
  43. m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle, aWidth ) );
  44. }
  45. void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
  46. {
  47. m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices, aWidth ) );
  48. }
  49. void GRAPHICS_IMPORTER_BUFFER::AddText( const VECTOR2D& aOrigin, const wxString& aText,
  50. double aHeight, double aWidth, double aThickness, double aOrientation,
  51. EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify )
  52. {
  53. m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth,
  54. aThickness, aOrientation, aHJustify, aVJustify ) );
  55. }
  56. void GRAPHICS_IMPORTER_BUFFER::AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
  57. const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd , double aWidth )
  58. {
  59. m_shapes.push_back( make_shape< IMPORTED_SPLINE >( aStart, aBezierControl1, aBezierControl2, aEnd, aWidth ) );
  60. }
  61. void GRAPHICS_IMPORTER_BUFFER::AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape )
  62. {
  63. m_shapes.push_back( std::move( aShape ) );
  64. }
  65. void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter )
  66. {
  67. for( auto& shape : m_shapes )
  68. shape->ImportTo( aImporter );
  69. }