gerbview.cpp 3.94 KB
Newer Older
1 2 3 4
/**
 * @file gerbview.cpp
 * @brief GERBVIEW main file.
 */
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

29 30 31 32 33
 #include <fctsys.h>
#include <appl_wxstruct.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <gestfich.h>
34
//#include <gr_basic.h>
35 36 37 38 39 40

#include <gerbview.h>
#include <gerbview_id.h>
#include <hotkeys.h>

#include <build_version.h>
41

42 43
#include <wx/file.h>
#include <wx/snglinst.h>
44

45 46
// Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings;
47 48
extern int g_DrawBgColor;
int g_Default_GERBER_Format;
49 50


51 52 53 54 55 56 57 58 59 60 61 62 63
const wxChar* g_GerberPageSizeList[] = {
    wxT( "GERBER" ),    // index 0: full size page selection, and do not show page limits
    wxT( "GERBER" ),    // index 1: full size page selection, and show page limits
    wxT( "A4" ),
    wxT( "A3" ),
    wxT( "A2" ),
    wxT( "A" ),
    wxT( "B" ),
    wxT( "C" ),
};


GERBER_IMAGE*  g_GERBER_List[32];
64

65

66
IMPLEMENT_APP( EDA_APP )
67

68
/* MacOSX: Needed for file association
69 70
 * http://wiki.wxwidgets.org/WxMac-specific_topics
 */
71
void EDA_APP::MacOpenFile(const wxString &fileName)
72 73
{
    wxFileName           filename = fileName;
74
    GERBVIEW_FRAME * frame = ((GERBVIEW_FRAME*)GetTopWindow());
75

76
    if( !filename.FileExists() )
77 78
        return;

jean-pierre charras's avatar
jean-pierre charras committed
79
    frame->LoadGerberFiles( fileName );
80 81
}

82

83
bool EDA_APP::OnInit()
84
{
85
    wxFileName          fn;
86
    GERBVIEW_FRAME* frame = NULL;
87

88
    InitEDA_Appl( wxT( "GerbView" ), APP_GERBVIEW_T );
89

90 91 92 93 94
    if( m_Checker && m_Checker->IsAnotherRunning() )
    {
        if( !IsOK( NULL, _( "GerbView is already running. Continue?" ) ) )
            return false;
    }
95

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

dickelbeck's avatar
dickelbeck committed
101
    g_DrawBgColor = BLACK;
102

103 104 105 106
   /* Must be called before creating the main frame in order to
    * display the real hotkeys in menus or tool tips */
    ReadHotkeyConfig( wxT("GerberFrame"), s_Gerbview_Hokeys_Descr );

107
    frame = new  GERBVIEW_FRAME( NULL, wxT( "GerbView" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
dickelbeck's avatar
dickelbeck committed
108

109
    /* Gerbview mainframe title */
110
    frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() );
dickelbeck's avatar
dickelbeck committed
111

112
    SetTopWindow( frame );                  // Set GerbView mainframe on top
113 114 115
    frame->Show( true );                    // Show GerbView mainframe
    frame->Zoom_Automatique( true );        // Zoom fit in frame
    frame->GetScreen()->m_FirstRedraw = false;
dickelbeck's avatar
dickelbeck committed
116

117

118
    if( argc <= 1 )
119 120 121 122 123
        return true;

    fn = argv[1];

    if( fn.IsOk() )
dickelbeck's avatar
dickelbeck committed
124
    {
125 126
        if( fn.DirExists() )
            wxSetWorkingDirectory( fn.GetPath() );
127

128
        // Load all files specified on the command line.
129
        int jj = 0;
130

131
        for( int ii = 1; ii < argc && ii <= GERBVIEW_LAYER_COUNT; ++ii )
132
        {
charras's avatar
charras committed
133
            fn = wxFileName( argv[ii] );
dickelbeck's avatar
dickelbeck committed
134

135
            if( fn.FileExists() )
dickelbeck's avatar
dickelbeck committed
136
            {
137
                frame->setActiveLayer( jj++ );
jean-pierre charras's avatar
jean-pierre charras committed
138
                frame->LoadGerberFiles( fn.GetFullPath() );
dickelbeck's avatar
dickelbeck committed
139 140 141 142
            }
        }
    }

143
    return true;
dickelbeck's avatar
dickelbeck committed
144
}