kicad/pcbnew/print_board_functions.cpp

414 lines
14 KiB
C++
Raw Normal View History

/**
* @file print_board_functions.cpp
* @brief Functions to print boards.
*/
#include <fctsys.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <printout_controler.h>
#include <colors_selection.h>
#include <pcbcommon.h>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <class_track.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <protos.h>
#include <pcbplot.h>
#include <module_editor_frame.h>
static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
GR_DRAWMODE aDraw_mode, int aMasklayer,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt );
void FOOTPRINT_EDIT_FRAME::PrintPage( wxDC* aDC,
int aPrintMaskLayer,
bool aPrintMirrorMode,
void * aData)
{
GR_DRAWMODE drawmode = GR_COPY;
int defaultPenSize = 50;
DISPLAY_OPTIONS save_opt;
PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null
PRINT_PARAMETERS::DrillShapeOptT drillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE;
if( printParameters )
defaultPenSize = printParameters->m_PenDefaultSize;
save_opt = DisplayOpt;
DisplayOpt.ContrastModeDisplay = false;
DisplayOpt.DisplayPadFill = true;
DisplayOpt.DisplayViaFill = true;
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
m_DisplayPadNum = DisplayOpt.DisplayPadNum = false;
bool nctmp = GetBoard()->IsElementVisible(NO_CONNECTS_VISIBLE);
GetBoard()->SetElementVisibility(NO_CONNECTS_VISIBLE, false);
DisplayOpt.DisplayPadIsol = false;
DisplayOpt.DisplayModEdge = FILLED;
DisplayOpt.DisplayModText = FILLED;
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill = FILLED;
DisplayOpt.ShowTrackClearanceMode = DO_NOT_SHOW_CLEARANCE;
DisplayOpt.DisplayDrawItems = FILLED;
DisplayOpt.DisplayZonesMode = 0;
DisplayOpt.DisplayNetNamesMode = 0;
m_canvas->SetPrintMirrored( aPrintMirrorMode );
// The OR mode is used in color mode, but be aware the background *must be
// BLACK. In the print page dialog, we first print in BLACK, and after
// reprint in color, on the black "local" background, in OR mode the black
// print is not made before, only a white page is printed
if( GetGRForceBlackPenState() == false )
drawmode = GR_OR;
// Draw footprints, this is done at last in order to print the pad holes in
// white (or g_DrawBgColor) after the tracks and zones
int tmp = D_PAD::m_PadSketchModePenSize;
D_PAD::m_PadSketchModePenSize = defaultPenSize;
wxSize pageSizeIU = GetPageSizeIU() / 2;
wxPoint offset( pageSizeIU.x, pageSizeIU.y );
for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
{
module->Move( offset );
2011-12-22 22:12:21 +00:00
Print_Module( m_canvas, aDC, module, drawmode, aPrintMaskLayer, drillShapeOpt );
module->Move( -offset );
}
D_PAD::m_PadSketchModePenSize = tmp;
m_canvas->SetPrintMirrored( false );
DisplayOpt = save_opt;
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
m_DisplayPadNum = DisplayOpt.DisplayPadNum;
GetBoard()->SetElementVisibility( NO_CONNECTS_VISIBLE, nctmp );
}
2007-08-23 04:28:46 +00:00
/**
* Function PrintPage
* is used to print the board (on printer, or when creating SVF files).
* Print the board, but only layers allowed by aPrintMaskLayer
* @param aDC = the print device context
2010-12-29 17:47:32 +00:00
* @param aPrintMaskLayer = a 32 bits mask: bit n = 1 -> layer n is printed
* @param aPrintMirrorMode = true to plot mirrored
* @param aData = a pointer to an optional data (NULL if not used)
2007-08-23 04:28:46 +00:00
*/
void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
int aPrintMaskLayer,
bool aPrintMirrorMode,
void* aData)
{
MODULE* Module;
GR_DRAWMODE drawmode = GR_COPY;
DISPLAY_OPTIONS save_opt;
TRACK* pt_trace;
BOARD* Pcb = GetBoard();
int defaultPenSize = 50;
bool onePagePerLayer = false;
PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null
if( printParameters && printParameters->m_OptionPrintPage == 0 )
onePagePerLayer = true;
PRINT_PARAMETERS::DrillShapeOptT drillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE;
if( printParameters )
{
drillShapeOpt = printParameters->m_DrillShapeOpt;
defaultPenSize = printParameters->m_PenDefaultSize;
}
2007-08-23 04:28:46 +00:00
save_opt = DisplayOpt;
int activeLayer = GetScreen()->m_Active_Layer;
DisplayOpt.ContrastModeDisplay = false;
DisplayOpt.DisplayPadFill = true;
DisplayOpt.DisplayViaFill = true;
if( (aPrintMaskLayer & ALL_CU_LAYERS) == 0 )
2009-09-29 04:44:35 +00:00
{
if( onePagePerLayer )
{ // We can print mask layers (solder mask and solder paste) with the actual
// pad sizes. To do that, we must set ContrastModeDisplay to true and set
//the GetScreen()->m_Active_Layer to the current printed layer
DisplayOpt.ContrastModeDisplay = true;
DisplayOpt.DisplayPadFill = true;
// Calculate the active layer number to print from its mask layer:
GetScreen()->m_Active_Layer = 0;
for(int kk = 0; kk < 32; kk ++ )
{
if( ((1 << kk) & aPrintMaskLayer) != 0 )
{
GetScreen()->m_Active_Layer = kk;
break;
}
}
// pads on Silkscreen layer are usually plot in sketch mode:
if( (GetScreen()->m_Active_Layer == SILKSCREEN_N_BACK)
|| (GetScreen()->m_Active_Layer == SILKSCREEN_N_FRONT) )
DisplayOpt.DisplayPadFill = false;
}
else
{
DisplayOpt.DisplayPadFill = false;
}
2009-09-29 04:44:35 +00:00
}
2009-09-29 04:44:35 +00:00
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
m_DisplayPadNum = DisplayOpt.DisplayPadNum = false;
bool nctmp = GetBoard()->IsElementVisible( NO_CONNECTS_VISIBLE );
GetBoard()->SetElementVisibility( NO_CONNECTS_VISIBLE, false );
2008-12-17 06:51:39 +00:00
DisplayOpt.DisplayPadIsol = false;
m_DisplayModEdge = DisplayOpt.DisplayModEdge = FILLED;
m_DisplayModText = DisplayOpt.DisplayModText = FILLED;
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill = FILLED;
DisplayOpt.ShowTrackClearanceMode = DO_NOT_SHOW_CLEARANCE;
DisplayOpt.DisplayDrawItems = FILLED;
DisplayOpt.DisplayZonesMode = 0;
DisplayOpt.DisplayNetNamesMode = 0;
2007-08-23 04:28:46 +00:00
m_canvas->SetPrintMirrored( aPrintMirrorMode );
// The OR mode is used in color mode, but be aware the background *must be
// BLACK. In the print page dialog, we first print in BLACK, and after
// reprint in color, on the black "local" background, in OR mode the black
// print is not made before, only a white page is printed
if( GetGRForceBlackPenState() == false )
drawmode = GR_OR;
2012-02-19 04:02:19 +00:00
// Print the pcb graphic items (texts, ...)
GRSetDrawMode( aDC, drawmode );
for( BOARD_ITEM* item = Pcb->m_Drawings; item; item = item->Next() )
2007-08-23 04:28:46 +00:00
{
2008-04-01 06:32:48 +00:00
switch( item->Type() )
2007-08-23 04:28:46 +00:00
{
case PCB_LINE_T:
case PCB_DIMENSION_T:
case PCB_TEXT_T:
case PCB_TARGET_T:
if( ( ( 1 << item->GetLayer() ) & aPrintMaskLayer ) == 0 )
2007-08-23 04:28:46 +00:00
break;
item->Draw( m_canvas, aDC, drawmode );
2007-08-23 04:28:46 +00:00
break;
case PCB_MARKER_T:
2007-08-23 04:28:46 +00:00
default:
break;
}
}
2012-02-19 04:02:19 +00:00
// Print tracks
pt_trace = Pcb->m_Track;
for( ; pt_trace != NULL; pt_trace = pt_trace->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
2012-02-19 04:02:19 +00:00
if( pt_trace->Type() == PCB_VIA_T ) // VIA encountered.
2007-08-23 04:28:46 +00:00
{
int radius = pt_trace->m_Width >> 1;
EDA_COLOR_T color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + pt_trace->m_Shape );
GRSetDrawMode( aDC, drawmode );
GRFilledCircle( m_canvas->GetClipBox(), aDC,
pt_trace->m_Start.x,
pt_trace->m_Start.y,
radius,
0, color, color );
2007-08-23 04:28:46 +00:00
}
else
{
pt_trace->Draw( m_canvas, aDC, drawmode );
}
2007-08-23 04:28:46 +00:00
}
pt_trace = Pcb->m_Zone;
for( ; pt_trace != NULL; pt_trace = pt_trace->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
pt_trace->Draw( m_canvas, aDC, drawmode );
2007-08-23 04:28:46 +00:00
}
2012-02-19 04:02:19 +00:00
// Draw filled areas (i.e. zones)
for( int ii = 0; ii < Pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* zone = Pcb->GetArea( ii );
if( ( aPrintMaskLayer & ( 1 << zone->GetLayer() ) ) == 0 )
continue;
zone->DrawFilledArea( m_canvas, aDC, drawmode );
}
// Draw footprints, this is done at last in order to print the pad holes in
// white (or g_DrawBgColor) after the tracks and zones
Module = (MODULE*) Pcb->m_Modules;
int tmp = D_PAD::m_PadSketchModePenSize;
D_PAD::m_PadSketchModePenSize = defaultPenSize;
for( ; Module != NULL; Module = Module->Next() )
{
Print_Module( m_canvas, aDC, Module, drawmode, aPrintMaskLayer, drillShapeOpt );
}
D_PAD::m_PadSketchModePenSize = tmp;
/* Print via holes in bg color: Not sure it is good for buried or blind
* vias */
if( drillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE )
2007-08-23 04:28:46 +00:00
{
pt_trace = Pcb->m_Track;
EDA_COLOR_T color = g_DrawBgColor;
bool blackpenstate = GetGRForceBlackPenState();
GRForceBlackPen( false );
GRSetDrawMode( aDC, GR_COPY );
for( ; pt_trace != NULL; pt_trace = pt_trace->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 )
continue;
2012-02-19 04:02:19 +00:00
if( pt_trace->Type() == PCB_VIA_T ) // VIA encountered.
{
int diameter;
if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
2012-08-03 15:43:15 +00:00
diameter = std::min( SMALL_DRILL, pt_trace->GetDrillValue() );
else
diameter = pt_trace->GetDrillValue();
GRFilledCircle( m_canvas->GetClipBox(), aDC,
pt_trace->m_Start.x, pt_trace->m_Start.y,
diameter/2,
0, color, color );
}
2007-08-23 04:28:46 +00:00
}
GRForceBlackPen( blackpenstate );
2007-08-23 04:28:46 +00:00
}
m_canvas->SetPrintMirrored( false );
2007-08-23 04:28:46 +00:00
DisplayOpt = save_opt;
GetScreen()->m_Active_Layer = activeLayer;
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
m_DisplayPadNum = DisplayOpt.DisplayPadNum;
m_DisplayModEdge = DisplayOpt.DisplayModEdge;
m_DisplayModText = DisplayOpt.DisplayModText;
GetBoard()->SetElementVisibility(NO_CONNECTS_VISIBLE, nctmp);
}
static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
GR_DRAWMODE aDraw_mode, int aMasklayer,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
{
2012-02-19 04:02:19 +00:00
// Print pads
for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
2012-02-19 04:02:19 +00:00
if( (pad->GetLayerMask() & aMasklayer ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
// Manage hole according to the print drill option
2012-02-19 04:02:19 +00:00
wxSize drill_tmp = pad->GetDrillSize();
2012-02-19 04:02:19 +00:00
switch( aDrillShapeOpt )
{
2012-02-19 04:02:19 +00:00
case PRINT_PARAMETERS::NO_DRILL_SHAPE:
pad->SetDrillSize( wxSize(0,0) );
break;
case PRINT_PARAMETERS::SMALL_DRILL_SHAPE:
{
2012-08-03 15:43:15 +00:00
wxSize sz( std::min( SMALL_DRILL, pad->GetDrillSize().x ),
std::min( SMALL_DRILL, pad->GetDrillSize().y ) );
2012-02-19 04:02:19 +00:00
pad->SetDrillSize( sz );
}
break;
case PRINT_PARAMETERS::FULL_DRILL_SHAPE:
// Do nothing
break;
}
2012-02-19 04:02:19 +00:00
pad->Draw( aPanel, aDC, aDraw_mode );
pad->SetDrillSize( drill_tmp );
2007-08-23 04:28:46 +00:00
}
2012-02-19 04:02:19 +00:00
// Print footprint graphic shapes
int mlayer = GetLayerMask( aModule->GetLayer() );
if( aModule->GetLayer() == LAYER_N_BACK )
mlayer = SILKSCREEN_LAYER_BACK;
else if( aModule->GetLayer() == LAYER_N_FRONT )
mlayer = SILKSCREEN_LAYER_FRONT;
2008-04-01 05:21:50 +00:00
if( mlayer & aMasklayer )
2007-08-23 04:28:46 +00:00
{
2011-12-12 08:37:05 +00:00
if( aModule->m_Reference->IsVisible() )
aModule->m_Reference->Draw( aPanel, aDC, aDraw_mode );
2011-12-12 08:37:05 +00:00
if( aModule->m_Value->IsVisible() )
aModule->m_Value->Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
}
2012-02-19 04:02:19 +00:00
for( EDA_ITEM* item = aModule->m_Drawings; item; item = item->Next() )
2007-08-23 04:28:46 +00:00
{
2012-02-19 04:02:19 +00:00
switch( item->Type() )
2007-08-23 04:28:46 +00:00
{
case PCB_MODULE_TEXT_T:
if( ( mlayer & aMasklayer ) == 0 )
2007-08-23 04:28:46 +00:00
break;
2012-02-19 04:02:19 +00:00
TEXTE_MODULE* textMod;
textMod = (TEXTE_MODULE*) item;
textMod->Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
break;
case PCB_MODULE_EDGE_T:
2012-02-19 04:02:19 +00:00
{
EDGE_MODULE* edge = (EDGE_MODULE*) item;
2012-02-19 04:02:19 +00:00
if( ( GetLayerMask( edge->GetLayer() ) & aMasklayer ) == 0 )
break;
2012-02-19 04:02:19 +00:00
edge->Draw( aPanel, aDC, aDraw_mode );
}
2007-08-23 04:28:46 +00:00
break;
default:
break;
}
}
}