dialog_print_for_modedit.cpp 7.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/****************************************/
/* File: dialog_print_for_modedit.cpp */
/****************************************/

// Set this to 1 if you want to test PostScript printing under MSW.
#define wxTEST_POSTSCRIPT_IN_MSW 1

#include "fctsys.h"
#include "appl_wxstruct.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
14
#include "module_editor_frame.h"
15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "pcbplot.h"

#include "dialog_print_for_modedit_base.h"
#include "printout_controler.h"

#define WIDTH_MAX_VALUE           1000
#define WIDTH_MIN_VALUE           1

static double s_ScaleList[] =
{ 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 };


// static print data and page setup data, to remember settings during the session
static PRINT_PARAMETERS  s_Parameters;
29 30
static wxPrintData* s_PrintData;
static wxPageSetupDialogData* s_pageSetupData = (wxPageSetupDialogData*) NULL;
31 32 33 34 35 36 37 38


/* Dialog to print schematic. Class derived from DIALOG_PRINT_FOR_MODEDIT_BASE
 *  created by wxFormBuilder
 */
class DIALOG_PRINT_FOR_MODEDIT : public DIALOG_PRINT_FOR_MODEDIT_BASE
{
private:
39 40
    EDA_DRAW_FRAME* m_Parent;
    wxConfig*       m_Config;
41 42

public:
43
    DIALOG_PRINT_FOR_MODEDIT( EDA_DRAW_FRAME* parent );
44 45 46 47 48 49 50 51 52 53 54 55 56 57
    ~DIALOG_PRINT_FOR_MODEDIT() {};

private:
    void OnCloseWindow( wxCloseEvent& event );
    void OnPrintSetup( wxCommandEvent& event );
    void OnPrintPreview( wxCommandEvent& event );
    void OnPrintButtonClick( wxCommandEvent& event );

    void OnButtonCancelClick( wxCommandEvent& event ) { Close(); }
    void InitValues( );
};


/*************************************************************/
58
void FOOTPRINT_EDIT_FRAME::ToPrinter( wxCommandEvent& event )
59 60 61 62 63
/*************************************************************/
/* Virtual function:
 * Display the print dialog
 */
{
64
    if( s_PrintData == NULL )  // First print
65
    {
66
        s_PrintData = new wxPrintData();
67

68
        if( !s_PrintData->Ok() )
69 70 71
        {
            DisplayError( this, _( "Error Init Printer info" ) );
        }
72 73
        s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH );      // Default resolution = HIGHT;
        s_PrintData->SetOrientation( DEFAULT_ORIENTATION_PAPER );
74 75 76 77 78 79 80 81
    }

    DIALOG_PRINT_FOR_MODEDIT* frame = new DIALOG_PRINT_FOR_MODEDIT( this );

    frame->ShowModal(); frame->Destroy();
}

/*************************************************************************************/
82
DIALOG_PRINT_FOR_MODEDIT::DIALOG_PRINT_FOR_MODEDIT( EDA_DRAW_FRAME* parent ) :
83 84 85 86 87 88 89 90
    DIALOG_PRINT_FOR_MODEDIT_BASE( parent )
/*************************************************************************************/
{
    m_Parent = parent;
    s_Parameters.m_ForceCentered = true;
    m_Config = wxGetApp().m_EDA_Config;
    InitValues();

91
    m_buttonPrint->SetDefault();
charras's avatar
charras committed
92 93
    GetSizer()->SetSizeHints( this );
    Center();
94 95 96 97 98 99 100 101 102
}


/************************************************************************/
void DIALOG_PRINT_FOR_MODEDIT::InitValues( )
/************************************************************************/
{
    SetFocus();

103 104 105 106 107 108 109 110 111 112 113
    if( s_pageSetupData == NULL )
    {
        s_pageSetupData = new wxPageSetupDialogData;
        // Set initial page margins.
        // Margins are already set in Pcbnew, so we cans use 0
        s_pageSetupData->SetMarginTopLeft(wxPoint(0, 0));
        s_pageSetupData->SetMarginBottomRight(wxPoint(0, 0));
    }

    s_Parameters.m_PageSetupData = s_pageSetupData;

114 115 116 117 118 119 120 121
    // Read the scale adjust option
    int scale_Select = 3; // default selected scale = ScaleList[3] = 1
    if( m_Config )
    {
        m_Config->Read( OPTKEY_PRINT_MODULE_SCALE, &scale_Select );
        m_Config->Read( OPTKEY_PRINT_MONOCHROME_MODE, &s_Parameters.m_Print_Black_and_White, 1);
    }

122 123
    extern int g_DrawDefaultLineThickness;
    s_Parameters.m_PenDefaultSize = g_DrawDefaultLineThickness;
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
    m_ScaleOption->SetSelection( scale_Select );

    if( s_Parameters.m_Print_Black_and_White )
        m_ModeColorOption->SetSelection( 1 );
}


/********************************************************************/
void DIALOG_PRINT_FOR_MODEDIT::OnCloseWindow( wxCloseEvent& event )
/********************************************************************/
{
    if( m_Config )
    {
        m_Config->Write( OPTKEY_PRINT_MODULE_SCALE, m_ScaleOption->GetSelection() );
        m_Config->Write( OPTKEY_PRINT_MONOCHROME_MODE, s_Parameters.m_Print_Black_and_White);
    }
    EndModal( 0 );
}


/**********************************************************/
void DIALOG_PRINT_FOR_MODEDIT::OnPrintSetup( wxCommandEvent& event )
/**********************************************************/

/* Open a dialog box for printer setup (printer options, page size ...)
 */
{
151
    wxPrintDialogData printDialogData( *s_PrintData );
152 153 154 155 156

    if( printDialogData.Ok() )
    {
        wxPrintDialog printerDialog( this, &printDialogData );
        printerDialog.ShowModal();
157
        *s_PrintData = printerDialog.GetPrintDialogData().GetPrintData();
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    }
    else
        DisplayError( this, _( "Printer Problem!" ) );
}


/************************************************************/
void DIALOG_PRINT_FOR_MODEDIT::OnPrintPreview( wxCommandEvent& event )
/************************************************************/

/* Open and display a previewer frame for printing
 */
{
    s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
    s_Parameters.m_PrintScale = s_ScaleList[m_ScaleOption->GetSelection()];

    // Pass two printout objects: for preview, and possible printing.
    wxString        title   = _( "Print Preview" );
    wxPrintPreview* preview =
        new wxPrintPreview( new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ),
                            new BOARD_PRINTOUT_CONTROLER( s_Parameters, m_Parent, title ),
179
                            s_PrintData );
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

    if( preview == NULL )
    {
        DisplayError( this, wxT( "OnPrintPreview() problem" ) );
        return;
    }

     // Uses the parent position and size.
    // @todo uses last position and size ans store them when exit in m_Config
    wxPoint         WPos  = m_Parent->GetPosition();
    wxSize          WSize = m_Parent->GetSize();

    wxPreviewFrame* frame = new wxPreviewFrame( preview, this, title, WPos, WSize );

    frame->Initialize();
    frame->Show( TRUE );
}


/***************************************************************************/
void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event )
/***************************************************************************/

/* Called on activate Print button
 */
{
    s_Parameters.m_Print_Black_and_White = m_ModeColorOption->GetSelection();
    s_Parameters.m_PrintScale = s_ScaleList[m_ScaleOption->GetSelection()];

209 210 211
    g_PcbPlotOptions.m_FineScaleAdjustX = s_Parameters.m_XScaleAdjust;
    g_PcbPlotOptions.m_FineScaleAdjustY = s_Parameters.m_YScaleAdjust;
    g_PcbPlotOptions.m_PlotScale = s_Parameters.m_PrintScale;
212

213
    wxPrintDialogData printDialogData( *s_PrintData );
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    wxPrinter         printer( &printDialogData );

    BOARD_PRINTOUT_CONTROLER      printout( s_Parameters, m_Parent, _( "Print Footprint" ) );

#if !defined(__WINDOWS__) && !wxCHECK_VERSION(2,9,0)
    wxDC*             dc = printout.GetDC();
    ( (wxPostScriptDC*) dc )->SetResolution( 600 );  // Postscript DC resolution is 600 ppi
#endif

    if( !printer.Print( this, &printout, TRUE ) )
    {
        if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
            DisplayError( this, _( "There was a problem printing" ) );
        return;
    }
    else
    {
231
        *s_PrintData = printer.GetPrintDialogData().GetPrintData();
232 233
    }
}