KiCad PCB EDA Suite
eeschema.cpp File Reference

Go to the source code of this file.

Classes

struct  SCH::IFACE
 

Namespaces

namespace  SCH
 

Functions

static std::unique_ptr< SCHEMATICSCH::readSchematicFromFile (const std::string &aFilename)
 
bool SCH::generateSchematicNetlist (const wxString &aFilename, wxString &aNetlist)
 
SCH::IFACE KIFACE_BASE, UNITS_PROVIDER SCH::kiface ("eeschema", KIWAY::FACE_SCH)
 
 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits) override
 
void OnKifaceEnd () override
 
wxWindow * CreateKiWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 
void * IfaceOrAddress (int aDataId) override
 Return a pointer to the requested object. More...
 
void SaveFileAs (const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
 Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating). More...
 
int HandleJob (JOB *aJob) override
 
KIFACE_BASEKiface ()
 Global KIFACE_BASE "get" accessor. More...
 
 MY_API (KIFACE *) KIFACE_GETTER(int *aKIFACEversion
 
PGM_BASEPgm ()
 The global Program "get" accessor. More...
 
PGM_BASEPgmOrNull ()
 similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from a script, not from a kicad appl More...
 
static void traverseSEXPR (SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
 

Variables

SCH_SHEETg_RootSheet = nullptr
 
std::unique_ptr< EESCHEMA_JOBS_HANDLERm_jobHandler
 
static PGM_BASEprocess
 
int aKiwayVersion
 
int PGM_BASEaProgram
 
return & kiface
 

Function Documentation

◆ CreateKiWindow()

wxWindow * kiface::CreateKiWindow ( wxWindow *  aParent,
int  aClassId,
KIWAY aKiway,
int  aCtlBits = 0 
)
override

Definition at line 11 of file eeschema.cpp.

19 :
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <pgm_base.h>
27#include <kiface_base.h>
28#include <confirm.h>
29#include <gestfich.h>
30#include <eda_dde.h>
32#include "eeschema_helpers.h"
33#include <eeschema_settings.h>
34#include <sch_edit_frame.h>
35#include <symbol_edit_frame.h>
36#include <symbol_viewer_frame.h>
37#include <transform.h>
38#include <symbol_lib_table.h>
41#include <kiway.h>
44#include <sexpr/sexpr.h>
45#include <sexpr/sexpr_parser.h>
46#include <kiface_ids.h>
48#include <wx/ffile.h>
50
51#include <schematic.h>
52#include <connection_graph.h>
62#include <sim/sim_plot_frame.h>
63
64#include <wx/crt.h>
65
66// The main sheet of the project
67SCH_SHEET* g_RootSheet = nullptr;
68
69
70namespace SCH {
71
72
73static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFilename )
74{
75 auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
76 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr );
77
78 auto &manager = Pgm().GetSettingsManager();
79
80 manager.LoadProject( "" );
81 schematic->Reset();
82 schematic->SetProject( &manager.Prj() );
83 schematic->SetRoot( pi->Load( aFilename, schematic.get() ) );
84 schematic->CurrentSheet().push_back( &schematic->Root() );
85
86 SCH_SCREENS screens( schematic->Root() );
87
88 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
89 screen->UpdateLocalLibSymbolLinks();
90
91 SCH_SHEET_LIST sheets = schematic->GetSheets();
92
93 // Restore all of the loaded symbol instances from the root sheet screen.
94 sheets.UpdateSymbolInstanceData( schematic->RootScreen()->GetSymbolInstances() );
95
96 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
97 screen->MigrateSimModels();
98
99 sheets.AnnotatePowerSymbols();
100
101 // NOTE: This is required for multi-unit symbols to be correct
102 for( SCH_SHEET_PATH& sheet : sheets )
103 sheet.UpdateAllScreenReferences();
104
105 // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
106 // SchematicCleanUp must be freed from its UI dependencies.
107
108 schematic->ConnectionGraph()->Recalculate( sheets, true );
109
110 return schematic;
111}
112
113
114bool generateSchematicNetlist( const wxString& aFilename, wxString& aNetlist )
115{
116 std::unique_ptr<SCHEMATIC> schematic = readSchematicFromFile( aFilename.ToStdString() );
117 NETLIST_EXPORTER_KICAD exporter( schematic.get() );
118 STRING_FORMATTER formatter;
119
120 exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD );
121 aNetlist = formatter.GetString();
122
123 return true;
124}
Generate the KiCad netlist format supported by Pcbnew.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:135
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:656
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:415
const std::string & GetString()
Definition: richio.h:438
This file is part of the common library.
DDE server & client.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:67
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: eeschema.cpp:312
Definition: eeschema.cpp:70
static std::unique_ptr< SCHEMATIC > readSchematicFromFile(const std::string &aFilename)
Definition: eeschema.cpp:73
bool generateSchematicNetlist(const wxString &aFilename, wxString &aNetlist)
Definition: eeschema.cpp:114
#define GNL_ALL
@ GNL_OPT_KICAD
see class PGM_BASE
Definition of file extensions used in Kicad.

◆ HandleJob()

int kiface::HandleJob ( JOB aJob)
override

◆ IFACE()

kiface::IFACE ( const char *  aName,
KIWAY::FACE_T  aType 
)

Definition at line 2 of file eeschema.cpp.

19 :
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

◆ IfaceOrAddress()

void * kiface::IfaceOrAddress ( int  aDataId)
override

Return a pointer to the requested object.

The safest way to use this is to retrieve a pointer to a static instance of an interface, similar to how the KIFACE interface is exported. But if you know what you are doing use it to retrieve anything you want.

Parameters
aDataIdidentifies which object you want the address of.
Returns
the object requested and must be cast into the know type.

Definition at line 136 of file eeschema.cpp.

142 {
143 switch( aClassId )
144 {
145 case FRAME_SCH:
@ FRAME_SCH
Definition: frame_type.h:34

◆ Kiface()

KIFACE_BASE & Kiface ( )

Global KIFACE_BASE "get" accessor.

Definition at line 300 of file eeschema.cpp.

300{ return kiface; }
return & kiface
Definition: eeschema.cpp:308

References kiface.

Referenced by SCH::IFACE::CreateKiWindow().

◆ MY_API()

MY_API ( KIFACE )

◆ OnKifaceEnd()

void kiface::OnKifaceEnd ( )
override

Definition at line 11 of file test_app_main.cpp.

18:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

◆ OnKifaceStart()

bool kiface::OnKifaceStart ( PGM_BASE aProgram,
int  aCtlBits 
)
override

Definition at line 6 of file test_app_main.cpp.

18 :
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

◆ Pgm()

PGM_BASE & Pgm ( )

The global Program "get" accessor.

Implemented in: 1) common/single_top.cpp, 2) kicad/kicad.cpp, and 3) scripting/kiway.i

Definition at line 312 of file eeschema.cpp.

313{
314 wxASSERT( process ); // KIFACE_GETTER has already been called.
315 return *process;
316}
static PGM_BASE * process
Definition: eeschema.cpp:297

References process.

Referenced by SCH::readSchematicFromFile().

◆ PgmOrNull()

PGM_BASE * PgmOrNull ( )

similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from a script, not from a kicad appl

Definition at line 320 of file eeschema.cpp.

321{
322 return process;
323}

References process.

◆ SaveFileAs()

void kiface::SaveFileAs ( const wxString &  aProjectBasePath,
const wxString &  aProjectName,
const wxString &  aNewProjectBasePath,
const wxString &  aNewProjectName,
const wxString &  aSrcFilePath,
wxString &  aErrors 
)
override

Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating).

References KIWAY_PLAYER::CreateServer(), and KICAD_SCH_PORT_SERVICE_NUMBER.

◆ traverseSEXPR()

static void traverseSEXPR ( SEXPR::SEXPR aNode,
const std::function< void(SEXPR::SEXPR *)> &  aVisitor 
)
static

Definition at line 381 of file eeschema.cpp.

383{
384 aVisitor( aNode );
385
386 if( aNode->IsList() )
387 {
388 for( unsigned i = 0; i < aNode->GetNumberOfChildren(); i++ )
389 traverseSEXPR( aNode->GetChild( i ), aVisitor );
390 }
391}
size_t GetNumberOfChildren() const
Definition: sexpr.cpp:70
bool IsList() const
Definition: sexpr.h:49
SEXPR * GetChild(size_t aIndex) const
Definition: sexpr.cpp:48
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
Definition: eeschema.cpp:381

References SEXPR::SEXPR::GetChild(), SEXPR::SEXPR::GetNumberOfChildren(), SEXPR::SEXPR::IsList(), and traverseSEXPR().

Referenced by SCH::IFACE::SaveFileAs(), and traverseSEXPR().

Variable Documentation

◆ aKiwayVersion

int aKiwayVersion

Definition at line 305 of file eeschema.cpp.

◆ aProgram

int PGM_BASE* aProgram
Initial value:
{
int PGM_BASE * aProgram
Definition: eeschema.cpp:306

Definition at line 305 of file eeschema.cpp.

Referenced by SCH::IFACE::OnKifaceStart().

◆ g_RootSheet

SCH_SHEET* g_RootSheet = nullptr

Definition at line 67 of file eeschema.cpp.

◆ kiface

return& kiface

Definition at line 308 of file eeschema.cpp.

Referenced by Kiface().

◆ m_jobHandler

std::unique_ptr<EESCHEMA_JOBS_HANDLER> m_jobHandler
private

Definition at line 160 of file eeschema.cpp.

◆ process

PGM_BASE* process
static

Definition at line 297 of file eeschema.cpp.

Referenced by Pgm(), and PgmOrNull().