KiCad PCB EDA Suite
preview_utils.cpp File Reference

Go to the source code of this file.

Functions

static wxString formatPreviewDimension (double aVal, EDA_UNITS_T aUnits)
 

Function Documentation

◆ formatPreviewDimension()

static wxString formatPreviewDimension ( double  aVal,
EDA_UNITS_T  aUnits 
)
static

Definition at line 36 of file preview_utils.cpp.

37 {
38  int precision = 4;
39 
40  // show a sane precision for the preview, which doesn't need to
41  // be accurate down to the nanometre
42  switch( aUnits )
43  {
44  case MILLIMETRES:
45  precision = 2; // 10um
46  break;
47 
48  case INCHES:
49  precision = 4; // 0.1mil
50  break;
51 
52  case DEGREES:
53  precision = 1; // 0.1deg
54  break;
55 
56  case UNSCALED_UNITS:
57  break;
58  }
59 
60  const wxString fmtStr = wxString::Format( "%%.%df", precision );
61 
62  wxString str = wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
63 
64  const wxString symbol = GetAbbreviatedUnitsLabel( aUnits, false );
65 
66  if( symbol.size() )
67  str << " " << symbol;
68 
69  return str;
70 }
const string & str
Definition: json11.cpp:596
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
Definition: common.h:161
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
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432

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

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