KiCad PCB EDA Suite
gpcb_plugin.cpp File Reference

Geda PCB file plugin implementation file. More...

#include <fctsys.h>
#include <common.h>
#include <macros.h>
#include <trigo.h>
#include <wildcards_and_files_ext.h>
#include <filter_reader.h>
#include <class_board.h>
#include <class_module.h>
#include <class_pcb_text.h>
#include <class_drawsegment.h>
#include <class_edge_mod.h>
#include <gpcb_plugin.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <boost/ptr_container/ptr_map.hpp>
#include <memory.h>

Go to the source code of this file.

Classes

class  GPCB_FPL_CACHE_ITEM
 Class GPCB_FPL_CACHE_ITEM is helper class for creating a footprint library cache. More...
 
class  GPCB_FPL_CACHE
 

Macros

#define TRACE_PARAMS(arr)
 
#define TEXT_DEFAULT_SIZE   ( 40*IU_PER_MILS )
 
#define OLD_GPCB_UNIT_CONV   IU_PER_MILS
 
#define NEW_GPCB_UNIT_CONV   ( 0.01*IU_PER_MILS )
 

Typedefs

typedef boost::ptr_map< std::string, GPCB_FPL_CACHE_ITEMMODULE_MAP
 
typedef MODULE_MAP::iterator MODULE_ITER
 
typedef MODULE_MAP::const_iterator MODULE_CITER
 

Functions

static const wxString traceFootprintLibrary (wxT("GedaPcbFootprintLib"))
 Definition for enabling and disabling footprint library trace output. More...
 
static long parseInt (const wxString &aValue, double aScalar)
 

Detailed Description

Geda PCB file plugin implementation file.

Geda PCB file plugin definition file.

Definition in file gpcb_plugin.cpp.

Macro Definition Documentation

#define NEW_GPCB_UNIT_CONV   ( 0.01*IU_PER_MILS )
#define OLD_GPCB_UNIT_CONV   IU_PER_MILS
#define TEXT_DEFAULT_SIZE   ( 40*IU_PER_MILS )
#define TRACE_PARAMS (   arr)

Definition at line 125 of file gpcb_plugin.cpp.

Referenced by GPCB_FPL_CACHE::parseParameters().

Typedef Documentation

typedef MODULE_MAP::const_iterator MODULE_CITER

Definition at line 180 of file gpcb_plugin.cpp.

typedef MODULE_MAP::iterator MODULE_ITER

Definition at line 179 of file gpcb_plugin.cpp.

typedef boost::ptr_map< std::string, GPCB_FPL_CACHE_ITEM > MODULE_MAP

Definition at line 178 of file gpcb_plugin.cpp.

Function Documentation

static long parseInt ( const wxString &  aValue,
double  aScalar 
)
inlinestatic

Definition at line 73 of file gpcb_plugin.cpp.

References Format(), KiROUND(), and THROW_IO_ERROR.

Referenced by PCB_PARSER::parseD_PAD(), PCB_PARSER::parseGeneralSection(), PCB_PARSER::parseHeader(), PCB_PARSER::parseLayer(), GPCB_FPL_CACHE::parseMODULE(), PCB_PARSER::parseMODULE_unchecked(), PCB_PARSER::parseNETINFO_ITEM(), PCB_PARSER::parseTITLE_BLOCK(), PCB_PARSER::parseTRACK(), PCB_PARSER::parseVersion(), PCB_PARSER::parseVIA(), and PCB_PARSER::parseZONE_CONTAINER().

74 {
75  double value = LONG_MAX;
76 
77  /*
78  * In 2011 gEDA/pcb introduced values with units, like "10mm" or "200mil".
79  * Unit-less values are still centimils (100000 units per inch), like with
80  * the previous format.
81  *
82  * Distinction between the even older format (mils, 1000 units per inch)
83  * and the pre-2011 format is done in ::parseMODULE already; the
84  * distinction is by wether an object definition opens with '(' or '['.
85  * All values with explicite unit open with a '[' so there's no need to
86  * consider this distinction when parsing them.
87  *
88  * The solution here is to watch for a unit and, if present, convert the
89  * value to centimils. All unit-less values are read unaltered. This way
90  * the code below can contine to consider all read values to be in mils or
91  * centimils. It also matches the strategy gEDA/pcb uses for backwards
92  * compatibility with its own layouts.
93  *
94  * Fortunately gEDA/pcb allows only units 'mil' and 'mm' in files, see
95  * definition of ALLOW_READABLE in gEDA/pcb's pcb_printf.h. So we don't
96  * have to test for all 11 units gEDA/pcb allows in user dialogs.
97  */
98  if( aValue.EndsWith( wxT( "mm" ) ) )
99  {
100  aScalar *= 100000.0 / 25.4;
101  }
102  else if( aValue.EndsWith( wxT( "mil" ) ) )
103  {
104  aScalar *= 100.;
105  }
106 
107  // This conversion reports failure on strings as simple as "1000", still
108  // it returns the right result in &value. Thus, ignore the return value.
109  aValue.ToCDouble(&value);
110  if( value == LONG_MAX ) // conversion really failed
111  {
112  THROW_IO_ERROR( wxString::Format( _( "Cannot convert \"%s\" to an integer" ),
113  aValue.GetData() ) );
114  return 0;
115  }
116 
117  return KiROUND( value * aScalar );
118 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
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 THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static const wxString traceFootprintLibrary ( wxT("GedaPcbFootprintLib")  )
static

Definition for enabling and disabling footprint library trace output.

See the wxWidgets documentation on using the WXTRACE environment variable.

Referenced by GPCB_PLUGIN::FootprintLibDelete(), GPCB_FPL_CACHE::IsModified(), and GPCB_FPL_CACHE::parseMODULE().