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, see <https://www.gnu.org/licenses/>.
18 */
19
23#include <bitmaps.h>
24#include <pcb_edit_frame.h>
25#include <grid_tricks.h>
26#include <layer_ids.h>
27#include <magic_enum.hpp>
28#include <pgm_base.h>
30
32 BOARD* aBoard,
33 std::shared_ptr<TUNING_PROFILES> aTimeDomainParameters ) :
34 PANEL_SETUP_TUNING_PROFILES_BASE( aParentWindow ),
35 m_tuningProfileParameters( std::move( aTimeDomainParameters ) ),
36 m_dlg( dynamic_cast<DIALOG_SHIM*>( aParentWindow ) ),
37 m_frame( aFrame ),
38 m_board( aFrame->GetBoard() ),
39 m_unitsProvider( std::make_unique<UNITS_PROVIDER>( pcbIUScale, m_frame->GetUserUnits() ) )
40{
41 Freeze();
42
45
46 Thaw();
47}
48
49
53
54
56{
57 m_tuningProfiles->DeleteAllPages();
58 SyncCopperLayers( m_board->GetCopperLayerCount() );
59
60 const std::vector<TUNING_PROFILE>& tuningProfiles = m_tuningProfileParameters->GetTuningProfiles();
61
62 for( const TUNING_PROFILE& profile : tuningProfiles )
63 {
65 m_tuningProfiles->AddPage( panel, profile.m_ProfileName, true );
66 panel->LoadProfile( profile );
67 }
68
69 return true;
70}
71
72
74{
75 if( !Validate() )
76 return false;
77
78 m_tuningProfileParameters->ClearTuningProfiles();
79
80 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
81 {
82 auto* panel = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
83 TUNING_PROFILE profile = panel->GetProfile();
84 m_tuningProfileParameters->AddTuningProfile( std::move( profile ) );
85 }
86
87 return true;
88}
89
90
91void PANEL_SETUP_TUNING_PROFILES::SyncCopperLayers( const int aNumCopperLayers )
92{
96 m_layerNames.clear();
97 m_layerNamesToIDs.clear();
98
99 int layerIdx = 0;
100
101 for( const auto& layer : LSET::AllCuMask( aNumCopperLayers ).CuStack() )
102 {
103 wxString layerName = m_board->GetLayerName( layer );
104 m_layerNames.emplace_back( layerName );
105 m_layerNamesToIDs[layerName] = layer;
106 m_copperLayerIdsToIndex[layer] = layerIdx;
107 m_copperIndexToLayerId[layerIdx] = layer;
108 ++layerIdx;
109 }
110
111 if( m_prevLayerNamesToIDs.empty() )
113
114 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
115 {
116 auto* panel = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
117 panel->UpdateLayerNames();
118 }
119}
120
121
123{
125 m_tuningProfiles->AddPage( panel, "Profile ", true );
126}
127
128
130{
131 if( const wxWindow* page = m_tuningProfiles->GetCurrentPage() )
132 {
133 const size_t pageIdx = m_tuningProfiles->FindPage( page );
134 m_tuningProfiles->RemovePage( pageIdx );
135 }
136}
137
138
140{
141 for( size_t i = 0; i < m_tuningProfiles->GetPageCount(); ++i )
142 {
144 static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
145
146 if( !panel->ValidateProfile( i ) )
147 return false;
148 }
149
150 return true;
151}
152
153
155{
156 const int pageId = m_tuningProfiles->FindPage( panel );
157
158 if( pageId == wxNOT_FOUND )
159 return;
160
161 m_tuningProfiles->SetPageText( pageId, newName );
162}
163
164
165void PANEL_SETUP_TUNING_PROFILES::ImportSettingsFrom( const std::shared_ptr<TUNING_PROFILES>& aOtherParameters )
166{
167 std::shared_ptr<TUNING_PROFILES> savedSettings = m_tuningProfileParameters;
168
169 m_tuningProfileParameters = aOtherParameters;
171
172 m_tuningProfileParameters = std::move( savedSettings );
173}
174
175
177{
178 std::vector<wxString> names;
179
180 size_t profileCount = m_tuningProfiles->GetPageCount();
181
182 for( size_t i = 0; i < profileCount; ++i )
183 {
184 const auto* profilePage = static_cast<PANEL_SETUP_TUNING_PROFILE_INFO*>( m_tuningProfiles->GetPage( i ) );
185
186 if( const wxString& name = profilePage->GetProfileName(); name != wxEmptyString )
187 names.push_back( name );
188 }
189
190 return names;
191}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:65
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
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.
see class PGM_BASE
Represents a single line in the tuning profile configuration grid.