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>
33
34#include <fstream>
35#include <wx/txtstrm.h>
36#include <wx/wfstream.h>
37#include <wx/mstream.h>
38#include <wx/zipstrm.h>
39#include <wx/fs_zip.h>
40#include <wx/log.h>
41
42#include <nlohmann/json.hpp>
43#include <string_utils.h>
47#include <core/map_helpers.h>
48#include <project_sch.h>
49
50
52{
53 std::map<wxString, EASYEDAPRO::SYM_INFO> m_Symbols;
54 std::map<wxString, EASYEDAPRO::BLOB> m_Blobs;
55};
56
57
58SCH_IO_EASYEDAPRO::SCH_IO_EASYEDAPRO() : SCH_IO( wxS( "EasyEDA Pro (JLCEDA) Schematic" ) )
59{
61}
62
63
65{
66 if( m_projectData )
67 delete m_projectData;
68}
69
70
71bool SCH_IO_EASYEDAPRO::CanReadSchematicFile( const wxString& aFileName ) const
72{
73 if( aFileName.Lower().EndsWith( wxS( ".epro" ) ) )
74 {
75 return true;
76 }
77 else if( aFileName.Lower().EndsWith( wxS( ".zip" ) ) )
78 {
79 std::shared_ptr<wxZipEntry> entry;
80 wxFFileInputStream in( aFileName );
81 wxZipInputStream zip( in );
82
83 if( !zip.IsOk() )
84 return false;
85
86 while( entry.reset( zip.GetNextEntry() ), entry.get() != NULL )
87 {
88 wxString name = entry->GetName();
89
90 if( name == wxS( "project.json" ) )
91 return true;
92 }
93
94 return false;
95 }
96
97 return false;
98}
99
100
102{
103 return 0;
104}
105
106
107static LIB_SYMBOL* loadSymbol( nlohmann::json project, const wxString& aLibraryPath,
108 const wxString& aAliasName, const STRING_UTF8_MAP* aProperties )
109{
110 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
111 LIB_SYMBOL* symbol = nullptr;
112 wxFileName libFname( aLibraryPath );
113 wxString symLibName = LIB_ID::FixIllegalChars( libFname.GetName(), true );
114
115 /*if( libFname.GetExt() == wxS( "esym" ) )
116 {
117 wxFFileInputStream ffis( aLibraryPath );
118 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
119
120 bool loadThis = false;
121 std::vector<nlohmann::json> lines;
122 while( ffis.CanRead() )
123 {
124 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
125 lines.emplace_back( js );
126
127 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
128 {
129 if( js.at( 4 ).get<wxString>() == aAliasName )
130 {
131 loadThis = true;
132 }
133 }
134 }
135
136 if( loadThis )
137 {
138 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines );
139 return symInfo.libSymbol.release();
140 }
141 }
142 else */
143 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
144 || libFname.GetExt() == wxS( "zip" ) )
145 {
146 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
147 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints;
148 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices;
149
150 if( project.contains( "footprints" ) )
151 prjFootprints = project.at( "footprints" );
152
153 if( project.contains( "devices" ) )
154 prjDevices = project.at( "devices" );
155
156 auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(),
157 [&]( const auto& pair )
158 {
159 return pair.second.title == aAliasName;
160 } );
161
162 if( prjSymIt == prjSymbols.end() )
163 return nullptr;
164
165 wxString prjSymUuid = prjSymIt->first;
166
167 wxString description;
168 wxString customTags;
169 std::map<wxString, wxString> deviceAttributes;
170 wxString fpTitle;
171
172 for( auto& [key, device] : prjDevices )
173 {
174 auto val = get_opt( device.attributes, "Symbol" );
175
176 if( val && *val == prjSymUuid )
177 {
178 description = device.description;
179 deviceAttributes = device.attributes;
180
181 if( device.custom_tags.is_string() )
182 customTags = device.custom_tags.get<wxString>();
183
184 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
185 {
186 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
187 {
188 fpTitle = prjFp->title;
189 break;
190 }
191 }
192 }
193 }
194
195 auto cb = [&]( const wxString& name, const wxString& symUuid, wxInputStream& zip ) -> bool
196 {
197 if( !name.EndsWith( wxS( ".esym" ) ) )
199
200 if( symUuid != prjSymUuid )
202
203 wxTextInputStream txt( zip, wxS( " " ), wxConvUTF8 );
204
205 std::vector<nlohmann::json> lines;
206 while( zip.CanRead() )
207 {
208 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
209 lines.emplace_back( js );
210 }
211
212 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
213
214 if( !symInfo.libSymbol )
216
217 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, aAliasName );
218 symInfo.libSymbol->SetLibId( libID );
219 symInfo.libSymbol->SetName( aAliasName );
220 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
221
222 wxString keywords = customTags;
223 keywords.Replace( wxS( ":" ), wxS( " " ), true );
224
225 symInfo.libSymbol->SetKeyWords( keywords );
226
227 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
228
229 symInfo.libSymbol->SetDescription( description );
230
231 symbol = symInfo.libSymbol.release();
232
234 };
235 EASYEDAPRO::IterateZipFiles( aLibraryPath, cb );
236 }
237
238 return symbol;
239}
240
241
242void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
243 const wxString& aLibraryPath,
244 const STRING_UTF8_MAP* aProperties )
245{
246 wxFileName fname( aLibraryPath );
247
248 if( fname.GetExt() == wxS( "esym" ) )
249 {
250 wxFFileInputStream ffis( aLibraryPath );
251 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
252
253 while( ffis.CanRead() )
254 {
255 wxString line = txt.ReadLine();
256
257 if( !line.Contains( wxS( "ATTR" ) ) )
258 continue; // Don't bother parsing
259
260 nlohmann::json js = nlohmann::json::parse( line );
261 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
262 {
263 aSymbolNameList.Add( js.at( 4 ).get<wxString>() );
264 }
265 }
266 }
267 else if( fname.GetExt() == wxS( "elibz" ) || fname.GetExt() == wxS( "epro" )
268 || fname.GetExt() == wxS( "zip" ) )
269 {
270 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aLibraryPath );
271 std::map<wxString, nlohmann::json> symbolMap = project.at( "symbols" );
272
273 for( auto& [key, value] : symbolMap )
274 {
275 wxString title;
276
277 if( value.contains( "display_title" ) )
278 title = value.at( "display_title" ).get<wxString>();
279 else
280 title = value.at( "title" ).get<wxString>();
281
282 aSymbolNameList.Add( title );
283 }
284 }
285}
286
287
288void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
289 const wxString& aLibraryPath,
290 const STRING_UTF8_MAP* aProperties )
291{
292 wxFileName libFname( aLibraryPath );
293 wxArrayString symbolNameList;
294 nlohmann::json project;
295
296 EnumerateSymbolLib( symbolNameList, aLibraryPath, aProperties );
297
298 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
299 || libFname.GetExt() == wxS( "zip" ) )
300 {
302 }
303
304 for( const wxString& symbolName : symbolNameList )
305 {
306 LIB_SYMBOL* sym = loadSymbol( project, aLibraryPath, symbolName, aProperties );
307
308 if( sym )
309 aSymbolList.push_back( sym );
310 }
311}
312
313
314void SCH_IO_EASYEDAPRO::LoadAllDataFromProject( const wxString& aProjectPath )
315{
316 if( m_projectData )
317 delete m_projectData;
318
320
321 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
322 wxFileName fname( aProjectPath );
323 wxString symLibName = EASYEDAPRO::ShortenLibName( fname.GetName() );
324
325 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
326 return;
327
328 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aProjectPath );
329
330 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
331 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints = project.at( "footprints" );
332 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices = project.at( "devices" );
333
334 auto cb = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
335 {
336 if( !name.EndsWith( wxS( ".esym" ) ) && !name.EndsWith( wxS( ".eblob" ) ) )
338
339 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
340
341 if( name.EndsWith( wxS( ".esym" ) ) )
342 {
343 wxString description;
344 wxString customTags;
345 std::map<wxString, wxString> deviceAttributes;
346 wxString fpTitle;
347
348 for( auto& [key, device] : prjDevices )
349 {
350 auto val = get_opt( device.attributes, "Symbol" );
351
352 if( val && *val == baseName )
353 {
354 description = device.description;
355 deviceAttributes = device.attributes;
356
357 if( device.custom_tags.is_string() )
358 customTags = device.custom_tags.get<wxString>();
359
360 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
361 {
362 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
363 {
364 fpTitle = prjFp->title;
365 break;
366 }
367 }
368 }
369 }
370
371 EASYEDAPRO::PRJ_SYMBOL symData = prjSymbols.at( baseName );
372 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
373
374 if( !symInfo.libSymbol )
376
377 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, symData.title );
378 symInfo.libSymbol->SetLibId( libID );
379 symInfo.libSymbol->SetName( symData.title );
380 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
381
382 wxString keywords = customTags;
383 keywords.Replace( wxS( ":" ), wxS( " " ), true );
384
385 symInfo.libSymbol->SetKeyWords( keywords );
386
387 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
388
389 symInfo.libSymbol->SetDescription( description );
390
391 m_projectData->m_Symbols.emplace( baseName, std::move( symInfo ) );
392 }
393 else if( name.EndsWith( wxS( ".eblob" ) ) )
394 {
395 for( const nlohmann::json& line : lines )
396 {
397 if( line.at( 0 ) == "BLOB" )
398 {
399 EASYEDAPRO::BLOB blob = line;
400 m_projectData->m_Blobs[blob.objectId] = blob;
401 }
402 }
403 }
404
406 };
407 EASYEDAPRO::IterateZipFiles( aProjectPath, cb );
408}
409
410
411LIB_SYMBOL* SCH_IO_EASYEDAPRO::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
412 const STRING_UTF8_MAP* aProperties )
413{
414 wxFileName libFname( aLibraryPath );
415 nlohmann::json project;
416
417 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
418 || libFname.GetExt() == wxS( "zip" ) )
419 {
421 }
422
423 return loadSymbol( project, aLibraryPath, aAliasName, aProperties );
424}
425
426
428 SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe,
429 const STRING_UTF8_MAP* aProperties )
430{
431 wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
432
433 // Show the font substitution warnings
435
436 SCH_SHEET* rootSheet = nullptr;
437
438 if( aAppendToMe )
439 {
440 wxCHECK_MSG( aSchematic->IsValid(), nullptr,
441 wxS( "Can't append to a schematic with no root!" ) );
442
443 rootSheet = &aSchematic->Root();
444 }
445 else
446 {
447 rootSheet = new SCH_SHEET( aSchematic );
448 rootSheet->SetFileName( aFileName );
449 aSchematic->SetRoot( rootSheet );
450 }
451
452 if( !rootSheet->GetScreen() )
453 {
454 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
455
456 screen->SetFileName( aFileName );
457 rootSheet->SetScreen( screen );
458 }
459
460 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
461 wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) );
462
463 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
464 wxFileName fname( aFileName );
465 wxString libName = EASYEDAPRO::ShortenLibName( fname.GetName() );
466
467 wxFileName libFileName( fname.GetPath(), libName, FILEEXT::KiCadSymbolLibFileExtension );
468
469 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
470 return rootSheet;
471
472 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aFileName );
473
474 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics = project.at( "schematics" );
475
476 wxString schematicToLoad;
477
478 if( aProperties && aProperties->Exists( "sch_id" ) )
479 {
480 schematicToLoad = wxString::FromUTF8( aProperties->at( "sch_id" ) );
481 }
482 else
483 {
484 if( prjSchematics.size() == 1 )
485 {
486 schematicToLoad = prjSchematics.begin()->first;
487 }
488 else
489 {
490 std::vector<IMPORT_PROJECT_DESC> chosen = m_choose_project_handler(
492
493 if( chosen.size() > 0 )
494 schematicToLoad = chosen[0].SchematicId;
495 }
496 }
497
498 if( schematicToLoad.empty() )
499 return nullptr;
500
501 wxString rootBaseName = EscapeString( prjSchematics[schematicToLoad].name, CTX_FILENAME );
502
503 wxFileName rootFname( aFileName );
504 rootFname.SetFullName( rootBaseName + wxS( "." )
505 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
506
507 rootSheet->SetName( prjSchematics[schematicToLoad].name );
508 rootSheet->SetFileName( rootFname.GetFullPath() );
509 rootSheet->GetScreen()->SetFileName( rootFname.GetFullPath() );
510
511 const std::vector<EASYEDAPRO::PRJ_SHEET>& prjSchematicSheets =
512 prjSchematics[schematicToLoad].sheets;
513
514 LoadAllDataFromProject( aFileName );
515
516 if( !m_projectData )
517 return nullptr;
518
519 const int schSheetsCount = prjSchematicSheets.size();
520
521 auto cbs = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
522 {
523 if( !name.EndsWith( wxS( ".esch" ) ) )
525
526 wxArrayString nameParts = wxSplit( name, '\\', '\0' );
527
528 if( nameParts.size() == 1 )
529 nameParts = wxSplit( name, '/', '\0' );
530
531 if( nameParts.size() < 3 )
533
534 wxString schematicUuid = nameParts[1];
535 wxString sheetFileName = nameParts[2];
536 wxString sheetId = sheetFileName.BeforeLast( '.' );
537 int sheetId_i;
538 sheetId.ToInt( &sheetId_i );
539
540 if( schematicUuid != schematicToLoad )
542
543 auto prjSheetIt = std::find_if( prjSchematicSheets.begin(), prjSchematicSheets.end(),
544 [&]( const EASYEDAPRO::PRJ_SHEET& s )
545 {
546 return s.id == sheetId_i;
547 } );
548
549 if( prjSheetIt == prjSchematicSheets.end() )
551
552 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
553
554 if( schSheetsCount > 1 )
555 {
556 wxString sheetBaseName =
557 sheetId + wxS( "_" ) + EscapeString( prjSheetIt->name, CTX_FILENAME );
558
559 wxFileName sheetFname( aFileName );
560 sheetFname.SetFullName( sheetBaseName + wxS( "." )
561 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
562
563 wxFileName relSheetPath( sheetFname );
564 relSheetPath.MakeRelativeTo( rootFname.GetPath() );
565
566 std::unique_ptr<SCH_SHEET> subSheet = std::make_unique<SCH_SHEET>( aSchematic );
567 subSheet->SetFileName( relSheetPath.GetFullPath() );
568 subSheet->SetName( prjSheetIt->name );
569
570 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
571 screen->SetFileName( sheetFname.GetFullPath() );
572 screen->SetPageNumber( sheetId );
573 subSheet->SetScreen( screen );
574
575 VECTOR2I pos;
576 pos.x = schIUScale.MilsToIU( 200 );
577 pos.y = schIUScale.MilsToIU( 200 )
578 + ( subSheet->GetSize().y + schIUScale.MilsToIU( 200 ) ) * ( sheetId_i - 1 );
579
580 subSheet->SetPosition( pos );
581
582 SCH_SHEET_PATH sheetPath;
583 sheetPath.push_back( rootSheet );
584 sheetPath.push_back( subSheet.get() );
585 sheetPath.SetPageNumber( sheetId );
586 aSchematic->SetCurrentSheet( sheetPath );
587
588 parser.ParseSchematic( aSchematic, subSheet.get(), project, m_projectData->m_Symbols,
589 m_projectData->m_Blobs, lines, libName );
590
591 rootSheet->GetScreen()->Append( subSheet.release() );
592 }
593 else
594 {
595 parser.ParseSchematic( aSchematic, rootSheet, project, m_projectData->m_Symbols,
596 m_projectData->m_Blobs, lines, libName );
597 }
598
600 };
601 EASYEDAPRO::IterateZipFiles( aFileName, cbs );
602
603 IO_RELEASER<SCH_IO> sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
604
605 if( !libTable->HasLibrary( libName ) )
606 {
607 // Create a new empty symbol library.
608 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
609 wxString libTableUri = wxS( "${KIPRJMOD}/" ) + libFileName.GetFullName();
610
611 // Add the new library to the project symbol library table.
612 libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( libName, libTableUri, wxS( "KiCad" ) ) );
613
614 // Save project symbol library table.
615 wxFileName fn( aSchematic->Prj().GetProjectPath(),
617
618 // So output formatter goes out of scope and closes the file before reloading.
619 {
620 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
621 libTable->Format( &formatter, 0 );
622 }
623
624 // Relaod the symbol library table.
625 aSchematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
626 PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
627 }
628
629 // set properties to prevent save file on every symbol save
630 STRING_UTF8_MAP properties;
631 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
632
633 for( auto& [symbolUuid, symInfo] : m_projectData->m_Symbols )
634 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symInfo.libSymbol.release(),
635 &properties );
636
637 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
638
640 aSchematic->FixupJunctions();
641
642 return rootSheet;
643}
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:475
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:215
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 const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:309
@ ELEM_SYMBOL_LIB_TABLE
Definition: project.h:228
Holds all the data relating to one schematic.
Definition: schematic.h:76
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:144
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:149
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:734
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:129
SCH_SHEET & Root() const
Definition: schematic.h:113
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:91
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)
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
PRJ_DATA * m_projectData
void LoadAllDataFromProject(const wxString &aLibraryPath)
int GetModifyHash() const override
Return the modification hash from the library cache.
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
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:152
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:117
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:172
A name/value tuple with unique names and optional values.
bool Exists(const std::string &aProperty) const
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:212
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 STRING_UTF8_MAP *aProperties)
static LIB_SYMBOL * loadSymbol(nlohmann::json project, const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *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.