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 <kiface_base.h>
23#include <confirm.h>
24#include <pcb_edit_frame.h>
25#include <pcbnew_settings.h>
26#include <zones.h>
28#include <widgets/unit_binder.h>
30#include <zone.h>
31#include <zone_settings_bag.h>
32#include <pad.h>
34#include <tool/tool_manager.h>
37#include <tools/pcb_actions.h>
38
39
41{
42public:
43 // The dialog can be closed for several reasons.
50
51 DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE* aZone, ZONE_SETTINGS* aSettings,
52 CONVERT_SETTINGS* aConvertSettings );
53
54 bool TransferDataToWindow() override;
55 bool TransferDataFromWindow() override;
56
58
59private:
60 void OnLayerSelection( wxDataViewEvent& event ) override;
61 void onZoneManager( wxCommandEvent& event ) override;
62
63private:
67 ZONE_SETTINGS_BAG m_zoneSettingsBag; // Local storage of settings
68
71
73};
74
75
76int InvokeCopperZonesEditor( PCB_BASE_FRAME* aCaller, ZONE* aZone, ZONE_SETTINGS* aSettings,
77 CONVERT_SETTINGS* aConvertSettings )
78{
79 DIALOG_COPPER_ZONE dlg( aCaller, aZone, aSettings, aConvertSettings );
80
81 dlg.ShowModal();
82
83 switch( dlg.GetReturnValue() )
84 {
86 return wxID_OK;
87
89 aCaller->CallAfter(
90 [aCaller]()
91 {
93 } );
94
95 return wxID_OK;
96
97 default:
99 return wxID_CANCEL;
100 }
101}
102
103
105 CONVERT_SETTINGS* aConvertSettings ) :
106 DIALOG_COPPER_ZONE_BASE( aParent ),
107 m_Parent( aParent ),
108 m_zone( aZone ),
109 m_zoneSettingsBag( aZone, aSettings ),
111{
112 m_ptr = aSettings;
114
115 if( aSettings->m_TeardropType != TEARDROP_TYPE::TD_NONE )
116 SetTitle( _( "Legacy Teardrop Properties" ) );
117
118 if( aConvertSettings )
119 {
120 m_conversionControls = new PANEL_ZONE_CONVERSION( this, aParent, *aConvertSettings );
121 GetSizer()->Insert( 0, m_conversionControls, 0, wxALL|wxEXPAND, 10 );
122 SetTitle( _( "Convert to Copper Zone" ) );
123 }
124
125 // A zone still in creation (ie: not yet in the document) can't be edited by the Zone Manager
126 if( !aZone )
127 m_openZoneManager->Hide();
128
130 m_sizerRight->Add( m_panelZoneProperties, 1, wxEXPAND, 5 );
131
133
135}
136
137
139{
141 m_conversionControls->TransferDataToWindow();
142
143 m_panelZoneProperties->SetZone( m_zone );
144 return true;
145}
146
147
149{
150 if( m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.empty() )
151 {
152 DisplayError( this, _( "No layer selected." ) );
153 return false;
154 }
155
156 if( !m_panelZoneProperties->TransferZoneSettingsFromWindow() )
157 return false;
158
160 m_conversionControls->TransferDataFromWindow();
161
162 *m_ptr = *m_zoneSettingsBag.GetZoneSettings( m_zone );
164 return true;
165}
166
167
168void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
169{
170 if( event.GetColumn() != 0 )
171 return;
172
173 int row = m_layers->ItemToRow( event.GetItem() );
174
175 bool checked = m_layers->GetToggleValue( row, 0 );
176
177 wxVariant layerID;
178 m_layers->GetValue( layerID, row, 2 );
179
180 m_zoneSettingsBag.GetZoneSettings( m_zone )->m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
181}
182
183
184void DIALOG_COPPER_ZONE::onZoneManager( wxCommandEvent& event )
185{
187 {
189 Close();
190 }
191}
int GetCopperLayerCount() const
Definition board.cpp:1138
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
bool TransferDataToWindow() override
void OnLayerSelection(wxDataViewEvent &event) override
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 onZoneManager(wxCommandEvent &event) override
PANEL_ZONE_CONVERSION * m_conversionControls
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.
Handle zones parameters.
TEARDROP_TYPE m_TeardropType
A zone outline can be a teardrop zone with different rules priority, smoothed corners,...
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)
Invoke a modal dialog window for copper zone editing.
#define _(s)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750