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"
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() ) && IsCopperLayer( zone->GetFirstLayer() )
41 && ( !zone->IsTeardropArea() ) )
42 {
43 std::shared_ptr<ZONE> zone_clone =
44 std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
45 m_zonesColoneMap.try_emplace( zone, zone_clone );
46 m_clonedZoneList.push_back( zone_clone.get() );
47 clonedZones.push_back( std::move( zone_clone ) );
48 }
49 }
50
51 std::sort( clonedZones.begin(), clonedZones.end(),
52 []( std::shared_ptr<ZONE> const& l, std::shared_ptr<ZONE> const& r
53
54 )
55 {
56 return l->GetAssignedPriority() > r->GetAssignedPriority();
57 } );
58
59 unsigned currentPriority = clonedZones.size() - 1;
60
61 for( const std::shared_ptr<ZONE>& zone : clonedZones )
62 {
64 std::make_shared<ZONE_PRIORITY_CONTAINER>( zone, currentPriority ) );
65 --currentPriority;
66 }
67}
68
70
71std::shared_ptr<ZONE_SETTINGS> ZONES_CONTAINER::GetZoneSettings( ZONE* aZone )
72{
73 if( auto ll = m_zoneSettings.find( aZone ); ll != m_zoneSettings.end() )
74 return ll->second;
75
76 std::shared_ptr<ZONE_SETTINGS> zoneSetting = std::make_shared<ZONE_SETTINGS>();
77 *zoneSetting << *aZone;
78 m_zoneSettings.try_emplace( aZone, zoneSetting );
79 return zoneSetting;
80}
81
83{
86
87 for( auto& [c, v] : m_zonesColoneMap )
88 {
89 *c = *v;
90 }
91}
92
94{
95 for( const std::shared_ptr<ZONE_PRIORITY_CONTAINER>& zone : m_zonesPriorityContainer )
96 {
97 if( auto ll = m_zoneSettings.find( &zone->GetZone() ); ll != m_zoneSettings.end() )
98 ll->second->ExportSetting( zone->GetZone() );
99 }
100}
101
103{
104 bool priorityChanged = false;
105
106 for( const std::shared_ptr<ZONE_PRIORITY_CONTAINER>& c : m_zonesPriorityContainer )
107 {
108 if( c->PriorityChanged() )
109 {
110 priorityChanged = true;
111 break;
112 }
113 }
114
115 if( priorityChanged )
116 {
117 for( std::shared_ptr<ZONE_PRIORITY_CONTAINER>& c : m_zonesPriorityContainer )
118 {
119 c->OnUserConfirmChange();
120 }
121 }
122
123 return priorityChanged;
124}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
const ZONES & Zones() const
Definition: board.h:327
std::shared_ptr< ZONE_SETTINGS > GetZoneSettings(ZONE *zone)
std::vector< ZONE * > m_clonedZoneList
std::vector< std::shared_ptr< ZONE_PRIORITY_CONTAINER > > m_zonesPriorityContainer
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_zonesColoneMap
void OnUserConfirmChange() override
std::unordered_map< ZONE *, std::shared_ptr< ZONE_SETTINGS > > m_zoneSettings
~ZONES_CONTAINER() override
ZONES_CONTAINER(BOARD *board)
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:881