~bidulock/kicad/kicad-fonts

« back to all changes in this revision

Viewing changes to gerbview/dialog_print_using_printer.cpp

  • Committer: jean-pierre charras
  • Date: 2010-10-28 16:30:48 UTC
  • mfrom: (2575.1.2 testing)
  • Revision ID: jp.charras@wanadoo.fr-20101028163048-jf0o302q42nr304c
Fix bug in PolyLine.cpp, Fix bug in DRC calculations (see changelog).
Cvpcb and Gerbview: move dialog files in dialogs/.
Eeschema: fix bug in libedit: crashes with import a symbol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************/
2
 
/* File: dialog_print_using_printer.cpp */
3
 
/****************************************/
4
 
 
5
 
// Set this to 1 if you want to test PostScript printing under MSW.
6
 
#define wxTEST_POSTSCRIPT_IN_MSW 1
7
 
 
8
 
#include "fctsys.h"
9
 
#include "appl_wxstruct.h"
10
 
#include "common.h"
11
 
#include "class_drawpanel.h"
12
 
#include "confirm.h"
13
 
 
14
 
#include "dialog_print_using_printer_base.h"
15
 
#include "printout_controler.h"
16
 
 
17
 
#include "gerbview.h"
18
 
#include "wxGerberFrame.h"
19
 
#include "wxPcbStruct.h"
20
 
#include "pcbplot.h"
21
 
#include "class_board_design_settings.h"
22
 
 
23
 
#define WIDTH_MAX_VALUE           1000
24
 
#define WIDTH_MIN_VALUE           1
25
 
 
26
 
static long   s_SelectedLayers;
27
 
static double s_ScaleList[] =
28
 
{ 0, 0.5, 0.7, 0.999, 1.0, 1.4, 2.0, 3.0, 4.0 };
29
 
 
30
 
// Define min et max reasonnable values for print scale
31
 
#define MIN_SCALE 0.01
32
 
#define MAX_SCALE 100.0
33
 
 
34
 
// static print data and page setup data, to remember settings during the session
35
 
static wxPrintData* g_PrintData;
36
 
static wxPageSetupDialogData* g_pageSetupData = (wxPageSetupDialogData*) NULL;
37
 
 
38
 
// Variables locales
39
 
static PRINT_PARAMETERS  s_Parameters;
40
 
 
41
 
 
42
 
/* Dialog to print schematic. Class derived from DIALOG_PRINT_USING_PRINTER_base
43
 
 *  created by wxFormBuilder
44
 
 */
45
 
class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_base
46
 
{
47
 
private:
48
 
    WinEDA_GerberFrame* m_Parent;
49
 
    wxConfig*         m_Config;
50
 
    wxCheckBox*       m_BoxSelectLayer[32];
51
 
    static wxPoint      s_LastPos;
52
 
    static wxSize       s_LastSize;
53
 
 
54
 
public:
55
 
    DIALOG_PRINT_USING_PRINTER( WinEDA_GerberFrame* parent );
56
 
    ~DIALOG_PRINT_USING_PRINTER() {};
57
 
 
58
 
private:
59
 
    void OnCloseWindow( wxCloseEvent& event );
60
 
    void OnInitDialog( wxInitDialogEvent& event );
61
 
    void OnPageSetup( wxCommandEvent& event );
62
 
    void OnPrintPreview( wxCommandEvent& event );
63
 
    void OnPrintButtonClick( wxCommandEvent& event );
64
 
        void OnScaleSelectionClick( wxCommandEvent& event );
65
 
 
66
 
    void OnButtonCancelClick( wxCommandEvent& event ) { Close(); }
67
 
    void SetPrintParameters( );
68
 
    void InitValues( );
69
 
 
70
 
    bool Show( bool show );     // overload stock function
71
 
 
72
 
public:
73
 
    bool IsMirrored() { return m_Print_Mirror->IsChecked(); }
74
 
    bool PrintUsingSinglePage() { return m_PagesOption->GetSelection(); }
75
 
    int SetLayerMaskFromListSelection();
76
 
};
77
 
 
78
 
// We want our dialog to remember its previous screen position
79
 
wxPoint DIALOG_PRINT_USING_PRINTER::s_LastPos( -1, -1 );
80
 
wxSize  DIALOG_PRINT_USING_PRINTER::s_LastSize;
81
 
 
82
 
 
83
 
/*******************************************************/
84
 
void WinEDA_GerberFrame::ToPrinter( wxCommandEvent& event )
85
 
/*******************************************************/
86
 
 
87
 
/* Virtual function:
88
 
 * Display the print dialog
89
 
 */
90
 
{
91
 
    if( g_PrintData == NULL )  // First print
92
 
    {
93
 
        g_PrintData = new wxPrintData();
94
 
 
95
 
        if( !g_PrintData->Ok() )
96
 
        {
97
 
            DisplayError( this, _( "Error Init Printer info" ) );
98
 
        }
99
 
        g_PrintData->SetQuality( wxPRINT_QUALITY_HIGH );      // Default resolution = HIGHT;
100
 
        g_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER );
101
 
    }
102
 
 
103
 
    DIALOG_PRINT_USING_PRINTER* frame = new DIALOG_PRINT_USING_PRINTER( this );
104
 
 
105
 
    frame->ShowModal(); frame->Destroy();
106
 
}
107
 
 
108
 
 
109
 
/*************************************************************************************/
110
 
DIALOG_PRINT_USING_PRINTER::DIALOG_PRINT_USING_PRINTER( WinEDA_GerberFrame* parent ) :
111
 
    DIALOG_PRINT_USING_PRINTER_base( parent )
112
 
/*************************************************************************************/
113
 
{
114
 
    m_Parent = parent;
115
 
    m_Config = wxGetApp().m_EDA_Config;
116
 
 
117
 
    InitValues( );
118
 
 
119
 
    if( GetSizer() )
120
 
    {
121
 
        GetSizer()->SetSizeHints( this );
122
 
    }
123
 
}
124
 
 
125
 
 
126
 
/************************************************************************/
127
 
void DIALOG_PRINT_USING_PRINTER::InitValues( )
128
 
/************************************************************************/
129
 
{
130
 
    SetFocus();
131
 
    int      layer_max = NB_LAYERS;
132
 
    wxString msg;
133
 
 
134
 
    if( g_pageSetupData == NULL )
135
 
    {
136
 
        g_pageSetupData = new wxPageSetupDialogData;
137
 
        // Set initial page margins.
138
 
        // Margins are already set in Pcbnew, so we cans use 0
139
 
        g_pageSetupData->SetMarginTopLeft(wxPoint(0, 0));
140
 
        g_pageSetupData->SetMarginBottomRight(wxPoint(0, 0));
141
 
    }
142
 
 
143
 
    s_Parameters.m_PageSetupData = g_pageSetupData;
144
 
 
145
 
    layer_max = 32;
146
 
    /* Create layer list */
147
 
    int mask = 1, ii;
148
 
    for( ii = 0; ii < layer_max; ii++, mask <<= 1 )
149
 
    {
150
 
        msg = _( "Layer" );
151
 
        msg << wxT( " " ) << ii + 1;
152
 
        m_BoxSelectLayer[ii] = new wxCheckBox( this, -1, msg );
153
 
 
154
 
        if( mask & s_SelectedLayers )
155
 
            m_BoxSelectLayer[ii]->SetValue( TRUE );
156
 
        if( ii < 16 )
157
 
            m_leftLayersBoxSizer->Add( m_BoxSelectLayer[ii],
158
 
                                         wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE );
159
 
        else
160
 
            m_rightLayersBoxSizer->Add( m_BoxSelectLayer[ii],
161
 
                                            wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE );
162
 
    }
163
 
 
164
 
 
165
 
    // Read the scale adjust option
166
 
    int scale_idx = 4; // default selected scale = ScaleList[4] = 1.000
167
 
 
168
 
    if( m_Config )
169
 
    {
170
 
        m_Config->Read( OPTKEY_PRINT_X_FINESCALE_ADJ, &s_Parameters.m_XScaleAdjust );
171
 
        m_Config->Read( OPTKEY_PRINT_Y_FINESCALE_ADJ, &s_Parameters.m_YScaleAdjust );
172
 
        m_Config->Read( OPTKEY_PRINT_SCALE, &scale_idx );
173
 
        m_Config->Read( OPTKEY_PRINT_PAGE_FRAME, &s_Parameters.m_Print_Sheet_Ref, 1);
174
 
        m_Config->Read( OPTKEY_PRINT_MONOCHROME_MODE, &s_Parameters.m_Print_Black_and_White, 1);
175
 
 
176
 
        // Test for a reasonnable scale value. Set to 1 if problem
177
 
        if( s_Parameters.m_XScaleAdjust < MIN_SCALE ||
178
 
            s_Parameters.m_YScaleAdjust < MIN_SCALE ||
179
 
            s_Parameters.m_XScaleAdjust > MAX_SCALE ||
180
 
            s_Parameters.m_YScaleAdjust > MAX_SCALE )
181
 
            s_Parameters.m_XScaleAdjust = s_Parameters.m_YScaleAdjust = 1.0;
182
 
 
183
 
        s_SelectedLayers = 0;
184
 
        for( int layer = 0;  layer<layer_max;  ++layer )
185
 
        {
186
 
            wxString layerKey;
187
 
            bool     option;
188
 
 
189
 
            layerKey.Printf( OPTKEY_LAYERBASE, layer );
190
 
 
191
 
            option = false;
192
 
            if( m_Config->Read( layerKey, &option ) )
193
 
            {
194
 
                m_BoxSelectLayer[layer]->SetValue( option );
195
 
                if( option )
196
 
                    s_SelectedLayers |= 1 << layer;
197
 
            }
198
 
        }
199
 
    }
200
 
 
201
 
    // Disable checkboxes if the corresponding layer is not enabled
202
 
    BOARD* board = ((WinEDA_BasePcbFrame*)m_Parent)->GetBoard();
203
 
    for( int layer = 0; layer<NB_LAYERS; layer++, mask <<= 1 )
204
 
    {
205
 
       if( ! board->IsLayerEnabled( layer ) )
206
 
        {
207
 
            m_BoxSelectLayer[layer]->Enable( false );
208
 
            m_BoxSelectLayer[layer]->SetValue( false );
209
 
        }
210
 
    }
211
 
 
212
 
    m_ScaleOption->SetSelection( scale_idx );
213
 
    scale_idx = m_ScaleOption->GetSelection();
214
 
    s_Parameters.m_PrintScale =  s_ScaleList[scale_idx];
215
 
    m_Print_Mirror->SetValue(s_Parameters.m_PrintMirror);
216
 
 
217
 
 
218
 
    if( s_Parameters.m_Print_Black_and_White )
219
 
        m_ModeColorOption->SetSelection( 1 );
220
 
    else
221
 
        m_ModeColorOption->SetSelection( 0 );
222
 
 
223
 
    s_Parameters.m_PenDefaultSize = 0;
224
 
 
225
 
    // Create scale adjust option
226
 
    msg.Printf( wxT( "%f" ), s_Parameters.m_XScaleAdjust );
227
 
    m_FineAdjustXscaleOpt->SetValue( msg );
228
 
    msg.Printf( wxT( "%f" ), s_Parameters.m_YScaleAdjust );
229
 
    m_FineAdjustYscaleOpt->SetValue( msg );
230
 
 
231
 
    bool enable = (s_Parameters.m_PrintScale == 1.0);
232
 
    if( m_FineAdjustXscaleOpt )
233
 
        m_FineAdjustXscaleOpt->Enable(enable);
234
 
    if( m_FineAdjustYscaleOpt )
235
 
        m_FineAdjustYscaleOpt->Enable(enable);
236
 
}
237
 
 
238
 
/*************************************************/
239
 
bool DIALOG_PRINT_USING_PRINTER::Show( bool show )
240
 
/*************************************************/
241
 
{
242
 
    bool ret;
243
 
 
244
 
    if( show )
245
 
    {
246
 
        if( s_LastPos.x != -1 )
247
 
        {
248
 
            SetSize( s_LastPos.x, s_LastPos.y, s_LastSize.x, s_LastSize.y, 0 );
249
 
        }
250
 
        ret = DIALOG_PRINT_USING_PRINTER_base::Show( show );
251
 
    }
252
 
    else
253
 
    {
254
 
        // Save the dialog's position before hiding
255
 
        s_LastPos  = GetPosition();
256
 
        s_LastSize = GetSize();
257
 
 
258
 
        ret = DIALOG_PRINT_USING_PRINTER_base::Show( show );
259
 
    }
260
 
 
261
 
    return ret;
262
 
}
263
 
 
264
 
/**************************************************************/
265
 
int DIALOG_PRINT_USING_PRINTER::SetLayerMaskFromListSelection()
266
 
/**************************************************************/
267
 
{
268
 
    int page_count;
269
 
    s_Parameters.m_PrintMaskLayer = 0;
270
 
    int ii;
271
 
    for( ii = 0, page_count = 0; ii < LAYER_COUNT; ii++ )
272
 
    {
273
 
        if( m_BoxSelectLayer[ii]->IsChecked() )
274
 
        {
275
 
            page_count++;
276
 
            s_Parameters.m_PrintMaskLayer |= 1 << ii;
277
 
        }
278
 
    }
279
 
 
280
 
    s_Parameters.m_PageCount = page_count;
281
 
 
282
 
    return page_count;
283
 
}
284
 
 
285
 
 
286
 
/********************************************************************/
287
 
void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )
288
 
/********************************************************************/
289
 
{
290
 
    SetPrintParameters();
291
 
 
292
 
    if( m_Config )
293
 
    {
294
 
        m_Config->Write( OPTKEY_PRINT_X_FINESCALE_ADJ, s_Parameters.m_XScaleAdjust );
295
 
        m_Config->Write( OPTKEY_PRINT_Y_FINESCALE_ADJ, s_Parameters.m_YScaleAdjust );
296
 
        m_Config->Write( OPTKEY_PRINT_SCALE, m_ScaleOption->GetSelection() );
297
 
        m_Config->Write( OPTKEY_PRINT_PAGE_FRAME, s_Parameters.m_Print_Sheet_Ref);
298
 
        m_Config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
299
 
        wxString layerKey;
300
 
        for( int layer = 0;  layer < LAYER_COUNT;  ++layer )
301
 
        {
302
 
            layerKey.Printf( OPTKEY_LAYERBASE, layer );
303
 
            m_Config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
304
 
        }
305
 
    }
306
 
    EndModal( 0 );
307
 
}
308
 
 
309
 
 
310
 
/******************************************************************/
311
 
void DIALOG_PRINT_USING_PRINTER::SetPrintParameters( )
312
 
/******************************************************************/
313
 
{
314
 
    s_Parameters.m_PrintMirror = m_Print_Mirror->GetValue();
315
 
    s_Parameters.m_Print_Black_and_White =
316
 
        m_ModeColorOption->GetSelection() != 0;
317
 
 
318
 
    if( m_PagesOption )
319
 
        s_Parameters.m_OptionPrintPage = m_PagesOption->GetSelection() != 0;
320
 
 
321
 
 
322
 
    SetLayerMaskFromListSelection();
323
 
 
324
 
    int idx = m_ScaleOption->GetSelection();
325
 
    s_Parameters.m_PrintScale =  s_ScaleList[idx];
326
 
    g_pcb_plot_options.Scale =  s_Parameters.m_PrintScale;
327
 
 
328
 
    if( m_FineAdjustXscaleOpt )
329
 
    {
330
 
        if( s_Parameters.m_XScaleAdjust > MAX_SCALE ||
331
 
            s_Parameters.m_YScaleAdjust > MAX_SCALE )
332
 
            DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very large value" ) );
333
 
        m_FineAdjustXscaleOpt->GetValue().ToDouble( &s_Parameters.m_XScaleAdjust );
334
 
    }
335
 
    if( m_FineAdjustYscaleOpt )
336
 
    {
337
 
        // Test for a reasonnable scale value
338
 
        if( s_Parameters.m_XScaleAdjust < MIN_SCALE ||
339
 
            s_Parameters.m_YScaleAdjust < MIN_SCALE )
340
 
            DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very small value" ) );
341
 
        m_FineAdjustYscaleOpt->GetValue().ToDouble( &s_Parameters.m_YScaleAdjust );
342
 
    }
343
 
    g_pcb_plot_options.ScaleAdjX = s_Parameters.m_XScaleAdjust;
344
 
    g_pcb_plot_options.ScaleAdjX = s_Parameters.m_YScaleAdjust;
345
 
}
346
 
 
347
 
void DIALOG_PRINT_USING_PRINTER::OnScaleSelectionClick( wxCommandEvent& event )
348
 
{
349
 
    double scale = s_ScaleList[m_ScaleOption->GetSelection()];
350
 
    bool enable = (scale == 1.0);
351
 
    if( m_FineAdjustXscaleOpt )
352
 
        m_FineAdjustXscaleOpt->Enable(enable);
353
 
    if( m_FineAdjustYscaleOpt )
354
 
        m_FineAdjustYscaleOpt->Enable(enable);
355
 
}
356
 
 
357
 
/**********************************************************/
358
 
void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event )
359
 
/**********************************************************/
360
 
 
361
 
/* Open a dialog box for printer setup (printer options, page size ...)
362
 
 */
363
 
{
364
 
    *g_pageSetupData = *g_PrintData;
365
 
 
366
 
    wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
367
 
    pageSetupDialog.ShowModal();
368
 
 
369
 
    (*g_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData();
370
 
    (*g_pageSetupData) = pageSetupDialog.GetPageSetupDialogData();
371
 
}
372
 
 
373
 
 
374
 
/************************************************************/
375
 
void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
376
 
/************************************************************/
377
 
 
378
 
/* Open and display a previewer frame for printing
379
 
 */
380
 
{
381
 
    SetPrintParameters( );
382
 
 
383
 
    // Pass two printout objects: for preview, and possible printing.
384
 
    wxString        title   = _( "Print Preview" );
385
 
    wxPrintPreview* preview =
386
 
        new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ),
387
 
                            new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ),
388
 
                            g_PrintData );
389
 
 
390
 
    if( preview == NULL )
391
 
    {
392
 
        DisplayError( this, wxT( "OnPrintPreview() problem" ) );
393
 
        return;
394
 
    }
395
 
 
396
 
    SetLayerMaskFromListSelection();
397
 
 
398
 
    // If no layer selected, we have no plot. prompt user if it happens
399
 
    // because he could think there is a bug in pcbnew:
400
 
    if( s_Parameters.m_PrintMaskLayer == 0 )
401
 
    {
402
 
        DisplayError( this, _( "No layer selected" ) );
403
 
        return;
404
 
    }
405
 
 
406
 
 
407
 
    // Uses the parent position and size.
408
 
    // @todo uses last position and size ans store them when exit in m_Config
409
 
    wxPoint         WPos  = m_Parent->GetPosition();
410
 
    wxSize          WSize = m_Parent->GetSize();
411
 
 
412
 
    wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );
413
 
 
414
 
    frame->Initialize();
415
 
    frame->Show( TRUE );
416
 
}
417
 
 
418
 
 
419
 
/***************************************************************************/
420
 
void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
421
 
/***************************************************************************/
422
 
 
423
 
/* Called on activate Print button
424
 
 */
425
 
{
426
 
    SetPrintParameters( );
427
 
 
428
 
    // If no layer selected, we have no plot. prompt user if it happens
429
 
    // because he could think there is a bug in pcbnew:
430
 
    if( s_Parameters.m_PrintMaskLayer == 0 )
431
 
    {
432
 
        DisplayError( this, _( "No layer selected" ) );
433
 
        return;
434
 
    }
435
 
 
436
 
    wxPrintDialogData printDialogData( *g_PrintData );
437
 
 
438
 
    wxPrinter         printer( &printDialogData );
439
 
 
440
 
    wxString          title = _( "Print" );
441
 
    BOARD_PRINTOUT_CONTROLER      printout( s_Parameters, m_Parent, title );
442
 
 
443
 
#if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
444
 
    wxDC*             dc = printout.GetDC();
445
 
    ( (wxPostScriptDC*) dc )->SetResolution( 600 );  // Postscript DC resolution is 600 ppi
446
 
#endif
447
 
 
448
 
    if( !printer.Print( this, &printout, TRUE ) )
449
 
    {
450
 
        if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
451
 
            DisplayError( this, _( "There was a problem printing" ) );
452
 
        return;
453
 
    }
454
 
    else
455
 
    {
456
 
        *g_PrintData = printer.GetPrintDialogData().GetPrintData();
457
 
    }
458
 
}
459