Browse Source

Fix lib_fields column attributes

Need to properly display footprint selector and datasheet globe
pull/19/head
Seth Hillbrand 3 months ago
parent
commit
05d04e665a
  1. 30
      eeschema/dialogs/dialog_lib_fields.cpp
  2. 1
      eeschema/dialogs/dialog_lib_fields.h
  3. 28
      eeschema/lib_fields_data_model.cpp
  4. 12
      eeschema/lib_fields_data_model.h

30
eeschema/dialogs/dialog_lib_fields.cpp

@ -28,11 +28,13 @@
#include <kiface_base.h>
#include <kiplatform/ui.h>
#include <kiway_player.h>
#include <string_utils.h>
#include <symbol_editor/lib_symbol_library_manager.h>
#include <project_sch.h>
#include <symbol_edit_frame.h>
#include <symbol_editor/symbol_editor_settings.h>
#include <widgets/grid_checkbox.h>
#include <widgets/grid_icon_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>
#include <widgets/std_bitmap_button.h>
#include <tools/sch_actions.h>
@ -1063,7 +1065,30 @@ void DIALOG_LIB_FIELDS::SetupColumnProperties( int aCol )
// Set some column types to specific editors
if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( FIELD_T::FOOTPRINT ) )
{
attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) );
// Create symbol netlist for footprint picker
wxString symbolNetlist;
if( !m_symbolsList.empty() )
{
// Use the first symbol's netlist (all symbols in lib should have similar pin structure)
LIB_SYMBOL* symbol = m_symbolsList[0];
wxArrayString pins;
for( SCH_PIN* pin : symbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ) )
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
if( !pins.IsEmpty() )
symbolNetlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
symbolNetlist << wxS( "\r" );
wxArrayString fpFilters = symbol->GetFPFilters();
if( !fpFilters.IsEmpty() )
symbolNetlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
symbolNetlist << wxS( "\r" );
}
attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, symbolNetlist ) );
m_dataModel->SetColAttr( attr, aCol );
}
else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( FIELD_T::DATASHEET ) )
@ -1076,7 +1101,7 @@ void DIALOG_LIB_FIELDS::SetupColumnProperties( int aCol )
{
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
attr->SetRenderer( new GRID_CELL_CHECKBOX_RENDERER() );
m_dataModel->SetColAttr( attr, aCol );
m_dataModel->SetColAttr( attr, aCol );
}
else if( IsGeneratedField( m_dataModel->GetColFieldName( aCol ) ) )
{
@ -1162,3 +1187,4 @@ void DIALOG_LIB_FIELDS::SetupAllColumnProperties()
m_dataModel->SetSorting( sortCol, sortAscending );
m_grid->SetSortingColumn( sortCol, sortAscending );
}

1
eeschema/dialogs/dialog_lib_fields.h

@ -22,6 +22,7 @@
#include <dialog_lib_fields_base.h>
#include <sch_reference_list.h>
#include <widgets/grid_text_button_helpers.h>
class SYMBOL_EDIT_FRAME;
class LIB_FIELDS_EDITOR_GRID_DATA_MODEL;

28
eeschema/lib_fields_data_model.cpp

@ -259,8 +259,34 @@ wxGridCellAttr* LIB_FIELDS_EDITOR_GRID_DATA_MODEL::GetAttr( int aRow, int aCol,
{
wxGridCellAttr* attr = wxGridTableBase::GetAttr( aRow, aCol, aKind );
if( !attr )
// Check for column-specific attributes first
if( m_colAttrs.find( aCol ) != m_colAttrs.end() && m_colAttrs[aCol] )
{
if( attr )
{
// Merge with existing attributes
wxGridCellAttr* newAttr = m_colAttrs[aCol]->Clone();
// Copy any existing attributes that aren't overridden
if( attr->HasBackgroundColour() && !newAttr->HasBackgroundColour() )
newAttr->SetBackgroundColour( attr->GetBackgroundColour() );
if( attr->HasTextColour() && !newAttr->HasTextColour() )
newAttr->SetTextColour( attr->GetTextColour() );
if( attr->HasFont() && !newAttr->HasFont() )
newAttr->SetFont( attr->GetFont() );
attr->DecRef();
attr = newAttr;
}
else
{
attr = m_colAttrs[aCol]->Clone();
}
}
else if( !attr )
{
attr = new wxGridCellAttr;
}
bool rowModified = false;
bool cellModified = false;

12
eeschema/lib_fields_data_model.h

@ -118,6 +118,9 @@ public:
pair.second->DecRef();
m_stripedRenderers.clear();
for( const auto& [col, attr] : m_colAttrs )
wxSafeDecRef( attr );
}
static const wxString QUANTITY_VARIABLE;
@ -287,6 +290,12 @@ public:
return m_rows[aRow].m_Flag == GROUP_SINGLETON || m_rows[aRow].m_Flag == CHILD_ITEM;
}
void SetColAttr( wxGridCellAttr* aAttr, int aCol ) override
{
wxSafeDecRef( m_colAttrs[aCol] );
m_colAttrs[aCol] = aAttr;
}
private:
static bool cmp( const LIB_DATA_MODEL_ROW& lhGroup, const LIB_DATA_MODEL_ROW& rhGroup,
LIB_FIELDS_EDITOR_GRID_DATA_MODEL* dataModel, int sortCol, bool ascending );
@ -329,4 +338,7 @@ protected:
// stripe bitmap support
mutable STRIPED_STRING_RENDERER* m_stripedStringRenderer;
mutable std::map<wxString, wxGridCellRenderer*> m_stripedRenderers;
// Column attributes storage
std::map<int, wxGridCellAttr*> m_colAttrs;
};
Loading…
Cancel
Save