diff --git a/eeschema/dialogs/dialog_eeschema_options.cpp b/eeschema/dialogs/dialog_eeschema_options.cpp index 062333c15a..308f51ff56 100644 --- a/eeschema/dialogs/dialog_eeschema_options.cpp +++ b/eeschema/dialogs/dialog_eeschema_options.cpp @@ -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(); } diff --git a/eeschema/dialogs/dialog_eeschema_options.h b/eeschema/dialogs/dialog_eeschema_options.h index fff03c4c52..c1787b4f27 100644 --- a/eeschema/dialogs/dialog_eeschema_options.h +++ b/eeschema/dialogs/dialog_eeschema_options.h @@ -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. + * + * NOTE: 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(); } diff --git a/eeschema/dialogs/dialog_eeschema_options_base.cpp b/eeschema/dialogs/dialog_eeschema_options_base.cpp index b8f6a2ae4e..e9fe31c14d 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.cpp +++ b/eeschema/dialogs/dialog_eeschema_options_base.cpp @@ -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 ) diff --git a/eeschema/dialogs/dialog_eeschema_options_base.fbp b/eeschema/dialogs/dialog_eeschema_options_base.fbp index 75dd865ec8..f65d30dabf 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.fbp +++ b/eeschema/dialogs/dialog_eeschema_options_base.fbp @@ -86,7 +86,7 @@ - + OnSize diff --git a/eeschema/dialogs/dialog_eeschema_options_base.h b/eeschema/dialogs/dialog_eeschema_options_base.h index 6d7f7602d3..07e4c59367 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.h +++ b/eeschema/dialogs/dialog_eeschema_options_base.h @@ -45,16 +45,17 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public DIALOG_SHIM { DECLARE_EVENT_TABLE() 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 ); } void _wxFB_OnTemplateFieldSelected( wxListEvent& event ){ OnTemplateFieldSelected( event ); } void _wxFB_OnAddButtonClick( wxCommandEvent& event ){ OnAddButtonClick( event ); } void _wxFB_OnDeleteButtonClick( wxCommandEvent& event ){ OnDeleteButtonClick( event ); } - - + + protected: enum { @@ -63,7 +64,7 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public DIALOG_SHIM wxID_ADD_FIELD, wxID_DELETE_FIELD }; - + wxNotebook* m_notebook1; wxPanel* m_panel1; wxStaticText* m_staticText2; @@ -114,21 +115,22 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; 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(); } virtual void OnTemplateFieldSelected( wxListEvent& event ) { event.Skip(); } virtual void OnAddButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnDeleteButtonClick( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_EESCHEMA_OPTIONS_BASE(); - + }; #endif //__DIALOG_EESCHEMA_OPTIONS_BASE_H__ diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 3f78ba30a2..64de5fcce0 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -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; im_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.