KiCad PCB EDA Suite
zones_by_polygon.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <fctsys.h>
28 #include <kiface_i.h>
29 #include <confirm.h>
30 #include <pcb_edit_frame.h>
31 #include <board_commit.h>
32 #include <view/view.h>
33 #include <class_board.h>
34 #include <class_zone.h>
35 #include <pcbnew.h>
36 #include <zones.h>
37 #include <pcbnew_id.h>
39 #include <tools/drc.h>
42 #include <zone_filler.h>
43 
44 // Local variables
45 static PICKED_ITEMS_LIST s_PickedList; // a picked list to save zones for undo/redo command
46 static PICKED_ITEMS_LIST s_AuxiliaryList; // a picked list to store zones that are deleted or added when combined
47 
48 
50 {
51  int dialogResult;
52  ZONE_SETTINGS zoneInfo = GetZoneSettings();
53 
54  BOARD_COMMIT commit( this );
55 
56  // Save initial zones configuration, for undo/redo, before adding new zone
57  // note the net name and the layer can be changed, so we must save all zones
61 
62  if( aZone->GetIsKeepout() )
63  {
64  // edit a keepout area on a copper layer
65  zoneInfo << *aZone;
66  dialogResult = InvokeKeepoutAreaEditor( this, &zoneInfo );
67  }
68  else if( IsCopperLayer( aZone->GetLayer() ) )
69  {
70  // edit a zone on a copper layer
71  zoneInfo << *aZone;
72  dialogResult = InvokeCopperZonesEditor( this, &zoneInfo );
73  }
74  else
75  {
76  zoneInfo << *aZone;
77  dialogResult = InvokeNonCopperZonesEditor( this, &zoneInfo );
78  }
79 
80  if( dialogResult == wxID_CANCEL )
81  {
84  return;
85  }
86 
87  SetZoneSettings( zoneInfo );
88  OnModify();
89 
90  if( dialogResult == ZONE_EXPORT_VALUES )
91  {
93  commit.Stage( s_PickedList );
94  commit.Push( _( "Modify zone properties" ) );
95  s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
96  return;
97  }
98 
99  wxBusyCursor dummy;
100 
101  // Undraw old zone outlines
102  for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
103  {
104  ZONE_CONTAINER* edge_zone = GetBoard()->GetArea( ii );
105  GetCanvas()->GetView()->Update( edge_zone );
106  }
107 
108  zoneInfo.ExportSetting( *aZone );
109 
110  NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
111 
112  if( net ) // net == NULL should not occur
113  aZone->SetNetCode( net->GetNet() );
114 
115  // Combine zones if possible
117 
119 
120  // refill zones with the new properties applied
121  std::vector<ZONE_CONTAINER*> zones_to_refill;
122 
123  for( unsigned i = 0; i < s_PickedList.GetCount(); ++i )
124  {
125  ZONE_CONTAINER* zone = dyn_cast<ZONE_CONTAINER*>( s_PickedList.GetPickedItem( i ) );
126 
127  if( zone == nullptr )
128  {
129  wxASSERT_MSG( false, "Expected a zone after zone properties edit" );
130  continue;
131  }
132 
133  if( zone->IsFilled() )
134  zones_to_refill.push_back( zone );
135  }
136 
137  if( zones_to_refill.size() )
138  {
139  ZONE_FILLER filler ( GetBoard() );
140  wxString title = wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() );
141  filler.InstallNewProgressReporter( this, title, 4 );
142  filler.Fill( zones_to_refill );
143  }
144 
145  commit.Stage( s_PickedList );
146  commit.Push( _( "Modify zone properties" ) );
147  GetBoard()->GetConnectivity()->RecalculateRatsnest();
148 
149  s_PickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
150 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool IsFilled() const
Definition: class_zone.h:173
void Edit_Zone_Params(ZONE_CONTAINER *zone_container)
Function Edit_Zone_Params Edit params (layer, clearance, ...) for a zone outline.
int InvokeKeepoutAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeKeepoutAreaEditor invokes up a modal dialog window for copper zone editing.
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
This file is part of the common library.
void UpdateCopyOfZonesList(PICKED_ITEMS_LIST &aPickList, PICKED_ITEMS_LIST &aAuxiliaryList, BOARD *aPcb)
Function UpdateCopyOfZonesList Check a pick list to remove zones identical to their copies and set th...
bool OnAreaPolygonModified(PICKED_ITEMS_LIST *aModifiedZonesList, ZONE_CONTAINER *modified_area)
Function OnAreaPolygonModified Process an area that has been modified, by normalizing its polygon and...
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:203
#define ZONE_EXPORT_VALUES
Definition: zones.h:46
unsigned GetCount() const
Function GetCount.
void InstallNewProgressReporter(wxWindow *aParent, const wxString &aTitle, int aNumPhases)
Definition: zone_filler.cpp:95
static PICKED_ITEMS_LIST s_AuxiliaryList
int SaveCopyOfZones(PICKED_ITEMS_LIST &aPickList, BOARD *aPcb, int aNetCode, LAYER_NUM aLayer)
Function SaveCopyOfZones creates a copy of zones having a given netcode on a given layer,...
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:74
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:949
const ZONE_SETTINGS & GetZoneSettings() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:301
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
bool Fill(const std::vector< ZONE_CONTAINER * > &aZones, bool aCheck=false)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
#define _(s)
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:630
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:49
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
static PICKED_ITEMS_LIST s_PickedList
size_t i
Definition: json11.cpp:649
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:914
BOARD * GetBoard() const
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType) override
Adds a change of the item aItem of type aChangeType to the change list.