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

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

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

59 {
60  int precision = 4;
61 
62  // show a sane precision for the preview, which doesn't need to
63  // be accurate down to the nanometre
64  switch( aUnits )
65  {
66  case MILLIMETRES:
67  precision = 2; // 10um
68  break;
69  case INCHES:
70  precision = 4; // 1mil
71  break;
72  case DEGREES:
73  precision = 1; // 0.1deg (limit of formats anyway)
74  break;
75  case UNSCALED_UNITS:
76  break;
77  }
78 
79  const wxString fmtStr = wxString::Format( "%%.%df", precision );
80 
81  wxString str = wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
82 
83  const wxString symbol = getDimensionUnit( aUnits );
84 
85  if( symbol.size() )
86  str << " " << symbol;
87 
88  return str;
89 }
static wxString getDimensionUnit(EDA_UNITS_T aUnits)
Definition: common.h:144
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 36 of file preview_utils.cpp.

References DEGREES, INCHES, MILLIMETRES, and UNSCALED_UNITS.

Referenced by formatPreviewDimension().

37 {
38  switch( aUnits )
39  {
40  case INCHES:
41  return _( "\"" );
42 
43  case MILLIMETRES:
44  return _( "mm" );
45 
46  case DEGREES:
47  return _( "deg" );
48 
49  case UNSCALED_UNITS:
50  break;
51  // no default: handle all cases
52  }
53 
54  return wxEmptyString;
55 }
Definition: common.h:144