DXF parameters are for DXF (only).

Fixes https://gitlab.com/kicad/code/kicad/issues/12021

(cherry picked from commit 763c77eab8)
This commit is contained in:
Jeff Young 2022-07-18 17:49:50 +01:00
parent 39dd51490d
commit 466f1283c1
5 changed files with 73 additions and 40 deletions

View File

@ -45,7 +45,7 @@ bool DIALOG_IMPORT_GFX::m_shouldGroupItems = true;
LAYER_NUM DIALOG_IMPORT_GFX::m_layer = Dwgs_User; LAYER_NUM DIALOG_IMPORT_GFX::m_layer = Dwgs_User;
double DIALOG_IMPORT_GFX::m_scaleImport = 1.0; // Do not change the imported items size double DIALOG_IMPORT_GFX::m_scaleImport = 1.0; // Do not change the imported items size
int DIALOG_IMPORT_GFX::m_originUnits = 0; // millimeter int DIALOG_IMPORT_GFX::m_originUnits = 0; // millimeter
int DIALOG_IMPORT_GFX::m_lineWidthUnits = 0; // millimeter int DIALOG_IMPORT_GFX::m_dxfLineWidthUnits = 0; // millimeter
int DIALOG_IMPORT_GFX::m_dxfUnits = 0; // first entry in the dxfUnits map below int DIALOG_IMPORT_GFX::m_dxfUnits = 0; // first entry in the dxfUnits map below
const std::map<DXF_IMPORT_UNITS, wxString> dxfUnitsMap = { const std::map<DXF_IMPORT_UNITS, wxString> dxfUnitsMap = {
@ -86,23 +86,23 @@ DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aImportAsFoo
m_originUnits = 0; m_originUnits = 0;
m_origin.x = 0.0; // always in mm m_origin.x = 0.0; // always in mm
m_origin.y = 0.0; // always in mm m_origin.y = 0.0; // always in mm
m_lineWidth = 0.2; // always in mm m_dxfLineWidth = 0.2; // always in mm
m_lineWidthUnits = 0; m_dxfLineWidthUnits = 0;
auto cfg = m_parent->GetPcbNewSettings(); auto cfg = m_parent->GetPcbNewSettings();
m_layer = cfg->m_ImportGraphics.layer; m_layer = cfg->m_ImportGraphics.layer;
m_placementInteractive = cfg->m_ImportGraphics.interactive_placement; m_placementInteractive = cfg->m_ImportGraphics.interactive_placement;
m_filename = cfg->m_ImportGraphics.last_file; m_filename = cfg->m_ImportGraphics.last_file;
m_lineWidth = cfg->m_ImportGraphics.line_width; m_dxfLineWidth = cfg->m_ImportGraphics.dxf_line_width;
m_lineWidthUnits = cfg->m_ImportGraphics.line_width_units; m_dxfLineWidthUnits = cfg->m_ImportGraphics.dxf_line_width_units;
m_originUnits = cfg->m_ImportGraphics.origin_units; m_originUnits = cfg->m_ImportGraphics.origin_units;
m_origin.x = cfg->m_ImportGraphics.origin_x; m_origin.x = cfg->m_ImportGraphics.origin_x;
m_origin.y = cfg->m_ImportGraphics.origin_y; m_origin.y = cfg->m_ImportGraphics.origin_y;
m_dxfUnits = cfg->m_ImportGraphics.dxf_units; m_dxfUnits = cfg->m_ImportGraphics.dxf_units;
m_choiceUnitLineWidth->SetSelection( m_lineWidthUnits ); m_choiceUnitLineWidth->SetSelection( m_dxfLineWidthUnits );
showPCBdefaultLineWidth(); showDXFDefaultLineWidth();
m_DxfPcbPositionUnits->SetSelection( m_originUnits ); m_DxfPcbPositionUnits->SetSelection( m_originUnits );
showPcbImportOffsets(); showPcbImportOffsets();
@ -132,11 +132,18 @@ DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aImportAsFoo
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) ); m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
wxCommandEvent dummy;
onFilename( dummy );
SetInitialFocus( m_textCtrlFileName ); SetInitialFocus( m_textCtrlFileName );
m_sdbSizerOK->SetDefault(); m_sdbSizerOK->SetDefault();
GetSizer()->Fit( this ); GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
Centre(); Centre();
m_textCtrlFileName->Connect( wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler( DIALOG_IMPORT_GFX::onFilename ),
NULL, this );
} }
@ -147,16 +154,37 @@ DIALOG_IMPORT_GFX::~DIALOG_IMPORT_GFX()
cfg->m_ImportGraphics.layer = m_layer; cfg->m_ImportGraphics.layer = m_layer;
cfg->m_ImportGraphics.interactive_placement = m_placementInteractive; cfg->m_ImportGraphics.interactive_placement = m_placementInteractive;
cfg->m_ImportGraphics.last_file = m_filename; cfg->m_ImportGraphics.last_file = m_filename;
cfg->m_ImportGraphics.line_width = m_lineWidth; cfg->m_ImportGraphics.dxf_line_width = m_dxfLineWidth;
cfg->m_ImportGraphics.line_width_units = m_lineWidthUnits; cfg->m_ImportGraphics.dxf_line_width_units = m_dxfLineWidthUnits;
cfg->m_ImportGraphics.origin_units = m_originUnits; cfg->m_ImportGraphics.origin_units = m_originUnits;
cfg->m_ImportGraphics.origin_x = m_origin.x; cfg->m_ImportGraphics.origin_x = m_origin.x;
cfg->m_ImportGraphics.origin_y = m_origin.y; cfg->m_ImportGraphics.origin_y = m_origin.y;
cfg->m_ImportGraphics.dxf_units = m_dxfUnits; cfg->m_ImportGraphics.dxf_units = m_dxfUnits;
m_textCtrlFileName->Disconnect( wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler( DIALOG_IMPORT_GFX::onFilename ),
NULL, this );
} }
void DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX::onUnitPositionSelection( wxCommandEvent& event ) void DIALOG_IMPORT_GFX::onFilename( wxCommandEvent& event )
{
bool enableDXFControls = true;
wxString filename = m_textCtrlFileName->GetValue();
if( auto plugin = m_gfxImportMgr->GetPluginByExt( wxFileName( filename ).GetExt() ) )
enableDXFControls = dynamic_cast<DXF_IMPORT_PLUGIN*>( plugin.get() ) != nullptr;
m_staticTextLineWidth->Enable( enableDXFControls );
m_textCtrlLineWidth->Enable( enableDXFControls );
m_choiceUnitLineWidth->Enable( enableDXFControls );
m_staticTextLineWidth1->Enable( enableDXFControls );
m_choiceDxfUnits->Enable( enableDXFControls );
}
void DIALOG_IMPORT_GFX::onUnitPositionSelection( wxCommandEvent& event )
{ {
// Collect last entered values: // Collect last entered values:
updatePcbImportOffsets_mm(); updatePcbImportOffsets_mm();
@ -166,11 +194,11 @@ void DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX::onUnitPositionSelection( wxCommandEve
} }
double DIALOG_IMPORT_GFX::getPCBdefaultLineWidthMM() double DIALOG_IMPORT_GFX::getDXFDefaultLineWidthMM()
{ {
double value = DoubleValueFromString( EDA_UNITS::UNSCALED, m_textCtrlLineWidth->GetValue() ); double value = DoubleValueFromString( EDA_UNITS::UNSCALED, m_textCtrlLineWidth->GetValue() );
switch( m_lineWidthUnits ) switch( m_dxfLineWidthUnits )
{ {
default: default:
case 0: break; // display units = mm case 0: break; // display units = mm
@ -184,11 +212,11 @@ double DIALOG_IMPORT_GFX::getPCBdefaultLineWidthMM()
void DIALOG_IMPORT_GFX::onUnitWidthSelection( wxCommandEvent& event ) void DIALOG_IMPORT_GFX::onUnitWidthSelection( wxCommandEvent& event )
{ {
m_lineWidth = getPCBdefaultLineWidthMM(); m_dxfLineWidth = getDXFDefaultLineWidthMM();
// Switch to new units // Switch to new units
m_lineWidthUnits = m_choiceUnitLineWidth->GetSelection(); m_dxfLineWidthUnits = m_choiceUnitLineWidth->GetSelection();
showPCBdefaultLineWidth(); showDXFDefaultLineWidth();
} }
@ -206,16 +234,16 @@ void DIALOG_IMPORT_GFX::showPcbImportOffsets()
} }
void DIALOG_IMPORT_GFX::showPCBdefaultLineWidth() void DIALOG_IMPORT_GFX::showDXFDefaultLineWidth()
{ {
double value; double value;
switch( m_lineWidthUnits ) switch( m_dxfLineWidthUnits )
{ {
default: default:
case 0: value = m_lineWidth; break; // display units = mm case 0: value = m_dxfLineWidth; break; // display units = mm
case 1: value = m_lineWidth / 25.4 * 1000; break; // display units = mil case 1: value = m_dxfLineWidth / 25.4 * 1000; break; // display units = mil
case 2: value = m_lineWidth / 25.4; break; // display units = inch case 2: value = m_dxfLineWidth / 25.4; break; // display units = inch
} }
m_textCtrlLineWidth->SetValue( wxString::Format( wxT( "%f" ), value ) ); m_textCtrlLineWidth->SetValue( wxString::Format( wxT( "%f" ), value ) );
@ -238,10 +266,10 @@ void DIALOG_IMPORT_GFX::onBrowseFiles( wxCommandEvent& event )
wxString wildcardsDesc; wxString wildcardsDesc;
wxString allWildcards; wxString allWildcards;
for( auto pluginType : m_gfxImportMgr->GetImportableFileTypes() ) for( GRAPHICS_IMPORT_MGR::GFX_FILE_T pluginType : m_gfxImportMgr->GetImportableFileTypes() )
{ {
auto plugin = m_gfxImportMgr->GetPlugin( pluginType ); std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin = m_gfxImportMgr->GetPlugin( pluginType );
const auto extensions = plugin->GetFileExtensions(); const std::vector<std::string> extensions = plugin->GetFileExtensions();
wildcardsDesc += wxT( "|" ) + plugin->GetName() + AddFileExtListToFilter( extensions ); wildcardsDesc += wxT( "|" ) + plugin->GetName() + AddFileExtListToFilter( extensions );
allWildcards += plugin->GetWildcards() + wxT( ";" ); allWildcards += plugin->GetWildcards() + wxT( ";" );
@ -289,19 +317,18 @@ bool DIALOG_IMPORT_GFX::TransferDataFromWindow()
return false; return false;
} }
m_lineWidthUnits = m_choiceUnitLineWidth->GetSelection(); m_dxfLineWidthUnits = m_choiceUnitLineWidth->GetSelection();
m_lineWidth = getPCBdefaultLineWidthMM(); m_dxfLineWidth = getDXFDefaultLineWidthMM();
m_dxfUnits = m_choiceDxfUnits->GetSelection(); m_dxfUnits = m_choiceDxfUnits->GetSelection();
m_importer->SetLayer( PCB_LAYER_ID( m_layer ) ); m_importer->SetLayer( PCB_LAYER_ID( m_layer ) );
auto plugin = m_gfxImportMgr->GetPluginByExt( wxFileName( m_filename ).GetExt() ); if( auto plugin = m_gfxImportMgr->GetPluginByExt( wxFileName( m_filename ).GetExt() ) )
if( plugin )
{ {
DXF_IMPORT_PLUGIN* dxfPlugin = dynamic_cast<DXF_IMPORT_PLUGIN*>( plugin.get() ); DXF_IMPORT_PLUGIN* dxfPlugin = dynamic_cast<DXF_IMPORT_PLUGIN*>( plugin.get() );
if( dxfPlugin != nullptr )
if( dxfPlugin )
{ {
auto it = dxfUnitsMap.begin(); auto it = dxfUnitsMap.begin();
std::advance( it, m_dxfUnits ); std::advance( it, m_dxfUnits );
@ -310,6 +337,12 @@ bool DIALOG_IMPORT_GFX::TransferDataFromWindow()
dxfPlugin->SetUnit( DXF_IMPORT_UNITS::DEFAULT ); dxfPlugin->SetUnit( DXF_IMPORT_UNITS::DEFAULT );
else else
dxfPlugin->SetUnit( it->first ); dxfPlugin->SetUnit( it->first );
m_importer->SetLineWidthMM( m_dxfLineWidth );
}
else
{
m_importer->SetLineWidthMM( 0.0 );
} }
// Set coordinates offset for import (offset is given in mm) // Set coordinates offset for import (offset is given in mm)
@ -317,9 +350,6 @@ bool DIALOG_IMPORT_GFX::TransferDataFromWindow()
m_scaleImport = DoubleValueFromString( EDA_UNITS::UNSCALED, m_scaleImport = DoubleValueFromString( EDA_UNITS::UNSCALED,
m_textCtrlImportScale->GetValue() ); m_textCtrlImportScale->GetValue() );
// The line width is meant to be in pcbnew units, so we scale the import width before
// applying
m_importer->SetLineWidthMM( m_lineWidth );
m_importer->SetPlugin( std::move( plugin ) ); m_importer->SetPlugin( std::move( plugin ) );
LOCALE_IO dummy; // Ensure floats can be read. LOCALE_IO dummy; // Ensure floats can be read.

View File

@ -71,6 +71,7 @@ private:
void onUnitPositionSelection( wxCommandEvent& event ) override; void onUnitPositionSelection( wxCommandEvent& event ) override;
void onUnitWidthSelection( wxCommandEvent& event ) override; void onUnitWidthSelection( wxCommandEvent& event ) override;
void onBrowseFiles( wxCommandEvent& event ) override; void onBrowseFiles( wxCommandEvent& event ) override;
void onFilename( wxCommandEvent& event );
void originOptionOnUpdateUI( wxUpdateUIEvent& event ) override; void originOptionOnUpdateUI( wxUpdateUIEvent& event ) override;
void onInteractivePlacement( wxCommandEvent& event ) override void onInteractivePlacement( wxCommandEvent& event ) override
@ -89,8 +90,8 @@ private:
} }
void updatePcbImportOffsets_mm(); void updatePcbImportOffsets_mm();
double getPCBdefaultLineWidthMM(); double getDXFDefaultLineWidthMM();
void showPCBdefaultLineWidth(); void showDXFDefaultLineWidth();
void showPcbImportOffsets(); void showPcbImportOffsets();
PCB_BASE_FRAME* m_parent; PCB_BASE_FRAME* m_parent;
@ -104,9 +105,9 @@ private:
static bool m_shouldGroupItems; static bool m_shouldGroupItems;
static bool m_placementInteractive; static bool m_placementInteractive;
static LAYER_NUM m_layer; static LAYER_NUM m_layer;
double m_lineWidth; // always in mm: line width when a line width double m_dxfLineWidth; // always in mm: line width when a line width
// is not specified // is not specified
static int m_lineWidthUnits; static int m_dxfLineWidthUnits;
static double m_scaleImport; // a scale factor to change the size of imported static double m_scaleImport; // a scale factor to change the size of imported
// items m_scaleImport =1.0 means keep original size // items m_scaleImport =1.0 means keep original size
static int m_dxfUnits; static int m_dxfUnits;

View File

@ -88,9 +88,11 @@ bool SVG_IMPORT_PLUGIN::Import()
m_internalImporter.NewShape( rule ); m_internalImporter.NewShape( rule );
for( NSVGpath* path = shape->paths; path != nullptr; path = path->next ) for( NSVGpath* path = shape->paths; path != nullptr; path = path->next )
{
DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR, DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR,
lineWidth ); lineWidth );
} }
}
m_internalImporter.PostprocessNestedPolygons(); m_internalImporter.PostprocessNestedPolygons();
wxCHECK( m_importer, false ); wxCHECK( m_importer, false );

View File

@ -364,10 +364,10 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
&m_ImportGraphics.interactive_placement, true ) ); &m_ImportGraphics.interactive_placement, true ) );
m_params.emplace_back( new PARAM<int>( "import_graphics.line_width_units", m_params.emplace_back( new PARAM<int>( "import_graphics.line_width_units",
&m_ImportGraphics.line_width_units, 0 ) ); &m_ImportGraphics.dxf_line_width_units, 0 ) );
m_params.emplace_back( new PARAM<double>( "import_graphics.line_width", m_params.emplace_back( new PARAM<double>( "import_graphics.line_width",
&m_ImportGraphics.line_width, 0.2 ) ); &m_ImportGraphics.dxf_line_width, 0.2 ) );
m_params.emplace_back( new PARAM<int>( "import_graphics.origin_units", m_params.emplace_back( new PARAM<int>( "import_graphics.origin_units",
&m_ImportGraphics.origin_units, 0 ) ); &m_ImportGraphics.origin_units, 0 ) );

View File

@ -153,8 +153,8 @@ public:
int layer; int layer;
bool interactive_placement; bool interactive_placement;
wxString last_file; wxString last_file;
double line_width; double dxf_line_width;
int line_width_units; int dxf_line_width_units;
int origin_units; int origin_units;
double origin_x; double origin_x;
double origin_y; double origin_y;