This is a patch to move gerbv toward supporting Gerber X2.
The X2 specification was released in 2014 by Ucamco the authors of Gerber.
This patch is of use especially for Altium users, as Altium supports X2
export very well, yet the internal Camtastic viewer is weak.

In some sense gerbv already supports X2, as X2 is fully backward
compatible.  But loading an X2 file throws tons of warnings, which
can obscure real errors.

This patch does not attempt to round trip X2 metadata.  There is
a flag that could be used to pop up a warning that the X2 data
won't be preserved on save.  For viewer only users, however, this
patch is helpful without any real downsides.

Someone could extend this to put layers in the right order for display,
by default, or to draw a stackup diagram including drill depths.

-------------------------------------------------------------------------------------------------------

diff --git a/src/callbacks.c b/src/callbacks.c
index 9310e14..59f09af 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -822,8 +822,9 @@
callbacks_analyze_active_gerbers_activate(GtkMenuItem *menuitem,
                        _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING,
                        _("Error"), G_TYPE_STRING);
        } else {
-               general_table = table_new_with_columns(2,
-                       _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING);
+               general_table = table_new_with_columns(3,
+                       _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING,
+                       _("Purpose"), G_TYPE_STRING);
        }
        table_set_column_align(general_table, 0, 1.0);

@@ -833,7 +834,8 @@
callbacks_analyze_active_gerbers_activate(GtkMenuItem *menuitem,
                if (files[i] && files[i]->isVisible &&
                                (files[i]->image->layertype ==
                                 GERBV_LAYERTYPE_RS274X)) {
-                       table_add_row(general_table, i + 1, files[i]->name, "");
+                       table_add_row(general_table, i + 1, files[i]->name,
+                          files[i]->image->info->Gerber_X2_Function);

                        /* Check error report on layer */
                        if (stats_report->layer_count > 0 &&
diff --git a/src/gerber.c b/src/gerber.c
index 6810d52..794e5ab 100644
--- a/src/gerber.c
+++ b/src/gerber.c
@@ -1937,6 +1937,47 @@ parse_rs274x(gint levelOfRecursion, gerb_file_t
*fd, gerbv_image_t *image,
            g_free(string);
        }
        break;This is a patch to move gerbv toward supporting Gerber X2.
The X2 specification was released in 2014 by Ucamco the authors of Gerber.
This patch is of use especially for Altium users, as Altium supports X2
export very well, yet it's internal Camtastic viewer is weak.

In some sense gerbv already supports X2, as X2 is fully backward
compatible.  But loading an X2 file throws tons of warnings, which
can obscure real errors.

This patch does not attempt to round trip X2 metadata.  There is
a flag that could be used to pop up a warning that the X2 data
won't be preserved on save.  For viewer only users, however, this
patch is helpful.

Someone could extend this to put layers in the right order for display,
by default.



diff --git a/src/callbacks.c b/src/callbacks.c
index 9310e14..59f09af 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -822,8 +822,9 @@
callbacks_analyze_active_gerbers_activate(GtkMenuItem *menuitem,
                        _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING,
                        _("Error"), G_TYPE_STRING);
        } else {
-               general_table = table_new_with_columns(2,
-                       _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING);
+               general_table = table_new_with_columns(3,
+                       _("Layer"), G_TYPE_UINT, _("File"), G_TYPE_STRING,
+                       _("Purpose"), G_TYPE_STRING);
        }
        table_set_column_align(general_table, 0, 1.0);

@@ -833,7 +834,8 @@
callbacks_analyze_active_gerbers_activate(GtkMenuItem *menuitem,
                if (files[i] && files[i]->isVisible &&
                                (files[i]->image->layertype ==
                                 GERBV_LAYERTYPE_RS274X)) {
-                       table_add_row(general_table, i + 1, files[i]->name, "");
+                       table_add_row(general_table, i + 1, files[i]->name,
+                          files[i]->image->info->Gerber_X2_Function);

                        /* Check error report on layer */
                        if (stats_report->layer_count > 0 &&
diff --git a/src/gerber.c b/src/gerber.c
index 6810d52..794e5ab 100644
--- a/src/gerber.c
+++ b/src/gerber.c
@@ -1937,6 +1937,47 @@ parse_rs274x(gint levelOfRecursion, gerb_file_t
*fd, gerbv_image_t *image,
            g_free(string);
        }
        break;
+
+    /* Gerber X2 is the official Jun 2014 update to Gerber by Ucamco.
X2 is backwards
+       compatible with Gerber X, and thus gerbv really has to do very little to
+       support X2.  Hooks are left below for anyone wanting to process more
+       X2 attributes.
+
+       See:  https://www.ucamco.com/en/guest/downloads
+    */
+
+    /* Gerber X2 Functions */
+    case A2I('T','F'):
+        string = gerb_fgetstring(fd, '*');
+        #ifdef DEBUG
+        printf("Gerber X2 TF %s\n", string);
+        #endif
+
+        /* Store role of file (e.g. plane/copper/legend/mechanical) */
+        if( !memcmp(string, ".FileFunction", strlen(".FileFunction"))) {
+            string[0]=' ';
+            image->info->Gerber_X2_Function = string;
+        }
+        else {
+            g_free(string);
+        }
+
+        image->info->Gerber_X2_Dirty = TRUE;    /* Warning: file
won't be identical on save */
+       break;
+
+    /* Gerber X2 Metadata Attributes to Ignore */
+    case A2I('T','A'):  // Aperture Attribute
+    case A2I('T','D'):  // Delete Attribute
+    case A2I('T','O'):  // Object Attribute (from 2016.07 spec draft)
+        string = gerb_fgetstring(fd, '*');
+        #ifdef DEBUG
+        printf("Gerber X2 Attribute %s\n", string);
+        #endif
+
+        image->info->Gerber_X2_Dirty = TRUE;    /* Warning: file
won't be identical on save */
+        g_free(string);
+       break;
+
     default:
        string = g_strdup_printf(_("Unknown RS-274X extension found
%%%c%c%% in file \"%s\""),
                                 op[0], op[1], fd->filename);
diff --git a/src/gerbv.h b/src/gerbv.h
index e0575c6..0ad9fd7 100644
--- a/src/gerbv.h
+++ b/src/gerbv.h
@@ -656,6 +656,8 @@ typedef struct gerbv_format {
 /*! Struct holding info about a particular image */
 typedef struct gerbv_image_info {
     char *name;
+    char     *Gerber_X2_Function;   /* Metadata on the role or
function of the given file */
+    gboolean  Gerber_X2_Dirty;      /* Some Gerber X2 data was not
parsed: warn at save */
     gerbv_polarity_t polarity;
     double min_x; /* Always in inches */
     double min_y;
(END)

+
+    /* Gerber X2 is the official Jun 2014 update to Gerber by Ucamco.
X2 is backwards
+       compatible with Gerber X, and thus gerbv really has to do very little to
+       support X2.  Hooks are left below for anyone wanting to process more
+       X2 attributes.
+
+       See:  https://www.ucamco.com/en/guest/downloads
+    */
+
+    /* Gerber X2 Functions */
+    case A2I('T','F'):
+        string = gerb_fgetstring(fd, '*');
+        #ifdef DEBUG
+        printf("Gerber X2 TF %s\n", string);
+        #endif
+
+        /* Store role of file (e.g. plane/copper/legend/mechanical) */
+        if( !memcmp(string, ".FileFunction", strlen(".FileFunction"))) {
+            string[0]=' ';
+            image->info->Gerber_X2_Function = string;
+        }
+        else {
+            g_free(string);
+        }
+
+        image->info->Gerber_X2_Dirty = TRUE;    /* Warning: file
won't be identical on save */
+       break;
+
+    /* Gerber X2 Metadata Attributes to Ignore */
+    case A2I('T','A'):  // Aperture Attribute
+    case A2I('T','D'):  // Delete Attribute
+    case A2I('T','O'):  // Object Attribute (from 2016.07 spec draft)
+        string = gerb_fgetstring(fd, '*');
+        #ifdef DEBUG
+        printf("Gerber X2 Attribute %s\n", string);
+        #endif
+
+        image->info->Gerber_X2_Dirty = TRUE;    /* Warning: file
won't be identical on save */
+        g_free(string);
+       break;
+
     default:
        string = g_strdup_printf(_("Unknown RS-274X extension found
%%%c%c%% in file \"%s\""),
                                 op[0], op[1], fd->filename);
diff --git a/src/gerbv.h b/src/gerbv.h
index e0575c6..0ad9fd7 100644
--- a/src/gerbv.h
+++ b/src/gerbv.h
@@ -656,6 +656,8 @@ typedef struct gerbv_format {
 /*! Struct holding info about a particular image */
 typedef struct gerbv_image_info {
     char *name;
+    char     *Gerber_X2_Function;   /* Metadata on the role or
function of the given file */
+    gboolean  Gerber_X2_Dirty;      /* Some Gerber X2 data was not
parsed: warn at save */
     gerbv_polarity_t polarity;
     double min_x; /* Always in inches */
     double min_y;
(END)

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Gerbv-devel mailing list
Gerbv-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gerbv-devel

Reply via email to