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>
28#include <panel_snapping_base.h>
30
39{
40public:
49
58 PANEL_SNAPPING( wxWindow* aParent, FRAME_T aFrameType, KIGFX::GRID_SNAPPING* aGridSnap,
59 SNAP_INFERENCE_SETTINGS* aInference, MAGNETIC_SETTINGS* aMagnetics,
60 std::function<VALUES()> aDefaults );
61
62 bool TransferDataToWindow() override;
63 bool TransferDataFromWindow() override;
64
65 void ResetPanel() override;
66
67private:
68 void load( const VALUES& aValues );
69
71
75 std::function<VALUES()> m_defaults;
76
77 std::vector<MAGNETIC_OPTIONS> m_padOptions;
78 std::vector<MAGNETIC_OPTIONS> m_trackOptions;
79 std::vector<MAGNETIC_OPTIONS> m_graphicsOptions;
80};
81
82
89std::vector<MAGNETIC_OPTIONS> MagneticSnapOptions( bool aRouting );
90
96int MagneticSnapIndex( const std::vector<MAGNETIC_OPTIONS>& aOptions, MAGNETIC_OPTIONS aValue );
97
101MAGNETIC_OPTIONS MagneticSnapValue( const std::vector<MAGNETIC_OPTIONS>& aOptions, int aIndex );
102
103
110template <typename SETTINGS_T>
111PANEL_SNAPPING* CreateSnappingPanel( wxWindow* aParent, SETTINGS_T* aCfg, FRAME_T aFrameType,
112 SNAP_INFERENCE_SETTINGS SETTINGS_T::* aInference = nullptr,
113 MAGNETIC_SETTINGS SETTINGS_T::* aMagnetics = nullptr )
114{
115 auto valuesOf =
116 [aInference, aMagnetics]( const SETTINGS_T& aSettings )
117 {
119 values.gridSnap = aSettings.m_Window.grid.snap;
120
121 if( aInference )
122 values.inference = aSettings.*aInference;
123
124 if( aMagnetics )
125 values.magnetics = aSettings.*aMagnetics;
126
127 return values;
128 };
129
130 return new PANEL_SNAPPING( aParent, aFrameType, &aCfg->m_Window.grid.snap,
131 aInference ? &( aCfg->*aInference ) : nullptr,
132 aMagnetics ? &( aCfg->*aMagnetics ) : nullptr,
133 [valuesOf]()
134 {
135 SETTINGS_T defaults;
136 defaults.Load(); // Loading without a file gives the defaults
137 return valuesOf( defaults );
138 } );
139}
140
141#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
PANEL_SNAPPING(wxWindow *aParent, FRAME_T aFrameType, KIGFX::GRID_SNAPPING *aGridSnap, SNAP_INFERENCE_SETTINGS *aInference, MAGNETIC_SETTINGS *aMagnetics, std::function< VALUES()> aDefaults)
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
KIGFX::GRID_SNAPPING * m_gridSnap
std::vector< MAGNETIC_OPTIONS > m_graphicsOptions
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...
KIGFX::GRID_SNAPPING gridSnap
SNAP_INFERENCE_SETTINGS inference
MAGNETIC_SETTINGS magnetics