/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2023 Ethan Chien * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, you may find one here: * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * or you may search the http://www.gnu.org website for the version 2 license, * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include "zones_container.h" #include "zone_priority_container.h" #include #include #include #include ZONES_CONTAINER::ZONES_CONTAINER( BOARD* aBoard ) : m_originalZoneList( aBoard->Zones() ) { std::vector> clonedZones; for( ZONE* zone : aBoard->Zones() ) { if( ( !zone->GetIsRuleArea() ) && IsCopperLayer( zone->GetFirstLayer() ) && ( !zone->IsTeardropArea() ) ) { std::shared_ptr zone_clone = std::shared_ptr( static_cast( zone->Clone() ) ); m_zonesCloneMap.try_emplace( zone, zone_clone ); m_clonedZoneList.push_back( zone_clone.get() ); clonedZones.push_back( std::move( zone_clone ) ); } } std::sort( clonedZones.begin(), clonedZones.end(), []( std::shared_ptr const& l, std::shared_ptr const& r ) { return l->GetAssignedPriority() > r->GetAssignedPriority(); } ); unsigned currentPriority = clonedZones.size() - 1; for( const std::shared_ptr& zone : clonedZones ) { m_zonesPriorityContainer.push_back( std::make_shared( zone, currentPriority ) ); --currentPriority; } } ZONES_CONTAINER::~ZONES_CONTAINER() = default; std::shared_ptr ZONES_CONTAINER::GetZoneSettings( ZONE* aZone ) { if( auto ll = m_zoneSettings.find( aZone ); ll != m_zoneSettings.end() ) return ll->second; std::shared_ptr zoneSetting = std::make_shared(); *zoneSetting << *aZone; m_zoneSettings.try_emplace( aZone, zoneSetting ); return zoneSetting; } void ZONES_CONTAINER::OnUserConfirmChange() { FlushZoneSettingsChange(); FlushPriorityChange(); for( auto& [ zone, zoneClone ] : m_zonesCloneMap ) *zone = *zoneClone; } void ZONES_CONTAINER::FlushZoneSettingsChange() { for( const std::shared_ptr& zone : m_zonesPriorityContainer ) { if( auto ll = m_zoneSettings.find( &zone->GetZone() ); ll != m_zoneSettings.end() ) ll->second->ExportSetting( zone->GetZone() ); } } bool ZONES_CONTAINER::FlushPriorityChange() { bool priorityChanged = false; for( const std::shared_ptr& c : m_zonesPriorityContainer ) { if( c->PriorityChanged() ) { priorityChanged = true; break; } } if( priorityChanged ) { for( std::shared_ptr& c : m_zonesPriorityContainer ) c->OnUserConfirmChange(); } return priorityChanged; }