Index: trunk/src/crosshair.h =================================================================== --- trunk/src/crosshair.h (revision 5248) +++ trunk/src/crosshair.h (revision 5249) @@ -51,9 +51,6 @@ void *Ptr1, /* three pointers to data, see */ *Ptr2, /* search.c */ *Ptr3; - pcb_cardinal_t RubberbandN, /* number of lines in array */ - RubberbandMax; - pcb_rubberband_t *Rubberband; } pcb_attached_object_t; typedef struct { Index: trunk/src/rubberband.c =================================================================== --- trunk/src/rubberband.c (revision 5248) +++ trunk/src/rubberband.c (revision 5249) @@ -48,18 +48,20 @@ #include "polygon.h" -/* --------------------------------------------------------------------------- - * some local prototypes - */ -static pcb_rubberband_t *pcb_rubber_band_alloc(void); -static pcb_rubberband_t *pcb_rubber_band_create(pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *MovedPoint); -static void CheckPadForRubberbandConnection(pcb_pad_t *); -static void CheckPinForRubberbandConnection(pcb_pin_t *); -static void CheckLinePointForRubberbandConnection(pcb_layer_t *, pcb_line_t *, pcb_point_t *, pcb_bool); -static void CheckPolygonForRubberbandConnection(pcb_layer_t *, pcb_polygon_t *); -static void CheckLinePointForRat(pcb_layer_t *, pcb_point_t *); -static pcb_r_dir_t rubber_callback(const pcb_box_t * b, void *cl); +typedef struct { /* rubberband lines for element moves */ + pcb_layer_t *Layer; /* layer that holds the line */ + pcb_line_t *Line; /* the line itself */ + pcb_point_t *MovedPoint; /* and finally the point */ +} pcb_rubberband_t; +typedef struct { + pcb_cardinal_t RubberbandN, /* number of lines in array */ + RubberbandMax; + pcb_rubberband_t *Rubberband; +} rubber_ctx_t; +static rubber_ctx_t rubber_band_state; + + struct rubber_info { pcb_coord_t radius; pcb_coord_t X, Y; @@ -66,12 +68,28 @@ pcb_line_t *line; pcb_box_t box; pcb_layer_t *layer; + rubber_ctx_t *rbnd; }; + +static pcb_rubberband_t *pcb_rubber_band_alloc(rubber_ctx_t *rbnd); +static pcb_rubberband_t *pcb_rubber_band_create(rubber_ctx_t *rbnd, pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *MovedPoint); +static void CheckPadForRubberbandConnection(rubber_ctx_t *rbnd, pcb_pad_t *); +static void CheckPinForRubberbandConnection(rubber_ctx_t *rbnd, pcb_pin_t *); +static void CheckLinePointForRubberbandConnection(rubber_ctx_t *rbnd, pcb_layer_t *, pcb_line_t *, pcb_point_t *, pcb_bool); +static void CheckPolygonForRubberbandConnection(rubber_ctx_t *rbnd, pcb_layer_t *, pcb_polygon_t *); +static void CheckLinePointForRat(rubber_ctx_t *rbnd, pcb_layer_t *, pcb_point_t *); +static pcb_r_dir_t rubber_callback(const pcb_box_t *b, void *cl); + + + + + static pcb_r_dir_t rubber_callback(const pcb_box_t * b, void *cl) { pcb_line_t *line = (pcb_line_t *) b; struct rubber_info *i = (struct rubber_info *) cl; + rubber_ctx_t *rbnd = i->rbnd; double x, y, rad, dist1, dist2; pcb_coord_t t; int touches = 0; @@ -119,7 +137,7 @@ touches = 1; } if (touches) { - pcb_rubber_band_create(i->layer, line, &line->Point1); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point1); found++; } } @@ -140,7 +158,7 @@ touches = 1; } if (touches) { - pcb_rubber_band_create(i->layer, line, &line->Point2); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point2); found++; } } @@ -169,14 +187,14 @@ #ifdef CLOSEST_ONLY /* keep this to remind me */ if (dist1 < dist2) - pcb_rubber_band_create(i->layer, line, &line->Point1); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point1); else - pcb_rubber_band_create(i->layer, line, &line->Point2); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point2); #else if (dist1 <= 0) - pcb_rubber_band_create(i->layer, line, &line->Point1); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point1); if (dist2 <= 0) - pcb_rubber_band_create(i->layer, line, &line->Point2); + pcb_rubber_band_create(rbnd, i->layer, line, &line->Point2); #endif return PCB_R_DIR_FOUND_CONTINUE; } @@ -186,7 +204,7 @@ * passed pad. If one of the endpoints of the line lays inside the pad, * the line is added to the 'rubberband' list */ -static void CheckPadForRubberbandConnection(pcb_pad_t *Pad) +static void CheckPadForRubberbandConnection(rubber_ctx_t *rbnd, pcb_pad_t *Pad) { pcb_coord_t half = Pad->Thickness / 2; pcb_cardinal_t i, group; @@ -198,6 +216,7 @@ info.box.Y2 = MAX(Pad->Point1.Y, Pad->Point2.Y) + half; info.radius = 0; info.line = NULL; + info.rbnd = rbnd; i = PCB_FLAG_TEST(PCB_FLAG_ONSOLDER, Pad) ? pcb_solder_silk_layer : pcb_component_silk_layer; group = GetLayerGroupNumberByNumber(i); @@ -219,6 +238,7 @@ pcb_pin_t *pin; pcb_pad_t *pad; pcb_point_t *point; + rubber_ctx_t *rbnd; }; static pcb_r_dir_t rat_callback(const pcb_box_t * box, void *cl) @@ -225,37 +245,38 @@ { pcb_rat_t *rat = (pcb_rat_t *) box; struct rinfo *i = (struct rinfo *) cl; + rubber_ctx_t *rbnd = i->rbnd; switch (i->type) { case PCB_TYPE_PIN: if (rat->Point1.X == i->pin->X && rat->Point1.Y == i->pin->Y) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point1); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point1); else if (rat->Point2.X == i->pin->X && rat->Point2.Y == i->pin->Y) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point2); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point2); break; case PCB_TYPE_PAD: if (rat->Point1.X == i->pad->Point1.X && rat->Point1.Y == i->pad->Point1.Y && rat->group1 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point1); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point1); else if (rat->Point2.X == i->pad->Point1.X && rat->Point2.Y == i->pad->Point1.Y && rat->group2 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point2); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point2); else if (rat->Point1.X == i->pad->Point2.X && rat->Point1.Y == i->pad->Point2.Y && rat->group1 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point1); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point1); else if (rat->Point2.X == i->pad->Point2.X && rat->Point2.Y == i->pad->Point2.Y && rat->group2 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point2); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point2); else if (rat->Point1.X == (i->pad->Point1.X + i->pad->Point2.X) / 2 && rat->Point1.Y == (i->pad->Point1.Y + i->pad->Point2.Y) / 2 && rat->group1 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point1); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point1); else if (rat->Point2.X == (i->pad->Point1.X + i->pad->Point2.X) / 2 && rat->Point2.Y == (i->pad->Point1.Y + i->pad->Point2.Y) / 2 && rat->group2 == i->group) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point2); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point2); break; case PCB_TYPE_LINE_POINT: if (rat->group1 == i->group && rat->Point1.X == i->point->X && rat->Point1.Y == i->point->Y) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point1); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point1); else if (rat->group2 == i->group && rat->Point2.X == i->point->X && rat->Point2.Y == i->point->Y) - pcb_rubber_band_create(NULL, (pcb_line_t *) rat, &rat->Point2); + pcb_rubber_band_create(rbnd, NULL, (pcb_line_t *) rat, &rat->Point2); break; default: pcb_message(PCB_MSG_DEFAULT, "hace: bad rubber-rat lookup callback\n"); @@ -263,7 +284,7 @@ return PCB_R_DIR_NOT_FOUND; } -static void CheckPadForRat(pcb_pad_t *Pad) +static void CheckPadForRat(rubber_ctx_t *rbnd, pcb_pad_t *Pad) { struct rinfo info; pcb_cardinal_t i; @@ -272,25 +293,28 @@ info.group = GetLayerGroupNumberByNumber(i); info.pad = Pad; info.type = PCB_TYPE_PAD; + info.rbnd = rbnd; pcb_r_search(PCB->Data->rat_tree, &Pad->BoundingBox, NULL, rat_callback, &info, NULL); } -static void CheckPinForRat(pcb_pin_t *Pin) +static void CheckPinForRat(rubber_ctx_t *rbnd, pcb_pin_t *Pin) { struct rinfo info; info.type = PCB_TYPE_PIN; info.pin = Pin; + info.rbnd = rbnd; pcb_r_search(PCB->Data->rat_tree, &Pin->BoundingBox, NULL, rat_callback, &info, NULL); } -static void CheckLinePointForRat(pcb_layer_t *Layer, pcb_point_t *Point) +static void CheckLinePointForRat(rubber_ctx_t *rbnd, pcb_layer_t *Layer, pcb_point_t *Point) { struct rinfo info; info.group = GetLayerGroupNumberByPointer(Layer); info.point = Point; info.type = PCB_TYPE_LINE_POINT; + info.rbnd = rbnd; pcb_r_search(PCB->Data->rat_tree, (pcb_box_t *) Point, NULL, rat_callback, &info, NULL); } @@ -303,7 +327,7 @@ * and readability is more important then the few % * of failures that are immediately recognized */ -static void CheckPinForRubberbandConnection(pcb_pin_t *Pin) +static void CheckPinForRubberbandConnection(rubber_ctx_t *rbnd, pcb_pin_t *Pin) { struct rubber_info info; pcb_cardinal_t n; @@ -314,6 +338,8 @@ info.box.Y1 = Pin->Y - t; info.box.Y2 = Pin->Y + t; info.line = NULL; + info.rbnd = rbnd; + if (PCB_FLAG_TEST(PCB_FLAG_SQUARE, Pin)) info.radius = 0; else { @@ -333,7 +359,7 @@ * If one of the endpoints of the line lays * inside the passed line, * the scanned line is added to the 'rubberband' list */ -static void CheckLinePointForRubberbandConnection(pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *LinePoint, pcb_bool Exact) +static void CheckLinePointForRubberbandConnection(rubber_ctx_t *rbnd, pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *LinePoint, pcb_bool Exact) { pcb_cardinal_t group; struct rubber_info info; @@ -346,8 +372,10 @@ info.box.Y1 = LinePoint->Y - t; info.box.Y2 = LinePoint->Y + t; info.line = Line; + info.rbnd = rbnd; info.X = LinePoint->X; info.Y = LinePoint->Y; + group = GetLayerGroupNumberByPointer(Layer); GROUP_LOOP(PCB->Data, group); { @@ -365,7 +393,7 @@ * If one of the endpoints of the line lays inside the passed polygon, * the scanned line is added to the 'rubberband' list */ -static void CheckPolygonForRubberbandConnection(pcb_layer_t *Layer, pcb_polygon_t *Polygon) +static void CheckPolygonForRubberbandConnection(rubber_ctx_t *rbnd, pcb_layer_t *Layer, pcb_polygon_t *Polygon) { pcb_cardinal_t group; @@ -387,9 +415,9 @@ continue; thick = (line->Thickness + 1) / 2; if (pcb_poly_is_point_in_p(line->Point1.X, line->Point1.Y, thick, Polygon)) - pcb_rubber_band_create(layer, line, &line->Point1); + pcb_rubber_band_create(rbnd, layer, line, &line->Point1); if (pcb_poly_is_point_in_p(line->Point2.X, line->Point2.Y, thick, Polygon)) - pcb_rubber_band_create(layer, line, &line->Point2); + pcb_rubber_band_create(rbnd, layer, line, &line->Point2); } PCB_END_LOOP; } @@ -402,7 +430,7 @@ * data to 'pcb_crosshair.AttachedObject.Rubberband' * lookup is only done for visible layers */ -void pcb_rubber_band_lookup_lines(int Type, void *Ptr1, void *Ptr2, void *Ptr3) +static void pcb_rubber_band_lookup_lines(rubber_ctx_t *rbnd, int Type, void *Ptr1, void *Ptr2, void *Ptr3) { /* the function is only supported for some types @@ -421,12 +449,12 @@ */ PCB_PIN_LOOP(element); { - CheckPinForRubberbandConnection(pin); + CheckPinForRubberbandConnection(rbnd, pin); } PCB_END_LOOP; PCB_PAD_LOOP(element); { - CheckPadForRubberbandConnection(pad); + CheckPadForRubberbandConnection(rbnd, pad); } PCB_END_LOOP; break; @@ -437,8 +465,8 @@ pcb_layer_t *layer = (pcb_layer_t *) Ptr1; pcb_line_t *line = (pcb_line_t *) Ptr2; if (GetLayerNumber(PCB->Data, layer) < pcb_max_copper_layer) { - CheckLinePointForRubberbandConnection(layer, line, &line->Point1, pcb_false); - CheckLinePointForRubberbandConnection(layer, line, &line->Point2, pcb_false); + CheckLinePointForRubberbandConnection(rbnd, layer, line, &line->Point1, pcb_false); + CheckLinePointForRubberbandConnection(rbnd, layer, line, &line->Point2, pcb_false); } break; } @@ -445,21 +473,21 @@ case PCB_TYPE_LINE_POINT: if (GetLayerNumber(PCB->Data, (pcb_layer_t *) Ptr1) < pcb_max_copper_layer) - CheckLinePointForRubberbandConnection((pcb_layer_t *) Ptr1, (pcb_line_t *) Ptr2, (pcb_point_t *) Ptr3, pcb_true); + CheckLinePointForRubberbandConnection(rbnd, (pcb_layer_t *) Ptr1, (pcb_line_t *) Ptr2, (pcb_point_t *) Ptr3, pcb_true); break; case PCB_TYPE_VIA: - CheckPinForRubberbandConnection((pcb_pin_t *) Ptr1); + CheckPinForRubberbandConnection(rbnd, (pcb_pin_t *) Ptr1); break; case PCB_TYPE_POLYGON: if (GetLayerNumber(PCB->Data, (pcb_layer_t *) Ptr1) < pcb_max_copper_layer) - CheckPolygonForRubberbandConnection((pcb_layer_t *) Ptr1, (pcb_polygon_t *) Ptr2); + CheckPolygonForRubberbandConnection(rbnd, (pcb_layer_t *) Ptr1, (pcb_polygon_t *) Ptr2); break; } } -void pcb_rubber_band_lookup_rat_lines(int Type, void *Ptr1, void *Ptr2, void *Ptr3) +static void pcb_rubber_band_lookup_rat_lines(rubber_ctx_t *rbnd, int Type, void *Ptr1, void *Ptr2, void *Ptr3) { switch (Type) { case PCB_TYPE_ELEMENT: @@ -468,12 +496,12 @@ PCB_PIN_LOOP(element); { - CheckPinForRat(pin); + CheckPinForRat(rbnd, pin); } PCB_END_LOOP; PCB_PAD_LOOP(element); { - CheckPadForRat(pad); + CheckPadForRat(rbnd, pad); } PCB_END_LOOP; break; @@ -484,17 +512,17 @@ pcb_layer_t *layer = (pcb_layer_t *) Ptr1; pcb_line_t *line = (pcb_line_t *) Ptr2; - CheckLinePointForRat(layer, &line->Point1); - CheckLinePointForRat(layer, &line->Point2); + CheckLinePointForRat(rbnd, layer, &line->Point1); + CheckLinePointForRat(rbnd, layer, &line->Point2); break; } case PCB_TYPE_LINE_POINT: - CheckLinePointForRat((pcb_layer_t *) Ptr1, (pcb_point_t *) Ptr3); + CheckLinePointForRat(rbnd, (pcb_layer_t *) Ptr1, (pcb_point_t *) Ptr3); break; case PCB_TYPE_VIA: - CheckPinForRat((pcb_pin_t *) Ptr1); + CheckPinForRat(rbnd, (pcb_pin_t *) Ptr1); break; } } @@ -502,18 +530,18 @@ /* --------------------------------------------------------------------------- * get next slot for a rubberband connection, allocates memory if necessary */ -static pcb_rubberband_t *pcb_rubber_band_alloc(void) +static pcb_rubberband_t *pcb_rubber_band_alloc(rubber_ctx_t *rbnd) { - pcb_rubberband_t *ptr = pcb_crosshair.AttachedObject.Rubberband; + pcb_rubberband_t *ptr = rbnd->Rubberband; /* realloc new memory if necessary and clear it */ - if (pcb_crosshair.AttachedObject.RubberbandN >= pcb_crosshair.AttachedObject.RubberbandMax) { - pcb_crosshair.AttachedObject.RubberbandMax += STEP_RUBBERBAND; - ptr = (pcb_rubberband_t *) realloc(ptr, pcb_crosshair.AttachedObject.RubberbandMax * sizeof(pcb_rubberband_t)); - pcb_crosshair.AttachedObject.Rubberband = ptr; - memset(ptr + pcb_crosshair.AttachedObject.RubberbandN, 0, STEP_RUBBERBAND * sizeof(pcb_rubberband_t)); + if (rbnd->RubberbandN >= rbnd->RubberbandMax) { + rbnd->RubberbandMax += STEP_RUBBERBAND; + ptr = (pcb_rubberband_t *) realloc(ptr, rbnd->RubberbandMax * sizeof(pcb_rubberband_t)); + rbnd->Rubberband = ptr; + memset(ptr + rbnd->RubberbandN, 0, STEP_RUBBERBAND * sizeof(pcb_rubberband_t)); } - return (ptr + pcb_crosshair.AttachedObject.RubberbandN++); + return (ptr + rbnd->RubberbandN++); } /* --------------------------------------------------------------------------- @@ -520,9 +548,9 @@ * adds a new line to the rubberband list of 'pcb_crosshair.AttachedObject' * if Layer == 0 it is a rat line */ -static pcb_rubberband_t *pcb_rubber_band_create(pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *MovedPoint) +static pcb_rubberband_t *pcb_rubber_band_create(rubber_ctx_t *rbnd, pcb_layer_t *Layer, pcb_line_t *Line, pcb_point_t *MovedPoint) { - pcb_rubberband_t *ptr = pcb_rubber_band_alloc(); + pcb_rubberband_t *ptr = pcb_rubber_band_alloc(rbnd); /* we toggle the PCB_FLAG_RUBBEREND of the line to determine if */ /* both points are being moved. */ @@ -536,19 +564,21 @@ /*** event handlers ***/ static void rbe_reset(void *user_data, int argc, pcb_event_arg_t argv[]) { - pcb_crosshair.AttachedObject.RubberbandN = 0; + rubber_ctx_t *rbnd = user_data; + rbnd->RubberbandN = 0; } static void rbe_remove_element(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; pcb_rubberband_t *ptr; void *ptr1 = argv[1].d.p, *ptr2 = argv[2].d.p, *ptr3 = argv[3].d.p; int i, type = PCB_TYPE_ELEMENT; - pcb_crosshair.AttachedObject.RubberbandN = 0; - pcb_rubber_band_lookup_rat_lines(type, ptr1, ptr2, ptr3); - ptr = pcb_crosshair.AttachedObject.Rubberband; - for (i = 0; i < pcb_crosshair.AttachedObject.RubberbandN; i++) { + rbnd->RubberbandN = 0; + pcb_rubber_band_lookup_rat_lines(rbnd, type, ptr1, ptr2, ptr3); + ptr = rbnd->Rubberband; + for (i = 0; i < rbnd->RubberbandN; i++) { if (PCB->RatOn) EraseRat((pcb_rat_t *) ptr->Line); if (PCB_FLAG_TEST(PCB_FLAG_RUBBEREND, ptr->Line)) @@ -561,6 +591,7 @@ static void rbe_move(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; pcb_rubberband_t *ptr; pcb_coord_t DX = argv[1].d.c, DY = argv[2].d.c; pcb_opctx_t *ctx = argv[3].d.p; @@ -569,7 +600,7 @@ int n; /* first clear any marks that we made in the line flags */ - for(n = 0, ptr = pcb_crosshair.AttachedObject.Rubberband; n < pcb_crosshair.AttachedObject.RubberbandN; n++, ptr++) + for(n = 0, ptr = rbnd->Rubberband; n < rbnd->RubberbandN; n++, ptr++) PCB_FLAG_CLEAR(PCB_FLAG_RUBBEREND, ptr->Line); return; @@ -576,13 +607,13 @@ } /* move all the lines... and reset the counter */ - ptr = pcb_crosshair.AttachedObject.Rubberband; - while (pcb_crosshair.AttachedObject.RubberbandN) { + ptr = rbnd->Rubberband; + while (rbnd->RubberbandN) { /* first clear any marks that we made in the line flags */ PCB_FLAG_CLEAR(PCB_FLAG_RUBBEREND, ptr->Line); pcb_undo_add_obj_to_move(PCB_TYPE_LINE_POINT, ptr->Layer, ptr->Line, ptr->MovedPoint, DX, DY); MoveLinePoint(ctx, ptr->Layer, ptr->Line, ptr->MovedPoint); - pcb_crosshair.AttachedObject.RubberbandN--; + rbnd->RubberbandN--; ptr++; } } @@ -589,6 +620,7 @@ static void rbe_draw(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; pcb_rubberband_t *ptr; pcb_cardinal_t i; pcb_coord_t dx = argv[1].d.c, dy = argv[2].d.c; @@ -595,8 +627,8 @@ /* draw the attached rubberband lines too */ - i = pcb_crosshair.AttachedObject.RubberbandN; - ptr = pcb_crosshair.AttachedObject.Rubberband; + i = rbnd->RubberbandN; + ptr = rbnd->Rubberband; while (i) { pcb_point_t *point1, *point2; @@ -626,6 +658,7 @@ static void rbe_rotate90(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; pcb_rubberband_t *ptr; /* int Type = argv[1].d.i; */ /* void *ptr1 = argv[2].d.p, *ptr2 = argv[3].d.p, *ptr3 = argv[4].d.p; */ @@ -635,8 +668,8 @@ /* move all the rubberband lines... and reset the counter */ - ptr = pcb_crosshair.AttachedObject.Rubberband; - while (pcb_crosshair.AttachedObject.RubberbandN) { + ptr = rbnd->Rubberband; + while (rbnd->RubberbandN) { *changed = 1; PCB_FLAG_CLEAR(PCB_FLAG_RUBBEREND, ptr->Line); pcb_undo_add_obj_to_rotate(PCB_TYPE_LINE_POINT, ptr->Layer, ptr->Line, ptr->MovedPoint, cx, cy, steps); @@ -658,7 +691,7 @@ pcb_r_insert_entry(PCB->Data->rat_tree, (pcb_box_t *) ptr->Line, 0); DrawRat((pcb_rat_t *) ptr->Line); } - pcb_crosshair.AttachedObject.RubberbandN--; + rbnd->RubberbandN--; ptr++; } } @@ -665,6 +698,7 @@ static void rbe_rename(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; int type = argv[1].d.i; void *ptr1 = argv[2].d.p, *ptr2 = argv[3].d.p, *ptr3 = argv[4].d.p; /* int pinnum = argv[5].d.i;*/ @@ -674,10 +708,10 @@ int i; pcb_undo_restore_serial(); - pcb_crosshair.AttachedObject.RubberbandN = 0; - pcb_rubber_band_lookup_rat_lines(type, ptr1, ptr2, ptr3); - ptr = pcb_crosshair.AttachedObject.Rubberband; - for (i = 0; i < pcb_crosshair.AttachedObject.RubberbandN; i++, ptr++) { + rbnd->RubberbandN = 0; + pcb_rubber_band_lookup_rat_lines(rbnd, type, ptr1, ptr2, ptr3); + ptr = rbnd->Rubberband; + for (i = 0; i < rbnd->RubberbandN; i++, ptr++) { if (PCB->RatOn) EraseRat((pcb_rat_t *) ptr->Line); pcb_undo_move_obj_to_remove(PCB_TYPE_RATLINE, ptr->Line, ptr->Line, ptr->Line); @@ -689,26 +723,29 @@ static void rbe_lookup_lines(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; int type = argv[1].d.i; void *ptr1 = argv[2].d.p, *ptr2 = argv[3].d.p, *ptr3 = argv[4].d.p; - pcb_rubber_band_lookup_lines(type, ptr1, ptr2, ptr3); + pcb_rubber_band_lookup_lines(rbnd, type, ptr1, ptr2, ptr3); } static void rbe_lookup_rats(void *user_data, int argc, pcb_event_arg_t argv[]) { + rubber_ctx_t *rbnd = user_data; int type = argv[1].d.i; void *ptr1 = argv[2].d.p, *ptr2 = argv[3].d.p, *ptr3 = argv[4].d.p; - pcb_rubber_band_lookup_rat_lines(type, ptr1, ptr2, ptr3); + pcb_rubber_band_lookup_rat_lines(rbnd, type, ptr1, ptr2, ptr3); } static const char *rubber_cookie = "old rubberband"; + void pcb_rubberband_init(void) { - void *ctx = NULL; + void *ctx = &rubber_band_state; pcb_event_bind(PCB_EVENT_RUBBER_RESET, rbe_reset, ctx, rubber_cookie); pcb_event_bind(PCB_EVENT_RUBBER_REMOVE_ELEMENT, rbe_remove_element, ctx, rubber_cookie); pcb_event_bind(PCB_EVENT_RUBBER_MOVE, rbe_move, ctx, rubber_cookie); Index: trunk/src/rubberband.h =================================================================== --- trunk/src/rubberband.h (revision 5248) +++ trunk/src/rubberband.h (revision 5249) @@ -30,16 +30,6 @@ #ifndef PCB_RUBBERBAND_H #define PCB_RUBBERBAND_H -/* --------------------------------------------------------------------------- - * some types for cursor drawing, setting of block and lines - * as well as for merging of elements - */ -typedef struct { /* rubberband lines for element moves */ - pcb_layer_t *Layer; /* layer that holds the line */ - pcb_line_t *Line; /* the line itself */ - pcb_point_t *MovedPoint; /* and finally the point */ -} pcb_rubberband_t; - /* temporary call until rubber band is moved out into a plugin */ void pcb_rubberband_init(void);