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 289 of file dialog_create_array.cpp.

292 {
293  void* clientData = typeEntry.GetClientData( typeEntry.GetSelection() );
294  const NUMBERING_LIST_DATA* numberingData = static_cast<NUMBERING_LIST_DATA*>( clientData );
295 
296  wxCHECK_MSG( numberingData, false, "Failed to get client data from list control." );
297 
298  aAxis.SetAxisType( numberingData->m_numbering_type );
299 
300  const wxString text = offsetEntry.GetValue();
301 
302  bool ok = aAxis.SetOffset( text );
303 
304  if( !ok )
305  {
306  errors.Add( wxString::Format( _( "Could not determine numbering start from '%s': "
307  "expected value consistent with alphabet '%s'." ),
308  text,
309  aAxis.GetAlphabet() ) );
310  return false;
311  }
312 
313  long step;
314  ok = validateLongEntry( aStepEntry, step, _( "step value" ), errors );
315 
316  if( ok )
317  aAxis.SetStep( step );
318 
319  return ok;
320 }
static bool validateLongEntry(const wxTextEntry &entry, long &dest, const wxString &description, wxArrayString &errors)
Validate and save a long integer entry.
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
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
void SetStep(int aStep)
Set the skip between consecutive numbers (useful when doing a partial array, e.g.
Definition: array_axis.cpp:127
#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
const wxString & GetAlphabet() const
Get the alphabet for the current numbering scheme.
Definition: array_axis.cpp:43

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 262 of file dialog_create_array.cpp.

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

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" ),
},
}
#define _(s)

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

Definition at line 131 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 116 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().