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...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Return 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...
 
PCB_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 (wxXmlNode *aDocument)
 
void loadDesignRules (wxXmlNode *aDesignRules)
 
void loadLayerDefs (wxXmlNode *aLayers)
 
void loadPlain (wxXmlNode *aPlain)
 
void loadSignals (wxXmlNode *aSignals)
 
void loadLibrary (wxXmlNode *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 (wxXmlNode *aLibs)
 
void loadElements (wxXmlNode *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 (wxXmlNode *aPackage, const std::string &aPkgName) const
 Function makeModule creates a MODULE from an Eagle package. More...
 
void packageWire (MODULE *aModule, wxXmlNode *aTree) const
 
void packagePad (MODULE *aModule, wxXmlNode *aTree) const
 
void packageText (MODULE *aModule, wxXmlNode *aTree) const
 
void packageRectangle (MODULE *aModule, wxXmlNode *aTree) const
 
void packagePolygon (MODULE *aModule, wxXmlNode *aTree) const
 
void packageCircle (MODULE *aModule, wxXmlNode *aTree) const
 
void packageHole (MODULE *aModule, wxXmlNode *aTree) const
 
void packageSMD (MODULE *aModule, wxXmlNode *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 83 of file eagle_plugin.h.

Member Typedef Documentation

typedef int EAGLE_PLUGIN::BIU

Definition at line 122 of file eagle_plugin.h.

Constructor & Destructor Documentation

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 134 of file eagle_plugin.cpp.

References clear_cu_map(), and init().

134  :
135  m_rules( new ERULES() ),
136  m_xpath( new XPATH() ),
137  m_mod_time( wxDateTime::Now() )
138 {
139  init( NULL );
140 
141  clear_cu_map();
142 }
void clear_cu_map()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:99
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:132
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:42
wxDateTime m_mod_time
Definition: eagle_plugin.h:155
EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 145 of file eagle_plugin.cpp.

References m_rules, and m_xpath.

146 {
147  delete m_rules;
148  delete m_xpath;
149 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132

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 2003 of file eagle_plugin.cpp.

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

Referenced by FootprintEnumerate(), and FootprintLoad().

2004 {
2005  try
2006  {
2007  wxDateTime modtime = getModificationTime( aLibPath );
2008 
2009  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2010  // cache if either of the wxDateTime objects are invalid or the last file modification
2011  // time differs from the current file modification time.
2012  bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
2013  m_mod_time != modtime;
2014 
2015  if( aLibPath != m_lib_path || load )
2016  {
2017  wxXmlNode* doc;
2018  LOCALE_IO toggle; // toggles on, then off, the C locale.
2019 
2020  m_templates.clear();
2021 
2022  // Set this before completion of loading, since we rely on it for
2023  // text of an exception. Delay setting m_mod_time until after successful load
2024  // however.
2025  m_lib_path = aLibPath;
2026 
2027  // 8 bit "filename" should be encoded according to disk filename encoding,
2028  // (maybe this is current locale, maybe not, its a filesystem issue),
2029  // and is not necessarily utf8.
2030  string filename = (const char*) aLibPath.char_str( wxConvFile );
2031 
2032  // Load the document
2033  wxXmlDocument xmlDocument;
2034  wxFileName fn( filename );
2035 
2036  if( !xmlDocument.Load( fn.GetFullPath() ) )
2037  THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
2038  fn.GetFullPath() ) );
2039 
2040  doc = xmlDocument.GetRoot();
2041 
2042  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2043  NODE_MAP drawingChildren = MapChildren( drawing );
2044 
2045  // clear the cu map and then rebuild it.
2046  clear_cu_map();
2047 
2048  m_xpath->push( "eagle.drawing.layers" );
2049  wxXmlNode* layers = drawingChildren["layers"];
2050  loadLayerDefs( layers );
2051  m_xpath->pop();
2052 
2053  m_xpath->push( "eagle.drawing.library" );
2054  wxXmlNode* library = drawingChildren["library"];
2055  loadLibrary( library, NULL );
2056  m_xpath->pop();
2057 
2058  m_mod_time = modtime;
2059  }
2060  }
2061  catch(...){}
2062  // TODO: Handle exceptions
2063  // catch( file_parser_error fpe )
2064  // {
2065  // // for xml_parser_error, what() has the line number in it,
2066  // // but no byte offset. That should be an adequate error message.
2067  // THROW_IO_ERROR( fpe.what() );
2068  // }
2069  //
2070  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2071  // // so one catch should be OK for all errors.
2072  // catch( ptree_error pte )
2073  // {
2074  // string errmsg = pte.what();
2075  //
2076  // errmsg += " @\n";
2077  // errmsg += m_xpath->Contents();
2078  //
2079  // THROW_IO_ERROR( errmsg );
2080  // }
2081 }
std::unordered_map< string, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:46
void clear_cu_map()
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
NODE_MAP MapChildren(wxXmlNode *currentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
void loadLayerDefs(wxXmlNode *aLayers)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
wxString m_lib_path
Definition: eagle_plugin.h:154
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
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:139
wxDateTime m_mod_time
Definition: eagle_plugin.h:155
void pop()
Definition: eagle_parser.h:111
void loadLibrary(wxXmlNode *aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

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

1946 {
1947  if( m_props )
1948  {
1949  UTF8 page_width;
1950  UTF8 page_height;
1951 
1952  if( m_props->Value( "page_width", &page_width ) &&
1953  m_props->Value( "page_height", &page_height ) )
1954  {
1956 
1957  int w = atoi( page_width.c_str() );
1958  int h = atoi( page_height.c_str() );
1959 
1960  int desired_x = ( w - bbbox.GetWidth() ) / 2;
1961  int desired_y = ( h - bbbox.GetHeight() ) / 2;
1962 
1963  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
1964  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
1965 
1966  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
1967  }
1968  }
1969 }
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:145
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:837
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:144
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 288 of file eagle_plugin.cpp.

References DIM, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

289 {
290  // All cu layers are invalid until we see them in the <layers> section while
291  // loading either a board or library. See loadLayerDefs().
292  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
293  m_cu_map[i] = -1;
294 }
#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:129
double EAGLE_PLUGIN::eagle ( BIU  d) const
inlineprivate

Convert a KiCad distance to an Eagle distance.

Definition at line 174 of file eagle_plugin.h.

Referenced by eagle_x(), and eagle_y().

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

Definition at line 175 of file eagle_plugin.h.

References eagle().

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

Definition at line 176 of file eagle_plugin.h.

References eagle().

176 { return eagle( y ); }
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:174
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
void EAGLE_PLUGIN::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Return 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.
aFootprintNamesis 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 2084 of file eagle_plugin.cpp.

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

2086 {
2087  init( aProperties );
2088 
2089  cacheLib( aLibraryPath );
2090 
2091  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2092  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2093 }
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:139
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 2117 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

2118 {
2119  PLUGIN::FootprintLibOptions( aListToAppendTo );
2120 
2121  /*
2122  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2123  "Ignore duplicately named footprints within the same Eagle library. "
2124  "Only the first similarly named footprint will be loaded."
2125  ));
2126  */
2127 }
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 2096 of file eagle_plugin.cpp.

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

2098 {
2099  init( aProperties );
2100 
2101  cacheLib( aLibraryPath );
2102 
2103  string key = TO_UTF8( aFootprintName );
2104 
2105  MODULE_CITER mi = m_templates.find( key );
2106 
2107  if( mi == m_templates.end() )
2108  return NULL;
2109 
2110  // copy constructor to clone the template
2111  MODULE* ret = new MODULE( *mi->second );
2112 
2113  return ret;
2114 }
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:139
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 158 of file eagle_plugin.cpp.

159 {
160  return wxT( "brd" );
161 }
wxDateTime EAGLE_PLUGIN::getModificationTime ( const wxString &  aPath)
staticprivate

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

Definition at line 1972 of file eagle_plugin.cpp.

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

Referenced by cacheLib().

1973 {
1974  wxFileName fn( aPath );
1975 
1976  // Do not call wxFileName::GetModificationTime() on a non-existent file, because
1977  // if it fails, wx's implementation calls the crap wxLogSysError() which
1978  // eventually infects our UI with an unwanted popup window, so don't let it fail.
1979  if( !fn.IsFileReadable() )
1980  {
1981  wxString msg = wxString::Format(
1982  _( "File '%s' is not readable." ),
1983  GetChars( aPath ) );
1984 
1985  THROW_IO_ERROR( msg );
1986  }
1987 
1988  /*
1989  // update the writable flag while we have a wxFileName, in a network this
1990  // is possibly quite dynamic anyway.
1991  m_writable = fn.IsFileWritable();
1992  */
1993 
1994  wxDateTime modTime = fn.GetModificationTime();
1995 
1996  if( !modTime.IsValid() )
1997  modTime.Now();
1998 
1999  return modTime;
2000 }
#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 266 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().

267 {
268  m_hole_count = 0;
269  m_min_trace = 0;
270  m_min_via = 0;
271  m_min_via_hole = 0;
272  m_xpath->clear();
273  m_pads_to_nets.clear();
274 
275  // m_templates.clear(); this is the FOOTPRINT cache too
276 
277  m_board = NULL;
278  m_props = aProperties;
279 
280  mm_per_biu = 1/IU_PER_MM;
281  biu_per_mm = IU_PER_MM;
282 
283  delete m_rules;
284  m_rules = new ERULES();
285 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:145
void clear()
Definition: eagle_parser.h:109
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:148
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:149
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:144
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:42
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:147
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:151
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:135
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:137
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:152
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 101 of file eagle_plugin.h.

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

Convert an Eagle distance to a KiCad distance.

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

165 {
166  return KiROUND( biu_per_mm * d );
167 }
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:152
wxSize EAGLE_PLUGIN::kicad_fontz ( double  d) const
inlineprivate

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

Definition at line 170 of file eagle_plugin.cpp.

References kicad().

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

171 {
172  // texts seem to better match eagle when scaled down by 0.95
173  int kz = kicad( d ) * 95 / 100;
174  return wxSize( kz, kz );
175 }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer ( int  aLayer) const
private

Convert an Eagle layer to a KiCad layer.

Definition at line 1888 of file eagle_plugin.cpp.

References B_Adhes, B_Fab, B_Mask, B_Paste, B_SilkS, EAGLE_LAYER::BCREAM, EAGLE_LAYER::BDOCU, EAGLE_LAYER::BFINISH, EAGLE_LAYER::BGLUE, EAGLE_LAYER::BNAMES, EAGLE_LAYER::BPLACE, EAGLE_LAYER::BSTOP, EAGLE_LAYER::BVALUES, Cmts_User, DIM, EAGLE_LAYER::DIMENSION, EAGLE_LAYER::DOCUMENT, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Fab, F_Mask, F_Paste, F_SilkS, Format(), m_cu_map, EAGLE_LAYER::REFERENCELC, EAGLE_LAYER::REFERENCELS, EAGLE_LAYER::TCREAM, EAGLE_LAYER::TDOCU, EAGLE_LAYER::TFINISH, EAGLE_LAYER::TGLUE, EAGLE_LAYER::TNAMES, EAGLE_LAYER::TPLACE, EAGLE_LAYER::TSTOP, EAGLE_LAYER::TVALUES, UNDEFINED_LAYER, EAGLE_LAYER::USERLAYER1, and EAGLE_LAYER::USERLAYER2.

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

1889 {
1890  int kiLayer;
1891 
1892  // eagle copper layer:
1893  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
1894  {
1895  kiLayer = m_cu_map[aEagleLayer];
1896  }
1897 
1898  else
1899  {
1900  // translate non-copper eagle layer to pcbnew layer
1901  switch( aEagleLayer )
1902  {
1903  // Eagle says "Dimension" layer, but it's for board perimeter
1904  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
1905  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
1906  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
1907  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
1908  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
1909  case EAGLE_LAYER::TVALUES: kiLayer = F_SilkS; break;
1910  case EAGLE_LAYER::BVALUES: kiLayer = B_SilkS; break;
1911  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
1912  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
1913  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
1914  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
1915  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
1916  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
1917  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
1918  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
1919  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
1920  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
1921  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
1922 
1923  // Packages show the future chip pins on SMD parts using layer 51.
1924  // This is an area slightly smaller than the PAD/SMD copper area.
1925  // Carry those visual aids into the MODULE on the fabrication layer,
1926  // not silkscreen. This is perhaps not perfect, but there is not a lot
1927  // of other suitable paired layers
1928  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
1929  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
1930 
1931  // thes layers are defined as user layers. put them on ECO layers
1932  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
1933  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
1934  default:
1935  // some layers do not map to KiCad
1936  wxASSERT_MSG( false, wxString::Format( "Unsupported Eagle layer %d", aEagleLayer ) );
1937  kiLayer = UNDEFINED_LAYER; break;
1938  }
1939  }
1940 
1941  return PCB_LAYER_ID( kiLayer );
1942 }
#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:129
PCB_LAYER_ID
A quick note on layer IDs:
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
int EAGLE_PLUGIN::kicad_x ( double  x) const
inlineprivate

Definition at line 165 of file eagle_plugin.h.

References kicad().

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

165 { 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 164 of file eagle_plugin.h.

References kicad().

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

164 { 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 178 of file eagle_plugin.cpp.

References centerBoard(), XPATH::Contents(), Format(), 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.

179 {
180  LOCALE_IO toggle; // toggles on, then off, the C locale.
181  wxXmlNode* doc;
182 
183  init( aProperties );
184 
185  m_board = aAppendToMe ? aAppendToMe : new BOARD();
186 
187  // Give the filename to the board if it's new
188  if( !aAppendToMe )
189  m_board->SetFileName( aFileName );
190 
191  // delete on exception, if I own m_board, according to aAppendToMe
192  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
193 
194  try
195  {
196  // Load the document
197  wxXmlDocument xmlDocument;
198  wxFileName fn = aFileName;
199 
200  if( !xmlDocument.Load( fn.GetFullPath() ) )
201  THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
202  fn.GetFullPath() ) );
203 
204  doc = xmlDocument.GetRoot();
205 
206  m_min_trace = INT_MAX;
207  m_min_via = INT_MAX;
208  m_min_via_hole = INT_MAX;
209 
210  loadAllSections( doc );
211 
212  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
213 
214  if( m_min_trace < designSettings.m_TrackMinWidth )
215  designSettings.m_TrackMinWidth = m_min_trace;
216 
217  if( m_min_via < designSettings.m_ViasMinSize )
218  designSettings.m_ViasMinSize = m_min_via;
219 
220  if( m_min_via_hole < designSettings.m_ViasMinDrill )
221  designSettings.m_ViasMinDrill = m_min_via_hole;
222 
223  if( m_rules->mdWireWire )
224  {
225  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
226  int clearance = KiROUND( m_rules->mdWireWire );
227 
228  if( clearance < defaultNetclass->GetClearance() )
229  defaultNetclass->SetClearance( clearance );
230  }
231 
232  // should be empty, else missing m_xpath->pop()
233  wxASSERT( m_xpath->Contents().size() == 0 );
234  }
235  // Catch all exceptions thrown from the parser.
236  catch( const XML_PARSER_ERROR &exc )
237  {
238  string errmsg = exc.what();
239 
240  errmsg += "\n@ ";
241  errmsg += m_xpath->Contents();
242 
243  THROW_IO_ERROR( errmsg );
244  }
245 
246  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
247 
248  // Ensure the copper layers count is a multiple of 2
249  // Pcbnew does not like boards with odd layers count
250  // (these boards cannot exist. they actually have a even layers count)
251  int lyrcnt = m_board->GetCopperLayerCount();
252 
253  if( (lyrcnt % 2) != 0 )
254  {
255  lyrcnt++;
256  m_board->SetCopperLayerCount( lyrcnt );
257  }
258 
259  centerBoard();
260 
261  deleter.release();
262  return m_board;
263 }
void loadAllSections(wxXmlNode *aDocument)
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:145
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
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
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:148
Class XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown ...
Definition: eagle_parser.h:57
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:149
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:528
#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.
Definition: eagle_plugin.h:58
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:147
string Contents()
return the contents of the XPATH as a single string
Definition: eagle_parser.h:126
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
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 ( wxXmlNode *  aDocument)
private

Definition at line 297 of file eagle_plugin.cpp.

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

Referenced by Load().

298 {
299  wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
300  NODE_MAP drawingChildren = MapChildren( drawing );
301 
302  wxXmlNode* board = drawingChildren["board"];
303  NODE_MAP boardChildren = MapChildren( board );
304 
305  m_xpath->push( "eagle.drawing" );
306 
307  {
308  m_xpath->push( "board" );
309 
310  wxXmlNode* designrules = boardChildren["designrules"];
311  loadDesignRules( designrules );
312 
313  m_xpath->pop();
314  }
315 
316  {
317  m_xpath->push( "layers" );
318 
319  wxXmlNode* layers = drawingChildren["layers"];
320  loadLayerDefs( layers );
321 
322  m_xpath->pop();
323  }
324 
325  {
326  m_xpath->push( "board" );
327 
328  wxXmlNode* plain = boardChildren["plain"];
329  loadPlain( plain );
330 
331  wxXmlNode* signals = boardChildren["signals"];
332  loadSignals( signals );
333 
334  wxXmlNode* libs = boardChildren["libraries"];
335  loadLibraries( libs );
336 
337  wxXmlNode* elems = boardChildren["elements"];
338  loadElements( elems );
339 
340  m_xpath->pop(); // "board"
341  }
342 
343  m_xpath->pop(); // "eagle.drawing"
344 }
std::unordered_map< string, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:46
NODE_MAP MapChildren(wxXmlNode *currentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
void loadLayerDefs(wxXmlNode *aLayers)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void loadElements(wxXmlNode *aElements)
void pop()
Definition: eagle_parser.h:111
void loadDesignRules(wxXmlNode *aDesignRules)
void loadSignals(wxXmlNode *aSignals)
void EAGLE_PLUGIN::loadDesignRules ( wxXmlNode *  aDesignRules)
private

Definition at line 347 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

348 {
349  m_xpath->push( "designrules" );
350  m_rules->parse( aDesignRules );
351  m_xpath->pop(); // "designrules"
352 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
void parse(wxXmlNode *aRules)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
void pop()
Definition: eagle_parser.h:111
void EAGLE_PLUGIN::loadElements ( wxXmlNode *  aElements)
private

Definition at line 812 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(), name, 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().

813 {
814  m_xpath->push( "elements.element", "name" );
815 
816  EATTR name;
817  EATTR value;
818  bool refanceNamePresetInPackageLayout;
819  bool valueNamePresetInPackageLayout;
820 
821  // Get the first element and iterate
822  wxXmlNode* element = aElements->GetChildren();
823 
824  while( element )
825  {
826  if( element->GetName() != "element" )
827  continue;
828 
829  EELEMENT e( element );
830 
831  // use "NULL-ness" as an indication of presence of the attribute:
832  EATTR* nameAttr = 0;
833  EATTR* valueAttr = 0;
834 
835  m_xpath->Value( e.name.c_str() );
836 
837  string pkg_key = makeKey( e.library, e.package );
838 
839  MODULE_CITER mi = m_templates.find( pkg_key );
840 
841  if( mi == m_templates.end() )
842  {
843  wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
844  GetChars( FROM_UTF8( e.package.c_str() ) ),
845  GetChars( FROM_UTF8( e.library.c_str() ) ) );
846  THROW_IO_ERROR( emsg );
847  }
848 
849  // copy constructor to clone the template
850  MODULE* m = new MODULE( *mi->second );
851  m_board->Add( m, ADD_APPEND );
852 
853  // update the nets within the pads of the clone
854  for( D_PAD* pad = m->Pads(); pad; pad = pad->Next() )
855  {
856  string pn_key = makeKey( e.name, TO_UTF8( pad->GetPadName() ) );
857 
858  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
859  if( ni != m_pads_to_nets.end() )
860  {
861  const ENET* enet = &ni->second;
862  pad->SetNetCode( enet->netcode );
863  }
864  }
865 
866  refanceNamePresetInPackageLayout = true;
867  valueNamePresetInPackageLayout = true;
868  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
869  // Is >NAME field set in package layout ?
870  if( m->GetReference().size() == 0 )
871  {
872  m->Reference().SetVisible( false ); // No so no show
873  refanceNamePresetInPackageLayout = false;
874  }
875  // Is >VALUE field set in package layout
876  if( m->GetValue().size() == 0 )
877  {
878  m->Value().SetVisible( false ); // No so no show
879  valueNamePresetInPackageLayout = false;
880  }
881  m->SetReference( FROM_UTF8( e.name.c_str() ) );
882  m->SetValue( FROM_UTF8( e.value.c_str() ) );
883 
884  if( !e.smashed )
885  { // Not smashed so show NAME & VALUE
886  if( valueNamePresetInPackageLayout )
887  m->Value().SetVisible( true ); // Only if place holder in package layout
888  if( refanceNamePresetInPackageLayout )
889  m->Reference().SetVisible( true ); // Only if place holder in package layout
890  }
891  else if( *e.smashed == true )
892  { // Smasted so set default to no show for NAME and VALUE
893  m->Value().SetVisible( false );
894  m->Reference().SetVisible( false );
895 
896  // initalize these to default values incase the <attribute> elements are not present.
897  m_xpath->push( "attribute", "name" );
898 
899  // VALUE and NAME can have something like our text "effects" overrides
900  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
901  // There can be one for NAME and/or VALUE both. Features present in the
902  // EATTR override the ones established in the package only if they are
903  // present here (except for rot, which if not present means angle zero).
904  // So the logic is a bit different than in packageText() and in plain text.
905 
906  // Get the first attribute and iterate
907  wxXmlNode* attribute = element->GetChildren();
908 
909  while( attribute )
910  {
911  if( attribute->GetName() != "attribute" )
912  continue;
913 
914  EATTR a( attribute );
915 
916  if( a.name == "NAME" )
917  {
918  name = a;
919  nameAttr = &name;
920 
921  // do we have a display attribute ?
922  if( a.display )
923  {
924  // Yes!
925  switch( *a.display )
926  {
927  case EATTR::VALUE :
928  nameAttr->name = e.name;
929  m->SetReference( e.name );
930  if( refanceNamePresetInPackageLayout )
931  m->Reference().SetVisible( true );
932  break;
933 
934  case EATTR::NAME :
935  if( refanceNamePresetInPackageLayout )
936  {
937  m->SetReference( "NAME" );
938  m->Reference().SetVisible( true );
939  }
940  break;
941 
942  case EATTR::BOTH :
943  if( refanceNamePresetInPackageLayout )
944  m->Reference().SetVisible( true );
945  nameAttr->name = nameAttr->name + " = " + e.name;
946  m->SetReference( "NAME = " + e.name );
947  break;
948 
949  case EATTR::Off :
950  m->Reference().SetVisible( false );
951  break;
952 
953  default:
954  nameAttr->name = e.name;
955  if( refanceNamePresetInPackageLayout )
956  m->Reference().SetVisible( true );
957  }
958  }
959  else
960  // No display, so default is visable, and show value of NAME
961  m->Reference().SetVisible( true );
962  }
963  else if( a.name == "VALUE" )
964  {
965  value = a;
966  valueAttr = &value;
967 
968  if( a.display )
969  {
970  // Yes!
971  switch( *a.display )
972  {
973  case EATTR::VALUE :
974  valueAttr->value = e.value;
975  m->SetValue( e.value );
976  if( valueNamePresetInPackageLayout )
977  m->Value().SetVisible( true );
978  break;
979 
980  case EATTR::NAME :
981  if( valueNamePresetInPackageLayout )
982  m->Value().SetVisible( true );
983  m->SetValue( "VALUE" );
984  break;
985 
986  case EATTR::BOTH :
987  if( valueNamePresetInPackageLayout )
988  m->Value().SetVisible( true );
989  valueAttr->value = "VALUE = " + e.value;
990  m->SetValue( "VALUE = " + e.value );
991  break;
992 
993  case EATTR::Off :
994  m->Value().SetVisible( false );
995  break;
996 
997  default:
998  valueAttr->value = e.value;
999  if( valueNamePresetInPackageLayout )
1000  m->Value().SetVisible( true );
1001  }
1002  }
1003  else
1004  // No display, so default is visible, and show value of NAME
1005  m->Value().SetVisible( true );
1006 
1007  }
1008 
1009  attribute = attribute->GetNext();
1010  }
1011 
1012  m_xpath->pop(); // "attribute"
1013  }
1014 
1015  orientModuleAndText( m, e, nameAttr, valueAttr );
1016 
1017  // Get next element
1018  element = element->GetNext();
1019  }
1020 
1021  m_xpath->pop(); // "elements.element"
1022 }
TEXTE_MODULE & Reference()
Definition: class_module.h:452
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:145
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
Eagle element element.
Definition: eagle_parser.h:643
void SetVisible(bool aVisible)
Definition: eda_text.h:175
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:436
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:38
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
int kicad_y(double y) const
Definition: eagle_plugin.h:164
#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
string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:451
string name
Definition: eagle_parser.h:475
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
D_PAD * Next() const
Definition: class_pad.h:106
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:418
opt_string value
Definition: eagle_parser.h:476
int kicad_x(double x) const
Definition: eagle_plugin.h:165
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetPosition(const wxPoint &aPos) override
Eagle net.
Definition: eagle_parser.h:357
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:473
MODULE_MAP::const_iterator MODULE_CITER
int netcode
Definition: eagle_parser.h:359
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:408
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:139
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:445
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:137
const char * name
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
void pop()
Definition: eagle_parser.h:111
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:114
void EAGLE_PLUGIN::loadLayerDefs ( wxXmlNode *  aLayers)
private

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

356 {
357  typedef std::vector<ELAYER> ELAYERS;
358  typedef ELAYERS::const_iterator EITER;
359 
360  ELAYERS cu; // copper layers
361 
362  // Get the first layer and iterate
363  wxXmlNode* layerNode = aLayers->GetChildren();
364 
365  // find the subset of layers that are copper, and active
366  while( layerNode )
367  {
368  ELAYER elayer( layerNode );
369 
370  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
371  {
372  cu.push_back( elayer );
373  }
374 
375  layerNode = layerNode->GetNext();
376  }
377 
378  // establish cu layer map:
379  int ki_layer_count = 0;
380 
381  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
382  {
383  if( ki_layer_count == 0 )
384  m_cu_map[it->number] = F_Cu;
385  else if( ki_layer_count == int( cu.size()-1 ) )
386  m_cu_map[it->number] = B_Cu;
387  else
388  {
389  // some eagle boards do not have contiguous layer number sequences.
390 
391 #if 0 // pre PCB_LAYER_ID & LSET:
392  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
393 #else
394  m_cu_map[it->number] = ki_layer_count;
395 #endif
396  }
397  }
398 
399 #if 0 && defined(DEBUG)
400  printf( "m_cu_map:\n" );
401  for( unsigned i=0; i<DIM(m_cu_map); ++i )
402  {
403  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
404  }
405 #endif
406 
407  // Set the layer names and cu count iff we're loading a board.
408  if( m_board )
409  {
410  m_board->SetCopperLayerCount( cu.size() );
411 
412  for( EITER it = cu.begin(); it != cu.end(); ++it )
413  {
414  PCB_LAYER_ID layer = kicad_layer( it->number );
415 
416  // these function provide their own protection against UNDEFINED_LAYER:
417  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
418  m_board->SetLayerType( layer, LT_SIGNAL );
419 
420  // could map the colors here
421  }
422  }
423 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
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:145
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetCopperLayerCount(int aCount)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
#define cu(a)
Definition: auxiliary.h:88
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:129
PCB_LAYER_ID
A quick note on layer IDs:
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
void EAGLE_PLUGIN::loadLibraries ( wxXmlNode *  aLibs)
private

Definition at line 790 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

791 {
792  m_xpath->push( "libraries.library", "name" );
793 
794  // Get the first library and iterate
795  wxXmlNode* library = aLibs->GetChildren();
796 
797  while( library )
798  {
799  const string& lib_name = library->GetAttribute( "name" ).ToStdString();
800 
801  m_xpath->Value( lib_name.c_str() );
802 
803  loadLibrary( library, &lib_name );
804 
805  library = library->GetNext();
806  }
807 
808  m_xpath->pop();
809 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
void pop()
Definition: eagle_parser.h:111
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:114
void loadLibrary(wxXmlNode *aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void EAGLE_PLUGIN::loadLibrary ( wxXmlNode *  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 732 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadLibraries().

733 {
734  m_xpath->push( "packages" );
735 
736  // library will have <xmlattr> node, skip that and get the single packages node
737  wxXmlNode* packages = MapChildren( aLib )["packages"];
738 
739 
740  // Create a MODULE for all the eagle packages, for use later via a copy constructor
741  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
742  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
743 
744  // Get the first package and iterate
745  wxXmlNode* package = packages->GetChildren();
746 
747  while( package )
748  {
749  m_xpath->push( "package", "name" );
750 
751  const wxString& pack_ref = package->GetAttribute( "name" );
752 
753  string pack_name( pack_ref.ToStdString() );
754 
755  ReplaceIllegalFileNameChars( &pack_name );
756 
757  m_xpath->Value( pack_name.c_str() );
758 
759  string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name;
760 
761  MODULE* m = makeModule( package, pack_name );
762 
763  // add the templating MODULE to the MODULE template factory "m_templates"
764  std::pair<MODULE_ITER, bool> r = m_templates.insert( {key, m} );
765 
766  if( !r.second
767  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
768  )
769  {
770  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
771  wxString pkg = FROM_UTF8( pack_name.c_str() );
772 
773  wxString emsg = wxString::Format(
774  _( "<package> name: '%s' duplicated in eagle <library>: '%s'" ),
775  GetChars( pkg ),
776  GetChars( lib )
777  );
778  THROW_IO_ERROR( emsg );
779  }
780 
781  m_xpath->pop();
782 
783  package = package->GetNext();
784  }
785 
786  m_xpath->pop(); // "packages"
787 }
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
NODE_MAP MapChildren(wxXmlNode *currentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
MODULE * makeModule(wxXmlNode *aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
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:132
string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
wxString m_lib_path
Definition: eagle_plugin.h:154
#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
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:139
void pop()
Definition: eagle_parser.h:111
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:114
void EAGLE_PLUGIN::loadPlain ( wxXmlNode *  aPlain)
private

Definition at line 426 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, EROT::degrees, 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, EROT::mirror, 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, EROT::spin, 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().

427 {
428  m_xpath->push( "plain" );
429 
430  // Get the first graphic and iterate
431  wxXmlNode* gr = aGraphics->GetChildren();
432 
433  // (polygon | wire | text | circle | rectangle | frame | hole)*
434  while( gr )
435  {
436  wxString grName = gr->GetName();
437 
438  if( grName == "wire" )
439  {
440  m_xpath->push( "wire" );
441 
442  EWIRE w( gr );
443  PCB_LAYER_ID layer = kicad_layer( w.layer );
444 
445  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
446  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
447 
448  if( layer != UNDEFINED_LAYER )
449  {
450  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
451  m_board->Add( dseg, ADD_APPEND );
452 
453  if( !w.curve )
454  {
455  dseg->SetStart( start );
456  dseg->SetEnd( end );
457  }
458  else
459  {
460  wxPoint center = kicad_arc_center( start, end, *w.curve);
461 
462  dseg->SetShape( S_ARC );
463  dseg->SetStart( center );
464  dseg->SetEnd( start );
465  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
466  }
467 
468  dseg->SetTimeStamp( timeStamp( gr ) );
469  dseg->SetLayer( layer );
470  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
471  }
472  m_xpath->pop();
473  }
474  else if( grName == "text" )
475  {
476  m_xpath->push( "text" );
477 
478  ETEXT t( gr );
479  PCB_LAYER_ID layer = kicad_layer( t.layer );
480 
481  if( layer != UNDEFINED_LAYER )
482  {
483  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
484  m_board->Add( pcbtxt, ADD_APPEND );
485 
486  pcbtxt->SetLayer( layer );
487  pcbtxt->SetTimeStamp( timeStamp( gr ) );
488  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
489  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
490 
491  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
492 
493  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
494 
495  pcbtxt->SetThickness( kicad( t.size * ratio / 100 ) );
496 
497  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
498 
499  if( t.rot )
500  {
501  int sign = t.rot->mirror ? -1 : 1;
502  pcbtxt->SetMirrored( t.rot->mirror );
503 
504  double degrees = t.rot->degrees;
505 
506  if( degrees == 90 || t.rot->spin )
507  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
508  else if( degrees == 180 )
509  align = ETEXT::TOP_RIGHT;
510  else if( degrees == 270 )
511  {
512  pcbtxt->SetTextAngle( sign * 90 * 10 );
513  align = ETEXT::TOP_RIGHT;
514  }
515  else // Ok so text is not at 90,180 or 270 so do some funny stuf to get placement right
516  {
517  if( ( degrees > 0 ) && ( degrees < 90 ) )
518  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
519  else if( ( degrees > 90 ) && ( degrees < 180 ) )
520  {
521  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
522  align = ETEXT::TOP_RIGHT;
523  }
524  else if( ( degrees > 180 ) && ( degrees < 270 ) )
525  {
526  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
527  align = ETEXT::TOP_RIGHT;
528  }
529  else if( ( degrees > 270 ) && ( degrees < 360 ) )
530  {
531  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
532  align = ETEXT::BOTTOM_LEFT;
533  }
534  }
535  }
536 
537  switch( align )
538  {
539  case ETEXT::CENTER:
540  // this was the default in pcbtxt's constructor
541  break;
542 
543  case ETEXT::CENTER_LEFT:
545  break;
546 
547  case ETEXT::CENTER_RIGHT:
549  break;
550 
551  case ETEXT::TOP_CENTER:
553  break;
554 
555  case ETEXT::TOP_LEFT:
558  break;
559 
560  case ETEXT::TOP_RIGHT:
563  break;
564 
567  break;
568 
569  case ETEXT::BOTTOM_LEFT:
572  break;
573 
574  case ETEXT::BOTTOM_RIGHT:
577  break;
578  }
579  }
580  m_xpath->pop();
581  }
582  else if( grName == "circle" )
583  {
584  m_xpath->push( "circle" );
585 
586  ECIRCLE c( gr );
587  PCB_LAYER_ID layer = kicad_layer( c.layer );
588 
589  if( layer != UNDEFINED_LAYER ) // unsupported layer
590  {
591  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
592  m_board->Add( dseg, ADD_APPEND );
593 
594  dseg->SetShape( S_CIRCLE );
595  dseg->SetTimeStamp( timeStamp( gr ) );
596  dseg->SetLayer( layer );
597  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
598  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
599  dseg->SetWidth( kicad( c.width ) );
600  }
601  m_xpath->pop();
602  }
603  else if( grName == "rectangle" )
604  {
605  // This seems to be a simplified rectangular [copper] zone, cannot find any
606  // net related info on it from the DTD.
607  m_xpath->push( "rectangle" );
608 
609  ERECT r( gr );
610  PCB_LAYER_ID layer = kicad_layer( r.layer );
611 
612  if( IsCopperLayer( layer ) )
613  {
614  // use a "netcode = 0" type ZONE:
615  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
616  m_board->Add( zone, ADD_APPEND );
617 
618  zone->SetTimeStamp( timeStamp( gr ) );
619  zone->SetLayer( layer );
621 
623 
624  const int outlineIdx = -1; // this is the id of the copper zone main outline
625  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
626  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
627  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
628  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
629 
630  // this is not my fault:
631  zone->SetHatch( outline_hatch, Mils2iu( zone->GetDefaultHatchPitchMils() ), true );
632  }
633 
634  m_xpath->pop();
635  }
636  else if( grName == "hole" )
637  {
638  m_xpath->push( "hole" );
639  EHOLE e( gr );
640 
641  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
642  // Use m_hole_count to gen up a unique name.
643 
644  MODULE* module = new MODULE( m_board );
645  m_board->Add( module, ADD_APPEND );
646 
647  char temp[40];
648  sprintf( temp, "@HOLE%d", m_hole_count++ );
649  module->SetReference( FROM_UTF8( temp ) );
650  module->Reference().SetVisible( false );
651 
652  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
653 
654  module->SetPosition( pos );
655 
656  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
657  D_PAD* pad = new D_PAD( module );
658  module->Pads().PushBack( pad );
659 
660  pad->SetShape( PAD_SHAPE_CIRCLE );
662 
663  /* pad's position is already centered on module at relative (0, 0)
664  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
665 
666  pad->SetPos0( padpos );
667  pad->SetPosition( padpos + module->GetPosition() );
668  */
669 
670  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
671 
672  pad->SetDrillSize( sz );
673  pad->SetSize( sz );
674 
675  pad->SetLayerSet( LSET::AllCuMask() );
676  m_xpath->pop();
677  }
678  else if( grName == "frame" )
679  {
680  // picture this
681  }
682  else if( grName == "polygon" )
683  {
684  // could be on a copper layer, could be on another layer.
685  // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
686  }
687  else if( grName == "dimension" )
688  {
689  EDIMENSION d( gr );
690  PCB_LAYER_ID layer = kicad_layer( d.layer );
691 
692  if( layer != UNDEFINED_LAYER )
693  {
694  DIMENSION* dimension = new DIMENSION( m_board );
695  m_board->Add( dimension, ADD_APPEND );
696 
697  dimension->SetLayer( layer );
698  // The origin and end are assumed to always be in this order from eagle
699  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
700  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
702 
704  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
705 
706  if( width > maxThickness )
707  width = maxThickness;
708 
709  dimension->Text().SetThickness( width );
710  dimension->SetWidth( width );
711 
712  // check which axis the dimension runs in
713  // because the "height" of the dimension is perpendicular to that axis
714  // Note the check is just if two axes are close enough to each other
715  // Eagle appears to have some rounding errors
716  if( fabs( d.x1 - d.x2 ) < 0.05 )
717  dimension->SetHeight( kicad_x( d.x1 - d.x3 ) );
718  else
719  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
720 
721  dimension->AdjustDimensionDetails();
722  }
723  }
724 
725  // Get next graphic
726  gr = gr->GetNext();
727  }
728  m_xpath->pop();
729 }
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 PCB_LAYER_IDs.
Definition: lset.cpp:639
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:452
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:145
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
int m_PcbTextWidth
current Pcb (not module) Text width
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetVisible(bool aVisible)
Definition: eda_text.h:175
wxPoint kicad_arc_center(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC.
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:920
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.
Definition: eagle_parser.h:632
Eagle text element.
Definition: eagle_parser.h:515
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
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.
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.
Definition: eagle_parser.h:441
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:528
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:418
int kicad_x(double x) const
Definition: eagle_plugin.h:165
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:85
void SetPosition(const wxPoint &aPos) override
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:135
Eagle XML rectangle in binary.
Definition: eagle_parser.h:454
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:348
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
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.
Definition: eagle_parser.h:395
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.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition: class_zone.cpp:846
static int GetDefaultHatchPitchMils()
Function GetDefaultHatchPitchMils.
Definition: class_zone.h:675
Eagle dimension element.
Definition: eagle_parser.h:498
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void pop()
Definition: eagle_parser.h:111
void SetWidth(int aWidth)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
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 ( wxXmlNode *  aSignals)
private

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

1647 {
1648  ZONES zones; // per net
1649 
1650  m_xpath->push( "signals.signal", "name" );
1651 
1652  int netCode = 1;
1653 
1654  // Get the first signal and iterate
1655  wxXmlNode* net = aSignals->GetChildren();
1656 
1657  while( net )
1658  {
1659  bool sawPad = false;
1660 
1661  zones.clear();
1662 
1663  const string& nname = net->GetAttribute( "name" ).ToStdString();
1664  wxString netName = FROM_UTF8( nname.c_str() );
1665  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
1666 
1667  m_xpath->Value( nname.c_str() );
1668 
1669  // Get the first net item and iterate
1670  wxXmlNode* netItem = net->GetChildren();
1671 
1672  // (contactref | polygon | wire | via)*
1673  while( netItem )
1674  {
1675  const wxString& itemName = netItem->GetName();
1676  if( itemName == "wire" )
1677  {
1678  m_xpath->push( "wire" );
1679 
1680  EWIRE w( netItem );
1681  PCB_LAYER_ID layer = kicad_layer( w.layer );
1682 
1683  if( IsCopperLayer( layer ) )
1684  {
1685  TRACK* t = new TRACK( m_board );
1686 
1687  t->SetTimeStamp( timeStamp( netItem ) );
1688 
1689  t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
1690  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
1691 
1692  int width = kicad( w.width );
1693  if( width < m_min_trace )
1694  m_min_trace = width;
1695 
1696  t->SetWidth( width );
1697  t->SetLayer( layer );
1698  t->SetNetCode( netCode );
1699 
1700  m_board->m_Track.Insert( t, NULL );
1701  }
1702  else
1703  {
1704  // put non copper wires where the sun don't shine.
1705  }
1706 
1707  m_xpath->pop();
1708  }
1709 
1710  else if( itemName == "via" )
1711  {
1712  m_xpath->push( "via" );
1713  EVIA v( netItem );
1714 
1715  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
1716  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
1717 
1718  if( IsCopperLayer( layer_front_most ) &&
1719  IsCopperLayer( layer_back_most ) )
1720  {
1721  int kidiam;
1722  int drillz = kicad( v.drill );
1723  VIA* via = new VIA( m_board );
1724  m_board->m_Track.Insert( via, NULL );
1725 
1726  via->SetLayerPair( layer_front_most, layer_back_most );
1727 
1728  if( v.diam )
1729  {
1730  kidiam = kicad( *v.diam );
1731  via->SetWidth( kidiam );
1732  }
1733  else
1734  {
1735  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
1736  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
1737  kidiam = KiROUND( drillz + 2 * annulus );
1738  via->SetWidth( kidiam );
1739  }
1740 
1741  via->SetDrill( drillz );
1742 
1743  if( kidiam < m_min_via )
1744  m_min_via = kidiam;
1745 
1746  if( drillz < m_min_via_hole )
1747  m_min_via_hole = drillz;
1748 
1749  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
1750  via->SetViaType( VIA_THROUGH );
1751  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
1752  via->SetViaType( VIA_MICROVIA );
1753  else
1754  via->SetViaType( VIA_BLIND_BURIED );
1755 
1756  via->SetTimeStamp( timeStamp( netItem ) );
1757 
1758  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
1759 
1760  via->SetPosition( pos );
1761  via->SetEnd( pos );
1762 
1763  via->SetNetCode( netCode );
1764  }
1765  m_xpath->pop();
1766  }
1767 
1768  else if( itemName == "contactref" )
1769  {
1770  m_xpath->push( "contactref" );
1771  // <contactref element="RN1" pad="7"/>
1772 
1773  const string& reference = netItem->GetAttribute( "element" ).ToStdString();
1774  const string& pad = netItem->GetAttribute( "pad" ).ToStdString();
1775 
1776  string key = makeKey( reference, pad ) ;
1777 
1778  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
1779 
1780  m_pads_to_nets[ key ] = ENET( netCode, nname );
1781 
1782  m_xpath->pop();
1783 
1784  sawPad = true;
1785  }
1786 
1787  else if( itemName == "polygon" )
1788  {
1789  m_xpath->push( "polygon" );
1790 
1791  EPOLYGON p( netItem );
1792  PCB_LAYER_ID layer = kicad_layer( p.layer );
1793 
1794  if( IsCopperLayer( layer ) )
1795  {
1796  // use a "netcode = 0" type ZONE:
1797  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
1798  m_board->Add( zone, ADD_APPEND );
1799  zones.push_back( zone );
1800 
1801  zone->SetTimeStamp( timeStamp( netItem ) );
1802  zone->SetLayer( layer );
1803  zone->SetNetCode( netCode );
1804 
1805  // Get the first vertex and iterate
1806  wxXmlNode* vertex = netItem->GetChildren();
1807 
1808  while( vertex )
1809  {
1810  if( vertex->GetName() != "vertex" ) // skip <xmlattr> node
1811  continue;
1812 
1813  EVERTEX v( vertex );
1814 
1815  // Append the corner
1816  zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ), -1 );
1817 
1818  vertex = vertex->GetNext();
1819  }
1820 
1821  // If the pour is a cutout it needs to be set to a keepout
1822  if( p.pour == EPOLYGON::CUTOUT )
1823  {
1824  zone->SetIsKeepout( true );
1825  zone->SetDoNotAllowCopperPour( true );
1827  }
1828 
1829  // if spacing is set the zone should be hatched
1830  if( p.spacing )
1831  zone->SetHatch( ZONE_CONTAINER::DIAGONAL_EDGE, *p.spacing, true );
1832 
1833  // clearances, etc.
1834  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
1835  zone->SetMinThickness( kicad( p.width ) );
1836 
1837  // FIXME: KiCad zones have very rounded corners compared to eagle.
1838  // This means that isolation amounts that work well in eagle
1839  // tend to make copper intrude in soldermask free areas around pads.
1840  if( p.isolate )
1841  {
1842  zone->SetZoneClearance( kicad( *p.isolate ) );
1843  }
1844 
1845  // missing == yes per DTD.
1846  bool thermals = !p.thermals || *p.thermals;
1848  if( thermals )
1849  {
1850  // FIXME: eagle calculates dimensions for thermal spokes
1851  // based on what the zone is connecting to.
1852  // (i.e. width of spoke is half of the smaller side of an smd pad)
1853  // This is a basic workaround
1854  zone->SetThermalReliefGap( kicad( p.width + 0.05 ) );
1855  zone->SetThermalReliefCopperBridge( kicad( p.width + 0.05 ) );
1856  }
1857 
1858  int rank = p.rank ? *p.rank : p.max_priority;
1859  zone->SetPriority( rank );
1860  }
1861 
1862  m_xpath->pop(); // "polygon"
1863  }
1864 
1865  netItem = netItem->GetNext();
1866  }
1867 
1868  if( zones.size() && !sawPad )
1869  {
1870  // KiCad does not support an unconnected zone with its own non-zero netcode,
1871  // but only when assigned netcode = 0 w/o a name...
1872  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
1873  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
1874 
1875  // therefore omit this signal/net.
1876  }
1877  else
1878  netCode++;
1879 
1880  // Get next signal
1881  net = net->GetNext();
1882  }
1883 
1884  m_xpath->pop(); // "signals.signal"
1885 }
Eagle vertex.
Definition: eagle_parser.h:593
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:57
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:145
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:440
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:412
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:131
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:104
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:920
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:148
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:55
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:132
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:164
void SetWidth(int aWidth)
Definition: class_track.h:114
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:113
PCB_LAYER_ID
A quick note on layer IDs:
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:149
string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
int kicad_x(double x) const
Definition: eagle_plugin.h:165
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:147
Eagle net.
Definition: eagle_parser.h:357
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:191
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:655
Eagle via.
Definition: eagle_parser.h:426
Class NETINFO_ITEM handles the data for a net.
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:111
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:447
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:554
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:137
Eagle wire.
Definition: eagle_parser.h:395
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition: class_zone.cpp:846
DLIST< TRACK > m_Track
Definition: class_board.h:244
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:603
void pop()
Definition: eagle_parser.h:111
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:654
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
Definition: eagle_plugin.h:56
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
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
Definition: eagle_parser.h:114
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
MODULE * EAGLE_PLUGIN::makeModule ( wxXmlNode *  aPackage,
const std::string &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 1155 of file eagle_plugin.cpp.

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

Referenced by loadLibrary().

1156 {
1157  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1158 
1159  m->SetFPID( LIB_ID( aPkgName ) );
1160 
1161  // Get the first package item and iterate
1162  wxXmlNode* packageItem = aPackage->GetChildren();
1163 
1164  while( packageItem )
1165  {
1166  const wxString& itemName = packageItem->GetName();
1167 
1168  if( itemName == "description" )
1169  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1170 
1171  else if( itemName == "wire" )
1172  packageWire( m.get(), packageItem );
1173 
1174  else if( itemName == "pad" )
1175  packagePad( m.get(), packageItem );
1176 
1177  else if( itemName == "text" )
1178  packageText( m.get(), packageItem );
1179 
1180  else if( itemName == "rectangle" )
1181  packageRectangle( m.get(), packageItem );
1182 
1183  else if( itemName == "polygon" )
1184  packagePolygon( m.get(), packageItem );
1185 
1186  else if( itemName == "circle" )
1187  packageCircle( m.get(), packageItem );
1188 
1189  else if( itemName == "hole" )
1190  packageHole( m.get(), packageItem );
1191 
1192  else if( itemName == "smd" )
1193  packageSMD( m.get(), packageItem );
1194 
1195  packageItem = packageItem->GetNext();
1196  }
1197 
1198  return m.release();
1199 }
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:145
void packageHole(MODULE *aModule, wxXmlNode *aTree) const
void packageText(MODULE *aModule, wxXmlNode *aTree) const
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
Class LIB_ID.
Definition: lib_id.h:56
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
void EAGLE_PLUGIN::orientModuleAndText ( MODULE m,
const EELEMENT e,
const EATTR nameAttr,
const EATTR valueAttr 
)
private

Definition at line 1025 of file eagle_plugin.cpp.

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

Referenced by loadElements().

1027 {
1028  if( e.rot )
1029  {
1030  if( e.rot->mirror )
1031  {
1032  double orientation = e.rot->degrees + 180.0;
1033  m->SetOrientation( orientation * 10 );
1034  m->Flip( m->GetPosition() );
1035  }
1036  else
1037  m->SetOrientation( e.rot->degrees * 10 );
1038  }
1039 
1040  orientModuleText( m, e, &m->Reference(), nameAttr );
1041  orientModuleText( m, e, &m->Value(), valueAttr );
1042 }
bool mirror
Definition: eagle_parser.h:376
TEXTE_MODULE & Reference()
Definition: class_module.h:452
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
Definition: eagle_parser.h:653
double degrees
Definition: eagle_parser.h:378
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:451
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 1045 of file eagle_plugin.cpp.

References abs, ETEXT::BOTTOM_LEFT, EROT::degrees, 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(), EROT::mirror, 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, EROT::spin, ETEXT::TOP_RIGHT, EATTR::value, EATTR::x, and EATTR::y.

Referenced by orientModuleAndText().

1047 {
1048  // Smashed part ?
1049  if( aAttr )
1050  { // Yes
1051  const EATTR& a = *aAttr;
1052 
1053  if( a.value )
1054  {
1055  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1056  }
1057 
1058  if( a.x && a.y ) // boost::optional
1059  {
1060  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1061  txt->SetTextPos( pos );
1062  }
1063 
1064  // Even though size and ratio are both optional, I am not seeing
1065  // a case where ratio is present but size is not.
1066  double ratio = 8;
1067  wxSize fontz = txt->GetTextSize();
1068 
1069  if( a.size )
1070  {
1071  fontz = kicad_fontz( *a.size );
1072  txt->SetTextSize( fontz );
1073 
1074  if( a.ratio )
1075  ratio = *a.ratio;
1076  }
1077 
1078  int lw = int( fontz.y * ratio / 100.0 );
1079  txt->SetThickness( lw );
1080 
1081  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1082 
1083  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1084  // present, and this zero rotation becomes an override to the
1085  // package's text field. If they did not want zero, they specify
1086  // what they want explicitly.
1087  double degrees = a.rot ? a.rot->degrees : 0;
1088  double orient; // relative to parent
1089 
1090  int sign = 1;
1091  bool spin = false;
1092 
1093  if( a.rot )
1094  {
1095  spin = a.rot->spin;
1096  sign = a.rot->mirror ? -1 : 1;
1097  txt->SetMirrored( a.rot->mirror );
1098  }
1099 
1100  if( degrees == 90 || degrees == 0 || spin )
1101  {
1102  orient = degrees - m->GetOrientation() / 10;
1103  txt->SetTextAngle( sign * orient * 10 );
1104  }
1105  else if( degrees == 180 )
1106  {
1107  orient = 0 - m->GetOrientation() / 10;
1108  txt->SetTextAngle( sign * orient * 10 );
1109  align = ETEXT::TOP_RIGHT;
1110  }
1111  else if( degrees == 270 )
1112  {
1113  orient = 90 - m->GetOrientation() / 10;
1114  align = ETEXT::TOP_RIGHT;
1115  txt->SetTextAngle( sign * orient * 10 );
1116  }
1117  else
1118  {
1119  orient = 90 - degrees - m->GetOrientation() / 10;
1120  txt->SetTextAngle( sign * orient * 10 );
1121  }
1122 
1123  switch( align )
1124  {
1125  case ETEXT::TOP_RIGHT:
1128  break;
1129 
1130  case ETEXT::BOTTOM_LEFT:
1133  break;
1134 
1135  default:
1136  ;
1137  }
1138  }
1139  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1140  {
1141  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1142 
1143  // @todo there are a few more cases than these to contend with:
1144  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1145  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1146  {
1147  // ETEXT::TOP_RIGHT:
1150  }
1151  }
1152 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
bool mirror
Definition: eagle_parser.h:376
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
double degrees
Definition: eagle_parser.h:378
opt_double size
Definition: eagle_parser.h:479
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
Definition: eagle_parser.h:482
double GetTextAngle() const
Definition: eda_text.h:164
int kicad_y(double y) const
Definition: eagle_plugin.h:164
double GetOrientation() const
Definition: class_module.h:147
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
opt_string value
Definition: eagle_parser.h:476
int kicad_x(double x) const
Definition: eagle_plugin.h:165
opt_double x
Definition: eagle_parser.h:477
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:473
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
bool IsMirrored() const
Definition: eda_text.h:179
opt_double ratio
Definition: eagle_parser.h:481
void SetTextAngle(double aAngle)
bool spin
Definition: eagle_parser.h:377
const wxSize & GetTextSize() const
Definition: eda_text.h:215
opt_double y
Definition: eagle_parser.h:478
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,
wxXmlNode *  aTree 
) const
private

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

1524 {
1525  ECIRCLE e( aTree );
1526  PCB_LAYER_ID layer = kicad_layer( e.layer );
1527  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1528 
1529  aModule->GraphicalItems().PushBack( gr );
1530 
1531  gr->SetWidth( kicad( e.width ) );
1532 
1533  switch( (int) layer )
1534  {
1535  case UNDEFINED_LAYER: layer = Cmts_User; break;
1536  /*
1537  case Eco1_User: layer = F_SilkS; break;
1538  case Eco2_User: layer = B_SilkS; break;
1539  */
1540  default:
1541  break;
1542  }
1543 
1544  gr->SetLayer( layer );
1545  gr->SetTimeStamp( timeStamp( aTree ) );
1546 
1547  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1548  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
1549 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Eagle circle.
Definition: eagle_parser.h:441
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetStart0(const wxPoint &aPoint)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageHole ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

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

1553 {
1554  EHOLE e( aTree );
1555 
1556  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1557  D_PAD* pad = new D_PAD( aModule );
1558  aModule->Pads().PushBack( pad );
1559 
1560  pad->SetShape( PAD_SHAPE_CIRCLE );
1562 
1563  // Mechanical purpose only:
1564  // no offset, no net name, no pad name allowed
1565  // pad->SetOffset( wxPoint( 0, 0 ) );
1566  // pad->SetPadName( wxEmptyString );
1567 
1568  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1569 
1570  pad->SetPos0( padpos );
1571  pad->SetPosition( padpos + aModule->GetPosition() );
1572 
1573  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
1574 
1575  pad->SetDrillSize( sz );
1576  pad->SetSize( sz );
1577 
1578  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
1579 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
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.
Definition: eagle_parser.h:632
int kicad_y(double y) const
Definition: eagle_plugin.h:164
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:165
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:348
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,
wxXmlNode *  aTree 
) const
private

Definition at line 1241 of file eagle_plugin.cpp.

References LSET::AllCuMask(), B_Mask, Clamp(), EROT::degrees, 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().

1242 {
1243  // this is thru hole technology here, no SMDs
1244  EPAD e( aTree );
1245 
1246  D_PAD* pad = new D_PAD( aModule );
1247  aModule->Pads().PushBack( pad );
1248 
1249  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
1250 
1251  // pad's "Position" is not relative to the module's,
1252  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1253 
1254  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1255 
1256  pad->SetPos0( padpos );
1257 
1258  RotatePoint( &padpos, aModule->GetOrientation() );
1259 
1260  pad->SetPosition( padpos + aModule->GetPosition() );
1261 
1262  pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
1263 
1264  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1265 
1266  if( e.shape )
1267  {
1268  switch( *e.shape )
1269  {
1270  case EPAD::ROUND:
1271  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1272  break;
1273 
1274  case EPAD::OCTAGON:
1275  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1276  // pad->SetShape( PAD_OCTAGON );
1277  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1278  break;
1279 
1280  case EPAD::LONG:
1281  pad->SetShape( PAD_SHAPE_OVAL );
1282  break;
1283 
1284  case EPAD::SQUARE:
1285  pad->SetShape( PAD_SHAPE_RECT );
1286  break;
1287 
1288  case EPAD::OFFSET:
1289  ; // don't know what to do here.
1290  }
1291  }
1292  else
1293  {
1294  // if shape is not present, our default is circle and that matches their default "round"
1295  }
1296 
1297  if( e.diameter )
1298  {
1299  int diameter = kicad( *e.diameter );
1300  pad->SetSize( wxSize( diameter, diameter ) );
1301  }
1302  else
1303  {
1304  double drillz = pad->GetDrillSize().x;
1305  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1306  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1307  int diameter = KiROUND( drillz + 2 * annulus );
1308  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1309  }
1310 
1311  if( pad->GetShape() == PAD_SHAPE_OVAL )
1312  {
1313  // The Eagle "long" pad is wider than it is tall,
1314  // m_elongation is percent elongation
1315  wxSize sz = pad->GetSize();
1316  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1317  pad->SetSize( sz );
1318  }
1319 
1320  if( e.rot )
1321  {
1322  pad->SetOrientation( e.rot->degrees * 10 );
1323  }
1324 
1325  // @todo: handle stop and thermal
1326 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
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:131
const wxPoint & GetPosition() const override
Definition: class_module.h:143
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:53
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle thru hol pad.
Definition: eagle_parser.h:547
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:165
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:44
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:455
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:357
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:49
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:52
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

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

1469 {
1470  EPOLYGON p( aTree );
1471  PCB_LAYER_ID layer = kicad_layer( p.layer );
1472 
1473  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
1474  {
1475  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1476  aModule->GraphicalItems().PushBack( dwg );
1477 
1478  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1479 
1480  /*
1481  switch( layer )
1482  {
1483  case Eco1_User: layer = F_SilkS; break;
1484  case Eco2_User: layer = B_SilkS; break;
1485 
1486  // all MODULE templates (created from eagle packages) are on front layer
1487  // until cloned.
1488  case Cmts_User: layer = F_SilkS; break;
1489  }
1490  */
1491 
1492  dwg->SetLayer( layer );
1493 
1494  dwg->SetTimeStamp( timeStamp( aTree ) );
1495 
1496  std::vector<wxPoint> pts;
1497  // TODO: I think there's no way to know a priori the number of children in wxXmlNode :()
1498  // pts.reserve( aTree.size() );
1499 
1500  // Get the first vertex and iterate
1501  wxXmlNode* vertex = aTree->GetChildren();
1502 
1503  while( vertex )
1504  {
1505  if( vertex->GetName() != "vertex" ) // skip <xmlattr> node
1506  continue;
1507 
1508  EVERTEX v( vertex );
1509 
1510  pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
1511 
1512  vertex = vertex->GetNext();
1513  }
1514 
1515  dwg->SetPolyPoints( pts );
1516 
1517  dwg->SetStart0( *pts.begin() );
1518  dwg->SetEnd0( pts.back() );
1519  }
1520 }
Eagle vertex.
Definition: eagle_parser.h:593
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
polygon (not yet used for tracks, but could be in microwave apps)
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void SetStart0(const wxPoint &aPoint)
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:603
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

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

1436 {
1437  ERECT r( aTree );
1438  PCB_LAYER_ID layer = kicad_layer( r.layer );
1439 
1440  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
1441  {
1442  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1443  aModule->GraphicalItems().PushBack( dwg );
1444 
1445  dwg->SetLayer( layer );
1446  dwg->SetWidth( 0 );
1447 
1448  dwg->SetTimeStamp( timeStamp( aTree ) );
1449 
1450  std::vector<wxPoint> pts;
1451 
1452  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1453  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1454 
1455  pts.push_back( start );
1456  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1457  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1458  pts.push_back( end );
1459 
1460  dwg->SetPolyPoints( pts );
1461 
1462  dwg->SetStart0( start );
1463  dwg->SetEnd0( end );
1464  }
1465 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
polygon (not yet used for tracks, but could be in microwave apps)
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
int kicad_x(double x) const
Definition: eagle_plugin.h:165
Eagle XML rectangle in binary.
Definition: eagle_parser.h:454
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void SetStart0(const wxPoint &aPoint)
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1582 of file eagle_plugin.cpp.

References B_Cu, B_Mask, B_Paste, EROT::degrees, 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().

1583 {
1584  ESMD e( aTree );
1585  PCB_LAYER_ID layer = kicad_layer( e.layer );
1586 
1587  if( !IsCopperLayer( layer ) )
1588  {
1589  return;
1590  }
1591 
1592  D_PAD* pad = new D_PAD( aModule );
1593  aModule->Pads().PushBack( pad );
1594 
1595  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
1596  pad->SetShape( PAD_SHAPE_RECT );
1597  pad->SetAttribute( PAD_ATTRIB_SMD );
1598 
1599  // pad's "Position" is not relative to the module's,
1600  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1601 
1602  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1603 
1604  pad->SetPos0( padpos );
1605 
1606  RotatePoint( &padpos, aModule->GetOrientation() );
1607 
1608  pad->SetPosition( padpos + aModule->GetPosition() );
1609 
1610  pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
1611 
1612  pad->SetLayer( layer );
1613 
1614  static const LSET front( 3, F_Cu, F_Paste, F_Mask );
1615  static const LSET back( 3, B_Cu, B_Paste, B_Mask );
1616 
1617  if( layer == F_Cu )
1618  pad->SetLayerSet( front );
1619  else if( layer == B_Cu )
1620  pad->SetLayerSet( back );
1621 
1622  // Optional according to DTD
1623  if( e.roundness ) // set set shape to PAD_SHAPE_RECT above, in case roundness is not present
1624  {
1625  if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
1626  {
1627  if( e.dy == e.dx )
1628  pad->SetShape( PAD_SHAPE_CIRCLE );
1629  else
1630  pad->SetShape( PAD_SHAPE_OVAL );
1631  }
1632  }
1633 
1634  if( e.rot )
1635  {
1636  pad->SetOrientation( e.rot->degrees * 10 );
1637  }
1638 
1639  // don't know what stop, thermals, and cream should look like now.
1640 }
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
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
const wxPoint & GetPosition() const override
Definition: class_module.h:143
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.
Definition: eagle_parser.h:574
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
int kicad_y(double y) const
Definition: eagle_plugin.h:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_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:165
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:348
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:455
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:357
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,
wxXmlNode *  aTree 
) const
private

Definition at line 1329 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, EROT::degrees, 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, EROT::mirror, 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, EROT::spin, ETEXT::text, timeStamp(), ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, UNDEFINED_LAYER, MODULE::Value(), ETEXT::x, and ETEXT::y.

Referenced by makeModule().

1330 {
1331  ETEXT t( aTree );
1332  PCB_LAYER_ID layer = kicad_layer( t.layer );
1333 
1334  if( layer == UNDEFINED_LAYER )
1335  {
1336  layer = Cmts_User;
1337  }
1338 
1339  TEXTE_MODULE* txt;
1340 
1341  if( t.text == ">NAME" || t.text == ">name" )
1342  txt = &aModule->Reference();
1343  else if( t.text == ">VALUE" || t.text == ">value" )
1344  txt = &aModule->Value();
1345  else
1346  {
1347  // FIXME: graphical text items are rotated for some reason.
1348  txt = new TEXTE_MODULE( aModule );
1349  aModule->GraphicalItems().PushBack( txt );
1350  }
1351 
1352  txt->SetTimeStamp( timeStamp( aTree ) );
1353  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1354 
1355  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1356 
1357  txt->SetTextPos( pos );
1358  txt->SetPos0( pos - aModule->GetPosition() );
1359 
1360  txt->SetLayer( layer );
1361  txt->SetTextSize( kicad_fontz( t.size ) );
1362 
1363  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1364 
1365  txt->SetThickness( kicad( t.size * ratio / 100 ) );
1366 
1367  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1368 
1369  // An eagle package is never rotated, the DTD does not allow it.
1370  // angle -= aModule->GetOrienation();
1371 
1372  if( t.rot )
1373  {
1374  int sign = t.rot->mirror ? -1 : 1;
1375  txt->SetMirrored( t.rot->mirror );
1376 
1377  double degrees = t.rot->degrees;
1378 
1379  if( degrees == 90 || t.rot->spin )
1380  txt->SetTextAngle( sign * degrees * 10 );
1381  else if( degrees == 180 )
1382  align = ETEXT::TOP_RIGHT;
1383  else if( degrees == 270 )
1384  {
1385  align = ETEXT::TOP_RIGHT;
1386  txt->SetTextAngle( sign * 90 * 10 );
1387  }
1388  }
1389 
1390  switch( align )
1391  {
1392  case ETEXT::CENTER:
1393  // this was the default in pcbtxt's constructor
1394  break;
1395 
1396  case ETEXT::CENTER_LEFT:
1398  break;
1399 
1400  case ETEXT::CENTER_RIGHT:
1402  break;
1403 
1404  case ETEXT::TOP_CENTER:
1406  break;
1407 
1408  case ETEXT::TOP_LEFT:
1411  break;
1412 
1413  case ETEXT::TOP_RIGHT:
1416  break;
1417 
1418  case ETEXT::BOTTOM_CENTER:
1420  break;
1421 
1422  case ETEXT::BOTTOM_LEFT:
1425  break;
1426 
1427  case ETEXT::BOTTOM_RIGHT:
1430  break;
1431  }
1432 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
TEXTE_MODULE & Reference()
Definition: class_module.h:452
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
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
const wxPoint & GetPosition() const override
Definition: class_module.h:143
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.
Definition: eagle_parser.h:515
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:451
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetPos0(const wxPoint &aPos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetTextAngle(double aAngle)
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,
wxXmlNode *  aTree 
) const
private

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

1203 {
1204  EWIRE w( aTree );
1205  PCB_LAYER_ID layer = kicad_layer( w.layer );
1206 
1207  if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
1208  {
1209  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1210  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1211  int width = kicad( w.width );
1212 
1213  // FIXME: the cap attribute is ignored because kicad can't create lines
1214  // with flat ends.
1215  EDGE_MODULE* dwg;
1216  if( !w.curve )
1217  {
1218  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1219 
1220  dwg->SetStart0( start );
1221  dwg->SetEnd0( end );
1222  }
1223  else
1224  {
1225  dwg = new EDGE_MODULE( aModule, S_ARC );
1226  wxPoint center = kicad_arc_center( start, end, *w.curve);
1227 
1228  dwg->SetStart0( center );
1229  dwg->SetEnd0( start );
1230  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1231  }
1232 
1233  dwg->SetLayer( layer );
1234  dwg->SetWidth( width );
1235 
1236  aModule->GraphicalItems().PushBack( dwg );
1237  }
1238 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
usual segment : line with rounded ends
wxPoint kicad_arc_center(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC.
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:164
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Arcs (with rounded ends)
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetStart0(const wxPoint &aPoint)
Eagle wire.
Definition: eagle_parser.h:395
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 152 of file eagle_plugin.cpp.

153 {
154  return wxT( "Eagle" );
155 }
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 152 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 145 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 129 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 135 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 154 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 147 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 148 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 149 of file eagle_plugin.h.

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

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 155 of file eagle_plugin.h.

Referenced by cacheLib().

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

Definition at line 137 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 144 of file eagle_plugin.h.

Referenced by centerBoard(), and init().

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 131 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 139 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 132 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 151 of file eagle_plugin.h.

Referenced by init().


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