diff --git a/pcbnew/zone_manager/dialog_zone_manager.cpp b/pcbnew/zone_manager/dialog_zone_manager.cpp index 88915431e4..a2d195e30c 100644 --- a/pcbnew/zone_manager/dialog_zone_manager.cpp +++ b/pcbnew/zone_manager/dialog_zone_manager.cpp @@ -89,7 +89,7 @@ DIALOG_ZONE_MANAGER::DIALOG_ZONE_MANAGER( PCB_BASE_FRAME* aParent, ZONE_SETTINGS m_viewZonesOverview->AppendTextColumn( v, k ); } - m_modelZoneOverviewTable = new MODEL_ZONES_OVERVIEW_TABLE( m_zonesContainer->GetZonesPriorityContainers(), + m_modelZoneOverviewTable = new MODEL_ZONES_OVERVIEW_TABLE( m_zonesContainer->GetManagedZones(), aParent->GetBoard(), aParent, this ); m_viewZonesOverview->AssociateModel( m_modelZoneOverviewTable.get() ); diff --git a/pcbnew/zone_manager/zone_priority_container.h b/pcbnew/zone_manager/managed_zone.h similarity index 86% rename from pcbnew/zone_manager/zone_priority_container.h rename to pcbnew/zone_manager/managed_zone.h index a053b97729..da90236b63 100644 --- a/pcbnew/zone_manager/zone_priority_container.h +++ b/pcbnew/zone_manager/managed_zone.h @@ -23,8 +23,8 @@ */ -#ifndef ZONE_PRIORITY_CONTAINER_H -#define ZONE_PRIORITY_CONTAINER_H +#ifndef MANAGED_ZONE_H +#define MANAGED_ZONE_H #include #include @@ -34,21 +34,21 @@ * @brief Workaround to keep the original priorities if user didn't change any * */ -class ZONE_PRIORITY_CONTAINER : public ZONE_MANAGEMENT_BASE +class MANAGED_ZONE : public ZONE_MANAGEMENT_BASE { friend class MODEL_ZONES_OVERVIEW_TABLE; public: - ZONE_PRIORITY_CONTAINER( std::shared_ptr aZone, unsigned aInitialIndex ) : + MANAGED_ZONE( std::shared_ptr aZone, unsigned aInitialIndex ) : m_zone( std::move( aZone ) ), m_initialPriority( aInitialIndex ), m_currentPriority( aInitialIndex ) { } - ZONE_PRIORITY_CONTAINER() = delete; + MANAGED_ZONE() = delete; - ~ZONE_PRIORITY_CONTAINER() override = default; + ~MANAGED_ZONE() override = default; bool PriorityChanged() const { return m_initialPriority != m_currentPriority; } diff --git a/pcbnew/zone_manager/model_zones_overview_table.cpp b/pcbnew/zone_manager/model_zones_overview_table.cpp index b30664b2c4..de881fdfde 100644 --- a/pcbnew/zone_manager/model_zones_overview_table.cpp +++ b/pcbnew/zone_manager/model_zones_overview_table.cpp @@ -31,18 +31,15 @@ #include #include #include "zone_manager_preference.h" -#include "zone_priority_container.h" +#include "managed_zone.h" #include "model_zones_overview_table.h" wxDEFINE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); void MODEL_ZONES_OVERVIEW_TABLE::SortZoneContainers() { - std::sort( m_filteredZoneContainers.begin(), m_filteredZoneContainers.end(), - []( std::shared_ptr const& l, - std::shared_ptr const& r - - ) + std::sort( m_filteredZones.begin(), m_filteredZones.end(), + []( std::shared_ptr const& l, std::shared_ptr const& r ) { return l->GetCurrentPriority() > r->GetCurrentPriority(); } ); @@ -72,9 +69,13 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s if( layer_cout > 4 ) { - for( const PCB_LAYER_ID& i : - { layers[0], layers[1], layers[layer_cout - 1], layers[layer_cout - 2] } ) + for( const PCB_LAYER_ID& i : { layers[0], + layers[1], + layers[layer_cout - 1], + layers[layer_cout - 2] } ) + { layersToDraw.push_back( i ); + } } else { @@ -97,18 +98,18 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s } -MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( ZONE_PRIORITY_CONTAINER_LIST aZones, +MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( std::vector> aZones, BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ) : - m_allZoneContainers( aZones ), - m_filteredZoneContainers( std::move( aZones ) ), + m_allZones( aZones ), + m_filteredZones( std::move( aZones ) ), m_pcb( a_pcb ), m_PCB_FRAME( aPCB_FRAME ), m_dialog( a_dialog ), m_sortByName( true ), m_sortByNet( true ) { - Reset( m_filteredZoneContainers.size() ); + Reset( m_filteredZones.size() ); } @@ -118,10 +119,10 @@ MODEL_ZONES_OVERVIEW_TABLE::~MODEL_ZONES_OVERVIEW_TABLE() = default; void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aRow, unsigned aCol ) const { - if( static_cast( aRow ) + 1 > m_filteredZoneContainers.size() ) + if( static_cast( aRow ) + 1 > m_filteredZones.size() ) return; - const ZONE& cur = m_filteredZoneContainers[aRow]->GetZone(); + const ZONE& cur = m_filteredZones[aRow]->GetZone(); switch( aCol ) { @@ -136,15 +137,15 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR case LAYERS: { wxArrayString layers; + wxSize bmSize( LAYER_BAR_WIDTH, ZONE_MANAGER_PREFERENCE::LAYER_ICON_SIZE::HEIGHT ); for( PCB_LAYER_ID layer : cur.GetLayerSet().Seq() ) layers.Add( m_pcb->GetLayerName( layer ) ); - aVariant << wxDataViewIconText( - wxJoin( layers, ',' ), - MakeBitmapForLayers( - cur.GetLayerSet().Seq(), *m_PCB_FRAME->GetColorSettings(), - { LAYER_BAR_WIDTH, ZONE_MANAGER_PREFERENCE::LAYER_ICON_SIZE::HEIGHT } ) ); + aVariant << wxDataViewIconText( wxJoin( layers, ',' ), + MakeBitmapForLayers( cur.GetLayerSet().Seq(), + *m_PCB_FRAME->GetColorSettings(), + bmSize ) ); break; } @@ -175,7 +176,7 @@ bool MODEL_ZONES_OVERVIEW_TABLE::SetValueByRow( const wxVariant& aVariant, unsig unsigned int MODEL_ZONES_OVERVIEW_TABLE::GetCount() const { - return m_filteredZoneContainers.size(); + return m_filteredZones.size(); } @@ -189,7 +190,7 @@ ZONE* MODEL_ZONES_OVERVIEW_TABLE::GetZone( wxDataViewItem const& aItem ) const if( aRow + 1 > GetCount() ) return nullptr; - return &m_filteredZoneContainers[aRow]->GetZone(); + return &m_filteredZones[aRow]->GetZone(); } @@ -198,9 +199,9 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const if( !aZone ) return {}; - for( size_t i = 0; i < m_filteredZoneContainers.size(); i++ ) + for( size_t i = 0; i < m_filteredZones.size(); i++ ) { - if( &m_filteredZoneContainers[i]->GetZone() == aZone ) + if( &m_filteredZones[i]->GetZone() == aZone ) return GetItem( i ); } @@ -242,9 +243,9 @@ std::optional MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a if( aDragIndex == aDropIndex ) return aDragIndex; - std::swap( m_filteredZoneContainers[aDragIndex]->m_currentPriority, - m_filteredZoneContainers[aDropIndex]->m_currentPriority ); - std::swap( m_filteredZoneContainers[aDragIndex], m_filteredZoneContainers[aDropIndex] ); + std::swap( m_filteredZones[aDragIndex]->m_currentPriority, + m_filteredZones[aDropIndex]->m_currentPriority ); + std::swap( m_filteredZones[aDragIndex], m_filteredZones[aDropIndex] ); for( const unsigned int row : { aDragIndex, aDropIndex } ) RowChanged( row ); @@ -265,16 +266,16 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ApplyFilter( wxString const& aFilterT return ClearFilter( aSelection ); ZONE* selected_zone = GetZone( aSelection ); - m_filteredZoneContainers.clear(); + m_filteredZones.clear(); - for( const auto& container : m_allZoneContainers ) + for( const auto& container : m_allZones ) { const ZONE zone = container->GetZone(); if( ( m_sortByName && zone.GetZoneName().Lower().Contains( lowerFilterText ) ) || ( m_sortByNet && zone.GetNetname().Lower().Contains( lowerFilterText ) ) ) { - m_filteredZoneContainers.push_back( container ); + m_filteredZones.push_back( container ); } } @@ -291,7 +292,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ClearFilter( wxDataViewItem aSelectio return {}; ZONE* zone = GetZone( aSelection ); - m_filteredZoneContainers = m_allZoneContainers; + m_filteredZones = m_allZones; SortZoneContainers(); Reset( GetCount() ); OnRowCountChange(); diff --git a/pcbnew/zone_manager/model_zones_overview_table.h b/pcbnew/zone_manager/model_zones_overview_table.h index 4af0559399..86f29ac5b0 100644 --- a/pcbnew/zone_manager/model_zones_overview_table.h +++ b/pcbnew/zone_manager/model_zones_overview_table.h @@ -37,12 +37,10 @@ class PCB_BASE_FRAME; class PCB_BASE_FRAME; -class ZONE_PRIORITY_CONTAINER; +class MANAGED_ZONE; wxDECLARE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); -using ZONE_PRIORITY_CONTAINER_LIST = std::vector>; - enum class ZONE_INDEX_MOVEMENT { @@ -81,7 +79,7 @@ public: return ColNames; } - MODEL_ZONES_OVERVIEW_TABLE( ZONE_PRIORITY_CONTAINER_LIST aZones, BOARD* a_pcb, + MODEL_ZONES_OVERVIEW_TABLE( std::vector> aZones, BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ); ~MODEL_ZONES_OVERVIEW_TABLE() override; @@ -132,7 +130,7 @@ public: */ wxDataViewItem ClearFilter( wxDataViewItem aSelection ); - unsigned int GetAllZonesCount() const { return m_allZoneContainers.size(); } + unsigned int GetAllZonesCount() const { return m_allZones.size(); } private: void SortZoneContainers(); @@ -140,13 +138,13 @@ private: void OnRowCountChange(); private: - ZONE_PRIORITY_CONTAINER_LIST m_allZoneContainers; - ZONE_PRIORITY_CONTAINER_LIST m_filteredZoneContainers; - BOARD* m_pcb; - PCB_BASE_FRAME* m_PCB_FRAME; - wxWindow* m_dialog; - bool m_sortByName; - bool m_sortByNet; + std::vector> m_allZones; + std::vector> m_filteredZones; + BOARD* m_pcb; + PCB_BASE_FRAME* m_PCB_FRAME; + wxWindow* m_dialog; + bool m_sortByName; + bool m_sortByNet; }; #endif \ No newline at end of file diff --git a/pcbnew/zone_manager/zones_container.cpp b/pcbnew/zone_manager/zones_container.cpp index f64714f068..08df9866bd 100644 --- a/pcbnew/zone_manager/zones_container.cpp +++ b/pcbnew/zone_manager/zones_container.cpp @@ -23,7 +23,7 @@ */ #include "zones_container.h" -#include "zone_priority_container.h" +#include "managed_zone.h" #include #include @@ -37,11 +37,9 @@ ZONES_CONTAINER::ZONES_CONTAINER( BOARD* aBoard ) : m_originalZoneList( aBoard-> for( ZONE* zone : aBoard->Zones() ) { - if( ( !zone->GetIsRuleArea() ) && IsCopperLayer( zone->GetFirstLayer() ) - && ( !zone->IsTeardropArea() ) ) + if( !zone->GetIsRuleArea() && !zone->IsTeardropArea() && zone->IsOnCopperLayer() ) { - std::shared_ptr zone_clone = - std::shared_ptr( static_cast( zone->Clone() ) ); + auto 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 ) ); @@ -49,9 +47,7 @@ ZONES_CONTAINER::ZONES_CONTAINER( BOARD* aBoard ) : m_originalZoneList( aBoard-> } std::sort( clonedZones.begin(), clonedZones.end(), - []( std::shared_ptr const& l, std::shared_ptr const& r - - ) + []( std::shared_ptr const& l, std::shared_ptr const& r ) { return l->GetAssignedPriority() > r->GetAssignedPriority(); } ); @@ -60,13 +56,11 @@ ZONES_CONTAINER::ZONES_CONTAINER( BOARD* aBoard ) : m_originalZoneList( aBoard-> for( const std::shared_ptr& zone : clonedZones ) { - m_zonesPriorityContainer.push_back( - std::make_shared( zone, currentPriority ) ); + m_managedZones.push_back( std::make_shared( zone, currentPriority ) ); --currentPriority; } } -ZONES_CONTAINER::~ZONES_CONTAINER() = default; std::shared_ptr ZONES_CONTAINER::GetZoneSettings( ZONE* aZone ) { @@ -79,16 +73,14 @@ std::shared_ptr ZONES_CONTAINER::GetZoneSettings( ZONE* aZone ) return zoneSetting; } + void ZONES_CONTAINER::OnUserConfirmChange() { FlushZoneSettingsChange(); FlushPriorityChange(); - for( auto iter : m_zonesCloneMap ) + for( const auto& [ zone, zoneClone ] : m_zonesCloneMap ) { - ZONE* zone = iter.first; - std::shared_ptr zoneClone = iter.second; - std::map> filled_zone_to_restore; ZONE* internal_zone = zone; // Duplicate the zone pointer to allow capture on older MacOS (13) @@ -96,24 +88,21 @@ void ZONES_CONTAINER::OnUserConfirmChange() [&]( PCB_LAYER_ID layer ) { std::shared_ptr fill = internal_zone->GetFilledPolysList( layer ); + if( fill ) - { filled_zone_to_restore[layer] = fill; - } } ); *zone = *zoneClone; - for( auto& it : filled_zone_to_restore ) - { - zone->SetFilledPolysList( it.first, *it.second.get() ); - } + for( const auto& [ layer, fill ] : filled_zone_to_restore ) + zone->SetFilledPolysList( layer, *fill ); } } void ZONES_CONTAINER::FlushZoneSettingsChange() { - for( const std::shared_ptr& zone : m_zonesPriorityContainer ) + for( const std::shared_ptr& zone : m_managedZones ) { if( auto ll = m_zoneSettings.find( &zone->GetZone() ); ll != m_zoneSettings.end() ) ll->second->ExportSetting( zone->GetZone() ); @@ -124,7 +113,7 @@ bool ZONES_CONTAINER::FlushPriorityChange() { bool priorityChanged = false; - for( const std::shared_ptr& c : m_zonesPriorityContainer ) + for( const std::shared_ptr& c : m_managedZones ) { if( c->PriorityChanged() ) { @@ -135,7 +124,7 @@ bool ZONES_CONTAINER::FlushPriorityChange() if( priorityChanged ) { - for( std::shared_ptr& c : m_zonesPriorityContainer ) + for( std::shared_ptr& c : m_managedZones ) c->OnUserConfirmChange(); } diff --git a/pcbnew/zone_manager/zones_container.h b/pcbnew/zone_manager/zones_container.h index 3ac57502a1..dbd1a02554 100644 --- a/pcbnew/zone_manager/zones_container.h +++ b/pcbnew/zone_manager/zones_container.h @@ -33,16 +33,18 @@ #include "zone_management_base.h" #include "zone_settings.h" -class ZONE_PRIORITY_CONTAINER; +class MANAGED_ZONE; + + class ZONES_CONTAINER : public ZONE_MANAGEMENT_BASE { public: ZONES_CONTAINER( BOARD* board ); - ~ZONES_CONTAINER() override; + ~ZONES_CONTAINER() override = default; - std::vector> GetZonesPriorityContainers() const + std::vector> GetManagedZones() const { - return m_zonesPriorityContainer; + return m_managedZones; } std::shared_ptr GetZoneSettings( ZONE* zone ); @@ -75,7 +77,7 @@ public: private: std::unordered_map> m_zonesCloneMap; std::unordered_map> m_zoneSettings; - std::vector> m_zonesPriorityContainer; + std::vector> m_managedZones; std::vector m_clonedZoneList; std::vector m_originalZoneList; };