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>
38#include <board.h>
40
43
44
46{
47public:
48 DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings, CONVERT_SETTINGS* aConvertSettings );
49
50 ~DIALOG_COPPER_ZONE() override;
51
52private:
53 bool TransferDataToWindow() override;
54 bool TransferDataFromWindow() override;
55
56 void OnLayerSelection( wxDataViewEvent& event ) override;
57 void OnUpdateUI( wxUpdateUIEvent& ) override;
58
59private:
62
65
66 wxStaticText* m_gapLabel;
67 wxTextCtrl* m_gapCtrl;
68 wxStaticText* m_gapUnits;
70
72 wxRadioButton* m_rbCenterline;
73 wxRadioButton* m_rbEnvelope;
75};
76
77
78int InvokeCopperZonesEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aSettings, CONVERT_SETTINGS* aConvertSettings )
79{
80 DIALOG_COPPER_ZONE dlg( aCaller, aSettings, aConvertSettings );
81
82 // TODO: why does this need QuasiModal?
83 return dlg.ShowQuasiModal();
84}
85
86
88 CONVERT_SETTINGS* aConvertSettings ) :
89 DIALOG_COPPER_ZONE_BASE( aParent ),
90 m_zoneSettingsBag( aSettings ),
91 m_convertSettings( aConvertSettings ),
92 m_rbCenterline( nullptr ),
93 m_rbEnvelope( nullptr ),
94 m_cbDeleteOriginals( nullptr )
95{
96 m_Parent = aParent;
97
98 m_ptr = aSettings;
100
101 if( aSettings->m_TeardropType != TEARDROP_TYPE::TD_NONE )
102 SetTitle( _( "Legacy Teardrop Properties" ) );
103
104 if( aConvertSettings )
105 {
106 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY, _( "Conversion Settings" ) );
107 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
108
109 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
110 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
111
112 bConvertSizer->AddSpacer( 2 );
113 m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
114 bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
115
116 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
117 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
118 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
120 m_gap->SetValue( m_convertSettings->m_Gap );
121
122 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
123 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 );
124 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 );
125 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 );
126 bConvertSizer->AddSpacer( 2 );
127 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
128
129 bConvertSizer->AddSpacer( 6 );
130 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) );
131 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
132
133 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
134 SetTitle( _( "Convert to Copper Zone" ) );
135 }
136 else
137 {
138 m_gapLabel = nullptr;
139 m_gapCtrl = nullptr;
140 m_gapUnits = nullptr;
141 m_gap = nullptr;
142 }
143
145 m_panelZoneProperties->SetZone( nullptr );
146 m_sizerRight->Add( m_panelZoneProperties, 1, wxEXPAND, 5 );
147
149
151}
152
153
158
159
161{
163 {
164 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
165 m_rbEnvelope->SetValue( true );
166 else
167 m_rbCenterline->SetValue( true );
168
169 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
170 m_gap->Enable( m_rbEnvelope->GetValue() );
171 }
172
173 return m_panelZoneProperties->TransferZoneSettingsToWindow();
174}
175
176
177void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
178{
179 if( m_gap )
180 m_gap->Enable( m_rbEnvelope->GetValue() );
181}
182
183
185{
186 // Get the layer selection for this zone
187 int layers = 0;
188
189 for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
190 {
191 if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
192 layers++;
193 }
194
195 if( layers == 0 )
196 {
197 DisplayError( this, _( "No layer selected." ) );
198 return false;
199 }
200
201 if( !m_panelZoneProperties->TransferZoneSettingsFromWindow() )
202 return false;
203
205 {
206 if( m_rbEnvelope->GetValue() )
207 m_convertSettings->m_Strategy = BOUNDING_HULL;
208 else
209 m_convertSettings->m_Strategy = CENTERLINE;
210
211 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
212 m_convertSettings->m_Gap = m_gap->GetIntValue();
213 }
214
215 *m_ptr = *m_zoneSettingsBag.GetZoneSettings( nullptr );
216 return true;
217}
218
219
220void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
221{
222 if( event.GetColumn() != 0 )
223 return;
224
225 int row = m_layers->ItemToRow( event.GetItem() );
226
227 bool checked = m_layers->GetToggleValue( row, 0 );
228
229 wxVariant layerID;
230 m_layers->GetValue( layerID, row, 2 );
231
232 m_zoneSettingsBag.GetZoneSettings( nullptr )->m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
233}
int GetCopperLayerCount() const
Definition board.cpp:879
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
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
wxRadioButton * m_rbCenterline
bool TransferDataToWindow() override
void OnLayerSelection(wxDataViewEvent &event) override
CONVERT_SETTINGS * m_convertSettings
PCB_BASE_FRAME * m_Parent
PANEL_ZONE_PROPERTIES * m_panelZoneProperties
void OnUpdateUI(wxUpdateUIEvent &) 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
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
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).
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_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