From 96fe93618e3676d1473fac1d6fd19597fb9f4a85 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 25 Nov 2022 16:29:56 -0500 Subject: [PATCH] Properties: Stop sorting by name It's more useful to have properties shown in add order, since we can group them --- common/properties/property_mgr.cpp | 20 +++++++++++++++++++- common/widgets/properties_panel.cpp | 4 ++-- include/properties/property.h | 6 ++++++ include/properties/property_mgr.h | 24 +++++++++++++++++++++++- pcbnew/board_item.cpp | 4 ++-- pcbnew/dialogs/pcb_properties_panel.cpp | 6 ++++-- pcbnew/footprint.cpp | 22 ++++++++++++---------- 7 files changed, 68 insertions(+), 18 deletions(-) diff --git a/common/properties/property_mgr.cpp b/common/properties/property_mgr.cpp index 2ad72acaed..7a9c2ce406 100644 --- a/common/properties/property_mgr.cpp +++ b/common/properties/property_mgr.cpp @@ -24,9 +24,15 @@ #include #include +#include static wxString EMPTY_STRING( wxEmptyString ); +const PROPERTY_MANAGER::PROPERTY_GROUP PROPERTY_MANAGER::DEFAULT_GROUP = { + 0, + _( "Other Properties" ) +}; + void PROPERTY_MANAGER::RegisterType( TYPE_ID aType, const wxString& aName ) { @@ -99,12 +105,16 @@ const void* PROPERTY_MANAGER::TypeCast( const void* aSource, TYPE_ID aBase, TYPE } -void PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty ) +void PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty, const PROPERTY_GROUP& aGroup ) { const wxString& name = aProperty->Name(); TYPE_ID hash = aProperty->OwnerHash(); CLASS_DESC& classDesc = getClass( hash ); classDesc.m_ownProperties.emplace( name, aProperty ); + + if( aGroup.id > DEFAULT_GROUP.id && aGroup.id < classDesc.m_groups.size() ) + aProperty->SetGroup( aGroup.id ); + m_dirty = true; } @@ -118,6 +128,14 @@ void PROPERTY_MANAGER::ReplaceProperty( size_t aBase, const wxString& aName, PRO } +const PROPERTY_MANAGER::PROPERTY_GROUP& PROPERTY_MANAGER::AddPropertyGroup( TYPE_ID aOwner, + const wxString& aName ) +{ + CLASS_DESC& desc = getClass( aOwner ); + return desc.m_groups.emplace_back( PROPERTY_GROUP( { desc.m_groups.size(), aName } ) ); +} + + void PROPERTY_MANAGER::AddTypeCast( TYPE_CAST_BASE* aCast ) { TYPE_ID derivedHash = aCast->DerivedHash(); diff --git a/common/widgets/properties_panel.cpp b/common/widgets/properties_panel.cpp index 3b326611fc..5c448c70c7 100644 --- a/common/widgets/properties_panel.cpp +++ b/common/widgets/properties_panel.cpp @@ -54,7 +54,7 @@ PROPERTIES_PANEL::PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame ) mainSizer->Add( m_caption, 0, wxALL | wxEXPAND, 5 ); m_grid = new wxPropertyGrid( this, wxID_ANY, wxDefaultPosition, wxSize( 300, 400 ), - wxPG_AUTO_SORT | wxPG_DEFAULT_STYLE ); + wxPG_DEFAULT_STYLE ); m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT( "<...>" ) ) ); m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS ); mainSizer->Add( m_grid, 1, wxALL | wxEXPAND, 5 ); @@ -107,7 +107,7 @@ void PROPERTIES_PANEL::update( const SELECTION& aSelection ) if( aSelection.Size() > 1 ) { - m_caption->SetLabel( _( "Multiple objects selected" ) ); + m_caption->SetLabel( wxString::Format( _( "%d objects selected" ), aSelection.Size() ) ); } else { diff --git a/include/properties/property.h b/include/properties/property.h index 43bfe5a315..7fce210bbc 100644 --- a/include/properties/property.h +++ b/include/properties/property.h @@ -184,6 +184,7 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, m_display( aDisplay ), m_coordType( aCoordType ), m_isInternal( false ), + m_groupId( -1 ), m_availFunc( [](INSPECTABLE*)->bool { return true; } ) { } @@ -267,6 +268,9 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, void SetIsInternal( bool aIsInternal ) { m_isInternal = aIsInternal; } bool IsInternal() const { return m_isInternal; } + void SetGroup( int aGroup ) { m_groupId = aGroup; } + int Group() const { return m_groupId; } + protected: template void set( void* aObject, T aValue ) @@ -298,6 +302,8 @@ private: /// Internal properties are hidden from the GUI bool m_isInternal; + int m_groupId; + std::function m_availFunc; ///< Eval to determine if prop is available friend class INSPECTABLE; diff --git a/include/properties/property_mgr.h b/include/properties/property_mgr.h index 2a45a59ae2..df8ae410cc 100644 --- a/include/properties/property_mgr.h +++ b/include/properties/property_mgr.h @@ -122,12 +122,24 @@ public: return const_cast( TypeCast( (const void*) aSource, aBase, aTarget ) ); } + /** + * Defines a grouping of properties in the editor + */ + struct PROPERTY_GROUP + { + size_t id; ///< Controls the display order of the group (lowest first) + wxString name; ///< Header to display in the properties manager + }; + + static const PROPERTY_GROUP DEFAULT_GROUP; + /** * Register a property. * * @param aProperty is the property to register. + * @param aGroup is the group to place the property in */ - void AddProperty( PROPERTY_BASE* aProperty ); + void AddProperty( PROPERTY_BASE* aProperty, const PROPERTY_GROUP& aGroup = DEFAULT_GROUP ); /** * Replace an existing property for a specific type. @@ -193,6 +205,13 @@ public: std::vector GetMatchingClasses( PROPERTY_BASE* aProperty ); + /** + * Defines a named group of properties belonging to a certain class + * @param aOwner is the class type that delivers the properties in the group + * @param aName will be shown as the group name in the properties manager + */ + const PROPERTY_GROUP& AddPropertyGroup( TYPE_ID aOwner, const wxString& aName ); + private: PROPERTY_MANAGER() : m_dirty( false ), @@ -207,6 +226,7 @@ private: CLASS_DESC( TYPE_ID aId ) : m_id( aId ) { + m_groups.emplace_back( DEFAULT_GROUP ); } ///< Unique type identifier (obtained using TYPE_HASH) @@ -224,6 +244,8 @@ private: ///< All properties (both unique to the type and inherited) std::vector m_allProperties; + std::vector m_groups; + ///< Replaced properties (TYPE_ID / name) PROPERTY_SET m_replaced; diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index f51b13777e..0c06a2c243 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -279,10 +279,10 @@ static struct BOARD_ITEM_DESC propMgr.AddProperty( new PROPERTY( _HKI( "Position X" ), &BOARD_ITEM::SetX, &BOARD_ITEM::GetX, PROPERTY_DISPLAY::PT_COORD, - ORIGIN_TRANSFORMS::ABS_X_COORD) ); + ORIGIN_TRANSFORMS::ABS_X_COORD ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Position Y" ), &BOARD_ITEM::SetY, &BOARD_ITEM::GetY, PROPERTY_DISPLAY::PT_COORD, - ORIGIN_TRANSFORMS::ABS_Y_COORD) ); + ORIGIN_TRANSFORMS::ABS_Y_COORD ) ); propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Layer" ), &BOARD_ITEM::SetLayer, &BOARD_ITEM::GetLayer ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Locked" ), diff --git a/pcbnew/dialogs/pcb_properties_panel.cpp b/pcbnew/dialogs/pcb_properties_panel.cpp index 10bade877f..dde24eace0 100644 --- a/pcbnew/dialogs/pcb_properties_panel.cpp +++ b/pcbnew/dialogs/pcb_properties_panel.cpp @@ -103,7 +103,8 @@ void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool(); const SELECTION& selection = selectionTool->GetSelection(); BOARD_ITEM* firstItem = static_cast( selection.Front() ); - PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ), aEvent.GetPropertyName() ); + PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ), + aEvent.GetPropertyName() ); wxVariant newValue = aEvent.GetPropertyValue(); BOARD_COMMIT changes( m_frame ); @@ -134,7 +135,8 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard ) m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) )->SetChoices( layersAll ); // Copper only properties - m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) )->SetChoices( layersCu ); + m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), + _HKI( "Layer" ) )->SetChoices( layersCu ); m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Top" ) )->SetChoices( layersCu ); m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Bottom" ) )->SetChoices( layersCu ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 774481b338..97194a5228 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -2852,16 +2852,7 @@ static struct FOOTPRINT_DESC propMgr.AddProperty( new PROPERTY( _HKI( "Orientation" ), &FOOTPRINT::SetOrientationDegrees, &FOOTPRINT::GetOrientationDegrees, PROPERTY_DISPLAY::PT_DEGREE ) ); - propMgr.AddProperty( new PROPERTY( _HKI( "Clearance Override" ), - &FOOTPRINT::SetLocalClearance, &FOOTPRINT::GetLocalClearance, - PROPERTY_DISPLAY::PT_SIZE ) ); - propMgr.AddProperty( new PROPERTY( _HKI( "Solderpaste Margin Override" ), - &FOOTPRINT::SetLocalSolderPasteMargin, &FOOTPRINT::GetLocalSolderPasteMargin, - PROPERTY_DISPLAY::PT_SIZE ) ); - propMgr.AddProperty( new PROPERTY( - _HKI( "Solderpaste Margin Ratio Override" ), - &FOOTPRINT::SetLocalSolderPasteMarginRatio, - &FOOTPRINT::GetLocalSolderPasteMarginRatio ) ); + propMgr.AddProperty( new PROPERTY( _HKI( "Library link" ), NO_SETTER( FOOTPRINT, wxString ), &FOOTPRINT::GetFPIDAsString ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Description" ), @@ -2878,6 +2869,17 @@ static struct FOOTPRINT_DESC propMgr.AddProperty( new PROPERTY( _HKI( "Exempt from courtyard requirement" ), &FOOTPRINT::SetAllowMissingCourtyard, &FOOTPRINT::AllowMissingCourtyard ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Clearance Override" ), + &FOOTPRINT::SetLocalClearance, &FOOTPRINT::GetLocalClearance, + PROPERTY_DISPLAY::PT_SIZE ) ); + propMgr.AddProperty( new PROPERTY( _HKI( "Solderpaste Margin Override" ), + &FOOTPRINT::SetLocalSolderPasteMargin, &FOOTPRINT::GetLocalSolderPasteMargin, + PROPERTY_DISPLAY::PT_SIZE ) ); + propMgr.AddProperty( new PROPERTY( + _HKI( "Solderpaste Margin Ratio Override" ), + &FOOTPRINT::SetLocalSolderPasteMarginRatio, + &FOOTPRINT::GetLocalSolderPasteMarginRatio ) ); // TODO zone connection } } _FOOTPRINT_DESC;