KiCad PCB EDA Suite
gpcb_plugin.cpp File Reference

Geda PCB file plugin implementation file. More...

#include <wildcards_and_files_ext.h>
#include <trace_helpers.h>
#include <math/util.h>
#include <board.h>
#include <footprint.h>
#include <pad.h>
#include <locale_io.h>
#include <macros.h>
#include <pcb_text.h>
#include <pcb_shape.h>
#include <fp_shape.h>
#include <plugins/geda/gpcb_plugin.h>
#include <wx_filename.h>
#include <wx/dir.h>
#include <wx/log.h>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <boost/ptr_container/ptr_map.hpp>

Go to the source code of this file.

Classes

class  GPCB_FPL_CACHE_ITEM
 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_ITEMFOOTPRINT_MAP
 

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

◆ NEW_GPCB_UNIT_CONV

#define NEW_GPCB_UNIT_CONV   ( 0.01*IU_PER_MILS )

◆ OLD_GPCB_UNIT_CONV

#define OLD_GPCB_UNIT_CONV   IU_PER_MILS

◆ TEXT_DEFAULT_SIZE

#define TEXT_DEFAULT_SIZE   ( 40*IU_PER_MILS )

Typedef Documentation

◆ FOOTPRINT_MAP

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

Definition at line 129 of file gpcb_plugin.cpp.

Function Documentation

◆ parseInt()

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

Definition at line 52 of file gpcb_plugin.cpp.

53 {
54  double value = std::numeric_limits<double>::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 ::parseFOOTPRINT already; the
63  * distinction is by whether an object definition opens with '(' or '['.
64  * All values with explicit 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 continue 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 == std::numeric_limits<double>::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 }
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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:73
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

Referenced by GPCB_FPL_CACHE::parseFOOTPRINT().