You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3157 lines
101 KiB

4 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
4 years ago
Clean up arc/circle polygonization. 1) For a while now we've been using a calculated seg count from a given maxError, and a correction factor to push the radius out so that all the error is outside the arc/circle. However, the second calculation (which pre-dates the first) is pretty much just the inverse of the first (and yields nothing more than maxError back). This is particularly sub-optimal given the cost of trig functions. 2) There are a lot of old optimizations to reduce segcounts in certain situations, someting that our error-based calculation compensates for anyway. (Smaller radii need fewer segments to meet the maxError condition.) But perhaps more importantly we now surface maxError in the UI and we don't really want to call it "Max deviation except when it's not". 3) We were also clamping the segCount twice: once in the calculation routine and once in most of it's callers. Furthermore, the caller clamping was inconsistent (both in being done and in the clamping value). We now clamp only in the calculation routine. 4) There's no reason to use the correction factors in the 3Dviewer; it's just a visualization and whether the polygonization error is inside or outside the shape isn't really material. 5) The arc-correction-disabling stuff (used for solder mask layer) was somewhat fragile in that it depended on the caller to turn it back on afterwards. It's now only exposed as a RAII object which automatically cleans up when it goes out of scope. 6) There were also bugs in a couple of the polygonization routines where we'd accumulate round-off error in adding up the segments and end up with an overly long last segment (which of course would voilate the error max). This was the cause of the linked bug and also some issues with vias that we had fudged in the past with extra clearance. Fixes https://gitlab.com/kicad/code/kicad/issues/5567
5 years ago
13 years ago
13 years ago
13 years ago
13 years ago
4 years ago
5 years ago
4 years ago
Clean up arc/circle polygonization. 1) For a while now we've been using a calculated seg count from a given maxError, and a correction factor to push the radius out so that all the error is outside the arc/circle. However, the second calculation (which pre-dates the first) is pretty much just the inverse of the first (and yields nothing more than maxError back). This is particularly sub-optimal given the cost of trig functions. 2) There are a lot of old optimizations to reduce segcounts in certain situations, someting that our error-based calculation compensates for anyway. (Smaller radii need fewer segments to meet the maxError condition.) But perhaps more importantly we now surface maxError in the UI and we don't really want to call it "Max deviation except when it's not". 3) We were also clamping the segCount twice: once in the calculation routine and once in most of it's callers. Furthermore, the caller clamping was inconsistent (both in being done and in the clamping value). We now clamp only in the calculation routine. 4) There's no reason to use the correction factors in the 3Dviewer; it's just a visualization and whether the polygonization error is inside or outside the shape isn't really material. 5) The arc-correction-disabling stuff (used for solder mask layer) was somewhat fragile in that it depended on the caller to turn it back on afterwards. It's now only exposed as a RAII object which automatically cleans up when it goes out of scope. 6) There were also bugs in a couple of the polygonization routines where we'd accumulate round-off error in adding up the segments and end up with an overly long last segment (which of course would voilate the error max). This was the cause of the linked bug and also some issues with vias that we had fudged in the past with extra clearance. Fixes https://gitlab.com/kicad/code/kicad/issues/5567
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /*
  25. Pcbnew PLUGIN for Eagle 6.x XML *.brd and footprint format.
  26. XML parsing and converting:
  27. Getting line numbers and byte offsets from the source XML file is not
  28. possible using currently available XML libraries within KiCad project:
  29. wxXmlDocument and boost::property_tree.
  30. property_tree will give line numbers but no byte offsets, and only during
  31. document loading. This means that if we have a problem after the document is
  32. successfully loaded, there is no way to correlate back to line number and byte
  33. offset of the problem. So a different approach is taken, one which relies on the
  34. XML elements themselves using an XPATH type of reporting mechanism. The path to
  35. the problem is reported in the error messages. This means keeping track of that
  36. path as we traverse the XML document for the sole purpose of accurate error
  37. reporting.
  38. User can load the source XML file into firefox or other xml browser and follow
  39. our error message.
  40. Load() TODO's
  41. *) verify zone fill clearances are correct
  42. */
  43. #include <cerrno>
  44. #include <wx/string.h>
  45. #include <wx/xml/xml.h>
  46. #include <wx/filename.h>
  47. #include <wx/log.h>
  48. #include <wx/wfstream.h>
  49. #include <convert_basic_shapes_to_polygon.h>
  50. #include <core/arraydim.h>
  51. #include <geometry/geometry_utils.h>
  52. #include <string_utils.h>
  53. #include <locale_io.h>
  54. #include <macros.h>
  55. #include <properties.h>
  56. #include <trigo.h>
  57. #include <math/util.h> // for KiROUND
  58. #include <progress_reporter.h>
  59. #include <project.h>
  60. #include <board.h>
  61. #include <board_design_settings.h>
  62. #include <footprint.h>
  63. #include <pad.h>
  64. #include <pcb_track.h>
  65. #include <fp_shape.h>
  66. #include <zone.h>
  67. #include <pad_shapes.h>
  68. #include <pcb_text.h>
  69. #include <pcb_dimension.h>
  70. #include <plugins/eagle/eagle_plugin.h>
  71. using namespace std;
  72. /// Parse an eagle distance which is either mm, or mils if there is "mil" suffix.
  73. /// Return is in BIU.
  74. static int parseEagle( const wxString& aDistance )
  75. {
  76. ECOORD::EAGLE_UNIT unit = ( aDistance.npos != aDistance.find( "mil" ) )
  77. ? ECOORD::EAGLE_UNIT::EU_MIL : ECOORD::EAGLE_UNIT::EU_MM;
  78. ECOORD coord( aDistance, unit );
  79. return coord.ToPcbUnits();
  80. }
  81. // In Eagle one can specify DRC rules where min value > max value,
  82. // in such case the max value has the priority
  83. template<typename T>
  84. static T eagleClamp( T aMin, T aValue, T aMax )
  85. {
  86. T ret = std::max( aMin, aValue );
  87. return std::min( aMax, ret );
  88. }
  89. /// Assemble a two part key as a simple concatenation of aFirst and aSecond parts,
  90. /// using a separator.
  91. static wxString makeKey( const wxString& aFirst, const wxString& aSecond )
  92. {
  93. wxString key = aFirst + '\x02' + aSecond;
  94. return key;
  95. }
  96. /// interpret special characters in Eagle text and converts them to KiCAD notation
  97. static wxString interpret_text( const wxString& aText )
  98. {
  99. wxString text;
  100. bool sectionOpen = false;
  101. for ( wxString::size_type i = 0; i < aText.size(); i++ )
  102. {
  103. // Interpret escaped characters
  104. if ( aText[ i ] == '\\' )
  105. {
  106. if ( i + 1 != aText.size() )
  107. text.Append( aText[ i + 1 ] );
  108. i++;
  109. continue;
  110. }
  111. // Escape ~ for KiCAD
  112. if( aText[i] == '~' )
  113. {
  114. text.Append( '~' );
  115. text.Append( '~' );
  116. continue;
  117. }
  118. if ( aText[ i ] == '!' )
  119. {
  120. if ( sectionOpen )
  121. {
  122. text.Append( '~' );
  123. sectionOpen = false;
  124. continue;
  125. }
  126. static wxString escapeChars( " )]}'\"" );
  127. if( i + 1 != aText.size() && escapeChars.Find( aText[i + 1] ) == wxNOT_FOUND )
  128. {
  129. sectionOpen = true;
  130. text.Append( '~' );
  131. }
  132. else
  133. {
  134. text.Append( aText[ i ] );
  135. }
  136. continue;
  137. }
  138. if( aText[i] == ',' && sectionOpen )
  139. {
  140. text.Append( '~' );
  141. sectionOpen = false;
  142. }
  143. text.Append( aText[ i ] );
  144. }
  145. return text;
  146. }
  147. static void setKeepoutSettingsToZone( ZONE* aZone, int aLayer )
  148. {
  149. if( aLayer == EAGLE_LAYER::TRESTRICT || aLayer == EAGLE_LAYER::BRESTRICT )
  150. {
  151. aZone->SetIsRuleArea( true );
  152. aZone->SetDoNotAllowVias( true );
  153. aZone->SetDoNotAllowTracks( true );
  154. aZone->SetDoNotAllowCopperPour( true );
  155. aZone->SetDoNotAllowPads( true );
  156. aZone->SetDoNotAllowFootprints( false );
  157. if( aLayer == EAGLE_LAYER::TRESTRICT ) // front layer keepout
  158. aZone->SetLayer( F_Cu );
  159. else // bottom layer keepout
  160. aZone->SetLayer( B_Cu );
  161. }
  162. else if( aLayer == EAGLE_LAYER::VRESTRICT )
  163. {
  164. aZone->SetIsRuleArea( true );
  165. aZone->SetDoNotAllowVias( true );
  166. aZone->SetDoNotAllowTracks( false );
  167. aZone->SetDoNotAllowCopperPour( false );
  168. aZone->SetDoNotAllowPads( false );
  169. aZone->SetDoNotAllowFootprints( false );
  170. aZone->SetLayerSet( LSET::AllCuMask() );
  171. }
  172. }
  173. void ERULES::parse( wxXmlNode* aRules, std::function<void()> aCheckpoint )
  174. {
  175. wxXmlNode* child = aRules->GetChildren();
  176. while( child )
  177. {
  178. aCheckpoint();
  179. if( child->GetName() == "param" )
  180. {
  181. const wxString& name = child->GetAttribute( "name" );
  182. const wxString& value = child->GetAttribute( "value" );
  183. if( name == "psElongationLong" )
  184. psElongationLong = wxAtoi( value );
  185. else if( name == "psElongationOffset" )
  186. psElongationOffset = wxAtoi( value );
  187. else if( name == "mvStopFrame" )
  188. value.ToCDouble( &mvStopFrame );
  189. else if( name == "mvCreamFrame" )
  190. value.ToCDouble( &mvCreamFrame );
  191. else if( name == "mlMinStopFrame" )
  192. mlMinStopFrame = parseEagle( value );
  193. else if( name == "mlMaxStopFrame" )
  194. mlMaxStopFrame = parseEagle( value );
  195. else if( name == "mlMinCreamFrame" )
  196. mlMinCreamFrame = parseEagle( value );
  197. else if( name == "mlMaxCreamFrame" )
  198. mlMaxCreamFrame = parseEagle( value );
  199. else if( name == "srRoundness" )
  200. value.ToCDouble( &srRoundness );
  201. else if( name == "srMinRoundness" )
  202. srMinRoundness = parseEagle( value );
  203. else if( name == "srMaxRoundness" )
  204. srMaxRoundness = parseEagle( value );
  205. else if( name == "psTop" )
  206. psTop = wxAtoi( value );
  207. else if( name == "psBottom" )
  208. psBottom = wxAtoi( value );
  209. else if( name == "psFirst" )
  210. psFirst = wxAtoi( value );
  211. else if( name == "rvPadTop" )
  212. value.ToCDouble( &rvPadTop );
  213. else if( name == "rlMinPadTop" )
  214. rlMinPadTop = parseEagle( value );
  215. else if( name == "rlMaxPadTop" )
  216. rlMaxPadTop = parseEagle( value );
  217. else if( name == "rvViaOuter" )
  218. value.ToCDouble( &rvViaOuter );
  219. else if( name == "rlMinViaOuter" )
  220. rlMinViaOuter = parseEagle( value );
  221. else if( name == "rlMaxViaOuter" )
  222. rlMaxViaOuter = parseEagle( value );
  223. else if( name == "mdWireWire" )
  224. mdWireWire = parseEagle( value );
  225. }
  226. child = child->GetNext();
  227. }
  228. }
  229. EAGLE_PLUGIN::EAGLE_PLUGIN() :
  230. m_rules( new ERULES() ),
  231. m_xpath( new XPATH() ),
  232. m_progressReporter( nullptr ),
  233. m_doneCount( 0 ),
  234. m_lastProgressCount( 0 ),
  235. m_totalCount( 0 ),
  236. m_mod_time( wxDateTime::Now() )
  237. {
  238. using namespace std::placeholders;
  239. init( nullptr );
  240. clear_cu_map();
  241. RegisterLayerMappingCallback( std::bind( &EAGLE_PLUGIN::DefaultLayerMappingCallback,
  242. this, _1 ) );
  243. }
  244. EAGLE_PLUGIN::~EAGLE_PLUGIN()
  245. {
  246. deleteTemplates();
  247. delete m_rules;
  248. delete m_xpath;
  249. }
  250. const wxString EAGLE_PLUGIN::PluginName() const
  251. {
  252. return wxT( "Eagle" );
  253. }
  254. const wxString EAGLE_PLUGIN::GetFileExtension() const
  255. {
  256. return wxT( "brd" );
  257. }
  258. void EAGLE_PLUGIN::checkpoint()
  259. {
  260. const unsigned PROGRESS_DELTA = 50;
  261. if( m_progressReporter )
  262. {
  263. if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
  264. {
  265. m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
  266. / std::max( 1U, m_totalCount ) );
  267. if( !m_progressReporter->KeepRefreshing() )
  268. THROW_IO_ERROR( ( "Open cancelled by user." ) );
  269. m_lastProgressCount = m_doneCount;
  270. }
  271. }
  272. }
  273. wxSize inline EAGLE_PLUGIN::kicad_fontz( const ECOORD& d, int aTextThickness ) const
  274. {
  275. // Eagle includes stroke thickness in the text size, KiCAD does not
  276. int kz = d.ToPcbUnits();
  277. return wxSize( kz - aTextThickness, kz - aTextThickness );
  278. }
  279. BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
  280. const PROPERTIES* aProperties, PROJECT* aProject,
  281. PROGRESS_REPORTER* aProgressReporter )
  282. {
  283. LOCALE_IO toggle; // toggles on, then off, the C locale.
  284. wxXmlNode* doc;
  285. init( aProperties );
  286. m_board = aAppendToMe ? aAppendToMe : new BOARD();
  287. m_progressReporter = aProgressReporter;
  288. // Give the filename to the board if it's new
  289. if( !aAppendToMe )
  290. m_board->SetFileName( aFileName );
  291. // delete on exception, if I own m_board, according to aAppendToMe
  292. unique_ptr<BOARD> deleter( aAppendToMe ? nullptr : m_board );
  293. try
  294. {
  295. if( m_progressReporter )
  296. {
  297. m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
  298. if( !m_progressReporter->KeepRefreshing() )
  299. THROW_IO_ERROR( ( "Open cancelled by user." ) );
  300. }
  301. wxFileName fn = aFileName;
  302. // Load the document
  303. wxFFileInputStream stream( fn.GetFullPath() );
  304. wxXmlDocument xmlDocument;
  305. if( !stream.IsOk() || !xmlDocument.Load( stream ) )
  306. {
  307. THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
  308. fn.GetFullPath() ) );
  309. }
  310. doc = xmlDocument.GetRoot();
  311. m_min_trace = INT_MAX;
  312. m_min_hole = INT_MAX;
  313. m_min_via = INT_MAX;
  314. m_min_annulus = INT_MAX;
  315. loadAllSections( doc );
  316. BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
  317. if( m_min_trace < designSettings.m_TrackMinWidth )
  318. designSettings.m_TrackMinWidth = m_min_trace;
  319. if( m_min_via < designSettings.m_ViasMinSize )
  320. designSettings.m_ViasMinSize = m_min_via;
  321. if( m_min_hole < designSettings.m_MinThroughDrill )
  322. designSettings.m_MinThroughDrill = m_min_hole;
  323. if( m_min_annulus < designSettings.m_ViasMinAnnularWidth )
  324. designSettings.m_ViasMinAnnularWidth = m_min_annulus;
  325. if( m_rules->mdWireWire )
  326. designSettings.m_MinClearance = KiROUND( m_rules->mdWireWire );
  327. NETCLASS defaults( "dummy" );
  328. auto finishNetclass =
  329. [&]( NETCLASSPTR netclass )
  330. {
  331. // If Eagle has a clearance matrix then we'll build custom rules from that.
  332. // Netclasses should just be the board minimum clearance.
  333. netclass->SetClearance( KiROUND( designSettings.m_MinClearance ) );
  334. if( netclass->GetTrackWidth() == INT_MAX )
  335. netclass->SetTrackWidth( defaults.GetTrackWidth() );
  336. if( netclass->GetViaDiameter() == INT_MAX )
  337. netclass->SetViaDiameter( defaults.GetViaDiameter() );
  338. if( netclass->GetViaDrill() == INT_MAX )
  339. netclass->SetViaDrill( defaults.GetViaDrill() );
  340. };
  341. finishNetclass( designSettings.GetNetClasses().GetDefault() );
  342. for( const std::pair<const wxString, NETCLASSPTR>& entry : designSettings.GetNetClasses() )
  343. finishNetclass( entry.second );
  344. m_board->m_LegacyNetclassesLoaded = true;
  345. m_board->m_LegacyDesignSettingsLoaded = true;
  346. fn.SetExt( "kicad_dru" );
  347. wxFile rulesFile( fn.GetFullPath(), wxFile::write );
  348. rulesFile.Write( m_customRules );
  349. // should be empty, else missing m_xpath->pop()
  350. wxASSERT( m_xpath->Contents().size() == 0 );
  351. }
  352. catch( const XML_PARSER_ERROR &exc )
  353. {
  354. wxString errmsg = exc.what();
  355. errmsg += "\n@ ";
  356. errmsg += m_xpath->Contents();
  357. THROW_IO_ERROR( errmsg );
  358. }
  359. // IO_ERROR exceptions are left uncaught, they pass upwards from here.
  360. // Ensure the copper layers count is a multiple of 2
  361. // Pcbnew does not like boards with odd layers count
  362. // (these boards cannot exist. they actually have a even layers count)
  363. int lyrcnt = m_board->GetCopperLayerCount();
  364. if( (lyrcnt % 2) != 0 )
  365. {
  366. lyrcnt++;
  367. m_board->SetCopperLayerCount( lyrcnt );
  368. }
  369. centerBoard();
  370. deleter.release();
  371. return m_board;
  372. }
  373. std::vector<FOOTPRINT*> EAGLE_PLUGIN::GetImportedCachedLibraryFootprints()
  374. {
  375. std::vector<FOOTPRINT*> retval;
  376. for( std::pair<wxString, FOOTPRINT*> fp : m_templates )
  377. retval.push_back( static_cast<FOOTPRINT*>( fp.second->Clone() ) );
  378. return retval;
  379. }
  380. void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
  381. {
  382. m_hole_count = 0;
  383. m_min_trace = 0;
  384. m_min_hole = 0;
  385. m_min_via = 0;
  386. m_min_annulus = 0;
  387. m_xpath->clear();
  388. m_pads_to_nets.clear();
  389. m_board = nullptr;
  390. m_props = aProperties;
  391. delete m_rules;
  392. m_rules = new ERULES();
  393. }
  394. void EAGLE_PLUGIN::clear_cu_map()
  395. {
  396. // All cu layers are invalid until we see them in the <layers> section while
  397. // loading either a board or library. See loadLayerDefs().
  398. for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
  399. m_cu_map[i] = -1;
  400. }
  401. void EAGLE_PLUGIN::loadAllSections( wxXmlNode* aDoc )
  402. {
  403. wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
  404. NODE_MAP drawingChildren = MapChildren( drawing );
  405. wxXmlNode* board = drawingChildren["board"];
  406. NODE_MAP boardChildren = MapChildren( board );
  407. auto count_children = [this]( wxXmlNode* aNode )
  408. {
  409. if( aNode )
  410. {
  411. wxXmlNode* child = aNode->GetChildren();
  412. while( child )
  413. {
  414. m_totalCount++;
  415. child = child->GetNext();
  416. }
  417. }
  418. };
  419. wxXmlNode* designrules = boardChildren["designrules"];
  420. wxXmlNode* layers = drawingChildren["layers"];
  421. wxXmlNode* plain = boardChildren["plain"];
  422. wxXmlNode* classes = boardChildren["classes"];
  423. wxXmlNode* signals = boardChildren["signals"];
  424. wxXmlNode* libs = boardChildren["libraries"];
  425. wxXmlNode* elems = boardChildren["elements"];
  426. if( m_progressReporter )
  427. {
  428. m_totalCount = 0;
  429. m_doneCount = 0;
  430. count_children( designrules );
  431. count_children( layers );
  432. count_children( plain );
  433. count_children( signals );
  434. count_children( elems );
  435. while( libs )
  436. {
  437. count_children( MapChildren( libs )["packages"] );
  438. libs = libs->GetNext();
  439. }
  440. // Rewind
  441. libs = boardChildren["libraries"];
  442. }
  443. m_xpath->push( "eagle.drawing" );
  444. {
  445. m_xpath->push( "board" );
  446. loadDesignRules( designrules );
  447. m_xpath->pop();
  448. }
  449. {
  450. m_xpath->push( "layers" );
  451. loadLayerDefs( layers );
  452. mapEagleLayersToKicad();
  453. m_xpath->pop();
  454. }
  455. {
  456. m_xpath->push( "board" );
  457. loadPlain( plain );
  458. loadClasses( classes );
  459. loadSignals( signals );
  460. loadLibraries( libs );
  461. loadElements( elems );
  462. m_xpath->pop();
  463. }
  464. m_xpath->pop(); // "eagle.drawing"
  465. }
  466. void EAGLE_PLUGIN::loadDesignRules( wxXmlNode* aDesignRules )
  467. {
  468. if( aDesignRules )
  469. {
  470. m_xpath->push( "designrules" );
  471. m_rules->parse( aDesignRules, [this](){ checkpoint(); } );
  472. m_xpath->pop(); // "designrules"
  473. }
  474. }
  475. void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
  476. {
  477. if( !aLayers )
  478. return;
  479. ELAYERS cu; // copper layers
  480. // Get the first layer and iterate
  481. wxXmlNode* layerNode = aLayers->GetChildren();
  482. m_eagleLayers.clear();
  483. m_eagleLayersIds.clear();
  484. while( layerNode )
  485. {
  486. ELAYER elayer( layerNode );
  487. m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
  488. m_eagleLayersIds.insert( std::make_pair( elayer.name, elayer.number ) );
  489. // find the subset of layers that are copper and active
  490. if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
  491. cu.push_back( elayer );
  492. layerNode = layerNode->GetNext();
  493. }
  494. // establish cu layer map:
  495. int ki_layer_count = 0;
  496. for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
  497. {
  498. if( ki_layer_count == 0 )
  499. {
  500. m_cu_map[it->number] = F_Cu;
  501. }
  502. else if( ki_layer_count == int( cu.size()-1 ) )
  503. {
  504. m_cu_map[it->number] = B_Cu;
  505. }
  506. else
  507. {
  508. // some eagle boards do not have contiguous layer number sequences.
  509. m_cu_map[it->number] = ki_layer_count;
  510. }
  511. }
  512. // Set the layer names and cu count if we're loading a board.
  513. if( m_board )
  514. {
  515. m_board->SetCopperLayerCount( cu.size() );
  516. for( EITER it = cu.begin(); it != cu.end(); ++it )
  517. {
  518. PCB_LAYER_ID layer = kicad_layer( it->number );
  519. // these function provide their own protection against non enabled layers:
  520. if( layer >= 0 && layer < PCB_LAYER_ID_COUNT ) // layer should be valid
  521. {
  522. m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
  523. m_board->SetLayerType( layer, LT_SIGNAL );
  524. }
  525. // could map the colors here
  526. }
  527. }
  528. }
  529. #define DIMENSION_PRECISION 1 // 0.001 mm
  530. void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
  531. {
  532. if( !aGraphics )
  533. return;
  534. m_xpath->push( "plain" );
  535. // Get the first graphic and iterate
  536. wxXmlNode* gr = aGraphics->GetChildren();
  537. // (polygon | wire | text | circle | rectangle | frame | hole)*
  538. while( gr )
  539. {
  540. checkpoint();
  541. wxString grName = gr->GetName();
  542. if( grName == "wire" )
  543. {
  544. m_xpath->push( "wire" );
  545. EWIRE w( gr );
  546. PCB_LAYER_ID layer = kicad_layer( w.layer );
  547. VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
  548. VECTOR2I end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
  549. if( layer != UNDEFINED_LAYER )
  550. {
  551. PCB_SHAPE* shape = new PCB_SHAPE( m_board );
  552. int width = w.width.ToPcbUnits();
  553. // KiCad cannot handle zero or negative line widths
  554. if( width <= 0 )
  555. width = m_board->GetDesignSettings().GetLineThickness( layer );
  556. m_board->Add( shape, ADD_MODE::APPEND );
  557. if( !w.curve )
  558. {
  559. shape->SetShape( SHAPE_T::SEGMENT );
  560. shape->SetStart( start );
  561. shape->SetEnd( end );
  562. }
  563. else
  564. {
  565. VECTOR2I center = ConvertArcCenter( start, end, *w.curve );
  566. shape->SetShape( SHAPE_T::ARC );
  567. shape->SetCenter( center );
  568. shape->SetStart( start );
  569. shape->SetArcAngleAndEnd( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way
  570. }
  571. shape->SetLayer( layer );
  572. shape->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
  573. }
  574. m_xpath->pop();
  575. }
  576. else if( grName == "text" )
  577. {
  578. m_xpath->push( "text" );
  579. ETEXT t( gr );
  580. PCB_LAYER_ID layer = kicad_layer( t.layer );
  581. if( layer != UNDEFINED_LAYER )
  582. {
  583. PCB_TEXT* pcbtxt = new PCB_TEXT( m_board );
  584. m_board->Add( pcbtxt, ADD_MODE::APPEND );
  585. pcbtxt->SetLayer( layer );
  586. wxString kicadText = interpret_text( t.text );
  587. pcbtxt->SetText( FROM_UTF8( kicadText.c_str() ) );
  588. pcbtxt->SetTextPos( VECTOR2I( kicad_x( t.x ), kicad_y( t.y ) ) );
  589. double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
  590. int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
  591. pcbtxt->SetTextThickness( textThickness );
  592. pcbtxt->SetTextSize( kicad_fontz( t.size, textThickness ) );
  593. int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
  594. if( t.rot )
  595. {
  596. int sign = t.rot->mirror ? -1 : 1;
  597. pcbtxt->SetMirrored( t.rot->mirror );
  598. double degrees = t.rot->degrees;
  599. if( degrees == 90 || t.rot->spin )
  600. {
  601. pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
  602. }
  603. else if( degrees == 180 )
  604. {
  605. align = -align;
  606. }
  607. else if( degrees == 270 )
  608. {
  609. pcbtxt->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) );
  610. align = -align;
  611. }
  612. else
  613. {
  614. // Ok so text is not at 90,180 or 270 so do some funny stuff to get
  615. // placement right.
  616. if( ( degrees > 0 ) && ( degrees < 90 ) )
  617. {
  618. pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
  619. }
  620. else if( ( degrees > 90 ) && ( degrees < 180 ) )
  621. {
  622. pcbtxt->SetTextAngle( EDA_ANGLE( sign * ( t.rot->degrees + 180 ), DEGREES_T ) );
  623. align = ETEXT::TOP_RIGHT;
  624. }
  625. else if( ( degrees > 180 ) && ( degrees < 270 ) )
  626. {
  627. pcbtxt->SetTextAngle( EDA_ANGLE( sign * ( t.rot->degrees - 180 ), DEGREES_T ) );
  628. align = ETEXT::TOP_RIGHT;
  629. }
  630. else if( ( degrees > 270 ) && ( degrees < 360 ) )
  631. {
  632. pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
  633. align = ETEXT::BOTTOM_LEFT;
  634. }
  635. }
  636. }
  637. switch( align )
  638. {
  639. case ETEXT::CENTER:
  640. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  641. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  642. break;
  643. case ETEXT::CENTER_LEFT:
  644. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  645. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  646. break;
  647. case ETEXT::CENTER_RIGHT:
  648. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  649. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  650. break;
  651. case ETEXT::TOP_CENTER:
  652. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  653. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  654. break;
  655. case ETEXT::TOP_LEFT:
  656. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  657. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  658. break;
  659. case ETEXT::TOP_RIGHT:
  660. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  661. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  662. break;
  663. case ETEXT::BOTTOM_CENTER:
  664. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  665. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  666. break;
  667. case ETEXT::BOTTOM_LEFT:
  668. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  669. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  670. break;
  671. case ETEXT::BOTTOM_RIGHT:
  672. pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  673. pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  674. break;
  675. }
  676. }
  677. m_xpath->pop();
  678. }
  679. else if( grName == "circle" )
  680. {
  681. m_xpath->push( "circle" );
  682. ECIRCLE c( gr );
  683. int width = c.width.ToPcbUnits();
  684. int radius = c.radius.ToPcbUnits();
  685. if( c.layer == EAGLE_LAYER::TRESTRICT || c.layer == EAGLE_LAYER::BRESTRICT
  686. || c.layer == EAGLE_LAYER::VRESTRICT )
  687. {
  688. ZONE* zone = new ZONE( m_board );
  689. m_board->Add( zone, ADD_MODE::APPEND );
  690. setKeepoutSettingsToZone( zone, c.layer );
  691. // approximate circle as polygon
  692. VECTOR2I center( kicad_x( c.x ), kicad_y( c.y ) );
  693. int outlineRadius = radius + ( width / 2 );
  694. int segsInCircle = GetArcToSegmentCount( outlineRadius, ARC_HIGH_DEF, FULL_CIRCLE );
  695. EDA_ANGLE delta = ANGLE_360 / segsInCircle;
  696. for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
  697. {
  698. VECTOR2I rotatedPoint( outlineRadius, 0 );
  699. RotatePoint( rotatedPoint, angle );
  700. zone->AppendCorner( center + rotatedPoint, -1 );
  701. }
  702. if( width > 0 )
  703. {
  704. zone->NewHole();
  705. int innerRadius = radius - ( width / 2 );
  706. segsInCircle = GetArcToSegmentCount( innerRadius, ARC_HIGH_DEF, FULL_CIRCLE );
  707. delta = ANGLE_360 / segsInCircle;
  708. for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
  709. {
  710. VECTOR2I rotatedPoint( innerRadius, 0 );
  711. RotatePoint( rotatedPoint, angle );
  712. zone->AppendCorner( center + rotatedPoint, 0 );
  713. }
  714. }
  715. zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
  716. ZONE::GetDefaultHatchPitch(), true );
  717. }
  718. else
  719. {
  720. PCB_LAYER_ID layer = kicad_layer( c.layer );
  721. if( layer != UNDEFINED_LAYER ) // unsupported layer
  722. {
  723. PCB_SHAPE* shape = new PCB_SHAPE( m_board, SHAPE_T::CIRCLE );
  724. m_board->Add( shape, ADD_MODE::APPEND );
  725. shape->SetFilled( false );
  726. shape->SetLayer( layer );
  727. shape->SetStart( VECTOR2I( kicad_x( c.x ), kicad_y( c.y ) ) );
  728. shape->SetEnd( VECTOR2I( kicad_x( c.x ) + radius, kicad_y( c.y ) ) );
  729. shape->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
  730. }
  731. }
  732. m_xpath->pop();
  733. }
  734. else if( grName == "rectangle" )
  735. {
  736. // This seems to be a simplified rectangular [copper] zone, cannot find any
  737. // net related info on it from the DTD.
  738. m_xpath->push( "rectangle" );
  739. ERECT r( gr );
  740. PCB_LAYER_ID layer = kicad_layer( r.layer );
  741. if( IsCopperLayer( layer ) )
  742. {
  743. // use a "netcode = 0" type ZONE:
  744. ZONE* zone = new ZONE( m_board );
  745. m_board->Add( zone, ADD_MODE::APPEND );
  746. zone->SetLayer( layer );
  747. zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
  748. ZONE_BORDER_DISPLAY_STYLE outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
  749. const int outlineIdx = -1; // this is the id of the copper zone main outline
  750. zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
  751. zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
  752. zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
  753. zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
  754. if( r.rot )
  755. zone->Rotate( zone->GetPosition(), EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
  756. // this is not my fault:
  757. zone->SetBorderDisplayStyle( outline_hatch, ZONE::GetDefaultHatchPitch(),
  758. true );
  759. }
  760. m_xpath->pop();
  761. }
  762. else if( grName == "hole" )
  763. {
  764. m_xpath->push( "hole" );
  765. // Fabricate a FOOTPRINT with a single PAD_ATTRIB::NPTH pad.
  766. // Use m_hole_count to gen up a unique name.
  767. FOOTPRINT* footprint = new FOOTPRINT( m_board );
  768. m_board->Add( footprint, ADD_MODE::APPEND );
  769. footprint->SetReference( wxString::Format( "@HOLE%d", m_hole_count++ ) );
  770. footprint->Reference().SetVisible( false );
  771. packageHole( footprint, gr, true );
  772. m_xpath->pop();
  773. }
  774. else if( grName == "frame" )
  775. {
  776. // picture this
  777. }
  778. else if( grName == "polygon" )
  779. {
  780. m_xpath->push( "polygon" );
  781. loadPolygon( gr );
  782. m_xpath->pop(); // "polygon"
  783. }
  784. else if( grName == "dimension" )
  785. {
  786. EDIMENSION d( gr );
  787. PCB_LAYER_ID layer = kicad_layer( d.layer );
  788. if( layer != UNDEFINED_LAYER )
  789. {
  790. const BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
  791. PCB_DIM_ALIGNED* dimension = new PCB_DIM_ALIGNED( m_board, PCB_DIM_ALIGNED_T );
  792. m_board->Add( dimension, ADD_MODE::APPEND );
  793. if( d.dimensionType )
  794. {
  795. // Eagle dimension graphic arms may have different lengths, but they look
  796. // incorrect in KiCad (the graphic is tilted). Make them even length in
  797. // such case.
  798. if( *d.dimensionType == "horizontal" )
  799. {
  800. int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
  801. d.y1 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
  802. d.y2 = ECOORD( newY, ECOORD::EAGLE_UNIT::EU_NM );
  803. }
  804. else if( *d.dimensionType == "vertical" )
  805. {
  806. int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2;
  807. d.x1 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
  808. d.x2 = ECOORD( newX, ECOORD::EAGLE_UNIT::EU_NM );
  809. }
  810. }
  811. dimension->SetLayer( layer );
  812. dimension->SetPrecision( DIMENSION_PRECISION );
  813. // The origin and end are assumed to always be in this order from eagle
  814. dimension->SetStart( VECTOR2I( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
  815. dimension->SetEnd( VECTOR2I( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
  816. dimension->Text().SetTextSize( designSettings.GetTextSize( layer ) );
  817. dimension->Text().SetTextThickness( designSettings.GetTextThickness( layer ) );
  818. dimension->SetLineThickness( designSettings.GetLineThickness( layer ) );
  819. dimension->SetUnits( EDA_UNITS::MILLIMETRES );
  820. // check which axis the dimension runs in
  821. // because the "height" of the dimension is perpendicular to that axis
  822. // Note the check is just if two axes are close enough to each other
  823. // Eagle appears to have some rounding errors
  824. if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm
  825. dimension->SetHeight( kicad_x( d.x3 - d.x1 ) );
  826. else
  827. dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
  828. }
  829. }
  830. // Get next graphic
  831. gr = gr->GetNext();
  832. }
  833. m_xpath->pop();
  834. }
  835. void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const wxString* aLibName )
  836. {
  837. if( !aLib )
  838. return;
  839. // library will have <xmlattr> node, skip that and get the single packages node
  840. wxXmlNode* packages = MapChildren( aLib )["packages"];
  841. if( !packages )
  842. return;
  843. m_xpath->push( "packages" );
  844. // Create a FOOTPRINT for all the eagle packages, for use later via a copy constructor
  845. // to instantiate needed footprints in our BOARD. Save the FOOTPRINT templates in
  846. // a FOOTPRINT_MAP using a single lookup key consisting of libname+pkgname.
  847. // Get the first package and iterate
  848. wxXmlNode* package = packages->GetChildren();
  849. while( package )
  850. {
  851. checkpoint();
  852. m_xpath->push( "package", "name" );
  853. wxString pack_ref = package->GetAttribute( "name" );
  854. ReplaceIllegalFileNameChars( pack_ref, '_' );
  855. m_xpath->Value( pack_ref.ToUTF8() );
  856. wxString key = aLibName ? makeKey( *aLibName, pack_ref ) : pack_ref;
  857. FOOTPRINT* m = makeFootprint( package, pack_ref );
  858. // add the templating FOOTPRINT to the FOOTPRINT template factory "m_templates"
  859. std::pair<FOOTPRINT_MAP::iterator, bool> r = m_templates.insert( {key, m} );
  860. if( !r.second /* && !( m_props && m_props->Value( "ignore_duplicates" ) ) */ )
  861. {
  862. wxString lib = aLibName ? *aLibName : m_lib_path;
  863. const wxString& pkg = pack_ref;
  864. wxString emsg = wxString::Format( _( "<package> '%s' duplicated in <library> '%s'" ),
  865. pkg,
  866. lib );
  867. THROW_IO_ERROR( emsg );
  868. }
  869. m_xpath->pop();
  870. package = package->GetNext();
  871. }
  872. m_xpath->pop(); // "packages"
  873. }
  874. void EAGLE_PLUGIN::loadLibraries( wxXmlNode* aLibs )
  875. {
  876. if( !aLibs )
  877. return;
  878. m_xpath->push( "libraries.library", "name" );
  879. // Get the first library and iterate
  880. wxXmlNode* library = aLibs->GetChildren();
  881. while( library )
  882. {
  883. const wxString& lib_name = library->GetAttribute( "name" );
  884. m_xpath->Value( lib_name.c_str() );
  885. loadLibrary( library, &lib_name );
  886. library = library->GetNext();
  887. }
  888. m_xpath->pop();
  889. }
  890. void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
  891. {
  892. if( !aElements )
  893. return;
  894. m_xpath->push( "elements.element", "name" );
  895. EATTR name;
  896. EATTR value;
  897. bool refanceNamePresetInPackageLayout;
  898. bool valueNamePresetInPackageLayout;
  899. // Get the first element and iterate
  900. wxXmlNode* element = aElements->GetChildren();
  901. while( element )
  902. {
  903. checkpoint();
  904. if( element->GetName() != "element" )
  905. {
  906. // Get next item
  907. element = element->GetNext();
  908. continue;
  909. }
  910. EELEMENT e( element );
  911. // use "NULL-ness" as an indication of presence of the attribute:
  912. EATTR* nameAttr = nullptr;
  913. EATTR* valueAttr = nullptr;
  914. m_xpath->Value( e.name.c_str() );
  915. wxString pkg_key = makeKey( e.library, e.package );
  916. FOOTPRINT_MAP::const_iterator it = m_templates.find( pkg_key );
  917. if( it == m_templates.end() )
  918. {
  919. wxString emsg = wxString::Format( _( "No '%s' package in library '%s'." ),
  920. FROM_UTF8( e.package.c_str() ),
  921. FROM_UTF8( e.library.c_str() ) );
  922. THROW_IO_ERROR( emsg );
  923. }
  924. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( it->second->Duplicate() );
  925. m_board->Add( footprint, ADD_MODE::APPEND );
  926. // update the nets within the pads of the clone
  927. for( PAD* pad : footprint->Pads() )
  928. {
  929. wxString pn_key = makeKey( e.name, pad->GetNumber() );
  930. NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
  931. if( ni != m_pads_to_nets.end() )
  932. {
  933. const ENET* enet = &ni->second;
  934. pad->SetNetCode( enet->netcode );
  935. }
  936. }
  937. refanceNamePresetInPackageLayout = true;
  938. valueNamePresetInPackageLayout = true;
  939. footprint->SetPosition( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) );
  940. // Is >NAME field set in package layout ?
  941. if( footprint->GetReference().size() == 0 )
  942. {
  943. footprint->Reference().SetVisible( false ); // No so no show
  944. refanceNamePresetInPackageLayout = false;
  945. }
  946. // Is >VALUE field set in package layout
  947. if( footprint->GetValue().size() == 0 )
  948. {
  949. footprint->Value().SetVisible( false ); // No so no show
  950. valueNamePresetInPackageLayout = false;
  951. }
  952. footprint->SetReference( FROM_UTF8( e.name.c_str() ) );
  953. footprint->SetValue( FROM_UTF8( e.value.c_str() ) );
  954. if( !e.smashed )
  955. {
  956. // Not smashed so show NAME & VALUE
  957. if( valueNamePresetInPackageLayout )
  958. footprint->Value().SetVisible( true ); // Only if place holder in package layout
  959. if( refanceNamePresetInPackageLayout )
  960. footprint->Reference().SetVisible( true ); // Only if place holder in package layout
  961. }
  962. else if( *e.smashed == true )
  963. {
  964. // Smashed so set default to no show for NAME and VALUE
  965. footprint->Value().SetVisible( false );
  966. footprint->Reference().SetVisible( false );
  967. // initialize these to default values in case the <attribute> elements are not present.
  968. m_xpath->push( "attribute", "name" );
  969. // VALUE and NAME can have something like our text "effects" overrides
  970. // in SWEET and new schematic. Eagle calls these XML elements "attribute".
  971. // There can be one for NAME and/or VALUE both. Features present in the
  972. // EATTR override the ones established in the package only if they are
  973. // present here (except for rot, which if not present means angle zero).
  974. // So the logic is a bit different than in packageText() and in plain text.
  975. // Get the first attribute and iterate
  976. wxXmlNode* attribute = element->GetChildren();
  977. while( attribute )
  978. {
  979. if( attribute->GetName() != "attribute" )
  980. {
  981. attribute = attribute->GetNext();
  982. continue;
  983. }
  984. EATTR a( attribute );
  985. if( a.name == "NAME" )
  986. {
  987. name = a;
  988. nameAttr = &name;
  989. // do we have a display attribute ?
  990. if( a.display )
  991. {
  992. // Yes!
  993. switch( *a.display )
  994. {
  995. case EATTR::VALUE :
  996. {
  997. wxString reference = e.name;
  998. // EAGLE allows references to be single digits. This breaks KiCad
  999. // netlisting, which requires parts to have non-digit + digit
  1000. // annotation. If the reference begins with a number, we prepend
  1001. // 'UNK' (unknown) for the symbol designator.
  1002. if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
  1003. reference.Prepend( "UNK" );
  1004. nameAttr->name = reference;
  1005. footprint->SetReference( reference );
  1006. if( refanceNamePresetInPackageLayout )
  1007. footprint->Reference().SetVisible( true );
  1008. break;
  1009. }
  1010. case EATTR::NAME :
  1011. if( refanceNamePresetInPackageLayout )
  1012. {
  1013. footprint->SetReference( "NAME" );
  1014. footprint->Reference().SetVisible( true );
  1015. }
  1016. break;
  1017. case EATTR::BOTH :
  1018. if( refanceNamePresetInPackageLayout )
  1019. footprint->Reference().SetVisible( true );
  1020. nameAttr->name = nameAttr->name + " = " + e.name;
  1021. footprint->SetReference( "NAME = " + e.name );
  1022. break;
  1023. case EATTR::Off :
  1024. footprint->Reference().SetVisible( false );
  1025. break;
  1026. default:
  1027. nameAttr->name = e.name;
  1028. if( refanceNamePresetInPackageLayout )
  1029. footprint->Reference().SetVisible( true );
  1030. }
  1031. }
  1032. else
  1033. {
  1034. // No display, so default is visible, and show value of NAME
  1035. footprint->Reference().SetVisible( true );
  1036. }
  1037. }
  1038. else if( a.name == "VALUE" )
  1039. {
  1040. value = a;
  1041. valueAttr = &value;
  1042. if( a.display )
  1043. {
  1044. // Yes!
  1045. switch( *a.display )
  1046. {
  1047. case EATTR::VALUE :
  1048. valueAttr->value = opt_wxString( e.value );
  1049. footprint->SetValue( e.value );
  1050. if( valueNamePresetInPackageLayout )
  1051. footprint->Value().SetVisible( true );
  1052. break;
  1053. case EATTR::NAME :
  1054. if( valueNamePresetInPackageLayout )
  1055. footprint->Value().SetVisible( true );
  1056. footprint->SetValue( "VALUE" );
  1057. break;
  1058. case EATTR::BOTH :
  1059. if( valueNamePresetInPackageLayout )
  1060. footprint->Value().SetVisible( true );
  1061. valueAttr->value = opt_wxString( "VALUE = " + e.value );
  1062. footprint->SetValue( "VALUE = " + e.value );
  1063. break;
  1064. case EATTR::Off :
  1065. footprint->Value().SetVisible( false );
  1066. break;
  1067. default:
  1068. valueAttr->value = opt_wxString( e.value );
  1069. if( valueNamePresetInPackageLayout )
  1070. footprint->Value().SetVisible( true );
  1071. }
  1072. }
  1073. else
  1074. {
  1075. // No display, so default is visible, and show value of NAME
  1076. footprint->Value().SetVisible( true );
  1077. }
  1078. }
  1079. attribute = attribute->GetNext();
  1080. }
  1081. m_xpath->pop(); // "attribute"
  1082. }
  1083. orientFootprintAndText( footprint, e, nameAttr, valueAttr );
  1084. // Set the local coordinates for the footprint text items
  1085. footprint->Reference().SetLocalCoord();
  1086. footprint->Value().SetLocalCoord();
  1087. // Get next element
  1088. element = element->GetNext();
  1089. }
  1090. m_xpath->pop(); // "elements.element"
  1091. }
  1092. ZONE* EAGLE_PLUGIN::loadPolygon( wxXmlNode* aPolyNode )
  1093. {
  1094. EPOLYGON p( aPolyNode );
  1095. PCB_LAYER_ID layer = kicad_layer( p.layer );
  1096. ZONE* zone = nullptr;
  1097. bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT
  1098. || p.layer == EAGLE_LAYER::BRESTRICT
  1099. || p.layer == EAGLE_LAYER::VRESTRICT );
  1100. if( layer == UNDEFINED_LAYER )
  1101. {
  1102. wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
  1103. "was not mapped" ),
  1104. eagle_layer_name( p.layer ), p.layer ) );
  1105. return nullptr;
  1106. }
  1107. if( !IsCopperLayer( layer ) && !keepout )
  1108. return nullptr;
  1109. // use a "netcode = 0" type ZONE:
  1110. zone = new ZONE( m_board );
  1111. m_board->Add( zone, ADD_MODE::APPEND );
  1112. if( !keepout )
  1113. zone->SetLayer( layer );
  1114. else
  1115. setKeepoutSettingsToZone( zone, p.layer );
  1116. // Get the first vertex and iterate
  1117. wxXmlNode* vertex = aPolyNode->GetChildren();
  1118. std::vector<EVERTEX> vertices;
  1119. // Create a circular vector of vertices
  1120. // The "curve" parameter indicates a curve from the current
  1121. // to the next vertex, so we keep the first at the end as well
  1122. // to allow the curve to link back
  1123. while( vertex )
  1124. {
  1125. if( vertex->GetName() == "vertex" )
  1126. vertices.emplace_back( vertex );
  1127. vertex = vertex->GetNext();
  1128. }
  1129. vertices.push_back( vertices[0] );
  1130. SHAPE_POLY_SET polygon;
  1131. polygon.NewOutline();
  1132. for( size_t i = 0; i < vertices.size() - 1; i++ )
  1133. {
  1134. EVERTEX v1 = vertices[i];
  1135. // Append the corner
  1136. polygon.Append( kicad_x( v1.x ), kicad_y( v1.y ) );
  1137. if( v1.curve )
  1138. {
  1139. EVERTEX v2 = vertices[i + 1];
  1140. VECTOR2I center =
  1141. ConvertArcCenter( VECTOR2I( kicad_x( v1.x ), kicad_y( v1.y ) ),
  1142. VECTOR2I( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
  1143. double angle = DEG2RAD( *v1.curve );
  1144. double end_angle = atan2( kicad_y( v2.y ) - center.y, kicad_x( v2.x ) - center.x );
  1145. double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
  1146. + pow( center.y - kicad_y( v1.y ), 2 ) );
  1147. int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
  1148. EDA_ANGLE( *v1.curve, DEGREES_T ) );
  1149. double delta_angle = angle / segCount;
  1150. for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta_angle );
  1151. a -= delta_angle )
  1152. {
  1153. polygon.Append( KiROUND( radius * cos( a ) ) + center.x,
  1154. KiROUND( radius * sin( a ) ) + center.y );
  1155. }
  1156. }
  1157. }
  1158. // Eagle traces the zone such that half of the pen width is outside the polygon.
  1159. // We trace the zone such that the copper is completely inside.
  1160. if( p.width.ToPcbUnits() > 0 )
  1161. {
  1162. polygon.Inflate( p.width.ToPcbUnits() / 2, 32, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS );
  1163. polygon.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
  1164. }
  1165. zone->AddPolygon( polygon.COutline( 0 ) );
  1166. // If the pour is a cutout it needs to be set to a keepout
  1167. if( p.pour == EPOLYGON::CUTOUT )
  1168. {
  1169. zone->SetIsRuleArea( true );
  1170. zone->SetDoNotAllowVias( false );
  1171. zone->SetDoNotAllowTracks( false );
  1172. zone->SetDoNotAllowPads( false );
  1173. zone->SetDoNotAllowFootprints( false );
  1174. zone->SetDoNotAllowCopperPour( true );
  1175. zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
  1176. }
  1177. else if( p.pour == EPOLYGON::HATCH )
  1178. {
  1179. int spacing = p.spacing ? p.spacing->ToPcbUnits() : 50 * IU_PER_MILS;
  1180. zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
  1181. zone->SetHatchThickness( p.width.ToPcbUnits() );
  1182. zone->SetHatchGap( spacing - p.width.ToPcbUnits() );
  1183. zone->SetHatchOrientation( ANGLE_0 );
  1184. }
  1185. // We divide the thickness by half because we are tracing _inside_ the zone outline
  1186. // This means the radius of curvature will be twice the size for an equivalent EAGLE zone
  1187. zone->SetMinThickness( std::max<int>( ZONE_THICKNESS_MIN_VALUE_MIL * IU_PER_MILS,
  1188. p.width.ToPcbUnits() / 2 ) );
  1189. if( p.isolate )
  1190. zone->SetLocalClearance( p.isolate->ToPcbUnits() );
  1191. else
  1192. zone->SetLocalClearance( 1 ); // @todo: set minimum clearance value based on board settings
  1193. // missing == yes per DTD.
  1194. bool thermals = !p.thermals || *p.thermals;
  1195. zone->SetPadConnection( thermals ? ZONE_CONNECTION::THERMAL : ZONE_CONNECTION::FULL );
  1196. if( thermals )
  1197. {
  1198. // FIXME: eagle calculates dimensions for thermal spokes
  1199. // based on what the zone is connecting to.
  1200. // (i.e. width of spoke is half of the smaller side of an smd pad)
  1201. // This is a basic workaround
  1202. zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
  1203. zone->SetThermalReliefSpokeWidth( p.width.ToPcbUnits() + 50000 );
  1204. }
  1205. int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
  1206. zone->SetPriority( rank );
  1207. return zone;
  1208. }
  1209. void EAGLE_PLUGIN::orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e,
  1210. const EATTR* aNameAttr, const EATTR* aValueAttr )
  1211. {
  1212. if( e.rot )
  1213. {
  1214. if( e.rot->mirror )
  1215. {
  1216. aFootprint->SetOrientation( EDA_ANGLE( e.rot->degrees + 180.0, DEGREES_T ) );
  1217. aFootprint->Flip( aFootprint->GetPosition(), false );
  1218. }
  1219. else
  1220. {
  1221. aFootprint->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
  1222. }
  1223. }
  1224. orientFPText( aFootprint, e, &aFootprint->Reference(), aNameAttr );
  1225. orientFPText( aFootprint, e, &aFootprint->Value(), aValueAttr );
  1226. }
  1227. void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
  1228. const EATTR* aAttr )
  1229. {
  1230. // Smashed part ?
  1231. if( aAttr )
  1232. {
  1233. // Yes
  1234. const EATTR& a = *aAttr;
  1235. if( a.value )
  1236. {
  1237. aFPText->SetText( FROM_UTF8( a.value->c_str() ) );
  1238. }
  1239. if( a.x && a.y ) // OPT
  1240. {
  1241. VECTOR2I pos( kicad_x( *a.x ), kicad_y( *a.y ) );
  1242. aFPText->SetTextPos( pos );
  1243. }
  1244. // Even though size and ratio are both optional, I am not seeing
  1245. // a case where ratio is present but size is not.
  1246. double ratio = 8;
  1247. if( a.ratio )
  1248. ratio = *a.ratio;
  1249. wxSize fontz = aFPText->GetTextSize();
  1250. int textThickness = KiROUND( fontz.y * ratio / 100 );
  1251. aFPText->SetTextThickness( textThickness );
  1252. if( a.size )
  1253. {
  1254. fontz = kicad_fontz( *a.size, textThickness );
  1255. aFPText->SetTextSize( fontz );
  1256. }
  1257. int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
  1258. if( a.align )
  1259. align = a.align;
  1260. // The "rot" in a EATTR seems to be assumed to be zero if it is not
  1261. // present, and this zero rotation becomes an override to the
  1262. // package's text field. If they did not want zero, they specify
  1263. // what they want explicitly.
  1264. double degrees = a.rot ? a.rot->degrees : 0.0;
  1265. double orient; // relative to parent
  1266. int sign = 1;
  1267. bool spin = false;
  1268. if( a.rot )
  1269. {
  1270. spin = a.rot->spin;
  1271. sign = a.rot->mirror ? -1 : 1;
  1272. aFPText->SetMirrored( a.rot->mirror );
  1273. }
  1274. if( degrees == 90 || degrees == 0 || spin )
  1275. {
  1276. orient = degrees - aFootprint->GetOrientation().AsDegrees();
  1277. aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) );
  1278. }
  1279. else if( degrees == 180 )
  1280. {
  1281. orient = 0 - aFootprint->GetOrientation().AsDegrees();
  1282. aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) );
  1283. align = -align;
  1284. }
  1285. else if( degrees == 270 )
  1286. {
  1287. orient = 90 - aFootprint->GetOrientation().AsDegrees();
  1288. align = -align;
  1289. aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) );
  1290. }
  1291. else
  1292. {
  1293. orient = 90 - degrees - aFootprint->GetOrientation().AsDegrees();
  1294. aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) );
  1295. }
  1296. switch( align )
  1297. {
  1298. case ETEXT::TOP_RIGHT:
  1299. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1300. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1301. break;
  1302. case ETEXT::BOTTOM_LEFT:
  1303. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1304. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1305. break;
  1306. case ETEXT::TOP_LEFT:
  1307. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1308. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1309. break;
  1310. case ETEXT::BOTTOM_RIGHT:
  1311. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1312. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1313. break;
  1314. case ETEXT::TOP_CENTER:
  1315. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1316. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1317. break;
  1318. case ETEXT::BOTTOM_CENTER:
  1319. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1320. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1321. break;
  1322. case ETEXT::CENTER:
  1323. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1324. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1325. break;
  1326. case ETEXT::CENTER_LEFT:
  1327. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1328. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1329. break;
  1330. case ETEXT::CENTER_RIGHT:
  1331. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1332. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1333. break;
  1334. default:
  1335. ;
  1336. }
  1337. }
  1338. else
  1339. {
  1340. // Part is not smash so use Lib default for NAME/VALUE
  1341. // the text is per the original package, sans <attribute>.
  1342. double degrees = aFPText->GetTextAngle().AsDegrees()
  1343. + aFootprint->GetOrientation().AsDegrees();
  1344. // @todo there are a few more cases than these to contend with:
  1345. if( ( !aFPText->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ) )
  1346. || ( aFPText->IsMirrored() && ( degrees == 360 ) ) )
  1347. {
  1348. // ETEXT::TOP_RIGHT:
  1349. aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1350. aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1351. }
  1352. }
  1353. }
  1354. FOOTPRINT* EAGLE_PLUGIN::makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName )
  1355. {
  1356. std::unique_ptr<FOOTPRINT> m = std::make_unique<FOOTPRINT>( m_board );
  1357. LIB_ID fpID;
  1358. fpID.Parse( aPkgName, true );
  1359. m->SetFPID( fpID );
  1360. // Get the first package item and iterate
  1361. wxXmlNode* packageItem = aPackage->GetChildren();
  1362. // layer 27 is default layer for tValues
  1363. // set default layer for created footprint
  1364. PCB_LAYER_ID layer = kicad_layer( 27 );
  1365. m.get()->Value().SetLayer( layer );
  1366. while( packageItem )
  1367. {
  1368. const wxString& itemName = packageItem->GetName();
  1369. if( itemName == "description" )
  1370. m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
  1371. else if( itemName == "wire" )
  1372. packageWire( m.get(), packageItem );
  1373. else if( itemName == "pad" )
  1374. packagePad( m.get(), packageItem );
  1375. else if( itemName == "text" )
  1376. packageText( m.get(), packageItem );
  1377. else if( itemName == "rectangle" )
  1378. packageRectangle( m.get(), packageItem );
  1379. else if( itemName == "polygon" )
  1380. packagePolygon( m.get(), packageItem );
  1381. else if( itemName == "circle" )
  1382. packageCircle( m.get(), packageItem );
  1383. else if( itemName == "hole" )
  1384. packageHole( m.get(), packageItem, false );
  1385. else if( itemName == "smd" )
  1386. packageSMD( m.get(), packageItem );
  1387. packageItem = packageItem->GetNext();
  1388. }
  1389. return m.release();
  1390. }
  1391. void EAGLE_PLUGIN::packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1392. {
  1393. EWIRE w( aTree );
  1394. PCB_LAYER_ID layer = kicad_layer( w.layer );
  1395. VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
  1396. VECTOR2I end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
  1397. int width = w.width.ToPcbUnits();
  1398. if( layer == UNDEFINED_LAYER )
  1399. {
  1400. wxLogMessage( wxString::Format( _( "Ignoring a wire since Eagle layer '%s' (%d) "
  1401. "was not mapped" ),
  1402. eagle_layer_name( w.layer ), w.layer ) );
  1403. return;
  1404. }
  1405. // KiCad cannot handle zero or negative line widths which apparently have meaning in Eagle.
  1406. if( width <= 0 )
  1407. {
  1408. BOARD* board = aFootprint->GetBoard();
  1409. if( board )
  1410. {
  1411. width = board->GetDesignSettings().GetLineThickness( layer );
  1412. }
  1413. else
  1414. {
  1415. // When loading footprint libraries, there is no board so use the default KiCad
  1416. // line widths.
  1417. switch( layer )
  1418. {
  1419. case Edge_Cuts: width = Millimeter2iu( DEFAULT_EDGE_WIDTH ); break;
  1420. case F_SilkS:
  1421. case B_SilkS: width = Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ); break;
  1422. case F_CrtYd:
  1423. case B_CrtYd: width = Millimeter2iu( DEFAULT_COURTYARD_WIDTH ); break;
  1424. default: width = Millimeter2iu( DEFAULT_LINE_WIDTH ); break;
  1425. }
  1426. }
  1427. }
  1428. // FIXME: the cap attribute is ignored because KiCad can't create lines
  1429. // with flat ends.
  1430. FP_SHAPE* dwg;
  1431. if( !w.curve )
  1432. {
  1433. dwg = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT );
  1434. dwg->SetStart0( start );
  1435. dwg->SetEnd0( end );
  1436. }
  1437. else
  1438. {
  1439. dwg = new FP_SHAPE( aFootprint, SHAPE_T::ARC );
  1440. VECTOR2I center = ConvertArcCenter( start, end, *w.curve );
  1441. dwg->SetCenter0( center );
  1442. dwg->SetStart0( start );
  1443. dwg->SetArcAngleAndEnd0( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way
  1444. }
  1445. dwg->SetLayer( layer );
  1446. dwg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
  1447. dwg->SetDrawCoord();
  1448. aFootprint->Add( dwg );
  1449. }
  1450. void EAGLE_PLUGIN::packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree )
  1451. {
  1452. // this is thru hole technology here, no SMDs
  1453. EPAD e( aTree );
  1454. int shape = EPAD::UNDEF;
  1455. int eagleDrillz = e.drill.ToPcbUnits();
  1456. PAD* pad = new PAD( aFootprint );
  1457. aFootprint->Add( pad );
  1458. transferPad( e, pad );
  1459. if( e.first && *e.first && m_rules->psFirst != EPAD::UNDEF )
  1460. shape = m_rules->psFirst;
  1461. else if( aFootprint->GetLayer() == F_Cu && m_rules->psTop != EPAD::UNDEF )
  1462. shape = m_rules->psTop;
  1463. else if( aFootprint->GetLayer() == B_Cu && m_rules->psBottom != EPAD::UNDEF )
  1464. shape = m_rules->psBottom;
  1465. pad->SetDrillSize( wxSize( eagleDrillz, eagleDrillz ) );
  1466. pad->SetLayerSet( LSET::AllCuMask() );
  1467. if( eagleDrillz < m_min_hole )
  1468. m_min_hole = eagleDrillz;
  1469. // Solder mask
  1470. if( !e.stop || *e.stop == true ) // enabled by default
  1471. pad->SetLayerSet( pad->GetLayerSet().set( B_Mask ).set( F_Mask ) );
  1472. if( shape == EPAD::ROUND || shape == EPAD::SQUARE || shape == EPAD::OCTAGON )
  1473. e.shape = shape;
  1474. if( e.shape )
  1475. {
  1476. switch( *e.shape )
  1477. {
  1478. case EPAD::ROUND:
  1479. pad->SetShape( PAD_SHAPE::CIRCLE );
  1480. break;
  1481. case EPAD::OCTAGON:
  1482. // no KiCad octagonal pad shape, use PAD_CIRCLE for now.
  1483. // pad->SetShape( PAD_OCTAGON );
  1484. wxASSERT( pad->GetShape() == PAD_SHAPE::CIRCLE ); // verify set in PAD constructor
  1485. pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
  1486. pad->SetChamferPositions( RECT_CHAMFER_ALL );
  1487. pad->SetChamferRectRatio( 0.25 );
  1488. break;
  1489. case EPAD::LONG:
  1490. pad->SetShape( PAD_SHAPE::OVAL );
  1491. break;
  1492. case EPAD::SQUARE:
  1493. pad->SetShape( PAD_SHAPE::RECT );
  1494. break;
  1495. case EPAD::OFFSET:
  1496. pad->SetShape( PAD_SHAPE::OVAL );
  1497. break;
  1498. }
  1499. }
  1500. else
  1501. {
  1502. // if shape is not present, our default is circle and that matches their default "round"
  1503. }
  1504. if( e.diameter && e.diameter->value > 0 )
  1505. {
  1506. int diameter = e.diameter->ToPcbUnits();
  1507. pad->SetSize( wxSize( diameter, diameter ) );
  1508. }
  1509. else
  1510. {
  1511. double drillz = pad->GetDrillSize().x;
  1512. double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
  1513. annulus = eagleClamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
  1514. int diameter = KiROUND( drillz + 2 * annulus );
  1515. pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
  1516. }
  1517. if( pad->GetShape() == PAD_SHAPE::OVAL )
  1518. {
  1519. // The Eagle "long" pad is wider than it is tall,
  1520. // m_elongation is percent elongation
  1521. VECTOR2I sz = pad->GetSize();
  1522. sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
  1523. pad->SetSize( sz );
  1524. if( e.shape && *e.shape == EPAD::OFFSET )
  1525. {
  1526. int offset = KiROUND( ( sz.x - sz.y ) / 2.0 );
  1527. pad->SetOffset( VECTOR2I( offset, 0 ) );
  1528. }
  1529. }
  1530. if( e.rot )
  1531. pad->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
  1532. }
  1533. void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1534. {
  1535. ETEXT t( aTree );
  1536. PCB_LAYER_ID layer = kicad_layer( t.layer );
  1537. if( layer == UNDEFINED_LAYER )
  1538. {
  1539. wxLogMessage( wxString::Format( _( "Ignoring a text since Eagle layer '%s' (%d) "
  1540. "was not mapped" ),
  1541. eagle_layer_name( t.layer ), t.layer ) );
  1542. return;
  1543. }
  1544. FP_TEXT* txt;
  1545. if( t.text.MakeUpper() == ">NAME" )
  1546. txt = &aFootprint->Reference();
  1547. else if( t.text.MakeUpper() == ">VALUE" )
  1548. txt = &aFootprint->Value();
  1549. else
  1550. {
  1551. // FIXME: graphical text items are rotated for some reason.
  1552. txt = new FP_TEXT( aFootprint );
  1553. aFootprint->Add( txt );
  1554. }
  1555. txt->SetText( FROM_UTF8( t.text.c_str() ) );
  1556. VECTOR2I pos( kicad_x( t.x ), kicad_y( t.y ) );
  1557. txt->SetTextPos( pos );
  1558. txt->SetPos0( pos - aFootprint->GetPosition() );
  1559. txt->SetLayer( layer );
  1560. double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
  1561. int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
  1562. txt->SetTextThickness( textThickness );
  1563. txt->SetTextSize( kicad_fontz( t.size, textThickness ) );
  1564. int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
  1565. // An eagle package is never rotated, the DTD does not allow it.
  1566. // angle -= aFootprint->GetOrienation();
  1567. if( t.rot )
  1568. {
  1569. int sign = t.rot->mirror ? -1 : 1;
  1570. txt->SetMirrored( t.rot->mirror );
  1571. double degrees = t.rot->degrees;
  1572. if( degrees == 90 || t.rot->spin )
  1573. {
  1574. txt->SetTextAngle( EDA_ANGLE( sign * degrees, DEGREES_T ) );
  1575. }
  1576. else if( degrees == 180 )
  1577. {
  1578. align = ETEXT::TOP_RIGHT;
  1579. }
  1580. else if( degrees == 270 )
  1581. {
  1582. align = ETEXT::TOP_RIGHT;
  1583. txt->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) );
  1584. }
  1585. }
  1586. switch( align )
  1587. {
  1588. case ETEXT::CENTER:
  1589. txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1590. txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1591. break;
  1592. case ETEXT::CENTER_LEFT:
  1593. txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1594. txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1595. break;
  1596. case ETEXT::CENTER_RIGHT:
  1597. txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1598. txt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
  1599. break;
  1600. case ETEXT::TOP_CENTER:
  1601. txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1602. txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1603. break;
  1604. case ETEXT::TOP_LEFT:
  1605. txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1606. txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1607. break;
  1608. case ETEXT::TOP_RIGHT:
  1609. txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1610. txt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
  1611. break;
  1612. case ETEXT::BOTTOM_CENTER:
  1613. txt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
  1614. txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1615. break;
  1616. case ETEXT::BOTTOM_LEFT:
  1617. txt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
  1618. txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1619. break;
  1620. case ETEXT::BOTTOM_RIGHT:
  1621. txt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
  1622. txt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
  1623. break;
  1624. }
  1625. }
  1626. void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1627. {
  1628. ERECT r( aTree );
  1629. if( r.layer == EAGLE_LAYER::TRESTRICT || r.layer == EAGLE_LAYER::BRESTRICT
  1630. || r.layer == EAGLE_LAYER::VRESTRICT )
  1631. {
  1632. FP_ZONE* zone = new FP_ZONE( aFootprint );
  1633. aFootprint->Add( zone, ADD_MODE::APPEND );
  1634. setKeepoutSettingsToZone( zone, r.layer );
  1635. const int outlineIdx = -1; // this is the id of the copper zone main outline
  1636. zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
  1637. zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
  1638. zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
  1639. zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
  1640. if( r.rot )
  1641. {
  1642. VECTOR2I center( ( kicad_x( r.x1 ) + kicad_x( r.x2 ) ) / 2,
  1643. ( kicad_y( r.y1 ) + kicad_y( r.y2 ) ) / 2 );
  1644. zone->Rotate( center, EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
  1645. }
  1646. zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
  1647. ZONE::GetDefaultHatchPitch(), true );
  1648. }
  1649. else
  1650. {
  1651. PCB_LAYER_ID layer = kicad_layer( r.layer );
  1652. if( layer == UNDEFINED_LAYER )
  1653. {
  1654. wxLogMessage( wxString::Format( _( "Ignoring a rectangle since Eagle layer '%s' (%d) "
  1655. "was not mapped" ),
  1656. eagle_layer_name( r.layer ), r.layer ) );
  1657. return;
  1658. }
  1659. FP_SHAPE* dwg = new FP_SHAPE( aFootprint, SHAPE_T::POLY );
  1660. aFootprint->Add( dwg );
  1661. dwg->SetLayer( layer );
  1662. dwg->SetStroke( STROKE_PARAMS( 0 ) );
  1663. dwg->SetFilled( true );
  1664. std::vector<VECTOR2I> pts;
  1665. VECTOR2I start( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
  1666. VECTOR2I end( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
  1667. pts.push_back( start );
  1668. pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y1 ) );
  1669. pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y2 ) );
  1670. pts.push_back( end );
  1671. dwg->SetPolyPoints( pts );
  1672. dwg->SetStart0( start );
  1673. dwg->SetEnd0( end );
  1674. if( r.rot )
  1675. dwg->Rotate( dwg->GetCenter(), EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
  1676. }
  1677. }
  1678. void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1679. {
  1680. EPOLYGON p( aTree );
  1681. std::vector<VECTOR2I> pts;
  1682. // Get the first vertex and iterate
  1683. wxXmlNode* vertex = aTree->GetChildren();
  1684. std::vector<EVERTEX> vertices;
  1685. // Create a circular vector of vertices
  1686. // The "curve" parameter indicates a curve from the current
  1687. // to the next vertex, so we keep the first at the end as well
  1688. // to allow the curve to link back
  1689. while( vertex )
  1690. {
  1691. if( vertex->GetName() == "vertex" )
  1692. vertices.emplace_back( vertex );
  1693. vertex = vertex->GetNext();
  1694. }
  1695. vertices.push_back( vertices[0] );
  1696. for( size_t i = 0; i < vertices.size() - 1; i++ )
  1697. {
  1698. EVERTEX v1 = vertices[i];
  1699. // Append the corner
  1700. pts.emplace_back( kicad_x( v1.x ), kicad_y( v1.y ) );
  1701. if( v1.curve )
  1702. {
  1703. EVERTEX v2 = vertices[i + 1];
  1704. VECTOR2I center =
  1705. ConvertArcCenter( VECTOR2I( kicad_x( v1.x ), kicad_y( v1.y ) ),
  1706. VECTOR2I( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
  1707. double angle = DEG2RAD( *v1.curve );
  1708. double end_angle = atan2( kicad_y( v2.y ) - center.y, 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. // Don't allow a zero-radius curve
  1712. if( KiROUND( radius ) == 0 )
  1713. radius = 1.0;
  1714. int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
  1715. EDA_ANGLE( *v1.curve, DEGREES_T ) );
  1716. double delta = angle / segCount;
  1717. for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta ); a -= delta )
  1718. {
  1719. pts.push_back(
  1720. VECTOR2I( KiROUND( radius * cos( a ) ), KiROUND( radius * sin( a ) ) )
  1721. + center );
  1722. }
  1723. }
  1724. }
  1725. if( p.layer == EAGLE_LAYER::TRESTRICT
  1726. || p.layer == EAGLE_LAYER::BRESTRICT
  1727. || p.layer == EAGLE_LAYER::VRESTRICT )
  1728. {
  1729. FP_ZONE* zone = new FP_ZONE( aFootprint );
  1730. aFootprint->Add( zone, ADD_MODE::APPEND );
  1731. setKeepoutSettingsToZone( zone, p.layer );
  1732. SHAPE_LINE_CHAIN outline( pts );
  1733. outline.SetClosed( true );
  1734. zone->Outline()->AddOutline( outline );
  1735. zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
  1736. ZONE::GetDefaultHatchPitch(), true );
  1737. }
  1738. else
  1739. {
  1740. PCB_LAYER_ID layer = kicad_layer( p.layer );
  1741. if( layer == UNDEFINED_LAYER )
  1742. {
  1743. wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
  1744. "was not mapped" ),
  1745. eagle_layer_name( p.layer ), p.layer ) );
  1746. return;
  1747. }
  1748. FP_SHAPE* dwg = new FP_SHAPE( aFootprint, SHAPE_T::POLY );
  1749. aFootprint->Add( dwg );
  1750. dwg->SetStroke( STROKE_PARAMS( 0 ) );
  1751. dwg->SetFilled( true );
  1752. dwg->SetLayer( layer );
  1753. dwg->SetPolyPoints( pts );
  1754. dwg->SetStart0( *pts.begin() );
  1755. dwg->SetEnd0( pts.back() );
  1756. dwg->SetDrawCoord();
  1757. dwg->GetPolyShape().Inflate( p.width.ToPcbUnits() / 2, 32,
  1758. SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS );
  1759. }
  1760. }
  1761. void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1762. {
  1763. ECIRCLE e( aTree );
  1764. int width = e.width.ToPcbUnits();
  1765. int radius = e.radius.ToPcbUnits();
  1766. if( e.layer == EAGLE_LAYER::TRESTRICT
  1767. || e.layer == EAGLE_LAYER::BRESTRICT
  1768. || e.layer == EAGLE_LAYER::VRESTRICT )
  1769. {
  1770. FP_ZONE* zone = new FP_ZONE( aFootprint );
  1771. aFootprint->Add( zone, ADD_MODE::APPEND );
  1772. setKeepoutSettingsToZone( zone, e.layer );
  1773. // approximate circle as polygon
  1774. VECTOR2I center( kicad_x( e.x ), kicad_y( e.y ) );
  1775. int outlineRadius = radius + ( width / 2 );
  1776. int segsInCircle = GetArcToSegmentCount( outlineRadius, ARC_HIGH_DEF, FULL_CIRCLE );
  1777. EDA_ANGLE delta = ANGLE_360 / segsInCircle;
  1778. for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
  1779. {
  1780. VECTOR2I rotatedPoint( outlineRadius, 0 );
  1781. RotatePoint( rotatedPoint, angle );
  1782. zone->AppendCorner( center + rotatedPoint, -1 );
  1783. }
  1784. if( width > 0 )
  1785. {
  1786. zone->NewHole();
  1787. int innerRadius = radius - ( width / 2 );
  1788. segsInCircle = GetArcToSegmentCount( innerRadius, ARC_HIGH_DEF, FULL_CIRCLE );
  1789. delta = ANGLE_360 / segsInCircle;
  1790. for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
  1791. {
  1792. VECTOR2I rotatedPoint( innerRadius, 0 );
  1793. RotatePoint( rotatedPoint, angle );
  1794. zone->AppendCorner( center + rotatedPoint, 0 );
  1795. }
  1796. }
  1797. zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
  1798. ZONE::GetDefaultHatchPitch(), true );
  1799. }
  1800. else
  1801. {
  1802. PCB_LAYER_ID layer = kicad_layer( e.layer );
  1803. if( layer == UNDEFINED_LAYER )
  1804. {
  1805. wxLogMessage( wxString::Format( _( "Ignoring a circle since Eagle layer '%s' (%d) "
  1806. "was not mapped" ),
  1807. eagle_layer_name( e.layer ), e.layer ) );
  1808. return;
  1809. }
  1810. FP_SHAPE* gr = new FP_SHAPE( aFootprint, SHAPE_T::CIRCLE );
  1811. // width == 0 means filled circle
  1812. if( width <= 0 )
  1813. {
  1814. width = radius;
  1815. radius = radius / 2;
  1816. gr->SetFilled( true );
  1817. }
  1818. aFootprint->Add( gr );
  1819. gr->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
  1820. switch( (int) layer )
  1821. {
  1822. case UNDEFINED_LAYER:
  1823. layer = Cmts_User;
  1824. break;
  1825. default:
  1826. break;
  1827. }
  1828. gr->SetLayer( layer );
  1829. gr->SetStart0( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) );
  1830. gr->SetEnd0( VECTOR2I( kicad_x( e.x ) + radius, kicad_y( e.y ) ) );
  1831. gr->SetDrawCoord();
  1832. }
  1833. }
  1834. void EAGLE_PLUGIN::packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const
  1835. {
  1836. EHOLE e( aTree );
  1837. if( e.drill.value == 0 )
  1838. return;
  1839. // we add a PAD_ATTRIB::NPTH pad to this footprint.
  1840. PAD* pad = new PAD( aFootprint );
  1841. aFootprint->Add( pad );
  1842. pad->SetShape( PAD_SHAPE::CIRCLE );
  1843. pad->SetAttribute( PAD_ATTRIB::NPTH );
  1844. // Mechanical purpose only:
  1845. // no offset, no net name, no pad name allowed
  1846. // pad->SetOffset( VECTOR2I( 0, 0 ) );
  1847. // pad->SetNumber( wxEmptyString );
  1848. VECTOR2I padpos( kicad_x( e.x ), kicad_y( e.y ) );
  1849. if( aCenter )
  1850. {
  1851. pad->SetPos0( VECTOR2I( 0, 0 ) );
  1852. aFootprint->SetPosition( padpos );
  1853. pad->SetPosition( padpos );
  1854. }
  1855. else
  1856. {
  1857. pad->SetPos0( padpos );
  1858. pad->SetPosition( padpos + aFootprint->GetPosition() );
  1859. }
  1860. wxSize sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
  1861. pad->SetDrillSize( sz );
  1862. pad->SetSize( sz );
  1863. pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
  1864. }
  1865. void EAGLE_PLUGIN::packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
  1866. {
  1867. ESMD e( aTree );
  1868. PCB_LAYER_ID layer = kicad_layer( e.layer );
  1869. if( !IsCopperLayer( layer ) || e.dx.value == 0 || e.dy.value == 0 )
  1870. return;
  1871. PAD* pad = new PAD( aFootprint );
  1872. aFootprint->Add( pad );
  1873. transferPad( e, pad );
  1874. pad->SetShape( PAD_SHAPE::RECT );
  1875. pad->SetAttribute( PAD_ATTRIB::SMD );
  1876. wxSize padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
  1877. pad->SetSize( padSize );
  1878. pad->SetLayer( layer );
  1879. const LSET front( 3, F_Cu, F_Paste, F_Mask );
  1880. const LSET back( 3, B_Cu, B_Paste, B_Mask );
  1881. if( layer == F_Cu )
  1882. pad->SetLayerSet( front );
  1883. else if( layer == B_Cu )
  1884. pad->SetLayerSet( back );
  1885. int minPadSize = std::min( padSize.x, padSize.y );
  1886. // Rounded rectangle pads
  1887. int roundRadius =
  1888. eagleClamp( m_rules->srMinRoundness * 2, (int) ( minPadSize * m_rules->srRoundness ),
  1889. m_rules->srMaxRoundness * 2 );
  1890. if( e.roundness || roundRadius > 0 )
  1891. {
  1892. double roundRatio = (double) roundRadius / minPadSize / 2.0;
  1893. // Eagle uses a different definition of roundness, hence division by 200
  1894. if( e.roundness )
  1895. roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
  1896. pad->SetShape( PAD_SHAPE::ROUNDRECT );
  1897. pad->SetRoundRectRadiusRatio( roundRatio );
  1898. }
  1899. if( e.rot )
  1900. pad->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
  1901. pad->SetLocalSolderPasteMargin( -eagleClamp( m_rules->mlMinCreamFrame,
  1902. (int) ( m_rules->mvCreamFrame * minPadSize ),
  1903. m_rules->mlMaxCreamFrame ) );
  1904. // Solder mask
  1905. if( e.stop && *e.stop == false ) // enabled by default
  1906. {
  1907. if( layer == F_Cu )
  1908. pad->SetLayerSet( pad->GetLayerSet().set( F_Mask, false ) );
  1909. else if( layer == B_Cu )
  1910. pad->SetLayerSet( pad->GetLayerSet().set( B_Mask, false ) );
  1911. }
  1912. // Solder paste (only for SMD pads)
  1913. if( e.cream && *e.cream == false ) // enabled by default
  1914. {
  1915. if( layer == F_Cu )
  1916. pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
  1917. else if( layer == B_Cu )
  1918. pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
  1919. }
  1920. }
  1921. void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const
  1922. {
  1923. aPad->SetNumber( FROM_UTF8( aEaglePad.name.c_str() ) );
  1924. // pad's "Position" is not relative to the footprint's,
  1925. // whereas Pos0 is relative to the footprint's but is the unrotated coordinate.
  1926. VECTOR2I padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
  1927. aPad->SetPos0( padPos );
  1928. // Solder mask
  1929. const VECTOR2I& padSize( aPad->GetSize() );
  1930. aPad->SetLocalSolderMaskMargin(
  1931. eagleClamp( m_rules->mlMinStopFrame,
  1932. (int) ( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
  1933. m_rules->mlMaxStopFrame ) );
  1934. // Solid connection to copper zones
  1935. if( aEaglePad.thermals && !*aEaglePad.thermals )
  1936. aPad->SetZoneConnection( ZONE_CONNECTION::FULL );
  1937. FOOTPRINT* footprint = aPad->GetParent();
  1938. wxCHECK( footprint, /* void */ );
  1939. RotatePoint( padPos, footprint->GetOrientation() );
  1940. aPad->SetPosition( padPos + footprint->GetPosition() );
  1941. }
  1942. void EAGLE_PLUGIN::deleteTemplates()
  1943. {
  1944. for( auto& t : m_templates )
  1945. delete t.second;
  1946. m_templates.clear();
  1947. }
  1948. void EAGLE_PLUGIN::loadClasses( wxXmlNode* aClasses )
  1949. {
  1950. BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
  1951. m_xpath->push( "classes.class", "number" );
  1952. std::vector<ECLASS> eClasses;
  1953. wxXmlNode* classNode = aClasses->GetChildren();
  1954. while( classNode )
  1955. {
  1956. checkpoint();
  1957. ECLASS eClass( classNode );
  1958. NETCLASSPTR netclass;
  1959. if( eClass.name.CmpNoCase( "default" ) == 0 )
  1960. {
  1961. netclass = bds.GetNetClasses().GetDefault();
  1962. }
  1963. else
  1964. {
  1965. netclass.reset( new NETCLASS( eClass.name ) );
  1966. m_board->GetDesignSettings().GetNetClasses().Add( netclass );
  1967. }
  1968. netclass->SetTrackWidth( INT_MAX );
  1969. netclass->SetViaDiameter( INT_MAX );
  1970. netclass->SetViaDrill( INT_MAX );
  1971. eClasses.emplace_back( eClass );
  1972. m_classMap[ eClass.number ] = netclass;
  1973. // Get next class
  1974. classNode = classNode->GetNext();
  1975. }
  1976. m_customRules = "(version 1)";
  1977. for( ECLASS& eClass : eClasses )
  1978. {
  1979. for( std::pair<const wxString&, ECOORD> entry : eClass.clearanceMap )
  1980. {
  1981. if( m_classMap[ entry.first ] != nullptr )
  1982. {
  1983. wxString rule;
  1984. rule.Printf( "(rule \"class %s:%s\"\n"
  1985. " (condition \"A.NetClass == '%s' && B.NetClass == '%s'\")\n"
  1986. " (constraint clearance (min %smm)))\n",
  1987. eClass.number,
  1988. entry.first,
  1989. eClass.name,
  1990. m_classMap[ entry.first ]->GetName(),
  1991. StringFromValue( EDA_UNITS::MILLIMETRES, entry.second.ToPcbUnits() ) );
  1992. m_customRules += "\n" + rule;
  1993. }
  1994. }
  1995. }
  1996. m_xpath->pop(); // "classes.class"
  1997. }
  1998. void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
  1999. {
  2000. ZONES zones; // per net
  2001. int netCode = 1;
  2002. m_xpath->push( "signals.signal", "name" );
  2003. // Get the first signal and iterate
  2004. wxXmlNode* net = aSignals->GetChildren();
  2005. while( net )
  2006. {
  2007. checkpoint();
  2008. bool sawPad = false;
  2009. zones.clear();
  2010. const wxString& netName = escapeName( net->GetAttribute( "name" ) );
  2011. NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, netName, netCode );
  2012. NETCLASSPTR netclass;
  2013. if( net->HasAttribute( "class" ) )
  2014. {
  2015. netclass = m_classMap[ net->GetAttribute( "class" ) ];
  2016. netclass->Add( netName );
  2017. netInfo->SetNetClass( netclass );
  2018. }
  2019. m_board->Add( netInfo );
  2020. m_xpath->Value( netName.c_str() );
  2021. // Get the first net item and iterate
  2022. wxXmlNode* netItem = net->GetChildren();
  2023. // (contactref | polygon | wire | via)*
  2024. while( netItem )
  2025. {
  2026. const wxString& itemName = netItem->GetName();
  2027. if( itemName == "wire" )
  2028. {
  2029. m_xpath->push( "wire" );
  2030. EWIRE w( netItem );
  2031. PCB_LAYER_ID layer = kicad_layer( w.layer );
  2032. if( IsCopperLayer( layer ) )
  2033. {
  2034. VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
  2035. double angle = 0.0;
  2036. double end_angle = 0.0;
  2037. double radius = 0.0;
  2038. double delta_angle = 0.0;
  2039. VECTOR2I center;
  2040. int width = w.width.ToPcbUnits();
  2041. if( width < m_min_trace )
  2042. m_min_trace = width;
  2043. if( netclass && width < netclass->GetTrackWidth() )
  2044. netclass->SetTrackWidth( width );
  2045. if( w.curve )
  2046. {
  2047. center = ConvertArcCenter( VECTOR2I( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
  2048. VECTOR2I( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
  2049. *w.curve );
  2050. angle = DEG2RAD( *w.curve );
  2051. end_angle = atan2( kicad_y( w.y2 ) - center.y,
  2052. kicad_x( w.x2 ) - center.x );
  2053. radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
  2054. pow( center.y - kicad_y( w.y1 ), 2 ) );
  2055. int segs = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
  2056. EDA_ANGLE( *w.curve, DEGREES_T ) );
  2057. delta_angle = angle / segs;
  2058. }
  2059. while( fabs( angle ) > fabs( delta_angle ) )
  2060. {
  2061. wxASSERT( radius > 0.0 );
  2062. VECTOR2I end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
  2063. KiROUND( radius * sin( end_angle + angle ) + center.y ) );
  2064. PCB_TRACK* t = new PCB_TRACK( m_board );
  2065. t->SetPosition( start );
  2066. t->SetEnd( end );
  2067. t->SetWidth( width );
  2068. t->SetLayer( layer );
  2069. t->SetNetCode( netCode );
  2070. m_board->Add( t );
  2071. start = end;
  2072. angle -= delta_angle;
  2073. }
  2074. PCB_TRACK* t = new PCB_TRACK( m_board );
  2075. t->SetPosition( start );
  2076. t->SetEnd( VECTOR2I( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
  2077. t->SetWidth( width );
  2078. t->SetLayer( layer );
  2079. t->SetNetCode( netCode );
  2080. m_board->Add( t );
  2081. }
  2082. else
  2083. {
  2084. // put non copper wires where the sun don't shine.
  2085. }
  2086. m_xpath->pop();
  2087. }
  2088. else if( itemName == "via" )
  2089. {
  2090. m_xpath->push( "via" );
  2091. EVIA v( netItem );
  2092. if( v.layer_front_most > v.layer_back_most )
  2093. std::swap( v.layer_front_most, v.layer_back_most );
  2094. PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
  2095. PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
  2096. if( IsCopperLayer( layer_front_most ) && IsCopperLayer( layer_back_most )
  2097. && layer_front_most != layer_back_most )
  2098. {
  2099. int kidiam;
  2100. int drillz = v.drill.ToPcbUnits();
  2101. PCB_VIA* via = new PCB_VIA( m_board );
  2102. m_board->Add( via );
  2103. if( v.diam )
  2104. {
  2105. kidiam = v.diam->ToPcbUnits();
  2106. via->SetWidth( kidiam );
  2107. }
  2108. else
  2109. {
  2110. double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
  2111. annulus = eagleClamp( m_rules->rlMinViaOuter, annulus,
  2112. m_rules->rlMaxViaOuter );
  2113. kidiam = KiROUND( drillz + 2 * annulus );
  2114. via->SetWidth( kidiam );
  2115. }
  2116. via->SetDrill( drillz );
  2117. // make sure the via diameter respects the restring rules
  2118. if( !v.diam || via->GetWidth() <= via->GetDrill() )
  2119. {
  2120. double annulus =
  2121. eagleClamp( m_rules->rlMinViaOuter,
  2122. (double) ( via->GetWidth() / 2 - via->GetDrill() ),
  2123. m_rules->rlMaxViaOuter );
  2124. via->SetWidth( drillz + 2 * annulus );
  2125. }
  2126. if( kidiam < m_min_via )
  2127. m_min_via = kidiam;
  2128. if( netclass && kidiam < netclass->GetViaDiameter() )
  2129. netclass->SetViaDiameter( kidiam );
  2130. if( drillz < m_min_hole )
  2131. m_min_hole = drillz;
  2132. if( netclass && drillz < netclass->GetViaDrill() )
  2133. netclass->SetViaDrill( drillz );
  2134. if( ( kidiam - drillz ) / 2 < m_min_annulus )
  2135. m_min_annulus = ( kidiam - drillz ) / 2;
  2136. if( layer_front_most == F_Cu && layer_back_most == B_Cu )
  2137. {
  2138. via->SetViaType( VIATYPE::THROUGH );
  2139. }
  2140. /// This is, at best, a guess. Eagle doesn't seem to differentiate
  2141. /// between blind/buried vias that only go one layer and micro vias
  2142. /// so the user will need to clean up a bit
  2143. else if( v.layer_back_most - v.layer_front_most == 1 )
  2144. {
  2145. via->SetViaType( VIATYPE::MICROVIA );
  2146. }
  2147. else
  2148. {
  2149. via->SetViaType( VIATYPE::BLIND_BURIED );
  2150. }
  2151. VECTOR2I pos( kicad_x( v.x ), kicad_y( v.y ) );
  2152. via->SetLayerPair( layer_front_most, layer_back_most );
  2153. via->SetPosition( pos );
  2154. via->SetEnd( pos );
  2155. via->SetNetCode( netCode );
  2156. }
  2157. m_xpath->pop();
  2158. }
  2159. else if( itemName == "contactref" )
  2160. {
  2161. m_xpath->push( "contactref" );
  2162. // <contactref element="RN1" pad="7"/>
  2163. const wxString& reference = netItem->GetAttribute( "element" );
  2164. const wxString& pad = netItem->GetAttribute( "pad" );
  2165. wxString key = makeKey( reference, pad ) ;
  2166. m_pads_to_nets[ key ] = ENET( netCode, netName );
  2167. m_xpath->pop();
  2168. sawPad = true;
  2169. }
  2170. else if( itemName == "polygon" )
  2171. {
  2172. m_xpath->push( "polygon" );
  2173. auto* zone = loadPolygon( netItem );
  2174. if( zone )
  2175. {
  2176. zones.push_back( zone );
  2177. if( !zone->GetIsRuleArea() )
  2178. zone->SetNetCode( netCode );
  2179. }
  2180. m_xpath->pop(); // "polygon"
  2181. }
  2182. netItem = netItem->GetNext();
  2183. }
  2184. if( zones.size() && !sawPad )
  2185. {
  2186. // KiCad does not support an unconnected zone with its own non-zero netcode,
  2187. // but only when assigned netcode = 0 w/o a name...
  2188. for( ZONE* zone : zones )
  2189. zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
  2190. // therefore omit this signal/net.
  2191. }
  2192. else
  2193. {
  2194. netCode++;
  2195. }
  2196. // Get next signal
  2197. net = net->GetNext();
  2198. }
  2199. m_xpath->pop(); // "signals.signal"
  2200. }
  2201. std::map<wxString, PCB_LAYER_ID> EAGLE_PLUGIN::DefaultLayerMappingCallback(
  2202. const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
  2203. {
  2204. std::map<wxString, PCB_LAYER_ID> layer_map;
  2205. for ( const INPUT_LAYER_DESC& layer : aInputLayerDescriptionVector )
  2206. {
  2207. PCB_LAYER_ID layerId = std::get<0>( defaultKicadLayer( eagle_layer_id( layer.Name ) ) );
  2208. layer_map.emplace( layer.Name, layerId );
  2209. }
  2210. return layer_map;
  2211. }
  2212. void EAGLE_PLUGIN::mapEagleLayersToKicad()
  2213. {
  2214. std::vector<INPUT_LAYER_DESC> inputDescs;
  2215. for ( const std::pair<const int, ELAYER>& layerPair : m_eagleLayers )
  2216. {
  2217. const ELAYER& eLayer = layerPair.second;
  2218. INPUT_LAYER_DESC layerDesc;
  2219. std::tie( layerDesc.AutoMapLayer, layerDesc.PermittedLayers, layerDesc.Required ) =
  2220. defaultKicadLayer( eLayer.number );
  2221. if( layerDesc.AutoMapLayer == UNDEFINED_LAYER )
  2222. continue; // Ignore unused copper layers
  2223. layerDesc.Name = eLayer.name;
  2224. inputDescs.push_back( layerDesc );
  2225. }
  2226. if( m_progressReporter && dynamic_cast<wxWindow*>( m_progressReporter ) )
  2227. dynamic_cast<wxWindow*>( m_progressReporter )->Hide();
  2228. m_layer_map = m_layer_mapping_handler( inputDescs );
  2229. if( m_progressReporter && dynamic_cast<wxWindow*>( m_progressReporter ))
  2230. dynamic_cast<wxWindow*>( m_progressReporter )->Show();
  2231. }
  2232. PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
  2233. {
  2234. auto result = m_layer_map.find( eagle_layer_name( aEagleLayer ) );
  2235. return result == m_layer_map.end() ? UNDEFINED_LAYER : result->second;
  2236. }
  2237. std::tuple<PCB_LAYER_ID, LSET, bool> EAGLE_PLUGIN::defaultKicadLayer( int aEagleLayer ) const
  2238. {
  2239. // eagle copper layer:
  2240. if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
  2241. {
  2242. LSET copperLayers;
  2243. for( int copperLayer : m_cu_map )
  2244. {
  2245. if( copperLayer >= 0 )
  2246. copperLayers[copperLayer] = true;
  2247. }
  2248. return { PCB_LAYER_ID( m_cu_map[aEagleLayer] ), copperLayers, true };
  2249. }
  2250. int kiLayer = UNSELECTED_LAYER;
  2251. bool required = false;
  2252. LSET permittedLayers;
  2253. permittedLayers.set();
  2254. // translate non-copper eagle layer to pcbnew layer
  2255. switch( aEagleLayer )
  2256. {
  2257. // Eagle says "Dimension" layer, but it's for board perimeter
  2258. case EAGLE_LAYER::DIMENSION:
  2259. kiLayer = Edge_Cuts;
  2260. required = true;
  2261. permittedLayers = LSET( 1, Edge_Cuts );
  2262. break;
  2263. case EAGLE_LAYER::TPLACE:
  2264. kiLayer = F_SilkS;
  2265. break;
  2266. case EAGLE_LAYER::BPLACE:
  2267. kiLayer = B_SilkS;
  2268. break;
  2269. case EAGLE_LAYER::TNAMES:
  2270. kiLayer = F_SilkS;
  2271. break;
  2272. case EAGLE_LAYER::BNAMES:
  2273. kiLayer = B_SilkS;
  2274. break;
  2275. case EAGLE_LAYER::TVALUES:
  2276. kiLayer = F_Fab;
  2277. break;
  2278. case EAGLE_LAYER::BVALUES:
  2279. kiLayer = B_Fab;
  2280. break;
  2281. case EAGLE_LAYER::TSTOP:
  2282. kiLayer = F_Mask;
  2283. break;
  2284. case EAGLE_LAYER::BSTOP:
  2285. kiLayer = B_Mask;
  2286. break;
  2287. case EAGLE_LAYER::TCREAM:
  2288. kiLayer = F_Paste;
  2289. break;
  2290. case EAGLE_LAYER::BCREAM:
  2291. kiLayer = B_Paste;
  2292. break;
  2293. case EAGLE_LAYER::TFINISH:
  2294. kiLayer = F_Mask;
  2295. break;
  2296. case EAGLE_LAYER::BFINISH:
  2297. kiLayer = B_Mask;
  2298. break;
  2299. case EAGLE_LAYER::TGLUE:
  2300. kiLayer = F_Adhes;
  2301. break;
  2302. case EAGLE_LAYER::BGLUE:
  2303. kiLayer = B_Adhes;
  2304. break;
  2305. case EAGLE_LAYER::DOCUMENT:
  2306. kiLayer = Cmts_User;
  2307. break;
  2308. case EAGLE_LAYER::REFERENCELC:
  2309. kiLayer = Cmts_User;
  2310. break;
  2311. case EAGLE_LAYER::REFERENCELS:
  2312. kiLayer = Cmts_User;
  2313. break;
  2314. // Packages show the future chip pins on SMD parts using layer 51.
  2315. // This is an area slightly smaller than the PAD/SMD copper area.
  2316. // Carry those visual aids into the FOOTPRINT on the fabrication layer,
  2317. // not silkscreen. This is perhaps not perfect, but there is not a lot
  2318. // of other suitable paired layers
  2319. case EAGLE_LAYER::TDOCU:
  2320. kiLayer = F_Fab;
  2321. break;
  2322. case EAGLE_LAYER::BDOCU:
  2323. kiLayer = B_Fab;
  2324. break;
  2325. // these layers are defined as user layers. put them on ECO layers
  2326. case EAGLE_LAYER::USERLAYER1:
  2327. kiLayer = Eco1_User;
  2328. break;
  2329. case EAGLE_LAYER::USERLAYER2:
  2330. kiLayer = Eco2_User;
  2331. break;
  2332. // these will also appear in the ratsnest, so there's no need for a warning
  2333. case EAGLE_LAYER::UNROUTED:
  2334. kiLayer = Dwgs_User;
  2335. break;
  2336. case EAGLE_LAYER::TKEEPOUT:
  2337. kiLayer = F_CrtYd;
  2338. break;
  2339. case EAGLE_LAYER::BKEEPOUT:
  2340. kiLayer = B_CrtYd;
  2341. break;
  2342. case EAGLE_LAYER::MILLING:
  2343. case EAGLE_LAYER::TTEST:
  2344. case EAGLE_LAYER::BTEST:
  2345. case EAGLE_LAYER::HOLES:
  2346. default:
  2347. kiLayer = UNDEFINED_LAYER;
  2348. break;
  2349. }
  2350. return { PCB_LAYER_ID( kiLayer ), permittedLayers, required };
  2351. }
  2352. const wxString& EAGLE_PLUGIN::eagle_layer_name( int aLayer ) const
  2353. {
  2354. static const wxString unknown( "unknown" );
  2355. auto it = m_eagleLayers.find( aLayer );
  2356. return it == m_eagleLayers.end() ? unknown : it->second.name;
  2357. }
  2358. int EAGLE_PLUGIN::eagle_layer_id( const wxString& aLayerName ) const
  2359. {
  2360. static const int unknown = -1;
  2361. auto it = m_eagleLayersIds.find( aLayerName );
  2362. return it == m_eagleLayersIds.end() ? unknown : it->second;
  2363. }
  2364. void EAGLE_PLUGIN::centerBoard()
  2365. {
  2366. if( m_props )
  2367. {
  2368. UTF8 page_width;
  2369. UTF8 page_height;
  2370. if( m_props->Value( "page_width", &page_width ) &&
  2371. m_props->Value( "page_height", &page_height ) )
  2372. {
  2373. EDA_RECT bbbox = m_board->GetBoardEdgesBoundingBox();
  2374. int w = atoi( page_width.c_str() );
  2375. int h = atoi( page_height.c_str() );
  2376. int desired_x = ( w - bbbox.GetWidth() ) / 2;
  2377. int desired_y = ( h - bbbox.GetHeight() ) / 2;
  2378. m_board->Move( VECTOR2I( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
  2379. }
  2380. }
  2381. }
  2382. wxDateTime EAGLE_PLUGIN::getModificationTime( const wxString& aPath )
  2383. {
  2384. // File hasn't been loaded yet.
  2385. if( aPath.IsEmpty() )
  2386. return wxDateTime::Now();
  2387. wxFileName fn( aPath );
  2388. if( fn.IsFileReadable() )
  2389. return fn.GetModificationTime();
  2390. else
  2391. return wxDateTime( 0.0 );
  2392. }
  2393. void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
  2394. {
  2395. try
  2396. {
  2397. wxDateTime modtime = getModificationTime( aLibPath );
  2398. // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
  2399. // cache if either of the wxDateTime objects are invalid or the last file modification
  2400. // time differs from the current file modification time.
  2401. bool load = !m_mod_time.IsValid() || !modtime.IsValid() || m_mod_time != modtime;
  2402. if( aLibPath != m_lib_path || load )
  2403. {
  2404. wxXmlNode* doc;
  2405. LOCALE_IO toggle; // toggles on, then off, the C locale.
  2406. deleteTemplates();
  2407. // Set this before completion of loading, since we rely on it for
  2408. // text of an exception. Delay setting m_mod_time until after successful load
  2409. // however.
  2410. m_lib_path = aLibPath;
  2411. // 8 bit "filename" should be encoded according to disk filename encoding,
  2412. // (maybe this is current locale, maybe not, its a filesystem issue),
  2413. // and is not necessarily utf8.
  2414. string filename = (const char*) aLibPath.char_str( wxConvFile );
  2415. // Load the document
  2416. wxFileName fn( filename );
  2417. wxFFileInputStream stream( fn.GetFullPath() );
  2418. wxXmlDocument xmlDocument;
  2419. if( !stream.IsOk() || !xmlDocument.Load( stream ) )
  2420. {
  2421. THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'." ),
  2422. fn.GetFullPath() ) );
  2423. }
  2424. doc = xmlDocument.GetRoot();
  2425. wxXmlNode* drawing = MapChildren( doc )["drawing"];
  2426. NODE_MAP drawingChildren = MapChildren( drawing );
  2427. // clear the cu map and then rebuild it.
  2428. clear_cu_map();
  2429. m_xpath->push( "eagle.drawing.layers" );
  2430. wxXmlNode* layers = drawingChildren["layers"];
  2431. loadLayerDefs( layers );
  2432. mapEagleLayersToKicad();
  2433. m_xpath->pop();
  2434. m_xpath->push( "eagle.drawing.library" );
  2435. wxXmlNode* library = drawingChildren["library"];
  2436. loadLibrary( library, nullptr );
  2437. m_xpath->pop();
  2438. m_mod_time = modtime;
  2439. }
  2440. }
  2441. catch(...){}
  2442. // TODO: Handle exceptions
  2443. // catch( file_parser_error fpe )
  2444. // {
  2445. // // for xml_parser_error, what() has the line number in it,
  2446. // // but no byte offset. That should be an adequate error message.
  2447. // THROW_IO_ERROR( fpe.what() );
  2448. // }
  2449. //
  2450. // // Class ptree_error is a base class for xml_parser_error & file_parser_error,
  2451. // // so one catch should be OK for all errors.
  2452. // catch( ptree_error pte )
  2453. // {
  2454. // string errmsg = pte.what();
  2455. //
  2456. // errmsg += " @\n";
  2457. // errmsg += m_xpath->Contents();
  2458. //
  2459. // THROW_IO_ERROR( errmsg );
  2460. // }
  2461. }
  2462. void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
  2463. bool aBestEfforts, const PROPERTIES* aProperties )
  2464. {
  2465. wxString errorMsg;
  2466. init( aProperties );
  2467. try
  2468. {
  2469. cacheLib( aLibraryPath );
  2470. }
  2471. catch( const IO_ERROR& ioe )
  2472. {
  2473. errorMsg = ioe.What();
  2474. }
  2475. // Some of the files may have been parsed correctly so we want to add the valid files to
  2476. // the library.
  2477. for( FOOTPRINT_MAP::const_iterator it = m_templates.begin(); it != m_templates.end(); ++it )
  2478. aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
  2479. if( !errorMsg.IsEmpty() && !aBestEfforts )
  2480. THROW_IO_ERROR( errorMsg );
  2481. }
  2482. FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
  2483. const wxString& aFootprintName, bool aKeepUUID,
  2484. const PROPERTIES* aProperties )
  2485. {
  2486. init( aProperties );
  2487. cacheLib( aLibraryPath );
  2488. FOOTPRINT_MAP::const_iterator it = m_templates.find( aFootprintName );
  2489. if( it == m_templates.end() )
  2490. return nullptr;
  2491. // Return a copy of the template
  2492. FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate();
  2493. copy->SetParent( nullptr );
  2494. return copy;
  2495. }
  2496. void EAGLE_PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
  2497. {
  2498. PLUGIN::FootprintLibOptions( aListToAppendTo );
  2499. }