~jeru-sheng/kicad/kicad-feature

« back to all changes in this revision

Viewing changes to common/base_units.cpp

  • Committer: jean-pierre charras
  • Date: 2013-07-19 18:27:22 UTC
  • mto: This revision was merged to the branch mainline in revision 4244.
  • Revision ID: jp.charras@wanadoo.fr-20130719182722-193syk49ehwi95rk
Initial release of pl_editor, the page layout and title block editor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <base_units.h>
41
41
 
42
42
 
43
 
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW )
 
43
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
44
44
#define IU_TO_MM( x )       ( x / IU_PER_MM )
45
45
#define IU_TO_IN( x )       ( x / IU_PER_MILS / 1000 )
46
46
#define MM_TO_IU( x )       ( x * IU_PER_MM )
50
50
#endif
51
51
 
52
52
 
 
53
// Helper function to print a float number without using scientific notation
 
54
// and no trailing 0
 
55
// So we cannot always just use the %g or the %f format to print a fp number
 
56
// this helper function uses the %f format when needed, or %g when %f is
 
57
// not well working and then removes trailing 0
 
58
 
 
59
std::string Double2Str( double aValue )
 
60
{
 
61
    char    buf[50];
 
62
    int     len;
 
63
 
 
64
    if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
 
65
    {
 
66
        // For these small values, %f works fine,
 
67
        // and %g gives an exponent
 
68
        len = sprintf( buf,  "%.16f", aValue );
 
69
 
 
70
        while( --len > 0 && buf[len] == '0' )
 
71
            buf[len] = '\0';
 
72
 
 
73
        if( buf[len] == '.' )
 
74
            buf[len] = '\0';
 
75
        else
 
76
            ++len;
 
77
    }
 
78
    else
 
79
    {
 
80
        // For these values, %g works fine, and sometimes %f
 
81
        // gives a bad value (try aValue = 1.222222222222, with %.16f format!)
 
82
        len = sprintf( buf, "%.16g", aValue );
 
83
    }
 
84
 
 
85
    return std::string( buf, len );;
 
86
}
 
87
 
 
88
 
53
89
double To_User_Unit( EDA_UNITS_T aUnit, double aValue )
54
90
{
55
91
    switch( aUnit )