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
27#include <bitmaps.h>
28#include <pcb_edit_frame.h>
29#include <grid_tricks.h>
30#include <layer_ids.h>
31#include <magic_enum.hpp>
32#include <pgm_base.h>
34
36 BOARD* aBoard,
37 std::shared_ptr<TUNING_PROFILES> aTimeDomainParameters ) :
38 PANEL_SETUP_TUNING_PROFILES_BASE( aParentWindow ),
39 m_tuningProfileParameters( std::move( aTimeDomainParameters ) ),
40 m_dlg( dynamic_cast<DIALOG_SHIM*>( aParentWindow ) ),
41 m_frame( aFrame ),
42 m_board( aFrame->GetBoard() ),
44{
45 Freeze();
46
49
50 Thaw();
51}
52
53
57
58
60{
61 m_tuningProfiles->DeleteAllPages();
62 SyncCopperLayers( m_board->GetCopperLayerCount() );
63
64 const std::vector<TUNING_PROFILE>& tuningProfiles = m_tuningProfileParameters->GetTuningProfiles();
65
66 for( const TUNING_PROFILE& profile : tuningProfiles )
67 {
69 m_tuningProfiles->AddPage( panel, profile.m_ProfileName, true );
70 panel->LoadProfile( profile );
71 }
72
73 return true;
74}
75
76
78{
79 if( !Validate() )
80 return false;
81
82 m_tuningProfileParameters->ClearTuningProfiles();
83
84 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
85 {
86 auto* panel = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
87 TUNING_PROFILE profile = panel->GetProfile();
88 m_tuningProfileParameters->AddTuningProfile( std::move( profile ) );
89 }
90
91 return true;
92}
93
94
95void PANEL_SETUP_TUNING_PROFILES::SyncCopperLayers( const int aNumCopperLayers )
96{
100 m_layerNames.clear();
101 m_layerNamesToIDs.clear();
102
103 int layerIdx = 0;
104
105 for( const auto& layer : LSET::AllCuMask( aNumCopperLayers ).CuStack() )
106 {
107 wxString layerName = m_board->GetLayerName( layer );
108 m_layerNames.emplace_back( layerName );
109 m_layerNamesToIDs[layerName] = layer;
110 m_copperLayerIdsToIndex[layer] = layerIdx;
111 m_copperIndexToLayerId[layerIdx] = layer;
112 ++layerIdx;
113 }
114
115 if( m_prevLayerNamesToIDs.empty() )
117
118 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
119 {
120 auto* panel = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
121 panel->UpdateLayerNames();
122 }
123}
124
125
127{
129 m_tuningProfiles->AddPage( panel, "Profile ", true );
130}
131
132
134{
135 if( const wxWindow* page = m_tuningProfiles->GetCurrentPage() )
136 {
137 const size_t pageIdx = m_tuningProfiles->FindPage( page );
138 m_tuningProfiles->RemovePage( pageIdx );
139 }
140}
141
142
144{
145 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
146 {
148 static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
149
150 if( !panel->ValidateProfile( i ) )
151 return false;
152 }
153
154 return true;
155}
156
157
159{
160 const int pageId = m_tuningProfiles->FindPage( panel );
161
162 if( pageId == wxNOT_FOUND )
163 return;
164
165 m_tuningProfiles->SetPageText( pageId, newName );
166}
167
168
169void PANEL_SETUP_TUNING_PROFILES::ImportSettingsFrom( const std::shared_ptr<TUNING_PROFILES>& aOtherParameters )
170{
171 std::shared_ptr<TUNING_PROFILES> savedSettings = m_tuningProfileParameters;
172
173 m_tuningProfileParameters = aOtherParameters;
175
176 m_tuningProfileParameters = std::move( savedSettings );
177}
178
179
181{
182 std::vector<wxString> names;
183
184 size_t profileCount = m_tuningProfiles->GetPageCount();
185
186 for( size_t i = 0; i < profileCount; ++i )
187 {
188 const auto* profilePage = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
189
190 if( const wxString& name = profilePage->GetProfileName(); name != wxEmptyString )
191 names.push_back( name );
192 }
193
194 return names;
195}
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 LoadProfile(const TUNING_PROFILE &aProfile)
Loads the given profile in to the panel.
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.