kicad/pcbnew/print_board_functions.cpp

393 lines
14 KiB
C++
Raw Normal View History

/************************************************************/
/* print_board_functions.cpp: some functions to plot boards */
/************************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
2009-10-28 11:48:47 +00:00
#include "class_board_design_settings.h"
#include "pcbplot.h"
#include "printout_controler.h"
#include "colors_selection.h"
#include "protos.h"
static void Print_Module( WinEDA_DrawPanel* aPanel, wxDC* aDC, MODULE* aModule,
int aDraw_mode, int aMasklayer,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt );
/** Function WinEDA_ModuleEditFrame::PrintPage
* 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
* @param aPrint_Sheet_Ref = true to print frame references
* @param aPrint_Sheet_Ref = 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)
*/
void WinEDA_ModuleEditFrame::PrintPage( wxDC* aDC,
bool aPrint_Sheet_Ref,
int aPrintMaskLayer,
bool aPrintMirrorMode,
void * aData)
{
MODULE* Module;
int drawmode = GR_COPY;
DISPLAY_OPTIONS save_opt;
BOARD* Pcb = GetBoard();
int defaultPenSize = 50;
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;
DrawPanel->m_PrintIsMirrored = aPrintMirrorMode;
// The OR mode is used in color mode, but be aware the backgroud *must be
// BLACK. In the print page dialog, we first print in BLACK, and after
// reprint in color, on the black "local" backgroud, 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
Module = (MODULE*) Pcb->m_Modules;
int tmp = D_PAD::m_PadSketchModePenSize;
D_PAD::m_PadSketchModePenSize = defaultPenSize;
for( ; Module != NULL; Module = Module->Next() )
{
Print_Module( DrawPanel, aDC, Module, drawmode, aPrintMaskLayer, drillShapeOpt );
}
D_PAD::m_PadSketchModePenSize = tmp;
if( aPrint_Sheet_Ref )
TraceWorkSheet( aDC, GetScreen(), defaultPenSize );
DrawPanel->m_PrintIsMirrored = 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
/** WinEDA_PcbFrame::Function PrintPage
* 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
* @param aPrint_Sheet_Ref = true to print frame references
* @param aPrint_Sheet_Ref = 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 WinEDA_PcbFrame::PrintPage( wxDC* aDC,
bool aPrint_Sheet_Ref,
int aPrintMaskLayer,
bool aPrintMirrorMode,
void * aData)
{
MODULE* Module;
int drawmode = GR_COPY;
2007-08-23 04:28:46 +00:00
DISPLAY_OPTIONS save_opt;
TRACK* pt_piste;
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;
2007-08-23 04:28:46 +00:00
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;
2007-08-23 04:28:46 +00:00
DrawPanel->m_PrintIsMirrored = aPrintMirrorMode;
// The OR mode is used in color mode, but be aware the backgroud *must be
// BLACK. In the print page dialog, we first print in BLACK, and after
// reprint in color, on the black "local" backgroud, in OR mode the black
// print is not made before, only a white page is printed
if( GetGRForceBlackPenState() == false )
drawmode = GR_OR;
2008-12-17 06:51:39 +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 TYPE_DRAWSEGMENT:
case TYPE_DIMENSION:
case TYPE_TEXTE:
case TYPE_MIRE:
if( ( ( 1 << item->GetLayer() ) & aPrintMaskLayer ) == 0 )
2007-08-23 04:28:46 +00:00
break;
item->Draw( DrawPanel, aDC, drawmode );
2007-08-23 04:28:46 +00:00
break;
case TYPE_MARKER_PCB:
2007-08-23 04:28:46 +00:00
default:
break;
}
}
2008-12-17 06:51:39 +00:00
/* Print tracks */
2007-08-23 04:28:46 +00:00
pt_piste = Pcb->m_Track;
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
if( pt_piste->Type() == TYPE_VIA ) /* VIA encountered. */
2007-08-23 04:28:46 +00:00
{
int rayon = pt_piste->m_Width >> 1;
int color = g_ColorsSettings.GetItemColor(VIAS_VISIBLE+pt_piste->m_Shape);
GRSetDrawMode( aDC, drawmode );
GRFilledCircle( &DrawPanel->m_ClipBox, aDC,
pt_piste->m_Start.x,
pt_piste->m_Start.y,
rayon,
0, color, color );
2007-08-23 04:28:46 +00:00
}
else
pt_piste->Draw( DrawPanel, aDC, drawmode );
2007-08-23 04:28:46 +00:00
}
pt_piste = Pcb->m_Zone;
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
pt_piste->Draw( DrawPanel, aDC, drawmode );
2007-08-23 04:28:46 +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( DrawPanel, 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( DrawPanel, 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_piste = Pcb->m_Track;
int color = g_DrawBgColor;
bool blackpenstate = GetGRForceBlackPenState();
GRForceBlackPen( false );
GRSetDrawMode( aDC, GR_COPY );
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
2007-08-23 04:28:46 +00:00
{
if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 )
continue;
if( pt_piste->Type() == TYPE_VIA ) /* VIA encountered. */
{
int diameter;
if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
diameter = min( SMALL_DRILL, pt_piste->GetDrillValue());
else
diameter = pt_piste->GetDrillValue();
GRFilledCircle( &DrawPanel->m_ClipBox, aDC,
pt_piste->m_Start.x, pt_piste->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
}
if( aPrint_Sheet_Ref )
TraceWorkSheet( aDC, GetScreen(), defaultPenSize );
2007-08-23 04:28:46 +00:00
DrawPanel->m_PrintIsMirrored = 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;
GetBoard()->SetElementVisibility(NO_CONNECTS_VISIBLE, nctmp);
}
static void Print_Module( WinEDA_DrawPanel* aPanel, wxDC* aDC, MODULE* aModule,
int aDraw_mode, int aMasklayer,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
{
2007-08-23 04:28:46 +00:00
D_PAD* pt_pad;
EDA_BaseStruct* PtStruct;
TEXTE_MODULE* TextMod;
int mlayer;
2008-12-17 06:51:39 +00:00
/* Print pads */
pt_pad = aModule->m_Pads;
for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
2007-08-23 04:28:46 +00:00
{
if( (pt_pad->m_Masque_Layer & aMasklayer ) == 0 )
2007-08-23 04:28:46 +00:00
continue;
// Manage hole according to the print drill option
wxSize drill_tmp = pt_pad->m_Drill;
switch ( aDrillShapeOpt )
{
case PRINT_PARAMETERS::NO_DRILL_SHAPE:
pt_pad->m_Drill = wxSize(0,0);
break;
case PRINT_PARAMETERS::SMALL_DRILL_SHAPE:
pt_pad->m_Drill.x = MIN(SMALL_DRILL,pt_pad->m_Drill.x);
pt_pad->m_Drill.y = MIN(SMALL_DRILL,pt_pad->m_Drill.y);
break;
case PRINT_PARAMETERS::FULL_DRILL_SHAPE:
// Do nothing
break;
}
pt_pad->Draw( aPanel, aDC, aDraw_mode );
pt_pad->m_Drill = drill_tmp;
2007-08-23 04:28:46 +00:00
}
2008-12-17 06:51:39 +00:00
/* Print footprint graphic shapes */
PtStruct = aModule->m_Drawings;
mlayer = g_TabOneLayerMask[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
{
if( !aModule->m_Reference->m_NoShow )
aModule->m_Reference->Draw( aPanel, aDC, aDraw_mode );
if( !aModule->m_Value->m_NoShow )
aModule->m_Value->Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
}
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
{
2007-09-01 12:00:30 +00:00
switch( PtStruct->Type() )
2007-08-23 04:28:46 +00:00
{
case TYPE_TEXTE_MODULE:
if( (mlayer & aMasklayer ) == 0 )
2007-08-23 04:28:46 +00:00
break;
TextMod = (TEXTE_MODULE*) PtStruct;
TextMod->Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
break;
case TYPE_EDGE_MODULE:
2007-08-23 04:28:46 +00:00
{
EDGE_MODULE* edge = (EDGE_MODULE*) PtStruct;
if( ( g_TabOneLayerMask[edge->GetLayer()] & aMasklayer ) == 0 )
2007-08-23 04:28:46 +00:00
break;
edge->Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
break;
}
default:
break;
}
}
}