KiCad PCB EDA Suite
units_provider.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) 2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef UNITS_PROVIDER_H
25#define UNITS_PROVIDER_H
26
27#include <eda_units.h>
28#include <origin_transforms.h>
29
30
32{
33public:
34 UNITS_PROVIDER( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
35 m_iuScale( aIuScale ),
36 m_userUnits( aUnits )
37 {}
38
40 {}
41
43 void SetUserUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }
44
45 const EDA_IU_SCALE& GetIuScale() const { return m_iuScale; }
46 // No SetIuScale(); scale is invariant
47
49 {
50 static ORIGIN_TRANSFORMS identityTransform;
51
52 return identityTransform;
53 }
54
67 wxString StringFromValue( double aValue, bool aAddUnitLabel = false,
69 {
71 aAddUnitLabel, aType );
72 }
73
74 wxString StringFromValue( const EDA_ANGLE& aValue, bool aAddUnitLabel = false )
75 {
77 aValue.AsDegrees(), aAddUnitLabel,
79 }
80
87 wxString MessageTextFromValue( double aValue, bool aAddUnitLabel = true,
89 {
91 aAddUnitLabel, aType );
92 }
93
94 wxString MessageTextFromValue( const EDA_ANGLE& aValue, bool aAddUnitLabel = true )
95 {
97 aValue.AsDegrees(), aAddUnitLabel,
99 }
100
108 int ValueFromString( const wxString& aTextValue, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE )
109 {
111 aTextValue, aType );
112
113 return KiROUND<double, int>( value );
114 }
115
116 EDA_ANGLE AngleValueFromString( const wxString& aTextValue )
117 {
119 aTextValue );
120
121 return EDA_ANGLE( angle, DEGREES_T );
122 }
123
124private:
127};
128
129#endif // UNITS_PROVIDER_H
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:112
double AsDegrees() const
Definition: eda_angle.h:149
A class to perform either relative or absolute display origin transforms for a single axis of a point...
EDA_ANGLE AngleValueFromString(const wxString &aTextValue)
EDA_UNITS m_userUnits
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aValue in internal units into a united string.
const EDA_IU_SCALE & m_iuScale
const EDA_IU_SCALE & GetIuScale() const
virtual ~UNITS_PROVIDER()
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
wxString StringFromValue(const EDA_ANGLE &aValue, bool aAddUnitLabel=false)
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aTextValue in aUnits to internal units used by the frame.
wxString MessageTextFromValue(const EDA_ANGLE &aValue, bool aAddUnitLabel=true)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
@ DEGREES_T
Definition: eda_angle.h:31
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:36
EDA_UNITS
Definition: eda_units.h:43
wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
Definition: eda_units.cpp:315
wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Returns the string from aValue according to aUnits (inch, mm ...) for display.
Definition: eda_units.cpp:225
double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
Definition: eda_units.cpp:445
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)