2017-04-02 12:09:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Oliver Walters
|
2023-02-09 20:13:05 +00:00
|
|
|
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-04-02 12:09:01 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
#include <common.h>
|
2018-03-07 12:48:08 +00:00
|
|
|
#include <base_units.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <bitmaps.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <eda_doc.h>
|
2022-09-12 22:38:36 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2023-02-09 20:13:05 +00:00
|
|
|
#include <schematic_settings.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <general.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <grid_tricks.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2023-08-02 16:50:50 +00:00
|
|
|
#include <sch_commit.h>
|
2018-04-17 10:34:48 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_reference_list.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-07-17 20:21:22 +00:00
|
|
|
#include <tools/sch_editor_control.h>
|
2021-12-16 04:56:21 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2018-07-20 22:26:37 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2022-04-17 19:02:05 +00:00
|
|
|
#include <widgets/bitmap_button.h>
|
2023-08-24 09:05:35 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2023-02-06 21:05:53 +00:00
|
|
|
#include <wx/debug.h>
|
2022-05-09 13:41:00 +00:00
|
|
|
#include <wx/ffile.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <wx/grid.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/textdlg.h>
|
2022-05-09 13:41:00 +00:00
|
|
|
#include <wx/filedlg.h>
|
2023-02-09 20:13:05 +00:00
|
|
|
#include <dialogs/eda_view_switcher.h>
|
2021-07-03 20:43:30 +00:00
|
|
|
#include "dialog_symbol_fields_table.h"
|
2023-02-28 18:37:04 +00:00
|
|
|
#include <fields_data_model.h>
|
2023-08-24 09:05:35 +00:00
|
|
|
#include <eda_list_dialog.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-08-14 14:41:28 +00:00
|
|
|
wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxCommandEvent );
|
|
|
|
|
2020-10-28 10:22:52 +00:00
|
|
|
#ifdef __WXMAC__
|
2023-08-24 09:05:35 +00:00
|
|
|
#define COLUMN_MARGIN 3
|
2020-10-28 10:22:52 +00:00
|
|
|
#else
|
|
|
|
#define COLUMN_MARGIN 15
|
|
|
|
#endif
|
|
|
|
|
2023-08-23 16:40:10 +00:00
|
|
|
using SCOPE = FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE;
|
|
|
|
|
|
|
|
|
2018-07-20 22:26:37 +00:00
|
|
|
enum
|
|
|
|
{
|
2022-03-26 11:05:10 +00:00
|
|
|
MYID_SELECT_FOOTPRINT = GRIDTRICKS_FIRST_CLIENT_ID,
|
2018-07-20 22:26:37 +00:00
|
|
|
MYID_SHOW_DATASHEET
|
|
|
|
};
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
class FIELDS_EDITOR_GRID_TRICKS : public GRID_TRICKS
|
|
|
|
{
|
|
|
|
public:
|
2019-03-04 11:02:12 +00:00
|
|
|
FIELDS_EDITOR_GRID_TRICKS( DIALOG_SHIM* aParent, WX_GRID* aGrid,
|
2023-06-05 12:24:56 +00:00
|
|
|
wxDataViewListCtrl* aFieldsCtrl,
|
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL* aDataModel ) :
|
2018-03-14 04:51:59 +00:00
|
|
|
GRID_TRICKS( aGrid ),
|
2018-07-20 22:26:37 +00:00
|
|
|
m_dlg( aParent ),
|
2023-06-05 12:24:56 +00:00
|
|
|
m_fieldsCtrl( aFieldsCtrl ),
|
|
|
|
m_dataModel( aDataModel )
|
2018-03-14 04:51:59 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
2023-02-05 20:47:27 +00:00
|
|
|
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override
|
2018-07-20 22:26:37 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( m_grid->GetGridCursorCol() == FOOTPRINT_FIELD )
|
2018-07-20 22:26:37 +00:00
|
|
|
{
|
2019-06-17 19:05:11 +00:00
|
|
|
menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
|
|
|
|
_( "Browse for footprint" ) );
|
2018-07-20 22:26:37 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( m_grid->GetGridCursorCol() == DATASHEET_FIELD )
|
2018-07-20 22:26:37 +00:00
|
|
|
{
|
2019-06-17 19:05:11 +00:00
|
|
|
menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
|
|
|
|
_( "Show datasheet in browser" ) );
|
2018-07-20 22:26:37 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
GRID_TRICKS::showPopupMenu( menu, aEvent );
|
2018-07-20 22:26:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
void doPopupSelection( wxCommandEvent& event ) override
|
|
|
|
{
|
2018-07-20 22:26:37 +00:00
|
|
|
if( event.GetId() == MYID_SELECT_FOOTPRINT )
|
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2021-07-16 20:13:26 +00:00
|
|
|
wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
|
|
|
|
FOOTPRINT_FIELD );
|
2023-09-26 17:31:45 +00:00
|
|
|
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg );
|
2018-07-20 22:26:37 +00:00
|
|
|
|
|
|
|
if( frame->ShowModal( &fpid, m_dlg ) )
|
2020-11-12 21:31:41 +00:00
|
|
|
m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid );
|
2018-07-20 22:26:37 +00:00
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
else if (event.GetId() == MYID_SHOW_DATASHEET )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
|
|
|
|
DATASHEET_FIELD );
|
2023-09-28 03:04:53 +00:00
|
|
|
GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(),
|
|
|
|
PROJECT_SCH::SchSearchS( &m_dlg->Prj() ) );
|
2018-07-20 22:26:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-05 12:24:56 +00:00
|
|
|
// We have grid tricks events to show/hide the columns from the popup menu
|
|
|
|
// and we need to make sure the data model is updated to match the grid,
|
|
|
|
// so do it through our code instead
|
|
|
|
if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE )
|
|
|
|
{
|
|
|
|
// Pop-up column order is the order of the shown fields, not the
|
|
|
|
// fieldsCtrl order
|
|
|
|
int col = event.GetId() - GRIDTRICKS_FIRST_SHOWHIDE;
|
|
|
|
|
|
|
|
bool show = !m_dataModel->GetShowColumn( col );
|
|
|
|
|
|
|
|
// Convert data model column to by iterating over m_fieldsCtrl rows
|
|
|
|
// and finding the matching field name
|
|
|
|
wxString fieldName = m_dataModel->GetColFieldName( col );
|
|
|
|
|
|
|
|
for( int row = 0; row < m_fieldsCtrl->GetItemCount(); row++ )
|
|
|
|
{
|
|
|
|
if( m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN ) == fieldName )
|
|
|
|
{
|
|
|
|
m_fieldsCtrl->SetToggleValue( show, row, SHOW_FIELD_COLUMN );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
2018-07-20 22:26:37 +00:00
|
|
|
}
|
2018-03-14 04:51:59 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 22:26:37 +00:00
|
|
|
DIALOG_SHIM* m_dlg;
|
2018-03-14 04:51:59 +00:00
|
|
|
wxDataViewListCtrl* m_fieldsCtrl;
|
2023-06-05 12:24:56 +00:00
|
|
|
FIELDS_EDITOR_GRID_DATA_MODEL* m_dataModel;
|
2018-03-14 04:51:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) :
|
2023-02-09 20:13:05 +00:00
|
|
|
DIALOG_SYMBOL_FIELDS_TABLE_BASE( parent ), m_currentBomPreset( nullptr ),
|
|
|
|
m_lastSelectedBomPreset( nullptr ), m_parent( parent ),
|
|
|
|
m_schSettings( parent->Schematic().Settings() )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
// Get all symbols from the list of schematic sheets
|
|
|
|
m_parent->Schematic().GetSheets().GetSymbols( m_symbolsList, false );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bRefresh->SetBitmap( KiBitmapBundle( BITMAPS::small_refresh ) );
|
|
|
|
m_bRefreshPreview->SetBitmap( KiBitmapBundle( BITMAPS::small_refresh ) );
|
|
|
|
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
2023-02-28 17:16:36 +00:00
|
|
|
|
2023-10-21 18:56:19 +00:00
|
|
|
m_addFieldButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_removeFieldButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_renameFieldButton->SetBitmap( KiBitmapBundle( BITMAPS::small_edit ) );
|
2023-02-28 17:16:36 +00:00
|
|
|
|
|
|
|
m_removeFieldButton->Enable( false );
|
|
|
|
m_renameFieldButton->Enable( false );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-08-24 10:20:55 +00:00
|
|
|
m_bomPresetsLabel->SetFont( KIUI::GetInfoFont( this ) );
|
|
|
|
m_labelBomExportPresets->SetFont( KIUI::GetInfoFont( this ) );
|
2023-08-24 09:05:35 +00:00
|
|
|
|
2021-02-23 14:34:06 +00:00
|
|
|
m_fieldsCtrl->AppendTextColumn( _( "Field" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
|
2023-02-23 19:10:50 +00:00
|
|
|
m_fieldsCtrl->AppendTextColumn( _( "Label" ), wxDATAVIEW_CELL_EDITABLE, 0, wxALIGN_LEFT, 0 );
|
2020-12-12 14:59:48 +00:00
|
|
|
m_fieldsCtrl->AppendToggleColumn( _( "Show" ), wxDATAVIEW_CELL_ACTIVATABLE, 0,
|
|
|
|
wxALIGN_CENTER, 0 );
|
2019-06-17 19:05:11 +00:00
|
|
|
m_fieldsCtrl->AppendToggleColumn( _( "Group By" ), wxDATAVIEW_CELL_ACTIVATABLE, 0,
|
|
|
|
wxALIGN_CENTER, 0 );
|
2020-12-12 14:59:48 +00:00
|
|
|
|
|
|
|
// GTK asserts if the number of columns doesn't match the data, but we still don't want
|
|
|
|
// to display the canonical names. So we'll insert a column for them, but keep it 0 width.
|
|
|
|
m_fieldsCtrl->AppendTextColumn( _( "Name" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
|
2018-04-23 17:23:09 +00:00
|
|
|
|
2018-04-26 17:00:25 +00:00
|
|
|
// SetWidth( wxCOL_WIDTH_AUTOSIZE ) fails here on GTK, so we calculate the title sizes and
|
|
|
|
// set the column widths ourselves.
|
2020-10-28 10:22:52 +00:00
|
|
|
wxDataViewColumn* column = m_fieldsCtrl->GetColumn( SHOW_FIELD_COLUMN );
|
2020-10-25 16:41:38 +00:00
|
|
|
m_showColWidth = KIUI::GetTextSize( column->GetTitle(), m_fieldsCtrl ).x + COLUMN_MARGIN;
|
2020-10-28 10:22:52 +00:00
|
|
|
column->SetMinWidth( m_showColWidth );
|
2018-04-26 10:09:41 +00:00
|
|
|
|
|
|
|
column = m_fieldsCtrl->GetColumn( GROUP_BY_COLUMN );
|
2020-10-25 16:41:38 +00:00
|
|
|
m_groupByColWidth = KIUI::GetTextSize( column->GetTitle(), m_fieldsCtrl ).x + COLUMN_MARGIN;
|
2020-10-28 10:22:52 +00:00
|
|
|
column->SetMinWidth( m_groupByColWidth );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// The fact that we're a list should keep the control from reserving space for the
|
|
|
|
// expander buttons... but it doesn't. Fix by forcing the indent to 0.
|
|
|
|
m_fieldsCtrl->SetIndent( 0 );
|
|
|
|
|
2022-04-17 19:02:05 +00:00
|
|
|
m_filter->SetDescriptiveText( _( "Filter" ) );
|
2023-03-15 00:03:57 +00:00
|
|
|
m_dataModel = new FIELDS_EDITOR_GRID_DATA_MODEL( m_symbolsList );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-03-30 14:17:09 +00:00
|
|
|
// We want to show excluded symbols because the Edit page needs to show all symbols,
|
|
|
|
// they will still be excluded from the export.
|
|
|
|
m_dataModel->SetIncludeExcludedFromBOM( true );
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
LoadFieldNames(); // loads rows into m_fieldsCtrl and columns into m_dataModel
|
|
|
|
|
2018-04-26 10:09:41 +00:00
|
|
|
// Now that the fields are loaded we can set the initial location of the splitter
|
2018-04-26 17:00:25 +00:00
|
|
|
// based on the list width. Again, SetWidth( wxCOL_WIDTH_AUTOSIZE ) fails us on GTK.
|
2023-02-23 19:10:50 +00:00
|
|
|
m_fieldNameColWidth = 0;
|
|
|
|
m_labelColWidth = 0;
|
2018-04-29 13:45:11 +00:00
|
|
|
|
2023-10-01 19:47:47 +00:00
|
|
|
int colWidth = 0;
|
|
|
|
|
2018-04-29 13:45:11 +00:00
|
|
|
for( int row = 0; row < m_fieldsCtrl->GetItemCount(); ++row )
|
2018-04-26 17:00:25 +00:00
|
|
|
{
|
2023-02-07 15:04:44 +00:00
|
|
|
const wxString& displayName = m_fieldsCtrl->GetTextValue( row, DISPLAY_NAME_COLUMN );
|
2023-10-01 19:47:47 +00:00
|
|
|
colWidth = std::max( colWidth, KIUI::GetTextSize( displayName, m_fieldsCtrl ).x );
|
2023-02-23 19:10:50 +00:00
|
|
|
|
|
|
|
const wxString& label = m_fieldsCtrl->GetTextValue( row, LABEL_COLUMN );
|
2023-10-01 19:47:47 +00:00
|
|
|
colWidth = std::max( colWidth, KIUI::GetTextSize( label, m_fieldsCtrl ).x );
|
2018-04-26 17:00:25 +00:00
|
|
|
}
|
2018-04-29 13:45:11 +00:00
|
|
|
|
2023-10-01 19:47:47 +00:00
|
|
|
m_fieldNameColWidth = colWidth + 20;
|
|
|
|
m_labelColWidth = colWidth + 20;
|
|
|
|
|
2023-02-23 19:10:50 +00:00
|
|
|
int fieldsMinWidth = m_fieldNameColWidth + m_labelColWidth + m_groupByColWidth + m_showColWidth;
|
2020-10-28 10:22:52 +00:00
|
|
|
|
2023-02-23 19:10:50 +00:00
|
|
|
m_fieldsCtrl->GetColumn( DISPLAY_NAME_COLUMN )->SetWidth( m_fieldNameColWidth );
|
|
|
|
m_fieldsCtrl->GetColumn( LABEL_COLUMN )->SetWidth( m_labelColWidth );
|
2020-12-12 14:59:48 +00:00
|
|
|
|
|
|
|
// This is used for data only. Don't show it to the user.
|
2023-02-07 15:04:44 +00:00
|
|
|
m_fieldsCtrl->GetColumn( FIELD_NAME_COLUMN )->SetHidden( true );
|
2020-10-29 16:27:38 +00:00
|
|
|
|
|
|
|
m_splitterMainWindow->SetMinimumPaneSize( fieldsMinWidth );
|
|
|
|
m_splitterMainWindow->SetSashPosition( fieldsMinWidth + 40 );
|
2018-04-26 10:09:41 +00:00
|
|
|
|
2022-07-08 17:16:14 +00:00
|
|
|
m_grid->UseNativeColHeader( true );
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->SetTable( m_dataModel, true );
|
|
|
|
|
2020-04-21 15:15:04 +00:00
|
|
|
// must be done after SetTable(), which appears to re-set it
|
2021-02-03 03:32:20 +00:00
|
|
|
m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
|
2020-04-21 15:15:04 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// add Cut, Copy, and Paste to wxGrid
|
2023-10-01 19:47:47 +00:00
|
|
|
m_grid->PushEventHandler( new FIELDS_EDITOR_GRID_TRICKS( this, m_grid, m_fieldsCtrl,
|
|
|
|
m_dataModel ) );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-07-20 22:26:37 +00:00
|
|
|
// give a bit more room for comboboxes
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-02-23 19:10:50 +00:00
|
|
|
// Load our BOM view presets
|
|
|
|
SetUserBomPresets( m_schSettings.m_BomPresets );
|
2023-03-27 20:48:37 +00:00
|
|
|
ApplyBomPreset( m_schSettings.m_BomSettings );
|
2023-02-23 19:10:50 +00:00
|
|
|
syncBomPresetSelection();
|
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
// Load BOM export format presets
|
|
|
|
SetUserBomFmtPresets( m_schSettings.m_BomFmtPresets );
|
2023-03-27 20:48:37 +00:00
|
|
|
ApplyBomFmtPreset( m_schSettings.m_BomFmtSettings );
|
2023-03-09 15:54:57 +00:00
|
|
|
syncBomFmtPresetSelection();
|
|
|
|
|
2023-02-06 21:05:53 +00:00
|
|
|
SetInitialFocus( m_grid );
|
2023-08-07 19:04:46 +00:00
|
|
|
m_grid->ClearSelection();
|
2023-02-06 21:05:53 +00:00
|
|
|
|
|
|
|
SetupStandardButtons();
|
|
|
|
|
|
|
|
finishDialogSettings();
|
2023-04-01 12:57:59 +00:00
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
|
|
|
EESCHEMA_SETTINGS::PANEL_FIELD_EDITOR& panelCfg = cfg->m_FieldEditorPanel;
|
2023-04-01 12:57:59 +00:00
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
wxSize dlgSize( panelCfg.width > 0 ? panelCfg.width : horizPixelsFromDU( 600 ),
|
|
|
|
panelCfg.height > 0 ? panelCfg.height : vertPixelsFromDU( 300 ) );
|
|
|
|
SetSize( dlgSize );
|
2023-04-01 12:57:59 +00:00
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
m_nbPages->SetSelection( cfg->m_FieldEditorPanel.page );
|
2023-08-23 16:40:10 +00:00
|
|
|
|
|
|
|
switch( cfg->m_FieldEditorPanel.selection_mode )
|
|
|
|
{
|
|
|
|
case 0: m_radioHighlight->SetValue( true ); break;
|
|
|
|
case 1: m_radioSelect->SetValue( true ); break;
|
|
|
|
case 2: m_radioOff->SetValue( true ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( cfg->m_FieldEditorPanel.scope )
|
|
|
|
{
|
|
|
|
case SCOPE::SCOPE_ALL: m_radioProject->SetValue( true ); break;
|
|
|
|
case SCOPE::SCOPE_SHEET: m_radioCurrentSheet->SetValue( true ); break;
|
|
|
|
case SCOPE::SCOPE_SHEET_RECURSIVE: m_radioRecursive->SetValue( true ); break;
|
|
|
|
}
|
2023-04-01 12:57:59 +00:00
|
|
|
|
2023-06-04 17:45:07 +00:00
|
|
|
m_outputFileName->SetValue( cfg->m_FieldEditorPanel.export_filename );
|
|
|
|
|
2023-02-06 21:05:53 +00:00
|
|
|
Center();
|
|
|
|
|
|
|
|
// Connect Events
|
|
|
|
m_grid->Connect( wxEVT_GRID_COL_SORT,
|
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr, this );
|
|
|
|
m_grid->Connect( wxEVT_GRID_COL_MOVE,
|
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColMove ), nullptr, this );
|
2023-02-09 20:13:05 +00:00
|
|
|
m_cbBomPresets->Bind( wxEVT_CHOICE, &DIALOG_SYMBOL_FIELDS_TABLE::onBomPresetChanged, this );
|
2023-03-09 15:54:57 +00:00
|
|
|
m_cbBomFmtPresets->Bind( wxEVT_CHOICE, &DIALOG_SYMBOL_FIELDS_TABLE::onBomFmtPresetChanged, this );
|
2023-02-23 19:10:50 +00:00
|
|
|
m_fieldsCtrl->Bind( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
|
|
|
|
&DIALOG_SYMBOL_FIELDS_TABLE::OnColLabelChange, this );
|
2023-08-14 14:41:28 +00:00
|
|
|
|
|
|
|
// Start listening for schematic changes
|
|
|
|
m_parent->Schematic().AddListener( this );
|
2023-02-06 21:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-01 17:28:56 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::SetupColumnProperties( int aCol )
|
|
|
|
{
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly( false );
|
|
|
|
|
|
|
|
// Set some column types to specific editors
|
|
|
|
if( m_dataModel->ColIsReference( aCol ) )
|
|
|
|
{
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
}
|
2023-10-03 16:14:03 +00:00
|
|
|
else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( FOOTPRINT_FIELD ) )
|
2023-08-01 17:28:56 +00:00
|
|
|
{
|
|
|
|
attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) );
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
}
|
2023-10-03 16:14:03 +00:00
|
|
|
else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( DATASHEET_FIELD ) )
|
2023-08-01 17:28:56 +00:00
|
|
|
{
|
|
|
|
// set datasheet column viewer button
|
2023-09-28 03:04:53 +00:00
|
|
|
attr->SetEditor(
|
|
|
|
new GRID_CELL_URL_EDITOR( this, PROJECT_SCH::SchSearchS( &Prj() ) ) );
|
2023-08-01 17:28:56 +00:00
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
}
|
|
|
|
else if( m_dataModel->ColIsQuantity( aCol ) || m_dataModel->ColIsItemNumber( aCol ) )
|
|
|
|
{
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
m_grid->SetColFormatNumber( aCol );
|
|
|
|
}
|
|
|
|
else if( m_dataModel->ColIsAttribute( aCol ) )
|
|
|
|
{
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
m_grid->SetColFormatBool( aCol );
|
|
|
|
}
|
|
|
|
else if( IsTextVar( m_dataModel->GetColFieldName( aCol ) ) )
|
|
|
|
{
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attr->SetEditor( m_grid->GetDefaultEditor() );
|
|
|
|
m_grid->SetColAttr( aCol, attr );
|
|
|
|
m_grid->SetColFormatCustom( aCol, wxGRID_VALUE_STRING );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::SetupAllColumnProperties()
|
2023-02-06 21:05:53 +00:00
|
|
|
{
|
2023-04-19 13:52:31 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
2023-02-09 20:13:05 +00:00
|
|
|
wxSize defaultDlgSize = ConvertDialogToPixels( wxSize( 600, 300 ) );
|
2019-06-17 19:05:11 +00:00
|
|
|
|
2023-01-30 17:16:33 +00:00
|
|
|
// Restore column sorting order and widths
|
2023-02-02 19:12:02 +00:00
|
|
|
m_grid->AutoSizeColumns( false );
|
2023-01-30 17:16:33 +00:00
|
|
|
int sortCol = 0;
|
|
|
|
bool sortAscending = true;
|
|
|
|
|
2020-04-21 15:15:04 +00:00
|
|
|
for( int col = 0; col < m_grid->GetNumberCols(); ++col )
|
2018-09-27 12:04:15 +00:00
|
|
|
{
|
2023-08-01 17:28:56 +00:00
|
|
|
SetupColumnProperties( col );
|
2023-02-06 21:05:53 +00:00
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
if( col == m_dataModel->GetSortCol() )
|
2023-03-01 15:06:00 +00:00
|
|
|
{
|
|
|
|
sortCol = col;
|
2023-04-01 12:57:59 +00:00
|
|
|
sortAscending = m_dataModel->GetSortAsc();
|
2018-10-05 12:54:15 +00:00
|
|
|
}
|
2018-09-27 12:04:15 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-02-06 21:05:53 +00:00
|
|
|
// sync m_grid's column visibilities to Show checkboxes in m_fieldsCtrl
|
|
|
|
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
|
2023-01-30 17:16:33 +00:00
|
|
|
{
|
2023-02-23 19:10:50 +00:00
|
|
|
int col = m_dataModel->GetFieldNameCol( m_fieldsCtrl->GetTextValue( i, FIELD_NAME_COLUMN ) );
|
|
|
|
|
|
|
|
if( col == -1 )
|
|
|
|
continue;
|
2023-01-30 17:16:33 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
bool show = m_fieldsCtrl->GetToggleValue( i, SHOW_FIELD_COLUMN );
|
|
|
|
m_dataModel->SetShowColumn( col, show );
|
|
|
|
|
|
|
|
if( show )
|
2023-04-01 12:57:59 +00:00
|
|
|
{
|
2023-02-23 19:10:50 +00:00
|
|
|
m_grid->ShowCol( col );
|
2023-04-01 12:57:59 +00:00
|
|
|
|
|
|
|
std::string key( m_dataModel->GetColFieldName( col ).ToUTF8() );
|
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
if( cfg->m_FieldEditorPanel.field_widths.count( key )
|
2023-04-01 12:57:59 +00:00
|
|
|
&& ( cfg->m_FieldEditorPanel.field_widths.at( key ) > 0 ) )
|
|
|
|
{
|
|
|
|
m_grid->SetColSize( col, cfg->m_FieldEditorPanel.field_widths.at( key ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int textWidth = m_dataModel->GetDataWidth( col ) + COLUMN_MARGIN;
|
|
|
|
int maxWidth = defaultDlgSize.x / 3;
|
|
|
|
|
2023-08-01 16:51:53 +00:00
|
|
|
m_grid->SetColSize( col, Clamp( 100, textWidth, maxWidth ) );
|
2023-04-01 12:57:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 21:05:53 +00:00
|
|
|
else
|
2023-04-01 12:57:59 +00:00
|
|
|
{
|
2023-02-23 19:10:50 +00:00
|
|
|
m_grid->HideCol( col );
|
2023-04-01 12:57:59 +00:00
|
|
|
}
|
2023-01-30 17:16:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetSorting( sortCol, sortAscending );
|
2023-02-06 21:05:53 +00:00
|
|
|
m_grid->SetSortingColumn( sortCol, sortAscending );
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
DIALOG_SYMBOL_FIELDS_TABLE::~DIALOG_SYMBOL_FIELDS_TABLE()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// Disconnect Events
|
2019-06-17 19:05:11 +00:00
|
|
|
m_grid->Disconnect( wxEVT_GRID_COL_SORT,
|
2021-07-16 20:13:26 +00:00
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr,
|
|
|
|
this );
|
2023-01-30 17:16:33 +00:00
|
|
|
m_grid->Disconnect( wxEVT_GRID_COL_SORT,
|
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColMove ), nullptr,
|
|
|
|
this );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// we gave ownership of m_dataModel to the wxGrid...
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
bool DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow()
|
2020-01-09 00:57:39 +00:00
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TOOL_MANAGER* toolMgr = m_parent->GetToolManager();
|
|
|
|
EE_SELECTION_TOOL* selectionTool = toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
EE_SELECTION& selection = selectionTool->GetSelection();
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = nullptr;
|
2020-01-09 00:57:39 +00:00
|
|
|
|
2023-09-20 13:40:48 +00:00
|
|
|
UpdateScope();
|
|
|
|
|
2020-01-09 00:57:39 +00:00
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = selection.Front();
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
symbol = (SCH_SYMBOL*) item;
|
|
|
|
else if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T )
|
|
|
|
symbol = (SCH_SYMBOL*) item->GetParent();
|
2020-01-09 00:57:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
if( symbol )
|
2020-01-09 00:57:39 +00:00
|
|
|
{
|
|
|
|
for( int row = 0; row < m_dataModel->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
std::vector<SCH_REFERENCE> references = m_dataModel->GetRowReferences( row );
|
|
|
|
bool found = false;
|
|
|
|
|
2020-01-09 22:55:46 +00:00
|
|
|
for( const SCH_REFERENCE& ref : references )
|
2020-01-09 00:57:39 +00:00
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
if( ref.GetSymbol() == symbol )
|
2020-01-09 00:57:39 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
{
|
2023-09-20 13:40:48 +00:00
|
|
|
// Find the value column and the reference column if they're shown
|
|
|
|
int valueCol = -1;
|
|
|
|
int refCol = -1;
|
|
|
|
int anyCol = -1;
|
|
|
|
|
|
|
|
for( int col = 0; col < m_dataModel->GetNumberCols(); col++ )
|
|
|
|
{
|
|
|
|
if( m_dataModel->ColIsValue( col ) )
|
|
|
|
valueCol = col;
|
|
|
|
else if( m_dataModel->ColIsReference( col ) )
|
|
|
|
refCol = col;
|
|
|
|
else if( anyCol == -1 && m_dataModel->GetShowColumn( col ) )
|
|
|
|
anyCol = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( valueCol != -1 && m_dataModel->GetShowColumn( valueCol ) )
|
|
|
|
m_grid->GoToCell( row, valueCol );
|
|
|
|
else if( refCol != -1 && m_dataModel->GetShowColumn( refCol ) )
|
|
|
|
m_grid->GoToCell( row, refCol );
|
|
|
|
else if( anyCol != -1 )
|
|
|
|
m_grid->GoToCell( row, anyCol );
|
|
|
|
|
2020-01-09 00:57:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:55:26 +00:00
|
|
|
// We don't want table range selection events to happen until we've loaded the data or we
|
|
|
|
// we'll clear our selection as the grid is built before the code above can get the
|
|
|
|
// user's current selection.
|
|
|
|
EnableSelectionEvents();
|
|
|
|
|
2020-01-09 00:57:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
bool DIALOG_SYMBOL_FIELDS_TABLE::TransferDataFromWindow()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-08-03 12:23:30 +00:00
|
|
|
SCH_COMMIT commit( m_parent );
|
2018-04-17 10:34:48 +00:00
|
|
|
SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
std::function<void( SCH_SYMBOL&, SCH_SHEET_PATH & aPath )> changeHandler =
|
2023-08-02 16:50:50 +00:00
|
|
|
[&commit]( SCH_SYMBOL& aSymbol, SCH_SHEET_PATH& aPath ) -> void
|
2023-03-15 00:03:57 +00:00
|
|
|
{
|
2023-08-02 16:50:50 +00:00
|
|
|
commit.Modify( &aSymbol, aPath.LastScreen() );
|
2023-03-15 00:03:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
m_dataModel->ApplyData( changeHandler );
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-08-02 16:50:50 +00:00
|
|
|
commit.Push( wxS( "Symbol Fields Table Edit" ) );
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
// Reset the view to where we left the user
|
|
|
|
m_parent->SetCurrentSheet( currentSheet );
|
2020-05-09 19:02:54 +00:00
|
|
|
m_parent->SyncView();
|
2018-04-17 10:34:48 +00:00
|
|
|
m_parent->Refresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2020-05-09 19:02:54 +00:00
|
|
|
m_parent->OnModify();
|
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
return true;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::AddField( const wxString& aFieldName, const wxString& aLabelValue,
|
|
|
|
bool show, bool groupBy, bool addedByUser )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2023-08-01 14:13:56 +00:00
|
|
|
// Users can add fields with variable names that match the special names in the grid,
|
|
|
|
// e.g. ${QUANTITY} so make sure we don't add them twice
|
|
|
|
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); i++ )
|
|
|
|
if( m_fieldsCtrl->GetTextValue( i, FIELD_NAME_COLUMN ) == aFieldName )
|
|
|
|
return;
|
|
|
|
|
2023-02-23 19:10:50 +00:00
|
|
|
m_dataModel->AddColumn( aFieldName, aLabelValue, addedByUser );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
wxVector<wxVariant> fieldsCtrlRow;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2023-02-02 19:12:02 +00:00
|
|
|
std::string key( aFieldName.ToUTF8() );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-04-21 21:19:15 +00:00
|
|
|
// Don't change these to emplace_back: some versions of wxWidgets don't support it
|
2023-02-02 19:12:02 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( aFieldName ) );
|
2023-02-23 19:10:50 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( aLabelValue ) );
|
2020-04-21 21:19:15 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( show ) );
|
2023-03-15 00:03:57 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( groupBy ) );
|
2023-02-23 19:10:50 +00:00
|
|
|
fieldsCtrlRow.push_back( wxVariant( aFieldName ) );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2018-05-22 11:50:57 +00:00
|
|
|
m_fieldsCtrl->AppendItem( fieldsCtrlRow );
|
2023-04-04 14:35:30 +00:00
|
|
|
|
|
|
|
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_APPENDED, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames()
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2023-03-16 13:53:37 +00:00
|
|
|
// Add mandatory fields first
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
|
|
|
{
|
|
|
|
bool show = false;
|
|
|
|
bool groupBy = false;
|
|
|
|
|
|
|
|
switch( i )
|
|
|
|
{
|
|
|
|
case REFERENCE_FIELD:
|
|
|
|
case VALUE_FIELD:
|
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
show = true;
|
|
|
|
groupBy = true;
|
|
|
|
break;
|
|
|
|
case DATASHEET_FIELD:
|
|
|
|
show = true;
|
|
|
|
groupBy = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddField( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ),
|
|
|
|
TEMPLATE_FIELDNAME::GetDefaultFieldName( i, true ), show, groupBy );
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:13:56 +00:00
|
|
|
// Generated fields present only in the fields table
|
|
|
|
AddField( FIELDS_EDITOR_GRID_DATA_MODEL::QUANTITY_VARIABLE, _( "Qty" ), true, false );
|
|
|
|
AddField( FIELDS_EDITOR_GRID_DATA_MODEL::ITEM_NUMBER_VARIABLE, _( "#" ), true, false );
|
2023-03-16 13:53:37 +00:00
|
|
|
|
2023-08-01 14:13:56 +00:00
|
|
|
// User fields next
|
2018-05-19 15:47:39 +00:00
|
|
|
std::set<wxString> userFieldNames;
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = m_symbolsList[ i ].GetSymbol();
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j )
|
2021-02-28 13:28:23 +00:00
|
|
|
userFieldNames.insert( symbol->GetFields()[j].GetName() );
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2019-07-17 20:45:43 +00:00
|
|
|
for( const wxString& fieldName : userFieldNames )
|
2023-07-12 15:28:23 +00:00
|
|
|
AddField( fieldName, GetTextVars( fieldName ), true, false );
|
2018-05-19 15:47:39 +00:00
|
|
|
|
2018-07-07 02:36:31 +00:00
|
|
|
// Add any templateFieldNames which aren't already present in the userFieldNames
|
2020-08-30 17:57:10 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& templateFieldname :
|
2023-02-09 20:13:05 +00:00
|
|
|
m_schSettings.m_TemplateFieldNames.GetTemplateFieldNames() )
|
2020-02-16 12:51:44 +00:00
|
|
|
{
|
2020-08-30 17:57:10 +00:00
|
|
|
if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
|
2023-07-12 15:28:23 +00:00
|
|
|
AddField( templateFieldname.m_Name, GetTextVars( templateFieldname.m_Name ), false,
|
|
|
|
false );
|
2020-02-16 12:51:44 +00:00
|
|
|
}
|
2018-04-17 10:34:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event )
|
2018-05-23 12:12:01 +00:00
|
|
|
{
|
|
|
|
wxTextEntryDialog dlg( this, _( "New field name:" ), _( "Add Field" ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString fieldName = dlg.GetValue();
|
|
|
|
|
|
|
|
if( fieldName.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Field must have a name." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 0; i < m_dataModel->GetNumberCols(); ++i )
|
|
|
|
{
|
2023-02-02 19:12:02 +00:00
|
|
|
if( fieldName == m_dataModel->GetColFieldName( i ) )
|
2018-05-23 12:12:01 +00:00
|
|
|
{
|
2021-11-04 00:02:14 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Field name '%s' already in use." ),
|
2019-06-17 19:05:11 +00:00
|
|
|
fieldName ) );
|
2018-05-23 12:12:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
AddField( fieldName, GetTextVars( fieldName ), true, false, true );
|
2018-05-23 12:12:01 +00:00
|
|
|
|
2023-08-01 17:28:56 +00:00
|
|
|
SetupColumnProperties( m_dataModel->GetColsCount() - 1 );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2018-05-23 12:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-12 20:13:26 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event )
|
|
|
|
{
|
2022-09-11 12:28:53 +00:00
|
|
|
int col = -1;
|
|
|
|
int row = m_fieldsCtrl->GetSelectedRow();
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
// Should never occur: "Remove Field..." button should be disabled if invalid selection
|
|
|
|
// via OnFieldsCtrlSelectionChanged()
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_RET( row != -1, wxS( "Some user defined field must be selected first" ) );
|
|
|
|
wxCHECK_RET( row >= MANDATORY_FIELDS, wxS( "Mandatory fields cannot be removed" ) );
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2023-02-07 15:04:44 +00:00
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
|
|
|
wxString displayName = m_fieldsCtrl->GetTextValue( row, DISPLAY_NAME_COLUMN );
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2023-02-07 15:04:44 +00:00
|
|
|
wxString confirm_msg =
|
|
|
|
wxString::Format( _( "Are you sure you want to remove the field '%s'?" ), displayName );
|
2022-11-25 15:17:20 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
if( !IsOK( this, confirm_msg ) )
|
|
|
|
return;
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
for( int i = 0; i < m_dataModel->GetNumberCols(); ++i )
|
2022-04-12 20:13:26 +00:00
|
|
|
{
|
2023-02-02 19:12:02 +00:00
|
|
|
if( fieldName == m_dataModel->GetColFieldName( i ) )
|
2022-09-24 01:44:15 +00:00
|
|
|
col = i;
|
2022-04-12 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
m_fieldsCtrl->DeleteItem( row );
|
|
|
|
m_dataModel->RemoveColumn( col );
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
// Make selection and update the state of "Remove field..." button via OnFieldsCtrlSelectionChanged()
|
|
|
|
// Safe to decrement row index because we always have mandatory fields
|
|
|
|
m_fieldsCtrl->SelectRow( --row );
|
|
|
|
|
|
|
|
if( row < MANDATORY_FIELDS )
|
2023-01-27 14:18:32 +00:00
|
|
|
{
|
|
|
|
m_removeFieldButton->Enable( false );
|
|
|
|
m_renameFieldButton->Enable( false );
|
|
|
|
}
|
2022-09-11 12:28:53 +00:00
|
|
|
|
2023-08-14 12:36:49 +00:00
|
|
|
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_DELETED, col, 1 );
|
2022-11-25 15:17:20 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
m_grid->ProcessTableMessage( msg );
|
2022-04-12 20:13:26 +00:00
|
|
|
|
2023-02-09 20:13:05 +00:00
|
|
|
syncBomPresetSelection();
|
2022-04-12 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-27 14:18:32 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnRenameField( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int row = m_fieldsCtrl->GetSelectedRow();
|
2023-04-04 15:04:52 +00:00
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
2023-01-27 14:18:32 +00:00
|
|
|
|
|
|
|
// Should never occur: "Rename Field..." button should be disabled if invalid selection
|
|
|
|
// via OnFieldsCtrlSelectionChanged()
|
|
|
|
wxCHECK_RET( row != -1, wxS( "Some user defined field must be selected first" ) );
|
|
|
|
wxCHECK_RET( row >= MANDATORY_FIELDS, wxS( "Mandatory fields cannot be renamed" ) );
|
2023-04-04 15:04:52 +00:00
|
|
|
wxCHECK_RET( !fieldName.IsEmpty(), wxS( "Field must have a name" ) );
|
2023-01-27 14:18:32 +00:00
|
|
|
|
2023-04-04 15:04:52 +00:00
|
|
|
int col = m_dataModel->GetFieldNameCol( fieldName );
|
|
|
|
wxCHECK_RET( col != -1, wxS( "Existing field name missing from data model" ) );
|
2023-01-27 14:18:32 +00:00
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, _( "New field name:" ), _( "Rename Field" ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString newFieldName = dlg.GetValue();
|
|
|
|
|
2023-04-04 15:04:52 +00:00
|
|
|
// No change, no-op
|
|
|
|
if( newFieldName == fieldName )
|
2023-01-27 14:18:32 +00:00
|
|
|
return;
|
|
|
|
|
2023-04-04 15:04:52 +00:00
|
|
|
// New field name already exists
|
|
|
|
if( m_dataModel->GetFieldNameCol( newFieldName ) != -1 )
|
2023-01-27 14:18:32 +00:00
|
|
|
{
|
2023-04-04 15:04:52 +00:00
|
|
|
wxString confirm_msg = wxString::Format(
|
|
|
|
_( "Field name %s already exists. Cannot rename over existing field." ),
|
|
|
|
newFieldName );
|
|
|
|
DisplayError( this, confirm_msg );
|
|
|
|
return;
|
2023-01-27 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dataModel->RenameColumn( col, newFieldName );
|
2023-04-04 15:04:52 +00:00
|
|
|
m_fieldsCtrl->SetTextValue( newFieldName, col, DISPLAY_NAME_COLUMN );
|
|
|
|
m_fieldsCtrl->SetTextValue( newFieldName, col, FIELD_NAME_COLUMN );
|
2023-01-27 14:18:32 +00:00
|
|
|
|
2023-02-09 20:13:05 +00:00
|
|
|
syncBomPresetSelection();
|
2023-01-27 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 19:02:05 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnFilterText( wxCommandEvent& aEvent )
|
|
|
|
{
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetFilter( m_filter->GetValue() );
|
|
|
|
m_dataModel->RebuildRows();
|
2022-04-17 19:02:05 +00:00
|
|
|
m_grid->ForceRefresh();
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2022-04-17 19:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnFilterMouseMoved( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxPoint pos = aEvent.GetPosition();
|
|
|
|
wxRect ctrlRect = m_filter->GetScreenRect();
|
|
|
|
int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
|
|
|
|
|
2023-11-29 03:04:36 +00:00
|
|
|
// TODO: restore cursor when mouse leaves the filter field (or is it a MSW bug?)
|
2022-04-17 19:02:05 +00:00
|
|
|
if( m_filter->IsSearchButtonVisible() && pos.x < buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else if( m_filter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else
|
|
|
|
SetCursor( wxCURSOR_IBEAM );
|
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2022-09-11 12:28:53 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnFieldsCtrlSelectionChanged( wxDataViewEvent& event )
|
|
|
|
{
|
|
|
|
int row = m_fieldsCtrl->GetSelectedRow();
|
|
|
|
|
|
|
|
if( row >= MANDATORY_FIELDS )
|
2023-01-27 14:18:32 +00:00
|
|
|
{
|
2022-09-11 12:28:53 +00:00
|
|
|
m_removeFieldButton->Enable( true );
|
2023-01-27 14:18:32 +00:00
|
|
|
m_renameFieldButton->Enable( true );
|
|
|
|
}
|
2022-09-11 12:28:53 +00:00
|
|
|
else
|
2023-01-27 14:18:32 +00:00
|
|
|
{
|
2022-09-11 12:28:53 +00:00
|
|
|
m_removeFieldButton->Enable( false );
|
2023-01-27 14:18:32 +00:00
|
|
|
m_renameFieldButton->Enable( false );
|
|
|
|
}
|
2022-09-11 12:28:53 +00:00
|
|
|
}
|
2022-04-17 19:02:05 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )
|
2018-04-17 10:34:48 +00:00
|
|
|
{
|
2023-02-09 20:13:05 +00:00
|
|
|
wxDataViewItem item = event.GetItem();
|
|
|
|
int row = m_fieldsCtrl->ItemToRow( item );
|
|
|
|
int col = event.GetColumn();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
switch ( col )
|
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
case SHOW_FIELD_COLUMN:
|
2018-05-19 15:47:39 +00:00
|
|
|
{
|
|
|
|
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
2023-03-15 00:03:57 +00:00
|
|
|
int dataCol = m_dataModel->GetFieldNameCol(
|
|
|
|
m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN ) );
|
2019-02-03 20:53:21 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetShowColumn( dataCol, value );
|
2023-02-23 19:10:50 +00:00
|
|
|
|
|
|
|
if( dataCol != -1 )
|
|
|
|
{
|
|
|
|
if( value )
|
|
|
|
m_grid->ShowCol( dataCol );
|
|
|
|
else
|
|
|
|
m_grid->HideCol( dataCol );
|
|
|
|
}
|
2021-02-23 14:34:06 +00:00
|
|
|
|
2017-04-02 12:09:01 +00:00
|
|
|
break;
|
2018-05-19 15:47:39 +00:00
|
|
|
}
|
2017-11-03 08:41:48 +00:00
|
|
|
|
2018-04-17 10:34:48 +00:00
|
|
|
case GROUP_BY_COLUMN:
|
2018-05-19 15:47:39 +00:00
|
|
|
{
|
|
|
|
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
2023-06-04 18:42:55 +00:00
|
|
|
int dataCol = m_dataModel->GetFieldNameCol(
|
|
|
|
m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN ) );
|
2023-02-02 19:12:02 +00:00
|
|
|
|
2023-06-04 18:42:55 +00:00
|
|
|
if( m_dataModel->ColIsQuantity( dataCol ) && value )
|
2023-02-02 19:12:02 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "The Quantity column cannot be grouped by." ) );
|
|
|
|
|
|
|
|
value = false;
|
|
|
|
m_fieldsCtrl->SetToggleValue( value, row, col );
|
|
|
|
}
|
|
|
|
|
2023-07-12 19:08:32 +00:00
|
|
|
if( m_dataModel->ColIsItemNumber( dataCol ) && value )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "The Item Number column cannot be grouped by." ) );
|
|
|
|
|
|
|
|
value = false;
|
|
|
|
m_fieldsCtrl->SetToggleValue( value, row, col );
|
|
|
|
}
|
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetGroupColumn( m_dataModel->GetFieldNameCol( fieldName ), value );
|
|
|
|
m_dataModel->RebuildRows();
|
2018-05-19 15:47:39 +00:00
|
|
|
m_grid->ForceRefresh();
|
2017-05-08 10:41:46 +00:00
|
|
|
break;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
2021-02-23 14:34:06 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2018-05-19 15:47:39 +00:00
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnGroupSymbolsToggled( wxCommandEvent& event )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetGroupingEnabled( m_groupSymbolsBox->GetValue() );
|
|
|
|
m_dataModel->RebuildRows();
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->ForceRefresh();
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2017-04-18 09:25:02 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2023-03-30 14:17:09 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnExcludeDNPToggled( wxCommandEvent& event )
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
m_dataModel->SetExcludeDNP( m_checkExcludeDNP->GetValue() );
|
2023-03-30 14:17:09 +00:00
|
|
|
m_dataModel->RebuildRows();
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
|
|
|
|
syncBomPresetSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnColSort( wxGridEvent& aEvent )
|
2017-04-18 09:25:02 +00:00
|
|
|
{
|
2023-02-09 20:13:05 +00:00
|
|
|
int sortCol = aEvent.GetCol();
|
|
|
|
std::string key( m_dataModel->GetColFieldName( sortCol ).ToUTF8() );
|
|
|
|
bool ascending;
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-07-12 19:08:32 +00:00
|
|
|
// Don't sort by item number, it is generated by the sort
|
|
|
|
if( m_dataModel->ColIsItemNumber( sortCol ) )
|
|
|
|
{
|
|
|
|
aEvent.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-12 14:59:48 +00:00
|
|
|
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the event, and
|
|
|
|
// if we ask it will give us pre-event info.
|
2018-04-17 10:34:48 +00:00
|
|
|
if( m_grid->IsSortingBy( sortCol ) )
|
2020-12-12 14:59:48 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// same column; invert ascending
|
|
|
|
ascending = !m_grid->IsSortOrderAscending();
|
2020-12-12 14:59:48 +00:00
|
|
|
}
|
2018-04-17 10:34:48 +00:00
|
|
|
else
|
2020-12-12 14:59:48 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
// different column; start with ascending
|
|
|
|
ascending = true;
|
2020-12-12 14:59:48 +00:00
|
|
|
}
|
2017-04-02 12:09:01 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->SetSorting( sortCol, ascending );
|
|
|
|
m_dataModel->RebuildRows();
|
2019-11-13 07:33:29 +00:00
|
|
|
m_grid->ForceRefresh();
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2023-01-30 17:16:33 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnColMove( wxGridEvent& aEvent )
|
|
|
|
{
|
2023-02-06 21:05:53 +00:00
|
|
|
int origPos = aEvent.GetCol();
|
|
|
|
|
2023-01-30 17:16:33 +00:00
|
|
|
CallAfter(
|
2023-02-06 21:05:53 +00:00
|
|
|
[origPos, this]()
|
2023-01-30 17:16:33 +00:00
|
|
|
{
|
2023-02-06 21:05:53 +00:00
|
|
|
int newPos = m_grid->GetColPos( origPos );
|
|
|
|
|
|
|
|
m_dataModel->MoveColumn( origPos, newPos );
|
|
|
|
|
|
|
|
// "Unmove" the column since we've moved the column internally
|
|
|
|
m_grid->ResetColPos();
|
|
|
|
|
|
|
|
// We need to reset all the column attr's to the correct column order
|
2023-08-01 17:28:56 +00:00
|
|
|
SetupAllColumnProperties();
|
2023-01-30 17:16:33 +00:00
|
|
|
|
2023-02-06 21:05:53 +00:00
|
|
|
m_grid->ForceRefresh();
|
2023-01-30 17:16:33 +00:00
|
|
|
} );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
syncBomPresetSelection();
|
2023-01-30 17:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-23 19:10:50 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnColLabelChange( wxDataViewEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxDataViewItem item = aEvent.GetItem();
|
|
|
|
int row = m_fieldsCtrl->ItemToRow( item );
|
|
|
|
wxString label = m_fieldsCtrl->GetTextValue( row, LABEL_COLUMN );
|
|
|
|
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
|
|
|
int col = m_dataModel->GetFieldNameCol( fieldName );
|
|
|
|
|
|
|
|
if( col != -1 )
|
|
|
|
m_dataModel->SetColLabelValue( col, label );
|
|
|
|
|
|
|
|
syncBomPresetSelection();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
}
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableValueChanged( wxGridEvent& aEvent )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->ForceRefresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 16:43:28 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableColSize( wxGridSizeEvent& aEvent )
|
2020-04-21 15:15:04 +00:00
|
|
|
{
|
2023-02-09 20:13:05 +00:00
|
|
|
int col = aEvent.GetRowOrCol();
|
|
|
|
std::string key( m_dataModel->GetColFieldName( col ).ToUTF8() );
|
2020-04-21 15:15:04 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
2023-02-23 19:10:50 +00:00
|
|
|
|
|
|
|
m_grid->ForceRefresh();
|
2020-04-21 15:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnRegroupSymbols( wxCommandEvent& aEvent )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->RebuildRows();
|
2018-04-17 10:34:48 +00:00
|
|
|
m_grid->ForceRefresh();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2023-08-07 19:04:46 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnScopeChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
UpdateScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::UpdateScope()
|
|
|
|
{
|
|
|
|
m_dataModel->SetPath( m_parent->GetCurrentSheet() );
|
2023-08-23 16:40:10 +00:00
|
|
|
|
|
|
|
if( m_radioProject->GetValue() )
|
|
|
|
m_dataModel->SetScope( FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_ALL );
|
|
|
|
else if( m_radioCurrentSheet->GetValue() )
|
|
|
|
m_dataModel->SetScope( FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_SHEET );
|
|
|
|
else if( m_radioRecursive->GetValue() )
|
|
|
|
m_dataModel->SetScope( FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_SHEET_RECURSIVE );
|
|
|
|
|
2023-08-07 19:04:46 +00:00
|
|
|
m_dataModel->RebuildRows();
|
|
|
|
}
|
2017-11-03 08:41:48 +00:00
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableCellClick( wxGridEvent& event )
|
2018-05-12 22:04:11 +00:00
|
|
|
{
|
2023-02-06 21:05:53 +00:00
|
|
|
if( m_dataModel->ColIsReference( event.GetCol() ) )
|
2018-05-19 15:25:28 +00:00
|
|
|
{
|
2019-01-16 13:16:23 +00:00
|
|
|
m_grid->ClearSelection();
|
|
|
|
|
2018-05-19 15:25:28 +00:00
|
|
|
m_dataModel->ExpandCollapseRow( event.GetRow() );
|
2023-08-07 17:49:27 +00:00
|
|
|
m_grid->SetGridCursor( event.GetRow(), event.GetCol() );
|
2018-05-19 15:25:28 +00:00
|
|
|
}
|
2018-05-12 22:04:11 +00:00
|
|
|
else
|
2018-05-19 15:25:28 +00:00
|
|
|
{
|
2018-05-12 22:04:11 +00:00
|
|
|
event.Skip();
|
2018-05-19 15:25:28 +00:00
|
|
|
}
|
2018-05-12 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected( wxGridRangeSelectEvent& aEvent )
|
2023-01-29 11:51:21 +00:00
|
|
|
{
|
2023-08-07 17:49:27 +00:00
|
|
|
// Multi-select can grab the rows that are expanded child refs, and also the row
|
|
|
|
// containing the list of all child refs. Make sure we add refs/symbols uniquely
|
|
|
|
std::set<SCH_REFERENCE> refs;
|
|
|
|
std::set<SCH_ITEM*> symbols;
|
2023-01-29 11:51:21 +00:00
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
// This handler handles selecting and deselecting
|
|
|
|
if( aEvent.Selecting() )
|
2023-01-30 14:29:47 +00:00
|
|
|
{
|
2023-08-07 17:49:27 +00:00
|
|
|
for( int i = aEvent.GetTopRow(); i <= aEvent.GetBottomRow(); i++ )
|
2023-08-23 16:40:10 +00:00
|
|
|
{
|
|
|
|
for( const SCH_REFERENCE& ref : m_dataModel->GetRowReferences( i ) )
|
2023-08-07 17:49:27 +00:00
|
|
|
refs.insert( ref );
|
2023-08-23 16:40:10 +00:00
|
|
|
}
|
2023-01-29 11:51:21 +00:00
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
for( const SCH_REFERENCE& ref : refs )
|
|
|
|
symbols.insert( ref.GetSymbol() );
|
|
|
|
}
|
2023-01-29 11:51:21 +00:00
|
|
|
|
2023-08-23 16:40:10 +00:00
|
|
|
if( m_radioHighlight->GetValue() )
|
2023-08-07 17:49:27 +00:00
|
|
|
{
|
|
|
|
SCH_EDITOR_CONTROL* editor = m_parent->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>();
|
2023-01-30 14:40:48 +00:00
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
if( refs.size() > 0 )
|
2023-08-08 12:17:43 +00:00
|
|
|
{
|
|
|
|
// Use of full path based on UUID allows select of not yet annotated or duplicaded symbols
|
|
|
|
wxString symbol_path = refs.begin()->GetFullPath();
|
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
// Focus only handles on item at this time
|
|
|
|
editor->FindSymbolAndItem( &symbol_path, nullptr, true, HIGHLIGHT_SYMBOL,
|
|
|
|
wxEmptyString );
|
2023-08-08 12:17:43 +00:00
|
|
|
}
|
2023-08-07 17:49:27 +00:00
|
|
|
else
|
2023-08-23 16:40:10 +00:00
|
|
|
{
|
2023-08-07 17:49:27 +00:00
|
|
|
m_parent->FocusOnItem( nullptr );
|
2023-08-23 16:40:10 +00:00
|
|
|
}
|
2023-01-29 11:51:21 +00:00
|
|
|
}
|
2023-08-23 16:40:10 +00:00
|
|
|
else if( m_radioSelect->GetValue() )
|
2023-08-07 17:49:27 +00:00
|
|
|
{
|
|
|
|
EE_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
|
2023-01-29 11:51:21 +00:00
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
std::vector<SCH_ITEM*> items( symbols.begin(), symbols.end() );
|
2018-05-12 22:04:11 +00:00
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
if( refs.size() > 0 )
|
|
|
|
selTool->SyncSelection( refs.begin()->GetSheetPath(), nullptr, items );
|
|
|
|
else
|
|
|
|
selTool->ClearSelection();
|
|
|
|
}
|
|
|
|
}
|
2023-08-23 16:40:10 +00:00
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableItemContextMenu( wxGridEvent& event )
|
2017-04-25 02:55:49 +00:00
|
|
|
{
|
2019-06-17 19:02:48 +00:00
|
|
|
// TODO: Option to select footprint if FOOTPRINT column selected
|
2017-04-25 02:55:49 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
2017-06-07 16:43:28 +00:00
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSizeFieldList( wxSizeEvent& event )
|
2017-04-25 02:55:49 +00:00
|
|
|
{
|
2023-10-01 19:47:47 +00:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_fieldsCtrl ).x
|
|
|
|
- m_showColWidth
|
|
|
|
- m_groupByColWidth;
|
2022-07-08 17:16:14 +00:00
|
|
|
#ifdef __WXMAC__
|
2022-11-14 18:46:39 +00:00
|
|
|
// TODO: something in wxWidgets 3.1.x pads checkbox columns with extra space. (It used to
|
|
|
|
// also be that the width of the column would get set too wide (to 30), but that's patched in
|
|
|
|
// our local wxWidgets fork.)
|
2023-10-01 19:47:47 +00:00
|
|
|
width -= 50;
|
2022-07-08 17:16:14 +00:00
|
|
|
#endif
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-10-01 19:47:47 +00:00
|
|
|
m_fieldNameColWidth = width / 2;
|
|
|
|
m_labelColWidth = width = m_fieldNameColWidth;
|
|
|
|
|
2018-05-04 14:43:59 +00:00
|
|
|
// GTK loses its head and messes these up when resizing the splitter bar:
|
2020-10-28 10:22:52 +00:00
|
|
|
m_fieldsCtrl->GetColumn( SHOW_FIELD_COLUMN )->SetWidth( m_showColWidth );
|
|
|
|
m_fieldsCtrl->GetColumn( GROUP_BY_COLUMN )->SetWidth( m_groupByColWidth );
|
2018-04-17 10:34:48 +00:00
|
|
|
|
2023-02-07 15:04:44 +00:00
|
|
|
m_fieldsCtrl->GetColumn( FIELD_NAME_COLUMN )->SetHidden( true );
|
2023-02-23 19:10:50 +00:00
|
|
|
m_fieldsCtrl->GetColumn( DISPLAY_NAME_COLUMN )->SetWidth( m_fieldNameColWidth );
|
|
|
|
m_fieldsCtrl->GetColumn( LABEL_COLUMN )->SetWidth( m_labelColWidth );
|
2017-04-25 02:55:49 +00:00
|
|
|
|
2021-12-15 04:35:44 +00:00
|
|
|
m_fieldsCtrl->Refresh(); // To refresh checkboxes on Windows.
|
|
|
|
|
2017-04-25 02:55:49 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
2018-04-19 22:13:19 +00:00
|
|
|
|
|
|
|
|
2021-07-03 20:43:30 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSaveAndContinue( wxCommandEvent& aEvent )
|
2018-04-19 22:13:19 +00:00
|
|
|
{
|
|
|
|
if( TransferDataFromWindow() )
|
2018-08-01 23:06:12 +00:00
|
|
|
m_parent->SaveProject();
|
2018-04-19 22:13:19 +00:00
|
|
|
}
|
2018-06-05 19:59:58 +00:00
|
|
|
|
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnPageChanged( wxNotebookEvent& event )
|
|
|
|
{
|
|
|
|
PreviewRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-28 18:37:04 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnPreviewRefresh( wxCommandEvent& event )
|
|
|
|
{
|
2023-03-09 15:54:57 +00:00
|
|
|
PreviewRefresh();
|
|
|
|
syncBomFmtPresetSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::PreviewRefresh()
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
m_dataModel->SetIncludeExcludedFromBOM( false );
|
|
|
|
m_dataModel->RebuildRows();
|
|
|
|
|
|
|
|
m_textOutput->SetValue( m_dataModel->Export( GetCurrentBomFmtSettings() ) );
|
|
|
|
|
|
|
|
m_dataModel->SetIncludeExcludedFromBOM( true );
|
|
|
|
m_dataModel->RebuildRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOM_FMT_PRESET DIALOG_SYMBOL_FIELDS_TABLE::GetCurrentBomFmtSettings()
|
|
|
|
{
|
|
|
|
BOM_FMT_PRESET current;
|
2023-03-03 13:43:40 +00:00
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
current.name = m_cbBomFmtPresets->GetStringSelection();
|
2023-03-09 15:54:57 +00:00
|
|
|
current.fieldDelimiter = m_textFieldDelimiter->GetValue();
|
|
|
|
current.stringDelimiter = m_textStringDelimiter->GetValue();
|
2023-03-15 00:03:57 +00:00
|
|
|
current.refDelimiter = m_textRefDelimiter->GetValue();
|
|
|
|
current.refRangeDelimiter = m_textRefRangeDelimiter->GetValue();
|
|
|
|
current.keepTabs = m_checkKeepTabs->GetValue();
|
|
|
|
current.keepLineBreaks = m_checkKeepLineBreaks->GetValue();
|
2023-03-09 15:54:57 +00:00
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
return current;
|
2023-02-28 18:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-27 13:13:55 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ShowEditTab()
|
|
|
|
{
|
|
|
|
m_nbPages->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-20 15:12:03 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ShowExportTab()
|
|
|
|
{
|
|
|
|
m_nbPages->SetSelection( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnOutputFileBrowseClicked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// Build the absolute path of current output directory to preselect it in the file browser.
|
|
|
|
wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
|
|
|
|
path = Prj().AbsolutePath( path );
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the export filename
|
|
|
|
wxFileName fn( Prj().AbsolutePath( m_parent->Schematic().GetFileName() ) );
|
|
|
|
fn.SetExt( CsvFileExtension );
|
|
|
|
|
2023-10-23 17:01:04 +00:00
|
|
|
wxFileDialog saveDlg( this, _( "Bill of Materials Output File" ), path, fn.GetFullName(),
|
2023-03-08 19:31:51 +00:00
|
|
|
CsvFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( saveDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
wxFileName file = wxFileName( saveDlg.GetPath() );
|
|
|
|
wxString defaultPath = fn.GetPathWithSep();
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
|
|
|
|
|
|
|
|
wxMessageDialog dialog( this, msg, _( "BOM Output File" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_YES )
|
|
|
|
{
|
|
|
|
if( !file.MakeRelativeTo( defaultPath ) )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Cannot make path relative (target volume different from schematic "
|
|
|
|
"file volume)!" ),
|
|
|
|
_( "BOM Output File" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputFileName->SetValue( file.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-09 13:41:00 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnExport( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_dataModel->IsEdited() )
|
|
|
|
if( OKOrCancelDialog( nullptr, _( "Unsaved data" ),
|
|
|
|
_( "Changes are unsaved. Export unsaved data?" ), "", _( "OK" ),
|
|
|
|
_( "Cancel" ) )
|
|
|
|
== wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
// Create output directory if it does not exist (also transform it in absolute form).
|
|
|
|
// Bail if it fails.
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
std::function<bool( wxString* )> textResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
SCHEMATIC& schematic = m_parent->Schematic();
|
|
|
|
|
|
|
|
// Handles m_board->GetTitleBlock() *and* m_board->GetProject()
|
|
|
|
return schematic.ResolveTextVar( &schematic.CurrentSheet(), token, 0 );
|
|
|
|
};
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
wxString path = m_outputFileName->GetValue();
|
2023-10-06 11:50:59 +00:00
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "No filename specified in exporter" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
path = ExpandTextVars( path, &textResolver );
|
|
|
|
path = ExpandEnvVarSubstitutions( path, nullptr );
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
wxFileName outputFile = wxFileName::FileName( path );
|
2023-10-06 11:50:59 +00:00
|
|
|
wxString msg;
|
2023-03-08 19:31:51 +00:00
|
|
|
|
|
|
|
if( !EnsureFileDirectoryExists( &outputFile,
|
|
|
|
Prj().AbsolutePath( m_parent->Schematic().GetFileName() ),
|
|
|
|
&NULL_REPORTER::GetInstance() ) )
|
|
|
|
{
|
2023-10-06 11:50:59 +00:00
|
|
|
msg.Printf( _( "Could not open/create path '%s'." ), outputFile.GetPath() );
|
|
|
|
DisplayError( this, msg );
|
2022-05-09 13:41:00 +00:00
|
|
|
return;
|
2023-03-08 19:31:51 +00:00
|
|
|
}
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-03-08 19:31:51 +00:00
|
|
|
wxFFile out( outputFile.GetFullPath(), "wb" );
|
2022-05-09 13:41:00 +00:00
|
|
|
|
|
|
|
if( !out.IsOpened() )
|
2023-03-08 19:31:51 +00:00
|
|
|
{
|
2023-10-06 11:50:59 +00:00
|
|
|
msg.Printf( _( "Could not create BOM output '%s'." ), outputFile.GetFullPath() );
|
|
|
|
DisplayError( this, msg );
|
2022-05-09 13:41:00 +00:00
|
|
|
return;
|
2023-03-08 19:31:51 +00:00
|
|
|
}
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
PreviewRefresh();
|
2022-05-09 13:41:00 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
if( !out.Write( m_textOutput->GetValue() ) )
|
2023-03-08 19:31:51 +00:00
|
|
|
{
|
2023-10-06 11:50:59 +00:00
|
|
|
msg.Printf( _( "Could not write BOM output '%s'." ), outputFile.GetFullPath() );
|
|
|
|
DisplayError( this, msg );
|
2023-03-08 19:31:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.Printf( _( "Wrote BOM output to '%s'" ), outputFile.GetFullPath() );
|
|
|
|
DisplayInfoMessage( this, msg );
|
2022-05-09 13:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-27 13:13:55 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnCancel( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnOk( wxCommandEvent& aEvent )
|
2018-06-05 19:59:58 +00:00
|
|
|
{
|
2023-09-27 13:13:55 +00:00
|
|
|
TransferDataFromWindow();
|
2018-06-05 19:59:58 +00:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-27 13:13:55 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnClose( wxCloseEvent& aEvent )
|
2018-06-05 19:59:58 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
// This is a cancel, so commit quietly as we're going to throw the results away anyway.
|
|
|
|
m_grid->CommitPendingChanges( true );
|
2018-06-05 19:59:58 +00:00
|
|
|
|
|
|
|
if( m_dataModel->IsEdited() )
|
|
|
|
{
|
2020-08-10 20:48:26 +00:00
|
|
|
if( !HandleUnsavedChanges( this, _( "Save changes?" ),
|
2021-10-01 20:49:14 +00:00
|
|
|
[&]() -> bool
|
2020-12-12 14:59:48 +00:00
|
|
|
{
|
|
|
|
return TransferDataFromWindow();
|
|
|
|
} ) )
|
2018-06-05 19:59:58 +00:00
|
|
|
{
|
2023-09-27 13:13:55 +00:00
|
|
|
aEvent.Veto();
|
2018-08-11 20:46:03 +00:00
|
|
|
return;
|
2018-06-05 19:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-11 20:46:03 +00:00
|
|
|
|
2023-08-14 14:41:28 +00:00
|
|
|
// Stop listening to schematic events
|
|
|
|
m_parent->Schematic().RemoveListener( this );
|
|
|
|
|
|
|
|
// Save all our settings since we're really closing
|
|
|
|
savePresetsToSchematic();
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
|
|
|
|
|
|
|
cfg->m_FieldEditorPanel.width = GetSize().x;
|
|
|
|
cfg->m_FieldEditorPanel.height = GetSize().y;
|
|
|
|
cfg->m_FieldEditorPanel.page = m_nbPages->GetSelection();
|
|
|
|
cfg->m_FieldEditorPanel.export_filename = m_outputFileName->GetValue();
|
2023-08-23 16:40:10 +00:00
|
|
|
|
|
|
|
if( m_radioHighlight->GetValue() )
|
|
|
|
cfg->m_FieldEditorPanel.selection_mode = 0;
|
2023-10-16 17:41:35 +00:00
|
|
|
else if( m_radioSelect->GetValue() )
|
2023-08-23 16:40:10 +00:00
|
|
|
cfg->m_FieldEditorPanel.selection_mode = 1;
|
|
|
|
else if( m_radioOff->GetValue() )
|
|
|
|
cfg->m_FieldEditorPanel.selection_mode = 2;
|
|
|
|
|
|
|
|
if( m_radioProject->GetValue() )
|
|
|
|
cfg->m_FieldEditorPanel.scope = SCOPE::SCOPE_ALL;
|
|
|
|
else if( m_radioCurrentSheet->GetValue() )
|
|
|
|
cfg->m_FieldEditorPanel.scope = SCOPE::SCOPE_SHEET;
|
|
|
|
else if( m_radioRecursive->GetValue() )
|
|
|
|
cfg->m_FieldEditorPanel.scope = SCOPE::SCOPE_SHEET_RECURSIVE;
|
2023-08-14 14:41:28 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < m_grid->GetNumberCols(); i++ )
|
|
|
|
{
|
|
|
|
if( m_grid->IsColShown( i ) )
|
|
|
|
{
|
|
|
|
std::string fieldName( m_dataModel->GetColFieldName( i ).ToUTF8() );
|
|
|
|
cfg->m_FieldEditorPanel.field_widths[fieldName] = m_grid->GetColSize( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_parent->FocusOnItem( nullptr );
|
|
|
|
|
|
|
|
wxCommandEvent* evt = new wxCommandEvent( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxID_ANY );
|
|
|
|
|
|
|
|
wxWindow* parent = GetParent();
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
wxQueueEvent( parent, evt );
|
2018-06-05 19:59:58 +00:00
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::vector<BOM_PRESET> DIALOG_SYMBOL_FIELDS_TABLE::GetUserBomPresets() const
|
|
|
|
{
|
|
|
|
std::vector<BOM_PRESET> ret;
|
|
|
|
|
|
|
|
for( const std::pair<const wxString, BOM_PRESET>& pair : m_bomPresets )
|
|
|
|
{
|
|
|
|
if( !pair.second.readOnly )
|
|
|
|
ret.emplace_back( pair.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::SetUserBomPresets( std::vector<BOM_PRESET>& aPresetList )
|
|
|
|
{
|
|
|
|
// Reset to defaults
|
|
|
|
loadDefaultBomPresets();
|
|
|
|
|
|
|
|
for( const BOM_PRESET& preset : aPresetList )
|
|
|
|
{
|
|
|
|
if( m_bomPresets.count( preset.name ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_bomPresets[preset.name] = preset;
|
|
|
|
|
|
|
|
m_bomPresetMRU.Add( preset.name );
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuildBomPresetsWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ApplyBomPreset( const wxString& aPresetName )
|
|
|
|
{
|
|
|
|
updateBomPresetSelection( aPresetName );
|
|
|
|
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
onBomPresetChanged( dummy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ApplyBomPreset( const BOM_PRESET& aPreset )
|
|
|
|
{
|
|
|
|
if( m_bomPresets.count( aPreset.name ) )
|
|
|
|
m_currentBomPreset = &m_bomPresets[aPreset.name];
|
|
|
|
else
|
|
|
|
m_currentBomPreset = nullptr;
|
|
|
|
|
|
|
|
m_lastSelectedBomPreset =
|
|
|
|
( m_currentBomPreset && !m_currentBomPreset->readOnly ) ? m_currentBomPreset : nullptr;
|
|
|
|
|
|
|
|
updateBomPresetSelection( aPreset.name );
|
|
|
|
doApplyBomPreset( aPreset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::loadDefaultBomPresets()
|
|
|
|
{
|
|
|
|
m_bomPresets.clear();
|
|
|
|
m_bomPresetMRU.clear();
|
|
|
|
|
|
|
|
// Load the read-only defaults
|
2023-09-20 14:54:37 +00:00
|
|
|
for( const BOM_PRESET& preset : BOM_PRESET::BuiltInPresets() )
|
2023-02-09 20:13:05 +00:00
|
|
|
{
|
|
|
|
m_bomPresets[preset.name] = preset;
|
|
|
|
m_bomPresets[preset.name].readOnly = true;
|
|
|
|
|
|
|
|
m_bomPresetMRU.Add( preset.name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::rebuildBomPresetsWidget()
|
|
|
|
{
|
|
|
|
m_cbBomPresets->Clear();
|
|
|
|
|
|
|
|
// Build the layers preset list.
|
|
|
|
// By default, the presetAllLayers will be selected
|
|
|
|
int idx = 0;
|
|
|
|
int default_idx = 0;
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_PRESET>& pair : m_bomPresets )
|
|
|
|
{
|
|
|
|
m_cbBomPresets->Append( wxGetTranslation( pair.first ),
|
|
|
|
static_cast<void*>( &pair.second ) );
|
|
|
|
|
2023-03-27 20:48:37 +00:00
|
|
|
if( pair.first == BOM_PRESET::GroupedByValue().name )
|
2023-02-09 20:13:05 +00:00
|
|
|
default_idx = idx;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cbBomPresets->Append( wxT( "---" ) );
|
|
|
|
m_cbBomPresets->Append( _( "Save preset..." ) );
|
|
|
|
m_cbBomPresets->Append( _( "Delete preset..." ) );
|
|
|
|
|
|
|
|
// At least the built-in presets should always be present
|
|
|
|
wxASSERT( !m_bomPresets.empty() );
|
|
|
|
|
|
|
|
// Default preset: all Boms
|
|
|
|
m_cbBomPresets->SetSelection( default_idx );
|
|
|
|
m_currentBomPreset = static_cast<BOM_PRESET*>( m_cbBomPresets->GetClientData( default_idx ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::syncBomPresetSelection()
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
BOM_PRESET current = m_dataModel->GetBomSettings();
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
auto it = std::find_if( m_bomPresets.begin(), m_bomPresets.end(),
|
|
|
|
[&]( const std::pair<const wxString, BOM_PRESET>& aPair )
|
|
|
|
{
|
2023-03-27 20:48:37 +00:00
|
|
|
const BOM_PRESET& preset = aPair.second;
|
|
|
|
|
|
|
|
// Check the simple settings first
|
|
|
|
if( !( preset.sortField == current.sortField
|
|
|
|
&& preset.sortAsc == current.sortAsc
|
|
|
|
&& preset.filterString == current.filterString
|
2023-04-01 12:57:59 +00:00
|
|
|
&& preset.groupSymbols == current.groupSymbols
|
|
|
|
&& preset.excludeDNP == current.excludeDNP ) )
|
2023-03-27 20:48:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Only compare shown or grouped fields
|
|
|
|
std::vector<BOM_FIELD> A, B;
|
|
|
|
|
2023-04-04 14:35:30 +00:00
|
|
|
for( const BOM_FIELD& field : preset.fieldsOrdered )
|
2023-03-27 20:48:37 +00:00
|
|
|
if( field.show || field.groupBy )
|
|
|
|
A.emplace_back( field );
|
|
|
|
|
2023-04-04 14:35:30 +00:00
|
|
|
for( const BOM_FIELD& field : current.fieldsOrdered )
|
2023-03-27 20:48:37 +00:00
|
|
|
if( field.show || field.groupBy )
|
|
|
|
B.emplace_back( field );
|
|
|
|
|
|
|
|
return A == B;
|
2023-02-09 20:13:05 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( it != m_bomPresets.end() )
|
|
|
|
{
|
|
|
|
// Select the right m_cbBomPresets item.
|
|
|
|
// but these items are translated if they are predefined items.
|
|
|
|
bool do_translate = it->second.readOnly;
|
|
|
|
wxString text = do_translate ? wxGetTranslation( it->first ) : it->first;
|
|
|
|
|
|
|
|
m_cbBomPresets->SetStringSelection( text );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cbBomPresets->SetSelection( m_cbBomPresets->GetCount() - 3 ); // separator
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentBomPreset = static_cast<BOM_PRESET*>(
|
|
|
|
m_cbBomPresets->GetClientData( m_cbBomPresets->GetSelection() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::updateBomPresetSelection( const wxString& aName )
|
|
|
|
{
|
|
|
|
// look at m_userBomPresets to know if aName is a read only preset, or a user preset.
|
|
|
|
// Read only presets have translated names in UI, so we have to use
|
|
|
|
// a translated name in UI selection.
|
|
|
|
// But for a user preset name we should search for aName (not translated)
|
|
|
|
wxString ui_label = aName;
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_PRESET>& pair : m_bomPresets )
|
|
|
|
{
|
|
|
|
if( pair.first != aName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pair.second.readOnly == true )
|
|
|
|
ui_label = wxGetTranslation( aName );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = m_cbBomPresets->FindString( ui_label );
|
|
|
|
|
|
|
|
if( idx >= 0 && m_cbBomPresets->GetSelection() != idx )
|
|
|
|
{
|
|
|
|
m_cbBomPresets->SetSelection( idx );
|
|
|
|
m_currentBomPreset = static_cast<BOM_PRESET*>( m_cbBomPresets->GetClientData( idx ) );
|
|
|
|
}
|
|
|
|
else if( idx < 0 )
|
|
|
|
{
|
|
|
|
m_cbBomPresets->SetSelection( m_cbBomPresets->GetCount() - 3 ); // separator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::onBomPresetChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
int count = m_cbBomPresets->GetCount();
|
|
|
|
int index = m_cbBomPresets->GetSelection();
|
|
|
|
|
|
|
|
auto resetSelection =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( m_currentBomPreset )
|
|
|
|
m_cbBomPresets->SetStringSelection( m_currentBomPreset->name );
|
|
|
|
else
|
|
|
|
m_cbBomPresets->SetSelection( m_cbBomPresets->GetCount() - 3 );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( index == count - 3 )
|
|
|
|
{
|
|
|
|
// Separator: reject the selection
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( index == count - 2 )
|
|
|
|
{
|
|
|
|
// Save current state to new preset
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
if( m_lastSelectedBomPreset )
|
|
|
|
name = m_lastSelectedBomPreset->name;
|
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, _( "BOM preset name:" ), _( "Save BOM Preset" ), name );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = dlg.GetValue();
|
|
|
|
bool exists = m_bomPresets.count( name );
|
|
|
|
|
|
|
|
if( !exists )
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
m_bomPresets[name] = m_dataModel->GetBomSettings();
|
2023-03-29 14:53:11 +00:00
|
|
|
m_bomPresets[name].readOnly = false;
|
|
|
|
m_bomPresets[name].name = name;
|
2023-02-09 20:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOM_PRESET* preset = &m_bomPresets[name];
|
|
|
|
|
|
|
|
if( !exists )
|
|
|
|
{
|
|
|
|
index = m_cbBomPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
|
|
|
|
}
|
2023-09-20 13:09:01 +00:00
|
|
|
else if( preset->readOnly )
|
|
|
|
{
|
2023-09-25 11:10:18 +00:00
|
|
|
wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
|
|
|
|
_( "Error" ), wxOK | wxICON_ERROR, this );
|
|
|
|
resetSelection();
|
2023-09-20 13:09:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
else
|
|
|
|
{
|
2023-09-20 13:09:01 +00:00
|
|
|
// Ask the user if they want to overwrite the existing preset
|
2023-09-25 11:10:18 +00:00
|
|
|
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
|
2023-09-20 13:09:01 +00:00
|
|
|
{
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
*preset = m_dataModel->GetBomSettings();
|
2023-03-29 14:53:11 +00:00
|
|
|
preset->name = name;
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
index = m_cbBomPresets->FindString( name );
|
|
|
|
m_bomPresetMRU.Remove( name );
|
|
|
|
}
|
|
|
|
|
2023-09-20 13:09:01 +00:00
|
|
|
m_currentBomPreset = preset;
|
2023-02-09 20:13:05 +00:00
|
|
|
m_cbBomPresets->SetSelection( index );
|
|
|
|
m_bomPresetMRU.Insert( name, 0 );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( index == count - 1 )
|
|
|
|
{
|
|
|
|
// Delete a preset
|
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> items;
|
|
|
|
|
|
|
|
headers.Add( _( "Presets" ) );
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_PRESET>& pair : m_bomPresets )
|
|
|
|
{
|
|
|
|
if( !pair.second.readOnly )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( pair.first );
|
|
|
|
items.emplace_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Delete Preset" ), headers, items );
|
|
|
|
dlg.SetListLabel( _( "Select preset:" ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxString presetName = dlg.GetTextSelection();
|
|
|
|
int idx = m_cbBomPresets->FindString( presetName );
|
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_bomPresets.erase( presetName );
|
|
|
|
|
|
|
|
m_cbBomPresets->Delete( idx );
|
|
|
|
m_currentBomPreset = nullptr;
|
|
|
|
|
|
|
|
m_bomPresetMRU.Remove( presetName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOM_PRESET* preset = static_cast<BOM_PRESET*>( m_cbBomPresets->GetClientData( index ) );
|
|
|
|
m_currentBomPreset = preset;
|
|
|
|
|
|
|
|
m_lastSelectedBomPreset = ( !preset || preset->readOnly ) ? nullptr : preset;
|
|
|
|
|
|
|
|
if( preset )
|
|
|
|
{
|
|
|
|
doApplyBomPreset( *preset );
|
|
|
|
syncBomPresetSelection();
|
|
|
|
m_currentBomPreset = preset;
|
|
|
|
|
|
|
|
if( !m_currentBomPreset->name.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_bomPresetMRU.Remove( preset->name );
|
|
|
|
m_bomPresetMRU.Insert( preset->name, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::doApplyBomPreset( const BOM_PRESET& aPreset )
|
|
|
|
{
|
2023-06-17 16:56:00 +00:00
|
|
|
// Disable rebuilds while we're applying the preset otherwise we'll be
|
|
|
|
// rebuilding the model constantly while firing off wx events
|
|
|
|
m_dataModel->DisableRebuilds();
|
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
// Basically, we apply the BOM preset to the data model and then
|
|
|
|
// update our UI to reflect resulting the data model state, not the preset.
|
|
|
|
m_dataModel->ApplyBomPreset( aPreset );
|
|
|
|
|
|
|
|
// BOM Presets can add, but not remove, columns, so make sure the field control
|
|
|
|
// grid has all of them before starting
|
|
|
|
for( int i = 0; i < m_dataModel->GetColsCount(); i++ )
|
|
|
|
{
|
|
|
|
const wxString& fieldName( m_dataModel->GetColFieldName( i ) );
|
|
|
|
bool found = false;
|
|
|
|
|
2023-04-30 14:53:46 +00:00
|
|
|
for( int j = 0; j < m_fieldsCtrl->GetItemCount(); j++ )
|
2023-03-15 00:03:57 +00:00
|
|
|
{
|
|
|
|
if( m_fieldsCtrl->GetTextValue( j, FIELD_NAME_COLUMN ) == fieldName )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Properties like label, etc. will be added in the next loop
|
|
|
|
if( !found )
|
2023-07-12 15:28:23 +00:00
|
|
|
AddField( fieldName, GetTextVars( fieldName ), false, false );
|
2023-03-15 00:03:57 +00:00
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
// Sync all fields
|
2023-02-09 20:13:05 +00:00
|
|
|
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); i++ )
|
|
|
|
{
|
2023-03-15 00:03:57 +00:00
|
|
|
const wxString& fieldName( m_fieldsCtrl->GetTextValue( i, FIELD_NAME_COLUMN ) );
|
|
|
|
int col = m_dataModel->GetFieldNameCol( fieldName );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
|
|
|
if( col == -1 )
|
2023-03-15 00:03:57 +00:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( true, "Fields control has a field not found in the data model." );
|
2023-02-09 20:13:05 +00:00
|
|
|
continue;
|
2023-03-15 00:03:57 +00:00
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
2023-03-15 00:03:57 +00:00
|
|
|
std::string fieldNameStr( fieldName.ToUTF8() );
|
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
// Set column labels
|
|
|
|
const wxString& label = m_dataModel->GetColLabelValue( col );
|
|
|
|
m_fieldsCtrl->SetTextValue( label, i, LABEL_COLUMN );
|
|
|
|
m_grid->SetColLabelValue( col, label );
|
|
|
|
|
2023-04-19 13:52:31 +00:00
|
|
|
if( cfg->m_FieldEditorPanel.field_widths.count( fieldNameStr ) )
|
2023-06-01 22:02:17 +00:00
|
|
|
m_grid->SetColSize( col, cfg->m_FieldEditorPanel.field_widths.at( fieldNameStr ) );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
// Set shown colums
|
2023-03-15 00:03:57 +00:00
|
|
|
bool show = m_dataModel->GetShowColumn( col );
|
2023-02-09 20:13:05 +00:00
|
|
|
m_fieldsCtrl->SetToggleValue( show, i, SHOW_FIELD_COLUMN );
|
|
|
|
|
|
|
|
if( show )
|
|
|
|
m_grid->ShowCol( col );
|
|
|
|
else
|
|
|
|
m_grid->HideCol( col );
|
|
|
|
|
2023-03-01 15:06:00 +00:00
|
|
|
// Set grouped columns
|
2023-03-15 00:03:57 +00:00
|
|
|
bool groupBy = m_dataModel->GetGroupColumn( col );
|
2023-02-09 20:13:05 +00:00
|
|
|
m_fieldsCtrl->SetToggleValue( groupBy, i, GROUP_BY_COLUMN );
|
|
|
|
}
|
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
m_grid->SetSortingColumn( m_dataModel->GetSortCol(), m_dataModel->GetSortAsc() );
|
|
|
|
m_groupSymbolsBox->SetValue( m_dataModel->GetGroupingEnabled() );
|
|
|
|
m_filter->ChangeValue( m_dataModel->GetFilter() );
|
2023-04-01 12:57:59 +00:00
|
|
|
m_checkExcludeDNP->SetValue( m_dataModel->GetExcludeDNP() );
|
2023-03-01 15:06:00 +00:00
|
|
|
|
2023-08-01 17:28:56 +00:00
|
|
|
SetupAllColumnProperties();
|
2023-03-01 15:06:00 +00:00
|
|
|
|
2023-03-15 00:03:57 +00:00
|
|
|
// This will rebuild all rows and columns in the model such that the order
|
|
|
|
// and labels are right, then we refresh the shown grid data to match
|
2023-06-17 16:56:00 +00:00
|
|
|
m_dataModel->EnableRebuilds();
|
2023-03-01 15:06:00 +00:00
|
|
|
m_dataModel->RebuildRows();
|
|
|
|
m_grid->ForceRefresh();
|
2023-02-09 20:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
std::vector<BOM_FMT_PRESET> DIALOG_SYMBOL_FIELDS_TABLE::GetUserBomFmtPresets() const
|
2023-02-09 20:13:05 +00:00
|
|
|
{
|
2023-03-09 15:54:57 +00:00
|
|
|
std::vector<BOM_FMT_PRESET> ret;
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
for( const std::pair<const wxString, BOM_FMT_PRESET>& pair : m_bomFmtPresets )
|
|
|
|
{
|
|
|
|
if( !pair.second.readOnly )
|
|
|
|
ret.emplace_back( pair.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::SetUserBomFmtPresets( std::vector<BOM_FMT_PRESET>& aPresetList )
|
|
|
|
{
|
|
|
|
// Reset to defaults
|
|
|
|
loadDefaultBomFmtPresets();
|
|
|
|
|
|
|
|
for( const BOM_FMT_PRESET& preset : aPresetList )
|
|
|
|
{
|
|
|
|
if( m_bomFmtPresets.count( preset.name ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_bomFmtPresets[preset.name] = preset;
|
|
|
|
|
|
|
|
m_bomFmtPresetMRU.Add( preset.name );
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuildBomFmtPresetsWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ApplyBomFmtPreset( const wxString& aPresetName )
|
|
|
|
{
|
|
|
|
updateBomFmtPresetSelection( aPresetName );
|
|
|
|
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
onBomFmtPresetChanged( dummy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::ApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset )
|
|
|
|
{
|
|
|
|
if( m_bomFmtPresets.count( aPreset.name ) )
|
|
|
|
m_currentBomFmtPreset = &m_bomFmtPresets[aPreset.name];
|
|
|
|
else
|
|
|
|
m_currentBomFmtPreset = nullptr;
|
|
|
|
|
|
|
|
m_lastSelectedBomFmtPreset = ( m_currentBomFmtPreset && !m_currentBomFmtPreset->readOnly )
|
|
|
|
? m_currentBomFmtPreset
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
updateBomFmtPresetSelection( aPreset.name );
|
|
|
|
doApplyBomFmtPreset( aPreset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::loadDefaultBomFmtPresets()
|
|
|
|
{
|
|
|
|
m_bomFmtPresets.clear();
|
|
|
|
m_bomFmtPresetMRU.clear();
|
|
|
|
|
|
|
|
// Load the read-only defaults
|
2023-09-20 14:54:37 +00:00
|
|
|
for( const BOM_FMT_PRESET& preset : BOM_FMT_PRESET::BuiltInPresets() )
|
2023-03-09 15:54:57 +00:00
|
|
|
{
|
|
|
|
m_bomFmtPresets[preset.name] = preset;
|
|
|
|
m_bomFmtPresets[preset.name].readOnly = true;
|
|
|
|
|
|
|
|
m_bomFmtPresetMRU.Add( preset.name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::rebuildBomFmtPresetsWidget()
|
|
|
|
{
|
|
|
|
m_cbBomFmtPresets->Clear();
|
|
|
|
|
|
|
|
// Build the layers preset list.
|
|
|
|
// By default, the presetAllLayers will be selected
|
|
|
|
int idx = 0;
|
|
|
|
int default_idx = 0;
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_FMT_PRESET>& pair : m_bomFmtPresets )
|
|
|
|
{
|
|
|
|
m_cbBomFmtPresets->Append( wxGetTranslation( pair.first ),
|
|
|
|
static_cast<void*>( &pair.second ) );
|
|
|
|
|
2023-03-27 20:48:37 +00:00
|
|
|
if( pair.first == BOM_FMT_PRESET::CSV().name )
|
2023-03-09 15:54:57 +00:00
|
|
|
default_idx = idx;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cbBomFmtPresets->Append( wxT( "---" ) );
|
|
|
|
m_cbBomFmtPresets->Append( _( "Save preset..." ) );
|
|
|
|
m_cbBomFmtPresets->Append( _( "Delete preset..." ) );
|
|
|
|
|
|
|
|
// At least the built-in presets should always be present
|
|
|
|
wxASSERT( !m_bomFmtPresets.empty() );
|
|
|
|
|
|
|
|
// Default preset: all Boms
|
|
|
|
m_cbBomFmtPresets->SetSelection( default_idx );
|
|
|
|
m_currentBomFmtPreset =
|
|
|
|
static_cast<BOM_FMT_PRESET*>( m_cbBomFmtPresets->GetClientData( default_idx ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::syncBomFmtPresetSelection()
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
BOM_FMT_PRESET current = GetCurrentBomFmtSettings();
|
2023-03-09 15:54:57 +00:00
|
|
|
|
|
|
|
auto it = std::find_if( m_bomFmtPresets.begin(), m_bomFmtPresets.end(),
|
|
|
|
[&]( const std::pair<const wxString, BOM_FMT_PRESET>& aPair )
|
|
|
|
{
|
|
|
|
return ( aPair.second.fieldDelimiter == current.fieldDelimiter
|
|
|
|
&& aPair.second.stringDelimiter == current.stringDelimiter
|
2023-03-15 00:03:57 +00:00
|
|
|
&& aPair.second.refDelimiter == current.refDelimiter
|
|
|
|
&& aPair.second.refRangeDelimiter == current.refRangeDelimiter
|
|
|
|
&& aPair.second.keepTabs == current.keepTabs
|
|
|
|
&& aPair.second.keepLineBreaks == current.keepLineBreaks );
|
2023-03-09 15:54:57 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( it != m_bomFmtPresets.end() )
|
|
|
|
{
|
|
|
|
// Select the right m_cbBomFmtPresets item.
|
|
|
|
// but these items are translated if they are predefined items.
|
|
|
|
bool do_translate = it->second.readOnly;
|
|
|
|
wxString text = do_translate ? wxGetTranslation( it->first ) : it->first;
|
|
|
|
|
|
|
|
m_cbBomFmtPresets->SetStringSelection( text );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cbBomFmtPresets->SetSelection( m_cbBomFmtPresets->GetCount() - 3 ); // separator
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentBomFmtPreset = static_cast<BOM_FMT_PRESET*>(
|
|
|
|
m_cbBomFmtPresets->GetClientData( m_cbBomFmtPresets->GetSelection() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::updateBomFmtPresetSelection( const wxString& aName )
|
|
|
|
{
|
|
|
|
// look at m_userBomFmtPresets to know if aName is a read only preset, or a user preset.
|
|
|
|
// Read only presets have translated names in UI, so we have to use
|
|
|
|
// a translated name in UI selection.
|
|
|
|
// But for a user preset name we should search for aName (not translated)
|
|
|
|
wxString ui_label = aName;
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_FMT_PRESET>& pair : m_bomFmtPresets )
|
|
|
|
{
|
|
|
|
if( pair.first != aName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pair.second.readOnly == true )
|
|
|
|
ui_label = wxGetTranslation( aName );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = m_cbBomFmtPresets->FindString( ui_label );
|
|
|
|
|
|
|
|
if( idx >= 0 && m_cbBomFmtPresets->GetSelection() != idx )
|
|
|
|
{
|
|
|
|
m_cbBomFmtPresets->SetSelection( idx );
|
|
|
|
m_currentBomFmtPreset =
|
|
|
|
static_cast<BOM_FMT_PRESET*>( m_cbBomFmtPresets->GetClientData( idx ) );
|
|
|
|
}
|
|
|
|
else if( idx < 0 )
|
|
|
|
{
|
|
|
|
m_cbBomFmtPresets->SetSelection( m_cbBomFmtPresets->GetCount() - 3 ); // separator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::onBomFmtPresetChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
int count = m_cbBomFmtPresets->GetCount();
|
|
|
|
int index = m_cbBomFmtPresets->GetSelection();
|
|
|
|
|
|
|
|
auto resetSelection =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( m_currentBomFmtPreset )
|
|
|
|
m_cbBomFmtPresets->SetStringSelection( m_currentBomFmtPreset->name );
|
|
|
|
else
|
|
|
|
m_cbBomFmtPresets->SetSelection( m_cbBomFmtPresets->GetCount() - 3 );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( index == count - 3 )
|
|
|
|
{
|
|
|
|
// Separator: reject the selection
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( index == count - 2 )
|
|
|
|
{
|
|
|
|
// Save current state to new preset
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
if( m_lastSelectedBomFmtPreset )
|
|
|
|
name = m_lastSelectedBomFmtPreset->name;
|
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, _( "BOM preset name:" ), _( "Save BOM Preset" ), name );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
{
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = dlg.GetValue();
|
|
|
|
bool exists = m_bomFmtPresets.count( name );
|
|
|
|
|
|
|
|
if( !exists )
|
|
|
|
{
|
2023-04-01 12:57:59 +00:00
|
|
|
m_bomFmtPresets[name] = GetCurrentBomFmtSettings();
|
2023-03-29 14:53:11 +00:00
|
|
|
m_bomFmtPresets[name].readOnly = false;
|
|
|
|
m_bomFmtPresets[name].name = name;
|
2023-03-09 15:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOM_FMT_PRESET* preset = &m_bomFmtPresets[name];
|
|
|
|
|
|
|
|
if( !exists )
|
|
|
|
{
|
|
|
|
index = m_cbBomFmtPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
|
|
|
|
}
|
2023-09-20 13:09:01 +00:00
|
|
|
else if( preset->readOnly )
|
|
|
|
{
|
2023-09-25 11:10:18 +00:00
|
|
|
wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
|
|
|
|
_( "Error" ), wxOK | wxICON_ERROR, this );
|
|
|
|
resetSelection();
|
2023-09-20 13:09:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-09 15:54:57 +00:00
|
|
|
else
|
|
|
|
{
|
2023-09-20 13:09:01 +00:00
|
|
|
// Ask the user if they want to overwrite the existing preset
|
2023-09-25 11:10:18 +00:00
|
|
|
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
|
2023-09-20 13:09:01 +00:00
|
|
|
{
|
|
|
|
resetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-01 12:57:59 +00:00
|
|
|
*preset = GetCurrentBomFmtSettings();
|
2023-03-27 20:48:37 +00:00
|
|
|
preset->name = name;
|
2023-03-09 15:54:57 +00:00
|
|
|
|
|
|
|
index = m_cbBomFmtPresets->FindString( name );
|
|
|
|
m_bomFmtPresetMRU.Remove( name );
|
|
|
|
}
|
|
|
|
|
2023-09-20 13:09:01 +00:00
|
|
|
m_currentBomFmtPreset = preset;
|
2023-03-09 15:54:57 +00:00
|
|
|
m_cbBomFmtPresets->SetSelection( index );
|
|
|
|
m_bomFmtPresetMRU.Insert( name, 0 );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( index == count - 1 )
|
2023-02-09 20:13:05 +00:00
|
|
|
{
|
2023-03-09 15:54:57 +00:00
|
|
|
// Delete a preset
|
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> items;
|
|
|
|
|
|
|
|
headers.Add( _( "Presets" ) );
|
|
|
|
|
|
|
|
for( std::pair<const wxString, BOM_FMT_PRESET>& pair : m_bomFmtPresets )
|
2023-02-09 20:13:05 +00:00
|
|
|
{
|
2023-03-09 15:54:57 +00:00
|
|
|
if( !pair.second.readOnly )
|
2023-02-09 20:13:05 +00:00
|
|
|
{
|
2023-03-09 15:54:57 +00:00
|
|
|
wxArrayString item;
|
|
|
|
item.Add( pair.first );
|
|
|
|
items.emplace_back( item );
|
|
|
|
}
|
|
|
|
}
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Delete Preset" ), headers, items );
|
|
|
|
dlg.SetListLabel( _( "Select preset:" ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxString presetName = dlg.GetTextSelection();
|
|
|
|
int idx = m_cbBomFmtPresets->FindString( presetName );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_bomFmtPresets.erase( presetName );
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
m_cbBomFmtPresets->Delete( idx );
|
|
|
|
m_currentBomFmtPreset = nullptr;
|
2023-02-09 20:13:05 +00:00
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
m_bomFmtPresetMRU.Remove( presetName );
|
2023-02-09 20:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-09 15:54:57 +00:00
|
|
|
|
|
|
|
resetSelection();
|
|
|
|
return;
|
2023-02-09 20:13:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
BOM_FMT_PRESET* preset =
|
|
|
|
static_cast<BOM_FMT_PRESET*>( m_cbBomFmtPresets->GetClientData( index ) );
|
|
|
|
m_currentBomFmtPreset = preset;
|
|
|
|
|
|
|
|
m_lastSelectedBomFmtPreset = ( !preset || preset->readOnly ) ? nullptr : preset;
|
|
|
|
|
|
|
|
if( preset )
|
|
|
|
{
|
|
|
|
doApplyBomFmtPreset( *preset );
|
|
|
|
syncBomFmtPresetSelection();
|
|
|
|
m_currentBomFmtPreset = preset;
|
|
|
|
|
|
|
|
if( !m_currentBomFmtPreset->name.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_bomFmtPresetMRU.Remove( preset->name );
|
|
|
|
m_bomFmtPresetMRU.Insert( preset->name, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::doApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset )
|
|
|
|
{
|
|
|
|
m_textFieldDelimiter->ChangeValue( aPreset.fieldDelimiter );
|
|
|
|
m_textStringDelimiter->ChangeValue( aPreset.stringDelimiter );
|
2023-03-29 14:53:11 +00:00
|
|
|
m_textRefDelimiter->ChangeValue( aPreset.refDelimiter );
|
|
|
|
m_textRefRangeDelimiter->ChangeValue( aPreset.refRangeDelimiter );
|
2023-03-15 00:03:57 +00:00
|
|
|
m_checkKeepTabs->SetValue( aPreset.keepTabs );
|
|
|
|
m_checkKeepLineBreaks->SetValue( aPreset.keepLineBreaks );
|
2023-03-09 15:54:57 +00:00
|
|
|
|
2023-06-17 16:56:00 +00:00
|
|
|
|
|
|
|
// Refresh the preview if that's the current page
|
|
|
|
if( m_nbPages->GetSelection() == 1 )
|
|
|
|
PreviewRefresh();
|
2023-03-29 14:53:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 15:54:57 +00:00
|
|
|
|
2023-03-29 14:53:11 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::savePresetsToSchematic()
|
|
|
|
{
|
|
|
|
// Save our BOM presets
|
|
|
|
std::vector<BOM_PRESET> presets;
|
|
|
|
|
|
|
|
for( const std::pair<const wxString, BOM_PRESET>& pair : m_bomPresets )
|
|
|
|
{
|
|
|
|
if( !pair.second.readOnly )
|
|
|
|
presets.emplace_back( pair.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_schSettings.m_BomPresets = presets;
|
2023-04-01 12:57:59 +00:00
|
|
|
m_schSettings.m_BomSettings = m_dataModel->GetBomSettings();
|
2023-03-29 14:53:11 +00:00
|
|
|
|
|
|
|
// Save our BOM Format presets
|
|
|
|
std::vector<BOM_FMT_PRESET> fmts;
|
|
|
|
|
|
|
|
for( const std::pair<const wxString, BOM_FMT_PRESET>& pair : m_bomFmtPresets )
|
|
|
|
{
|
|
|
|
if( !pair.second.readOnly )
|
|
|
|
fmts.emplace_back( pair.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_schSettings.m_BomFmtPresets = fmts;
|
2023-04-01 12:57:59 +00:00
|
|
|
m_schSettings.m_BomFmtSettings = GetCurrentBomFmtSettings();
|
2023-02-09 20:13:05 +00:00
|
|
|
}
|
2023-08-14 14:41:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsAdded( SCHEMATIC& aSch,
|
|
|
|
std::vector<SCH_ITEM*>& aSchItem )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aSchItem )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
// Add all fields again in case this symbol has a new one
|
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
|
|
|
AddField( field.GetCanonicalName(), field.GetName(), true, false, true );
|
|
|
|
|
2023-08-14 18:19:00 +00:00
|
|
|
m_dataModel->AddReferences( getSymbolReferences( symbol ) );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
std::set<SCH_SYMBOL*> symbols;
|
|
|
|
SCH_REFERENCE_LIST refs = getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) );
|
|
|
|
|
|
|
|
for( SCH_REFERENCE& ref : refs )
|
|
|
|
symbols.insert( ref.GetSymbol() );
|
|
|
|
|
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
|
|
|
{
|
|
|
|
// Add all fields again in case this symbol has a new one
|
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
|
|
|
AddField( field.GetCanonicalName(), field.GetName(), true, false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dataModel->AddReferences( refs );
|
2023-08-14 14:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:55:26 +00:00
|
|
|
DisableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
m_dataModel->RebuildRows();
|
2023-08-21 12:55:26 +00:00
|
|
|
EnableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsRemoved( SCHEMATIC& aSch,
|
|
|
|
std::vector<SCH_ITEM*>& aSchItem )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aSchItem )
|
2023-08-14 18:19:00 +00:00
|
|
|
{
|
2023-08-14 14:41:28 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
m_dataModel->RemoveSymbol( *static_cast<SCH_SYMBOL*>( item ) );
|
2023-08-14 18:19:00 +00:00
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
m_dataModel->RemoveReferences(
|
|
|
|
getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) ) );
|
|
|
|
}
|
2023-08-14 14:41:28 +00:00
|
|
|
|
2023-08-21 12:55:26 +00:00
|
|
|
DisableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
m_dataModel->RebuildRows();
|
2023-08-21 12:55:26 +00:00
|
|
|
EnableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsChanged( SCHEMATIC& aSch,
|
|
|
|
std::vector<SCH_ITEM*>& aSchItem )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aSchItem )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
// Add all fields again in case this symbol has a new one
|
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
|
|
|
AddField( field.GetCanonicalName(), field.GetName(), true, false, true );
|
|
|
|
|
2023-08-14 18:19:00 +00:00
|
|
|
m_dataModel->UpdateReferences( getSymbolReferences( symbol ) );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
std::set<SCH_SYMBOL*> symbols;
|
|
|
|
SCH_REFERENCE_LIST refs = getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) );
|
|
|
|
|
|
|
|
for( SCH_REFERENCE& ref : refs )
|
|
|
|
symbols.insert( ref.GetSymbol() );
|
|
|
|
|
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
|
|
|
{
|
|
|
|
// Add all fields again in case this symbol has a new one
|
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
|
|
|
AddField( field.GetCanonicalName(), field.GetName(), true, false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dataModel->UpdateReferences( refs );
|
2023-08-14 14:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:55:26 +00:00
|
|
|
DisableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
m_dataModel->RebuildRows();
|
2023-08-21 12:55:26 +00:00
|
|
|
EnableSelectionEvents();
|
2023-08-14 14:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 20:13:07 +00:00
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::OnSchSheetChanged( SCHEMATIC& aSch )
|
|
|
|
{
|
|
|
|
m_dataModel->SetPath( aSch.CurrentSheet() );
|
|
|
|
|
|
|
|
if( m_dataModel->GetScope() != FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_ALL )
|
2023-08-21 12:55:26 +00:00
|
|
|
{
|
|
|
|
DisableSelectionEvents();
|
2023-08-20 20:13:07 +00:00
|
|
|
m_dataModel->RebuildRows();
|
2023-08-21 12:55:26 +00:00
|
|
|
EnableSelectionEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::EnableSelectionEvents()
|
|
|
|
{
|
|
|
|
m_grid->Connect(
|
|
|
|
wxEVT_GRID_RANGE_SELECTED,
|
|
|
|
wxGridRangeSelectEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected ),
|
|
|
|
nullptr, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_FIELDS_TABLE::DisableSelectionEvents()
|
|
|
|
{
|
|
|
|
m_grid->Disconnect(
|
|
|
|
wxEVT_GRID_RANGE_SELECTED,
|
|
|
|
wxGridRangeSelectEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected ),
|
|
|
|
nullptr, this );
|
2023-08-20 20:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-14 14:41:28 +00:00
|
|
|
SCH_REFERENCE_LIST DIALOG_SYMBOL_FIELDS_TABLE::getSymbolReferences( SCH_SYMBOL* aSymbol )
|
|
|
|
{
|
2023-08-14 18:19:00 +00:00
|
|
|
SCH_SHEET_LIST allSheets = m_parent->Schematic().GetSheets();
|
2023-08-14 14:41:28 +00:00
|
|
|
SCH_REFERENCE_LIST allRefs;
|
|
|
|
SCH_REFERENCE_LIST symbolRefs;
|
|
|
|
|
2023-08-14 18:19:00 +00:00
|
|
|
allSheets.GetSymbols( allRefs );
|
2023-08-14 14:41:28 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < allRefs.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE& ref = allRefs[i];
|
|
|
|
|
|
|
|
if( ref.GetSymbol() == aSymbol )
|
|
|
|
{
|
|
|
|
ref.Split(); // Figures out if we are annotated or not
|
|
|
|
symbolRefs.AddItem( ref );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return symbolRefs;
|
|
|
|
}
|
2023-08-14 18:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCH_REFERENCE_LIST DIALOG_SYMBOL_FIELDS_TABLE::getSheetSymbolReferences( SCH_SHEET& aSheet )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST allSheets = m_parent->Schematic().GetSheets();
|
|
|
|
SCH_REFERENCE_LIST sheetRefs;
|
|
|
|
|
|
|
|
// We need to operate on all instances of the sheet
|
|
|
|
for( const SCH_SHEET_INSTANCE& instance : aSheet.GetInstances() )
|
|
|
|
{
|
|
|
|
// For every sheet instance we need to get the current schematic sheet
|
|
|
|
// instance that matches that particular sheet path from the root
|
|
|
|
for( SCH_SHEET_PATH& basePath : allSheets )
|
|
|
|
{
|
|
|
|
if( basePath.Path() == instance.m_Path )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = basePath;
|
|
|
|
sheetPath.push_back( &aSheet );
|
|
|
|
|
|
|
|
// Create a list of all sheets in this path, starting with the path
|
|
|
|
// of the sheet that we just deleted, then all of its subsheets
|
|
|
|
SCH_SHEET_LIST subSheets;
|
|
|
|
subSheets.push_back( sheetPath );
|
|
|
|
allSheets.GetSheetsWithinPath( subSheets, sheetPath );
|
|
|
|
|
|
|
|
subSheets.GetSymbolsWithinPath( sheetRefs, sheetPath, false, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_REFERENCE& ref : sheetRefs )
|
|
|
|
ref.Split();
|
|
|
|
|
|
|
|
return sheetRefs;
|
|
|
|
}
|