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.

152 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2011 jean-pierre.charras
  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 2
  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. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 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. /**
  25. * @file class_regulator_data.h
  26. * Contains structures for storage of regulator data
  27. */
  28. #ifndef CLASS_REGULATOR_DATA_H
  29. #define CLASS_REGULATOR_DATA_H
  30. #include <string_utils.h>
  31. #include <vector>
  32. #include <wx/arrstr.h>
  33. // Helper class to store parameters for a regulator
  34. class REGULATOR_DATA
  35. {
  36. public:
  37. REGULATOR_DATA( const wxString& aName, double aVrefMin, double aVrefTyp, double aVrefMax,
  38. int aType, double aIadjTyp = 0, double aIadjMax = 0 ) :
  39. m_Name( aName ),
  40. m_Type( aType ), m_VrefMin( aVrefMin ), m_VrefTyp( aVrefTyp ), m_VrefMax( aVrefMax ),
  41. m_IadjTyp( aIadjTyp ), m_IadjMax( aIadjMax )
  42. {
  43. }
  44. public:
  45. wxString m_Name; // Regulator name
  46. int m_Type; // type: with separate sense pin (normal) (=0)
  47. // or adjustable 3 pins reg (=1)
  48. double m_VrefMin; // min Vreference in volt
  49. double m_VrefTyp; // typ Vreference in volt
  50. double m_VrefMax; // max Vreference in volt
  51. double m_IadjTyp; // 3 pin type only: typ I adjust in micro amp
  52. double m_IadjMax; // 3 pin type only: max I adjust in micro amp
  53. };
  54. // Helper class to store the list of known regulators
  55. class REGULATOR_LIST
  56. {
  57. public:
  58. REGULATOR_LIST() {}
  59. ~REGULATOR_LIST()
  60. {
  61. for( REGULATOR_DATA* regulator : m_List )
  62. delete regulator;
  63. }
  64. unsigned int GetCount()
  65. {
  66. return m_List.size();
  67. }
  68. void Add( REGULATOR_DATA* aItem )
  69. {
  70. // add new item an try to keep alphabetic order,
  71. // and because name have numbers inside, use a KiCad compare function
  72. // that handles number as numbers not ASCII chars
  73. unsigned ii = 0;
  74. for( ; ii < m_List.size(); ii++ )
  75. {
  76. if( StrNumCmp( aItem->m_Name, m_List[ii]->m_Name, true ) < 0 )
  77. break;
  78. }
  79. m_List.insert( m_List.begin() + ii, aItem );
  80. }
  81. REGULATOR_DATA* GetReg( const wxString& aName )
  82. {
  83. for( REGULATOR_DATA* regulator : m_List )
  84. {
  85. if( aName.CmpNoCase( regulator->m_Name ) == 0 )
  86. return regulator;
  87. }
  88. return nullptr;
  89. }
  90. void Remove( const wxString& aRegName )
  91. {
  92. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  93. {
  94. if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
  95. {
  96. // Found! remove it
  97. m_List.erase( m_List.begin() + ii );
  98. break;
  99. }
  100. }
  101. }
  102. /**
  103. * Replace an old REGULATOR_DATA by a new one
  104. * The old one is deleted
  105. * the 2 items must have the same name
  106. */
  107. void Replace( REGULATOR_DATA* aItem )
  108. {
  109. // Search for the old regulator
  110. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  111. {
  112. if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
  113. {
  114. // Found! remove it
  115. delete m_List[ii];
  116. m_List[ii] = aItem;
  117. break;
  118. }
  119. }
  120. }
  121. wxArrayString GetRegList() const
  122. {
  123. wxArrayString list;
  124. for( REGULATOR_DATA* regulator : m_List )
  125. list.Add( regulator->m_Name );
  126. return list;
  127. }
  128. void Clear() { m_List.clear(); }
  129. std::vector <REGULATOR_DATA*> m_List;
  130. };
  131. #endif // CLASS_REGULATOR_DATA_H