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
55{
56 double gridX = m_gridSizeX.GetDoubleValue();
57
58 if( !m_gridSizeX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
59 {
60 wxMessageBox( _( "Grid size X out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
61 return false;
62 }
63
64 if( !m_checkLinked->IsChecked()
65 && !m_gridSizeY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
66 {
67 wxMessageBox( _( "Grid size Y out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
68 return false;
69 }
70
71 double gridY = m_checkLinked->IsChecked() ? gridX : m_gridSizeY.GetDoubleValue();
72
73 m_grid.name = m_textName->GetValue();
74 // Grid X/Y are always stored in millimeters so we can compare them easily
76 EDA_UNITS::MILLIMETRES, gridX );
78 EDA_UNITS::MILLIMETRES, gridY );
79
80 return true;
81}
82
83
84void DIALOG_GRID_SETTINGS::OnLinkedChecked( wxCommandEvent& event )
85{
86 m_textY->Enable( !m_checkLinked->IsChecked() );
87}
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
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 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
wxString x
Definition: grid_settings.h:52
wxString name
Definition: grid_settings.h:51