KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_easyedapro.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Alex Shvartzkop <[email protected]>
5 * Copyright (C) 2023-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include "sch_io_easyedapro.h"
27
28#include <font/fontconfig.h>
29#include <schematic.h>
30#include <sch_sheet.h>
31#include <sch_screen.h>
32#include <symbol_lib_table.h>
34
35#include <fstream>
36#include <wx/txtstrm.h>
37#include <wx/wfstream.h>
38#include <wx/mstream.h>
39#include <wx/zipstrm.h>
40#include <wx/fs_zip.h>
41#include <wx/log.h>
42
43#include <nlohmann/json.hpp>
44#include <string_utils.h>
48#include <core/map_helpers.h>
49#include <project_sch.h>
50
51
53{
54 std::map<wxString, EASYEDAPRO::SYM_INFO> m_Symbols;
55 std::map<wxString, EASYEDAPRO::BLOB> m_Blobs;
56};
57
58
59SCH_IO_EASYEDAPRO::SCH_IO_EASYEDAPRO() : SCH_IO( wxS( "EasyEDA Pro (JLCEDA) Schematic" ) )
60{
62}
63
64
66{
67 if( m_projectData )
68 delete m_projectData;
69}
70
71
72bool SCH_IO_EASYEDAPRO::CanReadSchematicFile( const wxString& aFileName ) const
73{
74 if( aFileName.Lower().EndsWith( wxS( ".epro" ) ) )
75 {
76 return true;
77 }
78 else if( aFileName.Lower().EndsWith( wxS( ".zip" ) ) )
79 {
80 std::shared_ptr<wxZipEntry> entry;
81 wxFFileInputStream in( aFileName );
82 wxZipInputStream zip( in );
83
84 if( !zip.IsOk() )
85 return false;
86
87 while( entry.reset( zip.GetNextEntry() ), entry.get() != NULL )
88 {
89 wxString name = entry->GetName();
90
91 if( name == wxS( "project.json" ) )
92 return true;
93 }
94
95 return false;
96 }
97
98 return false;
99}
100
101
103{
104 return 0;
105}
106
107
108static LIB_SYMBOL* loadSymbol( nlohmann::json project, const wxString& aLibraryPath,
109 const wxString& aAliasName, const std::map<std::string, UTF8>* aProperties )
110{
111 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
112 LIB_SYMBOL* symbol = nullptr;
113 wxFileName libFname( aLibraryPath );
114 wxString symLibName = LIB_ID::FixIllegalChars( libFname.GetName(), true );
115
116 /*if( libFname.GetExt() == wxS( "esym" ) )
117 {
118 wxFFileInputStream ffis( aLibraryPath );
119 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
120
121 bool loadThis = false;
122 std::vector<nlohmann::json> lines;
123 while( ffis.CanRead() )
124 {
125 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
126 lines.emplace_back( js );
127
128 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
129 {
130 if( js.at( 4 ).get<wxString>() == aAliasName )
131 {
132 loadThis = true;
133 }
134 }
135 }
136
137 if( loadThis )
138 {
139 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines );
140 return symInfo.libSymbol.release();
141 }
142 }
143 else */
144 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
145 || libFname.GetExt() == wxS( "zip" ) )
146 {
147 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
148 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints;
149 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices;
150
151 if( project.contains( "footprints" ) )
152 prjFootprints = project.at( "footprints" );
153
154 if( project.contains( "devices" ) )
155 prjDevices = project.at( "devices" );
156
157 auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(),
158 [&]( const auto& pair )
159 {
160 return pair.second.title == aAliasName;
161 } );
162
163 if( prjSymIt == prjSymbols.end() )
164 return nullptr;
165
166 wxString prjSymUuid = prjSymIt->first;
167
168 wxString description;
169 wxString customTags;
170 std::map<wxString, wxString> deviceAttributes;
171 wxString fpTitle;
172
173 for( auto& [key, device] : prjDevices )
174 {
175 auto val = get_opt( device.attributes, "Symbol" );
176
177 if( val && *val == prjSymUuid )
178 {
179 description = device.description;
180 deviceAttributes = device.attributes;
181
182 if( device.custom_tags.is_string() )
183 customTags = device.custom_tags.get<wxString>();
184
185 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
186 {
187 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
188 {
189 fpTitle = prjFp->title;
190 break;
191 }
192 }
193 }
194 }
195
196 auto cb = [&]( const wxString& name, const wxString& symUuid, wxInputStream& zip ) -> bool
197 {
198 if( !name.EndsWith( wxS( ".esym" ) ) )
200
201 if( symUuid != prjSymUuid )
203
204 wxTextInputStream txt( zip, wxS( " " ), wxConvUTF8 );
205
206 std::vector<nlohmann::json> lines;
207 while( zip.CanRead() )
208 {
209 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
210 lines.emplace_back( js );
211 }
212
213 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
214
215 if( !symInfo.libSymbol )
217
218 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, aAliasName );
219 symInfo.libSymbol->SetLibId( libID );
220 symInfo.libSymbol->SetName( aAliasName );
221 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
222
223 wxString keywords = customTags;
224 keywords.Replace( wxS( ":" ), wxS( " " ), true );
225
226 symInfo.libSymbol->SetKeyWords( keywords );
227
228 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
229
230 symInfo.libSymbol->SetDescription( description );
231
232 symbol = symInfo.libSymbol.release();
233
235 };
236 EASYEDAPRO::IterateZipFiles( aLibraryPath, cb );
237 }
238
239 return symbol;
240}
241
242
243void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
244 const wxString& aLibraryPath,
245 const std::map<std::string, UTF8>* aProperties )
246{
247 wxFileName fname( aLibraryPath );
248
249 if( fname.GetExt() == wxS( "esym" ) )
250 {
251 wxFFileInputStream ffis( aLibraryPath );
252 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
253
254 while( ffis.CanRead() )
255 {
256 wxString line = txt.ReadLine();
257
258 if( !line.Contains( wxS( "ATTR" ) ) )
259 continue; // Don't bother parsing
260
261 nlohmann::json js = nlohmann::json::parse( line );
262 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
263 {
264 aSymbolNameList.Add( js.at( 4 ).get<wxString>() );
265 }
266 }
267 }
268 else if( fname.GetExt() == wxS( "elibz" ) || fname.GetExt() == wxS( "epro" )
269 || fname.GetExt() == wxS( "zip" ) )
270 {
271 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aLibraryPath );
272 std::map<wxString, nlohmann::json> symbolMap = project.at( "symbols" );
273
274 for( auto& [key, value] : symbolMap )
275 {
276 wxString title;
277
278 if( value.contains( "display_title" ) )
279 title = value.at( "display_title" ).get<wxString>();
280 else
281 title = value.at( "title" ).get<wxString>();
282
283 aSymbolNameList.Add( title );
284 }
285 }
286}
287
288
289void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
290 const wxString& aLibraryPath,
291 const std::map<std::string, UTF8>* aProperties )
292{
293 wxFileName libFname( aLibraryPath );
294 wxArrayString symbolNameList;
295 nlohmann::json project;
296
297 EnumerateSymbolLib( symbolNameList, aLibraryPath, aProperties );
298
299 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
300 || libFname.GetExt() == wxS( "zip" ) )
301 {
303 }
304
305 for( const wxString& symbolName : symbolNameList )
306 {
307 LIB_SYMBOL* sym = loadSymbol( project, aLibraryPath, symbolName, aProperties );
308
309 if( sym )
310 aSymbolList.push_back( sym );
311 }
312}
313
314
315void SCH_IO_EASYEDAPRO::LoadAllDataFromProject( const wxString& aProjectPath )
316{
317 if( m_projectData )
318 delete m_projectData;
319
321
322 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
323 wxFileName fname( aProjectPath );
324 wxString symLibName = EASYEDAPRO::ShortenLibName( fname.GetName() );
325
326 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
327 return;
328
329 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aProjectPath );
330
331 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
332 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints = project.at( "footprints" );
333 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices = project.at( "devices" );
334
335 auto cb = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
336 {
337 if( !name.EndsWith( wxS( ".esym" ) ) && !name.EndsWith( wxS( ".eblob" ) ) )
339
340 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
341
342 if( name.EndsWith( wxS( ".esym" ) ) )
343 {
344 wxString description;
345 wxString customTags;
346 std::map<wxString, wxString> deviceAttributes;
347 wxString fpTitle;
348
349 for( auto& [key, device] : prjDevices )
350 {
351 auto val = get_opt( device.attributes, "Symbol" );
352
353 if( val && *val == baseName )
354 {
355 description = device.description;
356 deviceAttributes = device.attributes;
357
358 if( device.custom_tags.is_string() )
359 customTags = device.custom_tags.get<wxString>();
360
361 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
362 {
363 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
364 {
365 fpTitle = prjFp->title;
366 break;
367 }
368 }
369 }
370 }
371
372 EASYEDAPRO::PRJ_SYMBOL symData = prjSymbols.at( baseName );
373 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
374
375 if( !symInfo.libSymbol )
377
378 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, symData.title );
379 symInfo.libSymbol->SetLibId( libID );
380 symInfo.libSymbol->SetName( symData.title );
381 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
382
383 wxString keywords = customTags;
384 keywords.Replace( wxS( ":" ), wxS( " " ), true );
385
386 symInfo.libSymbol->SetKeyWords( keywords );
387
388 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
389
390 symInfo.libSymbol->SetDescription( description );
391
392 m_projectData->m_Symbols.emplace( baseName, std::move( symInfo ) );
393 }
394 else if( name.EndsWith( wxS( ".eblob" ) ) )
395 {
396 for( const nlohmann::json& line : lines )
397 {
398 if( line.at( 0 ) == "BLOB" )
399 {
400 EASYEDAPRO::BLOB blob = line;
401 m_projectData->m_Blobs[blob.objectId] = blob;
402 }
403 }
404 }
405
407 };
408 EASYEDAPRO::IterateZipFiles( aProjectPath, cb );
409}
410
411
412LIB_SYMBOL* SCH_IO_EASYEDAPRO::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
413 const std::map<std::string, UTF8>* aProperties )
414{
415 wxFileName libFname( aLibraryPath );
416 nlohmann::json project;
417
418 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
419 || libFname.GetExt() == wxS( "zip" ) )
420 {
422 }
423
424 return loadSymbol( project, aLibraryPath, aAliasName, aProperties );
425}
426
427
429 SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe,
430 const std::map<std::string, UTF8>* aProperties )
431{
432 wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
433
434 // Show the font substitution warnings
436
437 SCH_SHEET* rootSheet = nullptr;
438
439 if( aAppendToMe )
440 {
441 wxCHECK_MSG( aSchematic->IsValid(), nullptr,
442 wxS( "Can't append to a schematic with no root!" ) );
443
444 rootSheet = &aSchematic->Root();
445 }
446 else
447 {
448 rootSheet = new SCH_SHEET( aSchematic );
449 rootSheet->SetFileName( aFileName );
450 aSchematic->SetRoot( rootSheet );
451 }
452
453 if( !rootSheet->GetScreen() )
454 {
455 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
456
457 screen->SetFileName( aFileName );
458 rootSheet->SetScreen( screen );
459 }
460
461 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
462 wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) );
463
464 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
465 wxFileName fname( aFileName );
466 wxString libName = EASYEDAPRO::ShortenLibName( fname.GetName() );
467
468 wxFileName libFileName( fname.GetPath(), libName, FILEEXT::KiCadSymbolLibFileExtension );
469
470 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
471 return rootSheet;
472
473 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aFileName );
474
475 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics = project.at( "schematics" );
476
477 wxString schematicToLoad;
478
479 if( aProperties && aProperties->contains( "sch_id" ) )
480 {
481 schematicToLoad = wxString::FromUTF8( aProperties->at( "sch_id" ) );
482 }
483 else
484 {
485 if( prjSchematics.size() == 1 )
486 {
487 schematicToLoad = prjSchematics.begin()->first;
488 }
489 else
490 {
491 std::vector<IMPORT_PROJECT_DESC> chosen = m_choose_project_handler(
493
494 if( chosen.size() > 0 )
495 schematicToLoad = chosen[0].SchematicId;
496 }
497 }
498
499 if( schematicToLoad.empty() )
500 return nullptr;
501
502 wxString rootBaseName = EscapeString( prjSchematics[schematicToLoad].name, CTX_FILENAME );
503
504 wxFileName rootFname( aFileName );
505 rootFname.SetFullName( rootBaseName + wxS( "." )
506 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
507
508 rootSheet->SetName( prjSchematics[schematicToLoad].name );
509 rootSheet->SetFileName( rootFname.GetFullPath() );
510 rootSheet->GetScreen()->SetFileName( rootFname.GetFullPath() );
511
512 const std::vector<EASYEDAPRO::PRJ_SHEET>& prjSchematicSheets =
513 prjSchematics[schematicToLoad].sheets;
514
515 LoadAllDataFromProject( aFileName );
516
517 if( !m_projectData )
518 return nullptr;
519
520 const int schSheetsCount = prjSchematicSheets.size();
521
522 auto cbs = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
523 {
524 if( !name.EndsWith( wxS( ".esch" ) ) )
526
527 wxArrayString nameParts = wxSplit( name, '\\', '\0' );
528
529 if( nameParts.size() == 1 )
530 nameParts = wxSplit( name, '/', '\0' );
531
532 if( nameParts.size() < 3 )
534
535 wxString schematicUuid = nameParts[1];
536 wxString sheetFileName = nameParts[2];
537 wxString sheetId = sheetFileName.BeforeLast( '.' );
538 int sheetId_i;
539 sheetId.ToInt( &sheetId_i );
540
541 if( schematicUuid != schematicToLoad )
543
544 auto prjSheetIt = std::find_if( prjSchematicSheets.begin(), prjSchematicSheets.end(),
545 [&]( const EASYEDAPRO::PRJ_SHEET& s )
546 {
547 return s.id == sheetId_i;
548 } );
549
550 if( prjSheetIt == prjSchematicSheets.end() )
552
553 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
554
555 if( schSheetsCount > 1 )
556 {
557 wxString sheetBaseName =
558 sheetId + wxS( "_" ) + EscapeString( prjSheetIt->name, CTX_FILENAME );
559
560 wxFileName sheetFname( aFileName );
561 sheetFname.SetFullName( sheetBaseName + wxS( "." )
562 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
563
564 wxFileName relSheetPath( sheetFname );
565 relSheetPath.MakeRelativeTo( rootFname.GetPath() );
566
567 std::unique_ptr<SCH_SHEET> subSheet = std::make_unique<SCH_SHEET>( aSchematic );
568 subSheet->SetFileName( relSheetPath.GetFullPath() );
569 subSheet->SetName( prjSheetIt->name );
570
571 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
572 screen->SetFileName( sheetFname.GetFullPath() );
573 screen->SetPageNumber( sheetId );
574 subSheet->SetScreen( screen );
575
576 VECTOR2I pos;
577 pos.x = schIUScale.MilsToIU( 200 );
578 pos.y = schIUScale.MilsToIU( 200 )
579 + ( subSheet->GetSize().y + schIUScale.MilsToIU( 200 ) ) * ( sheetId_i - 1 );
580
581 subSheet->SetPosition( pos );
582
583 SCH_SHEET_PATH sheetPath;
584 sheetPath.push_back( rootSheet );
585 sheetPath.push_back( subSheet.get() );
586 sheetPath.SetPageNumber( sheetId );
587 aSchematic->SetCurrentSheet( sheetPath );
588
589 parser.ParseSchematic( aSchematic, subSheet.get(), project, m_projectData->m_Symbols,
590 m_projectData->m_Blobs, lines, libName );
591
592 rootSheet->GetScreen()->Append( subSheet.release() );
593 }
594 else
595 {
596 parser.ParseSchematic( aSchematic, rootSheet, project, m_projectData->m_Symbols,
597 m_projectData->m_Blobs, lines, libName );
598 }
599
601 };
602 EASYEDAPRO::IterateZipFiles( aFileName, cbs );
603
604 IO_RELEASER<SCH_IO> sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
605
606 if( !libTable->HasLibrary( libName ) )
607 {
608 // Create a new empty symbol library.
609 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
610 wxString libTableUri = wxS( "${KIPRJMOD}/" ) + libFileName.GetFullName();
611
612 // Add the new library to the project symbol library table.
613 libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( libName, libTableUri, wxS( "KiCad" ) ) );
614
615 // Save project symbol library table.
616 wxFileName fn( aSchematic->Prj().GetProjectPath(),
618
619 // So output formatter goes out of scope and closes the file before reloading.
620 {
621 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
622 libTable->Format( &formatter, 0 );
623 }
624
625 // Relaod the symbol library table.
626 aSchematic->Prj().SetElem( PROJECT::ELEM::SYMBOL_LIB_TABLE, NULL );
627 PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
628 }
629
630 // set properties to prevent save file on every symbol save
631 std::map<std::string, UTF8> properties;
632 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
633
634 for( auto& [symbolUuid, symInfo] : m_projectData->m_Symbols )
635 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symInfo.libSymbol.release(),
636 &properties );
637
638 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
639
641 aSchematic->FixupJunctions();
642
643 return rootSheet;
644}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
void SetPageNumber(const wxString &aPageNumber)
Definition: base_screen.h:79
Used for text file output.
Definition: richio.h:478
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:218
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:191
Define a library symbol object.
Definition: lib_symbol.h:78
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
CHOOSE_PROJECT_HANDLER m_choose_project_handler
Callback to choose projects to import.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition: project.cpp:348
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
Holds all the data relating to one schematic.
Definition: schematic.h:77
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:152
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:157
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:740
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:194
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:137
SCH_SHEET & Root() const
Definition: schematic.h:121
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:92
EASYEDAPRO::SYM_INFO ParseSymbol(const std::vector< nlohmann::json > &aLines, const std::map< wxString, wxString > &aDeviceAttributes)
void ParseSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const nlohmann::json &aProject, std::map< wxString, EASYEDAPRO::SYM_INFO > &aSymbolMap, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const std::vector< nlohmann::json > &aLines, const wxString &aLibName)
PRJ_DATA * m_projectData
void LoadAllDataFromProject(const wxString &aLibraryPath)
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...
int GetModifyHash() const override
Return the modification hash from the library cache.
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.
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
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,...
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:153
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:118
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:312
void SetName(const wxString &aName)
Definition: sch_sheet.h:108
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:173
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
static const wxString & GetSymbolLibTableFileName()
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
static REPORTER & GetInstance()
Definition: reporter.cpp:199
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
Definition: fontconfig.cpp:64
#define EASY_IT_BREAK
#define EASY_IT_CONTINUE
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition: map_helpers.h:34
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
void IterateZipFiles(const wxString &aFileName, std::function< bool(const wxString &, const wxString &, wxInputStream &)> aCallback)
std::vector< nlohmann::json > ParseJsonLines(wxInputStream &aInput, const wxString &aSource)
std::vector< IMPORT_PROJECT_DESC > ProjectToSelectorDialog(const nlohmann::json &aProject, bool aPcbOnly=false, bool aSchOnly=false)
nlohmann::json ReadProjectOrDeviceFile(const wxString &aZipFileName)
wxString ShortenLibName(wxString aProjectName)
LIB_SYMBOL * loadSymbol(const wxString &aLibraryPath, nlohmann::json aFileData, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties)
static LIB_SYMBOL * loadSymbol(nlohmann::json project, const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_FILENAME
Definition: string_utils.h:61
std::unique_ptr< LIB_SYMBOL > libSymbol
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
std::map< wxString, EASYEDAPRO::BLOB > m_Blobs
std::map< wxString, EASYEDAPRO::SYM_INFO > m_Symbols
Definition of file extensions used in Kicad.