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 <view/view.h>
47 
48 #define FORMAT_STRING _( "Filling zone %d out of %d (net %s)..." )
49 
50 
60 void PCB_EDIT_FRAME::Delete_OldZone_Fill( SEGZONE* aZone, time_t aTimestamp )
61 {
62  bool modify = false;
63  time_t TimeStamp;
64 
65  if( aZone == NULL )
66  TimeStamp = aTimestamp;
67  else
68  TimeStamp = aZone->GetTimeStamp(); // Save reference time stamp (aZone will be deleted)
69 
70  SEGZONE* next;
71 
72  for( SEGZONE* zone = GetBoard()->m_Zone; zone != NULL; zone = next )
73  {
74  next = zone->Next();
75 
76  if( zone->GetTimeStamp() == TimeStamp )
77  {
78  modify = true;
79  // remove item from linked list and free memory
80  zone->DeleteStructure();
81  }
82  }
83 
84  if( modify )
85  {
86  OnModify();
87  m_canvas->Refresh();
88  }
89 }
90 
91 
93 {
94  aZone->ClearFilledPolysList();
95  aZone->UnFill();
96 
97  // Cannot fill keepout zones:
98  if( aZone->GetIsKeepout() )
99  return 1;
100 
101  wxString msg;
102 
103  ClearMsgPanel();
104 
105  // Shows the net
106  ZONE_SETTINGS zoneInfo = GetZoneSettings();
107  zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
108  SetZoneSettings( zoneInfo );
109 
110  msg = aZone->GetNetname();
111 
112  if( msg.IsEmpty() )
113  msg = wxT( "No net" );
114 
115  AppendMsgPanel( _( "NetName" ), msg, RED );
116 
117  wxBusyCursor dummy; // Shows an hourglass cursor (removed by its destructor)
118 
120  GetGalCanvas()->GetView()->Update( aZone, KIGFX::ALL );
121  GetBoard()->GetRatsnest()->Update( aZone );
122 
123  OnModify();
124 
125  return 0;
126 }
127 
128 
129 int PCB_EDIT_FRAME::Fill_All_Zones( wxWindow * aActiveWindow, bool aVerbose )
130 {
131  int errorLevel = 0;
132  int areaCount = GetBoard()->GetAreaCount();
133  wxBusyCursor dummyCursor;
134  wxString msg;
135  wxProgressDialog * progressDialog = NULL;
136 
137  // Create a message with a long net name, and build a wxProgressDialog
138  // with a correct size to show this long net name
139  msg.Printf( FORMAT_STRING, 000, areaCount, wxT("XXXXXXXXXXXXXXXXX" ) );
140 
141  if( aActiveWindow )
142  progressDialog = new wxProgressDialog( _( "Fill All Zones" ), msg,
143  areaCount+2, aActiveWindow,
144  wxPD_AUTO_HIDE | wxPD_CAN_ABORT |
145  wxPD_APP_MODAL | wxPD_ELAPSED_TIME );
146  // Display the actual message
147  if( progressDialog )
148  progressDialog->Update( 0, _( "Starting zone fill..." ) );
149 
150  // Remove segment zones
152 
153  int ii;
154 
155  for( ii = 0; ii < areaCount; ii++ )
156  {
157  ZONE_CONTAINER* zoneContainer = GetBoard()->GetArea( ii );
158  if( zoneContainer->GetIsKeepout() )
159  continue;
160 
161  msg.Printf( FORMAT_STRING, ii + 1, areaCount, GetChars( zoneContainer->GetNetname() ) );
162 
163  if( progressDialog )
164  {
165  if( !progressDialog->Update( ii+1, msg ) )
166  break; // Aborted by user
167  }
168 
169  errorLevel = Fill_Zone( zoneContainer );
170 
171  if( errorLevel && !aVerbose )
172  break;
173  }
174 
175  if( progressDialog )
176  {
177  progressDialog->Update( ii+2, _( "Updating ratsnest..." ) );
178 #ifdef __WXMAC__
179  // Work around a dialog z-order issue on OS X
180  aActiveWindow->Raise();
181 #endif
182  }
183  TestConnections();
184 
185  // Recalculate the active ratsnest, i.e. the unconnected links
187  if( progressDialog )
188  progressDialog->Destroy();
189  return errorLevel;
190 }
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:1004
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
void TestForActiveLinksInRatsnest(int aNetCode)
Function TestForActiveLinksInRatsnest Explores the full rats nest list (which must exist) to determin...
Definition: ratsnest.cpp:469
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
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)
Function BuildFilledSolidAreasPolygons Build the filled solid areas data from real outlines (stored i...
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:245
bool Update(const BOARD_ITEM *aItem)
Function Update() Updates the ratsnest data for an item.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
Layers have changed.
Definition: view_item.h:59
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:362
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:644
int m_NetcodeSelection
Net code selection for the current zone.
void TestConnections()
Function TestConnections tests the connections relative to all nets.
Definition: connect.cpp:733
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:1051
int Fill_Zone(ZONE_CONTAINER *aZone)
Function Fill_Zone Calculate the zone filling for the outline zone_container The zone outline is a fr...
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1378
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
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:731
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:1022
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)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:803
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:742
void ClearFilledPolysList()
Function ClearFilledPolysList clears the list of filled polygons.
Definition: class_zone.h:577