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