KiCad PCB EDA Suite
EAGLE_PLUGIN Class Reference

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

#include <eagle_plugin.h>

Inheritance diagram for EAGLE_PLUGIN:
PLUGIN

Public Types

typedef int BIU
 

Public Member Functions

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

Private Types

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

Private Member Functions

void init (const PROPERTIES *aProperties)
 initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. More...
 
void clear_cu_map ()
 
int kicad_y (const ECOORD &y) const
 Convert an Eagle distance to a KiCad distance. More...
 
int kicad_x (const ECOORD &x) const
 
wxSize kicad_fontz (const ECOORD &d) const
 create a font size (fontz) from an eagle font size scalar More...
 
PCB_LAYER_ID kicad_layer (int aLayer) const
 Convert an Eagle layer to a KiCad layer. More...
 
const wxString & eagle_layer_name (int aLayer) const
 Get Eagle layer name by its number. More...
 
void cacheLib (const wxString &aLibraryPath)
 This PLUGIN only caches one footprint library, this determines which one. More...
 
void loadAllSections (wxXmlNode *aDocument)
 
void loadDesignRules (wxXmlNode *aDesignRules)
 
void loadLayerDefs (wxXmlNode *aLayers)
 
void loadPlain (wxXmlNode *aPlain)
 
void loadSignals (wxXmlNode *aSignals)
 
void loadLibrary (wxXmlNode *aLib, const wxString *aLibName)
 Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries" element (if a *.brd file) or under a "drawing" element if a *.lbr file. More...
 
void loadLibraries (wxXmlNode *aLibs)
 
void loadElements (wxXmlNode *aElements)
 
ZONE_CONTAINERloadPolygon (wxXmlNode *aPolyNode)
 Loads a copper or keepout polygon and adds it to the board. More...
 
void orientModuleAndText (MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
 
void orientModuleText (MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
 
void centerBoard ()
 move the BOARD into the center of the page More...
 
wxString fmtDEG (double aAngle) const
 Function fmtDEG formats an angle in a way particular to a board file format. More...
 
MODULEmakeModule (wxXmlNode *aPackage, const wxString &aPkgName) const
 Function makeModule creates a MODULE from an Eagle package. More...
 
void packageWire (MODULE *aModule, wxXmlNode *aTree) const
 
void packagePad (MODULE *aModule, wxXmlNode *aTree) const
 
void packageText (MODULE *aModule, wxXmlNode *aTree) const
 
void packageRectangle (MODULE *aModule, wxXmlNode *aTree) const
 
void packagePolygon (MODULE *aModule, wxXmlNode *aTree) const
 
void packageCircle (MODULE *aModule, wxXmlNode *aTree) const
 
void packageHole (MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
 Function packageHole aModule - The KiCad module to which to assign the hole aTree - The Eagle XML node that is of type "hole" aCenter - If true, center the hole in the module and offset the module position. More...
 
void packageSMD (MODULE *aModule, wxXmlNode *aTree) const
 
void transferPad (const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
 

Handles common pad properties

More...
 
void deleteTemplates ()
 

Deletes the footprint templates list

More...
 

Static Private Member Functions

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

Private Attributes

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

Detailed Description

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

Definition at line 109 of file eagle_plugin.h.

Member Typedef Documentation

typedef int EAGLE_PLUGIN::BIU

Definition at line 153 of file eagle_plugin.h.

typedef ELAYERS::const_iterator EAGLE_PLUGIN::EITER
private

Definition at line 160 of file eagle_plugin.h.

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

Definition at line 159 of file eagle_plugin.h.

Constructor & Destructor Documentation

EAGLE_PLUGIN::EAGLE_PLUGIN ( )

Definition at line 175 of file eagle_plugin.cpp.

References clear_cu_map(), and init().

175  :
176  m_rules( new ERULES() ),
177  m_xpath( new XPATH() ),
178  m_mod_time( wxDateTime::Now() )
179 {
180  init( NULL );
181  clear_cu_map();
182 }
void clear_cu_map()
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:112
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
wxDateTime m_mod_time
Definition: eagle_plugin.h:186
EAGLE_PLUGIN::~EAGLE_PLUGIN ( )

Definition at line 185 of file eagle_plugin.cpp.

References deleteTemplates(), m_rules, and m_xpath.

186 {
187  deleteTemplates();
188  delete m_rules;
189  delete m_xpath;
190 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
void deleteTemplates()
Deletes the footprint templates list

Member Function Documentation

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

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

Definition at line 2282 of file eagle_plugin.cpp.

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

Referenced by FootprintEnumerate(), and FootprintLoad().

2283 {
2284  try
2285  {
2286  wxDateTime modtime = getModificationTime( aLibPath );
2287 
2288  // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
2289  // cache if either of the wxDateTime objects are invalid or the last file modification
2290  // time differs from the current file modification time.
2291  bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
2292 
2293  if( aLibPath != m_lib_path || load )
2294  {
2295  wxXmlNode* doc;
2296  LOCALE_IO toggle; // toggles on, then off, the C locale.
2297 
2298  deleteTemplates();
2299 
2300  // Set this before completion of loading, since we rely on it for
2301  // text of an exception. Delay setting m_mod_time until after successful load
2302  // however.
2303  m_lib_path = aLibPath;
2304 
2305  // 8 bit "filename" should be encoded according to disk filename encoding,
2306  // (maybe this is current locale, maybe not, its a filesystem issue),
2307  // and is not necessarily utf8.
2308  string filename = (const char*) aLibPath.char_str( wxConvFile );
2309 
2310  // Load the document
2311  wxXmlDocument xmlDocument;
2312  wxFileName fn( filename );
2313 
2314  if( !xmlDocument.Load( fn.GetFullPath() ) )
2315  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
2316  fn.GetFullPath() ) );
2317 
2318  doc = xmlDocument.GetRoot();
2319 
2320  wxXmlNode* drawing = MapChildren( doc )["drawing"];
2321  NODE_MAP drawingChildren = MapChildren( drawing );
2322 
2323  // clear the cu map and then rebuild it.
2324  clear_cu_map();
2325 
2326  m_xpath->push( "eagle.drawing.layers" );
2327  wxXmlNode* layers = drawingChildren["layers"];
2328  loadLayerDefs( layers );
2329  m_xpath->pop();
2330 
2331  m_xpath->push( "eagle.drawing.library" );
2332  wxXmlNode* library = drawingChildren["library"];
2333  loadLibrary( library, NULL );
2334  m_xpath->pop();
2335 
2336  m_mod_time = modtime;
2337  }
2338  }
2339  catch(...){}
2340  // TODO: Handle exceptions
2341  // catch( file_parser_error fpe )
2342  // {
2343  // // for xml_parser_error, what() has the line number in it,
2344  // // but no byte offset. That should be an adequate error message.
2345  // THROW_IO_ERROR( fpe.what() );
2346  // }
2347  //
2348  // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
2349  // // so one catch should be OK for all errors.
2350  // catch( ptree_error pte )
2351  // {
2352  // string errmsg = pte.what();
2353  //
2354  // errmsg += " @\n";
2355  // errmsg += m_xpath->Contents();
2356  //
2357  // THROW_IO_ERROR( errmsg );
2358  // }
2359 }
void clear_cu_map()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:180
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
void loadLayerDefs(wxXmlNode *aLayers)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
wxString m_lib_path
Definition: eagle_plugin.h:185
#define THROW_IO_ERROR(msg)
static wxDateTime getModificationTime(const wxString &aPath)
get a file&#39;s or dir&#39;s modification time.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxDateTime m_mod_time
Definition: eagle_plugin.h:186
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
void deleteTemplates()
Deletes the footprint templates list
void pop()
Definition: eagle_parser.h:124
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void EAGLE_PLUGIN::centerBoard ( )
private

move the BOARD into the center of the page

Definition at line 2240 of file eagle_plugin.cpp.

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

Referenced by Load().

2241 {
2242  if( m_props )
2243  {
2244  UTF8 page_width;
2245  UTF8 page_height;
2246 
2247  if( m_props->Value( "page_width", &page_width ) &&
2248  m_props->Value( "page_height", &page_height ) )
2249  {
2251 
2252  int w = atoi( page_width.c_str() );
2253  int h = atoi( page_height.c_str() );
2254 
2255  int desired_x = ( w - bbbox.GetWidth() ) / 2;
2256  int desired_y = ( h - bbbox.GetHeight() ) / 2;
2257 
2258  DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
2259  bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
2260 
2261  m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
2262  }
2263  }
2264 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:179
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
int GetHeight() const
Definition: eda_rect.h:118
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:810
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:178
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
const char * c_str() const
Definition: utf8.h:107
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetX() const
Definition: eda_rect.h:109
int GetWidth() const
Definition: eda_rect.h:117
int GetY() const
Definition: eda_rect.h:110
#define DBG(x)
Definition: fctsys.h:33
void EAGLE_PLUGIN::clear_cu_map ( )
private

Definition at line 319 of file eagle_plugin.cpp.

References arrayDim(), i, and m_cu_map.

Referenced by cacheLib(), and EAGLE_PLUGIN().

320 {
321  // All cu layers are invalid until we see them in the <layers> section while
322  // loading either a board or library. See loadLayerDefs().
323  for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
324  m_cu_map[i] = -1;
325 }
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:162
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
size_t i
Definition: json11.cpp:597
void EAGLE_PLUGIN::deleteTemplates ( )
private

Deletes the footprint templates list

Definition at line 1917 of file eagle_plugin.cpp.

References m_templates.

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

1918 {
1919  for( auto& t : m_templates )
1920  delete t.second;
1921 
1922  m_templates.clear();
1923 }
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:173
const wxString & EAGLE_PLUGIN::eagle_layer_name ( int  aLayer) const
private

Get Eagle layer name by its number.

Definition at line 2232 of file eagle_plugin.cpp.

References m_eagleLayers.

Referenced by kicad_layer().

2233 {
2234  static const wxString unknown( "unknown" );
2235  auto it = m_eagleLayers.find( aLayer );
2236  return it == m_eagleLayers.end() ? unknown : it->second.name;
2237 }
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:163
wxString EAGLE_PLUGIN::fmtDEG ( double  aAngle) const
private

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

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

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

Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.

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

Reimplemented in GITHUB_PLUGIN, PCB_IO, and GPCB_PLUGIN.

Definition at line 101 of file plugin.cpp.

References not_implemented().

Referenced by FP_LIB_TABLE::FootprintDelete().

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

Return a list of footprint names contained within the library at aLibraryPath.

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

Reimplemented from PLUGIN.

Definition at line 2362 of file eagle_plugin.cpp.

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

2364 {
2365  init( aProperties );
2366 
2367  cacheLib( aLibraryPath );
2368 
2369  for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
2370  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
2371 }
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:173
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 109 of file plugin.cpp.

References not_implemented().

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

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

References not_implemented().

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

117 {
118  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
119  not_implemented( this, __FUNCTION__ );
120  return false;
121 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: plugin.cpp:38
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 2391 of file eagle_plugin.cpp.

References PLUGIN::FootprintLibOptions().

2392 {
2393  PLUGIN::FootprintLibOptions( aListToAppendTo );
2394 
2395  /*
2396  (*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
2397  "Ignore duplicately named footprints within the same Eagle library. "
2398  "Only the first similarly named footprint will be loaded."
2399  ));
2400  */
2401 }
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:132
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 2374 of file eagle_plugin.cpp.

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

2376 {
2377  init( aProperties );
2378  cacheLib( aLibraryPath );
2379  MODULE_CITER mi = m_templates.find( aFootprintName );
2380 
2381  if( mi == m_templates.end() )
2382  return NULL;
2383 
2384  // copy constructor to clone the template
2385  MODULE* ret = new MODULE( *mi->second );
2386 
2387  return ret;
2388 }
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:173
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 93 of file plugin.cpp.

References not_implemented().

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

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

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

Reimplemented in PCB_IO, and GPCB_PLUGIN.

Definition at line 75 of file plugin.cpp.

References PLUGIN::FootprintLoad().

Referenced by FP_LIB_TABLE::GetEnumeratedFootprint(), and FOOTPRINT_EDIT_FRAME::SaveLibraryAs().

78 {
79  // default implementation
80  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
81 }
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:84
const wxString EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 199 of file eagle_plugin.cpp.

200 {
201  return wxT( "brd" );
202 }
long long EAGLE_PLUGIN::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
inlineoverridevirtual

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

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

Implements PLUGIN.

Definition at line 127 of file eagle_plugin.h.

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

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

Definition at line 2267 of file eagle_plugin.cpp.

Referenced by cacheLib().

2268 {
2269  // File hasn't been loaded yet.
2270  if( aPath.IsEmpty() )
2271  return wxDateTime::Now();
2272 
2273  wxFileName fn( aPath );
2274 
2275  if( fn.IsFileReadable() )
2276  return fn.GetModificationTime();
2277  else
2278  return wxDateTime( 0.0 );
2279 }
void EAGLE_PLUGIN::init ( const PROPERTIES aProperties)
private

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

Definition at line 301 of file eagle_plugin.cpp.

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

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

302 {
303  m_hole_count = 0;
304  m_min_trace = 0;
305  m_min_via = 0;
306  m_min_via_hole = 0;
307  m_xpath->clear();
308  m_pads_to_nets.clear();
309 
310  m_board = NULL;
311  m_props = aProperties;
312 
313 
314  delete m_rules;
315  m_rules = new ERULES();
316 }
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:179
void clear()
Definition: eagle_parser.h:122
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:182
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:183
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:178
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:181
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:169
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:171
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 132 of file eagle_plugin.h.

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

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

Definition at line 205 of file eagle_plugin.cpp.

References ECOORD::ToPcbUnits().

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

206 {
207  // texts seem to better match eagle when scaled down by 0.95
208  int kz = d.ToPcbUnits() * 95 / 100;
209  return wxSize( kz, kz );
210 }
int ToPcbUnits() const
Definition: eagle_parser.h:439
PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer ( int  aLayer) const
private

Convert an Eagle layer to a KiCad layer.

Definition at line 2163 of file eagle_plugin.cpp.

References arrayDim(), B_Adhes, B_Fab, B_Mask, B_Paste, B_SilkS, EAGLE_LAYER::BCREAM, EAGLE_LAYER::BDOCU, EAGLE_LAYER::BFINISH, EAGLE_LAYER::BGLUE, EAGLE_LAYER::BKEEPOUT, EAGLE_LAYER::BNAMES, EAGLE_LAYER::BPLACE, EAGLE_LAYER::BSTOP, EAGLE_LAYER::BTEST, EAGLE_LAYER::BVALUES, Cmts_User, EAGLE_LAYER::DIMENSION, EAGLE_LAYER::DOCUMENT, Dwgs_User, eagle_layer_name(), Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Fab, F_Mask, F_Paste, F_SilkS, Format(), EAGLE_LAYER::HOLES, m_cu_map, EAGLE_LAYER::MILLING, EAGLE_LAYER::REFERENCELC, EAGLE_LAYER::REFERENCELS, EAGLE_LAYER::TCREAM, EAGLE_LAYER::TDOCU, EAGLE_LAYER::TFINISH, EAGLE_LAYER::TGLUE, EAGLE_LAYER::TKEEPOUT, EAGLE_LAYER::TNAMES, EAGLE_LAYER::TPLACE, EAGLE_LAYER::TSTOP, EAGLE_LAYER::TTEST, EAGLE_LAYER::TVALUES, EAGLE_LAYER::UNROUTED, EAGLE_LAYER::USERLAYER1, and EAGLE_LAYER::USERLAYER2.

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

2164 {
2165  int kiLayer;
2166 
2167  // eagle copper layer:
2168  if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
2169  {
2170  kiLayer = m_cu_map[aEagleLayer];
2171  }
2172 
2173  else
2174  {
2175  // translate non-copper eagle layer to pcbnew layer
2176  switch( aEagleLayer )
2177  {
2178  // Eagle says "Dimension" layer, but it's for board perimeter
2179  case EAGLE_LAYER::MILLING: kiLayer = Edge_Cuts; break;
2180  case EAGLE_LAYER::DIMENSION: kiLayer = Edge_Cuts; break;
2181 
2182  case EAGLE_LAYER::TPLACE: kiLayer = F_SilkS; break;
2183  case EAGLE_LAYER::BPLACE: kiLayer = B_SilkS; break;
2184  case EAGLE_LAYER::TNAMES: kiLayer = F_SilkS; break;
2185  case EAGLE_LAYER::BNAMES: kiLayer = B_SilkS; break;
2186  case EAGLE_LAYER::TVALUES: kiLayer = F_Fab; break;
2187  case EAGLE_LAYER::BVALUES: kiLayer = B_Fab; break;
2188  case EAGLE_LAYER::TSTOP: kiLayer = F_Mask; break;
2189  case EAGLE_LAYER::BSTOP: kiLayer = B_Mask; break;
2190  case EAGLE_LAYER::TCREAM: kiLayer = F_Paste; break;
2191  case EAGLE_LAYER::BCREAM: kiLayer = B_Paste; break;
2192  case EAGLE_LAYER::TFINISH: kiLayer = F_Mask; break;
2193  case EAGLE_LAYER::BFINISH: kiLayer = B_Mask; break;
2194  case EAGLE_LAYER::TGLUE: kiLayer = F_Adhes; break;
2195  case EAGLE_LAYER::BGLUE: kiLayer = B_Adhes; break;
2196  case EAGLE_LAYER::DOCUMENT: kiLayer = Cmts_User; break;
2197  case EAGLE_LAYER::REFERENCELC: kiLayer = Cmts_User; break;
2198  case EAGLE_LAYER::REFERENCELS: kiLayer = Cmts_User; break;
2199 
2200  // Packages show the future chip pins on SMD parts using layer 51.
2201  // This is an area slightly smaller than the PAD/SMD copper area.
2202  // Carry those visual aids into the MODULE on the fabrication layer,
2203  // not silkscreen. This is perhaps not perfect, but there is not a lot
2204  // of other suitable paired layers
2205  case EAGLE_LAYER::TDOCU: kiLayer = F_Fab; break;
2206  case EAGLE_LAYER::BDOCU: kiLayer = B_Fab; break;
2207 
2208  // thes layers are defined as user layers. put them on ECO layers
2209  case EAGLE_LAYER::USERLAYER1: kiLayer = Eco1_User; break;
2210  case EAGLE_LAYER::USERLAYER2: kiLayer = Eco2_User; break;
2211 
2212  case EAGLE_LAYER::UNROUTED:
2213  case EAGLE_LAYER::TKEEPOUT:
2214  case EAGLE_LAYER::BKEEPOUT:
2215  case EAGLE_LAYER::TTEST:
2216  case EAGLE_LAYER::BTEST:
2217  case EAGLE_LAYER::HOLES:
2218  default:
2219  // some layers do not map to KiCad
2220  wxLogMessage( wxString::Format( _( "Unsupported Eagle layer '%s' (%d), converted to Dwgs.User layer" ),
2221  eagle_layer_name( aEagleLayer ), aEagleLayer ) );
2222 
2223  kiLayer = Dwgs_User;
2224  break;
2225  }
2226  }
2227 
2228  return PCB_LAYER_ID( kiLayer );
2229 }
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:162
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
PCB_LAYER_ID
A quick note on layer IDs:
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int EAGLE_PLUGIN::kicad_x ( const ECOORD x) const
inlineprivate
int EAGLE_PLUGIN::kicad_y ( const ECOORD y) const
inlineprivate

Convert an Eagle distance to a KiCad distance.

Definition at line 194 of file eagle_plugin.h.

References ECOORD::ToPcbUnits().

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

194 { return -y.ToPcbUnits(); }
int ToPcbUnits() const
Definition: eagle_parser.h:439
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 213 of file eagle_plugin.cpp.

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

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

Definition at line 328 of file eagle_plugin.cpp.

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

Referenced by Load().

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

Definition at line 378 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

379 {
380  if( aDesignRules )
381  {
382  m_xpath->push( "designrules" );
383  m_rules->parse( aDesignRules );
384  m_xpath->pop(); // "designrules"
385  }
386 }
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
void parse(wxXmlNode *aRules)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
void pop()
Definition: eagle_parser.h:124
void EAGLE_PLUGIN::loadElements ( wxXmlNode *  aElements)
private

Definition at line 847 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

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

Definition at line 389 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadAllSections().

390 {
391  if( !aLayers )
392  return;
393 
394  ELAYERS cu; // copper layers
395 
396  // Get the first layer and iterate
397  wxXmlNode* layerNode = aLayers->GetChildren();
398 
399  m_eagleLayers.clear();
400 
401  while( layerNode )
402  {
403  ELAYER elayer( layerNode );
404  m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
405 
406  // find the subset of layers that are copper and active
407  if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
408  {
409  cu.push_back( elayer );
410  }
411 
412  layerNode = layerNode->GetNext();
413  }
414 
415  // establish cu layer map:
416  int ki_layer_count = 0;
417 
418  for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
419  {
420  if( ki_layer_count == 0 )
421  m_cu_map[it->number] = F_Cu;
422  else if( ki_layer_count == int( cu.size()-1 ) )
423  m_cu_map[it->number] = B_Cu;
424  else
425  {
426  // some eagle boards do not have contiguous layer number sequences.
427 
428 #if 0 // pre PCB_LAYER_ID & LSET:
429  m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
430 #else
431  m_cu_map[it->number] = ki_layer_count;
432 #endif
433  }
434  }
435 
436 #if 0 && defined(DEBUG)
437  printf( "m_cu_map:\n" );
438  for( unsigned i=0; i<arrayDim(m_cu_map); ++i )
439  {
440  printf( "\t[%d]:%d\n", i, m_cu_map[i] );
441  }
442 #endif
443 
444  // Set the layer names and cu count iff we're loading a board.
445  if( m_board )
446  {
447  m_board->SetCopperLayerCount( cu.size() );
448 
449  for( EITER it = cu.begin(); it != cu.end(); ++it )
450  {
451  PCB_LAYER_ID layer = kicad_layer( it->number );
452 
453  // these function provide their own protection against UNDEFINED_LAYER:
454  m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
455  m_board->SetLayerType( layer, LT_SIGNAL );
456 
457  // could map the colors here
458  }
459  }
460 }
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:179
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:162
PCB_LAYER_ID
A quick note on layer IDs:
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:163
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:159
size_t i
Definition: json11.cpp:597
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:160
void EAGLE_PLUGIN::loadLibraries ( wxXmlNode *  aLibs)
private

Definition at line 824 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

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

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

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

Definition at line 764 of file eagle_plugin.cpp.

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

Referenced by cacheLib(), and loadLibraries().

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

Definition at line 463 of file eagle_plugin.cpp.

References abs, BOARD::Add(), ADD_APPEND, DIMENSION::AdjustDimensionDetails(), ETEXT::align, ZONE_CONTAINER::AppendCorner(), ETEXT::BOTTOM_CENTER, ETEXT::BOTTOM_LEFT, ETEXT::BOTTOM_RIGHT, ETEXT::CENTER, ETEXT::CENTER_LEFT, ETEXT::CENTER_RIGHT, ConvertArcCenter(), EWIRE::curve, DEFAULT_PCB_EDGE_THICKNESS, EROT::degrees, ZONE_CONTAINER::DIAGONAL_EDGE, EDIMENSION::dimensionType, EagleTimeStamp(), Format(), FROM_UTF8(), ZONE_CONTAINER::GetDefaultHatchPitch(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetLineThickness(), ZONE_CONTAINER::GetPosition(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, IsCopperLayer(), kicad_fontz(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, ECIRCLE::layer, ERECT::layer, EDIMENSION::layer, ETEXT::layer, loadPolygon(), m_board, m_hole_count, m_xpath, MILLIMETRES, EROT::mirror, packageHole(), XPATH::pop(), XPATH::push(), ECIRCLE::radius, ETEXT::ratio, MODULE::Reference(), ERECT::rot, ETEXT::rot, ZONE_CONTAINER::Rotate(), S_ARC, S_CIRCLE, DRAWSEGMENT::SetAngle(), DRAWSEGMENT::SetEnd(), DIMENSION::SetEnd(), ZONE_CONTAINER::SetHatch(), DIMENSION::SetHeight(), EDA_TEXT::SetHorizJustify(), DIMENSION::SetLayer(), BOARD_ITEM::SetLayer(), ZONE_CONTAINER::SetLayer(), EDA_TEXT::SetMirrored(), BOARD_CONNECTED_ITEM::SetNetCode(), DIMENSION::SetOrigin(), MODULE::SetReference(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetStart(), EDA_TEXT::SetText(), TEXTE_PCB::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_ITEM::SetTimeStamp(), DIMENSION::SetUnits(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), DRAWSEGMENT::SetWidth(), DIMENSION::SetWidth(), sign(), ETEXT::size, EROT::spin, DIMENSION::Text(), ETEXT::text, ETEXT::TOP_CENTER, ETEXT::TOP_LEFT, ETEXT::TOP_RIGHT, ECOORD::ToPcbUnits(), NETINFO_LIST::UNCONNECTED, UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, ETEXT::x, EWIRE::x1, ERECT::x1, EDIMENSION::x1, EWIRE::x2, ERECT::x2, EDIMENSION::x2, EDIMENSION::x3, ECIRCLE::y, ETEXT::y, EWIRE::y1, ERECT::y1, EDIMENSION::y1, EWIRE::y2, ERECT::y2, EDIMENSION::y2, and EDIMENSION::y3.

Referenced by loadAllSections().

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

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

Returns
The loaded zone or nullptr if was not processed.

Definition at line 1076 of file eagle_plugin.cpp.

References BOARD::Add(), ADD_APPEND, PNS::angle(), ZONE_CONTAINER::AppendCorner(), ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF, B_Cu, EAGLE_LAYER::BRESTRICT, ConvertArcCenter(), EVERTEX::curve, EPOLYGON::CUTOUT, DEG2RAD(), ZONE_CONTAINER::DIAGONAL_EDGE, EagleTimeStamp(), F_Cu, GetArcToSegmentCount(), ZONE_CONTAINER::GetDefaultHatchPitch(), i, IsCopperLayer(), EPOLYGON::isolate, IU_PER_MILS, kicad_layer(), kicad_x(), kicad_y(), KiROUND(), EPOLYGON::layer, m_board, max, EPOLYGON::max_priority, ZONE_CONTAINER::NO_HATCH, PAD_ZONE_CONN_FULL, PAD_ZONE_CONN_THERMAL, EPOLYGON::pour, EPOLYGON::rank, ZONE_CONTAINER::SetArcSegmentCount(), ZONE_CONTAINER::SetDoNotAllowCopperPour(), ZONE_CONTAINER::SetDoNotAllowTracks(), ZONE_CONTAINER::SetDoNotAllowVias(), ZONE_CONTAINER::SetHatch(), ZONE_CONTAINER::SetHatchStyle(), ZONE_CONTAINER::SetIsKeepout(), ZONE_CONTAINER::SetLayer(), ZONE_CONTAINER::SetMinThickness(), ZONE_CONTAINER::SetPadConnection(), ZONE_CONTAINER::SetPriority(), ZONE_CONTAINER::SetThermalReliefCopperBridge(), ZONE_CONTAINER::SetThermalReliefGap(), EDA_ITEM::SetTimeStamp(), ZONE_CONTAINER::SetZoneClearance(), EPOLYGON::spacing, EPOLYGON::thermals, ECOORD::ToPcbUnits(), EAGLE_LAYER::TRESTRICT, EPOLYGON::width, EVERTEX::x, EVERTEX::y, and ZONE_THICKNESS_MIN_VALUE_MIL.

Referenced by loadPlain(), and loadSignals().

1077 {
1078  EPOLYGON p( aPolyNode );
1079  PCB_LAYER_ID layer = kicad_layer( p.layer );
1080  ZONE_CONTAINER* zone = nullptr;
1081  bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT || p.layer == EAGLE_LAYER::BRESTRICT );
1082 
1083  if( !IsCopperLayer( layer ) && !keepout )
1084  return nullptr;
1085 
1086  // use a "netcode = 0" type ZONE:
1087  zone = new ZONE_CONTAINER( m_board );
1088  zone->SetTimeStamp( EagleTimeStamp( aPolyNode ) );
1089  m_board->Add( zone, ADD_APPEND );
1090 
1091  if( p.layer == EAGLE_LAYER::TRESTRICT ) // front layer keepout
1092  zone->SetLayer( F_Cu );
1093  else if( p.layer == EAGLE_LAYER::BRESTRICT ) // bottom layer keepout
1094  zone->SetLayer( B_Cu );
1095  else
1096  zone->SetLayer( layer );
1097 
1098  if( keepout )
1099  {
1100  zone->SetIsKeepout( true );
1101  zone->SetDoNotAllowVias( true );
1102  zone->SetDoNotAllowTracks( true );
1103  zone->SetDoNotAllowCopperPour( true );
1104  }
1105 
1106  // Get the first vertex and iterate
1107  wxXmlNode* vertex = aPolyNode->GetChildren();
1108  std::vector<EVERTEX> vertices;
1109 
1110  // Create a circular vector of vertices
1111  // The "curve" parameter indicates a curve from the current
1112  // to the next vertex, so we keep the first at the end as well
1113  // to allow the curve to link back
1114  while( vertex )
1115  {
1116  if( vertex->GetName() == "vertex" )
1117  vertices.push_back( EVERTEX( vertex ) );
1118 
1119  vertex = vertex->GetNext();
1120  }
1121 
1122  vertices.push_back( vertices[0] );
1123 
1124  for( size_t i = 0; i < vertices.size() - 1; i++ )
1125  {
1126  EVERTEX v1 = vertices[i];
1127 
1128  // Append the corner
1129  zone->AppendCorner( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ), -1 );
1130 
1131  if( v1.curve )
1132  {
1133  EVERTEX v2 = vertices[i + 1];
1134  wxPoint center = ConvertArcCenter(
1135  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1136  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1137  double angle = DEG2RAD( *v1.curve );
1138  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1139  kicad_x( v2.x ) - center.x );
1140  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1141  + pow( center.y - kicad_y( v1.y ), 2 ) );
1142 
1143  // If we are curving, we need at least 2 segments otherwise
1144  // delta_angle == angle
1145  double delta_angle = angle / std::max(
1146  2, GetArcToSegmentCount( KiROUND( radius ),
1147  ARC_HIGH_DEF, *v1.curve ) - 1 );
1148 
1149  for( double a = end_angle + angle;
1150  fabs( a - end_angle ) > fabs( delta_angle );
1151  a -= delta_angle )
1152  {
1153  zone->AppendCorner(
1154  wxPoint( KiROUND( radius * cos( a ) ),
1155  KiROUND( radius * sin( a ) ) ) + center,
1156  -1 );
1157  }
1158  }
1159  }
1160 
1161  // If the pour is a cutout it needs to be set to a keepout
1162  if( p.pour == EPOLYGON::CUTOUT )
1163  {
1164  zone->SetIsKeepout( true );
1165  zone->SetDoNotAllowCopperPour( true );
1167  }
1168 
1169  // if spacing is set the zone should be hatched
1170  // However, use the default hatch step, p.spacing value has no meaning for Kicad
1171  // TODO: see if this parameter is related to a grid fill option.
1172  if( p.spacing )
1174 
1175  // clearances, etc.
1176  zone->SetArcSegmentCount( ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF ); // @todo: should be a constructor default?
1177  zone->SetMinThickness( std::max<int>(
1178  ZONE_THICKNESS_MIN_VALUE_MIL*IU_PER_MILS, p.width.ToPcbUnits() ) );
1179 
1180  // FIXME: KiCad zones have very rounded corners compared to eagle.
1181  // This means that isolation amounts that work well in eagle
1182  // tend to make copper intrude in soldermask free areas around pads.
1183  if( p.isolate )
1184  zone->SetZoneClearance( p.isolate->ToPcbUnits() );
1185  else
1186  zone->SetZoneClearance( 1 ); // @todo: set minimum clearance value based on board settings
1187 
1188  // missing == yes per DTD.
1189  bool thermals = !p.thermals || *p.thermals;
1191 
1192  if( thermals )
1193  {
1194  // FIXME: eagle calculates dimensions for thermal spokes
1195  // based on what the zone is connecting to.
1196  // (i.e. width of spoke is half of the smaller side of an smd pad)
1197  // This is a basic workaround
1198  zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
1199  zone->SetThermalReliefCopperBridge( p.width.ToPcbUnits() + 50000 );
1200  }
1201 
1202  int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
1203  zone->SetPriority( rank );
1204 
1205  return zone;
1206 }
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:638
Eagle vertex.
Definition: eagle_parser.h:746
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:179
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
ECOORD y
Definition: eagle_parser.h:749
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:191
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:637
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:100
PCB_LAYER_ID
A quick note on layer IDs:
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:202
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:198
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:750
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:185
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:636
#define ZONE_THICKNESS_MIN_VALUE_MIL
Definition: zones.h:41
ECOORD x
Definition: eagle_parser.h:748
double DEG2RAD(double deg)
Definition: trigo.h:199
#define max(a, b)
Definition: auxiliary.h:86
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
#define IU_PER_MILS
Definition: plotter.cpp:134
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:531
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:757
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:635
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:201
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:204
#define ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF
Definition: pcbnew.h:42
Use thermal relief for pads.
Definition: zones.h:53
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:182
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
pads are covered by copper
Definition: zones.h:54
void EAGLE_PLUGIN::loadSignals ( wxXmlNode *  aSignals)
private

Definition at line 1926 of file eagle_plugin.cpp.

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

Referenced by loadAllSections().

1927 {
1928  ZONES zones; // per net
1929 
1930  m_xpath->push( "signals.signal", "name" );
1931 
1932  int netCode = 1;
1933 
1934  // Get the first signal and iterate
1935  wxXmlNode* net = aSignals->GetChildren();
1936 
1937  while( net )
1938  {
1939  bool sawPad = false;
1940 
1941  zones.clear();
1942 
1943  const wxString& netName = escapeName( net->GetAttribute( "name" ) );
1944  m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
1945 
1946  m_xpath->Value( netName.c_str() );
1947 
1948  // Get the first net item and iterate
1949  wxXmlNode* netItem = net->GetChildren();
1950 
1951  // (contactref | polygon | wire | via)*
1952  while( netItem )
1953  {
1954  const wxString& itemName = netItem->GetName();
1955 
1956  if( itemName == "wire" )
1957  {
1958  m_xpath->push( "wire" );
1959 
1960  EWIRE w( netItem );
1961  PCB_LAYER_ID layer = kicad_layer( w.layer );
1962 
1963  if( IsCopperLayer( layer ) )
1964  {
1965  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1966  double angle = 0.0;
1967  double end_angle = 0.0;
1968  double radius = 0.0;
1969  double delta_angle = 0.0;
1970  wxPoint center;
1971 
1972  int width = w.width.ToPcbUnits();
1973  if( width < m_min_trace )
1974  m_min_trace = width;
1975 
1976  if( w.curve )
1977  {
1978  center = ConvertArcCenter(
1979  wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
1980  wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
1981  *w.curve );
1982 
1983  angle = DEG2RAD( *w.curve );
1984 
1985  end_angle = atan2( kicad_y( w.y2 ) - center.y,
1986  kicad_x( w.x2 ) - center.x );
1987 
1988  radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
1989  pow( center.y - kicad_y( w.y1 ), 2 ) );
1990 
1991  // If we are curving, we need at least 2 segments otherwise
1992  // delta_angle == angle
1993  int segments = std::max( 2, GetArcToSegmentCount( KiROUND( radius ),
1994  ARC_HIGH_DEF, *w.curve ) - 1 );
1995  delta_angle = angle / segments;
1996  }
1997 
1998  while( fabs( angle ) > fabs( delta_angle ) )
1999  {
2000  wxASSERT( radius > 0.0 );
2001  wxPoint end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
2002  KiROUND( radius * sin( end_angle + angle ) + center.y ) );
2003 
2004  TRACK* t = new TRACK( m_board );
2005 
2006  t->SetTimeStamp( EagleTimeStamp( netItem ) + int( RAD2DEG( angle ) ) );
2007  t->SetPosition( start );
2008  t->SetEnd( end );
2009  t->SetWidth( width );
2010  t->SetLayer( layer );
2011  t->SetNetCode( netCode );
2012 
2013  m_board->m_Track.PushBack( t );
2014 
2015  start = end;
2016  angle -= delta_angle;
2017  }
2018 
2019  TRACK* t = new TRACK( m_board );
2020 
2021  t->SetTimeStamp( EagleTimeStamp( netItem ) );
2022  t->SetPosition( start );
2023  t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
2024  t->SetWidth( width );
2025  t->SetLayer( layer );
2026  t->SetNetCode( netCode );
2027 
2028  m_board->m_Track.PushBack( t );
2029  }
2030  else
2031  {
2032  // put non copper wires where the sun don't shine.
2033  }
2034 
2035  m_xpath->pop();
2036  }
2037 
2038  else if( itemName == "via" )
2039  {
2040  m_xpath->push( "via" );
2041  EVIA v( netItem );
2042 
2043  PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
2044  PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
2045 
2046  if( IsCopperLayer( layer_front_most ) &&
2047  IsCopperLayer( layer_back_most ) )
2048  {
2049  int kidiam;
2050  int drillz = v.drill.ToPcbUnits();
2051  VIA* via = new VIA( m_board );
2052  m_board->m_Track.PushBack( via );
2053 
2054  via->SetLayerPair( layer_front_most, layer_back_most );
2055 
2056  if( v.diam )
2057  {
2058  kidiam = v.diam->ToPcbUnits();
2059  via->SetWidth( kidiam );
2060  }
2061  else
2062  {
2063  double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
2064  annulus = eagleClamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
2065  kidiam = KiROUND( drillz + 2 * annulus );
2066  via->SetWidth( kidiam );
2067  }
2068 
2069  via->SetDrill( drillz );
2070 
2071  // make sure the via diameter respects the restring rules
2072 
2073  if( !v.diam || via->GetWidth() <= via->GetDrill() )
2074  {
2075  double annulus = eagleClamp( m_rules->rlMinViaOuter,
2076  (double)( via->GetWidth() / 2 - via->GetDrill() ), m_rules->rlMaxViaOuter );
2077  via->SetWidth( drillz + 2 * annulus );
2078  }
2079 
2080  if( kidiam < m_min_via )
2081  m_min_via = kidiam;
2082 
2083  if( drillz < m_min_via_hole )
2084  m_min_via_hole = drillz;
2085 
2086  if( layer_front_most == F_Cu && layer_back_most == B_Cu )
2087  via->SetViaType( VIA_THROUGH );
2088  else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
2089  via->SetViaType( VIA_MICROVIA );
2090  else
2091  via->SetViaType( VIA_BLIND_BURIED );
2092 
2093  via->SetTimeStamp( EagleTimeStamp( netItem ) );
2094 
2095  wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
2096 
2097  via->SetPosition( pos );
2098  via->SetEnd( pos );
2099 
2100  via->SetNetCode( netCode );
2101  }
2102 
2103  m_xpath->pop();
2104  }
2105 
2106  else if( itemName == "contactref" )
2107  {
2108  m_xpath->push( "contactref" );
2109  // <contactref element="RN1" pad="7"/>
2110 
2111  const wxString& reference = netItem->GetAttribute( "element" );
2112  const wxString& pad = netItem->GetAttribute( "pad" );
2113  wxString key = makeKey( reference, pad ) ;
2114 
2115  // D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, netName.c_str() );)
2116 
2117  m_pads_to_nets[ key ] = ENET( netCode, netName );
2118 
2119  m_xpath->pop();
2120 
2121  sawPad = true;
2122  }
2123 
2124  else if( itemName == "polygon" )
2125  {
2126  m_xpath->push( "polygon" );
2127  auto* zone = loadPolygon( netItem );
2128 
2129  if( zone )
2130  {
2131  zones.push_back( zone );
2132 
2133  if( !zone->GetIsKeepout() )
2134  zone->SetNetCode( netCode );
2135  }
2136 
2137  m_xpath->pop(); // "polygon"
2138  }
2139 
2140  netItem = netItem->GetNext();
2141  }
2142 
2143  if( zones.size() && !sawPad )
2144  {
2145  // KiCad does not support an unconnected zone with its own non-zero netcode,
2146  // but only when assigned netcode = 0 w/o a name...
2147  for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
2148  (*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
2149 
2150  // therefore omit this signal/net.
2151  }
2152  else
2153  netCode++;
2154 
2155  // Get next signal
2156  net = net->GetNext();
2157  }
2158 
2159  m_xpath->pop(); // "signals.signal"
2160 }
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:71
static T eagleClamp(T aMin, T aValue, T aMax)
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:179
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:462
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:434
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:122
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void push(const char *aPathSegment, const char *aAttribute="")
Definition: eagle_parser.h:117
double RAD2DEG(double rad)
Definition: trigo.h:200
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:182
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:69
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:476
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:166
void SetWidth(int aWidth)
Definition: class_track.h:119
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 m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:183
static wxString makeKey(const wxString &aFirst, const wxString &aSecond)
Assemble a two part key as a simple concatenation of aFirst and aSecond parts, using a separator...
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
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...
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:181
Eagle net.
Definition: eagle_parser.h:462
Eagle via.
Definition: eagle_parser.h:556
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
double DEG2RAD(double deg)
Definition: trigo.h:199
#define max(a, b)
Definition: auxiliary.h:86
int GetWidth() const
Definition: class_track.h:120
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:116
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:469
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:171
Eagle wire.
Definition: eagle_parser.h:500
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
DLIST< TRACK > m_Track
Definition: class_board.h:250
void pop()
Definition: eagle_parser.h:124
std::vector< ZONE_CONTAINER * > ZONES
Definition: eagle_plugin.h:39
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:70
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:469
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
void Value(const char *aValue)
modify the last path node&#39;s value
Definition: eagle_parser.h:127
MODULE * EAGLE_PLUGIN::makeModule ( wxXmlNode *  aPackage,
const wxString &  aPkgName 
) const
private

Function makeModule creates a MODULE from an Eagle package.

Definition at line 1339 of file eagle_plugin.cpp.

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

Referenced by loadLibrary().

1340 {
1341  std::unique_ptr<MODULE> m( new MODULE( m_board ) );
1342 
1343  LIB_ID fpID;
1344  fpID.Parse( aPkgName, LIB_ID::ID_PCB, true );
1345  m->SetFPID( fpID );
1346 
1347  // Get the first package item and iterate
1348  wxXmlNode* packageItem = aPackage->GetChildren();
1349 
1350  while( packageItem )
1351  {
1352  const wxString& itemName = packageItem->GetName();
1353 
1354  if( itemName == "description" )
1355  m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
1356 
1357  else if( itemName == "wire" )
1358  packageWire( m.get(), packageItem );
1359 
1360  else if( itemName == "pad" )
1361  packagePad( m.get(), packageItem );
1362 
1363  else if( itemName == "text" )
1364  packageText( m.get(), packageItem );
1365 
1366  else if( itemName == "rectangle" )
1367  packageRectangle( m.get(), packageItem );
1368 
1369  else if( itemName == "polygon" )
1370  packagePolygon( m.get(), packageItem );
1371 
1372  else if( itemName == "circle" )
1373  packageCircle( m.get(), packageItem );
1374 
1375  else if( itemName == "hole" )
1376  packageHole( m.get(), packageItem, false );
1377 
1378  else if( itemName == "smd" )
1379  packageSMD( m.get(), packageItem );
1380 
1381  packageItem = packageItem->GetNext();
1382  }
1383 
1384  return m.release();
1385 }
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:179
void packageText(MODULE *aModule, wxXmlNode *aTree) const
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void packageHole(MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
Function packageHole aModule - The KiCad module to which to assign the hole aTree - The Eagle XML n...
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
void EAGLE_PLUGIN::orientModuleAndText ( MODULE m,
const EELEMENT e,
const EATTR nameAttr,
const EATTR valueAttr 
)
private

Definition at line 1209 of file eagle_plugin.cpp.

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

Referenced by loadElements().

1211 {
1212  if( e.rot )
1213  {
1214  if( e.rot->mirror )
1215  {
1216  double orientation = e.rot->degrees + 180.0;
1217  m->SetOrientation( orientation * 10 );
1218  m->Flip( m->GetPosition() );
1219  }
1220  else
1221  m->SetOrientation( e.rot->degrees * 10 );
1222  }
1223 
1224  orientModuleText( m, e, &m->Reference(), nameAttr );
1225  orientModuleText( m, e, &m->Value(), valueAttr );
1226 }
bool mirror
Definition: eagle_parser.h:481
TEXTE_MODULE & Reference()
Definition: class_module.h:512
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
opt_erot rot
Definition: eagle_parser.h:807
double degrees
Definition: eagle_parser.h:483
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:511
void SetOrientation(double newangle)
const wxPoint GetPosition() const override
Definition: class_module.h:183
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 1229 of file eagle_plugin.cpp.

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

Referenced by orientModuleAndText().

1231 {
1232  // Smashed part ?
1233  if( aAttr )
1234  { // Yes
1235  const EATTR& a = *aAttr;
1236 
1237  if( a.value )
1238  {
1239  txt->SetText( FROM_UTF8( a.value->c_str() ) );
1240  }
1241 
1242  if( a.x && a.y ) // OPT
1243  {
1244  wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
1245  txt->SetTextPos( pos );
1246  }
1247 
1248  // Even though size and ratio are both optional, I am not seeing
1249  // a case where ratio is present but size is not.
1250  double ratio = 8;
1251  wxSize fontz = txt->GetTextSize();
1252 
1253  if( a.size )
1254  {
1255  fontz = kicad_fontz( *a.size );
1256  txt->SetTextSize( fontz );
1257 
1258  if( a.ratio )
1259  ratio = *a.ratio;
1260  }
1261 
1262  int lw = int( fontz.y * ratio / 100 );
1263  txt->SetThickness( lw );
1264 
1265  int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1266 
1267  // The "rot" in a EATTR seems to be assumed to be zero if it is not
1268  // present, and this zero rotation becomes an override to the
1269  // package's text field. If they did not want zero, they specify
1270  // what they want explicitly.
1271  double degrees = a.rot ? a.rot->degrees : 0;
1272  double orient; // relative to parent
1273 
1274  int sign = 1;
1275  bool spin = false;
1276 
1277  if( a.rot )
1278  {
1279  spin = a.rot->spin;
1280  sign = a.rot->mirror ? -1 : 1;
1281  txt->SetMirrored( a.rot->mirror );
1282  }
1283 
1284  if( degrees == 90 || degrees == 0 || spin )
1285  {
1286  orient = degrees - m->GetOrientation() / 10;
1287  txt->SetTextAngle( sign * orient * 10 );
1288  }
1289  else if( degrees == 180 )
1290  {
1291  orient = 0 - m->GetOrientation() / 10;
1292  txt->SetTextAngle( sign * orient * 10 );
1293  align = ETEXT::TOP_RIGHT;
1294  }
1295  else if( degrees == 270 )
1296  {
1297  orient = 90 - m->GetOrientation() / 10;
1298  align = ETEXT::TOP_RIGHT;
1299  txt->SetTextAngle( sign * orient * 10 );
1300  }
1301  else
1302  {
1303  orient = 90 - degrees - m->GetOrientation() / 10;
1304  txt->SetTextAngle( sign * orient * 10 );
1305  }
1306 
1307  switch( align )
1308  {
1309  case ETEXT::TOP_RIGHT:
1312  break;
1313 
1314  case ETEXT::BOTTOM_LEFT:
1317  break;
1318 
1319  default:
1320  ;
1321  }
1322  }
1323  else // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
1324  {
1325  double degrees = ( txt->GetTextAngle() + m->GetOrientation() ) / 10;
1326 
1327  // @todo there are a few more cases than these to contend with:
1328  if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
1329  || ( txt->IsMirrored() && ( degrees == 360 ) ) )
1330  {
1331  // ETEXT::TOP_RIGHT:
1334  }
1335  }
1336 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:191
bool mirror
Definition: eagle_parser.h:481
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:236
double degrees
Definition: eagle_parser.h:483
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
#define abs(a)
Definition: auxiliary.h:84
opt_erot rot
Definition: eagle_parser.h:612
double GetTextAngle() const
Definition: eda_text.h:177
opt_ecoord y
Definition: eagle_parser.h:608
double GetOrientation() const
Definition: class_module.h:188
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
opt_wxString value
Definition: eagle_parser.h:606
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:603
opt_ecoord x
Definition: eagle_parser.h:607
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
bool IsMirrored() const
Definition: eda_text.h:192
opt_double ratio
Definition: eagle_parser.h:611
void SetTextAngle(double aAngle)
bool spin
Definition: eagle_parser.h:482
const wxSize & GetTextSize() const
Definition: eda_text.h:228
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
opt_ecoord size
Definition: eagle_parser.h:609
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
void EAGLE_PLUGIN::packageCircle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1736 of file eagle_plugin.cpp.

References B_CrtYd, B_SilkS, Cmts_User, DEFAULT_COURTYARD_WIDTH, DEFAULT_EDGE_WIDTH, DEFAULT_LINE_WIDTH, DEFAULT_SILK_LINE_WIDTH, EagleTimeStamp(), Edge_Cuts, F_CrtYd, F_SilkS, MODULE::GraphicalItemsList(), kicad_layer(), kicad_x(), kicad_y(), ECIRCLE::layer, DLIST< T >::PushBack(), ECIRCLE::radius, S_CIRCLE, EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), EDA_ITEM::SetTimeStamp(), DRAWSEGMENT::SetWidth(), ECOORD::ToPcbUnits(), UNDEFINED_LAYER, ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

Referenced by makeModule().

1737 {
1738  ECIRCLE e( aTree );
1739  PCB_LAYER_ID layer = kicad_layer( e.layer );
1740  EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
1741  int width = e.width.ToPcbUnits();
1742 
1743  if( width <= 0 )
1744  {
1745  switch( layer )
1746  {
1747  case Edge_Cuts:
1748  width = DEFAULT_EDGE_WIDTH;
1749  break;
1750  case F_SilkS:
1751  case B_SilkS:
1752  width = DEFAULT_SILK_LINE_WIDTH;
1753  break;
1754  case F_CrtYd:
1755  case B_CrtYd:
1756  width = DEFAULT_COURTYARD_WIDTH;
1757  break;
1758  default:
1759  width = DEFAULT_LINE_WIDTH;
1760  }
1761  }
1762 
1763  aModule->GraphicalItemsList().PushBack( gr );
1764  gr->SetWidth( width );
1765 
1766  switch ( (int) layer )
1767  {
1768  case UNDEFINED_LAYER:
1769  layer = Cmts_User;
1770  break;
1771  default:
1772  break;
1773  }
1774 
1775  gr->SetLayer( layer );
1776  gr->SetTimeStamp( EagleTimeStamp( aTree ) );
1777  gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
1778  gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
1779  gr->SetDrawCoord();
1780 }
#define DEFAULT_EDGE_WIDTH
void SetEnd0(const wxPoint &aPoint)
#define DEFAULT_COURTYARD_WIDTH
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.
#define DEFAULT_LINE_WIDTH
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
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:
#define DEFAULT_SILK_LINE_WIDTH
Eagle circle.
Definition: eagle_parser.h:571
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageHole ( MODULE aModule,
wxXmlNode *  aTree,
bool  aCenter 
) const
private

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

Definition at line 1783 of file eagle_plugin.cpp.

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

Referenced by loadPlain(), and makeModule().

1784 {
1785  EHOLE e( aTree );
1786 
1787  // we add a PAD_ATTRIB_HOLE_NOT_PLATED pad to this module.
1788  D_PAD* pad = new D_PAD( aModule );
1789  aModule->PadsList().PushBack( pad );
1790 
1791  pad->SetShape( PAD_SHAPE_CIRCLE );
1793 
1794  // Mechanical purpose only:
1795  // no offset, no net name, no pad name allowed
1796  // pad->SetOffset( wxPoint( 0, 0 ) );
1797  // pad->SetName( wxEmptyString );
1798 
1799  wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
1800 
1801  if( aCenter )
1802  {
1803  pad->SetPos0( wxPoint( 0, 0 ) );
1804  aModule->SetPosition( padpos );
1805  pad->SetPosition( padpos );
1806  }
1807  else
1808  {
1809  pad->SetPos0( padpos );
1810  pad->SetPosition( padpos + aModule->GetPosition() );
1811  }
1812 
1813  wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
1814 
1815  pad->SetDrillSize( sz );
1816  pad->SetSize( sz );
1817 
1818  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1819 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
Eagle hole element.
Definition: eagle_parser.h:786
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
void SetPosition(const wxPoint &aPos) override
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:408
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
const wxPoint GetPosition() const override
Definition: class_module.h:183
void EAGLE_PLUGIN::packagePad ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1445 of file eagle_plugin.cpp.

References LSET::AllCuMask(), B_Mask, EROT::degrees, EPAD::diameter, EPAD::drill, eagleClamp(), F_Mask, D_PAD::GetDrillSize(), D_PAD::GetShape(), D_PAD::GetSize(), KiROUND(), EPAD::LONG, m_rules, EPAD::OCTAGON, EPAD::OFFSET, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, MODULE::PadsList(), ERULES::psElongationLong, DLIST< T >::PushBack(), ERULES::rlMaxPadTop, ERULES::rlMinPadTop, EPAD_COMMON::rot, EPAD::ROUND, ERULES::rvPadTop, D_PAD::SetDrillSize(), D_PAD::SetLayerSet(), D_PAD::SetOrientation(), D_PAD::SetShape(), D_PAD::SetSize(), EPAD::shape, EPAD::SQUARE, ECOORD::ToPcbUnits(), and transferPad().

Referenced by makeModule().

1446 {
1447  // this is thru hole technology here, no SMDs
1448  EPAD e( aTree );
1449 
1450  D_PAD* pad = new D_PAD( aModule );
1451  aModule->PadsList().PushBack( pad );
1452  transferPad( e, pad );
1453 
1454  pad->SetDrillSize( wxSize( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() ) );
1455  pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
1456 
1457  if( e.shape )
1458  {
1459  switch( *e.shape )
1460  {
1461  case EPAD::ROUND:
1462  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1463  break;
1464 
1465  case EPAD::OCTAGON:
1466  // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
1467  // pad->SetShape( PAD_OCTAGON );
1468  wxASSERT( pad->GetShape() == PAD_SHAPE_CIRCLE ); // verify set in D_PAD constructor
1469  break;
1470 
1471  case EPAD::LONG:
1472  pad->SetShape( PAD_SHAPE_OVAL );
1473  break;
1474 
1475  case EPAD::SQUARE:
1476  pad->SetShape( PAD_SHAPE_RECT );
1477  break;
1478 
1479  case EPAD::OFFSET:
1480  ; // don't know what to do here.
1481  }
1482  }
1483  else
1484  {
1485  // if shape is not present, our default is circle and that matches their default "round"
1486  }
1487 
1488  if( e.diameter )
1489  {
1490  int diameter = e.diameter->ToPcbUnits();
1491  pad->SetSize( wxSize( diameter, diameter ) );
1492  }
1493  else
1494  {
1495  double drillz = pad->GetDrillSize().x;
1496  double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
1497  annulus = eagleClamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
1498  int diameter = KiROUND( drillz + 2 * annulus );
1499  pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
1500  }
1501 
1502  if( pad->GetShape() == PAD_SHAPE_OVAL )
1503  {
1504  // The Eagle "long" pad is wider than it is tall,
1505  // m_elongation is percent elongation
1506  wxSize sz = pad->GetSize();
1507  sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
1508  pad->SetSize( sz );
1509  }
1510 
1511  if( e.rot )
1512  {
1513  pad->SetOrientation( e.rot->degrees * 10 );
1514  }
1515 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
static T eagleClamp(T aMin, T aValue, T aMax)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:67
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Eagle thru hole pad.
Definition: eagle_parser.h:694
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:47
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:417
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:63
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:66
void EAGLE_PLUGIN::packagePolygon ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1659 of file eagle_plugin.cpp.

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

Referenced by makeModule().

1660 {
1661  EPOLYGON p( aTree );
1662  PCB_LAYER_ID layer = kicad_layer( p.layer );
1663  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1664 
1665  aModule->GraphicalItemsList().PushBack( dwg );
1666 
1667  dwg->SetWidth( 0 ); // it's filled, no need for boundary width
1668  dwg->SetLayer( layer );
1669  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1670 
1671  std::vector<wxPoint> pts;
1672  // TODO: I think there's no way to know a priori the number of children in wxXmlNode :()
1673  // pts.reserve( aTree.size() );
1674 
1675  // Get the first vertex and iterate
1676  wxXmlNode* vertex = aTree->GetChildren();
1677  std::vector<EVERTEX> vertices;
1678 
1679  // Create a circular vector of vertices
1680  // The "curve" parameter indicates a curve from the current
1681  // to the next vertex, so we keep the first at the end as well
1682  // to allow the curve to link back
1683  while( vertex )
1684  {
1685  if( vertex->GetName() == "vertex" )
1686  vertices.push_back( EVERTEX( vertex ) );
1687 
1688  vertex = vertex->GetNext();
1689  }
1690 
1691  vertices.push_back( vertices[0] );
1692 
1693  for( size_t i = 0; i < vertices.size() - 1; i++ )
1694  {
1695  EVERTEX v1 = vertices[i];
1696 
1697  // Append the corner
1698  pts.push_back( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ) );
1699 
1700  if( v1.curve )
1701  {
1702  EVERTEX v2 = vertices[i + 1];
1703  wxPoint center = ConvertArcCenter(
1704  wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
1705  wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
1706  double angle = DEG2RAD( *v1.curve );
1707  double end_angle = atan2( kicad_y( v2.y ) - center.y,
1708  kicad_x( v2.x ) - center.x );
1709  double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
1710  + pow( center.y - kicad_y( v1.y ), 2 ) );
1711 
1712  // If we are curving, we need at least 2 segments otherwise
1713  // delta_angle == angle
1714  double delta_angle = angle / std::max(
1715  2, GetArcToSegmentCount( KiROUND( radius ),
1716  ARC_HIGH_DEF, *v1.curve ) - 1 );
1717 
1718  for( double a = end_angle + angle;
1719  fabs( a - end_angle ) > fabs( delta_angle );
1720  a -= delta_angle )
1721  {
1722  pts.push_back(
1723  wxPoint( KiROUND( radius * cos( a ) ),
1724  KiROUND( radius * sin( a ) ) ) + center );
1725  }
1726  }
1727  }
1728 
1729  dwg->SetPolyPoints( pts );
1730  dwg->SetStart0( *pts.begin() );
1731  dwg->SetEnd0( pts.back() );
1732  dwg->SetDrawCoord();
1733 }
Eagle vertex.
Definition: eagle_parser.h:746
void SetEnd0(const wxPoint &aPoint)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
ECOORD y
Definition: eagle_parser.h:749
polygon (not yet used for tracks, but could be in microwave apps)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
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_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
opt_double curve
range is -359.9..359.9
Definition: eagle_parser.h:750
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
ECOORD x
Definition: eagle_parser.h:748
double DEG2RAD(double deg)
Definition: trigo.h:199
#define max(a, b)
Definition: auxiliary.h:86
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:757
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageRectangle ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1624 of file eagle_plugin.cpp.

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

Referenced by makeModule().

1625 {
1626  ERECT r( aTree );
1627  PCB_LAYER_ID layer = kicad_layer( r.layer );
1628  EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
1629 
1630  aModule->GraphicalItemsList().PushBack( dwg );
1631 
1632  dwg->SetLayer( layer );
1633  dwg->SetWidth( 0 );
1634 
1635  dwg->SetTimeStamp( EagleTimeStamp( aTree ) );
1636 
1637  std::vector<wxPoint> pts;
1638 
1639  wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
1640  wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
1641 
1642  pts.push_back( start );
1643  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
1644  pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
1645  pts.push_back( end );
1646 
1647  dwg->SetPolyPoints( pts );
1648 
1649  dwg->SetStart0( start );
1650  dwg->SetEnd0( end );
1651 
1652  if( r.rot )
1653  {
1654  dwg->Rotate( dwg->GetCenter(), r.rot->degrees * 10 );
1655  }
1656 }
void SetEnd0(const wxPoint &aPoint)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
const wxPoint GetCenter() const override
Function GetCenter()
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
polygon (not yet used for tracks, but could be in microwave apps)
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
PCB_LAYER_ID
A quick note on layer IDs:
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
Eagle XML rectangle in binary.
Definition: eagle_parser.h:584
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void SetStart0(const wxPoint &aPoint)
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
void SetWidth(int aWidth)
void EAGLE_PLUGIN::packageSMD ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1822 of file eagle_plugin.cpp.

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

Referenced by makeModule().

1823 {
1824  ESMD e( aTree );
1825  PCB_LAYER_ID layer = kicad_layer( e.layer );
1826 
1827  if( !IsCopperLayer( layer ) )
1828  return;
1829 
1830  D_PAD* pad = new D_PAD( aModule );
1831  aModule->PadsList().PushBack( pad );
1832  transferPad( e, pad );
1833 
1834  pad->SetShape( PAD_SHAPE_RECT );
1835  pad->SetAttribute( PAD_ATTRIB_SMD );
1836 
1837  wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
1838  pad->SetSize( padSize );
1839  pad->SetLayer( layer );
1840 
1841  const LSET front( 3, F_Cu, F_Paste, F_Mask );
1842  const LSET back( 3, B_Cu, B_Paste, B_Mask );
1843 
1844  if( layer == F_Cu )
1845  pad->SetLayerSet( front );
1846  else if( layer == B_Cu )
1847  pad->SetLayerSet( back );
1848 
1849  int minPadSize = std::min( padSize.x, padSize.y );
1850 
1851  // Rounded rectangle pads
1852  int roundRadius = eagleClamp( m_rules->srMinRoundness * 2,
1853  (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
1854 
1855  if( e.roundness || roundRadius > 0 )
1856  {
1857  double roundRatio = (double) roundRadius / minPadSize / 2.0;
1858 
1859  // Eagle uses a different definition of roundness, hence division by 200
1860  if( e.roundness )
1861  roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
1862 
1863  pad->SetShape( PAD_SHAPE_ROUNDRECT );
1864  pad->SetRoundRectRadiusRatio( roundRatio );
1865  }
1866 
1867  if( e.rot )
1868  {
1869  pad->SetOrientation( e.rot->degrees * 10 );
1870  }
1871 
1873  (int) ( m_rules->mvCreamFrame * minPadSize ),
1874  m_rules->mlMaxCreamFrame ) );
1875 
1876  // Solder paste (only for SMD pads)
1877  if( e.cream && *e.cream == false ) // enabled by default
1878  {
1879  if( layer == F_Cu )
1880  pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
1881  else if( layer == B_Cu )
1882  pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
1883  }
1884 }
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
static T eagleClamp(T aMin, T aValue, T aMax)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:60
Eagle SMD pad.
Definition: eagle_parser.h:715
void SetRoundRectRadiusRatio(double aRadiusScale)
has meaning only for rounded rect pads Set the scaling factor between the smaller Y or Y size and the...
Definition: class_pad.h:646
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:59
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:408
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:56
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:417
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_pad.h:421
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:57
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:61
#define min(a, b)
Definition: auxiliary.h:85
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:53
void EAGLE_PLUGIN::packageText ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1518 of file eagle_plugin.cpp.

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

Referenced by makeModule().

1519 {
1520  ETEXT t( aTree );
1521  PCB_LAYER_ID layer = kicad_layer( t.layer );
1522 
1523  if( layer == UNDEFINED_LAYER )
1524  {
1525  layer = Cmts_User;
1526  }
1527 
1528  TEXTE_MODULE* txt;
1529 
1530  if( t.text == ">NAME" || t.text == ">name" )
1531  txt = &aModule->Reference();
1532  else if( t.text == ">VALUE" || t.text == ">value" )
1533  txt = &aModule->Value();
1534  else
1535  {
1536  // FIXME: graphical text items are rotated for some reason.
1537  txt = new TEXTE_MODULE( aModule );
1538  aModule->GraphicalItemsList().PushBack( txt );
1539  }
1540 
1541  txt->SetTimeStamp( EagleTimeStamp( aTree ) );
1542  txt->SetText( FROM_UTF8( t.text.c_str() ) );
1543 
1544  wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
1545 
1546  txt->SetTextPos( pos );
1547  txt->SetPos0( pos - aModule->GetPosition() );
1548 
1549  txt->SetLayer( layer );
1550  txt->SetTextSize( kicad_fontz( t.size ) );
1551 
1552  double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
1553 
1554  txt->SetThickness( t.size.ToPcbUnits() * ratio / 100 );
1555 
1556  int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
1557 
1558  // An eagle package is never rotated, the DTD does not allow it.
1559  // angle -= aModule->GetOrienation();
1560 
1561  if( t.rot )
1562  {
1563  int sign = t.rot->mirror ? -1 : 1;
1564  txt->SetMirrored( t.rot->mirror );
1565 
1566  double degrees = t.rot->degrees;
1567 
1568  if( degrees == 90 || t.rot->spin )
1569  txt->SetTextAngle( sign * degrees * 10 );
1570  else if( degrees == 180 )
1571  align = ETEXT::TOP_RIGHT;
1572  else if( degrees == 270 )
1573  {
1574  align = ETEXT::TOP_RIGHT;
1575  txt->SetTextAngle( sign * 90 * 10 );
1576  }
1577  }
1578 
1579  switch( align )
1580  {
1581  case ETEXT::CENTER:
1582  // this was the default in pcbtxt's constructor
1583  break;
1584 
1585  case ETEXT::CENTER_LEFT:
1587  break;
1588 
1589  case ETEXT::CENTER_RIGHT:
1591  break;
1592 
1593  case ETEXT::TOP_CENTER:
1595  break;
1596 
1597  case ETEXT::TOP_LEFT:
1600  break;
1601 
1602  case ETEXT::TOP_RIGHT:
1605  break;
1606 
1607  case ETEXT::BOTTOM_CENTER:
1609  break;
1610 
1611  case ETEXT::BOTTOM_LEFT:
1614  break;
1615 
1616  case ETEXT::BOTTOM_RIGHT:
1619  break;
1620  }
1621 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:191
TEXTE_MODULE & Reference()
Definition: class_module.h:512
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
Eagle text element.
Definition: eagle_parser.h:646
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:511
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
timestamp_t EagleTimeStamp(wxXmlNode *aTree)
Make a unique time stamp
void SetPos0(const wxPoint &aPos)
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
void SetTextAngle(double aAngle)
const wxPoint GetPosition() const override
Definition: class_module.h:183
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
int sign(T val)
Definition: math_util.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
void EAGLE_PLUGIN::packageWire ( MODULE aModule,
wxXmlNode *  aTree 
) const
private

Definition at line 1388 of file eagle_plugin.cpp.

References B_CrtYd, B_SilkS, ConvertArcCenter(), EWIRE::curve, DEFAULT_COURTYARD_WIDTH, DEFAULT_EDGE_WIDTH, DEFAULT_LINE_WIDTH, DEFAULT_SILK_LINE_WIDTH, Edge_Cuts, F_CrtYd, F_SilkS, MODULE::GraphicalItemsList(), kicad_layer(), kicad_x(), kicad_y(), EWIRE::layer, DLIST< T >::PushBack(), S_ARC, S_SEGMENT, DRAWSEGMENT::SetAngle(), EDGE_MODULE::SetDrawCoord(), EDGE_MODULE::SetEnd0(), BOARD_ITEM::SetLayer(), EDGE_MODULE::SetStart0(), DRAWSEGMENT::SetWidth(), ECOORD::ToPcbUnits(), EWIRE::width, EWIRE::x1, EWIRE::x2, EWIRE::y1, and EWIRE::y2.

Referenced by makeModule().

1389 {
1390  EWIRE w( aTree );
1391  PCB_LAYER_ID layer = kicad_layer( w.layer );
1392  wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
1393  wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
1394  int width = w.width.ToPcbUnits();
1395 
1396  if( width <= 0 )
1397  {
1398  switch( layer )
1399  {
1400  case Edge_Cuts:
1401  width = DEFAULT_EDGE_WIDTH;
1402  break;
1403  case F_SilkS:
1404  case B_SilkS:
1405  width = DEFAULT_SILK_LINE_WIDTH;
1406  break;
1407  case F_CrtYd:
1408  case B_CrtYd:
1409  width = DEFAULT_COURTYARD_WIDTH;
1410  break;
1411  default:
1412  width = DEFAULT_LINE_WIDTH;
1413  }
1414  }
1415 
1416  // FIXME: the cap attribute is ignored because kicad can't create lines
1417  // with flat ends.
1418  EDGE_MODULE* dwg;
1419 
1420  if( !w.curve )
1421  {
1422  dwg = new EDGE_MODULE( aModule, S_SEGMENT );
1423 
1424  dwg->SetStart0( start );
1425  dwg->SetEnd0( end );
1426  }
1427  else
1428  {
1429  dwg = new EDGE_MODULE( aModule, S_ARC );
1430  wxPoint center = ConvertArcCenter( start, end, *w.curve );
1431 
1432  dwg->SetStart0( center );
1433  dwg->SetEnd0( start );
1434  dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
1435  }
1436 
1437  dwg->SetLayer( layer );
1438  dwg->SetWidth( width );
1439  dwg->SetDrawCoord();
1440 
1441  aModule->GraphicalItemsList().PushBack( dwg );
1442 }
#define DEFAULT_EDGE_WIDTH
void SetEnd0(const wxPoint &aPoint)
#define DEFAULT_COURTYARD_WIDTH
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.
#define DEFAULT_LINE_WIDTH
usual segment : line with rounded ends
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
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:
#define DEFAULT_SILK_LINE_WIDTH
Arcs (with rounded ends)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetStart0(const wxPoint &aPoint)
Eagle wire.
Definition: eagle_parser.h:500
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
void SetWidth(int aWidth)
const wxString EAGLE_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 193 of file eagle_plugin.cpp.

194 {
195  return wxT( "Eagle" );
196 }
void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

performing downloads). Does not parse. Threadsafe.

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

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

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

Reimplemented in GITHUB_PLUGIN.

Definition at line 68 of file plugin.cpp.

Referenced by FP_LIB_TABLE::PrefetchLib().

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

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

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

Reimplemented in PCB_IO, and CLIPBOARD_IO.

Definition at line 53 of file plugin.cpp.

References not_implemented().

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

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

Handles common pad properties

Definition at line 1887 of file eagle_plugin.cpp.

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

Referenced by packagePad(), and packageSMD().

1888 {
1889  aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) );
1890 
1891  // pad's "Position" is not relative to the module's,
1892  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1893  wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
1894  aPad->SetPos0( padPos );
1895 
1896  // Solder mask
1897  const wxSize& padSize( aPad->GetSize() );
1898 
1899  if( !aEaglePad.stop || !*aEaglePad.stop ) // enabled by default
1900  {
1902  (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
1903  m_rules->mlMaxStopFrame ) );
1904  }
1905 
1906  // Solid connection to copper zones
1907  if( aEaglePad.thermals && !*aEaglePad.thermals )
1909 
1910  MODULE* module = aPad->GetParent();
1911  wxCHECK( module, /* void */ );
1912  RotatePoint( &padPos, module->GetOrientation() );
1913  aPad->SetPosition( padPos + module->GetPosition() );
1914 }
static T eagleClamp(T aMin, T aValue, T aMax)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:165
MODULE * GetParent() const
Definition: class_pad.h:162
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
wxString name
Definition: eagle_parser.h:683
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:195
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
opt_bool thermals
Definition: eagle_parser.h:687
void SetZoneConnection(ZoneConnection aType)
Definition: class_pad.h:489
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
double GetOrientation() const
Definition: class_module.h:188
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:194
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_pad.h:415
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:52
opt_bool stop
Definition: eagle_parser.h:686
const wxPoint GetPosition() const override
Definition: class_module.h:183
#define min(a, b)
Definition: auxiliary.h:85
pads are covered by copper
Definition: zones.h:54
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55

Member Data Documentation

BOARD* EAGLE_PLUGIN::m_board
private

which BOARD is being worked on, no ownership here

Definition at line 179 of file eagle_plugin.h.

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

int EAGLE_PLUGIN::m_cu_map[17]
private

map eagle to kicad, cu layers only.

Definition at line 162 of file eagle_plugin.h.

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

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

Eagle layers data stored by the layer number.

Definition at line 163 of file eagle_plugin.h.

Referenced by eagle_layer_name(), and loadLayerDefs().

int EAGLE_PLUGIN::m_hole_count
private

generates unique module names from eagle "hole"s.

Definition at line 169 of file eagle_plugin.h.

Referenced by init(), and loadPlain().

wxString EAGLE_PLUGIN::m_lib_path
private

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

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

wxDateTime EAGLE_PLUGIN::m_mod_time
private

Definition at line 186 of file eagle_plugin.h.

Referenced by cacheLib().

NET_MAP EAGLE_PLUGIN::m_pads_to_nets
private

net list

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

Referenced by centerBoard(), and init().

ERULES* EAGLE_PLUGIN::m_rules
private

Eagle design rules.

Definition at line 165 of file eagle_plugin.h.

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

MODULE_MAP EAGLE_PLUGIN::m_templates
private

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

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

Definition at line 173 of file eagle_plugin.h.

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

XPATH* EAGLE_PLUGIN::m_xpath
private

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

Definition at line 166 of file eagle_plugin.h.

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


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