Date: Sat, 10 Sep 2016 13:31:59 -0400
Subject: [PATCH 1/2] Add %L formatter for the layer name on pcb prints.

---
 common/worksheet.cpp              | 13 ++++++++++---
 gerbview/printout_control.cpp     |  4 ++--
 include/draw_frame.h              |  4 +++-
 include/worksheet.h               |  4 +++-
 include/worksheet_shape_builder.h | 10 ++++++++++
 pcbnew/printout_controler.cpp     | 14 +++++++++++---
 pcbnew/printout_controler.h       |  2 +-
 7 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/common/worksheet.cpp b/common/worksheet.cpp
index 3e9255d..3453141 100644
--- a/common/worksheet.cpp
+++ b/common/worksheet.cpp
@@ -53,7 +53,8 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
                      TITLE_BLOCK& aTitleBlock,
                      int aSheetCount, int aSheetNumber,
                      int aPenWidth, double aScalar,
-                     EDA_COLOR_T aColor, EDA_COLOR_T aAltColor )
+                     EDA_COLOR_T aColor, EDA_COLOR_T aAltColor,
+                     const wxString& aSheetLayer )
 {
     WS_DRAW_ITEM_LIST drawList;
 
@@ -63,6 +64,7 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
     drawList.SetSheetCount( aSheetCount );
     drawList.SetFileName( aFileName );
     drawList.SetSheetName( aFullSheetName );
+    drawList.SetSheetLayer( aSheetLayer );
 
     drawList.BuildWorkSheetGraphicList( aPageInfo,
                                aTitleBlock, aColor, aAltColor );
@@ -73,7 +75,7 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
 
 
 void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
-                                     double aScalar, const wxString &aFilename )
+                                     double aScalar, const wxString &aFilename,                                      const wxString &aSheetLayer )
 {
     if( !m_showBorderAndTitleBlock )
         return;
@@ -104,7 +106,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi
     DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
                     GetScreenDesc(), aFilename, t_block,
                     aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
-                    aLineWidth, aScalar, color, color );
+                    aLineWidth, aScalar, color, color, aSheetLayer );
 
     if( aScreen->m_IsPrinting && origin.y > 0 )
     {
@@ -136,6 +138,7 @@ wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
      * %R = revision
      * %S = sheet number
      * %N = number of sheets
+     * %L = layer name
      * %Cx = comment (x = 0 to 9 to identify the comment)
      * %F = filename
      * %P = sheet path (sheet full name)
@@ -192,6 +195,10 @@ wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
                 }
                 break;
 
+            case 'L':
+                msg += *m_sheetLayer;
+                break;
+
             case 'P':
                 msg += *m_sheetFullName;
                 break;
diff --git a/gerbview/printout_control.cpp b/gerbview/printout_control.cpp
index 9098cdd..74f35aa 100644
--- a/gerbview/printout_control.cpp
+++ b/gerbview/printout_control.cpp
@@ -77,7 +77,7 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
     // in gerbview, draw layers are always printed on separate pages
     // because handling negative objects when using only one page is tricky
     m_PrintParams.m_Flags = aPage;
-    DrawPage();
+    DrawPage( wxEmptyString );
 
     return true;
 }
@@ -99,7 +99,7 @@ void BOARD_PRINTOUT_CONTROLLER::GetPageInfo( int* minPage, int* maxPage,
 }
 
 
-void BOARD_PRINTOUT_CONTROLLER::DrawPage()
+void BOARD_PRINTOUT_CONTROLLER::DrawPage( wxString layer = wxEmptyString )
 {
     wxPoint       offset;
     double        userscale;
diff --git a/include/draw_frame.h b/include/draw_frame.h
index 1913c52..2a65c7d 100644
--- a/include/draw_frame.h
+++ b/include/draw_frame.h
@@ -593,9 +593,11 @@ public:
      * @param aLineWidth The pen width to use to draw the layout.
      * @param aScale The mils to Iu conversion factor.
      * @param aFilename The filename to display in basic inscriptions.
+     * @param aSheetLayer The layer displayed from pcbnew.
      */
     void DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
-                         double aScale, const wxString &aFilename );
+                         double aScale, const wxString &aFilename,
+                         const wxString &aSheetLayer = wxEmptyString );
 
     void            DisplayToolMsg( const wxString& msg );
     virtual void    RedrawActiveWindow( wxDC* DC, bool EraseBg ) = 0;
diff --git a/include/worksheet.h b/include/worksheet.h
index 985f77d..fbd53cb 100644
--- a/include/worksheet.h
+++ b/include/worksheet.h
@@ -49,6 +49,7 @@ class TITLE_BLOCK;
  * @param aScalar the scale factor to convert from mils to internal units.
  * @param aColor The color for drawing.
  * @param aAltColor The color for items which need to be "hightlighted".
+ * @param aSheetLayer The layer from pcbnew.
  *
  * Parameters used in aPageInfo
  * - the size of the page layout.
@@ -62,7 +63,8 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
                      TITLE_BLOCK& aTitleBlock,
                      int aSheetCount, int aSheetNumber,
                      int aPenWidth, double aScalar,
-                     EDA_COLOR_T aColor, EDA_COLOR_T aAltColor );
+                     EDA_COLOR_T aColor, EDA_COLOR_T aAltColor,
+                     const wxString& aSheetLayer = wxEmptyString );
 
 
 #endif // WORKSHEET_H_
diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h
index 6ff408e..bd9af9a 100644
--- a/include/worksheet_shape_builder.h
+++ b/include/worksheet_shape_builder.h
@@ -384,6 +384,7 @@ protected:
     const wxString* m_paperFormat;      // for basic inscriptions
     wxString        m_fileName;         // for basic inscriptions
     const wxString* m_sheetFullName;    // for basic inscriptions
+    const wxString* m_sheetLayer;       // for basic inscriptions
 
 
 public:
@@ -423,6 +424,15 @@ public:
         m_sheetFullName = &aSheetName;
     }
 
+    /**
+     * Set the sheet layer to draw/plot
+     * @param aSheetLayer = the text to draw/plot by the "sheetlayer" format
+     */
+    void SetSheetLayer( const wxString & aSheetLayer )
+    {
+        m_sheetLayer = &aSheetLayer;
+    }
+
     /** Function SetPenSize
      * Set the default pen size to draw/plot lines and texts
      * @param aPenSize the thickness of lines
diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp
index 7ad346f..c7b9775 100644
--- a/pcbnew/printout_controler.cpp
+++ b/pcbnew/printout_controler.cpp
@@ -84,6 +84,8 @@ BOARD_PRINTOUT_CONTROLLER::BOARD_PRINTOUT_CONTROLLER( const PRINT_PARAMETERS& aP
 bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
 {
     LSET lset = m_PrintParams.m_PrintMaskLayer;
+    wxString layer;
+    LAYER_ID extractLayer;
 
     // compute layer mask from page number if we want one page per layer
     if( m_PrintParams.m_OptionPrintPage == 0 )  // One page per layer
@@ -101,11 +103,17 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
     if( !m_PrintParams.m_PrintMaskLayer.any() )
         return false;
 
+    extractLayer = m_PrintParams.m_PrintMaskLayer.ExtractLayer();
+    if( extractLayer == UNDEFINED_LAYER )
+        layer = "Multiple Layers";
+    else
+        layer = LSET::Name( extractLayer );
+
     // In Pcbnew we can want the layer EDGE always printed
     if( m_PrintParams.m_Flags == 1 )
         m_PrintParams.m_PrintMaskLayer.set( Edge_Cuts );
 
-    DrawPage();
+    DrawPage( layer );
 
     m_PrintParams.m_PrintMaskLayer = lset;
 
@@ -129,7 +137,7 @@ void BOARD_PRINTOUT_CONTROLLER::GetPageInfo( int* minPage, int* maxPage,
 }
 
 
-void BOARD_PRINTOUT_CONTROLLER::DrawPage()
+void BOARD_PRINTOUT_CONTROLLER::DrawPage( wxString layer = wxEmptyString )
 {
     wxPoint       offset;
     double        userscale;
@@ -279,7 +287,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
 
     if( m_PrintParams.PrintBorderAndTitleBlock() )
         m_Parent->DrawWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
-                                  IU_PER_MILS, titleblockFilename );
+                                  IU_PER_MILS, titleblockFilename, layer );
 
     if( printMirror )
     {
diff --git a/pcbnew/printout_controler.h b/pcbnew/printout_controler.h
index a9cd6c2..90239aa 100644
--- a/pcbnew/printout_controler.h
+++ b/pcbnew/printout_controler.h
@@ -123,7 +123,7 @@ public:
 
     void GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo );
 
-    void DrawPage();
+    void DrawPage( wxString layer );
 };
 
 #endif      // PRINTOUT_CONTROLLER_H
-- 
2.6.6


From 6eae36ec4bb48cc4ca0c1a2286e2df7e3e59f801 Mon Sep 17 00:00:00 2001
From: imr <iron_hat@hotmail.com>
Date: Sat, 10 Sep 2016 13:41:34 -0400
Subject: [PATCH 2/2] Fix source file formatting.

---
 common/worksheet.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/worksheet.cpp b/common/worksheet.cpp
index 3453141..45fcac2 100644
--- a/common/worksheet.cpp
+++ b/common/worksheet.cpp
@@ -75,7 +75,8 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
 
 
 void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
-                                     double aScalar, const wxString &aFilename,                                      const wxString &aSheetLayer )
+                                     double aScalar, const wxString &aFilename,
+                                     const wxString &aSheetLayer )
 {
     if( !m_showBorderAndTitleBlock )
         return;
-- 
2.6.6
