From f85f10930af5a56e91fdb2b2dd073efdbf6f7a3d Mon Sep 17 00:00:00 2001 From: John Beard Date: Mon, 28 Jan 2019 21:37:36 +0000 Subject: [PATCH] Break widget save/restore out to reusable class The CONFIG_SAVE_RESTORE_WINDOW class does not need to be tied to the array dialog, put it in common/widgets. Also do a refactor and tidy-up of the the class, use a union for (slightly) better type-safety and syntax (a variant would be better but that's C++17). Also enable integral field save/restore from text boxes. --- common/CMakeLists.txt | 1 + common/widgets/widget_save_restore.cpp | 169 +++++++++++++++++++++ include/widgets/widget_save_restore.h | 194 +++++++++++++++++++++++++ pcbnew/dialogs/dialog_create_array.cpp | 123 ++++++++-------- pcbnew/dialogs/dialog_create_array.h | 160 +------------------- 5 files changed, 434 insertions(+), 213 deletions(-) create mode 100644 common/widgets/widget_save_restore.cpp create mode 100644 include/widgets/widget_save_restore.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7b77a24149..38ad022778 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -225,6 +225,7 @@ set( COMMON_WIDGET_SRCS widgets/two_column_tree_list.cpp widgets/ui_common.cpp widgets/unit_binder.cpp + widgets/widget_save_restore.cpp widgets/widget_hotkey_list.cpp widgets/wx_grid.cpp ) diff --git a/common/widgets/widget_save_restore.cpp b/common/widgets/widget_save_restore.cpp new file mode 100644 index 0000000000..fef802ed63 --- /dev/null +++ b/common/widgets/widget_save_restore.cpp @@ -0,0 +1,169 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * 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 + */ + +#include + +#include +#include +#include +#include +#include + +#include + + +void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, long& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, double& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, long& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest ) +{ + m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest ); +} + + +void WIDGET_SAVE_RESTORE::ReadConfigFromControls() +{ + for( auto& ctrl : m_ctrls ) + { + switch( ctrl.m_type ) + { + case WIDGET_CTRL_TYPE_T::CHECKBOX: + *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue(); + break; + + case WIDGET_CTRL_TYPE_T::TEXT: + *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue(); + break; + + case WIDGET_CTRL_TYPE_T::TEXT_INTEGER: + ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long ); + break; + + case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE: + ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double ); + break; + + case WIDGET_CTRL_TYPE_T::UNIT_BINDER: + *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue(); + break; + + case WIDGET_CTRL_TYPE_T::CHOICE: + *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection(); + break; + + case WIDGET_CTRL_TYPE_T::RADIOBOX: + *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection(); + break; + + case WIDGET_CTRL_TYPE_T::TAB: + *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection(); + break; + } + } + + m_valid = true; +} + + +void WIDGET_SAVE_RESTORE::RestoreConfigToControls() +{ + if( !m_valid ) + return; + + for( auto& ctrl : m_ctrls ) + { + switch( ctrl.m_type ) + { + case WIDGET_CTRL_TYPE_T::CHECKBOX: + ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool ); + break; + + case WIDGET_CTRL_TYPE_T::TEXT: + ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str ); + break; + + case WIDGET_CTRL_TYPE_T::TEXT_INTEGER: + ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) ); + break; + + case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE: + ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) ); + break; + + case WIDGET_CTRL_TYPE_T::UNIT_BINDER: + ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long ); + break; + + case WIDGET_CTRL_TYPE_T::CHOICE: + ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long ); + break; + + case WIDGET_CTRL_TYPE_T::RADIOBOX: + ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long ); + break; + + case WIDGET_CTRL_TYPE_T::TAB: + ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long ); + break; + } + } +} diff --git a/include/widgets/widget_save_restore.h b/include/widgets/widget_save_restore.h new file mode 100644 index 0000000000..a8b917eab0 --- /dev/null +++ b/include/widgets/widget_save_restore.h @@ -0,0 +1,194 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * 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 + */ + +#ifndef WIDGETS_WIDGET_SAVE_RESTORE__H +#define WIDGETS_WIDGET_SAVE_RESTORE__H + +#include + +class wxCheckBox; +class wxChoice; +class wxNotebook; +class wxRadioBox; +class wxString; +class wxTextCtrl; + +class UNIT_BINDER; + +class WIDGET_SAVE_RESTORE +{ +public: + WIDGET_SAVE_RESTORE( bool& aValidFlag ) : m_valid( aValidFlag ) + { + } + + /** + * Bind a radiobox to a choice. + */ + void Add( wxRadioBox& ctrl, long& dest ); + + /** + * Bind a check box to a binary choice + */ + void Add( wxCheckBox& ctrl, bool& dest ); + + /** + * Bind a text ctrl to a string: the control value is stored directly + * into the string + */ + void Add( wxTextCtrl& ctrl, wxString& dest ); + + /** + * Bind a text ctrl to a integer: the control value is converted to and + * from integer on save/restore. + */ + void Add( wxTextCtrl& ctrl, long& dest ); + + /** + * Bind a text ctrl to a double: the control value is converted to and + * from double on save/restore. + */ + void Add( wxTextCtrl& ctrl, double& dest ); + + /** + * Bind a control managed by a #UNIT_BINDER into a integer + */ + void Add( UNIT_BINDER& ctrl, long& dest ); + + /** + * Bind a choice control into a choice (agnostic to the actual + * meaning of the choice) + */ + void Add( wxChoice& ctrl, long& dest ); + + /** + * Bind a notebook tab choice to an integer + */ + void Add( wxNotebook& ctrl, long& dest ); + + /** + * Read values of all bound controls into the internally-stored + * references to the underlying data. + */ + void ReadConfigFromControls(); + + /** + * Restore the values from the internally-stored references to the underlying + * data to each bound control. + */ + void RestoreConfigToControls(); + +private: + /** + * Recognised parameters types (encodes an implicit widget type, + * data type and appropriate conversion). + */ + enum class WIDGET_CTRL_TYPE_T + { + TEXT, + TEXT_INTEGER, + TEXT_DOUBLE, + UNIT_BINDER, + CHECKBOX, + RADIOBOX, + CHOICE, + TAB + }; + + union CONTROL { + CONTROL( wxCheckBox* aCtrl ) : m_checkbox( aCtrl ) + { + } + + CONTROL( wxChoice* aCtrl ) : m_choice( aCtrl ) + { + } + + CONTROL( wxNotebook* aCtrl ) : m_notebook( aCtrl ) + { + } + + CONTROL( wxRadioBox* aCtrl ) : m_radiobox( aCtrl ) + { + } + + CONTROL( wxTextCtrl* aCtrl ) : m_textctrl( aCtrl ) + { + } + + CONTROL( UNIT_BINDER* aCtrl ) : m_unit_binder( aCtrl ) + { + } + + wxCheckBox* m_checkbox; + wxChoice* m_choice; + wxNotebook* m_notebook; + wxRadioBox* m_radiobox; + wxTextCtrl* m_textctrl; + UNIT_BINDER* m_unit_binder; + }; + + union DATA { + DATA( long* aDest ) : m_long( aDest ) + { + } + + DATA( bool* aDest ) : m_bool( aDest ) + { + } + + DATA( wxString* aDest ) : m_str( aDest ) + { + } + + DATA( double* aDest ) : m_double( aDest ) + { + } + + long* m_long; + bool* m_bool; + wxString* m_str; + double* m_double; + }; + + /** + * Struct that represents a single bound control + */ + struct WIDGET_CTRL_T + { + template + WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) + : m_type( aType ), m_control( &aCtrl ), m_dest( &aDest ) + { + } + + WIDGET_CTRL_TYPE_T m_type; + CONTROL m_control; + DATA m_dest; + }; + + std::vector m_ctrls; + bool& m_valid; +}; + +#endif // WIDGETS_WIDGET_SAVE_RESTORE__H \ No newline at end of file diff --git a/pcbnew/dialogs/dialog_create_array.cpp b/pcbnew/dialogs/dialog_create_array.cpp index a4854e8563..914a40694c 100644 --- a/pcbnew/dialogs/dialog_create_array.cpp +++ b/pcbnew/dialogs/dialog_create_array.cpp @@ -42,13 +42,13 @@ struct CREATE_ARRAY_DIALOG_ENTRIES */ CREATE_ARRAY_DIALOG_ENTRIES() : m_optionsSet( true ), - m_gridNx( "5" ), - m_gridNy( "5" ), + m_gridNx( 5 ), + m_gridNy( 5 ), m_gridDx( Millimeter2iu( 2.54 ) ), m_gridDy( Millimeter2iu( 2.54 ) ), m_gridOffsetX( 0 ), m_gridOffsetY( 0 ), - m_gridStagger( "1" ), + m_gridStagger( 1 ), m_gridStaggerType( 0 ), // rows m_gridNumberingAxis( 0 ), // h then v m_gridNumberingReverseAlternate( false ), @@ -60,8 +60,8 @@ struct CREATE_ARRAY_DIALOG_ENTRIES m_gridSecNumberingOffset( "1" ), // numeric m_circCentreX( 0 ), m_circCentreY( 0 ), - m_circAngle( "0" ), - m_circCount( "4" ), + m_circAngle( 0.0 ), + m_circCount( 4 ), m_circNumberingStartSet( 1 ), // use specified start m_circNumberingOffset( "1" ), m_circRotate( false ), @@ -71,44 +71,46 @@ struct CREATE_ARRAY_DIALOG_ENTRIES bool m_optionsSet; - wxString m_gridNx, m_gridNy; - int m_gridDx, m_gridDy; - int m_gridOffsetX, m_gridOffsetY; - wxString m_gridStagger; + long m_gridNx, m_gridNy; + long m_gridDx, m_gridDy; + long m_gridOffsetX, m_gridOffsetY; + long m_gridStagger; - int m_gridStaggerType, m_gridNumberingAxis; + long m_gridStaggerType, m_gridNumberingAxis; bool m_gridNumberingReverseAlternate; - int m_gridNumberingStartSet; - int m_grid2dArrayNumbering; - int m_gridPriAxisNumScheme, m_gridSecAxisNumScheme; + long m_gridNumberingStartSet; + long m_grid2dArrayNumbering; + long m_gridPriAxisNumScheme, m_gridSecAxisNumScheme; wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset; - int m_circCentreX, m_circCentreY; - wxString m_circAngle, m_circCount; - int m_circNumberingStartSet; + long m_circCentreX, m_circCentreY; + long m_circAngle; + long m_circCount; + long m_circNumberingStartSet; wxString m_circNumberingOffset; bool m_circRotate; - int m_arrayTypeTab; + long m_arrayTypeTab; }; // Persistent options settings static CREATE_ARRAY_DIALOG_ENTRIES saved_array_options; -DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNumbering, - wxPoint aOrigPos ) : - DIALOG_CREATE_ARRAY_BASE( aParent ), - CONFIG_SAVE_RESTORE_WINDOW( saved_array_options.m_optionsSet ), - m_settings( NULL ), - m_hSpacing( aParent, m_labelDx, m_entryDx, m_unitLabelDx ), - m_vSpacing( aParent, m_labelDy, m_entryDy, m_unitLabelDy ), - m_hOffset( aParent, m_labelOffsetX, m_entryOffsetX, m_unitLabelOffsetX ), - m_vOffset( aParent, m_labelOffsetY, m_entryOffsetY, m_unitLabelOffsetY ), - m_hCentre( aParent, m_labelCentreX, m_entryCentreX, m_unitLabelCentreX ), - m_vCentre( aParent, m_labelCentreY, m_entryCentreY, m_unitLabelCentreY ), - m_circRadius( aParent, m_labelCircRadius, m_valueCircRadius, m_unitLabelCircRadius ), - m_originalItemPosition( aOrigPos ), - m_numberingEnabled( enableNumbering ) +DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( + PCB_BASE_FRAME* aParent, bool enableNumbering, wxPoint aOrigPos ) + : DIALOG_CREATE_ARRAY_BASE( aParent ), + m_settings( NULL ), + m_hSpacing( aParent, m_labelDx, m_entryDx, m_unitLabelDx ), + m_vSpacing( aParent, m_labelDy, m_entryDy, m_unitLabelDy ), + m_hOffset( aParent, m_labelOffsetX, m_entryOffsetX, m_unitLabelOffsetX ), + m_vOffset( aParent, m_labelOffsetY, m_entryOffsetY, m_unitLabelOffsetY ), + m_hCentre( aParent, m_labelCentreX, m_entryCentreX, m_unitLabelCentreX ), + m_vCentre( aParent, m_labelCentreY, m_entryCentreY, m_unitLabelCentreY ), + m_circRadius( aParent, m_labelCircRadius, m_valueCircRadius, m_unitLabelCircRadius ), + m_circAngle( aParent, m_labelCircAngle, m_entryCircAngle, m_unitLabelCircAngle ), + m_cfg_persister( saved_array_options.m_optionsSet ), + m_originalItemPosition( aOrigPos ), + m_numberingEnabled( enableNumbering ) { // Set up numbering scheme drop downs // @@ -127,43 +129,48 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNu m_choicePriAxisNumbering->SetSelection( 0 ); m_choiceSecAxisNumbering->SetSelection( 0 ); + m_circAngle.SetUnits( EDA_UNITS_T::DEGREES ); + // bind grid options to persister - Add( m_entryNx, saved_array_options.m_gridNx ); - Add( m_entryNy, saved_array_options.m_gridNy ); - Add( m_hSpacing, saved_array_options.m_gridDx ); - Add( m_vSpacing, saved_array_options.m_gridDy ); + m_cfg_persister.Add( *m_entryNx, saved_array_options.m_gridNx ); + m_cfg_persister.Add( *m_entryNy, saved_array_options.m_gridNy ); + m_cfg_persister.Add( m_hSpacing, saved_array_options.m_gridDx ); + m_cfg_persister.Add( m_vSpacing, saved_array_options.m_gridDy ); - Add( m_hOffset, saved_array_options.m_gridOffsetX ); - Add( m_vOffset, saved_array_options.m_gridOffsetY ); - Add( m_entryStagger, saved_array_options.m_gridStagger ); + m_cfg_persister.Add( m_hOffset, saved_array_options.m_gridOffsetX ); + m_cfg_persister.Add( m_vOffset, saved_array_options.m_gridOffsetY ); + m_cfg_persister.Add( *m_entryStagger, saved_array_options.m_gridStagger ); - Add( m_radioBoxGridStaggerType, saved_array_options.m_gridStaggerType ); + m_cfg_persister.Add( *m_radioBoxGridStaggerType, saved_array_options.m_gridStaggerType ); - Add( m_radioBoxGridNumberingAxis, saved_array_options.m_gridNumberingAxis ); - Add( m_checkBoxGridReverseNumbering, saved_array_options.m_gridNumberingReverseAlternate ); + m_cfg_persister.Add( *m_radioBoxGridNumberingAxis, saved_array_options.m_gridNumberingAxis ); + m_cfg_persister.Add( + *m_checkBoxGridReverseNumbering, saved_array_options.m_gridNumberingReverseAlternate ); - Add( m_rbGridStartNumberingOpt, saved_array_options.m_gridNumberingStartSet ); - Add( m_radioBoxGridNumberingScheme, saved_array_options.m_grid2dArrayNumbering ); - Add( m_choicePriAxisNumbering, saved_array_options.m_gridPriAxisNumScheme ); - Add( m_choiceSecAxisNumbering, saved_array_options.m_gridSecAxisNumScheme ); + m_cfg_persister.Add( *m_rbGridStartNumberingOpt, saved_array_options.m_gridNumberingStartSet ); + m_cfg_persister.Add( + *m_radioBoxGridNumberingScheme, saved_array_options.m_grid2dArrayNumbering ); + m_cfg_persister.Add( *m_choicePriAxisNumbering, saved_array_options.m_gridPriAxisNumScheme ); + m_cfg_persister.Add( *m_choiceSecAxisNumbering, saved_array_options.m_gridSecAxisNumScheme ); - Add( m_entryGridPriNumberingOffset, saved_array_options.m_gridPriNumberingOffset ); - Add( m_entryGridSecNumberingOffset, saved_array_options.m_gridSecNumberingOffset ); + m_cfg_persister.Add( + *m_entryGridPriNumberingOffset, saved_array_options.m_gridPriNumberingOffset ); + m_cfg_persister.Add( + *m_entryGridSecNumberingOffset, saved_array_options.m_gridSecNumberingOffset ); // bind circular options to persister - Add( m_hCentre, saved_array_options.m_circCentreX ); - Add( m_vCentre, saved_array_options.m_circCentreY ); - Add( m_entryCircAngle, saved_array_options.m_circAngle ); - Add( m_entryCircCount, saved_array_options.m_circCount ); - Add( m_entryRotateItemsCb, saved_array_options.m_circRotate ); + m_cfg_persister.Add( m_hCentre, saved_array_options.m_circCentreX ); + m_cfg_persister.Add( m_vCentre, saved_array_options.m_circCentreY ); + m_cfg_persister.Add( m_circAngle, saved_array_options.m_circAngle ); + m_cfg_persister.Add( *m_entryCircCount, saved_array_options.m_circCount ); + m_cfg_persister.Add( *m_entryRotateItemsCb, saved_array_options.m_circRotate ); - Add( m_rbCircStartNumberingOpt, saved_array_options.m_circNumberingStartSet ); - Add( m_entryCircNumberingStart, saved_array_options.m_circNumberingOffset ); + m_cfg_persister.Add( *m_rbCircStartNumberingOpt, saved_array_options.m_circNumberingStartSet ); + m_cfg_persister.Add( *m_entryCircNumberingStart, saved_array_options.m_circNumberingOffset ); - Add( m_gridTypeNotebook, saved_array_options.m_arrayTypeTab ); + m_cfg_persister.Add( *m_gridTypeNotebook, saved_array_options.m_arrayTypeTab ); - - RestoreConfigToControls(); + m_cfg_persister.RestoreConfigToControls(); // Run the callbacks once to process the dialog contents setControlEnablement(); @@ -360,7 +367,7 @@ bool DIALOG_CREATE_ARRAY::TransferDataFromWindow() // assign pointer and ownership here m_settings = newSettings; - ReadConfigFromControls(); + m_cfg_persister.ReadConfigFromControls(); return true; } diff --git a/pcbnew/dialogs/dialog_create_array.h b/pcbnew/dialogs/dialog_create_array.h index fafba57f13..4da7b5088a 100644 --- a/pcbnew/dialogs/dialog_create_array.h +++ b/pcbnew/dialogs/dialog_create_array.h @@ -34,163 +34,10 @@ #include #include - -class CONFIG_SAVE_RESTORE_WINDOW -{ -private: - - enum CONFIG_CTRL_TYPE_T - { - CFG_CTRL_TEXT, - CFG_CTRL_UNIT_BINDER, - CFG_CTRL_CHECKBOX, - CFG_CTRL_RADIOBOX, - CFG_CTRL_CHOICE, - CFG_CTRL_TAB - }; - - struct CONFIG_CTRL_T - { - void* control; - CONFIG_CTRL_TYPE_T type; - void* dest; - }; - - std::vector ctrls; - bool& valid; - -protected: - CONFIG_SAVE_RESTORE_WINDOW( bool& validFlag ) : - valid( validFlag ) - {} - - void Add( wxRadioBox* ctrl, int& dest ) - { - CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_RADIOBOX, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } - - void Add( wxCheckBox* ctrl, bool& dest ) - { - CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHECKBOX, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } - - void Add( wxTextCtrl* ctrl, wxString& dest ) - { - CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TEXT, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } - - void Add( UNIT_BINDER& ctrl, int& dest ) - { - CONFIG_CTRL_T ctrlInfo = { &ctrl, CFG_CTRL_UNIT_BINDER, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } +#include - void Add( wxChoice* ctrl, int& dest ) - { - CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHOICE, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } - - void Add( wxNotebook* ctrl, int& dest ) - { - CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TAB, (void*) &dest }; - - ctrls.push_back( ctrlInfo ); - } - - void ReadConfigFromControls() - { - for( std::vector::const_iterator iter = ctrls.begin(), iend = ctrls.end(); - iter != iend; ++iter ) - { - switch( iter->type ) - { - case CFG_CTRL_CHECKBOX: - *(bool*) iter->dest = static_cast( iter->control )->GetValue(); - break; - - case CFG_CTRL_TEXT: - *(wxString*) iter->dest = static_cast( iter->control )->GetValue(); - break; - - case CFG_CTRL_UNIT_BINDER: - *(int*) iter->dest = static_cast( iter->control )->GetValue(); - break; - - case CFG_CTRL_CHOICE: - *(int*) iter->dest = static_cast( iter->control )->GetSelection(); - break; - - case CFG_CTRL_RADIOBOX: - *(int*) iter->dest = static_cast( iter->control )->GetSelection(); - break; - - case CFG_CTRL_TAB: - *(int*) iter->dest = static_cast( iter->control )->GetSelection(); - break; - - default: - wxASSERT_MSG( false, wxString( - "Unhandled control type for config store: " ) << iter->type ); - } - } - - valid = true; - } - - void RestoreConfigToControls() - { - if( !valid ) - return; - - for( std::vector::const_iterator iter = ctrls.begin(), iend = ctrls.end(); - iter != iend; ++iter ) - { - switch( iter->type ) - { - case CFG_CTRL_CHECKBOX: - static_cast( iter->control )->SetValue( *(bool*) iter->dest ); - break; - - case CFG_CTRL_TEXT: - static_cast( iter->control )->SetValue( *(wxString*) iter->dest ); - break; - - case CFG_CTRL_UNIT_BINDER: - static_cast( iter->control )->SetValue( *(int*) iter->dest ); - break; - - case CFG_CTRL_CHOICE: - static_cast( iter->control )->SetSelection( *(int*) iter->dest ); - break; - - case CFG_CTRL_RADIOBOX: - static_cast( iter->control )->SetSelection( *(int*) iter->dest ); - break; - - case CFG_CTRL_TAB: - static_cast( iter->control )->SetSelection( *(int*) iter->dest ); - break; - - default: - wxASSERT_MSG( false, wxString( - "Unhandled control type for config restore: " ) << iter->type ); - } - } - } -}; - -class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE, - public CONFIG_SAVE_RESTORE_WINDOW +class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE { public: @@ -223,6 +70,9 @@ private: UNIT_BINDER m_hOffset, m_vOffset; UNIT_BINDER m_hCentre, m_vCentre; UNIT_BINDER m_circRadius; + UNIT_BINDER m_circAngle; + + WIDGET_SAVE_RESTORE m_cfg_persister; /* * The position of the original item(s), used for finding radius, etc