~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to include/pgm_base.h

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This program source code file is part of KiCad, a free EDA CAD application.
3
 
 *
4
 
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5
 
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
6
 
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License
10
 
 * as published by the Free Software Foundation; either version 2
11
 
 * of the License, or (at your option) any later version.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program; if not, you may find one here:
20
 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21
 
 * or you may search the http://www.gnu.org website for the version 2 license,
22
 
 * or you may write to the Free Software Foundation, Inc.,
23
 
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
24
 
 */
25
 
 
26
 
/**
27
 
 * @file pgm_base.h
28
 
 * @brief see class PGM_BASE
29
 
 */
30
 
 
31
 
#ifndef  PGM_BASE_H_
32
 
#define  PGM_BASE_H_
33
 
 
34
 
#include <wx/filename.h>
35
 
#include <search_stack.h>
36
 
#include <wx/gdicmn.h>
37
 
 
38
 
 
39
 
class wxConfigBase;
40
 
class wxSingleInstanceChecker;
41
 
class wxHtmlHelpController;
42
 
class wxApp;
43
 
class wxMenu;
44
 
 
45
 
// inter program module calling
46
 
#define VTBL_ENTRY      virtual
47
 
 
48
 
 
49
 
/**
50
 
 * Class PGM_BASE
51
 
 * keeps program (whole process) data for KiCad programs.
52
 
 * The VTBL_ENTRY functions are VTBL_ENTRY so we can do cross module calls
53
 
 * without linking to them.  This used to be a wxApp derivative, but that
54
 
 * is difficult under wxPython which shapes the wxApp. So now this is a "side-car"
55
 
 * (like a motorcycle side-car) object with a back pointer into the wxApp
56
 
 * which initializes it.
57
 
 * <p>
58
 
 * OnPgmStart() is virtual, may be overridden, and parallels
59
 
 * wxApp::OnInit(), from where it should called.
60
 
 * <p>
61
 
 * OnPgmEnd() is virtual, may be overridden, and parallels wxApp::OnExit(),
62
 
 * from where it should be called.
63
 
 */
64
 
class PGM_BASE
65
 
{
66
 
public:
67
 
    PGM_BASE();
68
 
    ~PGM_BASE();
69
 
 
70
 
    /**
71
 
     * Function OnPgmInit
72
 
     * this is the first executed function (like main() )
73
 
     * @return true if the application can be started.
74
 
     */
75
 
    virtual bool OnPgmInit( wxApp* aWxApp ) = 0;    // call this from wxApp::OnInit()
76
 
 
77
 
    virtual void OnPgmExit() = 0;                   // call this from wxApp::OnExit()
78
 
 
79
 
    /**
80
 
     * Function MacOpenFile
81
 
     * is specific to MacOSX (not used under Linux or Windows).
82
 
     * MacOSX requires it for file association.
83
 
     * @see http://wiki.wxwidgets.org/WxMac-specific_topics
84
 
     */
85
 
    virtual void MacOpenFile( const wxString& aFileName ) = 0;
86
 
 
87
 
    //----<Cross Module API>-----------------------------------------------------
88
 
 
89
 
    VTBL_ENTRY wxHtmlHelpController* GetHtmlHelpController()        { return m_html_ctrl; }
90
 
 
91
 
    VTBL_ENTRY void SetHtmlHelpController( wxHtmlHelpController* aController );
92
 
 
93
 
    VTBL_ENTRY wxConfigBase* CommonSettings() const                 { return m_common_settings; }
94
 
 
95
 
    VTBL_ENTRY void SetEditorName( const wxString& aFileName );
96
 
 
97
 
    /**
98
 
     * Return the preferred editor name.
99
 
     */
100
 
    VTBL_ENTRY const wxString& GetEditorName();
101
 
 
102
 
    VTBL_ENTRY bool IsKicadEnvVariableDefined() const               { return !m_kicad_env.IsEmpty(); }
103
 
 
104
 
    VTBL_ENTRY const wxString& GetKicadEnvVariable() const          { return m_kicad_env; }
105
 
 
106
 
    VTBL_ENTRY const wxString& GetExecutablePath() const            { return m_bin_dir; }
107
 
 
108
 
    VTBL_ENTRY wxLocale* GetLocale()                                { return m_locale; }
109
 
 
110
 
    VTBL_ENTRY const wxString& GetPdfBrowserName() const            { return m_pdf_browser; }
111
 
 
112
 
    VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName )  { m_pdf_browser = aFileName; }
113
 
 
114
 
    /**
115
 
     * Function UseSystemPdfBrowser
116
 
     * returns true if the PDF browser is the default (system) PDF browser
117
 
     * and false if the PDF browser is the prefered (selected) browser, else
118
 
     * returns false if there is no selected browser
119
 
     */
120
 
    VTBL_ENTRY bool UseSystemPdfBrowser() const
121
 
    {
122
 
        return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
123
 
    }
124
 
 
125
 
    /**
126
 
     * Function ForceSystemPdfBrowser
127
 
     * forces the use of system PDF browser, even if a preferend PDF browser is set.
128
 
     */
129
 
    VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
130
 
 
131
 
    /**
132
 
     * Function SetLanguage
133
 
     * sets the dictionary file name for internationalization.
134
 
     * <p>
135
 
     * The files are in kicad/internat/xx or kicad/internat/xx_XX and are named kicad.mo
136
 
     * </p>
137
 
     * @param   first_time  must be set to true the first time this funct is
138
 
     *          called, false otherwise
139
 
     * @return  true if the language can be set (i.e. if the locale is available)
140
 
     */
141
 
    VTBL_ENTRY bool SetLanguage( bool first_time = false );
142
 
 
143
 
    /**
144
 
     * Function AddMenuLanguageList
145
 
     * creates a menu list for language choice, and add it as submenu to \a MasterMenu.
146
 
     *
147
 
     * @param MasterMenu The main menu. The sub menu list will be accessible from the menu
148
 
     *                   item with id ID_LANGUAGE_CHOICE
149
 
     */
150
 
    VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
151
 
 
152
 
    /**
153
 
     * Function SetLanguageIdentifier
154
 
     * sets in .m_language_id member the wxWidgets language identifier Id  from
155
 
     * the KiCad menu id (internal menu identifier).
156
 
     *
157
 
     * @param menu_id The KiCad menuitem id (returned by Menu Event, when
158
 
     *                clicking on a menu item)
159
 
     */
160
 
    VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
161
 
 
162
 
    VTBL_ENTRY void SetLanguagePath();
163
 
 
164
 
    /**
165
 
     * Function InitOnLineHelp
166
 
     * initializes KiCad's online help.
167
 
     */
168
 
    VTBL_ENTRY void InitOnLineHelp();
169
 
 
170
 
    /**
171
 
     * Function ReadPdfBrowserInfos
172
 
     * reads the PDF browser choice from the common configuration.
173
 
     */
174
 
    VTBL_ENTRY void ReadPdfBrowserInfos();
175
 
 
176
 
    /**
177
 
     * Function WritePdfBrowserInfos
178
 
     * saves the PDF browser choice to the common configuration.
179
 
     */
180
 
    VTBL_ENTRY void WritePdfBrowserInfos();
181
 
 
182
 
    /**
183
 
     * Function LockFile
184
 
     * marks a file as being in use.
185
 
     * @param aFileName = full path to the file.
186
 
     * @return false if the file was already locked, true otherwise.
187
 
     */
188
 
    VTBL_ENTRY bool LockFile( const wxString& aFileName );
189
 
 
190
 
    /**
191
 
     * Function App
192
 
     * returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
193
 
     * Use this function instead of wxGetApp().
194
 
     */
195
 
    VTBL_ENTRY wxApp&   App()
196
 
    {
197
 
        wxASSERT( m_wx_app );
198
 
        return *m_wx_app;
199
 
    }
200
 
 
201
 
    //----</Cross Module API>----------------------------------------------------
202
 
 
203
 
    static const wxChar workingDirKey[];
204
 
 
205
 
protected:
206
 
 
207
 
    /**
208
 
     * Function initPgm
209
 
     * initializes this program (process) in a KiCad standard way,
210
 
     * using some generalized techniques.
211
 
     *  - Default paths (help, libs, bin) and configuration file names
212
 
     *  - Language and locale
213
 
     *  - fonts
214
 
     * <p>
215
 
     * But nothing relating to DSOs or projects.
216
 
     * @return bool - true if success, false if failure and program is to terminate.
217
 
     */
218
 
    bool initPgm();
219
 
 
220
 
    /**
221
 
     * Function loadCommonSettings
222
 
     * loads the program (process) settings subset which are stored in .kicad_common
223
 
     */
224
 
    void loadCommonSettings();
225
 
 
226
 
    /**
227
 
     * Function saveCommonSettings
228
 
     * saves the program (process) settings subset which are stored .kicad_common
229
 
     */
230
 
    void saveCommonSettings();
231
 
 
232
 
    /// prevents multiple instances of a program from being run at the same time.
233
 
    wxSingleInstanceChecker* m_pgm_checker;
234
 
 
235
 
    /// prevents opening the same file multiple times.
236
 
    wxSingleInstanceChecker* m_file_checker;
237
 
 
238
 
    /// Configuration settings common to all KiCad program modules,
239
 
    /// like as in $HOME/.kicad_common
240
 
    wxConfigBase*   m_common_settings;
241
 
 
242
 
    /// full path to this program
243
 
    wxString        m_bin_dir;
244
 
 
245
 
    /// The KICAD system environment variable.
246
 
    wxString        m_kicad_env;
247
 
 
248
 
    /// The current locale.
249
 
    wxLocale*       m_locale;
250
 
 
251
 
    /// The current language setting.
252
 
    int             m_language_id;
253
 
 
254
 
    /// true to use the selected PDF browser, if exists, or false to use the default
255
 
    bool            m_use_system_pdf_browser;
256
 
 
257
 
    /// Trap all changes in here, simplifies debugging
258
 
    void setLanguageId( int aId )       { m_language_id = aId; }
259
 
 
260
 
    /**
261
 
     * Function setExecutablePath
262
 
     * finds the path to the executable and stores it in PGM_BASE::m_bin_dir
263
 
     * @return bool - true if success, else false.
264
 
     */
265
 
    bool setExecutablePath();
266
 
 
267
 
    /// The file name of the the program selected for browsing pdf files.
268
 
    wxString        m_pdf_browser;
269
 
    wxString        m_editor_name;
270
 
    wxSize          m_help_size;
271
 
 
272
 
    wxHtmlHelpController*   m_html_ctrl;
273
 
 
274
 
    wxApp*          m_wx_app;
275
 
 
276
 
    // The PGM_* classes can have difficulties at termination if they
277
 
    // are not destroyed soon enough.  Relying on a static destructor can be
278
 
    // too late for contained objects like wxSingleInstanceChecker.
279
 
    void destroy();
280
 
};
281
 
 
282
 
 
283
 
#if !defined(PGM_KICAD_H_)                  // PGM_KICAD has an alternate
284
 
/// The global Program "get" accessor.
285
 
extern PGM_BASE& Pgm();
286
 
#endif
287
 
 
288
 
#endif  // PGM_BASE_H_