KiCad PCB EDA Suite
preview_utils.cpp File Reference

Go to the source code of this file.

Functions

static wxString getDimensionUnit (EDA_UNITS_T aUnits)
 
static wxString formatPreviewDimension (double aVal, EDA_UNITS_T aUnits)
 

Function Documentation

static wxString formatPreviewDimension ( double  aVal,
EDA_UNITS_T  aUnits 
)
static

Definition at line 75 of file preview_utils.cpp.

References DEGREES, Format(), getDimensionUnit(), INCHES, MILLIMETRES, To_User_Unit(), and UNSCALED_UNITS.

Referenced by KIGFX::PREVIEW::DimensionLabel().

76 {
77  int precision = 4;
78 
79  // show a sane precision for the preview, which doesn't need to
80  // be accurate down to the nanometre
81  switch( aUnits )
82  {
83  case MILLIMETRES:
84  precision = 2; // 10um
85  break;
86  case INCHES:
87  precision = 4; // 1mil
88  break;
89  case DEGREES:
90  precision = 1; // 0.1deg (limit of formats anyway)
91  break;
92  case UNSCALED_UNITS:
93  break;
94  }
95 
96  const wxString fmtStr = wxString::Format( "%%.%df", precision );
97 
98  wxString str = wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
99 
100  const wxString symbol = getDimensionUnit( aUnits );
101 
102  if( symbol.size() )
103  str << " " << symbol;
104 
105  return str;
106 }
static wxString getDimensionUnit(EDA_UNITS_T aUnits)
Definition: common.h:145
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
double To_User_Unit(EDA_UNITS_T aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:90
static wxString getDimensionUnit ( EDA_UNITS_T  aUnits)
static

Definition at line 53 of file preview_utils.cpp.

References DEGREES, INCHES, MILLIMETRES, and UNSCALED_UNITS.

Referenced by formatPreviewDimension().

54 {
55  switch( aUnits )
56  {
57  case INCHES:
58  return _( "\"" );
59 
60  case MILLIMETRES:
61  return _( "mm" );
62 
63  case DEGREES:
64  return _( "deg" );
65 
66  case UNSCALED_UNITS:
67  break;
68  // no default: handle all cases
69  }
70 
71  return wxEmptyString;
72 }
Definition: common.h:145