KiCad PCB EDA Suite
dialog_create_array.cpp File Reference
#include <pcb_edit_frame.h>
#include <base_units.h>
#include <boost/algorithm/string/join.hpp>
#include <widgets/text_ctrl_eval.h>
#include <class_board.h>
#include <class_module.h>
#include "dialog_create_array.h"

Go to the source code of this file.

Functions

static const wxString & alphabetFromNumberingScheme (DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type)
 
static bool schemeNonUnitColsStartAt0 (DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type)
 
static bool getNumberingOffset (const wxString &str, DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type, int &offsetToFill)
 
static bool validateNumberingTypeAndOffset (const wxTextCtrl &offsetEntry, const wxChoice &typeEntry, DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T &type, int &offset, wxArrayString &errors)
 Validates and saves (if valid) the type and offset of an array axis numbering. More...
 
static bool validateLongEntry (const wxTextEntry &entry, long &dest, const wxString &description, wxArrayString &errors)
 Validate and save a long integer entry. More...
 

Function Documentation

static const wxString& alphabetFromNumberingScheme ( DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T  type)
static

Definition at line 127 of file dialog_create_array.cpp.

References DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_FULL, DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_NO_IOSQXZ, DIALOG_CREATE_ARRAY::NUMBERING_HEX, and DIALOG_CREATE_ARRAY::NUMBERING_NUMERIC.

Referenced by DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::getCoordinateNumber(), getNumberingOffset(), and validateNumberingTypeAndOffset().

128 {
129  static const wxString alphaNumeric = "0123456789";
130  static const wxString alphaHex = "0123456789ABCDEF";
131  static const wxString alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
132  static const wxString alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY";
133 
134  switch( type )
135  {
136  default:
137  case DIALOG_CREATE_ARRAY::NUMBERING_NUMERIC: return alphaNumeric;
138  case DIALOG_CREATE_ARRAY::NUMBERING_HEX: return alphaHex;
139  case DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_NO_IOSQXZ: return alphaNoIOSQXZ;
140  case DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_FULL: return alphaFull;
141  }
142 }
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
static bool getNumberingOffset ( const wxString &  str,
DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T  type,
int &  offsetToFill 
)
static

Definition at line 156 of file dialog_create_array.cpp.

References alphabetFromNumberingScheme(), i, and schemeNonUnitColsStartAt0().

Referenced by validateNumberingTypeAndOffset().

158 {
159  const wxString& alphabet = alphabetFromNumberingScheme( type );
160 
161  int offset = 0;
162  const int radix = alphabet.length();
163 
164  for( unsigned i = 0; i < str.length(); i++ )
165  {
166  int chIndex = alphabet.Find( str[i], false );
167 
168  if( chIndex == wxNOT_FOUND )
169  return false;
170 
171  const bool start0 = schemeNonUnitColsStartAt0( type );
172 
173  // eg "AA" is actually index 27, not 26
174  if( start0 && i < str.length() - 1 )
175  chIndex++;
176 
177  offset *= radix;
178  offset += chIndex;
179  }
180 
181  offsetToFill = offset;
182  return true;
183 }
static bool schemeNonUnitColsStartAt0(DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type)
static const wxString & alphabetFromNumberingScheme(DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type)
const string & str
Definition: json11.cpp:596
size_t i
Definition: json11.cpp:597
static bool schemeNonUnitColsStartAt0 ( DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T  type)
static
Returns
False for schemes like 0,1...9,10 True for schemes like A,B..Z,AA (where the tens column starts with char 0)

Definition at line 149 of file dialog_create_array.cpp.

References DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_FULL, and DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_NO_IOSQXZ.

Referenced by DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::getCoordinateNumber(), and getNumberingOffset().

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

References err.

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

247 {
248  bool ok = true;
249 
250  if( !entry.GetValue().ToLong( &dest ) )
251  {
252  wxString err;
253  err.Printf( _("Bad numeric value for %s: %s"), description, entry.GetValue() );
254  errors.Add( err );
255  ok = false;
256  }
257 
258  return ok;
259 }
string & err
Definition: json11.cpp:598
static bool validateNumberingTypeAndOffset ( const wxTextCtrl &  offsetEntry,
const wxChoice &  typeEntry,
DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type,
int &  offset,
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 196 of file dialog_create_array.cpp.

References alphabetFromNumberingScheme(), err, getNumberingOffset(), and NUMBERING_TYPE_MAX.

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

200 {
201  const int typeVal = typeEntry.GetSelection();
202  // mind undefined casts to enums (should not be able to happen)
203  bool ok = typeVal <= DIALOG_CREATE_ARRAY::NUMBERING_TYPE_MAX;
204 
205  if( ok )
206  {
207  type = (DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T) typeVal;
208  }
209  else
210  {
211  wxString err;
212  err.Printf( _("Unrecognized numbering scheme: %d"), typeVal );
213  errors.Add( err );
214  // we can't proceed - we don't know the numbering type
215  return false;
216  }
217 
218  const wxString text = offsetEntry.GetValue();
219  ok = getNumberingOffset( text, type, offset );
220 
221  if( !ok )
222  {
223  const wxString& alphabet = alphabetFromNumberingScheme( type );
224 
225  wxString err;
226  err.Printf( _( "Could not determine numbering start from \"%s\": "
227  "expected value consistent with alphabet \"%s\"" ),
228  text, alphabet );
229  errors.Add(err);
230  }
231 
232  return ok;
233 }
static const wxString & alphabetFromNumberingScheme(DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type)
static bool getNumberingOffset(const wxString &str, DIALOG_CREATE_ARRAY::NUMBERING_TYPE_T type, int &offsetToFill)
#define NUMBERING_TYPE_MAX
string & err
Definition: json11.cpp:598