KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_settings.cpp
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) 2023 Mike Williams <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <nlohmann/json.hpp>
23#include <wx/translation.h>
25
26#include <units_provider.h>
27
28wxString GRID::MessageText( EDA_IU_SCALE aScale, EDA_UNITS aUnits, bool aDisplayUnits ) const
29{
30 EDA_DATA_TYPE type = EDA_DATA_TYPE::DISTANCE;
31
33 aScale, aUnits,
34 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MILLIMETRES, x, type ),
35 aDisplayUnits );
37 aScale, aUnits,
38 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MILLIMETRES, y, type ),
39 aDisplayUnits );
40
41 if( xStr == yStr )
42 return xStr;
43
44 return wxString::Format( wxS( "%s x %s" ), xStr, yStr );
45}
46
47wxString GRID::UserUnitsMessageText( UNITS_PROVIDER* aProvider, bool aDisplayUnits ) const
48{
49 return MessageText( aProvider->GetIuScale(), aProvider->GetUserUnits(), aDisplayUnits );
50}
51
52
54{
55 return VECTOR2D{
56 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MILLIMETRES, x ),
57 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MILLIMETRES, y ),
58 };
59}
60
61
62bool GRID::operator==( const GRID& aOther ) const
63{
64 return x == aOther.x && y == aOther.y;
65}
66
67
68bool operator!=( const GRID& lhs, const GRID& rhs )
69{
70 return !( lhs == rhs );
71}
72
73
74bool operator<( const GRID& lhs, const GRID& rhs )
75{
76 return lhs.name < rhs.name;
77}
78
79
80void to_json( nlohmann::json& j, const GRID& g )
81{
82 j = nlohmann::json{
83 { "name", g.name },
84 { "x", g.x },
85 { "y", g.y },
86 };
87}
88
89
90void from_json( const nlohmann::json& j, GRID& g )
91{
92 j.at( "name" ).get_to( g.name );
93 j.at( "x" ).get_to( g.x );
94 j.at( "y" ).get_to( g.y );
95}
const EDA_IU_SCALE & GetIuScale() const
EDA_UNITS GetUserUnits() const
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:38
EDA_UNITS
Definition: eda_units.h:46
bool operator<(const GRID &lhs, const GRID &rhs)
void from_json(const nlohmann::json &j, GRID &g)
bool operator!=(const GRID &lhs, const GRID &rhs)
void to_json(nlohmann::json &j, const GRID &g)
KICOMMON_API 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:404
KICOMMON_API 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:572
Common grid settings, available to every frame.
Definition: grid_settings.h:34
bool operator==(const GRID &aOther) const
wxString UserUnitsMessageText(UNITS_PROVIDER *aProvider, bool aDisplayUnits=true) const
Returns a string representation of the grid in the user's units.
wxString y
Definition: grid_settings.h:53
wxString MessageText(EDA_IU_SCALE aScale, EDA_UNITS aUnits, bool aDisplayUnits=true) const
Returns a string representation of the grid in specified units.
VECTOR2D ToDouble(EDA_IU_SCALE aScale) const
wxString x
Definition: grid_settings.h:52
wxString name
Definition: grid_settings.h:51