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
2.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 Mikolaj Wielgus
  5. * Copyright The 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 3
  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. * https://www.gnu.org/licenses/gpl-3.0.html
  20. * or you may search the http://www.gnu.org website for the version 3 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. #ifndef SIM_LIBRARY_H
  25. #define SIM_LIBRARY_H
  26. #include <sim/sim_model.h>
  27. #include <reporter.h>
  28. class SIM_LIBRARY
  29. {
  30. public:
  31. static constexpr auto LIBRARY_FIELD = "Sim.Library";
  32. static constexpr auto NAME_FIELD = "Sim.Name";
  33. struct MODEL
  34. {
  35. std::string name;
  36. SIM_MODEL& model;
  37. };
  38. virtual ~SIM_LIBRARY() = default;
  39. SIM_LIBRARY() = default;
  40. /**
  41. * Read library from a source file (e.g. in Spice format), and return a newly constructed
  42. * object of an appropriate subclass.
  43. *
  44. * @param aFilePath Path to the file.
  45. * @param aReporter The reporter the library reports to
  46. * @param aForceFullParse Caller requires fully parsed models. If false fallback models can
  47. * be generarted for performance.
  48. * @return The library loaded in a newly constructed object.
  49. */
  50. static std::unique_ptr<SIM_LIBRARY>
  51. Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
  52. const std::function<wxString( const wxString&, const wxString& )>& aResolver );
  53. /**
  54. * Read library from a source file. Must be in the format appropriate to the subclass, e.g.
  55. * Spice for SIM_LIBRARY_SPICE).
  56. *
  57. * @param aFilePath Path to the file.
  58. * @throw IO_ERROR on read or parsing error.
  59. */
  60. virtual void ReadFile( const wxString& aFilePath, REPORTER& aReporter ) = 0;
  61. SIM_MODEL* FindModel( const std::string& aModelName ) const;
  62. std::vector<MODEL> GetModels() const;
  63. std::string GetFilePath() const { return m_filePath; }
  64. protected:
  65. std::vector<std::string> m_modelNames;
  66. std::vector<std::unique_ptr<SIM_MODEL>> m_models;
  67. std::function<wxString( const wxString&, const wxString& )> m_pathResolver;
  68. std::string m_filePath;
  69. };
  70. #endif // SIM_LIBRARY_H