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.

102 lines
3.8 KiB

  1. /*
  2. * This program source code file
  3. * is part of KiCad, a free EDA CAD application.
  4. *
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <cmath>
  21. #include "eseries.h"
  22. namespace ESERIES
  23. {
  24. const std::vector<uint16_t> ESERIES_VALUES::s_e24table = {
  25. 100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300,
  26. 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910
  27. };
  28. const std::vector<uint16_t> ESERIES_VALUES::s_e192table = {
  29. 100, 101, 102, 104, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 123,
  30. 124, 126, 127, 129, 130, 132, 133, 135, 137, 138, 140, 142, 143, 145, 147, 149, 150, 152,
  31. 154, 156, 158, 160, 162, 164, 165, 167, 169, 172, 174, 176, 178, 180, 182, 184, 187, 189,
  32. 191, 193, 196, 198, 200, 203, 205, 208, 210, 213, 215, 218, 221, 223, 226, 229, 232, 234,
  33. 237, 240, 243, 246, 249, 252, 255, 258, 261, 264, 267, 271, 274, 277, 280, 284, 287, 291,
  34. 294, 298, 301, 305, 309, 312, 316, 320, 324, 328, 332, 336, 340, 344, 348, 352, 357, 361,
  35. 365, 370, 374, 379, 383, 388, 392, 397, 402, 407, 412, 417, 422, 427, 432, 437, 442, 448,
  36. 453, 459, 464, 470, 475, 481, 487, 493, 499, 505, 511, 517, 523, 530, 536, 542, 549, 556,
  37. 562, 569, 576, 583, 590, 597, 604, 612, 619, 626, 634, 642, 649, 657, 665, 673, 681, 690,
  38. 698, 706, 715, 723, 732, 741, 750, 759, 768, 777, 787, 796, 806, 816, 825, 835, 845, 856,
  39. 866, 876, 887, 898, 909, 920, 931, 942, 953, 965, 976, 988
  40. };
  41. ESERIES_VALUES::ESERIES_VALUES( int aESeries )
  42. {
  43. const std::vector<uint16_t>* baseSeries = &s_e24table;
  44. unsigned int baseSeriesSkipValue = 24;
  45. if( ESERIES::E1 == aESeries || ESERIES::E3 == aESeries || ESERIES::E6 == aESeries
  46. || ESERIES::E12 == aESeries || ESERIES::E24 == aESeries )
  47. {
  48. // The below table depends on the values and order of entries
  49. // in the E1,E3, etc. enum in eseries.h
  50. const unsigned int skipTableE124[] = { 24, 8, 4, 2, 1 };
  51. baseSeries = &ESERIES_VALUES::s_e24table;
  52. baseSeriesSkipValue = skipTableE124[aESeries];
  53. }
  54. else if( ESERIES::E48 == aESeries || ESERIES::E96 == aESeries || ESERIES::E192 == aESeries )
  55. {
  56. baseSeries = &ESERIES_VALUES::s_e192table;
  57. // The below calculation depends on the values and order of entries
  58. // in the E1,E3, etc. enum in eseries.h
  59. baseSeriesSkipValue = 1 << ( ESERIES::E192 - aESeries );
  60. }
  61. unsigned int decadeBaseLen = baseSeries->size();
  62. reserve( decadeBaseLen / baseSeriesSkipValue );
  63. for( unsigned int idx = 0; idx < decadeBaseLen; idx += baseSeriesSkipValue )
  64. {
  65. emplace_back( ( *baseSeries )[idx] );
  66. }
  67. shrink_to_fit();
  68. }
  69. ESERIES_IN_DECADE::ESERIES_IN_DECADE( int aESeries, int aDecadeExponent )
  70. {
  71. ESERIES::ESERIES_VALUES seriesValues( aESeries );
  72. uint16_t decadeBase = seriesValues[0];
  73. unsigned int decadeBaseLen = seriesValues.size();
  74. double decadeMultiplier = std::pow( 10, aDecadeExponent );
  75. reserve( decadeBaseLen );
  76. for( const uint16_t seriesValue : seriesValues )
  77. {
  78. emplace_back( decadeMultiplier * seriesValue / decadeBase );
  79. }
  80. shrink_to_fit();
  81. }
  82. } // namespace ESERIES