PCB Fields: use validators in dialogs, restrict editing of footprint
This commit is contained in:
parent
7d84fa2a9d
commit
b81fcaeaf7
|
@ -77,7 +77,7 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
|
|||
m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
||||
m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
||||
|
||||
m_fields = new FP_TEXT_GRID_TABLE( m_frame );
|
||||
m_fields = new FP_TEXT_GRID_TABLE( m_frame, this );
|
||||
|
||||
m_delayedErrorMessage = wxEmptyString;
|
||||
m_delayedFocusGrid = nullptr;
|
||||
|
|
|
@ -142,7 +142,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(
|
|||
m_3dPanel = new PANEL_FP_PROPERTIES_3D_MODEL( m_frame, m_footprint, this, m_NoteBook );
|
||||
m_NoteBook->AddPage( m_3dPanel, _("3D Models"), false );
|
||||
|
||||
m_fields = new FP_TEXT_GRID_TABLE( m_frame );
|
||||
m_fields = new FP_TEXT_GRID_TABLE( m_frame, this );
|
||||
m_privateLayers = new PRIVATE_LAYERS_GRID_TABLE( m_frame );
|
||||
|
||||
m_delayedErrorMessage = wxEmptyString;
|
||||
|
|
|
@ -98,6 +98,10 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PC
|
|||
}
|
||||
else
|
||||
{
|
||||
// Don't let users modify the library link
|
||||
if( field->IsFootprint() )
|
||||
m_SingleLineText->SetEditable( false );
|
||||
|
||||
title = _( "Footprint Field Properties" );
|
||||
m_TextLabel->SetLabel( _( "Text:" ) );
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <kiway_player.h>
|
||||
#include <project.h>
|
||||
#include <fp_text_grid_table.h>
|
||||
#include <widgets/grid_icon_text_helpers.h>
|
||||
#include <widgets/grid_combobox.h>
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include <pcb_base_frame.h>
|
||||
#include <footprint.h>
|
||||
#include "grid_layer_box_helpers.h"
|
||||
#include "widgets/grid_text_button_helpers.h"
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -40,8 +42,14 @@ enum
|
|||
wxArrayString g_menuOrientations;
|
||||
|
||||
|
||||
FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) :
|
||||
m_frame( aFrame )
|
||||
FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame, DIALOG_SHIM* aDialog ) :
|
||||
m_frame( aFrame ),
|
||||
m_dialog( aDialog ),
|
||||
m_fieldNameValidator( FIELD_NAME ),
|
||||
m_referenceValidator( REFERENCE_FIELD ),
|
||||
m_valueValidator( VALUE_FIELD ),
|
||||
m_urlValidator( FIELD_VALUE ),
|
||||
m_nonUrlValidator( FIELD_VALUE )
|
||||
{
|
||||
// Build the column attributes.
|
||||
|
||||
|
@ -68,6 +76,27 @@ FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) :
|
|||
m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
|
||||
m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
|
||||
|
||||
m_referenceAttr = new wxGridCellAttr;
|
||||
GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
|
||||
referenceEditor->SetValidator( m_referenceValidator );
|
||||
m_referenceAttr->SetEditor( referenceEditor );
|
||||
|
||||
m_valueAttr = new wxGridCellAttr;
|
||||
GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
|
||||
valueEditor->SetValidator( m_valueValidator );
|
||||
m_valueAttr->SetEditor( valueEditor );
|
||||
|
||||
m_footprintAttr = new wxGridCellAttr;
|
||||
m_footprintAttr->SetReadOnly( true );
|
||||
GRID_CELL_FPID_EDITOR* fpIdEditor = new GRID_CELL_FPID_EDITOR( m_dialog, "" );
|
||||
fpIdEditor->SetValidator( m_nonUrlValidator );
|
||||
m_footprintAttr->SetEditor( fpIdEditor );
|
||||
|
||||
m_urlAttr = new wxGridCellAttr;
|
||||
GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( m_dialog );
|
||||
urlEditor->SetValidator( m_urlValidator );
|
||||
m_urlAttr->SetEditor( urlEditor );
|
||||
|
||||
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
|
||||
|
||||
m_frame->Bind( EDA_EVT_UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
|
||||
|
@ -80,6 +109,10 @@ FP_TEXT_GRID_TABLE::~FP_TEXT_GRID_TABLE()
|
|||
m_boolColAttr->DecRef();
|
||||
m_orientationColAttr->DecRef();
|
||||
m_layerColAttr->DecRef();
|
||||
m_referenceAttr->DecRef();
|
||||
m_valueAttr->DecRef();
|
||||
m_footprintAttr->DecRef();
|
||||
m_urlAttr->DecRef();
|
||||
|
||||
m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
|
||||
}
|
||||
|
@ -166,6 +199,27 @@ wxGridCellAttr* FP_TEXT_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr:
|
|||
return nullptr;
|
||||
|
||||
case FPT_VALUE:
|
||||
if( aRow == REFERENCE_FIELD )
|
||||
{
|
||||
m_referenceAttr->IncRef();
|
||||
return m_referenceAttr;
|
||||
}
|
||||
else if( aRow == VALUE_FIELD )
|
||||
{
|
||||
m_valueAttr->IncRef();
|
||||
return m_valueAttr;
|
||||
}
|
||||
else if( aRow == FOOTPRINT_FIELD )
|
||||
{
|
||||
m_footprintAttr->IncRef();
|
||||
return m_footprintAttr;
|
||||
}
|
||||
else if( aRow == DATASHEET_FIELD )
|
||||
{
|
||||
m_urlAttr->IncRef();
|
||||
return m_urlAttr;
|
||||
}
|
||||
|
||||
case FPT_WIDTH:
|
||||
case FPT_HEIGHT:
|
||||
case FPT_THICKNESS:
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <wx/grid.h>
|
||||
#include <grid_tricks.h>
|
||||
#include <pcb_field.h>
|
||||
#include <validators.h>
|
||||
#include <dialog_shim.h>
|
||||
|
||||
|
||||
class PCB_BASE_FRAME;
|
||||
|
@ -54,7 +56,7 @@ enum FP_TEXT_COL_ORDER
|
|||
class FP_TEXT_GRID_TABLE : public wxGridTableBase, public std::vector<PCB_FIELD*>
|
||||
{
|
||||
public:
|
||||
FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame );
|
||||
FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame, DIALOG_SHIM* aDialog );
|
||||
~FP_TEXT_GRID_TABLE();
|
||||
|
||||
int GetNumberRows() override { return (int) size(); }
|
||||
|
@ -84,11 +86,22 @@ protected:
|
|||
|
||||
private:
|
||||
PCB_BASE_FRAME* m_frame;
|
||||
DIALOG_SHIM* m_dialog;
|
||||
|
||||
FIELD_VALIDATOR m_fieldNameValidator;
|
||||
FIELD_VALIDATOR m_referenceValidator;
|
||||
FIELD_VALIDATOR m_valueValidator;
|
||||
FIELD_VALIDATOR m_urlValidator;
|
||||
FIELD_VALIDATOR m_nonUrlValidator;
|
||||
|
||||
wxGridCellAttr* m_readOnlyAttr;
|
||||
wxGridCellAttr* m_boolColAttr;
|
||||
wxGridCellAttr* m_orientationColAttr;
|
||||
wxGridCellAttr* m_layerColAttr;
|
||||
wxGridCellAttr* m_referenceAttr;
|
||||
wxGridCellAttr* m_valueAttr;
|
||||
wxGridCellAttr* m_footprintAttr;
|
||||
wxGridCellAttr* m_urlAttr;
|
||||
|
||||
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
|
||||
std::map< std::pair<int, int>, wxString > m_evalOriginal;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <pcb_field.h>
|
||||
#include <footprint.h>
|
||||
#include <board_design_settings.h>
|
||||
#include <i18n_utility.h>
|
||||
|
||||
PCB_FIELD::PCB_FIELD( FOOTPRINT* aParent, int aFieldId, const wxString& aName ) :
|
||||
PCB_TEXT( aParent, PCB_FIELD_T ), m_id( aFieldId ), m_name( aName )
|
||||
|
@ -169,5 +170,17 @@ static struct PCB_FIELD_DESC
|
|||
propMgr.InheritsAfter( TYPE_HASH( PCB_FIELD ), TYPE_HASH( BOARD_ITEM ) );
|
||||
propMgr.InheritsAfter( TYPE_HASH( PCB_FIELD ), TYPE_HASH( PCB_TEXT ) );
|
||||
propMgr.InheritsAfter( TYPE_HASH( PCB_FIELD ), TYPE_HASH( EDA_TEXT ) );
|
||||
|
||||
auto isNotFootprintFootprint =
|
||||
[]( INSPECTABLE* aItem ) -> bool
|
||||
{
|
||||
if( PCB_FIELD* field = dynamic_cast<PCB_FIELD*>( aItem ) )
|
||||
return !field->IsFootprint();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
propMgr.OverrideAvailability( TYPE_HASH( PCB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Text" ),
|
||||
isNotFootprintFootprint );
|
||||
}
|
||||
} _PCB_FIELD_DESC;
|
||||
|
|
Loading…
Reference in New Issue