2018-01-28 16:49:55 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-10-18 20:30:37 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-01-28 16:49:55 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-09-23 18:58:13 +00:00
|
|
|
#include <plotters_specific.h>
|
2020-10-14 00:23:36 +00:00
|
|
|
#include <page_layout/ws_data_item.h>
|
|
|
|
#include <page_layout/ws_draw_item.h>
|
|
|
|
#include <page_layout/ws_painter.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <title_block.h>
|
2018-01-28 16:49:55 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
wxString GetDefaultPlotExtension( PLOT_FORMAT aFormat )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
switch( aFormat )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_FORMAT::DXF:
|
|
|
|
return DXF_PLOTTER::GetDefaultFileExtension();
|
|
|
|
case PLOT_FORMAT::POST:
|
|
|
|
return PS_PLOTTER::GetDefaultFileExtension();
|
|
|
|
case PLOT_FORMAT::PDF:
|
|
|
|
return PDF_PLOTTER::GetDefaultFileExtension();
|
|
|
|
case PLOT_FORMAT::HPGL:
|
|
|
|
return HPGL_PLOTTER::GetDefaultFileExtension();
|
|
|
|
case PLOT_FORMAT::GERBER:
|
|
|
|
return GERBER_PLOTTER::GetDefaultFileExtension();
|
|
|
|
case PLOT_FORMAT::SVG:
|
|
|
|
return SVG_PLOTTER::GetDefaultFileExtension();
|
|
|
|
default:
|
|
|
|
wxASSERT( false );
|
|
|
|
return wxEmptyString;
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
void PlotWorkSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
|
2020-10-18 20:30:37 +00:00
|
|
|
const PAGE_INFO& aPageInfo, const wxString& aSheetNumber, int aNumberOfSheets,
|
|
|
|
const wxString& aSheetDesc, const wxString& aFilename, COLOR4D aColor,
|
|
|
|
bool aIsFirstPage )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
/* Note: Page sizes values are given in mils
|
|
|
|
*/
|
|
|
|
double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
|
2020-04-14 12:25:00 +00:00
|
|
|
COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
|
|
|
|
int defaultPenWidth = plotter->RenderSettings()->GetDefaultPenWidth();
|
2019-05-26 16:20:54 +00:00
|
|
|
|
|
|
|
if( plotColor == COLOR4D::UNSPECIFIED )
|
|
|
|
plotColor = COLOR4D( RED );
|
|
|
|
|
2018-01-28 16:49:55 +00:00
|
|
|
plotter->SetColor( plotColor );
|
|
|
|
WS_DRAW_ITEM_LIST drawList;
|
|
|
|
|
|
|
|
// Print only a short filename, if aFilename is the full filename
|
|
|
|
wxFileName fn( aFilename );
|
|
|
|
|
|
|
|
// Prepare plot parameters
|
2019-05-20 10:23:32 +00:00
|
|
|
drawList.SetDefaultPenSize( PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2018-01-28 16:49:55 +00:00
|
|
|
drawList.SetMilsToIUfactor( iusPerMil );
|
2020-10-18 20:30:37 +00:00
|
|
|
drawList.SetPageNumber( aSheetNumber );
|
2018-01-28 16:49:55 +00:00
|
|
|
drawList.SetSheetCount( aNumberOfSheets );
|
|
|
|
drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
|
|
|
|
drawList.SetSheetName( aSheetDesc );
|
2020-03-26 11:02:59 +00:00
|
|
|
drawList.SetProject( aProject );
|
2020-10-18 20:30:37 +00:00
|
|
|
drawList.SetIsFirstPage( aIsFirstPage );
|
2018-01-28 16:49:55 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
|
2018-01-28 16:49:55 +00:00
|
|
|
|
|
|
|
// Draw item list
|
2019-05-20 10:23:32 +00:00
|
|
|
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
plotter->SetCurrentLineWidth( PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
switch( item->Type() )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_LINE_T:
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
|
2020-04-14 12:25:00 +00:00
|
|
|
plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
|
2018-01-28 16:49:55 +00:00
|
|
|
plotter->MoveTo( line->GetStart() );
|
|
|
|
plotter->FinishTo( line->GetEnd() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_RECT_T:
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( rect->GetPenWidth(), defaultPenWidth );
|
2020-10-15 01:45:20 +00:00
|
|
|
plotter->Rect( rect->GetStart(), rect->GetEnd(), FILL_TYPE::NO_FILL, penWidth );
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_TEXT_T:
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
|
2019-05-20 10:23:32 +00:00
|
|
|
plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
|
2020-04-14 12:25:00 +00:00
|
|
|
text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
|
|
|
|
text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
|
2020-04-18 20:04:41 +00:00
|
|
|
text->IsMultilineAllowed() );
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_POLY_T:
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
2019-06-13 11:23:39 +00:00
|
|
|
WS_DRAW_ITEM_POLYPOLYGONS* poly = (WS_DRAW_ITEM_POLYPOLYGONS*) item;
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( poly->GetPenWidth(), defaultPenWidth );
|
2019-06-13 11:23:39 +00:00
|
|
|
std::vector<wxPoint> points;
|
|
|
|
|
|
|
|
for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
|
|
|
|
{
|
|
|
|
points.clear();
|
|
|
|
SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < outline.PointCount(); ii++ )
|
2019-03-23 18:26:44 +00:00
|
|
|
points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
|
2019-06-13 11:23:39 +00:00
|
|
|
|
2020-10-15 01:45:20 +00:00
|
|
|
plotter->PlotPoly( points, FILL_TYPE::FILLED_SHAPE, penWidth );
|
2019-06-13 11:23:39 +00:00
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_BITMAP_T:
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
WS_DRAW_ITEM_BITMAP* drawItem = (WS_DRAW_ITEM_BITMAP*) item;
|
2019-05-25 11:05:39 +00:00
|
|
|
auto* bitmap = (WS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
|
2018-01-28 16:49:55 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( bitmap->m_ImageBitmap == NULL )
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
|
|
|
|
PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
|
|
|
|
break;
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|