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 <mutex>
28 
29 #include <class_zone.h>
30 #include <class_module.h>
32 #include <board_commit.h>
33 
35 #include <tool/tool_manager.h>
36 #include <bitmaps.h>
37 #include <hotkeys.h>
38 
39 #include "pcb_actions.h"
40 #include "selection_tool.h"
41 #include "zone_filler_tool.h"
42 #include "zone_filler.h"
43 
44 // Zone actions
45 TOOL_ACTION PCB_ACTIONS::zoneFill( "pcbnew.ZoneFiller.zoneFill",
46  AS_GLOBAL, 0,
47  _( "Fill" ), _( "Fill zone(s)" ), fill_zone_xpm );
48 
49 TOOL_ACTION PCB_ACTIONS::zoneFillAll( "pcbnew.ZoneFiller.zoneFillAll",
51  _( "Fill All" ), _( "Fill all zones" ) );
52 
53 TOOL_ACTION PCB_ACTIONS::zoneUnfill( "pcbnew.ZoneFiller.zoneUnfill",
54  AS_GLOBAL, 0,
55  _( "Unfill" ), _( "Unfill zone(s)" ), zone_unfill_xpm );
56 
57 TOOL_ACTION PCB_ACTIONS::zoneUnfillAll( "pcbnew.ZoneFiller.zoneUnfillAll",
59  _( "Unfill All" ), _( "Unfill all zones" ) );
60 
62  PCB_TOOL_BASE( "pcbnew.ZoneFiller" )
63 {
64 }
65 
66 
68 {
69 }
70 
71 
73 {
74 }
75 
76 // Zone actions
78 {
79  std::vector<ZONE_CONTAINER*> toFill;
80 
81  BOARD_COMMIT commit( this );
82 
83  for( auto item : selection() )
84  {
85  assert( item->Type() == PCB_ZONE_AREA_T );
86 
87  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*> ( item );
88 
89  toFill.push_back(zone);
90  }
91 
92  std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
93  new WX_PROGRESS_REPORTER( frame(), _( "Fill Zone" ), 4 )
94  );
95 
96  ZONE_FILLER filler( board(), &commit );
97  filler.SetProgressReporter( progressReporter.get() );
98  filler.Fill( toFill );
99 
100  canvas()->Refresh();
101 
102  return 0;
103 }
104 
105 
107 {
108  std::vector<ZONE_CONTAINER*> toFill;
109 
110  BOARD_COMMIT commit( this );
111 
112  for( auto zone : board()->Zones() )
113  {
114  toFill.push_back(zone);
115  }
116 
117  std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
118  new WX_PROGRESS_REPORTER( frame(), _( "Fill All Zones" ), 4 )
119  );
120 
121  ZONE_FILLER filler( board(), &commit );
122  filler.SetProgressReporter( progressReporter.get() );
123 
124  if( filler.Fill( toFill ) )
125  frame()->m_ZoneFillsDirty = false;
126 
127  canvas()->Refresh();
128 
129  return 0;
130 }
131 
132 
134 {
135  BOARD_COMMIT commit( this );
136 
137  for( auto item : selection() )
138  {
139  assert( item->Type() == PCB_ZONE_AREA_T );
140 
141  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
142 
143  commit.Modify( zone );
144 
145  zone->SetIsFilled( false );
146  zone->ClearFilledPolysList();
147  }
148 
149  commit.Push( _( "Unfill Zone" ) );
150  canvas()->Refresh();
151 
152  return 0;
153 }
154 
155 
157 {
158  BOARD_COMMIT commit( this );
159 
160  for ( auto zone : board()->Zones() )
161  {
162  commit.Modify( zone );
163 
164  zone->SetIsFilled( false );
165  zone->ClearFilledPolysList();
166  }
167 
168  commit.Push( _( "Unfill All Zones" ) );
169  canvas()->Refresh();
170 
171  return 0;
172 }
173 
174 
176 {
177  // Zone actions
182 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
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:251
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
int ZoneUnfillAll(const TOOL_EVENT &aEvent)
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key.
Definition: tool_action.h:165
Classes to handle copper zones.
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:250
Pcbnew hotkeys.
void SetProgressReporter(WX_PROGRESS_REPORTER *aReporter)
Definition: zone_filler.cpp:97
int ZoneFill(const TOOL_EVENT &aEvent)
Class TOOL_EVENT.
Definition: tool_event.h:167
bool Fill(const std::vector< ZONE_CONTAINER * > &aZones, bool aCheck=false)
All active tools
Definition: tool_event.h:143
PCB_EDIT_FRAME * frame() const
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:253
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:252
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.
Class TOOL_ACTION.
Definition: tool_action.h:46
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:80
Module description (excepted pads)
PCB_DRAW_PANEL_GAL * canvas() const
const SELECTION & selection() const
int ZoneFillAll(const TOOL_EVENT &aEvent)