Commit 64be6fd2 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Eeschema: converted plot PS dialog from Dialogblocks to wxFormBuilder Fixed a...

Eeschema: converted plot PS dialog from Dialogblocks to wxFormBuilder Fixed a minor bug when plotting shapes with filled in background option. Pcbnew: Added locked modules block patch
parent 6566b0c5
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -16,3 +16,4 @@ config.h
install_manifest.txt
install_manifest.txt
Documentation/doxygen
Documentation/doxygen
*.cmake
*.cmake
*.bak
+3 −1
Original line number Original line Diff line number Diff line
@@ -2,6 +2,7 @@ add_definitions(-DEESCHEMA)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
                    ${CMAKE_SOURCE_DIR}/common
                    ${CMAKE_SOURCE_DIR}/common
                    ${CMAKE_SOURCE_DIR}/dialogs
                    ${Boost_INCLUDE_DIR}
                    ${Boost_INCLUDE_DIR}
                   )
                   )


@@ -36,6 +37,8 @@ set(EESCHEMA_SRCS
    database.cpp
    database.cpp
    delete.cpp
    delete.cpp
    delsheet.cpp
    delsheet.cpp
    dialogs/dialog_plot_schematic_PS.cpp
    dialogs/dialog_plot_schematic_PS_base.cpp
    dialog_annotate_base.cpp
    dialog_annotate_base.cpp
    dialog_bodygraphictext_properties_base.cpp
    dialog_bodygraphictext_properties_base.cpp
    dialog_build_BOM.cpp
    dialog_build_BOM.cpp
@@ -116,7 +119,6 @@ set(EESCHEMA_SRCS
    pinedit.cpp
    pinedit.cpp
    plot.cpp
    plot.cpp
    plothpgl.cpp
    plothpgl.cpp
    plotps.cpp
    plotdxf.cpp
    plotdxf.cpp
    read_from_file_schematic_items_descriptions.cpp
    read_from_file_schematic_items_descriptions.cpp
    save_schemas.cpp
    save_schemas.cpp
+297 −0
Original line number Original line Diff line number Diff line
/** @file dialog_plot_schematic_ps.cpp
 */

/*
 * This program source code file is part of KICAD, a free EDA CAD application.
 *
 * Copyright (C) 1992-2010 Jean-Pieere 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 "gr_basic.h"
#include "common.h"
#include "confirm.h"
#include "worksheet.h"
#include "plot_common.h"

#include "program.h"
#include "general.h"
#include "protos.h"

enum PageFormatReq {
    PAGE_SIZE_AUTO,
    PAGE_SIZE_A4,
    PAGE_SIZE_A
};

#include "dialog_plot_schematic_PS_base.h"

class DIALOG_PLOT_SCHEMATIC_PS : public DIALOG_PLOT_SCHEMATIC_PS_BASE
{
private:
    WinEDA_SchematicFrame* m_Parent;

public:

    /// Constructors
    DIALOG_PLOT_SCHEMATIC_PS( WinEDA_SchematicFrame* parent );

private:
    static bool m_plotColorOpt;
    static int  m_pageSizeSelect;
    static bool m_plot_Sheet_Ref;
    bool        m_select_PlotAll;
private:
    void OnPlotPsCurrentExecuteClick( wxCommandEvent& event );
    void OnPlotPsAllExecuteClick( wxCommandEvent& event );
    void OnCancelClick( wxCommandEvent& event );

    void initDlg();
    void initOptVars();
    void createPSFile();
    void plotOneSheetPS( const wxString& FileName,
                         SCH_SCREEN* screen, Ki_PageDescr* sheet,
                         wxPoint plot_offset, double scale );
};
/* static variables (staic to remember last state: */
bool DIALOG_PLOT_SCHEMATIC_PS::m_plotColorOpt   = false;
int DIALOG_PLOT_SCHEMATIC_PS:: m_pageSizeSelect = PAGE_SIZE_AUTO;
bool DIALOG_PLOT_SCHEMATIC_PS::m_plot_Sheet_Ref = true;


void WinEDA_SchematicFrame::ToPlot_PS( wxCommandEvent& event )
{
    DIALOG_PLOT_SCHEMATIC_PS dlg( this );

    dlg.ShowModal();
}


DIALOG_PLOT_SCHEMATIC_PS::DIALOG_PLOT_SCHEMATIC_PS( WinEDA_SchematicFrame* parent ) :
    DIALOG_PLOT_SCHEMATIC_PS_BASE( parent )
{
    m_Parent = parent;
    m_select_PlotAll = false;
    initDlg();

    GetSizer()->SetSizeHints( this );
    Centre();
}


/*!
 * Control creation for DIALOG_PLOT_SCHEMATIC_PS
 */

void DIALOG_PLOT_SCHEMATIC_PS::initDlg()
{
    SetFocus(); // make the ESC work

    // Set options
    m_SizeOption->SetSelection( m_pageSizeSelect );
    m_PlotPSColorOption->SetSelection( m_plotColorOpt ? 1 : 0 );
    m_Plot_Sheet_Ref_Ctrl->SetValue( m_plot_Sheet_Ref );

    AddUnitSymbol( *m_defaultLineWidthTitle, g_UserUnit );
    PutValueInLocalUnits( *m_DefaultLineSizeCtrl,
                          g_DrawDefaultLineThickness, EESCHEMA_INTERNAL_UNIT );
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
 */

void DIALOG_PLOT_SCHEMATIC_PS::OnPlotPsCurrentExecuteClick( wxCommandEvent& event )
{
    m_select_PlotAll = false;

    initOptVars();
    createPSFile();
    m_MsgBox->AppendText( wxT( "*****\n" ) );
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
 */

void DIALOG_PLOT_SCHEMATIC_PS::OnPlotPsAllExecuteClick( wxCommandEvent& event )
{
    m_select_PlotAll = TRUE;

    initOptVars();
    createPSFile();
    m_MsgBox->AppendText( wxT( "*****\n" ) );
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
 */

void DIALOG_PLOT_SCHEMATIC_PS::OnCancelClick( wxCommandEvent& event )
{
    initOptVars();
    EndModal( 0 );
}


void DIALOG_PLOT_SCHEMATIC_PS::initOptVars()
{
    m_plot_Sheet_Ref = m_Plot_Sheet_Ref_Ctrl->GetValue();
    m_plotColorOpt   = m_PlotPSColorOption->GetSelection();
    m_pageSizeSelect = m_SizeOption->GetSelection();
    g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DefaultLineSizeCtrl,
                                                          EESCHEMA_INTERNAL_UNIT );
    if( g_DrawDefaultLineThickness < 1 )
        g_DrawDefaultLineThickness = 1;
}


void DIALOG_PLOT_SCHEMATIC_PS::createPSFile()
{
    SCH_SCREEN*     screen    = m_Parent->GetScreen();
    SCH_SCREEN*     oldscreen = screen;
    SCH_SHEET_PATH* sheetpath;
    SCH_SHEET_PATH* oldsheetpath = m_Parent->GetSheet();        // sheetpath is saved here
    wxString        plotFileName;
    Ki_PageDescr*   actualPage;                                 // page size selected in schematic
    Ki_PageDescr*   plotPage;                                   // page size selected to plot
    wxPoint         plot_offset;

    /* When printing all pages, the printed page is not the current page.
     * In complex hierarchies, we must update component references
     *  and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
     *  because in complex hierarchies a SCH_SCREEN (a drawing )
     *  is shared between many sheets and component references depend on the actual sheet path used
     */
    SCH_SHEET_LIST SheetList( NULL );

    sheetpath = SheetList.GetFirst();
    SCH_SHEET_PATH list;

    while( true )
    {
        if( m_select_PlotAll )
        {
            if( sheetpath == NULL )
                break;
            list.Clear();
            if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
            {
                m_Parent->m_CurrentSheet = &list;
                m_Parent->m_CurrentSheet->UpdateAllScreenReferences();
                m_Parent->SetSheetNumberAndCount();
                screen = m_Parent->m_CurrentSheet->LastScreen();
                ActiveScreen = screen;
            }
            else  // Should not happen
                return;
            sheetpath = SheetList.GetNext();
        }
        actualPage = screen->m_CurrentSheetDesc;
        switch( m_pageSizeSelect )
        {
        case PAGE_SIZE_A:
            plotPage = &g_Sheet_A;
            break;

        case PAGE_SIZE_A4:
            plotPage = &g_Sheet_A4;
            break;

        case PAGE_SIZE_AUTO:
        default:
            plotPage = actualPage;
            break;
        }

        double scalex = (double) plotPage->m_Size.x / actualPage->m_Size.x;
        double scaley = (double) plotPage->m_Size.y / actualPage->m_Size.y;
        double scale  = 10 * MIN( scalex, scaley );

        plot_offset.x = 0;
        plot_offset.y = 0;

        plotFileName = m_Parent->GetUniqueFilenameForCurrentSheet() + wxT( ".ps" );

        plotOneSheetPS( plotFileName, screen, plotPage, plot_offset, scale );

        if( !m_select_PlotAll )
            break;
    }

    ActiveScreen = oldscreen;
    m_Parent->m_CurrentSheet = oldsheetpath;
    m_Parent->m_CurrentSheet->UpdateAllScreenReferences();
    m_Parent->SetSheetNumberAndCount();
}


void DIALOG_PLOT_SCHEMATIC_PS::plotOneSheetPS( const wxString& FileName,
                                               SCH_SCREEN*     screen,
                                               Ki_PageDescr*   sheet,
                                               wxPoint         plot_offset,
                                               double          scale )
{
    wxString msg;

    FILE*    output_file = wxFopen( FileName, wxT( "wt" ) );

    if( output_file == NULL )
    {
        msg  = wxT( "\n** " );
        msg += _( "Unable to create " ) + FileName + wxT( " **\n" );
        m_MsgBox->AppendText( msg );
        wxBell();
        return;
    }

    SetLocaleTo_C_standard();
    msg.Printf( _( "Plot: %s " ), GetChars( FileName ) );
    m_MsgBox->AppendText( msg );

    PS_PLOTTER* plotter = new PS_PLOTTER();
    plotter->set_paper_size( sheet );
    plotter->set_viewport( plot_offset, scale, 0 );
    plotter->set_default_line_width( g_DrawDefaultLineThickness );
    plotter->set_color_mode( m_plotColorOpt );

    /* Init : */
    plotter->set_creator( wxT( "EESchema-PS" ) );
    plotter->set_filename( FileName );
    plotter->start_plot( output_file );

    if( m_plot_Sheet_Ref )
    {
        plotter->set_color( BLACK );
        m_Parent->PlotWorkSheet( plotter, screen );
    }

    PlotDrawlist( plotter, screen->EEDrawList );

    plotter->end_plot();
    delete plotter;
    SetLocaleTo_Default();

    m_MsgBox->AppendText( wxT( "Ok\n" ) );
}
+104 −0
Original line number Original line Diff line number Diff line
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep  8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "dialog_plot_schematic_PS_base.h"

///////////////////////////////////////////////////////////////////////////

DIALOG_PLOT_SCHEMATIC_PS_BASE::DIALOG_PLOT_SCHEMATIC_PS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	wxBoxSizer* bmainSizer;
	bmainSizer = new wxBoxSizer( wxVERTICAL );
	
	wxBoxSizer* bupperSizer;
	bupperSizer = new wxBoxSizer( wxHORIZONTAL );
	
	wxString m_SizeOptionChoices[] = { wxT("Schematic size"), wxT("Force size A4"), wxT("Force size A") };
	int m_SizeOptionNChoices = sizeof( m_SizeOptionChoices ) / sizeof( wxString );
	m_SizeOption = new wxRadioBox( this, wxID_ANY, wxT("Plot Page Size:"), wxDefaultPosition, wxDefaultSize, m_SizeOptionNChoices, m_SizeOptionChoices, 1, wxRA_SPECIFY_COLS );
	m_SizeOption->SetSelection( 0 );
	bupperSizer->Add( m_SizeOption, 1, wxALL, 5 );
	
	
	bupperSizer->Add( 10, 10, 0, wxEXPAND, 5 );
	
	wxBoxSizer* sbSizerMiddle;
	sbSizerMiddle = new wxBoxSizer( wxVERTICAL );
	
	wxString m_PlotPSColorOptionChoices[] = { wxT("B/W"), wxT("Color") };
	int m_PlotPSColorOptionNChoices = sizeof( m_PlotPSColorOptionChoices ) / sizeof( wxString );
	m_PlotPSColorOption = new wxRadioBox( this, wxID_ANY, wxT("Plot Mode:"), wxDefaultPosition, wxDefaultSize, m_PlotPSColorOptionNChoices, m_PlotPSColorOptionChoices, 1, wxRA_SPECIFY_COLS );
	m_PlotPSColorOption->SetSelection( 0 );
	sbSizerMiddle->Add( m_PlotPSColorOption, 0, wxALL|wxEXPAND, 5 );
	
	m_Plot_Sheet_Ref_Ctrl = new wxCheckBox( this, wxID_ANY, wxT("Print page references"), wxDefaultPosition, wxDefaultSize, 0 );
	m_Plot_Sheet_Ref_Ctrl->SetValue(true); 
	sbSizerMiddle->Add( m_Plot_Sheet_Ref_Ctrl, 0, wxALL|wxEXPAND, 5 );
	
	bupperSizer->Add( sbSizerMiddle, 1, wxEXPAND, 5 );
	
	
	bupperSizer->Add( 10, 10, 0, wxEXPAND, 5 );
	
	wxBoxSizer* bbuttonsSizer;
	bbuttonsSizer = new wxBoxSizer( wxVERTICAL );
	
	m_buttonPlotPage = new wxButton( this, wxID_ANY, wxT("&Plot Page"), wxDefaultPosition, wxDefaultSize, 0 );
	bbuttonsSizer->Add( m_buttonPlotPage, 0, wxALL|wxEXPAND, 5 );
	
	m_buttonPlotAll = new wxButton( this, wxID_ANY, wxT("Plot A&LL"), wxDefaultPosition, wxDefaultSize, 0 );
	bbuttonsSizer->Add( m_buttonPlotAll, 0, wxALL|wxEXPAND, 5 );
	
	m_buttonClose = new wxButton( this, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0 );
	bbuttonsSizer->Add( m_buttonClose, 0, wxALL|wxEXPAND, 5 );
	
	bupperSizer->Add( bbuttonsSizer, 0, wxALIGN_CENTER_VERTICAL, 5 );
	
	bmainSizer->Add( bupperSizer, 0, wxEXPAND, 5 );
	
	wxBoxSizer* bSizerLineWidth;
	bSizerLineWidth = new wxBoxSizer( wxHORIZONTAL );
	
	m_defaultLineWidthTitle = new wxStaticText( this, wxID_ANY, wxT("Default line width:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_defaultLineWidthTitle->Wrap( -1 );
	bSizerLineWidth->Add( m_defaultLineWidthTitle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_DefaultLineSizeCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	bSizerLineWidth->Add( m_DefaultLineSizeCtrl, 1, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 );
	
	bmainSizer->Add( bSizerLineWidth, 0, wxEXPAND, 5 );
	
	m_staticText1 = new wxStaticText( this, wxID_ANY, wxT("Messages :"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText1->Wrap( -1 );
	bmainSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_MsgBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
	m_MsgBox->SetMinSize( wxSize( -1,150 ) );
	
	bmainSizer->Add( m_MsgBox, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	this->SetSizer( bmainSizer );
	this->Layout();
	
	this->Centre( wxBOTH );
	
	// Connect Events
	m_buttonPlotPage->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnPlotPsCurrentExecuteClick ), NULL, this );
	m_buttonPlotAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnPlotPsAllExecuteClick ), NULL, this );
	m_buttonClose->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnCancelClick ), NULL, this );
}

DIALOG_PLOT_SCHEMATIC_PS_BASE::~DIALOG_PLOT_SCHEMATIC_PS_BASE()
{
	// Disconnect Events
	m_buttonPlotPage->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnPlotPsCurrentExecuteClick ), NULL, this );
	m_buttonPlotAll->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnPlotPsAllExecuteClick ), NULL, this );
	m_buttonClose->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PLOT_SCHEMATIC_PS_BASE::OnCancelClick ), NULL, this );
	
}
+732 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading