KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_convert_image_to_outlines.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/button.h>
23#include <wx/checkbox.h>
24#include <wx/choice.h>
25#include <wx/sizer.h>
26#include <wx/slider.h>
27#include <wx/stattext.h>
28
29
30DIALOG_CONVERT_IMAGE_TO_OUTLINES::DIALOG_CONVERT_IMAGE_TO_OUTLINES( wxWindow* aParent, const wxArrayString& aLayerNames,
31 int aSelectedLayer,
32 std::function<void( double, bool )> aOnChange ) :
33 DIALOG_SHIM( aParent, wxID_ANY, _( "Convert to Outlines" ) ),
34 m_threshold( nullptr ),
35 m_invert( nullptr ),
36 m_layer( nullptr ),
37 m_onChange( std::move( aOnChange ) )
38{
39 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
40
41 wxStaticText* thresholdLabel = new wxStaticText( this, wxID_ANY, _( "Black / white threshold:" ) );
42 mainSizer->Add( thresholdLabel, 0, wxTOP | wxRIGHT | wxLEFT, 5 );
43
45 new wxSlider( this, wxID_ANY, 50, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
46 m_threshold->SetMinSize( wxSize( FromDIP( 360 ), -1 ) );
47 mainSizer->Add( m_threshold, 0, wxEXPAND | wxRIGHT | wxLEFT, 5 );
48
49 m_invert = new wxCheckBox( this, wxID_ANY, _( "Invert Colors" ) );
50 mainSizer->Add( m_invert, 0, wxALL, 5 );
51
52 if( !aLayerNames.IsEmpty() )
53 {
54 wxBoxSizer* layerSizer = new wxBoxSizer( wxHORIZONTAL );
55
56 wxStaticText* layerLabel = new wxStaticText( this, wxID_ANY, _( "Layer:" ) );
57 layerSizer->Add( layerLabel, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
58
59 m_layer = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, aLayerNames );
60 m_layer->SetSelection( aSelectedLayer );
61
62 // A remembered index would be a different layer on a board with another layer set.
63 OptOut( m_layer );
64
65 layerSizer->Add( m_layer, 1, wxALIGN_CENTER_VERTICAL, 5 );
66
67 mainSizer->Add( layerSizer, 0, wxEXPAND | wxALL, 5 );
68 }
69
70 wxStdDialogButtonSizer* buttonSizer = new wxStdDialogButtonSizer();
71 buttonSizer->AddButton( new wxButton( this, wxID_OK ) );
72 buttonSizer->AddButton( new wxButton( this, wxID_CANCEL ) );
73 buttonSizer->Realize();
74
75 mainSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, 5 );
76
77 m_hash_key = "DIALOG_CONVERT_IMAGE_TO_OUTLINES";
78
79 SetSizer( mainSizer );
81 Layout();
82
83 m_threshold->Bind( wxEVT_SCROLL_CHANGED, &DIALOG_CONVERT_IMAGE_TO_OUTLINES::onThresholdScrolled, this );
84 m_threshold->Bind( wxEVT_SCROLL_THUMBTRACK, &DIALOG_CONVERT_IMAGE_TO_OUTLINES::onThresholdScrolled, this );
86
88}
89
90
92{
93 return (double) m_threshold->GetValue() / m_threshold->GetMax();
94}
95
96
98{
99 return m_invert->IsChecked();
100}
101
102
104{
105 return m_layer ? m_layer->GetSelection() : -1;
106}
107
108
110{
111 if( m_onChange )
113}
114
115
117{
118 if( m_onChange )
120}
double GetThreshold() const
Brightness cut deciding which pixels are traced, from 0 to 1.
int GetLayerSelection() const
Index into the layer names given to the constructor, or -1 when there were none.
DIALOG_CONVERT_IMAGE_TO_OUTLINES(wxWindow *aParent, const wxArrayString &aLayerNames, int aSelectedLayer, std::function< void(double, bool)> aOnChange)
std::function< void(double, bool)> m_onChange
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
#define _(s)
STL namespace.