|
|
@ -44,6 +44,11 @@ |
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <sexpr/sexpr.h>
|
|
|
|
#include <sexpr/sexpr_parser.h>
|
|
|
|
#include <kiface_ids.h>
|
|
|
|
#include <netlist_exporters/netlist_exporter_kicad.h>
|
|
|
|
|
|
|
|
#include <schematic.h>
|
|
|
|
#include <connection_graph.h>
|
|
|
|
|
|
|
|
// The main sheet of the project
|
|
|
|
SCH_SHEET* g_RootSheet = NULL; |
|
|
@ -54,6 +59,59 @@ TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 ); |
|
|
|
|
|
|
|
namespace SCH { |
|
|
|
|
|
|
|
|
|
|
|
static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFilename ) |
|
|
|
{ |
|
|
|
auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ); |
|
|
|
std::unique_ptr<SCHEMATIC> schematic( new SCHEMATIC ( nullptr ) ); |
|
|
|
|
|
|
|
auto &manager = Pgm().GetSettingsManager(); |
|
|
|
|
|
|
|
manager.LoadProject( "" ); |
|
|
|
schematic->Reset(); |
|
|
|
schematic->SetProject( &manager.Prj() ); |
|
|
|
schematic->SetRoot( pi->Load( aFilename, schematic.get() ) ); |
|
|
|
schematic->CurrentSheet().push_back( &schematic->Root() ); |
|
|
|
|
|
|
|
SCH_SCREENS screens( schematic->Root() ); |
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) |
|
|
|
screen->UpdateLocalLibSymbolLinks(); |
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = schematic->GetSheets(); |
|
|
|
|
|
|
|
// Restore all of the loaded symbol instances from the root sheet screen.
|
|
|
|
sheets.UpdateSymbolInstances( schematic->RootScreen()->GetSymbolInstances() ); |
|
|
|
|
|
|
|
sheets.AnnotatePowerSymbols(); |
|
|
|
|
|
|
|
// NOTE: This is required for multi-unit symbols to be correct
|
|
|
|
// Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
|
|
|
|
for( SCH_SHEET_PATH& sheet : sheets ) |
|
|
|
sheet.UpdateAllScreenReferences(); |
|
|
|
|
|
|
|
// NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
|
|
|
|
// SchematicCleanUp must be freed from its UI dependencies.
|
|
|
|
|
|
|
|
schematic->ConnectionGraph()->Recalculate( sheets, true ); |
|
|
|
|
|
|
|
return schematic; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool generateSchematicNetlist( const wxString& aFilename, wxString& aNetlist ) |
|
|
|
{ |
|
|
|
std::unique_ptr<SCHEMATIC> schematic ( readSchematicFromFile( (const char*) aFilename ) ); |
|
|
|
NETLIST_EXPORTER_KICAD exporter( schematic.get() ); |
|
|
|
STRING_FORMATTER formatter; |
|
|
|
|
|
|
|
exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD ); |
|
|
|
aNetlist = formatter.GetString(); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static struct IFACE : public KIFACE_I |
|
|
|
{ |
|
|
|
// Of course all are virtual overloads, implementations of the KIFACE.
|
|
|
@ -123,6 +181,11 @@ static struct IFACE : public KIFACE_I |
|
|
|
*/ |
|
|
|
void* IfaceOrAddress( int aDataId ) override |
|
|
|
{ |
|
|
|
switch( aDataId ) |
|
|
|
{ |
|
|
|
case KIFACE_NETLIST_SCHEMATIC: |
|
|
|
return (void*) generateSchematicNetlist; |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|