Commit b7b972d8 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Rework on layer box selector, to use it in dialogs (currently the active layer...

Rework on layer box selector, to use it in dialogs (currently the active layer selector, the layer pair selector and the dimension editor dialog.
This rework solves Bug #1214545.
Work in progress: many dialogs do not yet use the layer box selector.
parents 93eeb75c 902e5cce
Loading
Loading
Loading
Loading
+43 −44
Original line number Diff line number Diff line
@@ -7,53 +7,70 @@
#include <wx/wx.h>
#include <wx/ownerdrw.h>
#include <wx/menuitem.h>
#include <wx/aui/aui.h>

#include <class_layer_box_selector.h>

/* class to display a layer list.
 *
 */

LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
                                        const wxPoint& pos, const wxSize& size,
                                        int n, const wxString choices[] ) :
    wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY )
LAYER_SELECTOR::LAYER_SELECTOR()
{
    m_layerorder   = true;
    m_layerhotkeys = true;
    m_hotkeys      = NULL;

    if( choices != NULL )
        ResyncBitmapOnly();
}


LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
                                        const wxPoint& pos, const wxSize& size,
                                        const wxArrayString& choices ) :
    wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY )
bool LAYER_SELECTOR::SetLayersOrdered( bool value )
{
    m_layerorder   = true;
    m_layerhotkeys = true;
    m_hotkeys      = NULL;
    m_layerorder = value;
    return m_layerorder;
}

    if( !choices.IsEmpty() )
        ResyncBitmapOnly();

bool LAYER_SELECTOR::SetLayersHotkeys( bool value )
{
    m_layerhotkeys = value;
    return m_layerhotkeys;
}


bool LAYER_BOX_SELECTOR::SetLayersOrdered( bool value )
void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
{
    m_layerorder = value;
    return m_layerorder;
    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 in a wxBitmapComboBox.
 */
LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( 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 ),
    LAYER_SELECTOR()
{
    if( choices != NULL )
        ResyncBitmapOnly();
}

bool LAYER_BOX_SELECTOR::SetLayersHotkeys( bool value )

LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
                                        const wxPoint& pos, const wxSize& size,
                                        const wxArrayString& choices ) :
    wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
    LAYER_SELECTOR()
{
    m_layerhotkeys = value;
    return m_layerhotkeys;
    if( !choices.IsEmpty() )
        ResyncBitmapOnly();
}


@@ -104,21 +121,3 @@ void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
        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() );
}
+0 −6
Original line number Diff line number Diff line
@@ -32,14 +32,8 @@
#include <common.h>
#include <colors_selection.h>
#include <layers_id_colors_and_visibility.h>

#include <gerbview_frame.h>

#include <wx/ownerdrw.h>
#include <wx/menuitem.h>
#include <wx/bmpcbox.h>
#include <wx/wx.h>

#include <class_gbr_layer_box_selector.h>

void GBR_LAYER_BOX_SELECTOR::Resync()
+2 −15
Original line number Diff line number Diff line
@@ -4,14 +4,11 @@
#include <class_layer_box_selector.h>


/* class to display a layer list in GerbView.
 *
 */

// class to display a layer list in GerbView.
class GBR_LAYER_BOX_SELECTOR : public LAYER_BOX_SELECTOR
{
public:
    GBR_LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
    GBR_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        int n = 0, const wxString choices[] = NULL )
@@ -21,16 +18,6 @@ public:
            m_layerorder = false;
        }

    GBR_LAYER_BOX_SELECTOR( wxAuiToolBar* parent, wxWindowID id,
                        const wxPoint& pos, const wxSize& size,
                        const wxArrayString& choices )
        :LAYER_BOX_SELECTOR( parent, id, pos, size, choices )
        {
            m_layerhotkeys = false;
            m_layerorder = false;
        }


    // Reload the Layers names and bitmaps
    // Virtual function
    void Resync();
+34 −24
Original line number Diff line number Diff line
#ifndef CLASS_LAYER_BOX_SELECTOR_H
#define CLASS_LAYER_BOX_SELECTOR_H 1

#include <hotkeys_basic.h>
#include <wx/bmpcbox.h>
#include <colors.h>     // EDA_COLOR_T definition
#include <layers_id_colors_and_visibility.h>

class EDA_HOTKEY_CONFIG;

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_BOX_SELECTOR : public wxBitmapComboBox
class LAYER_SELECTOR
{
protected:
    bool m_layerhotkeys;
@@ -24,14 +22,7 @@ public:
    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 );
    LAYER_SELECTOR();

    // Returns a color index from the layer id
    // Virtual function because GerbView uses its own functions in a derived class
@@ -45,6 +36,32 @@ public:
    // Virtual function pure because GerbView uses its own functions in a derived class
    virtual bool IsLayerEnabled( LAYER_NUM aLayer ) const = 0;

    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 wxBitmapComboBox, public LAYER_SELECTOR
{
public:
    // Hotkey Info
    struct EDA_HOTKEY_CONFIG* m_hotkeys;

public:
    LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        int n = 0, const wxString choices[] = NULL );

    LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
                        const wxPoint& pos, const wxSize& size,
                        const wxArrayString& choices );

    // Get Current Item #
    int GetChoice();

@@ -60,13 +77,6 @@ public:

    // Reload the Layers bitmaps colors
    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] = \
+9 −1
Original line number Diff line number Diff line
@@ -542,7 +542,15 @@ public:
    void ReCreateMicrowaveVToolbar();
    void ReCreateOptToolbar();
    void ReCreateMenuBar();
    PCB_LAYER_BOX_SELECTOR* ReCreateLayerBox( wxAuiToolBar* parent );

    /**
     * Re create the layer Box by clearing the old list, and building
     * le new one, from the new layers names and cole layers
     * @param aForceResizeToolbar = true to resize the parent toolbar
     * false if not needed (mainly in parent toolbar creation,
     * or when the layers names are not modified)
     */
    void ReCreateLayerBox( bool aForceResizeToolbar = true );

    /**
     * Function OnModify
Loading