KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <mike@mikebwilliams.com>
5 * Copyright The 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::MM, x, type ),
35 aDisplayUnits );
37 aScale, aUnits,
38 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MM, 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( EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MM, x ),
56 EDA_UNIT_UTILS::UI::DoubleValueFromString( aScale, EDA_UNITS::MM, y ) );
57}
58
59
60bool GRID::operator==( const GRID& aOther ) const
61{
62 return x == aOther.x && y == aOther.y && name == aOther.name;
63}
64
65
66bool operator!=( const GRID& lhs, const GRID& rhs )
67{
68 return !( lhs == rhs );
69}
70
71
72bool operator<( const GRID& lhs, const GRID& rhs )
73{
74 return lhs.name < rhs.name;
75}
76
77
78void to_json( nlohmann::json& j, const GRID& g )
79{
80 j = nlohmann::json{
81 { "name", g.name },
82 { "x", g.x },
83 { "y", g.y },
84 };
85}
86
87
88void from_json( const nlohmann::json& j, GRID& g )
89{
90 j.at( "name" ).get_to( g.name );
91 j.at( "x" ).get_to( g.x );
92 j.at( "y" ).get_to( g.y );
93}
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:361
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
Definition: eda_units.cpp:497
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
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694