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 79 of file preview_utils.cpp.

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

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

80 {
81  int precision = 4;
82 
83  // show a sane precision for the preview, which doesn't need to
84  // be accurate down to the nanometre
85  switch( aUnits )
86  {
87  case MILLIMETRES:
88  precision = 2; // 10um
89  break;
90  case INCHES:
91  precision = 4; // 1mil
92  break;
93  case DEGREES:
94  precision = 1; // 0.1deg (limit of formats anyway)
95  break;
96  case UNSCALED_UNITS:
97  break;
98  }
99 
100  const wxString fmtStr = wxString::Format( "%%.%df", precision );
101 
102  wxString str = wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
103 
104  const wxString symbol = getDimensionUnit( aUnits );
105 
106  if( symbol.size() )
107  str << " " << symbol;
108 
109  return str;
110 }
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 57 of file preview_utils.cpp.

References DEGREES, INCHES, MILLIMETRES, and UNSCALED_UNITS.

Referenced by formatPreviewDimension().

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