KiCad PCB EDA Suite
zones_by_polygon_fill_functions.cpp
Go to the documentation of this file.
1 /*
2  * @file zones_by_polygon_fill_functions.cpp
3  */
4 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2009 Jean-Pierre Charras jp.charras at wanadoo.fr
9  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <wx/progdlg.h>
30 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <class_drawpanel.h>
34 #include <class_draw_panel_gal.h>
35 #include <ratsnest_data.h>
36 #include <pcb_edit_frame.h>
37 #include <macros.h>
38 
39 #include <tool/tool_manager.h>
40 #include <tools/pcb_actions.h>
41 
42 #include <class_board.h>
43 #include <class_track.h>
44 #include <class_zone.h>
45 
46 #include <pcbnew.h>
47 #include <zones.h>
48 
49 #include <board_commit.h>
50 
52 #include <zone_filler.h>
53 
54 
65 {
66  bool modify = false;
67  timestamp_t TimeStamp;
68 
69  if( aZone == NULL )
70  TimeStamp = aTimestamp;
71  else
72  TimeStamp = aZone->GetTimeStamp(); // Save reference time stamp (aZone will be deleted)
73 
74  // SEGZONE is a deprecated item, only used for compatibility with very old boards
75  SEGZONE* next;
76 
77  for( SEGZONE* zone = GetBoard()->m_SegZoneDeprecated; zone != NULL; zone = next )
78  {
79  next = zone->Next();
80 
81  if( zone->GetTimeStamp() == TimeStamp )
82  {
83  modify = true;
84  // remove item from linked list and free memory
85  zone->DeleteStructure();
86  }
87  }
88 
89  if( modify )
90  {
91  OnModify();
92  m_canvas->Refresh();
93  }
94 }
95 
96 
97 int PCB_EDIT_FRAME::Fill_All_Zones( wxWindow* aActiveWindow )
98 {
99  auto toolMgr = GetToolManager();
100  wxCHECK( toolMgr, 1 );
101  toolMgr->RunAction( PCB_ACTIONS::zoneFillAll, true );
102  return 0;
103 }
104 
105 
106 void PCB_EDIT_FRAME::Check_All_Zones( wxWindow* aActiveWindow )
107 {
108  if( !m_ZoneFillsDirty )
109  return;
110 
111  std::vector<ZONE_CONTAINER*> toFill;
112 
113  for( auto zone : GetBoard()->Zones() )
114  toFill.push_back(zone);
115 
116  BOARD_COMMIT commit( this );
117 
118  std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
119  new WX_PROGRESS_REPORTER( aActiveWindow, _( "Checking Zones" ), 4 ) );
120 
121  ZONE_FILLER filler( GetBoard(), &commit );
122  filler.SetProgressReporter( progressReporter.get() );
123 
124  if( filler.Fill( toFill, true ) )
125  {
126  m_ZoneFillsDirty = false;
127 
128  if( IsGalCanvasActive() && GetGalCanvas() )
130 
131  GetCanvas()->Refresh();
132  }
133 }
CITER next(CITER it)
Definition: ptree.cpp:130
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:303
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
void Check_All_Zones(wxWindow *aActiveWindow)
Function Check_All_Zones Checks for out-of-date fills and fills them if requested by the user.
Classes to handle copper zones.
Functions relatives to tracks, vias and segments used to fill zones.
This file contains miscellaneous commonly used macros and functions.
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:941
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:928
void SetProgressReporter(WX_PROGRESS_REPORTER *aReporter)
Definition: zone_filler.cpp:78
bool Fill(std::vector< ZONE_CONTAINER * > aZones, bool aCheck=false)
Definition: zone_filler.cpp:83
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:395
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
see class PGM_BASE
int Fill_All_Zones(wxWindow *aActiveWindow)
Function Fill_All_Zones Fill all zones on the board The old fillings are removed.
BOARD * GetBoard() const
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void Delete_OldZone_Fill(SEGZONE *aZone, timestamp_t aTimestamp=0)
Function Delete_OldZone_Fill (obsolete) Used for compatibility with old boards Remove the zone fillin...