KiCad PCB EDA Suite
dialog_create_array.cpp File Reference
#include "dialogs/dialog_create_array.h"
#include <base_units.h>
#include <widgets/text_ctrl_eval.h>
#include <board.h>
#include <footprint.h>
#include <pcb_edit_frame.h>
#include <wx/msgdlg.h>
#include <boost/algorithm/string/join.hpp>

Go to the source code of this file.

Classes

struct  CREATE_ARRAY_DIALOG_ENTRIES
 Struct containing the last-entered values for the dialog. More...
 
struct  NUMBERING_LIST_DATA
 Local mapping for list-box <-> numbering type. More...
 

Functions

static bool validateLongEntry (const wxTextEntry &entry, long &dest, const wxString &description, wxArrayString &errors)
 Validate and save a long integer entry. More...
 
static bool validateAxisOptions (const wxTextCtrl &offsetEntry, const wxChoice &typeEntry, const wxTextCtrl &aStepEntry, ARRAY_AXIS &aAxis, wxArrayString &errors)
 Validates and saves (if valid) the type and offset of an array axis numbering. More...
 

Variables

static CREATE_ARRAY_DIALOG_ENTRIES s_arrayOptions
 
static const std::vector< NUMBERING_LIST_DATAnumberingTypeData
 List of type <--> name mappings (in order) for the numbering type list boxes. More...
 

Function Documentation

◆ validateAxisOptions()

static bool validateAxisOptions ( const wxTextCtrl &  offsetEntry,
const wxChoice &  typeEntry,
const wxTextCtrl &  aStepEntry,
ARRAY_AXIS aAxis,
wxArrayString &  errors 
)
static

Validates and saves (if valid) the type and offset of an array axis numbering.

Parameters
offsetEntrythe entry of the offset (text)
typeEntrythe entry of the axis nmbering scheme (choice)
typethe destination of the type if valid
offsetthe destination of the offset if valid
errorserror string accumulator
Returns
if all valid

Definition at line 288 of file dialog_create_array.cpp.

291{
292 void* clientData = typeEntry.GetClientData( typeEntry.GetSelection() );
293 const NUMBERING_LIST_DATA* numberingData = static_cast<NUMBERING_LIST_DATA*>( clientData );
294
295 wxCHECK_MSG( numberingData, false, wxT( "Failed to get client data from list control." ) );
296
297 aAxis.SetAxisType( numberingData->m_numbering_type );
298
299 const wxString text = offsetEntry.GetValue();
300
301 bool ok = aAxis.SetOffset( text );
302
303 if( !ok )
304 {
305 errors.Add( wxString::Format( _( "Could not determine numbering start from '%s': "
306 "expected value consistent with alphabet '%s'." ),
307 text,
308 aAxis.GetAlphabet() ) );
309 return false;
310 }
311
312 long step;
313 ok = validateLongEntry( aStepEntry, step, _( "step value" ), errors );
314
315 if( ok )
316 aAxis.SetStep( step );
317
318 return ok;
319}
bool SetOffset(const wxString &aOffsetName)
Set the axis start (as a string, which should decode to a valid index in the alphabet)
Definition: array_axis.cpp:102
const wxString & GetAlphabet() const
Get the alphabet for the current numbering scheme.
Definition: array_axis.cpp:43
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
void SetStep(int aStep)
Set the skip between consecutive numbers (useful when doing a partial array, e.g.
Definition: array_axis.cpp:127
static bool validateLongEntry(const wxTextEntry &entry, long &dest, const wxString &description, wxArrayString &errors)
Validate and save a long integer entry.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Local mapping for list-box <-> numbering type.
ARRAY_AXIS::NUMBERING_TYPE m_numbering_type

References _, Format(), ARRAY_AXIS::GetAlphabet(), NUMBERING_LIST_DATA::m_numbering_type, ARRAY_AXIS::SetAxisType(), ARRAY_AXIS::SetOffset(), ARRAY_AXIS::SetStep(), text, and validateLongEntry().

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

◆ validateLongEntry()

static bool validateLongEntry ( const wxTextEntry &  entry,
long &  dest,
const wxString &  description,
wxArrayString &  errors 
)
static

Validate and save a long integer entry.

Parameters
entrythe text entry to read from
destthe value destination
descriptiondescription of the field (used if the value is not OK)
errorsa list of errors to add any error to
Returns
valid

Definition at line 261 of file dialog_create_array.cpp.

263{
264 bool ok = true;
265
266 if( !entry.GetValue().ToLong( &dest ) )
267 {
268 wxString err;
269 err.Printf( _( "Bad numeric value for %s: %s" ), description, entry.GetValue() );
270 errors.Add( err );
271 ok = false;
272 }
273
274 return ok;
275}

References _.

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow(), and validateAxisOptions().

Variable Documentation

◆ numberingTypeData

const std::vector<NUMBERING_LIST_DATA> numberingTypeData
static
Initial value:
{
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
_( "Numerals (0,1,2,...,9,10)" ),
},
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_HEX,
_( "Hexadecimal (0,1,...,F,10,...)" ),
},
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_NO_IOSQXZ,
_( "Alphabet, minus IOSQXZ" ),
},
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
_( "Alphabet, full 26 characters" ),
},
}

List of type <--> name mappings (in order) for the numbering type list boxes.

Definition at line 130 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().

◆ s_arrayOptions

CREATE_ARRAY_DIALOG_ENTRIES s_arrayOptions
static

Definition at line 115 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().