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>
71#define T_STYLE "style"
73#define T_COLORA "rgba"
74#define T_WIDTH "width"
79 m_lineReader( nullptr ),
80 m_lastProgressLine( 0 ),
106 const unsigned PROGRESS_DELTA = 250;
128 const std::map<std::string, UTF8>* aProperties )
130 wxASSERT( !aFileName || aSchematic !=
nullptr );
135 wxFileName fn = aFileName;
140 wxASSERT( fn.IsAbsolute() );
149 if( !normedFn.IsAbsolute() )
151 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
152 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
166 init( aSchematic, aProperties );
168 if( aAppendToMe ==
nullptr )
171 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
172 newSheet->SetFileName( aFileName );
177 sheet = newSheet.release();
183 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
209 fileName.SetExt(
"sch" );
211 if( !fileName.IsAbsolute() )
260 wxCHECK2( aItem->Type() ==
SCH_SHEET_T,
continue );
261 auto sheet =
static_cast<SCH_SHEET*
>( aItem );
309 char* line = reader.
Line();
311 while( *line ==
' ' )
326 "Cannot call SCH_IO_KICAD_LEGACY::LoadContent() without setting root sheet." );
332 char* line = aReader.
Line();
334 while( *line ==
' ' )
371 const char* line = aReader.
ReadLine();
373 if( !line || !
strCompare(
"Eeschema Schematic File Version", line, &line ) )
375 m_error.Printf(
_(
"'%s' does not appear to be an Eeschema file." ),
396 line = aReader.
Line();
398 while( *line ==
' ' )
411 wxASSERT( aScreen !=
nullptr );
414 const char* line = aReader.
Line();
419 wxCHECK_RET(
strCompare(
"$Descr", line, &line ),
"Invalid sheet description" );
426 int pagew =
parseInt( aReader, line, &line );
427 int pageh =
parseInt( aReader, line, &line );
436 wxString orientation;
442 if( orientation ==
"portrait" )
448 while( line !=
nullptr )
455 line = aReader.
Line();
482 else if(
strCompare(
"Comment1", line, &line ) )
487 else if(
strCompare(
"Comment2", line, &line ) )
492 else if(
strCompare(
"Comment3", line, &line ) )
497 else if(
strCompare(
"Comment4", line, &line ) )
502 else if(
strCompare(
"Comment5", line, &line ) )
507 else if(
strCompare(
"Comment6", line, &line ) )
512 else if(
strCompare(
"Comment7", line, &line ) )
517 else if(
strCompare(
"Comment8", line, &line ) )
522 else if(
strCompare(
"Comment9", line, &line ) )
540 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
542 const char* line = aReader.
ReadLine();
544 while( line !=
nullptr )
552 sheet->SetPosition( position );
558 sheet->SetSize( size );
565 if(
text !=
"00000000" )
568 else if( *line ==
'F' )
574 int legacy_field_id =
parseInt( aReader, line, &line );
576 if( legacy_field_id == 0 || legacy_field_id == 1 )
581 SCH_FIELD* field = sheet->GetField( legacy_field_id == 0 ? FIELD_T::SHEET_NAME
582 : FIELD_T::SHEET_FILENAME );
589 std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
591 sheetPin->SetNumber( legacy_field_id );
598 if( line ==
nullptr )
601 switch(
parseChar( aReader, line, &line ) )
603 case 'I': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
break;
604 case 'O': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
break;
605 case 'B': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
break;
606 case 'T': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
break;
607 case 'U': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
break;
611 switch(
parseChar( aReader, line, &line ) )
613 case 'R': sheetPin->SetSide( SHEET_SIDE::RIGHT );
break;
614 case 'T': sheetPin->SetSide( SHEET_SIDE::TOP );
break;
615 case 'B': sheetPin->SetSide( SHEET_SIDE::BOTTOM );
break;
616 case 'L': sheetPin->SetSide( SHEET_SIDE::LEFT );
break;
625 sheetPin->SetPosition( position );
629 sheetPin->SetTextSize(
VECTOR2I( size, size ) );
631 sheet->AddPin( sheetPin.release() );
637 return sheet.release();
651 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
654 const char* line = aReader.
Line();
656 wxCHECK(
strCompare(
"$Bitmap", line, &line ),
nullptr );
660 while( line !=
nullptr )
668 bitmap->SetPosition( position );
672 auto scalefactor =
parseDouble( aReader, line, &line );
678 if( !std::isnormal( scalefactor ) )
685 wxMemoryBuffer buffer;
692 line = aReader.
Line();
713 int len = strlen( line );
715 for( ; len > 0 && !isspace( *line ) &&
'$' != *line; len -= 3, line += 3 )
719 if( sscanf( line,
"%X", &value ) == 1 )
720 buffer.AppendByte( (
char) value );
726 if( line ==
nullptr )
731 return bitmap.release();
743 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
745 const char* line = aReader.
Line();
747 wxCHECK(
strCompare(
"Connection", line, &line ),
nullptr );
757 junction->SetPosition( position );
759 return junction.release();
765 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
767 const char* line = aReader.
Line();
769 wxCHECK(
strCompare(
"NoConn", line, &line ),
nullptr );
779 no_connect->SetPosition( position );
781 return no_connect.release();
787 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
789 const char* line = aReader.
Line();
791 wxCHECK(
strCompare(
"Wire", line, &line ),
nullptr );
807 wire->SetLineStyle( LINE_STYLE::DASH );
823 wire->SetLineWidth( size );
829 if( buf == wxT(
"solid" ) )
830 wire->SetLineStyle( LINE_STYLE::SOLID );
831 else if( buf == wxT(
"dashed" ) )
832 wire->SetLineStyle( LINE_STYLE::DASH );
833 else if( buf == wxT(
"dash_dot" ) )
834 wire->SetLineStyle( LINE_STYLE::DASHDOT );
835 else if( buf == wxT(
"dotted" ) )
836 wire->SetLineStyle( LINE_STYLE::DOT );
844 wxString prm, keyword;
845 keyword = buf.BeforeLast(
'(', &prm );
849 long color[4] = { 0 };
855 prm.ToLong( &
color[ii] );
859 int prm_count = ( keyword ==
T_COLORA ) ? 4 : 3;
864 for(; ii < prm_count && !
is_eol( *line ); ii++ )
869 if( *line ==
',' || *line ==
' ')
888 wire->SetStartPoint( begin );
889 wire->SetEndPoint(
end );
891 return wire.release();
897 const char* line = aReader.
Line();
899 wxCHECK(
strCompare(
"Entry", line, &line ),
nullptr );
901 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
905 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
908 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Line'", aReader, line );
912 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
915 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Bus'", aReader, line );
935 busEntry->SetPosition( pos );
936 busEntry->SetSize( size );
938 return busEntry.release();
956 const char* line = aReader.
Line();
959 wxCHECK(
strCompare(
"Text", line, &line ),
nullptr );
969 else if(
strCompare(
"HLabel", line, &line ) )
973 else if(
strCompare(
"GLabel", line, &line ) )
991 std::unique_ptr<SCH_TEXT>
text;
1002 int spinStyle =
parseInt( aReader, line, &line );
1014 if( spinStyle == 0 )
1016 else if( spinStyle == 2 )
1034 [ &line ](
const auto& it )
1036 return strCompare( it.second, line, &line );
1040 label->
SetShape( resultIt->first );
1082 text->SetItalicFlag(
true );
1090 penWidth =
parseInt( aReader, line, &line );
1093 text->SetBoldFlag( penWidth != 0 );
1099 tmp = strtok( tmp,
"\r\n" );
1104 size_t i = val.find( wxT(
"\\n" ) );
1106 if( i == wxString::npos )
1110 val.insert( i, wxT(
"\n" ) );
1115 return text.release();
1121 const char* line = aReader.
Line();
1123 wxCHECK(
strCompare(
"$Comp", line, &line ),
nullptr );
1125 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1129 while( line !=
nullptr )
1135 wxString utf8Line = wxString::FromUTF8( line );
1136 wxStringTokenizer tokens( utf8Line,
" \r\n\t" );
1138 if( tokens.CountTokens() < 2 )
1142 libName = tokens.GetNextToken();
1143 libName.Replace(
"~",
" " );
1151 libId.
Parse( libName,
true );
1155 symbol->SetLibId( libId );
1157 wxString refDesignator = tokens.GetNextToken();
1159 refDesignator.Replace(
"~",
" " );
1161 wxString prefix = refDesignator;
1163 while( prefix.Length() )
1165 if( ( prefix.Last() <
'0' || prefix.Last() >
'9') && prefix.Last() !=
'?' )
1168 prefix.RemoveLast();
1172 prefix.Trim(
true );
1173 prefix.Trim(
false );
1175 if( prefix.IsEmpty() )
1176 symbol->SetPrefix( wxString(
"U" ) );
1178 symbol->SetPrefix( prefix );
1184 int unit =
parseInt( aReader, line, &line );
1195 symbol->SetUnit( unit );
1198 int bodyStyle =
parseInt( aReader, line, &line );
1200 if( bodyStyle == 0 )
1209 symbol->SetBodyStyle( bodyStyle );
1214 if(
text !=
"00000000" )
1223 symbol->SetPosition( pos );
1230 if( strncasecmp(
strCompare, line, len ) != 0 )
1234 wxString pathStr, reference, unit;
1242 if(
path.size() > 0 )
1254 if( strncasecmp(
strCompare, line, len ) != 0 )
1263 if( strncasecmp(
strCompare, line, len ) != 0 )
1271 if( !unit.ToLong( &tmp, 10 ) )
1277 symbol->AddHierarchicalReference(
path, reference, (
int)tmp );
1278 symbol->GetField( FIELD_T::REFERENCE )->SetText( reference );
1282 int legacy_field_id =
parseInt( aReader, line, &line );
1288 char orientation =
parseChar( aReader, line, &line );
1294 pos.
y = -( pos.
y - symbol->GetY() ) + symbol->GetY();
1297 int attributes =
parseHex( aReader, line, &line );
1302 switch( legacy_field_id )
1304 case 0: field = symbol->GetField( FIELD_T::REFERENCE );
break;
1305 case 1: field = symbol->GetField( FIELD_T::VALUE );
break;
1306 case 2: field = symbol->GetField( FIELD_T::FOOTPRINT );
break;
1307 case 3: field = symbol->GetField( FIELD_T::DATASHEET );
break;
1310 field = symbol->AddField(
SCH_FIELD( { 0, 0 }, FIELD_T::USER, symbol.get() ) );
1318 char hjustify =
parseChar( aReader, line, &line );
1325 if( hjustify ==
'L' )
1327 else if( hjustify ==
'R' )
1329 else if( hjustify !=
'C' )
1330 SCH_PARSE_ERROR(
"symbol field text horizontal justification must be "
1331 "L, R, or C", aReader, line );
1335 if( textAttrs[0] ==
'T' )
1337 else if( textAttrs[0] ==
'B' )
1339 else if( textAttrs[0] !=
'C' )
1341 "B, T, or C", aReader, line );
1344 if( textAttrs.Length() > 1 )
1346 if( textAttrs.Length() != 3 )
1348 SCH_PARSE_ERROR(
_(
"symbol field text attributes must be 3 characters wide" ),
1352 if( textAttrs[1] ==
'I' )
1356 else if( textAttrs[1] !=
'N' )
1358 SCH_PARSE_ERROR(
"symbol field text italics indicator must be I or N",
1362 if( textAttrs[2] ==
'B' )
1366 else if( textAttrs[2] !=
'N' )
1379 if( orientation ==
'H' )
1381 else if( orientation ==
'V' )
1384 SCH_PARSE_ERROR(
"symbol field orientation must be H or V", aReader, line );
1386 if(
name.IsEmpty() )
1407 instance.
m_Reference = symbol->GetField( FIELD_T::REFERENCE )->GetText();
1408 instance.
m_Unit = symbol->GetUnit();
1409 symbol->AddHierarchicalReference( instance );
1416 symbol->AddHierarchicalReference( tmpInstance );
1422 symbol->ClearFlags();
1423 return symbol.release();
1440 transform.
x1 =
parseInt( aReader, line, &line );
1442 if( transform.
x1 < -1 || transform.
x1 > 1 )
1443 SCH_PARSE_ERROR(
"invalid symbol X1 transform value", aReader, line );
1445 transform.
y1 = -
parseInt( aReader, line, &line );
1447 if( transform.
y1 < -1 || transform.
y1 > 1 )
1448 SCH_PARSE_ERROR(
"invalid symbol Y1 transform value", aReader, line );
1450 transform.
x2 =
parseInt( aReader, line, &line );
1452 if( transform.
x2 < -1 || transform.
x2 > 1 )
1453 SCH_PARSE_ERROR(
"invalid symbol X2 transform value", aReader, line );
1455 transform.
y2 = -
parseInt( aReader, line, &line );
1457 if( transform.
y2 < -1 || transform.
y2 > 1 )
1458 SCH_PARSE_ERROR(
"invalid symbol Y2 transform value", aReader, line );
1460 symbol->SetTransform( transform );
1475 auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1476 const char* line = aReader.
Line();
1478 wxCHECK(
strCompare(
"BusAlias", line, &line ),
nullptr );
1482 busAlias->SetName( buf );
1484 while( *line !=
'\0' )
1489 if( !buf.IsEmpty() )
1490 busAlias->Members().emplace_back( buf );
1499 const std::map<std::string, UTF8>* aProperties )
1501 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET object." );
1502 wxCHECK_RET( !aFileName.IsEmpty(),
"No schematic file name defined." );
1506 init( aSchematic, aProperties );
1508 wxFileName fn = aFileName;
1512 wxASSERT( fn.IsAbsolute() );
1526 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET* object." );
1527 wxCHECK_RET(
m_schematic !=
nullptr,
"NULL SCHEMATIC* object." );
1569 for(
const std::shared_ptr<BUS_ALIAS>& alias : screen->
GetBusAliases() )
1574 std::multiset<
SCH_ITEM*,
decltype( cmp )> save_map( cmp );
1577 save_map.insert( item );
1580 for(
auto& item : save_map )
1582 switch( item->Type() )
1613 wxASSERT(
"Unexpected schematic object type in SCH_IO_KICAD_LEGACY::Format()" );
1625 for(
unsigned i = 0; i < aSelection->
GetSize(); ++i )
1629 switch( item->
Type() )
1660 wxASSERT(
"Unexpected schematic object type in SCH_IO_KICAD_LEGACY::Format()" );
1671 static wxString delimiters( wxT(
" " ) );
1689 if( symbol_name.size() )
1699 m_out->
Print( 0,
"L %s %s\n", name2.c_str(), name1.c_str() );
1728 wxString
path =
"/";
1731 for(
int i = 1; i < (int) instance.m_Path.size(); ++i )
1732 path += instance.m_Path[i].AsLegacyTimestampString() +
"/";
1734 m_out->
Print( 0,
"AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1736 TO_UTF8( instance.m_Reference ),
1742 int legacy_field_id = 0;
1755 transform.
x1, transform.
y1, transform.
x2, transform.
y2 );
1762 char hjustify =
'C';
1769 char vjustify =
'C';
1776 m_out->
Print( 0,
"F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1786 aField->
IsBold() ?
'B' :
'N' );
1802 wxCHECK_RET(
image !=
nullptr,
"wxImage* is NULL" );
1811 wxMemoryOutputStream stream;
1813 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1816 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1817 char* begin = (
char*) buffer->GetBufferStart();
1819 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1838 wxCHECK_RET( aSheet !=
nullptr,
"SCH_SHEET* is NULL" );
1852 if( !sheetName->
GetText().IsEmpty() )
1859 if( !fileName->
GetText().IsEmpty() )
1870 if(
pin->GetText().IsEmpty() )
1873 switch(
pin->GetSide() )
1876 case SHEET_SIDE::LEFT: side =
'L';
break;
1877 case SHEET_SIDE::RIGHT: side =
'R';
break;
1878 case SHEET_SIDE::TOP: side =
'T';
break;
1879 case SHEET_SIDE::BOTTOM: side =
'B';
break;
1882 switch(
pin->GetShape() )
1885 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type =
'U';
break;
1886 case LABEL_FLAG_SHAPE::L_INPUT: type =
'I';
break;
1887 case LABEL_FLAG_SHAPE::L_OUTPUT: type =
'O';
break;
1888 case LABEL_FLAG_SHAPE::L_BIDI: type =
'B';
break;
1889 case LABEL_FLAG_SHAPE::L_TRISTATE: type =
'T';
break;
1892 m_out->
Print( 0,
"F%d %s %c %c %-3d %-3d %-3d\n",
1906 wxCHECK_RET( aJunction !=
nullptr,
"SCH_JUNCTION* is NULL" );
1916 wxCHECK_RET( aNoConnect !=
nullptr,
"SCH_NOCONNECT* is NULL" );
1926 wxCHECK_RET( aBusEntry !=
nullptr,
"SCH_BUS_ENTRY_BASE* is NULL" );
1930 m_out->
Print( 0,
"Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1938 m_out->
Print( 0,
"Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1949 wxCHECK_RET( aLine !=
nullptr,
"SCH_LINE* is NULL" );
1951 const char* layer =
"Notes";
1952 const char* width =
"Line";
1959 m_out->
Print( 0,
"Wire %s %s", layer, width );
1973 if( stroke.
GetColor() != COLOR4D::UNSPECIFIED )
1991 wxCHECK_RET( aText !=
nullptr,
"SCH_TEXT* is NULL" );
1993 const char* italics =
"~";
1994 const char* textType =
"Notes";
2009 text.Replace( wxT(
"\n" ), wxT(
"\\n" ) );
2017 for(
unsigned ii = 0; ii <
text.Len(); )
2019 if(
text[ii] == 0x0A ||
text[ii] == 0x0D )
2020 text.erase( ii, 1 );
2035 spinStyle =
static_cast<int>( label->GetSpinStyle() );
2037 if( spinStyle == 0 )
2039 else if( spinStyle == 2 )
2043 m_out->
Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2056 wxCHECK_RET( shapeLabelIt !=
sheetLabelNames.end(),
"Shape not found in names list" );
2058 m_out->
Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2063 shapeLabelIt->second,
2072 wxCHECK_RET( aAlias !=
nullptr,
"BUS_ALIAS* is NULL" );
2074 wxString members = boost::algorithm::join( aAlias->Members(),
" " );
2082 const std::map<std::string, UTF8>* aProperties )
2100 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2124 const wxString& aLibraryPath,
2125 const std::map<std::string, UTF8>* aProperties )
2129 bool powerSymbolsOnly = ( aProperties &&
2132 cacheLib( aLibraryPath, aProperties );
2136 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2138 if( !powerSymbolsOnly || it->second->IsGlobalPower() )
2139 aSymbolNameList.Add( it->first );
2145 const wxString& aLibraryPath,
2146 const std::map<std::string, UTF8>* aProperties )
2150 bool powerSymbolsOnly = ( aProperties &&
2153 cacheLib( aLibraryPath, aProperties );
2157 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2159 if( !powerSymbolsOnly || it->second->IsGlobalPower() )
2160 aSymbolList.push_back( it->second );
2166 const wxString& aSymbolName,
2167 const std::map<std::string, UTF8>* aProperties )
2171 cacheLib( aLibraryPath, aProperties );
2173 LIB_SYMBOL_MAP::const_iterator it =
m_cache->
m_symbols.find( aSymbolName );
2183 const std::map<std::string, UTF8>* aProperties )
2187 cacheLib( aLibraryPath, aProperties );
2197 const std::map<std::string, UTF8>* aProperties )
2201 cacheLib( aLibraryPath, aProperties );
2211 const std::map<std::string, UTF8>* aProperties )
2213 if( wxFileExists( aLibraryPath ) )
2215 THROW_IO_ERROR( wxString::Format(
_(
"Symbol library '%s' already exists." ),
2216 aLibraryPath.GetData() ) );
2230 const std::map<std::string, UTF8>* aProperties )
2232 wxFileName fn = aLibraryPath;
2234 if( !fn.FileExists() )
2239 if( wxRemove( aLibraryPath ) )
2241 THROW_IO_ERROR( wxString::Format(
_(
"Symbol library '%s' cannot be deleted." ),
2242 aLibraryPath.GetData() ) );
2256 const std::map<std::string, UTF8>* aProperties )
constexpr EDA_IU_SCALE schIUScale
void SetPageCount(int aPageCount)
int GetVirtualPageNumber() const
void SetVirtualPageNumber(int aPageNumber)
void SetContentModified(bool aModified=true)
This class handle bitmap images in KiCad.
bool IsHorizontal() const
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
const EDA_ANGLE & GetTextAngle() const
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
void SetTextPos(const VECTOR2I &aPoint)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
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)
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
int GetTextThickness() const
VECTOR2I GetTextSize() const
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.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(double aHeightInMils)
double GetHeightMils() const
const wxString & GetType() const
double GetWidthMils() const
void SetWidthMils(double aWidthInMils)
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
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 & Prj() 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.
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
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)
void Save(const std::optional< bool > &aOpt) override
Save the entire library to file m_libFileName;.
void DeleteSymbol(const wxString &aName) override
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)
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 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,...
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
bool writeDocFile(const std::map< std::string, UTF8 > *aProperties)
LINE_READER * m_lineReader
for progress reporting
bool IsFile(const wxString &aFullPathAndFileName) const
void SetFileName(const wxString &aFileName)
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)
bool IsFileChanged() const
wxString GetFileName() const
void SetModified(bool aModified=true)
Base class that schematic file and library loading and saving plugins should derive from.
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
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
auto & GetBusAliases() const
Return a set of bus aliases defined in this screen.
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 (and transfers ownership of the pointer).
void SetPageSettings(const PAGE_INFO &aPageSettings)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
const KIID & GetUuid() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
const TITLE_BLOCK & GetTitleBlock() const
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.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
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
int GetPenSizeForBold(int aTextSize)
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
#define SCH_LAYER_ID_COUNT
SCH_LAYER_ID
Eeschema drawing layers.
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.
wxString From_UTF8(const char *cstring)
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
constexpr int IUToMils(int iu) const
constexpr int MilsToIU(int mils) const
A simple container for schematic symbol instance information.
Definition for symbol library class.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
wxString GetCanonicalFieldName(FIELD_T aFieldType)
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.