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...
 
long long GetLibraryTimestamp (const wxString &aLibraryPath) const override
 Generate a timestamp representing all the files in the library (including the library directory). 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 MODULELoadEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. 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 Types

typedef std::vector< ELAYERELAYERS
 
typedef ELAYERS::const_iterator EITER
 

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_y (const ECOORD &y) const
 Convert an Eagle distance to a KiCad distance. More...
 
int kicad_x (const ECOORD &x) const
 
wxSize kicad_fontz (const ECOORD &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...
 
const wxString & eagle_layer_name (int aLayer) const
 Get Eagle layer name by its number. More...
 
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 wxString *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...
 
wxString fmtDEG (double aAngle) const
 Function fmtDEG formats an angle in a way particular to a board file format. More...
 
MODULEmakeModule (wxXmlNode *aPackage, const wxString &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 transferPad (const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
 

Handles common pad properties

More...
 
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...
 
std::map< int, ELAYERm_eagleLayers
 Eagle layers data stored by the layer number. 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...
 
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 107 of file eagle_plugin.h.

Member Typedef Documentation

typedef int EAGLE_PLUGIN::BIU

Definition at line 151 of file eagle_plugin.h.

typedef ELAYERS::const_iterator EAGLE_PLUGIN::EITER
private

Definition at line 158 of file eagle_plugin.h.

typedef std::vector<ELAYER> EAGLE_PLUGIN::ELAYERS
private

Definition at line 157 of file eagle_plugin.h.

Constructor & Destructor Documentation

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 165 of file eagle_plugin.cpp.

References clear_cu_map(), and init().

165  :
166  m_rules( new ERULES() ),
167  m_xpath( new XPATH() ),
168  m_mod_time( wxDateTime::Now() )
169 {
170  init( NULL );
171  clear_cu_map();
172 }
void clear_cu_map()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:112
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:164
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:43
wxDateTime m_mod_time
Definition: eagle_plugin.h:184
EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 175 of file eagle_plugin.cpp.

References deleteTemplates(), m_rules, and m_xpath.

176 {
177  deleteTemplates();
178  delete m_rules;
179  delete m_xpath;
180 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
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 2257 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().

2258 {
2259  try
2260  {
2261  wxDateTime modtime = getModificationTime( aLibPath );
2262 
2263  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2264  // cache if either of the wxDateTime objects are invalid or the last file modification
2265  // time differs from the current file modification time.
2266  bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
2267 
2268  if( aLibPath != m_lib_path || load )
2269  {
2270  wxXmlNode* doc;
2271  LOCALE_IO toggle; // toggles on, then off, the C locale.
2272 
2273  deleteTemplates();
2274 
2275  // Set this before completion of loading, since we rely on it for
2276  // text of an exception. Delay setting m_mod_time until after successful load
2277  // however.
2278  m_lib_path = aLibPath;
2279 
2280  // 8 bit "filename" should be encoded according to disk filename encoding,
2281  // (maybe this is current locale, maybe not, its a filesystem issue),
2282  // and is not necessarily utf8.
2283  string filename = (const char*) aLibPath.char_str( wxConvFile );
2284 
2285  // Load the document
2286  wxXmlDocument xmlDocument;
2287  wxFileName fn( filename );
2288 
2289  if( !xmlDocument.Load( fn.GetFullPath() ) )
2290  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
2291  fn.GetFullPath() ) );
2292 
2293  doc = xmlDocument.GetRoot();
2294 
2295  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2296  NODE_MAP drawingChildren = MapChildren( drawing );
2297 
2298  // clear the cu map and then rebuild it.
2299  clear_cu_map();
2300 
2301  m_xpath->push( "eagle.drawing.layers" );
2302  wxXmlNode* layers = drawingChildren["layers"];
2303  loadLayerDefs( layers );
2304  m_xpath->pop();
2305 
2306  m_xpath->push( "eagle.drawing.library" );
2307  wxXmlNode* library = drawingChildren["library"];
2308  loadLibrary( library, NULL );
2309  m_xpath->pop();
2310 
2311  m_mod_time = modtime;
2312  }
2313  }
2314  catch(...){}
2315  // TODO: Handle exceptions
2316  // catch( file_parser_error fpe )
2317  // {
2318  // // for xml_parser_error, what() has the line number in it,
2319  // // but no byte offset. That should be an adequate error message.
2320  // THROW_IO_ERROR( fpe.what() );
2321  // }
2322  //
2323  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2324  // // so one catch should be OK for all errors.
2325  // catch( ptree_error pte )
2326  // {
2327  // string errmsg = pte.what();
2328  //
2329  // errmsg += " @\n";
2330  // errmsg += m_xpath->Contents();
2331  //
2332  // THROW_IO_ERROR( errmsg );
2333  // }
2334 }
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
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
void loadLayerDefs(wxXmlNode *aLayers)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
wxString m_lib_path
Definition: eagle_plugin.h:183
static wxDateTime getModificationTime(const wxString &aPath)
get a file&#39;s or dir&#39;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:184
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void deleteTemplates()
Deletes the footprint templates list
void pop()
Definition: eagle_parser.h:124
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

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

2216 {
2217  if( m_props )
2218  {
2219  UTF8 page_width;
2220  UTF8 page_height;
2221 
2222  if( m_props->Value( "page_width", &page_width ) &&
2223  m_props->Value( "page_height", &page_height ) )
2224  {
2226 
2227  int w = atoi( page_width.c_str() );
2228  int h = atoi( page_height.c_str() );
2229 
2230  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2231  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2232 
2233  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2234  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2235 
2236  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2237  }
2238  }
2239 }
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:177
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
Definition: eda_rect.h:118
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:176
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.
Definition: eda_rect.h:44
int GetX() const
Definition: eda_rect.h:109
int GetWidth() const
Definition: eda_rect.h:117
int GetY() const
Definition: eda_rect.h:110
#define DBG(x)
Definition: fctsys.h:33
void EAGLE_PLUGIN::clear_cu_map ( )
private

Definition at line 309 of file eagle_plugin.cpp.

References DIM, i, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

310 {
311  // All cu layers are invalid until we see them in the <layers> section while
312  // loading either a board or library. See loadLayerDefs().
313  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
314  m_cu_map[i] = -1;
315 }
#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:160
size_t i
Definition: json11.cpp:597
void EAGLE_PLUGIN::deleteTemplates ( )
private

Deletes the footprint templates list

Definition at line 1782 of file eagle_plugin.cpp.

References m_templates.

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

1783 {
1784  for( auto& t : m_templates )
1785  delete t.second;
1786 
1787  m_templates.clear();
1788 }
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:171
const wxString & EAGLE_PLUGIN::eagle_layer_name ( int  aLayer) const
private

Get Eagle layer name by its number.

Definition at line 2207 of file eagle_plugin.cpp.

References m_eagleLayers.

Referenced by kicad_layer().

2208 {
2209  static const wxString unknown( "unknown" );
2210  auto it = m_eagleLayers.find( aLayer );
2211  return it == m_eagleLayers.end() ? unknown : it->second.name;
2212 }
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:161
wxString 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 101 of file plugin.cpp.

References not_implemented().

Referenced by FP_LIB_TABLE::FootprintDelete().

102 {
103  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
104  not_implemented( this, __FUNCTION__ );
105 }
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 2337 of file eagle_plugin.cpp.

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

2339 {
2340  init( aProperties );
2341 
2342  cacheLib( aLibraryPath );
2343 
2344  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2345  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2346 }
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:171
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 108 of file plugin.cpp.

References not_implemented().

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

109 {
110  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
111  not_implemented( this, __FUNCTION__ );
112 }
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 115 of file plugin.cpp.

References not_implemented().

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

116 {
117  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
118  not_implemented( this, __FUNCTION__ );
119  return false;
120 }
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 2366 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

2367 {
2368  PLUGIN::FootprintLibOptions( aListToAppendTo );
2369 
2370  /*
2371  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2372  "Ignore duplicately named footprints within the same Eagle library. "
2373  "Only the first similarly named footprint will be loaded."
2374  ));
2375  */
2376 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:131
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 2349 of file eagle_plugin.cpp.

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

2351 {
2352  init( aProperties );
2353  cacheLib( aLibraryPath );
2354  MODULE_CITER mi = m_templates.find( aFootprintName );
2355 
2356  if( mi == m_templates.end() )
2357  return NULL;
2358 
2359  // copy constructor to clone the template
2360  MODULE* ret = new MODULE( *mi->second );
2361 
2362  return ret;
2363 }
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:171
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 94 of file plugin.cpp.

References not_implemented().

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

95 {
96  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
97  not_implemented( this, __FUNCTION__ );
98 }
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 189 of file eagle_plugin.cpp.

190 {
191  return wxT( "brd" );
192 }
long long EAGLE_PLUGIN::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
inlineoverridevirtual

Generate a timestamp representing all the files in the library (including the library directory).

Timestamps should not be considered ordered; they either match or they don't.

Implements PLUGIN.

Definition at line 125 of file eagle_plugin.h.

126  {
127  return getModificationTime( aLibraryPath ).GetValue().GetValue();
128  }
static wxDateTime getModificationTime(const wxString &aPath)
get a file&#39;s or dir&#39;s modification time.
wxDateTime EAGLE_PLUGIN::getModificationTime ( const wxString &  aPath)
staticprivate

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

Definition at line 2242 of file eagle_plugin.cpp.

Referenced by cacheLib().

2243 {
2244  // File hasn't been loaded yet.
2245  if( aPath.IsEmpty() )
2246  return wxDateTime::Now();
2247 
2248  wxFileName fn( aPath );
2249 
2250  if( fn.IsFileReadable() )
2251  return fn.GetModificationTime();
2252  else
2253  return wxDateTime( 0.0 );
2254 }
void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 291 of file eagle_plugin.cpp.

References 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, and m_xpath.

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

292 {
293  m_hole_count = 0;
294  m_min_trace = 0;
295  m_min_via = 0;
296  m_min_via_hole = 0;
297  m_xpath->clear();
298  m_pads_to_nets.clear();
299 
300  m_board = NULL;
301  m_props = aProperties;
302 
303 
304  delete m_rules;
305  m_rules = new ERULES();
306 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:177
void clear()
Definition: eagle_parser.h:122
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:180
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:181
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:176
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:43
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:179
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:167
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:169
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 130 of file eagle_plugin.h.

131  {
132  return false; // until someone writes others like FootprintSave(), etc.
133  }
wxSize EAGLE_PLUGIN::kicad_fontz ( const ECOORD d) const
inlineprivate

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

Definition at line 195 of file eagle_plugin.cpp.

References ECOORD::ToPcbUnits().

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

196 {
197  // texts seem to better match eagle when scaled down by 0.95
198  int kz = d.ToPcbUnits() * 95 / 100;
199  return wxSize( kz, kz );
200 }
int ToPcbUnits() const
Definition: eagle_parser.h:438
PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer ( int  aLayer) const
private

Convert an Eagle layer to a KiCad layer.

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

2140 {
2141  int kiLayer;
2142 
2143  // eagle copper layer:
2144  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
2145  {
2146  kiLayer = m_cu_map[aEagleLayer];
2147  }
2148 
2149  else
2150  {
2151  // translate non-copper eagle layer to pcbnew layer
2152  switch( aEagleLayer )
2153  {
2154  // Eagle says "Dimension" layer, but it's for board perimeter
2155  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
2156  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
2157  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
2158  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
2159  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
2160  case EAGLE_LAYER::TVALUES: kiLayer = F_SilkS; break;
2161  case EAGLE_LAYER::BVALUES: kiLayer = B_SilkS; break;
2162  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
2163  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
2164  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
2165  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
2166  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
2167  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
2168  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
2169  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
2170  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
2171  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
2172  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
2173 
2174  // Packages show the future chip pins on SMD parts using layer 51.
2175  // This is an area slightly smaller than the PAD/SMD copper area.
2176  // Carry those visual aids into the MODULE on the fabrication layer,
2177  // not silkscreen. This is perhaps not perfect, but there is not a lot
2178  // of other suitable paired layers
2179  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
2180  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
2181 
2182  // thes layers are defined as user layers. put them on ECO layers
2183  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
2184  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
2185 
2186  case EAGLE_LAYER::UNROUTED:
2187  case EAGLE_LAYER::TKEEPOUT:
2188  case EAGLE_LAYER::BKEEPOUT:
2189  case EAGLE_LAYER::TTEST:
2190  case EAGLE_LAYER::BTEST:
2191  case EAGLE_LAYER::MILLING:
2192  case EAGLE_LAYER::HOLES:
2193  default:
2194  // some layers do not map to KiCad
2195  wxLogMessage( wxString::Format( "Unsupported Eagle layer '%s' (%d), converted to Dwgs.User layer",
2196  eagle_layer_name( aEagleLayer ), aEagleLayer ) );
2197 
2198  kiLayer = Dwgs_User;
2199  break;
2200  }
2201  }
2202 
2203  return PCB_LAYER_ID( kiLayer );
2204 }
#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:160
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
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 ( const ECOORD x) const
inlineprivate
int EAGLE_PLUGIN::kicad_y ( const ECOORD y) const
inlineprivate

Convert an Eagle distance to a KiCad distance.

Definition at line 192 of file eagle_plugin.h.

References ECOORD::ToPcbUnits().

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

192 { return -y.ToPcbUnits(); }
int ToPcbUnits() const
Definition: eagle_parser.h:438
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 203 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.

204 {
205  LOCALE_IO toggle; // toggles on, then off, the C locale.
206  wxXmlNode* doc;
207 
208  init( aProperties );
209 
210  m_board = aAppendToMe ? aAppendToMe : new BOARD();
211 
212  // Give the filename to the board if it's new
213  if( !aAppendToMe )
214  m_board->SetFileName( aFileName );
215 
216  // delete on exception, if I own m_board, according to aAppendToMe
217  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
218 
219  try
220  {
221  // Load the document
222  wxXmlDocument xmlDocument;
223  wxFileName fn = aFileName;
224 
225  if( !xmlDocument.Load( fn.GetFullPath() ) )
226  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
227  fn.GetFullPath() ) );
228 
229  doc = xmlDocument.GetRoot();
230 
231  m_min_trace = INT_MAX;
232  m_min_via = INT_MAX;
233  m_min_via_hole = INT_MAX;
234 
235  loadAllSections( doc );
236 
237  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
238 
239  if( m_min_trace < designSettings.m_TrackMinWidth )
240  designSettings.m_TrackMinWidth = m_min_trace;
241 
242  if( m_min_via < designSettings.m_ViasMinSize )
243  designSettings.m_ViasMinSize = m_min_via;
244 
245  if( m_min_via_hole < designSettings.m_ViasMinDrill )
246  designSettings.m_ViasMinDrill = m_min_via_hole;
247 
248  if( m_rules->mdWireWire )
249  {
250  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
251  int clearance = KiROUND( m_rules->mdWireWire );
252 
253  if( clearance < defaultNetclass->GetClearance() )
254  defaultNetclass->SetClearance( clearance );
255  }
256 
257  // should be empty, else missing m_xpath->pop()
258  wxASSERT( m_xpath->Contents().size() == 0 );
259  }
260  // Catch all exceptions thrown from the parser.
261  catch( const XML_PARSER_ERROR &exc )
262  {
263  wxString errmsg = exc.what();
264 
265  errmsg += "\n@ ";
266  errmsg += m_xpath->Contents();
267 
268  THROW_IO_ERROR( errmsg );
269  }
270 
271  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
272 
273  // Ensure the copper layers count is a multiple of 2
274  // Pcbnew does not like boards with odd layers count
275  // (these boards cannot exist. they actually have a even layers count)
276  int lyrcnt = m_board->GetCopperLayerCount();
277 
278  if( (lyrcnt % 2) != 0 )
279  {
280  lyrcnt++;
281  m_board->SetCopperLayerCount( lyrcnt );
282  }
283 
284  centerBoard();
285 
286  deleter.release();
287  return m_board;
288 }
wxString Contents()
return the contents of the XPATH as a single string
Definition: eagle_parser.h:139
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:177
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:163
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:180
Class XML_PARSER_ERROR implements a simple wrapper around runtime_error to isolate the errors thrown ...
Definition: eagle_parser.h:70
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:181
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:70
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:179
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 318 of file eagle_plugin.cpp.

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

Referenced by Load().

319 {
320  wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
321  NODE_MAP drawingChildren = MapChildren( drawing );
322 
323  wxXmlNode* board = drawingChildren["board"];
324  NODE_MAP boardChildren = MapChildren( board );
325 
326  m_xpath->push( "eagle.drawing" );
327 
328  {
329  m_xpath->push( "board" );
330 
331  wxXmlNode* designrules = boardChildren["designrules"];
332  loadDesignRules( designrules );
333 
334  m_xpath->pop();
335  }
336 
337  {
338  m_xpath->push( "layers" );
339 
340  wxXmlNode* layers = drawingChildren["layers"];
341  loadLayerDefs( layers );
342 
343  m_xpath->pop();
344  }
345 
346  {
347  m_xpath->push( "board" );
348 
349  wxXmlNode* plain = boardChildren["plain"];
350  loadPlain( plain );
351 
352  wxXmlNode* signals = boardChildren["signals"];
353  loadSignals( signals );
354 
355  wxXmlNode* libs = boardChildren["libraries"];
356  loadLibraries( libs );
357 
358  wxXmlNode* elems = boardChildren["elements"];
359  loadElements( elems );
360 
361  m_xpath->pop(); // "board"
362  }
363 
364  m_xpath->pop(); // "eagle.drawing"
365 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
void loadLayerDefs(wxXmlNode *aLayers)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void loadElements(wxXmlNode *aElements)
void pop()
Definition: eagle_parser.h:124
void loadDesignRules(wxXmlNode *aDesignRules)
void loadSignals(wxXmlNode *aSignals)
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void EAGLE_PLUGIN::loadDesignRules ( wxXmlNode *  aDesignRules)
private

Definition at line 368 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

369 {
370  m_xpath->push( "designrules" );
371  m_rules->parse( aDesignRules );
372  m_xpath->pop(); // "designrules"
373 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
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:164
void pop()
Definition: eagle_parser.h:124
void EAGLE_PLUGIN::loadElements ( wxXmlNode *  aElements)
private

Definition at line 851 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, XPATH::Value(), MODULE::Value(), EATTR::value, EATTR::VALUE, EELEMENT::value, EELEMENT::x, and EELEMENT::y.

Referenced by loadAllSections().

852 {
853  m_xpath->push( "elements.element", "name" );
854 
855  EATTR name;
856  EATTR value;
857  bool refanceNamePresetInPackageLayout;
858  bool valueNamePresetInPackageLayout;
859 
860  // Get the first element and iterate
861  wxXmlNode* element = aElements->GetChildren();
862 
863  while( element )
864  {
865  if( element->GetName() != "element" )
866  {
867  wxLogMessage( "expected: <element> read <%s>. Skip it", element->GetName() );
868  // Get next item
869  element = element->GetNext();
870  continue;
871  }
872 
873  EELEMENT e( element );
874 
875  // use "NULL-ness" as an indication of presence of the attribute:
876  EATTR* nameAttr = 0;
877  EATTR* valueAttr = 0;
878 
879  m_xpath->Value( e.name.c_str() );
880 
881  wxString pkg_key = makeKey( e.library, e.package );
882 
883  MODULE_CITER mi = m_templates.find( pkg_key );
884 
885  if( mi == m_templates.end() )
886  {
887  wxString emsg = wxString::Format( _( "No \"%s\" package in library \"%s\"" ),
888  GetChars( FROM_UTF8( e.package.c_str() ) ),
889  GetChars( FROM_UTF8( e.library.c_str() ) ) );
890  THROW_IO_ERROR( emsg );
891  }
892 
893  // copy constructor to clone the template
894  MODULE* m = new MODULE( *mi->second );
895  m_board->Add( m, ADD_APPEND );
896 
897  // update the nets within the pads of the clone
898  for( D_PAD* pad = m->PadsList(); pad; pad = pad->Next() )
899  {
900  wxString pn_key = makeKey( e.name, pad->GetName() );
901 
902  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
903  if( ni != m_pads_to_nets.end() )
904  {
905  const ENET* enet = &ni->second;
906  pad->SetNetCode( enet->netcode );
907  }
908  }
909 
910  refanceNamePresetInPackageLayout = true;
911  valueNamePresetInPackageLayout = true;
912  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
913 
914  // Is >NAME field set in package layout ?
915  if( m->GetReference().size() == 0 )
916  {
917  m->Reference().SetVisible( false ); // No so no show
918  refanceNamePresetInPackageLayout = false;
919  }
920 
921  // Is >VALUE field set in package layout
922  if( m->GetValue().size() == 0 )
923  {
924  m->Value().SetVisible( false ); // No so no show
925  valueNamePresetInPackageLayout = false;
926  }
927 
928  m->SetReference( FROM_UTF8( e.name.c_str() ) );
929  m->SetValue( FROM_UTF8( e.value.c_str() ) );
930 
931  if( !e.smashed )
932  { // Not smashed so show NAME & VALUE
933  if( valueNamePresetInPackageLayout )
934  m->Value().SetVisible( true ); // Only if place holder in package layout
935 
936  if( refanceNamePresetInPackageLayout )
937  m->Reference().SetVisible( true ); // Only if place holder in package layout
938  }
939  else if( *e.smashed == true )
940  { // Smasted so set default to no show for NAME and VALUE
941  m->Value().SetVisible( false );
942  m->Reference().SetVisible( false );
943 
944  // initalize these to default values incase the <attribute> elements are not present.
945  m_xpath->push( "attribute", "name" );
946 
947  // VALUE and NAME can have something like our text "effects" overrides
948  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
949  // There can be one for NAME and/or VALUE both. Features present in the
950  // EATTR override the ones established in the package only if they are
951  // present here (except for rot, which if not present means angle zero).
952  // So the logic is a bit different than in packageText() and in plain text.
953 
954  // Get the first attribute and iterate
955  wxXmlNode* attribute = element->GetChildren();
956 
957  while( attribute )
958  {
959  if( attribute->GetName() != "attribute" )
960  {
961  wxLogMessage( "expected: <attribute> read <%s>. Skip it", attribute->GetName() );
962  attribute = attribute->GetNext();
963  continue;
964  }
965 
966  EATTR a( attribute );
967 
968  if( a.name == "NAME" )
969  {
970  name = a;
971  nameAttr = &name;
972 
973  // do we have a display attribute ?
974  if( a.display )
975  {
976  // Yes!
977  switch( *a.display )
978  {
979  case EATTR::VALUE :
980  nameAttr->name = e.name;
981  m->SetReference( e.name );
982  if( refanceNamePresetInPackageLayout )
983  m->Reference().SetVisible( true );
984  break;
985 
986  case EATTR::NAME :
987  if( refanceNamePresetInPackageLayout )
988  {
989  m->SetReference( "NAME" );
990  m->Reference().SetVisible( true );
991  }
992  break;
993 
994  case EATTR::BOTH :
995  if( refanceNamePresetInPackageLayout )
996  m->Reference().SetVisible( true );
997  nameAttr->name = nameAttr->name + " = " + e.name;
998  m->SetReference( "NAME = " + e.name );
999  break;
1000 
1001  case EATTR::Off :
1002  m->Reference().SetVisible( false );
1003  break;
1004 
1005  default:
1006  nameAttr->name = e.name;
1007  if( refanceNamePresetInPackageLayout )
1008  m->Reference().SetVisible( true );
1009  }
1010  }
1011  else
1012  // No display, so default is visable, and show value of NAME
1013  m->Reference().SetVisible( true );
1014  }
1015  else if( a.name == "VALUE" )
1016  {
1017  value = a;
1018  valueAttr = &value;
1019 
1020  if( a.display )
1021  {
1022  // Yes!
1023  switch( *a.display )
1024  {
1025  case EATTR::VALUE :
1026  valueAttr->value = opt_wxString( e.value );
1027  m->SetValue( e.value );
1028  if( valueNamePresetInPackageLayout )
1029  m->Value().SetVisible( true );
1030  break;
1031 
1032  case EATTR::NAME :
1033  if( valueNamePresetInPackageLayout )
1034  m->Value().SetVisible( true );
1035  m->SetValue( "VALUE" );
1036  break;
1037 
1038  case EATTR::BOTH :
1039  if( valueNamePresetInPackageLayout )
1040  m->Value().SetVisible( true );
1041  valueAttr->value = opt_wxString( "VALUE = " + e.value );
1042  m->SetValue( "VALUE = " + e.value );
1043  break;
1044 
1045  case EATTR::Off :
1046  m->Value().SetVisible( false );
1047  break;
1048 
1049  default:
1050  valueAttr->value = opt_wxString( e.value );
1051  if( valueNamePresetInPackageLayout )
1052  m->Value().SetVisible( true );
1053  }
1054  }
1055  else
1056  // No display, so default is visible, and show value of NAME
1057  m->Value().SetVisible( true );
1058 
1059  }
1060 
1061  attribute = attribute->GetNext();
1062  }
1063 
1064  m_xpath->pop(); // "attribute"
1065  }
1066 
1067  orientModuleAndText( m, e, nameAttr, valueAttr );
1068 
1069  // Get next element
1070  element = element->GetNext();
1071  }
1072 
1073  m_xpath->pop(); // "elements.element"
1074 }
TEXTE_MODULE & Reference()
Definition: class_module.h:502
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:177
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
Eagle element element.
Definition: eagle_parser.h:796
void SetVisible(bool aVisible)
Definition: eda_text.h:173
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:486
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:39
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
Definition: eagle_parser.h:378
wxString name
Definition: eagle_parser.h:604
static wxString makeKey(const wxString &aFirst, const wxString &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:501
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:160
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:468
void SetPosition(const wxPoint &aPos) override
opt_wxString value
Definition: eagle_parser.h:605
Eagle net.
Definition: eagle_parser.h:461
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:602
MODULE_MAP::const_iterator MODULE_CITER
int netcode
Definition: eagle_parser.h:463
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
const char * name
Definition: DXF_plotter.cpp:61
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:458
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:171
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:495
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:169
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
void pop()
Definition: eagle_parser.h:124
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
MODULE * PLUGIN::LoadEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented in PCB_IO, and GPCB_PLUGIN.

Definition at line 76 of file plugin.cpp.

References PLUGIN::FootprintLoad().

Referenced by FP_LIB_TABLE::LoadEnumeratedFootprint(), and FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs().

79 {
80  // default implementation
81  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
82 }
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:85
void EAGLE_PLUGIN::loadLayerDefs ( wxXmlNode *  aLayers)
private

Definition at line 376 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadAllSections().

377 {
378  ELAYERS cu; // copper layers
379 
380  // Get the first layer and iterate
381  wxXmlNode* layerNode = aLayers->GetChildren();
382 
383  m_eagleLayers.clear();
384 
385  while( layerNode )
386  {
387  ELAYER elayer( layerNode );
388  m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
389 
390  // find the subset of layers that are copper and active
391  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
392  {
393  cu.push_back( elayer );
394  }
395 
396  layerNode = layerNode->GetNext();
397  }
398 
399  // establish cu layer map:
400  int ki_layer_count = 0;
401 
402  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
403  {
404  if( ki_layer_count == 0 )
405  m_cu_map[it->number] = F_Cu;
406  else if( ki_layer_count == int( cu.size()-1 ) )
407  m_cu_map[it->number] = B_Cu;
408  else
409  {
410  // some eagle boards do not have contiguous layer number sequences.
411 
412 #if 0 // pre PCB_LAYER_ID & LSET:
413  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
414 #else
415  m_cu_map[it->number] = ki_layer_count;
416 #endif
417  }
418  }
419 
420 #if 0 && defined(DEBUG)
421  printf( "m_cu_map:\n" );
422  for( unsigned i=0; i<DIM(m_cu_map); ++i )
423  {
424  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
425  }
426 #endif
427 
428  // Set the layer names and cu count iff we're loading a board.
429  if( m_board )
430  {
431  m_board->SetCopperLayerCount( cu.size() );
432 
433  for( EITER it = cu.begin(); it != cu.end(); ++it )
434  {
435  PCB_LAYER_ID layer = kicad_layer( it->number );
436 
437  // these function provide their own protection against UNDEFINED_LAYER:
438  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
439  m_board->SetLayerType( layer, LT_SIGNAL );
440 
441  // could map the colors here
442  }
443  }
444 }
#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:177
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:160
PCB_LAYER_ID
A quick note on layer IDs:
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:161
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:157
size_t i
Definition: json11.cpp:597
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:158
void EAGLE_PLUGIN::loadLibraries ( wxXmlNode *  aLibs)
private

Definition at line 831 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

832 {
833  m_xpath->push( "libraries.library", "name" );
834 
835  // Get the first library and iterate
836  wxXmlNode* library = aLibs->GetChildren();
837 
838  while( library )
839  {
840  const wxString& lib_name = library->GetAttribute( "name" );
841 
842  m_xpath->Value( lib_name.c_str() );
843  loadLibrary( library, &lib_name );
844  library = library->GetNext();
845  }
846 
847  m_xpath->pop();
848 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void pop()
Definition: eagle_parser.h:124
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
void EAGLE_PLUGIN::loadLibrary ( wxXmlNode *  aLib,
const wxString *  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 775 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().

776 {
777  m_xpath->push( "packages" );
778 
779  // library will have <xmlattr> node, skip that and get the single packages node
780  wxXmlNode* packages = MapChildren( aLib )["packages"];
781 
782 
783  // Create a MODULE for all the eagle packages, for use later via a copy constructor
784  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
785  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
786 
787  // Get the first package and iterate
788  wxXmlNode* package = packages->GetChildren();
789 
790  while( package )
791  {
792  m_xpath->push( "package", "name" );
793 
794  const wxString& pack_ref = package->GetAttribute( "name" );
795  std::string pack_name( pack_ref );
796  ReplaceIllegalFileNameChars( &pack_name, '_' );
797 
798  m_xpath->Value( pack_name.c_str() );
799 
800  wxString key = aLibName ? makeKey( *aLibName, pack_name ) : wxString( pack_name );
801 
802  MODULE* m = makeModule( package, pack_name );
803 
804  // add the templating MODULE to the MODULE template factory "m_templates"
805  std::pair<MODULE_ITER, bool> r = m_templates.insert( {key, m} );
806 
807  if( !r.second
808  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
809  )
810  {
811  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
812  wxString pkg = FROM_UTF8( pack_name.c_str() );
813 
814  wxString emsg = wxString::Format(
815  _( "<package> name: \"%s\" duplicated in eagle <library>: \"%s\"" ),
816  GetChars( pkg ),
817  GetChars( lib )
818  );
819  THROW_IO_ERROR( emsg );
820  }
821 
822  m_xpath->pop();
823 
824  package = package->GetNext();
825  }
826 
827  m_xpath->pop(); // "packages"
828 }
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 push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:570
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
static wxString makeKey(const wxString &aFirst, const wxString &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:183
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:171
void pop()
Definition: eagle_parser.h:124
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
MODULE * makeModule(wxXmlNode *aPackage, const wxString &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
void EAGLE_PLUGIN::loadPlain ( wxXmlNode *  aPlain)
private

Definition at line 447 of file eagle_plugin.cpp.

References abs, 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(), ConvertArcCenter(), EWIRE::curve, DEFAULT_PCB_EDGE_THICKNESS, EROT::degrees, ZONE_CONTAINER::DIAGONAL_EDGE, EDIMENSION::dimensionType, EHOLE::drill, EagleTimeStamp(), FROM_UTF8(), ZONE_CONTAINER::GetDefaultHatchPitch(), BOARD::GetDesignSettings(), ZONE_CONTAINER::GetPosition(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, IsCopperLayer(), 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(), ERECT::rot, ETEXT::rot, ZONE_CONTAINER::Rotate(), 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(), ZONE_CONTAINER::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, ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, ECOORD::ToPcbUnits(), 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().

448 {
449  m_xpath->push( "plain" );
450 
451  // Get the first graphic and iterate
452  wxXmlNode* gr = aGraphics->GetChildren();
453 
454  // (polygon | wire | text | circle | rectangle | frame | hole)*
455  while( gr )
456  {
457  wxString grName = gr->GetName();
458 
459  if( grName == "wire" )
460  {
461  m_xpath->push( "wire" );
462 
463  EWIRE w( gr );
464  PCB_LAYER_ID layer = kicad_layer( w.layer );
465 
466  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
467  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
468 
469  if( layer != UNDEFINED_LAYER )
470  {
471  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
472  m_board->Add( dseg, ADD_APPEND );
473 
474  if( !w.curve )
475  {
476  dseg->SetStart( start );
477  dseg->SetEnd( end );
478  }
479  else
480  {
481  wxPoint center = ConvertArcCenter( start, end, *w.curve );
482 
483  dseg->SetShape( S_ARC );
484  dseg->SetStart( center );
485  dseg->SetEnd( start );
486  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
487  }
488 
489  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
490  dseg->SetLayer( layer );
491  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
492  }
493  m_xpath->pop();
494  }
495  else if( grName == "text" )
496  {
497  m_xpath->push( "text" );
498 
499  ETEXT t( gr );
500  PCB_LAYER_ID layer = kicad_layer( t.layer );
501 
502  if( layer != UNDEFINED_LAYER )
503  {
504  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
505  m_board->Add( pcbtxt, ADD_APPEND );
506 
507  pcbtxt->SetLayer( layer );
508  pcbtxt->SetTimeStamp( EagleTimeStamp( gr ) );
509  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
510  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
511 
512  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
513 
514  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
515 
516  pcbtxt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
517 
518  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
519 
520  if( t.rot )
521  {
522  int sign = t.rot->mirror ? -1 : 1;
523  pcbtxt->SetMirrored( t.rot->mirror );
524 
525  double degrees = t.rot->degrees;
526 
527  if( degrees == 90 || t.rot->spin )
528  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
529  else if( degrees == 180 )
530  align = ETEXT::TOP_RIGHT;
531  else if( degrees == 270 )
532  {
533  pcbtxt->SetTextAngle( sign * 90 * 10 );
534  align = ETEXT::TOP_RIGHT;
535  }
536  else // Ok so text is not at 90,180 or 270 so do some funny stuf to get placement right
537  {
538  if( ( degrees > 0 ) && ( degrees < 90 ) )
539  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
540  else if( ( degrees > 90 ) && ( degrees < 180 ) )
541  {
542  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
543  align = ETEXT::TOP_RIGHT;
544  }
545  else if( ( degrees > 180 ) && ( degrees < 270 ) )
546  {
547  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
548  align = ETEXT::TOP_RIGHT;
549  }
550  else if( ( degrees > 270 ) && ( degrees < 360 ) )
551  {
552  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
553  align = ETEXT::BOTTOM_LEFT;
554  }
555  }
556  }
557 
558  switch( align )
559  {
560  case ETEXT::CENTER:
561  // this was the default in pcbtxt's constructor
562  break;
563 
564  case ETEXT::CENTER_LEFT:
566  break;
567 
568  case ETEXT::CENTER_RIGHT:
570  break;
571 
572  case ETEXT::TOP_CENTER:
574  break;
575 
576  case ETEXT::TOP_LEFT:
579  break;
580 
581  case ETEXT::TOP_RIGHT:
584  break;
585 
588  break;
589 
590  case ETEXT::BOTTOM_LEFT:
593  break;
594 
595  case ETEXT::BOTTOM_RIGHT:
598  break;
599  }
600  }
601  m_xpath->pop();
602  }
603  else if( grName == "circle" )
604  {
605  m_xpath->push( "circle" );
606 
607  ECIRCLE c( gr );
608  PCB_LAYER_ID layer = kicad_layer( c.layer );
609 
610  if( layer != UNDEFINED_LAYER ) // unsupported layer
611  {
612  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
613  m_board->Add( dseg, ADD_APPEND );
614 
615  dseg->SetShape( S_CIRCLE );
616  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
617  dseg->SetLayer( layer );
618  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
619  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
620  dseg->SetWidth( c.width.ToPcbUnits() );
621  }
622  m_xpath->pop();
623  }
624  else if( grName == "rectangle" )
625  {
626  // This seems to be a simplified rectangular [copper] zone, cannot find any
627  // net related info on it from the DTD.
628  m_xpath->push( "rectangle" );
629 
630  ERECT r( gr );
631  PCB_LAYER_ID layer = kicad_layer( r.layer );
632 
633  if( IsCopperLayer( layer ) )
634  {
635  // use a "netcode = 0" type ZONE:
636  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
637  m_board->Add( zone, ADD_APPEND );
638 
639  zone->SetTimeStamp( EagleTimeStamp( gr ) );
640  zone->SetLayer( layer );
642 
644 
645  const int outlineIdx = -1; // this is the id of the copper zone main outline
646  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
647  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
648  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
649  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
650 
651  if( r.rot )
652  {
653  zone->Rotate( zone->GetPosition(), r.rot->degrees * 10 );
654  }
655  // this is not my fault:
656  zone->SetHatch( outline_hatch, zone->GetDefaultHatchPitch(), true );
657  }
658 
659  m_xpath->pop();
660  }
661  else if( grName == "hole" )
662  {
663  m_xpath->push( "hole" );
664  EHOLE e( gr );
665 
666  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
667  // Use m_hole_count to gen up a unique name.
668 
669  MODULE* module = new MODULE( m_board );
670  m_board->Add( module, ADD_APPEND );
671 
672  char temp[40];
673  snprintf( temp, sizeof( temp ), "@HOLE%d", m_hole_count++ );
674  module->SetReference( FROM_UTF8( temp ) );
675  module->Reference().SetVisible( false );
676 
677  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
678 
679  module->SetPosition( pos );
680 
681  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
682  D_PAD* pad = new D_PAD( module );
683  module->PadsList().PushBack( pad );
684 
685  pad->SetShape( PAD_SHAPE_CIRCLE );
687 
688  /* pad's position is already centered on module at relative (0, 0)
689  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
690 
691  pad->SetPos0( padpos );
692  pad->SetPosition( padpos + module->GetPosition() );
693  */
694 
695  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
696 
697  pad->SetDrillSize( sz );
698  pad->SetSize( sz );
699 
700  pad->SetLayerSet( LSET::AllCuMask() );
701  m_xpath->pop();
702  }
703  else if( grName == "frame" )
704  {
705  // picture this
706  }
707  else if( grName == "polygon" )
708  {
709  // could be on a copper layer, could be on another layer.
710  // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
711  }
712  else if( grName == "dimension" )
713  {
714  EDIMENSION d( gr );
715  PCB_LAYER_ID layer = kicad_layer( d.layer );
716 
717  if( layer != UNDEFINED_LAYER )
718  {
719  DIMENSION* dimension = new DIMENSION( m_board );
720  m_board->Add( dimension, ADD_APPEND );
721 
722  if( d.dimensionType )
723  {
724  // Eagle dimension graphic arms may have different lengths, but they look
725  // incorrect in KiCad (the graphic is tilted). Make them even lenght in such case.
726  if( *d.dimensionType == "horizontal" )
727  {
728  int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
729  d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
730  d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
731  }
732  else if( *d.dimensionType == "vertical" )
733  {
734  int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
735  d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
736  d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
737  }
738  }
739 
740  dimension->SetLayer( layer );
741  // The origin and end are assumed to always be in this order from eagle
742  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
743  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
745 
747  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
748 
749  if( width > maxThickness )
750  width = maxThickness;
751 
752  dimension->Text().SetThickness( width );
753  dimension->SetWidth( width );
754 
755  // check which axis the dimension runs in
756  // because the "height" of the dimension is perpendicular to that axis
757  // Note the check is just if two axes are close enough to each other
758  // Eagle appears to have some rounding errors
759  if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm
760  dimension->SetHeight( kicad_x( d.x3 - d.x1 ) );
761  else
762  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
763 
764  dimension->AdjustDimensionDetails();
765  }
766  }
767 
768  // Get next graphic
769  gr = gr->GetNext();
770  }
771  m_xpath->pop();
772 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
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:673
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void SetTextAngle(double aAngle)
TEXTE_MODULE & Reference()
Definition: class_module.h:502
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...
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:177
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.
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:117
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
void SetVisible(bool aVisible)
Definition: eda_text.h:173
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
Eagle hole element.
Definition: eagle_parser.h:785
const wxPoint GetPosition() const override
Function GetPosition.
Definition: class_zone.cpp:169
Eagle text element.
Definition: eagle_parser.h:645
#define abs(a)
Definition: auxiliary.h:84
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: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.
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
Arcs (with rounded ends)
Eagle circle.
Definition: eagle_parser.h:570
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
void Rotate(const wxPoint &centre, double angle) override
Function Rotate Move the outlines.
Definition: class_zone.cpp:927
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:202
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
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:468
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:67
void SetPosition(const wxPoint &aPos) override
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:167
Eagle XML rectangle in binary.
Definition: eagle_parser.h:583
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
#define DEFAULT_PCB_EDGE_THICKNESS
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:401
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
TEXTE_PCB & Text()
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
void SetEnd(const wxPoint &aEnd)
Eagle wire.
Definition: eagle_parser.h:499
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)
Eagle dimension element.
Definition: eagle_parser.h:628
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
const wxSize & GetTextSize() const
Definition: eda_text.h:213
void pop()
Definition: eagle_parser.h:124
void SetWidth(int aWidth)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
Class DIMENSION.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
void SetWidth(int aWidth)
void EAGLE_PLUGIN::loadSignals ( wxXmlNode *  aSignals)
private

Definition at line 1795 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, PNS::angle(), ZONE_CONTAINER::AppendCorner(), B_Cu, Clamp(), ConvertArcCenter(), EWIRE::curve, EVERTEX::curve, EPOLYGON::CUTOUT, DEG2RAD(), ZONE_CONTAINER::DIAGONAL_EDGE, EVIA::diam, EVIA::drill, EagleTimeStamp(), escapeName(), F_Cu, GetArcToSegmentCount(), ZONE_CONTAINER::GetDefaultHatchPitch(), VIA::GetDrill(), TRACK::GetWidth(), i, DLIST< T >::Insert(), IsCopperLayer(), EPOLYGON::isolate, 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(), max, EPOLYGON::max_priority, ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_THERMAL, XPATH::pop(), EPOLYGON::pour, XPATH::push(), RAD2DEG(), 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(), ZONE_CONTAINER::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, ECOORD::ToPcbUnits(), NETINFO_LIST::UNCONNECTED, XPATH::Value(), VIA, VIA_BLIND_BURIED, VIA_MICROVIA, VIA_THROUGH, EWIRE::width, EPOLYGON::width, wxPoint::x, EVIA::x, EVERTEX::x, EWIRE::x1, EWIRE::x2, wxPoint::y, EVIA::y, EVERTEX::y, EWIRE::y1, and EWIRE::y2.

Referenced by loadAllSections().

1796 {
1797  ZONES zones; // per net
1798 
1799  m_xpath->push( "signals.signal", "name" );
1800 
1801  int netCode = 1;
1802 
1803  // Get the first signal and iterate
1804  wxXmlNode* net = aSignals->GetChildren();
1805 
1806  while( net )
1807  {
1808  bool sawPad = false;
1809 
1810  zones.clear();
1811 
1812  const wxString& netName = escapeName( net->GetAttribute( "name" ) );
1813  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
1814 
1815  m_xpath->Value( netName.c_str() );
1816 
1817  // Get the first net item and iterate
1818  wxXmlNode* netItem = net->GetChildren();
1819 
1820  // (contactref | polygon | wire | via)*
1821  while( netItem )
1822  {
1823  const wxString& itemName = netItem->GetName();
1824 
1825  if( itemName == "wire" )
1826  {
1827  m_xpath->push( "wire" );
1828 
1829  EWIRE w( netItem );
1830  PCB_LAYER_ID layer = kicad_layer( w.layer );
1831 
1832  if( IsCopperLayer( layer ) )
1833  {
1834  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1835  double angle = 0.0;
1836  double end_angle = 0.0;
1837  double radius = 0.0;
1838  double delta_angle = 0.0;
1839  wxPoint center;
1840 
1841  int width = w.width.ToPcbUnits();
1842  if( width < m_min_trace )
1843  m_min_trace = width;
1844 
1845  if( w.curve )
1846  {
1847  center = ConvertArcCenter(
1848  wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
1849  wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
1850  *w.curve );
1851 
1852  angle = DEG2RAD( *w.curve );
1853 
1854  end_angle = atan2( kicad_y( w.y2 ) - center.y,
1855  kicad_x( w.x2 ) - center.x );
1856 
1857  radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
1858  pow( center.y - kicad_y( w.y1 ), 2 ) );
1859 
1860  // If we are curving, we need at least 2 segments otherwise
1861  // delta_angle == angle
1862  int segments = std::max( 2, GetArcToSegmentCount( KiROUND( radius ),
1863  ARC_HIGH_DEF, *w.curve ) - 1 );
1864  delta_angle = angle / segments;
1865  }
1866 
1867  while( fabs( angle ) > fabs( delta_angle ) )
1868  {
1869  wxASSERT( radius > 0.0 );
1870  wxPoint end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
1871  KiROUND( radius * sin( end_angle + angle ) + center.y ) );
1872 
1873  TRACK* t = new TRACK( m_board );
1874 
1875  t->SetTimeStamp( EagleTimeStamp( netItem ) + int( RAD2DEG( angle ) ) );
1876  t->SetPosition( start );
1877  t->SetEnd( end );
1878  t->SetWidth( width );
1879  t->SetLayer( layer );
1880  t->SetNetCode( netCode );
1881 
1882  m_board->m_Track.Insert( t, NULL );
1883 
1884  start = end;
1885  angle -= delta_angle;
1886  }
1887 
1888  TRACK* t = new TRACK( m_board );
1889 
1890  t->SetTimeStamp( EagleTimeStamp( netItem ) );
1891  t->SetPosition( start );
1892  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
1893  t->SetWidth( width );
1894  t->SetLayer( layer );
1895  t->SetNetCode( netCode );
1896 
1897  m_board->m_Track.Insert( t, NULL );
1898  }
1899  else
1900  {
1901  // put non copper wires where the sun don't shine.
1902  }
1903 
1904  m_xpath->pop();
1905  }
1906 
1907  else if( itemName == "via" )
1908  {
1909  m_xpath->push( "via" );
1910  EVIA v( netItem );
1911 
1912  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
1913  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
1914 
1915  if( IsCopperLayer( layer_front_most ) &&
1916  IsCopperLayer( layer_back_most ) )
1917  {
1918  int kidiam;
1919  int drillz = v.drill.ToPcbUnits();
1920  VIA* via = new VIA( m_board );
1921  m_board->m_Track.Insert( via, NULL );
1922 
1923  via->SetLayerPair( layer_front_most, layer_back_most );
1924 
1925  if( v.diam )
1926  {
1927  kidiam = v.diam->ToPcbUnits();
1928  via->SetWidth( kidiam );
1929  }
1930  else
1931  {
1932  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
1933  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
1934  kidiam = KiROUND( drillz + 2 * annulus );
1935  via->SetWidth( kidiam );
1936  }
1937 
1938  via->SetDrill( drillz );
1939 
1940  // make sure the via diameter respects the restring rules
1941 
1942  if( !v.diam || via->GetWidth() <= via->GetDrill() )
1943  {
1944  double annulus = Clamp( m_rules->rlMinViaOuter,
1945  (double)( via->GetWidth() / 2 - via->GetDrill() ), m_rules->rlMaxViaOuter );
1946  via->SetWidth( drillz + 2 * annulus );
1947  }
1948 
1949  if( kidiam < m_min_via )
1950  m_min_via = kidiam;
1951 
1952  if( drillz < m_min_via_hole )
1953  m_min_via_hole = drillz;
1954 
1955  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
1956  via->SetViaType( VIA_THROUGH );
1957  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
1958  via->SetViaType( VIA_MICROVIA );
1959  else
1960  via->SetViaType( VIA_BLIND_BURIED );
1961 
1962  via->SetTimeStamp( EagleTimeStamp( netItem ) );
1963 
1964  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
1965 
1966  via->SetPosition( pos );
1967  via->SetEnd( pos );
1968 
1969  via->SetNetCode( netCode );
1970  }
1971 
1972  m_xpath->pop();
1973  }
1974 
1975  else if( itemName == "contactref" )
1976  {
1977  m_xpath->push( "contactref" );
1978  // <contactref element="RN1" pad="7"/>
1979 
1980  const wxString& reference = netItem->GetAttribute( "element" );
1981  const wxString& pad = netItem->GetAttribute( "pad" );
1982  wxString key = makeKey( reference, pad ) ;
1983 
1984  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, netName.c_str() );)
1985 
1986  m_pads_to_nets[ key ] = ENET( netCode, netName );
1987 
1988  m_xpath->pop();
1989 
1990  sawPad = true;
1991  }
1992 
1993  else if( itemName == "polygon" )
1994  {
1995  m_xpath->push( "polygon" );
1996 
1997  EPOLYGON p( netItem );
1998  PCB_LAYER_ID layer = kicad_layer( p.layer );
1999 
2000  if( IsCopperLayer( layer ) )
2001  {
2002  // use a "netcode = 0" type ZONE:
2003  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
2004  m_board->Add( zone, ADD_APPEND );
2005  zones.push_back( zone );
2006 
2007  zone->SetTimeStamp( EagleTimeStamp( netItem ) );
2008  zone->SetLayer( layer );
2009  zone->SetNetCode( netCode );
2010 
2011  // Get the first vertex and iterate
2012  wxXmlNode* vertex = netItem->GetChildren();
2013  std::vector<EVERTEX> vertices;
2014 
2015  // Create a circular vector of vertices
2016  // The "curve" parameter indicates a curve from the current
2017  // to the next vertex, so we keep the first at the end as well
2018  // to allow the curve to link back
2019  while( vertex )
2020  {
2021  if( vertex->GetName() == "vertex" )
2022  vertices.push_back( EVERTEX( vertex ) );
2023 
2024  vertex = vertex->GetNext();
2025  }
2026 
2027  vertices.push_back( vertices[0] );
2028 
2029  for( size_t i = 0; i < vertices.size() - 1; i++ )
2030  {
2031  EVERTEX v1 = vertices[i];
2032 
2033  // Append the corner
2034  zone->AppendCorner( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ), -1 );
2035 
2036  if( v1.curve )
2037  {
2038  EVERTEX v2 = vertices[i + 1];
2039  wxPoint center = ConvertArcCenter(
2040  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
2041  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
2042  double angle = DEG2RAD( *v1.curve );
2043  double end_angle = atan2( kicad_y( v2.y ) - center.y,
2044  kicad_x( v2.x ) - center.x );
2045  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
2046  + pow( center.y - kicad_y( v1.y ), 2 ) );
2047 
2048  // If we are curving, we need at least 2 segments otherwise
2049  // delta_angle == angle
2050  double delta_angle = angle / std::max(
2051  2, GetArcToSegmentCount( KiROUND( radius ),
2052  ARC_HIGH_DEF, *v1.curve ) - 1 );
2053 
2054  for( double a = end_angle + angle;
2055  fabs( a - end_angle ) > fabs( delta_angle );
2056  a -= delta_angle )
2057  {
2058  zone->AppendCorner(
2059  wxPoint( KiROUND( radius * cos( a ) ),
2060  KiROUND( radius * sin( a ) ) ) + center,
2061  -1 );
2062  }
2063  }
2064  }
2065 
2066  // If the pour is a cutout it needs to be set to a keepout
2067  if( p.pour == EPOLYGON::CUTOUT )
2068  {
2069  zone->SetIsKeepout( true );
2070  zone->SetDoNotAllowCopperPour( true );
2072  }
2073 
2074  // if spacing is set the zone should be hatched
2075  // However, use the default hatch step, p.spacing value has no meaning for Kicad
2076  // TODO: see if this parameter is related to a grid fill option.
2077  if( p.spacing )
2079 
2080  // clearances, etc.
2081  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
2082  zone->SetMinThickness( p.width.ToPcbUnits() );
2083 
2084  // FIXME: KiCad zones have very rounded corners compared to eagle.
2085  // This means that isolation amounts that work well in eagle
2086  // tend to make copper intrude in soldermask free areas around pads.
2087  if( p.isolate )
2088  {
2089  zone->SetZoneClearance( p.isolate->ToPcbUnits() );
2090  } else
2091  {
2092  zone->SetZoneClearance( 0 );
2093  }
2094 
2095  // missing == yes per DTD.
2096  bool thermals = !p.thermals || *p.thermals;
2098 
2099  if( thermals )
2100  {
2101  // FIXME: eagle calculates dimensions for thermal spokes
2102  // based on what the zone is connecting to.
2103  // (i.e. width of spoke is half of the smaller side of an smd pad)
2104  // This is a basic workaround
2105  zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
2106  zone->SetThermalReliefCopperBridge( p.width.ToPcbUnits() + 50000 );
2107  }
2108 
2109  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
2110  zone->SetPriority( rank );
2111  }
2112 
2113  m_xpath->pop(); // "polygon"
2114  }
2115 
2116  netItem = netItem->GetNext();
2117  }
2118 
2119  if( zones.size() && !sawPad )
2120  {
2121  // KiCad does not support an unconnected zone with its own non-zero netcode,
2122  // but only when assigned netcode = 0 w/o a name...
2123  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2124  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2125 
2126  // therefore omit this signal/net.
2127  }
2128  else
2129  netCode++;
2130 
2131  // Get next signal
2132  net = net->GetNext();
2133  }
2134 
2135  m_xpath->pop(); // "signals.signal"
2136 }
Eagle vertex.
Definition: eagle_parser.h:745
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:69
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
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
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:177
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:456
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:428
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:118
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
ECOORD y
Definition: eagle_parser.h:748
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
double RAD2DEG(double rad)
Definition: trigo.h:200
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:186
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:180
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:67
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:470
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:164
void SetWidth(int aWidth)
Definition: class_track.h:115
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:95
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:181
static wxString makeKey(const wxString &aFirst, const wxString &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:202
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
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...
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:193
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
std::vector< ZONE_CONTAINER * > ZONES
non-owning container
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:179
Eagle net.
Definition: eagle_parser.h:461
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:749
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:180
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:608
Eagle via.
Definition: eagle_parser.h:555
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
ECOORD x
Definition: eagle_parser.h:747
double DEG2RAD(double deg)
Definition: trigo.h:199
#define max(a, b)
Definition: auxiliary.h:86
int GetWidth() const
Definition: class_track.h:116
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:112
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:463
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:503
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:169
Eagle wire.
Definition: eagle_parser.h:499
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)
DLIST< TRACK > m_Track
Definition: class_board.h:246
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:756
void pop()
Definition: eagle_parser.h:124
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:607
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:196
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:199
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:68
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
Use thermal relief for pads.
Definition: zones.h:58
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:177
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
pads are covered by copper
Definition: zones.h:59
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
MODULE * EAGLE_PLUGIN::makeModule ( wxXmlNode *  aPackage,
const wxString &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 1207 of file eagle_plugin.cpp.

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

Referenced by loadLibrary().

1208 {
1209  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1210 
1211  m->SetFPID( LIB_ID( UTF8( aPkgName ) ) );
1212 
1213  // Get the first package item and iterate
1214  wxXmlNode* packageItem = aPackage->GetChildren();
1215 
1216  while( packageItem )
1217  {
1218  const wxString& itemName = packageItem->GetName();
1219 
1220  if( itemName == "description" )
1221  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1222 
1223  else if( itemName == "wire" )
1224  packageWire( m.get(), packageItem );
1225 
1226  else if( itemName == "pad" )
1227  packagePad( m.get(), packageItem );
1228 
1229  else if( itemName == "text" )
1230  packageText( m.get(), packageItem );
1231 
1232  else if( itemName == "rectangle" )
1233  packageRectangle( m.get(), packageItem );
1234 
1235  else if( itemName == "polygon" )
1236  packagePolygon( m.get(), packageItem );
1237 
1238  else if( itemName == "circle" )
1239  packageCircle( m.get(), packageItem );
1240 
1241  else if( itemName == "hole" )
1242  packageHole( m.get(), packageItem );
1243 
1244  else if( itemName == "smd" )
1245  packageSMD( m.get(), packageItem );
1246 
1247  packageItem = packageItem->GetNext();
1248  }
1249 
1250  return m.release();
1251 }
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:177
void packageHole(MODULE *aModule, wxXmlNode *aTree) const
void packageText(MODULE *aModule, wxXmlNode *aTree) const
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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 1077 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().

1079 {
1080  if( e.rot )
1081  {
1082  if( e.rot->mirror )
1083  {
1084  double orientation = e.rot->degrees + 180.0;
1085  m->SetOrientation( orientation * 10 );
1086  m->Flip( m->GetPosition() );
1087  }
1088  else
1089  m->SetOrientation( e.rot->degrees * 10 );
1090  }
1091 
1092  orientModuleText( m, e, &m->Reference(), nameAttr );
1093  orientModuleText( m, e, &m->Value(), valueAttr );
1094 }
bool mirror
Definition: eagle_parser.h:480
TEXTE_MODULE & Reference()
Definition: class_module.h:502
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
opt_erot rot
Definition: eagle_parser.h:806
double degrees
Definition: eagle_parser.h:482
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
void SetOrientation(double newangle)
const wxPoint GetPosition() const override
Definition: class_module.h:182
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 1097 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().

1099 {
1100  // Smashed part ?
1101  if( aAttr )
1102  { // Yes
1103  const EATTR& a = *aAttr;
1104 
1105  if( a.value )
1106  {
1107  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1108  }
1109 
1110  if( a.x && a.y ) // OPT
1111  {
1112  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1113  txt->SetTextPos( pos );
1114  }
1115 
1116  // Even though size and ratio are both optional, I am not seeing
1117  // a case where ratio is present but size is not.
1118  double ratio = 8;
1119  wxSize fontz = txt->GetTextSize();
1120 
1121  if( a.size )
1122  {
1123  fontz = kicad_fontz( *a.size );
1124  txt->SetTextSize( fontz );
1125 
1126  if( a.ratio )
1127  ratio = *a.ratio;
1128  }
1129 
1130  int lw = int( fontz.y * ratio / 100 );
1131  txt->SetThickness( lw );
1132 
1133  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1134 
1135  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1136  // present, and this zero rotation becomes an override to the
1137  // package's text field. If they did not want zero, they specify
1138  // what they want explicitly.
1139  double degrees = a.rot ? a.rot->degrees : 0;
1140  double orient; // relative to parent
1141 
1142  int sign = 1;
1143  bool spin = false;
1144 
1145  if( a.rot )
1146  {
1147  spin = a.rot->spin;
1148  sign = a.rot->mirror ? -1 : 1;
1149  txt->SetMirrored( a.rot->mirror );
1150  }
1151 
1152  if( degrees == 90 || degrees == 0 || spin )
1153  {
1154  orient = degrees - m->GetOrientation() / 10;
1155  txt->SetTextAngle( sign * orient * 10 );
1156  }
1157  else if( degrees == 180 )
1158  {
1159  orient = 0 - m->GetOrientation() / 10;
1160  txt->SetTextAngle( sign * orient * 10 );
1161  align = ETEXT::TOP_RIGHT;
1162  }
1163  else if( degrees == 270 )
1164  {
1165  orient = 90 - m->GetOrientation() / 10;
1166  align = ETEXT::TOP_RIGHT;
1167  txt->SetTextAngle( sign * orient * 10 );
1168  }
1169  else
1170  {
1171  orient = 90 - degrees - m->GetOrientation() / 10;
1172  txt->SetTextAngle( sign * orient * 10 );
1173  }
1174 
1175  switch( align )
1176  {
1177  case ETEXT::TOP_RIGHT:
1180  break;
1181 
1182  case ETEXT::BOTTOM_LEFT:
1185  break;
1186 
1187  default:
1188  ;
1189  }
1190  }
1191  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1192  {
1193  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1194 
1195  // @todo there are a few more cases than these to contend with:
1196  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1197  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1198  {
1199  // ETEXT::TOP_RIGHT:
1202  }
1203  }
1204 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
bool mirror
Definition: eagle_parser.h:480
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:221
double degrees
Definition: eagle_parser.h:482
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
#define abs(a)
Definition: auxiliary.h:84
opt_erot rot
Definition: eagle_parser.h:611
double GetTextAngle() const
Definition: eda_text.h:162
opt_ecoord y
Definition: eagle_parser.h:607
double GetOrientation() const
Definition: class_module.h:187
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
opt_wxString value
Definition: eagle_parser.h:605
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:602
opt_ecoord x
Definition: eagle_parser.h:606
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
bool IsMirrored() const
Definition: eda_text.h:177
opt_double ratio
Definition: eagle_parser.h:610
void SetTextAngle(double aAngle)
bool spin
Definition: eagle_parser.h:481
const wxSize & GetTextSize() const
Definition: eda_text.h:213
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
opt_ecoord size
Definition: eagle_parser.h:608
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
void EAGLE_PLUGIN::packageCircle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1619 of file eagle_plugin.cpp.

References UTF8::c_str(), Cmts_User, Dwgs_User, EagleTimeStamp(), Format(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), MODULE::GraphicalItemsList(), IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, DLIST< T >::PushBack(), ECIRCLE::radius, S_CIRCLE, EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), ECOORD::ToPcbUnits(), UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

Referenced by makeModule().

1620 {
1621  ECIRCLE e( aTree );
1622  PCB_LAYER_ID layer = kicad_layer( e.layer );
1623 
1624  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1625  {
1626  wxLogMessage( wxString::Format(
1627  "Unsupported circle on copper layer in package %s.\nMoving to Dwgs.User layer.",
1628  aModule->GetFPID().GetLibItemName().c_str() ) );
1629  layer = Dwgs_User;
1630  }
1631 
1632  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1633 
1634  aModule->GraphicalItemsList().PushBack( gr );
1635 
1636  gr->SetWidth( e.width.ToPcbUnits() );
1637 
1638  switch( (int) layer )
1639  {
1640  case UNDEFINED_LAYER: layer = Cmts_User; break;
1641  /*
1642  case Eco1_User: layer = F_SilkS; break;
1643  case Eco2_User: layer = B_SilkS; break;
1644  */
1645  default:
1646  break;
1647  }
1648 
1649  gr->SetLayer( layer );
1650  gr->SetTimeStamp( EagleTimeStamp( aTree ) );
1651  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1652  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
1653  gr->SetDrawCoord();
1654 }
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.
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
const LIB_ID & GetFPID() const
Definition: class_module.h:191
PCB_LAYER_ID
A quick note on layer IDs:
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
Eagle circle.
Definition: eagle_parser.h:570
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
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 char * c_str() const
Definition: utf8.h:107
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageHole ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1657 of file eagle_plugin.cpp.

References LSET::AllCuMask(), EHOLE::drill, MODULE::GetPosition(), 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(), ECOORD::ToPcbUnits(), EHOLE::x, and EHOLE::y.

Referenced by makeModule().

1658 {
1659  EHOLE e( aTree );
1660 
1661  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1662  D_PAD* pad = new D_PAD( aModule );
1663  aModule->PadsList().PushBack( pad );
1664 
1665  pad->SetShape( PAD_SHAPE_CIRCLE );
1667 
1668  // Mechanical purpose only:
1669  // no offset, no net name, no pad name allowed
1670  // pad->SetOffset( wxPoint( 0, 0 ) );
1671  // pad->SetName( wxEmptyString );
1672 
1673  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1674 
1675  pad->SetPos0( padpos );
1676  pad->SetPosition( padpos + aModule->GetPosition() );
1677 
1678  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
1679 
1680  pad->SetDrillSize( sz );
1681  pad->SetSize( sz );
1682 
1683  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
1684 }
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:673
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
Eagle hole element.
Definition: eagle_parser.h:785
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:262
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
const wxPoint GetPosition() const override
Definition: class_module.h:182
void EAGLE_PLUGIN::packagePad ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1302 of file eagle_plugin.cpp.

References LSET::AllCuMask(), B_Mask, Clamp(), EROT::degrees, EPAD::diameter, EPAD::drill, F_Mask, D_PAD::GetDrillSize(), D_PAD::GetShape(), D_PAD::GetSize(), KiROUND(), EPAD::LONG, m_rules, 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_COMMON::rot, EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, ECOORD::ToPcbUnits(), and transferPad().

Referenced by makeModule().

1303 {
1304  // this is thru hole technology here, no SMDs
1305  EPAD e( aTree );
1306 
1307  D_PAD* pad = new D_PAD( aModule );
1308  aModule->PadsList().PushBack( pad );
1309  transferPad( e, pad );
1310 
1311  pad->SetDrillSize( wxSize( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() ) );
1312  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1313 
1314  if( e.shape )
1315  {
1316  switch( *e.shape )
1317  {
1318  case EPAD::ROUND:
1319  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1320  break;
1321 
1322  case EPAD::OCTAGON:
1323  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1324  // pad->SetShape( PAD_OCTAGON );
1325  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1326  break;
1327 
1328  case EPAD::LONG:
1329  pad->SetShape( PAD_SHAPE_OVAL );
1330  break;
1331 
1332  case EPAD::SQUARE:
1333  pad->SetShape( PAD_SHAPE_RECT );
1334  break;
1335 
1336  case EPAD::OFFSET:
1337  ; // don't know what to do here.
1338  }
1339  }
1340  else
1341  {
1342  // if shape is not present, our default is circle and that matches their default "round"
1343  }
1344 
1345  if( e.diameter )
1346  {
1347  int diameter = e.diameter->ToPcbUnits();
1348  pad->SetSize( wxSize( diameter, diameter ) );
1349  }
1350  else
1351  {
1352  double drillz = pad->GetDrillSize().x;
1353  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1354  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1355  int diameter = KiROUND( drillz + 2 * annulus );
1356  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1357  }
1358 
1359  if( pad->GetShape() == PAD_SHAPE_OVAL )
1360  {
1361  // The Eagle "long" pad is wider than it is tall,
1362  // m_elongation is percent elongation
1363  wxSize sz = pad->GetSize();
1364  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1365  pad->SetSize( sz );
1366  }
1367 
1368  if( e.rot )
1369  {
1370  pad->SetOrientation( e.rot->degrees * 10 );
1371  }
1372 }
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:673
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
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 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:163
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:65
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle thru hole pad.
Definition: eagle_parser.h:693
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:45
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
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:61
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:64
void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1532 of file eagle_plugin.cpp.

References PNS::angle(), UTF8::c_str(), ConvertArcCenter(), EVERTEX::curve, DEG2RAD(), Dwgs_User, EagleTimeStamp(), Format(), GetArcToSegmentCount(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), MODULE::GraphicalItemsList(), i, IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, max, DLIST< T >::PushBack(), S_POLYGON, EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), wxPoint::x, EVERTEX::x, wxPoint::y, and EVERTEX::y.

Referenced by makeModule().

1533 {
1534  EPOLYGON p( aTree );
1535  PCB_LAYER_ID layer = kicad_layer( p.layer );
1536 
1537  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1538  {
1539  wxLogMessage( wxString::Format(
1540  "Unsupported polygon on copper layer in package %s.\nMoving to Dwgs.User layer.",
1541  aModule->GetFPID().GetLibItemName().c_str() ) );
1542  layer = Dwgs_User;
1543  }
1544 
1545  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1546  aModule->GraphicalItemsList().PushBack( dwg );
1547 
1548  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1549 
1550  dwg->SetLayer( layer );
1551 
1552  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1553 
1554  std::vector<wxPoint> pts;
1555  // TODO: I think there's no way to know a priori the number of children in wxXmlNode :()
1556  // pts.reserve( aTree.size() );
1557 
1558  // Get the first vertex and iterate
1559  wxXmlNode* vertex = aTree->GetChildren();
1560  std::vector<EVERTEX> vertices;
1561 
1562  // Create a circular vector of vertices
1563  // The "curve" parameter indicates a curve from the current
1564  // to the next vertex, so we keep the first at the end as well
1565  // to allow the curve to link back
1566  while( vertex )
1567  {
1568  if( vertex->GetName() == "vertex" )
1569  vertices.push_back( EVERTEX( vertex ) );
1570 
1571  vertex = vertex->GetNext();
1572  }
1573 
1574  vertices.push_back( vertices[0] );
1575 
1576  for( size_t i = 0; i < vertices.size() - 1; i++ )
1577  {
1578  EVERTEX v1 = vertices[i];
1579 
1580  // Append the corner
1581  pts.push_back( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ) );
1582 
1583  if( v1.curve )
1584  {
1585  EVERTEX v2 = vertices[i + 1];
1586  wxPoint center = ConvertArcCenter(
1587  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1588  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1589  double angle = DEG2RAD( *v1.curve );
1590  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1591  kicad_x( v2.x ) - center.x );
1592  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1593  + pow( center.y - kicad_y( v1.y ), 2 ) );
1594 
1595  // If we are curving, we need at least 2 segments otherwise
1596  // delta_angle == angle
1597  double delta_angle = angle / std::max(
1598  2, GetArcToSegmentCount( KiROUND( radius ),
1599  ARC_HIGH_DEF, *v1.curve ) - 1 );
1600 
1601  for( double a = end_angle + angle;
1602  fabs( a - end_angle ) > fabs( delta_angle );
1603  a -= delta_angle )
1604  {
1605  pts.push_back(
1606  wxPoint( KiROUND( radius * cos( a ) ),
1607  KiROUND( radius * sin( a ) ) ) + center );
1608  }
1609  }
1610  }
1611 
1612  dwg->SetPolyPoints( pts );
1613  dwg->SetStart0( *pts.begin() );
1614  dwg->SetEnd0( pts.back() );
1615  dwg->SetDrawCoord();
1616 }
Eagle vertex.
Definition: eagle_parser.h:745
void SetEnd0(const wxPoint &aPoint)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
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
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.
ECOORD y
Definition: eagle_parser.h:748
polygon (not yet used for tracks, but could be in microwave apps)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
const LIB_ID & GetFPID() const
Definition: class_module.h:191
PCB_LAYER_ID
A quick note on layer IDs:
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:749
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
ECOORD x
Definition: eagle_parser.h:747
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
double DEG2RAD(double deg)
Definition: trigo.h:199
#define max(a, b)
Definition: auxiliary.h:86
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
const char * c_str() const
Definition: utf8.h:107
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:756
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1489 of file eagle_plugin.cpp.

References UTF8::c_str(), EROT::degrees, Dwgs_User, EagleTimeStamp(), Format(), DRAWSEGMENT::GetCenter(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), MODULE::GraphicalItemsList(), IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), ERECT::layer, DLIST< T >::PushBack(), ERECT::rot, EDGE_MODULE::Rotate(), S_POLYGON, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), ERECT::x1, ERECT::x2, ERECT::y1, and ERECT::y2.

Referenced by makeModule().

1490 {
1491  ERECT r( aTree );
1492  PCB_LAYER_ID layer = kicad_layer( r.layer );
1493 
1494  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1495  {
1496  wxLogMessage( wxString::Format(
1497  "Unsupported rectangle on copper layer in package %s.\nMoving to Dwgs.User layer.",
1498  aModule->GetFPID().GetLibItemName().c_str() ) );
1499  layer = Dwgs_User;
1500  }
1501 
1502  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1503  aModule->GraphicalItemsList().PushBack( dwg );
1504 
1505  dwg->SetLayer( layer );
1506  dwg->SetWidth( 0 );
1507 
1508  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1509 
1510  std::vector<wxPoint> pts;
1511 
1512  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1513  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1514 
1515  pts.push_back( start );
1516  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1517  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1518  pts.push_back( end );
1519 
1520  dwg->SetPolyPoints( pts );
1521 
1522  dwg->SetStart0( start );
1523  dwg->SetEnd0( end );
1524 
1525  if( r.rot )
1526  {
1527  dwg->Rotate( dwg->GetCenter(), r.rot->degrees * 10 );
1528  }
1529 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
const wxPoint GetCenter() const override
Function GetCenter()
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)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
const LIB_ID & GetFPID() const
Definition: class_module.h:191
PCB_LAYER_ID
A quick note on layer IDs:
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
Eagle XML rectangle in binary.
Definition: eagle_parser.h:583
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
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 char * c_str() const
Definition: utf8.h:107
void SetStart0(const wxPoint &aPoint)
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1687 of file eagle_plugin.cpp.

References B_Cu, B_Mask, B_Paste, Clamp(), ESMD::cream, EROT::degrees, ESMD::dx, ESMD::dy, F_Cu, F_Mask, F_Paste, D_PAD::GetLayerSet(), IsCopperLayer(), kicad_layer(), ESMD::layer, m_rules, min, ERULES::mlMaxCreamFrame, ERULES::mlMinCreamFrame, ERULES::mvCreamFrame, PAD_ATTRIB_SMD, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, MODULE::PadsList(), DLIST< T >::PushBack(), EPAD_COMMON::rot, ESMD::roundness, D_PAD::SetAttribute(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), D_PAD::SetLocalSolderPasteMargin(), D_PAD::SetOrientation(), D_PAD::SetRoundRectRadiusRatio(), D_PAD::SetShape(), D_PAD::SetSize(), ERULES::srMaxRoundness, ERULES::srMinRoundness, ERULES::srRoundness, ECOORD::ToPcbUnits(), and transferPad().

Referenced by makeModule().

1688 {
1689  ESMD e( aTree );
1690  PCB_LAYER_ID layer = kicad_layer( e.layer );
1691 
1692  if( !IsCopperLayer( layer ) )
1693  return;
1694 
1695  D_PAD* pad = new D_PAD( aModule );
1696  aModule->PadsList().PushBack( pad );
1697  transferPad( e, pad );
1698 
1699  pad->SetShape( PAD_SHAPE_RECT );
1700  pad->SetAttribute( PAD_ATTRIB_SMD );
1701 
1702  wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
1703  pad->SetSize( padSize );
1704  pad->SetLayer( layer );
1705 
1706  const LSET front( 3, F_Cu, F_Paste, F_Mask );
1707  const LSET back( 3, B_Cu, B_Paste, B_Mask );
1708 
1709  if( layer == F_Cu )
1710  pad->SetLayerSet( front );
1711  else if( layer == B_Cu )
1712  pad->SetLayerSet( back );
1713 
1714  int minPadSize = std::min( padSize.x, padSize.y );
1715 
1716  // Rounded rectangle pads
1717  int roundRadius = Clamp( m_rules->srMinRoundness * 2,
1718  (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
1719 
1720  if( e.roundness || roundRadius > 0 )
1721  {
1722  double roundRatio = (double) roundRadius / minPadSize / 2.0;
1723 
1724  // Eagle uses a different definition of roundness, hence division by 200
1725  if( e.roundness )
1726  roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
1727 
1728  pad->SetShape( PAD_SHAPE_ROUNDRECT );
1729  pad->SetRoundRectRadiusRatio( roundRatio );
1730  }
1731 
1732  if( e.rot )
1733  {
1734  pad->SetOrientation( e.rot->degrees * 10 );
1735  }
1736 
1738  (int) ( m_rules->mvCreamFrame * minPadSize ),
1739  m_rules->mlMaxCreamFrame ) );
1740 
1741  // Solder paste (only for SMD pads)
1742  if( e.cream && *e.cream == false ) // enabled by default
1743  {
1744  if( layer == F_Cu )
1745  pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
1746  else if( layer == B_Cu )
1747  pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
1748  }
1749 }
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
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
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:58
Eagle SMD pad.
Definition: eagle_parser.h:714
void SetRoundRectRadiusRatio(double aRadiusScale)
has meaning only for rounded rect pads Set the scaling factor between the smaller Y or Y size and the...
Definition: class_pad.h:627
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.
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:57
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
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.
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_pad.h:417
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:59
#define min(a, b)
Definition: auxiliary.h:85
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:51
void EAGLE_PLUGIN::packageText ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1375 of file eagle_plugin.cpp.

References ETEXT::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, UTF8::c_str(), ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Cmts_User, EROT::degrees, Dwgs_User, EagleTimeStamp(), Format(), FROM_UTF8(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), MODULE::GetPosition(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, MODULE::GraphicalItemsList(), IsCopperLayer(), 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, ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, ECOORD::ToPcbUnits(), UNDEFINED_LAYER, MODULE::Value(), ETEXT::x, and ETEXT::y.

Referenced by makeModule().

1376 {
1377  ETEXT t( aTree );
1378  PCB_LAYER_ID layer = kicad_layer( t.layer );
1379 
1380  if( IsCopperLayer( layer ) ) // skip copper texts
1381  {
1382  wxLogMessage( wxString::Format(
1383  "Unsupported text on copper layer in package %s.\nMoving to Dwgs.User layer.",
1384  aModule->GetFPID().GetLibItemName().c_str() ) );
1385  layer = Dwgs_User;
1386  }
1387 
1388  if( layer == UNDEFINED_LAYER )
1389  {
1390  layer = Cmts_User;
1391  }
1392 
1393  TEXTE_MODULE* txt;
1394 
1395  if( t.text == ">NAME" || t.text == ">name" )
1396  txt = &aModule->Reference();
1397  else if( t.text == ">VALUE" || t.text == ">value" )
1398  txt = &aModule->Value();
1399  else
1400  {
1401  // FIXME: graphical text items are rotated for some reason.
1402  txt = new TEXTE_MODULE( aModule );
1403  aModule->GraphicalItemsList().PushBack( txt );
1404  }
1405 
1406  txt->SetTimeStamp( EagleTimeStamp( aTree ) );
1407  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1408 
1409  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1410 
1411  txt->SetTextPos( pos );
1412  txt->SetPos0( pos - aModule->GetPosition() );
1413 
1414  txt->SetLayer( layer );
1415  txt->SetTextSize( kicad_fontz( t.size ) );
1416 
1417  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1418 
1419  txt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
1420 
1421  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1422 
1423  // An eagle package is never rotated, the DTD does not allow it.
1424  // angle -= aModule->GetOrienation();
1425 
1426  if( t.rot )
1427  {
1428  int sign = t.rot->mirror ? -1 : 1;
1429  txt->SetMirrored( t.rot->mirror );
1430 
1431  double degrees = t.rot->degrees;
1432 
1433  if( degrees == 90 || t.rot->spin )
1434  txt->SetTextAngle( sign * degrees * 10 );
1435  else if( degrees == 180 )
1436  align = ETEXT::TOP_RIGHT;
1437  else if( degrees == 270 )
1438  {
1439  align = ETEXT::TOP_RIGHT;
1440  txt->SetTextAngle( sign * 90 * 10 );
1441  }
1442  }
1443 
1444  switch( align )
1445  {
1446  case ETEXT::CENTER:
1447  // this was the default in pcbtxt's constructor
1448  break;
1449 
1450  case ETEXT::CENTER_LEFT:
1452  break;
1453 
1454  case ETEXT::CENTER_RIGHT:
1456  break;
1457 
1458  case ETEXT::TOP_CENTER:
1460  break;
1461 
1462  case ETEXT::TOP_LEFT:
1465  break;
1466 
1467  case ETEXT::TOP_RIGHT:
1470  break;
1471 
1472  case ETEXT::BOTTOM_CENTER:
1474  break;
1475 
1476  case ETEXT::BOTTOM_LEFT:
1479  break;
1480 
1481  case ETEXT::BOTTOM_RIGHT:
1484  break;
1485  }
1486 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
TEXTE_MODULE & Reference()
Definition: class_module.h:502
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.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
Eagle text element.
Definition: eagle_parser.h:645
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
const LIB_ID & GetFPID() const
Definition: class_module.h:191
PCB_LAYER_ID
A quick note on layer IDs:
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
void SetPos0(const wxPoint &aPos)
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
const char * c_str() const
Definition: utf8.h:107
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
void SetTextAngle(double aAngle)
const wxPoint GetPosition() const override
Definition: class_module.h:182
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
void EAGLE_PLUGIN::packageWire ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1254 of file eagle_plugin.cpp.

References UTF8::c_str(), ConvertArcCenter(), EWIRE::curve, Dwgs_User, Format(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), MODULE::GraphicalItemsList(), IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, DLIST< T >::PushBack(), S_ARC, S_SEGMENT, DRAWSEGMENT::SetAngle(), EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), DRAWSEGMENT::SetWidth(), ECOORD::ToMm(), ECOORD::ToPcbUnits(), EWIRE::width, EWIRE::x1, EWIRE::x2, EWIRE::y1, and EWIRE::y2.

Referenced by makeModule().

1255 {
1256  EWIRE w( aTree );
1257  PCB_LAYER_ID layer = kicad_layer( w.layer );
1258 
1259  if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
1260  {
1261  wxLogMessage( wxString::Format(
1262  "Line on copper layer in package %s (%f mm, %f mm) (%f mm, %f mm)."
1263  "\nMoving to Dwgs.User layer",
1264  aModule->GetFPID().GetLibItemName().c_str(), w.x1.ToMm(), w.y1.ToMm(),
1265  w.x2.ToMm(), w.y2.ToMm() ) );
1266  layer = Dwgs_User;
1267  }
1268 
1269  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1270  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1271  int width = w.width.ToPcbUnits();
1272 
1273  // FIXME: the cap attribute is ignored because kicad can't create lines
1274  // with flat ends.
1275  EDGE_MODULE* dwg;
1276 
1277  if( !w.curve )
1278  {
1279  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1280 
1281  dwg->SetStart0( start );
1282  dwg->SetEnd0( end );
1283  }
1284  else
1285  {
1286  dwg = new EDGE_MODULE( aModule, S_ARC );
1287  wxPoint center = ConvertArcCenter( start, end, *w.curve );
1288 
1289  dwg->SetStart0( center );
1290  dwg->SetEnd0( start );
1291  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1292  }
1293 
1294  dwg->SetLayer( layer );
1295  dwg->SetWidth( width );
1296  dwg->SetDrawCoord();
1297 
1298  aModule->GraphicalItemsList().PushBack( dwg );
1299 }
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
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
const LIB_ID & GetFPID() const
Definition: class_module.h:191
PCB_LAYER_ID
A quick note on layer IDs:
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
Arcs (with rounded ends)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
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
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
const char * c_str() const
Definition: utf8.h:107
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
Eagle wire.
Definition: eagle_parser.h:499
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.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
void SetWidth(int aWidth)
const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 183 of file eagle_plugin.cpp.

184 {
185  return wxT( "Eagle" );
186 }
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, and CLIPBOARD_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
void EAGLE_PLUGIN::transferPad ( const EPAD_COMMON aEaglePad,
D_PAD aPad 
) const
private

Handles common pad properties

Definition at line 1752 of file eagle_plugin.cpp.

References Clamp(), FROM_UTF8(), MODULE::GetOrientation(), D_PAD::GetParent(), MODULE::GetPosition(), D_PAD::GetSize(), kicad_x(), kicad_y(), m_rules, min, ERULES::mlMaxStopFrame, ERULES::mlMinStopFrame, ERULES::mvStopFrame, EPAD_COMMON::name, PAD_ZONE_CONN_FULL, RotatePoint(), D_PAD::SetLocalSolderMaskMargin(), D_PAD::SetName(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetZoneConnection(), EPAD_COMMON::stop, EPAD_COMMON::thermals, EPAD_COMMON::x, and EPAD_COMMON::y.

Referenced by packagePad(), and packageSMD().

1753 {
1754  aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) );
1755 
1756  // pad's "Position" is not relative to the module's,
1757  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1758  wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
1759  aPad->SetPos0( padPos );
1760 
1761  // Solder mask
1762  const wxSize& padSize( aPad->GetSize() );
1763 
1764  if( !aEaglePad.stop || !*aEaglePad.stop ) // enabled by default
1765  {
1767  (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
1768  m_rules->mlMaxStopFrame ) );
1769  }
1770 
1771  // Solid connection to copper zones
1772  if( aEaglePad.thermals && !*aEaglePad.thermals )
1774 
1775  MODULE* module = aPad->GetParent();
1776  wxCHECK( module, /* void */ );
1777  RotatePoint( &padPos, module->GetOrientation() );
1778  aPad->SetPosition( padPos + module->GetPosition() );
1779 }
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
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
MODULE * GetParent() const
Definition: class_pad.h:162
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:52
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
wxString name
Definition: eagle_parser.h:682
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
opt_bool thermals
Definition: eagle_parser.h:686
void SetZoneConnection(ZoneConnection aType)
Definition: class_pad.h:476
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:182
double GetOrientation() const
Definition: class_module.h:187
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_pad.h:411
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:50
opt_bool stop
Definition: eagle_parser.h:685
const wxPoint GetPosition() const override
Definition: class_module.h:182
#define min(a, b)
Definition: auxiliary.h:85
pads are covered by copper
Definition: zones.h:59
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:53

Member Data Documentation

BOARD* EAGLE_PLUGIN::m_board
private

which BOARD is being worked on, no ownership here

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

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

std::map<int, ELAYER> EAGLE_PLUGIN::m_eagleLayers
private

Eagle layers data stored by the layer number.

Definition at line 161 of file eagle_plugin.h.

Referenced by eagle_layer_name(), and loadLayerDefs().

int EAGLE_PLUGIN::m_hole_count
private

generates unique module names from eagle "hole"s.

Definition at line 167 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 183 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 179 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 180 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 181 of file eagle_plugin.h.

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

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 184 of file eagle_plugin.h.

Referenced by cacheLib().

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

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

Referenced by centerBoard(), and init().

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 163 of file eagle_plugin.h.

Referenced by init(), Load(), loadDesignRules(), loadSignals(), packagePad(), packageSMD(), transferPad(), 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 171 of file eagle_plugin.h.

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

XPATH* EAGLE_PLUGIN::m_xpath
private

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

Definition at line 164 of file eagle_plugin.h.

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


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