KiCad PCB EDA Suite
dialog_create_array.cpp File Reference
#include <wxPcbStruct.h>
#include <base_units.h>
#include <macros.h>
#include <boost/algorithm/string/join.hpp>
#include <class_drawpanel.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::ARRAY_NUMBERING_TYPE_T type)
 
static bool schemeNonUnitColsStartAt0 (DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type)
 
static bool getNumberingOffset (const wxString &str, DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type, int &offsetToFill)
 
static bool validateNumberingTypeAndOffset (const wxTextCtrl &offsetEntry, const wxChoice &typeEntry, DIALOG_CREATE_ARRAY::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::ARRAY_NUMBERING_TYPE_T  type)
static

Definition at line 135 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().

137 {
138  static const wxString alphaNumeric = "0123456789";
139  static const wxString alphaHex = "0123456789ABCDEF";
140  static const wxString alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
141  static const wxString alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY";
142 
143  switch( type )
144  {
145  default:
147  break;
148 
150  return alphaHex;
151 
153  return alphaNoIOSQXZ;
154 
156  return alphaFull;
157  }
158 
159  return alphaNumeric;
160 }
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
static bool getNumberingOffset ( const wxString &  str,
DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T  type,
int &  offsetToFill 
)
static

Definition at line 174 of file dialog_create_array.cpp.

References alphabetFromNumberingScheme(), and schemeNonUnitColsStartAt0().

Referenced by validateNumberingTypeAndOffset().

177 {
178  const wxString alphabet = alphabetFromNumberingScheme( type );
179 
180  int offset = 0;
181  const int radix = alphabet.length();
182 
183  for( unsigned i = 0; i < str.length(); i++ )
184  {
185  int chIndex = alphabet.Find( str[i], false );
186 
187  if( chIndex == wxNOT_FOUND )
188  return false;
189 
190  const bool start0 = schemeNonUnitColsStartAt0( type );
191 
192  // eg "AA" is actually index 27, not 26
193  if( start0 && i < str.length() - 1 )
194  chIndex++;
195 
196  offset *= radix;
197  offset += chIndex;
198  }
199 
200  offsetToFill = offset;
201  return true;
202 }
static bool schemeNonUnitColsStartAt0(DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type)
static const wxString & alphabetFromNumberingScheme(DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type)
static bool schemeNonUnitColsStartAt0 ( DIALOG_CREATE_ARRAY::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 167 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 265 of file dialog_create_array.cpp.

Referenced by DIALOG_CREATE_ARRAY::OnOkClick().

269 {
270  bool ok = true;
271 
272  if( !entry.GetValue().ToLong( &dest ) )
273  {
274  wxString err;
275  err.Printf( _("Bad numeric value for %s: %s"), description, entry.GetValue() );
276  errors.Add( err );
277  ok = false;
278  }
279 
280  return ok;
281 }
static bool validateNumberingTypeAndOffset ( const wxTextCtrl &  offsetEntry,
const wxChoice &  typeEntry,
DIALOG_CREATE_ARRAY::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 215 of file dialog_create_array.cpp.

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

Referenced by DIALOG_CREATE_ARRAY::OnOkClick().

220 {
221  const int typeVal = typeEntry.GetSelection();
222  // mind undefined casts to enums (should not be able to happen)
223  bool ok = typeVal <= DIALOG_CREATE_ARRAY::NUMBERING_TYPE_MAX;
224 
225  if( ok )
226  {
228  }
229  else
230  {
231  wxString err;
232  err.Printf( _("Unrecognised numbering scheme: %d"), typeVal );
233  errors.Add( err );
234  // we can't proceed - we don't know the numbering type
235  return false;
236  }
237 
238  const wxString text = offsetEntry.GetValue();
239  ok = getNumberingOffset( text, type, offset );
240 
241  if( !ok )
242  {
243  const wxString& alphabet = alphabetFromNumberingScheme( type );
244 
245  wxString err;
246  err.Printf( _( "Could not determine numbering start from \"%s\": "
247  "expected value consistent with alphabet \"%s\"" ),
248  text, alphabet );
249  errors.Add(err);
250  }
251 
252  return ok;
253 }
static bool getNumberingOffset(const wxString &str, DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type, int &offsetToFill)
#define NUMBERING_TYPE_MAX
static const wxString & alphabetFromNumberingScheme(DIALOG_CREATE_ARRAY::ARRAY_NUMBERING_TYPE_T type)