diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp index 22b0112f4e..d4279933f4 100644 --- a/common/plotters/DXF_plotter.cpp +++ b/common/plotters/DXF_plotter.cpp @@ -26,11 +26,10 @@ */ -#include -#include +#include #include #include -#include +#include #include #include #include diff --git a/common/plotters/GERBER_plotter.cpp b/common/plotters/GERBER_plotter.cpp index 6187e4807a..e661d24120 100644 --- a/common/plotters/GERBER_plotter.cpp +++ b/common/plotters/GERBER_plotter.cpp @@ -4,22 +4,18 @@ * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2020 KiCad Developers, see AUTHORS.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 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. + * 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 + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ /** @@ -27,20 +23,17 @@ * @brief specialized plotter for GERBER files format */ -#include -#include -#include +#include #include #include -#include -#include -#include #include #include #include // for KiROUND #include +#include "plotter_gerber.h" + #include @@ -346,6 +339,7 @@ void GERBER_PLOTTER::selectAperture( const wxSize& aSize, } } + void GERBER_PLOTTER::selectAperture( int aDiameter, double aPolygonRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute ) { diff --git a/common/plotters/HPGL_plotter.cpp b/common/plotters/HPGL_plotter.cpp index 2949b30060..96597adeeb 100644 --- a/common/plotters/HPGL_plotter.cpp +++ b/common/plotters/HPGL_plotter.cpp @@ -194,17 +194,15 @@ */ -#include -#include -#include +#include #include #include -#include -#include #include #include #include // for KiROUND +#include "plotter_hpgl.h" + // The hpgl command to close a polygon def, fill it and plot outline: // PM 2; ends the polygon definition and closes it if not closed diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index 9bef072c1f..311139b354 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -40,6 +39,9 @@ #include +#include "plotters_pslike.h" + + std::string PDF_PLOTTER::encodeStringForPlotter( const wxString& aText ) { diff --git a/common/plotters/PS_plotter.cpp b/common/plotters/PS_plotter.cpp index f21e6ad4e8..3d8ab4554b 100644 --- a/common/plotters/PS_plotter.cpp +++ b/common/plotters/PS_plotter.cpp @@ -27,16 +27,15 @@ * @brief Kicad: specialized plotter for PS files format */ -#include -#include +#include #include #include -#include -#include -#include #include #include // for KiROUND +#include "plotters_pslike.h" + + /* Forward declaration of the font width metrics (yes extern! this is the way to forward declare variables */ extern const double hv_widths[256]; diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index 5124c67ead..b42dccbf24 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -91,20 +91,20 @@ * The center of ellipse is automatically calculated. */ +#include #include -#include -#include #include #include #include #include -#include -#include #include #include #include +#include "plotters_pslike.h" + + /** * Function XmlEsc * translates '<' to "<", '>' to ">" and so on, according to the spec: diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index aaa0813813..247b732671 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/common/plotters/gbr_plotter_apertures.h b/common/plotters/gbr_plotter_apertures.h new file mode 100644 index 0000000000..45c0a2341c --- /dev/null +++ b/common/plotters/gbr_plotter_apertures.h @@ -0,0 +1,125 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engine (Gerber) + * + * @file gbr_plotter_apertures.h + */ + +#pragma once + + +/* Class to handle a D_CODE when plotting a board using Standard Aperture Templates + * (complex apertures need aperture macros to be flashed) + * 5 types: + * Circle (round) + * Rectangle + * Obround (oval) + * regular polygon + * + * We need round apertures to plot lines, so we also defined a aperture type for plotting + */ +#define FIRST_DCODE_VALUE 10 // D_CODE < 10 is a command, D_CODE >= 10 is a tool + +class APERTURE +{ +public: + enum APERTURE_TYPE { + AT_CIRCLE = 1, // round aperture, to flash pads + AT_RECT = 2, // rect aperture, to flash pads + AT_PLOTTING = 3, // round aperture, to plot lines + AT_OVAL = 4, // oval aperture, to flash pads + AT_REGULAR_POLY = 5,// Regular polygon (n vertices, n = 3 .. 12, with rotation) + AT_REGULAR_POLY3, // Regular polygon 3 vertices, with rotation + AT_REGULAR_POLY4, // Regular polygon 4 vertices, with rotation + AT_REGULAR_POLY5, // Regular polygon 5 vertices, with rotation + AT_REGULAR_POLY6, // Regular polygon 6 vertices, with rotation + AT_REGULAR_POLY7, // Regular polygon 7 vertices, with rotation + AT_REGULAR_POLY8, // Regular polygon 8 vertices, with rotation + AT_REGULAR_POLY9, // Regular polygon 9 vertices, with rotation + AT_REGULAR_POLY10, // Regular polygon 10 vertices, with rotation + AT_REGULAR_POLY11, // Regular polygon 11 vertices, with rotation + AT_REGULAR_POLY12, // Regular polygon 12 vertices, with rotation + }; + + void SetSize( const wxSize& aSize ) + { + m_Size = aSize; + } + + const wxSize GetSize() + { + return m_Size; + } + + void SetDiameter( int aDiameter ) + { + m_Size.x = aDiameter; + } + + int GetDiameter() + { + return m_Size.x; + } + + void SetVerticeCount( int aCount ) + { + if( aCount < 3 ) + aCount = 3; + else if( aCount > 12 ) + aCount = 12; + + m_Type = (APERTURE_TYPE)(AT_REGULAR_POLY3 - 3 + aCount); + } + + int GetVerticeCount() + { + return m_Type - AT_REGULAR_POLY3 + 3; + } + + void SetRotation( double aRotDegree ) + { + // The rotation is stored in 1/1000 degree + m_Size.y = int( aRotDegree * 1000.0 ); + } + + double GetRotation() + { + // The rotation is stored in 1/1000 degree + return m_Size.y / 1000.0; + } + + // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices ) + APERTURE_TYPE m_Type; + + // horiz and Vert size, or diameter and rotation for regular polygon + // The diameter (for circle and polygons) is stored in m_Size.x + // the rotation is stored in m_Size.y in 1/1000 degree + wxSize m_Size; + + // code number ( >= 10 ) + int m_DCode; + + // the attribute attached to this aperture + // Only one attribute is allowed by aperture + // 0 = no specific aperture attribute + int m_ApertureAttribute; +}; diff --git a/common/plotters/plotter_dxf.h b/common/plotters/plotter_dxf.h new file mode 100644 index 0000000000..f983a3749c --- /dev/null +++ b/common/plotters/plotter_dxf.h @@ -0,0 +1,175 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engine (DXF) + * + * @file plotter_dxf.h + */ + +#pragma once + +#include +#include +#include // FILL_T +#include + + +class DXF_PLOTTER : public PLOTTER +{ +public: + DXF_PLOTTER() : m_textAsLines( false ) + { + m_textAsLines = true; + m_currentColor = COLOR4D::BLACK; + m_currentLineType = PLOT_DASH_TYPE::SOLID; + 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 ); + } + + virtual bool StartPlot() override; + virtual bool EndPlot() override; + + // For now we don't use 'thick' primitives, so no line width + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override + { + currentPenWidth = 0; + } + + virtual void SetDash( PLOT_DASH_TYPE dashed ) override; + + virtual void SetColor( COLOR4D color ) override; + + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, void * aData = NULL ) override; + virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, + EDA_DRAW_MODE_T tracemode, void* aData ) override; + virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void PenTo( const wxPoint& pos, char plume ) override; + + virtual void FlashPadCircle( const wxPoint& pos, int diametre, + EDA_DRAW_MODE_T trace_mode, void* aData ) override; + virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient, + EDA_DRAW_MODE_T trace_mode, void* aData ) override; + virtual void FlashPadRect( const wxPoint& pos, const wxSize& size, + double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override; + virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, + int aCornerRadius, double aOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, + SHAPE_POLY_SET* aPolygons, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, + double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, + double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + + virtual void Text( const wxPoint& aPos, + const COLOR4D aColor, + const wxString& aText, + double aOrient, + const wxSize& aSize, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed = false, + void* aData = NULL ) override; + + + // Must be in the same order as the drop-down list in the plot dialog inside pcbnew + enum class DXF_UNITS + { + INCHES = 0, + MILLIMETERS = 1 + }; + + /** + * 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: + bool m_textAsLines; + COLOR4D m_currentColor; + PLOT_DASH_TYPE m_currentLineType; + + DXF_UNITS m_plotUnits; + double m_unitScalingFactor; + unsigned int m_measurementDirective; +}; diff --git a/common/plotters/plotter_gerber.h b/common/plotters/plotter_gerber.h new file mode 100644 index 0000000000..40b48318a8 --- /dev/null +++ b/common/plotters/plotter_gerber.h @@ -0,0 +1,306 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engine (Gerber) + * + * @file plotter_gerber.h + */ + +#pragma once + +#include +#include +#include // FILL_T + +#include +#include "gbr_plotter_apertures.h" + + +class GERBER_PLOTTER : public PLOTTER +{ +public: + GERBER_PLOTTER(); + + virtual PLOT_FORMAT GetPlotterType() const override + { + return PLOT_FORMAT::GERBER; + } + + static wxString GetDefaultFileExtension() + { + return wxString( wxT( "gbr" ) ); + } + + /** + * Function StartPlot + * Write GERBER header to file + * initialize global variable g_Plot_PlotOutputFile + */ + virtual bool StartPlot() override; + virtual bool EndPlot() override; + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; + + // RS274X has no dashing, nor colours + virtual void SetDash( PLOT_DASH_TYPE dashed ) override + { + } + + virtual void SetColor( COLOR4D color ) override {} + // Currently, aScale and aMirror are not used in gerber plotter + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle, + int aRadius, FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH ) override; + + virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, + EDA_DRAW_MODE_T tracemode, void* aData ) override; + + virtual void ThickArc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, int width, EDA_DRAW_MODE_T tracemode, void* aData ) override; + virtual void ThickRect( const wxPoint& p1, const wxPoint& p2, int width, + EDA_DRAW_MODE_T tracemode, void* aData ) override; + virtual void ThickCircle( const wxPoint& pos, int diametre, int width, + EDA_DRAW_MODE_T tracemode, void* aData ) override; + /** + * Gerber polygon: they can (and *should*) be filled with the + * appropriate G36/G37 sequence + */ + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, + void* aData = nullptr ) override; + + virtual void PenTo( const wxPoint& pos, char plume ) override; + + virtual void Text( const wxPoint& aPos, + const COLOR4D aColor, + const wxString& aText, + double aOrient, + const wxSize& aSize, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed = false, + void* aData = NULL ) override; + + /** + * Filled circular flashes are stored as apertures + */ + virtual void FlashPadCircle( const wxPoint& pos, int diametre, + EDA_DRAW_MODE_T trace_mode, void* aData ) override; + + /** + * Filled oval flashes are handled as aperture in the 90 degree positions only + */ + virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient, + EDA_DRAW_MODE_T trace_mode, void* aData ) override; + /** + * Filled rect flashes are handled as aperture in the 0 90 180 or 270 degree orientation only + * and as polygon for other orientations + * TODO: always use flashed shapes (aperture macros) + */ + virtual void FlashPadRect( const wxPoint& pos, const wxSize& size, + double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override; + + /** + * Roundrect pad at the moment are not handled as aperture, since + * they require aperture macros + * TODO: always use flashed shapes (aperture macros) + */ + virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, + int aCornerRadius, double aOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, + SHAPE_POLY_SET* aPolygons, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + /** + * Trapezoidal pad at the moment are *never* handled as aperture, since + * they require aperture macros + * TODO: always use flashed shapes (aperture macros) + */ + virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, + double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + + virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, + double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + + /** + * Plot a Gerber region: similar to PlotPoly but plot only filled polygon, + * and add the TA.AperFunction if aData contains this attribute, and clear it + * after plotting + */ + void PlotGerberRegion( const std::vector< wxPoint >& aCornerList, + void * aData = NULL ); + + /** + * Change the plot polarity and begin a new layer + * Used to 'scratch off' silk screen away from solder mask + */ + virtual void SetLayerPolarity( bool aPositive ) override; + + /** + * Function SetGerberCoordinatesFormat + * selection of Gerber units and resolution (number of digits in mantissa) + * @param aResolution = number of digits in mantissa of coordinate + * use 5 or 6 for mm and 6 or 7 for inches + * do not use value > 6 (mm) or > 7 (in) to avoid overflow + * @param aUseInches = true to use inches, false to use mm (default) + * + * Should be called only after SetViewport() is called + */ + virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override; + + void UseX2format( bool aEnable ) { m_useX2format = aEnable; } + void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; } + + /** + * calling this function allows one to define the beginning of a group + * of drawing items (used in X2 format with netlist attributes) + * @param aData can define any parameter + */ + virtual void StartBlock( void* aData ) override; + + /** + * calling this function allows one to define the end of a group of drawing + * items the group is started by StartBlock() + * (used in X2 format with netlist attributes) + * @param aData can define any parameter + */ + virtual void EndBlock( void* aData ) override; + + /** Remove (clear) all attributes from object attributes dictionary (TO. and TA commands) + * similar to clearNetAttribute(), this is an unconditional reset of TO. and TA. attributes + */ + void ClearAllAttributes(); + + /** + * @return a index to the aperture in aperture list which meets the size and type of tool + * if the aperture does not exist, it is created and entered in aperture list + * @param aSize = the size of tool + * @param aType = the type ( shape ) of tool + * @param aApertureAttribute = an aperture attribute of the tool (a tool can have onlu one attribute) + * 0 = no specific attribute + */ + int GetOrCreateAperture( const wxSize& aSize, + APERTURE::APERTURE_TYPE aType, int aApertureAttribute ); + +protected: + /** Plot a round rect (a round rect shape in fact) as a Gerber region + * using lines and arcs for corners + * @param aRectCenter is the center of the rectangle + * @param aSize is the size of the rectangle + * @param aCornerRadius is the radius of the corners + * @param aOrient is the rotation of the rectangle + * Note: only the G36 ... G37 region is created. + */ + void plotRoundRectAsRegion( const wxPoint& aRectCenter, const wxSize& aSize, + int aCornerRadius, double aOrient ); + /** + * Plot a Gerber arc. + * if aPlotInRegion = true, the current pen position will not be + * initialized to the arc start position, and therefore the arc can be used + * to define a region outline item + * a line will be created from current ^position to arc start point + * if aPlotInRegion = false, the current pen position will be initialized + * to the arc start position, to plot an usual arc item + * The line thickness is not initialized in plotArc, and must be initialized + * before calling it if needed. + */ + void plotArc( const wxPoint& aCenter, double aStAngle, double aEndAngle, + int aRadius, bool aPlotInRegion ); + + /** + * Pick an existing aperture or create a new one, matching the + * size, type and attributes. + * write the DCode selection on gerber file + */ + void selectAperture( const wxSize& aSize, APERTURE::APERTURE_TYPE aType, + int aApertureAttribute ); + /** + * Pick an existing aperture or create a new one, matching the + * aDiameter, aPolygonRotation, type and attributes. + * It apply only to apertures with type = AT_REGULAR_POLY3 to AT_REGULAR_POLY12 + * write the DCode selection on gerber file + */ + void selectAperture( int aDiameter, double aPolygonRotation, + APERTURE::APERTURE_TYPE aType, int aApertureAttribute ); + + /** + * Emit a D-Code record, using proper conversions + * to format a leading zero omitted gerber coordinate + * (for n decimal positions, see header generation in start_plot + */ + void emitDcode( const DPOINT& pt, int dcode ); + + /** + * print a Gerber net attribute object record. + * In a gerber file, a net attribute is owned by a graphic object + * formatNetAttribute must be called before creating the object + * @param aData contains the dato to format. + * the generated string depends on the type of netlist info + */ + void formatNetAttribute( GBR_NETLIST_METADATA* aData ); + + /** + * clear a Gerber net attribute record (clear object attribute dictionary) + * and output the clear object attribute dictionary command to gerber file + * has effect only if a net attribute is stored in m_objectAttributesDictionnary + */ + void clearNetAttribute(); + + // the attributes dictionary created/modifed by %TO, attached to objects, when they are created + // by D01, D03, G36/G37 commands + // standard attributes are .P, .C and .N + // this is used by gerber readers when creating a new object. Cleared by %TD command + // Note: m_objectAttributesDictionnary can store more than one attribute + // the string stores the line(s) actually written to the gerber file + // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL) + std::string m_objectAttributesDictionnary; + + // The last aperture attribute generated (only one aperture attribute can be set) + int m_apertureAttribute; + + FILE* workFile; + FILE* finalFile; + wxString m_workFilename; + + /** + * Generate the table of D codes + */ + void writeApertureList(); + + std::vector m_apertures; // The list of available apertures + int m_currentApertureIdx; // The index of the current aperture in m_apertures + + bool m_gerberUnitInch; // true if the gerber units are inches, false for mm + int m_gerberUnitFmt; // number of digits in mantissa. + // usually 6 in Inches and 5 or 6 in mm + bool m_useX2format; // Add X2 file header attributes. If false, attributes + // will be added as comments. + bool m_useNetAttributes; // In recent gerber files, netlist info can be added. + // It will be added if this param is true, using X2 or + // X1 format +}; diff --git a/common/plotters/plotter_hpgl.h b/common/plotters/plotter_hpgl.h new file mode 100644 index 0000000000..3807792c3a --- /dev/null +++ b/common/plotters/plotter_hpgl.h @@ -0,0 +1,116 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engine (HPGL) + * + * @file plotter_hpgl.h + */ + +#pragma once + +#include +#include +#include // FILL_T +#include + + +class HPGL_PLOTTER : public PLOTTER +{ +public: + HPGL_PLOTTER(); + + virtual PLOT_FORMAT GetPlotterType() const override + { + return PLOT_FORMAT::HPGL; + } + + static wxString GetDefaultFileExtension() + { + return wxString( wxT( "plt" ) ); + } + + virtual bool StartPlot() override; + virtual bool EndPlot() override; + + /// HPGL doesn't handle line thickness or color + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override + { + // This is the truth + currentPenWidth = userToDeviceSize( penDiameter ); + } + + virtual void SetDash( PLOT_DASH_TYPE dashed ) override; + + virtual void SetColor( COLOR4D color ) override {} + + virtual void SetPenSpeed( int speed ) + { + penSpeed = speed; + } + + virtual void SetPenNumber( int number ) + { + penNumber = number; + } + + virtual void SetPenDiameter( double diameter ); + + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, + void * aData = NULL) override; + + virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, + EDA_DRAW_MODE_T tracemode, void* aData ) override; + virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void PenTo( const wxPoint& pos, char plume ) override; + virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize, + double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, + int aCornerRadius, double aOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, + SHAPE_POLY_SET* aPolygons, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, + double aPadOrient, EDA_DRAW_MODE_T aTraceMode, + void* aData ) override; + virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, + double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + +protected: + void penControl( char plume ); + + int penSpeed; + int penNumber; + double penDiameter; +}; + + diff --git a/common/plotters/plotters_pslike.h b/common/plotters/plotters_pslike.h new file mode 100644 index 0000000000..46568e8a4a --- /dev/null +++ b/common/plotters/plotters_pslike.h @@ -0,0 +1,414 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engines similar to ps (Postscript, Gerber, svg) + * + * @file plotters_pslike.h + */ + +#pragma once + +#include +#include +#include // FILL_T +#include + + +/** + * The PSLIKE_PLOTTER class is an intermediate class to handle common + * routines for engines working more or less with the postscript imaging + * model + */ +class PSLIKE_PLOTTER : public PLOTTER +{ +public: + PSLIKE_PLOTTER() : + plotScaleAdjX( 1 ), + plotScaleAdjY( 1 ), + m_textMode( PLOT_TEXT_MODE::PHANTOM ) + { + } + + /** + * PS and PDF fully implement native text (for the Latin-1 subset) + */ + virtual void SetTextMode( PLOT_TEXT_MODE mode ) override + { + if( mode != PLOT_TEXT_MODE::DEFAULT ) + m_textMode = mode; + } + + /** + * Set the 'fine' scaling for the postscript engine + */ + void SetScaleAdjust( double scaleX, double scaleY ) + { + plotScaleAdjX = scaleX; + plotScaleAdjY = scaleY; + } + + // Pad routines are handled with lower level primitives + virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize, + double aPadOrient, EDA_DRAW_MODE_T aTraceMode, + void* aData ) override; + virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, + int aCornerRadius, double aOrient, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, + SHAPE_POLY_SET* aPolygons, + EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, + double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, + double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; + + /** The SetColor implementation is split with the subclasses: + * The PSLIKE computes the rgb values, the subclass emits the + * operator to actually do it + */ + virtual void SetColor( COLOR4D color ) override; + +protected: + void computeTextParameters( const wxPoint& aPos, + const wxString& aText, + int aOrient, + const wxSize& aSize, + bool aMirror, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + double *wideningFactor, + double *ctm_a, + double *ctm_b, + double *ctm_c, + double *ctm_d, + double *ctm_e, + double *ctm_f, + double *heightFactor ); + void postscriptOverlinePositions( const wxString& aText, int aXSize, + bool aItalic, bool aBold, + std::vector *pos_pairs ); + + /// convert a wxString unicode string to a char string compatible with the accepted + /// string plotter format (convert special chars and non ascii7 chars) + virtual std::string encodeStringForPlotter( const wxString& aUnicode ); + + /// Virtual primitive for emitting the setrgbcolor operator + virtual void emitSetRGBColor( double r, double g, double b ) = 0; + + /// Height of the postscript font (from the AFM) + static const double postscriptTextAscent; // = 0.718; + + int returnPostscriptTextWidth( const wxString& aText, int aXSize, + bool aItalic, bool aBold ); + + /// Fine user scale adjust ( = 1.0 if no correction) + double plotScaleAdjX, plotScaleAdjY; + + /// How to draw text + PLOT_TEXT_MODE m_textMode; +}; + + +class PS_PLOTTER : public PSLIKE_PLOTTER +{ +public: + PS_PLOTTER() + { + // The phantom plot in postscript is an hack and reportedly + // crashes Adobe's own postscript interpreter! + m_textMode = PLOT_TEXT_MODE::STROKE; + } + + static wxString GetDefaultFileExtension() + { + return wxString( wxT( "ps" ) ); + } + + virtual PLOT_FORMAT GetPlotterType() const override + { + return PLOT_FORMAT::POST; + } + + virtual bool StartPlot() override; + virtual bool EndPlot() override; + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; + virtual void SetDash( PLOT_DASH_TYPE dashed ) override; + + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; + + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, + void * aData = NULL ) override; + + virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, + double aScaleFactor ) override; + + virtual void PenTo( const wxPoint& pos, char plume ) override; + virtual void Text( const wxPoint& aPos, + const COLOR4D aColor, + const wxString& aText, + double aOrient, + const wxSize& aSize, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed = false, + void* aData = NULL ) override; +protected: + virtual void emitSetRGBColor( double r, double g, double b ) override; +}; + +class PDF_PLOTTER : public PSLIKE_PLOTTER +{ +public: + PDF_PLOTTER() : + pageTreeHandle( 0 ), + fontResDictHandle( 0 ), + pageStreamHandle( 0 ), + streamLengthHandle( 0 ), + workFile( nullptr ) + { + } + + virtual PLOT_FORMAT GetPlotterType() const override + { + return PLOT_FORMAT::PDF; + } + + static wxString GetDefaultFileExtension() + { + return wxString( wxT( "pdf" ) ); + } + + /** + * Open or create the plot file aFullFilename + * @param aFullFilename = the full file name of the file to create + * @return true if success, false if the file cannot be created/opened + * + * The base class open the file in text mode, so we should have this + * function overlaid for PDF files, which are binary files + */ + virtual bool OpenFile( const wxString& aFullFilename ) override; + + virtual bool StartPlot() override; + virtual bool EndPlot() override; + virtual void StartPage(); + virtual void ClosePage(); + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; + virtual void SetDash( PLOT_DASH_TYPE dashed ) override; + + /** PDF can have multiple pages, so SetPageSettings can be called + * with the outputFile open (but not inside a page stream!) */ + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; + + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, + void * aData = NULL ) override; + + virtual void PenTo( const wxPoint& pos, char plume ) override; + + virtual void Text( const wxPoint& aPos, + const COLOR4D aColor, + const wxString& aText, + double aOrient, + const wxSize& aSize, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed = false, + void* aData = NULL ) override; + + virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, + double aScaleFactor ) override; + + +protected: + /// convert a wxString unicode string to a char string compatible with the accepted + /// string PDF format (convert special chars and non ascii7 chars) + std::string encodeStringForPlotter( const wxString& aUnicode ) override; + + virtual void emitSetRGBColor( double r, double g, double b ) override; + int allocPdfObject(); + int startPdfObject(int handle = -1); + void closePdfObject(); + int startPdfStream(int handle = -1); + void closePdfStream(); + int pageTreeHandle; /// Handle to the root of the page tree object + int fontResDictHandle; /// Font resource dictionary + std::vector pageHandles;/// Handles to the page objects + int pageStreamHandle; /// Handle of the page content object + int streamLengthHandle; /// Handle to the deferred stream length + wxString workFilename; + FILE* workFile; /// Temporary file to costruct the stream before zipping + std::vector xrefTable; /// The PDF xref offset table +}; + +class SVG_PLOTTER : public PSLIKE_PLOTTER +{ +public: + SVG_PLOTTER(); + + static wxString GetDefaultFileExtension() + { + return wxString( wxT( "svg" ) ); + } + + virtual PLOT_FORMAT GetPlotterType() const override + { + return PLOT_FORMAT::SVG; + } + + virtual void SetColor( COLOR4D color ) override; + virtual bool StartPlot() override; + virtual bool EndPlot() override; + virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; + virtual void SetDash( PLOT_DASH_TYPE dashed ) override; + + virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, + double aScale, bool aMirror ) override; + virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, + int width = USE_DEFAULT_LINE_WIDTH ) override; + virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, + int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; + + virtual void BezierCurve( const wxPoint& aStart, const wxPoint& aControl1, + const wxPoint& aControl2, const wxPoint& aEnd, + int aTolerance, + int aLineThickness = USE_DEFAULT_LINE_WIDTH ) override; + + virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, + FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, + void * aData = NULL ) override; + + virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, + double aScaleFactor ) override; + + virtual void PenTo( const wxPoint& pos, char plume ) override; + + /** + * Function SetSvgCoordinatesFormat + * selection of SVG step size (number of digits needed for 1 mm or 1 inch ) + * @param aResolution = number of digits in mantissa of coordinate + * use a value from 3-6 + * do not use value > 6 to avoid overflow in PCBNEW + * do not use value > 4 to avoid overflow for other parts + * @param aUseInches = true to use inches, false to use mm (default) + * + * Should be called only after SetViewport() is called + */ + virtual void SetSvgCoordinatesFormat( unsigned aResolution, bool aUseInches = false ) override; + + /** + * calling this function allows one to define the beginning of a group + * of drawing items (used in SVG format to separate components) + * @param aData should be a string for the SVG ID tage + */ + virtual void StartBlock( void* aData ) override; + + /** + * calling this function allows one to define the end of a group of drawing + * items the group is started by StartBlock() + * @param aData should be null + */ + virtual void EndBlock( void* aData ) override; + + virtual void Text( const wxPoint& aPos, + const COLOR4D aColor, + const wxString& aText, + double aOrient, + const wxSize& aSize, + enum EDA_TEXT_HJUSTIFY_T aH_justify, + enum EDA_TEXT_VJUSTIFY_T aV_justify, + int aWidth, + bool aItalic, + bool aBold, + bool aMultilineAllowed = false, + void* aData = NULL ) override; + +protected: + FILL_T m_fillMode; // true if the current contour + // rect, arc, circle, polygon must be filled + long m_pen_rgb_color; // current rgb color value: each color has + // a value 0 ... 255, and the 3 colors are + // grouped in a 3x8 bits value + // (written in hex to svg files) + long m_brush_rgb_color; // same as m_pen_rgb_color, used to fill + // some contours. + bool m_graphics_changed; // true if a pen/brush parameter is modified + // color, pen size, fil mode ... + // the new SVG stype must be output on file + PLOT_DASH_TYPE m_dashed; // plot line style + bool m_useInch; // is 0 if the step size is 10**-n*mm + // is 1 if the step size is 10**-n*inch + // Where n is given from m_precision + unsigned m_precision; // How fine the step size is + // Use 3-6 (3 means um precision, 6 nm precision) in pcbnew + // 3-4 in other moduls (avoid values >4 to avoid overflow) + // see also comment for m_useInch. + + /** + * function emitSetRGBColor() + * initialize m_pen_rgb_color from reduced values r, g ,b + * ( reduced values are 0.0 to 1.0 ) + */ + virtual void emitSetRGBColor( double r, double g, double b ) override; + + /** + * function setSVGPlotStyle() + * output the string which define pen and brush color, shape, transparency + * + * @param aIsGroup If false, do not form a new group for the style. + * @param aExtraStyle If given, the string will be added into the style string before closing + */ + void setSVGPlotStyle( bool aIsGroup = true, const std::string& aExtraStyle = {} ); + + /** + * function setFillMode() + * prepare parameters for setSVGPlotStyle() + */ + void setFillMode( FILL_T fill ); +}; diff --git a/eeschema/dialogs/dialog_plot_schematic.h b/eeschema/dialogs/dialog_plot_schematic.h index c9930fc3ca..dea1fb1f05 100644 --- a/eeschema/dialogs/dialog_plot_schematic.h +++ b/eeschema/dialogs/dialog_plot_schematic.h @@ -41,6 +41,7 @@ enum PageFormatReq { PAGE_SIZE_A }; +class PDF_PLOTTER; class DIALOG_PLOT_SCHEMATIC : public DIALOG_PLOT_SCHEMATIC_BASE { diff --git a/eeschema/libedit/libedit_plot_component.cpp b/eeschema/libedit/libedit_plot_component.cpp index d96930e907..b1a1d3846e 100644 --- a/eeschema/libedit/libedit_plot_component.cpp +++ b/eeschema/libedit/libedit_plot_component.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include void LIB_EDIT_FRAME::SVG_PlotComponent( const wxString& aFullFileName ) { diff --git a/eeschema/plot_schematic_DXF.cpp b/eeschema/plot_schematic_DXF.cpp index 5e336c391c..6a605f1a99 100644 --- a/eeschema/plot_schematic_DXF.cpp +++ b/eeschema/plot_schematic_DXF.cpp @@ -26,7 +26,7 @@ */ #include -#include +#include #include #include #include diff --git a/eeschema/plot_schematic_HPGL.cpp b/eeschema/plot_schematic_HPGL.cpp index 5d58cb0466..3225439942 100644 --- a/eeschema/plot_schematic_HPGL.cpp +++ b/eeschema/plot_schematic_HPGL.cpp @@ -26,7 +26,7 @@ */ #include -#include +#include #include #include #include diff --git a/eeschema/plot_schematic_PDF.cpp b/eeschema/plot_schematic_PDF.cpp index 760f42e917..c0ea7ca70c 100644 --- a/eeschema/plot_schematic_PDF.cpp +++ b/eeschema/plot_schematic_PDF.cpp @@ -26,7 +26,7 @@ */ #include -#include +#include #include #include #include diff --git a/eeschema/plot_schematic_PS.cpp b/eeschema/plot_schematic_PS.cpp index 6f57d447bd..4973aaa327 100644 --- a/eeschema/plot_schematic_PS.cpp +++ b/eeschema/plot_schematic_PS.cpp @@ -25,7 +25,7 @@ */ #include -#include +#include #include #include #include diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index c5d9274fe9..1bd068f842 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -42,6 +42,7 @@ #include #include #include "sch_painter.h" +#include void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef, RENDER_SETTINGS* aRenderSettings ) diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index c79f9db8a7..37f61899ef 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -31,7 +31,6 @@ #define _SCH_BUS_ENTRY_H_ #include -#include #include #define TARGET_BUSENTRY_RADIUS Mils2iu( 12 ) // Circle diameter drawn at the ends diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 801ad9f6b2..ff8a822ac7 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -30,7 +30,7 @@ #include #include -#include +#include // for PLOT_DASH_TYPE definition #include diff --git a/include/plotter.h b/include/plotter.h index ae902d9c32..97fe9a530b 100644 --- a/include/plotter.h +++ b/include/plotter.h @@ -26,7 +26,7 @@ * Common plot library \n * Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) * - * @file plot_common.h + * @file plotter.h */ #ifndef PLOT_COMMON_H_ @@ -604,983 +604,6 @@ protected: // variables used in most of plotters: }; -class HPGL_PLOTTER : public PLOTTER -{ -public: - HPGL_PLOTTER(); - - virtual PLOT_FORMAT GetPlotterType() const override - { - return PLOT_FORMAT::HPGL; - } - - static wxString GetDefaultFileExtension() - { - return wxString( wxT( "plt" ) ); - } - - virtual bool StartPlot() override; - virtual bool EndPlot() override; - - /// HPGL doesn't handle line thickness or color - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override - { - // This is the truth - currentPenWidth = userToDeviceSize( penDiameter ); - } - - virtual void SetDash( PLOT_DASH_TYPE dashed ) override; - - virtual void SetColor( COLOR4D color ) override {} - - virtual void SetPenSpeed( int speed ) - { - penSpeed = speed; - } - - virtual void SetPenNumber( int number ) - { - penNumber = number; - } - - virtual void SetPenDiameter( double diameter ); - - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, - void * aData = NULL) override; - - virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, - EDA_DRAW_MODE_T tracemode, void* aData ) override; - virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void PenTo( const wxPoint& pos, char plume ) override; - virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize, - double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, - int aCornerRadius, double aOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, - SHAPE_POLY_SET* aPolygons, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, - double aPadOrient, EDA_DRAW_MODE_T aTraceMode, - void* aData ) override; - virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, - double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - -protected: - void penControl( char plume ); - - int penSpeed; - int penNumber; - double penDiameter; -}; - -/** - * The PSLIKE_PLOTTER class is an intermediate class to handle common - * routines for engines working more or less with the postscript imaging - * model - */ -class PSLIKE_PLOTTER : public PLOTTER -{ -public: - PSLIKE_PLOTTER() : - plotScaleAdjX( 1 ), - plotScaleAdjY( 1 ), - m_textMode( PLOT_TEXT_MODE::PHANTOM ) - { - } - - /** - * PS and PDF fully implement native text (for the Latin-1 subset) - */ - virtual void SetTextMode( PLOT_TEXT_MODE mode ) override - { - if( mode != PLOT_TEXT_MODE::DEFAULT ) - m_textMode = mode; - } - - /** - * Set the 'fine' scaling for the postscript engine - */ - void SetScaleAdjust( double scaleX, double scaleY ) - { - plotScaleAdjX = scaleX; - plotScaleAdjY = scaleY; - } - - // Pad routines are handled with lower level primitives - virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize, - double aPadOrient, EDA_DRAW_MODE_T aTraceMode, - void* aData ) override; - virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, - int aCornerRadius, double aOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, - SHAPE_POLY_SET* aPolygons, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, - double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, - double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - - /** The SetColor implementation is split with the subclasses: - * The PSLIKE computes the rgb values, the subclass emits the - * operator to actually do it - */ - virtual void SetColor( COLOR4D color ) override; - -protected: - void computeTextParameters( const wxPoint& aPos, - const wxString& aText, - int aOrient, - const wxSize& aSize, - bool aMirror, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - double *wideningFactor, - double *ctm_a, - double *ctm_b, - double *ctm_c, - double *ctm_d, - double *ctm_e, - double *ctm_f, - double *heightFactor ); - void postscriptOverlinePositions( const wxString& aText, int aXSize, - bool aItalic, bool aBold, - std::vector *pos_pairs ); - - /// convert a wxString unicode string to a char string compatible with the accepted - /// string plotter format (convert special chars and non ascii7 chars) - virtual std::string encodeStringForPlotter( const wxString& aUnicode ); - - /// Virtual primitive for emitting the setrgbcolor operator - virtual void emitSetRGBColor( double r, double g, double b ) = 0; - - /// Height of the postscript font (from the AFM) - static const double postscriptTextAscent; // = 0.718; - - int returnPostscriptTextWidth( const wxString& aText, int aXSize, - bool aItalic, bool aBold ); - - /// Fine user scale adjust ( = 1.0 if no correction) - double plotScaleAdjX, plotScaleAdjY; - - /// How to draw text - PLOT_TEXT_MODE m_textMode; -}; - - -class PS_PLOTTER : public PSLIKE_PLOTTER -{ -public: - PS_PLOTTER() - { - // The phantom plot in postscript is an hack and reportedly - // crashes Adobe's own postscript interpreter! - m_textMode = PLOT_TEXT_MODE::STROKE; - } - - static wxString GetDefaultFileExtension() - { - return wxString( wxT( "ps" ) ); - } - - virtual PLOT_FORMAT GetPlotterType() const override - { - return PLOT_FORMAT::POST; - } - - virtual bool StartPlot() override; - virtual bool EndPlot() override; - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; - virtual void SetDash( PLOT_DASH_TYPE dashed ) override; - - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; - - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, - void * aData = NULL ) override; - - virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, - double aScaleFactor ) override; - - virtual void PenTo( const wxPoint& pos, char plume ) override; - virtual void Text( const wxPoint& aPos, - const COLOR4D aColor, - const wxString& aText, - double aOrient, - const wxSize& aSize, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - void* aData = NULL ) override; -protected: - virtual void emitSetRGBColor( double r, double g, double b ) override; -}; - -class PDF_PLOTTER : public PSLIKE_PLOTTER -{ -public: - PDF_PLOTTER() : - pageTreeHandle( 0 ), - fontResDictHandle( 0 ), - pageStreamHandle( 0 ), - streamLengthHandle( 0 ), - workFile( nullptr ) - { - } - - virtual PLOT_FORMAT GetPlotterType() const override - { - return PLOT_FORMAT::PDF; - } - - static wxString GetDefaultFileExtension() - { - return wxString( wxT( "pdf" ) ); - } - - /** - * Open or create the plot file aFullFilename - * @param aFullFilename = the full file name of the file to create - * @return true if success, false if the file cannot be created/opened - * - * The base class open the file in text mode, so we should have this - * function overlaid for PDF files, which are binary files - */ - virtual bool OpenFile( const wxString& aFullFilename ) override; - - virtual bool StartPlot() override; - virtual bool EndPlot() override; - virtual void StartPage(); - virtual void ClosePage(); - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; - virtual void SetDash( PLOT_DASH_TYPE dashed ) override; - - /** PDF can have multiple pages, so SetPageSettings can be called - * with the outputFile open (but not inside a page stream!) */ - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; - - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, - void * aData = NULL ) override; - - virtual void PenTo( const wxPoint& pos, char plume ) override; - - virtual void Text( const wxPoint& aPos, - const COLOR4D aColor, - const wxString& aText, - double aOrient, - const wxSize& aSize, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - void* aData = NULL ) override; - - virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, - double aScaleFactor ) override; - - -protected: - /// convert a wxString unicode string to a char string compatible with the accepted - /// string PDF format (convert special chars and non ascii7 chars) - std::string encodeStringForPlotter( const wxString& aUnicode ) override; - - virtual void emitSetRGBColor( double r, double g, double b ) override; - int allocPdfObject(); - int startPdfObject(int handle = -1); - void closePdfObject(); - int startPdfStream(int handle = -1); - void closePdfStream(); - int pageTreeHandle; /// Handle to the root of the page tree object - int fontResDictHandle; /// Font resource dictionary - std::vector pageHandles;/// Handles to the page objects - int pageStreamHandle; /// Handle of the page content object - int streamLengthHandle; /// Handle to the deferred stream length - wxString workFilename; - FILE* workFile; /// Temporary file to costruct the stream before zipping - std::vector xrefTable; /// The PDF xref offset table -}; - -class SVG_PLOTTER : public PSLIKE_PLOTTER -{ -public: - SVG_PLOTTER(); - - static wxString GetDefaultFileExtension() - { - return wxString( wxT( "svg" ) ); - } - - virtual PLOT_FORMAT GetPlotterType() const override - { - return PLOT_FORMAT::SVG; - } - - virtual void SetColor( COLOR4D color ) override; - virtual bool StartPlot() override; - virtual bool EndPlot() override; - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; - virtual void SetDash( PLOT_DASH_TYPE dashed ) override; - - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; - - virtual void BezierCurve( const wxPoint& aStart, const wxPoint& aControl1, - const wxPoint& aControl2, const wxPoint& aEnd, - int aTolerance, - int aLineThickness = USE_DEFAULT_LINE_WIDTH ) override; - - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, - void * aData = NULL ) override; - - virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos, - double aScaleFactor ) override; - - virtual void PenTo( const wxPoint& pos, char plume ) override; - - /** - * Function SetSvgCoordinatesFormat - * selection of SVG step size (number of digits needed for 1 mm or 1 inch ) - * @param aResolution = number of digits in mantissa of coordinate - * use a value from 3-6 - * do not use value > 6 to avoid overflow in PCBNEW - * do not use value > 4 to avoid overflow for other parts - * @param aUseInches = true to use inches, false to use mm (default) - * - * Should be called only after SetViewport() is called - */ - virtual void SetSvgCoordinatesFormat( unsigned aResolution, bool aUseInches = false ) override; - - /** - * calling this function allows one to define the beginning of a group - * of drawing items (used in SVG format to separate components) - * @param aData should be a string for the SVG ID tage - */ - virtual void StartBlock( void* aData ) override; - - /** - * calling this function allows one to define the end of a group of drawing - * items the group is started by StartBlock() - * @param aData should be null - */ - virtual void EndBlock( void* aData ) override; - - virtual void Text( const wxPoint& aPos, - const COLOR4D aColor, - const wxString& aText, - double aOrient, - const wxSize& aSize, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - void* aData = NULL ) override; - -protected: - FILL_T m_fillMode; // true if the current contour - // rect, arc, circle, polygon must be filled - long m_pen_rgb_color; // current rgb color value: each color has - // a value 0 ... 255, and the 3 colors are - // grouped in a 3x8 bits value - // (written in hex to svg files) - long m_brush_rgb_color; // same as m_pen_rgb_color, used to fill - // some contours. - bool m_graphics_changed; // true if a pen/brush parameter is modified - // color, pen size, fil mode ... - // the new SVG stype must be output on file - PLOT_DASH_TYPE m_dashed; // plot line style - bool m_useInch; // is 0 if the step size is 10**-n*mm - // is 1 if the step size is 10**-n*inch - // Where n is given from m_precision - unsigned m_precision; // How fine the step size is - // Use 3-6 (3 means um precision, 6 nm precision) in pcbnew - // 3-4 in other moduls (avoid values >4 to avoid overflow) - // see also comment for m_useInch. - - /** - * function emitSetRGBColor() - * initialize m_pen_rgb_color from reduced values r, g ,b - * ( reduced values are 0.0 to 1.0 ) - */ - virtual void emitSetRGBColor( double r, double g, double b ) override; - - /** - * function setSVGPlotStyle() - * output the string which define pen and brush color, shape, transparency - * - * @param aIsGroup If false, do not form a new group for the style. - * @param aExtraStyle If given, the string will be added into the style string before closing - */ - void setSVGPlotStyle( bool aIsGroup = true, const std::string& aExtraStyle = {} ); - - /** - * function setFillMode() - * prepare parameters for setSVGPlotStyle() - */ - void setFillMode( FILL_T fill ); -}; - -/* Class to handle a D_CODE when plotting a board using Standard Aperture Templates - * (complex apertures need aperture macros - * 5 types: - * Circle (round) - * Rectangle - * Obround (oval) - * regular polygon - * - * We need round apertures to plot lines, so we also defined a aperture type for plotting - */ -#define FIRST_DCODE_VALUE 10 // D_CODE < 10 is a command, D_CODE >= 10 is a tool - -class APERTURE -{ -public: - enum APERTURE_TYPE { - AT_CIRCLE = 1, // round aperture, to flash pads - AT_RECT = 2, // rect aperture, to flash pads - AT_PLOTTING = 3, // round aperture, to plot lines - AT_OVAL = 4, // oval aperture, to flash pads - AT_REGULAR_POLY = 5,// Regular polygon (n vertices, n = 3 .. 12, with rotation) - AT_REGULAR_POLY3, // Regular polygon 3 vertices, with rotation - AT_REGULAR_POLY4, // Regular polygon 4 vertices, with rotation - AT_REGULAR_POLY5, // Regular polygon 5 vertices, with rotation - AT_REGULAR_POLY6, // Regular polygon 6 vertices, with rotation - AT_REGULAR_POLY7, // Regular polygon 7 vertices, with rotation - AT_REGULAR_POLY8, // Regular polygon 8 vertices, with rotation - AT_REGULAR_POLY9, // Regular polygon 9 vertices, with rotation - AT_REGULAR_POLY10, // Regular polygon 10 vertices, with rotation - AT_REGULAR_POLY11, // Regular polygon 11 vertices, with rotation - AT_REGULAR_POLY12, // Regular polygon 12 vertices, with rotation - }; - - void SetSize( const wxSize& aSize ) - { - m_Size = aSize; - } - - const wxSize GetSize() - { - return m_Size; - } - - void SetDiameter( int aDiameter ) - { - m_Size.x = aDiameter; - } - - int GetDiameter() - { - return m_Size.x; - } - - void SetVerticeCount( int aCount ) - { - if( aCount < 3 ) - aCount = 3; - else if( aCount > 12 ) - aCount = 12; - - m_Type = (APERTURE_TYPE)(AT_REGULAR_POLY3 - 3 + aCount); - } - - int GetVerticeCount() - { - return m_Type - AT_REGULAR_POLY3 + 3; - } - - void SetRotation( double aRotDegree ) - { - // The rotation is stored in 1/1000 degree - m_Size.y = int( aRotDegree * 1000.0 ); - } - - double GetRotation() - { - // The rotation is stored in 1/1000 degree - return m_Size.y / 1000.0; - } - - // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices ) - APERTURE_TYPE m_Type; - - // horiz and Vert size, or diameter and rotation for regular polygon - // The diameter (for circle and polygons) is stored in m_Size.x - // the rotation is stored in m_Size.y in 1/1000 degree - wxSize m_Size; - - // code number ( >= 10 ) - int m_DCode; - - // the attribute attached to this aperture - // Only one attribute is allowed by aperture - // 0 = no specific aperture attribute - int m_ApertureAttribute; -}; - - -class GERBER_PLOTTER : public PLOTTER -{ -public: - GERBER_PLOTTER(); - - virtual PLOT_FORMAT GetPlotterType() const override - { - return PLOT_FORMAT::GERBER; - } - - static wxString GetDefaultFileExtension() - { - return wxString( wxT( "gbr" ) ); - } - - /** - * Function StartPlot - * Write GERBER header to file - * initialize global variable g_Plot_PlotOutputFile - */ - virtual bool StartPlot() override; - virtual bool EndPlot() override; - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override; - - // RS274X has no dashing, nor colours - virtual void SetDash( PLOT_DASH_TYPE dashed ) override - { - } - - virtual void SetColor( COLOR4D color ) override {} - // Currently, aScale and aMirror are not used in gerber plotter - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle, - int aRadius, FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH ) override; - - virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, - EDA_DRAW_MODE_T tracemode, void* aData ) override; - - virtual void ThickArc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, int width, EDA_DRAW_MODE_T tracemode, void* aData ) override; - virtual void ThickRect( const wxPoint& p1, const wxPoint& p2, int width, - EDA_DRAW_MODE_T tracemode, void* aData ) override; - virtual void ThickCircle( const wxPoint& pos, int diametre, int width, - EDA_DRAW_MODE_T tracemode, void* aData ) override; - /** - * Gerber polygon: they can (and *should*) be filled with the - * appropriate G36/G37 sequence - */ - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, - void* aData = nullptr ) override; - - virtual void PenTo( const wxPoint& pos, char plume ) override; - - virtual void Text( const wxPoint& aPos, - const COLOR4D aColor, - const wxString& aText, - double aOrient, - const wxSize& aSize, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - void* aData = NULL ) override; - - /** - * Filled circular flashes are stored as apertures - */ - virtual void FlashPadCircle( const wxPoint& pos, int diametre, - EDA_DRAW_MODE_T trace_mode, void* aData ) override; - - /** - * Filled oval flashes are handled as aperture in the 90 degree positions only - */ - virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient, - EDA_DRAW_MODE_T trace_mode, void* aData ) override; - /** - * Filled rect flashes are handled as aperture in the 0 90 180 or 270 degree orientation only - * and as polygon for other orientations - * TODO: always use flashed shapes (aperture macros) - */ - virtual void FlashPadRect( const wxPoint& pos, const wxSize& size, - double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override; - - /** - * Roundrect pad at the moment are not handled as aperture, since - * they require aperture macros - * TODO: always use flashed shapes (aperture macros) - */ - virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, - int aCornerRadius, double aOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, - SHAPE_POLY_SET* aPolygons, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - /** - * Trapezoidal pad at the moment are *never* handled as aperture, since - * they require aperture macros - * TODO: always use flashed shapes (aperture macros) - */ - virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, - double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - - virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, - double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - - /** - * Plot a Gerber region: similar to PlotPoly but plot only filled polygon, - * and add the TA.AperFunction if aData contains this attribute, and clear it - * after plotting - */ - void PlotGerberRegion( const std::vector< wxPoint >& aCornerList, - void * aData = NULL ); - - /** - * Change the plot polarity and begin a new layer - * Used to 'scratch off' silk screen away from solder mask - */ - virtual void SetLayerPolarity( bool aPositive ) override; - - /** - * Function SetGerberCoordinatesFormat - * selection of Gerber units and resolution (number of digits in mantissa) - * @param aResolution = number of digits in mantissa of coordinate - * use 5 or 6 for mm and 6 or 7 for inches - * do not use value > 6 (mm) or > 7 (in) to avoid overflow - * @param aUseInches = true to use inches, false to use mm (default) - * - * Should be called only after SetViewport() is called - */ - virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override; - - void UseX2format( bool aEnable ) { m_useX2format = aEnable; } - void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; } - - /** - * calling this function allows one to define the beginning of a group - * of drawing items (used in X2 format with netlist attributes) - * @param aData can define any parameter - */ - virtual void StartBlock( void* aData ) override; - - /** - * calling this function allows one to define the end of a group of drawing - * items the group is started by StartBlock() - * (used in X2 format with netlist attributes) - * @param aData can define any parameter - */ - virtual void EndBlock( void* aData ) override; - - /** Remove (clear) all attributes from object attributes dictionary (TO. and TA commands) - * similar to clearNetAttribute(), this is an unconditional reset of TO. and TA. attributes - */ - void ClearAllAttributes(); - - /** - * @return a index to the aperture in aperture list which meets the size and type of tool - * if the aperture does not exist, it is created and entered in aperture list - * @param aSize = the size of tool - * @param aType = the type ( shape ) of tool - * @param aApertureAttribute = an aperture attribute of the tool (a tool can have onlu one attribute) - * 0 = no specific attribute - */ - int GetOrCreateAperture( const wxSize& aSize, - APERTURE::APERTURE_TYPE aType, int aApertureAttribute ); - -protected: - /** Plot a round rect (a round rect shape in fact) as a Gerber region - * using lines and arcs for corners - * @param aRectCenter is the center of the rectangle - * @param aSize is the size of the rectangle - * @param aCornerRadius is the radius of the corners - * @param aOrient is the rotation of the rectangle - * Note: only the G36 ... G37 region is created. - */ - void plotRoundRectAsRegion( const wxPoint& aRectCenter, const wxSize& aSize, - int aCornerRadius, double aOrient ); - /** - * Plot a Gerber arc. - * if aPlotInRegion = true, the current pen position will not be - * initialized to the arc start position, and therefore the arc can be used - * to define a region outline item - * a line will be created from current ^position to arc start point - * if aPlotInRegion = false, the current pen position will be initialized - * to the arc start position, to plot an usual arc item - * The line thickness is not initialized in plotArc, and must be initialized - * before calling it if needed. - */ - void plotArc( const wxPoint& aCenter, double aStAngle, double aEndAngle, - int aRadius, bool aPlotInRegion ); - - /** - * Pick an existing aperture or create a new one, matching the - * size, type and attributes. - * write the DCode selection on gerber file - */ - void selectAperture( const wxSize& aSize, APERTURE::APERTURE_TYPE aType, - int aApertureAttribute ); - /** - * Pick an existing aperture or create a new one, matching the - * aDiameter, aPolygonRotation, type and attributes. - * It apply only to apertures with type = AT_REGULAR_POLY3 to AT_REGULAR_POLY12 - * write the DCode selection on gerber file - */ - void selectAperture( int aDiameter, double aPolygonRotation, - APERTURE::APERTURE_TYPE aType, int aApertureAttribute ); - - /** - * Emit a D-Code record, using proper conversions - * to format a leading zero omitted gerber coordinate - * (for n decimal positions, see header generation in start_plot - */ - void emitDcode( const DPOINT& pt, int dcode ); - - /** - * print a Gerber net attribute object record. - * In a gerber file, a net attribute is owned by a graphic object - * formatNetAttribute must be called before creating the object - * @param aData contains the dato to format. - * the generated string depends on the type of netlist info - */ - void formatNetAttribute( GBR_NETLIST_METADATA* aData ); - - /** - * clear a Gerber net attribute record (clear object attribute dictionary) - * and output the clear object attribute dictionary command to gerber file - * has effect only if a net attribute is stored in m_objectAttributesDictionnary - */ - void clearNetAttribute(); - - // the attributes dictionary created/modifed by %TO, attached to objects, when they are created - // by D01, D03, G36/G37 commands - // standard attributes are .P, .C and .N - // this is used by gerber readers when creating a new object. Cleared by %TD command - // Note: m_objectAttributesDictionnary can store more than one attribute - // the string stores the line(s) actually written to the gerber file - // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL) - std::string m_objectAttributesDictionnary; - - // The last aperture attribute generated (only one aperture attribute can be set) - int m_apertureAttribute; - - FILE* workFile; - FILE* finalFile; - wxString m_workFilename; - - /** - * Generate the table of D codes - */ - void writeApertureList(); - - std::vector m_apertures; // The list of available apertures - int m_currentApertureIdx; // The index of the current aperture in m_apertures - - bool m_gerberUnitInch; // true if the gerber units are inches, false for mm - int m_gerberUnitFmt; // number of digits in mantissa. - // usually 6 in Inches and 5 or 6 in mm - bool m_useX2format; // Add X2 file header attributes. If false, attributes - // will be added as comments. - bool m_useNetAttributes; // In recent gerber files, netlist info can be added. - // It will be added if this param is true, using X2 or - // X1 format -}; - - -class DXF_PLOTTER : public PLOTTER -{ -public: - DXF_PLOTTER() : m_textAsLines( false ) - { - m_textAsLines = true; - m_currentColor = COLOR4D::BLACK; - m_currentLineType = PLOT_DASH_TYPE::SOLID; - 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 ); - } - - virtual bool StartPlot() override; - virtual bool EndPlot() override; - - // For now we don't use 'thick' primitives, so no line width - virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override - { - currentPenWidth = 0; - } - - virtual void SetDash( PLOT_DASH_TYPE dashed ) override; - - virtual void SetColor( COLOR4D color ) override; - - virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil, - double aScale, bool aMirror ) override; - virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, - int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, - FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, void * aData = NULL ) override; - virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width, - EDA_DRAW_MODE_T tracemode, void* aData ) override; - virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle, - int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override; - virtual void PenTo( const wxPoint& pos, char plume ) override; - - virtual void FlashPadCircle( const wxPoint& pos, int diametre, - EDA_DRAW_MODE_T trace_mode, void* aData ) override; - virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient, - EDA_DRAW_MODE_T trace_mode, void* aData ) override; - virtual void FlashPadRect( const wxPoint& pos, const wxSize& size, - double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override; - virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize, - int aCornerRadius, double aOrient, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize, - SHAPE_POLY_SET* aPolygons, - EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners, - double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount, - double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override; - - virtual void Text( const wxPoint& aPos, - const COLOR4D aColor, - const wxString& aText, - double aOrient, - const wxSize& aSize, - enum EDA_TEXT_HJUSTIFY_T aH_justify, - enum EDA_TEXT_VJUSTIFY_T aV_justify, - int aWidth, - bool aItalic, - bool aBold, - bool aMultilineAllowed = false, - void* aData = NULL ) override; - - - // Must be in the same order as the drop-down list in the plot dialog inside pcbnew - enum class DXF_UNITS - { - INCHES = 0, - MILLIMETERS = 1 - }; - - /** - * 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: - bool m_textAsLines; - COLOR4D m_currentColor; - PLOT_DASH_TYPE m_currentLineType; - - DXF_UNITS m_plotUnits; - double m_unitScalingFactor; - unsigned int m_measurementDirective; -}; - class TITLE_BLOCK; void PlotWorkSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock, diff --git a/include/plotters_specific.h b/include/plotters_specific.h new file mode 100644 index 0000000000..2aa46c5720 --- /dev/null +++ b/include/plotters_specific.h @@ -0,0 +1,32 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.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 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 . + */ + +/** + * Plotting engines (Postscript, Gerber, HPGL and DXF) + * + * @file plotters_specific.h + */ + +#pragma once + +#include <../common/plotters/plotter_hpgl.h> +#include <../common/plotters/plotter_gerber.h> +#include <../common/plotters/plotter_dxf.h> +#include <../common/plotters/plotters_pslike.h> diff --git a/pcbnew/pcb_plot_params.h b/pcbnew/pcb_plot_params.h index 2d8049d75d..199240f1c5 100644 --- a/pcbnew/pcb_plot_params.h +++ b/pcbnew/pcb_plot_params.h @@ -25,7 +25,7 @@ #include #include // EDA_DRAW_MODE_T -#include +#include #include class COLOR_SETTINGS;