← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Refactor LAYER_ID to be the one and only layer definition

 

Hi Wayne, new patch attached.

Thanks,
Jon

On Tue, Mar 21, 2017 at 9:28 AM, Wayne Stambaugh <stambaughw@xxxxxxxxx>
wrote:

> Jon,
>
> I just attempted to apply your patch and it no longer applies cleanly.
> Please rebase it when you get a chance.
>
> Thanks,
>
> Wayne
>
> On 3/16/2017 10:14 AM, Jon Evans wrote:
> > Bump -- does anyone have time to look at this and report back if there
> > are any issues?  I'd like to get it merged so that I can feel confident
> > about doing more work on top of these changes.
> >
> > Thanks,
> > Jon
> >
> > On Tue, Mar 14, 2017 at 6:05 PM, Wayne Stambaugh <stambaughw@xxxxxxxxx
> > <mailto:stambaughw@xxxxxxxxx>> wrote:
> >
> >     Hey Jon,
> >
> >     This is better than the giant enum concept and I'm willing to accept
> >     this.  It still lacks the type safety of the enum inheritance
> solution.
> >     I still see ints being cast to enums and enum bounds checking so
> this is
> >     less than ideal.  I would prefer to see some additional testing so if
> >     any one has time, please test this patch before we commit it.
> >
> >     Thanks,
> >
> >     Wayne
> >
> >     On 3/14/2017 3:09 PM, Jon Evans wrote:
> >     > Hi Wayne,
> >     >
> >     > New patch attached.  Let me know what you think of this approach.
> >     >
> >     > Thanks,
> >     > Jon
> >     >
> >     > On Tue, Mar 14, 2017 at 10:40 AM, Jon Evans <jon@xxxxxxxxxxxxx
> <mailto:jon@xxxxxxxxxxxxx>
> >     > <mailto:jon@xxxxxxxxxxxxx <mailto:jon@xxxxxxxxxxxxx>>> wrote:
> >     >
> >     >     Hi John, that's basically what my first patch did, but inside
> >     one enum.
> >     >
> >     >     Hi Wayne, thanks for elaborating more, I see your point.
> >     >
> >     >     I am still not sure there is benefit to adding some class to
> >     handle
> >     >     enum inheritance.
> >     >     I think it would work fine to just chain multiple enums
> >     together, as
> >     >     was done before, but with some tweaks.
> >     >
> >     >     enum PCB_LAYER_ID
> >     >     {
> >     >         F_Cu = 0,
> >     >         //...
> >     >         PCB_LAYER_ID_COUNT
> >     >     };
> >     >
> >     >     enum NETNAME_LAYER_ID
> >     >     {
> >     >         NETNAME_LAYER_ID_START = PCB_LAYER_ID_COUNT,
> >     >         NETNAME_LAYER_ID_COUNT = NETNAME_LAYER_ID_START +
> >     PCB_LAYER_ID_COUNT
> >     >     };
> >     >
> >     >     enum GAL_LAYER_ID
> >     >     {
> >     >         GAL_LAYER_ID_START = NETNAME_LAYER_ID_COUNT,
> >     >         //....
> >     >     };
> >     >
> >     >     And so on for gerbview, eeschema, etc
> >     >
> >     >     That way the IDs will be unique and cover a contiguous range,
> so
> >     >     functions that want to take any layer ID can just check that
> >     the ID
> >     >     is >= 0 and < the end sentinel of the last enum.
> >     >
> >     >     Any concerns with this approach?
> >     >
> >     >
> >     >     Best,
> >     >     Jon
> >     >
> >     >     On Tue, Mar 14, 2017 at 10:29 AM, John Beard
> >     <john.j.beard@xxxxxxxxx <mailto:john.j.beard@xxxxxxxxx>
> >     >     <mailto:john.j.beard@xxxxxxxxx
> >     <mailto:john.j.beard@xxxxxxxxx>>> wrote:
> >     >
> >     >         Hi Jon,
> >     >
> >     >         Protocol Buffers has the same problem. Messages have a
> >     unique number
> >     >         for each field, but extensions to messages don't know about
> >     >         "siblings". A common thing [1] to so is reserve IDs up to
> 1000
> >     >         for the
> >     >         base message, and then messages start at offsets 1000,
> >     2000, etc,
> >     >         based on some in-house scheme.
> >     >
> >     >         It probably won't just "drop in" to KiCad due to fixed
> >     arrays (I
> >     >         think?), but this is certainly one way it has been
> >     "solved" in the
> >     >         real world, by Google, no less! It's a bit crusty to
> manually
> >     >         reserve
> >     >         space, but the "enum inheritance" problem isn't limited to
> >     C++.
> >     >
> >     >         There's plenty of space in enums and I sincerely doubt
> >     there is a
> >     >         measurable benefit to forcing the compiler to use shorter
> >     integral
> >     >         types anyway, so we could just say "0-9999" is "common
> GAL",
> >     >         "10000-19999" is Pcbnew, etc. Some work might be needed to
> >     handle
> >     >         non-contiguous enums here. "10000 layers should be enough
> for
> >     >         anyone",
> >     >         right?
> >     >
> >     >         Just a thought, without any real consideration of the
> >     >         consequences for
> >     >         things like formats and so on.
> >     >
> >     >         Cheers,
> >     >
> >     >         John
> >     >
> >     >         [1]
> >     >
> >      https://developers.google.com/protocol-buffers/docs/proto#
> choosing-extension-numbers
> >     <https://developers.google.com/protocol-buffers/docs/
> proto#choosing-extension-numbers>
> >     >
> >      <https://developers.google.com/protocol-buffers/docs/
> proto#choosing-extension-numbers
> >     <https://developers.google.com/protocol-buffers/docs/
> proto#choosing-extension-numbers>>
> >     >
> >     >         On Tue, Mar 14, 2017 at 10:08 PM, Jon Evans
> >     <jon@xxxxxxxxxxxxx <mailto:jon@xxxxxxxxxxxxx>
> >     >         <mailto:jon@xxxxxxxxxxxxx <mailto:jon@xxxxxxxxxxxxx>>>
> wrote:
> >     >         > Hi Orson, Wayne,
> >     >         >
> >     >         > I looked at the "enum inheritance" thing some more and I
> >     don't
> >     >         think it
> >     >         > would be a good solution for our case.
> >     >         >
> >     >         > This technique lets you extend enum A with enum B, and
> have
> >     >         functions f(A)
> >     >         > and f(A or B), and you could continue making larger
> >     enums that
> >     >         contained
> >     >         > smaller ones.
> >     >         > But, if we maintain multiple enums (one for each
> >     application,
> >     >         plus one for
> >     >         > GAL layers) I don't see how it would make anything
> simpler,
> >     >         because we would
> >     >         > not be able to treat them as "sibling classes"
> >     >         >
> >     >         > Before I spend more time coding things I want to get an
> idea
> >     >         of what your
> >     >         > requirements are / what you would and would not accept
> as a
> >     >         change in this
> >     >         > area.  I misunderstood Wayne's earlier reply to me and
> >     thought
> >     >         that a single
> >     >         > enum would be accepted, but if not, I don't currently
> >     have a good
> >     >         > understanding of what the concerns are with that
> approach.
> >     >         >
> >     >         > Questions for Wayne, Orson, and others who care about
> this:
> >     >         >
> >     >         > 1) Is there any opposition to moving the layer
> definitions
> >     >         from GerbView and
> >     >         > Eeschema into layers_id_colors_and_visibility.h?
> (ignoring
> >     >         whether they are
> >     >         > merged into one enum for now)
> >     >         >
> >     >         > 2) Is there any opposition to ensuring that no layer IDs
> >     >         overlap across all
> >     >         > applications?  To be clear, what I mean now is that
> >     currently
> >     >         GerbView draw
> >     >         > layers occupy the same layer IDs as Pcbnew board
> layers.  I
> >     >         want to change
> >     >         > it so that a layer ID (cast to integer) is always unique
> >     >         across all
> >     >         > applications, unless it truly is the same layer (i.e can
> use
> >     >         the same color
> >     >         > settings, visibility settings, etc. as GP_OVERLAY can
> across
> >     >         > GerbView/Pcbnew).
> >     >         >
> >     >         > 3) If the answers to both 1 and 2 are "no", can you give
> >     some
> >     >         more details
> >     >         > on why it's a bad idea to put all the layers in the same
> >     enum,
> >     >         and based on
> >     >         > that I will come back with a proposal on a different way
> of
> >     >         doing it?
> >     >         >
> >     >         > Thanks,
> >     >         > Jon
> >     >         >
> >     >         > On Mon, Mar 13, 2017 at 3:07 PM, Jon Evans
> >     <jon@xxxxxxxxxxxxx <mailto:jon@xxxxxxxxxxxxx>
> >     >         <mailto:jon@xxxxxxxxxxxxx <mailto:jon@xxxxxxxxxxxxx>>>
> wrote:
> >     >         >>
> >     >         >> Hi Orson,
> >     >         >>
> >     >         >> It's an interesting idea, I will have to look at it
> more.
> >     >         But, doesn't
> >     >         >> this still allow the programmer to accidentally overlap
> two
> >     >         enum values?  I
> >     >         >> can add checks to prevent this from happening elsewhere
> in
> >     >         the code, but it
> >     >         >> seems less clean to me.
> >     >         >>
> >     >         >> Best,
> >     >         >> -Jon
> >     >         >>
> >     >         >> On Mon, Mar 13, 2017 at 1:52 PM, Maciej Suminski
> >     >         <maciej.suminski@xxxxxxx <mailto:maciej.suminski@xxxxxxx>
> >     <mailto:maciej.suminski@xxxxxxx <mailto:maciej.suminski@xxxxxxx>>>
> >     >         >> wrote:
> >     >         >>>
> >     >         >>> Hi,
> >     >         >>>
> >     >         >>> How about emulating enum inheritance [1]? I suppose it
> >     would
> >     >         be the
> >     >         >>> cleanest solution allowing us to clearly specify what
> kind
> >     >         of layer is
> >     >         >>> expected for certain methods. This is even better kind
> of
> >     >         type checking.
> >     >         >>>
> >     >         >>> Cheers,
> >     >         >>> Orson
> >     >         >>>
> >     >         >>> 1. https://www.codeproject.com/kb/cpp/inheritenum.aspx
> >     <https://www.codeproject.com/kb/cpp/inheritenum.aspx>
> >     >         <https://www.codeproject.com/kb/cpp/inheritenum.aspx
> >     <https://www.codeproject.com/kb/cpp/inheritenum.aspx>>
> >     >         >>>
> >     >         >>> On 03/13/2017 02:50 PM, Jon Evans wrote:
> >     >         >>> > Hi Wayne,
> >     >         >>> >
> >     >         >>> > I understand this might seem like too big a change.
> >     >         >>> > Here is what I was thinking when I thought that
> >     combining
> >     >         everything
> >     >         >>> > would
> >     >         >>> > be a good solution.
> >     >         >>> >
> >     >         >>> > - If there is more than one enum, then functions that
> >     >         consume data from
> >     >         >>> > more than one app (i.e. things in common/GAL) have
> >     to cast
> >     >         to int, so
> >     >         >>> > you
> >     >         >>> > lose type checking that the enum gives you for free
> (or
> >     >         your type
> >     >         >>> > checking
> >     >         >>> > gets more complicated, because the range of valid
> values
> >     >         is different
> >     >         >>> > for
> >     >         >>> > each application)
> >     >         >>> >
> >     >         >>> > - If there is more than one enum, it's easier to
> >     duplicate
> >     >         layers for
> >     >         >>> > no
> >     >         >>> > good reason (i.e. GerbView and Pcbnew have different
> >     layer
> >     >         ids for
> >     >         >>> > "grid"
> >     >         >>> > right now)
> >     >         >>> >
> >     >         >>> > - I want to combine the color settings for all
> >     >         applications under the
> >     >         >>> > hood
> >     >         >>> > (users will still be able to configure different
> colors
> >     >         for each
> >     >         >>> > application).  This change will let color settings
> take
> >     >         LAYER_ID
> >     >         >>> > instead of
> >     >         >>> > int, and there will only be one key/value mapping of
> >     >         colors -- no more
> >     >         >>> > difference between "GetLayerColor" and
> "GetItemColor".
> >     >         There will be
> >     >         >>> > no
> >     >         >>> > clashes between the meaning of a layer id (int type)
> >     >         between different
> >     >         >>> > applications.
> >     >         >>> >
> >     >         >>> > - Bringing Eeschema into this now is just early
> >     groundwork
> >     >         for Eeschema
> >     >         >>> > GAL
> >     >         >>> > port (as well as unified color settings)
> >     >         >>> >
> >     >         >>> > If you will not accept this change, I have to think
> >     about
> >     >         a different
> >     >         >>> > proposal that will make the different layer types in
> >     different
> >     >         >>> > applications
> >     >         >>> > a bit more manageable than they are today.  I
> understand
> >     >         how having one
> >     >         >>> > giant enum for LAYER_ID seems more complicated, I'm
> just
> >     >         worried that
> >     >         >>> > having several different enums will make the code
> that
> >     >         consumes
> >     >         >>> > LAYER_ID
> >     >         >>> > more complicated, especially if the applications
> become
> >     >         more integrated
> >     >         >>> > with each other and start sharing more code.
> >     >         >>> >
> >     >         >>> > Best,
> >     >         >>> > Jon
> >     >         >>> >
> >     >         >>> > On Mon, Mar 13, 2017 at 8:21 AM, Wayne Stambaugh
> >     >         <stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>
> >     <mailto:stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>>>
> >     >         >>> > wrote:
> >     >         >>> >
> >     >         >>> >> Jon,
> >     >         >>> >>
> >     >         >>> >> I misunderstood your original intent.  I don't think
> >     >         cluttering the
> >     >         >>> >> board layer enums with all of the virtual layer and
> >     >         schematic layer
> >     >         >>> >> enums is a good idea.  It just seems like overkill
> to
> >     >         me.  I thought
> >     >         >>> >> you
> >     >         >>> >> were going to create a separate enum for virtual
> board
> >     >         layers.  You
> >     >         >>> >> could always start the virtual board layer enums
> >     from the
> >     >         last board
> >     >         >>> >> layer enum if you need unique enums.  I would also
> >     prefer the
> >     >         >>> >> schematic
> >     >         >>> >> layer enums be separate from the board layer enums
> for
> >     >         clarity.
> >     >         >>> >> Anyone
> >     >         >>> >> else have any thoughts on this?
> >     >         >>> >>
> >     >         >>> >> Cheers,
> >     >         >>> >>
> >     >         >>> >> Wayne
> >     >         >>> >>
> >     >         >>> >> On 3/12/2017 11:24 PM, Jon Evans wrote:
> >     >         >>> >>> Hi all,
> >     >         >>> >>>
> >     >         >>> >>> Per the other thread, this patch unifies the layer
> >     >         definitions
> >     >         >>> >>> between
> >     >         >>> >>> Pcbnew, GerbView, and Eeschema.  It removes the
> >     need for
> >     >         >>> >>> ITEM_GAL_LAYER
> >     >         >>> >>> and some other macros, and it will simplify the
> >     >         implementation of
> >     >         >>> >>> cross-application color themes and using GAL in
> >     multiple
> >     >         >>> >>> applications.
> >     >         >>> >>>
> >     >         >>> >>> Note that this patch introduces some temporary
> >     weirdness
> >     >         in a few
> >     >         >>> >>> places, such as in COLORS_DESIGN_SETTINGS (there
> >     is now
> >     >         a single
> >     >         >>> >>> array
> >     >         >>> >>> for color storage, but it's still referred to by
> >     two sets of
> >     >         >>> >>> getters/setters).  This is because I wanted to
> >     keep this
> >     >         refactor as
> >     >         >>> >>> simple as possible, as I plan to follow it up with
> an
> >     >         overhaul of
> >     >         >>> >>> color
> >     >         >>> >>> settings when I share my color themes work.  I
> didn't
> >     >         want to do work
> >     >         >>> >>> that I would soon end up getting rid of anyway.
> >     >         >>> >>>
> >     >         >>> >>> Best,
> >     >         >>> >>> Jon
> >     >         >>> >>>
> >     >         >>> >>>
> >     >         >>> >>> _______________________________________________
> >     >         >>> >>> Mailing list:
> >     https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> >>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >     >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >     >         >>> >>> Unsubscribe : https://launchpad.net/~kicad-
> developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> >>> More help   : https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>
> >     >         <https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>>
> >     >         >>> >>>
> >     >         >>> >>
> >     >         >>> >> _______________________________________________
> >     >         >>> >> Mailing list: https://launchpad.net/~kicad-
> developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> >> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >     >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >     >         >>> >> Unsubscribe : https://launchpad.net/~kicad-
> developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> >> More help   : https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>
> >     >         <https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>>
> >     >         >>> >>
> >     >         >>> >
> >     >         >>> >
> >     >         >>> >
> >     >         >>> > _______________________________________________
> >     >         >>> > Mailing list: https://launchpad.net/~kicad-
> developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> > Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >     >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >     >         >>> > Unsubscribe : https://launchpad.net/~kicad-
> developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> > More help   : https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>
> >     >         <https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>>
> >     >         >>> >
> >     >         >>>
> >     >         >>> _______________________________________________
> >     >         >>> Mailing list: https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >     >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >     >         >>> Unsubscribe : https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         >>> More help   : https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>
> >     >         <https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>>
> >     >         >>
> >     >         >>
> >     >         >
> >     >         >
> >     >         > _______________________________________________
> >     >         > Mailing list: https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         > Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >     >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >     >         > Unsubscribe : https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>
> >     >         <https://launchpad.net/~kicad-developers
> >     <https://launchpad.net/~kicad-developers>>
> >     >         > More help   : https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>
> >     >         <https://help.launchpad.net/ListHelp
> >     <https://help.launchpad.net/ListHelp>>
> >     >         >
> >     >
> >     >
> >     >
> >
> >
>
From 4694cbc86f07a97c1c908c091d234b88a76932f3 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sun, 12 Mar 2017 23:19:33 -0400
Subject: [PATCH 1/3] Refactor layer enumerations to all live in the same place

---
 3d-viewer/3d_canvas/cinfo3d_visu.cpp               |  10 +-
 3d-viewer/3d_canvas/cinfo3d_visu.h                 |  32 +-
 3d-viewer/3d_canvas/create_layer_items.cpp         |  48 +--
 3d-viewer/3d_canvas/create_layer_poly.cpp          |   4 +-
 .../c3d_render_createscene_ogl_legacy.cpp          |  10 +-
 .../3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp |   8 +-
 .../3d_render_ogl_legacy/c3d_render_ogl_legacy.h   |  14 +-
 .../c3d_render_createscene.cpp                     |  10 +-
 common/class_colors_design_settings.cpp            |  48 ++-
 common/draw_panel_gal.cpp                          |   2 +-
 common/lset.cpp                                    |  51 +--
 common/painter.cpp                                 |   2 +-
 common/preview_items/ruler_item.cpp                |   2 +-
 common/preview_items/simple_overlay_item.cpp       |   3 +-
 common/swig/kicad.i                                |   6 +-
 common/view/view_group.cpp                         |   2 +-
 common/worksheet_viewitem.cpp                      |   2 +-
 eeschema/eeschema.cpp                              |  77 ++--
 eeschema/eeschema_config.cpp                       |   8 +-
 eeschema/general.h                                 |  47 +--
 eeschema/sch_base_frame.cpp                        |   4 +-
 eeschema/sch_item_struct.h                         |   6 +-
 eeschema/sch_legacy_plugin.cpp                     |   4 +-
 eeschema/sch_screen.cpp                            |   2 +-
 eeschema/viewlib_frame.cpp                         |   4 +-
 eeschema/widgets/widget_eeschema_color_config.cpp  |  22 +-
 gerbview/class_gerbview_layer_widget.cpp           |  16 +-
 gerbview/dialogs/dialog_select_one_pcb_layer.cpp   |   4 +-
 .../gerbview_dialog_display_options_frame.cpp      |   4 +-
 gerbview/draw_gerber_screen.cpp                    |   2 +-
 gerbview/events_called_functions.cpp               |   4 +-
 gerbview/export_to_pcbnew.cpp                      |   2 +-
 gerbview/gerbview.h                                |  15 -
 gerbview/gerbview_config.cpp                       |   8 +-
 gerbview/gerbview_frame.cpp                        |  46 +--
 gerbview/gerbview_frame.h                          |  15 +-
 gerbview/hotkeys.cpp                               |   4 +-
 gerbview/toolbars_gerber.cpp                       |   4 +-
 include/class_board_design_settings.h              |  22 +-
 include/class_board_item.h                         |   8 +-
 include/class_colors_design_settings.h             |   7 +-
 include/class_pcb_screen.h                         |   6 +-
 include/layers_id_colors_and_visibility.h          | 390 ++++++++++++---------
 include/origin_viewitem.h                          |   2 +-
 include/painter.h                                  |   8 +-
 include/preview_items/bright_box.h                 |   2 +-
 include/preview_items/selection_area.h             |   1 +
 include/preview_items/simple_overlay_item.h        |   1 +
 include/view/view.h                                |   3 +-
 include/wxBasePcbFrame.h                           |   8 +-
 include/wxPcbStruct.h                              |  16 +-
 pcbnew/autorouter/auto_place_footprints.cpp        |   2 +-
 pcbnew/autorouter/graphpcb.cpp                     |   2 +-
 .../autorouter/move_and_route_event_functions.cpp  |   2 +-
 pcbnew/basepcbframe.cpp                            |  22 +-
 pcbnew/block.cpp                                   |   2 +-
 pcbnew/board_items_to_polygon_shape_transform.cpp  |  10 +-
 pcbnew/class_board.cpp                             | 134 +++----
 pcbnew/class_board.h                               |  80 ++---
 pcbnew/class_board_design_settings.cpp             |  15 +-
 pcbnew/class_dimension.cpp                         |   2 +-
 pcbnew/class_dimension.h                           |   2 +-
 pcbnew/class_drawsegment.cpp                       |   2 +-
 pcbnew/class_drc_item.cpp                          |   2 +-
 pcbnew/class_edge_mod.cpp                          |   2 +-
 pcbnew/class_marker_pcb.cpp                        |   4 +-
 pcbnew/class_marker_pcb.h                          |   2 +-
 pcbnew/class_mire.cpp                              |   2 +-
 pcbnew/class_mire.h                                |   2 +-
 pcbnew/class_module.cpp                            |  20 +-
 pcbnew/class_module.h                              |   6 +-
 pcbnew/class_netinfo_item.cpp                      |   2 +-
 pcbnew/class_pad.cpp                               |  20 +-
 pcbnew/class_pad.h                                 |   2 +-
 pcbnew/class_pad_draw_functions.cpp                |  20 +-
 pcbnew/class_pcb_layer_box_selector.cpp            |   4 +-
 pcbnew/class_pcb_layer_widget.cpp                  |  82 ++---
 pcbnew/class_pcb_layer_widget.h                    |   4 +-
 pcbnew/class_pcb_text.cpp                          |   6 +-
 pcbnew/class_text_mod.cpp                          |  36 +-
 pcbnew/class_track.cpp                             |  48 +--
 pcbnew/class_track.h                               |  11 +-
 pcbnew/class_zone.cpp                              |   6 +-
 pcbnew/class_zone_settings.h                       |   2 +-
 pcbnew/clean.cpp                                   |   2 +-
 pcbnew/collectors.cpp                              |   4 +-
 pcbnew/collectors.h                                |  22 +-
 pcbnew/deltrack.cpp                                |   2 +-
 pcbnew/dialogs/dialog_SVG_print.cpp                |   6 +-
 pcbnew/dialogs/dialog_copper_zones.cpp             |   4 +-
 pcbnew/dialogs/dialog_display_options.cpp          |   4 +-
 pcbnew/dialogs/dialog_exchange_modules.cpp         |   2 +-
 pcbnew/dialogs/dialog_general_options.cpp          |   6 +-
 pcbnew/dialogs/dialog_keepout_area_properties.cpp  |   2 +-
 pcbnew/dialogs/dialog_layers_setup.cpp             |  16 +-
 .../dialogs/dialog_non_copper_zones_properties.cpp |   4 +-
 pcbnew/dialogs/dialog_pad_properties.cpp           |   4 +-
 pcbnew/dialogs/dialog_plot.cpp                     |   4 +-
 pcbnew/dialogs/dialog_print_using_printer.cpp      |   4 +-
 pcbnew/dialogs/dialog_track_via_properties.cpp     |   4 +-
 pcbnew/dimension.cpp                               |   2 +-
 pcbnew/drc_clearance_test_functions.cpp            |   2 +-
 pcbnew/eagle_plugin.cpp                            |  56 +--
 pcbnew/eagle_plugin.h                              |   2 +-
 pcbnew/edgemod.cpp                                 |   4 +-
 pcbnew/edit.cpp                                    |  12 +-
 pcbnew/edit_pcb_text.cpp                           |   2 +-
 pcbnew/editedge.cpp                                |   2 +-
 pcbnew/editrack-part2.cpp                          |   8 +-
 pcbnew/exporters/export_d356.cpp                   |   2 +-
 pcbnew/exporters/export_gencad.cpp                 |  14 +-
 pcbnew/exporters/export_vrml.cpp                   |   8 +-
 pcbnew/exporters/gendrill_Excellon_writer.cpp      |   2 +-
 pcbnew/exporters/gendrill_Excellon_writer.h        |  24 +-
 pcbnew/files.cpp                                   |   2 +-
 pcbnew/footprint_wizard_frame.cpp                  |   2 +-
 pcbnew/initpcb.cpp                                 |   8 +-
 pcbnew/kicad_plugin.cpp                            |  16 +-
 pcbnew/legacy_plugin.cpp                           |  18 +-
 pcbnew/legacy_plugin.h                             |   2 +-
 pcbnew/magnetic_tracks_functions.cpp               |   2 +-
 pcbnew/modedit.cpp                                 |   4 +-
 pcbnew/module_editor_frame.h                       |  10 +-
 pcbnew/moduleframe.cpp                             |  10 +-
 pcbnew/modules.cpp                                 |  16 +-
 pcbnew/modview_frame.cpp                           |   2 +-
 pcbnew/pcad2kicadpcb_plugin/pcb.cpp                |   8 +-
 pcbnew/pcad2kicadpcb_plugin/pcb.h                  |   2 +-
 pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h        |   4 +-
 pcbnew/pcad2kicadpcb_plugin/pcb_component.h        |   4 +-
 pcbnew/pcb_draw_panel_gal.cpp                      | 224 ++++++------
 pcbnew/pcb_draw_panel_gal.h                        |   8 +-
 pcbnew/pcb_painter.cpp                             |  91 ++---
 pcbnew/pcb_painter.h                               |   2 +-
 pcbnew/pcb_parser.cpp                              |  28 +-
 pcbnew/pcb_parser.h                                |   6 +-
 pcbnew/pcbframe.cpp                                |  30 +-
 pcbnew/pcbnew.cpp                                  |  24 +-
 pcbnew/pcbnew.h                                    |   4 +-
 pcbnew/pcbnew_config.cpp                           |  30 +-
 pcbnew/pcbnew_config.h                             |   2 +-
 pcbnew/pcbplot.h                                   |   2 +-
 pcbnew/plot_board_layers.cpp                       |  14 +-
 pcbnew/plot_brditems_plotter.cpp                   |   6 +-
 pcbnew/print_board_functions.cpp                   |  26 +-
 pcbnew/printout_controler.cpp                      |   2 +-
 pcbnew/ratsnest.cpp                                |  12 +-
 pcbnew/ratsnest_viewitem.cpp                       |   4 +-
 pcbnew/router/pns_kicad_iface.cpp                  |   6 +-
 pcbnew/router/router_preview_item.cpp              |   4 +-
 pcbnew/router/router_tool.cpp                      |   4 +-
 pcbnew/sel_layer.cpp                               |  46 +--
 pcbnew/specctra.cpp                                |   2 +-
 pcbnew/specctra.h                                  |   2 +-
 pcbnew/specctra_export.cpp                         |   6 +-
 pcbnew/specctra_import.cpp                         |   4 +-
 pcbnew/swap_layers.cpp                             |  24 +-
 pcbnew/swig/board.i                                |  10 +-
 pcbnew/tool_pcb.cpp                                |   4 +-
 pcbnew/toolbars_update_user_interface.cpp          |   4 +-
 pcbnew/tools/drawing_tool.cpp                      |  10 +-
 pcbnew/tools/drawing_tool.h                        |   2 +-
 pcbnew/tools/edit_points.h                         |   2 +-
 pcbnew/tools/grid_helper.cpp                       |   2 +-
 pcbnew/tools/module_editor_tools.cpp               |  12 +-
 pcbnew/tools/pcbnew_control.cpp                    |   2 +-
 pcbnew/tools/selection_tool.cpp                    |  10 +-
 pcbnew/tracepcb.cpp                                |   4 +-
 pcbnew/zones_by_polygon.cpp                        |   4 +-
 169 files changed, 1307 insertions(+), 1296 deletions(-)

diff --git a/3d-viewer/3d_canvas/cinfo3d_visu.cpp b/3d-viewer/3d_canvas/cinfo3d_visu.cpp
index 088f580..e84c866 100644
--- a/3d-viewer/3d_canvas/cinfo3d_visu.cpp
+++ b/3d-viewer/3d_canvas/cinfo3d_visu.cpp
@@ -120,9 +120,9 @@ CINFO3D_VISU::~CINFO3D_VISU()
 }
 
 
-bool CINFO3D_VISU::Is3DLayerEnabled( LAYER_ID aLayer ) const
+bool CINFO3D_VISU::Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const
 {
-    wxASSERT( aLayer < LAYER_ID_COUNT );
+    wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
 
     DISPLAY3D_FLG flg;
 
@@ -372,7 +372,7 @@ void CINFO3D_VISU::InitSettings( REPORTER *aStatusTextReporter )
 
     // calculate z position for each non copper layer
     // Solder mask and Solder paste have the same Z position
-    for( int layer_id = MAX_CU_LAYERS; layer_id < LAYER_ID_COUNT; ++layer_id )
+    for( int layer_id = MAX_CU_LAYERS; layer_id < PCB_LAYER_ID_COUNT; ++layer_id )
     {
         float zposTop;
         float zposBottom;
@@ -528,9 +528,9 @@ void CINFO3D_VISU::CameraSetType( CAMERA_TYPE aCameraType )
 }
 
 
-SFVEC3F CINFO3D_VISU::GetLayerColor( LAYER_ID aLayerId ) const
+SFVEC3F CINFO3D_VISU::GetLayerColor( PCB_LAYER_ID aLayerId ) const
 {
-    wxASSERT( aLayerId < LAYER_ID_COUNT );
+    wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
 
     const COLOR4D color = g_ColorsSettings.GetLayerColor( aLayerId );
 
diff --git a/3d-viewer/3d_canvas/cinfo3d_visu.h b/3d-viewer/3d_canvas/cinfo3d_visu.h
index 90db438..71ca8eb 100644
--- a/3d-viewer/3d_canvas/cinfo3d_visu.h
+++ b/3d-viewer/3d_canvas/cinfo3d_visu.h
@@ -52,10 +52,10 @@
 #include <reporter.h>
 
 /// A type that stores a container of 2d objects for each layer id
-typedef std::map< LAYER_ID, CBVHCONTAINER2D *> MAP_CONTAINER_2D;
+typedef std::map< PCB_LAYER_ID, CBVHCONTAINER2D *> MAP_CONTAINER_2D;
 
 /// A type that stores polysets for each layer id
-typedef std::map< LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
+typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
 
 /// This defines the range that all coord will have to be rendered.
 /// It will use this value to convert to a normalized value between
@@ -106,7 +106,7 @@ class CINFO3D_VISU
      * @param aLayer: layer ID to get status
      * @return true if layer should be displayed, false if not
      */
-    bool Is3DLayerEnabled( LAYER_ID aLayer ) const;
+    bool Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const;
 
     /**
      * @brief ShouldModuleBeDisplayed - Test if module should be displayed in
@@ -256,7 +256,7 @@ class CINFO3D_VISU
      * @param aLayerId: the layer to get the color information
      * @return the color in SFVEC3F format
      */
-    SFVEC3F GetLayerColor( LAYER_ID aLayerId ) const;
+    SFVEC3F GetLayerColor( PCB_LAYER_ID aLayerId ) const;
 
     /**
      * @brief GetItemColor - get the technical color of a layer
@@ -277,14 +277,14 @@ class CINFO3D_VISU
      * @param aLayerId: layer id
      * @return position in 3D unities
      */
-    float GetLayerTopZpos3DU( LAYER_ID aLayerId ) const { return m_layerZcoordTop[aLayerId]; }
+    float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordTop[aLayerId]; }
 
     /**
      * @brief GetLayerBottomZpos3DU - Get the bottom z position
      * @param aLayerId: layer id
      * @return position in 3D unities
      */
-    float GetLayerBottomZpos3DU( LAYER_ID aLayerId ) const { return m_layerZcoordBottom[aLayerId]; }
+    float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordBottom[aLayerId]; }
 
     /**
      * @brief GetMapLayers - Get the map of container that have the objects per layer
@@ -437,33 +437,33 @@ class CINFO3D_VISU
 
     void AddPadsShapesWithClearanceToContainer( const MODULE *aModule,
                                                 CGENERICCONTAINER2D *aDstContainer,
-                                                LAYER_ID aLayerId,
+                                                PCB_LAYER_ID aLayerId,
                                                 int aInflateValue,
                                                 bool aSkipNPTHPadsWihNoCopper );
 
     void AddGraphicsShapesWithClearanceToContainer( const MODULE *aModule,
                                                     CGENERICCONTAINER2D *aDstContainer,
-                                                    LAYER_ID aLayerId,
+                                                    PCB_LAYER_ID aLayerId,
                                                     int aInflateValue );
 
     void AddShapeWithClearanceToContainer( const TEXTE_PCB *aTextPCB,
                                            CGENERICCONTAINER2D *aDstContainer,
-                                           LAYER_ID aLayerId,
+                                           PCB_LAYER_ID aLayerId,
                                            int aClearanceValue );
 
     void AddShapeWithClearanceToContainer( const DRAWSEGMENT *aDrawSegment,
                                            CGENERICCONTAINER2D *aDstContainer,
-                                           LAYER_ID aLayerId,
+                                           PCB_LAYER_ID aLayerId,
                                            int aClearanceValue );
 
     void AddShapeWithClearanceToContainer( const DIMENSION *aDimension,
                                            CGENERICCONTAINER2D *aDstContainer,
-                                           LAYER_ID aLayerId,
+                                           PCB_LAYER_ID aLayerId,
                                            int aClearanceValue );
 
     void AddSolidAreasShapesToContainer( const ZONE_CONTAINER *aZoneContainer,
                                          CGENERICCONTAINER2D *aDstContainer,
-                                         LAYER_ID aLayerId );
+                                         PCB_LAYER_ID aLayerId );
 
     void TransformArcToSegments( const wxPoint &aCentre,
                                  const wxPoint &aStart,
@@ -483,13 +483,13 @@ class CINFO3D_VISU
                                              int aWidth) const;
 
     void transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD> &aPads,
-                                                    LAYER_ID aLayer,
+                                                    PCB_LAYER_ID aLayer,
                                                     SHAPE_POLY_SET &aCornerBuffer,
                                                     int aInflateValue,
                                                     bool aSkipNPTHPadsWihNoCopper) const;
 
     void transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
-                                                 LAYER_ID aLayer,
+                                                 PCB_LAYER_ID aLayer,
                                                  SHAPE_POLY_SET& aCornerBuffer ) const;
 
     void buildPadShapePolygon( const D_PAD *aPad,
@@ -616,10 +616,10 @@ class CINFO3D_VISU
     double m_biuTo3Dunits;
 
     /// Top (End) Z position of each layer (normalized)
-    float  m_layerZcoordTop[LAYER_ID_COUNT];
+    float  m_layerZcoordTop[PCB_LAYER_ID_COUNT];
 
     /// Bottom (Start) Z position of each layer (normalized)
-    float  m_layerZcoordBottom[LAYER_ID_COUNT];
+    float  m_layerZcoordBottom[PCB_LAYER_ID_COUNT];
 
     /// Copper thickness (normalized)
     float  m_copperThickness3DU;
diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp
index 39b5e57..d783a65 100644
--- a/3d-viewer/3d_canvas/create_layer_items.cpp
+++ b/3d-viewer/3d_canvas/create_layer_items.cpp
@@ -91,7 +91,7 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf )
 // board_items_to_polygon_shape_transform.cpp
 void CINFO3D_VISU::AddShapeWithClearanceToContainer( const TEXTE_PCB* aTextPCB,
                                                      CGENERICCONTAINER2D *aDstContainer,
-                                                     LAYER_ID aLayerId,
+                                                     PCB_LAYER_ID aLayerId,
                                                      int aClearanceValue )
 {
     wxSize size = aTextPCB->GetTextSize();
@@ -141,7 +141,7 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const TEXTE_PCB* aTextPCB,
 
 void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DIMENSION* aDimension,
                                                      CGENERICCONTAINER2D *aDstContainer,
-                                                     LAYER_ID aLayerId,
+                                                     PCB_LAYER_ID aLayerId,
                                                      int aClearanceValue )
 {
     AddShapeWithClearanceToContainer(&aDimension->Text(), aDstContainer, aLayerId, aClearanceValue);
@@ -178,7 +178,7 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DIMENSION* aDimension
 // board_items_to_polygon_shape_transform.cpp#L204
 void CINFO3D_VISU::AddGraphicsShapesWithClearanceToContainer( const MODULE* aModule,
                                                               CGENERICCONTAINER2D *aDstContainer,
-                                                              LAYER_ID aLayerId,
+                                                              PCB_LAYER_ID aLayerId,
                                                               int aInflateValue )
 {
     std::vector<TEXTE_MODULE *> texts;  // List of TEXTE_MODULE to convert
@@ -603,7 +603,7 @@ void CINFO3D_VISU::createNewPad( const D_PAD* aPad,
 
 void CINFO3D_VISU::AddPadsShapesWithClearanceToContainer( const MODULE* aModule,
                                                           CGENERICCONTAINER2D *aDstContainer,
-                                                          LAYER_ID aLayerId,
+                                                          PCB_LAYER_ID aLayerId,
                                                           int aInflateValue,
                                                           bool aSkipNPTHPadsWihNoCopper )
 {
@@ -745,7 +745,7 @@ void CINFO3D_VISU::TransformArcToSegments( const wxPoint &aCentre,
 // board_items_to_polygon_shape_transform.cpp#L431
 void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSegment,
                                                      CGENERICCONTAINER2D *aDstContainer,
-                                                     LAYER_ID aLayerId,
+                                                     PCB_LAYER_ID aLayerId,
                                                      int aClearanceValue )
 {
     // The full width of the lines to create:
@@ -909,7 +909,7 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSeg
 // board_items_to_polygon_shape_transform.cpp
 void CINFO3D_VISU::AddSolidAreasShapesToContainer( const ZONE_CONTAINER* aZoneContainer,
                                                    CGENERICCONTAINER2D *aDstContainer,
-                                                   LAYER_ID aLayerId )
+                                                   PCB_LAYER_ID aLayerId )
 {
     // Copy the polys list because we have to simplify it
     SHAPE_POLY_SET polyList = SHAPE_POLY_SET(aZoneContainer->GetFilledPolysList());
@@ -1164,7 +1164,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     unsigned start_Time = stats_startCopperLayersTime;
 #endif
 
-    LAYER_ID cu_seq[MAX_CU_LAYERS];
+    PCB_LAYER_ID cu_seq[MAX_CU_LAYERS];
     LSET     cu_set = LSET::AllCuMask( m_copperLayersCount );
 
     m_stats_nr_tracks               = 0;
@@ -1216,7 +1216,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
 
     // Prepare copper layers index and containers
     // /////////////////////////////////////////////////////////////////////////
-    std::vector< LAYER_ID > layer_id;
+    std::vector< PCB_LAYER_ID > layer_id;
     layer_id.clear();
     layer_id.reserve( m_copperLayersCount );
 
@@ -1225,7 +1225,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
 
     for( LSEQ cu = cu_set.Seq( cu_seq, DIM( cu_seq ) ); cu; ++cu )
     {
-        const LAYER_ID curr_layer_id = *cu;
+        const PCB_LAYER_ID curr_layer_id = *cu;
 
         if( !Is3DLayerEnabled( curr_layer_id ) ) // Skip non enabled layers
             continue;
@@ -1255,7 +1255,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     // /////////////////////////////////////////////////////////////////////////
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
 
@@ -1286,7 +1286,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     // /////////////////////////////////////////////////////////////////////////
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         // ADD TRACKS
         unsigned int nTracks = trackList.size();
@@ -1370,7 +1370,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     // /////////////////////////////////////////////////////////////////////////
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         // ADD TRACKS
         const unsigned int nTracks = trackList.size();
@@ -1481,7 +1481,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     {
         for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
 
@@ -1599,7 +1599,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     // /////////////////////////////////////////////////////////////////////////
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
 
@@ -1636,7 +1636,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     {
         for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
 
@@ -1679,7 +1679,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     // /////////////////////////////////////////////////////////////////////////
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
 
@@ -1739,7 +1739,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
     {
         for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
 
@@ -1800,7 +1800,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
         // /////////////////////////////////////////////////////////////////////
         for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             if( aStatusTextReporter )
                 aStatusTextReporter->Report( wxString::Format( _( "Create zones of layer %s" ),
@@ -1814,7 +1814,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
             for( int ii = 0; ii < m_board->GetAreaCount(); ++ii )
             {
                 const ZONE_CONTAINER* zone = m_board->GetArea( ii );
-                const LAYER_ID zonelayer = zone->GetLayer();
+                const PCB_LAYER_ID zonelayer = zone->GetLayer();
 
                 if( zonelayer == curr_layer_id )
                 {
@@ -1839,7 +1839,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
         // /////////////////////////////////////////////////////////////////////
         for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
 
@@ -1880,7 +1880,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
         #pragma omp parallel for
         for( signed int lIdx = 0; lIdx < nLayers; ++lIdx )
         {
-            const LAYER_ID curr_layer_id = layer_id[lIdx];
+            const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
             wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
 
@@ -1905,7 +1905,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
 
     for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
     {
-        const LAYER_ID curr_layer_id = layer_id[lIdx];
+        const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
 
         if( m_layers_outer_holes_poly.find( curr_layer_id ) !=
             m_layers_outer_holes_poly.end() )
@@ -1951,7 +1951,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
         aStatusTextReporter->Report( _( "Build Tech layers" ) );
 
     // draw graphic items, on technical layers
-    static const LAYER_ID teckLayerList[] = {
+    static const PCB_LAYER_ID teckLayerList[] = {
             B_Adhes,
             F_Adhes,
             B_Paste,
@@ -1975,7 +1975,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
          seq;
          ++seq )
     {
-        const LAYER_ID curr_layer_id = *seq;
+        const PCB_LAYER_ID curr_layer_id = *seq;
 
         if( !Is3DLayerEnabled( curr_layer_id ) )
                     continue;
diff --git a/3d-viewer/3d_canvas/create_layer_poly.cpp b/3d-viewer/3d_canvas/create_layer_poly.cpp
index b3016af..8cfbba4 100644
--- a/3d-viewer/3d_canvas/create_layer_poly.cpp
+++ b/3d-viewer/3d_canvas/create_layer_poly.cpp
@@ -125,7 +125,7 @@ void CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
 
 // Based on the same function name in board_items_to_polyshape_transform.cpp
 // It was implemented here to allow dynamic segments count per pad shape
-void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD>& aPads, LAYER_ID aLayer,
+void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD>& aPads, PCB_LAYER_ID aLayer,
                                                               SHAPE_POLY_SET& aCornerBuffer,
                                                               int aInflateValue,
                                                               bool aSkipNPTHPadsWihNoCopper ) const
@@ -191,7 +191,7 @@ void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD>
 }
 
 void CINFO3D_VISU::transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
-                                                           LAYER_ID aLayer,
+                                                           PCB_LAYER_ID aLayer,
                                                            SHAPE_POLY_SET& aCornerBuffer ) const
 {
     for( const EDA_ITEM* item = aModule->GraphicalItems();
diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp
index 485fcc5..c3fe812 100644
--- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp
+++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp
@@ -493,7 +493,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER *aStatusTextReporter )
              ii != outerMapHoles.end();
              ++ii )
         {
-            LAYER_ID layer_id = static_cast<LAYER_ID>(ii->first);
+            PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
             const SHAPE_POLY_SET *poly = static_cast<const SHAPE_POLY_SET *>(ii->second);
             const CBVHCONTAINER2D *container = map_holes.at( layer_id );
 
@@ -511,7 +511,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER *aStatusTextReporter )
              ii != innerMapHoles.end();
              ++ii )
         {
-            LAYER_ID layer_id = static_cast<LAYER_ID>(ii->first);
+            PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
             const SHAPE_POLY_SET *poly = static_cast<const SHAPE_POLY_SET *>(ii->second);
             const CBVHCONTAINER2D *container = map_holes.at( layer_id );
 
@@ -539,7 +539,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER *aStatusTextReporter )
          ii != m_settings.GetMapLayers().end();
          ++ii )
     {
-        LAYER_ID layer_id = static_cast<LAYER_ID>(ii->first);
+        PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
 
         if( !m_settings.Is3DLayerEnabled( layer_id ) )
             continue;
@@ -685,7 +685,7 @@ void C3D_RENDER_OGL_LEGACY::add_triangle_top_bot( CLAYER_TRIANGLES *aDst,
 }
 
 
-void C3D_RENDER_OGL_LEGACY::get_layer_z_pos ( LAYER_ID aLayerID,
+void C3D_RENDER_OGL_LEGACY::get_layer_z_pos ( PCB_LAYER_ID aLayerID,
                                               float &aOutZtop,
                                               float &aOutZbot ) const
 {
@@ -773,7 +773,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
                 const SFVEC2F via_center(  via->GetStart().x * m_settings.BiuTo3Dunits(),
                                           -via->GetStart().y * m_settings.BiuTo3Dunits() );
 
-                LAYER_ID top_layer, bottom_layer;
+                PCB_LAYER_ID top_layer, bottom_layer;
                 via->LayerPair( &top_layer, &bottom_layer );
 
                 float ztop, zbot, dummy;
diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
index 6f79fc3..c95850b 100644
--- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
+++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
@@ -302,7 +302,7 @@ void C3D_RENDER_OGL_LEGACY::setupMaterials()
 }
 
 
-void C3D_RENDER_OGL_LEGACY::set_layer_material( LAYER_ID aLayerID )
+void C3D_RENDER_OGL_LEGACY::set_layer_material( PCB_LAYER_ID aLayerID )
 {
     switch( aLayerID )
     {
@@ -360,7 +360,7 @@ void C3D_RENDER_OGL_LEGACY::set_layer_material( LAYER_ID aLayerID )
 }
 
 
-SFVEC3F C3D_RENDER_OGL_LEGACY::get_layer_color( LAYER_ID aLayerID )
+SFVEC3F C3D_RENDER_OGL_LEGACY::get_layer_color( PCB_LAYER_ID aLayerID )
 {
     SFVEC3F layerColor = m_settings.GetLayerColor( aLayerID );
 
@@ -623,7 +623,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving,
          ++ii )
     {
 
-        const LAYER_ID layer_id = (LAYER_ID)(ii->first);
+        const PCB_LAYER_ID layer_id = (PCB_LAYER_ID)(ii->first);
 
         // Mask kayers are not processed here because they are a special case
         if( (layer_id == B_Mask) || (layer_id == F_Mask) )
@@ -918,7 +918,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
 }
 
 
-void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer( LAYER_ID aLayerID,
+void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer( PCB_LAYER_ID aLayerID,
                                                       float aZPosition,
                                                       bool aIsRenderingOnPreviewMode )
 {
diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h
index ebfc2df..b8e387b 100644
--- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h
+++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h
@@ -47,8 +47,8 @@
 #include <map>
 
 
-typedef std::map< LAYER_ID, CLAYERS_OGL_DISP_LISTS* > MAP_OGL_DISP_LISTS;
-typedef std::map< LAYER_ID, CLAYER_TRIANGLES * > MAP_TRIANGLES;
+typedef std::map< PCB_LAYER_ID, CLAYERS_OGL_DISP_LISTS* > MAP_OGL_DISP_LISTS;
+typedef std::map< PCB_LAYER_ID, CLAYER_TRIANGLES * > MAP_TRIANGLES;
 typedef std::map< wxString, C_OGL_3DMODEL * > MAP_3DMODEL;
 
 #define SIZE_OF_CIRCLE_TEXTURE 1024
@@ -148,11 +148,11 @@ private:
                                        float aZtop,
                                        float aZbot );
 
-    void render_solder_mask_layer( LAYER_ID aLayerID,
+    void render_solder_mask_layer( PCB_LAYER_ID aLayerID,
                                    float aZPosition,
                                    bool aIsRenderingOnPreviewMode );
 
-    void get_layer_z_pos( LAYER_ID aLayerID,
+    void get_layer_z_pos( PCB_LAYER_ID aLayerID,
                           float &aOutZtop,
                           float &aOutZbot ) const;
 
@@ -208,12 +208,12 @@ private:
         SMATERIAL m_GrayMaterial;
     }m_materials;
 
-    void set_layer_material( LAYER_ID aLayerID );
-    SFVEC3F get_layer_color( LAYER_ID aLayerID );
+    void set_layer_material( PCB_LAYER_ID aLayerID );
+    SFVEC3F get_layer_color( PCB_LAYER_ID aLayerID );
 
 public:
     const MAP_OGL_DISP_LISTS &GetLayerDispListMap() const { return m_ogl_disp_lists_layers; }
-    const CLAYERS_OGL_DISP_LISTS *GetLayerDispList( LAYER_ID aLayerId ) const { return m_ogl_disp_lists_layers.at( aLayerId ); }
+    const CLAYERS_OGL_DISP_LISTS *GetLayerDispList( PCB_LAYER_ID aLayerId ) const { return m_ogl_disp_lists_layers.at( aLayerId ); }
     const CLAYERS_OGL_DISP_LISTS *GetBoardDispList() const { return m_ogl_disp_list_board; }
 };
 
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
index c9968ff..8476960 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
@@ -442,7 +442,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
          ii != m_settings.GetMapLayers().end();
          ++ii )
     {
-        LAYER_ID layer_id = static_cast<LAYER_ID>(ii->first);
+        PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
 
         // Mask kayers are not processed here because they are a special case
         if( (layer_id == B_Mask) || (layer_id == F_Mask) )
@@ -644,7 +644,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
              ii != m_settings.GetMapLayers().end();
              ++ii )
         {
-            LAYER_ID layer_id = static_cast<LAYER_ID>(ii->first);
+            PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
 
             const CBVHCONTAINER2D *containerLayer2d =
                     static_cast<const CBVHCONTAINER2D *>(ii->second);
@@ -971,7 +971,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
 // 3d_draw_helper_functions.cpp
 void C3D_RENDER_RAYTRACING::insert3DViaHole( const VIA* aVia )
 {
-    LAYER_ID    top_layer, bottom_layer;
+    PCB_LAYER_ID    top_layer, bottom_layer;
     int radiusBUI = (aVia->GetDrillValue() / 2);
 
     aVia->LayerPair( &top_layer, &bottom_layer );
@@ -1001,7 +1001,7 @@ void C3D_RENDER_RAYTRACING::insert3DViaHole( const VIA* aVia )
     if( m_settings.GetFlag( FL_USE_REALISTIC_MODE ) )
         objPtr->SetColor( ConvertSRGBToLinear( (SFVEC3F)m_settings.m_CopperColor ) );
     else
-        objPtr->SetColor( ConvertSRGBToLinear( m_settings.GetItemColor( VIAS_VISIBLE + aVia->GetViaType() ) ) );
+        objPtr->SetColor( ConvertSRGBToLinear( m_settings.GetItemColor( LAYER_VIAS + aVia->GetViaType() ) ) );
 
     m_object_container.Add( objPtr );
 }
@@ -1018,7 +1018,7 @@ void C3D_RENDER_RAYTRACING::insert3DPadHole( const D_PAD* aPad )
     if( m_settings.GetFlag( FL_USE_REALISTIC_MODE ) )
         objColor = (SFVEC3F)m_settings.m_CopperColor;
     else
-        objColor = m_settings.GetItemColor( PADS_VISIBLE );
+        objColor = m_settings.GetItemColor( LAYER_PADS );
 
     const wxSize  drillsize   = aPad->GetDrillSize();
     const bool    hasHole     = drillsize.x && drillsize.y;
diff --git a/common/class_colors_design_settings.cpp b/common/class_colors_design_settings.cpp
index 3e996da..38deb2b 100644
--- a/common/class_colors_design_settings.cpp
+++ b/common/class_colors_design_settings.cpp
@@ -66,18 +66,18 @@ static const EDA_COLOR_T default_layer_color[] = {
 
 static const EDA_COLOR_T default_items_color[] = {
     LIGHTGRAY, // unused
-    CYAN,      // VIA_MICROVIA_VISIBLE
-    BROWN,     // VIA_BBLIND_VISIBLE
-    LIGHTGRAY, // VIA_THROUGH_VISIBLE
-    YELLOW,    // NON_PLATED_VISIBLE
-    LIGHTGRAY, // MOD_TEXT_FR_VISIBLE
-    BLUE,      // MOD_TEXT_BK_VISIBLE
-    DARKGRAY,  // MOD_TEXT_INVISIBLE
-    BLUE,      // ANCHOR_VISIBLE
-    RED,       // PAD_FR_VISIBLE
-    GREEN,     // PAD_BK_VISIBLE
-    LIGHTGRAY, // RATSNEST_VISIBLE
-    DARKGRAY,  // GRID_VISIBLE
+    CYAN,      // LAYER_VIA_MICROVIA
+    BROWN,     // LAYER_VIA_BBLIND
+    LIGHTGRAY, // LAYER_VIA_THROUGH
+    YELLOW,    // LAYER_NON_PLATED
+    LIGHTGRAY, // LAYER_MOD_TEXT_FR
+    BLUE,      // LAYER_MOD_TEXT_BK
+    DARKGRAY,  // LAYER_MOD_TEXT_INVISIBLE
+    BLUE,      // LAYER_ANCHOR
+    RED,       // LAYER_PAD_FR
+    GREEN,     // LAYER_PAD_BK
+    LIGHTGRAY, // LAYER_RATSNEST
+    DARKGRAY,  // LAYER_GRID
     LIGHTRED,  LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
     LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
     LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
@@ -88,7 +88,7 @@ static const EDA_COLOR_T default_items_color[] = {
 
 COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS()
 {
-    for( unsigned src = 0, dst = 0; dst < DIM(m_LayersColors); ++dst )
+    for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
     {
         m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
 
@@ -96,19 +96,16 @@ COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS()
             src = 0;        // wrap the source.
     }
 
-    for( unsigned src = 0, dst = 0; dst < DIM(m_ItemsColors);  ++dst )
+    for( unsigned src = 0, dst = LAYER_VIAS; dst < DIM( default_items_color ); ++dst )
     {
-        m_ItemsColors[dst] = COLOR4D( default_items_color[src++] );
-
-        if( src >= DIM( default_items_color ) )
-            src = 0;
+        m_LayersColors[dst] = COLOR4D( default_items_color[src++] );
     }
 }
 
 
 COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
 {
-    if( (unsigned) aLayer < DIM(m_LayersColors) )
+    if( (unsigned) aLayer < DIM( m_LayersColors ) )
     {
         return m_LayersColors[aLayer];
     }
@@ -118,7 +115,7 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
 
 void COLORS_DESIGN_SETTINGS::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
 {
-    if( (unsigned) aLayer < DIM(m_LayersColors) )
+    if( (unsigned) aLayer < DIM( m_LayersColors ) )
     {
         m_LayersColors[aLayer] = aColor;
     }
@@ -127,9 +124,9 @@ void COLORS_DESIGN_SETTINGS::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
 
 COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
 {
-    if( (unsigned) aItemIdx < DIM( m_ItemsColors ) )
+    if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
     {
-        return m_ItemsColors[aItemIdx];
+        return m_LayersColors[aItemIdx];
     }
 
     return COLOR4D::UNSPECIFIED;
@@ -138,9 +135,9 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
 
 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
 {
-    if( (unsigned) aItemIdx < DIM(m_ItemsColors) )
+    if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
     {
-        m_ItemsColors[aItemIdx] = aColor;
+        m_LayersColors[aItemIdx] = aColor;
     }
 }
 
@@ -149,7 +146,4 @@ void COLORS_DESIGN_SETTINGS::SetAllColorsAs( COLOR4D aColor )
 {
     for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
         m_LayersColors[ii] = aColor;
-
-    for( unsigned ii = 0; ii < DIM(m_ItemsColors); ii++ )
-        m_ItemsColors[ii] = aColor;
 }
diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp
index 76af622..52524e4 100644
--- a/common/draw_panel_gal.cpp
+++ b/common/draw_panel_gal.cpp
@@ -175,7 +175,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
         m_gal->BeginDrawing();
         m_gal->ClearScreen( settings->GetBackgroundColor() );
 
-        KIGFX::COLOR4D gridColor = settings->GetLayerColor( ITEM_GAL_LAYER( GRID_VISIBLE ) );
+        KIGFX::COLOR4D gridColor = settings->GetLayerColor( LAYER_GRID );
         m_gal->SetGridColor( gridColor );
 
         if( m_view->IsDirty() )
diff --git a/common/lset.cpp b/common/lset.cpp
index 110968c..d0a58d9 100644
--- a/common/lset.cpp
+++ b/common/lset.cpp
@@ -30,7 +30,7 @@
 #include <class_board.h>
 
 
-LSET::LSET( const LAYER_ID* aArray, unsigned aCount ) :
+LSET::LSET( const PCB_LAYER_ID* aArray, unsigned aCount ) :
     BASE_SET()
 {
     for( unsigned i=0; i<aCount; ++i )
@@ -42,7 +42,7 @@ LSET::LSET( unsigned aIdCount, int aFirst, ... ) :
     BASE_SET()
 {
     // The constructor, without the mandatory aFirst argument, could have been confused
-    // by the compiler with the LSET( LAYER_ID ).  With aFirst, that ambiguity is not
+    // by the compiler with the LSET( PCB_LAYER_ID ).  With aFirst, that ambiguity is not
     // present.  Therefore aIdCount must always be >=1.
     wxASSERT_MSG( aIdCount > 0, wxT( "aIdCount must be >= 1" ) );
 
@@ -56,11 +56,11 @@ LSET::LSET( unsigned aIdCount, int aFirst, ... ) :
 
         for( unsigned i=0;  i<aIdCount;  ++i )
         {
-            LAYER_ID id = (LAYER_ID) va_arg( ap, int );
+            PCB_LAYER_ID id = (PCB_LAYER_ID) va_arg( ap, int );
 
-            // printf( "%s: id:%d LAYER_ID_COUNT:%d\n", __func__, id, LAYER_ID_COUNT );
+            // printf( "%s: id:%d PCB_LAYER_ID_COUNT:%d\n", __func__, id, PCB_LAYER_ID_COUNT );
 
-            assert( unsigned( id ) < LAYER_ID_COUNT );
+            assert( unsigned( id ) < PCB_LAYER_ID_COUNT );
 
             set( id );
         }
@@ -70,7 +70,7 @@ LSET::LSET( unsigned aIdCount, int aFirst, ... ) :
 }
 
 
-const wxChar* LSET::Name( LAYER_ID aLayerId )
+const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
 {
     const wxChar* txt;
 
@@ -135,6 +135,7 @@ const wxChar* LSET::Name( LAYER_ID aLayerId )
     case B_Fab:             txt = wxT( "B.Fab" );           break;
 
     default:
+        std::cout << aLayerId << std::endl;
         wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
                             txt = wxT( "BAD INDEX!" );      break;
     }
@@ -146,7 +147,7 @@ const wxChar* LSET::Name( LAYER_ID aLayerId )
 LSEQ LSET::CuStack() const
 {
     // desired sequence
-    static const LAYER_ID sequence[] = {
+    static const PCB_LAYER_ID sequence[] = {
         F_Cu,
         In1_Cu,
         In2_Cu,
@@ -188,7 +189,7 @@ LSEQ LSET::CuStack() const
 LSEQ LSET::Technicals( LSET aSetToOmit ) const
 {
     // desired sequence
-    static const LAYER_ID sequence[] = {
+    static const PCB_LAYER_ID sequence[] = {
         B_Adhes,
         F_Adhes,
         B_Paste,
@@ -212,7 +213,7 @@ LSEQ LSET::Technicals( LSET aSetToOmit ) const
 LSEQ LSET::Users() const
 {
     // desired
-    static const LAYER_ID sequence[] = {
+    static const PCB_LAYER_ID sequence[] = {
         Dwgs_User,
         Cmts_User,
         Eco1_User,
@@ -333,7 +334,7 @@ int LSET::ParseHex( const char* aStart, int aCount )
 }
 
 
-LSEQ LSET::Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const
+LSEQ LSET::Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const
 {
     LSEQ ret;
 
@@ -342,7 +343,7 @@ LSEQ LSET::Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const
 
     for( unsigned i=0; i<aCount;  ++i )
     {
-        LAYER_ID id = aWishListSequence[i];
+        PCB_LAYER_ID id = aWishListSequence[i];
 
         if( test( id ) )
         {
@@ -356,7 +357,7 @@ LSEQ LSET::Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const
 
     for( unsigned i=0; i<aCount;  ++i )
     {
-        LAYER_ID id = aWishListSequence[i];
+        PCB_LAYER_ID id = aWishListSequence[i];
 
         if( test( id ) )
             ret.push_back( id );
@@ -374,7 +375,7 @@ LSEQ LSET::Seq() const
     for( unsigned i=0;  i<size();  ++i )
     {
         if( test(i) )
-            ret.push_back( LAYER_ID( i ) );
+            ret.push_back( PCB_LAYER_ID( i ) );
     }
 
     return ret;
@@ -384,7 +385,7 @@ LSEQ LSET::Seq() const
 LSEQ LSET::SeqStackupBottom2Top() const
 {
     // bottom-to-top stack-up layers
-    static const LAYER_ID sequence[] = {
+    static const PCB_LAYER_ID sequence[] = {
         B_Fab,
         B_CrtYd,
         B_Adhes,
@@ -441,7 +442,7 @@ LSEQ LSET::SeqStackupBottom2Top() const
 }
 
 
-LAYER_ID FlipLayer( LAYER_ID aLayerId, int aCopperLayersCount )
+PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
 {
     switch( aLayerId )
     {
@@ -470,7 +471,7 @@ LAYER_ID FlipLayer( LAYER_ID aLayerId, int aCopperLayersCount )
         if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
         {
             // internal copper layers count is aCopperLayersCount-2
-            LAYER_ID fliplayer = LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
+            PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
             // Ensure fliplayer has a value which does not crash pcbnew:
             if( fliplayer < F_Cu )
                 fliplayer = F_Cu;
@@ -574,7 +575,7 @@ LSET FlipLayerMask( LSET aMask, int aCopperLayersCount )
 }
 
 
-LAYER_ID LSET::ExtractLayer() const
+PCB_LAYER_ID LSET::ExtractLayer() const
 {
     unsigned set_count = count();
 
@@ -586,7 +587,7 @@ LAYER_ID LSET::ExtractLayer() const
     for( unsigned i=0; i < size(); ++i )
     {
         if( test( i ) )
-            return LAYER_ID( i );
+            return PCB_LAYER_ID( i );
     }
 
     wxASSERT( 0 );  // set_count was verified as 1 above, what did you break?
@@ -597,7 +598,7 @@ LAYER_ID LSET::ExtractLayer() const
 
 LSET LSET::InternalCuMask()
 {
-    static const LAYER_ID cu_internals[] = {
+    static const PCB_LAYER_ID cu_internals[] = {
         In1_Cu,
         In2_Cu,
         In3_Cu,
@@ -750,22 +751,22 @@ LSET LSET::BackMask()
 
 LSEQ LSET::UIOrder() const
 {
-    LAYER_ID order[LAYER_ID_COUNT];
+    PCB_LAYER_ID order[PCB_LAYER_ID_COUNT];
 
-    // Assmuming that the LAYER_ID order is according to preferred UI order, as of
+    // Assmuming that the PCB_LAYER_ID order is according to preferred UI order, as of
     // today this is true.  When that becomes not true, its easy to change the order
     // in here to compensate.
 
     for( unsigned i=0;  i<DIM(order);  ++i )
-        order[i] = LAYER_ID( i );
+        order[i] = PCB_LAYER_ID( i );
 
     return Seq( order, DIM( order ) );
 }
 
 
-LAYER_ID ToLAYER_ID( int aLayer )
+PCB_LAYER_ID ToLAYER_ID( int aLayer )
 {
-    wxASSERT( unsigned( aLayer ) < LAYER_ID_COUNT );
-    return LAYER_ID( aLayer );
+    wxASSERT( unsigned( aLayer ) < PCB_LAYER_ID_COUNT );
+    return PCB_LAYER_ID( aLayer );
 }
 
diff --git a/common/painter.cpp b/common/painter.cpp
index 3ee4c43..0c4e4d2 100644
--- a/common/painter.cpp
+++ b/common/painter.cpp
@@ -55,7 +55,7 @@ void RENDER_SETTINGS::update()
                                  m_layerOpacity );
 
     // Calculate darkened/highlighted variants of layer colors
-    for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
+    for( int i = 0; i < LAYER_ID_COUNT; i++ )
     {
         m_layerColorsHi[i]   = m_layerColors[i].Brightened( m_highlightFactor );
         m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp
index 331fc45..df45129 100644
--- a/common/preview_items/ruler_item.cpp
+++ b/common/preview_items/ruler_item.cpp
@@ -221,7 +221,7 @@ const BOX2I RULER_ITEM::ViewBBox() const
 
 void RULER_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
 {
-    aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY );
+    aLayers[0] = LAYER_GP_OVERLAY;
     aCount = 1;
 }
 
diff --git a/common/preview_items/simple_overlay_item.cpp b/common/preview_items/simple_overlay_item.cpp
index d8726d0..32b1de5 100644
--- a/common/preview_items/simple_overlay_item.cpp
+++ b/common/preview_items/simple_overlay_item.cpp
@@ -25,7 +25,6 @@
 
 #include <gal/graphics_abstraction_layer.h>
 #include <view/view.h>
-#include <layers_id_colors_and_visibility.h>
 
 
 using namespace KIGFX::PREVIEW;
@@ -51,7 +50,7 @@ void SIMPLE_OVERLAY_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
 
 void SIMPLE_OVERLAY_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
 {
-    static const int SelectionLayer = ITEM_GAL_LAYER( GP_OVERLAY );
+    static const int SelectionLayer = LAYER_GP_OVERLAY;
 
     aLayers[0] = SelectionLayer;
     aCount = 1;
diff --git a/common/swig/kicad.i b/common/swig/kicad.i
index 768b9b6..a3077d9 100644
--- a/common/swig/kicad.i
+++ b/common/swig/kicad.i
@@ -116,10 +116,10 @@ principle should be easily implemented by adapting the current STL containers.
 %template(intVector) std::vector<int>;
 %template(str_utf8_Map) std::map< std::string,UTF8 >;
 
-// wrapper of BASE_SEQ (see typedef std::vector<LAYER_ID> BASE_SEQ;)
-%template(base_seqVect) std::vector<enum LAYER_ID>;
+// wrapper of BASE_SEQ (see typedef std::vector<PCB_LAYER_ID> BASE_SEQ;)
+%template(base_seqVect) std::vector<enum PCB_LAYER_ID>;
 
-// TODO: wrapper of BASE_SET (see std::bitset<LAYER_ID_COUNT> BASE_SET;)
+// TODO: wrapper of BASE_SET (see std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;)
 
 
 // KiCad plugin handling
diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp
index cb11c61..ba87fe9 100644
--- a/common/view/view_group.cpp
+++ b/common/view/view_group.cpp
@@ -41,7 +41,7 @@
 using namespace KIGFX;
 
 VIEW_GROUP::VIEW_GROUP( VIEW* aView ) :
-    m_layer( ITEM_GAL_LAYER( GP_OVERLAY ) )
+    m_layer( LAYER_GP_OVERLAY )
 {
 }
 
diff --git a/common/worksheet_viewitem.cpp b/common/worksheet_viewitem.cpp
index 18f8fb9..8b7b148 100644
--- a/common/worksheet_viewitem.cpp
+++ b/common/worksheet_viewitem.cpp
@@ -131,7 +131,7 @@ void WORKSHEET_VIEWITEM::ViewDraw( int aLayer, VIEW* aView ) const
 void WORKSHEET_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
 {
     aCount = 1;
-    aLayers[0] = ITEM_GAL_LAYER( WORKSHEET );
+    aLayers[0] = LAYER_WORKSHEET;
 }
 
 
diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp
index d0141cf..1b41451 100644
--- a/eeschema/eeschema.cpp
+++ b/eeschema/eeschema.cpp
@@ -161,18 +161,20 @@ PGM_BASE& Pgm()
 }
 
 
-static COLOR4D s_layerColor[LAYERSCH_ID_COUNT];
+static COLOR4D s_layerColor[SCH_LAYER_ID_COUNT];
 
-COLOR4D GetLayerColor( LAYERSCH_ID aLayer )
+COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
 {
-    wxASSERT( unsigned( aLayer ) < DIM( s_layerColor ) );
-    return s_layerColor[aLayer];
+    unsigned layer = SCH_LAYER_INDEX( aLayer );
+    wxASSERT( layer < DIM( s_layerColor ) );
+    return s_layerColor[layer];
 }
 
-void SetLayerColor( COLOR4D aColor, LAYERSCH_ID aLayer )
+void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer )
 {
-    wxASSERT( unsigned( aLayer ) < DIM( s_layerColor ) );
-    s_layerColor[aLayer] = aColor;
+    unsigned layer = SCH_LAYER_INDEX( aLayer );
+    wxASSERT( layer < DIM( s_layerColor ) );
+    s_layerColor[layer] = aColor;
 }
 
 
@@ -186,34 +188,35 @@ static PARAM_CFG_ARRAY& cfg_params()
         // eeschema KIFACE comes in.
 
 #define CLR(x, y, z)\
-    ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ), &s_layerColor[y], z ) );
-
-        CLR( "ColorWireEx",             LAYER_WIRE,              COLOR4D( GREEN ) )
-        CLR( "ColorBusEx",              LAYER_BUS,               COLOR4D( BLUE ) )
-        CLR( "ColorConnEx",             LAYER_JUNCTION,          COLOR4D( GREEN ) )
-        CLR( "ColorLLabelEx",           LAYER_LOCLABEL,          COLOR4D( BLACK ) )
-        CLR( "ColorHLabelEx",           LAYER_HIERLABEL,         COLOR4D( BROWN ) )
-        CLR( "ColorGLabelEx",           LAYER_GLOBLABEL,         COLOR4D( RED ) )
-        CLR( "ColorPinNumEx",           LAYER_PINNUM,            COLOR4D( RED ) )
-        CLR( "ColorPinNameEx",          LAYER_PINNAM,            COLOR4D( CYAN ) )
-        CLR( "ColorFieldEx",            LAYER_FIELDS,            COLOR4D( MAGENTA ) )
-        CLR( "ColorReferenceEx",        LAYER_REFERENCEPART,     COLOR4D( CYAN ) )
-        CLR( "ColorValueEx",            LAYER_VALUEPART,         COLOR4D( CYAN ) )
-        CLR( "ColorNoteEx",             LAYER_NOTES,             COLOR4D( LIGHTBLUE ) )
-        CLR( "ColorBodyEx",             LAYER_DEVICE,            COLOR4D( RED ) )
-        CLR( "ColorBodyBgEx",           LAYER_DEVICE_BACKGROUND, COLOR4D( LIGHTYELLOW ) )
-        CLR( "ColorNetNameEx",          LAYER_NETNAM,            COLOR4D( DARKGRAY ) )
-        CLR( "ColorPinEx",              LAYER_PIN,               COLOR4D( RED ) )
-        CLR( "ColorSheetEx",            LAYER_SHEET,             COLOR4D( MAGENTA ) )
-        CLR( "ColorSheetFileNameEx",    LAYER_SHEETFILENAME,     COLOR4D( BROWN ) )
-        CLR( "ColorSheetNameEx",        LAYER_SHEETNAME,         COLOR4D( CYAN ) )
-        CLR( "ColorSheetLabelEx",       LAYER_SHEETLABEL,        COLOR4D( BROWN ) )
-        CLR( "ColorNoConnectEx",        LAYER_NOCONNECT,         COLOR4D( BLUE ) )
-        CLR( "ColorErcWEx",             LAYER_ERC_WARN,          COLOR4D( GREEN ) )
-        CLR( "ColorErcEEx",             LAYER_ERC_ERR,           COLOR4D( RED ) )
-        CLR( "ColorGridEx",             LAYER_GRID,              COLOR4D( DARKGRAY ) )
-        CLR( "ColorBgCanvasEx",         LAYER_BACKGROUND,        COLOR4D( WHITE ) )
-        CLR( "ColorBrighenedEx",        LAYER_BRIGHTENED,        COLOR4D( PUREMAGENTA ) )
+    ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ),\
+                                          &s_layerColor[SCH_LAYER_INDEX( y )], z ) );
+
+        CLR( "ColorWireEx",             LAYER_WIRE,                 COLOR4D( GREEN ) )
+        CLR( "ColorBusEx",              LAYER_BUS,                  COLOR4D( BLUE ) )
+        CLR( "ColorConnEx",             LAYER_JUNCTION,             COLOR4D( GREEN ) )
+        CLR( "ColorLLabelEx",           LAYER_LOCLABEL,             COLOR4D( BLACK ) )
+        CLR( "ColorHLabelEx",           LAYER_HIERLABEL,            COLOR4D( BROWN ) )
+        CLR( "ColorGLabelEx",           LAYER_GLOBLABEL,            COLOR4D( RED ) )
+        CLR( "ColorPinNumEx",           LAYER_PINNUM,               COLOR4D( RED ) )
+        CLR( "ColorPinNameEx",          LAYER_PINNAM,               COLOR4D( CYAN ) )
+        CLR( "ColorFieldEx",            LAYER_FIELDS,               COLOR4D( MAGENTA ) )
+        CLR( "ColorReferenceEx",        LAYER_REFERENCEPART,        COLOR4D( CYAN ) )
+        CLR( "ColorValueEx",            LAYER_VALUEPART,            COLOR4D( CYAN ) )
+        CLR( "ColorNoteEx",             LAYER_NOTES,                COLOR4D( LIGHTBLUE ) )
+        CLR( "ColorBodyEx",             LAYER_DEVICE,               COLOR4D( RED ) )
+        CLR( "ColorBodyBgEx",           LAYER_DEVICE_BACKGROUND,    COLOR4D( LIGHTYELLOW ) )
+        CLR( "ColorNetNameEx",          LAYER_NETNAM,               COLOR4D( DARKGRAY ) )
+        CLR( "ColorPinEx",              LAYER_PIN,                  COLOR4D( RED ) )
+        CLR( "ColorSheetEx",            LAYER_SHEET,                COLOR4D( MAGENTA ) )
+        CLR( "ColorSheetFileNameEx",    LAYER_SHEETFILENAME,        COLOR4D( BROWN ) )
+        CLR( "ColorSheetNameEx",        LAYER_SHEETNAME,            COLOR4D( CYAN ) )
+        CLR( "ColorSheetLabelEx",       LAYER_SHEETLABEL,           COLOR4D( BROWN ) )
+        CLR( "ColorNoConnectEx",        LAYER_NOCONNECT,            COLOR4D( BLUE ) )
+        CLR( "ColorErcWEx",             LAYER_ERC_WARN,             COLOR4D( GREEN ) )
+        CLR( "ColorErcEEx",             LAYER_ERC_ERR,              COLOR4D( RED ) )
+        CLR( "ColorGridEx",             LAYER_SCHEMATIC_GRID,       COLOR4D( DARKGRAY ) )
+        CLR( "ColorBgCanvasEx",         LAYER_SCHEMATIC_BACKGROUND, COLOR4D( WHITE ) )
+        CLR( "ColorBrighenedEx",        LAYER_BRIGHTENED,           COLOR4D( PUREMAGENTA ) )
     }
 
     return ca;
@@ -230,10 +233,10 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
 
     // Give a default colour for all layers
     // (actual color will be initialized by config)
-    for( LAYERSCH_ID ii = LAYER_FIRST; ii < LAYERSCH_ID_COUNT; ++ii )
+    for( SCH_LAYER_ID ii = SCH_LAYER_ID_START; ii < SCH_LAYER_ID_END; ++ii )
         SetLayerColor( COLOR4D( DARKGRAY ), ii );
 
-    SetLayerColor( COLOR4D::WHITE, LAYER_BACKGROUND );
+    SetLayerColor( COLOR4D::WHITE, LAYER_SCHEMATIC_BACKGROUND );
 
     // Must be called before creating the main frame in order to
     // display the real hotkeys in menus or tool tips
diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp
index 18d2764..79b2321 100644
--- a/eeschema/eeschema_config.cpp
+++ b/eeschema/eeschema_config.cpp
@@ -595,8 +595,8 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
 
     wxConfigLoadSetups( aCfg, GetConfigurationSettings() );
 
-    SetGridColor( GetLayerColor( LAYER_GRID ) );
-    SetDrawBgColor( GetLayerColor( LAYER_BACKGROUND ) );
+    SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
+    SetDrawBgColor( GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
 
     SetDefaultBusThickness( aCfg->Read( DefaultBusWidthEntry, DEFAULTBUSTHICKNESS ) );
     SetDefaultLineThickness( aCfg->Read( DefaultDrawLineWidthEntry, DEFAULTDRAWLINETHICKNESS ) );
@@ -759,8 +759,8 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
 {
     EDA_DRAW_FRAME::LoadSettings( aCfg );
 
-    SetGridColor( GetLayerColor( LAYER_GRID ) );
-    SetDrawBgColor( GetLayerColor( LAYER_BACKGROUND ) );
+    SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
+    SetDrawBgColor( GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
 
     SetDefaultLineThickness( aCfg->Read( DefaultDrawLineWidthEntry, DEFAULTDRAWLINETHICKNESS ) );
     SetDefaultPinLength( aCfg->Read( DefaultPinLengthEntry, DEFAULTPINLENGTH ) );
diff --git a/eeschema/general.h b/eeschema/general.h
index 6a094dc..9943373 100644
--- a/eeschema/general.h
+++ b/eeschema/general.h
@@ -30,6 +30,7 @@
 #define _GENERAL_H_
 
 #include <gal/color4d.h>
+#include <layers_id_colors_and_visibility.h>
 
 using KIGFX::COLOR4D;
 
@@ -68,48 +69,6 @@ class SCH_SHEET;
 
 #define GR_DEFAULT_DRAWMODE GR_COPY
 
-// this enum is for color management
-// Using here "LAYER" in name is due to historical reasons.
-// Eeschema does not actually use layers. It just uses "LAYER_XX" as identifier
-// mainly for item color
-typedef enum {
-    LAYER_FIRST,
-    LAYER_WIRE = LAYER_FIRST,
-    LAYER_BUS,
-    LAYER_JUNCTION,
-    LAYER_LOCLABEL,
-    LAYER_GLOBLABEL,
-    LAYER_HIERLABEL,
-    LAYER_PINNUM,
-    LAYER_PINNAM,
-    LAYER_REFERENCEPART,
-    LAYER_VALUEPART,
-    LAYER_FIELDS,
-    LAYER_DEVICE,
-    LAYER_NOTES,
-    LAYER_NETNAM,
-    LAYER_PIN,
-    LAYER_SHEET,
-    LAYER_SHEETNAME,
-    LAYER_SHEETFILENAME,
-    LAYER_SHEETLABEL,
-    LAYER_NOCONNECT,
-    LAYER_ERC_WARN,
-    LAYER_ERC_ERR,
-    LAYER_DEVICE_BACKGROUND,
-    LAYER_GRID,
-    LAYER_BACKGROUND,
-    LAYER_BRIGHTENED,
-    LAYERSCH_ID_COUNT
-} LAYERSCH_ID;
-
-inline LAYERSCH_ID operator++( LAYERSCH_ID& a )
-{
-    a = LAYERSCH_ID( int( a ) + 1 );
-    return a;
-}
-
-
 /* Rotation, mirror of graphic items in components bodies are handled by a
  * transform matrix.  The default matrix is useful to draw lib entries with
  * using this default matrix ( no rotation, no mirror but Y axis is bottom to top, and
@@ -140,8 +99,8 @@ void SetDefaultTextSize( int aSize );
 int GetDefaultBusThickness();
 void SetDefaultBusThickness( int aThickness );
 
-COLOR4D  GetLayerColor( LAYERSCH_ID aLayer );
-void     SetLayerColor( COLOR4D aColor, LAYERSCH_ID aLayer );
+COLOR4D  GetLayerColor( SCH_LAYER_ID aLayer );
+void     SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer );
 
 // Color to draw selected items
 COLOR4D GetItemSelectedColor();
diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp
index bd434c1..8a0d957 100644
--- a/eeschema/sch_base_frame.cpp
+++ b/eeschema/sch_base_frame.cpp
@@ -65,13 +65,13 @@ void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
 // Virtual from EDA_DRAW_FRAME
 COLOR4D SCH_BASE_FRAME::GetDrawBgColor() const
 {
-    return GetLayerColor( LAYER_BACKGROUND );
+    return GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
 }
 
 void SCH_BASE_FRAME::SetDrawBgColor( COLOR4D aColor)
 {
     m_drawBgColor= aColor;
-    SetLayerColor( aColor, LAYER_BACKGROUND );
+    SetLayerColor( aColor, LAYER_SCHEMATIC_BACKGROUND );
 }
 
 
diff --git a/eeschema/sch_item_struct.h b/eeschema/sch_item_struct.h
index 7f5dc1f..1022d40 100644
--- a/eeschema/sch_item_struct.h
+++ b/eeschema/sch_item_struct.h
@@ -116,7 +116,7 @@ public:
 class SCH_ITEM : public EDA_ITEM
 {
 protected:
-    LAYERSCH_ID    m_Layer;
+    SCH_LAYER_ID   m_Layer;
     EDA_ITEMS      m_connections;   ///< List of items connected to this item.
     wxPoint        m_storedPos;     ///< a temporary variable used in some move commands
                                     ///> to store a initial pos (of the item or mouse cursor)
@@ -161,14 +161,14 @@ public:
      * Function GetLayer
      * returns the layer this item is on.
      */
-    LAYERSCH_ID GetLayer() const { return m_Layer; }
+    SCH_LAYER_ID GetLayer() const { return m_Layer; }
 
     /**
      * Function SetLayer
      * sets the layer this item is on.
      * @param aLayer The layer number.
      */
-    void SetLayer( LAYERSCH_ID aLayer )  { m_Layer = aLayer; }
+    void SetLayer( SCH_LAYER_ID aLayer )  { m_Layer = aLayer; }
 
     /**
      * Function GetPenSize virtual pure
diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp
index 2d4eaf8..a4404fb 100644
--- a/eeschema/sch_legacy_plugin.cpp
+++ b/eeschema/sch_legacy_plugin.cpp
@@ -1578,7 +1578,7 @@ void SCH_LEGACY_PLUGIN::Format( SCH_SCREEN* aScreen )
         m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
 
     // This section is not used, but written for file compatibility
-    m_out->Print( 0, "EELAYER %d %d\n", LAYERSCH_ID_COUNT, 0 );
+    m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_END, 0 );
     m_out->Print( 0, "EELAYER END\n" );
 
     /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
@@ -1959,7 +1959,7 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
 
     wxString text = aText->GetText();
 
-    LAYERSCH_ID layer = aText->GetLayer();
+    SCH_LAYER_ID layer = aText->GetLayer();
 
     if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
     {
diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp
index 6f48374..c4fc86e 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -486,7 +486,7 @@ bool SCH_SCREEN::Save( FILE* aFile ) const
     }
 
     // This section is not used, but written for file compatibility
-    if( fprintf( aFile, "EELAYER %d %d\n", LAYERSCH_ID_COUNT, 0 ) < 0
+    if( fprintf( aFile, "EELAYER %d %d\n", SCH_LAYER_ID_END, 0 ) < 0
         || fprintf( aFile, "EELAYER END\n" ) < 0 )
         return false;
 
diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp
index 31dac55..802f469 100644
--- a/eeschema/viewlib_frame.cpp
+++ b/eeschema/viewlib_frame.cpp
@@ -629,8 +629,8 @@ void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
 {
     EDA_DRAW_FRAME::LoadSettings( aCfg );
 
-    SetGridColor( GetLayerColor( LAYER_GRID ) );
-    SetDrawBgColor( GetLayerColor( LAYER_BACKGROUND ) );
+    SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
+    SetDrawBgColor( GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
 
     aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
     aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
diff --git a/eeschema/widgets/widget_eeschema_color_config.cpp b/eeschema/widgets/widget_eeschema_color_config.cpp
index f8eabad..f0b86a8 100644
--- a/eeschema/widgets/widget_eeschema_color_config.cpp
+++ b/eeschema/widgets/widget_eeschema_color_config.cpp
@@ -90,7 +90,7 @@ static COLORBUTTON sheetColorButtons[] = {
 static COLORBUTTON miscColorButtons[] = {
     { _( "ERC warning" ),       LAYER_ERC_WARN },
     { _( "ERC error" ),         LAYER_ERC_ERR },
-    { _( "Grid" ),              LAYER_GRID },
+    { _( "Grid" ),              LAYER_SCHEMATIC_GRID },
     { _( "Brightened" ),        LAYER_BRIGHTENED },
     { wxT( "" ), -1 }                           // Sentinel marking end of list.
 };
@@ -104,9 +104,9 @@ static BUTTONINDEX buttonGroups[] = {
     { wxT( "" ), NULL }
 };
 
-static COLORBUTTON bgColorButton = { "", LAYER_BACKGROUND };
+static COLORBUTTON bgColorButton = { "", LAYER_SCHEMATIC_BACKGROUND };
 
-static COLOR4D currentColors[ LAYERSCH_ID_COUNT ];
+static COLOR4D currentColors[ SCH_LAYER_ID_COUNT ];
 
 
 WIDGET_EESCHEMA_COLOR_CONFIG::WIDGET_EESCHEMA_COLOR_CONFIG( wxWindow* aParent, EDA_DRAW_FRAME* aDrawFrame ) :
@@ -151,7 +151,7 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
             rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
             columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
 
-            COLOR4D color = GetLayerColor( LAYERSCH_ID( buttons->m_Layer ) );
+            COLOR4D color = GetLayerColor( SCH_LAYER_ID( buttons->m_Layer ) );
             currentColors[ buttons->m_Layer ] = color;
 
             wxMemoryDC iconDC;
@@ -217,7 +217,7 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
         columnBoxSizer->Add( selBgColorBtn, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
     }
 
-    currentColors[ LAYER_BACKGROUND ] = bgColor;
+    currentColors[ LAYER_SCHEMATIC_BACKGROUND ] = bgColor;
 
     // Dialog now needs to be resized, but the associated command is found elsewhere.
 }
@@ -275,11 +275,11 @@ bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl()
     // Check for color conflicts with background color to give user a chance to bail
     // out before making changes.
 
-    COLOR4D bgcolor = currentColors[LAYER_BACKGROUND];
+    COLOR4D bgcolor = currentColors[LAYER_SCHEMATIC_BACKGROUND];
 
-    for( LAYERSCH_ID clyr = LAYER_WIRE; clyr < LAYERSCH_ID_COUNT; ++clyr )
+    for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
     {
-        if( bgcolor == currentColors[ clyr ] && clyr != LAYER_BACKGROUND )
+        if( bgcolor == currentColors[ clyr ] && clyr != LAYER_SCHEMATIC_BACKGROUND )
         {
             warning = true;
             break;
@@ -300,15 +300,15 @@ bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl()
 
     // Update color of background
     GetDrawFrame()->SetDrawBgColor( bgcolor );
-    currentColors[ LAYER_BACKGROUND ] = bgcolor;
+    currentColors[ LAYER_SCHEMATIC_BACKGROUND ] = bgcolor;
 
 
-    for( LAYERSCH_ID clyr = LAYER_WIRE; clyr < LAYERSCH_ID_COUNT; ++clyr )
+    for( SCH_LAYER_ID clyr = LAYER_WIRE; clyr < SCH_LAYER_ID_END; ++clyr )
     {
         SetLayerColor( currentColors[ clyr ], clyr );
     }
 
-    GetDrawFrame()->SetGridColor( GetLayerColor( LAYER_GRID ) );
+    GetDrawFrame()->SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) );
     GetDrawFrame()->GetCanvas()->Refresh();
 
     return true;
diff --git a/gerbview/class_gerbview_layer_widget.cpp b/gerbview/class_gerbview_layer_widget.cpp
index 1470417..d484f9a 100644
--- a/gerbview/class_gerbview_layer_widget.cpp
+++ b/gerbview/class_gerbview_layer_widget.cpp
@@ -105,10 +105,10 @@ void GERBER_LAYER_WIDGET::ReFillRender()
 
 #define RR  LAYER_WIDGET::ROW   // Render Row abreviation to reduce source width
 
-             // text                id                      color       tooltip                 checked
-        RR( _( "Grid" ),            GERBER_GRID_VISIBLE,    WHITE,      _( "Show the (x,y) grid dots" ) ),
-        RR( _( "DCodes" ),          DCODES_VISIBLE,         WHITE,      _( "Show DCodes identification" ) ),
-        RR( _( "Neg. Obj." ),       NEGATIVE_OBJECTS_VISIBLE,  DARKGRAY,
+             // text            id                      color       tooltip                 checked
+        RR( _( "Grid" ),        LAYER_GERBVIEW_GRID,    WHITE,      _( "Show the (x,y) grid dots" ) ),
+        RR( _( "DCodes" ),      LAYER_DCODES,           WHITE,      _( "Show DCodes identification" ) ),
+        RR( _( "Neg. Obj." ),   LAYER_NEGATIVE_OBJECTS, DARKGRAY,
                                     _( "Show negative objects in this color" ) ),
     };
 
@@ -117,10 +117,10 @@ void GERBER_LAYER_WIDGET::ReFillRender()
         if( renderRows[row].color != COLOR4D::UNSPECIFIED )       // does this row show a color?
         {
             renderRows[row].color = myframe->GetVisibleElementColor(
-                                    (GERBER_VISIBLE_ID)renderRows[row].id );
+                                    ( GERBVIEW_LAYER_ID )renderRows[row].id );
         }
         renderRows[row].state = myframe->IsElementVisible(
-                                (GERBER_VISIBLE_ID)renderRows[row].id );
+                                ( GERBVIEW_LAYER_ID )renderRows[row].id );
     }
 
     AppendRenderRows( renderRows, DIM(renderRows) );
@@ -293,13 +293,13 @@ void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFin
 
 void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor )
 {
-    myframe->SetVisibleElementColor( (GERBER_VISIBLE_ID)aId, aColor );
+    myframe->SetVisibleElementColor( (GERBVIEW_LAYER_ID) aId, aColor );
     myframe->GetCanvas()->Refresh();
 }
 
 void GERBER_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
 {
-    myframe->SetElementVisibility( (GERBER_VISIBLE_ID)aId, isEnabled );
+    myframe->SetElementVisibility( (GERBVIEW_LAYER_ID) aId, isEnabled );
     myframe->GetCanvas()->Refresh();
 }
 
diff --git a/gerbview/dialogs/dialog_select_one_pcb_layer.cpp b/gerbview/dialogs/dialog_select_one_pcb_layer.cpp
index 1a847ce..4bd1255 100644
--- a/gerbview/dialogs/dialog_select_one_pcb_layer.cpp
+++ b/gerbview/dialogs/dialog_select_one_pcb_layer.cpp
@@ -31,7 +31,7 @@
 #include <gerbview_frame.h>
 #include <select_layers_to_pcb.h>
 
-#define NB_PCB_LAYERS LAYER_ID_COUNT
+#define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
 #define FIRST_COPPER_LAYER 0
 #define LAST_COPPER_LAYER 31
 
@@ -202,7 +202,7 @@ void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
 }
 
 // This function is a duplicate of
-// const wxChar* LSET::Name( LAYER_ID aLayerId )
+// const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
 // However it avoids a dependency to Pcbnew code.
 const wxString GetPCBDefaultLayerName( int aLayerId )
 {
diff --git a/gerbview/dialogs/gerbview_dialog_display_options_frame.cpp b/gerbview/dialogs/gerbview_dialog_display_options_frame.cpp
index 41ace4a..c1794fb 100644
--- a/gerbview/dialogs/gerbview_dialog_display_options_frame.cpp
+++ b/gerbview/dialogs/gerbview_dialog_display_options_frame.cpp
@@ -123,7 +123,7 @@ void DIALOG_DISPLAY_OPTIONS::initOptDialog( )
         }
     }
 
-    m_OptDisplayDCodes->SetValue( m_Parent->IsElementVisible( DCODES_VISIBLE ) );
+    m_OptDisplayDCodes->SetValue( m_Parent->IsElementVisible( LAYER_DCODES ) );
 
 
     m_OptZoomNoCenter->SetValue( m_Parent->GetCanvas()->GetEnableZoomNoCenter() );
@@ -161,7 +161,7 @@ void DIALOG_DISPLAY_OPTIONS::OnOKBUttonClick( wxCommandEvent& event )
     else
         m_Parent->m_DisplayOptions.m_DisplayPolygonsFill = true;
 
-    m_Parent->SetElementVisibility( DCODES_VISIBLE, m_OptDisplayDCodes->GetValue() );
+    m_Parent->SetElementVisibility( LAYER_DCODES, m_OptDisplayDCodes->GetValue() );
 
     int idx = m_ShowPageLimits->GetSelection();
 
diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp
index 022db48..64c630c 100644
--- a/gerbview/draw_gerber_screen.cpp
+++ b/gerbview/draw_gerber_screen.cpp
@@ -120,7 +120,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
 
     if( m_DisplayOptions.m_DisplayDCodes )
     {
-        COLOR4D dcode_color = GetVisibleElementColor( DCODES_VISIBLE );
+        COLOR4D dcode_color = GetVisibleElementColor( LAYER_DCODES );
         GetGerberLayout()->DrawItemsDCodeID( m_canvas, DC, GR_COPY, dcode_color );
     }
 
diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp
index 37f6cbe..df964f7 100644
--- a/gerbview/events_called_functions.cpp
+++ b/gerbview/events_called_functions.cpp
@@ -433,12 +433,12 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
         break;
 
     case ID_TB_OPTIONS_SHOW_DCODES:
-        SetElementVisibility( DCODES_VISIBLE, state );
+        SetElementVisibility( LAYER_DCODES, state );
         m_canvas->Refresh( true );
         break;
 
     case ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS:
-        SetElementVisibility( NEGATIVE_OBJECTS_VISIBLE, state );
+        SetElementVisibility( LAYER_NEGATIVE_OBJECTS, state );
         m_canvas->Refresh( true );
         break;
 
diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp
index ab23594..c444799 100644
--- a/gerbview/export_to_pcbnew.cpp
+++ b/gerbview/export_to_pcbnew.cpp
@@ -456,7 +456,7 @@ void GBR_TO_PCB_EXPORTER::writePcbHeader( LAYER_NUM* aLayerLookUpTable )
         fprintf( m_fp, "    (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
     }
 
-    for( int ii = B_Adhes; ii < LAYER_ID_COUNT; ii++ )
+    for( int ii = B_Adhes; ii < PCB_LAYER_ID_COUNT; ii++ )
     {
         fprintf( m_fp, "    (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
     }
diff --git a/gerbview/gerbview.h b/gerbview/gerbview.h
index a1e81f3..203951c 100644
--- a/gerbview/gerbview.h
+++ b/gerbview/gerbview.h
@@ -41,22 +41,7 @@
 /// List of page sizes
 extern const wxChar* g_GerberPageSizeList[8];
 
-// number fo draw layers in Gerbview
-#define GERBER_DRAWLAYERS_COUNT 32
 
-/**
- * Enum GERBER_VISIBLE_ID
- * is a set of visible GERBVIEW elements.
- */
-enum GERBER_VISIBLE_ID
-{
-    DCODES_VISIBLE = 1,         // visible item id cannot be 0
-                                // because this id is used as wxWidget id
-    GERBER_GRID_VISIBLE,
-    NEGATIVE_OBJECTS_VISIBLE,   // use the selected color to draw negative objects
-                                // instaed of background color, to make them visible
-    END_GERBER_VISIBLE_LIST     // sentinel
-};
 
 // Interpolation type
 enum Gerb_Interpolation
diff --git a/gerbview/gerbview_config.cpp b/gerbview/gerbview_config.cpp
index d53b028..2d7b4b4 100644
--- a/gerbview/gerbview_config.cpp
+++ b/gerbview/gerbview_config.cpp
@@ -89,13 +89,13 @@ PARAM_CFG_ARRAY& GERBVIEW_FRAME::GetConfigurationSettings()
                                                    &m_displayMode, 2, 0, 2 ) );
     m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true,
                                                         wxT( "DCodeColorEx" ),
-                                                        &g_ColorsSettings.m_ItemsColors[
-                                                            DCODES_VISIBLE],
+                                                        &g_ColorsSettings.m_LayersColors[
+                                                            LAYER_DCODES],
                                                         WHITE ) );
     m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true,
                                                         wxT( "NegativeObjectsColorEx" ),
-                                                        &g_ColorsSettings.m_ItemsColors[
-                                                            NEGATIVE_OBJECTS_VISIBLE],
+                                                        &g_ColorsSettings.m_LayersColors[
+                                                            LAYER_NEGATIVE_OBJECTS],
                                                         DARKGRAY ) );
     m_configSettings.push_back( new PARAM_CFG_BOOL( true,
                                                     wxT( "DisplayPolarCoordinates" ),
diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp
index 7404f06..85d99b6 100644
--- a/gerbview/gerbview_frame.cpp
+++ b/gerbview/gerbview_frame.cpp
@@ -293,9 +293,9 @@ void GERBVIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
 
     bool tmp;
     aCfg->Read( cfgShowDCodes, &tmp, true );
-    SetElementVisibility( DCODES_VISIBLE, tmp );
+    SetElementVisibility( LAYER_DCODES, tmp );
     aCfg->Read( cfgShowNegativeObjects, &tmp, false );
-    SetElementVisibility( NEGATIVE_OBJECTS_VISIBLE, tmp );
+    SetElementVisibility( LAYER_NEGATIVE_OBJECTS, tmp );
 
     // because we have more than one file history, we must read this one
     // using a specific path
@@ -320,9 +320,9 @@ void GERBVIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
 
     aCfg->Write( cfgShowPageSizeOption, GetPageSettings().GetType() );
     aCfg->Write( cfgShowBorderAndTitleBlock, m_showBorderAndTitleBlock );
-    aCfg->Write( cfgShowDCodes, IsElementVisible( DCODES_VISIBLE ) );
+    aCfg->Write( cfgShowDCodes, IsElementVisible( LAYER_DCODES ) );
     aCfg->Write( cfgShowNegativeObjects,
-                 IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
+                 IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
 
     // Save the drill file history list.
     // Because we have  more than one file history, we must save this one
@@ -362,20 +362,20 @@ void GERBVIEW_FRAME::ReFillLayerWidget()
 }
 
 
-void GERBVIEW_FRAME::SetElementVisibility( GERBER_VISIBLE_ID aItemIdVisible,
+void GERBVIEW_FRAME::SetElementVisibility( GERBVIEW_LAYER_ID aItemIdVisible,
                                            bool aNewState )
 {
     switch( aItemIdVisible )
     {
-    case DCODES_VISIBLE:
+    case LAYER_DCODES:
         m_DisplayOptions.m_DisplayDCodes = aNewState;
         break;
 
-    case NEGATIVE_OBJECTS_VISIBLE:
+    case LAYER_NEGATIVE_OBJECTS:
         m_DisplayOptions.m_DisplayNegativeObjects = aNewState;
         break;
 
-    case GERBER_GRID_VISIBLE:
+    case LAYER_GERBVIEW_GRID:
         SetGridVisibility( aNewState );
         break;
 
@@ -562,19 +562,19 @@ void GERBVIEW_FRAME::UpdateTitleAndInfo()
 }
 
 
-bool GERBVIEW_FRAME::IsElementVisible( GERBER_VISIBLE_ID aItemIdVisible ) const
+bool GERBVIEW_FRAME::IsElementVisible( GERBVIEW_LAYER_ID aItemIdVisible ) const
 {
     switch( aItemIdVisible )
     {
-    case DCODES_VISIBLE:
+    case LAYER_DCODES:
         return m_DisplayOptions.m_DisplayDCodes;
         break;
 
-    case NEGATIVE_OBJECTS_VISIBLE:
+    case LAYER_NEGATIVE_OBJECTS:
         return m_DisplayOptions.m_DisplayNegativeObjects;
         break;
 
-    case GERBER_GRID_VISIBLE:
+    case LAYER_GERBVIEW_GRID:
         return IsGridVisible();
         break;
 
@@ -607,18 +607,18 @@ bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const
 }
 
 
-COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible ) const
+COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( GERBVIEW_LAYER_ID aItemIdVisible ) const
 {
     COLOR4D color = COLOR4D::UNSPECIFIED;
 
     switch( aItemIdVisible )
     {
-    case NEGATIVE_OBJECTS_VISIBLE:
-    case DCODES_VISIBLE:
+    case LAYER_NEGATIVE_OBJECTS:
+    case LAYER_DCODES:
         color = m_colorsSettings->GetItemColor( aItemIdVisible );
         break;
 
-    case GERBER_GRID_VISIBLE:
+    case LAYER_GERBVIEW_GRID:
         color = GetGridColor();
         break;
 
@@ -634,21 +634,21 @@ COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible
 void GERBVIEW_FRAME::SetGridVisibility( bool aVisible )
 {
     EDA_DRAW_FRAME::SetGridVisibility( aVisible );
-    m_LayersManager->SetRenderState( GERBER_GRID_VISIBLE, aVisible );
+    m_LayersManager->SetRenderState( LAYER_GERBVIEW_GRID, aVisible );
 }
 
 
-void GERBVIEW_FRAME::SetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible,
+void GERBVIEW_FRAME::SetVisibleElementColor( GERBVIEW_LAYER_ID aItemIdVisible,
                                              COLOR4D aColor )
 {
     switch( aItemIdVisible )
     {
-    case NEGATIVE_OBJECTS_VISIBLE:
-    case DCODES_VISIBLE:
+    case LAYER_NEGATIVE_OBJECTS:
+    case LAYER_DCODES:
         m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
         break;
 
-    case GERBER_GRID_VISIBLE:
+    case LAYER_GERBVIEW_GRID:
         SetGridColor( aColor );
         m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
         break;
@@ -661,8 +661,8 @@ void GERBVIEW_FRAME::SetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible,
 
 COLOR4D GERBVIEW_FRAME::GetNegativeItemsColor() const
 {
-    if( IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) )
-        return GetVisibleElementColor( NEGATIVE_OBJECTS_VISIBLE );
+    if( IsElementVisible( LAYER_NEGATIVE_OBJECTS ) )
+        return GetVisibleElementColor( LAYER_NEGATIVE_OBJECTS );
     else
         return GetDrawBgColor();
 }
diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h
index 8646ff8..6819fb2 100644
--- a/gerbview/gerbview_frame.h
+++ b/gerbview/gerbview_frame.h
@@ -33,6 +33,7 @@
 
 #include <config_params.h>
 #include <draw_frame.h>
+#include <layers_id_colors_and_visibility.h>
 
 #include <gerbview.h>
 #include <class_gbr_layout.h>
@@ -285,19 +286,19 @@ public:
      * Function IsElementVisible
      * tests whether a given element category is visible. Keep this as an
      * inline function.
-     * @param aItemIdVisible is an item id from the enum GERBER_VISIBLE_ID
+     * @param aItemIdVisible is an item id from the enum GERBVIEW_LAYER_ID
      * @return bool - true if the element is visible.
      */
-    bool    IsElementVisible( GERBER_VISIBLE_ID aItemIdVisible ) const;
+    bool    IsElementVisible( GERBVIEW_LAYER_ID aItemIdVisible ) const;
 
     /**
      * Function SetElementVisibility
      * changes the visibility of an element category
-     * @param aItemIdVisible is an item id from the enum GERBER_VISIBLE_ID
+     * @param aItemIdVisible is an item id from the enum GERBVIEW_LAYER_ID
      * @param aNewState = The new visibility state of the element category
-     *  (see enum PCB_VISIBLE)
+     *  (see enum PCB)
      */
-    void    SetElementVisibility( GERBER_VISIBLE_ID aItemIdVisible, bool aNewState );
+    void    SetElementVisibility( GERBVIEW_LAYER_ID aItemIdVisible, bool aNewState );
 
     /**
      * Function SetGridVisibility(), virtual from EDA_DRAW_FRAME
@@ -334,9 +335,9 @@ public:
      * Function GetVisibleElementColor
      * returns the color of a gerber visible element.
      */
-    COLOR4D GetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible ) const;
+    COLOR4D GetVisibleElementColor( GERBVIEW_LAYER_ID aItemIdVisible ) const;
 
-    void    SetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible, COLOR4D aColor );
+    void    SetVisibleElementColor( GERBVIEW_LAYER_ID aItemIdVisible, COLOR4D aColor );
 
     /**
      * Function GetLayerColor
diff --git a/gerbview/hotkeys.cpp b/gerbview/hotkeys.cpp
index ce9c169..e95cade 100644
--- a/gerbview/hotkeys.cpp
+++ b/gerbview/hotkeys.cpp
@@ -185,12 +185,12 @@ bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit
         break;
 
     case HK_GBR_NEGATIVE_DISPLAY_ONOFF:
-        SetElementVisibility( NEGATIVE_OBJECTS_VISIBLE, not IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
+        SetElementVisibility( LAYER_NEGATIVE_OBJECTS, not IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
         m_canvas->Refresh();
         break;
 
     case HK_GBR_DCODE_DISPLAY_ONOFF:
-        SetElementVisibility( DCODES_VISIBLE, not IsElementVisible( DCODES_VISIBLE ) );
+        SetElementVisibility( LAYER_DCODES, not IsElementVisible( LAYER_DCODES ) );
         m_canvas->Refresh();
         break;
 
diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp
index 23802f9..6d77c26 100644
--- a/gerbview/toolbars_gerber.cpp
+++ b/gerbview/toolbars_gerber.cpp
@@ -505,13 +505,13 @@ void GERBVIEW_FRAME::OnUpdatePolygonsDrawMode( wxUpdateUIEvent& aEvent )
 
 void GERBVIEW_FRAME::OnUpdateShowDCodes( wxUpdateUIEvent& aEvent )
 {
-    aEvent.Check( IsElementVisible( DCODES_VISIBLE ) );
+    aEvent.Check( IsElementVisible( LAYER_DCODES ) );
 }
 
 
 void GERBVIEW_FRAME::OnUpdateShowNegativeItems( wxUpdateUIEvent& aEvent )
 {
-    aEvent.Check( IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
+    aEvent.Check( IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
 }
 
 
diff --git a/include/class_board_design_settings.h b/include/class_board_design_settings.h
index a7b200e..a55d988 100644
--- a/include/class_board_design_settings.h
+++ b/include/class_board_design_settings.h
@@ -144,14 +144,14 @@ public:
                                             // if empty, use footprint name as default
     bool    m_RefDefaultVisibility;         ///< Default ref text visibility on fp creation
     int     m_RefDefaultlayer;              ///< Default ref text layer on fp creation
-                                            // should be a LAYER_ID, but use an int
+                                            // should be a PCB_LAYER_ID, but use an int
                                             // to save this param in config
 
     wxString    m_ValueDefaultText;         ///< Default value text on fp creation
                                             // if empty, use footprint name as default
     bool    m_ValueDefaultVisibility;       ///< Default value text visibility on fp creation
     int     m_ValueDefaultlayer;            ///< Default value text layer on fp creation
-                                            // should be a LAYER_ID, but use an int
+                                            // should be a PCB_LAYER_ID, but use an int
                                             // to save this param in config
 
     // Miscellaneous
@@ -447,7 +447,7 @@ public:
      * @param aLayerId = The layer to be tested
      * @return bool - true if the layer is visible.
      */
-    inline bool IsLayerVisible( LAYER_ID aLayerId ) const
+    inline bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const
     {
         // If a layer is disabled, it is automatically invisible
         return (m_visibleLayers & m_enabledLayers)[aLayerId];
@@ -459,7 +459,7 @@ public:
      * @param aLayerId = The layer to be changed
      * @param aNewState = The new visibility state of the layer
      */
-    void SetLayerVisibility( LAYER_ID aLayerId, bool aNewState );
+    void SetLayerVisibility( PCB_LAYER_ID aLayerId, bool aNewState );
 
     /**
      * Function GetVisibleElements
@@ -487,13 +487,11 @@ public:
      * inline function.
      * @param aElementCategory is from the enum by the same name
      * @return bool - true if the element is visible.
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    inline bool IsElementVisible( int aElementCategory ) const
+    inline bool IsElementVisible( GAL_LAYER_ID aElementCategory ) const
     {
-        assert( aElementCategory >= 0 && aElementCategory < END_PCB_VISIBLE_LIST );
-
-        return ( m_visibleElements & ( 1 << aElementCategory ) );
+        return ( m_visibleElements & ( 1 << GAL_LAYER_INDEX( aElementCategory ) ) );
     }
 
     /**
@@ -501,9 +499,9 @@ public:
      * changes the visibility of an element category
      * @param aElementCategory is from the enum by the same name
      * @param aNewState = The new visibility state of the element category
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    void SetElementVisibility( int aElementCategory, bool aNewState );
+    void SetElementVisibility( GAL_LAYER_ID aElementCategory, bool aNewState );
 
     /**
      * Function GetEnabledLayers
@@ -528,7 +526,7 @@ public:
      * @param aLayerId = The layer to be tested
      * @return bool - true if the layer is enabled
      */
-    inline bool IsLayerEnabled( LAYER_ID aLayerId ) const
+    inline bool IsLayerEnabled( PCB_LAYER_ID aLayerId ) const
     {
         return m_enabledLayers[aLayerId];
     }
diff --git a/include/class_board_item.h b/include/class_board_item.h
index 34c275c..3ccee95 100644
--- a/include/class_board_item.h
+++ b/include/class_board_item.h
@@ -77,7 +77,7 @@ class BOARD_ITEM : public EDA_ITEM
     void SetBack( EDA_ITEM* aBack )       { Pback = aBack; }
 
 protected:
-    LAYER_ID    m_Layer;
+    PCB_LAYER_ID    m_Layer;
 
     static int getTrailingInt( wxString aStr );
     static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
@@ -129,7 +129,7 @@ public:
      * Function GetLayer
      * returns the primary layer this item is on.
      */
-    LAYER_ID GetLayer() const { return m_Layer; }
+    PCB_LAYER_ID GetLayer() const { return m_Layer; }
 
     /**
      * Function GetLayerSet
@@ -146,7 +146,7 @@ public:
      * is virtual because some items (in fact: class DIMENSION)
      * have a slightly different initialization
      */
-    virtual void SetLayer( LAYER_ID aLayer )
+    virtual void SetLayer( PCB_LAYER_ID aLayer )
     {
         // trap any invalid layers, then go find the caller and fix it.
         // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
@@ -179,7 +179,7 @@ public:
      * @param aLayer The layer to test for.
      * @return bool - true if on given layer, else false.
      */
-    virtual bool IsOnLayer( LAYER_ID aLayer ) const
+    virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
     {
         return m_Layer == aLayer;
     }
diff --git a/include/class_colors_design_settings.h b/include/class_colors_design_settings.h
index 1ba91e4..aa0ffc0 100644
--- a/include/class_colors_design_settings.h
+++ b/include/class_colors_design_settings.h
@@ -46,9 +46,6 @@ public:
     // Common to Eeschema, Pcbnew, GerbView
     COLOR4D m_LayersColors[LAYER_ID_COUNT];     ///< Layer colors (tracks and graphic items)
 
-    // Common to Eeschema, Pcbnew
-    COLOR4D m_ItemsColors[32];                  ///< All others items but layers
-
 public:
     COLORS_DESIGN_SETTINGS();
 
@@ -69,14 +66,14 @@ public:
     /**
      * Function GetItemColor
      * @return the color for an item which is one of the item indices given
-     * in pcbstruct.h, enum PCB_VISIBLE or in schematic
+     * in enum PCB_LAYER_ID
      */
     COLOR4D GetItemColor( int aItemIdx ) const;
 
     /**
      * Function SetItemColor
      * sets the color for an item which is one of the item indices given
-     * in pcbstruct.h, enum PCB_VISIBLE or in schematic
+     * in enum PCB_LAYER_ID
      */
     void SetItemColor( int aItemIdx, COLOR4D aColor );
 
diff --git a/include/class_pcb_screen.h b/include/class_pcb_screen.h
index 348add1..c95dc9f 100644
--- a/include/class_pcb_screen.h
+++ b/include/class_pcb_screen.h
@@ -41,9 +41,9 @@ class UNDO_REDO_CONTAINER;
 class PCB_SCREEN : public BASE_SCREEN
 {
 public:
-    LAYER_ID m_Active_Layer;
-    LAYER_ID m_Route_Layer_TOP;
-    LAYER_ID m_Route_Layer_BOTTOM;
+    PCB_LAYER_ID m_Active_Layer;
+    PCB_LAYER_ID m_Route_Layer_TOP;
+    PCB_LAYER_ID m_Route_Layer_BOTTOM;
 
 public:
 
diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h
index 0343c66..5104f4c 100644
--- a/include/layers_id_colors_and_visibility.h
+++ b/include/layers_id_colors_and_visibility.h
@@ -47,15 +47,35 @@ class BOARD;
  */
 typedef int     LAYER_NUM;
 
+/**
+ * A quick note on layer IDs:
+ *
+ * The layers are stored in separate enums so that certain functions can
+ * take in the enums as datatypes and don't have to know about layers from
+ * other applications.
+ *
+ * Layers that are shared between applications should be in the GAL_LAYER_ID enum.
+ *
+ * The PCB_LAYER_ID struct must start at zero for compatibility with legacy board files.
+ *
+ * Some functions accept any layer ID, so they start at zero (i.e. F_Cu) and go up to
+ * the LAYER_ID_COUNT, which needs to be kept up-to-date if new enums are added.
+ */
+
 
 /**
- * Enum LAYER_ID
- * is the set of PCB layers.  It has nothing to do with gerbers or view layers.
- * One of these cannot be "incremented".
+ * Enum PCB_LAYER_ID
+ * This is the definition of all layers used in Pcbnew
+ * The PCB layer types are fixed at value 0 through LAYER_ID_COUNT,
+ * to ensure compatibility with legacy board files.
+ *
  */
-enum LAYER_ID: int
+enum PCB_LAYER_ID: int
 {
-    F_Cu,           // 0
+    UNDEFINED_LAYER = -1,
+    UNSELECTED_LAYER = -2,
+
+    F_Cu = 0,           // 0
     In1_Cu,
     In2_Cu,
     In3_Cu,
@@ -113,22 +133,181 @@ enum LAYER_ID: int
     B_Fab,
     F_Fab,
 
-    LAYER_ID_COUNT,
+    PCB_LAYER_ID_COUNT
+};
 
-    UNDEFINED_LAYER = -1,
-    UNSELECTED_LAYER = -2,
+#define MAX_CU_LAYERS       (B_Cu - F_Cu + 1)
+
+/// Dedicated layers for net names used in Pcbnew
+enum NETNAMES_LAYER_ID: int
+{
+
+    NETNAMES_LAYER_ID_START = PCB_LAYER_ID_COUNT,
+
+    /// Reserved space for board layer netnames
+
+    NETNAMES_LAYER_ID_RESERVED = NETNAMES_LAYER_ID_START + PCB_LAYER_ID_COUNT,
+
+    /// Additional netnames layers (not associated with a PCB layer)
+
+    LAYER_PAD_FR_NETNAMES,
+    LAYER_PAD_BK_NETNAMES,
+    LAYER_PADS_NETNAMES,
+
+    NETNAMES_LAYER_ID_END
 };
 
+/// Macro for obtaining netname layer for a given PCB layer
+#define NETNAMES_LAYER_INDEX( layer )   ( NETNAMES_LAYER_ID_START + layer )
+
+/// GAL layers are "virtual" layers, i.e. not tied into design data.
+/// Some layers here are shared between applications.
+enum GAL_LAYER_ID: int
+{
+    GAL_LAYER_ID_START = NETNAMES_LAYER_ID_END,
+
+    LAYER_VIAS = GAL_LAYER_ID_START,
+    LAYER_VIA_MICROVIA,
+    LAYER_VIA_BBLIND,
+    LAYER_VIA_THROUGH,
+    LAYER_NON_PLATED,
+    LAYER_MOD_TEXT_FR,
+    LAYER_MOD_TEXT_BK,
+    LAYER_MOD_TEXT_INVISIBLE,   ///< text marked as invisible
+    LAYER_ANCHOR,
+    LAYER_PAD_FR,
+    LAYER_PAD_BK,
+    LAYER_RATSNEST,
+    LAYER_GRID,
+    LAYER_GRID_AXES,
+    LAYER_NO_CONNECTS,          ///< show a marker on pads with no nets
+    LAYER_MOD_FR,               ///< show modules on front
+    LAYER_MOD_BK,               ///< show modules on back
+    LAYER_MOD_VALUES,           ///< show modules values (when texts are visibles)
+    LAYER_MOD_REFERENCES,       ///< show modules references (when texts are visibles)
+    LAYER_TRACKS,
+    LAYER_PADS,                 ///< multilayer pads, usually with holes
+    LAYER_PADS_HOLES,
+    LAYER_VIAS_HOLES,
+    LAYER_DRC,                  ///< drc markers
+    LAYER_WORKSHEET,            ///< worksheet frame
+    LAYER_GP_OVERLAY,           ///< general purpose overlay
+
+    /// This is the end of the layers used for visibility bitmasks in Pcbnew
+    /// There can be at most 32 layers above here.
+    GAL_LAYER_ID_BITMASK_END,
+
+    /// Add new GAL layers here
+
+    GAL_LAYER_ID_END
+};
+
+/// Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS
+#define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
+
+inline GAL_LAYER_ID operator++( GAL_LAYER_ID& a )
+{
+    a = GAL_LAYER_ID( int( a ) + 1 );
+    return a;
+}
+
+/// Used for via types
+inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
+{
+    GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
+    wxASSERT( t <= GAL_LAYER_ID_END );
+    return t;
+}
+
+/// Eeschema drawing layers
+enum SCH_LAYER_ID: int
+{
+    SCH_LAYER_ID_START = GAL_LAYER_ID_END,
+
+    LAYER_WIRE = SCH_LAYER_ID_START,
+    LAYER_BUS,
+    LAYER_JUNCTION,
+    LAYER_LOCLABEL,
+    LAYER_GLOBLABEL,
+    LAYER_HIERLABEL,
+    LAYER_PINNUM,
+    LAYER_PINNAM,
+    LAYER_REFERENCEPART,
+    LAYER_VALUEPART,
+    LAYER_FIELDS,
+    LAYER_DEVICE,
+    LAYER_NOTES,
+    LAYER_NETNAM,
+    LAYER_PIN,
+    LAYER_SHEET,
+    LAYER_SHEETNAME,
+    LAYER_SHEETFILENAME,
+    LAYER_SHEETLABEL,
+    LAYER_NOCONNECT,
+    LAYER_ERC_WARN,
+    LAYER_ERC_ERR,
+    LAYER_DEVICE_BACKGROUND,
+    LAYER_SCHEMATIC_GRID,
+    LAYER_SCHEMATIC_BACKGROUND,
+    LAYER_BRIGHTENED,
+
+    SCH_LAYER_ID_END
+};
+
+#define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
+
+#define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
+
+inline SCH_LAYER_ID operator++( SCH_LAYER_ID& a )
+{
+    a = SCH_LAYER_ID( int( a ) + 1 );
+    return a;
+}
+
+// number of draw layers in Gerbview
+#define GERBER_DRAWLAYERS_COUNT 32
+
+/// GerbView draw layers
+enum GERBVIEW_LAYER_ID: int
+{
+    GERBVIEW_LAYER_ID_START = SCH_LAYER_ID_END,
+
+    /// GerbView draw layers
+    GERBVIEW_LAYER_ID_RESERVED = GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT,
+
+    LAYER_DCODES,
+    LAYER_NEGATIVE_OBJECTS,
+    LAYER_GERBVIEW_GRID,
+    LAYER_GERBVIEW_AXES,
+    LAYER_GERBVIEW_BACKGROUND,
+
+    GERBVIEW_LAYER_ID_END
+};
+
+/// Must update this if you add any enums after GerbView!
+#define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
+
+
+// Some elements do not have yet a visibility control
+// from a dialog, but have a visibility control flag.
+// Here is a mask to set them visible, to be sure they are displayed
+// after loading a board for instance
+#define MIN_VISIBILITY_MASK int( (1 << GAL_LAYER_INDEX( LAYER_TRACKS ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_PADS ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_PADS_HOLES ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_WORKSHEET ) ) +\
+                 ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
 
-#define MAX_CU_LAYERS       (B_Cu - F_Cu + 1)
 
 /// A sequence of layers, a sequence provides a certain order.
-typedef std::vector<LAYER_ID>   BASE_SEQ;
+typedef std::vector<PCB_LAYER_ID>   BASE_SEQ;
 
 
 /**
  * Class LSEQ
- * is a sequence (and therefore also a set) of LAYER_IDs.  A sequence provides
+ * is a sequence (and therefore also a set) of PCB_LAYER_IDs.  A sequence provides
  * a certain order.
  * <p>
  * It can also be used as an iterator:
@@ -166,19 +345,19 @@ public:
 
     operator bool ()        { return m_index < size(); }
 
-    LAYER_ID operator * () const
+    PCB_LAYER_ID operator * () const
     {
         return at( m_index );       // throws std::out_of_range
     }
 };
 
 
-typedef std::bitset<LAYER_ID_COUNT>     BASE_SET;
+typedef std::bitset<PCB_LAYER_ID_COUNT>     BASE_SET;
 
 
 /**
  * Class LSET
- * is a set of LAYER_IDs.  It can be converted to numerous purpose LSEQs using
+ * is a set of PCB_LAYER_IDs.  It can be converted to numerous purpose LSEQs using
  * the various member functions, most of which are based on Seq(). The advantage
  * of converting to LSEQ using purposeful code, is it removes any dependency
  * on order/sequence inherent in this set.
@@ -190,7 +369,7 @@ public:
     // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
     // That excludes  "LSET s = 0;" and excludes "LSET s = -1;", etc.
     // LSET s = 0;  needs to be removed from the code, this accomplishes that.
-    // Remember LSET( LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
+    // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
     // to prevent that surprize.  Therefore LSET's constructor suite is significantly
     // different than the base class from which it is derived.
 
@@ -212,8 +391,8 @@ public:
     }
 
     /**
-     * Constructor LSET( LAYER_ID )
-     * takes a LAYER_ID and sets that bit.  This makes the following code into
+     * Constructor LSET( PCB_LAYER_ID )
+     * takes a PCB_LAYER_ID and sets that bit.  This makes the following code into
      * a bug:
      *
      * <code>   LSET s = 0;  </code>
@@ -226,26 +405,26 @@ public:
      *
      * for an empty set.
      */
-    LSET( LAYER_ID aLayer ) :    // LAYER_ID deliberately exludes int and relatives
+    LSET( PCB_LAYER_ID aLayer ) :    // PCB_LAYER_ID deliberately exludes int and relatives
         BASE_SET()
     {
         set( aLayer );
     }
 
     /**
-     * Constructor LSET( const LAYER_ID* aArray, unsigned aCount )
+     * Constructor LSET( const PCB_LAYER_ID* aArray, unsigned aCount )
      * works well with an array or LSEQ.
      */
-    LSET( const LAYER_ID* aArray, unsigned aCount );
+    LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
 
     /**
-     * Constructor LSET( unsigned, LAYER_ID, ...)
-     * takes one or more LAYER_IDs in the argument list to construct
+     * Constructor LSET( unsigned, PCB_LAYER_ID, ...)
+     * takes one or more PCB_LAYER_IDs in the argument list to construct
      * the set.  Typically only used in static construction.
      *
-     * @param aIdCount is the number of LAYER_IDs which follow.
+     * @param aIdCount is the number of PCB_LAYER_IDs which follow.
      * @param aFirst is the first included in @a aIdCount and must always be present, and can
-     *  be followed by any number of additional LAYER_IDs so long as @a aIdCount accurately
+     *  be followed by any number of additional PCB_LAYER_IDs so long as @a aIdCount accurately
      *  reflects the count.
      *
      *  Parameter is 'int' to avoid va_start undefined behavior.
@@ -256,7 +435,7 @@ public:
      * Function Name
      * returns the fixed name association with aLayerId.
      */
-    static const wxChar* Name( LAYER_ID aLayerId );
+    static const wxChar* Name( PCB_LAYER_ID aLayerId );
 
     /**
      * Function InternalCuMask()
@@ -267,7 +446,7 @@ public:
 
     /**
      * Function AllCuMask
-     * returns a mask holding the requested number of Cu LAYER_IDs.
+     * returns a mask holding the requested number of Cu PCB_LAYER_IDs.
      */
     static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
 
@@ -364,15 +543,15 @@ public:
      * returns an LSEQ from the union of this LSET and a desired sequence.  The LSEQ
      * element will be in the same sequence as aWishListSequence if they are present.
      * @param aWishListSequence establishes the order of the returned LSEQ, and the LSEQ will only
-     * contiain LAYER_IDs which are present in this set.
+     * contain PCB_LAYER_IDs which are present in this set.
      * @param aCount is the length of aWishListSequence array.
      */
-    LSEQ Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const;
+    LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
 
     /**
      * Function Seq
-     * returns a LSEQ from this LSET in ascending LAYER_ID order.  Each LSEQ
-     * element will be in the same sequence as in LAYER_ID and only present
+     * returns a LSEQ from this LSET in ascending PCB_LAYER_ID order.  Each LSEQ
+     * element will be in the same sequence as in PCB_LAYER_ID and only present
      * in the resultant LSEQ if present in this set.  Therefore the sequence is
      * subject to change, use it only when enumeration and not order is important.
      */
@@ -408,138 +587,31 @@ public:
     std::string FmtBin() const;
 
     /**
-     * Find the first set LAYER_ID. Returns UNDEFINED_LAYER if more
+     * Find the first set PCB_LAYER_ID. Returns UNDEFINED_LAYER if more
      * than one is set or UNSELECTED_LAYER if none is set.
      */
-    LAYER_ID ExtractLayer() const;
+    PCB_LAYER_ID ExtractLayer() const;
 
 private:
 
-    /// Take this off the market, it may not be used because of LSET( LAYER_ID ).
+    /// Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
     LSET( unsigned long __val )
     {
         // not usable, it's private.
     }
 };
 
-
-/**
- * Enum PCB_VISIBLE
- * is a set of visible PCB elements.
- * @see BOARD::SetVisibleElementColor()
- * @see BOARD::SetVisibleElement()
- */
-enum PCB_VISIBLE
-{
-    VIAS_VISIBLE,
-    VIA_MICROVIA_VISIBLE,
-    VIA_BBLIND_VISIBLE,
-    VIA_THROUGH_VISIBLE,
-    NON_PLATED_VISIBLE,
-    MOD_TEXT_FR_VISIBLE,
-    MOD_TEXT_BK_VISIBLE,
-    MOD_TEXT_INVISIBLE,         ///< text marked as invisible
-    ANCHOR_VISIBLE,
-    PAD_FR_VISIBLE,
-    PAD_BK_VISIBLE,
-    RATSNEST_VISIBLE,
-    GRID_VISIBLE,
-
-    // the rest of these do not currently support color changes:
-    NO_CONNECTS_VISIBLE,        ///< show a marker on pads with no nets
-    MOD_FR_VISIBLE,             ///< show modules on front
-    MOD_BK_VISIBLE,             ///< show modules on back
-    MOD_VALUES_VISIBLE,         ///< show modules values (when texts are visibles)
-    MOD_REFERENCES_VISIBLE,     ///< show modules references (when texts are visibles)
-
-    TRACKS_VISIBLE,
-    PADS_VISIBLE,               ///< multilayer pads, usually with holes
-    PADS_HOLES_VISIBLE,
-    VIAS_HOLES_VISIBLE,
-
-    DRC_VISIBLE,                ///< drc markers
-    WORKSHEET,                  ///< worksheet frame
-    GP_OVERLAY,                 ///< general purpose overlay
-
-    END_PCB_VISIBLE_LIST        // sentinel
-};
-
-// Some elements do not have yet a visibility control
-// from a dialog, but have a visibility control flag.
-// Here is a mask to set them visible, to be sure they are displayed
-// after loading a board for instance
-#define MIN_VISIBILITY_MASK int( (1 << TRACKS_VISIBLE) +\
-                 (1 << PADS_VISIBLE) +\
-                 (1 << PADS_HOLES_VISIBLE) +\
-                 (1 << VIAS_HOLES_VISIBLE) +\
-                 (1 << DRC_VISIBLE) +\
-                 (1 << WORKSHEET) +\
-                 (1 << GP_OVERLAY) )
-
-/**
- * Enum NETNAMES_VISIBLE
- * is a set of layers specific for displaying net names.
- * Their visiblity is not supposed to be saved in a board file,
- * they are only to be used by the GAL.
- */
-#if 0
-// was:
-enum NETNAMES_VISIBLE
-{
-    LAYER_1_NETNAMES_VISIBLE,   // bottom layer
-    LAYER_2_NETNAMES_VISIBLE,
-    LAYER_3_NETNAMES_VISIBLE,
-    LAYER_4_NETNAMES_VISIBLE,
-    LAYER_5_NETNAMES_VISIBLE,
-    LAYER_6_NETNAMES_VISIBLE,
-    LAYER_7_NETNAMES_VISIBLE,
-    LAYER_8_NETNAMES_VISIBLE,
-    LAYER_9_NETNAMES_VISIBLE,
-    LAYER_10_NETNAMES_VISIBLE,
-    LAYER_11_NETNAMES_VISIBLE,
-    LAYER_12_NETNAMES_VISIBLE,
-    LAYER_13_NETNAMES_VISIBLE,
-    LAYER_14_NETNAMES_VISIBLE,
-    LAYER_15_NETNAMES_VISIBLE,
-    LAYER_16_NETNAMES_VISIBLE,  // top layer
-
-    PAD_FR_NETNAMES_VISIBLE,
-    PAD_BK_NETNAMES_VISIBLE,
-    PADS_NETNAMES_VISIBLE,
-
-    END_NETNAMES_VISIBLE_LIST   // sentinel
-};
-#else
-enum NETNAMES_VISIBLE
-{
-    PAD_FR_NETNAMES_VISIBLE = B_Cu+1,
-    PAD_BK_NETNAMES_VISIBLE,
-    PADS_NETNAMES_VISIBLE,
-
-    END_NETNAMES_VISIBLE_LIST   // sentinel
-};
-#endif
-
-
-/// macro for obtaining layer number for specific item (eg. pad or text)
-#define ITEM_GAL_LAYER(layer)       (LAYER_ID_COUNT + layer)
-
-#define NETNAMES_GAL_LAYER(layer)   (LAYER_ID_COUNT + END_PCB_VISIBLE_LIST + layer )
-
-/// number of *all* GAL layers including PCB and item layers
-#define TOTAL_LAYER_COUNT	        (LAYER_ID_COUNT + END_PCB_VISIBLE_LIST + END_NETNAMES_VISIBLE_LIST)
-
 /**
  * Function IsValidLayer
  * tests whether a given integer is a valid layer index, i.e. can
- * be safely put in a LAYER_ID
+ * be safely put in a PCB_LAYER_ID
  * @param aLayerId = Layer index to test. It can be an int, so its
  * useful during I/O
  * @return true if aLayerIndex is a valid layer index
  */
 inline bool IsValidLayer( LAYER_NUM aLayerId )
 {
-    return unsigned( aLayerId ) < LAYER_ID_COUNT;
+    return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
 }
 
 /**
@@ -550,7 +622,7 @@ inline bool IsValidLayer( LAYER_NUM aLayerId )
  */
 inline bool IsPcbLayer( LAYER_NUM aLayer )
 {
-    return aLayer >= F_Cu && aLayer < LAYER_ID_COUNT;
+    return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
 }
 
 /**
@@ -572,7 +644,7 @@ inline bool IsCopperLayer( LAYER_NUM aLayerId )
  */
 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
 {
-    return aLayerId > B_Cu && aLayerId <= LAYER_ID_COUNT;
+    return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
 }
 
 /**
@@ -581,7 +653,7 @@ inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
  * @param aLayerId = Layer to test
  * @return true if aLayer is a user layer
  */
-inline bool IsUserLayer( LAYER_ID aLayerId )
+inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
 {
     return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
 }
@@ -599,7 +671,7 @@ inline bool IsUserLayer( LAYER_ID aLayerId )
 /**
  * Layer classification: check if it's a front layer
  */
-inline bool IsFrontLayer( LAYER_ID aLayerId )
+inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
 {
     switch( aLayerId )
     {
@@ -622,7 +694,7 @@ inline bool IsFrontLayer( LAYER_ID aLayerId )
 /**
  * Layer classification: check if it's a back layer
  */
-inline bool IsBackLayer( LAYER_ID aLayerId )
+inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
 {
     switch( aLayerId )
     {
@@ -648,11 +720,11 @@ inline bool IsBackLayer( LAYER_ID aLayerId )
  * some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... )
  * are swapped between front and back sides
  * internal layers are flipped only if the copper layers count is known
- * @param aLayer = the LAYER_ID to flip
+ * @param aLayer = the PCB_LAYER_ID to flip
  * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  *  internal layers will be not flipped because the layer count is not known
  */
-LAYER_ID FlipLayer( LAYER_ID aLayerId, int aCopperLayersCount = 0 );
+PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
 
 /**
  * Calculate the mask layer when flipping a footprint
@@ -671,13 +743,13 @@ LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
 inline int GetNetnameLayer( int aLayer )
 {
     if( IsCopperLayer( aLayer ) )
-        return NETNAMES_GAL_LAYER( aLayer );
-    else if( aLayer == ITEM_GAL_LAYER( PADS_VISIBLE ) )
-        return NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE );
-    else if( aLayer == ITEM_GAL_LAYER( PAD_FR_VISIBLE ) )
-        return NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE );
-    else if( aLayer == ITEM_GAL_LAYER( PAD_BK_VISIBLE ) )
-        return NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE );
+        return NETNAMES_LAYER_INDEX( aLayer );
+    else if( aLayer == LAYER_PADS )
+        return LAYER_PADS_NETNAMES;
+    else if( aLayer == LAYER_PAD_FR )
+        return LAYER_PAD_FR_NETNAMES;
+    else if( aLayer == LAYER_PAD_BK )
+        return LAYER_PAD_BK_NETNAMES;
 
     // Fallback
     return Cmts_User;
@@ -691,11 +763,11 @@ inline int GetNetnameLayer( int aLayer )
  */
 inline bool IsNetnameLayer( LAYER_NUM aLayer )
 {
-    return aLayer >= NETNAMES_GAL_LAYER( F_Cu ) &&
-           aLayer < NETNAMES_GAL_LAYER( END_NETNAMES_VISIBLE_LIST );
+    return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
+           aLayer < NETNAMES_LAYER_ID_END;
 }
 
 
-LAYER_ID ToLAYER_ID( int aLayer );
+PCB_LAYER_ID ToLAYER_ID( int aLayer );
 
 #endif // LAYERS_ID_AND_VISIBILITY_H_
diff --git a/include/origin_viewitem.h b/include/origin_viewitem.h
index 1e55611..4cec850 100644
--- a/include/origin_viewitem.h
+++ b/include/origin_viewitem.h
@@ -54,7 +54,7 @@ public:
 
     void ViewGetLayers( int aLayers[], int& aCount ) const override
     {
-        aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY );
+        aLayers[0] = LAYER_GP_OVERLAY;
         aCount = 1;
     }
 
diff --git a/include/painter.h b/include/painter.h
index 3d52b86..4f0df3d 100644
--- a/include/painter.h
+++ b/include/painter.h
@@ -231,16 +231,16 @@ protected:
     std::set<unsigned int> m_activeLayers; ///< Stores active layers number
 
     ///> Colors for all layers (normal)
-    COLOR4D m_layerColors[TOTAL_LAYER_COUNT];
+    COLOR4D m_layerColors[LAYER_ID_COUNT];
 
     ///> Colors for all layers (highlighted)
-    COLOR4D m_layerColorsHi[TOTAL_LAYER_COUNT];
+    COLOR4D m_layerColorsHi[LAYER_ID_COUNT];
 
     ///> Colors for all layers (selected)
-    COLOR4D m_layerColorsSel[TOTAL_LAYER_COUNT];
+    COLOR4D m_layerColorsSel[LAYER_ID_COUNT];
 
     ///> Colors for all layers (darkened)
-    COLOR4D m_layerColorsDark[TOTAL_LAYER_COUNT];
+    COLOR4D m_layerColorsDark[LAYER_ID_COUNT];
 
     /// Parameters for display modes
     bool    m_hiContrastEnabled;    ///< High contrast display mode on/off
diff --git a/include/preview_items/bright_box.h b/include/preview_items/bright_box.h
index bb2ec9c..2af9bee 100644
--- a/include/preview_items/bright_box.h
+++ b/include/preview_items/bright_box.h
@@ -58,7 +58,7 @@ public:
 
     void ViewGetLayers( int aLayers[], int& aCount ) const override
     {
-        aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY );
+        aLayers[0] = LAYER_GP_OVERLAY ;
         aCount = 1;
     }
 
diff --git a/include/preview_items/selection_area.h b/include/preview_items/selection_area.h
index 9c274c8..c860ee4 100644
--- a/include/preview_items/selection_area.h
+++ b/include/preview_items/selection_area.h
@@ -46,6 +46,7 @@ namespace PREVIEW
 class SELECTION_AREA : public SIMPLE_OVERLAY_ITEM
 {
 public:
+    static const int SelectionLayer = LAYER_GP_OVERLAY;
 
     SELECTION_AREA();
 
diff --git a/include/preview_items/simple_overlay_item.h b/include/preview_items/simple_overlay_item.h
index b2d673d..37f3581 100644
--- a/include/preview_items/simple_overlay_item.h
+++ b/include/preview_items/simple_overlay_item.h
@@ -26,6 +26,7 @@
 
 #include <base_struct.h>
 
+#include <layers_id_colors_and_visibility.h>
 #include <gal/color4d.h>
 
 namespace KIGFX
diff --git a/include/view/view.h b/include/view/view.h
index 108b2df..6f436fb 100644
--- a/include/view/view.h
+++ b/include/view/view.h
@@ -637,7 +637,8 @@ public:
         m_useDrawPriority = aFlag;
     }
 
-    static const int VIEW_MAX_LAYERS = 256;      ///< maximum number of layers that may be shown
+    static const int VIEW_MAX_LAYERS = 512;      ///< maximum number of layers that may be shown
+
 
 private:
     struct VIEW_LAYER
diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h
index 13fc5a6..d86a245 100644
--- a/include/wxBasePcbFrame.h
+++ b/include/wxBasePcbFrame.h
@@ -606,7 +606,7 @@ public:
      * @param aDlgPosition = position of dialog ( defualt = centered)
      * @return the selected layer id
      */
-    LAYER_ID SelectLayer( LAYER_ID aDefaultLayer,
+    PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer,
                           LSET aNotAllowedLayersMask = LSET(),
                           wxPoint aDlgPosition = wxDefaultPosition );
 
@@ -615,13 +615,13 @@ public:
      */
     void SelectCopperLayerPair();
 
-    virtual void SwitchLayer( wxDC* DC, LAYER_ID layer );
+    virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer );
 
     /**
      * Function SetActiveLayer
      * will change the currently active layer to \a aLayer.
      */
-    virtual void SetActiveLayer( LAYER_ID aLayer )
+    virtual void SetActiveLayer( PCB_LAYER_ID aLayer )
     {
         GetScreen()->m_Active_Layer = aLayer;
     }
@@ -630,7 +630,7 @@ public:
      * Function GetActiveLayer
      * returns the active layer
      */
-    virtual LAYER_ID GetActiveLayer() const
+    virtual PCB_LAYER_ID GetActiveLayer() const
     {
         return GetScreen()->m_Active_Layer;
     }
diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h
index b6c0766..2a8e7a1 100644
--- a/include/wxPcbStruct.h
+++ b/include/wxPcbStruct.h
@@ -606,7 +606,7 @@ public:
      * will change the currently active layer to \a aLayer and also
      * update the PCB_LAYER_WIDGET.
      */
-    virtual void SetActiveLayer( LAYER_ID aLayer ) override;
+    virtual void SetActiveLayer( PCB_LAYER_ID aLayer ) override;
 
     /**
      * Function IsElementVisible
@@ -614,18 +614,18 @@ public:
      * inline function.
      * @param aElement is from the enum by the same name
      * @return bool - true if the element is visible.
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    bool IsElementVisible( int aElement ) const;
+    bool IsElementVisible( GAL_LAYER_ID aElement ) const;
 
     /**
      * Function SetElementVisibility
      * changes the visibility of an element category
      * @param aElement is from the enum by the same name
-     * @param aNewState = The new visibility state of the element category
-     * @see enum PCB_VISIBLE
+     * @param GAL_LAYER_ID = The new visibility state of the element category
+     * @see enum PCB_LAYER_ID
      */
-    void SetElementVisibility( int aElement, bool aNewState );
+    void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState );
 
     /**
      * Function SetVisibleAlls
@@ -1300,7 +1300,7 @@ public:
     bool MergeCollinearTracks( TRACK* track, wxDC* DC, int end );
 
     void Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC );
-    void SwitchLayer( wxDC* DC, LAYER_ID layer ) override;
+    void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ) override;
 
     /**
      * Function Add45DegreeSegment
@@ -1500,7 +1500,7 @@ public:
     DRAWSEGMENT* Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T shape, wxDC* DC );
     void End_Edge( DRAWSEGMENT* Segment, wxDC* DC );
     void Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC );
-    void Delete_Drawings_All_Layer( LAYER_ID aLayer );
+    void Delete_Drawings_All_Layer( PCB_LAYER_ID aLayer );
 
     // Dimension handling:
     void ShowDimensionPropertyDialog( DIMENSION* aDimension, wxDC* aDC );
diff --git a/pcbnew/autorouter/auto_place_footprints.cpp b/pcbnew/autorouter/auto_place_footprints.cpp
index ddb75be..94ed5a4 100644
--- a/pcbnew/autorouter/auto_place_footprints.cpp
+++ b/pcbnew/autorouter/auto_place_footprints.cpp
@@ -132,7 +132,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
     wxPoint             PosOK;
     wxPoint             memopos;
     int                 error;
-    LAYER_ID            lay_tmp_TOP, lay_tmp_BOTTOM;
+    PCB_LAYER_ID            lay_tmp_TOP, lay_tmp_BOTTOM;
 
     // Undo: init list
     PICKED_ITEMS_LIST   newList;
diff --git a/pcbnew/autorouter/graphpcb.cpp b/pcbnew/autorouter/graphpcb.cpp
index 840bfcb..119eed1 100644
--- a/pcbnew/autorouter/graphpcb.cpp
+++ b/pcbnew/autorouter/graphpcb.cpp
@@ -323,7 +323,7 @@ void TraceSegmentPcb( TRACK* aTrack, int color, int marge, int op_logic )
         int uy1 = aTrack->GetEnd().y - RoutingMatrix.GetBrdCoordOrigin().y;
 
         // Ordinary track
-        LAYER_ID layer = aTrack->GetLayer();
+        PCB_LAYER_ID layer = aTrack->GetLayer();
 
         if( color == VIA_IMPOSSIBLE )
             layer = UNDEFINED_LAYER;
diff --git a/pcbnew/autorouter/move_and_route_event_functions.cpp b/pcbnew/autorouter/move_and_route_event_functions.cpp
index 90aad41..6adf7cc 100644
--- a/pcbnew/autorouter/move_and_route_event_functions.cpp
+++ b/pcbnew/autorouter/move_and_route_event_functions.cpp
@@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::OnPlaceOrRouteFootprints( wxCommandEvent& event )
     }
 
     // Erase ratsnest if needed
-    if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) )
+    if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
         DrawGeneralRatsnest( &dc );
 
     GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST;
diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp
index d192bb2..ac52b9d 100644
--- a/pcbnew/basepcbframe.cpp
+++ b/pcbnew/basepcbframe.cpp
@@ -375,9 +375,9 @@ void PCB_BASE_FRAME::Show3D_Frame( wxCommandEvent& event )
 
 
 // Note: virtual, overridden in PCB_EDIT_FRAME;
-void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, LAYER_ID layer )
+void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer )
 {
-    LAYER_ID preslayer = GetActiveLayer();
+    PCB_LAYER_ID preslayer = GetActiveLayer();
     DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
 
     // Check if the specified layer matches the present layer
@@ -595,15 +595,15 @@ GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide()
                                     GetActiveLayer() );
 
     // account for the globals
-    guide.SetIgnoreMTextsMarkedNoShow( ! m_Pcb->IsElementVisible( MOD_TEXT_INVISIBLE ));
-    guide.SetIgnoreMTextsOnBack( ! m_Pcb->IsElementVisible( MOD_TEXT_BK_VISIBLE ));
-    guide.SetIgnoreMTextsOnFront( ! m_Pcb->IsElementVisible( MOD_TEXT_FR_VISIBLE ));
-    guide.SetIgnoreModulesOnBack( ! m_Pcb->IsElementVisible( MOD_BK_VISIBLE ) );
-    guide.SetIgnoreModulesOnFront( ! m_Pcb->IsElementVisible( MOD_FR_VISIBLE ) );
-    guide.SetIgnorePadsOnBack( ! m_Pcb->IsElementVisible( PAD_BK_VISIBLE ) );
-    guide.SetIgnorePadsOnFront( ! m_Pcb->IsElementVisible( PAD_FR_VISIBLE ) );
-    guide.SetIgnoreModulesVals( ! m_Pcb->IsElementVisible( MOD_VALUES_VISIBLE ) );
-    guide.SetIgnoreModulesRefs( ! m_Pcb->IsElementVisible( MOD_REFERENCES_VISIBLE ) );
+    guide.SetIgnoreMTextsMarkedNoShow( ! m_Pcb->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
+    guide.SetIgnoreMTextsOnBack( ! m_Pcb->IsElementVisible( LAYER_MOD_TEXT_BK ) );
+    guide.SetIgnoreMTextsOnFront( ! m_Pcb->IsElementVisible( LAYER_MOD_TEXT_FR ) );
+    guide.SetIgnoreModulesOnBack( ! m_Pcb->IsElementVisible( LAYER_MOD_BK ) );
+    guide.SetIgnoreModulesOnFront( ! m_Pcb->IsElementVisible( LAYER_MOD_FR ) );
+    guide.SetIgnorePadsOnBack( ! m_Pcb->IsElementVisible( LAYER_PAD_BK ) );
+    guide.SetIgnorePadsOnFront( ! m_Pcb->IsElementVisible( LAYER_PAD_FR ) );
+    guide.SetIgnoreModulesVals( ! m_Pcb->IsElementVisible( LAYER_MOD_VALUES ) );
+    guide.SetIgnoreModulesRefs( ! m_Pcb->IsElementVisible( LAYER_MOD_REFERENCES ) );
 
     return guide;
 }
diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp
index 81d6036..9393a4b 100644
--- a/pcbnew/block.cpp
+++ b/pcbnew/block.cpp
@@ -317,7 +317,7 @@ void PCB_EDIT_FRAME::Block_SelectItems()
     {
         for( MODULE* module = m_Pcb->m_Modules;  module;  module = module->Next() )
         {
-            LAYER_ID layer = module->GetLayer();
+            PCB_LAYER_ID layer = module->GetLayer();
 
             if( module->HitTest( GetScreen()->m_BlockLocate, selectOnlyComplete )
                 && ( !module->IsLocked() || blockOpts.includeLockedModules ) )
diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp
index 1e38be4..47a91d0 100644
--- a/pcbnew/board_items_to_polygon_shape_transform.cpp
+++ b/pcbnew/board_items_to_polygon_shape_transform.cpp
@@ -63,7 +63,7 @@ static void addTextSegmToPoly( int x0, int y0, int xf, int yf )
 }
 
 
-void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines )
+void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines )
 {
     // Number of segments to convert a circle to a polygon
     const int       segcountforcircle   = 18;
@@ -94,7 +94,7 @@ void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET&
     for( int ii = 0; ii < GetAreaCount(); ii++ )
     {
         ZONE_CONTAINER* zone = GetArea( ii );
-        LAYER_ID        zonelayer = zone->GetLayer();
+        PCB_LAYER_ID        zonelayer = zone->GetLayer();
 
         if( zonelayer == aLayer )
             zone->TransformSolidAreasShapesToPolygonSet(
@@ -126,7 +126,7 @@ void BOARD::ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET&
 }
 
 
-void MODULE::TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
+void MODULE::TransformPadsShapesWithClearanceToPolygon( PCB_LAYER_ID aLayer,
                         SHAPE_POLY_SET& aCornerBuffer,
                         int                    aInflateValue,
                         int                    aCircleToSegmentsCount,
@@ -201,7 +201,7 @@ void MODULE::TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
  *  initial radius * aCorrectionFactor
  */
 void MODULE::TransformGraphicShapesWithClearanceToPolygonSet(
-                        LAYER_ID        aLayer,
+                        PCB_LAYER_ID        aLayer,
                         SHAPE_POLY_SET& aCornerBuffer,
                         int             aInflateValue,
                         int             aCircleToSegmentsCount,
@@ -277,7 +277,7 @@ void MODULE::TransformGraphicShapesWithClearanceToPolygonSet(
 // Same as function TransformGraphicShapesWithClearanceToPolygonSet but
 // this only render text
 void MODULE::TransformGraphicTextWithClearanceToPolygonSet(
-                        LAYER_ID        aLayer,
+                        PCB_LAYER_ID        aLayer,
                         SHAPE_POLY_SET& aCornerBuffer,
                         int             aInflateValue,
                         int             aCircleToSegmentsCount,
diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp
index 18bc8ee..86337ee 100644
--- a/pcbnew/class_board.cpp
+++ b/pcbnew/class_board.cpp
@@ -84,7 +84,7 @@ BOARD::BOARD() :
 
     BuildListOfNets();                      // prepare pad and netlist containers.
 
-    for( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
+    for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
     {
         m_Layer[layer].m_name = GetStandardLayerName( ToLAYER_ID( layer ) );
 
@@ -503,7 +503,7 @@ void BOARD::PopHighLight()
 }
 
 
-bool BOARD::SetLayerDescr( LAYER_ID aIndex, const LAYER& aLayer )
+bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
 {
     if( unsigned( aIndex ) < DIM( m_Layer ) )
     {
@@ -516,11 +516,11 @@ bool BOARD::SetLayerDescr( LAYER_ID aIndex, const LAYER& aLayer )
 
 #include <stdio.h>
 
-const LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
+const PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
 {
 
     // Look for the BOARD specific copper layer names
-    for( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
+    for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
     {
         if ( IsCopperLayer( layer ) && ( m_Layer[ layer ].m_name == aLayerName ) )
         {
@@ -529,7 +529,7 @@ const LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
     }
 
     // Otherwise fall back to the system standard layer names
-    for( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
+    for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
     {
         if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
         {
@@ -540,7 +540,7 @@ const LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
     return UNDEFINED_LAYER;
 }
 
-const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
+const wxString BOARD::GetLayerName( PCB_LAYER_ID aLayer ) const
 {
     // All layer names are stored in the BOARD.
     if( IsLayerEnabled( aLayer ) )
@@ -556,7 +556,7 @@ const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
     return GetStandardLayerName( aLayer );
 }
 
-bool BOARD::SetLayerName( LAYER_ID aLayer, const wxString& aLayerName )
+bool BOARD::SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName )
 {
     if( !IsCopperLayer( aLayer ) )
         return false;
@@ -584,7 +584,7 @@ bool BOARD::SetLayerName( LAYER_ID aLayer, const wxString& aLayerName )
 #else
         for( LSEQ cu = GetEnabledLayers().CuStack();  cu;  ++cu )
         {
-            LAYER_ID id = *cu;
+            PCB_LAYER_ID id = *cu;
 
             // veto changing the name if it exists elsewhere.
             if( id != aLayer && nameTemp == m_Layer[id].m_name )
@@ -602,7 +602,7 @@ bool BOARD::SetLayerName( LAYER_ID aLayer, const wxString& aLayerName )
 }
 
 
-LAYER_T BOARD::GetLayerType( LAYER_ID aLayer ) const
+LAYER_T BOARD::GetLayerType( PCB_LAYER_ID aLayer ) const
 {
     if( !IsCopperLayer( aLayer ) )
         return LT_SIGNAL;
@@ -616,7 +616,7 @@ LAYER_T BOARD::GetLayerType( LAYER_ID aLayer ) const
 }
 
 
-bool BOARD::SetLayerType( LAYER_ID aLayer, LAYER_T aLayerType )
+bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType )
 {
     if( !IsCopperLayer( aLayer ) )
         return false;
@@ -717,9 +717,9 @@ void BOARD::SetVisibleElements( int aMask )
     // Call SetElementVisibility for each item
     // to ensure specific calculations that can be needed by some items,
     // just changing the visibility flags could be not sufficient.
-    for( int ii = 0; ii < PCB_VISIBLE( END_PCB_VISIBLE_LIST ); ii++ )
+    for( GAL_LAYER_ID ii = GAL_LAYER_ID_START; ii < GAL_LAYER_ID_BITMASK_END; ++ii )
     {
-        int item_mask = 1 << ii;
+        int item_mask = 1 << GAL_LAYER_INDEX( ii );
         SetElementVisibility( ii, aMask & item_mask );
     }
 }
@@ -731,7 +731,7 @@ void BOARD::SetVisibleAlls()
 
     // Call SetElementVisibility for each item,
     // to ensure specific calculations that can be needed by some items
-    for( int ii = 0; ii < PCB_VISIBLE(END_PCB_VISIBLE_LIST); ii++ )
+    for( GAL_LAYER_ID ii = GAL_LAYER_ID_START; ii < GAL_LAYER_ID_BITMASK_END; ++ii )
         SetElementVisibility( ii, true );
 }
 
@@ -742,24 +742,24 @@ int BOARD::GetVisibleElements() const
 }
 
 
-bool BOARD::IsElementVisible( int aPCB_VISIBLE ) const
+bool BOARD::IsElementVisible( GAL_LAYER_ID LAYER_aPCB ) const
 {
-    return m_designSettings.IsElementVisible( aPCB_VISIBLE );
+    return m_designSettings.IsElementVisible( LAYER_aPCB );
 }
 
 
-void BOARD::SetElementVisibility( int aPCB_VISIBLE, bool isEnabled )
+void BOARD::SetElementVisibility( GAL_LAYER_ID LAYER_aPCB, bool isEnabled )
 {
-    m_designSettings.SetElementVisibility( aPCB_VISIBLE, isEnabled );
+    m_designSettings.SetElementVisibility( LAYER_aPCB, isEnabled );
 
-    switch( aPCB_VISIBLE )
+    switch( LAYER_aPCB )
     {
-    case RATSNEST_VISIBLE:
+    case LAYER_RATSNEST:
 
         // we must clear or set the CH_VISIBLE flags to hide/show ratsnest
         // because we have a tool to show/hide ratsnest relative to a pad or a module
         // so the hide/show option is a per item selection
-        if( IsElementVisible( RATSNEST_VISIBLE ) )
+        if( IsElementVisible( LAYER_RATSNEST ) )
         {
             for( unsigned ii = 0; ii < GetRatsnestsCount(); ii++ )
                 m_FullRatsnest[ii].m_Status |= CH_VISIBLE;
@@ -777,81 +777,81 @@ void BOARD::SetElementVisibility( int aPCB_VISIBLE, bool isEnabled )
 }
 
 
-COLOR4D BOARD::GetVisibleElementColor( int aPCB_VISIBLE )
+COLOR4D BOARD::GetVisibleElementColor( GAL_LAYER_ID aLayerId )
 {
     COLOR4D color = COLOR4D::UNSPECIFIED;
 
-    switch( aPCB_VISIBLE )
-    {
-    case NON_PLATED_VISIBLE:
-    case VIA_THROUGH_VISIBLE:
-    case VIA_MICROVIA_VISIBLE:
-    case VIA_BBLIND_VISIBLE:
-    case MOD_TEXT_FR_VISIBLE:
-    case MOD_TEXT_BK_VISIBLE:
-    case MOD_TEXT_INVISIBLE:
-    case ANCHOR_VISIBLE:
-    case PAD_FR_VISIBLE:
-    case PAD_BK_VISIBLE:
-    case RATSNEST_VISIBLE:
-    case GRID_VISIBLE:
-        color = GetColorsSettings()->GetItemColor( aPCB_VISIBLE );
+    switch( aLayerId )
+    {
+    case LAYER_NON_PLATED:
+    case LAYER_VIA_THROUGH:
+    case LAYER_VIA_MICROVIA:
+    case LAYER_VIA_BBLIND:
+    case LAYER_MOD_TEXT_FR:
+    case LAYER_MOD_TEXT_BK:
+    case LAYER_MOD_TEXT_INVISIBLE:
+    case LAYER_ANCHOR:
+    case LAYER_PAD_FR:
+    case LAYER_PAD_BK:
+    case LAYER_RATSNEST:
+    case LAYER_GRID:
+        color = GetColorsSettings()->GetItemColor( aLayerId );
         break;
 
     default:
-        wxLogDebug( wxT( "BOARD::GetVisibleElementColor(): bad arg %d" ), aPCB_VISIBLE );
+        wxLogDebug( wxT( "BOARD::GetVisibleElementColor(): bad arg %d" ), aLayerId );
     }
 
     return color;
 }
 
 
-void BOARD::SetVisibleElementColor( int aPCB_VISIBLE, COLOR4D aColor )
+void BOARD::SetVisibleElementColor( GAL_LAYER_ID aLayerId, COLOR4D aColor )
 {
-    switch( aPCB_VISIBLE )
+    switch( aLayerId )
     {
-    case NON_PLATED_VISIBLE:
-    case VIA_THROUGH_VISIBLE:
-    case VIA_MICROVIA_VISIBLE:
-    case VIA_BBLIND_VISIBLE:
-    case MOD_TEXT_FR_VISIBLE:
-    case MOD_TEXT_BK_VISIBLE:
-    case MOD_TEXT_INVISIBLE:
-    case ANCHOR_VISIBLE:
-    case PAD_FR_VISIBLE:
-    case PAD_BK_VISIBLE:
-    case GRID_VISIBLE:
-    case RATSNEST_VISIBLE:
-        GetColorsSettings()->SetItemColor( aPCB_VISIBLE, aColor );
+    case LAYER_NON_PLATED:
+    case LAYER_VIA_THROUGH:
+    case LAYER_VIA_MICROVIA:
+    case LAYER_VIA_BBLIND:
+    case LAYER_MOD_TEXT_FR:
+    case LAYER_MOD_TEXT_BK:
+    case LAYER_MOD_TEXT_INVISIBLE:
+    case LAYER_ANCHOR:
+    case LAYER_PAD_FR:
+    case LAYER_PAD_BK:
+    case LAYER_GRID:
+    case LAYER_RATSNEST:
+        GetColorsSettings()->SetItemColor( aLayerId, aColor );
         break;
 
     default:
-        wxLogDebug( wxT( "BOARD::SetVisibleElementColor(): bad arg %d" ), aPCB_VISIBLE );
+        wxLogDebug( wxT( "BOARD::SetVisibleElementColor(): bad arg %d" ), aLayerId );
     }
 }
 
 
-void BOARD::SetLayerColor( LAYER_ID aLayer, COLOR4D aColor )
+void BOARD::SetLayerColor( PCB_LAYER_ID aLayer, COLOR4D aColor )
 {
     GetColorsSettings()->SetLayerColor( aLayer, aColor );
 }
 
 
-COLOR4D BOARD::GetLayerColor( LAYER_ID aLayer ) const
+COLOR4D BOARD::GetLayerColor( PCB_LAYER_ID aLayer ) const
 {
     return GetColorsSettings()->GetLayerColor( aLayer );
 }
 
 
-bool BOARD::IsModuleLayerVisible( LAYER_ID layer )
+bool BOARD::IsModuleLayerVisible( PCB_LAYER_ID layer )
 {
     switch( layer )
     {
     case F_Cu:
-        return IsElementVisible( PCB_VISIBLE(MOD_FR_VISIBLE) );
+        return IsElementVisible( LAYER_MOD_FR );
 
     case B_Cu:
-        return IsElementVisible( PCB_VISIBLE(MOD_BK_VISIBLE) );
+        return IsElementVisible( LAYER_MOD_BK );
 
     default:
         wxFAIL_MSG( wxT( "BOARD::IsModuleLayerVisible() param error: bad layer" ) );
@@ -1470,7 +1470,7 @@ int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount )
 }
 
 
-void BOARD::RedrawAreasOutlines( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, LAYER_ID aLayer )
+void BOARD::RedrawAreasOutlines( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer )
 {
     if( !aDC )
         return;
@@ -1485,7 +1485,7 @@ void BOARD::RedrawAreasOutlines( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE a
 }
 
 
-void BOARD::RedrawFilledAreas( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, LAYER_ID aLayer )
+void BOARD::RedrawFilledAreas( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer )
 {
     if( !aDC )
         return;
@@ -1501,7 +1501,7 @@ void BOARD::RedrawFilledAreas( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDr
 
 
 ZONE_CONTAINER* BOARD::HitTestForAnyFilledArea( const wxPoint& aRefPos,
-    LAYER_ID aStartLayer, LAYER_ID aEndLayer,  int aNetCode )
+    PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer,  int aNetCode )
 {
     if( aEndLayer < 0 )
         aEndLayer = aStartLayer;
@@ -1568,7 +1568,7 @@ int BOARD::SetAreasNetCodesFromNetNames()
 }
 
 
-VIA* BOARD::GetViaByPosition( const wxPoint& aPosition, LAYER_ID aLayer) const
+VIA* BOARD::GetViaByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer) const
 {
     for( VIA *via = GetFirstVia( m_Track); via; via = GetFirstVia( via->Next() ) )
     {
@@ -1776,7 +1776,7 @@ TRACK* BOARD::GetVisibleTrack( TRACK* aStartingTrace, const wxPoint& aPosition,
 {
     for( TRACK* track = aStartingTrace; track; track = track->Next() )
     {
-        LAYER_ID layer = track->GetLayer();
+        PCB_LAYER_ID layer = track->GetLayer();
 
         if( track->GetState( BUSY | IS_DELETED ) )
             continue;
@@ -2145,7 +2145,7 @@ TRACK* BOARD::MarkTrace( TRACK*  aTrace, int* aCount,
 }
 
 
-MODULE* BOARD::GetFootprint( const wxPoint& aPosition, LAYER_ID aActiveLayer,
+MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer,
                              bool aVisibleOnly, bool aIgnoreLocked )
 {
     MODULE* pt_module;
@@ -2165,7 +2165,7 @@ MODULE* BOARD::GetFootprint( const wxPoint& aPosition, LAYER_ID aActiveLayer,
         if( aIgnoreLocked && pt_module->IsLocked() )
             continue;
 
-        LAYER_ID layer = pt_module->GetLayer();
+        PCB_LAYER_ID layer = pt_module->GetLayer();
 
         // Filter non visible modules if requested
         if( !aVisibleOnly || IsModuleLayerVisible( layer ) )
@@ -2313,7 +2313,7 @@ TRACK* BOARD::CreateLockPoint( wxPoint& aPosition, TRACK* aSegment, PICKED_ITEMS
 
 
 ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
-                                LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch )
+                                PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch )
 {
     ZONE_CONTAINER* new_area = InsertArea( aNetcode,
                                            m_ZoneDescriptorList.size( ) - 1,
@@ -2348,7 +2348,7 @@ void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to
 }
 
 
-ZONE_CONTAINER* BOARD::InsertArea( int netcode, int iarea, LAYER_ID layer, int x, int y, int hatch )
+ZONE_CONTAINER* BOARD::InsertArea( int netcode, int iarea, PCB_LAYER_ID layer, int x, int y, int hatch )
 {
     ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
 
diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h
index bff0513..cc61321 100644
--- a/pcbnew/class_board.h
+++ b/pcbnew/class_board.h
@@ -177,7 +177,7 @@ private:
     /// edge zone descriptors, owned by pointer.
     ZONE_CONTAINERS         m_ZoneDescriptorList;
 
-    LAYER                   m_Layer[LAYER_ID_COUNT];
+    LAYER                   m_Layer[PCB_LAYER_ID_COUNT];
 
                                                     // if true m_highLight_NetCode is used
     HIGH_LIGHT_INFO         m_highLight;                // current high light data
@@ -425,7 +425,7 @@ public:
      * @param aLayer = The layer to be tested
      * @return bool - true if the layer is visible.
      */
-    bool IsLayerEnabled( LAYER_ID aLayer ) const
+    bool IsLayerEnabled( PCB_LAYER_ID aLayer ) const
     {
         return m_designSettings.IsLayerEnabled( aLayer );
     }
@@ -437,7 +437,7 @@ public:
      * @param aLayer = The layer to be tested
      * @return bool - true if the layer is visible.
      */
-    bool IsLayerVisible( LAYER_ID aLayer ) const
+    bool IsLayerVisible( PCB_LAYER_ID aLayer ) const
     {
         return m_designSettings.IsLayerVisible( aLayer );
     }
@@ -458,15 +458,15 @@ public:
      */
     void SetVisibleLayers( LSET aLayerMask );
 
-    // these 2 functions are not tidy at this time, since there are PCB_VISIBLEs that
+    // these 2 functions are not tidy at this time, since there are PCB_LAYER_IDs that
     // are not stored in the bitmap.
 
     /**
      * Function GetVisibleElements
      * is a proxy function that calls the correspondent function in m_BoardSettings
      * returns a bit-mask of all the element categories that are visible
-     * @return int - the visible element bitmap or-ed from enum PCB_VISIBLE
-     * @see enum PCB_VISIBLE
+     * @return int - the visible element bitmap or-ed from enum GAL_LAYER_ID
+     * @see enum GAL_LAYER_ID
      */
     int GetVisibleElements() const;
 
@@ -474,15 +474,15 @@ public:
      * Function SetVisibleElements
      * is a proxy function that calls the correspondent function in m_BoardSettings
      * changes the bit-mask of visible element categories
-     * @param aMask = The new bit-mask of visible element bitmap or-ed from enum PCB_VISIBLE
-     * @see enum PCB_VISIBLE
+     * @param aMask = The new bit-mask of visible element bitmap or-ed from enum GAL_LAYER_ID
+     * @see enum GAL_LAYER_ID
      */
     void SetVisibleElements( int aMask );
 
     /**
      * Function SetVisibleAlls
      * changes the bit-mask of visible element categories and layers
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
     void SetVisibleAlls();
 
@@ -490,20 +490,20 @@ public:
      * Function IsElementVisible
      * tests whether a given element category is visible. Keep this as an
      * inline function.
-     * @param aPCB_VISIBLE is from the enum by the same name
+     * @param LAYER_aPCB is from the enum by the same name
      * @return bool - true if the element is visible.
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    bool IsElementVisible( int aPCB_VISIBLE ) const;
+    bool IsElementVisible( GAL_LAYER_ID LAYER_aPCB ) const;
 
     /**
      * Function SetElementVisibility
      * changes the visibility of an element category
-     * @param aPCB_VISIBLE is from the enum by the same name
+     * @param LAYER_aPCB is from the enum by the same name
      * @param aNewState = The new visibility state of the element category
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    void SetElementVisibility( int aPCB_VISIBLE, bool aNewState );
+    void SetElementVisibility( GAL_LAYER_ID LAYER_aPCB, bool aNewState );
 
     /**
      * Function IsModuleLayerVisible
@@ -512,16 +512,16 @@ public:
      * @param layer One of the two allowed layers for modules: F_Cu or B_Cu
      * @return bool - true if the layer is visible, else false.
      */
-    bool IsModuleLayerVisible( LAYER_ID layer );
+    bool IsModuleLayerVisible( PCB_LAYER_ID layer );
 
     /**
      * Function GetVisibleElementColor
      * returns the color of a pcb visible element.
-     * @see enum PCB_VISIBLE
+     * @see enum GAL_LAYER_ID
      */
-    COLOR4D GetVisibleElementColor( int aPCB_VISIBLE );
+    COLOR4D GetVisibleElementColor( GAL_LAYER_ID LAYER_aPCB );
 
-    void SetVisibleElementColor( int aPCB_VISIBLE, COLOR4D aColor );
+    void SetVisibleElementColor( GAL_LAYER_ID LAYER_aPCB, COLOR4D aColor );
 
     /**
      * Function GetDesignSettings
@@ -596,7 +596,7 @@ public:
      * @param aLayer = A copper layer, like B_Cu, etc.
      * @param aOutlines The SHAPE_POLY_SET to fill in with items outline.
      */
-    void ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines );
+    void ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines );
 
     /**
      * Function GetLayerID
@@ -605,10 +605,10 @@ public:
      *
      * @param aLayerName = A layer name, like wxT("B.Cu"), etc.
      *
-     * @return LAYER_ID -   the layer id, which for copper layers may
+     * @return PCB_LAYER_ID -   the layer id, which for copper layers may
      *                      be custom, else standard.
      */
-    const LAYER_ID GetLayerID( const wxString& aLayerName ) const;
+    const PCB_LAYER_ID GetLayerID( const wxString& aLayerName ) const;
 
     /**
      * Function GetLayerName
@@ -620,7 +620,7 @@ public:
      * @return wxString -   the layer name, which for copper layers may
      *                      be custom, else standard.
      */
-    const wxString GetLayerName( LAYER_ID aLayer ) const;
+    const wxString GetLayerName( PCB_LAYER_ID aLayer ) const;
 
     /**
      * Function SetLayerName
@@ -631,7 +631,7 @@ public:
      * @return bool - true if aLayerName was legal and unique among other
      *   layer names at other layer indices and aLayer was within range, else false.
      */
-    bool SetLayerName( LAYER_ID aLayer, const wxString& aLayerName );
+    bool SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName );
 
     /**
      * Function GetStandardLayerName
@@ -644,9 +644,9 @@ public:
      * @return const wxString - containing the layer name or "BAD INDEX" if aLayerId
      *                      is not legal
      */
-    static wxString GetStandardLayerName( LAYER_ID aLayerId )
+    static wxString GetStandardLayerName( PCB_LAYER_ID aLayerId )
     {
-        // a BOARD's standard layer name is the LAYER_ID fixed name
+        // a BOARD's standard layer name is the PCB_LAYER_ID fixed name
         return LSET::Name( aLayerId );
     }
 
@@ -658,7 +658,7 @@ public:
      * @param aLayer A reference to a LAYER description.
      * @return false if the index was out of range.
      */
-    bool SetLayerDescr( LAYER_ID aIndex, const LAYER& aLayer );
+    bool SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer );
 
     /**
      * Function GetLayerType
@@ -668,7 +668,7 @@ public:
      * @return LAYER_T - the layer type, or LAYER_T(-1) if the
      *  index was out of range.
      */
-    LAYER_T GetLayerType( LAYER_ID aLayer ) const;
+    LAYER_T GetLayerType( PCB_LAYER_ID aLayer ) const;
 
     /**
      * Function SetLayerType
@@ -678,19 +678,19 @@ public:
      * @param aLayerType The new layer type.
      * @return bool - true if aLayerType was legal and aLayer was within range, else false.
      */
-    bool SetLayerType( LAYER_ID aLayer, LAYER_T aLayerType );
+    bool SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType );
 
     /**
      * Function SetLayerColor
      * changes a layer color for any valid layer, including non-copper ones.
      */
-    void SetLayerColor( LAYER_ID aLayer, COLOR4D aColor );
+    void SetLayerColor( PCB_LAYER_ID aLayer, COLOR4D aColor );
 
     /**
      * Function GetLayerColor
      * gets a layer color for any valid layer, including non-copper ones.
      */
-    COLOR4D GetLayerColor( LAYER_ID aLayer ) const;
+    COLOR4D GetLayerColor( PCB_LAYER_ID aLayer ) const;
 
     /** Functions to get some items count */
     int GetNumSegmTrack() const;
@@ -982,8 +982,8 @@ public:
      * @return ZONE_CONTAINER* return a pointer to the ZONE_CONTAINER found, else NULL
      */
     ZONE_CONTAINER* HitTestForAnyFilledArea( const wxPoint& aRefPos,
-                                             LAYER_ID      aStartLayer,
-                                             LAYER_ID      aEndLayer,
+                                             PCB_LAYER_ID      aStartLayer,
+                                             PCB_LAYER_ID      aEndLayer,
                                              int aNetCode );
 
     /**
@@ -993,14 +993,14 @@ public:
     void RedrawAreasOutlines( EDA_DRAW_PANEL* aPanel,
                               wxDC*           aDC,
                               GR_DRAWMODE     aDrawMode,
-                              LAYER_ID       aLayer );
+                              PCB_LAYER_ID       aLayer );
 
     /**
      * Function RedrawFilledAreas
      * Redraw all filled areas on layer aLayer ( redraw all if aLayer < 0 )
      */
     void RedrawFilledAreas( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
-                            LAYER_ID aLayer );
+                            PCB_LAYER_ID aLayer );
 
     /**
      * Function SetAreasNetCodesFromNetNames
@@ -1068,14 +1068,14 @@ public:
      * @return a reference to the new area
      */
     ZONE_CONTAINER* AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
-                             LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch );
+                             PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch );
 
     /**
      * Function InsertArea
      * add empty copper area to net, inserting after m_ZoneDescriptorList[iarea]
      * @return pointer to the new area
      */
-    ZONE_CONTAINER* InsertArea( int netcode, int iarea, LAYER_ID layer, int x, int y, int hatch );
+    ZONE_CONTAINER* InsertArea( int netcode, int iarea, PCB_LAYER_ID layer, int x, int y, int hatch );
 
     /**
      * Function NormalizeAreaPolygon
@@ -1188,10 +1188,10 @@ public:
      * of the via.
      * </p>
      * @param aPosition The wxPoint to HitTest() against.
-     * @param aLayer The layer to search.  Use -1 (LAYER_ID::UNDEFINED_LAYER) for a don't care.
+     * @param aLayer The layer to search.  Use -1 (<PCB_LAYER_ID>::UNDEFINED_LAYER) for a don't care.
      * @return VIA* A point a to the VIA object if found, else NULL.
      */
-    VIA* GetViaByPosition( const wxPoint& aPosition, LAYER_ID aLayer = LAYER_ID( -1 ) ) const;
+    VIA* GetViaByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer = PCB_LAYER_ID( -1 ) ) const;
 
     /**
      * Function GetPad
@@ -1352,7 +1352,7 @@ public:
      * @param aIgnoreLocked Ignore locked modules when true.
      * @return MODULE* The best module or NULL if none.
      */
-    MODULE* GetFootprint( const wxPoint& aPosition, LAYER_ID aActiveLayer,
+    MODULE* GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer,
                           bool aVisibleOnly, bool aIgnoreLocked = false );
 
     /**
diff --git a/pcbnew/class_board_design_settings.cpp b/pcbnew/class_board_design_settings.cpp
index d53a208..c49aefd 100644
--- a/pcbnew/class_board_design_settings.cpp
+++ b/pcbnew/class_board_design_settings.cpp
@@ -47,7 +47,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
     SetVisibleLayers( all_set );
 
     // set all but hidden text as visible.
-    m_visibleElements = ~( 1 << MOD_TEXT_INVISIBLE );
+    m_visibleElements = ~( 1 << GAL_LAYER_INDEX( LAYER_MOD_TEXT_INVISIBLE ) );
 
     SetCopperLayerCount( 2 );               // Default design is a double sided board
 
@@ -322,7 +322,7 @@ void BOARD_DESIGN_SETTINGS::SetVisibleAlls()
 }
 
 
-void BOARD_DESIGN_SETTINGS::SetLayerVisibility( LAYER_ID aLayer, bool aNewState )
+void BOARD_DESIGN_SETTINGS::SetLayerVisibility( PCB_LAYER_ID aLayer, bool aNewState )
 {
     if( aNewState && IsLayerEnabled( aLayer ) )
         m_visibleLayers.set( aLayer, true );
@@ -331,15 +331,12 @@ void BOARD_DESIGN_SETTINGS::SetLayerVisibility( LAYER_ID aLayer, bool aNewState
 }
 
 
-void BOARD_DESIGN_SETTINGS::SetElementVisibility( int aElementCategory, bool aNewState )
+void BOARD_DESIGN_SETTINGS::SetElementVisibility( GAL_LAYER_ID aElementCategory, bool aNewState )
 {
-    if( aElementCategory < 0 || aElementCategory >= END_PCB_VISIBLE_LIST )
-        return;
-
     if( aNewState )
-        m_visibleElements |= 1 << aElementCategory;
+        m_visibleElements |= 1 << GAL_LAYER_INDEX( aElementCategory );
     else
-        m_visibleElements &= ~( 1 << aElementCategory );
+        m_visibleElements &= ~( 1 << GAL_LAYER_INDEX( aElementCategory ) );
 }
 
 
@@ -389,7 +386,7 @@ struct list_size_check {
    {
        // Int (the type used for saving visibility settings) is only 32 bits guaranteed,
        // be sure that we do not cross the limit
-       assert( END_PCB_VISIBLE_LIST <= 32 );
+       assert( GAL_LAYER_INDEX( GAL_LAYER_ID_BITMASK_END ) <= 32 );
    };
 };
 static list_size_check check;
diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp
index db1e65a..706d41e 100644
--- a/pcbnew/class_dimension.cpp
+++ b/pcbnew/class_dimension.cpp
@@ -83,7 +83,7 @@ const wxString DIMENSION::GetText() const
 }
 
 
-void DIMENSION::SetLayer( LAYER_ID aLayer )
+void DIMENSION::SetLayer( PCB_LAYER_ID aLayer )
 {
     m_Layer = aLayer;
     m_Text.SetLayer( aLayer );
diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h
index d6012fe..2dc4934 100644
--- a/pcbnew/class_dimension.h
+++ b/pcbnew/class_dimension.h
@@ -96,7 +96,7 @@ public:
         m_Text.SetTextSize( aTextSize );
     }
 
-    void SetLayer( LAYER_ID aLayer ) override;
+    void SetLayer( PCB_LAYER_ID aLayer ) override;
 
     void SetShape( int aShape )         { m_Shape = aShape; }
     int GetShape() const                { return m_Shape; }
diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp
index 351e532..568c8be 100644
--- a/pcbnew/class_drawsegment.cpp
+++ b/pcbnew/class_drawsegment.cpp
@@ -205,7 +205,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
     int l_trace;
     int radius;
 
-    LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
     COLOR4D    color;
 
     BOARD * brd =  GetBoard( );
diff --git a/pcbnew/class_drc_item.cpp b/pcbnew/class_drc_item.cpp
index 88e3eeb..754cc02 100644
--- a/pcbnew/class_drc_item.cpp
+++ b/pcbnew/class_drc_item.cpp
@@ -133,7 +133,7 @@ wxString DRC_ITEM::GetErrorText() const
         return wxString( _( "Footprint has no courtyard defined" ) );
 
     case DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT:
-        return wxString( _( "Footprint has incorect courtyard (not a closed shape)" ) );
+        return wxString( _( "Footprint has incorrect courtyard (not a closed shape)" ) );
 
     default:
         return wxString::Format( wxT( "Unknown DRC error code %d" ), m_ErrorCode );
diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp
index 078475a..9eca984 100644
--- a/pcbnew/class_edge_mod.cpp
+++ b/pcbnew/class_edge_mod.cpp
@@ -107,7 +107,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
                         const wxPoint& offset )
 {
     int         ux0, uy0, dx, dy, radius, StAngle, EndAngle;
-    LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
     MODULE* module = (MODULE*) m_Parent;
 
diff --git a/pcbnew/class_marker_pcb.cpp b/pcbnew/class_marker_pcb.cpp
index 6c3f583..8a90bac 100644
--- a/pcbnew/class_marker_pcb.cpp
+++ b/pcbnew/class_marker_pcb.cpp
@@ -86,7 +86,7 @@ MARKER_PCB::~MARKER_PCB()
  * param aLayer The layer to test for.
  * return bool - true if on given layer, else false.
  */
-bool MARKER_PCB::IsOnLayer( LAYER_ID aLayer ) const
+bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
 {
     return IsCopperLayer( aLayer );
 }
@@ -147,7 +147,7 @@ BITMAP_DEF MARKER_PCB::GetMenuImage() const
 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
 {
     aCount = 1;
-    aLayers[0] = ITEM_GAL_LAYER( DRC_VISIBLE );
+    aLayers[0] = LAYER_DRC;
 }
 
 const EDA_RECT MARKER_PCB::GetBoundingBox() const
diff --git a/pcbnew/class_marker_pcb.h b/pcbnew/class_marker_pcb.h
index feecfdc..904affc 100644
--- a/pcbnew/class_marker_pcb.h
+++ b/pcbnew/class_marker_pcb.h
@@ -103,7 +103,7 @@ public:
         return HitTestMarker( aPosition );
     }
 
-    bool IsOnLayer( LAYER_ID aLayer ) const override;
+    bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
 
     void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
 
diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp
index f0eac1c..287f08d 100644
--- a/pcbnew/class_mire.cpp
+++ b/pcbnew/class_mire.cpp
@@ -54,7 +54,7 @@ PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
     m_Layer = Edge_Cuts;                   // a target is on all layers
 }
 
-PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, LAYER_ID aLayer,
+PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
         const wxPoint& aPos, int aSize, int aWidth ) :
     BOARD_ITEM( aParent, PCB_TARGET_T )
 {
diff --git a/pcbnew/class_mire.h b/pcbnew/class_mire.h
index 5d41996..13b19bc 100644
--- a/pcbnew/class_mire.h
+++ b/pcbnew/class_mire.h
@@ -51,7 +51,7 @@ public:
 
     // Do not create a copy constructor.  The one generated by the compiler is adequate.
 
-    PCB_TARGET( BOARD_ITEM* aParent, int aShape, LAYER_ID aLayer,
+    PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
                 const wxPoint& aPos, int aSize, int aWidth );
 
     // Do not create a copy constructor & operator=.
diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp
index 52a2ad2..7649521 100644
--- a/pcbnew/class_module.cpp
+++ b/pcbnew/class_module.cpp
@@ -239,11 +239,11 @@ void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
 {
     GRSetDrawMode( DC, draw_mode );
 
-    if( GetBoard()->IsElementVisible( ANCHOR_VISIBLE ) )
+    if( GetBoard()->IsElementVisible( LAYER_ANCHOR ) )
     {
         GRDrawAnchor( panel->GetClipBox(), DC, m_Pos.x, m_Pos.y,
                       dim_ancre,
-                      g_ColorsSettings.GetItemColor( ANCHOR_VISIBLE ) );
+                      g_ColorsSettings.GetItemColor( LAYER_ANCHOR ) );
     }
 }
 
@@ -404,13 +404,13 @@ void MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
     DrawAncre( aPanel, aDC, aOffset, DIM_ANCRE_MODULE, aDrawMode );
 
     // Draw graphic items
-    if( brd->IsElementVisible( MOD_REFERENCES_VISIBLE ) )
+    if( brd->IsElementVisible( LAYER_MOD_REFERENCES ) )
     {
         if( !(m_Reference->IsMoving()) )
             m_Reference->Draw( aPanel, aDC, aDrawMode, aOffset );
     }
 
-    if( brd->IsElementVisible( MOD_VALUES_VISIBLE ) )
+    if( brd->IsElementVisible( LAYER_MOD_VALUES ) )
     {
         if( !(m_Value->IsMoving()) )
             m_Value->Draw( aPanel, aDC, aDrawMode, aOffset );
@@ -837,7 +837,7 @@ void MODULE::RunOnChildren( std::function<void (BOARD_ITEM*)> aFunction )
 void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
 {
     aCount = 2;
-    aLayers[0] = ITEM_GAL_LAYER( ANCHOR_VISIBLE );
+    aLayers[0] = LAYER_ANCHOR;
 
     switch( m_Layer )
     {
@@ -846,11 +846,11 @@ void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
         wxASSERT_MSG( false, "Illegal layer" );    // do you really have modules placed on other layers?
         // pass through
     case F_Cu:
-        aLayers[1] = ITEM_GAL_LAYER( MOD_FR_VISIBLE );
+        aLayers[1] = LAYER_MOD_FR;
         break;
 
     case B_Cu:
-        aLayers[1] = ITEM_GAL_LAYER( MOD_BK_VISIBLE );
+        aLayers[1] = LAYER_MOD_BK;
         break;
     }
 }
@@ -858,11 +858,11 @@ void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
 
 unsigned int MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
 {
-    int layer = ( m_Layer == F_Cu ) ? MOD_FR_VISIBLE :
-                ( m_Layer == B_Cu ) ? MOD_BK_VISIBLE : ANCHOR_VISIBLE;
+    int layer = ( m_Layer == F_Cu ) ? LAYER_MOD_FR :
+                ( m_Layer == B_Cu ) ? LAYER_MOD_BK : LAYER_ANCHOR;
 
     // Currently it is only for anchor layer
-    if( aView->IsLayerVisible( ITEM_GAL_LAYER( layer ) ) )
+    if( aView->IsLayerVisible( layer ) )
         return 30;
 
     return std::numeric_limits<unsigned int>::max();
diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h
index a101749..3fe661d 100644
--- a/pcbnew/class_module.h
+++ b/pcbnew/class_module.h
@@ -320,7 +320,7 @@ public:
      *  there is no copper left on the board (for instance when creating Gerber Files or 3D shapes)
      *  default = false
      */
-    void TransformPadsShapesWithClearanceToPolygon( LAYER_ID aLayer,
+    void TransformPadsShapesWithClearanceToPolygon( PCB_LAYER_ID aLayer,
                             SHAPE_POLY_SET& aCornerBuffer,
                             int             aInflateValue,
                             int             aCircleToSegmentsCount,
@@ -348,7 +348,7 @@ public:
      *       if 0, use the aCircleToSegmentsCount value
      */
     void TransformGraphicShapesWithClearanceToPolygonSet(
-                            LAYER_ID aLayer,
+                            PCB_LAYER_ID aLayer,
                             SHAPE_POLY_SET& aCornerBuffer,
                             int             aInflateValue,
                             int             aCircleToSegmentsCount,
@@ -367,7 +367,7 @@ public:
      * @param aCircleToSegmentsCountForTexts
      */
     void TransformGraphicTextWithClearanceToPolygonSet(
-                            LAYER_ID aLayer,
+                            PCB_LAYER_ID aLayer,
                             SHAPE_POLY_SET& aCornerBuffer,
                             int             aInflateValue,
                             int             aCircleToSegmentsCount,
diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp
index 53cfe66..8566083 100644
--- a/pcbnew/class_netinfo_item.cpp
+++ b/pcbnew/class_netinfo_item.cpp
@@ -174,7 +174,7 @@ void RATSNEST_ITEM::Draw( EDA_DRAW_PANEL* panel,
 {
     GRSetDrawMode( DC, aDrawMode );
 
-    COLOR4D color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
+    COLOR4D color = g_ColorsSettings.GetItemColor( LAYER_RATSNEST );
 
     GRLine( panel->GetClipBox(), DC,
             m_PadStart->GetPosition() - aOffset,
diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp
index 7b50e45..1d2b81a 100644
--- a/pcbnew/class_pad.cpp
+++ b/pcbnew/class_pad.cpp
@@ -931,31 +931,31 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const
 
     // These types of pads contain a hole
     if( m_Attribute == PAD_ATTRIB_STANDARD || m_Attribute == PAD_ATTRIB_HOLE_NOT_PLATED )
-        aLayers[aCount++] = ITEM_GAL_LAYER( PADS_HOLES_VISIBLE );
+        aLayers[aCount++] = LAYER_PADS_HOLES;
 
     if( IsOnLayer( F_Cu ) && IsOnLayer( B_Cu ) )
     {
         // Multi layer pad
-        aLayers[aCount++] = ITEM_GAL_LAYER( PADS_VISIBLE );
-        aLayers[aCount++] = NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE );
+        aLayers[aCount++] = LAYER_PADS;
+        aLayers[aCount++] = LAYER_PADS_NETNAMES;
     }
     else if( IsOnLayer( F_Cu ) )
     {
-        aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_VISIBLE );
-        aLayers[aCount++] = NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE );
+        aLayers[aCount++] = LAYER_PAD_FR;
+        aLayers[aCount++] = LAYER_PAD_FR_NETNAMES;
     }
     else if( IsOnLayer( B_Cu ) )
     {
-        aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_VISIBLE );
-        aLayers[aCount++] = NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE );
+        aLayers[aCount++] = LAYER_PAD_BK;
+        aLayers[aCount++] = LAYER_PAD_BK_NETNAMES;
     }
 
     // Check non-copper layers. This list should include all the layers that the
     // footprint editor allows a pad to be placed on.
-    static const LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
+    static const PCB_LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
         F_Adhes, B_Adhes, F_SilkS, B_SilkS, Dwgs_User, Eco1_User, Eco2_User };
 
-    for( LAYER_ID each_layer : layers_mech )
+    for( PCB_LAYER_ID each_layer : layers_mech )
     {
         if( IsOnLayer( each_layer ) )
             aLayers[aCount++] = each_layer;
@@ -1013,7 +1013,7 @@ const BOX2I D_PAD::ViewBBox() const
 wxString LayerMaskDescribe( const BOARD *aBoard, LSET aMask )
 {
     // Try the single or no- layer case (easy)
-    LAYER_ID layer = aMask.ExtractLayer();
+    PCB_LAYER_ID layer = aMask.ExtractLayer();
 
     switch( (int) layer )
     {
diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h
index 8b928eb..4dd2233 100644
--- a/pcbnew/class_pad.h
+++ b/pcbnew/class_pad.h
@@ -476,7 +476,7 @@ public:
 
     void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
 
-    bool IsOnLayer( LAYER_ID aLayer ) const override
+    bool IsOnLayer( PCB_LAYER_ID aLayer ) const override
     {
         return m_layerMask[aLayer];
     }
diff --git a/pcbnew/class_pad_draw_functions.cpp b/pcbnew/class_pad_draw_functions.cpp
index 86fba2b..3bef965 100644
--- a/pcbnew/class_pad_draw_functions.cpp
+++ b/pcbnew/class_pad_draw_functions.cpp
@@ -102,8 +102,8 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
      */
 
     BOARD* brd = GetBoard();
-    bool   frontVisible = brd->IsElementVisible( PCB_VISIBLE( PAD_FR_VISIBLE ) );
-    bool   backVisible  = brd->IsElementVisible( PCB_VISIBLE( PAD_BK_VISIBLE ) );
+    bool   frontVisible = brd->IsElementVisible( LAYER_PAD_FR );
+    bool   backVisible  = brd->IsElementVisible( LAYER_PAD_BK );
 
     if( !frontVisible && !backVisible )
         return;
@@ -134,12 +134,12 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
 
     if( m_layerMask[F_Cu] )
     {
-        color = brd->GetVisibleElementColor( PAD_FR_VISIBLE );
+        color = brd->GetVisibleElementColor( LAYER_PAD_FR );
     }
 
     if( m_layerMask[B_Cu] )
     {
-        color = color.LegacyMix( brd->GetVisibleElementColor( PAD_BK_VISIBLE ) );
+        color = color.LegacyMix( brd->GetVisibleElementColor( LAYER_PAD_BK ) );
     }
 
     if( color == BLACK ) // Not on a visible copper layer (i.e. still nothing to show)
@@ -150,7 +150,7 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
 #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
         mask_non_copper_layers &= brd->GetVisibleLayers();
 #endif
-        LAYER_ID pad_layer = mask_non_copper_layers.ExtractLayer();
+        PCB_LAYER_ID pad_layer = mask_non_copper_layers.ExtractLayer();
 
         switch( (int) pad_layer )
         {
@@ -177,8 +177,8 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
         // when routing tracks
         if( frame->GetToolId() == ID_TRACK_BUTT )
         {
-            LAYER_ID routeTop = screen->m_Route_Layer_TOP;
-            LAYER_ID routeBot = screen->m_Route_Layer_BOTTOM;
+            PCB_LAYER_ID routeTop = screen->m_Route_Layer_TOP;
+            PCB_LAYER_ID routeBot = screen->m_Route_Layer_BOTTOM;
 
             // if routing between copper and component layers,
             // or the current layer is one of said 2 external copper layers,
@@ -273,17 +273,17 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
         DisplayIsol = false;
 
     if( ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) &&
-        brd->IsElementVisible( NON_PLATED_VISIBLE ) )
+        brd->IsElementVisible( LAYER_NON_PLATED ) )
     {
         drawInfo.m_ShowNotPlatedHole = true;
-        drawInfo.m_NPHoleColor = brd->GetVisibleElementColor( NON_PLATED_VISIBLE );
+        drawInfo.m_NPHoleColor = brd->GetVisibleElementColor( LAYER_NON_PLATED );
     }
 
     drawInfo.m_DrawMode    = aDraw_mode;
     drawInfo.m_Color       = color;
     drawInfo.m_DrawPanel   = aPanel;
     drawInfo.m_Mask_margin = mask_margin;
-    drawInfo.m_ShowNCMark  = brd->IsElementVisible( PCB_VISIBLE( NO_CONNECTS_VISIBLE ) );
+    drawInfo.m_ShowNCMark  = brd->IsElementVisible( LAYER_NO_CONNECTS );
     drawInfo.m_IsPrinting  = screen->m_IsPrinting;
     color.a = 0.666;
 
diff --git a/pcbnew/class_pcb_layer_box_selector.cpp b/pcbnew/class_pcb_layer_box_selector.cpp
index 152be82..2eec022 100644
--- a/pcbnew/class_pcb_layer_box_selector.cpp
+++ b/pcbnew/class_pcb_layer_box_selector.cpp
@@ -41,7 +41,7 @@
 #include <class_pcb_layer_box_selector.h>
 
 // translate aLayer to its hotkey
-static int layer2hotkey_id( LAYER_ID aLayer )
+static int layer2hotkey_id( PCB_LAYER_ID aLayer )
 {
     switch( aLayer )
     {
@@ -90,7 +90,7 @@ void PCB_LAYER_BOX_SELECTOR::Resync()
 
     for( LSEQ seq = show.UIOrder();  seq;  ++seq )
     {
-        LAYER_ID   layerid = *seq;
+        PCB_LAYER_ID   layerid = *seq;
 
         if( !m_showNotEnabledBrdlayers && !activated[layerid] )
             continue;
diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp
index b9ada86..acfac43 100644
--- a/pcbnew/class_pcb_layer_widget.cpp
+++ b/pcbnew/class_pcb_layer_widget.cpp
@@ -37,7 +37,7 @@
 
 #include <confirm.h>
 #include <wxPcbStruct.h>
-#include <pcbstruct.h>      // enum PCB_VISIBLE
+#include <pcbstruct.h>
 #include <layer_widget.h>
 #include <macros.h>
 #include <menus_helpers.h>
@@ -58,32 +58,32 @@ const LAYER_WIDGET::ROW PCB_LAYER_WIDGET::s_render_rows[] = {
 #define RR  LAYER_WIDGET::ROW   // Render Row abbreviation to reduce source width
 
          // text                id                      color       tooltip
-    RR( _( "Through Via" ),     VIA_THROUGH_VISIBLE,    WHITE,      _( "Show through vias" ) ),
-    RR( _( "Bl/Buried Via" ),   VIA_BBLIND_VISIBLE,     WHITE,      _( "Show blind or buried vias" )  ),
-    RR( _( "Micro Via" ),       VIA_MICROVIA_VISIBLE,   WHITE,      _( "Show micro vias") ),
-    RR( _( "Non Plated" ),      NON_PLATED_VISIBLE,     WHITE,      _( "Show non plated holes") ),
-    RR( _( "Ratsnest" ),        RATSNEST_VISIBLE,       WHITE,      _( "Show unconnected nets as a ratsnest") ),
-
-    RR( _( "Pads Front" ),      PAD_FR_VISIBLE,         WHITE,      _( "Show footprint pads on board's front" ) ),
-    RR( _( "Pads Back" ),       PAD_BK_VISIBLE,         WHITE,      _( "Show footprint pads on board's back" ) ),
-
-    RR( _( "Text Front" ),      MOD_TEXT_FR_VISIBLE,    COLOR4D::UNSPECIFIED,  _( "Show footprint text on board's front" ) ),
-    RR( _( "Text Back" ),       MOD_TEXT_BK_VISIBLE,    COLOR4D::UNSPECIFIED,  _( "Show footprint text on board's back" ) ),
-    RR( _( "Hidden Text" ),     MOD_TEXT_INVISIBLE,     WHITE,      _( "Show footprint text marked as invisible" ) ),
-
-    RR( _( "Anchors" ),         ANCHOR_VISIBLE,         WHITE,      _( "Show footprint and text origins as a cross" ) ),
-    RR( _( "Grid" ),            GRID_VISIBLE,           WHITE,      _( "Show the (x,y) grid dots" ) ),
-    RR( _( "No-Connects" ),     NO_CONNECTS_VISIBLE,    COLOR4D::UNSPECIFIED,  _( "Show a marker on pads which have no net connected" ) ),
-    RR( _( "Footprints Front" ),   MOD_FR_VISIBLE,         COLOR4D::UNSPECIFIED,  _( "Show footprints that are on board's front") ),
-    RR( _( "Footprints Back" ),    MOD_BK_VISIBLE,         COLOR4D::UNSPECIFIED,  _( "Show footprints that are on board's back") ),
-    RR( _( "Values" ),          MOD_VALUES_VISIBLE,     COLOR4D::UNSPECIFIED,  _( "Show footprint's values") ),
-    RR( _( "References" ),      MOD_REFERENCES_VISIBLE, COLOR4D::UNSPECIFIED,  _( "Show footprint's references") ),
+    RR( _( "Through Via" ),     LAYER_VIA_THROUGH,    WHITE,      _( "Show through vias" ) ),
+    RR( _( "Bl/Buried Via" ),   LAYER_VIA_BBLIND,     WHITE,      _( "Show blind or buried vias" )  ),
+    RR( _( "Micro Via" ),       LAYER_VIA_MICROVIA,   WHITE,      _( "Show micro vias") ),
+    RR( _( "Non Plated" ),      LAYER_NON_PLATED,     WHITE,      _( "Show non plated holes") ),
+    RR( _( "Ratsnest" ),        LAYER_RATSNEST,       WHITE,      _( "Show unconnected nets as a ratsnest") ),
+
+    RR( _( "Pads Front" ),      LAYER_PAD_FR,         WHITE,      _( "Show footprint pads on board's front" ) ),
+    RR( _( "Pads Back" ),       LAYER_PAD_BK,         WHITE,      _( "Show footprint pads on board's back" ) ),
+
+    RR( _( "Text Front" ),      LAYER_MOD_TEXT_FR,        COLOR4D::UNSPECIFIED,  _( "Show footprint text on board's front" ) ),
+    RR( _( "Text Back" ),       LAYER_MOD_TEXT_BK,        COLOR4D::UNSPECIFIED,  _( "Show footprint text on board's back" ) ),
+    RR( _( "Hidden Text" ),     LAYER_MOD_TEXT_INVISIBLE, WHITE,                 _( "Show footprint text marked as invisible" ) ),
+
+    RR( _( "Anchors" ),         LAYER_ANCHOR,         WHITE,                _( "Show footprint and text origins as a cross" ) ),
+    RR( _( "Grid" ),            LAYER_GRID,           WHITE,                _( "Show the (x,y) grid dots" ) ),
+    RR( _( "No-Connects" ),     LAYER_NO_CONNECTS,    COLOR4D::UNSPECIFIED, _( "Show a marker on pads which have no net connected" ) ),
+    RR( _( "Footprints Front" ),LAYER_MOD_FR,         COLOR4D::UNSPECIFIED, _( "Show footprints that are on board's front") ),
+    RR( _( "Footprints Back" ), LAYER_MOD_BK,         COLOR4D::UNSPECIFIED, _( "Show footprints that are on board's back") ),
+    RR( _( "Values" ),          LAYER_MOD_VALUES,     COLOR4D::UNSPECIFIED, _( "Show footprint's values") ),
+    RR( _( "References" ),      LAYER_MOD_REFERENCES, COLOR4D::UNSPECIFIED, _( "Show footprint's references") ),
 };
 
 static int s_allowed_in_FpEditor[] =
 {
-    MOD_TEXT_INVISIBLE, PAD_FR_VISIBLE, PAD_BK_VISIBLE,
-    GRID_VISIBLE, MOD_VALUES_VISIBLE, MOD_REFERENCES_VISIBLE
+    LAYER_MOD_TEXT_INVISIBLE, LAYER_PAD_FR, LAYER_PAD_BK,
+    LAYER_GRID, LAYER_MOD_VALUES, LAYER_MOD_REFERENCES
 };
 
 
@@ -131,7 +131,7 @@ bool PCB_LAYER_WIDGET::isAllowedInFpMode( int aId )
 }
 
 
-bool PCB_LAYER_WIDGET::isLayerAllowedInFpMode( LAYER_ID aLayer )
+bool PCB_LAYER_WIDGET::isLayerAllowedInFpMode( PCB_LAYER_ID aLayer )
 {
     static LSET allowed = LSET::AllTechMask();
     // Currently not in use because putting a graphic item on a copper layer
@@ -213,7 +213,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
         {
             bool isLast;
             wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
-            LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
+            PCB_LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
             cb->SetValue( visible );
 
             isLast = row == rowCount-1;
@@ -236,7 +236,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
         for( int row = rowCount-1; row>=0; --row )
         {
             wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
-            LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
+            PCB_LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
 
             if( IsCopperLayer( layer ) )
             {
@@ -249,7 +249,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
         for( int row=0;  row<rowCount;  ++row )
         {
             wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
-            LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
+            PCB_LAYER_ID    layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
 
             if( IsCopperLayer( layer ) )
             {
@@ -302,10 +302,10 @@ void PCB_LAYER_WIDGET::ReFillRender()
         if( renderRow.color != COLOR4D::UNSPECIFIED )       // does this row show a color?
         {
             // this window frame must have an established BOARD, i.e. after SetBoard()
-            renderRow.color = board->GetVisibleElementColor( renderRow.id );
+            renderRow.color = board->GetVisibleElementColor( static_cast<GAL_LAYER_ID>( renderRow.id ) );
         }
 
-        renderRow.state = board->IsElementVisible( renderRow.id );
+        renderRow.state = board->IsElementVisible( static_cast<GAL_LAYER_ID>( renderRow.id ) );
 
         AppendRenderRow( renderRow );
     }
@@ -324,7 +324,7 @@ void PCB_LAYER_WIDGET::SyncRenderStates()
             continue;
 
         // this does not fire a UI event
-        SetRenderState( rowId, board->IsElementVisible( rowId ) );
+        SetRenderState( rowId, board->IsElementVisible( static_cast<GAL_LAYER_ID>( rowId ) ) );
     }
 }
 
@@ -341,7 +341,7 @@ void PCB_LAYER_WIDGET::SyncLayerVisibilities()
 
         wxWindow* w = getLayerComp( row, COLUMN_ICON_ACTIVE );
 
-        LAYER_ID layerId = ToLAYER_ID( getDecodedId( w->GetId() ) );
+        PCB_LAYER_ID layerId = ToLAYER_ID( getDecodedId( w->GetId() ) );
 
         // this does not fire a UI event
         SetLayerVisible( layerId, board->IsLayerVisible( layerId ) );
@@ -361,7 +361,7 @@ void PCB_LAYER_WIDGET::ReFill()
     // show all coppers first, with front on top, back on bottom, then technical layers
     for( LSEQ cu_stack = enabled.CuStack(); cu_stack; ++cu_stack )
     {
-        LAYER_ID layer = *cu_stack;
+        PCB_LAYER_ID layer = *cu_stack;
 
         switch( layer )
         {
@@ -395,7 +395,7 @@ void PCB_LAYER_WIDGET::ReFill()
     // Because they are static, wxGetTranslation must be explicitly
     // called for tooltips.
     static const struct {
-        LAYER_ID    layerId;
+        PCB_LAYER_ID    layerId;
         wxString    tooltip;
     } non_cu_seq[] = {
         { F_Adhes,          _( "Adhesive on board's front" ) },
@@ -420,7 +420,7 @@ void PCB_LAYER_WIDGET::ReFill()
 
     for( unsigned i=0;  i<DIM( non_cu_seq );  ++i )
     {
-        LAYER_ID layer = non_cu_seq[i].layerId;
+        PCB_LAYER_ID layer = non_cu_seq[i].layerId;
 
         if( !enabled[layer] )
             continue;
@@ -463,7 +463,7 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( int aLayer )
 {
     // the layer change from the PCB_LAYER_WIDGET can be denied by returning
     // false from this function.
-    LAYER_ID layer = ToLAYER_ID( aLayer );
+    PCB_LAYER_ID layer = ToLAYER_ID( aLayer );
 
     if( m_fp_editor_mode && !isLayerAllowedInFpMode( layer ) )
         return false;
@@ -517,7 +517,8 @@ void PCB_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFinal
 
 void PCB_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor )
 {
-    myframe->GetBoard()->SetVisibleElementColor( aId, aColor );
+    wxASSERT( aId > GAL_LAYER_ID_START && aId < GAL_LAYER_ID_END );
+    myframe->GetBoard()->SetVisibleElementColor( static_cast<GAL_LAYER_ID>( aId ), aColor );
 
     if( myframe->GetGalCanvas() )
     {
@@ -533,28 +534,29 @@ void PCB_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor )
 void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
 {
     BOARD*  brd = myframe->GetBoard();
+    wxASSERT( aId > GAL_LAYER_ID_START && aId < GAL_LAYER_ID_END );
 
     LSET visibleLayers = brd->GetVisibleLayers();
     visibleLayers.set( aId, isEnabled );
 
     // The layer visibility status is saved in the board file so set the board modified
     // state so the user has the option to save the changes.
-    if( brd->IsElementVisible( aId ) != isEnabled )
+    if( brd->IsElementVisible( static_cast<GAL_LAYER_ID>( aId ) ) != isEnabled )
         myframe->OnModify();
 
-    brd->SetElementVisibility( aId, isEnabled );
+    brd->SetElementVisibility( static_cast<GAL_LAYER_ID>( aId ), isEnabled );
 
     EDA_DRAW_PANEL_GAL* galCanvas = myframe->GetGalCanvas();
 
     if( galCanvas )
     {
-        if( aId == GRID_VISIBLE )
+        if( aId == LAYER_GRID )
         {
             galCanvas->GetGAL()->SetGridVisibility( myframe->IsGridVisible() );
             galCanvas->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
         }
         else
-            galCanvas->GetView()->SetLayerVisible( ITEM_GAL_LAYER( aId ), isEnabled );
+            galCanvas->GetView()->SetLayerVisible( aId , isEnabled );
     }
 
     if( galCanvas && myframe->IsGalCanvasActive() )
diff --git a/pcbnew/class_pcb_layer_widget.h b/pcbnew/class_pcb_layer_widget.h
index be1fe4e..5c623de 100644
--- a/pcbnew/class_pcb_layer_widget.h
+++ b/pcbnew/class_pcb_layer_widget.h
@@ -141,10 +141,10 @@ protected:
      * listed layer can be reachable in the graphic item properties dialog.
      *
      * @param aLayer is the layer id to test
-     * @return true if LAYER_ID aLayer has meaning in footprint editor mode.
+     * @return true if PCB_LAYER_ID aLayer has meaning in footprint editor mode.
      * and therefore is shown in render panel
      */
-    bool isLayerAllowedInFpMode( LAYER_ID aLayer );
+    bool isLayerAllowedInFpMode( PCB_LAYER_ID aLayer );
 
     /**
      * Function OnRightDownLayers
diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp
index e7f7fec..5dcb89f 100644
--- a/pcbnew/class_pcb_text.cpp
+++ b/pcbnew/class_pcb_text.cpp
@@ -87,7 +87,7 @@ void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
     // shade text if high contrast mode is active
     if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
     {
-        LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+        PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
         if( !IsOnLayer( curr_layer ) )
             color = COLOR4D( DARKDARKGRAY );
@@ -95,8 +95,8 @@ void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
 
     COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
 
-    if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
-        anchor_color = brd->GetVisibleElementColor( ANCHOR_VISIBLE );
+    if( brd->IsElementVisible( LAYER_ANCHOR ) )
+        anchor_color = brd->GetVisibleElementColor( LAYER_ANCHOR );
 
     EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
     EDA_TEXT::Draw( clipbox, DC, offset, color,
diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp
index 460ce0a..0e6bbb7 100644
--- a/pcbnew/class_text_mod.cpp
+++ b/pcbnew/class_text_mod.cpp
@@ -224,21 +224,21 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMod
 
     BOARD* brd = GetBoard( );
     COLOR4D color = brd->GetLayerColor( GetLayer() );
-    LAYER_ID text_layer = GetLayer();
+    PCB_LAYER_ID text_layer = GetLayer();
 
     if( !brd->IsLayerVisible( m_Layer )
-      || (IsFrontLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_FR_VISIBLE ))
-      || (IsBackLayer( text_layer ) && !brd->IsElementVisible( MOD_TEXT_BK_VISIBLE )) )
+      || ( IsFrontLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_FR ) )
+      || ( IsBackLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_BK ) ) )
         return;
 
-    // Invisible texts are still drawn (not plotted) in MOD_TEXT_INVISIBLE
+    // Invisible texts are still drawn (not plotted) in LAYER_MOD_TEXT_INVISIBLE
     // Just because we must have to edit them (at least to make them visible)
     if( !IsVisible() )
     {
-        if( !brd->IsElementVisible( MOD_TEXT_INVISIBLE ) )
+        if( !brd->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) )
             return;
 
-        color = brd->GetVisibleElementColor( MOD_TEXT_INVISIBLE );
+        color = brd->GetVisibleElementColor( LAYER_MOD_TEXT_INVISIBLE );
     }
 
     DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)aPanel->GetDisplayOptions();
@@ -246,7 +246,7 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMod
     // shade text if high contrast mode is active
     if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
     {
-        LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
+        PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
 
         if( !IsOnLayer( curr_layer ) )
             color = COLOR4D( DARKDARKGRAY );
@@ -262,9 +262,9 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMod
     wxPoint pos = GetTextPos() - aOffset;
 
     // Draw the text anchor point
-    if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
+    if( brd->IsElementVisible( LAYER_ANCHOR ) )
     {
-        COLOR4D anchor_color = brd->GetVisibleElementColor(ANCHOR_VISIBLE);
+        COLOR4D anchor_color = brd->GetVisibleElementColor( LAYER_ANCHOR );
         GRDrawAnchor( aPanel->GetClipBox(), aDC, pos.x, pos.y, DIM_ANCRE_TEXTE, anchor_color );
     }
 
@@ -433,11 +433,11 @@ const BOX2I TEXTE_MODULE::ViewBBox() const
 void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
 {
     if( !IsVisible() )      // Hidden text
-        aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_INVISIBLE );
+        aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
     //else if( IsFrontLayer( m_Layer ) )
-        //aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE );
+        //aLayers[0] = LAYER_MOD_TEXT_FR;
     //else if( IsBackLayer( m_Layer ) )
-        //aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE );
+        //aLayers[0] = LAYER_MOD_TEXT_BK;
     else
         aLayers[0] = GetLayer();
 
@@ -452,18 +452,18 @@ unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
     if( !aView )
         return 0;
 
-    if( m_Type == TEXT_is_VALUE && !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_VALUES_VISIBLE ) ) )
+    if( m_Type == TEXT_is_VALUE && !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
         return MAX;
 
-    if( m_Type == TEXT_is_REFERENCE && !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_REFERENCES_VISIBLE ) ) )
+    if( m_Type == TEXT_is_REFERENCE && !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
         return MAX;
 
-    if( IsFrontLayer( m_Layer ) && ( !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ) ) ||
-                                     !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_FR_VISIBLE ) ) ) )
+    if( IsFrontLayer( m_Layer ) && ( !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) ||
+                                     !aView->IsLayerVisible( LAYER_MOD_FR ) ) )
         return MAX;
 
-    if( IsBackLayer( m_Layer ) && ( !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ) ) ||
-                                    !aView->IsLayerVisible( ITEM_GAL_LAYER( MOD_BK_VISIBLE ) ) ) )
+    if( IsBackLayer( m_Layer ) && ( !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) ||
+                                    !aView->IsLayerVisible( LAYER_MOD_BK ) ) )
         return MAX;
 
     return 0;
diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp
index 4e7774c..e016c27 100644
--- a/pcbnew/class_track.cpp
+++ b/pcbnew/class_track.cpp
@@ -196,8 +196,8 @@ wxString VIA::GetSelectMenuText() const
         wxString netname = GetNetname();
 
         // say which layers, only two for now
-        LAYER_ID topLayer;
-        LAYER_ID botLayer;
+        PCB_LAYER_ID topLayer;
+        PCB_LAYER_ID botLayer;
         LayerPair( &topLayer, &botLayer );
         text.Printf( format.GetData(), GetChars( ShowWidth() ),
                      GetChars( netname ), GetNetCode(),
@@ -364,8 +364,8 @@ void VIA::Flip( const wxPoint& aCentre )
     if( GetViaType() != VIA_THROUGH )
     {
         int copperLayerCount = GetBoard()->GetCopperLayerCount();
-        LAYER_ID top_layer;
-        LAYER_ID bottom_layer;
+        PCB_LAYER_ID top_layer;
+        PCB_LAYER_ID bottom_layer;
         LayerPair( &top_layer, &bottom_layer );
         top_layer = FlipLayer( top_layer, copperLayerCount );
         bottom_layer = FlipLayer( bottom_layer, copperLayerCount );
@@ -390,9 +390,9 @@ SEARCH_RESULT TRACK::Visit( INSPECTOR inspector, void* testData, const KICAD_T s
 }
 
 
-bool VIA::IsOnLayer( LAYER_ID layer_number ) const
+bool VIA::IsOnLayer( PCB_LAYER_ID layer_number ) const
 {
-    LAYER_ID bottom_layer, top_layer;
+    PCB_LAYER_ID bottom_layer, top_layer;
 
     LayerPair( &top_layer, &bottom_layer );
 
@@ -416,7 +416,7 @@ LSET VIA::GetLayerSet() const
 
     wxASSERT( m_Layer <= m_BottomLayer );
 
-    // LAYER_IDs are numbered from front to back, this is top to bottom.
+    // PCB_LAYER_IDs are numbered from front to back, this is top to bottom.
     for( LAYER_NUM id = m_Layer;  id <= m_BottomLayer;  ++id )
     {
         layermask.set( id );
@@ -426,7 +426,7 @@ LSET VIA::GetLayerSet() const
 }
 
 
-void VIA::SetLayerPair( LAYER_ID aTopLayer, LAYER_ID aBottomLayer )
+void VIA::SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer )
 {
     if( GetViaType() == VIA_THROUGH )
     {
@@ -442,10 +442,10 @@ void VIA::SetLayerPair( LAYER_ID aTopLayer, LAYER_ID aBottomLayer )
 }
 
 
-void VIA::LayerPair( LAYER_ID* top_layer, LAYER_ID* bottom_layer ) const
+void VIA::LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const
 {
-    LAYER_ID t_layer = F_Cu;
-    LAYER_ID b_layer = B_Cu;
+    PCB_LAYER_ID t_layer = F_Cu;
+    PCB_LAYER_ID b_layer = B_Cu;
 
     if( GetViaType() != VIA_THROUGH )
     {
@@ -613,7 +613,7 @@ void TRACK::DrawShortNetname( EDA_DRAW_PANEL* panel,
             }
         }
 
-        LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+        PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
         if( ( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE )
          && ( !(!IsOnLayer( curr_layer )&& displ_opts->m_ContrastModeDisplay) ) )
@@ -652,7 +652,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
 
     if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts->m_ContrastModeDisplay )
     {
-        LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+        PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
         if( !IsOnLayer( curr_layer ) )
             color = COLOR4D( DARKDARKGRAY );
@@ -720,7 +720,7 @@ void SEGZONE::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
 
     if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts->m_ContrastModeDisplay )
     {
-        LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+        PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
         if( !IsOnLayer( curr_layer ) )
             color = COLOR4D( DARKDARKGRAY );
@@ -783,7 +783,7 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
     wxCHECK_RET( panel != NULL, wxT( "VIA::Draw panel cannot be NULL." ) );
 
     int radius;
-    LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
 
     int fillvia = 0;
     PCB_BASE_FRAME* frame  = (PCB_BASE_FRAME*) panel->GetParent();
@@ -796,9 +796,9 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
     GRSetDrawMode( aDC, aDrawMode );
 
     BOARD * brd =  GetBoard();
-    COLOR4D color = brd->GetVisibleElementColor( VIAS_VISIBLE + GetViaType() );
+    COLOR4D color = brd->GetVisibleElementColor( LAYER_VIAS + GetViaType() );
 
-    if( brd->IsElementVisible( PCB_VISIBLE(VIAS_VISIBLE + GetViaType()) ) == false
+    if( brd->IsElementVisible( LAYER_VIAS + GetViaType() ) == false
         && !( aDrawMode & GR_HIGHLIGHT ) )
        return;
 
@@ -929,7 +929,7 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
     if( GetViaType() == VIA_BLIND_BURIED )
     {
         int ax = 0, ay = radius, bx = 0, by = drill_radius;
-        LAYER_ID layer_top, layer_bottom;
+        PCB_LAYER_ID layer_top, layer_bottom;
 
         LayerPair( &layer_top, &layer_bottom );
 
@@ -990,25 +990,25 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w
 
 void VIA::ViewGetLayers( int aLayers[], int& aCount ) const
 {
-    aLayers[0] = ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE );
+    aLayers[0] = LAYER_VIAS_HOLES;
     aCount = 2;
 
     // Just show it on common via & via holes layers
     switch( GetViaType() )
     {
     case VIA_THROUGH:
-        aLayers[1] = ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE );
+        aLayers[1] = LAYER_VIA_THROUGH;
         break;
 
     case VIA_BLIND_BURIED:
-        aLayers[1] = ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE );
+        aLayers[1] = LAYER_VIA_BBLIND;
         aLayers[2] = m_Layer;
         aLayers[3] = m_BottomLayer;
         aCount += 2;
         break;
 
     case VIA_MICROVIA:
-        aLayers[1] = ITEM_GAL_LAYER( VIA_MICROVIA_VISIBLE );
+        aLayers[1] = LAYER_VIA_MICROVIA;
         break;
 
     default:
@@ -1213,7 +1213,7 @@ void VIA::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
 
 
     // Display layer pair
-    LAYER_ID top_layer, bottom_layer;
+    PCB_LAYER_ID top_layer, bottom_layer;
 
     LayerPair( &top_layer, &bottom_layer );
 
@@ -1312,7 +1312,7 @@ bool VIA::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
 }
 
 
-VIA* TRACK::GetVia( const wxPoint& aPosition, LAYER_ID aLayer)
+VIA* TRACK::GetVia( const wxPoint& aPosition, PCB_LAYER_ID aLayer)
 {
     for( VIA* via = GetFirstVia( this ); via; via = GetFirstVia( via->Next() ) )
     {
diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h
index a9cee70..4cfa369 100644
--- a/pcbnew/class_track.h
+++ b/pcbnew/class_track.h
@@ -45,6 +45,7 @@ class MSG_PANEL_ITEM;
 
 
 // Via types
+// Note that this enum must be synchronized to GAL_LAYER_ID
 enum VIATYPE_T
 {
     VIA_THROUGH      = 3,      /* Always a through hole via */
@@ -232,7 +233,7 @@ public:
      * @param aLayer The layer to match, pass -1 for a don't care.
      * @return A pointer to a VIA object if found, else NULL.
      */
-    VIA* GetVia( const wxPoint& aPosition, LAYER_ID aLayer = UNDEFINED_LAYER );
+    VIA* GetVia( const wxPoint& aPosition, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
 
     /**
      * Function GetVia
@@ -390,7 +391,7 @@ public:
     void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
                GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
 
-    bool IsOnLayer( LAYER_ID aLayer ) const override;
+    bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
 
     virtual LSET GetLayerSet() const override;
 
@@ -401,7 +402,7 @@ public:
      * @param aTopLayer = first layer connected by the via
      * @param aBottomLayer = last layer connected by the via
      */
-    void SetLayerPair( LAYER_ID aTopLayer, LAYER_ID aBottomLayer );
+    void SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer );
 
     /**
      * Function LayerPair
@@ -410,7 +411,7 @@ public:
      *  @param top_layer = pointer to the first layer (can be null)
      *  @param bottom_layer = pointer to the last layer (can be null)
      */
-    void LayerPair( LAYER_ID* top_layer, LAYER_ID* bottom_layer ) const;
+    void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const;
 
     const wxPoint& GetPosition() const override {  return m_Start; }
     void SetPosition( const wxPoint& aPoint ) override { m_Start = aPoint;  m_End = aPoint; }
@@ -481,7 +482,7 @@ protected:
 
 private:
     /// The bottom layer of the via (the top layer is in m_Layer)
-    LAYER_ID  m_BottomLayer;
+    PCB_LAYER_ID  m_BottomLayer;
 
     VIATYPE_T m_ViaType;        // Type of via
 
diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp
index a716184..6468995 100644
--- a/pcbnew/class_zone.cpp
+++ b/pcbnew/class_zone.cpp
@@ -172,7 +172,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMod
         return;
 
     wxPoint     seg_start, seg_end;
-    LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
     BOARD*      brd   = GetBoard();
 
     COLOR4D     color = brd->GetLayerColor( m_Layer );
@@ -255,7 +255,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
         return;
 
     BOARD*      brd = GetBoard();
-    LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
     COLOR4D     color = brd->GetLayerColor( m_Layer );
 
     if( brd->IsLayerVisible( m_Layer ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
@@ -380,7 +380,7 @@ void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC,
     if( !DC )
         return;
 
-    LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
+    PCB_LAYER_ID    curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
     BOARD*      brd   = GetBoard();
     COLOR4D     color = brd->GetLayerColor( m_Layer );
     DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
diff --git a/pcbnew/class_zone_settings.h b/pcbnew/class_zone_settings.h
index d2a4611..d7977e9 100644
--- a/pcbnew/class_zone_settings.h
+++ b/pcbnew/class_zone_settings.h
@@ -64,7 +64,7 @@ public:
     int  m_ZoneMinThickness;            ///< Min thickness value in filled areas
     int  m_NetcodeSelection;            ///< Net code selection for the current zone
 
-    LAYER_ID    m_CurrentZone_Layer;    ///< Layer used to create the current zone
+    PCB_LAYER_ID    m_CurrentZone_Layer;    ///< Layer used to create the current zone
 
     /// Option to show the zone area (outlines only, short hatches or full hatches
     int  m_Zone_HatchingStyle;
diff --git a/pcbnew/clean.cpp b/pcbnew/clean.cpp
index cd75aec..34c49a9 100644
--- a/pcbnew/clean.cpp
+++ b/pcbnew/clean.cpp
@@ -403,7 +403,7 @@ const ZONE_CONTAINER* TRACKS_CLEANER::zoneForTrackEndpoint( const TRACK* aTrack,
         ENDPOINT_T aEndPoint )
 {
     // Vias are special cased, since they get a layer range, not a single one
-    LAYER_ID    top_layer, bottom_layer;
+    PCB_LAYER_ID    top_layer, bottom_layer;
     const VIA*  via = dyn_cast<const VIA*>( aTrack );
 
     if( via )
diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp
index 5768b4c..72a62d6 100644
--- a/pcbnew/collectors.cpp
+++ b/pcbnew/collectors.cpp
@@ -380,7 +380,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
     if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) ||
             m_Guide->IgnorePreferredLayer() )
     {
-        LAYER_ID layer = item->GetLayer();
+        PCB_LAYER_ID layer = item->GetLayer();
 
         /* Modules and their subcomponents: reference, value and pads
          * are not sensitive to the layer visibility controls.  They all
@@ -413,7 +413,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
         // no effect on other criteria, since there is a separate "ignore" control for
         // those in the COLLECTORS_GUIDE
 
-        LAYER_ID layer = item->GetLayer();
+        PCB_LAYER_ID layer = item->GetLayer();
 
         /* Modules and their subcomponents: reference, value and pads
          * are not sensitive to the layer visibility controls.  They all
diff --git a/pcbnew/collectors.h b/pcbnew/collectors.h
index d3fdb73..1406f47 100644
--- a/pcbnew/collectors.h
+++ b/pcbnew/collectors.h
@@ -71,13 +71,13 @@ public:
      * Function IsLayerLocked
      * @return bool - true if the given layer is locked, else false.
      */
-    virtual     bool IsLayerLocked( LAYER_ID layer ) const = 0;
+    virtual     bool IsLayerLocked( PCB_LAYER_ID layer ) const = 0;
 
     /**
      * Function IsLayerVisible
      * @return bool - true if the given layer is visible, else false.
      */
-    virtual     bool IsLayerVisible( LAYER_ID layer ) const = 0;
+    virtual     bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
 
     /**
      * Function IgnoreLockedLayers
@@ -95,7 +95,7 @@ public:
      * Function GetPreferredLayer
      * @return int - the preferred layer for HitTest()ing.
      */
-    virtual     LAYER_ID GetPreferredLayer() const = 0;
+    virtual     PCB_LAYER_ID GetPreferredLayer() const = 0;
 
     /**
      * Function IgnorePreferredLayer
@@ -381,7 +381,7 @@ private:
     // the storage architecture here is not important, since this is only
     // a carrier object and its functions are what is used, and data only indirectly.
 
-    LAYER_ID m_PreferredLayer;
+    PCB_LAYER_ID m_PreferredLayer;
     bool    m_IgnorePreferredLayer;
 
     LSET    m_LayerLocked;                  ///< bit-mapped layer locked bits
@@ -412,7 +412,7 @@ public:
      * @param aVisibleLayerMask = current visible layers (bit mask)
      * @param aPreferredLayer = the layer to search first
      */
-    GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, LAYER_ID aPreferredLayer )
+    GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer )
     {
         m_PreferredLayer            = aPreferredLayer;
         m_IgnorePreferredLayer      = false;
@@ -445,12 +445,12 @@ public:
      * Function IsLayerLocked
      * @return bool - true if the given layer is locked, else false.
      */
-    bool IsLayerLocked( LAYER_ID aLayerId ) const override
+    bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
     {
         return m_LayerLocked[aLayerId];
     }
 
-    void SetLayerLocked( LAYER_ID aLayerId, bool isLocked )
+    void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
     {
         m_LayerLocked.set( aLayerId, isLocked );
     }
@@ -459,11 +459,11 @@ public:
      * Function IsLayerVisible
      * @return bool - true if the given layer is visible, else false.
      */
-    bool IsLayerVisible( LAYER_ID aLayerId ) const override
+    bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
     {
         return m_LayerVisible[aLayerId];
     }
-    void SetLayerVisible( LAYER_ID aLayerId, bool isVisible )
+    void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
     {
         m_LayerVisible.set( aLayerId, isVisible );
     }
@@ -489,8 +489,8 @@ public:
      * Function GetPreferredLayer
      * @return int - the preferred layer for HitTest()ing.
      */
-    LAYER_ID GetPreferredLayer() const override    { return m_PreferredLayer; }
-    void SetPreferredLayer( LAYER_ID aLayer )      { m_PreferredLayer = aLayer; }
+    PCB_LAYER_ID GetPreferredLayer() const override    { return m_PreferredLayer; }
+    void SetPreferredLayer( PCB_LAYER_ID aLayer )      { m_PreferredLayer = aLayer; }
 
 
     /**
diff --git a/pcbnew/deltrack.cpp b/pcbnew/deltrack.cpp
index 5ddf4db..47f6d83 100644
--- a/pcbnew/deltrack.cpp
+++ b/pcbnew/deltrack.cpp
@@ -51,7 +51,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack )
     {
         if( g_CurrentTrackList.GetCount() > 0 )
         {
-            LAYER_ID previous_layer = GetActiveLayer();
+            PCB_LAYER_ID previous_layer = GetActiveLayer();
 
             DBG( g_CurrentTrackList.VerifyListIntegrity(); )
 
diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp
index af39ad8..93560a3 100644
--- a/pcbnew/dialogs/dialog_SVG_print.cpp
+++ b/pcbnew/dialogs/dialog_SVG_print.cpp
@@ -62,7 +62,7 @@ private:
     LSET            m_printMaskLayer;
     // the list of existing board layers in wxCheckListBox, with the
     // board layers id:
-    std::pair<wxCheckListBox*, int> m_boxSelectLayer[LAYER_ID_COUNT];
+    std::pair<wxCheckListBox*, int> m_boxSelectLayer[PCB_LAYER_ID_COUNT];
     bool            m_printBW;
     wxString        m_outputDirectory;
     bool            m_printMirror;
@@ -160,7 +160,7 @@ void DIALOG_SVG_PRINT::initDialog()
 
     for(  ;  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
         int checkIndex;
 
         if( IsCopperLayer( layer ) )
@@ -286,7 +286,7 @@ void DIALOG_SVG_PRINT::ExportSVGFile( bool aOnlyOneFile )
 
     for( LSEQ seq = all_selected.Seq();  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         wxFileName fn( boardFilename );
 
diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp
index b20b241..5f069a3 100644
--- a/pcbnew/dialogs/dialog_copper_zones.cpp
+++ b/pcbnew/dialogs/dialog_copper_zones.cpp
@@ -71,7 +71,7 @@ private:
 
     long            m_NetFiltering;
 
-    std::vector<LAYER_ID> m_LayerId;        ///< Handle the real layer number from layer
+    std::vector<PCB_LAYER_ID> m_LayerId;    ///< Handle the real layer number from layer
                                             ///< name position in m_LayerSelectionCtrl
 
     static wxString m_netNameShowFilter;    ///< the filter to show nets (default * "*").
@@ -245,7 +245,7 @@ void DIALOG_COPPER_ZONE::initDialog()
 
     for( LSEQ cu_stack = cu_set.UIOrder();  cu_stack;  ++cu_stack, imgIdx++ )
     {
-        LAYER_ID layer = *cu_stack;
+        PCB_LAYER_ID layer = *cu_stack;
 
         m_LayerId.push_back( layer );
 
diff --git a/pcbnew/dialogs/dialog_display_options.cpp b/pcbnew/dialogs/dialog_display_options.cpp
index 9a91864..adc1552 100644
--- a/pcbnew/dialogs/dialog_display_options.cpp
+++ b/pcbnew/dialogs/dialog_display_options.cpp
@@ -99,7 +99,7 @@ bool DIALOG_DISPLAY_OPTIONS::TransferDataToWindow()
     m_OptDisplayModOutlines->SetValue( displ_opts->m_DisplayModEdgeFill == SKETCH );
     m_OptDisplayPadClearence->SetValue( displ_opts->m_DisplayPadIsol );
     m_OptDisplayPadNumber->SetValue( displ_opts->m_DisplayPadNum );
-    m_OptDisplayPadNoConn->SetValue( m_parent->IsElementVisible( PCB_VISIBLE( NO_CONNECTS_VISIBLE ) ) );
+    m_OptDisplayPadNoConn->SetValue( m_parent->IsElementVisible( LAYER_NO_CONNECTS ) );
     m_OptDisplayDrawings->SetValue( displ_opts->m_DisplayDrawItemsFill == SKETCH );
     m_ShowNetNamesOption->SetSelection( displ_opts->m_DisplayNetNamesMode );
 
@@ -133,7 +133,7 @@ bool DIALOG_DISPLAY_OPTIONS::TransferDataFromWindow()
 
     displ_opts->m_DisplayPadNum = m_OptDisplayPadNumber->GetValue();
 
-    m_parent->SetElementVisibility( PCB_VISIBLE( NO_CONNECTS_VISIBLE ),
+    m_parent->SetElementVisibility( LAYER_NO_CONNECTS,
                                     m_OptDisplayPadNoConn->GetValue() );
 
     displ_opts->m_DisplayDrawItemsFill = not m_OptDisplayDrawings->GetValue();
diff --git a/pcbnew/dialogs/dialog_exchange_modules.cpp b/pcbnew/dialogs/dialog_exchange_modules.cpp
index 8004e72..c411ef0 100644
--- a/pcbnew/dialogs/dialog_exchange_modules.cpp
+++ b/pcbnew/dialogs/dialog_exchange_modules.cpp
@@ -123,7 +123,7 @@ void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event )
 
     if( result )
     {
-        if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+        if( m_parent->GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
             m_parent->Compile_Ratsnest( NULL, true );
 
         m_parent->GetCanvas()->Refresh();
diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp
index 8f2b0fb..4ecae6c 100644
--- a/pcbnew/dialogs/dialog_general_options.cpp
+++ b/pcbnew/dialogs/dialog_general_options.cpp
@@ -83,7 +83,7 @@ void DIALOG_GENERALOPTIONS::init()
     m_MaxShowLinks->SetValue( displ_opts->m_MaxLinksShowed );
 
     m_DrcOn->SetValue( g_Drc_On );
-    m_ShowGlobalRatsnest->SetValue( m_Board->IsElementVisible( RATSNEST_VISIBLE ) );
+    m_ShowGlobalRatsnest->SetValue( m_Board->IsElementVisible( LAYER_RATSNEST ) );
     m_TrackAutodel->SetValue( g_AutoDeleteOldTrack );
     m_Track_45_Only_Ctrl->SetValue( g_Track_45_Only_Allowed );
     m_Segments_45_Only_Ctrl->SetValue( g_Segments_45_Only );
@@ -124,9 +124,9 @@ void DIALOG_GENERALOPTIONS::OnOkClick( wxCommandEvent& event )
     displ_opts->m_MaxLinksShowed = m_MaxShowLinks->GetValue();
     g_Drc_On = m_DrcOn->GetValue();
 
-    if( m_Board->IsElementVisible(RATSNEST_VISIBLE) != m_ShowGlobalRatsnest->GetValue() )
+    if( m_Board->IsElementVisible( LAYER_RATSNEST ) != m_ShowGlobalRatsnest->GetValue() )
     {
-        GetParent()->SetElementVisibility( RATSNEST_VISIBLE, m_ShowGlobalRatsnest->GetValue() );
+        GetParent()->SetElementVisibility( LAYER_RATSNEST, m_ShowGlobalRatsnest->GetValue() );
         GetParent()->GetCanvas()->Refresh();
         GetParent()->OnModify();
     }
diff --git a/pcbnew/dialogs/dialog_keepout_area_properties.cpp b/pcbnew/dialogs/dialog_keepout_area_properties.cpp
index 9da362d..80363a2 100644
--- a/pcbnew/dialogs/dialog_keepout_area_properties.cpp
+++ b/pcbnew/dialogs/dialog_keepout_area_properties.cpp
@@ -158,7 +158,7 @@ void DIALOG_KEEPOUT_AREA_PROPERTIES::initDialog()
 
     for( LSEQ cu_stack = show.UIOrder();  cu_stack;  ++cu_stack, imgIdx++ )
     {
-        LAYER_ID layer = *cu_stack;
+        PCB_LAYER_ID layer = *cu_stack;
 
         m_layerId.push_back( layer );
 
diff --git a/pcbnew/dialogs/dialog_layers_setup.cpp b/pcbnew/dialogs/dialog_layers_setup.cpp
index 0b4d546..a7b9756 100644
--- a/pcbnew/dialogs/dialog_layers_setup.cpp
+++ b/pcbnew/dialogs/dialog_layers_setup.cpp
@@ -73,7 +73,7 @@ static LSEQ dlg_layers()
 {
     // layers that are put out into the dialog UI, coordinate with wxformbuilder and
     // getCTLs( LAYER_NUM aLayerNumber )
-    static const LAYER_ID layers[] = {
+    static const PCB_LAYER_ID layers[] = {
         F_CrtYd,
         F_Fab,
         F_Adhes,
@@ -396,7 +396,7 @@ void DIALOG_LAYERS_SETUP::showBoardLayerNames()
 
     for( LSEQ seq = dlg_layers();  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         wxControl*  ctl = getName( layer );
 
@@ -421,7 +421,7 @@ void DIALOG_LAYERS_SETUP::showSelectedLayerCheckBoxes( LSET enabledLayers )
     // the check boxes
     for( LSEQ seq = dlg_layers();  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
         setLayerCheckBox( layer, enabledLayers[layer] );
     }
 }
@@ -448,7 +448,7 @@ void DIALOG_LAYERS_SETUP::showLayerTypes()
 {
     for( LSEQ seq = LSET::AllCuMask().Seq();  seq;  ++seq )
     {
-        LAYER_ID cu_layer = *seq;
+        PCB_LAYER_ID cu_layer = *seq;
 
         wxChoice* ctl = getChoice( cu_layer );
         ctl->SetSelection( m_pcb->GetLayerType( cu_layer ) );
@@ -462,7 +462,7 @@ LSET DIALOG_LAYERS_SETUP::getUILayerMask()
 
     for( LSEQ seq = dlg_layers();  seq;  ++seq )
     {
-        LAYER_ID    layer = *seq;
+        PCB_LAYER_ID    layer = *seq;
         wxCheckBox* ctl = getCheckBox( layer );
 
         if( ctl->GetValue() )
@@ -498,7 +498,7 @@ void DIALOG_LAYERS_SETUP::setCopperLayerCheckBoxes( int copperCount )
 
     for( LSEQ seq = LSET::InternalCuMask().Seq();  seq;  ++seq, --copperCount )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
         bool     state = copperCount > 0;
 
 #ifdef HIDE_INACTIVE_LAYERS
@@ -607,7 +607,7 @@ void DIALOG_LAYERS_SETUP::OnOkButtonClick( wxCommandEvent& event )
 
         for( LSEQ seq = LSET::AllCuMask().Seq();  seq;  ++seq )
         {
-            LAYER_ID  layer = *seq;
+            PCB_LAYER_ID  layer = *seq;
 
             if( m_enabledLayers[layer] )
             {
@@ -671,7 +671,7 @@ bool DIALOG_LAYERS_SETUP::testLayerNames()
 
     for( LSEQ seq = LSET::AllCuMask().Seq();  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         // we _can_ rely on m_enabledLayers being current here:
         if( !m_enabledLayers[layer] )
diff --git a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
index d55eea7..b46ba83 100644
--- a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
+++ b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
@@ -143,7 +143,7 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init()
     wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
     m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL );
 
-    LAYER_ID lyrSelect = m_parent->GetActiveLayer();
+    PCB_LAYER_ID lyrSelect = m_parent->GetActiveLayer();
 
     if( m_zone )
         lyrSelect = m_zone->GetLayer();
@@ -153,7 +153,7 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init()
 
     for( LSEQ seq = LSET::AllNonCuMask().Seq(); seq; ++seq, ++imgIdx )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         COLOR4D layerColor = board->GetLayerColor( layer );
         imageList->Add( makeLayerBitmap( layerColor ) );
diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp
index 3e127b5..321cabe 100644
--- a/pcbnew/dialogs/dialog_pad_properties.cpp
+++ b/pcbnew/dialogs/dialog_pad_properties.cpp
@@ -171,12 +171,12 @@ void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event )
 
     if( m_dummyPad->GetLayerSet()[F_Cu] )
     {
-        color = m_board->GetVisibleElementColor( PAD_FR_VISIBLE );
+        color = m_board->GetVisibleElementColor( LAYER_PAD_FR );
     }
 
     if( m_dummyPad->GetLayerSet()[B_Cu] )
     {
-        color = color.LegacyMix( m_board->GetVisibleElementColor( PAD_BK_VISIBLE ) );
+        color = color.LegacyMix( m_board->GetVisibleElementColor( LAYER_PAD_BK ) );
     }
 
     // What could happen: the pad color is *actually* black, or no
diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp
index dea1cec..ff67b19 100644
--- a/pcbnew/dialogs/dialog_plot.cpp
+++ b/pcbnew/dialogs/dialog_plot.cpp
@@ -149,7 +149,7 @@ void DIALOG_PLOT::Init_Dialog()
     // Populate the check list box by all enabled layers names
     for( LSEQ seq = m_layerList;  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         int checkIndex = m_layerCheckListBox->Append( m_board->GetLayerName( layer ) );
 
@@ -768,7 +768,7 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
 
     for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder();  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         // All copper layers that are disabled are actually selected
         // This is due to wonkyness in automatically selecting copper layers
diff --git a/pcbnew/dialogs/dialog_print_using_printer.cpp b/pcbnew/dialogs/dialog_print_using_printer.cpp
index 93f1eb4..7edd573 100644
--- a/pcbnew/dialogs/dialog_print_using_printer.cpp
+++ b/pcbnew/dialogs/dialog_print_using_printer.cpp
@@ -83,7 +83,7 @@ private:
     wxConfigBase*   m_config;
     // the list of existing board layers in wxCheckListBox, with the
     // board layers id:
-    std::pair<wxCheckListBox*, int> m_boxSelectLayer[LAYER_ID_COUNT];
+    std::pair<wxCheckListBox*, int> m_boxSelectLayer[PCB_LAYER_ID_COUNT];
     static bool     m_ExcludeEdgeLayer;
 
     void OnCloseWindow( wxCloseEvent& event ) override;
@@ -178,7 +178,7 @@ void DIALOG_PRINT_USING_PRINTER::initValues( )
 
     for( ;  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
         int checkIndex;
 
         if( IsCopperLayer( layer ) )
diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp
index 9394805..a55858e 100644
--- a/pcbnew/dialogs/dialog_track_via_properties.cpp
+++ b/pcbnew/dialogs/dialog_track_via_properties.cpp
@@ -51,7 +51,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen
     boost::optional<int> trackEndX = boost::make_optional<int>( false, 0 );
     boost::optional<int> trackEndY = boost::make_optional<int>( false, 0 );
     boost::optional<int> trackWidth = boost::make_optional<int>( false, 0 );
-    boost::optional<LAYER_ID> trackLayer = boost::make_optional<LAYER_ID>( false, (LAYER_ID) 0 );
+    boost::optional<PCB_LAYER_ID> trackLayer = boost::make_optional<PCB_LAYER_ID>( false, (PCB_LAYER_ID) 0 );
     boost::optional<int> viaX, viaY, viaDiameter;
     boost::optional<int> viaDrill = boost::make_optional<int>( false, 0 );
 
@@ -262,7 +262,7 @@ bool DIALOG_TRACK_VIA_PROPERTIES::Apply( COMMIT& aCommit )
                 LAYER_NUM layer = m_TrackLayerCtrl->GetLayerSelection();
 
                 if( layer != UNDEFINED_LAYER )
-                    t->SetLayer( (LAYER_ID) layer );
+                    t->SetLayer( (PCB_LAYER_ID) layer );
 
                 if( changeLock )
                     t->SetLocked( setLock );
diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp
index dabb9db..6d70e99 100644
--- a/pcbnew/dimension.cpp
+++ b/pcbnew/dimension.cpp
@@ -162,7 +162,7 @@ void DIALOG_DIMENSION_EDITOR::OnOKClick( wxCommandEvent& event )
 {
     BOARD_COMMIT commit( m_parent );
 
-    LAYER_ID newlayer = ToLAYER_ID( m_SelLayerBox->GetLayerSelection() );
+    PCB_LAYER_ID newlayer = ToLAYER_ID( m_SelLayerBox->GetLayerSelection() );
 
     if( !m_parent->GetBoard()->IsLayerEnabled( newlayer ) )
     {
diff --git a/pcbnew/drc_clearance_test_functions.cpp b/pcbnew/drc_clearance_test_functions.cpp
index 4f58d8e..f8fa8db 100644
--- a/pcbnew/drc_clearance_test_functions.cpp
+++ b/pcbnew/drc_clearance_test_functions.cpp
@@ -207,7 +207,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
         // and **only one layer** can be drilled
         if( refvia->GetViaType() == VIA_MICROVIA )
         {
-            LAYER_ID    layer1, layer2;
+            PCB_LAYER_ID    layer1, layer2;
             bool        err = true;
 
             refvia->LayerPair( &layer1, &layer2 );
diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp
index a4ce2a5..b943e83 100644
--- a/pcbnew/eagle_plugin.cpp
+++ b/pcbnew/eagle_plugin.cpp
@@ -1391,7 +1391,7 @@ void EAGLE_PLUGIN::loadLayerDefs( CPTREE& aLayers )
         {
             // some eagle boards do not have contiguous layer number sequences.
 
-#if 0   // pre LAYER_ID & LSET:
+#if 0   // pre PCB_LAYER_ID & LSET:
             m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
 #else
             m_cu_map[it->number] = ki_layer_count;
@@ -1414,7 +1414,7 @@ void EAGLE_PLUGIN::loadLayerDefs( CPTREE& aLayers )
 
         for( EITER it = cu.begin();  it != cu.end();  ++it )
         {
-            LAYER_ID layer =  kicad_layer( it->number );
+            PCB_LAYER_ID layer =  kicad_layer( it->number );
 
             // these function provide their own protection against UNDEFINED_LAYER:
             m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
@@ -1437,8 +1437,8 @@ void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
         {
             m_xpath->push( "wire" );
 
-            EWIRE       w( gr->second );
-            LAYER_ID    layer = kicad_layer( w.layer );
+            EWIRE        w( gr->second );
+            PCB_LAYER_ID layer = kicad_layer( w.layer );
 
             wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
             wxPoint end(   kicad_x( w.x2 ), kicad_y( w.y2 ) );
@@ -1473,8 +1473,8 @@ void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
         {
             m_xpath->push( "text" );
 
-            ETEXT       t( gr->second );
-            LAYER_ID    layer = kicad_layer( t.layer );
+            ETEXT        t( gr->second );
+            PCB_LAYER_ID layer = kicad_layer( t.layer );
 
             if( layer != UNDEFINED_LAYER )
             {
@@ -1561,8 +1561,8 @@ void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
         {
             m_xpath->push( "circle" );
 
-            ECIRCLE     c( gr->second );
-            LAYER_ID    layer = kicad_layer( c.layer );
+            ECIRCLE      c( gr->second );
+            PCB_LAYER_ID layer = kicad_layer( c.layer );
 
             if( layer != UNDEFINED_LAYER )       // unsupported layer
             {
@@ -1584,8 +1584,8 @@ void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
             // net related info on it from the DTD.
             m_xpath->push( "rectangle" );
 
-            ERECT       r( gr->second );
-            LAYER_ID    layer = kicad_layer( r.layer );
+            ERECT        r( gr->second );
+            PCB_LAYER_ID layer = kicad_layer( r.layer );
 
             if( IsCopperLayer( layer ) )
             {
@@ -2148,8 +2148,8 @@ MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) con
 
 void EAGLE_PLUGIN::packageWire( MODULE* aModule, CPTREE& aTree ) const
 {
-    EWIRE       w( aTree );
-    LAYER_ID    layer = kicad_layer( w.layer );
+    EWIRE        w( aTree );
+    PCB_LAYER_ID layer = kicad_layer( w.layer );
 
     if( IsNonCopperLayer( layer ) )     // only valid non-copper wires, skip copper package wires
     {
@@ -2275,8 +2275,8 @@ void EAGLE_PLUGIN::packagePad( MODULE* aModule, CPTREE& aTree ) const
 
 void EAGLE_PLUGIN::packageText( MODULE* aModule, CPTREE& aTree ) const
 {
-    ETEXT       t( aTree );
-    LAYER_ID    layer = kicad_layer( t.layer );
+    ETEXT        t( aTree );
+    PCB_LAYER_ID layer = kicad_layer( t.layer );
 
     if( layer == UNDEFINED_LAYER )
     {
@@ -2381,8 +2381,8 @@ void EAGLE_PLUGIN::packageText( MODULE* aModule, CPTREE& aTree ) const
 
 void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, CPTREE& aTree ) const
 {
-    ERECT       r( aTree );
-    LAYER_ID    layer = kicad_layer( r.layer );
+    ERECT        r( aTree );
+    PCB_LAYER_ID layer = kicad_layer( r.layer );
 
     if( IsNonCopperLayer( layer ) )  // skip copper "package.rectangle"s
     {
@@ -2415,7 +2415,7 @@ void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, CPTREE& aTree ) const
 void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, CPTREE& aTree ) const
 {
     EPOLYGON    p( aTree );
-    LAYER_ID    layer = kicad_layer( p.layer );
+    PCB_LAYER_ID    layer = kicad_layer( p.layer );
 
     if( IsNonCopperLayer( layer ) )  // skip copper "package.rectangle"s
     {
@@ -2464,7 +2464,7 @@ void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, CPTREE& aTree ) const
 void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const
 {
     ECIRCLE         e( aTree );
-    LAYER_ID        layer = kicad_layer( e.layer );
+    PCB_LAYER_ID    layer = kicad_layer( e.layer );
     EDGE_MODULE*    gr = new EDGE_MODULE( aModule, S_CIRCLE );
 
     aModule->GraphicalItems().PushBack( gr );
@@ -2522,8 +2522,8 @@ void EAGLE_PLUGIN::packageHole( MODULE* aModule, CPTREE& aTree ) const
 
 void EAGLE_PLUGIN::packageSMD( MODULE* aModule, CPTREE& aTree ) const
 {
-    ESMD        e( aTree );
-    LAYER_ID    layer = kicad_layer( e.layer );
+    ESMD         e( aTree );
+    PCB_LAYER_ID layer = kicad_layer( e.layer );
 
     if( !IsCopperLayer( layer ) )
     {
@@ -2610,8 +2610,8 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
             if( it->first == "wire" )
             {
                 m_xpath->push( "wire" );
-                EWIRE   w( it->second );
-                LAYER_ID  layer = kicad_layer( w.layer );
+                EWIRE        w( it->second );
+                PCB_LAYER_ID layer = kicad_layer( w.layer );
 
                 if( IsCopperLayer( layer ) )
                 {
@@ -2645,8 +2645,8 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
                 m_xpath->push( "via" );
                 EVIA    v( it->second );
 
-                LAYER_ID  layer_front_most = kicad_layer( v.layer_front_most );
-                LAYER_ID  layer_back_most  = kicad_layer( v.layer_back_most );
+                PCB_LAYER_ID  layer_front_most = kicad_layer( v.layer_front_most );
+                PCB_LAYER_ID  layer_back_most  = kicad_layer( v.layer_back_most );
 
                 if( IsCopperLayer( layer_front_most ) &&
                     IsCopperLayer( layer_back_most ) )
@@ -2722,8 +2722,8 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
             {
                 m_xpath->push( "polygon" );
 
-                EPOLYGON    p( it->second );
-                LAYER_ID    layer = kicad_layer( p.layer );
+                EPOLYGON     p( it->second );
+                PCB_LAYER_ID layer = kicad_layer( p.layer );
 
                 if( IsCopperLayer( layer ) )
                 {
@@ -2821,7 +2821,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
 }
 
 
-LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
+PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
 {
     /* will assume this is a valid mapping for all eagle boards until I get paid more:
 
@@ -2949,7 +2949,7 @@ LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
         }
     }
 
-    return LAYER_ID( kiLayer );
+    return PCB_LAYER_ID( kiLayer );
 }
 
 
diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h
index 99a667f..e550be6 100644
--- a/pcbnew/eagle_plugin.h
+++ b/pcbnew/eagle_plugin.h
@@ -160,7 +160,7 @@ private:
     wxSize  kicad_fontz( double d ) const;
 
     /// Convert an Eagle layer to a KiCad layer.
-    LAYER_ID kicad_layer( int aLayer ) const;
+    PCB_LAYER_ID kicad_layer( int aLayer ) const;
 
     /// Convert a KiCad distance to an Eagle distance.
     double  eagle( BIU d ) const            { return mm_per_biu * d; }
diff --git a/pcbnew/edgemod.cpp b/pcbnew/edgemod.cpp
index f24dc07..dd0c494 100644
--- a/pcbnew/edgemod.cpp
+++ b/pcbnew/edgemod.cpp
@@ -193,14 +193,14 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* aEdge )
     // note: if aEdge == NULL, all outline segments will be modified
 
     MODULE*     module = GetBoard()->m_Modules;
-    LAYER_ID    layer = F_SilkS;
+    PCB_LAYER_ID    layer = F_SilkS;
     bool        modified = false;
 
     if( aEdge )
         layer = aEdge->GetLayer();
 
     // Ask for the new layer
-    LAYER_ID new_layer = SelectLayer( layer, Edge_Cuts );
+    PCB_LAYER_ID new_layer = SelectLayer( layer, Edge_Cuts );
 
     if( layer < 0 )
         return;
diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp
index 22307a8..3c594ce 100644
--- a/pcbnew/edit.cpp
+++ b/pcbnew/edit.cpp
@@ -439,7 +439,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
 
                 wxGetMousePosition( &dlgPosition.x, &dlgPosition.y );
 
-                LAYER_ID layer = SelectLayer( GetActiveLayer(), LSET::AllNonCuMask(), dlgPosition );
+                PCB_LAYER_ID layer = SelectLayer( GetActiveLayer(), LSET::AllNonCuMask(), dlgPosition );
 
                 m_canvas->SetIgnoreMouseEvents( false );
                 m_canvas->MoveCursorToCrossHair();
@@ -988,7 +988,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
 
     case ID_POPUP_PCB_SELECT_LAYER:
         {
-            LAYER_ID itmp = SelectLayer( GetActiveLayer() );
+            PCB_LAYER_ID itmp = SelectLayer( GetActiveLayer() );
 
             if( itmp >= 0 )
             {
@@ -1011,7 +1011,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
 
     case ID_POPUP_PCB_SELECT_NO_CU_LAYER:
         {
-            LAYER_ID itmp = SelectLayer( GetActiveLayer(), LSET::AllCuMask() );
+            PCB_LAYER_ID itmp = SelectLayer( GetActiveLayer(), LSET::AllCuMask() );
 
             if( itmp >= 0 )
                 SetActiveLayer( itmp );
@@ -1022,7 +1022,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
 
     case ID_POPUP_PCB_SELECT_CU_LAYER:
         {
-            LAYER_ID itmp = SelectLayer( GetActiveLayer(), LSET::AllNonCuMask() );
+            PCB_LAYER_ID itmp = SelectLayer( GetActiveLayer(), LSET::AllNonCuMask() );
 
             if( itmp >= 0 )
                 SetActiveLayer( itmp );
@@ -1347,9 +1347,9 @@ void PCB_EDIT_FRAME::RemoveStruct( BOARD_ITEM* Item, wxDC* DC )
 }
 
 
-void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_ID layer )
+void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer )
 {
-    LAYER_ID curLayer = GetActiveLayer();
+    PCB_LAYER_ID curLayer = GetActiveLayer();
     DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
 
     // Check if the specified layer matches the present layer
diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp
index c12e608..f793e3e 100644
--- a/pcbnew/edit_pcb_text.cpp
+++ b/pcbnew/edit_pcb_text.cpp
@@ -203,7 +203,7 @@ TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
         GetBoard()->Add( textePcb );
         textePcb->SetFlags( IS_NEW );
 
-        LAYER_ID layer = GetActiveLayer();
+        PCB_LAYER_ID layer = GetActiveLayer();
 
         textePcb->SetLayer( layer );
 
diff --git a/pcbnew/editedge.cpp b/pcbnew/editedge.cpp
index 88fe313..c529831 100644
--- a/pcbnew/editedge.cpp
+++ b/pcbnew/editedge.cpp
@@ -145,7 +145,7 @@ void PCB_EDIT_FRAME::Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC )
 }
 
 
-void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( LAYER_ID aLayer )
+void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( PCB_LAYER_ID aLayer )
 {
     if( IsCopperLayer( aLayer ) )
     {
diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp
index 0d114f1..c0f3b87 100644
--- a/pcbnew/editrack-part2.cpp
+++ b/pcbnew/editrack-part2.cpp
@@ -108,8 +108,8 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC )
     // layer pair is B_Cu and F_Cu.
     via->SetLayerPair( B_Cu, F_Cu );
 
-    LAYER_ID first_layer = GetActiveLayer();
-    LAYER_ID last_layer;
+    PCB_LAYER_ID first_layer = GetActiveLayer();
+    PCB_LAYER_ID last_layer;
 
     // prepare switch to new active layer:
     if( first_layer != GetScreen()->m_Route_Layer_TOP )
@@ -126,7 +126,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC )
 
     case VIA_MICROVIA:  // from external to the near neighbor inner layer
         {
-            LAYER_ID last_inner_layer = ToLAYER_ID( ( GetBoard()->GetCopperLayerCount() - 2 ) );
+            PCB_LAYER_ID last_inner_layer = ToLAYER_ID( ( GetBoard()->GetCopperLayerCount() - 2 ) );
 
             if( first_layer == B_Cu )
                 last_layer = last_inner_layer;
@@ -224,7 +224,7 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC )
     D_PAD*   pt_pad = NULL;
     MODULE*  Module = NULL;
 
-    if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) )
+    if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
         return;
 
     if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
diff --git a/pcbnew/exporters/export_d356.cpp b/pcbnew/exporters/export_d356.cpp
index ab3e581..13c8023 100644
--- a/pcbnew/exporters/export_d356.cpp
+++ b/pcbnew/exporters/export_d356.cpp
@@ -212,7 +212,7 @@ static void build_via_testpoints( BOARD *aPcb,
             rk.drill = via->GetDrillValue();
             rk.mechanical = false;
 
-            LAYER_ID top_layer, bottom_layer;
+            PCB_LAYER_ID top_layer, bottom_layer;
 
             via->LayerPair( &top_layer, &bottom_layer );
 
diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp
index 1276864..67d1361 100644
--- a/pcbnew/exporters/export_gencad.cpp
+++ b/pcbnew/exporters/export_gencad.cpp
@@ -97,7 +97,7 @@ static const wxString GenCADLayerNameFlipped[32] =
 
 #else
 
-static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
+static std::string GenCADLayerName( int aCuCount, PCB_LAYER_ID aId )
 {
     if( IsCopperLayer( aId ) )
     {
@@ -157,7 +157,7 @@ static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
 };
 
 
-static const LAYER_ID gc_seq[] = {
+static const PCB_LAYER_ID gc_seq[] = {
     B_Cu,
     In30_Cu,
     In29_Cu,
@@ -194,7 +194,7 @@ static const LAYER_ID gc_seq[] = {
 
 
 // flipped layer name for Gencad export (to make CAM350 imports correct)
-static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId )
+static std::string GenCADLayerNameFlipped( int aCuCount, PCB_LAYER_ID aId )
 {
     if( 1<= aId && aId <= 14 )
     {
@@ -574,7 +574,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
 
         for( LSEQ seq = mask.Seq( gc_seq, DIM( gc_seq ) );  seq;  ++seq )
         {
-            LAYER_ID layer = *seq;
+            PCB_LAYER_ID layer = *seq;
 
             fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
                     via->GetWidth(), via->GetDrillValue(),
@@ -601,7 +601,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
         // the special gc_seq
         for( LSEQ seq = pad_set.Seq( gc_seq, DIM( gc_seq ) );  seq;  ++seq )
         {
-            LAYER_ID layer = *seq;
+            PCB_LAYER_ID layer = *seq;
 
             fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerName( cu_count, layer ).c_str() );
         }
@@ -609,10 +609,10 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
         // Flipped padstack
         fprintf( aFile, "PADSTACK PAD%uF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
 
-        // the normal LAYER_ID sequence is inverted from gc_seq[]
+        // the normal PCB_LAYER_ID sequence is inverted from gc_seq[]
         for( LSEQ seq = pad_set.Seq();  seq;  ++seq )
         {
-            LAYER_ID layer = *seq;
+            PCB_LAYER_ID layer = *seq;
 
             fprintf( aFile, "PAD P%u %s 0 0\n", i, GenCADLayerNameFlipped( cu_count, layer ).c_str() );
         }
diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp
index b09e1d6..3f55479 100644
--- a/pcbnew/exporters/export_vrml.cpp
+++ b/pcbnew/exporters/export_vrml.cpp
@@ -140,7 +140,7 @@ static SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL };
 class MODEL_VRML
 {
 private:
-    double      m_layer_z[LAYER_ID_COUNT];
+    double      m_layer_z[PCB_LAYER_ID_COUNT];
 
     int         m_iMaxSeg;                  // max. sides to a small circle
     double      m_arcMinLen, m_arcMaxLen;   // min and max lengths of an arc chord
@@ -567,7 +567,7 @@ static void compute_layer_Zs( MODEL_VRML& aModel, BOARD* pcb )
     // Compute each layer's Z value, more or less like the 3d view
     for( LSEQ seq = LSET::AllCuMask().Seq();  seq;  ++seq )
     {
-        LAYER_ID i = *seq;
+        PCB_LAYER_ID i = *seq;
 
         if( i < copper_layers )
             aModel.SetLayerZ( i,  half_thickness - aModel.m_brd_thickness * i / (copper_layers - 1) );
@@ -773,7 +773,7 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb )
     // draw graphic items
     for( BOARD_ITEM* drawing = pcb->m_Drawings; drawing != 0; drawing = drawing->Next() )
     {
-        LAYER_ID layer = drawing->GetLayer();
+        PCB_LAYER_ID layer = drawing->GetLayer();
 
         if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
             continue;
@@ -903,7 +903,7 @@ static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb,
 static void export_vrml_via( MODEL_VRML& aModel, BOARD* aPcb, const VIA* aVia )
 {
     double      x, y, r, hole;
-    LAYER_ID    top_layer, bottom_layer;
+    PCB_LAYER_ID    top_layer, bottom_layer;
 
     hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0;
     r   = aVia->GetWidth() * BOARD_SCALE / 2.0;
diff --git a/pcbnew/exporters/gendrill_Excellon_writer.cpp b/pcbnew/exporters/gendrill_Excellon_writer.cpp
index 941483b..1d52dcd 100644
--- a/pcbnew/exporters/gendrill_Excellon_writer.cpp
+++ b/pcbnew/exporters/gendrill_Excellon_writer.cpp
@@ -714,7 +714,7 @@ std::vector<DRILL_LAYER_PAIR> EXCELLON_WRITER::getUniqueLayerPairs() const
 }
 
 
-const std::string EXCELLON_WRITER::layerName( LAYER_ID aLayer ) const
+const std::string EXCELLON_WRITER::layerName( PCB_LAYER_ID aLayer ) const
 {
     // Generic names here.
     switch( aLayer )
diff --git a/pcbnew/exporters/gendrill_Excellon_writer.h b/pcbnew/exporters/gendrill_Excellon_writer.h
index 9ad5409..79e0e6c 100644
--- a/pcbnew/exporters/gendrill_Excellon_writer.h
+++ b/pcbnew/exporters/gendrill_Excellon_writer.h
@@ -66,16 +66,16 @@ public:
 class HOLE_INFO
 {
 public:
-    int         m_Hole_Diameter;        // hole value, and for oblong: min(hole size x, hole size y)
-    int         m_Tool_Reference;       // Tool reference for this hole = 1 ... n (values <=0 must not be used)
-    wxSize      m_Hole_Size;            // hole size for oblong holes
-    double      m_Hole_Orient;          // Hole rotation (= pad rotation) for oblong holes
-    int         m_Hole_Shape;           // hole shape: round (0) or oval (1)
-    wxPoint     m_Hole_Pos;             // hole position
-    LAYER_ID    m_Hole_Bottom_Layer;    // hole ending layer (usually back layer)
-    LAYER_ID    m_Hole_Top_Layer;       // hole starting layer (usually front layer):
-                                        // m_Hole_Top_Layer < m_Hole_Bottom_Layer
-    bool        m_Hole_NotPlated;       // hole not plated. Must be in a specific drill file or section
+    int          m_Hole_Diameter;        // hole value, and for oblong: min(hole size x, hole size y)
+    int          m_Tool_Reference;       // Tool reference for this hole = 1 ... n (values <=0 must not be used)
+    wxSize       m_Hole_Size;            // hole size for oblong holes
+    double       m_Hole_Orient;          // Hole rotation (= pad rotation) for oblong holes
+    int          m_Hole_Shape;           // hole shape: round (0) or oval (1)
+    wxPoint      m_Hole_Pos;             // hole position
+    PCB_LAYER_ID m_Hole_Bottom_Layer;    // hole ending layer (usually back layer)
+    PCB_LAYER_ID m_Hole_Top_Layer;       // hole starting layer (usually front layer):
+                                         // m_Hole_Top_Layer < m_Hole_Bottom_Layer
+    bool         m_Hole_NotPlated;       // hole not plated. Must be in a specific drill file or section
 
 public:
     HOLE_INFO()
@@ -116,7 +116,7 @@ public:
 };
 
 
-typedef std::pair<LAYER_ID, LAYER_ID>   DRILL_LAYER_PAIR;
+typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID>   DRILL_LAYER_PAIR;
 class OUTPUTFORMATTER;
 
 /**
@@ -361,7 +361,7 @@ private:
 
     const std::string layerPairName( DRILL_LAYER_PAIR aPair ) const;
 
-    const std::string layerName( LAYER_ID aLayer ) const;
+    const std::string layerName( PCB_LAYER_ID aLayer ) const;
 
     /**
      * @return a filename which identify the drill file function.
diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp
index 4790a57..b6a1583 100644
--- a/pcbnew/files.cpp
+++ b/pcbnew/files.cpp
@@ -601,7 +601,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
 
     // Update the RATSNEST items, which were not loaded at the time
     // BOARD::SetVisibleElements() was called from within any PLUGIN.
-    // See case RATSNEST_VISIBLE: in BOARD::SetElementVisibility()
+    // See case LAYER_RATSNEST: in BOARD::SetElementVisibility()
     GetBoard()->SetVisibleElements( GetBoard()->GetVisibleElements() );
 
     // Display the loaded board:
diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp
index 0c025c1..3238903 100644
--- a/pcbnew/footprint_wizard_frame.cpp
+++ b/pcbnew/footprint_wizard_frame.cpp
@@ -146,7 +146,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway,
     DISPLAY_OPTIONS* disp_opts = (DISPLAY_OPTIONS*) GetDisplayOptions();
     disp_opts->m_DisplayPadIsol = false;
     disp_opts->m_DisplayPadNum = true;
-    GetBoard()->SetElementVisibility( PCB_VISIBLE(NO_CONNECTS_VISIBLE), false );
+    GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
 
     GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId  );
 
diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp
index a614e84..11fe793 100644
--- a/pcbnew/initpcb.cpp
+++ b/pcbnew/initpcb.cpp
@@ -54,14 +54,14 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery )
 
     // Items visibility flags will be set because a new board will be created.
     // Grid and ratsnest can be left to their previous state
-    bool showGrid = IsElementVisible( GRID_VISIBLE );
-    bool showRats = IsElementVisible( RATSNEST_VISIBLE );
+    bool showGrid = IsElementVisible( LAYER_GRID );
+    bool showRats = IsElementVisible( LAYER_RATSNEST );
 
     // delete the old BOARD and create a new BOARD so that the default
     // layer names are put into the BOARD.
     SetBoard( new BOARD() );
-    SetElementVisibility( GRID_VISIBLE, showGrid );
-    SetElementVisibility( RATSNEST_VISIBLE, showRats );
+    SetElementVisibility( LAYER_GRID, showGrid );
+    SetElementVisibility( LAYER_RATSNEST, showRats );
 
     SetCurItem( NULL );
 
diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp
index eedff9e..f5eace1 100644
--- a/pcbnew/kicad_plugin.cpp
+++ b/pcbnew/kicad_plugin.cpp
@@ -501,7 +501,7 @@ void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
 {
     if( m_ctl & CTL_STD_LAYER_NAMES )
     {
-        LAYER_ID layer = aItem->GetLayer();
+        PCB_LAYER_ID layer = aItem->GetLayer();
 
         // English layer names should never need quoting.
         m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
@@ -548,7 +548,7 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
 
     for( LSEQ cu = aBoard->GetEnabledLayers().CuStack();  cu;  ++cu )
     {
-        LAYER_ID layer = *cu;
+        PCB_LAYER_ID layer = *cu;
 
         m_out->Print( aNestLevel+1, "(%d %s %s", layer,
                       m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
@@ -562,7 +562,7 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
 
     // Save used non-copper layers in the order they are defined.
     // desired sequence for non Cu BOARD layers.
-    static const LAYER_ID non_cu[] = {
+    static const PCB_LAYER_ID non_cu[] = {
         B_Adhes,        // 32
         F_Adhes,
         B_Paste,
@@ -585,7 +585,7 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
 
     for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) );  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         m_out->Print( aNestLevel+1, "(%d %s user", layer,
                       m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
@@ -1211,15 +1211,15 @@ void PCB_IO::formatLayers( LSET aLayerMask, int aNestLevel ) const
 
     wxString layerName;
 
-    for( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
+    for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
     {
         if( aLayerMask[layer] )
         {
             if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
-                layerName = m_board->GetLayerName( LAYER_ID( layer ) );
+                layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
 
             else    // I am being called from FootprintSave()
-                layerName = BOARD::GetStandardLayerName( LAYER_ID( layer ) );
+                layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
 
             output += ' ';
             output += m_out->Quotew( layerName );
@@ -1437,7 +1437,7 @@ void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const
 {
     if( aTrack->Type() == PCB_VIA_T )
     {
-        LAYER_ID  layer1, layer2;
+        PCB_LAYER_ID  layer1, layer2;
 
         const VIA*  via = static_cast<const VIA*>(aTrack);
         BOARD*      board = (BOARD*) via->GetParent();
diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp
index 5454892..cffbde7 100644
--- a/pcbnew/legacy_plugin.cpp
+++ b/pcbnew/legacy_plugin.cpp
@@ -282,7 +282,7 @@ inline bool is_leg_copperlayer_valid( int aCu_Count, LAYER_NUM aLegacyLayerNum )
 }
 
 
-LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
+PCB_LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
 {
     int         newid;
     unsigned    old = aLayerNum;
@@ -325,7 +325,7 @@ LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
         }
     }
 
-    return LAYER_ID( newid );
+    return PCB_LAYER_ID( newid );
 }
 
 
@@ -868,8 +868,8 @@ void LEGACY_PLUGIN::loadSETUP()
         {
             // eg: "Layer[n]  <a_Layer_name_with_no_spaces> <LAYER_T>"
 
-            LAYER_NUM   layer_num = layerParse( line + SZ( "Layer[" ), &data );
-            LAYER_ID    layer_id  = leg_layer2new( m_cu_count, layer_num );
+            LAYER_NUM    layer_num = layerParse( line + SZ( "Layer[" ), &data );
+            PCB_LAYER_ID layer_id  = leg_layer2new( m_cu_count, layer_num );
 
             /*
             switch( layer_num )
@@ -883,7 +883,7 @@ void LEGACY_PLUGIN::loadSETUP()
                 break;
 
             default:
-                layer_id = LAYER_ID( layer_num );
+                layer_id = PCB_LAYER_ID( layer_num );
             }
             */
 
@@ -1214,8 +1214,8 @@ void LEGACY_PLUGIN::loadMODULE( MODULE* aModule )
             BIU pos_y  = biuParse( data, &data );
             int orient = intParse( data, &data );
 
-            LAYER_NUM layer_num = layerParse( data, &data );
-            LAYER_ID  layer_id  = leg_layer2new( m_cu_count,  layer_num );
+            LAYER_NUM    layer_num = layerParse( data, &data );
+            PCB_LAYER_ID layer_id  = leg_layer2new( m_cu_count,  layer_num );
 
             long edittime  = hexParse( data, &data );
             time_t timestamp = hexParse( data, &data );
@@ -2339,8 +2339,8 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
                 via->SetLayerPair( F_Cu, B_Cu );
             else
             {
-                LAYER_ID  back  = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
-                LAYER_ID  front = leg_layer2new( m_cu_count, layer_num & 0xf );
+                PCB_LAYER_ID back  = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
+                PCB_LAYER_ID front = leg_layer2new( m_cu_count, layer_num & 0xf );
 
                 if( is_leg_copperlayer_valid( m_cu_count, back ) &&
                     is_leg_copperlayer_valid( m_cu_count, front ) )
diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h
index 3aae932..39e6dd8 100644
--- a/pcbnew/legacy_plugin.h
+++ b/pcbnew/legacy_plugin.h
@@ -107,7 +107,7 @@ public:
     void    SaveModule3D( const MODULE* aModule ) const;
 
     // return the new .kicad_pcb layer id from the old (legacy) layer id
-    static LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
+    static PCB_LAYER_ID leg_layer2new( int cu_count, LAYER_NUM aLayerNum );
 
     static LSET     leg_mask2new( int cu_count, unsigned aMask );
 
diff --git a/pcbnew/magnetic_tracks_functions.cpp b/pcbnew/magnetic_tracks_functions.cpp
index 093ddde..ebd0498 100644
--- a/pcbnew/magnetic_tracks_functions.cpp
+++ b/pcbnew/magnetic_tracks_functions.cpp
@@ -191,7 +191,7 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize,
     // after pads, only track & via tests remain, skip them if not desired
     if( doTrack )
     {
-        LAYER_ID layer = screen->m_Active_Layer;
+        PCB_LAYER_ID layer = screen->m_Active_Layer;
 
         for( TRACK* via = m_Pcb->m_Track;
                 via && (via = via->GetVia( *curpos, layer )) != NULL;
diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp
index ddf9681..3651d26 100644
--- a/pcbnew/modedit.cpp
+++ b/pcbnew/modedit.cpp
@@ -976,11 +976,11 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
 
 COLOR4D FOOTPRINT_EDIT_FRAME::GetGridColor() const
 {
-    return g_ColorsSettings.GetItemColor( GRID_VISIBLE );
+    return g_ColorsSettings.GetItemColor( LAYER_GRID );
 }
 
 
-void FOOTPRINT_EDIT_FRAME::SetActiveLayer( LAYER_ID aLayer )
+void FOOTPRINT_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
 {
     PCB_BASE_FRAME::SetActiveLayer( aLayer );
 
diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h
index 310e001..30d806a 100644
--- a/pcbnew/module_editor_frame.h
+++ b/pcbnew/module_editor_frame.h
@@ -419,18 +419,18 @@ public:
      * inline function.
      * @param aElement is from the enum by the same name
      * @return bool - true if the element is visible.
-     * @see enum PCB_VISIBLE
+     * @see enum PCB_LAYER_ID
      */
-    bool IsElementVisible( int aElement ) const;
+    bool IsElementVisible( GAL_LAYER_ID aElement ) const;
 
     /**
      * Function SetElementVisibility
      * changes the visibility of an element category
      * @param aElement is from the enum by the same name
      * @param aNewState = The new visibility state of the element category
-     * @see enum PCB_VISIBLE
+     * @see enum PCB_LAYER_ID
      */
-    void SetElementVisibility( int aElement, bool aNewState );
+    void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState );
 
     /**
      * Function IsGridVisible() , virtual
@@ -453,7 +453,7 @@ public:
     virtual COLOR4D GetGridColor() const override;
 
     ///> @copydoc PCB_BASE_FRAME::SetActiveLayer()
-    void SetActiveLayer( LAYER_ID aLayer ) override;
+    void SetActiveLayer( PCB_LAYER_ID aLayer ) override;
 
     ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
     virtual void UseGalCanvas( bool aEnable ) override;
diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp
index f9deadb..8506cd3 100644
--- a/pcbnew/moduleframe.cpp
+++ b/pcbnew/moduleframe.cpp
@@ -821,25 +821,25 @@ void FOOTPRINT_EDIT_FRAME::updateView()
 
 bool FOOTPRINT_EDIT_FRAME::IsGridVisible() const
 {
-    return IsElementVisible( GRID_VISIBLE );
+    return IsElementVisible( LAYER_GRID );
 }
 
 
 void FOOTPRINT_EDIT_FRAME::SetGridVisibility(bool aVisible)
 {
-    SetElementVisibility( GRID_VISIBLE, aVisible );
+    SetElementVisibility( LAYER_GRID, aVisible );
 }
 
 
-bool FOOTPRINT_EDIT_FRAME::IsElementVisible( int aElement ) const
+bool FOOTPRINT_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
 {
     return GetBoard()->IsElementVisible( aElement );
 }
 
 
-void FOOTPRINT_EDIT_FRAME::SetElementVisibility( int aElement, bool aNewState )
+void FOOTPRINT_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
 {
-    GetGalCanvas()->GetView()->SetLayerVisible( ITEM_GAL_LAYER( aElement ), aNewState );
+    GetGalCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
     GetBoard()->SetElementVisibility( aElement, aNewState );
     m_Layers->SetRenderState( aElement, aNewState );
 }
diff --git a/pcbnew/modules.cpp b/pcbnew/modules.cpp
index a31a2e6..fc09aa6 100644
--- a/pcbnew/modules.cpp
+++ b/pcbnew/modules.cpp
@@ -116,7 +116,7 @@ void PCB_EDIT_FRAME::StartMoveModule( MODULE* aModule, wxDC* aDC,
     aModule->SetFlags( IS_MOVED );
 
     /* Show ratsnest. */
-    if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+    if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
         DrawGeneralRatsnest( aDC );
 
     EraseDragList();
@@ -223,7 +223,7 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC )
     // Display ratsnest is allowed
     pcbframe->GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST;
 
-    if( pcbframe->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+    if( pcbframe->GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
         pcbframe->DrawGeneralRatsnest( DC );
 
 #ifdef __WXMAC__
@@ -269,7 +269,7 @@ bool PCB_EDIT_FRAME::Delete_Module( MODULE* aModule, wxDC* aDC )
     aModule->SetState( IS_DELETED, true );
     SaveCopyInUndoList( aModule, UR_DELETED );
 
-    if( aDC && GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+    if( aDC && GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
         Compile_Ratsnest( aDC, true );
 
     // Redraw the full screen to ensure perfect display of board and ratsnest.
@@ -304,7 +304,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC )
         }
 
         /* Show ratsnest if necessary. */
-        if( DC && GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+        if( DC && GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
             DrawGeneralRatsnest( DC );
 
         g_Offset_Module.x = 0;
@@ -331,7 +331,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC )
         {
             Module->Draw( m_canvas, DC, GR_OR );
 
-            if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+            if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
                 Compile_Ratsnest( DC, true );
         }
     }
@@ -410,7 +410,7 @@ void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreat
 
     m_canvas->SetMouseCapture( NULL, NULL );
 
-    if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) && !aDoNotRecreateRatsnest )
+    if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) && !aDoNotRecreateRatsnest )
         Compile_Ratsnest( aDC, true );
 
     if( aDC )
@@ -443,7 +443,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool
             m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
             module->ClearFlags( DO_NOT_DRAW );
 
-            if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+            if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
                 DrawGeneralRatsnest( DC );
         }
     }
@@ -472,7 +472,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool
             //  not beiing moved: redraw the module and update ratsnest
             module->Draw( m_canvas, DC, GR_OR );
 
-            if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
+            if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
                 Compile_Ratsnest( DC, true );
         }
         else
diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp
index 7cb3695..03e0880 100644
--- a/pcbnew/modview_frame.cpp
+++ b/pcbnew/modview_frame.cpp
@@ -684,7 +684,7 @@ void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
 
 COLOR4D FOOTPRINT_VIEWER_FRAME::GetGridColor() const
 {
-    return g_ColorsSettings.GetItemColor( GRID_VISIBLE );
+    return g_ColorsSettings.GetItemColor( LAYER_GRID );
 }
 
 
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp
index 1b27a8f..f98abae 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp
@@ -48,7 +48,7 @@
 
 namespace PCAD2KICAD {
 
-LAYER_ID PCB::GetKiCadLayer( int aPCadLayer )
+PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer )
 {
     wxASSERT( aPCadLayer >= 0 && aPCadLayer < MAX_PCAD_LAYER_QTY );
     return m_layersMap[aPCadLayer].KiCadLayer;
@@ -479,9 +479,9 @@ int PCB::FindLayer( wxString aLayerName )
  */
 void PCB::MapLayer( XNODE* aNode )
 {
-    wxString    lName, layerType;
-    LAYER_ID    KiCadLayer;
-    long        num = 0;
+    wxString     lName, layerType;
+    PCB_LAYER_ID KiCadLayer;
+    long         num = 0;
 
     aNode->GetAttribute( wxT( "Name" ), &lName );
     lName = lName.MakeUpper();
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.h b/pcbnew/pcad2kicadpcb_plugin/pcb.h
index 916837e..97f6f98 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb.h
@@ -53,7 +53,7 @@ public:
     PCB( BOARD* aBoard );
     ~PCB();
 
-    LAYER_ID        GetKiCadLayer( int aPCadLayer ) override;
+    PCB_LAYER_ID        GetKiCadLayer( int aPCadLayer ) override;
     LAYER_TYPE_T    GetLayerType( int aPCadLayer ) override;
     wxString        GetLayerNetNameRef( int aPCadLayer ) override;
     int             GetNewTimestamp() override;
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h b/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h
index 2c2b5f8..91866cc 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h
@@ -42,7 +42,7 @@ enum LAYER_TYPE_T
 
 typedef struct _TLAYER
 {
-    LAYER_ID      KiCadLayer;
+    PCB_LAYER_ID      KiCadLayer;
     LAYER_TYPE_T  layerType;
     wxString      netNameRef;
 } TLAYER;
@@ -53,7 +53,7 @@ namespace PCAD2KICAD
     class PCB_CALLBACKS
     {
     public:
-        virtual LAYER_ID      GetKiCadLayer( int aPCadLayer ) = 0;
+        virtual PCB_LAYER_ID      GetKiCadLayer( int aPCadLayer ) = 0;
         virtual LAYER_TYPE_T  GetLayerType( int aPCadLayer ) = 0;
         virtual wxString      GetLayerNetNameRef( int aPCadLayer ) = 0;
         virtual int           GetNewTimestamp() = 0;
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_component.h b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h
index 6088fad..72098ce 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_component.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h
@@ -51,7 +51,7 @@ public:
     int         m_tag;
     char        m_objType;
     int         m_PCadLayer;
-    LAYER_ID    m_KiCadLayer;
+    PCB_LAYER_ID    m_KiCadLayer;
     int         m_timestamp;
     int         m_positionX;
     int         m_positionY;
@@ -70,7 +70,7 @@ public:
     virtual void    AddToModule( MODULE* aModule );
     virtual void    AddToBoard() = 0;
 
-    LAYER_ID        GetKiCadLayer() { return m_callbacks->GetKiCadLayer( m_PCadLayer ); }
+    PCB_LAYER_ID        GetKiCadLayer() { return m_callbacks->GetKiCadLayer( m_PCadLayer ); }
     int GetNewTimestamp() { return m_callbacks->GetNewTimestamp(); }
     int GetNetCode( wxString aNetName ) { return m_callbacks->GetNetCode( aNetName ); }
 
diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp
index 7eeefad..5e8ba99 100644
--- a/pcbnew/pcb_draw_panel_gal.cpp
+++ b/pcbnew/pcb_draw_panel_gal.cpp
@@ -41,58 +41,58 @@ using namespace std::placeholders;
 
 const LAYER_NUM GAL_LAYER_ORDER[] =
 {
-    ITEM_GAL_LAYER( GP_OVERLAY ),
-    ITEM_GAL_LAYER( DRC_VISIBLE ),
-    NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE ),
+    LAYER_GP_OVERLAY ,
+    LAYER_DRC,
+    LAYER_PADS_NETNAMES,
     Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts,
 
-    ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ),
-    ITEM_GAL_LAYER( MOD_REFERENCES_VISIBLE), ITEM_GAL_LAYER( MOD_VALUES_VISIBLE ),
-
-    ITEM_GAL_LAYER( RATSNEST_VISIBLE ), ITEM_GAL_LAYER( ANCHOR_VISIBLE ),
-    ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ),
-    ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE ), ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE ),
-    ITEM_GAL_LAYER( VIA_MICROVIA_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ),
-
-    NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_FR_VISIBLE ),
-    NETNAMES_GAL_LAYER( F_Cu ), F_Cu, F_Mask, F_SilkS, F_Paste, F_Adhes,
-
-    NETNAMES_GAL_LAYER( In1_Cu ),   In1_Cu,
-    NETNAMES_GAL_LAYER( In2_Cu ),   In2_Cu,
-    NETNAMES_GAL_LAYER( In3_Cu ),   In3_Cu,
-    NETNAMES_GAL_LAYER( In4_Cu ),   In4_Cu,
-    NETNAMES_GAL_LAYER( In5_Cu ),   In5_Cu,
-    NETNAMES_GAL_LAYER( In6_Cu ),   In6_Cu,
-    NETNAMES_GAL_LAYER( In7_Cu ),   In7_Cu,
-    NETNAMES_GAL_LAYER( In8_Cu ),   In8_Cu,
-    NETNAMES_GAL_LAYER( In9_Cu ),   In9_Cu,
-    NETNAMES_GAL_LAYER( In10_Cu ),  In10_Cu,
-    NETNAMES_GAL_LAYER( In11_Cu ),  In11_Cu,
-    NETNAMES_GAL_LAYER( In12_Cu ),  In12_Cu,
-    NETNAMES_GAL_LAYER( In13_Cu ),  In13_Cu,
-    NETNAMES_GAL_LAYER( In14_Cu ),  In14_Cu,
-    NETNAMES_GAL_LAYER( In15_Cu ),  In15_Cu,
-    NETNAMES_GAL_LAYER( In16_Cu ),  In16_Cu,
-    NETNAMES_GAL_LAYER( In17_Cu ),  In17_Cu,
-    NETNAMES_GAL_LAYER( In18_Cu ),  In18_Cu,
-    NETNAMES_GAL_LAYER( In19_Cu ),  In19_Cu,
-    NETNAMES_GAL_LAYER( In20_Cu ),  In20_Cu,
-    NETNAMES_GAL_LAYER( In21_Cu ),  In21_Cu,
-    NETNAMES_GAL_LAYER( In22_Cu ),  In22_Cu,
-    NETNAMES_GAL_LAYER( In23_Cu ),  In23_Cu,
-    NETNAMES_GAL_LAYER( In24_Cu ),  In24_Cu,
-    NETNAMES_GAL_LAYER( In25_Cu ),  In25_Cu,
-    NETNAMES_GAL_LAYER( In26_Cu ),  In26_Cu,
-    NETNAMES_GAL_LAYER( In27_Cu ),  In27_Cu,
-    NETNAMES_GAL_LAYER( In28_Cu ),  In28_Cu,
-    NETNAMES_GAL_LAYER( In29_Cu ),  In29_Cu,
-    NETNAMES_GAL_LAYER( In30_Cu ),  In30_Cu,
-
-    NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_BK_VISIBLE ),
-    NETNAMES_GAL_LAYER( B_Cu ), B_Cu, B_Mask, B_Adhes, B_Paste, B_SilkS,
-
-    ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ),
-    ITEM_GAL_LAYER( WORKSHEET )
+    LAYER_MOD_TEXT_FR,
+    LAYER_MOD_REFERENCES, LAYER_MOD_VALUES,
+
+    LAYER_RATSNEST, LAYER_ANCHOR,
+    LAYER_VIAS_HOLES, LAYER_PADS_HOLES,
+    LAYER_VIA_THROUGH, LAYER_VIA_BBLIND,
+    LAYER_VIA_MICROVIA, LAYER_PADS,
+
+    NETNAMES_LAYER_INDEX( LAYER_PAD_FR_NETNAMES ), LAYER_PAD_FR,
+    NETNAMES_LAYER_INDEX( F_Cu ), F_Cu, F_Mask, F_SilkS, F_Paste, F_Adhes,
+
+    NETNAMES_LAYER_INDEX( In1_Cu ),   In1_Cu,
+    NETNAMES_LAYER_INDEX( In2_Cu ),   In2_Cu,
+    NETNAMES_LAYER_INDEX( In3_Cu ),   In3_Cu,
+    NETNAMES_LAYER_INDEX( In4_Cu ),   In4_Cu,
+    NETNAMES_LAYER_INDEX( In5_Cu ),   In5_Cu,
+    NETNAMES_LAYER_INDEX( In6_Cu ),   In6_Cu,
+    NETNAMES_LAYER_INDEX( In7_Cu ),   In7_Cu,
+    NETNAMES_LAYER_INDEX( In8_Cu ),   In8_Cu,
+    NETNAMES_LAYER_INDEX( In9_Cu ),   In9_Cu,
+    NETNAMES_LAYER_INDEX( In10_Cu ),  In10_Cu,
+    NETNAMES_LAYER_INDEX( In11_Cu ),  In11_Cu,
+    NETNAMES_LAYER_INDEX( In12_Cu ),  In12_Cu,
+    NETNAMES_LAYER_INDEX( In13_Cu ),  In13_Cu,
+    NETNAMES_LAYER_INDEX( In14_Cu ),  In14_Cu,
+    NETNAMES_LAYER_INDEX( In15_Cu ),  In15_Cu,
+    NETNAMES_LAYER_INDEX( In16_Cu ),  In16_Cu,
+    NETNAMES_LAYER_INDEX( In17_Cu ),  In17_Cu,
+    NETNAMES_LAYER_INDEX( In18_Cu ),  In18_Cu,
+    NETNAMES_LAYER_INDEX( In19_Cu ),  In19_Cu,
+    NETNAMES_LAYER_INDEX( In20_Cu ),  In20_Cu,
+    NETNAMES_LAYER_INDEX( In21_Cu ),  In21_Cu,
+    NETNAMES_LAYER_INDEX( In22_Cu ),  In22_Cu,
+    NETNAMES_LAYER_INDEX( In23_Cu ),  In23_Cu,
+    NETNAMES_LAYER_INDEX( In24_Cu ),  In24_Cu,
+    NETNAMES_LAYER_INDEX( In25_Cu ),  In25_Cu,
+    NETNAMES_LAYER_INDEX( In26_Cu ),  In26_Cu,
+    NETNAMES_LAYER_INDEX( In27_Cu ),  In27_Cu,
+    NETNAMES_LAYER_INDEX( In28_Cu ),  In28_Cu,
+    NETNAMES_LAYER_INDEX( In29_Cu ),  In29_Cu,
+    NETNAMES_LAYER_INDEX( In30_Cu ),  In30_Cu,
+
+    NETNAMES_LAYER_INDEX( LAYER_PAD_BK_NETNAMES ), LAYER_PAD_BK,
+    NETNAMES_LAYER_INDEX( B_Cu ), B_Cu, B_Mask, B_Adhes, B_Paste, B_SilkS,
+
+    LAYER_MOD_TEXT_BK,
+    LAYER_WORKSHEET
 };
 
 
@@ -177,7 +177,7 @@ void PCB_DRAW_PANEL_GAL::UseColorScheme( const COLORS_DESIGN_SETTINGS* aSettings
 }
 
 
-void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( LAYER_ID aLayer )
+void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( PCB_LAYER_ID aLayer )
 {
     // Set display settings for high contrast mode
     KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
@@ -193,10 +193,10 @@ void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( LAYER_ID aLayer )
         // fixme do not like the idea of storing the list of layers here,
         // should be done in some other way I guess..
         LAYER_NUM layers[] = {
-                GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE ),
-                ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ),
-                ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE ),
-                ITEM_GAL_LAYER( GP_OVERLAY ), ITEM_GAL_LAYER( RATSNEST_VISIBLE )
+                GetNetnameLayer( aLayer ), LAYER_VIA_THROUGH,
+                LAYER_VIAS_HOLES, LAYER_PADS,
+                LAYER_PADS_HOLES, LAYER_PADS_NETNAMES,
+                LAYER_GP_OVERLAY, LAYER_RATSNEST
         };
 
         for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
@@ -205,15 +205,15 @@ void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( LAYER_ID aLayer )
         // Pads should be shown too
         if( aLayer == B_Cu )
         {
-            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
-            rSettings->SetActiveLayer( ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-            rSettings->SetActiveLayer( NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) );
+            rSettings->SetActiveLayer( LAYER_PAD_BK );
+            rSettings->SetActiveLayer( LAYER_MOD_BK );
+            rSettings->SetActiveLayer( LAYER_PAD_BK_NETNAMES );
         }
         else if( aLayer == F_Cu )
         {
-            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
-            rSettings->SetActiveLayer( ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
-            rSettings->SetActiveLayer( NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) );
+            rSettings->SetActiveLayer( LAYER_PAD_FR );
+            rSettings->SetActiveLayer( LAYER_MOD_FR );
+            rSettings->SetActiveLayer( LAYER_PAD_FR_NETNAMES );
         }
     }
 
@@ -221,7 +221,7 @@ void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( LAYER_ID aLayer )
 }
 
 
-void PCB_DRAW_PANEL_GAL::SetTopLayer( LAYER_ID aLayer )
+void PCB_DRAW_PANEL_GAL::SetTopLayer( PCB_LAYER_ID aLayer )
 {
     m_view->ClearTopLayers();
     setDefaultLayerOrder();
@@ -229,11 +229,11 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( LAYER_ID aLayer )
 
     // Layers that should always have on-top attribute enabled
     const LAYER_NUM layers[] = {
-            ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE ),
-            ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ),
-            ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE ),
-            ITEM_GAL_LAYER( GP_OVERLAY ), ITEM_GAL_LAYER( RATSNEST_VISIBLE ), Dwgs_User,
-            ITEM_GAL_LAYER( DRC_VISIBLE )
+            LAYER_VIA_THROUGH,
+            LAYER_VIAS_HOLES, LAYER_PADS,
+            LAYER_PADS_HOLES, LAYER_PADS_NETNAMES,
+            LAYER_GP_OVERLAY, LAYER_RATSNEST, Dwgs_User,
+            LAYER_DRC
     };
 
     for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
@@ -241,13 +241,13 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( LAYER_ID aLayer )
 
     // Extra layers that are brought to the top if a F.* or B.* is selected
     const LAYER_NUM frontLayers[] = {
-        F_Cu, F_Adhes, F_Paste, F_SilkS, F_Mask, F_CrtYd, F_Fab, ITEM_GAL_LAYER( PAD_FR_VISIBLE ),
-        NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), NETNAMES_GAL_LAYER( F_Cu ), -1
+        F_Cu, F_Adhes, F_Paste, F_SilkS, F_Mask, F_CrtYd, F_Fab, LAYER_PAD_FR,
+        LAYER_PAD_FR_NETNAMES, NETNAMES_LAYER_INDEX( F_Cu ), -1
     };
 
     const LAYER_NUM backLayers[] = {
-        B_Cu, B_Adhes, B_Paste, B_SilkS, B_Mask, B_CrtYd, B_Fab, ITEM_GAL_LAYER( PAD_BK_VISIBLE ),
-        NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), NETNAMES_GAL_LAYER( B_Cu ), -1
+        B_Cu, B_Adhes, B_Paste, B_SilkS, B_Mask, B_CrtYd, B_Fab, LAYER_PAD_BK,
+        LAYER_PAD_BK_NETNAMES, NETNAMES_LAYER_INDEX( B_Cu ), -1
     };
 
     const LAYER_NUM* extraLayers = NULL;
@@ -282,25 +282,25 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( LAYER_ID aLayer )
 void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard )
 {
     // Load layer & elements visibility settings
-    for( LAYER_NUM i = 0; i < LAYER_ID_COUNT; ++i )
+    for( LAYER_NUM i = 0; i < PCB_LAYER_ID_COUNT; ++i )
     {
-        m_view->SetLayerVisible( i, aBoard->IsLayerVisible( LAYER_ID( i ) ) );
+        m_view->SetLayerVisible( i, aBoard->IsLayerVisible( PCB_LAYER_ID( i ) ) );
 
         // Synchronize netname layers as well
         if( IsCopperLayer( i ) )
-            m_view->SetLayerVisible( GetNetnameLayer( i ), aBoard->IsLayerVisible( LAYER_ID( i ) ) );
+            m_view->SetLayerVisible( GetNetnameLayer( i ), aBoard->IsLayerVisible( PCB_LAYER_ID( i ) ) );
     }
 
-    for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i )
+    for( GAL_LAYER_ID i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; ++i )
     {
-        m_view->SetLayerVisible( ITEM_GAL_LAYER( i ), aBoard->IsElementVisible( i ) );
+        m_view->SetLayerVisible( i , aBoard->IsElementVisible( i ) );
     }
 
     // Enable some layers that are GAL specific
-    m_view->SetLayerVisible( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), true );
-    m_view->SetLayerVisible( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), true );
-    m_view->SetLayerVisible( ITEM_GAL_LAYER( WORKSHEET ), true );
-    m_view->SetLayerVisible( ITEM_GAL_LAYER( GP_OVERLAY ), true );
+    m_view->SetLayerVisible( LAYER_PADS_HOLES, true );
+    m_view->SetLayerVisible( LAYER_VIAS_HOLES, true );
+    m_view->SetLayerVisible( LAYER_WORKSHEET , true );
+    m_view->SetLayerVisible( LAYER_GP_OVERLAY , true );
 }
 
 
@@ -395,42 +395,42 @@ void PCB_DRAW_PANEL_GAL::setDefaultLayerDeps()
             m_view->SetLayerDisplayOnly( layer );
     }
 
-    m_view->SetLayerTarget( ITEM_GAL_LAYER( ANCHOR_VISIBLE ), KIGFX::TARGET_NONCACHED );
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( ANCHOR_VISIBLE ) );
+    m_view->SetLayerTarget( LAYER_ANCHOR, KIGFX::TARGET_NONCACHED );
+    m_view->SetLayerDisplayOnly( LAYER_ANCHOR );
 
     // Some more required layers settings
-    m_view->SetRequired( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE ) );
-    m_view->SetRequired( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) );
-    m_view->SetRequired( NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) );
+    m_view->SetRequired( LAYER_VIAS_HOLES, LAYER_VIA_THROUGH );
+    m_view->SetRequired( LAYER_PADS_HOLES, LAYER_PADS );
+    m_view->SetRequired( LAYER_PADS_NETNAMES, LAYER_PADS );
 
     // Front modules
-    m_view->SetRequired( ITEM_GAL_LAYER( PAD_FR_VISIBLE ), ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
-    m_view->SetRequired( ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ), ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
-    m_view->SetRequired( NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
-    m_view->SetRequired( F_Adhes, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
-    m_view->SetRequired( F_Paste, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
-    m_view->SetRequired( F_Mask, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
-    m_view->SetRequired( F_CrtYd, ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
-    m_view->SetRequired( F_Fab, ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
-    m_view->SetRequired( F_SilkS, ITEM_GAL_LAYER( MOD_FR_VISIBLE ) );
+    m_view->SetRequired( LAYER_PAD_FR, LAYER_MOD_FR );
+    m_view->SetRequired( LAYER_MOD_TEXT_FR, LAYER_MOD_FR );
+    m_view->SetRequired( LAYER_PAD_FR_NETNAMES, LAYER_PAD_FR );
+    m_view->SetRequired( F_Adhes, LAYER_PAD_FR );
+    m_view->SetRequired( F_Paste, LAYER_PAD_FR );
+    m_view->SetRequired( F_Mask, LAYER_PAD_FR );
+    m_view->SetRequired( F_CrtYd, LAYER_MOD_FR );
+    m_view->SetRequired( F_Fab, LAYER_MOD_FR );
+    m_view->SetRequired( F_SilkS, LAYER_MOD_FR );
 
     // Back modules
-    m_view->SetRequired( ITEM_GAL_LAYER( PAD_BK_VISIBLE ), ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-    m_view->SetRequired( ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ), ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-    m_view->SetRequired( NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
-    m_view->SetRequired( B_Adhes, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
-    m_view->SetRequired( B_Paste, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
-    m_view->SetRequired( B_Mask, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
-    m_view->SetRequired( B_CrtYd, ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-    m_view->SetRequired( B_Fab, ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-    m_view->SetRequired( B_SilkS, ITEM_GAL_LAYER( MOD_BK_VISIBLE ) );
-
-    m_view->SetLayerTarget( ITEM_GAL_LAYER( GP_OVERLAY ), KIGFX::TARGET_OVERLAY );
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( GP_OVERLAY ) );
-    m_view->SetLayerTarget( ITEM_GAL_LAYER( RATSNEST_VISIBLE ), KIGFX::TARGET_OVERLAY );
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( RATSNEST_VISIBLE ) );
-
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( WORKSHEET ) );
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( GRID_VISIBLE ) );
-    m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( DRC_VISIBLE ) );
+    m_view->SetRequired( LAYER_PAD_BK, LAYER_MOD_BK );
+    m_view->SetRequired( LAYER_MOD_TEXT_BK, LAYER_MOD_BK );
+    m_view->SetRequired( LAYER_PAD_BK_NETNAMES, LAYER_PAD_BK );
+    m_view->SetRequired( B_Adhes, LAYER_PAD_BK );
+    m_view->SetRequired( B_Paste, LAYER_PAD_BK );
+    m_view->SetRequired( B_Mask, LAYER_PAD_BK );
+    m_view->SetRequired( B_CrtYd, LAYER_MOD_BK );
+    m_view->SetRequired( B_Fab, LAYER_MOD_BK );
+    m_view->SetRequired( B_SilkS, LAYER_MOD_BK );
+
+    m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
+    m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
+    m_view->SetLayerTarget( LAYER_RATSNEST, KIGFX::TARGET_OVERLAY );
+    m_view->SetLayerDisplayOnly( LAYER_RATSNEST );
+
+    m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
+    m_view->SetLayerDisplayOnly( LAYER_GRID );
+    m_view->SetLayerDisplayOnly( LAYER_DRC );
 }
diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h
index dfd3a98..605b378 100644
--- a/pcbnew/pcb_draw_panel_gal.h
+++ b/pcbnew/pcb_draw_panel_gal.h
@@ -69,20 +69,20 @@ public:
     ///> @copydoc EDA_DRAW_PANEL_GAL::SetHighContrastLayer()
     virtual void SetHighContrastLayer( int aLayer ) override
     {
-        SetHighContrastLayer( static_cast< LAYER_ID >( aLayer ) );
+        SetHighContrastLayer( static_cast< PCB_LAYER_ID >( aLayer ) );
     }
 
     ///> SetHighContrastLayer(), with some extra smarts for PCB
-    void SetHighContrastLayer( LAYER_ID aLayer );
+    void SetHighContrastLayer( PCB_LAYER_ID aLayer );
 
     ///> @copydoc EDA_DRAW_PANEL_GAL::SetTopLayer()
     virtual void SetTopLayer( int aLayer ) override
     {
-        SetTopLayer( static_cast< LAYER_ID >( aLayer ) );
+        SetTopLayer( static_cast< PCB_LAYER_ID >( aLayer ) );
     }
 
     ///> SetTopLayer(), with some extra smarts for PCB
-    void SetTopLayer( LAYER_ID aLayer );
+    void SetTopLayer( PCB_LAYER_ID aLayer );
 
     /**
      * Function SyncLayersVisibility
diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp
index 3783d63..55c7ff6 100644
--- a/pcbnew/pcb_painter.cpp
+++ b/pcbnew/pcb_painter.cpp
@@ -54,7 +54,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS()
     m_sketchFpGfx = false;
 
     // By default everything should be displayed as filled
-    for( unsigned int i = 0; i < TOTAL_LAYER_COUNT; ++i )
+    for( unsigned int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
     {
         m_sketchMode[i] = false;
     }
@@ -65,41 +65,42 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS()
 
 void PCB_RENDER_SETTINGS::ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings )
 {
-    for( int i = 0; i < LAYER_ID_COUNT; i++ )
+    for( int i = 0; i < PCB_LAYER_ID_COUNT; i++ )
     {
         m_layerColors[i] = aSettings->GetLayerColor( i );
         m_layerColors[i].a = 0.8;   // slightly transparent
     }
 
-    for( int i = 0; i < END_PCB_VISIBLE_LIST; i++ )
-        m_layerColors[ITEM_GAL_LAYER( i )] = aSettings->GetItemColor( i );
+    for( int i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; i++ )
+        m_layerColors[i] = aSettings->GetItemColor( i );
 
-    m_layerColors[ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE )]            = m_layerColors[F_SilkS];
-    m_layerColors[ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE )]            = m_layerColors[B_SilkS];
+    m_layerColors[LAYER_MOD_TEXT_FR]            = m_layerColors[F_SilkS];
+    m_layerColors[LAYER_MOD_TEXT_BK]            = m_layerColors[B_SilkS];
 
     // Default colors for specific layers
-    m_layerColors[ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE )]             = COLOR4D( 0.5, 0.4, 0.0, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( PADS_HOLES_VISIBLE )]             = COLOR4D( 0.0, 0.5, 0.5, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE )]            = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE )]             = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( VIA_MICROVIA_VISIBLE )]           = COLOR4D( 0.4, 0.4, 0.8, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( PADS_VISIBLE )]                   = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
-    m_layerColors[NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE )]      = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
-    m_layerColors[NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE )]    = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
-    m_layerColors[NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE )]    = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
-    m_layerColors[ITEM_GAL_LAYER( ANCHOR_VISIBLE )]                 = COLOR4D( 0.3, 0.3, 1.0, 0.9 );
-    m_layerColors[ITEM_GAL_LAYER( WORKSHEET )]                      = COLOR4D( 0.5, 0.0, 0.0, 0.8 );
-    m_layerColors[ITEM_GAL_LAYER( DRC_VISIBLE )]                    = COLOR4D( 1.0, 0.0, 0.0, 0.8 );
+    m_layerColors[LAYER_VIAS_HOLES]             = COLOR4D( 0.5, 0.4, 0.0, 0.8 );
+    m_layerColors[LAYER_PADS_HOLES]             = COLOR4D( 0.0, 0.5, 0.5, 0.8 );
+    m_layerColors[LAYER_VIA_THROUGH]            = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
+    m_layerColors[LAYER_VIA_BBLIND]             = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
+    m_layerColors[LAYER_VIA_MICROVIA]           = COLOR4D( 0.4, 0.4, 0.8, 0.8 );
+    m_layerColors[LAYER_PADS]                   = COLOR4D( 0.6, 0.6, 0.6, 0.8 );
+    m_layerColors[LAYER_PADS_NETNAMES]          = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
+    m_layerColors[LAYER_PAD_FR_NETNAMES]        = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
+    m_layerColors[LAYER_PAD_BK_NETNAMES]        = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
+    m_layerColors[LAYER_ANCHOR]                 = COLOR4D( 0.3, 0.3, 1.0, 0.9 );
+    m_layerColors[LAYER_RATSNEST]               = COLOR4D( 0.4, 0.4, 0.4, 0.8 );
+    m_layerColors[LAYER_WORKSHEET]              = COLOR4D( 0.5, 0.0, 0.0, 0.8 );
+    m_layerColors[LAYER_DRC]                    = COLOR4D( 1.0, 0.0, 0.0, 0.8 );
 
     // Make ratsnest lines slightly transparent
-    m_layerColors[ITEM_GAL_LAYER( RATSNEST_VISIBLE )].a = 0.8;
+    m_layerColors[LAYER_RATSNEST].a = 0.8;
 
     // Netnames for copper layers
     for( LSEQ cu = LSET::AllCuMask().CuStack();  cu;  ++cu )
     {
         const COLOR4D lightLabel( 0.8, 0.8, 0.8, 0.7 );
         const COLOR4D darkLabel = lightLabel.Inverted();
-        LAYER_ID layer = *cu;
+        PCB_LAYER_ID layer = *cu;
 
         if( m_layerColors[layer].GetBrightness() > 0.5 )
             m_layerColors[GetNetnameLayer( layer )] = darkLabel;
@@ -122,11 +123,11 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS* aOptions )
     m_sketchFpGfx       = !aOptions->m_DisplayModEdgeFill;
 
     // Whether to draw tracks, vias & pads filled or as outlines
-    m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )]         = !aOptions->m_DisplayPadFill;
-    m_sketchMode[ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE )]  = !aOptions->m_DisplayViaFill;
-    m_sketchMode[ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE )]   = !aOptions->m_DisplayViaFill;
-    m_sketchMode[ITEM_GAL_LAYER( VIA_MICROVIA_VISIBLE )] = !aOptions->m_DisplayViaFill;
-    m_sketchMode[ITEM_GAL_LAYER( TRACKS_VISIBLE )]       = !aOptions->m_DisplayPcbTrackFill;
+    m_sketchMode[LAYER_PADS]         = !aOptions->m_DisplayPadFill;
+    m_sketchMode[LAYER_VIA_THROUGH]  = !aOptions->m_DisplayViaFill;
+    m_sketchMode[LAYER_VIA_BBLIND]   = !aOptions->m_DisplayViaFill;
+    m_sketchMode[LAYER_VIA_MICROVIA] = !aOptions->m_DisplayViaFill;
+    m_sketchMode[LAYER_TRACKS]       = !aOptions->m_DisplayPcbTrackFill;
 
     // Net names display settings
     switch( aOptions->m_DisplayNetNamesMode )
@@ -355,7 +356,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
         m_gal->SetStrokeColor( color );
         m_gal->SetIsStroke( true );
 
-        if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( TRACKS_VISIBLE )] )
+        if( m_pcbSettings.m_sketchMode[LAYER_TRACKS] )
         {
             // Outline mode
             m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
@@ -396,7 +397,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
         return;
 
     // Choose drawing settings depending on if we are drawing via's pad or hole
-    if( aLayer == ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ) )
+    if( aLayer == LAYER_VIAS_HOLES )
         radius = aVia->GetDrillValue() / 2.0;
     else
         radius = aVia->GetWidth() / 2.0;
@@ -407,15 +408,15 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
     switch( aVia->GetViaType() )
     {
     case VIA_THROUGH:
-        sketchMode = m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE )];
+        sketchMode = m_pcbSettings.m_sketchMode[LAYER_VIA_THROUGH];
         break;
 
     case VIA_BLIND_BURIED:
-        sketchMode = m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE )];
+        sketchMode = m_pcbSettings.m_sketchMode[LAYER_VIA_BBLIND];
         break;
 
     case VIA_MICROVIA:
-        sketchMode = m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( VIA_MICROVIA_VISIBLE )];
+        sketchMode = m_pcbSettings.m_sketchMode[LAYER_VIA_MICROVIA];
         break;
 
     default:
@@ -426,10 +427,10 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
     if( aVia->GetViaType() == VIA_BLIND_BURIED )
     {
         // Buried vias are drawn in a special way to indicate the top and bottom layers
-        LAYER_ID layerTop, layerBottom;
+        PCB_LAYER_ID layerTop, layerBottom;
         aVia->LayerPair( &layerTop, &layerBottom );
 
-        if( aLayer == ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ) )
+        if( aLayer == LAYER_VIAS_HOLES )
         {                                                               // TODO outline mode
             m_gal->SetIsFill( true );
             m_gal->SetIsStroke( false );
@@ -453,7 +454,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
             {
                 m_gal->DrawArc( center, radius, M_PI, 3.0 * M_PI / 2.0 );
             }
-            else if( aLayer == ITEM_GAL_LAYER( VIA_BBLIND_VISIBLE ) )
+            else if( aLayer == LAYER_VIA_BBLIND )
             {
                 m_gal->DrawArc( center, radius, M_PI / 2.0, M_PI );
                 m_gal->DrawArc( center, radius, 3.0 * M_PI / 2.0, 2.0 * M_PI );
@@ -485,7 +486,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
     constexpr int clearanceFlags = PCB_RENDER_SETTINGS::CL_EXISTING | PCB_RENDER_SETTINGS::CL_VIAS;
 
     if( ( m_pcbSettings.m_clearance & clearanceFlags ) == clearanceFlags
-            && aLayer != ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ) )
+            && aLayer != LAYER_VIAS_HOLES )
     {
         m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
         m_gal->SetIsFill( false );
@@ -601,7 +602,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
     const COLOR4D& color = m_pcbSettings.GetColor( aPad, aLayer );
     VECTOR2D size;
 
-    if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] )
+    if( m_pcbSettings.m_sketchMode[LAYER_PADS] )
     {
         // Outline mode
         m_gal->SetIsFill( false );
@@ -622,7 +623,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
     m_gal->Rotate( -aPad->GetOrientationRadians() );
 
     // Choose drawing settings depending on if we are drawing a pad itself or a hole
-    if( aLayer == ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ) )
+    if( aLayer == LAYER_PADS_HOLES )
     {
         // Drawing hole: has same shape as PAD_CIRCLE or PAD_OVAL
         size  = VECTOR2D( aPad->GetDrillSize() ) / 2.0;
@@ -664,7 +665,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
             m = ( size.y - size.x );
             n = size.x;
 
-            if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] )
+            if( m_pcbSettings.m_sketchMode[LAYER_PADS] )
             {
                 // Outline mode
                 m_gal->DrawArc( VECTOR2D( 0, -m ), n, -M_PI, 0 );
@@ -685,7 +686,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
             m = ( size.x - size.y );
             n = size.y;
 
-            if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] )
+            if( m_pcbSettings.m_sketchMode[LAYER_PADS] )
             {
                 // Outline mode
                 m_gal->DrawArc( VECTOR2D( -m, 0 ), n, M_PI / 2, 3 * M_PI / 2 );
@@ -716,7 +717,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
         TransformRoundRectToPolygon( polySet, wxPoint( 0, 0 ), prsize,
                 0.0, corner_radius, segmentToCircleCount );
 
-        if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] )
+        if( m_pcbSettings.m_sketchMode[LAYER_PADS] )
         {
             if( polySet.OutlineCount() > 0 )
                 m_gal->DrawPolyline( polySet.Outline( 0 ) );
@@ -744,7 +745,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
         polySet.Append( VECTOR2I( corners[2] ) );
         polySet.Append( VECTOR2I( corners[3] ) );
 
-        if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] )
+        if( m_pcbSettings.m_sketchMode[LAYER_PADS] )
             m_gal->DrawPolyline( polySet.COutline( 0 ) );
         else
             m_gal->DrawPolygon( polySet );
@@ -764,9 +765,9 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
     constexpr int clearanceFlags = /*PCB_RENDER_SETTINGS::CL_EXISTING |*/ PCB_RENDER_SETTINGS::CL_PADS;
 
     if( ( m_pcbSettings.m_clearance & clearanceFlags ) == clearanceFlags
-            && ( aLayer == ITEM_GAL_LAYER( PAD_FR_VISIBLE )
-                || aLayer == ITEM_GAL_LAYER( PAD_BK_VISIBLE )
-                || aLayer == ITEM_GAL_LAYER( PADS_VISIBLE ) ) )
+            && ( aLayer == LAYER_PAD_FR
+                || aLayer == LAYER_PAD_BK
+                || aLayer == LAYER_PADS ) )
     {
         SHAPE_POLY_SET polySet;
         constexpr int SEGCOUNT = 64;
@@ -943,9 +944,9 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
 
 void PCB_PAINTER::draw( const MODULE* aModule, int aLayer )
 {
-    if( aLayer == ITEM_GAL_LAYER( ANCHOR_VISIBLE ) )
+    if( aLayer == LAYER_ANCHOR )
     {
-        const COLOR4D color = m_pcbSettings.GetColor( aModule, ITEM_GAL_LAYER( ANCHOR_VISIBLE ) );
+        const COLOR4D color = m_pcbSettings.GetColor( aModule, LAYER_ANCHOR );
 
         // Draw anchor
         m_gal->SetStrokeColor( color );
diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h
index 2363500..ef5d5b8 100644
--- a/pcbnew/pcb_painter.h
+++ b/pcbnew/pcb_painter.h
@@ -128,7 +128,7 @@ public:
 
 protected:
     ///> Flag determining if items on a given layer should be drawn as an outline or a filled item
-    bool    m_sketchMode[TOTAL_LAYER_COUNT];
+    bool    m_sketchMode[GAL_LAYER_ID_END];
 
     ///> Flag determining if board graphic items should be outlined or stroked
     bool    m_sketchBoardGfx;
diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp
index d8e5e1c..40fc5da 100644
--- a/pcbnew/pcb_parser.cpp
+++ b/pcbnew/pcb_parser.cpp
@@ -63,12 +63,12 @@ void PCB_PARSER::init()
     // Add untranslated default (i.e. english) layernames.
     // Some may be overridden later if parsing a board rather than a footprint.
     // The english name will survive if parsing only a footprint.
-    for( LAYER_NUM layer = 0;  layer < LAYER_ID_COUNT;  ++layer )
+    for( LAYER_NUM layer = 0;  layer < PCB_LAYER_ID_COUNT;  ++layer )
     {
-        std::string untranslated = TO_UTF8( wxString( LSET::Name( LAYER_ID( layer ) ) ) );
+        std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
 
-        m_layerIndices[ untranslated ] = LAYER_ID( layer );
-        m_layerMasks[ untranslated ]   = LSET( LAYER_ID( layer ) );
+        m_layerIndices[ untranslated ] = PCB_LAYER_ID( layer );
+        m_layerMasks[ untranslated ]   = LSET( PCB_LAYER_ID( layer ) );
     }
 
     m_layerMasks[ "*.Cu" ]      = LSET::AllCuMask();
@@ -90,7 +90,7 @@ void PCB_PARSER::init()
     {
         std::string key = StrPrintf( "Inner%d.Cu", i );
 
-        m_layerMasks[ key ] = LSET( LAYER_ID( In15_Cu - i ) );
+        m_layerMasks[ key ] = LSET( PCB_LAYER_ID( In15_Cu - i ) );
     }
 
 #if defined(DEBUG) && 0
@@ -856,12 +856,12 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
             if( it->m_visible )
                 visibleLayers.set( it->m_number );
 
-            m_board->SetLayerDescr( LAYER_ID( it->m_number ), *it );
+            m_board->SetLayerDescr( PCB_LAYER_ID( it->m_number ), *it );
 
             UTF8 name = it->m_name;
 
-            m_layerIndices[ name ] = LAYER_ID( it->m_number );
-            m_layerMasks[   name ] = LSET( LAYER_ID( it->m_number ) );
+            m_layerIndices[ name ] = PCB_LAYER_ID( it->m_number );
+            m_layerMasks[   name ] = LSET( PCB_LAYER_ID( it->m_number ) );
         }
 
         copperLayerCount = cu.size();
@@ -955,14 +955,14 @@ T PCB_PARSER::lookUpLayer( const M& aMap ) throw( PARSE_ERROR, IO_ERROR )
 }
 
 
-LAYER_ID PCB_PARSER::parseBoardItemLayer() throw( PARSE_ERROR, IO_ERROR )
+PCB_LAYER_ID PCB_PARSER::parseBoardItemLayer() throw( PARSE_ERROR, IO_ERROR )
 {
     wxCHECK_MSG( CurTok() == T_layer, UNDEFINED_LAYER,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layer." ) );
 
     NextTok();
 
-    LAYER_ID layerIndex = lookUpLayer<LAYER_ID>( m_layerIndices );
+    PCB_LAYER_ID layerIndex = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
 
     // Handle closing ) in object parser.
 
@@ -1793,7 +1793,7 @@ MODULE* PCB_PARSER::parseMODULE_unchecked( wxArrayString* aInitialComments )
             // Footprints can be only on the front side or the back side.
             // but because we can find some stupid layer in file, ensure a
             // acceptable layer is set for the footprint
-            LAYER_ID layer = parseBoardItemLayer();
+            PCB_LAYER_ID layer = parseBoardItemLayer();
             module->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
         }
             NeedRIGHT();
@@ -2600,11 +2600,11 @@ VIA* PCB_PARSER::parseVIA() throw( IO_ERROR, PARSE_ERROR )
 
         case T_layers:
             {
-                LAYER_ID layer1, layer2;
+                PCB_LAYER_ID layer1, layer2;
                 NextTok();
-                layer1 = lookUpLayer<LAYER_ID>( m_layerIndices );
+                layer1 = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
                 NextTok();
-                layer2 = lookUpLayer<LAYER_ID>( m_layerIndices );
+                layer2 = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
                 via->SetLayerPair( layer1, layer2 );
                 NeedRIGHT();
             }
diff --git a/pcbnew/pcb_parser.h b/pcbnew/pcb_parser.h
index ceb055d..068669d 100644
--- a/pcbnew/pcb_parser.h
+++ b/pcbnew/pcb_parser.h
@@ -32,7 +32,7 @@
 
 #include <pcb_lexer.h>
 #include <hashtables.h>
-#include <layers_id_colors_and_visibility.h>    // LAYER_ID
+#include <layers_id_colors_and_visibility.h>    // PCB_LAYER_ID
 #include <common.h>                             // KiROUND
 #include <convert_to_biu.h>                     // IU_PER_MM
 #include <3d_cache/3d_info.h>
@@ -65,7 +65,7 @@ struct LAYER;
  */
 class PCB_PARSER : public PCB_LEXER
 {
-    typedef boost::unordered_map< std::string, LAYER_ID >   LAYER_ID_MAP;
+    typedef boost::unordered_map< std::string, PCB_LAYER_ID >   LAYER_ID_MAP;
     typedef boost::unordered_map< std::string, LSET >       LSET_MAP;
 
     BOARD*              m_board;
@@ -170,7 +170,7 @@ class PCB_PARSER : public PCB_LEXER
      * @throw PARSE_ERROR if the layer syntax is incorrect.
      * @return The index the parsed #BOARD_ITEM layer.
      */
-    LAYER_ID parseBoardItemLayer() throw( IO_ERROR, PARSE_ERROR );
+    PCB_LAYER_ID parseBoardItemLayer() throw( IO_ERROR, PARSE_ERROR );
 
     /**
      * Function parseBoardItemLayersAsMask
diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp
index 4927fdc..6759e66 100644
--- a/pcbnew/pcbframe.cpp
+++ b/pcbnew/pcbframe.cpp
@@ -736,21 +736,13 @@ void PCB_EDIT_FRAME::forceColorsToLegacy()
 {
     COLORS_DESIGN_SETTINGS* cds = GetBoard()->GetColorsSettings();
 
-    for( int i = 0; i < LAYER_ID_COUNT; i++ )
+    for( unsigned i = 0; i < DIM( cds->m_LayersColors ); i++ )
     {
         COLOR4D c = cds->GetLayerColor( i );
         c.SetToNearestLegacyColor();
         c.a = 0.8;
         cds->SetLayerColor( i, c );
     }
-
-    for( unsigned int i = 0; i < DIM( cds->m_ItemsColors ); i++ )
-    {
-        COLOR4D c = cds->GetItemColor( i );
-        c.SetToNearestLegacyColor();
-        c.a = 0.8;
-        cds->SetItemColor( i, c );
-    }
 }
 
 
@@ -841,26 +833,26 @@ void PCB_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
 
 bool PCB_EDIT_FRAME::IsGridVisible() const
 {
-    return IsElementVisible( GRID_VISIBLE );
+    return IsElementVisible( LAYER_GRID );
 }
 
 
 void PCB_EDIT_FRAME::SetGridVisibility(bool aVisible)
 {
-    SetElementVisibility( GRID_VISIBLE, aVisible );
+    SetElementVisibility( LAYER_GRID, aVisible );
 }
 
 
 COLOR4D PCB_EDIT_FRAME::GetGridColor() const
 {
-    return GetBoard()->GetVisibleElementColor( GRID_VISIBLE );
+    return GetBoard()->GetVisibleElementColor( LAYER_GRID );
 }
 
 
 void PCB_EDIT_FRAME::SetGridColor( COLOR4D aColor )
 {
 
-    GetBoard()->SetVisibleElementColor( GRID_VISIBLE, aColor );
+    GetBoard()->SetVisibleElementColor( LAYER_GRID, aColor );
 
     if( IsGalCanvasActive() )
     {
@@ -885,7 +877,7 @@ void PCB_EDIT_FRAME::SetCursorShape( int aCursorShape )
 bool PCB_EDIT_FRAME::IsMicroViaAcceptable()
 {
     int copperlayercnt = GetBoard()->GetCopperLayerCount( );
-    LAYER_ID currLayer = GetActiveLayer();
+    PCB_LAYER_ID currLayer = GetActiveLayer();
 
     if( !GetDesignSettings().m_MicroViasAllowed )
         return false;   // Obvious..
@@ -903,7 +895,7 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable()
 }
 
 
-void PCB_EDIT_FRAME::SetActiveLayer( LAYER_ID aLayer )
+void PCB_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
 {
     PCB_BASE_FRAME::SetActiveLayer( aLayer );
 
@@ -948,15 +940,15 @@ void PCB_EDIT_FRAME::unitsChangeRefresh()
 }
 
 
-bool PCB_EDIT_FRAME::IsElementVisible( int aElement ) const
+bool PCB_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
 {
     return GetBoard()->IsElementVisible( aElement );
 }
 
 
-void PCB_EDIT_FRAME::SetElementVisibility( int aElement, bool aNewState )
+void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
 {
-    GetGalCanvas()->GetView()->SetLayerVisible( ITEM_GAL_LAYER( aElement ), aNewState );
+    GetGalCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
     GetBoard()->SetElementVisibility( aElement, aNewState );
     m_Layers->SetRenderState( aElement, aNewState );
 }
@@ -966,7 +958,7 @@ void PCB_EDIT_FRAME::SetVisibleAlls()
 {
     GetBoard()->SetVisibleAlls();
 
-    for( int ii = 0; ii < PCB_VISIBLE( END_PCB_VISIBLE_LIST ); ii++ )
+    for( GAL_LAYER_ID ii = GAL_LAYER_ID_START; ii < GAL_LAYER_ID_BITMASK_END; ++ii )
         m_Layers->SetRenderState( ii, true );
 }
 
diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp
index 65d4a2d..597c6f8 100644
--- a/pcbnew/pcbnew.cpp
+++ b/pcbnew/pcbnew.cpp
@@ -64,18 +64,18 @@ extern bool IsWxPythonLoaded();
 // Colors for layers and items
 COLORS_DESIGN_SETTINGS g_ColorsSettings;
 
-bool        g_Drc_On = true;
-bool        g_AutoDeleteOldTrack = true;
-bool        g_Raccord_45_Auto = true;
-bool        g_Alternate_Track_Posture = false;
-bool        g_Track_45_Only_Allowed = true;  // True to allow horiz, vert. and 45deg only tracks
-bool        g_Segments_45_Only;              // True to allow horiz, vert. and 45deg only graphic segments
-bool        g_TwoSegmentTrackBuild = true;
-
-LAYER_ID    g_Route_Layer_TOP;
-LAYER_ID    g_Route_Layer_BOTTOM;
-int         g_MagneticPadOption   = CAPTURE_CURSOR_IN_TRACK_TOOL;
-int         g_MagneticTrackOption = CAPTURE_CURSOR_IN_TRACK_TOOL;
+bool         g_Drc_On = true;
+bool         g_AutoDeleteOldTrack = true;
+bool         g_Raccord_45_Auto = true;
+bool         g_Alternate_Track_Posture = false;
+bool         g_Track_45_Only_Allowed = true;  // True to allow horiz, vert. and 45deg only tracks
+bool         g_Segments_45_Only;              // True to allow horiz, vert. and 45deg only graphic segments
+bool         g_TwoSegmentTrackBuild = true;
+
+PCB_LAYER_ID g_Route_Layer_TOP;
+PCB_LAYER_ID g_Route_Layer_BOTTOM;
+int          g_MagneticPadOption   = CAPTURE_CURSOR_IN_TRACK_TOOL;
+int          g_MagneticTrackOption = CAPTURE_CURSOR_IN_TRACK_TOOL;
 
 wxPoint     g_Offset_Module;     // module offset used when moving a footprint
 
diff --git a/pcbnew/pcbnew.h b/pcbnew/pcbnew.h
index 4f25fd8..3bc65c7 100644
--- a/pcbnew/pcbnew.h
+++ b/pcbnew/pcbnew.h
@@ -85,8 +85,8 @@ extern bool     g_Alternate_Track_Posture;
 extern bool     g_Segments_45_Only;
 
 // Layer pair for auto routing and switch layers by hotkey
-extern LAYER_ID g_Route_Layer_TOP;
-extern LAYER_ID g_Route_Layer_BOTTOM;
+extern PCB_LAYER_ID g_Route_Layer_TOP;
+extern PCB_LAYER_ID g_Route_Layer_BOTTOM;
 
 extern bool     g_TwoSegmentTrackBuild;
 
diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp
index da954bc..ee9dda9 100644
--- a/pcbnew/pcbnew_config.cpp
+++ b/pcbnew/pcbnew_config.cpp
@@ -94,7 +94,7 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
     case ID_PCB_LAYERS_SETUP:
         if( InvokeLayerSetup( this, GetBoard() ) )
         {
-            LAYER_ID cur_layer = GetActiveLayer();
+            PCB_LAYER_ID cur_layer = GetActiveLayer();
 
             // If after showing the dialog the user has removed the active layer,
             // then select a new active layer (front copper layer).
@@ -362,45 +362,45 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings()
                                                        &displ_opts->m_DisplayZonesMode, 0, 0, 2 ) );
 
         // layer colors:
-        wxASSERT( DIM( cds.m_LayersColors ) == LAYER_ID_COUNT );
-        for( int i = 0;  i<LAYER_ID_COUNT;  ++i )
+        wxASSERT( DIM( cds.m_LayersColors ) >= PCB_LAYER_ID_COUNT );
+        for( int i = 0;  i<PCB_LAYER_ID_COUNT;  ++i )
         {
             wxString vn = wxString::Format(
                             wxT( "ColorPCBLayer_%s" ),
-                            LSET::Name( LAYER_ID( i ) ) );
+                            LSET::Name( PCB_LAYER_ID( i ) ) );
 
             m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, vn, LOC_COLOR( i ), cds.m_LayersColors[i] ) );
         }
 
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtFrontEx" ),
-                                                            ITEM_COLOR( MOD_TEXT_FR_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_MOD_TEXT_FR ),
                                                             LIGHTGRAY ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtBackEx" ),
-                                                            ITEM_COLOR( MOD_TEXT_BK_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_MOD_TEXT_BK ),
                                                             BLUE ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtInvisEx" ),
-                                                            ITEM_COLOR( MOD_TEXT_INVISIBLE ),
+                                                            ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ),
                                                             DARKGRAY ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorAnchorEx" ),
-                                                            ITEM_COLOR( ANCHOR_VISIBLE ), BLUE ) );
+                                                            ITEM_COLOR( LAYER_ANCHOR ), BLUE ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPadBackEx" ),
-                                                            ITEM_COLOR( PAD_BK_VISIBLE ), GREEN ) );
+                                                            ITEM_COLOR( LAYER_PAD_BK ), GREEN ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPadFrontEx" ),
-                                                            ITEM_COLOR( PAD_FR_VISIBLE ), RED ) );
+                                                            ITEM_COLOR( LAYER_PAD_FR ), RED ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaThruEx" ),
-                                                            ITEM_COLOR( VIA_THROUGH_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_VIA_THROUGH ),
                                                             LIGHTGRAY ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaBBlindEx" ),
-                                                            ITEM_COLOR( VIA_BBLIND_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_VIA_BBLIND ),
                                                             BROWN ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaMicroEx" ),
-                                                            ITEM_COLOR( VIA_MICROVIA_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_VIA_MICROVIA ),
                                                             CYAN ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorNonPlatedEx" ),
-                                                            ITEM_COLOR( NON_PLATED_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_NON_PLATED ),
                                                             YELLOW ) );
         m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorRatsEx" ),
-                                                            ITEM_COLOR( RATSNEST_VISIBLE ),
+                                                            ITEM_COLOR( LAYER_RATSNEST ),
                                                             WHITE ) );
 
         // Miscellaneous:
diff --git a/pcbnew/pcbnew_config.h b/pcbnew/pcbnew_config.h
index f4c153e..e2f9ac3 100644
--- a/pcbnew/pcbnew_config.h
+++ b/pcbnew/pcbnew_config.h
@@ -11,7 +11,7 @@
 
 /* Useful macro : */
 #define LOC_COLOR(layer)            &g_ColorsSettings.m_LayersColors[layer]
-#define ITEM_COLOR(item_visible)    &g_ColorsSettings.m_ItemsColors[item_visible]
+#define ITEM_COLOR(item_visible)    &g_ColorsSettings.m_LayersColors[item_visible]
 
 
 #endif    // _PCBNEW_CONFIG_H_
diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h
index d204833..e923d40 100644
--- a/pcbnew/pcbplot.h
+++ b/pcbnew/pcbplot.h
@@ -180,7 +180,7 @@ PLOTTER* StartPlotBoard( BOARD* aBoard,
  * @param aLayer = the layer id to plot
  * @param aPlotOpt = the plot options (files, sketch). Has meaning for some formats only
  */
-void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_ID aLayer,
+void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
                         const PCB_PLOT_PARAMS& aPlotOpt );
 
 /**
diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index be39fc2..57137c1 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -150,7 +150,7 @@ void PlotSilkScreen( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
     }
 }
 
-void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, LAYER_ID aLayer,
+void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
                         const PCB_PLOT_PARAMS& aPlotOpt )
 {
     PCB_PLOT_PARAMS plotOpt = aPlotOpt;
@@ -411,10 +411,10 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter,
             COLOR4D color = COLOR4D::BLACK;
 
             if( pad->GetLayerSet()[B_Cu] )
-               color = aBoard->GetVisibleElementColor( PAD_BK_VISIBLE );
+               color = aBoard->GetVisibleElementColor( LAYER_PAD_BK );
 
             if( pad->GetLayerSet()[F_Cu] )
-                color = color.LegacyMix( aBoard->GetVisibleElementColor( PAD_FR_VISIBLE ) );
+                color = color.LegacyMix( aBoard->GetVisibleElementColor( LAYER_PAD_FR ) );
 
             // Temporary set the pad size to the required plot size:
             wxSize tmppadsize = pad->GetSize();
@@ -507,7 +507,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter,
 
         gbr_metadata.SetNetName( Via->GetNetname() );
 
-        COLOR4D color = aBoard->GetVisibleElementColor( VIAS_VISIBLE + Via->GetViaType() );
+        COLOR4D color = aBoard->GetVisibleElementColor( LAYER_VIAS + Via->GetViaType() );
         // Set plot color (change WHITE to LIGHTGRAY because
         // the white items are not seen on a white paper or screen
         aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY);
@@ -570,7 +570,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter,
 
 
 // Seems like we want to plot from back to front?
-static const LAYER_ID plot_seq[] = {
+static const PCB_LAYER_ID plot_seq[] = {
 
     B_Adhes,        // 32
     F_Adhes,
@@ -641,7 +641,7 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter,
 
     for( LSEQ seq = aLayerMask.Seq( plot_seq, DIM( plot_seq ) );  seq;  ++seq )
     {
-        LAYER_ID layer = *seq;
+        PCB_LAYER_ID layer = *seq;
 
         outlines.RemoveAllContours();
         aBoard->ConvertBrdLayerToPolygonalContours( layer, outlines );
@@ -733,7 +733,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter,
                           LSET aLayerMask, const PCB_PLOT_PARAMS& aPlotOpt,
                           int aMinThickness )
 {
-    LAYER_ID    layer = aLayerMask[B_Mask] ? B_Mask : F_Mask;
+    PCB_LAYER_ID    layer = aLayerMask[B_Mask] ? B_Mask : F_Mask;
     int         inflate = aMinThickness/2;
 
     BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp
index 704f0c3..6e0b7f0 100644
--- a/pcbnew/plot_brditems_plotter.cpp
+++ b/pcbnew/plot_brditems_plotter.cpp
@@ -199,7 +199,7 @@ bool BRDITEMS_PLOTTER::PlotAllTextsModule( MODULE* aModule )
     TEXTE_MODULE* textModule = &aModule->Reference();
     LAYER_NUM     textLayer = textModule->GetLayer();
 
-    if( textLayer >= LAYER_ID_COUNT )       // how will this ever be true?
+    if( textLayer >= PCB_LAYER_ID_COUNT )       // how will this ever be true?
         return false;
 
     if( !m_layerMask[textLayer] )
@@ -211,7 +211,7 @@ bool BRDITEMS_PLOTTER::PlotAllTextsModule( MODULE* aModule )
     textModule = &aModule->Value();
     textLayer = textModule->GetLayer();
 
-    if( textLayer > LAYER_ID_COUNT )        // how will this ever be true?
+    if( textLayer > PCB_LAYER_ID_COUNT )        // how will this ever be true?
         return false;
 
     if( !m_layerMask[textLayer] )
@@ -249,7 +249,7 @@ bool BRDITEMS_PLOTTER::PlotAllTextsModule( MODULE* aModule )
 
         textLayer = textModule->GetLayer();
 
-        if( textLayer >= LAYER_ID_COUNT )
+        if( textLayer >= PCB_LAYER_ID_COUNT )
             return false;
 
         if( !m_layerMask[textLayer] )
diff --git a/pcbnew/print_board_functions.cpp b/pcbnew/print_board_functions.cpp
index 016688c..ce8a611 100644
--- a/pcbnew/print_board_functions.cpp
+++ b/pcbnew/print_board_functions.cpp
@@ -68,8 +68,8 @@ void FOOTPRINT_EDIT_FRAME::PrintPage( wxDC* aDC,
     displ_opts->m_DisplayPadFill = true;
     displ_opts->m_DisplayViaFill = true;
     displ_opts->m_DisplayPadNum = false;
-    bool nctmp = GetBoard()->IsElementVisible(NO_CONNECTS_VISIBLE);
-    GetBoard()->SetElementVisibility(NO_CONNECTS_VISIBLE, false);
+    bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
+    GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
     displ_opts->m_DisplayPadIsol    = false;
     displ_opts->m_DisplayModEdgeFill    = FILLED;
     displ_opts->m_DisplayModTextFill    = FILLED;
@@ -101,7 +101,7 @@ void FOOTPRINT_EDIT_FRAME::PrintPage( wxDC* aDC,
     m_canvas->SetPrintMirrored( false );
 
     *displ_opts = save_opt;
-    GetBoard()->SetElementVisibility( NO_CONNECTS_VISIBLE, nctmp );
+    GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, nctmp );
 }
 
 
@@ -132,7 +132,7 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
 
     save_opt = *displ_opts;
 
-    LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
+    PCB_LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
 
     displ_opts->m_ContrastModeDisplay = false;
     displ_opts->m_DisplayPadFill = true;
@@ -151,11 +151,11 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
             // Calculate the active layer number to print from its mask layer:
             GetScreen()->m_Active_Layer = B_Cu;
 
-            for( LAYER_NUM id = LAYER_ID_COUNT-1; id >= 0; --id )
+            for( LAYER_NUM id = PCB_LAYER_ID_COUNT-1; id >= 0; --id )
             {
                 if( aPrintMask[id] )
                 {
-                    GetScreen()->m_Active_Layer = LAYER_ID( id );
+                    GetScreen()->m_Active_Layer = PCB_LAYER_ID( id );
                     break;
                 }
             }
@@ -175,13 +175,13 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
 
     displ_opts->m_DisplayPadNum = false;
 
-    bool nctmp = GetBoard()->IsElementVisible( NO_CONNECTS_VISIBLE );
+    bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
 
-    GetBoard()->SetElementVisibility( NO_CONNECTS_VISIBLE, false );
+    GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
 
-    bool anchorsTmp = GetBoard()->IsElementVisible( ANCHOR_VISIBLE );
+    bool anchorsTmp = GetBoard()->IsElementVisible( LAYER_ANCHOR );
 
-    GetBoard()->SetElementVisibility( ANCHOR_VISIBLE, false );
+    GetBoard()->SetElementVisibility( LAYER_ANCHOR, false );
 
     displ_opts->m_DisplayPadIsol = false;
     displ_opts->m_DisplayModEdgeFill = FILLED;
@@ -223,7 +223,7 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
             int         radius = track->GetWidth() / 2;
             const VIA*  via = static_cast<const VIA*>( track );
 
-            COLOR4D color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + via->GetViaType() );
+            COLOR4D color = g_ColorsSettings.GetItemColor( LAYER_VIAS + via->GetViaType() );
 
             GRFilledCircle( m_canvas->GetClipBox(), aDC,
                             via->GetStart().x,
@@ -308,8 +308,8 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC,
     *displ_opts = save_opt;
     GetScreen()->m_Active_Layer = activeLayer;
 
-    GetBoard()->SetElementVisibility( NO_CONNECTS_VISIBLE, nctmp );
-    GetBoard()->SetElementVisibility( ANCHOR_VISIBLE, anchorsTmp );
+    GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, nctmp );
+    GetBoard()->SetElementVisibility( LAYER_ANCHOR, anchorsTmp );
 }
 
 
diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp
index 1e55633..5825aeb 100644
--- a/pcbnew/printout_controler.cpp
+++ b/pcbnew/printout_controler.cpp
@@ -86,7 +86,7 @@ bool BOARD_PRINTOUT_CONTROLLER::OnPrintPage( int aPage )
     LSET lset = m_PrintParams.m_PrintMaskLayer;
     int pageCount = lset.count();
     wxString layer;
-    LAYER_ID extractLayer;
+    PCB_LAYER_ID extractLayer;
 
     // compute layer mask from page number if we want one page per layer
     if( m_PrintParams.m_OptionPrintPage == 0 )  // One page per layer
diff --git a/pcbnew/ratsnest.cpp b/pcbnew/ratsnest.cpp
index 0015185..21126fe 100644
--- a/pcbnew/ratsnest.cpp
+++ b/pcbnew/ratsnest.cpp
@@ -197,7 +197,7 @@ void PCB_BASE_FRAME::Compile_Ratsnest( wxDC* aDC, bool aDisplayStatus )
     TestForActiveLinksInRatsnest( 0 );
 
     // Redraw the active ratsnest ( if enabled )
-    if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) && aDC )
+    if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) && aDC )
         DrawGeneralRatsnest( aDC, 0 );
 
     if( aDisplayStatus )
@@ -284,7 +284,7 @@ void PCB_BASE_FRAME::Build_Board_Ratsnest()
     // Update the ratsnest display option (visible/invisible) flag
     for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ )
     {
-        if( !GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )  // Clear VISIBLE flag
+        if( !GetBoard()->IsElementVisible( LAYER_RATSNEST ) )  // Clear VISIBLE flag
             m_Pcb->m_FullRatsnest[ii].m_Status &= ~CH_VISIBLE;
     }
 }
@@ -756,7 +756,7 @@ void PCB_BASE_FRAME::TraceModuleRatsNest( wxDC* DC )
     if( ( m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 )
         return;
 
-    COLOR4D tmpcolor = g_ColorsSettings.GetItemColor( RATSNEST_VISIBLE );
+    COLOR4D tmpcolor = g_ColorsSettings.GetItemColor( LAYER_RATSNEST );
 
     for( unsigned ii = 0; ii < m_Pcb->m_LocalRatsnest.size(); ii++ )
     {
@@ -764,12 +764,12 @@ void PCB_BASE_FRAME::TraceModuleRatsNest( wxDC* DC )
 
         if( rats->m_Status & LOCAL_RATSNEST_ITEM )
         {
-            g_ColorsSettings.SetItemColor(RATSNEST_VISIBLE, YELLOW);
+            g_ColorsSettings.SetItemColor( LAYER_RATSNEST, YELLOW );
             rats->Draw( m_canvas, DC, GR_XOR, g_Offset_Module );
         }
         else
         {
-            g_ColorsSettings.SetItemColor(RATSNEST_VISIBLE, tmpcolor);
+            g_ColorsSettings.SetItemColor( LAYER_RATSNEST, tmpcolor );
 
             wxPoint tmp = rats->m_PadStart->GetPosition();
 
@@ -780,7 +780,7 @@ void PCB_BASE_FRAME::TraceModuleRatsNest( wxDC* DC )
         }
     }
 
-    g_ColorsSettings.SetItemColor( RATSNEST_VISIBLE, tmpcolor );
+    g_ColorsSettings.SetItemColor( LAYER_RATSNEST, tmpcolor );
 }
 
 
diff --git a/pcbnew/ratsnest_viewitem.cpp b/pcbnew/ratsnest_viewitem.cpp
index cdeba78..2d8fff6 100644
--- a/pcbnew/ratsnest_viewitem.cpp
+++ b/pcbnew/ratsnest_viewitem.cpp
@@ -60,7 +60,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
     gal->SetIsFill( false );
     gal->SetLineWidth( 1.0 );
     auto rs = aView->GetPainter()->GetSettings();
-    auto color = rs->GetColor( NULL, ITEM_GAL_LAYER( RATSNEST_VISIBLE ) );
+    auto color = rs->GetColor( NULL, LAYER_RATSNEST );
     int highlightedNet = rs->GetHighlightNetCode();
 
     // Dynamic ratsnest (for e.g. dragged items)
@@ -117,7 +117,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
 void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
 {
     aCount = 1;
-    aLayers[0] = ITEM_GAL_LAYER( RATSNEST_VISIBLE );
+    aLayers[0] = LAYER_RATSNEST;
 }
 
 }
diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp
index b6b6520..0cadbc2 100644
--- a/pcbnew/router/pns_kicad_iface.cpp
+++ b/pcbnew/router/pns_kicad_iface.cpp
@@ -353,7 +353,7 @@ public:
             return;
 
         m_items = new KIGFX::VIEW_GROUP( m_view );
-        m_items->SetLayer( ITEM_GAL_LAYER( GP_OVERLAY ) );
+        m_items->SetLayer( LAYER_GP_OVERLAY ) ;
         m_view->Add( m_items );
     }
 
@@ -729,7 +729,7 @@ std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE::syncTrack( TRACK* aTrack )
 
 std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE::syncVia( VIA* aVia )
 {
-    LAYER_ID top, bottom;
+    PCB_LAYER_ID top, bottom;
     aVia->LayerPair( &top, &bottom );
     std::unique_ptr<PNS::VIA> via( new PNS::VIA(
             aVia->GetPosition(),
@@ -943,7 +943,7 @@ void PNS_KICAD_IFACE::SetView( KIGFX::VIEW* aView )
 
     m_view = aView;
     m_previewItems = new KIGFX::VIEW_GROUP( m_view );
-    m_previewItems->SetLayer( ITEM_GAL_LAYER( GP_OVERLAY ) );
+    m_previewItems->SetLayer( LAYER_GP_OVERLAY ) ;
     m_view->Add( m_previewItems );
 
     delete m_debugDecorator;
diff --git a/pcbnew/router/router_preview_item.cpp b/pcbnew/router/router_preview_item.cpp
index abd4609..a8bf217 100644
--- a/pcbnew/router/router_preview_item.cpp
+++ b/pcbnew/router/router_preview_item.cpp
@@ -43,7 +43,7 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
 
     m_shape = NULL;
     m_clearance = -1;
-    m_originLayer = m_layer = ITEM_GAL_LAYER( GP_OVERLAY );
+    m_originLayer = m_layer = LAYER_GP_OVERLAY ;
 
     m_showTrackClearance = false;
     m_showViaClearance = false;
@@ -102,7 +102,7 @@ void ROUTER_PREVIEW_ITEM::Update( const PNS::ITEM* aItem )
     }
 
     case PNS::ITEM::VIA_T:
-        m_originLayer = m_layer = ITEM_GAL_LAYER( VIAS_VISIBLE );
+        m_originLayer = m_layer = LAYER_VIAS;
         m_type = PR_SHAPE;
         m_width = 0;
         m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 );
diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp
index de95967..965ea34 100644
--- a/pcbnew/router/router_tool.cpp
+++ b/pcbnew/router/router_tool.cpp
@@ -435,8 +435,8 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
 
     const int layerCount = bds.GetCopperLayerCount();
     int currentLayer = m_router->GetCurrentLayer();
-    LAYER_ID pairTop = m_frame->GetScreen()->m_Route_Layer_TOP;
-    LAYER_ID pairBottom = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
+    PCB_LAYER_ID pairTop = m_frame->GetScreen()->m_Route_Layer_TOP;
+    PCB_LAYER_ID pairBottom = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
 
     PNS::SIZES_SETTINGS sizes = m_router->Sizes();
 
diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp
index 63b9654..235ccc9 100644
--- a/pcbnew/sel_layer.cpp
+++ b/pcbnew/sel_layer.cpp
@@ -54,7 +54,7 @@ protected:
     // Returns true if the layer id is enabled (i.e. is it should be displayed)
     bool IsLayerEnabled( LAYER_NUM aLayer ) const override
     {
-        return m_brd->IsLayerEnabled( LAYER_ID( aLayer ) );
+        return m_brd->IsLayerEnabled( PCB_LAYER_ID( aLayer ) );
     }
 
     // Returns a color index from the layer id
@@ -79,15 +79,15 @@ protected:
 class PCB_ONE_LAYER_SELECTOR : public PCB_LAYER_SELECTOR,
                                public DIALOG_LAYER_SELECTION_BASE
 {
-    LAYER_ID    m_layerSelected;
+    PCB_LAYER_ID    m_layerSelected;
     LSET        m_notAllowedLayersMask;
 
-    std::vector<LAYER_ID> m_layersIdLeftColumn;
-    std::vector<LAYER_ID> m_layersIdRightColumn;
+    std::vector<PCB_LAYER_ID> m_layersIdLeftColumn;
+    std::vector<PCB_LAYER_ID> m_layersIdRightColumn;
 
 public:
     PCB_ONE_LAYER_SELECTOR( wxWindow* aParent, BOARD * aBrd,
-                        LAYER_ID aDefaultLayer,
+                        PCB_LAYER_ID aDefaultLayer,
                         LSET aNotAllowedLayersMask );
 
     LAYER_NUM GetLayerSelection()   { return m_layerSelected; }
@@ -102,7 +102,7 @@ private:
 
 
 PCB_ONE_LAYER_SELECTOR::PCB_ONE_LAYER_SELECTOR( wxWindow* aParent,
-        BOARD* aBrd, LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask )
+        BOARD* aBrd, PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask )
     : PCB_LAYER_SELECTOR( aBrd ), DIALOG_LAYER_SELECTION_BASE( aParent )
 {
     m_layerSelected = aDefaultLayer;
@@ -133,7 +133,7 @@ void PCB_ONE_LAYER_SELECTOR::buildList()
 
     for( LSEQ ui_seq = m_brd->GetEnabledLayers().UIOrder();  ui_seq;  ++ui_seq )
     {
-        LAYER_ID  layerid = *ui_seq;
+        PCB_LAYER_ID  layerid = *ui_seq;
 
         if( m_notAllowedLayersMask[layerid] )
             continue;
@@ -217,7 +217,7 @@ void PCB_ONE_LAYER_SELECTOR::OnRightGridCellClick( wxGridEvent& event )
 }
 
 
-LAYER_ID PCB_BASE_FRAME::SelectLayer( LAYER_ID aDefaultLayer,
+PCB_LAYER_ID PCB_BASE_FRAME::SelectLayer( PCB_LAYER_ID aDefaultLayer,
         LSET aNotAllowedLayersMask, wxPoint aDlgPosition )
 {
     PCB_ONE_LAYER_SELECTOR dlg( this, GetBoard(), aDefaultLayer, aNotAllowedLayersMask );
@@ -232,7 +232,7 @@ LAYER_ID PCB_BASE_FRAME::SelectLayer( LAYER_ID aDefaultLayer,
 
     dlg.ShowModal();
 
-    LAYER_ID layer = ToLAYER_ID( dlg.GetLayerSelection() );
+    PCB_LAYER_ID layer = ToLAYER_ID( dlg.GetLayerSelection() );
     return layer;
 }
 
@@ -246,18 +246,18 @@ class SELECT_COPPER_LAYERS_PAIR_DIALOG: public PCB_LAYER_SELECTOR,
                                         public DIALOG_COPPER_LAYER_PAIR_SELECTION_BASE
 {
 private:
-    LAYER_ID    m_frontLayer;
-    LAYER_ID    m_backLayer;
-    int         m_leftRowSelected;
-    int         m_rightRowSelected;
+    PCB_LAYER_ID m_frontLayer;
+    PCB_LAYER_ID m_backLayer;
+    int          m_leftRowSelected;
+    int          m_rightRowSelected;
 
-    std::vector<LAYER_ID> m_layersId;
+    std::vector<PCB_LAYER_ID> m_layersId;
 
 public:
     SELECT_COPPER_LAYERS_PAIR_DIALOG( wxWindow* aParent, BOARD* aPcb,
-                                      LAYER_ID aFrontLayer, LAYER_ID aBackLayer );
+                                      PCB_LAYER_ID aFrontLayer, PCB_LAYER_ID aBackLayer );
 
-    void GetLayerPair( LAYER_ID& aFrontLayer, LAYER_ID& aBackLayer )
+    void GetLayerPair( PCB_LAYER_ID& aFrontLayer, PCB_LAYER_ID& aBackLayer )
     {
         aFrontLayer = m_frontLayer;
         aBackLayer = m_backLayer;
@@ -306,7 +306,7 @@ void PCB_BASE_FRAME::SelectCopperLayerPair()
 
 
 SELECT_COPPER_LAYERS_PAIR_DIALOG::SELECT_COPPER_LAYERS_PAIR_DIALOG(
-        wxWindow* aParent, BOARD * aPcb, LAYER_ID aFrontLayer, LAYER_ID aBackLayer) :
+        wxWindow* aParent, BOARD * aPcb, PCB_LAYER_ID aFrontLayer, PCB_LAYER_ID aBackLayer) :
     PCB_LAYER_SELECTOR( aPcb ),
     DIALOG_COPPER_LAYER_PAIR_SELECTION_BASE( aParent )
 {
@@ -333,7 +333,7 @@ void SELECT_COPPER_LAYERS_PAIR_DIALOG::buildList()
 
     for( LSEQ ui_seq = m_brd->GetEnabledLayers().UIOrder();  ui_seq;  ++ui_seq )
     {
-        LAYER_ID  layerid = *ui_seq;
+        PCB_LAYER_ID layerid = *ui_seq;
 
         if( !IsCopperLayer( layerid ) )
             break;
@@ -383,7 +383,7 @@ void SELECT_COPPER_LAYERS_PAIR_DIALOG::SetGridCursor( wxGrid* aGrid, int aRow,
 {
     if( aEnable )
     {
-        LAYER_ID  layerid = m_layersId[aRow];
+        PCB_LAYER_ID layerid = m_layersId[aRow];
         COLOR4D color = GetLayerColor( layerid );
         aGrid->SetCellValue( aRow, SELECT_COLNUM, wxT("X") );
         aGrid->SetCellBackgroundColour( aRow, SELECT_COLNUM, color.ToColour() );
@@ -401,8 +401,8 @@ void SELECT_COPPER_LAYERS_PAIR_DIALOG::SetGridCursor( wxGrid* aGrid, int aRow,
 
 void SELECT_COPPER_LAYERS_PAIR_DIALOG::OnLeftGridCellClick( wxGridEvent& event )
 {
-    int         row = event.GetRow();
-    LAYER_ID    layer = m_layersId[row];
+    int          row = event.GetRow();
+    PCB_LAYER_ID layer = m_layersId[row];
 
     if( m_frontLayer == layer )
         return;
@@ -416,8 +416,8 @@ void SELECT_COPPER_LAYERS_PAIR_DIALOG::OnLeftGridCellClick( wxGridEvent& event )
 
 void SELECT_COPPER_LAYERS_PAIR_DIALOG::OnRightGridCellClick( wxGridEvent& event )
 {
-    int         row = event.GetRow();
-    LAYER_ID    layer = m_layersId[row];
+    int          row = event.GetRow();
+    PCB_LAYER_ID layer = m_layersId[row];
 
     if( m_backLayer == layer )
         return;
diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp
index eda9301..e016af6 100644
--- a/pcbnew/specctra.cpp
+++ b/pcbnew/specctra.cpp
@@ -109,7 +109,7 @@ void SPECCTRA_DB::buildLayerMaps( BOARD* aBoard )
 
     for( unsigned i = 0;  i < pcbLayer2kicad.size();  ++i )
     {
-        LAYER_ID id = ( i < layerCount-1 ) ? ToLAYER_ID( i ) : B_Cu;
+        PCB_LAYER_ID id = ( i < layerCount-1 ) ? ToLAYER_ID( i ) : B_Cu;
 
         pcbLayer2kicad[i] = id;
 
diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h
index 4f4e59e..cb814a8 100644
--- a/pcbnew/specctra.h
+++ b/pcbnew/specctra.h
@@ -3622,7 +3622,7 @@ class SPECCTRA_DB : public SPECCTRA_LEXER
     std::vector<int> kicadLayer2pcb;
 
     /// maps PCB layer number to BOARD layer numbers
-    std::vector<LAYER_ID>   pcbLayer2kicad;
+    std::vector<PCB_LAYER_ID>   pcbLayer2kicad;
 
     /// used during FromSESSION() only, memory for it is not owned here.
     UNIT_RES*       routeResolution;
diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp
index 65a7cd3..cc04cb8 100644
--- a/pcbnew/specctra_export.cpp
+++ b/pcbnew/specctra_export.cpp
@@ -277,7 +277,7 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, D_PAD* aPad )
 
     for( int layer=0; layer<copperCount; ++layer )
     {
-        LAYER_ID kilayer = pcbLayer2kicad[layer];
+        PCB_LAYER_ID kilayer = pcbLayer2kicad[layer];
 
         if( onAllCopperLayers || aPad->IsOnLayer( kilayer ) )
         {
@@ -713,8 +713,8 @@ PADSTACK* SPECCTRA_DB::makeVia( int aCopperDiameter, int aDrillDiameter,
 
 PADSTACK* SPECCTRA_DB::makeVia( const ::VIA* aVia )
 {
-    LAYER_ID    topLayerNum;
-    LAYER_ID    botLayerNum;
+    PCB_LAYER_ID    topLayerNum;
+    PCB_LAYER_ID    botLayerNum;
 
     aVia->LayerPair( &topLayerNum, &botLayerNum );
 
diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp
index b75626a..09a39f9 100644
--- a/pcbnew/specctra_import.cpp
+++ b/pcbnew/specctra_import.cpp
@@ -342,8 +342,8 @@ TRACK* SPECCTRA_DB::makeTRACK( PATH* aPath, int aPointIndex, int aNetcode ) thro
 
         via->SetWidth( viaDiam );
 
-        LAYER_ID topLayer = pcbLayer2kicad[topLayerNdx];
-        LAYER_ID botLayer = pcbLayer2kicad[botLayerNdx];
+        PCB_LAYER_ID topLayer = pcbLayer2kicad[topLayerNdx];
+        PCB_LAYER_ID botLayer = pcbLayer2kicad[botLayerNdx];
 
         via->SetLayerPair( topLayer, botLayer );
     }
diff --git a/pcbnew/swap_layers.cpp b/pcbnew/swap_layers.cpp
index f27fe8e..deb022d 100644
--- a/pcbnew/swap_layers.cpp
+++ b/pcbnew/swap_layers.cpp
@@ -41,20 +41,20 @@
 #include <wx/statline.h>
 
 
-#define NO_CHANGE     LAYER_ID(-3)
+#define NO_CHANGE     PCB_LAYER_ID(-3)
 
 
 enum swap_layer_id {
     ID_WINEDA_SWAPLAYERFRAME = 1800,
     ID_BUTTON_0,
-    ID_TEXT_0 = ID_BUTTON_0 + LAYER_ID_COUNT
+    ID_TEXT_0 = ID_BUTTON_0 + PCB_LAYER_ID_COUNT
 };
 
 
 class SWAP_LAYERS_DIALOG : public DIALOG_SHIM
 {
 public:
-    SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray );
+    SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, PCB_LAYER_ID* aArray );
     // ~SWAP_LAYERS_DIALOG() { };
 
 private:
@@ -68,8 +68,8 @@ private:
     wxStaticLine*           Line;
     wxStdDialogButtonSizer* StdDialogButtonSizer;
 
-    LAYER_ID*               m_callers_nlayers;          // DIM() is LAYER_ID_COUNT
-    wxStaticText*           layer_list[LAYER_ID_COUNT];
+    PCB_LAYER_ID*               m_callers_nlayers;          // DIM() is PCB_LAYER_ID_COUNT
+    wxStaticText*           layer_list[PCB_LAYER_ID_COUNT];
 
     void Sel_Layer( wxCommandEvent& event );
     void OnOkClick( wxCommandEvent& event );
@@ -80,7 +80,7 @@ private:
 
 
 BEGIN_EVENT_TABLE( SWAP_LAYERS_DIALOG, wxDialog )
-    EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + LAYER_ID_COUNT - 1,
+    EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + PCB_LAYER_ID_COUNT - 1,
                        wxEVT_COMMAND_BUTTON_CLICKED, SWAP_LAYERS_DIALOG::Sel_Layer )
 
     EVT_BUTTON( wxID_OK, SWAP_LAYERS_DIALOG::OnOkClick )
@@ -89,7 +89,7 @@ BEGIN_EVENT_TABLE( SWAP_LAYERS_DIALOG, wxDialog )
 END_EVENT_TABLE()
 
 
-SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray ) :
+SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, PCB_LAYER_ID* aArray ) :
     DIALOG_SHIM( parent, -1, _( "Swap Layers:" ), wxPoint( -1, -1 ),
                  wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
     m_callers_nlayers( aArray )
@@ -229,7 +229,7 @@ SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray
          */
         if( layer == 0 )
         {
-            text = new wxStaticText( this, item_ID, board->GetLayerName( LAYER_ID( 0 ) ),
+            text = new wxStaticText( this, item_ID, board->GetLayerName( PCB_LAYER_ID( 0 ) ),
                                      wxDefaultPosition, wxDefaultSize, 0 );
             goodSize = text->GetSize();
 
@@ -306,12 +306,12 @@ void SWAP_LAYERS_DIALOG::Sel_Layer( wxCommandEvent& event )
 
     ii = event.GetId();
 
-    if( ii < ID_BUTTON_0 || ii >= ID_BUTTON_0 + LAYER_ID_COUNT )
+    if( ii < ID_BUTTON_0 || ii >= ID_BUTTON_0 + PCB_LAYER_ID_COUNT )
         return;
 
     ii = event.GetId() - ID_BUTTON_0;
 
-    LAYER_ID layer = m_callers_nlayers[ii];
+    PCB_LAYER_ID layer = m_callers_nlayers[ii];
 
     LSET notallowed_mask = IsCopperLayer( ii ) ? LSET::AllNonCuMask() : LSET::AllCuMask();
 
@@ -358,7 +358,7 @@ void SWAP_LAYERS_DIALOG::OnOkClick( wxCommandEvent& event )
 
 void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event )
 {
-    LAYER_ID    new_layer[LAYER_ID_COUNT];
+    PCB_LAYER_ID    new_layer[PCB_LAYER_ID_COUNT];
 
     for( unsigned i = 0; i < DIM( new_layer );  ++i )
         new_layer[i] = NO_CHANGE;
@@ -380,7 +380,7 @@ void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event )
             if( via->GetViaType() == VIA_THROUGH )
                 continue;
 
-            LAYER_ID top_layer, bottom_layer;
+            PCB_LAYER_ID top_layer, bottom_layer;
 
             via->LayerPair( &top_layer, &bottom_layer );
 
diff --git a/pcbnew/swig/board.i b/pcbnew/swig/board.i
index 244f7f8..7e6f6ed 100644
--- a/pcbnew/swig/board.i
+++ b/pcbnew/swig/board.i
@@ -62,14 +62,20 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints)
 %include netinfo.i
 %include netclass.i
 
+%ignore operator++(SCH_LAYER_ID&);
+
+%ignore operator++(GAL_LAYER_ID&);
+
+%ignore operator+(const GAL_LAYER_ID&, int);
 
 %include layers_id_colors_and_visibility.h
+
 // Extend LSET by 2 methods to add or remove layers from the layer list
 // Mainly used to add or remove layers of a pad layer list
 %extend LSET
 {
-    LSET addLayer( LAYER_ID aLayer)    { return self->set(aLayer); }
-    LSET removeLayer( LAYER_ID aLayer) { return self->reset(aLayer); }
+    LSET addLayer( PCB_LAYER_ID aLayer)    { return self->set(aLayer); }
+    LSET removeLayer( PCB_LAYER_ID aLayer) { return self->reset(aLayer); }
     LSET addLayerSet( LSET aLayerSet)    { return *self |= aLayerSet; }
     LSET removeLayerSet( LSET aLayerSet) { return *self &= ~aLayerSet; }
 
diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp
index d51bd21..f547f6e 100644
--- a/pcbnew/tool_pcb.cpp
+++ b/pcbnew/tool_pcb.cpp
@@ -129,7 +129,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
     }
 
     int via_type = GetDesignSettings().m_CurrentViaType;
-    via_color = GetBoard()->GetVisibleElementColor(VIAS_VISIBLE+via_type);
+    via_color = GetBoard()->GetVisibleElementColor( LAYER_VIAS + via_type );
 
     if( previous_via_color != via_color )
     {
@@ -745,7 +745,7 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
         break;
 
     case ID_TB_OPTIONS_SHOW_RATSNEST:
-        SetElementVisibility( RATSNEST_VISIBLE, state );
+        SetElementVisibility( LAYER_RATSNEST, state );
         OnModify();
 
         if( state && (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp
index 95b38a2..4ccc686 100644
--- a/pcbnew/toolbars_update_user_interface.cpp
+++ b/pcbnew/toolbars_update_user_interface.cpp
@@ -141,9 +141,9 @@ void PCB_EDIT_FRAME::OnUpdateDrcEnable( wxUpdateUIEvent& aEvent )
 
 void PCB_EDIT_FRAME::OnUpdateShowBoardRatsnest( wxUpdateUIEvent& aEvent )
 {
-    aEvent.Check( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) );
+    aEvent.Check( GetBoard()->IsElementVisible( LAYER_RATSNEST ) );
     m_optionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_RATSNEST,
-                                        GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ?
+                                        GetBoard()->IsElementVisible( LAYER_RATSNEST ) ?
                                         _( "Hide board ratsnest" ) :
                                         _( "Show board ratsnest" ) );
 }
diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp
index 9038e7f..0c6c632 100644
--- a/pcbnew/tools/drawing_tool.cpp
+++ b/pcbnew/tools/drawing_tool.cpp
@@ -383,7 +383,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
                     // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
                     textPcb->SetFlags( IS_NEW );
 
-                    LAYER_ID layer = m_frame->GetActiveLayer();
+                    PCB_LAYER_ID layer = m_frame->GetActiveLayer();
                     textPcb->SetLayer( layer );
 
                     // Set the mirrored option for layers on the BACK side of the board
@@ -527,7 +527,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
             {
             case SET_ORIGIN:
                 {
-                    LAYER_ID layer = getDrawingLayer();
+                    PCB_LAYER_ID layer = getDrawingLayer();
 
                     if( layer == Edge_Cuts )    // dimensions are not allowed on EdgeCuts
                         layer = Dwgs_User;
@@ -1112,7 +1112,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
                 m_controls->SetAutoPan( true );
                 m_controls->CaptureCursor( true );
 
-                LAYER_ID layer = getDrawingLayer();
+                PCB_LAYER_ID layer = getDrawingLayer();
 
                 // Init the new item attributes
                 // (non-geometric, those are handled by the manager)
@@ -1557,9 +1557,9 @@ int DRAWING_TOOL::getSegmentWidth( unsigned int aLayer ) const
 }
 
 
-LAYER_ID DRAWING_TOOL::getDrawingLayer() const
+PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer() const
 {
-    LAYER_ID layer = m_frame->GetActiveLayer();
+    PCB_LAYER_ID layer = m_frame->GetActiveLayer();
 
     if( IsCopperLayer( layer ) )
     {
diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h
index 6617d84..51a41e8 100644
--- a/pcbnew/tools/drawing_tool.h
+++ b/pcbnew/tools/drawing_tool.h
@@ -275,7 +275,7 @@ private:
     int getSegmentWidth( unsigned int aLayer ) const;
 
     ///> Selects a non-copper layer for drawing
-    LAYER_ID getDrawingLayer() const;
+    PCB_LAYER_ID getDrawingLayer() const;
 
     KIGFX::VIEW* m_view;
     KIGFX::VIEW_CONTROLS* m_controls;
diff --git a/pcbnew/tools/edit_points.h b/pcbnew/tools/edit_points.h
index dab5d78..f4d925f 100644
--- a/pcbnew/tools/edit_points.h
+++ b/pcbnew/tools/edit_points.h
@@ -502,7 +502,7 @@ public:
     virtual void ViewGetLayers( int aLayers[], int& aCount ) const override
     {
         aCount = 1;
-        aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY );
+        aLayers[0] = LAYER_GP_OVERLAY ;
     }
 
 #if defined(DEBUG)
diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp
index 2ae97e0..888ce4e 100644
--- a/pcbnew/tools/grid_helper.cpp
+++ b/pcbnew/tools/grid_helper.cpp
@@ -275,7 +275,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos )
             DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
             VECTOR2I start = dseg->GetStart();
             VECTOR2I end = dseg->GetEnd();
-            //LAYER_ID layer = dseg->GetLayer();
+            //PCB_LAYER_ID layer = dseg->GetLayer();
 
             switch( dseg->GetShape() )
             {
diff --git a/pcbnew/tools/module_editor_tools.cpp b/pcbnew/tools/module_editor_tools.cpp
index e82a89c..bef12ae 100644
--- a/pcbnew/tools/module_editor_tools.cpp
+++ b/pcbnew/tools/module_editor_tools.cpp
@@ -518,11 +518,11 @@ int MODULE_EDITOR_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent )
     KIGFX::PCB_RENDER_SETTINGS* settings =
             static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
 
-    const LAYER_NUM layers[] = { ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ),
-                                 ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ),
-                                 ITEM_GAL_LAYER( MOD_TEXT_INVISIBLE ),
-                                 ITEM_GAL_LAYER( MOD_REFERENCES_VISIBLE ),
-                                 ITEM_GAL_LAYER( MOD_VALUES_VISIBLE ) };
+    const LAYER_NUM layers[] = { LAYER_MOD_TEXT_BK,
+                                 LAYER_MOD_TEXT_FR,
+                                 LAYER_MOD_TEXT_INVISIBLE,
+                                 LAYER_MOD_REFERENCES,
+                                 LAYER_MOD_VALUES };
 
     bool enable = !settings->GetSketchMode( layers[0] );
 
@@ -553,7 +553,7 @@ int MODULE_EDITOR_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent )
     KIGFX::PCB_RENDER_SETTINGS* settings =
             static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
 
-    const LAYER_ID layers[] = { F_Adhes, B_Adhes, F_Paste, B_Paste,
+    const PCB_LAYER_ID layers[] = { F_Adhes, B_Adhes, F_Paste, B_Paste,
             F_SilkS, B_SilkS, F_Mask, B_Mask,
             Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts };
 
diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp
index c7cb553..67701e7 100644
--- a/pcbnew/tools/pcbnew_control.cpp
+++ b/pcbnew/tools/pcbnew_control.cpp
@@ -375,7 +375,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
 // Layer control
 int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
 {
-    m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter<intptr_t>() );
+    m_frame->SwitchLayer( NULL, (PCB_LAYER_ID) aEvent.Parameter<intptr_t>() );
 
     return 0;
 }
diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp
index 6252a63..37d2968 100644
--- a/pcbnew/tools/selection_tool.cpp
+++ b/pcbnew/tools/selection_tool.cpp
@@ -1005,7 +1005,7 @@ static bool itemIsIncludedByFilter( const BOARD_ITEM& aItem,
                                     const DIALOG_BLOCK_OPTIONS::OPTIONS& aBlockOpts )
 {
     bool include = true;
-    const LAYER_ID layer = aItem.GetLayer();
+    const PCB_LAYER_ID layer = aItem.GetLayer();
 
     // can skip without even checking item type
     if( !aBlockOpts.includeItemsOnInvisibleLayers
@@ -1281,7 +1281,7 @@ bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) const
     case PCB_VIA_T:
         {
             // For vias it is enough if only one of layers is visible
-            LAYER_ID top, bottom;
+            PCB_LAYER_ID top, bottom;
 
             static_cast<const VIA*>( aItem )->LayerPair( &top, &bottom );
 
@@ -1290,10 +1290,10 @@ bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) const
         break;
 
     case PCB_MODULE_T:
-        if( aItem->IsOnLayer( F_Cu ) && board()->IsElementVisible( MOD_FR_VISIBLE ) )
+        if( aItem->IsOnLayer( F_Cu ) && board()->IsElementVisible( LAYER_MOD_FR ) )
             return !m_editModules;
 
-        if( aItem->IsOnLayer( B_Cu ) && board()->IsElementVisible( MOD_BK_VISIBLE ) )
+        if( aItem->IsOnLayer( B_Cu ) && board()->IsElementVisible( LAYER_MOD_BK ) )
             return !m_editModules;
 
         return false;
@@ -1550,7 +1550,7 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
     // its unique area).
     const double commonAreaRatio = 0.6;
 
-    LAYER_ID actLayer = m_frame->GetActiveLayer();
+    PCB_LAYER_ID actLayer = m_frame->GetActiveLayer();
 
     LSET silkLayers( 2, B_SilkS, F_SilkS );
 
diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp
index 56b3a8b..dc11079 100644
--- a/pcbnew/tracepcb.cpp
+++ b/pcbnew/tracepcb.cpp
@@ -211,7 +211,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const
         if( module->IsMoving() )
             continue;
 
-        if( !IsElementVisible( PCB_VISIBLE( MOD_FR_VISIBLE ) ) )
+        if( !IsElementVisible( LAYER_MOD_FR ) )
         {
             if( module->GetLayer() == F_Cu )
                 display = false;
@@ -219,7 +219,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const
             layerMask.set( F_Cu, false );
         }
 
-        if( !IsElementVisible( PCB_VISIBLE( MOD_BK_VISIBLE ) ) )
+        if( !IsElementVisible( LAYER_MOD_BK ) )
         {
             if( module->GetLayer() == B_Cu )
                 display = false;
diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp
index 4f8332c..db739c4 100644
--- a/pcbnew/zones_by_polygon.cpp
+++ b/pcbnew/zones_by_polygon.cpp
@@ -383,7 +383,7 @@ void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* aZone )
         return;
     }
 
-    LAYER_ID layer = aZone->GetLayer();
+    PCB_LAYER_ID layer = aZone->GetLayer();
 
     if( DC )
     {
@@ -755,7 +755,7 @@ bool PCB_EDIT_FRAME::End_Zone( wxDC* DC )
     m_canvas->SetMouseCapture( NULL, NULL );
 
     // Undraw old drawings, because they can have important changes
-    LAYER_ID layer = zone->GetLayer();
+    PCB_LAYER_ID layer = zone->GetLayer();
     GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_XOR, layer );
     GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_XOR, layer );
 
-- 
2.7.4


Follow ups

References