2020-09-23 18:58:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-08-06 19:20:53 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-09-23 18:58:13 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include "plotter.h"
|
2020-09-23 18:58:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DXF_PLOTTER : public PLOTTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DXF_PLOTTER() : m_textAsLines( false )
|
|
|
|
{
|
|
|
|
m_textAsLines = true;
|
|
|
|
m_currentColor = COLOR4D::BLACK;
|
2023-11-25 13:05:45 +00:00
|
|
|
m_currentLineType = LINE_STYLE::SOLID;
|
2020-09-23 18:58:13 +00:00
|
|
|
SetUnits( DXF_UNITS::INCHES );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PLOT_FORMAT GetPlotterType() const override
|
|
|
|
{
|
|
|
|
return PLOT_FORMAT::DXF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxString GetDefaultFileExtension()
|
|
|
|
{
|
|
|
|
return wxString( wxT( "dxf" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF handles NATIVE text emitting TEXT entities
|
|
|
|
*/
|
|
|
|
virtual void SetTextMode( PLOT_TEXT_MODE mode ) override
|
|
|
|
{
|
|
|
|
if( mode != PLOT_TEXT_MODE::DEFAULT )
|
|
|
|
m_textAsLines = ( mode != PLOT_TEXT_MODE::NATIVE );
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
/**
|
2021-08-17 19:41:08 +00:00
|
|
|
* Open the DXF plot with a skeleton header.
|
2021-06-07 18:31:53 +00:00
|
|
|
*/
|
2022-08-27 18:14:57 +00:00
|
|
|
virtual bool StartPlot( const wxString& aPageNumber ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
virtual bool EndPlot() override;
|
|
|
|
|
|
|
|
// For now we don't use 'thick' primitives, so no line width
|
2021-06-07 18:31:53 +00:00
|
|
|
virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override
|
2020-09-23 18:58:13 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_currentPenWidth = 0;
|
2020-09-23 18:58:13 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
/**
|
|
|
|
* The DXF exporter handles 'colors' as layers...
|
|
|
|
*/
|
|
|
|
virtual void SetColor( const COLOR4D& color ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
/**
|
|
|
|
* Set the scale/position for the DXF plot.
|
|
|
|
*
|
|
|
|
* The DXF engine doesn't support line widths and mirroring. The output
|
|
|
|
* coordinate system is in the first quadrant (in mm).
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
|
2021-06-07 18:31:53 +00:00
|
|
|
double aScale, bool aMirror ) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF rectangle: fill not supported.
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill,
|
2020-09-23 18:58:13 +00:00
|
|
|
int width = USE_DEFAULT_LINE_WIDTH ) override;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF circle: full functionality; it even does 'fills' drawing a
|
|
|
|
* circle with a dual-arc polyline wide as the radius.
|
|
|
|
*
|
|
|
|
* I could use this trick to do other filled primitives.
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void Circle( const VECTOR2I& pos, int diametre, FILL_T fill,
|
2020-09-23 18:58:13 +00:00
|
|
|
int width = USE_DEFAULT_LINE_WIDTH ) override;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2023-08-22 13:06:53 +00:00
|
|
|
virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
|
|
|
|
const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth ) override;
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
/**
|
|
|
|
* DXF polygon: doesn't fill it but at least it close the filled ones
|
|
|
|
* DXF does not know thick outline.
|
|
|
|
*
|
|
|
|
* It does not know thick segments, therefore filled polygons with thick outline
|
|
|
|
* are converted to inflated polygon by aWidth/2.
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill,
|
2021-06-07 18:31:53 +00:00
|
|
|
int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData ) override;
|
2022-09-20 16:29:29 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void PenTo( const VECTOR2I& pos, char plume ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
/**
|
|
|
|
* DXF round pad: always done in sketch mode; it could be filled but it isn't
|
|
|
|
* pretty if other kinds of pad aren't...
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void FlashPadCircle( const VECTOR2I& pos, int diametre,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE trace_mode, void* aData ) override;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF oval pad: always done in sketch mode.
|
|
|
|
*/
|
2022-01-16 01:06:25 +00:00
|
|
|
virtual void FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData ) override;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF rectangular pad: always done in sketch mode.
|
|
|
|
*/
|
2022-01-16 01:06:25 +00:00
|
|
|
virtual void FlashPadRect( const VECTOR2I& aPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData ) override;
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
|
2022-01-16 01:06:25 +00:00
|
|
|
int aCornerRadius, const EDA_ANGLE& aOrient,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData ) override;
|
2022-01-16 01:06:25 +00:00
|
|
|
virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, SHAPE_POLY_SET* aPolygons,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData ) override;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DXF trapezoidal pad: only sketch mode is supported.
|
|
|
|
*/
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData ) override;
|
2021-12-29 19:02:50 +00:00
|
|
|
virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2022-06-28 18:21:00 +00:00
|
|
|
virtual void Text( const VECTOR2I& aPos,
|
|
|
|
const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const EDA_ANGLE& aOrient,
|
|
|
|
const VECTOR2I& aSize,
|
|
|
|
enum GR_TEXT_H_ALIGN_T aH_justify,
|
|
|
|
enum GR_TEXT_V_ALIGN_T aV_justify,
|
|
|
|
int aWidth,
|
|
|
|
bool aItalic,
|
|
|
|
bool aBold,
|
2023-08-06 19:20:53 +00:00
|
|
|
bool aMultilineAllowed,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
const KIFONT::METRICS& aFontMetrics,
|
2022-06-28 18:21:00 +00:00
|
|
|
void* aData = nullptr ) override;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
virtual void PlotText( const VECTOR2I& aPos,
|
|
|
|
const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttributes,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
const KIFONT::METRICS& aFontMetrics,
|
|
|
|
void* aData = nullptr ) override;
|
|
|
|
|
2020-09-23 18:58:13 +00:00
|
|
|
/**
|
|
|
|
* Set the units to use for plotting the DXF file.
|
|
|
|
*
|
|
|
|
* @param aUnit - The units to use
|
|
|
|
*/
|
|
|
|
void SetUnits( DXF_UNITS aUnit );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The units currently enabled for plotting
|
|
|
|
*
|
|
|
|
* @return The currently configured units
|
|
|
|
*/
|
|
|
|
DXF_UNITS GetUnits() const
|
|
|
|
{
|
|
|
|
return m_plotUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scale factor to apply to convert the device units to be in the
|
|
|
|
* currently set units.
|
|
|
|
*
|
|
|
|
* @return Scaling factor to apply for unit conversion
|
|
|
|
*/
|
|
|
|
double GetUnitScaling() const
|
|
|
|
{
|
|
|
|
return m_unitScalingFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the correct value for the $MEASUREMENT field given the current units
|
|
|
|
*
|
|
|
|
* @return the $MEASUREMENT directive field value
|
|
|
|
*/
|
|
|
|
unsigned int GetMeasurementDirective() const
|
|
|
|
{
|
|
|
|
return m_measurementDirective;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2023-08-06 19:20:53 +00:00
|
|
|
void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttrs );
|
2023-02-24 08:44:25 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
bool m_textAsLines;
|
|
|
|
COLOR4D m_currentColor;
|
|
|
|
LINE_STYLE m_currentLineType;
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
DXF_UNITS m_plotUnits;
|
|
|
|
double m_unitScalingFactor;
|
|
|
|
unsigned int m_measurementDirective;
|
2020-09-23 18:58:13 +00:00
|
|
|
};
|