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 <math/vector2d.h>
38 #include <common.h>
39 #include <convert_to_biu.h>
40 
41 //TODO: Abstract Base Units to a single class
42 
47 #define INDETERMINATE wxString( "..." )
48 
49 
51 inline int Mm2mils( double x ) { return KiROUND( x * 1000./25.4 ); }
52 
54 inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); }
55 
64 std::string Double2Str( double aValue );
65 
72 void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed = 1 );
73 
74 
84 double To_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils = false );
85 
91 wxString AngleToStringDegrees( double aAngle );
92 
111 wxString MessageTextFromValue( EDA_UNITS_T aUnits, double aValue, bool aUseMils = false );
112 
113 wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils = false );
114 
135 wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false,
136  bool aUseMils = false );
137 
142 double From_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils = false );
143 
144 
153 double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue,
154  bool aUseMils = false );
155 
165 int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMils = false );
166 
171 void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS_T& aUnits, bool& aUseMils );
172 
179 wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit, bool aUseMils = false );
180 
192 std::string FormatInternalUnits( int aValue );
193 
203 std::string FormatAngle( double aAngle );
204 
205 std::string FormatInternalUnits( const wxPoint& aPoint );
206 
207 std::string FormatInternalUnits( const wxSize& aSize );
208 
209 std::string FormatInternalUnits( const VECTOR2I& aPoint );
210 
211 
212 #endif // _BASE_UNITS_H_
int Mm2mils(double x)
Convert mm to mils.
Definition: base_units.h:51
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils=false)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:414
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
double From_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils=false)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:282
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils=false)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
int Mils2mm(double x)
Convert mils to mm.
Definition: base_units.h:54
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils=false)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:307
wxString AngleToStringDegrees(double aAngle)
Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string...
Definition: base_units.cpp:426
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol=false, bool aUseMils=false)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210
void FetchUnitsFromString(const wxString &aTextValue, EDA_UNITS_T &aUnits, bool &aUseMils)
Function FetchUnitsFromString writes any unit info found in the string to aUnits and aUseMils.
Definition: base_units.cpp:375
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed=1)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number.
Definition: base_units.cpp:178
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:465
The common library.
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils=false)
Get the units string for a given units type.
Definition: base_units.cpp:437
wxString MessageTextFromValue(EDA_UNITS_T aUnits, double aValue, bool aUseMils=false)
Function MessageTextFromValue is a helper to convert the double length aValue to a string in inches,...
Definition: base_units.cpp:132
EDA_UNITS_T
Definition: common.h:157
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:498