Split up Double2Str to a format function to make its use case clear

This commit is contained in:
Marek Roszko 2022-09-16 23:35:16 -04:00
parent 59a9ddac20
commit ece23d434b
15 changed files with 140 additions and 107 deletions

View File

@ -39,8 +39,6 @@
using namespace DRAWINGSHEET_T;
#define double2Str Double2Str
// A helper function to write tokens:
static const char* getTokenName( T aTok )
{
@ -210,17 +208,17 @@ void DS_DATA_MODEL_IO::Format( DS_DATA_MODEL* aSheet ) const
// Write default values:
m_out->Print( nestLevel, "(setup " );
m_out->Print( 0, "(textsize %s %s)",
double2Str( aSheet->m_DefaultTextSize.x ).c_str(),
double2Str( aSheet->m_DefaultTextSize.y ).c_str() );
m_out->Print( 0, "(linewidth %s)", double2Str( aSheet->m_DefaultLineWidth ).c_str() );
m_out->Print( 0, "(textlinewidth %s)", double2Str( aSheet->m_DefaultTextThickness ).c_str() );
FormatDouble2Str( aSheet->m_DefaultTextSize.x ).c_str(),
FormatDouble2Str( aSheet->m_DefaultTextSize.y ).c_str() );
m_out->Print( 0, "(linewidth %s)", FormatDouble2Str( aSheet->m_DefaultLineWidth ).c_str() );
m_out->Print( 0, "(textlinewidth %s)", FormatDouble2Str( aSheet->m_DefaultTextThickness ).c_str() );
m_out->Print( 0, "\n" );
// Write margin values
m_out->Print( nestLevel, "(left_margin %s)", double2Str( aSheet->GetLeftMargin() ).c_str() );
m_out->Print( 0, "(right_margin %s)", double2Str( aSheet->GetRightMargin() ).c_str() );
m_out->Print( 0, "(top_margin %s)", double2Str( aSheet->GetTopMargin() ).c_str() );
m_out->Print( 0, "(bottom_margin %s)", double2Str( aSheet->GetBottomMargin() ).c_str() );
m_out->Print( nestLevel, "(left_margin %s)", FormatDouble2Str( aSheet->GetLeftMargin() ).c_str() );
m_out->Print( 0, "(right_margin %s)", FormatDouble2Str( aSheet->GetRightMargin() ).c_str() );
m_out->Print( 0, "(top_margin %s)", FormatDouble2Str( aSheet->GetTopMargin() ).c_str() );
m_out->Print( 0, "(bottom_margin %s)", FormatDouble2Str( aSheet->GetBottomMargin() ).c_str() );
m_out->Print( 0, ")\n" );
// Save the graphical items on the drawing sheet
@ -244,7 +242,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
formatOptions( aItem );
if( aItem->m_Orient )
m_out->Print( 0, " (rotate %s)", double2Str(aItem->m_Orient ).c_str() );
m_out->Print( 0, " (rotate %s)", FormatDouble2Str( aItem->m_Orient ).c_str() );
// Write font info, only if it is not the default setup
bool write_size = aItem->m_TextSize.x != 0.0 || aItem->m_TextSize.y != 0.0;
@ -258,13 +256,13 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
m_out->Print( 0, " (face \"%s\")", aItem->m_Font->NameAsToken() );
if( write_thickness )
m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
m_out->Print( 0, " (linewidth %s)", FormatDouble2Str( aItem->m_LineWidth ).c_str() );
if( write_size )
{
m_out->Print( 0, " (size %s %s)",
double2Str( aItem->m_TextSize.x ).c_str(),
double2Str( aItem->m_TextSize.y ).c_str() );
FormatDouble2Str( aItem->m_TextSize.x ).c_str(),
FormatDouble2Str( aItem->m_TextSize.y ).c_str() );
}
if( aItem->m_Bold )
@ -279,7 +277,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
KiROUND( aItem->m_TextColor.r * 255.0 ),
KiROUND( aItem->m_TextColor.g * 255.0 ),
KiROUND( aItem->m_TextColor.b * 255.0 ),
Double2Str( aItem->m_TextColor.a ).c_str() );
FormatDouble2Str( aItem->m_TextColor.a ).c_str() );
}
m_out->Print( 0, ")" );
@ -307,10 +305,10 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
// write constraints
if( aItem->m_BoundingBoxSize.x )
m_out->Print( 0, " (maxlen %s)", double2Str(aItem->m_BoundingBoxSize.x ).c_str() );
m_out->Print( 0, " (maxlen %s)", FormatDouble2Str( aItem->m_BoundingBoxSize.x ).c_str() );
if( aItem->m_BoundingBoxSize.y )
m_out->Print( 0, " (maxheight %s)", double2Str(aItem->m_BoundingBoxSize.y ).c_str() );
m_out->Print( 0, " (maxheight %s)", FormatDouble2Str(aItem->m_BoundingBoxSize.y ).c_str() );
formatRepeatParameters( aItem );
@ -335,7 +333,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int a
formatOptions( aItem );
if( aItem->m_LineWidth && aItem->m_LineWidth != aModel->m_DefaultLineWidth )
m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
m_out->Print( 0, " (linewidth %s)", FormatDouble2Str( aItem->m_LineWidth ).c_str() );
formatRepeatParameters( aItem );
@ -356,10 +354,10 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) co
formatRepeatParameters( aItem );
if( !aItem->m_Orient.IsZero() )
m_out->Print( 0, " (rotate %s)", double2Str( aItem->m_Orient.AsDegrees() ).c_str() );
m_out->Print( 0, " (rotate %s)", FormatDouble2Str( aItem->m_Orient.AsDegrees() ).c_str() );
if( aItem->m_LineWidth )
m_out->Print( 0, " (linewidth %s)\n", double2Str( aItem->m_LineWidth ).c_str() );
m_out->Print( 0, " (linewidth %s)\n", FormatDouble2Str( aItem->m_LineWidth ).c_str() );
if( !aItem->m_Info.IsEmpty() )
m_out->Print( 0, " (comment %s)\n", m_out->Quotew( aItem->m_Info ).c_str() );
@ -386,8 +384,8 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) co
}
m_out->Print( nestLevel, " (xy %s %s)",
double2Str( pos.x ).c_str(),
double2Str( pos.y ).c_str() );
FormatDouble2Str( pos.x ).c_str(),
FormatDouble2Str( pos.y ).c_str() );
}
m_out->Print( 0, ")\n" );
@ -404,7 +402,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) cons
formatCoordinate( "pos", aItem->m_Pos );
formatOptions( aItem );
m_out->Print( 0, " (scale %s)", double2Str( aItem->m_ImageBitmap->GetScale() ).c_str() );
m_out->Print( 0, " (scale %s)", FormatDouble2Str( aItem->m_ImageBitmap->GetScale() ).c_str() );
formatRepeatParameters( aItem );
m_out->Print( 0,"\n");
@ -429,8 +427,8 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) cons
void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken, POINT_COORD & aCoord ) const
{
m_out->Print( 0, " (%s %s %s", aToken,
double2Str( aCoord.m_Pos.x ).c_str(),
double2Str( aCoord.m_Pos.y ).c_str() );
FormatDouble2Str( aCoord.m_Pos.x ).c_str(),
FormatDouble2Str( aCoord.m_Pos.y ).c_str() );
switch( aCoord.m_Anchor )
{
@ -452,10 +450,10 @@ void DS_DATA_MODEL_IO::formatRepeatParameters( DS_DATA_ITEM* aItem ) const
m_out->Print( 0, " (repeat %d)", aItem->m_RepeatCount );
if( aItem->m_IncrementVector.x )
m_out->Print( 0, " (incrx %s)", double2Str(aItem-> m_IncrementVector.x ).c_str() );
m_out->Print( 0, " (incrx %s)", FormatDouble2Str( aItem->m_IncrementVector.x ).c_str() );
if( aItem->m_IncrementVector.y )
m_out->Print( 0, " (incry %s)", double2Str( aItem->m_IncrementVector.y ).c_str() );
m_out->Print( 0, " (incry %s)", FormatDouble2Str( aItem->m_IncrementVector.y ).c_str() );
if( aItem->m_IncrementLabel != 1 && aItem->GetType() == DS_DATA_ITEM::DS_TEXT )
m_out->Print( 0, " (incrlabel %d)", aItem->m_IncrementLabel );

View File

@ -789,7 +789,7 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
if( GetLineSpacing() != 1.0 )
{
aFormatter->Print( 0, " (line_spacing %s)",
Double2Str( GetLineSpacing() ).c_str() );
FormatDouble2Str( GetLineSpacing() ).c_str() );
}
if( GetTextThickness() )
@ -810,7 +810,7 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
KiROUND( GetTextColor().r * 255.0 ),
KiROUND( GetTextColor().g * 255.0 ),
KiROUND( GetTextColor().b * 255.0 ),
Double2Str( GetTextColor().a ).c_str() );
FormatDouble2Str( GetTextColor().a ).c_str() );
}
aFormatter->Print( 0, ")"); // (font

View File

@ -128,12 +128,9 @@ wxString EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS aUnits, EDA_DATA_TY
std::string EDA_UNIT_UTILS::FormatAngle( const EDA_ANGLE& aAngle )
{
char temp[50];
int len;
std::string temp = fmt::format( "{:.10g}", aAngle.AsDegrees() );
len = snprintf( temp, sizeof( temp ), "%.10g", aAngle.AsDegrees() );
return std::string( temp, len );
return temp;
}

View File

@ -110,8 +110,8 @@ void NUMERIC_EVALUATOR::parseSetResult( double val )
// Can be printed as a floating point
// Warning: DO NOT use a format like %f or %g, because they can create issues.
// especially %g can generate an exponent, incompatible with UNIT_BINDER
// Use the optimized Double2Str
snprintf( m_token.token, m_token.OutLen, "%s", Double2Str( val ).c_str() );
// Use the optimized UIDouble2Str
snprintf( m_token.token, m_token.OutLen, "%s", UIDouble2Str( val ).c_str() );
}
}

View File

@ -28,6 +28,7 @@
#include <clocale>
#include <cmath>
#include <fmt/core.h>
#include <macros.h>
#include <richio.h> // StrPrintf
#include <string_utils.h>
@ -1088,7 +1089,30 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
}
std::string Double2Str( double aValue )
std::string FormatDouble2Str( double aValue )
{
std::string buf;
if( aValue != 0.0 && std::fabs( aValue ) <= 0.0001 )
{
buf = fmt::format( "{:.16f}", aValue );
// remove trailing zeros
while( !buf.empty() && buf[buf.size() - 1] == '0' )
{
buf.pop_back();
}
}
else
{
buf = fmt::format( "{:.10g}", aValue );
}
return buf;
}
std::string UIDouble2Str( double aValue )
{
char buf[50];
int len;

View File

@ -236,7 +236,7 @@ void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, const EDA_IU_SCALE& aIu
KiROUND( GetColor().r * 255.0 ),
KiROUND( GetColor().g * 255.0 ),
KiROUND( GetColor().b * 255.0 ),
Double2Str( GetColor().a ).c_str() );
FormatDouble2Str( GetColor().a ).c_str() );
}
}

View File

@ -972,7 +972,7 @@ void SCH_SEXPR_PLUGIN::saveJunction( SCH_JUNCTION* aJunction, int aNestLevel )
KiROUND( aJunction->GetColor().r * 255.0 ),
KiROUND( aJunction->GetColor().g * 255.0 ),
KiROUND( aJunction->GetColor().b * 255.0 ),
Double2Str( aJunction->GetColor().a ).c_str() );
FormatDouble2Str( aJunction->GetColor().a ).c_str() );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aJunction->m_Uuid.AsString() ) );

View File

@ -52,7 +52,7 @@ void formatFill( OUTPUTFORMATTER* aFormatter, int aNestLevel, FILL_T aFillMode,
KiROUND( aFillColor.r * 255.0 ),
KiROUND( aFillColor.g * 255.0 ),
KiROUND( aFillColor.b * 255.0 ),
Double2Str( aFillColor.a ).c_str() );
FormatDouble2Str( aFillColor.a ).c_str() );
}
else
{

View File

@ -195,23 +195,23 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt
if( angle == 360.0 || angle == 0 )
{
fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s) (layer %s) (width %s))\n",
Double2Str( MapToPcbUnits(seg_start.x) ).c_str(),
Double2Str( MapToPcbUnits(seg_start.y) ).c_str(),
Double2Str( MapToPcbUnits(seg_end.x) ).c_str(),
Double2Str( MapToPcbUnits(seg_end.y) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
}
else
{
fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s) (layer %s) (width %s))\n",
Double2Str( MapToPcbUnits(seg_start.x) ).c_str(),
Double2Str( MapToPcbUnits(seg_start.y) ).c_str(),
Double2Str( MapToPcbUnits(seg_end.x) ).c_str(),
Double2Str( MapToPcbUnits(seg_end.y) ).c_str(),
Double2Str( angle ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
FormatDouble2Str( angle ).c_str(),
TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
}
}
break;
@ -222,12 +222,12 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt
seg_end.y = -seg_end.y;
fprintf( m_fp, "(gr_circle (start %s %s) (end %s %s) (layer %s) (width %s))\n",
Double2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
Double2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
Double2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
Double2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
break;
case GBR_SEGMENT:
@ -236,12 +236,12 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt
seg_end.y = -seg_end.y;
fprintf( m_fp, "(gr_line (start %s %s) (end %s %s) (layer %s) (width %s))\n",
Double2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
Double2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
Double2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
Double2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
break;
}
}
@ -263,10 +263,10 @@ void GBR_TO_PCB_EXPORTER::export_via( const EXPORT_VIA& aVia )
// Layers are Front to Back
fprintf( m_fp, " (via (at %s %s) (size %s) (drill %s)",
Double2Str( MapToPcbUnits( via_pos.x ) ).c_str(),
Double2Str( MapToPcbUnits( via_pos.y ) ).c_str(),
Double2Str( MapToPcbUnits( aVia.m_Size ) ).c_str(),
Double2Str( MapToPcbUnits( aVia.m_Drill ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( via_pos.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( via_pos.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aVia.m_Size ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aVia.m_Drill ) ).c_str() );
fprintf( m_fp, " (layers %s %s))\n",
TO_UTF8( GetPCBDefaultLayerName( F_Cu ) ),
@ -329,11 +329,11 @@ void GBR_TO_PCB_EXPORTER::writeCopperLineItem( const VECTOR2I& aStart, const VEC
int aWidth, int aLayer )
{
fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
Double2Str( MapToPcbUnits( aWidth ) ).c_str(),
FormatDouble2Str( MapToPcbUnits(aStart.x) ).c_str(),
FormatDouble2Str( MapToPcbUnits(aStart.y) ).c_str(),
FormatDouble2Str( MapToPcbUnits(aEnd.x) ).c_str(),
FormatDouble2Str( MapToPcbUnits(aEnd.y) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aWidth ) ).c_str(),
TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
}
@ -435,10 +435,10 @@ void GBR_TO_PCB_EXPORTER::writePcbFilledCircle( const VECTOR2I& aCenterPosition,
{
fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s)",
Double2Str( MapToPcbUnits( aCenterPosition.x ) ).c_str(),
Double2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str(),
Double2Str( MapToPcbUnits( aCenterPosition.x + aRadius ) ).c_str(),
Double2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( aCenterPosition.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aCenterPosition.x + aRadius ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str() );
fprintf( m_fp, "(layer %s) (width 0) (fill solid) )\n",
@ -505,8 +505,8 @@ void GBR_TO_PCB_EXPORTER::writePcbPolygon( const SHAPE_POLY_SET& aPolys, int aLa
}
fprintf( m_fp, " (xy %s %s)",
Double2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(),
Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() );
FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() );
}
fprintf( m_fp, ")" );
@ -560,8 +560,8 @@ void GBR_TO_PCB_EXPORTER::writePcbZoneItem( const GERBER_DRAW_ITEM* aGbrItem, in
fprintf( m_fp, "\n " );
}
fprintf( m_fp, " (xy %s %s)", Double2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
fprintf( m_fp, " (xy %s %s)", FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
}
fprintf( m_fp, ")\n" );

View File

@ -82,6 +82,8 @@ namespace EDA_UNIT_UTILS
/**
* Converts \a aAngle from board units to a string appropriate for writing to file.
*
* This should only be used for writing to files as it ignores locale
*
* @note Internal angles for board items can be either degrees or tenths of degree
* on how KiCad is built.
* @param aAngle A angle value to convert.
@ -93,6 +95,8 @@ namespace EDA_UNIT_UTILS
* Converts \a aValue from internal units to a string appropriate for writing
* to file.
*
* This should only be used for writing to files as it ignores locale
*
* @note Internal units for board items can be either deci-mils or nanometers depending
* on how KiCad is built.
*

View File

@ -353,6 +353,16 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed =
* this helper function uses the %f format when needed, or %g when %f is
* not well working and then removes trailing 0
*/
std::string Double2Str( double aValue );
std::string UIDouble2Str( double aValue );
/**
* Print a float number without using scientific notation and no trailing 0
* This function is intended in uses to write to file, it ignores locale
*
* We cannot always just use the %g or the %f format to print a fp number
* this helper function uses the %f format when needed, or %g when %f is
* not well working and then removes trailing 0
*/
std::string FormatDouble2Str( double aValue );
#endif // STRING_UTILS_H

View File

@ -266,7 +266,7 @@ wxString BOARD_STACKUP_ITEM::FormatEpsilonR( int aDielectricSubLayer ) const
{
// return a wxString to print/display Epsilon R
// note: we do not want scientific notation
wxString txt = Double2Str( GetEpsilonR( aDielectricSubLayer ) );
wxString txt = UIDouble2Str( GetEpsilonR( aDielectricSubLayer ) );
return txt;
}
@ -275,7 +275,7 @@ wxString BOARD_STACKUP_ITEM::FormatLossTangent( int aDielectricSubLayer ) const
{
// return a wxString to print/display Loss Tangent
// note: we do not want scientific notation
wxString txt = Double2Str( GetLossTangent( aDielectricSubLayer ) );
wxString txt = UIDouble2Str( GetLossTangent( aDielectricSubLayer ) );
return txt;
}
@ -666,7 +666,7 @@ void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter,
if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
aFormatter->Print( 0, " (loss_tangent %s)",
Double2Str(item->GetLossTangent( idx ) ).c_str() );
FormatDouble2Str( item->GetLossTangent( idx ) ).c_str() );
}
aFormatter->Print( 0, ")\n" );

View File

@ -26,7 +26,7 @@
#include "stackup_predefined_prms.h"
#include "dielectric_material.h"
#include <core/arraydim.h>
#include <string_utils.h> // for Double2Str()
#include <string_utils.h> // for UIDouble2Str()
// A list of available substrate material
@ -70,7 +70,7 @@ wxString DIELECTRIC_SUBSTRATE::FormatEpsilonR()
{
// return a wxString to print/display Epsilon R
// note: we do not want scientific notation
wxString txt = Double2Str( m_EpsilonR );
wxString txt = UIDouble2Str( m_EpsilonR );
return txt;
}
@ -79,7 +79,7 @@ wxString DIELECTRIC_SUBSTRATE::FormatLossTangent()
{
// return a wxString to print/display Loss Tangent
// note: we do not want scientific notation
wxString txt = Double2Str( m_LossTangent );
wxString txt = UIDouble2Str( m_LossTangent );
return txt;
}

View File

@ -48,7 +48,7 @@
#include <locale_io.h>
#include <eda_list_dialog.h>
#include <string_utils.h> // for Double2Str()
#include <string_utils.h> // for UIDouble2Str()
// Some wx widget ID to know what widget has fired a event:
@ -573,7 +573,7 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync )
if( item->HasEpsilonRValue() )
{
wxString txt = Double2Str( item->GetEpsilonR( sub_item ) );
wxString txt = UIDouble2Str( item->GetEpsilonR( sub_item ) );
wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( ui_row_item.m_EpsilonCtrl );
if( textCtrl )
@ -582,7 +582,7 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync )
if( item->HasLossTangentValue() )
{
wxString txt = Double2Str( item->GetLossTangent( sub_item ) );
wxString txt = UIDouble2Str( item->GetLossTangent( sub_item ) );
wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( ui_row_item.m_LossTgCtrl );
if( textCtrl )
@ -832,7 +832,7 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow,
if( item->HasEpsilonRValue() )
{
wxString txt = Double2Str( item->GetEpsilonR( aSublayerIdx ) );
wxString txt = UIDouble2Str( item->GetEpsilonR( aSublayerIdx ) );
wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString,
wxDefaultPosition, m_numericFieldsSize );
textCtrl->ChangeValue( txt );
@ -846,7 +846,7 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow,
if( item->HasLossTangentValue() )
{
wxString txt = Double2Str( item->GetLossTangent( aSublayerIdx ) );;
wxString txt = UIDouble2Str( item->GetLossTangent( aSublayerIdx ) );;
wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString,
wxDefaultPosition, m_numericFieldsSize );
textCtrl->ChangeValue( txt );

View File

@ -608,7 +608,7 @@ void PCB_PLUGIN::formatSetup( const BOARD* aBoard, int aNestLevel ) const
if( dsnSettings.m_SolderPasteMarginRatio != 0 )
{
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
FormatDouble2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
}
if( dsnSettings.m_AllowSoldermaskBridgesInFPs )
@ -1268,7 +1268,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
if( aFootprint->GetLocalSolderPasteMarginRatio() != 0 )
{
m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
Double2Str( aFootprint->GetLocalSolderPasteMarginRatio() ).c_str() );
FormatDouble2Str( aFootprint->GetLocalSolderPasteMarginRatio() ).c_str() );
}
if( aFootprint->GetLocalClearance() != 0 )
@ -1384,19 +1384,19 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
Double2Str( bs3D->m_Offset.x ).c_str(),
Double2Str( bs3D->m_Offset.y ).c_str(),
Double2Str( bs3D->m_Offset.z ).c_str() );
FormatDouble2Str( bs3D->m_Offset.x ).c_str(),
FormatDouble2Str( bs3D->m_Offset.y ).c_str(),
FormatDouble2Str( bs3D->m_Offset.z ).c_str() );
m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
Double2Str( bs3D->m_Scale.x ).c_str(),
Double2Str( bs3D->m_Scale.y ).c_str(),
Double2Str( bs3D->m_Scale.z ).c_str() );
FormatDouble2Str( bs3D->m_Scale.x ).c_str(),
FormatDouble2Str( bs3D->m_Scale.y ).c_str(),
FormatDouble2Str( bs3D->m_Scale.z ).c_str() );
m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
Double2Str( bs3D->m_Rotation.x ).c_str(),
Double2Str( bs3D->m_Rotation.y ).c_str(),
Double2Str( bs3D->m_Rotation.z ).c_str() );
FormatDouble2Str( bs3D->m_Rotation.x ).c_str(),
FormatDouble2Str( bs3D->m_Rotation.y ).c_str(),
FormatDouble2Str( bs3D->m_Rotation.z ).c_str() );
m_out->Print( aNestLevel+1, ")\n" );
}
@ -1607,7 +1607,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const
if( aPad->GetShape() == PAD_SHAPE::ROUNDRECT || aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT)
{
m_out->Print( 0, " (roundrect_rratio %s)",
Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
FormatDouble2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
}
// Output the chamfer corners for chamfered rect pads
@ -1616,7 +1616,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
Double2Str( aPad->GetChamferRectRatio() ).c_str() );
FormatDouble2Str( aPad->GetChamferRectRatio() ).c_str() );
m_out->Print( 0, " (chamfer" );
@ -1682,7 +1682,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const
if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
{
StrPrintf( &output, " (solder_paste_margin_ratio %s)",
Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
FormatDouble2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
}
if( aPad->GetLocalClearance() != 0 )
@ -2331,20 +2331,20 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const
m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetHatchThickness() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetHatchGap() ).c_str(),
Double2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() );
FormatDouble2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() );
if( aZone->GetHatchSmoothingLevel() > 0 )
{
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
aZone->GetHatchSmoothingLevel(),
Double2Str( aZone->GetHatchSmoothingValue() ).c_str() );
FormatDouble2Str( aZone->GetHatchSmoothingValue() ).c_str() );
}
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel+2, "(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
aZone->GetHatchBorderAlgorithm() ? "hatch_thickness" : "min_thickness",
Double2Str( aZone->GetHatchHoleMinArea() ).c_str() );
FormatDouble2Str( aZone->GetHatchHoleMinArea() ).c_str() );
}
m_out->Print( 0, ")\n" );