KiCad PCB EDA Suite
SCH_EAGLE_PLUGIN Class Reference

A SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files. More...

#include <sch_eagle_plugin.h>

Inheritance diagram for SCH_EAGLE_PLUGIN:
SCH_PLUGIN

Classes

struct  EAGLE_MISSING_CMP
 
struct  SEG_DESC_STRUCT
 

Public Member Functions

 SCH_EAGLE_PLUGIN ()
 
 ~SCH_EAGLE_PLUGIN ()
 
const wxString GetName () const override
 Return a brief hard coded name for this SCH_PLUGIN. More...
 
void SetReporter (REPORTER *aReporter) override
 Set an optional reporter for warnings/errors. More...
 
const wxString GetFileExtension () const override
 Return the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
virtual void SaveLibrary (const wxString &aFileName, const PROPERTIES *aProperties=nullptr)
 
virtual void Save (const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
virtual void EnumerateSymbolLib (wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
virtual void EnumerateSymbolLib (std::vector< LIB_PART * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
virtual LIB_PARTLoadSymbol (const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=nullptr)
 Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
virtual void SaveSymbol (const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr)
 Write aSymbol to an existing library located at aLibraryPath. More...
 
virtual void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr)
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
virtual void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Create a new empty symbol library at aLibraryPath. More...
 
virtual bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
virtual bool IsSymbolLibWritable (const wxString &aLibraryPath)
 Return true if the library at aLibraryPath is writable. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
virtual const wxString & GetError () const
 Return an error string to the caller. More...
 

Private Types

typedef struct SCH_EAGLE_PLUGIN::SEG_DESC_STRUCT SEG_DESC
 Segments representing wires for intersection checking. More...
 

Private Member Functions

void loadDrawing (wxXmlNode *aDrawingNode)
 
void loadLayerDefs (wxXmlNode *aLayers)
 
void loadSchematic (wxXmlNode *aSchematicNode)
 
void loadSheet (wxXmlNode *aSheetNode, int sheetcount)
 
void loadInstance (wxXmlNode *aInstanceNode)
 
EAGLE_LIBRARYloadLibrary (wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
 
void countNets (wxXmlNode *aSchematicNode)
 
void moveLabels (SCH_ITEM *aWire, const wxPoint &aNewEndPoint)
 Move any labels on the wire to the new end point of the wire. More...
 
void addBusEntries ()
 This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Eagle bus segment. More...
 
SCH_LAYER_ID kiCadLayer (int aEagleLayer)
 Return the matching layer or return LAYER_NOTES. More...
 
std::pair< VECTOR2I, const SEG * > findNearestLinePoint (const wxPoint &aPoint, const std::vector< SEG > &aLines) const
 
void loadSegments (wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
 
SCH_LINEloadWire (wxXmlNode *aWireNode)
 
SCH_TEXTloadLabel (wxXmlNode *aLabelNode, const wxString &aNetName)
 
SCH_JUNCTIONloadJunction (wxXmlNode *aJunction)
 
SCH_TEXTloadPlainText (wxXmlNode *aSchText)
 
void loadFrame (wxXmlNode *aFrameNode, std::vector< SCH_LINE * > &aLines)
 
bool loadSymbol (wxXmlNode *aSymbolNode, std::unique_ptr< LIB_PART > &aPart, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
 
LIB_CIRCLEloadSymbolCircle (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aCircleNode, int aGateNumber)
 
LIB_RECTANGLEloadSymbolRectangle (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aRectNode, int aGateNumber)
 
LIB_POLYLINEloadSymbolPolyLine (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aPolygonNode, int aGateNumber)
 
LIB_ITEMloadSymbolWire (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aWireNode, int aGateNumber)
 
LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *, EPIN *epin, int aGateNumber)
 
LIB_TEXTloadSymbolText (std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aLibText, int aGateNumber)
 
void loadFrame (wxXmlNode *aFrameNode, std::vector< LIB_ITEM * > &aLines)
 
void loadTextAttributes (EDA_TEXT *aText, const ETEXT &aAttribs) const
 
void loadFieldAttributes (LIB_FIELD *aField, const LIB_TEXT *aText) const
 Move net labels that are detached from any wire to the nearest wire. More...
 
void adjustNetLabels ()
 
wxString translateEagleBusName (const wxString &aEagleName) const
 Translate an Eagle-style bus name into one that is KiCad-compatible. More...
 
wxString getLibName ()
 
wxFileName getLibFileName ()
 Checks if there are other wires or pins at the position of the tested pin. More...
 
bool checkConnections (const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
 
void addImplicitConnections (SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
 Create net labels to emulate implicit connections in Eagle. More...
 
bool netHasPowerDriver (SCH_LINE *aLine, const wxString &aNetName) const
 

Static Private Member Functions

static wxString fixSymbolName (const wxString &aName)
 Fix invalid characters in Eagle symbol names. More...
 

Private Attributes

REPORTERm_reporter
 Reporter for warnings/errors. More...
 
std::map< wxString, EAGLE_MISSING_CMPm_missingCmps
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded. More...
 
SCH_SHEETm_currentSheet
 The current sheet of the schematic being loaded. More...
 
wxString m_version
 Eagle file version. More...
 
wxFileName m_filename
 
wxString m_libName
 Library name to save symbols. More...
 
SCHEMATICm_schematic
 Passed to Load(), the schematic object being loaded. More...
 
EPART_MAP m_partlist
 
std::map< wxString, EAGLE_LIBRARYm_eagleLibs
 
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
 Plugin to create the KiCad symbol library. More...
 
std::unique_ptr< PROPERTIESm_properties
 Library plugin properties. More...
 
std::map< wxString, int > m_netCounts
 
std::map< int, SCH_LAYER_IDm_layerMap
 Wire intersection points, used for quick checks whether placing a net label in a particular place would short two nets. More...
 
std::vector< VECTOR2Im_wireIntersections
 Wires and labels of a single connection (segment in Eagle nomenclature) More...
 
std::vector< SEG_DESCm_segments
 Nets as defined in the <nets> sections of an Eagle schematic file. More...
 
std::map< wxString, ENETm_nets
 Positions of pins and wire endings mapped to its parent. More...
 
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
 

Detailed Description

A SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files.

As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.

Definition at line 81 of file sch_eagle_plugin.h.

Member Typedef Documentation

◆ SEG_DESC

Segments representing wires for intersection checking.

Constructor & Destructor Documentation

◆ SCH_EAGLE_PLUGIN()

SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN ( )

Definition at line 352 of file sch_eagle_plugin.cpp.

353 {
354  m_rootSheet = nullptr;
355  m_currentSheet = nullptr;
356  m_schematic = nullptr;
357 
359 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
static REPORTER & GetInstance()
Definition: reporter.cpp:163
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
REPORTER * m_reporter
Reporter for warnings/errors.
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.

References WXLOG_REPORTER::GetInstance().

◆ ~SCH_EAGLE_PLUGIN()

SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN ( )

Definition at line 362 of file sch_eagle_plugin.cpp.

363 {
364 }

Member Function Documentation

◆ addBusEntries()

void SCH_EAGLE_PLUGIN::addBusEntries ( )
private

This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Eagle bus segment.

Definition at line 2240 of file sch_eagle_plugin.cpp.

2241 {
2242  // Add bus entry symbols
2243  // TODO: Cleanup this function and break into pieces
2244 
2245  // for each wire segment, compare each end with all busses.
2246  // If the wire end is found to end on a bus segment, place a bus entry symbol.
2247 
2248  for( auto it1 = m_currentSheet->GetScreen()->Items().OfType( SCH_LINE_T ).begin();
2249  it1 != m_currentSheet->GetScreen()->Items().end(); ++it1 )
2250  {
2251  SCH_LINE* bus = static_cast<SCH_LINE*>( *it1 );
2252 
2253  // Check line type for wire
2254  if( bus->GetLayer() != LAYER_BUS )
2255  continue;
2256 
2257  wxPoint busstart = bus->GetStartPoint();
2258  wxPoint busend = bus->GetEndPoint();
2259 
2260  auto it2 = it1;
2261  ++it2;
2262 
2263  for( ; it2 != m_currentSheet->GetScreen()->Items().end(); ++it2 )
2264  {
2265  SCH_LINE* line = static_cast<SCH_LINE*>( *it2 );
2266 
2267  // Check line type for bus
2268  if( ( (SCH_LINE*) *it2 )->GetLayer() == LAYER_WIRE )
2269  {
2270  // Get points of both segments.
2271  wxPoint linestart = line->GetStartPoint();
2272  wxPoint lineend = line->GetEndPoint();
2273 
2274  // Test for horizontal wire and vertical bus
2275  if( linestart.y == lineend.y && busstart.x == busend.x )
2276  {
2277  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
2278  {
2279  // Wire start is on a bus.
2280  // Wire start is on the vertical bus
2281 
2282  // if the end of the wire is to the left of the bus
2283  if( lineend.x < busstart.x )
2284  {
2285  // |
2286  // ---|
2287  // |
2288  if( TestSegmentHit(
2289  linestart + wxPoint( 0, -100 ), busstart, busend, 0 ) )
2290  {
2291  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2292  linestart + wxPoint( -100, 0 ), true );
2293  busEntry->SetFlags( IS_NEW );
2294  m_currentSheet->GetScreen()->Append( busEntry );
2295  moveLabels( line, linestart + wxPoint( -100, 0 ) );
2296  line->SetStartPoint( linestart + wxPoint( -100, 0 ) );
2297  }
2298  else if( TestSegmentHit(
2299  linestart + wxPoint( 0, 100 ), busstart, busend, 0 ) )
2300  {
2301  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2302  linestart + wxPoint( -100, 0 ), false );
2303  busEntry->SetFlags( IS_NEW );
2304  m_currentSheet->GetScreen()->Append( busEntry );
2305  moveLabels( line, linestart + wxPoint( -100, 0 ) );
2306  line->SetStartPoint( linestart + wxPoint( -100, 0 ) );
2307  }
2308  else
2309  {
2310  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2311  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2312 
2313  SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
2314  m_currentSheet->GetScreen()->Append( marker );
2315  }
2316  }
2317  // else the wire end is to the right of the bus
2318  // Wire is to the right of the bus
2319  // |
2320  // |----
2321  // |
2322  else
2323  {
2324  // test is bus exists above the wire
2325  if( TestSegmentHit(
2326  linestart + wxPoint( 0, -100 ), busstart, busend, 0 ) )
2327  {
2328  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2329  linestart + wxPoint( 0, -100 ), false );
2330  busEntry->SetFlags( IS_NEW );
2331  m_currentSheet->GetScreen()->Append( busEntry );
2332  moveLabels( line, linestart + wxPoint( 100, 0 ) );
2333  line->SetStartPoint( linestart + wxPoint( 100, 0 ) );
2334  }
2335  // test is bus exists below the wire
2336  else if( TestSegmentHit(
2337  linestart + wxPoint( 0, 100 ), busstart, busend, 0 ) )
2338  {
2339  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2340  linestart + wxPoint( 0, 100 ), true );
2341  busEntry->SetFlags( IS_NEW );
2342  m_currentSheet->GetScreen()->Append( busEntry );
2343  moveLabels( line, linestart + wxPoint( 100, 0 ) );
2344  line->SetStartPoint( linestart + wxPoint( 100, 0 ) );
2345  }
2346  else
2347  {
2348  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2349  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2350 
2351  SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
2352  m_currentSheet->GetScreen()->Append( marker );
2353  }
2354  }
2355  }
2356 
2357  // Same thing but test end of the wire instead.
2358  if( TestSegmentHit( lineend, busstart, busend, 0 ) )
2359  {
2360  // Wire end is on the vertical bus
2361 
2362  // if the start of the wire is to the left of the bus
2363  if( linestart.x < busstart.x )
2364  {
2365  // Test if bus exists above the wire
2366  if( TestSegmentHit( lineend + wxPoint( 0, 100 ), busstart, busend, 0 ) )
2367  {
2368  // |
2369  // ___/|
2370  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2371  lineend + wxPoint( -100, 0 ), false );
2372  busEntry->SetFlags( IS_NEW );
2373  m_currentSheet->GetScreen()->Append( busEntry );
2374  moveLabels( line, lineend + wxPoint( -100, 0 ) );
2375  line->SetEndPoint( lineend + wxPoint( -100, 0 ) );
2376  }
2377  // Test if bus exists below the wire
2378  else if( TestSegmentHit(
2379  lineend + wxPoint( 0, -100 ), busstart, busend, 0 ) )
2380  {
2381  SCH_BUS_WIRE_ENTRY* busEntry =
2382  new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( -100, 0 ),
2383  true );
2384  busEntry->SetFlags( IS_NEW );
2385  m_currentSheet->GetScreen()->Append( busEntry );
2386  moveLabels( line, lineend + wxPoint( -100, 0 ) );
2387  line->SetEndPoint( lineend + wxPoint( -100, 0 ) );
2388  }
2389  else
2390  {
2391  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2392  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2393 
2394  SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
2395  m_currentSheet->GetScreen()->Append( marker );
2396  }
2397  }
2398  // else the start of the wire is to the right of the bus
2399  // |
2400  // |----
2401  // |
2402  else
2403  {
2404  // test if bus existed above the wire
2405  if( TestSegmentHit(
2406  lineend + wxPoint( 0, -100 ), busstart, busend, 0 ) )
2407  {
2408  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2409  lineend + wxPoint( 0, -100 ), false );
2410  busEntry->SetFlags( IS_NEW );
2411  m_currentSheet->GetScreen()->Append( busEntry );
2412  moveLabels( line, lineend + wxPoint( 100, 0 ) );
2413  line->SetEndPoint( lineend + wxPoint( 100, 0 ) );
2414  }
2415  // test if bus existed below the wire
2416  else if( TestSegmentHit(
2417  lineend + wxPoint( 0, 100 ), busstart, busend, 0 ) )
2418  {
2419  SCH_BUS_WIRE_ENTRY* busEntry =
2420  new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( 0, 100 ), true );
2421  busEntry->SetFlags( IS_NEW );
2422  m_currentSheet->GetScreen()->Append( busEntry );
2423  moveLabels( line, lineend + wxPoint( 100, 0 ) );
2424  line->SetEndPoint( lineend + wxPoint( 100, 0 ) );
2425  }
2426  else
2427  {
2428  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2429  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2430 
2431  SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
2432  m_currentSheet->GetScreen()->Append( marker );
2433  }
2434  }
2435  }
2436  } // if( linestart.y == lineend.y && busstart.x == busend.x)
2437 
2438  // Test for horizontal wire and vertical bus
2439  if( linestart.x == lineend.x && busstart.y == busend.y )
2440  {
2441  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
2442  {
2443  // Wire start is on the bus
2444  // If wire end is above the bus,
2445  if( lineend.y < busstart.y )
2446  {
2447  // Test for bus existence to the left of the wire
2448  if( TestSegmentHit(
2449  linestart + wxPoint( -100, 0 ), busstart, busend, 0 ) )
2450  {
2451  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2452  linestart + wxPoint( -100, 0 ), true );
2453  busEntry->SetFlags( IS_NEW );
2454  m_currentSheet->GetScreen()->Append( busEntry );
2455  moveLabels( line, linestart + wxPoint( 0, -100 ) );
2456  line->SetStartPoint( linestart + wxPoint( 0, -100 ) );
2457  }
2458  else if( TestSegmentHit(
2459  linestart + wxPoint( 100, 0 ), busstart, busend, 0 ) )
2460  {
2461  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2462  linestart + wxPoint( 0, 100 ), false );
2463  busEntry->SetFlags( IS_NEW );
2464  m_currentSheet->GetScreen()->Append( busEntry );
2465  moveLabels( line, linestart + wxPoint( 0, -100 ) );
2466  line->SetStartPoint( linestart + wxPoint( 0, -100 ) );
2467  }
2468  else
2469  {
2470  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2471  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2472 
2473  SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
2474  m_currentSheet->GetScreen()->Append( marker );
2475  }
2476  }
2477  else // wire end is below the bus.
2478  {
2479  // Test for bus existence to the left of the wire
2480  if( TestSegmentHit(
2481  linestart + wxPoint( -100, 0 ), busstart, busend, 0 ) )
2482  {
2483  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2484  linestart + wxPoint( -100, 0 ), false );
2485  busEntry->SetFlags( IS_NEW );
2486  m_currentSheet->GetScreen()->Append( busEntry );
2487  moveLabels( line, linestart + wxPoint( 0, 100 ) );
2488  line->SetStartPoint( linestart + wxPoint( 0, 100 ) );
2489  }
2490  else if( TestSegmentHit(
2491  linestart + wxPoint( 100, 0 ), busstart, busend, 0 ) )
2492  {
2493  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2494  linestart + wxPoint( 100, 0 ), true );
2495  busEntry->SetFlags( IS_NEW );
2496  m_currentSheet->GetScreen()->Append( busEntry );
2497  moveLabels( line, linestart + wxPoint( 0, 100 ) );
2498  line->SetStartPoint( linestart + wxPoint( 0, 100 ) );
2499  }
2500  else
2501  {
2502  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2503  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2504 
2505  SCH_MARKER* marker = new SCH_MARKER( ercItem, linestart );
2506  m_currentSheet->GetScreen()->Append( marker );
2507  }
2508  }
2509  }
2510 
2511  if( TestSegmentHit( lineend, busstart, busend, 0 ) )
2512  {
2513  // Wire end is on the bus
2514  // If wire start is above the bus,
2515 
2516  if( linestart.y < busstart.y )
2517  {
2518  // Test for bus existence to the left of the wire
2519  if( TestSegmentHit(
2520  lineend + wxPoint( -100, 0 ), busstart, busend, 0 ) )
2521  {
2522  SCH_BUS_WIRE_ENTRY* busEntry =
2523  new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( -100, 0 ),
2524  true );
2525  busEntry->SetFlags( IS_NEW );
2526  m_currentSheet->GetScreen()->Append( busEntry );
2527  moveLabels( line, lineend + wxPoint( 0, -100 ) );
2528  line->SetEndPoint( lineend + wxPoint( 0, -100 ) );
2529  }
2530  else if( TestSegmentHit(
2531  lineend + wxPoint( 100, 0 ), busstart, busend, 0 ) )
2532  {
2533  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2534  lineend + wxPoint( 0, -100 ), false );
2535  busEntry->SetFlags( IS_NEW );
2536  m_currentSheet->GetScreen()->Append( busEntry );
2537  moveLabels( line, lineend + wxPoint( 0, -100 ) );
2538  line->SetEndPoint( lineend + wxPoint( 0, -100 ) );
2539  }
2540  else
2541  {
2542  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2543  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2544 
2545  SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
2546  m_currentSheet->GetScreen()->Append( marker );
2547  }
2548  }
2549  else // wire end is below the bus.
2550  {
2551  // Test for bus existence to the left of the wire
2552  if( TestSegmentHit(
2553  lineend + wxPoint( -100, 0 ), busstart, busend, 0 ) )
2554  {
2555  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY(
2556  lineend + wxPoint( -100, 0 ), false );
2557  busEntry->SetFlags( IS_NEW );
2558  m_currentSheet->GetScreen()->Append( busEntry );
2559  moveLabels( line, lineend + wxPoint( 0, 100 ) );
2560  line->SetEndPoint( lineend + wxPoint( 0, 100 ) );
2561  }
2562  else if( TestSegmentHit(
2563  lineend + wxPoint( 100, 0 ), busstart, busend, 0 ) )
2564  {
2565  SCH_BUS_WIRE_ENTRY* busEntry =
2566  new SCH_BUS_WIRE_ENTRY( lineend + wxPoint( 0, 100 ), true );
2567  busEntry->SetFlags( IS_NEW );
2568  m_currentSheet->GetScreen()->Append( busEntry );
2569  moveLabels( line, lineend + wxPoint( 0, 100 ) );
2570  line->SetEndPoint( lineend + wxPoint( 0, 100 ) );
2571  }
2572  else
2573  {
2574  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( 0 );
2575  ercItem->SetErrorMessage( _( "Bus Entry needed" ) );
2576 
2577  SCH_MARKER* marker = new SCH_MARKER( ercItem, lineend );
2578  m_currentSheet->GetScreen()->Append( marker );
2579  }
2580  }
2581  }
2582  }
2583 
2584  linestart = line->GetStartPoint();
2585  lineend = line->GetEndPoint();
2586  busstart = bus->GetStartPoint();
2587  busend = bus->GetEndPoint();
2588 
2589  // bus entry wire isn't horizontal or vertical
2590  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
2591  {
2592  wxPoint wirevector = linestart - lineend;
2593 
2594  if( wirevector.x > 0 )
2595  {
2596  if( wirevector.y > 0 )
2597  {
2598  wxPoint p = linestart + wxPoint( -100, -100 );
2599  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, false );
2600  busEntry->SetFlags( IS_NEW );
2601  m_currentSheet->GetScreen()->Append( busEntry );
2602  moveLabels( line, p );
2603 
2604  if( p == lineend ) // wire is overlapped by bus entry symbol
2605  {
2606  m_currentSheet->GetScreen()->DeleteItem( line );
2607  line = nullptr;
2608  }
2609  else
2610  {
2611  line->SetStartPoint( p );
2612  }
2613  }
2614  else
2615  {
2616  wxPoint p = linestart + wxPoint( -100, 100 );
2617  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, true );
2618  busEntry->SetFlags( IS_NEW );
2619  m_currentSheet->GetScreen()->Append( busEntry );
2620 
2621  moveLabels( line, p );
2622 
2623  if( p == lineend ) // wire is overlapped by bus entry symbol
2624  {
2625  m_currentSheet->GetScreen()->DeleteItem( line );
2626  line = nullptr;
2627  }
2628  else
2629  {
2630  line->SetStartPoint( p );
2631  }
2632  }
2633  }
2634  else
2635  {
2636  if( wirevector.y > 0 )
2637  {
2638  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart,
2639  true );
2640  busEntry->SetFlags( IS_NEW );
2641  m_currentSheet->GetScreen()->Append( busEntry );
2642 
2643  moveLabels( line, linestart + wxPoint( 100, -100 ) );
2644 
2645  if( linestart + wxPoint( 100, -100 )
2646  == lineend ) // wire is overlapped by bus entry symbol
2647  {
2648  m_currentSheet->GetScreen()->DeleteItem( line );
2649  line = nullptr;
2650  }
2651  else
2652  {
2653  line->SetStartPoint( linestart + wxPoint( 100, -100 ) );
2654  }
2655  }
2656  else
2657  {
2658  SCH_BUS_WIRE_ENTRY* busEntry =
2659  new SCH_BUS_WIRE_ENTRY( linestart, false );
2660  busEntry->SetFlags( IS_NEW );
2661  m_currentSheet->GetScreen()->Append( busEntry );
2662  moveLabels( line, linestart + wxPoint( 100, 100 ) );
2663 
2664  if( linestart + wxPoint( 100, 100 )
2665  == lineend ) // wire is overlapped by bus entry symbol
2666  {
2667  m_currentSheet->GetScreen()->DeleteItem( line );
2668  line = nullptr;
2669  }
2670  else
2671  {
2672  line->SetStartPoint( linestart + wxPoint( 100, 100 ) );
2673  }
2674  }
2675  }
2676  }
2677 
2678  if( line && TestSegmentHit( lineend, busstart, busend, 0 ) )
2679  {
2680  wxPoint wirevector = linestart - lineend;
2681 
2682  if( wirevector.x > 0 )
2683  {
2684  if( wirevector.y > 0 )
2685  {
2686  wxPoint p = lineend + wxPoint( 100, 100 );
2687  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend, false );
2688  busEntry->SetFlags( IS_NEW );
2689  m_currentSheet->GetScreen()->Append( busEntry );
2690 
2691  moveLabels( line, p );
2692 
2693  if( p == linestart ) // wire is overlapped by bus entry symbol
2694  {
2695  m_currentSheet->GetScreen()->DeleteItem( line );
2696  }
2697  else
2698  {
2699  line->SetEndPoint( p );
2700  }
2701  }
2702  else
2703  {
2704  wxPoint p = lineend + wxPoint( 100, -100 );
2705  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend, true );
2706  busEntry->SetFlags( IS_NEW );
2707  m_currentSheet->GetScreen()->Append( busEntry );
2708 
2709  moveLabels( line, p );
2710 
2711  if( p == linestart ) // wire is overlapped by bus entry symbol
2712  {
2713  m_currentSheet->GetScreen()->DeleteItem( line );
2714  }
2715  else
2716  {
2717  line->SetEndPoint( p );
2718  }
2719  }
2720  }
2721  else
2722  {
2723  if( wirevector.y > 0 )
2724  {
2725  wxPoint p = lineend + wxPoint( -100, 100 );
2726  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, true );
2727  busEntry->SetFlags( IS_NEW );
2728  m_currentSheet->GetScreen()->Append( busEntry );
2729  moveLabels( line, p );
2730 
2731  if( p == linestart ) // wire is overlapped by bus entry symbol
2732  {
2733  m_currentSheet->GetScreen()->DeleteItem( line );
2734  }
2735  else
2736  {
2737  line->SetEndPoint( p );
2738  }
2739  }
2740  else
2741  {
2742  wxPoint p = lineend + wxPoint( -100, -100 );
2743  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, false );
2744  busEntry->SetFlags( IS_NEW );
2745  m_currentSheet->GetScreen()->Append( busEntry );
2746  moveLabels( line, p );
2747 
2748  if( p == linestart ) // wire is overlapped by bus entry symbol
2749  {
2750  m_currentSheet->GetScreen()->DeleteItem( line );
2751  }
2752  else
2753  {
2754  line->SetEndPoint( p );
2755  }
2756  }
2757  }
2758  }
2759  }
2760  }
2761  } // for ( bus ..
2762 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:216
wxPoint GetStartPoint() const
Definition: sch_line.h:90
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:189
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:203
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:282
iterator end()
Definition: sch_rtree.h:250
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:91
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
iterator begin()
Definition: sch_rtree.h:205
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
#define _(s)
Definition: 3d_actions.cpp:33
EE_RTREE & Items()
Definition: sch_screen.h:103
void moveLabels(SCH_ITEM *aWire, const wxPoint &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
Class for a wire to bus entry.
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References _, ERC_ITEM::Create(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetStartPoint(), IS_NEW, LAYER_BUS, LAYER_WIRE, SCH_LINE_T, SCH_LINE::SetEndPoint(), EDA_ITEM::SetFlags(), SCH_LINE::SetStartPoint(), and TestSegmentHit().

◆ addImplicitConnections()

void SCH_EAGLE_PLUGIN::addImplicitConnections ( SCH_COMPONENT aComponent,
SCH_SCREEN aScreen,
bool  aUpdateSet 
)
private

Create net labels to emulate implicit connections in Eagle.

Each named power input pin creates an implicit connection in Eagle. To emulate this behavior one needs to attach global net labels to the mentioned pins. This is is also expected for the units that are not instantiated in the schematics, therefore such units need to be stored in order to create them at later stage.

Parameters
aComponentis the component to process.
aScreenis the screen where net labels should be added.
aUpdateSetdecides whether the missing units data should be updated.

Definition at line 2796 of file sch_eagle_plugin.cpp.

2798 {
2799  wxCHECK( aComponent->GetPartRef(), /*void*/ );
2800 
2801  // Normally power parts also have power input pins,
2802  // but they already force net names on the attached wires
2803  if( aComponent->GetPartRef()->IsPower() )
2804  return;
2805 
2806  int unit = aComponent->GetUnit();
2807  const wxString reference = aComponent->GetField( REFERENCE_FIELD )->GetText();
2808  std::vector<LIB_PIN*> pins;
2809  aComponent->GetPartRef()->GetPins( pins );
2810  std::set<int> missingUnits;
2811 
2812  // Search all units for pins creating implicit connections
2813  for( const auto& pin : pins )
2814  {
2815  if( pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
2816  {
2817  bool pinInUnit = !unit || pin->GetUnit() == unit; // pin belongs to the tested unit
2818 
2819  // Create a global net label only if there are no other wires/pins attached
2820  if( pinInUnit )
2821  {
2822  if( !checkConnections( aComponent, pin ) )
2823  {
2824  // Create a net label to force the net name on the pin
2825  SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
2826  netLabel->SetPosition( aComponent->GetPinPhysicalPosition( pin ) );
2827  netLabel->SetText( extractNetName( pin->GetName() ) );
2828  netLabel->SetTextSize( wxSize( Mils2iu( 40 ), Mils2iu( 40 ) ) );
2830  aScreen->Append( netLabel );
2831  }
2832  }
2833  else if( aUpdateSet )
2834  {
2835  // Found a pin creating implicit connection information in another unit.
2836  // Such units will be instantiated if they do not appear in another sheet and
2837  // processed later.
2838  wxASSERT( pin->GetUnit() );
2839  missingUnits.insert( pin->GetUnit() );
2840  }
2841  }
2842  }
2843 
2844  if( aUpdateSet && aComponent->GetPartRef()->GetUnitCount() > 1 )
2845  {
2846  auto cmpIt = m_missingCmps.find( reference );
2847 
2848  // The first unit found has always already been processed.
2849  if( cmpIt == m_missingCmps.end() )
2850  {
2851  EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
2852  entry.cmp = aComponent;
2853  entry.units.emplace( unit, false );
2854  }
2855  else
2856  {
2857  // Set the flag indicating this unit has been processed.
2858  cmpIt->second.units[unit] = false;
2859  }
2860 
2861  if( !missingUnits.empty() ) // Save the units that need later processing
2862  {
2863  EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
2864  entry.cmp = aComponent;
2865 
2866  // Add units that haven't already been processed.
2867  for( int i : missingUnits )
2868  {
2869  if( entry.units.find( i ) != entry.units.end() )
2870  entry.units.emplace( i, true );
2871  }
2872  }
2873  }
2874 }
Field Reference of part, i.e. "IC21".
power input (GND, VCC for ICs). Must be connected to a power output.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:693
bool checkConnections(const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
int GetUnit() const
Definition: sch_symbol.h:195
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
std::unique_ptr< LIB_PART > & GetPartRef()
Definition: sch_symbol.h:164
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
static wxString extractNetName(const wxString &aPinName)
void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:948
void SetPosition(const wxPoint &aPosition) override
Definition: sch_text.h:294
wxPoint GetPinPhysicalPosition(const LIB_PIN *Pin) const
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

References SCH_SCREEN::Append(), SCH_EAGLE_PLUGIN::EAGLE_MISSING_CMP::cmp, extractNetName(), SCH_COMPONENT::GetField(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetPinPhysicalPosition(), EDA_TEXT::GetText(), SCH_COMPONENT::GetUnit(), LABEL_SPIN_STYLE::LEFT, pin, PT_POWER_IN, REFERENCE_FIELD, SCH_GLOBALLABEL::SetLabelSpinStyle(), SCH_TEXT::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), and SCH_EAGLE_PLUGIN::EAGLE_MISSING_CMP::units.

◆ adjustNetLabels()

void SCH_EAGLE_PLUGIN::adjustNetLabels ( )
private

Definition at line 2128 of file sch_eagle_plugin.cpp.

2129 {
2130  // Eagle supports detached labels, so a label does not need to be placed on a wire
2131  // to be associated with it. KiCad needs to move them, so the labels actually touch the
2132  // corresponding wires.
2133 
2134  // Sort the intersection points to speed up the search process
2135  std::sort( m_wireIntersections.begin(), m_wireIntersections.end() );
2136 
2137  auto onIntersection =
2138  [&]( const VECTOR2I& aPos )
2139  {
2140  return std::binary_search( m_wireIntersections.begin(),
2141  m_wireIntersections.end(), aPos );
2142  };
2143 
2144  for( auto& segDesc : m_segments )
2145  {
2146  for( SCH_TEXT* label : segDesc.labels )
2147  {
2148  VECTOR2I labelPos( label->GetPosition() );
2149  const SEG* segAttached = segDesc.LabelAttached( label );
2150 
2151  if( segAttached && !onIntersection( labelPos ) )
2152  continue; // label is placed correctly
2153 
2154 
2155  // Move the label to the nearest wire
2156  if( !segAttached )
2157  {
2158  std::tie( labelPos, segAttached ) =
2159  findNearestLinePoint( label->GetPosition(), segDesc.segs );
2160 
2161  if( !segAttached ) // we cannot do anything
2162  continue;
2163  }
2164 
2165 
2166  // Create a vector pointing in the direction of the wire, 50 mils long
2167  VECTOR2I wireDirection( segAttached->B - segAttached->A );
2168  wireDirection = wireDirection.Resize( Mils2iu( 50 ) );
2169  const VECTOR2I origPos( labelPos );
2170 
2171  // Flags determining the search direction
2172  bool checkPositive = true, checkNegative = true, move = false;
2173  int trial = 0;
2174 
2175  // Be sure the label is not placed on a wire intersection
2176  while( ( !move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
2177  {
2178  move = false;
2179 
2180  // Move along the attached wire to find the new label position
2181  if( trial % 2 == 1 )
2182  {
2183  labelPos = wxPoint( origPos + wireDirection * trial / 2 );
2184  move = checkPositive = segAttached->Contains( labelPos );
2185  }
2186  else
2187  {
2188  labelPos = wxPoint( origPos - wireDirection * trial / 2 );
2189  move = checkNegative = segAttached->Contains( labelPos );
2190  }
2191 
2192  ++trial;
2193  }
2194 
2195  if( move )
2196  label->SetPosition( wxPoint( labelPos ) );
2197  }
2198  }
2199 
2200  m_segments.clear();
2201  m_wireIntersections.clear();
2202 }
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const wxPoint &aPoint, const std::vector< SEG > &aLines) const
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
wxPoint GetPosition() const override
Definition: sch_text.h:293
Definition: seg.h:41
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
void SetPosition(const wxPoint &aPosition) override
Definition: sch_text.h:294

References SCH_TEXT::GetPosition(), move, VECTOR2< T >::Resize(), and SCH_TEXT::SetPosition().

◆ checkConnections()

bool SCH_EAGLE_PLUGIN::checkConnections ( const SCH_COMPONENT aComponent,
const LIB_PIN aPin 
) const
private

Definition at line 2781 of file sch_eagle_plugin.cpp.

2783 {
2784  wxPoint pinPosition = aComponent->GetPinPhysicalPosition( aPin );
2785  auto pointIt = m_connPoints.find( pinPosition );
2786 
2787  if( pointIt == m_connPoints.end() )
2788  return false;
2789 
2790  const auto& items = pointIt->second;
2791  wxASSERT( items.find( aPin ) != items.end() );
2792  return items.size() > 1;
2793 }
wxPoint GetPinPhysicalPosition(const LIB_PIN *Pin) const
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints

References SCH_COMPONENT::GetPinPhysicalPosition().

◆ CheckHeader()

bool SCH_EAGLE_PLUGIN::CheckHeader ( const wxString &  aFileName)
overridevirtual

Return true if the first line in aFileName begins with the expected header.

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 2205 of file sch_eagle_plugin.cpp.

2206 {
2207  // Open file and check first line
2208  wxTextFile tempFile;
2209 
2210  tempFile.Open( aFileName );
2211  wxString firstline;
2212 
2213  // read the first line
2214  firstline = tempFile.GetFirstLine();
2215  wxString secondline = tempFile.GetNextLine();
2216  wxString thirdline = tempFile.GetNextLine();
2217  tempFile.Close();
2218 
2219  return firstline.StartsWith( "<?xml" ) && secondline.StartsWith( "<!DOCTYPE eagle SYSTEM" )
2220  && thirdline.StartsWith( "<eagle version" );
2221 }

◆ countNets()

void SCH_EAGLE_PLUGIN::countNets ( wxXmlNode *  aSchematicNode)
private

Definition at line 517 of file sch_eagle_plugin.cpp.

518 {
519  // Map all children into a readable dictionary
520  NODE_MAP schematicChildren = MapChildren( aSchematicNode );
521 
522  // Loop through all the sheets
523  wxXmlNode* sheetNode = getChildrenNodes( schematicChildren, "sheets" );
524 
525  while( sheetNode )
526  {
527  NODE_MAP sheetChildren = MapChildren( sheetNode );
528 
529  // Loop through all nets
530  // From the DTD: "Net is an electrical connection in a schematic."
531  wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
532 
533  while( netNode )
534  {
535  wxString netName = netNode->GetAttribute( "name" );
536 
537  if( m_netCounts.count( netName ) )
538  m_netCounts[netName] = m_netCounts[netName] + 1;
539  else
540  m_netCounts[netName] = 1;
541 
542  // Get next net
543  netNode = netNode->GetNext();
544  }
545 
546  sheetNode = sheetNode->GetNext();
547  }
548 }
std::map< wxString, int > m_netCounts
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:57

References getChildrenNodes(), and MapChildren().

◆ CreateSymbolLib()

void SCH_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Create a new empty symbol library at aLibraryPath.

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

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 110 of file sch_plugin.cpp.

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

References not_implemented().

◆ DeleteSymbol()

void SCH_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aSymbolName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 102 of file sch_plugin.cpp.

104 {
105  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
106  not_implemented( this, __FUNCTION__ );
107 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ DeleteSymbolLib()

bool SCH_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

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

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 117 of file sch_plugin.cpp.

118 {
119  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
120  not_implemented( this, __FUNCTION__ );
121  return false;
122 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ EnumerateSymbolLib() [1/2]

void SCH_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aSymbolNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Populate a list of LIB_PART alias names contained within the library aLibraryPath.

Parameters
aSymbolNameListis an array to populate with the LIB_PART names associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_PART objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 67 of file sch_plugin.cpp.

70 {
71  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
72  not_implemented( this, __FUNCTION__ );
73 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ EnumerateSymbolLib() [2/2]

void SCH_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_PART * > &  aSymbolList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Populate a list of LIB_PART aliases contained within the library aLibraryPath.

Note
It is the responsibility of the caller to delete the returned object from the heap. Failure to do this will result in memory leaks.
Parameters
aSymbolListis an array to populate with the LIB_PART pointers associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_PART objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 76 of file sch_plugin.cpp.

79 {
80  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
81  not_implemented( this, __FUNCTION__ );
82 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ findNearestLinePoint()

std::pair< VECTOR2I, const SEG * > SCH_EAGLE_PLUGIN::findNearestLinePoint ( const wxPoint &  aPoint,
const std::vector< SEG > &  aLines 
) const
private

Definition at line 1100 of file sch_eagle_plugin.cpp.

1102 {
1103  VECTOR2I nearestPoint;
1104  const SEG* nearestLine = nullptr;
1105 
1106  float d, mindistance = std::numeric_limits<float>::max();
1107 
1108  // Find the nearest start, middle or end of a line from the list of lines.
1109  for( const SEG& line : aLines )
1110  {
1111  auto testpoint = line.A;
1112  d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
1113 
1114  if( d < mindistance )
1115  {
1116  mindistance = d;
1117  nearestPoint = testpoint;
1118  nearestLine = &line;
1119  }
1120 
1121  testpoint = line.Center();
1122  d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
1123 
1124  if( d < mindistance )
1125  {
1126  mindistance = d;
1127  nearestPoint = testpoint;
1128  nearestLine = &line;
1129  }
1130 
1131  testpoint = line.B;
1132  d = sqrt( abs( ( ( aPoint.x - testpoint.x ) ^ 2 ) + ( ( aPoint.y - testpoint.y ) ^ 2 ) ) );
1133 
1134  if( d < mindistance )
1135  {
1136  mindistance = d;
1137  nearestPoint = testpoint;
1138  nearestLine = &line;
1139  }
1140  }
1141 
1142  return std::make_pair( nearestPoint, nearestLine );
1143 }
VECTOR2I Center() const
Definition: seg.h:384
Definition: seg.h:41
VECTOR2I B
Definition: seg.h:50

References SEG::B, and SEG::Center().

◆ fixSymbolName()

wxString SCH_EAGLE_PLUGIN::fixSymbolName ( const wxString &  aName)
staticprivate

Fix invalid characters in Eagle symbol names.

It changes invalid characters to underscores.

Parameters
aNameis the symbol name to be fixed.
Returns
Fixed symbol name.

Definition at line 2877 of file sch_eagle_plugin.cpp.

2878 {
2879  wxString ret = LIB_ID::FixIllegalChars( aName );
2880 
2881  return ret;
2882 }
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:347

References LIB_ID::FixIllegalChars().

◆ GetError()

const wxString & SCH_PLUGIN::GetError ( ) const
virtualinherited

Return an error string to the caller.

This is useful for schematic loaders that can load partial schematics where throwing an exception would be problematic such as the KiCad legacy plugin.

Returns
an unformatted string containing errors if any.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 177 of file sch_plugin.cpp.

178 {
179  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
180  not_implemented( this, __FUNCTION__ );
181  static wxString error;
182  return error;
183 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic(), and TEST_NETLISTS_FIXTURE::loadSchematic().

◆ GetFileExtension()

const wxString SCH_EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 373 of file sch_eagle_plugin.cpp.

374 {
375  return "sch";
376 }

◆ getLibFileName()

wxFileName SCH_EAGLE_PLUGIN::getLibFileName ( )
private

Checks if there are other wires or pins at the position of the tested pin.

Definition at line 155 of file sch_eagle_plugin.cpp.

156 {
158 
159  return fn;
160 }
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
const std::string KiCadSymbolLibFileExtension

References KiCadSymbolLibFileExtension.

◆ getLibName()

wxString SCH_EAGLE_PLUGIN::getLibName ( )
private

Definition at line 131 of file sch_eagle_plugin.cpp.

132 {
133  if( m_libName.IsEmpty() )
134  {
135  // Try to come up with a meaningful name
137 
138  if( m_libName.IsEmpty() )
139  {
140  wxFileName fn( m_rootSheet->GetFileName() );
141  m_libName = fn.GetName();
142  }
143 
144  if( m_libName.IsEmpty() )
145  m_libName = "noname";
146 
147  m_libName += "-eagle-import";
149  }
150 
151  return m_libName;
152 }
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:347
wxString m_libName
Library name to save symbols.
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:129

References LIB_ID::FixIllegalChars().

◆ GetLibraryFileExtension()

const wxString SCH_EAGLE_PLUGIN::GetLibraryFileExtension ( ) const
overridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 379 of file sch_eagle_plugin.cpp.

380 {
381  return "lbr";
382 }

◆ GetModifyHash()

int SCH_EAGLE_PLUGIN::GetModifyHash ( ) const
overridevirtual

Return the modification hash from the library cache.

Note
This is temporary until the new s-expr file format is implement. The new file format will embed symbols instead of referencing them from the library. This function can be removed when the new file format is implemented.
Returns
the modification hash of the library cache.

Implements SCH_PLUGIN.

Definition at line 385 of file sch_eagle_plugin.cpp.

386 {
387  return 0;
388 }

◆ GetName()

const wxString SCH_EAGLE_PLUGIN::GetName ( ) const
overridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 367 of file sch_eagle_plugin.cpp.

368 {
369  return "EAGLE";
370 }

◆ IsSymbolLibWritable()

bool SCH_PLUGIN::IsSymbolLibWritable ( const wxString &  aLibraryPath)
virtualinherited

Return true if the library at aLibraryPath is writable.

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

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 125 of file sch_plugin.cpp.

126 {
127  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
128  not_implemented( this, __FUNCTION__ );
129  return false;
130 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ kiCadLayer()

SCH_LAYER_ID SCH_EAGLE_PLUGIN::kiCadLayer ( int  aEagleLayer)
private

Return the matching layer or return LAYER_NOTES.

Definition at line 214 of file sch_eagle_plugin.cpp.

215 {
216  auto it = m_layerMap.find( aEagleLayer );
217  return it == m_layerMap.end() ? LAYER_NOTES : it->second;
218 }
std::map< int, SCH_LAYER_ID > m_layerMap
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...

References LAYER_NOTES.

◆ Load()

SCH_SHEET * SCH_EAGLE_PLUGIN::Load ( const wxString &  aFileName,
SCHEMATIC aSchematic,
SCH_SHEET aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one.

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

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aAppendToMeis an existing SCH_SHEET to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
the successfully loaded schematic, or the same one as aAppendToMe if aAppendToMe was not NULL, and the caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.
Note
No check is being done here to see if the existing symbol library exists so this will overwrite the existing one.

Reimplemented from SCH_PLUGIN.

Definition at line 391 of file sch_eagle_plugin.cpp.

393 {
394  wxASSERT( !aFileName || aSchematic != nullptr );
395  LOCALE_IO toggle; // toggles on, then off, the C locale.
396 
397  // Load the document
398  wxXmlDocument xmlDocument;
399 
400  m_filename = aFileName;
401  m_schematic = aSchematic;
402 
403  if( !xmlDocument.Load( m_filename.GetFullPath() ) )
404  {
405  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
406  m_filename.GetFullPath() ) );
407  }
408 
409  // Delete on exception, if I own m_rootSheet, according to aAppendToMe
410  unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
411 
412  wxFileName newFilename( m_filename );
413  newFilename.SetExt( KiCadSchematicFileExtension );
414 
415  if( aAppendToMe )
416  {
417  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
418  m_rootSheet = &aSchematic->Root();
419  }
420  else
421  {
422  m_rootSheet = new SCH_SHEET( aSchematic );
423  m_rootSheet->SetFileName( newFilename.GetFullPath() );
424  }
425 
426  if( !m_rootSheet->GetScreen() )
427  {
428  SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
429  screen->SetFileName( newFilename.GetFullPath() );
430  m_rootSheet->SetScreen( screen );
431  }
432 
433  SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable();
434 
435  wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." );
436 
437  m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
438  m_properties = std::make_unique<PROPERTIES>();
439  ( *m_properties )[SCH_LEGACY_PLUGIN::PropBuffering] = "";
440 
443  if( !libTable->HasLibrary( getLibName() ) )
444  {
445  // Create a new empty symbol library.
446  m_pi->CreateSymbolLib( getLibFileName().GetFullPath() );
447  wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName();
448 
449  // Add the new library to the project symbol library table.
450  libTable->InsertRow(
451  new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "KiCad" ) ) );
452 
453  // Save project symbol library table.
454  wxFileName fn( m_schematic->Prj().GetProjectPath(),
456 
457  // So output formatter goes out of scope and closes the file before reloading.
458  {
459  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
460  libTable->Format( &formatter, 0 );
461  }
462 
463  // Reload the symbol library table.
465  m_schematic->Prj().SchSymbolLibTable();
466  }
467 
468  // Retrieve the root as current node
469  wxXmlNode* currentNode = xmlDocument.GetRoot();
470 
471  // If the attribute is found, store the Eagle version;
472  // otherwise, store the dummy "0.0" version.
473  m_version = currentNode->GetAttribute( "version", "0.0" );
474 
475  // Map all children into a readable dictionary
476  NODE_MAP children = MapChildren( currentNode );
477 
478  // Load drawing
479  loadDrawing( children["drawing"] );
480 
481  m_pi->SaveLibrary( getLibFileName().GetFullPath() );
482 
483  SCH_SCREENS allSheets( m_rootSheet );
484  allSheets.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
485 
486  return m_rootSheet;
487 }
static const wxString & GetSymbolLibTableFileName()
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:156
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:108
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:501
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:259
void SetFileName(wxString aFilename)
Definition: sch_sheet.h:321
#define NULL
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
wxString m_version
Eagle file version.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
SCH_SHEET & Root() const
Definition: schematic.h:92
void loadDrawing(wxXmlNode *aDrawingNode)
#define _(s)
Definition: 3d_actions.cpp:33
const std::string KiCadSchematicFileExtension
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
Used for text file output.
Definition: richio.h:453
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:131
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:549
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47

References _, PROJECT::ELEM_SYMBOL_LIB_TABLE, SYMBOL_LIB_TABLE::Format(), Format(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), LIB_TABLE::HasLibrary(), LIB_TABLE::InsertRow(), SCHEMATIC::IsValid(), KiCadSchematicFileExtension, MapChildren(), NULL, SCH_LEGACY_PLUGIN::PropBuffering, SCHEMATIC::Root(), SCH_SCREEN::SetFileName(), THROW_IO_ERROR, and SCH_SCREENS::UpdateSymbolLinks().

◆ loadDrawing()

void SCH_EAGLE_PLUGIN::loadDrawing ( wxXmlNode *  aDrawingNode)
private

Definition at line 490 of file sch_eagle_plugin.cpp.

491 {
492  // Map all children into a readable dictionary
493  NODE_MAP drawingChildren = MapChildren( aDrawingNode );
494 
495  // Board nodes should not appear in .sch files
496  // wxXmlNode* board = drawingChildren["board"]
497 
498  // wxXmlNode* grid = drawingChildren["grid"]
499 
500  auto layers = drawingChildren["layers"];
501 
502  if( layers )
503  loadLayerDefs( layers );
504 
505  // wxXmlNode* library = drawingChildren["library"]
506 
507  // wxXmlNode* settings = drawingChildren["settings"]
508 
509  // Load schematic
510  auto schematic = drawingChildren["schematic"];
511 
512  if( schematic )
513  loadSchematic( schematic );
514 }
void loadSchematic(wxXmlNode *aSchematicNode)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
void loadLayerDefs(wxXmlNode *aLayers)
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47

References MapChildren().

◆ loadFieldAttributes()

void SCH_EAGLE_PLUGIN::loadFieldAttributes ( LIB_FIELD aField,
const LIB_TEXT aText 
) const
private

Move net labels that are detached from any wire to the nearest wire.

Definition at line 2116 of file sch_eagle_plugin.cpp.

2117 {
2118  aField->SetTextPos( aText->GetPosition() );
2119  aField->SetTextSize( aText->GetTextSize() );
2120  aField->SetTextAngle( aText->GetTextAngle() );
2121  aField->SetBold( aText->IsBold() );
2122  aField->SetVertJustify( aText->GetVertJustify() );
2123  aField->SetHorizJustify( aText->GetHorizJustify() );
2124  aField->SetVisible( true );
2125 }
bool IsBold() const
Definition: eda_text.h:190
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
wxPoint GetPosition() const override
Definition: lib_text.h:93
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
void SetVisible(bool aVisible)
Definition: eda_text.h:192
double GetTextAngle() const
Definition: eda_text.h:181
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
const wxSize & GetTextSize() const
Definition: eda_text.h:245
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:174
void SetBold(bool aBold)
Definition: eda_text.h:189

References EDA_TEXT::GetHorizJustify(), LIB_TEXT::GetPosition(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetVertJustify(), EDA_TEXT::IsBold(), EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVertJustify(), and EDA_TEXT::SetVisible().

◆ loadFrame() [1/2]

void SCH_EAGLE_PLUGIN::loadFrame ( wxXmlNode *  aFrameNode,
std::vector< SCH_LINE * > &  aLines 
)
private

Definition at line 862 of file sch_eagle_plugin.cpp.

863 {
864  EFRAME eframe( aFrameNode );
865 
866  wxPoint corner1( eframe.x1.ToSchUnits(), -eframe.y1.ToSchUnits() );
867  wxPoint corner3( eframe.x2.ToSchUnits(), -eframe.y2.ToSchUnits() );
868  wxPoint corner2( corner3.x, corner1.y );
869  wxPoint corner4( corner1.x, corner3.y );
870 
871  SCH_LINE* line = new SCH_LINE();
873  line->SetStartPoint( corner1 );
874  line->SetEndPoint( corner2 );
875  aLines.push_back( line );
876 
877  line = new SCH_LINE();
879  line->SetStartPoint( corner2 );
880  line->SetEndPoint( corner3 );
881  aLines.push_back( line );
882 
883  line = new SCH_LINE();
885  line->SetStartPoint( corner3 );
886  line->SetEndPoint( corner4 );
887  aLines.push_back( line );
888 
889  line = new SCH_LINE();
891  line->SetStartPoint( corner4 );
892  line->SetEndPoint( corner1 );
893  aLines.push_back( line );
894 }
Parse an Eagle frame element.
Definition: eagle_parser.h:674
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:239
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:91
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37

References SCH_LINE::SetEndPoint(), SCH_LINE::SetLineStyle(), SCH_LINE::SetStartPoint(), SOLID, ECOORD::ToSchUnits(), EFRAME::x1, EFRAME::x2, EFRAME::y1, and EFRAME::y2.

◆ loadFrame() [2/2]

void SCH_EAGLE_PLUGIN::loadFrame ( wxXmlNode *  aFrameNode,
std::vector< LIB_ITEM * > &  aLines 
)
private

Definition at line 1885 of file sch_eagle_plugin.cpp.

1886 {
1887  EFRAME eframe( aFrameNode );
1888 
1889  int xMin = eframe.x1.ToSchUnits();
1890  int xMax = eframe.x2.ToSchUnits();
1891  int yMin = eframe.y1.ToSchUnits();
1892  int yMax = eframe.y2.ToSchUnits();
1893 
1894  if( xMin > xMax )
1895  std::swap( xMin, xMax );
1896 
1897  if( yMin > yMax )
1898  std::swap( yMin, yMax );
1899 
1900  LIB_POLYLINE* lines = new LIB_POLYLINE( nullptr );
1901  lines->AddPoint( wxPoint( xMin, yMin ) );
1902  lines->AddPoint( wxPoint( xMax, yMin ) );
1903  lines->AddPoint( wxPoint( xMax, yMax ) );
1904  lines->AddPoint( wxPoint( xMin, yMax ) );
1905  lines->AddPoint( wxPoint( xMin, yMin ) );
1906  aItems.push_back( lines );
1907 
1908  if( !eframe.border_left )
1909  {
1910  lines = new LIB_POLYLINE( nullptr );
1911  lines->AddPoint( wxPoint( xMin + Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
1912  lines->AddPoint( wxPoint( xMin + Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
1913  aItems.push_back( lines );
1914 
1915  int i;
1916  int height = yMax - yMin;
1917  int x1 = xMin;
1918  int x2 = x1 + Mils2iu( 150 );
1919  int legendPosX = xMin + Mils2iu( 75 );
1920  double rowSpacing = height / double( eframe.rows );
1921  double legendPosY = yMax - ( rowSpacing / 2 );
1922 
1923  for( i = 1; i < eframe.rows; i++ )
1924  {
1925  int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
1926  lines = new LIB_POLYLINE( nullptr );
1927  lines->AddPoint( wxPoint( x1, newY ) );
1928  lines->AddPoint( wxPoint( x2, newY ) );
1929  aItems.push_back( lines );
1930  }
1931 
1932  char legendChar = 'A';
1933 
1934  for( i = 0; i < eframe.rows; i++ )
1935  {
1936  LIB_TEXT* legendText = new LIB_TEXT( nullptr );
1937  legendText->SetPosition( wxPoint( legendPosX, KiROUND( legendPosY ) ) );
1938  legendText->SetText( wxString( legendChar ) );
1939  legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
1940  aItems.push_back( legendText );
1941  legendChar++;
1942  legendPosY -= rowSpacing;
1943  }
1944  }
1945 
1946  if( !eframe.border_right )
1947  {
1948  lines = new LIB_POLYLINE( nullptr );
1949  lines->AddPoint( wxPoint( xMax - Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
1950  lines->AddPoint( wxPoint( xMax - Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
1951  aItems.push_back( lines );
1952 
1953  int i;
1954  int height = yMax - yMin;
1955  int x1 = xMax - Mils2iu( 150 );
1956  int x2 = xMax;
1957  int legendPosX = xMax - Mils2iu( 75 );
1958  double rowSpacing = height / double( eframe.rows );
1959  double legendPosY = yMax - ( rowSpacing / 2 );
1960 
1961  for( i = 1; i < eframe.rows; i++ )
1962  {
1963  int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
1964  lines = new LIB_POLYLINE( nullptr );
1965  lines->AddPoint( wxPoint( x1, newY ) );
1966  lines->AddPoint( wxPoint( x2, newY ) );
1967  aItems.push_back( lines );
1968  }
1969 
1970  char legendChar = 'A';
1971 
1972  for( i = 0; i < eframe.rows; i++ )
1973  {
1974  LIB_TEXT* legendText = new LIB_TEXT( nullptr );
1975  legendText->SetPosition( wxPoint( legendPosX, KiROUND( legendPosY ) ) );
1976  legendText->SetText( wxString( legendChar ) );
1977  legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
1978  aItems.push_back( legendText );
1979  legendChar++;
1980  legendPosY -= rowSpacing;
1981  }
1982  }
1983 
1984  if( !eframe.border_top )
1985  {
1986  lines = new LIB_POLYLINE( nullptr );
1987  lines->AddPoint( wxPoint( xMax - Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
1988  lines->AddPoint( wxPoint( xMin + Mils2iu( 150 ), yMax - Mils2iu( 150 ) ) );
1989  aItems.push_back( lines );
1990 
1991  int i;
1992  int width = xMax - xMin;
1993  int y1 = yMin;
1994  int y2 = yMin + Mils2iu( 150 );
1995  int legendPosY = yMax - Mils2iu( 75 );
1996  double columnSpacing = width / double( eframe.columns );
1997  double legendPosX = xMin + ( columnSpacing / 2 );
1998 
1999  for( i = 1; i < eframe.columns; i++ )
2000  {
2001  int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
2002  lines = new LIB_POLYLINE( nullptr );
2003  lines->AddPoint( wxPoint( newX, y1 ) );
2004  lines->AddPoint( wxPoint( newX, y2 ) );
2005  aItems.push_back( lines );
2006  }
2007 
2008  char legendChar = '1';
2009 
2010  for( i = 0; i < eframe.columns; i++ )
2011  {
2012  LIB_TEXT* legendText = new LIB_TEXT( nullptr );
2013  legendText->SetPosition( wxPoint( KiROUND( legendPosX ), legendPosY ) );
2014  legendText->SetText( wxString( legendChar ) );
2015  legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
2016  aItems.push_back( legendText );
2017  legendChar++;
2018  legendPosX += columnSpacing;
2019  }
2020  }
2021 
2022  if( !eframe.border_bottom )
2023  {
2024  lines = new LIB_POLYLINE( nullptr );
2025  lines->AddPoint( wxPoint( xMax - Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
2026  lines->AddPoint( wxPoint( xMin + Mils2iu( 150 ), yMin + Mils2iu( 150 ) ) );
2027  aItems.push_back( lines );
2028 
2029  int i;
2030  int width = xMax - xMin;
2031  int y1 = yMax - Mils2iu( 150 );
2032  int y2 = yMax;
2033  int legendPosY = yMin + Mils2iu( 75 );
2034  double columnSpacing = width / double( eframe.columns );
2035  double legendPosX = xMin + ( columnSpacing / 2 );
2036 
2037  for( i = 1; i < eframe.columns; i++ )
2038  {
2039  int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
2040  lines = new LIB_POLYLINE( nullptr );
2041  lines->AddPoint( wxPoint( newX, y1 ) );
2042  lines->AddPoint( wxPoint( newX, y2 ) );
2043  aItems.push_back( lines );
2044  }
2045 
2046  char legendChar = '1';
2047 
2048  for( i = 0; i < eframe.columns; i++ )
2049  {
2050  LIB_TEXT* legendText = new LIB_TEXT( nullptr );
2051  legendText->SetPosition( wxPoint( KiROUND( legendPosX ), legendPosY ) );
2052  legendText->SetText( wxString( legendChar ) );
2053  legendText->SetTextSize( wxSize( Mils2iu( 90 ), Mils2iu( 100 ) ) );
2054  aItems.push_back( legendText );
2055  legendChar++;
2056  legendPosX += columnSpacing;
2057  }
2058  }
2059 }
Define a symbol library graphical text item.
Definition: lib_text.h:39
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
Parse an Eagle frame element.
Definition: eagle_parser.h:674
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void AddPoint(const wxPoint &aPoint)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:213

References LIB_POLYLINE::AddPoint(), EFRAME::border_bottom, EFRAME::border_left, EFRAME::border_right, EFRAME::border_top, EFRAME::columns, KiROUND(), EFRAME::rows, LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), ECOORD::ToSchUnits(), EFRAME::x1, EFRAME::x2, EFRAME::y1, and EFRAME::y2.

◆ loadInstance()

void SCH_EAGLE_PLUGIN::loadInstance ( wxXmlNode *  aInstanceNode)
private

Definition at line 1146 of file sch_eagle_plugin.cpp.

1147 {
1148  auto einstance = EINSTANCE( aInstanceNode );
1149 
1150  SCH_SCREEN* screen = m_currentSheet->GetScreen();
1151 
1152  // Find the part in the list for the sheet.
1153  // Assign the component its value from the part entry
1154  // Calculate the unit number from the gate entry of the instance
1155  // Assign the the LIB_ID from device set and device names
1156 
1157  auto part_it = m_partlist.find( einstance.part.Upper() );
1158 
1159  if( part_it == m_partlist.end() )
1160  {
1161  m_reporter->Report( wxString::Format( _( "Error parsing Eagle file. Could not find '%s' "
1162  "instance but it is referenced in the schematic." ),
1163  einstance.part ),
1165 
1166  return;
1167  }
1168 
1169  EPART* epart = part_it->second.get();
1170 
1171  wxString libraryname = epart->library;
1172  wxString gatename = epart->deviceset + epart->device + einstance.gate;
1173  wxString symbolname = wxString( epart->deviceset + epart->device );
1174  symbolname.Replace( "*", "" );
1175  wxString kisymbolname = fixSymbolName( symbolname );
1176 
1177  int unit = m_eagleLibs[libraryname].GateUnit[gatename];
1178 
1179  wxString package;
1180  EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname];
1181 
1182  auto p = elib->package.find( kisymbolname );
1183 
1184  if( p != elib->package.end() )
1185  package = p->second;
1186 
1187  LIB_PART* part =
1188  m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname, m_properties.get() );
1189 
1190  if( !part )
1191  {
1192  m_reporter->Report( wxString::Format( _( "Could not find '%s' in the imported library." ),
1193  kisymbolname ),
1195  return;
1196  }
1197 
1198  LIB_ID libId( getLibName(), kisymbolname );
1199  std::unique_ptr<SCH_COMPONENT> component = std::make_unique<SCH_COMPONENT>();
1200  component->SetLibId( libId );
1201  component->SetUnit( unit );
1202  component->SetPosition( wxPoint( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) );
1203  component->GetField( FOOTPRINT_FIELD )->SetText( package );
1204 
1205  if( einstance.rot )
1206  {
1207  component->SetOrientation( kiCadComponentRotation( einstance.rot->degrees ) );
1208 
1209  if( einstance.rot->mirror )
1210  component->MirrorHorizontally( einstance.x.ToSchUnits() );
1211  }
1212 
1213  std::vector<LIB_FIELD*> partFields;
1214  part->GetFields( partFields );
1215 
1216  for( const LIB_FIELD* field : partFields )
1217  {
1218  component->GetFieldById( field->GetId() )->ImportValues( *field );
1219  component->GetFieldById( field->GetId() )->SetTextPos( component->GetPosition()
1220  + field->GetTextPos() );
1221  }
1222 
1223  // If there is no footprint assigned, then prepend the reference value
1224  // with a hash character to mute netlist updater complaints
1225  wxString reference = package.IsEmpty() ? '#' + einstance.part : einstance.part;
1226 
1227  // EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
1228  // parts to have non-digit + digit annotation. If the reference begins with a number,
1229  // we prepend 'UNK' (unknown) for the symbol designator
1230  if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
1231  reference.Prepend( "UNK" );
1232 
1233  SCH_SHEET_PATH sheetpath;
1234  m_rootSheet->LocatePathOfScreen( screen, &sheetpath );
1235  wxString current_sheetpath = sheetpath.PathAsString() + component->m_Uuid.AsString();
1236 
1237  component->GetField( REFERENCE_FIELD )->SetText( reference );
1238  component->AddHierarchicalReference( current_sheetpath, reference, unit );
1239 
1240  if( epart->value )
1241  component->GetField( VALUE_FIELD )->SetText( *epart->value );
1242  else
1243  component->GetField( VALUE_FIELD )->SetText( kisymbolname );
1244 
1245  // Set the visibility of fields.
1246  component->GetField( REFERENCE_FIELD )->SetVisible( part->GetFieldById( REFERENCE_FIELD )->IsVisible() );
1247  component->GetField( VALUE_FIELD )->SetVisible( part->GetFieldById( VALUE_FIELD )->IsVisible() );
1248 
1249  for( const auto& a : epart->attribute )
1250  {
1251  auto field = component->AddField( *component->GetField( VALUE_FIELD ) );
1252  field->SetName( a.first );
1253  field->SetText( a.second );
1254  field->SetVisible( false );
1255  }
1256 
1257  for( const auto& a : epart->variant )
1258  {
1259  auto field = component->AddField( *component->GetField( VALUE_FIELD ) );
1260  field->SetName( "VARIANT_" + a.first );
1261  field->SetText( a.second );
1262  field->SetVisible( false );
1263  }
1264 
1265  bool valueAttributeFound = false;
1266  bool nameAttributeFound = false;
1267 
1268  wxXmlNode* attributeNode = aInstanceNode->GetChildren();
1269 
1270  // Parse attributes for the instance
1271  while( attributeNode )
1272  {
1273  if( attributeNode->GetName() == "attribute" )
1274  {
1275  auto attr = EATTR( attributeNode );
1276  SCH_FIELD* field = NULL;
1277 
1278  if( attr.name.Lower() == "name" )
1279  {
1280  field = component->GetField( REFERENCE_FIELD );
1281  nameAttributeFound = true;
1282  }
1283  else if( attr.name.Lower() == "value" )
1284  {
1285  field = component->GetField( VALUE_FIELD );
1286  valueAttributeFound = true;
1287  }
1288  else
1289  {
1290  field = component->FindField( attr.name );
1291 
1292  if( field )
1293  field->SetVisible( false );
1294  }
1295 
1296  if( field )
1297  {
1298 
1299  field->SetPosition( wxPoint( attr.x->ToSchUnits(), -attr.y->ToSchUnits() ) );
1300  int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
1301  int absdegrees = attr.rot ? attr.rot->degrees : 0;
1302  bool mirror = attr.rot ? attr.rot->mirror : false;
1303 
1304  if( einstance.rot && einstance.rot->mirror )
1305  mirror = !mirror;
1306 
1307  bool spin = attr.rot ? attr.rot->spin : false;
1308 
1309  if( attr.display == EATTR::Off || attr.display == EATTR::NAME )
1310  field->SetVisible( false );
1311 
1312  int rotation = einstance.rot ? einstance.rot->degrees : 0;
1313  int reldegrees = ( absdegrees - rotation + 360.0 );
1314  reldegrees %= 360;
1315 
1317  (EDA_TEXT*) field, align, reldegrees, mirror, spin, absdegrees );
1318  }
1319  }
1320  else if( attributeNode->GetName() == "variant" )
1321  {
1322  wxString variant, value;
1323 
1324  if( attributeNode->GetAttribute( "name", &variant )
1325  && attributeNode->GetAttribute( "value", &value ) )
1326  {
1327  auto field = component->AddField( *component->GetField( VALUE_FIELD ) );
1328  field->SetName( "VARIANT_" + variant );
1329  field->SetText( value );
1330  field->SetVisible( false );
1331  }
1332  }
1333 
1334  attributeNode = attributeNode->GetNext();
1335  }
1336 
1337  if( einstance.smashed && einstance.smashed.Get() )
1338  {
1339  if( !valueAttributeFound )
1340  component->GetField( VALUE_FIELD )->SetVisible( false );
1341 
1342  if( !nameAttributeFound )
1343  component->GetField( REFERENCE_FIELD )->SetVisible( false );
1344  }
1345 
1346  // Save the pin positions
1347  SYMBOL_LIB_TABLE& schLibTable = *m_schematic->Prj().SchSymbolLibTable();
1348  LIB_PART* libSymbol = schLibTable.LoadSymbol( component->GetLibId() );
1349 
1350  wxCHECK( libSymbol, /*void*/ );
1351 
1352  component->SetLibSymbol( new LIB_PART( *libSymbol ) );
1353 
1354  std::vector<LIB_PIN*> pins;
1355  component->GetLibPins( pins );
1356 
1357  for( const auto& pin : pins )
1358  m_connPoints[component->GetPinPhysicalPosition( pin )].emplace( pin );
1359 
1360  component->ClearFlags();
1361 
1362  screen->Append( component.release() );
1363 }
Field Reference of part, i.e. "IC21".
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
wxString deviceset
Definition: eagle_parser.h:925
Instances are attached to a symbol or sheet and provide a place for the component's value,...
Definition: sch_field.h:50
wxString library
Definition: eagle_parser.h:924
std::unordered_map< wxString, wxString > package
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:192
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
std::map< std::string, std::string > variant
Definition: eagle_parser.h:930
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
static void eagleToKicadAlignment(EDA_TEXT *aText, int aEagleAlignment, int aRelDegress, bool aMirror, bool aSpin, int aAbsDegress)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
opt_wxString value
Definition: eagle_parser.h:928
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
static wxString fixSymbolName(const wxString &aName)
Fix invalid characters in Eagle symbol names.
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
#define NULL
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
Define a library symbol object.
Definition: lib_symbol.h:93
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
std::map< std::string, std::string > attribute
Definition: eagle_parser.h:929
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:594
static COMPONENT_ORIENTATION_T kiCadComponentRotation(float eagleDegrees)
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:665
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
REPORTER * m_reporter
Reporter for warnings/errors.
#define _(s)
Definition: 3d_actions.cpp:33
void SetName(const wxString &aName)
Definition: sch_field.h:112
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
wxString device
Definition: eagle_parser.h:926
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:664
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Field Name Module PCB, i.e. "16DIP300".

References _, SCH_SCREEN::Append(), EPART::attribute, ETEXT::BOTTOM_LEFT, EPART::device, EPART::deviceset, eagleToKicadAlignment(), FOOTPRINT_FIELD, Format(), kiCadComponentRotation(), EPART::library, SYMBOL_LIB_TABLE::LoadSymbol(), EATTR::NAME, NULL, EATTR::Off, EAGLE_LIBRARY::package, SCH_SHEET_PATH::PathAsString(), pin, REFERENCE_FIELD, RPT_SEVERITY_ERROR, SCH_FIELD::SetPosition(), EDA_TEXT::SetVisible(), EPART::value, VALUE_FIELD, and EPART::variant.

◆ loadJunction()

SCH_JUNCTION * SCH_EAGLE_PLUGIN::loadJunction ( wxXmlNode *  aJunction)
private

Definition at line 1042 of file sch_eagle_plugin.cpp.

1043 {
1044  std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1045 
1046  auto ejunction = EJUNCTION( aJunction );
1047  wxPoint pos( ejunction.x.ToSchUnits(), -ejunction.y.ToSchUnits() );
1048 
1049  junction->SetPosition( pos );
1050 
1051  return junction.release();
1052 }
Eagle Junction.
Definition: eagle_parser.h:522

◆ loadLabel()

SCH_TEXT * SCH_EAGLE_PLUGIN::loadLabel ( wxXmlNode *  aLabelNode,
const wxString &  aNetName 
)
private

Definition at line 1055 of file sch_eagle_plugin.cpp.

1056 {
1057  auto elabel = ELABEL( aLabelNode, aNetName );
1058  wxPoint elabelpos( elabel.x.ToSchUnits(), -elabel.y.ToSchUnits() );
1059 
1060  // Determine if the label is local or global depending on
1061  // the number of sheets the net appears in
1062  bool global = m_netCounts[aNetName] > 1;
1063  std::unique_ptr<SCH_TEXT> label;
1064 
1065  wxSize textSize;
1066 
1067  if( global )
1068  {
1069  label = std::make_unique<SCH_GLOBALLABEL>();
1070  textSize = wxSize( KiROUND( elabel.size.ToSchUnits() * 0.75 ),
1071  KiROUND( elabel.size.ToSchUnits() * 0.75 ) );
1072  }
1073  else
1074  {
1075  label = std::make_unique<SCH_LABEL>();
1076  textSize = wxSize( KiROUND( elabel.size.ToSchUnits() * 0.85 ),
1077  KiROUND( elabel.size.ToSchUnits() * 0.85 ) );
1078  }
1079 
1080  label->SetPosition( elabelpos );
1081  label->SetText( escapeName( elabel.netname ) );
1082  label->SetTextSize( textSize );
1083  label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
1084 
1085  if( elabel.rot )
1086  {
1087  label->SetLabelSpinStyle(
1088  (LABEL_SPIN_STYLE::SPIN) ( KiROUND( elabel.rot->degrees / 90 ) % 4 ) );
1089 
1090  if( elabel.rot->mirror )
1091  {
1092  label->SetLabelSpinStyle( label->GetLabelSpinStyle().MirrorY() );
1093  }
1094  }
1095 
1096  return label.release();
1097 }
std::map< wxString, int > m_netCounts
Eagle label.
Definition: eagle_parser.h:532
wxString escapeName(const wxString &aNetName)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References escapeName(), KiROUND(), and LABEL_SPIN_STYLE::RIGHT.

◆ loadLayerDefs()

void SCH_EAGLE_PLUGIN::loadLayerDefs ( wxXmlNode *  aLayers)
private

Layers in KiCad schematics are not actually layers, but abstract groups mainly used to decide item colors.

<layers> <layer number="90" name="Modules" color="5" fill="1" visible="yes" active="yes"> <layer number="91" name="Nets" color="2" fill="1" visible="yes" active="yes"> <layer number="92" name="Busses" color="1" fill="1" visible="yes" active="yes"> <layer number="93" name="Pins" color="2" fill="1" visible="no" active="yes"> <layer number="94" name="Symbols" color="4" fill="1" visible="yes" active="yes"> <layer number="95" name="Names" color="7" fill="1" visible="yes" active="yes"> <layer number="96" name="Values" color="7" fill="1" visible="yes" active="yes"> <layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"> <layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"> </layers>

Definition at line 163 of file sch_eagle_plugin.cpp.

164 {
165  std::vector<ELAYER> eagleLayers;
166 
167  // Get the first layer and iterate
168  wxXmlNode* layerNode = aLayers->GetChildren();
169 
170  while( layerNode )
171  {
172  ELAYER elayer( layerNode );
173  eagleLayers.push_back( elayer );
174 
175  layerNode = layerNode->GetNext();
176  }
177 
178  // match layers based on their names
179  for( const auto& elayer : eagleLayers )
180  {
198  if( elayer.name == "Nets" )
199  {
200  m_layerMap[elayer.number] = LAYER_WIRE;
201  }
202  else if( elayer.name == "Info" || elayer.name == "Guide" )
203  {
204  m_layerMap[elayer.number] = LAYER_NOTES;
205  }
206  else if( elayer.name == "Busses" )
207  {
208  m_layerMap[elayer.number] = LAYER_BUS;
209  }
210  }
211 }
std::map< int, SCH_LAYER_ID > m_layerMap
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...

References LAYER_BUS, LAYER_NOTES, and LAYER_WIRE.

◆ loadLibrary()

EAGLE_LIBRARY * SCH_EAGLE_PLUGIN::loadLibrary ( wxXmlNode *  aLibraryNode,
EAGLE_LIBRARY aEagleLib 
)
private

Definition at line 1366 of file sch_eagle_plugin.cpp.

1368 {
1369  NODE_MAP libraryChildren = MapChildren( aLibraryNode );
1370 
1371  // Loop through the symbols and load each of them
1372  wxXmlNode* symbolNode = getChildrenNodes( libraryChildren, "symbols" );
1373 
1374  while( symbolNode )
1375  {
1376  wxString symbolName = symbolNode->GetAttribute( "name" );
1377  aEagleLibrary->SymbolNodes[symbolName] = symbolNode;
1378  symbolNode = symbolNode->GetNext();
1379  }
1380 
1381  // Loop through the device sets and load each of them
1382  wxXmlNode* devicesetNode = getChildrenNodes( libraryChildren, "devicesets" );
1383 
1384  while( devicesetNode )
1385  {
1386  // Get Device set information
1387  EDEVICE_SET edeviceset = EDEVICE_SET( devicesetNode );
1388 
1389  wxString prefix = edeviceset.prefix ? edeviceset.prefix.Get() : "";
1390 
1391  NODE_MAP aDeviceSetChildren = MapChildren( devicesetNode );
1392  wxXmlNode* deviceNode = getChildrenNodes( aDeviceSetChildren, "devices" );
1393 
1394  // For each device in the device set:
1395  while( deviceNode )
1396  {
1397  // Get device information
1398  EDEVICE edevice = EDEVICE( deviceNode );
1399 
1400  // Create symbol name from deviceset and device names.
1401  wxString symbolName = edeviceset.name + edevice.name;
1402  symbolName.Replace( "*", "" );
1403  wxASSERT( !symbolName.IsEmpty() );
1404  symbolName = fixSymbolName( symbolName );
1405 
1406  if( edevice.package )
1407  aEagleLibrary->package[symbolName] = edevice.package.Get();
1408 
1409  // Create KiCad symbol.
1410  unique_ptr<LIB_PART> kpart( new LIB_PART( symbolName ) );
1411 
1412  // Process each gate in the deviceset for this device.
1413  wxXmlNode* gateNode = getChildrenNodes( aDeviceSetChildren, "gates" );
1414  int gates_count = countChildren( aDeviceSetChildren["gates"], "gate" );
1415  kpart->SetUnitCount( gates_count );
1416  kpart->LockUnits( true );
1417 
1418  LIB_FIELD* reference = kpart->GetFieldById( REFERENCE_FIELD );
1419 
1420  if( prefix.length() == 0 )
1421  reference->SetVisible( false );
1422  else
1423  // If there is no footprint assigned, then prepend the reference value
1424  // with a hash character to mute netlist updater complaints
1425  reference->SetText( edevice.package ? prefix : '#' + prefix );
1426 
1427  int gateindex = 1;
1428  bool ispower = false;
1429 
1430  while( gateNode )
1431  {
1432  EGATE egate = EGATE( gateNode );
1433 
1434  aEagleLibrary->GateUnit[edeviceset.name + edevice.name + egate.name] = gateindex;
1435 
1436  ispower = loadSymbol( aEagleLibrary->SymbolNodes[egate.symbol], kpart, &edevice,
1437  gateindex, egate.name );
1438 
1439  gateindex++;
1440  gateNode = gateNode->GetNext();
1441  } // gateNode
1442 
1443  kpart->SetUnitCount( gates_count );
1444 
1445  if( gates_count == 1 && ispower )
1446  kpart->SetPower();
1447 
1448  wxString name = fixSymbolName( kpart->GetName() );
1449  kpart->SetName( name );
1450  m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ),
1451  m_properties.get() );
1452  aEagleLibrary->KiCadSymbols.insert( name, kpart.release() );
1453 
1454  deviceNode = deviceNode->GetNext();
1455  } // devicenode
1456 
1457  devicesetNode = devicesetNode->GetNext();
1458  } // devicesetNode
1459 
1460  return aEagleLibrary;
1461 }
Field Reference of part, i.e. "IC21".
wxString name
T & Get()
Return a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:292
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:192
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provide an easy access to the children of an XML node via their names.
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
wxString name
static wxString fixSymbolName(const wxString &aName)
Fix invalid characters in Eagle symbol names.
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxString symbol
Definition: eagle_parser.h:976
bool loadSymbol(wxXmlNode *aSymbolNode, std::unique_ptr< LIB_PART > &aPart, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
Define a library symbol object.
Definition: lib_symbol.h:93
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
wxString name
Definition: eagle_parser.h:975
opt_wxString prefix
const char * name
Definition: DXF_plotter.cpp:59
opt_wxString package
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:57

References countChildren(), EAGLE_LIBRARY::GateUnit, OPTIONAL_XML_ATTRIBUTE< T >::Get(), getChildrenNodes(), EAGLE_LIBRARY::KiCadSymbols, MapChildren(), name, EGATE::name, EDEVICE::name, EDEVICE_SET::name, EAGLE_LIBRARY::package, EDEVICE::package, EDEVICE_SET::prefix, REFERENCE_FIELD, EDA_TEXT::SetText(), EDA_TEXT::SetVisible(), EGATE::symbol, and EAGLE_LIBRARY::SymbolNodes.

◆ loadPin()

LIB_PIN * SCH_EAGLE_PLUGIN::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aPin,
EPIN epin,
int  aGateNumber 
)
private

Definition at line 1763 of file sch_eagle_plugin.cpp.

1765 {
1766  std::unique_ptr<LIB_PIN> pin = std::make_unique<LIB_PIN>( aPart.get() );
1767  pin->SetPosition( wxPoint( aEPin->x.ToSchUnits(), aEPin->y.ToSchUnits() ) );
1768  pin->SetName( aEPin->name );
1769  pin->SetUnit( aGateNumber );
1770 
1771  int roti = aEPin->rot ? aEPin->rot->degrees : 0;
1772 
1773  switch( roti )
1774  {
1775  default:
1776  wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
1778 
1779  case 0:
1780  pin->SetOrientation( 'R' );
1781  break;
1782 
1783  case 90:
1784  pin->SetOrientation( 'U' );
1785  break;
1786 
1787  case 180:
1788  pin->SetOrientation( 'L' );
1789  break;
1790 
1791  case 270:
1792  pin->SetOrientation( 'D' );
1793  break;
1794  }
1795 
1796  pin->SetLength( Mils2iu( 300 ) ); // Default pin length when not defined.
1797 
1798  if( aEPin->length )
1799  {
1800  wxString length = aEPin->length.Get();
1801 
1802  if( length == "short" )
1803  pin->SetLength( Mils2iu( 100 ) );
1804  else if( length == "middle" )
1805  pin->SetLength( Mils2iu( 200 ) );
1806  else if( length == "long" )
1807  pin->SetLength( Mils2iu( 300 ) );
1808  else if( length == "point" )
1809  pin->SetLength( Mils2iu( 0 ) );
1810  }
1811 
1812  // emulate the visibility of pin elements
1813  if( aEPin->visible )
1814  {
1815  wxString visible = aEPin->visible.Get();
1816 
1817  if( visible == "off" )
1818  {
1819  pin->SetNameTextSize( 0 );
1820  pin->SetNumberTextSize( 0 );
1821  }
1822  else if( visible == "pad" )
1823  {
1824  pin->SetNameTextSize( 0 );
1825  }
1826  else if( visible == "pin" )
1827  {
1828  pin->SetNumberTextSize( 0 );
1829  }
1830 
1831  /*
1832  * else if( visible == "both" )
1833  * {
1834  * }
1835  */
1836  }
1837 
1838  if( aEPin->function )
1839  {
1840  wxString function = aEPin->function.Get();
1841 
1842  if( function == "dot" )
1843  {
1844  pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
1845  }
1846  else if( function == "clk" )
1847  {
1848  pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
1849  }
1850  else if( function == "dotclk" )
1851  {
1853  }
1854  }
1855 
1856  return pin.release();
1857 }
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References CLOCK, EROT::degrees, Format(), EPIN::function, OPTIONAL_XML_ATTRIBUTE< T >::Get(), INVERTED, INVERTED_CLOCK, KI_FALLTHROUGH, EPIN::length, EPIN::name, pin, EPIN::rot, ECOORD::ToSchUnits(), EPIN::visible, EPIN::x, and EPIN::y.

◆ loadPlainText()

SCH_TEXT * SCH_EAGLE_PLUGIN::loadPlainText ( wxXmlNode *  aSchText)
private

Definition at line 2062 of file sch_eagle_plugin.cpp.

2063 {
2064  std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
2065  ETEXT etext = ETEXT( aSchText );
2066 
2067  const wxString& thetext = aSchText->GetNodeContent();
2068 
2069  wxString adjustedText;
2070  wxStringTokenizer tokenizer( thetext, "\r\n" );
2071 
2072  // Strip the whitespace from both ends of each line.
2073  while( tokenizer.HasMoreTokens() )
2074  {
2075  wxString tmp = tokenizer.GetNextToken().Trim();
2076 
2077  tmp = tmp.Trim( false );
2078 
2079  if( tokenizer.HasMoreTokens() )
2080  tmp += wxT( "\n" );
2081 
2082  adjustedText += tmp;
2083  }
2084 
2085  schtext->SetText( adjustedText.IsEmpty() ? "\" \"" : escapeName( adjustedText ) );
2086  schtext->SetPosition( wxPoint( etext.x.ToSchUnits(), -etext.y.ToSchUnits() ) );
2087  loadTextAttributes( schtext.get(), etext );
2088  schtext->SetItalic( false );
2089 
2090  return schtext.release();
2091 }
int ToSchUnits() const
Definition: eagle_parser.h:429
Eagle text element.
Definition: eagle_parser.h:637
wxString escapeName(const wxString &aNetName)
ECOORD x
Definition: eagle_parser.h:640
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
ECOORD y
Definition: eagle_parser.h:641

References escapeName(), ECOORD::ToSchUnits(), ETEXT::x, and ETEXT::y.

◆ loadSchematic()

void SCH_EAGLE_PLUGIN::loadSchematic ( wxXmlNode *  aSchematicNode)
private

Definition at line 551 of file sch_eagle_plugin.cpp.

552 {
553  // Map all children into a readable dictionary
554  NODE_MAP schematicChildren = MapChildren( aSchematicNode );
555  wxXmlNode* partNode = getChildrenNodes( schematicChildren, "parts" );
556  wxXmlNode* libraryNode = getChildrenNodes( schematicChildren, "libraries" );
557  wxXmlNode* sheetNode = getChildrenNodes( schematicChildren, "sheets" );
558 
559  if( !partNode || !libraryNode || !sheetNode )
560  return;
561 
562  while( partNode )
563  {
564  std::unique_ptr<EPART> epart = std::make_unique<EPART>( partNode );
565 
566  // N.B. Eagle parts are case-insensitive in matching but we keep the display case
567  m_partlist[epart->name.Upper()] = std::move( epart );
568  partNode = partNode->GetNext();
569  }
570 
571  // Loop through all the libraries
572  while( libraryNode )
573  {
574  // Read the library name
575  wxString libName = libraryNode->GetAttribute( "name" );
576 
577  EAGLE_LIBRARY* elib = &m_eagleLibs[libName];
578  elib->name = libName;
579 
580  loadLibrary( libraryNode, &m_eagleLibs[libName] );
581 
582  libraryNode = libraryNode->GetNext();
583  }
584 
585  m_pi->SaveLibrary( getLibFileName().GetFullPath() );
586 
587  // find all nets and count how many sheets they appear on.
588  // local labels will be used for nets found only on that sheet.
589  countNets( aSchematicNode );
590 
591  // Loop through all the sheets
592  int sheet_count = countChildren( sheetNode->GetParent(), "sheet" );
593 
594  // If eagle schematic has multiple sheets then create corresponding subsheets on the root sheet
595  if( sheet_count > 1 )
596  {
597  int x, y, i;
598  i = 1;
599  x = 1;
600  y = 1;
601 
602  while( sheetNode )
603  {
604  wxPoint pos = wxPoint( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) );
605  std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>( m_rootSheet, pos );
606  SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
607 
608  sheet->SetScreen( screen );
609  sheet->GetScreen()->SetFileName( sheet->GetFileName() );
610 
611  m_currentSheet = sheet.get();
612  loadSheet( sheetNode, i );
613  m_rootSheet->GetScreen()->Append( sheet.release() );
614 
615  sheetNode = sheetNode->GetNext();
616  x += 2;
617 
618  if( x > 10 ) // start next row
619  {
620  x = 1;
621  y += 2;
622  }
623 
624  i++;
625  }
626  }
627  else
628  {
629  while( sheetNode )
630  {
632  loadSheet( sheetNode, 0 );
633  sheetNode = sheetNode->GetNext();
634  }
635  }
636 
637  // Handle the missing component units that need to be instantiated
638  // to create the missing implicit connections
639 
640  // Calculate the already placed items bounding box and the page size to determine
641  // placement for the new components
642  wxSize pageSizeIU = m_rootSheet->GetScreen()->GetPageSettings().GetSizeIU();
643  EDA_RECT sheetBbox = getSheetBbox( m_rootSheet );
644  wxPoint newCmpPosition( sheetBbox.GetLeft(), sheetBbox.GetBottom() );
645  int maxY = sheetBbox.GetY();
646 
647  SCH_SHEET_PATH sheetpath;
649 
650  for( auto& cmp : m_missingCmps )
651  {
652  const SCH_COMPONENT* origCmp = cmp.second.cmp;
653 
654  for( auto unitEntry : cmp.second.units )
655  {
656  if( unitEntry.second == false )
657  continue; // unit has been already processed
658 
659  // Instantiate the missing component unit
660  int unit = unitEntry.first;
661  const wxString reference = origCmp->GetField( REFERENCE_FIELD )->GetText();
662  std::unique_ptr<SCH_COMPONENT> component( (SCH_COMPONENT*) origCmp->Duplicate() );
663 
664  component->SetUnitSelection( &sheetpath, unit );
665  component->SetUnit( unit );
666  component->SetOrientation( 0 );
667  component->AddHierarchicalReference( sheetpath.Path(), reference, unit );
668 
669  // Calculate the placement position
670  EDA_RECT cmpBbox = component->GetBoundingBox();
671  int posY = newCmpPosition.y + cmpBbox.GetHeight();
672  component->SetPosition( wxPoint( newCmpPosition.x, posY ) );
673  newCmpPosition.x += cmpBbox.GetWidth();
674  maxY = std::max( maxY, posY );
675 
676  if( newCmpPosition.x >= pageSizeIU.GetWidth() ) // reached the page boundary?
677  newCmpPosition = wxPoint( sheetBbox.GetLeft(), maxY ); // then start a new row
678 
679  // Add the global net labels to recreate the implicit connections
680  addImplicitConnections( component.get(), m_rootSheet->GetScreen(), false );
681  m_rootSheet->GetScreen()->Append( component.release() );
682  }
683  }
684 
685  m_missingCmps.clear();
686 }
Field Reference of part, i.e. "IC21".
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:693
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
int GetLeft() const
Definition: eda_rect.h:117
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
int GetWidth() const
Definition: eda_rect.h:114
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provide an easy access to the children of an XML node via their names.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:128
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
int GetBottom() const
Definition: eda_rect.h:119
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:78
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
int GetHeight() const
Definition: eda_rect.h:115
static EDA_RECT getSheetBbox(SCH_SHEET *aSheet)
Extract the net name part from a pin name (e.g. return 'GND' for pin named 'GND@2')
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:665
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
Handle the component boundary box.
Definition: eda_rect.h:42
Schematic symbol object.
Definition: sch_symbol.h:78
int GetY() const
Definition: eda_rect.h:104
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
void countNets(wxXmlNode *aSchematicNode)
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:57

References countChildren(), SCH_ITEM::Duplicate(), EDA_RECT::GetBottom(), getChildrenNodes(), SCH_COMPONENT::GetField(), EDA_RECT::GetHeight(), EDA_RECT::GetLeft(), getSheetBbox(), EDA_TEXT::GetText(), EDA_RECT::GetWidth(), EDA_RECT::GetY(), MapChildren(), EAGLE_LIBRARY::name, SCH_SHEET_PATH::Path(), and REFERENCE_FIELD.

◆ loadSegments()

void SCH_EAGLE_PLUGIN::loadSegments ( wxXmlNode *  aSegmentsNode,
const wxString &  aNetName,
const wxString &  aNetClass 
)
private

Definition at line 897 of file sch_eagle_plugin.cpp.

899 {
900  // Loop through all segments
901  wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
902  SCH_SCREEN* screen = m_currentSheet->GetScreen();
903 
904  int segmentCount = countChildren( aSegmentsNode, "segment" );
905 
906  // wxCHECK( screen, [>void<] );
907  while( currentSegment )
908  {
909  bool labelled = false; // has a label been added to this continuously connected segment
910  NODE_MAP segmentChildren = MapChildren( currentSegment );
911  SCH_LINE* firstWire = nullptr;
912  m_segments.emplace_back();
913  SEG_DESC& segDesc = m_segments.back();
914 
915  // Loop through all segment children
916  wxXmlNode* segmentAttribute = currentSegment->GetChildren();
917 
918  while( segmentAttribute )
919  {
920  if( segmentAttribute->GetName() == "wire" )
921  {
922  SCH_LINE* wire = loadWire( segmentAttribute );
923 
924  if( !firstWire )
925  firstWire = wire;
926 
927  // Test for intersections with other wires
928  SEG thisWire( wire->GetStartPoint(), wire->GetEndPoint() );
929 
930  for( auto& desc : m_segments )
931  {
932  if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
933  continue; // no point in saving intersections of the same net
934 
935  for( const auto& seg : desc.segs )
936  {
937  auto intersection = thisWire.Intersect( seg, true );
938 
939  if( intersection )
940  m_wireIntersections.push_back( *intersection );
941  }
942  }
943 
944  segDesc.segs.push_back( thisWire );
945  screen->Append( wire );
946  }
947 
948  segmentAttribute = segmentAttribute->GetNext();
949  }
950 
951  segmentAttribute = currentSegment->GetChildren();
952 
953  while( segmentAttribute )
954  {
955  wxString nodeName = segmentAttribute->GetName();
956 
957  if( nodeName == "junction" )
958  {
959  screen->Append( loadJunction( segmentAttribute ) );
960  }
961  else if( nodeName == "label" )
962  {
963  SCH_TEXT* label = loadLabel( segmentAttribute, netName );
964  screen->Append( label );
965  wxASSERT( segDesc.labels.empty()
966  || segDesc.labels.front()->GetText() == label->GetText() );
967  segDesc.labels.push_back( label );
968  labelled = true;
969  }
970  else if( nodeName == "pinref" )
971  {
972  segmentAttribute->GetAttribute( "gate" ); // REQUIRED
973  segmentAttribute->GetAttribute( "part" ); // REQUIRED
974  segmentAttribute->GetAttribute( "pin" ); // REQUIRED
975  }
976  else if( nodeName == "wire" )
977  {
978  // already handled;
979  }
980  else // DEFAULT
981  {
982  // THROW_IO_ERROR( wxString::Format( _( "XML node \"%s\" unknown" ), nodeName ) );
983  }
984 
985  // Get next segment attribute
986  segmentAttribute = segmentAttribute->GetNext();
987  }
988 
989  // Add a small label to the net segment if it hasn't been labeled already or is not
990  // connect to a power symbol with a pin on the same net. This preserves the named net
991  // feature of Eagle schematics.
992  if( !labelled && firstWire )
993  {
994  std::unique_ptr<SCH_TEXT> label;
995 
996  // Add a global label if the net appears on more than one Eagle sheet
997  if( m_netCounts[netName.ToStdString()] > 1 )
998  label.reset( new SCH_GLOBALLABEL );
999  else if( segmentCount > 1 )
1000  label.reset( new SCH_LABEL );
1001 
1002  if( label )
1003  {
1004  label->SetPosition( firstWire->GetStartPoint() );
1005  label->SetText( escapeName( netName ) );
1006  label->SetTextSize( wxSize( Mils2iu( 40 ), Mils2iu( 40 ) ) );
1007  label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
1008  screen->Append( label.release() );
1009  }
1010  }
1011 
1012  currentSegment = currentSegment->GetNext();
1013  }
1014 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
wxPoint GetStartPoint() const
Definition: sch_line.h:90
SCH_LINE * loadWire(wxXmlNode *aWireNode)
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition: seg.cpp:119
std::map< wxString, int > m_netCounts
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provide an easy access to the children of an XML node via their names.
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
wxString escapeName(const wxString &aNetName)
SCH_TEXT * loadLabel(wxXmlNode *aLabelNode, const wxString &aNetName)
Definition: seg.h:41
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
struct SCH_EAGLE_PLUGIN::SEG_DESC_STRUCT SEG_DESC
Segments representing wires for intersection checking.
void SetPosition(const wxPoint &aPosition) override
Definition: sch_text.h:294
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References SCH_SCREEN::Append(), countChildren(), escapeName(), SCH_LINE::GetEndPoint(), SCH_LINE::GetStartPoint(), EDA_TEXT::GetText(), SEG::Intersect(), SCH_EAGLE_PLUGIN::SEG_DESC_STRUCT::labels, LABEL_SPIN_STYLE::LEFT, MapChildren(), and SCH_EAGLE_PLUGIN::SEG_DESC_STRUCT::segs.

◆ loadSheet()

void SCH_EAGLE_PLUGIN::loadSheet ( wxXmlNode *  aSheetNode,
int  sheetcount 
)
private

Definition at line 689 of file sch_eagle_plugin.cpp.

690 {
691  // Map all children into a readable dictionary
692  NODE_MAP sheetChildren = MapChildren( aSheetNode );
693 
694  // Get description node
695  wxXmlNode* descriptionNode = getChildrenNodes( sheetChildren, "description" );
696 
697  wxString des;
698  std::string filename;
699  SCH_FIELD& sheetNameField = m_currentSheet->GetFields()[SHEETNAME];
700  SCH_FIELD& filenameField = m_currentSheet->GetFields()[SHEETFILENAME];
701 
702  if( descriptionNode )
703  {
704  des = descriptionNode->GetContent();
705  des.Replace( "\n", "_", true );
706  sheetNameField.SetText( des );
707  filename = des.ToStdString();
708  }
709  else
710  {
711  filename = wxString::Format( "%s_%d", m_filename.GetName(), aSheetIndex );
712  sheetNameField.SetText( filename );
713  }
714 
715  ReplaceIllegalFileNameChars( &filename );
716  replace( filename.begin(), filename.end(), ' ', '_' );
717 
718  wxString fn = wxString( filename + "." + KiCadSchematicFileExtension );
719  filenameField.SetText( fn );
720  wxFileName fileName( fn );
721  m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
723 
724 
725  // Loop through all of the symbol instances.
726  wxXmlNode* instanceNode = getChildrenNodes( sheetChildren, "instances" );
727 
728  while( instanceNode )
729  {
730  loadInstance( instanceNode );
731  instanceNode = instanceNode->GetNext();
732  }
733 
734  // Loop through all buses
735  // From the DTD: "Buses receive names which determine which signals they include.
736  // A bus is a drawing object. It does not create any electrical connections.
737  // These are always created by means of the nets and their names."
738  wxXmlNode* busNode = getChildrenNodes( sheetChildren, "busses" );
739 
740  while( busNode )
741  {
742  // Get the bus name
743  wxString busName = translateEagleBusName( busNode->GetAttribute( "name" ) );
744 
745  // Load segments of this bus
746  loadSegments( busNode, busName, wxString() );
747 
748  // Get next bus
749  busNode = busNode->GetNext();
750  }
751 
752  // Loop through all nets
753  // From the DTD: "Net is an electrical connection in a schematic."
754  wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
755 
756  while( netNode )
757  {
758  // Get the net name and class
759  wxString netName = netNode->GetAttribute( "name" );
760  wxString netClass = netNode->GetAttribute( "class" );
761 
762  // Load segments of this net
763  loadSegments( netNode, netName, netClass );
764 
765  // Get next net
766  netNode = netNode->GetNext();
767  }
768 
769  adjustNetLabels(); // needs to be called before addBusEntries()
770  addBusEntries();
771 
772  /* moduleinst is a design block definition and is an EagleCad 8 feature,
773  *
774  * // Loop through all moduleinsts
775  * wxXmlNode* moduleinstNode = getChildrenNodes( sheetChildren, "moduleinsts" );
776  *
777  * while( moduleinstNode )
778  * {
779  * loadModuleinst( moduleinstNode );
780  * moduleinstNode = moduleinstNode->GetNext();
781  * }
782  */
783 
784  wxXmlNode* plainNode = getChildrenNodes( sheetChildren, "plain" );
785 
786  while( plainNode )
787  {
788  wxString nodeName = plainNode->GetName();
789 
790  if( nodeName == "text" )
791  {
792  m_currentSheet->GetScreen()->Append( loadPlainText( plainNode ) );
793  }
794  else if( nodeName == "wire" )
795  {
796  m_currentSheet->GetScreen()->Append( loadWire( plainNode ) );
797  }
798  else if( nodeName == "frame" )
799  {
800  std::vector<SCH_LINE*> lines;
801 
802  loadFrame( plainNode, lines );
803 
804  for( SCH_LINE* line : lines )
805  m_currentSheet->GetScreen()->Append( line );
806  }
807 
808  plainNode = plainNode->GetNext();
809  }
810 
811  // Calculate the new sheet size.
812  EDA_RECT sheetBoundingBox = getSheetBbox( m_currentSheet );
813  wxSize targetSheetSize = sheetBoundingBox.GetSize();
814  targetSheetSize.IncBy( Mils2iu( 1500 ), Mils2iu( 1500 ) );
815 
816  // Get current Eeschema sheet size.
817  wxSize pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
819 
820  // Increase if necessary
821  if( pageSizeIU.x < targetSheetSize.x )
822  pageInfo.SetWidthMils( Iu2Mils( targetSheetSize.x ) );
823 
824  if( pageSizeIU.y < targetSheetSize.y )
825  pageInfo.SetHeightMils( Iu2Mils( targetSheetSize.y ) );
826 
827  // Set the new sheet size.
828  m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
829 
830  pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
831  wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
832  wxPoint itemsCentre = sheetBoundingBox.Centre();
833 
834  // round the translation to nearest 100mil to place it on the grid.
835  wxPoint translation = sheetcentre - itemsCentre;
836  translation.x = translation.x - translation.x % Mils2iu( 100 );
837  translation.y = translation.y - translation.y % Mils2iu( 100 );
838 
839  // Add global net labels for the named power input pins in this sheet
840  for( auto item : m_currentSheet->GetScreen()->Items().OfType( SCH_COMPONENT_T ) )
842  static_cast<SCH_COMPONENT*>( item ), m_currentSheet->GetScreen(), true );
843 
844  m_connPoints.clear();
845 
846  // Translate the items.
847  std::vector<SCH_ITEM*> allItems;
848 
849  std::copy( m_currentSheet->GetScreen()->Items().begin(),
850  m_currentSheet->GetScreen()->Items().end(), std::back_inserter( allItems ) );
851 
852  for( auto item : allItems )
853  {
854  item->SetPosition( item->GetPosition() + translation );
855  item->ClearFlags();
856  m_currentSheet->GetScreen()->Update( item );
857 
858  }
859 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:216
Instances are attached to a symbol or sheet and provide a place for the component's value,...
Definition: sch_field.h:50
SCH_LINE * loadWire(wxXmlNode *aWireNode)
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:765
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:129
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:128
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Provide an easy access to the children of an XML node via their names.
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
iterator end()
Definition: sch_rtree.h:250
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_LINE * > &aLines)
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static EDA_RECT getSheetBbox(SCH_SHEET *aSheet)
Extract the net name part from a pin name (e.g. return 'GND' for pin named 'GND@2')
void loadInstance(wxXmlNode *aInstanceNode)
wxString translateEagleBusName(const wxString &aEagleName) const
Translate an Eagle-style bus name into one that is KiCad-compatible.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:128
iterator begin()
Definition: sch_rtree.h:245
EE_RTREE & Items()
Definition: sch_screen.h:103
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:243
Handle the component boundary box.
Definition: eda_rect.h:42
const std::string KiCadSchematicFileExtension
wxPoint Centre() const
Definition: eda_rect.h:60
void Update(SCH_ITEM *aItem)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:237
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:131
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:515
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:47
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:57
const wxSize GetSize() const
Definition: eda_rect.h:96
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints

References EDA_RECT::Centre(), Format(), getChildrenNodes(), getSheetBbox(), EDA_RECT::GetSize(), KiCadSchematicFileExtension, MapChildren(), SCH_FIELD::Replace(), ReplaceIllegalFileNameChars(), SCH_COMPONENT_T, PAGE_INFO::SetHeightMils(), EDA_TEXT::SetText(), PAGE_INFO::SetWidthMils(), SHEETFILENAME, and SHEETNAME.

◆ loadSymbol()

bool SCH_EAGLE_PLUGIN::loadSymbol ( wxXmlNode *  aSymbolNode,
std::unique_ptr< LIB_PART > &  aPart,
EDEVICE aDevice,
int  aGateNumber,
const wxString &  aGateName 
)
private

Definition at line 1464 of file sch_eagle_plugin.cpp.

1466 {
1467  wxString symbolName = aSymbolNode->GetAttribute( "name" );
1468  std::vector<LIB_ITEM*> items;
1469 
1470  wxXmlNode* currentNode = aSymbolNode->GetChildren();
1471 
1472  bool foundName = false;
1473  bool foundValue = false;
1474  bool ispower = false;
1475  int pincount = 0;
1476 
1477  while( currentNode )
1478  {
1479  wxString nodeName = currentNode->GetName();
1480 
1481  if( nodeName == "circle" )
1482  {
1483  aPart->AddDrawItem( loadSymbolCircle( aPart, currentNode, aGateNumber ) );
1484  }
1485  else if( nodeName == "pin" )
1486  {
1487  EPIN ePin = EPIN( currentNode );
1488  std::unique_ptr<LIB_PIN> pin( loadPin( aPart, currentNode, &ePin, aGateNumber ) );
1489  pincount++;
1490 
1491  pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
1492 
1493  if( ePin.direction )
1494  {
1495  for( const auto& pinDir : pinDirectionsMap )
1496  {
1497  if( ePin.direction->Lower() == pinDir.first )
1498  {
1499  pin->SetType( pinDir.second );
1500 
1501  if( pinDir.first == "sup" ) // power supply symbol
1502  ispower = true;
1503 
1504  break;
1505  }
1506  }
1507  }
1508 
1509 
1510  if( aDevice->connects.size() != 0 )
1511  {
1512  for( const auto& connect : aDevice->connects )
1513  {
1514  if( connect.gate == aGateName && pin->GetName() == connect.pin )
1515  {
1516  wxArrayString pads = wxSplit( wxString( connect.pad ), ' ' );
1517 
1518  pin->SetUnit( aGateNumber );
1519  pin->SetName( escapeName( pin->GetName() ) );
1520 
1521  if( pads.GetCount() > 1 )
1522  {
1523  pin->SetNumberTextSize( 0 );
1524  }
1525 
1526  for( unsigned i = 0; i < pads.GetCount(); i++ )
1527  {
1528  LIB_PIN* apin = new LIB_PIN( *pin );
1529 
1530  wxString padname( pads[i] );
1531  apin->SetNumber( padname );
1532  aPart->AddDrawItem( apin );
1533  }
1534 
1535  break;
1536  }
1537  }
1538  }
1539  else
1540  {
1541  pin->SetUnit( aGateNumber );
1542  pin->SetNumber( wxString::Format( "%i", pincount ) );
1543  aPart->AddDrawItem( pin.release() );
1544  }
1545  }
1546  else if( nodeName == "polygon" )
1547  {
1548  aPart->AddDrawItem( loadSymbolPolyLine( aPart, currentNode, aGateNumber ) );
1549  }
1550  else if( nodeName == "rectangle" )
1551  {
1552  aPart->AddDrawItem( loadSymbolRectangle( aPart, currentNode, aGateNumber ) );
1553  }
1554  else if( nodeName == "text" )
1555  {
1556  std::unique_ptr<LIB_TEXT> libtext( loadSymbolText( aPart, currentNode, aGateNumber ) );
1557 
1558  if( libtext->GetText().Upper() == ">NAME" )
1559  {
1560  LIB_FIELD* field = aPart->GetFieldById( REFERENCE_FIELD );
1561  loadFieldAttributes( field, libtext.get() );
1562  foundName = true;
1563  }
1564  else if( libtext->GetText().Upper() == ">VALUE" )
1565  {
1566  LIB_FIELD* field = aPart->GetFieldById( VALUE_FIELD );
1567  loadFieldAttributes( field, libtext.get() );
1568  foundValue = true;
1569  }
1570  else
1571  {
1572  aPart->AddDrawItem( libtext.release() );
1573  }
1574  }
1575  else if( nodeName == "wire" )
1576  {
1577  aPart->AddDrawItem( loadSymbolWire( aPart, currentNode, aGateNumber ) );
1578  }
1579  else if( nodeName == "frame" )
1580  {
1581  std::vector<LIB_ITEM*> frameItems;
1582 
1583  loadFrame( currentNode, frameItems );
1584 
1585  for( LIB_ITEM* item : frameItems )
1586  {
1587  item->SetParent( aPart.get() );
1588  aPart->AddDrawItem( item );
1589  }
1590  }
1591 
1592  /*
1593  * else if( nodeName == "description" )
1594  * {
1595  * }
1596  * else if( nodeName == "dimension" )
1597  * {
1598  * }
1599  */
1600 
1601  currentNode = currentNode->GetNext();
1602  }
1603 
1604  if( foundName == false )
1605  aPart->GetFieldById( REFERENCE_FIELD )->SetVisible( false );
1606 
1607  if( foundValue == false )
1608  aPart->GetFieldById( VALUE_FIELD )->SetVisible( false );
1609 
1610  return pincount == 1 ? ispower : false;
1611 }
Field Reference of part, i.e. "IC21".
opt_wxString direction
Definition: eagle_parser.h:749
Field object used in symbol libraries.
Definition: lib_field.h:59
LIB_RECTANGLE * loadSymbolRectangle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aRectNode, int aGateNumber)
Eagle pin element.
Definition: eagle_parser.h:741
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:118
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *, EPIN *epin, int aGateNumber)
wxString escapeName(const wxString &aNetName)
Field Value of part, i.e. "3.3K".
LIB_CIRCLE * loadSymbolCircle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aCircleNode, int aGateNumber)
void loadFrame(wxXmlNode *aFrameNode, std::vector< SCH_LINE * > &aLines)
LIB_ITEM * loadSymbolWire(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aWireNode, int aGateNumber)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void loadFieldAttributes(LIB_FIELD *aField, const LIB_TEXT *aText) const
Move net labels that are detached from any wire to the nearest wire.
std::vector< ECONNECT > connects
static const std::map< wxString, ELECTRICAL_PINTYPE > pinDirectionsMap
Map of EAGLE pin type values to KiCad pin type values.
LIB_TEXT * loadSymbolText(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aLibText, int aGateNumber)
input or output (like port for a microprocessor)
LIB_POLYLINE * loadSymbolPolyLine(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aPolygonNode, int aGateNumber)

References EDEVICE::connects, EPIN::direction, escapeName(), Format(), pin, pinDirectionsMap, PT_BIDI, REFERENCE_FIELD, LIB_PIN::SetNumber(), and VALUE_FIELD.

◆ LoadSymbol()

LIB_PART * SCH_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aPartName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about.

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 85 of file sch_plugin.cpp.

87 {
88  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
89  not_implemented( this, __FUNCTION__ );
90  return NULL;
91 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37
#define NULL

References not_implemented(), and NULL.

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ loadSymbolCircle()

LIB_CIRCLE * SCH_EAGLE_PLUGIN::loadSymbolCircle ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aCircleNode,
int  aGateNumber 
)
private

Definition at line 1614 of file sch_eagle_plugin.cpp.

1616 {
1617  // Parse the circle properties
1618  ECIRCLE c( aCircleNode );
1619 
1620  unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( aPart.get() ) );
1621 
1622  circle->SetPosition( wxPoint( c.x.ToSchUnits(), c.y.ToSchUnits() ) );
1623  circle->SetRadius( c.radius.ToSchUnits() );
1624  circle->SetWidth( c.width.ToSchUnits() );
1625  circle->SetUnit( aGateNumber );
1626 
1627  return circle.release();
1628 }
Eagle circle.
Definition: eagle_parser.h:562

References ECIRCLE::radius, ECOORD::ToSchUnits(), ECIRCLE::width, ECIRCLE::x, and ECIRCLE::y.

◆ loadSymbolPolyLine()

LIB_POLYLINE * SCH_EAGLE_PLUGIN::loadSymbolPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aPolygonNode,
int  aGateNumber 
)
private

Definition at line 1735 of file sch_eagle_plugin.cpp.

1737 {
1738  std::unique_ptr<LIB_POLYLINE> polyLine = std::make_unique<LIB_POLYLINE>( aPart.get() );
1739 
1740  EPOLYGON epoly( aPolygonNode );
1741  wxXmlNode* vertex = aPolygonNode->GetChildren();
1742  wxPoint pt;
1743 
1744  while( vertex )
1745  {
1746  if( vertex->GetName() == "vertex" ) // skip <xmlattr> node
1747  {
1748  EVERTEX evertex( vertex );
1749  pt = wxPoint( evertex.x.ToSchUnits(), evertex.y.ToSchUnits() );
1750  polyLine->AddPoint( pt );
1751  }
1752 
1753  vertex = vertex->GetNext();
1754  }
1755 
1756  polyLine->SetFillMode( FILL_TYPE::FILLED_SHAPE );
1757  polyLine->SetUnit( aGateNumber );
1758 
1759  return polyLine.release();
1760 }
Eagle vertex.
Definition: eagle_parser.h:759
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:770

References FILLED_SHAPE, ECOORD::ToSchUnits(), EVERTEX::x, and EVERTEX::y.

◆ loadSymbolRectangle()

LIB_RECTANGLE * SCH_EAGLE_PLUGIN::loadSymbolRectangle ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aRectNode,
int  aGateNumber 
)
private

Definition at line 1631 of file sch_eagle_plugin.cpp.

1633 {
1634  ERECT rect( aRectNode );
1635 
1636  unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( aPart.get() ) );
1637 
1638  rectangle->SetPosition( wxPoint( rect.x1.ToSchUnits(), rect.y1.ToSchUnits() ) );
1639  rectangle->SetEnd( wxPoint( rect.x2.ToSchUnits(), rect.y2.ToSchUnits() ) );
1640 
1641  rectangle->SetUnit( aGateNumber );
1642 
1643  // Eagle rectangles are filled by definition.
1644  rectangle->SetFillMode( FILL_TYPE::FILLED_SHAPE );
1645 
1646  return rectangle.release();
1647 }
Eagle XML rectangle in binary.
Definition: eagle_parser.h:575

References FILLED_SHAPE, ECOORD::ToSchUnits(), ERECT::x1, ERECT::x2, ERECT::y1, and ERECT::y2.

◆ loadSymbolText()

LIB_TEXT * SCH_EAGLE_PLUGIN::loadSymbolText ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aLibText,
int  aGateNumber 
)
private

Definition at line 1860 of file sch_eagle_plugin.cpp.

1862 {
1863  std::unique_ptr<LIB_TEXT> libtext = std::make_unique<LIB_TEXT>( aPart.get() );
1864  ETEXT etext( aLibText );
1865 
1866  libtext->SetUnit( aGateNumber );
1867  libtext->SetPosition( wxPoint( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
1868 
1869  // Eagle supports multiple line text in library symbols. Legacy library symbol text cannot
1870  // contain CRs or LFs.
1871  //
1872  // @todo Split this into multiple text objects and offset the Y position so that it looks
1873  // more like the original Eagle schematic.
1874  wxString text = aLibText->GetNodeContent();
1875  std::replace( text.begin(), text.end(), '\n', '_' );
1876  std::replace( text.begin(), text.end(), '\r', '_' );
1877 
1878  libtext->SetText( text.IsEmpty() ? "~~" : text );
1879  loadTextAttributes( libtext.get(), etext );
1880 
1881  return libtext.release();
1882 }
Eagle text element.
Definition: eagle_parser.h:637
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const

References text.

◆ loadSymbolWire()

LIB_ITEM * SCH_EAGLE_PLUGIN::loadSymbolWire ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aWireNode,
int  aGateNumber 
)
private

Definition at line 1650 of file sch_eagle_plugin.cpp.

1652 {
1653  auto ewire = EWIRE( aWireNode );
1654 
1655  wxPoint begin, end;
1656 
1657  begin.x = ewire.x1.ToSchUnits();
1658  begin.y = ewire.y1.ToSchUnits();
1659  end.x = ewire.x2.ToSchUnits();
1660  end.y = ewire.y2.ToSchUnits();
1661 
1662  if( begin == end )
1663  return nullptr;
1664 
1665  // if the wire is an arc
1666  if( ewire.curve )
1667  {
1668  std::unique_ptr<LIB_ARC> arc = std::make_unique<LIB_ARC>( aPart.get() );
1669  wxPoint center = ConvertArcCenter( begin, end, *ewire.curve * -1 );
1670 
1671  double radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
1672  + ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) )
1673  * 2;
1674 
1675  // this emulates the filled semicircles created by a thick arc with flat ends caps.
1676  if( ewire.width.ToSchUnits() * 2 > radius )
1677  {
1678  wxPoint centerStartVector = begin - center;
1679  wxPoint centerEndVector = end - center;
1680 
1681  centerStartVector.x = centerStartVector.x * ewire.width.ToSchUnits() * 2 / radius;
1682  centerStartVector.y = centerStartVector.y * ewire.width.ToSchUnits() * 2 / radius;
1683 
1684  centerEndVector.x = centerEndVector.x * ewire.width.ToSchUnits() * 2 / radius;
1685  centerEndVector.y = centerEndVector.y * ewire.width.ToSchUnits() * 2 / radius;
1686 
1687  begin = center + centerStartVector;
1688  end = center + centerEndVector;
1689 
1690  radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
1691  + ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) )
1692  * 2;
1693 
1694  arc->SetWidth( 1 );
1695  arc->SetFillMode( FILL_TYPE::FILLED_SHAPE );
1696  }
1697  else
1698  {
1699  arc->SetWidth( ewire.width.ToSchUnits() );
1700  }
1701 
1702  arc->SetPosition( center );
1703 
1704  if( *ewire.curve > 0 )
1705  {
1706  arc->SetStart( begin );
1707  arc->SetEnd( end );
1708  }
1709  else
1710  {
1711  arc->SetStart( end );
1712  arc->SetEnd( begin );
1713  }
1714 
1715  arc->SetRadius( radius );
1716  arc->CalcRadiusAngles();
1717  arc->SetUnit( aGateNumber );
1718 
1719  return (LIB_ITEM*) arc.release();
1720  }
1721  else
1722  {
1723  std::unique_ptr<LIB_POLYLINE> polyLine = std::make_unique<LIB_POLYLINE>( aPart.get() );
1724 
1725  polyLine->AddPoint( begin );
1726  polyLine->AddPoint( end );
1727  polyLine->SetUnit( aGateNumber );
1728  polyLine->SetWidth( ewire.width.ToSchUnits() );
1729 
1730  return (LIB_ITEM*) polyLine.release();
1731  }
1732 }
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Eagle wire.
Definition: eagle_parser.h:491

References ConvertArcCenter(), and FILLED_SHAPE.

◆ loadTextAttributes()

void SCH_EAGLE_PLUGIN::loadTextAttributes ( EDA_TEXT aText,
const ETEXT aAttribs 
) const
private

Definition at line 2094 of file sch_eagle_plugin.cpp.

2095 {
2096  aText->SetTextSize( aAttribs.ConvertSize() );
2097 
2098  if( aAttribs.ratio )
2099  {
2100  if( aAttribs.ratio.CGet() > 12 )
2101  {
2102  aText->SetBold( true );
2103  aText->SetTextThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
2104  }
2105  }
2106 
2107  int align = aAttribs.align ? *aAttribs.align : ETEXT::BOTTOM_LEFT;
2108  int degrees = aAttribs.rot ? aAttribs.rot->degrees : 0;
2109  bool mirror = aAttribs.rot ? aAttribs.rot->mirror : false;
2110  bool spin = aAttribs.rot ? aAttribs.rot->spin : false;
2111 
2112  eagleToKicadAlignment( aText, align, degrees, mirror, spin, 0 );
2113 }
bool mirror
Definition: eagle_parser.h:472
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: gr_text.cpp:48
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:303
opt_double ratio
Definition: eagle_parser.h:645
double degrees
Definition: eagle_parser.h:474
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
static void eagleToKicadAlignment(EDA_TEXT *aText, int aEagleAlignment, int aRelDegress, bool aMirror, bool aSpin, int aAbsDegress)
wxSize ConvertSize() const
Calculate text size based on font type and size.
opt_int align
Definition: eagle_parser.h:662
opt_erot rot
Definition: eagle_parser.h:646
int GetTextWidth() const
Definition: eda_text.h:248
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
bool spin
Definition: eagle_parser.h:473
void SetBold(bool aBold)
Definition: eda_text.h:189

References ETEXT::align, ETEXT::BOTTOM_LEFT, OPTIONAL_XML_ATTRIBUTE< T >::CGet(), ETEXT::ConvertSize(), EROT::degrees, eagleToKicadAlignment(), GetPenSizeForBold(), EDA_TEXT::GetTextWidth(), EROT::mirror, ETEXT::ratio, ETEXT::rot, EDA_TEXT::SetBold(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), and EROT::spin.

◆ loadWire()

SCH_LINE * SCH_EAGLE_PLUGIN::loadWire ( wxXmlNode *  aWireNode)
private

Definition at line 1017 of file sch_eagle_plugin.cpp.

1018 {
1019  std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
1020 
1021  auto ewire = EWIRE( aWireNode );
1022 
1023  wire->SetLayer( kiCadLayer( ewire.layer ) );
1024 
1025  wxPoint begin, end;
1026 
1027  begin.x = ewire.x1.ToSchUnits();
1028  begin.y = -ewire.y1.ToSchUnits();
1029  end.x = ewire.x2.ToSchUnits();
1030  end.y = -ewire.y2.ToSchUnits();
1031 
1032  wire->SetStartPoint( begin );
1033  wire->SetEndPoint( end );
1034 
1035  m_connPoints[begin].emplace( wire.get() );
1036  m_connPoints[end].emplace( wire.get() );
1037 
1038  return wire.release();
1039 }
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
Eagle wire.
Definition: eagle_parser.h:491
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints

◆ moveLabels()

void SCH_EAGLE_PLUGIN::moveLabels ( SCH_ITEM aWire,
const wxPoint &  aNewEndPoint 
)
private

Move any labels on the wire to the new end point of the wire.

Definition at line 2224 of file sch_eagle_plugin.cpp.

2225 {
2226  for( auto item : m_currentSheet->GetScreen()->Items().Overlapping( aWire->GetBoundingBox() ) )
2227  {
2228  if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
2229  {
2230  if( TestSegmentHit( item->GetPosition(), ( (SCH_LINE*) aWire )->GetStartPoint(),
2231  ( (SCH_LINE*) aWire )->GetEndPoint(), 0 ) )
2232  {
2233  item->SetPosition( aNewEndPoint );
2234  }
2235  }
2236  }
2237 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
EE_TYPE Overlapping(const EDA_RECT &aRect) const
Definition: sch_rtree.h:221
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
EE_RTREE & Items()
Definition: sch_screen.h:103
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:73

References EDA_ITEM::GetBoundingBox(), SCH_GLOBAL_LABEL_T, SCH_LABEL_T, and TestSegmentHit().

◆ netHasPowerDriver()

bool SCH_EAGLE_PLUGIN::netHasPowerDriver ( SCH_LINE aLine,
const wxString &  aNetName 
) const
private

◆ Save()

void SCH_PLUGIN::Save ( const wxString &  aFileName,
SCH_SHEET aSheet,
SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aSheetis the class SCH_SHEET in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
aSchematicis the SCHEMATIC object used to access any schematic-wide or project information needed to save the document.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL. Set the #PropSaveCurrentSheetOnly property to only save the current sheet. Otherwise, all hierarchical sheets are saved.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 59 of file sch_plugin.cpp.

61 {
62  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
63  not_implemented( this, __FUNCTION__ );
64 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ SaveLibrary()

void SCH_PLUGIN::SaveLibrary ( const wxString &  aFileName,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 45 of file sch_plugin.cpp.

46 {
47  not_implemented( this, __FUNCTION__ );
48 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

◆ SaveSymbol()

void SCH_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_PART aSymbol,
const PROPERTIES aProperties = nullptr 
)
virtualinherited

Write aSymbol to an existing library located at aLibraryPath.

If a LIB_PART by the same name already exists or there are any conflicting alias names, the new LIB_PART will silently overwrite any existing aliases and/or part because libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

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

Reimplemented in SCH_LEGACY_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 94 of file sch_plugin.cpp.

96 {
97  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
98  not_implemented( this, __FUNCTION__ );
99 }
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:37

References not_implemented().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ SetReporter()

void SCH_EAGLE_PLUGIN::SetReporter ( REPORTER aReporter)
inlineoverridevirtual

Set an optional reporter for warnings/errors.

Reimplemented from SCH_PLUGIN.

Definition at line 89 of file sch_eagle_plugin.h.

89 { m_reporter = aReporter; }
REPORTER * m_reporter
Reporter for warnings/errors.

References m_reporter.

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

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

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

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

Definition at line 133 of file sch_plugin.cpp.

134 {
135  // disable all these in another couple of months, after everyone has seen them:
136 #if 1
137  (*aListToAppendTo)["debug_level"] = UTF8( _(
138  "Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
139  ) );
140 
141  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
142  "Regular expression <b>symbol name</b> filter."
143  ) );
144 
145  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
146  "Enable transaction logging. The mere presence of this option turns on the "
147  "logging, no need to set a Value."
148  ) );
149 
150  (*aListToAppendTo)["username"] = UTF8( _(
151  "User name for <b>login</b> to some special library server."
152  ) );
153 
154  (*aListToAppendTo)["password"] = UTF8( _(
155  "Password for <b>login</b> to some special library server."
156  ) );
157 #endif
158 
159 #if 1
160  // Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
161  // if and when implemented.
162  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
163  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
164  ) );
165 #endif
166 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
#define _(s)
Definition: 3d_actions.cpp:33

References _.

◆ translateEagleBusName()

wxString SCH_EAGLE_PLUGIN::translateEagleBusName ( const wxString &  aEagleName) const
private

Translate an Eagle-style bus name into one that is KiCad-compatible.

For vector buses such as A[7..0] this has no impact. For group buses, we translate from Eagle-style to KiCad-style.

Parameters
aEagleNameis the name of the bus from the Eagle schematic

Definition at line 2885 of file sch_eagle_plugin.cpp.

2886 {
2887  if( NET_SETTINGS::ParseBusVector( aEagleName, nullptr, nullptr ) )
2888  return aEagleName;
2889 
2890  wxString ret = "{";
2891 
2892  wxStringTokenizer tokenizer( aEagleName, "," );
2893 
2894  while( tokenizer.HasMoreTokens() )
2895  {
2896  wxString member = tokenizer.GetNextToken();
2897 
2898  // In Eagle, overbar text is automatically stopped at the end of the net name, even when
2899  // that net name is part of a bus definition. In KiCad, we don't (currently) do that, so
2900  // if there is an odd number of overbar markers in this net name, we need to append one
2901  // to close it out before appending the space.
2902 
2903  if( member.Freq( '!' ) % 2 > 0 )
2904  member << "!";
2905 
2906  ret << member << " ";
2907  }
2908 
2909  ret.Trim( true );
2910  ret << "}";
2911 
2912  return ret;
2913 }
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parses a bus vector (e.g.

References NET_SETTINGS::ParseBusVector().

Member Data Documentation

◆ m_connPoints

std::map<wxPoint, std::set<const EDA_ITEM*> > SCH_EAGLE_PLUGIN::m_connPoints
private

Definition at line 259 of file sch_eagle_plugin.h.

◆ m_currentSheet

SCH_SHEET* SCH_EAGLE_PLUGIN::m_currentSheet
private

The current sheet of the schematic being loaded.

Definition at line 223 of file sch_eagle_plugin.h.

◆ m_eagleLibs

std::map<wxString, EAGLE_LIBRARY> SCH_EAGLE_PLUGIN::m_eagleLibs
private

Definition at line 230 of file sch_eagle_plugin.h.

◆ m_filename

wxFileName SCH_EAGLE_PLUGIN::m_filename
private

Definition at line 225 of file sch_eagle_plugin.h.

◆ m_layerMap

std::map<int, SCH_LAYER_ID> SCH_EAGLE_PLUGIN::m_layerMap
private

Wire intersection points, used for quick checks whether placing a net label in a particular place would short two nets.

Definition at line 236 of file sch_eagle_plugin.h.

◆ m_libName

wxString SCH_EAGLE_PLUGIN::m_libName
private

Library name to save symbols.

Definition at line 226 of file sch_eagle_plugin.h.

◆ m_missingCmps

std::map<wxString, EAGLE_MISSING_CMP> SCH_EAGLE_PLUGIN::m_missingCmps
private

Definition at line 220 of file sch_eagle_plugin.h.

◆ m_netCounts

std::map<wxString, int> SCH_EAGLE_PLUGIN::m_netCounts
private

Definition at line 235 of file sch_eagle_plugin.h.

◆ m_nets

std::map<wxString, ENET> SCH_EAGLE_PLUGIN::m_nets
private

Positions of pins and wire endings mapped to its parent.

Definition at line 256 of file sch_eagle_plugin.h.

◆ m_partlist

EPART_MAP SCH_EAGLE_PLUGIN::m_partlist
private

Definition at line 229 of file sch_eagle_plugin.h.

◆ m_pi

SCH_PLUGIN::SCH_PLUGIN_RELEASER SCH_EAGLE_PLUGIN::m_pi
private

Plugin to create the KiCad symbol library.

Definition at line 232 of file sch_eagle_plugin.h.

◆ m_properties

std::unique_ptr< PROPERTIES > SCH_EAGLE_PLUGIN::m_properties
private

Library plugin properties.

Definition at line 233 of file sch_eagle_plugin.h.

◆ m_reporter

REPORTER* SCH_EAGLE_PLUGIN::m_reporter
private

Reporter for warnings/errors.

Map references to missing component units data

Definition at line 217 of file sch_eagle_plugin.h.

Referenced by SetReporter().

◆ m_rootSheet

SCH_SHEET* SCH_EAGLE_PLUGIN::m_rootSheet
private

The root sheet of the schematic being loaded.

Definition at line 222 of file sch_eagle_plugin.h.

◆ m_schematic

SCHEMATIC* SCH_EAGLE_PLUGIN::m_schematic
private

Passed to Load(), the schematic object being loaded.

Definition at line 227 of file sch_eagle_plugin.h.

◆ m_segments

std::vector<SEG_DESC> SCH_EAGLE_PLUGIN::m_segments
private

Nets as defined in the <nets> sections of an Eagle schematic file.

Definition at line 253 of file sch_eagle_plugin.h.

◆ m_version

wxString SCH_EAGLE_PLUGIN::m_version
private

Eagle file version.

Definition at line 224 of file sch_eagle_plugin.h.

◆ m_wireIntersections

std::vector<VECTOR2I> SCH_EAGLE_PLUGIN::m_wireIntersections
private

Wires and labels of a single connection (segment in Eagle nomenclature)

Definition at line 240 of file sch_eagle_plugin.h.


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