Handle drill mark options in pcbnew printouts

This commit is contained in:
Maciej Suminski 2018-09-28 23:45:48 +02:00
parent 3e5ee254cf
commit 8cb464b725
5 changed files with 154 additions and 11 deletions

View File

@ -183,6 +183,7 @@ void BOARD_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
{
aView->SetLayerVisible( i, false );
aView->SetTopLayer( i, false );
aView->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
}
}
@ -191,4 +192,5 @@ void BOARD_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
void BOARD_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter )
{
aPainter->GetSettings()->SetOutlineWidth( m_PrintParams.m_PenDefaultSize );
aPainter->GetSettings()->SetBackgroundColor( COLOR4D::WHITE );
}

View File

@ -278,6 +278,24 @@ int PCB_PAINTER::getLineThickness( int aActualThickness ) const
}
int PCB_PAINTER::getDrillShape( const D_PAD* aPad ) const
{
return aPad->GetDrillShape();
}
VECTOR2D PCB_PAINTER::getDrillSize( const D_PAD* aPad ) const
{
return VECTOR2D( aPad->GetDrillSize() );
}
int PCB_PAINTER::getDrillSize( const VIA* aVia ) const
{
return aVia->GetDrillValue();
}
bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
{
const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
@ -478,7 +496,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
// Choose drawing settings depending on if we are drawing via's pad or hole
if( aLayer == LAYER_VIAS_HOLES )
radius = aVia->GetDrillValue() / 2.0;
radius = getDrillSize( aVia ) / 2.0;
else
radius = aVia->GetWidth() / 2.0;
@ -677,9 +695,9 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
}
// Pad drawing
COLOR4D color = m_pcbSettings.GetColor( aPad, aLayer );
COLOR4D color;
// Pad holes color is specific
// Pad holes color is type specific
if( aLayer == LAYER_PADS_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
{
// Hole color is the background color for plated holes, but a specific color
@ -692,6 +710,10 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
else
color = m_pcbSettings.GetBackgroundColor();
}
else
{
color = m_pcbSettings.GetColor( aPad, aLayer );
}
VECTOR2D size;
@ -721,8 +743,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
if( aLayer == LAYER_PADS_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
{
// Drawing hole: has same shape as PAD_CIRCLE or PAD_OVAL
size = VECTOR2D( aPad->GetDrillSize() ) / 2.0;
shape = aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ? PAD_SHAPE_OVAL : PAD_SHAPE_CIRCLE;
size = getDrillSize( aPad ) / 2.0;
shape = getDrillShape( aPad ) == PAD_DRILL_SHAPE_OBLONG ? PAD_SHAPE_OVAL : PAD_SHAPE_CIRCLE;
}
else if( aLayer == F_Mask || aLayer == B_Mask )
{

View File

@ -236,6 +236,21 @@ protected:
* @return the thickness to draw
*/
int getLineThickness( int aActualThickness ) const;
/**
* Return drill shape of a pad.
*/
virtual int getDrillShape( const D_PAD* aPad ) const;
/**
* Return drill size for a pad (internal units).
*/
virtual VECTOR2D getDrillSize( const D_PAD* aPad ) const;
/**
* Return drill diameter for a via (internal units).
*/
virtual int getDrillSize( const VIA* aVia ) const;
};
} // namespace KIGFX

View File

@ -101,12 +101,23 @@ void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView
if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
{
// Enable items on copper layers, but do not draw holes
const int copperItems[] = {
LAYER_PADS_TH, LAYER_VIA_MICROVIA, LAYER_VIA_BBLIND, LAYER_VIA_THROUGH
};
for( int item : copperItems )
for( auto item : { LAYER_PADS_TH, LAYER_VIA_MICROVIA,
LAYER_VIA_BBLIND, LAYER_VIA_THROUGH } )
{
aView->SetLayerVisible( item, true );
}
if( m_PrintParams.m_DrillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE )
{
// Enable hole layers to draw drill marks
for( auto holeLayer : { LAYER_PADS_PLATEDHOLES,
LAYER_NON_PLATEDHOLES, LAYER_VIAS_HOLES })
{
aView->SetLayerVisible( holeLayer, true );
aView->SetTopLayer( holeLayer, true );
}
}
}
@ -121,6 +132,33 @@ void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView
}
void PCBNEW_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter )
{
BOARD_PRINTOUT::setupPainter( aPainter );
auto painter = static_cast<KIGFX::PCB_PRINT_PAINTER*>( aPainter.get() );
switch( m_PrintParams.m_DrillShapeOpt )
{
case PRINT_PARAMETERS::NO_DRILL_SHAPE:
painter->SetDrillMarks( false, 0 );
break;
case PRINT_PARAMETERS::SMALL_DRILL_SHAPE:
painter->SetDrillMarks( false, Millimeter2iu( 0.3 ) );
break;
case PRINT_PARAMETERS::FULL_DRILL_SHAPE:
painter->SetDrillMarks( true );
break;
}
painter->GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE );
painter->GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE );
painter->GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE );
}
EDA_RECT PCBNEW_PRINTOUT::getBoundingBox()
{
return m_board->ComputeBoundingBox();
@ -129,5 +167,26 @@ EDA_RECT PCBNEW_PRINTOUT::getBoundingBox()
std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
{
return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::PCB_PAINTER( aGal ) );
return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::PCB_PRINT_PAINTER( aGal ) );
}
int KIGFX::PCB_PRINT_PAINTER::getDrillShape( const D_PAD* aPad ) const
{
return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
}
VECTOR2D KIGFX::PCB_PRINT_PAINTER::getDrillSize( const D_PAD* aPad ) const
{
// TODO should it depend on the pad size?
return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aPad ) :
VECTOR2D( m_drillMarkSize, m_drillMarkSize );
}
int KIGFX::PCB_PRINT_PAINTER::getDrillSize( const VIA* aVia ) const
{
// TODO should it depend on the via size?
return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aVia ) : m_drillMarkSize;
}

View File

@ -21,6 +21,7 @@
#define PCBNEW_PRINTOUT_H
#include <board_printout.h>
#include <pcb_painter.h>
class BOARD;
@ -35,6 +36,8 @@ public:
protected:
void setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView, const LSET& aLayerSet ) override;
void setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter ) override;
EDA_RECT getBoundingBox() override;
std::unique_ptr<KIGFX::PAINTER> getPainter( KIGFX::GAL* aGal ) override;
@ -43,4 +46,46 @@ private:
BOARD* m_board;
};
namespace KIGFX {
/**
* Special flavor of PCB_PAINTER that contains
* modifications to handle printing options.
*/
class PCB_PRINT_PAINTER : public PCB_PAINTER
{
public:
PCB_PRINT_PAINTER( GAL* aGal )
: PCB_PAINTER( aGal ), m_drillMarkReal( false ), m_drillMarkSize( 0 )
{
}
/**
* Set drill marks visibility and options.
* @param aRealSize when enabled, drill marks represent actual holes. Otherwise aSize
* parameter is used.
* @param aSize is drill mark size (internal units), valid only when aRealSize == false.
*/
void SetDrillMarks( bool aRealSize, unsigned int aSize = 0 )
{
m_drillMarkReal = aRealSize;
m_drillMarkSize = aSize;
}
protected:
int getDrillShape( const D_PAD* aPad ) const override;
VECTOR2D getDrillSize( const D_PAD* aPad ) const override;
int getDrillSize( const VIA* aVia ) const override;
///> Flag deciding whether use the actual hole size or user-specified size for drill marks
bool m_drillMarkReal;
///> User-specified size for drill marks (expressed in internal units)
int m_drillMarkSize;
};
}; // namespace KIGFX
#endif /* PCBNEW_PRINTOUT_H */