2011-04-23 19:01:41 +00:00
|
|
|
/**
|
2012-12-18 13:54:44 +00:00
|
|
|
* @file select_layers_to_pcb.cpp
|
2012-05-04 17:44:42 +00:00
|
|
|
* @brief Dialog to choose equivalence between gerber layers and pcb layers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-16 20:13:26 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-05-04 17:44:42 +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
|
2011-04-23 19:01:41 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
#include <X2_gerber_attributes.h>
|
2020-07-04 22:12:49 +00:00
|
|
|
#include <gerber_file_image.h>
|
|
|
|
#include <gerber_file_image_list.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview_id.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <gerbview_settings.h>
|
2020-07-04 22:12:49 +00:00
|
|
|
#include <kiface_i.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-08 22:59:16 +00:00
|
|
|
#include <dialogs/dialog_layers_select_to_pcb.h>
|
2011-04-23 19:01:41 +00:00
|
|
|
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
enum swap_layer_id {
|
2011-04-26 08:30:16 +00:00
|
|
|
ID_LAYERS_MAP_DIALOG = ID_GERBER_END_LIST,
|
2007-11-02 05:33:31 +00:00
|
|
|
ID_BUTTON_0,
|
2014-06-27 17:07:42 +00:00
|
|
|
ID_TEXT_0 = ID_BUTTON_0 + GERBER_DRAWLAYERS_COUNT
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2012-12-18 13:54:44 +00:00
|
|
|
|
|
|
|
int LAYERS_MAP_DIALOG::m_exportBoardCopperLayersCount = 2;
|
|
|
|
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
BEGIN_EVENT_TABLE( LAYERS_MAP_DIALOG, LAYERS_MAP_DIALOG_BASE )
|
2014-06-27 17:07:42 +00:00
|
|
|
EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + GERBER_DRAWLAYERS_COUNT-1,
|
2012-12-18 13:54:44 +00:00
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
LAYERS_MAP_DIALOG::OnSelectLayer )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
LAYERS_MAP_DIALOG::LAYERS_MAP_DIALOG( GERBVIEW_FRAME* parent ) :
|
|
|
|
LAYERS_MAP_DIALOG_BASE( parent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-11-02 05:33:31 +00:00
|
|
|
m_Parent = parent;
|
2011-04-24 18:26:42 +00:00
|
|
|
initDialog();
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2011-04-24 18:26:42 +00:00
|
|
|
// Resize the dialog
|
2011-04-26 11:07:37 +00:00
|
|
|
Layout();
|
2011-04-24 18:26:42 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::initDialog()
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
|
|
|
wxStaticText* label;
|
|
|
|
wxStaticText* text;
|
2011-04-26 08:30:16 +00:00
|
|
|
int item_ID;
|
2011-04-24 18:26:42 +00:00
|
|
|
wxString msg;
|
|
|
|
wxSize goodSize;
|
2020-07-24 22:22:38 +00:00
|
|
|
GERBVIEW_SETTINGS* config = static_cast<GERBVIEW_SETTINGS*>( Kiface().KifaceSettings() );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
|
|
|
// Specify the default value for each member of these arrays.
|
2020-07-04 01:21:24 +00:00
|
|
|
m_buttonTable[ii] = -1;
|
2013-03-31 13:27:46 +00:00
|
|
|
m_layersLookUpTable[ii] = UNSELECTED_LAYER;
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
// Ensure we have:
|
2020-07-04 01:21:24 +00:00
|
|
|
// At least 2 copper layers and less than max pcb copper layers count
|
|
|
|
// Even number of layers because a board *must* have even layers count
|
2011-04-26 08:30:16 +00:00
|
|
|
normalizeBrdLayersCount();
|
|
|
|
|
|
|
|
int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1;
|
|
|
|
m_comboCopperLayersCount->SetSelection( idx );
|
2011-04-23 19:01:41 +00:00
|
|
|
|
2020-07-04 01:21:24 +00:00
|
|
|
m_gerberActiveLayersCount = 0;
|
2016-06-17 18:00:29 +00:00
|
|
|
GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( images->GetGbrImage( ii ) == nullptr )
|
2014-06-27 17:07:42 +00:00
|
|
|
break;
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
m_buttonTable[m_gerberActiveLayersCount] = ii;
|
|
|
|
m_gerberActiveLayersCount++;
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 01:21:24 +00:00
|
|
|
if( m_gerberActiveLayersCount <= GERBER_DRAWLAYERS_COUNT / 2 ) // Only one list is enough
|
2011-04-23 19:01:41 +00:00
|
|
|
m_staticlineSep->Hide();
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
wxFlexGridSizer* flexColumnBoxSizer = m_flexLeftColumnBoxSizer;
|
2018-01-05 10:45:50 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
2011-04-23 19:01:41 +00:00
|
|
|
// Each Gerber layer has an associated static text string (to
|
|
|
|
// identify that layer), a button (for invoking a child dialog
|
2011-09-30 18:15:37 +00:00
|
|
|
// box to change which Pcbnew layer that the Gerber layer is
|
2011-04-23 19:01:41 +00:00
|
|
|
// mapped to), and a second static text string (to depict which
|
2011-09-30 18:15:37 +00:00
|
|
|
// Pcbnew layer that the Gerber layer has been mapped to). Each
|
2011-04-23 19:01:41 +00:00
|
|
|
// of those items are placed into the left hand column, middle
|
|
|
|
// column, and right hand column (respectively) of the Flexgrid
|
|
|
|
// sizer, and the color of the second text string is set to
|
|
|
|
// fuchsia or blue (to respectively indicate whether the Gerber
|
2011-09-30 18:15:37 +00:00
|
|
|
// layer has been mapped to a Pcbnew layer or is not being
|
2011-04-23 19:01:41 +00:00
|
|
|
// exported at all). (Experimentation has shown that if a text
|
2011-09-30 18:15:37 +00:00
|
|
|
// control is used to depict which Pcbnew layer that each Gerber
|
2011-04-23 19:01:41 +00:00
|
|
|
// layer is mapped to (instead of a static text string), then
|
|
|
|
// those controls do not behave in a fully satisfactory manner
|
|
|
|
// in the Linux version. Even when the read-only attribute is
|
|
|
|
// specified for all of those controls, they can still be selected
|
|
|
|
// when the arrow keys or Tab key is used to step through all of
|
|
|
|
// the controls within the dialog box, and directives to set the
|
|
|
|
// foreground color of the text of each such control to blue (to
|
|
|
|
// indicate that the text is of a read-only nature) are disregarded.
|
|
|
|
// Specify a FlexGrid sizer with an appropriate number of rows
|
|
|
|
// and three columns. If nb_items < 16, then the number of rows
|
|
|
|
// is nb_items; otherwise, the number of rows is 16 (with two
|
|
|
|
// separate columns of controls being used if nb_items > 16).
|
|
|
|
|
2020-07-04 01:21:24 +00:00
|
|
|
if( ii == GERBER_DRAWLAYERS_COUNT / 2 )
|
2011-04-23 19:01:41 +00:00
|
|
|
flexColumnBoxSizer = m_flexRightColumnBoxSizer;
|
2007-11-02 05:33:31 +00:00
|
|
|
|
|
|
|
// Provide a text string to identify the Gerber layer
|
2011-04-26 08:30:16 +00:00
|
|
|
msg.Printf( _( "Layer %d" ), m_buttonTable[ii] + 1 );
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2020-06-06 15:35:46 +00:00
|
|
|
label = new wxStaticText( this, wxID_STATIC, msg );
|
2018-01-05 10:45:50 +00:00
|
|
|
flexColumnBoxSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2020-07-04 01:21:24 +00:00
|
|
|
/* Add file name and extension without path. */
|
2016-06-17 18:00:29 +00:00
|
|
|
wxFileName fn( images->GetGbrImage( ii )->m_FileName );
|
2020-06-06 15:35:46 +00:00
|
|
|
label = new wxStaticText( this, wxID_STATIC, fn.GetFullName() );
|
|
|
|
flexColumnBoxSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
2007-11-02 05:33:31 +00:00
|
|
|
|
|
|
|
// Provide a button for this layer (which will invoke a child dialog box)
|
2020-07-04 01:21:24 +00:00
|
|
|
item_ID = ID_BUTTON_0 + ii;
|
2020-06-06 15:35:46 +00:00
|
|
|
wxButton * Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxBU_EXACTFIT );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2018-01-05 10:45:50 +00:00
|
|
|
flexColumnBoxSizer->Add( Button, 0, wxALIGN_CENTER_VERTICAL | wxALL );
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Provide another text string to specify which Pcbnew layer that this
|
2020-07-04 01:21:24 +00:00
|
|
|
// Gerber layer is mapped to. All layers initially default to
|
|
|
|
// "Do NotExport" (which corresponds to UNSELECTED_LAYER). Whenever
|
|
|
|
// a layer is set to "Do Not Export" it's displayed in blue. When a
|
|
|
|
// user selects a specific KiCad layer to map to, it's displayed in
|
|
|
|
// magenta which indicates it will be exported.
|
2007-11-02 05:33:31 +00:00
|
|
|
item_ID = ID_TEXT_0 + ii;
|
|
|
|
|
2020-07-04 01:21:24 +00:00
|
|
|
// All layers default to "Do Not Export" displayed in blue
|
|
|
|
msg = _( "Do not export" );
|
|
|
|
text = new wxStaticText( this, item_ID, msg );
|
|
|
|
text->SetForegroundColour( *wxBLUE );
|
|
|
|
|
2009-04-29 17:09:00 +00:00
|
|
|
// When the first of these text strings is being added, determine what
|
|
|
|
// size is necessary to to be able to display any possible string
|
|
|
|
// without it being truncated. Then specify that size as the minimum
|
|
|
|
// size for all of these text strings. (If this minimum size is not
|
|
|
|
// determined in this fashion, then it is possible for the display of
|
2011-09-30 18:15:37 +00:00
|
|
|
// one or more of these strings to be truncated after different Pcbnew
|
2009-04-29 17:09:00 +00:00
|
|
|
// layers are selected.)
|
2020-07-04 01:21:24 +00:00
|
|
|
|
2007-11-02 05:33:31 +00:00
|
|
|
if( ii == 0 )
|
|
|
|
{
|
|
|
|
goodSize = text->GetSize();
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( LAYER_NUM jj = 0; jj < GERBER_DRAWLAYERS_COUNT; ++jj )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
2012-05-04 17:44:42 +00:00
|
|
|
text->SetLabel( GetPCBDefaultLayerName( jj ) );
|
2020-06-06 15:35:46 +00:00
|
|
|
|
2007-11-02 05:33:31 +00:00
|
|
|
if( goodSize.x < text->GetSize().x )
|
|
|
|
goodSize.x = text->GetSize().x;
|
|
|
|
}
|
2020-07-04 01:21:24 +00:00
|
|
|
text->SetLabel( msg ); // Reset label to default text
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
2020-07-04 01:21:24 +00:00
|
|
|
|
2007-11-02 05:33:31 +00:00
|
|
|
text->SetMinSize( goodSize );
|
2020-06-06 15:35:46 +00:00
|
|
|
flexColumnBoxSizer->Add( text, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii] = text;
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// If the user has never stored any Gerber to KiCad layer mapping,
|
2020-07-24 22:22:38 +00:00
|
|
|
// then disable the button to retrieve it
|
|
|
|
if( config->m_GerberToPcbLayerMapping.size() == 0 )
|
|
|
|
m_buttonRetrieve->Enable( false );
|
|
|
|
|
2020-07-04 22:12:49 +00:00
|
|
|
std::vector<int> gerber2KicadMapping;
|
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
// See how many of the loaded Gerbers can be mapped to KiCad layers automatically
|
|
|
|
int numMappedGerbers = findKnownGerbersLoaded( gerber2KicadMapping );
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
if( numMappedGerbers > 0 )
|
2020-07-04 22:12:49 +00:00
|
|
|
{
|
|
|
|
// See if the user wants to map the Altium Gerbers to known KiCad PCB layers
|
|
|
|
int returnVal = wxMessageBox(
|
2020-07-29 03:05:06 +00:00
|
|
|
_( "Gerbers with known layers: " + wxString::Format( wxT( "%i" ), numMappedGerbers )
|
2020-07-04 22:12:49 +00:00
|
|
|
+ "\n\nAssign to matching KiCad PCB layers?" ),
|
|
|
|
_( "Automatic Layer Assignment" ), wxOK | wxCANCEL | wxOK_DEFAULT );
|
|
|
|
|
|
|
|
if( returnVal == wxOK )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
|
|
|
{
|
|
|
|
int currLayer = gerber2KicadMapping[ii];
|
|
|
|
|
|
|
|
// Default to "Do Not Export" for unselected or undefined layer
|
|
|
|
if( ( currLayer == UNSELECTED_LAYER ) || ( currLayer == UNDEFINED_LAYER ) )
|
|
|
|
{
|
|
|
|
m_layersList[ii]->SetLabel( _( "Do not export" ) );
|
|
|
|
m_layersList[ii]->SetForegroundColour( *wxBLUE );
|
|
|
|
|
|
|
|
// Set the layer internally to unselected
|
|
|
|
m_layersLookUpTable[ii] = UNSELECTED_LAYER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_layersList[ii]->SetLabel( GetPCBDefaultLayerName( currLayer ) );
|
|
|
|
m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
|
|
|
|
|
|
|
|
// Set the layer internally to the matching KiCad layer
|
|
|
|
m_layersLookUpTable[ii] = currLayer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::normalizeBrdLayersCount()
|
|
|
|
{
|
|
|
|
if( ( m_exportBoardCopperLayersCount & 1 ) )
|
|
|
|
m_exportBoardCopperLayersCount++;
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
if( m_exportBoardCopperLayersCount > GERBER_DRAWLAYERS_COUNT )
|
|
|
|
m_exportBoardCopperLayersCount = GERBER_DRAWLAYERS_COUNT;
|
2011-04-26 08:30:16 +00:00
|
|
|
|
|
|
|
if( m_exportBoardCopperLayersCount < 2 )
|
|
|
|
m_exportBoardCopperLayersCount = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::OnBrdLayersCountSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int id = event.GetSelection();
|
2021-07-21 21:37:49 +00:00
|
|
|
m_exportBoardCopperLayersCount = ( id + 1 ) * 2;
|
2011-04-26 08:30:16 +00:00
|
|
|
}
|
2011-04-24 18:26:42 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::OnResetClick( wxCommandEvent& event )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-07-04 01:21:24 +00:00
|
|
|
wxString msg;
|
|
|
|
int ii;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer;
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( ii = 0, layer = 0; ii < m_gerberActiveLayersCount; ii++, ++layer )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-07-04 01:21:24 +00:00
|
|
|
m_layersLookUpTable[ii] = UNSELECTED_LAYER;
|
|
|
|
m_layersList[ii]->SetLabel( _( "Do not export" ) );
|
|
|
|
m_layersList[ii]->SetForegroundColour( *wxBLUE );
|
2011-04-26 08:30:16 +00:00
|
|
|
m_buttonTable[ii] = ii;
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::OnStoreSetup( wxCommandEvent& event )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-03-23 15:17:22 +00:00
|
|
|
auto config = static_cast<GERBVIEW_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-01-13 01:44:19 +00:00
|
|
|
config->m_BoardLayersCount = m_exportBoardCopperLayersCount;
|
|
|
|
|
|
|
|
config->m_GerberToPcbLayerMapping.clear();
|
2011-04-24 18:26:42 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
config->m_GerberToPcbLayerMapping.push_back( m_layersLookUpTable[ii] );
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
2020-07-24 22:22:38 +00:00
|
|
|
|
|
|
|
// Enable the "Get Stored Choice" button in case it was disabled in "initDialog()"
|
|
|
|
// due to no previously stored choices.
|
|
|
|
m_buttonRetrieve->Enable( true );
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::OnGetSetup( wxCommandEvent& event )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-07-11 07:36:59 +00:00
|
|
|
GERBVIEW_SETTINGS* config = static_cast<GERBVIEW_SETTINGS*>( Kiface().KifaceSettings() );
|
2011-04-26 08:30:16 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_exportBoardCopperLayersCount = config->m_BoardLayersCount;
|
2011-04-26 08:30:16 +00:00
|
|
|
normalizeBrdLayersCount();
|
|
|
|
|
|
|
|
int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1;
|
|
|
|
m_comboCopperLayersCount->SetSelection( idx );
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2020-07-11 07:36:59 +00:00
|
|
|
// Ensure the layer mapping in config exists for this layer, and store it
|
|
|
|
if( (size_t)ii >= config->m_GerberToPcbLayerMapping.size() )
|
|
|
|
break;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_layersLookUpTable[ii] = config->m_GerberToPcbLayerMapping[ ii ];
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = m_layersLookUpTable[ii];
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer == UNSELECTED_LAYER )
|
2011-04-24 18:26:42 +00:00
|
|
|
{
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii]->SetLabel( _( "Do not export" ) );
|
|
|
|
m_layersList[ii]->SetForegroundColour( *wxBLUE );
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
2020-06-06 15:35:46 +00:00
|
|
|
else if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
m_layersList[ii]->SetLabel( _( "Hole data" ) );
|
|
|
|
m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
|
|
|
|
}
|
2011-04-24 18:26:42 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-04 17:44:42 +00:00
|
|
|
m_layersList[ii]->SetLabel( GetPCBDefaultLayerName( layer ) );
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
|
2011-04-24 18:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
int ii;
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
ii = event.GetId() - ID_BUTTON_0;
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
if( (ii < 0) || (ii >= GERBER_DRAWLAYERS_COUNT) )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxFAIL_MSG( wxT( "Bad layer id" ) );
|
2007-11-02 05:33:31 +00:00
|
|
|
return;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM jj = m_layersLookUpTable[m_buttonTable[ii]];
|
2014-07-14 18:59:41 +00:00
|
|
|
|
2020-06-06 15:35:46 +00:00
|
|
|
if( jj != UNSELECTED_LAYER && jj != UNDEFINED_LAYER && !IsValidLayer( jj ) )
|
2014-06-24 16:17:18 +00:00
|
|
|
jj = B_Cu; // (Defaults to "Copper" layer.)
|
2011-04-26 08:30:16 +00:00
|
|
|
|
2020-07-22 02:03:43 +00:00
|
|
|
// Get file name of Gerber loaded on this layer
|
|
|
|
wxFileName fn( m_Parent->GetGerberLayout()->GetImagesList()->GetGbrImage( ii )->m_FileName );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-07-22 02:03:43 +00:00
|
|
|
// Surround it with quotes to make it stand out on the dialog title bar
|
|
|
|
wxString layerName = "\"" + fn.GetFullName() + "\"";
|
|
|
|
|
|
|
|
// Display dialog to let user select a layer for the Gerber
|
|
|
|
jj = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, layerName );
|
2007-11-02 05:33:31 +00:00
|
|
|
|
2020-06-06 15:35:46 +00:00
|
|
|
if( jj != UNSELECTED_LAYER && jj != UNDEFINED_LAYER && !IsValidLayer( jj ) )
|
2007-11-02 05:33:31 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
if( jj != m_layersLookUpTable[m_buttonTable[ii]] )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersLookUpTable[m_buttonTable[ii]] = jj;
|
2014-07-14 18:59:41 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( jj == UNSELECTED_LAYER )
|
2007-11-05 06:14:55 +00:00
|
|
|
{
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii]->SetLabel( _( "Do not export" ) );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2007-11-05 06:14:55 +00:00
|
|
|
// Change the text color to blue (to highlight
|
|
|
|
// that this layer is *not* being exported)
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii]->SetForegroundColour( *wxBLUE );
|
2007-11-05 06:14:55 +00:00
|
|
|
}
|
2020-06-06 15:35:46 +00:00
|
|
|
else if( jj == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
m_layersList[ii]->SetLabel( _( "Hole data" ) );
|
|
|
|
|
|
|
|
// Change the text color to fuchsia (to highlight
|
|
|
|
// that this layer *is* being exported)
|
|
|
|
m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
|
|
|
|
}
|
2007-11-02 05:33:31 +00:00
|
|
|
else
|
2007-11-05 06:14:55 +00:00
|
|
|
{
|
2012-05-04 17:44:42 +00:00
|
|
|
m_layersList[ii]->SetLabel( GetPCBDefaultLayerName( jj ) );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
// Change the text color to fuchsia (to highlight
|
2007-11-05 06:14:55 +00:00
|
|
|
// that this layer *is* being exported)
|
2011-04-26 08:30:16 +00:00
|
|
|
m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
|
2007-11-05 06:14:55 +00:00
|
|
|
}
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
bool LAYERS_MAP_DIALOG::TransferDataFromWindow()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2021-07-21 21:37:49 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Board must have enough copper layers to handle selected internal layers.
|
2011-04-26 08:30:16 +00:00
|
|
|
normalizeBrdLayersCount();
|
2011-04-24 18:26:42 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
int inner_layer_max = 0;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
|
2007-11-02 05:33:31 +00:00
|
|
|
{
|
2021-07-21 21:37:49 +00:00
|
|
|
if( m_layersLookUpTable[ii] < F_Cu )
|
|
|
|
{
|
|
|
|
if( m_layersLookUpTable[ii ] > inner_layer_max )
|
|
|
|
inner_layer_max = m_layersLookUpTable[ii];
|
|
|
|
}
|
2007-11-02 05:33:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
// inner_layer_max must be less than (or equal to the number of internal copper layers
|
2011-04-26 08:30:16 +00:00
|
|
|
// internal copper layers = m_exportBoardCopperLayersCount-2
|
|
|
|
if( inner_layer_max > m_exportBoardCopperLayersCount-2 )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxMessageBox( _("Exported board does not have enough copper layers to handle selected "
|
|
|
|
"inner layers") );
|
2021-07-21 21:37:49 +00:00
|
|
|
return false;
|
2011-04-26 08:30:16 +00:00
|
|
|
}
|
2016-06-18 09:37:36 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
return true;
|
2007-10-07 03:08:24 +00:00
|
|
|
}
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
|
|
|
|
int LAYERS_MAP_DIALOG::findKnownGerbersLoaded( std::vector<int>& aGerber2KicadMapping )
|
|
|
|
{
|
|
|
|
int numKnownGerbers = 0;
|
|
|
|
|
|
|
|
// We can automatically map Gerbers using different techniques. The first thing we
|
|
|
|
// try is to see if any of the loaded Gerbers were created by or use the
|
|
|
|
// Altium/Protel file extensions
|
|
|
|
numKnownGerbers += findNumAltiumGerbersLoaded( aGerber2KicadMapping );
|
|
|
|
|
|
|
|
// Next we check if any of the loaded Gerbers are X2 Gerbers and if they contain
|
|
|
|
|
|
|
|
// layer information in "File Functions". For info about X2 Gerbers see
|
|
|
|
// http://www.ucamco.com/files/downloads/file/81/the_gerber_file_format_specification.pdf
|
|
|
|
numKnownGerbers += findNumX2GerbersLoaded( aGerber2KicadMapping );
|
|
|
|
|
|
|
|
// Finally, check if any of the loaded Gerbers use the KiCad naming conventions
|
|
|
|
numKnownGerbers += findNumKiCadGerbersLoaded( aGerber2KicadMapping );
|
|
|
|
|
|
|
|
return numKnownGerbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-04 22:12:49 +00:00
|
|
|
int LAYERS_MAP_DIALOG::findNumAltiumGerbersLoaded( std::vector<int>& aGerber2KicadMapping )
|
|
|
|
{
|
|
|
|
// The next comment preserves initializer formatting below it
|
|
|
|
// clang-format off
|
|
|
|
// This map contains the known Altium file extensions for Gerbers that we care about,
|
|
|
|
// along with their corresponding KiCad layer
|
|
|
|
std::map<wxString, PCB_LAYER_ID> altiumExt{
|
|
|
|
{ "GTL", F_Cu }, // Top copper
|
|
|
|
{ "G1", In1_Cu }, // Inner layers 1 - 30
|
|
|
|
{ "G2", In2_Cu },
|
|
|
|
{ "G3", In3_Cu },
|
|
|
|
{ "G4", In4_Cu },
|
|
|
|
{ "G5", In5_Cu },
|
|
|
|
{ "G6", In6_Cu },
|
|
|
|
{ "G7", In7_Cu },
|
|
|
|
{ "G8", In8_Cu },
|
|
|
|
{ "G9", In9_Cu },
|
|
|
|
{ "G10", In10_Cu },
|
|
|
|
{ "G11", In11_Cu },
|
|
|
|
{ "G12", In12_Cu },
|
|
|
|
{ "G13", In13_Cu },
|
|
|
|
{ "G14", In14_Cu },
|
|
|
|
{ "G15", In15_Cu },
|
|
|
|
{ "G16", In16_Cu },
|
|
|
|
{ "G17", In17_Cu },
|
|
|
|
{ "G18", In18_Cu },
|
|
|
|
{ "G19", In19_Cu },
|
|
|
|
{ "G20", In20_Cu },
|
|
|
|
{ "G21", In21_Cu },
|
|
|
|
{ "G22", In22_Cu },
|
|
|
|
{ "G23", In23_Cu },
|
|
|
|
{ "G24", In24_Cu },
|
|
|
|
{ "G25", In25_Cu },
|
|
|
|
{ "G26", In26_Cu },
|
|
|
|
{ "G27", In27_Cu },
|
|
|
|
{ "G28", In28_Cu },
|
|
|
|
{ "G29", In29_Cu },
|
|
|
|
{ "G30", In30_Cu },
|
|
|
|
{ "GBL", B_Cu }, // Bottom copper
|
|
|
|
{ "GTP", F_Paste }, // Paste top
|
|
|
|
{ "GBP", B_Paste }, // Paste bottom
|
|
|
|
{ "GTO", F_SilkS }, // Silkscreen top
|
|
|
|
{ "GBO", B_SilkS }, // Silkscreen bottom
|
|
|
|
{ "GTS", F_Mask }, // Soldermask top
|
|
|
|
{ "GBS", B_Mask }, // Soldermask bottom
|
|
|
|
{ "GM1", Eco1_User }, // Altium mechanical layer 1
|
|
|
|
{ "GM2", Eco2_User }, // Altium mechanical layer 2
|
|
|
|
{ "GKO", Edge_Cuts } // PCB Outline
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
std::map<wxString, PCB_LAYER_ID>::iterator it;
|
|
|
|
|
|
|
|
int numAltiumMatches = 0; // Assume we won't find Altium Gerbers
|
|
|
|
|
|
|
|
GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
|
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
// If the passed vector isn't empty but is too small to hold the loaded
|
|
|
|
// Gerbers, then bail because something isn't right.
|
|
|
|
|
|
|
|
if( ( aGerber2KicadMapping.size() != 0 )
|
|
|
|
&& ( aGerber2KicadMapping.size() != (size_t) m_gerberActiveLayersCount ) )
|
|
|
|
return numAltiumMatches;
|
|
|
|
|
|
|
|
// If the passed vector is empty, set it to the same number of elements as there
|
|
|
|
// are loaded Gerbers, and set each to "UNSELECTED_LAYER"
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping.size() == 0 )
|
|
|
|
aGerber2KicadMapping.assign( m_gerberActiveLayersCount, UNSELECTED_LAYER );
|
|
|
|
|
2020-07-04 22:12:49 +00:00
|
|
|
// Loop through all loaded Gerbers looking for any with Altium specific extensions
|
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
|
|
|
{
|
2020-07-29 03:05:06 +00:00
|
|
|
if( images->GetGbrImage( ii ) )
|
|
|
|
{
|
|
|
|
// Get file name of Gerber loaded on this layer.
|
|
|
|
wxFileName fn( images->GetGbrImage( ii )->m_FileName );
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
// Get uppercase version of file extension
|
|
|
|
wxString FileExt = fn.GetExt();
|
|
|
|
FileExt.MakeUpper();
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
// Check for matching Altium Gerber file extension we'll handle
|
|
|
|
it = altiumExt.find( FileExt );
|
2020-07-04 22:12:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
if( it != altiumExt.end() )
|
|
|
|
{
|
|
|
|
// We got a match, so store the KiCad layer number. We verify it's set to
|
|
|
|
// "UNSELECTED_LAYER" in case the passed vector already had entries
|
|
|
|
// matched to other known Gerber files. This will preserve them.
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping[ii] == UNSELECTED_LAYER )
|
|
|
|
{
|
|
|
|
aGerber2KicadMapping[ii] = it->second;
|
|
|
|
numAltiumMatches++;
|
|
|
|
}
|
|
|
|
}
|
2020-07-04 22:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of Altium Gerbers we found. Each index in the passed vector corresponds to
|
|
|
|
// a loaded Gerber layer, and the entry will contain the index to the matching
|
|
|
|
// KiCad layer for Altium Gerbers, or "UNSELECTED_LAYER" for the rest.
|
|
|
|
return numAltiumMatches;
|
|
|
|
}
|
2020-07-29 03:05:06 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
int LAYERS_MAP_DIALOG::findNumKiCadGerbersLoaded( std::vector<int>& aGerber2KicadMapping )
|
|
|
|
{
|
|
|
|
// The next comment preserves initializer formatting below it
|
|
|
|
// clang-format off
|
|
|
|
// This map contains the known KiCad suffixes used for Gerbers that we care about,
|
|
|
|
// along with their corresponding KiCad layer
|
|
|
|
std::map<wxString, PCB_LAYER_ID> kicadLayers
|
|
|
|
{
|
|
|
|
{ "-F_Cu", F_Cu },
|
|
|
|
{ "-In1_Cu", In1_Cu },
|
|
|
|
{ "-In2_Cu", In2_Cu },
|
|
|
|
{ "-In3_Cu", In3_Cu },
|
|
|
|
{ "-In4_Cu", In4_Cu },
|
|
|
|
{ "-In5_Cu", In5_Cu },
|
|
|
|
{ "-In6_Cu", In6_Cu },
|
|
|
|
{ "-In7_Cu", In7_Cu },
|
|
|
|
{ "-In8_Cu", In8_Cu },
|
|
|
|
{ "-In9_Cu", In9_Cu },
|
|
|
|
{ "-In10_Cu", In10_Cu },
|
|
|
|
{ "-In11_Cu", In11_Cu },
|
|
|
|
{ "-In12_Cu", In12_Cu },
|
|
|
|
{ "-In13_Cu", In13_Cu },
|
|
|
|
{ "-In14_Cu", In14_Cu },
|
|
|
|
{ "-In15_Cu", In15_Cu },
|
|
|
|
{ "-In16_Cu", In16_Cu },
|
|
|
|
{ "-In17_Cu", In17_Cu },
|
|
|
|
{ "-In18_Cu", In18_Cu },
|
|
|
|
{ "-In19_Cu", In19_Cu },
|
|
|
|
{ "-In20_Cu", In20_Cu },
|
|
|
|
{ "-In21_Cu", In21_Cu },
|
|
|
|
{ "-In22_Cu", In22_Cu },
|
|
|
|
{ "-In23_Cu", In23_Cu },
|
|
|
|
{ "-In24_Cu", In24_Cu },
|
|
|
|
{ "-In25_Cu", In25_Cu },
|
|
|
|
{ "-In26_Cu", In26_Cu },
|
|
|
|
{ "-In27_Cu", In27_Cu },
|
|
|
|
{ "-In28_Cu", In28_Cu },
|
|
|
|
{ "-In29_Cu", In29_Cu },
|
|
|
|
{ "-In30_Cu", In30_Cu },
|
|
|
|
{ "-B_Cu", B_Cu },
|
|
|
|
{ "-B_Adhes", B_Adhes },
|
|
|
|
{ "-F_Adhes", F_Adhes },
|
|
|
|
{ "-B_Paste", B_Paste },
|
|
|
|
{ "-F_Paste", F_Paste },
|
|
|
|
{ "-B_SilkS", B_SilkS },
|
|
|
|
{ "-F_SilkS", F_SilkS },
|
|
|
|
{ "-B_Mask", B_Mask },
|
|
|
|
{ "-F_Mask", F_Mask },
|
|
|
|
{ "-Dwgs_User", Dwgs_User },
|
|
|
|
{ "-Cmts_User", Cmts_User },
|
|
|
|
{ "-Eco1_User", Eco1_User },
|
|
|
|
{ "-Eco2_User", Eco2_User },
|
|
|
|
{ "-Edge_Cuts", Edge_Cuts }
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
std::map<wxString, PCB_LAYER_ID>::iterator it;
|
|
|
|
|
|
|
|
int numKicadMatches = 0; // Assume we won't find KiCad Gerbers
|
|
|
|
|
|
|
|
GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
|
|
|
|
|
|
|
|
// If the passed vector isn't empty but is too small to hold the loaded
|
|
|
|
// Gerbers, then bail because something isn't right.
|
|
|
|
|
|
|
|
if( ( aGerber2KicadMapping.size() != 0 )
|
|
|
|
&& ( aGerber2KicadMapping.size() < (size_t) m_gerberActiveLayersCount ) )
|
|
|
|
return numKicadMatches;
|
|
|
|
|
|
|
|
// If the passed vector is empty, set it to the same number of elements as there
|
|
|
|
// are loaded Gerbers, and set each to "UNSELECTED_LAYER"
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping.size() == 0 )
|
|
|
|
aGerber2KicadMapping.assign( m_gerberActiveLayersCount, UNSELECTED_LAYER );
|
|
|
|
|
|
|
|
// Loop through all loaded Gerbers looking for any with KiCad specific layer names
|
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
|
|
|
{
|
|
|
|
if( images->GetGbrImage( ii ) )
|
|
|
|
{
|
|
|
|
// Get file name of Gerber loaded on this layer.
|
|
|
|
wxFileName fn( images->GetGbrImage( ii )->m_FileName );
|
|
|
|
|
|
|
|
wxString layerName = fn.GetName();
|
|
|
|
|
|
|
|
// To create Gerber file names, KiCad appends a suffix consisting of a "-" and the
|
|
|
|
// name of the layer to the project name. We need to isolate the suffix if present
|
|
|
|
// and see if it's a known KiCad layer name. Start by looking for the last "-" in
|
|
|
|
// the file name.
|
|
|
|
int dashPos = layerName.Find( '-', true );
|
|
|
|
|
|
|
|
// If one was found, isolate the suffix from the "-" to the end of the file name
|
|
|
|
wxString suffix;
|
|
|
|
|
|
|
|
if( dashPos != wxNOT_FOUND )
|
|
|
|
suffix = layerName.Right( layerName.length() - dashPos );
|
|
|
|
|
|
|
|
// Check if the string we've isolated matches any known KiCad layer names
|
|
|
|
it = kicadLayers.find( suffix );
|
|
|
|
|
|
|
|
if( it != kicadLayers.end() )
|
|
|
|
{
|
|
|
|
// We got a match, so store the KiCad layer number. We verify it's set to
|
|
|
|
// "UNSELECTED_LAYER" in case the passed vector already had entries
|
|
|
|
// matched to other known Gerber files. This will preserve them.
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping[ii] == UNSELECTED_LAYER )
|
|
|
|
{
|
|
|
|
aGerber2KicadMapping[ii] = it->second;
|
|
|
|
numKicadMatches++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return number of KiCad Gerbers we found. Each index in the passed vector corresponds to
|
|
|
|
// a loaded Gerber layer, and the entry will contain the index to the matching
|
|
|
|
// KiCad layer for KiCad Gerbers, or "UNSELECTED_LAYER" for the rest.
|
|
|
|
return numKicadMatches;
|
|
|
|
}
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
int LAYERS_MAP_DIALOG::findNumX2GerbersLoaded( std::vector<int>& aGerber2KicadMapping )
|
|
|
|
{
|
|
|
|
// The next comment preserves initializer formatting below it
|
|
|
|
// clang-format off
|
|
|
|
// This map contains the known KiCad X2 "File Function" values used for Gerbers that we
|
|
|
|
// care about, along with their corresponding KiCad layer
|
|
|
|
std::map<wxString, PCB_LAYER_ID> kicadLayers
|
|
|
|
{
|
|
|
|
{ "Top", F_Cu },
|
|
|
|
{ "L2", In1_Cu },
|
2021-01-31 16:51:08 +00:00
|
|
|
{ "L3", In2_Cu },
|
|
|
|
{ "L4", In3_Cu },
|
|
|
|
{ "L5", In4_Cu },
|
|
|
|
{ "L6", In5_Cu },
|
|
|
|
{ "L7", In6_Cu },
|
|
|
|
{ "L8", In7_Cu },
|
|
|
|
{ "L9", In8_Cu },
|
|
|
|
{ "L10", In9_Cu },
|
|
|
|
{ "L11", In10_Cu },
|
|
|
|
{ "L12", In11_Cu },
|
|
|
|
{ "L13", In12_Cu },
|
|
|
|
{ "L14", In13_Cu },
|
|
|
|
{ "L15", In14_Cu },
|
|
|
|
{ "L16", In15_Cu },
|
|
|
|
{ "L17", In16_Cu },
|
|
|
|
{ "L18", In17_Cu },
|
|
|
|
{ "L19", In18_Cu },
|
|
|
|
{ "L20", In19_Cu },
|
|
|
|
{ "L21", In20_Cu },
|
|
|
|
{ "L22", In21_Cu },
|
|
|
|
{ "L23", In22_Cu },
|
|
|
|
{ "L24", In23_Cu },
|
|
|
|
{ "L25", In24_Cu },
|
|
|
|
{ "L26", In25_Cu },
|
|
|
|
{ "L27", In26_Cu },
|
|
|
|
{ "L28", In27_Cu },
|
|
|
|
{ "L29", In28_Cu },
|
|
|
|
{ "L30", In29_Cu },
|
2020-07-29 03:05:06 +00:00
|
|
|
{ "Bot", B_Cu },
|
|
|
|
{ "BotGlue", B_Adhes },
|
|
|
|
{ "TopGlue", F_Adhes },
|
|
|
|
{ "BotPaste", B_Paste },
|
|
|
|
{ "TopPaste", F_Paste },
|
|
|
|
{ "BotLegend", B_SilkS },
|
|
|
|
{ "TopLegend", F_SilkS },
|
|
|
|
{ "BotSoldermask", B_Mask },
|
|
|
|
{ "TopSoldermask", F_Mask },
|
|
|
|
{ "FabricationDrawing", Dwgs_User },
|
|
|
|
{ "OtherDrawing", Cmts_User },
|
|
|
|
{ "TopAssemblyDrawing", Eco1_User },
|
|
|
|
{ "BotAssemblyDrawing", Eco2_User },
|
|
|
|
{ "PProfile", Edge_Cuts }, // Plated PCB outline
|
|
|
|
{ "NPProfile", Edge_Cuts } // Non-plated PCB outline
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
std::map<wxString, PCB_LAYER_ID>::iterator it;
|
|
|
|
|
|
|
|
int numKicadMatches = 0; // Assume we won't find KiCad Gerbers
|
|
|
|
|
|
|
|
wxString mapThis;
|
|
|
|
|
|
|
|
GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
|
|
|
|
|
|
|
|
// If the passed vector isn't empty but is too small to hold the loaded
|
|
|
|
// Gerbers, then bail because something isn't right.
|
|
|
|
|
|
|
|
if( ( aGerber2KicadMapping.size() != 0 )
|
|
|
|
&& ( aGerber2KicadMapping.size() < (size_t) m_gerberActiveLayersCount ) )
|
|
|
|
return numKicadMatches;
|
|
|
|
|
|
|
|
// If the passed vector is empty, set it to the same number of elements as there
|
|
|
|
// are loaded Gerbers, and set each to "UNSELECTED_LAYER"
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping.size() == 0 )
|
|
|
|
aGerber2KicadMapping.assign( m_gerberActiveLayersCount, UNSELECTED_LAYER );
|
|
|
|
|
|
|
|
// Loop through all loaded Gerbers looking for any with X2 File Functions
|
|
|
|
for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
|
|
|
|
{
|
|
|
|
if( images->GetGbrImage( ii ) )
|
|
|
|
{
|
|
|
|
X2_ATTRIBUTE_FILEFUNCTION* x2 = images->GetGbrImage( ii )->m_FileFunction;
|
|
|
|
|
|
|
|
mapThis = "";
|
|
|
|
|
|
|
|
if( images->GetGbrImage( ii )->m_IsX2_file )
|
|
|
|
{
|
2021-01-27 22:17:32 +00:00
|
|
|
wxCHECK( x2, numKicadMatches );
|
|
|
|
|
2020-07-29 03:05:06 +00:00
|
|
|
if( x2->IsCopper() )
|
|
|
|
{
|
|
|
|
// This is a copper layer, so figure out which one
|
|
|
|
mapThis = x2->GetBrdLayerSide(); // Returns "Top", "Bot" or "Inr"
|
|
|
|
|
|
|
|
// To map inner layers properly, we need the layer number
|
|
|
|
if( mapThis.IsSameAs( wxT( "Inr" ), false ) )
|
|
|
|
mapThis = x2->GetBrdLayerId(); // Returns "L2", "L5", etc
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create strings like "TopSolderMask" or "BotPaste" for non-copper layers
|
|
|
|
mapThis << x2->GetBrdLayerId() << x2->GetFileType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the string we've isolated matches any known X2 layer names
|
|
|
|
it = kicadLayers.find( mapThis );
|
|
|
|
|
|
|
|
if( it != kicadLayers.end() )
|
|
|
|
{
|
|
|
|
// We got a match, so store the KiCad layer number. We verify it's set to
|
|
|
|
// "UNSELECTED_LAYER" in case the passed vector already had entries
|
|
|
|
// matched to other known Gerber files. This will preserve them.
|
|
|
|
|
|
|
|
if( aGerber2KicadMapping[ii] == UNSELECTED_LAYER )
|
|
|
|
{
|
|
|
|
aGerber2KicadMapping[ii] = it->second;
|
|
|
|
numKicadMatches++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numKicadMatches;
|
2020-10-08 22:59:16 +00:00
|
|
|
}
|