2018-10-13 18:37:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2020-11-23 11:44:46 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-13 18:37:28 +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
|
|
|
|
*/
|
|
|
|
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2019-09-06 18:57:04 +00:00
|
|
|
|
2018-12-12 12:26:03 +00:00
|
|
|
#include "dialog_import_gfx.h"
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2018-11-05 16:04:05 +00:00
|
|
|
#include <pcb_layer_box_selector.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-23 11:44:46 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-22 03:11:24 +00:00
|
|
|
#include <map>
|
|
|
|
#include "dxf_import_plugin.h"
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2021-06-06 12:41:16 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
// Static members of DIALOG_IMPORT_GFX, to remember the user's choices during the session
|
2018-10-13 18:37:28 +00:00
|
|
|
wxString DIALOG_IMPORT_GFX::m_filename;
|
2018-11-05 16:04:05 +00:00
|
|
|
bool DIALOG_IMPORT_GFX::m_placementInteractive = true;
|
2020-08-20 00:22:48 +00:00
|
|
|
bool DIALOG_IMPORT_GFX::m_shouldGroupItems = true;
|
2021-07-21 23:14:56 +00:00
|
|
|
int DIALOG_IMPORT_GFX::m_layer = Dwgs_User;
|
2019-04-03 13:57:31 +00:00
|
|
|
double DIALOG_IMPORT_GFX::m_scaleImport = 1.0; // Do not change the imported items size
|
|
|
|
int DIALOG_IMPORT_GFX::m_originUnits = 0; // millimeter
|
2022-07-18 16:49:50 +00:00
|
|
|
int DIALOG_IMPORT_GFX::m_dxfLineWidthUnits = 0; // millimeter
|
2020-11-23 11:44:46 +00:00
|
|
|
int DIALOG_IMPORT_GFX::m_dxfUnits = 0; // first entry in the dxfUnits map below
|
2020-11-22 03:11:24 +00:00
|
|
|
|
|
|
|
const std::map<DXF_IMPORT_UNITS, wxString> dxfUnitsMap = {
|
|
|
|
{ DXF_IMPORT_UNITS::INCHES, _( "Inches" ) },
|
|
|
|
{ DXF_IMPORT_UNITS::MILLIMETERS, _( "Millimeters" ) },
|
|
|
|
{ DXF_IMPORT_UNITS::MILS, _( "Mils" ) },
|
|
|
|
{ DXF_IMPORT_UNITS::CENTIMETERS, _( "Centimeter" ) },
|
|
|
|
{ DXF_IMPORT_UNITS::FEET, _( "Feet" ) },
|
|
|
|
};
|
2019-04-03 13:57:31 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aImportAsFootprintGraphic )
|
2018-10-13 18:37:28 +00:00
|
|
|
: DIALOG_IMPORT_GFX_BASE( aParent )
|
|
|
|
{
|
|
|
|
m_parent = aParent;
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
if( aImportAsFootprintGraphic )
|
2020-11-13 01:33:30 +00:00
|
|
|
m_importer = std::make_unique<GRAPHICS_IMPORTER_FOOTPRINT>( m_parent->GetBoard()->GetFirstFootprint() );
|
2018-10-13 18:37:28 +00:00
|
|
|
else
|
2019-12-05 13:43:55 +00:00
|
|
|
m_importer = std::make_unique<GRAPHICS_IMPORTER_BOARD>( m_parent->GetBoard() );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-12-12 12:26:03 +00:00
|
|
|
// construct an import manager with options from config
|
|
|
|
{
|
|
|
|
GRAPHICS_IMPORT_MGR::TYPE_LIST blacklist;
|
2019-03-11 17:30:59 +00:00
|
|
|
// Currently: all types are allowed, so the blacklist is empty
|
|
|
|
// (no GFX_FILE_T in the blacklist)
|
2019-03-11 18:25:52 +00:00
|
|
|
// To disable SVG import, enable these 2 lines
|
|
|
|
// if( !ADVANCED_CFG::GetCfg().m_enableSvgImport )
|
|
|
|
// blacklist.push_back( GRAPHICS_IMPORT_MGR::SVG );
|
2019-07-16 01:31:07 +00:00
|
|
|
// The SVG import has currently a flaw: all SVG shapes are imported as curves and
|
|
|
|
// converted to a lot of segments. A better approach is to convert to polylines
|
|
|
|
// (not yet existing in Pcbnew) and keep arcs and circles as primitives (not yet
|
|
|
|
// possible with tinysvg library).
|
2019-03-11 18:25:52 +00:00
|
|
|
|
2018-12-12 12:26:03 +00:00
|
|
|
m_gfxImportMgr = std::make_unique<GRAPHICS_IMPORT_MGR>( blacklist );
|
|
|
|
}
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
m_originUnits = 0;
|
|
|
|
m_origin.x = 0.0; // always in mm
|
|
|
|
m_origin.y = 0.0; // always in mm
|
2022-07-18 16:49:50 +00:00
|
|
|
m_dxfLineWidth = 0.2; // always in mm
|
|
|
|
m_dxfLineWidthUnits = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_layer = cfg->m_ImportGraphics.layer;
|
|
|
|
m_placementInteractive = cfg->m_ImportGraphics.interactive_placement;
|
|
|
|
m_filename = cfg->m_ImportGraphics.last_file;
|
2022-07-18 16:49:50 +00:00
|
|
|
m_dxfLineWidth = cfg->m_ImportGraphics.dxf_line_width;
|
|
|
|
m_dxfLineWidthUnits = cfg->m_ImportGraphics.dxf_line_width_units;
|
2020-01-13 01:44:19 +00:00
|
|
|
m_originUnits = cfg->m_ImportGraphics.origin_units;
|
|
|
|
m_origin.x = cfg->m_ImportGraphics.origin_x;
|
|
|
|
m_origin.y = cfg->m_ImportGraphics.origin_y;
|
2020-11-22 03:11:24 +00:00
|
|
|
m_dxfUnits = cfg->m_ImportGraphics.dxf_units;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
m_choiceUnitLineWidth->SetSelection( m_dxfLineWidthUnits );
|
|
|
|
showDXFDefaultLineWidth();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
m_DxfPcbPositionUnits->SetSelection( m_originUnits );
|
2018-11-05 16:04:05 +00:00
|
|
|
showPcbImportOffsets();
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
m_textCtrlFileName->SetValue( m_filename );
|
2018-11-05 16:04:05 +00:00
|
|
|
m_rbInteractivePlacement->SetValue( m_placementInteractive );
|
|
|
|
m_rbAbsolutePlacement->SetValue( not m_placementInteractive );
|
2020-08-20 00:22:48 +00:00
|
|
|
m_groupItems->SetValue( m_shouldGroupItems );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
m_textCtrlImportScale->SetValue( wxString::Format( wxT( "%f" ), m_scaleImport ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
// Configure the layers list selector
|
2019-04-03 13:57:31 +00:00
|
|
|
m_SelLayerBox->SetLayersHotkeys( false ); // Do not display hotkeys
|
2018-10-13 18:37:28 +00:00
|
|
|
m_SelLayerBox->SetBoardFrame( m_parent );
|
|
|
|
m_SelLayerBox->Resync();
|
|
|
|
|
|
|
|
if( m_SelLayerBox->SetLayerSelection( m_layer ) < 0 )
|
|
|
|
{
|
|
|
|
m_layer = Dwgs_User;
|
|
|
|
m_SelLayerBox->SetLayerSelection( m_layer );
|
|
|
|
}
|
|
|
|
|
2020-11-22 03:11:24 +00:00
|
|
|
for( auto& unitEntry : dxfUnitsMap )
|
|
|
|
m_choiceDxfUnits->Append( unitEntry.second );
|
|
|
|
|
2020-11-22 20:44:36 +00:00
|
|
|
m_choiceDxfUnits->SetSelection( m_dxfUnits );
|
2020-11-22 03:11:24 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
2020-11-23 11:44:46 +00:00
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
onFilename( dummy );
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
SetInitialFocus( m_textCtrlFileName );
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
2022-07-18 16:49:50 +00:00
|
|
|
|
|
|
|
m_textCtrlFileName->Connect( wxEVT_COMMAND_TEXT_UPDATED,
|
|
|
|
wxCommandEventHandler( DIALOG_IMPORT_GFX::onFilename ),
|
|
|
|
NULL, this );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_IMPORT_GFX::~DIALOG_IMPORT_GFX()
|
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
cfg->m_ImportGraphics.layer = m_layer;
|
|
|
|
cfg->m_ImportGraphics.interactive_placement = m_placementInteractive;
|
|
|
|
cfg->m_ImportGraphics.last_file = m_filename;
|
2022-07-18 16:49:50 +00:00
|
|
|
cfg->m_ImportGraphics.dxf_line_width = m_dxfLineWidth;
|
|
|
|
cfg->m_ImportGraphics.dxf_line_width_units = m_dxfLineWidthUnits;
|
2020-01-13 01:44:19 +00:00
|
|
|
cfg->m_ImportGraphics.origin_units = m_originUnits;
|
|
|
|
cfg->m_ImportGraphics.origin_x = m_origin.x;
|
|
|
|
cfg->m_ImportGraphics.origin_y = m_origin.y;
|
2020-11-22 03:11:24 +00:00
|
|
|
cfg->m_ImportGraphics.dxf_units = m_dxfUnits;
|
2022-07-18 16:49:50 +00:00
|
|
|
|
|
|
|
m_textCtrlFileName->Disconnect( wxEVT_COMMAND_TEXT_UPDATED,
|
|
|
|
wxCommandEventHandler( DIALOG_IMPORT_GFX::onFilename ),
|
|
|
|
NULL, this );
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
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 )
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
|
|
|
// Collect last entered values:
|
|
|
|
updatePcbImportOffsets_mm();
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
m_originUnits = m_DxfPcbPositionUnits->GetSelection();;
|
2018-11-05 16:04:05 +00:00
|
|
|
showPcbImportOffsets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
double DIALOG_IMPORT_GFX::getDXFDefaultLineWidthMM()
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
double value = DoubleValueFromString( EDA_UNITS::UNSCALED, m_textCtrlLineWidth->GetValue() );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
switch( m_dxfLineWidthUnits )
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
default:
|
2019-07-16 01:31:07 +00:00
|
|
|
case 0: break; // display units = mm
|
|
|
|
case 1: value *= 25.4 / 1000; break; // display units = mil
|
|
|
|
case 2: value *= 25.4; break; // display units = inch
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return value; // value is in mm
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_IMPORT_GFX::onUnitWidthSelection( wxCommandEvent& event )
|
|
|
|
{
|
2022-07-18 16:49:50 +00:00
|
|
|
m_dxfLineWidth = getDXFDefaultLineWidthMM();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
|
|
|
// Switch to new units
|
2022-07-18 16:49:50 +00:00
|
|
|
m_dxfLineWidthUnits = m_choiceUnitLineWidth->GetSelection();
|
|
|
|
showDXFDefaultLineWidth();
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_IMPORT_GFX::showPcbImportOffsets()
|
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
// Display m_origin value according to the unit selection:
|
|
|
|
VECTOR2D offset = m_origin;
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
if( m_originUnits ) // Units are inches
|
|
|
|
offset = m_origin / 25.4;
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
m_DxfPcbXCoord->SetValue( wxString::Format( wxT( "%f" ), offset.x ) );
|
|
|
|
m_DxfPcbYCoord->SetValue( wxString::Format( wxT( "%f" ), offset.y ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
void DIALOG_IMPORT_GFX::showDXFDefaultLineWidth()
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
|
|
|
double value;
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
switch( m_dxfLineWidthUnits )
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
default:
|
2022-07-18 16:49:50 +00:00
|
|
|
case 0: value = m_dxfLineWidth; break; // display units = mm
|
|
|
|
case 1: value = m_dxfLineWidth / 25.4 * 1000; break; // display units = mil
|
|
|
|
case 2: value = m_dxfLineWidth / 25.4; break; // display units = inch
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
m_textCtrlLineWidth->SetValue( wxString::Format( wxT( "%f" ), value ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
void DIALOG_IMPORT_GFX::onBrowseFiles( wxCommandEvent& event )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
wxString filename;
|
|
|
|
|
|
|
|
if( !m_filename.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_filename );
|
|
|
|
path = fn.GetPath();
|
|
|
|
filename = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the list of handled file formats
|
|
|
|
wxString wildcardsDesc;
|
|
|
|
wxString allWildcards;
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
for( GRAPHICS_IMPORT_MGR::GFX_FILE_T pluginType : m_gfxImportMgr->GetImportableFileTypes() )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2022-07-18 16:49:50 +00:00
|
|
|
std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin = m_gfxImportMgr->GetPlugin( pluginType );
|
|
|
|
const std::vector<std::string> extensions = plugin->GetFileExtensions();
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
wildcardsDesc += wxT( "|" ) + plugin->GetName() + AddFileExtListToFilter( extensions );
|
|
|
|
allWildcards += plugin->GetWildcards() + wxT( ";" );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
wildcardsDesc = _( "All supported formats|" ) + allWildcards + wildcardsDesc;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2019-07-16 01:31:07 +00:00
|
|
|
wxFileDialog dlg( m_parent, _( "Open File" ), path, filename, wildcardsDesc,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString fileName = dlg.GetPath();
|
|
|
|
|
|
|
|
if( fileName.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_filename = fileName;
|
|
|
|
m_textCtrlFileName->SetValue( fileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
bool DIALOG_IMPORT_GFX::TransferDataFromWindow()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
m_filename = m_textCtrlFileName->GetValue();
|
|
|
|
|
|
|
|
if( m_filename.IsEmpty() )
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
wxMessageBox( _( "No file selected!" ) );
|
|
|
|
return false;
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
m_originUnits = m_DxfPcbPositionUnits->GetSelection();
|
|
|
|
updatePcbImportOffsets_mm(); // Update m_originX and m_originY;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
m_layer = m_SelLayerBox->GetLayerSelection();
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
if( m_layer < 0 )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
wxMessageBox( _( "Please select a valid layer." ) );
|
|
|
|
return false;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
m_dxfLineWidthUnits = m_choiceUnitLineWidth->GetSelection();
|
|
|
|
m_dxfLineWidth = getDXFDefaultLineWidthMM();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-11-22 03:11:24 +00:00
|
|
|
m_dxfUnits = m_choiceDxfUnits->GetSelection();
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
m_importer->SetLayer( PCB_LAYER_ID( m_layer ) );
|
2018-12-12 12:26:03 +00:00
|
|
|
|
2022-07-18 16:49:50 +00:00
|
|
|
if( auto plugin = m_gfxImportMgr->GetPluginByExt( wxFileName( m_filename ).GetExt() ) )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-11-22 03:11:24 +00:00
|
|
|
DXF_IMPORT_PLUGIN* dxfPlugin = dynamic_cast<DXF_IMPORT_PLUGIN*>( plugin.get() );
|
2022-07-18 16:49:50 +00:00
|
|
|
|
|
|
|
if( dxfPlugin )
|
2020-11-22 03:11:24 +00:00
|
|
|
{
|
|
|
|
auto it = dxfUnitsMap.begin();
|
|
|
|
std::advance( it, m_dxfUnits );
|
|
|
|
|
|
|
|
if( it == dxfUnitsMap.end() )
|
|
|
|
dxfPlugin->SetUnit( DXF_IMPORT_UNITS::DEFAULT );
|
|
|
|
else
|
|
|
|
dxfPlugin->SetUnit( it->first );
|
2022-07-18 16:49:50 +00:00
|
|
|
|
|
|
|
m_importer->SetLineWidthMM( m_dxfLineWidth );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_importer->SetLineWidthMM( 0.0 );
|
2020-11-22 03:11:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
// Set coordinates offset for import (offset is given in mm)
|
2019-04-03 13:57:31 +00:00
|
|
|
m_importer->SetImportOffsetMM( m_origin );
|
2021-03-20 12:16:59 +00:00
|
|
|
m_scaleImport = DoubleValueFromString( EDA_UNITS::UNSCALED,
|
|
|
|
m_textCtrlImportScale->GetValue() );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
m_importer->SetPlugin( std::move( plugin ) );
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
LOCALE_IO dummy; // Ensure floats can be read.
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
if( m_importer->Load( m_filename ) )
|
2018-11-05 16:04:05 +00:00
|
|
|
m_importer->Import( m_scaleImport );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
// Get warning messages:
|
2019-09-06 18:57:04 +00:00
|
|
|
wxString warnings = m_importer->GetMessages();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2019-04-03 13:57:31 +00:00
|
|
|
// This isn't a fatal error so allow the dialog to close with wxID_OK.
|
2018-11-05 16:04:05 +00:00
|
|
|
if( !warnings.empty() )
|
2019-09-06 18:57:04 +00:00
|
|
|
{
|
|
|
|
HTML_MESSAGE_BOX dlg( this, _( "Warning" ) );
|
|
|
|
dlg.MessageSet( _( "Items in the imported file could not be handled properly." ) );
|
2022-02-05 13:25:43 +00:00
|
|
|
warnings.Replace( wxT( "\n" ), wxT( "<br/>" ) );
|
2019-09-06 18:57:04 +00:00
|
|
|
dlg.AddHTML_Text( warnings );
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-03 13:57:31 +00:00
|
|
|
wxMessageBox( _( "There is no plugin to handle this file type." ) );
|
|
|
|
return false;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
2019-04-03 13:57:31 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_IMPORT_GFX::originOptionOnUpdateUI( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
if( m_rbInteractivePlacement->GetValue() != m_placementInteractive )
|
|
|
|
m_rbInteractivePlacement->SetValue( m_placementInteractive );
|
|
|
|
|
|
|
|
if( m_rbAbsolutePlacement->GetValue() == m_placementInteractive )
|
|
|
|
m_rbAbsolutePlacement->SetValue( not m_placementInteractive );
|
|
|
|
|
|
|
|
m_DxfPcbPositionUnits->Enable( not m_placementInteractive );
|
|
|
|
m_DxfPcbXCoord->Enable( not m_placementInteractive );
|
|
|
|
m_DxfPcbYCoord->Enable( not m_placementInteractive );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_IMPORT_GFX::updatePcbImportOffsets_mm()
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
m_origin.x = DoubleValueFromString( EDA_UNITS::UNSCALED, m_DxfPcbXCoord->GetValue() );
|
|
|
|
m_origin.y = DoubleValueFromString( EDA_UNITS::UNSCALED, m_DxfPcbYCoord->GetValue() );
|
2019-04-03 13:57:31 +00:00
|
|
|
|
|
|
|
if( m_originUnits ) // Units are inches
|
|
|
|
m_origin = m_origin * 25.4;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
|