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 <trace_helpers.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 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 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 )

Typedef Documentation

typedef MODULE_MAP::const_iterator MODULE_CITER

Definition at line 131 of file gpcb_plugin.cpp.

typedef MODULE_MAP::iterator MODULE_ITER

Definition at line 130 of file gpcb_plugin.cpp.

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

Definition at line 129 of file gpcb_plugin.cpp.

Function Documentation

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

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

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