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 <math/util.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
 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

◆ 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

◆ MODULE_CITER

typedef MODULE_MAP::const_iterator MODULE_CITER

Definition at line 132 of file gpcb_plugin.cpp.

◆ MODULE_ITER

typedef MODULE_MAP::iterator MODULE_ITER

Definition at line 131 of file gpcb_plugin.cpp.

◆ MODULE_MAP

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

Definition at line 130 of file gpcb_plugin.cpp.

Function Documentation

◆ parseInt()

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

Definition at line 53 of file gpcb_plugin.cpp.

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

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

Referenced by GPCB_FPL_CACHE::parseMODULE().