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

gEDA-cvs: pcb.git: branch: master updated (44a8ca4f7d71cd743053a14ace0740b1f6e0b458)



The branch, master has been updated
       via  44a8ca4f7d71cd743053a14ace0740b1f6e0b458 (commit)
       via  023dd955353cc355e00a3099f3262e16fa432bf6 (commit)
       via  c96e65eeb94c569e81cc940d4a10dd54e3b7ebc1 (commit)
      from  351ebc91665795f98d0e6c6676d0c85c7e464008 (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/Makefile.am         |    2 +
 src/draw.c              |  538 ++++++++---------------------------------------
 src/draw.h              |    1 -
 src/draw_funcs.c        |  402 +++++++++++++++++++++++++++++++++++
 src/draw_funcs.h        |   17 ++
 src/hid/gerber/gerber.c |    3 +-
 src/hid/ps/ps.c         |    3 +-
 7 files changed, 509 insertions(+), 457 deletions(-)
 create mode 100644 src/draw_funcs.c
 create mode 100644 src/draw_funcs.h


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

commit 44a8ca4f7d71cd743053a14ace0740b1f6e0b458
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    draw.c: Remove obsolete comment

:100644 100644 53757f4... 20a269d... M	src/draw.c

commit 023dd955353cc355e00a3099f3262e16fa432bf6
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    Continue with crazy idea

:100644 100644 cc04a43... 53757f4... M	src/draw.c
:100644 100644 adfee36... cf324a5... M	src/draw.h
:100644 100644 49beeba... 363a85e... M	src/draw_funcs.c
:100644 100644 1f97d82... 25c33a1... M	src/draw_funcs.h
:100644 100644 d5843ef... 4429121... M	src/hid/gerber/gerber.c
:100644 100644 a417753... 8024abc... M	src/hid/ps/ps.c

commit c96e65eeb94c569e81cc940d4a10dd54e3b7ebc1
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    Crasy test

:100644 100644 5abbfb2... 34cd5b3... M	src/Makefile.am
:100644 100644 8e8821d... cc04a43... M	src/draw.c
:000000 100644 0000000... 49beeba... A	src/draw_funcs.c
:000000 100644 0000000... 1f97d82... A	src/draw_funcs.h

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

commit 44a8ca4f7d71cd743053a14ace0740b1f6e0b458
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    draw.c: Remove obsolete comment

diff --git a/src/draw.c b/src/draw.c
index 53757f4..20a269d 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -108,17 +108,13 @@ AddPart (void *b)
 }
 
 /*
- * initiate the actual drawing to the pixmap/screen
- * make the update block slightly larger to handle round-off
- * caused by the TO_SCREEN operation
+ * initiate the actual redrawing of the updated area
  */
 void
 Draw (void)
 {
   HideCrosshair ();
 
-  /* clear and create event if not drawing to a pixmap
-   */
   if (Block.X1 <= Block.X2 && Block.Y1 <= Block.Y2)
     gui->invalidate_lr (Block.X1, Block.X2, Block.Y1, Block.Y2);
 

commit 023dd955353cc355e00a3099f3262e16fa432bf6
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    Continue with crazy idea

diff --git a/src/draw.c b/src/draw.c
index cc04a43..53757f4 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -149,16 +149,6 @@ set_pv_color (PinType *pv, int type)
                                                                                          : PCB->PinColor);
 }
 
-static void
-set_pv_inlayer_color (PinType *pv, LayerType *layer, int type)
-{
-  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
-  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, (type == VIA_TYPE) ? PCB->ViaSelectedColor
-                                                                                         : PCB->PinSelectedColor);
-  else if (TEST_FLAG (FOUNDFLAG, pv))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
-  else                                   gui->set_color (Output.fgGC, layer->Color);
-}
-
 static int
 pin_callback (const BoxType * b, void *cl)
 {
@@ -168,14 +158,6 @@ pin_callback (const BoxType * b, void *cl)
 }
 
 static int
-pin_inlayer_callback (const BoxType * b, void *cl)
-{
-  set_pv_inlayer_color ((PinType *)b, cl, PIN_TYPE);
-  dapi->draw_pin ((PinType *)b, NULL, NULL);
-  return 1;
-}
-
-static int
 via_callback (const BoxType * b, void *cl)
 {
   set_pv_color ((PinType *)b, VIA_TYPE);
@@ -184,14 +166,6 @@ via_callback (const BoxType * b, void *cl)
 }
 
 static int
-via_inlayer_callback (const BoxType * b, void *cl)
-{
-  set_pv_inlayer_color ((PinType *)b, cl, VIA_TYPE);
-  dapi->draw_via ((PinType *)b, NULL, NULL);
-  return 1;
-}
-
-static int
 pad_callback (const BoxType * b, void *cl)
 {
   PadTypePtr pad = (PadTypePtr) b;
@@ -210,28 +184,6 @@ pad_callback (const BoxType * b, void *cl)
   return 1;
 }
 
-static int
-pad_inlayer_callback (const BoxType * b, void *cl)
-{
-  PadTypePtr pad = (PadTypePtr) b;
-  LayerType *layer = cl;
-  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
-  int group = GetLayerGroupNumberByPointer (layer);
-
-  int side = (group == solder_group) ? SOLDER_LAYER : COMPONENT_LAYER;
-
-  if (ON_SIDE (pad, side))
-    {
-      if (TEST_FLAG (WARNFLAG, pad))          gui->set_color (Output.fgGC, PCB->WarnColor);
-      else if (TEST_FLAG (SELECTEDFLAG, pad)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
-      else if (TEST_FLAG (FOUNDFLAG, pad))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
-      else                                    gui->set_color (Output.fgGC, layer->Color);
-
-      dapi->draw_pad (pad, NULL, NULL);
-    }
-  return 1;
-}
-
 static void
 draw_element_name (ElementType *element)
 {
@@ -365,20 +317,6 @@ CountHoles (int *plated, int *unplated, BoxType *drawn_area)
 }
 
 static int
-line_callback (const BoxType * b, void *cl)
-{
-  LayerType *layer = cl;
-  LineType *line = (LineType *)b;
-
-  if (TEST_FLAG (SELECTEDFLAG, line))   gui->set_color (Output.fgGC, layer->SelectedColor);
-  else if (TEST_FLAG (FOUNDFLAG, line)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
-  else                                  gui->set_color (Output.fgGC, layer->Color);
-
-  dapi->draw_line (line, NULL, NULL);
-  return 1;
-}
-
-static int
 rat_callback (const BoxType * b, void *cl)
 {
   RatType *rat = (RatType *)b;
@@ -391,20 +329,6 @@ rat_callback (const BoxType * b, void *cl)
   return 1;
 }
 
-static int
-arc_callback (const BoxType * b, void *cl)
-{
-  LayerType *layer = cl;
-  ArcType *arc = (ArcType *)b;
-
-  if (TEST_FLAG (SELECTEDFLAG, arc))   gui->set_color (Output.fgGC, layer->SelectedColor);
-  else if (TEST_FLAG (FOUNDFLAG, arc)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
-  else                                 gui->set_color (Output.fgGC, layer->Color);
-
-  dapi->draw_arc (arc, NULL, NULL);
-  return 1;
-}
-
 static void
 draw_element_package (ElementType *element)
 {
@@ -506,7 +430,7 @@ DrawEverything (BoxTypePtr drawn_area)
 	{
 	  r_search (PCB->Data->element_tree, drawn_area, NULL, element_callback, &side);
 	  r_search (PCB->Data->name_tree[NAME_INDEX (PCB)], drawn_area, NULL, name_callback, &side);
-	  DrawLayer (&(PCB->Data->Layer[max_copper_layer + side]), drawn_area);
+	  dapi->draw_layer (&(PCB->Data->Layer[max_copper_layer + side]), drawn_area, NULL);
 	}
       r_search (PCB->Data->pad_tree, drawn_area, NULL, pad_callback, &side);
     }
@@ -670,25 +594,6 @@ via_mask_callback (const BoxType * b, void *cl)
   return 1;
 }
 
-struct poly_info {
-  const BoxType *drawn_area;
-  LayerType *layer;
-};
-
-static int
-poly_callback (const BoxType * b, void *cl)
-{
-  struct poly_info *i = cl;
-  PolygonType *polygon = (PolygonType *)b;
-
-  if (TEST_FLAG (SELECTEDFLAG, polygon))   gui->set_color (Output.fgGC, i->layer->SelectedColor);
-  else if (TEST_FLAG (FOUNDFLAG, polygon)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
-  else                                     gui->set_color (Output.fgGC, i->layer->Color);
-
-  dapi->draw_poly (polygon, i->drawn_area, NULL);
-  return 1;
-}
-
 static int
 pad_mask_callback (const BoxType * b, void *cl)
 {
@@ -717,7 +622,7 @@ DrawSilk (int side, const BoxType * drawn_area)
     {
       gui->use_mask (HID_MASK_BEFORE);
 #endif
-      DrawLayer (LAYER_PTR (max_copper_layer + side), drawn_area);
+      dapi->draw_layer (LAYER_PTR (max_copper_layer + side), drawn_area, NULL);
       /* draw package */
       r_search (PCB->Data->element_tree, drawn_area, NULL, element_callback, &side);
       r_search (PCB->Data->name_tree[NAME_INDEX (PCB)], drawn_area, NULL, name_callback, &side);
@@ -732,7 +637,7 @@ DrawSilk (int side, const BoxType * drawn_area)
   if (gui->poly_after)
     {
       gui->use_mask (HID_MASK_AFTER);
-      DrawLayer (LAYER_PTR (max_copper_layer + layer), drawn_area);
+      dapi->draw_layer (LAYER_PTR (max_copper_layer + layer), drawn_area, NULL);
       /* draw package */
       r_search (PCB->Data->element_tree, drawn_area, NULL, element_callback, &side);
       r_search (PCB->Data->name_tree[NAME_INDEX (PCB)], drawn_area, NULL, name_callback, &side);
@@ -820,116 +725,6 @@ DrawRats (BoxTypePtr drawn_area)
     gui->use_mask (HID_MASK_OFF);
 }
 
-static int
-text_callback (const BoxType * b, void *cl)
-{
-  LayerType *layer = cl;
-  TextType *text = (TextType *)b;
-  int min_silk_line;
-
-  if (TEST_FLAG (SELECTEDFLAG, text))
-    gui->set_color (Output.fgGC, layer->SelectedColor);
-  else
-    gui->set_color (Output.fgGC, layer->Color);
-  if (layer == &PCB->Data->SILKLAYER ||
-      layer == &PCB->Data->BACKSILKLAYER)
-    min_silk_line = PCB->minSlk;
-  else
-    min_silk_line = PCB->minWid;
-  DrawTextLowLevel (text, min_silk_line);
-  return 1;
-}
-
-/* ---------------------------------------------------------------------------
- * draws one non-copper layer
- */
-void
-DrawLayerCommon (LayerTypePtr Layer, const BoxType * screen, bool clear_pins)
-{
-  int component_group = GetLayerGroupNumberByNumber (component_silk_layer);
-  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
-  int group = GetLayerGroupNumberByPointer (Layer);
-  struct poly_info info = {screen, Layer};
-
-  /* print the non-clearing polys */
-  r_search (Layer->polygon_tree, screen, NULL, poly_callback, &info);
-
-  if (clear_pins && TEST_FLAG (CHECKPLANESFLAG, PCB))
-    return;
-
-  /* draw all visible lines this layer */
-  r_search (Layer->line_tree, screen, NULL, line_callback, Layer);
-
-  /* draw the layer arcs on screen */
-  r_search (Layer->arc_tree, screen, NULL, arc_callback, Layer);
-
-  /* draw the layer text on screen */
-  r_search (Layer->text_tree, screen, NULL, text_callback, Layer);
-
-  /* We should check for gui->gui here, but it's kinda cool seeing the
-     auto-outline magically disappear when you first add something to
-     the "outline" layer.  */
-
-  if (strcmp (Layer->Name, "outline") == 0 ||
-      strcmp (Layer->Name, "route") == 0)
-    {
-      if (IsLayerEmpty (Layer))
-        {
-          gui->set_color (Output.fgGC, Layer->Color);
-          gui->set_line_width (Output.fgGC, PCB->minWid);
-          gui->draw_rect (Output.fgGC, 0, 0, PCB->MaxWidth, PCB->MaxHeight);
-        }
-      return;
-    }
-
-  /* draw element pins */
-  r_search (PCB->Data->pin_tree, screen, NULL, pin_inlayer_callback, Layer);
-
-  /* draw element pads */
-  if (group == component_group)
-    r_search (PCB->Data->pad_tree, screen, NULL, pad_inlayer_callback, Layer);
-
-  if (group == solder_group)
-    r_search (PCB->Data->pad_tree, screen, NULL, pad_inlayer_callback, Layer);
-
-  /* draw vias */
-  r_search (PCB->Data->via_tree, screen, NULL, via_inlayer_callback, Layer);
-  r_search (PCB->Data->pin_tree, screen, NULL, hole_callback, NULL);
-  r_search (PCB->Data->via_tree, screen, NULL, hole_callback, NULL);
-}
-
-void
-DrawLayer (LayerTypePtr Layer, const BoxType * screen)
-{
-  struct poly_info info = {screen, Layer};
-
-  /* print the non-clearing polys */
-  r_search (Layer->polygon_tree, screen, NULL, poly_callback, &info);
-
-  /* draw all visible lines this layer */
-  r_search (Layer->line_tree, screen, NULL, line_callback, Layer);
-
-  /* draw the layer arcs on screen */
-  r_search (Layer->arc_tree, screen, NULL, arc_callback, Layer);
-
-  /* draw the layer text on screen */
-  r_search (Layer->text_tree, screen, NULL, text_callback, Layer);
-
-  /* We should check for gui->gui here, but it's kinda cool seeing the
-     auto-outline magically disappear when you first add something to
-     the "outline" layer.  */
-  if (IsLayerEmpty (Layer)
-      && (strcmp (Layer->Name, "outline") == 0
-	  || strcmp (Layer->Name, "route") == 0))
-    {
-      gui->set_color (Output.fgGC, Layer->Color);
-      gui->set_line_width (Output.fgGC, PCB->minWid);
-      gui->draw_rect (Output.fgGC,
-		      0, 0,
-		      PCB->MaxWidth, PCB->MaxHeight);
-    }
-}
-
 /* ---------------------------------------------------------------------------
  * draws one layer group.  Returns non-zero if pins and pads should be
  * drawn with this group.
@@ -951,7 +746,7 @@ DrawLayerGroup (int group, const BoxType *drawn_area)
           strcmp (Layer->Name, "route") == 0)
         rv = 0;
       if (layernum < max_copper_layer && Layer->On)
-        DrawLayerCommon (Layer, drawn_area, true);
+        dapi->draw_layer (Layer, drawn_area, NULL);
     }
   if (n_entries > 1)
     rv = 1;
diff --git a/src/draw.h b/src/draw.h
index adfee36..cf324a5 100644
--- a/src/draw.h
+++ b/src/draw.h
@@ -54,7 +54,6 @@ void DrawElementName (ElementTypePtr);
 void DrawElementPackage (ElementTypePtr);
 void DrawElementPinsAndPads (ElementTypePtr);
 void DrawObject (int, void *, void *);
-void DrawLayer (LayerTypePtr, const BoxType *);
 void EraseVia (PinTypePtr);
 void EraseRat (RatTypePtr);
 void EraseViaName (PinTypePtr);
diff --git a/src/draw_funcs.c b/src/draw_funcs.c
index 49beeba..363a85e 100644
--- a/src/draw_funcs.c
+++ b/src/draw_funcs.c
@@ -1,7 +1,10 @@
 
 #include "global.h"
 #include "data.h"
+#include "misc.h"
+#include "rtree.h"
 #include "draw_funcs.h"
+#include "draw.h"
 
 static void
 _draw_pv (PinType *pv, bool draw_hole)
@@ -180,6 +183,206 @@ draw_poly (PolygonType *polygon, const BoxType *drawn_area, void *userdata)
     }
 }
 
+static int
+line_callback (const BoxType * b, void *cl)
+{
+  LayerType *layer = cl;
+  LineType *line = (LineType *)b;
+
+  if (TEST_FLAG (SELECTEDFLAG, line))   gui->set_color (Output.fgGC, layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, line)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                  gui->set_color (Output.fgGC, layer->Color);
+
+  dapi->draw_line (line, NULL, NULL);
+  return 1;
+}
+
+static int
+arc_callback (const BoxType * b, void *cl)
+{
+  LayerType *layer = cl;
+  ArcType *arc = (ArcType *)b;
+
+  if (TEST_FLAG (SELECTEDFLAG, arc))   gui->set_color (Output.fgGC, layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, arc)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                 gui->set_color (Output.fgGC, layer->Color);
+
+  dapi->draw_arc (arc, NULL, NULL);
+  return 1;
+}
+
+struct poly_info {
+  const const BoxType *drawn_area;
+  LayerType *layer;
+};
+
+static int
+poly_callback (const BoxType * b, void *cl)
+{
+  struct poly_info *i = cl;
+  PolygonType *polygon = (PolygonType *)b;
+
+  if (TEST_FLAG (SELECTEDFLAG, polygon))   gui->set_color (Output.fgGC, i->layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, polygon)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                     gui->set_color (Output.fgGC, i->layer->Color);
+
+  dapi->draw_poly (polygon, i->drawn_area, NULL);
+  return 1;
+}
+
+static int
+text_callback (const BoxType * b, void *cl)
+{
+  LayerType *layer = cl;
+  TextType *text = (TextType *)b;
+  int min_silk_line;
+
+  if (TEST_FLAG (SELECTEDFLAG, text))
+    gui->set_color (Output.fgGC, layer->SelectedColor);
+  else
+    gui->set_color (Output.fgGC, layer->Color);
+  if (layer == &PCB->Data->SILKLAYER ||
+      layer == &PCB->Data->BACKSILKLAYER)
+    min_silk_line = PCB->minSlk;
+  else
+    min_silk_line = PCB->minWid;
+  DrawTextLowLevel (text, min_silk_line);
+  return 1;
+}
+
+static void
+set_pv_inlayer_color (PinType *pv, LayerType *layer, int type)
+{
+  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
+  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, (type == VIA_TYPE) ? PCB->ViaSelectedColor
+                                                                                         : PCB->PinSelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, pv))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                   gui->set_color (Output.fgGC, layer->Color);
+}
+
+static int
+pin_inlayer_callback (const BoxType * b, void *cl)
+{
+  set_pv_inlayer_color ((PinType *)b, cl, PIN_TYPE);
+  dapi->draw_pin ((PinType *)b, NULL, NULL);
+  return 1;
+}
+
+static int
+via_inlayer_callback (const BoxType * b, void *cl)
+{
+  set_pv_inlayer_color ((PinType *)b, cl, VIA_TYPE);
+  dapi->draw_via ((PinType *)b, NULL, NULL);
+  return 1;
+}
+
+static int
+pad_inlayer_callback (const BoxType * b, void *cl)
+{
+  PadTypePtr pad = (PadTypePtr) b;
+  LayerType *layer = cl;
+  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
+  int group = GetLayerGroupNumberByPointer (layer);
+
+  int side = (group == solder_group) ? SOLDER_LAYER : COMPONENT_LAYER;
+
+  if (ON_SIDE (pad, side))
+    {
+      if (TEST_FLAG (WARNFLAG, pad))          gui->set_color (Output.fgGC, PCB->WarnColor);
+      else if (TEST_FLAG (SELECTEDFLAG, pad)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+      else if (TEST_FLAG (FOUNDFLAG, pad))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+      else                                    gui->set_color (Output.fgGC, layer->Color);
+
+      dapi->draw_pad (pad, NULL, NULL);
+    }
+  return 1;
+}
+
+static int
+hole_callback (const BoxType * b, void *cl)
+{
+  PinTypePtr pv = (PinTypePtr) b;
+  int plated = cl ? *(int *) cl : -1;
+
+  if ((plated == 0 && !TEST_FLAG (HOLEFLAG, pv)) ||
+      (plated == 1 &&  TEST_FLAG (HOLEFLAG, pv)))
+    return 1;
+
+  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
+  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+  else                                   gui->set_color (Output.fgGC, Settings.BlackColor);
+
+  dapi->draw_hole (pv, NULL, NULL);
+  return 1;
+}
+
+static void
+draw_layer (LayerType *layer, const BoxType *drawn_area, void *userdata)
+{
+  int component_group = GetLayerGroupNumberByNumber (component_silk_layer);
+  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
+  int layer_num = GetLayerNumber (PCB->Data, layer);
+  int group = GetLayerGroupNumberByPointer (layer);
+  struct poly_info info = {drawn_area, layer};
+
+  /* print the non-clearing polys */
+  r_search (layer->polygon_tree, drawn_area, NULL, poly_callback, &info);
+
+  if (TEST_FLAG (CHECKPLANESFLAG, PCB))
+    return;
+
+  /* draw all visible lines this layer */
+  r_search (layer->line_tree, drawn_area, NULL, line_callback, layer);
+
+  /* draw the layer arcs on drawn_area */
+  r_search (layer->arc_tree, drawn_area, NULL, arc_callback, layer);
+
+  /* draw the layer text on drawn_area */
+  r_search (layer->text_tree, drawn_area, NULL, text_callback, layer);
+
+  /* We should check for gui->gui here, but it's kinda cool seeing the
+     auto-outline magically disappear when you first add something to
+     the "outline" layer.  */
+
+  if (strcmp (layer->Name, "outline") == 0 ||
+      strcmp (layer->Name, "route") == 0)
+    {
+      if (IsLayerEmpty (layer))
+        {
+          gui->set_color (Output.fgGC, layer->Color);
+          gui->set_line_width (Output.fgGC, PCB->minWid);
+          gui->draw_rect (Output.fgGC, 0, 0, PCB->MaxWidth, PCB->MaxHeight);
+        }
+      return;
+    }
+
+  /* Don't draw vias on silk layers */
+  if (layer_num >= max_copper_layer)
+    return;
+
+#if 0
+  /* Don't draw vias on layers which are out of the layer stack */
+  if ((group >= component_group && group >= solder_group) ||
+      (group <= component_group && group <= solder_group))
+    return;
+#endif
+
+  /* draw element pins */
+  r_search (PCB->Data->pin_tree, drawn_area, NULL, pin_inlayer_callback, layer);
+
+  /* draw element pads */
+  if (group == component_group)
+    r_search (PCB->Data->pad_tree, drawn_area, NULL, pad_inlayer_callback, layer);
+
+  if (group == solder_group)
+    r_search (PCB->Data->pad_tree, drawn_area, NULL, pad_inlayer_callback, layer);
+
+  /* draw vias */
+  r_search (PCB->Data->via_tree, drawn_area, NULL, via_inlayer_callback, layer);
+  r_search (PCB->Data->pin_tree, drawn_area, NULL, hole_callback, NULL);
+  r_search (PCB->Data->via_tree, drawn_area, NULL, hole_callback, NULL);
+}
+
 struct draw_funcs d_f = {
   .draw_pin       = draw_pin,
   .draw_pin_mask  = draw_pin_mask,
@@ -193,6 +396,7 @@ struct draw_funcs d_f = {
   .draw_rat       = draw_rat,
   .draw_arc       = draw_arc,
   .draw_poly      = draw_poly,
+  .draw_layer     = draw_layer,
 };
 
 struct draw_funcs *dapi = &d_f;
diff --git a/src/draw_funcs.h b/src/draw_funcs.h
index 1f97d82..25c33a1 100644
--- a/src/draw_funcs.h
+++ b/src/draw_funcs.h
@@ -11,6 +11,7 @@ struct draw_funcs {
   void (*draw_rat)       (RatType *,     const BoxType *, void *);
   void (*draw_arc)       (ArcType *,     const BoxType *, void *);
   void (*draw_poly)      (PolygonType *, const BoxType *, void *);
+  void (*draw_layer)     (LayerType *,   const BoxType *, void *);
 };
 
 extern struct draw_funcs *dapi;
diff --git a/src/hid/gerber/gerber.c b/src/hid/gerber/gerber.c
index d5843ef..4429121 100644
--- a/src/hid/gerber/gerber.c
+++ b/src/hid/gerber/gerber.c
@@ -26,6 +26,7 @@
 #include "misc.h"
 #include "error.h"
 #include "draw.h"
+#include "draw_funcs.h"
 
 #include "hid.h"
 #include "../hidint.h"
@@ -719,7 +720,7 @@ gerber_set_layer (const char *name, int group, int empty)
     {
       if (outline_layer
 	  && outline_layer != PCB->Data->Layer+idx)
-	DrawLayer (outline_layer, &region);
+	dapi->draw_layer (outline_layer, &region, NULL);
       else if (!outline_layer)
 	{
 	  hidGC gc = gui->make_gc ();
diff --git a/src/hid/ps/ps.c b/src/hid/ps/ps.c
index a417753..8024abc 100644
--- a/src/hid/ps/ps.c
+++ b/src/hid/ps/ps.c
@@ -16,6 +16,7 @@
 #include "misc.h"
 #include "error.h"
 #include "draw.h"
+#include "draw_funcs.h"
 
 #include "hid.h"
 #include "../hidint.h"
@@ -863,7 +864,7 @@ ps_set_layer (const char *name, int group, int empty)
       && strcmp (name, "outline")
       && strcmp (name, "route"))
     {
-      DrawLayer (outline_layer, &region);
+      dapi->draw_layer (outline_layer, &region, NULL);
     }
 
   return 1;

commit c96e65eeb94c569e81cc940d4a10dd54e3b7ebc1
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    Crasy test

diff --git a/src/Makefile.am b/src/Makefile.am
index 5abbfb2..34cd5b3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,8 @@ PCB_SRCS = \
 	dolists.h \
 	draw.c \
 	draw.h \
+	draw_funcs.c \
+	draw_funcs.h \
 	drill.c \
 	drill.h \
 	edif.y \
diff --git a/src/draw.c b/src/draw.c
index 8e8821d..cc04a43 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -41,6 +41,7 @@
 #include "crosshair.h"
 #include "data.h"
 #include "draw.h"
+#include "draw_funcs.h"
 #include "error.h"
 #include "mymem.h"
 #include "misc.h"
@@ -85,54 +86,12 @@ static void DrawEverything (BoxTypePtr);
 static void DrawPPV (int group, const BoxType *);
 static int DrawLayerGroup (int, const BoxType *);
 static void AddPart (void *);
-static void SetPVColor (PinTypePtr, int);
 static void DrawEMark (ElementTypePtr, LocationType, LocationType, bool);
 static void DrawMask (int side, BoxType *);
 static void DrawPaste (int side, BoxType *);
 static void DrawRats (BoxType *);
 static void DrawSilk (int side, const BoxType *);
 
-/*--------------------------------------------------------------------------------------
- * setup color for pin or via
- */
-static void
-SetPVColor (PinTypePtr Pin, int Type)
-{
-  char *color;
-
-  if (Type == VIA_TYPE)
-    {
-      if (!doing_pinout
-	  && TEST_FLAG (WARNFLAG | SELECTEDFLAG | FOUNDFLAG, Pin))
-	{
-	  if (TEST_FLAG (WARNFLAG, Pin))
-	    color = PCB->WarnColor;
-	  else if (TEST_FLAG (SELECTEDFLAG, Pin))
-	    color = PCB->ViaSelectedColor;
-	  else
-	    color = PCB->ConnectedColor;
-	}
-      else
-	color = PCB->ViaColor;
-    }
-  else
-    {
-      if (!doing_pinout
-	  && TEST_FLAG (WARNFLAG | SELECTEDFLAG | FOUNDFLAG, Pin))
-	{
-	  if (TEST_FLAG (WARNFLAG, Pin))
-	    color = PCB->WarnColor;
-	  else if (TEST_FLAG (SELECTEDFLAG, Pin))
-	    color = PCB->PinSelectedColor;
-	  else
-	    color = PCB->ConnectedColor;
-	}
-      else
-	color = PCB->PinColor;
-    }
-
-  gui->set_color (Output.fgGC, color);
-}
 
 /*---------------------------------------------------------------------------
  *  Adds the update rect to the update region
@@ -180,172 +139,96 @@ Redraw (void)
 }
 
 static void
-_draw_pv_name (PinType *pv)
+set_pv_color (PinType *pv, int type)
 {
-  BoxType box;
-  bool vert;
-  TextType text;
-
-  if (!pv->Name || !pv->Name[0])
-    text.TextString = EMPTY (pv->Number);
-  else
-    text.TextString = EMPTY (TEST_FLAG (SHOWNUMBERFLAG, PCB) ? pv->Number : pv->Name);
-
-  vert = TEST_FLAG (EDGE2FLAG, pv);
-
-  if (vert)
-    {
-      box.X1 = pv->X - pv->Thickness    / 2 + Settings.PinoutTextOffsetY;
-      box.Y1 = pv->Y - pv->DrillingHole / 2 - Settings.PinoutTextOffsetX;
-    }
-  else
-    {
-      box.X1 = pv->X + pv->DrillingHole / 2 + Settings.PinoutTextOffsetX;
-      box.Y1 = pv->Y - pv->Thickness    / 2 + Settings.PinoutTextOffsetY;
-    }
-
-  gui->set_color (Output.fgGC, PCB->PinNameColor);
-
-  text.Flags = NoFlags ();
-  text.Scale = pv->Thickness / 80;
-  text.X = box.X1;
-  text.Y = box.Y1;
-  text.Direction = vert ? 1 : 0;
-
-  if (gui->gui)
-    doing_pinout++;
-  DrawTextLowLevel (&text, 0);
-  if (gui->gui)
-    doing_pinout--;
+  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
+  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, (type == VIA_TYPE) ? PCB->ViaSelectedColor
+                                                                                         : PCB->PinSelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, pv))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                   gui->set_color (Output.fgGC, (type == VIA_TYPE) ? PCB->ViaColor
+                                                                                         : PCB->PinColor);
 }
 
 static void
-_draw_pv (PinTypePtr pv, bool draw_hole)
+set_pv_inlayer_color (PinType *pv, LayerType *layer, int type)
 {
-  if (TEST_FLAG (THINDRAWFLAG, PCB))
-    gui->thindraw_pcb_pv (Output.fgGC, Output.fgGC, pv, draw_hole, false);
-  else
-    gui->fill_pcb_pv (Output.fgGC, Output.bgGC, pv, draw_hole, false);
-
-  if (!TEST_FLAG (HOLEFLAG, pv) && TEST_FLAG (DISPLAYNAMEFLAG, pv))
-    _draw_pv_name (pv);
-}
-
-static void
-draw_pin (PinTypePtr pin, bool draw_hole)
-{
-  SetPVColor (pin, PIN_TYPE);
-  _draw_pv (pin, draw_hole);
+  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
+  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, (type == VIA_TYPE) ? PCB->ViaSelectedColor
+                                                                                         : PCB->PinSelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, pv))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                   gui->set_color (Output.fgGC, layer->Color);
 }
 
 static int
 pin_callback (const BoxType * b, void *cl)
 {
-  draw_pin ((PinType *)b, false);
+  set_pv_color ((PinType *)b, PIN_TYPE);
+  dapi->draw_pin ((PinType *)b, NULL, NULL);
   return 1;
 }
 
-static void
-draw_via (PinTypePtr via, bool draw_hole)
+static int
+pin_inlayer_callback (const BoxType * b, void *cl)
 {
-  SetPVColor (via, VIA_TYPE);
-  _draw_pv (via, draw_hole);
+  set_pv_inlayer_color ((PinType *)b, cl, PIN_TYPE);
+  dapi->draw_pin ((PinType *)b, NULL, NULL);
+  return 1;
 }
 
 static int
 via_callback (const BoxType * b, void *cl)
 {
-  draw_via ((PinType *)b, false);
+  set_pv_color ((PinType *)b, VIA_TYPE);
+  dapi->draw_via ((PinType *)b, NULL, NULL);
   return 1;
 }
 
-static void
-draw_pad_name (PadType *pad)
+static int
+via_inlayer_callback (const BoxType * b, void *cl)
 {
-  BoxType box;
-  bool vert;
-  TextType text;
-
-  if (!pad->Name || !pad->Name[0])
-    text.TextString = EMPTY (pad->Number);
-  else
-    text.TextString = EMPTY (TEST_FLAG (SHOWNUMBERFLAG, PCB) ? pad->Number : pad->Name);
-
-  /* should text be vertical ? */
-  vert = (pad->Point1.X == pad->Point2.X);
-
-  if (vert)
-    {
-      box.X1 = pad->Point1.X                      - pad->Thickness / 2;
-      box.Y1 = MAX (pad->Point1.Y, pad->Point2.Y) + pad->Thickness / 2;
-      box.X1 += Settings.PinoutTextOffsetY;
-      box.Y1 -= Settings.PinoutTextOffsetX;
-    }
-  else
-    {
-      box.X1 = MIN (pad->Point1.X, pad->Point2.X) - pad->Thickness / 2;
-      box.Y1 = pad->Point1.Y                      - pad->Thickness / 2;
-      box.X1 += Settings.PinoutTextOffsetX;
-      box.Y1 += Settings.PinoutTextOffsetY;
-    }
-
-  gui->set_color (Output.fgGC, PCB->PinNameColor);
-
-  text.Flags = NoFlags ();
-  text.Scale = pad->Thickness / 50;
-  text.X = box.X1;
-  text.Y = box.Y1;
-  text.Direction = vert ? 1 : 0;
-
-  DrawTextLowLevel (&text, 0);
+  set_pv_inlayer_color ((PinType *)b, cl, VIA_TYPE);
+  dapi->draw_via ((PinType *)b, NULL, NULL);
+  return 1;
 }
 
-static void
-_draw_pad (hidGC gc, PadType *pad, bool clear, bool mask)
+static int
+pad_callback (const BoxType * b, void *cl)
 {
-  if (clear && !mask && pad->Clearance <= 0)
-    return;
-
-  if (TEST_FLAG (THINDRAWFLAG, PCB) ||
-      (clear && TEST_FLAG (THINDRAWPOLYFLAG, PCB)))
-    gui->thindraw_pcb_pad (gc, pad, clear, mask);
-  else
-    gui->fill_pcb_pad (gc, pad, clear, mask);
-}
-
-static void
-draw_pad (PadType *pad)
-{
-  if (doing_pinout)
-   gui->set_color (Output.fgGC, PCB->PinColor);
-  else if (TEST_FLAG (WARNFLAG | SELECTEDFLAG | FOUNDFLAG, pad))
-   {
-     if (TEST_FLAG (WARNFLAG, pad))
-       gui->set_color (Output.fgGC, PCB->WarnColor);
-     else if (TEST_FLAG (SELECTEDFLAG, pad))
-       gui->set_color (Output.fgGC, PCB->PinSelectedColor);
-     else
-       gui->set_color (Output.fgGC, PCB->ConnectedColor);
-   }
-  else if (FRONT (pad))
-   gui->set_color (Output.fgGC, PCB->PinColor);
-  else
-   gui->set_color (Output.fgGC, PCB->InvisibleObjectsColor);
+  PadTypePtr pad = (PadTypePtr) b;
+  int *side = cl;
 
-  _draw_pad (Output.fgGC, pad, false, false);
+  if (ON_SIDE (pad, *side))
+    {
+      if (TEST_FLAG (WARNFLAG, pad))          gui->set_color (Output.fgGC, PCB->WarnColor);
+      else if (TEST_FLAG (SELECTEDFLAG, pad)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+      else if (TEST_FLAG (FOUNDFLAG, pad))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+      else if (FRONT (pad))                   gui->set_color (Output.fgGC, PCB->PinColor);
+      else                                    gui->set_color (Output.fgGC, PCB->InvisibleObjectsColor);
 
-  if (doing_pinout || TEST_FLAG (DISPLAYNAMEFLAG, pad))
-    draw_pad_name (pad);
+      dapi->draw_pad (pad, NULL, NULL);
+    }
+  return 1;
 }
 
 static int
-pad_callback (const BoxType * b, void *cl)
+pad_inlayer_callback (const BoxType * b, void *cl)
 {
   PadTypePtr pad = (PadTypePtr) b;
-  int *side = cl;
+  LayerType *layer = cl;
+  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
+  int group = GetLayerGroupNumberByPointer (layer);
 
-  if (ON_SIDE (pad, *side))
-    draw_pad (pad);
+  int side = (group == solder_group) ? SOLDER_LAYER : COMPONENT_LAYER;
+
+  if (ON_SIDE (pad, side))
+    {
+      if (TEST_FLAG (WARNFLAG, pad))          gui->set_color (Output.fgGC, PCB->WarnColor);
+      else if (TEST_FLAG (SELECTEDFLAG, pad)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+      else if (TEST_FLAG (FOUNDFLAG, pad))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+      else                                    gui->set_color (Output.fgGC, layer->Color);
+
+      dapi->draw_pad (pad, NULL, NULL);
+    }
   return 1;
 }
 
@@ -387,12 +270,27 @@ draw_element_pins_and_pads (ElementType *element)
   PAD_LOOP (element);
   {
     if (doing_pinout || doing_assy || FRONT (pad) || PCB->InvisibleObjectsOn)
-      draw_pad (pad);
+      {
+        if (TEST_FLAG (WARNFLAG, pad))          gui->set_color (Output.fgGC, PCB->WarnColor);
+        else if (TEST_FLAG (SELECTEDFLAG, pad)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+        else if (TEST_FLAG (FOUNDFLAG, pad))    gui->set_color (Output.fgGC, PCB->ConnectedColor);
+        else if (FRONT (pad))                   gui->set_color (Output.fgGC, PCB->PinColor);
+        else                                    gui->set_color (Output.fgGC, PCB->InvisibleObjectsColor);
+
+        dapi->draw_pad (pad, NULL, NULL);
+      }
   }
   END_LOOP;
   PIN_LOOP (element);
   {
-    draw_pin (pin, true);
+    set_pv_color (pin, PIN_TYPE);
+    dapi->draw_pin (pin, NULL, NULL);
+
+    if (TEST_FLAG (WARNFLAG, pin))          gui->set_color (Output.fgGC, PCB->WarnColor);
+    else if (TEST_FLAG (SELECTEDFLAG, pin)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+    else                                    gui->set_color (Output.fgGC, Settings.BlackColor);
+
+    dapi->draw_hole (pin, NULL, NULL);
   }
   END_LOOP;
 }
@@ -416,35 +314,11 @@ hole_callback (const BoxType * b, void *cl)
       (plated == 1 &&  TEST_FLAG (HOLEFLAG, pv)))
     return 1;
 
-  if (TEST_FLAG (THINDRAWFLAG, PCB))
-    {
-      if (!TEST_FLAG (HOLEFLAG, pv))
-        {
-          gui->set_line_cap (Output.fgGC, Round_Cap);
-          gui->set_line_width (Output.fgGC, 0);
-          gui->draw_arc (Output.fgGC,
-                         pv->X, pv->Y, pv->DrillingHole / 2,
-                         pv->DrillingHole / 2, 0, 360);
-        }
-    }
-  else
-    gui->fill_circle (Output.bgGC, pv->X, pv->Y, pv->DrillingHole / 2);
+  if (TEST_FLAG (WARNFLAG, pv))          gui->set_color (Output.fgGC, PCB->WarnColor);
+  else if (TEST_FLAG (SELECTEDFLAG, pv)) gui->set_color (Output.fgGC, PCB->PinSelectedColor);
+  else                                   gui->set_color (Output.fgGC, Settings.BlackColor);
 
-  if (TEST_FLAG (HOLEFLAG, pv))
-    {
-      if (TEST_FLAG (WARNFLAG, pv))
-        gui->set_color (Output.fgGC, PCB->WarnColor);
-      else if (TEST_FLAG (SELECTEDFLAG, pv))
-        gui->set_color (Output.fgGC, PCB->ViaSelectedColor);
-      else
-        gui->set_color (Output.fgGC, Settings.BlackColor);
-
-      gui->set_line_cap (Output.fgGC, Round_Cap);
-      gui->set_line_width (Output.fgGC, 0);
-      gui->draw_arc (Output.fgGC,
-                     pv->X, pv->Y, pv->DrillingHole / 2,
-                     pv->DrillingHole / 2, 0, 360);
-    }
+  dapi->draw_hole (pv, NULL, NULL);
   return 1;
 }
 
@@ -490,39 +364,17 @@ CountHoles (int *plated, int *unplated, BoxType *drawn_area)
   if (unplated != NULL) *unplated = hcs.nunplated;
 }
 
-static void
-_draw_line (LineType *line)
-{
-  gui->set_line_cap (Output.fgGC, Trace_Cap);
-  if (TEST_FLAG (THINDRAWFLAG, PCB))
-    gui->set_line_width (Output.fgGC, 0);
-  else
-    gui->set_line_width (Output.fgGC, line->Thickness);
-
-  gui->draw_line (Output.fgGC,
-		  line->Point1.X, line->Point1.Y,
-		  line->Point2.X, line->Point2.Y);
-}
-
-static void
-draw_line (LayerType *layer, LineType *line)
-{
-  if (TEST_FLAG (SELECTEDFLAG | FOUNDFLAG, line))
-    {
-      if (TEST_FLAG (SELECTEDFLAG, line))
-        gui->set_color (Output.fgGC, layer->SelectedColor);
-      else
-        gui->set_color (Output.fgGC, PCB->ConnectedColor);
-    }
-  else
-    gui->set_color (Output.fgGC, layer->Color);
-  _draw_line (line);
-}
-
 static int
 line_callback (const BoxType * b, void *cl)
 {
-  draw_line ((LayerType *) cl, (LineType *) b);
+  LayerType *layer = cl;
+  LineType *line = (LineType *)b;
+
+  if (TEST_FLAG (SELECTEDFLAG, line))   gui->set_color (Output.fgGC, layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, line)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                  gui->set_color (Output.fgGC, layer->Color);
+
+  dapi->draw_line (line, NULL, NULL);
   return 1;
 }
 
@@ -531,71 +383,25 @@ rat_callback (const BoxType * b, void *cl)
 {
   RatType *rat = (RatType *)b;
 
-  if (TEST_FLAG (SELECTEDFLAG | FOUNDFLAG, rat))
-    {
-      if (TEST_FLAG (SELECTEDFLAG, rat))
-        gui->set_color (Output.fgGC, PCB->RatSelectedColor);
-      else
-        gui->set_color (Output.fgGC, PCB->ConnectedColor);
-    }
-  else
-    gui->set_color (Output.fgGC, PCB->RatColor);
-
-  if (Settings.RatThickness < 20)
-    rat->Thickness = pixel_slop * Settings.RatThickness;
-  /* rats.c set VIAFLAG if this rat goes to a containing poly: draw a donut */
-  if (TEST_FLAG(VIAFLAG, rat))
-    {
-      int w = rat->Thickness;
+  if (TEST_FLAG (SELECTEDFLAG, rat))   gui->set_color (Output.fgGC, PCB->RatSelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, rat)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                 gui->set_color (Output.fgGC, PCB->RatColor);
 
-      if (TEST_FLAG (THINDRAWFLAG, PCB))
-        gui->set_line_width (Output.fgGC, 0);
-      else
-        gui->set_line_width (Output.fgGC, w);
-      gui->draw_arc (Output.fgGC, rat->Point1.X, rat->Point1.Y,
-                     w * 2, w * 2, 0, 360);
-    }
-  else
-    _draw_line ((LineType *) rat);
+  dapi->draw_rat (rat, NULL, NULL);
   return 1;
 }
 
-static void
-_draw_arc (ArcType *arc)
-{
-  if (!arc->Thickness)
-    return;
-
-  if (TEST_FLAG (THINDRAWFLAG, PCB))
-    gui->set_line_width (Output.fgGC, 0);
-  else
-    gui->set_line_width (Output.fgGC, arc->Thickness);
-  gui->set_line_cap (Output.fgGC, Trace_Cap);
-
-  gui->draw_arc (Output.fgGC, arc->X, arc->Y, arc->Width,
-                 arc->Height, arc->StartAngle, arc->Delta);
-}
-
-static void
-draw_arc (LayerType *layer, ArcType *arc)
-{
-  if (TEST_FLAG (SELECTEDFLAG | FOUNDFLAG, arc))
-    {
-      if (TEST_FLAG (SELECTEDFLAG, arc))
-        gui->set_color (Output.fgGC, layer->SelectedColor);
-      else
-        gui->set_color (Output.fgGC, PCB->ConnectedColor);
-    }
-  else
-    gui->set_color (Output.fgGC, layer->Color);
-
-  _draw_arc (arc);
-}
-
 static int
 arc_callback (const BoxType * b, void *cl)
 {
-  draw_arc ((LayerTypePtr) cl, (ArcTypePtr) b);
+  LayerType *layer = cl;
+  ArcType *arc = (ArcType *)b;
+
+  if (TEST_FLAG (SELECTEDFLAG, arc))   gui->set_color (Output.fgGC, layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, arc)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                 gui->set_color (Output.fgGC, layer->Color);
+
+  dapi->draw_arc (arc, NULL, NULL);
   return 1;
 }
 
@@ -615,12 +421,14 @@ draw_element_package (ElementType *element)
   /* draw lines, arcs, text and pins */
   ELEMENTLINE_LOOP (element);
   {
-    _draw_line (line);
+    //_draw_line (line);
+    dapi->draw_line (line, NULL, NULL);
   }
   END_LOOP;
   ARC_LOOP (element);
   {
-    _draw_arc (arc);
+    //_draw_arc (arc);
+    dapi->draw_arc (arc, NULL, NULL);
   }
   END_LOOP;
 }
@@ -849,13 +657,16 @@ DrawPPV (int group, const BoxType *drawn_area)
 }
 
 static int
-clearPin_callback (const BoxType * b, void *cl)
+pin_mask_callback (const BoxType * b, void *cl)
 {
-  PinType *pin = (PinTypePtr) b;
-  if (TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG (THINDRAWPOLYFLAG, PCB))
-    gui->thindraw_pcb_pv (Output.pmGC, Output.pmGC, pin, false, true);
-  else
-    gui->fill_pcb_pv (Output.pmGC, Output.pmGC, pin, false, true);
+  dapi->draw_pin_mask ((PinType *) b, NULL, NULL);
+  return 1;
+}
+
+static int
+via_mask_callback (const BoxType * b, void *cl)
+{
+  dapi->draw_via_mask ((PinType *) b, NULL, NULL);
   return 1;
 }
 
@@ -869,49 +680,22 @@ poly_callback (const BoxType * b, void *cl)
 {
   struct poly_info *i = cl;
   PolygonType *polygon = (PolygonType *)b;
-  static char *color;
-
-  if (!polygon->Clipped)
-    return 0;
 
-  if (TEST_FLAG (SELECTEDFLAG, polygon))
-    color = i->layer->SelectedColor;
-  else if (TEST_FLAG (FOUNDFLAG, polygon))
-    color = PCB->ConnectedColor;
-  else
-    color = i->layer->Color;
-  gui->set_color (Output.fgGC, color);
-
-  if (gui->thindraw_pcb_polygon != NULL &&
-      (TEST_FLAG (THINDRAWFLAG, PCB) ||
-       TEST_FLAG (THINDRAWPOLYFLAG, PCB)))
-    gui->thindraw_pcb_polygon (Output.fgGC, polygon, i->drawn_area);
-  else
-    gui->fill_pcb_polygon (Output.fgGC, polygon, i->drawn_area);
-
-  /* If checking planes, thin-draw any pieces which have been clipped away */
-  if (gui->thindraw_pcb_polygon != NULL &&
-      TEST_FLAG (CHECKPLANESFLAG, PCB) &&
-      !TEST_FLAG (FULLPOLYFLAG, polygon))
-    {
-      PolygonType poly = *polygon;
-
-      for (poly.Clipped = polygon->Clipped->f;
-           poly.Clipped != polygon->Clipped;
-           poly.Clipped = poly.Clipped->f)
-        gui->thindraw_pcb_polygon (Output.fgGC, &poly, i->drawn_area);
-    }
+  if (TEST_FLAG (SELECTEDFLAG, polygon))   gui->set_color (Output.fgGC, i->layer->SelectedColor);
+  else if (TEST_FLAG (FOUNDFLAG, polygon)) gui->set_color (Output.fgGC, PCB->ConnectedColor);
+  else                                     gui->set_color (Output.fgGC, i->layer->Color);
 
+  dapi->draw_poly (polygon, i->drawn_area, NULL);
   return 1;
 }
 
 static int
-clearPad_callback (const BoxType * b, void *cl)
+pad_mask_callback (const BoxType * b, void *cl)
 {
   PadTypePtr pad = (PadTypePtr) b;
   int *side = cl;
-  if (ON_SIDE (pad, *side) && pad->Mask)
-    _draw_pad (Output.pmGC, pad, true, true);
+  if (ON_SIDE (pad, *side))
+    dapi->draw_pad_mask (pad, NULL, NULL);
   return 1;
 }
 
@@ -941,9 +725,9 @@ DrawSilk (int side, const BoxType * drawn_area)
     }
 
   gui->use_mask (HID_MASK_CLEAR);
-  r_search (PCB->Data->pin_tree, drawn_area, NULL, clearPin_callback, NULL);
-  r_search (PCB->Data->via_tree, drawn_area, NULL, clearPin_callback, NULL);
-  r_search (PCB->Data->pad_tree, drawn_area, NULL, clearPad_callback, &side);
+  r_search (PCB->Data->pin_tree, drawn_area, NULL, pin_mask_callback, NULL);
+  r_search (PCB->Data->via_tree, drawn_area, NULL, via_mask_callback, NULL);
+  r_search (PCB->Data->pad_tree, drawn_area, NULL, pad_mask_callback, &side);
 
   if (gui->poly_after)
     {
@@ -991,9 +775,9 @@ DrawMask (int side, BoxType * screen)
       gui->use_mask (HID_MASK_CLEAR);
     }
 
-  r_search (PCB->Data->pin_tree, screen, NULL, clearPin_callback, NULL);
-  r_search (PCB->Data->via_tree, screen, NULL, clearPin_callback, NULL);
-  r_search (PCB->Data->pad_tree, screen, NULL, clearPad_callback, &side);
+  r_search (PCB->Data->pin_tree, screen, NULL, pin_mask_callback, NULL);
+  r_search (PCB->Data->via_tree, screen, NULL, via_mask_callback, NULL);
+  r_search (PCB->Data->pad_tree, screen, NULL, pad_mask_callback, &side);
 
   if (thin)
     gui->set_color (Output.pmGC, "erase");
@@ -1013,13 +797,8 @@ DrawPaste (int side, BoxType *drawn_area)
   gui->set_color (Output.fgGC, PCB->ElementColor);
   ALLPAD_LOOP (PCB->Data);
   {
-    if (ON_SIDE (pad, side) && !TEST_FLAG (NOPASTEFLAG, pad) && pad->Mask > 0)
-      {
-        if (pad->Mask < pad->Thickness)
-          _draw_pad (Output.fgGC, pad, true, true);
-        else
-          _draw_pad (Output.fgGC, pad, false, false);
-      }
+    if (ON_SIDE (pad, side))
+      dapi->draw_pad_paste (pad, NULL, NULL);
   }
   ENDALL_LOOP;
 }
@@ -1067,6 +846,9 @@ text_callback (const BoxType * b, void *cl)
 void
 DrawLayerCommon (LayerTypePtr Layer, const BoxType * screen, bool clear_pins)
 {
+  int component_group = GetLayerGroupNumberByNumber (component_silk_layer);
+  int solder_group = GetLayerGroupNumberByNumber (solder_silk_layer);
+  int group = GetLayerGroupNumberByPointer (Layer);
   struct poly_info info = {screen, Layer};
 
   /* print the non-clearing polys */
@@ -1087,6 +869,55 @@ DrawLayerCommon (LayerTypePtr Layer, const BoxType * screen, bool clear_pins)
   /* We should check for gui->gui here, but it's kinda cool seeing the
      auto-outline magically disappear when you first add something to
      the "outline" layer.  */
+
+  if (strcmp (Layer->Name, "outline") == 0 ||
+      strcmp (Layer->Name, "route") == 0)
+    {
+      if (IsLayerEmpty (Layer))
+        {
+          gui->set_color (Output.fgGC, Layer->Color);
+          gui->set_line_width (Output.fgGC, PCB->minWid);
+          gui->draw_rect (Output.fgGC, 0, 0, PCB->MaxWidth, PCB->MaxHeight);
+        }
+      return;
+    }
+
+  /* draw element pins */
+  r_search (PCB->Data->pin_tree, screen, NULL, pin_inlayer_callback, Layer);
+
+  /* draw element pads */
+  if (group == component_group)
+    r_search (PCB->Data->pad_tree, screen, NULL, pad_inlayer_callback, Layer);
+
+  if (group == solder_group)
+    r_search (PCB->Data->pad_tree, screen, NULL, pad_inlayer_callback, Layer);
+
+  /* draw vias */
+  r_search (PCB->Data->via_tree, screen, NULL, via_inlayer_callback, Layer);
+  r_search (PCB->Data->pin_tree, screen, NULL, hole_callback, NULL);
+  r_search (PCB->Data->via_tree, screen, NULL, hole_callback, NULL);
+}
+
+void
+DrawLayer (LayerTypePtr Layer, const BoxType * screen)
+{
+  struct poly_info info = {screen, Layer};
+
+  /* print the non-clearing polys */
+  r_search (Layer->polygon_tree, screen, NULL, poly_callback, &info);
+
+  /* draw all visible lines this layer */
+  r_search (Layer->line_tree, screen, NULL, line_callback, Layer);
+
+  /* draw the layer arcs on screen */
+  r_search (Layer->arc_tree, screen, NULL, arc_callback, Layer);
+
+  /* draw the layer text on screen */
+  r_search (Layer->text_tree, screen, NULL, text_callback, Layer);
+
+  /* We should check for gui->gui here, but it's kinda cool seeing the
+     auto-outline magically disappear when you first add something to
+     the "outline" layer.  */
   if (IsLayerEmpty (Layer)
       && (strcmp (Layer->Name, "outline") == 0
 	  || strcmp (Layer->Name, "route") == 0))
@@ -1099,12 +930,6 @@ DrawLayerCommon (LayerTypePtr Layer, const BoxType * screen, bool clear_pins)
     }
 }
 
-void
-DrawLayer (LayerTypePtr Layer, const BoxType * screen)
-{
-  DrawLayerCommon (Layer, screen, false);
-}
-
 /* ---------------------------------------------------------------------------
  * draws one layer group.  Returns non-zero if pins and pads should be
  * drawn with this group.
@@ -1195,6 +1020,20 @@ GatherPadName (PadTypePtr Pad)
   return;
 }
 
+static void
+_draw_line (LineType *line)
+{
+  gui->set_line_cap (Output.fgGC, Trace_Cap);
+  if (TEST_FLAG (THINDRAWFLAG, PCB))
+    gui->set_line_width (Output.fgGC, 0);
+  else
+    gui->set_line_width (Output.fgGC, line->Thickness);
+
+  gui->draw_line (Output.fgGC,
+                  line->Point1.X, line->Point1.Y,
+                  line->Point2.X, line->Point2.Y);
+}
+
 /* ---------------------------------------------------------------------------
  * lowlevel drawing routine for text objects
  */
diff --git a/src/draw_funcs.c b/src/draw_funcs.c
new file mode 100644
index 0000000..49beeba
--- /dev/null
+++ b/src/draw_funcs.c
@@ -0,0 +1,198 @@
+
+#include "global.h"
+#include "data.h"
+#include "draw_funcs.h"
+
+static void
+_draw_pv (PinType *pv, bool draw_hole)
+{
+  if (TEST_FLAG (THINDRAWFLAG, PCB))
+    gui->thindraw_pcb_pv (Output.fgGC, Output.fgGC, pv, draw_hole, false);
+  else
+    gui->fill_pcb_pv (Output.fgGC, Output.bgGC, pv, draw_hole, false);
+}
+
+static void
+draw_pin (PinType *pin, const BoxType *drawn_area, void *userdata)
+{
+  _draw_pv (pin, false);
+}
+
+static void
+draw_pin_mask (PinType *pin, const BoxType *drawn_area, void *userdata)
+{
+  if (TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG (THINDRAWPOLYFLAG, PCB))
+    gui->thindraw_pcb_pv (Output.pmGC, Output.pmGC, pin, false, true);
+  else
+    gui->fill_pcb_pv (Output.pmGC, Output.pmGC, pin, false, true);
+}
+
+static void
+draw_via (PinType *via, const BoxType *drawn_area, void *userdata)
+{
+  _draw_pv (via, false);
+}
+
+static void
+draw_via_mask (PinType *via, const BoxType *drawn_area, void *userdata)
+{
+  if (TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG (THINDRAWPOLYFLAG, PCB))
+    gui->thindraw_pcb_pv (Output.pmGC, Output.pmGC, via, false, true);
+  else
+    gui->fill_pcb_pv (Output.pmGC, Output.pmGC, via, false, true);
+}
+
+static void
+draw_hole (PinType *pv, const BoxType *drawn_area, void *userdata)
+{
+  gui->set_line_cap (Output.fgGC, Round_Cap);
+  gui->set_line_width (Output.fgGC, 0);
+
+  if (!TEST_FLAG (THINDRAWFLAG, PCB))
+    gui->fill_circle (Output.bgGC, pv->X, pv->Y, pv->DrillingHole / 2);
+
+  if (TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG (HOLEFLAG, pv))
+    gui->draw_arc (Output.fgGC, pv->X, pv->Y,
+                   pv->DrillingHole / 2, pv->DrillingHole / 2, 0, 360);
+}
+
+static void
+_draw_pad (hidGC gc, PadType *pad, bool clear, bool mask)
+{
+  if (clear && !mask && pad->Clearance <= 0)
+    return;
+
+  if (TEST_FLAG (THINDRAWFLAG, PCB) ||
+      (clear && TEST_FLAG (THINDRAWPOLYFLAG, PCB)))
+    gui->thindraw_pcb_pad (gc, pad, clear, mask);
+  else
+    gui->fill_pcb_pad (gc, pad, clear, mask);
+}
+
+static void
+draw_pad (PadType *pad, const BoxType *drawn_area, void *userdata)
+{
+  _draw_pad (Output.fgGC, pad, false, false);
+}
+
+static void
+draw_pad_mask (PadType *pad, const BoxType *drawn_area, void *userdata)
+{
+  if (pad->Mask <= 0)
+    return;
+
+  _draw_pad (Output.pmGC, pad, true, true);
+}
+
+static void
+draw_pad_paste (PadType *pad, const BoxType *drawn_area, void *userdata)
+{
+  if (TEST_FLAG (NOPASTEFLAG, pad) || pad->Mask <= 0)
+    return;
+
+  if (pad->Mask < pad->Thickness)
+    _draw_pad (Output.fgGC, pad, true, true);
+  else
+    _draw_pad (Output.fgGC, pad, false, false);
+}
+
+static void
+_draw_line (LineType *line)
+{
+  gui->set_line_cap (Output.fgGC, Trace_Cap);
+  if (TEST_FLAG (THINDRAWFLAG, PCB))
+    gui->set_line_width (Output.fgGC, 0);
+  else
+    gui->set_line_width (Output.fgGC, line->Thickness);
+
+  gui->draw_line (Output.fgGC,
+                  line->Point1.X, line->Point1.Y,
+                  line->Point2.X, line->Point2.Y);
+}
+
+static void
+draw_line (LineType *line, const BoxType *drawn_area, void *userdata)
+{
+  _draw_line (line);
+}
+
+static void
+draw_rat (RatType *rat, const BoxType *drawn_area, void *userdata)
+{
+  if (Settings.RatThickness < 20)
+    rat->Thickness = pixel_slop * Settings.RatThickness;
+  /* rats.c set VIAFLAG if this rat goes to a containing poly: draw a donut */
+  if (TEST_FLAG(VIAFLAG, rat))
+    {
+      int w = rat->Thickness;
+
+      if (TEST_FLAG (THINDRAWFLAG, PCB))
+        gui->set_line_width (Output.fgGC, 0);
+      else
+        gui->set_line_width (Output.fgGC, w);
+      gui->draw_arc (Output.fgGC, rat->Point1.X, rat->Point1.Y,
+                     w * 2, w * 2, 0, 360);
+    }
+  else
+    _draw_line ((LineType *) rat);
+}
+
+static void
+draw_arc (ArcType *arc, const BoxType *drawn_area, void *userdata)
+{
+  if (!arc->Thickness)
+    return;
+
+  if (TEST_FLAG (THINDRAWFLAG, PCB))
+    gui->set_line_width (Output.fgGC, 0);
+  else
+    gui->set_line_width (Output.fgGC, arc->Thickness);
+  gui->set_line_cap (Output.fgGC, Trace_Cap);
+
+  gui->draw_arc (Output.fgGC, arc->X, arc->Y, arc->Width,
+                 arc->Height, arc->StartAngle, arc->Delta);
+}
+
+static void
+draw_poly (PolygonType *polygon, const BoxType *drawn_area, void *userdata)
+{
+  if (!polygon->Clipped)
+    return;
+
+  if (gui->thindraw_pcb_polygon != NULL &&
+      (TEST_FLAG (THINDRAWFLAG, PCB) ||
+       TEST_FLAG (THINDRAWPOLYFLAG, PCB)))
+    gui->thindraw_pcb_polygon (Output.fgGC, polygon, drawn_area);
+  else
+    gui->fill_pcb_polygon (Output.fgGC, polygon, drawn_area);
+
+  /* If checking planes, thin-draw any pieces which have been clipped away */
+  if (gui->thindraw_pcb_polygon != NULL &&
+      TEST_FLAG (CHECKPLANESFLAG, PCB) &&
+      !TEST_FLAG (FULLPOLYFLAG, polygon))
+    {
+      PolygonType poly = *polygon;
+
+      for (poly.Clipped = polygon->Clipped->f;
+           poly.Clipped != polygon->Clipped;
+           poly.Clipped = poly.Clipped->f)
+        gui->thindraw_pcb_polygon (Output.fgGC, &poly, drawn_area);
+    }
+}
+
+struct draw_funcs d_f = {
+  .draw_pin       = draw_pin,
+  .draw_pin_mask  = draw_pin_mask,
+  .draw_via       = draw_via,
+  .draw_via_mask  = draw_via_mask,
+  .draw_hole      = draw_hole,
+  .draw_pad       = draw_pad,
+  .draw_pad_mask  = draw_pad_mask,
+  .draw_pad_paste = draw_pad_paste,
+  .draw_line      = draw_line,
+  .draw_rat       = draw_rat,
+  .draw_arc       = draw_arc,
+  .draw_poly      = draw_poly,
+};
+
+struct draw_funcs *dapi = &d_f;
diff --git a/src/draw_funcs.h b/src/draw_funcs.h
new file mode 100644
index 0000000..1f97d82
--- /dev/null
+++ b/src/draw_funcs.h
@@ -0,0 +1,16 @@
+struct draw_funcs {
+  void (*draw_pin)       (PinType *,     const BoxType *, void *);
+  void (*draw_pin_mask)  (PinType *,     const BoxType *, void *);
+  void (*draw_via)       (PinType *,     const BoxType *, void *);
+  void (*draw_via_mask)  (PinType *,     const BoxType *, void *);
+  void (*draw_hole)      (PinType *,     const BoxType *, void *);
+  void (*draw_pad)       (PadType *,     const BoxType *, void *);
+  void (*draw_pad_mask)  (PadType *,     const BoxType *, void *);
+  void (*draw_pad_paste) (PadType *,     const BoxType *, void *);
+  void (*draw_line)      (LineType *,    const BoxType *, void *);
+  void (*draw_rat)       (RatType *,     const BoxType *, void *);
+  void (*draw_arc)       (ArcType *,     const BoxType *, void *);
+  void (*draw_poly)      (PolygonType *, const BoxType *, void *);
+};
+
+extern struct draw_funcs *dapi;




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