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 The 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 <json_common.h>
43#include <string_utils.h>
47#include <core/map_helpers.h>
48#include <project_sch.h>
51
52
54{
55 std::map<wxString, EASYEDAPRO::SYM_INFO> m_Symbols;
56 std::map<wxString, EASYEDAPRO::BLOB> m_Blobs;
57};
58
59
60SCH_IO_EASYEDAPRO::SCH_IO_EASYEDAPRO() : SCH_IO( wxS( "EasyEDA Pro (JLCEDA) Schematic" ) )
61{
63}
64
65
71
72
73bool SCH_IO_EASYEDAPRO::CanReadSchematicFile( const wxString& aFileName ) const
74{
75 if( aFileName.Lower().EndsWith( wxS( ".epro" ) ) )
76 {
77 return true;
78 }
79 else if( aFileName.Lower().EndsWith( wxS( ".zip" ) ) )
80 {
81 std::shared_ptr<wxZipEntry> entry;
82 wxFFileInputStream in( aFileName );
83 wxZipInputStream zip( in );
84
85 if( !zip.IsOk() )
86 return false;
87
88 while( entry.reset( zip.GetNextEntry() ), entry.get() != NULL )
89 {
90 wxString name = entry->GetName();
91
92 if( name == wxS( "project.json" ) )
93 return true;
94 }
95
96 return false;
97 }
98
99 return false;
100}
101
102
104{
105 return 0;
106}
107
108
109static LIB_SYMBOL* loadSymbol( nlohmann::json project, const wxString& aLibraryPath,
110 const wxString& aAliasName, const std::map<std::string, UTF8>* aProperties )
111{
112 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
113 LIB_SYMBOL* symbol = nullptr;
114 wxFileName libFname( aLibraryPath );
115 wxString symLibName = LIB_ID::FixIllegalChars( libFname.GetName(), true );
116
117 /*if( libFname.GetExt() == wxS( "esym" ) )
118 {
119 wxFFileInputStream ffis( aLibraryPath );
120 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
121
122 bool loadThis = false;
123 std::vector<nlohmann::json> lines;
124 while( ffis.CanRead() )
125 {
126 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
127 lines.emplace_back( js );
128
129 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
130 {
131 if( js.at( 4 ).get<wxString>() == aAliasName )
132 {
133 loadThis = true;
134 }
135 }
136 }
137
138 if( loadThis )
139 {
140 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines );
141 return symInfo.libSymbol.release();
142 }
143 }
144 else */
145 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
146 || libFname.GetExt() == wxS( "zip" ) )
147 {
148 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
149 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints;
150 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices;
151
152 if( project.contains( "footprints" ) )
153 prjFootprints = project.at( "footprints" );
154
155 if( project.contains( "devices" ) )
156 prjDevices = project.at( "devices" );
157
158 auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(),
159 [&]( const auto& pair )
160 {
161 return pair.second.title == aAliasName;
162 } );
163
164 if( prjSymIt == prjSymbols.end() )
165 return nullptr;
166
167 wxString prjSymUuid = prjSymIt->first;
168
169 wxString description;
170 wxString customTags;
171 std::map<wxString, wxString> deviceAttributes;
172 wxString fpTitle;
173
174 for( auto& [key, device] : prjDevices )
175 {
176 auto val = get_opt( device.attributes, "Symbol" );
177
178 if( val && *val == prjSymUuid )
179 {
180 description = device.description;
181 deviceAttributes = device.attributes;
182
183 if( device.custom_tags.is_string() )
184 customTags = device.custom_tags.get<wxString>();
185
186 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
187 {
188 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
189 {
190 fpTitle = prjFp->title;
191 break;
192 }
193 }
194 }
195 }
196
197 auto cb = [&]( const wxString& name, const wxString& symUuid, wxInputStream& zip ) -> bool
198 {
199 if( !name.EndsWith( wxS( ".esym" ) ) )
201
202 if( symUuid != prjSymUuid )
204
205 wxTextInputStream txt( zip, wxS( " " ), wxConvUTF8 );
206
207 std::vector<nlohmann::json> lines;
208 while( zip.CanRead() )
209 {
210 nlohmann::json js = nlohmann::json::parse( txt.ReadLine() );
211 lines.emplace_back( js );
212 }
213
214 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
215
216 if( !symInfo.libSymbol )
218
219 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, aAliasName );
220 symInfo.libSymbol->SetLibId( libID );
221 symInfo.libSymbol->SetName( aAliasName );
222 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
223
224 wxString keywords = customTags;
225 keywords.Replace( wxS( ":" ), wxS( " " ), true );
226
227 symInfo.libSymbol->SetKeyWords( keywords );
228
229 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
230
231 symInfo.libSymbol->SetDescription( description );
232
233 symbol = symInfo.libSymbol.release();
234
236 };
237 EASYEDAPRO::IterateZipFiles( aLibraryPath, cb );
238 }
239
240 return symbol;
241}
242
243
244void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
245 const wxString& aLibraryPath,
246 const std::map<std::string, UTF8>* aProperties )
247{
248 wxFileName fname( aLibraryPath );
249
250 if( fname.GetExt() == wxS( "esym" ) )
251 {
252 wxFFileInputStream ffis( aLibraryPath );
253 wxTextInputStream txt( ffis, wxS( " " ), wxConvUTF8 );
254
255 while( ffis.CanRead() )
256 {
257 wxString line = txt.ReadLine();
258
259 if( !line.Contains( wxS( "ATTR" ) ) )
260 continue; // Don't bother parsing
261
262 nlohmann::json js = nlohmann::json::parse( line );
263 if( js.at( 0 ) == "ATTR" && js.at( 3 ) == "Symbol" )
264 {
265 aSymbolNameList.Add( js.at( 4 ).get<wxString>() );
266 }
267 }
268 }
269 else if( fname.GetExt() == wxS( "elibz" ) || fname.GetExt() == wxS( "epro" )
270 || fname.GetExt() == wxS( "zip" ) )
271 {
272 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aLibraryPath );
273 std::map<wxString, nlohmann::json> symbolMap = project.at( "symbols" );
274
275 for( auto& [key, value] : symbolMap )
276 {
277 wxString title;
278
279 if( value.contains( "display_title" ) )
280 title = value.at( "display_title" ).get<wxString>();
281 else
282 title = value.at( "title" ).get<wxString>();
283
284 aSymbolNameList.Add( title );
285 }
286 }
287}
288
289
290void SCH_IO_EASYEDAPRO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
291 const wxString& aLibraryPath,
292 const std::map<std::string, UTF8>* aProperties )
293{
294 wxFileName libFname( aLibraryPath );
295 wxArrayString symbolNameList;
296 nlohmann::json project;
297
298 EnumerateSymbolLib( symbolNameList, aLibraryPath, aProperties );
299
300 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
301 || libFname.GetExt() == wxS( "zip" ) )
302 {
304 }
305
306 for( const wxString& symbolName : symbolNameList )
307 {
308 LIB_SYMBOL* sym = loadSymbol( project, aLibraryPath, symbolName, aProperties );
309
310 if( sym )
311 aSymbolList.push_back( sym );
312 }
313}
314
315
316void SCH_IO_EASYEDAPRO::LoadAllDataFromProject( const wxString& aProjectPath )
317{
318 if( m_projectData )
319 delete m_projectData;
320
322
323 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
324 wxFileName fname( aProjectPath );
325 wxString symLibName = EASYEDAPRO::ShortenLibName( fname.GetName() );
326
327 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
328 return;
329
330 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aProjectPath );
331
332 std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
333 std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints = project.at( "footprints" );
334 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices = project.at( "devices" );
335
336 auto cb = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
337 {
338 if( !name.EndsWith( wxS( ".esym" ) ) && !name.EndsWith( wxS( ".eblob" ) ) )
340
341 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
342
343 if( name.EndsWith( wxS( ".esym" ) ) )
344 {
345 wxString description;
346 wxString customTags;
347 std::map<wxString, wxString> deviceAttributes;
348 wxString fpTitle;
349
350 for( auto& [key, device] : prjDevices )
351 {
352 auto val = get_opt( device.attributes, "Symbol" );
353
354 if( val && *val == baseName )
355 {
356 description = device.description;
357 deviceAttributes = device.attributes;
358
359 if( device.custom_tags.is_string() )
360 customTags = device.custom_tags.get<wxString>();
361
362 if( auto fpUuid = get_opt( device.attributes, "Footprint" ) )
363 {
364 if( auto prjFp = get_opt( prjFootprints, *fpUuid ) )
365 {
366 fpTitle = prjFp->title;
367 break;
368 }
369 }
370 }
371 }
372
373 EASYEDAPRO::PRJ_SYMBOL symData = prjSymbols.at( baseName );
374 EASYEDAPRO::SYM_INFO symInfo = parser.ParseSymbol( lines, deviceAttributes );
375
376 if( !symInfo.libSymbol )
378
379 LIB_ID libID = EASYEDAPRO::ToKiCadLibID( symLibName, symData.title );
380 symInfo.libSymbol->SetLibId( libID );
381 symInfo.libSymbol->SetName( symData.title );
382 symInfo.libSymbol->GetFootprintField().SetText( symLibName + wxS( ":" ) + fpTitle );
383
384 wxString keywords = customTags;
385 keywords.Replace( wxS( ":" ), wxS( " " ), true );
386
387 symInfo.libSymbol->SetKeyWords( keywords );
388
389 description.Replace( wxS( "\u2103" ), wxS( "\u00B0C" ), true ); // ℃ -> °C
390
391 symInfo.libSymbol->SetDescription( description );
392
393 m_projectData->m_Symbols.emplace( baseName, std::move( symInfo ) );
394 }
395 else if( name.EndsWith( wxS( ".eblob" ) ) )
396 {
397 for( const nlohmann::json& line : lines )
398 {
399 if( line.at( 0 ) == "BLOB" )
400 {
401 EASYEDAPRO::BLOB blob = line;
402 m_projectData->m_Blobs[blob.objectId] = blob;
403 }
404 }
405 }
406
408 };
409 EASYEDAPRO::IterateZipFiles( aProjectPath, cb );
410}
411
412
413LIB_SYMBOL* SCH_IO_EASYEDAPRO::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
414 const std::map<std::string, UTF8>* aProperties )
415{
416 wxFileName libFname( aLibraryPath );
417 nlohmann::json project;
418
419 if( libFname.GetExt() == wxS( "elibz" ) || libFname.GetExt() == wxS( "epro" )
420 || libFname.GetExt() == wxS( "zip" ) )
421 {
423 }
424
425 return loadSymbol( project, aLibraryPath, aAliasName, aProperties );
426}
427
428
430 SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe,
431 const std::map<std::string, UTF8>* aProperties )
432{
433 wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
434
435 // Show the font substitution warnings
437
438 SCH_SHEET* rootSheet = nullptr;
439
440 if( aAppendToMe )
441 {
442 wxCHECK_MSG( aSchematic->IsValid(), nullptr,
443 wxS( "Can't append to a schematic with no root!" ) );
444
445 rootSheet = &aSchematic->Root();
446 }
447 else
448 {
449 rootSheet = new SCH_SHEET( aSchematic );
450 rootSheet->SetFileName( aFileName );
451 aSchematic->SetRoot( rootSheet );
452 }
453
454 if( !rootSheet->GetScreen() )
455 {
456 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
457
458 screen->SetFileName( aFileName );
459 rootSheet->SetScreen( screen );
460
461 // Virtual root sheet UUID must be the same as the schematic file UUID.
462 const_cast<KIID&>( rootSheet->m_Uuid ) = screen->GetUuid();
463 }
464
465 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
466 wxFileName fname( aFileName );
467 wxString libName = EASYEDAPRO::ShortenLibName( fname.GetName() );
468
469 wxFileName libFileName( fname.GetPath(), libName, FILEEXT::KiCadSymbolLibFileExtension );
470
471 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
472 return rootSheet;
473
474 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aFileName );
475
476 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics = project.at( "schematics" );
477
478 wxString schematicToLoad;
479
480 if( aProperties && aProperties->contains( "sch_id" ) )
481 {
482 schematicToLoad = wxString::FromUTF8( aProperties->at( "sch_id" ) );
483 }
484 else
485 {
486 if( prjSchematics.size() == 1 )
487 {
488 schematicToLoad = prjSchematics.begin()->first;
489 }
490 else
491 {
492 std::vector<IMPORT_PROJECT_DESC> chosen = m_choose_project_handler(
494
495 if( chosen.size() > 0 )
496 schematicToLoad = chosen[0].SchematicId;
497 }
498 }
499
500 if( schematicToLoad.empty() )
501 return nullptr;
502
503 wxString rootBaseName = EscapeString( prjSchematics[schematicToLoad].name, CTX_FILENAME );
504
505 wxFileName rootFname( aFileName );
506 rootFname.SetFullName( rootBaseName + wxS( "." )
507 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
508
509 rootSheet->SetName( prjSchematics[schematicToLoad].name );
510 rootSheet->SetFileName( rootFname.GetFullPath() );
511 rootSheet->GetScreen()->SetFileName( rootFname.GetFullPath() );
512
513 const std::vector<EASYEDAPRO::PRJ_SHEET>& prjSchematicSheets =
514 prjSchematics[schematicToLoad].sheets;
515
516 LoadAllDataFromProject( aFileName );
517
518 if( !m_projectData )
519 return nullptr;
520
521 const int schSheetsCount = prjSchematicSheets.size();
522
523 auto cbs = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
524 {
525 if( !name.EndsWith( wxS( ".esch" ) ) )
527
528 wxArrayString nameParts = wxSplit( name, '\\', '\0' );
529
530 if( nameParts.size() == 1 )
531 nameParts = wxSplit( name, '/', '\0' );
532
533 if( nameParts.size() < 3 )
535
536 wxString schematicUuid = nameParts[1];
537 wxString sheetFileName = nameParts[2];
538 wxString sheetId = sheetFileName.BeforeLast( '.' );
539 int sheetId_i;
540 sheetId.ToInt( &sheetId_i );
541
542 if( schematicUuid != schematicToLoad )
544
545 auto prjSheetIt = std::find_if( prjSchematicSheets.begin(), prjSchematicSheets.end(),
546 [&]( const EASYEDAPRO::PRJ_SHEET& s )
547 {
548 return s.id == sheetId_i;
549 } );
550
551 if( prjSheetIt == prjSchematicSheets.end() )
553
554 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
555
556 if( schSheetsCount > 1 )
557 {
558 wxString sheetBaseName =
559 sheetId + wxS( "_" ) + EscapeString( prjSheetIt->name, CTX_FILENAME );
560
561 wxFileName sheetFname( aFileName );
562 sheetFname.SetFullName( sheetBaseName + wxS( "." )
563 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
564
565 wxFileName relSheetPath( sheetFname );
566 relSheetPath.MakeRelativeTo( rootFname.GetPath() );
567
568 std::unique_ptr<SCH_SHEET> subSheet = std::make_unique<SCH_SHEET>( aSchematic );
569 subSheet->SetFileName( relSheetPath.GetFullPath() );
570 subSheet->SetName( prjSheetIt->name );
571
572 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
573 screen->SetFileName( sheetFname.GetFullPath() );
574 screen->SetPageNumber( sheetId );
575 subSheet->SetScreen( screen );
576
577 VECTOR2I pos;
578 pos.x = schIUScale.MilsToIU( 200 );
579 pos.y = schIUScale.MilsToIU( 200 )
580 + ( subSheet->GetSize().y + schIUScale.MilsToIU( 200 ) ) * ( sheetId_i - 1 );
581
582 subSheet->SetPosition( pos );
583
584 SCH_SHEET_PATH sheetPath;
585 sheetPath.push_back( rootSheet );
586 sheetPath.push_back( subSheet.get() );
587 sheetPath.SetPageNumber( sheetId );
588 aSchematic->SetCurrentSheet( sheetPath );
589
590 parser.ParseSchematic( aSchematic, subSheet.get(), project, m_projectData->m_Symbols,
591 m_projectData->m_Blobs, lines, libName );
592
593 rootSheet->GetScreen()->Append( subSheet.release() );
594 }
595 else
596 {
597 parser.ParseSchematic( aSchematic, rootSheet, project, m_projectData->m_Symbols,
598 m_projectData->m_Blobs, lines, libName );
599 }
600
602 };
603 EASYEDAPRO::IterateZipFiles( aFileName, cbs );
604
605 IO_RELEASER<SCH_IO> sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
606
608 LIBRARY_TABLE* table = adapter->ProjectTable().value_or( nullptr );
609 wxCHECK_MSG( table, nullptr, "Could not load symbol lib table." );
610
611 if( !table->HasRow( libName ) )
612 {
613 // Create a new empty symbol library.
614 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
615 wxString libTableUri = wxS( "${KIPRJMOD}/" ) + libFileName.GetFullName();
616
617 // Add the new library to the project symbol library table.
618 LIBRARY_TABLE_ROW& row = table->InsertRow();
619 row.SetNickname( libName );
620 row.SetURI( libTableUri );
621 row.SetType( "KiCad" );
622
623 table->Save();
624
625 adapter->LoadOne( libName );
626 }
627
628 // set properties to prevent save file on every symbol save
629 std::map<std::string, UTF8> properties;
630 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
631
632 for( auto& [symbolUuid, symInfo] : m_projectData->m_Symbols )
633 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symInfo.libSymbol.release(),
634 &properties );
635
636 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
637
639 aSchematic->FixupJunctionsAfterImport();
640
641 return rootSheet;
642}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
void SetPageNumber(const wxString &aPageNumber)
Definition base_screen.h:79
const KIID m_Uuid
Definition eda_item.h:516
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:235
Definition kiid.h:49
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
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:192
Define a library symbol object.
Definition lib_symbol.h:85
SCH_FIELD & GetFootprintField()
Return reference to the footprint field.
Definition lib_symbol.h:344
void SetDescription(const wxString &aDescription)
Gets the Description field text value *‍/.
Definition lib_symbol.h:164
void SetKeyWords(const wxString &aKeyWords)
Definition lib_symbol.h:183
void SetLibId(const LIB_ID &aLibId)
Definition lib_symbol.h:156
virtual void SetName(const wxString &aName)
CHOOSE_PROJECT_HANDLER m_choose_project_handler
Callback to choose projects to import.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Holds all the data relating to one schematic.
Definition schematic.h:88
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:191
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:103
void FixupJunctionsAfterImport()
Add junctions to this schematic where required.
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:171
SCH_SHEET & Root() const
Definition schematic.h:125
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:186
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)
void SetText(const wxString &aText) override
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 ...
SCH_IO(const wxString &aName)
Definition sch_io.h:375
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const KIID & GetUuid() const
Definition sch_screen.h:520
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
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:47
void SetFileName(const wxString &aFilename)
Definition sch_sheet.h:347
void SetName(const wxString &aName)
Definition sch_sheet.h:114
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:116
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(const wxString &aNickname)
Loads or reloads the given library, if it exists.
static REPORTER & GetInstance()
Definition reporter.cpp:190
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
#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
std::unique_ptr< LIB_SYMBOL > libSymbol
std::map< wxString, EASYEDAPRO::BLOB > m_Blobs
std::map< wxString, EASYEDAPRO::SYM_INFO > m_Symbols
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
Definition of file extensions used in Kicad.