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.

119 lines
4.0 KiB

9 years ago
9 years ago
2 years ago
9 years ago
9 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016-2022 CERN
  5. * Copyright (C) 2017-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 3
  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. * https://www.gnu.org/licenses/gpl-3.0.html
  22. * or you may search the http://www.gnu.org website for the version 3 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 SPICE_CIRCUIT_MODEL_H
  27. #define SPICE_CIRCUIT_MODEL_H
  28. #include <netlist_exporters/netlist_exporter_spice.h>
  29. #include <vector>
  30. #include "sim_types.h"
  31. #include "spice_simulator.h"
  32. #include "spice_value.h"
  33. struct SPICE_DC_PARAMS
  34. {
  35. wxString m_source;
  36. SPICE_VALUE m_vstart;
  37. SPICE_VALUE m_vend;
  38. SPICE_VALUE m_vincrement;
  39. };
  40. struct SPICE_PZ_ANALYSES
  41. {
  42. bool m_Poles;
  43. bool m_Zeros;
  44. };
  45. /// Special netlist exporter flavor that allows one to override simulation commands
  46. class SPICE_CIRCUIT_MODEL : public NETLIST_EXPORTER_SPICE, public SIMULATION_MODEL
  47. {
  48. public:
  49. SPICE_CIRCUIT_MODEL( SCHEMATIC_IFACE* aSchematic ) :
  50. NETLIST_EXPORTER_SPICE( aSchematic )
  51. {}
  52. virtual ~SPICE_CIRCUIT_MODEL() {}
  53. /**
  54. * Return name of Spice dataset for a specific trace.
  55. *
  56. * @param aVector is name of the vector produced by ngspice
  57. * @param [out] aSignal is output in form: V(R1), Ib(Q2), I(L8)
  58. * @return [SPT_VOLTAGE, SPT_CURRENT]. Otherwise SPT_UNKNOWN if vector is of different,
  59. * unsupported type.
  60. */
  61. SIM_TRACE_TYPE VectorToSignal( const std::string& aVector, wxString& aSignal ) const;
  62. bool GetNetlist( const wxString& aCommand, unsigned aOptions, OUTPUTFORMATTER* aFormatter,
  63. REPORTER& aReporter )
  64. {
  65. return SPICE_CIRCUIT_MODEL::DoWriteNetlist( aCommand, aOptions, *aFormatter, aReporter );
  66. }
  67. /**
  68. * Return simulation command directives placed in schematic sheets (if any).
  69. */
  70. wxString GetSchTextSimCommand();
  71. /**
  72. * Parse a two-source .dc command directive into its symbols.
  73. *
  74. * @param aCmd is the input command string
  75. * @return true if the command was parsed successfully
  76. */
  77. bool ParseDCCommand( const wxString& aCmd, SPICE_DC_PARAMS* aSource1,
  78. SPICE_DC_PARAMS* aSource2 );
  79. bool ParsePZCommand( const wxString& aCmd, wxString* transferFunction, wxString* input,
  80. wxString* inputRef, wxString* output, wxString* outputRef,
  81. SPICE_PZ_ANALYSES* analyses );
  82. bool ParseNoiseCommand( const wxString& aCmd, wxString* aOutput, wxString* aRef,
  83. wxString* aSource, wxString* aScale, SPICE_VALUE* aPts,
  84. SPICE_VALUE* aFStart, SPICE_VALUE* aFStop, bool* aSaveAll );
  85. /**
  86. * Determine if a directive is a simulation command.
  87. */
  88. static bool IsSimCommand( const wxString& aCmd )
  89. {
  90. return CommandToSimType( aCmd ) != ST_UNKNOWN;
  91. }
  92. /**
  93. * Return simulation type basing on a simulation command directive.
  94. */
  95. static SIM_TYPE CommandToSimType( const wxString& aCmd );
  96. protected:
  97. void WriteDirectives( const wxString& aSimCommand, unsigned aSimOptions,
  98. OUTPUTFORMATTER& aFormatter ) const override;
  99. };
  100. #endif /* SPICE_CIRCUIT_MODEL_H */