KiCad PCB EDA Suite
EAGLE_PLUGIN Class Reference

Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API, or a portion of it. More...

#include <eagle_plugin.h>

Inheritance diagram for EAGLE_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...
 
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...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
wxArrayString FootprintEnumerate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintEnumerate returns 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 IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
void FootprintLibOptions (PROPERTIES *aProperties) const override
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
 EAGLE_PLUGIN ()
 
 ~EAGLE_PLUGIN ()
 
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 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 bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 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...
 

Private Member Functions

void init (const PROPERTIES *aProperties)
 initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. More...
 
void clear_cu_map ()
 
int kicad (double d) const
 Convert an Eagle distance to a KiCad distance. More...
 
int kicad_y (double y) const
 
int kicad_x (double x) const
 
wxSize kicad_fontz (double d) const
 create a font size (fontz) from an eagle font size scalar More...
 
LAYER_ID kicad_layer (int aLayer) const
 Convert an Eagle layer to a KiCad layer. More...
 
double eagle (BIU d) const
 Convert a KiCad distance to an Eagle distance. More...
 
double eagle_x (BIU x) const
 
double eagle_y (BIU y) const
 
void cacheLib (const wxString &aLibraryPath)
 This PLUGIN only caches one footprint library, this determines which one. More...
 
void loadAllSections (CPTREE &aDocument)
 
void loadDesignRules (CPTREE &aDesignRules)
 
void loadLayerDefs (CPTREE &aLayers)
 
void loadPlain (CPTREE &aPlain)
 
void loadSignals (CPTREE &aSignals)
 
void loadLibrary (CPTREE &aLib, const std::string *aLibName)
 Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries" element (if a *.brd file) or under a "drawing" element if a *.lbr file. More...
 
void loadLibraries (CPTREE &aLibs)
 
void loadElements (CPTREE &aElements)
 
void orientModuleAndText (MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
 
void orientModuleText (MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
 
void centerBoard ()
 move the BOARD into the center of the page More...
 
std::string fmtDEG (double aAngle) const
 Function fmtDEG formats an angle in a way particular to a board file format. More...
 
MODULEmakeModule (CPTREE &aPackage, const std::string &aPkgName) const
 Function makeModule creates a MODULE from an Eagle package. More...
 
void packageWire (MODULE *aModule, CPTREE &aTree) const
 
void packagePad (MODULE *aModule, CPTREE &aTree) const
 
void packageText (MODULE *aModule, CPTREE &aTree) const
 
void packageRectangle (MODULE *aModule, CPTREE &aTree) const
 
void packagePolygon (MODULE *aModule, CPTREE &aTree) const
 
void packageCircle (MODULE *aModule, CPTREE &aTree) const
 
void packageHole (MODULE *aModule, CPTREE &aTree) const
 
void packageSMD (MODULE *aModule, CPTREE &aTree) const
 

Static Private Member Functions

static wxDateTime getModificationTime (const wxString &aPath)
 get a file's or dir's modification time. More...
 

Private Attributes

int m_cu_map [17]
 map eagle to kicad, cu layers only. More...
 
ERULESm_rules
 Eagle design rules. More...
 
XPATHm_xpath
 keeps track of what we are working on within XML document during a Load(). More...
 
int m_hole_count
 generates unique module names from eagle "hole"s. More...
 
NET_MAP m_pads_to_nets
 net list More...
 
MODULE_MAP m_templates
 is part of a MODULE factory that operates using copy construction. More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
BOARDm_board
 which BOARD is being worked on, no ownership here More...
 
int m_min_trace
 smallest trace we find on Load(), in BIU. More...
 
int m_min_via
 smallest via we find on Load(), in BIU. More...
 
int m_min_via_hole
 smallest via diameter hole we find on Load(), in BIU. More...
 
double mm_per_biu
 how many mm in each BIU More...
 
double biu_per_mm
 how many bius in a mm More...
 
wxString m_lib_path
 
wxDateTime m_mod_time
 

Detailed Description

Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API, or a portion of it.

Definition at line 77 of file eagle_plugin.h.

Member Typedef Documentation

typedef int EAGLE_PLUGIN::BIU

Definition at line 114 of file eagle_plugin.h.

Constructor & Destructor Documentation

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 1139 of file eagle_plugin.cpp.

References clear_cu_map(), and init().

1139  :
1140  m_rules( new ERULES() ),
1141  m_xpath( new XPATH() ),
1142  m_mod_time( wxDateTime::Now() )
1143 {
1144  init( NULL );
1145 
1146  clear_cu_map();
1147 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
Class XPATH keeps track of what we are working on within a PTREE.
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
subset of eagle.drawing.board.designrules in the XML document
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 1150 of file eagle_plugin.cpp.

References m_rules, and m_xpath.

1151 {
1152  delete m_rules;
1153  delete m_xpath;
1154 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124

Member Function Documentation

void EAGLE_PLUGIN::cacheLib ( const wxString &  aLibraryPath)
private

This PLUGIN only caches one footprint library, this determines which one.

Definition at line 3000 of file eagle_plugin.cpp.

References clear_cu_map(), XPATH::Contents(), getModificationTime(), loadLayerDefs(), loadLibrary(), m_lib_path, m_mod_time, m_templates, m_xpath, XPATH::pop(), XPATH::push(), and THROW_IO_ERROR.

Referenced by FootprintEnumerate(), and FootprintLoad().

3001 {
3002  try
3003  {
3004  wxDateTime modtime = getModificationTime( aLibPath );
3005 
3006  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
3007  // cache if either of the wxDateTime objects are invalid or the last file modification
3008  // time differs from the current file modification time.
3009  bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
3010  m_mod_time != modtime;
3011 
3012  if( aLibPath != m_lib_path || load )
3013  {
3014  PTREE doc;
3015  LOCALE_IO toggle; // toggles on, then off, the C locale.
3016 
3017  m_templates.clear();
3018 
3019  // Set this before completion of loading, since we rely on it for
3020  // text of an exception. Delay setting m_mod_time until after successful load
3021  // however.
3022  m_lib_path = aLibPath;
3023 
3024  // 8 bit "filename" should be encoded according to disk filename encoding,
3025  // (maybe this is current locale, maybe not, its a filesystem issue),
3026  // and is not necessarily utf8.
3027  string filename = (const char*) aLibPath.char_str( wxConvFile );
3028 
3029  read_xml( filename, doc, xml_parser::no_comments );
3030 
3031  // clear the cu map and then rebuild it.
3032  clear_cu_map();
3033 
3034  m_xpath->push( "eagle.drawing.layers" );
3035  CPTREE& layers = doc.get_child( "eagle.drawing.layers" );
3036  loadLayerDefs( layers );
3037  m_xpath->pop();
3038 
3039  m_xpath->push( "eagle.drawing.library" );
3040  CPTREE& library = doc.get_child( "eagle.drawing.library" );
3041  loadLibrary( library, NULL );
3042  m_xpath->pop();
3043 
3044  m_mod_time = modtime;
3045  }
3046  }
3047  catch( file_parser_error fpe )
3048  {
3049  // for xml_parser_error, what() has the line number in it,
3050  // but no byte offset. That should be an adequate error message.
3051  THROW_IO_ERROR( fpe.what() );
3052  }
3053 
3054  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
3055  // so one catch should be OK for all errors.
3056  catch( ptree_error pte )
3057  {
3058  string errmsg = pte.what();
3059 
3060  errmsg += " @\n";
3061  errmsg += m_xpath->Contents();
3062 
3063  THROW_IO_ERROR( errmsg );
3064  }
3065 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
wxString m_lib_path
Definition: eagle_plugin.h:146
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
string Contents()
return the contents of the XPATH as a single string
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
void pop()
void loadLayerDefs(CPTREE &aLayers)
void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

Definition at line 2942 of file eagle_plugin.cpp.

References DBG, BOARD::GetBoardEdgesBoundingBox(), EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), m_board, m_props, BOARD::Move(), and PROPERTIES::Value().

Referenced by Load().

2943 {
2944  if( m_props )
2945  {
2946  UTF8 page_width;
2947  UTF8 page_height;
2948 
2949  if( m_props->Value( "page_width", &page_width ) &&
2950  m_props->Value( "page_height", &page_height ) )
2951  {
2953 
2954  int w = atoi( page_width.c_str() );
2955  int h = atoi( page_height.c_str() );
2956 
2957  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2958  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2959 
2960  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2961  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2962 
2963  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2964  }
2965  }
2966 }
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
int GetHeight() const
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:839
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:136
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Class EDA_RECT handles the component boundary box.
int GetX() const
int GetWidth() const
int GetY() const
#define DBG(x)
Definition: fctsys.h:33
void EAGLE_PLUGIN::clear_cu_map ( )
private

Definition at line 1299 of file eagle_plugin.cpp.

References DIM, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

1300 {
1301  // All cu layers are invalid until we see them in the <layers> section while
1302  // loading either a board or library. See loadLayerDefs().
1303  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
1304  m_cu_map[i] = -1;
1305 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
double EAGLE_PLUGIN::eagle ( BIU  d) const
inlineprivate

Convert a KiCad distance to an Eagle distance.

Definition at line 166 of file eagle_plugin.h.

Referenced by eagle_x(), and eagle_y().

166 { return mm_per_biu * d; }
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:143
double EAGLE_PLUGIN::eagle_x ( BIU  x) const
inlineprivate

Definition at line 167 of file eagle_plugin.h.

References eagle().

167 { return eagle( x ); }
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:166
double EAGLE_PLUGIN::eagle_y ( BIU  y) const
inlineprivate

Definition at line 168 of file eagle_plugin.h.

References eagle().

168 { return eagle( y ); }
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:166
std::string EAGLE_PLUGIN::fmtDEG ( double  aAngle) const
private

Function fmtDEG formats an angle in a way particular to a board file format.

This function is the opposite or complement of degParse(). One has to know what the other is doing.

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 92 of file plugin.cpp.

References not_implemented().

Referenced by FP_LIB_TABLE::FootprintDelete().

93 {
94  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
95  not_implemented( this, __FUNCTION__ );
96 }
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
wxArrayString EAGLE_PLUGIN::FootprintEnumerate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintEnumerate returns 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.
Returns
wxArrayString - is the array of available footprint names inside a library
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 3068 of file eagle_plugin.cpp.

References cacheLib(), FROM_UTF8(), init(), and m_templates.

3069 {
3070  init( aProperties );
3071 
3072  cacheLib( aLibraryPath );
3073 
3074  wxArrayString ret;
3075 
3076  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
3077  ret.Add( FROM_UTF8( it->first.c_str() ) );
3078 
3079  return ret;
3080 }
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:53
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
MODULE_MAP::const_iterator MODULE_CITER
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
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 99 of file plugin.cpp.

References not_implemented().

Referenced by PCB_BASE_EDIT_FRAME::CreateNewLibrary(), and FP_LIB_TABLE::FootprintLibCreate().

100 {
101  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
102  not_implemented( this, __FUNCTION__ );
103 }
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
bool PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in GITHUB_PLUGIN, PCB_IO, LEGACY_PLUGIN, and GPCB_PLUGIN.

Definition at line 106 of file plugin.cpp.

References not_implemented().

Referenced by PCB_BASE_EDIT_FRAME::CreateNewLibrary(), and FP_LIB_TABLE::FootprintLibDelete().

107 {
108  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
109  not_implemented( this, __FUNCTION__ );
110  return false;
111 }
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
void EAGLE_PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
overridevirtual

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 from PLUGIN.

Definition at line 3104 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

3105 {
3106  PLUGIN::FootprintLibOptions( aListToAppendTo );
3107 
3108  /*
3109  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
3110  "Ignore duplicately named footprints within the same Eagle library. "
3111  "Only the first similarly named footprint will be loaded."
3112  ));
3113  */
3114 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:122
MODULE * EAGLE_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 3083 of file eagle_plugin.cpp.

References cacheLib(), init(), m_templates, and TO_UTF8.

3085 {
3086  init( aProperties );
3087 
3088  cacheLib( aLibraryPath );
3089 
3090  string key = TO_UTF8( aFootprintName );
3091 
3092  MODULE_CITER mi = m_templates.find( key );
3093 
3094  if( mi == m_templates.end() )
3095  return NULL;
3096 
3097  // copy constructor to clone the template
3098  MODULE* ret = new MODULE( *mi->second );
3099 
3100  return ret;
3101 }
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
MODULE_MAP::const_iterator MODULE_CITER
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
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 85 of file plugin.cpp.

References not_implemented().

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), FP_LIB_TABLE::FootprintSave(), FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs(), and FOOTPRINT_EDIT_FRAME::SaveCurrentModule().

86 {
87  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
88  not_implemented( this, __FUNCTION__ );
89 }
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
const wxString EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 1163 of file eagle_plugin.cpp.

1164 {
1165  return wxT( "brd" );
1166 }
wxDateTime EAGLE_PLUGIN::getModificationTime ( const wxString &  aPath)
staticprivate

get a file's or dir's modification time.

Definition at line 2969 of file eagle_plugin.cpp.

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

Referenced by cacheLib().

2970 {
2971  wxFileName fn( aPath );
2972 
2973  // Do not call wxFileName::GetModificationTime() on a non-existent file, because
2974  // if it fails, wx's implementation calls the crap wxLogSysError() which
2975  // eventually infects our UI with an unwanted popup window, so don't let it fail.
2976  if( !fn.IsFileReadable() )
2977  {
2978  wxString msg = wxString::Format(
2979  _( "File '%s' is not readable." ),
2980  GetChars( aPath ) );
2981 
2982  THROW_IO_ERROR( msg );
2983  }
2984 
2985  /*
2986  // update the writable flag while we have a wxFileName, in a network this
2987  // is possibly quite dynamic anyway.
2988  m_writable = fn.IsFileWritable();
2989  */
2990 
2991  wxDateTime modTime = fn.GetModificationTime();
2992 
2993  if( !modTime.IsValid() )
2994  modTime.Now();
2995 
2996  return modTime;
2997 }
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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:92
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
void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 1277 of file eagle_plugin.cpp.

References biu_per_mm, XPATH::clear(), m_board, m_hole_count, m_min_trace, m_min_via, m_min_via_hole, m_pads_to_nets, m_props, m_rules, m_xpath, and mm_per_biu.

Referenced by EAGLE_PLUGIN(), FootprintEnumerate(), FootprintLoad(), and Load().

1278 {
1279  m_hole_count = 0;
1280  m_min_trace = 0;
1281  m_min_via = 0;
1282  m_min_via_hole = 0;
1283  m_xpath->clear();
1284  m_pads_to_nets.clear();
1285 
1286  // m_templates.clear(); this is the FOOTPRINT cache too
1287 
1288  m_board = NULL;
1289  m_props = aProperties;
1290 
1291  mm_per_biu = 1/IU_PER_MM;
1292  biu_per_mm = IU_PER_MM;
1293 
1294  delete m_rules;
1295  m_rules = new ERULES();
1296 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void clear()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:136
subset of eagle.drawing.board.designrules in the XML document
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:143
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
bool EAGLE_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
inlineoverridevirtual

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 93 of file eagle_plugin.h.

94  {
95  return false; // until someone writes others like FootprintSave(), etc.
96  }
int EAGLE_PLUGIN::kicad ( double  d) const
inlineprivate

Convert an Eagle distance to a KiCad distance.

Definition at line 1169 of file eagle_plugin.cpp.

References biu_per_mm, and KiROUND().

Referenced by kicad_fontz(), kicad_x(), kicad_y(), loadPlain(), loadSignals(), packageCircle(), packageHole(), packagePad(), packageSMD(), packageText(), and packageWire().

1170 {
1171  return KiROUND( biu_per_mm * d );
1172 }
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
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
wxSize EAGLE_PLUGIN::kicad_fontz ( double  d) const
inlineprivate

create a font size (fontz) from an eagle font size scalar

Definition at line 1175 of file eagle_plugin.cpp.

References kicad().

Referenced by loadPlain(), orientModuleText(), and packageText().

1176 {
1177  // texts seem to better match eagle when scaled down by 0.95
1178  int kz = kicad( d ) * 95 / 100;
1179  return wxSize( kz, kz );
1180 }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
LAYER_ID EAGLE_PLUGIN::kicad_layer ( int  aLayer) const
private

Convert an Eagle layer to a KiCad layer.

Definition at line 2810 of file eagle_plugin.cpp.

References B_Adhes, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, DIM, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Fab, F_Mask, F_Paste, F_SilkS, m_cu_map, and UNDEFINED_LAYER.

Referenced by loadLayerDefs(), loadPlain(), loadSignals(), packageCircle(), packagePolygon(), packageRectangle(), packageSMD(), packageText(), and packageWire().

2811 {
2812  /* will assume this is a valid mapping for all eagle boards until I get paid more:
2813 
2814  <layers>
2815  <layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
2816  <layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
2817  <layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
2818  <layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
2819  <layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
2820  <layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
2821  <layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
2822  <layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
2823  <layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
2824  <layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
2825  <layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
2826  <layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
2827  <layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
2828  <layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
2829  <layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
2830  <layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
2831  <layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
2832  <layer number="18" name="Vias" color="14" fill="1" visible="yes" active="yes"/>
2833  <layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
2834  <layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
2835  <layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
2836  <layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
2837  <layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
2838  <layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
2839  <layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
2840  <layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
2841  <layer number="27" name="tValues" color="7" fill="1" visible="no" active="yes"/>
2842  <layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
2843  <layer number="29" name="tStop" color="2" fill="3" visible="no" active="yes"/>
2844  <layer number="30" name="bStop" color="5" fill="6" visible="no" active="yes"/>
2845  <layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
2846  <layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
2847  <layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
2848  <layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
2849  <layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
2850  <layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
2851  <layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
2852  <layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
2853  <layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
2854  <layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
2855  <layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
2856  <layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
2857  <layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
2858  <layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
2859  <layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
2860  <layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
2861  <layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
2862  <layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
2863  <layer number="49" name="ReferenceLC" color="13" fill="1" visible="yes" active="yes"/>
2864  <layer number="50" name="ReferenceLS" color="12" fill="1" visible="yes" active="yes"/>
2865  <layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
2866  <layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
2867 
2868  * These layers are used only in eagle schematic.
2869  * They should not be found in board files.
2870  * They are listed for info only.
2871  <layer number="91" name="Nets" color="2" fill="1" visible="no" active="no"/>
2872  <layer number="92" name="Busses" color="1" fill="1" visible="no" active="no"/>
2873  <layer number="93" name="Pins" color="2" fill="1" visible="no" active="no"/>
2874  <layer number="94" name="Symbols" color="4" fill="1" visible="no" active="no"/>
2875  <layer number="95" name="Names" color="7" fill="1" visible="no" active="no"/>
2876  <layer number="96" name="Values" color="7" fill="1" visible="no" active="no"/>
2877  <layer number="97" name="Info" color="7" fill="1" visible="no" active="no"/>
2878  <layer number="98" name="Guide" color="6" fill="1" visible="no" active="no"/>
2879 
2880  * These layers are user layers
2881  <layer number="160" name="???" color="7" fill="1" visible="yes" active="yes"/>
2882  <layer number="161" name="???" color="7" fill="1" visible="yes" active="yes"/>
2883 
2884  </layers>
2885 
2886  */
2887 
2888  int kiLayer;
2889 
2890  // eagle copper layer:
2891  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
2892  {
2893  kiLayer = m_cu_map[aEagleLayer];
2894  }
2895 
2896  else
2897  {
2898  // translate non-copper eagle layer to pcbnew layer
2899  switch( aEagleLayer )
2900  {
2901  case 20: kiLayer = Edge_Cuts; break; // eagle says "Dimension" layer, but it's for board perimeter
2902  case 21: kiLayer = F_SilkS; break;
2903  case 22: kiLayer = B_SilkS; break;
2904  case 25: kiLayer = F_SilkS; break;
2905  case 26: kiLayer = B_SilkS; break;
2906  case 27: kiLayer = F_SilkS; break;
2907  case 28: kiLayer = B_SilkS; break;
2908  case 29: kiLayer = F_Mask; break;
2909  case 30: kiLayer = B_Mask; break;
2910  case 31: kiLayer = F_Paste; break;
2911  case 32: kiLayer = B_Paste; break;
2912  case 33: kiLayer = F_Mask; break;
2913  case 34: kiLayer = B_Mask; break;
2914  case 35: kiLayer = F_Adhes; break;
2915  case 36: kiLayer = B_Adhes; break;
2916  case 48: kiLayer = Cmts_User; break;
2917  case 49: kiLayer = Cmts_User; break;
2918  case 50: kiLayer = Cmts_User; break;
2919 
2920  // Packages show the future chip pins on SMD parts using layer 51.
2921  // This is an area slightly smaller than the PAD/SMD copper area.
2922  // Carry those visual aids into the MODULE on the fabrication layer,
2923  // not silkscreen. This is perhaps not perfect, but there is not a lot
2924  // of other suitable paired layers
2925  case 51: kiLayer = F_Fab; break;
2926  case 52: kiLayer = B_Fab; break;
2927 
2928  // thes layers are defined as user layers. put them on ECO layers
2929  case 160: kiLayer = Eco1_User; break;
2930  case 161: kiLayer = Eco2_User; break;
2931  default:
2932  // some layers do not map to KiCad
2933  // DBG( printf( "unsupported eagle layer: %d\n", aEagleLayer );)
2934  kiLayer = UNDEFINED_LAYER; break;
2935  }
2936  }
2937 
2938  return LAYER_ID( kiLayer );
2939 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
int EAGLE_PLUGIN::kicad_x ( double  x) const
inlineprivate

Definition at line 157 of file eagle_plugin.h.

References kicad().

Referenced by loadElements(), loadPlain(), loadSignals(), orientModuleText(), packageCircle(), packageHole(), packagePad(), packagePolygon(), packageRectangle(), packageSMD(), packageText(), and packageWire().

157 { return kicad( x ); }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
int EAGLE_PLUGIN::kicad_y ( double  y) const
inlineprivate

Definition at line 156 of file eagle_plugin.h.

References kicad().

Referenced by loadElements(), loadPlain(), loadSignals(), orientModuleText(), packageCircle(), packageHole(), packagePad(), packagePolygon(), packageRectangle(), packageSMD(), packageText(), and packageWire().

156 { return -kicad( y ); }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
BOARD * EAGLE_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 1183 of file eagle_plugin.cpp.

References centerBoard(), XPATH::Contents(), BOARD_DESIGN_SETTINGS::GetDefault(), init(), KiROUND(), loadAllSections(), m_board, m_min_trace, m_min_via, m_min_via_hole, m_rules, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, m_xpath, ERULES::mdWireWire, BOARD::SetFileName(), and THROW_IO_ERROR.

1184 {
1185  LOCALE_IO toggle; // toggles on, then off, the C locale.
1186  PTREE doc;
1187 
1188  init( aProperties );
1189 
1190  m_board = aAppendToMe ? aAppendToMe : new BOARD();
1191 
1192  // Give the filename to the board if it's new
1193  if( !aAppendToMe )
1194  m_board->SetFileName( aFileName );
1195 
1196  // delete on exception, if I own m_board, according to aAppendToMe
1197  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
1198 
1199  try
1200  {
1201  // 8 bit "filename" should be encoded according to disk filename encoding,
1202  // (maybe this is current locale, maybe not, its a filesystem issue),
1203  // and is not necessarily utf8.
1204  string filename = (const char*) aFileName.char_str( wxConvFile );
1205 
1206  read_xml( filename, doc, xml_parser::no_comments );
1207 
1208  m_min_trace = INT_MAX;
1209  m_min_via = INT_MAX;
1210  m_min_via_hole = INT_MAX;
1211 
1212  loadAllSections( doc );
1213 
1214  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
1215 
1216  if( m_min_trace < designSettings.m_TrackMinWidth )
1217  designSettings.m_TrackMinWidth = m_min_trace;
1218 
1219  if( m_min_via < designSettings.m_ViasMinSize )
1220  designSettings.m_ViasMinSize = m_min_via;
1221 
1222  if( m_min_via_hole < designSettings.m_ViasMinDrill )
1223  designSettings.m_ViasMinDrill = m_min_via_hole;
1224 
1225  if( m_rules->mdWireWire )
1226  {
1227  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
1228  int clearance = KiROUND( m_rules->mdWireWire );
1229 
1230  if( clearance < defaultNetclass->GetClearance() )
1231  defaultNetclass->SetClearance( clearance );
1232  }
1233 
1234  // should be empty, else missing m_xpath->pop()
1235  wxASSERT( m_xpath->Contents().size() == 0 );
1236  }
1237 
1238  catch( file_parser_error fpe )
1239  {
1240  // for xml_parser_error, what() has the line number in it,
1241  // but no byte offset. That should be an adequate error message.
1242  THROW_IO_ERROR( fpe.what() );
1243  }
1244 
1245  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
1246  // so one catch should be OK for all errors.
1247  catch( ptree_error pte )
1248  {
1249  string errmsg = pte.what();
1250 
1251  errmsg += " @\n";
1252  errmsg += m_xpath->Contents();
1253 
1254  THROW_IO_ERROR( errmsg );
1255  }
1256 
1257  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
1258 
1259  // Ensure the copper layers count is a multiple of 2
1260  // Pcbnew does not like boards with odd layers count
1261  // (these boards cannot exist. they actually have a even layers count)
1262  int lyrcnt = m_board->GetCopperLayerCount();
1263 
1264  if( (lyrcnt % 2) != 0 )
1265  {
1266  lyrcnt++;
1267  m_board->SetCopperLayerCount( lyrcnt );
1268  }
1269 
1270  centerBoard();
1271 
1272  deleter.release();
1273  return m_board;
1274 }
NETCLASSPTR GetDefault() const
Function GetDefault.
void centerBoard()
move the BOARD into the center of the page
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
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
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void loadAllSections(CPTREE &aDocument)
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetCopperLayerCount(int aCount)
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_ViasMinDrill
vias (not micro vias) min drill diameter
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetFileName(const wxString &aFileName)
Definition: class_board.h:235
double mdWireWire
wire to wire spacing I presume.
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
string Contents()
return the contents of the XPATH as a single string
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void EAGLE_PLUGIN::loadAllSections ( CPTREE aDocument)
private

Definition at line 1308 of file eagle_plugin.cpp.

References loadDesignRules(), loadElements(), loadLayerDefs(), loadLibraries(), loadPlain(), loadSignals(), m_xpath, XPATH::pop(), and XPATH::push().

Referenced by Load().

1309 {
1310  CPTREE& drawing = aDoc.get_child( "eagle.drawing" );
1311  CPTREE& board = drawing.get_child( "board" );
1312 
1313  m_xpath->push( "eagle.drawing" );
1314 
1315  {
1316  m_xpath->push( "board" );
1317 
1318  CPTREE& designrules = board.get_child( "designrules" );
1319  loadDesignRules( designrules );
1320 
1321  m_xpath->pop();
1322  }
1323 
1324  {
1325  m_xpath->push( "layers" );
1326 
1327  CPTREE& layers = drawing.get_child( "layers" );
1328  loadLayerDefs( layers );
1329 
1330  m_xpath->pop();
1331  }
1332 
1333  {
1334  m_xpath->push( "board" );
1335 
1336  CPTREE& plain = board.get_child( "plain" );
1337  loadPlain( plain );
1338 
1339  CPTREE& signals = board.get_child( "signals" );
1340  loadSignals( signals );
1341 
1342  CPTREE& libs = board.get_child( "libraries" );
1343  loadLibraries( libs );
1344 
1345  CPTREE& elems = board.get_child( "elements" );
1346  loadElements( elems );
1347 
1348  m_xpath->pop(); // "board"
1349  }
1350 
1351  m_xpath->pop(); // "eagle.drawing"
1352 }
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void loadDesignRules(CPTREE &aDesignRules)
void loadSignals(CPTREE &aSignals)
void loadLibraries(CPTREE &aLibs)
void loadPlain(CPTREE &aPlain)
void pop()
void loadElements(CPTREE &aElements)
void loadLayerDefs(CPTREE &aLayers)
void EAGLE_PLUGIN::loadDesignRules ( CPTREE aDesignRules)
private

Definition at line 1355 of file eagle_plugin.cpp.

References m_rules, m_xpath, ERULES::parse(), XPATH::pop(), and XPATH::push().

Referenced by loadAllSections().

1356 {
1357  m_xpath->push( "designrules" );
1358  m_rules->parse( aDesignRules );
1359  m_xpath->pop(); // "designrules"
1360 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
void push(const char *aPathSegment, const char *aAttribute="")
void parse(CPTREE &aRules)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void pop()
void EAGLE_PLUGIN::loadElements ( CPTREE aElements)
private

Definition at line 1771 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, EATTR::BOTH, EATTR::display, Format(), FROM_UTF8(), GetChars(), MODULE::GetReference(), MODULE::GetValue(), kicad_x(), kicad_y(), EELEMENT::library, m_board, m_pads_to_nets, m_templates, m_xpath, makeKey(), EATTR::name, EATTR::NAME, EELEMENT::name, ENET::netcode, D_PAD::Next(), EATTR::Off, orientModuleAndText(), EELEMENT::package, MODULE::Pads(), XPATH::pop(), XPATH::push(), MODULE::Reference(), MODULE::SetPosition(), MODULE::SetReference(), MODULE::SetValue(), EDA_TEXT::SetVisible(), EELEMENT::smashed, THROW_IO_ERROR, TO_UTF8, XPATH::Value(), MODULE::Value(), EATTR::value, EATTR::VALUE, EELEMENT::value, EELEMENT::x, and EELEMENT::y.

Referenced by loadAllSections().

1772 {
1773  m_xpath->push( "elements.element", "name" );
1774 
1775  EATTR name;
1776  EATTR value;
1777  bool refanceNamePresetInPackageLayout;
1778  bool valueNamePresetInPackageLayout;
1779 
1780 
1781 
1782  for( CITER it = aElements.begin(); it != aElements.end(); ++it )
1783  {
1784  if( it->first != "element" )
1785  continue;
1786 
1787  EELEMENT e( it->second );
1788 
1789  // use "NULL-ness" as an indication of presence of the attribute:
1790  EATTR* nameAttr = 0;
1791  EATTR* valueAttr = 0;
1792 
1793  m_xpath->Value( e.name.c_str() );
1794 
1795  string pkg_key = makeKey( e.library, e.package );
1796 
1797  MODULE_CITER mi = m_templates.find( pkg_key );
1798 
1799  if( mi == m_templates.end() )
1800  {
1801  wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
1802  GetChars( FROM_UTF8( e.package.c_str() ) ),
1803  GetChars( FROM_UTF8( e.library.c_str() ) ) );
1804  THROW_IO_ERROR( emsg );
1805  }
1806 
1807  // copy constructor to clone the template
1808  MODULE* m = new MODULE( *mi->second );
1809  m_board->Add( m, ADD_APPEND );
1810 
1811  // update the nets within the pads of the clone
1812  for( D_PAD* pad = m->Pads(); pad; pad = pad->Next() )
1813  {
1814  string pn_key = makeKey( e.name, TO_UTF8( pad->GetPadName() ) );
1815 
1816  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
1817  if( ni != m_pads_to_nets.end() )
1818  {
1819  const ENET* enet = &ni->second;
1820  pad->SetNetCode( enet->netcode );
1821  }
1822  }
1823 
1824  refanceNamePresetInPackageLayout = true;
1825  valueNamePresetInPackageLayout = true;
1826  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1827  // Is >NAME field set in package layout ?
1828  if( m->GetReference().size() == 0 )
1829  {
1830  m->Reference().SetVisible( false ); // No so no show
1831  refanceNamePresetInPackageLayout = false;
1832  }
1833  // Is >VALUE field set in package layout
1834  if( m->GetValue().size() == 0 )
1835  {
1836  m->Value().SetVisible( false ); // No so no show
1837  valueNamePresetInPackageLayout = false;
1838  }
1839  m->SetReference( FROM_UTF8( e.name.c_str() ) );
1840  m->SetValue( FROM_UTF8( e.value.c_str() ) );
1841 
1842  if( !e.smashed )
1843  { // Not smashed so show NAME & VALUE
1844  if( valueNamePresetInPackageLayout )
1845  m->Value().SetVisible( true ); // Only if place holder in package layout
1846  if( refanceNamePresetInPackageLayout )
1847  m->Reference().SetVisible( true ); // Only if place holder in package layout
1848  }
1849  else if( *e.smashed == true )
1850  { // Smasted so set default to no show for NAME and VALUE
1851  m->Value().SetVisible( false );
1852  m->Reference().SetVisible( false );
1853 
1854  // initalize these to default values incase the <attribute> elements are not present.
1855  m_xpath->push( "attribute", "name" );
1856 
1857  // VALUE and NAME can have something like our text "effects" overrides
1858  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
1859  // There can be one for NAME and/or VALUE both. Features present in the
1860  // EATTR override the ones established in the package only if they are
1861  // present here (except for rot, which if not present means angle zero).
1862  // So the logic is a bit different than in packageText() and in plain text.
1863  for( CITER ait = it->second.begin(); ait != it->second.end(); ++ait )
1864  {
1865 
1866  if( ait->first != "attribute" )
1867  continue;
1868 
1869  EATTR a( ait->second );
1870 
1871  if( a.name == "NAME" )
1872  {
1873  name = a;
1874  nameAttr = &name;
1875 
1876  // do we have a display attribute ?
1877  if( a.display )
1878  {
1879  // Yes!
1880  switch( *a.display )
1881  {
1882  case EATTR::VALUE :
1883  nameAttr->name = e.name;
1884  m->SetReference( e.name );
1885  if( refanceNamePresetInPackageLayout )
1886  m->Reference().SetVisible( true );
1887  break;
1888 
1889  case EATTR::NAME :
1890  if( refanceNamePresetInPackageLayout )
1891  {
1892  m->SetReference( "NAME" );
1893  m->Reference().SetVisible( true );
1894  }
1895  break;
1896 
1897  case EATTR::BOTH :
1898  if( refanceNamePresetInPackageLayout )
1899  m->Reference().SetVisible( true );
1900  nameAttr->name = nameAttr->name + " = " + e.name;
1901  m->SetReference( "NAME = " + e.name );
1902  break;
1903 
1904  case EATTR::Off :
1905  m->Reference().SetVisible( false );
1906  break;
1907 
1908  default:
1909  nameAttr->name = e.name;
1910  if( refanceNamePresetInPackageLayout )
1911  m->Reference().SetVisible( true );
1912  }
1913  }
1914  else
1915  // No display, so default is visable, and show value of NAME
1916  m->Reference().SetVisible( true );
1917  }
1918  else if( a.name == "VALUE" )
1919  {
1920  value = a;
1921  valueAttr = &value;
1922 
1923  if( a.display )
1924  {
1925  // Yes!
1926  switch( *a.display )
1927  {
1928  case EATTR::VALUE :
1929  valueAttr->value = e.value;
1930  m->SetValue( e.value );
1931  if( valueNamePresetInPackageLayout )
1932  m->Value().SetVisible( true );
1933  break;
1934 
1935  case EATTR::NAME :
1936  if( valueNamePresetInPackageLayout )
1937  m->Value().SetVisible( true );
1938  m->SetValue( "VALUE" );
1939  break;
1940 
1941  case EATTR::BOTH :
1942  if( valueNamePresetInPackageLayout )
1943  m->Value().SetVisible( true );
1944  valueAttr->value = "VALUE = " + e.value;
1945  m->SetValue( "VALUE = " + e.value );
1946  break;
1947 
1948  case EATTR::Off :
1949  m->Value().SetVisible( false );
1950  break;
1951 
1952  default:
1953  valueAttr->value = e.value;
1954  if( valueNamePresetInPackageLayout )
1955  m->Value().SetVisible( true );
1956  }
1957  }
1958  else
1959  // No display, so default is visible, and show value of NAME
1960  m->Value().SetVisible( true );
1961 
1962  }
1963  }
1964 
1965  m_xpath->pop(); // "attribute"
1966  }
1967 
1968  orientModuleAndText( m, e, nameAttr, valueAttr );
1969  }
1970 
1971  m_xpath->pop(); // "elements.element"
1972 }
TEXTE_MODULE & Reference()
Definition: class_module.h:455
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:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
void push(const char *aPathSegment, const char *aAttribute="")
Eagle element element.
void SetVisible(bool aVisible)
Definition: eda_text.h:175
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:439
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:60
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int kicad_y(double y) const
Definition: eagle_plugin.h:156
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
string name
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
D_PAD * Next() const
Definition: class_pad.h:106
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:421
opt_string value
int kicad_x(double x) const
Definition: eagle_plugin.h:157
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetPosition(const wxPoint &aPos) override
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
PTREE::const_iterator CITER
Eagle "attribute" XML element, no foolin'.
MODULE_MAP::const_iterator MODULE_CITER
int netcode
Definition: eagle_plugin.h:46
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:92
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
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:411
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:448
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadLayerDefs ( CPTREE aLayers)
private

Definition at line 1363 of file eagle_plugin.cpp.

References ELAYER::active, B_Cu, cu, DIM, F_Cu, FROM_UTF8(), kicad_layer(), LT_SIGNAL, m_board, m_cu_map, ELAYER::number, BOARD::SetCopperLayerCount(), BOARD::SetLayerName(), and BOARD::SetLayerType().

Referenced by cacheLib(), and loadAllSections().

1364 {
1365  typedef std::vector<ELAYER> ELAYERS;
1366  typedef ELAYERS::const_iterator EITER;
1367 
1368  ELAYERS cu; // copper layers
1369 
1370  // find the subset of layers that are copper, and active
1371  for( CITER layer = aLayers.begin(); layer != aLayers.end(); ++layer )
1372  {
1373  ELAYER elayer( layer->second );
1374 
1375  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
1376  {
1377  cu.push_back( elayer );
1378  }
1379  }
1380 
1381  // establish cu layer map:
1382  int ki_layer_count = 0;
1383 
1384  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
1385  {
1386  if( ki_layer_count == 0 )
1387  m_cu_map[it->number] = F_Cu;
1388  else if( ki_layer_count == int( cu.size()-1 ) )
1389  m_cu_map[it->number] = B_Cu;
1390  else
1391  {
1392  // some eagle boards do not have contiguous layer number sequences.
1393 
1394 #if 0 // pre LAYER_ID & LSET:
1395  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
1396 #else
1397  m_cu_map[it->number] = ki_layer_count;
1398 #endif
1399  }
1400  }
1401 
1402 #if 0 && defined(DEBUG)
1403  printf( "m_cu_map:\n" );
1404  for( unsigned i=0; i<DIM(m_cu_map); ++i )
1405  {
1406  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
1407  }
1408 #endif
1409 
1410  // Set the layer names and cu count iff we're loading a board.
1411  if( m_board )
1412  {
1413  m_board->SetCopperLayerCount( cu.size() );
1414 
1415  for( EITER it = cu.begin(); it != cu.end(); ++it )
1416  {
1417  LAYER_ID layer = kicad_layer( it->number );
1418 
1419  // these function provide their own protection against UNDEFINED_LAYER:
1420  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
1421  m_board->SetLayerType( layer, LT_SIGNAL );
1422 
1423  // could map the colors here
1424  }
1425  }
1426 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
bool SetLayerType(LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
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:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void SetCopperLayerCount(int aCount)
#define cu(a)
Definition: auxiliary.h:88
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
bool SetLayerName(LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
PTREE::const_iterator CITER
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void EAGLE_PLUGIN::loadLibraries ( CPTREE aLibs)
private

Definition at line 1754 of file eagle_plugin.cpp.

References loadLibrary(), m_xpath, XPATH::pop(), XPATH::push(), and XPATH::Value().

Referenced by loadAllSections().

1755 {
1756  m_xpath->push( "libraries.library", "name" );
1757 
1758  for( CITER library = aLibs.begin(); library != aLibs.end(); ++library )
1759  {
1760  const string& lib_name = library->second.get<string>( "<xmlattr>.name" );
1761 
1762  m_xpath->Value( lib_name.c_str() );
1763 
1764  loadLibrary( library->second, &lib_name );
1765  }
1766 
1767  m_xpath->pop();
1768 }
void push(const char *aPathSegment, const char *aAttribute="")
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
PTREE::const_iterator CITER
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadLibrary ( CPTREE aLib,
const std::string *  aLibName 
)
private

Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries" element (if a *.brd file) or under a "drawing" element if a *.lbr file.

Parameters
aLibis the portion of the loaded XML document tree that is the "library" element.
aLibNameis a pointer to the library name or NULL. If NULL this means we are loading a *.lbr not a *.brd file and the key used in m_templates is to exclude the library name.

Definition at line 1702 of file eagle_plugin.cpp.

References Format(), FROM_UTF8(), GetChars(), m_lib_path, m_templates, m_xpath, makeKey(), makeModule(), XPATH::pop(), XPATH::push(), ReplaceIllegalFileNameChars(), THROW_IO_ERROR, and XPATH::Value().

Referenced by cacheLib(), and loadLibraries().

1703 {
1704  m_xpath->push( "packages" );
1705 
1706  // library will have <xmlattr> node, skip that and get the single packages node
1707  CPTREE& packages = aLib.get_child( "packages" );
1708 
1709  // Create a MODULE for all the eagle packages, for use later via a copy constructor
1710  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
1711  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
1712 
1713  for( CITER package = packages.begin(); package != packages.end(); ++package )
1714  {
1715  m_xpath->push( "package", "name" );
1716 
1717  const string& pack_ref = package->second.get<string>( "<xmlattr>.name" );
1718 
1719  string pack_name( pack_ref );
1720 
1721  ReplaceIllegalFileNameChars( &pack_name );
1722 
1723  m_xpath->Value( pack_name.c_str() );
1724 
1725  string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name;
1726 
1727  MODULE* m = makeModule( package->second, pack_name );
1728 
1729  // add the templating MODULE to the MODULE template factory "m_templates"
1730  std::pair<MODULE_ITER, bool> r = m_templates.insert( key, m );
1731 
1732  if( !r.second
1733  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
1734  )
1735  {
1736  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
1737  wxString pkg = FROM_UTF8( pack_name.c_str() );
1738 
1739  wxString emsg = wxString::Format(
1740  _( "<package> name: '%s' duplicated in eagle <library>: '%s'" ),
1741  GetChars( pkg ),
1742  GetChars( lib )
1743  );
1744  THROW_IO_ERROR( emsg );
1745  }
1746 
1747  m_xpath->pop();
1748  }
1749 
1750  m_xpath->pop(); // "packages"
1751 }
MODULE * makeModule(CPTREE &aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
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:53
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:483
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
wxString m_lib_path
Definition: eagle_plugin.h:146
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
PTREE::const_iterator CITER
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:92
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
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadPlain ( CPTREE aPlain)
private

Definition at line 1429 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, DIMENSION::AdjustDimensionDetails(), ETEXT::align, LSET::AllCuMask(), ZONE_CONTAINER::AppendCorner(), ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Clamp_Text_PenSize(), EWIRE::curve, DEFAULT_PCB_EDGE_THICKNESS, ZONE_CONTAINER::DIAGONAL_EDGE, EHOLE::drill, FROM_UTF8(), ZONE_CONTAINER::GetDefaultHatchPitchMils(), BOARD::GetDesignSettings(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, IsCopperLayer(), kicad(), kicad_arc_center(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, ECIRCLE::layer, ERECT::layer, EDIMENSION::layer, ETEXT::layer, m_board, m_hole_count, BOARD_DESIGN_SETTINGS::m_PcbTextSize, BOARD_DESIGN_SETTINGS::m_PcbTextWidth, m_xpath, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CIRCLE, MODULE::Pads(), XPATH::pop(), XPATH::push(), DLIST< T >::PushBack(), ECIRCLE::radius, ETEXT::ratio, MODULE::Reference(), ETEXT::rot, S_ARC, S_CIRCLE, DRAWSEGMENT::SetAngle(), D_PAD::SetAttribute(), D_PAD::SetDrillSize(), DRAWSEGMENT::SetEnd(), DIMENSION::SetEnd(), ZONE_CONTAINER::SetHatch(), DIMENSION::SetHeight(), EDA_TEXT::SetHorizJustify(), DIMENSION::SetLayer(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), EDA_TEXT::SetMirrored(), BOARD_CONNECTED_ITEM::SetNetCode(), DIMENSION::SetOrigin(), MODULE::SetPosition(), MODULE::SetReference(), DRAWSEGMENT::SetShape(), D_PAD::SetShape(), D_PAD::SetSize(), DRAWSEGMENT::SetStart(), EDA_TEXT::SetText(), TEXTE_PCB::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), DRAWSEGMENT::SetWidth(), DIMENSION::SetWidth(), sign(), ETEXT::size, DIMENSION::Text(), ETEXT::text, timeStamp(), ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, NETINFO_LIST::UNCONNECTED, UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, ETEXT::x, EHOLE::x, EWIRE::x1, ERECT::x1, EDIMENSION::x1, EWIRE::x2, ERECT::x2, EDIMENSION::x2, EDIMENSION::x3, ECIRCLE::y, ETEXT::y, EHOLE::y, EWIRE::y1, ERECT::y1, EDIMENSION::y1, EWIRE::y2, ERECT::y2, EDIMENSION::y2, and EDIMENSION::y3.

Referenced by loadAllSections().

1430 {
1431  m_xpath->push( "plain" );
1432 
1433  // (polygon | wire | text | circle | rectangle | frame | hole)*
1434  for( CITER gr = aGraphics.begin(); gr != aGraphics.end(); ++gr )
1435  {
1436  if( gr->first == "wire" )
1437  {
1438  m_xpath->push( "wire" );
1439 
1440  EWIRE w( gr->second );
1441  LAYER_ID layer = kicad_layer( w.layer );
1442 
1443  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1444  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1445 
1446  if( layer != UNDEFINED_LAYER )
1447  {
1448  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1449  m_board->Add( dseg, ADD_APPEND );
1450 
1451  if( !w.curve )
1452  {
1453  dseg->SetStart( start );
1454  dseg->SetEnd( end );
1455  }
1456  else
1457  {
1458  wxPoint center = kicad_arc_center( start, end, *w.curve);
1459 
1460  dseg->SetShape( S_ARC );
1461  dseg->SetStart( center );
1462  dseg->SetEnd( start );
1463  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1464  }
1465 
1466  dseg->SetTimeStamp( timeStamp( gr->second ) );
1467  dseg->SetLayer( layer );
1468  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
1469  }
1470  m_xpath->pop();
1471  }
1472  else if( gr->first == "text" )
1473  {
1474  m_xpath->push( "text" );
1475 
1476  ETEXT t( gr->second );
1477  LAYER_ID layer = kicad_layer( t.layer );
1478 
1479  if( layer != UNDEFINED_LAYER )
1480  {
1481  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
1482  m_board->Add( pcbtxt, ADD_APPEND );
1483 
1484  pcbtxt->SetLayer( layer );
1485  pcbtxt->SetTimeStamp( timeStamp( gr->second ) );
1486  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
1487  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
1488 
1489  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
1490 
1491  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1492 
1493  pcbtxt->SetThickness( kicad( t.size * ratio / 100 ) );
1494 
1495  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
1496 
1497  if( t.rot )
1498  {
1499  int sign = t.rot->mirror ? -1 : 1;
1500  pcbtxt->SetMirrored( t.rot->mirror );
1501 
1502  double degrees = t.rot->degrees;
1503 
1504  if( degrees == 90 || t.rot->spin )
1505  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1506  else if( degrees == 180 )
1507  align = ETEXT::TOP_RIGHT;
1508  else if( degrees == 270 )
1509  {
1510  pcbtxt->SetTextAngle( sign * 90 * 10 );
1511  align = ETEXT::TOP_RIGHT;
1512  }
1513  }
1514 
1515  switch( align )
1516  {
1517  case ETEXT::CENTER:
1518  // this was the default in pcbtxt's constructor
1519  break;
1520 
1521  case ETEXT::CENTER_LEFT:
1523  break;
1524 
1525  case ETEXT::CENTER_RIGHT:
1527  break;
1528 
1529  case ETEXT::TOP_CENTER:
1531  break;
1532 
1533  case ETEXT::TOP_LEFT:
1536  break;
1537 
1538  case ETEXT::TOP_RIGHT:
1541  break;
1542 
1543  case ETEXT::BOTTOM_CENTER:
1545  break;
1546 
1547  case ETEXT::BOTTOM_LEFT:
1550  break;
1551 
1552  case ETEXT::BOTTOM_RIGHT:
1555  break;
1556  }
1557  }
1558  m_xpath->pop();
1559  }
1560  else if( gr->first == "circle" )
1561  {
1562  m_xpath->push( "circle" );
1563 
1564  ECIRCLE c( gr->second );
1565  LAYER_ID layer = kicad_layer( c.layer );
1566 
1567  if( layer != UNDEFINED_LAYER ) // unsupported layer
1568  {
1569  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1570  m_board->Add( dseg, ADD_APPEND );
1571 
1572  dseg->SetShape( S_CIRCLE );
1573  dseg->SetTimeStamp( timeStamp( gr->second ) );
1574  dseg->SetLayer( layer );
1575  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
1576  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
1577  dseg->SetWidth( kicad( c.width ) );
1578  }
1579  m_xpath->pop();
1580  }
1581  else if( gr->first == "rectangle" )
1582  {
1583  // This seems to be a simplified rectangular [copper] zone, cannot find any
1584  // net related info on it from the DTD.
1585  m_xpath->push( "rectangle" );
1586 
1587  ERECT r( gr->second );
1588  LAYER_ID layer = kicad_layer( r.layer );
1589 
1590  if( IsCopperLayer( layer ) )
1591  {
1592  // use a "netcode = 0" type ZONE:
1593  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
1594  m_board->Add( zone, ADD_APPEND );
1595 
1596  zone->SetTimeStamp( timeStamp( gr->second ) );
1597  zone->SetLayer( layer );
1599 
1601 
1602  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1603  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1604  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1605  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1606 
1607  // this is not my fault:
1608  zone->SetHatch( outline_hatch, Mils2iu( zone->GetDefaultHatchPitchMils() ), true );
1609  }
1610 
1611  m_xpath->pop();
1612  }
1613  else if( gr->first == "hole" )
1614  {
1615  m_xpath->push( "hole" );
1616  EHOLE e( gr->second );
1617 
1618  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
1619  // Use m_hole_count to gen up a unique name.
1620 
1621  MODULE* module = new MODULE( m_board );
1622  m_board->Add( module, ADD_APPEND );
1623 
1624  char temp[40];
1625  sprintf( temp, "@HOLE%d", m_hole_count++ );
1626  module->SetReference( FROM_UTF8( temp ) );
1627  module->Reference().SetVisible( false );
1628 
1629  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
1630 
1631  module->SetPosition( pos );
1632 
1633  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1634  D_PAD* pad = new D_PAD( module );
1635  module->Pads().PushBack( pad );
1636 
1637  pad->SetShape( PAD_SHAPE_CIRCLE );
1639 
1640  /* pad's position is already centered on module at relative (0, 0)
1641  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1642 
1643  pad->SetPos0( padpos );
1644  pad->SetPosition( padpos + module->GetPosition() );
1645  */
1646 
1647  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
1648 
1649  pad->SetDrillSize( sz );
1650  pad->SetSize( sz );
1651 
1652  pad->SetLayerSet( LSET::AllCuMask() );
1653  m_xpath->pop();
1654  }
1655  else if( gr->first == "frame" )
1656  {
1657  // picture this
1658  }
1659  else if( gr->first == "polygon" )
1660  {
1661  // could be on a copper layer, could be on another layer.
1662  // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
1663  }
1664  else if( gr->first == "dimension" )
1665  {
1666  EDIMENSION d( gr->second );
1667 
1668  DIMENSION* dimension = new DIMENSION( m_board );
1669  m_board->Add( dimension, ADD_APPEND );
1670 
1671  dimension->SetLayer( kicad_layer( d.layer ) );
1672  // The origin and end are assumed to always be in this order from eagle
1673  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
1674  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
1676 
1677  int width = m_board->GetDesignSettings().m_PcbTextWidth;
1678  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
1679 
1680  if( width > maxThickness )
1681  width = maxThickness;
1682 
1683  dimension->Text().SetThickness( width );
1684  dimension->SetWidth( width );
1685 
1686  // check which axis the dimension runs in
1687  // because the "height" of the dimension is perpendicular to that axis
1688  // Note the check is just if two axes are close enough to each other
1689  // Eagle appears to have some rounding errors
1690  if( fabs( d.x1 - d.x2 ) < 0.05 )
1691  dimension->SetHeight( kicad_x( d.x1 - d.x3 ) );
1692  else
1693  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
1694 
1695  dimension->AdjustDimensionDetails();
1696  }
1697  }
1698  m_xpath->pop();
1699 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
void SetTextAngle(double aAngle)
TEXTE_MODULE & Reference()
Definition: class_module.h:455
void SetShape(STROKE_T aShape)
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:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
int m_PcbTextWidth
current Pcb (not module) Text width
void push(const char *aPathSegment, const char *aAttribute="")
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetVisible(bool aVisible)
Definition: eda_text.h:175
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:881
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
Eagle hole element.
Eagle text element.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
#define DEFAULT_PCB_EDGE_THICKNESS
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void SetLayer(LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
wxSize m_PcbTextSize
current Pcb (not module) Text size
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
void AppendCorner(wxPoint position, bool aAllowDuplication=false)
Function AppendCorner.
Definition: class_zone.h:546
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
Arcs (with rounded ends)
Eagle circle.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:421
int kicad_x(double x) const
Definition: eagle_plugin.h:157
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:85
void SetPosition(const wxPoint &aPos) override
wxPoint kicad_arc_center(wxPoint start, wxPoint end, double angle)
Convert an Eagle curve end to a KiCad center for S_ARC.
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
Eagle XML rectangle in binary.
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
PTREE::const_iterator CITER
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
TEXTE_PCB & Text()
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetEnd(const wxPoint &aEnd)
Eagle wire.
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
static int GetDefaultHatchPitchMils()
Function GetDefaultHatchPitchMils.
Definition: class_zone.h:670
Eagle dimension element.
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void pop()
void SetWidth(int aWidth)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
Class DIMENSION.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::loadSignals ( CPTREE aSignals)
private

Definition at line 2585 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, ZONE_CONTAINER::AppendCorner(), B_Cu, Clamp(), EPOLYGON::CUTOUT, ZONE_CONTAINER::DIAGONAL_EDGE, EVIA::diam, EVIA::drill, F_Cu, FROM_UTF8(), DLIST< T >::Insert(), IsCopperLayer(), EPOLYGON::isolate, kicad(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EWIRE::layer, EPOLYGON::layer, EVIA::layer_back_most, EVIA::layer_front_most, m_board, m_min_trace, m_min_via, m_min_via_hole, m_pads_to_nets, m_rules, BOARD::m_Track, m_xpath, makeKey(), EPOLYGON::max_priority, ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_THERMAL, XPATH::pop(), EPOLYGON::pour, XPATH::push(), EPOLYGON::rank, ERULES::rlMaxViaOuter, ERULES::rlMinViaOuter, ERULES::rvViaOuter, ZONE_CONTAINER::SetArcSegmentCount(), ZONE_CONTAINER::SetDoNotAllowCopperPour(), VIA::SetDrill(), TRACK::SetEnd(), ZONE_CONTAINER::SetHatch(), ZONE_CONTAINER::SetHatchStyle(), ZONE_CONTAINER::SetIsKeepout(), BOARD_ITEM::SetLayer(), VIA::SetLayerPair(), ZONE_CONTAINER::SetMinThickness(), BOARD_CONNECTED_ITEM::SetNetCode(), ZONE_CONTAINER::SetPadConnection(), TRACK::SetPosition(), VIA::SetPosition(), ZONE_CONTAINER::SetPriority(), ZONE_CONTAINER::SetThermalReliefCopperBridge(), ZONE_CONTAINER::SetThermalReliefGap(), EDA_ITEM::SetTimeStamp(), VIA::SetViaType(), TRACK::SetWidth(), ZONE_CONTAINER::SetZoneClearance(), EPOLYGON::spacing, EPOLYGON::thermals, timeStamp(), NETINFO_LIST::UNCONNECTED, XPATH::Value(), VIA_BLIND_BURIED, VIA_MICROVIA, VIA_THROUGH, EWIRE::width, EPOLYGON::width, EVIA::x, EVERTEX::x, EWIRE::x1, EWIRE::x2, EVIA::y, EVERTEX::y, EWIRE::y1, and EWIRE::y2.

Referenced by loadAllSections().

2586 {
2587  ZONES zones; // per net
2588 
2589  m_xpath->push( "signals.signal", "name" );
2590 
2591  int netCode = 1;
2592 
2593  for( CITER net = aSignals.begin(); net != aSignals.end(); ++net )
2594  {
2595  bool sawPad = false;
2596 
2597  zones.clear();
2598 
2599  const string& nname = net->second.get<string>( "<xmlattr>.name" );
2600  wxString netName = FROM_UTF8( nname.c_str() );
2601  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
2602 
2603  m_xpath->Value( nname.c_str() );
2604 
2605  // (contactref | polygon | wire | via)*
2606  for( CITER it = net->second.begin(); it != net->second.end(); ++it )
2607  {
2608  if( it->first == "wire" )
2609  {
2610  m_xpath->push( "wire" );
2611  EWIRE w( it->second );
2612  LAYER_ID layer = kicad_layer( w.layer );
2613 
2614  if( IsCopperLayer( layer ) )
2615  {
2616  TRACK* t = new TRACK( m_board );
2617 
2618  t->SetTimeStamp( timeStamp( it->second ) );
2619 
2620  t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
2621  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2622 
2623  int width = kicad( w.width );
2624  if( width < m_min_trace )
2625  m_min_trace = width;
2626 
2627  t->SetWidth( width );
2628  t->SetLayer( layer );
2629  t->SetNetCode( netCode );
2630 
2631  m_board->m_Track.Insert( t, NULL );
2632  }
2633  else
2634  {
2635  // put non copper wires where the sun don't shine.
2636  }
2637 
2638  m_xpath->pop();
2639  }
2640 
2641  else if( it->first == "via" )
2642  {
2643  m_xpath->push( "via" );
2644  EVIA v( it->second );
2645 
2646  LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2647  LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2648 
2649  if( IsCopperLayer( layer_front_most ) &&
2650  IsCopperLayer( layer_back_most ) )
2651  {
2652  int kidiam;
2653  int drillz = kicad( v.drill );
2654  VIA* via = new VIA( m_board );
2655  m_board->m_Track.Insert( via, NULL );
2656 
2657  via->SetLayerPair( layer_front_most, layer_back_most );
2658 
2659  if( v.diam )
2660  {
2661  kidiam = kicad( *v.diam );
2662  via->SetWidth( kidiam );
2663  }
2664  else
2665  {
2666  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2667  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
2668  kidiam = KiROUND( drillz + 2 * annulus );
2669  via->SetWidth( kidiam );
2670  }
2671 
2672  via->SetDrill( drillz );
2673 
2674  if( kidiam < m_min_via )
2675  m_min_via = kidiam;
2676 
2677  if( drillz < m_min_via_hole )
2678  m_min_via_hole = drillz;
2679 
2680  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2681  via->SetViaType( VIA_THROUGH );
2682  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2683  via->SetViaType( VIA_MICROVIA );
2684  else
2685  via->SetViaType( VIA_BLIND_BURIED );
2686 
2687  via->SetTimeStamp( timeStamp( it->second ) );
2688 
2689  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2690 
2691  via->SetPosition( pos );
2692  via->SetEnd( pos );
2693 
2694  via->SetNetCode( netCode );
2695  }
2696  m_xpath->pop();
2697  }
2698 
2699  else if( it->first == "contactref" )
2700  {
2701  m_xpath->push( "contactref" );
2702  // <contactref element="RN1" pad="7"/>
2703  CPTREE& attribs = it->second.get_child( "<xmlattr>" );
2704 
2705  const string& reference = attribs.get<string>( "element" );
2706  const string& pad = attribs.get<string>( "pad" );
2707 
2708  string key = makeKey( reference, pad ) ;
2709 
2710  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
2711 
2712  m_pads_to_nets[ key ] = ENET( netCode, nname );
2713 
2714  m_xpath->pop();
2715 
2716  sawPad = true;
2717  }
2718 
2719  else if( it->first == "polygon" )
2720  {
2721  m_xpath->push( "polygon" );
2722 
2723  EPOLYGON p( it->second );
2724  LAYER_ID layer = kicad_layer( p.layer );
2725 
2726  if( IsCopperLayer( layer ) )
2727  {
2728  // use a "netcode = 0" type ZONE:
2729  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
2730  m_board->Add( zone, ADD_APPEND );
2731  zones.push_back( zone );
2732 
2733  zone->SetTimeStamp( timeStamp( it->second ) );
2734  zone->SetLayer( layer );
2735  zone->SetNetCode( netCode );
2736 
2737  for( CITER vi = it->second.begin(); vi != it->second.end(); ++vi )
2738  {
2739  if( vi->first != "vertex" ) // skip <xmlattr> node
2740  continue;
2741 
2742  EVERTEX v( vi->second );
2743 
2744  // Append the corner
2745  zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2746  }
2747 
2748  // If the pour is a cutout it needs to be set to a keepout
2749  if( p.pour == EPOLYGON::CUTOUT )
2750  {
2751  zone->SetIsKeepout( true );
2752  zone->SetDoNotAllowCopperPour( true );
2754  }
2755 
2756  // if spacing is set the zone should be hatched
2757  if( p.spacing )
2758  zone->SetHatch( ZONE_CONTAINER::DIAGONAL_EDGE, *p.spacing, true );
2759 
2760  // clearances, etc.
2761  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
2762  zone->SetMinThickness( kicad( p.width ) );
2763 
2764  // FIXME: KiCad zones have very rounded corners compared to eagle.
2765  // This means that isolation amounts that work well in eagle
2766  // tend to make copper intrude in soldermask free areas around pads.
2767  if( p.isolate )
2768  {
2769  zone->SetZoneClearance( kicad( *p.isolate ) );
2770  }
2771 
2772  // missing == yes per DTD.
2773  bool thermals = !p.thermals || *p.thermals;
2775  if( thermals )
2776  {
2777  // FIXME: eagle calculates dimensions for thermal spokes
2778  // based on what the zone is connecting to.
2779  // (i.e. width of spoke is half of the smaller side of an smd pad)
2780  // This is a basic workaround
2781  zone->SetThermalReliefGap( kicad( p.width + 0.05 ) );
2782  zone->SetThermalReliefCopperBridge( kicad( p.width + 0.05 ) );
2783  }
2784 
2785  int rank = p.rank ? *p.rank : p.max_priority;
2786  zone->SetPriority( rank );
2787  }
2788 
2789  m_xpath->pop(); // "polygon"
2790  }
2791  }
2792 
2793  if( zones.size() && !sawPad )
2794  {
2795  // KiCad does not support an unconnected zone with its own non-zero netcode,
2796  // but only when assigned netcode = 0 w/o a name...
2797  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2798  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2799 
2800  // therefore omit this signal/net.
2801  }
2802  else
2803  netCode++;
2804  }
2805 
2806  m_xpath->pop(); // "signals.signal"
2807 }
double rlMaxViaOuter
maximum copper annulus on via
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
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:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:443
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 SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:416
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:116
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:197
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:881
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
double rvViaOuter
copper annulus is this percent of via hole
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void SetWidth(int aWidth)
Definition: class_track.h:113
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:113
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
void SetLayerPair(LAYER_ID aTopLayer, LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
void AppendCorner(wxPoint position, bool aAllowDuplication=false)
Function AppendCorner.
Definition: class_zone.h:546
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:204
std::vector< ZONE_CONTAINER * > ZONES
non-owning container
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:191
PTREE::const_iterator CITER
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:650
Eagle via.
Class NETINFO_ITEM handles the data for a net.
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:110
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:450
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:559
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
Eagle wire.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< TRACK > m_Track
Definition: class_board.h:244
Eagle polygon, without vertices which are parsed as needed.
void pop()
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:649
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:207
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:210
double rlMinViaOuter
minimum copper annulus on via
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
Use thermal relief for pads.
Definition: zones.h:58
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:188
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
pads are covered by copper
Definition: zones.h:59
void Value(const char *aValue)
modify the last path node's value
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
MODULE * EAGLE_PLUGIN::makeModule ( CPTREE aPackage,
const std::string &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 2104 of file eagle_plugin.cpp.

References FROM_UTF8(), m_board, packageCircle(), packageHole(), packagePad(), packagePolygon(), packageRectangle(), packageSMD(), packageText(), and packageWire().

Referenced by loadLibrary().

2105 {
2106  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
2107 
2108  m->SetFPID( LIB_ID( aPkgName ) );
2109 
2110  opt_string description = aPackage.get_optional<string>( "description" );
2111  if( description )
2112  m->SetDescription( FROM_UTF8( description->c_str() ) );
2113 
2114  for( CITER it = aPackage.begin(); it != aPackage.end(); ++it )
2115  {
2116  CPTREE& t = it->second;
2117 
2118  if( it->first == "wire" )
2119  packageWire( m.get(), t );
2120 
2121  else if( it->first == "pad" )
2122  packagePad( m.get(), t );
2123 
2124  else if( it->first == "text" )
2125  packageText( m.get(), t );
2126 
2127  else if( it->first == "rectangle" )
2128  packageRectangle( m.get(), t );
2129 
2130  else if( it->first == "polygon" )
2131  packagePolygon( m.get(), t );
2132 
2133  else if( it->first == "circle" )
2134  packageCircle( m.get(), t );
2135 
2136  else if( it->first == "hole" )
2137  packageHole( m.get(), t );
2138 
2139  else if( it->first == "smd" )
2140  packageSMD( m.get(), t );
2141  }
2142 
2143  return m.release();
2144 }
void packageCircle(MODULE *aModule, CPTREE &aTree) const
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:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void packagePolygon(MODULE *aModule, CPTREE &aTree) const
void packageText(MODULE *aModule, CPTREE &aTree) const
const PTREE CPTREE
Definition: eagle_plugin.h:63
Class LIB_ID.
Definition: lib_id.h:56
void packagePad(MODULE *aModule, CPTREE &aTree) const
void packageRectangle(MODULE *aModule, CPTREE &aTree) const
void packageSMD(MODULE *aModule, CPTREE &aTree) const
void packageHole(MODULE *aModule, CPTREE &aTree) const
PTREE::const_iterator CITER
void packageWire(MODULE *aModule, CPTREE &aTree) const
void EAGLE_PLUGIN::orientModuleAndText ( MODULE m,
const EELEMENT e,
const EATTR nameAttr,
const EATTR valueAttr 
)
private

Definition at line 1975 of file eagle_plugin.cpp.

References MODULE::Flip(), MODULE::GetPosition(), orientModuleText(), MODULE::Reference(), EELEMENT::rot, MODULE::SetOrientation(), and MODULE::Value().

Referenced by loadElements().

1977 {
1978  if( e.rot )
1979  {
1980  if( e.rot->mirror )
1981  {
1982  double orientation = e.rot->degrees + 180.0;
1983  m->SetOrientation( orientation * 10 );
1984  m->Flip( m->GetPosition() );
1985  }
1986  else
1987  m->SetOrientation( e.rot->degrees * 10 );
1988  }
1989 
1990  orientModuleText( m, e, &m->Reference(), nameAttr );
1991  orientModuleText( m, e, &m->Value(), valueAttr );
1992 }
TEXTE_MODULE & Reference()
Definition: class_module.h:455
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
const wxPoint & GetPosition() const override
Definition: class_module.h:143
opt_erot rot
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
void SetOrientation(double newangle)
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
void EAGLE_PLUGIN::orientModuleText ( MODULE m,
const EELEMENT e,
TEXTE_MODULE txt,
const EATTR a 
)
private

Definition at line 1995 of file eagle_plugin.cpp.

References abs, ETEXT::BOTTOM_LEFT, FROM_UTF8(), MODULE::GetOrientation(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsMirrored(), kicad_fontz(), kicad_x(), kicad_y(), EATTR::ratio, EATTR::rot, EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetMirrored(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_TEXT::SetVertJustify(), sign(), EATTR::size, ETEXT::TOP_RIGHT, EATTR::value, EATTR::x, and EATTR::y.

Referenced by orientModuleAndText().

1997 {
1998  // Smashed part ?
1999  if( aAttr )
2000  { // Yes
2001  const EATTR& a = *aAttr;
2002 
2003  if( a.value )
2004  {
2005  txt->SetText( FROM_UTF8( a.value->c_str() ) );
2006  }
2007 
2008  if( a.x && a.y ) // boost::optional
2009  {
2010  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
2011  txt->SetTextPos( pos );
2012  }
2013 
2014  // Even though size and ratio are both optional, I am not seeing
2015  // a case where ratio is present but size is not.
2016  double ratio = 8;
2017  wxSize fontz = txt->GetTextSize();
2018 
2019  if( a.size )
2020  {
2021  fontz = kicad_fontz( *a.size );
2022  txt->SetTextSize( fontz );
2023 
2024  if( a.ratio )
2025  ratio = *a.ratio;
2026  }
2027 
2028  int lw = int( fontz.y * ratio / 100.0 );
2029  txt->SetThickness( lw );
2030 
2031  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2032 
2033  // The "rot" in a EATTR seems to be assumed to be zero if it is not
2034  // present, and this zero rotation becomes an override to the
2035  // package's text field. If they did not want zero, they specify
2036  // what they want explicitly.
2037  double degrees = a.rot ? a.rot->degrees : 0;
2038  double orient; // relative to parent
2039 
2040  int sign = 1;
2041  bool spin = false;
2042 
2043  if( a.rot )
2044  {
2045  spin = a.rot->spin;
2046  sign = a.rot->mirror ? -1 : 1;
2047  txt->SetMirrored( a.rot->mirror );
2048  }
2049 
2050  if( degrees == 90 || degrees == 0 || spin )
2051  {
2052  orient = degrees - m->GetOrientation() / 10;
2053  txt->SetTextAngle( sign * orient * 10 );
2054  }
2055  else if( degrees == 180 )
2056  {
2057  orient = 0 - m->GetOrientation() / 10;
2058  txt->SetTextAngle( sign * orient * 10 );
2059  align = ETEXT::TOP_RIGHT;
2060  }
2061  else if( degrees == 270 )
2062  {
2063  orient = 90 - m->GetOrientation() / 10;
2064  align = ETEXT::TOP_RIGHT;
2065  txt->SetTextAngle( sign * orient * 10 );
2066  }
2067  else
2068  {
2069  orient = 90 - degrees - m->GetOrientation() / 10;
2070  txt->SetTextAngle( sign * orient * 10 );
2071  }
2072 
2073  switch( align )
2074  {
2075  case ETEXT::TOP_RIGHT:
2078  break;
2079 
2080  case ETEXT::BOTTOM_LEFT:
2083  break;
2084 
2085  default:
2086  ;
2087  }
2088  }
2089  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
2090  {
2091  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
2092 
2093  // @todo there are a few more cases than these to contend with:
2094  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
2095  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
2096  {
2097  // ETEXT::TOP_RIGHT:
2100  }
2101  }
2102 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
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:53
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
opt_double size
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
#define abs(a)
Definition: auxiliary.h:84
opt_erot rot
double GetTextAngle() const
Definition: eda_text.h:164
int kicad_y(double y) const
Definition: eagle_plugin.h:156
double GetOrientation() const
Definition: class_module.h:147
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
opt_string value
int kicad_x(double x) const
Definition: eagle_plugin.h:157
opt_double x
Eagle "attribute" XML element, no foolin'.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
bool IsMirrored() const
Definition: eda_text.h:179
opt_double ratio
void SetTextAngle(double aAngle)
const wxSize & GetTextSize() const
Definition: eda_text.h:215
opt_double y
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
void EAGLE_PLUGIN::packageCircle ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2462 of file eagle_plugin.cpp.

References Cmts_User, MODULE::GraphicalItems(), kicad(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, DLIST< T >::PushBack(), ECIRCLE::radius, S_CIRCLE, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

Referenced by makeModule().

2463 {
2464  ECIRCLE e( aTree );
2465  LAYER_ID layer = kicad_layer( e.layer );
2466  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
2467 
2468  aModule->GraphicalItems().PushBack( gr );
2469 
2470  gr->SetWidth( kicad( e.width ) );
2471 
2472  switch( (int) layer )
2473  {
2474  case UNDEFINED_LAYER: layer = Cmts_User; break;
2475  /*
2476  case Eco1_User: layer = F_SilkS; break;
2477  case Eco2_User: layer = B_SilkS; break;
2478  */
2479  default:
2480  break;
2481  }
2482 
2483  gr->SetLayer( layer );
2484  gr->SetTimeStamp( timeStamp( aTree ) );
2485 
2486  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
2487  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
2488 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle circle.
int kicad_x(double x) const
Definition: eagle_plugin.h:157
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetStart0(const wxPoint &aPoint)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageHole ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2491 of file eagle_plugin.cpp.

References LSET::AllCuMask(), EHOLE::drill, MODULE::GetPosition(), kicad(), kicad_x(), kicad_y(), PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CIRCLE, MODULE::Pads(), DLIST< T >::PushBack(), D_PAD::SetAttribute(), D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), EHOLE::x, and EHOLE::y.

Referenced by makeModule().

2492 {
2493  EHOLE e( aTree );
2494 
2495  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
2496  D_PAD* pad = new D_PAD( aModule );
2497  aModule->Pads().PushBack( pad );
2498 
2499  pad->SetShape( PAD_SHAPE_CIRCLE );
2501 
2502  // Mechanical purpose only:
2503  // no offset, no net name, no pad name allowed
2504  // pad->SetOffset( wxPoint( 0, 0 ) );
2505  // pad->SetPadName( wxEmptyString );
2506 
2507  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2508 
2509  pad->SetPos0( padpos );
2510  pad->SetPosition( padpos + aModule->GetPosition() );
2511 
2512  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
2513 
2514  pad->SetDrillSize( sz );
2515  pad->SetSize( sz );
2516 
2517  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
2518 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
const wxPoint & GetPosition() const override
Definition: class_module.h:143
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
Eagle hole element.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packagePad ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2186 of file eagle_plugin.cpp.

References LSET::AllCuMask(), B_Mask, Clamp(), EPAD::diameter, EPAD::drill, F_Mask, FROM_UTF8(), D_PAD::GetDrillSize(), MODULE::GetOrientation(), MODULE::GetPosition(), D_PAD::GetShape(), D_PAD::GetSize(), kicad(), kicad_x(), kicad_y(), KiROUND(), EPAD::LONG, m_rules, EPAD::name, EPAD::OCTAGON, EPAD::OFFSET, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, MODULE::Pads(), ERULES::psElongationLong, DLIST< T >::PushBack(), ERULES::rlMaxPadTop, ERULES::rlMinPadTop, EPAD::rot, RotatePoint(), EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetPadName(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, EPAD::x, and EPAD::y.

Referenced by makeModule().

2187 {
2188  // this is thru hole technology here, no SMDs
2189  EPAD e( aTree );
2190 
2191  D_PAD* pad = new D_PAD( aModule );
2192  aModule->Pads().PushBack( pad );
2193 
2194  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2195 
2196  // pad's "Position" is not relative to the module's,
2197  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2198 
2199  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2200 
2201  pad->SetPos0( padpos );
2202 
2203  RotatePoint( &padpos, aModule->GetOrientation() );
2204 
2205  pad->SetPosition( padpos + aModule->GetPosition() );
2206 
2207  pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
2208 
2209  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
2210 
2211  if( e.shape )
2212  {
2213  switch( *e.shape )
2214  {
2215  case EPAD::ROUND:
2216  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2217  break;
2218 
2219  case EPAD::OCTAGON:
2220  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
2221  // pad->SetShape( PAD_OCTAGON );
2222  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2223  break;
2224 
2225  case EPAD::LONG:
2226  pad->SetShape( PAD_SHAPE_OVAL );
2227  break;
2228 
2229  case EPAD::SQUARE:
2230  pad->SetShape( PAD_SHAPE_RECT );
2231  break;
2232 
2233  case EPAD::OFFSET:
2234  ; // don't know what to do here.
2235  }
2236  }
2237  else
2238  {
2239  // if shape is not present, our default is circle and that matches their default "round"
2240  }
2241 
2242  if( e.diameter )
2243  {
2244  int diameter = kicad( *e.diameter );
2245  pad->SetSize( wxSize( diameter, diameter ) );
2246  }
2247  else
2248  {
2249  double drillz = pad->GetDrillSize().x;
2250  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
2251  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
2252  int diameter = KiROUND( drillz + 2 * annulus );
2253  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
2254  }
2255 
2256  if( pad->GetShape() == PAD_SHAPE_OVAL )
2257  {
2258  // The Eagle "long" pad is wider than it is tall,
2259  // m_elongation is percent elongation
2260  wxSize sz = pad->GetSize();
2261  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
2262  pad->SetSize( sz );
2263  }
2264 
2265  if( e.rot )
2266  {
2267  pad->SetOrientation( e.rot->degrees * 10 );
2268  }
2269 
2270  // @todo: handle stop and thermal
2271 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
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:53
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
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
const wxPoint & GetPosition() const override
Definition: class_module.h:143
double rlMaxPadTop
maximum copper annulus on through hole pads
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle thru hol pad.
double GetOrientation() const
Definition: class_module.h:147
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
const wxSize & GetSize() const
Definition: class_pad.h:182
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
int psElongationLong
percent over 100%.
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:404
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:306
double rvPadTop
top pad size as percent of drill size
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
double rlMinPadTop
minimum copper annulus on through hole pads
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2413 of file eagle_plugin.cpp.

References MODULE::GraphicalItems(), IsNonCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), EPOLYGON::layer, DLIST< T >::PushBack(), S_POLYGON, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), EVERTEX::x, and EVERTEX::y.

Referenced by makeModule().

2414 {
2415  EPOLYGON p( aTree );
2416  LAYER_ID layer = kicad_layer( p.layer );
2417 
2418  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2419  {
2420  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2421  aModule->GraphicalItems().PushBack( dwg );
2422 
2423  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
2424 
2425  /*
2426  switch( layer )
2427  {
2428  case Eco1_User: layer = F_SilkS; break;
2429  case Eco2_User: layer = B_SilkS; break;
2430 
2431  // all MODULE templates (created from eagle packages) are on front layer
2432  // until cloned.
2433  case Cmts_User: layer = F_SilkS; break;
2434  }
2435  */
2436 
2437  dwg->SetLayer( layer );
2438 
2439  dwg->SetTimeStamp( timeStamp( aTree ) );
2440 
2441  std::vector<wxPoint> pts;
2442  pts.reserve( aTree.size() );
2443 
2444  for( CITER vi = aTree.begin(); vi != aTree.end(); ++vi )
2445  {
2446  if( vi->first != "vertex" ) // skip <xmlattr> node
2447  continue;
2448 
2449  EVERTEX v( vi->second );
2450 
2451  pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2452  }
2453 
2454  dwg->SetPolyPoints( pts );
2455 
2456  dwg->SetStart0( *pts.begin() );
2457  dwg->SetEnd0( pts.back() );
2458  }
2459 }
void SetEnd0(const wxPoint &aPoint)
polygon (not yet used for tracks, but could be in microwave apps)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
PTREE::const_iterator CITER
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetStart0(const wxPoint &aPoint)
Eagle polygon, without vertices which are parsed as needed.
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2380 of file eagle_plugin.cpp.

References MODULE::GraphicalItems(), IsNonCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), ERECT::layer, DLIST< T >::PushBack(), S_POLYGON, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), ERECT::x1, ERECT::x2, ERECT::y1, and ERECT::y2.

Referenced by makeModule().

2381 {
2382  ERECT r( aTree );
2383  LAYER_ID layer = kicad_layer( r.layer );
2384 
2385  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2386  {
2387  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2388  aModule->GraphicalItems().PushBack( dwg );
2389 
2390  dwg->SetLayer( layer );
2391  dwg->SetWidth( 0 );
2392 
2393  dwg->SetTimeStamp( timeStamp( aTree ) );
2394 
2395  std::vector<wxPoint> pts;
2396 
2397  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
2398  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
2399 
2400  pts.push_back( start );
2401  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
2402  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
2403  pts.push_back( end );
2404 
2405  dwg->SetPolyPoints( pts );
2406 
2407  dwg->SetStart0( start );
2408  dwg->SetEnd0( end );
2409  }
2410 }
void SetEnd0(const wxPoint &aPoint)
polygon (not yet used for tracks, but could be in microwave apps)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
int kicad_x(double x) const
Definition: eagle_plugin.h:157
Eagle XML rectangle in binary.
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetStart0(const wxPoint &aPoint)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2521 of file eagle_plugin.cpp.

References B_Cu, B_Mask, B_Paste, ESMD::dx, ESMD::dy, F_Cu, F_Mask, F_Paste, FROM_UTF8(), MODULE::GetOrientation(), MODULE::GetPosition(), IsCopperLayer(), kicad(), kicad_layer(), kicad_x(), kicad_y(), ESMD::layer, ESMD::name, PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, MODULE::Pads(), DLIST< T >::PushBack(), ESMD::rot, RotatePoint(), ESMD::roundness, D_PAD::SetAttribute(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetPadName(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), ESMD::x, and ESMD::y.

Referenced by makeModule().

2522 {
2523  ESMD e( aTree );
2524  LAYER_ID layer = kicad_layer( e.layer );
2525 
2526  if( !IsCopperLayer( layer ) )
2527  {
2528  return;
2529  }
2530 
2531  D_PAD* pad = new D_PAD( aModule );
2532  aModule->Pads().PushBack( pad );
2533 
2534  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2535  pad->SetShape( PAD_SHAPE_RECT );
2536  pad->SetAttribute( PAD_ATTRIB_SMD );
2537 
2538  // pad's "Position" is not relative to the module's,
2539  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2540 
2541  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2542 
2543  pad->SetPos0( padpos );
2544 
2545  RotatePoint( &padpos, aModule->GetOrientation() );
2546 
2547  pad->SetPosition( padpos + aModule->GetPosition() );
2548 
2549  pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
2550 
2551  pad->SetLayer( layer );
2552 
2553  static const LSET front( 3, F_Cu, F_Paste, F_Mask );
2554  static const LSET back( 3, B_Cu, B_Paste, B_Mask );
2555 
2556  if( layer == F_Cu )
2557  pad->SetLayerSet( front );
2558  else if( layer == B_Cu )
2559  pad->SetLayerSet( back );
2560 
2561  // Optional according to DTD
2562  if( e.roundness ) // set set shape to PAD_SHAPE_RECT above, in case roundness is not present
2563  {
2564  if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
2565  {
2566  if( e.dy == e.dx )
2567  pad->SetShape( PAD_SHAPE_CIRCLE );
2568  else
2569  pad->SetShape( PAD_SHAPE_OVAL );
2570  }
2571  }
2572 
2573  if( e.rot )
2574  {
2575  pad->SetOrientation( e.rot->degrees * 10 );
2576  }
2577 
2578  // don't know what stop, thermals, and cream should look like now.
2579 }
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:53
const wxPoint & GetPosition() const override
Definition: class_module.h:143
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
Eagle SMD pad.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Class LSET is a set of LAYER_IDs.
double GetOrientation() const
Definition: class_module.h:147
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:404
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:306
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packageText ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2274 of file eagle_plugin.cpp.

References ETEXT::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Cmts_User, FROM_UTF8(), MODULE::GetPosition(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, MODULE::GraphicalItems(), kicad(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), ETEXT::layer, DLIST< T >::PushBack(), ETEXT::ratio, MODULE::Reference(), ETEXT::rot, EDA_TEXT::SetHorizJustify(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), TEXTE_MODULE::SetPos0(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), EDA_TEXT::SetVertJustify(), sign(), ETEXT::size, ETEXT::text, timeStamp(), ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, UNDEFINED_LAYER, MODULE::Value(), ETEXT::x, and ETEXT::y.

Referenced by makeModule().

2275 {
2276  ETEXT t( aTree );
2277  LAYER_ID layer = kicad_layer( t.layer );
2278 
2279  if( layer == UNDEFINED_LAYER )
2280  {
2281  layer = Cmts_User;
2282  }
2283 
2284  TEXTE_MODULE* txt;
2285 
2286  if( t.text == ">NAME" || t.text == ">name" )
2287  txt = &aModule->Reference();
2288  else if( t.text == ">VALUE" || t.text == ">value" )
2289  txt = &aModule->Value();
2290  else
2291  {
2292  // FIXME: graphical text items are rotated for some reason.
2293  txt = new TEXTE_MODULE( aModule );
2294  aModule->GraphicalItems().PushBack( txt );
2295  }
2296 
2297  txt->SetTimeStamp( timeStamp( aTree ) );
2298  txt->SetText( FROM_UTF8( t.text.c_str() ) );
2299 
2300  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
2301 
2302  txt->SetTextPos( pos );
2303  txt->SetPos0( pos - aModule->GetPosition() );
2304 
2305  txt->SetLayer( layer );
2306  txt->SetTextSize( kicad_fontz( t.size ) );
2307 
2308  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
2309 
2310  txt->SetThickness( kicad( t.size * ratio / 100 ) );
2311 
2312  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2313 
2314  // An eagle package is never rotated, the DTD does not allow it.
2315  // angle -= aModule->GetOrienation();
2316 
2317  if( t.rot )
2318  {
2319  int sign = t.rot->mirror ? -1 : 1;
2320  txt->SetMirrored( t.rot->mirror );
2321 
2322  double degrees = t.rot->degrees;
2323 
2324  if( degrees == 90 || t.rot->spin )
2325  txt->SetTextAngle( sign * degrees * 10 );
2326  else if( degrees == 180 )
2327  align = ETEXT::TOP_RIGHT;
2328  else if( degrees == 270 )
2329  {
2330  align = ETEXT::TOP_RIGHT;
2331  txt->SetTextAngle( sign * 90 * 10 );
2332  }
2333  }
2334 
2335  switch( align )
2336  {
2337  case ETEXT::CENTER:
2338  // this was the default in pcbtxt's constructor
2339  break;
2340 
2341  case ETEXT::CENTER_LEFT:
2343  break;
2344 
2345  case ETEXT::CENTER_RIGHT:
2347  break;
2348 
2349  case ETEXT::TOP_CENTER:
2351  break;
2352 
2353  case ETEXT::TOP_LEFT:
2356  break;
2357 
2358  case ETEXT::TOP_RIGHT:
2361  break;
2362 
2363  case ETEXT::BOTTOM_CENTER:
2365  break;
2366 
2367  case ETEXT::BOTTOM_LEFT:
2370  break;
2371 
2372  case ETEXT::BOTTOM_RIGHT:
2375  break;
2376  }
2377 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
TEXTE_MODULE & Reference()
Definition: class_module.h:455
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:53
const wxPoint & GetPosition() const override
Definition: class_module.h:143
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
Eagle text element.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetPos0(const wxPoint &aPos)
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetTextAngle(double aAngle)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packageWire ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2147 of file eagle_plugin.cpp.

References EWIRE::curve, MODULE::GraphicalItems(), IsNonCopperLayer(), kicad(), kicad_arc_center(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, DLIST< T >::PushBack(), S_ARC, S_SEGMENT, DRAWSEGMENT::SetAngle(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), DRAWSEGMENT::SetWidth(), EWIRE::width, EWIRE::x1, EWIRE::x2, EWIRE::y1, and EWIRE::y2.

Referenced by makeModule().

2148 {
2149  EWIRE w( aTree );
2150  LAYER_ID layer = kicad_layer( w.layer );
2151 
2152  if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
2153  {
2154  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
2155  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
2156  int width = kicad( w.width );
2157 
2158  // FIXME: the cap attribute is ignored because kicad can't create lines
2159  // with flat ends.
2160  EDGE_MODULE* dwg;
2161  if( !w.curve )
2162  {
2163  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
2164 
2165  dwg->SetStart0( start );
2166  dwg->SetEnd0( end );
2167  }
2168  else
2169  {
2170  dwg = new EDGE_MODULE( aModule, S_ARC );
2171  wxPoint center = kicad_arc_center( start, end, *w.curve);
2172 
2173  dwg->SetStart0( center );
2174  dwg->SetEnd0( start );
2175  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
2176  }
2177 
2178  dwg->SetLayer( layer );
2179  dwg->SetWidth( width );
2180 
2181  aModule->GraphicalItems().PushBack( dwg );
2182  }
2183 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
usual segment : line with rounded ends
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Arcs (with rounded ends)
int kicad_x(double x) const
Definition: eagle_plugin.h:157
wxPoint kicad_arc_center(wxPoint start, wxPoint end, double angle)
Convert an Eagle curve end to a KiCad center for S_ARC.
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void SetStart0(const wxPoint &aPoint)
Eagle wire.
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
void SetWidth(int aWidth)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 1157 of file eagle_plugin.cpp.

1158 {
1159  return wxT( "Eagle" );
1160 }
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 69 of file plugin.cpp.

Referenced by FP_LIB_TABLE::PrefetchLib().

70 {
71  (void) aLibraryPath;
72  (void) aProperties;
73 }
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.

Definition at line 54 of file plugin.cpp.

References not_implemented().

Referenced by IO_MGR::Save(), PCB_EDIT_FRAME::SavePcbCopy(), and PCB_EDIT_FRAME::SavePcbFile().

55 {
56  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
57  not_implemented( this, __FUNCTION__ );
58 }
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

Member Data Documentation

double EAGLE_PLUGIN::biu_per_mm
private

how many bius in a mm

Definition at line 144 of file eagle_plugin.h.

Referenced by init(), and kicad().

BOARD* EAGLE_PLUGIN::m_board
private

which BOARD is being worked on, no ownership here

Definition at line 137 of file eagle_plugin.h.

Referenced by centerBoard(), init(), Load(), loadElements(), loadLayerDefs(), loadPlain(), loadSignals(), and makeModule().

int EAGLE_PLUGIN::m_cu_map[17]
private

map eagle to kicad, cu layers only.

Definition at line 121 of file eagle_plugin.h.

Referenced by clear_cu_map(), kicad_layer(), and loadLayerDefs().

int EAGLE_PLUGIN::m_hole_count
private

generates unique module names from eagle "hole"s.

Definition at line 127 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 146 of file eagle_plugin.h.

Referenced by cacheLib(), and loadLibrary().

int EAGLE_PLUGIN::m_min_trace
private

smallest trace we find on Load(), in BIU.

Definition at line 139 of file eagle_plugin.h.

Referenced by init(), Load(), and loadSignals().

int EAGLE_PLUGIN::m_min_via
private

smallest via we find on Load(), in BIU.

Definition at line 140 of file eagle_plugin.h.

Referenced by init(), Load(), and loadSignals().

int EAGLE_PLUGIN::m_min_via_hole
private

smallest via diameter hole we find on Load(), in BIU.

Definition at line 141 of file eagle_plugin.h.

Referenced by init(), Load(), and loadSignals().

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 147 of file eagle_plugin.h.

Referenced by cacheLib().

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

Definition at line 129 of file eagle_plugin.h.

Referenced by init(), loadElements(), and loadSignals().

const PROPERTIES* EAGLE_PLUGIN::m_props
private

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

Definition at line 136 of file eagle_plugin.h.

Referenced by centerBoard(), and init().

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 123 of file eagle_plugin.h.

Referenced by init(), Load(), loadDesignRules(), loadSignals(), packagePad(), and ~EAGLE_PLUGIN().

MODULE_MAP EAGLE_PLUGIN::m_templates
private

is part of a MODULE factory that operates using copy construction.

lookup key is either libname.packagename or simply packagename if FootprintLoad() or FootprintEnumberate()

Definition at line 131 of file eagle_plugin.h.

Referenced by cacheLib(), FootprintEnumerate(), FootprintLoad(), loadElements(), and loadLibrary().

XPATH* EAGLE_PLUGIN::m_xpath
private

keeps track of what we are working on within XML document during a Load().

Definition at line 124 of file eagle_plugin.h.

Referenced by cacheLib(), init(), Load(), loadAllSections(), loadDesignRules(), loadElements(), loadLibraries(), loadLibrary(), loadPlain(), loadSignals(), and ~EAGLE_PLUGIN().

double EAGLE_PLUGIN::mm_per_biu
private

how many mm in each BIU

Definition at line 143 of file eagle_plugin.h.

Referenced by init().


The documentation for this class was generated from the following files: