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

« back to all changes in this revision

Viewing changes to pagelayout_editor/files.cpp

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file gerbview/files.cpp
 
3
 */
 
4
 
 
5
/*
 
6
 * This program source code file is part of KiCad, a free EDA CAD application.
 
7
 *
 
8
 * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 
9
 * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU General Public License
 
13
 * as published by the Free Software Foundation; either version 2
 
14
 * of the License, or (at your option) any later version.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program; if not, you may find one here:
 
23
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 
24
 * or you may search the http://www.gnu.org website for the version 2 license,
 
25
 * or you may write to the Free Software Foundation, Inc.,
 
26
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
27
 */
 
28
 
 
29
#include <fctsys.h>
 
30
#include <common.h>
 
31
#include <class_drawpanel.h>
 
32
#include <confirm.h>
 
33
#include <gestfich.h>
 
34
#include <macros.h>
 
35
#include <worksheet_shape_builder.h>
 
36
 
 
37
#include <pl_editor_frame.h>
 
38
#include <properties_frame.h>
 
39
#include <pl_editor_id.h>
 
40
#include <wildcards_and_files_ext.h>
 
41
 
 
42
void PL_EDITOR_FRAME::OnFileHistory( wxCommandEvent& event )
 
43
{
 
44
    wxString filename;
 
45
 
 
46
    filename = GetFileFromHistory( event.GetId(), _( "Page Layout Description File" ) );
 
47
 
 
48
    if( filename != wxEmptyString )
 
49
    {
 
50
        if( GetScreen()->IsModify() && !IsOK( this,
 
51
                   _( "The current page layout has been modified.\n"
 
52
                      "Do you wish to discard the changes?" ) ) )
 
53
            return;
 
54
 
 
55
         m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
 
56
        ::wxSetWorkingDirectory( ::wxPathOnly( filename ) );
 
57
        if( LoadPageLayoutDescrFile( filename ) )
 
58
        {
 
59
            wxString msg;
 
60
            msg.Printf( _("File <%s> loaded"), GetChars( filename ) );
 
61
            SetStatusText( msg );
 
62
        }
 
63
 
 
64
        OnNewPageLayout();
 
65
    }
 
66
}
 
67
 
 
68
/* File commands. */
 
69
void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
 
70
{
 
71
    wxString msg;
 
72
    int        id = event.GetId();
 
73
    wxString   filename = GetCurrFileName();
 
74
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
 
75
 
 
76
    if( filename.IsEmpty() && id == wxID_SAVE )
 
77
        id = wxID_SAVEAS;
 
78
 
 
79
    switch( id )
 
80
    {
 
81
    case ID_LOAD_DEFAULT_PAGE_LAYOUT:
 
82
    case wxID_NEW:
 
83
    case wxID_OPEN:
 
84
        if( GetScreen()->IsModify() && !IsOK( this,
 
85
                   _( "The current page layout has been modified.\n"
 
86
                      "Do you wish to discard the changes?" ) ) )
 
87
            return;
 
88
        break;
 
89
 
 
90
    default:
 
91
        break;
 
92
    }
 
93
 
 
94
 
 
95
    switch( id )
 
96
    {
 
97
    case ID_LOAD_DEFAULT_PAGE_LAYOUT:
 
98
        pglayout.SetPageLayout();
 
99
        // Force DefaultDescrFlag to false in page layout editor,
 
100
        // has meaning only for GOST version
 
101
        pglayout.SetDefaultDescrFlag( false );
 
102
        OnNewPageLayout();
 
103
        break;
 
104
 
 
105
    case wxID_NEW:
 
106
        pglayout.AllowVoidList( true );
 
107
        SetCurrFileName( wxEmptyString );
 
108
        pglayout.ClearList();
 
109
        // Force DefaultDescrFlag to false in page layout editor,
 
110
        // has meaning only for GOST version
 
111
        pglayout.SetDefaultDescrFlag( false );
 
112
        OnNewPageLayout();
 
113
        break;
 
114
 
 
115
    case ID_OPEN_POLYGON_DESCR_FILE:
 
116
    {
 
117
         wxFileDialog openFileDialog(this, _("Open polygon descr file"),
 
118
                wxEmptyString,
 
119
                wxEmptyString, PageLayoutDescrFileWildcard, wxFD_OPEN);
 
120
 
 
121
        if (openFileDialog.ShowModal() == wxID_CANCEL)
 
122
            return;
 
123
 
 
124
        filename = openFileDialog.GetPath();
 
125
        if( ! InsertPageLayoutDescrFile( filename ) )
 
126
        {
 
127
            wxString msg;
 
128
            msg.Printf( _("Unable to load %s file"), GetChars( filename ) );
 
129
            wxMessageBox( msg );
 
130
        }
 
131
        else
 
132
        {
 
133
            GetScreen()->SetModify();
 
134
            RebuildDesignTree();
 
135
            m_canvas->Refresh();
 
136
            msg.Printf( _("File <%s> inserted"), GetChars( filename ) );
 
137
            SetStatusText( msg );
 
138
        }
 
139
    }
 
140
        break;
 
141
 
 
142
    case wxID_OPEN:
 
143
    {
 
144
         wxFileDialog openFileDialog(this, _("Open file"), wxEmptyString,
 
145
                wxEmptyString, PageLayoutDescrFileWildcard, wxFD_OPEN);
 
146
 
 
147
        if (openFileDialog.ShowModal() == wxID_CANCEL)
 
148
            return;
 
149
 
 
150
        filename = openFileDialog.GetPath();
 
151
        if( ! LoadPageLayoutDescrFile( filename ) )
 
152
        {
 
153
            wxString msg;
 
154
            msg.Printf( _("Unable to load %s file"), GetChars( filename ) );
 
155
            wxMessageBox( msg );
 
156
        }
 
157
        else
 
158
        {
 
159
            OnNewPageLayout();
 
160
            msg.Printf( _("File <%s> loaded"), GetChars( filename ) );
 
161
            SetStatusText( msg );
 
162
        }
 
163
    }
 
164
        break;
 
165
 
 
166
    case wxID_SAVE:
 
167
        if( !SavePageLayoutDescrFile( filename ) )
 
168
        {
 
169
            msg.Printf( _("Unable to write <%s>"), GetChars( filename ) );
 
170
            wxMessageBox( msg );
 
171
        }
 
172
        else
 
173
        {
 
174
            msg.Printf( _("File <%s> written"), GetChars( filename ) );
 
175
            SetStatusText( msg );
 
176
        }
 
177
        break;
 
178
 
 
179
    case wxID_SAVEAS:
 
180
    {
 
181
         wxFileDialog openFileDialog(this, _("Create file"), wxEmptyString,
 
182
                wxEmptyString, PageLayoutDescrFileWildcard, wxFD_SAVE);
 
183
 
 
184
        if (openFileDialog.ShowModal() == wxID_CANCEL)
 
185
            return;
 
186
 
 
187
        filename = openFileDialog.GetPath();
 
188
        if( !SavePageLayoutDescrFile( filename ) )
 
189
        {
 
190
            wxString msg;
 
191
            msg.Printf( _("Unable to create <%s>"), GetChars( filename ) );
 
192
            wxMessageBox( msg );
 
193
        }
 
194
 
 
195
        else
 
196
        {
 
197
            msg.Printf( _("File <%s> written"), GetChars( filename ) );
 
198
            SetStatusText( msg );
 
199
            if( GetCurrFileName().IsEmpty() )
 
200
                SetCurrFileName( filename );
 
201
        }
 
202
    }
 
203
        break;
 
204
 
 
205
    default:
 
206
        wxMessageBox( wxT( "File_io: unexpected command id" ) );
 
207
        break;
 
208
    }
 
209
}
 
210
 
 
211
/* Loads a .kicad_wks page layout descr file
 
212
 */
 
213
bool PL_EDITOR_FRAME::LoadPageLayoutDescrFile( const wxString& aFullFileName )
 
214
{
 
215
    if( wxFileExists( aFullFileName ) )
 
216
    {
 
217
        WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName );
 
218
        SetCurrFileName( aFullFileName );
 
219
        UpdateFileHistory( aFullFileName );
 
220
        GetScreen()->ClrModify();
 
221
        return true;
 
222
    }
 
223
 
 
224
    return false;
 
225
}
 
226
 
 
227
/* Inserts a .kicad_wks page layout descr file
 
228
 * same as LoadPageLayoutDescrFile, but the new data is added
 
229
 * to the previous data.
 
230
 */
 
231
bool PL_EDITOR_FRAME::InsertPageLayoutDescrFile( const wxString& aFullFileName )
 
232
{
 
233
    if( wxFileExists( aFullFileName ) )
 
234
    {
 
235
        const bool append = true;
 
236
        SaveCopyInUndoList();
 
237
        WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName, append );
 
238
        return true;
 
239
    }
 
240
 
 
241
    return false;
 
242
}
 
243
 
 
244
 
 
245
/* Save the current layout in a .kicad_wks page layout descr file
 
246
 */
 
247
bool PL_EDITOR_FRAME::SavePageLayoutDescrFile( const wxString& aFullFileName )
 
248
{
 
249
    if( ! aFullFileName.IsEmpty() )
 
250
    {
 
251
        WORKSHEET_LAYOUT::GetTheInstance().Save( aFullFileName );
 
252
        GetScreen()->ClrModify();
 
253
        return true;
 
254
    }
 
255
 
 
256
    return false;
 
257
}