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 <class_board.h>
#include <class_module.h>
#include <pcb_edit_frame.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 saved_array_options
 
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 270 of file dialog_create_array.cpp.

272 {
273  const auto* typeData = static_cast<NUMBERING_LIST_DATA*>(
274  typeEntry.GetClientData( typeEntry.GetSelection() ) );
275 
276  wxCHECK_MSG( typeData, false, "Failed to get client data from list control." );
277 
278  aAxis.SetAxisType( typeData->m_numbering_type );
279 
280  const wxString text = offsetEntry.GetValue();
281 
282  bool ok = aAxis.SetOffset( text );
283 
284  if( !ok )
285  {
286  const wxString& alphabet = aAxis.GetAlphabet();
287 
288  wxString err;
289  err.Printf( _( "Could not determine numbering start from \"%s\": "
290  "expected value consistent with alphabet \"%s\"" ),
291  text, alphabet );
292  errors.Add(err);
293  return false;
294  }
295 
296  long step;
297  ok = validateLongEntry( aStepEntry, step, _( "step value" ), errors );
298 
299  if( ok )
300  aAxis.SetStep( step );
301 
302  return ok;
303 }
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)
Definition: 3d_actions.cpp:33
const wxString & GetAlphabet() const
Get the alphabet for the current numbering scheme.
Definition: array_axis.cpp:43

References _, ARRAY_AXIS::GetAlphabet(), ARRAY_AXIS::SetAxisType(), ARRAY_AXIS::SetOffset(), ARRAY_AXIS::SetStep(), 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 243 of file dialog_create_array.cpp.

245 {
246  bool ok = true;
247 
248  if( !entry.GetValue().ToLong( &dest ) )
249  {
250  wxString err;
251  err.Printf( _( "Bad numeric value for %s: %s" ), description, entry.GetValue() );
252  errors.Add( err );
253  ok = false;
254  }
255 
256  return ok;
257 }
#define _(s)
Definition: 3d_actions.cpp:33

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)
Definition: 3d_actions.cpp:33

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

Definition at line 120 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().

◆ saved_array_options

CREATE_ARRAY_DIALOG_ENTRIES saved_array_options
static

Definition at line 105 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY().