Allow DXF to be exported in either inches or millimeters

Fixes: lp:1832188
* https://bugs.launchpad.net/kicad/+bug/1832188
This commit is contained in:
Ian McInerney 2019-06-13 01:28:22 +01:00 committed by Seth Hillbrand
parent b2c848579a
commit d5f680ecd2
6 changed files with 217 additions and 114 deletions

View File

@ -121,6 +121,26 @@ static wxString getDXFColorName( COLOR4D aColor )
return cname; return cname;
} }
void DXF_PLOTTER::SetUnits( Units aUnit )
{
m_plotUnits = aUnit;
switch( aUnit )
{
case MILIMETERS:
m_unitScalingFactor = 0.00254;
m_measurementDirective = 1;
break;
case INCHES:
default:
m_unitScalingFactor = 0.0001;
m_measurementDirective = 0;
}
}
/** /**
* Set the scale/position for the DXF plot * Set the scale/position for the DXF plot
* The DXF engine doesn't support line widths and mirroring. The output * The DXF engine doesn't support line widths and mirroring. The output
@ -143,7 +163,7 @@ void DXF_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
* english units */ * english units */
m_IUsPerDecimil = aIusPerDecimil; m_IUsPerDecimil = aIusPerDecimil;
iuPerDeviceUnit = 1.0 / aIusPerDecimil; // Gives a DXF in decimils iuPerDeviceUnit = 1.0 / aIusPerDecimil; // Gives a DXF in decimils
iuPerDeviceUnit *= 0.0001; // ... now in inches iuPerDeviceUnit *= GetUnitScaling(); // Get the scaling factor for the current units
SetDefaultLineWidth( 0 ); // No line width on DXF SetDefaultLineWidth( 0 ); // No line width on DXF
m_plotMirror = false; // No mirroring on DXF m_plotMirror = false; // No mirroring on DXF
@ -160,117 +180,118 @@ bool DXF_PLOTTER::StartPlot()
// DXF HEADER - Boilerplate // DXF HEADER - Boilerplate
// Defines the minimum for drawing i.e. the angle system and the // Defines the minimum for drawing i.e. the angle system and the
// 4 linetypes (CONTINUOUS, DOTDASH, DASHED and DOTTED) // 4 linetypes (CONTINUOUS, DOTDASH, DASHED and DOTTED)
fputs( " 0\n" fprintf( outputFile,
"SECTION\n" " 0\n"
" 2\n" "SECTION\n"
"HEADER\n" " 2\n"
" 9\n" "HEADER\n"
"$ANGBASE\n" " 9\n"
" 50\n" "$ANGBASE\n"
"0.0\n" " 50\n"
" 9\n" "0.0\n"
"$ANGDIR\n" " 9\n"
" 70\n" "$ANGDIR\n"
" 1\n" " 70\n"
" 9\n" "1\n"
"$MEASUREMENT\n" " 9\n"
" 70\n" "$MEASUREMENT\n"
"0\n" " 70\n"
" 0\n" // This means 'english units' "%u\n"
"ENDSEC\n" " 0\n"
" 0\n" "ENDSEC\n"
"SECTION\n" " 0\n"
" 2\n" "SECTION\n"
"TABLES\n" " 2\n"
" 0\n" "TABLES\n"
"TABLE\n" " 0\n"
" 2\n" "TABLE\n"
"LTYPE\n" " 2\n"
" 70\n" "LTYPE\n"
"4\n" " 70\n"
" 0\n" "4\n"
"LTYPE\n" " 0\n"
" 5\n" "LTYPE\n"
"40F\n" " 5\n"
" 2\n" "40F\n"
"CONTINUOUS\n" " 2\n"
" 70\n" "CONTINUOUS\n"
"0\n" " 70\n"
" 3\n" "0\n"
"Solid line\n" " 3\n"
" 72\n" "Solid line\n"
"65\n" " 72\n"
" 73\n" "65\n"
"0\n" " 73\n"
" 40\n" "0\n"
"0.0\n" " 40\n"
" 0\n" "0.0\n"
"LTYPE\n" " 0\n"
" 5\n" "LTYPE\n"
"410\n" " 5\n"
" 2\n" "410\n"
"DASHDOT\n" " 2\n"
" 70\n" "DASHDOT\n"
"0\n" " 70\n"
" 3\n" "0\n"
"Dash Dot ____ _ ____ _\n" " 3\n"
" 72\n" "Dash Dot ____ _ ____ _\n"
"65\n" " 72\n"
" 73\n" "65\n"
"4\n" " 73\n"
" 40\n" "4\n"
"2.0\n" " 40\n"
" 49\n" "2.0\n"
"1.25\n" " 49\n"
" 49\n" "1.25\n"
"-0.25\n" " 49\n"
" 49\n" "-0.25\n"
"0.25\n" " 49\n"
" 49\n" "0.25\n"
"-0.25\n" " 49\n"
" 0\n" "-0.25\n"
"LTYPE\n" " 0\n"
" 5\n" "LTYPE\n"
"411\n" " 5\n"
" 2\n" "411\n"
"DASHED\n" " 2\n"
" 70\n" "DASHED\n"
"0\n" " 70\n"
" 3\n" "0\n"
"Dashed __ __ __ __ __\n" " 3\n"
" 72\n" "Dashed __ __ __ __ __\n"
"65\n" " 72\n"
" 73\n" "65\n"
"2\n" " 73\n"
" 40\n" "2\n"
"0.75\n" " 40\n"
" 49\n" "0.75\n"
"0.5\n" " 49\n"
" 49\n" "0.5\n"
"-0.25\n" " 49\n"
" 0\n" "-0.25\n"
"LTYPE\n" " 0\n"
" 5\n" "LTYPE\n"
"43B\n" " 5\n"
" 2\n" "43B\n"
"DOTTED\n" " 2\n"
" 70\n" "DOTTED\n"
"0\n" " 70\n"
" 3\n" "0\n"
"Dotted . . . .\n" " 3\n"
" 72\n" "Dotted . . . .\n"
"65\n" " 72\n"
" 73\n" "65\n"
"2\n" " 73\n"
" 40\n" "2\n"
"0.2\n" " 40\n"
" 49\n" "0.2\n"
"0.0\n" " 49\n"
" 49\n" "0.0\n"
"-0.2\n" " 49\n"
" 0\n" "-0.2\n"
"ENDTAB\n", " 0\n"
outputFile ); "ENDTAB\n",
GetMeasurementDirective() );
// Text styles table // Text styles table
// Defines 4 text styles, one for each bold/italic combination // Defines 4 text styles, one for each bold/italic combination

View File

@ -1259,6 +1259,7 @@ public:
textAsLines = true; textAsLines = true;
m_currentColor = COLOR4D::BLACK; m_currentColor = COLOR4D::BLACK;
m_currentLineType = 0; m_currentLineType = 0;
SetUnits( DXF_PLOTTER::INCHES );
} }
virtual PlotFormat GetPlotterType() const override virtual PlotFormat GetPlotterType() const override
@ -1341,10 +1342,60 @@ public:
bool aMultilineAllowed = false, bool aMultilineAllowed = false,
void* aData = NULL ) override; void* aData = NULL ) override;
// Should be the same order as in the PCB_PLOT_PARAMS class
enum Units
{
INCHES = 0,
MILIMETERS = 1
};
/**
* Set the units to use for plotting the DXF file.
*
* @param aUnit - The units to use
*/
void SetUnits( Units aUnit );
/**
* The units currently enabled for plotting
*
* @return The currently configured units
*/
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: protected:
bool textAsLines; bool textAsLines;
COLOR4D m_currentColor; COLOR4D m_currentColor;
int m_currentLineType; int m_currentLineType;
Units m_plotUnits;
double m_unitScalingFactor;
unsigned int m_measurementDirective;
}; };
class TITLE_BLOCK; class TITLE_BLOCK;

View File

@ -573,6 +573,8 @@ void DIALOG_PLOT::applyPlotSettings()
tempOptions.SetMirror( m_plotMirrorOpt->GetValue() ); tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED ); tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() ); tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
tempOptions.SetDXFPlotUnits(
static_cast<PCB_PLOT_PARAMS::Units>( m_DXF_plotUnits->GetSelection() ) );
tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() ); tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option

View File

@ -103,6 +103,7 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
m_plotViaOnMaskLayer = false; m_plotViaOnMaskLayer = false;
m_plotMode = FILLED; m_plotMode = FILLED;
m_DXFplotPolygonMode = true; m_DXFplotPolygonMode = true;
m_DXFplotUnits = INCHES;
m_useAuxOrigin = false; m_useAuxOrigin = false;
m_HPGLPenNum = 1; m_HPGLPenNum = 1;
m_HPGLPenSpeed = 20; // this param is always in cm/s m_HPGLPenSpeed = 20; // this param is always in cm/s
@ -260,7 +261,9 @@ bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams, bool aCom
if( !aCompareOnlySavedPrms ) if( !aCompareOnlySavedPrms )
{ {
if( m_DXFplotPolygonMode != aPcbPlotParams.m_DXFplotPolygonMode ) if( m_DXFplotPolygonMode != aPcbPlotParams.m_DXFplotPolygonMode )
return false; return false;
if( m_DXFplotUnits != aPcbPlotParams.m_DXFplotUnits )
return false;
} }
if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin ) if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin )
return false; return false;

View File

@ -44,6 +44,13 @@ public:
FULL_DRILL_SHAPE = 2 FULL_DRILL_SHAPE = 2
}; };
// Must be in the same order as the drop-down list in the plot dialog
enum Units
{
INCHES = 0,
MILIMETERS = 1,
};
private: private:
// If true, do not plot NPTH pads // If true, do not plot NPTH pads
// (mainly used to disable NPTH pads plotting on copper layers) // (mainly used to disable NPTH pads plotting on copper layers)
@ -60,6 +67,11 @@ private:
*/ */
bool m_DXFplotPolygonMode; bool m_DXFplotPolygonMode;
/**
* DXF format: Units to use when plotting the DXF
*/
Units m_DXFplotUnits;
/// Plot format type (chooses the driver to be used) /// Plot format type (chooses the driver to be used)
PlotFormat m_format; PlotFormat m_format;
@ -196,6 +208,16 @@ public:
void SetDXFPlotPolygonMode( bool aFlag ) { m_DXFplotPolygonMode = aFlag; } void SetDXFPlotPolygonMode( bool aFlag ) { m_DXFplotPolygonMode = aFlag; }
bool GetDXFPlotPolygonMode() const { return m_DXFplotPolygonMode; } bool GetDXFPlotPolygonMode() const { return m_DXFplotPolygonMode; }
void SetDXFPlotUnits( Units aUnit )
{
m_DXFplotUnits = aUnit;
}
Units GetDXFPlotUnits() const
{
return m_DXFplotUnits;
}
void SetDrillMarksType( DrillMarksType aVal ) { m_drillMarks = aVal; } void SetDrillMarksType( DrillMarksType aVal ) { m_drillMarks = aVal; }
DrillMarksType GetDrillMarksType() const { return m_drillMarks; } DrillMarksType GetDrillMarksType() const { return m_drillMarks; }

View File

@ -1026,7 +1026,11 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts,
switch( aPlotOpts->GetFormat() ) switch( aPlotOpts->GetFormat() )
{ {
case PLOT_FORMAT_DXF: case PLOT_FORMAT_DXF:
plotter = new DXF_PLOTTER(); DXF_PLOTTER* DXF_plotter;
DXF_plotter = new DXF_PLOTTER();
DXF_plotter->SetUnits( static_cast<DXF_PLOTTER::Units>( aPlotOpts->GetDXFPlotUnits() ) );
plotter = DXF_plotter;
break; break;
case PLOT_FORMAT_POST: case PLOT_FORMAT_POST: