[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: PCB, I lost my layer colors



Here is the initial revision of the patch-set.

The first patch is quite simple;
it just adds attributes to layers.

The second makes use of them.

In layer context, "PCB:Color" attribute is recognized
as the layer color definition.

To switch between two versions of the PCB file format
(with layer attributes and without them),
preserve_layer_attribute flag is added; in GUIs it
can be set via checkbutton in Preferences->General tab
(the GTK hid) or "Settings->Preserve layer attributes"
menu item (the Lesstif hid). when loading a PCB,
the flag is set if there are any layer attributes
in the file and cleared if there is none.

When the flag is set, the layer colors are saved in the
file as layer attributes; when the flag is cleared, no layer
attributes are written, even those that were read from the file.

Layer attributes override the --layer-color-# command line
option; as a means to override the attributes, I added
SetLayerColor action, e.g.
pcb --action-string 'SetLayerColor(\"solder\",red)' board.pcb
or
pcb --action-string 'SetLayerColor(0,#4f4f00)' board.pcb

The layers don't change their colors when moving.

Special layers including the elements are not affected yet;
actually, the `elements' color is used for both sides
of the silkscreen. I'm not quite sure whether to change
this and use the silkscreen layer color settings or
to introduce PCB attributes to handle these colors;
or to leave them as they are.

Any thoughts on logic/naming/etc?
From 5fe50d86f37afe2669e68c2c31a6cbc7d803c32e Mon Sep 17 00:00:00 2001
From: Ineiev <ineiev@xxxxxxxxxxxxxxxx>
Date: Tue, 22 Sep 2009 10:21:50 +0400
Subject: [PATCH 1/2] add attributes to layers

---
 src/file.c    |    9 +++------
 src/global.h  |    4 ++--
 src/parse_y.y |    7 ++++---
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/file.c b/src/file.c
index b6c67b9..9991d09 100644
--- a/src/file.c
+++ b/src/file.c
@@ -1,10 +1,8 @@
-/* $Id$ */
-
 /*
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau
+ *  Copyright (C) 1994,1995,1996,1997,1998,2005,2006,2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -18,7 +16,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *  Contact addresses for paper mail and Email:
  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
@@ -99,8 +97,6 @@
 #include <dmalloc.h>
 #endif
 
-RCSID ("$Id$");
-
 #if !defined(HAS_ATEXIT) && !defined(HAS_ON_EXIT)
 /* ---------------------------------------------------------------------------
  * some local identifiers for OS without an atexit() or on_exit()
@@ -781,6 +777,7 @@ WriteLayerData (FILE * FP, Cardinal Number, LayerTypePtr layer)
       fprintf (FP, "Layer(%i ", (int) Number + 1);
       PrintQuotedString (FP, EMPTY (layer->Name));
       fputs (")\n(\n", FP);
+      WriteAttributeList (FP, &layer->Attributes, "\t");
 
       for (n = 0; n < layer->LineN; n++)
 	{
diff --git a/src/global.h b/src/global.h
index e8fc8f1..092cd1a 100644
--- a/src/global.h
+++ b/src/global.h
@@ -2,7 +2,7 @@
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996, 2004 Thomas Nau
+ *  Copyright (C) 1994,1995,1996, 2004, 2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -24,7 +24,6 @@
  *
  *  RCS: $Id$
  */
-/* 15 Oct 2008 Ineiev: add different crosshair shapes */
 
 /* definition of types
  */
@@ -278,6 +277,7 @@ typedef struct			/* holds information about one layer */
   Boolean On;			/* visible flag */
   char *Color,			/* color */
    *SelectedColor;
+  AttributeListType Attributes;
 }
 LayerType, *LayerTypePtr;
 
diff --git a/src/parse_y.y b/src/parse_y.y
index dba2603..2aa7b0c 100644
--- a/src/parse_y.y
+++ b/src/parse_y.y
@@ -13,7 +13,7 @@
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996 Thomas Nau
+ *  Copyright (C) 1994,1995,1996,2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *  Contact addresses for paper mail and Email:
  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
@@ -837,7 +837,7 @@ component-side silk, in that order.
 @item Name
 The layer name.
 @item contents
-The contents of the layer, which may include lines, arcs, rectangles,
+The contents of the layer, which may include attributes, lines, arcs, rectangles,
 text, and polygons.
 @end table
 
@@ -894,6 +894,7 @@ layerdefinition
 		| text_hi_format
 		| text_newformat
 		| text_oldformat
+		| { attr_list = & Layer->Attributes; } attributes
 			/* flags are passed in */
 		| T_POLYGON '(' flags ')' '('
 			{
-- 
1.6.4.1

From a0b59120d33389f0f7cb3394d26fc602adb7f6db Mon Sep 17 00:00:00 2001
From: Ineiev <ineiev@xxxxxxxxxxxxxxxx>
Date: Mon, 19 Oct 2009 07:41:07 +0400
Subject: [PATCH 2/2] Handle "PCB:Color" layer attributes

Add PreserveLayerAttributes action and
preserve_layer_attributes flag to control
PCB behaviour in relation to saving layer attributes in PCB file.

Add SetLayerColor action

--layer-color-# command-line option is overriden
by the layer PCB:Color attribute when it is present in the file;
to override the attribute, --string-action "SetLayerColor(#,...)" may be used

Layers preserve their colours when moving (MoveLayer action)
---
 src/Makefile.am              |    3 +-
 src/attribute.c              |  305 ++++++++++++++++++++++++++++++++++++++++++
 src/attribute.h              |   40 ++++++
 src/create.c                 |   13 +-
 src/file.c                   |    9 +-
 src/flags.c                  |    2 +
 src/global.h                 |    1 +
 src/hid/gtk/gui-config.c     |   12 +-
 src/hid/gtk/gui-top-window.c |   13 +--
 src/hid/lesstif/menu.c       |    1 +
 src/move.c                   |   13 +--
 src/parse_y.y                |   18 ++-
 src/pcb-menu.res             |    1 +
 13 files changed, 392 insertions(+), 39 deletions(-)
 create mode 100644 src/attribute.c
 create mode 100644 src/attribute.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 1c97b60..f5ae837 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,4 @@
 ## -*- makefile -*-
-## $Id$
 ##
 
 SUBDIRS=	icons
@@ -30,6 +29,8 @@ endif
 PCB_SRCS = \
 	action.c \
 	action.h \
+	attribute.c \
+	attribute.h \
 	autoplace.c \
 	autoplace.h \
 	autoroute.c \
diff --git a/src/attribute.c b/src/attribute.c
new file mode 100644
index 0000000..651f621
--- /dev/null
+++ b/src/attribute.c
@@ -0,0 +1,305 @@
+/*
+ *                            COPYRIGHT
+ *
+ *  PCB, interactive printed circuit board design
+ *  Copyright (C) 2009 Thomas Nau
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  Contact addresses for paper mail and Email:
+ *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
+ *  Thomas.Nau@xxxxxxxxxxxxx
+ *
+ */
+/* manage PCB-handled attributes */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include "global.h"
+#include "attribute.h"
+#include "create.h"
+#include "data.h"
+#include "error.h"
+#include "mymem.h"
+/* attributes handled by PCB begin with "PCB:", namely,
+in layer context:
+   PCB:Color color in which the layer is displayed
+*/
+static char color_attr_name[]="PCB:Color";
+struct layer_attribute_action
+{
+  char *name;
+  /* parse a layer attribute;
+     return !0 to remove all subsequent attributes with the same name,
+     return 0 to process them */
+  int (*parse) (int layer_idx, AttributeTypePtr attribute, int alt);
+  /* set the layer attribute according to actual state */
+  void (*set) (LayerTypePtr layer, int alt);
+  int alt;
+};
+
+static int
+parse_color_attribute (int layer_idx, AttributeTypePtr attribute, int alt)
+{
+  LayerTypePtr layer = LAYER_PTR (layer_idx);
+
+  Settings.LayerColor[layer_idx] = layer->Color = attribute->value;
+  return 0;
+}
+
+static void
+set_layer_color (int layer_idx, char *value)
+{
+  AttributeTypePtr a;
+  LayerTypePtr layer = LAYER_PTR (layer_idx);
+
+  a = set_attribute (&layer->Attributes, color_attr_name, value);
+  parse_color_attribute (layer_idx, a, 0);
+}
+
+static void
+set_color_attribute (LayerTypePtr layer, int alt)
+{
+  AttributeListTypePtr attr = &layer->Attributes;
+
+  set_attribute (attr, color_attr_name, layer->Color);
+}
+
+struct layer_attribute_action layer_attributes[]=
+{
+ {color_attr_name, parse_color_attribute, set_color_attribute, 0}
+};
+#define LAYER_ATTR_NUM	(sizeof layer_attributes / sizeof *layer_attributes)
+
+/* remove from list all subsequent attributes with
+   name equal to list[index].name */
+static void
+remove_homonyms (AttributeListTypePtr list, int index)
+{
+  int n = list->Number;
+  int i, j;
+  AttributeTypePtr al = list->List;
+  char *name = al[index].name;
+
+  for (i = index + 1; i < n; i++)
+    if (!strcmp (al[i].name, name))
+      {
+	SaveFree (al[i].name);
+	SaveFree (al[i].value);
+	for (j = i; j + 1 < n; j++)
+	  al[j] = al[j+1];
+	n--; i--;
+      }
+  list->Number = n;
+}
+
+/* modify layer properties according to it's attributes */
+void
+parse_layer_attributes (int layer_idx)
+{
+  LayerTypePtr layer = LAYER_PTR (layer_idx);
+  int i, j, n = layer->Attributes.Number;
+  AttributeTypePtr al = layer->Attributes.List;
+  struct layer_attribute_action *attr = layer_attributes;
+
+  if (n)
+    Settings.preserve_layer_attributes = !0;
+  for (j = 0; j < LAYER_ATTR_NUM; j++, attr++)
+    for (i = 0; i < n; i++)
+      if (!strcmp(al[i].name, attr->name))
+	if (attr->parse (layer_idx, al+i, attr->alt))
+	  {
+	    remove_homonyms (&layer->Attributes, i);
+	    n = layer->Attributes.Number;
+	    break;
+	  }
+}
+
+AttributeTypePtr
+find_attribute (AttributeListTypePtr Attributes, const char *name)
+{
+  int n;
+  AttributeTypePtr a = Attributes->List;
+
+  for (n = Attributes->Number; n; n--, a++)
+    if (!strcmp (a->name, name))
+      return a;
+  return NULL;
+}
+
+/* replace first occurrence of attribute with given name
+   or push a new attribute when such attribute is absent */
+AttributeTypePtr
+set_attribute (AttributeListTypePtr attr_list, char *name, char *value)
+{
+  AttributeTypePtr a;
+
+  a = find_attribute (attr_list, name);
+  if (NULL == a)
+    a = CreateNewAttribute (attr_list, name, value);
+  else if (strcmp (value, a->value)) /* don't bite itself's tail */
+    {
+      SaveFree (a->value);
+      a->value = MyStrdup (value, "set_attribute");
+    }
+  return a;
+}
+
+/* synchronise layer attributes with actual state */
+void
+update_layer_attributes (LayerTypePtr layer)
+{
+  int i;
+
+  for (i = 0; i < LAYER_ATTR_NUM; i++)
+    layer_attributes[i].set (layer, layer_attributes[i].alt);
+}
+
+static const char setcolor_syntax[] =
+  "SetLayerColor(number|\\\"name\\\"|c, color)";
+
+static const char setcolor_help[] = "Sets color for layer.";
+
+/* %start-doc actions SetLayerColor
+
+
+@table @code
+
+@item number
+Layer number.
+
+@item \"name\"
+Layer name.
+
+@item c
+Specifies current layer.
+
+@item color
+Color in form @code{#rrggbb}.
+
+@end table
+
+@example
+SetColor(\"solder\", #ff0000)
+@end example
+
+%end-doc */
+
+static int
+ActionSetColor (int argc, char **argv, int x, int y)
+{
+  int layer_idx = -1, layers_changed = 0;
+  char *layer_name;
+
+  if (argc < 2)
+    AFAIL (setcolor);
+
+  if (!strcmp(*argv,"c"))
+    layer_idx = INDEXOFCURRENT;
+  else if (argv[0][0]!='"'|| argv[0][strlen(argv[0]) - 1]!='"')
+    {
+      layer_idx = atoi (*argv);
+      if (layer_idx < 0 || layer_idx > max_layer + 1)
+	{
+	  Message ("SetLayerColor: layer number `%s' out of range\n", *argv);
+	  return 0;
+	}
+    }
+  if (layer_idx >= 0)
+    {
+      set_layer_color (layer_idx, argv[1]);
+      hid_action ("LayersChanged");
+      return 0;
+    }
+
+  layer_name = MyStrdup (argv[0] + 1, "ActionSetColor");
+  layer_name [strlen(layer_name) - 1] = 0;
+
+  for (layer_idx = 0; layer_idx <= max_layer + 1; layer_idx++)
+    if (!strcmp (LAYER_PTR(layer_idx)->Name, layer_name))
+      {
+        set_layer_color (layer_idx, argv[1]);
+	layers_changed++;
+      }
+  if (layers_changed)
+    hid_action ("LayersChanged");
+  else
+    Message ("SetLayerColor: no layer `%s' found\n", layer_name);
+  return 0;
+}
+
+static const char preserve_layer_attributes_syntax[] =
+  "PreserveLayerAttributes(0|1|toggle)";
+
+static const char preserve_layer_attributes_help[] =
+ "Define whether layer attributes should be saved in PCB file.";
+
+/* %start-doc actions PreserveLayerAttributes
+
+@table @code
+
+@item 0
+Don't write layer attributes when saving PCB.
+
+@item 1
+Write layer attributes when saving PCB.
+
+@item toggle
+Reverse current setting.
+
+@end table
+
+@example
+PreserveLayerAttributes(1)
+@end example
+
+%end-doc */
+
+static int
+preserve_layer_attributes (int argc, char **argv, int x, int y)
+{
+  int setting;
+  if (argc < 1)
+    AFAIL (preserve_layer_attributes);
+
+  if (!strcmp(*argv,"0"))
+    setting = 0;
+  else if (!strcmp(*argv,"1"))
+    setting = 1;
+  else if (!strcmp(*argv,"toggle"))
+    setting = !Settings.preserve_layer_attributes;
+  else
+    AFAIL (preserve_layer_attributes);
+
+  Settings.preserve_layer_attributes = setting;
+  return 0;
+}
+
+
+HID_Action attribute_action_list[] = {
+  {"SetLayerColor", 0, ActionSetColor,
+   setcolor_help, setcolor_syntax}
+  ,
+  {"PreserveLayerAttributes", 0, preserve_layer_attributes,
+   preserve_layer_attributes_help, preserve_layer_attributes_syntax}
+  ,
+
+};
+
+REGISTER_ACTIONS (attribute_action_list)
diff --git a/src/attribute.h b/src/attribute.h
new file mode 100644
index 0000000..d389c63
--- /dev/null
+++ b/src/attribute.h
@@ -0,0 +1,40 @@
+/*
+ *                            COPYRIGHT
+ *
+ *  PCB, interactive printed circuit board design
+ *  Copyright (C) 2009 Thomas Nau
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  Contact addresses for paper mail and Email:
+ *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
+ *  Thomas.Nau@xxxxxxxxxxxxx
+ *
+ */
+/* manage PCB-handled attributes */
+
+/* modify layer properties according to it's attributes */
+void parse_layer_attributes (int layer_idx);
+/* synchronise layer attributes with actual state */
+void update_layer_attributes (LayerTypePtr layer);
+/* return first attribute with given name in the list
+   or NULL when absent */
+AttributeTypePtr find_attribute (AttributeListTypePtr Attributes,
+				 const char *name);
+/* replace first occurrence of attribute with given name
+   or push a new attribute when such attribute is absent;
+   returns pointer to the attribute */
+AttributeTypePtr set_attribute (AttributeListTypePtr Attributes,
+				char *name, char *value);
diff --git a/src/create.c b/src/create.c
index fc6b863..7446e8a 100644
--- a/src/create.c
+++ b/src/create.c
@@ -1,10 +1,8 @@
-/* $Id$ */
-
 /*
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996, 2005 Thomas Nau
+ *  Copyright (C) 1994,1995,1996, 2005, 2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -18,7 +16,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *  Contact addresses for paper mail and Email:
  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
@@ -40,6 +38,7 @@
 
 #include "global.h"
 
+#include "attribute.h"
 #include "create.h"
 #include "data.h"
 #include "draw.h"
@@ -58,8 +57,6 @@
 #include <dmalloc.h>
 #endif
 
-RCSID ("$Id$");
-
 /* ---------------------------------------------------------------------------
  * some local identifiers
  */
@@ -200,6 +197,7 @@ CreateNewPCB (Boolean SetDefaultNames)
 int
 CreateNewPCBPost (PCBTypePtr pcb, int use_defaults)
 {
+  int i;
   /* copy default settings */
   pcb_colors_from_settings (pcb);
 
@@ -213,6 +211,9 @@ CreateNewPCBPost (PCBTypePtr pcb, int use_defaults)
       pcb->Data->Layer[max_layer + SOLDER_LAYER].Name =
 	MyStrdup ("silk", "CreateNewPCB()");
     }
+  else for (i = 0; i <= max_layer + 1; i++)
+    parse_layer_attributes (i);
+
   return 0;
 }
 
diff --git a/src/file.c b/src/file.c
index 9991d09..2c90be1 100644
--- a/src/file.c
+++ b/src/file.c
@@ -73,7 +73,7 @@
 #include <unistd.h>
 #endif
 
-
+#include "attribute.h"
 #include "buffer.h"
 #include "change.h"
 #include "create.h"
@@ -777,8 +777,11 @@ WriteLayerData (FILE * FP, Cardinal Number, LayerTypePtr layer)
       fprintf (FP, "Layer(%i ", (int) Number + 1);
       PrintQuotedString (FP, EMPTY (layer->Name));
       fputs (")\n(\n", FP);
-      WriteAttributeList (FP, &layer->Attributes, "\t");
-
+      if (Settings.preserve_layer_attributes)
+	{
+	  update_layer_attributes (layer);
+	  WriteAttributeList (FP, &layer->Attributes, "\t");
+	}
       for (n = 0; n < layer->LineN; n++)
 	{
 	  LineTypePtr line = &layer->Line[n];
diff --git a/src/flags.c b/src/flags.c
index c6c7458..1cfd2d0 100644
--- a/src/flags.c
+++ b/src/flags.c
@@ -245,6 +245,8 @@ HID_Flag flags_flag_list[] = {
 	OffsetOf (SettingType, RingBellWhenFinished)},
 
   {"buffer", FlagBuffer, 0},
+  {"preserve_layer_attributes", FlagSETTINGS,
+	OffsetOf (SettingType, preserve_layer_attributes)},
 
 };
 
diff --git a/src/global.h b/src/global.h
index 092cd1a..14c3fbd 100644
--- a/src/global.h
+++ b/src/global.h
@@ -660,6 +660,7 @@ typedef struct			/* some resources... */
     /* connections is done */
     AutoPlace;			/* flag which says we should force placement of the
 				   windows on startup */
+  int preserve_layer_attributes; /* whether to save layer attributes in PCB file */
   int HistorySize,		/* FIXME? Used in hid/xaw code only. */
     init_done;
 }
diff --git a/src/hid/gtk/gui-config.c b/src/hid/gtk/gui-config.c
index 490befc..c26c188 100644
--- a/src/hid/gtk/gui-config.c
+++ b/src/hid/gtk/gui-config.c
@@ -1,10 +1,8 @@
-/* $Id$ */
-
 /*
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996 Thomas Nau
+ *  Copyright (C) 1994,1995,1996,2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -56,9 +54,6 @@
 
 extern int	MoveLayerAction(int argc, char **argv, int x, int y);
 
-
-RCSID ("$Id$");
-
 enum ConfigType
 {
   CONFIG_Boolean,
@@ -912,6 +907,11 @@ config_general_tab_create (GtkWidget * tab_vbox)
 		    600.0, 0, 0, config_backup_spin_button_cb, NULL, FALSE,
 		    _("Seconds between auto backups\n"
 		      "(set to zero to disable auto backups)"));
+  ghid_check_button_connected (vbox, NULL, Settings.preserve_layer_attributes,
+			       TRUE, FALSE, FALSE, 2,
+			       config_general_toggle_cb,
+			       &Settings.preserve_layer_attributes,
+			       _("Save layer attributes in PCB file"));
 
   vbox = ghid_category_vbox (tab_vbox, _("Misc"), 4, 2, TRUE, TRUE);
   ghid_spin_button (vbox, NULL, ghidgui->history_size,
diff --git a/src/hid/gtk/gui-top-window.c b/src/hid/gtk/gui-top-window.c
index ca17446..fad5023 100644
--- a/src/hid/gtk/gui-top-window.c
+++ b/src/hid/gtk/gui-top-window.c
@@ -1,10 +1,8 @@
-/* $Id$ */
-
 /*
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996 Thomas Nau
+ *  Copyright (C) 1994,1995,1996,2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -127,8 +125,6 @@ a zoom in/out.
 #include <dmalloc.h>
 #endif
 
-RCSID ("$Id$");
-
 /* ---------------------------------------------------------------------------
  * local types
  */
@@ -2745,15 +2741,10 @@ LayersChanged (int argc, char **argv, int px, int py)
     return 0;
 
   ghid_config_groups_changed();
+  ghid_layer_buttons_color_update ();
   ghid_layer_buttons_update ();
   ghid_show_layer_buttons();
 
-  /* FIXME - if a layer is moved it should retain its color.  But layers
-  |  currently can't do that because color info is not saved in the
-  |  pcb file.  So this makes a moved layer change its color to reflect
-  |  the way it will be when the pcb is reloaded.
-  */
-  pcb_colors_from_settings (PCB);
   return 0;
 }
 
diff --git a/src/hid/lesstif/menu.c b/src/hid/lesstif/menu.c
index d3e421d..1578460 100644
--- a/src/hid/lesstif/menu.c
+++ b/src/hid/lesstif/menu.c
@@ -303,6 +303,7 @@ LayersChanged (int argc, char **argv, int x, int y)
     }
 
   lesstif_update_layer_groups ();
+  lesstif_invalidate_all ();
 
   return 0;
 }
diff --git a/src/move.c b/src/move.c
index 003c2e0..52858ff 100644
--- a/src/move.c
+++ b/src/move.c
@@ -1,10 +1,8 @@
-/* $Id$ */
-
 /*
  *                            COPYRIGHT
  *
  *  PCB, interactive printed circuit board design
- *  Copyright (C) 1994,1995,1996 Thomas Nau
+ *  Copyright (C) 1994,1995,1996,2009 Thomas Nau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -18,7 +16,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *  Contact addresses for paper mail and Email:
  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
@@ -58,11 +56,6 @@
 #include <dmalloc.h>
 #endif
 
-RCSID ("$Id$");
-
-
-
-
 /* ---------------------------------------------------------------------------
  * some local prototypes
  */
@@ -1022,6 +1015,8 @@ MoveLayer (int old_index, int new_index)
 		   (old_index - new_index) * sizeof (int));
 	}
       memcpy (&PCB->Data->Layer[new_index], &saved_layer, sizeof (LayerType));
+      Settings.LayerColor[old_index] = PCB->Data->Layer[old_index].Color;
+      Settings.LayerColor[new_index] = PCB->Data->Layer[new_index].Color;
       groups[new_index] = saved_group;
     }
 
diff --git a/src/parse_y.y b/src/parse_y.y
index 2aa7b0c..d377fe6 100644
--- a/src/parse_y.y
+++ b/src/parse_y.y
@@ -1,4 +1,3 @@
-/* $Id$ */
 /*
  * ************************** README *******************
  *
@@ -44,6 +43,7 @@
 
 #define GRIDFIT(x,g) (int)(0.5 + (int)(((x)+(g)/2.)/(g))*(g))
 #include "global.h"
+#include "attribute.h"
 #include "create.h"
 #include "data.h"
 #include "error.h"
@@ -61,8 +61,6 @@
 # include <dmalloc.h> /* see http://dmalloc.com */
 #endif
 
-RCSID("$Id$");
-
 static	LayerTypePtr	Layer;
 static	PolygonTypePtr	Polygon;
 static	SymbolTypePtr	Symbol;
@@ -157,6 +155,9 @@ parsepcb
 				yyData->pcb = (void *)yyPCB;
 				yyData->LayerN = 0;
 				layer_group_string = NULL;
+				/* don't introduce backward
+				   incompatibility by default */
+				Settings.preserve_layer_attributes = 0;
 			}
 		  pcbfileversion
 		  pcbname 
@@ -841,6 +842,15 @@ The contents of the layer, which may include attributes, lines, arcs, rectangles
 text, and polygons.
 @end table
 
+Currently, the next attributes are parsed in layer context:
+
+@table @var
+
+@item PCB:Color
+Color the layer should be normally displayed with.
+
+@end table
+
 %end-doc */
 
 layer
@@ -1870,6 +1880,8 @@ if the value is interpreted as, for example, a number.
 
 @end table
 
+Attributes which name begins with "PCB:" may be handled by PCB itself.
+
 %end-doc */
 
 attributes	: attribute
diff --git a/src/pcb-menu.res b/src/pcb-menu.res
index 5186183..15a3b95 100644
--- a/src/pcb-menu.res
+++ b/src/pcb-menu.res
@@ -202,6 +202,7 @@ MainMenu =
    {"Thin draw" checked=thindraw Display(ToggleThindraw) a={"|" "<Key>|"}}
    {"Thin draw poly" checked=thindrawpoly Display(ToggleThindrawPoly) a={"Ctrl-Shift-P" "Ctrl Shift<Key>p"}}
    {"Check polygons" checked=checkplanes Display(ToggleCheckPlanes)}
+   {"Preserve layer attributes" checked=preserve_layer_attributes PreserveLayerAttributes(toggle)}
    -
    {"Pinout shows number" checked=shownumber Display(ToggleName)}
    {"Pins/Via show Name/Number" Display(PinOrPadName) a={"D" "<Key>d"}}
-- 
1.6.4.1


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user