From 08876f84f1c642b6963a3c7c2eafd060b2ca314a Mon Sep 17 00:00:00 2001 From: Igor2 Date: Sat, 21 Nov 2015 20:38:55 +0100 Subject: [PATCH 5/5] cycle drag object action. Signed-off-by: bert --- src/action.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/global.h | 4 ++ src/gpcb-menu.res.in | 2 + src/select.h | 1 + 4 files changed, 94 insertions(+), 0 deletions(-) diff --git a/src/action.c b/src/action.c index 93fcd4a..8c09e6e 100644 --- a/src/action.c +++ b/src/action.c @@ -615,6 +615,8 @@ click_cb (hidval hv) } else if (Note.Hit && !gui->shift_is_pressed ()) { + BoxType box; + SaveMode (); saved_mode = true; SetMode (gui->control_is_pressed ()? COPY_MODE : MOVE_MODE); @@ -622,6 +624,19 @@ click_cb (hidval hv) Crosshair.AttachedObject.Ptr2 = Note.ptr2; Crosshair.AttachedObject.Ptr3 = Note.ptr3; Crosshair.AttachedObject.Type = Note.Hit; + + if (Crosshair.drags != NULL) { + free(Crosshair.drags); + Crosshair.drags = NULL; + } + Crosshair.dragx = Note.X; + Crosshair.dragy = Note.Y; + box.X1 = Note.X + SLOP * pixel_slop; + box.X2 = Note.X - SLOP * pixel_slop; + box.Y1 = Note.Y + SLOP * pixel_slop; + box.Y2 = Note.Y - SLOP * pixel_slop; + Crosshair.drags = ListBlock (&box, &Crosshair.drags_len); + Crosshair.drags_current = 0; AttachForCopy (Note.X, Note.Y); } else @@ -1931,6 +1946,75 @@ ActionDumpLibrary (int argc, char **argv, Coord x, Coord y) return 0; } +/* ---------------------------------------------------------------- */ +static const char cycledrag_syntax[] = + "CycleDrag()\n"; + +static const char cycledrag_help[] = "Cycle through which object is being dragged"; + +#define close_enough(a, b) ((((a)-(b)) > 0) ? ((a)-(b) < (SLOP * pixel_slop)) : ((a)-(b) > -(SLOP * pixel_slop))) +static int +CycleDrag (int argc, char **argv, Coord x, Coord y) +{ + void *ptr1, *ptr2, *ptr3; + int over = 0; + + if (Crosshair.drags == NULL) + return (int) NULL; + + do { + Crosshair.drags_current++; + if (Crosshair.drags_current >= Crosshair.drags_len) { + Crosshair.drags_current = 0; + over++; + } + + if (SearchObjectByID (PCB->Data, &ptr1, &ptr2, &ptr3, Crosshair.drags[Crosshair.drags_current], LINE_TYPE) != NO_TYPE) { + /* line has two endpoints, check which one is close to the original x;y */ + LineType *l = ptr2; + if (close_enough(Note.X, l->Point1.X) && close_enough(Note.Y, l->Point1.Y)) { + Crosshair.AttachedObject.Type = LINEPOINT_TYPE; + Crosshair.AttachedObject.Ptr1 = ptr1; + Crosshair.AttachedObject.Ptr2 = ptr2; + Crosshair.AttachedObject.Ptr3 = &l->Point1; + return 0; + } + if (close_enough(Note.X, l->Point2.X) && close_enough(Note.Y, l->Point2.Y)) { + Crosshair.AttachedObject.Type = LINEPOINT_TYPE; + Crosshair.AttachedObject.Ptr1 = ptr1; + Crosshair.AttachedObject.Ptr2 = ptr2; + Crosshair.AttachedObject.Ptr3 = &l->Point2; + return 0; + } + } + else if (SearchObjectByID (PCB->Data, &ptr1, &ptr2, &ptr3, Crosshair.drags[Crosshair.drags_current], VIA_TYPE) != NO_TYPE) { + Crosshair.AttachedObject.Type = VIA_TYPE; + Crosshair.AttachedObject.Ptr1 = ptr1; + Crosshair.AttachedObject.Ptr2 = ptr2; + Crosshair.AttachedObject.Ptr3 = ptr3; + return 0; + } + else if (SearchObjectByID (PCB->Data, &ptr1, &ptr2, &ptr3, Crosshair.drags[Crosshair.drags_current], PAD_TYPE) != NO_TYPE) { + Crosshair.AttachedObject.Type = ELEMENT_TYPE; + Crosshair.AttachedObject.Ptr1 = ptr1; + Crosshair.AttachedObject.Ptr2 = ptr2; + Crosshair.AttachedObject.Ptr3 = ptr3; + return 0; + } + else if (SearchObjectByID (PCB->Data, &ptr1, &ptr2, &ptr3, Crosshair.drags[Crosshair.drags_current], ARC_TYPE) != NO_TYPE) { + Crosshair.AttachedObject.Type = ARC_TYPE; + Crosshair.AttachedObject.Ptr1 = ptr1; + Crosshair.AttachedObject.Ptr2 = ptr2; + Crosshair.AttachedObject.Ptr3 = ptr3; + return 0; + } + + } while(over <= 1); + + return -1; +} +#undef close_enough + /* -------------------------------------------------------------------------- */ static const char flip_syntax[] = N_("Flip(Object|Selected|SelectedElements)"); @@ -8140,6 +8224,9 @@ HID_Action action_action_list[] = { {"DRC", 0, ActionDRCheck, drc_help, drc_syntax} , + {"CycleDrag", 0, CycleDrag, + cycledrag_help, cycledrag_syntax} + , {"DumpLibrary", 0, ActionDumpLibrary, dumplibrary_help, dumplibrary_syntax} , diff --git a/src/global.h b/src/global.h index cf91f03..09aeea1 100644 --- a/src/global.h +++ b/src/global.h @@ -717,6 +717,10 @@ typedef struct PolygonType AttachedPolygon; AttachedObjectType AttachedObject; /*!< Data of attached objects. */ enum crosshair_shape shape; /*!< Shape of Crosshair. */ + /* list of object IDs that could have been dragged so that they can be cycled */ + long int *drags; + int drags_len, drags_current; + Coord dragx, dragy; /* the point where drag started */ } CrosshairType; typedef struct diff --git a/src/gpcb-menu.res.in b/src/gpcb-menu.res.in index 4cea179..a0e2563 100644 --- a/src/gpcb-menu.res.in +++ b/src/gpcb-menu.res.in @@ -286,6 +286,8 @@ MainMenu = {"Elements" ChangeSquare(SelectedElements)} {"Pins" ChangeSquare(SelectedPins)} } + + {"Cycle object being dragged" CycleDrag() a={"x" "x"}} } # diff --git a/src/select.h b/src/select.h index 40e475d..192e309 100644 --- a/src/select.h +++ b/src/select.h @@ -38,6 +38,7 @@ bool SelectObject (void); bool SelectBlock (BoxType *, bool); +long int *ListBlock (BoxType *Box, int *len); bool SelectedOperation (ObjectFunctionType *, bool, int); void *ObjectOperation (ObjectFunctionType *, int, void *, void *, void *); bool SelectByFlag (int flag, bool select); -- 1.7.3.4