kicad/pcbnew/print_board_functions.cpp

390 lines
12 KiB
C++
Raw Normal View History

/**
* @file print_board_functions.cpp
* @brief Functions to print boards.
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <printout_controler.h>
#include <colors_selection.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 <pcbplot.h>
#include <module_editor_frame.h>
static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
GR_DRAWMODE aDraw_mode, LSET aMasklayer,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt );
void FOOTPRINT_EDIT_FRAME::PrintPage( wxDC* aDC,
LSET aPrintMaskLayer,
bool aPrintMirrorMode,
void * aData)
{
2015-03-25 09:55:00 +00:00
const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
int defaultPenSize = Millimeter2iu( 0.2 );
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
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 = *displ_opts;
displ_opts->m_ContrastModeDisplay = false;
displ_opts->m_DisplayPadFill = true;
displ_opts->m_DisplayViaFill = true;
displ_opts->m_DisplayPadNum = false;
bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
displ_opts->m_DisplayPadIsol = false;
displ_opts->m_DisplayModEdgeFill = FILLED;
displ_opts->m_DisplayModTextFill = FILLED;
displ_opts->m_DisplayPcbTrackFill = true;
displ_opts->m_ShowTrackClearanceMode = DO_NOT_SHOW_CLEARANCE;
displ_opts->m_DisplayDrawItemsFill = FILLED;
displ_opts->m_DisplayZonesMode = 0;
displ_opts->m_DisplayNetNamesMode = 0;
m_canvas->SetPrintMirrored( aPrintMirrorMode );
// Draw footprints, this is done at last in order to print the pad holes in
// white 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 );
*displ_opts = save_opt;
GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, nctmp );
}
2007-08-23 04:28:46 +00:00
void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
LSET aPrintMask,
bool aPrintMirrorMode,
void* aData)
{
2015-03-25 09:55:00 +00:00
const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
DISPLAY_OPTIONS save_opt;
BOARD* Pcb = GetBoard();
int defaultPenSize = Millimeter2iu( 0.2 );
bool onePagePerLayer = false;
PRINT_PARAMETERS* printParameters = (PRINT_PARAMETERS*) aData; // can be null
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
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 = *displ_opts;
2014-06-29 13:05:51 +00:00
PCB_LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
displ_opts->m_ContrastModeDisplay = false;
displ_opts->m_DisplayPadFill = true;
displ_opts->m_DisplayViaFill = true;
if( !( aPrintMask & LSET::AllCuMask() ).any() )
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
displ_opts->m_ContrastModeDisplay = true;
displ_opts->m_DisplayPadFill = true;
// Calculate the active layer number to print from its mask layer:
GetScreen()->m_Active_Layer = B_Cu;
for( LAYER_NUM id = PCB_LAYER_ID_COUNT-1; id >= 0; --id )
{
if( aPrintMask[id] )
{
GetScreen()->m_Active_Layer = PCB_LAYER_ID( id );
break;
}
}
// pads on Silkscreen layer are usually plot in sketch mode:
if( GetScreen()->m_Active_Layer == B_SilkS ||
GetScreen()->m_Active_Layer == F_SilkS )
{
displ_opts->m_DisplayPadFill = false;
}
}
else
{
displ_opts->m_DisplayPadFill = false;
}
2009-09-29 04:44:35 +00:00
}
displ_opts->m_DisplayPadNum = false;
bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
bool anchorsTmp = GetBoard()->IsElementVisible( LAYER_ANCHOR );
GetBoard()->SetElementVisibility( LAYER_ANCHOR, false );
displ_opts->m_DisplayPadIsol = false;
displ_opts->m_DisplayModEdgeFill = FILLED;
displ_opts->m_DisplayModTextFill = FILLED;
displ_opts->m_DisplayPcbTrackFill = true;
displ_opts->m_ShowTrackClearanceMode = DO_NOT_SHOW_CLEARANCE;
displ_opts->m_DisplayDrawItemsFill = FILLED;
displ_opts->m_DisplayZonesMode = 0;
displ_opts->m_DisplayNetNamesMode = 0;
2007-08-23 04:28:46 +00:00
m_canvas->SetPrintMirrored( aPrintMirrorMode );
for( auto item : Pcb->Drawings() )
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( aPrintMask[item->GetLayer()] )
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
for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( !( aPrintMask & track->GetLayerSet() ).any() )
2007-08-23 04:28:46 +00:00
continue;
if( track->Type() == PCB_VIA_T ) // VIA encountered.
2007-08-23 04:28:46 +00:00
{
int radius = track->GetWidth() / 2;
const VIA* via = static_cast<const VIA*>( track );
COLOR4D color = g_ColorsSettings.GetItemColor( LAYER_VIAS + via->GetViaType() );
GRFilledCircle( m_canvas->GetClipBox(), aDC,
via->GetStart().x,
via->GetStart().y,
radius,
0, color, color );
2007-08-23 04:28:46 +00:00
}
else
{
track->Draw( m_canvas, aDC, drawmode );
}
2007-08-23 04:28:46 +00:00
}
// Outdated: only for compatibility to old boards
for( TRACK* track = Pcb->m_Zone; track; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( !( aPrintMask & track->GetLayerSet() ).any() )
2007-08-23 04:28:46 +00:00
continue;
track->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( aPrintMask[zone->GetLayer()] )
zone->DrawFilledArea( m_canvas, aDC, drawmode );
}
// Draw footprints, this is done at last in order to print the pad holes in
// white after the tracks and zones
int tmp = D_PAD::m_PadSketchModePenSize;
D_PAD::m_PadSketchModePenSize = defaultPenSize;
for( MODULE* module = (MODULE*) Pcb->m_Modules; module; module = module->Next() )
{
Print_Module( m_canvas, aDC, module, drawmode, aPrintMask, 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
{
TRACK* track = Pcb->m_Track;
COLOR4D color = COLOR4D::WHITE;
bool blackpenstate = GetGRForceBlackPenState();
GRForceBlackPen( false );
for( ; track; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( !( aPrintMask & track->GetLayerSet() ).any() )
continue;
if( track->Type() == PCB_VIA_T ) // VIA encountered.
{
int diameter;
const VIA *via = static_cast<const VIA*>( track );
if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
diameter = std::min( SMALL_DRILL, via->GetDrillValue() );
else
diameter = via->GetDrillValue();
GRFilledCircle( m_canvas->GetClipBox(), aDC,
track->GetStart().x, track->GetStart().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 );
*displ_opts = save_opt;
2014-06-29 13:05:51 +00:00
GetScreen()->m_Active_Layer = activeLayer;
GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, nctmp );
GetBoard()->SetElementVisibility( LAYER_ANCHOR, anchorsTmp );
}
static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
GR_DRAWMODE aDraw_mode, LSET aMask,
PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
{
2012-02-19 04:02:19 +00:00
// Print pads
for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
if( !( pad->GetLayerSet() & aMask ).any() )
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
}
if( aModule->Reference().IsVisible() && aMask[aModule->Reference().GetLayer()] )
aModule->Reference().Draw( aPanel, aDC, aDraw_mode );
if( aModule->Value().IsVisible() && aMask[aModule->Value().GetLayer()] )
aModule->Value().Draw( aPanel, aDC, aDraw_mode );
2007-08-23 04:28:46 +00:00
for( EDA_ITEM* item = aModule->GraphicalItemsList(); 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:
{
TEXTE_MODULE* textMod = static_cast<TEXTE_MODULE*>( item );
if( !aMask[textMod->GetLayer()] )
break;
2007-08-23 04:28:46 +00:00
textMod->Draw( aPanel, aDC, aDraw_mode );
break;
}
2007-08-23 04:28:46 +00:00
case PCB_MODULE_EDGE_T:
2012-02-19 04:02:19 +00:00
{
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
if( !aMask[edge->GetLayer()] )
2012-02-19 04:02:19 +00:00
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;
}
}
}