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->IsOnCopperLayer() )
37 {
38 auto zone_clone = std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
39 m_zonesCloneMap.try_emplace( zone, zone_clone );
40 m_clonedZoneList.push_back( zone_clone.get() );
41 }
42 }
43
44 for( ZONE* zone : m_clonedZoneList )
45 {
46 m_zoneSettings[zone] = std::make_shared<ZONE_SETTINGS>();
47 *m_zoneSettings[zone] << *zone;
48 }
49
50 std::vector<ZONE*> sortedClonedZones = m_clonedZoneList;
51
52 std::sort( sortedClonedZones.begin(), sortedClonedZones.end(),
53 []( ZONE* const& l, ZONE* const& r )
54 {
55 return l->GetAssignedPriority() > r->GetAssignedPriority();
56 } );
57
58 unsigned currentPriority = sortedClonedZones.size() - 1;
59
60 for( ZONE* zone : sortedClonedZones )
61 {
62 m_zonePriorities[zone] = std::make_pair<>( currentPriority, currentPriority );
63 --currentPriority;
64 }
65}
66
67
69{
70 m_zoneSettings[aZone] = std::make_shared<ZONE_SETTINGS>( *aSettings );
71}
72
73
74std::shared_ptr<ZONE_SETTINGS> ZONE_SETTINGS_BAG::GetZoneSettings( ZONE* aZone )
75{
76 return m_zoneSettings[aZone];
77}
78
79
81{
82 return m_zonePriorities[aZone].second;
83}
84
85
86void ZONE_SETTINGS_BAG::SwapPriority( ZONE* aZone, ZONE* otherZone )
87{
88 std::swap( m_zonePriorities[aZone].second, m_zonePriorities[otherZone].second );
89}
90
91
93{
94 for( ZONE* zone : m_clonedZoneList )
95 {
96 if( m_zoneSettings.contains( zone ) )
97 m_zoneSettings[zone]->ExportSetting( *zone );
98 }
99
100 // Prevent version-control churn by not updating potentially sparse priorities if their
101 // order didn't change.
102 bool priorityChanged = false;
103
104 for( ZONE* zone : m_clonedZoneList )
105 {
106 if( m_zonePriorities[zone].first != m_zonePriorities[zone].second )
107 {
108 priorityChanged = true;
109 break;
110 }
111 }
112
113 if( priorityChanged )
114 {
115 for( ZONE* zone : m_clonedZoneList )
116 zone->SetAssignedPriority( m_zonePriorities[zone].second );
117 }
118}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const ZONES & Zones() const
Definition board.h:367
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