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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
/** @file dialog_plot_schematic.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2015 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2010 Lorenzo Marcantonio
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
*
* Copyright (C) 1992-2015 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
*/
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <worksheet.h>
#include <plot_common.h>
#include <class_sch_screen.h>
#include <schframe.h>
#include <base_units.h>
#include <sch_sheet.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
// Keys for configuration
#define PLOT_FORMAT_KEY wxT( "PlotFormat" )
#define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
#define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
#define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
#define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )
#define PLOT_HPGL_PEN_SIZE_KEY wxT( "PlotHPGLPenSize" )
// static members (static to remember last state):
int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO;
void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
{
DIALOG_PLOT_SCHEMATIC dlg( this );
dlg.ShowModal();
// save project config if the prj config has changed:
if( dlg.PrjConfigChanged() )
SaveProjectSettings( true );
}
DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) :
DIALOG_PLOT_SCHEMATIC_BASE( parent )
{
m_parent = parent;
m_configChanged = false;
m_config = Kiface().KifaceSettings();
initDlg();
FixOSXCancelButtonIssue();
// Now all widgets have the size fixed, call FinishDialogSettings
FinishDialogSettings();
}
// Initialize the dialog options:
void DIALOG_PLOT_SCHEMATIC::initDlg()
{
// Set paper size option
m_PaperSizeOption->SetSelection( m_pageSizeSelect );
// Set color or B&W plot option
bool tmp;
m_config->Read( PLOT_MODECOLOR_KEY, &tmp, true );
setModeColor( tmp );
// Set plot or not frame reference option
m_config->Read( PLOT_FRAME_REFERENCE_KEY, &tmp, true );
setPlotFrameRef( tmp );
// Set HPGL plot origin to center of paper of left bottom corner
m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
SetPlotOriginCenter( tmp );
m_config->Read( PLOT_HPGL_PAPERSIZE_KEY, &m_HPGLPaperSizeSelect, 0 );
m_HPGLPaperSizeOption->SetSelection( m_HPGLPaperSizeSelect );
// HPGL Pen Size is stored in mm in config
m_config->Read( PLOT_HPGL_PEN_SIZE_KEY, &m_HPGLPenSize, 0.5 );
m_HPGLPenSize *= IU_PER_MM;
// Switch to the last save plot format
long plotfmt;
m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
switch( plotfmt )
{
default:
case PLOT_FORMAT_POST:
m_plotFormatOpt->SetSelection( 0 );
break;
case PLOT_FORMAT_PDF:
m_plotFormatOpt->SetSelection( 1 );
break;
case PLOT_FORMAT_SVG:
m_plotFormatOpt->SetSelection( 2 );
break;
case PLOT_FORMAT_DXF:
m_plotFormatOpt->SetSelection( 3 );
break;
case PLOT_FORMAT_HPGL:
m_plotFormatOpt->SetSelection( 4 );
break;
}
// Set the default line width (pen width which should be used for
// items that do not have a pen size defined (like frame ref)
AddUnitSymbol( *m_defaultLineWidthTitle, g_UserUnit );
PutValueInLocalUnits( *m_DefaultLineSizeCtrl, GetDefaultLineThickness() );
// Initialize HPGL specific widgets
AddUnitSymbol( *m_penHPLGWidthTitle, g_UserUnit );
PutValueInLocalUnits( *m_penHPGLWidthCtrl, m_HPGLPenSize );
m_HPGLPaperSizeOption->SetSelection( m_HPGLPaperSizeSelect );
// Plot directory
wxString path = m_parent->GetPlotDirectoryName();
#ifdef __WINDOWS__
path.Replace( '/', '\\' );
#endif
m_outputDirectoryName->SetValue( path );
// Hide/show widgets that are not always displayed:
wxCommandEvent cmd_event;
OnPlotFormatSelection( cmd_event );
}
/*
* TODO: Copy of DIALOG_PLOT::OnOutputDirectoryBrowseClicked in dialog_plot.cpp, maybe merge to a common method.
*/
void DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
{
// Build the absolute path of current output plot directory
// to preselect it when opening the dialog.
wxFileName fn( m_outputDirectoryName->GetValue() );
wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
if( dirDialog.ShowModal() == wxID_CANCEL )
{
return;
}
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
fn = Prj().AbsolutePath( g_RootSheet->GetFileName() );
wxString defaultPath = fn.GetPathWithSep();
wxString msg;
msg.Printf( _( "Do you want to use a path relative to\n'%s'" ),
GetChars( defaultPath ) );
wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
// relative directory selected
if( dialog.ShowModal() == wxID_YES )
{
if( !dirName.MakeRelativeTo( defaultPath ) )
wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
}
m_outputDirectoryName->SetValue( dirName.GetFullPath() );
}
PlotFormat DIALOG_PLOT_SCHEMATIC::GetPlotFileFormat()
{
switch( m_plotFormatOpt->GetSelection() )
{
default:
case 0: return PLOT_FORMAT_POST;
case 1: return PLOT_FORMAT_PDF;
case 2: return PLOT_FORMAT_SVG;
case 3: return PLOT_FORMAT_DXF;
case 4: return PLOT_FORMAT_HPGL;
}
}
void DIALOG_PLOT_SCHEMATIC::OnButtonCancelClick( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
}
void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
{
m_config->Write( PLOT_MODECOLOR_KEY, getModeColor() );
m_config->Write( PLOT_FRAME_REFERENCE_KEY, getPlotFrameRef() );
m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
m_config->Write( PLOT_HPGL_ORIGIN_KEY, GetPlotOriginCenter() );
m_HPGLPaperSizeSelect = m_HPGLPaperSizeOption->GetSelection();
m_config->Write( PLOT_HPGL_PAPERSIZE_KEY, m_HPGLPaperSizeSelect );
// HPGL Pen Size is stored in mm in config
m_config->Write( PLOT_HPGL_PEN_SIZE_KEY, m_HPGLPenSize/IU_PER_MM );
m_pageSizeSelect = m_PaperSizeOption->GetSelection();
SetDefaultLineThickness( ValueFromTextCtrl( *m_DefaultLineSizeCtrl ) );
// Plot directory
wxString path = m_outputDirectoryName->GetValue();
path.Replace( '\\', '/' );
if( m_parent->GetPlotDirectoryName() != path )
m_configChanged = true;
m_parent->SetPlotDirectoryName( path );
}
void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
{
switch( GetPlotFileFormat() )
{
default:
case PLOT_FORMAT_POST:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show( m_PaperSizeOption );
m_PaperSizeOption->Enable( true );
m_DefaultLineSizeCtrl->Enable( true );
break;
case PLOT_FORMAT_PDF:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( true );
m_DefaultLineSizeCtrl->Enable( true );
break;
case PLOT_FORMAT_SVG:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( false );
m_DefaultLineSizeCtrl->Enable( true );
break;
case PLOT_FORMAT_DXF:
m_paperOptionsSizer->Hide( m_paperHPGLSizer );
m_paperOptionsSizer->Show(m_PaperSizeOption);
m_PaperSizeOption->Enable( false );
m_DefaultLineSizeCtrl->Enable( false );
break;
case PLOT_FORMAT_HPGL:
m_paperOptionsSizer->Show( m_paperHPGLSizer );
m_paperOptionsSizer->Hide(m_PaperSizeOption);
m_DefaultLineSizeCtrl->Enable( false );
break;
}
GetSizer()->SetSizeHints( this );
}
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotCurrentClick( wxCommandEvent& event )
{
PlotSchematic( false );
}
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
{
PlotSchematic( true );
}
void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll )
{
getPlotOptions();
switch( GetPlotFileFormat() )
{
case PLOT_FORMAT_HPGL:
createHPGLFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_DXF:
CreateDXFFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_PDF:
createPDFFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_SVG:
createSVGFile( aPlotAll, getPlotFrameRef() );
break;
case PLOT_FORMAT_POST:
// Fall through. Default to Postscript.
default:
createPSFile( aPlotAll, getPlotFrameRef() );
break;
}
}
wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirectoryName,
wxString& aPlotFileName,
wxString& aExtension,
REPORTER* aReporter )
{
wxString outputDirName = aOutputDirectoryName->GetValue();
wxFileName outputDir = wxFileName::DirName( outputDirName );
wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT(".") + aExtension);
if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
{
wxString msg;
msg.Printf( _( "Could not write plot files to folder '%s'." ),
GetChars( outputDir.GetPath() ) );
aReporter->Report( msg, REPORTER::RPT_ERROR );
}
wxFileName fn( plotFileName );
fn.SetPath( outputDir.GetFullPath() );
return fn;
}
|