KiCad PCB EDA Suite
pcb_calculator.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) 2015 jean-pierre.charras
5  * Copyright (C) 2015 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 3
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 along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <pgm_base.h>
22 #include <kiface_i.h>
24 
25 #include "pcb_calculator_frame.h"
27 
28 // Pcb_calculator data file extension:
29 const wxString PcbCalcDataFileExt( wxT("pcbcalc") );
30 
31 
32 // PCB_CALCULATOR_APP
33 
34 
35 namespace PCBCALC {
36 
37 static struct IFACE : public KIFACE_I
38 {
39  // Of course all are virtual overloads, implementations of the KIFACE.
40 
41  IFACE( const char* aName, KIWAY::FACE_T aType ) :
42  KIFACE_I( aName, aType )
43  {}
44 
45  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
46 
47  void OnKifaceEnd() override;
48 
49  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
50  {
51  return new PCB_CALCULATOR_FRAME( aKiway, aParent );
52  }
53 
65  void* IfaceOrAddress( int aDataId ) override
66  {
67  return NULL;
68  }
69 
70 } kiface( "pcb_calculator", KIWAY::FACE_PCB_CALCULATOR );
71 
72 } // namespace
73 
74 using namespace PCBCALC;
75 
76 static PGM_BASE* process;
77 
78 KIFACE_I& Kiface() { return kiface; }
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.
83 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
84 {
86  return &kiface;
87 }
88 
89 
91 {
92  wxASSERT( process ); // KIFACE_GETTER has already been called.
93  return *process;
94 }
95 
96 
97 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from a python script.
99 {
100  return process;
101 }
102 
103 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
104 {
107  start_common( aCtlBits );
108 
109  return true;
110 }
111 
112 
114 {
115  end_common();
116 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
A KIFACE (I)mplementation.
Definition: kiface_i.h:37
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:88
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
const wxString PcbCalcDataFileExt(wxT("pcbcalc"))
Container for data for KiCad programs.
Definition: pgm_base.h:131
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
IFACE(const char *aName, KIWAY::FACE_T aType)
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:92
#define NULL
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:98
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
#define KIFACE_GETTER
Definition: kiway.h:109
FACE_T
Known KIFACE implementations.
Definition: kiway.h:266
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
see class PGM_BASE
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:147
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_i.h:94
PGM_BASE & Pgm()
The global Program "get" accessor.
static PGM_BASE * process
int aKiwayVersion
int PGM_BASE * aProgram
PCBCALC::IFACE KIFACE_I kiface("pcb_calculator", KIWAY::FACE_PCB_CALCULATOR)