2018-02-28 16:54:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2018-02-28 16:54:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2024-05-16 09:15:40 -07:00
|
|
|
#include <embedded_files.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <kiway_player.h>
|
|
|
|
#include <dialog_shim.h>
|
|
|
|
#include <fields_grid_table.h>
|
2018-08-08 21:57:53 +01:00
|
|
|
#include <sch_base_frame.h>
|
2018-03-07 12:48:08 +00:00
|
|
|
#include <sch_field.h>
|
2022-01-24 13:40:39 +00:00
|
|
|
#include <sch_label.h>
|
2018-03-07 12:48:08 +00:00
|
|
|
#include <sch_validators.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <validators.h>
|
2021-10-12 21:05:37 +01:00
|
|
|
#include <sch_edit_frame.h>
|
2021-06-15 09:24:55 -04:00
|
|
|
#include <symbol_library.h>
|
2021-10-12 21:05:37 +01:00
|
|
|
#include <schematic.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <template_fieldnames.h>
|
2018-07-20 16:03:43 +01:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2020-03-06 20:02:58 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-08-30 18:57:10 +01:00
|
|
|
#include <project/project_file.h>
|
2021-10-12 21:05:37 +01:00
|
|
|
#include <project/net_settings.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include "eda_doc.h"
|
2022-05-04 01:08:11 +01:00
|
|
|
#include "widgets/grid_color_swatch_helpers.h"
|
|
|
|
#include "font/fontconfig.h"
|
|
|
|
#include "font/kicad_font_name.h"
|
2023-08-02 20:11:59 +01:00
|
|
|
#include "widgets/grid_text_helpers.h"
|
2021-05-01 20:04:11 +02:00
|
|
|
#include <wx/settings.h>
|
2021-07-29 10:56:22 +01:00
|
|
|
#include <string_utils.h>
|
2021-10-12 21:05:37 +01:00
|
|
|
#include <widgets/grid_combobox.h>
|
2023-02-21 20:26:30 -05:00
|
|
|
#include <pgm_base.h>
|
2023-09-27 23:04:53 -04:00
|
|
|
#include <project_sch.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
enum
|
|
|
|
{
|
2022-03-26 11:05:10 +00:00
|
|
|
MYID_SELECT_FOOTPRINT = GRIDTRICKS_FIRST_CLIENT_ID,
|
2018-02-28 16:54:35 +00:00
|
|
|
MYID_SHOW_DATASHEET
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
#define DEFAULT_FONT_NAME _( "Default Font" )
|
|
|
|
|
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
static wxString netList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH& aSheetPath )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Symbol netlist format:
|
2024-03-09 11:58:23 +00:00
|
|
|
* pinNumber pinName <tab> pinNumber pinName...
|
|
|
|
* fpFilter fpFilter...
|
2022-07-24 23:40:47 +01:00
|
|
|
*/
|
|
|
|
wxString netlist;
|
|
|
|
|
2024-08-14 13:09:24 +02:00
|
|
|
// We need the list of pins of the lib symbol, not just the pins of the current
|
|
|
|
// sch symbol, that can be just an unit of a multi-unit symbol, to be able to
|
|
|
|
// select/filter right footprints
|
2024-03-09 11:58:23 +00:00
|
|
|
wxArrayString pins;
|
2022-07-24 23:40:47 +01:00
|
|
|
|
2024-08-14 13:09:24 +02:00
|
|
|
const std::unique_ptr< LIB_SYMBOL >& lib_symbol = aSymbol->GetLibSymbolRef();
|
|
|
|
|
|
|
|
if( lib_symbol )
|
|
|
|
{
|
|
|
|
for( SCH_PIN* pin : lib_symbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ) )
|
|
|
|
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
|
|
|
|
}
|
2024-03-09 11:58:23 +00:00
|
|
|
|
|
|
|
if( !pins.IsEmpty() )
|
|
|
|
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
|
|
|
|
|
|
|
|
netlist << wxS( "\r" );
|
2023-12-23 17:30:29 -05:00
|
|
|
|
2025-07-02 22:40:05 -06:00
|
|
|
if( lib_symbol )
|
|
|
|
{
|
|
|
|
wxArrayString fpFilters = lib_symbol->GetFPFilters();
|
2023-09-29 17:02:57 +01:00
|
|
|
|
2025-07-02 22:40:05 -06:00
|
|
|
if( !fpFilters.IsEmpty() )
|
|
|
|
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
|
|
|
|
}
|
2023-09-29 17:02:57 +01:00
|
|
|
|
|
|
|
netlist << wxS( "\r" );
|
2022-07-24 23:40:47 +01:00
|
|
|
|
|
|
|
return netlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-25 13:10:54 +00:00
|
|
|
static wxString netList( LIB_SYMBOL* aSymbol )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Symbol netlist format:
|
2024-03-09 11:58:23 +00:00
|
|
|
* pinNumber pinName <tab> pinNumber pinName...
|
|
|
|
* fpFilter fpFilter...
|
2024-02-25 13:10:54 +00:00
|
|
|
*/
|
2024-04-20 10:44:34 +01:00
|
|
|
wxString netlist;
|
2024-03-09 11:58:23 +00:00
|
|
|
wxArrayString pins;
|
|
|
|
|
2024-04-20 10:44:34 +01:00
|
|
|
for( SCH_PIN* pin : aSymbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ) )
|
2024-03-09 11:58:23 +00:00
|
|
|
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
|
|
|
|
|
|
|
|
if( !pins.IsEmpty() )
|
|
|
|
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
|
|
|
|
|
|
|
|
netlist << wxS( "\r" );
|
2024-02-25 13:10:54 +00:00
|
|
|
|
|
|
|
wxArrayString fpFilters = aSymbol->GetFPFilters();
|
|
|
|
|
|
|
|
if( !fpFilters.IsEmpty() )
|
|
|
|
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
|
|
|
|
|
|
|
|
netlist << wxS( "\r" );
|
|
|
|
|
|
|
|
return netlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
|
2025-04-23 15:11:13 +01:00
|
|
|
LIB_SYMBOL* aSymbol, std::vector<EMBEDDED_FILES*> aFilesStack ) :
|
2020-03-06 20:02:58 +00:00
|
|
|
m_frame( aFrame ),
|
2021-10-25 12:34:30 +01:00
|
|
|
m_dialog( aDialog ),
|
2021-06-10 10:10:55 -04:00
|
|
|
m_parentType( SCH_SYMBOL_T ),
|
2021-06-10 14:51:46 -04:00
|
|
|
m_part( aSymbol ),
|
2025-04-23 15:11:13 +01:00
|
|
|
m_filesStack( aFilesStack ),
|
2024-02-25 13:10:54 +00:00
|
|
|
m_symbolNetlist( netList( aSymbol ) ),
|
2025-02-08 13:45:57 +00:00
|
|
|
m_fieldNameValidator( FIELD_T::USER ),
|
|
|
|
m_referenceValidator( FIELD_T::REFERENCE ),
|
|
|
|
m_valueValidator( FIELD_T::VALUE ),
|
|
|
|
m_urlValidator( FIELD_T::USER ),
|
|
|
|
m_nonUrlValidator( FIELD_T::USER ),
|
|
|
|
m_filepathValidator( FIELD_T::SHEET_FILENAME )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-10-25 12:34:30 +01:00
|
|
|
initGrid( aGrid );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
|
2025-04-23 15:11:13 +01:00
|
|
|
SCH_SYMBOL* aSymbol ) :
|
2022-07-24 23:40:47 +01:00
|
|
|
m_frame( aFrame ),
|
|
|
|
m_dialog( aDialog ),
|
|
|
|
m_parentType( SCH_SYMBOL_T ),
|
2024-06-12 13:27:17 -04:00
|
|
|
m_part( aSymbol->GetLibSymbolRef().get() ),
|
2022-07-24 23:40:47 +01:00
|
|
|
m_symbolNetlist( netList( aSymbol, aFrame->GetCurrentSheet() ) ),
|
2025-02-08 13:45:57 +00:00
|
|
|
m_fieldNameValidator( FIELD_T::USER ),
|
|
|
|
m_referenceValidator( FIELD_T::REFERENCE ),
|
|
|
|
m_valueValidator( FIELD_T::VALUE ),
|
|
|
|
m_urlValidator( FIELD_T::USER ),
|
|
|
|
m_nonUrlValidator( FIELD_T::USER ),
|
|
|
|
m_filepathValidator( FIELD_T::SHEET_FILENAME )
|
2022-07-24 23:40:47 +01:00
|
|
|
{
|
2025-04-23 15:11:13 +01:00
|
|
|
m_filesStack.push_back( aSymbol->Schematic() );
|
|
|
|
|
|
|
|
if( m_part )
|
|
|
|
m_filesStack.push_back( m_part );
|
|
|
|
|
2022-07-24 23:40:47 +01:00
|
|
|
initGrid( aGrid );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
|
2025-01-27 15:13:35 -08:00
|
|
|
SCH_SHEET* aSheet ) :
|
2020-03-06 20:02:58 +00:00
|
|
|
m_frame( aFrame ),
|
2021-10-25 12:34:30 +01:00
|
|
|
m_dialog( aDialog ),
|
2020-03-06 20:02:58 +00:00
|
|
|
m_parentType( SCH_SHEET_T ),
|
|
|
|
m_part( nullptr ),
|
2025-02-08 13:45:57 +00:00
|
|
|
m_fieldNameValidator( FIELD_T::USER ),
|
|
|
|
m_referenceValidator( FIELD_T::SHEET_NAME ),
|
|
|
|
m_valueValidator( FIELD_T::VALUE ),
|
|
|
|
m_urlValidator( FIELD_T::USER ),
|
|
|
|
m_nonUrlValidator( FIELD_T::USER ),
|
|
|
|
m_filepathValidator( FIELD_T::SHEET_FILENAME )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2025-04-23 15:11:13 +01:00
|
|
|
m_filesStack.push_back( aSheet->Schematic() );
|
|
|
|
|
2021-10-25 12:34:30 +01:00
|
|
|
initGrid( aGrid );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
|
|
|
|
SCH_LABEL_BASE* aLabel ) :
|
2021-10-12 21:05:37 +01:00
|
|
|
m_frame( aFrame ),
|
|
|
|
m_dialog( aDialog ),
|
|
|
|
m_parentType( SCH_LABEL_LOCATE_ANY_T ),
|
|
|
|
m_part( nullptr ),
|
2025-02-08 13:45:57 +00:00
|
|
|
m_fieldNameValidator( FIELD_T::USER ),
|
|
|
|
m_referenceValidator( FIELD_T::USER ),
|
|
|
|
m_valueValidator( FIELD_T::USER ),
|
|
|
|
m_urlValidator( FIELD_T::USER ),
|
|
|
|
m_nonUrlValidator( FIELD_T::USER ),
|
|
|
|
m_filepathValidator( FIELD_T::USER )
|
2021-10-12 21:05:37 +01:00
|
|
|
{
|
2025-04-23 15:11:13 +01:00
|
|
|
m_filesStack.push_back( aLabel->Schematic() );
|
|
|
|
|
2021-10-12 21:05:37 +01:00
|
|
|
initGrid( aGrid );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-21 23:38:55 +00:00
|
|
|
int FIELDS_GRID_TABLE::GetMandatoryRowCount() const
|
|
|
|
{
|
|
|
|
int mandatoryRows = 0;
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : *this )
|
|
|
|
{
|
|
|
|
if( field.IsMandatory() )
|
|
|
|
mandatoryRows++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mandatoryRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
void FIELDS_GRID_TABLE::initGrid( WX_GRID* aGrid )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-07-21 21:23:13 +01:00
|
|
|
// Build the various grid cell attributes.
|
2019-06-04 14:32:10 +01:00
|
|
|
// NOTE: validators and cellAttrs are member variables to get the destruction order
|
|
|
|
// right. wxGrid is VERY cranky about this.
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
m_readOnlyAttr = new wxGridCellAttr;
|
|
|
|
m_readOnlyAttr->SetReadOnly( true );
|
|
|
|
|
2018-07-21 21:23:13 +01:00
|
|
|
m_fieldNameAttr = new wxGridCellAttr;
|
|
|
|
GRID_CELL_TEXT_EDITOR* nameEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nameEditor->SetValidator( m_fieldNameValidator );
|
|
|
|
m_fieldNameAttr->SetEditor( nameEditor );
|
|
|
|
|
|
|
|
m_referenceAttr = new wxGridCellAttr;
|
|
|
|
GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
referenceEditor->SetValidator( m_referenceValidator );
|
|
|
|
m_referenceAttr->SetEditor( referenceEditor );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2018-09-13 16:39:14 +01:00
|
|
|
m_valueAttr = new wxGridCellAttr;
|
2023-08-02 20:11:59 +01:00
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
if( m_parentType == LIB_SYMBOL_T )
|
|
|
|
{
|
|
|
|
GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
valueEditor->SetValidator( m_valueValidator );
|
|
|
|
m_valueAttr->SetEditor( valueEditor );
|
|
|
|
}
|
|
|
|
else
|
2023-08-02 20:11:59 +01:00
|
|
|
{
|
2025-05-28 13:53:43 +01:00
|
|
|
GRID_CELL_STC_EDITOR* valueEditor = new GRID_CELL_STC_EDITOR( true, true,
|
2023-08-02 20:11:59 +01:00
|
|
|
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
|
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
SCH_FIELD* valueField = this->GetField( FIELD_T::VALUE );
|
|
|
|
valueField->OnScintillaCharAdded( aScintillaTricks, aEvent );
|
2023-08-02 20:11:59 +01:00
|
|
|
} );
|
2025-02-06 09:47:00 -05:00
|
|
|
|
2023-08-02 20:11:59 +01:00
|
|
|
m_valueAttr->SetEditor( valueEditor );
|
|
|
|
}
|
2018-09-13 16:39:14 +01:00
|
|
|
|
2018-07-20 16:03:43 +01:00
|
|
|
m_footprintAttr = new wxGridCellAttr;
|
2022-07-24 23:40:47 +01:00
|
|
|
GRID_CELL_FPID_EDITOR* fpIdEditor = new GRID_CELL_FPID_EDITOR( m_dialog, m_symbolNetlist );
|
2023-05-31 17:22:35 +01:00
|
|
|
fpIdEditor->SetValidator( m_nonUrlValidator );
|
2019-05-10 08:21:08 -04:00
|
|
|
m_footprintAttr->SetEditor( fpIdEditor );
|
2018-07-20 16:03:43 +01:00
|
|
|
|
|
|
|
m_urlAttr = new wxGridCellAttr;
|
2025-01-05 12:22:26 +00:00
|
|
|
SEARCH_STACK* prjSearchStack = PROJECT_SCH::SchSearchS( &m_frame->Prj() );
|
2025-04-23 15:11:13 +01:00
|
|
|
GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( m_dialog, prjSearchStack, m_filesStack );
|
2019-06-04 14:32:10 +01:00
|
|
|
urlEditor->SetValidator( m_urlValidator );
|
2019-05-10 08:21:08 -04:00
|
|
|
m_urlAttr->SetEditor( urlEditor );
|
|
|
|
|
|
|
|
m_nonUrlAttr = new wxGridCellAttr;
|
2019-06-04 14:32:10 +01:00
|
|
|
GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nonUrlEditor->SetValidator( m_nonUrlValidator );
|
2019-05-10 08:21:08 -04:00
|
|
|
m_nonUrlAttr->SetEditor( nonUrlEditor );
|
2018-07-20 16:03:43 +01:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
m_curdir = m_frame->Prj().GetProjectPath();
|
|
|
|
m_filepathAttr = new wxGridCellAttr;
|
2020-04-05 09:56:40 +02:00
|
|
|
|
|
|
|
// Create a wild card using wxFileDialog syntax.
|
2020-04-05 09:39:08 -04:00
|
|
|
wxString wildCard( _( "Schematic Files" ) );
|
2020-04-05 09:56:40 +02:00
|
|
|
std::vector<std::string> exts;
|
2023-12-27 21:10:01 -05:00
|
|
|
exts.push_back( FILEEXT::KiCadSchematicFileExtension );
|
2020-04-05 09:56:40 +02:00
|
|
|
wildCard += AddFileExtListToFilter( exts );
|
|
|
|
|
2021-10-25 12:34:30 +01:00
|
|
|
auto filepathEditor = new GRID_CELL_PATH_EDITOR( m_dialog, aGrid, &m_curdir, wildCard );
|
2020-03-06 20:02:58 +00:00
|
|
|
filepathEditor->SetValidator( m_filepathValidator );
|
|
|
|
m_filepathAttr->SetEditor( filepathEditor );
|
|
|
|
|
2018-07-21 21:23:13 +01:00
|
|
|
m_boolAttr = new wxGridCellAttr;
|
|
|
|
m_boolAttr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
m_boolAttr->SetEditor( new wxGridCellBoolEditor() );
|
2020-09-04 15:41:36 +02:00
|
|
|
m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString vAlignNames;
|
|
|
|
vAlignNames.Add( _( "Top" ) );
|
|
|
|
vAlignNames.Add( _( "Center" ) );
|
|
|
|
vAlignNames.Add( _( "Bottom" ) );
|
2018-07-21 21:23:13 +01:00
|
|
|
m_vAlignAttr = new wxGridCellAttr;
|
|
|
|
m_vAlignAttr->SetEditor( new wxGridCellChoiceEditor( vAlignNames ) );
|
2023-09-18 17:27:30 +03:00
|
|
|
m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString hAlignNames;
|
|
|
|
hAlignNames.Add( _( "Left" ) );
|
|
|
|
hAlignNames.Add(_( "Center" ) );
|
|
|
|
hAlignNames.Add(_( "Right" ) );
|
2018-07-21 21:23:13 +01:00
|
|
|
m_hAlignAttr = new wxGridCellAttr;
|
|
|
|
m_hAlignAttr->SetEditor( new wxGridCellChoiceEditor( hAlignNames ) );
|
2023-09-18 17:27:30 +03:00
|
|
|
m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString orientationNames;
|
|
|
|
orientationNames.Add( _( "Horizontal" ) );
|
|
|
|
orientationNames.Add(_( "Vertical" ) );
|
2018-07-21 21:23:13 +01:00
|
|
|
m_orientationAttr = new wxGridCellAttr;
|
|
|
|
m_orientationAttr->SetEditor( new wxGridCellChoiceEditor( orientationNames ) );
|
2023-09-18 17:27:30 +03:00
|
|
|
m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2021-12-22 21:43:41 +00:00
|
|
|
|
2021-10-12 21:05:37 +01:00
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
wxArrayString existingNetclasses;
|
|
|
|
|
2024-05-16 09:15:40 -07:00
|
|
|
wxArrayString fonts;
|
|
|
|
std::vector<std::string> fontNames;
|
|
|
|
|
2021-10-12 21:05:37 +01:00
|
|
|
if( editFrame )
|
|
|
|
{
|
|
|
|
// Load the combobox with existing existingNetclassNames
|
2022-08-14 12:03:18 +01:00
|
|
|
PROJECT_FILE& projectFile = editFrame->Prj().GetProjectFile();
|
|
|
|
const std::shared_ptr<NET_SETTINGS>& settings = projectFile.NetSettings();
|
2021-10-12 21:05:37 +01:00
|
|
|
|
2024-07-26 20:49:29 +00:00
|
|
|
existingNetclasses.push_back( settings->GetDefaultNetclass()->GetName() );
|
2021-10-12 21:05:37 +01:00
|
|
|
|
2024-07-26 20:49:29 +00:00
|
|
|
for( const auto& [name, netclass] : settings->GetNetclasses() )
|
2022-08-14 12:03:18 +01:00
|
|
|
existingNetclasses.push_back( name );
|
2024-05-16 09:15:40 -07:00
|
|
|
|
2025-01-05 12:22:26 +00:00
|
|
|
// We don't need to re-cache the embedded fonts when looking at symbols in the schematic
|
|
|
|
// editor because the fonts are all available in the schematic.
|
2024-05-16 09:15:40 -07:00
|
|
|
const std::vector<wxString>* fontFiles = nullptr;
|
|
|
|
|
|
|
|
if( m_frame->GetScreen() && m_frame->GetScreen()->Schematic() )
|
|
|
|
fontFiles = m_frame->GetScreen()->Schematic()->GetEmbeddedFiles()->GetFontFiles();
|
|
|
|
|
|
|
|
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ),
|
2025-01-05 12:22:26 +00:00
|
|
|
fontFiles, false );
|
2024-05-16 09:15:40 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const std::vector<wxString>* fontFiles = m_part->GetEmbeddedFiles()->UpdateFontFiles();
|
|
|
|
|
2025-01-05 12:22:26 +00:00
|
|
|
// If there are font files embedded, we want to re-cache our fonts for each symbol that
|
|
|
|
// we are looking at in the symbol editor.
|
2024-05-16 09:15:40 -07:00
|
|
|
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ),
|
2025-01-05 12:22:26 +00:00
|
|
|
fontFiles, !fontFiles->empty() );
|
2021-10-12 21:05:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_netclassAttr = new wxGridCellAttr;
|
|
|
|
m_netclassAttr->SetEditor( new GRID_CELL_COMBOBOX( existingNetclasses ) );
|
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
for( const std::string& name : fontNames )
|
|
|
|
fonts.Add( wxString( name ) );
|
|
|
|
|
|
|
|
fonts.Sort();
|
|
|
|
fonts.Insert( KICAD_FONT_NAME, 0 );
|
|
|
|
fonts.Insert( DEFAULT_FONT_NAME, 0 );
|
|
|
|
|
|
|
|
m_fontAttr = new wxGridCellAttr;
|
|
|
|
m_fontAttr->SetEditor( new GRID_CELL_COMBOBOX( fonts ) );
|
|
|
|
|
|
|
|
m_colorAttr = new wxGridCellAttr;
|
|
|
|
m_colorAttr->SetRenderer( new GRID_CELL_COLOR_RENDERER( m_dialog ) );
|
|
|
|
m_colorAttr->SetEditor( new GRID_CELL_COLOR_SELECTOR( m_dialog, aGrid ) );
|
|
|
|
|
2022-10-11 18:01:47 +01:00
|
|
|
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
m_frame->Bind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE::onUnitsChanged, this );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
FIELDS_GRID_TABLE::~FIELDS_GRID_TABLE()
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
m_readOnlyAttr->DecRef();
|
2018-07-21 21:23:13 +01:00
|
|
|
m_fieldNameAttr->DecRef();
|
|
|
|
m_boolAttr->DecRef();
|
|
|
|
m_referenceAttr->DecRef();
|
2018-09-13 16:39:14 +01:00
|
|
|
m_valueAttr->DecRef();
|
2018-07-20 16:03:43 +01:00
|
|
|
m_footprintAttr->DecRef();
|
|
|
|
m_urlAttr->DecRef();
|
2019-06-26 00:26:25 +01:00
|
|
|
m_nonUrlAttr->DecRef();
|
2020-03-06 20:02:58 +00:00
|
|
|
m_filepathAttr->DecRef();
|
2018-07-21 21:23:13 +01:00
|
|
|
m_vAlignAttr->DecRef();
|
|
|
|
m_hAlignAttr->DecRef();
|
|
|
|
m_orientationAttr->DecRef();
|
2021-10-12 21:05:37 +01:00
|
|
|
m_netclassAttr->DecRef();
|
2022-05-04 01:08:11 +01:00
|
|
|
m_fontAttr->DecRef();
|
|
|
|
m_colorAttr->DecRef();
|
2021-12-22 21:43:41 +00:00
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE::onUnitsChanged, this );
|
2021-12-22 21:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
void FIELDS_GRID_TABLE::onUnitsChanged( wxCommandEvent& aEvent )
|
2021-12-22 21:43:41 +00:00
|
|
|
{
|
|
|
|
if( GetView() )
|
|
|
|
GetView()->ForceRefresh();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-05 21:23:25 +00:00
|
|
|
int FIELDS_GRID_TABLE::getColumnCount() const
|
|
|
|
{
|
|
|
|
if( m_frame->GetFrameType() == FRAME_SCH
|
|
|
|
|| m_frame->GetFrameType() == FRAME_SCH_VIEWER )
|
|
|
|
{
|
|
|
|
return FDC_SCH_EDIT_COUNT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FDC_SYMBOL_EDITOR_COUNT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-05 12:41:58 +00:00
|
|
|
int FIELDS_GRID_TABLE::getVisibleRowCount() const
|
|
|
|
{
|
|
|
|
if( m_frame->GetFrameType() == FRAME_SCH
|
|
|
|
|| m_frame->GetFrameType() == FRAME_SCH_VIEWER )
|
|
|
|
{
|
|
|
|
int visibleRows = 0;
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : *this )
|
|
|
|
{
|
|
|
|
if( !field.IsPrivate() )
|
|
|
|
visibleRows++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return visibleRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) this->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_FIELD& FIELDS_GRID_TABLE::getField( int aRow )
|
|
|
|
{
|
|
|
|
if( m_frame->GetFrameType() == FRAME_SCH
|
|
|
|
|| m_frame->GetFrameType() == FRAME_SCH_VIEWER )
|
|
|
|
{
|
|
|
|
int visibleRow = 0;
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : *this )
|
|
|
|
{
|
|
|
|
if( field.IsPrivate() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( visibleRow == aRow )
|
|
|
|
return field;
|
|
|
|
|
|
|
|
++visibleRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL_MSG( wxT( "Row index off end of visible row count" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->at( aRow );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
wxString FIELDS_GRID_TABLE::GetColLabelValue( int aCol )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2023-05-31 17:26:38 +01:00
|
|
|
case FDC_NAME: return _( "Name" );
|
|
|
|
case FDC_VALUE: return _( "Value" );
|
|
|
|
case FDC_SHOWN: return _( "Show" );
|
|
|
|
case FDC_SHOW_NAME: return _( "Show Name" );
|
|
|
|
case FDC_H_ALIGN: return _( "H Align" );
|
|
|
|
case FDC_V_ALIGN: return _( "V Align" );
|
|
|
|
case FDC_ITALIC: return _( "Italic" );
|
|
|
|
case FDC_BOLD: return _( "Bold" );
|
|
|
|
case FDC_TEXT_SIZE: return _( "Text Size" );
|
|
|
|
case FDC_ORIENTATION: return _( "Orientation" );
|
|
|
|
case FDC_POSX: return _( "X Position" );
|
|
|
|
case FDC_POSY: return _( "Y Position" );
|
|
|
|
case FDC_FONT: return _( "Font" );
|
|
|
|
case FDC_COLOR: return _( "Color" );
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE: return _( "Allow Autoplacement" );
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE: return _( "Private" );
|
2023-05-31 17:26:38 +01:00
|
|
|
default: wxFAIL; return wxEmptyString;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
bool FIELDS_GRID_TABLE::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
|
|
|
case FDC_VALUE:
|
|
|
|
case FDC_H_ALIGN:
|
|
|
|
case FDC_V_ALIGN:
|
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
case FDC_ORIENTATION:
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
2022-05-04 01:08:11 +01:00
|
|
|
case FDC_FONT:
|
|
|
|
case FDC_COLOR:
|
2018-02-28 16:54:35 +00:00
|
|
|
return aTypeName == wxGRID_VALUE_STRING;
|
|
|
|
|
|
|
|
case FDC_SHOWN:
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOW_NAME:
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_ITALIC:
|
|
|
|
case FDC_BOLD:
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE:
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE:
|
2018-02-28 16:54:35 +00:00
|
|
|
return aTypeName == wxGRID_VALUE_BOOL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
bool FIELDS_GRID_TABLE::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
return CanGetValueAs( aRow, aCol, aTypeName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-16 15:50:57 +01:00
|
|
|
wxGridCellAttr* FIELDS_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2025-01-21 23:38:55 +00:00
|
|
|
wxCHECK( aRow < GetNumberRows(), nullptr );
|
|
|
|
|
|
|
|
const SCH_FIELD& field = getField( aRow );
|
|
|
|
wxGridCellAttr* tmp;
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
2025-01-21 23:38:55 +00:00
|
|
|
if( field.IsMandatory() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-11-06 14:15:42 -05:00
|
|
|
tmp = m_fieldNameAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( tmp, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
2018-07-21 21:23:13 +01:00
|
|
|
{
|
|
|
|
m_fieldNameAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_fieldNameAttr, aRow, aCol, aKind );
|
2018-07-21 21:23:13 +01:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_VALUE:
|
2025-02-08 13:45:57 +00:00
|
|
|
if( field.GetId() == FIELD_T::REFERENCE )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2020-06-01 09:13:32 -04:00
|
|
|
m_referenceAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_referenceAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( field.GetId() == FIELD_T::VALUE )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2023-01-18 12:49:58 -05:00
|
|
|
m_valueAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_valueAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( field.GetId() == FIELD_T::FOOTPRINT )
|
2018-07-20 16:03:43 +01:00
|
|
|
{
|
2024-01-03 08:51:24 -05:00
|
|
|
// Power symbols have do not appear in the board, so don't allow
|
2024-03-02 15:23:23 +01:00
|
|
|
// a footprint (m_part can be nullptr when loading a old schematic
|
|
|
|
// (for instance Kicad 4) with libraries missing)
|
|
|
|
if( m_part && m_part->IsPower() )
|
2024-01-03 08:51:24 -05:00
|
|
|
{
|
|
|
|
m_readOnlyAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_readOnlyAttr, aRow, aCol, aKind );
|
2024-01-03 08:51:24 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_footprintAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_footprintAttr, aRow, aCol, aKind );
|
2024-01-03 08:51:24 -05:00
|
|
|
}
|
2018-07-20 16:03:43 +01:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( field.GetId() == FIELD_T::DATASHEET )
|
2018-07-20 16:03:43 +01:00
|
|
|
{
|
|
|
|
m_urlAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_urlAttr, aRow, aCol, aKind );
|
2018-07-20 16:03:43 +01:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( field.GetId() == FIELD_T::SHEET_NAME )
|
2020-05-03 15:52:31 +01:00
|
|
|
{
|
|
|
|
m_referenceAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_referenceAttr, aRow, aCol, aKind );
|
2020-05-03 15:52:31 +01:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( field.GetId() == FIELD_T::SHEET_FILENAME )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
m_filepathAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_filepathAttr, aRow, aCol, aKind );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2021-10-12 21:05:37 +01:00
|
|
|
else if( ( m_parentType == SCH_LABEL_LOCATE_ANY_T )
|
2025-01-22 18:17:05 +00:00
|
|
|
&& field.GetCanonicalName() == wxT( "Netclass" ) )
|
2021-10-12 21:05:37 +01:00
|
|
|
{
|
|
|
|
m_netclassAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_netclassAttr, aRow, aCol, aKind );
|
2021-10-12 21:05:37 +01:00
|
|
|
}
|
2018-08-08 21:57:53 +01:00
|
|
|
else
|
2018-08-08 01:41:56 +01:00
|
|
|
{
|
2020-08-30 18:57:10 +01:00
|
|
|
wxString fn = GetValue( aRow, FDC_NAME );
|
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS* settings = m_frame->Prj().GetProjectFile().m_SchematicSettings;
|
2020-11-15 13:50:10 +01:00
|
|
|
|
|
|
|
const TEMPLATE_FIELDNAME* templateFn =
|
|
|
|
settings ? settings->m_TemplateFieldNames.GetFieldName( fn ) : nullptr;
|
2018-08-08 21:57:53 +01:00
|
|
|
|
2025-02-17 12:13:28 +00:00
|
|
|
if( ( templateFn && templateFn->m_URL ) || field.IsHypertext() )
|
2018-08-08 21:57:53 +01:00
|
|
|
{
|
2020-06-01 09:13:32 -04:00
|
|
|
m_urlAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_urlAttr, aRow, aCol, aKind );
|
2018-08-08 21:57:53 +01:00
|
|
|
}
|
2019-05-10 08:21:08 -04:00
|
|
|
else
|
|
|
|
{
|
2020-06-01 09:13:32 -04:00
|
|
|
m_nonUrlAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_nonUrlAttr, aRow, aCol, aKind );
|
2019-05-10 08:21:08 -04:00
|
|
|
}
|
2018-08-08 01:41:56 +01:00
|
|
|
}
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( nullptr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_H_ALIGN:
|
2020-06-01 09:13:32 -04:00
|
|
|
m_hAlignAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_hAlignAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_V_ALIGN:
|
2020-06-01 09:13:32 -04:00
|
|
|
m_vAlignAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_vAlignAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
2020-06-01 09:13:32 -04:00
|
|
|
m_orientationAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_orientationAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_SHOWN:
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOW_NAME:
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_ITALIC:
|
|
|
|
case FDC_BOLD:
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE:
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE:
|
2020-06-01 09:13:32 -04:00
|
|
|
m_boolAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_boolAttr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
case FDC_FONT:
|
|
|
|
m_fontAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_fontAttr, aRow, aCol, aKind );
|
2022-05-04 01:08:11 +01:00
|
|
|
|
|
|
|
case FDC_COLOR:
|
|
|
|
m_colorAttr->IncRef();
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( m_colorAttr, aRow, aCol, aKind );
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
default:
|
|
|
|
wxFAIL;
|
2024-05-16 15:50:57 +01:00
|
|
|
return enhanceAttr( nullptr, aRow, aCol, aKind );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
wxString FIELDS_GRID_TABLE::GetValue( int aRow, int aCol )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-11-13 14:01:51 +01:00
|
|
|
wxCHECK( aRow < GetNumberRows(), wxEmptyString );
|
2022-10-11 18:01:47 +01:00
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
wxGrid* grid = GetView();
|
2025-01-05 12:41:58 +00:00
|
|
|
const SCH_FIELD& field = getField( aRow );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-10-11 18:01:47 +01:00
|
|
|
if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol
|
|
|
|
&& grid->IsCellEditControlShown() )
|
|
|
|
{
|
|
|
|
auto it = m_evalOriginal.find( { aRow, aCol } );
|
|
|
|
|
|
|
|
if( it != m_evalOriginal.end() )
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
2021-10-12 21:05:37 +01:00
|
|
|
// Use default field names for mandatory and system fields because they are translated
|
2018-02-28 16:54:35 +00:00
|
|
|
// according to the current locale
|
2025-02-08 13:45:57 +00:00
|
|
|
if( m_parentType == SCH_LABEL_LOCATE_ANY_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
return SCH_LABEL_BASE::GetDefaultFieldName( field.GetCanonicalName(), false );
|
2021-10-12 21:05:37 +01:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else
|
2021-10-12 21:05:37 +01:00
|
|
|
{
|
2025-01-21 23:38:55 +00:00
|
|
|
if( field.IsMandatory() )
|
2025-02-08 13:45:57 +00:00
|
|
|
return GetDefaultFieldName( field.GetId(), DO_TRANSLATE );
|
2021-10-12 21:05:37 +01:00
|
|
|
else
|
|
|
|
return field.GetName( false );
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_VALUE:
|
2023-10-15 01:00:02 +03:00
|
|
|
return EscapeString( UnescapeString( field.GetText() ), CTX_LINE );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-01-16 15:16:24 +02:00
|
|
|
case FDC_SHOWN:
|
|
|
|
return StringFromBool( field.IsVisible() );
|
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOW_NAME:
|
|
|
|
return StringFromBool( field.IsNameShown() );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_H_ALIGN:
|
2023-09-18 12:38:09 +01:00
|
|
|
switch ( field.GetEffectiveHorizJustify() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2024-02-16 12:54:28 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT: return _( "Left" );
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: return _( "Center" );
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: return _( "Right" );
|
|
|
|
case GR_TEXT_H_ALIGN_INDETERMINATE: return INDETERMINATE_STATE;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 04:43:11 -07:00
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_V_ALIGN:
|
2023-09-18 12:38:09 +01:00
|
|
|
switch ( field.GetEffectiveVertJustify() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2024-02-16 12:54:28 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP: return _( "Top" );
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: return _( "Center" );
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: return _( "Bottom" );
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE: return INDETERMINATE_STATE;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 04:43:11 -07:00
|
|
|
break;
|
|
|
|
|
2019-01-16 15:16:24 +02:00
|
|
|
case FDC_ITALIC:
|
|
|
|
return StringFromBool( field.IsItalic() );
|
|
|
|
|
|
|
|
case FDC_BOLD:
|
|
|
|
return StringFromBool( field.IsBold() );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_TEXT_SIZE:
|
2022-09-19 10:25:20 +01:00
|
|
|
return m_frame->StringFromValue( field.GetTextHeight(), true );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
2021-12-28 22:13:54 +00:00
|
|
|
if( field.GetTextAngle().IsHorizontal() )
|
|
|
|
return _( "Horizontal" );
|
|
|
|
else
|
|
|
|
return _( "Vertical" );
|
2018-10-11 04:43:11 -07:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_POSX:
|
2022-09-19 10:25:20 +01:00
|
|
|
return m_frame->StringFromValue( field.GetTextPos().x, true );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_POSY:
|
2022-09-19 10:25:20 +01:00
|
|
|
return m_frame->StringFromValue( field.GetTextPos().y, true );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
case FDC_FONT:
|
|
|
|
if( field.GetFont() )
|
|
|
|
return field.GetFont()->GetName();
|
|
|
|
else
|
|
|
|
return DEFAULT_FONT_NAME;
|
|
|
|
|
|
|
|
case FDC_COLOR:
|
2022-09-30 20:18:37 +01:00
|
|
|
return field.GetTextColor().ToCSSString();
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE:
|
|
|
|
return StringFromBool( field.CanAutoplace() );
|
|
|
|
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE:
|
|
|
|
return StringFromBool( field.IsPrivate() );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
default:
|
|
|
|
// we can't assert here because wxWidgets sometimes calls this without checking
|
|
|
|
// the column type when trying to see if there's an overflow
|
2018-10-11 07:13:12 -07:00
|
|
|
break;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2018-10-11 07:13:12 -07:00
|
|
|
|
|
|
|
return wxT( "bad wxWidgets!" );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
bool FIELDS_GRID_TABLE::GetValueAsBool( int aRow, int aCol )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-11-13 14:01:51 +01:00
|
|
|
wxCHECK( aRow < GetNumberRows(), false );
|
2025-01-05 12:41:58 +00:00
|
|
|
const SCH_FIELD& field = getField( aRow );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOWN: return field.IsVisible();
|
|
|
|
case FDC_SHOW_NAME: return field.IsNameShown();
|
|
|
|
case FDC_ITALIC: return field.IsItalic();
|
|
|
|
case FDC_BOLD: return field.IsBold();
|
|
|
|
case FDC_ALLOW_AUTOPLACE: return field.CanAutoplace();
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE: return field.IsPrivate();
|
2018-02-28 16:54:35 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-11-13 14:01:51 +01:00
|
|
|
wxCHECK( aRow < GetNumberRows(), /*void*/ );
|
2025-01-05 12:41:58 +00:00
|
|
|
SCH_FIELD& field = getField( aRow );
|
2024-04-12 22:00:41 +01:00
|
|
|
VECTOR2I pos;
|
|
|
|
wxString value = aValue;
|
2022-10-11 18:01:47 +01:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
|
|
|
m_eval->SetDefaultUnits( m_frame->GetUserUnits() );
|
|
|
|
|
|
|
|
if( m_eval->Process( value ) )
|
|
|
|
{
|
|
|
|
m_evalOriginal[ { aRow, aCol } ] = value;
|
|
|
|
value = m_eval->Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
2022-10-11 18:01:47 +01:00
|
|
|
field.SetName( value );
|
2018-02-28 16:54:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_VALUE:
|
2021-03-29 22:10:32 +01:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
if( m_parentType == SCH_SHEET_T && field.GetId() == FIELD_T::SHEET_FILENAME )
|
2021-03-29 22:10:32 +01:00
|
|
|
{
|
2023-12-27 21:10:01 -05:00
|
|
|
value = EnsureFileExtension( value, FILEEXT::KiCadSchematicFileExtension );
|
2021-03-29 22:10:32 +01:00
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( m_parentType == LIB_SYMBOL_T && field.GetId() == FIELD_T::VALUE )
|
2021-06-30 11:53:04 +01:00
|
|
|
{
|
|
|
|
value = EscapeString( value, CTX_LIBID );
|
|
|
|
}
|
2021-03-29 22:10:32 +01:00
|
|
|
|
2023-10-15 01:00:02 +03:00
|
|
|
field.SetText( UnescapeString( value ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
break;
|
2022-05-04 01:08:11 +01:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-01-16 15:16:24 +02:00
|
|
|
case FDC_SHOWN:
|
2022-10-11 18:01:47 +01:00
|
|
|
field.SetVisible( BoolFromString( value ) );
|
2019-01-16 15:16:24 +02:00
|
|
|
break;
|
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOW_NAME:
|
|
|
|
field.SetNameShown( BoolFromString( value ) );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_H_ALIGN:
|
2023-09-18 12:38:09 +01:00
|
|
|
{
|
2023-09-18 18:15:02 +02:00
|
|
|
GR_TEXT_H_ALIGN_T horizontalJustification = GR_TEXT_H_ALIGN_CENTER;
|
2023-09-18 12:38:09 +01:00
|
|
|
|
2022-10-11 18:01:47 +01:00
|
|
|
if( value == _( "Left" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
horizontalJustification = GR_TEXT_H_ALIGN_LEFT;
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == _( "Center" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
horizontalJustification = GR_TEXT_H_ALIGN_CENTER;
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == _( "Right" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
horizontalJustification = GR_TEXT_H_ALIGN_RIGHT;
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2023-09-18 12:38:09 +01:00
|
|
|
// Note that we must set justifications before we can ask if they're flipped. If the old
|
|
|
|
// justification is center then it won't know (whereas if the new justification is center
|
|
|
|
// the we don't care).
|
|
|
|
field.SetHorizJustify( horizontalJustification );
|
|
|
|
|
|
|
|
if( field.IsHorizJustifyFlipped() )
|
|
|
|
field.SetHorizJustify( EDA_TEXT::MapHorizJustify( - horizontalJustification ) );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
break;
|
2023-09-18 12:38:09 +01:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_V_ALIGN:
|
2023-09-18 12:38:09 +01:00
|
|
|
{
|
2023-09-18 18:15:02 +02:00
|
|
|
GR_TEXT_V_ALIGN_T verticalJustification = GR_TEXT_V_ALIGN_BOTTOM;
|
2023-09-18 12:38:09 +01:00
|
|
|
|
2022-10-11 18:01:47 +01:00
|
|
|
if( value == _( "Top" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
verticalJustification = GR_TEXT_V_ALIGN_TOP;
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == _( "Center" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
verticalJustification = GR_TEXT_V_ALIGN_CENTER;
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == _( "Bottom" ) )
|
2023-09-18 12:38:09 +01:00
|
|
|
verticalJustification = GR_TEXT_V_ALIGN_BOTTOM;
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2023-09-18 12:38:09 +01:00
|
|
|
// Note that we must set justifications before we can ask if they're flipped. If the old
|
|
|
|
// justification is center then it won't know (whereas if the new justification is center
|
|
|
|
// the we don't care).
|
|
|
|
field.SetVertJustify( verticalJustification );
|
|
|
|
|
|
|
|
if( field.IsVertJustifyFlipped() )
|
|
|
|
field.SetVertJustify( EDA_TEXT::MapVertJustify( -verticalJustification ) );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
break;
|
2023-09-18 12:38:09 +01:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-01-16 15:16:24 +02:00
|
|
|
case FDC_ITALIC:
|
2022-10-11 18:01:47 +01:00
|
|
|
field.SetItalic( BoolFromString( value ) );
|
2019-01-16 15:16:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_BOLD:
|
2022-10-11 18:01:47 +01:00
|
|
|
field.SetBold( BoolFromString( value ) );
|
2019-01-16 15:16:24 +02:00
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_TEXT_SIZE:
|
2023-02-18 22:40:07 -05:00
|
|
|
field.SetTextSize( VECTOR2I( m_frame->ValueFromString( value ),
|
|
|
|
m_frame->ValueFromString( value ) ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
2022-10-11 18:01:47 +01:00
|
|
|
if( value == _( "Horizontal" ) )
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == _( "Vertical" ) )
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
2022-10-11 18:01:47 +01:00
|
|
|
wxFAIL_MSG( wxT( "unknown orientation: " ) + value );
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2019-03-07 17:43:21 +01:00
|
|
|
break;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
|
|
|
pos = field.GetTextPos();
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( aCol == FDC_POSX )
|
2022-10-11 18:01:47 +01:00
|
|
|
pos.x = m_frame->ValueFromString( value );
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
2022-10-11 18:01:47 +01:00
|
|
|
pos.y = m_frame->ValueFromString( value );
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
field.SetTextPos( pos );
|
|
|
|
break;
|
|
|
|
|
2022-05-04 01:08:11 +01:00
|
|
|
case FDC_FONT:
|
2022-10-11 18:01:47 +01:00
|
|
|
if( value == DEFAULT_FONT_NAME )
|
2022-05-04 01:08:11 +01:00
|
|
|
field.SetFont( nullptr );
|
2022-10-11 18:01:47 +01:00
|
|
|
else if( value == KICAD_FONT_NAME )
|
2025-02-06 09:47:00 -05:00
|
|
|
field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(),
|
|
|
|
field.IsItalic() ) );
|
2022-05-04 01:08:11 +01:00
|
|
|
else
|
|
|
|
field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_COLOR:
|
2022-10-11 18:01:47 +01:00
|
|
|
field.SetTextColor( wxColor( value ) );
|
2022-05-04 01:08:11 +01:00
|
|
|
break;
|
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE:
|
|
|
|
field.SetCanAutoplace( BoolFromString( value ) );
|
|
|
|
break;
|
|
|
|
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE:
|
|
|
|
field.SetPrivate( BoolFromString( value ) );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-25 12:34:30 +01:00
|
|
|
m_dialog->OnModify();
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
GetView()->Refresh();
|
|
|
|
}
|
|
|
|
|
2018-11-13 14:01:51 +01:00
|
|
|
|
2024-04-12 22:00:41 +01:00
|
|
|
void FIELDS_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-11-13 14:01:51 +01:00
|
|
|
wxCHECK( aRow < GetNumberRows(), /*void*/ );
|
2025-01-05 12:41:58 +00:00
|
|
|
SCH_FIELD& field = getField( aRow );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_SHOWN:
|
|
|
|
field.SetVisible( aValue );
|
|
|
|
break;
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_SHOW_NAME:
|
|
|
|
field.SetNameShown( aValue );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_ITALIC:
|
|
|
|
field.SetItalic( aValue );
|
|
|
|
break;
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_BOLD:
|
|
|
|
field.SetBold( aValue );
|
|
|
|
break;
|
2022-05-04 01:08:11 +01:00
|
|
|
|
2022-11-09 21:43:37 -05:00
|
|
|
case FDC_ALLOW_AUTOPLACE:
|
|
|
|
field.SetCanAutoplace( aValue );
|
|
|
|
break;
|
|
|
|
|
2025-01-05 21:23:25 +00:00
|
|
|
case FDC_PRIVATE:
|
|
|
|
field.SetPrivate( aValue );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
2021-10-25 12:34:30 +01:00
|
|
|
|
|
|
|
m_dialog->OnModify();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-05 12:41:58 +00:00
|
|
|
wxString FIELDS_GRID_TABLE::StringFromBool( bool aValue ) const
|
|
|
|
{
|
|
|
|
if( aValue )
|
|
|
|
return wxT( "1" );
|
|
|
|
else
|
|
|
|
return wxT( "0" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FIELDS_GRID_TABLE::BoolFromString( const wxString& aValue ) const
|
|
|
|
{
|
|
|
|
if( aValue == wxS( "1" ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( aValue == wxS( "0" ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxString::Format( "string '%s' can't be converted to boolean correctly and "
|
|
|
|
"will be perceived as FALSE", aValue ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
SCH_FIELD* FIELDS_GRID_TABLE::GetField( FIELD_T aFieldId )
|
|
|
|
{
|
|
|
|
for( SCH_FIELD& field : *this )
|
|
|
|
{
|
|
|
|
if( field.GetId() == aFieldId )
|
|
|
|
return &field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FIELDS_GRID_TABLE::GetFieldRow( FIELD_T aFieldId )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < (int) this->size(); ++ii )
|
|
|
|
{
|
|
|
|
if( this->at( ii ).GetId() == aFieldId )
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-27 17:01:52 +00:00
|
|
|
void FIELDS_GRID_TABLE::DetachFields()
|
|
|
|
{
|
|
|
|
for( SCH_FIELD& field : *this )
|
|
|
|
field.SetParent( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
int FIELDS_GRID_TRICKS::getFieldRow( FIELD_T aFieldId )
|
|
|
|
{
|
|
|
|
return static_cast<FIELDS_GRID_TABLE*>( m_grid->GetTable() )->GetFieldRow( aFieldId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
void FIELDS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
if( m_grid->GetGridCursorRow() == getFieldRow( FIELD_T::FOOTPRINT )
|
|
|
|
&& m_grid->GetGridCursorCol() == FDC_VALUE
|
|
|
|
&& !m_grid->IsReadOnly( getFieldRow( FIELD_T::FOOTPRINT ), FDC_VALUE ) )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-05-10 08:21:08 -04:00
|
|
|
menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
|
|
|
|
_( "Browse for footprint" ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
2025-02-08 13:45:57 +00:00
|
|
|
else if( m_grid->GetGridCursorRow() == getFieldRow( FIELD_T::DATASHEET )
|
|
|
|
&& m_grid->GetGridCursorCol() == FDC_VALUE
|
|
|
|
&& !m_grid->IsReadOnly( getFieldRow( FIELD_T::DATASHEET ), FDC_VALUE ) )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-05-10 08:21:08 -04:00
|
|
|
menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
|
|
|
|
_( "Show datasheet in browser" ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
GRID_TRICKS::showPopupMenu( menu, aEvent );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetId() == MYID_SELECT_FOOTPRINT )
|
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2025-02-08 13:45:57 +00:00
|
|
|
wxString fpid = m_grid->GetCellValue( getFieldRow( FIELD_T::FOOTPRINT ), FDC_VALUE );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2024-05-08 18:19:24 +01:00
|
|
|
if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) )
|
|
|
|
{
|
|
|
|
if( frame->ShowModal( &fpid, m_dlg ) )
|
2025-02-08 13:45:57 +00:00
|
|
|
m_grid->SetCellValue( getFieldRow( FIELD_T::FOOTPRINT ), FDC_VALUE, fpid );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2024-05-08 18:19:24 +01:00
|
|
|
frame->Destroy();
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else if (event.GetId() == MYID_SHOW_DATASHEET )
|
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
wxString datasheet_uri = m_grid->GetCellValue( getFieldRow( FIELD_T::DATASHEET ), FDC_VALUE );
|
2024-05-16 09:15:40 -07:00
|
|
|
|
2025-04-23 15:11:13 +01:00
|
|
|
GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), PROJECT_SCH::SchSearchS( &m_dlg->Prj() ),
|
|
|
|
m_filesStack );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
|
|
|
}
|
|
|
|
}
|
2019-01-16 15:16:24 +02:00
|
|
|
|
2019-05-10 08:21:08 -04:00
|
|
|
|