← Back to team overview

kicad-developers team mailing list archive

Re: [Patch] Fix warnings in DXF plotting

 

Wayne,

That's just slightly embarrassing, since I was the author of the original
code. Here is a corrected version.

-Ian

On Wed, Jul 10, 2019 at 3:28 PM Wayne Stambaugh <stambaughw@xxxxxxxxx>
wrote:

> Ian,
>
> This patch look good except that the enum DXF_Units does not follow the
> coding policy.  I realize that the previous code was also not compliant
> but I would prefer we fix coding policy violations when making changes
> so please change it to DXF_UNITS.  Also, please correct the spelling of
> DXF_MILIMETERS to DXF_MILLIMETERS.  I will merge this patch once these
> changes are made.
>
> Cheers,
>
> Wayne
>
> On 6/30/19 4:55 PM, Ian McInerney wrote:
> > After updating my compiler to Clang 8.0.0, it appears that some new
> > warnings are appearing. This patch cleans up the warnings in the DXF
> > plotter (they were related to the units enum and it overshadowing it
> > some common units). I left these separate since the DXF enum is tied to
> > the order in the plot window, so it can't use the main units enum.
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> > Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~kicad-developers
> > More help   : https://help.launchpad.net/ListHelp
> >
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
From c164d42332d9ac0630142019cbda9a473ff7c8a9 Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Wed, 10 Jul 2019 16:47:12 +0200
Subject: [PATCH] pcbnew: Clean up warnings with unit handling in the DXF
 export

---
 common/plotters/DXF_plotter.cpp |  6 +++---
 include/plotter.h               | 16 ++++++++--------
 pcbnew/dialogs/dialog_plot.cpp  |  2 +-
 pcbnew/pcb_plot_params.cpp      |  2 +-
 pcbnew/pcb_plot_params.h        | 13 +++----------
 pcbnew/plot_board_layers.cpp    |  3 ++-
 6 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp
index 9f721e661..ffb31122e 100644
--- a/common/plotters/DXF_plotter.cpp
+++ b/common/plotters/DXF_plotter.cpp
@@ -122,18 +122,18 @@ static wxString getDXFColorName( COLOR4D aColor )
 }
 
 
-void DXF_PLOTTER::SetUnits( Units aUnit )
+void DXF_PLOTTER::SetUnits( DXF_UNITS aUnit )
 {
     m_plotUnits = aUnit;
 
     switch( aUnit )
     {
-    case MILIMETERS:
+    case DXF_UNIT_MILLIMETERS:
         m_unitScalingFactor = 0.00254;
         m_measurementDirective = 1;
         break;
 
-    case INCHES:
+    case DXF_UNIT_INCHES:
     default:
         m_unitScalingFactor = 0.0001;
         m_measurementDirective = 0;
diff --git a/include/plotter.h b/include/plotter.h
index 7cdec2e1a..a30043b0f 100644
--- a/include/plotter.h
+++ b/include/plotter.h
@@ -1259,7 +1259,7 @@ public:
         textAsLines = true;
         m_currentColor = COLOR4D::BLACK;
         m_currentLineType = 0;
-        SetUnits( DXF_PLOTTER::INCHES );
+        SetUnits( DXF_PLOTTER::DXF_UNIT_INCHES );
     }
 
     virtual PlotFormat GetPlotterType() const override
@@ -1343,11 +1343,11 @@ public:
                        void* aData = NULL ) override;
 
 
-    // Should be the same order as in the PCB_PLOT_PARAMS class
-    enum Units
+    // Must be in the same order as the drop-down list in the plot dialog inside pcbnew
+    enum DXF_UNITS
     {
-        INCHES = 0,
-        MILIMETERS = 1
+        DXF_UNIT_INCHES = 0,
+        DXF_UNIT_MILLIMETERS = 1
     };
 
     /**
@@ -1355,14 +1355,14 @@ public:
      *
      * @param aUnit - The units to use
      */
-    void SetUnits( Units aUnit );
+    void SetUnits( DXF_UNITS aUnit );
 
     /**
      * The units currently enabled for plotting
      *
      * @return The currently configured units
      */
-    Units GetUnits() const
+    DXF_UNITS GetUnits() const
     {
         return m_plotUnits;
     }
@@ -1393,7 +1393,7 @@ protected:
     COLOR4D m_currentColor;
     int m_currentLineType;
 
-    Units        m_plotUnits;
+    DXF_UNITS    m_plotUnits;
     double       m_unitScalingFactor;
     unsigned int m_measurementDirective;
 };
diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp
index ae984151f..b59f99388 100644
--- a/pcbnew/dialogs/dialog_plot.cpp
+++ b/pcbnew/dialogs/dialog_plot.cpp
@@ -575,7 +575,7 @@ void DIALOG_PLOT::applyPlotSettings()
     tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
     tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
     tempOptions.SetDXFPlotUnits(
-            static_cast<PCB_PLOT_PARAMS::Units>( m_DXF_plotUnits->GetSelection() ) );
+            static_cast<DXF_PLOTTER::DXF_UNITS>( m_DXF_plotUnits->GetSelection() ) );
     tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
 
     if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )     // Currently, only DXF supports this option
diff --git a/pcbnew/pcb_plot_params.cpp b/pcbnew/pcb_plot_params.cpp
index 077935259..9e03c76ba 100644
--- a/pcbnew/pcb_plot_params.cpp
+++ b/pcbnew/pcb_plot_params.cpp
@@ -103,7 +103,7 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
     m_plotViaOnMaskLayer         = false;
     m_plotMode                   = FILLED;
     m_DXFplotPolygonMode         = true;
-    m_DXFplotUnits               = INCHES;
+    m_DXFplotUnits               = DXF_PLOTTER::DXF_UNIT_INCHES;
     m_useAuxOrigin               = false;
     m_HPGLPenNum                 = 1;
     m_HPGLPenSpeed               = 20;        // this param is always in cm/s
diff --git a/pcbnew/pcb_plot_params.h b/pcbnew/pcb_plot_params.h
index cd92a8081..14d028761 100644
--- a/pcbnew/pcb_plot_params.h
+++ b/pcbnew/pcb_plot_params.h
@@ -44,13 +44,6 @@ public:
         FULL_DRILL_SHAPE  = 2
     };
 
-    // Must be in the same order as the drop-down list in the plot dialog
-    enum Units
-    {
-        INCHES = 0,
-        MILIMETERS = 1,
-    };
-
 private:
     // If true, do not plot NPTH pads
     // (mainly used to disable NPTH pads plotting on copper layers)
@@ -70,7 +63,7 @@ private:
     /**
      * DXF format: Units to use when plotting the DXF
      */
-    Units       m_DXFplotUnits;
+    DXF_PLOTTER::DXF_UNITS m_DXFplotUnits;
 
     /// Plot format type (chooses the driver to be used)
     PlotFormat  m_format;
@@ -208,12 +201,12 @@ public:
     void        SetDXFPlotPolygonMode( bool aFlag ) { m_DXFplotPolygonMode = aFlag; }
     bool        GetDXFPlotPolygonMode() const { return m_DXFplotPolygonMode; }
 
-    void SetDXFPlotUnits( Units aUnit )
+    void SetDXFPlotUnits( DXF_PLOTTER::DXF_UNITS aUnit )
     {
         m_DXFplotUnits = aUnit;
     }
 
-    Units GetDXFPlotUnits() const
+    DXF_PLOTTER::DXF_UNITS GetDXFPlotUnits() const
     {
         return m_DXFplotUnits;
     }
diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index 2862b99a9..9a9f0ba7f 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -1029,7 +1029,8 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts,
     case PLOT_FORMAT_DXF:
         DXF_PLOTTER* DXF_plotter;
         DXF_plotter = new DXF_PLOTTER();
-        DXF_plotter->SetUnits( static_cast<DXF_PLOTTER::Units>( aPlotOpts->GetDXFPlotUnits() ) );
+        DXF_plotter->SetUnits(
+                static_cast<DXF_PLOTTER::DXF_UNITS>( aPlotOpts->GetDXFPlotUnits() ) );
 
         plotter = DXF_plotter;
         break;
-- 
2.21.0


Follow ups

References