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.

82 lines
2.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * https://www.gnu.org/licenses/gpl-3.0.html
  19. * or you may search the http://www.gnu.org website for the version 3 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <sim/sim_model_spice_fallback.h>
  24. #include <fmt/format.h>
  25. SIM_MODEL_SPICE_FALLBACK::SIM_MODEL_SPICE_FALLBACK( TYPE aType, const std::string& aRawSpiceCode ) :
  26. SIM_MODEL_SPICE( aType, std::make_unique<SPICE_GENERATOR_SPICE>( *this ) )
  27. {
  28. // Create the model we *should* have had to copy its parameter list
  29. std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( aType );
  30. for( const SIM_MODEL::PARAM& param : model->GetParams() )
  31. AddParam( param.info );
  32. m_spiceCode = aRawSpiceCode;
  33. }
  34. void SIM_MODEL_SPICE_FALLBACK::SetPinSymbolPinNumber( const std::string& aPinName,
  35. const std::string& aSymbolPinNumber )
  36. {
  37. try
  38. {
  39. SIM_MODEL::SetPinSymbolPinNumber( aPinName, aSymbolPinNumber );
  40. }
  41. catch( IO_ERROR& )
  42. {
  43. // This is a fall-back, so we won't necessarily know the pin names. If we didn't find
  44. // it, then just create a new pin.
  45. m_pins.push_back( { aPinName, aSymbolPinNumber } );
  46. }
  47. }
  48. std::vector<std::string> SIM_MODEL_SPICE_FALLBACK::GetPinNames() const
  49. {
  50. // If we're a fall-back for a paticular model type, then return its pin names
  51. std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( GetType() );
  52. return model->GetPinNames();
  53. }
  54. int SIM_MODEL_SPICE_FALLBACK::doFindParam( const std::string& aParamName ) const
  55. {
  56. // Special case to allow escaped model parameters (suffixed with "_")
  57. std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
  58. for( int ii = 0; ii < (int) params.size(); ++ii )
  59. {
  60. const PARAM& param = params[ii];
  61. if( param.Matches( aParamName ) || param.Matches( aParamName + "_" ) )
  62. return ii;
  63. }
  64. return -1;
  65. }