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.

113 lines
4.6 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 (C) 2022 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_MODEL_SOURCE_H
  25. #define SIM_MODEL_SOURCE_H
  26. #include <sim/sim_model.h>
  27. #include <sim/sim_serde.h>
  28. #include <sim/spice_generator.h>
  29. namespace SIM_MODEL_SOURCE_GRAMMAR
  30. {
  31. using namespace SIM_SERDE_GRAMMAR;
  32. struct pwlSep : plus<space> {};
  33. struct pwlValues : seq<opt<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>,
  34. star<pwlSep,
  35. number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>> {};
  36. struct pwlValuesGrammar : must<opt<sep>,
  37. pwlValues,
  38. opt<sep>,
  39. tao::pegtl::eof> {};
  40. }
  41. class SPICE_GENERATOR_SOURCE : public SPICE_GENERATOR
  42. {
  43. public:
  44. using SPICE_GENERATOR::SPICE_GENERATOR;
  45. std::string ModelLine( const SPICE_ITEM& aItem ) const override;
  46. std::string ItemLine( const SPICE_ITEM& aItem ) const override;
  47. private:
  48. std::string getParamValueString( const std::string& aParamName,
  49. const std::string& aDefaultValue ) const;
  50. };
  51. class SIM_SERDE_SOURCE : public SIM_SERDE
  52. {
  53. public:
  54. using SIM_SERDE::SIM_SERDE;
  55. protected:
  56. std::string GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const override;
  57. };
  58. class SIM_MODEL_SOURCE : public SIM_MODEL
  59. {
  60. public:
  61. SIM_MODEL_SOURCE( TYPE aType );
  62. void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const override;
  63. void WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) const override;
  64. void SetParamValue( int aParamIndex, const SIM_VALUE& aValue ) override;
  65. bool HasAutofill() const override { return true; }
  66. bool HasPrimaryValue() const override { return true; }
  67. private:
  68. template <typename T>
  69. void inferredWriteDataFields( std::vector<T>& aFields ) const;
  70. std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
  71. static const std::vector<PARAM::INFO>& makeParamInfos( TYPE aType );
  72. static std::vector<PARAM::INFO> makeDcParamInfos( std::string aPrefix, std::string aUnit );
  73. static std::vector<PARAM::INFO> makeSinParamInfos( std::string aPrefix, std::string aUnit );
  74. static std::vector<PARAM::INFO> makePulseParamInfos( std::string aPrefix, std::string aUnit );
  75. static std::vector<PARAM::INFO> makeExpParamInfos( std::string aPrefix, std::string aUnit );
  76. //static std::vector<PARAM::INFO> makeSfamParamInfos( std::string aPrefix, std::string aUnit );
  77. //static std::vector<PARAM::INFO> makeSffmParamInfos( std::string aPrefix, std::string aUnit );
  78. static std::vector<PARAM::INFO> makePwlParamInfos( std::string aPrefix, std::string aQuantity,
  79. std::string aUnit );
  80. static std::vector<PARAM::INFO> makeWhiteNoiseParamInfos( std::string aPrefix, std::string aUnit );
  81. static std::vector<PARAM::INFO> makePinkNoiseParamInfos( std::string aPrefix, std::string aUnit );
  82. static std::vector<PARAM::INFO> makeBurstNoiseParamInfos( std::string aPrefix, std::string aUnit );
  83. static std::vector<PARAM::INFO> makeRandomUniformParamInfos( std::string aPrefix, std::string aUnit );
  84. static std::vector<PARAM::INFO> makeRandomNormalParamInfos( std::string aPrefix, std::string aUnit );
  85. static std::vector<PARAM::INFO> makeRandomExpParamInfos( std::string aPrefix, std::string aUnit );
  86. static std::vector<PARAM::INFO> makeRandomPoissonParamInfos( std::string aPrefix, std::string aUnit );
  87. static void appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, std::string aUnit );
  88. };
  89. #endif // SIM_MODEL_SOURCE_H