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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/radiobut.h>
27#include <wx/statbox.h>
28#include <kiface_base.h>
29#include <confirm.h>
30#include <pcb_edit_frame.h>
31#include <pcbnew_settings.h>
32#include <zones.h>
33#include <widgets/unit_binder.h>
35#include <zone.h>
36#include <zone_settings_bag.h>
37#include <pad.h>
39#include <tool/tool_manager.h>
42#include <tools/pcb_actions.h>
43
44
46{
47public:
48 // The dialog can be closed for several reasons.
55
56 DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE* aZone, ZONE_SETTINGS* aSettings,
57 CONVERT_SETTINGS* aConvertSettings );
58
59 ~DIALOG_COPPER_ZONE() override;
60
61 bool TransferDataToWindow() override;
62 bool TransferDataFromWindow() override;
63
65
66private:
67 void OnLayerSelection( wxDataViewEvent& event ) override;
68 void OnUpdateUI( wxUpdateUIEvent& ) override;
69 void onZoneManager( wxCommandEvent& event ) override;
70
71private:
75 ZONE_SETTINGS_BAG m_zoneSettingsBag; // Local storage of settings
76
78 wxRadioButton* m_rbCenterline;
79 wxRadioButton* m_rbEnvelope;
80 wxStaticText* m_gapLabel;
81 wxTextCtrl* m_gapCtrl;
82 wxStaticText* m_gapUnits;
86
88};
89
90
91int InvokeCopperZonesEditor( PCB_BASE_FRAME* aCaller, ZONE* aZone, ZONE_SETTINGS* aSettings,
92 CONVERT_SETTINGS* aConvertSettings )
93{
94 DIALOG_COPPER_ZONE dlg( aCaller, aZone, aSettings, aConvertSettings );
95
96 // TODO: why does this need QuasiModal?
97 dlg.ShowQuasiModal();
98
99 switch( dlg.GetReturnValue() )
100 {
102 return wxID_OK;
103
105 aCaller->CallAfter(
106 [aCaller]()
107 {
109 } );
110 return wxID_OK;
111
112 default:
114 return wxID_CANCEL;
115 }
116}
117
118
120 CONVERT_SETTINGS* aConvertSettings ) :
121 DIALOG_COPPER_ZONE_BASE( aParent ),
122 m_Parent( aParent ),
123 m_zone( aZone ),
124 m_zoneSettingsBag( aZone, aSettings ),
125 m_convertSettings( aConvertSettings ),
126 m_rbCenterline( nullptr ),
127 m_rbEnvelope( nullptr ),
128 m_cbDeleteOriginals( nullptr ),
130{
131 m_ptr = aSettings;
133
134 if( aSettings->m_TeardropType != TEARDROP_TYPE::TD_NONE )
135 SetTitle( _( "Legacy Teardrop Properties" ) );
136
137 if( aConvertSettings )
138 {
139 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY, _( "Conversion Settings" ) );
140 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
141
142 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
143 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
144
145 bConvertSizer->AddSpacer( 2 );
146 m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
147 bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
148
149 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
150 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
151 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
153 m_gap->SetValue( m_convertSettings->m_Gap );
154
155 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
156 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 );
157 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 );
158 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 );
159 bConvertSizer->AddSpacer( 2 );
160 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
161
162 bConvertSizer->AddSpacer( 6 );
163 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) );
164 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
165
166 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
167 SetTitle( _( "Convert to Copper Zone" ) );
168 }
169 else
170 {
171 m_gapLabel = nullptr;
172 m_gapCtrl = nullptr;
173 m_gapUnits = nullptr;
174 m_gap = nullptr;
175 }
176
177 // A zone still in creation (ie: not yet in the document) can't be edited by the Zone Manager
178 if( !aZone )
179 m_openZoneManager->Hide();
180
182 m_sizerRight->Add( m_panelZoneProperties, 1, wxEXPAND, 5 );
183
185
187}
188
189
194
195
197{
199 {
200 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
201 m_rbEnvelope->SetValue( true );
202 else
203 m_rbCenterline->SetValue( true );
204
205 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
206 m_gap->Enable( m_rbEnvelope->GetValue() );
207 }
208
209 m_panelZoneProperties->SetZone( m_zone );
210 return true;
211}
212
213
214void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
215{
216 if( m_gap )
217 m_gap->Enable( m_rbEnvelope->GetValue() );
218}
219
220
222{
223 if( m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.empty() )
224 {
225 DisplayError( this, _( "No layer selected." ) );
226 return false;
227 }
228
229 if( !m_panelZoneProperties->TransferZoneSettingsFromWindow() )
230 return false;
231
233 {
234 if( m_rbEnvelope->GetValue() )
235 m_convertSettings->m_Strategy = BOUNDING_HULL;
236 else
237 m_convertSettings->m_Strategy = CENTERLINE;
238
239 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
240 m_convertSettings->m_Gap = m_gap->GetIntValue();
241 }
242
243 *m_ptr = *m_zoneSettingsBag.GetZoneSettings( m_zone );
245 return true;
246}
247
248
249void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
250{
251 if( event.GetColumn() != 0 )
252 return;
253
254 int row = m_layers->ItemToRow( event.GetItem() );
255
256 bool checked = m_layers->GetToggleValue( row, 0 );
257
258 wxVariant layerID;
259 m_layers->GetValue( layerID, row, 2 );
260
261 m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
262}
263
264
265void DIALOG_COPPER_ZONE::onZoneManager( wxCommandEvent& event )
266{
268 {
270 Close();
271 }
272}
int GetCopperLayerCount() const
Definition board.cpp:906
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...
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:582
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:74
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
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:737
@ CENTERLINE
@ BOUNDING_HULL