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.

101 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 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 <dialog_sim_format_value.h>
  24. #include <sim/spice_value.h>
  25. #include <core/kicad_algo.h>
  26. DIALOG_SIM_FORMAT_VALUE::DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, SPICE_VALUE_FORMAT* aFormat ) :
  27. DIALOG_SIM_FORMAT_VALUE_BASE( aParent ),
  28. m_format( aFormat )
  29. {
  30. if( aFormat->Range.EndsWith( wxS( "V" ) ) )
  31. {
  32. m_units = aFormat->Range.Right( 1 );
  33. SetTitle( wxString::Format( GetTitle(), _( "Voltage" ) ) );
  34. }
  35. else if( aFormat->Range.EndsWith( wxS( "A" ) ) )
  36. {
  37. m_units = aFormat->Range.Right( 1 );
  38. SetTitle( wxString::Format( GetTitle(), _( "Current" ) ) );
  39. }
  40. else if( aFormat->Range.EndsWith( wxS( "s" ) ) )
  41. {
  42. m_units = aFormat->Range.Right( 1 );
  43. SetTitle( wxString::Format( GetTitle(), _( "Time" ) ) );
  44. }
  45. else if( aFormat->Range.EndsWith( wxS( "Hz" ) ) )
  46. {
  47. m_units = aFormat->Range.Right( 2 );
  48. SetTitle( wxString::Format( GetTitle(), _( "Frequency" ) ) );
  49. }
  50. else if( aFormat->Range.EndsWith( wxS( "dBV" ) ) )
  51. {
  52. m_units = aFormat->Range.Right( 3 );
  53. SetTitle( wxString::Format( GetTitle(), _( "Gain" ) ) );
  54. }
  55. else if( aFormat->Range.EndsWith( wxS( "°" ) ) )
  56. {
  57. m_units = aFormat->Range.Right( 1 );
  58. SetTitle( wxString::Format( GetTitle(), _( "Phase" ) ) );
  59. }
  60. else if( aFormat->Range.StartsWith( wxS( "~" ), &m_units ) )
  61. {
  62. // m_units set as remainder in StartsWith() call....
  63. SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
  64. }
  65. else
  66. {
  67. if( SPICE_VALUE::ParseSIPrefix( aFormat->Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE )
  68. m_units = aFormat->Range.Right( aFormat->Range.Length() - 1 );
  69. else
  70. m_units = aFormat->Range;
  71. SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
  72. }
  73. m_precisionCtrl->SetValue( aFormat->Precision );
  74. for( int ii = 1; ii < (int) m_rangeCtrl->GetCount(); ++ii )
  75. m_rangeCtrl->SetString( ii, m_rangeCtrl->GetString( ii ) + m_units );
  76. if( aFormat->Range.GetChar( 0 ) == '~' )
  77. m_rangeCtrl->SetSelection( 0 );
  78. else
  79. m_rangeCtrl->SetStringSelection( aFormat->Range );
  80. }
  81. bool DIALOG_SIM_FORMAT_VALUE::TransferDataFromWindow()
  82. {
  83. m_format->Precision = alg::clamp( 1, m_precisionCtrl->GetValue(), 9 );
  84. if( m_rangeCtrl->GetSelection() == 0 )
  85. m_format->Range = wxS( "~" ) + m_units;
  86. else
  87. m_format->Range = m_rangeCtrl->GetStringSelection();
  88. return true;
  89. }