KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_snapping.h
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 3
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#ifndef PANEL_SNAPPING_H
21#define PANEL_SNAPPING_H
22
23#include <functional>
24#include <vector>
25
26#include <frame_type.h>
27#include <panel_snapping_base.h>
29
38{
39public:
48
56 PANEL_SNAPPING( wxWindow* aParent, FRAME_T aFrameType, int* aGridSnap,
57 SNAP_INFERENCE_SETTINGS* aInference, MAGNETIC_SETTINGS* aMagnetics,
58 std::function<VALUES()> aDefaults );
59
60 bool TransferDataToWindow() override;
61 bool TransferDataFromWindow() override;
62
63 void ResetPanel() override;
64
65private:
66 void load( const VALUES& aValues );
67
69
73 std::function<VALUES()> m_defaults;
74
75 std::vector<MAGNETIC_OPTIONS> m_padOptions;
76 std::vector<MAGNETIC_OPTIONS> m_trackOptions;
77 std::vector<MAGNETIC_OPTIONS> m_graphicsOptions;
78};
79
80
87std::vector<MAGNETIC_OPTIONS> MagneticSnapOptions( bool aRouting );
88
94int MagneticSnapIndex( const std::vector<MAGNETIC_OPTIONS>& aOptions, MAGNETIC_OPTIONS aValue );
95
99MAGNETIC_OPTIONS MagneticSnapValue( const std::vector<MAGNETIC_OPTIONS>& aOptions, int aIndex );
100
101
108template <typename SETTINGS_T>
109PANEL_SNAPPING* CreateSnappingPanel( wxWindow* aParent, SETTINGS_T* aCfg, FRAME_T aFrameType,
110 SNAP_INFERENCE_SETTINGS SETTINGS_T::* aInference = nullptr,
111 MAGNETIC_SETTINGS SETTINGS_T::* aMagnetics = nullptr )
112{
113 auto valuesOf =
114 [aInference, aMagnetics]( const SETTINGS_T& aSettings )
115 {
117 values.gridSnap = aSettings.m_Window.grid.snap;
118
119 if( aInference )
120 values.inference = aSettings.*aInference;
121
122 if( aMagnetics )
123 values.magnetics = aSettings.*aMagnetics;
124
125 return values;
126 };
127
128 return new PANEL_SNAPPING( aParent, aFrameType, &aCfg->m_Window.grid.snap,
129 aInference ? &( aCfg->*aInference ) : nullptr,
130 aMagnetics ? &( aCfg->*aMagnetics ) : nullptr,
131 [valuesOf]()
132 {
133 SETTINGS_T defaults;
134 defaults.Load(); // Loading without a file gives the defaults
135 return valuesOf( defaults );
136 } );
137}
138
139#endif
PANEL_SNAPPING_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
The snapping preferences page.
std::function< VALUES()> m_defaults
void ResetPanel() override
Reset the contents of this panel.
bool TransferDataToWindow() override
bool TransferDataFromWindow() override
std::vector< MAGNETIC_OPTIONS > m_padOptions
SNAP_INFERENCE_SETTINGS * m_inference
MAGNETIC_SETTINGS * m_magnetics
void load(const VALUES &aValues)
std::vector< MAGNETIC_OPTIONS > m_trackOptions
std::vector< MAGNETIC_OPTIONS > m_graphicsOptions
PANEL_SNAPPING(wxWindow *aParent, FRAME_T aFrameType, int *aGridSnap, SNAP_INFERENCE_SETTINGS *aInference, MAGNETIC_SETTINGS *aMagnetics, std::function< VALUES()> aDefaults)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
int MagneticSnapIndex(const std::vector< MAGNETIC_OPTIONS > &aOptions, MAGNETIC_OPTIONS aValue)
The position of aValue in aOptions, falling back to the "never" entry for a value the editor does not...
PANEL_SNAPPING * CreateSnappingPanel(wxWindow *aParent, SETTINGS_T *aCfg, FRAME_T aFrameType, SNAP_INFERENCE_SETTINGS SETTINGS_T::*aInference=nullptr, MAGNETIC_SETTINGS SETTINGS_T::*aMagnetics=nullptr)
Build the snapping page for an editor.
std::vector< MAGNETIC_OPTIONS > MagneticSnapOptions(bool aRouting)
The object snapping modes an editor offers.
MAGNETIC_OPTIONS MagneticSnapValue(const std::vector< MAGNETIC_OPTIONS > &aOptions, int aIndex)
The mode at aIndex, or "never" if the index is out of range.
MAGNETIC_OPTIONS
One editor's snapping settings by value, so the page can also be filled from a settings object that i...
SNAP_INFERENCE_SETTINGS inference
MAGNETIC_SETTINGS magnetics