2007-06-05 12:10:51 +00:00
|
|
|
/*******************************************************/
|
|
|
|
/* Dialog frame to choose gerber layers and pcb layers */
|
|
|
|
/*******************************************************/
|
|
|
|
|
|
|
|
/* select_layers_to_pcb.cpp*/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "gerbview.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#include "protos.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Variables locales */
|
2007-10-07 03:08:24 +00:00
|
|
|
static int RadioButtonTable[32]; // Indexes radiobuttons to Gerber layers
|
|
|
|
static int LayerLookUpTable[32]; // Indexes Gerber layers to PCB file layers
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
enum swap_layer_id {
|
2007-10-07 03:08:24 +00:00
|
|
|
ID_SWAP_LAYER_BUTTON_SELECT = 1800,
|
|
|
|
ID_SWAP_LAYER_DESELECT,
|
|
|
|
ID_SWAP_LAYER_SELECT
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************/
|
|
|
|
/* classe pour la frame de selection de layers */
|
|
|
|
/***********************************************/
|
|
|
|
|
|
|
|
class WinEDA_SwapLayerFrame: public wxDialog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
WinEDA_GerberFrame *m_Parent;
|
|
|
|
wxRadioBox * m_LayerList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor and destructor
|
|
|
|
WinEDA_SwapLayerFrame(WinEDA_GerberFrame *parent);
|
2007-09-13 11:55:46 +00:00
|
|
|
~WinEDA_SwapLayerFrame() {};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2007-10-07 03:08:24 +00:00
|
|
|
void Sel_Layer(wxCommandEvent& event);
|
|
|
|
void OnOkClick(wxCommandEvent& event);
|
|
|
|
void OnCancelClick(wxCommandEvent& event);
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
};
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Table des evenements pour WinEDA_SwapLayerFrame */
|
|
|
|
BEGIN_EVENT_TABLE(WinEDA_SwapLayerFrame, wxDialog)
|
2007-10-07 03:08:24 +00:00
|
|
|
EVT_BUTTON(wxID_OK, WinEDA_SwapLayerFrame::OnOkClick)
|
|
|
|
EVT_BUTTON(wxID_CANCEL, WinEDA_SwapLayerFrame::OnCancelClick)
|
|
|
|
EVT_BUTTON(ID_SWAP_LAYER_DESELECT, WinEDA_SwapLayerFrame::Sel_Layer)
|
|
|
|
EVT_BUTTON(ID_SWAP_LAYER_BUTTON_SELECT, WinEDA_SwapLayerFrame::Sel_Layer)
|
|
|
|
EVT_RADIOBOX(ID_SWAP_LAYER_SELECT, WinEDA_SwapLayerFrame::Sel_Layer)
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
int * InstallDialogLayerPairChoice(WinEDA_GerberFrame * parent)
|
|
|
|
/*************************************************************/
|
|
|
|
/* Install a dialog frame to choose the equivalence
|
2007-10-07 03:08:24 +00:00
|
|
|
* between gerber layers and pcbnew layers
|
|
|
|
* return the "lookup table" if ok, or NULL
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
WinEDA_SwapLayerFrame * frame = new WinEDA_SwapLayerFrame(parent);
|
2007-10-07 03:08:24 +00:00
|
|
|
int ii = frame->ShowModal();
|
|
|
|
frame->Destroy();
|
|
|
|
if( ii >= 0 )
|
|
|
|
return LayerLookUpTable;
|
|
|
|
else
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
WinEDA_SwapLayerFrame::WinEDA_SwapLayerFrame(WinEDA_GerberFrame *parent):
|
2007-10-07 03:08:24 +00:00
|
|
|
wxDialog( parent, -1, _("Layer selection:"), wxPoint(-1, -1),
|
2007-06-05 12:10:51 +00:00
|
|
|
wxDefaultSize, DIALOG_STYLE )
|
|
|
|
/*************************************************************************/
|
|
|
|
{
|
|
|
|
wxButton * Button;
|
|
|
|
int ii, nb_items;
|
|
|
|
wxString g_Layer_Name_Pair[32];
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
SetFont(*g_DialogFont);
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
// Compute a reasonable number of copper layers
|
2007-06-05 12:10:51 +00:00
|
|
|
g_DesignSettings.m_CopperLayerCount = 0;
|
2007-10-07 03:08:24 +00:00
|
|
|
for( ii = 0; ii < 32; ii++ )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
if( g_GERBER_Descr_List[ii] != NULL )
|
2007-06-05 12:10:51 +00:00
|
|
|
g_DesignSettings.m_CopperLayerCount++;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
// Specify the default value for each member of these arrays.
|
|
|
|
RadioButtonTable[ii] = -1;
|
|
|
|
LayerLookUpTable[ii] = NB_LAYERS; // Value associated with deselected Gerber layer
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pcb_layer_number = 0;
|
2007-10-07 03:08:24 +00:00
|
|
|
for( nb_items = 0, ii = 0; ii < 32; ii++ )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
if( g_GERBER_Descr_List[ii] == NULL )
|
2007-06-05 12:10:51 +00:00
|
|
|
continue;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
if( (pcb_layer_number == g_DesignSettings.m_CopperLayerCount - 1)
|
2007-06-05 12:10:51 +00:00
|
|
|
&& (g_DesignSettings.m_CopperLayerCount > 1) )
|
|
|
|
pcb_layer_number = CMP_N;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
RadioButtonTable[nb_items] = ii;
|
2007-06-05 12:10:51 +00:00
|
|
|
LayerLookUpTable[ii] = pcb_layer_number;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
// Specify initial (temporary) caption for associated radiobutton,
|
|
|
|
// which will be appropriately updated after dialog box has been sized.
|
|
|
|
// (If the radiobuttons' captions are not changed in this way, some of
|
|
|
|
// each radiobutton's caption could be truncated if the associated
|
|
|
|
// (Gerber) layer is ever subsequently deselected by the user.)
|
|
|
|
g_Layer_Name_Pair[nb_items] = _("Gerber layer ");
|
|
|
|
g_Layer_Name_Pair[nb_items] << ii + 1 << wxT(" -> ") << _("Do not export");
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
nb_items++;
|
|
|
|
pcb_layer_number++;
|
|
|
|
}
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
wxBoxSizer* FrameBoxSizer = new wxBoxSizer(wxVERTICAL);
|
2007-06-05 12:10:51 +00:00
|
|
|
SetSizer(FrameBoxSizer);
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
wxBoxSizer* MainBoxSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
FrameBoxSizer->Add(MainBoxSizer, 0, wxGROW|wxALIGN_LEFT|wxALL, 5);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
m_LayerList = new wxRadioBox(this, ID_SWAP_LAYER_SELECT, _("Layers"),
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
nb_items, g_Layer_Name_Pair,
|
2007-10-07 03:08:24 +00:00
|
|
|
nb_items < 16 ? nb_items : 16,
|
2007-06-05 12:10:51 +00:00
|
|
|
wxRA_SPECIFY_ROWS);
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
// Specify a minimum size for this radiobox (with the objective
|
|
|
|
// of attempting to prevent any radiobutton's caption from being
|
|
|
|
// truncated if any of the layers are subsequently deselected)
|
|
|
|
m_LayerList->SetMinSize( m_LayerList->GetSize() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
MainBoxSizer->Add(m_LayerList, 0, wxALIGN_TOP|wxALL, 5);
|
|
|
|
|
|
|
|
wxBoxSizer* RightBoxSizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
MainBoxSizer->Add(RightBoxSizer, 0, wxALIGN_TOP|wxALL, 0);
|
|
|
|
|
|
|
|
RightBoxSizer->AddSpacer(10);
|
|
|
|
|
|
|
|
Button = new wxButton(this, ID_SWAP_LAYER_BUTTON_SELECT, _("Select..."));
|
|
|
|
Button->SetForegroundColour(wxColour(0,100,100));
|
2007-06-05 12:10:51 +00:00
|
|
|
RightBoxSizer->Add(Button, 0, wxGROW|wxALL, 5);
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
Button = new wxButton(this, ID_SWAP_LAYER_DESELECT, _("Deselect"));
|
2007-06-05 12:10:51 +00:00
|
|
|
Button->SetForegroundColour(wxColour(0,100,0));
|
|
|
|
RightBoxSizer->Add(Button, 0, wxGROW|wxALL, 5);
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
wxBoxSizer* BottomBoxSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
FrameBoxSizer->Add(BottomBoxSizer, 0, wxGROW|wxALIGN_RIGHT|wxALL, 5);
|
|
|
|
|
|
|
|
// The following stretch spacer ensures that the "OK" and "Cancel" buttons
|
|
|
|
// will be positioned at the lower right corner of the dialog box.
|
|
|
|
BottomBoxSizer->AddStretchSpacer();
|
|
|
|
|
|
|
|
Button = new wxButton(this, wxID_OK, _("OK"));
|
|
|
|
Button->SetForegroundColour(*wxRED);
|
|
|
|
BottomBoxSizer->Add(Button, 0, wxGROW|wxALL, 5);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
Button = new wxButton(this, wxID_CANCEL, _("Cancel"));
|
|
|
|
Button->SetForegroundColour(*wxBLUE);
|
|
|
|
BottomBoxSizer->Add(Button, 0, wxGROW|wxALL, 5);
|
|
|
|
|
|
|
|
if( GetSizer() )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
}
|
2007-10-07 03:08:24 +00:00
|
|
|
|
|
|
|
// Now specify the correct caption for each radiobutton.
|
|
|
|
// (Regrettably though there are still problems with the Windows
|
|
|
|
// version; captions for each radiobutton can still be truncated.) :-(
|
|
|
|
for( ii = 0; ii < nb_items; ii++ )
|
|
|
|
{
|
|
|
|
g_Layer_Name_Pair[ii] = _("Gerber layer ");
|
|
|
|
g_Layer_Name_Pair[ii] << RadioButtonTable[ii] + 1 << wxT(" -> ")
|
|
|
|
<< ReturnPcbLayerName(LayerLookUpTable[RadioButtonTable[ii]]);
|
|
|
|
|
|
|
|
m_LayerList->SetString( ii, g_Layer_Name_Pair[ii] );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************/
|
|
|
|
void WinEDA_SwapLayerFrame::Sel_Layer(wxCommandEvent& event)
|
|
|
|
/***************************************************************/
|
|
|
|
{
|
|
|
|
int ii, jj;
|
2007-10-07 03:08:24 +00:00
|
|
|
// int gerber_layer_number;
|
2007-06-05 12:10:51 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
ii = m_LayerList->GetSelection();
|
2007-10-07 03:08:24 +00:00
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
switch ( event.GetId() )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
case ID_SWAP_LAYER_DESELECT:
|
|
|
|
if( LayerLookUpTable[RadioButtonTable[ii]] != NB_LAYERS )
|
|
|
|
{
|
|
|
|
LayerLookUpTable[RadioButtonTable[ii]] = NB_LAYERS;
|
|
|
|
msg = _("Gerber layer ");
|
|
|
|
msg << RadioButtonTable[ii] + 1
|
|
|
|
<< wxT(" -> ") << _("Do not export");
|
|
|
|
m_LayerList->SetString( ii, msg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SWAP_LAYER_BUTTON_SELECT:
|
|
|
|
case ID_SWAP_LAYER_SELECT:
|
|
|
|
jj = LayerLookUpTable[RadioButtonTable[ii]];
|
|
|
|
if( (jj < 0) || (jj > NB_LAYERS) )
|
|
|
|
jj = 0; // (Defaults to "Copper" layer.)
|
|
|
|
jj = m_Parent->SelectLayer(jj, -1, -1, true);
|
|
|
|
if( (jj < 0) || (jj > NB_LAYERS) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( jj != LayerLookUpTable[RadioButtonTable[ii]] )
|
|
|
|
{
|
|
|
|
LayerLookUpTable[RadioButtonTable[ii]] = jj;
|
|
|
|
msg = _("Gerber layer ");
|
|
|
|
msg << RadioButtonTable[ii] + 1 << wxT(" -> ");
|
|
|
|
if( jj == NB_LAYERS )
|
|
|
|
msg << _("Do not export");
|
|
|
|
else
|
|
|
|
msg << ReturnPcbLayerName(jj);
|
|
|
|
m_LayerList->SetString( ii, msg );
|
|
|
|
}
|
|
|
|
break;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
2007-10-07 03:08:24 +00:00
|
|
|
void WinEDA_SwapLayerFrame::OnCancelClick(wxCommandEvent& event)
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
2007-10-07 03:08:24 +00:00
|
|
|
void WinEDA_SwapLayerFrame::OnOkClick(wxCommandEvent& event)
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
bool AsCmpLayer = false;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Compute the number of copper layers
|
2007-10-07 03:08:24 +00:00
|
|
|
* this is the max layer number + 1 (if some internal layers exist)
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
g_DesignSettings.m_CopperLayerCount = 1;
|
2007-10-07 03:08:24 +00:00
|
|
|
for( ii = 0; ii < 32; ii++ )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
if( LayerLookUpTable[ii] == CMP_N )
|
|
|
|
AsCmpLayer = true;
|
2007-06-05 12:10:51 +00:00
|
|
|
else
|
|
|
|
{
|
2007-10-07 03:08:24 +00:00
|
|
|
if( LayerLookUpTable[ii] >= CMP_N )
|
|
|
|
continue; // not a copper layer
|
|
|
|
if( LayerLookUpTable[ii] >= g_DesignSettings.m_CopperLayerCount )
|
2007-06-05 12:10:51 +00:00
|
|
|
g_DesignSettings.m_CopperLayerCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
if( AsCmpLayer )
|
|
|
|
g_DesignSettings.m_CopperLayerCount++;
|
|
|
|
if( g_DesignSettings.m_CopperLayerCount > CMP_N + 1 ) // should not occur.
|
|
|
|
g_DesignSettings.m_CopperLayerCount = CMP_N + 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( 1 );
|
|
|
|
}
|