38#include <wx/filedlg.h>
52 bool aAllowGrouping ) :
70 [
this]( wxCommandEvent& aEvent )
97 GetSizer()->Fit(
this );
98 GetSizer()->SetSizeHints(
this );
111 DIALOG_SHIM::TransferDataToWindow();
128 wxCommandEvent
dummy;
139 bool enableDXFControls =
true;
142 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
166 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( wxFileName(
path ).GetExt() );
177 if( !plugin->Load(
path ) )
180 const VECTOR2D size( plugin->GetImageWidth(), plugin->GetImageHeight() );
183 if( std::isfinite( size.
x ) && std::isfinite( size.
y ) && size.
x > 0 && size.
y > 0 )
241 if( aFromWidth && width > 0 )
243 else if( !aFromWidth && height > 0 )
259 if(
locked && aFromWidth )
306 bool isImage =
false;
308 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
317 GetSizer()->Fit(
this );
353 if( !filename.IsEmpty() )
355 wxFileName fn( filename );
357 filename = fn.GetFullName();
361 wxString wildcardsDesc;
362 wxString allWildcards;
366 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPlugin( pluginType );
367 const std::vector<std::string>
extensions = plugin->GetFileExtensions();
370 allWildcards += plugin->GetWildcards() + wxT(
";" );
373 wildcardsDesc =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcards + wildcardsDesc;
375 wxFileDialog dlg(
m_parent,
_(
"Import Graphics" ),
path, filename, wildcardsDesc,
376 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
380 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
387 if( !wxDialog::TransferDataFromWindow() )
392 wxMessageBox(
_(
"No file selected!" ) );
401 wxMessageBox(
_(
"Import scale must be a positive number." ) );
410 if( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> plugin =
m_gfxImportMgr->GetPluginByExt( ext ) )
430 {
m_parent->GetIuScale().IUTomm( origin.
x ),
m_parent->GetIuScale().IUTomm( origin.
y ) } );
438 wxString warnings =
m_importer->GetMessages();
441 if( !warnings.empty() )
444 dlg.
MessageSet(
_(
"Items in the imported file could not be handled properly." ) );
445 warnings.Replace( wxT(
"\n" ), wxT(
"<br/>" ) );
454 wxMessageBox(
_(
"There is no plugin to handle this file type." ) );
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.
wxStaticBitmap * m_previewBitmap
wxStaticText * m_importWidthLabel
wxCheckBox * m_aspectRatioCheckbox
wxCheckBox * m_cbGroupItems
wxRadioButton * m_rbInteractivePlacement
wxSlider * m_thresholdSlider
wxStaticText * m_importWidthUnits
wxCheckBox * m_cbInvertColors
wxTextCtrl * m_importWidthCtrl
wxTextCtrl * m_textCtrlFileName
wxTextCtrl * m_lineWidthCtrl
wxStaticText * m_importHeightUnits
DIALOG_IMPORT_GFX_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_importHeightCtrl
wxStaticText * m_lineWidthLabel
wxTextCtrl * m_importScaleCtrl
wxStaticText * m_importHeightLabel
wxChoice * m_choiceDxfUnits
wxRadioButton * m_rbAbsolutePlacement
wxStaticText * m_staticTextLineWidth1
wxStaticText * m_lineWidthUnits
STD_BITMAP_BUTTON * m_browseButton
wxString m_filenameOverride
DIALOG_IMPORT_GFX(EDA_DRAW_FRAME *aParent, std::unique_ptr< GRAPHICS_IMPORTER > aImporter, bool aAllowGrouping)
void sizeFromScale()
Write the scale into the size fields.
bool TransferDataFromWindow() override
void originOptionOnUpdateUI(wxUpdateUIEvent &event) override
UNIT_BINDER m_importWidth
void scaleFromSize(bool aFromWidth)
Work the scale out from a size the user typed.
void updateSizeControls()
Offer the size fields only when the source has a size to scale.
void updateImageControls()
Show the image controls only when the chosen file is a raster image.
void onFilenameChanged(wxCommandEvent &event) override
void loadSourceFile()
Read the chosen file, which is where the preview and the source size come from.
EDA_DRAW_FRAME * m_parent
void onLockAspectChanged(wxCommandEvent &event) override
VECTOR2D m_sourceSizeMM
Size of the source file's contents in mm, (0,0) when it has none to report.
std::unique_ptr< GRAPHICS_IMPORT_MGR > m_gfxImportMgr
bool TransferDataToWindow() override
static bool m_placementInteractive
UNIT_BINDER m_defaultLineWidth
void onInvertChanged(wxCommandEvent &event) override
void onThresholdChanged(wxScrollEvent &event) override
void onScaleChanged(wxCommandEvent &event) override
void onBrowseFiles(wxCommandEvent &event) override
wxString m_sourcePath
The file the source size and the preview were taken from.
std::unique_ptr< GRAPHICS_IMPORTER > m_importer
UNIT_BINDER m_importHeight
void onWidthChanged(wxCommandEvent &event) override
void onHeightChanged(wxCommandEvent &event) override
void SetFilenameOverride(const wxString &aFilenameOverride)
Set the filename override to be applied in TransferDataToWindow.
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={})
The base class for create windows for drawing purpose.
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.
wxArrayString GetDxfImportUnitChoices()
DXF_IMPORT_UNITS DxfImportUnitFromChoice(int aSelection)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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
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.