Commit 6c14eee6 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: Redesign layer selection and layer pair selection (give them a look...

Pcbnew: Redesign layer selection and layer pair selection (give them a look near the Layer selector in toolbarr)
parent 51eaeccf
...@@ -11,6 +11,46 @@ ...@@ -11,6 +11,46 @@
#include <class_layer_box_selector.h> #include <class_layer_box_selector.h>
LAYER_SELECTOR::LAYER_SELECTOR()
{
m_layerorder = true;
m_layerhotkeys = true;
m_hotkeys = NULL;
}
bool LAYER_SELECTOR::SetLayersOrdered( bool value )
{
m_layerorder = value;
return m_layerorder;
}
bool LAYER_SELECTOR::SetLayersHotkeys( bool value )
{
m_layerhotkeys = value;
return m_layerhotkeys;
}
void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
{
wxMemoryDC bmpDC;
wxBrush brush;
// Prepare Bitmap
bmpDC.SelectObject( aLayerbmp );
brush.SetColour( MakeColour( GetLayerColor( aLayer ) ) );
brush.SetStyle( wxSOLID );
bmpDC.SetBrush( brush );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
bmpDC.SetPen( *wxBLACK_PEN );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
}
/* class to display a layer list. /* class to display a layer list.
* *
*/ */
...@@ -18,12 +58,9 @@ ...@@ -18,12 +58,9 @@
LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id, LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
int n, const wxString choices[] ) : int n, const wxString choices[] ) :
LAYER_SELECTOR(),
wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ) wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY )
{ {
m_layerorder = true;
m_layerhotkeys = true;
m_hotkeys = NULL;
if( choices != NULL ) if( choices != NULL )
ResyncBitmapOnly(); ResyncBitmapOnly();
} }
...@@ -32,31 +69,14 @@ LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id, ...@@ -32,31 +69,14 @@ LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id, LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
const wxArrayString& choices ) : const wxArrayString& choices ) :
LAYER_SELECTOR(),
wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ) wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY )
{ {
m_layerorder = true;
m_layerhotkeys = true;
m_hotkeys = NULL;
if( !choices.IsEmpty() ) if( !choices.IsEmpty() )
ResyncBitmapOnly(); ResyncBitmapOnly();
} }
bool LAYER_BOX_SELECTOR::SetLayersOrdered( bool value )
{
m_layerorder = value;
return m_layerorder;
}
bool LAYER_BOX_SELECTOR::SetLayersHotkeys( bool value )
{
m_layerhotkeys = value;
return m_layerhotkeys;
}
// Get Current Item # // Get Current Item #
int LAYER_BOX_SELECTOR::GetChoice() int LAYER_BOX_SELECTOR::GetChoice()
{ {
...@@ -104,21 +124,3 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly() ...@@ -104,21 +124,3 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
SetBitmapLayer( layerbmp, i ); SetBitmapLayer( layerbmp, i );
} }
} }
void LAYER_BOX_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
{
wxMemoryDC bmpDC;
wxBrush brush;
// Prepare Bitmap
bmpDC.SelectObject( aLayerbmp );
brush.SetColour( MakeColour( GetLayerColor( aLayer ) ) );
brush.SetStyle( wxSOLID );
bmpDC.SetBrush( brush );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
bmpDC.SetPen( *wxBLACK_PEN );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
}
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
class wxAuiToolBar; class wxAuiToolBar;
/* class to display a layer list. /* Basic class to build a layer list.
* * this is an basic abstract class to build a layer list selector.
* To display this list, you should therefore derive this class
*/ */
class LAYER_SELECTOR
class LAYER_BOX_SELECTOR : public wxBitmapComboBox
{ {
protected: protected:
bool m_layerhotkeys; bool m_layerhotkeys;
...@@ -24,14 +24,7 @@ public: ...@@ -24,14 +24,7 @@ public:
struct EDA_HOTKEY_CONFIG* m_hotkeys; struct EDA_HOTKEY_CONFIG* m_hotkeys;
public: public:
LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id, LAYER_SELECTOR();
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL );
LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
const wxArrayString& choices );
// Returns a color index from the layer id // Returns a color index from the layer id
// Virtual function because GerbView uses its own functions in a derived class // Virtual function because GerbView uses its own functions in a derived class
...@@ -45,7 +38,33 @@ public: ...@@ -45,7 +38,33 @@ public:
// Virtual function pure because GerbView uses its own functions in a derived class // Virtual function pure because GerbView uses its own functions in a derived class
virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0; virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0;
// Get Current Item # bool SetLayersOrdered(bool value);
bool SetLayersHotkeys(bool value);
protected:
// Fills the layer bitmap aLayerbmp with the layer color
void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer );
};
/* class to display a layer list in a wxBitmapComboBox.
*/
class LAYER_BOX_SELECTOR : public LAYER_SELECTOR, public wxBitmapComboBox
{
public:
// Hotkey Info
struct EDA_HOTKEY_CONFIG* m_hotkeys;
public:
LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL );
LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
const wxArrayString& choices );
// Get Current Item #
int GetChoice(); int GetChoice();
// Get Current Layer // Get Current Layer
...@@ -60,13 +79,6 @@ public: ...@@ -60,13 +79,6 @@ public:
// Reload the Layers bitmaps colors // Reload the Layers bitmaps colors
void ResyncBitmapOnly(); void ResyncBitmapOnly();
bool SetLayersOrdered(bool value);
bool SetLayersHotkeys(bool value);
protected:
// Fills the layer bitmap aLayerbmp with the layer color
void SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer );
}; };
#define DECLARE_LAYERS_HOTKEY(list) int list[NB_LAYERS] = \ #define DECLARE_LAYERS_HOTKEY(list) int list[NB_LAYERS] = \
......
...@@ -186,9 +186,14 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event ) ...@@ -186,9 +186,14 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
filename = openFileDialog.GetPath(); filename = openFileDialog.GetPath();
// Ensure the file has the right extension: // Ensure the file has the right extension:
// because a name like name.subname.subsubname is legal,
// add the right extension without replacing the wxFileName
// extension
wxFileName fn(filename); wxFileName fn(filename);
fn.SetExt( PageLayoutDescrFileExtension );
filename = fn.GetFullPath(); if( fn.GetExt() != PageLayoutDescrFileExtension )
filename << wxT(".") << PageLayoutDescrFileExtension;
if( !SavePageLayoutDescrFile( filename ) ) if( !SavePageLayoutDescrFile( filename ) )
{ {
wxString msg; wxString msg;
......
...@@ -76,6 +76,7 @@ set( PCBNEW_DIALOGS ...@@ -76,6 +76,7 @@ set( PCBNEW_DIALOGS
dialogs/dialog_global_deletion_base.cpp dialogs/dialog_global_deletion_base.cpp
dialogs/dialog_keepout_area_properties.cpp dialogs/dialog_keepout_area_properties.cpp
dialogs/dialog_keepout_area_properties_base.cpp dialogs/dialog_keepout_area_properties_base.cpp
dialogs/dialog_layer_selection_base.cpp
dialogs/dialog_layers_setup.cpp dialogs/dialog_layers_setup.cpp
dialogs/dialog_layers_setup_base.cpp dialogs/dialog_layers_setup_base.cpp
dialogs/dialog_netlist.cpp dialogs/dialog_netlist.cpp
......
...@@ -925,7 +925,15 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -925,7 +925,15 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER ); itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER );
if( itmp >= 0 ) if( itmp >= 0 )
{
// if user changed colors and we are in high contrast mode, then redraw
// because the PAD_SMD pads may change color.
if( DisplayOpt.ContrastModeDisplay && getActiveLayer() != itmp )
{
m_canvas->Refresh();
}
setActiveLayer( itmp ); setActiveLayer( itmp );
}
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
break; break;
......
/** /**
* @file sel_layer.cpp * @file sel_layer.cpp
* @brief Set up the basic primitives for Layer control. * @brief dialogs for one layer selection and a layer pair selection.
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/ */
#include <fctsys.h> #include <fctsys.h>
#include <common.h> #include <common.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <confirm.h> #include <confirm.h>
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <class_layer_box_selector.h>
#include <class_board.h> #include <class_board.h>
#include <dialogs/dialog_layer_selection_base.h>
enum layer_sel_id { /* classes to display a layer list using a wxGrid.
ID_LAYER_SELECT_TOP = 1800, */
ID_LAYER_SELECT_BOTTOM, class PCB_LAYER_SELECTOR: public LAYER_SELECTOR
ID_LAYER_SELECT
};
class SELECT_LAYER_DIALOG : public wxDialog
{ {
private: BOARD * m_brd;
PCB_BASE_FRAME* m_Parent;
wxRadioBox* m_LayerList;
LAYER_NUM m_LayerId[int(NB_PCB_LAYERS) + 1]; // One extra element for "(Deselect)" radiobutton
public: public:
// Constructor and destructor PCB_LAYER_SELECTOR( BOARD* aBrd ):LAYER_SELECTOR()
SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent, LAYER_NUM default_layer, {
LAYER_NUM min_layer, LAYER_NUM max_layer, bool null_layer ); m_brd = aBrd;
~SELECT_LAYER_DIALOG() { }; }
private:
void OnLayerSelected( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog ) protected:
EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected ) // Returns true if the layer id is enabled (i.e. is it should be displayed)
EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick ) bool IsLayerEnabled( LAYER_NUM aLayer ) const
EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected ) {
END_EVENT_TABLE() return m_brd->IsLayerEnabled( aLayer );
}
// Returns a color index from the layer id
// Virtual function
EDA_COLOR_T GetLayerColor( LAYER_NUM aLayer ) const
{
return m_brd->GetLayerColor( aLayer );
}
/** Install the dialog box for layer selection // Returns the name of the layer id
* @param default_layer = Preselection (NB_PCB_LAYERS for "(Deselect)" layer) // Virtual function
* @param min_layer = min layer value (-1 if no min value) wxString GetLayerName( LAYER_NUM aLayer ) const
* @param max_layer = max layer value (-1 if no max value) {
* @param null_layer = display a "(Deselect)" radiobutton (when set to true) return m_brd->GetLayerName( aLayer );
* @return new layer value (NB_PCB_LAYERS when "(Deselect)" radiobutton selected), }
* or -1 if canceled
*
* Providing the option to also display a "(Deselect)" radiobutton makes the
* "Swap Layers" command (and GerbView's "Export to Pcbnew" command) more "user
* friendly", by permitting any layer to be "deselected" immediately after its
* corresponding radiobutton has been clicked on. (It would otherwise be
* necessary to first cancel the "Select Layer:" dialog box (invoked after a
* different radiobutton is clicked on) prior to then clicking on the
* "Deselect"
* button provided within the "Swap Layers:" or "Layer selection:" dialog box).
*/
LAYER_NUM PCB_BASE_FRAME::SelectLayer( LAYER_NUM default_layer,
LAYER_NUM min_layer,
LAYER_NUM max_layer,
bool null_layer )
{
SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this,
default_layer,
min_layer,
max_layer,
null_layer );
LAYER_NUM layer = frame->ShowModal();
frame->Destroy();
return layer;
}
};
/* /*
* The "OK" and "Cancel" buttons are positioned (in a horizontal line) * This class display a pcb layers list in adialog,
* beneath the "Layer" radiobox, unless that contains only one column of * to select one layer from this list
* radiobuttons, in which case they are positioned (in a vertical line)
* to the right of that radiobox.
*/ */
SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent, class PCB_ONE_LAYER_SELECTOR : public PCB_LAYER_SELECTOR,
LAYER_NUM default_layer, LAYER_NUM min_layer, public DIALOG_LAYER_SELECTION_BASE
LAYER_NUM max_layer, bool null_layer ) :
wxDialog( parent, -1, _( "Select Layer:" ), wxPoint( -1, -1 ),
wxSize( 470, 250 ),
DIALOG_STYLE )
{ {
BOARD* board = parent->GetBoard(); LAYER_NUM m_layerSelected;
wxButton* Button; LAYER_NUM m_minLayer;
LAYER_NUM ii; LAYER_NUM m_maxLayer;
wxString LayerList[NB_PCB_LAYERS + 1]; // One extra element for "(Deselect)"
// radiobutton
int LayerCount, LayerSelect = -1;
m_Parent = parent;
// Build the layer list public:
LayerCount = 0; PCB_ONE_LAYER_SELECTOR( wxWindow* aParent, BOARD * aBrd,
LAYER_MSK Masque_Layer = g_TabAllCopperLayerMask[board->GetCopperLayerCount() - 1]; LAYER_NUM aDefaultLayer,
Masque_Layer |= ALL_NO_CU_LAYERS; LAYER_NUM aMinLayer = -1, LAYER_NUM aMaxLayer = -1,
bool aClearTool = false )
for( ii = FIRST_LAYER; ii < NB_PCB_LAYERS; ++ii ) :PCB_LAYER_SELECTOR( aBrd ), DIALOG_LAYER_SELECTION_BASE( aParent )
{
m_LayerId[ii] = FIRST_LAYER;
if( GetLayerMask( ii ) & Masque_Layer )
{ {
if( min_layer > ii ) m_layerSelected = (int) aDefaultLayer;
continue; // When not needed, remove the "Clear" button
m_buttonClear->Show( aClearTool );
m_minLayer = aMinLayer;
m_maxLayer = aMaxLayer;
BuildList();
Layout();
GetSizer()->SetSizeHints(this);
SetFocus();
}
if( ( max_layer >= 0 ) && ( max_layer < ii ) ) LAYER_NUM GetLayerSelection() { return m_layerSelected; }
break;
LayerList[LayerCount] = board->GetLayerName( ii ); private:
// Event handlers
void OnLeftGridClick( wxGridEvent& event );
void OnRightGridClick( wxGridEvent& event );
void OnClearSelection( wxCommandEvent& event )
{
m_layerSelected = NB_PCB_LAYERS;
EndModal( NB_PCB_LAYERS );
}
if( ii == default_layer ) void BuildList();
LayerSelect = LayerCount; };
m_LayerId[LayerCount] = ii; // Build the layers list
LayerCount++; // Column position by function:
} #define SELECT_COLNUM 0
} #define COLOR_COLNUM 1
#define LAYERNAME_COLNUM 2
#define LAYERID_COLNUM 3
static DECLARE_LAYERS_ORDER_LIST( layertranscode );
// When appropriate, also provide a "(Deselect)" radiobutton void PCB_ONE_LAYER_SELECTOR::BuildList()
if( null_layer ) {
m_leftGridLayers->SetColFormatNumber( LAYERID_COLNUM );
m_rightGridLayers->SetColFormatNumber( LAYERID_COLNUM );
m_leftGridLayers->HideCol( LAYERID_COLNUM );
m_rightGridLayers->HideCol( LAYERID_COLNUM );
m_leftGridLayers->SetColSize( COLOR_COLNUM, 20 );
m_rightGridLayers->SetColSize( COLOR_COLNUM, 20 );
// Select a not show cell, to avoid a wrong cell selection for user
m_leftGridLayers->GoToCell( 0, LAYERID_COLNUM );
m_rightGridLayers->GoToCell( 0, LAYERID_COLNUM );
int left_row = 0;
int right_row = 0;
wxString layernum;
wxString layername;
for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i )
{ {
LayerList[LayerCount] = _( "(Deselect)" ); LAYER_NUM layerid = i;
if( NB_PCB_LAYERS == default_layer )
LayerSelect = LayerCount;
m_LayerId[LayerCount] = NB_PCB_LAYERS; if( m_layerorder )
LayerCount++; layerid = layertranscode[i];
}
m_LayerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), if( ! IsLayerEnabled( layerid ) )
wxPoint( -1, -1 ), wxSize( -1, -1 ), continue;
LayerCount, LayerList,
(LayerCount < 8) ? LayerCount : 8,
wxRA_SPECIFY_ROWS );
if( LayerSelect >= 0 ) if( m_minLayer >= 0 && layerid < m_minLayer )
m_LayerList->SetSelection( LayerSelect ); continue;
wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL ); if( m_maxLayer >= 0 && layerid > m_maxLayer )
SetSizer( FrameBoxSizer ); continue;
FrameBoxSizer->Add( m_LayerList, 0, wxALIGN_TOP | wxALL, 5 );
wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
Button = new wxButton( this, wxID_OK, _( "OK" ) ); wxColour color = MakeColour( GetLayerColor( layerid ) );
Button->SetDefault(); layername = GetLayerName( layerid );
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); layernum.Printf( wxT("%d"), layerid );
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) ); if( layerid <= LAST_COPPER_LAYER )
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); {
if( left_row )
m_leftGridLayers->AppendRows( 1 );
m_leftGridLayers->SetCellBackgroundColour ( left_row, COLOR_COLNUM,
color );
m_leftGridLayers->SetCellValue( left_row, LAYERNAME_COLNUM,
layername );
m_leftGridLayers->SetCellValue( left_row, LAYERID_COLNUM,
layernum );
if( m_layerSelected == layerid )
{
m_leftGridLayers->SetCellValue( left_row, SELECT_COLNUM,
wxT("X") );
m_leftGridLayers->SetCellBackgroundColour ( left_row, SELECT_COLNUM,
color );
}
left_row++;
}
else
{
if( right_row )
m_rightGridLayers->AppendRows( 1 );
m_rightGridLayers->SetCellBackgroundColour ( right_row, COLOR_COLNUM,
color );
m_rightGridLayers->SetCellValue( right_row, LAYERNAME_COLNUM,
layername );
m_rightGridLayers->SetCellValue( right_row, LAYERID_COLNUM,
layernum );
if( m_layerSelected == layerid )
{
m_rightGridLayers->SetCellValue( right_row, SELECT_COLNUM,
wxT("X") );
m_rightGridLayers->SetCellBackgroundColour ( right_row, SELECT_COLNUM,
color );
}
right_row++;
}
}
SetFocus(); // Show only populated lists:
if( left_row <= 0 )
m_leftGridLayers->Show( false );
GetSizer()->SetSizeHints( this ); if( right_row <= 0 )
m_rightGridLayers->Show( false );
Center(); m_leftGridLayers->AutoSizeColumn(LAYERNAME_COLNUM);
m_rightGridLayers->AutoSizeColumn(LAYERNAME_COLNUM);
m_leftGridLayers->AutoSizeColumn(SELECT_COLNUM);
m_rightGridLayers->AutoSizeColumn(SELECT_COLNUM);
} }
void PCB_ONE_LAYER_SELECTOR::OnLeftGridClick( wxGridEvent& event )
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
{ {
int ii = m_LayerId[m_LayerList->GetSelection()]; wxString text = m_leftGridLayers->GetCellValue(event.GetRow(), LAYERID_COLNUM);
long layer;
EndModal( ii ); text.ToLong( &layer );
m_layerSelected = layer;
EndModal( 1 );
} }
void PCB_ONE_LAYER_SELECTOR::OnRightGridClick( wxGridEvent& event )
void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
{ {
EndModal( -1 ); wxString text = m_rightGridLayers->GetCellValue(event.GetRow(), LAYERID_COLNUM);
long layer;
text.ToLong( &layer );
m_layerSelected = layer;
EndModal( 2 );
} }
/** Install the dialog box for layer selection
* @param aDefaultLayer = Preselection (NB_PCB_LAYERS for "(Deselect)" layer)
* @param aMinlayer = min layer id value (-1 if no min value)
* @param aMaxLayer = max layer id value (-1 if no max value)
* @param aDeselectTool = display a "Clear" button when true
* @return new layer value (NB_PCB_LAYERS when "(Deselect)" radiobutton selected),
* or -1 if canceled
*
* Providing the option to also display a "Clear" button makes the
* "Swap Layers" command more "user friendly",
* by permitting any layer to be "deselected" immediately after its
* corresponding radiobutton has been clicked on. (It would otherwise be
* necessary to first cancel the "Select Layer:" dialog box (invoked after a
* different radiobutton is clicked on) prior to then clicking on the
* "Clear" button provided within the "Swap Layers:"
* or "Layer selection:" dialog box).
*/
LAYER_NUM PCB_BASE_FRAME::SelectLayer( LAYER_NUM aDefaultLayer,
LAYER_NUM aMinlayer,
LAYER_NUM aMaxLayer,
bool aDeselectTool )
{
PCB_ONE_LAYER_SELECTOR dlg( this, GetBoard(),
aDefaultLayer, aMinlayer, aMaxLayer,
aDeselectTool );
dlg.ShowModal();
LAYER_NUM layer = dlg.GetLayerSelection();
return layer;
}
/*********************************************/
/* Dialog for the selecting pairs of layers. */
/*********************************************/
class SELECT_LAYERS_PAIR_DIALOG : public wxDialog /*
* This class display a double pcb copper layers list in a dialog,
* to select a layer pair from this list
*/
class SELECT_COPPER_LAYERS_PAIR_DIALOG: public PCB_LAYER_SELECTOR,
public DIALOG_COPPER_LAYER_PAIR_SELECTION_BASE
{ {
private: private:
PCB_BASE_FRAME* m_Parent; BOARD* m_brd;
wxRadioBox* m_LayerListTOP; LAYER_NUM m_frontLayer;
wxRadioBox* m_LayerListBOTTOM; LAYER_NUM m_backLayer;
LAYER_NUM m_LayerId[NB_COPPER_LAYERS]; int m_leftRowSelected;
int m_rightRowSelected;
public:
SELECT_COPPER_LAYERS_PAIR_DIALOG( wxWindow* aParent, BOARD * aPcb,
LAYER_NUM aFrontLayer, LAYER_NUM aBackLayer );
public: SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent ); void GetLayerPair( LAYER_NUM& aFrontLayer, LAYER_NUM& aBackLayer )
~SELECT_LAYERS_PAIR_DIALOG() { }; {
aFrontLayer = m_frontLayer;
aBackLayer = m_backLayer;
}
private: private:
void OnOkClick( wxCommandEvent& event ); void OnLeftGridClick( wxGridEvent& event );
void OnCancelClick( wxCommandEvent& event ); void OnRightGridClick( wxGridEvent& event );
DECLARE_EVENT_TABLE() void OnOkClick( wxCommandEvent& event )
}; {
EndModal( wxID_OK );
}
void OnCancelClick( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
}
BEGIN_EVENT_TABLE( SELECT_LAYERS_PAIR_DIALOG, wxDialog ) void BuildList();
EVT_BUTTON( wxID_OK, SELECT_LAYERS_PAIR_DIALOG::OnOkClick )
EVT_BUTTON( wxID_CANCEL, SELECT_LAYERS_PAIR_DIALOG::OnCancelClick )
END_EVENT_TABLE()
};
/* Display a list of two copper layers for selection of a pair of layers /* Display a list of two copper layers to choose a pair of layers
* for auto-routing, vias ... * for auto-routing, vias ...
*/ */
void PCB_BASE_FRAME::SelectLayerPair() void PCB_BASE_FRAME::SelectLayerPair()
{ {
// Check whether more than one copper layer has been enabled for the PCB_SCREEN* screen = GetScreen();
// current PCB file, as Layer Pairs can only meaningfully be defined SELECT_COPPER_LAYERS_PAIR_DIALOG dlg( this, GetBoard(),
// within PCB files which contain at least two copper layers. screen->m_Route_Layer_TOP,
if( GetBoard()->GetCopperLayerCount() < 2 ) screen->m_Route_Layer_BOTTOM );
if( dlg.ShowModal() == wxID_OK )
{ {
wxString InfoMsg; dlg.GetLayerPair( screen->m_Route_Layer_TOP, screen->m_Route_Layer_BOTTOM );
InfoMsg = _( "Less than two copper layers are being used." );
InfoMsg << wxT( "\n" ) << _( "Hence layer pairs cannot be specified." );
DisplayInfoMessage( this, InfoMsg );
return;
}
SELECT_LAYERS_PAIR_DIALOG* frame = new SELECT_LAYERS_PAIR_DIALOG( this ); // select the same layer for both layers is allowed (normal in some boards)
// but could be a mistake. So display an info message
if( screen->m_Route_Layer_TOP == screen->m_Route_Layer_BOTTOM )
DisplayInfoMessage( this,
_( "Warning: The Top Layer and Bottom Layer are same." ) );
}
int result = frame->ShowModal();
frame->Destroy();
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
// if user changed colors and we are in high contrast mode, then redraw
// because the PAD_SMD pads may change color.
if( result >= 0 && DisplayOpt.ContrastModeDisplay )
{
m_canvas->Refresh();
}
} }
SELECT_COPPER_LAYERS_PAIR_DIALOG::
SELECT_LAYERS_PAIR_DIALOG::SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent ) : SELECT_COPPER_LAYERS_PAIR_DIALOG( wxWindow* aParent, BOARD * aPcb,
wxDialog( parent, -1, _( "Select Layer Pair:" ), wxPoint( -1, -1 ), LAYER_NUM aFrontLayer, LAYER_NUM aBackLayer) :
wxSize( 470, 250 ), DIALOG_STYLE ) PCB_LAYER_SELECTOR( aPcb ),
DIALOG_COPPER_LAYER_PAIR_SELECTION_BASE( aParent )
{ {
BOARD* board = parent->GetBoard(); m_frontLayer = aFrontLayer;
wxButton* Button; m_backLayer = aBackLayer;
wxString LayerList[NB_COPPER_LAYERS]; m_leftRowSelected = 0;
LAYER_NUM LayerTopSelect = FIRST_LAYER, LayerBottomSelect = FIRST_LAYER; m_rightRowSelected = 0;
BuildList();
SetFocus();
GetSizer()->SetSizeHints( this );
Center();
}
m_Parent = parent; void SELECT_COPPER_LAYERS_PAIR_DIALOG::BuildList()
{
m_leftGridLayers->SetColFormatNumber( LAYERID_COLNUM );
m_rightGridLayers->SetColFormatNumber( LAYERID_COLNUM );
m_leftGridLayers->HideCol( LAYERID_COLNUM );
m_rightGridLayers->HideCol( LAYERID_COLNUM );
m_leftGridLayers->SetColSize( COLOR_COLNUM, 20 );
m_rightGridLayers->SetColSize( COLOR_COLNUM, 20 );
// Select a not show cell, to avoid a wrong cell selection for user
m_leftGridLayers->GoToCell( 0, LAYERID_COLNUM );
m_rightGridLayers->GoToCell( 0, LAYERID_COLNUM );
int row = 0;
wxString layernum;
wxString layername;
for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i )
{
LAYER_NUM layerid = i;
PCB_SCREEN* screen = (PCB_SCREEN*) m_Parent->GetScreen(); if( m_layerorder )
LAYER_MSK Masque_Layer = g_TabAllCopperLayerMask[board->GetCopperLayerCount() - 1]; layerid = layertranscode[i];
Masque_Layer |= ALL_NO_CU_LAYERS;
LAYER_NUM LayerCount = FIRST_LAYER; if( ! IsLayerEnabled( layerid ) )
for( LAYER_NUM ii = FIRST_COPPER_LAYER; ii < NB_COPPER_LAYERS; ++ii ) continue;
{
m_LayerId[ii] = FIRST_LAYER;
if( (GetLayerMask( ii ) & Masque_Layer) ) if( layerid > LAST_COPPER_LAYER )
{ continue;
LayerList[LayerCount] = board->GetLayerName( ii );
if( ii == screen->m_Route_Layer_TOP ) wxColour color = MakeColour( GetLayerColor( layerid ) );
LayerTopSelect = LayerCount; layername = GetLayerName( layerid );
layernum.Printf( wxT("%d"), layerid );
if( ii == screen->m_Route_Layer_BOTTOM ) if( row )
LayerBottomSelect = LayerCount; m_leftGridLayers->AppendRows( 1 );
m_leftGridLayers->SetCellBackgroundColour ( row, COLOR_COLNUM,
color );
m_leftGridLayers->SetCellValue( row, LAYERNAME_COLNUM,
layername );
m_leftGridLayers->SetCellValue( row, LAYERID_COLNUM,
layernum );
m_LayerId[LayerCount] = ii; if( m_frontLayer == layerid )
++LayerCount; {
m_leftGridLayers->SetCellValue( row, SELECT_COLNUM,
wxT("X") );
m_leftGridLayers->SetCellBackgroundColour( row, SELECT_COLNUM,
color );
m_leftRowSelected = row;
} }
}
m_LayerListTOP = new wxRadioBox( this, ID_LAYER_SELECT_TOP, if( row )
_( "Top Layer" ), m_rightGridLayers->AppendRows( 1 );
wxPoint( -1, -1 ), wxSize( -1, -1 ), m_rightGridLayers->SetCellBackgroundColour ( row, COLOR_COLNUM,
LayerCount, LayerList, color );
(LayerCount < 8) ? LayerCount : 8, m_rightGridLayers->SetCellValue( row, LAYERNAME_COLNUM,
wxRA_SPECIFY_ROWS ); layername );
m_LayerListTOP->SetSelection( LayerTopSelect ); m_rightGridLayers->SetCellValue( row, LAYERID_COLNUM,
layernum );
m_LayerListBOTTOM = new wxRadioBox( this, ID_LAYER_SELECT_BOTTOM, if( m_backLayer == layerid )
_( "Bottom Layer" ), {
wxPoint( -1, -1 ), wxSize( -1, -1 ), m_rightGridLayers->SetCellValue( row, SELECT_COLNUM,
LayerCount, LayerList, wxT("X") );
(LayerCount < 8) ? LayerCount : 8, m_rightGridLayers->SetCellBackgroundColour ( row, SELECT_COLNUM,
wxRA_SPECIFY_ROWS ); color );
m_LayerListBOTTOM->SetSelection( LayerBottomSelect ); m_rightRowSelected = row;
}
wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxVERTICAL ); row++;
SetSizer( FrameBoxSizer ); }
wxBoxSizer* RadioBoxSizer = new wxBoxSizer( wxHORIZONTAL ); m_leftGridLayers->AutoSizeColumn(LAYERNAME_COLNUM);
FrameBoxSizer->Add( RadioBoxSizer, 0, wxALIGN_LEFT | wxALL, 0 ); m_rightGridLayers->AutoSizeColumn(LAYERNAME_COLNUM);
m_leftGridLayers->AutoSizeColumn(SELECT_COLNUM);
m_rightGridLayers->AutoSizeColumn(SELECT_COLNUM);
}
wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxHORIZONTAL ); void SELECT_COPPER_LAYERS_PAIR_DIALOG::OnLeftGridClick( wxGridEvent& event )
FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_RIGHT | wxALL, 0 ); {
int row = event.GetRow();
wxString text = m_leftGridLayers->GetCellValue( row, LAYERID_COLNUM );
long layer;
text.ToLong( &layer );
RadioBoxSizer->Add( m_LayerListTOP, 0, wxALIGN_TOP | wxALL, 5 ); if( m_frontLayer == layer )
RadioBoxSizer->Add( m_LayerListBOTTOM, 0, wxALIGN_TOP | wxALL, 5 ); return;
Button = new wxButton( this, wxID_OK, _( "OK" ) ); m_leftGridLayers->SetCellValue( m_leftRowSelected, SELECT_COLNUM,
Button->SetDefault(); wxEmptyString );
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); m_leftGridLayers->SetCellBackgroundColour ( m_leftRowSelected, SELECT_COLNUM,
m_leftGridLayers->GetDefaultCellBackgroundColour() );
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) ); m_frontLayer = layer;
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); m_leftRowSelected = row;
SetFocus(); m_leftGridLayers->SetCellValue( row, SELECT_COLNUM,
wxT("X") );
m_leftGridLayers->SetCellBackgroundColour( row, SELECT_COLNUM,
MakeColour( GetLayerColor( layer ) ) );
GetSizer()->SetSizeHints( this );
Center();
} }
void SELECT_COPPER_LAYERS_PAIR_DIALOG::OnRightGridClick( wxGridEvent& event )
void SELECT_LAYERS_PAIR_DIALOG::OnOkClick( wxCommandEvent& event )
{ {
// select the same layer for top and bottom is allowed (normal in some int row = event.GetRow();
// boards) wxString text = m_rightGridLayers->GetCellValue( row, LAYERID_COLNUM );
// but could be a mistake. So display an info message long layer;
if( m_LayerId[m_LayerListTOP->GetSelection()] == m_LayerId[m_LayerListBOTTOM->GetSelection()] ) text.ToLong( &layer );
DisplayInfoMessage( this,
_( "Warning: The Top Layer and Bottom Layer are same." ) );
PCB_SCREEN* screen = (PCB_SCREEN*) m_Parent->GetScreen();
screen->m_Route_Layer_TOP = m_LayerId[m_LayerListTOP->GetSelection()];
screen->m_Route_Layer_BOTTOM = m_LayerId[m_LayerListBOTTOM->GetSelection()];
EndModal( 0 );
}
if( m_backLayer == layer )
return;
void SELECT_LAYERS_PAIR_DIALOG::OnCancelClick( wxCommandEvent& event ) m_rightGridLayers->SetCellValue( m_rightRowSelected, SELECT_COLNUM,
{ wxEmptyString );
EndModal( -1 ); m_rightGridLayers->SetCellBackgroundColour ( m_rightRowSelected, SELECT_COLNUM,
m_rightGridLayers->GetDefaultCellBackgroundColour() );
m_backLayer = layer;
m_rightRowSelected = row;
m_rightGridLayers->SetCellValue( row, SELECT_COLNUM,
wxT("X") );
m_rightGridLayers->SetCellBackgroundColour ( row, SELECT_COLNUM,
MakeColour( GetLayerColor( layer ) ) );
} }
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