24#include <boost/algorithm/string/join.hpp>
29#include <wx/mstream.h>
30#include <wx/filename.h>
32#include <wx/textfile.h>
33#include <wx/tokenzr.h>
37#include <fmt/format.h>
71#define T_STYLE "style"
73#define T_COLORA "rgba"
74#define T_WIDTH "width"
106 const unsigned PROGRESS_DELTA = 250;
128 const std::map<std::string, UTF8>* aProperties )
130 wxASSERT( !aFileName || aSchematic !=
nullptr );
133 wxFileName fn = aFileName;
138 wxASSERT( fn.IsAbsolute() );
147 if( !normedFn.IsAbsolute() )
149 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
150 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
164 init( aSchematic, aProperties );
166 if( aAppendToMe ==
nullptr )
169 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
170 newSheet->SetFileName( aFileName );
175 sheet = newSheet.release();
181 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
207 fileName.SetExt(
"sch" );
209 if( !fileName.IsAbsolute() )
220 m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
258 wxCHECK2( aItem->Type() ==
SCH_SHEET_T,
continue );
259 auto sheet =
static_cast<SCH_SHEET*
>( aItem );
307 char* line = reader.
Line();
309 while( *line ==
' ' )
324 "Cannot call SCH_IO_KICAD_LEGACY::LoadContent() without setting root sheet." );
330 char* line = aReader.
Line();
332 while( *line ==
' ' )
375 const char* line = aReader.
ReadLine();
377 if( !line || !
strCompare(
"Eeschema Schematic File Version", line, &line ) )
379 m_error.Printf(
_(
"'%s' does not appear to be an Eeschema file." ),
400 line = aReader.
Line();
402 while( *line ==
' ' )
415 wxASSERT( aScreen !=
nullptr );
418 const char* line = aReader.
Line();
423 wxCHECK_RET(
strCompare(
"$Descr", line, &line ),
"Invalid sheet description" );
430 int pagew =
parseInt( aReader, line, &line );
431 int pageh =
parseInt( aReader, line, &line );
440 wxString orientation;
446 if( orientation ==
"portrait" )
452 while( line !=
nullptr )
459 line = aReader.
Line();
486 else if(
strCompare(
"Comment1", line, &line ) )
491 else if(
strCompare(
"Comment2", line, &line ) )
496 else if(
strCompare(
"Comment3", line, &line ) )
501 else if(
strCompare(
"Comment4", line, &line ) )
506 else if(
strCompare(
"Comment5", line, &line ) )
511 else if(
strCompare(
"Comment6", line, &line ) )
516 else if(
strCompare(
"Comment7", line, &line ) )
521 else if(
strCompare(
"Comment8", line, &line ) )
526 else if(
strCompare(
"Comment9", line, &line ) )
544 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
546 const char* line = aReader.
ReadLine();
548 while( line !=
nullptr )
556 sheet->SetPosition( position );
562 sheet->SetSize( size );
569 if(
text !=
"00000000" )
572 else if( *line ==
'F' )
578 int legacy_field_id =
parseInt( aReader, line, &line );
580 if( legacy_field_id == 0 || legacy_field_id == 1 )
593 std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
595 sheetPin->SetNumber( legacy_field_id );
602 if( line ==
nullptr )
605 switch(
parseChar( aReader, line, &line ) )
615 switch(
parseChar( aReader, line, &line ) )
628 sheetPin->SetPosition( position );
632 sheetPin->SetTextSize(
VECTOR2I( size, size ) );
634 sheet->AddPin( sheetPin.release() );
640 return sheet.release();
654 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
657 const char* line = aReader.
Line();
659 wxCHECK(
strCompare(
"$Bitmap", line, &line ),
nullptr );
663 while( line !=
nullptr )
671 bitmap->SetPosition( position );
675 auto scalefactor =
parseDouble( aReader, line, &line );
681 if( !std::isnormal( scalefactor ) )
688 wxMemoryBuffer buffer;
695 line = aReader.
Line();
716 int len = strlen( line );
718 for( ; len > 0 && !isspace( *line ) &&
'$' != *line; len -= 3, line += 3 )
722 if( sscanf( line,
"%X", &value ) == 1 )
723 buffer.AppendByte( (
char) value );
729 if( line ==
nullptr )
734 return bitmap.release();
746 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
748 const char* line = aReader.
Line();
750 wxCHECK(
strCompare(
"Connection", line, &line ),
nullptr );
760 junction->SetPosition( position );
762 return junction.release();
768 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
770 const char* line = aReader.
Line();
772 wxCHECK(
strCompare(
"NoConn", line, &line ),
nullptr );
782 no_connect->SetPosition( position );
784 return no_connect.release();
790 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
792 const char* line = aReader.
Line();
794 wxCHECK(
strCompare(
"Wire", line, &line ),
nullptr );
826 wire->SetLineWidth( size );
832 if( buf == wxT(
"solid" ) )
834 else if( buf == wxT(
"dashed" ) )
836 else if( buf == wxT(
"dash_dot" ) )
838 else if( buf == wxT(
"dotted" ) )
847 wxString prm, keyword;
848 keyword = buf.BeforeLast(
'(', &prm );
852 long color[4] = { 0 };
858 prm.ToLong( &color[ii] );
862 int prm_count = ( keyword ==
T_COLORA ) ? 4 : 3;
867 for(; ii < prm_count && !
is_eol( *line ); ii++ )
869 color[ii] =
parseInt( aReader, line, &line );
872 if( *line ==
',' || *line ==
' ')
876 wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
891 wire->SetStartPoint( begin );
892 wire->SetEndPoint(
end );
894 return wire.release();
900 const char* line = aReader.
Line();
902 wxCHECK(
strCompare(
"Entry", line, &line ),
nullptr );
904 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
908 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
911 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Line'", aReader, line );
915 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
918 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Bus'", aReader, line );
938 busEntry->SetPosition( pos );
939 busEntry->SetSize( size );
941 return busEntry.release();
959 const char* line = aReader.
Line();
962 wxCHECK(
strCompare(
"Text", line, &line ),
nullptr );
972 else if(
strCompare(
"HLabel", line, &line ) )
976 else if(
strCompare(
"GLabel", line, &line ) )
994 std::unique_ptr<SCH_TEXT>
text;
1005 int spinStyle =
parseInt( aReader, line, &line );
1017 if( spinStyle == 0 )
1019 else if( spinStyle == 2 )
1037 [ &line ](
const auto& it )
1039 return strCompare( it.second, line, &line );
1043 label->
SetShape( resultIt->first );
1085 text->SetItalicFlag(
true );
1093 penWidth =
parseInt( aReader, line, &line );
1097 text->SetBoldFlag( penWidth != 0 );
1098 text->SetTextThickness( 0 );
1103 tmp = strtok( tmp,
"\r\n" );
1108 size_t i = val.find( wxT(
"\\n" ) );
1110 if( i == wxString::npos )
1114 val.insert( i, wxT(
"\n" ) );
1119 return text.release();
1125 const char* line = aReader.
Line();
1127 wxCHECK(
strCompare(
"$Comp", line, &line ),
nullptr );
1129 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1133 while( line !=
nullptr )
1139 wxString utf8Line = wxString::FromUTF8( line );
1140 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
1142 if( tokens.CountTokens() < 2 )
1148 libName = tokens.GetNextToken();
1149 libName.Replace(
"~",
" " );
1157 libId.
Parse( libName,
true );
1161 symbol->SetLibId( libId );
1163 wxString refDesignator = tokens.GetNextToken();
1165 refDesignator.Replace(
"~",
" " );
1167 wxString prefix = refDesignator;
1169 while( prefix.Length() )
1171 if( ( prefix.Last() <
'0' || prefix.Last() >
'9') && prefix.Last() !=
'?' )
1174 prefix.RemoveLast();
1178 prefix.Trim(
true );
1179 prefix.Trim(
false );
1181 if( prefix.IsEmpty() )
1182 symbol->SetPrefix( wxString(
"U" ) );
1184 symbol->SetPrefix( prefix );
1190 int unit =
parseInt( aReader, line, &line );
1201 symbol->SetUnit( unit );
1204 int bodyStyle =
parseInt( aReader, line, &line );
1206 if( bodyStyle == 0 )
1215 symbol->SetBodyStyle( bodyStyle );
1220 if(
text !=
"00000000" )
1229 symbol->SetPosition( pos );
1236 if( strncasecmp(
strCompare, line, len ) != 0 )
1240 wxString pathStr, reference, unit;
1248 if(
path.size() > 0 )
1260 if( strncasecmp(
strCompare, line, len ) != 0 )
1269 if( strncasecmp(
strCompare, line, len ) != 0 )
1277 if( !unit.ToLong( &tmp, 10 ) )
1283 symbol->AddHierarchicalReference(
path, reference, (
int)tmp );
1288 int legacy_field_id =
parseInt( aReader, line, &line );
1294 char orientation =
parseChar( aReader, line, &line );
1300 pos.
y = -( pos.
y - symbol->GetY() ) + symbol->GetY();
1303 int attributes =
parseHex( aReader, line, &line );
1308 switch( legacy_field_id )
1324 char hjustify =
parseChar( aReader, line, &line );
1331 if( hjustify ==
'L' )
1333 else if( hjustify ==
'R' )
1335 else if( hjustify !=
'C' )
1336 SCH_PARSE_ERROR(
"symbol field text horizontal justification must be "
1337 "L, R, or C", aReader, line );
1341 if( textAttrs[0] ==
'T' )
1343 else if( textAttrs[0] ==
'B' )
1345 else if( textAttrs[0] !=
'C' )
1347 "B, T, or C", aReader, line );
1350 if( textAttrs.Length() > 1 )
1352 if( textAttrs.Length() != 3 )
1354 SCH_PARSE_ERROR(
_(
"symbol field text attributes must be 3 characters wide" ),
1358 if( textAttrs[1] ==
'I' )
1362 else if( textAttrs[1] !=
'N' )
1364 SCH_PARSE_ERROR(
"symbol field text italics indicator must be I or N",
1368 if( textAttrs[2] ==
'B' )
1372 else if( textAttrs[2] !=
'N' )
1385 if( orientation ==
'H' )
1387 else if( orientation ==
'V' )
1390 SCH_PARSE_ERROR(
"symbol field orientation must be H or V", aReader, line );
1392 if(
name.IsEmpty() )
1414 instance.
m_Unit = symbol->GetUnit();
1415 symbol->AddHierarchicalReference( instance );
1422 symbol->AddHierarchicalReference( tmpInstance );
1428 symbol->ClearFlags();
1429 return symbol.release();
1446 transform.
x1 =
parseInt( aReader, line, &line );
1448 if( transform.
x1 < -1 || transform.
x1 > 1 )
1449 SCH_PARSE_ERROR(
"invalid symbol X1 transform value", aReader, line );
1451 transform.
y1 = -
parseInt( aReader, line, &line );
1453 if( transform.
y1 < -1 || transform.
y1 > 1 )
1454 SCH_PARSE_ERROR(
"invalid symbol Y1 transform value", aReader, line );
1456 transform.
x2 =
parseInt( aReader, line, &line );
1458 if( transform.
x2 < -1 || transform.
x2 > 1 )
1459 SCH_PARSE_ERROR(
"invalid symbol X2 transform value", aReader, line );
1461 transform.
y2 = -
parseInt( aReader, line, &line );
1463 if( transform.
y2 < -1 || transform.
y2 > 1 )
1464 SCH_PARSE_ERROR(
"invalid symbol Y2 transform value", aReader, line );
1466 symbol->SetTransform( transform );
1482 auto busAlias = std::make_shared<BUS_ALIAS>();
1483 const char* line = aReader.
Line();
1485 wxCHECK(
strCompare(
"BusAlias", line, &line ),
nullptr );
1489 busAlias->SetName( buf );
1491 while( *line !=
'\0' )
1496 if( !buf.IsEmpty() )
1497 busAlias->AddMember( buf );
1506 const std::map<std::string, UTF8>* aProperties )
1508 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET object." );
1509 wxCHECK_RET( !aFileName.IsEmpty(),
"No schematic file name defined." );
1511 init( aSchematic, aProperties );
1513 wxFileName fn = aFileName;
1517 wxASSERT( fn.IsAbsolute() );
1532 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET* object." );
1533 wxCHECK_RET(
m_schematic !=
nullptr,
"NULL SCHEMATIC* object." );
1544 m_out->Print( 0,
"EELAYER END\n" );
1558 m_out->Print( 0,
"encoding utf-8\n" );
1573 m_out->Print( 0,
"$EndDescr\n" );
1577 std::multiset<
SCH_ITEM*,
decltype( cmp )> save_map( cmp );
1580 save_map.insert( item );
1583 for(
auto& item : save_map )
1585 switch( item->Type() )
1616 wxASSERT(
"Unexpected schematic object type in SCH_IO_KICAD_LEGACY::Format()" );
1620 m_out->Print( 0,
"$EndSCHEMATC\n" );
1628 for(
unsigned i = 0; i < aSelection->
GetSize(); ++i )
1632 switch( item->
Type() )
1663 wxASSERT(
"Unexpected schematic object type in SCH_IO_KICAD_LEGACY::Format()" );
1690 if( symbol_name.size() )
1699 m_out->Print( 0,
"$Comp\n" );
1700 m_out->Print( 0,
"L %s %s\n", name2.c_str(), name1.c_str() );
1703 m_out->Print( 0,
"U %d %d %8.8X\n",
1709 m_out->Print( 0,
"P %d %d\n",
1729 wxString
path =
"/";
1732 for(
int i = 1; i < (int) instance.m_Path.size(); ++i )
1733 path += instance.m_Path[i].AsLegacyTimestampString() +
"/";
1735 m_out->Print( 0,
"AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1737 TO_UTF8( instance.m_Reference ),
1743 int legacy_field_id = 0;
1749 m_out->Print( 0,
"\t%-4d %-4d %-4d\n", aSymbol->
GetUnit(),
1755 m_out->Print( 0,
"\t%-4d %-4d %-4d %-4d\n",
1756 transform.
x1, transform.
y1, transform.
x2, transform.
y2 );
1757 m_out->Print( 0,
"$EndComp\n" );
1763 char hjustify =
'C';
1770 char vjustify =
'C';
1777 m_out->Print( 0,
"F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1787 aField->
IsBold() ?
'B' :
'N' );
1793 m_out->Print( 0,
"\n" );
1803 wxCHECK_RET(
image !=
nullptr,
"wxImage* is NULL" );
1805 m_out->Print( 0,
"$Bitmap\n" );
1806 m_out->Print( 0,
"Pos %-4d %-4d\n",
1810 m_out->Print( 0,
"Data\n" );
1812 wxMemoryOutputStream stream;
1814 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1817 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1818 char* begin = (
char*) buffer->GetBufferStart();
1820 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1826 m_out->Print( 0,
"\n" );
1829 m_out->Print( 0,
"%2.2X ", *begin & 0xFF );
1832 m_out->Print( 0,
"\nEndData\n" );
1833 m_out->Print( 0,
"$EndBitmap\n" );
1839 wxCHECK_RET( aSheet !=
nullptr,
"SCH_SHEET* is NULL" );
1841 m_out->Print( 0,
"$Sheet\n" );
1842 m_out->Print( 0,
"S %-4d %-4d %-4d %-4d\n",
1853 if( !sheetName->
GetText().IsEmpty() )
1855 m_out->Print( 0,
"F0 %s %d\n",
1860 if( !fileName->
GetText().IsEmpty() )
1862 m_out->Print( 0,
"F1 %s %d\n",
1871 switch(
pin->GetSide() )
1880 switch(
pin->GetShape() )
1890 m_out->Print( 0,
"F%d %s %c %c %-3d %-3d %-3d\n",
1898 m_out->Print( 0,
"$EndSheet\n" );
1904 wxCHECK_RET( aJunction !=
nullptr,
"SCH_JUNCTION* is NULL" );
1906 m_out->Print( 0,
"Connection ~ %-4d %-4d\n",
1914 wxCHECK_RET( aNoConnect !=
nullptr,
"SCH_NOCONNECT* is NULL" );
1916 m_out->Print( 0,
"NoConn ~ %-4d %-4d\n",
1924 wxCHECK_RET( aBusEntry !=
nullptr,
"SCH_BUS_ENTRY_BASE* is NULL" );
1928 m_out->Print( 0,
"Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1936 m_out->Print( 0,
"Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1947 wxCHECK_RET( aLine !=
nullptr,
"SCH_LINE* is NULL" );
1949 const char* layer =
"Notes";
1950 const char* width =
"Line";
1957 m_out->Print( 0,
"Wire %s %s", layer, width );
1967 m_out->Print( 0,
" %s %s",
1975 m_out->Print( 0,
"\n" );
1977 m_out->Print( 0,
"\t%-4d %-4d %-4d %-4d",
1983 m_out->Print( 0,
"\n");
1989 wxCHECK_RET( aText !=
nullptr,
"SCH_TEXT* is NULL" );
1991 const char* italics =
"~";
1992 const char* textType =
"Notes";
2007 text.Replace( wxT(
"\n" ), wxT(
"\\n" ) );
2015 for(
unsigned ii = 0; ii <
text.Len(); )
2017 if(
text[ii] == 0x0A ||
text[ii] == 0x0D )
2018 text.erase( ii, 1 );
2033 spinStyle =
static_cast<int>( label->GetSpinStyle() );
2035 if( spinStyle == 0 )
2037 else if( spinStyle == 2 )
2041 m_out->Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2054 wxCHECK_RET( shapeLabelIt !=
sheetLabelNames.end(),
"Shape not found in names list" );
2056 m_out->Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2061 shapeLabelIt->second,
2070 wxCHECK_RET( aAlias !=
nullptr,
"BUS_ALIAS* is NULL" );
2072 wxString members = boost::algorithm::join( aAlias->Members(),
" " );
2074 m_out->Print( 0,
"BusAlias %s %s\n",
2080 const std::map<std::string, UTF8>* aProperties )
2098 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2114 return m_cache->GetModifyHash();
2122 const wxString& aLibraryPath,
2123 const std::map<std::string, UTF8>* aProperties )
2127 cacheLib( aLibraryPath, aProperties );
2131 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2133 if( !powerSymbolsOnly || it->second->IsGlobalPower() )
2134 aSymbolNameList.Add( it->first );
2140 const wxString& aLibraryPath,
2141 const std::map<std::string, UTF8>* aProperties )
2145 cacheLib( aLibraryPath, aProperties );
2149 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2151 if( !powerSymbolsOnly || it->second->IsGlobalPower() )
2152 aSymbolList.push_back( it->second );
2158 const wxString& aSymbolName,
2159 const std::map<std::string, UTF8>* aProperties )
2161 cacheLib( aLibraryPath, aProperties );
2163 LIB_SYMBOL_MAP::const_iterator it =
m_cache->m_symbols.find( aSymbolName );
2165 if( it ==
m_cache->m_symbols.end() )
2173 const std::map<std::string, UTF8>* aProperties )
2175 cacheLib( aLibraryPath, aProperties );
2177 m_cache->AddSymbol( std::move( aSymbol ) );
2185 const std::map<std::string, UTF8>* aProperties )
2187 cacheLib( aLibraryPath, aProperties );
2189 m_cache->DeleteSymbol( aSymbolName );
2197 const std::map<std::string, UTF8>* aProperties )
2199 if( wxFileExists( aLibraryPath ) )
2200 THROW_IO_ERRORF(
_(
"Symbol library '%s' already exists." ), aLibraryPath.GetData() );
2211 const std::map<std::string, UTF8>* aProperties )
2213 wxFileName fn = aLibraryPath;
2215 if( !fn.FileExists() )
2220 if( wxRemove( aLibraryPath ) )
2221 THROW_IO_ERRORF(
_(
"Symbol library '%s' cannot be deleted." ), aLibraryPath.GetData() );
2234 const std::map<std::string, UTF8>* aProperties )
2239 wxString oldFileName =
m_cache->GetFileName();
2241 if( !
m_cache->IsFile( aLibraryPath ) )
2243 m_cache->SetFileName( aLibraryPath );
2249 m_cache->SetFileName( oldFileName );
constexpr EDA_IU_SCALE schIUScale
void SetPageCount(int aPageCount)
int GetVirtualPageNumber() const
void SetVirtualPageNumber(int aPageNumber)
This class handle bitmap images in KiCad.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
bool IsHorizontal() const
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
virtual VECTOR2I GetTextSize() const
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
virtual void SetTextPos(const VECTOR2I &aPoint)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual int GetTextWidth() const
GR_TEXT_H_ALIGN_T GetHorizJustify() const
void SetBoldFlag(bool aBold)
Set only the bold flag, without changing the font.
virtual void SetVisible(bool aVisible)
virtual EDA_ANGLE GetTextAngle() const
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual int GetTextThickness() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
EE_TYPE OfType(KICAD_T aType) const
A LINE_READER that reads from an open file.
void Rewind()
Rewind the file and resets the line number back to zero.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
wxString ToCSSString() const
wxString AsLegacyTimestampString() const
timestamp_t AsLegacyTimestamp() const
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Define a library symbol object.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
Describe the page size and margins of a paper page on which to eventually print or plot.
wxString GetTypeAsString() const
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
bool SetType(PAGE_SIZE_TYPE aPageSize, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
void SetHeightMils(double aHeightInMils)
double GetHeightMils() const
double GetWidthMils() const
void SetWidthMils(double aWidthInMils)
const PAGE_SIZE_TYPE & GetType() const
virtual const wxString GetProjectPath() const
Return the full path of the project.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
Holds all the data relating to one schematic.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
bool HasProjectBusAliases() const
Object to handle a bitmap image that can be inserted in a schematic.
VECTOR2I GetPosition() const override
REFERENCE_IMAGE & GetReferenceImage()
Base class for a bus or wire entry.
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
VECTOR2I GetLibPosition() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
A cache assistant for KiCad legacy symbol libraries.
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
wxString m_error
For throwing exceptions or errors on partial schematic loads.
SCH_SHEET * m_currentSheet
The sheet currently being loaded.
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
void saveText(SCH_TEXT *aText)
void saveJunction(SCH_JUNCTION *aJunction)
virtual ~SCH_IO_KICAD_LEGACY()
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void saveField(SCH_FIELD *aField, int aLegacyId)
bool isBuffering(const std::map< std::string, UTF8 > *aProperties)
void Format(SCH_SHEET *aSheet)
void loadHierarchy(SCH_SHEET *aSheet)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
int GetModifyHash() const override
Return the modification hash from the library cache.
wxString m_path
Root project path for loading child sheets.
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
void init(SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
initialize PLUGIN like a constructor would.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static void FormatPart(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
bool m_appending
Indicate if we are appending the loaded schemitic or loading a full project.
int m_version
Version of file being loaded.
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
void saveLine(SCH_LINE *aLine)
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
void saveSymbol(SCH_SYMBOL *aSymbol)
SCH_SHEET * loadSheet(LINE_READER &aReader)
SCH_LINE * loadWire(LINE_READER &aReader)
void SaveSymbol(const wxString &aLibraryPath, std::unique_ptr< LIB_SYMBOL > aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
unsigned m_lineCount
for progress reporting
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void SaveLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_IO_KICAD_LEGACY_LIB_CACHE * m_cache
unsigned m_lastProgressLine
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
void cacheLib(const wxString &aLibraryFileName, const std::map< std::string, UTF8 > *aProperties)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
void saveBitmap(const SCH_BITMAP &aBitmap)
void saveSheet(SCH_SHEET *aSheet)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void CreateLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
bool writeDocFile(const std::map< std::string, UTF8 > *aProperties)
LINE_READER * m_lineReader
for progress reporting
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
SCH_IO(const wxString &aName)
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
VECTOR2I GetPosition() const override
SPIN_STYLE GetSpinStyle() const
void SetShape(LABEL_FLAG_SHAPE aShape)
LABEL_FLAG_SHAPE GetShape() const
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
virtual STROKE_PARAMS GetStroke() const override
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
VECTOR2I GetPosition() const override
const PAGE_INFO & GetPageSettings() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Add a bus alias definition.
void SetPageSettings(const PAGE_INFO &aPageSettings)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
void SetFileReadOnly(bool aIsReadOnly)
void SetFileExists(bool aFileExists)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
wxString GetFileName() const
Return the filename corresponding to this sheet.
void SyncUuidToScreen()
Take the identity of the screen this sheet owns.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
std::vector< SCH_SHEET_PIN * > & GetPins()
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
const LIB_ID & GetLibId() const override
wxString GetPrefix() const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
virtual unsigned int GetSize() const override
Return the number of stored items.
Simple container to manage line stroke parameters.
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
static wxString GetLineStyleToken(LINE_STYLE aStyle)
static const char * PropPowerSymsOnly
const TRANSFORM & GetTransform() const
Hold the information shown in the lower right corner of a plot, printout, or editing view.
const wxString & GetCompany() const
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
const wxString & GetRevision() const
void SetTitle(const wxString &aTitle)
const wxString & GetDate() const
const wxString & GetComment(int aIdx) const
void SetCompany(const wxString &aCompany)
const wxString & GetTitle() const
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
#define SCHEMATIC_HEAD_STRING
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
#define SCH_LAYER_ID_COUNT
SCH_LAYER_ID
Eeschema drawing layers.
Definition for symbol library class.
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
const std::map< LABEL_FLAG_SHAPE, const char * > sheetLabelNames
int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
bool strCompare(const char *aString, const char *aLine, const char **aOutput)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define SCH_PARSE_ERROR(text, reader, pos)
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
A simple container for schematic symbol instance information.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol library map sorted by the symbol name.
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.