KiCad PCB EDA Suite
EAGLE_PLUGIN Class Reference

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 LAYER_REMAPPABLE_PLUGIN

Public Types

typedef int BIU
 

Public Member Functions

const wxString PluginName () const override
 Return a brief hard coded name for this PLUGIN. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr) override
 Load information from some input file format that this PLUGIN implementation knows about into either a new BOARD or an existing one. More...
 
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints () override
 Return a container with the cached library footprints generated in the last call to Load. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the PLUGIN. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
FOOTPRINTFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
 Load 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
 Return true if the library at aLibraryPath is writable. More...
 
void FootprintLibOptions (PROPERTIES *aProperties) const override
 Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
 EAGLE_PLUGIN ()
 
 ~EAGLE_PLUGIN ()
 
std::map< wxString, PCB_LAYER_IDDefaultLayerMappingCallback (const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
 Return the automapped layers. More...
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=nullptr)
 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=nullptr)
 If possible, prefetches the specified library (e.g. More...
 
virtual const FOOTPRINTGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr)
 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=nullptr)
 Check for the existence of a footprint. More...
 
virtual void FootprintSave (const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const PROPERTIES *aProperties=nullptr)
 Write aFootprint to an existing library located at aLibraryPath. More...
 
virtual void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr)
 Delete aFootprintName from the library at aLibraryPath. More...
 
virtual void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Create a new empty footprint library at aLibraryPath empty. More...
 
virtual bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Delete 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...
 
virtual void RegisterLayerMappingCallback (LAYER_MAPPING_HANDLER aLayerMappingHandler)
 Register a different handler to be called when mapping of input layers to KiCad layers occurs. More...
 

Protected Attributes

LAYER_MAPPING_HANDLER m_layer_mapping_handler
 Callback to get layer mapping. 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, int aTextThickness) const
 create a font size (fontz) from an eagle font size scalar and KiCad font thickness More...
 
void mapEagleLayersToKicad ()
 Generate mapping between Eagle na KiCad layers. More...
 
PCB_LAYER_ID kicad_layer (int aLayer) const
 Convert an Eagle layer to a KiCad layer. More...
 
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer (int aEagleLayer) const
 Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping options and required flag. More...
 
const wxString & eagle_layer_name (int aLayer) const
 Get Eagle layer name by its number. More...
 
int eagle_layer_id (const wxString &aLayerName) const
 Get Eagle layer number by its name. 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)
 Load 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)
 
ZONEloadPolygon (wxXmlNode *aPolyNode)
 Load a copper or keepout polygon and adds it to the board. More...
 
void orientFootprintAndText (FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
 
void orientFPText (FOOTPRINT *aFootprint, const EELEMENT &e, FP_TEXT *aFPText, const EATTR *aAttr)
 
void centerBoard ()
 move the BOARD into the center of the page More...
 
FOOTPRINTmakeFootprint (wxXmlNode *aPackage, const wxString &aPkgName)
 Create a FOOTPRINT from an Eagle package. More...
 
void packageWire (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 
void packagePad (FOOTPRINT *aFootprint, wxXmlNode *aTree)
 
void packageText (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 
void packageRectangle (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 
void packagePolygon (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 
void packageCircle (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 
void packageHole (FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
 
void packageSMD (FOOTPRINT *aFootprint, wxXmlNode *aTree) const
 Handles common pad properties. More...
 
void transferPad (const EPAD_COMMON &aEaglePad, PAD *aPad) const
 Deletes the footprint templates list. More...
 
void deleteTemplates ()
 

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 layer data stored by layer number. More...
 
std::map< wxString, int > m_eagleLayersIds
 Eagle layer ids stored by layer name. More...
 
std::map< wxString, PCB_LAYER_IDm_layer_map
 Map of Eagle layers to KiCad layers. 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 footprint names from eagle "hole"s. More...
 
NET_MAP m_pads_to_nets
 net list More...
 
FOOTPRINT_MAP m_templates
 is part of a FOOTPRINT 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_hole
 smallest diameter hole we find on Load(), in BIU. More...
 
int m_min_via
 smallest via we find on Load(), in BIU. More...
 
int m_min_annulus
 smallest via annulus we find on Load(), in BIU. More...
 
wxString m_lib_path
 
wxDateTime m_mod_time
 

Detailed Description

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

Definition at line 128 of file eagle_plugin.h.

Member Typedef Documentation

◆ BIU

typedef int EAGLE_PLUGIN::BIU

Definition at line 159 of file eagle_plugin.h.

◆ EITER

typedef ELAYERS::const_iterator EAGLE_PLUGIN::EITER
private

Definition at line 279 of file eagle_plugin.h.

◆ ELAYERS

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

Definition at line 278 of file eagle_plugin.h.

Constructor & Destructor Documentation

◆ EAGLE_PLUGIN()

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 270 of file eagle_plugin.cpp.

270  :
271  m_rules( new ERULES() ),
272  m_xpath( new XPATH() ),
273  m_mod_time( wxDateTime::Now() )
274 {
275  using namespace std::placeholders;
276 
277  init( NULL );
278  clear_cu_map();
279  RegisterLayerMappingCallback( std::bind(
281 }
void clear_cu_map()
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:110
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:287
virtual void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
#define NULL
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:49
wxDateTime m_mod_time
Definition: eagle_plugin.h:308

References clear_cu_map(), DefaultLayerMappingCallback(), init(), NULL, and LAYER_REMAPPABLE_PLUGIN::RegisterLayerMappingCallback().

◆ ~EAGLE_PLUGIN()

EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 284 of file eagle_plugin.cpp.

285 {
286  deleteTemplates();
287  delete m_rules;
288  delete m_xpath;
289 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
void deleteTemplates()

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

2747 {
2748  try
2749  {
2750  wxDateTime modtime = getModificationTime( aLibPath );
2751 
2752  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2753  // cache if either of the wxDateTime objects are invalid or the last file modification
2754  // time differs from the current file modification time.
2755  bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
2756 
2757  if( aLibPath != m_lib_path || load )
2758  {
2759  wxXmlNode* doc;
2760  LOCALE_IO toggle; // toggles on, then off, the C locale.
2761 
2762  deleteTemplates();
2763 
2764  // Set this before completion of loading, since we rely on it for
2765  // text of an exception. Delay setting m_mod_time until after successful load
2766  // however.
2767  m_lib_path = aLibPath;
2768 
2769  // 8 bit "filename" should be encoded according to disk filename encoding,
2770  // (maybe this is current locale, maybe not, its a filesystem issue),
2771  // and is not necessarily utf8.
2772  string filename = (const char*) aLibPath.char_str( wxConvFile );
2773 
2774  // Load the document
2775  wxXmlDocument xmlDocument;
2776  wxFileName fn( filename );
2777 
2778  if( !xmlDocument.Load( fn.GetFullPath() ) )
2779  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
2780  fn.GetFullPath() ) );
2781 
2782  doc = xmlDocument.GetRoot();
2783 
2784  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2785  NODE_MAP drawingChildren = MapChildren( drawing );
2786 
2787  // clear the cu map and then rebuild it.
2788  clear_cu_map();
2789 
2790  m_xpath->push( "eagle.drawing.layers" );
2791  wxXmlNode* layers = drawingChildren["layers"];
2792  loadLayerDefs( layers );
2793  m_xpath->pop();
2794 
2795  m_xpath->push( "eagle.drawing.library" );
2796  wxXmlNode* library = drawingChildren["library"];
2797  loadLibrary( library, NULL );
2798  m_xpath->pop();
2799 
2800  m_mod_time = modtime;
2801  }
2802  }
2803  catch(...){}
2804  // TODO: Handle exceptions
2805  // catch( file_parser_error fpe )
2806  // {
2807  // // for xml_parser_error, what() has the line number in it,
2808  // // but no byte offset. That should be an adequate error message.
2809  // THROW_IO_ERROR( fpe.what() );
2810  // }
2811  //
2812  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2813  // // so one catch should be OK for all errors.
2814  // catch( ptree_error pte )
2815  // {
2816  // string errmsg = pte.what();
2817  //
2818  // errmsg += " @\n";
2819  // errmsg += m_xpath->Contents();
2820  //
2821  // THROW_IO_ERROR( errmsg );
2822  // }
2823 }
void clear_cu_map()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
void loadLayerDefs(wxXmlNode *aLayers)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide 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:287
#define NULL
wxString m_lib_path
Definition: eagle_plugin.h:307
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
wxDateTime m_mod_time
Definition: eagle_plugin.h:308
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
void deleteTemplates()
void pop()
Definition: eagle_parser.h:122
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47

References _, clear_cu_map(), deleteTemplates(), Format(), getModificationTime(), library, loadLayerDefs(), loadLibrary(), m_lib_path, m_mod_time, m_xpath, MapChildren(), NULL, 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 2707 of file eagle_plugin.cpp.

2708 {
2709  if( m_props )
2710  {
2711  UTF8 page_width;
2712  UTF8 page_height;
2713 
2714  if( m_props->Value( "page_width", &page_width ) &&
2715  m_props->Value( "page_height", &page_height ) )
2716  {
2718 
2719  int w = atoi( page_width.c_str() );
2720  int h = atoi( page_height.c_str() );
2721 
2722  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2723  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2724 
2725  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2726  }
2727  }
2728 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
int GetX() const
Definition: eda_rect.h:103
const EDA_RECT GetBoardEdgesBoundingBox() const
Returns the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:812
int GetWidth() const
Definition: eda_rect.h:114
const char * c_str() const
Definition: utf8.h:102
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:299
bool Value(const char *aName, UTF8 *aFetchedValue=nullptr) const
Fetch a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
int GetHeight() const
Definition: eda_rect.h:115
void Move(const wxPoint &aMoveVector) override
Move this object.
Definition: board.cpp:248
Handle the component boundary box.
Definition: eda_rect.h:42
int GetY() const
Definition: eda_rect.h:104

References UTF8::c_str(), 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 438 of file eagle_plugin.cpp.

439 {
440  // All cu layers are invalid until we see them in the <layers> section while
441  // loading either a board or library. See loadLayerDefs().
442  for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
443  m_cu_map[i] = -1;
444 }
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:281
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31

References arrayDim(), and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

◆ defaultKicadLayer()

std::tuple< PCB_LAYER_ID, LSET, bool > EAGLE_PLUGIN::defaultKicadLayer ( int  aEagleLayer) const
private

Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping options and required flag.

Definition at line 2563 of file eagle_plugin.cpp.

2564 {
2565  // eagle copper layer:
2566  if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
2567  {
2568  LSET copperLayers;
2569  for( int copperLayer : m_cu_map )
2570  {
2571  if( copperLayer >= 0 )
2572  copperLayers[copperLayer] = true;
2573  }
2574 
2575  return { PCB_LAYER_ID( m_cu_map[aEagleLayer] ), copperLayers, true };
2576  }
2577 
2578  int kiLayer = UNSELECTED_LAYER;
2579  bool required = false;
2580  LSET permittedLayers;
2581 
2582  permittedLayers.set();
2583 
2584  // translate non-copper eagle layer to pcbnew layer
2585  switch( aEagleLayer )
2586  {
2587  // Eagle says "Dimension" layer, but it's for board perimeter
2589  kiLayer = Edge_Cuts;
2590  required = true;
2591  permittedLayers = LSET( 1, Edge_Cuts );
2592  break;
2593 
2594  case EAGLE_LAYER::TPLACE:
2595  kiLayer = F_SilkS;
2596  break;
2597  case EAGLE_LAYER::BPLACE:
2598  kiLayer = B_SilkS;
2599  break;
2600  case EAGLE_LAYER::TNAMES:
2601  kiLayer = F_SilkS;
2602  break;
2603  case EAGLE_LAYER::BNAMES:
2604  kiLayer = B_SilkS;
2605  break;
2606  case EAGLE_LAYER::TVALUES:
2607  kiLayer = F_Fab;
2608  break;
2609  case EAGLE_LAYER::BVALUES:
2610  kiLayer = B_Fab;
2611  break;
2612  case EAGLE_LAYER::TSTOP:
2613  kiLayer = F_Mask;
2614  break;
2615  case EAGLE_LAYER::BSTOP:
2616  kiLayer = B_Mask;
2617  break;
2618  case EAGLE_LAYER::TCREAM:
2619  kiLayer = F_Paste;
2620  break;
2621  case EAGLE_LAYER::BCREAM:
2622  kiLayer = B_Paste;
2623  break;
2624  case EAGLE_LAYER::TFINISH:
2625  kiLayer = F_Mask;
2626  break;
2627  case EAGLE_LAYER::BFINISH:
2628  kiLayer = B_Mask;
2629  break;
2630  case EAGLE_LAYER::TGLUE:
2631  kiLayer = F_Adhes;
2632  break;
2633  case EAGLE_LAYER::BGLUE:
2634  kiLayer = B_Adhes;
2635  break;
2636  case EAGLE_LAYER::DOCUMENT:
2637  kiLayer = Cmts_User;
2638  break;
2640  kiLayer = Cmts_User;
2641  break;
2643  kiLayer = Cmts_User;
2644  break;
2645 
2646  // Packages show the future chip pins on SMD parts using layer 51.
2647  // This is an area slightly smaller than the PAD/SMD copper area.
2648  // Carry those visual aids into the FOOTPRINT on the fabrication layer,
2649  // not silkscreen. This is perhaps not perfect, but there is not a lot
2650  // of other suitable paired layers
2651  case EAGLE_LAYER::TDOCU:
2652  kiLayer = F_Fab;
2653  break;
2654  case EAGLE_LAYER::BDOCU:
2655  kiLayer = B_Fab;
2656  break;
2657 
2658  // these layers are defined as user layers. put them on ECO layers
2660  kiLayer = Eco1_User;
2661  break;
2663  kiLayer = Eco2_User;
2664  break;
2665 
2666  // these will also appear in the ratsnest, so there's no need for a warning
2667  case EAGLE_LAYER::UNROUTED:
2668  kiLayer = Dwgs_User;
2669  break;
2670 
2671  case EAGLE_LAYER::TKEEPOUT:
2672  kiLayer = F_CrtYd;
2673  break;
2674  case EAGLE_LAYER::BKEEPOUT:
2675  kiLayer = B_CrtYd;
2676  break;
2677 
2678  case EAGLE_LAYER::MILLING:
2679  case EAGLE_LAYER::TTEST:
2680  case EAGLE_LAYER::BTEST:
2681  case EAGLE_LAYER::HOLES:
2682  default:
2683  kiLayer = UNSELECTED_LAYER;
2684  break;
2685  }
2686 
2687  return { PCB_LAYER_ID( kiLayer ), permittedLayers, required };
2688 }
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:281
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31

References arrayDim(), B_Adhes, B_CrtYd, 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, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, 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, UNSELECTED_LAYER, EAGLE_LAYER::USERLAYER1, and EAGLE_LAYER::USERLAYER2.

Referenced by DefaultLayerMappingCallback(), and mapEagleLayersToKicad().

◆ DefaultLayerMappingCallback()

std::map< wxString, PCB_LAYER_ID > EAGLE_PLUGIN::DefaultLayerMappingCallback ( const std::vector< INPUT_LAYER_DESC > &  aInputLayerDescriptionVector)

Return the automapped layers.

The callback needs to have the context of the current board so it can correctly determine copper layer mapping. Thus, it is not static and is expected to be bind to an instance of EAGLE_PLUGIN.

Parameters
aInputLayerDescriptionVector
Returns
Auto-mapped layers

Definition at line 2520 of file eagle_plugin.cpp.

2522 {
2523  std::map<wxString, PCB_LAYER_ID> layer_map;
2524 
2525  for ( const INPUT_LAYER_DESC& layer : aInputLayerDescriptionVector )
2526  {
2527  PCB_LAYER_ID layerId = std::get<0>( defaultKicadLayer( eagle_layer_id( layer.Name ) ) );
2528  layer_map.emplace( layer.Name, layerId );
2529  }
2530 
2531  return layer_map;
2532 }
int eagle_layer_id(const wxString &aLayerName) const
Get Eagle layer number by its name.
Describes an imported layer and how it could be mapped to KiCad Layers.
PCB_LAYER_ID
A quick note on layer IDs:
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer(int aEagleLayer) const
Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping...

References defaultKicadLayer(), and eagle_layer_id().

Referenced by EAGLE_PLUGIN().

◆ deleteTemplates()

void EAGLE_PLUGIN::deleteTemplates ( )
private

Definition at line 2279 of file eagle_plugin.cpp.

2280 {
2281  for( auto& t : m_templates )
2282  delete t.second;
2283 
2284  m_templates.clear();
2285 }
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294

References m_templates.

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

◆ eagle_layer_id()

int EAGLE_PLUGIN::eagle_layer_id ( const wxString &  aLayerName) const
private

Get Eagle layer number by its name.

Definition at line 2699 of file eagle_plugin.cpp.

2700 {
2701  static const int unknown = -1;
2702  auto it = m_eagleLayersIds.find( aLayerName );
2703  return it == m_eagleLayersIds.end() ? unknown : it->second;
2704 }
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:283

References m_eagleLayersIds, and unknown.

Referenced by DefaultLayerMappingCallback().

◆ eagle_layer_name()

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

Get Eagle layer name by its number.

Definition at line 2691 of file eagle_plugin.cpp.

2692 {
2693  static const wxString unknown( "unknown" );
2694  auto it = m_eagleLayers.find( aLayer );
2695  return it == m_eagleLayers.end() ? unknown : it->second.name;
2696 }
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:282

References m_eagleLayers, and unknown.

Referenced by kicad_layer(), loadPolygon(), packageCircle(), packagePolygon(), packageRectangle(), packageText(), and packageWire().

◆ FootprintDelete()

void PLUGIN::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Delete 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 PCB_IO, and GPCB_PLUGIN.

Definition at line 118 of file plugin.cpp.

120 {
121  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
122  not_implemented( this, __FUNCTION__ );
123 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw 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,
bool  aBestEfforts,
const PROPERTIES aProperties = nullptr 
)
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.
aBestEffortsif true, don't throw on errors, just return an empty list.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 2826 of file eagle_plugin.cpp.

2828 {
2829  wxString errorMsg;
2830 
2831  init( aProperties );
2832 
2833  try
2834  {
2835  cacheLib( aLibraryPath );
2836  }
2837  catch( const IO_ERROR& ioe )
2838  {
2839  errorMsg = ioe.What();
2840  }
2841 
2842  // Some of the files may have been parsed correctly so we want to add the valid files to
2843  // the library.
2844 
2845  for( FOOTPRINT_MAP::const_iterator it = m_templates.begin(); it != m_templates.end(); ++it )
2846  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2847 
2848  if( !errorMsg.IsEmpty() && !aBestEfforts )
2849  THROW_IO_ERROR( errorMsg );
2850 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References cacheLib(), FROM_UTF8(), init(), m_templates, THROW_IO_ERROR, and IO_ERROR::What().

◆ FootprintExists()

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

Check for the existence of a footprint.

Reimplemented in PCB_IO.

Definition at line 91 of file plugin.cpp.

93 {
94  // default implementation
95  return FootprintLoad( aLibraryPath, aFootprintName, true, aProperties ) != nullptr;
96 }
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
Definition: plugin.cpp:99

References PLUGIN::FootprintLoad().

◆ FootprintLibCreate()

void PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Create 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 PCB_IO.

Definition at line 126 of file plugin.cpp.

127 {
128  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
129  not_implemented( this, __FUNCTION__ );
130 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw 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 = nullptr 
)
virtualinherited

Delete 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
true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented in PCB_IO, LEGACY_PLUGIN, and GPCB_PLUGIN.

Definition at line 133 of file plugin.cpp.

134 {
135  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
136  not_implemented( this, __FUNCTION__ );
137  return false;
138 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw 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

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

2873 {
2874  PLUGIN::FootprintLibOptions( aListToAppendTo );
2875 
2876  /*
2877  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _( "Ignore duplicately named footprints within "
2878  "the same Eagle library. "
2879  "Only the first similarly named footprint "
2880  "will be loaded." ) );
2881  */
2882 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: plugin.cpp:149

References PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

FOOTPRINT * EAGLE_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
bool  aKeepUUID = false,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load 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.
aKeepUUID= true to keep initial items UUID, false to set new UUID normally true if loaded in the footprint editor, false if loaded in the board editor. Make sense only in kicad_plugin
Returns
the FOOTPRINT object 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 2853 of file eagle_plugin.cpp.

2857 {
2858  init( aProperties );
2859  cacheLib( aLibraryPath );
2860  FOOTPRINT_MAP::const_iterator it = m_templates.find( aFootprintName );
2861 
2862  if( it == m_templates.end() )
2863  return NULL;
2864 
2865  // Return a copy of the template
2866  FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate();
2867  copy->SetParent( nullptr );
2868  return copy;
2869 }
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
#define NULL

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

◆ FootprintSave()

void PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const FOOTPRINT aFootprint,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Write aFootprint 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 PCB_IO.

Definition at line 110 of file plugin.cpp.

112 {
113  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
114  not_implemented( this, __FUNCTION__ );
115 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ GetEnumeratedFootprint()

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

A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented in PCB_IO, and GPCB_PLUGIN.

Definition at line 82 of file plugin.cpp.

85 {
86  // default implementation
87  return FootprintLoad( aLibraryPath, aFootprintName, false, aProperties );
88 }
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
Definition: plugin.cpp:99

References PLUGIN::FootprintLoad().

◆ GetFileExtension()

const wxString EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 298 of file eagle_plugin.cpp.

299 {
300  return wxT( "brd" );
301 }

◆ GetImportedCachedLibraryFootprints()

std::vector< FOOTPRINT * > EAGLE_PLUGIN::GetImportedCachedLibraryFootprints ( )
overridevirtual

Return a container with the cached library footprints generated in the last call to Load.

This function is intended to be used ONLY by the non-KiCad board importers for the purpose of obtaining the footprint library of the design and creating a project-specific library.

Returns
Footprints (caller owns the objects)

Reimplemented from PLUGIN.

Definition at line 406 of file eagle_plugin.cpp.

407 {
408  std::vector<FOOTPRINT*> retval;
409 
410  for( std::pair<wxString, FOOTPRINT*> fp : m_templates )
411  {
412  retval.push_back( static_cast<FOOTPRINT*>( fp.second->Clone() ) );
413  }
414 
415  return retval;
416 }
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294

References m_templates.

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

148  {
149  return getModificationTime( aLibraryPath ).GetValue().GetValue();
150  }
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 2731 of file eagle_plugin.cpp.

2732 {
2733  // File hasn't been loaded yet.
2734  if( aPath.IsEmpty() )
2735  return wxDateTime::Now();
2736 
2737  wxFileName fn( aPath );
2738 
2739  if( fn.IsFileReadable() )
2740  return fn.GetModificationTime();
2741  else
2742  return wxDateTime( 0.0 );
2743 }

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

420 {
421  m_hole_count = 0;
422  m_min_trace = 0;
423  m_min_hole = 0;
424  m_min_via = 0;
425  m_min_annulus = 0;
426  m_xpath->clear();
427  m_pads_to_nets.clear();
428 
429  m_board = NULL;
430  m_props = aProperties;
431 
432 
433  delete m_rules;
434  m_rules = new ERULES();
435 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
void clear()
Definition: eagle_parser.h:120
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:304
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:299
#define NULL
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:49
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:302
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:290
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:305
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:292
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:303

References XPATH::clear(), m_board, m_hole_count, m_min_annulus, m_min_hole, m_min_trace, m_min_via, m_pads_to_nets, m_props, m_rules, m_xpath, and NULL.

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

◆ IsFootprintLibWritable()

bool EAGLE_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
inlineoverridevirtual

Return true if the library at aLibraryPath is writable.

The system libraries are typically 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 152 of file eagle_plugin.h.

153  {
154  return false; // until someone writes others like FootprintSave(), etc.
155  }

◆ kicad_fontz()

wxSize EAGLE_PLUGIN::kicad_fontz ( const ECOORD d,
int  aTextThickness 
) const
inlineprivate

create a font size (fontz) from an eagle font size scalar and KiCad font thickness

Definition at line 303 of file eagle_plugin.cpp.

304 {
305  // Eagle includes stroke thickness in the text size, KiCAD does not
306  int kz = d.ToPcbUnits();
307  return wxSize( kz - aTextThickness, kz - aTextThickness );
308 }
int ToPcbUnits() const
Definition: eagle_parser.h:430

References ECOORD::ToPcbUnits().

Referenced by loadPlain(), orientFPText(), 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 2557 of file eagle_plugin.cpp.

2558 {
2559  auto result = m_layer_map.find( eagle_layer_name( aEagleLayer ) );
2560  return result == m_layer_map.end() ? UNDEFINED_LAYER : result->second;
2561 }
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:284

References eagle_layer_name(), m_layer_map, and UNDEFINED_LAYER.

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

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

References ECOORD::ToPcbUnits().

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

◆ Load()

BOARD * EAGLE_PLUGIN::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = nullptr,
PROJECT aProject = nullptr 
)
overridevirtual

Load 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.
aProjectis the optional PROJECT object primarily used by third party importers.
Returns
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 311 of file eagle_plugin.cpp.

313 {
314  LOCALE_IO toggle; // toggles on, then off, the C locale.
315  wxXmlNode* doc;
316 
317  init( aProperties );
318 
319  m_board = aAppendToMe ? aAppendToMe : new BOARD();
320 
321  // Give the filename to the board if it's new
322  if( !aAppendToMe )
323  m_board->SetFileName( aFileName );
324 
325  // delete on exception, if I own m_board, according to aAppendToMe
326  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
327 
328  try
329  {
330  // Load the document
331  wxXmlDocument xmlDocument;
332  wxFileName fn = aFileName;
333 
334  if( !xmlDocument.Load( fn.GetFullPath() ) )
335  {
336  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
337  fn.GetFullPath() ) );
338  }
339 
340  doc = xmlDocument.GetRoot();
341 
342  m_min_trace = INT_MAX;
343  m_min_hole = INT_MAX;
344  m_min_via = INT_MAX;
345  m_min_annulus = INT_MAX;
346 
347  loadAllSections( doc );
348 
349  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
350 
351  if( m_min_trace < designSettings.m_TrackMinWidth )
352  designSettings.m_TrackMinWidth = m_min_trace;
353 
354  if( m_min_via < designSettings.m_ViasMinSize )
355  designSettings.m_ViasMinSize = m_min_via;
356 
357  if( m_min_hole < designSettings.m_MinThroughDrill )
358  designSettings.m_MinThroughDrill = m_min_hole;
359 
360  if( m_min_annulus < designSettings.m_ViasMinAnnulus )
361  designSettings.m_ViasMinAnnulus = m_min_annulus;
362 
363  if( m_rules->mdWireWire )
364  {
365  NETCLASS* defaultNetclass = designSettings.GetDefault();
366  int clearance = KiROUND( m_rules->mdWireWire );
367 
368  if( clearance < defaultNetclass->GetClearance() )
369  defaultNetclass->SetClearance( clearance );
370  }
371 
372  // should be empty, else missing m_xpath->pop()
373  wxASSERT( m_xpath->Contents().size() == 0 );
374  }
375  // Catch all exceptions thrown from the parser.
376  catch( const XML_PARSER_ERROR &exc )
377  {
378  wxString errmsg = exc.what();
379 
380  errmsg += "\n@ ";
381  errmsg += m_xpath->Contents();
382 
383  THROW_IO_ERROR( errmsg );
384  }
385 
386  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
387 
388  // Ensure the copper layers count is a multiple of 2
389  // Pcbnew does not like boards with odd layers count
390  // (these boards cannot exist. they actually have a even layers count)
391  int lyrcnt = m_board->GetCopperLayerCount();
392 
393  if( (lyrcnt % 2) != 0 )
394  {
395  lyrcnt++;
396  m_board->SetCopperLayerCount( lyrcnt );
397  }
398 
399  centerBoard();
400 
401  deleter.release();
402  return m_board;
403 }
wxString Contents()
return the contents of the XPATH as a single string
Definition: eagle_parser.h:137
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:300
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
void SetCopperLayerCount(int aCount)
Definition: board.cpp:441
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
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:304
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
Definition: eagle_parser.h:68
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
#define NULL
void SetClearance(int aClearance)
Definition: netclass.h:125
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
void SetFileName(const wxString &aFileName)
Definition: board.h:298
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:120
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:302
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
int GetCopperLayerCount() const
Definition: board.cpp:435
NETCLASS * GetDefault() const
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:305
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:303
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Container for 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_annulus, m_min_hole, m_min_trace, m_min_via, BOARD_DESIGN_SETTINGS::m_MinThroughDrill, m_rules, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinAnnulus, BOARD_DESIGN_SETTINGS::m_ViasMinSize, m_xpath, ERULES::mdWireWire, NULL, NETCLASS::SetClearance(), BOARD::SetCopperLayerCount(), BOARD::SetFileName(), and THROW_IO_ERROR.

◆ loadAllSections()

void EAGLE_PLUGIN::loadAllSections ( wxXmlNode *  aDocument)
private

Definition at line 447 of file eagle_plugin.cpp.

448 {
449  wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
450  NODE_MAP drawingChildren = MapChildren( drawing );
451 
452  wxXmlNode* board = drawingChildren["board"];
453  NODE_MAP boardChildren = MapChildren( board );
454 
455  m_xpath->push( "eagle.drawing" );
456 
457  {
458  m_xpath->push( "board" );
459 
460  wxXmlNode* designrules = boardChildren["designrules"];
461  loadDesignRules( designrules );
462 
463  m_xpath->pop();
464  }
465 
466  {
467  m_xpath->push( "layers" );
468 
469  wxXmlNode* layers = drawingChildren["layers"];
470  loadLayerDefs( layers );
472 
473  m_xpath->pop();
474  }
475 
476  {
477  m_xpath->push( "board" );
478 
479  wxXmlNode* plain = boardChildren["plain"];
480  loadPlain( plain );
481 
482  wxXmlNode* signals = boardChildren["signals"];
483  loadSignals( signals );
484 
485  wxXmlNode* libs = boardChildren["libraries"];
486  loadLibraries( libs );
487 
488  wxXmlNode* elems = boardChildren["elements"];
489  loadElements( elems );
490 
491  m_xpath->pop(); // "board"
492  }
493 
494  m_xpath->pop(); // "eagle.drawing"
495 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
void loadLayerDefs(wxXmlNode *aLayers)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide 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:287
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void loadElements(wxXmlNode *aElements)
void pop()
Definition: eagle_parser.h:122
void loadDesignRules(wxXmlNode *aDesignRules)
void mapEagleLayersToKicad()
Generate mapping between Eagle na KiCad layers.
void loadSignals(wxXmlNode *aSignals)
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47

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

Referenced by Load().

◆ loadDesignRules()

void EAGLE_PLUGIN::loadDesignRules ( wxXmlNode *  aDesignRules)
private

Definition at line 498 of file eagle_plugin.cpp.

499 {
500  if( aDesignRules )
501  {
502  m_xpath->push( "designrules" );
503  m_rules->parse( aDesignRules );
504  m_xpath->pop(); // "designrules"
505  }
506 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
void parse(wxXmlNode *aRules)
percent over 100%.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
void pop()
Definition: eagle_parser.h:122

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

999 {
1000  if( !aElements )
1001  return;
1002 
1003  m_xpath->push( "elements.element", "name" );
1004 
1005  EATTR name;
1006  EATTR value;
1007  bool refanceNamePresetInPackageLayout;
1008  bool valueNamePresetInPackageLayout;
1009 
1010  // Get the first element and iterate
1011  wxXmlNode* element = aElements->GetChildren();
1012 
1013  while( element )
1014  {
1015  if( element->GetName() != "element" )
1016  {
1017  // Get next item
1018  element = element->GetNext();
1019  continue;
1020  }
1021 
1022  EELEMENT e( element );
1023 
1024  // use "NULL-ness" as an indication of presence of the attribute:
1025  EATTR* nameAttr = nullptr;
1026  EATTR* valueAttr = nullptr;
1027 
1028  m_xpath->Value( e.name.c_str() );
1029 
1030  wxString pkg_key = makeKey( e.library, e.package );
1031 
1032  FOOTPRINT_MAP::const_iterator it = m_templates.find( pkg_key );
1033 
1034  if( it == m_templates.end() )
1035  {
1036  wxString emsg = wxString::Format( _( "No \"%s\" package in library \"%s\"" ),
1037  FROM_UTF8( e.package.c_str() ),
1038  FROM_UTF8( e.library.c_str() ) );
1039  THROW_IO_ERROR( emsg );
1040  }
1041 
1042  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( it->second->Duplicate() );
1043 
1044  m_board->Add( footprint, ADD_MODE::APPEND );
1045 
1046  // update the nets within the pads of the clone
1047  for( PAD* pad : footprint->Pads() )
1048  {
1049  wxString pn_key = makeKey( e.name, pad->GetName() );
1050 
1051  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
1052  if( ni != m_pads_to_nets.end() )
1053  {
1054  const ENET* enet = &ni->second;
1055  pad->SetNetCode( enet->netcode );
1056  }
1057  }
1058 
1059  refanceNamePresetInPackageLayout = true;
1060  valueNamePresetInPackageLayout = true;
1061  footprint->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1062 
1063  // Is >NAME field set in package layout ?
1064  if( footprint->GetReference().size() == 0 )
1065  {
1066  footprint->Reference().SetVisible( false ); // No so no show
1067  refanceNamePresetInPackageLayout = false;
1068  }
1069 
1070  // Is >VALUE field set in package layout
1071  if( footprint->GetValue().size() == 0 )
1072  {
1073  footprint->Value().SetVisible( false ); // No so no show
1074  valueNamePresetInPackageLayout = false;
1075  }
1076 
1077  footprint->SetReference( FROM_UTF8( e.name.c_str() ) );
1078  footprint->SetValue( FROM_UTF8( e.value.c_str() ) );
1079 
1080  if( !e.smashed )
1081  { // Not smashed so show NAME & VALUE
1082  if( valueNamePresetInPackageLayout )
1083  footprint->Value().SetVisible( true ); // Only if place holder in package layout
1084 
1085  if( refanceNamePresetInPackageLayout )
1086  footprint->Reference().SetVisible( true ); // Only if place holder in package layout
1087  }
1088  else if( *e.smashed == true )
1089  { // Smashed so set default to no show for NAME and VALUE
1090  footprint->Value().SetVisible( false );
1091  footprint->Reference().SetVisible( false );
1092 
1093  // initialize these to default values in case the <attribute> elements are not present.
1094  m_xpath->push( "attribute", "name" );
1095 
1096  // VALUE and NAME can have something like our text "effects" overrides
1097  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
1098  // There can be one for NAME and/or VALUE both. Features present in the
1099  // EATTR override the ones established in the package only if they are
1100  // present here (except for rot, which if not present means angle zero).
1101  // So the logic is a bit different than in packageText() and in plain text.
1102 
1103  // Get the first attribute and iterate
1104  wxXmlNode* attribute = element->GetChildren();
1105 
1106  while( attribute )
1107  {
1108  if( attribute->GetName() != "attribute" )
1109  {
1110  attribute = attribute->GetNext();
1111  continue;
1112  }
1113 
1114  EATTR a( attribute );
1115 
1116  if( a.name == "NAME" )
1117  {
1118  name = a;
1119  nameAttr = &name;
1120 
1121  // do we have a display attribute ?
1122  if( a.display )
1123  {
1124  // Yes!
1125  switch( *a.display )
1126  {
1127  case EATTR::VALUE :
1128  {
1129  wxString reference = e.name;
1130 
1131  // EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
1132  // parts to have non-digit + digit annotation. If the reference begins with a number,
1133  // we prepend 'UNK' (unknown) for the symbol designator
1134  if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
1135  reference.Prepend( "UNK" );
1136 
1137  nameAttr->name = reference;
1138  footprint->SetReference( reference );
1139 
1140  if( refanceNamePresetInPackageLayout )
1141  footprint->Reference().SetVisible( true );
1142 
1143  break;
1144  }
1145  case EATTR::NAME :
1146  if( refanceNamePresetInPackageLayout )
1147  {
1148  footprint->SetReference( "NAME" );
1149  footprint->Reference().SetVisible( true );
1150  }
1151  break;
1152 
1153  case EATTR::BOTH :
1154  if( refanceNamePresetInPackageLayout )
1155  footprint->Reference().SetVisible( true );
1156 
1157  nameAttr->name = nameAttr->name + " = " + e.name;
1158  footprint->SetReference( "NAME = " + e.name );
1159  break;
1160 
1161  case EATTR::Off :
1162  footprint->Reference().SetVisible( false );
1163  break;
1164 
1165  default:
1166  nameAttr->name = e.name;
1167 
1168  if( refanceNamePresetInPackageLayout )
1169  footprint->Reference().SetVisible( true );
1170  }
1171  }
1172  else
1173  // No display, so default is visible, and show value of NAME
1174  footprint->Reference().SetVisible( true );
1175  }
1176  else if( a.name == "VALUE" )
1177  {
1178  value = a;
1179  valueAttr = &value;
1180 
1181  if( a.display )
1182  {
1183  // Yes!
1184  switch( *a.display )
1185  {
1186  case EATTR::VALUE :
1187  valueAttr->value = opt_wxString( e.value );
1188  footprint->SetValue( e.value );
1189 
1190  if( valueNamePresetInPackageLayout )
1191  footprint->Value().SetVisible( true );
1192 
1193  break;
1194 
1195  case EATTR::NAME :
1196  if( valueNamePresetInPackageLayout )
1197  footprint->Value().SetVisible( true );
1198 
1199  footprint->SetValue( "VALUE" );
1200  break;
1201 
1202  case EATTR::BOTH :
1203  if( valueNamePresetInPackageLayout )
1204  footprint->Value().SetVisible( true );
1205 
1206  valueAttr->value = opt_wxString( "VALUE = " + e.value );
1207  footprint->SetValue( "VALUE = " + e.value );
1208  break;
1209 
1210  case EATTR::Off :
1211  footprint->Value().SetVisible( false );
1212  break;
1213 
1214  default:
1215  valueAttr->value = opt_wxString( e.value );
1216 
1217  if( valueNamePresetInPackageLayout )
1218  footprint->Value().SetVisible( true );
1219  }
1220  }
1221  else
1222  {
1223  // No display, so default is visible, and show value of NAME
1224  footprint->Value().SetVisible( true );
1225  }
1226 
1227  }
1228 
1229  attribute = attribute->GetNext();
1230  }
1231 
1232  m_xpath->pop(); // "attribute"
1233  }
1234 
1235  orientFootprintAndText( footprint, e, nameAttr, valueAttr );
1236 
1237  // Set the local coordinates for the footprint text items
1238  footprint->Reference().SetLocalCoord();
1239  footprint->Value().SetLocalCoord();
1240 
1241  // Get next element
1242  element = element->GetNext();
1243  }
1244 
1245  m_xpath->pop(); // "elements.element"
1246 }
void SetReference(const wxString &aReference)
Definition: footprint.h:441
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
const wxString & GetValue() const
Definition: footprint.h:454
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
Eagle element element.
Definition: eagle_parser.h:810
void SetVisible(bool aVisible)
Definition: eda_text.h:192
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:45
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
PADS & Pads()
Definition: footprint.h:164
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:468
OPTIONAL_XML_ATTRIBUTE< wxString > opt_wxString
Definition: eagle_parser.h:365
FP_TEXT & Reference()
Definition: footprint.h:469
wxString name
Definition: eagle_parser.h:596
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
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.
const wxString & GetReference() const
Definition: footprint.h:432
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
opt_wxString value
Definition: eagle_parser.h:597
void SetValue(const wxString &aValue)
Definition: footprint.h:462
Eagle net.
Definition: eagle_parser.h:453
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:594
int netcode
Definition: eagle_parser.h:455
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Definition: 3d_actions.cpp:33
void SetLocalCoord()
Definition: fp_text.cpp:206
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:292
void pop()
Definition: eagle_parser.h:122
Definition: pad.h:60
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1438
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:125

References _, BOARD::Add(), APPEND, EATTR::BOTH, EATTR::display, Format(), FROM_UTF8(), FOOTPRINT::GetReference(), FOOTPRINT::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, orientFootprintAndText(), EELEMENT::package, pad, FOOTPRINT::Pads(), XPATH::pop(), XPATH::push(), FOOTPRINT::Reference(), FP_TEXT::SetLocalCoord(), FOOTPRINT::SetPosition(), FOOTPRINT::SetReference(), FOOTPRINT::SetValue(), EDA_TEXT::SetVisible(), EELEMENT::smashed, THROW_IO_ERROR, XPATH::Value(), FOOTPRINT::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 509 of file eagle_plugin.cpp.

510 {
511  if( !aLayers )
512  return;
513 
514  ELAYERS cu; // copper layers
515 
516  // Get the first layer and iterate
517  wxXmlNode* layerNode = aLayers->GetChildren();
518 
519  m_eagleLayers.clear();
520  m_eagleLayersIds.clear();
521 
522  while( layerNode )
523  {
524  ELAYER elayer( layerNode );
525  m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
526  m_eagleLayersIds.insert( std::make_pair( elayer.name, elayer.number ) );
527 
528  // find the subset of layers that are copper and active
529  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
530  {
531  cu.push_back( elayer );
532  }
533 
534  layerNode = layerNode->GetNext();
535  }
536 
537  // establish cu layer map:
538  int ki_layer_count = 0;
539 
540  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
541  {
542  if( ki_layer_count == 0 )
543  m_cu_map[it->number] = F_Cu;
544  else if( ki_layer_count == int( cu.size()-1 ) )
545  m_cu_map[it->number] = B_Cu;
546  else
547  {
548  // some eagle boards do not have contiguous layer number sequences.
549  m_cu_map[it->number] = ki_layer_count;
550  }
551  }
552 
553  // Set the layer names and cu count if we're loading a board.
554  if( m_board )
555  {
556  m_board->SetCopperLayerCount( cu.size() );
557 
558  for( EITER it = cu.begin(); it != cu.end(); ++it )
559  {
560  PCB_LAYER_ID layer = kicad_layer( it->number );
561 
562  // these function provide their own protection against non enabled layers:
563  if( layer >= 0 && layer < PCB_LAYER_ID_COUNT ) // layer should be valid
564  {
565  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
566  m_board->SetLayerType( layer, LT_SIGNAL );
567  }
568  // could map the colors here
569  }
570  }
571 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetCopperLayerCount(int aCount)
Definition: board.cpp:441
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:283
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
Definition: board.cpp:390
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:281
PCB_LAYER_ID
A quick note on layer IDs:
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:282
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition: board.cpp:358
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:278
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:279

References ELAYER::active, B_Cu, F_Cu, FROM_UTF8(), kicad_layer(), LT_SIGNAL, m_board, m_cu_map, m_eagleLayers, m_eagleLayersIds, ELAYER::name, ELAYER::number, PCB_LAYER_ID_COUNT, BOARD::SetCopperLayerCount(), BOARD::SetLayerName(), and BOARD::SetLayerType().

Referenced by cacheLib(), and loadAllSections().

◆ loadLibraries()

void EAGLE_PLUGIN::loadLibraries ( wxXmlNode *  aLibs)
private

Definition at line 975 of file eagle_plugin.cpp.

976 {
977  if( !aLibs )
978  return;
979 
980  m_xpath->push( "libraries.library", "name" );
981 
982  // Get the first library and iterate
983  wxXmlNode* library = aLibs->GetChildren();
984 
985  while( library )
986  {
987  const wxString& lib_name = library->GetAttribute( "name" );
988 
989  m_xpath->Value( lib_name.c_str() );
990  loadLibrary( library, &lib_name );
991  library = library->GetNext();
992  }
993 
994  m_xpath->pop();
995 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
void pop()
Definition: eagle_parser.h:122
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:125

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

Referenced by loadAllSections().

◆ loadLibrary()

void EAGLE_PLUGIN::loadLibrary ( wxXmlNode *  aLib,
const wxString *  aLibName 
)
private

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

921 {
922  if( !aLib )
923  return;
924 
925  // library will have <xmlattr> node, skip that and get the single packages node
926  wxXmlNode* packages = MapChildren( aLib )["packages"];
927 
928  if( !packages )
929  return;
930 
931  m_xpath->push( "packages" );
932 
933  // Create a FOOTPRINT for all the eagle packages, for use later via a copy constructor
934  // to instantiate needed footprints in our BOARD. Save the FOOTPRINT templates in
935  // a FOOTPRINT_MAP using a single lookup key consisting of libname+pkgname.
936 
937  // Get the first package and iterate
938  wxXmlNode* package = packages->GetChildren();
939 
940  while( package )
941  {
942  m_xpath->push( "package", "name" );
943 
944  wxString pack_ref = package->GetAttribute( "name" );
945  ReplaceIllegalFileNameChars( pack_ref, '_' );
946 
947  m_xpath->Value( pack_ref.ToUTF8() );
948 
949  wxString key = aLibName ? makeKey( *aLibName, pack_ref ) : pack_ref;
950 
951  FOOTPRINT* m = makeFootprint( package, pack_ref );
952 
953  // add the templating FOOTPRINT to the FOOTPRINT template factory "m_templates"
954  std::pair<FOOTPRINT_MAP::iterator, bool> r = m_templates.insert( {key, m} );
955 
956  if( !r.second /* && !( m_props && m_props->Value( "ignore_duplicates" ) ) */ )
957  {
958  wxString lib = aLibName ? *aLibName : m_lib_path;
959  const wxString& pkg = pack_ref;
960 
961  wxString emsg = wxString::Format(
962  _( "<package> name: \"%s\" duplicated in eagle <library>: \"%s\"" ), pkg, lib );
963  THROW_IO_ERROR( emsg );
964  }
965 
966  m_xpath->pop();
967 
968  package = package->GetNext();
969  }
970 
971  m_xpath->pop(); // "packages"
972 }
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:765
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:294
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide 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:287
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:307
FOOTPRINT * makeFootprint(wxXmlNode *aPackage, const wxString &aPkgName)
Create a FOOTPRINT from an Eagle package.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
void pop()
Definition: eagle_parser.h:122
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:125

References _, Format(), m_lib_path, m_templates, m_xpath, makeFootprint(), makeKey(), 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 576 of file eagle_plugin.cpp.

577 {
578  if( !aGraphics )
579  return;
580 
581  m_xpath->push( "plain" );
582 
583  // Get the first graphic and iterate
584  wxXmlNode* gr = aGraphics->GetChildren();
585 
586  // (polygon | wire | text | circle | rectangle | frame | hole)*
587  while( gr )
588  {
589  wxString grName = gr->GetName();
590 
591  if( grName == "wire" )
592  {
593  m_xpath->push( "wire" );
594 
595  EWIRE w( gr );
596  PCB_LAYER_ID layer = kicad_layer( w.layer );
597 
598  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
599  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
600 
601  if( layer != UNDEFINED_LAYER )
602  {
603  PCB_SHAPE* shape = new PCB_SHAPE( m_board );
604  int width = w.width.ToPcbUnits();
605 
606  // KiCad cannot handle zero or negative line widths
607  if( width <= 0 )
608  width = m_board->GetDesignSettings().GetLineThickness( layer );
609 
610  m_board->Add( shape, ADD_MODE::APPEND );
611 
612  if( !w.curve )
613  {
614  shape->SetStart( start );
615  shape->SetEnd( end );
616  }
617  else
618  {
619  wxPoint center = ConvertArcCenter( start, end, *w.curve );
620 
621  shape->SetShape( S_ARC );
622  shape->SetStart( center );
623  shape->SetEnd( start );
624  shape->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
625  }
626 
627  shape->SetLayer( layer );
628  shape->SetWidth( width );
629  }
630 
631  m_xpath->pop();
632  }
633  else if( grName == "text" )
634  {
635  m_xpath->push( "text" );
636 
637  ETEXT t( gr );
638  PCB_LAYER_ID layer = kicad_layer( t.layer );
639 
640  if( layer != UNDEFINED_LAYER )
641  {
642  PCB_TEXT* pcbtxt = new PCB_TEXT( m_board );
643  m_board->Add( pcbtxt, ADD_MODE::APPEND );
644 
645  pcbtxt->SetLayer( layer );
646  wxString kicadText = interpret_text( t.text );
647  pcbtxt->SetText( FROM_UTF8( kicadText.c_str() ) );
648  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
649 
650  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
651  int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
652  pcbtxt->SetTextThickness( textThickness );
653  pcbtxt->SetTextSize( kicad_fontz( t.size, textThickness ) );
654 
655  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
656 
657  if( t.rot )
658  {
659  int sign = t.rot->mirror ? -1 : 1;
660  pcbtxt->SetMirrored( t.rot->mirror );
661 
662  double degrees = t.rot->degrees;
663 
664  if( degrees == 90 || t.rot->spin )
665  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
666  else if( degrees == 180 )
667  align = ETEXT::TOP_RIGHT;
668  else if( degrees == 270 )
669  {
670  pcbtxt->SetTextAngle( sign * 90 * 10 );
671  align = ETEXT::TOP_RIGHT;
672  }
673  else // Ok so text is not at 90,180 or 270 so do some funny stuff to get placement right
674  {
675  if( ( degrees > 0 ) && ( degrees < 90 ) )
676  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
677  else if( ( degrees > 90 ) && ( degrees < 180 ) )
678  {
679  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
680  align = ETEXT::TOP_RIGHT;
681  }
682  else if( ( degrees > 180 ) && ( degrees < 270 ) )
683  {
684  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
685  align = ETEXT::TOP_RIGHT;
686  }
687  else if( ( degrees > 270 ) && ( degrees < 360 ) )
688  {
689  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
690  align = ETEXT::BOTTOM_LEFT;
691  }
692  }
693  }
694 
695  switch( align )
696  {
697  case ETEXT::CENTER:
698  // this was the default in pcbtxt's constructor
699  break;
700 
701  case ETEXT::CENTER_LEFT:
703  break;
704 
705  case ETEXT::CENTER_RIGHT:
707  break;
708 
709  case ETEXT::TOP_CENTER:
711  break;
712 
713  case ETEXT::TOP_LEFT:
716  break;
717 
718  case ETEXT::TOP_RIGHT:
721  break;
722 
725  break;
726 
727  case ETEXT::BOTTOM_LEFT:
730  break;
731 
732  case ETEXT::BOTTOM_RIGHT:
735  break;
736  }
737  }
738  m_xpath->pop();
739  }
740  else if( grName == "circle" )
741  {
742  m_xpath->push( "circle" );
743 
744  ECIRCLE c( gr );
745 
746  int width = c.width.ToPcbUnits();
747  int radius = c.radius.ToPcbUnits();
748 
749  if( c.layer == EAGLE_LAYER::TRESTRICT || c.layer == EAGLE_LAYER::BRESTRICT
750  || c.layer == EAGLE_LAYER::VRESTRICT )
751  {
752  ZONE* zone = new ZONE( m_board );
753  m_board->Add( zone, ADD_MODE::APPEND );
754 
755  setKeepoutSettingsToZone( zone, c.layer );
756 
757  // approximate circle as polygon with a edge every 10 degree
758  wxPoint center( kicad_x( c.x ), kicad_y( c.y ) );
759  int outlineRadius = radius + ( width / 2 );
760  for( int angle = 0; angle < 360; angle += 10 )
761  {
762  wxPoint rotatedPoint( outlineRadius, 0 );
763  RotatePoint( &rotatedPoint, angle * 10. );
764  zone->AppendCorner( center + rotatedPoint, -1 );
765  }
766 
767  if( width > 0 )
768  {
769  zone->NewHole();
770  int innerRadius = radius - ( width / 2 );
771  for( int angle = 0; angle < 360; angle += 10 )
772  {
773  wxPoint rotatedPoint( innerRadius, 0 );
774  RotatePoint( &rotatedPoint, angle * 10. );
775  zone->AppendCorner( center + rotatedPoint, 0 );
776  }
777  }
778 
780  ZONE::GetDefaultHatchPitch(), true );
781  }
782  else
783  {
784  PCB_LAYER_ID layer = kicad_layer( c.layer );
785 
786  if( layer != UNDEFINED_LAYER ) // unsupported layer
787  {
788  PCB_SHAPE* shape = new PCB_SHAPE( m_board );
789  m_board->Add( shape, ADD_MODE::APPEND );
790 
791  shape->SetShape( S_CIRCLE );
792  shape->SetFilled( false );
793  shape->SetLayer( layer );
794  shape->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
795  shape->SetEnd( wxPoint( kicad_x( c.x ) + radius, kicad_y( c.y ) ) );
796  shape->SetWidth( width );
797  }
798  }
799  m_xpath->pop();
800  }
801  else if( grName == "rectangle" )
802  {
803  // This seems to be a simplified rectangular [copper] zone, cannot find any
804  // net related info on it from the DTD.
805  m_xpath->push( "rectangle" );
806 
807  ERECT r( gr );
808  PCB_LAYER_ID layer = kicad_layer( r.layer );
809 
810  if( IsCopperLayer( layer ) )
811  {
812  // use a "netcode = 0" type ZONE:
813  ZONE* zone = new ZONE( m_board );
814  m_board->Add( zone, ADD_MODE::APPEND );
815 
816  zone->SetLayer( layer );
818 
820 
821  const int outlineIdx = -1; // this is the id of the copper zone main outline
822  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
823  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
824  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
825  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
826 
827  if( r.rot )
828  zone->Rotate( zone->GetPosition(), r.rot->degrees * 10 );
829 
830  // this is not my fault:
831  zone->SetBorderDisplayStyle( outline_hatch, ZONE::GetDefaultHatchPitch(),
832  true );
833  }
834 
835  m_xpath->pop();
836  }
837  else if( grName == "hole" )
838  {
839  m_xpath->push( "hole" );
840 
841  // Fabricate a FOOTPRINT with a single PAD_ATTRIB_NPTH pad.
842  // Use m_hole_count to gen up a unique name.
843 
844  FOOTPRINT* footprint = new FOOTPRINT( m_board );
845  m_board->Add( footprint, ADD_MODE::APPEND );
846  footprint->SetReference( wxString::Format( "@HOLE%d", m_hole_count++ ) );
847  footprint->Reference().SetVisible( false );
848 
849  packageHole( footprint, gr, true );
850 
851  m_xpath->pop();
852  }
853  else if( grName == "frame" )
854  {
855  // picture this
856  }
857  else if( grName == "polygon" )
858  {
859  m_xpath->push( "polygon" );
860  loadPolygon( gr );
861  m_xpath->pop(); // "polygon"
862  }
863  else if( grName == "dimension" )
864  {
865  EDIMENSION d( gr );
866  PCB_LAYER_ID layer = kicad_layer( d.layer );
867 
868  if( layer != UNDEFINED_LAYER )
869  {
870  const BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
871  ALIGNED_DIMENSION* dimension = new ALIGNED_DIMENSION( m_board );
872  m_board->Add( dimension, ADD_MODE::APPEND );
873 
874  if( d.dimensionType )
875  {
876  // Eagle dimension graphic arms may have different lengths, but they look
877  // incorrect in KiCad (the graphic is tilted). Make them even length in such case.
878  if( *d.dimensionType == "horizontal" )
879  {
880  int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
881  d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
882  d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
883  }
884  else if( *d.dimensionType == "vertical" )
885  {
886  int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
887  d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
888  d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
889  }
890  }
891 
892  dimension->SetLayer( layer );
893  dimension->SetPrecision( DIMENSION_PRECISION );
894  // The origin and end are assumed to always be in this order from eagle
895  dimension->SetStart( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
896  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
897  dimension->Text().SetTextSize( designSettings.GetTextSize( layer ) );
898  dimension->Text().SetTextThickness( designSettings.GetTextThickness( layer ) );
899  dimension->SetLineThickness( designSettings.GetLineThickness( layer ) );
900  dimension->SetUnits( EDA_UNITS::MILLIMETRES );
901 
902  // check which axis the dimension runs in
903  // because the "height" of the dimension is perpendicular to that axis
904  // Note the check is just if two axes are close enough to each other
905  // Eagle appears to have some rounding errors
906  if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm
907  dimension->SetHeight( kicad_x( d.x3 - d.x1 ) );
908  else
909  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
910  }
911  }
912 
913  // Get next graphic
914  gr = gr->GetNext();
915  }
916  m_xpath->pop();
917 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
void SetReference(const wxString &aReference)
Definition: footprint.h:441
int sign(T val)
Definition: util.h:101
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
virtual void SetStart(const wxPoint &aPoint)
Definition: dimension.h:122
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:893
void SetTextAngle(double aAngle) override
Definition: pcb_text.cpp:102
void SetFilled(bool aFlag)
Definition: pcb_shape.h:94
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: dimension.cpp:212
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
void SetVisible(bool aVisible)
Definition: eda_text.h:192
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
Arcs (with rounded ends)
Definition: board_item.h:52
void SetUnits(EDA_UNITS aUnits)
Definition: dimension.cpp:144
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
Eagle text element.
Definition: eagle_parser.h:637
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
FP_TEXT & Reference()
Definition: footprint.h:469
void Rotate(const wxPoint &aCentre, double aAngle) override
Move the outlines.
Definition: zone.cpp:704
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
PCB_LAYER_ID
A quick note on layer IDs:
void SetHeight(int aHeight)
Sets the distance from the feature points to the crossbar line.
Definition: dimension.h:371
void NewHole()
Create a new hole on the zone; i.e., a new contour on the zone's outline.
Definition: zone.h:594
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
static int GetDefaultHatchPitch()
Definition: zone.cpp:1087
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
Eagle circle.
Definition: eagle_parser.h:562
PCB_TEXT & Text()
Definition: dimension.h:209
virtual void SetEnd(const wxPoint &aPoint)
Definition: dimension.h:125
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:290
Eagle XML rectangle in binary.
Definition: eagle_parser.h:575
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static wxString interpret_text(const wxString &aText)
interpret special characters in Eagle text and converts them to KiCAD notation
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
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: zone.cpp:833
wxPoint GetPosition() const override
Definition: zone.cpp:210
void SetStart(const wxPoint &aStart)
Definition: pcb_shape.h:148
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
void SetPrecision(int aPrecision)
Definition: dimension.h:170
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
#define DIMENSION_PRECISION
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
static void setKeepoutSettingsToZone(ZONE *aZone, LAYER_NUM aLayer)
Eagle wire.
Definition: eagle_parser.h:491
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
ring
Definition: board_item.h:53
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
Definition: zone_settings.h:46
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:236
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
Eagle dimension element.
Definition: eagle_parser.h:620
void pop()
Definition: eagle_parser.h:122
void SetLineThickness(int aWidth)
Definition: dimension.h:188
For better understanding of the points that make a dimension:
Definition: dimension.h:334
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: pcb_shape.cpp:466
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:365
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
void SetEnd(const wxPoint &aEnd)
Definition: pcb_shape.h:159
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
Container for design settings for a BOARD object.

References BOARD::Add(), ETEXT::align, PNS::angle(), APPEND, ZONE::AppendCorner(), ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, EAGLE_LAYER::BRESTRICT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, ConvertArcCenter(), EWIRE::curve, EROT::degrees, DIAGONAL_EDGE, DIMENSION_PRECISION, EDIMENSION::dimensionType, Format(), FROM_UTF8(), ZONE::GetDefaultHatchPitch(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetLineThickness(), ZONE::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, interpret_text(), IsCopperLayer(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EWIRE::layer, ECIRCLE::layer, ERECT::layer, EDIMENSION::layer, ETEXT::layer, loadPolygon(), m_board, m_hole_count, m_xpath, MILLIMETRES, EROT::mirror, ZONE::NewHole(), packageHole(), XPATH::pop(), XPATH::push(), ECIRCLE::radius, ETEXT::ratio, FOOTPRINT::Reference(), ERECT::rot, ETEXT::rot, ZONE::Rotate(), RotatePoint(), S_ARC, S_CIRCLE, PCB_SHAPE::SetAngle(), ZONE::SetBorderDisplayStyle(), DIMENSION_BASE::SetEnd(), PCB_SHAPE::SetEnd(), PCB_SHAPE::SetFilled(), ALIGNED_DIMENSION::SetHeight(), EDA_TEXT::SetHorizJustify(), setKeepoutSettingsToZone(), ZONE::SetLayer(), DIMENSION_BASE::SetLayer(), BOARD_ITEM::SetLayer(), DIMENSION_BASE::SetLineThickness(), EDA_TEXT::SetMirrored(), BOARD_CONNECTED_ITEM::SetNetCode(), DIMENSION_BASE::SetPrecision(), FOOTPRINT::SetReference(), PCB_SHAPE::SetShape(), DIMENSION_BASE::SetStart(), PCB_SHAPE::SetStart(), EDA_TEXT::SetText(), PCB_TEXT::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), DIMENSION_BASE::SetUnits(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), PCB_SHAPE::SetWidth(), sign(), ETEXT::size, EROT::spin, DIMENSION_BASE::Text(), ETEXT::text, ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, NETINFO_LIST::UNCONNECTED, UNDEFINED_LAYER, EAGLE_LAYER::VRESTRICT, 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 * EAGLE_PLUGIN::loadPolygon ( wxXmlNode *  aPolyNode)
private

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

Returns
The loaded zone or nullptr if was not processed.

Definition at line 1249 of file eagle_plugin.cpp.

1250 {
1251  EPOLYGON p( aPolyNode );
1252  PCB_LAYER_ID layer = kicad_layer( p.layer );
1253  ZONE* zone = nullptr;
1254  bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT
1255  || p.layer == EAGLE_LAYER::BRESTRICT
1256  || p.layer == EAGLE_LAYER::VRESTRICT );
1257 
1258  if( layer == UNDEFINED_LAYER ) {
1259  wxLogMessage( wxString::Format(
1260  _( "Ignoring a polygon since Eagle layer '%s' (%d) "
1261  "was not mapped" ),
1262  eagle_layer_name( p.layer ),
1263  p.layer ) );
1264  return nullptr;
1265  }
1266 
1267  if( !IsCopperLayer( layer ) && !keepout )
1268  return nullptr;
1269 
1270  // use a "netcode = 0" type ZONE:
1271  zone = new ZONE( m_board );
1272  m_board->Add( zone, ADD_MODE::APPEND );
1273 
1274  if( !keepout )
1275  zone->SetLayer( layer );
1276  else
1277  setKeepoutSettingsToZone( zone, p.layer );
1278 
1279  // Get the first vertex and iterate
1280  wxXmlNode* vertex = aPolyNode->GetChildren();
1281  std::vector<EVERTEX> vertices;
1282 
1283  // Create a circular vector of vertices
1284  // The "curve" parameter indicates a curve from the current
1285  // to the next vertex, so we keep the first at the end as well
1286  // to allow the curve to link back
1287  while( vertex )
1288  {
1289  if( vertex->GetName() == "vertex" )
1290  vertices.emplace_back( vertex );
1291 
1292  vertex = vertex->GetNext();
1293  }
1294 
1295  vertices.push_back( vertices[0] );
1296 
1297  SHAPE_POLY_SET polygon;
1298  polygon.NewOutline();
1299 
1300  for( size_t i = 0; i < vertices.size() - 1; i++ )
1301  {
1302  EVERTEX v1 = vertices[i];
1303 
1304  // Append the corner
1305  polygon.Append( kicad_x( v1.x ), kicad_y( v1.y ) );
1306 
1307  if( v1.curve )
1308  {
1309  EVERTEX v2 = vertices[i + 1];
1310  wxPoint center = ConvertArcCenter( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1311  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ),
1312  *v1.curve );
1313  double angle = DEG2RAD( *v1.curve );
1314  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1315  kicad_x( v2.x ) - center.x );
1316  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1317  + pow( center.y - kicad_y( v1.y ), 2 ) );
1318 
1319  int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, *v1.curve );
1320  double delta_angle = angle / segCount;
1321 
1322  for( double a = end_angle + angle;
1323  fabs( a - end_angle ) > fabs( delta_angle );
1324  a -= delta_angle )
1325  {
1326  polygon.Append( KiROUND( radius * cos( a ) ) + center.x,
1327  KiROUND( radius * sin( a ) ) + center.y );
1328  }
1329  }
1330  }
1331 
1332  // Eagle traces the zone such that half of the pen width is outside the polygon.
1333  // We trace the zone such that the copper is completely inside.
1334  if( p.width.ToPcbUnits() > 0 )
1335  {
1336  polygon.Inflate( p.width.ToPcbUnits() / 2, 32, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS );
1338  }
1339 
1340  zone->AddPolygon( polygon.COutline( 0 ) );
1341 
1342  // If the pour is a cutout it needs to be set to a keepout
1343  if( p.pour == EPOLYGON::CUTOUT )
1344  {
1345  zone->SetIsRuleArea( true );
1346  zone->SetDoNotAllowVias( false );
1347  zone->SetDoNotAllowTracks( false );
1348  zone->SetDoNotAllowPads( false );
1349  zone->SetDoNotAllowFootprints( false );
1350  zone->SetDoNotAllowCopperPour( true );
1352  }
1353  else if( p.pour == EPOLYGON::HATCH )
1354  {
1355  int spacing = p.spacing ? p.spacing->ToPcbUnits() : 50 * IU_PER_MILS;
1356 
1358  zone->SetHatchThickness( p.width.ToPcbUnits() );
1359  zone->SetHatchGap( spacing - p.width.ToPcbUnits() );
1360  zone->SetHatchOrientation( 0 );
1361  }
1362 
1363  // We divide the thickness by half because we are tracing _inside_ the zone outline
1364  // This means the radius of curvature will be twice the size for an equivalent EAGLE zone
1366  p.width.ToPcbUnits() / 2 ) );
1367 
1368  if( p.isolate )
1369  zone->SetLocalClearance( p.isolate->ToPcbUnits() );
1370  else
1371  zone->SetLocalClearance( 1 ); // @todo: set minimum clearance value based on board settings
1372 
1373  // missing == yes per DTD.
1374  bool thermals = !p.thermals || *p.thermals;
1376 
1377  if( thermals )
1378  {
1379  // FIXME: eagle calculates dimensions for thermal spokes
1380  // based on what the zone is connecting to.
1381  // (i.e. width of spoke is half of the smaller side of an smd pad)
1382  // This is a basic workaround
1383  zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
1384  zone->SetThermalReliefSpokeWidth( p.width.ToPcbUnits() + 50000 );
1385  }
1386 
1387  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
1388  zone->SetPriority( rank );
1389 
1390  return zone;
1391 }
Eagle vertex.
Definition: eagle_parser.h:759
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
void SetHatchThickness(int aThickness)
Definition: zone.h:251
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:742
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetHatchStyle(ZONE_BORDER_DISPLAY_STYLE aStyle)
Definition: zone.h:611
ECOORD y
Definition: eagle_parser.h:762
void Inflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
void SetPriority(unsigned aPriority)
Definition: zone.h:117
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: zone.h:180
void SetIsRuleArea(bool aEnable)
Definition: zone.h:739
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
PCB_LAYER_ID
A quick note on layer IDs:
pads are covered by copper
void SetHatchGap(int aStep)
Definition: zone.h:254
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:743
Represent a set of closed polygons.
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:741
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
void SetMinThickness(int aMinThickness)
Definition: zone.h:242
int NewOutline()
Creates a new hole in a given outline.
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:763
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Use thermal relief for pads.
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:239
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:32
ECOORD x
Definition: eagle_parser.h:761
double DEG2RAD(double deg)
Definition: trigo.h:231
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:740
#define _(s)
Definition: 3d_actions.cpp:33
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
#define IU_PER_MILS
Definition: plotter.cpp:137
void SetHatchOrientation(double aStep)
Definition: zone.h:257
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
static void setKeepoutSettingsToZone(ZONE *aZone, LAYER_NUM aLayer)
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:183
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:236
void SetLocalClearance(int aClearance)
Definition: zone.h:158
void AddPolygon(std::vector< wxPoint > &aPolygon)
Add a polygon to the zone outline.
Definition: zone.cpp:816
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:770
just inflate the polygon. Acute angles create spikes
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:744
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:193

References _, BOARD::Add(), ZONE::AddPolygon(), SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS, PNS::angle(), APPEND, SHAPE_POLY_SET::Append(), EAGLE_LAYER::BRESTRICT, ConvertArcCenter(), SHAPE_POLY_SET::COutline(), EVERTEX::curve, EPOLYGON::CUTOUT, DEG2RAD(), eagle_layer_name(), Format(), SHAPE_POLY_SET::Fracture(), FULL, GetArcToSegmentCount(), EPOLYGON::HATCH, HATCH_PATTERN, SHAPE_POLY_SET::Inflate(), IsCopperLayer(), EPOLYGON::isolate, IU_PER_MILS, kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, m_board, EPOLYGON::max_priority, SHAPE_POLY_SET::NewOutline(), NO_HATCH, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, EPOLYGON::pour, EPOLYGON::rank, ZONE::SetDoNotAllowCopperPour(), ZONE::SetDoNotAllowFootprints(), ZONE::SetDoNotAllowPads(), ZONE::SetDoNotAllowTracks(), ZONE::SetDoNotAllowVias(), ZONE::SetFillMode(), ZONE::SetHatchGap(), ZONE::SetHatchOrientation(), ZONE::SetHatchStyle(), ZONE::SetHatchThickness(), ZONE::SetIsRuleArea(), setKeepoutSettingsToZone(), ZONE::SetLayer(), ZONE::SetLocalClearance(), ZONE::SetMinThickness(), ZONE::SetPadConnection(), ZONE::SetPriority(), ZONE::SetThermalReliefGap(), ZONE::SetThermalReliefSpokeWidth(), EPOLYGON::spacing, THERMAL, EPOLYGON::thermals, ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, UNDEFINED_LAYER, v2, EAGLE_LAYER::VRESTRICT, EPOLYGON::width, VECTOR2< T >::x, EVERTEX::x, VECTOR2< T >::y, EVERTEX::y, and ZONE_THICKNESS_MIN_VALUE_MIL.

Referenced by loadPlain(), and loadSignals().

◆ loadSignals()

void EAGLE_PLUGIN::loadSignals ( wxXmlNode *  aSignals)
private

Definition at line 2288 of file eagle_plugin.cpp.

2289 {
2290  ZONES zones; // per net
2291 
2292  m_xpath->push( "signals.signal", "name" );
2293 
2294  int netCode = 1;
2295 
2296  // Get the first signal and iterate
2297  wxXmlNode* net = aSignals->GetChildren();
2298 
2299  while( net )
2300  {
2301  bool sawPad = false;
2302 
2303  zones.clear();
2304 
2305  const wxString& netName = escapeName( net->GetAttribute( "name" ) );
2306  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
2307 
2308  m_xpath->Value( netName.c_str() );
2309 
2310  // Get the first net item and iterate
2311  wxXmlNode* netItem = net->GetChildren();
2312 
2313  // (contactref | polygon | wire | via)*
2314  while( netItem )
2315  {
2316  const wxString& itemName = netItem->GetName();
2317 
2318  if( itemName == "wire" )
2319  {
2320  m_xpath->push( "wire" );
2321 
2322  EWIRE w( netItem );
2323  PCB_LAYER_ID layer = kicad_layer( w.layer );
2324 
2325  if( IsCopperLayer( layer ) )
2326  {
2327  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
2328  double angle = 0.0;
2329  double end_angle = 0.0;
2330  double radius = 0.0;
2331  double delta_angle = 0.0;
2332  wxPoint center;
2333 
2334  int width = w.width.ToPcbUnits();
2335  if( width < m_min_trace )
2336  m_min_trace = width;
2337 
2338  if( w.curve )
2339  {
2340  center = ConvertArcCenter(
2341  wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
2342  wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
2343  *w.curve );
2344 
2345  angle = DEG2RAD( *w.curve );
2346 
2347  end_angle = atan2( kicad_y( w.y2 ) - center.y,
2348  kicad_x( w.x2 ) - center.x );
2349 
2350  radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
2351  pow( center.y - kicad_y( w.y1 ), 2 ) );
2352 
2353  int segs = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, *w.curve );
2354  delta_angle = angle / segs;
2355  }
2356 
2357  while( fabs( angle ) > fabs( delta_angle ) )
2358  {
2359  wxASSERT( radius > 0.0 );
2360  wxPoint end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
2361  KiROUND( radius * sin( end_angle + angle ) + center.y ) );
2362 
2363  TRACK* t = new TRACK( m_board );
2364 
2365  t->SetPosition( start );
2366  t->SetEnd( end );
2367  t->SetWidth( width );
2368  t->SetLayer( layer );
2369  t->SetNetCode( netCode );
2370 
2371  m_board->Add( t );
2372 
2373  start = end;
2374  angle -= delta_angle;
2375  }
2376 
2377  TRACK* t = new TRACK( m_board );
2378 
2379  t->SetPosition( start );
2380  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2381  t->SetWidth( width );
2382  t->SetLayer( layer );
2383  t->SetNetCode( netCode );
2384 
2385  m_board->Add( t );
2386  }
2387  else
2388  {
2389  // put non copper wires where the sun don't shine.
2390  }
2391 
2392  m_xpath->pop();
2393  }
2394 
2395  else if( itemName == "via" )
2396  {
2397  m_xpath->push( "via" );
2398  EVIA v( netItem );
2399 
2400  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2401  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2402 
2403  if( IsCopperLayer( layer_front_most ) &&
2404  IsCopperLayer( layer_back_most ) )
2405  {
2406  int kidiam;
2407  int drillz = v.drill.ToPcbUnits();
2408  VIA* via = new VIA( m_board );
2409  m_board->Add( via );
2410 
2411  via->SetLayerPair( layer_front_most, layer_back_most );
2412 
2413  if( v.diam )
2414  {
2415  kidiam = v.diam->ToPcbUnits();
2416  via->SetWidth( kidiam );
2417  }
2418  else
2419  {
2420  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2421  annulus = eagleClamp( m_rules->rlMinViaOuter, annulus,
2423  kidiam = KiROUND( drillz + 2 * annulus );
2424  via->SetWidth( kidiam );
2425  }
2426 
2427  via->SetDrill( drillz );
2428 
2429  // make sure the via diameter respects the restring rules
2430 
2431  if( !v.diam || via->GetWidth() <= via->GetDrill() )
2432  {
2433  double annulus = eagleClamp( m_rules->rlMinViaOuter,
2434  (double)( via->GetWidth() / 2 - via->GetDrill() ),
2436  via->SetWidth( drillz + 2 * annulus );
2437  }
2438 
2439  if( kidiam < m_min_via )
2440  m_min_via = kidiam;
2441 
2442  if( drillz < m_min_hole )
2443  m_min_hole = drillz;
2444 
2445  if( ( kidiam - drillz ) / 2 < m_min_annulus )
2446  m_min_annulus = ( kidiam - drillz ) / 2;
2447 
2448  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2449  via->SetViaType( VIATYPE::THROUGH );
2450  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2451  via->SetViaType( VIATYPE::MICROVIA );
2452  else
2453  via->SetViaType( VIATYPE::BLIND_BURIED );
2454 
2455  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2456 
2457  via->SetPosition( pos );
2458  via->SetEnd( pos );
2459 
2460  via->SetNetCode( netCode );
2461  }
2462 
2463  m_xpath->pop();
2464  }
2465 
2466  else if( itemName == "contactref" )
2467  {
2468  m_xpath->push( "contactref" );
2469  // <contactref element="RN1" pad="7"/>
2470 
2471  const wxString& reference = netItem->GetAttribute( "element" );
2472  const wxString& pad = netItem->GetAttribute( "pad" );
2473  wxString key = makeKey( reference, pad ) ;
2474 
2475  m_pads_to_nets[ key ] = ENET( netCode, netName );
2476 
2477  m_xpath->pop();
2478 
2479  sawPad = true;
2480  }
2481 
2482  else if( itemName == "polygon" )
2483  {
2484  m_xpath->push( "polygon" );
2485  auto* zone = loadPolygon( netItem );
2486 
2487  if( zone )
2488  {
2489  zones.push_back( zone );
2490 
2491  if( !zone->GetIsRuleArea() )
2492  zone->SetNetCode( netCode );
2493  }
2494 
2495  m_xpath->pop(); // "polygon"
2496  }
2497 
2498  netItem = netItem->GetNext();
2499  }
2500 
2501  if( zones.size() && !sawPad )
2502  {
2503  // KiCad does not support an unconnected zone with its own non-zero netcode,
2504  // but only when assigned netcode = 0 w/o a name...
2505  for( ZONE* zone : zones )
2506  zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
2507 
2508  // therefore omit this signal/net.
2509  }
2510  else
2511  netCode++;
2512 
2513  // Get next signal
2514  net = net->GetNext();
2515  }
2516 
2517  m_xpath->pop(); // "signals.signal"
2518 }
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:43
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:119
Definition: track.h:343
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
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:300
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetEnd(const wxPoint &aEnd)
Definition: track.h:112
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:115
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:304
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:117
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:287
void SetWidth(int aWidth)
Definition: track.h:109
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
PCB_LAYER_ID
A quick note on layer IDs:
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)
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:302
Eagle net.
Definition: eagle_parser.h:453
Eagle via.
Definition: eagle_parser.h:547
Handle the data for a net.
Definition: netinfo.h:64
double DEG2RAD(double deg)
Definition: trigo.h:231
void SetPosition(const wxPoint &aPos) override
Definition: track.h:105
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:305
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:292
Eagle wire.
Definition: eagle_parser.h:491
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:303
void pop()
Definition: eagle_parser.h:122
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:118
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:365
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
Definition: track.h:83
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
void Value(const char *aValue)
modify the last path node's value
Definition: eagle_parser.h:125

References BOARD::Add(), PNS::angle(), B_Cu, BLIND_BURIED, ConvertArcCenter(), EWIRE::curve, DEG2RAD(), EVIA::diam, EVIA::drill, eagleClamp(), escapeName(), F_Cu, GetArcToSegmentCount(), IsCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EWIRE::layer, EVIA::layer_back_most, EVIA::layer_front_most, loadPolygon(), m_board, m_min_annulus, m_min_hole, m_min_trace, m_min_via, m_pads_to_nets, m_rules, m_xpath, makeKey(), MICROVIA, pad, XPATH::pop(), XPATH::push(), ERULES::rlMaxViaOuter, ERULES::rlMinViaOuter, ERULES::rvViaOuter, TRACK::SetEnd(), BOARD_ITEM::SetLayer(), BOARD_CONNECTED_ITEM::SetNetCode(), TRACK::SetPosition(), TRACK::SetWidth(), THROUGH, ECOORD::ToPcbUnits(), TRACK, NETINFO_LIST::UNCONNECTED, XPATH::Value(), VIA, via, EWIRE::width, EVIA::x, EWIRE::x1, EWIRE::x2, EVIA::y, EWIRE::y1, and EWIRE::y2.

Referenced by loadAllSections().

◆ makeFootprint()

FOOTPRINT * EAGLE_PLUGIN::makeFootprint ( wxXmlNode *  aPackage,
const wxString &  aPkgName 
)
private

Create a FOOTPRINT from an Eagle package.

Definition at line 1550 of file eagle_plugin.cpp.

1551 {
1552  std::unique_ptr<FOOTPRINT> m = std::make_unique<FOOTPRINT>( m_board );
1553 
1554  LIB_ID fpID;
1555  fpID.Parse( aPkgName, true );
1556  m->SetFPID( fpID );
1557 
1558  // Get the first package item and iterate
1559  wxXmlNode* packageItem = aPackage->GetChildren();
1560 
1561  while( packageItem )
1562  {
1563  const wxString& itemName = packageItem->GetName();
1564 
1565  if( itemName == "description" )
1566  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1567 
1568  else if( itemName == "wire" )
1569  packageWire( m.get(), packageItem );
1570 
1571  else if( itemName == "pad" )
1572  packagePad( m.get(), packageItem );
1573 
1574  else if( itemName == "text" )
1575  packageText( m.get(), packageItem );
1576 
1577  else if( itemName == "rectangle" )
1578  packageRectangle( m.get(), packageItem );
1579 
1580  else if( itemName == "polygon" )
1581  packagePolygon( m.get(), packageItem );
1582 
1583  else if( itemName == "circle" )
1584  packageCircle( m.get(), packageItem );
1585 
1586  else if( itemName == "hole" )
1587  packageHole( m.get(), packageItem, false );
1588 
1589  else if( itemName == "smd" )
1590  packageSMD( m.get(), packageItem );
1591 
1592  packageItem = packageItem->GetNext();
1593  }
1594 
1595  return m.release();
1596 }
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:300
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packageText(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Handles common pad properties.

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

Referenced by loadLibrary().

◆ mapEagleLayersToKicad()

void EAGLE_PLUGIN::mapEagleLayersToKicad ( )
private

Generate mapping between Eagle na KiCad layers.

Definition at line 2534 of file eagle_plugin.cpp.

2535 {
2536  std::vector<INPUT_LAYER_DESC> inputDescs;
2537 
2538  for ( const std::pair<const int, ELAYER>& layerPair : m_eagleLayers )
2539  {
2540  const ELAYER& eLayer = layerPair.second;
2541 
2542  INPUT_LAYER_DESC layerDesc;
2543  std::tie( layerDesc.AutoMapLayer, layerDesc.PermittedLayers, layerDesc.Required ) =
2544  defaultKicadLayer( eLayer.number );
2545 
2546  if( layerDesc.AutoMapLayer == UNDEFINED_LAYER )
2547  continue; // Ignore unused copper layers
2548 
2549  layerDesc.Name = eLayer.name;
2550 
2551  inputDescs.push_back( layerDesc );
2552  }
2553 
2554  m_layer_map = m_layer_mapping_handler( inputDescs );
2555 }
int number
Definition: eagle_parser.h:828
Describes an imported layer and how it could be mapped to KiCad Layers.
wxString name
Definition: eagle_parser.h:829
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:282
LSET PermittedLayers
KiCad layers that the imported layer can be mapped onto.
bool Required
Should we require the layer to be assigned?
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer(int aEagleLayer) const
Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping...
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:284
wxString Name
Imported layer name as displayed in original application.
PCB_LAYER_ID AutoMapLayer
Best guess as to what the equivalent KiCad layer might be.

References INPUT_LAYER_DESC::AutoMapLayer, defaultKicadLayer(), m_eagleLayers, m_layer_map, LAYER_REMAPPABLE_PLUGIN::m_layer_mapping_handler, INPUT_LAYER_DESC::Name, ELAYER::name, ELAYER::number, INPUT_LAYER_DESC::PermittedLayers, INPUT_LAYER_DESC::Required, and UNDEFINED_LAYER.

Referenced by loadAllSections().

◆ orientFootprintAndText()

void EAGLE_PLUGIN::orientFootprintAndText ( FOOTPRINT aFootprint,
const EELEMENT e,
const EATTR aNameAttr,
const EATTR aValueAttr 
)
private

Definition at line 1394 of file eagle_plugin.cpp.

1396 {
1397  if( e.rot )
1398  {
1399  if( e.rot->mirror )
1400  {
1401  double orientation = e.rot->degrees + 180.0;
1402  aFootprint->SetOrientation( orientation * 10 );
1403  aFootprint->Flip( aFootprint->GetPosition(), false );
1404  }
1405  else
1406  {
1407  aFootprint->SetOrientation( e.rot->degrees * 10 );
1408  }
1409  }
1410 
1411  orientFPText( aFootprint, e, &aFootprint->Reference(), aNameAttr );
1412  orientFPText( aFootprint, e, &aFootprint->Value(), aValueAttr );
1413 }
bool mirror
Definition: eagle_parser.h:472
opt_erot rot
Definition: eagle_parser.h:820
double degrees
Definition: eagle_parser.h:474
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:468
FP_TEXT & Reference()
Definition: footprint.h:469
void SetOrientation(double aNewAngle)
Definition: footprint.cpp:1557
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1367
wxPoint GetPosition() const override
Definition: footprint.h:182
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, FP_TEXT *aFPText, const EATTR *aAttr)

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

Referenced by loadElements().

◆ orientFPText()

void EAGLE_PLUGIN::orientFPText ( FOOTPRINT aFootprint,
const EELEMENT e,
FP_TEXT aFPText,
const EATTR aAttr 
)
private

Definition at line 1416 of file eagle_plugin.cpp.

1418 {
1419  // Smashed part ?
1420  if( aAttr )
1421  { // Yes
1422  const EATTR& a = *aAttr;
1423 
1424  if( a.value )
1425  {
1426  aFPText->SetText( FROM_UTF8( a.value->c_str() ) );
1427  }
1428 
1429  if( a.x && a.y ) // OPT
1430  {
1431  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1432  aFPText->SetTextPos( pos );
1433  }
1434 
1435  // Even though size and ratio are both optional, I am not seeing
1436  // a case where ratio is present but size is not.
1437  double ratio = 8;
1438  wxSize fontz = aFPText->GetTextSize();
1439  int textThickness = KiROUND( fontz.y * ratio / 100 );
1440 
1441  aFPText->SetTextThickness( textThickness );
1442  if( a.size )
1443  {
1444  fontz = kicad_fontz( *a.size, textThickness );
1445  aFPText->SetTextSize( fontz );
1446 
1447  if( a.ratio )
1448  ratio = *a.ratio;
1449  }
1450 
1451 
1452 
1453  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1454 
1455  if( a.align )
1456  align = a.align;
1457 
1458  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1459  // present, and this zero rotation becomes an override to the
1460  // package's text field. If they did not want zero, they specify
1461  // what they want explicitly.
1462  double degrees = a.rot ? a.rot->degrees : 0;
1463  double orient; // relative to parent
1464 
1465  int sign = 1;
1466  bool spin = false;
1467 
1468  if( a.rot )
1469  {
1470  spin = a.rot->spin;
1471  sign = a.rot->mirror ? -1 : 1;
1472  aFPText->SetMirrored( a.rot->mirror );
1473  }
1474 
1475  if( degrees == 90 || degrees == 0 || spin )
1476  {
1477  orient = degrees - aFootprint->GetOrientation() / 10;
1478  aFPText->SetTextAngle( sign * orient * 10 );
1479  }
1480  else if( degrees == 180 )
1481  {
1482  orient = 0 - aFootprint->GetOrientation() / 10;
1483  aFPText->SetTextAngle( sign * orient * 10 );
1484  align = -align;
1485  }
1486  else if( degrees == 270 )
1487  {
1488  orient = 90 - aFootprint->GetOrientation() / 10;
1489  align = -align;
1490  aFPText->SetTextAngle( sign * orient * 10 );
1491  }
1492  else
1493  {
1494  orient = 90 - degrees - aFootprint->GetOrientation() / 10;
1495  aFPText->SetTextAngle( sign * orient * 10 );
1496  }
1497 
1498  switch( align )
1499  {
1500  case ETEXT::TOP_RIGHT:
1503  break;
1504 
1505  case ETEXT::BOTTOM_LEFT:
1508  break;
1509 
1510  case ETEXT::TOP_LEFT:
1513  break;
1514 
1515  case ETEXT::BOTTOM_RIGHT:
1518  break;
1519 
1520  case ETEXT::TOP_CENTER:
1523  break;
1524 
1525  case ETEXT::BOTTOM_CENTER:
1528  break;
1529 
1530  default:
1531  ;
1532  }
1533  }
1534  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1535  {
1536  double degrees = ( aFPText->GetTextAngle() + aFootprint->GetOrientation() ) / 10;
1537 
1538  // @todo there are a few more cases than these to contend with:
1539  if( ( !aFPText->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ) )
1540  || ( aFPText->IsMirrored() && ( degrees == 360 ) ) )
1541  {
1542  // ETEXT::TOP_RIGHT:
1545  }
1546  }
1547 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
int sign(T val)
Definition: util.h:101
bool mirror
Definition: eagle_parser.h:472
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
bool IsMirrored() const
Definition: eda_text.h:196
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
void SetTextAngle(double aAngle) override
Definition: fp_text.cpp:70
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
double GetOrientation() const
Definition: footprint.h:186
double GetTextAngle() const
Definition: eda_text.h:181
double degrees
Definition: eagle_parser.h:474
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
opt_erot rot
Definition: eagle_parser.h:603
opt_int align
Definition: eagle_parser.h:612
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
opt_ecoord y
Definition: eagle_parser.h:599
const wxSize & GetTextSize() const
Definition: eda_text.h:245
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
opt_wxString value
Definition: eagle_parser.h:597
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:594
opt_ecoord x
Definition: eagle_parser.h:598
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
opt_double ratio
Definition: eagle_parser.h:602
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
bool spin
Definition: eagle_parser.h:473
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
opt_ecoord size
Definition: eagle_parser.h:600

References EATTR::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, EROT::degrees, FROM_UTF8(), FOOTPRINT::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(), KiROUND(), EROT::mirror, EATTR::ratio, EATTR::rot, EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetMirrored(), EDA_TEXT::SetText(), FP_TEXT::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), 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 orientFootprintAndText().

◆ packageCircle()

void EAGLE_PLUGIN::packageCircle ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Definition at line 2058 of file eagle_plugin.cpp.

2059 {
2060  ECIRCLE e( aTree );
2061 
2062  int width = e.width.ToPcbUnits();
2063  int radius = e.radius.ToPcbUnits();
2064 
2065  if( e.layer == EAGLE_LAYER::TRESTRICT
2066  || e.layer == EAGLE_LAYER::BRESTRICT
2067  || e.layer == EAGLE_LAYER::VRESTRICT )
2068  {
2069  FP_ZONE* zone = new FP_ZONE( aFootprint );
2070  aFootprint->Add( zone, ADD_MODE::APPEND );
2071 
2072  setKeepoutSettingsToZone( zone, e.layer );
2073 
2074  // approximate circle as polygon with a edge every 10 degree
2075  wxPoint center( kicad_x( e.x ), kicad_y( e.y ) );
2076  int outlineRadius = radius + ( width / 2 );
2077  for( int angle = 0; angle < 360; angle += 10 )
2078  {
2079  wxPoint rotatedPoint( outlineRadius, 0 );
2080  RotatePoint( &rotatedPoint, angle * 10. );
2081  zone->AppendCorner( center + rotatedPoint, -1 );
2082  }
2083 
2084  if( width > 0 )
2085  {
2086  zone->NewHole();
2087  int innerRadius = radius - ( width / 2 );
2088  for( int angle = 0; angle < 360; angle += 10 )
2089  {
2090  wxPoint rotatedPoint( innerRadius, 0 );
2091  RotatePoint( &rotatedPoint, angle * 10. );
2092  zone->AppendCorner( center + rotatedPoint, 0 );
2093  }
2094  }
2095 
2097  ZONE::GetDefaultHatchPitch(), true );
2098  }
2099  else
2100  {
2101  PCB_LAYER_ID layer = kicad_layer( e.layer );
2102 
2103  if( layer == UNDEFINED_LAYER )
2104  {
2105  wxLogMessage( wxString::Format( _( "Ignoring a circle since Eagle layer '%s' (%d) "
2106  "was not mapped" ),
2107  eagle_layer_name( e.layer ),
2108  e.layer ) );
2109  return;
2110  }
2111 
2112  FP_SHAPE* gr = new FP_SHAPE( aFootprint, S_CIRCLE );
2113 
2114  // with == 0 means filled circle
2115  if( width <= 0 )
2116  {
2117  width = radius;
2118  radius = radius / 2;
2119  }
2120 
2121  aFootprint->Add( gr );
2122  gr->SetWidth( width );
2123 
2124  switch( (int) layer )
2125  {
2126  case UNDEFINED_LAYER:
2127  layer = Cmts_User;
2128  break;
2129  default:
2130  break;
2131  }
2132 
2133  gr->SetLayer( layer );
2134  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
2135  gr->SetEnd0( wxPoint( kicad_x( e.x ) + radius, kicad_y( e.y ) ) );
2136  gr->SetDrawCoord();
2137  }
2138 }
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
void SetEnd0(const wxPoint &aPoint)
Definition: fp_shape.h:114
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:893
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
PCB_LAYER_ID
A quick note on layer IDs:
void NewHole()
Create a new hole on the zone; i.e., a new contour on the zone's outline.
Definition: zone.h:594
static int GetDefaultHatchPitch()
Definition: zone.cpp:1087
Eagle circle.
Definition: eagle_parser.h:562
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:82
void SetStart0(const wxPoint &aPoint)
Definition: fp_shape.h:111
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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: zone.cpp:833
#define _(s)
Definition: 3d_actions.cpp:33
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
static void setKeepoutSettingsToZone(ZONE *aZone, LAYER_NUM aLayer)
ring
Definition: board_item.h:53
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
A specialization of ZONE for use in footprints.
Definition: zone.h:943
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

References _, FOOTPRINT::Add(), PNS::angle(), APPEND, ZONE::AppendCorner(), EAGLE_LAYER::BRESTRICT, Cmts_User, DIAGONAL_EDGE, eagle_layer_name(), Format(), ZONE::GetDefaultHatchPitch(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, ZONE::NewHole(), ECIRCLE::radius, RotatePoint(), S_CIRCLE, ZONE::SetBorderDisplayStyle(), FP_SHAPE::SetDrawCoord(), FP_SHAPE::SetEnd0(), setKeepoutSettingsToZone(), BOARD_ITEM::SetLayer(), FP_SHAPE::SetStart0(), PCB_SHAPE::SetWidth(), ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, UNDEFINED_LAYER, EAGLE_LAYER::VRESTRICT, ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

Referenced by makeFootprint().

◆ packageHole()

void EAGLE_PLUGIN::packageHole ( FOOTPRINT aFootprint,
wxXmlNode *  aTree,
bool  aCenter 
) const
private
Parameters
aFootprintThe KiCad footprint to which to assign the hole.
aTreeThe Eagle XML node that is of type "hole".
aCenterIf true, center the hole in the footprint and offset the footprint position.

Definition at line 2141 of file eagle_plugin.cpp.

2142 {
2143  EHOLE e( aTree );
2144 
2145  // we add a PAD_ATTRIB_NPTH pad to this footprint.
2146  PAD* pad = new PAD( aFootprint );
2147  aFootprint->Add( pad );
2148 
2149  pad->SetShape( PAD_SHAPE_CIRCLE );
2150  pad->SetAttribute( PAD_ATTRIB_NPTH );
2151 
2152  // Mechanical purpose only:
2153  // no offset, no net name, no pad name allowed
2154  // pad->SetOffset( wxPoint( 0, 0 ) );
2155  // pad->SetName( wxEmptyString );
2156 
2157  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2158 
2159  if( aCenter )
2160  {
2161  pad->SetPos0( wxPoint( 0, 0 ) );
2162  aFootprint->SetPosition( padpos );
2163  pad->SetPosition( padpos );
2164  }
2165  else
2166  {
2167  pad->SetPos0( padpos );
2168  pad->SetPosition( padpos + aFootprint->GetPosition() );
2169  }
2170 
2171  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
2172 
2173  pad->SetDrillSize( sz );
2174  pad->SetSize( sz );
2175 
2176  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
2177 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
Eagle hole element.
Definition: eagle_parser.h:799
wxPoint GetPosition() const override
Definition: footprint.h:182
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
Definition: pad.h:60
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1438
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

References FOOTPRINT::Add(), LSET::AllCuMask(), B_Mask, EHOLE::drill, F_Mask, FOOTPRINT::GetPosition(), kicad_x(), kicad_y(), PAD, pad, PAD_ATTRIB_NPTH, PAD_SHAPE_CIRCLE, FOOTPRINT::SetPosition(), ECOORD::ToPcbUnits(), EHOLE::x, and EHOLE::y.

Referenced by loadPlain(), and makeFootprint().

◆ packagePad()

void EAGLE_PLUGIN::packagePad ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
)
private

Definition at line 1673 of file eagle_plugin.cpp.

1674 {
1675  // this is thru hole technology here, no SMDs
1676  EPAD e( aTree );
1677  int shape = EPAD::UNDEF;
1678  int eagleDrillz = e.drill.ToPcbUnits();
1679 
1680  PAD* pad = new PAD( aFootprint );
1681  aFootprint->Add( pad );
1682  transferPad( e, pad );
1683 
1684  if( e.first && *e.first && m_rules->psFirst != EPAD::UNDEF )
1685  shape = m_rules->psFirst;
1686  else if( aFootprint->GetLayer() == F_Cu && m_rules->psTop != EPAD::UNDEF )
1687  shape = m_rules->psTop;
1688  else if( aFootprint->GetLayer() == B_Cu && m_rules->psBottom != EPAD::UNDEF )
1689  shape = m_rules->psBottom;
1690 
1691  pad->SetDrillSize( wxSize( eagleDrillz, eagleDrillz ) );
1692  pad->SetLayerSet( LSET::AllCuMask() );
1693 
1694  if( eagleDrillz < m_min_hole )
1695  m_min_hole = eagleDrillz;
1696 
1697  // Solder mask
1698  if( !e.stop || *e.stop == true ) // enabled by default
1699  pad->SetLayerSet( pad->GetLayerSet().set( B_Mask ).set( F_Mask ) );
1700 
1701  if( shape == EPAD::ROUND || shape == EPAD::SQUARE || shape == EPAD::OCTAGON )
1702  e.shape = shape;
1703 
1704  if( e.shape )
1705  {
1706  switch( *e.shape )
1707  {
1708  case EPAD::ROUND:
1709  pad->SetShape( PAD_SHAPE_CIRCLE );
1710  break;
1711 
1712  case EPAD::OCTAGON:
1713  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1714  // pad->SetShape( PAD_OCTAGON );
1715  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in PAD constructor
1716  pad->SetShape( PAD_SHAPE_CHAMFERED_RECT );
1717  pad->SetChamferPositions( RECT_CHAMFER_ALL );
1718  pad->SetChamferRectRatio( 0.25 );
1719  break;
1720 
1721  case EPAD::LONG:
1722  pad->SetShape( PAD_SHAPE_OVAL );
1723  break;
1724 
1725  case EPAD::SQUARE:
1726  pad->SetShape( PAD_SHAPE_RECT );
1727  break;
1728 
1729  case EPAD::OFFSET:
1730  pad->SetShape( PAD_SHAPE_OVAL );
1731  break;
1732  }
1733  }
1734  else
1735  {
1736  // if shape is not present, our default is circle and that matches their default "round"
1737  }
1738 
1739  if( e.diameter )
1740  {
1741  int diameter = e.diameter->ToPcbUnits();
1742  pad->SetSize( wxSize( diameter, diameter ) );
1743  }
1744  else
1745  {
1746  double drillz = pad->GetDrillSize().x;
1747  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1748  annulus = eagleClamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1749  int diameter = KiROUND( drillz + 2 * annulus );
1750  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1751  }
1752 
1753  if( pad->GetShape() == PAD_SHAPE_OVAL )
1754  {
1755  // The Eagle "long" pad is wider than it is tall,
1756  // m_elongation is percent elongation
1757  wxSize sz = pad->GetSize();
1758  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1759  pad->SetSize( sz );
1760 
1761  if( e.shape && *e.shape == EPAD::OFFSET )
1762  {
1763  int offset = KiROUND( ( sz.x - sz.y ) / 2.0 );
1764  pad->SetOffset( wxPoint( offset, 0 ) );
1765  }
1766  }
1767 
1768  if( e.rot )
1769  {
1770  pad->SetOrientation( e.rot->degrees * 10 );
1771  }
1772 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
static T eagleClamp(T aMin, T aValue, T aMax)
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:99
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:115
Eagle thru hole pad.
Definition: eagle_parser.h:706
int psElongationLong
Definition: eagle_plugin.h:85
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:101
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:303
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:111
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
Definition: pad.h:60
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:100
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:114
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173

References FOOTPRINT::Add(), LSET::AllCuMask(), B_Cu, B_Mask, EROT::degrees, EPAD::diameter, EPAD::drill, eagleClamp(), F_Cu, F_Mask, EPAD::first, BOARD_ITEM::GetLayer(), KiROUND(), EPAD::LONG, m_min_hole, m_rules, EPAD::OCTAGON, EPAD::OFFSET, PAD, pad, 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, EPAD::shape, EPAD::SQUARE, EPAD_COMMON::stop, ECOORD::ToPcbUnits(), transferPad(), and EPAD::UNDEF.

Referenced by makeFootprint().

◆ packagePolygon()

void EAGLE_PLUGIN::packagePolygon ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Definition at line 1955 of file eagle_plugin.cpp.

1956 {
1957  EPOLYGON p( aTree );
1958 
1959  std::vector<wxPoint> pts;
1960 
1961  // Get the first vertex and iterate
1962  wxXmlNode* vertex = aTree->GetChildren();
1963  std::vector<EVERTEX> vertices;
1964 
1965  // Create a circular vector of vertices
1966  // The "curve" parameter indicates a curve from the current
1967  // to the next vertex, so we keep the first at the end as well
1968  // to allow the curve to link back
1969  while( vertex )
1970  {
1971  if( vertex->GetName() == "vertex" )
1972  vertices.emplace_back( vertex );
1973 
1974  vertex = vertex->GetNext();
1975  }
1976 
1977  vertices.push_back( vertices[0] );
1978 
1979  for( size_t i = 0; i < vertices.size() - 1; i++ )
1980  {
1981  EVERTEX v1 = vertices[i];
1982 
1983  // Append the corner
1984  pts.emplace_back( kicad_x( v1.x ), kicad_y( v1.y ) );
1985 
1986  if( v1.curve )
1987  {
1988  EVERTEX v2 = vertices[i + 1];
1989  wxPoint center = ConvertArcCenter(
1990  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1991  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1992  double angle = DEG2RAD( *v1.curve );
1993  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1994  kicad_x( v2.x ) - center.x );
1995  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1996  + pow( center.y - kicad_y( v1.y ), 2 ) );
1997 
1998  // Don't allow a zero-radius curve
1999  if( KiROUND( radius ) == 0 )
2000  radius = 1.0;
2001 
2002  int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, *v1.curve );
2003  double delta = angle / segCount;
2004 
2005  for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta ); a -= delta )
2006  {
2007  pts.push_back( wxPoint( KiROUND( radius * cos( a ) ),
2008  KiROUND( radius * sin( a ) ) ) + center );
2009  }
2010  }
2011  }
2012 
2013  if( p.layer == EAGLE_LAYER::TRESTRICT
2014  || p.layer == EAGLE_LAYER::BRESTRICT
2015  || p.layer == EAGLE_LAYER::VRESTRICT )
2016  {
2017  FP_ZONE* zone = new FP_ZONE( aFootprint );
2018  aFootprint->Add( zone, ADD_MODE::APPEND );
2019 
2020  setKeepoutSettingsToZone( zone, p.layer );
2021 
2022  SHAPE_LINE_CHAIN outline( pts );
2023  outline.SetClosed( true );
2024  zone->Outline()->AddOutline( outline );
2025 
2027  ZONE::GetDefaultHatchPitch(), true );
2028  }
2029  else
2030  {
2031  PCB_LAYER_ID layer = kicad_layer( p.layer );
2032 
2033  if( layer == UNDEFINED_LAYER )
2034  {
2035  wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
2036  "was not mapped" ),
2037  eagle_layer_name( p.layer ),
2038  p.layer ) );
2039  return;
2040  }
2041 
2042  FP_SHAPE* dwg = new FP_SHAPE( aFootprint, S_POLYGON );
2043 
2044  aFootprint->Add( dwg );
2045 
2046  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
2047  dwg->SetLayer( layer );
2048 
2049  dwg->SetPolyPoints( pts );
2050  dwg->SetStart0( *pts.begin() );
2051  dwg->SetEnd0( pts.back() );
2052  dwg->SetDrawCoord();
2053  dwg->GetPolyShape().Inflate( p.width.ToPcbUnits() / 2, 32,
2055  }
2056 }
Eagle vertex.
Definition: eagle_parser.h:759
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
void SetEnd0(const wxPoint &aPoint)
Definition: fp_shape.h:114
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
SHAPE_POLY_SET & GetPolyShape()
Definition: pcb_shape.h:268
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:893
SHAPE_POLY_SET * Outline()
Definition: zone.h:317
ECOORD y
Definition: eagle_parser.h:762
polygon (not yet used for tracks, but could be in microwave apps)
Definition: board_item.h:54
void Inflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
PCB_LAYER_ID
A quick note on layer IDs:
static int GetDefaultHatchPitch()
Definition: zone.cpp:1087
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:82
void SetStart0(const wxPoint &aPoint)
Definition: fp_shape.h:111
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:763
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
ECOORD x
Definition: eagle_parser.h:761
double DEG2RAD(double deg)
Definition: trigo.h:231
#define _(s)
Definition: 3d_actions.cpp:33
SHAPE_LINE_CHAIN.
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
static void setKeepoutSettingsToZone(ZONE *aZone, LAYER_NUM aLayer)
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:770
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
just inflate the polygon. Acute angles create spikes
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
Definition: pcb_shape.cpp:1076
A specialization of ZONE for use in footprints.
Definition: zone.h:943
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

References _, FOOTPRINT::Add(), SHAPE_POLY_SET::AddOutline(), SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS, PNS::angle(), APPEND, EAGLE_LAYER::BRESTRICT, ConvertArcCenter(), EVERTEX::curve, DEG2RAD(), DIAGONAL_EDGE, eagle_layer_name(), Format(), GetArcToSegmentCount(), ZONE::GetDefaultHatchPitch(), PCB_SHAPE::GetPolyShape(), SHAPE_POLY_SET::Inflate(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, ZONE::Outline(), S_POLYGON, ZONE::SetBorderDisplayStyle(), SHAPE_LINE_CHAIN::SetClosed(), FP_SHAPE::SetDrawCoord(), FP_SHAPE::SetEnd0(), setKeepoutSettingsToZone(), BOARD_ITEM::SetLayer(), PCB_SHAPE::SetPolyPoints(), FP_SHAPE::SetStart0(), PCB_SHAPE::SetWidth(), ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, UNDEFINED_LAYER, v2, EAGLE_LAYER::VRESTRICT, EPOLYGON::width, VECTOR2< T >::x, EVERTEX::x, VECTOR2< T >::y, and EVERTEX::y.

Referenced by makeFootprint().

◆ packageRectangle()

void EAGLE_PLUGIN::packageRectangle ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Definition at line 1886 of file eagle_plugin.cpp.

1887 {
1888  ERECT r( aTree );
1889 
1890  if( r.layer == EAGLE_LAYER::TRESTRICT || r.layer == EAGLE_LAYER::BRESTRICT
1891  || r.layer == EAGLE_LAYER::VRESTRICT )
1892  {
1893  FP_ZONE* zone = new FP_ZONE( aFootprint );
1894  aFootprint->Add( zone, ADD_MODE::APPEND );
1895 
1896  setKeepoutSettingsToZone( zone, r.layer );
1897 
1898  const int outlineIdx = -1; // this is the id of the copper zone main outline
1899  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
1900  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
1901  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
1902  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
1903 
1904  if( r.rot )
1905  {
1906  wxPoint center( ( kicad_x( r.x1 ) + kicad_x( r.x2 ) ) / 2,
1907  ( kicad_y( r.y1 ) + kicad_y( r.y2 ) ) / 2 );
1908  zone->Rotate( center, r.rot->degrees * 10 );
1909  }
1910 
1912  ZONE::GetDefaultHatchPitch(), true );
1913  }
1914  else
1915  {
1916  PCB_LAYER_ID layer = kicad_layer( r.layer );
1917 
1918  if( layer == UNDEFINED_LAYER )
1919  {
1920  wxLogMessage( wxString::Format( _( "Ignoring a rectangle since Eagle layer '%s' (%d) "
1921  "was not mapped" ),
1922  eagle_layer_name( r.layer ),
1923  r.layer ) );
1924  return;
1925  }
1926 
1927  FP_SHAPE* dwg = new FP_SHAPE( aFootprint, S_POLYGON );
1928 
1929  aFootprint->Add( dwg );
1930 
1931  dwg->SetLayer( layer );
1932  dwg->SetWidth( 0 );
1933 
1934  std::vector<wxPoint> pts;
1935 
1936  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1937  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1938 
1939  pts.push_back( start );
1940  pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y1 ) );
1941  pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y2 ) );
1942  pts.push_back( end );
1943 
1944  dwg->SetPolyPoints( pts );
1945 
1946  dwg->SetStart0( start );
1947  dwg->SetEnd0( end );
1948 
1949  if( r.rot )
1950  dwg->Rotate( dwg->GetCenter(), r.rot->degrees * 10 );
1951  }
1952 }
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
void SetEnd0(const wxPoint &aPoint)
Definition: fp_shape.h:114
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:893
polygon (not yet used for tracks, but could be in microwave apps)
Definition: board_item.h:54
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
void Rotate(const wxPoint &aCentre, double aAngle) override
Move the outlines.
Definition: zone.cpp:704
PCB_LAYER_ID
A quick note on layer IDs:
static int GetDefaultHatchPitch()
Definition: zone.cpp:1087
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
Definition: fp_shape.cpp:277
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.cpp:342
Eagle XML rectangle in binary.
Definition: eagle_parser.h:575
void SetStart0(const wxPoint &aPoint)
Definition: fp_shape.h:111
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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: zone.cpp:833
#define _(s)
Definition: 3d_actions.cpp:33
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
static void setKeepoutSettingsToZone(ZONE *aZone, LAYER_NUM aLayer)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
Definition: pcb_shape.cpp:1076
A specialization of ZONE for use in footprints.
Definition: zone.h:943
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

References _, FOOTPRINT::Add(), APPEND, ZONE::AppendCorner(), EAGLE_LAYER::BRESTRICT, EROT::degrees, DIAGONAL_EDGE, eagle_layer_name(), Format(), PCB_SHAPE::GetCenter(), ZONE::GetDefaultHatchPitch(), kicad_layer(), kicad_x(), kicad_y(), ERECT::layer, ERECT::rot, FP_SHAPE::Rotate(), ZONE::Rotate(), S_POLYGON, ZONE::SetBorderDisplayStyle(), FP_SHAPE::SetEnd0(), setKeepoutSettingsToZone(), BOARD_ITEM::SetLayer(), PCB_SHAPE::SetPolyPoints(), FP_SHAPE::SetStart0(), PCB_SHAPE::SetWidth(), EAGLE_LAYER::TRESTRICT, UNDEFINED_LAYER, EAGLE_LAYER::VRESTRICT, ERECT::x1, ERECT::x2, ERECT::y1, and ERECT::y2.

Referenced by makeFootprint().

◆ packageSMD()

void EAGLE_PLUGIN::packageSMD ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Handles common pad properties.

Definition at line 2180 of file eagle_plugin.cpp.

2181 {
2182  ESMD e( aTree );
2183  PCB_LAYER_ID layer = kicad_layer( e.layer );
2184 
2185  if( !IsCopperLayer( layer ) )
2186  return;
2187 
2188  PAD* pad = new PAD( aFootprint );
2189  aFootprint->Add( pad );
2190  transferPad( e, pad );
2191 
2192  pad->SetShape( PAD_SHAPE_RECT );
2193  pad->SetAttribute( PAD_ATTRIB_SMD );
2194 
2195  wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
2196  pad->SetSize( padSize );
2197  pad->SetLayer( layer );
2198 
2199  const LSET front( 3, F_Cu, F_Paste, F_Mask );
2200  const LSET back( 3, B_Cu, B_Paste, B_Mask );
2201 
2202  if( layer == F_Cu )
2203  pad->SetLayerSet( front );
2204  else if( layer == B_Cu )
2205  pad->SetLayerSet( back );
2206 
2207  int minPadSize = std::min( padSize.x, padSize.y );
2208 
2209  // Rounded rectangle pads
2210  int roundRadius = eagleClamp( m_rules->srMinRoundness * 2,
2211  (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
2212 
2213  if( e.roundness || roundRadius > 0 )
2214  {
2215  double roundRatio = (double) roundRadius / minPadSize / 2.0;
2216 
2217  // Eagle uses a different definition of roundness, hence division by 200
2218  if( e.roundness )
2219  roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
2220 
2221  pad->SetShape( PAD_SHAPE_ROUNDRECT );
2222  pad->SetRoundRectRadiusRatio( roundRatio );
2223  }
2224 
2225  if( e.rot )
2226  pad->SetOrientation( e.rot->degrees * 10 );
2227 
2228  pad->SetLocalSolderPasteMargin( -eagleClamp( m_rules->mlMinCreamFrame,
2229  (int) ( m_rules->mvCreamFrame * minPadSize ),
2230  m_rules->mlMaxCreamFrame ) );
2231 
2232  // Solder mask
2233  if( e.stop && *e.stop == false ) // enabled by default
2234  {
2235  if( layer == F_Cu )
2236  pad->SetLayerSet( pad->GetLayerSet().set( F_Mask, false ) );
2237  else if( layer == B_Cu )
2238  pad->SetLayerSet( pad->GetLayerSet().set( B_Mask, false ) );
2239  }
2240 
2241  // Solder paste (only for SMD pads)
2242  if( e.cream && *e.cream == false ) // enabled by default
2243  {
2244  if( layer == F_Cu )
2245  pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
2246  else if( layer == B_Cu )
2247  pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
2248  }
2249 }
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.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:106
Eagle SMD pad.
Definition: eagle_parser.h:728
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:103
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:96
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
Definition: pad.h:60
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:97
int srMaxRoundness
Definition: eagle_plugin.h:109
double mvCreamFrame
Definition: eagle_plugin.h:93

References FOOTPRINT::Add(), B_Cu, B_Mask, B_Paste, ESMD::cream, EROT::degrees, ESMD::dx, ESMD::dy, eagleClamp(), F_Cu, F_Mask, F_Paste, IsCopperLayer(), kicad_layer(), ESMD::layer, m_rules, ERULES::mlMaxCreamFrame, ERULES::mlMinCreamFrame, ERULES::mvCreamFrame, PAD, pad, PAD_ATTRIB_SMD, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, EPAD_COMMON::rot, ESMD::roundness, ERULES::srMaxRoundness, ERULES::srMinRoundness, ERULES::srRoundness, EPAD_COMMON::stop, ECOORD::ToPcbUnits(), and transferPad().

Referenced by makeFootprint().

◆ packageText()

void EAGLE_PLUGIN::packageText ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Definition at line 1775 of file eagle_plugin.cpp.

1776 {
1777  ETEXT t( aTree );
1778  PCB_LAYER_ID layer = kicad_layer( t.layer );
1779 
1780  if( layer == UNDEFINED_LAYER )
1781  {
1782  wxLogMessage( wxString::Format( _( "Ignoring a text since Eagle layer '%s' (%d) "
1783  "was not mapped" ),
1784  eagle_layer_name( t.layer ),
1785  t.layer ) );
1786  return;
1787  }
1788 
1789  FP_TEXT* txt;
1790 
1791  if( t.text == ">NAME" || t.text == ">name" )
1792  txt = &aFootprint->Reference();
1793  else if( t.text == ">VALUE" || t.text == ">value" )
1794  txt = &aFootprint->Value();
1795  else
1796  {
1797  // FIXME: graphical text items are rotated for some reason.
1798  txt = new FP_TEXT( aFootprint );
1799  aFootprint->Add( txt );
1800  }
1801 
1802  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1803 
1804  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1805 
1806  txt->SetTextPos( pos );
1807  txt->SetPos0( pos - aFootprint->GetPosition() );
1808 
1809  txt->SetLayer( layer );
1810 
1811 
1812  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1813  int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
1814 
1815  txt->SetTextThickness( textThickness );
1816  txt->SetTextSize( kicad_fontz( t.size, textThickness ) );
1817 
1818  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1819 
1820  // An eagle package is never rotated, the DTD does not allow it.
1821  // angle -= aFootprint->GetOrienation();
1822 
1823  if( t.rot )
1824  {
1825  int sign = t.rot->mirror ? -1 : 1;
1826  txt->SetMirrored( t.rot->mirror );
1827 
1828  double degrees = t.rot->degrees;
1829 
1830  if( degrees == 90 || t.rot->spin )
1831  txt->SetTextAngle( sign * degrees * 10 );
1832  else if( degrees == 180 )
1833  align = ETEXT::TOP_RIGHT;
1834  else if( degrees == 270 )
1835  {
1836  align = ETEXT::TOP_RIGHT;
1837  txt->SetTextAngle( sign * 90 * 10 );
1838  }
1839  }
1840 
1841  switch( align )
1842  {
1843  case ETEXT::CENTER:
1844  // this was the default in pcbtxt's constructor
1845  break;
1846 
1847  case ETEXT::CENTER_LEFT:
1849  break;
1850 
1851  case ETEXT::CENTER_RIGHT:
1853  break;
1854 
1855  case ETEXT::TOP_CENTER:
1857  break;
1858 
1859  case ETEXT::TOP_LEFT:
1862  break;
1863 
1864  case ETEXT::TOP_RIGHT:
1867  break;
1868 
1869  case ETEXT::BOTTOM_CENTER:
1871  break;
1872 
1873  case ETEXT::BOTTOM_LEFT:
1876  break;
1877 
1878  case ETEXT::BOTTOM_RIGHT:
1881  break;
1882  }
1883 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
int sign(T val)
Definition: util.h:101
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetTextAngle(double aAngle) override
Definition: fp_text.cpp:70
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
Eagle text element.
Definition: eagle_parser.h:637
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:468
FP_TEXT & Reference()
Definition: footprint.h:469
PCB_LAYER_ID
A quick note on layer IDs:
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
void SetPos0(const wxPoint &aPos)
Definition: fp_text.h:165
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
#define _(s)
Definition: 3d_actions.cpp:33
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
wxPoint GetPosition() const override
Definition: footprint.h:182
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

References _, FOOTPRINT::Add(), ETEXT::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, EROT::degrees, eagle_layer_name(), Format(), FROM_UTF8(), FOOTPRINT::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(), KiROUND(), ETEXT::layer, EROT::mirror, ETEXT::ratio, FOOTPRINT::Reference(), ETEXT::rot, EDA_TEXT::SetHorizJustify(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), FP_TEXT::SetPos0(), EDA_TEXT::SetText(), FP_TEXT::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetVertJustify(), sign(), ETEXT::size, EROT::spin, ETEXT::text, ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, ECOORD::ToPcbUnits(), UNDEFINED_LAYER, FOOTPRINT::Value(), ETEXT::x, and ETEXT::y.

Referenced by makeFootprint().

◆ packageWire()

void EAGLE_PLUGIN::packageWire ( FOOTPRINT aFootprint,
wxXmlNode *  aTree 
) const
private

Definition at line 1599 of file eagle_plugin.cpp.

1600 {
1601  EWIRE w( aTree );
1602  PCB_LAYER_ID layer = kicad_layer( w.layer );
1603  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1604  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1605  int width = w.width.ToPcbUnits();
1606 
1607  if( layer == UNDEFINED_LAYER )
1608  {
1609  wxLogMessage( wxString::Format( _( "Ignoring a wire since Eagle layer '%s' (%d) "
1610  "was not mapped" ),
1611  eagle_layer_name( w.layer ),
1612  w.layer ) );
1613  return;
1614  }
1615 
1616  // KiCad cannot handle zero or negative line widths which apparently have meaning in Eagle.
1617  if( width <= 0 )
1618  {
1619  BOARD* board = aFootprint->GetBoard();
1620 
1621  if( board )
1622  {
1623  width = board->GetDesignSettings().GetLineThickness( layer );
1624  }
1625  else
1626  {
1627  // When loading footprint libraries, there is no board so use the default KiCad
1628  // line widths.
1629  switch( layer )
1630  {
1631  case Edge_Cuts: width = Millimeter2iu( DEFAULT_EDGE_WIDTH ); break;
1632 
1633  case F_SilkS:
1634  case B_SilkS: width = Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ); break;
1635 
1636  case F_CrtYd:
1637  case B_CrtYd: width = Millimeter2iu( DEFAULT_COURTYARD_WIDTH ); break;
1638 
1639  default: width = Millimeter2iu( DEFAULT_LINE_WIDTH ); break;
1640  }
1641  }
1642  }
1643 
1644  // FIXME: the cap attribute is ignored because KiCad can't create lines
1645  // with flat ends.
1646  FP_SHAPE* dwg;
1647 
1648  if( !w.curve )
1649  {
1650  dwg = new FP_SHAPE( aFootprint, S_SEGMENT );
1651 
1652  dwg->SetStart0( start );
1653  dwg->SetEnd0( end );
1654  }
1655  else
1656  {
1657  dwg = new FP_SHAPE( aFootprint, S_ARC );
1658  wxPoint center = ConvertArcCenter( start, end, *w.curve );
1659 
1660  dwg->SetStart0( center );
1661  dwg->SetEnd0( start );
1662  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1663  }
1664 
1665  dwg->SetLayer( layer );
1666  dwg->SetWidth( width );
1667  dwg->SetDrawCoord();
1668 
1669  aFootprint->Add( dwg );
1670 }
#define DEFAULT_EDGE_WIDTH
#define DEFAULT_COURTYARD_WIDTH
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
void SetEnd0(const wxPoint &aPoint)
Definition: fp_shape.h:114
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
#define DEFAULT_LINE_WIDTH
usual segment : line with rounded ends
Definition: board_item.h:50
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
Arcs (with rounded ends)
Definition: board_item.h:52
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
PCB_LAYER_ID
A quick note on layer IDs:
#define DEFAULT_SILK_LINE_WIDTH
void SetAngle(double aAngle, bool aUpdateEnd=true) override
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: fp_shape.cpp:142
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:82
void SetStart0(const wxPoint &aPoint)
Definition: fp_shape.h:111
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
Eagle wire.
Definition: eagle_parser.h:491
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:468
static constexpr int Millimeter2iu(double mm)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184

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

Referenced by makeFootprint().

◆ PluginName()

const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

Return a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 292 of file eagle_plugin.cpp.

293 {
294  return wxT( "Eagle" );
295 }

◆ PrefetchLib()

void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

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.

Definition at line 75 of file plugin.cpp.

76 {
77  (void) aLibraryPath;
78  (void) aProperties;
79 }

◆ RegisterLayerMappingCallback()

virtual void LAYER_REMAPPABLE_PLUGIN::RegisterLayerMappingCallback ( LAYER_MAPPING_HANDLER  aLayerMappingHandler)
inlinevirtualinherited

Register a different handler to be called when mapping of input layers to KiCad layers occurs.

The function is marked as virtual, so the plugins can implement extra logic (e.g., enable warnings or checks)

Parameters
aLayerMappingHandler

Reimplemented in CADSTAR_PCB_ARCHIVE_PLUGIN.

Definition at line 72 of file plugin_common_layer_mapping.h.

73  {
74  m_layer_mapping_handler = aLayerMappingHandler;
75  }
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.

References LAYER_REMAPPABLE_PLUGIN::m_layer_mapping_handler.

Referenced by CADSTAR_PCB_ARCHIVE_PLUGIN::CADSTAR_PCB_ARCHIVE_PLUGIN(), EAGLE_PLUGIN(), PCB_EDIT_FRAME::OpenProjectFiles(), and CADSTAR_PCB_ARCHIVE_PLUGIN::RegisterLayerMappingCallback().

◆ Save()

void PLUGIN::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

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

61 {
62  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
63  not_implemented( this, __FUNCTION__ );
64 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw 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,
PAD aPad 
) const
private

Deletes the footprint templates list.

Definition at line 2252 of file eagle_plugin.cpp.

2253 {
2254  aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) );
2255 
2256  // pad's "Position" is not relative to the footprint's,
2257  // whereas Pos0 is relative to the footprint's but is the unrotated coordinate.
2258  wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
2259  aPad->SetPos0( padPos );
2260 
2261  // Solder mask
2262  const wxSize& padSize( aPad->GetSize() );
2263 
2265  (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
2266  m_rules->mlMaxStopFrame ) );
2267 
2268  // Solid connection to copper zones
2269  if( aEaglePad.thermals && !*aEaglePad.thermals )
2271 
2272  FOOTPRINT* footprint = aPad->GetParent();
2273  wxCHECK( footprint, /* void */ );
2274  RotatePoint( &padPos, footprint->GetOrientation() );
2275  aPad->SetPosition( padPos + footprint->GetPosition() );
2276 }
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:185
static T eagleClamp(T aMin, T aValue, T aMax)
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:286
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12).
Definition: pad.h:132
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:94
double GetOrientation() const
Definition: footprint.h:186
wxString name
Definition: eagle_parser.h:695
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
opt_bool thermals
Definition: eagle_parser.h:699
void SetLocalSolderMaskMargin(int aMargin)
Definition: pad.h:379
pads are covered by copper
void SetPos0(const wxPoint &aPos)
Definition: pad.h:225
const wxSize & GetSize() const
Definition: pad.h:232
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: pad.h:467
FOOTPRINT * GetParent() const
Definition: pad.cpp:1332
void SetPosition(const wxPoint &aPos) override
Definition: pad.h:171
double mvStopFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:90
wxPoint GetPosition() const override
Definition: footprint.h:182
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:184
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:95

References eagleClamp(), FROM_UTF8(), FULL, FOOTPRINT::GetOrientation(), PAD::GetParent(), FOOTPRINT::GetPosition(), PAD::GetSize(), kicad_x(), kicad_y(), m_rules, ERULES::mlMaxStopFrame, ERULES::mlMinStopFrame, ERULES::mvStopFrame, EPAD_COMMON::name, RotatePoint(), PAD::SetLocalSolderMaskMargin(), PAD::SetName(), PAD::SetPos0(), PAD::SetPosition(), 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 300 of file eagle_plugin.h.

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

◆ m_cu_map

int EAGLE_PLUGIN::m_cu_map[17]
private

map eagle to KiCad, cu layers only.

Definition at line 281 of file eagle_plugin.h.

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

◆ m_eagleLayers

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

Eagle layer data stored by layer number.

Definition at line 282 of file eagle_plugin.h.

Referenced by eagle_layer_name(), loadLayerDefs(), and mapEagleLayersToKicad().

◆ m_eagleLayersIds

std::map<wxString, int> EAGLE_PLUGIN::m_eagleLayersIds
private

Eagle layer ids stored by layer name.

Definition at line 283 of file eagle_plugin.h.

Referenced by eagle_layer_id(), and loadLayerDefs().

◆ m_hole_count

int EAGLE_PLUGIN::m_hole_count
private

generates unique footprint names from eagle "hole"s.

Definition at line 290 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

◆ m_layer_map

std::map<wxString, PCB_LAYER_ID> EAGLE_PLUGIN::m_layer_map
private

Map of Eagle layers to KiCad layers.

Definition at line 284 of file eagle_plugin.h.

Referenced by kicad_layer(), and mapEagleLayersToKicad().

◆ m_layer_mapping_handler

LAYER_MAPPING_HANDLER LAYER_REMAPPABLE_PLUGIN::m_layer_mapping_handler
protectedinherited

◆ m_lib_path

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 307 of file eagle_plugin.h.

Referenced by cacheLib(), and loadLibrary().

◆ m_min_annulus