From d65b6487227515e77c8e7816d2ee60d3965d3c0a Mon Sep 17 00:00:00 2001 From: Marco Serantoni Date: Wed, 3 Nov 2010 00:13:56 +0100 Subject: [PATCH] pcbnew: layer combo update, code cleanup --- include/class_layerchoicebox.h | 55 +++++++++++++++ include/wxPcbStruct.h | 5 +- pcbnew/CMakeLists.txt | 1 + pcbnew/class_layerchoicebox.cpp | 115 ++++++++++++++++++++++++++++++++ pcbnew/tool_pcb.cpp | 96 +++----------------------- 5 files changed, 185 insertions(+), 87 deletions(-) create mode 100644 include/class_layerchoicebox.h create mode 100644 pcbnew/class_layerchoicebox.cpp diff --git a/include/class_layerchoicebox.h b/include/class_layerchoicebox.h new file mode 100644 index 0000000000..0d8c93b629 --- /dev/null +++ b/include/class_layerchoicebox.h @@ -0,0 +1,55 @@ +#ifndef CLASS_LAYERCHOICEBOX_H +#define CLASS_LAYERCHOICEBOX_H 1 + +#include + +/* 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 diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 355f77826a..182de55447 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.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 diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 265c5719f1..fa190a9709 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -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 diff --git a/pcbnew/class_layerchoicebox.cpp b/pcbnew/class_layerchoicebox.cpp new file mode 100644 index 0000000000..588b166367 --- /dev/null +++ b/pcbnew/class_layerchoicebox.cpp @@ -0,0 +1,115 @@ +#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 +#include +#include +#include + +#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 ); + } + + } + diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index 89b37194af..250b054de1 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -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; listNdxwxItemContainer::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();