← Back to team overview

kicad-developers team mailing list archive

[PATCH] Set dash lines parameters in one place for plot

 

I deleted Magic numbers that set parameters of dash lines. Use constants in mils. Then apply radius correction and scale to plot units when start to plotting.
Make for PDF, PS, SVG plotters.
And some minor fixes.

 * Английский - определен
 * Русский

 * Русский

<javascript:void(0);>
=== modified file 'common/class_plotter.cpp'
--- common/class_plotter.cpp	2015-03-04 19:45:18 +0000
+++ common/class_plotter.cpp	2015-03-09 14:22:59 +0000
@@ -126,12 +126,23 @@
 }
 
 
-double PLOTTER::userToDeviceSize( double size )
+double PLOTTER::userToDeviceSize( double size ) const
 {
     return size * plotScale * iuPerDeviceUnit;
 }
 
 
+double PLOTTER::GetDashMarkLenIU() const
+{
+    return userToDeviceSize( DASH_MARK_LENGTH - currentPenWidth );
+}
+
+
+double PLOTTER::GetDashGapLenIU() const
+{
+    return userToDeviceSize( DASH_GAP_LENGTH + currentPenWidth );
+}
+
 void PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
                    FILL_T fill, int width )
 {

=== modified file 'common/common_plotPDF_functions.cpp'
--- common/common_plotPDF_functions.cpp	2015-03-03 12:41:43 +0000
+++ common/common_plotPDF_functions.cpp	2015-03-09 14:22:59 +0000
@@ -132,7 +132,8 @@
 {
     wxASSERT( workFile );
     if( dashed )
-        fputs( "[200] 100 d\n", workFile );
+        fprintf( workFile, "[%d %d] 0 d\n",
+                 (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
     else
         fputs( "[] 0 d\n", workFile );
 }

=== modified file 'common/common_plotPS_functions.cpp'
--- common/common_plotPS_functions.cpp	2014-10-19 20:20:16 +0000
+++ common/common_plotPS_functions.cpp	2015-03-09 14:22:59 +0000
@@ -228,7 +228,7 @@
 
 
 /**
- * Write on a stream a string escaped for postscript/PDF
+ * Write on a stream a string escaped for postscript/PDF
  */
 void PSLIKE_PLOTTER::fputsPostscriptString(FILE *fout, const wxString& txt)
 {
@@ -469,7 +469,8 @@
 {
     wxASSERT( outputFile );
     if( dashed )
-        fputs( "dashedline\n", outputFile );
+        fprintf( outputFile, "[%d %d] 0 setdash\n",
+                 (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
     else
         fputs( "solidline\n", outputFile );
 }

=== modified file 'common/common_plotSVG_functions.cpp'
--- common/common_plotSVG_functions.cpp	2015-03-06 17:46:04 +0000
+++ common/common_plotSVG_functions.cpp	2015-03-09 14:22:59 +0000
@@ -231,14 +231,8 @@
     fputs( "stroke-linecap:round; stroke-linejoin:round;", outputFile );
 
     if( m_dashed )
-    {
-        // Use a simple dash shape: a segment + a space
-        #define DASH_SIZE 0.3     // length in mm of a dash
-        double segm_len = DASH_SIZE * 10000/2.54 * m_IUsPerDecimil;
-        // Use a space to the same len as segment, between segments
-        double space_len = segm_len + pen_w;
-        fprintf( outputFile, "stroke-dasharray:%g,%g;", segm_len, space_len );
-    }
+        fprintf( outputFile, "stroke-dasharray:%g,%g;",
+                 GetDashMarkLenIU(), GetDashGapLenIU() );
 
     fputs( "\">\n", outputFile );
 

=== modified file 'include/plot_common.h'
--- include/plot_common.h	2015-03-06 17:46:04 +0000
+++ include/plot_common.h	2015-03-09 14:22:59 +0000
@@ -82,6 +82,11 @@
  */
 class PLOTTER
 {
+private:
+    /* Set dashed line parameters in mils */
+    static const int DASH_MARK_LENGTH = 80;
+    static const int DASH_GAP_LENGTH = 40;
+
 public:
     static const int DEFAULT_LINE_WIDTH = -1;
 
@@ -396,7 +401,11 @@
      * Modifies size according to the plotter scale factors
      * (simple double version)
      */
-    virtual double userToDeviceSize( double size );
+    virtual double userToDeviceSize( double size ) const;
+
+    double GetDashMarkLenIU() const;
+
+    double GetDashGapLenIU() const;
 
     /// Plot scale - chosen by the user (even implicitly with 'fit in a4')
     double        plotScale;


Follow ups