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.

140 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 CERN
  5. * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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. #ifndef GRAPHICS_IMPORT_PLUGIN_H
  27. #define GRAPHICS_IMPORT_PLUGIN_H
  28. #include <math/box2.h>
  29. #include <wildcards_and_files_ext.h>
  30. #include <wx/arrstr.h>
  31. class GRAPHICS_IMPORTER;
  32. /**
  33. * Interface for vector graphics import plugins.
  34. */
  35. class GRAPHICS_IMPORT_PLUGIN
  36. {
  37. public:
  38. virtual ~GRAPHICS_IMPORT_PLUGIN() { }
  39. /**
  40. * Set the receiver of the imported shapes.
  41. */
  42. virtual void SetImporter( GRAPHICS_IMPORTER* aImporter ) { m_importer = aImporter; }
  43. /**
  44. * Return the plugin name.
  45. *
  46. * This string will be used as the description in the file dialog.
  47. */
  48. virtual const wxString GetName() const = 0;
  49. /**
  50. * Return a vector of the file extensions handled by this plugin.
  51. */
  52. virtual const std::vector<std::string> GetFileExtensions() const = 0;
  53. /**
  54. * Return a list of wildcards that contains the file extensions
  55. * handled by this plugin, separated with a semi-colon.
  56. */
  57. wxString GetWildcards() const
  58. {
  59. wxString ret;
  60. bool first = true;
  61. for( const auto& extension : GetFileExtensions() )
  62. {
  63. if( first )
  64. first = false;
  65. else
  66. ret += wxT( ";" );
  67. ret += wxT( "*." ) + formatWildcardExt( extension );
  68. }
  69. return ret;
  70. }
  71. /**
  72. * Load file for import.
  73. *
  74. * It is necessary to have the GRAPHICS_IMPORTER object set before.
  75. */
  76. virtual bool Load( const wxString& aFileName ) = 0;
  77. /**
  78. * Set memory buffer with content for import.
  79. *
  80. * It is necessary to have the GRAPHICS_IMPORTER object set before.
  81. */
  82. virtual bool LoadFromMemory( const wxMemoryBuffer& aMemBuffer ) = 0;
  83. /**
  84. * Return image height from original imported file.
  85. *
  86. * @return Original Image height in mm.
  87. */
  88. virtual double GetImageHeight() const = 0;
  89. /**
  90. * Return image width from original imported file.
  91. *
  92. * @return Original Image width in mm.
  93. */
  94. virtual double GetImageWidth() const = 0;
  95. /**
  96. * Return image bounding box from original imported file.
  97. *
  98. * @return Image bounding box.
  99. */
  100. virtual BOX2D GetImageBBox() const = 0;
  101. /**
  102. * Actually imports the file.
  103. *
  104. * It is necessary to have loaded the file beforehand.
  105. */
  106. virtual bool Import() = 0;
  107. virtual void SetLineWidthMM( double aLineWidth ) {}
  108. /**
  109. * Collect warning and error messages after loading/importing.
  110. *
  111. * @return the list of messages in one string. Each message ends by '\n'
  112. */
  113. const virtual wxString& GetMessages() const = 0;
  114. protected:
  115. ///< Importer used to create objects representing the imported shapes.
  116. GRAPHICS_IMPORTER* m_importer;
  117. };
  118. #endif /* GRAPHICS_IMPORT_PLUGIN_H */