← Back to team overview

kicad-developers team mailing list archive

[PATCH] Layer order in SVG export, bug 1286646

 

Hello veryone,

Attached is a patch that creates an SVG file with the layers ordered from
bottom to top. This fixes bug 1286646.

This patch also stores that two options in the configuration file ("Print
mirrored" and "File option"); these two were previously forgotten when you
closed the "Export SVG file" dialog.

Regards,
Thiadmer Riemersma
=== modified file 'common/lset.cpp'
--- common/lset.cpp	2014-07-06 16:59:26 +0000
+++ common/lset.cpp	2014-08-08 09:49:32 +0000
@@ -381,6 +381,66 @@
 }
 
 
+LSEQ LSET::SeqStackup() const
+{
+    // bottom-to-top stack-up
+    static const LAYER_ID sequence[] = {
+        B_Adhes,
+        B_Paste,
+        B_SilkS,
+        B_Fab,
+        B_CrtYd,
+        B_Mask,
+        B_Cu,
+        In30_Cu,
+        In29_Cu,
+        In28_Cu,
+        In27_Cu,
+        In26_Cu,
+        In25_Cu,
+        In24_Cu,
+        In23_Cu,
+        In22_Cu,
+        In21_Cu,
+        In20_Cu,
+        In19_Cu,
+        In18_Cu,
+        In17_Cu,
+        In16_Cu,
+        In15_Cu,
+        In14_Cu,
+        In13_Cu,
+        In12_Cu,
+        In11_Cu,
+        In10_Cu,
+        In9_Cu,
+        In8_Cu,
+        In7_Cu,
+        In6_Cu,
+        In5_Cu,
+        In4_Cu,
+        In3_Cu,
+        In2_Cu,
+        In1_Cu,
+        F_Cu,
+        F_Mask,
+        F_CrtYd,
+        F_Fab,
+        F_SilkS,
+        F_Paste,
+        F_Adhes,
+        Dwgs_User,
+        Cmts_User,
+        Eco1_User,
+        Eco2_User,
+        Margin,
+        Edge_Cuts,
+    };
+
+    return Seq( sequence, DIM( sequence ) );
+}
+
+
 LAYER_ID FlipLayer( LAYER_ID aLayerId )
 {
     switch( aLayerId )

=== modified file 'include/layers_id_colors_and_visibility.h'
--- include/layers_id_colors_and_visibility.h	2014-08-02 10:29:10 +0000
+++ include/layers_id_colors_and_visibility.h	2014-08-08 09:50:10 +0000
@@ -367,11 +367,11 @@
     LSEQ Seq() const;
 
     /**
-     * Function SVG
-     * returns the sequence used to output an SVG plot.
-    LSEQ SVG() const;
-     put this in the needed source file using Seq() there.
-    */
+     * Function SeqStackup
+     * returns the sequence that is typical for a bottom-to-top stack-up (for
+     * example, to use for plotting multiple layers in a single image).
+     */
+    LSEQ SeqStackup() const;
 
     /**
      * Function FmtHex

=== modified file 'pcbnew/dialogs/dialog_SVG_print.cpp'
--- pcbnew/dialogs/dialog_SVG_print.cpp	2014-07-23 13:01:23 +0000
+++ pcbnew/dialogs/dialog_SVG_print.cpp	2014-08-08 09:55:54 +0000
@@ -62,10 +62,8 @@
     wxCheckBox*     m_boxSelectLayer[LAYER_ID_COUNT];
     bool            m_printBW;
     wxString        m_outputDirectory;
-
-    // Static member to store options
-    static bool     m_printMirror;
-    static bool     m_oneFileOnly;
+    bool            m_printMirror;
+    bool            m_oneFileOnly;
 
     void initDialog();
 
@@ -88,7 +86,7 @@
         return m_rbSvgPageSizeOpt->GetSelection() == 0;
     }
 
-    bool CreateSVGFile( const wxString& FullFileName );
+    bool CreateSVGFile( const wxString& FullFileName, bool aOnlyOneFile );
 
     LSET getCheckBoxSelectedLayers() const;
 };
@@ -97,6 +95,8 @@
 
 // Keys for configuration
 #define PLOTSVGMODECOLOR_KEY        wxT( "PlotSVGModeColor" )
+#define PLOTSVGMODEMIRROR_KEY       wxT( "PlotSVGModeMirror" )
+#define PLOTSVGMODEONEFILE_KEY      wxT( "PlotSVGModeOneFile" )
 #define PLOTSVGPAGESIZEOPT_KEY      wxT( "PlotSVGPageOpt" )
 #define PLOTSVGPLOT_BRD_EDGE_KEY    wxT( "PlotSVGBrdEdge" )
 
@@ -125,9 +125,6 @@
     Centre();
 }
 
-bool DIALOG_SVG_PRINT::m_printMirror = false;
-bool DIALOG_SVG_PRINT::m_oneFileOnly = false;
-
 
 void DIALOG_SVG_PRINT::initDialog()
 {
@@ -136,6 +133,8 @@
         m_config->Read( PLOTSVGMODECOLOR_KEY, &m_printBW, false );
         long ltmp;
         m_config->Read( PLOTSVGPAGESIZEOPT_KEY, &ltmp, 0 );
+        m_config->Read( PLOTSVGMODEMIRROR_KEY, &m_printMirror, false );
+        m_config->Read( PLOTSVGMODEONEFILE_KEY, &m_oneFileOnly, false);
         m_rbSvgPageSizeOpt->SetSelection( ltmp );
         m_config->Read( PLOTSVGPLOT_BRD_EDGE_KEY, &ltmp, 1 );
         m_PrintBoardEdgesCtrl->SetValue( ltmp );
@@ -144,11 +143,7 @@
     m_outputDirectory = m_callers_params->GetOutputDirectory();
     m_outputDirectoryName->SetValue( m_outputDirectory );
 
-    if( m_printBW )
-        m_ModeColorOption->SetSelection( 1 );
-    else
-        m_ModeColorOption->SetSelection( 0 );
-
+    m_ModeColorOption->SetSelection( m_printBW ? 1 : 0 );
     m_printMirrorOpt->SetValue( m_printMirror );
     m_rbFileOpt->SetSelection( m_oneFileOnly ? 1 : 0 );
 
@@ -307,7 +302,7 @@
         if( m_PrintBoardEdgesCtrl->IsChecked() )
             m_printMaskLayer.set( Edge_Cuts );
 
-        if( CreateSVGFile( fn.GetFullPath() ) )
+        if( CreateSVGFile( fn.GetFullPath(), aOnlyOneFile ) )
         {
             m_messagesBox->AppendText(
                     wxString::Format( _( "Plot: '%s' OK\n" ), GetChars( fn.GetFullPath() ) )
@@ -327,7 +322,7 @@
 
 
 // Actual SVG file export  function.
-bool DIALOG_SVG_PRINT::CreateSVGFile( const wxString& aFullFileName )
+bool DIALOG_SVG_PRINT::CreateSVGFile( const wxString& aFullFileName, bool aOnlyOneFile )
 {
     PCB_PLOT_PARAMS plot_opts;
 
@@ -372,15 +367,22 @@
 
     if( plotter )
     {
-        plotter->SetColorMode( m_ModeColorOption->GetSelection() == 0 );
-        PlotStandardLayer( m_board, plotter, m_printMaskLayer, plot_opts );
+        plotter->SetColorMode( !m_printBW );
+        if( aOnlyOneFile )
+        {
+            for( LSEQ seq = m_printMaskLayer.SeqStackup();  seq;  ++seq )
+                PlotOneBoardLayer( m_board, plotter, *seq, plot_opts );
+        }
+        else
+        {
+            PlotStandardLayer( m_board, plotter, m_printMaskLayer, plot_opts );
+        }
         plotter->EndPlot();
     }
 
     delete plotter;
 
-    m_board->SetAuxOrigin( axisorigin );        // really, without a message saying so?
-
+    m_board->SetAuxOrigin( axisorigin );        // reset to the values saved earlier
     m_board->SetPageSettings( pageInfo );
 
     return true;
@@ -410,10 +412,9 @@
         m_printBW = m_ModeColorOption->GetSelection();
         m_oneFileOnly = m_rbFileOpt->GetSelection() == 1;
 
-        // 1) Why is configuration data saved in two places: m_config and PCB_PLOT_OPTIONS?
-        // 2) Why are SVG layer choices co-mingled with other plot layer choices in the config file?
-        //    The string OPTKEY_LAYERBASE is used in multiple places.
-        // fix these.
+        // Why are SVG layer choices co-mingled with other plot layer choices in the config file?
+        // The string OPTKEY_LAYERBASE is used in multiple places.
+        // fix this.
 
         wxString dirStr = m_outputDirectoryName->GetValue();
         dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
@@ -423,6 +424,8 @@
         if( m_config )
         {
             m_config->Write( PLOTSVGMODECOLOR_KEY, m_printBW );
+            m_config->Write( PLOTSVGMODEMIRROR_KEY, m_printMirror );
+            m_config->Write( PLOTSVGMODEONEFILE_KEY, m_oneFileOnly );
             m_config->Write( PLOTSVGPAGESIZEOPT_KEY, m_rbSvgPageSizeOpt->GetSelection() );
             m_config->Write( PLOTSVGPLOT_BRD_EDGE_KEY, m_PrintBoardEdgesCtrl->GetValue() );
 

=== modified file 'pcbnew/dialogs/dialog_SVG_print_base.cpp'
--- pcbnew/dialogs/dialog_SVG_print_base.cpp	2014-06-30 19:19:58 +0000
+++ pcbnew/dialogs/dialog_SVG_print_base.cpp	2014-08-08 09:58:09 +0000
@@ -89,6 +89,8 @@
 	sbOptionsSizer->Add( m_PrintBoardEdgesCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
 	
 	m_printMirrorOpt = new wxCheckBox( this, wxID_ANY, _("Print mirrored"), wxDefaultPosition, wxDefaultSize, 0 );
+	m_printMirrorOpt->SetToolTip( _("Print the layer(s) horizontally mirrored") );
+	
 	sbOptionsSizer->Add( m_printMirrorOpt, 0, wxRIGHT|wxLEFT, 5 );
 	
 	

=== modified file 'pcbnew/dialogs/dialog_SVG_print_base.fbp'
--- pcbnew/dialogs/dialog_SVG_print_base.fbp	2014-06-30 19:19:58 +0000
+++ pcbnew/dialogs/dialog_SVG_print_base.fbp	2014-08-08 09:58:51 +0000
@@ -925,7 +925,7 @@
                                         <property name="style"></property>
                                         <property name="subclass"></property>
                                         <property name="toolbar_pane">0</property>
-                                        <property name="tooltip"></property>
+                                        <property name="tooltip">Print the layer(s) horizontally mirrored</property>
                                         <property name="validator_data_type"></property>
                                         <property name="validator_style">wxFILTER_NONE</property>
                                         <property name="validator_type">wxDefaultValidator</property>

=== modified file 'pcbnew/pcbplot.cpp'
--- pcbnew/pcbplot.cpp	2014-07-29 16:38:27 +0000
+++ pcbnew/pcbplot.cpp	2014-08-08 10:01:59 +0000
@@ -334,7 +334,7 @@
         return false;
 
     // Fully delegated to the parent
-    PlotOneBoardLayer( m_board, m_plotter, aLayer, m_plotOpts );
+    PlotOneBoardLayer( m_board, m_plotter, ToLAYER_ID( aLayer ), m_plotOpts );
 
     return true;
 }

=== modified file 'pcbnew/pcbplot.h'
--- pcbnew/pcbplot.h	2014-06-30 05:46:18 +0000
+++ pcbnew/pcbplot.h	2014-08-08 10:02:19 +0000
@@ -176,7 +176,7 @@
  * @param aLayer = the layer id to plot
  * @param aPlotOpt = the plot options (files, sketch). Has meaning for some formats only
  */
-void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_NUM aLayer,
+void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_ID aLayer,
                         const PCB_PLOT_PARAMS& aPlotOpt );
 
 /**

=== modified file 'pcbnew/plot_board_layers.cpp'
--- pcbnew/plot_board_layers.cpp	2014-07-04 14:22:38 +0000
+++ pcbnew/plot_board_layers.cpp	2014-08-08 10:03:00 +0000
@@ -142,7 +142,7 @@
     }
 }
 
-void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_NUM aLayer,
+void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_ID aLayer,
                      const PCB_PLOT_PARAMS& aPlotOpt )
 {
     PCB_PLOT_PARAMS plotOpt = aPlotOpt;
@@ -154,7 +154,7 @@
 
     // Specify that the contents of the "Edges Pcb" layer are to be plotted
     // in addition to the contents of the currently specified layer.
-    LSET    layer_mask( ToLAYER_ID( aLayer ) );
+    LSET    layer_mask( aLayer );
 
     if( !aPlotOpt.GetExcludeEdgeLayer() )
         layer_mask.set( Edge_Cuts );


Follow ups