2014-10-21 14:36:45 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-21 14:36:45 -04: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
|
|
|
|
*/
|
|
|
|
|
2012-05-04 19:44:42 +02:00
|
|
|
/**
|
2012-12-18 08:54:44 -05:00
|
|
|
* @file dialog_select_one_pcb_layer.cpp
|
2012-05-04 19:44:42 +02:00
|
|
|
* @brief Set up a dialog to choose a PCB Layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gerbview_frame.h>
|
2025-01-08 15:46:29 -08:00
|
|
|
#include <layer_range.h>
|
|
|
|
#include <lset.h>
|
2025-06-06 11:15:07 +01:00
|
|
|
#include <dialogs/dialog_map_gerber_layers_to_pcb.h>
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-10-18 20:24:20 +02:00
|
|
|
#include <wx/radiobox.h>
|
|
|
|
|
2012-05-04 19:44:42 +02:00
|
|
|
|
|
|
|
enum layer_sel_id {
|
|
|
|
ID_LAYER_SELECT_TOP = 1800,
|
|
|
|
ID_LAYER_SELECT_BOTTOM,
|
|
|
|
ID_LAYER_SELECT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
class SELECT_LAYER_DIALOG : public DIALOG_SHIM
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-07-22 02:03:43 +00:00
|
|
|
SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
|
2021-07-21 17:37:49 -04:00
|
|
|
wxString aGerberName );
|
2012-05-04 19:44:42 +02:00
|
|
|
~SELECT_LAYER_DIALOG() { };
|
|
|
|
|
2021-07-21 17:37:49 -04:00
|
|
|
int GetSelectedLayer() { return m_selectedLayer; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
|
2012-05-04 19:44:42 +02:00
|
|
|
private:
|
|
|
|
void OnLayerSelected( wxCommandEvent& event );
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2021-07-21 17:37:49 -04:00
|
|
|
|
|
|
|
int m_selectedLayer;
|
|
|
|
wxRadioBox* m_layerRadioBox;
|
|
|
|
std::vector <int> m_layerId;
|
2012-05-04 19:44:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-28 14:08:38 -05:00
|
|
|
BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, DIALOG_SHIM )
|
2012-05-04 19:44:42 +02:00
|
|
|
EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2021-07-27 08:22:27 -04:00
|
|
|
int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
|
|
|
|
const wxString& aGerberName )
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
2020-07-22 02:03:43 +00:00
|
|
|
SELECT_LAYER_DIALOG* frame =
|
|
|
|
new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2021-07-21 17:37:49 -04:00
|
|
|
frame->ShowModal();
|
2012-05-04 19:44:42 +02:00
|
|
|
frame->Destroy();
|
2021-07-21 17:37:49 -04:00
|
|
|
return frame->GetSelectedLayer();
|
2012-05-04 19:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-21 17:37:49 -04:00
|
|
|
SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer,
|
|
|
|
int aCopperLayerCount, wxString aGerberName )
|
|
|
|
: DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
2014-07-14 20:59:41 +02:00
|
|
|
wxButton* button;
|
|
|
|
wxArrayString layerList;
|
2020-06-06 16:35:46 +01:00
|
|
|
int selected = -1;
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-07-11 09:40:46 +00:00
|
|
|
// Store the passed default layer in case the user hits Cancel
|
2021-07-21 17:37:49 -04:00
|
|
|
m_selectedLayer = aDefaultLayer;
|
2020-07-11 09:40:46 +00:00
|
|
|
|
2012-05-04 19:44:42 +02:00
|
|
|
// Build the layer list; first build copper layers list
|
2025-01-08 15:46:29 -08:00
|
|
|
LSET layers = LSET::AllCuMask( aCopperLayerCount ) | LSET::AllTechMask() | LSET::UserMask();
|
2014-06-27 19:07:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
for( auto copper_it = layers.copper_layers_begin(); copper_it != layers.copper_layers_end(); ++copper_it )
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
2025-01-08 15:46:29 -08:00
|
|
|
layerList.Add( LSET::Name( *copper_it ) );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
if( aDefaultLayer == *copper_it )
|
|
|
|
selected = m_layerId.size();
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
m_layerId.push_back( *copper_it );
|
2012-05-04 19:44:42 +02:00
|
|
|
}
|
2014-06-27 19:07:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
for( auto non_copper_it = layers.non_copper_layers_begin(); non_copper_it != layers.non_copper_layers_end(); ++non_copper_it )
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
2025-01-08 15:46:29 -08:00
|
|
|
layerList.Add( LSET::Name( *non_copper_it ) );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
if( aDefaultLayer == *non_copper_it )
|
|
|
|
selected = m_layerId.size();
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2025-01-08 15:46:29 -08:00
|
|
|
m_layerId.push_back( *non_copper_it );
|
2012-05-04 19:44:42 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
layerList.Add( _( "Hole data" ) );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
if( aDefaultLayer == UNDEFINED_LAYER )
|
2025-01-08 15:46:29 -08:00
|
|
|
selected = m_layerId.size();
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
m_layerId.push_back( UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
layerList.Add( _( "Do not export" ) );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
if( aDefaultLayer == UNSELECTED_LAYER )
|
2025-01-08 15:46:29 -08:00
|
|
|
selected = m_layerId.size();
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
m_layerId.push_back( UNSELECTED_LAYER );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2020-06-06 16:35:46 +01:00
|
|
|
m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
|
2025-01-08 15:46:29 -08:00
|
|
|
wxDefaultSize, layerList, std::min( int( m_layerId.size() ), 12 ),
|
2020-06-06 16:35:46 +01:00
|
|
|
wxRA_SPECIFY_ROWS );
|
|
|
|
|
|
|
|
if( selected >= 0 )
|
|
|
|
m_layerRadioBox->SetSelection( selected );
|
|
|
|
|
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( mainSizer );
|
|
|
|
mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
|
|
|
|
wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2014-07-14 20:59:41 +02:00
|
|
|
button = new wxButton( this, wxID_OK, _( "OK" ) );
|
|
|
|
button->SetDefault();
|
2020-06-06 16:35:46 +01:00
|
|
|
buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
|
2012-05-04 19:44:42 +02:00
|
|
|
|
2014-07-14 20:59:41 +02:00
|
|
|
button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
2020-06-06 16:35:46 +01:00
|
|
|
buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
// Hack to fix clipped radio buttons on OSX
|
|
|
|
wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
|
|
|
|
m_layerRadioBox->SetMinSize( size );
|
|
|
|
#endif
|
2012-05-04 19:44:42 +02:00
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-21 17:37:49 -04:00
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
2012-05-04 19:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-21 17:37:49 -04:00
|
|
|
bool SELECT_LAYER_DIALOG::TransferDataFromWindow()
|
2012-05-04 19:44:42 +02:00
|
|
|
{
|
2021-07-21 17:37:49 -04:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_selectedLayer = m_layerId[m_layerRadioBox->GetSelection()];
|
|
|
|
return true;
|
2012-05-04 19:44:42 +02:00
|
|
|
}
|