← Back to team overview

kicad-developers team mailing list archive

Plotting/fabricating in nanometers

 

OK, I've done the deed, I think. I only tested it lightly but it wasn't
too invasive, anyway.

It fixes nanometer handling for:
- Plotting (postscript, HPGL, gerber and DXF). SVG is not handled by the
  plot routines, IIRC is handled as a print routine by wx;

- Excellon and related plotting/reporting

- Module position (pick & place) but *not* the module report (since it's
  pcbnew proprietary, anyway...)

- GENCAD (a one liner:D)

Also I removed the U_PCB constant (the 10 ratio between eeschema and
pcbnew)

I'm really not happy about the handling of the portrait mode in
postscript... why it was handled with a special case instead of just let
the printer do the turning? Didn't touch it, but I feel its not elegant.

Also at the moment the plotter interface works in this way: *everything*
from the caller is in IU, but the internals still works in decimils. The
optimum would be the whole plotter working in nanos and just emit the
scaled values, but since it's in common it would have complicated too
much the work. And, anyway, the gerbers we generate now are limited to
decimils...

-- 
Lorenzo Marcantonio
Logos Srl
=== modified file 'common/class_plotter.cpp'
--- common/class_plotter.cpp	2012-04-19 06:55:45 +0000
+++ common/class_plotter.cpp	2012-04-27 09:28:42 +0000
@@ -37,6 +37,9 @@
 
 /* Modifies coordinates pos.x and pos.y trace according to the orientation,
  * scale factor, and offsets trace
+ * IMPORTANT: there is a special case for portrait handling in the
+ * Postscript specialization (more or less the same with the coordinates
+ * swapped), keep it in sync with this!
  */
 void PLOTTER::user_to_device_coordinates( wxPoint& pos )
 {
@@ -426,8 +429,5 @@
 {
     wxASSERT( !output_file );
     pageInfo = aPageSettings;
-
-    // PAGE_INFO is in mils, plotter works with deci-mils
-    paper_size = pageInfo.GetSizeMils() * 10;
 }
 

=== modified file 'common/common_plotDXF_functions.cpp'
--- common/common_plotDXF_functions.cpp	2012-04-19 06:55:45 +0000
+++ common/common_plotDXF_functions.cpp	2012-04-27 09:28:42 +0000
@@ -13,16 +13,29 @@
 #include <kicad_string.h>
 
 
-/* Set the plot offset for the current plotting
+/**
+ * Function set_viewport
+ * Set the plot offset for the current plotting
+ * @param aOffset = plot offset
+ * @param aIusPerDecimil = how many internal units per decimil
+ * @param aScale = coordinate scale (scale coefficient for coordinates)
+ * @param aMirror = Mirror plot if true.
  */
-void DXF_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
+void DXF_PLOTTER::set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	double aScale, bool aMirror )
 {
     wxASSERT( !output_file );
     plot_offset  = aOffset;
     plot_scale   = aScale;
-    device_scale = 1;
-    set_default_line_width( 0 );    /* No line width on DXF */
-    plotMirror = false;             /* No mirroring on DXF */
+    /* XXX Need to think about this: what is the 'native' unit used for DXF? */
+    device_scale = 1.0 / aIusPerDecimil; // Gives a DXF in decimils
+    device_scale *= 0.00254;             // DXF in mm (I like it best)
+    /* Compute the paper size in IUs */
+    paper_size = pageInfo.GetSizeMils();
+    paper_size.x *= 10.0 * aIusPerDecimil;
+    paper_size.y *= 10.0 * aIusPerDecimil;
+    set_default_line_width( 0 );    // No line width on DXF
+    plotMirror = false;             // No mirroring on DXF 
     current_color = BLACK;
 }
 

=== modified file 'common/common_plotGERBER_functions.cpp'
--- common/common_plotGERBER_functions.cpp	2012-04-19 06:55:45 +0000
+++ common/common_plotGERBER_functions.cpp	2012-04-27 09:28:42 +0000
@@ -20,10 +20,12 @@
  * Function set_viewport
  * Set the plot offset for the current plotting
  * @param aOffset = plot offset
+ * @param aIusPerDecimil = how many mils internal units per decimil
  * @param aScale = coordinate scale (scale coefficient for coordinates)
- * @param aMirror - Mirror plot if true.
+ * @param aMirror = Mirror plot if true.
  */
-void GERBER_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
+void GERBER_PLOTTER::set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	double aScale, bool aMirror )
 {
     wxASSERT( !output_file );
     wxASSERT( aMirror == false );
@@ -31,8 +33,12 @@
     plot_offset = aOffset;
     wxASSERT( aScale == 1 );
     plot_scale   = 1;
-    device_scale = 1;
-    set_default_line_width( 100 );  /* line thickness in 1 / 1000 inch */
+    device_scale = 1.0 / aIusPerDecimil;
+    /* We don't handle the filmbox, and it's more useful to keep the
+     * origin at the origin */
+    paper_size.x = 0;
+    paper_size.y = 0;
+    set_default_line_width( 100 * aIusPerDecimil ); // Arbitrary default
 }
 
 
@@ -115,7 +121,7 @@
 }
 
 
-/* Set the default line width (in 1/1000 inch) for the current plotting
+/* Set the default line width (in IUs) for the current plotting
  */
 void GERBER_PLOTTER::set_default_line_width( int width )
 {
@@ -124,7 +130,7 @@
 }
 
 
-/* Set the Current line width (in 1/1000 inch) for the next plot
+/* Set the Current line width (in IUs) for the next plot
  */
 void GERBER_PLOTTER::set_current_line_width( int width )
 {
@@ -196,7 +202,8 @@
     for( std::vector<APERTURE>::iterator tool = apertures.begin();
          tool != apertures.end(); tool++ )
     {
-        const float fscale = 0.0001f * plot_scale; // For 3.4 format
+        const float fscale = 0.0001f * plot_scale 
+				* device_scale; // For 3.4 format
         char*       text;
 
         text = cbuf + sprintf( cbuf, "%%ADD%d", tool->D_code );
@@ -217,7 +224,8 @@
             break;
 
         case APERTURE::Oval:
-            sprintf( text, "O,%fX%f*%%\n", tool->size.x * fscale, tool->size.y * fscale );
+            sprintf( text, "O,%fX%f*%%\n", tool->size.x * fscale, 
+		    tool->size.y * fscale );
             break;
         }
 
@@ -555,3 +563,4 @@
     else
         fprintf( output_file, "%%LPC*%%\n" );
 }
+

=== modified file 'common/common_plotHPGL_functions.cpp'
--- common/common_plotHPGL_functions.cpp	2012-04-19 06:55:45 +0000
+++ common/common_plotHPGL_functions.cpp	2012-04-27 09:28:42 +0000
@@ -13,16 +13,29 @@
 #include <kicad_string.h>
 
 // HPGL scale factor.
-const double SCALE_HPGL = 0.102041;
-
-
-void HPGL_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
+static const double SCALE_HPGL = 0.102041;
+
+
+/**
+ * Function set_viewport
+ * Set the plot offset for the current plotting
+ * @param aOffset = plot offset
+ * @param aIusPerDecimil = how many internal units per decimil
+ * @param aScale = coordinate scale (scale coefficient for coordinates)
+ * @param aMirror = Mirror plot if true.
+ */
+void HPGL_PLOTTER::set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	double aScale, bool aMirror )
 {
     wxASSERT( !output_file );
     plot_offset  = aOffset;
     plot_scale   = aScale;
-    device_scale = SCALE_HPGL;
-    set_default_line_width( 100 ); // default line width in 1 / 1000 inch
+    device_scale = SCALE_HPGL / aIusPerDecimil;
+    /* Compute the paper size in IUs */
+    paper_size = pageInfo.GetSizeMils();
+    paper_size.x *= 10.0 * aIusPerDecimil;
+    paper_size.y *= 10.0 * aIusPerDecimil;
+    set_default_line_width( 0 ); // HPGL has pen sizes instead
     plotMirror = aMirror;
 }
 
@@ -576,3 +589,4 @@
         }
     }
 }
+

=== modified file 'common/common_plotPS_functions.cpp'
--- common/common_plotPS_functions.cpp	2012-04-20 06:51:22 +0000
+++ common/common_plotPS_functions.cpp	2012-04-27 09:28:42 +0000
@@ -14,28 +14,40 @@
 #include <kicad_string.h>
 
 
-/* Set the plot offset for the current plotting */
-void PS_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
+/**
+ * Function set_viewport
+ * Set the plot offset for the current plotting
+ * @param aOffset = plot offset
+ * @param aIusPerDecimil = how many internal units per decimil
+ * @param aScale = coordinate scale (scale coefficient for coordinates)
+ * @param aMirror = Mirror plot if true.
+ */
+void PS_PLOTTER::set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	double aScale, bool aMirror )
 {
     wxASSERT( !output_file );
     plotMirror = aMirror;
     plot_offset  = aOffset;
     plot_scale   = aScale;
-    device_scale = 1;               /* PS references in decimals */
-    set_default_line_width( 100 );  /* default line width in 1/1000 inch */
+    device_scale = 1.0 / aIusPerDecimil; 
+    /* Compute the paper size in IUs */
+    paper_size = pageInfo.GetSizeMils();
+    paper_size.x *= 10.0 * aIusPerDecimil;
+    paper_size.y *= 10.0 * aIusPerDecimil;
+    set_default_line_width( 100 * aIusPerDecimil );  // arbitrary default
 }
 
 
-/* Set the default line width (in 1/1000 inch) for the current plotting
+/* Set the default line width (in IUs) for the current plotting
  */
 void PS_PLOTTER::set_default_line_width( int width )
 {
-    default_pen_width = width;   // line width in 1/1000 inch
+    default_pen_width = width;
     current_pen_width = -1;
 }
 
 
-/* Set the current line width (in 1/1000 inch) for the next plot
+/* Set the current line width (in IUs) for the next plot
  */
 void PS_PLOTTER::set_current_line_width( int width )
 {
@@ -113,9 +125,9 @@
 {
     wxASSERT( output_file );
     if( dashed )
-        fputs( "dashedline\n", stderr );
+        fputs( "dashedline\n", output_file );
     else
-        fputs( "solidline\n", stderr );
+        fputs( "solidline\n", output_file );
 }
 
 
@@ -326,37 +338,36 @@
     output_file = fout;
     static const char* PSMacro[] =
     {
-        "/line {\n",
-        "    newpath\n",
-        "    moveto\n",
-        "    lineto\n",
-        "    stroke\n",
-        "} bind def\n",
-        "/cir0 { newpath 0 360 arc stroke } bind def\n",
-        "/cir1 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
-        "/cir2 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
-        "/arc0 { newpath arc stroke } bind def\n",
-        "/arc1 { newpath 4 index 4 index moveto arc closepath gsave fill ",
-        "grestore stroke } bind def\n",
-        "/arc2 { newpath 4 index 4 index moveto arc closepath gsave fill ",
-        "grestore stroke } bind def\n",
-        "/poly0 { stroke } bind def\n",
-        "/poly1 { closepath gsave fill grestore stroke } bind def\n",
-        "/poly2 { closepath gsave fill grestore stroke } bind def\n",
-        "/rect0 { rectstroke } bind def\n",
-        "/rect1 { rectfill } bind def\n",
-        "/rect2 { rectfill } bind def\n",
-        "/linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def\n",
-        "/linemode1 { 1 setlinecap 1 setlinejoin } bind def\n",
-        "/dashedline { [50 50] 0 setdash } bind def\n",
-        "/solidline { [] 0 setdash } bind def\n",
-        "gsave\n",
-        "0.0072 0.0072 scale\n",   // Configure postscript for decimals.
-        "linemode1\n",
-        NULL
+	"/line {\n",
+	"    newpath\n",
+	"    moveto\n",
+	"    lineto\n",
+	"    stroke\n",
+	"} bind def\n",
+	"/cir0 { newpath 0 360 arc stroke } bind def\n",
+	"/cir1 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
+	"/cir2 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
+	"/arc0 { newpath arc stroke } bind def\n",
+	"/arc1 { newpath 4 index 4 index moveto arc closepath gsave fill ",
+	"grestore stroke } bind def\n",
+	"/arc2 { newpath 4 index 4 index moveto arc closepath gsave fill ",
+	"grestore stroke } bind def\n",
+	"/poly0 { stroke } bind def\n",
+	"/poly1 { closepath gsave fill grestore stroke } bind def\n",
+	"/poly2 { closepath gsave fill grestore stroke } bind def\n",
+	"/rect0 { rectstroke } bind def\n",
+	"/rect1 { rectfill } bind def\n",
+	"/rect2 { rectfill } bind def\n",
+	"/linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def\n",
+	"/linemode1 { 1 setlinecap 1 setlinejoin } bind def\n",
+	"/dashedline { [50 50] 0 setdash } bind def\n",
+	"/solidline { [] 0 setdash } bind def\n",
+	"gsave\n",
+	"0.0072 0.0072 scale\n",   // Configure postscript for decimils coordinates
+	"linemode1\n",
+	NULL
     };
 
-    const double       DECIMIL_TO_INCH = 0.0001;
     time_t             time1970 = time( NULL );
 
     fputs( "%!PS-Adobe-3.0\n", output_file );    // Print header
@@ -370,20 +381,20 @@
     fprintf( output_file, "%%%%Pages: 1\n" );
     fprintf( output_file, "%%%%PageOrder: Ascend\n" );
 
-    // Print boundary box in 1/72 pixels per inch, box is in deci-mils
-    const double CONV_SCALE = DECIMIL_TO_INCH * 72;
+    // Print boundary box in 1/72 pixels per inch, box is in mils
+    const double CONV_SCALE = 0.072;
 
     // The coordinates of the lower left corner of the boundary
     // box need to be "rounded down", but the coordinates of its
     // upper right corner need to be "rounded up" instead.
-    wxSize  psPaperSize = paper_size;
+    wxSize psPaperSize = pageInfo.GetSizeMils();
 
     if( !pageInfo.IsPortrait() )
-        psPaperSize.Set( paper_size.y, paper_size.x );
-
+        psPaperSize.Set( pageInfo.GetHeightMils(), pageInfo.GetWidthMils() );
+    
     fprintf( output_file, "%%%%BoundingBox: 0 0 %d %d\n",
-            (int) ceil( psPaperSize.x * CONV_SCALE ),
-            (int) ceil( psPaperSize.y * CONV_SCALE ) );
+	    (int) ceil( psPaperSize.x * CONV_SCALE ),
+	    (int) ceil( psPaperSize.y * CONV_SCALE ) );
 
     // Specify the size of the sheet and the name associated with that size.
     // (If the "User size" option has been selected for the sheet size,
@@ -399,21 +410,17 @@
     // the order in which they are specified is not wrong!)
     // Also note pageSize is given in mils, not in internal units and must be
     // converted to internal units.
-    wxSize psPageSize = pageInfo.GetSizeMils();
-
-    if( !pageInfo.IsPortrait() )
-        psPageSize.Set( pageInfo.GetHeightMils(), pageInfo.GetWidthMils() );
 
     if( pageInfo.IsCustom() )
         fprintf( output_file, "%%%%DocumentMedia: Custom %d %d 0 () ()\n",
-                 KiROUND( psPageSize.x * 10 * CONV_SCALE ),
-                 KiROUND( psPageSize.y * 10 * CONV_SCALE ) );
+                 KiROUND( psPaperSize.x * CONV_SCALE ),
+                 KiROUND( psPaperSize.y * CONV_SCALE ) );
 
     else  // a standard paper size
         fprintf( output_file, "%%%%DocumentMedia: %s %d %d 0 () ()\n",
                  TO_UTF8( pageInfo.GetType() ),
-                 KiROUND( psPageSize.x * 10 * CONV_SCALE ),
-                 KiROUND( psPageSize.y * 10 * CONV_SCALE ) );
+                 KiROUND( psPaperSize.x * CONV_SCALE ),
+                 KiROUND( psPaperSize.y * CONV_SCALE ) );
 
     if( pageInfo.IsPortrait() )
         fprintf( output_file, "%%%%Orientation: Portrait\n" );
@@ -438,8 +445,11 @@
     // (If support for creating postscript files with a portrait orientation
     // is ever provided, determine whether it would be necessary to provide
     // an "else" command and then an appropriate "sprintf" command here.)
+    // XXX indeed it would remove the ugly virtual override for 
+    // user_to_device_coordinates
+
     if( !pageInfo.IsPortrait() )
-        fprintf( output_file, "%d 0 translate 90 rotate\n", paper_size.y );
+        fprintf( output_file, "%d 0 translate 90 rotate\n", 10 * psPaperSize.x );
 
     // Apply the scale adjustments
     if( plot_scale_adjX != 1.0 || plot_scale_adjY != 1.0 )

=== modified file 'common/common_plot_functions.cpp'
--- common/common_plot_functions.cpp	2012-04-20 06:51:22 +0000
+++ common/common_plot_functions.cpp	2012-04-27 09:28:42 +0000
@@ -1,6 +1,6 @@
 /**
  * @file common_plot_functions.cpp
- * @brief Kicad: Common plot Postscript Routines
+ * @brief Kicad: Common plotting Routines
  */
 
 #include <fctsys.h>

=== modified file 'eeschema/dialogs/dialog_plot_schematic_DXF.cpp'
--- eeschema/dialogs/dialog_plot_schematic_DXF.cpp	2012-01-23 04:33:36 +0000
+++ eeschema/dialogs/dialog_plot_schematic_DXF.cpp	2012-04-27 09:38:19 +0000
@@ -185,14 +185,12 @@
             sheetpath = SheetList.GetNext();
         }
 
-        double scale = 10;
-
         plot_offset.x = 0;
         plot_offset.y = 0;
 
         plotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT( ".dxf" );
 
-        PlotOneSheetDXF( plotFileName, screen, plot_offset, scale );
+        PlotOneSheetDXF( plotFileName, screen, plot_offset, 1 );
 
         if( !m_select_PlotAll )
             break;
@@ -232,7 +230,7 @@
     const PAGE_INFO&   pageInfo = screen->GetPageSettings();
     plotter->SetPageSettings( pageInfo );
 
-    plotter->set_viewport( plot_offset, scale, 0 );
+    plotter->set_viewport( plot_offset, IU_PER_DECIMILS, scale, 0 );
     plotter->set_color_mode( m_plotColorOpt );
 
     // Init :

=== modified file 'eeschema/dialogs/dialog_plot_schematic_HPGL.cpp'
--- eeschema/dialogs/dialog_plot_schematic_HPGL.cpp	2012-04-16 17:39:32 +0000
+++ eeschema/dialogs/dialog_plot_schematic_HPGL.cpp	2012-04-27 09:38:44 +0000
@@ -330,7 +330,7 @@
         // Calculation of conversion scales.
 
         // 10x because Eeschema works in mils, not deci-mils
-        double plot_scale = 10 * (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
+        double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
 
         // Calculate offsets
         plotOffset.x = -s_Offset.x;
@@ -380,7 +380,7 @@
 
     plotter->SetPageSettings( pageInfo );
 
-    plotter->set_viewport( offset, plot_scale, 0 );
+    plotter->set_viewport( offset, IU_PER_DECIMILS, plot_scale, 0 );
     plotter->set_default_line_width( g_DrawDefaultLineThickness );
 
     // Init :

=== modified file 'eeschema/dialogs/dialog_plot_schematic_PS.cpp'
--- eeschema/dialogs/dialog_plot_schematic_PS.cpp	2012-04-16 17:39:32 +0000
+++ eeschema/dialogs/dialog_plot_schematic_PS.cpp	2012-04-27 09:38:51 +0000
@@ -237,7 +237,7 @@
         double scalex = (double) plotPage.GetWidthMils()  / actualPage.GetWidthMils();
         double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
 
-        double scale  = 10 * MIN( scalex, scaley );
+        double scale  = MIN( scalex, scaley );
 
         plot_offset.x = 0;
         plot_offset.y = 0;
@@ -281,7 +281,7 @@
 
     PS_PLOTTER* plotter = new PS_PLOTTER();
     plotter->SetPageSettings( pageInfo );
-    plotter->set_viewport( plot_offset, scale, 0 );
+    plotter->set_viewport( plot_offset, IU_PER_DECIMILS, scale, 0 );
     plotter->set_default_line_width( g_DrawDefaultLineThickness );
     plotter->set_color_mode( m_plotColorOpt );
 

=== modified file 'include/convert_to_biu.h'
--- include/convert_to_biu.h	2012-04-26 21:34:20 +0000
+++ include/convert_to_biu.h	2012-04-27 09:29:25 +0000
@@ -55,6 +55,7 @@
 }
 
 #else            // Eeschema and anything else.
+#define IU_PER_DECIMILS  0.1
 #define IU_PER_MILS   1.0
 #define IU_PER_MM   (IU_PER_MILS / 0.0254)
 

=== modified file 'include/plot_common.h'
--- include/plot_common.h	2012-04-19 06:55:45 +0000
+++ include/plot_common.h	2012-04-27 09:28:42 +0000
@@ -97,7 +97,8 @@
     }
 
     /// Set the plot offset for the current plotting
-    virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror ) = 0;
+    virtual void set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	    double aScale, bool aMirror ) = 0;
 
     // Standard primitives
     virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill,
@@ -219,10 +220,10 @@
     /// Plot scale
     double        plot_scale;
 
-    /// Device scale (from decimils to device units)
+    /// Device scale (from IUs to device units)
     double        device_scale;
 
-    /// Plot offset (in decimils)
+    /// Plot offset (in IUs)
     wxPoint       plot_offset;
 
     /// Output file
@@ -257,7 +258,7 @@
     virtual void set_current_line_width( int width )
     {
         // Handy override
-        current_pen_width = KiROUND( pen_diameter );
+        current_pen_width = user_to_device_size( pen_diameter );
     }
 
     virtual void set_default_line_width( int width ) {};
@@ -289,7 +290,8 @@
         pen_overlap = overlap;
     }
 
-    virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
+    virtual void set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	    double aScale, bool aMirror );
     virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
     virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
 
@@ -374,7 +376,8 @@
         return plot_width_adj;
     }
 
-    virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
+    virtual void set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	    double aScale, bool aMirror );
     virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
     virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
     virtual void arc( wxPoint centre, int StAngle, int EndAngle, int rayon,
@@ -460,7 +463,8 @@
     // RS274X has no dashing, nor colours
     virtual void set_dash( bool dashed ) {};
     virtual void set_color( int color ) {};
-    virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
+    virtual void set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	    double aScale, bool aMirror );
     virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
     virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
     /*
@@ -542,7 +546,8 @@
 
     virtual void set_color( int color );
 
-    virtual void set_viewport( wxPoint aOffset, double aScale, bool aMirror );
+    virtual void set_viewport( wxPoint aOffset, double aIusPerDecimil,
+	    double aScale, bool aMirror );
     virtual void rect( wxPoint p1, wxPoint p2, FILL_T fill, int width = -1 );
     virtual void circle( wxPoint pos, int diametre, FILL_T fill, int width = -1 );
     /*

=== modified file 'pcbnew/export_gencad.cpp'
--- pcbnew/export_gencad.cpp	2012-02-20 07:45:12 +0000
+++ pcbnew/export_gencad.cpp	2012-04-27 09:35:28 +0000
@@ -97,7 +97,7 @@
 
 /* GerbTool chokes on units different than INCH so this is the conversion
  *  factor */
-const static double SCALE_FACTOR = 10000.0;
+const static double SCALE_FACTOR = 10000.0 * IU_PER_DECIMILS;
 
 
 /* Two helper functions to calculate coordinates of modules in gencad values

=== modified file 'pcbnew/gen_drill_report_files.cpp'
--- pcbnew/gen_drill_report_files.cpp	2012-04-05 18:27:56 +0000
+++ pcbnew/gen_drill_report_files.cpp	2012-04-27 09:47:49 +0000
@@ -18,6 +18,17 @@
 #include <pcbplot.h>
 #include <gendrill.h>
 
+/* Conversion utilities - these will be used often in there... */
+static double diameter_in_inches(double ius)
+{
+    return ius * 0.001 / IU_PER_MILS;
+}
+
+static double diameter_in_mm(double ius)
+{
+    return ius / IU_PER_MM;
+}
+
 
 void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName,
                       const PAGE_INFO& aSheet,
@@ -57,7 +68,7 @@
         scale   = 1;
         offset  = auxoffset;
         plotter = new GERBER_PLOTTER();
-        plotter->set_viewport( offset, scale, 0 );
+        plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 0 );
         break;
 
     case PLOT_FORMAT_HPGL:  // Scale for HPGL format.
@@ -71,7 +82,7 @@
             hpgl_plotter->set_pen_speed( plot_opts.m_HPGLPenSpeed );
             hpgl_plotter->set_pen_overlap( 0 );
             plotter->SetPageSettings( aSheet );
-            plotter->set_viewport( offset, scale, 0 );
+            plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 0 );
         }
         break;
 
@@ -93,7 +104,7 @@
             PS_PLOTTER* ps_plotter = new PS_PLOTTER;
             plotter = ps_plotter;
             ps_plotter->SetPageSettings( pageA4 );
-            plotter->set_viewport( offset, scale, 0 );
+            plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 0 );
         }
         break;
 
@@ -105,7 +116,7 @@
             DXF_PLOTTER* dxf_plotter = new DXF_PLOTTER;
             plotter = dxf_plotter;
             plotter->SetPageSettings( aSheet );
-            plotter->set_viewport( offset, scale, 0 );
+            plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 0 );
         }
         break;
 
@@ -115,7 +126,7 @@
 
     plotter->set_creator( wxT( "PCBNEW" ) );
     plotter->set_filename( aFullFileName );
-    plotter->set_default_line_width( 10 );
+    plotter->set_default_line_width( 10 * IU_PER_DECIMILS );
     plotter->start_plot( aFile );
 
     // Draw items on edge layer
@@ -150,14 +161,14 @@
     }
 
     // Set Drill Symbols width in 1/10000 mils
-    plotter->set_default_line_width( 10 );
+    plotter->set_default_line_width( 10 * IU_PER_DECIMILS );
     plotter->set_current_line_width( -1 );
 
     // Plot board outlines and drill map
     Gen_Drill_PcbMap( aPcb, plotter, aHoleListBuffer, aToolListBuffer );
 
     // Print a list of symbols used.
-    CharSize = 800;                        // text size in 1/10000 mils
+    CharSize = 50 * IU_PER_MILS; // text size in IUs
     double CharScale = 1.0 / scale;        /* real scale will be CharScale
                                             * scale_x, because the global
                                             * plot scale is scale_x */
@@ -165,7 +176,7 @@
     intervalle = (int) ( CharSize * CharScale ) + TextWidth;
 
     // Trace information.
-    plotX = (int) ( (double) bbbox.GetX() + 200.0 * CharScale );
+    plotX = (int) ( (double) bbbox.GetX() + 20 * IU_PER_MILS * CharScale );
     plotY = bbbox.GetBottom() + intervalle;
 
     // Plot title  "Info"
@@ -186,7 +197,8 @@
         plotY += intervalle;
 
         plot_diam = (int) aToolListBuffer[ii].m_Diameter;
-        x = (int) ( (double) plotX - 200.0 * CharScale - (double)plot_diam / 2.0 );
+        x = (int) ( (double) plotX - 20.0 * IU_PER_MILS * CharScale 
+                - (double)plot_diam / 2.0 );
         y = (int) ( (double) plotY + (double) CharSize * CharScale );
         plotter->marker( wxPoint( x, y ), plot_diam, ii );
 
@@ -196,12 +208,12 @@
         // and then its diameter in the other Drill Unit.
         if( aUnit_Drill_is_Inch )
             sprintf( line, "%2.3f\" / %2.2fmm ",
-                     double (aToolListBuffer[ii].m_Diameter) * 0.0001,
-                     double (aToolListBuffer[ii].m_Diameter) * 0.00254 );
+                    diameter_in_inches( aToolListBuffer[ii].m_Diameter ),
+                    diameter_in_mm( aToolListBuffer[ii].m_Diameter ) );
         else
             sprintf( line, "%2.2fmm / %2.3f\" ",
-                     double (aToolListBuffer[ii].m_Diameter) * 0.00254,
-                     double (aToolListBuffer[ii].m_Diameter) * 0.0001 );
+                    diameter_in_mm( aToolListBuffer[ii].m_Diameter ),
+                    diameter_in_inches( aToolListBuffer[ii].m_Diameter ) );
 
         msg = FROM_UTF8( line );
 
@@ -304,7 +316,7 @@
     // List which Drill Unit option had been selected for the associated
     // drill aFile.
     if( aUnit_Drill_is_Inch )
-        fputs( "Selected Drill Unit: Imperial (\")\n\n", aFile );
+        fputs( "Selected Drill Unit: Imperial (inches)\n\n", aFile );
     else
         fputs( "Selected Drill Unit: Metric (mm)\n\n", aFile );
 
@@ -327,12 +339,12 @@
 
         if( gen_NPTH_holes )
         {
-            sprintf( line, "Drill report for Not Plated through holes :\n" );
+            sprintf( line, "Drill report for unplated through holes :\n" );
         }
 
         else if( gen_through_holes )
         {
-            sprintf( line, "Drill report for through holes :\n" );
+            sprintf( line, "Drill report for plated through holes :\n" );
         }
         else
         {
@@ -342,7 +354,7 @@
                 fputs( line, aFile );
             }
 
-            sprintf( line, "Drill report for holes from layer %s to layer %s\n",
+            sprintf( line, "Drill report for holes from layer %s to layer %s :\n",
                      TO_UTF8( aPcb->GetLayerName( layer1 ) ),
                      TO_UTF8( aPcb->GetLayerName( layer2 ) ) );
         }
@@ -355,15 +367,19 @@
             // then its diameter in the selected Drill Unit,
             // and then its diameter in the other Drill Unit.
             if( aUnit_Drill_is_Inch )
+            {
                 sprintf( line, "T%d  %2.3f\"  %2.2fmm  ",
                          ii + 1,
-                         double (aToolListBuffer[ii].m_Diameter) * 0.0001,
-                         double (aToolListBuffer[ii].m_Diameter) * 0.00254 );
+                         diameter_in_inches( aToolListBuffer[ii].m_Diameter ),
+                         diameter_in_mm( aToolListBuffer[ii].m_Diameter ) );
+            }
             else
+            {
                 sprintf( line, "T%d  %2.2fmm  %2.3f\"  ",
                          ii + 1,
-                         double (aToolListBuffer[ii].m_Diameter) * 0.00254,
-                         double (aToolListBuffer[ii].m_Diameter) * 0.0001 );
+                         diameter_in_mm( aToolListBuffer[ii].m_Diameter ),
+                         diameter_in_inches( aToolListBuffer[ii].m_Diameter ) );
+            }
 
             fputs( line, aFile );
 
@@ -372,13 +388,13 @@
                && ( aToolListBuffer[ii].m_OvalCount == 0 ) )
                 sprintf( line, "(1 hole)\n" );
             else if( aToolListBuffer[ii].m_TotalCount == 1 )
-                sprintf( line, "(1 hole)  (with 1 oblong)\n" );
+                sprintf( line, "(1 hole)  (with 1 slot)\n" );
             else if( aToolListBuffer[ii].m_OvalCount == 0 )
                 sprintf( line, "(%d holes)\n", aToolListBuffer[ii].m_TotalCount );
             else if( aToolListBuffer[ii].m_OvalCount == 1 )
-                sprintf( line, "(%d holes)  (with 1 oblong)\n", aToolListBuffer[ii].m_TotalCount );
+                sprintf( line, "(%d holes)  (with 1 slot)\n", aToolListBuffer[ii].m_TotalCount );
             else  //  if ( buffer[ii]m_OvalCount > 1 )
-                sprintf( line, "(%d holes)  (with %d oblongs)\n",
+                sprintf( line, "(%d holes)  (with %d slots)\n",
                          aToolListBuffer[ii].m_TotalCount,
                          aToolListBuffer[ii].m_OvalCount );
 
@@ -388,9 +404,9 @@
         }
 
         if( gen_NPTH_holes )
-            sprintf( line, "\ntotal Not Plated holes count %d\n\n\n", TotalHoleCount );
+            sprintf( line, "\nTotal unplated holes count %d\n\n\n", TotalHoleCount );
         else
-            sprintf( line, "\ntotal plated holes count %d\n\n\n", TotalHoleCount );
+            sprintf( line, "\nTotal plated holes count %d\n\n\n", TotalHoleCount );
 
         fputs( line, aFile );
 

=== modified file 'pcbnew/gen_modules_placefile.cpp'
--- pcbnew/gen_modules_placefile.cpp	2012-04-17 01:35:43 +0000
+++ pcbnew/gen_modules_placefile.cpp	2012-04-27 09:49:31 +0000
@@ -212,10 +212,10 @@
     if( singleFile )
     {
         side = 2;
-        fn.SetName( fn.GetName() + wxT( "_" ) + wxT("all") );
+        fn.SetName( fn.GetName() + wxT( "-" ) + wxT("all") );
     }
      else
-        fn.SetName( fn.GetName() + wxT( "_" ) + frontLayerName );
+        fn.SetName( fn.GetName() + wxT( "-" ) + frontLayerName );
 
     fn.SetExt( FootprintPlaceFileExtension );
 
@@ -252,7 +252,7 @@
     side = 0;
     fn = screen->GetFileName();
     fn.SetPath( GetOutputDirectory() );
-    fn.SetName( fn.GetName() + wxT( "_" ) + backLayerName );
+    fn.SetName( fn.GetName() + wxT( "-" ) + backLayerName );
     fn.SetExt( wxT( "pos" ) );
 
     fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
@@ -286,10 +286,10 @@
 }
 
 // Defined values to write coordinates using inches or mm:
-static const double conv_unit_inch = 0.0001;      // units = INCHES
+static const double conv_unit_inch = 0.001 / IU_PER_MILS ;      // units = INCHES
 static const char unit_text_inch[] = "## Unit = inches, Angle = deg.\n";
 
-static const double conv_unit_mm = 0.00254;    // units = mm
+static const double conv_unit_mm = 1.0 / IU_PER_MM;    // units = mm
 static const char unit_text_mm[] = "## Unit = mm, Angle = deg.\n";
 
 static wxPoint File_Place_Offset;  // Offset coordinates for generated file.
@@ -465,9 +465,11 @@
         module_pos -= File_Place_Offset;
 
         char* text = line + strlen( line );
+        /* Keep the coordinates in the first quadrant, like the gerbers
+         * (i.e. change sign to y) */
         sprintf( text, " %9.4f  %9.4f  %8.1f    ",
                  module_pos.x * conv_unit,
-                 module_pos.y * conv_unit,
+                 -module_pos.y * conv_unit,
                  double(list[ii].m_Module->m_Orient) / 10 );
 
         int layer = list[ii].m_Module->GetLayer();

=== modified file 'pcbnew/gendrill.cpp'
--- pcbnew/gendrill.cpp	2012-04-19 06:55:45 +0000
+++ pcbnew/gendrill.cpp	2012-04-27 09:55:57 +0000
@@ -405,9 +405,9 @@
 
     /* Set conversion scale depending on drill file units */
     if( m_unitsDecimal )
-        m_conversionUnits = 0.00254;        // EXCELLON units = mm
+        m_conversionUnits = 1.0 / IU_PER_MM; // EXCELLON units = mm
     else
-        m_conversionUnits = 0.0001;         // EXCELLON units = INCHES
+        m_conversionUnits = 0.001 / IU_PER_MILS; // EXCELLON units = INCHES
 
     m_precision.m_lhs = aLeftDigits;
     m_precision.m_rhs = aRightDigits;

=== modified file 'pcbnew/pcb_plot_params.cpp'
--- pcbnew/pcb_plot_params.cpp	2012-04-05 18:27:56 +0000
+++ pcbnew/pcb_plot_params.cpp	2012-04-27 09:35:37 +0000
@@ -31,9 +31,9 @@
 
 
 #define PLOT_LINEWIDTH_MIN        0
-#define PLOT_LINEWIDTH_MAX        200
+#define PLOT_LINEWIDTH_MAX        (200*IU_PER_DECIMILS)
 #define HPGL_PEN_DIAMETER_MIN     0
-#define HPGL_PEN_DIAMETER_MAX     100
+#define HPGL_PEN_DIAMETER_MAX     (100*IU_PER_DECIMILS)
 #define HPGL_PEN_SPEED_MIN        0
 #define HPGL_PEN_SPEED_MAX        1000
 #define HPGL_PEN_NUMBER_MIN       1

=== modified file 'pcbnew/pcbnew.h'
--- pcbnew/pcbnew.h	2012-04-20 06:51:22 +0000
+++ pcbnew/pcbnew.h	2012-04-27 09:28:42 +0000
@@ -10,8 +10,6 @@
 #include <base_struct.h>    // IS_DRAGGED and IN_EDIT definitions.
 #include <convert_to_biu.h> // to define DMils2iu() conversion function
 
-#define U_PCB (PCB_INTERNAL_UNIT / EESCHEMA_INTERNAL_UNIT)
-
 // Arcs are approximated by segments: define the number of segments per 360 deg (KiCad uses 0.1
 // deg approximation).  Be aware 3600 / ARC_APPROX_SEGMENTS_COUNT_LOW_DEF is an integer.
 #define ARC_APPROX_SEGMENTS_COUNT_LOW_DEF 16

=== modified file 'pcbnew/plotdxf.cpp'
--- pcbnew/plotdxf.cpp	2012-04-05 18:27:56 +0000
+++ pcbnew/plotdxf.cpp	2012-04-27 09:35:52 +0000
@@ -31,7 +31,7 @@
 
     DXF_PLOTTER* plotter = new DXF_PLOTTER();
     plotter->SetPageSettings( GetPageSettings() );
-    plotter->set_viewport( wxPoint( 0, 0 ), 1, 0 );
+    plotter->set_viewport( wxPoint( 0, 0 ), IU_PER_DECIMILS, 1, 0 );
     plotter->set_creator( wxT( "PCBNEW-DXF" ) );
     plotter->set_filename( aFullFileName );
     plotter->start_plot( output_file );

=== modified file 'pcbnew/plotgerb.cpp'
--- pcbnew/plotgerb.cpp	2012-04-05 18:27:56 +0000
+++ pcbnew/plotgerb.cpp	2012-04-27 09:35:57 +0000
@@ -54,7 +54,7 @@
     PLOTTER* plotter = new GERBER_PLOTTER();
 
     // No mirror and scaling for gerbers!
-    plotter->set_viewport( offset, scale, 0 );
+    plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 0 );
     plotter->set_default_line_width( plot_opts.m_PlotLineWidth );
     plotter->set_creator( wxT( "PCBNEW-RS274X" ) );
     plotter->set_filename( aFullFileName );

=== modified file 'pcbnew/plothpgl.cpp'
--- pcbnew/plothpgl.cpp	2012-04-19 06:55:45 +0000
+++ pcbnew/plothpgl.cpp	2012-04-27 09:38:03 +0000
@@ -38,7 +38,7 @@
     // Compute pen_dim (from g_m_HPGLPenDiam in mils) in pcb units,
     // with plot scale (if Scale is 2, pen diameter is always g_m_HPGLPenDiam
     // so apparent pen diam is real pen diam / Scale
-    int pen_diam = KiROUND( (plot_opts.m_HPGLPenDiam * U_PCB) /
+    int pen_diam = KiROUND( plot_opts.m_HPGLPenDiam /
                             plot_opts.m_PlotScale );
 
     // compute pen_overlay (from g_m_HPGLPenOvr in mils) with plot scale
@@ -100,7 +100,8 @@
     // why did we have to change these settings above?
     SetPlotSettings( plot_opts );
 
-    plotter->set_viewport( offset, scale, plot_opts.m_PlotMirror );
+    plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 
+	    plot_opts.m_PlotMirror );
     plotter->set_default_line_width( plot_opts.m_PlotLineWidth );
     plotter->set_creator( wxT( "PCBNEW-HPGL" ) );
     plotter->set_filename( aFullFileName );

=== modified file 'pcbnew/plotps.cpp'
--- pcbnew/plotps.cpp	2012-04-19 06:55:45 +0000
+++ pcbnew/plotps.cpp	2012-04-27 09:38:03 +0000
@@ -111,7 +111,8 @@
     plotter->set_scale_adjust( plotOpts.m_FineScaleAdjustX,
                                plotOpts.m_FineScaleAdjustY );
     plotter->set_plot_width_adj( plotOpts.m_FineWidthAdjust );
-    plotter->set_viewport( offset, scale, plotOpts.m_PlotMirror );
+    plotter->set_viewport( offset, IU_PER_DECIMILS, scale, 
+	    plotOpts.m_PlotMirror );
     plotter->set_default_line_width( plotOpts.m_PlotLineWidth );
     plotter->set_creator( wxT( "PCBNEW-PS" ) );
     plotter->set_filename( aFullFileName );


Follow ups