* Intermediate changes

This commit is contained in:
Brian Sidebotham 2014-09-30 20:55:18 +01:00
parent 2c476bc780
commit d4b94b9be2
6 changed files with 178 additions and 83 deletions

View File

@ -38,27 +38,44 @@ DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( wxWindow* parent ) :
m_choiceUnits->SetFocus();
m_sdbSizer1OK->SetDefault();
// Setup the wxListCtrl for displaying the template fieldnames
wxListItem col0;
col0.SetId( 0 );
col0.SetText( _( "Field Name" ) );
col0.SetWidth( 150 );
wxListItem col1;
col1.SetId( 1 );
col1.SetText( _( "Default Value" ) );
col1.SetWidth( 250 );
wxListItem col2;
col2.SetId( 2 );
col2.SetText( _( "Visible" ) );
col2.SetWidth( 100 );
templateFieldListCtrl->InsertColumn( 0, col0 );
templateFieldListCtrl->InsertColumn( 1, col1 );
templateFieldListCtrl->InsertColumn( 2, col2 );
templateFieldListCtrl->SetColumnWidth( 0, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
templateFieldListCtrl->SetColumnWidth( 1, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
templateFieldListCtrl->SetColumnWidth( 2, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
// Invalid field selected...
// Invalid field selected and don't ignore selection events because
// they'll be from the user
selectedField = -1;
ignoreSelection = false;
// Make sure we select the first tab of the options tab page
m_notebook1->SetSelection( 0 );
}
void DIALOG_EESCHEMA_OPTIONS::OnSize( wxSizeEvent& event )
{
templateFieldListCtrl->SetColumnWidth( 0, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
templateFieldListCtrl->SetColumnWidth( 1, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
templateFieldListCtrl->SetColumnWidth( 2, templateFieldListCtrl->GetViewRect().GetWidth() / 3 );
/* We're just eves dropping on the event, pass it on... */
event.Skip();
}
@ -71,6 +88,7 @@ void DIALOG_EESCHEMA_OPTIONS::SetUnits( const wxArrayString& units, int select )
m_choiceUnits->SetSelection( select );
}
void DIALOG_EESCHEMA_OPTIONS::SetRefIdSeparator( wxChar aSep, wxChar aFirstId)
{
// m_choiceSeparatorRefId displays one of
@ -123,19 +141,19 @@ void DIALOG_EESCHEMA_OPTIONS::GetRefIdSeparator( int& aSep, int& aFirstId)
}
void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& grid_sizes, int grid_id )
void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GRIDS& aGridSizes, int aGridId )
{
wxASSERT( grid_sizes.size() > 0 );
wxASSERT( aGridSizes.size() > 0 );
int select = wxNOT_FOUND;
for( size_t i = 0; i < grid_sizes.size(); i++ )
for( size_t i = 0; i < aGridSizes.size(); i++ )
{
wxString tmp;
tmp.Printf( wxT( "%0.1f" ), grid_sizes[i].m_Size.x );
tmp.Printf( wxT( "%0.1f" ), aGridSizes[i].m_Size.x );
m_choiceGridSize->Append( tmp );
if( grid_sizes[i].m_Id == grid_id )
if( aGridSizes[i].m_Id == aGridId )
select = (int) i;
}
@ -149,24 +167,30 @@ void DIALOG_EESCHEMA_OPTIONS::RefreshTemplateFieldView( void )
// current template fields
templateFieldListCtrl->DeleteAllItems();
for( TEMPLATE_FIELDNAMES::iterator fld = templateFields.begin(); fld != templateFields.end(); ++fld )
// Loop through the template fieldnames and add then to the list control
for( TEMPLATE_FIELDNAMES::iterator fld = templateFields.begin();
fld != templateFields.end(); ++fld )
{
long itemindex = templateFieldListCtrl->InsertItem( templateFieldListCtrl->GetItemCount(), fld->m_Name );
long itemindex = templateFieldListCtrl->InsertItem(
templateFieldListCtrl->GetItemCount(), fld->m_Name );
templateFieldListCtrl->SetItem( itemindex, 1, fld->m_Value );
templateFieldListCtrl->SetItem( itemindex, 2, ( fld->m_Visible == true ) ? _( "Visible" ) : _( "Hidden" ) );
templateFieldListCtrl->SetItem( itemindex, 2,
( fld->m_Visible == true ) ? _( "Visible" ) : _( "Hidden" ) );
}
}
void DIALOG_EESCHEMA_OPTIONS::SelectTemplateField( int item )
void DIALOG_EESCHEMA_OPTIONS::SelectTemplateField( int aItem )
{
// Only select valid items!
if( ( item < 0 ) || ( item >= templateFieldListCtrl->GetItemCount() ) )
if( ( aItem < 0 ) || ( aItem >= templateFieldListCtrl->GetItemCount() ) )
return;
// Make sure we select the new item
ignoreSelection = true;
templateFieldListCtrl->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
templateFieldListCtrl->SetItemState( aItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
}
@ -194,8 +218,6 @@ void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event )
// Make sure we select the new item
SelectTemplateField( selectedField );
event.Skip();
}
@ -221,8 +243,6 @@ void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event )
// Make sure after the refresh that the selected item is correct
SelectTemplateField( selectedField );
}
event.Skip();
}
void DIALOG_EESCHEMA_OPTIONS::copyPanelToSelected( void )
@ -251,6 +271,8 @@ void DIALOG_EESCHEMA_OPTIONS::copySelectedToPanel( void )
void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldSelected( wxListEvent& event )
{
// If the class has generated the event and asked to ignore it, honour that and reset the
// ignore flag for the next user event.
if( ignoreSelection )
{
ignoreSelection = false;
@ -274,14 +296,6 @@ void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldSelected( wxListEvent& event )
// If an item was selected, make sure we re-select it, or at least the
// same position in the grid
SelectTemplateField( selectedField );
event.Skip();
}
void DIALOG_EESCHEMA_OPTIONS::OnTemplateFieldDeselected( wxListEvent& event )
{
event.Skip();
}

View File

@ -37,36 +37,143 @@
class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE
{
protected:
/** @brief The template fieldnames for this dialog */
TEMPLATE_FIELDNAMES templateFields;
int selectedField = -1;
bool ignoreSelection = false;
/** @brief The current row selected in the template fieldname wxListCtrl which is also in the
edit panel */
int selectedField;
/** @brief Set to true internally when OnTemplateFieldSelected() an event needs to be
ignored */
bool ignoreSelection;
/**
* Function OnAddButtonClick
* Process the wxWidgets @a event produced when the user presses the Add buton for the
* template fieldnames control
*
* @param event The wxWidgets produced event information
*
* Adds a new template fieldname (with default values) to the template fieldnames data
*/
void OnAddButtonClick( wxCommandEvent& event );
/**
* Function OnDeleteButtonClick
* Process the wxWidgets @a event produced when the user presses the Delete button for the
* template fieldnames control
*
* @param event The wxWidgets produced event information
*
* Deletes the selected template fieldname from the template fieldnames data
*/
void OnDeleteButtonClick( wxCommandEvent& event );
/**
* Function OnSize
* Resize any controls that are dynamically sized when the dialog is resized
*/
void OnSize( wxSizeEvent& event );
/**
* Function copyPanelToSelected
* Copies the data from the edit panel to the selected template fieldname
*/
void copyPanelToSelected( void );
/**
* Function copySelectedToPanel
* Copies the data from the selected template fieldname and fills in the edit panel
*/
void copySelectedToPanel( void );
/**
* Function OnTemplateFieldSelected
* Event handler for the wxListCtrl containing the template fieldnames
*
* @param event The event information provided by wxWidgets
*
* Processes data exchange between the edit panel and the selected template fieldname
*/
void OnTemplateFieldSelected( wxListEvent& event );
void OnTemplateFieldDeselected( wxListEvent& event );
/**
* Function RefreshTemplateFieldView
* Refresh the template fieldname wxListCtrl
*
* Deletes all data from the wxListCtrl and then re-polpulates the control with the data in
* the template fieldnames.
*
* Use any time the template field data has changed
*/
void RefreshTemplateFieldView( void );
void SelectTemplateField( int item );
/**
* Function SelectTemplateField
* Selects @a aItem from the wxListCtrl populated with the template fieldnames
*
* @param aItem The item index of the row to be selected
*
* When RefreshTemplateFieldView() is used the selection is lost because all of the items are
* removed from the wxListCtrl and then the control is re-populated. This function can be used
* to re-select an item that was previously selected so that the selection is not lost.
*
* <b>NOTE:</b> This function first sets the ignoreSelection flag before making the selection.
* This means the class can select something in the wxListCtrl without causing further
* selection events.
*/
void SelectTemplateField( int aItem );
public:
DIALOG_EESCHEMA_OPTIONS( wxWindow* parent );
void SetUnits( const wxArrayString& units, int select = 0 );
/**
* Function GetUnitsSelection
* Returns the currently selected grid size in the dialog
*/
int GetUnitsSelection( void ) { return m_choiceUnits->GetSelection(); }
void SetGridSelection( int select ) { m_choiceGridSize->SetSelection( select ); }
/**
* Function SetUnits
* Set the unit options
*
* @param units The array of strings representing the unit options
* @param select The unit to select from the unit options
*
* Appends the @a units options to the list of unit options and selects the @a aSelect option
*/
void SetUnits( const wxArrayString& units, int aSelect = 0 );
/**
* Function GetGridSelection
* Returns the curent grid size selected in the dialog
*/
int GetGridSelection( void ) { return m_choiceGridSize->GetSelection(); }
void SetGridSizes( const GRIDS& grid_sizes, int grid_id );
void SetBusWidth( int aWidth )
{
m_spinBusWidth->SetValue( aWidth );
}
/**
* Function SetGridSizes
* Sets the available grid size choices @a aGridSizes and selectd the current option @a aGridId
*
* @param aGridSizes The grid sizes that are able to be chosen from
* @param aGridId The grid size to select from the grid size options
*/
void SetGridSizes( const GRIDS& aGridSizes, int aGridId );
int GetBusWidth( void )
{
return m_spinBusWidth->GetValue();
}
/**
* Function GetBusWidth
* Get the current bus width setting from the dialog
*/
int GetBusWidth( void ) { return m_spinBusWidth->GetValue(); }
/**
* Function SetBusWidth
* Sets the bus width setting in the dialog
*
* @param aWidth The bus width to set the dialog edit spinbox with
*/
void SetBusWidth( int aWidth ) { m_spinBusWidth->SetValue( aWidth ); }
void SetLineWidth( int aWidth ) { m_spinLineWidth->SetValue( aWidth ); }
int GetLineWidth( void ) { return m_spinLineWidth->GetValue(); }

View File

@ -10,6 +10,7 @@
///////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( DIALOG_EESCHEMA_OPTIONS_BASE, DIALOG_SHIM )
EVT_SIZE( DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnSize )
EVT_CHOICE( wxID_ANY, DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnChooseUnits )
EVT_CHECKBOX( xwID_ANY, DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnMiddleBtnPanEnbl )
EVT_LIST_ITEM_DESELECTED( wxID_ANY, DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnTemplateFieldDeselected )

View File

@ -86,7 +86,7 @@
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnSize">OnSize</event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>

View File

@ -47,6 +47,7 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public DIALOG_SHIM
private:
// Private event handlers
void _wxFB_OnSize( wxSizeEvent& event ){ OnSize( event ); }
void _wxFB_OnChooseUnits( wxCommandEvent& event ){ OnChooseUnits( event ); }
void _wxFB_OnMiddleBtnPanEnbl( wxCommandEvent& event ){ OnMiddleBtnPanEnbl( event ); }
void _wxFB_OnTemplateFieldDeselected( wxListEvent& event ){ OnTemplateFieldDeselected( event ); }
@ -116,6 +117,7 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public DIALOG_SHIM
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void OnSize( wxSizeEvent& event ) { event.Skip(); }
virtual void OnChooseUnits( wxCommandEvent& event ) { event.Skip(); }
virtual void OnMiddleBtnPanEnbl( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTemplateFieldDeselected( wxListEvent& event ) { event.Skip(); }

View File

@ -323,7 +323,7 @@ void SCH_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event )
dlg.SetRepeatVertical( g_RepeatStep.y );
dlg.SetRepeatLabel( g_RepeatDeltaLabel );
dlg.SetAutoSaveInterval( GetAutoSaveInterval() / 60 );
dlg.SetRefIdSeparator( LIB_PART::GetSubpartIdSeparator( ),
dlg.SetRefIdSeparator( LIB_PART::GetSubpartIdSeparator(),
LIB_PART::GetSubpartFirstId() );
dlg.SetShowGrid( IsGridVisible() );
@ -338,16 +338,7 @@ void SCH_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event )
dlg.Fit();
dlg.SetMinSize( dlg.GetSize() );
dlg.SetTemplateFields( m_TemplateFieldNames.GetTemplateFieldNames() );
/*
const TEMPLATE_FIELDNAMES& tfnames = m_TemplateFieldNames.GetTemplateFieldNames();
for( unsigned i=0; i<tfnames.size(); ++i )
{
DBG(printf("dlg.SetFieldName(%d, '%s')\n", i, TO_UTF8( tfnames[i].m_Name) );)
dlg.SetFieldName( i, tfnames[i].m_Name );
}
*/
if( dlg.ShowModal() == wxID_CANCEL )
return;
@ -395,8 +386,6 @@ void SCH_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event )
SetForceHVLines( dlg.GetEnableHVBusOrientation() );
m_showPageLimits = dlg.GetShowPageLimits();
wxString templateFieldName;
// @todo this will change when the template field editor is redone to
// look like the component field property editor, showing visibility and value also
@ -406,26 +395,8 @@ void SCH_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event )
for( TEMPLATE_FIELDNAMES::iterator dlgfld = newFieldNames.begin(); dlgfld != newFieldNames.end(); ++dlgfld )
{
TEMPLATE_FIELDNAME fld = *dlgfld;
/* fld.m_Name = dlgfld->m_Name;
fld.m_Value = dlgfld->m_Value;
fld.m_Visible = dlgfld->m_Visible; */
AddTemplateFieldName( fld );
}
/*
for( int i=0; i<8; ++i ) // no. fields in this dialog window
{
templateFieldName = dlg.GetFieldName( i );
if( !templateFieldName.IsEmpty() )
{
TEMPLATE_FIELDNAME fld( dlg.GetFieldName( i ) );
// @todo set visibility and value also from a better editor
AddTemplateFieldName( fld );
}
}
*/
SaveSettings( config() ); // save values shared by eeschema applications.