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 <pgm_base.h>
25 #include <kiface_base.h>
26 #include <kiway.h>
27 #include <kiway_player.h>
28 
29 #include <wx/app.h>
30 
31 
32 static struct IFACE : public KIFACE_BASE
33 {
34  // Of course all are overloads, implementations of the KIFACE.
35 
36  IFACE( const char* aName, KIWAY::FACE_T aType ) :
37  KIFACE_BASE( aName, aType )
38  {}
39 
40  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
41  {
42  return true;
43  }
44 
45  void OnKifaceEnd() override {}
46 
47  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
48  {
49  assert( false );
50  return nullptr;
51  }
52 
64  void* IfaceOrAddress( int aDataId ) override
65  {
66  return NULL;
67  }
68 }
69  kiface( "pcb_test_frame", KIWAY::FACE_PCB );
70 
71 static struct PGM_TEST_FRAME : public PGM_BASE
72 {
73  bool OnPgmInit();
74 
75  void OnPgmExit()
76  {
77  Kiway.OnKiwayEnd();
78 
79  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
80  // earlier than wxApp and earlier than static destruction would.
82  }
83 
84  void MacOpenFile( const wxString& aFileName ) override
85  {
86  wxFileName filename( aFileName );
87 
88  if( filename.FileExists() )
89  {
90 #if 0
91  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
92  // the single_top link image.
93  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
94 #else
95  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
96 #endif
97 
98  if( frame )
99  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
100  }
101  }
102 }
103  program;
104 
106 {
107  return program;
108 }
109 
110 
111 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
112 // is run from a python script, mot from a Kicad application
114 {
115  return &program;
116 }
117 
118 
120 {
121  return kiface;
122 }
123 
124 
125 class MOCK_PLAYER : public KIWAY_PLAYER
126 {
127 public:
128  MOCK_PLAYER( KIWAY *aKiway ) :
129  KIWAY_PLAYER( aKiway, nullptr, FRAME_SCH, wxT( "Mock" ), wxDefaultPosition,
130  wxDefaultSize, wxDEFAULT_FRAME_STYLE )
131  {}
132 
133  ~MOCK_PLAYER();
134 };
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:118
PGM_TEST_FRAME program
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
A KIFACE implementation.
Definition: kiface_base.h:37
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Definition: mock_pgm.cpp:40
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
Definition: mock_pgm.cpp:84
Container for data for KiCad programs.
Definition: pgm_base.h:93
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:134
void Destroy()
Definition: pgm_base.cpp:126
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: mock_pgm.cpp:47
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: mock_pgm.cpp:45
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: mock_pgm.cpp:36
void OnKiwayEnd()
Definition: kiway.cpp:641
void OnPgmExit()
Definition: mock_pgm.cpp:75
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
MOCK_PLAYER(KIWAY *aKiway)
Definition: mock_pgm.cpp:128
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
pcbnew DSO
Definition: kiway.h:269
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: mock_pgm.cpp:64
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: mock_pgm.cpp:113
FACE_T
Known KIFACE implementations.
Definition: kiway.h:266
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: mock_pgm.cpp:119
see class PGM_BASE
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: mock_pgm.cpp:105
int PGM_BASE * aProgram
Definition: cvpcb.cpp:110
KIWAY Kiway