KiCad PCB EDA Suite
SCH_EAGLE_PLUGIN Class Reference

Class SCH_EAGLE_PLUGIN is 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
 

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

More...
 

Public Member Functions

 SCH_EAGLE_PLUGIN ()
 
 ~SCH_EAGLE_PLUGIN ()
 
const wxString GetName () const override
 Returns a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the SCH_PLUGIN. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL) 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=NULL)
 
virtual void Save (const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
 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 size_t GetSymbolLibCount (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 
virtual void EnumerateSymbolLib (wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
virtual void EnumerateSymbolLib (std::vector< LIB_ALIAS * > &aAliasList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
virtual LIB_ALIASLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
 Load a LIB_ALIAS object having aAliasName 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=NULL)
 Write aSymbol to an existing library located at aLibraryPath. More...
 
virtual void DeleteAlias (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
 Delete aAliasName from the library at aLibraryPath. More...
 
virtual void DeleteSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
virtual void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Create a new empty symbol library at aLibraryPath. More...
 
virtual bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 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 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)
 Moves 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)
 
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 loadTextAttributes (EDA_TEXT *aText, const ETEXT &aAttribs) const
 
void loadFieldAttributes (LIB_FIELD *aField, const LIB_TEXT *aText) const
 
void adjustNetLabels ()
 

Moves net labels that are detached from any wire to the nearest wire

More...
 
wxString getLibName ()
 
wxFileName getLibFileName ()
 
bool checkConnections (const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
 

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

More...
 
void addImplicitConnections (SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
 Creates net labels to emulate implicit connections in Eagle. More...
 

Static Private Member Functions

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

Private Attributes

KIWAYm_kiway
 For creating sub sheets. More...
 
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...
 
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
 
std::vector< VECTOR2Im_wireIntersections
 

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

More...
 
std::vector< SEG_DESCm_segments
 

Segments representing wires for intersection checking

More...
 
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
 

Positions of pins and wire endings mapped to its parent

More...
 
std::map< wxString, EAGLE_MISSING_CMPm_missingCmps
 

Map references to missing component units data

More...
 

Detailed Description

Class SCH_EAGLE_PLUGIN is 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 82 of file sch_eagle_plugin.h.

Constructor & Destructor Documentation

SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN ( )

Definition at line 341 of file sch_eagle_plugin.cpp.

342 {
343  m_kiway = nullptr;
344  m_rootSheet = nullptr;
345  m_currentSheet = nullptr;
346 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
KIWAY * m_kiway
For creating sub sheets.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN ( )

Definition at line 349 of file sch_eagle_plugin.cpp.

350 {
351 }

Member Function Documentation

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 1947 of file sch_eagle_plugin.cpp.

References IS_NEW, LAYER_BUS, LAYER_WIRE, SCH_ITEM::Next(), SCH_LINE_T, EDA_ITEM::SetFlags(), TestSegmentHit(), wxPoint::x, and wxPoint::y.

1948 {
1949  // Add bus entry symbols
1950 
1951  // for each wire segment, compare each end with all busess.
1952  // If the wire end is found to end on a bus segment, place a bus entry symbol.
1953 
1954  for( SCH_ITEM* bus = m_currentSheet->GetScreen()->GetDrawItems(); bus; bus = bus->Next() )
1955  {
1956  // Check line type for line
1957  if( bus->Type() != SCH_LINE_T )
1958  continue;
1959 
1960  // Check line type for wire
1961  if( ( (SCH_LINE*) bus )->GetLayer() != LAYER_BUS )
1962  continue;
1963 
1964 
1965  wxPoint busstart = ( (SCH_LINE*) bus )->GetStartPoint();
1966  wxPoint busend = ( (SCH_LINE*) bus )->GetEndPoint();
1967 
1968  SCH_ITEM* nextline;
1969 
1970  for( SCH_ITEM* line = m_currentSheet->GetScreen()->GetDrawItems(); line; line = nextline )
1971  {
1972  nextline = line->Next();
1973 
1974  // Check line type for line
1975  if( line->Type() == SCH_LINE_T )
1976  {
1977  // Check line type for bus
1978  if( ( (SCH_LINE*) line )->GetLayer() == LAYER_WIRE )
1979  {
1980  // Get points of both segments.
1981 
1982  wxPoint linestart = ( (SCH_LINE*) line )->GetStartPoint();
1983  wxPoint lineend = ( (SCH_LINE*) line )->GetEndPoint();
1984 
1985 
1986  // Test for horizontal wire and vertical bus
1987  if( linestart.y == lineend.y && busstart.x == busend.x )
1988  {
1989  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
1990  {
1991  // Wire start is on a bus.
1992  // Wire start is on the vertical bus
1993 
1994  // if the end of the wire is to the left of the bus
1995  if( lineend.x < busstart.x )
1996  {
1997  // |
1998  // ---|
1999  // |
2000  if( TestSegmentHit( linestart + wxPoint( 0, -100 ), busstart,
2001  busend, 0 ) )
2002  {
2003  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2004  -100,
2005  0 ),
2006  '/' );
2007  busEntry->SetFlags( IS_NEW );
2008  m_currentSheet->GetScreen()->Append( busEntry );
2009  moveLabels( line, linestart + wxPoint( -100, 0 ) );
2010  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2011  wxPoint( -100, 0 ) );
2012  }
2013  else if( TestSegmentHit( linestart + wxPoint( 0, 100 ), busstart,
2014  busend, 0 ) )
2015  {
2016  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2017  -100,
2018  0 ),
2019  '\\' );
2020  busEntry->SetFlags( IS_NEW );
2021  m_currentSheet->GetScreen()->Append( busEntry );
2022  moveLabels( line, linestart + wxPoint( -100, 0 ) );
2023  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2024  wxPoint( -100, 0 ) );
2025  }
2026  else
2027  {
2028  SCH_MARKER* marker = new SCH_MARKER( linestart,
2029  "Bus Entry needed" );
2030 
2031  m_currentSheet->GetScreen()->Append( marker );
2032  }
2033  }
2034  // else the wire end is to the right of the bus
2035  // Wire is to the right of the bus
2036  // |
2037  // |----
2038  // |
2039  else
2040  {
2041  // test is bus exists above the wire
2042  if( TestSegmentHit( linestart + wxPoint( 0, -100 ), busstart,
2043  busend, 0 ) )
2044  {
2045  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2046  0,
2047  -100 ),
2048  '\\' );
2049  busEntry->SetFlags( IS_NEW );
2050  m_currentSheet->GetScreen()->Append( busEntry );
2051  moveLabels( line, linestart + wxPoint( 100, 0 ) );
2052  ( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 100,
2053  0 ) );
2054  }
2055  // test is bus exists below the wire
2056  else if( TestSegmentHit( linestart + wxPoint( 0, 100 ), busstart,
2057  busend, 0 ) )
2058  {
2059  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2060  0,
2061  100 ),
2062  '/' );
2063  busEntry->SetFlags( IS_NEW );
2064  m_currentSheet->GetScreen()->Append( busEntry );
2065  moveLabels( line, linestart + wxPoint( 100, 0 ) );
2066  ( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 100,
2067  0 ) );
2068  }
2069  else
2070  {
2071  SCH_MARKER* marker = new SCH_MARKER( linestart,
2072  "Bus Entry needed" );
2073 
2074  m_currentSheet->GetScreen()->Append( marker );
2075  }
2076  }
2077  }
2078 
2079  // Same thing but test end of the wire instead.
2080  if( TestSegmentHit( lineend, busstart, busend, 0 ) )
2081  {
2082  // Wire end is on the vertical bus
2083 
2084  // if the start of the wire is to the left of the bus
2085  if( linestart.x < busstart.x )
2086  {
2087  // Test if bus exists above the wire
2088  if( TestSegmentHit( lineend + wxPoint( 0, 100 ), busstart, busend,
2089  0 ) )
2090  {
2091  // |
2092  // ___/|
2093  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2094  -100,
2095  0 ),
2096  '\\' );
2097  busEntry->SetFlags( IS_NEW );
2098  m_currentSheet->GetScreen()->Append( busEntry );
2099  moveLabels( line, lineend + wxPoint( -100, 0 ) );
2100  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2101  wxPoint( -100, 0 ) );
2102  }
2103  // Test if bus exists below the wire
2104  else if( TestSegmentHit( lineend + wxPoint( 0, -100 ), busstart,
2105  busend, 0 ) )
2106  {
2107  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2108  -100,
2109  0 ),
2110  '/' );
2111  busEntry->SetFlags( IS_NEW );
2112  m_currentSheet->GetScreen()->Append( busEntry );
2113  moveLabels( line, lineend + wxPoint( -100, 0 ) );
2114  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2115  wxPoint( -100, 0 ) );
2116  }
2117  else
2118  {
2119  SCH_MARKER* marker = new SCH_MARKER( lineend,
2120  "Bus Entry needed" );
2121 
2122  m_currentSheet->GetScreen()->Append( marker );
2123  }
2124  }
2125  // else the start of the wire is to the right of the bus
2126  // |
2127  // |----
2128  // |
2129  else
2130  {
2131  // test if bus existed above the wire
2132  if( TestSegmentHit( lineend + wxPoint( 0, -100 ), busstart,
2133  busend, 0 ) )
2134  {
2135  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2136  0,
2137  -100 ),
2138  '\\' );
2139  busEntry->SetFlags( IS_NEW );
2140  m_currentSheet->GetScreen()->Append( busEntry );
2141  moveLabels( line, lineend + wxPoint( 100, 0 ) );
2142  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2143  wxPoint( 100, 0 ) );
2144  }
2145  // test if bus existed below the wire
2146  else if( TestSegmentHit( lineend + wxPoint( 0, 100 ), busstart,
2147  busend, 0 ) )
2148  {
2149  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2150  0,
2151  100 ),
2152  '/' );
2153  busEntry->SetFlags( IS_NEW );
2154  m_currentSheet->GetScreen()->Append( busEntry );
2155  moveLabels( line, lineend + wxPoint( 100, 0 ) );
2156  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2157  wxPoint( 100, 0 ) );
2158  }
2159  else
2160  {
2161  SCH_MARKER* marker = new SCH_MARKER( lineend,
2162  "Bus Entry needed" );
2163 
2164  m_currentSheet->GetScreen()->Append( marker );
2165  }
2166  }
2167  }
2168  } // if( linestart.y == lineend.y && busstart.x == busend.x)
2169 
2170  // Test for horizontal wire and vertical bus
2171  if( linestart.x == lineend.x && busstart.y == busend.y )
2172  {
2173  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
2174  {
2175  // Wire start is on the bus
2176  // If wire end is above the bus,
2177  if( lineend.y < busstart.y )
2178  {
2179  // Test for bus existance to the left of the wire
2180  if( TestSegmentHit( linestart + wxPoint( -100, 0 ), busstart,
2181  busend, 0 ) )
2182  {
2183  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2184  -100,
2185  0 ),
2186  '/' );
2187  busEntry->SetFlags( IS_NEW );
2188  m_currentSheet->GetScreen()->Append( busEntry );
2189  moveLabels( line, linestart + wxPoint( 0, -100 ) );
2190  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2191  wxPoint( 0, -100 ) );
2192  }
2193  else if( TestSegmentHit( linestart + wxPoint( 100, 0 ), busstart,
2194  busend, 0 ) )
2195  {
2196  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2197  0,
2198  100 ),
2199  '\\' );
2200  busEntry->SetFlags( IS_NEW );
2201  m_currentSheet->GetScreen()->Append( busEntry );
2202  moveLabels( line, linestart + wxPoint( 0, -100 ) );
2203  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2204  wxPoint( 0, -100 ) );
2205  }
2206  else
2207  {
2208  SCH_MARKER* marker = new SCH_MARKER( linestart,
2209  "Bus Entry needed" );
2210 
2211  m_currentSheet->GetScreen()->Append( marker );
2212  }
2213  }
2214  else // wire end is below the bus.
2215  {
2216  // Test for bus existance to the left of the wire
2217  if( TestSegmentHit( linestart + wxPoint( -100, 0 ), busstart,
2218  busend, 0 ) )
2219  {
2220  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2221  -100,
2222  0 ),
2223  '\\' );
2224  busEntry->SetFlags( IS_NEW );
2225  m_currentSheet->GetScreen()->Append( busEntry );
2226  moveLabels( line, linestart + wxPoint( 0, 100 ) );
2227  ( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 0,
2228  100 ) );
2229  }
2230  else if( TestSegmentHit( linestart + wxPoint( 100, 0 ), busstart,
2231  busend, 0 ) )
2232  {
2233  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart + wxPoint(
2234  100,
2235  0 ),
2236  '/' );
2237  busEntry->SetFlags( IS_NEW );
2238  m_currentSheet->GetScreen()->Append( busEntry );
2239  moveLabels( line, linestart + wxPoint( 0, 100 ) );
2240  ( (SCH_LINE*) line )->SetStartPoint( linestart + wxPoint( 0,
2241  100 ) );
2242  }
2243  else
2244  {
2245  SCH_MARKER* marker = new SCH_MARKER( linestart,
2246  "Bus Entry needed" );
2247 
2248  m_currentSheet->GetScreen()->Append( marker );
2249  }
2250  }
2251  }
2252 
2253  if( TestSegmentHit( lineend, busstart, busend, 0 ) )
2254  {
2255  // Wire end is on the bus
2256  // If wire start is above the bus,
2257 
2258  if( linestart.y < busstart.y )
2259  {
2260  // Test for bus existance to the left of the wire
2261  if( TestSegmentHit( lineend + wxPoint( -100, 0 ), busstart,
2262  busend, 0 ) )
2263  {
2264  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2265  -100,
2266  0 ),
2267  '/' );
2268  busEntry->SetFlags( IS_NEW );
2269  m_currentSheet->GetScreen()->Append( busEntry );
2270  moveLabels( line, lineend + wxPoint( 0, -100 ) );
2271  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2272  wxPoint( 0, -100 ) );
2273  }
2274  else if( TestSegmentHit( lineend + wxPoint( 100, 0 ), busstart,
2275  busend, 0 ) )
2276  {
2277  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2278  0,
2279  -100 ),
2280  '\\' );
2281  busEntry->SetFlags( IS_NEW );
2282  m_currentSheet->GetScreen()->Append( busEntry );
2283  moveLabels( line, lineend + wxPoint( 0, -100 ) );
2284  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2285  wxPoint( 0, -100 ) );
2286  }
2287  else
2288  {
2289  SCH_MARKER* marker = new SCH_MARKER( lineend,
2290  "Bus Entry needed" );
2291 
2292  m_currentSheet->GetScreen()->Append( marker );
2293  }
2294  }
2295  else // wire end is below the bus.
2296  {
2297  // Test for bus existance to the left of the wire
2298  if( TestSegmentHit( lineend + wxPoint( -100, 0 ), busstart,
2299  busend, 0 ) )
2300  {
2301  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2302  -100,
2303  0 ),
2304  '\\' );
2305  busEntry->SetFlags( IS_NEW );
2306  m_currentSheet->GetScreen()->Append( busEntry );
2307  moveLabels( line, lineend + wxPoint( 0, 100 ) );
2308  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2309  wxPoint( 0, 100 ) );
2310  }
2311  else if( TestSegmentHit( lineend + wxPoint( 100, 0 ), busstart,
2312  busend, 0 ) )
2313  {
2314  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( lineend + wxPoint(
2315  0,
2316  100 ),
2317  '/' );
2318  busEntry->SetFlags( IS_NEW );
2319  m_currentSheet->GetScreen()->Append( busEntry );
2320  moveLabels( line, lineend + wxPoint( 0, 100 ) );
2321  ( (SCH_LINE*) line )->SetEndPoint( lineend +
2322  wxPoint( 0, 100 ) );
2323  }
2324  else
2325  {
2326  SCH_MARKER* marker = new SCH_MARKER( lineend,
2327  "Bus Entry needed" );
2328 
2329  m_currentSheet->GetScreen()->Append( marker );
2330  }
2331  }
2332  }
2333  }
2334 
2335  linestart = ( (SCH_LINE*) line )->GetStartPoint();
2336  lineend = ( (SCH_LINE*) line )->GetEndPoint();
2337  busstart = ( (SCH_LINE*) bus )->GetStartPoint();
2338  busend = ( (SCH_LINE*) bus )->GetEndPoint();
2339 
2340 
2341  // bus entry wire isn't horizontal or vertical
2342  if( TestSegmentHit( linestart, busstart, busend, 0 ) )
2343  {
2344  wxPoint wirevector = linestart - lineend;
2345 
2346  if( wirevector.x > 0 )
2347  {
2348  if( wirevector.y > 0 )
2349  {
2350  wxPoint p = linestart + wxPoint( -100, -100 );
2351  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, '\\' );
2352  busEntry->SetFlags( IS_NEW );
2353  m_currentSheet->GetScreen()->Append( busEntry );
2354  moveLabels( line, p );
2355 
2356  if( p == lineend ) // wire is overlapped by bus entry symbol
2357  {
2358  m_currentSheet->GetScreen()->DeleteItem( line );
2359  line = nullptr;
2360  }
2361  else
2362  {
2363  ( (SCH_LINE*) line )->SetStartPoint( p );
2364  }
2365  }
2366  else
2367  {
2368  wxPoint p = linestart + wxPoint( -100, 100 );
2369  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, '/' );
2370  busEntry->SetFlags( IS_NEW );
2371  m_currentSheet->GetScreen()->Append( busEntry );
2372 
2373  moveLabels( line, p );
2374 
2375  if( p == lineend ) // wire is overlapped by bus entry symbol
2376  {
2377  m_currentSheet->GetScreen()->DeleteItem( line );
2378  line = nullptr;
2379  }
2380  else
2381  {
2382  ( (SCH_LINE*) line )->SetStartPoint( p );
2383  }
2384  }
2385  }
2386  else
2387  {
2388  if( wirevector.y > 0 )
2389  {
2390  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart,
2391  '/' );
2392  busEntry->SetFlags( IS_NEW );
2393  m_currentSheet->GetScreen()->Append( busEntry );
2394 
2395  moveLabels( line, linestart + wxPoint( 100, -100 ) );
2396 
2397  if( linestart + wxPoint( 100, -100 )== lineend ) // wire is overlapped by bus entry symbol
2398  {
2399  m_currentSheet->GetScreen()->DeleteItem( line );
2400  line = nullptr;
2401  }
2402  else
2403  {
2404  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2405  wxPoint( 100, -100 ) );
2406  }
2407  }
2408  else
2409  {
2410  SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( linestart,
2411  '\\' );
2412  busEntry->SetFlags( IS_NEW );
2413  m_currentSheet->GetScreen()->Append( busEntry );
2414  moveLabels( line, linestart + wxPoint( 100, 100 ) );
2415 
2416  if( linestart + wxPoint( 100, 100 )== lineend ) // wire is overlapped by bus entry symbol
2417  {
2418  m_currentSheet->GetScreen()->DeleteItem( line );
2419  line = nullptr;
2420  }
2421  else
2422  {
2423  ( (SCH_LINE*) line )->SetStartPoint( linestart +
2424  wxPoint( 100, 100 ) );
2425  }
2426  }
2427  }
2428  }
2429 
2430  if( line && TestSegmentHit( lineend, busstart, busend, 0 ) )
2431  {
2432  wxPoint wirevector = linestart - lineend;
2433 
2434  if( wirevector.x > 0 )
2435  {
2436  if( wirevector.y > 0 )
2437  {
2438  wxPoint p = lineend + wxPoint( 100, 100 );
2439  SCH_BUS_WIRE_ENTRY* busEntry =
2440  new SCH_BUS_WIRE_ENTRY( lineend, '\\' );
2441  busEntry->SetFlags( IS_NEW );
2442  m_currentSheet->GetScreen()->Append( busEntry );
2443 
2444  moveLabels( line, p );
2445 
2446  if( p == linestart ) // wire is overlapped by bus entry symbol
2447  {
2448  m_currentSheet->GetScreen()->DeleteItem( line );
2449  }
2450  else
2451  {
2452  ( (SCH_LINE*) line )->SetEndPoint( p );
2453  }
2454  }
2455  else
2456  {
2457  wxPoint p = lineend + wxPoint( 100, -100 );
2458  SCH_BUS_WIRE_ENTRY* busEntry =
2459  new SCH_BUS_WIRE_ENTRY( lineend, '/' );
2460  busEntry->SetFlags( IS_NEW );
2461  m_currentSheet->GetScreen()->Append( busEntry );
2462 
2463  moveLabels( line, p );
2464 
2465  if( p== linestart ) // wire is overlapped by bus entry symbol
2466  {
2467  m_currentSheet->GetScreen()->DeleteItem( line );
2468  }
2469  else
2470  {
2471  ( (SCH_LINE*) line )->SetEndPoint( p );
2472  }
2473  }
2474  }
2475  else
2476  {
2477  if( wirevector.y > 0 )
2478  {
2479  wxPoint p = lineend + wxPoint( -100, 100 );
2480  SCH_BUS_WIRE_ENTRY* busEntry =
2481  new SCH_BUS_WIRE_ENTRY( p, '/' );
2482  busEntry->SetFlags( IS_NEW );
2483  m_currentSheet->GetScreen()->Append( busEntry );
2484  moveLabels( line, p );
2485 
2486  if( p == linestart ) // wire is overlapped by bus entry symbol
2487  {
2488  m_currentSheet->GetScreen()->DeleteItem( line );
2489  }
2490  else
2491  {
2492  ( (SCH_LINE*) line )->SetEndPoint( p );
2493  }
2494  }
2495  else
2496  {
2497  wxPoint p = lineend + wxPoint( -100, -100 );
2498  SCH_BUS_WIRE_ENTRY* busEntry =
2499  new SCH_BUS_WIRE_ENTRY( p, '\\' );
2500  busEntry->SetFlags( IS_NEW );
2501  m_currentSheet->GetScreen()->Append( busEntry );
2502  moveLabels( line, p );
2503 
2504  if( p == linestart ) // wire is overlapped by bus entry symbol
2505  {
2506  m_currentSheet->GetScreen()->DeleteItem( line );
2507  }
2508  else
2509  {
2510  ( (SCH_LINE*) line )->SetEndPoint( p );
2511  }
2512  }
2513  }
2514  }
2515  }
2516  }
2517  } // for ( line ..
2518  } // for ( bus ..
2519 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
SCH_ITEM * Next() const
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:182
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
void moveLabels(SCH_ITEM *aWire, const wxPoint &aNewEndPoint)
Moves any labels on the wire to the new end point of the wire.
Class for a wire to bus entry.
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void SCH_EAGLE_PLUGIN::addImplicitConnections ( SCH_COMPONENT aComponent,
SCH_SCREEN aScreen,
bool  aUpdateSet 
)
private

Creates 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 2551 of file sch_eagle_plugin.cpp.

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(), i, PIN_POWER_IN, REFERENCE, SCH_GLOBALLABEL::SetLabelSpinStyle(), SCH_TEXT::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), SCH_EAGLE_PLUGIN::EAGLE_MISSING_CMP::units, and SCH_COMPONENT::UpdatePinCache().

2553 {
2554  aComponent->UpdatePinCache();
2555  auto partRef = aComponent->GetPartRef().lock();
2556  wxCHECK( partRef, /*void*/ );
2557 
2558  // Normally power parts also have power input pins,
2559  // but they already force net names on the attached wires
2560  if( partRef->IsPower() )
2561  return;
2562 
2563  int unit = aComponent->GetUnit();
2564  const wxString& reference = aComponent->GetField( REFERENCE )->GetText();
2565  std::vector<LIB_PIN*> pins;
2566  partRef->GetPins( pins );
2567  std::set<int> missingUnits;
2568 
2569  // Search all units for pins creating implicit connections
2570  for( const auto& pin : pins )
2571  {
2572  if( pin->GetType() == PIN_POWER_IN )
2573  {
2574  bool pinInUnit = !unit || pin->GetUnit() == unit; // pin belongs to the tested unit
2575 
2576  // Create a global net label only if there are no other wires/pins attached
2577  if( pinInUnit && !checkConnections( aComponent, pin ) )
2578  {
2579  // Create a net label to force the net name on the pin
2580  SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
2581  netLabel->SetPosition( aComponent->GetPinPhysicalPosition( pin ) );
2582  netLabel->SetText( extractNetName( pin->GetName() ) );
2583  netLabel->SetTextSize( wxSize( 10, 10 ) );
2584  netLabel->SetLabelSpinStyle( 0 );
2585  aScreen->Append( netLabel );
2586  }
2587 
2588  else if( !pinInUnit && aUpdateSet )
2589  {
2590  // Found a pin creating implicit connection information in another unit.
2591  // Such units will be instantiated if they do not appear in another sheet and
2592  // processed later.
2593  wxASSERT( pin->GetUnit() );
2594  missingUnits.insert( pin->GetUnit() );
2595  }
2596  }
2597  }
2598 
2599  if( aUpdateSet )
2600  {
2601  auto cmpIt = m_missingCmps.find( reference );
2602 
2603  // Set the flag indicating this unit has been processed
2604  if( cmpIt != m_missingCmps.end() )
2605  cmpIt->second.units[unit] = false;
2606 
2607  // Save the units that need later processing
2608  else if( !missingUnits.empty() )
2609  {
2610  EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
2611  entry.cmp = aComponent;
2612 
2613  for( int i : missingUnits )
2614  entry.units.emplace( i, true );
2615  }
2616  }
2617 }
PART_REF & GetPartRef()
virtual void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_text.h:196
bool checkConnections(const SCH_COMPONENT *aComponent, const LIB_PIN *aPin) const
Checks if there are other wires or pins at the position of the tested pin
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
Map references to missing component units data
Field Reference of part, i.e. "IC21".
void UpdatePinCache()
Updates the local cache of pin positions.
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
int GetUnit() const
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
size_t i
Definition: json11.cpp:597
static wxString extractNetName(const wxString &aPinName)
Extracts the net name part from a pin name (e.g. return &#39;GND&#39; for pin named &#39;GND@2&#39;) ...
void SetLabelSpinStyle(int aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:756
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
wxPoint GetPinPhysicalPosition(const LIB_PIN *Pin) const
void SCH_EAGLE_PLUGIN::adjustNetLabels ( )
private

Moves net labels that are detached from any wire to the nearest wire

Definition at line 1839 of file sch_eagle_plugin.cpp.

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

1840 {
1841  // Eagle supports detached labels, so a label does not need to be placed on a wire
1842  // to be associated with it. KiCad needs to move them, so the labels actually touch the
1843  // corresponding wires.
1844 
1845  // Sort the intersection points to speed up the search process
1846  std::sort( m_wireIntersections.begin(), m_wireIntersections.end() );
1847 
1848  auto onIntersection = [&]( const VECTOR2I& aPos )
1849  {
1850  return std::binary_search( m_wireIntersections.begin(), m_wireIntersections.end(), aPos );
1851  };
1852 
1853  for( auto& segDesc : m_segments )
1854  {
1855  for( SCH_TEXT* label : segDesc.labels )
1856  {
1857  VECTOR2I labelPos( label->GetPosition() );
1858  const SEG* segAttached = segDesc.LabelAttached( label );
1859 
1860  if( segAttached && !onIntersection( labelPos ) )
1861  continue; // label is placed correctly
1862 
1863 
1864  // Move the label to the nearest wire
1865  if( !segAttached )
1866  {
1867  std::tie( labelPos, segAttached ) = findNearestLinePoint( label->GetPosition(), segDesc.segs );
1868 
1869  if( !segAttached ) // we cannot do anything
1870  continue;
1871  }
1872 
1873 
1874  // Create a vector pointing in the direction of the wire, 50 mils long
1875  VECTOR2I wireDirection( segAttached->B - segAttached->A );
1876  wireDirection = wireDirection.Resize( 50 );
1877  const VECTOR2I origPos( labelPos );
1878 
1879  // Flags determining the search direction
1880  bool checkPositive = true, checkNegative = true, move = false;
1881  int trial = 0;
1882 
1883  // Be sure the label is not placed on a wire intersection
1884  while( ( !move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
1885  {
1886  move = false;
1887 
1888  // Move along the attached wire to find the new label position
1889  if( trial % 2 == 1 )
1890  {
1891  labelPos = wxPoint( origPos + wireDirection * trial / 2 );
1892  move = checkPositive = segAttached->Contains( labelPos );
1893  }
1894  else
1895  {
1896  labelPos = wxPoint( origPos - wireDirection * trial / 2 );
1897  move = checkNegative = segAttached->Contains( labelPos );
1898  }
1899 
1900  ++trial;
1901  }
1902 
1903  if( move )
1904  label->SetPosition( wxPoint( labelPos ) );
1905  }
1906  }
1907 
1908  m_segments.clear();
1909  m_wireIntersections.clear();
1910 }
virtual void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_text.h:196
std::vector< VECTOR2I > m_wireIntersections
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...
virtual wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:194
Definition: seg.h:36
std::vector< SEG_DESC > m_segments
Segments representing wires for intersection checking
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const wxPoint &aPoint, const std::vector< SEG > &aLines) const
bool SCH_EAGLE_PLUGIN::checkConnections ( const SCH_COMPONENT aComponent,
const LIB_PIN aPin 
) const
private

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

Definition at line 2537 of file sch_eagle_plugin.cpp.

References SCH_COMPONENT::GetPinPhysicalPosition().

2538 {
2539  wxPoint pinPosition = aComponent->GetPinPhysicalPosition( aPin );
2540  auto pointIt = m_connPoints.find( pinPosition );
2541 
2542  if( pointIt == m_connPoints.end() )
2543  return false;
2544 
2545  const auto& items = pointIt->second;
2546  wxASSERT( items.find( aPin ) != items.end() );
2547  return items.size() > 1;
2548 }
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent
wxPoint GetPinPhysicalPosition(const LIB_PIN *Pin) const
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 1913 of file sch_eagle_plugin.cpp.

1914 {
1915  // Open file and check first line
1916  wxTextFile tempFile;
1917 
1918  tempFile.Open( aFileName );
1919  wxString firstline;
1920  // read the first line
1921  firstline = tempFile.GetFirstLine();
1922  wxString secondline = tempFile.GetNextLine();
1923  wxString thirdline = tempFile.GetNextLine();
1924  tempFile.Close();
1925 
1926  return firstline.StartsWith( "<?xml" ) && secondline.StartsWith( "<!DOCTYPE eagle SYSTEM" )
1927  && thirdline.StartsWith( "<eagle version" );
1928 }
void SCH_EAGLE_PLUGIN::countNets ( wxXmlNode *  aSchematicNode)
private

Definition at line 489 of file sch_eagle_plugin.cpp.

References getChildrenNodes(), and MapChildren().

490 {
491  // Map all children into a readable dictionary
492  NODE_MAP schematicChildren = MapChildren( aSchematicNode );
493  // Loop through all the sheets
494 
495  wxXmlNode* sheetNode = getChildrenNodes( schematicChildren, "sheets" );
496 
497  while( sheetNode )
498  {
499  NODE_MAP sheetChildren = MapChildren( sheetNode );
500  // Loop through all nets
501  // From the DTD: "Net is an electrical connection in a schematic."
502  wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
503 
504  while( netNode )
505  {
506  wxString netName = netNode->GetAttribute( "name" );
507 
508  if( m_netCounts.count( netName ) )
509  m_netCounts[netName] = m_netCounts[netName] + 1;
510  else
511  m_netCounts[netName] = 1;
512 
513  // Get next net
514  netNode = netNode->GetNext();
515  }
516 
517  sheetNode = sheetNode->GetNext();
518  }
519 }
std::map< wxString, int > m_netCounts
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:58
void SCH_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
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.

Definition at line 126 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::CreateSymbolLib(), LIB_EDIT_FRAME::OnExportPart(), and LIB_EDIT_FRAME::SaveOneSymbol().

127 {
128  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
129  not_implemented( this, __FUNCTION__ );
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:36
void SCH_PLUGIN::DeleteAlias ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Delete aAliasName from the library at aLibraryPath.

If aAliasName refers the the root LIB_PART object, the part is renamed to the next or previous LIB_ALIAS in the LIB_PART if one exists. If the LIB_ALIAS is the last alias referring to the root LIB_PART, the LIB_PART is also removed from the library.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aAliasNameis the name of a LIB_ALIAS 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.

Definition at line 110 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::DeleteAlias().

112 {
113  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
114  not_implemented( this, __FUNCTION__ );
115 }
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:36
void SCH_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
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.
aAliasNameis the name of a LIB_ALIAS 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.

Definition at line 118 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::DeleteSymbol().

120 {
121  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
122  not_implemented( this, __FUNCTION__ );
123 }
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:36
bool SCH_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
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.

Definition at line 133 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::DeleteSymbolLib().

134 {
135  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
136  not_implemented( this, __FUNCTION__ );
137  return false;
138 }
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:36
void SCH_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aAliasNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

Parameters
aAliasNameListis an array to populate with the LIB_ALIAS 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.

Definition at line 75 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::EnumerateSymbolLib(), LIB_EDIT_FRAME::LoadOneSymbol(), SYMBOL_LIB_TABLE::LoadSymbolLib(), and LIB_EDIT_FRAME::OnImportPart().

78 {
79  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
80  not_implemented( this, __FUNCTION__ );
81 }
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:36
void SCH_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_ALIAS * > &  aAliasList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

Parameters
aAliasListis an array to populate with the LIB_ALIAS 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.

Definition at line 84 of file sch_plugin.cpp.

References not_implemented().

87 {
88  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
89  not_implemented( this, __FUNCTION__ );
90 }
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:36
std::pair< VECTOR2I, const SEG * > SCH_EAGLE_PLUGIN::findNearestLinePoint ( const wxPoint aPoint,
const std::vector< SEG > &  aLines 
) const
private

Definition at line 1007 of file sch_eagle_plugin.cpp.

References abs, SEG::B, SEG::Center(), max, wxPoint::x, and wxPoint::y.

1009 {
1010  VECTOR2I nearestPoint;
1011  const SEG* nearestLine = nullptr;
1012 
1013  float d, mindistance = std::numeric_limits<float>::max();
1014 
1015  // Find the nearest start, middle or end of a line from the list of lines.
1016  for( const SEG& line : aLines )
1017  {
1018  auto testpoint = line.A;
1019  d = sqrt( abs( ( (aPoint.x - testpoint.x) ^ 2 ) + ( (aPoint.y - testpoint.y) ^ 2 ) ) );
1020 
1021  if( d < mindistance )
1022  {
1023  mindistance = d;
1024  nearestPoint = testpoint;
1025  nearestLine = &line;
1026  }
1027 
1028  testpoint = line.Center();
1029  d = sqrt( abs( ( (aPoint.x - testpoint.x) ^ 2 ) + ( (aPoint.y - testpoint.y) ^ 2 ) ) );
1030 
1031  if( d < mindistance )
1032  {
1033  mindistance = d;
1034  nearestPoint = testpoint;
1035  nearestLine = &line;
1036  }
1037 
1038  testpoint = line.B;
1039  d = sqrt( abs( ( (aPoint.x - testpoint.x) ^ 2 ) + ( (aPoint.y - testpoint.y) ^ 2 ) ) );
1040 
1041  if( d < mindistance )
1042  {
1043  mindistance = d;
1044  nearestPoint = testpoint;
1045  nearestLine = &line;
1046  }
1047  }
1048 
1049  return std::make_pair( nearestPoint, nearestLine );
1050 }
#define abs(a)
Definition: auxiliary.h:84
VECTOR2I Center() const
Returns the center point of the line
Definition: seg.h:325
Definition: seg.h:36
#define max(a, b)
Definition: auxiliary.h:86
VECTOR2I B
Definition: seg.h:47
wxString SCH_EAGLE_PLUGIN::fixSymbolName ( const wxString &  aName)
staticprivate

Fixes 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 2620 of file sch_eagle_plugin.cpp.

References LIB_ID::FixIllegalChars(), and LIB_ID::ID_SCH.

2621 {
2622  wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
2623 
2624  return ret;
2625 }
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
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.

Definition at line 193 of file sch_plugin.cpp.

References not_implemented().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), SCH_EDIT_FRAME::EditSheet(), and SCH_EDIT_FRAME::OpenProjectFiles().

194 {
195  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
196  not_implemented( this, __FUNCTION__ );
197  static wxString error;
198  return error;
199 }
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:36
const wxString SCH_EAGLE_PLUGIN::GetFileExtension ( ) const
overridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 360 of file sch_eagle_plugin.cpp.

361 {
362  return "sch";
363 }
wxFileName SCH_EAGLE_PLUGIN::getLibFileName ( )
private

Definition at line 145 of file sch_eagle_plugin.cpp.

References SchematicLibraryFileExtension.

146 {
148 
149  return fn;
150 }
KIWAY * m_kiway
For creating sub sheets.
const std::string SchematicLibraryFileExtension
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
wxString SCH_EAGLE_PLUGIN::getLibName ( )
private

Definition at line 121 of file sch_eagle_plugin.cpp.

References LIB_ID::FixIllegalChars(), and LIB_ID::ID_SCH.

122 {
123  if( m_libName.IsEmpty() )
124  {
125  // Try to come up with a meaningful name
127 
128  if( m_libName.IsEmpty() )
129  {
130  wxFileName fn( m_rootSheet->GetFileName() );
131  m_libName = fn.GetName();
132  }
133 
134  if( m_libName.IsEmpty() )
135  m_libName = "noname";
136 
137  m_libName += "-eagle-import";
138  m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, true );
139  }
140 
141  return m_libName;
142 }
KIWAY * m_kiway
For creating sub sheets.
wxString m_libName
Library name to save symbols.
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:661
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:108
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 366 of file sch_eagle_plugin.cpp.

367 {
368  return 0;
369 }
const wxString SCH_EAGLE_PLUGIN::GetName ( ) const
overridevirtual

Returns a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 354 of file sch_eagle_plugin.cpp.

355 {
356  return "EAGLE";
357 }
size_t SCH_PLUGIN::GetSymbolLibCount ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Reimplemented in SCH_LEGACY_PLUGIN.

Definition at line 66 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::GetSymbolCount().

68 {
69  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
70  not_implemented( this, __FUNCTION__ );
71  return 0;
72 }
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:36
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.

Definition at line 141 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::IsSymbolLibWritable().

142 {
143  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
144  not_implemented( this, __FUNCTION__ );
145  return false;
146 }
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:36
SCH_LAYER_ID SCH_EAGLE_PLUGIN::kiCadLayer ( int  aEagleLayer)
private

Return the matching layer or return LAYER_NOTES.

Definition at line 205 of file sch_eagle_plugin.cpp.

References LAYER_NOTES.

206 {
207  auto it = m_layerMap.find( aEagleLayer );
208  return it == m_layerMap.end() ? LAYER_NOTES : it->second;
209 }
std::map< int, SCH_LAYER_ID > m_layerMap
SCH_SHEET * SCH_EAGLE_PLUGIN::Load ( const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
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 372 of file sch_eagle_plugin.cpp.

References PROJECT::ELEM_SYMBOL_LIB_TABLE, SYMBOL_LIB_TABLE::Format(), Format(), SCH_SHEET::GetRootSheet(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), LIB_TABLE::HasLibrary(), LIB_TABLE::InsertRow(), MapChildren(), SCH_LEGACY_PLUGIN::PropBuffering, SCH_SCREEN::SetFileName(), and THROW_IO_ERROR.

374 {
375  wxASSERT( !aFileName || aKiway != NULL );
376  LOCALE_IO toggle; // toggles on, then off, the C locale.
377 
378  // Load the document
379  wxXmlDocument xmlDocument;
380 
381  m_filename = aFileName;
382  m_kiway = aKiway;
383 
384  if( !xmlDocument.Load( m_filename.GetFullPath() ) )
385  THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
386  m_filename.GetFullPath() ) );
387 
388  // Delete on exception, if I own m_rootSheet, according to aAppendToMe
389  unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
390 
391  if( aAppendToMe )
392  {
393  m_rootSheet = aAppendToMe->GetRootSheet();
394  }
395  else
396  {
397  m_rootSheet = new SCH_SHEET();
398  m_rootSheet->SetFileName( aFileName );
399  }
400 
401  if( !m_rootSheet->GetScreen() )
402  {
403  SCH_SCREEN* screen = new SCH_SCREEN( aKiway );
404  screen->SetFileName( aFileName );
405  m_rootSheet->SetScreen( screen );
406  }
407 
408  SYMBOL_LIB_TABLE* libTable = m_kiway->Prj().SchSymbolLibTable();
409 
410  wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." );
411 
412  m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
413  m_properties = std::make_unique<PROPERTIES>();
414  (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
415 
418  if( !libTable->HasLibrary( getLibName() ) )
419  {
420  // Create a new empty symbol library.
421  m_pi->CreateSymbolLib( getLibFileName().GetFullPath() );
422  wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName();
423 
424  // Add the new library to the project symbol library table.
425  libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri,
426  wxString( "Legacy" ) ) );
427 
428  // Save project symbol library table.
429  wxFileName fn( m_kiway->Prj().GetProjectPath(),
431 
432  // So output formatter goes out of scope and closes the file before reloading.
433  {
434  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
435  libTable->Format( &formatter, 0 );
436  }
437 
438  // Relaod the symbol library table.
440  m_kiway->Prj().SchSymbolLibTable();
441  }
442 
443  // Retrieve the root as current node
444  wxXmlNode* currentNode = xmlDocument.GetRoot();
445 
446  // If the attribute is found, store the Eagle version;
447  // otherwise, store the dummy "0.0" version.
448  m_version = currentNode->GetAttribute( "version", "0.0" );
449 
450  // Map all children into a readable dictionary
451  NODE_MAP children = MapChildren( currentNode );
452 
453  // Load drawing
454  loadDrawing( children["drawing"] );
455 
456  m_pi->SaveLibrary( getLibFileName().GetFullPath() );
457 
458  return m_rootSheet;
459 }
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:126
static const wxString & GetSymbolLibTableFileName()
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:467
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:104
SCH_SHEET * GetRootSheet()
Return the root sheet of this SCH_SHEET object.
Definition: sch_sheet.cpp:136
KIWAY * m_kiway
For creating sub sheets.
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:551
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxFileName getLibFileName()
wxString m_version
Eagle file version.
#define THROW_IO_ERROR(msg)
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:209
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:44
void loadDrawing(wxXmlNode *aDrawingNode)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
static const char * PropBuffering
const char* PropBuffering
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:129
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void SCH_EAGLE_PLUGIN::loadDrawing ( wxXmlNode *  aDrawingNode)
private

Definition at line 462 of file sch_eagle_plugin.cpp.

References MapChildren().

463 {
464  // Map all children into a readable dictionary
465  NODE_MAP drawingChildren = MapChildren( aDrawingNode );
466 
467  // Board nodes should not appear in .sch files
468  // wxXmlNode* board = drawingChildren["board"]
469 
470  // wxXmlNode* grid = drawingChildren["grid"]
471 
472  auto layers = drawingChildren["layers"];
473 
474  if( layers )
475  loadLayerDefs( layers );
476 
477  // wxXmlNode* library = drawingChildren["library"]
478 
479  // wxXmlNode* settings = drawingChildren["settings"]
480 
481 
482  // Load schematic
483  auto schematic = drawingChildren["schematic"];
484  if( schematic )
485  loadSchematic( schematic );
486 }
void loadSchematic(wxXmlNode *aSchematicNode)
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides 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:48
void SCH_EAGLE_PLUGIN::loadFieldAttributes ( LIB_FIELD aField,
const LIB_TEXT aText 
) const
private

Definition at line 1827 of file sch_eagle_plugin.cpp.

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().

1828 {
1829  aField->SetTextPos( aText->GetPosition() );
1830  aField->SetTextSize( aText->GetTextSize() );
1831  aField->SetTextAngle( aText->GetTextAngle() );
1832  aField->SetBold( aText->IsBold() );
1833  aField->SetVertJustify( aText->GetVertJustify() );
1834  aField->SetHorizJustify( aText->GetHorizJustify() );
1835  aField->SetVisible( true );
1836 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_text.h:117
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
void SetVisible(bool aVisible)
Definition: eda_text.h:188
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
bool IsBold() const
Definition: eda_text.h:186
double GetTextAngle() const
Definition: eda_text.h:177
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
const wxSize & GetTextSize() const
Definition: eda_text.h:228
void SetBold(bool aBold)
Definition: eda_text.h:185
void SCH_EAGLE_PLUGIN::loadInstance ( wxXmlNode *  aInstanceNode)
private

Definition at line 1053 of file sch_eagle_plugin.cpp.

References SCH_SCREEN::Append(), EPART::attribute, ETEXT::BOTTOM_LEFT, EPART::device, EPART::deviceset, EagleModuleTstamp(), eagleToKicadAlignment(), FOOTPRINT, Format(), LIB_PART::GetField(), LIB_PART::GetFields(), LIB_ALIAS::GetPart(), LIB_FIELD::IsVisible(), kiCadComponentRotation(), EPART::library, EATTR::NAME, EATTR::Off, EAGLE_LIBRARY::package, SCH_SHEET_PATH::Path(), REFERENCE, SCH_FIELD::SetPosition(), EDA_TEXT::SetVisible(), VALUE, EPART::value, and EPART::variant.

1054 {
1055  auto einstance = EINSTANCE( aInstanceNode );
1056 
1057  SCH_SCREEN* screen = m_currentSheet->GetScreen();
1058 
1059  // Find the part in the list for the sheet.
1060  // Assign the component its value from the part entry
1061  // Calculate the unit number from the gate entry of the instance
1062  // Assign the the LIB_ID from deviceset and device names
1063 
1064  EPART* epart = m_partlist[einstance.part].get();
1065 
1066  wxString libraryname = epart->library;
1067  wxString gatename = epart->deviceset + epart->device + einstance.gate;
1068  wxString symbolname = wxString( epart->deviceset + epart->device );
1069  symbolname.Replace( "*", "" );
1070  wxString kisymbolname = fixSymbolName( symbolname );
1071 
1072  int unit = m_eagleLibs[libraryname].GateUnit[gatename];
1073 
1074  wxString package;
1075  EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname];
1076 
1077  auto p = elib->package.find( kisymbolname );
1078 
1079  if( p != elib->package.end() )
1080  {
1081  package = p->second;
1082  }
1083 
1084  LIB_ALIAS* alias = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname,
1085  m_properties.get() );
1086 
1087  if( !alias || !alias->GetPart() )
1088  {
1089  wxLogMessage( wxString::Format( _( "Could not find %s in the imported library" ), kisymbolname ) );
1090  return;
1091  }
1092 
1093  LIB_PART* part = alias->GetPart();
1094  LIB_ID libId( getLibName(), kisymbolname );
1095  std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT() );
1096  component->SetLibId( libId );
1097  component->SetUnit( unit );
1098  component->SetPosition( wxPoint( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) );
1099  component->GetField( FOOTPRINT )->SetText( package );
1100  component->SetTimeStamp( EagleModuleTstamp( einstance.part, epart->value ? *epart->value : "",
1101  unit ) );
1102 
1103  if( einstance.rot )
1104  {
1105  component->SetOrientation( kiCadComponentRotation( einstance.rot->degrees ) );
1106 
1107  if( einstance.rot->mirror )
1108  {
1109  component->MirrorY( einstance.x.ToSchUnits() );
1110  }
1111  }
1112 
1113 
1114  LIB_FIELDS partFields;
1115  part->GetFields( partFields );
1116 
1117  for( auto const& field : partFields )
1118  {
1119  component->GetField( field.GetId() )->ImportValues( field );
1120  component->GetField( field.GetId() )->SetTextPos(
1121  component->GetPosition() + field.GetTextPos() );
1122  }
1123 
1124  // If there is no footprint assigned, then prepend the reference value
1125  // with a hash character to mute netlist updater complaints
1126  wxString reference = package.IsEmpty() ? '#' + einstance.part : einstance.part;
1127 
1128  SCH_SHEET_PATH sheetpath;
1129  m_rootSheet->LocatePathOfScreen( screen, &sheetpath );
1130  wxString current_sheetpath = sheetpath.Path();
1131 
1132  wxString tstamp;
1133  tstamp.Printf( "%8.8lX", (unsigned long) component->GetTimeStamp() );
1134  current_sheetpath += tstamp;
1135 
1136  component->GetField( REFERENCE )->SetText( reference );
1137  component->AddHierarchicalReference( current_sheetpath, reference, unit );
1138 
1139  if( epart->value )
1140  component->GetField( VALUE )->SetText( *epart->value );
1141  else
1142  component->GetField( VALUE )->SetText( kisymbolname );
1143 
1144  // Set the visibility of fields.
1145  component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
1146  component->GetField( VALUE )->SetVisible( part->GetField( VALUE )->IsVisible() );
1147 
1148  for( auto a:epart->attribute )
1149  {
1150  auto field = component->AddField( *component->GetField( VALUE ) );
1151  field->SetName( a.first );
1152  field->SetText( a.second );
1153  field->SetVisible( false );
1154  }
1155 
1156  for( auto a:epart->variant )
1157  {
1158  auto field = component->AddField( *component->GetField( VALUE ) );
1159  field->SetName( "VARIANT_" + a.first );
1160  field->SetText( a.second );
1161  field->SetVisible( false );
1162  }
1163 
1164  bool valueAttributeFound = false;
1165  bool nameAttributeFound = false;
1166 
1167 
1168  wxXmlNode* attributeNode = aInstanceNode->GetChildren();
1169 
1170  // Parse attributes for the instance
1171  while( attributeNode )
1172  {
1173  if( attributeNode->GetName() == "attribute" )
1174  {
1175  auto attr = EATTR( attributeNode );
1176  SCH_FIELD* field = NULL;
1177 
1178  if( attr.name.Lower() == "name" )
1179  {
1180  field = component->GetField( REFERENCE );
1181  nameAttributeFound = true;
1182  }
1183  else if( attr.name.Lower() == "value" )
1184  {
1185  field = component->GetField( VALUE );
1186  valueAttributeFound = true;
1187  }
1188  else
1189  {
1190  field = component->FindField( attr.name );
1191 
1192  if(field)
1193  field->SetVisible( false );
1194  }
1195 
1196  if( field )
1197  {
1198 
1199  field->SetPosition( wxPoint( attr.x->ToSchUnits(), -attr.y->ToSchUnits() ) );
1200  int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
1201  int absdegrees = attr.rot ? attr.rot->degrees : 0;
1202  bool mirror = attr.rot ? attr.rot->mirror : false;
1203 
1204  if( einstance.rot && einstance.rot->mirror )
1205  mirror = !mirror;
1206 
1207  bool spin = attr.rot ? attr.rot->spin : false;
1208 
1209  if( attr.display == EATTR::Off || attr.display == EATTR::NAME )
1210  field->SetVisible( false );
1211 
1212  int rotation = einstance.rot ? einstance.rot->degrees : 0;
1213  int reldegrees = ( absdegrees - rotation + 360.0 );
1214  reldegrees %= 360;
1215 
1216  eagleToKicadAlignment( (EDA_TEXT*) field, align, reldegrees, mirror, spin,
1217  absdegrees );
1218  }
1219  }
1220  else if( attributeNode->GetName() == "variant" )
1221  {
1222  wxString variant, value;
1223 
1224  if( attributeNode->GetAttribute( "name", &variant )
1225  && attributeNode->GetAttribute( "value", &value ) )
1226  {
1227  auto field = component->AddField( *component->GetField( VALUE ) );
1228  field->SetName( "VARIANT_" + variant );
1229  field->SetText( value );
1230  field->SetVisible( false );
1231  }
1232  }
1233 
1234  attributeNode = attributeNode->GetNext();
1235  }
1236 
1237  if( einstance.smashed && einstance.smashed.Get() )
1238  {
1239  if( !valueAttributeFound )
1240  component->GetField( VALUE )->SetVisible( false );
1241 
1242  if( !nameAttributeFound )
1243  component->GetField( REFERENCE )->SetVisible( false );
1244  }
1245 
1246 
1247  // Save the pin positions
1248  auto& schLibTable = *m_kiway->Prj().SchSymbolLibTable();
1249  wxCHECK( component->Resolve( schLibTable ), /*void*/ );
1250  component->UpdatePinCache();
1251  std::vector<LIB_PIN*> pins;
1252  component->GetPins( pins );
1253 
1254  for( const auto& pin : pins )
1255  m_connPoints[component->GetPinPhysicalPosition( pin )].emplace( pin );
1256 
1257 
1258  component->ClearFlags();
1259 
1260  screen->Append( component.release() );
1261 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
wxString deviceset
Definition: eagle_parser.h:912
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
LIB_FIELD * GetField(int aId)
Return pointer to the requested field.
Part library alias object definition.
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:93
wxString library
Definition: eagle_parser.h:911
std::unordered_map< wxString, wxString > package
void SetVisible(bool aVisible)
Definition: eda_text.h:188
KIWAY * m_kiway
For creating sub sheets.
std::map< std::string, std::string > variant
Definition: eagle_parser.h:917
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()
Definition: sch_sheet.h:279
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
opt_wxString value
Definition: eagle_parser.h:915
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
static wxString fixSymbolName(const wxString &aName)
Fixes invalid characters in Eagle symbol names.
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
timestamp_t EagleModuleTstamp(const wxString &aName, const wxString &aValue, int aUnit)
Computes module timestamp basing on its name, value and unit
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
Define a library symbol object.
wxFileName getLibFileName()
std::map< std::string, std::string > attribute
Definition: eagle_parser.h:916
Class SCH_SHEET_PATH.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
LIB_PART * GetPart() const
Get the shared LIB_PART.
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:603
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:609
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
bool IsVisible() const
Definition: lib_field.h:166
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:259
void SetName(const wxString &aName)
Definition: sch_field.h:85
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
wxString device
Definition: eagle_parser.h:913
#define VALUE
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_field.cpp:543
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
SCH_JUNCTION * SCH_EAGLE_PLUGIN::loadJunction ( wxXmlNode *  aJunction)
private

Definition at line 960 of file sch_eagle_plugin.cpp.

961 {
962  std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION );
963 
964  auto ejunction = EJUNCTION( aJunction );
965  wxPoint pos( ejunction.x.ToSchUnits(), -ejunction.y.ToSchUnits() );
966 
967  junction->SetPosition( pos );
968 
969  return junction.release();
970 }
Eagle Junction.
Definition: eagle_parser.h:531
SCH_TEXT * SCH_EAGLE_PLUGIN::loadLabel ( wxXmlNode *  aLabelNode,
const wxString &  aNetName 
)
private

Definition at line 973 of file sch_eagle_plugin.cpp.

References escapeName().

974 {
975  auto elabel = ELABEL( aLabelNode, aNetName );
976  wxPoint elabelpos( elabel.x.ToSchUnits(), -elabel.y.ToSchUnits() );
977 
978  // Determine if the label is local or global depending on
979  // the number of sheets the net appears in
980  bool global = m_netCounts[aNetName] > 1;
981  std::unique_ptr<SCH_TEXT> label;
982 
983  if( global )
984  label.reset( new SCH_GLOBALLABEL );
985  else
986  label.reset( new SCH_LABEL );
987 
988  label->SetPosition( elabelpos );
989  label->SetText( escapeName( elabel.netname ) );
990  label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
991  label->SetLabelSpinStyle( global ? 2 : 0 );
992 
993  if( elabel.rot )
994  {
995  int offset = global ? 2 : 0;
996  label->SetLabelSpinStyle( int( elabel.rot->degrees / 90 + offset ) % 4 );
997 
998  if( elabel.rot->mirror
999  && ( label->GetLabelSpinStyle() == 0 || label->GetLabelSpinStyle() == 2 ) )
1000  label->SetLabelSpinStyle( (label->GetLabelSpinStyle() + 2 ) % 4 );
1001  }
1002 
1003  return label.release();
1004 }
std::map< wxString, int > m_netCounts
Eagle label.
Definition: eagle_parser.h:541
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
void SCH_EAGLE_PLUGIN::loadLayerDefs ( wxXmlNode *  aLayers)
private

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

<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 153 of file sch_eagle_plugin.cpp.

References LAYER_BUS, LAYER_NOTES, and LAYER_WIRE.

154 {
155  std::vector<ELAYER> eagleLayers;
156 
157  // Get the first layer and iterate
158  wxXmlNode* layerNode = aLayers->GetChildren();
159 
160  while( layerNode )
161  {
162  ELAYER elayer( layerNode );
163  eagleLayers.push_back( elayer );
164 
165  layerNode = layerNode->GetNext();
166  }
167 
168  // match layers based on their names
169  for( const auto& elayer : eagleLayers )
170  {
189  if( elayer.name == "Nets" )
190  {
191  m_layerMap[elayer.number] = LAYER_WIRE;
192  }
193  else if( elayer.name == "Info" || elayer.name == "Guide" )
194  {
195  m_layerMap[elayer.number] = LAYER_NOTES;
196  }
197  else if( elayer.name == "Busses" )
198  {
199  m_layerMap[elayer.number] = LAYER_BUS;
200  }
201  }
202 }
std::map< int, SCH_LAYER_ID > m_layerMap
EAGLE_LIBRARY * SCH_EAGLE_PLUGIN::loadLibrary ( wxXmlNode *  aLibraryNode,
EAGLE_LIBRARY aEagleLib 
)
private

Definition at line 1264 of file sch_eagle_plugin.cpp.

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, LIB_FIELD::SetText(), EDA_TEXT::SetVisible(), EGATE::symbol, and EAGLE_LIBRARY::SymbolNodes.

1266 {
1267  NODE_MAP libraryChildren = MapChildren( aLibraryNode );
1268 
1269  // Loop through the symbols and load each of them
1270  wxXmlNode* symbolNode = getChildrenNodes( libraryChildren, "symbols" );
1271 
1272  while( symbolNode )
1273  {
1274  wxString symbolName = symbolNode->GetAttribute( "name" );
1275  aEagleLibrary->SymbolNodes[symbolName] = symbolNode;
1276  symbolNode = symbolNode->GetNext();
1277  }
1278 
1279  // Loop through the devicesets and load each of them
1280  wxXmlNode* devicesetNode = getChildrenNodes( libraryChildren, "devicesets" );
1281 
1282  while( devicesetNode )
1283  {
1284  // Get Device set information
1285  EDEVICE_SET edeviceset = EDEVICE_SET( devicesetNode );
1286 
1287  wxString prefix = edeviceset.prefix ? edeviceset.prefix.Get() : "";
1288 
1289  NODE_MAP aDeviceSetChildren = MapChildren( devicesetNode );
1290  wxXmlNode* deviceNode = getChildrenNodes( aDeviceSetChildren, "devices" );
1291 
1292  // For each device in the device set:
1293  while( deviceNode )
1294  {
1295  // Get device information
1296  EDEVICE edevice = EDEVICE( deviceNode );
1297 
1298  // Create symbol name from deviceset and device names.
1299  wxString symbolName = edeviceset.name + edevice.name;
1300  symbolName.Replace( "*", "" );
1301  wxASSERT( !symbolName.IsEmpty() );
1302  symbolName = fixSymbolName( symbolName );
1303 
1304  if( edevice.package )
1305  aEagleLibrary->package[symbolName] = edevice.package.Get();
1306 
1307  // Create KiCad symbol.
1308  unique_ptr<LIB_PART> kpart( new LIB_PART( symbolName ) );
1309 
1310  // Process each gate in the deviceset for this device.
1311  wxXmlNode* gateNode = getChildrenNodes( aDeviceSetChildren, "gates" );
1312  int gates_count = countChildren( aDeviceSetChildren["gates"], "gate" );
1313  kpart->SetUnitCount( gates_count );
1314  kpart->LockUnits( true );
1315 
1316  LIB_FIELD* reference = kpart->GetField( REFERENCE );
1317 
1318  if( prefix.length() == 0 )
1319  reference->SetVisible( false );
1320  else
1321  // If there is no footprint assigned, then prepend the reference value
1322  // with a hash character to mute netlist updater complaints
1323  reference->SetText( edevice.package ? prefix : '#' + prefix );
1324 
1325  int gateindex = 1;
1326  bool ispower = false;
1327 
1328  while( gateNode )
1329  {
1330  EGATE egate = EGATE( gateNode );
1331 
1332  aEagleLibrary->GateUnit[edeviceset.name + edevice.name + egate.name] = gateindex;
1333 
1334  ispower = loadSymbol( aEagleLibrary->SymbolNodes[egate.symbol],
1335  kpart, &edevice, gateindex, egate.name );
1336 
1337  gateindex++;
1338  gateNode = gateNode->GetNext();
1339  } // gateNode
1340 
1341  kpart->SetUnitCount( gates_count );
1342 
1343  if( gates_count == 1 && ispower )
1344  kpart->SetPower();
1345 
1346  wxString name = fixSymbolName( kpart->GetName() );
1347  kpart->SetName( name );
1348  m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ),
1349  m_properties.get() );
1350  aEagleLibrary->KiCadSymbols.insert( name, kpart.release() );
1351 
1352  deviceNode = deviceNode->GetNext();
1353  } // devicenode
1354 
1355  devicesetNode = devicesetNode->GetNext();
1356  } // devicesetNode
1357 
1358  return aEagleLibrary;
1359 }
wxString name
T & Get()
Function Get returns a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:300
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:188
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provides an easy access to the children of an XML node via their names.
Field Reference of part, i.e. "IC21".
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
wxString name
static wxString fixSymbolName(const wxString &aName)
Fixes invalid characters in Eagle symbol names.
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:510
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxString symbol
Definition: eagle_parser.h:963
bool loadSymbol(wxXmlNode *aSymbolNode, std::unique_ptr< LIB_PART > &aPart, EDEVICE *aDevice, int aGateNumber, const wxString &aGateName)
Define a library symbol object.
wxFileName getLibFileName()
wxString name
Definition: eagle_parser.h:962
opt_wxString prefix
const char * name
Definition: DXF_plotter.cpp:61
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:102
opt_wxString package
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:58
LIB_PIN * SCH_EAGLE_PLUGIN::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aPin,
EPIN epin,
int  aGateNumber 
)
private

Definition at line 1660 of file sch_eagle_plugin.cpp.

References EROT::degrees, Format(), EPIN::function, OPTIONAL_XML_ATTRIBUTE< T >::Get(), EPIN::length, EPIN::name, PINSHAPE_CLOCK, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, EPIN::rot, ECOORD::ToSchUnits(), EPIN::visible, EPIN::x, and EPIN::y.

1664 {
1665  std::unique_ptr<LIB_PIN> pin( new LIB_PIN( aPart.get() ) );
1666  pin->SetPosition( wxPoint( aEPin->x.ToSchUnits(), aEPin->y.ToSchUnits() ) );
1667  pin->SetName( aEPin->name );
1668  pin->SetUnit( aGateNumber );
1669 
1670  int roti = aEPin->rot ? aEPin->rot->degrees : 0;
1671 
1672  switch( roti )
1673  {
1674  default:
1675  wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
1676 
1677  // fall through
1678  case 0:
1679  pin->SetOrientation( 'R' );
1680  break;
1681 
1682  case 90:
1683  pin->SetOrientation( 'U' );
1684  break;
1685 
1686  case 180:
1687  pin->SetOrientation( 'L' );
1688  break;
1689 
1690  case 270:
1691  pin->SetOrientation( 'D' );
1692  break;
1693  }
1694 
1695  if( aEPin->length )
1696  {
1697  wxString length = aEPin->length.Get();
1698 
1699  if( length =="short" )
1700  {
1701  pin->SetLength( 100 );
1702  }
1703  else if( length =="middle" )
1704  {
1705  pin->SetLength( 200 );
1706  }
1707  else if( length == "long" )
1708  {
1709  pin->SetLength( 300 );
1710  }
1711  else if( length == "point" )
1712  {
1713  pin->SetLength( 0 );
1714  }
1715  }
1716 
1717  // emulate the visibility of pin elements
1718  if( aEPin->visible )
1719  {
1720  wxString visible = aEPin->visible.Get();
1721 
1722  if( visible == "off" )
1723  {
1724  pin->SetNameTextSize( 0 );
1725  pin->SetNumberTextSize( 0 );
1726  }
1727  else if( visible == "pad" )
1728  {
1729  pin->SetNameTextSize( 0 );
1730  }
1731  else if( visible == "pin" )
1732  {
1733  pin->SetNumberTextSize( 0 );
1734  }
1735 
1736  /*
1737  * else if( visible == "both" )
1738  * {
1739  * }
1740  */
1741  }
1742 
1743  if( aEPin->function )
1744  {
1745  wxString function = aEPin->function.Get();
1746 
1747  if( function == "dot" )
1748  {
1749  pin->SetShape( PINSHAPE_INVERTED );
1750  }
1751  else if( function == "clk" )
1752  {
1753  pin->SetShape( PINSHAPE_CLOCK );
1754  }
1755  else if( function == "dotclk" )
1756  {
1757  pin->SetShape( PINSHAPE_INVERTED_CLOCK );
1758  }
1759  }
1760 
1761  return pin.release();
1762 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
SCH_TEXT * SCH_EAGLE_PLUGIN::loadPlainText ( wxXmlNode *  aSchText)
private

Definition at line 1790 of file sch_eagle_plugin.cpp.

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

1791 {
1792  std::unique_ptr<SCH_TEXT> schtext( new SCH_TEXT() );
1793  ETEXT etext = ETEXT( aSchText );
1794 
1795  const wxString& thetext = aSchText->GetNodeContent();
1796  schtext->SetText( thetext.IsEmpty() ? "\" \"" : escapeName( thetext ) );
1797  schtext->SetPosition( wxPoint( etext.x.ToSchUnits(), -etext.y.ToSchUnits() ) );
1798  loadTextAttributes( schtext.get(), etext );
1799  schtext->SetItalic( false );
1800 
1801  return schtext.release();
1802 }
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
Eagle text element.
Definition: eagle_parser.h:646
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
ECOORD x
Definition: eagle_parser.h:649
ECOORD y
Definition: eagle_parser.h:650
int ToSchUnits() const
Definition: eagle_parser.h:438
void SCH_EAGLE_PLUGIN::loadSchematic ( wxXmlNode *  aSchematicNode)
private

Definition at line 522 of file sch_eagle_plugin.cpp.

References countChildren(), EagleModuleTstamp(), EDA_RECT::GetBottom(), getChildrenNodes(), SCH_COMPONENT::GetField(), EDA_RECT::GetHeight(), EDA_RECT::GetLeft(), GetNewTimeStamp(), getSheetBbox(), EDA_TEXT::GetText(), EDA_RECT::GetWidth(), EDA_RECT::GetY(), i, MapChildren(), max, EAGLE_LIBRARY::name, SCH_SHEET_PATH::Path(), REFERENCE, and VALUE.

523 {
524  // Map all children into a readable dictionary
525  NODE_MAP schematicChildren = MapChildren( aSchematicNode );
526  auto partNode = getChildrenNodes( schematicChildren, "parts" );
527  auto libraryNode = getChildrenNodes( schematicChildren, "libraries" );
528  auto sheetNode = getChildrenNodes( schematicChildren, "sheets" );
529 
530  if( !partNode || !libraryNode || !sheetNode )
531  return;
532 
533  while( partNode )
534  {
535  std::unique_ptr<EPART> epart( new EPART( partNode ) );
536  m_partlist[epart->name] = std::move( epart );
537  partNode = partNode->GetNext();
538  }
539 
540  // Loop through all the libraries
541  while( libraryNode )
542  {
543  // Read the library name
544  wxString libName = libraryNode->GetAttribute( "name" );
545 
546  EAGLE_LIBRARY* elib = &m_eagleLibs[libName];
547  elib->name = libName;
548 
549  loadLibrary( libraryNode, &m_eagleLibs[libName] );
550 
551  libraryNode = libraryNode->GetNext();
552  }
553 
554  m_pi->SaveLibrary( getLibFileName().GetFullPath() );
555 
556  // find all nets and count how many sheets they appear on.
557  // local labels will be used for nets found only on that sheet.
558  countNets( aSchematicNode );
559 
560  // Loop through all the sheets
561  int sheet_count = countChildren( sheetNode->GetParent(), "sheet" );
562 
563  // If eagle schematic has multiple sheets then create corresponding subsheets on the root sheet
564  if( sheet_count > 1 )
565  {
566  int x, y, i;
567  i = 1;
568  x = 1;
569  y = 1;
570 
571  while( sheetNode )
572  {
573  wxPoint pos = wxPoint( x * 1000, y * 1000 );
574  std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( pos ) );
575  SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
576 
577  sheet->SetTimeStamp( GetNewTimeStamp() - i ); // minus the sheet index to make it unique.
578  sheet->SetParent( m_rootSheet->GetScreen() );
579  sheet->SetScreen( screen );
580  sheet->GetScreen()->SetFileName( sheet->GetFileName() );
581 
582  m_currentSheet = sheet.get();
583  loadSheet( sheetNode, i );
584  m_rootSheet->GetScreen()->Append( sheet.release() );
585 
586  sheetNode = sheetNode->GetNext();
587  x += 2;
588 
589  if( x > 10 ) // start next row
590  {
591  x = 1;
592  y += 2;
593  }
594 
595  i++;
596  }
597  }
598  else
599  {
600  while( sheetNode )
601  {
603  loadSheet( sheetNode, 0 );
604  sheetNode = sheetNode->GetNext();
605  }
606  }
607 
608 
609  // Handle the missing component units that need to be instantiated
610  // to create the missing implicit connections
611 
612  // Calculate the already placed items bounding box and the page size to determine
613  // placement for the new components
614  wxSize pageSizeIU = m_rootSheet->GetScreen()->GetPageSettings().GetSizeIU();
615  EDA_RECT sheetBbox = getSheetBbox( m_rootSheet );
616  wxPoint newCmpPosition( sheetBbox.GetLeft(), sheetBbox.GetBottom() );
617  int maxY = sheetBbox.GetY();
618 
619  SCH_SHEET_PATH sheetpath;
621 
622  for( auto& cmp : m_missingCmps )
623  {
624  const SCH_COMPONENT* origCmp = cmp.second.cmp;
625 
626  for( auto unitEntry : cmp.second.units )
627  {
628  if( unitEntry.second == false )
629  continue; // unit has been already processed
630 
631  // Instantiate the missing component unit
632  int unit = unitEntry.first;
633  const wxString& reference = origCmp->GetField( REFERENCE )->GetText();
634  std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT( *origCmp ) );
635  component->SetUnitSelection( &sheetpath, unit );
636  component->SetUnit( unit );
637  component->SetTimeStamp( EagleModuleTstamp( reference, origCmp->GetField( VALUE )->GetText(), unit ) );
638  component->SetOrientation( 0 );
639  component->AddHierarchicalReference( sheetpath.Path(), reference, unit );
640 
641  // Calculate the placement position
642  EDA_RECT cmpBbox = component->GetBoundingBox();
643  int posY = newCmpPosition.y + cmpBbox.GetHeight();
644  component->SetPosition( wxPoint( newCmpPosition.x, posY ) );
645  newCmpPosition.x += cmpBbox.GetWidth();
646  maxY = std::max( maxY, posY );
647 
648  if( newCmpPosition.x >= pageSizeIU.GetWidth() ) // reached the page boundary?
649  newCmpPosition = wxPoint( sheetBbox.GetLeft(), maxY ); // then start a new row
650 
651  // Add the global net labels to recreate the implicit connections
652  addImplicitConnections( component.get(), m_rootSheet->GetScreen(), false );
653  m_rootSheet->GetScreen()->Append( component.release() );
654  }
655  }
656 
657  m_missingCmps.clear();
658 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
int GetLeft() const
Definition: eda_rect.h:120
EAGLE_LIBRARY * loadLibrary(wxXmlNode *aLibraryNode, EAGLE_LIBRARY *aEagleLib)
int GetHeight() const
Definition: eda_rect.h:118
KIWAY * m_kiway
For creating sub sheets.
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provides an easy access to the children of an XML node via their names.
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
Map references to missing component units data
Field Reference of part, i.e. "IC21".
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Creates net labels to emulate implicit connections in Eagle.
timestamp_t EagleModuleTstamp(const wxString &aName, const wxString &aValue, int aUnit)
Computes module timestamp basing on its name, value and unit
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Plugin to create the KiCad symbol library.
wxFileName getLibFileName()
int GetBottom() const
Definition: eda_rect.h:122
Class SCH_SHEET_PATH.
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:209
static EDA_RECT getSheetBbox(SCH_SHEET *aSheet)
Computes a bounding box for all items in a schematic sheet
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:44
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:609
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
int GetWidth() const
Definition: eda_rect.h:117
int GetY() const
Definition: eda_rect.h:110
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:126
void countNets(wxXmlNode *aSchematicNode)
void loadSheet(wxXmlNode *aSheetNode, int sheetcount)
#define VALUE
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:58
void SCH_EAGLE_PLUGIN::loadSegments ( wxXmlNode *  aSegmentsNode,
const wxString &  aNetName,
const wxString &  aNetClass 
)
private

Definition at line 817 of file sch_eagle_plugin.cpp.

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

819 {
820  // Loop through all segments
821  wxXmlNode* currentSegment = aSegmentsNode->GetChildren();
822  SCH_SCREEN* screen = m_currentSheet->GetScreen();
823 
824  int segmentCount = countChildren( aSegmentsNode, "segment" );
825 
826  // wxCHECK( screen, [>void<] );
827  while( currentSegment )
828  {
829  bool labelled = false; // has a label been added to this continously connected segment
830  NODE_MAP segmentChildren = MapChildren( currentSegment );
831  SCH_LINE* firstWire = nullptr;
832  m_segments.emplace_back();
833  SEG_DESC& segDesc = m_segments.back();
834 
835  // Loop through all segment children
836  wxXmlNode* segmentAttribute = currentSegment->GetChildren();
837 
838  while( segmentAttribute )
839  {
840  if( segmentAttribute->GetName() == "wire" )
841  {
842  SCH_LINE* wire = loadWire( segmentAttribute );
843 
844  if( !firstWire )
845  firstWire = wire;
846 
847  // Test for intersections with other wires
848  SEG thisWire( wire->GetStartPoint(), wire->GetEndPoint() );
849 
850  for( auto& desc : m_segments )
851  {
852  if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
853  continue; // no point in saving intersections of the same net
854 
855  for( const auto& seg : desc.segs )
856  {
857  auto intersection = thisWire.Intersect( seg, true );
858 
859  if( intersection )
860  m_wireIntersections.push_back( *intersection );
861  }
862  }
863 
864  segDesc.segs.push_back( thisWire );
865  screen->Append( wire );
866  }
867 
868  segmentAttribute = segmentAttribute->GetNext();
869  }
870 
871  segmentAttribute = currentSegment->GetChildren();
872 
873  while( segmentAttribute )
874  {
875  wxString nodeName = segmentAttribute->GetName();
876 
877  if( nodeName == "junction" )
878  {
879  screen->Append( loadJunction( segmentAttribute ) );
880  }
881  else if( nodeName == "label" )
882  {
883  SCH_TEXT* label = loadLabel( segmentAttribute, netName );
884  screen->Append( label );
885  wxASSERT( segDesc.labels.empty() || segDesc.labels.front()->GetText() == label->GetText() );
886  segDesc.labels.push_back( label );
887  labelled = true;
888  }
889  else if( nodeName == "pinref" )
890  {
891  segmentAttribute->GetAttribute( "gate" ); // REQUIRED
892  segmentAttribute->GetAttribute( "part" ); // REQUIRED
893  segmentAttribute->GetAttribute( "pin" ); // REQUIRED
894  }
895  else if( nodeName == "wire" )
896  {
897  // already handled;
898  }
899  else // DEFAULT
900  {
901  // THROW_IO_ERROR( wxString::Format( _( "XML node \"%s\" unknown" ), nodeName ) );
902  }
903 
904  // Get next segment attribute
905  segmentAttribute = segmentAttribute->GetNext();
906  }
907 
908  // Add a small label to the net segment if it hasn't been labelled already
909  // this preserves the named net feature of Eagle schematics.
910  if( !labelled && firstWire )
911  {
912  std::unique_ptr<SCH_TEXT> label;
913 
914  // Add a global label if the net appears on more than one Eagle sheet
915  if( m_netCounts[netName.ToStdString()] > 1 )
916  label.reset( new SCH_GLOBALLABEL );
917  else if( segmentCount > 1 )
918  label.reset( new SCH_LABEL );
919 
920  if( label )
921  {
922  label->SetPosition( firstWire->GetStartPoint() );
923  label->SetText( escapeName( netName ) );
924  label->SetTextSize( wxSize( 10, 10 ) );
925  label->SetLabelSpinStyle( 0 );
926  screen->Append( label.release() );
927  }
928  }
929 
930  currentSegment = currentSegment->GetNext();
931  }
932 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
SCH_LINE * loadWire(wxXmlNode *aWireNode)
virtual void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_text.h:196
std::map< wxString, int > m_netCounts
wxPoint GetEndPoint() const
Definition: sch_line.h:80
static int countChildren(wxXmlNode *aCurrentNode, const wxString &aName)
Provides an easy access to the children of an XML node via their names.
std::vector< VECTOR2I > m_wireIntersections
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:99
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
wxPoint GetStartPoint() const
Definition: sch_line.h:76
SCH_JUNCTION * loadJunction(wxXmlNode *aJunction)
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
SCH_TEXT * loadLabel(wxXmlNode *aLabelNode, const wxString &aNetName)
Definition: seg.h:36
std::vector< SEG_DESC > m_segments
Segments representing wires for intersection checking
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
void SCH_EAGLE_PLUGIN::loadSheet ( wxXmlNode *  aSheetNode,
int  sheetcount 
)
private

Definition at line 661 of file sch_eagle_plugin.cpp.

References EDA_RECT::Centre(), Format(), getChildrenNodes(), getSheetBbox(), EDA_RECT::GetSize(), MapChildren(), SCH_ITEM::Next(), ReplaceIllegalFileNameChars(), SCH_COMPONENT_T, PAGE_INFO::SetHeightMils(), PAGE_INFO::SetWidthMils(), wxPoint::x, and wxPoint::y.

662 {
663  // Map all children into a readable dictionary
664  NODE_MAP sheetChildren = MapChildren( aSheetNode );
665 
666  // Get description node
667  wxXmlNode* descriptionNode = getChildrenNodes( sheetChildren, "description" );
668 
669  wxString des;
670  std::string filename;
671 
672  if( descriptionNode )
673  {
674  des = descriptionNode->GetContent();
675  m_currentSheet->SetName( des );
676  filename = des.ToStdString();
677  }
678  else
679  {
680  filename = wxString::Format( "%s_%d", m_filename.GetName(), aSheetIndex );
681  m_currentSheet->SetName( filename );
682  }
683 
684  ReplaceIllegalFileNameChars( &filename );
685  replace( filename.begin(), filename.end(), ' ', '_' );
686 
687  wxString fn = wxString( filename + ".sch" );
689  wxFileName fileName = m_currentSheet->GetFileName();
690  m_currentSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
691 
692  // Loop through all busses
693  // From the DTD: "Buses receive names which determine which signals they include.
694  // A bus is a drawing object. It does not create any electrical connections.
695  // These are always created by means of the nets and their names."
696  wxXmlNode* busNode = getChildrenNodes( sheetChildren, "busses" );
697 
698  while( busNode )
699  {
700  // Get the bus name
701  wxString busName = busNode->GetAttribute( "name" );
702 
703  // Load segments of this bus
704  loadSegments( busNode, busName, wxString() );
705 
706  // Get next bus
707  busNode = busNode->GetNext();
708  }
709 
710  // Loop through all nets
711  // From the DTD: "Net is an electrical connection in a schematic."
712  wxXmlNode* netNode = getChildrenNodes( sheetChildren, "nets" );
713 
714  while( netNode )
715  {
716  // Get the net name and class
717  wxString netName = netNode->GetAttribute( "name" );
718  wxString netClass = netNode->GetAttribute( "class" );
719 
720  // Load segments of this net
721  loadSegments( netNode, netName, netClass );
722 
723  // Get next net
724  netNode = netNode->GetNext();
725  }
726 
727  adjustNetLabels(); // needs to be called before addBusEntries()
728  addBusEntries();
729 
730  // Loop through all instances
731  wxXmlNode* instanceNode = getChildrenNodes( sheetChildren, "instances" );
732 
733  while( instanceNode )
734  {
735  loadInstance( instanceNode );
736  instanceNode = instanceNode->GetNext();
737  }
738 
739  /* moduleinst is a design block definition and is an EagleCad 8 feature,
740  *
741  * // Loop through all moduleinsts
742  * wxXmlNode* moduleinstNode = getChildrenNodes( sheetChildren, "moduleinsts" );
743  *
744  * while( moduleinstNode )
745  * {
746  * loadModuleinst( moduleinstNode );
747  * moduleinstNode = moduleinstNode->GetNext();
748  * }
749  */
750 
751  wxXmlNode* plainNode = getChildrenNodes( sheetChildren, "plain" );
752 
753  while( plainNode )
754  {
755  wxString nodeName = plainNode->GetName();
756 
757  if( nodeName == "text" )
758  {
759  m_currentSheet->GetScreen()->Append( loadPlainText( plainNode ) );
760  }
761  else if( nodeName == "wire" )
762  {
763  m_currentSheet->GetScreen()->Append( loadWire( plainNode ) );
764  }
765 
766  plainNode = plainNode->GetNext();
767  }
768 
769  // Calculate the new sheet size.
770  EDA_RECT sheetBoundingBox = getSheetBbox( m_currentSheet );
771  wxSize targetSheetSize = sheetBoundingBox.GetSize();
772  targetSheetSize.IncBy( 1500, 1500 );
773 
774  // Get current Eeschema sheet size.
775  wxSize pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
777 
778  // Increase if necessary
779  if( pageSizeIU.x < targetSheetSize.x )
780  pageInfo.SetWidthMils( targetSheetSize.x );
781 
782  if( pageSizeIU.y < targetSheetSize.y )
783  pageInfo.SetHeightMils( targetSheetSize.y );
784 
785  // Set the new sheet size.
786  m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
787 
788  pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU();
789  wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
790  wxPoint itemsCentre = sheetBoundingBox.Centre();
791 
792  // round the translation to nearest 100mil to place it on the grid.
793  wxPoint translation = sheetcentre - itemsCentre;
794  translation.x = translation.x - translation.x % 100;
795  translation.y = translation.y - translation.y % 100;
796 
797  // Add global net labels for the named power input pins in this sheet
798  for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
799  {
800  if( item->Type() != SCH_COMPONENT_T )
801  continue;
802 
803  addImplicitConnections( static_cast<SCH_COMPONENT*>( item ), m_currentSheet->GetScreen(), true );
804  }
805 
806  m_connPoints.clear();
807 
808  // Translate the items.
809  for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
810  {
811  item->SetPosition( item->GetPosition() + translation );
812  item->ClearFlags();
813  }
814 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:467
SCH_LINE * loadWire(wxXmlNode *aWireNode)
const wxSize GetSize() const
Definition: eda_rect.h:101
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:650
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:127
SCH_TEXT * loadPlainText(wxXmlNode *aSchText)
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
SCH_ITEM * Next() const
NODE_MAP MapChildren(wxXmlNode *aCurrentNode)
Function MapChildren provides an easy access to the children of an XML node via their names...
void adjustNetLabels()
Moves net labels that are detached from any wire to the nearest wire
void SetName(const wxString &aName)
Definition: sch_sheet.h:269
void addImplicitConnections(SCH_COMPONENT *aComponent, SCH_SCREEN *aScreen, bool aUpdateSet)
Creates net labels to emulate implicit connections in Eagle.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
void loadSegments(wxXmlNode *aSegmentsNode, const wxString &aNetName, const wxString &aNetClass)
wxPoint Centre() const
Definition: eda_rect.h:60
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:661
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
static EDA_RECT getSheetBbox(SCH_SHEET *aSheet)
Computes a bounding box for all items in a schematic sheet
void loadInstance(wxXmlNode *aInstanceNode)
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:126
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:129
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
std::unordered_map< wxString, wxXmlNode * > NODE_MAP
Definition: eagle_parser.h:48
static wxXmlNode * getChildrenNodes(NODE_MAP &aMap, const wxString &aName)
Definition: eagle_parser.h:58
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent
bool SCH_EAGLE_PLUGIN::loadSymbol ( wxXmlNode *  aSymbolNode,
std::unique_ptr< LIB_PART > &  aPart,
EDEVICE aDevice,
int  aGateNumber,
const wxString &  aGateName 
)
private

Definition at line 1362 of file sch_eagle_plugin.cpp.

References EDEVICE::connects, EPIN::direction, escapeName(), Format(), i, PIN_BIDI, PIN_INPUT, PIN_NC, PIN_OPENCOLLECTOR, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_TRISTATE, PIN_UNSPECIFIED, REFERENCE, LIB_PIN::SetNumber(), EDA_TEXT::SetVisible(), and VALUE.

1364 {
1365  wxString symbolName = aSymbolNode->GetAttribute( "name" );
1366  std::vector<LIB_ITEM*> items;
1367 
1368  wxXmlNode* currentNode = aSymbolNode->GetChildren();
1369 
1370  bool foundName = false;
1371  bool foundValue = false;
1372  bool ispower = false;
1373  int pincount = 0;
1374 
1375  while( currentNode )
1376  {
1377  wxString nodeName = currentNode->GetName();
1378 
1379  if( nodeName == "circle" )
1380  {
1381  aPart->AddDrawItem( loadSymbolCircle( aPart, currentNode, aGateNumber ) );
1382  }
1383  else if( nodeName == "pin" )
1384  {
1385  EPIN ePin = EPIN( currentNode );
1386  std::unique_ptr<LIB_PIN> pin( loadPin( aPart, currentNode, &ePin, aGateNumber ) );
1387  pincount++;
1388 
1389  if( ePin.direction )
1390  {
1391  const std::map<wxString, ELECTRICAL_PINTYPE> pinDirectionsMap =
1392  {
1393  { "sup", PIN_POWER_IN }, { "pas", PIN_PASSIVE },
1394  { "out", PIN_OUTPUT }, { "in", PIN_INPUT },
1395  { "nc", PIN_NC }, { "io", PIN_BIDI },
1396  { "oc", PIN_OPENCOLLECTOR }, { "hiz", PIN_TRISTATE },
1397  { "pwr", PIN_POWER_IN },
1398  };
1399 
1400  pin->SetType( PIN_UNSPECIFIED );
1401 
1402  for( const auto& pinDir : pinDirectionsMap )
1403  {
1404  if( ePin.direction->Lower() == pinDir.first )
1405  {
1406  pin->SetType( pinDir.second );
1407 
1408  if( pinDir.first == "sup" ) // power supply symbol
1409  ispower = true;
1410 
1411  break;
1412  }
1413  }
1414  }
1415 
1416 
1417  if( aDevice->connects.size() != 0 )
1418  {
1419  for( auto connect : aDevice->connects )
1420  {
1421  if( connect.gate == aGateName && pin->GetName() == connect.pin )
1422  {
1423  wxArrayString pads = wxSplit( wxString( connect.pad ), ' ');
1424 
1425  pin->SetPartNumber( aGateNumber );
1426  pin->SetUnit( aGateNumber );
1427  pin->SetName( escapeName( pin->GetName() ) );
1428 
1429  if( pads.GetCount() > 1)
1430  {
1431  pin->SetNumberTextSize( 0 );
1432  }
1433 
1434  for( unsigned i = 0; i < pads.GetCount(); i++)
1435  {
1436  LIB_PIN* apin = new LIB_PIN( *pin );
1437 
1438  wxString padname( pads[i] );
1439  apin->SetNumber( padname );
1440  aPart->AddDrawItem( apin );
1441  }
1442  break;
1443  }
1444  }
1445  }
1446  else
1447  {
1448  pin->SetPartNumber( aGateNumber );
1449  pin->SetUnit( aGateNumber );
1450  pin->SetNumber( wxString::Format( "%i", pincount ) );
1451  aPart->AddDrawItem( pin.release() );
1452  }
1453  }
1454  else if( nodeName == "polygon" )
1455  {
1456  aPart->AddDrawItem( loadSymbolPolyLine( aPart, currentNode, aGateNumber ) );
1457  }
1458  else if( nodeName == "rectangle" )
1459  {
1460  aPart->AddDrawItem( loadSymbolRectangle( aPart, currentNode, aGateNumber ) );
1461  }
1462  else if( nodeName == "text" )
1463  {
1464  std::unique_ptr<LIB_TEXT> libtext( loadSymbolText( aPart, currentNode, aGateNumber ) );
1465 
1466  if( libtext->GetText().Upper() ==">NAME" )
1467  {
1468  LIB_FIELD* field = aPart->GetField( REFERENCE );
1469  loadFieldAttributes( field, libtext.get() );
1470  foundName = true;
1471  }
1472  else if( libtext->GetText().Upper() ==">VALUE" )
1473  {
1474  LIB_FIELD* field = aPart->GetField( VALUE );
1475  loadFieldAttributes( field, libtext.get() );
1476  foundValue = true;
1477  }
1478  else
1479  {
1480  aPart->AddDrawItem( libtext.release() );
1481  }
1482  }
1483  else if( nodeName == "wire" )
1484  {
1485  aPart->AddDrawItem( loadSymbolWire( aPart, currentNode, aGateNumber ) );
1486  }
1487 
1488  /*
1489  * else if( nodeName == "description" )
1490  * {
1491  * }
1492  * else if( nodeName == "dimension" )
1493  * {
1494  * }
1495  * else if( nodeName == "frame" )
1496  * {
1497  * }
1498  */
1499 
1500  currentNode = currentNode->GetNext();
1501  }
1502 
1503  if( foundName == false )
1504  aPart->GetField( REFERENCE )->SetVisible( false );
1505 
1506  if( foundValue == false )
1507  aPart->GetField( VALUE )->SetVisible( false );
1508 
1509  return pincount == 1 ? ispower : false;
1510 }
opt_wxString direction
Definition: eagle_parser.h:736
Field object used in symbol libraries.
Definition: lib_field.h:59
LIB_RECTANGLE * loadSymbolRectangle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aRectNode, int aGateNumber)
Field Reference of part, i.e. "IC21".
Eagle pin element.
Definition: eagle_parser.h:728
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:222
void loadFieldAttributes(LIB_FIELD *aField, const LIB_TEXT *aText) const
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *, EPIN *epin, int aGateNumber)
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
LIB_CIRCLE * loadSymbolCircle(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aCircleNode, int aGateNumber)
LIB_ITEM * loadSymbolWire(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aWireNode, int aGateNumber)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
size_t i
Definition: json11.cpp:597
std::vector< ECONNECT > connects
LIB_TEXT * loadSymbolText(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aLibText, int aGateNumber)
#define VALUE
LIB_POLYLINE * loadSymbolPolyLine(std::unique_ptr< LIB_PART > &aPart, wxXmlNode *aPolygonNode, int aGateNumber)
LIB_ALIAS * SCH_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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

The LIB_PART should be accessed indirectly using the LIB_ALIAS it is associated with.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aAliasNameis the alias 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 alias 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.

Definition at line 93 of file sch_plugin.cpp.

References not_implemented().

Referenced by LIB_EDIT_FRAME::LoadOneSymbol(), SYMBOL_LIB_TABLE::LoadSymbol(), LIB_EDIT_FRAME::OnExportPart(), LIB_EDIT_FRAME::OnImportPart(), and SYMBOL_LIB_TABLE::SaveSymbol().

95 {
96  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
97  not_implemented( this, __FUNCTION__ );
98  return NULL;
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:36
LIB_CIRCLE * SCH_EAGLE_PLUGIN::loadSymbolCircle ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aCircleNode,
int  aGateNumber 
)
private

Definition at line 1513 of file sch_eagle_plugin.cpp.

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

1516 {
1517  // Parse the circle properties
1518  ECIRCLE c( aCircleNode );
1519 
1520  unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( aPart.get() ) );
1521 
1522  circle->SetPosition( wxPoint( c.x.ToSchUnits(), c.y.ToSchUnits() ) );
1523  circle->SetRadius( c.radius.ToSchUnits() );
1524  circle->SetWidth( c.width.ToSchUnits() );
1525  circle->SetUnit( aGateNumber );
1526 
1527  return circle.release();
1528 }
Eagle circle.
Definition: eagle_parser.h:571
LIB_POLYLINE * SCH_EAGLE_PLUGIN::loadSymbolPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aPolygonNode,
int  aGateNumber 
)
private

Definition at line 1630 of file sch_eagle_plugin.cpp.

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

1632 {
1633  std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) );
1634 
1635  EPOLYGON epoly( aPolygonNode );
1636  wxXmlNode* vertex = aPolygonNode->GetChildren();
1637 
1638 
1639  wxPoint pt;
1640 
1641  while( vertex )
1642  {
1643  if( vertex->GetName() == "vertex" ) // skip <xmlattr> node
1644  {
1645  EVERTEX evertex( vertex );
1646  pt = wxPoint( evertex.x.ToSchUnits(), evertex.y.ToSchUnits() );
1647  polyLine->AddPoint( pt );
1648  }
1649 
1650  vertex = vertex->GetNext();
1651  }
1652 
1653  polyLine->SetFillMode( FILLED_SHAPE );
1654  polyLine->SetUnit( aGateNumber );
1655 
1656  return polyLine.release();
1657 }
Eagle vertex.
Definition: eagle_parser.h:746
Eagle polygon, without vertices which are parsed as needed.
Definition: eagle_parser.h:757
LIB_RECTANGLE * SCH_EAGLE_PLUGIN::loadSymbolRectangle ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aRectNode,
int  aGateNumber 
)
private

Definition at line 1531 of file sch_eagle_plugin.cpp.

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

1534 {
1535  ERECT rect( aRectNode );
1536 
1537  unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( aPart.get() ) );
1538 
1539  rectangle->SetPosition( wxPoint( rect.x1.ToSchUnits(), rect.y1.ToSchUnits() ) );
1540  rectangle->SetEnd( wxPoint( rect.x2.ToSchUnits(), rect.y2.ToSchUnits() ) );
1541 
1542  rectangle->SetUnit( aGateNumber );
1543  // Eagle rectangles are filled by definition.
1544  rectangle->SetFillMode( FILLED_SHAPE );
1545 
1546  return rectangle.release();
1547 }
Eagle XML rectangle in binary.
Definition: eagle_parser.h:584
LIB_TEXT * SCH_EAGLE_PLUGIN::loadSymbolText ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aLibText,
int  aGateNumber 
)
private

Definition at line 1765 of file sch_eagle_plugin.cpp.

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

1767 {
1768  std::unique_ptr<LIB_TEXT> libtext( new LIB_TEXT( aPart.get() ) );
1769  ETEXT etext( aLibText );
1770 
1771  libtext->SetUnit( aGateNumber );
1772  libtext->SetPosition( wxPoint( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
1773 
1774  // Eagle supports multiple line text in library symbols. Legacy library symbol text cannot
1775  // contain CRs or LFs.
1776  //
1777  // @todo Split this into multiple text objects and offset the Y position so that it looks
1778  // more like the original Eagle schematic.
1779  wxString text = aLibText->GetNodeContent();
1780  std::replace( text.begin(), text.end(), '\n', '_' );
1781  std::replace( text.begin(), text.end(), '\r', '_' );
1782 
1783  libtext->SetText( text.IsEmpty() ? "~~" : text );
1784  loadTextAttributes( libtext.get(), etext );
1785 
1786  return libtext.release();
1787 }
Define a symbol library graphical text item.
Definition: lib_text.h:44
void loadTextAttributes(EDA_TEXT *aText, const ETEXT &aAttribs) const
Eagle text element.
Definition: eagle_parser.h:646
LIB_ITEM * SCH_EAGLE_PLUGIN::loadSymbolWire ( std::unique_ptr< LIB_PART > &  aPart,
wxXmlNode *  aWireNode,
int  aGateNumber 
)
private

Definition at line 1550 of file sch_eagle_plugin.cpp.

References abs, ConvertArcCenter(), FILLED_SHAPE, wxPoint::x, and wxPoint::y.

1553 {
1554  auto ewire = EWIRE( aWireNode );
1555 
1556  wxPoint begin, end;
1557 
1558  begin.x = ewire.x1.ToSchUnits();
1559  begin.y = ewire.y1.ToSchUnits();
1560  end.x = ewire.x2.ToSchUnits();
1561  end.y = ewire.y2.ToSchUnits();
1562 
1563  // if the wire is an arc
1564  if( ewire.curve )
1565  {
1566  std::unique_ptr<LIB_ARC> arc( new LIB_ARC( aPart.get() ) );
1567  wxPoint center = ConvertArcCenter( begin, end, *ewire.curve * -1 );
1568 
1569  double radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
1570  + ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) ) * 2;
1571 
1572  // this emulates the filled semicircles created by a thick arc with flat ends caps.
1573  if( ewire.width.ToSchUnits() * 2 > radius )
1574  {
1575  wxPoint centerStartVector = begin - center;
1576  wxPoint centerEndVector = end - center;
1577 
1578  centerStartVector.x = centerStartVector.x * ewire.width.ToSchUnits() * 2 / radius;
1579  centerStartVector.y = centerStartVector.y * ewire.width.ToSchUnits() * 2 / radius;
1580 
1581  centerEndVector.x = centerEndVector.x * ewire.width.ToSchUnits() * 2 / radius;
1582  centerEndVector.y = centerEndVector.y * ewire.width.ToSchUnits() * 2 / radius;
1583 
1584  begin = center + centerStartVector;
1585  end = center + centerEndVector;
1586 
1587  radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) )
1588  + ( ( center.y - begin.y ) * ( center.y - begin.y ) ) ) ) * 2;
1589 
1590  arc->SetWidth( 1 );
1591  arc->SetFillMode( FILLED_SHAPE );
1592  }
1593  else
1594  {
1595  arc->SetWidth( ewire.width.ToSchUnits() );
1596  }
1597 
1598  arc->SetPosition( center );
1599 
1600  if( *ewire.curve > 0 )
1601  {
1602  arc->SetStart( begin );
1603  arc->SetEnd( end );
1604  }
1605  else
1606  {
1607  arc->SetStart( end );
1608  arc->SetEnd( begin );
1609  }
1610 
1611  arc->SetRadius( radius );
1612  arc->CalcRadiusAngles();
1613  arc->SetUnit( aGateNumber );
1614 
1615  return (LIB_ITEM*) arc.release();
1616  }
1617  else
1618  {
1619  std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) );
1620 
1621  polyLine->AddPoint( begin );
1622  polyLine->AddPoint( end );
1623  polyLine->SetUnit( aGateNumber );
1624 
1625  return (LIB_ITEM*) polyLine.release();
1626  }
1627 }
#define abs(a)
Definition: auxiliary.h:84
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
wxPoint ConvertArcCenter(const wxPoint &aStart, const wxPoint &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC
Eagle wire.
Definition: eagle_parser.h:500
void SCH_EAGLE_PLUGIN::loadTextAttributes ( EDA_TEXT aText,
const ETEXT aAttribs 
) const
private

Definition at line 1805 of file sch_eagle_plugin.cpp.

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::SetThickness(), and EROT::spin.

1806 {
1807  aText->SetTextSize( aAttribs.ConvertSize() );
1808 
1809  if( aAttribs.ratio )
1810  {
1811  if( aAttribs.ratio.CGet() > 12 )
1812  {
1813  aText->SetBold( true );
1814  aText->SetThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
1815  }
1816  }
1817 
1818  int align = aAttribs.align ? *aAttribs.align : ETEXT::BOTTOM_LEFT;
1819  int degrees = aAttribs.rot ? aAttribs.rot->degrees : 0;
1820  bool mirror = aAttribs.rot ? aAttribs.rot->mirror : false;
1821  bool spin = aAttribs.rot ? aAttribs.rot->spin : false;
1822 
1823  eagleToKicadAlignment( aText, align, degrees, mirror, spin, 0 );
1824 }
bool mirror
Definition: eagle_parser.h:481
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
int GetTextWidth() const
Definition: eda_text.h:231
opt_double ratio
Definition: eagle_parser.h:654
double degrees
Definition: eagle_parser.h:483
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
static void eagleToKicadAlignment(EDA_TEXT *aText, int aEagleAlignment, int aRelDegress, bool aMirror, bool aSpin, int aAbsDegress)
opt_int align
Definition: eagle_parser.h:671
opt_erot rot
Definition: eagle_parser.h:655
bool spin
Definition: eagle_parser.h:482
const T & CGet() const
Function CGet returns a constant reference to the value of the attribute assuming it is available...
Definition: eagle_parser.h:311
wxSize ConvertSize() const
Calculate text size based on font type and size.
void SetBold(bool aBold)
Definition: eda_text.h:185
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
SCH_LINE * SCH_EAGLE_PLUGIN::loadWire ( wxXmlNode *  aWireNode)
private

Definition at line 935 of file sch_eagle_plugin.cpp.

References wxPoint::x, and wxPoint::y.

936 {
937  std::unique_ptr<SCH_LINE> wire( new SCH_LINE );
938 
939  auto ewire = EWIRE( aWireNode );
940 
941  wire->SetLayer( kiCadLayer( ewire.layer ) );
942 
943  wxPoint begin, end;
944 
945  begin.x = ewire.x1.ToSchUnits();
946  begin.y = -ewire.y1.ToSchUnits();
947  end.x = ewire.x2.ToSchUnits();
948  end.y = -ewire.y2.ToSchUnits();
949 
950  wire->SetStartPoint( begin );
951  wire->SetEndPoint( end );
952 
953  m_connPoints[begin].emplace( wire.get() );
954  m_connPoints[end].emplace( wire.get() );
955 
956  return wire.release();
957 }
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
Eagle wire.
Definition: eagle_parser.h:500
std::map< wxPoint, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent
void SCH_EAGLE_PLUGIN::moveLabels ( SCH_ITEM aWire,
const wxPoint aNewEndPoint 
)
private

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

Definition at line 1931 of file sch_eagle_plugin.cpp.

References SCH_ITEM::Next(), SCH_GLOBAL_LABEL_T, SCH_LABEL_T, and TestSegmentHit().

1932 {
1933  for( SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); item; item = item->Next() )
1934  {
1935  if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
1936  {
1937  if( TestSegmentHit( item->GetPosition(), ( (SCH_LINE*) aWire )->GetStartPoint(),
1938  ( (SCH_LINE*) aWire )->GetEndPoint(), 0 ) )
1939  {
1940  item->SetPosition( aNewEndPoint );
1941  }
1942  }
1943  }
1944 }
SCH_SHEET * m_currentSheet
The current sheet of the schematic being loaded..
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
SCH_ITEM * Next() const
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void SCH_PLUGIN::Save ( const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
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.
aSchematicis the class SCH_SCREEN 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.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented in SCH_LEGACY_PLUGIN.

Definition at line 58 of file sch_plugin.cpp.

References not_implemented().

Referenced by SCH_EDIT_FRAME::EditSheet(), and SCH_IO_MGR::Save().

60 {
61  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
62  not_implemented( this, __FUNCTION__ );
63 }
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:36
void SCH_PLUGIN::SaveLibrary ( const wxString &  aFileName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Reimplemented in SCH_LEGACY_PLUGIN.

Definition at line 44 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

45 {
46  not_implemented( this, __FUNCTION__ );
47 }
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:36
void SCH_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_PART aSymbol,
const PROPERTIES aProperties = NULL 
)
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 becaue 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.

Definition at line 102 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE_RESCUER::AddPart(), LIB_EDIT_FRAME::OnExportPart(), LIB_MANAGER::LIB_BUFFER::SaveBuffer(), LIB_EDIT_FRAME::SaveOneSymbol(), and SYMBOL_LIB_TABLE::SaveSymbol().

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:36
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 149 of file sch_plugin.cpp.

150 {
151  // disable all these in another couple of months, after everyone has seen them:
152 #if 1
153  (*aListToAppendTo)["debug_level"] = UTF8( _(
154  "Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
155  ) );
156 
157  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
158  "Regular expression <b>symbol name</b> filter."
159  ) );
160 
161  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
162  "Enable transaction logging. The mere presence of this option turns on the "
163  "logging, no need to set a Value."
164  ) );
165 
166  (*aListToAppendTo)["username"] = UTF8( _(
167  "User name for <b>login</b> to some special library server."
168  ));
169 
170  (*aListToAppendTo)["password"] = UTF8( _(
171  "Password for <b>login</b> to some special library server."
172  ) );
173 #endif
174 
175 #if 1
176  // Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
177  // if and when implemented.
178  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
179  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
180  ) );
181 #endif
182 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73

Member Data Documentation

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

Positions of pins and wire endings mapped to its parent

Definition at line 213 of file sch_eagle_plugin.h.

SCH_SHEET* SCH_EAGLE_PLUGIN::m_currentSheet
private

The current sheet of the schematic being loaded..

Definition at line 182 of file sch_eagle_plugin.h.

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

Definition at line 188 of file sch_eagle_plugin.h.

wxFileName SCH_EAGLE_PLUGIN::m_filename
private

Definition at line 184 of file sch_eagle_plugin.h.

KIWAY* SCH_EAGLE_PLUGIN::m_kiway
private

For creating sub sheets.

Definition at line 180 of file sch_eagle_plugin.h.

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

Definition at line 194 of file sch_eagle_plugin.h.

wxString SCH_EAGLE_PLUGIN::m_libName
private

Library name to save symbols.

Definition at line 185 of file sch_eagle_plugin.h.

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

Map references to missing component units data

Definition at line 238 of file sch_eagle_plugin.h.

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

Definition at line 193 of file sch_eagle_plugin.h.

EPART_MAP SCH_EAGLE_PLUGIN::m_partlist
private

Definition at line 187 of file sch_eagle_plugin.h.

SCH_PLUGIN::SCH_PLUGIN_RELEASER SCH_EAGLE_PLUGIN::m_pi
private

Plugin to create the KiCad symbol library.

Definition at line 190 of file sch_eagle_plugin.h.

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

Library plugin properties.

Definition at line 191 of file sch_eagle_plugin.h.

SCH_SHEET* SCH_EAGLE_PLUGIN::m_rootSheet
private

The root sheet of the schematic being loaded..

Definition at line 181 of file sch_eagle_plugin.h.

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

Segments representing wires for intersection checking

Definition at line 210 of file sch_eagle_plugin.h.

wxString SCH_EAGLE_PLUGIN::m_version
private

Eagle file version.

Definition at line 183 of file sch_eagle_plugin.h.

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

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

Definition at line 198 of file sch_eagle_plugin.h.


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