From 51e99bd73ab292a706701b072166c16874284a09 Mon Sep 17 00:00:00 2001
From: ian <i.roth@rfproductsinc.com>
Date: Thu, 8 Sep 2016 10:20:47 -0400
Subject: [PATCH] Print layer name in pcbnew printing.

---
 common/dialogs/dialog_page_settings.cpp            |  2 +-
 common/worksheet.cpp                               | 11 +++++++++--
 eeschema/dialogs/dialog_print_using_printer.cpp    |  2 +-
 eeschema/eeredraw.cpp                              |  2 +-
 eeschema/schframe.cpp                              |  2 +-
 gerbview/draw_gerber_screen.cpp                    |  2 +-
 gerbview/printout_control.cpp                      |  6 +++---
 include/draw_frame.h                               |  4 +++-
 include/worksheet.h                                |  2 ++
 include/worksheet_shape_builder.h                  | 10 ++++++++++
 pagelayout_editor/dialogs/dialogs_for_printing.cpp |  3 ++-
 pagelayout_editor/pl_editor_frame.cpp              |  6 ++++--
 pcbnew/printout_controler.cpp                      | 14 +++++++++++---
 pcbnew/printout_controler.h                        |  2 +-
 pcbnew/tracepcb.cpp                                |  4 ++--
 15 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp
index 819d68a..6b94a70 100644
--- a/common/dialogs/dialog_page_settings.cpp
+++ b/common/dialogs/dialog_page_settings.cpp
@@ -683,7 +683,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
 
         WORKSHEET_LAYOUT::SetAltInstance( m_pagelayout );
         DrawPageLayout( &memDC, NULL, pageDUMMY,
-                        emptyString, emptyString,
+                        emptyString, emptyString, emptyString,
                         m_tb, m_screen->m_NumberOfScreens,
                         m_screen->m_ScreenNumber, 1, appScale, DARKGRAY, RED );
 
diff --git a/common/worksheet.cpp b/common/worksheet.cpp
index 3e9255d..f8487c7 100644
--- a/common/worksheet.cpp
+++ b/common/worksheet.cpp
@@ -50,6 +50,7 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
                      const PAGE_INFO& aPageInfo,
                      const wxString &aFullSheetName,
                      const wxString& aFileName,
+                     const wxString& aSheetLayer,
                      TITLE_BLOCK& aTitleBlock,
                      int aSheetCount, int aSheetNumber,
                      int aPenWidth, double aScalar,
@@ -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;
@@ -102,7 +104,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi
     }
 
     DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
-                    GetScreenDesc(), aFilename, t_block,
+                    GetScreenDesc(), aFilename, aSheetLayer, t_block,
                     aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
                     aLineWidth, aScalar, color, color );
 
@@ -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/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp
index 2a1139c..9b1a560 100644
--- a/eeschema/dialogs/dialog_print_using_printer.cpp
+++ b/eeschema/dialogs/dialog_print_using_printer.cpp
@@ -461,7 +461,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen )
 
     if( printReference )
         m_parent->DrawWorkSheet( dc, aScreen, GetDefaultLineThickness(),
-                IU_PER_MILS, aScreen->GetFileName() );
+                IU_PER_MILS, aScreen->GetFileName(), wxEmptyString );
 
     m_parent->SetDrawBgColor( bg_color );
     aScreen->m_IsPrinting = false;
diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp
index 7f0899d..1c6607b 100644
--- a/eeschema/eeredraw.cpp
+++ b/eeschema/eeredraw.cpp
@@ -61,7 +61,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
     GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE );
 
     DrawWorkSheet( DC, GetScreen(), GetDefaultLineThickness(), IU_PER_MILS,
-                    GetScreen()->GetFileName() );
+                    GetScreen()->GetFileName(), wxEmptyString );
 
 #ifdef USE_WX_OVERLAY
     if( IsShown() )
diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index 344342f..9d856ad 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -1215,7 +1215,7 @@ void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMod
     wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() );
 
     GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE );
-    DrawWorkSheet( aDC, GetScreen(), GetDefaultLineThickness(), IU_PER_MILS, fileName );
+    DrawWorkSheet( aDC, GetScreen(), GetDefaultLineThickness(), IU_PER_MILS, fileName, wxEmptyString );
 }
 
 
diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp
index d43c923..2d7f38b 100644
--- a/gerbview/draw_gerber_screen.cpp
+++ b/gerbview/draw_gerber_screen.cpp
@@ -129,7 +129,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
     // layer mainly in COPY mode
     m_canvas->DrawBackGround( DC );
 
-    DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString );
+    DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString, wxEmptyString );
 
 #ifdef USE_WX_OVERLAY
     if( IsShown() )
diff --git a/gerbview/printout_control.cpp b/gerbview/printout_control.cpp
index 9098cdd..0f144e1 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 )
 {
     wxPoint       offset;
     double        userscale;
@@ -224,7 +224,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, wxEmptyString );
 
     if( printMirror )
     {
diff --git a/include/draw_frame.h b/include/draw_frame.h
index 1913c52..a47f6f4 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 );
 
     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..29b18ca 100644
--- a/include/worksheet.h
+++ b/include/worksheet.h
@@ -42,6 +42,7 @@ class TITLE_BLOCK;
  * @param aPageInfo for margins and page size (in mils).
  * @param aFullSheetName The sheetpath (full sheet name), for basic inscriptions.
  * @param aFileName The file name, for basic inscriptions.
+ * @param aSheetLayer The layer from pcbnew.
  * @param aTitleBlock The sheet title block, for basic inscriptions.
  * @param aSheetCount The number of sheets (for basic inscriptions).
  * @param aSheetNumber The sheet number (for basic inscriptions).
@@ -59,6 +60,7 @@ void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
                      const PAGE_INFO& aPageInfo,
                      const wxString &aFullSheetName,
                      const wxString& aFileName,
+                     const wxString& aSheetLayer,
                      TITLE_BLOCK& aTitleBlock,
                      int aSheetCount, int aSheetNumber,
                      int aPenWidth, double aScalar,
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/pagelayout_editor/dialogs/dialogs_for_printing.cpp b/pagelayout_editor/dialogs/dialogs_for_printing.cpp
index 5ed93f4..2b22e66 100644
--- a/pagelayout_editor/dialogs/dialogs_for_printing.cpp
+++ b/pagelayout_editor/dialogs/dialogs_for_printing.cpp
@@ -190,7 +190,8 @@ void PLEDITOR_PRINTOUT::DrawPage( int aPageNum )
     m_parent->SetDrawBgColor( WHITE );
 
     screen->m_ScreenNumber = aPageNum;
-    m_parent->DrawWorkSheet( dc, screen, 0, IU_PER_MILS, wxEmptyString );
+    m_parent->DrawWorkSheet( dc, screen, 0, IU_PER_MILS, wxEmptyString,
+                             wxEmptyString );
 
     m_parent->SetDrawBgColor( bg_color );
     screen->m_IsPrinting = false;
diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp
index c305e79..17b50bf 100644
--- a/pagelayout_editor/pl_editor_frame.cpp
+++ b/pagelayout_editor/pl_editor_frame.cpp
@@ -510,7 +510,8 @@ void PL_EDITOR_FRAME::PrintPage( wxDC* aDC, LSET aPrintMasklayer,
                            bool aPrintMirrorMode, void * aData )
 {
     GetScreen()-> m_ScreenNumber = GetPageNumberOption() ? 1 : 2;
-    DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, wxEmptyString );
+    DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, wxEmptyString,
+                   wxEmptyString );
 }
 
 void PL_EDITOR_FRAME::RedrawActiveWindow( wxDC* aDC, bool aEraseBg )
@@ -542,7 +543,8 @@ void PL_EDITOR_FRAME::RedrawActiveWindow( wxDC* aDC, bool aEraseBg )
         item->SetSelected( item == selecteditem );
     }
 
-    DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, GetCurrFileName() );
+    DrawWorkSheet( aDC, GetScreen(), 0, IU_PER_MILS, GetCurrFileName(),
+                   wxEmptyString );
 
 #ifdef USE_WX_OVERLAY
     if( IsShown() )
diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp
index 7ad346f..72855e3 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 )
 {
     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
diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp
index 56b3a8b..cfbfad4 100644
--- a/pcbnew/tracepcb.cpp
+++ b/pcbnew/tracepcb.cpp
@@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
     GRSetDrawMode( DC, GR_COPY );
 
     m_canvas->DrawBackGround( DC );
-    DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString );
+    DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString, wxEmptyString );
 
     // Redraw the footprints
     for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
@@ -106,7 +106,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
     m_canvas->DrawBackGround( DC );
 
     DrawWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness,
-                    IU_PER_MILS, GetBoard()->GetFileName() );
+                    IU_PER_MILS, GetBoard()->GetFileName(), wxEmptyString );
 
     GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST );
 
-- 
2.6.6

