KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zone_settings_bag.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 The 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 "zone_settings_bag.h"
26
28#include <zone.h>
29#include <memory>
30#include <algorithm>
31
32
34{
35 std::vector<std::shared_ptr<ZONE>> clonedZones;
36
37 for( ZONE* zone : aBoard->Zones() )
38 {
39 if( !zone->GetIsRuleArea() && !zone->IsTeardropArea() && zone->IsOnCopperLayer() )
40 {
41 auto zone_clone = std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
42 m_zonesCloneMap.try_emplace( zone, zone_clone );
43 m_clonedZoneList.push_back( zone_clone.get() );
44 clonedZones.push_back( std::move( zone_clone ) );
45 }
46 }
47
48 std::sort( clonedZones.begin(), clonedZones.end(),
49 []( std::shared_ptr<ZONE> const& l, std::shared_ptr<ZONE> const& r )
50 {
51 return l->GetAssignedPriority() > r->GetAssignedPriority();
52 } );
53
54 unsigned currentPriority = clonedZones.size() - 1;
55
56 for( const std::shared_ptr<ZONE>& zone : clonedZones )
57 {
58 m_managedZones.push_back( std::make_shared<MANAGED_ZONE>( zone, currentPriority ) );
59 --currentPriority;
60 }
61}
62
63
65{
66 m_zoneSettings[nullptr] = std::make_shared<ZONE_SETTINGS>( *aSettings );
67}
68
69
70std::shared_ptr<ZONE_SETTINGS> ZONE_SETTINGS_BAG::GetZoneSettings( ZONE* aZone )
71{
72 if( auto ll = m_zoneSettings.find( aZone ); ll != m_zoneSettings.end() )
73 return ll->second;
74
75 std::shared_ptr<ZONE_SETTINGS> zoneSetting = std::make_shared<ZONE_SETTINGS>();
76 *zoneSetting << *aZone;
77 m_zoneSettings.try_emplace( aZone, zoneSetting );
78 return zoneSetting;
79}
80
81
83{
86
87 for( const auto& [ zone, zoneClone ] : m_zonesCloneMap )
88 {
89 std::map<PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>> filled_zone_to_restore;
90 ZONE* internal_zone = zone; // Duplicate the zone pointer to allow capture on older MacOS (13)
91
93 [&]( PCB_LAYER_ID layer )
94 {
95 std::shared_ptr<SHAPE_POLY_SET> fill = internal_zone->GetFilledPolysList( layer );
96
97 if( fill )
98 filled_zone_to_restore[layer] = fill;
99 } );
100
101 *zone = *zoneClone;
102
103 for( const auto& [ layer, fill ] : filled_zone_to_restore )
104 zone->SetFilledPolysList( layer, *fill );
105 }
106}
107
108
110{
111 for( const std::shared_ptr<MANAGED_ZONE>& zone : m_managedZones )
112 {
113 if( auto ll = m_zoneSettings.find( &zone->GetZone() ); ll != m_zoneSettings.end() )
114 ll->second->ExportSetting( zone->GetZone() );
115 }
116}
117
118
120{
121 bool priorityChanged = false;
122
123 for( const std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
124 {
125 if( c->PriorityChanged() )
126 {
127 priorityChanged = true;
128 break;
129 }
130 }
131
132 if( priorityChanged )
133 {
134 for( std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
135 c->OnUserConfirmChange();
136 }
137
138 return priorityChanged;
139}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const ZONES & Zones() const
Definition board.h:367
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
Definition lset.h:252
std::shared_ptr< ZONE_SETTINGS > GetZoneSettings(ZONE *zone)
std::vector< std::shared_ptr< MANAGED_ZONE > > m_managedZones
ZONE_SETTINGS_BAG()=default
std::unordered_map< ZONE *, std::shared_ptr< ZONE > > m_zonesCloneMap
bool FlushPriorityChange()
Flush the priority change to the cloned ones.
std::vector< ZONE * > m_clonedZoneList
std::unordered_map< ZONE *, std::shared_ptr< ZONE_SETTINGS > > m_zoneSettings
void FlushZoneSettingsChange()
Flush the zone settings change to the cloned ones.
ZONE_SETTINGS handles zones parameters.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:596
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:136
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60