KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zones_container.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) 2023 Ethan Chien <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include "zones_container.h"
26#include "managed_zone.h"
27
29#include <zone.h>
30#include <memory>
31#include <algorithm>
32
33
34ZONES_CONTAINER::ZONES_CONTAINER( BOARD* aBoard ) : m_originalZoneList( aBoard->Zones() )
35{
36 std::vector<std::shared_ptr<ZONE>> clonedZones;
37
38 for( ZONE* zone : aBoard->Zones() )
39 {
40 if( !zone->GetIsRuleArea() && !zone->IsTeardropArea() && zone->IsOnCopperLayer() )
41 {
42 auto zone_clone = std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
43 m_zonesCloneMap.try_emplace( zone, zone_clone );
44 m_clonedZoneList.push_back( zone_clone.get() );
45 clonedZones.push_back( std::move( zone_clone ) );
46 }
47 }
48
49 std::sort( clonedZones.begin(), clonedZones.end(),
50 []( std::shared_ptr<ZONE> const& l, std::shared_ptr<ZONE> const& r )
51 {
52 return l->GetAssignedPriority() > r->GetAssignedPriority();
53 } );
54
55 unsigned currentPriority = clonedZones.size() - 1;
56
57 for( const std::shared_ptr<ZONE>& zone : clonedZones )
58 {
59 m_managedZones.push_back( std::make_shared<MANAGED_ZONE>( zone, currentPriority ) );
60 --currentPriority;
61 }
62}
63
64
65std::shared_ptr<ZONE_SETTINGS> ZONES_CONTAINER::GetZoneSettings( ZONE* aZone )
66{
67 if( auto ll = m_zoneSettings.find( aZone ); ll != m_zoneSettings.end() )
68 return ll->second;
69
70 std::shared_ptr<ZONE_SETTINGS> zoneSetting = std::make_shared<ZONE_SETTINGS>();
71 *zoneSetting << *aZone;
72 m_zoneSettings.try_emplace( aZone, zoneSetting );
73 return zoneSetting;
74}
75
76
78{
81
82 for( const auto& [ zone, zoneClone ] : m_zonesCloneMap )
83 {
84 std::map<PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>> filled_zone_to_restore;
85 ZONE* internal_zone = zone; // Duplicate the zone pointer to allow capture on older MacOS (13)
86
88 [&]( PCB_LAYER_ID layer )
89 {
90 std::shared_ptr<SHAPE_POLY_SET> fill = internal_zone->GetFilledPolysList( layer );
91
92 if( fill )
93 filled_zone_to_restore[layer] = fill;
94 } );
95
96 *zone = *zoneClone;
97
98 for( const auto& [ layer, fill ] : filled_zone_to_restore )
99 zone->SetFilledPolysList( layer, *fill );
100 }
101}
102
104{
105 for( const std::shared_ptr<MANAGED_ZONE>& zone : m_managedZones )
106 {
107 if( auto ll = m_zoneSettings.find( &zone->GetZone() ); ll != m_zoneSettings.end() )
108 ll->second->ExportSetting( zone->GetZone() );
109 }
110}
111
113{
114 bool priorityChanged = false;
115
116 for( const std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
117 {
118 if( c->PriorityChanged() )
119 {
120 priorityChanged = true;
121 break;
122 }
123 }
124
125 if( priorityChanged )
126 {
127 for( std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
128 c->OnUserConfirmChange();
129 }
130
131 return priorityChanged;
132}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
const ZONES & Zones() const
Definition: board.h:335
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
Definition: lset.h:243
std::shared_ptr< ZONE_SETTINGS > GetZoneSettings(ZONE *zone)
std::vector< ZONE * > m_clonedZoneList
void FlushZoneSettingsChange()
Flush the zone settings change to the cloned ones.
bool FlushPriorityChange()
Flush the priority change to the cloned ones.
std::unordered_map< ZONE *, std::shared_ptr< ZONE > > m_zonesCloneMap
void OnUserConfirmChange() override
std::unordered_map< ZONE *, std::shared_ptr< ZONE_SETTINGS > > m_zoneSettings
std::vector< std::shared_ptr< MANAGED_ZONE > > m_managedZones
ZONES_CONTAINER(BOARD *board)
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:620
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60