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 const MODULEGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
virtual bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function FootprintExists check for the existence of a footprint. 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)
 
ZONE_CONTAINERloadPolygon (wxXmlNode *aPolyNode)
 Loads a copper or keepout polygon and adds it to the board. More...
 
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, bool aCenter) const
 Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTree - The Eagle XML node that is of type "hole" @parameter aCenter - If true, center the hole in the module and offset the module position. More...
 
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 117 of file eagle_plugin.h.

Member Typedef Documentation

◆ BIU

typedef int EAGLE_PLUGIN::BIU

Definition at line 161 of file eagle_plugin.h.

◆ EITER

typedef ELAYERS::const_iterator EAGLE_PLUGIN::EITER
private

Definition at line 168 of file eagle_plugin.h.

◆ ELAYERS

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

Definition at line 167 of file eagle_plugin.h.

Constructor & Destructor Documentation

◆ EAGLE_PLUGIN()

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 182 of file eagle_plugin.cpp.

182  :
183  m_rules( new ERULES() ),
184  m_xpath( new XPATH() ),
185  m_mod_time( wxDateTime::Now() )
186 {
187  init( NULL );
188  clear_cu_map();
189 }
void clear_cu_map()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
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:174
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
wxDateTime m_mod_time
Definition: eagle_plugin.h:194

References clear_cu_map(), and init().

◆ ~EAGLE_PLUGIN()

EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 192 of file eagle_plugin.cpp.

193 {
194  deleteTemplates();
195  delete m_rules;
196  delete m_xpath;
197 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:174
void deleteTemplates()
Deletes the footprint templates list

References deleteTemplates(), m_rules, and m_xpath.

Member Function Documentation

◆ cacheLib()

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

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

Definition at line 2404 of file eagle_plugin.cpp.

2405 {
2406  try
2407  {
2408  wxDateTime modtime = getModificationTime( aLibPath );
2409 
2410  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2411  // cache if either of the wxDateTime objects are invalid or the last file modification
2412  // time differs from the current file modification time.
2413  bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
2414 
2415  if( aLibPath != m_lib_path || load )
2416  {
2417  wxXmlNode* doc;
2418  LOCALE_IO toggle; // toggles on, then off, the C locale.
2419 
2420  deleteTemplates();
2421 
2422  // Set this before completion of loading, since we rely on it for
2423  // text of an exception. Delay setting m_mod_time until after successful load
2424  // however.
2425  m_lib_path = aLibPath;
2426 
2427  // 8 bit "filename" should be encoded according to disk filename encoding,
2428  // (maybe this is current locale, maybe not, its a filesystem issue),
2429  // and is not necessarily utf8.
2430  string filename = (const char*) aLibPath.char_str( wxConvFile );
2431 
2432  // Load the document
2433  wxXmlDocument xmlDocument;
2434  wxFileName fn( filename );
2435 
2436  if( !xmlDocument.Load( fn.GetFullPath() ) )
2437  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
2438  fn.GetFullPath() ) );
2439 
2440  doc = xmlDocument.GetRoot();
2441 
2442  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2443  NODE_MAP drawingChildren = MapChildren( drawing );
2444 
2445  // clear the cu map and then rebuild it.
2446  clear_cu_map();
2447 
2448  m_xpath->push( "eagle.drawing.layers" );
2449  wxXmlNode* layers = drawingChildren["layers"];
2450  loadLayerDefs( layers );
2451  m_xpath->pop();
2452 
2453  m_xpath->push( "eagle.drawing.library" );
2454  wxXmlNode* library = drawingChildren["library"];
2455  loadLibrary( library, NULL );
2456  m_xpath->pop();
2457 
2458  m_mod_time = modtime;
2459  }
2460  }
2461  catch(...){}
2462  // TODO: Handle exceptions
2463  // catch( file_parser_error fpe )
2464  // {
2465  // // for xml_parser_error, what() has the line number in it,
2466  // // but no byte offset. That should be an adequate error message.
2467  // THROW_IO_ERROR( fpe.what() );
2468  // }
2469  //
2470  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2471  // // so one catch should be OK for all errors.
2472  // catch( ptree_error pte )
2473  // {
2474  // string errmsg = pte.what();
2475  //
2476  // errmsg += " @\n";
2477  // errmsg += m_xpath->Contents();
2478  //
2479  // THROW_IO_ERROR( errmsg );
2480  // }
2481 }
void clear_cu_map()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:175
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:174
wxString m_lib_path
Definition: eagle_plugin.h:193
#define THROW_IO_ERROR(msg)
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
#define _(s)
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:194
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
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48

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().

◆ centerBoard()

void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

Definition at line 2362 of file eagle_plugin.cpp.

2363 {
2364  if( m_props )
2365  {
2366  UTF8 page_width;
2367  UTF8 page_height;
2368 
2369  if( m_props->Value( "page_width", &page_width ) &&
2370  m_props->Value( "page_height", &page_height ) )
2371  {
2373 
2374  int w = atoi( page_width.c_str() );
2375  int h = atoi( page_height.c_str() );
2376 
2377  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2378  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2379 
2380  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2381  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2382 
2383  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2384  }
2385  }
2386 }
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:187
int GetX() const
Definition: eda_rect.h:109
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
int GetWidth() const
Definition: eda_rect.h:117
const char * c_str() const
Definition: utf8.h:107
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:186
int GetHeight() const
Definition: eda_rect.h:118
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetY() const
Definition: eda_rect.h:110
#define DBG(x)
Definition: fctsys.h:33
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found,...
Definition: properties.cpp:24

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().

◆ clear_cu_map()

void EAGLE_PLUGIN::clear_cu_map ( )
private

Definition at line 326 of file eagle_plugin.cpp.

327 {
328  // All cu layers are invalid until we see them in the <layers> section while
329  // loading either a board or library. See loadLayerDefs().
330  for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
331  m_cu_map[i] = -1;
332 }
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:170
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
size_t i
Definition: json11.cpp:597

References arrayDim(), i, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

◆ deleteTemplates()

void EAGLE_PLUGIN::deleteTemplates ( )
private

Deletes the footprint templates list

Definition at line 2037 of file eagle_plugin.cpp.

2038 {
2039  for( auto& t : m_templates )
2040  delete t.second;
2041 
2042  m_templates.clear();
2043 }
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:181

References m_templates.

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

◆ eagle_layer_name()

const wxString & EAGLE_PLUGIN::eagle_layer_name ( int  aLayer) const
private

Get Eagle layer name by its number.

Definition at line 2354 of file eagle_plugin.cpp.

2355 {
2356  static const wxString unknown( "unknown" );
2357  auto it = m_eagleLayers.find( aLayer );
2358  return it == m_eagleLayers.end() ? unknown : it->second.name;
2359 }
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:171

References m_eagleLayers.

Referenced by kicad_layer().

◆ fmtDEG()

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.

◆ FootprintDelete()

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

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

References not_implemented().

◆ FootprintEnumerate()

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

2486 {
2487  init( aProperties );
2488 
2489  cacheLib( aLibraryPath );
2490 
2491  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2492  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2493 }
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:62
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:181

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

◆ FootprintExists()

bool PLUGIN::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintExists check for the existence of a footprint.

Reimplemented in PCB_IO.

Definition at line 84 of file plugin.cpp.

86 {
87  // default implementation
88  return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr;
89 }
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:92

References PLUGIN::FootprintLoad().

◆ FootprintLibCreate()

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

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

References not_implemented().

◆ FootprintLibDelete()

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

125 {
126  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
127  not_implemented( this, __FUNCTION__ );
128  return false;
129 }
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

References not_implemented().

◆ FootprintLibOptions()

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

2514 {
2515  PLUGIN::FootprintLibOptions( aListToAppendTo );
2516 
2517  /*
2518  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2519  "Ignore duplicately named footprints within the same Eagle library. "
2520  "Only the first similarly named footprint will be loaded."
2521  ));
2522  */
2523 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:140

References PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

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

2498 {
2499  init( aProperties );
2500  cacheLib( aLibraryPath );
2501  MODULE_CITER mi = m_templates.find( aFootprintName );
2502 
2503  if( mi == m_templates.end() )
2504  return NULL;
2505 
2506  // copy constructor to clone the template
2507  MODULE* ret = new MODULE( *mi->second );
2508 
2509  return ret;
2510 }
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:181

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

◆ FootprintSave()

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

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

References not_implemented().

◆ GetEnumeratedFootprint()

const MODULE * PLUGIN::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

Reimplemented in PCB_IO, and GPCB_PLUGIN.

Definition at line 75 of file plugin.cpp.

78 {
79  // default implementation
80  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
81 }
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:92

References PLUGIN::FootprintLoad().

◆ GetFileExtension()

const wxString EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 206 of file eagle_plugin.cpp.

207 {
208  return wxT( "brd" );
209 }

◆ GetLibraryTimestamp()

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

136  {
137  return getModificationTime( aLibraryPath ).GetValue().GetValue();
138  }
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.

References getModificationTime().

◆ getModificationTime()

wxDateTime EAGLE_PLUGIN::getModificationTime ( const wxString &  aPath)
staticprivate

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

Definition at line 2389 of file eagle_plugin.cpp.

2390 {
2391  // File hasn't been loaded yet.
2392  if( aPath.IsEmpty() )
2393  return wxDateTime::Now();
2394 
2395  wxFileName fn( aPath );
2396 
2397  if( fn.IsFileReadable() )
2398  return fn.GetModificationTime();
2399  else
2400  return wxDateTime( 0.0 );
2401 }

Referenced by cacheLib(), and GetLibraryTimestamp().

◆ init()

void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 308 of file eagle_plugin.cpp.

309 {
310  m_hole_count = 0;
311  m_min_trace = 0;
312  m_min_via = 0;
313  m_min_via_hole = 0;
314  m_xpath->clear();
315  m_pads_to_nets.clear();
316 
317  m_board = NULL;
318  m_props = aProperties;
319 
320 
321  delete m_rules;
322  m_rules = new ERULES();
323 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
void clear()
Definition: eagle_parser.h:122
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:190
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:174
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:191
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:186
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:189
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:177
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:179

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().

◆ IsFootprintLibWritable()

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

141  {
142  return false; // until someone writes others like FootprintSave(), etc.
143  }

◆ kicad_fontz()

wxSize EAGLE_PLUGIN::kicad_fontz ( const ECOORD d) const
inlineprivate

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

Definition at line 212 of file eagle_plugin.cpp.

213 {
214  // texts seem to better match eagle when scaled down by 0.95
215  int kz = d.ToPcbUnits() * 95 / 100;
216  return wxSize( kz, kz );
217 }
int ToPcbUnits() const
Definition: eagle_parser.h:439

References ECOORD::ToPcbUnits().

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

◆ kicad_layer()

PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer ( int  aLayer) const
private

Convert an Eagle layer to a KiCad layer.

Definition at line 2285 of file eagle_plugin.cpp.

2286 {
2287  int kiLayer;
2288 
2289  // eagle copper layer:
2290  if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
2291  {
2292  kiLayer = m_cu_map[aEagleLayer];
2293  }
2294 
2295  else
2296  {
2297  // translate non-copper eagle layer to pcbnew layer
2298  switch( aEagleLayer )
2299  {
2300  // Eagle says "Dimension" layer, but it's for board perimeter
2301  case EAGLE_LAYER::MILLING: kiLayer = Edge_Cuts; break;
2302  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
2303 
2304  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
2305  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
2306  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
2307  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
2308  case EAGLE_LAYER::TVALUES: kiLayer = F_Fab; break;
2309  case EAGLE_LAYER::BVALUES: kiLayer = B_Fab; break;
2310  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
2311  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
2312  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
2313  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
2314  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
2315  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
2316  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
2317  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
2318  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
2319  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
2320  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
2321 
2322  // Packages show the future chip pins on SMD parts using layer 51.
2323  // This is an area slightly smaller than the PAD/SMD copper area.
2324  // Carry those visual aids into the MODULE on the fabrication layer,
2325  // not silkscreen. This is perhaps not perfect, but there is not a lot
2326  // of other suitable paired layers
2327  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
2328  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
2329 
2330  // these layers are defined as user layers. put them on ECO layers
2331  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
2332  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
2333 
2334  case EAGLE_LAYER::UNROUTED:
2335  case EAGLE_LAYER::TKEEPOUT:
2336  case EAGLE_LAYER::BKEEPOUT:
2337  case EAGLE_LAYER::TTEST:
2338  case EAGLE_LAYER::BTEST:
2339  case EAGLE_LAYER::HOLES:
2340  default:
2341  // some layers do not map to KiCad
2342  wxLogMessage( wxString::Format( _( "Unsupported Eagle layer '%s' (%d), converted to Dwgs.User layer" ),
2343  eagle_layer_name( aEagleLayer ), aEagleLayer ) );
2344 
2345  kiLayer = Dwgs_User;
2346  break;
2347  }
2348  }
2349 
2350  return PCB_LAYER_ID( kiLayer );
2351 }
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:170
PCB_LAYER_ID
A quick note on layer IDs:
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
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

References _, arrayDim(), 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, 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(), loadPolygon(), loadSignals(), packageCircle(), packagePolygon(), packageRectangle(), packageSMD(), packageText(), and packageWire().

◆ kicad_x()

int EAGLE_PLUGIN::kicad_x ( const ECOORD x) const
inlineprivate

◆ kicad_y()

int EAGLE_PLUGIN::kicad_y ( const ECOORD y) const
inlineprivate

Convert an Eagle distance to a KiCad distance.

Definition at line 202 of file eagle_plugin.h.

202 { return -y.ToPcbUnits(); }
int ToPcbUnits() const
Definition: eagle_parser.h:439

References ECOORD::ToPcbUnits().

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

◆ Load()

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

221 {
222  LOCALE_IO toggle; // toggles on, then off, the C locale.
223  wxXmlNode* doc;
224 
225  init( aProperties );
226 
227  m_board = aAppendToMe ? aAppendToMe : new BOARD();
228 
229  // Give the filename to the board if it's new
230  if( !aAppendToMe )
231  m_board->SetFileName( aFileName );
232 
233  // delete on exception, if I own m_board, according to aAppendToMe
234  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
235 
236  try
237  {
238  // Load the document
239  wxXmlDocument xmlDocument;
240  wxFileName fn = aFileName;
241 
242  if( !xmlDocument.Load( fn.GetFullPath() ) )
243  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
244  fn.GetFullPath() ) );
245 
246  doc = xmlDocument.GetRoot();
247 
248  m_min_trace = INT_MAX;
249  m_min_via = INT_MAX;
250  m_min_via_hole = INT_MAX;
251 
252  loadAllSections( doc );
253 
254  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
255 
256  if( m_min_trace < designSettings.m_TrackMinWidth )
257  designSettings.m_TrackMinWidth = m_min_trace;
258 
259  if( m_min_via < designSettings.m_ViasMinSize )
260  designSettings.m_ViasMinSize = m_min_via;
261 
262  if( m_min_via_hole < designSettings.m_ViasMinDrill )
263  designSettings.m_ViasMinDrill = m_min_via_hole;
264 
265  if( m_rules->mdWireWire )
266  {
267  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
268  int clearance = KiROUND( m_rules->mdWireWire );
269 
270  if( clearance < defaultNetclass->GetClearance() )
271  defaultNetclass->SetClearance( clearance );
272  }
273 
274  // should be empty, else missing m_xpath->pop()
275  wxASSERT( m_xpath->Contents().size() == 0 );
276  }
277  // Catch all exceptions thrown from the parser.
278  catch( const XML_PARSER_ERROR &exc )
279  {
280  wxString errmsg = exc.what();
281 
282  errmsg += "\n@ ";
283  errmsg += m_xpath->Contents();
284 
285  THROW_IO_ERROR( errmsg );
286  }
287 
288  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
289 
290  // Ensure the copper layers count is a multiple of 2
291  // Pcbnew does not like boards with odd layers count
292  // (these boards cannot exist. they actually have a even layers count)
293  int lyrcnt = m_board->GetCopperLayerCount();
294 
295  if( (lyrcnt % 2) != 0 )
296  {
297  lyrcnt++;
298  m_board->SetCopperLayerCount( lyrcnt );
299  }
300 
301  centerBoard();
302 
303  deleter.release();
304  return m_board;
305 }
wxString Contents()
return the contents of the XPATH as a single string
Definition: eagle_parser.h:139
void loadAllSections(wxXmlNode *aDocument)
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:187
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:175
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
void SetCopperLayerCount(int aCount)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
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:190
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:174
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:191
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
#define THROW_IO_ERROR(msg)
void SetFileName(const wxString &aFileName)
Definition: class_board.h:223
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:76
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:189
#define _(s)
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
NETCLASSPTR GetDefault() const
Function GetDefault.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
int GetCopperLayerCount() const
Function GetCopperLayerCount.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References _, centerBoard(), XPATH::Contents(), Format(), BOARD::GetCopperLayerCount(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), 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::SetCopperLayerCount(), BOARD::SetFileName(), and THROW_IO_ERROR.

◆ loadAllSections()

void EAGLE_PLUGIN::loadAllSections ( wxXmlNode *  aDocument)
private

Definition at line 335 of file eagle_plugin.cpp.

336 {
337  wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
338  NODE_MAP drawingChildren = MapChildren( drawing );
339 
340  wxXmlNode* board = drawingChildren["board"];
341  NODE_MAP boardChildren = MapChildren( board );
342 
343  m_xpath->push( "eagle.drawing" );
344 
345  {
346  m_xpath->push( "board" );
347 
348  wxXmlNode* designrules = boardChildren["designrules"];
349  loadDesignRules( designrules );
350 
351  m_xpath->pop();
352  }
353 
354  {
355  m_xpath->push( "layers" );
356 
357  wxXmlNode* layers = drawingChildren["layers"];
358  loadLayerDefs( layers );
359 
360  m_xpath->pop();
361  }
362 
363  {
364  m_xpath->push( "board" );
365 
366  wxXmlNode* plain = boardChildren["plain"];
367  loadPlain( plain );
368 
369  wxXmlNode* signals = boardChildren["signals"];
370  loadSignals( signals );
371 
372  wxXmlNode* libs = boardChildren["libraries"];
373  loadLibraries( libs );
374 
375  wxXmlNode* elems = boardChildren["elements"];
376  loadElements( elems );
377 
378  m_xpath->pop(); // "board"
379  }
380 
381  m_xpath->pop(); // "eagle.drawing"
382 }
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:174
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

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

Referenced by Load().

◆ loadDesignRules()

void EAGLE_PLUGIN::loadDesignRules ( wxXmlNode *  aDesignRules)
private

Definition at line 385 of file eagle_plugin.cpp.

386 {
387  if( aDesignRules )
388  {
389  m_xpath->push( "designrules" );
390  m_rules->parse( aDesignRules );
391  m_xpath->pop(); // "designrules"
392  }
393 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
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:174
void pop()
Definition: eagle_parser.h:124

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

Referenced by loadAllSections().

◆ loadElements()

void EAGLE_PLUGIN::loadElements ( wxXmlNode *  aElements)
private

Definition at line 871 of file eagle_plugin.cpp.

872 {
873  if( !aElements )
874  return;
875 
876  m_xpath->push( "elements.element", "name" );
877 
878  EATTR name;
879  EATTR value;
880  bool refanceNamePresetInPackageLayout;
881  bool valueNamePresetInPackageLayout;
882 
883  // Get the first element and iterate
884  wxXmlNode* element = aElements->GetChildren();
885 
886  while( element )
887  {
888  if( element->GetName() != "element" )
889  {
890  wxLogDebug( "expected: <element> read <%s>. Skip it", element->GetName() );
891  // Get next item
892  element = element->GetNext();
893  continue;
894  }
895 
896  EELEMENT e( element );
897 
898  // use "NULL-ness" as an indication of presence of the attribute:
899  EATTR* nameAttr = 0;
900  EATTR* valueAttr = 0;
901 
902  m_xpath->Value( e.name.c_str() );
903 
904  wxString pkg_key = makeKey( e.library, e.package );
905 
906  MODULE_CITER mi = m_templates.find( pkg_key );
907 
908  if( mi == m_templates.end() )
909  {
910  wxString emsg = wxString::Format( _( "No \"%s\" package in library \"%s\"" ),
911  GetChars( FROM_UTF8( e.package.c_str() ) ),
912  GetChars( FROM_UTF8( e.library.c_str() ) ) );
913  THROW_IO_ERROR( emsg );
914  }
915 
916  // copy constructor to clone the template
917  MODULE* m = new MODULE( *mi->second );
918  m_board->Add( m, ADD_APPEND );
919 
920  // update the nets within the pads of the clone
921  for( auto pad : m->Pads() )
922  {
923  wxString pn_key = makeKey( e.name, pad->GetName() );
924 
925  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
926  if( ni != m_pads_to_nets.end() )
927  {
928  const ENET* enet = &ni->second;
929  pad->SetNetCode( enet->netcode );
930  }
931  }
932 
933  refanceNamePresetInPackageLayout = true;
934  valueNamePresetInPackageLayout = true;
935  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
936 
937  // Is >NAME field set in package layout ?
938  if( m->GetReference().size() == 0 )
939  {
940  m->Reference().SetVisible( false ); // No so no show
941  refanceNamePresetInPackageLayout = false;
942  }
943 
944  // Is >VALUE field set in package layout
945  if( m->GetValue().size() == 0 )
946  {
947  m->Value().SetVisible( false ); // No so no show
948  valueNamePresetInPackageLayout = false;
949  }
950 
951  m->SetReference( FROM_UTF8( e.name.c_str() ) );
952  m->SetValue( FROM_UTF8( e.value.c_str() ) );
953 
954  if( !e.smashed )
955  { // Not smashed so show NAME & VALUE
956  if( valueNamePresetInPackageLayout )
957  m->Value().SetVisible( true ); // Only if place holder in package layout
958 
959  if( refanceNamePresetInPackageLayout )
960  m->Reference().SetVisible( true ); // Only if place holder in package layout
961  }
962  else if( *e.smashed == true )
963  { // Smashed so set default to no show for NAME and VALUE
964  m->Value().SetVisible( false );
965  m->Reference().SetVisible( false );
966 
967  // initialize these to default values in case the <attribute> elements are not present.
968  m_xpath->push( "attribute", "name" );
969 
970  // VALUE and NAME can have something like our text "effects" overrides
971  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
972  // There can be one for NAME and/or VALUE both. Features present in the
973  // EATTR override the ones established in the package only if they are
974  // present here (except for rot, which if not present means angle zero).
975  // So the logic is a bit different than in packageText() and in plain text.
976 
977  // Get the first attribute and iterate
978  wxXmlNode* attribute = element->GetChildren();
979 
980  while( attribute )
981  {
982  if( attribute->GetName() != "attribute" )
983  {
984  wxLogDebug( "expected: <attribute> read <%s>. Skip it", attribute->GetName() );
985  attribute = attribute->GetNext();
986  continue;
987  }
988 
989  EATTR a( attribute );
990 
991  if( a.name == "NAME" )
992  {
993  name = a;
994  nameAttr = &name;
995 
996  // do we have a display attribute ?
997  if( a.display )
998  {
999  // Yes!
1000  switch( *a.display )
1001  {
1002  case EATTR::VALUE :
1003  {
1004  wxString reference = e.name;
1005 
1006  // EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
1007  // parts to have non-digit + digit annotation. If the reference begins with a number,
1008  // we prepend 'UNK' (unknown) for the symbol designator
1009  if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
1010  reference.Prepend( "UNK" );
1011 
1012  nameAttr->name = reference;
1013  m->SetReference( reference );
1014  if( refanceNamePresetInPackageLayout )
1015  m->Reference().SetVisible( true );
1016  break;
1017  }
1018  case EATTR::NAME :
1019  if( refanceNamePresetInPackageLayout )
1020  {
1021  m->SetReference( "NAME" );
1022  m->Reference().SetVisible( true );
1023  }
1024  break;
1025 
1026  case EATTR::BOTH :
1027  if( refanceNamePresetInPackageLayout )
1028  m->Reference().SetVisible( true );
1029  nameAttr->name = nameAttr->name + " = " + e.name;
1030  m->SetReference( "NAME = " + e.name );
1031  break;
1032 
1033  case EATTR::Off :
1034  m->Reference().SetVisible( false );
1035  break;
1036 
1037  default:
1038  nameAttr->name = e.name;
1039  if( refanceNamePresetInPackageLayout )
1040  m->Reference().SetVisible( true );
1041  }
1042  }
1043  else
1044  // No display, so default is visible, and show value of NAME
1045  m->Reference().SetVisible( true );
1046  }
1047  else if( a.name == "VALUE" )
1048  {
1049  value = a;
1050  valueAttr = &value;
1051 
1052  if( a.display )
1053  {
1054  // Yes!
1055  switch( *a.display )
1056  {
1057  case EATTR::VALUE :
1058  valueAttr->value = opt_wxString( e.value );
1059  m->SetValue( e.value );
1060  if( valueNamePresetInPackageLayout )
1061  m->Value().SetVisible( true );
1062  break;
1063 
1064  case EATTR::NAME :
1065  if( valueNamePresetInPackageLayout )
1066  m->Value().SetVisible( true );
1067  m->SetValue( "VALUE" );
1068  break;
1069 
1070  case EATTR::BOTH :
1071  if( valueNamePresetInPackageLayout )
1072  m->Value().SetVisible( true );
1073  valueAttr->value = opt_wxString( "VALUE = " + e.value );
1074  m->SetValue( "VALUE = " + e.value );
1075  break;
1076 
1077  case EATTR::Off :
1078  m->Value().SetVisible( false );
1079  break;
1080 
1081  default:
1082  valueAttr->value = opt_wxString( e.value );
1083  if( valueNamePresetInPackageLayout )
1084  m->Value().SetVisible( true );
1085  }
1086  }
1087  else
1088  // No display, so default is visible, and show value of NAME
1089  m->Value().SetVisible( true );
1090 
1091  }
1092 
1093  attribute = attribute->GetNext();
1094  }
1095 
1096  m_xpath->pop(); // "attribute"
1097  }
1098 
1099  orientModuleAndText( m, e, nameAttr, valueAttr );
1100 
1101  // Get next element
1102  element = element->GetNext();
1103  }
1104 
1105  m_xpath->pop(); // "elements.element"
1106 }
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
TEXTE_MODULE & Reference()
Definition: class_module.h:448
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:62
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
Eagle element element.
Definition: eagle_parser.h:798
void SetVisible(bool aVisible)
Definition: eda_text.h:169
PADS & Pads()
Definition: class_module.h:163
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:432
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:41
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:174
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:407
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
Definition: eagle_parser.h:379
wxString name
Definition: eagle_parser.h:605
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:447
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:417
#define THROW_IO_ERROR(msg)
void SetPosition(const wxPoint &aPos) override
opt_wxString value
Definition: eagle_parser.h:606
#define _(s)
Eagle net.
Definition: eagle_parser.h:462
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:603
MODULE_MAP::const_iterator MODULE_CITER
int netcode
Definition: eagle_parser.h:464
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:101
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
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:181
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:441
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:179
void pop()
Definition: eagle_parser.h:124
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:127

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, EATTR::Off, orientModuleAndText(), EELEMENT::package, MODULE::Pads(), XPATH::pop(), XPATH::push(), MODULE::Reference(), MODULE::SetPosition(), MODULE::SetReference(), MODULE::SetValue(), EDA_TEXT::SetVisible(), EELEMENT::smashed, THROW_IO_ERROR, XPATH::Value(), MODULE::Value(), EATTR::value, EATTR::VALUE, EELEMENT::value, EELEMENT::x, and EELEMENT::y.

Referenced by loadAllSections().

◆ loadLayerDefs()

void EAGLE_PLUGIN::loadLayerDefs ( wxXmlNode *  aLayers)
private

Definition at line 396 of file eagle_plugin.cpp.

397 {
398  if( !aLayers )
399  return;
400 
401  ELAYERS cu; // copper layers
402 
403  // Get the first layer and iterate
404  wxXmlNode* layerNode = aLayers->GetChildren();
405 
406  m_eagleLayers.clear();
407 
408  while( layerNode )
409  {
410  ELAYER elayer( layerNode );
411  m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
412 
413  // find the subset of layers that are copper and active
414  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
415  {
416  cu.push_back( elayer );
417  }
418 
419  layerNode = layerNode->GetNext();
420  }
421 
422  // establish cu layer map:
423  int ki_layer_count = 0;
424 
425  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
426  {
427  if( ki_layer_count == 0 )
428  m_cu_map[it->number] = F_Cu;
429  else if( ki_layer_count == int( cu.size()-1 ) )
430  m_cu_map[it->number] = B_Cu;
431  else
432  {
433  // some eagle boards do not have contiguous layer number sequences.
434 
435 #if 0 // pre PCB_LAYER_ID & LSET:
436  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
437 #else
438  m_cu_map[it->number] = ki_layer_count;
439 #endif
440  }
441  }
442 
443 #if 0 && defined(DEBUG)
444  printf( "m_cu_map:\n" );
445  for( unsigned i=0; i<arrayDim(m_cu_map); ++i )
446  {
447  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
448  }
449 #endif
450 
451  // Set the layer names and cu count if we're loading a board.
452  if( m_board )
453  {
454  m_board->SetCopperLayerCount( cu.size() );
455 
456  for( EITER it = cu.begin(); it != cu.end(); ++it )
457  {
458  PCB_LAYER_ID layer = kicad_layer( it->number );
459 
460  // these function provide their own protection against UNDEFINED_LAYER:
461  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
462  m_board->SetLayerType( layer, LT_SIGNAL );
463 
464  // could map the colors here
465  }
466  }
467 }
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:62
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
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:170
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:171
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:167
size_t i
Definition: json11.cpp:597
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:168

References ELAYER::active, arrayDim(), B_Cu, cu, 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().

◆ loadLibraries()

void EAGLE_PLUGIN::loadLibraries ( wxXmlNode *  aLibs)
private

Definition at line 848 of file eagle_plugin.cpp.

849 {
850  if( !aLibs )
851  return;
852 
853  m_xpath->push( "libraries.library", "name" );
854 
855  // Get the first library and iterate
856  wxXmlNode* library = aLibs->GetChildren();
857 
858  while( library )
859  {
860  const wxString& lib_name = library->GetAttribute( "name" );
861 
862  m_xpath->Value( lib_name.c_str() );
863  loadLibrary( library, &lib_name );
864  library = library->GetNext();
865  }
866 
867  m_xpath->pop();
868 }
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:174
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's value
Definition: eagle_parser.h:127

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

Referenced by loadAllSections().

◆ loadLibrary()

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

789 {
790  if( !aLib )
791  return;
792 
793  // library will have <xmlattr> node, skip that and get the single packages node
794  wxXmlNode* packages = MapChildren( aLib )["packages"];
795 
796  if( !packages )
797  return;
798 
799  m_xpath->push( "packages" );
800 
801  // Create a MODULE for all the eagle packages, for use later via a copy constructor
802  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
803  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
804 
805  // Get the first package and iterate
806  wxXmlNode* package = packages->GetChildren();
807 
808  while( package )
809  {
810  m_xpath->push( "package", "name" );
811 
812  wxString pack_ref = package->GetAttribute( "name" );
813  ReplaceIllegalFileNameChars( pack_ref, '_' );
814 
815  m_xpath->Value( pack_ref.ToUTF8() );
816 
817  wxString key = aLibName ? makeKey( *aLibName, pack_ref ) : pack_ref;
818 
819  MODULE* m = makeModule( package, pack_ref );
820 
821  // add the templating MODULE to the MODULE template factory "m_templates"
822  std::pair<MODULE_ITER, bool> r = m_templates.insert( {key, m} );
823 
824  if( !r.second
825  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
826  )
827  {
828  wxString lib = aLibName ? *aLibName : m_lib_path;
829  wxString pkg = pack_ref;
830 
831  wxString emsg = wxString::Format(
832  _( "<package> name: \"%s\" duplicated in eagle <library>: \"%s\"" ),
833  GetChars( pkg ),
834  GetChars( lib )
835  );
836  THROW_IO_ERROR( emsg );
837  }
838 
839  m_xpath->pop();
840 
841  package = package->GetNext();
842  }
843 
844  m_xpath->pop(); // "packages"
845 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:668
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:174
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:193
#define THROW_IO_ERROR(msg)
#define _(s)
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:101
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:181
void pop()
Definition: eagle_parser.h:124
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's value
Definition: eagle_parser.h:127

References _, Format(), 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().

◆ loadPlain()

void EAGLE_PLUGIN::loadPlain ( wxXmlNode *  aPlain)
private

Definition at line 470 of file eagle_plugin.cpp.

471 {
472  if( !aGraphics )
473  return;
474 
475  m_xpath->push( "plain" );
476 
477  // Get the first graphic and iterate
478  wxXmlNode* gr = aGraphics->GetChildren();
479 
480  // (polygon | wire | text | circle | rectangle | frame | hole)*
481  while( gr )
482  {
483  wxString grName = gr->GetName();
484 
485  if( grName == "wire" )
486  {
487  m_xpath->push( "wire" );
488 
489  EWIRE w( gr );
490  PCB_LAYER_ID layer = kicad_layer( w.layer );
491 
492  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
493  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
494 
495  if( layer != UNDEFINED_LAYER )
496  {
497  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
498  int width = w.width.ToPcbUnits();
499 
500  // KiCad cannot handle zero or negative line widths
501  if( width <= 0 )
502  width = m_board->GetDesignSettings().GetLineThickness( layer );
503 
504  m_board->Add( dseg, ADD_APPEND );
505 
506  if( !w.curve )
507  {
508  dseg->SetStart( start );
509  dseg->SetEnd( end );
510  }
511  else
512  {
513  wxPoint center = ConvertArcCenter( start, end, *w.curve );
514 
515  dseg->SetShape( S_ARC );
516  dseg->SetStart( center );
517  dseg->SetEnd( start );
518  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
519  }
520 
521  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
522  dseg->SetLayer( layer );
523  dseg->SetWidth( width );
524  }
525 
526  m_xpath->pop();
527  }
528  else if( grName == "text" )
529  {
530  m_xpath->push( "text" );
531 
532  ETEXT t( gr );
533  PCB_LAYER_ID layer = kicad_layer( t.layer );
534 
535  if( layer != UNDEFINED_LAYER )
536  {
537  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
538  m_board->Add( pcbtxt, ADD_APPEND );
539 
540  pcbtxt->SetLayer( layer );
541  pcbtxt->SetTimeStamp( EagleTimeStamp( gr ) );
542  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
543  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
544 
545  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
546 
547  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
548 
549  pcbtxt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
550 
551  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
552 
553  if( t.rot )
554  {
555  int sign = t.rot->mirror ? -1 : 1;
556  pcbtxt->SetMirrored( t.rot->mirror );
557 
558  double degrees = t.rot->degrees;
559 
560  if( degrees == 90 || t.rot->spin )
561  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
562  else if( degrees == 180 )
563  align = ETEXT::TOP_RIGHT;
564  else if( degrees == 270 )
565  {
566  pcbtxt->SetTextAngle( sign * 90 * 10 );
567  align = ETEXT::TOP_RIGHT;
568  }
569  else // Ok so text is not at 90,180 or 270 so do some funny stuff to get placement right
570  {
571  if( ( degrees > 0 ) && ( degrees < 90 ) )
572  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
573  else if( ( degrees > 90 ) && ( degrees < 180 ) )
574  {
575  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
576  align = ETEXT::TOP_RIGHT;
577  }
578  else if( ( degrees > 180 ) && ( degrees < 270 ) )
579  {
580  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
581  align = ETEXT::TOP_RIGHT;
582  }
583  else if( ( degrees > 270 ) && ( degrees < 360 ) )
584  {
585  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
586  align = ETEXT::BOTTOM_LEFT;
587  }
588  }
589  }
590 
591  switch( align )
592  {
593  case ETEXT::CENTER:
594  // this was the default in pcbtxt's constructor
595  break;
596 
597  case ETEXT::CENTER_LEFT:
599  break;
600 
601  case ETEXT::CENTER_RIGHT:
603  break;
604 
605  case ETEXT::TOP_CENTER:
607  break;
608 
609  case ETEXT::TOP_LEFT:
612  break;
613 
614  case ETEXT::TOP_RIGHT:
617  break;
618 
621  break;
622 
623  case ETEXT::BOTTOM_LEFT:
626  break;
627 
628  case ETEXT::BOTTOM_RIGHT:
631  break;
632  }
633  }
634  m_xpath->pop();
635  }
636  else if( grName == "circle" )
637  {
638  m_xpath->push( "circle" );
639 
640  ECIRCLE c( gr );
641  PCB_LAYER_ID layer = kicad_layer( c.layer );
642 
643  if( layer != UNDEFINED_LAYER ) // unsupported layer
644  {
645  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
646  m_board->Add( dseg, ADD_APPEND );
647 
648  int width = c.width.ToPcbUnits();
649  int radius = c.radius.ToPcbUnits();
650 
651  // with == 0 means filled circle
652  if( width <= 0 )
653  {
654  width = radius;
655  radius = radius / 2;
656  }
657 
658  dseg->SetShape( S_CIRCLE );
659  dseg->SetTimeStamp( EagleTimeStamp( gr ) );
660  dseg->SetLayer( layer );
661  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
662  dseg->SetEnd( wxPoint( kicad_x( c.x ) + radius, kicad_y( c.y ) ) );
663  dseg->SetWidth( width );
664  }
665  m_xpath->pop();
666  }
667  else if( grName == "rectangle" )
668  {
669  // This seems to be a simplified rectangular [copper] zone, cannot find any
670  // net related info on it from the DTD.
671  m_xpath->push( "rectangle" );
672 
673  ERECT r( gr );
674  PCB_LAYER_ID layer = kicad_layer( r.layer );
675 
676  if( IsCopperLayer( layer ) )
677  {
678  // use a "netcode = 0" type ZONE:
679  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
680  m_board->Add( zone, ADD_APPEND );
681 
682  zone->SetTimeStamp( EagleTimeStamp( gr ) );
683  zone->SetLayer( layer );
685 
687 
688  const int outlineIdx = -1; // this is the id of the copper zone main outline
689  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
690  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
691  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
692  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
693 
694  if( r.rot )
695  {
696  zone->Rotate( zone->GetPosition(), r.rot->degrees * 10 );
697  }
698  // this is not my fault:
699  zone->SetHatch( outline_hatch, zone->GetDefaultHatchPitch(), true );
700  }
701 
702  m_xpath->pop();
703  }
704  else if( grName == "hole" )
705  {
706  m_xpath->push( "hole" );
707 
708  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
709  // Use m_hole_count to gen up a unique name.
710 
711  MODULE* module = new MODULE( m_board );
712  m_board->Add( module, ADD_APPEND );
713  module->SetReference( wxString::Format( "@HOLE%d", m_hole_count++ ) );
714  module->Reference().SetVisible( false );
715 
716  packageHole( module, gr, true );
717 
718  m_xpath->pop();
719  }
720  else if( grName == "frame" )
721  {
722  // picture this
723  }
724  else if( grName == "polygon" )
725  {
726  m_xpath->push( "polygon" );
727  loadPolygon( gr );
728  m_xpath->pop(); // "polygon"
729  }
730  else if( grName == "dimension" )
731  {
732  EDIMENSION d( gr );
733  PCB_LAYER_ID layer = kicad_layer( d.layer );
734 
735  if( layer != UNDEFINED_LAYER )
736  {
737  const BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
738  DIMENSION* dimension = new DIMENSION( m_board );
739  m_board->Add( dimension, ADD_APPEND );
740 
741  if( d.dimensionType )
742  {
743  // Eagle dimension graphic arms may have different lengths, but they look
744  // incorrect in KiCad (the graphic is tilted). Make them even length in such case.
745  if( *d.dimensionType == "horizontal" )
746  {
747  int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
748  d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
749  d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
750  }
751  else if( *d.dimensionType == "vertical" )
752  {
753  int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
754  d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
755  d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
756  }
757  }
758 
759  dimension->SetLayer( layer );
760  // The origin and end are assumed to always be in this order from eagle
761  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
762  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
763  dimension->Text().SetTextSize( designSettings.GetTextSize( layer ) );
764  dimension->Text().SetThickness( designSettings.GetTextThickness( layer ) );
765  dimension->SetWidth( designSettings.GetLineThickness( layer ) );
766  dimension->SetUnits( MILLIMETRES, false );
767 
768  // check which axis the dimension runs in
769  // because the "height" of the dimension is perpendicular to that axis
770  // Note the check is just if two axes are close enough to each other
771  // Eagle appears to have some rounding errors
772  if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm
773  dimension->SetHeight( kicad_x( d.x3 - d.x1 ) );
774  else
775  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
776 
777  dimension->AdjustDimensionDetails();
778  }
779  }
780 
781  // Get next graphic
782  gr = gr->GetNext();
783  }
784  m_xpath->pop();
785 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
void SetTextAngle(double aAngle)
TEXTE_MODULE & Reference()
Definition: class_module.h:448
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:62
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:229
void SetVisible(bool aVisible)
Definition: eda_text.h:169
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:943
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:220
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
const wxPoint GetPosition() const override
Definition: class_zone.cpp:172
Eagle text element.
Definition: eagle_parser.h:646
#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:174
void packageHole(MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTr...
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
PCB_LAYER_ID
A quick note on layer IDs:
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:112
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:188
Arcs (with rounded ends)
Eagle circle.
Definition: eagle_parser.h:571
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:770
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:205
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void AdjustDimensionDetails()
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension.
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:417
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:64
void SetUnits(EDA_UNITS_T aUnits, bool aUseMils)
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:177
Eagle XML rectangle in binary.
Definition: eagle_parser.h:584
void SetStart(const wxPoint &aStart)
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:187
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 SetEnd(const wxPoint &aEnd)
Eagle wire.
Definition: eagle_parser.h:500
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition: class_zone.cpp:900
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
Eagle dimension element.
Definition: eagle_parser.h:629
void pop()
Definition: eagle_parser.h:124
void SetWidth(int aWidth)
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:463
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
Class DIMENSION.
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
int sign(T val)
Definition: math_util.h:44
void SetWidth(int aWidth)

References abs, BOARD::Add(), ADD_APPEND, DIMENSION::AdjustDimensionDetails(), ETEXT::align, ZONE_CONTAINER::AppendCorner(), ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, ConvertArcCenter(), EWIRE::curve, EROT::degrees, ZONE_CONTAINER::DIAGONAL_EDGE, EDIMENSION::dimensionType, EagleTimeStamp(), Format(), FROM_UTF8(), ZONE_CONTAINER::GetDefaultHatchPitch(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetLineThickness(), ZONE_CONTAINER::GetPosition(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), 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, loadPolygon(), m_board, m_hole_count, m_xpath, MILLIMETRES, EROT::mirror, packageHole(), XPATH::pop(), XPATH::push(), ECIRCLE::radius, ETEXT::ratio, MODULE::Reference(), ERECT::rot, ETEXT::rot, ZONE_CONTAINER::Rotate(), S_ARC, S_CIRCLE, DRAWSEGMENT::SetAngle(), DRAWSEGMENT::SetEnd(), DIMENSION::SetEnd(), ZONE_CONTAINER::SetHatch(), DIMENSION::SetHeight(), EDA_TEXT::SetHorizJustify(), DIMENSION::SetLayer(), ZONE_CONTAINER::SetLayer(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), BOARD_CONNECTED_ITEM::SetNetCode(), DIMENSION::SetOrigin(), MODULE::SetReference(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetStart(), EDA_TEXT::SetText(), TEXTE_PCB::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), DIMENSION::SetUnits(), 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, EWIRE::width, ECIRCLE::width, ECIRCLE::x, ETEXT::x, EWIRE::x1, ERECT::x1, EDIMENSION::x1, EWIRE::x2, ERECT::x2, EDIMENSION::x2, EDIMENSION::x3, ECIRCLE::y, ETEXT::y, EWIRE::y1, ERECT::y1, EDIMENSION::y1, EWIRE::y2, ERECT::y2, EDIMENSION::y2, and EDIMENSION::y3.

Referenced by loadAllSections().

◆ loadPolygon()

ZONE_CONTAINER * EAGLE_PLUGIN::loadPolygon ( wxXmlNode *  aPolyNode)
private

Loads a copper or keepout polygon and adds it to the board.

Returns
The loaded zone or nullptr if was not processed.

Definition at line 1109 of file eagle_plugin.cpp.

1110 {
1111  EPOLYGON p( aPolyNode );
1112  PCB_LAYER_ID layer = kicad_layer( p.layer );
1113  ZONE_CONTAINER* zone = nullptr;
1114  bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT || p.layer == EAGLE_LAYER::BRESTRICT );
1115 
1116  if( !IsCopperLayer( layer ) && !keepout )
1117  return nullptr;
1118 
1119  // use a "netcode = 0" type ZONE:
1120  zone = new ZONE_CONTAINER( m_board );
1121  zone->SetTimeStamp( EagleTimeStamp( aPolyNode ) );
1122  m_board->Add( zone, ADD_APPEND );
1123 
1124  if( p.layer == EAGLE_LAYER::TRESTRICT ) // front layer keepout
1125  zone->SetLayer( F_Cu );
1126  else if( p.layer == EAGLE_LAYER::BRESTRICT ) // bottom layer keepout
1127  zone->SetLayer( B_Cu );
1128  else
1129  zone->SetLayer( layer );
1130 
1131  if( keepout )
1132  {
1133  zone->SetIsKeepout( true );
1134  zone->SetDoNotAllowVias( true );
1135  zone->SetDoNotAllowTracks( true );
1136  zone->SetDoNotAllowCopperPour( true );
1137  }
1138 
1139  // Get the first vertex and iterate
1140  wxXmlNode* vertex = aPolyNode->GetChildren();
1141  std::vector<EVERTEX> vertices;
1142 
1143  // Create a circular vector of vertices
1144  // The "curve" parameter indicates a curve from the current
1145  // to the next vertex, so we keep the first at the end as well
1146  // to allow the curve to link back
1147  while( vertex )
1148  {
1149  if( vertex->GetName() == "vertex" )
1150  vertices.push_back( EVERTEX( vertex ) );
1151 
1152  vertex = vertex->GetNext();
1153  }
1154 
1155  vertices.push_back( vertices[0] );
1156 
1157  SHAPE_POLY_SET polygon;
1158  polygon.NewOutline();
1159 
1160  for( size_t i = 0; i < vertices.size() - 1; i++ )
1161  {
1162  EVERTEX v1 = vertices[i];
1163 
1164  // Append the corner
1165  polygon.Append( kicad_x( v1.x ), kicad_y( v1.y ) );
1166 
1167  if( v1.curve )
1168  {
1169  EVERTEX v2 = vertices[i + 1];
1170  wxPoint center = ConvertArcCenter(
1171  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1172  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1173  double angle = DEG2RAD( *v1.curve );
1174  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1175  kicad_x( v2.x ) - center.x );
1176  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1177  + pow( center.y - kicad_y( v1.y ), 2 ) );
1178 
1179  // If we are curving, we need at least 2 segments otherwise
1180  // delta_angle == angle
1181  double delta_angle = angle / std::max(
1182  2, GetArcToSegmentCount( KiROUND( radius ),
1183  ARC_HIGH_DEF, *v1.curve ) - 1 );
1184 
1185  for( double a = end_angle + angle;
1186  fabs( a - end_angle ) > fabs( delta_angle );
1187  a -= delta_angle )
1188  {
1189  polygon.Append( KiROUND( radius * cos( a ) ) + center.x,
1190  KiROUND( radius * sin( a ) ) + center.y );
1191  }
1192  }
1193  }
1194 
1195  // Eagle traces the zone such that half of the pen width is outside the polygon.
1196  // We trace the zone such that the copper is completely inside.
1197  if( p.width.ToPcbUnits() > 0 )
1198  {
1199  polygon.Inflate( p.width.ToPcbUnits() / 2, 32, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS );
1201  }
1202 
1203  zone->AddPolygon( polygon.COutline( 0 ) );
1204 
1205  // If the pour is a cutout it needs to be set to a keepout
1206  if( p.pour == EPOLYGON::CUTOUT )
1207  {
1208  zone->SetIsKeepout( true );
1209  zone->SetDoNotAllowCopperPour( true );
1211  }
1212  else if( p.pour == EPOLYGON::HATCH )
1213  {
1214  int spacing = p.spacing ? p.spacing->ToPcbUnits() : 50 * IU_PER_MILS;
1215 
1216  zone->SetFillMode( ZFM_HATCH_PATTERN );
1217  zone->SetHatchFillTypeThickness( p.width.ToPcbUnits() );
1218  zone->SetHatchFillTypeGap( spacing - p.width.ToPcbUnits() );
1219  zone->SetHatchFillTypeOrientation( 0 );
1220  }
1221 
1222  // We divide the thickness by half because we are tracing _inside_ the zone outline
1223  // This means the radius of curvature will be twice the size for an equivalent EAGLE zone
1224  zone->SetMinThickness(
1225  std::max<int>( ZONE_THICKNESS_MIN_VALUE_MIL * IU_PER_MILS, p.width.ToPcbUnits() / 2 ) );
1226 
1227  if( p.isolate )
1228  zone->SetZoneClearance( p.isolate->ToPcbUnits() );
1229  else
1230  zone->SetZoneClearance( 1 ); // @todo: set minimum clearance value based on board settings
1231 
1232  // missing == yes per DTD.
1233  bool thermals = !p.thermals || *p.thermals;
1235 
1236  if( thermals )
1237  {
1238  // FIXME: eagle calculates dimensions for thermal spokes
1239  // based on what the zone is connecting to.
1240  // (i.e. width of spoke is half of the smaller side of an smd pad)
1241  // This is a basic workaround
1242  zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
1243  zone->SetThermalReliefCopperBridge( p.width.ToPcbUnits() + 50000 );
1244  }
1245 
1246  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
1247  zone->SetPriority( rank );
1248 
1249  return zone;
1250 }
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:629
Eagle vertex.
Definition: eagle_parser.h:747
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
ECOORD y
Definition: eagle_parser.h:750
void Inflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Performs outline inflation/deflation.
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:628
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:88
PCB_LAYER_ID
A quick note on layer IDs:
void SetHatchFillTypeGap(int aStep)
Definition: class_zone.h:189
Class SHAPE_POLY_SET.
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:205
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:171
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
int NewOutline()
Creates a new empty polygon in the set and returns its index
void AddPolygon(std::vector< wxPoint > &aPolygon)
add a polygon to the zone outline if the zone outline is empty, this is the main outline else it is a...
Definition: class_zone.cpp:875
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:751
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:155
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:627
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:41
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:149
ECOORD x
Definition: eagle_parser.h:749
double DEG2RAD(double deg)
Definition: trigo.h:210
#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 SHAPE_LINE_CHAIN & COutline(int aIndex) const
void SetHatchFillTypeOrientation(double aStep)
Definition: class_zone.h:192
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
#define IU_PER_MILS
Definition: plotter.cpp:134
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:515
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void SetHatchFillTypeThickness(int aThickness)
Definition: class_zone.h:186
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:758
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:626
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:174
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:177
Use thermal relief for pads.
Definition: zones.h:53
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:152
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
pads are covered by copper
Definition: zones.h:54
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)

References BOARD::Add(), ADD_APPEND, ZONE_CONTAINER::AddPolygon(), SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS, PNS::angle(), SHAPE_POLY_SET::Append(), B_Cu, EAGLE_LAYER::BRESTRICT, ConvertArcCenter(), SHAPE_POLY_SET::COutline(), EVERTEX::curve, EPOLYGON::CUTOUT, DEG2RAD(), EagleTimeStamp(), F_Cu, SHAPE_POLY_SET::Fracture(), GetArcToSegmentCount(), EPOLYGON::HATCH, i, SHAPE_POLY_SET::Inflate(), IsCopperLayer(), EPOLYGON::isolate, IU_PER_MILS, kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, m_board, max, EPOLYGON::max_priority, SHAPE_POLY_SET::NewOutline(), ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_THERMAL, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, EPOLYGON::pour, EPOLYGON::rank, ZONE_CONTAINER::SetDoNotAllowCopperPour(), ZONE_CONTAINER::SetDoNotAllowTracks(), ZONE_CONTAINER::SetDoNotAllowVias(), ZONE_CONTAINER::SetFillMode(), ZONE_CONTAINER::SetHatchFillTypeGap(), ZONE_CONTAINER::SetHatchFillTypeOrientation(), ZONE_CONTAINER::SetHatchFillTypeThickness(), ZONE_CONTAINER::SetHatchStyle(), ZONE_CONTAINER::SetIsKeepout(), ZONE_CONTAINER::SetLayer(), ZONE_CONTAINER::SetMinThickness(), ZONE_CONTAINER::SetPadConnection(), ZONE_CONTAINER::SetPriority(), ZONE_CONTAINER::SetThermalReliefCopperBridge(), ZONE_CONTAINER::SetThermalReliefGap(), EDA_ITEM::SetTimeStamp(), ZONE_CONTAINER::SetZoneClearance(), EPOLYGON::spacing, EPOLYGON::thermals, ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, EPOLYGON::width, EVERTEX::x, EVERTEX::y, ZFM_HATCH_PATTERN, and ZONE_THICKNESS_MIN_VALUE_MIL.

Referenced by loadPlain(), and loadSignals().

◆ loadSignals()

void EAGLE_PLUGIN::loadSignals ( wxXmlNode *  aSignals)
private

Definition at line 2046 of file eagle_plugin.cpp.

2047 {
2048  ZONES zones; // per net
2049 
2050  m_xpath->push( "signals.signal", "name" );
2051 
2052  int netCode = 1;
2053 
2054  // Get the first signal and iterate
2055  wxXmlNode* net = aSignals->GetChildren();
2056 
2057  while( net )
2058  {
2059  bool sawPad = false;
2060 
2061  zones.clear();
2062 
2063  const wxString& netName = escapeName( net->GetAttribute( "name" ) );
2064  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
2065 
2066  m_xpath->Value( netName.c_str() );
2067 
2068  // Get the first net item and iterate
2069  wxXmlNode* netItem = net->GetChildren();
2070 
2071  // (contactref | polygon | wire | via)*
2072  while( netItem )
2073  {
2074  const wxString& itemName = netItem->GetName();
2075 
2076  if( itemName == "wire" )
2077  {
2078  m_xpath->push( "wire" );
2079 
2080  EWIRE w( netItem );
2081  PCB_LAYER_ID layer = kicad_layer( w.layer );
2082 
2083  if( IsCopperLayer( layer ) )
2084  {
2085  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
2086  double angle = 0.0;
2087  double end_angle = 0.0;
2088  double radius = 0.0;
2089  double delta_angle = 0.0;
2090  wxPoint center;
2091 
2092  int width = w.width.ToPcbUnits();
2093  if( width < m_min_trace )
2094  m_min_trace = width;
2095 
2096  if( w.curve )
2097  {
2098  center = ConvertArcCenter(
2099  wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
2100  wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
2101  *w.curve );
2102 
2103  angle = DEG2RAD( *w.curve );
2104 
2105  end_angle = atan2( kicad_y( w.y2 ) - center.y,
2106  kicad_x( w.x2 ) - center.x );
2107 
2108  radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
2109  pow( center.y - kicad_y( w.y1 ), 2 ) );
2110 
2111  // If we are curving, we need at least 2 segments otherwise
2112  // delta_angle == angle
2113  int segments = std::max( 2, GetArcToSegmentCount( KiROUND( radius ),
2114  ARC_HIGH_DEF, *w.curve ) - 1 );
2115  delta_angle = angle / segments;
2116  }
2117 
2118  while( fabs( angle ) > fabs( delta_angle ) )
2119  {
2120  wxASSERT( radius > 0.0 );
2121  wxPoint end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
2122  KiROUND( radius * sin( end_angle + angle ) + center.y ) );
2123 
2124  TRACK* t = new TRACK( m_board );
2125 
2126  t->SetTimeStamp( EagleTimeStamp( netItem ) + int( RAD2DEG( angle ) ) );
2127  t->SetPosition( start );
2128  t->SetEnd( end );
2129  t->SetWidth( width );
2130  t->SetLayer( layer );
2131  t->SetNetCode( netCode );
2132 
2133  m_board->Add( t );
2134 
2135  start = end;
2136  angle -= delta_angle;
2137  }
2138 
2139  TRACK* t = new TRACK( m_board );
2140 
2141  t->SetTimeStamp( EagleTimeStamp( netItem ) );
2142  t->SetPosition( start );
2143  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2144  t->SetWidth( width );
2145  t->SetLayer( layer );
2146  t->SetNetCode( netCode );
2147 
2148  m_board->Add( t );
2149  }
2150  else
2151  {
2152  // put non copper wires where the sun don't shine.
2153  }
2154 
2155  m_xpath->pop();
2156  }
2157 
2158  else if( itemName == "via" )
2159  {
2160  m_xpath->push( "via" );
2161  EVIA v( netItem );
2162 
2163  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2164  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2165 
2166  if( IsCopperLayer( layer_front_most ) &&
2167  IsCopperLayer( layer_back_most ) )
2168  {
2169  int kidiam;
2170  int drillz = v.drill.ToPcbUnits();
2171  VIA* via = new VIA( m_board );
2172  m_board->Add( via );
2173 
2174  via->SetLayerPair( layer_front_most, layer_back_most );
2175 
2176  if( v.diam )
2177  {
2178  kidiam = v.diam->ToPcbUnits();
2179  via->SetWidth( kidiam );
2180  }
2181  else
2182  {
2183  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2184  annulus = eagleClamp( m_rules->rlMinViaOuter, annulus,
2186  kidiam = KiROUND( drillz + 2 * annulus );
2187  via->SetWidth( kidiam );
2188  }
2189 
2190  via->SetDrill( drillz );
2191 
2192  // make sure the via diameter respects the restring rules
2193 
2194  if( !v.diam || via->GetWidth() <= via->GetDrill() )
2195  {
2196  double annulus = eagleClamp( m_rules->rlMinViaOuter,
2197  (double)( via->GetWidth() / 2 - via->GetDrill() ),
2199  via->SetWidth( drillz + 2 * annulus );
2200  }
2201 
2202  if( kidiam < m_min_via )
2203  m_min_via = kidiam;
2204 
2205  if( drillz < m_min_via_hole )
2206  m_min_via_hole = drillz;
2207 
2208  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2209  via->SetViaType( VIA_THROUGH );
2210  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2211  via->SetViaType( VIA_MICROVIA );
2212  else
2213  via->SetViaType( VIA_BLIND_BURIED );
2214 
2215  via->SetTimeStamp( EagleTimeStamp( netItem ) );
2216 
2217  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2218 
2219  via->SetPosition( pos );
2220  via->SetEnd( pos );
2221 
2222  via->SetNetCode( netCode );
2223  }
2224 
2225  m_xpath->pop();
2226  }
2227 
2228  else if( itemName == "contactref" )
2229  {
2230  m_xpath->push( "contactref" );
2231  // <contactref element="RN1" pad="7"/>
2232 
2233  const wxString& reference = netItem->GetAttribute( "element" );
2234  const wxString& pad = netItem->GetAttribute( "pad" );
2235  wxString key = makeKey( reference, pad ) ;
2236 
2237  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, netName.c_str() );)
2238 
2239  m_pads_to_nets[ key ] = ENET( netCode, netName );
2240 
2241  m_xpath->pop();
2242 
2243  sawPad = true;
2244  }
2245 
2246  else if( itemName == "polygon" )
2247  {
2248  m_xpath->push( "polygon" );
2249  auto* zone = loadPolygon( netItem );
2250 
2251  if( zone )
2252  {
2253  zones.push_back( zone );
2254 
2255  if( !zone->GetIsKeepout() )
2256  zone->SetNetCode( netCode );
2257  }
2258 
2259  m_xpath->pop(); // "polygon"
2260  }
2261 
2262  netItem = netItem->GetNext();
2263  }
2264 
2265  if( zones.size() && !sawPad )
2266  {
2267  // KiCad does not support an unconnected zone with its own non-zero netcode,
2268  // but only when assigned netcode = 0 w/o a name...
2269  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2270  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2271 
2272  // therefore omit this signal/net.
2273  }
2274  else
2275  netCode++;
2276 
2277  // Get next signal
2278  net = net->GetNext();
2279  }
2280 
2281  m_xpath->pop(); // "signals.signal"
2282 }
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:75
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
static T eagleClamp(T aMin, T aValue, T aMax)
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:347
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:320
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:105
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
double RAD2DEG(double rad)
Definition: trigo.h:211
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:190
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:73
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:174
void SetWidth(int aWidth)
Definition: class_track.h:102
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:191
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.
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:361
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
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.
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:189
Eagle net.
Definition: eagle_parser.h:462
Eagle via.
Definition: eagle_parser.h:556
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetWidth() const
Definition: class_track.h:103
double DEG2RAD(double deg)
Definition: trigo.h:210
#define max(a, b)
Definition: auxiliary.h:86
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:99
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)
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:354
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:179
Eagle wire.
Definition: eagle_parser.h:500
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void pop()
Definition: eagle_parser.h:124
std::vector< ZONE_CONTAINER * > ZONES
Definition: eagle_plugin.h:39
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:74
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:463
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:127

References BOARD::Add(), PNS::angle(), B_Cu, ConvertArcCenter(), EWIRE::curve, DEG2RAD(), EVIA::diam, EVIA::drill, eagleClamp(), EagleTimeStamp(), escapeName(), F_Cu, GetArcToSegmentCount(), VIA::GetDrill(), TRACK::GetWidth(), IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EWIRE::layer, EVIA::layer_back_most, EVIA::layer_front_most, loadPolygon(), m_board, m_min_trace, m_min_via, m_min_via_hole, m_pads_to_nets, m_rules, m_xpath, makeKey(), max, XPATH::pop(), XPATH::push(), RAD2DEG(), ERULES::rlMaxViaOuter, ERULES::rlMinViaOuter, ERULES::rvViaOuter, VIA::SetDrill(), TRACK::SetEnd(), BOARD_ITEM::SetLayer(), VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), TRACK::SetPosition(), VIA::SetPosition(), EDA_ITEM::SetTimeStamp(), VIA::SetViaType(), TRACK::SetWidth(), ECOORD::ToPcbUnits(), NETINFO_LIST::UNCONNECTED, XPATH::Value(), VIA, VIA_BLIND_BURIED, VIA_MICROVIA, VIA_THROUGH, EWIRE::width, EVIA::x, EWIRE::x1, EWIRE::x2, EVIA::y, EWIRE::y1, and EWIRE::y2.

Referenced by loadAllSections().

◆ makeModule()

MODULE * EAGLE_PLUGIN::makeModule ( wxXmlNode *  aPackage,
const wxString &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 1406 of file eagle_plugin.cpp.

1407 {
1408  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1409 
1410  LIB_ID fpID;
1411  fpID.Parse( aPkgName, LIB_ID::ID_PCB, true );
1412  m->SetFPID( fpID );
1413 
1414  // Get the first package item and iterate
1415  wxXmlNode* packageItem = aPackage->GetChildren();
1416 
1417  while( packageItem )
1418  {
1419  const wxString& itemName = packageItem->GetName();
1420 
1421  if( itemName == "description" )
1422  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1423 
1424  else if( itemName == "wire" )
1425  packageWire( m.get(), packageItem );
1426 
1427  else if( itemName == "pad" )
1428  packagePad( m.get(), packageItem );
1429 
1430  else if( itemName == "text" )
1431  packageText( m.get(), packageItem );
1432 
1433  else if( itemName == "rectangle" )
1434  packageRectangle( m.get(), packageItem );
1435 
1436  else if( itemName == "polygon" )
1437  packagePolygon( m.get(), packageItem );
1438 
1439  else if( itemName == "circle" )
1440  packageCircle( m.get(), packageItem );
1441 
1442  else if( itemName == "hole" )
1443  packageHole( m.get(), packageItem, false );
1444 
1445  else if( itemName == "smd" )
1446  packageSMD( m.get(), packageItem );
1447 
1448  packageItem = packageItem->GetNext();
1449  }
1450 
1451  return m.release();
1452 }
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:62
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:187
void packageText(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 packageHole(MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTr...
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const

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

Referenced by loadLibrary().

◆ orientModuleAndText()

void EAGLE_PLUGIN::orientModuleAndText ( MODULE m,
const EELEMENT e,
const EATTR nameAttr,
const EATTR valueAttr 
)
private

Definition at line 1253 of file eagle_plugin.cpp.

1255 {
1256  if( e.rot )
1257  {
1258  if( e.rot->mirror )
1259  {
1260  double orientation = e.rot->degrees + 180.0;
1261  m->SetOrientation( orientation * 10 );
1262  m->Flip( m->GetPosition(), false );
1263  }
1264  else
1265  m->SetOrientation( e.rot->degrees * 10 );
1266  }
1267 
1268  orientModuleText( m, e, &m->Reference(), nameAttr );
1269  orientModuleText( m, e, &m->Value(), valueAttr );
1270 }
bool mirror
Definition: eagle_parser.h:481
TEXTE_MODULE & Reference()
Definition: class_module.h:448
opt_erot rot
Definition: eagle_parser.h:808
double degrees
Definition: eagle_parser.h:483
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:447
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
void SetOrientation(double newangle)
const wxPoint GetPosition() const override
Definition: class_module.h:188
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)

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

Referenced by loadElements().

◆ orientModuleText()

void EAGLE_PLUGIN::orientModuleText ( MODULE m,
const EELEMENT e,
TEXTE_MODULE txt,
const EATTR a 
)
private

Definition at line 1273 of file eagle_plugin.cpp.

1275 {
1276  // Smashed part ?
1277  if( aAttr )
1278  { // Yes
1279  const EATTR& a = *aAttr;
1280 
1281  if( a.value )
1282  {
1283  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1284  }
1285 
1286  if( a.x && a.y ) // OPT
1287  {
1288  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1289  txt->SetTextPos( pos );
1290  }
1291 
1292  // Even though size and ratio are both optional, I am not seeing
1293  // a case where ratio is present but size is not.
1294  double ratio = 8;
1295  wxSize fontz = txt->GetTextSize();
1296 
1297  if( a.size )
1298  {
1299  fontz = kicad_fontz( *a.size );
1300  txt->SetTextSize( fontz );
1301 
1302  if( a.ratio )
1303  ratio = *a.ratio;
1304  }
1305 
1306  int lw = int( fontz.y * ratio / 100 );
1307  txt->SetThickness( lw );
1308 
1309  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1310 
1311  if( a.align )
1312  align = a.align;
1313 
1314  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1315  // present, and this zero rotation becomes an override to the
1316  // package's text field. If they did not want zero, they specify
1317  // what they want explicitly.
1318  double degrees = a.rot ? a.rot->degrees : 0;
1319  double orient; // relative to parent
1320 
1321  int sign = 1;
1322  bool spin = false;
1323 
1324  if( a.rot )
1325  {
1326  spin = a.rot->spin;
1327  sign = a.rot->mirror ? -1 : 1;
1328  txt->SetMirrored( a.rot->mirror );
1329  }
1330 
1331  if( degrees == 90 || degrees == 0 || spin )
1332  {
1333  orient = degrees - m->GetOrientation() / 10;
1334  txt->SetTextAngle( sign * orient * 10 );
1335  }
1336  else if( degrees == 180 )
1337  {
1338  orient = 0 - m->GetOrientation() / 10;
1339  txt->SetTextAngle( sign * orient * 10 );
1340  align = -align;
1341  }
1342  else if( degrees == 270 )
1343  {
1344  orient = 90 - m->GetOrientation() / 10;
1345  align = -align;
1346  txt->SetTextAngle( sign * orient * 10 );
1347  }
1348  else
1349  {
1350  orient = 90 - degrees - m->GetOrientation() / 10;
1351  txt->SetTextAngle( sign * orient * 10 );
1352  }
1353 
1354  switch( align )
1355  {
1356  case ETEXT::TOP_RIGHT:
1359  break;
1360 
1361  case ETEXT::BOTTOM_LEFT:
1364  break;
1365 
1366  case ETEXT::TOP_LEFT:
1369  break;
1370 
1371  case ETEXT::BOTTOM_RIGHT:
1374  break;
1375 
1376  case ETEXT::TOP_CENTER:
1379  break;
1380 
1381  case ETEXT::BOTTOM_CENTER:
1384  break;
1385 
1386  default:
1387  ;
1388  }
1389  }
1390  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1391  {
1392  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1393 
1394  // @todo there are a few more cases than these to contend with:
1395  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1396  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1397  {
1398  // ETEXT::TOP_RIGHT:
1401  }
1402  }
1403 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
bool mirror
Definition: eagle_parser.h:481
double GetOrientation() const
Definition: class_module.h:193
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
bool IsMirrored() const
Definition: eda_text.h:173
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:62
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:229
double GetTextAngle() const
Definition: eda_text.h:158
double degrees
Definition: eagle_parser.h:483
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:220
#define abs(a)
Definition: auxiliary.h:84
opt_erot rot
Definition: eagle_parser.h:612
opt_int align
Definition: eagle_parser.h:621
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:112
opt_ecoord y
Definition: eagle_parser.h:608
const wxSize & GetTextSize() const
Definition: eda_text.h:221
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
opt_wxString value
Definition: eagle_parser.h:606
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:603
opt_ecoord x
Definition: eagle_parser.h:607
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
opt_double ratio
Definition: eagle_parser.h:611
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetTextAngle(double aAngle)
bool spin
Definition: eagle_parser.h:482
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
opt_ecoord size
Definition: eagle_parser.h:609
int sign(T val)
Definition: math_util.h:44

References abs, EATTR::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, EROT::degrees, FROM_UTF8(), MODULE::GetOrientation(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_CENTER, 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_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, EATTR::value, EATTR::x, and EATTR::y.

Referenced by orientModuleAndText().

◆ packageCircle()

void EAGLE_PLUGIN::packageCircle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1837 of file eagle_plugin.cpp.

1838 {
1839  ECIRCLE e( aTree );
1840  PCB_LAYER_ID layer = kicad_layer( e.layer );
1841  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1842  int width = e.width.ToPcbUnits();
1843  int radius = e.radius.ToPcbUnits();
1844 
1845  // with == 0 means filled circle
1846  if( width <= 0 )
1847  {
1848  width = radius;
1849  radius = radius / 2;
1850  }
1851 
1852  aModule->Add( gr );
1853  gr->SetWidth( width );
1854 
1855  switch ( (int) layer )
1856  {
1857  case UNDEFINED_LAYER:
1858  layer = Cmts_User;
1859  break;
1860  default:
1861  break;
1862  }
1863 
1864  gr->SetLayer( layer );
1865  gr->SetTimeStamp( EagleTimeStamp( aTree ) );
1866  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1867  gr->SetEnd0( wxPoint( kicad_x( e.x ) + radius, kicad_y( e.y ) ) );
1868  gr->SetDrawCoord();
1869 }
void SetEnd0(const wxPoint &aPoint)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Eagle circle.
Definition: eagle_parser.h:571
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
void SetWidth(int aWidth)

References MODULE::Add(), Cmts_User, EagleTimeStamp(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, 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().

◆ packageHole()

void EAGLE_PLUGIN::packageHole ( MODULE aModule,
wxXmlNode *  aTree,
bool  aCenter 
) const
private

Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTree - The Eagle XML node that is of type "hole" @parameter aCenter - If true, center the hole in the module and offset the module position.

Definition at line 1872 of file eagle_plugin.cpp.

1873 {
1874  EHOLE e( aTree );
1875 
1876  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1877  D_PAD* pad = new D_PAD( aModule );
1878  aModule->Add( pad );
1879 
1880  pad->SetShape( PAD_SHAPE_CIRCLE );
1882 
1883  // Mechanical purpose only:
1884  // no offset, no net name, no pad name allowed
1885  // pad->SetOffset( wxPoint( 0, 0 ) );
1886  // pad->SetName( wxEmptyString );
1887 
1888  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1889 
1890  if( aCenter )
1891  {
1892  pad->SetPos0( wxPoint( 0, 0 ) );
1893  aModule->SetPosition( padpos );
1894  pad->SetPosition( padpos );
1895  }
1896  else
1897  {
1898  pad->SetPos0( padpos );
1899  pad->SetPosition( padpos + aModule->GetPosition() );
1900  }
1901 
1902  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
1903 
1904  pad->SetDrillSize( sz );
1905  pad->SetSize( sz );
1906 
1907  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1908 }
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:676
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:224
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:289
Eagle hole element.
Definition: eagle_parser.h:787
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:277
void SetSize(const wxSize &aSize)
Definition: class_pad.h:283
void SetPosition(const wxPoint &aPos) override
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:421
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:425
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:222
const wxPoint GetPosition() const override
Definition: class_module.h:188
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202

References MODULE::Add(), LSET::AllCuMask(), B_Mask, EHOLE::drill, F_Mask, MODULE::GetPosition(), kicad_x(), kicad_y(), PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CIRCLE, D_PAD::SetAttribute(), D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetPos0(), MODULE::SetPosition(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), ECOORD::ToPcbUnits(), EHOLE::x, and EHOLE::y.

Referenced by loadPlain(), and makeModule().

◆ packagePad()

void EAGLE_PLUGIN::packagePad ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1524 of file eagle_plugin.cpp.

1525 {
1526  // this is thru hole technology here, no SMDs
1527  EPAD e( aTree );
1528  int shape = EPAD::UNDEF;
1529 
1530  D_PAD* pad = new D_PAD( aModule );
1531  aModule->Add( pad );
1532  transferPad( e, pad );
1533 
1534  if( e.first && *e.first && m_rules->psFirst != EPAD::UNDEF )
1535  shape = m_rules->psFirst;
1536  else if( aModule->GetLayer() == F_Cu && m_rules->psTop != EPAD::UNDEF )
1537  shape = m_rules->psTop;
1538  else if( aModule->GetLayer() == B_Cu && m_rules->psBottom != EPAD::UNDEF )
1539  shape = m_rules->psBottom;
1540 
1541  pad->SetDrillSize( wxSize( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() ) );
1542  pad->SetLayerSet( LSET::AllCuMask() );
1543 
1544  // Solder mask
1545  if( !e.stop || *e.stop == true ) // enabled by default
1546  pad->SetLayerSet( pad->GetLayerSet().set( B_Mask ).set( F_Mask ) );
1547 
1548  if( shape == EPAD::ROUND || shape == EPAD::SQUARE || shape == EPAD::OCTAGON )
1549  e.shape = shape;
1550 
1551  if( e.shape )
1552  {
1553  switch( *e.shape )
1554  {
1555  case EPAD::ROUND:
1556  pad->SetShape( PAD_SHAPE_CIRCLE );
1557  break;
1558 
1559  case EPAD::OCTAGON:
1560  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1561  // pad->SetShape( PAD_OCTAGON );
1562  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1565  pad->SetChamferRectRatio( 0.25 );
1566  break;
1567 
1568  case EPAD::LONG:
1569  pad->SetShape( PAD_SHAPE_OVAL );
1570  break;
1571 
1572  case EPAD::SQUARE:
1573  pad->SetShape( PAD_SHAPE_RECT );
1574  break;
1575 
1576  case EPAD::OFFSET:
1577  pad->SetShape( PAD_SHAPE_OVAL );
1578  break;
1579  }
1580  }
1581  else
1582  {
1583  // if shape is not present, our default is circle and that matches their default "round"
1584  }
1585 
1586  if( e.diameter )
1587  {
1588  int diameter = e.diameter->ToPcbUnits();
1589  pad->SetSize( wxSize( diameter, diameter ) );
1590  }
1591  else
1592  {
1593  double drillz = pad->GetDrillSize().x;
1594  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1595  annulus = eagleClamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1596  int diameter = KiROUND( drillz + 2 * annulus );
1597  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1598  }
1599 
1600  if( pad->GetShape() == PAD_SHAPE_OVAL )
1601  {
1602  // The Eagle "long" pad is wider than it is tall,
1603  // m_elongation is percent elongation
1604  wxSize sz = pad->GetSize();
1605  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1606  pad->SetSize( sz );
1607 
1608  if( e.shape && *e.shape == EPAD::OFFSET )
1609  {
1610  int offset = KiROUND( ( sz.x - sz.y ) / 2.0 );
1611  pad->SetOffset( wxPoint( offset, 0 ) );
1612  }
1613  }
1614 
1615  if( e.rot )
1616  {
1617  pad->SetOrientation( e.rot->degrees * 10 );
1618  }
1619 }
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:676
static T eagleClamp(T aMin, T aValue, T aMax)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:59
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:71
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:289
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Eagle thru hole pad.
Definition: eagle_parser.h:694
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:426
void SetSize(const wxSize &aSize)
Definition: class_pad.h:283
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:47
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:61
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:425
const wxSize & GetDrillSize() const
Definition: class_pad.h:290
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:222
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:430
void SetChamferRectRatio(double aChamferScale)
has meaning only for chamfered rect pads Set the ratio between the smaller Y or Y size and the radius...
Definition: class_pad.h:681
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:67
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:221
const wxSize & GetSize() const
Definition: class_pad.h:284
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:292
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:60
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:70
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void SetChamferPositions(int aChamferPositions)
has meaning only for chamfered rect pads set the position of the chamfer for a 0 orientation,...
Definition: class_pad.h:701

References MODULE::Add(), LSET::AllCuMask(), B_Cu, B_Mask, EROT::degrees, EPAD::diameter, EPAD::drill, eagleClamp(), F_Cu, F_Mask, EPAD::first, D_PAD::GetDrillSize(), BOARD_ITEM::GetLayer(), D_PAD::GetLayerSet(), D_PAD::GetShape(), D_PAD::GetSize(), KiROUND(), EPAD::LONG, m_rules, EPAD::OCTAGON, EPAD::OFFSET, PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, ERULES::psBottom, ERULES::psElongationLong, ERULES::psFirst, ERULES::psTop, RECT_CHAMFER_ALL, ERULES::rlMaxPadTop, ERULES::rlMinPadTop, EPAD_COMMON::rot, EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetChamferPositions(), D_PAD::SetChamferRectRatio(), D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetOffset(), D_PAD::SetOrientation(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, EPAD_COMMON::stop, ECOORD::ToPcbUnits(), transferPad(), and EPAD::UNDEF.

Referenced by makeModule().

◆ packagePolygon()

void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1763 of file eagle_plugin.cpp.

1764 {
1765  EPOLYGON p( aTree );
1766  PCB_LAYER_ID layer = kicad_layer( p.layer );
1767  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1768 
1769  aModule->Add( dwg );
1770 
1771  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1772  dwg->SetLayer( layer );
1773  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1774 
1775  std::vector<wxPoint> pts;
1776 
1777  // Get the first vertex and iterate
1778  wxXmlNode* vertex = aTree->GetChildren();
1779  std::vector<EVERTEX> vertices;
1780 
1781  // Create a circular vector of vertices
1782  // The "curve" parameter indicates a curve from the current
1783  // to the next vertex, so we keep the first at the end as well
1784  // to allow the curve to link back
1785  while( vertex )
1786  {
1787  if( vertex->GetName() == "vertex" )
1788  vertices.push_back( EVERTEX( vertex ) );
1789 
1790  vertex = vertex->GetNext();
1791  }
1792 
1793  vertices.push_back( vertices[0] );
1794 
1795  for( size_t i = 0; i < vertices.size() - 1; i++ )
1796  {
1797  EVERTEX v1 = vertices[i];
1798 
1799  // Append the corner
1800  pts.push_back( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ) );
1801 
1802  if( v1.curve )
1803  {
1804  EVERTEX v2 = vertices[i + 1];
1805  wxPoint center = ConvertArcCenter(
1806  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1807  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1808  double angle = DEG2RAD( *v1.curve );
1809  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1810  kicad_x( v2.x ) - center.x );
1811  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1812  + pow( center.y - kicad_y( v1.y ), 2 ) );
1813 
1814  // If we are curving, we need at least 2 segments otherwise
1815  // delta_angle == angle
1816  double delta_angle = angle / std::max(
1817  2, GetArcToSegmentCount( KiROUND( radius ),
1818  ARC_HIGH_DEF, *v1.curve ) - 1 );
1819 
1820  for( double a = end_angle + angle;
1821  fabs( a - end_angle ) > fabs( delta_angle );
1822  a -= delta_angle )
1823  {
1824  pts.push_back(
1825  wxPoint( KiROUND( radius * cos( a ) ),
1826  KiROUND( radius * sin( a ) ) ) + center );
1827  }
1828  }
1829  }
1830 
1831  dwg->SetPolyPoints( pts );
1832  dwg->SetStart0( *pts.begin() );
1833  dwg->SetEnd0( pts.back() );
1834  dwg->SetDrawCoord();
1835 }
Eagle vertex.
Definition: eagle_parser.h:747
void SetEnd0(const wxPoint &aPoint)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
ECOORD y
Definition: eagle_parser.h:750
polygon (not yet used for tracks, but could be in microwave apps)
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:751
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
ECOORD x
Definition: eagle_parser.h:749
double DEG2RAD(double deg)
Definition: trigo.h:210
#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
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)
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:758
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
void SetWidth(int aWidth)

References MODULE::Add(), PNS::angle(), ConvertArcCenter(), EVERTEX::curve, DEG2RAD(), EagleTimeStamp(), GetArcToSegmentCount(), i, kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, max, S_POLYGON, EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), EVERTEX::x, and EVERTEX::y.

Referenced by makeModule().

◆ packageRectangle()

void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1728 of file eagle_plugin.cpp.

1729 {
1730  ERECT r( aTree );
1731  PCB_LAYER_ID layer = kicad_layer( r.layer );
1732  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1733 
1734  aModule->Add( dwg );
1735 
1736  dwg->SetLayer( layer );
1737  dwg->SetWidth( 0 );
1738 
1739  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1740 
1741  std::vector<wxPoint> pts;
1742 
1743  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1744  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1745 
1746  pts.push_back( start );
1747  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1748  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1749  pts.push_back( end );
1750 
1751  dwg->SetPolyPoints( pts );
1752 
1753  dwg->SetStart0( start );
1754  dwg->SetEnd0( end );
1755 
1756  if( r.rot )
1757  {
1758  dwg->Rotate( dwg->GetCenter(), r.rot->degrees * 10 );
1759  }
1760 }
void SetEnd0(const wxPoint &aPoint)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
const wxPoint GetCenter() const override
Function GetCenter()
polygon (not yet used for tracks, but could be in microwave apps)
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
Eagle XML rectangle in binary.
Definition: eagle_parser.h:584
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void SetStart0(const wxPoint &aPoint)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
void SetWidth(int aWidth)

References MODULE::Add(), EROT::degrees, EagleTimeStamp(), DRAWSEGMENT::GetCenter(), kicad_layer(), kicad_x(), kicad_y(), ERECT::layer, 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().

◆ packageSMD()

void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1911 of file eagle_plugin.cpp.

1912 {
1913  ESMD e( aTree );
1914  PCB_LAYER_ID layer = kicad_layer( e.layer );
1915 
1916  if( !IsCopperLayer( layer ) )
1917  return;
1918 
1919  bool shape_set = false;
1920  int shape = EPAD::UNDEF;
1921  D_PAD* pad = new D_PAD( aModule );
1922  aModule->Add( pad );
1923  transferPad( e, pad );
1924 
1925  if( pad->GetName() == wxT( "1" ) && m_rules->psFirst != EPAD::UNDEF )
1926  shape = m_rules->psFirst;
1927  else if( layer == F_Cu && m_rules->psTop != EPAD::UNDEF )
1928  shape = m_rules->psTop;
1929  else if( layer == B_Cu && m_rules->psBottom != EPAD::UNDEF )
1930  shape = m_rules->psBottom;
1931 
1932  switch( shape )
1933  {
1934  case EPAD::ROUND:
1935  case EPAD::OCTAGON:
1936  shape_set = true;
1937  pad->SetShape( PAD_SHAPE_CIRCLE );
1938  break;
1939 
1940  case EPAD::SQUARE:
1941  shape_set = true;
1942  pad->SetShape( PAD_SHAPE_RECT );
1943  break;
1944 
1945  default:
1946  pad->SetShape( PAD_SHAPE_RECT );
1947  }
1948 
1949  pad->SetAttribute( PAD_ATTRIB_SMD );
1950 
1951  wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
1952  pad->SetSize( padSize );
1953  pad->SetLayer( layer );
1954 
1955  const LSET front( 3, F_Cu, F_Paste, F_Mask );
1956  const LSET back( 3, B_Cu, B_Paste, B_Mask );
1957 
1958  if( layer == F_Cu )
1959  pad->SetLayerSet( front );
1960  else if( layer == B_Cu )
1961  pad->SetLayerSet( back );
1962 
1963  int minPadSize = std::min( padSize.x, padSize.y );
1964 
1965  // Rounded rectangle pads
1966  int roundRadius = eagleClamp( m_rules->srMinRoundness * 2,
1967  (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
1968 
1969  if( !shape_set && ( e.roundness || roundRadius > 0 ) )
1970  {
1971  double roundRatio = (double) roundRadius / minPadSize / 2.0;
1972 
1973  // Eagle uses a different definition of roundness, hence division by 200
1974  if( e.roundness )
1975  roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
1976 
1977  pad->SetShape( PAD_SHAPE_ROUNDRECT );
1978  pad->SetRoundRectRadiusRatio( roundRatio );
1979  }
1980 
1981  if( e.rot )
1982  {
1983  pad->SetOrientation( e.rot->degrees * 10 );
1984  }
1985 
1987  (int) ( m_rules->mvCreamFrame * minPadSize ),
1988  m_rules->mlMaxCreamFrame ) );
1989 
1990  // Solder mask
1991  if( e.stop && *e.stop == false ) // enabled by default
1992  {
1993  if( layer == F_Cu )
1994  pad->SetLayerSet( pad->GetLayerSet().set( F_Mask, false ) );
1995  else if( layer == B_Cu )
1996  pad->SetLayerSet( pad->GetLayerSet().set( B_Mask, false ) );
1997  }
1998 
1999  // Solder paste (only for SMD pads)
2000  if( e.cream && *e.cream == false ) // enabled by default
2001  {
2002  if( layer == F_Cu )
2003  pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
2004  else if( layer == B_Cu )
2005  pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
2006  }
2007 }
static T eagleClamp(T aMin, T aValue, T aMax)
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:59
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:173
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:64
Eagle SMD pad.
Definition: eagle_parser.h:716
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:656
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
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:426
const wxString & GetName() const
Definition: class_pad.h:195
void SetSize(const wxSize &aSize)
Definition: class_pad.h:283
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:63
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:421
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:61
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:425
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:56
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:222
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:430
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_pad.h:445
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:60
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:57
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:65
#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:53

References MODULE::Add(), B_Cu, B_Mask, B_Paste, ESMD::cream, EROT::degrees, ESMD::dx, ESMD::dy, eagleClamp(), F_Cu, F_Mask, F_Paste, D_PAD::GetLayerSet(), D_PAD::GetName(), IsCopperLayer(), kicad_layer(), ESMD::layer, m_rules, min, ERULES::mlMaxCreamFrame, ERULES::mlMinCreamFrame, ERULES::mvCreamFrame, EPAD::OCTAGON, PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, ERULES::psBottom, ERULES::psFirst, ERULES::psTop, EPAD_COMMON::rot, EPAD::ROUND, 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(), EPAD::SQUARE, ERULES::srMaxRoundness, ERULES::srMinRoundness, ERULES::srRoundness, EPAD_COMMON::stop, ECOORD::ToPcbUnits(), transferPad(), and EPAD::UNDEF.

Referenced by makeModule().

◆ packageText()

void EAGLE_PLUGIN::packageText ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1622 of file eagle_plugin.cpp.

1623 {
1624  ETEXT t( aTree );
1625  PCB_LAYER_ID layer = kicad_layer( t.layer );
1626 
1627  if( layer == UNDEFINED_LAYER )
1628  {
1629  layer = Cmts_User;
1630  }
1631 
1632  TEXTE_MODULE* txt;
1633 
1634  if( t.text == ">NAME" || t.text == ">name" )
1635  txt = &aModule->Reference();
1636  else if( t.text == ">VALUE" || t.text == ">value" )
1637  txt = &aModule->Value();
1638  else
1639  {
1640  // FIXME: graphical text items are rotated for some reason.
1641  txt = new TEXTE_MODULE( aModule );
1642  aModule->Add( txt );
1643  }
1644 
1645  txt->SetTimeStamp( EagleTimeStamp( aTree ) );
1646  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1647 
1648  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1649 
1650  txt->SetTextPos( pos );
1651  txt->SetPos0( pos - aModule->GetPosition() );
1652 
1653  txt->SetLayer( layer );
1654  txt->SetTextSize( kicad_fontz( t.size ) );
1655 
1656  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1657 
1658  txt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
1659 
1660  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1661 
1662  // An eagle package is never rotated, the DTD does not allow it.
1663  // angle -= aModule->GetOrienation();
1664 
1665  if( t.rot )
1666  {
1667  int sign = t.rot->mirror ? -1 : 1;
1668  txt->SetMirrored( t.rot->mirror );
1669 
1670  double degrees = t.rot->degrees;
1671 
1672  if( degrees == 90 || t.rot->spin )
1673  txt->SetTextAngle( sign * degrees * 10 );
1674  else if( degrees == 180 )
1675  align = ETEXT::TOP_RIGHT;
1676  else if( degrees == 270 )
1677  {
1678  align = ETEXT::TOP_RIGHT;
1679  txt->SetTextAngle( sign * 90 * 10 );
1680  }
1681  }
1682 
1683  switch( align )
1684  {
1685  case ETEXT::CENTER:
1686  // this was the default in pcbtxt's constructor
1687  break;
1688 
1689  case ETEXT::CENTER_LEFT:
1691  break;
1692 
1693  case ETEXT::CENTER_RIGHT:
1695  break;
1696 
1697  case ETEXT::TOP_CENTER:
1699  break;
1700 
1701  case ETEXT::TOP_LEFT:
1704  break;
1705 
1706  case ETEXT::TOP_RIGHT:
1709  break;
1710 
1711  case ETEXT::BOTTOM_CENTER:
1713  break;
1714 
1715  case ETEXT::BOTTOM_LEFT:
1718  break;
1719 
1720  case ETEXT::BOTTOM_RIGHT:
1723  break;
1724  }
1725 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
TEXTE_MODULE & Reference()
Definition: class_module.h:448
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:62
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:229
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:220
Eagle text element.
Definition: eagle_parser.h:646
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:112
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:447
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
void SetPos0(const wxPoint &aPos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetTextAngle(double aAngle)
const wxPoint GetPosition() const override
Definition: class_module.h:188
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
int sign(T val)
Definition: math_util.h:44

References MODULE::Add(), ETEXT::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Cmts_User, EROT::degrees, EagleTimeStamp(), FROM_UTF8(), MODULE::GetPosition(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), ETEXT::layer, EROT::mirror, 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().

◆ packageWire()

void EAGLE_PLUGIN::packageWire ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1455 of file eagle_plugin.cpp.

1456 {
1457  EWIRE w( aTree );
1458  PCB_LAYER_ID layer = kicad_layer( w.layer );
1459  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1460  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1461  int width = w.width.ToPcbUnits();
1462 
1463  // KiCad cannot handle zero or negative line widths which apparently have meaning in Eagle.
1464  if( width <= 0 )
1465  {
1466  BOARD* board = aModule->GetBoard();
1467 
1468  if( board )
1469  {
1470  width = board->GetDesignSettings().GetLineThickness( layer );
1471  }
1472  else
1473  {
1474  // When loading footprint libraries, there is no board so use the default KiCad
1475  // line widths.
1476  switch( layer )
1477  {
1478  case Edge_Cuts:
1479  width = Millimeter2iu( DEFAULT_EDGE_WIDTH );
1480  break;
1481  case F_SilkS:
1482  case B_SilkS:
1483  width = Millimeter2iu( DEFAULT_SILK_LINE_WIDTH );
1484  break;
1485  case F_CrtYd:
1486  case B_CrtYd:
1487  width = Millimeter2iu( DEFAULT_COURTYARD_WIDTH );
1488  break;
1489  default:
1490  width = Millimeter2iu( DEFAULT_LINE_WIDTH );
1491  }
1492  }
1493  }
1494 
1495  // FIXME: the cap attribute is ignored because KiCad can't create lines
1496  // with flat ends.
1497  EDGE_MODULE* dwg;
1498 
1499  if( !w.curve )
1500  {
1501  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1502 
1503  dwg->SetStart0( start );
1504  dwg->SetEnd0( end );
1505  }
1506  else
1507  {
1508  dwg = new EDGE_MODULE( aModule, S_ARC );
1509  wxPoint center = ConvertArcCenter( start, end, *w.curve );
1510 
1511  dwg->SetStart0( center );
1512  dwg->SetEnd0( start );
1513  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1514  }
1515 
1516  dwg->SetLayer( layer );
1517  dwg->SetWidth( width );
1518  dwg->SetDrawCoord();
1519 
1520  aModule->Add( dwg );
1521 }
#define DEFAULT_EDGE_WIDTH
void SetEnd0(const wxPoint &aPoint)
#define DEFAULT_COURTYARD_WIDTH
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
#define DEFAULT_LINE_WIDTH
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
usual segment : line with rounded ends
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
#define DEFAULT_SILK_LINE_WIDTH
Arcs (with rounded ends)
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
Eagle wire.
Definition: eagle_parser.h:500
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
void SetWidth(int aWidth)

References MODULE::Add(), B_CrtYd, B_SilkS, ConvertArcCenter(), EWIRE::curve, DEFAULT_COURTYARD_WIDTH, DEFAULT_EDGE_WIDTH, DEFAULT_LINE_WIDTH, DEFAULT_SILK_LINE_WIDTH, Edge_Cuts, F_CrtYd, F_SilkS, BOARD_ITEM::GetBoard(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetLineThickness(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, S_ARC, S_SEGMENT, DRAWSEGMENT::SetAngle(), EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), DRAWSEGMENT::SetWidth(), ECOORD::ToPcbUnits(), EWIRE::width, EWIRE::x1, EWIRE::x2, EWIRE::y1, and EWIRE::y2.

Referenced by makeModule().

◆ PluginName()

const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 200 of file eagle_plugin.cpp.

201 {
202  return wxT( "Eagle" );
203 }

◆ PrefetchLib()

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

69 {
70  (void) aLibraryPath;
71  (void) aProperties;
72 }

◆ Save()

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

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

References not_implemented().

Referenced by IO_MGR::Save().

◆ transferPad()

void EAGLE_PLUGIN::transferPad ( const EPAD_COMMON aEaglePad,
D_PAD aPad 
) const
private

Handles common pad properties

Definition at line 2010 of file eagle_plugin.cpp.

2011 {
2012  aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) );
2013 
2014  // pad's "Position" is not relative to the module's,
2015  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2016  wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
2017  aPad->SetPos0( padPos );
2018 
2019  // Solder mask
2020  const wxSize& padSize( aPad->GetSize() );
2021 
2023  (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
2024  m_rules->mlMaxStopFrame ) );
2025 
2026  // Solid connection to copper zones
2027  if( aEaglePad.thermals && !*aEaglePad.thermals )
2029 
2030  MODULE* module = aPad->GetParent();
2031  wxCHECK( module, /* void */ );
2032  RotatePoint( &padPos, module->GetOrientation() );
2033  aPad->SetPosition( padPos + module->GetPosition() );
2034 }
double GetOrientation() const
Definition: class_module.h:193
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
static T eagleClamp(T aMin, T aValue, T aMax)
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:62
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:224
wxString name
Definition: eagle_parser.h:683
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
opt_bool thermals
Definition: eagle_parser.h:687
void SetZoneConnection(ZoneConnection aType)
Definition: class_pad.h:507
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:187
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:277
MODULE * GetParent() const
Definition: class_pad.h:167
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_pad.h:439
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:52
const wxSize & GetSize() const
Definition: class_pad.h:284
const wxPoint GetPosition() const override
Definition: class_module.h:188
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
#define min(a, b)
Definition: auxiliary.h:85
pads are covered by copper
Definition: zones.h:54
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55

References eagleClamp(), 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::thermals, EPAD_COMMON::x, and EPAD_COMMON::y.

Referenced by packagePad(), and packageSMD().

Member Data Documentation

◆ m_board

BOARD* EAGLE_PLUGIN::m_board
private

which BOARD is being worked on, no ownership here

Definition at line 187 of file eagle_plugin.h.

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

◆ m_cu_map

int EAGLE_PLUGIN::m_cu_map[17]
private

map eagle to kicad, cu layers only.

Definition at line 170 of file eagle_plugin.h.

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

◆ m_eagleLayers

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

Eagle layers data stored by the layer number.

Definition at line 171 of file eagle_plugin.h.

Referenced by eagle_layer_name(), and loadLayerDefs().

◆ m_hole_count

int EAGLE_PLUGIN::m_hole_count
private

generates unique module names from eagle "hole"s.

Definition at line 177 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

◆ m_lib_path

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 193 of file eagle_plugin.h.

Referenced by cacheLib(), and loadLibrary().

◆ m_min_trace

int EAGLE_PLUGIN::m_min_trace
private

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

Definition at line 189 of file eagle_plugin.h.

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

◆ m_min_via

int EAGLE_PLUGIN::m_min_via
private

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

Definition at line 190 of file eagle_plugin.h.

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

◆ m_min_via_hole

int EAGLE_PLUGIN::m_min_via_hole
private

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

Definition at line 191 of file eagle_plugin.h.

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

◆ m_mod_time

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 194 of file eagle_plugin.h.

Referenced by cacheLib().

◆ m_pads_to_nets

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

Definition at line 179 of file eagle_plugin.h.

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

◆ m_props

const PROPERTIES* EAGLE_PLUGIN::m_props
private

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

Definition at line 186 of file eagle_plugin.h.

Referenced by centerBoard(), and init().

◆ m_rules

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 173 of file eagle_plugin.h.

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

◆ m_templates

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

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

◆ m_xpath

XPATH* EAGLE_PLUGIN::m_xpath
private

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

Definition at line 174 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: