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 <jean-pierre.charras@gipsa-lab.inpg.fr>
9  * Copyright (C) 2007 KiCad Developers, see change_log.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 <wxPcbStruct.h>
37 #include <macros.h>
38 
39 #include <class_board.h>
40 #include <class_track.h>
41 #include <class_zone.h>
42 
43 #include <pcbnew.h>
44 #include <zones.h>
45 
46 #include <connectivity.h>
47 #include <board_commit.h>
48 
49 #define FORMAT_STRING _( "Filling zone %d out of %d (net %s)..." )
50 
51 
61 void PCB_EDIT_FRAME::Delete_OldZone_Fill( SEGZONE* aZone, time_t aTimestamp )
62 {
63  bool modify = false;
64  time_t TimeStamp;
65 
66  if( aZone == NULL )
67  TimeStamp = aTimestamp;
68  else
69  TimeStamp = aZone->GetTimeStamp(); // Save reference time stamp (aZone will be deleted)
70 
71  SEGZONE* next;
72 
73  for( SEGZONE* zone = GetBoard()->m_Zone; zone != NULL; zone = next )
74  {
75  next = zone->Next();
76 
77  if( zone->GetTimeStamp() == TimeStamp )
78  {
79  modify = true;
80  // remove item from linked list and free memory
81  zone->DeleteStructure();
82  }
83  }
84 
85  if( modify )
86  {
87  OnModify();
88  m_canvas->Refresh();
89  }
90 }
91 
92 
94 {
95  aZone->ClearFilledPolysList();
96  aZone->UnFill();
97 
98  // Cannot fill keepout zones:
99  if( aZone->GetIsKeepout() )
100  return 1;
101 
102  wxString msg;
103 
104  ClearMsgPanel();
105 
106  // Shows the net
107  ZONE_SETTINGS zoneInfo = GetZoneSettings();
108  zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
109  SetZoneSettings( zoneInfo );
110 
111  msg = aZone->GetNetname();
112 
113  if( msg.IsEmpty() )
114  msg = wxT( "No net" );
115 
116  AppendMsgPanel( _( "NetName" ), msg, RED );
117 
118  wxBusyCursor dummy; // Shows an hourglass cursor (removed by its destructor)
119 
120  BOARD_COMMIT commit( this );
121  commit.Modify( aZone );
123  commit.Push( _( "Fill Zone" ), false );
124 
125  //GetGalCanvas()->GetView()->Update( aZone, KIGFX::ALL );
126  //GetBoard()->GetConnectivity()->Update( aZone );
127 
128  //OnModify();
129 
130  return 0;
131 }
132 
133 
134 int PCB_EDIT_FRAME::Fill_All_Zones( wxWindow * aActiveWindow, bool aVerbose )
135 {
136  int errorLevel = 0;
137  int areaCount = GetBoard()->GetAreaCount();
138  wxBusyCursor dummyCursor;
139  wxString msg;
140  wxProgressDialog * progressDialog = NULL;
141 
142  // Create a message with a long net name, and build a wxProgressDialog
143  // with a correct size to show this long net name
144  msg.Printf( FORMAT_STRING, 000, areaCount, wxT("XXXXXXXXXXXXXXXXX" ) );
145 
146  if( aActiveWindow )
147  progressDialog = new wxProgressDialog( _( "Fill All Zones" ), msg,
148  areaCount+2, aActiveWindow,
149  wxPD_AUTO_HIDE | wxPD_CAN_ABORT |
150  wxPD_APP_MODAL | wxPD_ELAPSED_TIME );
151  // Display the actual message
152  if( progressDialog )
153  progressDialog->Update( 0, _( "Starting zone fill..." ) );
154 
155  // Remove segment zones
157 
158  int ii;
159 
160  for( ii = 0; ii < areaCount; ii++ )
161  {
162  ZONE_CONTAINER* zoneContainer = GetBoard()->GetArea( ii );
163  if( zoneContainer->GetIsKeepout() )
164  continue;
165 
166  msg.Printf( FORMAT_STRING, ii + 1, areaCount, GetChars( zoneContainer->GetNetname() ) );
167 
168  if( progressDialog )
169  {
170  if( !progressDialog->Update( ii+1, msg ) )
171  break; // Aborted by user
172  }
173 
174  errorLevel = Fill_Zone( zoneContainer );
175 
176  if( errorLevel && !aVerbose )
177  break;
178  }
179 
180  if( progressDialog )
181  {
182  progressDialog->Update( ii+2, _( "Updating ratsnest..." ) );
183 #ifdef __WXMAC__
184  // Work around a dialog z-order issue on OS X
185  aActiveWindow->Raise();
186 #endif
187  }
188  //TestConnections();
189 
190  // Recalculate the active ratsnest, i.e. the unconnected links
191  //TestForActiveLinksInRatsnest( 0 );
192 
193  if( progressDialog )
194  progressDialog->Destroy();
195 
196  return errorLevel;
197 }
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.
Definition: pcbframe.cpp:999
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:326
int Fill_All_Zones(wxWindow *aActiveWindow, bool aVerbose=true)
Function Fill_All_Zones Fill all zones on the board The old fillings are removed. ...
bool BuildFilledSolidAreasPolygons(BOARD *aPcb, SHAPE_POLY_SET *aOutlineBuffer=NULL)
Build the filled solid areas polygons from zone outlines (stored in m_Poly) The solid areas can be mo...
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
const ZONE_SETTINGS & GetZoneSettings() const
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
BOARD * GetBoard() const
Classes to handle copper zones.
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
Functions relatives to tracks, vias and segments used to fill zones.
This file contains miscellaneous commonly used macros and functions.
SEGZONE * Next() const
Definition: class_track.h:358
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:654
int m_NetcodeSelection
Net code selection for the current zone.
void Delete_OldZone_Fill(SEGZONE *aZone, time_t aTimestamp=0)
Function Delete_OldZone_Fill (obsolete) Used for compatibility with old boards Remove the zone fillin...
bool UnFill()
Function UnFill Removes the zone filling.
Definition: class_zone.cpp:154
Definition: colors.h:60
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
int Fill_Zone(ZONE_CONTAINER *aZone)
Function Fill_Zone Calculate the zone filling for the outline zone_container The zone outline is a fr...
time_t GetTimeStamp() const
Definition: base_struct.h:204
Class ZONE_SETTINGS handles zones parameters.
int GetNetCode() const
Function GetNetCode.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:753
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
const wxString & GetNetname() const
Function GetNetname.
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764
void ClearFilledPolysList()
Function ClearFilledPolysList clears the list of filled polygons.
Definition: class_zone.h:572