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

gEDA-cvs: pcb.git: branch: master updated (419971a4139205e6c3b6cc255b37d7124ae3165b)



The branch, master has been updated
       via  419971a4139205e6c3b6cc255b37d7124ae3165b (commit)
       via  2b050ab4807e047ac3b4d09ebdd201663b723cea (commit)
      from  88b7775b936512f3c6310fab9b7f08694e638ab4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 src/hid/gtk/gtk-pcb-layer-selector.c |  122 +++++++++++++++++++++++++++++-----
 src/hid/gtk/gtk-pcb-layer-selector.h |    2 +
 src/hid/gtk/gui-top-window.c         |   32 ++++++++-
 3 files changed, 137 insertions(+), 19 deletions(-)


=================
 Commit Messages
=================

commit 419971a4139205e6c3b6cc255b37d7124ae3165b
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    gtk: Sync selection with pcb state in ghid_layer_buttons_update
    
    It was possible for PCB's active layer to come out of sync with
    the selected entry in the layer selector. This fixes that.

:100644 100644 e036ef5... f8674e6... M	src/hid/gtk/gui-top-window.c

commit 2b050ab4807e047ac3b4d09ebdd201663b723cea
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    Support adding/deletion of layers in GtkPcbLayerSelector
    
    If you add a layer to a GtkPcbLayerSelector, and its ID is already
    in the selector, it will update the layer instead of adding a new
    one. This way, we can update the layer selector by:
    
      1. Deleting all recently-deleted and non-copper layers.
      2. Re-adding all layers (including new ones)
      3. Re-adding all non-copper layers (so they go to the end)
    
    The old layer selector maintained MAX_LAYER + n layers (where n was
    the number of non-copper layers), and showed/hid the gui widget to
    managed deletion and adding of layers. The new one has no notion of
    MAX_LAYER, nor does it care whether a layer is copper or not. :)

:100644 100644 b2b30e5... 897cd2c... M	src/hid/gtk/gtk-pcb-layer-selector.c
:100644 100644 0773497... 27b0de9... M	src/hid/gtk/gtk-pcb-layer-selector.h
:100644 100644 8dc10b7... e036ef5... M	src/hid/gtk/gui-top-window.c

=========
 Changes
=========

commit 419971a4139205e6c3b6cc255b37d7124ae3165b
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    gtk: Sync selection with pcb state in ghid_layer_buttons_update
    
    It was possible for PCB's active layer to come out of sync with
    the selected entry in the layer selector. This fixes that.

diff --git a/src/hid/gtk/gui-top-window.c b/src/hid/gtk/gui-top-window.c
index e036ef5..f8674e6 100644
--- a/src/hid/gtk/gui-top-window.c
+++ b/src/hid/gtk/gui-top-window.c
@@ -1072,11 +1072,24 @@ get_layer_delete (gint layer)
 void
 ghid_layer_buttons_update (void)
 {
+  gint layer;
+
   gtk_pcb_layer_selector_delete_layers
     (GTK_PCB_LAYER_SELECTOR (ghidgui->layer_selector),
      get_layer_delete);
   make_layer_buttons (ghidgui->layer_selector);
   make_virtual_layer_buttons (ghidgui->layer_selector);
+
+  /* Sync selected layer with PCB's state */
+  if (PCB->RatDraw)
+    layer = LAYER_BUTTON_RATS;
+  else if (PCB->SilkActive)
+    layer = LAYER_BUTTON_SILK;
+  else
+    layer = LayerStack[0];
+
+  gtk_pcb_layer_selector_select_layer
+    (GTK_PCB_LAYER_SELECTOR (ghidgui->layer_selector), layer);
 }
 
 

commit 2b050ab4807e047ac3b4d09ebdd201663b723cea
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    Support adding/deletion of layers in GtkPcbLayerSelector
    
    If you add a layer to a GtkPcbLayerSelector, and its ID is already
    in the selector, it will update the layer instead of adding a new
    one. This way, we can update the layer selector by:
    
      1. Deleting all recently-deleted and non-copper layers.
      2. Re-adding all layers (including new ones)
      3. Re-adding all non-copper layers (so they go to the end)
    
    The old layer selector maintained MAX_LAYER + n layers (where n was
    the number of non-copper layers), and showed/hid the gui widget to
    managed deletion and adding of layers. The new one has no notion of
    MAX_LAYER, nor does it care whether a layer is copper or not. :)

diff --git a/src/hid/gtk/gtk-pcb-layer-selector.c b/src/hid/gtk/gtk-pcb-layer-selector.c
index b2b30e5..897cd2c 100644
--- a/src/hid/gtk/gtk-pcb-layer-selector.c
+++ b/src/hid/gtk/gtk-pcb-layer-selector.c
@@ -348,6 +348,9 @@ gtk_pcb_layer_selector_new (void)
  *  menus (assuming this is a selectable layer). For the first 20 layers,
  *  keyboard accelerators will be added for selection/visibility toggling.
  *
+ *  If the user_id passed already exists in the layer selector, that layer
+ *  will have its data overwritten with the new stuff.
+ *
  *  \param [in] ls            The selector to be acted on
  *  \param [in] user_id       An ID used to identify the layer; will be passed to selection/visibility callbacks
  *  \param [in] name          The name of the layer; will be used on selector and menus
@@ -364,27 +367,68 @@ gtk_pcb_layer_selector_add_layer (GtkPcbLayerSelector *ls,
                                   gboolean activatable)
 {
   gchar *pname, *vname, *paccel, *vaccel;
+  gboolean new_iter = TRUE;
+  gboolean last_activatable = TRUE;
   GtkTreePath *path;
   GtkTreeIter iter;
 
-  if (activatable != ls->last_activatable)
+  /* Look for existing layer with this ID */
+  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls->list_store), &iter))
+    do
+      {
+        gboolean is_sep, active;
+        gint read_id;
+        gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
+                            &iter, USER_ID_COL, &read_id,
+                            SEPARATOR_COL, &is_sep,
+                            ACTIVATABLE_COL, &active, -1);
+        if (!is_sep)
+          {
+            last_activatable = active;
+            if(read_id == user_id)
+              {
+                new_iter = FALSE;
+                break;
+              }
+          }
+      }
+    while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ls->list_store), &iter));
+
+  /* Handle separator addition */
+  if (new_iter)
     {
-      /* Add separator between activatable/non-activatable boundaries */
+      if (activatable != last_activatable)
+        {
+          /* Add separator between activatable/non-activatable boundaries */
+          gtk_list_store_append (ls->list_store, &iter);
+          gtk_list_store_set (ls->list_store, &iter,
+                              SEPARATOR_COL, TRUE, -1);
+        }
+      /* Create new layer */
       gtk_list_store_append (ls->list_store, &iter);
-      gtk_list_store_set (ls->list_store, &iter, SEPARATOR_COL, TRUE, -1);
+      gtk_list_store_set (ls->list_store, &iter,
+                          INDEX_COL, ls->n_actions,
+                          USER_ID_COL, user_id,
+                          VISIBLE_COL, visible,
+                          COLOR_COL, color_string,
+                          TEXT_COL, name,
+                          FONT_COL, activatable ? NULL : "Italic",
+                          ACTIVATABLE_COL, activatable,
+                          SEPARATOR_COL, FALSE,
+                          -1);
     }
-
-  gtk_list_store_append (ls->list_store, &iter);
-  gtk_list_store_set (ls->list_store, &iter,
-                      INDEX_COL, ls->n_actions,
-                      USER_ID_COL, user_id,
-                      VISIBLE_COL, visible,
-                      COLOR_COL, color_string,
-                      TEXT_COL, name,
-                      FONT_COL, activatable ? NULL : "Italic",
-                      ACTIVATABLE_COL, activatable,
-                      SEPARATOR_COL, FALSE,
-                      -1);
+  else
+    gtk_list_store_set (ls->list_store, &iter,
+                        VISIBLE_COL, visible,
+                        COLOR_COL, color_string,
+                        TEXT_COL, name,
+                        FONT_COL, activatable ? NULL : "Italic",
+                        ACTIVATABLE_COL, activatable,
+                        -1);
+
+  /* Unless we're adding new actions, we're done now */
+  if (!new_iter)
+    return;
 
   if (activatable && ls->n_actions == 0)
     gtk_tree_selection_select_iter (ls->selection, &iter);
@@ -477,7 +521,6 @@ gtk_pcb_layer_selector_add_layer (GtkPcbLayerSelector *ls,
   g_free (vname);
   g_free (pname);
 
-  ls->last_activatable = activatable;
   ls->n_actions++;
 }
 
@@ -708,4 +751,51 @@ gtk_pcb_layer_selector_update_colors (GtkPcbLayerSelector *ls,
   while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ls->list_store), &iter));
 }
 
+/*! \brief Deletes layers from a layer selector
+ *  \par Function Description
+ *  Deletes layers according to a callback function: a return value of TRUE
+ *  means delete, FALSE means leave it alone. Do not try to delete all layers
+ *  using this function; with nothing left to select, pcb will likely go into
+ *  an infinite recursion between hid_action() and g_signal().
+ *
+ *  Separators will be deleted if the layer AFTER them is deleted.
+ *
+ *  \param [in] ls       The selector to be acted on
+ *  \param [in] callback Takes the user_id of the layer and returns a boolean
+ */
+void
+gtk_pcb_layer_selector_delete_layers (GtkPcbLayerSelector *ls,
+                                      gboolean (*callback)(int user_id))
+{
+  GtkTreeIter iter, last_iter;
+  gboolean needs_inc;
+  gboolean was_separator = FALSE;
+  gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls->list_store), &iter);
+  do
+    {
+      gboolean sep;
+      gint user_id;
+      gtk_tree_model_get (GTK_TREE_MODEL (ls->list_store),
+                          &iter, USER_ID_COL, &user_id,
+                          SEPARATOR_COL, &sep, -1);
+      /* gtk_list_store_remove will increment the iter for us, so we
+       *  don't want to do it again in the loop condition */
+      needs_inc = TRUE;
+      if (!sep && callback (user_id))
+        {
+          if (gtk_list_store_remove (ls->list_store, &iter))
+            needs_inc = FALSE;
+          else
+            return;
+          if (was_separator)
+            gtk_list_store_remove (ls->list_store, &last_iter);
+        }
+      last_iter = iter;
+      was_separator = sep;
+    }
+  while (!needs_inc ||
+         gtk_tree_model_iter_next (GTK_TREE_MODEL (ls->list_store), &iter));
+}
+
+
 
diff --git a/src/hid/gtk/gtk-pcb-layer-selector.h b/src/hid/gtk/gtk-pcb-layer-selector.h
index 0773497..27b0de9 100644
--- a/src/hid/gtk/gtk-pcb-layer-selector.h
+++ b/src/hid/gtk/gtk-pcb-layer-selector.h
@@ -38,6 +38,8 @@ gboolean gtk_pcb_layer_selector_select_next_visible (GtkPcbLayerSelector *ls);
 void gtk_pcb_layer_selector_make_selected_visible (GtkPcbLayerSelector *ls);
 void gtk_pcb_layer_selector_update_colors (GtkPcbLayerSelector *ls,
                                            const gchar *(*callback)(int user_id));
+void gtk_pcb_layer_selector_delete_layers (GtkPcbLayerSelector *ls,
+                                           gboolean (*callback)(int user_id));
 
 G_END_DECLS  /* keep c++ happy */
 #endif
diff --git a/src/hid/gtk/gui-top-window.c b/src/hid/gtk/gui-top-window.c
index 8dc10b7..e036ef5 100644
--- a/src/hid/gtk/gui-top-window.c
+++ b/src/hid/gtk/gui-top-window.c
@@ -994,8 +994,9 @@ make_cursor_position_labels (GtkWidget * hbox, GHidPort * port)
 
 /* \brief Add "virtual layers" to a layer selector */
 static void
-make_virtual_layer_buttons (GtkPcbLayerSelector *layersel)
+make_virtual_layer_buttons (GtkWidget *layer_selector)
 {
+  GtkPcbLayerSelector *layersel = GTK_PCB_LAYER_SELECTOR (layer_selector);
   gchar *text;
   gchar *color_string;
   gboolean active;
@@ -1046,7 +1047,6 @@ make_layer_buttons (GtkWidget *layersel)
   gchar *text;
   gchar *color_string;
   gboolean active = TRUE;
-  ghidgui->layer_selector = layersel;
 
   for (i = 0; i < max_copper_layer; ++i)
     {
@@ -1054,7 +1054,14 @@ make_layer_buttons (GtkWidget *layersel)
       gtk_pcb_layer_selector_add_layer (GTK_PCB_LAYER_SELECTOR (layersel), i,
                                         text, color_string, active, TRUE);
     }
-  make_virtual_layer_buttons (GTK_PCB_LAYER_SELECTOR (layersel));
+}
+
+
+/*! \brief callback for gtk_pcb_layer_selector_delete_layers */
+gboolean
+get_layer_delete (gint layer)
+{
+  return layer >= max_copper_layer;
 }
 
 /*! \brief Synchronize layer selector widget with current PCB state
@@ -1065,6 +1072,11 @@ make_layer_buttons (GtkWidget *layersel)
 void
 ghid_layer_buttons_update (void)
 {
+  gtk_pcb_layer_selector_delete_layers
+    (GTK_PCB_LAYER_SELECTOR (ghidgui->layer_selector),
+     get_layer_delete);
+  make_layer_buttons (ghidgui->layer_selector);
+  make_virtual_layer_buttons (ghidgui->layer_selector);
 }
 
 
@@ -1462,6 +1474,7 @@ ghid_build_pcb_top_window (void)
   /* Build layer menus */
   ghidgui->layer_selector = gtk_pcb_layer_selector_new ();
   make_layer_buttons (ghidgui->layer_selector);
+  make_virtual_layer_buttons (ghidgui->layer_selector);
   g_signal_connect (G_OBJECT (ghidgui->layer_selector), "select_layer",
                     G_CALLBACK (layer_selector_select_callback),
                     NULL);




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