2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file common_plot_functions.cpp
|
2013-05-21 07:18:25 +00:00
|
|
|
* @brief Kicad: Common plotting functions
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-05-23 16:38:17 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <worksheet.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <class_title_block.h>
|
2013-05-21 07:18:25 +00:00
|
|
|
#include "worksheet_shape_builder.h"
|
2013-10-18 17:38:03 +00:00
|
|
|
#include "class_worksheet_dataitem.h"
|
2013-06-07 17:35:09 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
|
|
|
|
wxString GetDefaultPlotExtension( PlotFormat aFormat )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-08-29 16:59:50 +00:00
|
|
|
switch( aFormat )
|
|
|
|
{
|
|
|
|
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();
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
case PLOT_FORMAT_GERBER:
|
|
|
|
return GERBER_PLOTTER::GetDefaultFileExtension();
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2012-09-15 12:13:03 +00:00
|
|
|
case PLOT_FORMAT_SVG:
|
|
|
|
return SVG_PLOTTER::GetDefaultFileExtension();
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
default:
|
|
|
|
wxASSERT( false );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
|
|
|
|
const PAGE_INFO& aPageInfo,
|
|
|
|
int aSheetNumber, int aNumberOfSheets,
|
2013-05-21 07:18:25 +00:00
|
|
|
const wxString &aSheetDesc, const wxString &aFilename )
|
2012-08-29 16:59:50 +00:00
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
/* Note: Page sizes values are given in mils
|
|
|
|
*/
|
|
|
|
double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
|
2013-03-27 20:38:20 +00:00
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
COLOR4D plotColor = plotter->GetColorMode() ? COLOR4D( RED ) : COLOR4D::BLACK;
|
2013-05-21 07:18:25 +00:00
|
|
|
plotter->SetColor( plotColor );
|
|
|
|
WS_DRAW_ITEM_LIST drawList;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Print only a short filename, if aFilename is the full filename
|
|
|
|
wxFileName fn( aFilename );
|
|
|
|
|
2013-05-24 08:59:40 +00:00
|
|
|
// Prepare plot parameters
|
2015-05-21 09:04:47 +00:00
|
|
|
drawList.SetPenSize(PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2013-05-22 08:45:25 +00:00
|
|
|
drawList.SetMilsToIUfactor( iusPerMil );
|
2013-05-24 08:59:40 +00:00
|
|
|
drawList.SetSheetNumber( aSheetNumber );
|
|
|
|
drawList.SetSheetCount( aNumberOfSheets );
|
2013-07-19 18:27:22 +00:00
|
|
|
drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
|
|
|
|
drawList.SetSheetName( aSheetDesc );
|
2013-05-22 08:45:25 +00:00
|
|
|
|
2013-06-07 16:37:44 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
drawList.BuildWorkSheetGraphicList( aPageInfo,
|
|
|
|
aTitleBlock, plotColor, plotColor );
|
2013-05-21 07:18:25 +00:00
|
|
|
|
|
|
|
// Draw item list
|
|
|
|
for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item;
|
|
|
|
item = drawList.GetNext() )
|
2013-03-27 20:38:20 +00:00
|
|
|
{
|
2015-05-21 09:04:47 +00:00
|
|
|
plotter->SetCurrentLineWidth( PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2013-12-18 18:11:15 +00:00
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
switch( item->GetType() )
|
2013-03-27 20:38:20 +00:00
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
case WS_DRAW_ITEM_BASE::wsg_line:
|
2013-03-27 20:38:20 +00:00
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
|
2013-12-18 18:11:15 +00:00
|
|
|
plotter->SetCurrentLineWidth( line->GetPenWidth() );
|
2013-05-21 07:18:25 +00:00
|
|
|
plotter->MoveTo( line->GetStart() );
|
|
|
|
plotter->FinishTo( line->GetEnd() );
|
2013-03-27 20:38:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
case WS_DRAW_ITEM_BASE::wsg_rect:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
|
2013-12-18 18:11:15 +00:00
|
|
|
plotter->Rect( rect->GetStart(),
|
|
|
|
rect->GetEnd(),
|
|
|
|
NO_FILL,
|
|
|
|
rect->GetPenWidth() );
|
|
|
|
}
|
2013-03-27 20:38:20 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
case WS_DRAW_ITEM_BASE::wsg_text:
|
2013-03-27 20:38:20 +00:00
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
|
2017-01-23 20:30:11 +00:00
|
|
|
plotter->Text( text->GetTextPos(), text->GetColor(),
|
|
|
|
text->GetShownText(), text->GetTextAngle(),
|
|
|
|
text->GetTextSize(),
|
2013-05-21 07:18:25 +00:00
|
|
|
text->GetHorizJustify(), text->GetVertJustify(),
|
|
|
|
text->GetPenWidth(),
|
2013-12-23 16:25:13 +00:00
|
|
|
text->IsItalic(), text->IsBold(),
|
|
|
|
text->IsMultilineAllowed() );
|
2013-03-27 20:38:20 +00:00
|
|
|
}
|
2013-05-21 07:18:25 +00:00
|
|
|
break;
|
2013-03-27 20:38:20 +00:00
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
case WS_DRAW_ITEM_BASE::wsg_poly:
|
2013-03-27 20:38:20 +00:00
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
WS_DRAW_ITEM_POLYGON* poly = (WS_DRAW_ITEM_POLYGON*) item;
|
2013-05-23 16:38:17 +00:00
|
|
|
plotter->PlotPoly( poly->m_Corners,
|
2013-12-18 18:11:15 +00:00
|
|
|
poly->IsFilled() ? FILLED_SHAPE : NO_FILL,
|
|
|
|
poly->GetPenWidth() );
|
2013-03-27 20:38:20 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
break;
|
2013-10-18 17:38:03 +00:00
|
|
|
|
|
|
|
case WS_DRAW_ITEM_BASE::wsg_bitmap:
|
|
|
|
{
|
|
|
|
WS_DRAW_ITEM_BITMAP* bm = (WS_DRAW_ITEM_BITMAP*) item;
|
|
|
|
|
|
|
|
WORKSHEET_DATAITEM_BITMAP* parent = (WORKSHEET_DATAITEM_BITMAP*)bm->GetParent();
|
|
|
|
|
|
|
|
if( parent->m_ImageBitmap == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
parent->m_ImageBitmap->PlotImage( plotter, bm->GetPosition(),
|
2015-05-21 09:04:47 +00:00
|
|
|
plotColor, PLOTTER::USE_DEFAULT_LINE_WIDTH );
|
2013-10-18 17:38:03 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|