Index: trunk/src/tool.c =================================================================== --- trunk/src/tool.c (revision 16584) +++ trunk/src/tool.c (revision 16585) @@ -42,8 +42,13 @@ #include "undo.h" +pcb_toolid_t pcb_tool_prev_id; +pcb_toolid_t pcb_tool_next_id; + static void default_tool_reg(void); static void default_tool_unreg(void); +static void init_current_tool(void); +static void uninit_current_tool(void); void pcb_tool_init(void) { @@ -117,59 +122,25 @@ if (recursing) return -1; recursing = pcb_true; - pcb_notify_crosshair_change(pcb_false); - pcb_added_lines = 0; - pcb_route_reset(&pcb_crosshair.Route); - pcb_crosshair.AttachedObject.Type = PCB_OBJ_VOID; - pcb_crosshair.AttachedObject.State = PCB_CH_STATE_FIRST; - pcb_crosshair.AttachedPolygon.PointN = 0; + if (PCB->RatDraw && !pcb_tool_get(id)->allow_when_drawing_ratlines) { pcb_message(PCB_MSG_WARNING, _("That mode is NOT allowed when drawing ratlines!\n")); id = PCB_MODE_NO; } - if (conf_core.editor.mode == PCB_MODE_LINE && id == PCB_MODE_ARC && pcb_crosshair.AttachedLine.State != PCB_CH_STATE_FIRST) { - pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; - pcb_crosshair.AttachedBox.State = PCB_CH_STATE_SECOND; - pcb_crosshair.AttachedBox.Point1.X = pcb_crosshair.AttachedBox.Point2.X = pcb_crosshair.AttachedLine.Point1.X; - pcb_crosshair.AttachedBox.Point1.Y = pcb_crosshair.AttachedBox.Point2.Y = pcb_crosshair.AttachedLine.Point1.Y; - pcb_adjust_attached_objects(); - } - else if (conf_core.editor.mode == PCB_MODE_ARC && id == PCB_MODE_LINE && pcb_crosshair.AttachedBox.State != PCB_CH_STATE_FIRST) { - pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; - pcb_crosshair.AttachedLine.State = PCB_CH_STATE_SECOND; - pcb_crosshair.AttachedLine.Point1.X = pcb_crosshair.AttachedLine.Point2.X = pcb_crosshair.AttachedBox.Point1.X; - pcb_crosshair.AttachedLine.Point1.Y = pcb_crosshair.AttachedLine.Point2.Y = pcb_crosshair.AttachedBox.Point1.Y; - sprintf(id_s, "%d", id); - conf_set(CFR_DESIGN, "editor/mode", -1, id_s, POL_OVERWRITE); - pcb_adjust_attached_objects(); - } - else { - if (conf_core.editor.mode == PCB_MODE_ARC || conf_core.editor.mode == PCB_MODE_LINE) - pcb_crosshair_set_local_ref(0, 0, pcb_false); - pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; - pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; - if (id == PCB_MODE_LINE && conf_core.editor.auto_drc) { - if (pcb_reset_conns(pcb_true)) { - pcb_undo_inc_serial(); - pcb_draw(); - } - } - } - + + pcb_tool_prev_id = conf_core.editor.mode; + pcb_tool_next_id = id; + uninit_current_tool(); sprintf(id_s, "%d", id); conf_set(CFR_DESIGN, "editor/mode", -1, id_s, POL_OVERWRITE); + init_current_tool(); - if (id == PCB_MODE_PASTE_BUFFER) - /* do an update on the crosshair range */ - pcb_crosshair_range_to_buffer(); - else - pcb_crosshair_set_range(0, 0, PCB->MaxWidth, PCB->MaxHeight); - recursing = pcb_false; /* force a crosshair grid update because the valid range * may have changed */ + pcb_notify_crosshair_change(pcb_false); pcb_crosshair_move_relative(0, 0); pcb_notify_crosshair_change(pcb_true); return 0; @@ -206,6 +177,16 @@ #define wrap_void(func, args) wrap(func, return, ;, args) #define wrap_retv(func, err_ret, args) wrap(func, err_ret, return, args) +static void init_current_tool(void) +{ + wrap_void(init, ()); +} + +static void uninit_current_tool(void) +{ + wrap_void(uninit, ()); +} + void pcb_tool_notify_mode(void) { wrap_void(notify_mode, ()); Index: trunk/src/tool.h =================================================================== --- trunk/src/tool.h (revision 16584) +++ trunk/src/tool.h (revision 16585) @@ -62,6 +62,8 @@ unsigned int priority; /* lower values are higher priorities; escaping mode will try to select the highest prio tool */ /* tool implementation */ + void (*init)(void); + void (*uninit)(void); void (*notify_mode)(void); void (*release_mode)(void); void (*adjust_attached_objects)(void); @@ -119,6 +121,8 @@ extern pcb_tool_note_t pcb_tool_note; extern pcb_bool pcb_tool_is_saved; +extern pcb_toolid_t pcb_tool_prev_id; +extern pcb_toolid_t pcb_tool_next_id; void pcb_tool_attach_for_copy(pcb_coord_t PlaceX, pcb_coord_t PlaceY, pcb_bool do_rubberband); void pcb_tool_notify_block(void); /* create first or second corner of a marked block (when clicked) */ Index: trunk/src/tool_arc.c =================================================================== --- trunk/src/tool_arc.c (revision 16584) +++ trunk/src/tool_arc.c (revision 16585) @@ -49,6 +49,30 @@ #include "obj_arc_draw.h" +void pcb_tool_arc_init(void) +{ + pcb_notify_crosshair_change(pcb_false); + if (pcb_tool_prev_id == PCB_MODE_LINE && pcb_crosshair.AttachedLine.State != PCB_CH_STATE_FIRST) { + pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; + pcb_crosshair.AttachedBox.State = PCB_CH_STATE_SECOND; + pcb_crosshair.AttachedBox.Point1.X = pcb_crosshair.AttachedBox.Point2.X = pcb_crosshair.AttachedLine.Point1.X; + pcb_crosshair.AttachedBox.Point1.Y = pcb_crosshair.AttachedBox.Point2.Y = pcb_crosshair.AttachedLine.Point1.Y; + pcb_adjust_attached_objects(); + } + pcb_notify_crosshair_change(pcb_true); +} + +void pcb_tool_arc_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_added_lines = 0; + if (pcb_tool_next_id != PCB_MODE_LINE) { + pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; + pcb_crosshair_set_local_ref(0, 0, pcb_false); + } + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_arc_notify_mode(void) { switch (pcb_crosshair.AttachedBox.State) { @@ -164,6 +188,8 @@ pcb_tool_t pcb_tool_arc = { "arc", NULL, 100, + pcb_tool_arc_init, + pcb_tool_arc_uninit, pcb_tool_arc_notify_mode, NULL, pcb_tool_arc_adjust_attached_objects, Index: trunk/src/tool_arc.h =================================================================== --- trunk/src/tool_arc.h (revision 16584) +++ trunk/src/tool_arc.h (revision 16585) @@ -1,5 +1,7 @@ extern pcb_tool_t pcb_tool_arc; +void pcb_tool_arc_init(void); +void pcb_tool_arc_uninit(void); void pcb_tool_arc_notify_mode(void); void pcb_tool_arc_adjust_attached_objects(void); void pcb_tool_arc_draw_attached(void); Index: trunk/src/tool_arrow.c =================================================================== --- trunk/src/tool_arrow.c (revision 16584) +++ trunk/src/tool_arrow.c (revision 16585) @@ -48,6 +48,15 @@ #include "undo.h" +void pcb_tool_arrow_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedObject.Type = PCB_OBJ_VOID; + pcb_crosshair.AttachedObject.State = PCB_CH_STATE_FIRST; + pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + /* Called some time after the click if there was a release but no second click a.k.a. finalize single click (some things are already done in pcb_notify_mode at the initial click event) */ @@ -202,6 +211,8 @@ pcb_tool_t pcb_tool_arrow = { "arrow", NULL, 10, + NULL, + pcb_tool_arrow_uninit, pcb_tool_arrow_notify_mode, pcb_tool_arrow_release_mode, pcb_tool_arrow_adjust_attached_objects, Index: trunk/src/tool_arrow.h =================================================================== --- trunk/src/tool_arrow.h (revision 16584) +++ trunk/src/tool_arrow.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_arrow; +void pcb_tool_arrow_uninit(void); void pcb_tool_arrow_notify_mode(void); void pcb_tool_arrow_release_mode(void); void pcb_tool_arrow_adjust_attached_objects(void); Index: trunk/src/tool_buffer.c =================================================================== --- trunk/src/tool_buffer.c (revision 16584) +++ trunk/src/tool_buffer.c (revision 16585) @@ -46,6 +46,16 @@ #include "tool.h" #include "undo.h" +void pcb_tool_buffer_init(void) +{ + pcb_crosshair_range_to_buffer(); +} + +void pcb_tool_buffer_uninit(void) +{ + pcb_crosshair_set_range(0, 0, PCB->MaxWidth, PCB->MaxHeight); +} + void pcb_tool_buffer_notify_mode(void) { void *ptr1, *ptr2, *ptr3; @@ -92,6 +102,8 @@ pcb_tool_t pcb_tool_buffer = { "buffer", NULL, 100, + pcb_tool_buffer_init, + pcb_tool_buffer_uninit, pcb_tool_buffer_notify_mode, pcb_tool_buffer_release_mode, NULL, Index: trunk/src/tool_buffer.h =================================================================== --- trunk/src/tool_buffer.h (revision 16584) +++ trunk/src/tool_buffer.h (revision 16585) @@ -1,5 +1,7 @@ extern pcb_tool_t pcb_tool_buffer; +void pcb_tool_buffer_init(void); +void pcb_tool_buffer_uninit(void); void pcb_tool_buffer_notify_mode(void); void pcb_tool_buffer_release_mode(void); void pcb_tool_buffer_draw_attached(void); Index: trunk/src/tool_copy.c =================================================================== --- trunk/src/tool_copy.c (revision 16584) +++ trunk/src/tool_copy.c (revision 16585) @@ -41,6 +41,13 @@ #include "search.h" #include "tool.h" +void pcb_tool_copy_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedObject.Type = PCB_OBJ_VOID; + pcb_crosshair.AttachedObject.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} void pcb_tool_copy_notify_mode(void) { @@ -103,6 +110,8 @@ pcb_tool_t pcb_tool_copy = { "copy", NULL, 100, + NULL, + pcb_tool_copy_uninit, pcb_tool_copy_notify_mode, pcb_tool_copy_release_mode, NULL, Index: trunk/src/tool_copy.h =================================================================== --- trunk/src/tool_copy.h (revision 16584) +++ trunk/src/tool_copy.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_copy; +void pcb_tool_copy_uninit(void); void pcb_tool_copy_notify_mode(void); void pcb_tool_copy_release_mode (void); void pcb_tool_copy_draw_attached(void); Index: trunk/src/tool_insert.c =================================================================== --- trunk/src/tool_insert.c (revision 16584) +++ trunk/src/tool_insert.c (revision 16585) @@ -53,6 +53,14 @@ static pcb_cardinal_t polyIndex = 0; +void pcb_tool_insert_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedObject.Type = PCB_OBJ_VOID; + pcb_crosshair.AttachedObject.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_insert_notify_mode(void) { switch (pcb_crosshair.AttachedObject.State) { @@ -127,6 +135,8 @@ pcb_tool_t pcb_tool_insert = { "insert", NULL, 100, + NULL, + pcb_tool_insert_uninit, pcb_tool_insert_notify_mode, NULL, pcb_tool_insert_adjust_attached_objects, Index: trunk/src/tool_insert.h =================================================================== --- trunk/src/tool_insert.h (revision 16584) +++ trunk/src/tool_insert.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_insert; +void pcb_tool_insert_uninit(void); void pcb_tool_insert_notify_mode(void); void pcb_tool_insert_adjust_attached_objects(void); void pcb_tool_insert_draw_attached(void); Index: trunk/src/tool_line.c =================================================================== --- trunk/src/tool_line.c (revision 16584) +++ trunk/src/tool_line.c (revision 16585) @@ -59,6 +59,39 @@ static pcb_layer_t *last_layer; +void pcb_tool_line_init(void) +{ + pcb_notify_crosshair_change(pcb_false); + if (pcb_tool_prev_id == PCB_MODE_ARC && pcb_crosshair.AttachedBox.State != PCB_CH_STATE_FIRST) { + pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; + pcb_crosshair.AttachedLine.State = PCB_CH_STATE_SECOND; + pcb_crosshair.AttachedLine.Point1.X = pcb_crosshair.AttachedLine.Point2.X = pcb_crosshair.AttachedBox.Point1.X; + pcb_crosshair.AttachedLine.Point1.Y = pcb_crosshair.AttachedLine.Point2.Y = pcb_crosshair.AttachedBox.Point1.Y; + pcb_adjust_attached_objects(); + } + else { + if (conf_core.editor.auto_drc) { + if (pcb_reset_conns(pcb_true)) { + pcb_undo_inc_serial(); + pcb_draw(); + } + } + } + pcb_notify_crosshair_change(pcb_true); +} + +void pcb_tool_line_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_added_lines = 0; + pcb_route_reset(&pcb_crosshair.Route); + if (pcb_tool_next_id != PCB_MODE_ARC) { + pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; + pcb_crosshair_set_local_ref(0, 0, pcb_false); + } + pcb_notify_crosshair_change(pcb_true); +} + /* creates points of a line (when clicked) */ static void notify_line(void) { @@ -423,6 +456,8 @@ pcb_tool_t pcb_tool_line = { "line", NULL, 100, + pcb_tool_line_init, + pcb_tool_line_uninit, pcb_tool_line_notify_mode, NULL, pcb_tool_line_adjust_attached_objects, Index: trunk/src/tool_line.h =================================================================== --- trunk/src/tool_line.h (revision 16584) +++ trunk/src/tool_line.h (revision 16585) @@ -1,5 +1,7 @@ extern pcb_tool_t pcb_tool_line; +void pcb_tool_line_init(void); +void pcb_tool_line_uninit(void); void pcb_tool_line_notify_mode(void); void pcb_tool_line_adjust_attached_objects(void); void pcb_tool_line_draw_attached(void); Index: trunk/src/tool_lock.c =================================================================== --- trunk/src/tool_lock.c (revision 16584) +++ trunk/src/tool_lock.c (revision 16585) @@ -77,6 +77,8 @@ pcb_tool_t pcb_tool_lock = { "lock", NULL, 100, + NULL, + NULL, pcb_tool_lock_notify_mode, NULL, NULL, Index: trunk/src/tool_move.c =================================================================== --- trunk/src/tool_move.c (revision 16584) +++ trunk/src/tool_move.c (revision 16585) @@ -43,6 +43,14 @@ #include "tool.h" +void pcb_tool_move_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedObject.Type = PCB_OBJ_VOID; + pcb_crosshair.AttachedObject.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_move_notify_mode(void) { pcb_coord_t dx, dy; @@ -107,6 +115,8 @@ pcb_tool_t pcb_tool_move = { "move", NULL, 100, + NULL, + pcb_tool_move_uninit, pcb_tool_move_notify_mode, pcb_tool_move_release_mode, NULL, Index: trunk/src/tool_move.h =================================================================== --- trunk/src/tool_move.h (revision 16584) +++ trunk/src/tool_move.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_move; +void pcb_tool_move_uninit(void); void pcb_tool_move_notify_mode(void); void pcb_tool_move_release_mode (void); void pcb_tool_move_draw_attached(void); Index: trunk/src/tool_poly.c =================================================================== --- trunk/src/tool_poly.c (revision 16584) +++ trunk/src/tool_poly.c (revision 16585) @@ -42,6 +42,14 @@ #include "tool.h" +void pcb_tool_poly_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedPolygon.PointN = 0; + pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_poly_notify_mode(void) { pcb_point_t *points = pcb_crosshair.AttachedPolygon.Points; @@ -140,6 +148,8 @@ pcb_tool_t pcb_tool_poly = { "poly", NULL, 100, + NULL, + pcb_tool_poly_uninit, pcb_tool_poly_notify_mode, NULL, pcb_tool_poly_adjust_attached_objects, Index: trunk/src/tool_poly.h =================================================================== --- trunk/src/tool_poly.h (revision 16584) +++ trunk/src/tool_poly.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_poly; +void pcb_tool_poly_uninit(void); void pcb_tool_poly_notify_mode(void); void pcb_tool_poly_adjust_attached_objects(void); void pcb_tool_poly_draw_attached(void); Index: trunk/src/tool_polyhole.c =================================================================== --- trunk/src/tool_polyhole.c (revision 16584) +++ trunk/src/tool_polyhole.c (revision 16585) @@ -44,6 +44,14 @@ #include "tool.h" +void pcb_tool_polyhole_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedPolygon.PointN = 0; + pcb_crosshair.AttachedLine.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_polyhole_notify_mode(void) { switch (pcb_crosshair.AttachedObject.State) { @@ -171,6 +179,8 @@ pcb_tool_t pcb_tool_polyhole = { "polyhole", NULL, 100, + NULL, + pcb_tool_polyhole_uninit, pcb_tool_polyhole_notify_mode, NULL, pcb_tool_polyhole_adjust_attached_objects, Index: trunk/src/tool_polyhole.h =================================================================== --- trunk/src/tool_polyhole.h (revision 16584) +++ trunk/src/tool_polyhole.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_polyhole; +void pcb_tool_polyhole_uninit(void); void pcb_tool_polyhole_notify_mode(void); void pcb_tool_polyhole_adjust_attached_objects(void); void pcb_tool_polyhole_draw_attached(void); Index: trunk/src/tool_rectangle.c =================================================================== --- trunk/src/tool_rectangle.c (revision 16584) +++ trunk/src/tool_rectangle.c (revision 16585) @@ -46,6 +46,13 @@ #include "obj_poly_draw.h" +void pcb_tool_rectangle_uninit(void) +{ + pcb_notify_crosshair_change(pcb_false); + pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST; + pcb_notify_crosshair_change(pcb_true); +} + void pcb_tool_rectangle_notify_mode(void) { /* do update of position */ @@ -107,6 +114,8 @@ pcb_tool_t pcb_tool_rectangle = { "rectangle", NULL, 100, + NULL, + pcb_tool_rectangle_uninit, pcb_tool_rectangle_notify_mode, NULL, pcb_tool_rectangle_adjust_attached_objects, Index: trunk/src/tool_rectangle.h =================================================================== --- trunk/src/tool_rectangle.h (revision 16584) +++ trunk/src/tool_rectangle.h (revision 16585) @@ -1,5 +1,6 @@ extern pcb_tool_t pcb_tool_rectangle; +void pcb_tool_rectangle_uninit(void); void pcb_tool_rectangle_notify_mode(void); void pcb_tool_rectangle_adjust_attached_objects(void); pcb_bool pcb_tool_rectangle_undo_act(void); Index: trunk/src/tool_remove.c =================================================================== --- trunk/src/tool_remove.c (revision 16584) +++ trunk/src/tool_remove.c (revision 16585) @@ -82,6 +82,8 @@ pcb_tool_t pcb_tool_remove = { "remove", NULL, 100, + NULL, + NULL, pcb_tool_remove_notify_mode, NULL, NULL, Index: trunk/src/tool_rotate.c =================================================================== --- trunk/src/tool_rotate.c (revision 16584) +++ trunk/src/tool_rotate.c (revision 16585) @@ -49,6 +49,8 @@ pcb_tool_t pcb_tool_rotate = { "rotate", NULL, 100, + NULL, + NULL, pcb_tool_rotate_notify_mode, NULL, NULL, Index: trunk/src/tool_text.c =================================================================== --- trunk/src/tool_text.c (revision 16584) +++ trunk/src/tool_text.c (revision 16585) @@ -93,6 +93,8 @@ pcb_tool_t pcb_tool_text = { "text", NULL, 100, + NULL, + NULL, pcb_tool_text_notify_mode, NULL, NULL, Index: trunk/src/tool_thermal.c =================================================================== --- trunk/src/tool_thermal.c (revision 16584) +++ trunk/src/tool_thermal.c (revision 16585) @@ -103,6 +103,8 @@ pcb_tool_t pcb_tool_thermal = { "thermal", NULL, 100, + NULL, + NULL, pcb_tool_thermal_notify_mode, NULL, NULL, Index: trunk/src/tool_via.c =================================================================== --- trunk/src/tool_via.c (revision 16584) +++ trunk/src/tool_via.c (revision 16585) @@ -106,6 +106,8 @@ pcb_tool_t pcb_tool_via = { "via", NULL, 100, + NULL, + NULL, pcb_tool_via_notify_mode, NULL, NULL,