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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <bitmaps.h>
21#include <wx/msgdlg.h>
24#include <common.h>
26#include <eda_draw_frame.h>
27#include <tool/tool_manager.h>
28#include <tool/actions.h>
29#include <tool/grid_menu.h>
30#include <tool/common_tools.h>
31#include <pgm_base.h>
33
34DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( wxWindow* aParent, wxWindow* aEventSource,
35 UNITS_PROVIDER* aProvider, GRID& aGrid ) :
37 m_unitsProvider( aProvider ), m_grid( aGrid ),
38 m_gridSizeX( aProvider, aEventSource, m_staticTextX, m_textX, m_staticTextXUnits, true ),
39 m_gridSizeY( aProvider, aEventSource, m_staticTextY, m_textY, m_staticTextYUnits, true )
40{
41 // Properties dialogs don't really want state-saving/restoring
42 OptOut( this );
43
46
47 Layout();
48
49 // Now all widgets have the size fixed, call FinishDialogSettings
51}
52
53
55{
56 if( !m_grid.x.IsEmpty() )
57 {
58 bool linked = ( m_grid.x == m_grid.y );
59 VECTOR2D grid = m_grid.ToDouble( m_unitsProvider->GetIuScale() );
60
61 m_textName->SetValue( m_grid.name );
62 m_checkLinked->SetValue( linked );
63 m_gridSizeX.SetDoubleValue( grid.x );
64
65 if( !linked )
66 m_gridSizeY.SetDoubleValue( grid.y );
67
68 m_textY->Enable( !linked );
69 }
70
71 return true;
72}
73
74
76{
77 double gridX = m_gridSizeX.GetDoubleValue();
78
79 if( !m_gridSizeX.Validate( 0.001, 1000.0, EDA_UNITS::MM ) )
80 {
81 wxMessageBox( _( "Grid size X out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
82 return false;
83 }
84
85 if( !m_checkLinked->IsChecked() && !m_gridSizeY.Validate( 0.001, 1000.0, EDA_UNITS::MM ) )
86 {
87 wxMessageBox( _( "Grid size Y out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
88 return false;
89 }
90
91 double gridY = m_checkLinked->IsChecked() ? gridX : m_gridSizeY.GetDoubleValue();
92
93 m_grid.name = m_textName->GetValue();
94 // Grid X/Y are always stored in millimeters so we can compare them easily
97
98 return true;
99}
100
101
102void DIALOG_GRID_SETTINGS::OnLinkedChecked( wxCommandEvent& event )
103{
104 m_textY->Enable( !m_checkLinked->IsChecked() );
105}
DIALOG_GRID_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Grid Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE)
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 OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:79
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...
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)
Return the string from aValue according to aUnits (inch, mm ...) for display.
see class PGM_BASE
Common grid settings, available to every frame.
VECTOR2< double > VECTOR2D
Definition vector2d.h:682