Index: trunk/src/action_helper.c =================================================================== --- trunk/src/action_helper.c (revision 12694) +++ trunk/src/action_helper.c (revision 12695) @@ -64,86 +64,6 @@ #include "tool.h" -static void GetGridLockCoordinates(int type, void *ptr1, void *ptr2, void *ptr3, pcb_coord_t * x, pcb_coord_t * y) -{ - switch (type) { - case PCB_TYPE_VIA: - *x = ((pcb_pin_t *) ptr2)->X; - *y = ((pcb_pin_t *) ptr2)->Y; - break; - case PCB_TYPE_LINE: - *x = ((pcb_line_t *) ptr2)->Point1.X; - *y = ((pcb_line_t *) ptr2)->Point1.Y; - break; - case PCB_TYPE_TEXT: - case PCB_TYPE_ELEMENT_NAME: - *x = ((pcb_text_t *) ptr2)->X; - *y = ((pcb_text_t *) ptr2)->Y; - break; - case PCB_TYPE_ELEMENT: - *x = ((pcb_element_t *) ptr2)->MarkX; - *y = ((pcb_element_t *) ptr2)->MarkY; - break; - case PCB_TYPE_POLY: - *x = ((pcb_poly_t *) ptr2)->Points[0].X; - *y = ((pcb_poly_t *) ptr2)->Points[0].Y; - break; - - case PCB_TYPE_LINE_POINT: - case PCB_TYPE_POLY_POINT: - *x = ((pcb_point_t *) ptr3)->X; - *y = ((pcb_point_t *) ptr3)->Y; - break; - case PCB_TYPE_ARC: - pcb_arc_get_end((pcb_arc_t *) ptr2, 0, x, y); - break; - case PCB_TYPE_ARC_POINT: - if (ptr3 != NULL) /* need to check because: if snap off, there's no known endpoint (leave x;y as is, then) */ - pcb_arc_get_end((pcb_arc_t *) ptr2, ((*(int **)ptr3) != pcb_arc_start_ptr), x, y); - break; - } -} - -void pcb_attach_for_copy(pcb_coord_t PlaceX, pcb_coord_t PlaceY) -{ - pcb_box_t box; - pcb_coord_t mx = 0, my = 0; - - pcb_event(PCB_EVENT_RUBBER_RESET, NULL); - if (!conf_core.editor.snap_pin) { - /* dither the grab point so that the mark, center, etc - * will end up on a grid coordinate - */ - GetGridLockCoordinates(pcb_crosshair.AttachedObject.Type, - pcb_crosshair.AttachedObject.Ptr1, - pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3, &mx, &my); - mx = pcb_grid_fit(mx, PCB->Grid, PCB->GridOffsetX) - mx; - my = pcb_grid_fit(my, PCB->Grid, PCB->GridOffsetY) - my; - } - pcb_crosshair.AttachedObject.X = PlaceX - mx; - pcb_crosshair.AttachedObject.Y = PlaceY - my; - if (!pcb_marked.status || conf_core.editor.local_ref) - pcb_crosshair_set_local_ref(PlaceX - mx, PlaceY - my, pcb_true); - pcb_crosshair.AttachedObject.State = PCB_CH_STATE_SECOND; - - /* get boundingbox of object and set cursor range */ - GetObjectBoundingBox(pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3, &box); - pcb_crosshair_set_range(pcb_crosshair.AttachedObject.X - box.X1, - pcb_crosshair.AttachedObject.Y - box.Y1, - PCB->MaxWidth - (box.X2 - pcb_crosshair.AttachedObject.X), - PCB->MaxHeight - (box.Y2 - pcb_crosshair.AttachedObject.Y)); - - /* get all attached objects if necessary */ - if ((conf_core.editor.mode != PCB_MODE_COPY) && conf_core.editor.rubber_band_mode) - pcb_event(PCB_EVENT_RUBBER_LOOKUP_LINES, "ippp", pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3); - if (conf_core.editor.mode != PCB_MODE_COPY && - (pcb_crosshair.AttachedObject.Type == PCB_TYPE_ELEMENT || - pcb_crosshair.AttachedObject.Type == PCB_TYPE_VIA || - pcb_crosshair.AttachedObject.Type == PCB_TYPE_LINE || pcb_crosshair.AttachedObject.Type == PCB_TYPE_LINE_POINT)) - pcb_event(PCB_EVENT_RUBBER_LOOKUP_RATS, "ippp", pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3); -} - - /* --------------------------------------------------------------------------- */ /* %start-doc actions 00delta Index: trunk/src/action_helper.h =================================================================== --- trunk/src/action_helper.h (revision 12694) +++ trunk/src/action_helper.h (revision 12695) @@ -31,7 +31,6 @@ #include "global_typedefs.h" -void pcb_attach_for_copy(pcb_coord_t PlaceX, pcb_coord_t PlaceY); /* Event handler to set the cursor according to the X pointer position called from inside main.c */ Index: trunk/src/tool.c =================================================================== --- trunk/src/tool.c (revision 12694) +++ trunk/src/tool.c (revision 12695) @@ -24,8 +24,10 @@ #include "tool.h" +#include "board.h" +#include "conf_core.h" #include "error.h" -#include "conf_core.h" +#include "event.h" #warning tool TODO: remove this when pcb_crosshair_set_mode() got moved here #include "crosshair.h" @@ -156,6 +158,89 @@ wrap_retv(redo_act, return pcb_true, ()); } + +/**** tool helper functions ****/ + +static void get_grid_lock_coordinates(int type, void *ptr1, void *ptr2, void *ptr3, pcb_coord_t * x, pcb_coord_t * y) +{ + switch (type) { + case PCB_TYPE_VIA: + *x = ((pcb_pin_t *) ptr2)->X; + *y = ((pcb_pin_t *) ptr2)->Y; + break; + case PCB_TYPE_LINE: + *x = ((pcb_line_t *) ptr2)->Point1.X; + *y = ((pcb_line_t *) ptr2)->Point1.Y; + break; + case PCB_TYPE_TEXT: + case PCB_TYPE_ELEMENT_NAME: + *x = ((pcb_text_t *) ptr2)->X; + *y = ((pcb_text_t *) ptr2)->Y; + break; + case PCB_TYPE_ELEMENT: + *x = ((pcb_element_t *) ptr2)->MarkX; + *y = ((pcb_element_t *) ptr2)->MarkY; + break; + case PCB_TYPE_POLY: + *x = ((pcb_poly_t *) ptr2)->Points[0].X; + *y = ((pcb_poly_t *) ptr2)->Points[0].Y; + break; + + case PCB_TYPE_LINE_POINT: + case PCB_TYPE_POLY_POINT: + *x = ((pcb_point_t *) ptr3)->X; + *y = ((pcb_point_t *) ptr3)->Y; + break; + case PCB_TYPE_ARC: + pcb_arc_get_end((pcb_arc_t *) ptr2, 0, x, y); + break; + case PCB_TYPE_ARC_POINT: + if (ptr3 != NULL) /* need to check because: if snap off, there's no known endpoint (leave x;y as is, then) */ + pcb_arc_get_end((pcb_arc_t *) ptr2, ((*(int **)ptr3) != pcb_arc_start_ptr), x, y); + break; + } +} + +void pcb_tool_attach_for_copy(pcb_coord_t PlaceX, pcb_coord_t PlaceY) +{ + pcb_box_t box; + pcb_coord_t mx = 0, my = 0; + + pcb_event(PCB_EVENT_RUBBER_RESET, NULL); + if (!conf_core.editor.snap_pin) { + /* dither the grab point so that the mark, center, etc + * will end up on a grid coordinate + */ + get_grid_lock_coordinates(pcb_crosshair.AttachedObject.Type, + pcb_crosshair.AttachedObject.Ptr1, + pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3, &mx, &my); + mx = pcb_grid_fit(mx, PCB->Grid, PCB->GridOffsetX) - mx; + my = pcb_grid_fit(my, PCB->Grid, PCB->GridOffsetY) - my; + } + pcb_crosshair.AttachedObject.X = PlaceX - mx; + pcb_crosshair.AttachedObject.Y = PlaceY - my; + if (!pcb_marked.status || conf_core.editor.local_ref) + pcb_crosshair_set_local_ref(PlaceX - mx, PlaceY - my, pcb_true); + pcb_crosshair.AttachedObject.State = PCB_CH_STATE_SECOND; + + /* get boundingbox of object and set cursor range */ + GetObjectBoundingBox(pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3, &box); + pcb_crosshair_set_range(pcb_crosshair.AttachedObject.X - box.X1, + pcb_crosshair.AttachedObject.Y - box.Y1, + PCB->MaxWidth - (box.X2 - pcb_crosshair.AttachedObject.X), + PCB->MaxHeight - (box.Y2 - pcb_crosshair.AttachedObject.Y)); + + /* get all attached objects if necessary */ + if ((conf_core.editor.mode != PCB_MODE_COPY) && conf_core.editor.rubber_band_mode) + pcb_event(PCB_EVENT_RUBBER_LOOKUP_LINES, "ippp", pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3); + if (conf_core.editor.mode != PCB_MODE_COPY && + (pcb_crosshair.AttachedObject.Type == PCB_TYPE_ELEMENT || + pcb_crosshair.AttachedObject.Type == PCB_TYPE_VIA || + pcb_crosshair.AttachedObject.Type == PCB_TYPE_LINE || pcb_crosshair.AttachedObject.Type == PCB_TYPE_LINE_POINT)) + pcb_event(PCB_EVENT_RUBBER_LOOKUP_RATS, "ippp", pcb_crosshair.AttachedObject.Type, pcb_crosshair.AttachedObject.Ptr1, pcb_crosshair.AttachedObject.Ptr2, pcb_crosshair.AttachedObject.Ptr3); +} + + #warning tool TODO: move this out to a tool plugin #include "tool_arc.h" Index: trunk/src/tool.h =================================================================== --- trunk/src/tool.h (revision 12694) +++ trunk/src/tool.h (revision 12695) @@ -74,7 +74,11 @@ pcb_bool pcb_tool_redo_act(void); +/**** tool helper functions ****/ +void pcb_tool_attach_for_copy(pcb_coord_t PlaceX, pcb_coord_t PlaceY); + + /**** Low level, for internal use ****/ /* Get the tool pointer of a tool by id */ Index: trunk/src/tool_arrow.c =================================================================== --- trunk/src/tool_arrow.c (revision 12694) +++ trunk/src/tool_arrow.c (revision 12695) @@ -84,7 +84,7 @@ box.Y2 = Note.Y - PCB_SLOP * pcb_pixel_slop; pcb_crosshair.drags = pcb_list_block(PCB, &box, &pcb_crosshair.drags_len); pcb_crosshair.drags_current = 0; - pcb_attach_for_copy(Note.X, Note.Y); + pcb_tool_attach_for_copy(Note.X, Note.Y); } else { pcb_box_t box; Index: trunk/src/tool_copy.c =================================================================== --- trunk/src/tool_copy.c (revision 12694) +++ trunk/src/tool_copy.c (revision 12695) @@ -48,7 +48,7 @@ pcb_search_screen(Note.X, Note.Y, types, &pcb_crosshair.AttachedObject.Ptr1, &pcb_crosshair.AttachedObject.Ptr2, &pcb_crosshair.AttachedObject.Ptr3); if (pcb_crosshair.AttachedObject.Type != PCB_TYPE_NONE) { - pcb_attach_for_copy(Note.X, Note.Y); + pcb_tool_attach_for_copy(Note.X, Note.Y); } break; } Index: trunk/src/tool_move.c =================================================================== --- trunk/src/tool_move.c (revision 12694) +++ trunk/src/tool_move.c (revision 12695) @@ -54,7 +54,7 @@ pcb_crosshair.AttachedObject.Type = PCB_TYPE_NONE; } else - pcb_attach_for_copy(Note.X, Note.Y); + pcb_tool_attach_for_copy(Note.X, Note.Y); } break; }