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

Re: gEDA-user: This patch is breaking compile



Hello,

as you can see, some of the patches failed to get applied. The reason for this are some changes in git head (the nanometer-conversion). I have worked to get this fixed yesterday but did not fully complete. You can try to modify the patches from Markus by yourself or wait until I have finished this task, but this will need some days, perhaps even weeks. I have attached the patches I have modified until now. As said before, this work is not completed!

Kind regards,
Felix

Am 22.08.2011 20:11, schrieb kqt4at5v@xxxxxxxxxxx:
On Fri, 19 Aug 2011, Markus Hitter wrote:


Am 15.08.2011 um 22:37 schrieb kqt4at5v@xxxxxxxxxxx:

I was especially interested in the drillmill function but I have not been able to get that to work
I check the box and only get plain drilling

Did you look into the "outline" G-code file? As drill-milling and outline milling often uses the same tool, I've put the drill-mills there.


A fresh 'git pull' broke this patch again

###### 0001-HID-gcode-let-the-system-library-allocate-the-tempor.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 314 (offset 10 lines).
Hunk #3 succeeded at 440 (offset -2 lines).


###### 0002-HID-gcode-make-use-of-MAXPATHLEN.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 448 (offset -2 lines).


###### 0003-HID-gcode-get-rid-of-tabulators-in-gcode.c.-Pure-whi.patch

patching file src/hid/gcode/gcode.c
Hunk #5 succeeded at 252 (offset 10 lines).
Hunk #6 succeeded at 277 (offset 10 lines).
Hunk #7 succeeded at 380 (offset 11 lines).
Hunk #8 succeeded at 397 (offset 11 lines).
Hunk #9 FAILED at 405.
Hunk #10 succeeded at 429 (offset -2 lines).
Hunk #11 succeeded at 735 (offset -2 lines).
Hunk #12 succeeded at 748 (offset -2 lines).
Hunk #13 succeeded at 805 (offset -2 lines).
Hunk #14 succeeded at 839 (offset -2 lines).
Hunk #15 succeeded at 853 (offset -2 lines).
Hunk #16 FAILED at 876.
Hunk #17 succeeded at 909 (offset -10 lines).
Hunk #18 succeeded at 931 (offset -10 lines).
2 out of 18 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0004-HID-gcode-create-better-file-names.patch

patching file src/hid/gcode/gcode.c
Hunk #1 FAILED at 116.
Hunk #4 succeeded at 278 (offset 10 lines).
Hunk #5 succeeded at 430 (offset 11 lines).
Hunk #6 succeeded at 494 (offset -2 lines).
Hunk #7 succeeded at 562 (offset -2 lines).
1 out of 7 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0005-HID-gcode-add-a-flag-wether-to-produce-advanced-G-co.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 177 with fuzz 1.
Hunk #3 succeeded at 424 (offset 11 lines).
Hunk #4 succeeded at 458 (offset -2 lines).
Hunk #5 succeeded at 547 (offset -2 lines).
Hunk #6 succeeded at 566 (offset -2 lines).
Hunk #7 succeeded at 607 (offset -2 lines).
patching file src/hid/gcode/trace.c
patching file src/hid/gcode/trace.h


###### 0006-HID-gcode-Avoid-more-than-one-G-or-M-code-per-line-f.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 553 (offset -2 lines).
Hunk #2 succeeded at 586 (offset -2 lines).
Hunk #3 succeeded at 622 (offset -2 lines).
Hunk #4 succeeded at 654 (offset -2 lines).


###### 0007-HID-gcode-switch-from-tool-radius-to-tool-diameter-i.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 457 (offset -2 lines).


###### 0008-HID-gcode-add-a-comment-about-the-tool-diameter-into.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 542 (offset -2 lines).


###### 0009-HID-gcode-simplify-code-a-bit.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 639 (offset -2 lines).


###### 0010-HID-gcode-use-drill-cycles-only-for-advanced-G-code.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 636 (offset -2 lines).
Hunk #3 succeeded at 651 (offset -2 lines).


###### 0011-HID-gcode-postpone-closing-the-mill-file-until-the-d.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 396.
Hunk #3 succeeded at 576 (offset -2 lines).
Hunk #4 succeeded at 644 (offset -2 lines).
1 out of 4 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0012-HID-gcode-finally-add-predrilling.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 171.
Hunk #3 succeeded at 455 with fuzz 2 (offset -2 lines).
Hunk #4 succeeded at 595 (offset -2 lines).
Hunk #5 succeeded at 647 (offset -2 lines).
Hunk #6 succeeded at 669 (offset -2 lines).
1 out of 6 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0013-HID-gcode-enhance-accuracy-of-the-distance-report-fo.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 592 (offset -8 lines).
Hunk #2 succeeded at 676 (offset -8 lines).
Hunk #3 succeeded at 693 (offset -8 lines).


###### 0014-HID-gcode-remove-a-leftover-debug-printf.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 485 (offset -8 lines).


###### 0015-HID-gcode-provide-info-about-drill-diameters-in-G-co.patch

patching file src/hid/gcode/gcode.c
Hunk #3 succeeded at 595 (offset -8 lines).
Hunk #4 succeeded at 641 (offset -8 lines).
Hunk #5 succeeded at 661 (offset -8 lines).
Hunk #6 succeeded at 1062 (offset -16 lines).


###### 0016-HID-gcode-sort-drills-not-only-by-distance-but-also-.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 226 (offset -6 lines).
Hunk #2 succeeded at 259 (offset -6 lines).
Hunk #3 succeeded at 613 (offset -8 lines).


###### 0017-HID-gcode-report-one-drill-diameter-only-once-in-the.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 677 (offset -8 lines).


###### 0018-HID-gcode-don-t-do-isolation-milling-on-the-outline-.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 325 (offset 4 lines).
Hunk #2 succeeded at 728 (offset -8 lines).


###### 0019-HID-gcode-fetch-the-board-s-extents-from-the-outline.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 206 (offset -6 lines).
Hunk #3 succeeded at 526 (offset -8 lines).
Hunk #4 succeeded at 613 (offset -8 lines).
Hunk #5 succeeded at 686 (offset -8 lines).


###### 0020-HID-gcode-limit-the-produced-G-code-to-the-outline.patch

patching file src/hid/gcode/gcode.c
Hunk #1 succeeded at 415 (offset 4 lines).
Hunk #2 succeeded at 445 (offset 4 lines).
Hunk #3 succeeded at 1034 (offset -8 lines).
Hunk #4 succeeded at 1049 (offset -8 lines).
Hunk #5 FAILED at 1078.
Hunk #6 succeeded at 1114 (offset -16 lines).
Hunk #7 succeeded at 1129 (offset -16 lines).
Hunk #8 succeeded at 1145 (offset -16 lines).
Hunk #9 succeeded at 1168 (offset -16 lines).
1 out of 9 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0021-HID-gcode-reorder-user-interface-to-a-more-logical-s.patch

patching file src/hid/gcode/gcode.c
Hunk #1 FAILED at 160.
1 out of 1 hunk FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0022-HID-gcode-create-G-code-for-milling-the-outline-of-t.patch

patching file src/hid/gcode/gcode.c
Hunk #3 FAILED at 193.
Hunk #4 succeeded at 489 (offset 6 lines).
Hunk #5 succeeded at 523 (offset -7 lines).
Hunk #6 succeeded at 836 (offset -7 lines).
1 out of 6 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0023-HID-gcode-move-all-the-code-common-on-file-open-into.patch

patching file src/hid/gcode/gcode.c
Hunk #2 succeeded at 278 (offset -15 lines).
Hunk #3 FAILED at 506.
Hunk #4 FAILED at 552.
Hunk #5 succeeded at 580 (offset -17 lines).
Hunk #6 succeeded at 592 (offset -17 lines).
Hunk #7 succeeded at 622 (offset -17 lines).
Hunk #8 succeeded at 641 (offset -17 lines).
Hunk #9 succeeded at 653 (offset -17 lines).
Hunk #10 succeeded at 668 (offset -17 lines).
Hunk #11 succeeded at 686 (offset -17 lines).
Hunk #12 succeeded at 695 (offset -17 lines).
Hunk #13 succeeded at 712 (offset -17 lines).
Hunk #14 succeeded at 724 (offset -17 lines).
Hunk #15 succeeded at 758 (offset -17 lines).
Hunk #16 succeeded at 783 (offset -17 lines).
Hunk #17 succeeded at 803 (offset -17 lines).
Hunk #18 succeeded at 838 (offset -17 lines).
Hunk #19 succeeded at 869 (offset -17 lines).
2 out of 19 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0024-HID-gcode-refine-the-user-interface-regarding-accura.patch

patching file src/hid/gcode/gcode.c
Hunk #1 FAILED at 168.
Hunk #2 FAILED at 540.
2 out of 2 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0025-HID-gcode-add-user-defined-feedrates-for-isolation-m.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 187.
Hunk #3 succeeded at 524 (offset -3 lines).
Hunk #4 succeeded at 553 with fuzz 2 (offset -11 lines).
Hunk #5 succeeded at 572 (offset -11 lines).
Hunk #6 succeeded at 675 (offset -11 lines).
Hunk #7 succeeded at 700 (offset -11 lines).
Hunk #8 succeeded at 725 (offset -11 lines).
1 out of 8 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej
patching file src/hid/gcode/trace.c
patching file src/hid/gcode/trace.h


###### 0026-HID-gcode-add-user-defined-feedrates-for-drilling.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 207.
Hunk #3 succeeded at 558 with fuzz 2 (offset -20 lines).
Hunk #4 succeeded at 742 (offset -20 lines).
1 out of 4 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0027-HID-gcode-add-user-defined-feedrates-for-outline-mil.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 223.
Hunk #3 succeeded at 529 (offset -16 lines).
Hunk #4 succeeded at 568 (offset -24 lines).
Hunk #5 succeeded at 583 (offset -24 lines).
Hunk #6 succeeded at 594 (offset -24 lines).
Hunk #7 succeeded at 610 (offset -24 lines).
Hunk #8 succeeded at 889 (offset -24 lines).
1 out of 8 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


###### 0028-HID-gcode-implement-drill-milling.patch

patching file src/hid/gcode/gcode.c
Hunk #2 FAILED at 214.
Hunk #3 succeeded at 567 with fuzz 1 (offset -33 lines).
Hunk #4 succeeded at 769 (offset -33 lines).
Hunk #5 succeeded at 926 (offset -33 lines).
1 out of 5 hunks FAILED -- saving rejects to file src/hid/gcode/gcode.c.rej


Richard


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

From e022b9b24fdf46fee3bb74222af5641f4747a9d5 Mon Sep 17 00:00:00 2001
From: Markus Hitter <mah@xxxxxxxxxxx>
Date: Sun, 31 Oct 2010 22:22:27 +0100
Subject: HID-gcode: get rid of tabulators in gcode.c. Pure whitespace change.

Developers should decide wether to use tabs or not, but not mix both.
---
 src/hid/gcode/gcode.c |  604 +++++++++++++++++++++++++------------------------
 1 files changed, 304 insertions(+), 300 deletions(-)

diff --git a/src/hid/gcode/gcode.c b/src/hid/gcode/gcode.c
index af4a304..5dbff16 100644
--- a/src/hid/gcode/gcode.c
+++ b/src/hid/gcode/gcode.c
@@ -70,6 +70,7 @@
 #endif
 
 #define CRASH fprintf(stderr, "HID error: pcb called unimplemented GCODE function %s.\n", __FUNCTION__); abort()
+
 struct color_struct
 {
   /* the descriptor used by the gd library */
@@ -121,10 +122,10 @@ static char *gcode_basename = NULL;
 /* Horizontal DPI (grid points per inch) */
 static int gcode_dpi = -1;
 
-static double gcode_cutdepth = 0;	/* milling depth (inch) */
-static double gcode_drilldepth = 0;	/* drilling depth (inch) */
-static double gcode_safeZ = 100;	/* safe Z (inch) */
-static double gcode_toolradius = 0;	/* tool radius(inch) */
+static double gcode_cutdepth = 0;       /* milling depth (inch) */
+static double gcode_drilldepth = 0;     /* drilling depth (inch) */
+static double gcode_safeZ = 100;        /* safe Z (inch) */
+static double gcode_toolradius = 0;     /* tool radius(inch) */
 static int save_drill = 0;
 static int n_drill = 0;
 static int nmax_drill = 0;
@@ -202,17 +203,17 @@ sort_drill (struct drill_struct *drill, int n_drill)
       dmin = 1e20;
       imin = 0;
       for (i = 0; i < n_drill - j; i++)
-	{
-	  d =
-	    (drill[i].x - p.x) * (drill[i].x - p.x) + (drill[i].y -
-						       p.y) * (drill[i].y -
-							       p.y);
-	  if (d < dmin)
-	    {
-	      imin = i;
-	      dmin = d;
-	    }
-	}
+        {
+          d =
+            (drill[i].x - p.x) * (drill[i].x - p.x) + (drill[i].y -
+                                                       p.y) * (drill[i].y -
+                                                               p.y);
+          if (d < dmin)
+            {
+              imin = i;
+              dmin = d;
+            }
+        }
       /* printf("j=%d imin=%d dmin=%f p=(%f,%f)\n",j,imin,dmin,p.x,p.y); */
       temp[j] = drill[imin];
       drill[imin] = drill[n_drill - j - 1];
@@ -228,8 +229,8 @@ static void
 gcode_parse_arguments (int *argc, char ***argv)
 {
   hid_register_attributes (gcode_attribute_list,
-			   sizeof (gcode_attribute_list) /
-			   sizeof (gcode_attribute_list[0]));
+                           sizeof (gcode_attribute_list) /
+                           sizeof (gcode_attribute_list[0]));
   hid_parse_command_line (argc, argv);
 }
 
@@ -241,8 +242,8 @@ gcode_get_export_options (int *n)
   if (PCB)
     {
       derive_default_filename (PCB->Filename,
-			       &gcode_attribute_list[HA_basename],
-			       ".gcode", &last_made_filename);
+                               &gcode_attribute_list[HA_basename],
+                               ".gcode", &last_made_filename);
     }
   if (n)
     {
@@ -266,23 +267,23 @@ gcode_choose_groups ()
       layer = &PCB->Data->Layer[n];
 
       if (layer->LineN || layer->TextN || layer->ArcN || layer->PolygonN)
-	{
-	  /* layer isn't empty */
-
-	  /*
-	   * is this check necessary? It seems that special
-	   * layers have negative indexes?
-	   */
-
-	  if (SL_TYPE (n) == 0)
-	    {
-	      /* layer is a copper layer */
-	      m = GetLayerGroupNumberByNumber (n);
-
-	      /* the export layer */
-	      gcode_export_group[m] = 1;
-	    }
-	}
+        {
+          /* layer isn't empty */
+
+          /*
+           * is this check necessary? It seems that special
+           * layers have negative indexes?
+           */
+
+          if (SL_TYPE (n) == 0)
+            {
+              /* layer is a copper layer */
+              m = GetLayerGroupNumberByNumber (n);
+
+              /* the export layer */
+              gcode_export_group[m] = 1;
+            }
+        }
     }
 }
 
@@ -368,16 +369,16 @@ gcode_do_export (HID_Attr_Val * options)
   path_t *plist = NULL;
   potrace_bitmap_t *bm = NULL;
   potrace_param_t param_default = {
-    2,				/* turnsize */
-    POTRACE_TURNPOLICY_MINORITY,	/* turnpolicy */
-    1.0,			/* alphamax */
-    1,				/* opticurve */
-    0.2,			/* opttolerance */
+    2,                           /* turnsize */
+    POTRACE_TURNPOLICY_MINORITY, /* turnpolicy */
+    1.0,                         /* alphamax */
+    1,                           /* opticurve */
+    0.2,                         /* opttolerance */
     {
-     NULL,			/* callback function */
-     NULL,			/* callback data */
-     0.0, 1.0,			/* progress range  */
-     0.0,			/* granularity  */
+     NULL,                       /* callback function */
+     NULL,                       /* callback data */
+     0.0, 1.0,                   /* progress range  */
+     0.0,                        /* granularity  */
      },
   };
 
@@ -385,9 +386,9 @@ gcode_do_export (HID_Attr_Val * options)
     {
       gcode_get_export_options (0);
       for (i = 0; i < NUM_OPTIONS; i++)
-	{
-	  gcode_values[i] = gcode_attribute_list[i].default_val;
-	}
+        {
+          gcode_values[i] = gcode_attribute_list[i].default_val;
+        }
       options = gcode_values;
     }
   gcode_basename = options[HA_basename].str_value;
@@ -430,169 +431,173 @@ gcode_do_export (HID_Attr_Val * options)
   for (i = 0; i < MAX_LAYER; i++)
     {
       if (gcode_export_group[i])
-	{
-
-	  gcode_cur_group = i;
-
-	  /* magic */
-	  idx = (i >= 0 && i < max_group) ?
-	    PCB->LayerGroups.Entries[i][0] : i;
-	  printf ("idx=%d %s\n", idx, layer_type_to_file_name (idx, FNS_fixed));
-	  is_solder =
-	    (GetLayerGroupNumberByNumber (idx) ==
-	     GetLayerGroupNumberByNumber (solder_silk_layer)) ? 1 : 0;
-	  save_drill = is_solder;	/* save drills for one layer only */
-	  gcode_start_png ();
-	  hid_save_and_show_layer_ons (save_ons);
-	  gcode_start_png_export ();
-	  hid_restore_layer_ons (save_ons);
+        {
+
+          gcode_cur_group = i;
+
+          /* magic */
+          idx = (i >= 0 && i < max_group) ?
+            PCB->LayerGroups.Entries[i][0] : i;
+          printf ("idx=%d %s\n", idx, layer_type_to_file_name (idx, FNS_fixed));
+          is_solder =
+            (GetLayerGroupNumberByNumber (idx) ==
+             GetLayerGroupNumberByNumber (solder_silk_layer)) ? 1 : 0;
+          save_drill = is_solder;       /* save drills for one layer only */
+          gcode_start_png ();
+          hid_save_and_show_layer_ons (save_ons);
+          gcode_start_png_export ();
+          hid_restore_layer_ons (save_ons);
 
 /* ***************** gcode conversion *************************** */
 /* potrace uses a different kind of bitmap; for simplicity gcode_im is copied to this format */
-	  bm = bm_new (gdImageSX (gcode_im), gdImageSY (gcode_im));
-	  filename = (char *)malloc (MAXPATHLEN);
-	  plist = NULL;
-	  if (is_solder)
-	    {			/* only for back layer */
-	      gdImagePtr temp_im =
-		gdImageCreate (gdImageSX (gcode_im), gdImageSY (gcode_im));
-	      gdImageCopy (temp_im, gcode_im, 0, 0, 0, 0,
-			   gdImageSX (gcode_im), gdImageSY (gcode_im));
-	      for (r = 0; r < gdImageSX (gcode_im); r++)
-		{
-		  for (c = 0; c < gdImageSY (gcode_im); c++)
-		    {
-		      gdImageSetPixel (gcode_im, r, c,
-				       gdImageGetPixel (temp_im,
-							gdImageSX (gcode_im) -
-							1 - r, c));
-		    }
-		}
-	      gdImageDestroy (temp_im);
-	    }
-	  sprintf (filename, "%s.%s.cnc", gcode_basename,
-		   layer_type_to_file_name (idx, FNS_fixed));
-	  for (r = 0; r < gdImageSX (gcode_im); r++)
-	    {
-	      for (c = 0; c < gdImageSY (gcode_im); c++)
-		{
-		  v =
-		    gdImageGetPixel (gcode_im, r,
-				     gdImageSY (gcode_im) - 1 - c);
-		  p = (gcode_im->red[v] || gcode_im->green[v]
-		       || gcode_im->blue[v]) ? 0 : 0xFFFFFF;
-		  BM_PUT (bm, r, c, p);
-		}
-	    }
-	  gcode_f2 = fopen (filename, "wb");
-	  if (!gcode_f2)
-	    {
-	      perror (filename);
-	      return;
-	    }
-	  fprintf (gcode_f2, "(Created by G-code exporter)\n");
-	  t = time (NULL);
-	  sprintf (filename, "%s", ctime (&t));
-	  filename[strlen (filename) - 1] = 0;
-	  fprintf (gcode_f2, "( %s )\n", filename);
-	  fprintf (gcode_f2, "(%d dpi)\n", gcode_dpi);
-	  fprintf (gcode_f2, "(Unit: %s)\n", metric ? "mm" : "inch");
-	  if (metric)
-	    pcb_fprintf (gcode_f2, "(Board size: %.2mmx%.2mm mm)", PCB->MaxWidth, PCB->MaxHeight);
-	  else
-	    pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)", PCB->MaxWidth, PCB->MaxHeight);
-	  fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
-	  fprintf (gcode_f2, "#101=%f  (cutting depth)\n", gcode_cutdepth);
-	  fprintf (gcode_f2, "(---------------------------------)\n");
-	  fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
-		   metric ? 21 : 20, metric ? 25 : 1);
-	  fprintf (gcode_f2, "G0 Z#100\n");
-	  /* extract contour points from image */
-	  r = bm_to_pathlist (bm, &plist, &param_default);
-	  if (r)
-	    {
-	      fprintf (stderr, "ERROR: pathlist function failed\n");
-	      return;
-	    }
-	  /* generate best polygon and write vertices in g-code format */
-	  d =
-	    process_path (plist, &param_default, bm, gcode_f2,
-			  metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi);
-	  if (d < 0)
-	    {
-	      fprintf (stderr, "ERROR: path process function failed\n");
-	      return;
-	    }
-	  if (metric)
-	    fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n", d,
-		     d * 1 / 25.4);
-	  else
-	    fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
-		     25.4 * d, d);
-	  fprintf (gcode_f2, "M5 M9 M2\n");
-	  pathlist_free (plist);
-	  bm_free (bm);
-	  fclose (gcode_f2);
-	  if (save_drill)
-	    {
-	      d = 0;
-	      drill = sort_drill (drill, n_drill);
-	      sprintf (filename, "%s.drill.cnc", gcode_basename);
-	      gcode_f2 = fopen (filename, "wb");
-	      if (!gcode_f2)
-		{
-		  perror (filename);
-		  return;
-		}
-	      fprintf (gcode_f2, "(Created by G-code exporter)\n");
-	      fprintf (gcode_f2, "(drill file: %d drills)\n", n_drill);
-	      sprintf (filename, "%s", ctime (&t));
-	      filename[strlen (filename) - 1] = 0;
-	      fprintf (gcode_f2, "( %s )\n", filename);
-	      fprintf (gcode_f2, "(Unit: %s)\n", metric ? "mm" : "inch");
-	      if (metric)
-	        pcb_fprintf (gcode_f2, "(Board size: %.2mmx%.2mm mm)", PCB->MaxWidth, PCB->MaxHeight);
-	      else
-	        pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)", PCB->MaxWidth, PCB->MaxHeight);
-	      fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
-	      fprintf (gcode_f2, "#101=%f  (drill depth)\n",
-		       gcode_drilldepth);
-	      fprintf (gcode_f2, "(---------------------------------)\n");
-	      fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
-		       metric ? 21 : 20, metric ? 25 : 1);
+          bm = bm_new (gdImageSX (gcode_im), gdImageSY (gcode_im));
+          filename = (char *)malloc (MAXPATHLEN);
+          plist = NULL;
+          if (is_solder)
+            {                   /* only for back layer */
+              gdImagePtr temp_im =
+                gdImageCreate (gdImageSX (gcode_im), gdImageSY (gcode_im));
+              gdImageCopy (temp_im, gcode_im, 0, 0, 0, 0,
+                           gdImageSX (gcode_im), gdImageSY (gcode_im));
+              for (r = 0; r < gdImageSX (gcode_im); r++)
+                {
+                  for (c = 0; c < gdImageSY (gcode_im); c++)
+                    {
+                      gdImageSetPixel (gcode_im, r, c,
+                                       gdImageGetPixel (temp_im,
+                                                        gdImageSX (gcode_im) -
+                                                        1 - r, c));
+                    }
+                }
+              gdImageDestroy (temp_im);
+            }
+          sprintf (filename, "%s.%s.cnc", gcode_basename,
+                   layer_type_to_file_name (idx, FNS_fixed));
+          for (r = 0; r < gdImageSX (gcode_im); r++)
+            {
+              for (c = 0; c < gdImageSY (gcode_im); c++)
+                {
+                  v =
+                    gdImageGetPixel (gcode_im, r,
+                                     gdImageSY (gcode_im) - 1 - c);
+                  p = (gcode_im->red[v] || gcode_im->green[v]
+                       || gcode_im->blue[v]) ? 0 : 0xFFFFFF;
+                  BM_PUT (bm, r, c, p);
+                }
+            }
+          gcode_f2 = fopen (filename, "wb");
+          if (!gcode_f2)
+            {
+              perror (filename);
+              return;
+            }
+          fprintf (gcode_f2, "(Created by G-code exporter)\n");
+          t = time (NULL);
+          sprintf (filename, "%s", ctime (&t));
+          filename[strlen (filename) - 1] = 0;
+          fprintf (gcode_f2, "( %s )\n", filename);
+          fprintf (gcode_f2, "(%d dpi)\n", gcode_dpi);
+          fprintf (gcode_f2, "(Unit: %s)\n", metric ? "mm" : "inch");
+          if (metric)
+            pcb_fprintf (gcode_f2, "(Board size: %.2mmx%.2mm mm)",
+                         PCB->MaxWidth, PCB->MaxHeight);
+          else
+            pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)",
+                         PCB->MaxWidth, PCB->MaxHeight);
+          fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
+          fprintf (gcode_f2, "#101=%f  (cutting depth)\n", gcode_cutdepth);
+          fprintf (gcode_f2, "(---------------------------------)\n");
+          fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
+                   metric ? 21 : 20, metric ? 25 : 1);
+          fprintf (gcode_f2, "G0 Z#100\n");
+          /* extract contour points from image */
+          r = bm_to_pathlist (bm, &plist, &param_default);
+          if (r)
+            {
+              fprintf (stderr, "ERROR: pathlist function failed\n");
+              return;
+            }
+          /* generate best polygon and write vertices in g-code format */
+          d =
+            process_path (plist, &param_default, bm, gcode_f2,
+                          metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi);
+          if (d < 0)
+            {
+              fprintf (stderr, "ERROR: path process function failed\n");
+              return;
+            }
+          if (metric)
+            fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n", d,
+                     d * 1 / 25.4);
+          else
+            fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
+                     25.4 * d, d);
+          fprintf (gcode_f2, "M5 M9 M2\n");
+          pathlist_free (plist);
+          bm_free (bm);
+          fclose (gcode_f2);
+          if (save_drill)
+            {
+              d = 0;
+              drill = sort_drill (drill, n_drill);
+              sprintf (filename, "%s.drill.cnc", gcode_basename);
+              gcode_f2 = fopen (filename, "wb");
+              if (!gcode_f2)
+                {
+                  perror (filename);
+                  return;
+                }
+              fprintf (gcode_f2, "(Created by G-code exporter)\n");
+              fprintf (gcode_f2, "(drill file: %d drills)\n", n_drill);
+              sprintf (filename, "%s", ctime (&t));
+              filename[strlen (filename) - 1] = 0;
+              fprintf (gcode_f2, "( %s )\n", filename);
+              fprintf (gcode_f2, "(Unit: %s)\n", metric ? "mm" : "inch");
+              if (metric)
+                pcb_fprintf (gcode_f2, "(Board size: %.2mmx%.2mm mm)",
+                             PCB->MaxWidth, PCB->MaxHeight);
+              else
+                pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)",
+                             PCB->MaxWidth, PCB->MaxHeight);
+              fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
+              fprintf (gcode_f2, "#101=%f  (drill depth)\n",
+                       gcode_drilldepth);
+              fprintf (gcode_f2, "(---------------------------------)\n");
+              fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
+                       metric ? 21 : 20, metric ? 25 : 1);
 /*                              fprintf(gcode_f2,"G0 Z#100\n"); */
-	      for (r = 0; r < n_drill; r++)
-		{
+              for (r = 0; r < n_drill; r++)
+                {
 /*                                      if(metric) fprintf(gcode_f2,"G0 X%f Y%f\n",drill[r].x*25.4,drill[r].y*25.4); */
 /*                                      else fprintf(gcode_f2,"G0 X%f Y%f\n",drill[r].x,drill[r].y); */
-		  if (metric)
-		    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
-			     drill[r].x * 25.4, drill[r].y * 25.4);
-		  else
-		    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
-			     drill[r].x, drill[r].y);
+                  if (metric)
+                    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
+                             drill[r].x * 25.4, drill[r].y * 25.4);
+                  else
+                    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
+                             drill[r].x, drill[r].y);
 /*                                      fprintf(gcode_f2,"G1 Z#101\n"); */
 /*                                      fprintf(gcode_f2,"G0 Z#100\n"); */
-		  if (r > 0)
-		    d +=
-		      sqrt ((drill[r].x - drill[r - 1].x) * (drill[r].x -
-							     drill[r - 1].x) +
-			    (drill[r].y - drill[r - 1].y) * (drill[r].y -
-							     drill[r - 1].y));
-		}
-	      fprintf (gcode_f2, "M5 M9 M2\n");
-	      fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
-		       25.4 * d, d);
-	      fclose (gcode_f2);
-	      free (drill);
-	      drill = NULL;
-	      n_drill = nmax_drill = 0;
-	    }
-	  free (filename);
+                  if (r > 0)
+                    d +=
+                      sqrt ((drill[r].x - drill[r - 1].x) * (drill[r].x -
+                                                             drill[r - 1].x) +
+                            (drill[r].y - drill[r - 1].y) * (drill[r].y -
+                                                             drill[r - 1].y));
+                }
+              fprintf (gcode_f2, "M5 M9 M2\n");
+              fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
+                       25.4 * d, d);
+              fclose (gcode_f2);
+              free (drill);
+              drill = NULL;
+              n_drill = nmax_drill = 0;
+            }
+          free (filename);
 
 /* ******************* end gcode conversion **************************** */
-	  gcode_finish_png ();
-	}
+          gcode_finish_png ();
+        }
     }
 }
 
@@ -732,7 +737,7 @@ use_gc (hidGC gc)
          else
        */
       gdImageSetThickness (gcode_im,
-			   pcb_to_gcode (gc->width + 2 * gcode_toolradius));
+                           pcb_to_gcode (gc->width + 2 * gcode_toolradius));
       linewidth = gc->width;
       need_brush = 1;
     }
@@ -745,54 +750,54 @@ use_gc (hidGC gc)
       int r;
 
       switch (gc->cap)
-	{
-	case Round_Cap:
-	case Trace_Cap:
-	  type = 'C';
-	  r = pcb_to_gcode (gc->width / 2 + gcode_toolradius);
-	  break;
-	default:
-	case Square_Cap:
-	  r = pcb_to_gcode (gc->width + gcode_toolradius * 2);
-	  type = 'S';
-	  break;
-	}
+        {
+        case Round_Cap:
+        case Trace_Cap:
+          type = 'C';
+          r = pcb_to_gcode (gc->width / 2 + gcode_toolradius);
+          break;
+        default:
+        case Square_Cap:
+          r = pcb_to_gcode (gc->width + gcode_toolradius * 2);
+          type = 'S';
+          break;
+        }
       sprintf (name, "#%.2x%.2x%.2x_%c_%d", gc->color->r, gc->color->g,
-	       gc->color->b, type, r);
+               gc->color->b, type, r);
 
       if (hid_cache_color (0, name, &bval, &bcache))
-	{
-	  gc->brush = (gdImagePtr)bval.ptr;
-	}
+        {
+          gc->brush = (gdImagePtr)bval.ptr;
+        }
       else
-	{
-	  int bg, fg;
-	  if (type == 'C')
-	    gc->brush = gdImageCreate (2 * r + 1, 2 * r + 1);
-	  else
-	    gc->brush = gdImageCreate (r + 1, r + 1);
-	  bg = gdImageColorAllocate (gc->brush, 255, 255, 255);
-	  fg =
-	    gdImageColorAllocate (gc->brush, gc->color->r, gc->color->g,
-				  gc->color->b);
-	  gdImageColorTransparent (gc->brush, bg);
-
-	  /*
-	   * if we shrunk to a radius/box width of zero, then just use
-	   * a single pixel to draw with.
-	   */
-	  if (r == 0)
-	    gdImageFilledRectangle (gc->brush, 0, 0, 0, 0, fg);
-	  else
-	    {
-	      if (type == 'C')
-		gdImageFilledEllipse (gc->brush, r, r, 2 * r, 2 * r, fg);
-	      else
-		gdImageFilledRectangle (gc->brush, 0, 0, r, r, fg);
-	    }
-	  bval.ptr = gc->brush;
-	  hid_cache_color (1, name, &bval, &bcache);
-	}
+        {
+          int bg, fg;
+          if (type == 'C')
+            gc->brush = gdImageCreate (2 * r + 1, 2 * r + 1);
+          else
+            gc->brush = gdImageCreate (r + 1, r + 1);
+          bg = gdImageColorAllocate (gc->brush, 255, 255, 255);
+          fg =
+            gdImageColorAllocate (gc->brush, gc->color->r, gc->color->g,
+                                  gc->color->b);
+          gdImageColorTransparent (gc->brush, bg);
+
+          /*
+           * if we shrunk to a radius/box width of zero, then just use
+           * a single pixel to draw with.
+           */
+          if (r == 0)
+            gdImageFilledRectangle (gc->brush, 0, 0, 0, 0, fg);
+          else
+            {
+              if (type == 'C')
+                gdImageFilledEllipse (gc->brush, r, r, 2 * r, 2 * r, fg);
+              else
+                gdImageFilledRectangle (gc->brush, 0, 0, r, r, fg);
+            }
+          bval.ptr = gc->brush;
+          hid_cache_color (1, name, &bval, &bcache);
+        }
 
       gdImageSetBrush (gcode_im, gc->brush);
       lastbrush = gc->brush;
@@ -802,32 +807,32 @@ use_gc (hidGC gc)
   if (lastcolor != CBLEND (gc))
     {
       if (is_drill || is_mask)
-	{
+        {
 #ifdef FIXME
-	  fprintf (f, "%d gray\n", gc->erase ? 0 : 1);
+          fprintf (f, "%d gray\n", gc->erase ? 0 : 1);
 #endif
-	  lastcolor = 0;
-	}
+          lastcolor = 0;
+        }
       else
-	{
-	  double r, g, b;
-	  r = gc->r;
-	  g = gc->g;
-	  b = gc->b;
-	  if (gc->faded)
-	    {
-	      r = 0.8 * 255 + 0.2 * r;
-	      g = 0.8 * 255 + 0.2 * g;
-	      b = 0.8 * 255 + 0.2 * b;
-	    }
+        {
+          double r, g, b;
+          r = gc->r;
+          g = gc->g;
+          b = gc->b;
+          if (gc->faded)
+            {
+              r = 0.8 * 255 + 0.2 * r;
+              g = 0.8 * 255 + 0.2 * g;
+              b = 0.8 * 255 + 0.2 * b;
+            }
 #ifdef FIXME
-	  if (gc->r == gc->g && gc->g == gc->b)
-	    fprintf (f, "%g gray\n", r / 255.0);
-	  else
-	    fprintf (f, "%g %g %g rgb\n", r / 255.0, g / 255.0, b / 255.0);
+          if (gc->r == gc->g && gc->g == gc->b)
+            fprintf (f, "%g gray\n", r / 255.0);
+          else
+            fprintf (f, "%g %g %g rgb\n", r / 255.0, g / 255.0, b / 255.0);
 #endif
-	  lastcolor = CBLEND (gc);
-	}
+          lastcolor = CBLEND (gc);
+        }
     }
 }
 
@@ -836,10 +841,10 @@ gcode_draw_rect (hidGC gc, int x1, int y1, int x2, int y2)
 {
   use_gc (gc);
   gdImageRectangle (gcode_im,
-		    pcb_to_gcode (x1 - gcode_toolradius),
-		    pcb_to_gcode (y1 - gcode_toolradius),
-		    pcb_to_gcode (x2 + gcode_toolradius),
-		    pcb_to_gcode (y2 + gcode_toolradius), gc->color->c);
+                    pcb_to_gcode (x1 - gcode_toolradius),
+                    pcb_to_gcode (y1 - gcode_toolradius),
+                    pcb_to_gcode (x2 + gcode_toolradius),
+                    pcb_to_gcode (y2 + gcode_toolradius), gc->color->c);
 /*      printf("Rect %d %d %d %d\n",x1,y1,x2,y2); */
 }
 
@@ -850,10 +855,10 @@ gcode_fill_rect (hidGC gc, int x1, int y1, int x2, int y2)
   gdImageSetThickness (gcode_im, 0);
   linewidth = 0;
   gdImageFilledRectangle (gcode_im,
-			  pcb_to_gcode (x1 - gcode_toolradius),
-			  pcb_to_gcode (y1 - gcode_toolradius),
-			  pcb_to_gcode (x2 + gcode_toolradius),
-			  pcb_to_gcode (y2 + gcode_toolradius), gc->color->c);
+                          pcb_to_gcode (x1 - gcode_toolradius),
+                          pcb_to_gcode (y1 - gcode_toolradius),
+                          pcb_to_gcode (x2 + gcode_toolradius),
+                          pcb_to_gcode (y2 + gcode_toolradius), gc->color->c);
 /*      printf("FillRect %d %d %d %d\n",x1,y1,x2,y2); */
 }
 
@@ -871,12 +876,12 @@ gcode_draw_line (hidGC gc, int x1, int y1, int x2, int y2)
   gdImageSetThickness (gcode_im, 0);
   linewidth = 0;
   gdImageLine (gcode_im, pcb_to_gcode (x1), pcb_to_gcode (y1),
-	       pcb_to_gcode (x2), pcb_to_gcode (y2), gdBrushed);
+               pcb_to_gcode (x2), pcb_to_gcode (y2), gdBrushed);
 }
 
 static void
 gcode_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
-		Angle start_angle, Angle delta_angle)
+                Angle start_angle, Angle delta_angle)
 {
   Angle sa, ea;
 
@@ -914,18 +919,18 @@ gcode_draw_arc (hidGC gc, int cx, int cy, int width, int height,
 
 #if 0
   printf ("draw_arc %d,%d %dx%d %d..%d %d..%d\n",
-	  cx, cy, width, height, start_angle, delta_angle, sa, ea);
+          cx, cy, width, height, start_angle, delta_angle, sa, ea);
   printf ("gdImageArc (%p, %d, %d, %d, %d, %d, %d, %d)\n",
-	  im, SCALE_X (cx), SCALE_Y (cy),
-	  SCALE (width), SCALE (height), sa, ea, gc->color->c);
+          im, SCALE_X (cx), SCALE_Y (cy),
+          SCALE (width), SCALE (height), sa, ea, gc->color->c);
 #endif
   use_gc (gc);
   gdImageSetThickness (gcode_im, 0);
   linewidth = 0;
   gdImageArc (gcode_im, pcb_to_gcode (cx), pcb_to_gcode (cy),
-	      pcb_to_gcode (2 * width + gcode_toolradius * 2),
-	      pcb_to_gcode (2 * height + gcode_toolradius * 2), sa, ea,
-	      gdBrushed);
+              pcb_to_gcode (2 * width + gcode_toolradius * 2),
+              pcb_to_gcode (2 * height + gcode_toolradius * 2), sa, ea,
+              gdBrushed);
 }
 
 static void
@@ -936,22 +941,21 @@ gcode_fill_circle (hidGC gc, int cx, int cy, int radius)
   gdImageSetThickness (gcode_im, 0);
   linewidth = 0;
   gdImageFilledEllipse (gcode_im, pcb_to_gcode (cx), pcb_to_gcode (cy),
-			pcb_to_gcode (2 * radius + gcode_toolradius * 2),
-			pcb_to_gcode (2 * radius + gcode_toolradius * 2),
-			gc->color->c);
+                        pcb_to_gcode (2 * radius + gcode_toolradius * 2),
+                        pcb_to_gcode (2 * radius + gcode_toolradius * 2),
+                        gc->color->c);
   if (save_drill && is_drill)
     {
       if (n_drill == nmax_drill)
-	{
-	  drill =
-	    (struct drill_struct *) realloc (drill,
-					     (nmax_drill +
-					      100) *
-					     sizeof (struct drill_struct));
-	  nmax_drill += 100;
-	}
-      drill[n_drill].x = COORD_TO_INCH(PCB->MaxWidth - cx);	/* convert to inch, flip: will drill from bottom side */
-      drill[n_drill].y = COORD_TO_INCH(PCB->MaxHeight - cy);	/* PCB reverses y axis */
+        {
+          drill =
+            (struct drill_struct *) realloc (drill,
+                                             (nmax_drill + 100) *
+                                             sizeof (struct drill_struct));
+          nmax_drill += 100;
+        }
+      drill[n_drill].x = COORD_TO_INCH(PCB->MaxWidth - cx);       /* convert to inch, flip: will drill from bottom side */
+      drill[n_drill].y = COORD_TO_INCH(PCB->MaxHeight - cy);      /* PCB reverses y axis */
       n_drill++;
 /*              printf("Circle %d %d\n",cx,cy); */
     }
-- 
1.7.4.1

From de6aaea0dc9307b48d885b0a3794375de68b00ae Mon Sep 17 00:00:00 2001
From: Markus Hitter <mah@xxxxxxxxxxx>
Date: Thu, 21 Oct 2010 00:03:12 +0200
Subject: HID-gcode: create better file names.

If the user adds a suffix to a file name in the dialog, he expects
the resulting files to have these suffixes as well.
---
 src/hid/gcode/gcode.c |   38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/hid/gcode/gcode.c b/src/hid/gcode/gcode.c
index 5dbff16..055b458 100644
--- a/src/hid/gcode/gcode.c
+++ b/src/hid/gcode/gcode.c
@@ -116,7 +116,7 @@ static int gcode_export_group[MAX_LAYER];
 /* Group that is currently exported. */
 static int gcode_cur_group;
 
-/* Filename prefix that will be used when saving files. */
+/* Filename prefix and suffix that will be used when saving files. */
 static const char *gcode_basename = NULL;
 
 /* Horizontal DPI (grid points per inch) */
@@ -147,7 +147,8 @@ static const char *units[] = {
 
 HID_Attribute gcode_attribute_list[] = {
   /* other HIDs expect this to be first.  */
-  {"basename", "File name prefix",
+  {"basename", "File name prefix and suffix,\n"
+               "layer names will be inserted before the suffix",
    HID_String, 0, 0, {0, 0, 0}, 0, 0},
 #define HA_basename 0
 
@@ -190,6 +191,30 @@ static int pcb_to_gcode (int pcb)
   return round(COORD_TO_INCH(pcb) * gcode_dpi);
 }
 
+/* Fits the given layer name into basename, just before the suffix */
+static void
+gcode_get_filename (char *filename, const char *layername)
+{
+  char *pt;
+  char suffix[MAXPATHLEN];
+
+  suffix[0] = '\0';
+  pt = strrchr (gcode_basename, '.');
+  if (pt && pt > strrchr (gcode_basename, '/'))
+    strcpy (suffix, pt);
+  else
+    pt = NULL;
+
+  strcpy (filename, gcode_basename);
+  if (pt)
+    *(filename + (pt - gcode_basename)) = '\0';
+  strcat (filename, "-");
+  strcat (filename, layername);
+  strcat (filename, suffix);
+
+  // result is in char *filename
+}
+
 /* Sorts drills in order of distance from the origin */
 struct drill_struct *
 sort_drill (struct drill_struct *drill, int n_drill)
@@ -394,7 +419,7 @@ gcode_do_export (HID_Attr_Val * options)
   gcode_basename = options[HA_basename].str_value;
   if (!gcode_basename)
     {
-      gcode_basename = "pcb-out";
+      gcode_basename = "pcb-out.gcode";
     }
   gcode_dpi = options[HA_dpi].int_value;
   if (gcode_dpi < 0)
@@ -471,8 +496,7 @@ gcode_do_export (HID_Attr_Val * options)
                 }
               gdImageDestroy (temp_im);
             }
-          sprintf (filename, "%s.%s.cnc", gcode_basename,
-                   layer_type_to_file_name (idx, FNS_fixed));
+          gcode_get_filename (filename, layer_type_to_file_name (idx, FNS_fixed));
           for (r = 0; r < gdImageSX (gcode_im); r++)
             {
               for (c = 0; c < gdImageSY (gcode_im); c++)
@@ -540,7 +564,7 @@ gcode_do_export (HID_Attr_Val * options)
             {
               d = 0;
               drill = sort_drill (drill, n_drill);
-              sprintf (filename, "%s.drill.cnc", gcode_basename);
+              gcode_get_filename (filename, "drill");
               gcode_f2 = fopen (filename, "wb");
               if (!gcode_f2)
                 {
-- 
1.7.4.1

From 9509125a1a57c31951d4aa047ccd9ec682483466 Mon Sep 17 00:00:00 2001
From: Markus Hitter <mah@xxxxxxxxxxx>
Date: Thu, 21 Oct 2010 01:18:52 +0200
Subject: HID-gcode: add a flag wether to produce advanced G-code.

Some primitive machine controllers don't understand what a variable
is, while those understanding variables can work without as well.
After all, using variables is just a convenience for later hand-editing
of the G-code programs. More changes for primitive controllers are
to come.
---
 src/hid/gcode/gcode.c |   66 ++++++++++++++++++++++++++++++++++++------------
 src/hid/gcode/trace.c |   12 +++++---
 src/hid/gcode/trace.h |    3 +-
 3 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/hid/gcode/gcode.c b/src/hid/gcode/gcode.c
index 055b458..ae50587 100644
--- a/src/hid/gcode/gcode.c
+++ b/src/hid/gcode/gcode.c
@@ -126,6 +126,7 @@ static double gcode_cutdepth = 0;       /* milling depth (inch) */
 static double gcode_drilldepth = 0;     /* drilling depth (inch) */
 static double gcode_safeZ = 100;        /* safe Z (inch) */
 static double gcode_toolradius = 0;     /* tool radius(inch) */
+static char gcode_advanced = 0;
 static int save_drill = 0;
 static int n_drill = 0;
 static int nmax_drill = 0;
@@ -176,6 +177,12 @@ HID_Attribute gcode_attribute_list[] = {
    HID_Unit, 0, 0, {-1, 0, 0}, units, 0},
 #define HA_unit 6
 
+  {"advanced-gcode", "wether to produce G-code for advanced interpreters,\n"
+                     "like using variables for often used values. Not all\n"
+                     "machine controllers understand this, but it allows\n"
+                     "better hand-editing of the resulting files",
+   HID_Boolean, 0, 0, {0, 0, 0}, 0, 0},
+#define HA_advanced 7
 };
 
 #define NUM_OPTIONS (sizeof(gcode_attribute_list)/sizeof(gcode_attribute_list[0]))
@@ -406,6 +413,8 @@ gcode_do_export (HID_Attr_Val * options)
      0.0,                        /* granularity  */
      },
   };
+  char variable_safeZ[20], variable_cutdepth[20];
+  char variable_drilldepth[20];
 
   if (!options)
     {
@@ -451,13 +460,25 @@ gcode_do_export (HID_Attr_Val * options)
   gcode_toolradius = metric
                    ? MM_TO_COORD(options[HA_toolradius].real_value * scale)
                    : INCH_TO_COORD(options[HA_toolradius].real_value * scale);
+  gcode_advanced = options[HA_advanced].int_value;
   gcode_choose_groups ();
+  if (gcode_advanced)
+    {
+      strcpy (variable_safeZ, "#100");
+      strcpy (variable_cutdepth, "#101");
+      strcpy (variable_drilldepth, "#102");
+    }
+  else
+    {
+      snprintf (variable_safeZ, 20, "%f", gcode_safeZ);
+      snprintf (variable_cutdepth, 20, "%f", gcode_cutdepth);
+      snprintf (variable_drilldepth, 20, "%f", gcode_drilldepth);
+    }
 
   for (i = 0; i < MAX_LAYER; i++)
     {
       if (gcode_export_group[i])
         {
-
           gcode_cur_group = i;
 
           /* magic */
@@ -528,12 +549,17 @@ gcode_do_export (HID_Attr_Val * options)
           else
             pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)",
                          PCB->MaxWidth, PCB->MaxHeight);
-          fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
-          fprintf (gcode_f2, "#101=%f  (cutting depth)\n", gcode_cutdepth);
+          if (gcode_advanced)
+            {
+              fprintf (gcode_f2, "%s=%f  (safe Z)\n",
+                       variable_safeZ, gcode_safeZ);
+              fprintf (gcode_f2, "%s=%f  (cutting depth)\n",
+                       variable_cutdepth, gcode_cutdepth);
+            }
           fprintf (gcode_f2, "(---------------------------------)\n");
           fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
                    metric ? 21 : 20, metric ? 25 : 1);
-          fprintf (gcode_f2, "G0 Z#100\n");
+          fprintf (gcode_f2, "G0 Z%s\n", variable_safeZ);
           /* extract contour points from image */
           r = bm_to_pathlist (bm, &plist, &param_default);
           if (r)
@@ -542,9 +568,9 @@ gcode_do_export (HID_Attr_Val * options)
               return;
             }
           /* generate best polygon and write vertices in g-code format */
-          d =
-            process_path (plist, &param_default, bm, gcode_f2,
-                          metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi);
+          d = process_path (plist, &param_default, bm, gcode_f2,
+                            metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi,
+                            variable_cutdepth, variable_safeZ);
           if (d < 0)
             {
               fprintf (stderr, "ERROR: path process function failed\n");
@@ -583,25 +609,31 @@ gcode_do_export (HID_Attr_Val * options)
               else
                 pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)",
                              PCB->MaxWidth, PCB->MaxHeight);
-              fprintf (gcode_f2, "#100=%f  (safe Z)\n", gcode_safeZ);
-              fprintf (gcode_f2, "#101=%f  (drill depth)\n",
-                       gcode_drilldepth);
+              if (gcode_advanced)
+                {
+                  fprintf (gcode_f2, "%s=%f  (safe Z)\n",
+                           variable_safeZ, gcode_safeZ);
+                  fprintf (gcode_f2, "%s=%f  (drill depth)\n",
+                           variable_drilldepth, gcode_drilldepth);
+                }
               fprintf (gcode_f2, "(---------------------------------)\n");
               fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
                        metric ? 21 : 20, metric ? 25 : 1);
-/*                              fprintf(gcode_f2,"G0 Z#100\n"); */
+/*                              fprintf(gcode_f2,"G0 Z%s\n",variable_safeZ); */
               for (r = 0; r < n_drill; r++)
                 {
 /*                                      if(metric) fprintf(gcode_f2,"G0 X%f Y%f\n",drill[r].x*25.4,drill[r].y*25.4); */
 /*                                      else fprintf(gcode_f2,"G0 X%f Y%f\n",drill[r].x,drill[r].y); */
                   if (metric)
-                    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
-                             drill[r].x * 25.4, drill[r].y * 25.4);
+                    fprintf (gcode_f2, "G81 X%f Y%f Z%s R%s\n",
+                             drill[r].x * 25.4, drill[r].y * 25.4,
+                             variable_drilldepth, variable_safeZ);
                   else
-                    fprintf (gcode_f2, "G81 X%f Y%f Z#101 R#100\n",
-                             drill[r].x, drill[r].y);
-/*                                      fprintf(gcode_f2,"G1 Z#101\n"); */
-/*                                      fprintf(gcode_f2,"G0 Z#100\n"); */
+                    fprintf (gcode_f2, "G81 X%f Y%f Z%s R%s\n",
+                             drill[r].x, drill[r].y,
+                             variable_drilldepth, variable_safeZ);
+/*                                      fprintf(gcode_f2,"G1 Z%s\n",variable_depth); */
+/*                                      fprintf(gcode_f2,"G0 Z%s\n",variable_safeZ); */
                   if (r > 0)
                     d +=
                       sqrt ((drill[r].x - drill[r - 1].x) * (drill[r].x -
diff --git a/src/hid/gcode/trace.c b/src/hid/gcode/trace.c
index 7fb9012..5d7c62e 100644
--- a/src/hid/gcode/trace.c
+++ b/src/hid/gcode/trace.c
@@ -1401,7 +1401,8 @@ malloc_error:
 
 /* ---------------------------------------------------------------------- */
 double
-plotpolygon (privpath_t * pp, FILE * f, double scale)
+plotpolygon (privpath_t * pp, FILE * f, double scale, const char *var_cutdepth,
+             const char *var_safeZ)
 {
   int i;
   int m = pp->m;
@@ -1418,7 +1419,7 @@ plotpolygon (privpath_t * pp, FILE * f, double scale)
 
   fprintf (f, "G0 X%f Y%f    (start point)\n", pt[po[0]].x * scale,
 	   pt[po[0]].y * scale);
-  fprintf (f, "G1 Z#101\n");
+  fprintf (f, "G1 Z%s\n", var_cutdepth);
   for (i = 1; i < m; i++)
     {
       fprintf (f, "G1 X%f Y%f\n", pt[po[i]].x * scale, pt[po[i]].y * scale);
@@ -1432,7 +1433,7 @@ plotpolygon (privpath_t * pp, FILE * f, double scale)
 	      scale);
     }
   fprintf (f, "G1 X%f Y%f\n", pt[po[0]].x * scale, pt[po[0]].y * scale);
-  fprintf (f, "G0 Z#100\n");
+  fprintf (f, "G0 Z%s\n", var_safeZ);
   dm +=
     sqrt ((pt[po[m - 1]].x - pt[po[0]].x) * scale * (pt[po[m - 1]].x -
 						     pt[po[0]].x) * scale +
@@ -1447,7 +1448,8 @@ plotpolygon (privpath_t * pp, FILE * f, double scale)
 /* return distance on success, -1 on error with errno set. */
 double
 process_path (path_t * plist, const potrace_param_t * param,
-	      const potrace_bitmap_t * bm, FILE * f, double scale)
+	      const potrace_bitmap_t * bm, FILE * f, double scale,
+	      const char *var_cutdepth, const char *var_safeZ)
 {
   path_t *p;
   double dm = 0;
@@ -1460,7 +1462,7 @@ process_path (path_t * plist, const potrace_param_t * param,
     TRY (bestpolygon (p->priv));
     TRY (adjust_vertices (p->priv));
     fprintf (f, "(polygon %d)\n", ++n);
-    dm += plotpolygon (p->priv, f, scale);
+    dm += plotpolygon (p->priv, f, scale, var_cutdepth, var_safeZ);
 /*  No need to extract curves
 	TRY(smooth(&p->priv->curve, p->sign, param->alphamax));
     if (param->opticurve) {
diff --git a/src/hid/gcode/trace.h b/src/hid/gcode/trace.h
index 2a07e61..d55fd3e 100644
--- a/src/hid/gcode/trace.h
+++ b/src/hid/gcode/trace.h
@@ -10,6 +10,7 @@
 #include "potracelib.h"
 
 double process_path (path_t * plist, const potrace_param_t * param,
-		     const potrace_bitmap_t * bm, FILE * f, double scale);
+		     const potrace_bitmap_t * bm, FILE * f, double scale,
+		     const char *var_cutdepth, const char *var_safeZ);
 
 #endif /* TRACE_H */
-- 
1.7.4.1

From e1de0a2f827ec71ad62b24cc5eebb00da504cd71 Mon Sep 17 00:00:00 2001
From: Markus Hitter <mah@xxxxxxxxxxx>
Date: Fri, 22 Oct 2010 20:48:21 +0200
Subject: HID-gcode: postpone closing the mill file until the drill file is written.

This is in preparation for the pre-drill feature, which requires
to add drills to both files.
---
 src/hid/gcode/gcode.c |   88 ++++++++++++++++++++++++------------------------
 1 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/src/hid/gcode/gcode.c b/src/hid/gcode/gcode.c
index 87db04c..33202c7 100644
--- a/src/hid/gcode/gcode.c
+++ b/src/hid/gcode/gcode.c
@@ -101,7 +101,7 @@ static int lastcolor = -1;
 
 /* gd image and file for PNG export */
 static gdImagePtr gcode_im = NULL;
-static FILE *gcode_f = NULL, *gcode_f2 = NULL;
+static FILE *gcode_f = NULL, *gcode_f2 = NULL, *gcode_f3 = NULL;
 
 static int is_mask;
 static int is_drill;
@@ -396,7 +396,7 @@ gcode_do_export (HID_Attr_Val * options)
   int i, idx;
   time_t t;
   const Unit *unit;
-  double scale = 0, d = 0;
+  double scale = 0, d_mill = 0;
   int r, c, v, p, metric;
   char *filename;
   path_t *plist = NULL;
@@ -578,67 +578,59 @@ gcode_do_export (HID_Attr_Val * options)
               return;
             }
           /* generate best polygon and write vertices in g-code format */
-          d = process_path (plist, &param_default, bm, gcode_f2,
-                            metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi,
-                            variable_cutdepth, variable_safeZ);
-          if (d < 0)
+          d_mill = process_path (plist, &param_default, bm, gcode_f2,
+                                 metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi,
+                                 variable_cutdepth, variable_safeZ);
+          pathlist_free (plist);
+          bm_free (bm);
+          if (d_mill < 0)
             {
               fprintf (stderr, "ERROR: path process function failed\n");
               return;
             }
           if (metric)
-            fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n", d,
-                     d * 1 / 25.4);
-          else
-            fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
-                     25.4 * d, d);
-          if (gcode_advanced)
-            fprintf (gcode_f2, "M5 M9 M2\n");
-          else
-            fprintf (gcode_f2, "M5\nM9\nM2\n");
-          pathlist_free (plist);
-          bm_free (bm);
-          fclose (gcode_f2);
+            d_mill /= 25.4;
           if (save_drill)
             {
-              d = 0;
+              double d_drill = 0, d_delta = 0;
+
               drill = sort_drill (drill, n_drill);
               gcode_get_filename (filename, "drill");
-              gcode_f2 = fopen (filename, "wb");
-              if (!gcode_f2)
+              gcode_f3 = fopen (filename, "wb");
+              if (!gcode_f3)
                 {
                   perror (filename);
                   return;
                 }
-              fprintf (gcode_f2, "(Created by G-code exporter)\n");
-              fprintf (gcode_f2, "(drill file: %d drills)\n", n_drill);
+              fprintf (gcode_f3, "(Created by G-code exporter)\n");
+              fprintf (gcode_f3, "(drill file: %d drills)\n", n_drill);
               sprintf (filename, "%s", ctime (&t));
               filename[strlen (filename) - 1] = 0;
-              fprintf (gcode_f2, "( %s )\n", filename);
-              fprintf (gcode_f2, "(Unit: %s)\n", metric ? "mm" : "inch");
+              fprintf (gcode_f3, "( %s )\n", filename);
+              fprintf (gcode_f3, "(Unit: %s)\n", metric ? "mm" : "inch");
               if (metric)
-                pcb_fprintf (gcode_f2, "(Board size: %.2mmx%.2mm mm)",
+                pcb_fprintf (gcode_f3, "(Board size: %.2mmx%.2mm mm)",
                              PCB->MaxWidth, PCB->MaxHeight);
               else
-                pcb_fprintf (gcode_f2, "(Board size: %.2mix%.2mi inches)",
+                pcb_fprintf (gcode_f3, "(Board size: %.2mix%.2mi inches)",
                              PCB->MaxWidth, PCB->MaxHeight);
               if (gcode_advanced)
                 {
-                  fprintf (gcode_f2, "%s=%f  (safe Z)\n",
+                  fprintf (gcode_f3, "%s=%f  (safe Z)\n",
                            variable_safeZ, gcode_safeZ);
-                  fprintf (gcode_f2, "%s=%f  (drill depth)\n",
+                  fprintf (gcode_f3, "%s=%f  (drill depth)\n",
                            variable_drilldepth, gcode_drilldepth);
-                  fprintf (gcode_f2, "(---------------------------------)\n");
-                  fprintf (gcode_f2, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
+                  fprintf (gcode_f3, "(---------------------------------)\n");
+                  fprintf (gcode_f3, "G17 G%d G90 G64 P0.003 M3 S3000 M7 F%d\n",
                            metric ? 21 : 20, metric ? 25 : 1);
                 }
               else
                 {
-                  fprintf (gcode_f2, "(---------------------------------)\n");
-                  fprintf (gcode_f2, "G17\nG%d\nG90\nG64 P0.003\nM3 S3000\nM7\nF%d\n",
+                  fprintf (gcode_f3, "(---------------------------------)\n");
+                  fprintf (gcode_f3, "G17\nG%d\nG90\nG64 P0.003\nM3 S3000\nM7\nF%d\n",
                            metric ? 21 : 20, metric ? 25 : 1);
                 }
-              fprintf (gcode_f2, "G0 Z%s\n", variable_safeZ);
+              fprintf (gcode_f3, "G0 Z%s\n", variable_safeZ);
               for (r = 0; r < n_drill; r++)
                 {
                   double drillX, drillY;
@@ -654,32 +646,40 @@ gcode_do_export (HID_Attr_Val * options)
                       drillY = drill[r].y;
                     }
                   if (gcode_advanced)
-                    fprintf (gcode_f2, "G81 X%f Y%f Z%s R%s\n", drillX, drillY,
+                    fprintf (gcode_f3, "G81 X%f Y%f Z%s R%s\n", drillX, drillY,
                              variable_drilldepth, variable_safeZ);
                   else
                     {
-                      fprintf (gcode_f2, "G0 X%f Y%f\n", drillX, drillY);
-                      fprintf (gcode_f2, "G1 Z%s\n", variable_drilldepth);
-                      fprintf (gcode_f2, "G0 Z%s\n", variable_safeZ);
+                      fprintf (gcode_f3, "G0 X%f Y%f\n", drillX, drillY);
+                      fprintf (gcode_f3, "G1 Z%s\n", variable_drilldepth);
+                      fprintf (gcode_f3, "G0 Z%s\n", variable_safeZ);
                     }
                   if (r > 0)
-                    d +=
+                    d_delta =
                       sqrt ((drill[r].x - drill[r - 1].x) * (drill[r].x -
                                                              drill[r - 1].x) +
                             (drill[r].y - drill[r - 1].y) * (drill[r].y -
                                                              drill[r - 1].y));
+                  d_drill += d_delta;
                 }
               if (gcode_advanced)
-                fprintf (gcode_f2, "M5 M9 M2\n");
+                fprintf (gcode_f3, "M5 M9 M2\n");
               else
-                fprintf (gcode_f2, "M5\nM9\nM2\n");
-              fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
-                       25.4 * d, d);
-              fclose (gcode_f2);
+                fprintf (gcode_f3, "M5\nM9\nM2\n");
+              fprintf (gcode_f3, "(end, total distance %.2fmm = %.2fin)\n",
+                       25.4 * d_drill, d_drill);
+              fclose (gcode_f3);
               free (drill);
               drill = NULL;
               n_drill = nmax_drill = 0;
             }
+          if (gcode_advanced)
+            fprintf (gcode_f2, "M5 M9 M2\n");
+          else
+            fprintf (gcode_f2, "M5\nM9\nM2\n");
+          fprintf (gcode_f2, "(end, total distance %.2fmm = %.2fin)\n",
+                   25.4 * d_mill, d_mill);
+          fclose (gcode_f2);
           free (filename);
 
 /* ******************* end gcode conversion **************************** */
-- 
1.7.4.1


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