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
|
/** @file plot_schematic_HPGL.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 1992-2010 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 <plot_common.h>
#include <class_sch_screen.h>
#include <schframe.h>
#include <base_units.h>
#include <sch_sheet_path.h>
#include <project.h>
#include <dialog_plot_schematic.h>
#include <wx_html_report_panel.h>
enum HPGL_PAGEZ_T {
PAGE_DEFAULT = 0,
HPGL_PAGE_SIZE_A4,
HPGL_PAGE_SIZE_A3,
HPGL_PAGE_SIZE_A2,
HPGL_PAGE_SIZE_A1,
HPGL_PAGE_SIZE_A0,
HPGL_PAGE_SIZE_A,
HPGL_PAGE_SIZE_B,
HPGL_PAGE_SIZE_C,
HPGL_PAGE_SIZE_D,
HPGL_PAGE_SIZE_E,
};
static const wxChar* plot_sheet_list( int aSize )
{
const wxChar* ret;
switch( aSize )
{
default:
case PAGE_DEFAULT:
ret = NULL; break;
case HPGL_PAGE_SIZE_A4:
ret = wxT( "A4" ); break;
case HPGL_PAGE_SIZE_A3:
ret = wxT( "A3" ); break;
case HPGL_PAGE_SIZE_A2:
ret = wxT( "A2" ); break;
case HPGL_PAGE_SIZE_A1:
ret = wxT( "A1" ); break;
case HPGL_PAGE_SIZE_A0:
ret = wxT( "A0" ); break;
case HPGL_PAGE_SIZE_A:
ret = wxT( "A" ); break;
case HPGL_PAGE_SIZE_B:
ret = wxT( "B" ); break;
case HPGL_PAGE_SIZE_C:
ret = wxT( "C" ); break;
case HPGL_PAGE_SIZE_D:
ret = wxT( "D" ); break;
case HPGL_PAGE_SIZE_E:
ret = wxT( "E" ); break;
}
return ret;
};
void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
{
m_HPGLPenSize = ValueFromTextCtrl( *m_penHPGLWidthCtrl );
if( m_HPGLPenSize > Millimeter2iu( 2 ) )
m_HPGLPenSize = Millimeter2iu( 2 );
if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
m_HPGLPenSize = Millimeter2iu( 0.01 );
}
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
{
SCH_SCREEN* screen = m_parent->GetScreen();
SCH_SHEET_PATH* sheetpath;
SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
/* When printing all pages, the printed page is not the current page.
* In complex hierarchies, we must setup references and other parameters
* in the printed SCH_SCREEN
* because in complex hierarchies a SCH_SCREEN (a schematic drawings)
* is shared between many sheets
*/
SCH_SHEET_LIST SheetList( NULL );
sheetpath = SheetList.GetFirst();
SCH_SHEET_PATH list;
REPORTER& reporter = m_MessagesBox->Reporter();
SetHPGLPenWidth();
while( true )
{
if( aPlotAll )
{
if( sheetpath == NULL )
break;
list.Clear();
if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
{
m_parent->SetCurrentSheet( list );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
screen = m_parent->GetCurrentSheet().LastScreen();
if( !screen ) // LastScreen() may return NULL
screen = m_parent->GetScreen();
}
else // Should not happen
return;
sheetpath = SheetList.GetNext();
}
const PAGE_INFO& curPage = screen->GetPageSettings();
PAGE_INFO plotPage = curPage;
// if plotting on a page size other than curPage
if( m_HPGLPaperSizeOption->GetSelection() != PAGE_DEFAULT )
plotPage.SetType( plot_sheet_list( m_HPGLPaperSizeOption->GetSelection() ) );
// Calculation of conversion scales.
double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
// Calculate offsets
wxPoint plotOffset;
wxString msg;
if( GetPlotOriginCenter() )
{
plotOffset.x = plotPage.GetWidthIU() / 2;
plotOffset.y = -plotPage.GetHeightIU() / 2;
}
try
{
wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
ext, &reporter );
LOCALE_IO toggle;
if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, plotOffset,
plot_scale, aPlotFrameRef ) )
{
msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ACTION );
}
else
{
msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
if( !aPlotAll )
break;
}
catch( IO_ERROR& e )
{
msg.Printf( wxT( "HPGL Plotter exception: %s"), GetChars( e.errorText ) );
reporter.Report( msg, REPORTER::RPT_ERROR );
}
}
m_parent->SetCurrentSheet( oldsheetpath );
m_parent->GetCurrentSheet().UpdateAllScreenReferences();
m_parent->SetSheetNumberAndCount();
}
bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
SCH_SCREEN* aScreen,
const PAGE_INFO& aPageInfo,
wxPoint aPlot0ffset,
double aScale,
bool aPlotFrameRef )
{
HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
plotter->SetPageSettings( aPageInfo );
plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, aScale, false );
// Init :
plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
if( ! plotter->OpenFile( aFileName ) )
{
delete plotter;
return false;
}
LOCALE_IO toggle;
// Pen num and pen speed are not initialized here.
// Default HPGL driver values are used
plotter->SetPenDiameter( m_HPGLPenSize );
plotter->SetPenOverlap( m_HPGLPenSize / 4 );
plotter->StartPlot();
plotter->SetColor( BLACK );
if( getPlotFrameRef() )
PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
m_parent->GetPageSettings(),
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(),
aScreen->GetFileName() );
aScreen->Plot( plotter );
plotter->EndPlot();
delete plotter;
return true;
}
|