Adds plot functionality to Eeschema line formats

Dotted, dashed and dash-dot lines are provided in
HPGL, PDF, PS and SVG plot outputs along with line
width and color formatting.

DXF format does not currently provide any dashed
line functionality

A bug in HPGL plotted is corrected.  Previous HPGL
dashed line commands were incorrect, plotting all
lines as solid.
This commit is contained in:
Seth Hillbrand 2017-11-12 19:53:27 -08:00 committed by jean-pierre charras
parent b576189a00
commit 7c0a7f9f7b
10 changed files with 143 additions and 77 deletions

View File

@ -63,8 +63,9 @@ PLOTTER::PLOTTER( )
// Temporary init to avoid not initialized vars, will be set later // Temporary init to avoid not initialized vars, will be set later
m_IUsPerDecimil = 1; // will be set later to the actual value m_IUsPerDecimil = 1; // will be set later to the actual value
iuPerDeviceUnit = 1; // will be set later to the actual value iuPerDeviceUnit = 1; // will be set later to the actual value
m_dashMarkLength_mm = 0.5; // Dashed line parameter in mm: segment m_dotMarkLength_mm = 0.1; // Dotted line parameter in mm: segment
m_dashGapLength_mm = 0.25; // Dashed line parameter in mm: gap // Dashed line parameter is 5 * dotted line mark
// Dashed line gap is 3 * dotted line mark
} }
PLOTTER::~PLOTTER() PLOTTER::~PLOTTER()
@ -131,16 +132,22 @@ double PLOTTER::userToDeviceSize( double size ) const
} }
double PLOTTER::GetDotMarkLenIU() const
{
return userToDeviceSize( std::max( 1.0,
m_dotMarkLength_mm * 10000 / 25.4 * m_IUsPerDecimil - GetCurrentLineWidth() ) );
}
double PLOTTER::GetDashMarkLenIU() const double PLOTTER::GetDashMarkLenIU() const
{ {
double mark = userToDeviceSize( m_dashMarkLength_mm*10000/25.4*m_IUsPerDecimil - GetCurrentLineWidth() ); return std::max( GetDashGapLenIU(), 5.0 * GetDotMarkLenIU() );
return ( mark < 0.0 ) ? 0.0 : mark;
} }
double PLOTTER::GetDashGapLenIU() const double PLOTTER::GetDashGapLenIU() const
{ {
return userToDeviceSize( m_dashGapLength_mm*10000/25.4*m_IUsPerDecimil + GetCurrentLineWidth() ); return 3.0 * GetDotMarkLenIU() + userToDeviceSize( 2 * GetCurrentLineWidth() );
} }
void PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius, void PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,

View File

@ -496,7 +496,7 @@ void DXF_PLOTTER::PenTo( const wxPoint& pos, char plume )
/** /**
* Dashed lines are not (yet) supported by DXF_PLOTTER * Dashed lines are not (yet) supported by DXF_PLOTTER
*/ */
void DXF_PLOTTER::SetDash( bool dashed ) void DXF_PLOTTER::SetDash( int dashed )
{ {
// NOP for now // NOP for now
} }

View File

@ -420,14 +420,24 @@ void HPGL_PLOTTER::PenTo( const wxPoint& pos, char plume )
/** /**
* HPGL supports dashed lines * HPGL supports dashed lines
*/ */
void HPGL_PLOTTER::SetDash( bool dashed ) void HPGL_PLOTTER::SetDash( int dashed )
{ {
wxASSERT( outputFile ); wxASSERT( outputFile );
if( dashed ) switch( dashed )
fputs( "LI 2;\n", outputFile ); {
else case PLOTDASHTYPE_DASH:
fputs( "LI;\n", outputFile ); fprintf( outputFile, "LT -2 4 1;\n" );
break;
case PLOTDASHTYPE_DOT:
fprintf( outputFile, "LT -1 2 1;\n" );
break;
case PLOTDASHTYPE_DASHDOT:
fprintf( outputFile, "LT -4 6 1;\n" );
break;
default:
fputs( "LT;\n", outputFile );
}
} }

View File

@ -131,14 +131,27 @@ void PDF_PLOTTER::emitSetRGBColor( double r, double g, double b )
/** /**
* PDF supports dashed lines * PDF supports dashed lines
*/ */
void PDF_PLOTTER::SetDash( bool dashed ) void PDF_PLOTTER::SetDash( int dashed )
{ {
wxASSERT( workFile ); wxASSERT( workFile );
if( dashed ) switch( dashed )
{
case PLOTDASHTYPE_DASH:
fprintf( workFile, "[%d %d] 0 d\n", fprintf( workFile, "[%d %d] 0 d\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU() ); (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
else break;
case PLOTDASHTYPE_DOT:
fprintf( workFile, "[%d %d] 0 d\n",
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
break;
case PLOTDASHTYPE_DASHDOT:
fprintf( workFile, "[%d %d %d %d] 0 d\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
break;
default:
fputs( "[] 0 d\n", workFile ); fputs( "[] 0 d\n", workFile );
}
} }

View File

@ -545,14 +545,26 @@ void PS_PLOTTER::emitSetRGBColor( double r, double g, double b )
/** /**
* Postscript supports dashed lines * Postscript supports dashed lines
*/ */
void PS_PLOTTER::SetDash( bool dashed ) void PS_PLOTTER::SetDash( int dashed )
{ {
wxASSERT( outputFile ); switch( dashed )
if( dashed ) {
case PLOTDASHTYPE_DASH:
fprintf( outputFile, "[%d %d] 0 setdash\n", fprintf( outputFile, "[%d %d] 0 setdash\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU() ); (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
else break;
case PLOTDASHTYPE_DOT:
fprintf( outputFile, "[%d %d] 0 setdash\n",
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
break;
case PLOTDASHTYPE_DASHDOT:
fprintf( outputFile, "[%d %d %d %d] 0 setdash\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
break;
default:
fputs( "solidline\n", outputFile ); fputs( "solidline\n", outputFile );
}
} }

View File

@ -233,9 +233,21 @@ void SVG_PLOTTER::setSVGPlotStyle()
m_pen_rgb_color, pen_w ); m_pen_rgb_color, pen_w );
fputs( "stroke-linecap:round; stroke-linejoin:round;", outputFile ); fputs( "stroke-linecap:round; stroke-linejoin:round;", outputFile );
if( m_dashed ) switch( m_dashed )
{
case PLOTDASHTYPE_DASH:
fprintf( outputFile, "stroke-dasharray:%g,%g;", fprintf( outputFile, "stroke-dasharray:%g,%g;",
GetDashMarkLenIU(), GetDashGapLenIU() ); GetDashMarkLenIU(), GetDashGapLenIU() );
break;
case PLOTDASHTYPE_DOT:
fprintf( outputFile, "stroke-dasharray:%g,%g;",
GetDotMarkLenIU(), GetDashGapLenIU() );
break;
case PLOTDASHTYPE_DASHDOT:
fprintf( outputFile, "stroke-dasharray:%g,%g,%g,%g;",
GetDashMarkLenIU(), GetDashGapLenIU(), GetDotMarkLenIU(), GetDashGapLenIU() );
break;
}
fputs( "\">\n", outputFile ); fputs( "\">\n", outputFile );
@ -289,7 +301,7 @@ void SVG_PLOTTER::emitSetRGBColor( double r, double g, double b )
/** /**
* SVG supports dashed lines * SVG supports dashed lines
*/ */
void SVG_PLOTTER::SetDash( bool dashed ) void SVG_PLOTTER::SetDash( int dashed )
{ {
if( m_dashed != dashed ) if( m_dashed != dashed )
{ {

View File

@ -22,6 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <cassert>
#include <dialog_edit_line_style.h> #include <dialog_edit_line_style.h>
@ -29,6 +30,7 @@ DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( wxWindow* parent ) :
DIALOG_EDIT_LINE_STYLE_BASE( parent ) DIALOG_EDIT_LINE_STYLE_BASE( parent )
{ {
m_sdbSizer1Apply->SetLabel( _( "Default" ) ); m_sdbSizer1Apply->SetLabel( _( "Default" ) );
m_lineStyle->SetSelection( 0 ); m_lineStyle->SetSelection( 0 );
m_lineWidth->SetFocus(); m_lineWidth->SetFocus();
@ -57,39 +59,24 @@ void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event )
void DIALOG_EDIT_LINE_STYLE::SetColor( const COLOR4D& aColor ) void DIALOG_EDIT_LINE_STYLE::SetColor( const COLOR4D& aColor )
{ {
assert( aColor.r >= 0.0 && aColor.r <= 1.0 );
assert( aColor.g >= 0.0 && aColor.g <= 1.0 );
assert( aColor.b >= 0.0 && aColor.b <= 1.0 );
assert( aColor.a >= 0.0 && aColor.a <= 1.0 );
m_colorPicker->SetColour( aColor.ToColour() ); m_colorPicker->SetColour( aColor.ToColour() );
} }
void DIALOG_EDIT_LINE_STYLE::SetStyle( const int aStyle ) void DIALOG_EDIT_LINE_STYLE::SetStyle( const int aStyle )
{ {
switch( aStyle ) assert( aStyle >= 0 && aStyle < 4 );
{
case wxPENSTYLE_SHORT_DASH: m_lineStyle->SetSelection( aStyle );
m_lineStyle->SetSelection( 1 );
break;
case wxPENSTYLE_DOT:
m_lineStyle->SetSelection( 2 );
break;
case wxPENSTYLE_DOT_DASH:
m_lineStyle->SetSelection( 3 );
break;
default:
m_lineStyle->SetSelection( 0 );
break;
}
} }
int DIALOG_EDIT_LINE_STYLE::GetStyle() int DIALOG_EDIT_LINE_STYLE::GetStyle()
{ {
const int retval[4] = return m_lineStyle->GetSelection();
{
wxPENSTYLE_SOLID,
wxPENSTYLE_SHORT_DASH,
wxPENSTYLE_DOT,
wxPENSTYLE_DOT_DASH,
};
return retval[ m_lineStyle->GetSelection() ];
} }

View File

@ -42,6 +42,15 @@
#include <dialogs/dialog_edit_line_style.h> #include <dialogs/dialog_edit_line_style.h>
const enum wxPenStyle SCH_LINE::PenStyle[] =
{
[PLOTDASHTYPE_SOLID] = wxPENSTYLE_SOLID,
[PLOTDASHTYPE_DASH] = wxPENSTYLE_SHORT_DASH,
[PLOTDASHTYPE_DOT] = wxPENSTYLE_DOT,
[PLOTDASHTYPE_DASHDOT] = wxPENSTYLE_DOT_DASH
};
SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
SCH_ITEM( NULL, SCH_LINE_T ) SCH_ITEM( NULL, SCH_LINE_T )
{ {
@ -49,7 +58,7 @@ SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
m_end = pos; m_end = pos;
m_startIsDangling = m_endIsDangling = false; m_startIsDangling = m_endIsDangling = false;
m_size = 0; m_size = 0;
m_style = 0; m_style = -1;
m_color = COLOR4D::UNSPECIFIED; m_color = COLOR4D::UNSPECIFIED;
switch( layer ) switch( layer )
@ -243,34 +252,30 @@ COLOR4D SCH_LINE::GetLineColor() const
return m_color; return m_color;
} }
int SCH_LINE::GetDefaultStyle() const
enum wxPenStyle SCH_LINE::GetDefaultStyle() const
{ {
if( m_Layer == LAYER_NOTES ) if( m_Layer == LAYER_NOTES )
return wxPENSTYLE_SHORT_DASH; return PLOTDASHTYPE_DASH;
return wxPENSTYLE_SOLID; return PLOTDASHTYPE_SOLID;
} }
void SCH_LINE::SetLineStyle( const int aStyle ) void SCH_LINE::SetLineStyle( const int aStyle )
{ {
if( aStyle == GetDefaultStyle() ) if( aStyle == GetDefaultStyle() )
m_style = 0; m_style = -1;
else else
m_style = aStyle; m_style = aStyle;
} }
enum wxPenStyle SCH_LINE::GetLineStyle() const int SCH_LINE::GetLineStyle() const
{ {
if( m_style > 0 ) if( m_style >= 0 )
return (enum wxPenStyle) m_style; return m_style;
if( m_Layer == LAYER_NOTES ) return GetDefaultStyle();
return wxPENSTYLE_SHORT_DASH;
return wxPENSTYLE_SOLID;
} }
@ -328,7 +333,8 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
if( ( m_Flags & ENDPOINT ) == 0 ) if( ( m_Flags & ENDPOINT ) == 0 )
end += offset; end += offset;
GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color, GetLineStyle() ); GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color,
PenStyle[ GetLineStyle() ] );
if( m_startIsDangling ) if( m_startIsDangling )
DrawDanglingSymbol( panel, DC, start, color ); DrawDanglingSymbol( panel, DC, start, color );
@ -685,17 +691,19 @@ bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const
void SCH_LINE::Plot( PLOTTER* aPlotter ) void SCH_LINE::Plot( PLOTTER* aPlotter )
{ {
if( m_color != COLOR4D::UNSPECIFIED )
aPlotter->SetColor( m_color );
else
aPlotter->SetColor( GetLayerColor( GetLayer() ) ); aPlotter->SetColor( GetLayerColor( GetLayer() ) );
aPlotter->SetCurrentLineWidth( GetPenSize() ); aPlotter->SetCurrentLineWidth( GetPenSize() );
if( m_Layer == LAYER_NOTES ) aPlotter->SetDash( GetLineStyle() );
aPlotter->SetDash( true );
aPlotter->MoveTo( m_start ); aPlotter->MoveTo( m_start );
aPlotter->FinishTo( m_end ); aPlotter->FinishTo( m_end );
if( m_Layer == LAYER_NOTES ) aPlotter->SetDash( 0 );
aPlotter->SetDash( false );
} }

View File

@ -50,6 +50,9 @@ class SCH_LINE : public SCH_ITEM
COLOR4D m_color; ///< Line color COLOR4D m_color; ///< Line color
public: public:
static const enum wxPenStyle PenStyle[];
SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES ); SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
SCH_LINE( const SCH_LINE& aLine ); SCH_LINE( const SCH_LINE& aLine );
@ -79,11 +82,11 @@ public:
void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; } void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
enum wxPenStyle GetDefaultStyle() const; int GetDefaultStyle() const;
void SetLineStyle( const int aStyle ); void SetLineStyle( const int aStyle );
enum wxPenStyle GetLineStyle() const; int GetLineStyle() const;
void SetLineColor( const COLOR4D aColor ); void SetLineColor( const COLOR4D aColor );

View File

@ -76,6 +76,16 @@ enum PlotTextMode {
PLOTTEXTMODE_DEFAULT PLOTTEXTMODE_DEFAULT
}; };
/**
* Enum for choosing dashed line type
*/
enum PlotDashType {
PLOTDASHTYPE_SOLID,
PLOTDASHTYPE_DASH,
PLOTDASHTYPE_DOT,
PLOTDASHTYPE_DASHDOT,
PLOTDASHTYPE_COUNT,
};
/** /**
* Base plotter engine class. General rule: all the interface with the caller * Base plotter engine class. General rule: all the interface with the caller
@ -86,8 +96,7 @@ enum PlotTextMode {
class PLOTTER class PLOTTER
{ {
private: private:
double m_dashMarkLength_mm ; ///< Dashed line parameter in mm: segment double m_dotMarkLength_mm ; ///< Dotted line parameter in mm: segment
double m_dashGapLength_mm; ///< Dashed line parameter in mm: gap
public: public:
// These values are used as flag for pen or aperture selection // These values are used as flag for pen or aperture selection
@ -146,7 +155,7 @@ public:
virtual void SetColor( COLOR4D color ) = 0; virtual void SetColor( COLOR4D color ) = 0;
virtual void SetDash( bool dashed ) = 0; virtual void SetDash( int dashed ) = 0;
virtual void SetCreator( const wxString& aCreator ) virtual void SetCreator( const wxString& aCreator )
{ {
@ -501,6 +510,8 @@ protected:
*/ */
virtual double userToDeviceSize( double size ) const; virtual double userToDeviceSize( double size ) const;
double GetDotMarkLenIU() const;
double GetDashMarkLenIU() const; double GetDashMarkLenIU() const;
double GetDashGapLenIU() const; double GetDashGapLenIU() const;
@ -576,7 +587,7 @@ public:
} }
virtual void SetDefaultLineWidth( int width ) override {} virtual void SetDefaultLineWidth( int width ) override {}
virtual void SetDash( bool dashed ) override; virtual void SetDash( int dashed ) override;
virtual void SetColor( COLOR4D color ) override {} virtual void SetColor( COLOR4D color ) override {}
@ -751,7 +762,7 @@ public:
virtual bool StartPlot() override; virtual bool StartPlot() override;
virtual bool EndPlot() override; virtual bool EndPlot() override;
virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
virtual void SetDash( bool dashed ) override; virtual void SetDash( int dashed ) override;
virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
double aScale, bool aMirror ) override; double aScale, bool aMirror ) override;
@ -821,7 +832,7 @@ public:
virtual void StartPage(); virtual void StartPage();
virtual void ClosePage(); virtual void ClosePage();
virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
virtual void SetDash( bool dashed ) override; virtual void SetDash( int dashed ) override;
/** PDF can have multiple pages, so SetPageSettings can be called /** PDF can have multiple pages, so SetPageSettings can be called
* with the outputFile open (but not inside a page stream!) */ * with the outputFile open (but not inside a page stream!) */
@ -894,7 +905,7 @@ public:
virtual bool StartPlot() override; virtual bool StartPlot() override;
virtual bool EndPlot() override; virtual bool EndPlot() override;
virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
virtual void SetDash( bool dashed ) override; virtual void SetDash( int dashed ) override;
virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
double aScale, bool aMirror ) override; double aScale, bool aMirror ) override;
@ -938,7 +949,10 @@ protected:
bool m_graphics_changed; // true if a pen/brush parameter is modified bool m_graphics_changed; // true if a pen/brush parameter is modified
// color, pen size, fil mode ... // color, pen size, fil mode ...
// the new SVG stype must be output on file // the new SVG stype must be output on file
bool m_dashed; // true to use plot dashed line style int m_dashed; // 0 = plot solid line style
// 1 = plot dashed line style
// 2 = plot dotted line style
// 3 = plot dash-dot line style
/** /**
* function emitSetRGBColor() * function emitSetRGBColor()
@ -1008,7 +1022,7 @@ public:
virtual void SetDefaultLineWidth( int width ) override; virtual void SetDefaultLineWidth( int width ) override;
// RS274X has no dashing, nor colours // RS274X has no dashing, nor colours
virtual void SetDash( bool dashed ) override {} virtual void SetDash( int dashed ) override {}
virtual void SetColor( COLOR4D color ) override {} virtual void SetColor( COLOR4D color ) override {}
// Currently, aScale and aMirror are not used in gerber plotter // Currently, aScale and aMirror are not used in gerber plotter
virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
@ -1246,7 +1260,7 @@ public:
defaultPenWidth = 0; defaultPenWidth = 0;
} }
virtual void SetDash( bool dashed ) override; virtual void SetDash( int dashed ) override;
virtual void SetColor( COLOR4D color ) override; virtual void SetColor( COLOR4D color ) override;