KiCad PCB EDA Suite
mock_pgm.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) 1992-2020 KiCad Developers, see AUTHORS.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 <fctsys.h>
25 #include <pgm_base.h>
26 #include <kiface_i.h>
27 #include <kiway.h>
28 #include <kiway_player.h>
29 
30 
31 static struct IFACE : public KIFACE_I
32 {
33  // Of course all are overloads, implementations of the KIFACE.
34 
35  IFACE( const char* aName, KIWAY::FACE_T aType ) :
36  KIFACE_I( aName, aType )
37  {}
38 
39  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
40  {
41  return true;
42  }
43 
44  void OnKifaceEnd() override {}
45 
46  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
47  {
48  assert( false );
49  return nullptr;
50  }
51 
63  void* IfaceOrAddress( int aDataId ) override
64  {
65  return NULL;
66  }
67 }
68  kiface( "pcb_test_frame", KIWAY::FACE_PCB );
69 
70 static struct PGM_TEST_FRAME : public PGM_BASE
71 {
72  bool OnPgmInit();
73 
74  void OnPgmExit()
75  {
76  Kiway.OnKiwayEnd();
77 
78  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
79  // earlier than wxApp and earlier than static destruction would.
81  }
82 
83  void MacOpenFile( const wxString& aFileName ) override
84  {
85  wxFileName filename( aFileName );
86 
87  if( filename.FileExists() )
88  {
89 #if 0
90  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
91  // the single_top link image.
92  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
93 #else
94  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
95 #endif
96 
97  if( frame )
98  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
99  }
100  }
101 }
102  program;
103 
105 {
106  return program;
107 }
108 
109 
110 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
111 // is run from a python script, mot from a Kicad application
113 {
114  return &program;
115 }
116 
117 
119 {
120  return kiface;
121 }
122 
123 
124 class MOCK_PLAYER : public KIWAY_PLAYER
125 {
126 public:
127  MOCK_PLAYER( KIWAY *aKiway ) :
128  KIWAY_PLAYER( aKiway, nullptr, FRAME_SCH, wxT( "Mock" ), wxDefaultPosition,
129  wxDefaultSize, wxDEFAULT_FRAME_STYLE )
130  {}
131 
132  ~MOCK_PLAYER();
133 };
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
PGM_TEST_FRAME program
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
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
Definition: mock_pgm.cpp:39
void MacOpenFile(const wxString &aFileName) override
Function MacOpenFile is specific to MacOSX (not used under Linux or Windows).
Definition: mock_pgm.cpp:83
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: mock_pgm.cpp:118
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.
Definition: mock_pgm.cpp:46
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: mock_pgm.cpp:44
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: mock_pgm.cpp:35
void OnKiwayEnd()
Definition: kiway.cpp:538
IFACE KIFACE_I kiface("pcb_test_frame", KIWAY::FACE_PCB)
#define NULL
void OnPgmExit()
Definition: mock_pgm.cpp:74
MOCK_PLAYER(KIWAY *aKiway)
Definition: mock_pgm.cpp:127
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
pcbnew DSO
Definition: kiway.h:282
int PGM_BASE * aProgram
Definition: cvpcb/cvpcb.cpp:97
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: mock_pgm.cpp:63
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: mock_pgm.cpp:112
FACE_T
Known KIFACE implementations.
Definition: kiway.h:279
see class PGM_BASE
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: mock_pgm.cpp:104
KIWAY Kiway