KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_copper_zones.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 (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <wx/radiobut.h>
23#include <wx/statbox.h>
24#include <kiface_base.h>
25#include <confirm.h>
26#include <pcb_edit_frame.h>
27#include <pcbnew_settings.h>
28#include <zones.h>
29#include <widgets/unit_binder.h>
31#include <zone.h>
32#include <zone_settings_bag.h>
33#include <pad.h>
35#include <tool/tool_manager.h>
38#include <tools/pcb_actions.h>
39
40
42{
43public:
44 // The dialog can be closed for several reasons.
51
52 DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE* aZone, ZONE_SETTINGS* aSettings,
53 CONVERT_SETTINGS* aConvertSettings );
54
55 ~DIALOG_COPPER_ZONE() override;
56
57 bool TransferDataToWindow() override;
58 bool TransferDataFromWindow() override;
59
61
62private:
63 void OnLayerSelection( wxDataViewEvent& event ) override;
64 void OnUpdateUI( wxUpdateUIEvent& ) override;
65 void onZoneManager( wxCommandEvent& event ) override;
66
67private:
71 ZONE_SETTINGS_BAG m_zoneSettingsBag; // Local storage of settings
72
74 wxRadioButton* m_rbCenterline;
75 wxRadioButton* m_rbEnvelope;
76 wxStaticText* m_gapLabel;
77 wxTextCtrl* m_gapCtrl;
78 wxStaticText* m_gapUnits;
82
84};
85
86
87int InvokeCopperZonesEditor( PCB_BASE_FRAME* aCaller, ZONE* aZone, ZONE_SETTINGS* aSettings,
88 CONVERT_SETTINGS* aConvertSettings )
89{
90 DIALOG_COPPER_ZONE dlg( aCaller, aZone, aSettings, aConvertSettings );
91
92 dlg.ShowModal();
93
94 switch( dlg.GetReturnValue() )
95 {
97 return wxID_OK;
98
100 aCaller->CallAfter(
101 [aCaller]()
102 {
104 } );
105
106 return wxID_OK;
107
108 default:
110 return wxID_CANCEL;
111 }
112}
113
114
116 CONVERT_SETTINGS* aConvertSettings ) :
117 DIALOG_COPPER_ZONE_BASE( aParent ),
118 m_Parent( aParent ),
119 m_zone( aZone ),
120 m_zoneSettingsBag( aZone, aSettings ),
121 m_convertSettings( aConvertSettings ),
122 m_rbCenterline( nullptr ),
123 m_rbEnvelope( nullptr ),
124 m_cbDeleteOriginals( nullptr ),
126{
127 m_ptr = aSettings;
129
130 if( aSettings->m_TeardropType != TEARDROP_TYPE::TD_NONE )
131 SetTitle( _( "Legacy Teardrop Properties" ) );
132
133 if( aConvertSettings )
134 {
135 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY, _( "Conversion Settings" ) );
136 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
137
138 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
139 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
140
141 bConvertSizer->AddSpacer( 2 );
142 m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
143 bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
144
145 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
146 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
147 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
149 m_gap->SetValue( m_convertSettings->m_Gap );
150
151 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
152 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 );
153 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 );
154 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 );
155 bConvertSizer->AddSpacer( 2 );
156 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
157
158 bConvertSizer->AddSpacer( 6 );
159 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) );
160 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
161
162 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
163 SetTitle( _( "Convert to Copper Zone" ) );
164 }
165 else
166 {
167 m_gapLabel = nullptr;
168 m_gapCtrl = nullptr;
169 m_gapUnits = nullptr;
170 m_gap = nullptr;
171 }
172
173 // A zone still in creation (ie: not yet in the document) can't be edited by the Zone Manager
174 if( !aZone )
175 m_openZoneManager->Hide();
176
178 m_sizerRight->Add( m_panelZoneProperties, 1, wxEXPAND, 5 );
179
181
183}
184
185
190
191
193{
195 {
196 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
197 m_rbEnvelope->SetValue( true );
198 else
199 m_rbCenterline->SetValue( true );
200
201 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
202 m_gap->Enable( m_rbEnvelope->GetValue() );
203 }
204
205 m_panelZoneProperties->SetZone( m_zone );
206 return true;
207}
208
209
210void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
211{
212 if( m_gap )
213 m_gap->Enable( m_rbEnvelope->GetValue() );
214}
215
216
218{
219 if( m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.empty() )
220 {
221 DisplayError( this, _( "No layer selected." ) );
222 return false;
223 }
224
225 if( !m_panelZoneProperties->TransferZoneSettingsFromWindow() )
226 return false;
227
229 {
230 if( m_rbEnvelope->GetValue() )
231 m_convertSettings->m_Strategy = BOUNDING_HULL;
232 else
233 m_convertSettings->m_Strategy = CENTERLINE;
234
235 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
236 m_convertSettings->m_Gap = m_gap->GetIntValue();
237 }
238
239 *m_ptr = *m_zoneSettingsBag.GetZoneSettings( m_zone );
241 return true;
242}
243
244
245void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
246{
247 if( event.GetColumn() != 0 )
248 return;
249
250 int row = m_layers->ItemToRow( event.GetItem() );
251
252 bool checked = m_layers->GetToggleValue( row, 0 );
253
254 wxVariant layerID;
255 m_layers->GetValue( layerID, row, 2 );
256
257 m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
258}
259
260
261void DIALOG_COPPER_ZONE::onZoneManager( wxCommandEvent& event )
262{
264 {
266 Close();
267 }
268}
int GetCopperLayerCount() const
Definition board.cpp:985
DIALOG_COPPER_ZONE_BASE(wxWindow *parent, wxWindowID id=ID_DIALOG_COPPER_ZONE_BASE, const wxString &title=_("Copper Zone Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
bool TransferDataFromWindow() override
ZONE_SETTINGS_BAG m_zoneSettingsBag
wxRadioButton * m_rbCenterline
bool TransferDataToWindow() override
void OnLayerSelection(wxDataViewEvent &event) override
CONVERT_SETTINGS * m_convertSettings
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE *aZone, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
PCB_BASE_FRAME * m_Parent
PANEL_ZONE_PROPERTIES * m_panelZoneProperties
void OnUpdateUI(wxUpdateUIEvent &) override
void onZoneManager(wxCommandEvent &event) override
wxRadioButton * m_rbEnvelope
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static TOOL_ACTION zonesManager
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
ZONE_SETTINGS handles zones parameters.
TEARDROP_TYPE m_TeardropType
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE *aZone, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
#define _(s)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
@ CENTERLINE
@ BOUNDING_HULL