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, 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{
45 // Properties dialogs don't really want state-saving/restoring
46 OptOut( this );
47
50
51 Layout();
52
53 // Now all widgets have the size fixed, call FinishDialogSettings
55}
56
57
59{
60 if( !m_grid.x.IsEmpty() )
61 {
62 bool linked = ( m_grid.x == m_grid.y );
63 VECTOR2D grid = m_grid.ToDouble( m_unitsProvider->GetIuScale() );
64
65 m_textName->SetValue( m_grid.name );
66 m_checkLinked->SetValue( linked );
67 m_gridSizeX.SetDoubleValue( grid.x );
68
69 if( !linked )
70 m_gridSizeY.SetDoubleValue( grid.y );
71
72 m_textY->Enable( !linked );
73 }
74
75 return true;
76}
77
78
80{
81 double gridX = m_gridSizeX.GetDoubleValue();
82
83 if( !m_gridSizeX.Validate( 0.001, 1000.0, EDA_UNITS::MM ) )
84 {
85 wxMessageBox( _( "Grid size X out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
86 return false;
87 }
88
89 if( !m_checkLinked->IsChecked() && !m_gridSizeY.Validate( 0.001, 1000.0, EDA_UNITS::MM ) )
90 {
91 wxMessageBox( _( "Grid size Y out of range." ), _( "Error" ), wxOK | wxICON_ERROR );
92 return false;
93 }
94
95 double gridY = m_checkLinked->IsChecked() ? gridX : m_gridSizeY.GetDoubleValue();
96
97 m_grid.name = m_textName->GetValue();
98 // Grid X/Y are always stored in millimeters so we can compare them easily
101
102 return true;
103}
104
105
106void DIALOG_GRID_SETTINGS::OnLinkedChecked( wxCommandEvent& event )
107{
108 m_textY->Enable( !m_checkLinked->IsChecked() );
109}
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:82
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:694