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>
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 <json_common.h>
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
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 // Virtual root sheet UUID must be the same as the schematic file UUID.
461 const_cast<KIID&>( rootSheet->m_Uuid ) = screen->GetUuid();
462 }
463
464 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Project() );
465 wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) );
466
467 SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
468 wxFileName fname( aFileName );
469 wxString libName = EASYEDAPRO::ShortenLibName( fname.GetName() );
470
471 wxFileName libFileName( fname.GetPath(), libName, FILEEXT::KiCadSymbolLibFileExtension );
472
473 if( fname.GetExt() != wxS( "epro" ) && fname.GetExt() != wxS( "zip" ) )
474 return rootSheet;
475
476 nlohmann::json project = EASYEDAPRO::ReadProjectOrDeviceFile( aFileName );
477
478 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics = project.at( "schematics" );
479
480 wxString schematicToLoad;
481
482 if( aProperties && aProperties->contains( "sch_id" ) )
483 {
484 schematicToLoad = wxString::FromUTF8( aProperties->at( "sch_id" ) );
485 }
486 else
487 {
488 if( prjSchematics.size() == 1 )
489 {
490 schematicToLoad = prjSchematics.begin()->first;
491 }
492 else
493 {
494 std::vector<IMPORT_PROJECT_DESC> chosen = m_choose_project_handler(
496
497 if( chosen.size() > 0 )
498 schematicToLoad = chosen[0].SchematicId;
499 }
500 }
501
502 if( schematicToLoad.empty() )
503 return nullptr;
504
505 wxString rootBaseName = EscapeString( prjSchematics[schematicToLoad].name, CTX_FILENAME );
506
507 wxFileName rootFname( aFileName );
508 rootFname.SetFullName( rootBaseName + wxS( "." )
509 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
510
511 rootSheet->SetName( prjSchematics[schematicToLoad].name );
512 rootSheet->SetFileName( rootFname.GetFullPath() );
513 rootSheet->GetScreen()->SetFileName( rootFname.GetFullPath() );
514
515 const std::vector<EASYEDAPRO::PRJ_SHEET>& prjSchematicSheets =
516 prjSchematics[schematicToLoad].sheets;
517
518 LoadAllDataFromProject( aFileName );
519
520 if( !m_projectData )
521 return nullptr;
522
523 const int schSheetsCount = prjSchematicSheets.size();
524
525 auto cbs = [&]( const wxString& name, const wxString& baseName, wxInputStream& zip ) -> bool
526 {
527 if( !name.EndsWith( wxS( ".esch" ) ) )
529
530 wxArrayString nameParts = wxSplit( name, '\\', '\0' );
531
532 if( nameParts.size() == 1 )
533 nameParts = wxSplit( name, '/', '\0' );
534
535 if( nameParts.size() < 3 )
537
538 wxString schematicUuid = nameParts[1];
539 wxString sheetFileName = nameParts[2];
540 wxString sheetId = sheetFileName.BeforeLast( '.' );
541 int sheetId_i;
542 sheetId.ToInt( &sheetId_i );
543
544 if( schematicUuid != schematicToLoad )
546
547 auto prjSheetIt = std::find_if( prjSchematicSheets.begin(), prjSchematicSheets.end(),
548 [&]( const EASYEDAPRO::PRJ_SHEET& s )
549 {
550 return s.id == sheetId_i;
551 } );
552
553 if( prjSheetIt == prjSchematicSheets.end() )
555
556 std::vector<nlohmann::json> lines = EASYEDAPRO::ParseJsonLines( zip, name );
557
558 if( schSheetsCount > 1 )
559 {
560 wxString sheetBaseName =
561 sheetId + wxS( "_" ) + EscapeString( prjSheetIt->name, CTX_FILENAME );
562
563 wxFileName sheetFname( aFileName );
564 sheetFname.SetFullName( sheetBaseName + wxS( "." )
565 + wxString::FromUTF8( FILEEXT::KiCadSchematicFileExtension ) );
566
567 wxFileName relSheetPath( sheetFname );
568 relSheetPath.MakeRelativeTo( rootFname.GetPath() );
569
570 std::unique_ptr<SCH_SHEET> subSheet = std::make_unique<SCH_SHEET>( aSchematic );
571 subSheet->SetFileName( relSheetPath.GetFullPath() );
572 subSheet->SetName( prjSheetIt->name );
573
574 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
575 screen->SetFileName( sheetFname.GetFullPath() );
576 screen->SetPageNumber( sheetId );
577 subSheet->SetScreen( screen );
578
579 VECTOR2I pos;
580 pos.x = schIUScale.MilsToIU( 200 );
581 pos.y = schIUScale.MilsToIU( 200 )
582 + ( subSheet->GetSize().y + schIUScale.MilsToIU( 200 ) ) * ( sheetId_i - 1 );
583
584 subSheet->SetPosition( pos );
585
586 SCH_SHEET_PATH sheetPath;
587 sheetPath.push_back( rootSheet );
588 sheetPath.push_back( subSheet.get() );
589 sheetPath.SetPageNumber( sheetId );
590 aSchematic->SetCurrentSheet( sheetPath );
591
592 parser.ParseSchematic( aSchematic, subSheet.get(), project, m_projectData->m_Symbols,
593 m_projectData->m_Blobs, lines, libName );
594
595 rootSheet->GetScreen()->Append( subSheet.release() );
596 }
597 else
598 {
599 parser.ParseSchematic( aSchematic, rootSheet, project, m_projectData->m_Symbols,
600 m_projectData->m_Blobs, lines, libName );
601 }
602
604 };
605 EASYEDAPRO::IterateZipFiles( aFileName, cbs );
606
607 IO_RELEASER<SCH_IO> sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
608
609 if( !libTable->HasLibrary( libName ) )
610 {
611 // Create a new empty symbol library.
612 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
613 wxString libTableUri = wxS( "${KIPRJMOD}/" ) + libFileName.GetFullName();
614
615 // Add the new library to the project symbol library table.
616 libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( libName, libTableUri, wxS( "KiCad" ) ) );
617
618 // Save project symbol library table.
619 wxFileName fn( aSchematic->Project().GetProjectPath(),
621
622 // So output formatter goes out of scope and closes the file before reloading.
623 {
624 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
625 libTable->Format( &formatter, 0 );
626 }
627
628 // Relaod the symbol library table.
629 aSchematic->Project().SetElem( PROJECT::ELEM::SYMBOL_LIB_TABLE, NULL );
630 PROJECT_SCH::SchSymbolLibTable( &aSchematic->Project() );
631 }
632
633 // set properties to prevent save file on every symbol save
634 std::map<std::string, UTF8> properties;
635 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
636
637 for( auto& [symbolUuid, symInfo] : m_projectData->m_Symbols )
638 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symInfo.libSymbol.release(),
639 &properties );
640
641 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
642
644 aSchematic->FixupJunctionsAfterImport();
645
646 return rootSheet;
647}
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
Used for text file output.
Definition richio.h:491
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:220
Definition kiid.h:49
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:163
void SetKeyWords(const wxString &aKeyWords)
Definition lib_symbol.h:180
void SetLibId(const LIB_ID &aLibId)
Definition lib_symbol.h:155
virtual void SetName(const wxString &aName)
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:375
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:162
@ SYMBOL_LIB_TABLE
Definition project.h:77
Holds all the data relating to one schematic.
Definition schematic.h:88
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:176
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:156
SCH_SHEET & Root() const
Definition schematic.h:140
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:171
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:373
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const KIID & GetUuid() const
Definition sch_screen.h:539
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:327
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.
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: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.