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 <confirm.h>
26#include <wx/textdlg.h>
29#include <common.h>
31#include <eda_draw_frame.h>
32#include <tool/tool_manager.h>
33#include <tool/actions.h>
34#include <tool/grid_menu.h>
35#include <tool/common_tools.h>
36#include <pgm_base.h>
38
39DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( wxWindow* aParent, wxWindow* aEventSource,
40 UNITS_PROVIDER* aProvider, GRID& aGrid ) :
42 m_unitsProvider( aProvider ), m_grid( aGrid ),
43 m_gridSizeX( aProvider, aEventSource, m_staticTextX, m_textX, m_staticTextXUnits, true ),
44 m_gridSizeY( aProvider, aEventSource, m_staticTextY, m_textY, m_staticTextYUnits, true )
45{
48
49 Layout();
50
51 // Now all widgets have the size fixed, call FinishDialogSettings
53}
54
56{
57 double gridX = m_gridSizeX.GetDoubleValue();
58
59 if( !m_gridSizeX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
60 {
61 wxMessageBox( _( "Grid size X out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
62 return false;
63 }
64
65 if( !m_checkLinked->IsChecked()
66 && !m_gridSizeY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
67 {
68 wxMessageBox( _( "Grid size Y out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
69 return false;
70 }
71
72 double gridY = m_checkLinked->IsChecked() ? gridX : m_gridSizeY.GetDoubleValue();
73
74 m_grid.name = m_textName->GetValue();
75 // Grid X/Y are always stored in millimeters so we can compare them easily
77 EDA_UNITS::MILLIMETRES, gridX );
79 EDA_UNITS::MILLIMETRES, gridY );
80
81 return true;
82}
83
84
85void DIALOG_GRID_SETTINGS::OnLinkedChecked( wxCommandEvent& event )
86{
87 m_textY->Enable( !m_checkLinked->IsChecked() );
88}
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:98
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.
This file is part of 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