KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_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) 1992-2023 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#include <bitmaps.h>
25#include <wx/msgdlg.h>
28#include <common.h>
30#include <eda_draw_frame.h>
31#include <tool/tool_manager.h>
32#include <tool/actions.h>
33#include <tool/grid_menu.h>
34#include <tool/common_tools.h>
35#include <pgm_base.h>
37
38DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( wxWindow* aParent, wxWindow* aEventSource,
39 UNITS_PROVIDER* aProvider, GRID& aGrid ) :
41 m_unitsProvider( aProvider ), m_grid( aGrid ),
42 m_gridSizeX( aProvider, aEventSource, m_staticTextX, m_textX, m_staticTextXUnits, true ),
43 m_gridSizeY( aProvider, aEventSource, m_staticTextY, m_textY, m_staticTextYUnits, true )
44{
47
48 Layout();
49
50 // Now all widgets have the size fixed, call FinishDialogSettings
52}
53
54
56{
57 if( !m_grid.x.IsEmpty() )
58 {
59 bool linked = ( m_grid.x == m_grid.y );
61
62 m_textName->SetValue( m_grid.name );
63 m_checkLinked->SetValue( linked );
65
66 if( !linked )
68
69 m_textY->Enable( !linked );
70 }
71
72 return true;
73}
74
75
77{
78 double gridX = m_gridSizeX.GetDoubleValue();
79
80 if( !m_gridSizeX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
81 {
82 wxMessageBox( _( "Grid size X out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
83 return false;
84 }
85
86 if( !m_checkLinked->IsChecked()
87 && !m_gridSizeY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
88 {
89 wxMessageBox( _( "Grid size Y out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
90 return false;
91 }
92
93 double gridY = m_checkLinked->IsChecked() ? gridX : m_gridSizeY.GetDoubleValue();
94
95 m_grid.name = m_textName->GetValue();
96 // Grid X/Y are always stored in millimeters so we can compare them easily
98 EDA_UNITS::MILLIMETRES, gridX );
100 EDA_UNITS::MILLIMETRES, gridY );
101
102 return true;
103}
104
105
106void DIALOG_GRID_SETTINGS::OnLinkedChecked( wxCommandEvent& event )
107{
108 m_textY->Enable( !m_checkLinked->IsChecked() );
109}
Class DIALOG_GRID_SETTINGS_BASE.
UNITS_PROVIDER * m_unitsProvider
void OnLinkedChecked(wxCommandEvent &event) override
DIALOG_GRID_SETTINGS(wxWindow *aParent, wxWindow *aEventSource, UNITS_PROVIDER *aProvider, GRID &aGrid)
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const EDA_IU_SCALE & GetIuScale() const
virtual double GetDoubleValue()
Return the current value in Internal Units.
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
The common library.
#define _(s)
KICOMMON_API 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:300
see class PGM_BASE
Common grid settings, available to every frame.
Definition: grid_settings.h:34
wxString y
Definition: grid_settings.h:53
VECTOR2D ToDouble(EDA_IU_SCALE aScale) const
wxString x
Definition: grid_settings.h:52
wxString name
Definition: grid_settings.h:51