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

eeschema: plot functions: code cleaning.

SVG plotter: fix issues in draw arc and draw rectangle.
parent c3ecce2e
Loading
Loading
Loading
Loading
+40 −20
Original line number Original line Diff line number Diff line
@@ -71,7 +71,7 @@
 *
 *
 *   <polygon points="0,0  50,0  25,50" style="stroke:#660000; fill:#cc3333;"/>
 *   <polygon points="0,0  50,0  25,50" style="stroke:#660000; fill:#cc3333;"/>
 *
 *
 *  The <path> element is used to draw advanced shapes combined from lines and archs,
 *  The <path> element is used to draw advanced shapes combined from lines and arcs,
 *  with or without fill.
 *  with or without fill.
 *  It is probably the most advanced and versatile SVG shape of them all.
 *  It is probably the most advanced and versatile SVG shape of them all.
 *  It is probably also the hardest element to master.
 *  It is probably also the hardest element to master.
@@ -81,6 +81,14 @@
 *            M110,110
 *            M110,110
 *            L100,0"
 *            L100,0"
 *         style="stroke:#660000; fill:none;"/>
 *         style="stroke:#660000; fill:none;"/>
 *
 *  Draw an elliptic arc: it is one of basic path command:
 * <path d="M(startx,starty) A(radiusx,radiusy)
 *          rotation-axe-x
 *          flag_arc_large,flag_sweep endx,endy">
 * flag_arc_large: 0 = small arc > 180 deg, 1 = large arc > 180 deg
 * flag_sweep : 0 = CCW, 1 = CW
 * The center of ellipse is automatically calculated.
 */
 */
#include <fctsys.h>
#include <fctsys.h>
#include <trigo.h>
#include <trigo.h>
@@ -152,7 +160,7 @@ void SVG_PLOTTER::setSVGPlotStyle()
        break;
        break;


    case FILLED_WITH_BG_BODYCOLOR:
    case FILLED_WITH_BG_BODYCOLOR:
        fputs( "fill-opacity:0.3;\n", outputFile );
        fputs( "fill-opacity:0.6;\n", outputFile );
        break;
        break;
    }
    }


@@ -246,17 +254,18 @@ void SVG_PLOTTER::SetDash( bool dashed )


void SVG_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
void SVG_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
{
{
    DPOINT  p1_dev  = userToDeviceCoordinates( p1 );
    EDA_RECT rect( p1, wxSize( p2.x -p1.x,  p2.y -p1.y ) );
    DPOINT  p2_dev  = userToDeviceCoordinates( p2 );
    rect.Normalize();
    DPOINT  pos_dev  = userToDeviceCoordinates( rect.GetOrigin() );
    DPOINT  size_dev = userToDeviceSize( rect.GetSize() );


    setFillMode( fill );
    setFillMode( fill );
    SetCurrentLineWidth( width );
    SetCurrentLineWidth( width );


    fprintf( outputFile,
    fprintf( outputFile,
             "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%d\" />\n",
             "<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n",
             (int) p1_dev.x, (int) p1_dev.y,                            // origin
             pos_dev.x, pos_dev.y, size_dev.x, size_dev.y,
             (int) (p2_dev.x - p1_dev.x), (int) (p2_dev.y - p1_dev.y),  // size
             0.0   // radius of rounded corners
             0                                                          // radius of rounded corners
             );
             );
}
}


@@ -299,18 +308,21 @@ void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad
    DPOINT  centre_dev  = userToDeviceCoordinates( centre );
    DPOINT  centre_dev  = userToDeviceCoordinates( centre );
    double  radius_dev  = userToDeviceSize( radius );
    double  radius_dev  = userToDeviceSize( radius );


    if( plotMirror )
    if( !plotMirror )
    {
    {
        int tmp = StAngle;
        int tmp = StAngle;
        StAngle     = -EndAngle;
        StAngle     = -EndAngle;
        EndAngle    = -tmp;
        EndAngle    = -tmp;
    }
    }


    DPOINT  start = centre_dev;
    DPOINT  start;
    start.x += radius_dev;
    start.x = radius_dev;
    DPOINT  end = start;
    RotatePoint( &start.x, &start.y, StAngle );
    RotatePoint( &start.x, &start.y, StAngle );
    DPOINT  end;
    end.x = radius_dev;
    RotatePoint( &end.x, &end.y, EndAngle );
    RotatePoint( &end.x, &end.y, EndAngle );
    start += centre_dev;
    end += centre_dev;


    double theta1 = StAngle * M_PI / 1800.0;
    double theta1 = StAngle * M_PI / 1800.0;


@@ -336,13 +348,11 @@ void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad
    // params are start point, radius1, radius2, X axe rotation,
    // params are start point, radius1, radius2, X axe rotation,
    // flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg),
    // flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg),
    // sweep arc ( 0 = CCW, 1 = CW),
    // sweep arc ( 0 = CCW, 1 = CW),
    // end point,
    // end point
    // center point (optional, needed to draw a pie
    fprintf( outputFile, "<path d=\"M%g %g A%g %g 0.0 %d %d %g %g \" />\n",
    fprintf( outputFile, "<path d=\"M%d %d A%d %d 0.0 %d %d %d %d \" /> \n",
             start.x, start.y, radius_dev, radius_dev,
             (int) start.x, (int) start.y,
             (int) radius_dev, (int) radius_dev,
             flg_arc, flg_sweep,
             flg_arc, flg_sweep,
             (int) end.x, (int) end.y  );
             end.x, end.y  );
}
}




@@ -355,7 +365,17 @@ void SVG_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
    setFillMode( aFill );
    setFillMode( aFill );
    SetCurrentLineWidth( aWidth );
    SetCurrentLineWidth( aWidth );


    fprintf( outputFile, "<polygon style=\"fill-rule:evenodd;\"\n" );
    switch( aFill )
    {
        case NO_FILL:
            fprintf( outputFile, "<polyline fill=\"none;\"\n" );
            break;

        case FILLED_WITH_BG_BODYCOLOR:
        case FILLED_SHAPE:
            fprintf( outputFile, "<polyline style=\"fill-rule:evenodd;\"\n" );
            break;
    }


    DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
    DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
    fprintf( outputFile, "points=\"%d,%d\n", (int) pos.x, (int) pos.y );
    fprintf( outputFile, "points=\"%d,%d\n", (int) pos.x, (int) pos.y );
@@ -380,7 +400,7 @@ void SVG_PLOTTER::PlotImage( const wxImage& aImage, const wxPoint& aPos,
    // in svg file we must insert a link to a png image file to plot an image
    // in svg file we must insert a link to a png image file to plot an image
    // the image itself is not included in the svg file.
    // the image itself is not included in the svg file.
    // So we prefer skip the image, and just draw a rectangle,
    // So we prefer skip the image, and just draw a rectangle,
    // like othe plotter which do not support images
    // like other plotters which do not support images


    PLOTTER::PlotImage( aImage, aPos, aScaleFactor );
    PLOTTER::PlotImage( aImage, aPos, aScaleFactor );


+21 −52
Original line number Original line Diff line number Diff line
@@ -4,7 +4,7 @@
/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 1992-2012 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
 * Copyright (C) 1992-2012 Jean-Pierre Charras <jp.charras at wanadoo.fr
 * Copyright (C) 1992-2010 Lorenzo Marcantonio
 * Copyright (C) 1992-2010 Lorenzo Marcantonio
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 *
 *
@@ -42,13 +42,12 @@
#define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
#define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
#define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
#define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
#define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
#define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
#define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )






// static members (static to remember last state):
// static members (static to remember last state):
int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO;
int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO;
int DIALOG_PLOT_SCHEMATIC::m_HPGLPaperSizeSelect = 0;



void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
{
{
@@ -64,7 +63,6 @@ DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) :
    m_parent = parent;
    m_parent = parent;
    m_config   = wxGetApp().GetSettings();
    m_config   = wxGetApp().GetSettings();


    m_select_PlotAll = false;
    initDlg();
    initDlg();


    GetSizer()->SetSizeHints( this );
    GetSizer()->SetSizeHints( this );
@@ -94,6 +92,9 @@ void DIALOG_PLOT_SCHEMATIC::initDlg()
    m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
    m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
    SetPlotOriginCenter( tmp );
    SetPlotOriginCenter( tmp );


    m_config->Read( PLOT_HPGL_PAPERSIZE_KEY, &m_HPGLPaperSizeSelect, 0 );
    m_HPGLPaperSizeOption->SetSelection( m_HPGLPaperSizeSelect );

    // Switch to the last save plot format
    // Switch to the last save plot format
    long plotfmt;
    long plotfmt;
    m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
    m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
@@ -164,6 +165,7 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
    m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
    m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
    m_config->Write( PLOT_HPGL_ORIGIN_KEY, GetPlotOriginCenter() );
    m_config->Write( PLOT_HPGL_ORIGIN_KEY, GetPlotOriginCenter() );
    m_HPGLPaperSizeSelect = m_HPGLPaperSizeOption->GetSelection();
    m_HPGLPaperSizeSelect = m_HPGLPaperSizeOption->GetSelection();
    m_config->Write( PLOT_HPGL_PAPERSIZE_KEY, m_HPGLPaperSizeSelect );


    m_pageSizeSelect    = m_PaperSizeOption->GetSelection();
    m_pageSizeSelect    = m_PaperSizeOption->GetSelection();
    g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DefaultLineSizeCtrl );
    g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DefaultLineSizeCtrl );
@@ -175,37 +177,38 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
{
{


    switch( m_plotFormatOpt->GetSelection() )
    switch( GetPlotFileFormat() )
    {
    {
        case 0:     // postscript
        default:
        case PLOT_FORMAT_POST:
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Show( m_PaperSizeOption );
            m_paperOptionsSizer->Show( m_PaperSizeOption );
            m_PaperSizeOption->Enable( true );
            m_PaperSizeOption->Enable( true );
            m_DefaultLineSizeCtrl->Enable( true );
            m_DefaultLineSizeCtrl->Enable( true );
            break;
            break;


        case 1:     // PDF
        case PLOT_FORMAT_PDF:
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_PaperSizeOption->Enable( true );
            m_PaperSizeOption->Enable( true );
            m_DefaultLineSizeCtrl->Enable( true );
            m_DefaultLineSizeCtrl->Enable( true );
            break;
            break;


        case 2:     // SVG
        case PLOT_FORMAT_SVG:
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_PaperSizeOption->Enable( false );
            m_PaperSizeOption->Enable( false );
            m_DefaultLineSizeCtrl->Enable( true );
            m_DefaultLineSizeCtrl->Enable( true );
           break;
           break;


        case 3:     // DXF
        case PLOT_FORMAT_DXF:
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Hide( m_paperHPGLSizer );
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_paperOptionsSizer->Show(m_PaperSizeOption);
            m_PaperSizeOption->Enable( false );
            m_PaperSizeOption->Enable( false );
            m_DefaultLineSizeCtrl->Enable( false );
            m_DefaultLineSizeCtrl->Enable( false );
            break;
            break;


        case 4:     //HPGL
        case PLOT_FORMAT_HPGL:
            m_paperOptionsSizer->Show( m_paperHPGLSizer );
            m_paperOptionsSizer->Show( m_paperHPGLSizer );
            m_paperOptionsSizer->Hide(m_PaperSizeOption);
            m_paperOptionsSizer->Hide(m_PaperSizeOption);
            m_DefaultLineSizeCtrl->Enable( false );
            m_DefaultLineSizeCtrl->Enable( false );
@@ -217,75 +220,41 @@ void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
}
}




void DIALOG_PLOT_SCHEMATIC::setupPlotPage( PLOTTER * plotter, SCH_SCREEN* screen )
{
    PAGE_INFO   plotPage;                               // page size selected to plot
    // Considerations on page size and scaling requests
    PAGE_INFO   actualPage = screen->GetPageSettings(); // page size selected in schematic

    switch( m_pageSizeSelect )
    {
    case PAGE_SIZE_A:
        plotPage.SetType( wxT( "A" ) );
        plotPage.SetPortrait( actualPage.IsPortrait() );
        break;

    case PAGE_SIZE_A4:
        plotPage.SetType( wxT( "A4" ) );
        plotPage.SetPortrait( actualPage.IsPortrait() );
        break;

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

    double  scalex  = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
    double  scaley  = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
    double  scale   = MIN( scalex, scaley );
    plotter->SetPageSettings( plotPage );
    plotter->SetViewport( wxPoint( 0, 0 ), IU_PER_DECIMILS, scale, false );
}


void DIALOG_PLOT_SCHEMATIC::OnButtonPlotCurrentClick( wxCommandEvent& event )
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotCurrentClick( wxCommandEvent& event )
{
{
    m_select_PlotAll = false;
    PlotSchematic( true );
    PlotSchematic();
}
}




void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
{
{
    m_select_PlotAll = true;
    PlotSchematic( false );
    PlotSchematic();
}
}


void DIALOG_PLOT_SCHEMATIC::PlotSchematic()
void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll )
{
{
    getPlotOptions();
    getPlotOptions();
    switch( GetPlotFileFormat() )
    switch( GetPlotFileFormat() )
    {
    {
        case PLOT_FORMAT_HPGL:
        case PLOT_FORMAT_HPGL:
            createHPGLFile( m_select_PlotAll );
            createHPGLFile( aPlotAll, getPlotFrameRef() );
            break;
            break;


        default:
        default:
        case PLOT_FORMAT_POST:
        case PLOT_FORMAT_POST:
            createPSFile();
            createPSFile( aPlotAll, getPlotFrameRef() );
            break;
            break;


        case PLOT_FORMAT_DXF:
        case PLOT_FORMAT_DXF:
            CreateDXFFile();
            CreateDXFFile( aPlotAll, getPlotFrameRef() );
            break;
            break;


        case PLOT_FORMAT_PDF:
        case PLOT_FORMAT_PDF:
            createPDFFile();
            createPDFFile( aPlotAll, getPlotFrameRef() );
            break;
            break;


        case PLOT_FORMAT_SVG:
        case PLOT_FORMAT_SVG:
            createSVGFile( m_select_PlotAll, getPlotFrameRef() );
            createSVGFile( aPlotAll, getPlotFrameRef() );
            break;
            break;
    }
    }
    m_MessagesBox->AppendText( wxT( "****\n" ) );
    m_MessagesBox->AppendText( wxT( "****\n" ) );
+23 −23
Original line number Original line Diff line number Diff line
@@ -50,8 +50,7 @@ private:
    static int      m_pageSizeSelect;       // Static to keep last option for some format:
    static int      m_pageSizeSelect;       // Static to keep last option for some format:
                                            // Static to keep last option:
                                            // Static to keep last option:
                                            // use default size or force A or A4 size
                                            // use default size or force A or A4 size
    static int      m_HPGLPaperSizeSelect;  // for HPGL format only: last selected paper size
    int             m_HPGLPaperSizeSelect;  // for HPGL format only: last selected paper size
    bool            m_select_PlotAll;       // Flaf to plot current page or the full hierarchy


public:
public:
    // / Constructors
    // / Constructors
@@ -67,6 +66,7 @@ private:


    // common
    // common
    void getPlotOptions();
    void getPlotOptions();

    bool getModeColor()
    bool getModeColor()
    { return m_ModeColorOption->GetSelection() == 0; }
    { return m_ModeColorOption->GetSelection() == 0; }


@@ -78,18 +78,17 @@ private:
    bool getPlotFrameRef() { return m_PlotFrameRefOpt->GetValue(); }
    bool getPlotFrameRef() { return m_PlotFrameRefOpt->GetValue(); }
    void setPlotFrameRef( bool aPlot) {m_PlotFrameRefOpt->SetValue( aPlot ); }
    void setPlotFrameRef( bool aPlot) {m_PlotFrameRefOpt->SetValue( aPlot ); }


    void setupPlotPage( PLOTTER* plotter, SCH_SCREEN* screen );
    void PlotSchematic( bool aPlotAll );

    void PlotSchematic();


    // PDF
    // PDF
    void    createPDFFile();
    void    createPDFFile( bool aPlotAll, bool aPlotFrameRef );
    void    plotOneSheetPDF( PLOTTER* plotter, SCH_SCREEN* screen);
    void    plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotFrameRef);
    void    setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen );


    // DXF
    // DXF
    void    CreateDXFFile();
    void    CreateDXFFile( bool aPlotAll, bool aPlotFrameRef );
    void    PlotOneSheetDXF( const wxString& FileName, SCH_SCREEN* screen,
    bool    PlotOneSheetDXF( const wxString& aFileName, SCH_SCREEN* aScreen,
                             wxPoint plot_offset, double scale );
                             wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );


    // HPGL
    // HPGL
    bool    GetPlotOriginCenter()
    bool    GetPlotOriginCenter()
@@ -100,24 +99,25 @@ private:
    {
    {
        m_plotOriginOpt->SetSelection( aCenter ? 1 : 0 );
        m_plotOriginOpt->SetSelection( aCenter ? 1 : 0 );
    }
    }
    void    createHPGLFile( bool aPlotAll );
    void    createHPGLFile( bool aPlotAll, bool aPlotFrameRef );
    void    SetHPGLPenWidth();
    void    SetHPGLPenWidth();
    void    Plot_1_Page_HPGL( const wxString& FileName, SCH_SCREEN* screen,
    bool    Plot_1_Page_HPGL( const wxString& aFileName, SCH_SCREEN* aScreen,
                              const PAGE_INFO& pageInfo,
                              const PAGE_INFO& aPageInfo,
                              wxPoint& offset, double plot_scale );
                              wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );


    // PS
    // PS
    void    createPSFile();
    void    createPSFile( bool aPlotAll, bool aPlotFrameRef );
    void    plotOneSheetPS( const wxString& FileName, SCH_SCREEN* screen,
    bool    plotOneSheetPS( const wxString& aFileName, SCH_SCREEN* aScreen,
                            const PAGE_INFO& pageInfo,
                            const PAGE_INFO& aPageInfo,
                            wxPoint plot_offset, double scale );
                            wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef );


    // SVG
    // SVG
    void    createSVGFile( bool aPrintAll, bool aPrint_Sheet_Ref );
    void    createSVGFile( bool aPlotAll, bool aPlotFrameRef );

public:
public:
    // This function is static because it is called by libedit
    // This function is static because it is called by libedit
    // outside a dialog.
    // outside a dialog. This is the reason we need aFrame as parameter
    static bool plotOneSheetSVG( EDA_DRAW_FRAME* frame, const wxString& FullFileName,
    static bool plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, const wxString& aFileName,
                                 SCH_SCREEN* screen,
                                 SCH_SCREEN* aScreen,
                                 bool aPrintBlackAndWhite, bool aPrint_Sheet_Ref );
                                 bool aPlotBlackAndWhite, bool aPlotFrameRef );
};
};
+28 −33
Original line number Original line Diff line number Diff line
@@ -34,14 +34,13 @@
#include <dialog_plot_schematic.h>
#include <dialog_plot_schematic.h>




void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
{
{
    SCH_EDIT_FRAME* schframe  = (SCH_EDIT_FRAME*) m_parent;
    SCH_EDIT_FRAME* schframe  = (SCH_EDIT_FRAME*) m_parent;
    SCH_SCREEN*     screen    = schframe->GetScreen();
    SCH_SCREEN*     screen    = schframe->GetScreen();
    SCH_SHEET_PATH* sheetpath;
    SCH_SHEET_PATH* sheetpath;
    SCH_SHEET_PATH  oldsheetpath = schframe->GetCurrentSheet();
    SCH_SHEET_PATH  oldsheetpath = schframe->GetCurrentSheet();
    wxString        plotFileName;
    wxString        plotFileName;
    wxPoint         plot_offset;


    /* When printing all pages, the printed page is not the current page.
    /* When printing all pages, the printed page is not the current page.
     *  In complex hierarchies, we must setup references and others parameters
     *  In complex hierarchies, we must setup references and others parameters
@@ -56,7 +55,7 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )


    while( true )
    while( true )
    {
    {
        if( m_select_PlotAll )
        if( aPlotAll )
        {
        {
            if( sheetpath == NULL )
            if( sheetpath == NULL )
                break;
                break;
@@ -78,15 +77,21 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
            sheetpath = SheetList.GetNext();
            sheetpath = SheetList.GetNext();
        }
        }


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

        plotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT(".")
        plotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT(".")
                       + DXF_PLOTTER::GetDefaultFileExtension();
                       + DXF_PLOTTER::GetDefaultFileExtension();


        PlotOneSheetDXF( plotFileName, screen, plot_offset, 1 );
        wxString msg;

        if( PlotOneSheetDXF( plotFileName, screen, plot_offset, 1.0, aPlotFrameRef ) )
            msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
        else    // Error
             msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );


        if( !m_select_PlotAll )
        m_MessagesBox->AppendText( msg );


        if( !aPlotAll )
            break;
            break;
    }
    }


@@ -96,56 +101,46 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( )
}
}




void DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString&    FileName,
bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString&    aFileName,
                                                 SCH_SCREEN*        screen,
                                             SCH_SCREEN*        aScreen,
                                                 wxPoint            plot_offset,
                                             wxPoint            aPlotOffset,
                                                 double             scale )
                                             double             aScale,
                                             bool aPlotFrameRef )
{
{

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

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


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

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


    LOCALE_IO   toggle;
    LOCALE_IO   toggle;


    DXF_PLOTTER* plotter = new DXF_PLOTTER();
    DXF_PLOTTER* plotter = new DXF_PLOTTER();


    const PAGE_INFO&   pageInfo = screen->GetPageSettings();
    const PAGE_INFO&   pageInfo = aScreen->GetPageSettings();
    plotter->SetPageSettings( pageInfo );
    plotter->SetPageSettings( pageInfo );
    plotter->SetColorMode( getModeColor() );
    plotter->SetColorMode( getModeColor() );
    plotter->SetViewport( plot_offset, IU_PER_DECIMILS, scale, false );
    plotter->SetViewport( aPlotOffset, IU_PER_DECIMILS, aScale, false );


    // Init :
    // Init :
    plotter->SetCreator( wxT( "Eeschema-DXF" ) );
    plotter->SetCreator( wxT( "Eeschema-DXF" ) );
    plotter->SetFilename( FileName );
    plotter->SetFilename( aFileName );
    plotter->StartPlot( output_file );
    plotter->StartPlot( output_file );


    if( getPlotFrameRef() )
    if( aPlotFrameRef )
    {
    {
        plotter->SetColor( BLACK );
        plotter->SetColor( BLACK );
        PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
        PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
                       m_parent->GetPageSettings(),
                       m_parent->GetPageSettings(),
                       screen->m_ScreenNumber, screen->m_NumberOfScreens,
                       aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
                       m_parent->GetScreenDesc(),
                       m_parent->GetScreenDesc(),
                       screen->GetFileName() );
                       aScreen->GetFileName() );
    }
    }


    screen->Plot( plotter );
    aScreen->Plot( plotter );


    // finish
    // finish
    plotter->EndPlot();
    plotter->EndPlot();
    delete plotter;
    delete plotter;


    m_MessagesBox->AppendText( wxT( "Ok\n" ) );
    return true;
}
}
+24 −26
Original line number Original line Diff line number Diff line
@@ -108,7 +108,7 @@ void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
}
}




void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
{
{
    wxString        plotFileName;
    wxString        plotFileName;
    SCH_SCREEN*     screen = m_parent->GetScreen();
    SCH_SCREEN*     screen = m_parent->GetScreen();
@@ -179,7 +179,14 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )


        LOCALE_IO toggle;
        LOCALE_IO toggle;


        Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset, plot_scale );
        wxString msg;
        if( Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset,
                              plot_scale, aPlotFrameRef ) )
            msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) );
        else    // Error
             msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) );

        m_MessagesBox->AppendText( msg );


        if( !aPlotAll )
        if( !aPlotAll )
            break;
            break;
@@ -191,37 +198,28 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll )
}
}




void DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString&   FileName,
bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString&   aFileName,
                                              SCH_SCREEN*       screen,
                                              SCH_SCREEN*       aScreen,
                                              const PAGE_INFO&  pageInfo,
                                              const PAGE_INFO&  aPageInfo,
                                              wxPoint&          offset,
                                              wxPoint           aPlot0ffset,
                                              double            plot_scale )
                                              double            aScale,
                                              bool              aPlotFrameRef )
{
{
    wxString    msg;
    FILE*       output_file = wxFopen( aFileName, wxT( "wt" ) );

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


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


    LOCALE_IO toggle;
    LOCALE_IO toggle;


    msg.Printf( _( "Plot: %s " ), FileName.GetData() );
    m_MessagesBox->AppendText( msg );

    HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
    HPGL_PLOTTER* plotter = new HPGL_PLOTTER();


    plotter->SetPageSettings( pageInfo );
    plotter->SetPageSettings( aPageInfo );
    plotter->SetViewport( offset, IU_PER_DECIMILS, plot_scale, false );
    plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, aScale, false );


    // Init :
    // Init :
    plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
    plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
    plotter->SetFilename( FileName );
    plotter->SetFilename( aFileName );
    plotter->SetPenSpeed( g_HPGL_Pen_Descr.m_Pen_Speed );
    plotter->SetPenSpeed( g_HPGL_Pen_Descr.m_Pen_Speed );
    plotter->SetPenNumber( g_HPGL_Pen_Descr.m_Pen_Num );
    plotter->SetPenNumber( g_HPGL_Pen_Descr.m_Pen_Num );
    plotter->SetPenDiameter( g_HPGL_Pen_Descr.m_Pen_Diam );
    plotter->SetPenDiameter( g_HPGL_Pen_Descr.m_Pen_Diam );
@@ -233,14 +231,14 @@ void DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& FileName,
    if( getPlotFrameRef() )
    if( getPlotFrameRef() )
        PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
        PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
                       m_parent->GetPageSettings(),
                       m_parent->GetPageSettings(),
                       screen->m_ScreenNumber, screen->m_NumberOfScreens,
                       aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
                       m_parent->GetScreenDesc(),
                       m_parent->GetScreenDesc(),
                       screen->GetFileName() );
                       aScreen->GetFileName() );


    screen->Plot( plotter );
    aScreen->Plot( plotter );


    plotter->EndPlot();
    plotter->EndPlot();
    delete plotter;
    delete plotter;


    m_MessagesBox->AppendText( wxT( "Ok\n" ) );
    return true;
}
}
Loading