kicad/eeschema/sch_io/eagle/sch_io_eagle.h

287 lines
11 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 CERN
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Russell Oliver <roliver8143@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-12-24 00:31:24 +00:00
#ifndef SCH_IO_EAGLE_H_
#define SCH_IO_EAGLE_H_
2017-05-08 14:10:23 +00:00
#include <sch_line.h>
#include <sch_io/sch_io.h>
#include <sch_io/sch_io_mgr.h>
#include <io/eagle/eagle_parser.h>
#include <lib_item.h>
#include <geometry/seg.h>
#include <boost/ptr_container/ptr_map.hpp>
class EDA_TEXT;
class KIWAY;
class LINE_READER;
class SCH_SCREEN;
class SCH_SHEET;
class SCH_BITMAP;
class SCH_JUNCTION;
class SCH_NO_CONNECT;
class SCH_SHAPE;
class SCH_LINE;
class SCH_BUS_ENTRY_BASE;
class SCH_TEXT;
class SCH_GLOBALLABEL;
2021-06-10 14:10:55 +00:00
class SCH_SYMBOL;
class SCH_FIELD;
class STRING_UTF8_MAP;
2021-06-10 18:51:46 +00:00
class LIB_SYMBOL;
class SYMBOL_LIB;
class LIB_SHAPE;
class LIB_FIELD;
class LIB_RECTANGLE;
class LIB_POLYLINE;
class LIB_PIN;
class LIB_TEXT;
class wxXmlNode;
struct EAGLE_LIBRARY
2017-06-26 07:56:11 +00:00
{
wxString name;
2021-06-10 18:51:46 +00:00
boost::ptr_map<wxString, LIB_SYMBOL> KiCadSymbols;
std::unordered_map<wxString, wxXmlNode*> SymbolNodes;
std::unordered_map<wxString, int> GateUnit;
std::unordered_map<wxString, wxString> package;
};
typedef boost::ptr_map<wxString, EPART> EPART_LIST;
2017-06-26 07:56:11 +00:00
/**
* A #SCH_IO derivation for loading 6.x+ Eagle schematic files.
*
* As with all SCH_IO there is no UI dependencies i.e. windowing calls allowed.
*/
2023-12-24 00:31:24 +00:00
class SCH_IO_EAGLE : public SCH_IO
{
public:
const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
2023-12-24 00:31:24 +00:00
SCH_IO_EAGLE();
~SCH_IO_EAGLE();
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
{
return PLUGIN_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
}
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
{
return PLUGIN_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
}
bool CanReadSchematicFile( const wxString& aFileName ) const override;
bool CanReadLibrary( const wxString& aFileName ) const override;
int GetModifyHash() const override;
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
SCH_SHEET* aAppendToMe = nullptr,
const STRING_UTF8_MAP* aProperties = nullptr ) override;
void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
const STRING_UTF8_MAP* aProperties ) override;
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
const STRING_UTF8_MAP* aProperties ) override;
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
const STRING_UTF8_MAP* aProperties ) override;
2023-12-27 00:25:41 +00:00
bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
private:
void checkpoint();
bool checkHeader( const wxString& aFileName ) const;
wxXmlDocument loadXmlDocument( const wxString& aFileName );
long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
void ensureLoadedLibrary( const wxString& aLibraryPath );
2017-05-08 14:10:23 +00:00
void loadDrawing( wxXmlNode* aDrawingNode );
void loadLayerDefs( wxXmlNode* aLayers );
2017-05-08 14:10:23 +00:00
void loadSchematic( wxXmlNode* aSchematicNode );
void loadSheet( wxXmlNode* aSheetNode, int sheetcount );
2017-05-08 14:10:23 +00:00
void loadInstance( wxXmlNode* aInstanceNode );
EAGLE_LIBRARY* loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY* aEagleLib );
void countNets( wxXmlNode* aSchematicNode );
/// Move any labels on the wire to the new end point of the wire.
void moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint );
/// This function finds best way to place a bus entry symbol for when an Eagle wire segment
/// ends on an Eagle bus segment.
void addBusEntries();
/// Return the matching layer or return LAYER_NOTES
SCH_LAYER_ID kiCadLayer( int aEagleLayer );
std::pair<VECTOR2I, const SEG*> findNearestLinePoint( const VECTOR2I& aPoint,
const std::vector<SEG>& aLines ) const;
void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName,
const wxString& aNetClass );
SCH_SHAPE* loadPolyLine( wxXmlNode* aPolygonNode );
SCH_ITEM* loadWire( wxXmlNode* aWireNode, SEG& endpoints );
SCH_SHAPE* loadCircle( wxXmlNode* aCircleNode );
SCH_SHAPE* loadRectangle( wxXmlNode* aRectNode );
SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName );
SCH_JUNCTION* loadJunction( wxXmlNode* aJunction );
SCH_TEXT* loadPlainText( wxXmlNode* aSchText );
void loadFrame( wxXmlNode* aFrameNode, std::vector<SCH_ITEM*>& aItems );
bool loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBOL>& aSymbol,
EDEVICE* aDevice, int aGateNumber, const wxString& aGateName );
LIB_SHAPE* loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aCircleNode,
int aGateNumber );
LIB_SHAPE* loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aRectNode,
int aGateNumber );
LIB_SHAPE* loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
wxXmlNode* aPolygonNode, int aGateNumber );
LIB_ITEM* loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode* aWireNode,
int aGateNumber );
LIB_PIN* loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol, wxXmlNode*, EPIN* epin,
int aGateNumber );
LIB_TEXT* loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol, 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
void adjustNetLabels();
/**
* 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.
*
* @param aEagleName is the name of the bus from the Eagle schematic
*/
wxString translateEagleBusName( const wxString& aEagleName ) const;
wxString getLibName();
wxFileName getLibFileName();
///< Checks if there are other wires or pins at the position of the tested pin
2021-06-10 14:10:55 +00:00
bool checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const;
/**
* 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.
*
2021-06-10 14:10:55 +00:00
* @param aSymbol is the symbol to process.
* @param aScreen is the screen where net labels should be added.
* @param aUpdateSet decides whether the missing units data should be updated.
*/
2021-06-10 14:10:55 +00:00
void addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet );
bool netHasPowerDriver( SCH_LINE* aLine, const wxString& aNetName ) const;
SCH_SHEET* getCurrentSheet();
SCH_SCREEN* getCurrentScreen();
// Describe missing units containing pins creating implicit connections
// (named power pins in Eagle).
struct EAGLE_MISSING_CMP
{
2021-06-10 14:10:55 +00:00
EAGLE_MISSING_CMP( const SCH_SYMBOL* aSymbol = nullptr )
: cmp( aSymbol )
{
}
2021-06-10 14:10:55 +00:00
///< Link to the parent symbol
const SCH_SYMBOL* cmp;
2021-06-10 14:10:55 +00:00
/* Map of the symbol units: for each unit there is a flag saying
* whether the unit needs to be instantiated with appropriate net labels to
* emulate implicit connections as is done in Eagle.
*/
std::map<int, bool> units;
};
2021-06-10 14:10:55 +00:00
///< Map references to missing symbol units data
std::map<wxString, EAGLE_MISSING_CMP> m_missingCmps;
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded
SCH_SHEET_PATH m_sheetPath; ///< The current sheet path of the schematic being loaded.
wxString m_version; ///< Eagle file version.
wxFileName m_filename;
wxString m_libName; ///< Library name to save symbols
SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded
2017-06-26 07:56:11 +00:00
EPART_MAP m_partlist;
std::map<wxString, long long> m_timestamps;
std::map<wxString, EAGLE_LIBRARY> m_eagleLibs;
std::unordered_map<wxString, bool> m_userValue; ///< deviceset/@uservalue for device.
2017-06-26 07:56:11 +00:00
SCH_IO::SCH_IO_RELEASER m_pi; ///< PI to create KiCad symbol library.
std::unique_ptr<STRING_UTF8_MAP> m_properties; ///< Library plugin properties.
unsigned m_doneCount;
unsigned m_lastProgressCount;
unsigned m_totalCount; ///< for progress reporting
std::map<wxString, int> m_netCounts;
std::map<int, SCH_LAYER_ID> m_layerMap;
std::map<wxString, wxString> m_powerPorts; ///< map from symbol reference to global
///< label equivalent
///< Wire intersection points, used for quick checks whether placing a net label in a particular
///< place would short two nets.
std::vector<VECTOR2I> m_wireIntersections;
///< Wires and labels of a single connection (segment in Eagle nomenclature)
struct SEG_DESC
{
///< Test if a particular label is attached to any of the stored segments
const SEG* LabelAttached( const SCH_TEXT* aLabel ) const;
std::vector<SCH_TEXT*> labels;
std::vector<SEG> segs;
};
///< Segments representing wires for intersection checking
std::vector<SEG_DESC> m_segments;
///< Nets as defined in the <nets> sections of an Eagle schematic file.
std::map<wxString, ENET> m_nets;
///< Positions of pins and wire endings mapped to its parent
std::map<VECTOR2I, std::set<const EDA_ITEM*>> m_connPoints;
};
2023-12-24 00:31:24 +00:00
#endif // SCH_IO_EAGLE_H_