KiCad PCB EDA Suite
eserie.cpp File Reference
#include <array>
#include <algorithm>
#include <calculator_panels/panel_eserie.h>
#include <wx/msgdlg.h>
#include "eserie.h"

Go to the source code of this file.

Functions

double DoubleFromString (const wxString &TextValue)
 
static std::string strValue (double aValue)
 

Variables

E_SERIE r
 

Function Documentation

◆ DoubleFromString()

double DoubleFromString ( const wxString &  TextValue)

Definition at line 37 of file params_read_write.cpp.

38 {
39  double value = 0;
40 
41  /* Acquire the 'right' decimal point separator */
42  const struct lconv* lc = localeconv();
43  wxChar decimal_point = lc->decimal_point[0];
44  wxString buf( TextValue.Strip( wxString::both ) );
45 
46  /* Convert the period in decimal point */
47  buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
48  // An ugly fix needed by WxWidgets 2.9.1 that sometimes
49  // back to a point as separator, although the separator is the comma
50  buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
51 
52  /* Find the end of the numeric part
53  *(when units are append to the number, remove them)
54  */
55  unsigned brk_point = 0;
56  while( brk_point < buf.Len() )
57  {
58  wxChar ch = buf[brk_point];
59  if( !( ( ch >= '0' && ch <= '9' ) || ( ch == decimal_point ) || ( ch == '-' )
60  || ( ch == '+' ) || ( ch == 'e' ) || ( ch == 'E' ) ) )
61  {
62  break;
63  }
64  ++brk_point;
65  }
66 
67  // Check for strings that cannot qualify as a number
68  if( brk_point == 0 )
69  return std::nan( "" );
70 
71  /* Extract the numeric part */
72  if( !buf.Left( brk_point ).ToDouble( &value ) )
73  return std::nan( "" );
74 
75  return value;
76 }

Referenced by PANEL_E_SERIE::OnCalculateESeries().

◆ strValue()

static std::string strValue ( double  aValue)
static

Definition at line 49 of file eserie.cpp.

50 {
51  std::string result;
52 
53  if( aValue < 1000.0 )
54  {
55  result = std::to_string( static_cast<int>( aValue ) );
56  result += 'R';
57  }
58  else
59  {
60  double div = 1e3;
61  int unit = 'K';
62 
63  if( aValue >= 1e6 )
64  {
65  div = 1e6;
66  unit = 'M';
67  }
68 
69  aValue /= div;
70 
71  int integer = static_cast<int>( aValue );
72  result = std::to_string(integer);
73  result += unit;
74 
75  // Add mantissa: 1 digit, suitable for series up to E24
76  double mantissa = aValue - integer;
77 
78  if( mantissa > 0 )
79  result += std::to_string( static_cast<int>( (mantissa*10)+0.5 ) );
80  }
81 
82  return result;
83 }

Referenced by E_SERIE::buildSerieData().

Variable Documentation

◆ r

Definition at line 41 of file eserie.cpp.

Referenced by CRectPlacement::AddAtEmptySpot(), ZONE_FILLER::addHatchFillTypeOnZone(), CRectPlacement::AddRect(), PCAD2KICAD::PCB_FOOTPRINT::AddToBoard(), SEG::ApproxCollinear(), PNS::ApproximateSegmentAsRect(), SEG::ApproxParallel(), PolygonTriangulation::area(), SELECTION::AreAllItemsIdentical(), BlendColor(), PAD::BuildEffectiveShapes(), PNS::buildHullForPrimitiveShape(), DIALOG_NET_INSPECTOR::buildNetsList(), CalcArcCenter(), DXF_PLOTTER::Circle(), KIGFX::VIEW::Clear(), KIGFX::VIEW::clearGroupCache(), clipCircle(), Collide(), DIALOG_NET_INSPECTOR::DATA_MODEL::columnDesc(), EDA_RECT::Common(), PCB_GRID_HELPER::computeAnchors(), CRectPlacement::TRect::Contains(), SHAPE_ARC::ConvertToPolyline(), cosdecideg(), PNS_PCBNEW_RULE_RESOLVER::DpNetPair(), KIGFX::PCB_PAINTER::draw(), KIGFX::CAIRO_GAL_BASE::DrawArc(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), KIGFX::CAIRO_GAL_BASE::DrawCircle(), ROUTER_PREVIEW_ITEM::drawShape(), DRILL_PRECISION::DRILL_PRECISION(), TRANSLINE::ellipk(), PS_PLOTTER::emitSetRGBColor(), PDF_PLOTTER::emitSetRGBColor(), SVG_PLOTTER::emitSetRGBColor(), EDA_DRAW_FRAME::FocusOnLocation(), from_json(), SCH_PIN::GetBoundingBox(), DIALOG_POSITION_RELATIVE::GetTranslationInIU(), DIALOG_MOVE_EXACT::GetTranslationInIU(), LIB_TABLE_GRID::GetValue(), FIELDS_EDITOR_GRID_DATA_MODEL::GetValue(), GRArc(), GRArc1(), GRCircle(), GRFilledArc(), GRFilledCircle(), BOARD_INSPECTION_TOOL::InspectClearance(), BOARD_INSPECTION_TOOL::InspectConstraints(), BOARD_INSPECTION_TOOL::InspectDRCError(), intersect(), CRectPlacement::TRect::Intersects(), EDA_RECT::IntersectsCircle(), EDA_RECT::IntersectsCircleEdge(), KI_TEST::IsColorNearHex(), CRectPlacement::IsFree(), KI_TEST::IsImagePixelOfColor(), SEG::LineDistance(), EAGLE_PLUGIN::loadLibrary(), EAGLE_PLUGIN::loadPlain(), PLOTTER::markerSquare(), DIALOG_NET_INSPECTOR::OnBoardHighlightNetChanged(), DIALOG_NET_INSPECTOR::OnBoardItemAdded(), DIALOG_NET_INSPECTOR::OnBoardItemRemoved(), PANEL_E_SERIE::OnCalculateESeries(), DIALOG_POSITION_RELATIVE::OnClear(), PANEL_E_SERIE::OnESeriesSelection(), APPEARANCE_CONTROLS::OnLayerChanged(), LIB_TABLE_ROW::operator!=(), FP_LIB_TABLE::operator!=(), LIB_TABLE::operator!=(), LIB_TABLE_ROW::operator==(), LIB_TABLE::operator==(), EAGLE_PLUGIN::packageRectangle(), PCAD2KICAD::PCB_ARC::Parse(), mpBitmapLayer::Plot(), PDF_PLOTTER::PlotImage(), pushoutForce(), S3D::ReadColor(), KIGFX::VIEW::RecacheAllItems(), SCH_SYMBOL::ReplaceInstanceSheetPath(), BOARD_INSPECTION_TOOL::reportClearance(), reportCompileError(), rescale(), DIRECTION_45::Right(), round_to_half_pixel(), screenSpaceCircle(), SCH_LINE::SetLineColor(), DIALOG_NET_INSPECTOR::Settings(), SCINTILLA_TRICKS::setupStyles(), LIB_TABLE_GRID::SetValue(), sindecideg(), spreadRectangles(), tb_project_to_sphere(), to_json(), DIALOG_POSITION_RELATIVE::ToPolarDeg(), DIALOG_MOVE_EXACT::ToPolarDeg(), DIALOG_JUNCTION_PROPS::TransferDataToWindow(), DIALOG_LINE_WIRE_BUS_PROPERTIES::TransferDataToWindow(), KIGFX::VIEW::UpdateLayerColor(), SCH_SHEET_LIST::UpdateSheetInstances(), SCH_SHEET_LIST::UpdateSymbolInstances(), DIALOG_NET_INSPECTOR::DATA_MODEL::valueAt(), PANEL_SYM_LIB_TABLE::verifyTables(), PANEL_FP_LIB_TABLE::verifyTables(), SELECTION::ViewBBox(), S3D::WriteColor(), and SGCOLORS::WriteVRML().