38#include <wx/filedlg.h>
60 const LSET& aPermittedLayers )
62 std::vector<INPUT_LAYER_DESC> layerDescriptions;
64 for(
const wxString& sourceLayer : aSourceLayers )
67 desc.
Name = sourceLayer;
72 layerDescriptions.push_back( desc );
75 return layerDescriptions;
121 [
this]( wxCommandEvent& aEvent )
125 wxCommandEvent
dummy;
132 wxCommandEvent
dummy;
138 GetSizer()->Fit(
this );
139 GetSizer()->SetSizeHints(
this );
152 DIALOG_SHIM::TransferDataToWindow();
169 wxCommandEvent
dummy;
180 bool enableDXFControls =
true;
183 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
212 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( wxFileName(
path ).GetExt() );
223 if( !plugin->Load(
path ) )
226 const VECTOR2D size( plugin->GetImageWidth(), plugin->GetImageHeight() );
229 if( std::isfinite( size.
x ) && std::isfinite( size.
y ) && size.
x > 0 && size.
y > 0 )
287 if( aFromWidth && width > 0 )
289 else if( !aFromWidth && height > 0 )
305 if(
locked && aFromWidth )
352 bool isImage =
false;
354 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
363 GetSizer()->Fit(
this );
399 if( !filename.IsEmpty() )
401 wxFileName fn( filename );
403 filename = fn.GetFullName();
407 wxString wildcardsDesc;
408 wxString allWildcards;
412 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPlugin( pluginType );
413 const std::vector<std::string>
extensions = plugin->GetFileExtensions();
416 allWildcards += plugin->GetWildcards() + wxT(
";" );
419 wildcardsDesc =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcards + wildcardsDesc;
421 wxFileDialog dlg(
m_parent,
_(
"Import Graphics" ),
path, filename, wildcardsDesc,
422 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
426 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
433 if( !wxDialog::TransferDataFromWindow() )
438 wxMessageBox(
_(
"Please select a file to import." ) );
445 if( useSingleLayer &&
m_SelLayerBox->GetLayerSelection() < 0 )
447 wxMessageBox(
_(
"Please select a valid layer." ) );
457 wxMessageBox(
_(
"Import scale must be a positive number." ) );
475 case 1: origin +=
m_parent->GetAuxOrigin();
break;
476 case 2: origin +=
m_parent->GetGridOrigin();
break;
477 case 3: origin +=
m_parent->GetUserOrigin();
break;
480 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
514 if( useDxfLayerMapping && dxfPlugin )
518 if( !sourceLayers.empty() )
524 if( layerMap.empty() )
535 wxString warnings =
m_importer->GetMessages();
538 if( !warnings.empty() )
541 dlg.
MessageSet(
_(
"Items in the imported file could not be handled properly." ) );
542 warnings.Replace( wxT(
"\n" ), wxT(
"<br/>" ) );
551 wxMessageBox(
_(
"There is no plugin to handle this file type." ) );
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
wxImage MakeBilevelPreview(const wxImage &aImage, double aThreshold, bool aInvert, const wxSize &aRoom)
Produce the black and white view of an image, shrunk to fit a preview area.
Import a raster image by tracing its dark areas into filled polygons.
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
wxStaticBitmap * m_previewBitmap
wxTextCtrl * m_lineWidthCtrl
wxTextCtrl * m_importHeightCtrl
wxStaticText * m_dxfUnitsLabel
wxCheckBox * m_aspectRatioCheckbox
wxStaticText * m_importHeightUnits
wxStaticText * m_importWidthUnits
wxTextCtrl * m_importWidthCtrl
wxStaticText * m_lineWidthLabel
wxChoice * m_dxfUnitsChoice
wxStaticText * m_toleranceUnits
wxCheckBox * m_placeAtCheckbox
wxCheckBox * m_rbFixDiscontinuities
wxStaticText * m_lineWidthUnits
PCB_LAYER_BOX_SELECTOR * m_SelLayerBox
wxStaticText * m_importWidthLabel
wxStaticText * m_toleranceLabel
wxRadioButton * m_radioBtnSingleLayer
DIALOG_IMPORT_GRAPHICS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Import Graphics File"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxTextCtrl * m_toleranceCtrl
wxStaticText * m_originLabel
wxStaticText * m_importHeightLabel
wxTextCtrl * m_importScaleCtrl
wxTextCtrl * m_textCtrlFileName
wxSlider * m_thresholdSlider
STD_BITMAP_BUTTON * m_browseButton
wxCheckBox * m_cbInvertColors
wxRadioButton * m_radioBtnMapLayers
void onHeightChanged(wxCommandEvent &event) override
std::unique_ptr< GRAPHICS_IMPORT_MGR > m_gfxImportMgr
void updateImageControls()
Show the image controls only when the chosen file is a raster image.
std::unique_ptr< GRAPHICS_IMPORTER_PCBNEW > m_importer
PCB_BASE_FRAME * m_parent
UNIT_BINDER m_importWidth
void onInvertChanged(wxCommandEvent &event) override
void onLockAspectChanged(wxCommandEvent &event) override
bool TransferDataFromWindow() override
void onThresholdChanged(wxScrollEvent &event) override
bool TransferDataToWindow() override
void updateSizeControls()
Offer the size fields only when the source has a size to scale.
void scaleFromSize(bool aFromWidth)
Work the scale out from a size the user typed.
void loadSourceFile()
Read the chosen file, which is where the preview and the source size come from.
UNIT_BINDER m_defaultLineWidth
wxString m_filenameOverride
void onBrowseFiles(wxCommandEvent &event) override
void onFilenameChanged(wxCommandEvent &event) override
UNIT_BINDER m_importHeight
wxString m_sourcePath
The file the source size and the preview were taken from.
void SetFilenameOverride(const wxString &aFilenameOverride)
Set the filename override to be applied in TransferDataToWindow.
void sizeFromScale()
Write the scale into the size fields.
void onWidthChanged(wxCommandEvent &event) override
void onScaleChanged(wxCommandEvent &event) override
VECTOR2D m_sourceSizeMM
Size of the source file's contents in mm, (0,0) when it has none to report.
void onUpdateUI(wxUpdateUIEvent &event) override
DIALOG_IMPORT_GRAPHICS(PCB_BASE_FRAME *aParent)
static std::map< wxString, PCB_LAYER_ID > RunModal(wxWindow *aParent, const std::vector< INPUT_LAYER_DESC > &aLayerDesc)
Create and show a dialog (modal) and returns the data from it after completion.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::vector< wxString > GetSourceLayers() const
void SetUnit(DXF_IMPORT_UNITS aUnit)
Set the default units when importing DXFs.
GFX_FILE_T
List of handled file types.
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
LSET is a set of PCB_LAYER_IDs.
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
static const LSET & AllLayersMask()
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
DISPLAY_OPTIONS m_Display
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
static LSET getPermittedImportLayers(PCB_BASE_FRAME *aFrame)
static PCB_LAYER_ID getAutoMappedLayer(const wxString &aSourceLayer, const LSET &aPermittedLayers)
static std::vector< INPUT_LAYER_DESC > buildDxfLayerDescriptions(const std::vector< wxString > &aSourceLayers, const LSET &aPermittedLayers)
wxArrayString GetDxfImportUnitChoices()
DXF_IMPORT_UNITS DxfImportUnitFromChoice(int aSelection)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
PCB_LAYER_ID
A quick note on layer IDs:
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
static const std::vector< std::string > extensions
std::vector< FAB_LAYER_COLOR > dummy
bool m_DisplayInvertYAxis
bool m_DisplayInvertXAxis
VECTOR2< double > VECTOR2D
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Definition of file extensions used in Kicad.