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
27#include <zone.h>
28#include <memory>
29#include <algorithm>
30
31
33{
34 for( ZONE* zone : aBoard->Zones() )
35 {
36 if( !zone->GetIsRuleArea() && !zone->IsTeardropArea() && !zone->IsCopperThieving()
37 && zone->IsOnCopperLayer() )
38 {
39 auto zone_clone = std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
40 m_zonesCloneMap.try_emplace( zone, zone_clone );
41 m_clonedZoneList.push_back( zone_clone.get() );
42 }
43 }
44
45 for( ZONE* zone : m_clonedZoneList )
46 {
47 m_zoneSettings[zone] = std::make_shared<ZONE_SETTINGS>();
48 *m_zoneSettings[zone] << *zone;
49 }
50
51 std::vector<ZONE*> sortedClonedZones = m_clonedZoneList;
52
53 std::sort( sortedClonedZones.begin(), sortedClonedZones.end(),
54 []( ZONE* const& l, ZONE* const& r )
55 {
56 return l->HigherPriority( r );
57 } );
58
59 unsigned currentPriority = sortedClonedZones.size() - 1;
60
61 for( ZONE* zone : sortedClonedZones )
62 {
63 m_zonePriorities[zone] = std::make_pair<>( currentPriority, currentPriority );
64 --currentPriority;
65 }
66}
67
68
70{
71 m_zoneSettings[aZone] = std::make_shared<ZONE_SETTINGS>( *aSettings );
72}
73
74
75std::shared_ptr<ZONE_SETTINGS> ZONE_SETTINGS_BAG::GetZoneSettings( ZONE* aZone )
76{
77 return m_zoneSettings[aZone];
78}
79
80
82{
83 return m_zonePriorities[aZone].second;
84}
85
86
87void ZONE_SETTINGS_BAG::SwapPriority( ZONE* aZone, ZONE* otherZone )
88{
89 std::swap( m_zonePriorities[aZone].second, m_zonePriorities[otherZone].second );
90}
91
92
93void ZONE_SETTINGS_BAG::SetZonePriority( ZONE* aClone, unsigned aPriority )
94{
95 m_zonePriorities[aClone].second = aPriority;
96
97 if( m_zoneSettings.contains( aClone ) )
98 m_zoneSettings[aClone]->m_ZonePriority = aPriority;
99}
100
101
103{
104 for( ZONE* zone : m_clonedZoneList )
105 {
106 if( m_zoneSettings.contains( zone ) )
107 m_zoneSettings[zone]->ExportSetting( *zone );
108 }
109
110 // Prevent version-control churn by not updating potentially sparse priorities if their
111 // order didn't change.
112 bool priorityChanged = false;
113
114 for( ZONE* zone : m_clonedZoneList )
115 {
116 if( m_zonePriorities[zone].first != m_zonePriorities[zone].second )
117 {
118 priorityChanged = true;
119 break;
120 }
121 }
122
123 if( priorityChanged )
124 {
125 for( ZONE* zone : m_clonedZoneList )
126 zone->SetAssignedPriority( m_zonePriorities[zone].second );
127 }
128}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
const ZONES & Zones() const
Definition board.h:368
void SetZonePriority(ZONE *aClone, unsigned aPriority)
Update the tracked priority for a cloned zone.
unsigned GetZonePriority(ZONE *aZone)
ZONE_SETTINGS_BAG()=default
std::unordered_map< ZONE *, std::shared_ptr< ZONE > > m_zonesCloneMap
void UpdateClonedZones()
The cloned list is the working storage.
std::vector< ZONE * > m_clonedZoneList
void SwapPriority(ZONE *aZOne, ZONE *otherZone)
std::unordered_map< ZONE *, std::shared_ptr< ZONE_SETTINGS > > m_zoneSettings
std::shared_ptr< ZONE_SETTINGS > GetZoneSettings(ZONE *aZone)
std::unordered_map< ZONE *, std::pair< unsigned, unsigned > > m_zonePriorities
ZONE_SETTINGS handles zones parameters.
Handle a list of polygons defining a copper zone.
Definition zone.h:74