2011-09-30 18:15:37 +00:00
|
|
|
/**
|
2018-01-28 18:12:26 +00:00
|
|
|
* @file DXF_plotter.cpp
|
|
|
|
* @brief Kicad: specialized plotter for DXF files format
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2015-02-26 10:33:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-02-20 13:59:11 +00:00
|
|
|
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-26 10:33:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter_dxf.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2014-05-16 19:03:45 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
2012-10-13 18:54:33 +00:00
|
|
|
* Oblique angle for DXF native text
|
2012-05-03 18:37:56 +00:00
|
|
|
* (I don't remember if 15 degrees is the ISO value... it looks nice anyway)
|
|
|
|
*/
|
|
|
|
static const double DXF_OBLIQUE_ANGLE = 15;
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2017-04-21 14:44:15 +00:00
|
|
|
/* The layer/colors palette. The acad/DXF palette is divided in 3 zones:
|
|
|
|
|
|
|
|
- The primary colors (1 - 9)
|
|
|
|
- An HSV zone (10-250, 5 values x 2 saturations x 10 hues
|
|
|
|
- Greys (251 - 255)
|
|
|
|
|
|
|
|
There is *no* black... the white does it on paper, usually, and
|
|
|
|
anyway it depends on the plotter configuration, since DXF colors
|
|
|
|
are meant to be logical only (they represent *both* line color and
|
|
|
|
width); later version with plot styles only complicate the matter!
|
|
|
|
|
|
|
|
As usual, brown and magenta/purple are difficult to place since
|
|
|
|
they are actually variations of other colors.
|
|
|
|
*/
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int color;
|
|
|
|
} dxf_layer[NBCOLORS] =
|
|
|
|
{
|
|
|
|
{ "BLACK", 7 }, // In DXF, color 7 is *both* white and black!
|
|
|
|
{ "GRAY1", 251 },
|
|
|
|
{ "GRAY2", 8 },
|
|
|
|
{ "GRAY3", 9 },
|
|
|
|
{ "WHITE", 7 },
|
|
|
|
{ "LYELLOW", 51 },
|
2022-01-06 18:59:47 +00:00
|
|
|
{ "LORANGE", 41 },
|
2017-04-21 14:44:15 +00:00
|
|
|
{ "BLUE1", 178 },
|
|
|
|
{ "GREEN1", 98 },
|
|
|
|
{ "CYAN1", 138 },
|
|
|
|
{ "RED1", 18 },
|
|
|
|
{ "MAGENTA1", 228 },
|
|
|
|
{ "BROWN1", 58 },
|
2022-01-06 18:59:47 +00:00
|
|
|
{ "ORANGE1", 34 },
|
2017-04-21 14:44:15 +00:00
|
|
|
{ "BLUE2", 5 },
|
|
|
|
{ "GREEN2", 3 },
|
|
|
|
{ "CYAN2", 4 },
|
|
|
|
{ "RED2", 1 },
|
|
|
|
{ "MAGENTA2", 6 },
|
|
|
|
{ "BROWN2", 54 },
|
2022-01-06 18:59:47 +00:00
|
|
|
{ "ORANGE2", 42 },
|
2017-04-21 14:44:15 +00:00
|
|
|
{ "BLUE3", 171 },
|
|
|
|
{ "GREEN3", 91 },
|
|
|
|
{ "CYAN3", 131 },
|
|
|
|
{ "RED3", 11 },
|
|
|
|
{ "MAGENTA3", 221 },
|
|
|
|
{ "YELLOW3", 2 },
|
2022-01-06 18:59:47 +00:00
|
|
|
{ "ORANGE3", 32 },
|
2017-04-21 14:44:15 +00:00
|
|
|
{ "BLUE4", 5 },
|
|
|
|
{ "GREEN4", 3 },
|
|
|
|
{ "CYAN4", 4 },
|
|
|
|
{ "RED4", 1 },
|
|
|
|
{ "MAGENTA4", 6 },
|
2022-01-06 18:59:47 +00:00
|
|
|
{ "YELLOW4", 2 },
|
|
|
|
{ "ORANGE4", 40 }
|
2017-04-21 14:44:15 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 02:42:37 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
static const char* getDXFLineType( PLOT_DASH_TYPE aType )
|
2017-11-13 17:29:49 +00:00
|
|
|
{
|
2017-12-06 02:42:37 +00:00
|
|
|
switch( aType )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_DASH_TYPE::DEFAULT:
|
|
|
|
case PLOT_DASH_TYPE::SOLID:
|
|
|
|
return "CONTINUOUS";
|
|
|
|
case PLOT_DASH_TYPE::DASH:
|
|
|
|
return "DASHED";
|
|
|
|
case PLOT_DASH_TYPE::DOT:
|
|
|
|
return "DOTTED";
|
|
|
|
case PLOT_DASH_TYPE::DASHDOT:
|
|
|
|
return "DASHDOT";
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "Unhandled PLOT_DASH_TYPE" );
|
|
|
|
return "CONTINUOUS";
|
2017-12-06 02:42:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 17:29:49 +00:00
|
|
|
|
2017-04-21 14:44:15 +00:00
|
|
|
|
|
|
|
// A helper function to create a color name acceptable in DXF files
|
|
|
|
// DXF files do not use a RGB definition
|
2021-06-07 18:31:53 +00:00
|
|
|
static wxString getDXFColorName( const COLOR4D& aColor )
|
2017-04-21 14:44:15 +00:00
|
|
|
{
|
2020-06-19 02:32:14 +00:00
|
|
|
EDA_COLOR_T color = COLOR4D::FindNearestLegacyColor( int( aColor.r * 255 ),
|
|
|
|
int( aColor.g * 255 ),
|
|
|
|
int( aColor.b * 255 ) );
|
2017-04-21 14:44:15 +00:00
|
|
|
wxString cname( dxf_layer[color].name );
|
|
|
|
return cname;
|
|
|
|
}
|
|
|
|
|
2019-06-13 00:28:22 +00:00
|
|
|
|
2019-07-10 14:47:12 +00:00
|
|
|
void DXF_PLOTTER::SetUnits( DXF_UNITS aUnit )
|
2019-06-13 00:28:22 +00:00
|
|
|
{
|
|
|
|
m_plotUnits = aUnit;
|
|
|
|
|
|
|
|
switch( aUnit )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
case DXF_UNITS::MILLIMETERS:
|
2019-06-13 00:28:22 +00:00
|
|
|
m_unitScalingFactor = 0.00254;
|
|
|
|
m_measurementDirective = 1;
|
|
|
|
break;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
case DXF_UNITS::INCHES:
|
2019-06-13 00:28:22 +00:00
|
|
|
default:
|
|
|
|
m_unitScalingFactor = 0.0001;
|
|
|
|
m_measurementDirective = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
|
2012-05-03 18:37:56 +00:00
|
|
|
double aScale, bool aMirror )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotOffset = aOffset;
|
|
|
|
m_plotScale = aScale;
|
2012-08-29 16:59:50 +00:00
|
|
|
|
|
|
|
/* DXF paper is 'virtual' so there is no need of a paper size.
|
|
|
|
Also this way we can handle the aux origin which can be useful
|
|
|
|
(for example when aligning to a mechanical drawing) */
|
2020-11-16 00:04:55 +00:00
|
|
|
m_paperSize.x = 0;
|
|
|
|
m_paperSize.y = 0;
|
2012-08-29 16:59:50 +00:00
|
|
|
|
|
|
|
/* Like paper size DXF units are abstract too. Anyway there is a
|
2019-05-15 13:06:10 +00:00
|
|
|
* system variable (MEASUREMENT) which will be set to 0 to indicate
|
|
|
|
* english units */
|
2012-08-29 16:59:50 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
2020-11-16 00:04:55 +00:00
|
|
|
m_iuPerDeviceUnit = 1.0 / aIusPerDecimil; // Gives a DXF in decimils
|
|
|
|
m_iuPerDeviceUnit *= GetUnitScaling(); // Get the scaling factor for the current units
|
2012-08-29 16:59:50 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotMirror = false; // No mirroring on DXF
|
2017-02-20 17:48:27 +00:00
|
|
|
m_currentColor = COLOR4D::BLACK;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
bool DXF_PLOTTER::StartPlot( const wxString& aPageNumber )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// DXF HEADER - Boilerplate
|
2012-05-03 18:37:56 +00:00
|
|
|
// Defines the minimum for drawing i.e. the angle system and the
|
2017-11-13 17:29:49 +00:00
|
|
|
// 4 linetypes (CONTINUOUS, DOTDASH, DASHED and DOTTED)
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2019-06-13 00:28:22 +00:00
|
|
|
" 0\n"
|
|
|
|
"SECTION\n"
|
|
|
|
" 2\n"
|
|
|
|
"HEADER\n"
|
|
|
|
" 9\n"
|
|
|
|
"$ANGBASE\n"
|
|
|
|
" 50\n"
|
|
|
|
"0.0\n"
|
|
|
|
" 9\n"
|
|
|
|
"$ANGDIR\n"
|
|
|
|
" 70\n"
|
|
|
|
"1\n"
|
|
|
|
" 9\n"
|
|
|
|
"$MEASUREMENT\n"
|
|
|
|
" 70\n"
|
|
|
|
"%u\n"
|
|
|
|
" 0\n"
|
|
|
|
"ENDSEC\n"
|
|
|
|
" 0\n"
|
|
|
|
"SECTION\n"
|
|
|
|
" 2\n"
|
|
|
|
"TABLES\n"
|
|
|
|
" 0\n"
|
|
|
|
"TABLE\n"
|
|
|
|
" 2\n"
|
|
|
|
"LTYPE\n"
|
|
|
|
" 70\n"
|
|
|
|
"4\n"
|
|
|
|
" 0\n"
|
|
|
|
"LTYPE\n"
|
|
|
|
" 5\n"
|
|
|
|
"40F\n"
|
|
|
|
" 2\n"
|
|
|
|
"CONTINUOUS\n"
|
|
|
|
" 70\n"
|
|
|
|
"0\n"
|
|
|
|
" 3\n"
|
|
|
|
"Solid line\n"
|
|
|
|
" 72\n"
|
|
|
|
"65\n"
|
|
|
|
" 73\n"
|
|
|
|
"0\n"
|
|
|
|
" 40\n"
|
|
|
|
"0.0\n"
|
|
|
|
" 0\n"
|
|
|
|
"LTYPE\n"
|
|
|
|
" 5\n"
|
|
|
|
"410\n"
|
|
|
|
" 2\n"
|
|
|
|
"DASHDOT\n"
|
|
|
|
" 70\n"
|
|
|
|
"0\n"
|
|
|
|
" 3\n"
|
|
|
|
"Dash Dot ____ _ ____ _\n"
|
|
|
|
" 72\n"
|
|
|
|
"65\n"
|
|
|
|
" 73\n"
|
|
|
|
"4\n"
|
|
|
|
" 40\n"
|
|
|
|
"2.0\n"
|
|
|
|
" 49\n"
|
|
|
|
"1.25\n"
|
|
|
|
" 49\n"
|
|
|
|
"-0.25\n"
|
|
|
|
" 49\n"
|
|
|
|
"0.25\n"
|
|
|
|
" 49\n"
|
|
|
|
"-0.25\n"
|
|
|
|
" 0\n"
|
|
|
|
"LTYPE\n"
|
|
|
|
" 5\n"
|
|
|
|
"411\n"
|
|
|
|
" 2\n"
|
|
|
|
"DASHED\n"
|
|
|
|
" 70\n"
|
|
|
|
"0\n"
|
|
|
|
" 3\n"
|
|
|
|
"Dashed __ __ __ __ __\n"
|
|
|
|
" 72\n"
|
|
|
|
"65\n"
|
|
|
|
" 73\n"
|
|
|
|
"2\n"
|
|
|
|
" 40\n"
|
|
|
|
"0.75\n"
|
|
|
|
" 49\n"
|
|
|
|
"0.5\n"
|
|
|
|
" 49\n"
|
|
|
|
"-0.25\n"
|
|
|
|
" 0\n"
|
|
|
|
"LTYPE\n"
|
|
|
|
" 5\n"
|
|
|
|
"43B\n"
|
|
|
|
" 2\n"
|
|
|
|
"DOTTED\n"
|
|
|
|
" 70\n"
|
|
|
|
"0\n"
|
|
|
|
" 3\n"
|
|
|
|
"Dotted . . . .\n"
|
|
|
|
" 72\n"
|
|
|
|
"65\n"
|
|
|
|
" 73\n"
|
|
|
|
"2\n"
|
|
|
|
" 40\n"
|
|
|
|
"0.2\n"
|
|
|
|
" 49\n"
|
|
|
|
"0.0\n"
|
|
|
|
" 49\n"
|
|
|
|
"-0.2\n"
|
|
|
|
" 0\n"
|
|
|
|
"ENDTAB\n",
|
2020-11-16 00:04:55 +00:00
|
|
|
GetMeasurementDirective() );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// Text styles table
|
2012-05-03 18:37:56 +00:00
|
|
|
// Defines 4 text styles, one for each bold/italic combination
|
|
|
|
fputs( " 0\n"
|
|
|
|
"TABLE\n"
|
|
|
|
" 2\n"
|
|
|
|
"STYLE\n"
|
|
|
|
" 70\n"
|
2020-11-16 00:04:55 +00:00
|
|
|
"4\n", m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
|
|
|
static const char *style_name[4] = {"KICAD", "KICADB", "KICADI", "KICADBI"};
|
2012-10-13 18:54:33 +00:00
|
|
|
for(int i = 0; i < 4; i++ )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2012-05-03 18:37:56 +00:00
|
|
|
" 0\n"
|
|
|
|
"STYLE\n"
|
2012-10-13 18:54:33 +00:00
|
|
|
" 2\n"
|
2012-05-03 18:37:56 +00:00
|
|
|
"%s\n" // Style name
|
2012-10-13 18:54:33 +00:00
|
|
|
" 70\n"
|
2012-05-03 18:37:56 +00:00
|
|
|
"0\n" // Standard flags
|
2012-10-13 18:54:33 +00:00
|
|
|
" 40\n"
|
2012-05-03 18:37:56 +00:00
|
|
|
"0\n" // Non-fixed height text
|
|
|
|
" 41\n"
|
|
|
|
"1\n" // Width factor (base)
|
|
|
|
" 42\n"
|
|
|
|
"1\n" // Last height (mandatory)
|
|
|
|
" 50\n"
|
|
|
|
"%g\n" // Oblique angle
|
|
|
|
" 71\n"
|
|
|
|
"0\n" // Generation flags (default)
|
|
|
|
" 3\n"
|
|
|
|
// The standard ISO font (when kicad is build with it
|
|
|
|
// the dxf text in acad matches *perfectly*)
|
|
|
|
"isocp.shx\n", // Font name (when not bigfont)
|
|
|
|
// Apply a 15 degree angle to italic text
|
|
|
|
style_name[i], i < 2 ? 0 : DXF_OBLIQUE_ANGLE );
|
|
|
|
}
|
|
|
|
|
2019-06-13 16:45:24 +00:00
|
|
|
EDA_COLOR_T numLayers = NBCOLORS;
|
|
|
|
|
|
|
|
// If printing in monochrome, only output the black layer
|
|
|
|
if( !GetColorMode() )
|
|
|
|
numLayers = static_cast<EDA_COLOR_T>( 1 );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// Layer table - one layer per color
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2012-05-03 18:37:56 +00:00
|
|
|
" 0\n"
|
|
|
|
"ENDTAB\n"
|
|
|
|
" 0\n"
|
|
|
|
"TABLE\n"
|
|
|
|
" 2\n"
|
|
|
|
"LAYER\n"
|
|
|
|
" 70\n"
|
2019-06-13 16:45:24 +00:00
|
|
|
"%d\n", numLayers );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
|
|
|
/* The layer/colors palette. The acad/DXF palette is divided in 3 zones:
|
|
|
|
|
|
|
|
- The primary colors (1 - 9)
|
|
|
|
- An HSV zone (10-250, 5 values x 2 saturations x 10 hues
|
|
|
|
- Greys (251 - 255)
|
|
|
|
*/
|
|
|
|
|
2021-05-02 14:02:33 +00:00
|
|
|
wxASSERT( numLayers <= NBCOLORS );
|
2020-06-19 02:32:14 +00:00
|
|
|
|
|
|
|
for( EDA_COLOR_T i = BLACK; i < numLayers; i = static_cast<EDA_COLOR_T>( int( i ) + 1 ) )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2012-05-03 18:37:56 +00:00
|
|
|
" 0\n"
|
|
|
|
"LAYER\n"
|
|
|
|
" 2\n"
|
|
|
|
"%s\n" // Layer name
|
|
|
|
" 70\n"
|
|
|
|
"0\n" // Standard flags
|
2012-10-13 18:54:33 +00:00
|
|
|
" 62\n"
|
2012-05-03 18:37:56 +00:00
|
|
|
"%d\n" // Color number
|
|
|
|
" 6\n"
|
|
|
|
"CONTINUOUS\n",// Linetype name
|
|
|
|
dxf_layer[i].name, dxf_layer[i].color );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// End of layer table, begin entities
|
|
|
|
fputs( " 0\n"
|
|
|
|
"ENDTAB\n"
|
|
|
|
" 0\n"
|
|
|
|
"ENDSEC\n"
|
|
|
|
" 0\n"
|
|
|
|
"SECTION\n"
|
|
|
|
" 2\n"
|
2020-11-16 00:04:55 +00:00
|
|
|
"ENTITIES\n", m_outputFile );
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
bool DXF_PLOTTER::EndPlot()
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// DXF FOOTER
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( " 0\n"
|
|
|
|
"ENDSEC\n"
|
|
|
|
" 0\n"
|
2020-11-16 00:04:55 +00:00
|
|
|
"EOF\n", m_outputFile );
|
|
|
|
fclose( m_outputFile );
|
2021-07-15 19:26:35 +00:00
|
|
|
m_outputFile = nullptr;
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
void DXF_PLOTTER::SetColor( const COLOR4D& color )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
if( ( m_colorMode )
|
2017-02-20 17:48:27 +00:00
|
|
|
|| ( color == COLOR4D::BLACK )
|
|
|
|
|| ( color == COLOR4D::WHITE ) )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
m_currentColor = color;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
2013-02-20 20:26:34 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
{
|
2017-02-20 17:48:27 +00:00
|
|
|
m_currentColor = COLOR4D::BLACK;
|
2020-11-16 00:04:55 +00:00
|
|
|
}
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( p1 );
|
2021-12-29 19:02:50 +00:00
|
|
|
LineTo( VECTOR2I( p1.x, p2.y ) );
|
|
|
|
LineTo( VECTOR2I( p2.x, p2.y ) );
|
|
|
|
LineTo( VECTOR2I( p2.x, p1.y ) );
|
|
|
|
FinishTo( VECTOR2I( p1.x, p1.y ) );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::Circle( const VECTOR2I& centre, int diameter, FILL_T fill, int width )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-01-20 00:17:44 +00:00
|
|
|
double radius = userToDeviceSize( diameter / 2 );
|
|
|
|
VECTOR2D centre_dev = userToDeviceCoordinates( centre );
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( radius > 0 )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2017-04-21 14:44:15 +00:00
|
|
|
wxString cname = getDXFColorName( m_currentColor );
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( fill == FILL_T::NO_FILL )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "0\nCIRCLE\n8\n%s\n10\n%g\n20\n%g\n40\n%g\n",
|
|
|
|
TO_UTF8( cname ),
|
|
|
|
centre_dev.x, centre_dev.y, radius );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
else if( fill == FILL_T::FILLED_SHAPE )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
|
|
|
double r = radius*0.5;
|
2021-06-07 18:31:53 +00:00
|
|
|
fprintf( m_outputFile, "0\nPOLYLINE\n" );
|
|
|
|
fprintf( m_outputFile, "8\n%s\n66\n1\n70\n1\n", TO_UTF8( cname ) );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "40\n%g\n41\n%g\n", radius, radius);
|
2021-06-07 18:31:53 +00:00
|
|
|
fprintf( m_outputFile, "0\nVERTEX\n8\n%s\n", TO_UTF8( cname ) );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "10\n%g\n 20\n%g\n42\n1.0\n",
|
2021-06-07 18:31:53 +00:00
|
|
|
centre_dev.x-r, centre_dev.y );
|
|
|
|
fprintf( m_outputFile, "0\nVERTEX\n8\n%s\n", TO_UTF8( cname ) );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "10\n%g\n 20\n%g\n42\n1.0\n",
|
2021-06-07 18:31:53 +00:00
|
|
|
centre_dev.x+r, centre_dev.y );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "0\nSEQEND\n");
|
2010-02-10 17:27:45 +00:00
|
|
|
}
|
2010-11-12 16:36:43 +00:00
|
|
|
}
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
|
2021-07-18 23:08:54 +00:00
|
|
|
void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList.size() <= 1 )
|
2009-06-30 10:43:20 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
unsigned last = aCornerList.size() - 1;
|
|
|
|
|
2014-05-15 06:32:24 +00:00
|
|
|
// Plot outlines with lines (thickness = 0) to define the polygon
|
2014-05-16 19:03:45 +00:00
|
|
|
if( aWidth <= 0 )
|
2014-05-15 06:32:24 +00:00
|
|
|
{
|
|
|
|
MoveTo( aCornerList[0] );
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
LineTo( aCornerList[ii] );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
// Close polygon if 'fill' requested
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2014-05-16 19:03:45 +00:00
|
|
|
{
|
|
|
|
if( aCornerList[last] != aCornerList[0] )
|
|
|
|
LineTo( aCornerList[0] );
|
|
|
|
}
|
2014-05-15 06:32:24 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
PenFinish();
|
|
|
|
|
|
|
|
return;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
2014-05-15 06:32:24 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
// if the polygon outline has thickness, and is not filled
|
|
|
|
// (i.e. is a polyline) plot outlines with thick segments
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aWidth > 0 && aFill == FILL_T::NO_FILL )
|
2014-05-15 06:32:24 +00:00
|
|
|
{
|
|
|
|
MoveTo( aCornerList[0] );
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
2021-07-15 19:26:35 +00:00
|
|
|
ThickSegment( aCornerList[ii-1], aCornerList[ii], aWidth, FILLED, nullptr );
|
2014-05-15 06:32:24 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The polygon outline has thickness, and is filled
|
|
|
|
// Build and plot the polygon which contains the initial
|
|
|
|
// polygon and its thick outline
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET bufferOutline;
|
|
|
|
SHAPE_POLY_SET bufferPolybase;
|
2014-05-16 19:03:45 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
bufferPolybase.NewOutline();
|
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
// enter outline as polygon:
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
{
|
2020-09-10 23:05:20 +00:00
|
|
|
TransformOvalToPolygon( bufferOutline, aCornerList[ ii - 1 ], aCornerList[ ii ],
|
2020-10-13 10:55:24 +00:00
|
|
|
aWidth, GetPlotterArcHighDef(), ERROR_INSIDE );
|
2014-05-16 19:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// enter the initial polygon:
|
|
|
|
for( unsigned ii = 0; ii < aCornerList.size(); ii++ )
|
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
bufferPolybase.Append( aCornerList[ii] );
|
2014-05-16 19:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Merge polygons to build the polygon which contains the initial
|
|
|
|
// polygon and its thick outline
|
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
// create the outline which contains thick outline:
|
|
|
|
bufferPolybase.BooleanAdd( bufferOutline, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
bufferPolybase.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2014-05-16 19:03:45 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( bufferPolybase.OutlineCount() < 1 ) // should not happen
|
2014-05-16 19:03:45 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& path = bufferPolybase.COutline( 0 );
|
2014-05-16 19:03:45 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( path.PointCount() < 2 ) // should not happen
|
2014-05-16 19:03:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Now, output the final polygon to DXF file:
|
2015-07-27 19:45:57 +00:00
|
|
|
last = path.PointCount() - 1;
|
2017-04-22 20:15:08 +00:00
|
|
|
VECTOR2I point = path.CPoint( 0 );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I startPoint( point.x, point.y );
|
2014-05-16 19:03:45 +00:00
|
|
|
MoveTo( startPoint );
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int ii = 1; ii < path.PointCount(); ii++ )
|
2014-05-16 19:03:45 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
point = path.CPoint( ii );
|
2021-12-29 19:02:50 +00:00
|
|
|
LineTo( VECTOR2I( point.x, point.y ) );
|
2014-05-15 06:32:24 +00:00
|
|
|
}
|
2014-05-16 19:03:45 +00:00
|
|
|
|
|
|
|
// Close polygon, if needed
|
2015-07-27 19:45:57 +00:00
|
|
|
point = path.CPoint( last );
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I endPoint( point.x, point.y );
|
2014-05-16 19:03:45 +00:00
|
|
|
|
|
|
|
if( endPoint != startPoint )
|
|
|
|
LineTo( startPoint );
|
|
|
|
|
|
|
|
PenFinish();
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
|
|
|
|
2009-06-30 10:43:20 +00:00
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
VECTOR2D pen_lastpos_dev = userToDeviceCoordinates( m_penLastpos );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
if( m_penLastpos != pos && plume == 'D' )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
wxASSERT( m_currentLineType >= PLOT_DASH_TYPE::FIRST_TYPE
|
|
|
|
&& m_currentLineType <= PLOT_DASH_TYPE::LAST_TYPE );
|
2012-10-13 18:54:33 +00:00
|
|
|
// DXF LINE
|
2019-12-28 00:55:11 +00:00
|
|
|
wxString cname = getDXFColorName( m_currentColor );
|
|
|
|
const char* lname = getDXFLineType( static_cast<PLOT_DASH_TYPE>( m_currentLineType ) );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "0\nLINE\n8\n%s\n6\n%s\n10\n%g\n20\n%g\n11\n%g\n21\n%g\n",
|
2017-11-13 17:29:49 +00:00
|
|
|
TO_UTF8( cname ), lname,
|
2012-05-03 18:37:56 +00:00
|
|
|
pen_lastpos_dev.x, pen_lastpos_dev.y, pos_dev.x, pos_dev.y );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_penLastpos = pos;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
void DXF_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
wxASSERT( aLineStyle >= PLOT_DASH_TYPE::FIRST_TYPE
|
|
|
|
&& aLineStyle <= PLOT_DASH_TYPE::LAST_TYPE );
|
|
|
|
|
|
|
|
m_currentLineType = aLineStyle;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::ThickSegment( const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE aPlotMode, void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2018-01-27 16:32:59 +00:00
|
|
|
if( aPlotMode == SKETCH )
|
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
std::vector<VECTOR2I> cornerList;
|
2018-01-27 16:32:59 +00:00
|
|
|
SHAPE_POLY_SET outlineBuffer;
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformOvalToPolygon( outlineBuffer, aStart, aEnd, aWidth, GetPlotterArcHighDef(),
|
|
|
|
ERROR_INSIDE );
|
2019-12-05 15:20:59 +00:00
|
|
|
const SHAPE_LINE_CHAIN& path = outlineBuffer.COutline( 0 );
|
2018-01-27 16:32:59 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
cornerList.reserve( path.PointCount() );
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2018-01-27 16:32:59 +00:00
|
|
|
for( int jj = 0; jj < path.PointCount(); jj++ )
|
2019-12-05 15:20:59 +00:00
|
|
|
cornerList.emplace_back( path.CPoint( jj ).x, path.CPoint( jj ).y );
|
2018-01-27 16:32:59 +00:00
|
|
|
|
|
|
|
// Ensure the polygon is closed
|
|
|
|
if( cornerList[0] != cornerList[cornerList.size() - 1] )
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL );
|
2018-01-27 16:32:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MoveTo( aStart );
|
|
|
|
FinishTo( aEnd );
|
|
|
|
}
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void DXF_PLOTTER::Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
|
|
|
|
const EDA_ANGLE& aEndAngle, int aRadius, FILL_T aFill, int aWidth )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aRadius <= 0 )
|
2009-06-30 10:43:20 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE startAngle( aStartAngle );
|
|
|
|
EDA_ANGLE endAngle( aEndAngle );
|
|
|
|
|
2013-12-19 11:33:57 +00:00
|
|
|
// In DXF, arcs are drawn CCW.
|
2022-01-16 01:06:25 +00:00
|
|
|
// If startAngle > endAngle, it is CW. So transform it to CCW
|
|
|
|
if( startAngle > endAngle )
|
|
|
|
std::swap( startAngle, endAngle );
|
2013-12-19 11:33:57 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2D centre_device = userToDeviceCoordinates( aCenter );
|
|
|
|
double radius_device = userToDeviceSize( aRadius );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// Emit a DXF ARC entity
|
2017-04-21 14:44:15 +00:00
|
|
|
wxString cname = getDXFColorName( m_currentColor );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2012-05-03 18:37:56 +00:00
|
|
|
"0\nARC\n8\n%s\n10\n%g\n20\n%g\n40\n%g\n50\n%g\n51\n%g\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( cname ),
|
2022-01-16 01:06:25 +00:00
|
|
|
centre_device.x, centre_device.y, radius_device,
|
|
|
|
startAngle.AsDegrees(), endAngle.AsDegrees() );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void DXF_PLOTTER::FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode, void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2022-01-16 01:06:25 +00:00
|
|
|
|
|
|
|
VECTOR2I size( aSize );
|
|
|
|
EDA_ANGLE orient( aOrient );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* The chip is reduced to an oval tablet with size.y > size.x
|
|
|
|
* (Oval vertical orientation 0) */
|
2009-06-30 10:43:20 +00:00
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2022-01-16 01:06:25 +00:00
|
|
|
orient += ANGLE_90;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
2013-12-19 11:33:57 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
sketchOval( aPos, size, orient, -1 );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::FlashPadCircle( const VECTOR2I& pos, int diametre,
|
2021-06-07 18:31:53 +00:00
|
|
|
OUTLINE_MODE trace_mode, void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::NO_FILL );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
void DXF_PLOTTER::FlashPadRect( const VECTOR2I& aPos, const VECTOR2I& aPadSize,
|
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode, void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
VECTOR2I size, start, end;
|
|
|
|
|
|
|
|
size.x = aPadSize.x / 2;
|
|
|
|
size.y = aPadSize.y / 2;
|
2009-06-30 10:43:20 +00:00
|
|
|
|
|
|
|
if( size.x < 0 )
|
|
|
|
size.x = 0;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2009-06-30 10:43:20 +00:00
|
|
|
if( size.y < 0 )
|
|
|
|
size.y = 0;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// If a dimension is zero, the trace is reduced to 1 line
|
2009-06-30 10:43:20 +00:00
|
|
|
if( size.x == 0 )
|
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
start = VECTOR2I( aPos.x, aPos.y - size.y );
|
|
|
|
end = VECTOR2I( aPos.x, aPos.y + size.y );
|
|
|
|
RotatePoint( start, aPos, aOrient );
|
|
|
|
RotatePoint( end, aPos, aOrient );
|
|
|
|
MoveTo( start );
|
|
|
|
FinishTo( end );
|
2009-06-30 10:43:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2009-06-30 10:43:20 +00:00
|
|
|
if( size.y == 0 )
|
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
start = VECTOR2I( aPos.x - size.x, aPos.y );
|
|
|
|
end = VECTOR2I( aPos.x + size.x, aPos.y );
|
|
|
|
RotatePoint( start, aPos, aOrient );
|
|
|
|
RotatePoint( end, aPos, aOrient );
|
|
|
|
MoveTo( start );
|
|
|
|
FinishTo( end );
|
2009-06-30 10:43:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
start = VECTOR2I( aPos.x - size.x, aPos.y - size.y );
|
|
|
|
RotatePoint( start, aPos, aOrient );
|
|
|
|
MoveTo( start );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
end = VECTOR2I( aPos.x - size.x, aPos.y + size.y );
|
|
|
|
RotatePoint( end, aPos, aOrient );
|
|
|
|
LineTo( end );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
end = VECTOR2I( aPos.x + size.x, aPos.y + size.y );
|
|
|
|
RotatePoint( end, aPos, aOrient );
|
|
|
|
LineTo( end );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
end = VECTOR2I( aPos.x + size.x, aPos.y - size.y );
|
|
|
|
RotatePoint( end, aPos, aOrient );
|
|
|
|
LineTo( end );
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
FinishTo( start );
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::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 )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
2022-01-16 01:06:25 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, aPadPos, aSize, aOrient, aCornerRadius, 0.0, 0,
|
|
|
|
0, GetPlotterArcHighDef(), ERROR_INSIDE );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( poly.CPoint( 0 ).x, poly.CPoint( 0 ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
for( int ii = 1; ii < poly.PointCount(); ++ii )
|
2021-12-29 19:02:50 +00:00
|
|
|
LineTo( VECTOR2I( poly.CPoint( ii ).x, poly.CPoint( ii ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
FinishTo( VECTOR2I( poly.CPoint( 0 ).x, poly.CPoint( 0 ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aOrient, SHAPE_POLY_SET* aPolygons,
|
2021-01-23 17:02:58 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
|
|
|
for( int cnt = 0; cnt < aPolygons->OutlineCount(); ++cnt )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = aPolygons->Outline( cnt );
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
MoveTo( VECTOR2I( poly.CPoint( 0 ).x, poly.CPoint( 0 ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
for( int ii = 1; ii < poly.PointCount(); ++ii )
|
2021-12-29 19:02:50 +00:00
|
|
|
LineTo( VECTOR2I( poly.CPoint( ii ).x, poly.CPoint( ii ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
FinishTo( VECTOR2I( poly.CPoint( 0 ).x, poly.CPoint( 0 ).y ) );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:43:20 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData )
|
2009-06-30 10:43:20 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I coord[4]; /* coord actual corners of a trapezoidal trace */
|
2009-06-30 10:43:20 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
2010-09-13 11:51:09 +00:00
|
|
|
coord[ii] = aCorners[ii];
|
2021-12-29 19:02:50 +00:00
|
|
|
RotatePoint( coord[ii], aPadOrient );
|
2010-09-13 11:51:09 +00:00
|
|
|
coord[ii] += aPadPos;
|
2009-06-30 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Plot edge:
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( coord[0] );
|
|
|
|
LineTo( coord[1] );
|
|
|
|
LineTo( coord[2] );
|
|
|
|
LineTo( coord[3] );
|
|
|
|
FinishTo( coord[0] );
|
|
|
|
}
|
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::FlashRegularPolygon( const VECTOR2I& aShapePos, int aRadius, int aCornerCount,
|
2022-01-16 01:06:25 +00:00
|
|
|
const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
|
|
|
|
void* aData )
|
2019-10-02 15:16:27 +00:00
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
wxASSERT( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 11:53:16 +00:00
|
|
|
/**
|
2021-06-07 18:31:53 +00:00
|
|
|
* Check if a given string contains non-ASCII characters.
|
|
|
|
*
|
|
|
|
* @param string String to check.
|
2013-02-15 11:53:16 +00:00
|
|
|
* @return true if it contains some non-ASCII character, false if all characters are
|
|
|
|
* inside ASCII range (<=255).
|
|
|
|
*/
|
|
|
|
bool containsNonAsciiChars( const wxString& string )
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < string.length(); i++ )
|
|
|
|
{
|
|
|
|
wchar_t ch = string[i];
|
2021-12-03 17:44:43 +00:00
|
|
|
|
2013-02-15 11:53:16 +00:00
|
|
|
if( ch > 255 )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void DXF_PLOTTER::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,
|
|
|
|
bool aMultilineAllowed,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
void* aData )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2014-04-28 16:13:18 +00:00
|
|
|
// Fix me: see how to use DXF text mode for multiline texts
|
|
|
|
if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) )
|
|
|
|
aMultilineAllowed = false; // the text has only one line.
|
|
|
|
|
2020-04-18 20:04:41 +00:00
|
|
|
bool processSuperSub = aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) );
|
2020-01-09 00:13:02 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
if( m_textAsLines || containsNonAsciiChars( aText ) || aMultilineAllowed || processSuperSub )
|
2014-04-28 16:13:18 +00:00
|
|
|
{
|
|
|
|
// output text as graphics.
|
2017-04-16 17:07:31 +00:00
|
|
|
// Perhaps multiline texts could be handled as DXF text entity
|
2014-04-28 16:13:18 +00:00
|
|
|
// but I do not want spend time about this (JPC)
|
2021-12-29 17:31:40 +00:00
|
|
|
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
|
|
|
|
aBold, aMultilineAllowed, aFont, aData );
|
2014-04-28 16:13:18 +00:00
|
|
|
}
|
2012-10-13 18:54:33 +00:00
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
TEXT_ATTRIBUTES attrs;
|
|
|
|
attrs.m_Halign = aH_justify;
|
|
|
|
attrs.m_Valign =aV_justify;
|
|
|
|
attrs.m_StrokeWidth = aWidth;
|
|
|
|
attrs.m_Angle = aOrient;
|
|
|
|
attrs.m_Italic = aItalic;
|
|
|
|
attrs.m_Bold = aBold;
|
|
|
|
attrs.m_Mirrored = aSize.x < 0;
|
|
|
|
attrs.m_Multiline = false;
|
|
|
|
plotOneLineOfText( aPos, aColor, aText, attrs );
|
|
|
|
}
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttributes,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
void* aData )
|
|
|
|
{
|
|
|
|
TEXT_ATTRIBUTES attrs = aAttributes;
|
|
|
|
// Fix me: see how to use DXF text mode for multiline texts
|
|
|
|
if( attrs.m_Multiline && !aText.Contains( wxT( "\n" ) ) )
|
|
|
|
attrs.m_Multiline = false; // the text has only one line.
|
|
|
|
|
|
|
|
bool processSuperSub = aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) );
|
|
|
|
|
|
|
|
if( m_textAsLines || containsNonAsciiChars( aText ) || attrs.m_Multiline || processSuperSub )
|
|
|
|
{
|
|
|
|
// output text as graphics.
|
|
|
|
// Perhaps multiline texts could be handled as DXF text entity
|
|
|
|
// but I do not want spend time about that (JPC)
|
|
|
|
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
plotOneLineOfText( aPos, aColor, aText, attrs );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DXF_PLOTTER::plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttributes )
|
|
|
|
{
|
|
|
|
/* Emit text as a text entity. This loses formatting and shape but it's
|
|
|
|
more useful as a CAD object */
|
|
|
|
VECTOR2D origin_dev = userToDeviceCoordinates( aPos );
|
|
|
|
SetColor( aColor );
|
|
|
|
wxString cname = getDXFColorName( m_currentColor );
|
|
|
|
VECTOR2D size_dev = userToDeviceSize( aAttributes.m_Size );
|
|
|
|
int h_code = 0, v_code = 0;
|
|
|
|
|
|
|
|
switch( aAttributes.m_Halign )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT: h_code = 0; break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: h_code = 1; break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: h_code = 2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( aAttributes.m_Valign )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP: v_code = 3; break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: v_code = 2; break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: v_code = 1; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position, size, rotation and alignment
|
|
|
|
// The two alignment point usages is somewhat idiot (see the DXF ref)
|
|
|
|
// Anyway since we don't use the fit/aligned options, they're the same
|
|
|
|
fprintf( m_outputFile,
|
|
|
|
" 0\n"
|
|
|
|
"TEXT\n"
|
|
|
|
" 7\n"
|
|
|
|
"%s\n" // Text style
|
|
|
|
" 8\n"
|
|
|
|
"%s\n" // Layer name
|
|
|
|
" 10\n"
|
|
|
|
"%g\n" // First point X
|
|
|
|
" 11\n"
|
|
|
|
"%g\n" // Second point X
|
|
|
|
" 20\n"
|
|
|
|
"%g\n" // First point Y
|
|
|
|
" 21\n"
|
|
|
|
"%g\n" // Second point Y
|
|
|
|
" 40\n"
|
|
|
|
"%g\n" // Text height
|
|
|
|
" 41\n"
|
|
|
|
"%g\n" // Width factor
|
|
|
|
" 50\n"
|
|
|
|
"%g\n" // Rotation
|
|
|
|
" 51\n"
|
|
|
|
"%g\n" // Oblique angle
|
|
|
|
" 71\n"
|
|
|
|
"%d\n" // Mirror flags
|
|
|
|
" 72\n"
|
|
|
|
"%d\n" // H alignment
|
|
|
|
" 73\n"
|
|
|
|
"%d\n", // V alignment
|
|
|
|
aAttributes.m_Bold ?
|
|
|
|
(aAttributes.m_Italic ? "KICADBI" : "KICADB")
|
|
|
|
: (aAttributes.m_Italic ? "KICADI" : "KICAD"), TO_UTF8( cname ),
|
|
|
|
origin_dev.x, origin_dev.x,
|
|
|
|
origin_dev.y, origin_dev.y,
|
|
|
|
size_dev.y, fabs( size_dev.x / size_dev.y ),
|
|
|
|
aAttributes.m_Angle.AsDegrees(),
|
|
|
|
aAttributes.m_Italic ? DXF_OBLIQUE_ANGLE : 0,
|
|
|
|
aAttributes.m_Mirrored ? 2 : 0, // X mirror flag
|
|
|
|
h_code, v_code );
|
|
|
|
|
|
|
|
/* There are two issue in emitting the text:
|
|
|
|
- Our overline character (~) must be converted to the appropriate
|
|
|
|
control sequence %%O or %%o
|
|
|
|
- Text encoding in DXF is more or less unspecified since depends on
|
|
|
|
the DXF declared version, the acad version reading it *and* some
|
|
|
|
system variables to be put in the header handled only by newer acads
|
|
|
|
Also before R15 unicode simply is not supported (you need to use
|
|
|
|
bigfonts which are a massive PITA). Common denominator solution:
|
|
|
|
use Latin1 (and however someone could choke on it, anyway). Sorry
|
|
|
|
for the extended latin people. If somewant want to try fixing this
|
|
|
|
recent version seems to use UTF-8 (and not UCS2 like the rest of
|
|
|
|
Windows)
|
|
|
|
|
|
|
|
XXX Actually there is a *third* issue: older DXF formats are limited
|
|
|
|
to 255 bytes records (it was later raised to 2048); since I'm lazy
|
|
|
|
and text so long is not probable I just don't implement this rule.
|
|
|
|
If someone is interested in fixing this, you have to emit the first
|
|
|
|
partial lines with group code 3 (max 250 bytes each) and then finish
|
|
|
|
with a group code 1 (less than 250 bytes). The DXF refs explains it
|
|
|
|
in no more details...
|
|
|
|
*/
|
|
|
|
|
|
|
|
int braceNesting = 0;
|
|
|
|
int overbarDepth = -1;
|
|
|
|
|
|
|
|
fputs( " 1\n", m_outputFile );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < aText.length(); i++ )
|
|
|
|
{
|
|
|
|
/* Here I do a bad thing: writing the output one byte at a time!
|
|
|
|
but today I'm lazy and I have no idea on how to coerce a Unicode
|
|
|
|
wxString to spit out latin1 encoded text ...
|
|
|
|
|
|
|
|
At least stdio is *supposed* to do output buffering, so there is
|
|
|
|
hope is not too slow */
|
|
|
|
wchar_t ch = aText[i];
|
|
|
|
|
|
|
|
if( ch > 255 )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
// I can't encode this...
|
|
|
|
putc( '?', m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2023-02-24 08:44:25 +00:00
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
if( aText[i] == '~' && i+1 < aText.length() && aText[i+1] == '{' )
|
|
|
|
{
|
|
|
|
fputs( "%%o", m_outputFile );
|
|
|
|
overbarDepth = braceNesting;
|
2019-11-18 11:35:42 +00:00
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
// Skip the '{'
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( aText[i] == '{' )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
braceNesting++;
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2023-02-24 08:44:25 +00:00
|
|
|
else if( aText[i] == '}' )
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
if( braceNesting > 0 )
|
|
|
|
braceNesting--;
|
2019-11-18 11:35:42 +00:00
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
if( braceNesting == overbarDepth )
|
2021-06-05 13:52:58 +00:00
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
fputs( "%%O", m_outputFile );
|
|
|
|
overbarDepth = -1;
|
|
|
|
continue;
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
putc( ch, m_outputFile );
|
|
|
|
}
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
putc( '\n', m_outputFile );
|
|
|
|
}
|