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
 
void deleteTemplates ()
 

Deletes the footprint templates list

More...
 

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 deleteTemplates(), m_rules, and m_xpath.

146 {
147  deleteTemplates();
148  delete m_rules;
149  delete m_xpath;
150 }
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
void deleteTemplates()
Deletes the footprint templates list

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

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

Referenced by FootprintEnumerate(), and FootprintLoad().

2047 {
2048  try
2049  {
2050  wxDateTime modtime = getModificationTime( aLibPath );
2051 
2052  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2053  // cache if either of the wxDateTime objects are invalid or the last file modification
2054  // time differs from the current file modification time.
2055  bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
2056  m_mod_time != modtime;
2057 
2058  if( aLibPath != m_lib_path || load )
2059  {
2060  wxXmlNode* doc;
2061  LOCALE_IO toggle; // toggles on, then off, the C locale.
2062 
2063  deleteTemplates();
2064 
2065  // Set this before completion of loading, since we rely on it for
2066  // text of an exception. Delay setting m_mod_time until after successful load
2067  // however.
2068  m_lib_path = aLibPath;
2069 
2070  // 8 bit "filename" should be encoded according to disk filename encoding,
2071  // (maybe this is current locale, maybe not, its a filesystem issue),
2072  // and is not necessarily utf8.
2073  string filename = (const char*) aLibPath.char_str( wxConvFile );
2074 
2075  // Load the document
2076  wxXmlDocument xmlDocument;
2077  wxFileName fn( filename );
2078 
2079  if( !xmlDocument.Load( fn.GetFullPath() ) )
2080  THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
2081  fn.GetFullPath() ) );
2082 
2083  doc = xmlDocument.GetRoot();
2084 
2085  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2086  NODE_MAP drawingChildren = MapChildren( drawing );
2087 
2088  // clear the cu map and then rebuild it.
2089  clear_cu_map();
2090 
2091  m_xpath->push( "eagle.drawing.layers" );
2092  wxXmlNode* layers = drawingChildren["layers"];
2093  loadLayerDefs( layers );
2094  m_xpath->pop();
2095 
2096  m_xpath->push( "eagle.drawing.library" );
2097  wxXmlNode* library = drawingChildren["library"];
2098  loadLibrary( library, NULL );
2099  m_xpath->pop();
2100 
2101  m_mod_time = modtime;
2102  }
2103  }
2104  catch(...){}
2105  // TODO: Handle exceptions
2106  // catch( file_parser_error fpe )
2107  // {
2108  // // for xml_parser_error, what() has the line number in it,
2109  // // but no byte offset. That should be an adequate error message.
2110  // THROW_IO_ERROR( fpe.what() );
2111  // }
2112  //
2113  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2114  // // so one catch should be OK for all errors.
2115  // catch( ptree_error pte )
2116  // {
2117  // string errmsg = pte.what();
2118  //
2119  // errmsg += " @\n";
2120  // errmsg += m_xpath->Contents();
2121  //
2122  // THROW_IO_ERROR( errmsg );
2123  // }
2124 }
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
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
wxDateTime m_mod_time
Definition: eagle_plugin.h:155
void deleteTemplates()
Deletes the footprint templates list
void pop()
Definition: eagle_parser.h:111
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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 1988 of file eagle_plugin.cpp.

References UTF8::c_str(), 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().

1989 {
1990  if( m_props )
1991  {
1992  UTF8 page_width;
1993  UTF8 page_height;
1994 
1995  if( m_props->Value( "page_width", &page_width ) &&
1996  m_props->Value( "page_height", &page_height ) )
1997  {
1999 
2000  int w = atoi( page_width.c_str() );
2001  int h = atoi( page_height.c_str() );
2002 
2003  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2004  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2005 
2006  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2007  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2008 
2009  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2010  }
2011  }
2012 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
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:797
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.
const char * c_str() const
Definition: utf8.h:107
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
void EAGLE_PLUGIN::deleteTemplates ( )
private

Deletes the footprint templates list

Definition at line 1652 of file eagle_plugin.cpp.

References m_templates.

Referenced by cacheLib(), and ~EAGLE_PLUGIN().

1653 {
1654  for( auto& t : m_templates )
1655  delete t.second;
1656 
1657  m_templates.clear();
1658 }
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:139
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 2127 of file eagle_plugin.cpp.

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

2129 {
2130  init( aProperties );
2131 
2132  cacheLib( aLibraryPath );
2133 
2134  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2135  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2136 }
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 2160 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

2161 {
2162  PLUGIN::FootprintLibOptions( aListToAppendTo );
2163 
2164  /*
2165  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2166  "Ignore duplicately named footprints within the same Eagle library. "
2167  "Only the first similarly named footprint will be loaded."
2168  ));
2169  */
2170 }
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 2139 of file eagle_plugin.cpp.

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

2141 {
2142  init( aProperties );
2143 
2144  cacheLib( aLibraryPath );
2145 
2146  string key = TO_UTF8( aFootprintName );
2147 
2148  MODULE_CITER mi = m_templates.find( key );
2149 
2150  if( mi == m_templates.end() )
2151  return NULL;
2152 
2153  // copy constructor to clone the template
2154  MODULE* ret = new MODULE( *mi->second );
2155 
2156  return ret;
2157 }
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 159 of file eagle_plugin.cpp.

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

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

Definition at line 2015 of file eagle_plugin.cpp.

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

Referenced by cacheLib().

2016 {
2017  wxFileName fn( aPath );
2018 
2019  // Do not call wxFileName::GetModificationTime() on a non-existent file, because
2020  // if it fails, wx's implementation calls the crap wxLogSysError() which
2021  // eventually infects our UI with an unwanted popup window, so don't let it fail.
2022  if( !fn.IsFileReadable() )
2023  {
2024  wxString msg = wxString::Format(
2025  _( "File '%s' is not readable." ),
2026  GetChars( aPath ) );
2027 
2028  THROW_IO_ERROR( msg );
2029  }
2030 
2031  /*
2032  // update the writable flag while we have a wxFileName, in a network this
2033  // is possibly quite dynamic anyway.
2034  m_writable = fn.IsFileWritable();
2035  */
2036 
2037  wxDateTime modTime = fn.GetModificationTime();
2038 
2039  if( !modTime.IsValid() )
2040  modTime.Now();
2041 
2042  return modTime;
2043 }
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 267 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_templates, m_xpath, and mm_per_biu.

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

268 {
269  m_hole_count = 0;
270  m_min_trace = 0;
271  m_min_via = 0;
272  m_min_via_hole = 0;
273  m_xpath->clear();
274  m_pads_to_nets.clear();
275  m_templates.clear();
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
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:139
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 165 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().

166 {
167  return KiROUND( biu_per_mm * d );
168 }
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 171 of file eagle_plugin.cpp.

References kicad().

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

172 {
173  // texts seem to better match eagle when scaled down by 0.95
174  int kz = kicad( d ) * 95 / 100;
175  return wxSize( kz, kz );
176 }
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 1922 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::BKEEPOUT, EAGLE_LAYER::BNAMES, EAGLE_LAYER::BPLACE, EAGLE_LAYER::BSTOP, EAGLE_LAYER::BTEST, EAGLE_LAYER::BVALUES, Cmts_User, DIM, EAGLE_LAYER::DIMENSION, EAGLE_LAYER::DOCUMENT, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Fab, F_Mask, F_Paste, F_SilkS, Format(), EAGLE_LAYER::HOLES, m_cu_map, EAGLE_LAYER::MILLING, EAGLE_LAYER::REFERENCELC, EAGLE_LAYER::REFERENCELS, EAGLE_LAYER::TCREAM, EAGLE_LAYER::TDOCU, EAGLE_LAYER::TFINISH, EAGLE_LAYER::TGLUE, EAGLE_LAYER::TKEEPOUT, EAGLE_LAYER::TNAMES, EAGLE_LAYER::TPLACE, EAGLE_LAYER::TSTOP, EAGLE_LAYER::TTEST, EAGLE_LAYER::TVALUES, EAGLE_LAYER::UNROUTED, EAGLE_LAYER::USERLAYER1, and EAGLE_LAYER::USERLAYER2.

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

1923 {
1924  int kiLayer;
1925 
1926  // eagle copper layer:
1927  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
1928  {
1929  kiLayer = m_cu_map[aEagleLayer];
1930  }
1931 
1932  else
1933  {
1934  // translate non-copper eagle layer to pcbnew layer
1935  switch( aEagleLayer )
1936  {
1937  // Eagle says "Dimension" layer, but it's for board perimeter
1938  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
1939  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
1940  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
1941  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
1942  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
1943  case EAGLE_LAYER::TVALUES: kiLayer = F_SilkS; break;
1944  case EAGLE_LAYER::BVALUES: kiLayer = B_SilkS; break;
1945  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
1946  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
1947  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
1948  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
1949  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
1950  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
1951  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
1952  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
1953  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
1954  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
1955  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
1956 
1957  // Packages show the future chip pins on SMD parts using layer 51.
1958  // This is an area slightly smaller than the PAD/SMD copper area.
1959  // Carry those visual aids into the MODULE on the fabrication layer,
1960  // not silkscreen. This is perhaps not perfect, but there is not a lot
1961  // of other suitable paired layers
1962  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
1963  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
1964 
1965  // thes layers are defined as user layers. put them on ECO layers
1966  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
1967  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
1968 
1969  case EAGLE_LAYER::UNROUTED:
1970  case EAGLE_LAYER::TKEEPOUT:
1971  case EAGLE_LAYER::BKEEPOUT:
1972  case EAGLE_LAYER::TTEST:
1973  case EAGLE_LAYER::BTEST:
1974  case EAGLE_LAYER::MILLING:
1975  case EAGLE_LAYER::HOLES:
1976  default:
1977  // some layers do not map to KiCad
1978  wxLogMessage( wxString::Format( "Unsupported Eagle layer %d. Use drawings layer",
1979  aEagleLayer ) );
1980  kiLayer = Dwgs_User; break;
1981  }
1982  }
1983 
1984  return PCB_LAYER_ID( kiLayer );
1985 }
#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 179 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.

180 {
181  LOCALE_IO toggle; // toggles on, then off, the C locale.
182  wxXmlNode* doc;
183 
184  init( aProperties );
185 
186  m_board = aAppendToMe ? aAppendToMe : new BOARD();
187 
188  // Give the filename to the board if it's new
189  if( !aAppendToMe )
190  m_board->SetFileName( aFileName );
191 
192  // delete on exception, if I own m_board, according to aAppendToMe
193  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
194 
195  try
196  {
197  // Load the document
198  wxXmlDocument xmlDocument;
199  wxFileName fn = aFileName;
200 
201  if( !xmlDocument.Load( fn.GetFullPath() ) )
202  THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
203  fn.GetFullPath() ) );
204 
205  doc = xmlDocument.GetRoot();
206 
207  m_min_trace = INT_MAX;
208  m_min_via = INT_MAX;
209  m_min_via_hole = INT_MAX;
210 
211  loadAllSections( doc );
212 
213  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
214 
215  if( m_min_trace < designSettings.m_TrackMinWidth )
216  designSettings.m_TrackMinWidth = m_min_trace;
217 
218  if( m_min_via < designSettings.m_ViasMinSize )
219  designSettings.m_ViasMinSize = m_min_via;
220 
221  if( m_min_via_hole < designSettings.m_ViasMinDrill )
222  designSettings.m_ViasMinDrill = m_min_via_hole;
223 
224  if( m_rules->mdWireWire )
225  {
226  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
227  int clearance = KiROUND( m_rules->mdWireWire );
228 
229  if( clearance < defaultNetclass->GetClearance() )
230  defaultNetclass->SetClearance( clearance );
231  }
232 
233  // should be empty, else missing m_xpath->pop()
234  wxASSERT( m_xpath->Contents().size() == 0 );
235  }
236  // Catch all exceptions thrown from the parser.
237  catch( const XML_PARSER_ERROR &exc )
238  {
239  string errmsg = exc.what();
240 
241  errmsg += "\n@ ";
242  errmsg += m_xpath->Contents();
243 
244  THROW_IO_ERROR( errmsg );
245  }
246 
247  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
248 
249  // Ensure the copper layers count is a multiple of 2
250  // Pcbnew does not like boards with odd layers count
251  // (these boards cannot exist. they actually have a even layers count)
252  int lyrcnt = m_board->GetCopperLayerCount();
253 
254  if( (lyrcnt % 2) != 0 )
255  {
256  lyrcnt++;
257  m_board->SetCopperLayerCount( lyrcnt );
258  }
259 
260  centerBoard();
261 
262  deleter.release();
263  return m_board;
264 }
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:532
void SetFileName(const wxString &aFileName)
Definition: class_board.h:232
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:169
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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::PadsList(), 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  {
828  wxLogMessage( "expected: <element> read <%s>. Skip it", element->GetName() );
829  // Get next item
830  element = element->GetNext();
831  continue;
832  }
833 
834  EELEMENT e( element );
835 
836  // use "NULL-ness" as an indication of presence of the attribute:
837  EATTR* nameAttr = 0;
838  EATTR* valueAttr = 0;
839 
840  m_xpath->Value( e.name.c_str() );
841 
842  string pkg_key = makeKey( e.library, e.package );
843 
844  MODULE_CITER mi = m_templates.find( pkg_key );
845 
846  if( mi == m_templates.end() )
847  {
848  wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
849  GetChars( FROM_UTF8( e.package.c_str() ) ),
850  GetChars( FROM_UTF8( e.library.c_str() ) ) );
851  THROW_IO_ERROR( emsg );
852  }
853 
854  // copy constructor to clone the template
855  MODULE* m = new MODULE( *mi->second );
856  m_board->Add( m, ADD_APPEND );
857 
858  // update the nets within the pads of the clone
859  for( D_PAD* pad = m->PadsList(); pad; pad = pad->Next() )
860  {
861  string pn_key = makeKey( e.name, TO_UTF8( pad->GetName() ) );
862 
863  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
864  if( ni != m_pads_to_nets.end() )
865  {
866  const ENET* enet = &ni->second;
867  pad->SetNetCode( enet->netcode );
868  }
869  }
870 
871  refanceNamePresetInPackageLayout = true;
872  valueNamePresetInPackageLayout = true;
873  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
874  // Is >NAME field set in package layout ?
875  if( m->GetReference().size() == 0 )
876  {
877  m->Reference().SetVisible( false ); // No so no show
878  refanceNamePresetInPackageLayout = false;
879  }
880  // Is >VALUE field set in package layout
881  if( m->GetValue().size() == 0 )
882  {
883  m->Value().SetVisible( false ); // No so no show
884  valueNamePresetInPackageLayout = false;
885  }
886  m->SetReference( FROM_UTF8( e.name.c_str() ) );
887  m->SetValue( FROM_UTF8( e.value.c_str() ) );
888 
889  if( !e.smashed )
890  { // Not smashed so show NAME & VALUE
891  if( valueNamePresetInPackageLayout )
892  m->Value().SetVisible( true ); // Only if place holder in package layout
893  if( refanceNamePresetInPackageLayout )
894  m->Reference().SetVisible( true ); // Only if place holder in package layout
895  }
896  else if( *e.smashed == true )
897  { // Smasted so set default to no show for NAME and VALUE
898  m->Value().SetVisible( false );
899  m->Reference().SetVisible( false );
900 
901  // initalize these to default values incase the <attribute> elements are not present.
902  m_xpath->push( "attribute", "name" );
903 
904  // VALUE and NAME can have something like our text "effects" overrides
905  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
906  // There can be one for NAME and/or VALUE both. Features present in the
907  // EATTR override the ones established in the package only if they are
908  // present here (except for rot, which if not present means angle zero).
909  // So the logic is a bit different than in packageText() and in plain text.
910 
911  // Get the first attribute and iterate
912  wxXmlNode* attribute = element->GetChildren();
913 
914  while( attribute )
915  {
916  if( attribute->GetName() != "attribute" )
917  {
918  wxLogMessage( "expected: <attribute> read <%s>. Skip it", attribute->GetName() );
919  attribute = attribute->GetNext();
920  continue;
921  }
922 
923  EATTR a( attribute );
924 
925  if( a.name == "NAME" )
926  {
927  name = a;
928  nameAttr = &name;
929 
930  // do we have a display attribute ?
931  if( a.display )
932  {
933  // Yes!
934  switch( *a.display )
935  {
936  case EATTR::VALUE :
937  nameAttr->name = e.name;
938  m->SetReference( e.name );
939  if( refanceNamePresetInPackageLayout )
940  m->Reference().SetVisible( true );
941  break;
942 
943  case EATTR::NAME :
944  if( refanceNamePresetInPackageLayout )
945  {
946  m->SetReference( "NAME" );
947  m->Reference().SetVisible( true );
948  }
949  break;
950 
951  case EATTR::BOTH :
952  if( refanceNamePresetInPackageLayout )
953  m->Reference().SetVisible( true );
954  nameAttr->name = nameAttr->name + " = " + e.name;
955  m->SetReference( "NAME = " + e.name );
956  break;
957 
958  case EATTR::Off :
959  m->Reference().SetVisible( false );
960  break;
961 
962  default:
963  nameAttr->name = e.name;
964  if( refanceNamePresetInPackageLayout )
965  m->Reference().SetVisible( true );
966  }
967  }
968  else
969  // No display, so default is visable, and show value of NAME
970  m->Reference().SetVisible( true );
971  }
972  else if( a.name == "VALUE" )
973  {
974  value = a;
975  valueAttr = &value;
976 
977  if( a.display )
978  {
979  // Yes!
980  switch( *a.display )
981  {
982  case EATTR::VALUE :
983  valueAttr->value = e.value;
984  m->SetValue( e.value );
985  if( valueNamePresetInPackageLayout )
986  m->Value().SetVisible( true );
987  break;
988 
989  case EATTR::NAME :
990  if( valueNamePresetInPackageLayout )
991  m->Value().SetVisible( true );
992  m->SetValue( "VALUE" );
993  break;
994 
995  case EATTR::BOTH :
996  if( valueNamePresetInPackageLayout )
997  m->Value().SetVisible( true );
998  valueAttr->value = "VALUE = " + e.value;
999  m->SetValue( "VALUE = " + e.value );
1000  break;
1001 
1002  case EATTR::Off :
1003  m->Value().SetVisible( false );
1004  break;
1005 
1006  default:
1007  valueAttr->value = e.value;
1008  if( valueNamePresetInPackageLayout )
1009  m->Value().SetVisible( true );
1010  }
1011  }
1012  else
1013  // No display, so default is visible, and show value of NAME
1014  m->Value().SetVisible( true );
1015 
1016  }
1017 
1018  attribute = attribute->GetNext();
1019  }
1020 
1021  m_xpath->pop(); // "attribute"
1022  }
1023 
1024  orientModuleAndText( m, e, nameAttr, valueAttr );
1025 
1026  // Get next element
1027  element = element->GetNext();
1028  }
1029 
1030  m_xpath->pop(); // "elements.element"
1031 }
TEXTE_MODULE & Reference()
Definition: class_module.h:463
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:447
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:462
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:145
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:429
opt_string value
Definition: eagle_parser.h:476
int kicad_x(double x) const
Definition: eagle_plugin.h:165
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:419
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:456
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:137
const char * name
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
void pop()
Definition: eagle_parser.h:111
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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::GetDefaultHatchPitch(), 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::PadsList(), 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, zone->GetDefaultHatchPitch(), 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->PadsList().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:463
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:65
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:926
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:259
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
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
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:217
#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:532
void SetSize(const wxSize &aSize)
Definition: class_pad.h:253
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:429
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:392
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:376
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:202
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:852
Eagle dimension element.
Definition: eagle_parser.h:498
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
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 1665 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(), ZONE_CONTAINER::GetDefaultHatchPitch(), VIA::GetDrill(), TRACK::GetWidth(), 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().

1666 {
1667  ZONES zones; // per net
1668 
1669  m_xpath->push( "signals.signal", "name" );
1670 
1671  int netCode = 1;
1672 
1673  // Get the first signal and iterate
1674  wxXmlNode* net = aSignals->GetChildren();
1675 
1676  while( net )
1677  {
1678  bool sawPad = false;
1679 
1680  zones.clear();
1681 
1682  const string& nname = net->GetAttribute( "name" ).ToStdString();
1683  wxString netName = FROM_UTF8( nname.c_str() );
1684  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
1685 
1686  m_xpath->Value( nname.c_str() );
1687 
1688  // Get the first net item and iterate
1689  wxXmlNode* netItem = net->GetChildren();
1690 
1691  // (contactref | polygon | wire | via)*
1692  while( netItem )
1693  {
1694  const wxString& itemName = netItem->GetName();
1695  if( itemName == "wire" )
1696  {
1697  m_xpath->push( "wire" );
1698 
1699  EWIRE w( netItem );
1700  PCB_LAYER_ID layer = kicad_layer( w.layer );
1701 
1702  if( IsCopperLayer( layer ) )
1703  {
1704  TRACK* t = new TRACK( m_board );
1705 
1706  t->SetTimeStamp( timeStamp( netItem ) );
1707 
1708  t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
1709  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
1710 
1711  int width = kicad( w.width );
1712  if( width < m_min_trace )
1713  m_min_trace = width;
1714 
1715  t->SetWidth( width );
1716  t->SetLayer( layer );
1717  t->SetNetCode( netCode );
1718 
1719  m_board->m_Track.Insert( t, NULL );
1720  }
1721  else
1722  {
1723  // put non copper wires where the sun don't shine.
1724  }
1725 
1726  m_xpath->pop();
1727  }
1728 
1729  else if( itemName == "via" )
1730  {
1731  m_xpath->push( "via" );
1732  EVIA v( netItem );
1733 
1734  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
1735  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
1736 
1737  if( IsCopperLayer( layer_front_most ) &&
1738  IsCopperLayer( layer_back_most ) )
1739  {
1740  int kidiam;
1741  int drillz = kicad( v.drill );
1742  VIA* via = new VIA( m_board );
1743  m_board->m_Track.Insert( via, NULL );
1744 
1745  via->SetLayerPair( layer_front_most, layer_back_most );
1746 
1747  if( v.diam )
1748  {
1749  kidiam = kicad( *v.diam );
1750  via->SetWidth( kidiam );
1751  }
1752  else
1753  {
1754  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
1755  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
1756  kidiam = KiROUND( drillz + 2 * annulus );
1757  via->SetWidth( kidiam );
1758  }
1759 
1760  via->SetDrill( drillz );
1761 
1762  // make sure the via diameter respects the restring rules
1763 
1764  if( !v.diam || via->GetWidth() <= via->GetDrill() )
1765  {
1766  double annulus = Clamp( m_rules->rlMinViaOuter,
1767  (double)( via->GetWidth() / 2 - via->GetDrill() ), m_rules->rlMaxViaOuter );
1768  via->SetWidth( drillz + 2 * annulus );
1769  }
1770 
1771  if( kidiam < m_min_via )
1772  m_min_via = kidiam;
1773 
1774  if( drillz < m_min_via_hole )
1775  m_min_via_hole = drillz;
1776 
1777  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
1778  via->SetViaType( VIA_THROUGH );
1779  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
1780  via->SetViaType( VIA_MICROVIA );
1781  else
1782  via->SetViaType( VIA_BLIND_BURIED );
1783 
1784  via->SetTimeStamp( timeStamp( netItem ) );
1785 
1786  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
1787 
1788  via->SetPosition( pos );
1789  via->SetEnd( pos );
1790 
1791  via->SetNetCode( netCode );
1792  }
1793 
1794  m_xpath->pop();
1795  }
1796 
1797  else if( itemName == "contactref" )
1798  {
1799  m_xpath->push( "contactref" );
1800  // <contactref element="RN1" pad="7"/>
1801 
1802  const string& reference = netItem->GetAttribute( "element" ).ToStdString();
1803  const string& pad = netItem->GetAttribute( "pad" ).ToStdString();
1804 
1805  string key = makeKey( reference, pad ) ;
1806 
1807  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
1808 
1809  m_pads_to_nets[ key ] = ENET( netCode, nname );
1810 
1811  m_xpath->pop();
1812 
1813  sawPad = true;
1814  }
1815 
1816  else if( itemName == "polygon" )
1817  {
1818  m_xpath->push( "polygon" );
1819 
1820  EPOLYGON p( netItem );
1821  PCB_LAYER_ID layer = kicad_layer( p.layer );
1822 
1823  if( IsCopperLayer( layer ) )
1824  {
1825  // use a "netcode = 0" type ZONE:
1826  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
1827  m_board->Add( zone, ADD_APPEND );
1828  zones.push_back( zone );
1829 
1830  zone->SetTimeStamp( timeStamp( netItem ) );
1831  zone->SetLayer( layer );
1832  zone->SetNetCode( netCode );
1833 
1834  // Get the first vertex and iterate
1835  wxXmlNode* vertex = netItem->GetChildren();
1836 
1837  while( vertex )
1838  {
1839  if( vertex->GetName() != "vertex" ) // skip <xmlattr> node
1840  continue;
1841 
1842  EVERTEX v( vertex );
1843 
1844  // Append the corner
1845  zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ), -1 );
1846 
1847  vertex = vertex->GetNext();
1848  }
1849 
1850  // If the pour is a cutout it needs to be set to a keepout
1851  if( p.pour == EPOLYGON::CUTOUT )
1852  {
1853  zone->SetIsKeepout( true );
1854  zone->SetDoNotAllowCopperPour( true );
1856  }
1857 
1858  // if spacing is set the zone should be hatched
1859  // However, use the default hatch step, p.spacing value has no meaning for Kicad
1860  // TODO: see if this parameter is related to a grid fill option.
1861  if( p.spacing )
1863 
1864  // clearances, etc.
1865  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
1866  zone->SetMinThickness( kicad( p.width ) );
1867 
1868  // FIXME: KiCad zones have very rounded corners compared to eagle.
1869  // This means that isolation amounts that work well in eagle
1870  // tend to make copper intrude in soldermask free areas around pads.
1871  if( p.isolate )
1872  {
1873  zone->SetZoneClearance( kicad( *p.isolate ) );
1874  } else
1875  {
1876  zone->SetZoneClearance( 0 );
1877  }
1878 
1879  // missing == yes per DTD.
1880  bool thermals = !p.thermals || *p.thermals;
1882  if( thermals )
1883  {
1884  // FIXME: eagle calculates dimensions for thermal spokes
1885  // based on what the zone is connecting to.
1886  // (i.e. width of spoke is half of the smaller side of an smd pad)
1887  // This is a basic workaround
1888  zone->SetThermalReliefGap( kicad( p.width + 0.05 ) );
1889  zone->SetThermalReliefCopperBridge( kicad( p.width + 0.05 ) );
1890  }
1891 
1892  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
1893  zone->SetPriority( rank );
1894  }
1895 
1896  m_xpath->pop(); // "polygon"
1897  }
1898 
1899  netItem = netItem->GetNext();
1900  }
1901 
1902  if( zones.size() && !sawPad )
1903  {
1904  // KiCad does not support an unconnected zone with its own non-zero netcode,
1905  // but only when assigned netcode = 0 w/o a name...
1906  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
1907  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
1908 
1909  // therefore omit this signal/net.
1910  }
1911  else
1912  netCode++;
1913 
1914  // Get next signal
1915  net = net->GetNext();
1916  }
1917 
1918  m_xpath->pop(); // "signals.signal"
1919 }
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:926
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
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:454
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
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:217
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:660
Eagle via.
Definition: eagle_parser.h:426
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
int GetWidth() const
Definition: class_track.h:115
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:852
DLIST< TRACK > m_Track
Definition: class_board.h:246
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:659
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 1164 of file eagle_plugin.cpp.

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

Referenced by loadLibrary().

1165 {
1166  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1167 
1168  m->SetFPID( LIB_ID( UTF8(aPkgName) ) );
1169 
1170  // Get the first package item and iterate
1171  wxXmlNode* packageItem = aPackage->GetChildren();
1172 
1173  while( packageItem )
1174  {
1175  const wxString& itemName = packageItem->GetName();
1176 
1177  if( itemName == "description" )
1178  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1179 
1180  else if( itemName == "wire" )
1181  packageWire( m.get(), packageItem );
1182 
1183  else if( itemName == "pad" )
1184  packagePad( m.get(), packageItem );
1185 
1186  else if( itemName == "text" )
1187  packageText( m.get(), packageItem );
1188 
1189  else if( itemName == "rectangle" )
1190  packageRectangle( m.get(), packageItem );
1191 
1192  else if( itemName == "polygon" )
1193  packagePolygon( m.get(), packageItem );
1194 
1195  else if( itemName == "circle" )
1196  packageCircle( m.get(), packageItem );
1197 
1198  else if( itemName == "hole" )
1199  packageHole( m.get(), packageItem );
1200 
1201  else if( itemName == "smd" )
1202  packageSMD( m.get(), packageItem );
1203 
1204  packageItem = packageItem->GetNext();
1205  }
1206 
1207  return m.release();
1208 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
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 1034 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().

1036 {
1037  if( e.rot )
1038  {
1039  if( e.rot->mirror )
1040  {
1041  double orientation = e.rot->degrees + 180.0;
1042  m->SetOrientation( orientation * 10 );
1043  m->Flip( m->GetPosition() );
1044  }
1045  else
1046  m->SetOrientation( e.rot->degrees * 10 );
1047  }
1048 
1049  orientModuleText( m, e, &m->Reference(), nameAttr );
1050  orientModuleText( m, e, &m->Value(), valueAttr );
1051 }
bool mirror
Definition: eagle_parser.h:376
TEXTE_MODULE & Reference()
Definition: class_module.h:463
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
const wxPoint & GetPosition() const override
Definition: class_module.h:155
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:462
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 1054 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().

1056 {
1057  // Smashed part ?
1058  if( aAttr )
1059  { // Yes
1060  const EATTR& a = *aAttr;
1061 
1062  if( a.value )
1063  {
1064  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1065  }
1066 
1067  if( a.x && a.y ) // boost::optional
1068  {
1069  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1070  txt->SetTextPos( pos );
1071  }
1072 
1073  // Even though size and ratio are both optional, I am not seeing
1074  // a case where ratio is present but size is not.
1075  double ratio = 8;
1076  wxSize fontz = txt->GetTextSize();
1077 
1078  if( a.size )
1079  {
1080  fontz = kicad_fontz( *a.size );
1081  txt->SetTextSize( fontz );
1082 
1083  if( a.ratio )
1084  ratio = *a.ratio;
1085  }
1086 
1087  int lw = int( fontz.y * ratio / 100.0 );
1088  txt->SetThickness( lw );
1089 
1090  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1091 
1092  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1093  // present, and this zero rotation becomes an override to the
1094  // package's text field. If they did not want zero, they specify
1095  // what they want explicitly.
1096  double degrees = a.rot ? a.rot->degrees : 0;
1097  double orient; // relative to parent
1098 
1099  int sign = 1;
1100  bool spin = false;
1101 
1102  if( a.rot )
1103  {
1104  spin = a.rot->spin;
1105  sign = a.rot->mirror ? -1 : 1;
1106  txt->SetMirrored( a.rot->mirror );
1107  }
1108 
1109  if( degrees == 90 || degrees == 0 || spin )
1110  {
1111  orient = degrees - m->GetOrientation() / 10;
1112  txt->SetTextAngle( sign * orient * 10 );
1113  }
1114  else if( degrees == 180 )
1115  {
1116  orient = 0 - m->GetOrientation() / 10;
1117  txt->SetTextAngle( sign * orient * 10 );
1118  align = ETEXT::TOP_RIGHT;
1119  }
1120  else if( degrees == 270 )
1121  {
1122  orient = 90 - m->GetOrientation() / 10;
1123  align = ETEXT::TOP_RIGHT;
1124  txt->SetTextAngle( sign * orient * 10 );
1125  }
1126  else
1127  {
1128  orient = 90 - degrees - m->GetOrientation() / 10;
1129  txt->SetTextAngle( sign * orient * 10 );
1130  }
1131 
1132  switch( align )
1133  {
1134  case ETEXT::TOP_RIGHT:
1137  break;
1138 
1139  case ETEXT::BOTTOM_LEFT:
1142  break;
1143 
1144  default:
1145  ;
1146  }
1147  }
1148  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1149  {
1150  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1151 
1152  // @todo there are a few more cases than these to contend with:
1153  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1154  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1155  {
1156  // ETEXT::TOP_RIGHT:
1159  }
1160  }
1161 }
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:160
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 1532 of file eagle_plugin.cpp.

References Cmts_User, MODULE::GraphicalItemsList(), 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().

1533 {
1534  ECIRCLE e( aTree );
1535  PCB_LAYER_ID layer = kicad_layer( e.layer );
1536  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1537 
1538  aModule->GraphicalItemsList().PushBack( gr );
1539 
1540  gr->SetWidth( kicad( e.width ) );
1541 
1542  switch( (int) layer )
1543  {
1544  case UNDEFINED_LAYER: layer = Cmts_User; break;
1545  /*
1546  case Eco1_User: layer = F_SilkS; break;
1547  case Eco2_User: layer = B_SilkS; break;
1548  */
1549  default:
1550  break;
1551  }
1552 
1553  gr->SetLayer( layer );
1554  gr->SetTimeStamp( timeStamp( aTree ) );
1555 
1556  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1557  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
1558 }
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.
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
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)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
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 1561 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::PadsList(), 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().

1562 {
1563  EHOLE e( aTree );
1564 
1565  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1566  D_PAD* pad = new D_PAD( aModule );
1567  aModule->PadsList().PushBack( pad );
1568 
1569  pad->SetShape( PAD_SHAPE_CIRCLE );
1571 
1572  // Mechanical purpose only:
1573  // no offset, no net name, no pad name allowed
1574  // pad->SetOffset( wxPoint( 0, 0 ) );
1575  // pad->SetName( wxEmptyString );
1576 
1577  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1578 
1579  pad->SetPos0( padpos );
1580  pad->SetPosition( padpos + aModule->GetPosition() );
1581 
1582  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
1583 
1584  pad->SetDrillSize( sz );
1585  pad->SetSize( sz );
1586 
1587  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
1588 }
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:65
const wxPoint & GetPosition() const override
Definition: class_module.h:155
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:204
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:259
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:247
void SetSize(const wxSize &aSize)
Definition: class_pad.h:253
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:376
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:202
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
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 1250 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::PadsList(), ERULES::psElongationLong, DLIST< T >::PushBack(), ERULES::rlMaxPadTop, ERULES::rlMinPadTop, EPAD::rot, RotatePoint(), EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetName(), D_PAD::SetOrientation(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, EPAD::x, and EPAD::y.

Referenced by makeModule().

1251 {
1252  // this is thru hole technology here, no SMDs
1253  EPAD e( aTree );
1254 
1255  D_PAD* pad = new D_PAD( aModule );
1256  aModule->PadsList().PushBack( pad );
1257 
1258  pad->SetName( FROM_UTF8( e.name.c_str() ) );
1259 
1260  // pad's "Position" is not relative to the module's,
1261  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1262 
1263  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1264 
1265  pad->SetPos0( padpos );
1266 
1267  RotatePoint( &padpos, aModule->GetOrientation() );
1268 
1269  pad->SetPosition( padpos + aModule->GetPosition() );
1270 
1271  pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
1272 
1273  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1274 
1275  if( e.shape )
1276  {
1277  switch( *e.shape )
1278  {
1279  case EPAD::ROUND:
1280  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1281  break;
1282 
1283  case EPAD::OCTAGON:
1284  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1285  // pad->SetShape( PAD_OCTAGON );
1286  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1287  break;
1288 
1289  case EPAD::LONG:
1290  pad->SetShape( PAD_SHAPE_OVAL );
1291  break;
1292 
1293  case EPAD::SQUARE:
1294  pad->SetShape( PAD_SHAPE_RECT );
1295  break;
1296 
1297  case EPAD::OFFSET:
1298  ; // don't know what to do here.
1299  }
1300  }
1301  else
1302  {
1303  // if shape is not present, our default is circle and that matches their default "round"
1304  }
1305 
1306  if( e.diameter )
1307  {
1308  int diameter = kicad( *e.diameter );
1309  pad->SetSize( wxSize( diameter, diameter ) );
1310  }
1311  else
1312  {
1313  double drillz = pad->GetDrillSize().x;
1314  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1315  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1316  int diameter = KiROUND( drillz + 2 * annulus );
1317  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1318  }
1319 
1320  if( pad->GetShape() == PAD_SHAPE_OVAL )
1321  {
1322  // The Eagle "long" pad is wider than it is tall,
1323  // m_elongation is percent elongation
1324  wxSize sz = pad->GetSize();
1325  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1326  pad->SetSize( sz );
1327  }
1328 
1329  if( e.rot )
1330  {
1331  pad->SetOrientation( e.rot->degrees * 10 );
1332  }
1333 
1334  // @todo: handle stop and thermal
1335 }
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:155
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:53
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:204
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:259
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
const wxSize & GetDrillSize() const
Definition: class_pad.h:260
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:201
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
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:167
double GetOrientation() const
Definition: class_module.h:160
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:247
const wxSize & GetSize() const
Definition: class_pad.h:254
void SetSize(const wxSize &aSize)
Definition: class_pad.h:253
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:376
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:202
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:401
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:49
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
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 1477 of file eagle_plugin.cpp.

References MODULE::GraphicalItemsList(), 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().

1478 {
1479  EPOLYGON p( aTree );
1480  PCB_LAYER_ID layer = kicad_layer( p.layer );
1481 
1482  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
1483  {
1484  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1485  aModule->GraphicalItemsList().PushBack( dwg );
1486 
1487  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1488 
1489  /*
1490  switch( layer )
1491  {
1492  case Eco1_User: layer = F_SilkS; break;
1493  case Eco2_User: layer = B_SilkS; break;
1494 
1495  // all MODULE templates (created from eagle packages) are on front layer
1496  // until cloned.
1497  case Cmts_User: layer = F_SilkS; break;
1498  }
1499  */
1500 
1501  dwg->SetLayer( layer );
1502 
1503  dwg->SetTimeStamp( timeStamp( aTree ) );
1504 
1505  std::vector<wxPoint> pts;
1506  // TODO: I think there's no way to know a priori the number of children in wxXmlNode :()
1507  // pts.reserve( aTree.size() );
1508 
1509  // Get the first vertex and iterate
1510  wxXmlNode* vertex = aTree->GetChildren();
1511 
1512  while( vertex )
1513  {
1514  if( vertex->GetName() != "vertex" ) // skip <xmlattr> node
1515  continue;
1516 
1517  EVERTEX v( vertex );
1518 
1519  pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
1520 
1521  vertex = vertex->GetNext();
1522  }
1523 
1524  dwg->SetPolyPoints( pts );
1525 
1526  dwg->SetStart0( *pts.begin() );
1527  dwg->SetEnd0( pts.back() );
1528  }
1529 }
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)
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
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)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
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 1444 of file eagle_plugin.cpp.

References MODULE::GraphicalItemsList(), 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().

1445 {
1446  ERECT r( aTree );
1447  PCB_LAYER_ID layer = kicad_layer( r.layer );
1448 
1449  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
1450  {
1451  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1452  aModule->GraphicalItemsList().PushBack( dwg );
1453 
1454  dwg->SetLayer( layer );
1455  dwg->SetWidth( 0 );
1456 
1457  dwg->SetTimeStamp( timeStamp( aTree ) );
1458 
1459  std::vector<wxPoint> pts;
1460 
1461  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1462  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1463 
1464  pts.push_back( start );
1465  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1466  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1467  pts.push_back( end );
1468 
1469  dwg->SetPolyPoints( pts );
1470 
1471  dwg->SetStart0( start );
1472  dwg->SetEnd0( end );
1473  }
1474 }
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)
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
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)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1591 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::PadsList(), DLIST< T >::PushBack(), ESMD::rot, RotatePoint(), ESMD::roundness, D_PAD::SetAttribute(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), D_PAD::SetName(), D_PAD::SetOrientation(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), ESMD::x, and ESMD::y.

Referenced by makeModule().

1592 {
1593  ESMD e( aTree );
1594  PCB_LAYER_ID layer = kicad_layer( e.layer );
1595 
1596  if( !IsCopperLayer( layer ) )
1597  {
1598  return;
1599  }
1600 
1601  D_PAD* pad = new D_PAD( aModule );
1602  aModule->PadsList().PushBack( pad );
1603 
1604  pad->SetName( FROM_UTF8( e.name.c_str() ) );
1605  pad->SetShape( PAD_SHAPE_RECT );
1606  pad->SetAttribute( PAD_ATTRIB_SMD );
1607 
1608  // pad's "Position" is not relative to the module's,
1609  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1610 
1611  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1612 
1613  pad->SetPos0( padpos );
1614 
1615  RotatePoint( &padpos, aModule->GetOrientation() );
1616 
1617  pad->SetPosition( padpos + aModule->GetPosition() );
1618 
1619  pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
1620 
1621  pad->SetLayer( layer );
1622 
1623  static const LSET front( 3, F_Cu, F_Paste, F_Mask );
1624  static const LSET back( 3, B_Cu, B_Paste, B_Mask );
1625 
1626  if( layer == F_Cu )
1627  pad->SetLayerSet( front );
1628  else if( layer == B_Cu )
1629  pad->SetLayerSet( back );
1630 
1631  // Optional according to DTD
1632  if( e.roundness ) // set set shape to PAD_SHAPE_RECT above, in case roundness is not present
1633  {
1634  if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
1635  {
1636  if( e.dy == e.dx )
1637  pad->SetShape( PAD_SHAPE_CIRCLE );
1638  else
1639  pad->SetShape( PAD_SHAPE_OVAL );
1640  }
1641  }
1642 
1643  if( e.rot )
1644  {
1645  pad->SetOrientation( e.rot->degrees * 10 );
1646  }
1647 
1648  // don't know what stop, thermals, and cream should look like now.
1649 }
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:155
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:204
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.
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:167
double GetOrientation() const
Definition: class_module.h:160
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:247
void SetSize(const wxSize &aSize)
Definition: class_pad.h:253
int kicad_x(double x) const
Definition: eagle_plugin.h:165
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:376
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:202
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:401
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
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 1338 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::GraphicalItemsList(), 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().

1339 {
1340  ETEXT t( aTree );
1341  PCB_LAYER_ID layer = kicad_layer( t.layer );
1342 
1343  if( layer == UNDEFINED_LAYER )
1344  {
1345  layer = Cmts_User;
1346  }
1347 
1348  TEXTE_MODULE* txt;
1349 
1350  if( t.text == ">NAME" || t.text == ">name" )
1351  txt = &aModule->Reference();
1352  else if( t.text == ">VALUE" || t.text == ">value" )
1353  txt = &aModule->Value();
1354  else
1355  {
1356  // FIXME: graphical text items are rotated for some reason.
1357  txt = new TEXTE_MODULE( aModule );
1358  aModule->GraphicalItemsList().PushBack( txt );
1359  }
1360 
1361  txt->SetTimeStamp( timeStamp( aTree ) );
1362  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1363 
1364  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1365 
1366  txt->SetTextPos( pos );
1367  txt->SetPos0( pos - aModule->GetPosition() );
1368 
1369  txt->SetLayer( layer );
1370  txt->SetTextSize( kicad_fontz( t.size ) );
1371 
1372  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1373 
1374  txt->SetThickness( kicad( t.size * ratio / 100 ) );
1375 
1376  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1377 
1378  // An eagle package is never rotated, the DTD does not allow it.
1379  // angle -= aModule->GetOrienation();
1380 
1381  if( t.rot )
1382  {
1383  int sign = t.rot->mirror ? -1 : 1;
1384  txt->SetMirrored( t.rot->mirror );
1385 
1386  double degrees = t.rot->degrees;
1387 
1388  if( degrees == 90 || t.rot->spin )
1389  txt->SetTextAngle( sign * degrees * 10 );
1390  else if( degrees == 180 )
1391  align = ETEXT::TOP_RIGHT;
1392  else if( degrees == 270 )
1393  {
1394  align = ETEXT::TOP_RIGHT;
1395  txt->SetTextAngle( sign * 90 * 10 );
1396  }
1397  }
1398 
1399  switch( align )
1400  {
1401  case ETEXT::CENTER:
1402  // this was the default in pcbtxt's constructor
1403  break;
1404 
1405  case ETEXT::CENTER_LEFT:
1407  break;
1408 
1409  case ETEXT::CENTER_RIGHT:
1411  break;
1412 
1413  case ETEXT::TOP_CENTER:
1415  break;
1416 
1417  case ETEXT::TOP_LEFT:
1420  break;
1421 
1422  case ETEXT::TOP_RIGHT:
1425  break;
1426 
1427  case ETEXT::BOTTOM_CENTER:
1429  break;
1430 
1431  case ETEXT::BOTTOM_LEFT:
1434  break;
1435 
1436  case ETEXT::BOTTOM_RIGHT:
1439  break;
1440  }
1441 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
TEXTE_MODULE & Reference()
Definition: class_module.h:463
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:155
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
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:217
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:462
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
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
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 1211 of file eagle_plugin.cpp.

References EWIRE::curve, MODULE::GraphicalItemsList(), 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().

1212 {
1213  EWIRE w( aTree );
1214  PCB_LAYER_ID layer = kicad_layer( w.layer );
1215 
1216  if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
1217  {
1218  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1219  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1220  int width = kicad( w.width );
1221 
1222  // FIXME: the cap attribute is ignored because kicad can't create lines
1223  // with flat ends.
1224  EDGE_MODULE* dwg;
1225  if( !w.curve )
1226  {
1227  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1228 
1229  dwg->SetStart0( start );
1230  dwg->SetEnd0( end );
1231  }
1232  else
1233  {
1234  dwg = new EDGE_MODULE( aModule, S_ARC );
1235  wxPoint center = kicad_arc_center( start, end, *w.curve);
1236 
1237  dwg->SetStart0( center );
1238  dwg->SetEnd0( start );
1239  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1240  }
1241 
1242  dwg->SetLayer( layer );
1243  dwg->SetWidth( width );
1244 
1245  aModule->GraphicalItemsList().PushBack( dwg );
1246  }
1247 }
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.
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...
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
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 153 of file eagle_plugin.cpp.

154 {
155  return wxT( "Eagle" );
156 }
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 deleteTemplates(), FootprintEnumerate(), FootprintLoad(), init(), 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: