2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@verizon.net>
|
2016-01-16 01:55:50 +00:00
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-15 13:25:57 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file dialog_eeschema_options.cpp
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_base_screen.h>
|
2010-01-27 16:35:15 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_eeschema_options.h>
|
2016-01-16 01:56:57 +00:00
|
|
|
#include <widgets/widget_hotkey_list.h>
|
2016-01-16 23:51:38 +00:00
|
|
|
#include "../widgets/widget_eeschema_color_config.h"
|
2016-01-16 02:06:25 +00:00
|
|
|
#include <schframe.h>
|
|
|
|
#include <hotkeys.h>
|
2010-01-27 16:35:15 +00:00
|
|
|
|
2016-01-16 02:06:25 +00:00
|
|
|
#include <wx/settings.h>
|
2010-01-27 16:35:15 +00:00
|
|
|
|
2017-08-06 08:42:11 +00:00
|
|
|
int DIALOG_EESCHEMA_OPTIONS::m_lastPageSelected = 0;
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2016-01-16 01:56:00 +00:00
|
|
|
DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( SCH_EDIT_FRAME* parent ) :
|
2010-01-27 16:35:15 +00:00
|
|
|
DIALOG_EESCHEMA_OPTIONS_BASE( parent )
|
|
|
|
{
|
|
|
|
m_choiceUnits->SetFocus();
|
2014-12-19 15:37:14 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2014-03-07 17:52:43 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
// wxformbuilder doesn't seem to let us set minimal sizes. Copy the default
|
|
|
|
// sizes into the minimal sizes, then, and autosize:
|
|
|
|
for( int i = 0; i < m_fieldGrid->GetNumberCols(); ++i )
|
|
|
|
{
|
|
|
|
m_fieldGrid->SetColMinimalWidth( i, m_fieldGrid->GetColSize( i ) );
|
|
|
|
m_fieldGrid->AutoSizeColLabelSize( i );
|
|
|
|
}
|
2014-09-30 19:55:18 +00:00
|
|
|
|
2016-01-16 01:55:50 +00:00
|
|
|
// Embed the hotkeys list
|
2016-01-16 01:56:57 +00:00
|
|
|
HOTKEY_SECTIONS sections = WIDGET_HOTKEY_LIST::GenSections( g_Eeschema_Hokeys_Descr );
|
2016-01-16 01:58:39 +00:00
|
|
|
m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( m_panelHotkeys, sections );
|
|
|
|
m_hotkeyListCtrl->InstallOnPanel( m_panelHotkeys );
|
2016-01-16 01:55:50 +00:00
|
|
|
|
2016-01-16 23:51:38 +00:00
|
|
|
// Embed the color configurator
|
|
|
|
m_colorConfigCtrl = new WIDGET_EESCHEMA_COLOR_CONFIG( m_panelColors, GetParent() );
|
|
|
|
m_colorConfigCtrl->InstallOnPanel( m_panelColors );
|
|
|
|
|
2017-08-06 08:42:11 +00:00
|
|
|
// Make sure we select the last used tab of the options tab page
|
|
|
|
m_notebook->SetSelection( m_lastPageSelected );
|
2014-10-14 18:52:31 +00:00
|
|
|
|
2016-01-16 01:56:16 +00:00
|
|
|
// Lay out all child pages
|
|
|
|
// No, I don't know why this->Layout() doesn't propagate through to these,
|
|
|
|
// but at least on MSW, it does not.
|
|
|
|
for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
|
|
|
|
{
|
|
|
|
m_notebook->GetPage( i )->Layout();
|
|
|
|
}
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2016-01-16 01:56:16 +00:00
|
|
|
Layout();
|
2016-07-18 07:04:13 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2014-09-30 19:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-16 01:56:00 +00:00
|
|
|
SCH_EDIT_FRAME* DIALOG_EESCHEMA_OPTIONS::GetParent()
|
|
|
|
{
|
|
|
|
return static_cast<SCH_EDIT_FRAME*>( DIALOG_EESCHEMA_OPTIONS_BASE::GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-26 07:11:21 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::SetUnits( const wxArrayString& aUnits, int aSelect )
|
2010-01-27 16:35:15 +00:00
|
|
|
{
|
2017-06-26 07:11:21 +00:00
|
|
|
wxASSERT( aUnits.GetCount() > 0
|
|
|
|
&& ( aSelect >= 0 && (size_t) aSelect < aUnits.GetCount() ) );
|
2010-01-27 16:35:15 +00:00
|
|
|
|
2017-06-26 07:11:21 +00:00
|
|
|
m_choiceUnits->Append( aUnits );
|
|
|
|
m_choiceUnits->SetSelection( aSelect );
|
2010-01-27 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 19:55:18 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::SetRefIdSeparator( wxChar aSep, wxChar aFirstId)
|
|
|
|
{
|
2013-07-19 18:27:22 +00:00
|
|
|
// m_choiceSeparatorRefId displays one of
|
|
|
|
// "A" ".A" "-A" "_A" ".1" "-1" "_1" option
|
2013-05-22 08:45:25 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
int sel = 0;
|
|
|
|
switch( aSep )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
aFirstId = 'A'; // cannot use a number without separator
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
sel = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
sel = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '_':
|
|
|
|
sel = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aFirstId == '1' )
|
|
|
|
sel = 4;
|
|
|
|
|
|
|
|
m_choiceSeparatorRefId->SetSelection( sel );
|
|
|
|
}
|
2013-05-22 08:45:25 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::GetRefIdSeparator( int& aSep, int& aFirstId)
|
|
|
|
{
|
|
|
|
// m_choiceSeparatorRefId displays one of
|
|
|
|
// "A" ".A" "-A" "_A" ".1" "-1" "_1" option
|
|
|
|
|
|
|
|
aFirstId = 'A';
|
|
|
|
switch( m_choiceSeparatorRefId->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: aSep = 0; break;
|
|
|
|
case 1: aSep = '.'; break;
|
|
|
|
case 2: aSep = '-'; break;
|
|
|
|
case 3: aSep = '_'; break;
|
|
|
|
case 4: aFirstId = '1'; aSep = '.'; break;
|
|
|
|
case 5: aFirstId = '1'; aSep = '-'; break;
|
|
|
|
case 6: aFirstId = '1'; aSep = '_'; break;
|
|
|
|
}
|
2013-05-22 08:45:25 +00:00
|
|
|
}
|
2010-01-27 16:35:15 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2014-09-30 19:55:18 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& aGridSizes, int aGridId )
|
2010-01-27 16:35:15 +00:00
|
|
|
{
|
2014-09-30 19:55:18 +00:00
|
|
|
wxASSERT( aGridSizes.size() > 0 );
|
2010-01-27 16:35:15 +00:00
|
|
|
|
|
|
|
int select = wxNOT_FOUND;
|
|
|
|
|
2014-09-30 19:55:18 +00:00
|
|
|
for( size_t i = 0; i < aGridSizes.size(); i++ )
|
2010-01-27 16:35:15 +00:00
|
|
|
{
|
|
|
|
wxString tmp;
|
2014-09-30 19:55:18 +00:00
|
|
|
tmp.Printf( wxT( "%0.1f" ), aGridSizes[i].m_Size.x );
|
2010-01-27 16:35:15 +00:00
|
|
|
m_choiceGridSize->Append( tmp );
|
|
|
|
|
2015-05-12 09:05:36 +00:00
|
|
|
if( aGridSizes[i].m_CmdId == aGridId )
|
2010-01-27 16:35:15 +00:00
|
|
|
select = (int) i;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_choiceGridSize->SetSelection( select );
|
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
|
2014-03-07 17:52:43 +00:00
|
|
|
{
|
2015-12-31 15:12:09 +00:00
|
|
|
// If a single row is selected, insert after that row.
|
|
|
|
int selected_row = -1;
|
|
|
|
int n_found = 0;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
|
2014-09-28 20:37:35 +00:00
|
|
|
{
|
2015-12-31 15:12:09 +00:00
|
|
|
bool this_row_selected = false;
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
|
2014-12-19 15:37:14 +00:00
|
|
|
{
|
2015-12-31 15:12:09 +00:00
|
|
|
if( m_fieldGrid->IsInSelection( row, col ) )
|
|
|
|
this_row_selected = true;
|
|
|
|
}
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
if( this_row_selected )
|
|
|
|
{
|
|
|
|
selected_row = row;
|
|
|
|
++n_found;
|
2014-12-19 15:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
TransferDataFromWindow();
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
TEMPLATE_FIELDNAMES::iterator pos;
|
2014-03-07 17:52:43 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
if( n_found == 1 )
|
|
|
|
pos = templateFields.begin() + selected_row + 1;
|
|
|
|
else
|
|
|
|
pos = templateFields.end();
|
2014-09-16 19:34:52 +00:00
|
|
|
|
2014-09-28 20:37:35 +00:00
|
|
|
// Add a new fieldname to the fieldname list
|
2014-09-29 19:47:25 +00:00
|
|
|
TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
|
|
|
|
newFieldname.m_Value = wxT( "Value" );
|
2014-09-28 20:37:35 +00:00
|
|
|
newFieldname.m_Visible = false;
|
2015-12-31 15:12:09 +00:00
|
|
|
templateFields.insert( pos, newFieldname );
|
|
|
|
TransferDataToWindow();
|
2014-10-14 22:50:47 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2014-09-16 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-29 19:47:25 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2015-12-31 15:12:09 +00:00
|
|
|
// wxGrid has a somewhat complex way of detemining selection.
|
|
|
|
// This is pretty much the easiest way to do it, here.
|
2014-09-29 19:47:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
std::vector<bool> rows_to_delete( templateFields.size(), false );
|
2014-09-29 19:47:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
for( int col = 0; col < m_fieldGrid->GetNumberCols(); ++col )
|
|
|
|
{
|
|
|
|
if( m_fieldGrid->IsInSelection( row, col ) )
|
|
|
|
rows_to_delete[row] = true;
|
|
|
|
}
|
2014-09-29 19:47:25 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
TransferDataFromWindow();
|
2014-12-19 15:37:14 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
int n_rows = m_fieldGrid->GetNumberRows();
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int count = 0; count < n_rows; ++count )
|
|
|
|
{
|
|
|
|
// Iterate backwards, unsigned-friendly way for future
|
|
|
|
int row = n_rows - count - 1;
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
if( rows_to_delete[row] )
|
|
|
|
{
|
|
|
|
templateFields.erase( templateFields.begin() + row );
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 19:34:52 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
TransferDataToWindow();
|
2014-09-28 20:37:35 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2014-09-16 19:34:52 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
bool DIALOG_EESCHEMA_OPTIONS::TransferDataToWindow()
|
2014-12-19 15:37:14 +00:00
|
|
|
{
|
2015-12-31 15:12:09 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
2014-12-19 15:37:14 +00:00
|
|
|
|
2016-01-16 01:55:50 +00:00
|
|
|
if( !m_hotkeyListCtrl->TransferDataToControl() )
|
|
|
|
return false;
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
m_fieldGrid->Freeze();
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
if( m_fieldGrid->GetNumberRows() )
|
|
|
|
m_fieldGrid->DeleteRows( 0, m_fieldGrid->GetNumberRows() );
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
m_fieldGrid->AppendRows( templateFields.size() );
|
2014-12-19 15:37:14 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name );
|
|
|
|
m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value );
|
|
|
|
m_fieldGrid->SetCellValue( row, 2,
|
|
|
|
templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
|
|
|
|
|
|
|
|
// Set cell properties
|
|
|
|
m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
|
|
|
|
m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE );
|
|
|
|
|
|
|
|
// Render the Visible column as a check box
|
|
|
|
m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() );
|
|
|
|
m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
|
|
|
|
m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
|
|
|
|
}
|
2016-01-16 02:06:25 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
m_fieldGrid->AutoSizeRows();
|
|
|
|
m_fieldGrid->Thaw();
|
2014-09-16 19:34:52 +00:00
|
|
|
|
2016-01-16 01:56:16 +00:00
|
|
|
Layout();
|
2015-12-31 15:12:09 +00:00
|
|
|
return true;
|
2014-09-16 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
bool DIALOG_EESCHEMA_OPTIONS::TransferDataFromWindow()
|
2014-09-16 19:34:52 +00:00
|
|
|
{
|
2017-08-06 08:42:11 +00:00
|
|
|
m_lastPageSelected = m_notebook->GetSelection();
|
|
|
|
|
2016-01-16 02:06:25 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
2016-01-16 01:55:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !m_hotkeyListCtrl->TransferDataFromControl() )
|
|
|
|
return false;
|
|
|
|
|
2016-01-21 15:17:55 +00:00
|
|
|
GetParent()->WriteHotkeyConfig( g_Eeschema_Hokeys_Descr );
|
|
|
|
|
2016-01-16 23:51:38 +00:00
|
|
|
if( !m_colorConfigCtrl->TransferDataFromControl() )
|
|
|
|
return false;
|
|
|
|
|
2016-01-16 01:56:23 +00:00
|
|
|
// Refresh hotkeys
|
|
|
|
GetParent()->ReCreateMenuBar();
|
|
|
|
GetParent()->Refresh();
|
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
2016-01-16 02:06:25 +00:00
|
|
|
templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 );
|
2015-12-31 15:12:09 +00:00
|
|
|
templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 );
|
|
|
|
templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString );
|
|
|
|
}
|
2016-01-16 01:56:23 +00:00
|
|
|
|
2015-12-31 15:12:09 +00:00
|
|
|
return true;
|
2014-09-16 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-07 17:52:43 +00:00
|
|
|
void DIALOG_EESCHEMA_OPTIONS::SetTemplateFields( const TEMPLATE_FIELDNAMES& aFields )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2014-09-28 20:37:35 +00:00
|
|
|
// Set the template fields object
|
2014-09-16 19:34:52 +00:00
|
|
|
templateFields = aFields;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2014-12-19 15:37:14 +00:00
|
|
|
// Build and refresh the view
|
2015-12-31 15:12:09 +00:00
|
|
|
TransferDataToWindow();
|
2014-03-07 17:52:43 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2014-03-07 17:52:43 +00:00
|
|
|
|
2014-09-16 19:34:52 +00:00
|
|
|
TEMPLATE_FIELDNAMES DIALOG_EESCHEMA_OPTIONS::GetTemplateFields( void )
|
2014-03-07 17:52:43 +00:00
|
|
|
{
|
2014-09-16 19:34:52 +00:00
|
|
|
return templateFields;
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|