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.

144 lines
4.0 KiB

  1. #ifndef CLASS_REGULATOR_DATA_H
  2. #define CLASS_REGULATOR_DATA_H
  3. /**
  4. * @file class_regulator_data.h
  5. */
  6. /*
  7. * This program source code file is part of KICAD, a free EDA CAD application.
  8. *
  9. * Copyright (C) 1992-2011 jean-pierre.charras
  10. * Copyright (C) 1992-2011 Kicad Developers, see change_log.txt for contributors.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, you may find one here:
  24. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. * or you may search the http://www.gnu.org website for the version 2 license,
  26. * or you may write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #include <refdes_utils.h>
  30. #include <vector>
  31. // Helper class to store parameters for a regulator
  32. class REGULATOR_DATA
  33. {
  34. public:
  35. wxString m_Name; // Regulator name
  36. int m_Type; // type: with separate sense pin (normal) (=0)
  37. // or adjustable 3 pins reg (=1)
  38. double m_Vref; // Vreference in volt
  39. double m_Iadj; // 3 pin type only: I adjust in micro amp
  40. public:
  41. REGULATOR_DATA( const wxString& aName, double aVref, int aType, double aIadj = 0)
  42. {
  43. m_Type = aType;
  44. m_Vref = aVref;
  45. m_Name = aName;
  46. m_Iadj = aIadj;
  47. }
  48. };
  49. // Helper class to store the list of known regulators
  50. class REGULATOR_LIST
  51. {
  52. public:
  53. std::vector <REGULATOR_DATA*> m_List;
  54. public:
  55. REGULATOR_LIST() {};
  56. ~REGULATOR_LIST()
  57. {
  58. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  59. delete m_List[ii];
  60. }
  61. unsigned int GetCount()
  62. {
  63. return m_List.size();
  64. }
  65. void Add( REGULATOR_DATA* aItem )
  66. {
  67. // add new item an try to keep alphabetic order,
  68. // and because name have numbers inside, use a KiCad compare function
  69. // that handles number as numbers not ascii chars
  70. unsigned ii = 0;
  71. for( ; ii < m_List.size(); ii++ )
  72. {
  73. if( UTIL::RefDesStringCompare( aItem->m_Name, m_List[ii]->m_Name ) < 0 )
  74. break;
  75. }
  76. m_List.insert( m_List.begin() + ii, aItem );
  77. }
  78. REGULATOR_DATA* GetReg( const wxString& aName )
  79. {
  80. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  81. {
  82. if( aName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
  83. {
  84. return m_List[ii];
  85. }
  86. }
  87. return NULL;
  88. }
  89. void Remove( const wxString & aRegName )
  90. {
  91. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  92. {
  93. if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
  94. {
  95. // Found! remove it
  96. m_List.erase( m_List.begin() + ii );
  97. break;
  98. }
  99. }
  100. }
  101. /**
  102. * Replace an old REGULATOR_DATA by a new one
  103. * The old one is deleted
  104. * the 2 items must have the same name
  105. */
  106. void Replace( REGULATOR_DATA* aItem )
  107. {
  108. // Search for the old regulator
  109. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  110. {
  111. if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
  112. {
  113. // Found! remove it
  114. delete m_List[ii];
  115. m_List[ii] = aItem;
  116. break;
  117. }
  118. }
  119. }
  120. wxArrayString GetRegList()
  121. {
  122. wxArrayString list;
  123. for( unsigned ii = 0; ii < m_List.size(); ii++ )
  124. list.Add( m_List[ii]->m_Name );
  125. return list;
  126. }
  127. };
  128. #endif // CLASS_REGULATOR_DATA_H