2015-02-12 03:22:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-02-07 12:33:29 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-12 03:22:24 +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
|
|
|
|
*/
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2015-02-12 03:22:24 +00:00
|
|
|
#include <base_units.h>
|
2016-04-02 12:52:29 +00:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2017-11-23 13:05:26 +00:00
|
|
|
#include <widgets/text_ctrl_eval.h>
|
2015-02-12 03:22:24 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
|
|
|
|
#include "dialog_create_array.h"
|
|
|
|
|
2019-01-28 12:05:53 +00:00
|
|
|
/**
|
|
|
|
* Struct containing the last-entered values for the dialog.
|
|
|
|
*/
|
|
|
|
struct CREATE_ARRAY_DIALOG_ENTRIES
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Construct with some sensible defaults.
|
|
|
|
* In future, this could be loaded from config?
|
|
|
|
*/
|
|
|
|
CREATE_ARRAY_DIALOG_ENTRIES()
|
|
|
|
: m_optionsSet( true ),
|
2019-01-28 21:37:36 +00:00
|
|
|
m_gridNx( 5 ),
|
|
|
|
m_gridNy( 5 ),
|
2019-01-28 12:05:53 +00:00
|
|
|
m_gridDx( Millimeter2iu( 2.54 ) ),
|
|
|
|
m_gridDy( Millimeter2iu( 2.54 ) ),
|
|
|
|
m_gridOffsetX( 0 ),
|
|
|
|
m_gridOffsetY( 0 ),
|
2019-01-28 21:37:36 +00:00
|
|
|
m_gridStagger( 1 ),
|
2019-01-28 12:05:53 +00:00
|
|
|
m_gridStaggerType( 0 ), // rows
|
|
|
|
m_gridNumberingAxis( 0 ), // h then v
|
|
|
|
m_gridNumberingReverseAlternate( false ),
|
|
|
|
m_gridNumberingStartSet( 1 ), // use specified start
|
|
|
|
m_grid2dArrayNumbering( 0 ), // linear numbering
|
|
|
|
m_gridPriAxisNumScheme( 0 ), // numeric
|
|
|
|
m_gridSecAxisNumScheme( 0 ), // numeric
|
|
|
|
m_gridPriNumberingOffset( "1" ), // numeric
|
|
|
|
m_gridSecNumberingOffset( "1" ), // numeric
|
|
|
|
m_circCentreX( 0 ),
|
|
|
|
m_circCentreY( 0 ),
|
2019-01-28 21:37:36 +00:00
|
|
|
m_circAngle( 0.0 ),
|
|
|
|
m_circCount( 4 ),
|
2019-01-28 12:05:53 +00:00
|
|
|
m_circNumberingStartSet( 1 ), // use specified start
|
|
|
|
m_circNumberingOffset( "1" ),
|
|
|
|
m_circRotate( false ),
|
|
|
|
m_arrayTypeTab( 0 ) // start on grid view
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool m_optionsSet;
|
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
long m_gridNx, m_gridNy;
|
|
|
|
long m_gridDx, m_gridDy;
|
|
|
|
long m_gridOffsetX, m_gridOffsetY;
|
|
|
|
long m_gridStagger;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
long m_gridStaggerType, m_gridNumberingAxis;
|
2019-01-28 12:05:53 +00:00
|
|
|
bool m_gridNumberingReverseAlternate;
|
2019-01-28 21:37:36 +00:00
|
|
|
long m_gridNumberingStartSet;
|
|
|
|
long m_grid2dArrayNumbering;
|
|
|
|
long m_gridPriAxisNumScheme, m_gridSecAxisNumScheme;
|
2019-01-28 12:05:53 +00:00
|
|
|
wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset;
|
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
long m_circCentreX, m_circCentreY;
|
|
|
|
long m_circAngle;
|
|
|
|
long m_circCount;
|
|
|
|
long m_circNumberingStartSet;
|
2019-01-28 12:05:53 +00:00
|
|
|
wxString m_circNumberingOffset;
|
|
|
|
bool m_circRotate;
|
2019-01-28 21:37:36 +00:00
|
|
|
long m_arrayTypeTab;
|
2019-01-28 12:05:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Persistent options settings
|
|
|
|
static CREATE_ARRAY_DIALOG_ENTRIES saved_array_options;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
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 )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2015-02-12 03:22:24 +00:00
|
|
|
// Set up numbering scheme drop downs
|
2015-04-05 09:52:41 +00:00
|
|
|
//
|
|
|
|
// character set
|
2018-06-14 08:26:11 +00:00
|
|
|
// NOTE: do not change the order of this relative to the NUMBERING_TYPE_T enum
|
2015-04-05 09:52:41 +00:00
|
|
|
const wxString charSetDescriptions[] =
|
|
|
|
{
|
|
|
|
_( "Numerals (0,1,2,...,9,10)" ),
|
|
|
|
_( "Hexadecimal (0,1,...,F,10,...)" ),
|
|
|
|
_( "Alphabet, minus IOSQXZ" ),
|
|
|
|
_( "Alphabet, full 26 characters" )
|
|
|
|
};
|
2019-01-06 16:43:12 +00:00
|
|
|
m_choicePriAxisNumbering->Set( arrayDim( charSetDescriptions ), charSetDescriptions );
|
|
|
|
m_choiceSecAxisNumbering->Set( arrayDim( charSetDescriptions ), charSetDescriptions );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
m_choicePriAxisNumbering->SetSelection( 0 );
|
|
|
|
m_choiceSecAxisNumbering->SetSelection( 0 );
|
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_circAngle.SetUnits( EDA_UNITS_T::DEGREES );
|
|
|
|
|
2019-01-28 12:05:53 +00:00
|
|
|
// bind grid options to persister
|
2019-01-28 21:37:36 +00:00
|
|
|
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 );
|
2019-01-28 12:05:53 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
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 );
|
2019-01-28 12:05:53 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.Add( *m_radioBoxGridStaggerType, saved_array_options.m_gridStaggerType );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.Add( *m_radioBoxGridNumberingAxis, saved_array_options.m_gridNumberingAxis );
|
|
|
|
m_cfg_persister.Add(
|
|
|
|
*m_checkBoxGridReverseNumbering, saved_array_options.m_gridNumberingReverseAlternate );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
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 );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.Add(
|
|
|
|
*m_entryGridPriNumberingOffset, saved_array_options.m_gridPriNumberingOffset );
|
|
|
|
m_cfg_persister.Add(
|
|
|
|
*m_entryGridSecNumberingOffset, saved_array_options.m_gridSecNumberingOffset );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 12:05:53 +00:00
|
|
|
// bind circular options to persister
|
2019-01-28 21:37:36 +00:00
|
|
|
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 );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.Add( *m_rbCircStartNumberingOpt, saved_array_options.m_circNumberingStartSet );
|
|
|
|
m_cfg_persister.Add( *m_entryCircNumberingStart, saved_array_options.m_circNumberingOffset );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.Add( *m_gridTypeNotebook, saved_array_options.m_arrayTypeTab );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.RestoreConfigToControls();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// Run the callbacks once to process the dialog contents
|
2015-02-12 03:22:24 +00:00
|
|
|
setControlEnablement();
|
2015-02-12 03:22:24 +00:00
|
|
|
calculateCircularArrayProperties();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-07-11 23:11:34 +00:00
|
|
|
m_stdButtonsOK->SetDefault();
|
2015-02-12 03:22:24 +00:00
|
|
|
Fit();
|
2015-07-11 23:11:34 +00:00
|
|
|
SetMinSize( GetSize() );
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
DIALOG_CREATE_ARRAY::~DIALOG_CREATE_ARRAY()
|
|
|
|
{
|
|
|
|
if( m_settings != NULL )
|
|
|
|
delete m_settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
void DIALOG_CREATE_ARRAY::OnParameterChanged( wxCommandEvent& event )
|
|
|
|
{
|
2016-03-07 07:13:06 +00:00
|
|
|
setControlEnablement();
|
|
|
|
calculateCircularArrayProperties();
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
/**
|
|
|
|
* Validates and saves (if valid) the type and offset of an array axis numbering
|
|
|
|
*
|
|
|
|
* @param offsetEntry the entry of the offset (text)
|
|
|
|
* @param typeEntry the entry of the axis nmbering scheme (choice)
|
|
|
|
* @param type the destination of the type if valid
|
|
|
|
* @param offset the destination of the offset if valid
|
|
|
|
* @param errors error string accumulator
|
|
|
|
* @return if all valid
|
|
|
|
*/
|
|
|
|
static bool validateNumberingTypeAndOffset( const wxTextCtrl& offsetEntry,
|
|
|
|
const wxChoice& typeEntry,
|
2019-01-24 18:15:21 +00:00
|
|
|
ARRAY_OPTIONS::NUMBERING_TYPE_T& type,
|
2018-06-14 08:26:11 +00:00
|
|
|
int& offset, wxArrayString& errors )
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
const int typeVal = typeEntry.GetSelection();
|
|
|
|
// mind undefined casts to enums (should not be able to happen)
|
2019-01-24 18:15:21 +00:00
|
|
|
bool ok = typeVal <= ARRAY_OPTIONS::NUMBERING_TYPE_MAX;
|
2016-04-02 12:52:29 +00:00
|
|
|
|
|
|
|
if( ok )
|
|
|
|
{
|
2019-01-24 18:15:21 +00:00
|
|
|
type = (ARRAY_OPTIONS::NUMBERING_TYPE_T) typeVal;
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString err;
|
2018-03-09 05:34:57 +00:00
|
|
|
err.Printf( _("Unrecognized numbering scheme: %d"), typeVal );
|
2016-04-02 12:52:29 +00:00
|
|
|
errors.Add( err );
|
|
|
|
// we can't proceed - we don't know the numbering type
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString text = offsetEntry.GetValue();
|
2019-01-24 18:15:21 +00:00
|
|
|
ok = ARRAY_OPTIONS::GetNumberingOffset( text, type, offset );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
|
|
|
if( !ok )
|
|
|
|
{
|
2019-01-24 18:15:21 +00:00
|
|
|
const wxString& alphabet = ARRAY_OPTIONS::AlphabetFromNumberingScheme( type );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
|
|
|
wxString err;
|
|
|
|
err.Printf( _( "Could not determine numbering start from \"%s\": "
|
|
|
|
"expected value consistent with alphabet \"%s\"" ),
|
|
|
|
text, alphabet );
|
|
|
|
errors.Add(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate and save a long integer entry
|
|
|
|
*
|
|
|
|
* @param entry the text entry to read from
|
|
|
|
* @param dest the value destination
|
|
|
|
* @param description description of the field (used if the value is not OK)
|
|
|
|
* @param errors a list of errors to add any error to
|
|
|
|
* @return valid
|
|
|
|
*/
|
2018-06-14 08:26:11 +00:00
|
|
|
static bool validateLongEntry( const wxTextEntry& entry, long& dest, const wxString& description,
|
|
|
|
wxArrayString& errors )
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if( !entry.GetValue().ToLong( &dest ) )
|
|
|
|
{
|
|
|
|
wxString err;
|
2016-04-21 07:19:08 +00:00
|
|
|
err.Printf( _("Bad numeric value for %s: %s"), description, entry.GetValue() );
|
2016-04-02 12:52:29 +00:00
|
|
|
errors.Add( err );
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 21:11:36 +00:00
|
|
|
bool DIALOG_CREATE_ARRAY::TransferDataFromWindow()
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
ARRAY_OPTIONS* newSettings = NULL;
|
|
|
|
wxArrayString errors;
|
2015-02-12 03:22:24 +00:00
|
|
|
const wxWindow* page = m_gridTypeNotebook->GetCurrentPage();
|
|
|
|
|
|
|
|
if( page == m_gridPanel )
|
|
|
|
{
|
|
|
|
ARRAY_GRID_OPTIONS* newGrid = new ARRAY_GRID_OPTIONS();
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
// ints
|
2018-06-14 08:26:11 +00:00
|
|
|
ok = ok && validateLongEntry(*m_entryNx, newGrid->m_nx, _("horizontal count"), errors);
|
|
|
|
ok = ok && validateLongEntry(*m_entryNy, newGrid->m_ny, _("vertical count"), errors);
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
newGrid->m_delta.x = m_hSpacing.GetValue();
|
|
|
|
newGrid->m_delta.y = m_vSpacing.GetValue();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
newGrid->m_offset.x = m_hOffset.GetValue();
|
|
|
|
newGrid->m_offset.y = m_vOffset.GetValue();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
ok = ok && validateLongEntry(*m_entryStagger, newGrid->m_stagger, _("stagger"), errors);
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
newGrid->m_stagger_rows = m_radioBoxGridStaggerType->GetSelection() == 0;
|
|
|
|
|
|
|
|
newGrid->m_horizontalThenVertical = m_radioBoxGridNumberingAxis->GetSelection() == 0;
|
|
|
|
newGrid->m_reverseNumberingAlternate = m_checkBoxGridReverseNumbering->GetValue();
|
|
|
|
|
2019-01-24 18:15:21 +00:00
|
|
|
newGrid->SetShouldNumber( m_numberingEnabled );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
if ( m_numberingEnabled )
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2019-02-07 12:33:29 +00:00
|
|
|
newGrid->SetNumberingStartIsSpecified( m_rbGridStartNumberingOpt->GetSelection() == 1 );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
if( newGrid->GetNumberingStartIsSpecified() )
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
2019-02-07 12:33:29 +00:00
|
|
|
newGrid->m_2dArrayNumbering = m_radioBoxGridNumberingScheme->GetSelection() != 0;
|
|
|
|
|
|
|
|
// validate from the input fields
|
|
|
|
bool numOk = validateNumberingTypeAndOffset( *m_entryGridPriNumberingOffset,
|
|
|
|
*m_choicePriAxisNumbering, newGrid->m_priAxisNumType,
|
|
|
|
newGrid->m_numberingOffsetX, errors );
|
|
|
|
|
|
|
|
if( newGrid->m_2dArrayNumbering )
|
|
|
|
{
|
|
|
|
numOk = validateNumberingTypeAndOffset( *m_entryGridSecNumberingOffset,
|
|
|
|
*m_choiceSecAxisNumbering, newGrid->m_secAxisNumType,
|
|
|
|
newGrid->m_numberingOffsetY, errors )
|
|
|
|
&& numOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = ok && numOk;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// artificial linear numeric scheme from 1
|
|
|
|
newGrid->m_2dArrayNumbering = false;
|
|
|
|
newGrid->m_priAxisNumType = ARRAY_OPTIONS::NUMBERING_TYPE_T::NUMBERING_NUMERIC;
|
|
|
|
newGrid->m_numberingOffsetX = 1; // Start at "1"
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
// Only use settings if all values are good
|
|
|
|
if( ok )
|
|
|
|
newSettings = newGrid;
|
2015-02-21 13:58:39 +00:00
|
|
|
else
|
|
|
|
delete newGrid;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
else if( page == m_circularPanel )
|
|
|
|
{
|
|
|
|
ARRAY_CIRCULAR_OPTIONS* newCirc = new ARRAY_CIRCULAR_OPTIONS();
|
|
|
|
bool ok = true;
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
newCirc->m_centre.x = m_hCentre.GetValue();
|
|
|
|
newCirc->m_centre.y = m_vCentre.GetValue();
|
2015-02-12 03:22:24 +00:00
|
|
|
newCirc->m_angle = DoubleValueFromString( DEGREES, m_entryCircAngle->GetValue() );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
ok = ok && validateLongEntry(*m_entryCircCount, newCirc->m_nPts, _("point count"), errors);
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
newCirc->m_rotateItems = m_entryRotateItemsCb->GetValue();
|
2019-01-24 18:15:21 +00:00
|
|
|
newCirc->SetShouldNumber( m_numberingEnabled );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
|
|
|
if ( m_numberingEnabled )
|
|
|
|
{
|
2019-01-24 18:15:21 +00:00
|
|
|
newCirc->SetNumberingStartIsSpecified( m_rbCircStartNumberingOpt->GetSelection() == 1 );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
if( newCirc->GetNumberingStartIsSpecified() )
|
|
|
|
{
|
|
|
|
newCirc->m_numberingType = ARRAY_OPTIONS::NUMBERING_NUMERIC;
|
|
|
|
|
|
|
|
ok = ok
|
|
|
|
&& validateLongEntry( *m_entryCircNumberingStart, newCirc->m_numberingOffset,
|
|
|
|
_( "numbering start" ), errors );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// artificial linear numeric scheme from 1
|
|
|
|
newCirc->m_numberingOffset = 1; // Start at "1"
|
|
|
|
}
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
// Only use settings if all values are good
|
|
|
|
if( ok )
|
|
|
|
newSettings = newCirc;
|
2015-02-21 13:58:39 +00:00
|
|
|
else
|
|
|
|
delete newCirc;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we got good settings, send them out and finish
|
|
|
|
if( newSettings )
|
|
|
|
{
|
2016-04-02 12:52:29 +00:00
|
|
|
delete m_settings;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
// assign pointer and ownership here
|
2016-04-02 12:52:29 +00:00
|
|
|
m_settings = newSettings;
|
2019-01-28 21:37:36 +00:00
|
|
|
m_cfg_persister.ReadConfigFromControls();
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2018-03-06 21:11:36 +00:00
|
|
|
return true;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
2016-03-07 07:13:06 +00:00
|
|
|
else
|
2016-04-02 12:52:29 +00:00
|
|
|
{
|
|
|
|
wxString errorStr;
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
if( errors.IsEmpty() )
|
2016-04-02 12:52:29 +00:00
|
|
|
errorStr = _("Bad parameters");
|
|
|
|
else
|
2018-06-14 08:26:11 +00:00
|
|
|
errorStr = boost::algorithm::join( errors, "\n" );
|
2016-04-02 12:52:29 +00:00
|
|
|
|
|
|
|
wxMessageBox( errorStr );
|
2018-03-06 21:11:36 +00:00
|
|
|
return false;
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CREATE_ARRAY::setControlEnablement()
|
|
|
|
{
|
2016-04-02 12:52:29 +00:00
|
|
|
if ( m_numberingEnabled )
|
|
|
|
{
|
2019-02-07 12:33:29 +00:00
|
|
|
// If we set the start number, we can set the other options,
|
|
|
|
// otherwise it's a hardcoded linear array
|
2019-01-25 16:28:53 +00:00
|
|
|
const bool use_set_start_grid = m_rbGridStartNumberingOpt->GetSelection() == 1;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
m_radioBoxGridNumberingScheme->Enable( use_set_start_grid );
|
|
|
|
m_labelPriAxisNumbering->Enable( use_set_start_grid );
|
|
|
|
m_choicePriAxisNumbering->Enable( use_set_start_grid );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
// Disable the secondary axis numbering option if the
|
|
|
|
// numbering scheme doesn't have two axes
|
|
|
|
const bool num2d = m_radioBoxGridNumberingScheme->GetSelection() != 0;
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
m_labelSecAxisNumbering->Enable( use_set_start_grid && num2d );
|
|
|
|
m_choiceSecAxisNumbering->Enable( use_set_start_grid && num2d );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-25 16:28:53 +00:00
|
|
|
// We can only set an offset if we're setting the start number
|
|
|
|
m_labelGridNumberingOffset->Enable( use_set_start_grid );
|
|
|
|
m_entryGridPriNumberingOffset->Enable( use_set_start_grid );
|
|
|
|
m_entryGridSecNumberingOffset->Enable( use_set_start_grid && num2d );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2019-01-25 16:28:53 +00:00
|
|
|
// disable the circular number offset in the same way
|
|
|
|
const bool use_set_start_circ = m_rbCircStartNumberingOpt->GetSelection() == 1;
|
|
|
|
m_entryCircNumberingStart->Enable( use_set_start_circ );
|
2016-04-02 12:52:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// grid
|
|
|
|
m_rbGridStartNumberingOpt->Enable( false );
|
|
|
|
m_radioBoxGridNumberingScheme->Enable( false );
|
2019-02-07 12:33:29 +00:00
|
|
|
|
|
|
|
m_labelPriAxisNumbering->Enable( false );
|
|
|
|
m_labelSecAxisNumbering->Enable( false );
|
|
|
|
|
2016-04-02 12:52:29 +00:00
|
|
|
m_choiceSecAxisNumbering->Enable( false );
|
|
|
|
m_choicePriAxisNumbering->Enable( false );
|
2019-02-07 12:33:29 +00:00
|
|
|
|
|
|
|
m_labelGridNumberingOffset->Enable( false );
|
2016-04-02 12:52:29 +00:00
|
|
|
m_entryGridPriNumberingOffset->Enable( false );
|
|
|
|
m_entryGridSecNumberingOffset->Enable( false );
|
|
|
|
|
|
|
|
// circular
|
|
|
|
m_rbCircStartNumberingOpt->Enable( false );
|
|
|
|
m_entryCircNumberingStart->Enable( false );
|
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
void DIALOG_CREATE_ARRAY::calculateCircularArrayProperties()
|
|
|
|
{
|
2019-01-24 18:15:21 +00:00
|
|
|
VECTOR2I centre( m_hCentre.GetValue(), m_vCentre.GetValue() );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-04-22 16:39:49 +00:00
|
|
|
// Find the radius, etc of the circle
|
2015-02-12 03:22:24 +00:00
|
|
|
centre -= m_originalItemPosition;
|
|
|
|
|
2019-01-24 18:15:21 +00:00
|
|
|
m_circRadius.SetValue( int( centre.EuclideanNorm() ) );
|
|
|
|
}
|