KiCad PCB EDA Suite
mocks_eeschema.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) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <kiface_i.h>
25 #include <pgm_base.h>
26 #include <transform.h>
27 
28 #include <sch_edit_frame.h>
30 
31 
32 // a transform matrix, to display components in lib editor
34 
35 static struct IFACE : public KIFACE_I
36 {
37  // Of course all are overloads, implementations of the KIFACE.
38 
39  IFACE( const char* aName, KIWAY::FACE_T aType ) : KIFACE_I( aName, aType )
40  {
41  }
42 
43  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
44  {
45  return true;
46  }
47 
48  void OnKifaceEnd() override
49  {
50  }
51 
52  wxWindow* CreateWindow(
53  wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
54  {
55  assert( false );
56  return nullptr;
57  }
58 
70  void* IfaceOrAddress( int aDataId ) override
71  {
72  return NULL;
73  }
74 } kiface( "mock_eeschema", KIWAY::FACE_SCH );
75 
76 static struct PGM_MOCK_EESCHEMA_FRAME : public PGM_BASE
77 {
78  bool OnPgmInit();
79 
80  void OnPgmExit()
81  {
82  Kiway.OnKiwayEnd();
83 
84  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
85  // earlier than wxApp and earlier than static destruction would.
87  }
88 
89  void MacOpenFile( const wxString& aFileName ) override
90  {
91  wxFileName filename( aFileName );
92 
93  if( filename.FileExists() )
94  {
95 #if 0
96  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
97  // the single_top link image.
98  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
99 #else
100  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
101 #endif
102 
103  if( frame )
104  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
105  }
106  }
107 } program;
108 
110 {
111  return program;
112 }
113 
114 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from
115 // a python script or something else.
116 // Therefore here return always nullptr
118 {
119  return nullptr;
120 }
121 
122 
124 {
125  return kiface;
126 }
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList.
Definition: kiway_player.h:118
KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIFACE.
Definition: kiface_i.h:37
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
PGM_MOCK_EESCHEMA_FRAME program
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
void MacOpenFile(const wxString &aFileName) override
Function MacOpenFile is specific to MacOSX (not used under Linux or Windows).
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:138
void Destroy()
Definition: pgm_base.cpp:127
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Function CreateWindow creates a wxWindow for the current project.
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
IFACE(const char *aName, KIWAY::FACE_T aType)
void OnKiwayEnd()
Definition: kiway.cpp:542
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
#define NULL
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
int PGM_BASE * aProgram
Definition: cvpcb/cvpcb.cpp:97
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
FACE_T
Known KIFACE implementations.
Definition: kiway.h:279
eeschema DSO
Definition: kiway.h:281
see class PGM_BASE
IFACE KIFACE_I kiface("mock_eeschema", KIWAY::FACE_SCH)
PGM_BASE & Pgm()
The global Program "get" accessor.
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
TRANSFORM DefaultTransform
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
KIWAY Kiway