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 <kiface_i.h>
28 #include <confirm.h>
29 #include <pcb_edit_frame.h>
30 #include <board_commit.h>
31 #include <view/view.h>
32 #include <class_board.h>
33 #include <class_zone.h>
34 #include <pcbnew.h>
35 #include <zones.h>
39 #include <zone_filler.h>
40 
41 // TODO: Remove these to the commit object below
42 // Local variables
43 static PICKED_ITEMS_LIST s_PickedList; // a picked list to save zones for undo/redo command
44 static PICKED_ITEMS_LIST s_AuxiliaryList; // a picked list to store zones that are deleted or added when combined
45 
47 {
48  int dialogResult;
49  ZONE_SETTINGS zoneInfo = GetZoneSettings();
50 
51  BOARD_COMMIT commit( this );
52 
53  // Save initial zones configuration, for undo/redo, before adding new zone
54  // note the net name and the layer can be changed, so we must save all zones
58 
59  if( aZone->GetIsRuleArea() )
60  {
61  // edit a rule area on a copper layer
62  zoneInfo << *aZone;
63  dialogResult = InvokeRuleAreaEditor( this, &zoneInfo );
64  }
65  else if( IsCopperLayer( aZone->GetLayer() ) )
66  {
67  // edit a zone on a copper layer
68  zoneInfo << *aZone;
69  dialogResult = InvokeCopperZonesEditor( this, &zoneInfo );
70  }
71  else
72  {
73  zoneInfo << *aZone;
74  dialogResult = InvokeNonCopperZonesEditor( this, &zoneInfo );
75  }
76 
77  if( dialogResult == wxID_CANCEL )
78  {
81  return;
82  }
83 
84  SetZoneSettings( zoneInfo );
85  OnModify();
86 
87  if( dialogResult == ZONE_EXPORT_VALUES )
88  {
90  commit.Stage( s_PickedList );
91  commit.Push( _( "Modify zone properties" ) );
92  s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
93  return;
94  }
95 
96  wxBusyCursor dummy;
97 
98  // Undraw old zone outlines
99  for( ZONE_CONTAINER* zone : GetBoard()->Zones() )
100  GetCanvas()->GetView()->Update( zone );
101 
102  zoneInfo.ExportSetting( *aZone );
103 
104  NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
105 
106  if( net ) // net == NULL should not occur
107  aZone->SetNetCode( net->GetNet() );
108 
109  // Combine zones if possible
111 
113 
114  // refill zones with the new properties applied
115  std::vector<ZONE_CONTAINER*> zones_to_refill;
116 
117  for( unsigned i = 0; i < s_PickedList.GetCount(); ++i )
118  {
119  ZONE_CONTAINER* zone = dyn_cast<ZONE_CONTAINER*>( s_PickedList.GetPickedItem( i ) );
120 
121  if( zone == nullptr )
122  {
123  wxASSERT_MSG( false, "Expected a zone after zone properties edit" );
124  continue;
125  }
126 
127  // aZone won't be filled if the layer set was modified, but it needs to be updated
128  if( zone->IsFilled() || zone == aZone )
129  zones_to_refill.push_back( zone );
130  }
131 
132  commit.Stage( s_PickedList );
133 
134  if( zones_to_refill.size() )
135  {
136  ZONE_FILLER filler( GetBoard(), &commit );
137  wxString title = wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() );
138  filler.InstallNewProgressReporter( this, title, 4 );
139 
140  if( !filler.Fill( zones_to_refill ) )
141  {
142  commit.Revert();
143  return;
144  }
145  }
146 
147  commit.Push( _( "Modify zone properties" ) );
148  GetBoard()->GetConnectivity()->RecalculateRatsnest();
149 
150  s_PickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
151 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
bool IsFilled() const
Definition: class_zone.h:214
void Edit_Zone_Params(ZONE_CONTAINER *zone_container)
Function Edit_Zone_Params Edit params (layer, clearance, ...) for a zone outline.
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)
Process an area that has been modified, by normalizing its polygon and merging the intersecting polyg...
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
virtual void Revert() override
Revertes the commit by restoring the modifed items state.
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:214
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
#define ZONE_EXPORT_VALUES
Definition: zones.h:37
unsigned GetCount() const
Function GetCount.
void InstallNewProgressReporter(wxWindow *aParent, const wxString &aTitle, int aNumPhases)
Definition: zone_filler.cpp:72
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
Definition: zone_settings.h:93
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
const ZONE_SETTINGS & GetZoneSettings() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: class_board.h:381
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
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.
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: class_zone.h:728
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
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:201
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:223
#define _(s)
Definition: 3d_actions.cpp:33
static PICKED_ITEMS_LIST s_PickedList
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)
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)
BOARD * GetBoard() const
bool Fill(std::vector< ZONE_CONTAINER * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Definition: zone_filler.cpp:87
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.