1 /*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2010 jean-pierre.charras
5 * Copyright (C) 1992-2021 Kicad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25 #include <bitmap2cmp_gui.h>
26 #include <bitmap2cmp_settings.h>
27 #include <kiface_base.h>
28 #include <kiway.h>
29 #include <pgm_base.h>
30 #include <settings/settings_manager.h>
31
32
33 namespace BMP2CMP {
34
35 static struct IFACE : public KIFACE_BASE
36 {
37 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
38
CreateWindowBMP2CMP::IFACE39 wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
40 int aCtlBits = 0 ) override
41 {
42 InitSettings( new BITMAP2CMP_SETTINGS );
43 Pgm().GetSettingsManager().RegisterSettings( KifaceSettings() );
44 return new BM2CMP_FRAME( aKiway, aParent );
45 }
46
47 /**
48 * Return a pointer to the requested object.
49 *
50 * The safest way to use this is to retrieve a pointer to a static instance of an interface,
51 * similar to how the KIFACE interface is exported. But if you know what you are doing use
52 * it to retrieve anything you want.
53 *
54 * @param aDataId identifies which object you want the address of.
55 * @return the object which must be cast into the known type.
56 */
IfaceOrAddressBMP2CMP::IFACE57 void* IfaceOrAddress( int aDataId ) override
58 {
59 return nullptr;
60 }
61
IFACEBMP2CMP::IFACE62 IFACE( const char* aDSOname, KIWAY::FACE_T aType ) :
63 KIFACE_BASE( aDSOname, aType )
64 {}
65
66 } kiface( "BMP2CMP", KIWAY::FACE_BMP2CMP );
67
68 } // namespace BMP2CMP
69
70 using namespace BMP2CMP;
71
72 static PGM_BASE* process;
73
74
Kiface()75 KIFACE_BASE& Kiface()
76 {
77 return kiface;
78 }
79
80
81 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
82 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
KIFACE_GETTER(int * aKIFACEversion,int aKIWAYversion,PGM_BASE * aProgram)83 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
84 {
85 process = (PGM_BASE*) aProgram;
86 return &kiface;
87 }
88
89
90 #if defined(BUILD_KIWAY_DLLS)
Pgm()91 PGM_BASE& Pgm()
92 {
93 wxASSERT( process ); // KIFACE_GETTER has already been called.
94 return *process;
95 }
96
97
98 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from a python script.
PgmOrNull()99 PGM_BASE* PgmOrNull()
100 {
101 return process;
102 }
103 #endif
104
105
OnKifaceStart(PGM_BASE * aProgram,int aCtlBits)106 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
107 {
108 return start_common( aCtlBits );
109 }
110