~cern-kicad/kicad/kicad-pns-tom

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * @file cvpcb.cpp
 */

#include <fctsys.h>
#include <gr_basic.h>
#include <appl_wxstruct.h>
#include <wxstruct.h>
#include <confirm.h>
#include <gestfich.h>

#include <cvpcb.h>
#include <zones.h>
#include <cvpcb_mainframe.h>
#include <colors_selection.h>
#include <cvpcb_id.h>

#include <build_version.h>

#include <wx/snglinst.h>

// Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings;

/* Constant string definitions for CvPcb */
const wxString RetroFileExtension( wxT( "stf" ) );
const wxString FootprintAliasFileExtension( wxT( "equ" ) );

// Wildcard for schematic retroannotation (import footprint names in schematic):
const wxString FootprintAliasFileWildcard( _( "KiCad footprint alias files (*.equ)|*.equ" ) );

const wxString titleLibLoadError( _( "Library Load Error" ) );


/*
 * MacOSX: Needed for file association
 * http://wiki.wxwidgets.org/WxMac-specific_topics
 */
void EDA_APP::MacOpenFile(const wxString &fileName)
{
    wxFileName filename = fileName;
    wxString oldPath;
    CVPCB_MAINFRAME* frame = (CVPCB_MAINFRAME*) GetTopWindow();

    if( !filename.FileExists() )
        return;

    if( frame->m_NetlistFileName.DirExists() )
        oldPath = frame->m_NetlistFileName.GetPath();

    /* Update the library search path list. */
    if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
        wxGetApp().GetLibraryPathList().Remove( oldPath );

    wxGetApp().GetLibraryPathList().Insert( filename.GetPath(), 0 );

    frame->m_NetlistFileName = filename;
    frame->ReadNetListAndLinkFiles();
}

// Create a new application object
IMPLEMENT_APP( EDA_APP )


/************************************/
/* Called to initialize the program */
/************************************/

bool EDA_APP::OnInit()
{
    wxFileName       filename;
    wxString         message;
    CVPCB_MAINFRAME* frame = NULL;

    InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T );

    if( m_Checker && m_Checker->IsAnotherRunning() )
    {
        if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
            return false;
    }

    if( argc > 1 )
    {
        filename = argv[1];
        wxSetWorkingDirectory( filename.GetPath() );
    }

    // read current setup and reopen last directory if no filename to open in command line
    bool reopenLastUsedDirectory = argc == 1;
    GetSettings(reopenLastUsedDirectory);

    g_DrawBgColor = BLACK;

    wxString Title = GetTitle() + wxT( " " ) + GetBuildVersion();
    frame = new CVPCB_MAINFRAME( Title );

    // Show the frame
    SetTopWindow( frame );

    frame->LoadProjectFile( filename.GetFullPath() );
    frame->Show( true );
    frame->BuildFOOTPRINTS_LISTBOX();
    frame->BuildLIBRARY_LISTBOX();

    if( filename.IsOk() && filename.FileExists() )
    {
        frame->m_NetlistFileName = filename;

        if( frame->ReadNetListAndLinkFiles() )
        {
            frame->m_NetlistFileExtension = filename.GetExt();
            return true;
        }
    }

    frame->LoadFootprintFiles();
    frame->m_NetlistFileExtension = wxT( "net" );
    frame->m_NetlistFileName.Clear();
    frame->UpdateTitle();

    return true;
}