dialog_print_using_printer.cpp 16.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2010-2014 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
 * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.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
 */
plyatov's avatar
plyatov committed
24 25

// Set this to 1 if you want to test PostScript printing under MSW.
26
//#define wxTEST_POSTSCRIPT_IN_MSW 1
plyatov's avatar
plyatov committed
27

28
#include <fctsys.h>
29 30
//#include <pgm_base.h>
#include <kiface_i.h>
31 32 33
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
34
#include <base_units.h>
plyatov's avatar
plyatov committed
35

36 37 38
#include <printout_controler.h>
#include <pcbnew.h>
#include <pcbplot.h>
39

40
#include <class_board.h>
41

42
#include <dialog_print_using_printer_base.h>
43

charras's avatar
charras committed
44

45 46
#define PEN_WIDTH_MAX_VALUE ( KiROUND( 5 * IU_PER_MM ) )
#define PEN_WIDTH_MIN_VALUE ( KiROUND( 0.005 * IU_PER_MM ) )
plyatov's avatar
plyatov committed
47

48 49 50 51

extern int g_DrawDefaultLineThickness;

// Local variables
Dick Hollenbeck's avatar
Dick Hollenbeck committed
52
static LSET s_SelectedLayers;
charras's avatar
charras committed
53 54 55
static double s_ScaleList[] =
{ 0, 0.5, 0.7, 0.999, 1.0, 1.4, 2.0, 3.0, 4.0 };

56 57 58
// Define min et max reasonnable values for print scale
#define MIN_SCALE 0.01
#define MAX_SCALE 100.0
charras's avatar
charras committed
59

plyatov's avatar
plyatov committed
60
// static print data and page setup data, to remember settings during the session
61 62
static wxPrintData* s_PrintData;
static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL;
plyatov's avatar
plyatov committed
63

64
static PRINT_PARAMETERS  s_Parameters;
plyatov's avatar
plyatov committed
65

66

67 68
/**
 * Dialog to print schematic. Class derived from DIALOG_PRINT_USING_PRINTER_base
69 70 71 72 73
 *  created by wxFormBuilder
 */
class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_base
{
public:
74
    DIALOG_PRINT_USING_PRINTER( PCB_EDIT_FRAME* parent );
75 76 77 78

    bool IsMirrored() { return m_Print_Mirror->IsChecked(); }
    bool ExcludeEdges() { return m_Exclude_Edges_Pcb->IsChecked(); }
    bool PrintUsingSinglePage() { return m_PagesOption->GetSelection(); }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
79
    int SetLayerSetFromListSelection();
80

81 82

private:
83 84

    PCB_EDIT_FRAME* m_parent;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
85 86
    wxConfigBase*   m_config;
    wxCheckBox*     m_BoxSelectLayer[LAYER_ID_COUNT];
87 88
    static bool     m_ExcludeEdgeLayer;

89
    void OnCloseWindow( wxCloseEvent& event );
90
    void OnPageSetup( wxCommandEvent& event );
91 92
    void OnPrintPreview( wxCommandEvent& event );
    void OnPrintButtonClick( wxCommandEvent& event );
93
    void OnScaleSelectionClick( wxCommandEvent& event );
94 95

    void OnButtonCancelClick( wxCommandEvent& event ) { Close(); }
96
    void SetPrintParameters( );
97
    void SetPenWidth();
Dick Hollenbeck's avatar
Dick Hollenbeck committed
98
    void initValues( );
99
};
plyatov's avatar
plyatov committed
100

dickelbeck's avatar
dickelbeck committed
101

102
bool DIALOG_PRINT_USING_PRINTER::m_ExcludeEdgeLayer;
charras's avatar
charras committed
103

plyatov's avatar
plyatov committed
104

105
void PCB_EDIT_FRAME::ToPrinter( wxCommandEvent& event )
plyatov's avatar
plyatov committed
106
{
107 108
    const PAGE_INFO& pageInfo = GetPageSettings();

109
    if( s_PrintData == NULL )  // First print
dickelbeck's avatar
dickelbeck committed
110
    {
111
        s_PrintData = new wxPrintData();
dickelbeck's avatar
dickelbeck committed
112

113
        if( !s_PrintData->Ok() )
dickelbeck's avatar
dickelbeck committed
114 115 116
        {
            DisplayError( this, _( "Error Init Printer info" ) );
        }
117 118 119 120 121 122 123
        s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH );      // Default resolution = HIGH;
    }

    if( s_pageSetupData == NULL )
        s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );

    s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
124
    s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
125 126 127 128 129 130 131 132 133

    if( pageInfo.IsCustom() )
    {
        if( pageInfo.IsPortrait() )
            s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ),
                                                   Mils2mm( pageInfo.GetHeightMils() ) ) );
        else
            s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ),
                                                   Mils2mm( pageInfo.GetWidthMils() ) ) );
dickelbeck's avatar
dickelbeck committed
134
    }
plyatov's avatar
plyatov committed
135

136
    *s_PrintData = s_pageSetupData->GetPrintData();
137

138
    DIALOG_PRINT_USING_PRINTER dlg( this );
dickelbeck's avatar
dickelbeck committed
139

140
    dlg.ShowModal();
plyatov's avatar
plyatov committed
141 142 143
}


144
DIALOG_PRINT_USING_PRINTER::DIALOG_PRINT_USING_PRINTER( PCB_EDIT_FRAME* parent ) :
145
    DIALOG_PRINT_USING_PRINTER_base( parent )
146
{
147
    m_parent = parent;
148
    m_config = Kiface().KifaceSettings();
149

Dick Hollenbeck's avatar
Dick Hollenbeck committed
150 151 152
    memset( m_BoxSelectLayer, 0, sizeof( m_BoxSelectLayer ) );

    initValues( );
153 154 155 156 157

    if( GetSizer() )
    {
        GetSizer()->SetSizeHints( this );
    }
158

159
    Center();
160 161 162 163 164
#ifdef __WXMAC__
    /* Problems with modal on wx-2.9 - Anyway preview is standard for OSX */
   m_buttonPreview->Hide();
#endif

165
}
plyatov's avatar
plyatov committed
166

167

Dick Hollenbeck's avatar
Dick Hollenbeck committed
168
void DIALOG_PRINT_USING_PRINTER::initValues( )
169 170
{
    wxString msg;
171
    BOARD*   board = m_parent->GetBoard();
172

173
    s_Parameters.m_PageSetupData = s_pageSetupData;
174

Dick Hollenbeck's avatar
Dick Hollenbeck committed
175
    // Create layer list.
176
    wxString layerKey;
177

Dick Hollenbeck's avatar
Dick Hollenbeck committed
178
    LSEQ seq = board->GetEnabledLayers().UIOrder();
179

Dick Hollenbeck's avatar
Dick Hollenbeck committed
180 181 182
    for( ;  seq;  ++seq )
    {
        LAYER_ID layer = *seq;
183

Dick Hollenbeck's avatar
Dick Hollenbeck committed
184
        m_BoxSelectLayer[layer] = new wxCheckBox( this, -1, board->GetLayerName( layer ) );
185

Dick Hollenbeck's avatar
Dick Hollenbeck committed
186
        if( IsCopperLayer( layer ) )
187 188 189 190 191 192 193
            m_CopperLayersBoxSizer->Add( m_BoxSelectLayer[layer],
                                     0, wxGROW | wxALL, 1 );
        else
            m_TechnicalLayersBoxSizer->Add( m_BoxSelectLayer[layer],
                                     0, wxGROW | wxALL, 1 );

        layerKey.Printf( OPTKEY_LAYERBASE, layer );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
194

195
        bool option;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
196

197
        if( m_config->Read( layerKey, &option ) )
198
            m_BoxSelectLayer[layer]->SetValue( option );
dickelbeck's avatar
dickelbeck committed
199
        else
200
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
201
            if( s_SelectedLayers[layer] )
202 203
                m_BoxSelectLayer[layer]->SetValue( true );
        }
dickelbeck's avatar
dickelbeck committed
204 205
    }

206 207 208
    // Option for excluding contents of "Edges Pcb" layer
    m_Exclude_Edges_Pcb->Show( true );

dickelbeck's avatar
dickelbeck committed
209
    // Read the scale adjust option
210 211
    int scale_idx = 4; // default selected scale = ScaleList[4] = 1.000

212
    if( m_config )
dickelbeck's avatar
dickelbeck committed
213
    {
214 215 216 217 218
        m_config->Read( OPTKEY_PRINT_X_FINESCALE_ADJ, &s_Parameters.m_XScaleAdjust );
        m_config->Read( OPTKEY_PRINT_Y_FINESCALE_ADJ, &s_Parameters.m_YScaleAdjust );
        m_config->Read( OPTKEY_PRINT_SCALE, &scale_idx );
        m_config->Read( OPTKEY_PRINT_PAGE_FRAME, &s_Parameters.m_Print_Sheet_Ref, 1);
        m_config->Read( OPTKEY_PRINT_MONOCHROME_MODE, &s_Parameters.m_Print_Black_and_White, 1);
219
        m_config->Read( OPTKEY_PRINT_PAGE_PER_LAYER, &s_Parameters.m_OptionPrintPage, 0);
220
        int tmp;
221
        m_config->Read( OPTKEY_PRINT_PADS_DRILL,  &tmp, PRINT_PARAMETERS::SMALL_DRILL_SHAPE );
222
        s_Parameters.m_DrillShapeOpt = (PRINT_PARAMETERS::DrillShapeOptT) tmp;
charras's avatar
charras committed
223

224
        // Test for a reasonnable scale value. Set to 1 if problem
225 226 227 228 229
        if( s_Parameters.m_XScaleAdjust < MIN_SCALE ||
            s_Parameters.m_YScaleAdjust < MIN_SCALE ||
            s_Parameters.m_XScaleAdjust > MAX_SCALE ||
            s_Parameters.m_YScaleAdjust > MAX_SCALE )
            s_Parameters.m_XScaleAdjust = s_Parameters.m_YScaleAdjust = 1.0;
230

Dick Hollenbeck's avatar
Dick Hollenbeck committed
231 232 233
        s_SelectedLayers = LSET();

        for( seq.Rewind();  seq;  ++seq )
charras's avatar
charras committed
234
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
235
            LAYER_ID layer = *seq;
236

charras's avatar
charras committed
237 238 239 240 241 242
            wxString layerKey;
            bool     option;

            layerKey.Printf( OPTKEY_LAYERBASE, layer );

            option = false;
243
            if( m_config->Read( layerKey, &option ) )
charras's avatar
charras committed
244
            {
245
                m_BoxSelectLayer[layer]->SetValue( option );
charras's avatar
charras committed
246
                if( option )
Dick Hollenbeck's avatar
Dick Hollenbeck committed
247
                    s_SelectedLayers.set( layer );
charras's avatar
charras committed
248 249
            }
        }
dickelbeck's avatar
dickelbeck committed
250 251
    }

252
    m_ScaleOption->SetSelection( scale_idx );
253 254
    scale_idx = m_ScaleOption->GetSelection();
    s_Parameters.m_PrintScale =  s_ScaleList[scale_idx];
255 256 257
    m_Print_Mirror->SetValue(s_Parameters.m_PrintMirror);
    m_Exclude_Edges_Pcb->SetValue(m_ExcludeEdgeLayer);
    m_Print_Sheet_Ref->SetValue( s_Parameters.m_Print_Sheet_Ref );
dickelbeck's avatar
dickelbeck committed
258

259 260
    // Options to plot pads and vias holes
    m_Drill_Shape_Opt->SetSelection( s_Parameters.m_DrillShapeOpt );
261 262

    if( s_Parameters.m_Print_Black_and_White )
263
        m_ModeColorOption->SetSelection( 1 );
264 265
    else
        m_ModeColorOption->SetSelection( 0 );
266

267
    m_PagesOption->SetSelection(s_Parameters.m_OptionPrintPage);
268
    s_Parameters.m_PenDefaultSize = g_DrawDefaultLineThickness;
269
    AddUnitSymbol( *m_TextPenWidth, g_UserUnit );
270
    m_DialogPenWidth->SetValue(
271
        StringFromValue( g_UserUnit, s_Parameters.m_PenDefaultSize ) );
272

dickelbeck's avatar
dickelbeck committed
273
    // Create scale adjust option
274
    msg.Printf( wxT( "%f" ), s_Parameters.m_XScaleAdjust );
dickelbeck's avatar
dickelbeck committed
275
    m_FineAdjustXscaleOpt->SetValue( msg );
276

277
    msg.Printf( wxT( "%f" ), s_Parameters.m_YScaleAdjust );
dickelbeck's avatar
dickelbeck committed
278
    m_FineAdjustYscaleOpt->SetValue( msg );
279 280 281 282 283 284

    bool enable = (s_Parameters.m_PrintScale == 1.0);
    if( m_FineAdjustXscaleOpt )
        m_FineAdjustXscaleOpt->Enable(enable);
    if( m_FineAdjustYscaleOpt )
        m_FineAdjustYscaleOpt->Enable(enable);
plyatov's avatar
plyatov committed
285 286
}

dickelbeck's avatar
dickelbeck committed
287

Dick Hollenbeck's avatar
Dick Hollenbeck committed
288
int DIALOG_PRINT_USING_PRINTER::SetLayerSetFromListSelection()
plyatov's avatar
plyatov committed
289
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
290
    int page_count = 0;
291

Dick Hollenbeck's avatar
Dick Hollenbeck committed
292 293 294
    s_Parameters.m_PrintMaskLayer = LSET();

    for( unsigned ii = 0; ii < DIM(m_BoxSelectLayer); ++ii )
dickelbeck's avatar
dickelbeck committed
295
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
296
        if( !m_BoxSelectLayer[ii] )
297
            continue;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
298

299
        if( m_BoxSelectLayer[ii]->IsChecked() )
dickelbeck's avatar
dickelbeck committed
300 301
        {
            page_count++;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
302
            s_Parameters.m_PrintMaskLayer.set( ii );
dickelbeck's avatar
dickelbeck committed
303 304
        }
    }
305

306
    // In Pcbnew force the EDGE layer to be printed or not with the other layers
307 308 309 310 311 312 313
    m_ExcludeEdgeLayer = m_Exclude_Edges_Pcb->IsChecked();
    if( m_ExcludeEdgeLayer )
        s_Parameters.m_Flags = 0;
    else
        s_Parameters.m_Flags = 1;

    s_Parameters.m_PageCount = page_count;
dickelbeck's avatar
dickelbeck committed
314 315

    return page_count;
plyatov's avatar
plyatov committed
316 317
}

dickelbeck's avatar
dickelbeck committed
318

319
void DIALOG_PRINT_USING_PRINTER::OnCloseWindow( wxCloseEvent& event )
plyatov's avatar
plyatov committed
320
{
321
    SetPrintParameters();
322

323
    if( m_config )
dickelbeck's avatar
dickelbeck committed
324
    {
325 326 327 328
        ConfigBaseWriteDouble( m_config, OPTKEY_PRINT_X_FINESCALE_ADJ,
                               s_Parameters.m_XScaleAdjust );
        ConfigBaseWriteDouble( m_config, OPTKEY_PRINT_Y_FINESCALE_ADJ,
                               s_Parameters.m_YScaleAdjust );
329 330 331
        m_config->Write( OPTKEY_PRINT_SCALE, m_ScaleOption->GetSelection() );
        m_config->Write( OPTKEY_PRINT_PAGE_FRAME, s_Parameters.m_Print_Sheet_Ref);
        m_config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
332
        m_config->Write( OPTKEY_PRINT_PAGE_PER_LAYER, s_Parameters.m_OptionPrintPage );
333
        m_config->Write( OPTKEY_PRINT_PADS_DRILL, (long) s_Parameters.m_DrillShapeOpt );
charras's avatar
charras committed
334
        wxString layerKey;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
335 336

        for( unsigned layer = 0; layer < DIM(m_BoxSelectLayer);  ++layer )
charras's avatar
charras committed
337
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
338
            if( !m_BoxSelectLayer[layer] )
339
                continue;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
340

charras's avatar
charras committed
341
            layerKey.Printf( OPTKEY_LAYERBASE, layer );
342
            m_config->Write( layerKey, m_BoxSelectLayer[layer]->IsChecked() );
charras's avatar
charras committed
343
        }
dickelbeck's avatar
dickelbeck committed
344 345
    }
    EndModal( 0 );
plyatov's avatar
plyatov committed
346 347 348
}


349
void DIALOG_PRINT_USING_PRINTER::SetPrintParameters( )
plyatov's avatar
plyatov committed
350
{
351 352
    PCB_PLOT_PARAMS plot_opts = m_parent->GetPlotSettings();

353 354
    s_Parameters.m_PrintMirror = m_Print_Mirror->GetValue();
    s_Parameters.m_Print_Sheet_Ref = m_Print_Sheet_Ref->GetValue();
355
    s_Parameters.m_Print_Black_and_White =
356 357
        m_ModeColorOption->GetSelection() != 0;

358 359 360
    s_Parameters.m_DrillShapeOpt =
        (PRINT_PARAMETERS::DrillShapeOptT) m_Drill_Shape_Opt->GetSelection();

361 362
    if( m_PagesOption )
        s_Parameters.m_OptionPrintPage = m_PagesOption->GetSelection() != 0;
363

Dick Hollenbeck's avatar
Dick Hollenbeck committed
364
    SetLayerSetFromListSelection();
365 366 367

    int idx = m_ScaleOption->GetSelection();
    s_Parameters.m_PrintScale =  s_ScaleList[idx];
368
    plot_opts.SetScale( s_Parameters.m_PrintScale );
369

dickelbeck's avatar
dickelbeck committed
370
    if( m_FineAdjustXscaleOpt )
371 372 373 374 375 376
    {
        if( s_Parameters.m_XScaleAdjust > MAX_SCALE ||
            s_Parameters.m_YScaleAdjust > MAX_SCALE )
            DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very large value" ) );
        m_FineAdjustXscaleOpt->GetValue().ToDouble( &s_Parameters.m_XScaleAdjust );
    }
dickelbeck's avatar
dickelbeck committed
377
    if( m_FineAdjustYscaleOpt )
378 379 380 381 382 383 384
    {
        // Test for a reasonnable scale value
        if( s_Parameters.m_XScaleAdjust < MIN_SCALE ||
            s_Parameters.m_YScaleAdjust < MIN_SCALE )
            DisplayInfoMessage( NULL, _( "Warning: Scale option set to a very small value" ) );
        m_FineAdjustYscaleOpt->GetValue().ToDouble( &s_Parameters.m_YScaleAdjust );
    }
385

386 387
    plot_opts.SetFineScaleAdjustX( s_Parameters.m_XScaleAdjust );
    plot_opts.SetFineScaleAdjustY( s_Parameters.m_YScaleAdjust );
388 389 390

    m_parent->SetPlotSettings( plot_opts );

391
    SetPenWidth();
plyatov's avatar
plyatov committed
392 393
}

dickelbeck's avatar
dickelbeck committed
394

395
void DIALOG_PRINT_USING_PRINTER::SetPenWidth()
plyatov's avatar
plyatov committed
396
{
397 398 399
    // Get the new pen width value, and verify min et max value
    // NOTE: s_Parameters.m_PenDefaultSize is in internal units

400
    s_Parameters.m_PenDefaultSize = ValueFromTextCtrl( *m_DialogPenWidth );
401

402
    if( s_Parameters.m_PenDefaultSize > PEN_WIDTH_MAX_VALUE )
dickelbeck's avatar
dickelbeck committed
403
    {
404
        s_Parameters.m_PenDefaultSize = PEN_WIDTH_MAX_VALUE;
dickelbeck's avatar
dickelbeck committed
405
    }
406

407
    if( s_Parameters.m_PenDefaultSize < PEN_WIDTH_MIN_VALUE )
dickelbeck's avatar
dickelbeck committed
408
    {
409
        s_Parameters.m_PenDefaultSize = PEN_WIDTH_MIN_VALUE;
dickelbeck's avatar
dickelbeck committed
410
    }
411

412 413
    g_DrawDefaultLineThickness = s_Parameters.m_PenDefaultSize;

414
    m_DialogPenWidth->SetValue(
415
        StringFromValue( g_UserUnit, s_Parameters.m_PenDefaultSize ) );
plyatov's avatar
plyatov committed
416 417
}

418 419 420 421
void DIALOG_PRINT_USING_PRINTER::OnScaleSelectionClick( wxCommandEvent& event )
{
    double scale = s_ScaleList[m_ScaleOption->GetSelection()];
    bool enable = (scale == 1.0);
422

423 424 425 426 427 428
    if( m_FineAdjustXscaleOpt )
        m_FineAdjustXscaleOpt->Enable(enable);
    if( m_FineAdjustYscaleOpt )
        m_FineAdjustYscaleOpt->Enable(enable);
}

plyatov's avatar
plyatov committed
429

430
void DIALOG_PRINT_USING_PRINTER::OnPageSetup( wxCommandEvent& event )
plyatov's avatar
plyatov committed
431
{
432
    wxPageSetupDialog pageSetupDialog( this, s_pageSetupData );
433
    pageSetupDialog.ShowModal();
dickelbeck's avatar
dickelbeck committed
434

435 436
    (*s_PrintData) = pageSetupDialog.GetPageSetupDialogData().GetPrintData();
    (*s_pageSetupData) = pageSetupDialog.GetPageSetupDialogData();
plyatov's avatar
plyatov committed
437 438 439
}


440
void DIALOG_PRINT_USING_PRINTER::OnPrintPreview( wxCommandEvent& event )
plyatov's avatar
plyatov committed
441
{
442
    SetPrintParameters( );
dickelbeck's avatar
dickelbeck committed
443

444 445 446 447 448 449 450 451
    // If no layer selected, we have no plot. prompt user if it happens
    // because he could think there is a bug in Pcbnew:
    if( s_Parameters.m_PrintMaskLayer == 0 )
    {
        DisplayError( this, _( "No layer selected" ) );
        return;
    }

dickelbeck's avatar
dickelbeck committed
452
    // Pass two printout objects: for preview, and possible printing.
453
    wxString        title   = _( "Print Preview" );
dickelbeck's avatar
dickelbeck committed
454
    wxPrintPreview* preview =
455 456
        new wxPrintPreview( new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
                            new BOARD_PRINTOUT_CONTROLLER( s_Parameters, m_parent, title ),
457
                            s_PrintData );
dickelbeck's avatar
dickelbeck committed
458 459 460

    if( preview == NULL )
    {
461
        DisplayError( this, wxT( "OnPrintPreview() problem" ) );
dickelbeck's avatar
dickelbeck committed
462 463
        return;
    }
464

465
    // Uses the parent position and size.
466 467
    wxPoint         WPos  = m_parent->GetPosition();
    wxSize          WSize = m_parent->GetSize();
plyatov's avatar
plyatov committed
468

469 470
    preview->SetZoom( 100 );

471
    wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );
dickelbeck's avatar
dickelbeck committed
472 473

    frame->Initialize();
474
    frame->Show( true );
plyatov's avatar
plyatov committed
475 476 477
}


478
void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
plyatov's avatar
plyatov committed
479
{
480
    SetPrintParameters( );
481 482

    // If no layer selected, we have no plot. prompt user if it happens
483
    // because he could think there is a bug in Pcbnew:
484
    if( s_Parameters.m_PrintMaskLayer == 0 )
485 486 487 488 489
    {
        DisplayError( this, _( "No layer selected" ) );
        return;
    }

490
    wxPrintDialogData printDialogData( *s_PrintData );
plyatov's avatar
plyatov committed
491

charras's avatar
charras committed
492
    wxPrinter         printer( &printDialogData );
plyatov's avatar
plyatov committed
493

494
    wxString          title = _( "Print" );
495
    BOARD_PRINTOUT_CONTROLLER      printout( s_Parameters, m_parent, title );
plyatov's avatar
plyatov committed
496

497 498
    // Alexander's patch had this removed altogether, waiting for testing.
#if 0 && !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
charras's avatar
charras committed
499
    wxDC*             dc = printout.GetDC();
dickelbeck's avatar
dickelbeck committed
500
    ( (wxPostScriptDC*) dc )->SetResolution( 600 );  // Postscript DC resolution is 600 ppi
plyatov's avatar
plyatov committed
501 502
#endif

503
    if( !printer.Print( this, &printout, true ) )
dickelbeck's avatar
dickelbeck committed
504 505 506
    {
        if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
            DisplayError( this, _( "There was a problem printing" ) );
plyatov's avatar
plyatov committed
507
        return;
dickelbeck's avatar
dickelbeck committed
508 509 510
    }
    else
    {
511
        *s_PrintData = printer.GetPrintDialogData().GetPrintData();
dickelbeck's avatar
dickelbeck committed
512
    }
plyatov's avatar
plyatov committed
513 514
}