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-2021 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 <kiface_base.h>
25 #include <pgm_base.h>
26 #include <transform.h>
27 
28 #include <sch_edit_frame.h>
30 
31 #include <wx/app.h>
32 
33 
34 // a transform matrix, to display components in lib editor
36 
37 
38 static struct IFACE : public KIFACE_BASE
39 {
40  // Of course all are overloads, implementations of the KIFACE.
41 
42  IFACE( const char* aName, KIWAY::FACE_T aType ) : KIFACE_BASE( aName, aType )
43  {
44  }
45 
46  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
47  {
48  return true;
49  }
50 
51  void OnKifaceEnd() override
52  {
53  }
54 
55  wxWindow* CreateWindow(
56  wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
57  {
58  assert( false );
59  return nullptr;
60  }
61 
72  void* IfaceOrAddress( int aDataId ) override
73  {
74  return nullptr;
75  }
76 } kiface( "mock_eeschema", KIWAY::FACE_SCH );
77 
78 
79 static struct PGM_MOCK_EESCHEMA_FRAME : public PGM_BASE
80 {
81  bool OnPgmInit();
82 
83  void OnPgmExit()
84  {
85  Kiway.OnKiwayEnd();
86 
87  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
88  // earlier than wxApp and earlier than static destruction would.
89  //PGM_BASE::Destroy();
90  }
91 
92  void MacOpenFile( const wxString& aFileName ) override
93  {
94  wxFileName filename( aFileName );
95 
96  if( filename.FileExists() )
97  {
98 #if 0
99  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
100  // the single_top link image.
101  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
102 #else
103  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
104 #endif
105 
106  if( frame )
107  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
108  }
109  }
110 } program;
111 
112 
114 {
115  return program;
116 }
117 
118 
119 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from
120 // a python script or something else.
121 // Therefore here return always nullptr
123 {
124  return nullptr;
125 }
126 
127 
129 {
130  return kiface;
131 }
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
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
PGM_MOCK_EESCHEMA_FRAME program
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
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:132
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
void OnKiwayEnd()
Definition: kiway.cpp:641
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
FACE_T
Known KIFACE implementations.
Definition: kiway.h:266
eeschema DSO
Definition: kiway.h:268
see class PGM_BASE
IFACE(const char *aDSOname, KIWAY::FACE_T aType)
PGM_BASE & Pgm()
The global Program "get" accessor.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
TRANSFORM DefaultTransform
IFACE KIFACE_BASE kiface("mock_eeschema", KIWAY::FACE_SCH)
int PGM_BASE * aProgram
Definition: cvpcb.cpp:110
KIWAY Kiway