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

gEDA-cvs: pcb.git: branch: master updated (9e33678b20433f571c54009c704e75d114a3ea10)



The branch, master has been updated
       via  9e33678b20433f571c54009c704e75d114a3ea10 (commit)
       via  7e6eecd18812912b6be43a890774d0b6e3cef3f4 (commit)
      from  17712d53c4b07690ddfc550d8550c39e4b19dfbc (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/crosshair.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 80 insertions(+), 10 deletions(-)


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

commit 9e33678b20433f571c54009c704e75d114a3ea10
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    crosshair.c: Snap to points along off-grid lines when drawing tracks
    
    This should greatly easy making tidy layouts where some lines have
    (perhaps by necessity) ended up off-grid.
    
    This patch adds code to snap onto the center of a line. It finds
    the nearest grid point to the cursor, then will allow snapping at
    the intersections between the line in question and the lines of an
    imaginary X and + centered on the nearest grid-point to the cursor.
    
    This allows neat drawing of horizontal, vertical and 45 degree lines
    which will land correctly on the existing line.

:100644 100644 6bcd002... 4024881... M	src/crosshair.c

commit 7e6eecd18812912b6be43a890774d0b6e3cef3f4
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    crosshair.c: Rename some variables for clarity

:100644 100644 da8bb92... 6bcd002... M	src/crosshair.c

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

commit 9e33678b20433f571c54009c704e75d114a3ea10
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    crosshair.c: Snap to points along off-grid lines when drawing tracks
    
    This should greatly easy making tidy layouts where some lines have
    (perhaps by necessity) ended up off-grid.
    
    This patch adds code to snap onto the center of a line. It finds
    the nearest grid point to the cursor, then will allow snapping at
    the intersections between the line in question and the lines of an
    imaginary X and + centered on the nearest grid-point to the cursor.
    
    This allows neat drawing of horizontal, vertical and 45 degree lines
    which will land correctly on the existing line.

diff --git a/src/crosshair.c b/src/crosshair.c
index 6bcd002..4024881 100644
--- a/src/crosshair.c
+++ b/src/crosshair.c
@@ -976,6 +976,75 @@ FitCrosshairIntoGrid (LocationType X, LocationType Y)
       check_snap_object (&snap_data, pnt->X, pnt->Y, true);
     }
 
+  /* Code to snap at some sensible point along a line */
+  /* Pick the nearest grid-point in the x or y direction
+   * to align with, then adjust until we hit the line
+   */
+  ans = NO_TYPE;
+  if (TEST_FLAG (SNAPPINFLAG, PCB))
+    ans = SearchScreenGridSlop (Crosshair.X, Crosshair.Y,
+                                LINE_TYPE, &ptr1, &ptr2, &ptr3);
+
+  if (ans != NO_TYPE)
+    {
+      LineType *line = (LineType *)ptr2;
+      LocationType try_x, try_y;
+      double dx, dy;
+      double dist;
+
+      dx = line->Point2.X - line->Point1.X;
+      dy = line->Point2.Y - line->Point1.Y;
+
+      /* Try snapping along the X axis */
+      if (dy != 0.)
+        {
+          /* Move in the X direction until we hit the line */
+          try_x = (nearest_grid_y - line->Point1.Y) / dy * dx + line->Point1.X;
+          try_y = nearest_grid_y;
+          check_snap_object (&snap_data, try_x, try_y, true);
+        }
+
+      /* Try snapping along the Y axis */
+      if (dx != 0.)
+        {
+          try_x = nearest_grid_x;
+          try_y = (nearest_grid_x - line->Point1.X) / dx * dy + line->Point1.Y;
+          check_snap_object (&snap_data, try_x, try_y, true);
+        }
+
+      if (dx != dy) /* If line not parallel with dX = dY direction.. */
+        {
+          /* Try snapping diagonally towards the line in the dX = dY direction */
+
+          if (dy == 0)
+            dist = line->Point1.Y - nearest_grid_y;
+          else
+            dist = ((line->Point1.X - nearest_grid_x) -
+                    (line->Point1.Y - nearest_grid_y) * dx / dy) / (1 - dx / dy);
+
+          try_x = nearest_grid_x + dist;
+          try_y = nearest_grid_y + dist;
+
+          check_snap_object (&snap_data, try_x, try_y, true);
+        }
+
+      if (dx != -dy) /* If line not parallel with dX = -dY direction.. */
+        {
+          /* Try snapping diagonally towards the line in the dX = -dY direction */
+
+          if (dy == 0)
+            dist = nearest_grid_y - line->Point1.Y;
+          else
+            dist = ((line->Point1.X - nearest_grid_x) -
+                    (line->Point1.Y - nearest_grid_y) * dx / dy) / (1 + dx / dy);
+
+          try_x = nearest_grid_x + dist;
+          try_y = nearest_grid_y - dist;
+
+          check_snap_object (&snap_data, try_x, try_y, true);
+        }
+    }
+
   ans = NO_TYPE;
   if (TEST_FLAG (SNAPPINFLAG, PCB))
     ans = SearchScreenGridSlop (Crosshair.X, Crosshair.Y,

commit 7e6eecd18812912b6be43a890774d0b6e3cef3f4
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Commit: Peter Clifton <pcjc2@xxxxxxxxx>

    crosshair.c: Rename some variables for clarity

diff --git a/src/crosshair.c b/src/crosshair.c
index da8bb92..6bcd002 100644
--- a/src/crosshair.c
+++ b/src/crosshair.c
@@ -825,7 +825,7 @@ check_snap_object (struct snap_data *snap_data, LocationType x, LocationType y,
 void
 FitCrosshairIntoGrid (LocationType X, LocationType Y)
 {
-  LocationType x, y;
+  LocationType nearest_grid_x, nearest_grid_y;
   void *ptr1, *ptr2, *ptr3;
   struct snap_data snap_data;
   int ans;
@@ -835,31 +835,32 @@ FitCrosshairIntoGrid (LocationType X, LocationType Y)
 
   if (PCB->RatDraw)
     {
-      x = -600;
-      y = -600;
+      nearest_grid_x = -600;
+      nearest_grid_y = -600;
     }
   else
     {
-      x = GRIDFIT_X (Crosshair.X, PCB->Grid);
-      y = GRIDFIT_Y (Crosshair.Y, PCB->Grid);
+      nearest_grid_x = GRIDFIT_X (Crosshair.X, PCB->Grid);
+      nearest_grid_y = GRIDFIT_Y (Crosshair.Y, PCB->Grid);
 
       if (Marked.status && TEST_FLAG (ORTHOMOVEFLAG, PCB))
 	{
 	  int dx = Crosshair.X - Marked.X;
 	  int dy = Crosshair.Y - Marked.Y;
 	  if (ABS (dx) > ABS (dy))
-	    y = Marked.Y;
+	    nearest_grid_y = Marked.Y;
 	  else
-	    x = Marked.X;
+	    nearest_grid_x = Marked.X;
 	}
 
     }
 
   snap_data.crosshair = &Crosshair;
-  snap_data.nearest_sq_dist = crosshair_sq_dist (&Crosshair, x, y);
+  snap_data.nearest_sq_dist =
+    crosshair_sq_dist (&Crosshair, nearest_grid_x, nearest_grid_y);
   snap_data.nearest_is_grid = true;
-  snap_data.x = x;
-  snap_data.y = y;
+  snap_data.x = nearest_grid_x;
+  snap_data.y = nearest_grid_y;
 
   ans = NO_TYPE;
   if (!PCB->RatDraw)




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