KiCad PCB EDA Suite
draw_gerber_screen.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 Jean-Pierre Charras, jpierre.charras at wanadoo
5  * Copyright (C) 2013-2015 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <gr_basic.h>
33 #include <common.h>
34 #include <class_drawpanel.h>
35 #include <drawtxt.h>
36 #include <base_units.h>
37 
38 #include <gerbview.h>
39 #include <gerbview_frame.h>
42 #include <printout_controler.h>
43 
44 
45 void GERBVIEW_FRAME::PrintPage( wxDC* aDC, LSET aPrintMasklayer,
46  bool aPrintMirrorMode, void* aData )
47 {
48  wxCHECK_RET( aData != NULL, wxT( "aData cannot be NULL." ) );
49 
50  PRINT_PARAMETERS* printParameters = (PRINT_PARAMETERS*) aData;
51 
52  // Build a suitable draw options for printing:
53  GBR_DISPLAY_OPTIONS displayOptions;
54  displayOptions.m_DisplayFlashedItemsFill = true;
55  displayOptions.m_DisplayLinesFill = true;
56  displayOptions.m_DisplayPolygonsFill = true;
57  displayOptions.m_DisplayDCodes = false;
58  displayOptions.m_IsPrinting = true;
59  displayOptions.m_ForceBlackAndWhite = printParameters->m_Print_Black_and_White;
60  displayOptions.m_NegativeDrawColor = GetDrawBgColor();
61  displayOptions.m_BgDrawColor = GetDrawBgColor();
62 
63  // Find the graphic layer to be printed
64  int page_number = printParameters->m_Flags; // contains the page number (not necessarily graphic layer number)
65 
66  // Find the graphic layer number for the printed page (search through the mask and count bits)
67  std::vector<int> printList = GetGerberLayout()->GetPrintableLayers();
68 
69  if( printList.size() < 1 )
70  return;
71 
72  int graphiclayer = printList[page_number-1];
73 
74  // In Gerbview, only one graphic layer is printed by page.
75  // So we temporary set the graphic layer list to print with only one layer id
77  GetGerberLayout()->AddLayerToPrintableList( graphiclayer );
78  m_canvas->SetPrintMirrored( aPrintMirrorMode );
79 
81  wxPoint( 0, 0 ), &displayOptions );
82 
83  m_canvas->SetPrintMirrored( false );
84 
85  // Restore the list of printable graphic layers list:
86  GetGerberLayout()->SetPrintableLayers( printList );
87 }
88 
89 
90 void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
91 {
92  GBR_SCREEN* screen = (GBR_SCREEN*) GetScreen();
93 
94  if( !GetGerberLayout() )
95  return;
96 
97  wxBusyCursor dummy;
98 
100 
101  switch( GetDisplayMode() )
102  {
103  default:
104  case 0:
105  break;
106 
107  case 1:
108  drawMode = GR_COPY;
109  break;
110 
111  case 2:
112  drawMode = GR_OR;
113  break;
114  }
115 
116  // Draw according to the current setting. This needs to be GR_COPY or GR_OR.
119  GetGerberLayout()->Draw( m_canvas, DC, drawMode, wxPoint( 0, 0 ), &m_DisplayOptions );
120 
122  {
124  GetGerberLayout()->DrawItemsDCodeID( m_canvas, DC, GR_COPY, dcode_color );
125  }
126 
127  // Draw the "background" now, i.e. grid and axis after gerber layers
128  // because most of time the actual background is erased by successive drawings of each gerber
129  // layer mainly in COPY mode
130  m_canvas->DrawBackGround( DC );
131 
132  DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString );
133 
134 #ifdef USE_WX_OVERLAY
135  if( IsShown() )
136  {
137  m_overlay.Reset();
138  wxDCOverlay overlaydc( m_overlay, (wxWindowDC*)DC );
139  overlaydc.Clear();
140  }
141 #endif
142 
143  if( m_canvas->IsMouseCaptured() )
144  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
145 
146  m_canvas->DrawCrossHair( DC );
147 }
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
Board print handler definition file.
Implementation of conversion functions that require both schematic and board internal units...
int GetDisplayMode()
Function GetDisplayMode.
void AddLayerToPrintableList(int aLayer)
Function AddLayerToPrintableList.
COLOR4D m_BgDrawColor
The background color.
void SetPrintableLayers(const std::vector< int > &aLayerList)
Function SetPrintableLayers changes the list of printable layers.
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:216
Class PRINT_PARAMETERS handles the parameters used to print a board drawing.
std::vector< int > GetPrintableLayers()
Function GetPrintableLayers.
void DrawItemsDCodeID(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aDrawColor)
Function DrawItemsDCodeID Draw the DCode value (if exists) corresponding to gerber item (polygons do ...
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
COLOR4D m_NegativeDrawColor
The color used to draw negative objects, usually the background color, but not always, when negative objects must be visible.
void ClearPrintableLayers()
Function ClearPrintableLayers.
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:309
Class LSET is a set of LAYER_IDs.
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:286
bool m_ForceBlackAndWhite
Option print in blackand white (ont used id draw mode.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsMouseCaptured() const
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
GBR_LAYOUT * GetGerberLayout() const
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Definition: gr_basic.h:42
COLOR4D GetNegativeItemsColor() const
Function GetNegativeItemsColor.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
The common library.
void SetPrintMirrored(bool aMirror)
This file is part of the common libary.
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:666
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Function DrawWorkSheet Draws on screen the page layout with the frame and the basic inscriptions...
Definition: worksheet.cpp:77
COLOR4D GetVisibleElementColor(GERBER_VISIBLE_ID aItemIdVisible) const
Function GetVisibleElementColor returns the color of a gerber visible element.
virtual void PrintPage(wxDC *aDC, LSET aPrintMasklayer, bool aPrintMirrorMode, void *aData=NULL) override
Virtual function PrintPage used to print a page.
bool m_IsPrinting
true when printing a page, false when drawing on screen
bool m_DisplayDCodes
Option to show dcode values on items drawn with a dcode tool.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset, GBR_DISPLAY_OPTIONS *aDisplayOptions)
Function Draw.