KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_tuning_profiles.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
26#include <widgets/wx_panel.h>
28#include <bitmaps.h>
29#include <pcb_edit_frame.h>
30#include <grid_tricks.h>
31#include <layer_ids.h>
32#include <magic_enum.hpp>
33#include <pgm_base.h>
36
38 BOARD* aBoard,
39 std::shared_ptr<TUNING_PROFILES> aTimeDomainParameters ) :
40 PANEL_SETUP_TUNING_PROFILES_BASE( aParentWindow ),
41 m_tuningProfileParameters( std::move( aTimeDomainParameters ) ),
42 m_dlg( dynamic_cast<DIALOG_SHIM*>( aParentWindow ) ),
43 m_frame( aFrame ),
44 m_board( aFrame->GetBoard() ),
46{
47 Freeze();
48
51
52 Thaw();
53}
54
55
59
60
62{
63 m_tuningProfiles->DeleteAllPages();
64 SyncCopperLayers( m_board->GetCopperLayerCount() );
65
66 const std::vector<TUNING_PROFILE>& tuningProfiles = m_tuningProfileParameters->GetTuningProfiles();
67
68 for( const TUNING_PROFILE& profile : tuningProfiles )
69 {
71 m_tuningProfiles->AddPage( panel, profile.m_ProfileName, true );
72 panel->LoadProfile( profile );
73 }
74
75 return true;
76}
77
78
80{
81 if( !Validate() )
82 return false;
83
84 m_tuningProfileParameters->ClearTuningProfiles();
85
86 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
87 {
89 dynamic_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
90 TUNING_PROFILE profile = panel->GetProfile();
91 m_tuningProfileParameters->AddTuningProfile( std::move( profile ) );
92 }
93
94 return true;
95}
96
97
98void PANEL_SETUP_TUNING_PROFILES::SyncCopperLayers( const int aNumCopperLayers )
99{
103 m_layerNames.clear();
104 m_layerNamesToIDs.clear();
105
106 int layerIdx = 0;
107
108 for( const auto& layer : LSET::AllCuMask( aNumCopperLayers ).CuStack() )
109 {
110 wxString layerName = m_board->GetLayerName( layer );
111 m_layerNames.emplace_back( layerName );
112 m_layerNamesToIDs[layerName] = layer;
113 m_copperLayerIdsToIndex[layer] = layerIdx;
114 m_copperIndexToLayerId[layerIdx] = layer;
115 ++layerIdx;
116 }
117
118 if( m_prevLayerNamesToIDs.empty() )
120
121 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
122 {
124 static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
125 panel->UpdateLayerNames();
126 }
127}
128
129
131{
133 m_tuningProfiles->AddPage( panel, "Profile ", true );
134}
135
136
138{
139 if( const wxWindow* page = m_tuningProfiles->GetCurrentPage() )
140 {
141 const size_t pageIdx = m_tuningProfiles->FindPage( page );
142 m_tuningProfiles->RemovePage( pageIdx );
143 }
144}
145
146
148{
149 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
150 {
152 static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
153
154 if( !panel->ValidateProfile( i ) )
155 return false;
156 }
157
158 return true;
159}
160
161
163{
164 const int pageId = m_tuningProfiles->FindPage( panel );
165
166 if( pageId == wxNOT_FOUND )
167 return;
168
169 m_tuningProfiles->SetPageText( pageId, newName );
170}
171
172
173void PANEL_SETUP_TUNING_PROFILES::ImportSettingsFrom( const std::shared_ptr<TUNING_PROFILES>& aOtherParameters )
174{
175 std::shared_ptr<TUNING_PROFILES> savedSettings = m_tuningProfileParameters;
176
177 m_tuningProfileParameters = aOtherParameters;
179
180 m_tuningProfileParameters = std::move( savedSettings );
181}
182
183
185{
186 std::vector<wxString> names;
187
188 size_t profileCount = m_tuningProfiles->GetPageCount();
189
190 for( size_t i = 0; i < profileCount; ++i )
191 {
192 const auto* profilePage = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
193
194 if( const wxString& name = profilePage->GetProfileName(); name != wxEmptyString )
195 names.push_back( name );
196 }
197
198 return names;
199}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:582
PANEL_SETUP_TUNING_PROFILES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(719, 506), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::map< wxString, PCB_LAYER_ID > m_layerNamesToIDs
void OnRemoveTuningProfileClick(wxCommandEvent &event) override
Removes a tuning profile entry from the tuning profile grid.
void OnAddTuningProfileClick(wxCommandEvent &event) override
Adds a new tuning profile entry to the tuning profile grid.
void ImportSettingsFrom(const std::shared_ptr< TUNING_PROFILES > &aOtherParameters)
Load configuration from the given settings object.
std::map< wxString, PCB_LAYER_ID > m_prevLayerNamesToIDs
PCB_EDIT_FRAME * m_frame
The active edit frame.
std::map< int, PCB_LAYER_ID > m_copperIndexToLayerId
std::map< PCB_LAYER_ID, int > m_copperLayerIdsToIndex
bool Validate() override
Validates all data.
void SyncCopperLayers(int aNumCopperLayers)
Called when switching to this tab to make sure that any changes to the copper layer count made on the...
std::unique_ptr< UNITS_PROVIDER > m_unitsProvider
bool TransferDataToWindow() override
Load parameter data from the settings object.
PANEL_SETUP_TUNING_PROFILES(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame, BOARD *aBoard, std::shared_ptr< TUNING_PROFILES > aTimeDomainParameters)
std::shared_ptr< TUNING_PROFILES > m_tuningProfileParameters
The parameters object to load / save data from / to.
std::vector< wxString > GetDelayProfileNames() const
Returns all configured tuning profile names. Used by the netclass setup panel.
void UpdateProfileName(PANEL_SETUP_TUNING_PROFILE_INFO *panel, wxString newName) const
Update the notebook display of the name for a given panel.
bool TransferDataFromWindow() override
Save parameter data to the settings object.
DIALOG_SHIM * m_dlg
The parent dialog.
bool ValidateProfile(size_t aPageIndex)
Validate this panel's data.
void UpdateLayerNames()
Updates the displayed layer names in all grids.
void LoadProfile(const TUNING_PROFILE &aProfile)
Loads the given profile in to the panel.
TUNING_PROFILE GetProfile() const
Saves the panel to the given profile.
The main frame for Pcbnew.
STL namespace.
int GetUserUnits()
Return the currently selected user unit value for the interface.
BOARD * GetBoard()
see class PGM_BASE
Represents a single line in the tuning profile configuration grid.