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

Eeschema: Plot dialogs: unify 5 dialogs (which means 5 duplicate code) to only...

Eeschema: Plot dialogs: unify 5 dialogs (which means 5 duplicate code) to only one plot dialog (like in Pcbnew)
clean duplicate code.
Simplify HPGL dialog: plot offet removed and replace by only one option (plot origin to center of sheet or not)
This is surely enought.
parent a9744e3f
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -175,9 +175,9 @@ void HPGL_PLOTTER::SetDash( bool dashed )
{
{
    wxASSERT( outputFile );
    wxASSERT( outputFile );
    if( dashed )
    if( dashed )
        fputs( "LI 2;\n", stderr );
        fputs( "LI 2;\n", outputFile );
    else
    else
        fputs( "LI;\n", stderr );
        fputs( "LI;\n", outputFile );
}
}




+7 −10
Original line number Original line Diff line number Diff line
@@ -12,14 +12,6 @@ include_directories(


set(EESCHEMA_DLGS
set(EESCHEMA_DLGS
    dialogs/dialog_color_config.cpp
    dialogs/dialog_color_config.cpp
    dialogs/dialog_plot_schematic_DXF.cpp
    dialogs/dialog_plot_schematic_DXF_base.cpp
    dialogs/dialog_plot_schematic_HPGL.cpp
    dialogs/dialog_plot_schematic_HPGL_base.cpp
    dialogs/dialog_plot_schematic_PS.cpp
    dialogs/dialog_plot_schematic_PS_base.cpp
    dialogs/dialog_plot_schematic_PDF.cpp
    dialogs/dialog_plot_schematic_PDF_base.cpp
    dialogs/annotate_dialog.cpp
    dialogs/annotate_dialog.cpp
    dialogs/dialog_annotate_base.cpp
    dialogs/dialog_annotate_base.cpp
    dialogs/dialog_lib_edit_text.cpp
    dialogs/dialog_lib_edit_text.cpp
@@ -50,6 +42,8 @@ set(EESCHEMA_DLGS
    dialogs/dialog_lib_new_component.cpp
    dialogs/dialog_lib_new_component.cpp
    dialogs/dialog_lib_new_component_base.cpp
    dialogs/dialog_lib_new_component_base.cpp
    dialogs/dialog_netlist_base.cpp
    dialogs/dialog_netlist_base.cpp
    dialogs/dialog_plot_schematic_base.cpp
    dialogs/dialog_plot_schematic.cpp
    dialogs/dialog_print_using_printer_base.cpp
    dialogs/dialog_print_using_printer_base.cpp
    dialogs/dialog_print_using_printer.cpp
    dialogs/dialog_print_using_printer.cpp
    dialogs/dialog_sch_edit_sheet_pin.cpp
    dialogs/dialog_sch_edit_sheet_pin.cpp
@@ -58,8 +52,6 @@ set(EESCHEMA_DLGS
    dialogs/dialog_sch_sheet_props_base.cpp
    dialogs/dialog_sch_sheet_props_base.cpp
    dialogs/dialog_schematic_find.cpp
    dialogs/dialog_schematic_find.cpp
    dialogs/dialog_schematic_find_base.cpp
    dialogs/dialog_schematic_find_base.cpp
    dialogs/dialog_SVG_print.cpp
    dialogs/dialog_SVG_print_base.cpp
    )
    )


set(EESCHEMA_SRCS
set(EESCHEMA_SRCS
@@ -125,6 +117,11 @@ set(EESCHEMA_SRCS
    onrightclick.cpp
    onrightclick.cpp
    operations_on_items_lists.cpp
    operations_on_items_lists.cpp
    pinedit.cpp
    pinedit.cpp
    plot_schematic_DXF.cpp
    plot_schematic_HPGL.cpp
    plot_schematic_PS.cpp
    plot_schematic_PDF.cpp
    plot_schematic_SVG.cpp
    sch_base_frame.cpp
    sch_base_frame.cpp
    sch_bitmap.cpp
    sch_bitmap.cpp
    sch_bus_entry.cpp
    sch_bus_entry.cpp
+0 −291
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 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
 */

/**
 * @file eeschema/dialogs/dialog_SVG_print.cpp
 */

#include <fctsys.h>
#include <appl_wxstruct.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <gestfich.h>
#include <class_sch_screen.h>
#include <wxEeschemaStruct.h>
#include <dcsvg.h>
#include <base_units.h>

#include <general.h>
#include <libeditframe.h>
#include <sch_sheet_path.h>

#include <dialog_SVG_print.h>


// Keys for configuration
#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" )

#define WIDTH_MAX_VALUE 100
#define WIDTH_MIN_VALUE 1

// Variables locales
static bool s_Print_Frame_Ref      = true;
static int  s_PlotBlackAndWhite    = 0;


/*!
 * DIALOG_SVG_PRINT functions
 */
DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( EDA_DRAW_FRAME* parent ) :
    DIALOG_SVG_PRINT_base( parent )
{
    m_Parent   = parent;
    m_Config   = wxGetApp().GetSettings();
}


void DIALOG_SVG_PRINT::OnInitDialog( wxInitDialogEvent& event )
{
    SetFocus();     // Make ESC key working

    if( m_Config )
    {
        m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_PlotBlackAndWhite );
    }

    m_ModeColorOption->SetSelection( s_PlotBlackAndWhite );

    AddUnitSymbol( *m_TextPenWidth, g_UserUnit );
    m_DialogPenWidth->SetValue(
        ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) );
    m_Print_Sheet_Ref->SetValue( s_Print_Frame_Ref );

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


void DIALOG_SVG_PRINT::SetPenWidth()
{
    g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DialogPenWidth );

    if( g_DrawDefaultLineThickness > WIDTH_MAX_VALUE )
    {
        g_DrawDefaultLineThickness = WIDTH_MAX_VALUE;
    }

    if( g_DrawDefaultLineThickness < WIDTH_MIN_VALUE )
    {
        g_DrawDefaultLineThickness = WIDTH_MIN_VALUE;
    }

    m_DialogPenWidth->SetValue(
        ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) );
}


void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref )
{
    wxString    msg;
    wxFileName  fn;

    SetPenWidth();

    g_DrawDefaultLineThickness =
    ReturnValueFromTextCtrl( *m_DialogPenWidth );

    SCH_SCREEN* screen = (SCH_SCREEN*) m_Parent->GetScreen();

    if( aPrintAll && m_Parent->IsType( SCHEMATIC_FRAME_TYPE ) )
    {
        SCH_EDIT_FRAME*  schframe = (SCH_EDIT_FRAME*) m_Parent;
        SCH_SHEET_PATH*  sheetpath;
        SCH_SHEET_PATH   oldsheetpath = schframe->GetCurrentSheet();
        SCH_SCREEN*      schscreen = schframe->GetScreen();
        SCH_SHEET_LIST   SheetList( NULL );
        sheetpath = SheetList.GetFirst();
        SCH_SHEET_PATH   list;

        for( ; ; )
        {
            if( sheetpath == NULL )
                break;

            list.Clear();

            if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
            {
                schframe->SetCurrentSheet( list );
                schframe->GetCurrentSheet().UpdateAllScreenReferences();
                schframe->SetSheetNumberAndCount();
                schscreen = schframe->GetCurrentSheet().LastScreen();
            }
            else  // Should not happen
                return;

            sheetpath = SheetList.GetNext();

            fn = schframe->GetUniqueFilenameForCurrentSheet() + wxT( ".svg" );

            bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) schscreen,
                                        m_ModeColorOption->GetSelection() == 0 ? false : true,
                                        aPrint_Sheet_Ref );
            msg = _( "Create file " ) + fn.GetFullPath();
            if( !success )
                msg += _( " error" );
            msg += wxT( "\n" );
            m_MessagesBox->AppendText( msg );
        }

        schframe->SetCurrentSheet( oldsheetpath );
        schframe->GetCurrentSheet().UpdateAllScreenReferences();
        schframe->SetSheetNumberAndCount();
    }
    else
    {
        fn = m_FileNameCtrl->GetValue();

        if( !fn.IsOk() )
            fn = screen->GetFileName();

        fn.SetExt( wxT( "svg" ) );
        fn.MakeAbsolute();

        bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) screen,
                                    m_ModeColorOption->GetSelection() == 0 ? false : true,
                                    aPrint_Sheet_Ref );
        msg = _( "Create file " ) + fn.GetFullPath();

        if( !success )
            msg += _( " error" );

        msg += wxT( "\n" );
        m_MessagesBox->AppendText( msg );
    }
}


bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame,
                                    const wxString& FullFileName,
                                    SCH_SCREEN*     screen,
                                    bool            aPrintBlackAndWhite,
                                    bool            aPrint_Sheet_Ref )
{
    int     tmpzoom;
    wxPoint tmp_startvisu;
    wxSize  sheetSize;          // Sheet size in internal units
    wxPoint old_org;
    bool    success = true;

    tmp_startvisu = screen->m_StartVisu;
    tmpzoom    = screen->GetZoom();
    old_org    = screen->m_DrawOrg;
    screen->m_DrawOrg.x    = screen->m_DrawOrg.y = 0;
    screen->m_StartVisu.x  = screen->m_StartVisu.y = 0;

    sheetSize = screen->GetPageSettings().GetSizeIU();  // page size in 1/1000 inch, ie in internal units

    screen->SetScalingFactor( 1.0 );
    EDA_DRAW_PANEL* panel = frame->GetCanvas();

    LOCALE_IO   toggle;

    double dpi = 1000.0*IU_PER_MILS;
    wxPoint origin;
    KicadSVGFileDC dc( FullFileName, origin, sheetSize, dpi );

    EDA_RECT    tmp = *panel->GetClipBox();
    GRResetPenAndBrush( &dc );
    GRForceBlackPen( aPrintBlackAndWhite );


    panel->SetClipBox( EDA_RECT( wxPoint( -0x3FFFFF0, -0x3FFFFF0 ),
                                 wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );

    screen->m_IsPrinting = true;

    if( frame->IsType( SCHEMATIC_FRAME_TYPE ) )
        screen->Draw( panel, &dc, GR_COPY );

    if( frame->IsType( LIBEDITOR_FRAME_TYPE ) )
        ((LIB_EDIT_FRAME*)frame)->RedrawComponent( &dc,
                                                   wxPoint(sheetSize.x/2,
                                                   sheetSize.y/2) );

    if( aPrint_Sheet_Ref )
        frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness,
                IU_PER_MILS, frame->GetScreenDesc() );

    screen->m_IsPrinting   = false;
    panel->SetClipBox( tmp );

    GRForceBlackPen( false );

    screen->m_StartVisu    = tmp_startvisu;
    screen->m_DrawOrg      = old_org;
    screen->SetZoom( tmpzoom );

    return success;
}


void DIALOG_SVG_PRINT::OnButtonPlotAllClick( wxCommandEvent& event )
{
    PrintSVGDoc( true, m_Print_Sheet_Ref->GetValue() );
}


void DIALOG_SVG_PRINT::OnButtonPlotCurrentClick( wxCommandEvent& event )
{
    PrintSVGDoc( false, m_Print_Sheet_Ref->GetValue() );
}


void DIALOG_SVG_PRINT::OnButtonCancelClick( wxCommandEvent& event )
{
    Close();
}


void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event )
{
    if( m_Config )
    {
        s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
        m_Config->Write( PLOTSVGMODECOLOR_KEY, s_PlotBlackAndWhite );
    }
    EndModal( 0 );
}


/* called on radiobox color/black and white selection
 */
void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event )
{
    s_PlotBlackAndWhite = m_ModeColorOption->GetSelection();
}
+0 −40
Original line number Original line Diff line number Diff line

#ifndef _DIALOG_SVG_PRINT_H_
#define _DIALOG_SVG_PRINT_H_


class EDA_DRAW_FRAME;


#include <dialog_SVG_print_base.h>


class DIALOG_SVG_PRINT : public DIALOG_SVG_PRINT_base
{
private:
    EDA_DRAW_FRAME* m_Parent;
    wxConfig*       m_Config;

public:
    DIALOG_SVG_PRINT( EDA_DRAW_FRAME* parent );
    ~DIALOG_SVG_PRINT() {}

private:
    void        OnCloseWindow( wxCloseEvent& event );
    void        OnInitDialog( wxInitDialogEvent& event );
    void        OnButtonPlotCurrentClick( wxCommandEvent& event );
    void        OnButtonPlotAllClick( wxCommandEvent& event );
    void        OnButtonCancelClick( wxCommandEvent& event );
    void        OnSetColorModeSelected( wxCommandEvent& event );
    void        SetPenWidth();
    void        PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref );

public:
    static bool DrawSVGPage( EDA_DRAW_FRAME* frame,
                             const wxString& FullFileName, SCH_SCREEN* screen,
                             bool aPrintBlackAndWhite = false,
                             bool aPrint_Sheet_Ref = false );
};


#endif    // _DIALOG_SVG_PRINT_H_
+0 −107
Original line number Original line Diff line number Diff line
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "dialog_SVG_print_base.h"

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

DIALOG_SVG_PRINT_base::DIALOG_SVG_PRINT_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( wxSize( -1,-1 ), wxDefaultSize );
	
	wxBoxSizer* bMainSizer;
	bMainSizer = new wxBoxSizer( wxVERTICAL );
	
	wxBoxSizer* bUpperSizer;
	bUpperSizer = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticBoxSizer* sbOptionsSizer;
	sbOptionsSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Print SVG options:") ), wxVERTICAL );
	
	m_TextPenWidth = new wxStaticText( this, wxID_ANY, _("Default Pen Size"), wxDefaultPosition, wxDefaultSize, 0 );
	m_TextPenWidth->Wrap( -1 );
	sbOptionsSizer->Add( m_TextPenWidth, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_DialogPenWidth = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_DialogPenWidth->SetToolTip( _("Selection of the default pen thickness used to draw items, when their thickness is set to 0.") );
	
	sbOptionsSizer->Add( m_DialogPenWidth, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
	
	wxString m_ModeColorOptionChoices[] = { _("Color"), _("Black and White") };
	int m_ModeColorOptionNChoices = sizeof( m_ModeColorOptionChoices ) / sizeof( wxString );
	m_ModeColorOption = new wxRadioBox( this, wxID_ANY, _("Print mode"), wxDefaultPosition, wxDefaultSize, m_ModeColorOptionNChoices, m_ModeColorOptionChoices, 1, wxRA_SPECIFY_COLS );
	m_ModeColorOption->SetSelection( 1 );
	m_ModeColorOption->SetToolTip( _("Choose if you want to draw the sheet like it appears on screen,\nor in black and white mode, better to print it when using  black and white printers") );
	
	sbOptionsSizer->Add( m_ModeColorOption, 0, wxALL|wxEXPAND, 5 );
	
	m_Print_Sheet_Ref = new wxCheckBox( this, wxID_ANY, _("Print Frame Ref"), wxDefaultPosition, wxDefaultSize, 0 );
	m_Print_Sheet_Ref->SetToolTip( _("Print (or not) the Frame references.") );
	
	sbOptionsSizer->Add( m_Print_Sheet_Ref, 0, wxALL, 5 );
	
	bUpperSizer->Add( sbOptionsSizer, 1, 0, 5 );
	
	wxBoxSizer* bButtonsSizer;
	bButtonsSizer = new wxBoxSizer( wxVERTICAL );
	
	m_buttonPlotCurrent = new wxButton( this, wxID_PRINT_CURRENT, _("Print Current"), wxDefaultPosition, wxDefaultSize, 0 );
	bButtonsSizer->Add( m_buttonPlotCurrent, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
	
	m_buttonPlotAll = new wxButton( this, wxID_PRINT_ALL, _("Print All"), wxDefaultPosition, wxDefaultSize, 0 );
	m_buttonPlotAll->SetDefault(); 
	bButtonsSizer->Add( m_buttonPlotAll, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
	
	m_buttonQuit = new wxButton( this, wxID_CANCEL, _("Quit"), wxDefaultPosition, wxDefaultSize, 0 );
	bButtonsSizer->Add( m_buttonQuit, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
	
	bUpperSizer->Add( bButtonsSizer, 0, wxALIGN_CENTER_VERTICAL, 5 );
	
	bMainSizer->Add( bUpperSizer, 0, wxEXPAND, 5 );
	
	m_staticText1 = new wxStaticText( this, wxID_ANY, _("Filename:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText1->Wrap( -1 );
	bMainSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_FileNameCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_FileNameCtrl->SetToolTip( _("Enter a filename if you do not want to use default file names\nCan be used only when printing the current sheet") );
	m_FileNameCtrl->SetMinSize( wxSize( 450,-1 ) );
	
	bMainSizer->Add( m_FileNameCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	m_staticText2 = new wxStaticText( this, wxID_ANY, _("Messages:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText2->Wrap( -1 );
	bMainSizer->Add( m_staticText2, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_MessagesBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
	m_MessagesBox->SetMinSize( wxSize( -1,80 ) );
	
	bMainSizer->Add( m_MessagesBox, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	this->SetSizer( bMainSizer );
	this->Layout();
	
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_SVG_PRINT_base::OnCloseWindow ) );
	this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_SVG_PRINT_base::OnInitDialog ) );
	m_ModeColorOption->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnSetColorModeSelected ), NULL, this );
	m_buttonPlotCurrent->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonPlotCurrentClick ), NULL, this );
	m_buttonPlotAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonPlotAllClick ), NULL, this );
	m_buttonQuit->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonCancelClick ), NULL, this );
}

DIALOG_SVG_PRINT_base::~DIALOG_SVG_PRINT_base()
{
	// Disconnect Events
	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_SVG_PRINT_base::OnCloseWindow ) );
	this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_SVG_PRINT_base::OnInitDialog ) );
	m_ModeColorOption->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnSetColorModeSelected ), NULL, this );
	m_buttonPlotCurrent->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonPlotCurrentClick ), NULL, this );
	m_buttonPlotAll->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonPlotAllClick ), NULL, this );
	m_buttonQuit->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SVG_PRINT_base::OnButtonCancelClick ), NULL, this );
	
}
Loading