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 
61 TOOL_ACTION PCB_ACTIONS::zoneDeleteSegzone( "pcbnew.ZoneFiller.zoneDeleteSegzone",
62  AS_GLOBAL, 0,
63  _( "Delete Zone Filling" ), _( "Delete Zone Filling" ), delete_xpm );
64 
66  PCB_TOOL( "pcbnew.ZoneFiller" )
67 {
68 }
69 
70 
72 {
73 }
74 
75 
77 {
78 }
79 
80 // Zone actions
82 {
83  std::vector<ZONE_CONTAINER*> toFill;
84 
85  BOARD_COMMIT commit( this );
86 
87  for( auto item : selection() )
88  {
89  assert( item->Type() == PCB_ZONE_AREA_T );
90 
91  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*> ( item );
92 
93  toFill.push_back(zone);
94  }
95 
96  std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
97  new WX_PROGRESS_REPORTER( frame(), _( "Fill Zone" ), 4 )
98  );
99 
100  ZONE_FILLER filler( board(), &commit );
101  filler.SetProgressReporter( progressReporter.get() );
102  filler.Fill( toFill );
103 
104  getEditFrame<PCB_EDIT_FRAME>()->Refresh();
105 
106  return 0;
107 }
108 
109 
111 {
112  std::vector<ZONE_CONTAINER*> toFill;
113 
114  BOARD_COMMIT commit( this );
115 
116  for( auto zone : board()->Zones() )
117  {
118  toFill.push_back(zone);
119  }
120 
121  std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
122  new WX_PROGRESS_REPORTER( frame(), _( "Fill All Zones" ), 4 )
123  );
124 
125  ZONE_FILLER filler( board(), &commit );
126  filler.SetProgressReporter( progressReporter.get() );
127 
128  if( filler.Fill( toFill ) )
129  frame()->m_ZoneFillsDirty = false;
130 
131  getEditFrame<PCB_EDIT_FRAME>()->Refresh();
132 
133  return 0;
134 }
135 
136 
138 {
139  BOARD_COMMIT commit( this );
140 
141  for( auto item : selection() )
142  {
143  assert( item->Type() == PCB_ZONE_AREA_T );
144 
145  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
146 
147  commit.Modify( zone );
148 
149  zone->SetIsFilled( false );
150  zone->ClearFilledPolysList();
151  }
152 
153  commit.Push( _( "Unfill Zone" ) );
154  getEditFrame<PCB_EDIT_FRAME>()->Refresh();
155 
156  return 0;
157 }
158 
159 
161 {
162  BOARD_COMMIT commit( this );
164 
165  for( auto item : selection() )
166  {
167  assert( item->Type() == PCB_SEGZONE_T );
168 
169  timestamp_t timestamp = item->GetTimeStamp(); // Save reference time stamp (aZone will be deleted)
170  SEGZONE* next;
171 
172  for( SEGZONE* zone = board->m_SegZoneDeprecated; zone; zone = next )
173  {
174  next = zone->Next();
175 
176  if( timestamp == zone->GetTimeStamp() )
177  commit.Remove( zone );
178  }
179  }
180 
181  commit.Push( _( "Delete Zone Filling" ) );
182  getEditFrame<PCB_EDIT_FRAME>()->Refresh();
183 
184  return 0;
185 }
186 
187 
189 {
190  BOARD_COMMIT commit( this );
191 
192  for ( auto zone : board()->Zones() )
193  {
194  commit.Modify( zone );
195 
196  zone->SetIsFilled( false );
197  zone->ClearFilledPolysList();
198  }
199 
200  commit.Push( _( "Unfill All Zones" ) );
201  getEditFrame<PCB_EDIT_FRAME>()->Refresh();
202 
203  return 0;
204 }
205 
206 
208 {
209  // Zone actions
215 }
CITER next(CITER it)
Definition: ptree.cpp:130
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
int ZoneUnfill(const TOOL_EVENT &aEvent)
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:298
static TOOL_ACTION zoneDeleteSegzone
Definition: pcb_actions.h:302
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
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:174
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:297
int SegzoneDeleteFill(const TOOL_EVENT &aEvent)
Pcbnew hotkeys.
SEGZONE * Next() const
Definition: class_track.h:363
void SetProgressReporter(WX_PROGRESS_REPORTER *aReporter)
Definition: zone_filler.cpp:78
int ZoneFill(const TOOL_EVENT &aEvent)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
DLIST< SEGZONE > m_SegZoneDeprecated
Definition: class_board.h:250
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
Class TOOL_EVENT.
Definition: tool_event.h:168
bool Fill(std::vector< ZONE_CONTAINER * > aZones, bool aCheck=false)
Definition: zone_filler.cpp:83
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
All active tools
Definition: tool_event.h:144
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:300
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:299
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.
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
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)
class SEGZONE, a segment used to fill a zone area (segment on a
Definition: typeinfo.h:97
int ZoneFillAll(const TOOL_EVENT &aEvent)
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
BOARD * board() const
Definition: pcb_tool.h:140