2018-01-28 16:49:55 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-13 11:25:30 +00:00
|
|
|
* Copyright (C) 1992-2023 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>
|
2022-10-22 20:32:10 +00:00
|
|
|
#include <font/font.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter_dxf.h>
|
|
|
|
#include <plotters/plotter_hpgl.h>
|
|
|
|
#include <plotters/plotters_pslike.h>
|
|
|
|
#include <plotters/plotter_gerber.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_draw_item.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 )
|
|
|
|
{
|
2023-03-13 11:25:30 +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: wxFAIL; return wxEmptyString;
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
|
2022-09-20 14:25:03 +00:00
|
|
|
const PAGE_INFO& aPageInfo, const std::map<wxString, wxString>* aProperties,
|
|
|
|
const wxString& aSheetNumber, int aSheetCount, const wxString& aSheetName,
|
|
|
|
const wxString& aSheetPath, const wxString& aFilename, COLOR4D aColor,
|
2021-02-22 16:37:43 +00:00
|
|
|
bool aIsFirstPage )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
|
|
|
/* Note: Page sizes values are given in mils
|
|
|
|
*/
|
2022-10-22 20:32:10 +00:00
|
|
|
double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
|
|
|
|
COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
|
|
|
|
RENDER_SETTINGS* settings = plotter->RenderSettings();
|
|
|
|
int defaultPenWidth = settings->GetDefaultPenWidth();
|
2019-05-26 16:20:54 +00:00
|
|
|
|
|
|
|
if( plotColor == COLOR4D::UNSPECIFIED )
|
|
|
|
plotColor = COLOR4D( RED );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_LIST drawList;
|
2018-01-28 16:49:55 +00:00
|
|
|
|
|
|
|
// 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 );
|
2021-02-22 16:37:43 +00:00
|
|
|
drawList.SetSheetCount( aSheetCount );
|
2018-01-28 16:49:55 +00:00
|
|
|
drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
|
2022-04-09 14:38:47 +00:00
|
|
|
drawList.SetSheetName( aSheetName );
|
|
|
|
drawList.SetSheetPath( aSheetPath );
|
2022-10-22 20:32:10 +00:00
|
|
|
drawList.SetSheetLayer( settings->GetLayerName() );
|
2020-03-26 11:02:59 +00:00
|
|
|
drawList.SetProject( aProject );
|
2020-10-18 20:30:37 +00:00
|
|
|
drawList.SetIsFirstPage( aIsFirstPage );
|
2022-09-20 14:25:03 +00:00
|
|
|
drawList.SetProperties( aProperties );
|
2018-01-28 16:49:55 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
|
2018-01-28 16:49:55 +00:00
|
|
|
|
|
|
|
// Draw item list
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
|
2018-01-28 16:49:55 +00:00
|
|
|
{
|
2023-02-08 20:20:37 +00:00
|
|
|
plotter->SetColor( plotColor );
|
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:
|
2021-08-17 17:44:11 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_LINE* line = (DS_DRAW_ITEM_LINE*) item;
|
|
|
|
plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
|
|
|
|
plotter->MoveTo( line->GetStart() );
|
|
|
|
plotter->FinishTo( line->GetEnd() );
|
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_RECT_T:
|
2021-08-17 17:44:11 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_RECT* rect = (DS_DRAW_ITEM_RECT*) item;
|
2022-10-17 16:49:28 +00:00
|
|
|
plotter->SetCurrentLineWidth( std::max( rect->GetPenWidth(), defaultPenWidth ) );
|
|
|
|
plotter->MoveTo( rect->GetStart() );
|
|
|
|
plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetStart().y ) );
|
|
|
|
plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetEnd().y ) );
|
|
|
|
plotter->LineTo( VECTOR2I( rect->GetStart().x, rect->GetEnd().y ) );
|
|
|
|
plotter->FinishTo( rect->GetStart() );
|
2021-08-17 17:44:11 +00:00
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_TEXT_T:
|
2021-08-17 17:44:11 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item;
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = text->GetFont();
|
2023-02-08 20:20:37 +00:00
|
|
|
COLOR4D color = plotColor;
|
2022-10-22 20:32:10 +00:00
|
|
|
|
|
|
|
if( !font )
|
|
|
|
{
|
|
|
|
font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(),
|
|
|
|
text->IsItalic() );
|
|
|
|
}
|
|
|
|
|
2023-02-08 20:20:37 +00:00
|
|
|
if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
color = text->GetTextColor();
|
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
|
2022-10-22 20:32:10 +00:00
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
plotter->Text( text->GetTextPos(), color, text->GetShownText( true ),
|
|
|
|
text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
|
|
|
|
text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
|
|
|
|
text->IsMultilineAllowed(), font );
|
2021-08-17 17:44:11 +00:00
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_POLY_T:
|
2021-08-17 17:44:11 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_POLYPOLYGONS* poly = (DS_DRAW_ITEM_POLYPOLYGONS*) item;
|
2022-01-11 00:49:49 +00:00
|
|
|
int penWidth = std::max( poly->GetPenWidth(), defaultPenWidth );
|
|
|
|
std::vector<VECTOR2I> points;
|
2019-06-13 11:23:39 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
|
|
|
|
{
|
|
|
|
points.clear();
|
|
|
|
SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
|
2019-06-13 11:23:39 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
for( int ii = 0; ii < outline.PointCount(); ii++ )
|
|
|
|
points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
|
2019-06-13 11:23:39 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
plotter->PlotPoly( points, FILL_T::FILLED_SHAPE, penWidth );
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
2021-08-17 17:44:11 +00:00
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
case WSG_BITMAP_T:
|
2021-08-17 17:44:11 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_BITMAP* drawItem = (DS_DRAW_ITEM_BITMAP*) item;
|
|
|
|
DS_DATA_ITEM_BITMAP* bitmap = (DS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
|
2018-01-28 16:49:55 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
if( bitmap->m_ImageBitmap == nullptr )
|
|
|
|
break;
|
2018-01-28 16:49:55 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
|
2023-03-13 11:25:30 +00:00
|
|
|
PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2021-08-17 17:44:11 +00:00
|
|
|
}
|
2018-01-28 16:49:55 +00:00
|
|
|
break;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
default:
|
2021-02-22 16:37:43 +00:00
|
|
|
wxFAIL_MSG( "PlotDrawingSheet(): Unknown drawing sheet item." );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
2018-01-28 16:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|