KiCad PCB EDA Suite
LEGACY_PLUGIN Class Reference

LEGACY_PLUGIN is a PLUGIN derivation which could possibly be put into a DLL/DSO. More...

#include <legacy_plugin.h>

Inheritance diagram for LEGACY_PLUGIN:
PLUGIN

Public Types

typedef int BIU
 

Public Member Functions

const wxString PluginName () const override
 Function PluginName returns a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
 Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
MODULEFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
long long GetLibraryTimestamp (const wxString &aLibraryPath) const override
 Generate a timestamp representing all the files in the library (including the library directory). More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
 LEGACY_PLUGIN ()
 
 ~LEGACY_PLUGIN ()
 
void SetReader (LINE_READER *aReader)
 
void SetFilePtr (FILE *aFile)
 
void SaveModule3D (const MODULE *aModule) const
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
 Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual const MODULEGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
virtual bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function FootprintExists check for the existence of a footprint. More...
 
virtual void FootprintSave (const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
 Function FootprintSave will write aModule to an existing library located at aLibraryPath. More...
 
virtual void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. More...
 
virtual void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static PCB_LAYER_ID leg_layer2new (int cu_count, LAYER_NUM aLayerNum)
 
static LSET leg_mask2new (int cu_count, unsigned aMask)
 

Protected Member Functions

void init (const PROPERTIES *aProperties)
 initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. More...
 
int getNetCode (int aNetCode)
 

Converts net code using the mapping table if available, otherwise returns unchanged net code

More...
 
BIU biuParse (const char *aValue, const char **nptrptr=NULL)
 Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to the current value of diskToBui. More...
 
double degParse (const char *aValue, const char **nptrptr=NULL)
 Function degParse parses an ASCII decimal floating point value which is certainly an angle. More...
 
void checkVersion ()
 
void loadAllSections (bool doAppend)
 
void loadGENERAL ()
 
void loadSETUP ()
 
void loadSHEET ()
 
void load3D (MODULE *aModule)
 
void loadPAD (MODULE *aModule)
 
void loadMODULE_TEXT (TEXTE_MODULE *aText)
 
void loadMODULE_EDGE (MODULE *aModule)
 
void loadPCB_LINE ()
 
void loadNETINFO_ITEM ()
 
void loadPCB_TEXT ()
 
void loadNETCLASS ()
 
void loadMODULE (MODULE *aModule)
 
void loadTrackList (int aStructType)
 Function loadTrackList reads a list of segments (Tracks and Vias, or Segzones) More...
 
void loadZONE_CONTAINER ()
 
void loadDIMENSION ()
 
void loadPCB_TARGET ()
 
void cacheLib (const wxString &aLibraryPath)
 we only cache one footprint library for now, this determines which one. More...
 

Protected Attributes

int m_cu_count
 
wxString m_error
 for throwing exceptions More...
 
BOARDm_board
 which BOARD, no ownership here More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
LINE_READERm_reader
 no ownership here. More...
 
FILE * m_fp
 no ownership here. More...
 
wxString m_field
 reused to stuff MODULE fields. More...
 
int m_loading_format_version
 which BOARD_FORMAT_VERSION am I Load()ing? More...
 
LP_CACHEm_cache
 
bool m_showLegacyZoneWarning
 
NETINFO_MAPPINGm_mapping
 mapping for net codes, so only not empty nets are stored with consecutive integers as net codes More...
 
std::vector< int > m_netCodes
 net codes mapping for boards being loaded More...
 
double biuToDisk
 convert from BIUs to disk engineering units with this scale factor More...
 
double diskToBiu
 convert from disk engineering units to BIUs with this scale factor More...
 

Friends

struct LP_CACHE
 

Detailed Description

LEGACY_PLUGIN is a PLUGIN derivation which could possibly be put into a DLL/DSO.

As with any PLUGIN, there is no UI, i.e. windowing calls allowed.

Definition at line 65 of file legacy_plugin.h.

Member Typedef Documentation

◆ BIU

typedef int LEGACY_PLUGIN::BIU

Definition at line 101 of file legacy_plugin.h.

Constructor & Destructor Documentation

◆ LEGACY_PLUGIN()

LEGACY_PLUGIN::LEGACY_PLUGIN ( )

Definition at line 3543 of file legacy_plugin.cpp.

3543  :
3544  m_cu_count( 16 ), // for FootprintLoad()
3545  m_board( 0 ),
3546  m_props( 0 ),
3547  m_reader( 0 ),
3548  m_fp( 0 ),
3549  m_cache( 0 ),
3550  m_mapping( new NETINFO_MAPPING() )
3551 {
3552  init( NULL );
3553 }
FILE * m_fp
no ownership here.
LINE_READER * m_reader
no ownership here.
#define NULL
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
BOARD * m_board
which BOARD, no ownership here
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty nets are stored with consecutive integers as net codes
LP_CACHE * m_cache
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.

References init(), and NULL.

◆ ~LEGACY_PLUGIN()

LEGACY_PLUGIN::~LEGACY_PLUGIN ( )

Definition at line 3556 of file legacy_plugin.cpp.

3557 {
3558  delete m_cache;
3559  delete m_mapping;
3560 }
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty nets are stored with consecutive integers as net codes
LP_CACHE * m_cache

References m_cache, and m_mapping.

Member Function Documentation

◆ biuParse()

BIU LEGACY_PLUGIN::biuParse ( const char *  aValue,
const char **  nptrptr = NULL 
)
protected

Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to the current value of diskToBui.

This fuction is the complement of fmtBIU(). One has to know what the other is doing.

Parameters
aValueis the ASCII value in C locale form with possible leading whitespace
nptrptrmay be NULL, but if not, then it tells where to put a pointer to the next unconsumed input text. See "man strtod" for more information.
Returns
BIU - the converted Board Internal Unit.

Definition at line 3031 of file legacy_plugin.cpp.

3032 {
3033  char* nptr;
3034 
3035  errno = 0;
3036 
3037  double fval = strtod( aValue, &nptr );
3038 
3039  if( errno )
3040  {
3041  m_error.Printf( _( "invalid float number in file: \"%s\"\nline: %d, offset: %d" ),
3042  m_reader->GetSource().GetData(),
3043  m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
3044 
3046  }
3047 
3048  if( aValue == nptr )
3049  {
3050  m_error.Printf( _( "missing float number in file: \"%s\"\nline: %d, offset: %d" ),
3051  m_reader->GetSource().GetData(),
3052  m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
3053 
3055  }
3056 
3057  if( nptrptr )
3058  *nptrptr = nptr;
3059 
3060  fval *= diskToBiu;
3061 
3062  // fval is up into the whole number realm here, and should be bounded
3063  // within INT_MIN to INT_MAX since BIU's are nanometers.
3064  return KiROUND( fval );
3065 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
LINE_READER * m_reader
no ownership here.
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
#define THROW_IO_ERROR(msg)
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61

References _, diskToBiu, LINE_READER::GetSource(), KiROUND(), LINE_READER::Line(), LINE_READER::LineNumber(), m_error, m_reader, and THROW_IO_ERROR.

Referenced by loadDIMENSION(), loadGENERAL(), loadMODULE(), loadMODULE_EDGE(), loadMODULE_TEXT(), loadNETCLASS(), loadPAD(), loadPCB_LINE(), loadPCB_TARGET(), loadPCB_TEXT(), loadSETUP(), loadTrackList(), and loadZONE_CONTAINER().

◆ cacheLib()

void LEGACY_PLUGIN::cacheLib ( const wxString &  aLibraryPath)
protected

we only cache one footprint library for now, this determines which one.

Definition at line 3433 of file legacy_plugin.cpp.

3434 {
3435  if( !m_cache || m_cache->m_lib_path != aLibraryPath || m_cache->IsModified() )
3436  {
3437  // a spectacular episode in memory management:
3438  delete m_cache;
3439  m_cache = new LP_CACHE( this, aLibraryPath );
3440  m_cache->Load();
3441  }
3442 }
friend struct LP_CACHE
Definition: legacy_plugin.h:67
bool IsModified()
wxString m_lib_path
LP_CACHE * m_cache

References LP_CACHE::IsModified(), LP_CACHE::Load(), LP_CACHE, m_cache, and LP_CACHE::m_lib_path.

Referenced by FootprintEnumerate(), FootprintLoad(), and IsFootprintLibWritable().

◆ checkVersion()

void LEGACY_PLUGIN::checkVersion ( )
protected

Definition at line 539 of file legacy_plugin.cpp.

540 {
541  // Read first line and TEST if it is a PCB file format header like this:
542  // "PCBNEW-BOARD Version 1 ...."
543 
544  m_reader->ReadLine();
545 
546  char* line = m_reader->Line();
547 
548  if( !TESTLINE( "PCBNEW-BOARD" ) )
549  {
550  THROW_IO_ERROR( "Unknown file type" );
551  }
552 
553  int ver = 1; // if sccanf fails
554  sscanf( line, "PCBNEW-BOARD Version %d", &ver );
555 
556 #if !defined(DEBUG)
557  if( ver > LEGACY_BOARD_FILE_VERSION )
558  {
559  // "File \"%s\" is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file."
561  m_reader->GetSource().GetData(), ver, LEGACY_BOARD_FILE_VERSION );
563  }
564 #endif
565 
568 }
void SetFileFormatVersionAtLoad(int aVersion)
Definition: class_board.h:264
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
LINE_READER * m_reader
no ownership here.
#define THROW_IO_ERROR(msg)
BOARD * m_board
which BOARD, no ownership here
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define VERSION_ERROR_FORMAT
wxString m_error
for throwing exceptions
#define TESTLINE(x)
C string compare test for a specific length of characters.

References LINE_READER::GetSource(), LINE_READER::Line(), m_board, m_error, m_loading_format_version, m_reader, LINE_READER::ReadLine(), BOARD::SetFileFormatVersionAtLoad(), TESTLINE, THROW_IO_ERROR, and VERSION_ERROR_FORMAT.

Referenced by Load().

◆ degParse()

double LEGACY_PLUGIN::degParse ( const char *  aValue,
const char **  nptrptr = NULL 
)
protected

Function degParse parses an ASCII decimal floating point value which is certainly an angle.

This is a dedicated function for encapsulating support for the migration from tenths of degrees to degrees in floating point. This function is the complement of fmtDEG(). One has to know what the other is doing.

Parameters
aValueis the ASCII value in C locale form with possible leading whitespace
nptrptrmay be NULL, but if not, then it tells where to put a pointer to the next unconsumed input text. See "man strtod" for more information.
Returns
double - the string converted to a primitive double type

Definition at line 3068 of file legacy_plugin.cpp.

3069 {
3070  char* nptr;
3071 
3072  errno = 0;
3073 
3074  double fval = strtod( aValue, &nptr );
3075 
3076  if( errno )
3077  {
3078  m_error.Printf( _( "invalid float number in file: \"%s\"\nline: %d, offset: %d" ),
3079  m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
3080 
3082  }
3083 
3084  if( aValue == nptr )
3085  {
3086  m_error.Printf( _( "missing float number in file: \"%s\"\nline: %d, offset: %d" ),
3087  m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
3088 
3090  }
3091 
3092  if( nptrptr )
3093  *nptrptr = nptr;
3094 
3095  return fval;
3096 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
LINE_READER * m_reader
no ownership here.
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
#define THROW_IO_ERROR(msg)
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions

References _, LINE_READER::GetSource(), LINE_READER::Line(), LINE_READER::LineNumber(), m_error, m_reader, and THROW_IO_ERROR.

Referenced by loadDIMENSION(), loadMODULE_EDGE(), loadMODULE_TEXT(), loadPAD(), loadPCB_LINE(), and loadPCB_TEXT().

◆ FootprintDelete()

void PLUGIN::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of a footprint to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the footprint or the library, or deleting it.

Reimplemented in GITHUB_PLUGIN, PCB_IO, and GPCB_PLUGIN.

Definition at line 109 of file plugin.cpp.

111 {
112  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
113  not_implemented( this, __FUNCTION__ );
114 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ FootprintEnumerate()

void LEGACY_PLUGIN::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
bool  aBestEfforts,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Return a list of footprint names contained within the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
aFootprintNamesis the array of available footprint names inside a library.
aBestEffortsif true, don't throw on errors, just return an empty list.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 3445 of file legacy_plugin.cpp.

3447 {
3448  LOCALE_IO toggle; // toggles on, then off, the C locale.
3449  wxString errorMsg;
3450 
3451  init( aProperties );
3452 
3453  try
3454  {
3455  cacheLib( aLibPath );
3456  }
3457  catch( const IO_ERROR& ioe )
3458  {
3459  errorMsg = ioe.What();
3460  }
3461 
3462  // Some of the files may have been parsed correctly so we want to add the valid files to
3463  // the library.
3464 
3465  for( MODULE_CITER it = m_cache->m_modules.begin(); it != m_cache->m_modules.end(); ++it )
3466  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
3467 
3468  if( !errorMsg.IsEmpty() && !aBestEfforts )
3469  THROW_IO_ERROR( errorMsg );
3470 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
#define THROW_IO_ERROR(msg)
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP m_modules
LP_CACHE * m_cache

References cacheLib(), FROM_UTF8(), init(), m_cache, LP_CACHE::m_modules, THROW_IO_ERROR, and IO_ERROR::What().

◆ FootprintExists()

bool PLUGIN::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintExists check for the existence of a footprint.

Reimplemented in PCB_IO.

Definition at line 84 of file plugin.cpp.

86 {
87  // default implementation
88  return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr;
89 }
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:92

References PLUGIN::FootprintLoad().

◆ FootprintLibCreate()

void PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented in GITHUB_PLUGIN, and PCB_IO.

Definition at line 117 of file plugin.cpp.

118 {
119  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
120  not_implemented( this, __FUNCTION__ );
121 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ FootprintLibDelete()

bool LEGACY_PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain footprints.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
bool - true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented from PLUGIN.

Definition at line 3501 of file legacy_plugin.cpp.

3502 {
3503  wxFileName fn = aLibraryPath;
3504 
3505  if( !fn.FileExists() )
3506  return false;
3507 
3508  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
3509  // we don't want that. we want bare metal portability with no UI here.
3510  if( wxRemove( aLibraryPath ) )
3511  {
3513  _( "library \"%s\" cannot be deleted" ),
3514  aLibraryPath.GetData() ) );
3515  }
3516 
3517  if( m_cache && m_cache->m_lib_path == aLibraryPath )
3518  {
3519  delete m_cache;
3520  m_cache = 0;
3521  }
3522 
3523  return true;
3524 }
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_lib_path
LP_CACHE * m_cache

References _, Format(), m_cache, LP_CACHE::m_lib_path, and THROW_IO_ERROR.

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Footprint*() functions in all derived PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to PLUGIN, which has been avoided to date.

Reimplemented in GITHUB_PLUGIN, and EAGLE_PLUGIN.

Definition at line 140 of file plugin.cpp.

141 {
142  // disable all these in another couple of months, after everyone has seen them:
143 #if 1
144  (*aListToAppendTo)["debug_level"] = UTF8( _(
145  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
146  ));
147 
148  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
149  "Regular expression <b>footprint name</b> filter."
150  ));
151 
152  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
153  "Enable transaction logging. The mere presence of this option turns on the "
154  "logging, no need to set a Value."
155  ));
156 
157  (*aListToAppendTo)["username"] = UTF8( _(
158  "User name for <b>login</b> to some special library server."
159  ));
160 
161  (*aListToAppendTo)["password"] = UTF8( _(
162  "Password for <b>login</b> to some special library server."
163  ));
164 #endif
165 
166 #if 1
167  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
168  // if and when implemented.
169  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
170  "Enter the python module which implements the PLUGIN::Footprint*() functions."
171  ));
172 #endif
173 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
#define _(s)
Definition: 3d_actions.cpp:31

References _.

Referenced by EAGLE_PLUGIN::FootprintLibOptions(), and GITHUB_PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

MODULE * LEGACY_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of the footprint to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Reimplemented from PLUGIN.

Definition at line 3473 of file legacy_plugin.cpp.

3475 {
3476  LOCALE_IO toggle; // toggles on, then off, the C locale.
3477 
3478  init( aProperties );
3479 
3480  cacheLib( aLibraryPath );
3481 
3482  const MODULE_MAP& mods = m_cache->m_modules;
3483 
3484  MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
3485 
3486  if( it == mods.end() )
3487  {
3488  /*
3489  THROW_IO_ERROR( wxString::Format( _( "No \"%s\" footprint in library \"%s\"" ),
3490  aFootprintName.GetData(), aLibraryPath.GetData() ) );
3491  */
3492 
3493  return NULL;
3494  }
3495 
3496  // copy constructor to clone the already loaded MODULE
3497  return new MODULE( *it->second );
3498 }
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define NULL
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
MODULE_MAP::const_iterator MODULE_CITER
MODULE_MAP m_modules
LP_CACHE * m_cache

References cacheLib(), init(), m_cache, LP_CACHE::m_modules, NULL, and TO_UTF8.

◆ FootprintSave()

void PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintSave will write aModule to an existing library located at aLibraryPath.

If a footprint by the same name already exists, it is replaced.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aPropertiesis an associative array that can be used to tell the saver how to save the footprint, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented in GITHUB_PLUGIN, and PCB_IO.

Definition at line 101 of file plugin.cpp.

103 {
104  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
105  not_implemented( this, __FUNCTION__ );
106 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ GetEnumeratedFootprint()

const MODULE * PLUGIN::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented in PCB_IO, and GPCB_PLUGIN.

Definition at line 75 of file plugin.cpp.

78 {
79  // default implementation
80  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
81 }
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:92

References PLUGIN::FootprintLoad().

◆ GetFileExtension()

const wxString LEGACY_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 78 of file legacy_plugin.h.

79  {
80  return wxT( "brd" );
81  }

◆ GetLibraryTimestamp()

long long LEGACY_PLUGIN::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
overridevirtual

Generate a timestamp representing all the files in the library (including the library directory).

Timestamps should not be considered ordered; they either match or they don't.

Implements PLUGIN.

Definition at line 3427 of file legacy_plugin.cpp.

3428 {
3429  return LP_CACHE::GetTimestamp( aLibraryPath );
3430 }
static long long GetTimestamp(const wxString &aLibPath)

References LP_CACHE::GetTimestamp().

◆ getNetCode()

int LEGACY_PLUGIN::getNetCode ( int  aNetCode)
inlineprotected

Converts net code using the mapping table if available, otherwise returns unchanged net code

Definition at line 147 of file legacy_plugin.h.

148  {
149  if( (unsigned int) aNetCode < m_netCodes.size() )
150  return m_netCodes[aNetCode];
151 
152  return aNetCode;
153  }
std::vector< int > m_netCodes
net codes mapping for boards being loaded

References m_netCodes.

Referenced by loadPAD(), loadTrackList(), and loadZONE_CONTAINER().

◆ init()

void LEGACY_PLUGIN::init ( const PROPERTIES aProperties)
protected

initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.

Definition at line 3099 of file legacy_plugin.cpp.

3100 {
3102  m_cu_count = 16;
3103  m_board = NULL;
3104  m_showLegacyZoneWarning = true;
3105  m_props = aProperties;
3106 
3107  // conversion factor for saving RAM BIUs to KICAD legacy file format.
3108  biuToDisk = 1.0/IU_PER_MM; // BIUs are nanometers & file is mm
3109 
3110  // Conversion factor for loading KICAD legacy file format into BIUs in RAM
3111  // Start by assuming the *.brd file is in deci-mils.
3112  // If we see "Units mm" in the $GENERAL section, set diskToBiu to 1000000.0
3113  // then, during the file loading process, to start a conversion from
3114  // mm to nanometers. The deci-mil legacy files have no such "Units" marker
3115  // so we must assume the file is in deci-mils until told otherwise.
3116 
3117  diskToBiu = IU_PER_MILS / 10; // BIUs are nanometers
3118 }
bool m_showLegacyZoneWarning
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
#define NULL
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
BOARD * m_board
which BOARD, no ownership here
#define IU_PER_MILS
Definition: plotter.cpp:137
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.

References biuToDisk, diskToBiu, IU_PER_MILS, m_board, m_cu_count, m_loading_format_version, m_props, m_showLegacyZoneWarning, and NULL.

Referenced by FootprintEnumerate(), FootprintLoad(), IsFootprintLibWritable(), LEGACY_PLUGIN(), and Load().

◆ IsFootprintLibWritable()

bool LEGACY_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from PLUGIN.

Definition at line 3527 of file legacy_plugin.cpp.

3528 {
3529 #if 0 // no support for 32 Cu layers in legacy format
3530  return false;
3531 #else
3532  LOCALE_IO toggle;
3533 
3534  init( NULL );
3535 
3536  cacheLib( aLibraryPath );
3537 
3538  return m_cache->m_writable;
3539 #endif
3540 }
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
#define NULL
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
LP_CACHE * m_cache

References cacheLib(), init(), m_cache, LP_CACHE::m_writable, and NULL.

◆ leg_layer2new()

PCB_LAYER_ID LEGACY_PLUGIN::leg_layer2new ( int  cu_count,
LAYER_NUM  aLayerNum 
)
static

Definition at line 285 of file legacy_plugin.cpp.

286 {
287  int newid;
288  unsigned old = aLayerNum;
289 
290  // this is a speed critical function, be careful.
291 
292  if( unsigned( old ) <= unsigned( LAYER_N_FRONT ) )
293  {
294  // In .brd files, the layers are numbered from back to front
295  // (the opposite of the .kicad_pcb files)
296  if( old == LAYER_N_FRONT )
297  newid = F_Cu;
298  else if( old == LAYER_N_BACK )
299  newid = B_Cu;
300  else
301  {
302  newid = cu_count - 1 - old;
303  wxASSERT( newid >= 0 );
304  // This is of course incorrect, but at least it avoid crashing pcbnew:
305  if( newid < 0 )
306  newid = 0;
307  }
308  }
309  else
310  {
311  switch( old )
312  {
313  case ADHESIVE_N_BACK: newid = B_Adhes; break;
314  case ADHESIVE_N_FRONT: newid = F_Adhes; break;
315  case SOLDERPASTE_N_BACK: newid = B_Paste; break;
316  case SOLDERPASTE_N_FRONT: newid = F_Paste; break;
317  case SILKSCREEN_N_BACK: newid = B_SilkS; break;
318  case SILKSCREEN_N_FRONT: newid = F_SilkS; break;
319  case SOLDERMASK_N_BACK: newid = B_Mask; break;
320  case SOLDERMASK_N_FRONT: newid = F_Mask; break;
321  case DRAW_N: newid = Dwgs_User; break;
322  case COMMENT_N: newid = Cmts_User; break;
323  case ECO1_N: newid = Eco1_User; break;
324  case ECO2_N: newid = Eco2_User; break;
325  case EDGE_N: newid = Edge_Cuts; break;
326  default:
327 // wxASSERT( 0 );
328  // Remap all illegal non copper layers to comment layer
329  newid = Cmts_User;
330  }
331  }
332 
333  return PCB_LAYER_ID( newid );
334 }
#define SILKSCREEN_N_BACK
#define LAYER_N_BACK
#define COMMENT_N
#define EDGE_N
#define ADHESIVE_N_FRONT
#define SOLDERMASK_N_FRONT
#define ECO2_N
#define SOLDERMASK_N_BACK
#define ADHESIVE_N_BACK
#define SILKSCREEN_N_FRONT
PCB_LAYER_ID
A quick note on layer IDs:
#define ECO1_N
#define LAYER_N_FRONT
#define SOLDERPASTE_N_FRONT
#define DRAW_N
#define SOLDERPASTE_N_BACK

References ADHESIVE_N_BACK, ADHESIVE_N_FRONT, B_Adhes, B_Cu, B_Mask, B_Paste, B_SilkS, Cmts_User, COMMENT_N, DRAW_N, Dwgs_User, ECO1_N, Eco1_User, ECO2_N, Eco2_User, Edge_Cuts, EDGE_N, F_Adhes, F_Cu, F_Mask, F_Paste, F_SilkS, LAYER_N_BACK, LAYER_N_FRONT, SILKSCREEN_N_BACK, SILKSCREEN_N_FRONT, SOLDERMASK_N_BACK, SOLDERMASK_N_FRONT, SOLDERPASTE_N_BACK, and SOLDERPASTE_N_FRONT.

Referenced by leg_mask2new(), loadDIMENSION(), loadMODULE(), loadMODULE_EDGE(), loadMODULE_TEXT(), loadPCB_LINE(), loadPCB_TARGET(), loadPCB_TEXT(), loadSETUP(), loadTrackList(), and loadZONE_CONTAINER().

◆ leg_mask2new()

LSET LEGACY_PLUGIN::leg_mask2new ( int  cu_count,
unsigned  aMask 
)
static

Definition at line 337 of file legacy_plugin.cpp.

338 {
339  LSET ret;
340 
341  if( ( aMask & ALL_CU_LAYERS ) == ALL_CU_LAYERS )
342  {
343  ret = LSET::AllCuMask();
344 
345  aMask &= ~ALL_CU_LAYERS;
346  }
347 
348  for( int i=0; aMask; ++i, aMask >>= 1 )
349  {
350  if( aMask & 1 )
351  ret.set( leg_layer2new( cu_count, i ) );
352  }
353 
354  return ret;
355 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
LSET is a set of PCB_LAYER_IDs.
#define ALL_CU_LAYERS

References ALL_CU_LAYERS, LSET::AllCuMask(), and leg_layer2new().

Referenced by loadGENERAL(), and loadPAD().

◆ Load()

BOARD * LEGACY_PLUGIN::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one.

This may be used to load an entire new BOARD, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aAppendToMeis an existing BOARD to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
BOARD* - the successfully loaded board, or the same one as aAppendToMe if aAppendToMe was not NULL, and caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.

Reimplemented from PLUGIN.

Definition at line 394 of file legacy_plugin.cpp.

396 {
397  LOCALE_IO toggle; // toggles on, then off, the C locale.
398 
399  init( aProperties );
400 
401  m_board = aAppendToMe ? aAppendToMe : new BOARD();
402 
403  // Give the filename to the board if it's new
404  if( !aAppendToMe )
405  m_board->SetFileName( aFileName );
406 
407  // delete on exception, iff I own m_board, according to aAppendToMe
408  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
409 
410  FILE_LINE_READER reader( aFileName );
411 
412  m_reader = &reader; // member function accessibility
413 
414  checkVersion();
415 
416  loadAllSections( bool( aAppendToMe ) );
417 
418  deleter.release();
419  return m_board;
420 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
LINE_READER * m_reader
no ownership here.
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define NULL
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void SetFileName(const wxString &aFileName)
Definition: class_board.h:213
BOARD * m_board
which BOARD, no ownership here
void loadAllSections(bool doAppend)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160

References checkVersion(), init(), loadAllSections(), m_board, m_reader, NULL, and BOARD::SetFileName().

◆ load3D()

void LEGACY_PLUGIN::load3D ( MODULE aModule)
protected

Definition at line 1897 of file legacy_plugin.cpp.

1898 {
1899  MODULE_3D_SETTINGS t3D;
1900 
1901  char* line;
1902  while( ( line = READLINE( m_reader ) ) != NULL )
1903  {
1904  if( TESTLINE( "Na" ) ) // Shape File Name
1905  {
1906  char buf[512];
1907  ReadDelimitedText( buf, line + SZ( "Na" ), sizeof(buf) );
1908  t3D.m_Filename = buf;
1909  }
1910 
1911  else if( TESTLINE( "Sc" ) ) // Scale
1912  {
1913  sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n",
1914  &t3D.m_Scale.x,
1915  &t3D.m_Scale.y,
1916  &t3D.m_Scale.z );
1917  }
1918 
1919  else if( TESTLINE( "Of" ) ) // Offset
1920  {
1921  sscanf( line + SZ( "Of" ), "%lf %lf %lf\n",
1922  &t3D.m_Offset.x,
1923  &t3D.m_Offset.y,
1924  &t3D.m_Offset.z );
1925  }
1926 
1927  else if( TESTLINE( "Ro" ) ) // Rotation
1928  {
1929  sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n",
1930  &t3D.m_Rotation.x,
1931  &t3D.m_Rotation.y,
1932  &t3D.m_Rotation.z );
1933  }
1934 
1935  else if( TESTLINE( "$EndSHAPE3D" ) )
1936  {
1937  aModule->Models().push_back( t3D );
1938  return; // preferred exit
1939  }
1940  }
1941 
1942  THROW_IO_ERROR( "Missing '$EndSHAPE3D'" );
1943 }
#define READLINE(rdr)
VECTOR3D m_Offset
3D model offset (mm)
Definition: class_module.h:99
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:100
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition: class_module.h:98
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition: class_module.h:97
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.

References MODULE_3D_SETTINGS::m_Filename, MODULE_3D_SETTINGS::m_Offset, m_reader, MODULE_3D_SETTINGS::m_Rotation, MODULE_3D_SETTINGS::m_Scale, MODULE::Models(), NULL, ReadDelimitedText(), READLINE, SZ, TESTLINE, THROW_IO_ERROR, MODULE_3D_SETTINGS::VECTOR3D::x, MODULE_3D_SETTINGS::VECTOR3D::y, and MODULE_3D_SETTINGS::VECTOR3D::z.

Referenced by loadMODULE().

◆ loadAllSections()

void LEGACY_PLUGIN::loadAllSections ( bool  doAppend)
protected

Definition at line 423 of file legacy_plugin.cpp.

424 {
425  // $GENERAL section is first
426 
427  // $SHEETDESCR section is next
428 
429  // $SETUP section is next
430 
431  // Then follows $EQUIPOT and all the rest
432  char* line;
433 
434  while( ( line = READLINE( m_reader ) ) != NULL )
435  {
436  // put the more frequent ones at the top, but realize TRACKs are loaded as a group
437 
438  if( TESTLINE( "$MODULE" ) )
439  {
440  unique_ptr<MODULE> module( new MODULE( m_board ) );
441 
442  LIB_ID fpid;
443  std::string fpName = StrPurge( line + SZ( "$MODULE" ) );
444 
445  // The footprint names in legacy libraries can contain the '/' and ':'
446  // characters which will cause the FPID parser to choke.
447  ReplaceIllegalFileNameChars( &fpName );
448 
449  if( !fpName.empty() )
450  fpid.Parse( fpName, LIB_ID::ID_PCB, true );
451 
452  module->SetFPID( fpid );
453 
454  loadMODULE( module.get() );
455  m_board->Add( module.release(), ADD_MODE::APPEND );
456  }
457 
458  else if( TESTLINE( "$DRAWSEGMENT" ) )
459  {
460  loadPCB_LINE();
461  }
462 
463  else if( TESTLINE( "$EQUIPOT" ) )
464  {
466  }
467 
468  else if( TESTLINE( "$TEXTPCB" ) )
469  {
470  loadPCB_TEXT();
471  }
472 
473  else if( TESTLINE( "$TRACK" ) )
474  {
476  }
477 
478  else if( TESTLINE( "$NCLASS" ) )
479  {
480  loadNETCLASS();
481  }
482 
483  else if( TESTLINE( "$CZONE_OUTLINE" ) )
484  {
486  }
487 
488  else if( TESTLINE( "$COTATION" ) )
489  {
490  loadDIMENSION();
491  }
492 
493  else if( TESTLINE( "$PCB_TARGET" ) || TESTLINE( "$MIREPCB" ) )
494  {
495  loadPCB_TARGET();
496  }
497 
498  else if( TESTLINE( "$ZONE" ) )
499  {
500  // No longer supported; discard segment fills
502  }
503 
504  else if( TESTLINE( "$GENERAL" ) )
505  {
506  loadGENERAL();
507  }
508 
509  else if( TESTLINE( "$SHEETDESCR" ) )
510  {
511  loadSHEET();
512  }
513 
514  else if( TESTLINE( "$SETUP" ) )
515  {
516  if( !doAppend )
517  {
518  loadSETUP();
519  }
520  else
521  {
522  while( ( line = READLINE( m_reader ) ) != NULL )
523  {
524  // gobble until $EndSetup
525  if( TESTLINE( "$EndSETUP" ) )
526  break;
527  }
528  }
529  }
530 
531  else if( TESTLINE( "$EndBOARD" ) )
532  return; // preferred exit
533  }
534 
535  THROW_IO_ERROR( "Missing '$EndBOARD'" );
536 }
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310
the 3d code uses this value
Definition: typeinfo.h:80
void loadMODULE(MODULE *aModule)
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:680
#define READLINE(rdr)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
BOARD * m_board
which BOARD, no ownership here
void loadZONE_CONTAINER()
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
void loadTrackList(int aStructType)
Function loadTrackList reads a list of segments (Tracks and Vias, or Segzones)

References BOARD::Add(), APPEND, LIB_ID::ID_PCB, loadDIMENSION(), loadGENERAL(), loadMODULE(), loadNETCLASS(), loadNETINFO_ITEM(), loadPCB_LINE(), loadPCB_TARGET(), loadPCB_TEXT(), loadSETUP(), loadSHEET(), loadTrackList(), loadZONE_CONTAINER(), m_board, m_reader, NOT_USED, NULL, LIB_ID::Parse(), PCB_TRACE_T, READLINE, ReplaceIllegalFileNameChars(), StrPurge(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by Load().

◆ loadDIMENSION()

void LEGACY_PLUGIN::loadDIMENSION ( )
protected

Definition at line 2795 of file legacy_plugin.cpp.

2796 {
2797  unique_ptr<DIMENSION> dim( new DIMENSION( m_board ) );
2798 
2799  char* line;
2800  char* saveptr;
2801 
2802  while( ( line = READLINE( m_reader ) ) != NULL )
2803  {
2804  const char* data;
2805 
2806  if( TESTLINE( "$endCOTATION" ) )
2807  {
2808  m_board->Add( dim.release(), ADD_MODE::APPEND );
2809  return; // preferred exit
2810  }
2811 
2812  else if( TESTLINE( "Va" ) )
2813  {
2814  BIU value = biuParse( line + SZ( "Va" ) );
2815  dim->SetValue( value );
2816  }
2817 
2818  else if( TESTLINE( "Ge" ) )
2819  {
2820  LAYER_NUM layer_num;
2821  unsigned long timestamp;
2822  int shape;
2823  int ilayer;
2824 
2825  sscanf( line + SZ( "Ge" ), " %d %d %lX", &shape, &ilayer, &timestamp );
2826 
2827  if( ilayer < FIRST_NON_COPPER_LAYER )
2828  layer_num = FIRST_NON_COPPER_LAYER;
2829  else if( ilayer > LAST_NON_COPPER_LAYER )
2830  layer_num = LAST_NON_COPPER_LAYER;
2831  else
2832  layer_num = ilayer;
2833 
2834  dim->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2835  dim->SetTimeStamp( (timestamp_t) timestamp );
2836  dim->SetShape( shape );
2837  }
2838 
2839  else if( TESTLINE( "Te" ) )
2840  {
2841  char buf[2048];
2842 
2843  ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
2844  dim->SetText( FROM_UTF8( buf ) );
2845  }
2846 
2847  else if( TESTLINE( "Po" ) )
2848  {
2849  // sscanf( Line + 2, " %d %d %d %d %d %d %d", &m_Text->m_Pos.x, &m_Text->m_Pos.y,
2850  // &m_Text->m_Size.x, &m_Text->m_Size.y, &thickness, &orientation, &normal_display );
2851 
2852  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
2853  BIU pos_y = biuParse( data, &data );
2854  BIU width = biuParse( data, &data );
2855  BIU height = biuParse( data, &data );
2856  BIU thickn = biuParse( data, &data );
2857  double orient = degParse( data, &data );
2858  char* mirror = strtok_r( (char*) data, delims, &saveptr );
2859 
2860  // This sets both DIMENSION's position and internal m_Text's.
2861  // @todo: But why do we even know about internal m_Text?
2862  dim->SetPosition( wxPoint( pos_x, pos_y ) );
2863  dim->SetTextSize( wxSize( width, height ) );
2864 
2865  dim->Text().SetMirrored( mirror && *mirror == '0' );
2866  dim->Text().SetThickness( thickn );
2867  dim->Text().SetTextAngle( orient );
2868  }
2869 
2870  else if( TESTLINE( "Sb" ) )
2871  {
2872  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_crossBarOx, &m_crossBarOy, &m_crossBarFx, &m_crossBarFy, &m_Width );
2873 
2874  int ignore = biuParse( line + SZ( "Sb" ), &data );
2875  BIU crossBarOx = biuParse( data, &data );
2876  BIU crossBarOy = biuParse( data, &data );
2877  BIU crossBarFx = biuParse( data, &data );
2878  BIU crossBarFy = biuParse( data, &data );
2879  BIU width = biuParse( data );
2880 
2881  dim->m_crossBarO.x = crossBarOx;
2882  dim->m_crossBarO.y = crossBarOy;
2883  dim->m_crossBarF.x = crossBarFx;
2884  dim->m_crossBarF.y = crossBarFy;
2885  dim->SetWidth( width );
2886  (void) ignore;
2887  }
2888 
2889  else if( TESTLINE( "Sd" ) )
2890  {
2891  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineDOx, &m_featureLineDOy, &m_featureLineDFx, &m_featureLineDFy, &Dummy );
2892 
2893  int ignore = intParse( line + SZ( "Sd" ), &data );
2894  BIU featureLineDOx = biuParse( data, &data );
2895  BIU featureLineDOy = biuParse( data, &data );
2896  BIU featureLineDFx = biuParse( data, &data );
2897  BIU featureLineDFy = biuParse( data );
2898 
2899  dim->m_featureLineDO.x = featureLineDOx;
2900  dim->m_featureLineDO.y = featureLineDOy;
2901  dim->m_featureLineDF.x = featureLineDFx;
2902  dim->m_featureLineDF.y = featureLineDFy;
2903  (void) ignore;
2904  }
2905 
2906  else if( TESTLINE( "Sg" ) )
2907  {
2908  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineGOx, &m_featureLineGOy, &m_featureLineGFx, &m_featureLineGFy, &Dummy );
2909 
2910  int ignore = intParse( line + SZ( "Sg" ), &data );
2911  BIU featureLineGOx = biuParse( data, &data );
2912  BIU featureLineGOy = biuParse( data, &data );
2913  BIU featureLineGFx = biuParse( data, &data );
2914  BIU featureLineGFy = biuParse( data );
2915 
2916  dim->m_featureLineGO.x = featureLineGOx;
2917  dim->m_featureLineGO.y = featureLineGOy;
2918  dim->m_featureLineGF.x = featureLineGFx;
2919  dim->m_featureLineGF.y = featureLineGFy;
2920  (void) ignore;
2921  }
2922 
2923  else if( TESTLINE( "S1" ) )
2924  {
2925  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD1Ox, &m_arrowD1Oy, &m_arrowD1Fx, &m_arrowD1Fy, &Dummy );
2926 
2927  int ignore = intParse( line + SZ( "S1" ), &data );
2928  biuParse( data, &data ); // skipping excessive data
2929  biuParse( data, &data ); // skipping excessive data
2930  BIU arrowD1Fx = biuParse( data, &data );
2931  BIU arrowD1Fy = biuParse( data );
2932 
2933  dim->m_arrowD1F.x = arrowD1Fx;
2934  dim->m_arrowD1F.y = arrowD1Fy;
2935  (void) ignore;
2936  }
2937 
2938  else if( TESTLINE( "S2" ) )
2939  {
2940  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD2Ox, &m_arrowD2Oy, &m_arrowD2Fx, &m_arrowD2Fy, &Dummy );
2941 
2942  int ignore = intParse( line + SZ( "S2" ), &data );
2943  biuParse( data, &data ); // skipping excessive data
2944  biuParse( data, &data ); // skipping excessive data
2945  BIU arrowD2Fx = biuParse( data, &data );
2946  BIU arrowD2Fy = biuParse( data, &data );
2947 
2948  dim->m_arrowD2F.x = arrowD2Fx;
2949  dim->m_arrowD2F.y = arrowD2Fy;
2950  (void) ignore;
2951  }
2952 
2953  else if( TESTLINE( "S3" ) )
2954  {
2955  // sscanf( Line + 2, " %d %d %d %d %d %d\n", &Dummy, &m_arrowG1Ox, &m_arrowG1Oy, &m_arrowG1Fx, &m_arrowG1Fy, &Dummy );
2956  int ignore = intParse( line + SZ( "S3" ), &data );
2957  biuParse( data, &data ); // skipping excessive data
2958  biuParse( data, &data ); // skipping excessive data
2959  BIU arrowG1Fx = biuParse( data, &data );
2960  BIU arrowG1Fy = biuParse( data, &data );
2961 
2962  dim->m_arrowG1F.x = arrowG1Fx;
2963  dim->m_arrowG1F.y = arrowG1Fy;
2964  (void) ignore;
2965  }
2966 
2967  else if( TESTLINE( "S4" ) )
2968  {
2969  // sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowG2Ox, &m_arrowG2Oy, &m_arrowG2Fx, &m_arrowG2Fy, &Dummy );
2970  int ignore = intParse( line + SZ( "S4" ), &data );
2971  biuParse( data, &data ); // skipping excessive data
2972  biuParse( data, &data ); // skipping excessive data
2973  BIU arrowG2Fx = biuParse( data, &data );
2974  BIU arrowG2Fy = biuParse( data, &data );
2975 
2976  dim->m_arrowG2F.x = arrowG2Fx;
2977  dim->m_arrowG2F.y = arrowG2Fy;
2978  (void) ignore;
2979  }
2980  }
2981 
2982  THROW_IO_ERROR( "Missing '$endCOTATION'" );
2983 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static const char delims[]
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
#define LAST_NON_COPPER_LAYER
char * strtok_r(char *str, const char *delim, char **nextp)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
DIMENSION.
#define FIRST_NON_COPPER_LAYER

References BOARD::Add(), APPEND, biuParse(), degParse(), delims, FIRST_NON_COPPER_LAYER, FROM_UTF8(), intParse(), LAST_NON_COPPER_LAYER, leg_layer2new(), m_board, m_cu_count, m_reader, NULL, ReadDelimitedText(), READLINE, strtok_r(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadGENERAL()

void LEGACY_PLUGIN::loadGENERAL ( )
protected

Definition at line 571 of file legacy_plugin.cpp.

572 {
573  char* line;
574  char* saveptr;
575  bool saw_LayerCount = false;
576 
577  while( ( line = READLINE( m_reader ) ) != NULL )
578  {
579  const char* data;
580 
581  if( TESTLINE( "Units" ) )
582  {
583  // what are the engineering units of the lengths in the BOARD?
584  data = strtok_r( line + SZ("Units"), delims, &saveptr );
585 
586  if( !strcmp( data, "mm" ) )
587  {
588  diskToBiu = IU_PER_MM;
589  }
590  }
591 
592  else if( TESTLINE( "LayerCount" ) )
593  {
594  int tmp = intParse( line + SZ( "LayerCount" ) );
596 
597  // This has to be set early so that leg_layer2new() works OK, and
598  // that means before parsing "EnabledLayers" and "VisibleLayers".
599  m_cu_count = tmp;
600 
601  saw_LayerCount = true;
602  }
603 
604  else if( TESTLINE( "EnabledLayers" ) )
605  {
606  if( !saw_LayerCount )
607  THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
608 
609  LEG_MASK enabledLayers = hexParse( line + SZ( "EnabledLayers" ) );
610 
611  LSET new_mask = leg_mask2new( m_cu_count, enabledLayers );
612 
613  //DBG( printf( "EnabledLayers: %s\n", new_mask.FmtHex().c_str() );)
614 
615  m_board->SetEnabledLayers( new_mask );
616 
617  // layer visibility equals layer usage, unless overridden later via "VisibleLayers"
618  // Must call SetEnabledLayers() before calling SetVisibleLayers().
619  m_board->SetVisibleLayers( new_mask );
620  }
621 
622  else if( TESTLINE( "VisibleLayers" ) )
623  {
624  if( !saw_LayerCount )
625  THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
626 
627  LEG_MASK visibleLayers = hexParse( line + SZ( "VisibleLayers" ) );
628 
629  LSET new_mask = leg_mask2new( m_cu_count, visibleLayers );
630 
631  m_board->SetVisibleLayers( new_mask );
632  }
633 
634  else if( TESTLINE( "Ly" ) ) // Old format for Layer count
635  {
636  if( !saw_LayerCount )
637  {
638  LEG_MASK layer_mask = hexParse( line + SZ( "Ly" ) );
639 
640  m_cu_count = layerMaskCountSet( layer_mask & ALL_CU_LAYERS );
641 
643 
644  saw_LayerCount = true;
645  }
646  }
647 
648  else if( TESTLINE( "BoardThickness" ) )
649  {
650  BIU thickn = biuParse( line + SZ( "BoardThickness" ) );
652  }
653 
654  /*
655  else if( TESTLINE( "Links" ) )
656  {
657  // Info only, do nothing, but only for a short while.
658  }
659  */
660 
661  else if( TESTLINE( "NoConn" ) )
662  {
663  // ignore
664  intParse( line + SZ( "NoConn" ) );
665  }
666 
667  else if( TESTLINE( "Di" ) )
668  {
669  biuParse( line + SZ( "Di" ), &data );
670  biuParse( data, &data );
671  biuParse( data, &data );
672  biuParse( data );
673  }
674 
675  /* This is no more usefull, so this info is no more parsed
676  // Read the number of segments of type DRAW, TRACK, ZONE
677  else if( TESTLINE( "Ndraw" ) )
678  {
679  NbDraw = intParse( line + SZ( "Ndraw" ) );
680  }
681 
682  else if( TESTLINE( "Ntrack" ) )
683  {
684  NbTrack = intParse( line + SZ( "Ntrack" ) );
685  }
686 
687  else if( TESTLINE( "Nzone" ) )
688  {
689  NbZone = intParse( line + SZ( "Nzone" ) );
690  }
691 
692  else if( TESTLINE( "Nmodule" ) )
693  {
694  NbMod = intParse( line + SZ( "Nmodule" ) );
695  }*/
696 
697  else if( TESTLINE( "Nnets" ) )
698  {
699  m_netCodes.resize( intParse( line + SZ( "Nnets" ) ) );
700  }
701 
702  else if( TESTLINE( "Nn" ) ) // id "Nnets" for old .brd files
703  {
704  m_netCodes.resize( intParse( line + SZ( "Nn" ) ) );
705  }
706 
707  else if( TESTLINE( "$EndGENERAL" ) )
708  return; // preferred exit
709  }
710 
711  THROW_IO_ERROR( "Missing '$EndGENERAL'" );
712 }
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static const char delims[]
void SetCopperLayerCount(int aCount)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define READLINE(rdr)
void SetBoardThickness(int aThickness)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
std::vector< int > m_netCodes
net codes mapping for boards being loaded
LINE_READER * m_reader
no ownership here.
LSET is a set of PCB_LAYER_IDs.
#define NULL
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
#define ALL_CU_LAYERS
#define THROW_IO_ERROR(msg)
unsigned LEG_MASK
LEGACY_PLUGIN::BIU BIU
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
BOARD * m_board
which BOARD, no ownership here
static LSET leg_mask2new(int cu_count, unsigned aMask)
int layerMaskCountSet(LEG_MASK aMask)
Count the number of set layers in the mask.
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...

References ALL_CU_LAYERS, biuParse(), delims, diskToBiu, BOARD::GetDesignSettings(), hexParse(), intParse(), layerMaskCountSet(), leg_mask2new(), m_board, m_cu_count, m_netCodes, m_reader, NULL, READLINE, BOARD_DESIGN_SETTINGS::SetBoardThickness(), BOARD::SetCopperLayerCount(), BOARD::SetEnabledLayers(), BOARD::SetVisibleLayers(), strtok_r(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadMODULE()

void LEGACY_PLUGIN::loadMODULE ( MODULE aModule)
protected

Definition at line 1194 of file legacy_plugin.cpp.

1195 {
1196  char* line;
1197  char* saveptr;
1198 
1199  while( ( line = READLINE( m_reader ) ) != NULL )
1200  {
1201  const char* data;
1202 
1203  // most frequently encountered ones at the top
1204 
1205  if( TESTSUBSTR( "D" ) && strchr( "SCAP", line[1] ) ) // read a drawing item, e.g. "DS"
1206  {
1207  loadMODULE_EDGE( aModule );
1208  }
1209 
1210  else if( TESTLINE( "$PAD" ) )
1211  {
1212  loadPAD( aModule );
1213  }
1214 
1215  // Read a footprint text description (ref, value, or drawing)
1216  else if( TESTSUBSTR( "T" ) )
1217  {
1218  // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
1219 
1220  int tnum = intParse( line + SZ( "T" ) );
1221 
1222  TEXTE_MODULE* textm = 0;
1223 
1224  switch( tnum )
1225  {
1227  textm = &aModule->Reference();
1228  break;
1229 
1231  textm = &aModule->Value();
1232  break;
1233 
1234  // All other fields greater than 1.
1235  default:
1236  textm = new TEXTE_MODULE( aModule );
1237  aModule->Add( textm );
1238  }
1239 
1240  loadMODULE_TEXT( textm );
1241  }
1242 
1243  else if( TESTLINE( "Po" ) )
1244  {
1245  // e.g. "Po 19120 39260 900 0 4E823D06 46EAAFA5 ~~\r\n"
1246 
1247  // sscanf( PtLine, "%d %d %d %d %lX %lX %s", &m_Pos.x, &m_Pos.y, &m_Orient, &m_Layer, &m_LastEdit_Time, &m_TimeStamp, BufCar1 );
1248 
1249  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
1250  BIU pos_y = biuParse( data, &data );
1251  int orient = intParse( data, &data );
1252 
1253  LAYER_NUM layer_num = layerParse( data, &data );
1254  PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
1255 
1256  long edittime = hexParse( data, &data );
1257  timestamp_t timestamp = hexParse( data, &data );
1258 
1259  data = strtok_r( (char*) data+1, delims, &saveptr );
1260 
1261  // data is now a two character long string
1262  // Note: some old files do not have this field
1263  if( data && data[0] == 'F' )
1264  aModule->SetLocked( true );
1265 
1266  if( data && data[1] == 'P' )
1267  aModule->SetIsPlaced( true );
1268 
1269  aModule->SetPosition( wxPoint( pos_x, pos_y ) );
1270  aModule->SetLayer( layer_id );
1271  aModule->SetOrientation( orient );
1272  aModule->SetTimeStamp( timestamp );
1273  aModule->SetLastEditTime( edittime );
1274  }
1275 
1276  /* footprint name set earlier, immediately after MODULE construction
1277  else if( TESTLINE( "Li" ) ) // Library name of footprint
1278  {
1279  // There can be whitespace in the footprint name on some old libraries.
1280  // Grab everything after "Li" up to end of line:
1281  //aModule->SetFPID( FROM_UTF8( StrPurge( line + SZ( "Li" ) ) ) );
1282  }
1283  */
1284 
1285  else if( TESTLINE( "Sc" ) ) // timestamp
1286  {
1287  timestamp_t timestamp = hexParse( line + SZ( "Sc" ) );
1288  aModule->SetTimeStamp( timestamp );
1289  }
1290 
1291  else if( TESTLINE( "Op" ) ) // (Op)tions for auto placement
1292  {
1293  int itmp1 = hexParse( line + SZ( "Op" ), &data );
1294  int itmp2 = hexParse( data );
1295 
1296  int cntRot180 = itmp2 & 0x0F;
1297  if( cntRot180 > 10 )
1298  cntRot180 = 10;
1299 
1300  aModule->SetPlacementCost180( cntRot180 );
1301 
1302  int cntRot90 = itmp1 & 0x0F;
1303  if( cntRot90 > 10 )
1304  cntRot90 = 0;
1305 
1306  itmp1 = (itmp1 >> 4) & 0x0F;
1307  if( itmp1 > 10 )
1308  itmp1 = 0;
1309 
1310  aModule->SetPlacementCost90( (itmp1 << 4) | cntRot90 );
1311  }
1312 
1313  else if( TESTLINE( "At" ) ) // (At)tributes of module
1314  {
1315  int attrs = MOD_DEFAULT;
1316 
1317  data = line + SZ( "At" );
1318 
1319  if( strstr( data, "SMD" ) )
1320  attrs |= MOD_CMS;
1321 
1322  if( strstr( data, "VIRTUAL" ) )
1323  attrs |= MOD_VIRTUAL;
1324 
1325  aModule->SetAttributes( attrs );
1326  }
1327 
1328  else if( TESTLINE( "AR" ) ) // Alternate Reference
1329  {
1330  // e.g. "AR /47BA2624/45525076"
1331  data = strtok_r( line + SZ( "AR" ), delims, &saveptr );
1332  if( data )
1333  aModule->SetPath( FROM_UTF8( data ) );
1334  }
1335 
1336  else if( TESTLINE( "$SHAPE3D" ) )
1337  {
1338  load3D( aModule );
1339  }
1340 
1341  else if( TESTLINE( "Cd" ) )
1342  {
1343  // e.g. "Cd Double rangee de contacts 2 x 4 pins\r\n"
1344  aModule->SetDescription( FROM_UTF8( StrPurge( line + SZ( "Cd" ) ) ) );
1345  }
1346 
1347  else if( TESTLINE( "Kw" ) ) // Key words
1348  {
1349  aModule->SetKeywords( FROM_UTF8( StrPurge( line + SZ( "Kw" ) ) ) );
1350  }
1351 
1352  else if( TESTLINE( ".SolderPasteRatio" ) )
1353  {
1354  double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
1355  // Due to a bug in dialog editor in Modedit, fixed in BZR version 3565
1356  // this parameter can be broken.
1357  // It should be >= -50% (no solder paste) and <= 0% (full area of the pad)
1358 
1359  if( tmp < -0.50 )
1360  tmp = -0.50;
1361  if( tmp > 0.0 )
1362  tmp = 0.0;
1363  aModule->SetLocalSolderPasteMarginRatio( tmp );
1364  }
1365 
1366  else if( TESTLINE( ".SolderPaste" ) )
1367  {
1368  BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
1369  aModule->SetLocalSolderPasteMargin( tmp );
1370  }
1371 
1372  else if( TESTLINE( ".SolderMask" ) )
1373  {
1374  BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
1375  aModule->SetLocalSolderMaskMargin( tmp );
1376  }
1377 
1378  else if( TESTLINE( ".LocalClearance" ) )
1379  {
1380  BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
1381  aModule->SetLocalClearance( tmp );
1382  }
1383 
1384  else if( TESTLINE( ".ZoneConnection" ) )
1385  {
1386  int tmp = intParse( line + SZ( ".ZoneConnection" ) );
1387  aModule->SetZoneConnection( (ZONE_CONNECTION) tmp );
1388  }
1389 
1390  else if( TESTLINE( ".ThermalWidth" ) )
1391  {
1392  BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
1393  aModule->SetThermalWidth( tmp );
1394  }
1395 
1396  else if( TESTLINE( ".ThermalGap" ) )
1397  {
1398  BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
1399  aModule->SetThermalGap( tmp );
1400  }
1401 
1402  else if( TESTLINE( "$EndMODULE" ) )
1403  {
1404  aModule->CalculateBoundingBox();
1405 
1406  return; // preferred exit
1407  }
1408  }
1409 
1410  wxString msg = wxString::Format(
1411  _( "Missing '$EndMODULE' for MODULE \"%s\"" ),
1412  GetChars( aModule->GetFPID().GetLibItemName() ) );
1413 
1414  THROW_IO_ERROR( msg );
1415 }
void SetPlacementCost90(int aCost)
Definition: class_module.h:556
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:50
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
TEXTE_MODULE & Reference()
Definition: class_module.h:477
void SetThermalGap(int aGap)
Definition: class_module.h:256
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310
void SetLocalClearance(int aClearance)
Definition: class_module.h:235
void loadMODULE_TEXT(TEXTE_MODULE *aText)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:553
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
static const char delims[]
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
const LIB_ID & GetFPID() const
Definition: class_module.h:219
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:241
void load3D(MODULE *aModule)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
PCB_LAYER_ID
A quick note on layer IDs:
LINE_READER * m_reader
no ownership here.
#define NULL
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
void loadMODULE_EDGE(MODULE *aModule)
void SetLastEditTime(timestamp_t aTime)
Definition: class_module.h:347
void SetThermalWidth(int aWidth)
Definition: class_module.h:253
#define THROW_IO_ERROR(msg)
void SetIsPlaced(bool isPlaced)
Definition: class_module.h:320
LEGACY_PLUGIN::BIU BIU
void SetPosition(const wxPoint &aPos) override
#define TESTSUBSTR(x)
C sub-string compare test for a specific length of characters.
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:232
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
default
Definition: class_module.h:73
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:238
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:311
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:31
void SetOrientation(double newangle)
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:243
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
void SetKeywords(const wxString &aKeywords)
Definition: class_module.h:226
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
void loadPAD(MODULE *aModule)
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
void SetPath(const wxString &aPath)
Definition: class_module.h:229
void SetAttributes(int aAttributes)
Definition: class_module.h:260
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212
void SetDescription(const wxString &aDoc)
Definition: class_module.h:223

References _, MODULE::Add(), biuParse(), MODULE::CalculateBoundingBox(), delims, Format(), FROM_UTF8(), GetChars(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), hexParse(), intParse(), layerParse(), leg_layer2new(), load3D(), loadMODULE_EDGE(), loadMODULE_TEXT(), loadPAD(), m_cu_count, m_reader, MOD_CMS, MOD_DEFAULT, MOD_VIRTUAL, NULL, READLINE, MODULE::Reference(), MODULE::SetAttributes(), MODULE::SetDescription(), MODULE::SetIsPlaced(), MODULE::SetKeywords(), MODULE::SetLastEditTime(), BOARD_ITEM::SetLayer(), MODULE::SetLocalClearance(), MODULE::SetLocalSolderMaskMargin(), MODULE::SetLocalSolderPasteMargin(), MODULE::SetLocalSolderPasteMarginRatio(), MODULE::SetLocked(), MODULE::SetOrientation(), MODULE::SetPath(), MODULE::SetPlacementCost180(), MODULE::SetPlacementCost90(), MODULE::SetPosition(), MODULE::SetThermalGap(), MODULE::SetThermalWidth(), EDA_ITEM::SetTimeStamp(), MODULE::SetZoneConnection(), StrPurge(), strtok_r(), SZ, TESTLINE, TESTSUBSTR, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, THROW_IO_ERROR, and MODULE::Value().

Referenced by loadAllSections(), and LP_CACHE::LoadModules().

◆ loadMODULE_EDGE()

void LEGACY_PLUGIN::loadMODULE_EDGE ( MODULE aModule)
protected

Definition at line 1657 of file legacy_plugin.cpp.

1658 {
1659  STROKE_T shape;
1660  char* line = m_reader->Line(); // obtain current (old) line
1661 
1662  switch( line[1] )
1663  {
1664  case 'S': shape = S_SEGMENT; break;
1665  case 'C': shape = S_CIRCLE; break;
1666  case 'A': shape = S_ARC; break;
1667  case 'P': shape = S_POLYGON; break;
1668  default:
1669  m_error.Printf( _( "Unknown EDGE_MODULE type:'%c=0x%02x' on line:%d of footprint:\"%s\"" ),
1670  (unsigned char) line[1],
1671  (unsigned char) line[1],
1672  m_reader->LineNumber(),
1673  GetChars( aModule->GetFPID().GetLibItemName() )
1674  );
1676  }
1677 
1678  unique_ptr<EDGE_MODULE> dwg( new EDGE_MODULE( aModule, shape ) ); // a drawing
1679 
1680  const char* data;
1681 
1682  // common to all cases, and we have to check their values uniformly at end
1683  BIU width = 1;
1685 
1686  switch( shape )
1687  {
1688  case S_ARC:
1689  {
1690  // sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &m_Angle, &m_Width, &m_Layer );
1691  BIU start0_x = biuParse( line + SZ( "DA" ), &data );
1692  BIU start0_y = biuParse( data, &data );
1693  BIU end0_x = biuParse( data, &data );
1694  BIU end0_y = biuParse( data, &data );
1695  double angle = degParse( data, &data );
1696 
1697  width = biuParse( data, &data );
1698  layer = layerParse( data );
1699 
1700  dwg->SetAngle( angle );
1701  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1702  dwg->m_End0 = wxPoint( end0_x, end0_y );
1703  }
1704  break;
1705 
1706  case S_SEGMENT:
1707  case S_CIRCLE:
1708  {
1709  // e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
1710  // sscanf( Line + 3, "%d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &m_Width, &m_Layer );
1711 
1712  BIU start0_x = biuParse( line + SZ( "DS" ), &data );
1713  BIU start0_y = biuParse( data, &data );
1714  BIU end0_x = biuParse( data, &data );
1715  BIU end0_y = biuParse( data, &data );
1716 
1717  width = biuParse( data, &data );
1718  layer = layerParse( data );
1719 
1720  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1721  dwg->m_End0 = wxPoint( end0_x, end0_y );
1722  }
1723  break;
1724 
1725  case S_POLYGON:
1726  {
1727  // e.g. "DP %d %d %d %d %d %d %d\n"
1728  // sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &pointCount, &m_Width, &m_Layer );
1729 
1730  BIU start0_x = biuParse( line + SZ( "DP" ), &data );
1731  BIU start0_y = biuParse( data, &data );
1732  BIU end0_x = biuParse( data, &data );
1733  BIU end0_y = biuParse( data, &data );
1734  int ptCount = intParse( data, &data );
1735 
1736  width = biuParse( data, &data );
1737  layer = layerParse( data );
1738 
1739  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1740  dwg->m_End0 = wxPoint( end0_x, end0_y );
1741 
1742  std::vector<wxPoint> pts;
1743  pts.reserve( ptCount );
1744 
1745  for( int ii = 0; ii<ptCount; ++ii )
1746  {
1747  if( ( line = READLINE( m_reader ) ) == NULL )
1748  {
1749  THROW_IO_ERROR( "S_POLGON point count mismatch." );
1750  }
1751 
1752  // e.g. "Dl 23 44\n"
1753 
1754  if( !TESTLINE( "Dl" ) )
1755  {
1756  THROW_IO_ERROR( "Missing Dl point def" );
1757  }
1758 
1759  BIU x = biuParse( line + SZ( "Dl" ), &data );
1760  BIU y = biuParse( data );
1761 
1762  pts.emplace_back( x, y );
1763  }
1764 
1765  dwg->SetPolyPoints( pts );
1766  }
1767  break;
1768 
1769  default:
1770  // first switch code above prevents us from getting here.
1771  break;
1772  }
1773 
1774  // Check for a reasonable layer:
1775  // m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints
1776  // can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed.
1777  // @todo: changes use of EDGE_MODULE these footprints and allows only
1778  // m_Layer >= FIRST_NON_COPPER_LAYER
1779  if( layer < FIRST_LAYER || layer > LAST_NON_COPPER_LAYER )
1780  layer = SILKSCREEN_N_FRONT;
1781 
1782  dwg->SetWidth( width );
1783  dwg->SetLayer( leg_layer2new( m_cu_count, layer ) );
1784 
1785  EDGE_MODULE* em = dwg.release();
1786 
1787  aModule->Add( em );
1788 
1789  // this had been done at the MODULE level before, presumably because the
1790  // EDGE_MODULE needs to be already added to a module before this function will work.
1791  em->SetDrawCoord();
1792 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
polygon (not yet used for tracks, but could be in microwave apps)
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
usual segment : line with rounded ends
const LIB_ID & GetFPID() const
Definition: class_module.h:219
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
#define SILKSCREEN_N_FRONT
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
LINE_READER * m_reader
no ownership here.
#define NULL
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
Arcs (with rounded ends)
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
#define LAST_NON_COPPER_LAYER
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
#define FIRST_NON_COPPER_LAYER

References _, MODULE::Add(), PNS::angle(), biuParse(), degParse(), FIRST_NON_COPPER_LAYER, GetChars(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), intParse(), LAST_NON_COPPER_LAYER, layerParse(), leg_layer2new(), LINE_READER::Line(), LINE_READER::LineNumber(), m_cu_count, m_error, m_reader, NULL, READLINE, S_ARC, S_CIRCLE, S_POLYGON, S_SEGMENT, EDGE_MODULE::SetDrawCoord(), SILKSCREEN_N_FRONT, SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadMODULE().

◆ loadMODULE_TEXT()

void LEGACY_PLUGIN::loadMODULE_TEXT ( TEXTE_MODULE aText)
protected

Definition at line 1795 of file legacy_plugin.cpp.

1796 {
1797  const char* data;
1798  const char* txt_end;
1799  const char* line = m_reader->Line(); // current (old) line
1800  char* saveptr;
1801 
1802  // sscanf( line + 1, "%d %d %d %d %d %d %d %s %s %d %s",
1803  // &type, &m_Pos0.x, &m_Pos0.y, &m_Size.y, &m_Size.x,
1804  // &m_Orient, &m_Thickness, BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
1805 
1806  // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
1807  // or T1 0 500 600 400 900 80 M V 20 N"74LS245"
1808  // ouch, the last example has no space between N and "74LS245" !
1809  // that is an older version.
1810 
1811  int type = intParse( line+1, &data );
1812  BIU pos0_x = biuParse( data, &data );
1813  BIU pos0_y = biuParse( data, &data );
1814  BIU size0_y = biuParse( data, &data );
1815  BIU size0_x = biuParse( data, &data );
1816  double orient = degParse( data, &data );
1817  BIU thickn = biuParse( data, &data );
1818 
1819  // read the quoted text before the first call to strtok() which introduces
1820  // NULs into the string and chops it into mutliple C strings, something
1821  // ReadDelimitedText() cannot traverse.
1822 
1823  // convert the "quoted, escaped, UTF8, text" to a wxString, find it by skipping
1824  // as far forward as needed until the first double quote.
1825  txt_end = data + ReadDelimitedText( &m_field, data );
1826 
1827  aText->SetText( m_field );
1828 
1829  // after switching to strtok, there's no easy coming back because of the
1830  // embedded nul(s?) placed to the right of the current field.
1831  // (that's the reason why strtok was deprecated...)
1832  char* mirror = strtok_r( (char*) data, delims, &saveptr );
1833  char* hide = strtok_r( NULL, delims, &saveptr );
1834  char* tmp = strtok_r( NULL, delims, &saveptr );
1835 
1836  LAYER_NUM layer_num = tmp ? layerParse( tmp ) : SILKSCREEN_N_FRONT;
1837 
1838  char* italic = strtok_r( NULL, delims, &saveptr );
1839 
1840  char* hjust = strtok_r( (char*) txt_end, delims, &saveptr );
1841  char* vjust = strtok_r( NULL, delims, &saveptr );
1842 
1844  && type != TEXTE_MODULE::TEXT_is_VALUE )
1846 
1847  aText->SetType( static_cast<TEXTE_MODULE::TEXT_TYPE>( type ) );
1848 
1849  aText->SetPos0( wxPoint( pos0_x, pos0_y ) );
1850  aText->SetTextSize( wxSize( size0_x, size0_y ) );
1851 
1852  orient -= ( static_cast<MODULE*>( aText->GetParent() ) )->GetOrientation();
1853 
1854  aText->SetTextAngle( orient );
1855 
1856  // Set a reasonable width:
1857  if( thickn < 1 )
1858  thickn = 1;
1859 
1860  /* this is better left to the dialogs UIs
1861  aText->SetThickness( Clamp_Text_PenSize( thickn, aText->GetSize() ) );
1862  */
1863 
1864  aText->SetThickness( thickn );
1865 
1866  aText->SetMirrored( mirror && *mirror == 'M' );
1867 
1868  aText->SetVisible( !(hide && *hide == 'I') );
1869 
1870  aText->SetItalic( italic && *italic == 'I' );
1871 
1872  if( hjust )
1873  aText->SetHorizJustify( horizJustify( hjust ) );
1874 
1875  if( vjust )
1876  aText->SetVertJustify( vertJustify( vjust ) );
1877 
1878  // A protection against mal formed (or edited by hand) files:
1879  if( layer_num < FIRST_LAYER )
1880  layer_num = FIRST_LAYER;
1881  else if( layer_num > LAST_NON_COPPER_LAYER )
1882  layer_num = LAST_NON_COPPER_LAYER;
1883  else if( layer_num == LAYER_N_BACK )
1884  layer_num = SILKSCREEN_N_BACK;
1885  else if( layer_num == LAYER_N_FRONT )
1886  layer_num = SILKSCREEN_N_FRONT;
1887  else if( layer_num < LAYER_N_FRONT ) // this case is a internal layer
1888  layer_num = SILKSCREEN_N_FRONT;
1889 
1890  aText->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
1891 
1892  // Calculate the actual position.
1893  aText->SetDrawCoord();
1894 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
#define SILKSCREEN_N_BACK
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
#define LAYER_N_BACK
void SetItalic(bool isItalic)
Definition: eda_text.h:163
static const char delims[]
void SetVisible(bool aVisible)
Definition: eda_text.h:169
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
wxString m_field
reused to stuff MODULE fields.
#define SILKSCREEN_N_FRONT
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
LINE_READER * m_reader
no ownership here.
static EDA_TEXT_HJUSTIFY_T horizJustify(const char *horizontal)
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
#define NULL
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
LEGACY_PLUGIN::BIU BIU
void SetType(TEXT_TYPE aType)
void SetPos0(const wxPoint &aPos)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
#define LAYER_N_FRONT
#define FIRST_LAYER
static EDA_TEXT_VJUSTIFY_T vertJustify(const char *vertical)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
#define LAST_NON_COPPER_LAYER
void SetDrawCoord()
Set absolute coordinates.
char * strtok_r(char *str, const char *delim, char **nextp)
void SetTextAngle(double aAngle)
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
BOARD_ITEM_CONTAINER * GetParent() const
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143

References biuParse(), degParse(), delims, FIRST_LAYER, BOARD_ITEM::GetParent(), horizJustify(), intParse(), LAST_NON_COPPER_LAYER, LAYER_N_BACK, LAYER_N_FRONT, layerParse(), leg_layer2new(), LINE_READER::Line(), m_cu_count, m_field, m_reader, NULL, ReadDelimitedText(), TEXTE_MODULE::SetDrawCoord(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), TEXTE_MODULE::SetPos0(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), TEXTE_MODULE::SetType(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), SILKSCREEN_N_BACK, SILKSCREEN_N_FRONT, strtok_r(), TEXTE_MODULE::TEXT_is_DIVERS, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, and vertJustify().

Referenced by loadMODULE().

◆ loadNETCLASS()

void LEGACY_PLUGIN::loadNETCLASS ( )
protected

Definition at line 2398 of file legacy_plugin.cpp.

2399 {
2400  char buf[1024];
2401  wxString netname;
2402  char* line;
2403 
2404  // create an empty NETCLASS without a name, but do not add it to the BOARD
2405  // yet since that would bypass duplicate netclass name checking within the BOARD.
2406  // store it temporarily in an unique_ptr until successfully inserted into the BOARD
2407  // just before returning.
2408  NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
2409 
2410  while( ( line = READLINE( m_reader ) ) != NULL )
2411  {
2412  if( TESTLINE( "AddNet" ) ) // most frequent type of line
2413  {
2414  // e.g. "AddNet "V3.3D"\n"
2415  ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) );
2416  netname = FROM_UTF8( buf );
2417  nc->Add( netname );
2418  }
2419 
2420  else if( TESTLINE( "Clearance" ) )
2421  {
2422  BIU tmp = biuParse( line + SZ( "Clearance" ) );
2423  nc->SetClearance( tmp );
2424  }
2425 
2426  else if( TESTLINE( "TrackWidth" ) )
2427  {
2428  BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
2429  nc->SetTrackWidth( tmp );
2430  }
2431 
2432  else if( TESTLINE( "ViaDia" ) )
2433  {
2434  BIU tmp = biuParse( line + SZ( "ViaDia" ) );
2435  nc->SetViaDiameter( tmp );
2436  }
2437 
2438  else if( TESTLINE( "ViaDrill" ) )
2439  {
2440  BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
2441  nc->SetViaDrill( tmp );
2442  }
2443 
2444  else if( TESTLINE( "uViaDia" ) )
2445  {
2446  BIU tmp = biuParse( line + SZ( "uViaDia" ) );
2447  nc->SetuViaDiameter( tmp );
2448  }
2449 
2450  else if( TESTLINE( "uViaDrill" ) )
2451  {
2452  BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
2453  nc->SetuViaDrill( tmp );
2454  }
2455 
2456  else if( TESTLINE( "Name" ) )
2457  {
2458  ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
2459  nc->SetName( FROM_UTF8( buf ) );
2460  }
2461 
2462  else if( TESTLINE( "Desc" ) )
2463  {
2464  ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
2465  nc->SetDescription( FROM_UTF8( buf ) );
2466  }
2467 
2468  else if( TESTLINE( "$EndNCLASS" ) )
2469  {
2470  if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
2471  {
2472  // Must have been a name conflict, this is a bad board file.
2473  // User may have done a hand edit to the file.
2474 
2475  // unique_ptr will delete nc on this code path
2476 
2477  m_error.Printf( _( "duplicate NETCLASS name \"%s\"" ), nc->GetName().GetData() );
2479  }
2480 
2481  return; // preferred exit
2482  }
2483  }
2484 
2485  THROW_IO_ERROR( "Missing '$EndNCLASS'" );
2486 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define READLINE(rdr)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
bool Add(const NETCLASSPTR &aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:99
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.

References _, NETCLASSES::Add(), biuParse(), FROM_UTF8(), BOARD::GetDesignSettings(), m_board, m_error, BOARD_DESIGN_SETTINGS::m_NetClasses, m_reader, NULL, ReadDelimitedText(), READLINE, SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadNETINFO_ITEM()

void LEGACY_PLUGIN::loadNETINFO_ITEM ( )
protected

Definition at line 2059 of file legacy_plugin.cpp.

2060 {
2061  /* a net description is something like
2062  * $EQUIPOT
2063  * Na 5 "/BIT1"
2064  * St ~
2065  * $EndEQUIPOT
2066  */
2067 
2068  char buf[1024];
2069 
2070  NETINFO_ITEM* net = NULL;
2071  char* line;
2072  int netCode = 0;
2073 
2074  while( ( line = READLINE( m_reader ) ) != NULL )
2075  {
2076  const char* data;
2077 
2078  if( TESTLINE( "Na" ) )
2079  {
2080  // e.g. "Na 58 "/cpu.sch/PAD7"\r\n"
2081 
2082  netCode = intParse( line + SZ( "Na" ), &data );
2083 
2084  ReadDelimitedText( buf, data, sizeof(buf) );
2085 
2086  if( net == NULL )
2087  net = new NETINFO_ITEM( m_board, FROM_UTF8( buf ), netCode );
2088  else
2089  {
2090  THROW_IO_ERROR( "Two net definitions in '$EQUIPOT' block" );
2091  }
2092  }
2093 
2094  else if( TESTLINE( "$EndEQUIPOT" ) )
2095  {
2096  // net 0 should be already in list, so store this net
2097  // if it is not the net 0, or if the net 0 does not exists.
2098  if( net && ( net->GetNet() > 0 || m_board->FindNet( 0 ) == NULL ) )
2099  {
2100  m_board->Add( net );
2101 
2102  // Be sure we have room to store the net in m_netCodes
2103  if( (int)m_netCodes.size() <= netCode )
2104  m_netCodes.resize( netCode+1 );
2105 
2106  m_netCodes[netCode] = net->GetNet();
2107  net = NULL;
2108  }
2109  else
2110  {
2111  delete net;
2112  net = NULL; // Avoid double deletion.
2113  }
2114 
2115  return; // preferred exit
2116  }
2117  }
2118 
2119  // If we are here, there is an error.
2120  delete net;
2121  THROW_IO_ERROR( "Missing '$EndEQUIPOT'" );
2122 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
#define READLINE(rdr)
std::vector< int > m_netCodes
net codes mapping for boards being loaded
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
BOARD * m_board
which BOARD, no ownership here
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.

References BOARD::Add(), BOARD::FindNet(), FROM_UTF8(), NETINFO_ITEM::GetNet(), intParse(), m_board, m_netCodes, m_reader, NULL, ReadDelimitedText(), READLINE, SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadPAD()

void LEGACY_PLUGIN::loadPAD ( MODULE aModule)
protected

Definition at line 1418 of file legacy_plugin.cpp.

1419 {
1420  unique_ptr<D_PAD> pad( new D_PAD( aModule ) );
1421  char* line;
1422  char* saveptr;
1423 
1424  while( ( line = READLINE( m_reader ) ) != NULL )
1425  {
1426  const char* data;
1427 
1428  if( TESTLINE( "Sh" ) ) // (Sh)ape and padname
1429  {
1430  // e.g. "Sh "A2" C 520 520 0 0 900"
1431  // or "Sh "1" R 157 1378 0 0 900"
1432 
1433  // mypadname is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1,
1434  // but for BOARD_FORMAT_VERSION 2, it is UTF8 from disk.
1435  // So we have to go through two code paths. Moving forward
1436  // padnames will be in UTF8 on disk, as are all KiCad strings on disk.
1437  char mypadname[50];
1438 
1439  data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace
1440 
1441  data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1; // +1 trailing whitespace
1442 
1443  // sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient );
1444  while( isSpace( *data ) )
1445  ++data;
1446 
1447  unsigned char padchar = (unsigned char) *data++;
1448  int padshape;
1449 
1450  BIU size_x = biuParse( data, &data );
1451  BIU size_y = biuParse( data, &data );
1452  BIU delta_x = biuParse( data, &data );
1453  BIU delta_y = biuParse( data, &data );
1454  double orient = degParse( data );
1455 
1456  switch( padchar )
1457  {
1458  case 'C': padshape = PAD_SHAPE_CIRCLE; break;
1459  case 'R': padshape = PAD_SHAPE_RECT; break;
1460  case 'O': padshape = PAD_SHAPE_OVAL; break;
1461  case 'T': padshape = PAD_SHAPE_TRAPEZOID; break;
1462  default:
1463  m_error.Printf( _( "Unknown padshape '%c=0x%02x' on line: %d of footprint: \"%s\"" ),
1464  padchar,
1465  padchar,
1466  m_reader->LineNumber(),
1467  GetChars( aModule->GetFPID().GetLibItemName() )
1468  );
1470  }
1471 
1472  // go through a wxString to establish a universal character set properly
1473  wxString padname;
1474 
1475  if( m_loading_format_version == 1 )
1476  {
1477  // add 8 bit bytes, file format 1 was KiCad font type byte,
1478  // simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1)
1479  const unsigned char* cp = (unsigned char*) mypadname;
1480  while( *cp )
1481  {
1482  padname += *cp++; // unsigned, ls 8 bits only
1483  }
1484  }
1485  else
1486  {
1487  // version 2, which is UTF8.
1488  padname = FROM_UTF8( mypadname );
1489  }
1490  // chances are both were ASCII, but why take chances?
1491 
1492  pad->SetName( padname );
1493  pad->SetShape( PAD_SHAPE_T( padshape ) );
1494  pad->SetSize( wxSize( size_x, size_y ) );
1495  pad->SetDelta( wxSize( delta_x, delta_y ) );
1496  pad->SetOrientation( orient );
1497  }
1498 
1499  else if( TESTLINE( "Dr" ) ) // (Dr)ill
1500  {
1501  // e.g. "Dr 350 0 0" or "Dr 0 0 0 O 0 0"
1502  // sscanf( PtLine, "%d %d %d %s %d %d", &m_Drill.x, &m_Offset.x, &m_Offset.y, BufCar, &dx, &dy );
1503 
1504  BIU drill_x = biuParse( line + SZ( "Dr" ), &data );
1505  BIU drill_y = drill_x;
1506  BIU offs_x = biuParse( data, &data );
1507  BIU offs_y = biuParse( data, &data );
1508 
1510 
1511  data = strtok_r( (char*) data, delims, &saveptr );
1512  if( data ) // optional shape
1513  {
1514  if( data[0] == 'O' )
1515  {
1516  drShape = PAD_DRILL_SHAPE_OBLONG;
1517 
1518  data = strtok_r( NULL, delims, &saveptr );
1519  drill_x = biuParse( data );
1520 
1521  data = strtok_r( NULL, delims, &saveptr );
1522  drill_y = biuParse( data );
1523  }
1524  }
1525 
1526  pad->SetDrillShape( drShape );
1527  pad->SetOffset( wxPoint( offs_x, offs_y ) );
1528  pad->SetDrillSize( wxSize( drill_x, drill_y ) );
1529  }
1530 
1531  else if( TESTLINE( "At" ) ) // (At)tribute
1532  {
1533  // e.g. "At SMD N 00888000"
1534  // sscanf( PtLine, "%s %s %X", BufLine, BufCar, &m_layerMask );
1535 
1536  PAD_ATTR_T attribute;
1537 
1538  data = strtok_r( line + SZ( "At" ), delims, &saveptr );
1539 
1540  if( !strcmp( data, "SMD" ) )
1541  attribute = PAD_ATTRIB_SMD;
1542  else if( !strcmp( data, "CONN" ) )
1543  attribute = PAD_ATTRIB_CONN;
1544  else if( !strcmp( data, "HOLE" ) )
1545  attribute = PAD_ATTRIB_HOLE_NOT_PLATED;
1546  else
1547  attribute = PAD_ATTRIB_STANDARD;
1548 
1549  strtok_r( NULL, delims, &saveptr ); // skip BufCar
1550  data = strtok_r( NULL, delims, &saveptr );
1551 
1552  LEG_MASK layer_mask = hexParse( data );
1553 
1554  pad->SetLayerSet( leg_mask2new( m_cu_count, layer_mask ) );
1555  pad->SetAttribute( attribute );
1556  }
1557 
1558  else if( TESTLINE( "Ne" ) ) // (Ne)tname
1559  {
1560  // e.g. "Ne 461 "V5.0"
1561 
1562  char buf[1024]; // can be fairly long
1563  int netcode = intParse( line + SZ( "Ne" ), &data );
1564 
1565  // Store the new code mapping
1566  pad->SetNetCode( getNetCode( netcode ) );
1567 
1568  // read Netname
1569  ReadDelimitedText( buf, data, sizeof(buf) );
1570 #ifndef NDEBUG
1571  if( m_board )
1572  assert( m_board->FindNet( getNetCode( netcode ) )->GetNetname() ==
1573  FROM_UTF8( StrPurge( buf ) ) );
1574 #endif /* NDEBUG */
1575  }
1576 
1577  else if( TESTLINE( "Po" ) ) // (Po)sition
1578  {
1579  // e.g. "Po 500 -500"
1580  wxPoint pos;
1581 
1582  pos.x = biuParse( line + SZ( "Po" ), &data );
1583  pos.y = biuParse( data );
1584 
1585  pad->SetPos0( pos );
1586  // pad->SetPosition( pos ); set at function return
1587  }
1588 
1589  else if( TESTLINE( "Le" ) )
1590  {
1591  BIU tmp = biuParse( line + SZ( "Le" ) );
1592  pad->SetPadToDieLength( tmp );
1593  }
1594 
1595  else if( TESTLINE( ".SolderMask" ) )
1596  {
1597  BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
1598  pad->SetLocalSolderMaskMargin( tmp );
1599  }
1600 
1601  else if( TESTLINE( ".SolderPasteRatio" ) )
1602  {
1603  double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
1604  pad->SetLocalSolderPasteMarginRatio( tmp );
1605  }
1606 
1607  else if( TESTLINE( ".SolderPaste" ) )
1608  {
1609  BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
1610  pad->SetLocalSolderPasteMargin( tmp );
1611  }
1612 
1613  else if( TESTLINE( ".LocalClearance" ) )
1614  {
1615  BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
1616  pad->SetLocalClearance( tmp );
1617  }
1618 
1619  else if( TESTLINE( ".ZoneConnection" ) )
1620  {
1621  int tmp = intParse( line + SZ( ".ZoneConnection" ) );
1622  pad->SetZoneConnection( (ZONE_CONNECTION) tmp );
1623  }
1624 
1625  else if( TESTLINE( ".ThermalWidth" ) )
1626  {
1627  BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
1628  pad->SetThermalWidth( tmp );
1629  }
1630 
1631  else if( TESTLINE( ".ThermalGap" ) )
1632  {
1633  BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
1634  pad->SetThermalGap( tmp );
1635  }
1636 
1637  else if( TESTLINE( "$EndPAD" ) )
1638  {
1639  // pad's "Position" is not relative to the module's,
1640  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1641 
1642  wxPoint padpos = pad->GetPos0();
1643 
1644  RotatePoint( &padpos, aModule->GetOrientation() );
1645 
1646  pad->SetPosition( padpos + aModule->GetPosition() );
1647 
1648  aModule->Add( pad.release() );
1649  return; // preferred exit
1650  }
1651  }
1652 
1653  THROW_IO_ERROR( "Missing '$EndPAD'" );
1654 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:50
double GetOrientation() const
Definition: class_module.h:215
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
PAD_ATTR_T
Enum PAD_ATTR_T is the set of pad shapes, used with D_PAD::{Set,Get}Attribute() The double name is fo...
Definition: pad_shapes.h:59
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
static const char delims[]
const LIB_ID & GetFPID() const
Definition: class_module.h:219
#define READLINE(rdr)
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
PAD_DRILL_SHAPE_T
Enum PAD_DRILL_SHAPE_T is the set of pad drill shapes, used with D_PAD::{Set,Get}DrillShape()
Definition: pad_shapes.h:47
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
PAD_SHAPE_T
Enum PAD_SHAPE_T is the set of pad shapes, used with D_PAD::{Set,Get}Shape()
Definition: pad_shapes.h:31
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
LINE_READER * m_reader
no ownership here.
#define NULL
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
#define THROW_IO_ERROR(msg)
unsigned LEG_MASK
LEGACY_PLUGIN::BIU BIU
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
BOARD * m_board
which BOARD, no ownership here
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
static bool isSpace(int c)
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
static LSET leg_mask2new(int cu_count, unsigned aMask)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code
const wxPoint GetPosition() const override
Definition: class_module.h:210
#define TESTLINE(x)
C string compare test for a specific length of characters.

References _, MODULE::Add(), biuParse(), degParse(), delims, BOARD::FindNet(), FROM_UTF8(), GetChars(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), getNetCode(), NETINFO_ITEM::GetNetname(), MODULE::GetOrientation(), MODULE::GetPosition(), hexParse(), intParse(), isSpace(), leg_mask2new(), LINE_READER::LineNumber(), m_board, m_cu_count, m_error, m_loading_format_version, m_reader, NULL, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_CIRCLE, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_TRAPEZOID, ReadDelimitedText(), READLINE, RotatePoint(), StrPurge(), strtok_r(), SZ, TESTLINE, THROW_IO_ERROR, wxPoint::x, and wxPoint::y.

Referenced by loadMODULE().

◆ loadPCB_LINE()

void LEGACY_PLUGIN::loadPCB_LINE ( )
protected

Definition at line 1946 of file legacy_plugin.cpp.

1947 {
1948  /* example:
1949  $DRAWSEGMENT
1950  Po 0 57500 -1000 57500 0 150
1951  De 24 0 900 0 0
1952  $EndDRAWSEGMENT
1953  */
1954 
1955  unique_ptr<DRAWSEGMENT> dseg( new DRAWSEGMENT( m_board ) );
1956 
1957  char* line;
1958  char* saveptr;
1959 
1960  while( ( line = READLINE( m_reader ) ) != NULL )
1961  {
1962  const char* data;
1963 
1964  if( TESTLINE( "Po" ) )
1965  {
1966  // sscanf( line + 2, " %d %d %d %d %d %d", &m_Shape, &m_Start.x, &m_Start.y, &m_End.x, &m_End.y, &m_Width );
1967  int shape = intParse( line + SZ( "Po" ), &data );
1968  BIU start_x = biuParse( data, &data );
1969  BIU start_y = biuParse( data, &data );
1970  BIU end_x = biuParse( data, &data );
1971  BIU end_y = biuParse( data, &data );
1972  BIU width = biuParse( data );
1973 
1974  if( width < 0 )
1975  width = 0;
1976 
1977  dseg->SetShape( STROKE_T( shape ) );
1978  dseg->SetWidth( width );
1979  dseg->SetStart( wxPoint( start_x, start_y ) );
1980  dseg->SetEnd( wxPoint( end_x, end_y ) );
1981  }
1982 
1983  else if( TESTLINE( "De" ) )
1984  {
1985  BIU x = 0;
1986  BIU y;
1987 
1988  data = strtok_r( line + SZ( "De" ), delims, &saveptr );
1989  for( int i = 0; data; ++i, data = strtok_r( NULL, delims, &saveptr ) )
1990  {
1991  switch( i )
1992  {
1993  case 0:
1994  LAYER_NUM layer;
1995  layer = layerParse( data );
1996 
1997  if( layer < FIRST_NON_COPPER_LAYER )
1998  layer = FIRST_NON_COPPER_LAYER;
1999 
2000  else if( layer > LAST_NON_COPPER_LAYER )
2001  layer = LAST_NON_COPPER_LAYER;
2002 
2003  dseg->SetLayer( leg_layer2new( m_cu_count, layer ) );
2004  break;
2005  case 1:
2006  int mtype;
2007  mtype = intParse( data );
2008  dseg->SetType( mtype ); // m_Type
2009  break;
2010  case 2:
2011  double angle;
2012  angle = degParse( data );
2013  dseg->SetAngle( angle ); // m_Angle
2014  break;
2015  case 3:
2016  timestamp_t timestamp;
2017  timestamp = hexParse( data );
2018  dseg->SetTimeStamp( timestamp );
2019  break;
2020  case 4:
2021  STATUS_FLAGS state;
2022  state = static_cast<STATUS_FLAGS>( hexParse( data ) );
2023  dseg->SetState( state, true );
2024  break;
2025 
2026  // Bezier Control Points
2027  case 5:
2028  x = biuParse( data );
2029  break;
2030  case 6:
2031  y = biuParse( data );
2032  dseg->SetBezControl1( wxPoint( x, y ) );
2033  break;
2034 
2035  case 7:
2036  x = biuParse( data );
2037  break;
2038  case 8:
2039  y = biuParse( data );
2040  dseg->SetBezControl2( wxPoint( x, y ) );
2041  break;
2042 
2043  default:
2044  break;
2045  }
2046  }
2047  }
2048 
2049  else if( TESTLINE( "$EndDRAWSEGMENT" ) )
2050  {
2051  m_board->Add( dseg.release(), ADD_MODE::APPEND );
2052  return; // preferred exit
2053  }
2054  }
2055 
2056  THROW_IO_ERROR( "Missing '$EndDRAWSEGMENT'" );
2057 }
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static const char delims[]
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
#define NULL
unsigned STATUS_FLAGS
Definition: base_struct.h:156
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
#define LAST_NON_COPPER_LAYER
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
#define FIRST_NON_COPPER_LAYER

References BOARD::Add(), PNS::angle(), APPEND, biuParse(), degParse(), delims, FIRST_NON_COPPER_LAYER, hexParse(), intParse(), LAST_NON_COPPER_LAYER, layerParse(), leg_layer2new(), m_board, m_cu_count, m_reader, NULL, READLINE, strtok_r(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadPCB_TARGET()

void LEGACY_PLUGIN::loadPCB_TARGET ( )
protected

Definition at line 2986 of file legacy_plugin.cpp.

2987 {
2988  char* line;
2989 
2990  while( ( line = READLINE( m_reader ) ) != NULL )
2991  {
2992  const char* data;
2993 
2994  if( TESTLINE( "$EndPCB_TARGET" ) || TESTLINE( "$EndMIREPCB" ) )
2995  {
2996  return; // preferred exit
2997  }
2998 
2999  else if( TESTLINE( "Po" ) )
3000  {
3001  // sscanf( Line + 2, " %X %d %d %d %d %d %lX", &m_Shape, &m_Layer, &m_Pos.x, &m_Pos.y, &m_Size, &m_Width, &m_TimeStamp );
3002 
3003  int shape = intParse( line + SZ( "Po" ), &data );
3004 
3005  LAYER_NUM layer_num = layerParse( data, &data );
3006 
3007  BIU pos_x = biuParse( data, &data );
3008  BIU pos_y = biuParse( data, &data );
3009  BIU size = biuParse( data, &data );
3010  BIU width = biuParse( data, &data );
3011  timestamp_t timestamp = hexParse( data );
3012 
3013  if( layer_num < FIRST_NON_COPPER_LAYER )
3014  layer_num = FIRST_NON_COPPER_LAYER;
3015 
3016  else if( layer_num > LAST_NON_COPPER_LAYER )
3017  layer_num = LAST_NON_COPPER_LAYER;
3018 
3019  PCB_TARGET* t = new PCB_TARGET( m_board, shape, leg_layer2new( m_cu_count, layer_num ),
3020  wxPoint( pos_x, pos_y ), size, width );
3021  m_board->Add( t, ADD_MODE::APPEND );
3022 
3023  t->SetTimeStamp( timestamp );
3024  }
3025  }
3026 
3027  THROW_IO_ERROR( "Missing '$EndDIMENSION'" );
3028 }
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
#define NULL
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
#define LAST_NON_COPPER_LAYER
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
#define FIRST_NON_COPPER_LAYER
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

References BOARD::Add(), APPEND, biuParse(), FIRST_NON_COPPER_LAYER, hexParse(), intParse(), LAST_NON_COPPER_LAYER, layerParse(), leg_layer2new(), m_board, m_cu_count, m_reader, NULL, READLINE, EDA_ITEM::SetTimeStamp(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadPCB_TEXT()

void LEGACY_PLUGIN::loadPCB_TEXT ( )
protected

Definition at line 2125 of file legacy_plugin.cpp.

2126 {
2127  /* examples:
2128  For a single line text:
2129  ----------------------
2130  $TEXTPCB
2131  Te "Text example"
2132  Po 66750 53450 600 800 150 0
2133  De 24 1 0 Italic
2134  $EndTEXTPCB
2135 
2136  For a multi line text:
2137  ---------------------
2138  $TEXTPCB
2139  Te "Text example"
2140  Nl "Line 2"
2141  Po 66750 53450 600 800 150 0
2142  De 24 1 0 Italic
2143  $EndTEXTPCB
2144  Nl "line nn" is a line added to the current text
2145  */
2146 
2147  char text[1024];
2148 
2149  // maybe someday a constructor that takes all this data in one call?
2150  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
2151  m_board->Add( pcbtxt, ADD_MODE::APPEND );
2152 
2153  char* line;
2154  char* saveptr;
2155 
2156  while( ( line = READLINE( m_reader ) ) != NULL )
2157  {
2158  const char* data;
2159 
2160  if( TESTLINE( "Te" ) ) // Text line (or first line for multi line texts)
2161  {
2162  ReadDelimitedText( text, line + SZ( "Te" ), sizeof(text) );
2163  pcbtxt->SetText( FROM_UTF8( text ) );
2164  }
2165 
2166  else if( TESTLINE( "nl" ) ) // next line of the current text
2167  {
2168  ReadDelimitedText( text, line + SZ( "nl" ), sizeof(text) );
2169  pcbtxt->SetText( pcbtxt->GetText() + wxChar( '\n' ) + FROM_UTF8( text ) );
2170  }
2171 
2172  else if( TESTLINE( "Po" ) )
2173  {
2174  // sscanf( line + 2, " %d %d %d %d %d %d", &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y, &m_Thickness, &m_Orient );
2175  wxSize size;
2176 
2177  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
2178  BIU pos_y = biuParse( data, &data );
2179  size.x = biuParse( data, &data );
2180  size.y = biuParse( data, &data );
2181  BIU thickn = biuParse( data, &data );
2182  double angle = degParse( data );
2183 
2184  pcbtxt->SetTextSize( size );
2185 
2186  pcbtxt->SetThickness( thickn );
2187  pcbtxt->SetTextAngle( angle );
2188 
2189  pcbtxt->SetTextPos( wxPoint( pos_x, pos_y ) );
2190  }
2191 
2192  else if( TESTLINE( "De" ) )
2193  {
2194  // e.g. "De 21 1 0 Normal C\r\n"
2195  // sscanf( line + 2, " %d %d %lX %s %c\n", &m_Layer, &normal_display, &m_TimeStamp, style, &hJustify );
2196 
2197  LAYER_NUM layer_num = layerParse( line + SZ( "De" ), &data );
2198  int notMirrored = intParse( data, &data );
2199  timestamp_t timestamp = hexParse( data, &data );
2200  char* style = strtok_r( (char*) data, delims, &saveptr );
2201  char* hJustify = strtok_r( NULL, delims, &saveptr );
2202  char* vJustify = strtok_r( NULL, delims, &saveptr );
2203 
2204  pcbtxt->SetMirrored( !notMirrored );
2205  pcbtxt->SetTimeStamp( timestamp );
2206  pcbtxt->SetItalic( !strcmp( style, "Italic" ) );
2207 
2208  if( hJustify )
2209  pcbtxt->SetHorizJustify( horizJustify( hJustify ) );
2210  else
2211  {
2212  // boom, somebody changed a constructor, I was relying on this:
2213  wxASSERT( pcbtxt->GetHorizJustify() == GR_TEXT_HJUSTIFY_CENTER );
2214  }
2215 
2216  if( vJustify )
2217  pcbtxt->SetVertJustify( vertJustify( vJustify ) );
2218 
2219  if( layer_num < FIRST_COPPER_LAYER )
2220  layer_num = FIRST_COPPER_LAYER;
2221  else if( layer_num > LAST_NON_COPPER_LAYER )
2222  layer_num = LAST_NON_COPPER_LAYER;
2223 
2224  if( layer_num >= FIRST_NON_COPPER_LAYER ||
2225  is_leg_copperlayer_valid( m_cu_count, layer_num ) )
2226  pcbtxt->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2227  else // not perfect, but putting this text on front layer is a workaround
2228  pcbtxt->SetLayer( F_Cu );
2229  }
2230 
2231  else if( TESTLINE( "$EndTEXTPCB" ) )
2232  {
2233  return; // preferred exit
2234  }
2235  }
2236 
2237  THROW_IO_ERROR( "Missing '$EndTEXTPCB'" );
2238 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
void SetTextAngle(double aAngle)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
void SetItalic(bool isItalic)
Definition: eda_text.h:163
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
static const char delims[]
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
#define READLINE(rdr)
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
static EDA_TEXT_HJUSTIFY_T horizJustify(const char *horizontal)
bool is_leg_copperlayer_valid(int aCu_Count, LAYER_NUM aLegacyLayerNum)
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
#define NULL
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
static EDA_TEXT_VJUSTIFY_T vertJustify(const char *vertical)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
#define LAST_NON_COPPER_LAYER
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
#define FIRST_COPPER_LAYER
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
#define TESTLINE(x)
C string compare test for a specific length of characters.
#define FIRST_NON_COPPER_LAYER
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

References BOARD::Add(), PNS::angle(), APPEND, biuParse(), degParse(), delims, F_Cu, FIRST_COPPER_LAYER, FIRST_NON_COPPER_LAYER, FROM_UTF8(), EDA_TEXT::GetHorizJustify(), EDA_TEXT::GetText(), GR_TEXT_HJUSTIFY_CENTER, hexParse(), horizJustify(), intParse(), is_leg_copperlayer_valid(), LAST_NON_COPPER_LAYER, layerParse(), leg_layer2new(), m_board, m_cu_count, m_reader, NULL, ReadDelimitedText(), READLINE, EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), EDA_TEXT::SetText(), TEXTE_PCB::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), EDA_TEXT::SetVertJustify(), strtok_r(), SZ, TESTLINE, THROW_IO_ERROR, and vertJustify().

Referenced by loadAllSections().

◆ loadSETUP()

void LEGACY_PLUGIN::loadSETUP ( )
protected

Definition at line 859 of file legacy_plugin.cpp.

860 {
861  NETCLASSPTR netclass_default = m_board->GetDesignSettings().GetDefault();
862  // TODO Orson: is it really necessary to first operate on a copy and then apply it?
863  // would not it be better to use reference here and apply all the changes instantly?
866  char* line;
867  char* saveptr;
868 
869  while( ( line = READLINE( m_reader ) ) != NULL )
870  {
871  const char* data;
872 
873  if( TESTLINE( "PcbPlotParams" ) )
874  {
875  PCB_PLOT_PARAMS plot_opts;
876 
877  PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), m_reader->GetSource() );
878 
879  plot_opts.Parse( &parser );
880 
881  m_board->SetPlotOptions( plot_opts );
882  }
883 
884  else if( TESTLINE( "AuxiliaryAxisOrg" ) )
885  {
886  BIU gx = biuParse( line + SZ( "AuxiliaryAxisOrg" ), &data );
887  BIU gy = biuParse( data );
888 
889  // m_board->SetAuxOrigin( wxPoint( gx, gy ) ); gets overwritten by SetDesignSettings() below
890  bds.m_AuxOrigin = wxPoint( gx, gy );
891  }
892 
893  /* Done from $General above's "LayerCount"
894  else if( TESTLINE( "Layers" ) )
895  {
896  int tmp = intParse( line + SZ( "Layers" ) );
897  m_board->SetCopperLayerCount( tmp );
898 
899  m_cu_count = tmp;
900  }
901  */
902 
903  else if( TESTSUBSTR( "Layer[" ) )
904  {
905  // eg: "Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>"
906 
907  LAYER_NUM layer_num = layerParse( line + SZ( "Layer[" ), &data );
908  PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
909 
910  /*
911  switch( layer_num )
912  {
913  case LAYER_N_BACK:
914  layer_id = B_Cu;
915  break;
916 
917  case LAYER_N_FRONT:
918  layer_id = F_Cu;
919  break;
920 
921  default:
922  layer_id = PCB_LAYER_ID( layer_num );
923  }
924  */
925 
926  data = strtok_r( (char*) data+1, delims, &saveptr ); // +1 for ']'
927  if( data )
928  {
929  wxString layerName = FROM_UTF8( data );
930  m_board->SetLayerName( layer_id, layerName );
931 
932  data = strtok_r( NULL, delims, &saveptr );
933  if( data ) // optional in old board files
934  {
935  LAYER_T type = LAYER::ParseType( data );
936  m_board->SetLayerType( layer_id, type );
937  }
938  }
939  }
940 
941  else if( TESTLINE( "TrackWidth" ) )
942  {
943  BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
944  netclass_default->SetTrackWidth( tmp );
945  }
946 
947  else if( TESTLINE( "TrackWidthList" ) )
948  {
949  BIU tmp = biuParse( line + SZ( "TrackWidthList" ) );
950  bds.m_TrackWidthList.push_back( tmp );
951  }
952 
953  else if( TESTLINE( "TrackClearence" ) )
954  {
955  BIU tmp = biuParse( line + SZ( "TrackClearence" ) );
956  netclass_default->SetClearance( tmp );
957  }
958 
959  else if( TESTLINE( "TrackMinWidth" ) )
960  {
961  BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
962  bds.m_TrackMinWidth = tmp;
963  }
964 
965  else if( TESTLINE( "ZoneClearence" ) )
966  {
967  BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
968  zs.m_ZoneClearance = tmp;
969  }
970 
971  else if( TESTLINE( "Zone_45_Only" ) )
972  {
973  bool tmp = (bool) intParse( line + SZ( "Zone_45_Only" ) );
974  zs.m_Zone_45_Only = tmp;
975  }
976 
977  else if( TESTLINE( "DrawSegmWidth" ) )
978  {
979  BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
980  bds.m_LineThickness[ LAYER_CLASS_COPPER ] = tmp;
981  }
982 
983  else if( TESTLINE( "EdgeSegmWidth" ) )
984  {
985  BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
986  bds.m_LineThickness[ LAYER_CLASS_EDGES ] = tmp;
987  }
988 
989  else if( TESTLINE( "ViaMinSize" ) )
990  {
991  BIU tmp = biuParse( line + SZ( "ViaMinSize" ) );
992  bds.m_ViasMinSize = tmp;
993  }
994 
995  else if( TESTLINE( "MicroViaMinSize" ) )
996  {
997  BIU tmp = biuParse( line + SZ( "MicroViaMinSize" ) );
998  bds.m_MicroViasMinSize = tmp;
999  }
1000 
1001  else if( TESTLINE( "ViaSizeList" ) )
1002  {
1003  // e.g. "ViaSizeList DIAMETER [DRILL]"
1004 
1005  BIU drill = 0;
1006  BIU diameter = biuParse( line + SZ( "ViaSizeList" ), &data );
1007 
1008  data = strtok_r( (char*) data, delims, &saveptr );
1009  if( data ) // DRILL may not be present ?
1010  drill = biuParse( data );
1011 
1012  bds.m_ViasDimensionsList.emplace_back( diameter,
1013  drill );
1014  }
1015 
1016  else if( TESTLINE( "ViaSize" ) )
1017  {
1018  BIU tmp = biuParse( line + SZ( "ViaSize" ) );
1019  netclass_default->SetViaDiameter( tmp );
1020  }
1021 
1022  else if( TESTLINE( "ViaDrill" ) )
1023  {
1024  BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
1025  netclass_default->SetViaDrill( tmp );
1026  }
1027 
1028  else if( TESTLINE( "ViaMinDrill" ) )
1029  {
1030  BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
1031  bds.m_ViasMinDrill = tmp;
1032  }
1033 
1034  else if( TESTLINE( "MicroViaSize" ) )
1035  {
1036  BIU tmp = biuParse( line + SZ( "MicroViaSize" ) );
1037  netclass_default->SetuViaDiameter( tmp );
1038  }
1039 
1040  else if( TESTLINE( "MicroViaDrill" ) )
1041  {
1042  BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
1043  netclass_default->SetuViaDrill( tmp );
1044  }
1045 
1046  else if( TESTLINE( "MicroViaMinDrill" ) )
1047  {
1048  BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
1049  bds.m_MicroViasMinDrill = tmp;
1050  }
1051 
1052  else if( TESTLINE( "MicroViasAllowed" ) )
1053  {
1054  int tmp = intParse( line + SZ( "MicroViasAllowed" ) );
1055  bds.m_MicroViasAllowed = tmp;
1056  }
1057 
1058  else if( TESTLINE( "TextPcbWidth" ) )
1059  {
1060  BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
1061  bds.m_TextThickness[ LAYER_CLASS_COPPER ] = tmp;
1062  }
1063 
1064  else if( TESTLINE( "TextPcbSize" ) )
1065  {
1066  BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
1067  BIU y = biuParse( data );
1068 
1069  bds.m_TextSize[ LAYER_CLASS_COPPER ] = wxSize( x, y );
1070  }
1071 
1072  else if( TESTLINE( "EdgeModWidth" ) )
1073  {
1074  BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
1075  bds.m_LineThickness[ LAYER_CLASS_SILK ] = tmp;
1076  bds.m_LineThickness[ LAYER_CLASS_OTHERS ] = tmp;
1077  }
1078 
1079  else if( TESTLINE( "TextModWidth" ) )
1080  {
1081  BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
1082  bds.m_TextThickness[ LAYER_CLASS_SILK ] = tmp;
1083  bds.m_TextThickness[ LAYER_CLASS_OTHERS ] = tmp;
1084  }
1085 
1086  else if( TESTLINE( "TextModSize" ) )
1087  {
1088  BIU x = biuParse( line + SZ( "TextModSize" ), &data );
1089  BIU y = biuParse( data );
1090 
1091  bds.m_TextSize[ LAYER_CLASS_SILK ] = wxSize( x, y );
1092  bds.m_TextSize[ LAYER_CLASS_OTHERS ] = wxSize( x, y );
1093  }
1094 
1095  else if( TESTLINE( "PadSize" ) )
1096  {
1097  BIU x = biuParse( line + SZ( "PadSize" ), &data );
1098  BIU y = biuParse( data );
1099 
1100  bds.m_Pad_Master.SetSize( wxSize( x, y ) );
1101  }
1102 
1103  else if( TESTLINE( "PadDrill" ) )
1104  {
1105  BIU tmp = biuParse( line + SZ( "PadDrill" ) );
1106  bds.m_Pad_Master.SetDrillSize( wxSize( tmp, tmp ) );
1107  }
1108 
1109  else if( TESTLINE( "Pad2MaskClearance" ) )
1110  {
1111  BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
1112  bds.m_SolderMaskMargin = tmp;
1113  }
1114 
1115  else if( TESTLINE( "SolderMaskMinWidth" ) )
1116  {
1117  BIU tmp = biuParse( line + SZ( "SolderMaskMinWidth" ) );
1118  bds.m_SolderMaskMinWidth = tmp;
1119  }
1120 
1121  else if( TESTLINE( "Pad2PasteClearance" ) )
1122  {
1123  BIU tmp = biuParse( line + SZ( "Pad2PasteClearance" ) );
1124  bds.m_SolderPasteMargin = tmp;
1125  }
1126 
1127  else if( TESTLINE( "Pad2PasteClearanceRatio" ) )
1128  {
1129  double ratio = atof( line + SZ( "Pad2PasteClearanceRatio" ) );
1130  bds.m_SolderPasteMarginRatio = ratio;
1131  }
1132 
1133  else if( TESTLINE( "GridOrigin" ) )
1134  {
1135  BIU x = biuParse( line + SZ( "GridOrigin" ), &data );
1136  BIU y = biuParse( data );
1137 
1138  // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten by SetDesignSettings() below
1139  bds.m_GridOrigin = wxPoint( x, y );
1140  }
1141 
1142  else if( TESTLINE( "VisibleElements" ) )
1143  {
1144  int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
1145  bds.SetVisibleElements( visibleElements );
1146  }
1147 
1148  else if( TESTLINE( "$EndSETUP" ) )
1149  {
1150  m_board->SetDesignSettings( bds );
1151  m_board->SetZoneSettings( zs );
1152 
1153  // Very old *.brd file does not have NETCLASSes
1154  // "TrackWidth", "ViaSize", "ViaDrill", "ViaMinSize", and "TrackClearence" were
1155  // defined in SETUP; these values are put into the default NETCLASS until later board
1156  // load code should override them. *.brd files which have been saved with knowledge
1157  // of NETCLASSes will override these defaults, very old boards (before 2009) will not
1158  // and use the setup values.
1159  // However these values should be the same as default NETCLASS.
1160 
1161  return; // preferred exit
1162  }
1163  }
1164 
1165  /*
1166  * Ensure tracks and vias sizes lists are ok:
1167  * Sort lists by by increasing value and remove duplicates
1168  * (the first value is not tested, because it is the netclass value)
1169  */
1170  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
1171  sort( designSettings.m_ViasDimensionsList.begin() + 1, designSettings.m_ViasDimensionsList.end() );
1172  sort( designSettings.m_TrackWidthList.begin() + 1, designSettings.m_TrackWidthList.end() );
1173 
1174  for( unsigned ii = 1; ii < designSettings.m_ViasDimensionsList.size() - 1; ii++ )
1175  {
1176  if( designSettings.m_ViasDimensionsList[ii] == designSettings.m_ViasDimensionsList[ii + 1] )
1177  {
1178  designSettings.m_ViasDimensionsList.erase( designSettings.m_ViasDimensionsList.begin() + ii );
1179  ii--;
1180  }
1181  }
1182 
1183  for( unsigned ii = 1; ii < designSettings.m_TrackWidthList.size() - 1; ii++ )
1184  {
1185  if( designSettings.m_TrackWidthList[ii] == designSettings.m_TrackWidthList[ii + 1] )
1186  {
1187  designSettings.m_TrackWidthList.erase( designSettings.m_TrackWidthList.begin() + ii );
1188  ii--;
1189  }
1190  }
1191 }
int m_SolderMaskMargin
Solder mask margin.
wxPoint m_GridOrigin
origin for grid offsets
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
int m_SolderPasteMargin
Solder paste margin absolute value.
PCB_PLOT_PARAMS_PARSER is the parser class for PCB_PLOT_PARAMS.
std::vector< int > m_TrackWidthList
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static const char delims[]
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define READLINE(rdr)
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:305
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
wxSize m_TextSize[LAYER_CLASS_COUNT]
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
PCB_LAYER_ID
A quick note on layer IDs:
LINE_READER * m_reader
no ownership here.
int m_TextThickness[LAYER_CLASS_COUNT]
#define NULL
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
LAYER_T
Enum LAYER_T gives the allowed types of layers, same as Specctra DSN spec.
Definition: class_board.h:65
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
int m_ViasMinDrill
vias (not micro vias) min drill diameter
void SetSize(const wxSize &aSize)
Definition: class_pad.h:299
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:73
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:540
LEGACY_PLUGIN::BIU BIU
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:549
static LAYER_T ParseType(const char *aType)
Function ParseType converts a string to a LAYER_T.
int m_MicroViasMinSize
micro vias (not vias) min diameter
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
BOARD * m_board
which BOARD, no ownership here
int m_LineThickness[LAYER_CLASS_COUNT]
#define TESTSUBSTR(x)
C sub-string compare test for a specific length of characters.
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
Set the zone settings for this container.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:58
const ZONE_SETTINGS & GetZoneSettings() const
Fetch the zone settings for this container.
NETCLASSPTR GetDefault() const
Function GetDefault.
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
char * strtok_r(char *str, const char *delim, char **nextp)
void SetVisibleElements(int aMask)
Function SetVisibleElements changes the bit-mask of visible element categories.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
bool m_MicroViasAllowed
true to allow micro vias
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values.
void Parse(PCB_PLOT_PARAMS_PARSER *aParser)
#define SZ(x)
Get the length of a string constant, at compile time.
#define TESTLINE(x)
C string compare test for a specific length of characters.
wxPoint m_AuxOrigin
origin for plot exports
int m_SolderMaskMinWidth
Solder mask min width.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References biuParse(), delims, FROM_UTF8(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), LINE_READER::GetSource(), BOARD_ITEM_CONTAINER::GetZoneSettings(), hexParse(), intParse(), LAYER_CLASS_COPPER, LAYER_CLASS_EDGES, LAYER_CLASS_OTHERS, LAYER_CLASS_SILK, layerParse(), leg_layer2new(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, m_board, m_cu_count, BOARD_DESIGN_SETTINGS::m_GridOrigin, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_Pad_Master, m_reader, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, ZONE_SETTINGS::m_Zone_45_Only, ZONE_SETTINGS::m_ZoneClearance, NULL, PCB_PLOT_PARAMS::Parse(), LAYER::ParseType(), READLINE, BOARD::SetDesignSettings(), D_PAD::SetDrillSize(), BOARD::SetLayerName(), BOARD::SetLayerType(), BOARD::SetPlotOptions(), D_PAD::SetSize(), BOARD_DESIGN_SETTINGS::SetVisibleElements(), BOARD_ITEM_CONTAINER::SetZoneSettings(), strtok_r(), SZ, TESTLINE, and TESTSUBSTR.

Referenced by loadAllSections().

◆ loadSHEET()

void LEGACY_PLUGIN::loadSHEET ( )
protected

Definition at line 715 of file legacy_plugin.cpp.

716 {
717  char buf[260];
718  TITLE_BLOCK tb;
719  char* line;
720  char* saveptr;
721 
722  while( ( line = READLINE( m_reader ) ) != NULL )
723  {
724  if( TESTLINE( "Sheet" ) )
725  {
726  // e.g. "Sheet A3 16535 11700"
727  // width and height are in 1/1000th of an inch, always
728 
729  PAGE_INFO page;
730  char* sname = strtok_r( line + SZ( "Sheet" ), delims, &saveptr );
731 
732  if( sname )
733  {
734  wxString wname = FROM_UTF8( sname );
735  if( !page.SetType( wname ) )
736  {
737  m_error.Printf( _( "Unknown sheet type \"%s\" on line:%d" ),
738  wname.GetData(), m_reader->LineNumber() );
740  }
741 
742  char* width = strtok_r( NULL, delims, &saveptr );
743  char* height = strtok_r( NULL, delims, &saveptr );
744  char* orient = strtok_r( NULL, delims, &saveptr );
745 
746  // only parse the width and height if page size is custom ("User")
747  if( wname == PAGE_INFO::Custom )
748  {
749  if( width && height )
750  {
751  // legacy disk file describes paper in mils
752  // (1/1000th of an inch)
753  int w = intParse( width );
754  int h = intParse( height );
755 
756  page.SetWidthMils( w );
757  page.SetHeightMils( h );
758  }
759  }
760 
761  if( orient && !strcmp( orient, "portrait" ) )
762  {
763  page.SetPortrait( true );
764  }
765 
766  m_board->SetPageSettings( page );
767  }
768  }
769 
770  else if( TESTLINE( "Title" ) )
771  {
772  ReadDelimitedText( buf, line, sizeof(buf) );
773  tb.SetTitle( FROM_UTF8( buf ) );
774  }
775 
776  else if( TESTLINE( "Date" ) )
777  {
778  ReadDelimitedText( buf, line, sizeof(buf) );
779  tb.SetDate( FROM_UTF8( buf ) );
780  }
781 
782  else if( TESTLINE( "Rev" ) )
783  {
784  ReadDelimitedText( buf, line, sizeof(buf) );
785  tb.SetRevision( FROM_UTF8( buf ) );
786  }
787 
788  else if( TESTLINE( "Comp" ) )
789  {
790  ReadDelimitedText( buf, line, sizeof(buf) );
791  tb.SetCompany( FROM_UTF8( buf ) );
792  }
793 
794  else if( TESTLINE( "Comment1" ) )
795  {
796  ReadDelimitedText( buf, line, sizeof(buf) );
797  tb.SetComment( 0, FROM_UTF8( buf ) );
798  }
799 
800  else if( TESTLINE( "Comment2" ) )
801  {
802  ReadDelimitedText( buf, line, sizeof(buf) );
803  tb.SetComment( 1, FROM_UTF8( buf ) );
804  }
805 
806  else if( TESTLINE( "Comment3" ) )
807  {
808  ReadDelimitedText( buf, line, sizeof(buf) );
809  tb.SetComment( 2, FROM_UTF8( buf ) );
810  }
811 
812  else if( TESTLINE( "Comment4" ) )
813  {
814  ReadDelimitedText( buf, line, sizeof(buf) );
815  tb.SetComment( 3, FROM_UTF8( buf ) );
816  }
817 
818  else if( TESTLINE( "Comment5" ) )
819  {
820  ReadDelimitedText( buf, line, sizeof(buf) );
821  tb.SetComment( 4, FROM_UTF8( buf ) );
822  }
823 
824  else if( TESTLINE( "Comment6" ) )
825  {
826  ReadDelimitedText( buf, line, sizeof(buf) );
827  tb.SetComment( 5, FROM_UTF8( buf ) );
828  }
829 
830  else if( TESTLINE( "Comment7" ) )
831  {
832  ReadDelimitedText( buf, line, sizeof(buf) );
833  tb.SetComment( 6, FROM_UTF8( buf ) );
834  }
835 
836  else if( TESTLINE( "Comment8" ) )
837  {
838  ReadDelimitedText( buf, line, sizeof(buf) );
839  tb.SetComment( 7, FROM_UTF8( buf ) );
840  }
841 
842  else if( TESTLINE( "Comment9" ) )
843  {
844  ReadDelimitedText( buf, line, sizeof(buf) );
845  tb.SetComment( 8, FROM_UTF8( buf ) );
846  }
847 
848  else if( TESTLINE( "$EndSHEETDESCR" ) )
849  {
850  m_board->SetTitleBlock( tb );
851  return; // preferred exit
852  }
853  }
854 
855  THROW_IO_ERROR( "Missing '$EndSHEETDESCR'" );
856 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
void SetRevision(const wxString &aRevision)
Definition: title_block.h:84
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: class_board.h:552
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: class_board.h:546
static const char delims[]
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:74
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:78
#define READLINE(rdr)
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
LINE_READER * m_reader
no ownership here.
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:104
#define NULL
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void SetCompany(const wxString &aCompany)
Definition: title_block.h:94
#define THROW_IO_ERROR(msg)
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
BOARD * m_board
which BOARD, no ownership here
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
char * strtok_r(char *str, const char *delim, char **nextp)
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
#define TESTLINE(x)
C string compare test for a specific length of characters.

References _, PAGE_INFO::Custom, delims, FROM_UTF8(), intParse(), LINE_READER::LineNumber(), m_board, m_error, m_reader, NULL, ReadDelimitedText(), READLINE, TITLE_BLOCK::SetComment(), TITLE_BLOCK::SetCompany(), TITLE_BLOCK::SetDate(), PAGE_INFO::SetHeightMils(), BOARD::SetPageSettings(), PAGE_INFO::SetPortrait(), TITLE_BLOCK::SetRevision(), TITLE_BLOCK::SetTitle(), BOARD::SetTitleBlock(), PAGE_INFO::SetType(), PAGE_INFO::SetWidthMils(), strtok_r(), SZ, TESTLINE, and THROW_IO_ERROR.

Referenced by loadAllSections().

◆ loadTrackList()

void LEGACY_PLUGIN::loadTrackList ( int  aStructType)
protected

Function loadTrackList reads a list of segments (Tracks and Vias, or Segzones)

Parameters
aStructTypeis either PCB_TRACE_T to indicate tracks and vias, or NOT_USED to indicate oldschool zone segments (which are discarded).

Definition at line 2241 of file legacy_plugin.cpp.

2242 {
2243  char* line;
2244  char* saveptr;
2245 
2246  while( ( line = READLINE( m_reader ) ) != NULL )
2247  {
2248  // read two lines per loop iteration, each loop is one TRACK or VIA
2249  // example first line:
2250  // e.g. "Po 0 23994 28800 24400 28800 150 -1" for a track
2251  // e.g. "Po 3 21086 17586 21086 17586 180 -1" for a via (uses sames start and end)
2252 
2253  const char* data;
2254 
2255  if( line[0] == '$' ) // $EndTRACK
2256  return; // preferred exit
2257 
2258  // int arg_count = sscanf( line + 2, " %d %d %d %d %d %d %d", &shape, &tempStartX, &tempStartY, &tempEndX, &tempEndY, &width, &drill );
2259 
2260  assert( TESTLINE( "Po" ) );
2261 
2262  VIATYPE viatype = static_cast<VIATYPE>( intParse( line + SZ( "Po" ), &data ) );
2263  BIU start_x = biuParse( data, &data );
2264  BIU start_y = biuParse( data, &data );
2265  BIU end_x = biuParse( data, &data );
2266  BIU end_y = biuParse( data, &data );
2267  BIU width = biuParse( data, &data );
2268 
2269  // optional 7th drill parameter (must be optional in an old format?)
2270  data = strtok_r( (char*) data, delims, &saveptr );
2271 
2272  BIU drill = data ? biuParse( data ) : -1; // SetDefault() if < 0
2273 
2274  // Read the 2nd line to determine the exact type, one of:
2275  // PCB_TRACE_T, PCB_VIA_T, or PCB_SEGZONE_T. The type field in 2nd line
2276  // differentiates between PCB_TRACE_T and PCB_VIA_T. With virtual
2277  // functions in use, it is critical to instantiate the PCB_VIA_T
2278  // exactly.
2279  READLINE( m_reader );
2280 
2281  line = m_reader->Line();
2282 
2283  // example second line:
2284  // "De 0 0 463 0 800000\r\n"
2285 
2286 #if 1
2287  assert( TESTLINE( "De" ) );
2288 #else
2289  if( !TESTLINE( "De" ) )
2290  {
2291  // mandatory 2nd line is missing
2292  THROW_IO_ERROR( "Missing 2nd line of a TRACK def" );
2293  }
2294 #endif
2295 
2296  int makeType;
2297  unsigned long timeStamp;
2298  LAYER_NUM layer_num;
2299  int type, net_code, flags_int;
2300 
2301  // parse the 2nd line to determine the type of object
2302  // e.g. "De 15 1 7 0 0" for a via
2303  sscanf( line + SZ( "De" ), " %d %d %d %lX %X", &layer_num, &type, &net_code,
2304  &timeStamp, &flags_int );
2305 
2306  STATUS_FLAGS flags;
2307 
2308  flags = static_cast<STATUS_FLAGS>( flags_int );
2309 
2310  if( aStructType == PCB_TRACE_T )
2311  {
2312  makeType = ( type == 1 ) ? PCB_VIA_T : PCB_TRACE_T;
2313  }
2314  else if (aStructType == NOT_USED )
2315  {
2316  continue;
2317  }
2318  else
2319  {
2320  wxFAIL_MSG( "Segment type unknown" );
2321  continue;
2322  }
2323 
2324  TRACK* newTrack;
2325 
2326  switch( makeType )
2327  {
2328  default:
2329  case PCB_TRACE_T:
2330  newTrack = new TRACK( m_board );
2331  break;
2332 
2333  case PCB_VIA_T:
2334  newTrack = new VIA( m_board );
2335  break;
2336  }
2337 
2338  newTrack->SetTimeStamp( (timestamp_t)timeStamp );
2339  newTrack->SetPosition( wxPoint( start_x, start_y ) );
2340  newTrack->SetEnd( wxPoint( end_x, end_y ) );
2341 
2342  newTrack->SetWidth( width );
2343 
2344  if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
2345  {
2346  VIA *via = static_cast<VIA*>( newTrack );
2347  via->SetViaType( viatype );
2348 
2349  if( drill < 0 )
2350  via->SetDrillDefault();
2351  else
2352  via->SetDrill( drill );
2353 
2354  if( via->GetViaType() == VIATYPE::THROUGH )
2355  via->SetLayerPair( F_Cu, B_Cu );
2356  else
2357  {
2358  PCB_LAYER_ID back = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
2359  PCB_LAYER_ID front = leg_layer2new( m_cu_count, layer_num & 0xf );
2360 
2361  if( is_leg_copperlayer_valid( m_cu_count, back ) &&
2363  via->SetLayerPair( front, back );
2364  else
2365  {
2366  delete via;
2367  newTrack = NULL;
2368  }
2369  }
2370  }
2371  else
2372  {
2373  // A few legacy boards can have tracks on non existent layers, because
2374  // reducing the number of layers does not remove tracks on removed layers
2375  // If happens, skip them
2376  if( is_leg_copperlayer_valid( m_cu_count, layer_num ) )
2377  newTrack->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2378  else
2379  {
2380  delete newTrack;
2381  newTrack = NULL;
2382  }
2383  }
2384 
2385  if( newTrack )
2386  {
2387  newTrack->SetNetCode( getNetCode( net_code ) );
2388  newTrack->SetState( flags, true );
2389 
2390  m_board->Add( newTrack );
2391  }
2392  }
2393 
2394  THROW_IO_ERROR( "Missing '$EndTRACK'" );
2395 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:105
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
the 3d code uses this value
Definition: typeinfo.h:80
static const char delims[]
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void SetWidth(int aWidth)
Definition: class_track.h:102
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
PCB_LAYER_ID
A quick note on layer IDs:
LINE_READER * m_reader
no ownership here.
bool is_leg_copperlayer_valid(int aCu_Count, LAYER_NUM aLegacyLayerNum)
#define NULL
unsigned STATUS_FLAGS
Definition: base_struct.h:156
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer.
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
BOARD * m_board
which BOARD, no ownership here
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: class_track.h:372
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void SetState(int type, int state)
Definition: base_struct.h:244
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:99
char * strtok_r(char *str, const char *delim, char **nextp)
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:351
VIATYPE GetViaType() const
Definition: class_track.h:336
VIATYPE
Definition: class_track.h:60
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
#define SZ(x)
Get the length of a string constant, at compile time.
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:341
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code
#define TESTLINE(x)
C string compare test for a specific length of characters.
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

References BOARD::Add(), B_Cu, biuParse(), delims, F_Cu, getNetCode(), VIA::GetViaType(), intParse(), is_leg_copperlayer_valid(), leg_layer2new(), LINE_READER::Line(), m_board, m_cu_count, m_reader, NOT_USED, NULL, PCB_TRACE_T, PCB_VIA_T, READLINE, VIA::SetDrill(), VIA::SetDrillDefault(), TRACK::SetEnd(), BOARD_ITEM::SetLayer(), VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), TRACK::SetPosition(), EDA_ITEM::SetState(), EDA_ITEM::SetTimeStamp(), VIA::SetViaType(), TRACK::SetWidth(), strtok_r(), SZ, TESTLINE, THROUGH, THROW_IO_ERROR, and VIA.

Referenced by loadAllSections().

◆ loadZONE_CONTAINER()

void LEGACY_PLUGIN::loadZONE_CONTAINER ( )
protected

Definition at line 2489 of file legacy_plugin.cpp.

2490 {
2491  unique_ptr<ZONE_CONTAINER> zc( new ZONE_CONTAINER( m_board ) );
2492 
2494  bool endContour = false;
2495  int holeIndex = -1; // -1 is the main outline; holeIndex >= 0 = hole index
2496  char buf[1024];
2497  char* line;
2498  char* saveptr;
2499 
2500  while( ( line = READLINE( m_reader ) ) != NULL )
2501  {
2502  const char* data;
2503 
2504  if( TESTLINE( "ZCorner" ) ) // new corner of the zone outlines found
2505  {
2506  // e.g. "ZCorner 25650 49500 0"
2507  BIU x = biuParse( line + SZ( "ZCorner" ), &data );
2508  BIU y = biuParse( data, &data );
2509 
2510  if( endContour )
2511  {
2512  // the previous corner was the last corner of a contour.
2513  // so this corner is the first of a new hole
2514  endContour = false;
2515  zc->NewHole();
2516  holeIndex++;
2517  }
2518 
2519  zc->AppendCorner( wxPoint( x, y ), holeIndex );
2520 
2521  // Is this corner the end of current contour?
2522  // the next corner (if any) will be stored in a new contour (a hole)
2523  // intParse( data )returns 0 = usual corner, 1 = last corner of the current contour:
2524  endContour = intParse( data );
2525  }
2526 
2527  else if( TESTLINE( "ZInfo" ) ) // general info found
2528  {
2529  // e.g. 'ZInfo 479194B1 310 "COMMON"'
2530  timestamp_t timestamp = hexParse( line + SZ( "ZInfo" ), &data );
2531  int netcode = intParse( data, &data );
2532 
2533  if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
2534  {
2535  THROW_IO_ERROR( "ZInfo netname too long" );
2536  }
2537 
2538  zc->SetTimeStamp( timestamp );
2539  // Init the net code only, not the netname, to be sure
2540  // the zone net name is the name read in file.
2541  // (When mismatch, the user will be prompted in DRC, to fix the actual name)
2542  zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) );
2543  }
2544 
2545  else if( TESTLINE( "ZLayer" ) ) // layer found
2546  {
2547  LAYER_NUM layer_num = layerParse( line + SZ( "ZLayer" ) );
2548  zc->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2549  }
2550 
2551  else if( TESTLINE( "ZAux" ) ) // aux info found
2552  {
2553  // e.g. "ZAux 7 E"
2554  int ignore = intParse( line + SZ( "ZAux" ), &data );
2555  char* hopt = strtok_r( (char*) data, delims, &saveptr );
2556 
2557  if( !hopt )
2558  {
2559  m_error.Printf( _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ), zc->GetNetname().GetData() );
2561  }
2562 
2563  switch( *hopt ) // upper case required
2564  {
2565  case 'N':
2566  outline_hatch = ZONE_HATCH_STYLE::NO_HATCH;
2567  break;
2568  case 'E':
2569  outline_hatch = ZONE_HATCH_STYLE::DIAGONAL_EDGE;
2570  break;
2571  case 'F':
2572  outline_hatch = ZONE_HATCH_STYLE::DIAGONAL_FULL;
2573  break;
2574 
2575  default:
2576  m_error.Printf(
2577  _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ), zc->GetNetname().GetData() );
2579  }
2580 
2581  (void) ignore;
2582 
2583  // Set hatch mode later, after reading corner outline data
2584  }
2585 
2586  else if( TESTLINE( "ZSmoothing" ) )
2587  {
2588  // e.g. "ZSmoothing 0 0"
2589  int smoothing = intParse( line + SZ( "ZSmoothing" ), &data );
2590  BIU cornerRadius = biuParse( data );
2591 
2592  if( smoothing >= ZONE_SETTINGS::SMOOTHING_LAST || smoothing < 0 )
2593  {
2594  m_error.Printf( _( "Bad ZSmoothing for CZONE_CONTAINER \"%s\"" ), zc->GetNetname().GetData() );
2596  }
2597 
2598  zc->SetCornerSmoothingType( smoothing );
2599  zc->SetCornerRadius( cornerRadius );
2600  }
2601 
2602  else if( TESTLINE( "ZKeepout" ) )
2603  {
2604  zc->SetIsKeepout( true );
2605  // e.g. "ZKeepout tracks N vias N pads Y"
2606  data = strtok_r( line + SZ( "ZKeepout" ), delims, &saveptr );
2607 
2608  while( data )
2609  {
2610  if( !strcmp( data, "tracks" ) )
2611  {
2612  data = strtok_r( NULL, delims, &saveptr );
2613  zc->SetDoNotAllowTracks( data && *data == 'N' );
2614  }
2615  else if( !strcmp( data, "vias" ) )
2616  {
2617  data = strtok_r( NULL, delims, &saveptr );
2618  zc->SetDoNotAllowVias( data && *data == 'N' );
2619  }
2620  else if( !strcmp( data, "copperpour" ) )
2621  {
2622  data = strtok_r( NULL, delims, &saveptr );
2623  zc->SetDoNotAllowCopperPour( data && *data == 'N' );
2624  }
2625 
2626  data = strtok_r( NULL, delims, &saveptr );
2627  }
2628  }
2629 
2630  else if( TESTLINE( "ZOptions" ) )
2631  {
2632  // e.g. "ZOptions 0 32 F 200 200"
2633  int fillmode = intParse( line + SZ( "ZOptions" ), &data );
2634  static_cast<void>( intParse( data, &data ) ); // Ignored
2635  char fillstate = data[1]; // here e.g. " F"
2636  BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
2637  BIU thermalReliefCopperBridge = biuParse( data );
2638 
2639  if( fillmode)
2640  {
2641  // SEGMENT fill mode no longer supported. Make sure user is OK with converting them.
2643  {
2644  KIDIALOG dlg( nullptr,
2645  _( "The legacy segment fill mode is no longer supported.\n"
2646  "Convert zones to polygon fills?"),
2647  _( "Legacy Zone Warning" ),
2648  wxYES_NO | wxICON_WARNING );
2649 
2650  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
2651 
2652  if( dlg.ShowModal() == wxID_NO )
2653  THROW_IO_ERROR( wxT( "CANCEL" ) );
2654 
2655  m_showLegacyZoneWarning = false;
2656  }
2657 
2658  // User OK'd; switch to polygon mode
2659  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2660  m_board->SetModified();
2661  }
2662  else
2663  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2664 
2665  zc->SetIsFilled( fillstate == 'S' );
2666  zc->SetThermalReliefGap( thermalReliefGap );
2667  zc->SetThermalReliefCopperBridge( thermalReliefCopperBridge );
2668  }
2669 
2670  else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
2671  {
2672  // e.g. "ZClearance 40 I"
2673  BIU clearance = biuParse( line + SZ( "ZClearance" ), &data );
2674  char* padoption = strtok_r( (char*) data, delims, &saveptr ); // data: " I"
2675 
2676  ZONE_CONNECTION popt;
2677  switch( *padoption )
2678  {
2679  case 'I':
2680  popt = ZONE_CONNECTION::FULL;
2681  break;
2682  case 'T':
2683  popt = ZONE_CONNECTION::THERMAL;
2684  break;
2685  case 'H':
2687  break;
2688  case 'X':
2689  popt = ZONE_CONNECTION::NONE;
2690  break;
2691 
2692  default:
2693  m_error.Printf( _( "Bad ZClearance padoption for CZONE_CONTAINER \"%s\"" ),
2694  zc->GetNetname().GetData() );
2696  }
2697 
2698  zc->SetZoneClearance( clearance );
2699  zc->SetPadConnection( popt );
2700  }
2701 
2702  else if( TESTLINE( "ZMinThickness" ) )
2703  {
2704  BIU thickness = biuParse( line + SZ( "ZMinThickness" ) );
2705  zc->SetMinThickness( thickness );
2706  }
2707 
2708  else if( TESTLINE( "ZPriority" ) )
2709  {
2710  int priority = intParse( line + SZ( "ZPriority" ) );
2711  zc->SetPriority( priority );
2712  }
2713 
2714  else if( TESTLINE( "$POLYSCORNERS" ) )
2715  {
2716  // Read the PolysList (polygons that are the solid areas in the filled zone)
2717  SHAPE_POLY_SET polysList;
2718 
2719  bool makeNewOutline = true;
2720 
2721  while( ( line = READLINE( m_reader ) ) != NULL )
2722  {
2723  if( TESTLINE( "$endPOLYSCORNERS" ) )
2724  break;
2725 
2726  // e.g. "39610 43440 0 0"
2727  BIU x = biuParse( line, &data );
2728  BIU y = biuParse( data, &data );
2729 
2730  if( makeNewOutline )
2731  polysList.NewOutline();
2732 
2733  polysList.Append( x, y );
2734 
2735  bool end_contour = intParse( data, &data ); // end_countour was a bool when file saved, so '0' or '1' here
2736  intParse( data ); // skip corner utility flag
2737 
2738  makeNewOutline = end_contour;
2739  }
2740 
2741  zc->SetFilledPolysList( polysList );
2742  }
2743 
2744  else if( TESTLINE( "$FILLSEGMENTS" ) )
2745  {
2746  while( ( line = READLINE( m_reader ) ) != NULL )
2747  {
2748  if( TESTLINE( "$endFILLSEGMENTS" ) )
2749  break;
2750 
2751  // e.g. ""%d %d %d %d\n"
2752  BIU sx = biuParse( line, &data );
2753  BIU sy = biuParse( data, &data );
2754  BIU ex = biuParse( data, &data );
2755  BIU ey = biuParse( data );
2756 
2757  zc->FillSegments().push_back( SEG( VECTOR2I( sx, sy ), VECTOR2I( ex, ey ) ) );
2758  }
2759  }
2760 
2761  else if( TESTLINE( "$endCZONE_OUTLINE" ) )
2762  {
2763  // Ensure keepout does not have a net
2764  // (which have no sense for a keepout zone)
2765  if( zc->GetIsKeepout() )
2766  zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
2767 
2768  // should always occur, but who knows, a zone without two corners
2769  // is no zone at all, it's a spot?
2770 
2771  if( zc->GetNumCorners() > 2 )
2772  {
2773  if( !zc->IsOnCopperLayer() )
2774  {
2775  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2776  zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
2777  }
2778 
2779  // Hatch here, after outlines corners are read
2780  // Set hatch here, after outlines corners are read
2781  zc->SetHatch( outline_hatch, ZONE_CONTAINER::GetDefaultHatchPitch(),
2782  true );
2783 
2784  m_board->Add( zc.release() );
2785  }
2786 
2787  return; // preferred exit
2788  }
2789  }
2790 
2791  THROW_IO_ERROR( "Missing '$endCZONE_OUTLINE'" );
2792 }
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:50
void SetModified()
Definition: base_struct.cpp:95
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
bool m_showLegacyZoneWarning
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
static const char delims[]
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
#define READLINE(rdr)
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
LINE_READER * m_reader
no ownership here.
pads are covered by copper
#define NULL
SHAPE_POLY_SET.
#define THROW_IO_ERROR(msg)
LEGACY_PLUGIN::BIU BIU
int NewOutline()
Creates a new empty polygon in the set and returns its index
BOARD * m_board
which BOARD, no ownership here
Thermal relief only for THT pads.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Definition: seg.h:39
Use thermal relief for pads.
ZONE_HATCH_STYLE
Zone hatch styles.
Definition: zone_settings.h:45
#define _(s)
Definition: 3d_actions.cpp:31
wxString m_error
for throwing exceptions
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
char * strtok_r(char *str, const char *delim, char **nextp)
Pads are not covered.
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
#define SZ(x)
Get the length of a string constant, at compile time.
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:463
#define TESTLINE(x)
C string compare test for a specific length of characters.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)

References _, BOARD::Add(), SHAPE_POLY_SET::Append(), biuParse(), delims, DIAGONAL_EDGE, DIAGONAL_FULL, KIDIALOG::DoNotShowCheckbox(), FULL, ZONE_CONTAINER::GetDefaultHatchPitch(), getNetCode(), hexParse(), intParse(), layerParse(), leg_layer2new(), m_board, m_cu_count, m_error, m_reader, m_showLegacyZoneWarning, SHAPE_POLY_SET::NewOutline(), NO_HATCH, NONE, NULL, POLYGONS, ReadDelimitedText(), READLINE, EDA_ITEM::SetModified(), KIDIALOG::ShowModal(), ZONE_SETTINGS::SMOOTHING_LAST, strtok_r(), SZ, TESTLINE, THERMAL, THROW_IO_ERROR, THT_THERMAL, and NETINFO_LIST::UNCONNECTED.

Referenced by loadAllSections().

◆ PluginName()

const wxString LEGACY_PLUGIN::PluginName ( ) const
inlineoverridevirtual

Function PluginName returns a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 73 of file legacy_plugin.h.

74  {
75  return wxT( "KiCad-Legacy" );
76  }

◆ PrefetchLib()

void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Plugins that cannot prefetch need not override this; a default no-op is provided.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is an error prefetching the library.

Reimplemented in GITHUB_PLUGIN.

Definition at line 68 of file plugin.cpp.

69 {
70  (void) aLibraryPath;
71  (void) aProperties;
72 }

◆ Save()

void PLUGIN::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aBoardis the class BOARD in memory document tree from which to extract information when writing to aFileName. The caller continues to own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented in PCB_IO, and CLIPBOARD_IO.

Definition at line 53 of file plugin.cpp.

54 {
55  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
56  not_implemented( this, __FUNCTION__ );
57 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

Referenced by IO_MGR::Save().

◆ SaveModule3D()

void LEGACY_PLUGIN::SaveModule3D ( const MODULE aModule) const

Definition at line 3121 of file legacy_plugin.cpp.

3122 {
3123  auto sM = me->Models().begin();
3124  auto eM = me->Models().end();
3125 
3126  while( sM != eM )
3127  {
3128  if( sM->m_Filename.empty() )
3129  {
3130  ++sM;
3131  continue;
3132  }
3133 
3134  fprintf( m_fp, "$SHAPE3D\n" );
3135 
3136  fprintf( m_fp, "Na %s\n", EscapedUTF8( sM->m_Filename ).c_str() );
3137 
3138  fprintf(m_fp,
3139 #if defined(DEBUG)
3140  // use old formats for testing, just to verify compatibility
3141  // using "diff", then switch to more concise form for release builds.
3142  "Sc %lf %lf %lf\n",
3143 #else
3144  "Sc %.10g %.10g %.10g\n",
3145 #endif
3146  sM->m_Scale.x,
3147  sM->m_Scale.y,
3148  sM->m_Scale.z );
3149 
3150  fprintf(m_fp,
3151 #if defined(DEBUG)
3152  "Of %lf %lf %lf\n",
3153 #else
3154  "Of %.10g %.10g %.10g\n",
3155 #endif
3156  sM->m_Offset.x,
3157  sM->m_Offset.y,
3158  sM->m_Offset.z );
3159 
3160  fprintf(m_fp,
3161 #if defined(DEBUG)
3162  "Ro %lf %lf %lf\n",
3163 #else
3164  "Ro %.10g %.10g %.10g\n",
3165 #endif
3166  sM->m_Rotation.x,
3167  sM->m_Rotation.y,
3168  sM->m_Rotation.z );
3169 
3170  fprintf( m_fp, "$EndSHAPE3D\n" );
3171 
3172  ++sM;
3173  }
3174 
3175  return;
3176 }
FILE * m_fp
no ownership here.
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249

References EscapedUTF8(), m_fp, and MODULE::Models().

◆ SetFilePtr()

void LEGACY_PLUGIN::SetFilePtr ( FILE *  aFile)
inline

Definition at line 107 of file legacy_plugin.h.

107 { m_fp = aFile; }
FILE * m_fp
no ownership here.

References m_fp.

◆ SetReader()

void LEGACY_PLUGIN::SetReader ( LINE_READER aReader)
inline

Definition at line 106 of file legacy_plugin.h.

106 { m_reader = aReader; }
LINE_READER * m_reader
no ownership here.

References m_reader.

Referenced by LP_CACHE::LoadModules().

Friends And Related Function Documentation

◆ LP_CACHE

friend struct LP_CACHE
friend

Definition at line 67 of file legacy_plugin.h.

Referenced by cacheLib().

Member Data Documentation

◆ biuToDisk

double LEGACY_PLUGIN::biuToDisk
protected

convert from BIUs to disk engineering units with this scale factor

Definition at line 139 of file legacy_plugin.h.

Referenced by init().

◆ diskToBiu

double LEGACY_PLUGIN::diskToBiu
protected

convert from disk engineering units to BIUs with this scale factor

Definition at line 142 of file legacy_plugin.h.

Referenced by biuParse(), init(), loadGENERAL(), and LP_CACHE::ReadAndVerifyHeader().

◆ m_board

◆ m_cache

LP_CACHE* LEGACY_PLUGIN::m_cache
protected

◆ m_cu_count

◆ m_error

wxString LEGACY_PLUGIN::m_error
protected

for throwing exceptions

Definition at line 120 of file legacy_plugin.h.

Referenced by biuParse(), checkVersion(), degParse(), loadMODULE_EDGE(), loadNETCLASS(), loadPAD(), loadSHEET(), and loadZONE_CONTAINER().

◆ m_field

wxString LEGACY_PLUGIN::m_field
protected

reused to stuff MODULE fields.

Definition at line 127 of file legacy_plugin.h.

Referenced by loadMODULE_TEXT().

◆ m_fp

FILE* LEGACY_PLUGIN::m_fp
protected

no ownership here.

Definition at line 125 of file legacy_plugin.h.

Referenced by SaveModule3D(), and SetFilePtr().

◆ m_loading_format_version

int LEGACY_PLUGIN::m_loading_format_version
protected

which BOARD_FORMAT_VERSION am I Load()ing?

Definition at line 128 of file legacy_plugin.h.

Referenced by checkVersion(), init(), and loadPAD().

◆ m_mapping

NETINFO_MAPPING* LEGACY_PLUGIN::m_mapping
protected

mapping for net codes, so only not empty nets are stored with consecutive integers as net codes

Definition at line 132 of file legacy_plugin.h.

Referenced by ~LEGACY_PLUGIN().

◆ m_netCodes

std::vector<int> LEGACY_PLUGIN::m_netCodes
protected

net codes mapping for boards being loaded

Definition at line 134 of file legacy_plugin.h.

Referenced by getNetCode(), loadGENERAL(), and loadNETINFO_ITEM().

◆ m_props

const PROPERTIES* LEGACY_PLUGIN::m_props
protected

passed via Save() or Load(), no ownership, may be NULL.

Definition at line 122 of file legacy_plugin.h.

Referenced by init().

◆ m_reader

LINE_READER* LEGACY_PLUGIN::m_reader
protected

no ownership here.

Definition at line 124 of file