Commit d65b6487 authored by Marco Serantoni's avatar Marco Serantoni

pcbnew: layer combo update, code cleanup

parent ed9213c1
#ifndef CLASS_LAYERCHOICEBOX_H
#define CLASS_LAYERCHOICEBOX_H 1
#include <wx/bmpcbox.h>
/* class to display a layer list.
*
*/
class WinEDALayerChoiceBox : public wxBitmapComboBox
{
public:
WinEDALayerChoiceBox( wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL );
WinEDALayerChoiceBox( wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
const wxArrayString& choices );
// Get Current Item #
int GetChoice();
// Get Current Layer
int GetLayerChoice();
// Set Layer #
int SetLayerSelection(int layer);
// Reload the Layers
void Resync();
};
#define DECLARE_LAYERS_HOTKEY(list) int list[LAYER_COUNT] = \
{ \
HK_SWITCH_LAYER_TO_COPPER, \
HK_SWITCH_LAYER_TO_INNER1, \
HK_SWITCH_LAYER_TO_INNER2, \
HK_SWITCH_LAYER_TO_INNER3, \
HK_SWITCH_LAYER_TO_INNER4, \
HK_SWITCH_LAYER_TO_INNER5, \
HK_SWITCH_LAYER_TO_INNER6, \
HK_SWITCH_LAYER_TO_INNER7, \
HK_SWITCH_LAYER_TO_INNER8, \
HK_SWITCH_LAYER_TO_INNER9, \
HK_SWITCH_LAYER_TO_INNER10, \
HK_SWITCH_LAYER_TO_INNER11, \
HK_SWITCH_LAYER_TO_INNER12, \
HK_SWITCH_LAYER_TO_INNER13, \
HK_SWITCH_LAYER_TO_INNER14, \
HK_SWITCH_LAYER_TO_COMPONENT \
};
#endif //CLASS_LAYERCHOICEBOX_H
......@@ -9,6 +9,7 @@
#include "wxstruct.h"
#include "base_struct.h"
#include "param_config.h"
#include "class_layerchoicebox.h"
#ifndef PCB_INTERNAL_UNIT
#define PCB_INTERNAL_UNIT 10000
......@@ -114,7 +115,7 @@ protected:
public:
WinEDAChoiceBox* m_SelLayerBox; // a combo box to display and
WinEDALayerChoiceBox* m_SelLayerBox; // a combo box to display and
// select active layer
WinEDAChoiceBox* m_SelTrackWidthBox; // a combo box to display and
// select current track width
......@@ -308,7 +309,7 @@ public:
void ReCreateMicrowaveVToolbar();
void ReCreateOptToolbar();
void ReCreateMenuBar();
WinEDAChoiceBox* ReCreateLayerBox( WinEDA_Toolbar* parent );
WinEDALayerChoiceBox* ReCreateLayerBox( WinEDA_Toolbar* parent );
/** Virtual Function OnModify()
* Must be called after a board change
......
......@@ -32,6 +32,7 @@ set(PCBNEW_SRCS
block.cpp
block_module_editor.cpp
build_BOM_from_board.cpp
class_layerchoicebox.cpp
class_pcb_layer_widget.cpp
clean.cpp
# cleaningoptions_dialog.cpp
......
#include "common.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
#include "class_board_design_settings.h"
#include "colors_selection.h"
#include "bitmaps.h"
#include "pcbnew_id.h"
#include "hotkeys.h"
#include "help_common_strings.h"
#include <wx/ownerdrw.h>
#include <wx/menuitem.h>
#include <wx/bmpcbox.h>
#include <wx/wx.h>
#include "class_layerchoicebox.h"
/* class to display a layer list.
*
*/
WinEDALayerChoiceBox::WinEDALayerChoiceBox( wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
int n, const wxString choices[] ) :
wxBitmapComboBox( parent, id, wxEmptyString, pos, size,
n, choices, wxCB_READONLY )
{
}
WinEDALayerChoiceBox::WinEDALayerChoiceBox( wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
const wxArrayString& choices ) :
wxBitmapComboBox( parent, id, wxEmptyString, pos, size,
choices, wxCB_READONLY )
{
}
// Get Current Item #
int WinEDALayerChoiceBox::GetChoice()
{
return GetSelection();
}
// Get Current Layer
int WinEDALayerChoiceBox::GetLayerChoice()
{
return (long) GetClientData(GetSelection());
}
// Set Layer #
int WinEDALayerChoiceBox::SetLayerSelection(int layer)
{
int elements = GetCount();
for( int i = 0 ; i < elements; i++)
if(GetClientData(i) == (void*)layer)
if(GetSelection() != i) // Element (i) is not selected
{
SetSelection(i);
return i;
}
else
return i; //If element already selected; do nothing
// Not Found
SetSelection(-1);
return -1;
}
// Reload the Layers
void WinEDALayerChoiceBox::Resync()
{
BOARD* board = ((WinEDA_BasePcbFrame*)GetParent())->GetBoard();
wxASSERT(board != NULL);
Clear();
static DECLARE_LAYERS_ORDER_LIST(layertranscode);
static DECLARE_LAYERS_HOTKEY(layerhk);
for( int i=0 ; i < LAYER_COUNT ; i++)
{
wxBitmap layerbmp (20,18);
wxMemoryDC bmpDC;
wxBrush brush;
wxString layername;
int layerid = layertranscode[i];
// Prepare Bitmap
bmpDC.SelectObject(layerbmp);
brush.SetColour( MakeColour(board->GetLayerColor( layerid ) ));
brush.SetStyle( wxSOLID );
bmpDC.SetBrush(brush);
bmpDC.DrawRectangle(0,0,layerbmp.GetWidth(), layerbmp.GetHeight());
bmpDC.SetBrush(*wxTRANSPARENT_BRUSH);
bmpDC.SetPen(*wxBLACK_PEN);
bmpDC.DrawRectangle(0,0,layerbmp.GetWidth(), layerbmp.GetHeight());
layername = board->GetLayerName( layerid );
layername.Append("\t");
layername = AddHotkeyName( layername, s_Board_Editor_Hokeys_Descr, layerhk[layerid], false );
if(board->IsLayerEnabled(layerid))
Append(layername, layerbmp, (void*) layerid );
}
}
......@@ -27,6 +27,7 @@
#include "hotkeys.h"
#include "help_common_strings.h"
#include "class_layerchoicebox.h"
#define SEL_LAYER_HELP _( \
"Show active layer selections\nand select layer pair for route and place via" )
......@@ -266,8 +267,13 @@ void WinEDA_PcbFrame::ReCreateHToolbar()
_( "Perform design rules check" ) );
m_HToolBar->AddSeparator();
if(m_SelLayerBox == NULL)
m_SelLayerBox = new WinEDALayerChoiceBox( this, ID_TOOLBARH_PCB_SELECT_LAYER);
ReCreateLayerBox( m_HToolBar );
m_HToolBar->AddControl( m_SelLayerBox );
PrepareLayerIndicator(); // Initialize the bitmap with current
// active layer colors for the next tool
m_HToolBar->AddTool( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, wxEmptyString,
......@@ -685,97 +691,17 @@ void WinEDA_PcbFrame::syncLayerBox()
{
wxASSERT( m_SelLayerBox );
// Enable the display on the correct layer
// To avoid reentrancy ( Bug wxGTK Linux version? ), the selection is
// made only if it needs changing ( corrected on wxGTK 2.6.0 )
int count = m_SelLayerBox->GetCount();
int choice = m_SelLayerBox->GetChoice();
int layer = getActiveLayer();
for( int listNdx=0; listNdx<count; ++listNdx )
{
int clientData = (int) (size_t) m_SelLayerBox->wxItemContainer::GetClientData( listNdx );
if( clientData == layer )
{
if( listNdx != choice )
m_SelLayerBox->SetSelection( listNdx );
break;
}
}
m_SelLayerBox->SetLayerSelection(layer);
}
WinEDAChoiceBox* WinEDA_PcbFrame::ReCreateLayerBox( WinEDA_Toolbar* parent )
WinEDALayerChoiceBox* WinEDA_PcbFrame::ReCreateLayerBox( WinEDA_Toolbar* parent )
{
if( m_SelLayerBox == NULL )
{
if( parent == NULL )
return NULL;
m_SelLayerBox = new WinEDAChoiceBox( parent,
ID_TOOLBARH_PCB_SELECT_LAYER,
wxPoint( -1, -1 ),
#if defined (__UNIX__)
// Width enough for the longest
// string: "Component (Page Down)"
// Maybe that string is too long?
wxSize( 230, -1 )
#else
wxSize( LISTBOX_WIDTH + 30, -1 )
#endif
);
parent->AddControl( m_SelLayerBox );
}
int layer_mask = GetBoard()->GetEnabledLayers();
unsigned length = 0;
m_SelLayerBox->Clear();
static DECLARE_LAYERS_ORDER_LIST(layerOrder_for_display);
for( int idx=0, listNdx=0; idx <= EDGE_N; idx++ )
{
int layer = layerOrder_for_display[idx];
// List to append hotkeys in layer box selection
static const int HK_SwitchLayer[EDGE_N + 1] = {
HK_SWITCH_LAYER_TO_COPPER,
HK_SWITCH_LAYER_TO_INNER1,
HK_SWITCH_LAYER_TO_INNER2,
HK_SWITCH_LAYER_TO_INNER3,
HK_SWITCH_LAYER_TO_INNER4,
HK_SWITCH_LAYER_TO_INNER5,
HK_SWITCH_LAYER_TO_INNER6,
HK_SWITCH_LAYER_TO_INNER7,
HK_SWITCH_LAYER_TO_INNER8,
HK_SWITCH_LAYER_TO_INNER9,
HK_SWITCH_LAYER_TO_INNER10,
HK_SWITCH_LAYER_TO_INNER11,
HK_SWITCH_LAYER_TO_INNER12,
HK_SWITCH_LAYER_TO_INNER13,
HK_SWITCH_LAYER_TO_INNER14,
HK_SWITCH_LAYER_TO_COMPONENT
};
if( g_TabOneLayerMask[layer] & layer_mask )
{
wxString msg = GetBoard()->GetLayerName( layer );
msg << wxT(" ");
msg = AddHotkeyName( msg, s_Board_Editor_Hokeys_Descr,
HK_SwitchLayer[layer], false );
m_SelLayerBox->Append( msg );
//D(printf("appending layername=%s, ndx=%d, layer=%d\n", CONV_TO_UTF8(msg), listNdx, layer );)
m_SelLayerBox->wxItemContainer::SetClientData( listNdx, (void*) layer );
length = MAX( length, msg.Len() );
listNdx++;
}
}
if( m_SelLayerBox == NULL )
return NULL;
m_SelLayerBox->Resync();
m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
syncLayerBox();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment