KiCad PCB EDA Suite
EAGLE_PLUGIN Class Reference

Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API, or a portion of it. More...

#include <eagle_plugin.h>

Inheritance diagram for EAGLE_PLUGIN:
PLUGIN

Public Types

typedef int BIU
 

Public Member Functions

const wxString PluginName () const override
 Function PluginName returns a brief hard coded name for this PLUGIN. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
 Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one. More...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
wxArrayString FootprintEnumerate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function FootprintEnumerate returns a list of footprint names contained within the library at aLibraryPath. More...
 
MODULEFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
void FootprintLibOptions (PROPERTIES *aProperties) const override
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
 EAGLE_PLUGIN ()
 
 ~EAGLE_PLUGIN ()
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
 Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual void FootprintSave (const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
 Function FootprintSave will write aModule to an existing library located at aLibraryPath. More...
 
virtual void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. More...
 
virtual void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
virtual bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 

Private Member Functions

void init (const PROPERTIES *aProperties)
 initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. More...
 
void clear_cu_map ()
 
int kicad (double d) const
 Convert an Eagle distance to a KiCad distance. More...
 
int kicad_y (double y) const
 
int kicad_x (double x) const
 
wxSize kicad_fontz (double d) const
 create a font size (fontz) from an eagle font size scalar More...
 
PCB_LAYER_ID kicad_layer (int aLayer) const
 Convert an Eagle layer to a KiCad layer. More...
 
double eagle (BIU d) const
 Convert a KiCad distance to an Eagle distance. More...
 
double eagle_x (BIU x) const
 
double eagle_y (BIU y) const
 
void cacheLib (const wxString &aLibraryPath)
 This PLUGIN only caches one footprint library, this determines which one. More...
 
void loadAllSections (CPTREE &aDocument)
 
void loadDesignRules (CPTREE &aDesignRules)
 
void loadLayerDefs (CPTREE &aLayers)
 
void loadPlain (CPTREE &aPlain)
 
void loadSignals (CPTREE &aSignals)
 
void loadLibrary (CPTREE &aLib, const std::string *aLibName)
 Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries" element (if a *.brd file) or under a "drawing" element if a *.lbr file. More...
 
void loadLibraries (CPTREE &aLibs)
 
void loadElements (CPTREE &aElements)
 
void orientModuleAndText (MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
 
void orientModuleText (MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
 
void centerBoard ()
 move the BOARD into the center of the page More...
 
std::string fmtDEG (double aAngle) const
 Function fmtDEG formats an angle in a way particular to a board file format. More...
 
MODULEmakeModule (CPTREE &aPackage, const std::string &aPkgName) const
 Function makeModule creates a MODULE from an Eagle package. More...
 
void packageWire (MODULE *aModule, CPTREE &aTree) const
 
void packagePad (MODULE *aModule, CPTREE &aTree) const
 
void packageText (MODULE *aModule, CPTREE &aTree) const
 
void packageRectangle (MODULE *aModule, CPTREE &aTree) const
 
void packagePolygon (MODULE *aModule, CPTREE &aTree) const
 
void packageCircle (MODULE *aModule, CPTREE &aTree) const
 
void packageHole (MODULE *aModule, CPTREE &aTree) const
 
void packageSMD (MODULE *aModule, CPTREE &aTree) const
 

Static Private Member Functions

static wxDateTime getModificationTime (const wxString &aPath)
 get a file's or dir's modification time. More...
 

Private Attributes

int m_cu_map [17]
 map eagle to kicad, cu layers only. More...
 
ERULESm_rules
 Eagle design rules. More...
 
XPATHm_xpath
 keeps track of what we are working on within XML document during a Load(). More...
 
int m_hole_count
 generates unique module names from eagle "hole"s. More...
 
NET_MAP m_pads_to_nets
 net list More...
 
MODULE_MAP m_templates
 is part of a MODULE factory that operates using copy construction. More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
BOARDm_board
 which BOARD is being worked on, no ownership here More...
 
int m_min_trace
 smallest trace we find on Load(), in BIU. More...
 
int m_min_via
 smallest via we find on Load(), in BIU. More...
 
int m_min_via_hole
 smallest via diameter hole we find on Load(), in BIU. More...
 
double mm_per_biu
 how many mm in each BIU More...
 
double biu_per_mm
 how many bius in a mm More...
 
wxString m_lib_path
 
wxDateTime m_mod_time
 

Detailed Description

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

Definition at line 77 of file eagle_plugin.h.

Member Typedef Documentation

typedef int EAGLE_PLUGIN::BIU

Definition at line 114 of file eagle_plugin.h.

Constructor & Destructor Documentation

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 1139 of file eagle_plugin.cpp.

References clear_cu_map(), and init().

1139  :
1140  m_rules( new ERULES() ),
1141  m_xpath( new XPATH() ),
1142  m_mod_time( wxDateTime::Now() )
1143 {
1144  init( NULL );
1145 
1146  clear_cu_map();
1147 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
Class XPATH keeps track of what we are working on within a PTREE.
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:124
subset of eagle.drawing.board.designrules in the XML document
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 1150 of file eagle_plugin.cpp.

References m_rules, and m_xpath.

1151 {
1152  delete m_rules;
1153  delete m_xpath;
1154 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124

Member Function Documentation

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

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

Definition at line 3020 of file eagle_plugin.cpp.

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

Referenced by FootprintEnumerate(), and FootprintLoad().

3021 {
3022  try
3023  {
3024  wxDateTime modtime = getModificationTime( aLibPath );
3025 
3026  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
3027  // cache if either of the wxDateTime objects are invalid or the last file modification
3028  // time differs from the current file modification time.
3029  bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
3030  m_mod_time != modtime;
3031 
3032  if( aLibPath != m_lib_path || load )
3033  {
3034  PTREE doc;
3035  LOCALE_IO toggle; // toggles on, then off, the C locale.
3036 
3037  m_templates.clear();
3038 
3039  // Set this before completion of loading, since we rely on it for
3040  // text of an exception. Delay setting m_mod_time until after successful load
3041  // however.
3042  m_lib_path = aLibPath;
3043 
3044  // 8 bit "filename" should be encoded according to disk filename encoding,
3045  // (maybe this is current locale, maybe not, its a filesystem issue),
3046  // and is not necessarily utf8.
3047  string filename = (const char*) aLibPath.char_str( wxConvFile );
3048 
3049  read_xml( filename, doc, xml_parser::no_comments );
3050 
3051  // clear the cu map and then rebuild it.
3052  clear_cu_map();
3053 
3054  m_xpath->push( "eagle.drawing.layers" );
3055  CPTREE& layers = doc.get_child( "eagle.drawing.layers" );
3056  loadLayerDefs( layers );
3057  m_xpath->pop();
3058 
3059  m_xpath->push( "eagle.drawing.library" );
3060  CPTREE& library = doc.get_child( "eagle.drawing.library" );
3061  loadLibrary( library, NULL );
3062  m_xpath->pop();
3063 
3064  m_mod_time = modtime;
3065  }
3066  }
3067  catch( file_parser_error fpe )
3068  {
3069  // for xml_parser_error, what() has the line number in it,
3070  // but no byte offset. That should be an adequate error message.
3071  THROW_IO_ERROR( fpe.what() );
3072  }
3073 
3074  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
3075  // so one catch should be OK for all errors.
3076  catch( ptree_error pte )
3077  {
3078  string errmsg = pte.what();
3079 
3080  errmsg += " @\n";
3081  errmsg += m_xpath->Contents();
3082 
3083  THROW_IO_ERROR( errmsg );
3084  }
3085 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
wxString m_lib_path
Definition: eagle_plugin.h:146
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
string Contents()
return the contents of the XPATH as a single string
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
void pop()
void loadLayerDefs(CPTREE &aLayers)
void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

Definition at line 2962 of file eagle_plugin.cpp.

References DBG, BOARD::GetBoardEdgesBoundingBox(), EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), m_board, m_props, BOARD::Move(), and PROPERTIES::Value().

Referenced by Load().

2963 {
2964  if( m_props )
2965  {
2966  UTF8 page_width;
2967  UTF8 page_height;
2968 
2969  if( m_props->Value( "page_width", &page_width ) &&
2970  m_props->Value( "page_height", &page_height ) )
2971  {
2973 
2974  int w = atoi( page_width.c_str() );
2975  int h = atoi( page_height.c_str() );
2976 
2977  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2978  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2979 
2980  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2981  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2982 
2983  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2984  }
2985  }
2986 }
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
int GetHeight() const
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:839
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:136
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Class EDA_RECT handles the component boundary box.
int GetX() const
int GetWidth() const
int GetY() const
#define DBG(x)
Definition: fctsys.h:33
void EAGLE_PLUGIN::clear_cu_map ( )
private

Definition at line 1299 of file eagle_plugin.cpp.

References DIM, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

1300 {
1301  // All cu layers are invalid until we see them in the <layers> section while
1302  // loading either a board or library. See loadLayerDefs().
1303  for( unsigned i = 0; i < DIM(m_cu_map); ++i )
1304  m_cu_map[i] = -1;
1305 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
double EAGLE_PLUGIN::eagle ( BIU  d) const
inlineprivate

Convert a KiCad distance to an Eagle distance.

Definition at line 166 of file eagle_plugin.h.

Referenced by eagle_x(), and eagle_y().

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

Definition at line 167 of file eagle_plugin.h.

References eagle().

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

Definition at line 168 of file eagle_plugin.h.

References eagle().

168 { return eagle( y ); }
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:166
std::string EAGLE_PLUGIN::fmtDEG ( double  aAngle) const
private

Function fmtDEG formats an angle in a way particular to a board file format.

This function is the opposite or complement of degParse(). One has to know what the other is doing.

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

Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of a footprint to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the footprint or the library, or deleting it.

Reimplemented in GITHUB_PLUGIN, PCB_IO, and GPCB_PLUGIN.

Definition at line 92 of file plugin.cpp.

References not_implemented().

Referenced by FP_LIB_TABLE::FootprintDelete().

93 {
94  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
95  not_implemented( this, __FUNCTION__ );
96 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: plugin.cpp:38
wxArrayString EAGLE_PLUGIN::FootprintEnumerate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintEnumerate returns 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.
Returns
wxArrayString - is the array of available footprint names inside a library
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 3088 of file eagle_plugin.cpp.

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

3089 {
3090  init( aProperties );
3091 
3092  cacheLib( aLibraryPath );
3093 
3094  wxArrayString ret;
3095 
3096  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
3097  ret.Add( FROM_UTF8( it->first.c_str() ) );
3098 
3099  return ret;
3100 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
MODULE_MAP::const_iterator MODULE_CITER
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented in GITHUB_PLUGIN, and PCB_IO.

Definition at line 99 of file plugin.cpp.

References not_implemented().

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

100 {
101  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
102  not_implemented( this, __FUNCTION__ );
103 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: plugin.cpp:38
bool PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain footprints.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
bool - true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented in GITHUB_PLUGIN, PCB_IO, LEGACY_PLUGIN, and GPCB_PLUGIN.

Definition at line 106 of file plugin.cpp.

References not_implemented().

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

107 {
108  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
109  not_implemented( this, __FUNCTION__ );
110  return false;
111 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: plugin.cpp:38
void EAGLE_PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
overridevirtual

Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Footprint*() functions in all derived PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to PLUGIN, which has been avoided to date.

Reimplemented from PLUGIN.

Definition at line 3124 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

3125 {
3126  PLUGIN::FootprintLibOptions( aListToAppendTo );
3127 
3128  /*
3129  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
3130  "Ignore duplicately named footprints within the same Eagle library. "
3131  "Only the first similarly named footprint will be loaded."
3132  ));
3133  */
3134 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:122
MODULE * EAGLE_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of the footprint to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Reimplemented from PLUGIN.

Definition at line 3103 of file eagle_plugin.cpp.

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

3105 {
3106  init( aProperties );
3107 
3108  cacheLib( aLibraryPath );
3109 
3110  string key = TO_UTF8( aFootprintName );
3111 
3112  MODULE_CITER mi = m_templates.find( key );
3113 
3114  if( mi == m_templates.end() )
3115  return NULL;
3116 
3117  // copy constructor to clone the template
3118  MODULE* ret = new MODULE( *mi->second );
3119 
3120  return ret;
3121 }
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
MODULE_MAP::const_iterator MODULE_CITER
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintSave will write aModule to an existing library located at aLibraryPath.

If a footprint by the same name already exists, it is replaced.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aPropertiesis an associative array that can be used to tell the saver how to save the footprint, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented in GITHUB_PLUGIN, and PCB_IO.

Definition at line 85 of file plugin.cpp.

References not_implemented().

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

86 {
87  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
88  not_implemented( this, __FUNCTION__ );
89 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: plugin.cpp:38
const wxString EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 1163 of file eagle_plugin.cpp.

1164 {
1165  return wxT( "brd" );
1166 }
wxDateTime EAGLE_PLUGIN::getModificationTime ( const wxString &  aPath)
staticprivate

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

Definition at line 2989 of file eagle_plugin.cpp.

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

Referenced by cacheLib().

2990 {
2991  wxFileName fn( aPath );
2992 
2993  // Do not call wxFileName::GetModificationTime() on a non-existent file, because
2994  // if it fails, wx's implementation calls the crap wxLogSysError() which
2995  // eventually infects our UI with an unwanted popup window, so don't let it fail.
2996  if( !fn.IsFileReadable() )
2997  {
2998  wxString msg = wxString::Format(
2999  _( "File '%s' is not readable." ),
3000  GetChars( aPath ) );
3001 
3002  THROW_IO_ERROR( msg );
3003  }
3004 
3005  /*
3006  // update the writable flag while we have a wxFileName, in a network this
3007  // is possibly quite dynamic anyway.
3008  m_writable = fn.IsFileWritable();
3009  */
3010 
3011  wxDateTime modTime = fn.GetModificationTime();
3012 
3013  if( !modTime.IsValid() )
3014  modTime.Now();
3015 
3016  return modTime;
3017 }
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 1277 of file eagle_plugin.cpp.

References biu_per_mm, XPATH::clear(), m_board, m_hole_count, m_min_trace, m_min_via, m_min_via_hole, m_pads_to_nets, m_props, m_rules, m_xpath, and mm_per_biu.

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

1278 {
1279  m_hole_count = 0;
1280  m_min_trace = 0;
1281  m_min_via = 0;
1282  m_min_via_hole = 0;
1283  m_xpath->clear();
1284  m_pads_to_nets.clear();
1285 
1286  // m_templates.clear(); this is the FOOTPRINT cache too
1287 
1288  m_board = NULL;
1289  m_props = aProperties;
1290 
1291  mm_per_biu = 1/IU_PER_MM;
1292  biu_per_mm = IU_PER_MM;
1293 
1294  delete m_rules;
1295  m_rules = new ERULES();
1296 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void clear()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:136
subset of eagle.drawing.board.designrules in the XML document
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:143
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
bool EAGLE_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
inlineoverridevirtual

Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from PLUGIN.

Definition at line 93 of file eagle_plugin.h.

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

Convert an Eagle distance to a KiCad distance.

Definition at line 1169 of file eagle_plugin.cpp.

References biu_per_mm, and KiROUND().

Referenced by kicad_fontz(), kicad_x(), kicad_y(), loadPlain(), loadSignals(), packageCircle(), packageHole(), packagePad(), packageSMD(), packageText(), and packageWire().

1170 {
1171  return KiROUND( biu_per_mm * d );
1172 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
wxSize EAGLE_PLUGIN::kicad_fontz ( double  d) const
inlineprivate

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

Definition at line 1175 of file eagle_plugin.cpp.

References kicad().

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

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

Convert an Eagle layer to a KiCad layer.

Definition at line 2830 of file eagle_plugin.cpp.

References B_Adhes, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, DIM, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Fab, F_Mask, F_Paste, F_SilkS, m_cu_map, and UNDEFINED_LAYER.

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

2831 {
2832  /* will assume this is a valid mapping for all eagle boards until I get paid more:
2833 
2834  <layers>
2835  <layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
2836  <layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
2837  <layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
2838  <layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
2839  <layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
2840  <layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
2841  <layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
2842  <layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
2843  <layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
2844  <layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
2845  <layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
2846  <layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
2847  <layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
2848  <layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
2849  <layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
2850  <layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
2851  <layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
2852  <layer number="18" name="Vias" color="14" fill="1" visible="yes" active="yes"/>
2853  <layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
2854  <layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
2855  <layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
2856  <layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
2857  <layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
2858  <layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
2859  <layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
2860  <layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
2861  <layer number="27" name="tValues" color="7" fill="1" visible="no" active="yes"/>
2862  <layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
2863  <layer number="29" name="tStop" color="2" fill="3" visible="no" active="yes"/>
2864  <layer number="30" name="bStop" color="5" fill="6" visible="no" active="yes"/>
2865  <layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
2866  <layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
2867  <layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
2868  <layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
2869  <layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
2870  <layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
2871  <layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
2872  <layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
2873  <layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
2874  <layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
2875  <layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
2876  <layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
2877  <layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
2878  <layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
2879  <layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
2880  <layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
2881  <layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
2882  <layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
2883  <layer number="49" name="ReferenceLC" color="13" fill="1" visible="yes" active="yes"/>
2884  <layer number="50" name="ReferenceLS" color="12" fill="1" visible="yes" active="yes"/>
2885  <layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
2886  <layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
2887 
2888  * These layers are used only in eagle schematic.
2889  * They should not be found in board files.
2890  * They are listed for info only.
2891  <layer number="91" name="Nets" color="2" fill="1" visible="no" active="no"/>
2892  <layer number="92" name="Busses" color="1" fill="1" visible="no" active="no"/>
2893  <layer number="93" name="Pins" color="2" fill="1" visible="no" active="no"/>
2894  <layer number="94" name="Symbols" color="4" fill="1" visible="no" active="no"/>
2895  <layer number="95" name="Names" color="7" fill="1" visible="no" active="no"/>
2896  <layer number="96" name="Values" color="7" fill="1" visible="no" active="no"/>
2897  <layer number="97" name="Info" color="7" fill="1" visible="no" active="no"/>
2898  <layer number="98" name="Guide" color="6" fill="1" visible="no" active="no"/>
2899 
2900  * These layers are user layers
2901  <layer number="160" name="???" color="7" fill="1" visible="yes" active="yes"/>
2902  <layer number="161" name="???" color="7" fill="1" visible="yes" active="yes"/>
2903 
2904  </layers>
2905 
2906  */
2907 
2908  int kiLayer;
2909 
2910  // eagle copper layer:
2911  if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
2912  {
2913  kiLayer = m_cu_map[aEagleLayer];
2914  }
2915 
2916  else
2917  {
2918  // translate non-copper eagle layer to pcbnew layer
2919  switch( aEagleLayer )
2920  {
2921  case 20: kiLayer = Edge_Cuts; break; // eagle says "Dimension" layer, but it's for board perimeter
2922  case 21: kiLayer = F_SilkS; break;
2923  case 22: kiLayer = B_SilkS; break;
2924  case 25: kiLayer = F_SilkS; break;
2925  case 26: kiLayer = B_SilkS; break;
2926  case 27: kiLayer = F_SilkS; break;
2927  case 28: kiLayer = B_SilkS; break;
2928  case 29: kiLayer = F_Mask; break;
2929  case 30: kiLayer = B_Mask; break;
2930  case 31: kiLayer = F_Paste; break;
2931  case 32: kiLayer = B_Paste; break;
2932  case 33: kiLayer = F_Mask; break;
2933  case 34: kiLayer = B_Mask; break;
2934  case 35: kiLayer = F_Adhes; break;
2935  case 36: kiLayer = B_Adhes; break;
2936  case 48: kiLayer = Cmts_User; break;
2937  case 49: kiLayer = Cmts_User; break;
2938  case 50: kiLayer = Cmts_User; break;
2939 
2940  // Packages show the future chip pins on SMD parts using layer 51.
2941  // This is an area slightly smaller than the PAD/SMD copper area.
2942  // Carry those visual aids into the MODULE on the fabrication layer,
2943  // not silkscreen. This is perhaps not perfect, but there is not a lot
2944  // of other suitable paired layers
2945  case 51: kiLayer = F_Fab; break;
2946  case 52: kiLayer = B_Fab; break;
2947 
2948  // thes layers are defined as user layers. put them on ECO layers
2949  case 160: kiLayer = Eco1_User; break;
2950  case 161: kiLayer = Eco2_User; break;
2951  default:
2952  // some layers do not map to KiCad
2953  // DBG( printf( "unsupported eagle layer: %d\n", aEagleLayer );)
2954  kiLayer = UNDEFINED_LAYER; break;
2955  }
2956  }
2957 
2958  return PCB_LAYER_ID( kiLayer );
2959 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
PCB_LAYER_ID
A quick note on layer IDs:
int EAGLE_PLUGIN::kicad_x ( double  x) const
inlineprivate

Definition at line 157 of file eagle_plugin.h.

References kicad().

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

157 { return kicad( x ); }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
int EAGLE_PLUGIN::kicad_y ( double  y) const
inlineprivate

Definition at line 156 of file eagle_plugin.h.

References kicad().

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

156 { return -kicad( y ); }
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
BOARD * EAGLE_PLUGIN::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one.

This may be used to load an entire new BOARD, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aAppendToMeis an existing BOARD to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
BOARD* - the successfully loaded board, or the same one as aAppendToMe if aAppendToMe was not NULL, and caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.

Reimplemented from PLUGIN.

Definition at line 1183 of file eagle_plugin.cpp.

References centerBoard(), XPATH::Contents(), BOARD_DESIGN_SETTINGS::GetDefault(), init(), KiROUND(), loadAllSections(), m_board, m_min_trace, m_min_via, m_min_via_hole, m_rules, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, m_xpath, ERULES::mdWireWire, BOARD::SetFileName(), and THROW_IO_ERROR.

1184 {
1185  LOCALE_IO toggle; // toggles on, then off, the C locale.
1186  PTREE doc;
1187 
1188  init( aProperties );
1189 
1190  m_board = aAppendToMe ? aAppendToMe : new BOARD();
1191 
1192  // Give the filename to the board if it's new
1193  if( !aAppendToMe )
1194  m_board->SetFileName( aFileName );
1195 
1196  // delete on exception, if I own m_board, according to aAppendToMe
1197  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
1198 
1199  try
1200  {
1201  // 8 bit "filename" should be encoded according to disk filename encoding,
1202  // (maybe this is current locale, maybe not, its a filesystem issue),
1203  // and is not necessarily utf8.
1204  string filename = (const char*) aFileName.char_str( wxConvFile );
1205 
1206  read_xml( filename, doc, xml_parser::no_comments );
1207 
1208  m_min_trace = INT_MAX;
1209  m_min_via = INT_MAX;
1210  m_min_via_hole = INT_MAX;
1211 
1212  loadAllSections( doc );
1213 
1214  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
1215 
1216  if( m_min_trace < designSettings.m_TrackMinWidth )
1217  designSettings.m_TrackMinWidth = m_min_trace;
1218 
1219  if( m_min_via < designSettings.m_ViasMinSize )
1220  designSettings.m_ViasMinSize = m_min_via;
1221 
1222  if( m_min_via_hole < designSettings.m_ViasMinDrill )
1223  designSettings.m_ViasMinDrill = m_min_via_hole;
1224 
1225  if( m_rules->mdWireWire )
1226  {
1227  NETCLASSPTR defaultNetclass = designSettings.GetDefault();
1228  int clearance = KiROUND( m_rules->mdWireWire );
1229 
1230  if( clearance < defaultNetclass->GetClearance() )
1231  defaultNetclass->SetClearance( clearance );
1232  }
1233 
1234  // should be empty, else missing m_xpath->pop()
1235  wxASSERT( m_xpath->Contents().size() == 0 );
1236  }
1237 
1238  catch( file_parser_error fpe )
1239  {
1240  // for xml_parser_error, what() has the line number in it,
1241  // but no byte offset. That should be an adequate error message.
1242  THROW_IO_ERROR( fpe.what() );
1243  }
1244 
1245  // Class ptree_error is a base class for xml_parser_error & file_parser_error,
1246  // so one catch should be OK for all errors.
1247  catch( ptree_error pte )
1248  {
1249  string errmsg = pte.what();
1250 
1251  errmsg += " @\n";
1252  errmsg += m_xpath->Contents();
1253 
1254  THROW_IO_ERROR( errmsg );
1255  }
1256 
1257  // IO_ERROR exceptions are left uncaught, they pass upwards from here.
1258 
1259  // Ensure the copper layers count is a multiple of 2
1260  // Pcbnew does not like boards with odd layers count
1261  // (these boards cannot exist. they actually have a even layers count)
1262  int lyrcnt = m_board->GetCopperLayerCount();
1263 
1264  if( (lyrcnt % 2) != 0 )
1265  {
1266  lyrcnt++;
1267  m_board->SetCopperLayerCount( lyrcnt );
1268  }
1269 
1270  centerBoard();
1271 
1272  deleter.release();
1273  return m_board;
1274 }
NETCLASSPTR GetDefault() const
Function GetDefault.
void centerBoard()
move the BOARD into the center of the page
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void loadAllSections(CPTREE &aDocument)
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetCopperLayerCount(int aCount)
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_ViasMinDrill
vias (not micro vias) min drill diameter
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetFileName(const wxString &aFileName)
Definition: class_board.h:235
double mdWireWire
wire to wire spacing I presume.
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
string Contents()
return the contents of the XPATH as a single string
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void EAGLE_PLUGIN::loadAllSections ( CPTREE aDocument)
private

Definition at line 1308 of file eagle_plugin.cpp.

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

Referenced by Load().

1309 {
1310  CPTREE& drawing = aDoc.get_child( "eagle.drawing" );
1311  CPTREE& board = drawing.get_child( "board" );
1312 
1313  m_xpath->push( "eagle.drawing" );
1314 
1315  {
1316  m_xpath->push( "board" );
1317 
1318  CPTREE& designrules = board.get_child( "designrules" );
1319  loadDesignRules( designrules );
1320 
1321  m_xpath->pop();
1322  }
1323 
1324  {
1325  m_xpath->push( "layers" );
1326 
1327  CPTREE& layers = drawing.get_child( "layers" );
1328  loadLayerDefs( layers );
1329 
1330  m_xpath->pop();
1331  }
1332 
1333  {
1334  m_xpath->push( "board" );
1335 
1336  CPTREE& plain = board.get_child( "plain" );
1337  loadPlain( plain );
1338 
1339  CPTREE& signals = board.get_child( "signals" );
1340  loadSignals( signals );
1341 
1342  CPTREE& libs = board.get_child( "libraries" );
1343  loadLibraries( libs );
1344 
1345  CPTREE& elems = board.get_child( "elements" );
1346  loadElements( elems );
1347 
1348  m_xpath->pop(); // "board"
1349  }
1350 
1351  m_xpath->pop(); // "eagle.drawing"
1352 }
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void loadDesignRules(CPTREE &aDesignRules)
void loadSignals(CPTREE &aSignals)
void loadLibraries(CPTREE &aLibs)
void loadPlain(CPTREE &aPlain)
void pop()
void loadElements(CPTREE &aElements)
void loadLayerDefs(CPTREE &aLayers)
void EAGLE_PLUGIN::loadDesignRules ( CPTREE aDesignRules)
private

Definition at line 1355 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

1356 {
1357  m_xpath->push( "designrules" );
1358  m_rules->parse( aDesignRules );
1359  m_xpath->pop(); // "designrules"
1360 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
void push(const char *aPathSegment, const char *aAttribute="")
void parse(CPTREE &aRules)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void pop()
void EAGLE_PLUGIN::loadElements ( CPTREE aElements)
private

Definition at line 1791 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, EATTR::BOTH, EATTR::display, Format(), FROM_UTF8(), GetChars(), MODULE::GetReference(), MODULE::GetValue(), kicad_x(), kicad_y(), EELEMENT::library, m_board, m_pads_to_nets, m_templates, m_xpath, makeKey(), name, EATTR::name, EATTR::NAME, EELEMENT::name, ENET::netcode, D_PAD::Next(), EATTR::Off, orientModuleAndText(), EELEMENT::package, MODULE::Pads(), XPATH::pop(), XPATH::push(), MODULE::Reference(), MODULE::SetPosition(), MODULE::SetReference(), MODULE::SetValue(), EDA_TEXT::SetVisible(), EELEMENT::smashed, THROW_IO_ERROR, TO_UTF8, XPATH::Value(), MODULE::Value(), EATTR::value, EATTR::VALUE, EELEMENT::value, EELEMENT::x, and EELEMENT::y.

Referenced by loadAllSections().

1792 {
1793  m_xpath->push( "elements.element", "name" );
1794 
1795  EATTR name;
1796  EATTR value;
1797  bool refanceNamePresetInPackageLayout;
1798  bool valueNamePresetInPackageLayout;
1799 
1800 
1801 
1802  for( CITER it = aElements.begin(); it != aElements.end(); ++it )
1803  {
1804  if( it->first != "element" )
1805  continue;
1806 
1807  EELEMENT e( it->second );
1808 
1809  // use "NULL-ness" as an indication of presence of the attribute:
1810  EATTR* nameAttr = 0;
1811  EATTR* valueAttr = 0;
1812 
1813  m_xpath->Value( e.name.c_str() );
1814 
1815  string pkg_key = makeKey( e.library, e.package );
1816 
1817  MODULE_CITER mi = m_templates.find( pkg_key );
1818 
1819  if( mi == m_templates.end() )
1820  {
1821  wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
1822  GetChars( FROM_UTF8( e.package.c_str() ) ),
1823  GetChars( FROM_UTF8( e.library.c_str() ) ) );
1824  THROW_IO_ERROR( emsg );
1825  }
1826 
1827  // copy constructor to clone the template
1828  MODULE* m = new MODULE( *mi->second );
1829  m_board->Add( m, ADD_APPEND );
1830 
1831  // update the nets within the pads of the clone
1832  for( D_PAD* pad = m->Pads(); pad; pad = pad->Next() )
1833  {
1834  string pn_key = makeKey( e.name, TO_UTF8( pad->GetPadName() ) );
1835 
1836  NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
1837  if( ni != m_pads_to_nets.end() )
1838  {
1839  const ENET* enet = &ni->second;
1840  pad->SetNetCode( enet->netcode );
1841  }
1842  }
1843 
1844  refanceNamePresetInPackageLayout = true;
1845  valueNamePresetInPackageLayout = true;
1846  m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1847  // Is >NAME field set in package layout ?
1848  if( m->GetReference().size() == 0 )
1849  {
1850  m->Reference().SetVisible( false ); // No so no show
1851  refanceNamePresetInPackageLayout = false;
1852  }
1853  // Is >VALUE field set in package layout
1854  if( m->GetValue().size() == 0 )
1855  {
1856  m->Value().SetVisible( false ); // No so no show
1857  valueNamePresetInPackageLayout = false;
1858  }
1859  m->SetReference( FROM_UTF8( e.name.c_str() ) );
1860  m->SetValue( FROM_UTF8( e.value.c_str() ) );
1861 
1862  if( !e.smashed )
1863  { // Not smashed so show NAME & VALUE
1864  if( valueNamePresetInPackageLayout )
1865  m->Value().SetVisible( true ); // Only if place holder in package layout
1866  if( refanceNamePresetInPackageLayout )
1867  m->Reference().SetVisible( true ); // Only if place holder in package layout
1868  }
1869  else if( *e.smashed == true )
1870  { // Smasted so set default to no show for NAME and VALUE
1871  m->Value().SetVisible( false );
1872  m->Reference().SetVisible( false );
1873 
1874  // initalize these to default values incase the <attribute> elements are not present.
1875  m_xpath->push( "attribute", "name" );
1876 
1877  // VALUE and NAME can have something like our text "effects" overrides
1878  // in SWEET and new schematic. Eagle calls these XML elements "attribute".
1879  // There can be one for NAME and/or VALUE both. Features present in the
1880  // EATTR override the ones established in the package only if they are
1881  // present here (except for rot, which if not present means angle zero).
1882  // So the logic is a bit different than in packageText() and in plain text.
1883  for( CITER ait = it->second.begin(); ait != it->second.end(); ++ait )
1884  {
1885 
1886  if( ait->first != "attribute" )
1887  continue;
1888 
1889  EATTR a( ait->second );
1890 
1891  if( a.name == "NAME" )
1892  {
1893  name = a;
1894  nameAttr = &name;
1895 
1896  // do we have a display attribute ?
1897  if( a.display )
1898  {
1899  // Yes!
1900  switch( *a.display )
1901  {
1902  case EATTR::VALUE :
1903  nameAttr->name = e.name;
1904  m->SetReference( e.name );
1905  if( refanceNamePresetInPackageLayout )
1906  m->Reference().SetVisible( true );
1907  break;
1908 
1909  case EATTR::NAME :
1910  if( refanceNamePresetInPackageLayout )
1911  {
1912  m->SetReference( "NAME" );
1913  m->Reference().SetVisible( true );
1914  }
1915  break;
1916 
1917  case EATTR::BOTH :
1918  if( refanceNamePresetInPackageLayout )
1919  m->Reference().SetVisible( true );
1920  nameAttr->name = nameAttr->name + " = " + e.name;
1921  m->SetReference( "NAME = " + e.name );
1922  break;
1923 
1924  case EATTR::Off :
1925  m->Reference().SetVisible( false );
1926  break;
1927 
1928  default:
1929  nameAttr->name = e.name;
1930  if( refanceNamePresetInPackageLayout )
1931  m->Reference().SetVisible( true );
1932  }
1933  }
1934  else
1935  // No display, so default is visable, and show value of NAME
1936  m->Reference().SetVisible( true );
1937  }
1938  else if( a.name == "VALUE" )
1939  {
1940  value = a;
1941  valueAttr = &value;
1942 
1943  if( a.display )
1944  {
1945  // Yes!
1946  switch( *a.display )
1947  {
1948  case EATTR::VALUE :
1949  valueAttr->value = e.value;
1950  m->SetValue( e.value );
1951  if( valueNamePresetInPackageLayout )
1952  m->Value().SetVisible( true );
1953  break;
1954 
1955  case EATTR::NAME :
1956  if( valueNamePresetInPackageLayout )
1957  m->Value().SetVisible( true );
1958  m->SetValue( "VALUE" );
1959  break;
1960 
1961  case EATTR::BOTH :
1962  if( valueNamePresetInPackageLayout )
1963  m->Value().SetVisible( true );
1964  valueAttr->value = "VALUE = " + e.value;
1965  m->SetValue( "VALUE = " + e.value );
1966  break;
1967 
1968  case EATTR::Off :
1969  m->Value().SetVisible( false );
1970  break;
1971 
1972  default:
1973  valueAttr->value = e.value;
1974  if( valueNamePresetInPackageLayout )
1975  m->Value().SetVisible( true );
1976  }
1977  }
1978  else
1979  // No display, so default is visible, and show value of NAME
1980  m->Value().SetVisible( true );
1981 
1982  }
1983  }
1984 
1985  m_xpath->pop(); // "attribute"
1986  }
1987 
1988  orientModuleAndText( m, e, nameAttr, valueAttr );
1989  }
1990 
1991  m_xpath->pop(); // "elements.element"
1992 }
TEXTE_MODULE & Reference()
Definition: class_module.h:456
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
void push(const char *aPathSegment, const char *aAttribute="")
Eagle element element.
void SetVisible(bool aVisible)
Definition: eda_text.h:175
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:440
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:60
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
int kicad_y(double y) const
Definition: eagle_plugin.h:156
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
string name
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
D_PAD * Next() const
Definition: class_pad.h:106
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:422
opt_string value
int kicad_x(double x) const
Definition: eagle_plugin.h:157
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetPosition(const wxPoint &aPos) override
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
PTREE::const_iterator CITER
Eagle "attribute" XML element, no foolin'.
MODULE_MAP::const_iterator MODULE_CITER
int netcode
Definition: eagle_plugin.h:46
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:412
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:449
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
const char * name
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadLayerDefs ( CPTREE aLayers)
private

Definition at line 1363 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadAllSections().

1364 {
1365  typedef std::vector<ELAYER> ELAYERS;
1366  typedef ELAYERS::const_iterator EITER;
1367 
1368  ELAYERS cu; // copper layers
1369 
1370  // find the subset of layers that are copper, and active
1371  for( CITER layer = aLayers.begin(); layer != aLayers.end(); ++layer )
1372  {
1373  ELAYER elayer( layer->second );
1374 
1375  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
1376  {
1377  cu.push_back( elayer );
1378  }
1379  }
1380 
1381  // establish cu layer map:
1382  int ki_layer_count = 0;
1383 
1384  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
1385  {
1386  if( ki_layer_count == 0 )
1387  m_cu_map[it->number] = F_Cu;
1388  else if( ki_layer_count == int( cu.size()-1 ) )
1389  m_cu_map[it->number] = B_Cu;
1390  else
1391  {
1392  // some eagle boards do not have contiguous layer number sequences.
1393 
1394 #if 0 // pre PCB_LAYER_ID & LSET:
1395  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
1396 #else
1397  m_cu_map[it->number] = ki_layer_count;
1398 #endif
1399  }
1400  }
1401 
1402 #if 0 && defined(DEBUG)
1403  printf( "m_cu_map:\n" );
1404  for( unsigned i=0; i<DIM(m_cu_map); ++i )
1405  {
1406  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
1407  }
1408 #endif
1409 
1410  // Set the layer names and cu count iff we're loading a board.
1411  if( m_board )
1412  {
1413  m_board->SetCopperLayerCount( cu.size() );
1414 
1415  for( EITER it = cu.begin(); it != cu.end(); ++it )
1416  {
1417  PCB_LAYER_ID layer = kicad_layer( it->number );
1418 
1419  // these function provide their own protection against UNDEFINED_LAYER:
1420  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
1421  m_board->SetLayerType( layer, LT_SIGNAL );
1422 
1423  // could map the colors here
1424  }
1425  }
1426 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetCopperLayerCount(int aCount)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
#define cu(a)
Definition: auxiliary.h:88
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
PCB_LAYER_ID
A quick note on layer IDs:
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
PTREE::const_iterator CITER
void EAGLE_PLUGIN::loadLibraries ( CPTREE aLibs)
private

Definition at line 1774 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

1775 {
1776  m_xpath->push( "libraries.library", "name" );
1777 
1778  for( CITER library = aLibs.begin(); library != aLibs.end(); ++library )
1779  {
1780  const string& lib_name = library->second.get<string>( "<xmlattr>.name" );
1781 
1782  m_xpath->Value( lib_name.c_str() );
1783 
1784  loadLibrary( library->second, &lib_name );
1785  }
1786 
1787  m_xpath->pop();
1788 }
void push(const char *aPathSegment, const char *aAttribute="")
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
PTREE::const_iterator CITER
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadLibrary ( CPTREE aLib,
const std::string *  aLibName 
)
private

Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries" element (if a *.brd file) or under a "drawing" element if a *.lbr file.

Parameters
aLibis the portion of the loaded XML document tree that is the "library" element.
aLibNameis a pointer to the library name or NULL. If NULL this means we are loading a *.lbr not a *.brd file and the key used in m_templates is to exclude the library name.

Definition at line 1722 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadLibraries().

1723 {
1724  m_xpath->push( "packages" );
1725 
1726  // library will have <xmlattr> node, skip that and get the single packages node
1727  CPTREE& packages = aLib.get_child( "packages" );
1728 
1729  // Create a MODULE for all the eagle packages, for use later via a copy constructor
1730  // to instantiate needed MODULES in our BOARD. Save the MODULE templates in
1731  // a MODULE_MAP using a single lookup key consisting of libname+pkgname.
1732 
1733  for( CITER package = packages.begin(); package != packages.end(); ++package )
1734  {
1735  m_xpath->push( "package", "name" );
1736 
1737  const string& pack_ref = package->second.get<string>( "<xmlattr>.name" );
1738 
1739  string pack_name( pack_ref );
1740 
1741  ReplaceIllegalFileNameChars( &pack_name );
1742 
1743  m_xpath->Value( pack_name.c_str() );
1744 
1745  string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name;
1746 
1747  MODULE* m = makeModule( package->second, pack_name );
1748 
1749  // add the templating MODULE to the MODULE template factory "m_templates"
1750  std::pair<MODULE_ITER, bool> r = m_templates.insert( key, m );
1751 
1752  if( !r.second
1753  // && !( m_props && m_props->Value( "ignore_duplicates" ) )
1754  )
1755  {
1756  wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
1757  wxString pkg = FROM_UTF8( pack_name.c_str() );
1758 
1759  wxString emsg = wxString::Format(
1760  _( "<package> name: '%s' duplicated in eagle <library>: '%s'" ),
1761  GetChars( pkg ),
1762  GetChars( lib )
1763  );
1764  THROW_IO_ERROR( emsg );
1765  }
1766 
1767  m_xpath->pop();
1768  }
1769 
1770  m_xpath->pop(); // "packages"
1771 }
MODULE * makeModule(CPTREE &aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:483
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
wxString m_lib_path
Definition: eagle_plugin.h:146
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
PTREE::const_iterator CITER
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
void pop()
void Value(const char *aValue)
modify the last path node's value
void EAGLE_PLUGIN::loadPlain ( CPTREE aPlain)
private

Definition at line 1429 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, DIMENSION::AdjustDimensionDetails(), ETEXT::align, LSET::AllCuMask(), ZONE_CONTAINER::AppendCorner(), ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Clamp_Text_PenSize(), EWIRE::curve, DEFAULT_PCB_EDGE_THICKNESS, ZONE_CONTAINER::DIAGONAL_EDGE, EHOLE::drill, FROM_UTF8(), ZONE_CONTAINER::GetDefaultHatchPitchMils(), BOARD::GetDesignSettings(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, IsCopperLayer(), kicad(), kicad_arc_center(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, ECIRCLE::layer, ERECT::layer, EDIMENSION::layer, ETEXT::layer, m_board, m_hole_count, BOARD_DESIGN_SETTINGS::m_PcbTextSize, BOARD_DESIGN_SETTINGS::m_PcbTextWidth, m_xpath, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CIRCLE, MODULE::Pads(), XPATH::pop(), XPATH::push(), DLIST< T >::PushBack(), ECIRCLE::radius, ETEXT::ratio, MODULE::Reference(), ETEXT::rot, S_ARC, S_CIRCLE, DRAWSEGMENT::SetAngle(), D_PAD::SetAttribute(), D_PAD::SetDrillSize(), DRAWSEGMENT::SetEnd(), DIMENSION::SetEnd(), ZONE_CONTAINER::SetHatch(), DIMENSION::SetHeight(), EDA_TEXT::SetHorizJustify(), DIMENSION::SetLayer(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), EDA_TEXT::SetMirrored(), BOARD_CONNECTED_ITEM::SetNetCode(), DIMENSION::SetOrigin(), MODULE::SetPosition(), MODULE::SetReference(), DRAWSEGMENT::SetShape(), D_PAD::SetShape(), D_PAD::SetSize(), DRAWSEGMENT::SetStart(), EDA_TEXT::SetText(), TEXTE_PCB::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), DRAWSEGMENT::SetWidth(), DIMENSION::SetWidth(), sign(), ETEXT::size, DIMENSION::Text(), ETEXT::text, timeStamp(), ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, NETINFO_LIST::UNCONNECTED, UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, ETEXT::x, EHOLE::x, EWIRE::x1, ERECT::x1, EDIMENSION::x1, EWIRE::x2, ERECT::x2, EDIMENSION::x2, EDIMENSION::x3, ECIRCLE::y, ETEXT::y, EHOLE::y, EWIRE::y1, ERECT::y1, EDIMENSION::y1, EWIRE::y2, ERECT::y2, EDIMENSION::y2, and EDIMENSION::y3.

Referenced by loadAllSections().

1430 {
1431  m_xpath->push( "plain" );
1432 
1433  // (polygon | wire | text | circle | rectangle | frame | hole)*
1434  for( CITER gr = aGraphics.begin(); gr != aGraphics.end(); ++gr )
1435  {
1436  if( gr->first == "wire" )
1437  {
1438  m_xpath->push( "wire" );
1439 
1440  EWIRE w( gr->second );
1441  PCB_LAYER_ID layer = kicad_layer( w.layer );
1442 
1443  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1444  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1445 
1446  if( layer != UNDEFINED_LAYER )
1447  {
1448  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1449  m_board->Add( dseg, ADD_APPEND );
1450 
1451  if( !w.curve )
1452  {
1453  dseg->SetStart( start );
1454  dseg->SetEnd( end );
1455  }
1456  else
1457  {
1458  wxPoint center = kicad_arc_center( start, end, *w.curve);
1459 
1460  dseg->SetShape( S_ARC );
1461  dseg->SetStart( center );
1462  dseg->SetEnd( start );
1463  dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1464  }
1465 
1466  dseg->SetTimeStamp( timeStamp( gr->second ) );
1467  dseg->SetLayer( layer );
1468  dseg->SetWidth( Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ) );
1469  }
1470  m_xpath->pop();
1471  }
1472  else if( gr->first == "text" )
1473  {
1474  m_xpath->push( "text" );
1475 
1476  ETEXT t( gr->second );
1477  PCB_LAYER_ID layer = kicad_layer( t.layer );
1478 
1479  if( layer != UNDEFINED_LAYER )
1480  {
1481  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
1482  m_board->Add( pcbtxt, ADD_APPEND );
1483 
1484  pcbtxt->SetLayer( layer );
1485  pcbtxt->SetTimeStamp( timeStamp( gr->second ) );
1486  pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
1487  pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
1488 
1489  pcbtxt->SetTextSize( kicad_fontz( t.size ) );
1490 
1491  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1492 
1493  pcbtxt->SetThickness( kicad( t.size * ratio / 100 ) );
1494 
1495  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
1496 
1497  if( t.rot )
1498  {
1499  int sign = t.rot->mirror ? -1 : 1;
1500  pcbtxt->SetMirrored( t.rot->mirror );
1501 
1502  double degrees = t.rot->degrees;
1503 
1504  if( degrees == 90 || t.rot->spin )
1505  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1506  else if( degrees == 180 )
1507  align = ETEXT::TOP_RIGHT;
1508  else if( degrees == 270 )
1509  {
1510  pcbtxt->SetTextAngle( sign * 90 * 10 );
1511  align = ETEXT::TOP_RIGHT;
1512  }
1513  else // Ok so text is not at 90,180 or 270 so do some funny stuf to get placement right
1514  {
1515  if( ( degrees > 0 ) && ( degrees < 90 ) )
1516  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1517  else if( ( degrees > 90 ) && ( degrees < 180 ) )
1518  {
1519  pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
1520  align = ETEXT::TOP_RIGHT;
1521  }
1522  else if( ( degrees > 180 ) && ( degrees < 270 ) )
1523  {
1524  pcbtxt->SetTextAngle( sign * ( t.rot->degrees - 180 ) * 10 );
1525  align = ETEXT::TOP_RIGHT;
1526  }
1527  else if( ( degrees > 270 ) && ( degrees < 360 ) )
1528  {
1529  pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
1530  align = ETEXT::BOTTOM_LEFT;
1531  }
1532  }
1533  }
1534 
1535  switch( align )
1536  {
1537  case ETEXT::CENTER:
1538  // this was the default in pcbtxt's constructor
1539  break;
1540 
1541  case ETEXT::CENTER_LEFT:
1543  break;
1544 
1545  case ETEXT::CENTER_RIGHT:
1547  break;
1548 
1549  case ETEXT::TOP_CENTER:
1551  break;
1552 
1553  case ETEXT::TOP_LEFT:
1556  break;
1557 
1558  case ETEXT::TOP_RIGHT:
1561  break;
1562 
1563  case ETEXT::BOTTOM_CENTER:
1565  break;
1566 
1567  case ETEXT::BOTTOM_LEFT:
1570  break;
1571 
1572  case ETEXT::BOTTOM_RIGHT:
1575  break;
1576  }
1577  }
1578  m_xpath->pop();
1579  }
1580  else if( gr->first == "circle" )
1581  {
1582  m_xpath->push( "circle" );
1583 
1584  ECIRCLE c( gr->second );
1585  PCB_LAYER_ID layer = kicad_layer( c.layer );
1586 
1587  if( layer != UNDEFINED_LAYER ) // unsupported layer
1588  {
1589  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
1590  m_board->Add( dseg, ADD_APPEND );
1591 
1592  dseg->SetShape( S_CIRCLE );
1593  dseg->SetTimeStamp( timeStamp( gr->second ) );
1594  dseg->SetLayer( layer );
1595  dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
1596  dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
1597  dseg->SetWidth( kicad( c.width ) );
1598  }
1599  m_xpath->pop();
1600  }
1601  else if( gr->first == "rectangle" )
1602  {
1603  // This seems to be a simplified rectangular [copper] zone, cannot find any
1604  // net related info on it from the DTD.
1605  m_xpath->push( "rectangle" );
1606 
1607  ERECT r( gr->second );
1608  PCB_LAYER_ID layer = kicad_layer( r.layer );
1609 
1610  if( IsCopperLayer( layer ) )
1611  {
1612  // use a "netcode = 0" type ZONE:
1613  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
1614  m_board->Add( zone, ADD_APPEND );
1615 
1616  zone->SetTimeStamp( timeStamp( gr->second ) );
1617  zone->SetLayer( layer );
1619 
1621 
1622  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1623  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1624  zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1625  zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1626 
1627  // this is not my fault:
1628  zone->SetHatch( outline_hatch, Mils2iu( zone->GetDefaultHatchPitchMils() ), true );
1629  }
1630 
1631  m_xpath->pop();
1632  }
1633  else if( gr->first == "hole" )
1634  {
1635  m_xpath->push( "hole" );
1636  EHOLE e( gr->second );
1637 
1638  // Fabricate a MODULE with a single PAD_ATTRIB_HOLE_NOT_PLATED pad.
1639  // Use m_hole_count to gen up a unique name.
1640 
1641  MODULE* module = new MODULE( m_board );
1642  m_board->Add( module, ADD_APPEND );
1643 
1644  char temp[40];
1645  sprintf( temp, "@HOLE%d", m_hole_count++ );
1646  module->SetReference( FROM_UTF8( temp ) );
1647  module->Reference().SetVisible( false );
1648 
1649  wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
1650 
1651  module->SetPosition( pos );
1652 
1653  // Add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1654  D_PAD* pad = new D_PAD( module );
1655  module->Pads().PushBack( pad );
1656 
1657  pad->SetShape( PAD_SHAPE_CIRCLE );
1659 
1660  /* pad's position is already centered on module at relative (0, 0)
1661  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1662 
1663  pad->SetPos0( padpos );
1664  pad->SetPosition( padpos + module->GetPosition() );
1665  */
1666 
1667  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
1668 
1669  pad->SetDrillSize( sz );
1670  pad->SetSize( sz );
1671 
1672  pad->SetLayerSet( LSET::AllCuMask() );
1673  m_xpath->pop();
1674  }
1675  else if( gr->first == "frame" )
1676  {
1677  // picture this
1678  }
1679  else if( gr->first == "polygon" )
1680  {
1681  // could be on a copper layer, could be on another layer.
1682  // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
1683  }
1684  else if( gr->first == "dimension" )
1685  {
1686  EDIMENSION d( gr->second );
1687 
1688  DIMENSION* dimension = new DIMENSION( m_board );
1689  m_board->Add( dimension, ADD_APPEND );
1690 
1691  dimension->SetLayer( kicad_layer( d.layer ) );
1692  // The origin and end are assumed to always be in this order from eagle
1693  dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
1694  dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
1696 
1697  int width = m_board->GetDesignSettings().m_PcbTextWidth;
1698  int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
1699 
1700  if( width > maxThickness )
1701  width = maxThickness;
1702 
1703  dimension->Text().SetThickness( width );
1704  dimension->SetWidth( width );
1705 
1706  // check which axis the dimension runs in
1707  // because the "height" of the dimension is perpendicular to that axis
1708  // Note the check is just if two axes are close enough to each other
1709  // Eagle appears to have some rounding errors
1710  if( fabs( d.x1 - d.x2 ) < 0.05 )
1711  dimension->SetHeight( kicad_x( d.x1 - d.x3 ) );
1712  else
1713  dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
1714 
1715  dimension->AdjustDimensionDetails();
1716  }
1717  }
1718  m_xpath->pop();
1719 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
void SetTextAngle(double aAngle)
TEXTE_MODULE & Reference()
Definition: class_module.h:456
void SetShape(STROKE_T aShape)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
int m_PcbTextWidth
current Pcb (not module) Text width
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void push(const char *aPathSegment, const char *aAttribute="")
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetVisible(bool aVisible)
Definition: eda_text.h:175
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:889
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
Eagle hole element.
Eagle text element.
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
#define DEFAULT_PCB_EDGE_THICKNESS
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
wxSize m_PcbTextSize
current Pcb (not module) Text size
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
void AppendCorner(wxPoint position, bool aAllowDuplication=false)
Function AppendCorner.
Definition: class_zone.h:546
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
Arcs (with rounded ends)
Eagle circle.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:422
int kicad_x(double x) const
Definition: eagle_plugin.h:157
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:85
void SetPosition(const wxPoint &aPos) override
wxPoint kicad_arc_center(wxPoint start, wxPoint end, double angle)
Convert an Eagle curve end to a KiCad center for S_ARC.
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
Eagle XML rectangle in binary.
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
PTREE::const_iterator CITER
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
TEXTE_PCB & Text()
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetEnd(const wxPoint &aEnd)
Eagle wire.
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
static int GetDefaultHatchPitchMils()
Function GetDefaultHatchPitchMils.
Definition: class_zone.h:680
Eagle dimension element.
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void pop()
void SetWidth(int aWidth)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
Class DIMENSION.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::loadSignals ( CPTREE aSignals)
private

Definition at line 2605 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, ZONE_CONTAINER::AppendCorner(), B_Cu, Clamp(), EPOLYGON::CUTOUT, ZONE_CONTAINER::DIAGONAL_EDGE, EVIA::diam, EVIA::drill, F_Cu, FROM_UTF8(), DLIST< T >::Insert(), IsCopperLayer(), EPOLYGON::isolate, kicad(), kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EWIRE::layer, EPOLYGON::layer, EVIA::layer_back_most, EVIA::layer_front_most, m_board, m_min_trace, m_min_via, m_min_via_hole, m_pads_to_nets, m_rules, BOARD::m_Track, m_xpath, makeKey(), EPOLYGON::max_priority, ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_THERMAL, XPATH::pop(), EPOLYGON::pour, XPATH::push(), EPOLYGON::rank, ERULES::rlMaxViaOuter, ERULES::rlMinViaOuter, ERULES::rvViaOuter, ZONE_CONTAINER::SetArcSegmentCount(), ZONE_CONTAINER::SetDoNotAllowCopperPour(), VIA::SetDrill(), TRACK::SetEnd(), ZONE_CONTAINER::SetHatch(), ZONE_CONTAINER::SetHatchStyle(), ZONE_CONTAINER::SetIsKeepout(), BOARD_ITEM::SetLayer(), VIA::SetLayerPair(), ZONE_CONTAINER::SetMinThickness(), BOARD_CONNECTED_ITEM::SetNetCode(), ZONE_CONTAINER::SetPadConnection(), TRACK::SetPosition(), VIA::SetPosition(), ZONE_CONTAINER::SetPriority(), ZONE_CONTAINER::SetThermalReliefCopperBridge(), ZONE_CONTAINER::SetThermalReliefGap(), EDA_ITEM::SetTimeStamp(), VIA::SetViaType(), TRACK::SetWidth(), ZONE_CONTAINER::SetZoneClearance(), EPOLYGON::spacing, EPOLYGON::thermals, timeStamp(), NETINFO_LIST::UNCONNECTED, XPATH::Value(), VIA, VIA_BLIND_BURIED, VIA_MICROVIA, VIA_THROUGH, EWIRE::width, EPOLYGON::width, EVIA::x, EVERTEX::x, EWIRE::x1, EWIRE::x2, EVIA::y, EVERTEX::y, EWIRE::y1, and EWIRE::y2.

Referenced by loadAllSections().

2606 {
2607  ZONES zones; // per net
2608 
2609  m_xpath->push( "signals.signal", "name" );
2610 
2611  int netCode = 1;
2612 
2613  for( CITER net = aSignals.begin(); net != aSignals.end(); ++net )
2614  {
2615  bool sawPad = false;
2616 
2617  zones.clear();
2618 
2619  const string& nname = net->second.get<string>( "<xmlattr>.name" );
2620  wxString netName = FROM_UTF8( nname.c_str() );
2621  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
2622 
2623  m_xpath->Value( nname.c_str() );
2624 
2625  // (contactref | polygon | wire | via)*
2626  for( CITER it = net->second.begin(); it != net->second.end(); ++it )
2627  {
2628  if( it->first == "wire" )
2629  {
2630  m_xpath->push( "wire" );
2631  EWIRE w( it->second );
2632  PCB_LAYER_ID layer = kicad_layer( w.layer );
2633 
2634  if( IsCopperLayer( layer ) )
2635  {
2636  TRACK* t = new TRACK( m_board );
2637 
2638  t->SetTimeStamp( timeStamp( it->second ) );
2639 
2640  t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
2641  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2642 
2643  int width = kicad( w.width );
2644  if( width < m_min_trace )
2645  m_min_trace = width;
2646 
2647  t->SetWidth( width );
2648  t->SetLayer( layer );
2649  t->SetNetCode( netCode );
2650 
2651  m_board->m_Track.Insert( t, NULL );
2652  }
2653  else
2654  {
2655  // put non copper wires where the sun don't shine.
2656  }
2657 
2658  m_xpath->pop();
2659  }
2660 
2661  else if( it->first == "via" )
2662  {
2663  m_xpath->push( "via" );
2664  EVIA v( it->second );
2665 
2666  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2667  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2668 
2669  if( IsCopperLayer( layer_front_most ) &&
2670  IsCopperLayer( layer_back_most ) )
2671  {
2672  int kidiam;
2673  int drillz = kicad( v.drill );
2674  VIA* via = new VIA( m_board );
2675  m_board->m_Track.Insert( via, NULL );
2676 
2677  via->SetLayerPair( layer_front_most, layer_back_most );
2678 
2679  if( v.diam )
2680  {
2681  kidiam = kicad( *v.diam );
2682  via->SetWidth( kidiam );
2683  }
2684  else
2685  {
2686  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2687  annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
2688  kidiam = KiROUND( drillz + 2 * annulus );
2689  via->SetWidth( kidiam );
2690  }
2691 
2692  via->SetDrill( drillz );
2693 
2694  if( kidiam < m_min_via )
2695  m_min_via = kidiam;
2696 
2697  if( drillz < m_min_via_hole )
2698  m_min_via_hole = drillz;
2699 
2700  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2701  via->SetViaType( VIA_THROUGH );
2702  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2703  via->SetViaType( VIA_MICROVIA );
2704  else
2705  via->SetViaType( VIA_BLIND_BURIED );
2706 
2707  via->SetTimeStamp( timeStamp( it->second ) );
2708 
2709  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2710 
2711  via->SetPosition( pos );
2712  via->SetEnd( pos );
2713 
2714  via->SetNetCode( netCode );
2715  }
2716  m_xpath->pop();
2717  }
2718 
2719  else if( it->first == "contactref" )
2720  {
2721  m_xpath->push( "contactref" );
2722  // <contactref element="RN1" pad="7"/>
2723  CPTREE& attribs = it->second.get_child( "<xmlattr>" );
2724 
2725  const string& reference = attribs.get<string>( "element" );
2726  const string& pad = attribs.get<string>( "pad" );
2727 
2728  string key = makeKey( reference, pad ) ;
2729 
2730  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
2731 
2732  m_pads_to_nets[ key ] = ENET( netCode, nname );
2733 
2734  m_xpath->pop();
2735 
2736  sawPad = true;
2737  }
2738 
2739  else if( it->first == "polygon" )
2740  {
2741  m_xpath->push( "polygon" );
2742 
2743  EPOLYGON p( it->second );
2744  PCB_LAYER_ID layer = kicad_layer( p.layer );
2745 
2746  if( IsCopperLayer( layer ) )
2747  {
2748  // use a "netcode = 0" type ZONE:
2749  ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
2750  m_board->Add( zone, ADD_APPEND );
2751  zones.push_back( zone );
2752 
2753  zone->SetTimeStamp( timeStamp( it->second ) );
2754  zone->SetLayer( layer );
2755  zone->SetNetCode( netCode );
2756 
2757  for( CITER vi = it->second.begin(); vi != it->second.end(); ++vi )
2758  {
2759  if( vi->first != "vertex" ) // skip <xmlattr> node
2760  continue;
2761 
2762  EVERTEX v( vi->second );
2763 
2764  // Append the corner
2765  zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2766  }
2767 
2768  // If the pour is a cutout it needs to be set to a keepout
2769  if( p.pour == EPOLYGON::CUTOUT )
2770  {
2771  zone->SetIsKeepout( true );
2772  zone->SetDoNotAllowCopperPour( true );
2774  }
2775 
2776  // if spacing is set the zone should be hatched
2777  if( p.spacing )
2778  zone->SetHatch( ZONE_CONTAINER::DIAGONAL_EDGE, *p.spacing, true );
2779 
2780  // clearances, etc.
2781  zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
2782  zone->SetMinThickness( kicad( p.width ) );
2783 
2784  // FIXME: KiCad zones have very rounded corners compared to eagle.
2785  // This means that isolation amounts that work well in eagle
2786  // tend to make copper intrude in soldermask free areas around pads.
2787  if( p.isolate )
2788  {
2789  zone->SetZoneClearance( kicad( *p.isolate ) );
2790  }
2791 
2792  // missing == yes per DTD.
2793  bool thermals = !p.thermals || *p.thermals;
2795  if( thermals )
2796  {
2797  // FIXME: eagle calculates dimensions for thermal spokes
2798  // based on what the zone is connecting to.
2799  // (i.e. width of spoke is half of the smaller side of an smd pad)
2800  // This is a basic workaround
2801  zone->SetThermalReliefGap( kicad( p.width + 0.05 ) );
2802  zone->SetThermalReliefCopperBridge( kicad( p.width + 0.05 ) );
2803  }
2804 
2805  int rank = p.rank ? *p.rank : p.max_priority;
2806  zone->SetPriority( rank );
2807  }
2808 
2809  m_xpath->pop(); // "polygon"
2810  }
2811  }
2812 
2813  if( zones.size() && !sawPad )
2814  {
2815  // KiCad does not support an unconnected zone with its own non-zero netcode,
2816  // but only when assigned netcode = 0 w/o a name...
2817  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2818  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2819 
2820  // therefore omit this signal/net.
2821  }
2822  else
2823  netCode++;
2824  }
2825 
2826  m_xpath->pop(); // "signals.signal"
2827 }
double rlMaxViaOuter
maximum copper annulus on via
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:447
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:417
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
static string makeKey(const string &aFirst, const string &aSecond)
Assemble a two part key as a simple concatonation of aFirst and aSecond parts, using a separator...
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
const PTREE CPTREE
Definition: eagle_plugin.h:63
void push(const char *aPathSegment, const char *aAttribute="")
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:197
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:889
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
double rvViaOuter
copper annulus is this percent of via hole
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:124
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void SetWidth(int aWidth)
Definition: class_track.h:114
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:113
PCB_LAYER_ID
A quick note on layer IDs:
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
void AppendCorner(wxPoint position, bool aAllowDuplication=false)
Function AppendCorner.
Definition: class_zone.h:546
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:204
std::vector< ZONE_CONTAINER * > ZONES
non-owning container
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:191
PTREE::const_iterator CITER
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:660
Eagle via.
Class NETINFO_ITEM handles the data for a net.
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:111
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:454
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:559
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
Eagle wire.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< TRACK > m_Track
Definition: class_board.h:244
Eagle polygon, without vertices which are parsed as needed.
void pop()
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:659
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:207
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:210
double rlMinViaOuter
minimum copper annulus on via
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
Use thermal relief for pads.
Definition: zones.h:58
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:188
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
pads are covered by copper
Definition: zones.h:59
void Value(const char *aValue)
modify the last path node's value
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
MODULE * EAGLE_PLUGIN::makeModule ( CPTREE aPackage,
const std::string &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 2124 of file eagle_plugin.cpp.

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

Referenced by loadLibrary().

2125 {
2126  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
2127 
2128  m->SetFPID( LIB_ID( aPkgName ) );
2129 
2130  opt_string description = aPackage.get_optional<string>( "description" );
2131  if( description )
2132  m->SetDescription( FROM_UTF8( description->c_str() ) );
2133 
2134  for( CITER it = aPackage.begin(); it != aPackage.end(); ++it )
2135  {
2136  CPTREE& t = it->second;
2137 
2138  if( it->first == "wire" )
2139  packageWire( m.get(), t );
2140 
2141  else if( it->first == "pad" )
2142  packagePad( m.get(), t );
2143 
2144  else if( it->first == "text" )
2145  packageText( m.get(), t );
2146 
2147  else if( it->first == "rectangle" )
2148  packageRectangle( m.get(), t );
2149 
2150  else if( it->first == "polygon" )
2151  packagePolygon( m.get(), t );
2152 
2153  else if( it->first == "circle" )
2154  packageCircle( m.get(), t );
2155 
2156  else if( it->first == "hole" )
2157  packageHole( m.get(), t );
2158 
2159  else if( it->first == "smd" )
2160  packageSMD( m.get(), t );
2161  }
2162 
2163  return m.release();
2164 }
void packageCircle(MODULE *aModule, CPTREE &aTree) const
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:137
void packagePolygon(MODULE *aModule, CPTREE &aTree) const
void packageText(MODULE *aModule, CPTREE &aTree) const
const PTREE CPTREE
Definition: eagle_plugin.h:63
Class LIB_ID.
Definition: lib_id.h:56
void packagePad(MODULE *aModule, CPTREE &aTree) const
void packageRectangle(MODULE *aModule, CPTREE &aTree) const
void packageSMD(MODULE *aModule, CPTREE &aTree) const
void packageHole(MODULE *aModule, CPTREE &aTree) const
PTREE::const_iterator CITER
void packageWire(MODULE *aModule, CPTREE &aTree) const
void EAGLE_PLUGIN::orientModuleAndText ( MODULE m,
const EELEMENT e,
const EATTR nameAttr,
const EATTR valueAttr 
)
private

Definition at line 1995 of file eagle_plugin.cpp.

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

Referenced by loadElements().

1997 {
1998  if( e.rot )
1999  {
2000  if( e.rot->mirror )
2001  {
2002  double orientation = e.rot->degrees + 180.0;
2003  m->SetOrientation( orientation * 10 );
2004  m->Flip( m->GetPosition() );
2005  }
2006  else
2007  m->SetOrientation( e.rot->degrees * 10 );
2008  }
2009 
2010  orientModuleText( m, e, &m->Reference(), nameAttr );
2011  orientModuleText( m, e, &m->Value(), valueAttr );
2012 }
TEXTE_MODULE & Reference()
Definition: class_module.h:456
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
const wxPoint & GetPosition() const override
Definition: class_module.h:144
opt_erot rot
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
void SetOrientation(double newangle)
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
void EAGLE_PLUGIN::orientModuleText ( MODULE m,
const EELEMENT e,
TEXTE_MODULE txt,
const EATTR a 
)
private

Definition at line 2015 of file eagle_plugin.cpp.

References abs, ETEXT::BOTTOM_LEFT, FROM_UTF8(), MODULE::GetOrientation(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextSize(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsMirrored(), kicad_fontz(), kicad_x(), kicad_y(), EATTR::ratio, EATTR::rot, EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetMirrored(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_TEXT::SetVertJustify(), sign(), EATTR::size, ETEXT::TOP_RIGHT, EATTR::value, EATTR::x, and EATTR::y.

Referenced by orientModuleAndText().

2017 {
2018  // Smashed part ?
2019  if( aAttr )
2020  { // Yes
2021  const EATTR& a = *aAttr;
2022 
2023  if( a.value )
2024  {
2025  txt->SetText( FROM_UTF8( a.value->c_str() ) );
2026  }
2027 
2028  if( a.x && a.y ) // boost::optional
2029  {
2030  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
2031  txt->SetTextPos( pos );
2032  }
2033 
2034  // Even though size and ratio are both optional, I am not seeing
2035  // a case where ratio is present but size is not.
2036  double ratio = 8;
2037  wxSize fontz = txt->GetTextSize();
2038 
2039  if( a.size )
2040  {
2041  fontz = kicad_fontz( *a.size );
2042  txt->SetTextSize( fontz );
2043 
2044  if( a.ratio )
2045  ratio = *a.ratio;
2046  }
2047 
2048  int lw = int( fontz.y * ratio / 100.0 );
2049  txt->SetThickness( lw );
2050 
2051  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2052 
2053  // The "rot" in a EATTR seems to be assumed to be zero if it is not
2054  // present, and this zero rotation becomes an override to the
2055  // package's text field. If they did not want zero, they specify
2056  // what they want explicitly.
2057  double degrees = a.rot ? a.rot->degrees : 0;
2058  double orient; // relative to parent
2059 
2060  int sign = 1;
2061  bool spin = false;
2062 
2063  if( a.rot )
2064  {
2065  spin = a.rot->spin;
2066  sign = a.rot->mirror ? -1 : 1;
2067  txt->SetMirrored( a.rot->mirror );
2068  }
2069 
2070  if( degrees == 90 || degrees == 0 || spin )
2071  {
2072  orient = degrees - m->GetOrientation() / 10;
2073  txt->SetTextAngle( sign * orient * 10 );
2074  }
2075  else if( degrees == 180 )
2076  {
2077  orient = 0 - m->GetOrientation() / 10;
2078  txt->SetTextAngle( sign * orient * 10 );
2079  align = ETEXT::TOP_RIGHT;
2080  }
2081  else if( degrees == 270 )
2082  {
2083  orient = 90 - m->GetOrientation() / 10;
2084  align = ETEXT::TOP_RIGHT;
2085  txt->SetTextAngle( sign * orient * 10 );
2086  }
2087  else
2088  {
2089  orient = 90 - degrees - m->GetOrientation() / 10;
2090  txt->SetTextAngle( sign * orient * 10 );
2091  }
2092 
2093  switch( align )
2094  {
2095  case ETEXT::TOP_RIGHT:
2098  break;
2099 
2100  case ETEXT::BOTTOM_LEFT:
2103  break;
2104 
2105  default:
2106  ;
2107  }
2108  }
2109  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
2110  {
2111  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
2112 
2113  // @todo there are a few more cases than these to contend with:
2114  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
2115  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
2116  {
2117  // ETEXT::TOP_RIGHT:
2120  }
2121  }
2122 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
opt_double size
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
#define abs(a)
Definition: auxiliary.h:84
opt_erot rot
double GetTextAngle() const
Definition: eda_text.h:164
int kicad_y(double y) const
Definition: eagle_plugin.h:156
double GetOrientation() const
Definition: class_module.h:148
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
opt_string value
int kicad_x(double x) const
Definition: eagle_plugin.h:157
opt_double x
Eagle "attribute" XML element, no foolin'.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
bool IsMirrored() const
Definition: eda_text.h:179
opt_double ratio
void SetTextAngle(double aAngle)
const wxSize & GetTextSize() const
Definition: eda_text.h:215
opt_double y
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
void EAGLE_PLUGIN::packageCircle ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2482 of file eagle_plugin.cpp.

References Cmts_User, MODULE::GraphicalItems(), kicad(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, DLIST< T >::PushBack(), ECIRCLE::radius, S_CIRCLE, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

Referenced by makeModule().

2483 {
2484  ECIRCLE e( aTree );
2485  PCB_LAYER_ID layer = kicad_layer( e.layer );
2486  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
2487 
2488  aModule->GraphicalItems().PushBack( gr );
2489 
2490  gr->SetWidth( kicad( e.width ) );
2491 
2492  switch( (int) layer )
2493  {
2494  case UNDEFINED_LAYER: layer = Cmts_User; break;
2495  /*
2496  case Eco1_User: layer = F_SilkS; break;
2497  case Eco2_User: layer = B_SilkS; break;
2498  */
2499  default:
2500  break;
2501  }
2502 
2503  gr->SetLayer( layer );
2504  gr->SetTimeStamp( timeStamp( aTree ) );
2505 
2506  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
2507  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
2508 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Eagle circle.
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetStart0(const wxPoint &aPoint)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageHole ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2511 of file eagle_plugin.cpp.

References LSET::AllCuMask(), EHOLE::drill, MODULE::GetPosition(), kicad(), kicad_x(), kicad_y(), PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CIRCLE, MODULE::Pads(), DLIST< T >::PushBack(), D_PAD::SetAttribute(), D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), EHOLE::x, and EHOLE::y.

Referenced by makeModule().

2512 {
2513  EHOLE e( aTree );
2514 
2515  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
2516  D_PAD* pad = new D_PAD( aModule );
2517  aModule->Pads().PushBack( pad );
2518 
2519  pad->SetShape( PAD_SHAPE_CIRCLE );
2521 
2522  // Mechanical purpose only:
2523  // no offset, no net name, no pad name allowed
2524  // pad->SetOffset( wxPoint( 0, 0 ) );
2525  // pad->SetPadName( wxEmptyString );
2526 
2527  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2528 
2529  pad->SetPos0( padpos );
2530  pad->SetPosition( padpos + aModule->GetPosition() );
2531 
2532  wxSize sz( kicad( e.drill ), kicad( e.drill ) );
2533 
2534  pad->SetDrillSize( sz );
2535  pad->SetSize( sz );
2536 
2537  pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
2538 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
const wxPoint & GetPosition() const override
Definition: class_module.h:144
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
Eagle hole element.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packagePad ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2206 of file eagle_plugin.cpp.

References LSET::AllCuMask(), B_Mask, Clamp(), EPAD::diameter, EPAD::drill, F_Mask, FROM_UTF8(), D_PAD::GetDrillSize(), MODULE::GetOrientation(), MODULE::GetPosition(), D_PAD::GetShape(), D_PAD::GetSize(), kicad(), kicad_x(), kicad_y(), KiROUND(), EPAD::LONG, m_rules, EPAD::name, EPAD::OCTAGON, EPAD::OFFSET, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, MODULE::Pads(), ERULES::psElongationLong, DLIST< T >::PushBack(), ERULES::rlMaxPadTop, ERULES::rlMinPadTop, EPAD::rot, RotatePoint(), EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetPadName(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, EPAD::x, and EPAD::y.

Referenced by makeModule().

2207 {
2208  // this is thru hole technology here, no SMDs
2209  EPAD e( aTree );
2210 
2211  D_PAD* pad = new D_PAD( aModule );
2212  aModule->Pads().PushBack( pad );
2213 
2214  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2215 
2216  // pad's "Position" is not relative to the module's,
2217  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2218 
2219  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2220 
2221  pad->SetPos0( padpos );
2222 
2223  RotatePoint( &padpos, aModule->GetOrientation() );
2224 
2225  pad->SetPosition( padpos + aModule->GetPosition() );
2226 
2227  pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
2228 
2229  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
2230 
2231  if( e.shape )
2232  {
2233  switch( *e.shape )
2234  {
2235  case EPAD::ROUND:
2236  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2237  break;
2238 
2239  case EPAD::OCTAGON:
2240  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
2241  // pad->SetShape( PAD_OCTAGON );
2242  wxASSERT( pad->GetShape()==PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
2243  break;
2244 
2245  case EPAD::LONG:
2246  pad->SetShape( PAD_SHAPE_OVAL );
2247  break;
2248 
2249  case EPAD::SQUARE:
2250  pad->SetShape( PAD_SHAPE_RECT );
2251  break;
2252 
2253  case EPAD::OFFSET:
2254  ; // don't know what to do here.
2255  }
2256  }
2257  else
2258  {
2259  // if shape is not present, our default is circle and that matches their default "round"
2260  }
2261 
2262  if( e.diameter )
2263  {
2264  int diameter = kicad( *e.diameter );
2265  pad->SetSize( wxSize( diameter, diameter ) );
2266  }
2267  else
2268  {
2269  double drillz = pad->GetDrillSize().x;
2270  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
2271  annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
2272  int diameter = KiROUND( drillz + 2 * annulus );
2273  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
2274  }
2275 
2276  if( pad->GetShape() == PAD_SHAPE_OVAL )
2277  {
2278  // The Eagle "long" pad is wider than it is tall,
2279  // m_elongation is percent elongation
2280  wxSize sz = pad->GetSize();
2281  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
2282  pad->SetSize( sz );
2283  }
2284 
2285  if( e.rot )
2286  {
2287  pad->SetOrientation( e.rot->degrees * 10 );
2288  }
2289 
2290  // @todo: handle stop and thermal
2291 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
const T & Clamp(const T &lower, const T &value, const T &upper)
Function Clamp limits value within the range lower <= value <= upper.
Definition: macros.h:127
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
const wxPoint & GetPosition() const override
Definition: class_module.h:144
double rlMaxPadTop
maximum copper annulus on through hole pads
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle thru hol pad.
double GetOrientation() const
Definition: class_module.h:148
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
const wxSize & GetSize() const
Definition: class_pad.h:182
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
int psElongationLong
percent over 100%.
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:404
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:306
double rvPadTop
top pad size as percent of drill size
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
double rlMinPadTop
minimum copper annulus on through hole pads
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2433 of file eagle_plugin.cpp.

References MODULE::GraphicalItems(), IsNonCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), EPOLYGON::layer, DLIST< T >::PushBack(), S_POLYGON, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), EVERTEX::x, and EVERTEX::y.

Referenced by makeModule().

2434 {
2435  EPOLYGON p( aTree );
2436  PCB_LAYER_ID layer = kicad_layer( p.layer );
2437 
2438  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2439  {
2440  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2441  aModule->GraphicalItems().PushBack( dwg );
2442 
2443  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
2444 
2445  /*
2446  switch( layer )
2447  {
2448  case Eco1_User: layer = F_SilkS; break;
2449  case Eco2_User: layer = B_SilkS; break;
2450 
2451  // all MODULE templates (created from eagle packages) are on front layer
2452  // until cloned.
2453  case Cmts_User: layer = F_SilkS; break;
2454  }
2455  */
2456 
2457  dwg->SetLayer( layer );
2458 
2459  dwg->SetTimeStamp( timeStamp( aTree ) );
2460 
2461  std::vector<wxPoint> pts;
2462  pts.reserve( aTree.size() );
2463 
2464  for( CITER vi = aTree.begin(); vi != aTree.end(); ++vi )
2465  {
2466  if( vi->first != "vertex" ) // skip <xmlattr> node
2467  continue;
2468 
2469  EVERTEX v( vi->second );
2470 
2471  pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
2472  }
2473 
2474  dwg->SetPolyPoints( pts );
2475 
2476  dwg->SetStart0( *pts.begin() );
2477  dwg->SetEnd0( pts.back() );
2478  }
2479 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
polygon (not yet used for tracks, but could be in microwave apps)
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
PTREE::const_iterator CITER
void SetStart0(const wxPoint &aPoint)
Eagle polygon, without vertices which are parsed as needed.
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2400 of file eagle_plugin.cpp.

References MODULE::GraphicalItems(), IsNonCopperLayer(), kicad_layer(), kicad_x(), kicad_y(), ERECT::layer, DLIST< T >::PushBack(), S_POLYGON, EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetPolyPoints(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), timeStamp(), ERECT::x1, ERECT::x2, ERECT::y1, and ERECT::y2.

Referenced by makeModule().

2401 {
2402  ERECT r( aTree );
2403  PCB_LAYER_ID layer = kicad_layer( r.layer );
2404 
2405  if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
2406  {
2407  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
2408  aModule->GraphicalItems().PushBack( dwg );
2409 
2410  dwg->SetLayer( layer );
2411  dwg->SetWidth( 0 );
2412 
2413  dwg->SetTimeStamp( timeStamp( aTree ) );
2414 
2415  std::vector<wxPoint> pts;
2416 
2417  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
2418  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
2419 
2420  pts.push_back( start );
2421  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
2422  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
2423  pts.push_back( end );
2424 
2425  dwg->SetPolyPoints( pts );
2426 
2427  dwg->SetStart0( start );
2428  dwg->SetEnd0( end );
2429  }
2430 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
polygon (not yet used for tracks, but could be in microwave apps)
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
int kicad_x(double x) const
Definition: eagle_plugin.h:157
Eagle XML rectangle in binary.
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void SetStart0(const wxPoint &aPoint)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2541 of file eagle_plugin.cpp.

References B_Cu, B_Mask, B_Paste, ESMD::dx, ESMD::dy, F_Cu, F_Mask, F_Paste, FROM_UTF8(), MODULE::GetOrientation(), MODULE::GetPosition(), IsCopperLayer(), kicad(), kicad_layer(), kicad_x(), kicad_y(), ESMD::layer, ESMD::name, PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, MODULE::Pads(), DLIST< T >::PushBack(), ESMD::rot, RotatePoint(), ESMD::roundness, D_PAD::SetAttribute(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetPadName(), D_PAD::SetPos0(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), ESMD::x, and ESMD::y.

Referenced by makeModule().

2542 {
2543  ESMD e( aTree );
2544  PCB_LAYER_ID layer = kicad_layer( e.layer );
2545 
2546  if( !IsCopperLayer( layer ) )
2547  {
2548  return;
2549  }
2550 
2551  D_PAD* pad = new D_PAD( aModule );
2552  aModule->Pads().PushBack( pad );
2553 
2554  pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
2555  pad->SetShape( PAD_SHAPE_RECT );
2556  pad->SetAttribute( PAD_ATTRIB_SMD );
2557 
2558  // pad's "Position" is not relative to the module's,
2559  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
2560 
2561  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
2562 
2563  pad->SetPos0( padpos );
2564 
2565  RotatePoint( &padpos, aModule->GetOrientation() );
2566 
2567  pad->SetPosition( padpos + aModule->GetPosition() );
2568 
2569  pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
2570 
2571  pad->SetLayer( layer );
2572 
2573  static const LSET front( 3, F_Cu, F_Paste, F_Mask );
2574  static const LSET back( 3, B_Cu, B_Paste, B_Mask );
2575 
2576  if( layer == F_Cu )
2577  pad->SetLayerSet( front );
2578  else if( layer == B_Cu )
2579  pad->SetLayerSet( back );
2580 
2581  // Optional according to DTD
2582  if( e.roundness ) // set set shape to PAD_SHAPE_RECT above, in case roundness is not present
2583  {
2584  if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
2585  {
2586  if( e.dy == e.dx )
2587  pad->SetShape( PAD_SHAPE_CIRCLE );
2588  else
2589  pad->SetShape( PAD_SHAPE_OVAL );
2590  }
2591  }
2592 
2593  if( e.rot )
2594  {
2595  pad->SetOrientation( e.rot->degrees * 10 );
2596  }
2597 
2598  // don't know what stop, thermals, and cream should look like now.
2599 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
const wxPoint & GetPosition() const override
Definition: class_module.h:144
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
Eagle SMD pad.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
double GetOrientation() const
Definition: class_module.h:148
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:297
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:234
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:167
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:404
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:306
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packageText ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2294 of file eagle_plugin.cpp.

References ETEXT::align, ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, Cmts_User, FROM_UTF8(), MODULE::GetPosition(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, MODULE::GraphicalItems(), kicad(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), ETEXT::layer, DLIST< T >::PushBack(), ETEXT::ratio, MODULE::Reference(), ETEXT::rot, EDA_TEXT::SetHorizJustify(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), TEXTE_MODULE::SetPos0(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), EDA_TEXT::SetVertJustify(), sign(), ETEXT::size, ETEXT::text, timeStamp(), ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, UNDEFINED_LAYER, MODULE::Value(), ETEXT::x, and ETEXT::y.

Referenced by makeModule().

2295 {
2296  ETEXT t( aTree );
2297  PCB_LAYER_ID layer = kicad_layer( t.layer );
2298 
2299  if( layer == UNDEFINED_LAYER )
2300  {
2301  layer = Cmts_User;
2302  }
2303 
2304  TEXTE_MODULE* txt;
2305 
2306  if( t.text == ">NAME" || t.text == ">name" )
2307  txt = &aModule->Reference();
2308  else if( t.text == ">VALUE" || t.text == ">value" )
2309  txt = &aModule->Value();
2310  else
2311  {
2312  // FIXME: graphical text items are rotated for some reason.
2313  txt = new TEXTE_MODULE( aModule );
2314  aModule->GraphicalItems().PushBack( txt );
2315  }
2316 
2317  txt->SetTimeStamp( timeStamp( aTree ) );
2318  txt->SetText( FROM_UTF8( t.text.c_str() ) );
2319 
2320  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
2321 
2322  txt->SetTextPos( pos );
2323  txt->SetPos0( pos - aModule->GetPosition() );
2324 
2325  txt->SetLayer( layer );
2326  txt->SetTextSize( kicad_fontz( t.size ) );
2327 
2328  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
2329 
2330  txt->SetThickness( kicad( t.size * ratio / 100 ) );
2331 
2332  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
2333 
2334  // An eagle package is never rotated, the DTD does not allow it.
2335  // angle -= aModule->GetOrienation();
2336 
2337  if( t.rot )
2338  {
2339  int sign = t.rot->mirror ? -1 : 1;
2340  txt->SetMirrored( t.rot->mirror );
2341 
2342  double degrees = t.rot->degrees;
2343 
2344  if( degrees == 90 || t.rot->spin )
2345  txt->SetTextAngle( sign * degrees * 10 );
2346  else if( degrees == 180 )
2347  align = ETEXT::TOP_RIGHT;
2348  else if( degrees == 270 )
2349  {
2350  align = ETEXT::TOP_RIGHT;
2351  txt->SetTextAngle( sign * 90 * 10 );
2352  }
2353  }
2354 
2355  switch( align )
2356  {
2357  case ETEXT::CENTER:
2358  // this was the default in pcbtxt's constructor
2359  break;
2360 
2361  case ETEXT::CENTER_LEFT:
2363  break;
2364 
2365  case ETEXT::CENTER_RIGHT:
2367  break;
2368 
2369  case ETEXT::TOP_CENTER:
2371  break;
2372 
2373  case ETEXT::TOP_LEFT:
2376  break;
2377 
2378  case ETEXT::TOP_RIGHT:
2381  break;
2382 
2383  case ETEXT::BOTTOM_CENTER:
2385  break;
2386 
2387  case ETEXT::BOTTOM_LEFT:
2390  break;
2391 
2392  case ETEXT::BOTTOM_RIGHT:
2395  break;
2396  }
2397 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
TEXTE_MODULE & Reference()
Definition: class_module.h:456
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
const wxPoint & GetPosition() const override
Definition: class_module.h:144
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
Eagle text element.
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void SetPos0(const wxPoint &aPos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetTextAngle(double aAngle)
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void EAGLE_PLUGIN::packageWire ( MODULE aModule,
CPTREE aTree 
) const
private

Definition at line 2167 of file eagle_plugin.cpp.

References EWIRE::curve, MODULE::GraphicalItems(), IsNonCopperLayer(), kicad(), kicad_arc_center(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, DLIST< T >::PushBack(), S_ARC, S_SEGMENT, DRAWSEGMENT::SetAngle(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), DRAWSEGMENT::SetWidth(), EWIRE::width, EWIRE::x1, EWIRE::x2, EWIRE::y1, and EWIRE::y2.

Referenced by makeModule().

2168 {
2169  EWIRE w( aTree );
2170  PCB_LAYER_ID layer = kicad_layer( w.layer );
2171 
2172  if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
2173  {
2174  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
2175  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
2176  int width = kicad( w.width );
2177 
2178  // FIXME: the cap attribute is ignored because kicad can't create lines
2179  // with flat ends.
2180  EDGE_MODULE* dwg;
2181  if( !w.curve )
2182  {
2183  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
2184 
2185  dwg->SetStart0( start );
2186  dwg->SetEnd0( end );
2187  }
2188  else
2189  {
2190  dwg = new EDGE_MODULE( aModule, S_ARC );
2191  wxPoint center = kicad_arc_center( start, end, *w.curve);
2192 
2193  dwg->SetStart0( center );
2194  dwg->SetEnd0( start );
2195  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
2196  }
2197 
2198  dwg->SetLayer( layer );
2199  dwg->SetWidth( width );
2200 
2201  aModule->GraphicalItems().PushBack( dwg );
2202  }
2203 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
usual segment : line with rounded ends
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Arcs (with rounded ends)
int kicad_x(double x) const
Definition: eagle_plugin.h:157
wxPoint kicad_arc_center(wxPoint start, wxPoint end, double angle)
Convert an Eagle curve end to a KiCad center for S_ARC.
void SetStart0(const wxPoint &aPoint)
Eagle wire.
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
void SetWidth(int aWidth)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 1157 of file eagle_plugin.cpp.

1158 {
1159  return wxT( "Eagle" );
1160 }
void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Plugins that cannot prefetch need not override this; a default no-op is provided.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is an error prefetching the library.

Reimplemented in GITHUB_PLUGIN.

Definition at line 69 of file plugin.cpp.

Referenced by FP_LIB_TABLE::PrefetchLib().

70 {
71  (void) aLibraryPath;
72  (void) aProperties;
73 }
void PLUGIN::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aBoardis the class BOARD in memory document tree from which to extract information when writing to aFileName. The caller continues to own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented in PCB_IO.

Definition at line 54 of file plugin.cpp.

References not_implemented().

Referenced by IO_MGR::Save(), PCB_EDIT_FRAME::SavePcbCopy(), and PCB_EDIT_FRAME::SavePcbFile().

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

Member Data Documentation

double EAGLE_PLUGIN::biu_per_mm
private

how many bius in a mm

Definition at line 144 of file eagle_plugin.h.

Referenced by init(), and kicad().

BOARD* EAGLE_PLUGIN::m_board
private

which BOARD is being worked on, no ownership here

Definition at line 137 of file eagle_plugin.h.

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

int EAGLE_PLUGIN::m_cu_map[17]
private

map eagle to kicad, cu layers only.

Definition at line 121 of file eagle_plugin.h.

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

int EAGLE_PLUGIN::m_hole_count
private

generates unique module names from eagle "hole"s.

Definition at line 127 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

wxString EAGLE_PLUGIN::m_lib_path
private

Definition at line 146 of file eagle_plugin.h.

Referenced by cacheLib(), and loadLibrary().

int EAGLE_PLUGIN::m_min_trace
private

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

Definition at line 139 of file eagle_plugin.h.

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

int EAGLE_PLUGIN::m_min_via
private

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

Definition at line 140 of file eagle_plugin.h.

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

int EAGLE_PLUGIN::m_min_via_hole
private

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

Definition at line 141 of file eagle_plugin.h.

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

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 147 of file eagle_plugin.h.

Referenced by cacheLib().

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

Definition at line 129 of file eagle_plugin.h.

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

const PROPERTIES* EAGLE_PLUGIN::m_props
private

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

Definition at line 136 of file eagle_plugin.h.

Referenced by centerBoard(), and init().

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 123 of file eagle_plugin.h.

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

MODULE_MAP EAGLE_PLUGIN::m_templates
private

is part of a MODULE factory that operates using copy construction.

lookup key is either libname.packagename or simply packagename if FootprintLoad() or FootprintEnumberate()

Definition at line 131 of file eagle_plugin.h.

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

XPATH* EAGLE_PLUGIN::m_xpath
private

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

Definition at line 124 of file eagle_plugin.h.

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

double EAGLE_PLUGIN::mm_per_biu
private

how many mm in each BIU

Definition at line 143 of file eagle_plugin.h.

Referenced by init().


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