KiCad PCB EDA Suite
dialog_create_array.cpp File Reference
#include <pcb_edit_frame.h>
#include <base_units.h>
#include <macros.h>
#include <boost/algorithm/string/join.hpp>
#include <widgets/text_ctrl_eval.h>
#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 136 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().

138 {
139  static const wxString alphaNumeric = "0123456789";
140  static const wxString alphaHex = "0123456789ABCDEF";
141  static const wxString alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
142  static const wxString alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY";
143 
144  switch( type )
145  {
146  default:
148  break;
149 
151  return alphaHex;
152 
154  return alphaNoIOSQXZ;
155 
157  return alphaFull;
158  }
159 
160  return alphaNumeric;
161 }
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 175 of file dialog_create_array.cpp.

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

Referenced by validateNumberingTypeAndOffset().

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

References err.

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

270 {
271  bool ok = true;
272 
273  if( !entry.GetValue().ToLong( &dest ) )
274  {
275  wxString err;
276  err.Printf( _("Bad numeric value for %s: %s"), description, entry.GetValue() );
277  errors.Add( err );
278  ok = false;
279  }
280 
281  return ok;
282 }
string & err
Definition: json11.cpp:598
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 216 of file dialog_create_array.cpp.

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

Referenced by DIALOG_CREATE_ARRAY::TransferDataFromWindow().

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