2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-11-16 11:09:24 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-02-22 15:19:08 +00:00
|
|
|
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-19 20:20:16 +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
|
|
|
|
*/
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
2018-01-28 18:12:26 +00:00
|
|
|
* @file plotter.cpp
|
|
|
|
* @brief KiCad: Base of all the specialized plotters
|
2012-05-03 18:37:56 +00:00
|
|
|
* the class PLOTTER handle basic functions to plot schematic and boards
|
|
|
|
* with different plot formats.
|
|
|
|
*
|
|
|
|
* There are currently engines for:
|
|
|
|
* HPGL
|
|
|
|
* POSTSCRIPT
|
|
|
|
* GERBER
|
|
|
|
* DXF
|
2012-09-15 12:13:03 +00:00
|
|
|
* an SVG 'plot' is also provided along with the 'print' function by wx, but
|
2012-05-03 18:37:56 +00:00
|
|
|
* is not handled here.
|
|
|
|
*/
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2017-11-16 11:09:24 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2019-11-05 13:27:07 +00:00
|
|
|
#include <bezier_curves.h>
|
2022-01-10 14:03:53 +00:00
|
|
|
#include <callback_gal.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
PLOTTER::PLOTTER( )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotScale = 1;
|
|
|
|
m_currentPenWidth = -1; // To-be-set marker
|
|
|
|
m_penState = 'Z'; // End-of-path idle
|
2015-03-04 19:45:18 +00:00
|
|
|
m_plotMirror = false; // Plot mirror option flag
|
2013-12-06 18:31:15 +00:00
|
|
|
m_mirrorIsHorizontal = true;
|
|
|
|
m_yaxisReversed = false;
|
2021-04-22 21:20:34 +00:00
|
|
|
m_outputFile = nullptr;
|
2020-11-16 00:04:55 +00:00
|
|
|
m_colorMode = false; // Starts as a BW plot
|
|
|
|
m_negativeMode = false;
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2015-03-04 19:45:18 +00:00
|
|
|
// Temporary init to avoid not initialized vars, will be set later
|
|
|
|
m_IUsPerDecimil = 1; // will be set later to the actual value
|
2020-11-16 00:04:55 +00:00
|
|
|
m_iuPerDeviceUnit = 1; // will be set later to the actual value
|
2020-04-14 12:25:00 +00:00
|
|
|
m_renderSettings = nullptr;
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2013-02-06 11:54:51 +00:00
|
|
|
PLOTTER::~PLOTTER()
|
|
|
|
{
|
2021-08-17 17:44:11 +00:00
|
|
|
// Emergency cleanup, but closing the file is usually made in EndPlot().
|
2020-11-16 00:04:55 +00:00
|
|
|
if( m_outputFile )
|
|
|
|
fclose( m_outputFile );
|
2013-02-06 11:54:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
bool PLOTTER::OpenFile( const wxString& aFullFilename )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_filename = aFullFilename;
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( !m_outputFile );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
// Open the file in text mode (not suitable for all plotters but only for most of them.
|
2020-11-16 00:04:55 +00:00
|
|
|
m_outputFile = wxFopen( m_filename, wxT( "wt" ) );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
if( m_outputFile == nullptr )
|
2012-10-13 18:54:33 +00:00
|
|
|
return false ;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D PLOTTER::userToDeviceCoordinates( const VECTOR2I& aCoordinate )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I pos = aCoordinate - m_plotOffset;
|
2013-12-06 18:31:15 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
double x = pos.x * m_plotScale;
|
|
|
|
double y = ( m_paperSize.y - pos.y * m_plotScale );
|
2013-12-06 18:31:15 +00:00
|
|
|
|
|
|
|
if( m_plotMirror )
|
|
|
|
{
|
|
|
|
if( m_mirrorIsHorizontal )
|
2020-11-16 00:04:55 +00:00
|
|
|
x = ( m_paperSize.x - pos.x * m_plotScale );
|
2013-12-06 18:31:15 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
y = pos.y * m_plotScale;
|
2013-12-06 18:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_yaxisReversed )
|
2020-11-16 00:04:55 +00:00
|
|
|
y = m_paperSize.y - y;
|
2013-12-06 18:31:15 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
x *= m_iuPerDeviceUnit;
|
|
|
|
y *= m_iuPerDeviceUnit;
|
2013-12-06 18:31:15 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
return VECTOR2D( x, y );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D PLOTTER::userToDeviceSize( const VECTOR2I& size )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2022-01-20 00:17:44 +00:00
|
|
|
return VECTOR2D( size.x * m_plotScale * m_iuPerDeviceUnit,
|
|
|
|
size.y * m_plotScale * m_iuPerDeviceUnit );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2015-03-10 20:00:50 +00:00
|
|
|
double PLOTTER::userToDeviceSize( double size ) const
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
return size * m_plotScale * m_iuPerDeviceUnit;
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-07 21:33:01 +00:00
|
|
|
#define IU_PER_MILS ( m_IUsPerDecimil * 10 )
|
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
double PLOTTER::GetDotMarkLenIU( int aLineWidth ) const
|
2017-11-13 03:53:27 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
return userToDeviceSize( m_renderSettings->GetDotLength( aLineWidth ) );
|
2017-11-13 03:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
double PLOTTER::GetDashMarkLenIU( int aLineWidth ) const
|
2015-03-10 20:00:50 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
return userToDeviceSize( m_renderSettings->GetDashLength( aLineWidth ) );
|
2015-03-10 20:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
double PLOTTER::GetDashGapLenIU( int aLineWidth ) const
|
2015-03-10 20:00:50 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
return userToDeviceSize( m_renderSettings->GetGapLength( aLineWidth ) );
|
2015-03-10 20:00:50 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
#include <wx/log.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
void PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
|
|
|
FILL_T aFill, int aWidth, int aMaxError )
|
|
|
|
{
|
2023-07-06 15:39:24 +00:00
|
|
|
// Recalculate aCenter using double to be sure we will use a exact value, from aStart and aEnd
|
|
|
|
// it must be on the line passing by the middle of segment {aStart, aEnd}
|
|
|
|
// To simplify calculations, use aStart as origin in intermediate calculations
|
|
|
|
VECTOR2D center = aCenter - aStart;
|
|
|
|
VECTOR2D end = aEnd - aStart;
|
|
|
|
EDA_ANGLE segAngle( end );
|
|
|
|
|
|
|
|
// Rotate end and center, to make segment {aStart, aEnd} horizontal
|
|
|
|
RotatePoint( end, segAngle );
|
|
|
|
RotatePoint( center, segAngle );
|
|
|
|
|
|
|
|
// center.x must be at end.x/2 coordinate
|
|
|
|
center.x = end.x / 2;
|
|
|
|
|
|
|
|
// Now calculate the right center position
|
|
|
|
RotatePoint( center, -segAngle );
|
|
|
|
center += aStart;
|
|
|
|
|
|
|
|
EDA_ANGLE startAngle( VECTOR2D( aStart ) - center );
|
|
|
|
EDA_ANGLE endAngle( VECTOR2D( aEnd ) - center );
|
|
|
|
double radius = ( VECTOR2D( aStart ) - center ).EuclideanNorm();
|
2022-02-20 13:59:11 +00:00
|
|
|
|
|
|
|
if( startAngle > endAngle )
|
|
|
|
{
|
|
|
|
if( endAngle < ANGLE_0 )
|
|
|
|
endAngle.Normalize();
|
|
|
|
else
|
|
|
|
startAngle = startAngle.Normalize() - ANGLE_360;
|
|
|
|
}
|
|
|
|
|
2022-09-20 16:29:29 +00:00
|
|
|
// In old Kicad code, calls to Arc() using angles calls this function after
|
|
|
|
// swapping angles and negate them (to compensate the inverted Y axis).
|
|
|
|
// So to be compatible with Arc() calls with angles, do the same thing
|
2022-09-20 12:39:41 +00:00
|
|
|
std::swap( startAngle, endAngle );
|
|
|
|
startAngle = -startAngle;
|
|
|
|
endAngle = -endAngle;
|
2022-02-20 13:59:11 +00:00
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
Arc( center, startAngle, endAngle, radius, aFill, aWidth );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
void PLOTTER::Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
|
|
|
|
const EDA_ANGLE& aEndAngle, double aRadius, FILL_T aFill, int aWidth )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE startAngle( aStartAngle );
|
|
|
|
EDA_ANGLE endAngle( aEndAngle );
|
|
|
|
const EDA_ANGLE delta( 5.0, DEGREES_T ); // increment to draw arc
|
|
|
|
VECTOR2I start, end;
|
2022-09-20 12:39:41 +00:00
|
|
|
const int sign = -1;
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( startAngle > endAngle )
|
|
|
|
std::swap( startAngle, endAngle );
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2022-09-20 12:39:41 +00:00
|
|
|
start.x = aCenter.x + KiROUND( aRadius * startAngle.Cos() );
|
|
|
|
start.y = aCenter.y + sign*KiROUND( aRadius * startAngle.Sin() );
|
2019-08-20 13:45:57 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2019-08-20 13:45:57 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
MoveTo( aCenter );
|
2019-08-20 13:45:57 +00:00
|
|
|
LineTo( start );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MoveTo( start );
|
|
|
|
}
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
for( EDA_ANGLE ii = startAngle + delta; ii < endAngle; ii += delta )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2022-09-20 12:39:41 +00:00
|
|
|
end.x = aCenter.x + KiROUND( aRadius * ii.Cos() );
|
|
|
|
end.y = aCenter.y + sign*KiROUND( aRadius * ii.Sin() );
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( end );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 12:39:41 +00:00
|
|
|
end.x = aCenter.x + KiROUND( aRadius * endAngle.Cos() );
|
|
|
|
end.y = aCenter.y + sign*KiROUND( aRadius * endAngle.Sin() );
|
2019-08-20 13:45:57 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2019-08-20 13:45:57 +00:00
|
|
|
{
|
|
|
|
LineTo( end );
|
2022-01-16 01:06:25 +00:00
|
|
|
FinishTo( aCenter );
|
2019-08-20 13:45:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FinishTo( end );
|
|
|
|
}
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::BezierCurve( const VECTOR2I& aStart, const VECTOR2I& aControl1,
|
|
|
|
const VECTOR2I& aControl2, const VECTOR2I& aEnd,
|
2019-11-05 13:27:07 +00:00
|
|
|
int aTolerance, int aLineThickness )
|
|
|
|
{
|
|
|
|
// Generic fallback: Quadratic Bezier curve plotted as a polyline
|
|
|
|
int minSegLen = aLineThickness; // The segment min length to approximate a bezier curve
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> ctrlPoints;
|
2022-02-06 02:12:29 +00:00
|
|
|
ctrlPoints.reserve( 4 );
|
|
|
|
|
2019-11-05 13:27:07 +00:00
|
|
|
ctrlPoints.push_back( aStart );
|
|
|
|
ctrlPoints.push_back( aControl1 );
|
|
|
|
ctrlPoints.push_back( aControl2 );
|
|
|
|
ctrlPoints.push_back( aEnd );
|
|
|
|
|
|
|
|
BEZIER_POLY bezier_converter( ctrlPoints );
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> approxPoints;
|
2019-11-05 13:27:07 +00:00
|
|
|
bezier_converter.GetPoly( approxPoints, minSegLen );
|
|
|
|
|
2019-11-09 13:02:41 +00:00
|
|
|
SetCurrentLineWidth( aLineThickness );
|
2019-11-05 13:27:07 +00:00
|
|
|
MoveTo( aStart );
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < approxPoints.size()-1; ii++ )
|
|
|
|
LineTo( approxPoints[ii] );
|
|
|
|
|
|
|
|
FinishTo( aEnd );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I size( aImage.GetWidth() * aScaleFactor, aImage.GetHeight() * aScaleFactor );
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I start = aPos;
|
2012-05-03 18:37:56 +00:00
|
|
|
start.x -= size.x / 2;
|
|
|
|
start.y -= size.y / 2;
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I end = start;
|
2012-05-03 18:37:56 +00:00
|
|
|
end.x += size.x;
|
|
|
|
end.y += size.y;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( start, end, FILL_T::NO_FILL );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerSquare( const VECTOR2I& position, int radius )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
double r = KiROUND( radius / 1.4142 );
|
|
|
|
std::vector<VECTOR2I> corner_list;
|
|
|
|
VECTOR2I corner;
|
|
|
|
|
2022-02-06 02:12:29 +00:00
|
|
|
corner_list.reserve( 4 );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
corner.x = position.x + r;
|
|
|
|
corner.y = position.y + r;
|
2011-04-20 08:13:21 +00:00
|
|
|
corner_list.push_back( corner );
|
2012-05-03 18:37:56 +00:00
|
|
|
corner.x = position.x + r;
|
|
|
|
corner.y = position.y - r;
|
2011-04-20 08:13:21 +00:00
|
|
|
corner_list.push_back( corner );
|
2012-05-03 18:37:56 +00:00
|
|
|
corner.x = position.x - r;
|
|
|
|
corner.y = position.y - r;
|
2011-04-20 08:13:21 +00:00
|
|
|
corner_list.push_back( corner );
|
2012-05-03 18:37:56 +00:00
|
|
|
corner.x = position.x - r;
|
|
|
|
corner.y = position.y + r;
|
2011-04-20 08:13:21 +00:00
|
|
|
corner_list.push_back( corner );
|
2012-05-03 18:37:56 +00:00
|
|
|
corner.x = position.x + r;
|
|
|
|
corner.y = position.y + r;
|
2011-04-20 08:13:21 +00:00
|
|
|
corner_list.push_back( corner );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerCircle( const VECTOR2I& position, int radius )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( position, radius * 2, FILL_T::NO_FILL, GetCurrentLineWidth() );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerLozenge( const VECTOR2I& position, int radius )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> corner_list;
|
|
|
|
VECTOR2I corner;
|
|
|
|
|
2022-02-06 02:12:29 +00:00
|
|
|
corner_list.reserve( 4 );
|
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
corner.x = position.x;
|
|
|
|
corner.y = position.y + radius;
|
|
|
|
corner_list.push_back( corner );
|
|
|
|
corner.x = position.x + radius;
|
|
|
|
corner.y = position.y,
|
|
|
|
corner_list.push_back( corner );
|
|
|
|
corner.x = position.x;
|
|
|
|
corner.y = position.y - radius;
|
|
|
|
corner_list.push_back( corner );
|
|
|
|
corner.x = position.x - radius;
|
|
|
|
corner.y = position.y;
|
|
|
|
corner_list.push_back( corner );
|
|
|
|
corner.x = position.x;
|
|
|
|
corner.y = position.y + radius;
|
|
|
|
corner_list.push_back( corner );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerHBar( const VECTOR2I& pos, int radius )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( pos.x - radius, pos.y ) );
|
|
|
|
FinishTo( VECTOR2I( pos.x + radius, pos.y ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerSlash( const VECTOR2I& pos, int radius )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( pos.x - radius, pos.y - radius ) );
|
|
|
|
FinishTo( VECTOR2I( pos.x + radius, pos.y + radius ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerBackSlash( const VECTOR2I& pos, int radius )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( pos.x + radius, pos.y - radius ) );
|
|
|
|
FinishTo( VECTOR2I( pos.x - radius, pos.y + radius ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::markerVBar( const VECTOR2I& pos, int radius )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( pos.x, pos.y - radius ) );
|
|
|
|
FinishTo( VECTOR2I( pos.x, pos.y + radius ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::Marker( const VECTOR2I& position, int diametre, unsigned aShapeId )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
int radius = diametre / 2;
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2012-09-15 12:13:03 +00:00
|
|
|
/* Marker are composed by a series of 'parts' superimposed; not every
|
2012-05-03 18:37:56 +00:00
|
|
|
combination make sense, obviously. Since they are used in order I
|
|
|
|
tried to keep the uglier/more complex constructions at the end.
|
|
|
|
Also I avoided the |/ |\ -/ -\ construction because they're *very*
|
|
|
|
ugly... if needed they could be added anyway... I'd like to see
|
|
|
|
a board with more than 58 drilling/slotting tools!
|
|
|
|
If Visual C++ supported the 0b literals they would be optimally
|
|
|
|
and easily encoded as an integer array. We have to do with octal */
|
|
|
|
static const unsigned char marker_patterns[MARKER_COUNT] = {
|
2021-07-15 19:26:35 +00:00
|
|
|
|
|
|
|
// Bit order: O Square Lozenge - | \ /
|
|
|
|
// First choice: simple shapes
|
|
|
|
0003, // X
|
|
|
|
0100, // O
|
|
|
|
0014, // +
|
|
|
|
0040, // Sq
|
|
|
|
0020, // Lz
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Two simple shapes
|
|
|
|
0103, // X O
|
|
|
|
0017, // X +
|
|
|
|
0043, // X Sq
|
|
|
|
0023, // X Lz
|
|
|
|
0114, // O +
|
|
|
|
0140, // O Sq
|
|
|
|
0120, // O Lz
|
|
|
|
0054, // + Sq
|
|
|
|
0034, // + Lz
|
|
|
|
0060, // Sq Lz
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Three simple shapes
|
|
|
|
0117, // X O +
|
|
|
|
0143, // X O Sq
|
|
|
|
0123, // X O Lz
|
|
|
|
0057, // X + Sq
|
|
|
|
0037, // X + Lz
|
|
|
|
0063, // X Sq Lz
|
|
|
|
0154, // O + Sq
|
|
|
|
0134, // O + Lz
|
|
|
|
0074, // + Sq Lz
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Four simple shapes
|
|
|
|
0174, // O Sq Lz +
|
|
|
|
0163, // X O Sq Lz
|
|
|
|
0157, // X O Sq +
|
|
|
|
0137, // X O Lz +
|
|
|
|
0077, // X Sq Lz +
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// This draws *everything *
|
|
|
|
0177, // X O Sq Lz +
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Here we use the single bars... so the cross is forbidden
|
|
|
|
0110, // O -
|
|
|
|
0104, // O |
|
|
|
|
0101, // O /
|
|
|
|
0050, // Sq -
|
|
|
|
0044, // Sq |
|
|
|
|
0041, // Sq /
|
|
|
|
0030, // Lz -
|
|
|
|
0024, // Lz |
|
|
|
|
0021, // Lz /
|
|
|
|
0150, // O Sq -
|
|
|
|
0144, // O Sq |
|
|
|
|
0141, // O Sq /
|
|
|
|
0130, // O Lz -
|
|
|
|
0124, // O Lz |
|
|
|
|
0121, // O Lz /
|
|
|
|
0070, // Sq Lz -
|
|
|
|
0064, // Sq Lz |
|
|
|
|
0061, // Sq Lz /
|
|
|
|
0170, // O Sq Lz -
|
|
|
|
0164, // O Sq Lz |
|
|
|
|
0161, // O Sq Lz /
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
// Last resort: the backlash component (easy to confound)
|
|
|
|
0102, // \ O
|
|
|
|
0042, // \ Sq
|
|
|
|
0022, // \ Lz
|
|
|
|
0142, // \ O Sq
|
|
|
|
0122, // \ O Lz
|
|
|
|
0062, // \ Sq Lz
|
|
|
|
0162 // \ O Sq Lz
|
2012-05-03 18:37:56 +00:00
|
|
|
};
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( aShapeId >= MARKER_COUNT )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2014-10-13 08:40:34 +00:00
|
|
|
// Fallback shape
|
|
|
|
markerCircle( position, radius );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2021-07-15 19:26:35 +00:00
|
|
|
// Decode the pattern and draw the corresponding parts
|
|
|
|
unsigned char pat = marker_patterns[aShapeId];
|
|
|
|
|
|
|
|
if( pat & 0001 )
|
|
|
|
markerSlash( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0002 )
|
|
|
|
markerBackSlash( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0004 )
|
|
|
|
markerVBar( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0010 )
|
|
|
|
markerHBar( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0020 )
|
|
|
|
markerLozenge( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0040 )
|
|
|
|
markerSquare( position, radius );
|
|
|
|
|
|
|
|
if( pat & 0100 )
|
|
|
|
markerCircle( position, radius );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void PLOTTER::segmentAsOval( const VECTOR2I& start, const VECTOR2I& end, int aWidth,
|
|
|
|
OUTLINE_MODE aTraceMode )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
VECTOR2I center( ( start.x + end.x ) / 2, ( start.y + end.y ) / 2 );
|
|
|
|
VECTOR2I size( end.x - start.x, end.y - start.y );
|
|
|
|
EDA_ANGLE orient( size );
|
2022-01-21 11:34:32 +00:00
|
|
|
orient = -orient; // this is due to our Y axis orientation
|
2013-02-11 00:41:49 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
size.x = KiROUND( EuclideanNorm( size ) ) + aWidth;
|
|
|
|
size.y = aWidth;
|
2009-08-29 10:20:48 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
FlashPadOval( center, size, orient, aTraceMode, nullptr );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void PLOTTER::sketchOval( const VECTOR2I& aPos, const VECTOR2I& aSize, const EDA_ANGLE& aOrient,
|
|
|
|
int aWidth )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
|
|
|
|
EDA_ANGLE orient( aOrient );
|
|
|
|
VECTOR2I size( aSize );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2022-01-16 01:06:25 +00:00
|
|
|
orient += ANGLE_90;
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
int deltaxy = size.y - size.x; /* distance between centers of the oval */
|
2022-04-27 18:02:06 +00:00
|
|
|
int radius = size.x / 2;
|
2022-01-16 01:06:25 +00:00
|
|
|
|
2022-04-29 08:52:41 +00:00
|
|
|
// Build a vertical oval shape giving the start and end points of arcs and edges,
|
|
|
|
// and the middle point of arcs
|
|
|
|
std::vector<VECTOR2I> corners;
|
|
|
|
corners.reserve( 6 );
|
|
|
|
// Shape is (x = corner and arc ends, c = arc centre)
|
|
|
|
// xcx
|
|
|
|
//
|
|
|
|
// xcx
|
|
|
|
int half_height = deltaxy / 2;
|
|
|
|
corners.emplace_back( -radius, -half_height );
|
|
|
|
corners.emplace_back( -radius, half_height );
|
|
|
|
corners.emplace_back( 0, half_height );
|
|
|
|
corners.emplace_back( radius, half_height );
|
|
|
|
corners.emplace_back( radius, -half_height );
|
|
|
|
corners.emplace_back( 0, -half_height );
|
|
|
|
|
|
|
|
// Rotate and move to the actual position
|
|
|
|
for( size_t ii = 0; ii < corners.size(); ii++ )
|
|
|
|
{
|
|
|
|
RotatePoint( corners[ii], orient );
|
|
|
|
corners[ii] += aPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gen shape:
|
|
|
|
MoveTo( corners[0] );
|
|
|
|
FinishTo( corners[1] );
|
|
|
|
|
|
|
|
Arc( corners[2], orient + ANGLE_180, orient + ANGLE_360, radius, FILL_T::NO_FILL );
|
|
|
|
|
|
|
|
MoveTo( corners[3] );
|
|
|
|
FinishTo( corners[4] );
|
|
|
|
|
|
|
|
Arc( corners[5], orient, orient + ANGLE_180, radius, FILL_T::NO_FILL );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2015-02-02 08:06:39 +00:00
|
|
|
if( tracemode == FILLED )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2020-03-05 00:02:14 +00:00
|
|
|
if( start == end )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( start, width, FILL_T::FILLED_SHAPE, 0 );
|
2020-03-05 00:02:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( width );
|
|
|
|
MoveTo( start );
|
|
|
|
FinishTo( end );
|
|
|
|
}
|
2015-02-02 08:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
|
|
|
segmentAsOval( start, end, width, tracemode );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
void PLOTTER::ThickArc( const VECTOR2D& centre, const EDA_ANGLE& aStartAngle,
|
|
|
|
const EDA_ANGLE& aEndAngle, double aRadius, int aWidth,
|
2022-01-16 01:06:25 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aTraceMode == FILLED )
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
Arc( centre, aStartAngle, aEndAngle, aRadius, FILL_T::NO_FILL, aWidth );
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2015-02-02 08:06:39 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
2022-01-16 01:06:25 +00:00
|
|
|
Arc( centre, aStartAngle, aEndAngle, aRadius - ( aWidth - m_currentPenWidth ) / 2,
|
2021-07-18 23:08:54 +00:00
|
|
|
FILL_T::NO_FILL, -1 );
|
2022-01-16 01:06:25 +00:00
|
|
|
Arc( centre, aStartAngle, aEndAngle, aRadius + ( aWidth - m_currentPenWidth ) / 2,
|
2021-07-18 23:08:54 +00:00
|
|
|
FILL_T::NO_FILL, -1 );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-20 13:59:11 +00:00
|
|
|
void PLOTTER::ThickArc( const VECTOR2I& aCentre, const VECTOR2I& aStart,
|
|
|
|
const VECTOR2I& aEnd, int aWidth,
|
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
|
|
|
{
|
|
|
|
if( aTraceMode == FILLED )
|
|
|
|
{
|
|
|
|
Arc( aCentre, aStart, aEnd, FILL_T::NO_FILL, aWidth, GetPlotterArcHighDef() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( -1 );
|
|
|
|
int radius = ( aStart - aCentre ).EuclideanNorm();
|
|
|
|
|
|
|
|
int new_radius = radius - ( aWidth - m_currentPenWidth ) / 2;
|
|
|
|
VECTOR2I start = ( aStart - aCentre ).Resize( new_radius ) + aCentre;
|
|
|
|
VECTOR2I end = ( aEnd - aCentre ).Resize( new_radius ) + aCentre;
|
|
|
|
|
|
|
|
Arc( aCentre, start, end, FILL_T::NO_FILL, -1, GetPlotterArcHighDef() );
|
|
|
|
|
|
|
|
new_radius = radius + ( aWidth - m_currentPenWidth ) / 2;
|
|
|
|
start = ( aStart - aCentre ).Resize( new_radius ) + aCentre;
|
|
|
|
end = ( aEnd - aCentre ).Resize( new_radius ) + aCentre;
|
|
|
|
|
|
|
|
Arc( aCentre, start, end, FILL_T::NO_FILL, -1, GetPlotterArcHighDef() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PLOTTER::ThickArc( const EDA_SHAPE& aArcShape,
|
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
|
|
|
{
|
|
|
|
ThickArc( aArcShape.getCenter(),aArcShape.GetStart(), aArcShape.GetEnd(),
|
|
|
|
aArcShape.GetWidth(), aTraceMode, aData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2015-02-02 08:06:39 +00:00
|
|
|
if( tracemode == FILLED )
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( p1, p2, FILL_T::NO_FILL, width );
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2015-02-02 08:06:39 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I offsetp1( p1.x - ( width - m_currentPenWidth ) / 2,
|
|
|
|
p1.y - (width - m_currentPenWidth) / 2 );
|
|
|
|
VECTOR2I offsetp2( p2.x + ( width - m_currentPenWidth ) / 2,
|
|
|
|
p2.y + (width - m_currentPenWidth) / 2 );
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
|
2021-07-15 19:26:35 +00:00
|
|
|
offsetp1.x += ( width - m_currentPenWidth );
|
|
|
|
offsetp1.y += ( width - m_currentPenWidth );
|
|
|
|
offsetp2.x -= ( width - m_currentPenWidth );
|
|
|
|
offsetp2.y -= ( width - m_currentPenWidth );
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::ThickCircle( const VECTOR2I& pos, int diametre, int width, OUTLINE_MODE tracemode,
|
2020-11-14 01:16:02 +00:00
|
|
|
void* aData )
|
2009-08-29 10:20:48 +00:00
|
|
|
{
|
2015-02-02 08:06:39 +00:00
|
|
|
if( tracemode == FILLED )
|
2020-11-14 01:16:02 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::NO_FILL, width );
|
2020-11-14 01:16:02 +00:00
|
|
|
}
|
2015-02-02 08:06:39 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre - width + m_currentPenWidth, FILL_T::NO_FILL, -1 );
|
|
|
|
Circle( pos, diametre + width - m_currentPenWidth, FILL_T::NO_FILL, -1 );
|
2020-10-12 09:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::FilledCircle( const VECTOR2I& pos, int diametre, OUTLINE_MODE tracemode, void* aData )
|
2020-10-12 09:30:43 +00:00
|
|
|
{
|
|
|
|
if( tracemode == FILLED )
|
2020-11-14 01:16:02 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::FILLED_SHAPE, 0 );
|
2020-11-14 01:16:02 +00:00
|
|
|
}
|
2020-10-12 09:30:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( -1 );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::NO_FILL, -1 );
|
2009-08-29 10:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int aWidth, void* aData )
|
2017-11-16 11:09:24 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> cornerList;
|
2019-12-05 15:20:59 +00:00
|
|
|
cornerList.reserve( aCornerList.PointCount() );
|
2017-11-16 11:09:24 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < aCornerList.PointCount(); ii++ )
|
2019-12-05 15:41:21 +00:00
|
|
|
cornerList.emplace_back( aCornerList.CPoint( ii ) );
|
2017-11-16 11:09:24 +00:00
|
|
|
|
2019-08-20 13:45:57 +00:00
|
|
|
if( aCornerList.IsClosed() && cornerList.front() != cornerList.back() )
|
2019-12-05 15:41:21 +00:00
|
|
|
cornerList.emplace_back( aCornerList.CPoint( 0 ) );
|
2019-08-20 13:45:57 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
PlotPoly( cornerList, aFill, aWidth, aData );
|
2017-11-16 11:09:24 +00:00
|
|
|
}
|
2021-12-28 22:13:54 +00:00
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void PLOTTER::Text( const VECTOR2I& aPos,
|
|
|
|
const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const EDA_ANGLE& aOrient,
|
2022-01-10 01:53:01 +00:00
|
|
|
const VECTOR2I& aSize,
|
2021-12-29 19:02:50 +00:00
|
|
|
enum GR_TEXT_H_ALIGN_T aH_justify,
|
|
|
|
enum GR_TEXT_V_ALIGN_T aV_justify,
|
|
|
|
int aPenWidth,
|
|
|
|
bool aItalic,
|
|
|
|
bool aBold,
|
|
|
|
bool aMultilineAllowed,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
void* aData )
|
2021-12-28 22:13:54 +00:00
|
|
|
{
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
SetColor( aColor );
|
|
|
|
SetCurrentLineWidth( aPenWidth, aData );
|
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
if( aPenWidth == 0 && aBold ) // Use default values if aPenWidth == 0
|
|
|
|
aPenWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
|
|
|
|
|
|
|
|
if( aPenWidth < 0 )
|
|
|
|
aPenWidth = -aPenWidth;
|
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
CALLBACK_GAL callback_gal( empty_opts,
|
2022-01-10 01:53:01 +00:00
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
MoveTo( aPt1 );
|
|
|
|
LineTo( aPt2 );
|
2022-01-10 01:53:01 +00:00
|
|
|
PenFinish();
|
|
|
|
},
|
2022-01-14 01:04:14 +00:00
|
|
|
// Polygon callback
|
|
|
|
[&]( const SHAPE_LINE_CHAIN& aPoly )
|
2022-01-10 01:53:01 +00:00
|
|
|
{
|
2022-01-14 01:04:14 +00:00
|
|
|
PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
|
2022-01-10 01:53:01 +00:00
|
|
|
} );
|
2022-01-10 14:03:53 +00:00
|
|
|
|
|
|
|
TEXT_ATTRIBUTES attributes;
|
|
|
|
attributes.m_Angle = aOrient;
|
|
|
|
attributes.m_StrokeWidth = aPenWidth;
|
|
|
|
attributes.m_Italic = aItalic;
|
|
|
|
attributes.m_Bold = aBold;
|
|
|
|
attributes.m_Halign = aH_justify;
|
|
|
|
attributes.m_Valign = aV_justify;
|
2022-01-11 19:47:16 +00:00
|
|
|
attributes.m_Size = aSize;
|
2022-01-10 14:03:53 +00:00
|
|
|
|
2023-02-22 15:19:08 +00:00
|
|
|
// if Size.x is < 0, the text is mirrored (we have no other param to know a text is mirrored)
|
|
|
|
if( attributes.m_Size.x < 0 )
|
|
|
|
{
|
|
|
|
attributes.m_Size.x = -attributes.m_Size.x;
|
|
|
|
attributes.m_Mirrored = true;
|
|
|
|
}
|
|
|
|
|
2022-01-11 19:05:16 +00:00
|
|
|
if( !aFont )
|
|
|
|
aFont = KIFONT::FONT::GetFont();
|
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
aFont->Draw( &callback_gal, aText, aPos, attributes );
|
2021-12-28 22:13:54 +00:00
|
|
|
}
|
2023-02-24 08:44:25 +00:00
|
|
|
|
|
|
|
void PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttributes,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
void* aData )
|
|
|
|
{
|
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
|
|
|
|
|
|
|
TEXT_ATTRIBUTES attributes = aAttributes;
|
|
|
|
int penWidth = attributes.m_StrokeWidth;
|
|
|
|
|
|
|
|
SetColor( aColor );
|
|
|
|
SetCurrentLineWidth( penWidth, aData );
|
|
|
|
|
|
|
|
if( penWidth == 0 && attributes.m_Bold ) // Use default values if aPenWidth == 0
|
|
|
|
penWidth = GetPenSizeForBold( std::min( attributes.m_Size.x, attributes.m_Size.y ) );
|
|
|
|
|
|
|
|
if( penWidth < 0 )
|
|
|
|
penWidth = -penWidth;
|
|
|
|
|
|
|
|
attributes.m_StrokeWidth = penWidth;
|
|
|
|
|
|
|
|
CALLBACK_GAL callback_gal( empty_opts,
|
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
MoveTo( aPt1 );
|
|
|
|
LineTo( aPt2 );
|
|
|
|
PenFinish();
|
|
|
|
},
|
|
|
|
// Polygon callback
|
|
|
|
[&]( const SHAPE_LINE_CHAIN& aPoly )
|
|
|
|
{
|
|
|
|
PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( !aFont )
|
|
|
|
aFont = KIFONT::FONT::GetFont();
|
|
|
|
|
|
|
|
aFont->Draw( &callback_gal, aText, aPos, attributes );
|
|
|
|
}
|