KiCad PCB EDA Suite
zone_filler_tool.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) 2014-2017 CERN
5  * Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 #include <cstdint>
26 #include <thread>
27 #include <class_zone.h>
29 #include <board_commit.h>
31 #include <wx/event.h>
32 #include <tool/tool_manager.h>
33 #include <bitmaps.h>
34 #include "pcb_actions.h"
35 #include "selection_tool.h"
36 #include "zone_filler_tool.h"
37 #include "zone_filler.h"
38 
39 
41  PCB_TOOL_BASE( "pcbnew.ZoneFiller" )
42 {
43 }
44 
45 
47 {
48 }
49 
50 
52 {
53 }
54 
55 
56 void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller )
57 {
58  if( !getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty )
59  return;
60 
61  std::vector<ZONE_CONTAINER*> toFill;
62 
63  for( auto zone : board()->Zones() )
64  toFill.push_back(zone);
65 
66  BOARD_COMMIT commit( this );
67 
68  ZONE_FILLER filler( frame()->GetBoard(), &commit );
69  filler.InstallNewProgressReporter( aCaller, _( "Checking Zones" ), 4 );
70 
71  if( filler.Fill( toFill, true ) )
72  {
73  getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false;
74  canvas()->Refresh();
75  }
76 }
77 
78 
80 {
81  canvas()->SetFocus();
82  canvas()->Unbind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
83 }
84 
85 
86 void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
87 {
88  std::vector<ZONE_CONTAINER*> toFill;
89 
90  BOARD_COMMIT commit( this );
91 
92  for( auto zone : board()->Zones() )
93  toFill.push_back(zone);
94 
95  ZONE_FILLER filler( board(), &commit );
96  filler.InstallNewProgressReporter( aCaller, _( "Fill All Zones" ), 4 );
97 
98  if( filler.Fill( toFill ) )
99  getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false;
100 
101  canvas()->Refresh();
102 
103  // wxWidgets has keyboard focus issues after the progress reporter. Re-setting the focus
104  // here doesn't work, so we delay it to an idle event.
105  canvas()->Bind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
106 }
107 
108 
110 {
111  std::vector<ZONE_CONTAINER*> toFill;
112 
113  BOARD_COMMIT commit( this );
114 
115  if( auto passedZone = aEvent.Parameter<ZONE_CONTAINER*>() )
116  {
117  if( passedZone->Type() == PCB_ZONE_AREA_T )
118  toFill.push_back( passedZone );
119  }
120  else
121  {
122  for( auto item : selection() )
123  {
124  if( auto zone = dyn_cast<ZONE_CONTAINER*>( item ) )
125  toFill.push_back( zone );
126  }
127  }
128 
129  ZONE_FILLER filler( board(), &commit );
130  filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
131  filler.Fill( toFill );
132 
133  canvas()->Refresh();
134  return 0;
135 }
136 
137 
139 {
140  FillAllZones( frame() );
141  return 0;
142 }
143 
144 
146 {
147  BOARD_COMMIT commit( this );
148 
149  for( auto item : selection() )
150  {
151  assert( item->Type() == PCB_ZONE_AREA_T );
152 
153  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
154 
155  commit.Modify( zone );
156 
157  zone->SetIsFilled( false );
158  zone->ClearFilledPolysList();
159  }
160 
161  commit.Push( _( "Unfill Zone" ) );
162  canvas()->Refresh();
163 
164  return 0;
165 }
166 
167 
169 {
170  BOARD_COMMIT commit( this );
171 
172  for ( auto zone : board()->Zones() )
173  {
174  commit.Modify( zone );
175 
176  zone->SetIsFilled( false );
177  zone->ClearFilledPolysList();
178  }
179 
180  commit.Push( _( "Unfill All Zones" ) );
181  canvas()->Refresh();
182 
183  return 0;
184 }
185 
186 
188 {
189  // Zone actions
194 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
BOARD * board() const
int ZoneUnfill(const TOOL_EVENT &aEvent)
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:290
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
int ZoneUnfillAll(const TOOL_EVENT &aEvent)
void singleShotRefocus(wxIdleEvent &)
Refocuses on an idle event (used after the Progress Reporter messes up the focus)
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:289
void InstallNewProgressReporter(wxWindow *aParent, const wxString &aTitle, int aNumPhases)
Definition: zone_filler.cpp:94
PCB_BASE_EDIT_FRAME * frame() const
void FillAllZones(wxWindow *aCaller)
const PCBNEW_SELECTION & selection() const
int ZoneFill(const TOOL_EVENT &aEvent)
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
Class TOOL_EVENT.
Definition: tool_event.h:168
virtual void SetFocus() override
bool Fill(const std::vector< ZONE_CONTAINER * > &aZones, bool aCheck=false)
#define _(s)
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:292
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:291
BOARD * GetBoard()
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void setTransitions() override
Sets up handlers for various events.
void CheckAllZones(wxWindow *aCaller)
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
PCB_DRAW_PANEL_GAL * canvas() const
int ZoneFillAll(const TOOL_EVENT &aEvent)