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

« back to all changes in this revision

Viewing changes to kicad/kicad.cpp

  • 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:
28
28
 */
29
29
 
30
30
 
 
31
#include <macros.h>
31
32
#include <fctsys.h>
32
 
 
 
33
#include <wx/stdpaths.h>
33
34
#include <kicad.h>
34
35
#include <kiway.h>
35
36
#include <pgm_kicad.h>
40
41
 
41
42
#include <build_version.h>
42
43
 
 
44
 
 
45
/// Extend LIB_ENV_VAR list with the directory from which I came, prepending it.
 
46
static void set_lib_env_var( const wxString& aAbsoluteArgv0 )
 
47
{
 
48
    // POLICY CHOICE 2: Keep same path, so that installer MAY put the
 
49
    // "subsidiary DSOs" in the same directory as the kiway top process modules.
 
50
    // A subsidiary shared library is one that is not a top level DSO, but rather
 
51
    // some shared library that a top level DSO needs to even be loaded.  It is
 
52
    // a static link to a shared object from a top level DSO.
 
53
 
 
54
    // This directory POLICY CHOICE 2 is not the only dir in play, since LIB_ENV_VAR
 
55
    // has numerous path options in it, as does DSO searching on linux, windows, and OSX.
 
56
    // See "man ldconfig" on linux. What's being done here is for quick installs
 
57
    // into a non-standard place, and especially for Windows users who may not
 
58
    // know what the PATH environment variable is or how to set it.
 
59
 
 
60
    wxFileName  fn( aAbsoluteArgv0 );
 
61
 
 
62
    wxString    ld_path( LIB_ENV_VAR );
 
63
    wxString    my_path   = fn.GetPath();
 
64
    wxString    new_paths = PrePendPath( ld_path, my_path );
 
65
 
 
66
    wxSetEnv( ld_path, new_paths );
 
67
 
 
68
#if defined(DEBUG)
 
69
    {
 
70
        wxString    test;
 
71
        wxGetEnv( ld_path, &test );
 
72
        printf( "LIB_ENV_VAR:'%s'\n", TO_UTF8( test ) );
 
73
    }
 
74
#endif
 
75
}
 
76
 
 
77
 
43
78
// a dummy to quiet linking with EDA_BASE_FRAME::config();
44
79
#include <kiface_i.h>
45
80
KIFACE_I& Kiface()
46
81
{
47
 
    wxASSERT( 0 );  // should never be called, only reference is from EDA_BASE_FRAME::config();
 
82
    // This function should never be called.  It is only referenced from
 
83
    // EDA_BASE_FRAME::config() and this is only provided to satisfy the linker,
 
84
    // not to be actually called.
 
85
    wxLogFatalError( wxT( "Unexpected call to Kiface() in kicad/kicad.cpp" ) );
 
86
 
48
87
    return (KIFACE_I&) *(KIFACE_I*) 0;
49
88
}
50
89
 
62
101
 
63
102
    m_bm.Init();
64
103
 
65
 
#if 0   // copied from single_top.c, possibly for milestone B)
66
104
    wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
67
105
 
68
106
    if( !wxIsAbsolutePath( absoluteArgv0 ) )
71
109
        return false;
72
110
    }
73
111
 
74
 
    // Set LIB_ENV_VAR *before* loading the DSO, in case the top-level DSO holding the
75
 
    // KIFACE has hard dependencies on subsidiary DSOs below it.
76
 
    SetLibEnvVar( absoluteArgv0 );
77
 
#endif
 
112
    // Set LIB_ENV_VAR *before* loading the KIFACE DSOs, in case they have hard
 
113
    // dependencies on subsidiary DSOs below it.
 
114
    set_lib_env_var( absoluteArgv0 );
78
115
 
79
116
    if( !initPgm() )
80
117
        return false;
81
118
 
 
119
    // Add search paths to feed the PGM_KICAD::SysSearch() function,
 
120
    // currenly limited in support to only look for project templates
 
121
    {
 
122
        SEARCH_STACK bases;
 
123
 
 
124
        SystemDirsAppend( &bases );
 
125
 
 
126
        // DBG( bases.Show( (std::string(__func__) + " bases").c_str() );)
 
127
 
 
128
        for( unsigned i = 0; i < bases.GetCount(); ++i )
 
129
        {
 
130
            wxFileName fn( bases[i], wxEmptyString );
 
131
 
 
132
            // Add KiCad template file path to search path list.
 
133
            fn.AppendDir( wxT( "template" ) );
 
134
            m_bm.m_search.AddPaths( fn.GetPath() );
 
135
        }
 
136
 
 
137
        //DBG( m_bm.m_search.Show( (std::string( __func__ ) + " SysSearch()").c_str() );)
 
138
    }
 
139
 
82
140
    // Read current setup and reopen last directory if no filename to open on
83
141
    // command line.
84
142
    if( App().argc == 1  )
95
153
                                     wxDefaultPosition, wxDefaultSize );
96
154
    App().SetTopWindow( frame );
97
155
 
 
156
    Kiway.SetTop( frame );
 
157
 
98
158
    bool prjloaded = false;    // true when the project is loaded
99
159
 
100
160
    if( App().argc > 1 )
141
201
 
142
202
void PGM_KICAD::OnPgmExit()
143
203
{
 
204
    Kiway.OnKiwayEnd();
 
205
 
144
206
    saveCommonSettings();
145
207
 
146
208
    // write common settings to disk, and destroy everything in PGM_KICAD,
197
259
}
198
260
 
199
261
 
200
 
/**
201
 
 * Class KIWAY_MGR
202
 
 * is a container for all KIWAYS [and PROJECTS].  This class needs to work both
203
 
 * for a C++ project manager and an a wxPython one (after being moved into a
204
 
 * header later).
205
 
 */
206
 
class KIWAY_MGR
207
 
{
208
 
public:
209
 
    //KIWAY_MGR();
210
 
    // ~KIWAY_MGR();
211
 
 
212
 
    bool OnStart( wxApp* aProcess );
213
 
 
214
 
    void OnEnd();
215
 
 
216
 
    KIWAY& operator[]( int aIndex )
217
 
    {
218
 
        wxASSERT( m_kiways.size() );    // stuffed in OnStart()
219
 
        return m_kiways[aIndex];
220
 
    }
221
 
 
222
 
private:
223
 
 
224
 
    // KIWAYs may not be moved once doled out, since window DNA depends on the
225
 
    // pointer being good forever.
226
 
    // boost_ptr::vector however never moves the object pointed to.
227
 
    typedef boost::ptr_vector<KIWAY>    KIWAYS;
228
 
 
229
 
    KIWAYS  m_kiways;
230
 
};
231
 
 
232
 
static KIWAY_MGR   kiways;
 
262
KIWAY  Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE );
233
263
 
234
264
 
235
265
/**
240
270
{
241
271
    bool OnInit()           // overload wxApp virtual
242
272
    {
243
 
        if( kiways.OnStart( this ) )
 
273
        // if( Kiways.OnStart( this ) )
244
274
        {
245
275
            return Pgm().OnPgmInit( this );
246
276
        }
249
279
 
250
280
    int  OnExit()           // overload wxApp virtual
251
281
    {
252
 
        kiways.OnEnd();
 
282
        // Kiways.OnEnd();
253
283
 
254
284
        Pgm().OnPgmExit();
255
285
 
256
286
        return wxApp::OnExit();
257
287
    }
258
288
 
 
289
    int OnRun()             // overload wxApp virtual
 
290
    {
 
291
        try
 
292
        {
 
293
            return wxApp::OnRun();
 
294
        }
 
295
        catch( const std::exception& e )
 
296
        {
 
297
            wxLogError( wxT( "Unhandled exception class: %s  what: %s" ),
 
298
                GetChars( FROM_UTF8( typeid(e).name() )),
 
299
                GetChars( FROM_UTF8( e.what() ) ) );;
 
300
        }
 
301
        catch( const IO_ERROR& ioe )
 
302
        {
 
303
            wxLogError( GetChars( ioe.errorText ) );
 
304
        }
 
305
        catch(...)
 
306
        {
 
307
            wxLogError( wxT( "Unhandled exception of unknown type" ) );
 
308
        }
 
309
 
 
310
        return -1;
 
311
    }
 
312
 
259
313
    /**
260
314
     * Function MacOpenFile
261
315
     * is specific to MacOSX (not used under Linux or Windows).
275
329
// this link image need this function.
276
330
PROJECT& Prj()
277
331
{
278
 
    return kiways[0].Prj();
 
332
    return Kiway.Prj();
279
333
}
280
334
 
281
335
 
 
336
#if 0   // there can be only one in C++ project manager.
 
337
 
282
338
bool KIWAY_MGR::OnStart( wxApp* aProcess )
283
339
{
284
340
    // The C++ project manager supports only one open PROJECT
292
348
void KIWAY_MGR::OnEnd()
293
349
{
294
350
}
 
351
 
 
352
#endif