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

Re: gEDA-user: pcb flip-sides



On 10/29/09, DJ Delorie <dj@xxxxxxxxxxx> wrote:
>> <offtopic>
>> To be exact, the Ben mode of png exporter, which is
>> somewhat confusing IMVHO (why not in both modes?
>> and what is --as-shown for, then?)
>> </offtopic>
>
> Go ahead and fix it :-)

I did it this summer, when finishing Michael's board.

> --as-shown determines whether you use the layer stack as shown, or the
> layer stack as defined by the pcb.  It's a "what's on top" setup.
>
>> With my short-sighted mind I think I'd rather make
>> --action-string "SwapSides" a legal option
>> (currently, it segfaults with both GTK and Lesstif GUIs);
>
> Because it's defined *in* lesstif and gtk, so they expect you'll only
> call that for the gui.

I run
pcb --action-string "SwapSides(V)" random.pcb
and get a segfault. to my mind (well-known for it's stupidity),
I call that for the GUI, I want her to start with showing me the other side.

>   It won't do what you want now.

I'm glad we agree on this point.

>> or (less intrusive and less elegant) add an action which would work
>> for this particular case;
>
> I object to adding things "for this particular case" without
> considering future expansion or flexibility.  Adding something that
> selects a top side, without considering arbitrary rotation and/or 3-D
> view, is shortsighted.
[snip]
>
> ShowSolderSide is special because it determines which smt pads are
> drawn at which times, and which mask is drawn.  It doesn't control the
> orientation of the board at all; that's done in the HID.

+1

There is the ShowSolderSide flag; I suggest extending
the possibilities to change it:

(1) make SwapSides tolerant to --action-string option,
    both the Lesstif and GTK versions
(0003-generalise-GTK-and-Lesstif-SwapSides-actions.patch)

With the first patch suggested by Kai-Martin, this shall
solve his second issue (can't swap sides with -x option),
also, we'll be able e.g. to load the board starting
from the other side.

(2) add SwapSides action to batch GUI
(0001-add-SwapSides-action-to-batch-HID.patch)
  or
    add a generic FlipBoard action which will run
    SwapSides(V) and invoke a generic sequence if
    it doesn't change ShowSolderSide (probably,
    because SwapSides is absent)
(0005-add-FlipBoard-action.patch)

This step makes the feature available with batch GUI,
either patch is enough for this, though they
are orthogonal and may be used together.

However, none of these patches is touching
HID structure, sorry.

Best regards,
Ineiev
From 435ab845a70ccb83d99272948a5dd23a2838be84 Mon Sep 17 00:00:00 2001
From: Ineiev <ineiev@xxxxxxxxxxxxxxxx>
Date: Sun, 21 Jun 2009 07:01:00 +0000
Subject: [PATCH 1/5] add SwapSides action to batch HID

---
 src/hid/batch/batch.c |   87 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 83 insertions(+), 4 deletions(-)

diff --git a/src/hid/batch/batch.c b/src/hid/batch/batch.c
index cc09564..9bc968d 100644
--- a/src/hid/batch/batch.c
+++ b/src/hid/batch/batch.c
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -12,13 +10,12 @@
 #include "global.h"
 #include "hid.h"
 #include "data.h"
+#include "misc.h"
 
 #ifdef HAVE_LIBDMALLOC
 #include <dmalloc.h>
 #endif
 
-RCSID ("$Id$");
-
 /* This is a text-line "batch" HID, which exists for scripting and
    non-GUI needs.  */
 
@@ -96,6 +93,86 @@ info (int argc, char **argv, int x, int y)
   return 0;
 }
 
+/* ---------------------------------------------------------------------- */
+static const char swapsides_syntax[] =
+"SwapSides(|v|h|r)";
+
+static const char swapsides_help[] =
+"Swaps the side of the board you're looking at.";
+
+/* %start-doc actions SwapSides
+
+This action shows the opposite side of the board.
+
+Normally, this action changes which pads and silk layer are drawn as
+true silk, and which are drawn as the "invisible" layer.  It also
+determines which solder mask you see.
+
+As a special case, if the layer group for the side you're looking at
+is visible and currently active, and the layer group for the opposite
+is not visible (i.e. disabled), then this action will also swap which
+layer group is visible and active, effectively swapping the ``working
+side'' of the board.
+
+%end-doc */
+
+
+static int
+SwapSides (int argc, char **argv, int x, int y)
+{
+  int comp_group = GetLayerGroupNumberByNumber (max_layer + COMPONENT_LAYER);
+  int solder_group = GetLayerGroupNumberByNumber (max_layer + SOLDER_LAYER);
+  int active_group = GetLayerGroupNumberByNumber (LayerStack[0]);
+  int comp_showing =
+    PCB->Data->Layer[PCB->LayerGroups.Entries[comp_group][0]].On;
+  int solder_showing =
+    PCB->Data->Layer[PCB->LayerGroups.Entries[solder_group][0]].On;
+
+
+  if (argc > 0)
+    {
+     /* basic arguments handling for compatibility with GTK and Lesstif HIDs */
+      switch (argv[0][0]) {
+      case 'h':
+      case 'H':
+	break;
+      case 'v':
+      case 'V':
+	break;
+      case 'r':
+      case 'R':
+	break;
+      default:
+	return 1;
+      }
+    }
+
+  Settings.ShowSolderSide = !Settings.ShowSolderSide;
+  if (Settings.ShowSolderSide)
+    {
+      if (active_group == comp_group && comp_showing && !solder_showing)
+	{
+	  if (comp_showing && !solder_showing)
+	    ChangeGroupVisibility (PCB->LayerGroups.Entries[comp_group][0], 0,
+				   0);
+	  ChangeGroupVisibility (PCB->LayerGroups.Entries[solder_group][0], 1,
+				 1);
+	}
+    }
+  else
+    {
+      if (active_group == solder_group)
+	{
+	  if (solder_showing && !comp_showing)
+	    ChangeGroupVisibility (PCB->LayerGroups.Entries[solder_group][0], 0,
+				   0);
+	  ChangeGroupVisibility (PCB->LayerGroups.Entries[comp_group][0], 1,
+				 1);
+	}
+    }
+
+  return 0;
+}
 
 HID_Action batch_action_list[] = {
   {"PCBChanged", 0, PCBChanged },
@@ -105,6 +182,8 @@ HID_Action batch_action_list[] = {
   {"LibraryChanged", 0, nop },
   {"Busy", 0, nop },
   {"Help", 0, help },
+  {"SwapSides", 0, SwapSides,
+   swapsides_help, swapsides_syntax},
   {"Info", 0, info }
 };
 
-- 
1.6.4.1

From c2d0be4c2da534c548bf914a3fe316af031ab25c Mon Sep 17 00:00:00 2001
From: Ineiev <ineiev@xxxxxxxxxxxxxxxx>
Date: Thu, 29 Oct 2009 08:38:28 +0300
Subject: [PATCH 3/5] generalise GTK and Lesstif SwapSides actions

The actions were written for using with
GUI initialised; the patch extends them
to use in command line via --action-string
and --action-script options
---
 src/hid/gtk/gtkhid-main.c |    2 ++
 src/hid/lesstif/main.c    |   32 +++++++++++++++++---------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c
index cbdd104..5472f10 100644
--- a/src/hid/gtk/gtkhid-main.c
+++ b/src/hid/gtk/gtkhid-main.c
@@ -2013,6 +2013,8 @@ SwapSides (int argc, char **argv, int x, int y)
 				 1);
 	}
     }
+  if (!ghidgui || !gport->drawing_area)
+    return 0;
 
   /* Update coordinates so that the current location stays where it was on the
      other side; we need to do this since the actual flip center is the
diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c
index 370d816..f7525f7 100644
--- a/src/hid/lesstif/main.c
+++ b/src/hid/lesstif/main.c
@@ -573,21 +573,22 @@ SwapSides (int argc, char **argv, int x, int y)
       /* SwapSides will swap this */
       Settings.ShowSolderSide = (flip_x == flip_y);
     }
+  if (mainwind)
+    {
+      n = 0;
+      if (flip_x)
+	stdarg (XmNprocessingDirection, XmMAX_ON_LEFT);
+      else
+	stdarg (XmNprocessingDirection, XmMAX_ON_RIGHT);
+      XtSetValues (hscroll, args, n);
 
-  n = 0;
-  if (flip_x)
-    stdarg (XmNprocessingDirection, XmMAX_ON_LEFT);
-  else
-    stdarg (XmNprocessingDirection, XmMAX_ON_RIGHT);
-  XtSetValues (hscroll, args, n);
-
-  n = 0;
-  if (flip_y)
-    stdarg (XmNprocessingDirection, XmMAX_ON_TOP);
-  else
-    stdarg (XmNprocessingDirection, XmMAX_ON_BOTTOM);
-  XtSetValues (vscroll, args, n);
-
+      n = 0;
+      if (flip_y)
+	stdarg (XmNprocessingDirection, XmMAX_ON_TOP);
+      else
+	stdarg (XmNprocessingDirection, XmMAX_ON_BOTTOM);
+      XtSetValues (vscroll, args, n);
+    }
   Settings.ShowSolderSide = !Settings.ShowSolderSide;
 
   /* The idea is that if we're looking at the front side and the front
@@ -620,7 +621,8 @@ SwapSides (int argc, char **argv, int x, int y)
 	    }
 	}
     }
-  lesstif_invalidate_all ();
+  if (mainwind)
+    lesstif_invalidate_all ();
   return 0;
 }
 
-- 
1.6.4.1

From a7be646c8c699aae01d95b0aabde55a8f5b3f6e3 Mon Sep 17 00:00:00 2001
From: Ineiev <ineiev@xxxxxxxxxxxxxxxx>
Date: Tue, 27 Oct 2009 03:05:47 +0000
Subject: [PATCH 5/5] add FlipBoard action

the action generically changes the side
the HIDs are showing.
---
 src/action.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/src/action.c b/src/action.c
index 6b979d3..15c37a4 100644
--- a/src/action.c
+++ b/src/action.c
@@ -6793,6 +6793,80 @@ ActionPSCalib (int argc, char **argv, int x, int y)
   return 0;
 }
 
+/* ---------------------------------------------------------------------- */
+static const char flipboard_syntax[] =
+"FlipBoard()";
+
+static const char flipboard_help[] =
+"Generically change the side of the board HIDs are showing.";
+
+/* %start-doc actions FlipBoard
+
+This action changes generically the side of the board
+the HIDs, including the GUI and exporters, are showing.
+
+Normally, this action changes which pads and silk layer are drawn as
+true silk, and which are drawn as the "invisible" layer.  It also
+determines which solder mask you see.
+
+As a special case, if the layer group for the side you're looking at
+is visible and currently active, and the layer group for the opposite
+is not visible (i.e. disabled), then this action will also swap which
+layer group is visible and active, effectively swapping the ``working
+side'' of the board.
+
+%end-doc */
+
+static void
+flip_board_generic (void)
+{
+  int comp_group = GetLayerGroupNumberByNumber (max_layer + COMPONENT_LAYER);
+  int solder_group = GetLayerGroupNumberByNumber (max_layer + SOLDER_LAYER);
+  int active_group = GetLayerGroupNumberByNumber (LayerStack[0]);
+  int comp_showing =
+    PCB->Data->Layer[PCB->LayerGroups.Entries[comp_group][0]].On;
+  int solder_showing =
+    PCB->Data->Layer[PCB->LayerGroups.Entries[solder_group][0]].On;
+
+  Settings.ShowSolderSide = !Settings.ShowSolderSide;
+  if (Settings.ShowSolderSide)
+    {
+      if (active_group == comp_group)
+	{
+	  if (comp_showing && !solder_showing)
+	    ChangeGroupVisibility (PCB->LayerGroups.Entries[comp_group][0], 0,
+				   0);
+	  ChangeGroupVisibility (PCB->LayerGroups.Entries[solder_group][0], 1,
+				 1);
+	}
+    }
+  else
+    {
+      if (active_group == solder_group)
+	{
+	  if (solder_showing && !solder_showing)
+	    ChangeGroupVisibility (PCB->LayerGroups.Entries[solder_group][0], 0,
+				   0);
+	  ChangeGroupVisibility (PCB->LayerGroups.Entries[comp_group][0], 1,
+				 1);
+	}
+    }
+}
+
+static int
+ActionFlipBoard (int argc, char **argv, int x, int y)
+{
+  int show_solder_side = Settings.ShowSolderSide;
+
+  hid_actionl ("SwapSides", "V", NULL);
+
+  /* test if we either have no SwapSides action, like in batch GUI,
+     or the action does not handle Settings.ShowSolderSide */
+  if (show_solder_side != Settings.ShowSolderSide)
+    flip_board_generic ();
+  return 0;
+}
+
 /* --------------------------------------------------------------------------- */
 
 HID_Action action_action_list[] = {
@@ -6871,6 +6945,9 @@ HID_Action action_action_list[] = {
   {"Flip", "Click on Object or Flip Point", ActionFlip,
    flip_help, flip_syntax}
   ,
+  {"FlipBoard", 0, ActionFlipBoard,
+   flipboard_help, flipboard_syntax}
+  ,
   {"LoadFrom", 0, ActionLoadFrom,
    loadfrom_help, loadfrom_syntax}
   ,
-- 
1.6.4.1


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