KiCad PCB EDA Suite
base_units.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 CERN
5  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
32 #ifndef _BASE_UNITS_H_
33 #define _BASE_UNITS_H_
34 
35 #include <string>
36 
37 #include <eda_units.h>
38 #include <convert_to_biu.h>
39 #include <math/vector2d.h>
40 
41 //TODO: Abstract Base Units to a single class
42 
47 #define INDETERMINATE_STATE _( "-- mixed values --" )
48 #define INDETERMINATE_ACTION _( "-- leave unchanged --" )
49 
50 
51 // PCBNew doesn't support a bold style so we want to allow text thicknesses
52 // that achieve the same effect
53 #if defined( PCBNEW )
54 #define ALLOW_BOLD_THICKNESS true
55 #else
56 #define ALLOW_BOLD_THICKNESS IsBold()
57 #endif
58 
62 int Mm2mils( double x );
63 
67 int Mils2mm( double x );
68 
77 double To_User_Unit( EDA_UNITS aUnit, double aValue );
78 
98 wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel = true,
100 
101 wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel = true,
103 
104 wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel = true,
106 
126 wxString StringFromValue( EDA_UNITS aUnit, double aValue, bool aAddUnitSymbol = false,
128 
133 double From_User_Unit( EDA_UNITS aUnit, double aValue );
134 
135 
145 double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
147 
157 long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
159 
164 void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits );
165 
174 
186 std::string FormatInternalUnits( int aValue );
187 
197 std::string FormatAngle( double aAngle );
198 
199 std::string FormatInternalUnits( const wxPoint& aPoint );
200 
201 std::string FormatInternalUnits( const wxSize& aSize );
202 
203 std::string FormatInternalUnits( const VECTOR2I& aPoint );
204 
205 
206 #endif // _BASE_UNITS_H_
int Mm2mils(double x)
Convert mm to mils.
Definition: base_units.cpp:56
wxString MessageTextFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function MessageTextFromValue is a helper to convert the double length aValue to a string in inches,...
Definition: base_units.cpp:120
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:307
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:31
void FetchUnitsFromString(const wxString &aTextValue, EDA_UNITS &aUnits)
Function FetchUnitsFromString writes any unit info found in the string to aUnits.
Definition: base_units.cpp:387
Define a general 2D-vector/point.
Definition: vector2d.h:61
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:416
int Mils2mm(double x)
Convert mils to mm.
Definition: base_units.cpp:62
wxString StringFromValue(EDA_UNITS aUnit, double aValue, bool aAddUnitSymbol=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:204
EDA_UNITS
Definition: eda_units.h:38
double From_User_Unit(EDA_UNITS aUnit, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:282
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:485
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
Definition: base_units.cpp:424
double To_User_Unit(EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:68
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:520