7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 17:53:45 +00:00

Cleanup and formatting.

This commit is contained in:
Jeff Young 2024-08-15 08:41:24 -06:00
parent 67b9170146
commit 15d266f9a8
6 changed files with 68 additions and 78 deletions

View File

@ -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() );

View File

@ -23,8 +23,8 @@
*/
#ifndef ZONE_PRIORITY_CONTAINER_H
#define ZONE_PRIORITY_CONTAINER_H
#ifndef MANAGED_ZONE_H
#define MANAGED_ZONE_H
#include <memory>
#include <utility>
@ -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<ZONE> aZone, unsigned aInitialIndex ) :
MANAGED_ZONE( std::shared_ptr<ZONE> 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; }

View File

@ -31,18 +31,15 @@
#include <pcb_edit_frame.h>
#include <wx/variant.h>
#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<ZONE_PRIORITY_CONTAINER> const& l,
std::shared_ptr<ZONE_PRIORITY_CONTAINER> const& r
)
std::sort( m_filteredZones.begin(), m_filteredZones.end(),
[]( std::shared_ptr<MANAGED_ZONE> const& l, std::shared_ptr<MANAGED_ZONE> 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<std::shared_ptr<MANAGED_ZONE>> 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<size_t>( aRow ) + 1 > m_filteredZoneContainers.size() )
if( static_cast<size_t>( 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<unsigned> 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();

View File

@ -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<std::shared_ptr<ZONE_PRIORITY_CONTAINER>>;
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<std::shared_ptr<MANAGED_ZONE>> 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<std::shared_ptr<MANAGED_ZONE>> m_allZones;
std::vector<std::shared_ptr<MANAGED_ZONE>> m_filteredZones;
BOARD* m_pcb;
PCB_BASE_FRAME* m_PCB_FRAME;
wxWindow* m_dialog;
bool m_sortByName;
bool m_sortByNet;
};
#endif

View File

@ -23,7 +23,7 @@
*/
#include "zones_container.h"
#include "zone_priority_container.h"
#include "managed_zone.h"
#include <teardrop/teardrop_types.h>
#include <zone.h>
@ -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> zone_clone =
std::shared_ptr<ZONE>( static_cast<ZONE*>( zone->Clone() ) );
auto zone_clone = std::shared_ptr<ZONE>( static_cast<ZONE*>( 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<ZONE> const& l, std::shared_ptr<ZONE> const& r
)
[]( std::shared_ptr<ZONE> const& l, std::shared_ptr<ZONE> 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>& zone : clonedZones )
{
m_zonesPriorityContainer.push_back(
std::make_shared<ZONE_PRIORITY_CONTAINER>( zone, currentPriority ) );
m_managedZones.push_back( std::make_shared<MANAGED_ZONE>( zone, currentPriority ) );
--currentPriority;
}
}
ZONES_CONTAINER::~ZONES_CONTAINER() = default;
std::shared_ptr<ZONE_SETTINGS> ZONES_CONTAINER::GetZoneSettings( ZONE* aZone )
{
@ -79,16 +73,14 @@ std::shared_ptr<ZONE_SETTINGS> 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<ZONE> zoneClone = iter.second;
std::map<PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>> 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<SHAPE_POLY_SET> 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_PRIORITY_CONTAINER>& zone : m_zonesPriorityContainer )
for( const std::shared_ptr<MANAGED_ZONE>& 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<ZONE_PRIORITY_CONTAINER>& c : m_zonesPriorityContainer )
for( const std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
{
if( c->PriorityChanged() )
{
@ -135,7 +124,7 @@ bool ZONES_CONTAINER::FlushPriorityChange()
if( priorityChanged )
{
for( std::shared_ptr<ZONE_PRIORITY_CONTAINER>& c : m_zonesPriorityContainer )
for( std::shared_ptr<MANAGED_ZONE>& c : m_managedZones )
c->OnUserConfirmChange();
}

View File

@ -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<std::shared_ptr<ZONE_PRIORITY_CONTAINER>> GetZonesPriorityContainers() const
std::vector<std::shared_ptr<MANAGED_ZONE>> GetManagedZones() const
{
return m_zonesPriorityContainer;
return m_managedZones;
}
std::shared_ptr<ZONE_SETTINGS> GetZoneSettings( ZONE* zone );
@ -75,7 +77,7 @@ public:
private:
std::unordered_map<ZONE*, std::shared_ptr<ZONE>> m_zonesCloneMap;
std::unordered_map<ZONE*, std::shared_ptr<ZONE_SETTINGS>> m_zoneSettings;
std::vector<std::shared_ptr<ZONE_PRIORITY_CONTAINER>> m_zonesPriorityContainer;
std::vector<std::shared_ptr<MANAGED_ZONE>> m_managedZones;
std::vector<ZONE*> m_clonedZoneList;
std::vector<ZONE*> m_originalZoneList;
};