2
* @file gerbview/files.cpp
6
* This program source code file is part of KiCad, a free EDA CAD application.
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.
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.
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.
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
31
#include <class_drawpanel.h>
35
#include <worksheet_shape_builder.h>
37
#include <pl_editor_frame.h>
38
#include <properties_frame.h>
39
#include <pl_editor_id.h>
40
#include <wildcards_and_files_ext.h>
42
void PL_EDITOR_FRAME::OnFileHistory( wxCommandEvent& event )
46
filename = GetFileFromHistory( event.GetId(), _( "Page Layout Description File" ) );
48
if( filename != wxEmptyString )
50
if( GetScreen()->IsModify() && !IsOK( this,
51
_( "The current page layout has been modified.\n"
52
"Do you wish to discard the changes?" ) ) )
55
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
56
::wxSetWorkingDirectory( ::wxPathOnly( filename ) );
57
if( LoadPageLayoutDescrFile( filename ) )
60
msg.Printf( _("File <%s> loaded"), GetChars( filename ) );
69
void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
72
int id = event.GetId();
73
wxString filename = GetCurrFileName();
74
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
76
if( filename.IsEmpty() && id == wxID_SAVE )
81
case ID_LOAD_DEFAULT_PAGE_LAYOUT:
84
if( GetScreen()->IsModify() && !IsOK( this,
85
_( "The current page layout has been modified.\n"
86
"Do you wish to discard the changes?" ) ) )
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 );
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 );
115
case ID_OPEN_POLYGON_DESCR_FILE:
117
wxFileDialog openFileDialog(this, _("Open polygon descr file"),
119
wxEmptyString, PageLayoutDescrFileWildcard, wxFD_OPEN);
121
if (openFileDialog.ShowModal() == wxID_CANCEL)
124
filename = openFileDialog.GetPath();
125
if( ! InsertPageLayoutDescrFile( filename ) )
128
msg.Printf( _("Unable to load %s file"), GetChars( filename ) );
133
GetScreen()->SetModify();
136
msg.Printf( _("File <%s> inserted"), GetChars( filename ) );
137
SetStatusText( msg );
144
wxFileDialog openFileDialog(this, _("Open file"), wxEmptyString,
145
wxEmptyString, PageLayoutDescrFileWildcard, wxFD_OPEN);
147
if (openFileDialog.ShowModal() == wxID_CANCEL)
150
filename = openFileDialog.GetPath();
151
if( ! LoadPageLayoutDescrFile( filename ) )
154
msg.Printf( _("Unable to load %s file"), GetChars( filename ) );
160
msg.Printf( _("File <%s> loaded"), GetChars( filename ) );
161
SetStatusText( msg );
167
if( !SavePageLayoutDescrFile( filename ) )
169
msg.Printf( _("Unable to write <%s>"), GetChars( filename ) );
174
msg.Printf( _("File <%s> written"), GetChars( filename ) );
175
SetStatusText( msg );
181
wxFileDialog openFileDialog(this, _("Create file"), wxEmptyString,
182
wxEmptyString, PageLayoutDescrFileWildcard, wxFD_SAVE);
184
if (openFileDialog.ShowModal() == wxID_CANCEL)
187
filename = openFileDialog.GetPath();
188
if( !SavePageLayoutDescrFile( filename ) )
191
msg.Printf( _("Unable to create <%s>"), GetChars( filename ) );
197
msg.Printf( _("File <%s> written"), GetChars( filename ) );
198
SetStatusText( msg );
199
if( GetCurrFileName().IsEmpty() )
200
SetCurrFileName( filename );
206
wxMessageBox( wxT( "File_io: unexpected command id" ) );
211
/* Loads a .kicad_wks page layout descr file
213
bool PL_EDITOR_FRAME::LoadPageLayoutDescrFile( const wxString& aFullFileName )
215
if( wxFileExists( aFullFileName ) )
217
WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName );
218
SetCurrFileName( aFullFileName );
219
UpdateFileHistory( aFullFileName );
220
GetScreen()->ClrModify();
227
/* Inserts a .kicad_wks page layout descr file
228
* same as LoadPageLayoutDescrFile, but the new data is added
229
* to the previous data.
231
bool PL_EDITOR_FRAME::InsertPageLayoutDescrFile( const wxString& aFullFileName )
233
if( wxFileExists( aFullFileName ) )
235
const bool append = true;
236
SaveCopyInUndoList();
237
WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName, append );
245
/* Save the current layout in a .kicad_wks page layout descr file
247
bool PL_EDITOR_FRAME::SavePageLayoutDescrFile( const wxString& aFullFileName )
249
if( ! aFullFileName.IsEmpty() )
251
WORKSHEET_LAYOUT::GetTheInstance().Save( aFullFileName );
252
GetScreen()->ClrModify();