
(*
================================================================================

    This file is part of OpenTemplot2024, a computer program for the design of model railway track.
    Copyright (C) 2024  Martin Wynne and OpenTemplot contributors.    email: martin@85a.uk

    This program is free software: you may redistribute it and/or modify
    it under the terms of the GNU General Public Licence as published by
    the Free Software Foundation, either version 3 of the Licence, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public Licence for more details.

    You should have received a copy of the GNU General Public Licence
    along with this program. See the file: licence.txt

    Or if not, refer to the web site: https://www.gnu.org/licenses/

================================================================================

   This file was saved from Delphi5

   This file was derived from Templot2 version 245a

*)


unit pad_unit;

{$MODE Delphi}

{$ALIGN OFF}

interface

uses
  StdCtrls, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ExtCtrls, ComCtrls, Buttons, emf_unit,

  PrintersDlgs, ExtDlgs, ImgList, Readhtml, FramView;


type

  { Tpad_form }

  Tpad_form = class(TForm)
    Label12: TLabel;
    Label13: TLabel;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    MenuItem5: TMenuItem;
    MenuItem6: TMenuItem;
    MenuItem7: TMenuItem;
    OO3D_menu_entry: TMenuItem;
    pad_menu_bar: TMainMenu;
    main_menu: TMenuItem;
    minimize_panel: TPanel;
    T2_panel: TPanel;
    print_menu: TMenuItem;
    print_screen_menu_entry: TMenuItem;
    print_control_template_menu_entry: TMenuItem;
    program_panel_menu_entry: TMenuItem;
    pad_popup_menu: TPopupMenu;
    pad_menu: TMenuItem;
    pad_colours_menu_entry: TMenuItem;
    action_menu: TMenuItem;
    adjust_curving_menu_entry: TMenuItem;
    adjust_turnout_menu_entry: TMenuItem;
    adjust_both_menu_entry: TMenuItem;
    N6: TMenuItem;
    printer_setup_menu_entry: TMenuItem;
    paper_colour_menu_entry: TMenuItem;
    grid_colour_menu_entry: TMenuItem;
    rail_colour_menu_entry: TMenuItem;
    show_info_menu_entry: TMenuItem;
    adjust_slew_start_menu_entry: TMenuItem;
    f12_redraw_popup_entry: TMenuItem;
    show_info_popup_entry: TMenuItem;
    keep_this_menu_entry: TMenuItem;
    shift_menu_entry: TMenuItem;
    rotate_menu_entry: TMenuItem;
    lock_scaling_menu_entry: TMenuItem;
    free_scaling_menu_entry: TMenuItem;
    lock_scaling_at_menu_entry: TMenuItem;
    hide_info_popup_entry: TMenuItem;
    fix_keep_popup_entry: TMenuItem;
    N5: TMenuItem;
    timber_colour_menu_entry: TMenuItem;
    align_colour_menu_entry: TMenuItem;
    infill_colour_menu_entry: TMenuItem;
    hide_info_menu_entry: TMenuItem;
    N12: TMenuItem;
    output_grid_options_menu_entry: TMenuItem;
    print_grid_on_menu_entry: TMenuItem;
    print_grid_off_menu_entry: TMenuItem;
    grid_options_menu_entry: TMenuItem;
    screengrid_off_menu_entry: TMenuItem;
    screengrid_on_menu_entry: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    mouse_options_menu_entry: TMenuItem;
    info_options_menu_entry: TMenuItem;
    N2: TMenuItem;
    info_font_menu_entry: TMenuItem;
    back_colour_menu_entry: TMenuItem;
    min_rad_menu_entry: TMenuItem;
    red_lamp_timer: TTimer;
    template_menu: TMenuItem;
    basic_turnout_menu_entry: TMenuItem;
    oddsandends1: TMenuItem;
    ends1: TMenuItem;
    odds1: TMenuItem;
    rail_section_menu_entry: TMenuItem;
    lengths_mm_menu_entry: TMenuItem;
    adjacent_spacing_ts_menu_entry: TMenuItem;
    plain_track_data_menu_entry: TMenuItem;
    checks_menu_entry: TMenuItem;
    switch_menu_entry: TMenuItem;
    crossing_menu_entry: TMenuItem;
    curving_data_menu_entry: TMenuItem;
    generator_settings_menu_entry: TMenuItem;
    cross_hatched_infill_menu_entry: TMenuItem;
    solid_infill_menu_entry: TMenuItem;
    hatched_infill_menu_entry: TMenuItem;
    rail_centrelines_only_menu_entry: TMenuItem;
    outer_edges_only_menu_entry: TMenuItem;
    gauge_faces_only_menu_entry: TMenuItem;
    timber_numbers_menu_entry: TMenuItem;
    timber_centres_menu_entry: TMenuItem;
    timber_outlines_menu_entry: TMenuItem;
    timbering_data_menu_entry: TMenuItem;
    expert_shift_menu_entry: TMenuItem;
    pad_quit_menu_entry: TMenuItem;
    scalebarcolours1: TMenuItem;
    sb_black_white_menu_entry: TMenuItem;
    sb_red_yellow_menu_entry: TMenuItem;
    sb_grid_paper_menu_entry: TMenuItem;
    scalebaroptions1: TMenuItem;
    mm_scalebar_menu_entry: TMenuItem;
    inch_scalebar_menu_entry: TMenuItem;
    hide_scalebar_menu_entry: TMenuItem;
    grid_font_menu_entry: TMenuItem;
    gridcolour1: TMenuItem;
    set_any_grid_spacing_menu_entry: TMenuItem;
    paper_orientation_menu_entry: TMenuItem;
    print_setup_dialog: TPrinterSetupDialog;
    gauge_menu: TMenuItem;
    view_box_menu_entry: TMenuItem;
    calibrate_printer_menu_entry: TMenuItem;
    normal_scaling_menu_entry: TMenuItem;
    set_output_size_menu_entry: TMenuItem;
    portrait_menu_entry: TMenuItem;
    landscape_menu_entry: TMenuItem;
    print_grid_colour_menu_entry: TMenuItem;
    print_font_menu_entry: TMenuItem;
    print_drawing_options_menu_entry: TMenuItem;
    print_rail_colour_menu_entry: TMenuItem;
    print_timber_colour_menu_entry: TMenuItem;
    margin_colour_menu_entry: TMenuItem;
    print_preview_menu_entry: TMenuItem;
    straight_template_menu_entry: TMenuItem;
    constant_radius_menu_entry: TMenuItem;
    transition_template_menu_entry: TMenuItem;
    rail_infill_colours_menu_entry: TMenuItem;
    N27: TMenuItem;
    N8: TMenuItem;
    rail_infill_style_menu_entry: TMenuItem;
    N20: TMenuItem;
    swap_hand_menu_entry: TMenuItem;
    zoom_free_popup_entry: TMenuItem;
    zoom_locked_popup_entry: TMenuItem;
    lock_switch_popup_entry: TMenuItem;
    lock_xing_popup_entry: TMenuItem;
    N31: TMenuItem;
    unlock_both_popup_entry: TMenuItem;
    show_popup_menu_entry: TMenuItem;
    black_and_white_printing_menu_entry: TMenuItem;
    colour_printing_menu_entry: TMenuItem;
    modify_gauge_settings_menu_entry: TMenuItem;
    adjust_length_menu_entry: TMenuItem;
    guide_marks_menu_entry: TMenuItem;
    rad_end_marks_menu_entry: TMenuItem;
    N23: TMenuItem;
    nearest_menu_entry: TMenuItem;
    equalized_incremental_menu_entry: TMenuItem;
    square_on_menu_entry: TMenuItem;
    redraw_menu_entry: TMenuItem;
    N4: TMenuItem;
    pad_timber_font_label: TLabel;
    paddrawingoptions1: TMenuItem;
    current_timber_centres_menu_entry: TMenuItem;
    current_timber_outlines_menu_entry: TMenuItem;
    show_current_template_guides_menu_entry: TMenuItem;
    mouse_actions_current_menu_entry: TMenuItem;
    transform_data_menu_entry: TMenuItem;
    transform_clear_menu_entry: TMenuItem;
    adjust_zoom_menu_entry: TMenuItem;
    tools_menu: TMenuItem;
    metric_calc_menu_entry: TMenuItem;
    print_info_menu_entry: TMenuItem;
    metriccalculator2: TMenuItem;
    transform_normalize_menu_entry: TMenuItem;
    length_free_popup_entry: TMenuItem;
    length_locked_popup_entry: TMenuItem;
    N39: TMenuItem;
    geometry_menu: TMenuItem;
    distortion_warning_panel: TPanel;
    preset_schemes_menu_entry: TMenuItem;
    all_grey_menu_entry: TMenuItem;
    shift_to_datum_menu_entry: TMenuItem;
    adjust_turnout_approach_menu_entry: TMenuItem;
    long_turnout_road_menu_entry: TMenuItem;
    show_mouse_panel_menu_entry: TMenuItem;
    hide_mouse_panel_menu_entry: TMenuItem;
    mouse_factors_menu_entry: TMenuItem;
    cross_hairs_pointer_menu_entry: TMenuItem;
    print_guide_colour_menu_entry: TMenuItem;
    print_align_colour_menu_entry: TMenuItem;
    N41: TMenuItem;
    startup_colours_menu_entry: TMenuItem;
    timber_infill_colour_menu_entry: TMenuItem;
    guide_colour_menu_entry: TMenuItem;
    page_outlines_pdf_menu_entry: TMenuItem;
    N42: TMenuItem;
    page_outlines_off_menu_entry: TMenuItem;
    slide_menu_entry: TMenuItem;
    both_edges_menu_entry: TMenuItem;
    rails1: TMenuItem;
    stock_rails_menu_entry: TMenuItem;
    crossing_rails_menu_entry: TMenuItem;
    check_rails_menu_entry: TMenuItem;
    f5_crossing_angles_menu_entry: TMenuItem;
    f5_quarter_steps_menu_entry: TMenuItem;
    f5_any_angle_menu_entry: TMenuItem;
    program_warning_panel: TPanel;
    joint_marks_menu_entry: TMenuItem;
    print_joint_colour_menu_entry: TMenuItem;
    joint_colour_menu_entry: TMenuItem;
    page_outline_colour_menu_entry: TMenuItem;
    warn_label: TLabel;
    pr_cal_menu_entry: TMenuItem;
    reload_calibration_menu_entry: TMenuItem;
    save_calibration_menu_entry: TMenuItem;
    N33: TMenuItem;
    delete_calibration_menu_entry: TMenuItem;
    delete_all_calibrations_menu_entry: TMenuItem;
    proof_sheet_menu_entry: TMenuItem;
    page_outlines_colour_menu_entry: TMenuItem;
    fkey_chart_menu_entry: TMenuItem;
    move_pad_origin_menu_entry: TMenuItem;
    move_datum_menu_entry: TMenuItem;
    transitionoptions1: TMenuItem;
    adjust_rad1_menu_entry: TMenuItem;
    adjust_rad2_menu_entry: TMenuItem;
    adjust_trans_length_menu_entry: TMenuItem;
    trans_colour_menu_entry: TMenuItem;
    trace_on_menu_entry: TMenuItem;
    trace_off_menu_entry: TMenuItem;
    N44: TMenuItem;
    trace_on_popup_entry: TMenuItem;
    trace_off_popup_entry: TMenuItem;
    N45: TMenuItem;
    reset_options_popup_entry: TMenuItem;
    pad_reset_bgnd_popup_entry: TMenuItem;
    N46: TMenuItem;
    timbering_menu_entry: TMenuItem;
    timbers_in_line_menu_entry: TMenuItem;
    timbers_centralized_menu_entry: TMenuItem;
    exit_timbers_menu_entry: TMenuItem;
    exit_sleepers_menu_entry: TMenuItem;
    exit_no_timbers_menu_entry: TMenuItem;
    slew_nudge_menu_entry: TMenuItem;
    cal_settings_menu_entry: TMenuItem;
    modify_gauge_menu_entry: TMenuItem;
    help_menu: TMenuItem;
    rotate_current_180_menu_entry: TMenuItem;
    generate_with_diagnostics_menu_entry: TMenuItem;
    open_keeps_popup_entry: TMenuItem;
    reorg_warning_panel: TPanel;
    shift_to_datum_poup_entry: TMenuItem;
    cancel_distortions_popup_entry: TMenuItem;
    quit_Templot_popup_entry: TMenuItem;
    print_timber_numbers_font_menu_entry: TMenuItem;
    snap_to_catch_points_menu_entry: TMenuItem;
    bgnd_shapes_menu_entry: TMenuItem;
    show_shapes_menu_entry: TMenuItem;
    toggle_bgnd_templates_menu_entry: TMenuItem;
    pad_background_options_menu_entry: TMenuItem;
    shapes_data_menu_entry: TMenuItem;
    N26: TMenuItem;
    hide_shapes_menu_entry: TMenuItem;
    shapes_colour_menu_entry: TMenuItem;
    bgrails_colour_menu_entry: TMenuItem;
    fit_bgnd_menu_entry: TMenuItem;
    adjust_spot_zoom_menu_entry: TMenuItem;
    store_and_background_menu_entry: TMenuItem;
    keep_to_background_popup_entry: TMenuItem;
    fit_org_extents_current_menu_entry: TMenuItem;
    pad_reset_current_popup_entry: TMenuItem;
    spot_and_scale_menu_entry: TMenuItem;
    show_zoom_target_menu_entry: TMenuItem;
    show_pan_controls_menu_entry: TMenuItem;
    set_skeleton_mouse_draw_menu_entry: TMenuItem;
    view_reset_max_menu_entry: TMenuItem;
    pad_max_popup_entry: TMenuItem;
    reset_datum_menu_entry: TMenuItem;
    reset_datum_popup_entry: TMenuItem;
    zoom_menu_entry: TMenuItem;
    N51: TMenuItem;
    set_datum_menu_entry: TMenuItem;
    move_ring_menu_entry: TMenuItem;
    adjust_slew_length_menu_entry: TMenuItem;
    shortcuts_list_menu_entry: TMenuItem;
    bgtimber_colour_menu_entry: TMenuItem;
    bgmarks_colour_menu_entry: TMenuItem;
    bgnd_keeps_font_label: TLabel;
    background_font_menu_entry: TMenuItem;
    N53: TMenuItem;
    move_peg_menu_entry: TMenuItem;
    shift_keeps_menu_entry: TMenuItem;
    rotate_keeps_menu_entry: TMenuItem;
    reset_peg_menu_entry: TMenuItem;
    peg_on_fp_menu_entry: TMenuItem;
    peg_on_joint_end_menu_entry: TMenuItem;
    set_peg_menu_entry: TMenuItem;
    peg_rail_options_menu_entry: TMenuItem;
    peg_on_rail4_menu_entry: TMenuItem;
    peg_on_rail3_menu_entry: TMenuItem;
    peg_on_rail2_menu_entry: TMenuItem;
    peg_on_rail1_menu_entry: TMenuItem;
    peg_is_free_menu_entry: TMenuItem;
    orbit_rad_centre_menu_entry: TMenuItem;
    explode_normal_menu_entry: TMenuItem;
    shrink_normal_menu_entry: TMenuItem;
    N40: TMenuItem;
    spot_explode_popup_entry: TMenuItem;
    spot_shrink_menu_entry: TMenuItem;
    centre_lines_menu_entry: TMenuItem;
    set_peg_position_menu_entry: TMenuItem;
    peg_on_dp_menu_entry: TMenuItem;
    peg_on_rail8_menu_entry: TMenuItem;
    peg_on_rail9_menu_entry: TMenuItem;
    N55: TMenuItem;
    N56: TMenuItem;
    peg_on_tp_menu_entry: TMenuItem;
    peg_on_mxp_menu_entry: TMenuItem;
    peg_on_txp_menu_entry: TMenuItem;
    peg_on_mcp_menu_entry: TMenuItem;
    peg_on_tcp_menu_entry: TMenuItem;
    peg_on_overall_length_menu_entry: TMenuItem;
    pad_on_peg_menu_entry: TMenuItem;
    N58: TMenuItem;
    move_notch_menu_entry: TMenuItem;
    notch_options_menu_entry: TMenuItem;
    set_notch_menu_entry: TMenuItem;
    notch_under_peg_menu_entry: TMenuItem;
    shift_current_onto_notch_menu_entry: TMenuItem;
    turnout_road_options_menu_entry: TMenuItem;
    normal_turnout_road_menu_entry: TMenuItem;
    crossover_road_menu_entry: TMenuItem;
    make_simple_crossover_menu_entry: TMenuItem;
    reset_notch_menu_entry: TMenuItem;
    adjust_trans_start_menu_entry: TMenuItem;
    select_centre_menu_entry: TMenuItem;
    pad_on_notch_menu_entry: TMenuItem;
    bg_peg_colour_menu_entry: TMenuItem;
    reset_peg_popup_entry: TMenuItem;
    control_room_popup_entry: TMenuItem;
    peg_options_popup_entry: TMenuItem;
    reset_peg1_popup_entry: TMenuItem;
    shift_onto_notch_popup_entry: TMenuItem;
    notch_under_peg_popup_entry: TMenuItem;
    hide_control_template_popup_entry: TMenuItem;
    hide_control_template_menu_entry: TMenuItem;
    undo_changes_menu_entry: TMenuItem;
    redo_changes_menu_entry: TMenuItem;
    peg_on_trp_menu_entry: TMenuItem;
    peg_on_mrp_menu_entry: TMenuItem;
    print_entire_pad_menu_entry: TMenuItem;
    print_in_normal_colours_menu_entry: TMenuItem;
    print_all_in_single_colour_menu_entry: TMenuItem;
    set_single_colour_menu_entry: TMenuItem;
    printed_shapes_colour_menu_entry: TMenuItem;
    peg_on_rail6_menu_entry: TMenuItem;
    N61: TMenuItem;
    peg_on_rail5_menu_entry: TMenuItem;
    peg_on_rail7_menu_entry: TMenuItem;
    peg_on_adjacent_ts_menu_entry: TMenuItem;
    make_double_track_ts_menu_entry: TMenuItem;
    make_double_track_ms_menu_entry: TMenuItem;
    peg_on_adjacent_ms_menu_entry: TMenuItem;
    reduced_ends_menu_entry: TMenuItem;
    enlarge_reduce_size_menu_entry: TMenuItem;
    half50_menu_entry: TMenuItem;
    third3333_menu_entry: TMenuItem;
    quarter25_menu_entry: TMenuItem;
    fifth20_menu_entry: TMenuItem;
    eighth125_menu_entry: TMenuItem;
    tenth10_menu_entry: TMenuItem;
    sixteenth625_menu_entry: TMenuItem;
    N2ft1667_menu_entry: TMenuItem;
    N1ft833_menu_entry: TMenuItem;
    N05ft417_menu_entry: TMenuItem;
    N025ft208_menu_entry: TMenuItem;
    twentieth5_menu_entry: TMenuItem;
    double200_menu_entry: TMenuItem;
    fortieth25_menu_entry: TMenuItem;
    convert_vcrossing_RAM_to_CLM_menu_entry: TMenuItem;
    peg_on_TORG_menu_entry: TMenuItem;
    spacing_ring_menu_entry: TMenuItem;
    peg_on_trans_start_menu_entry: TMenuItem;
    peg_on_trans_length_menu_entry: TMenuItem;
    outline_extensions_menu_entry: TMenuItem;
    pad_about_Templot_menu_entry: TMenuItem;
    fineadjust1: TMenuItem;
    extra_fine_adjust_menu_entry: TMenuItem;
    fine_adjust_menu_entry: TMenuItem;
    normal_adjust_menu_entry: TMenuItem;
    coarse_adjust_menu_entry: TMenuItem;
    N65: TMenuItem;
    click_bgnd_selection_menu_entry: TMenuItem;
    backgroundnamelabels1: TMenuItem;
    transparent_names_menu_entry: TMenuItem;
    boxed_over_names_menu_entry: TMenuItem;
    N66: TMenuItem;
    rotate_keeps_180_menu_entry: TMenuItem;
    N68: TMenuItem;
    show_group_menu_entry: TMenuItem;
    group_select_menu_entry: TMenuItem;
    invert_selections_menu_entry: TMenuItem;
    names_fullsize_menu_entry: TMenuItem;
    names_scaled_menu_entry: TMenuItem;
    N72: TMenuItem;
    slewing_data_menu_entry: TMenuItem;
    slewing_panel: TPanel;
    disable_slewing_menu_entry: TMenuItem;
    adjust_slew_amount_menu_entry: TMenuItem;
    cycle_notch_menu_entry: TMenuItem;
    pad1: TMenuItem;
    bring_to_front_menu_entry: TMenuItem;
    send_to_back_menu_entry: TMenuItem;
    mouse_draw_menu_entry: TMenuItem;
    shove_timbers_menu_entry: TMenuItem;
    adjust_print_size_menu_entry: TMenuItem;
    mouse_actions_help_menu_entry: TMenuItem;
    N49: TMenuItem;
    centre_lines_only_menu_radio: TMenuItem;
    restore_and_bgnd_menu_entry: TMenuItem;
    A3_A4_menu_entry: TMenuItem;
    N74: TMenuItem;
    single_sheets_menu_entry: TMenuItem;
    banner_paper_menu_entry: TMenuItem;
    fit_single_page_menu_entry: TMenuItem;
    snap_approach_track_menu_entry: TMenuItem;
    extend_approach_one_menu_entry: TMenuItem;
    shorten_approach_one_menu_entry: TMenuItem;
    snap_approach_to_nearest_menu_entry: TMenuItem;
    snap_exit_track_menu_entry: TMenuItem;
    extend_exit_one_menu_entry: TMenuItem;
    shorten_exit_one_menu_entry: TMenuItem;
    snap_exit_to_nearest_menu_entry: TMenuItem;
    peg_on_MVJP_menu_entry: TMenuItem;
    snap_to_MVJP_menu_entry: TMenuItem;
    snap_exit_to_return_curve_menu_entry: TMenuItem;
    make_return_curve_menu_entry: TMenuItem;
    peg_on_TVJP_menu_entry: TMenuItem;
    make_mirror_menu_entry: TMenuItem;
    mirror_keeps_Y_menu_entry: TMenuItem;
    mirror_keeps_X_menu_entry: TMenuItem;
    length_free_menu_entry: TMenuItem;
    length_locked_menu_entry: TMenuItem;
    clear_all_selections_menu_entry: TMenuItem;
    invert_handing_menu_entry: TMenuItem;
    invert_curving_rads_menu_entry: TMenuItem;
    adjust_roam_menu_entry: TMenuItem;
    mouse_actions_pad_menu_entry: TMenuItem;
    repeat_last_action_menu_entry: TMenuItem;
    mouse_actions_group_menu_entry: TMenuItem;
    N11: TMenuItem;
    N79: TMenuItem;
    N81: TMenuItem;
    N82: TMenuItem;
    N83: TMenuItem;
    spacings_grid_menu_entry: TMenuItem;
    N85: TMenuItem;
    insert_turnout_menu_entry: TMenuItem;
    convert_to_plain_track_menu_entry: TMenuItem;
    N86: TMenuItem;
    swap_current_ends_menu_entry: TMenuItem;
    mirror_current_menu_entry: TMenuItem;
    examine_peg_menu_entry: TMenuItem;
    explode_slow_menu_entry: TMenuItem;
    shrink_slow_menu_entry: TMenuItem;
    N88: TMenuItem;
    N89: TMenuItem;
    selection_colour_menu_entry: TMenuItem;
    hover_colour_menu_entry: TMenuItem;
    crop_approach_menu_entry: TMenuItem;
    snap_exit_back_menu_entry: TMenuItem;
    N91: TMenuItem;
    crop_exit_to_vee_joint_menu_entry: TMenuItem;
    slew_mode1_menu_entry: TMenuItem;
    slew_mode2_menu_entry: TMenuItem;
    N92: TMenuItem;
    snap_to_peg_menu_entry: TMenuItem;
    explode_step_size_menu_entry: TMenuItem;
    blank_to_peg_menu_entry: TMenuItem;
    selection_popup: TPopupMenu;
    move_label_popup_entry: TMenuItem;
    rename_popup_entry: TMenuItem;
    wipe_bg_popup_entry: TMenuItem;
    copy_bg_to_current_popup_entry: TMenuItem;
    N96: TMenuItem;
    delete_keep_popup_entry: TMenuItem;
    select_bg_popup_entry: TMenuItem;
    adjust_slew2_factor_menu_entry: TMenuItem;
    cancel_blanking_menu_entry: TMenuItem;
    template_menu_top_entry: TMenuItem;
    N98: TMenuItem;
    select_all_keeps_menu_entry: TMenuItem;
    examine_peg_popup_entry: TMenuItem;
    swap_transition_rads_menu_entry: TMenuItem;
    edge_panning_on_menu_entry: TMenuItem;
    edge_panning_off_menu_entry: TMenuItem;
    padviewpanning1: TMenuItem;
    N99: TMenuItem;
    doubleclickoptions1: TMenuItem;
    double_grid_menu_entry: TMenuItem;
    double_CTRLF1_menu_entry: TMenuItem;
    double_F4_menu_entry: TMenuItem;
    double_F7_menu_entry: TMenuItem;
    double_ring_menu_entry: TMenuItem;
    double_none_menu_entry: TMenuItem;
    N100: TMenuItem;
    N101: TMenuItem;
    paper_bunching_on_menu_entry: TMenuItem;
    paper_bunching_off_menu_entry: TMenuItem;
    N102: TMenuItem;
    adjust_paper_bunching_menu_entry: TMenuItem;
    old_printedelementoptions_menu_entry: TMenuItem;
    double_bunching_menu_entry: TMenuItem;
    restore_label_popup_entry: TMenuItem;
    dummy_label_panel: TPanel;
    make_label_shape_popup_entry: TMenuItem;
    double_CTRLF9_menu_entry: TMenuItem;
    fit_current_only_menu_entry: TMenuItem;
    N78: TMenuItem;
    N103: TMenuItem;
    set_print_origin_menu_entry: TMenuItem;
    reset_page_origin_menu_entry: TMenuItem;
    move_page_origin_menu_entry: TMenuItem;
    N48: TMenuItem;
    multipleprintruns1: TMenuItem;
    next_run_width_menu_entry: TMenuItem;
    previous_run_width_menu_entry: TMenuItem;
    N106: TMenuItem;
    next_run_length_menu_entry: TMenuItem;
    previous_run_length_menu_entry: TMenuItem;
    notch_on_ring_menu_entry: TMenuItem;
    enter_shift_keeps_menu_entry: TMenuItem;
    enter_rotation_keeps_menu_entry: TMenuItem;
    shift_rotate_current_menu_entry: TMenuItem;
    N107: TMenuItem;
    shift_current_by_menu_entry: TMenuItem;
    rotate_current_by_menu_entry: TMenuItem;
    bright_night_scheme_menu_entry: TMenuItem;
    double_SHIFTCTRLF10_menu_entry: TMenuItem;
    sb_silver_grey_menu_entry: TMenuItem;
    sb_yellow_blue_menu_entry: TMenuItem;
    sb_white_black_menu_entry: TMenuItem;
    sb_teal_aqua_menu_entry: TMenuItem;
    arrow_label: TLabel;
    moving_name_label: TLabel;
    no_infill_menu_entry: TMenuItem;
    cancel_popup_entry: TMenuItem;
    N21: TMenuItem;
    top_toolbar_panel: TPanel;
    mouse_actions_shapes_menu_entry: TMenuItem;
    double_shift_shapes_menu_entry: TMenuItem;
    N109: TMenuItem;
    shift_all_shapes_menu_entry: TMenuItem;
    N110: TMenuItem;
    shift_corner1_menu_entry: TMenuItem;
    shift_corner2_menu_entry: TMenuItem;
    shift_shape_menu_entry: TMenuItem;
    cancel1: TMenuItem;
    N111: TMenuItem;
    rebuild_popup_entry: TMenuItem;
    mint_popup_entry: TMenuItem;
    N112: TMenuItem;
    mint_menu_entry: TMenuItem;
    quick_set_menu_entry: TMenuItem;
    pad_save_all_menu_entry: TMenuItem;
    pad_clear_all_menu_entry: TMenuItem;
    timber_numbering_font_menu_entry: TMenuItem;
    N114: TMenuItem;
    quick_set_popup_entry: TMenuItem;
    mint_from_current_popup_entry: TMenuItem;
    N76: TMenuItem;
    set_pad_view_menu_entry: TMenuItem;
    N115: TMenuItem;
    N116: TMenuItem;
    N117: TMenuItem;
    timbering_infill_menu_entry: TMenuItem;
    no_timbering_infill_menu_entry: TMenuItem;
    hatched_timbering_infill_menu_entry: TMenuItem;
    solid_timbering_infill_menu_entry: TMenuItem;
    crosshatched_timbering_infill_menu_entry: TMenuItem;
    print_timber_infill_colour_menu_entry: TMenuItem;
    generator_rebuild_bgnd_menu_entry: TMenuItem;
    print_timber_infill_menu_entry: TMenuItem;
    N122: TMenuItem;
    N123: TMenuItem;
    print_timber_numbering_menu_entry: TMenuItem;
    omit_timber_numbering_menu_entry: TMenuItem;
    scale_timber_numbering_menu_entry: TMenuItem;
    N125: TMenuItem;
    equalized_constant_menu_entry: TMenuItem;
    exittrack1: TMenuItem;
    rails_menu_entry: TMenuItem;
    last_action_toolbutton: TSpeedButton;
    zom_in_toolbutton: TSpeedButton;
    zoom_out_toolbutton: TSpeedButton;
    N73: TMenuItem;
    N29: TMenuItem;
    click_zoom_rectangle_menu_entry: TMenuItem;
    N105: TMenuItem;
    zoom_to_fit_template_popup_entry: TMenuItem;
    wipe_to_current_popup_entry: TMenuItem;
    generator_skeleton_menu_entry: TMenuItem;
    generator_normal_menu_entry: TMenuItem;
    delete_to_current_popup_entry: TMenuItem;
    align_current_popup_entry: TMenuItem;
    N128: TMenuItem;
    notch_under_bgnd_peg_popup_entry: TMenuItem;
    snake_menu_entry: TMenuItem;
    hide_group_menu_entry: TMenuItem;
    group_colour_menu_entry: TMenuItem;
    sleepers_9ft_menu_entry: TMenuItem;
    sleepers_8ft6in_menu_entry: TMenuItem;
    sleepers_otherlength_menu_entry: TMenuItem;
    N71: TMenuItem;
    bgtimber_infill_colour_menu_entry: TMenuItem;
    info_popup_entry: TMenuItem;
    N130: TMenuItem;
    cancel_mouse_action_popup_entry: TMenuItem;
    N67: TMenuItem;
    N131: TMenuItem;
    snake_peg_popup_entry: TMenuItem;
    top_name_info_popup_entry: TMenuItem;
    N132: TMenuItem;
    peg_facing_facing_popup_entry: TMenuItem;
    peg_facing_trailing_popup_entry: TMenuItem;
    N133: TMenuItem;
    over_facing_facing_popup_entry: TMenuItem;
    over_facing_trailing_popup_entry: TMenuItem;
    numbering_fullsize_only_menu_entry: TMenuItem;
    parking_bay_menu_entry: TMenuItem;
    park_1_menu_entry: TMenuItem;
    unpark_1_menu_entry: TMenuItem;
    N137: TMenuItem;
    park_2_menu_entry: TMenuItem;
    unpark_2_menu_entry: TMenuItem;
    N138: TMenuItem;
    park_3_menu_entry: TMenuItem;
    unpark_3_menu_entry: TMenuItem;
    N139: TMenuItem;
    N140: TMenuItem;
    N141: TMenuItem;
    transition_previous_menu_entry: TMenuItem;
    transition_from_straight_menu_entry: TMenuItem;
    transition_to_straight_menu_entry: TMenuItem;
    N80: TMenuItem;
    transition_help_menu_entry: TMenuItem;
    shift_radial_centre_menu_entry: TMenuItem;
    N142: TMenuItem;
    show_rings_menu_entry: TMenuItem;
    hide_rings_menu_entry: TMenuItem;
    N143: TMenuItem;
    fit_shapes_menu_entry: TMenuItem;
    pad_view_fit_shapes_menu_entry: TMenuItem;
    toggle_group_menu_entry: TMenuItem;
    toggle_bgnd_menu_entry: TMenuItem;
    pad_reload_menu_entry: TMenuItem;
    pad_fit_shapes_popup_entry: TMenuItem;
    N146: TMenuItem;
    trans_calc_timer: TTimer;
    zone_rollout_menu_entry: TMenuItem;
    zone_normal_menu_entry: TMenuItem;
    transitionradiusoptions1: TMenuItem;
    grey_shade_printing_menu_entry: TMenuItem;
    OOBF_menu_entry: TMenuItem;
    EM_menu_entry: TMenuItem;
    S4P4_menu_entry: TMenuItem;
    GOGF_menu_entry: TMenuItem;
    S7_menu_entry: TMenuItem;
    other_gauges_menu_entry: TMenuItem;
    gauge_details_menu_entry: TMenuItem;
    N148: TMenuItem;
    gauge_mint_new_menu_entry: TMenuItem;
    gauge_match_original_menu_entry: TMenuItem;
    blank_infill_menu_entry: TMenuItem;
    blank_timbering_infill_menu_entry: TMenuItem;
    currenttemplatecolours1: TMenuItem;
    background_templates_colours_menu_entry: TMenuItem;
    bg_solid_timber_infill_menu_entry: TMenuItem;
    bg_crosshatched_timber_infill_menu_entry: TMenuItem;
    bg_hatched_timber_infill_menu_entry: TMenuItem;
    bg_blank_timber_infill_menu_entry: TMenuItem;
    bg_no_timber_infill_menu_entry: TMenuItem;
    N152: TMenuItem;
    current_timber_numbers_menu_entry: TMenuItem;
    N34: TMenuItem;
    print_solid_timber_infill_menu_entry: TMenuItem;
    print_crosshatched_timber_infill_menu_entry: TMenuItem;
    print_hatched_timber_infill_menu_entry: TMenuItem;
    print_blank_timber_infill_menu_entry: TMenuItem;
    print_no_timber_infill_menu_entry: TMenuItem;
    bgnd_rail_infill_colour_menu_entry: TMenuItem;
    no_timbering_menu_entry: TMenuItem;
    N124: TMenuItem;
    peg_on_planing_menu_entry: TMenuItem;
    peg_on_heel_menu_entry: TMenuItem;
    peg_on_CESP_menu_entry: TMenuItem;
    new_transition_settings_menu_entry: TMenuItem;
    make_separate_approach_menu_entry: TMenuItem;
    make_separate_exit_menu_entry: TMenuItem;
    make_split_menu_entry: TMenuItem;
    make_split_at_peg_menu_entry: TMenuItem;
    scale_all_shapes_menu_entry: TMenuItem;
    rotate_all_shapes_menu_entry: TMenuItem;
    invert_colours_menu_entry: TMenuItem;
    make_tools_options_menu_entry: TMenuItem;
    make_tools_cancel_blanking_menu_entry: TMenuItem;
    make_tools_retain_blanking_menu_entry: TMenuItem;
    N135: TMenuItem;
    make_tools_restore_shoved_menu_entry: TMenuItem;
    make_tools_retain_shoved_menu_entry: TMenuItem;
    group_menu: TMenuItem;
    mouse_action_shift_group_menu_entry: TMenuItem;
    mouse_action_rotate_group_menu_entry: TMenuItem;
    swings_in_degs_menu_entry: TMenuItem;
    modifyallcolours1: TMenuItem;
    rotate_colours_menu_entry: TMenuItem;
    swap_red_blue_menu_entry: TMenuItem;
    N36: TMenuItem;
    unlink_group_from_notch_menu_entry: TMenuItem;
    group_linked_warning_panel: TPanel;
    scale_shape_menu_entry: TMenuItem;
    group_fence_latching_toolbutton: TSpeedButton;
    group_selection_fence_menu_entry: TMenuItem;
    group_fence_options_menu_entry: TMenuItem;
    group_fence_partial_menu_entry: TMenuItem;
    group_fence_whole_menu_entry: TMenuItem;
    N151: TMenuItem;
    peg_on_midlength_menu_entry: TMenuItem;
    shift_radial_centre_to_notch_menu_entry: TMenuItem;
    notch_linked_to_current_menu_entry: TMenuItem;
    N155: TMenuItem;
    N156: TMenuItem;
    notch_link_help_menu_entry: TMenuItem;
    notch_unlinked_from_current_menu_entry: TMenuItem;
    peg_on_user_defined_menu_entry: TMenuItem;
    set_user_defined_position_menu_entry: TMenuItem;
    overscale_joggles_menu_entry: TMenuItem;
    jotter_menu_entry: TMenuItem;
    s_curve_transition_menu_entry: TMenuItem;
    c_curve_shrinking_transition_menu_entry: TMenuItem;
    c_curve_expanding_transition_menu_entry: TMenuItem;
    make_transition_popup_entry: TMenuItem;
    make_link_help_popup_entry: TMenuItem;
    N159: TMenuItem;
    peg_on_EGTP_menu_entry: TMenuItem;
    peg_on_IGTP_menu_entry: TMenuItem;
    peg_on_EGORG_menu_entry: TMenuItem;
    peg_on_IGORG_menu_entry: TMenuItem;
    peg_on_slew_start_menu_entry: TMenuItem;
    peg_on_slew_length_menu_entry: TMenuItem;
    N134: TMenuItem;
    N160: TMenuItem;
    N161: TMenuItem;
    N157: TMenuItem;
    N162: TMenuItem;
    make_turnout_road_menu_entry: TMenuItem;
    make_internal_road_menu_entry: TMenuItem;
    make_external_road_menu_entry: TMenuItem;
    snap_to_EGTP_menu_entry: TMenuItem;
    snap_to_IGTP_menu_entry: TMenuItem;
    N47: TMenuItem;
    N164: TMenuItem;
    swap_end_for_end_menu_entry: TMenuItem;
    bullhead_rails_menu_entry: TMenuItem;
    flatbottom_rails_menu_entry: TMenuItem;
    no_rails_menu_entry: TMenuItem;
    wing_check_rails_menu_entry: TMenuItem;
    snap_approach_to_railjoint_menu_entry: TMenuItem;
    N165: TMenuItem;
    snap_exit_to_railjoint_menu_entry: TMenuItem;
    N166: TMenuItem;
    N90: TMenuItem;
    normal_track_centre_lines_menu_radio: TMenuItem;
    bent_flares_menu_entry: TMenuItem;
    machined_flares_menu_entry: TMenuItem;
    N167: TMenuItem;
    arrow_button_dummy_trackbar: TTrackBar;
    notch_on_radial_centre_menu_entry: TMenuItem;
    notch_on_1st_radial_centre_menu_entry: TMenuItem;
    notch_on_2nd_radial_centre_menu_entry: TMenuItem;
    move_trans_end_to_peg_menu_entry: TMenuItem;
    move_trans_start_to_peg_menu_entry: TMenuItem;
    N168: TMenuItem;
    move_slew_start_to_peg_menu_entry: TMenuItem;
    move_slew_end_to_peg_menu_entry: TMenuItem;
    N169: TMenuItem;
    jotter_popup_entry: TMenuItem;
    angled_on_menu_entry: TMenuItem;
    edit_memo_popup_entry: TMenuItem;
    jotter_to_memo_popup_entry: TMenuItem;
    fit_extents_toolbutton: TSpeedButton;
    fit_current_toolbutton: TSpeedButton;
    chairs_baseplates_menu_entry: TMenuItem;
    experimental_chairing_menu_entry: TMenuItem;
    no_chairing_menu_entry: TMenuItem;
    adjust_line_thickness_menu_entry: TMenuItem;
    set_line_thicknesses_menu_entry: TMenuItem;
    linethickness1: TMenuItem;
    thin_printed_lines_menu_entry: TMenuItem;
    normal_printed_lines_menu_entry: TMenuItem;
    thick_printed_lines_menu_entry: TMenuItem;
    N172: TMenuItem;
    N173: TMenuItem;
    line_thickness_help_menu_entry: TMenuItem;
    switch_drive_markx_menu_entry: TMenuItem;
    N174: TMenuItem;
    end_trans_at_peg_menu_entry: TMenuItem;
    duplicate_group_menu_entry: TMenuItem;
    gen_rebuild_group_menu_entry: TMenuItem;
    prefix_tags_popup_entry: TMenuItem;
    N176: TMenuItem;
    N178: TMenuItem;
    N179: TMenuItem;
    group_fence_new_menu_entry: TMenuItem;
    group_fence_add_menu_entry: TMenuItem;
    group_fence_toggle_menu_entry: TMenuItem;
    group_fence_remove_menu_entry: TMenuItem;
    bgnd_shape_image: TImage;
    printed_grid_solid_menu_entry: TMenuItem;
    printed_grid_dotted_menu_entry: TMenuItem;
    N180: TMenuItem;
    fit_selected_group_only_menu_entry: TMenuItem;
    customize_crossing_menu_entry: TMenuItem;
    blunt_nose_menu_entry: TMenuItem;
    wing_front_menu_entry: TMenuItem;
    vee_rail_menu_entry: TMenuItem;
    N184: TMenuItem;
    real_menu: TMenuItem;
    f5_sizing_options_menu_entry: TMenuItem;
    N15: TMenuItem;
    N17: TMenuItem;
    N30: TMenuItem;
    N75: TMenuItem;
    N181: TMenuItem;
    bonus_timbers_menu_entry: TMenuItem;
    add_bonus_timber_menu_entry: TMenuItem;
    remove_bonus_timber_menu_entry: TMenuItem;
    N185: TMenuItem;
    remove_all_bonus_timbers_menu_entry: TMenuItem;
    plain_track_joints_menu_entry: TMenuItem;
    no_joints_menu_entry: TMenuItem;
    staggered_joints_menu_entry: TMenuItem;
    normal_joints_menu_entry: TMenuItem;
    rail_joints_help_menu_entry: TMenuItem;
    N186: TMenuItem;
    use_marker_colours_all_menu_entry: TMenuItem;
    use_normal_colours_menu_entry: TMenuItem;
    N187: TMenuItem;
    use_marker_colours_rails_only_menu_entry: TMenuItem;
    template_colours_popup_entry: TMenuItem;
    set_print_marker_colour_popup_entry: TMenuItem;
    print_mapping_colour_popup_entry: TMenuItem;
    normal_print_colours_popup_entry: TMenuItem;
    N189: TMenuItem;
    set_marker_colour_popup_entry: TMenuItem;
    marker_colour_popup_entry: TMenuItem;
    normal_colours_popup_entry: TMenuItem;
    N188: TMenuItem;
    group_template_colours_menu_entry: TMenuItem;
    group_mapping_colour_menu_entry: TMenuItem;
    print_group_mapping_colours_menu_entry: TMenuItem;
    print_group_normal_colours_menu_entry: TMenuItem;
    N191: TMenuItem;
    group_marker_colour_menu_entry: TMenuItem;
    show_group_marker_colours_menu_entry: TMenuItem;
    show_group_normal_colours_menu_entry: TMenuItem;
    N190: TMenuItem;
    railinfillcolours1: TMenuItem;
    print_rails_only_in_mapping_colours_menu_entry: TMenuItem;
    print_all_in_mapping_colours_menu_entry: TMenuItem;
    print_colour_options_menu_entry: TMenuItem;
    N150: TMenuItem;
    print_timbers_only_in_mapping_colours_menu_entry: TMenuItem;
    print_using_pad_marker_colours_menu_entry: TMenuItem;
    use_marker_colours_timbers_only_menu_entry: TMenuItem;
    select_group_by_marker_colour_menu_entry: TMenuItem;
    use_print_mapping_colours_menu_entry: TMenuItem;
    marker_and_mapping_colours_help_menu_entry: TMenuItem;
    N25: TMenuItem;
    marker_mapping_help_menu_entry: TMenuItem;
    N193: TMenuItem;
    printer_marker_map_help_menu_entry: TMenuItem;
    marker_and_mapping_colours_help_popup_entry: TMenuItem;
    N195: TMenuItem;
    trim_margins_menu_entry: TMenuItem;
    trim_per_printer_menu_entry: TMenuItem;
    set_trim_margins_menu_entry: TMenuItem;
    N84: TMenuItem;
    trim_margins_help_menu_entry: TMenuItem;
    show_printable_area_menu_entry: TMenuItem;
    pages_staggered_menu_entry: TMenuItem;
    pages_inline_menu_entry: TMenuItem;
    N198: TMenuItem;
    vertical_rails_menu_entry: TMenuItem;
    inclined_rails_menu_entry: TMenuItem;
    rails_help_menu_entry: TMenuItem;
    N201: TMenuItem;
    adjust_blanking_length_menu_entry: TMenuItem;
    re_generate_on_error_menu_entry: TMenuItem;
    N28: TMenuItem;
    ring_infringements_menu_entry: TMenuItem;
    warn_if_centrelines_infringe_menu_entry: TMenuItem;
    warn_if_rails_infringe_menu_entry: TMenuItem;
    N18: TMenuItem;
    lengths_rails_menu_entry: TMenuItem;
    roll_rails_by_menu_entry: TMenuItem;
    H0_EU_menu_entry: TMenuItem;
    adjust_roll_sleepers_menu_entry: TMenuItem;
    H0_US_menu_entry: TMenuItem;
    read_first_menu_entry: TMenuItem;
    peg_on_joints_menu_entry: TMenuItem;
    N204: TMenuItem;
    undo_clear_or_reload_menu_entry: TMenuItem;
    adjust_spacing_ring_size_menu_entry: TMenuItem;
    notch_on_shape_menu_entry: TMenuItem;
    N206: TMenuItem;
    N207: TMenuItem;
    peg_on_trans_org_menu_entry: TMenuItem;
    N208: TMenuItem;
    start_trans_from_peg_menu_entry: TMenuItem;
    match_trans_zone_to_template_menu_entry: TMenuItem;
    move_transition_zone_menu_entry: TMenuItem;
    change_transition_zone_menu_entry: TMenuItem;
    match_trans_zone_to_slew_menu_entry: TMenuItem;
    match_trans_start_to_template_menu_entry: TMenuItem;
    match_trans_end_to_template_menu_entry: TMenuItem;
    move_trans_start_to_template_menu_entry: TMenuItem;
    move_trans_end_to_template_menu_entry: TMenuItem;
    normalize_transition_menu_entry: TMenuItem;
    N210: TMenuItem;
    N37: TMenuItem;
    rotate_to_datum_menu_entry: TMenuItem;
    N54: TMenuItem;
    move_slewing_zone_menu_entry: TMenuItem;
    change_slewing_zone_menu_entry: TMenuItem;
    N213: TMenuItem;
    slew_help_menu_entry: TMenuItem;
    move_slew_start_to_template_menu_entry: TMenuItem;
    move_slew_end_to_template_menu_entry: TMenuItem;
    start_slew_from_peg_menu_entry: TMenuItem;
    end_slew_at_peg_menu_entry: TMenuItem;
    match_slew_start_to_template_menu_entry: TMenuItem;
    match_slew_end_to_template_menu_entry: TMenuItem;
    match_slew_zone_to_template_menu_entry: TMenuItem;
    match_slew_zone_to_trans_menu_entry: TMenuItem;
    N211: TMenuItem;
    N212: TMenuItem;
    N214: TMenuItem;
    N215: TMenuItem;
    N216: TMenuItem;
    N217: TMenuItem;
    move_slew_centre_to_template_menu_entry: TMenuItem;
    zero_trans_zone_menu_entry: TMenuItem;
    N218: TMenuItem;
    N219: TMenuItem;
    make_tools_normalize_transitions_menu_entry: TMenuItem;
    make_tools_no_normalizing_menu_entry: TMenuItem;
    N220: TMenuItem;
    make_tools_cancel_rolled_menu_entry: TMenuItem;
    make_tools_retain_rolled_menu_entry: TMenuItem;
    N221: TMenuItem;
    background_template_detail_menu_entry: TMenuItem;
    N222: TMenuItem;
    group_rebuild_menu_item: TMenuItem;
    swap_current_facing_trailing_menu_entry: TMenuItem;
    invert_current_handing_menu_entry: TMenuItem;
    swap_facing_trailing_menu_entry: TMenuItem;
    pad_fit_group_menu_entry: TMenuItem;
    N225: TMenuItem;
    N57: TMenuItem;
    N136: TMenuItem;
    N59: TMenuItem;
    customize_k_crossing_menu_entry: TMenuItem;
    convert_turnout_to_half_diamond_menu_entry: TMenuItem;
    fixed_diamond_menu_entry: TMenuItem;
    movable_diamond_menu_entry: TMenuItem;
    convert_half_diamond_to_turnout_menu_entry: TMenuItem;
    N203: TMenuItem;
    insert_half_diamond_menu_entry: TMenuItem;
    k_crossing_check_rails_menu_entry: TMenuItem;
    N87: TMenuItem;
    auto_diamond_menu_entry: TMenuItem;
    k_crossings_help_menu_entry: TMenuItem;
    N113: TMenuItem;
    v_crossing_options_menu_entry: TMenuItem;
    select_customize_switch_menu_entry: TMenuItem;
    N227: TMenuItem;
    N228: TMenuItem;
    N229: TMenuItem;
    head_rail_centreline_only_menu_entry: TMenuItem;
    hd_timbering_as_prototype_menu_entry: TMenuItem;
    hd_timbering_as_model_menu_entry: TMenuItem;
    N231: TMenuItem;
    make_diamond_crossing_menu_entry: TMenuItem;
    do_menu: TMenuItem;
    N70: TMenuItem;
    N10: TMenuItem;
    N232: TMenuItem;
    N233: TMenuItem;
    N234: TMenuItem;
    tools_adjacent_centres_menu_entry: TMenuItem;
    N235: TMenuItem;
    N163: TMenuItem;
    N237: TMenuItem;
    N238: TMenuItem;
    N239: TMenuItem;
    store_as_library_menu_entry: TMenuItem;
    redo_toolbutton: TSpeedButton;
    undo_toolbutton: TSpeedButton;
    normal_hd_checkrails_menu_entry: TMenuItem;
    short_hd_checkrail_ts_menu_entry: TMenuItem;
    half_diamond_checkrail_options_menu_entry: TMenuItem;
    short_hd_checkrail_ms_menu_entry: TMenuItem;
    short_hd_checkrails_both_menu_entry: TMenuItem;
    snap_to_heel_menu_entry: TMenuItem;
    blank_to_toe_menu_entry: TMenuItem;
    half_diamond_timbering_menu_entry: TMenuItem;
    normal_hd_timbers_menu_entry: TMenuItem;
    extended_hd_timbers_ts_menu_entry: TMenuItem;
    extended_hd_timbers_ms_menu_entry: TMenuItem;
    extended_hd_timbers_both_menu_entry: TMenuItem;
    N230: TMenuItem;
    hd_timbering_help_menu_entry: TMenuItem;
    N241: TMenuItem;
    N242: TMenuItem;
    six_inch_steps_menu_entry: TMenuItem;
    other_size_steps_menu_entry: TMenuItem;
    gradual_steps_menu_entry: TMenuItem;
    timber_length_increments_menu_entry: TMenuItem;
    N243: TMenuItem;
    obtain_to_control_popup_entry: TMenuItem;
    obtain_switch_popup_entry: TMenuItem;
    obtain_plain_track_popup_entry: TMenuItem;
    show_in_box_popup_entry: TMenuItem;
    N244: TMenuItem;
    move_ruler_1st_end_menu_entry: TMenuItem;
    move_ruler_2nd_end_menu_entry: TMenuItem;
    ruler_tool_menu_entry: TMenuItem;
    set_ruler_ends_menu_entry: TMenuItem;
    show_ruler_menu_entry: TMenuItem;
    hide_ruler_menu_entry: TMenuItem;
    N24: TMenuItem;
    ruler_mm_menu_entry: TMenuItem;
    ruler_inch_menu_entry: TMenuItem;
    ruler_as_grid_menu_entry: TMenuItem;
    N245: TMenuItem;
    ruler_spacing_menu_entry: TMenuItem;
    move_ruler_end1_menu_entry: TMenuItem;
    move_ruler_end2_menu_entry: TMenuItem;
    N247: TMenuItem;
    modify_and_rebuild_popup_entry: TMenuItem;
    create_unused_copy_popup_entry: TMenuItem;
    N248: TMenuItem;
    zoom_fit_ruler_menu_entry: TMenuItem;
    ruler_on_ring_menu_entry: TMenuItem;
    ruler_on_notch_menu_entry: TMenuItem;
    swap_ruler_ends_menu_entry: TMenuItem;
    N249: TMenuItem;
    print_group_only_menu_entry: TMenuItem;
    print_group_menu_entry: TMenuItem;
    swell_menu_entry: TMenuItem;
    N250: TMenuItem;
    plain_track_options_menu_entry: TMenuItem;
    snap_to_MXP_menu_entry: TMenuItem;
    blank_to_v_crossing_menu_entry: TMenuItem;
    omit_rails_joints_menu_entry: TMenuItem;
    N50: TMenuItem;
    N251: TMenuItem;
    mouse_actions_real_menu_entry: TMenuItem;
    N38: TMenuItem;
    N93: TMenuItem;
    N171: TMenuItem;
    N224: TMenuItem;
    N252: TMenuItem;
    grid_50mm_spacing_menu_entry: TMenuItem;
    grid_250mm_spacing_menu_entry: TMenuItem;
    grid_300mm_spacing_menu_entry: TMenuItem;
    grid_3in_spacing_menu_entry: TMenuItem;
    grid_1ft_spacing_menu_entry: TMenuItem;
    grid_4ft_spacing_menu_entry: TMenuItem;
    grid_12proto_ft_spacing_menu_entry: TMenuItem;
    grid_100proto_ft_spacing_menu_entry: TMenuItem;
    N253: TMenuItem;
    N254: TMenuItem;
    N255: TMenuItem;
    grid_1000mm_spacing_menu_entry: TMenuItem;
    grid_3ft_spacing_menu_entry: TMenuItem;
    grid_500mm_spacing_menu_entry: TMenuItem;
    grid_6in_spacing_menu_entry: TMenuItem;
    N256: TMenuItem;
    N257: TMenuItem;
    N258: TMenuItem;
    snap_to_background_popup_entry: TMenuItem;
    snap_to_ctrl0_popup_entry: TMenuItem;
    snap_to_ctrl1_popup_entry: TMenuItem;
    snap_to_ctrl6_popup_entry: TMenuItem;
    snap_to_ctrl9_popup_entry: TMenuItem;
    peg_on_tolp_menu_entry: TMenuItem;
    N259: TMenuItem;
    snap_to_tolp_popup_entry: TMenuItem;
    f7_snap_options_menu_entry: TMenuItem;
    snap_on_background_templates_menu_entry: TMenuItem;
    set_snap_proximity_menu_entry: TMenuItem;
    snap_to_ctrl3_popup_entry: TMenuItem;
    snap_to_ctrl4_popup_entry: TMenuItem;
    snap_to_ctrl5_popup_entry: TMenuItem;
    snap_to_ctrl7_popup_entry: TMenuItem;
    snap_to_ctrl8_popup_entry: TMenuItem;
    snap_to_tcp_popup_entry: TMenuItem;
    snap_to_mcp_popup_entry: TMenuItem;
    snap_to_bgnd_peg_popup_entry: TMenuItem;
    N261: TMenuItem;
    make_branch_track_menu_item: TMenuItem;
    templot_group_menu_entry: TMenuItem;
    www_templot_com_menu_entry: TMenuItem;
    N94: TMenuItem;
    pad_reload_recent_file_menu_entry: TMenuItem;
    pad_add_recent_file_menu_entry: TMenuItem;
    recent_files_menu_entry: TMenuItem;
    N263: TMenuItem;
    switch_drive_menu_entry: TMenuItem;
    N265: TMenuItem;
    N266: TMenuItem;
    peg_on_blanked_length_menu_entry: TMenuItem;
    f7_snap_popup_entry: TMenuItem;
    enable_f7_snap_popup_entry: TMenuItem;
    disable_f7_snap_popup_entry: TMenuItem;
    make_slip_road_menu_item: TMenuItem;
    bat_name_label_popup_entry: TMenuItem;
    hide_name_labels_menu_entry: TMenuItem;
    printed_element_options_menu_entry: TMenuItem;
    rollcurrentrailstomatch1: TMenuItem;
    roll_match_ctrl0_menu_entry: TMenuItem;
    roll_match_ctrl1_menu_entry: TMenuItem;
    N7: TMenuItem;
    arrange_labels_popup_entry: TMenuItem;
    N260: TMenuItem;
    N97: TMenuItem;
    move_name_labels_menu_entry: TMenuItem;
    mouse_action_move_labels_menu_entry: TMenuItem;
    gen_platforms_trackbed_edges_menu_entry: TMenuItem;
    N19: TMenuItem;
    group_select_all_plain_track_menu_entry: TMenuItem;
    orientation_help_menu_entry: TMenuItem;
    align_options_menu_entry: TMenuItem;
    align_maintain_length_menu_entry: TMenuItem;
    align_match_length_menu_entry: TMenuItem;
    F6_curving_options_menu_entry: TMenuItem;
    f6_length_fixed_menu_entry: TMenuItem;
    N126: TMenuItem;
    f6_options_help_menu_entry: TMenuItem;
    f6_swing_fixed_menu_entry: TMenuItem;
    N144: TMenuItem;
    adjust_entry_straight_menu_entry: TMenuItem;
    N240: TMenuItem;
    allow_left_drag_panning_menu_entry: TMenuItem;
    save_group_menu_entry: TMenuItem;
    delete_group_menu_entry: TMenuItem;
    restore_group_labels_menu_entry: TMenuItem;
    grid_in_front_of_shapes_menu_entry: TMenuItem;
    N269: TMenuItem;
    N270: TMenuItem;
    output_detail_mode_menu_entry: TMenuItem;
    output_diagram_mode_menu_entry: TMenuItem;
    N272: TMenuItem;
    output_mode_options_menu_entry: TMenuItem;
    omit_output_boundaries_menu_entry: TMenuItem;
    include_output_boundaries_menu_entry: TMenuItem;
    N273: TMenuItem;
    output_diagram_options_menu_entry: TMenuItem;
    output_mode_help_menu_entry: TMenuItem;
    N274: TMenuItem;
    N276: TMenuItem;
    output_show_points_menu_entry: TMenuItem;
    write_reminder_menu_entry: TMenuItem;
    print_now_menu: TMenuItem;
    print_control_now_menu_entry: TMenuItem;
    print_entire_pad_now_menu_entry: TMenuItem;
    N277: TMenuItem;
    print_help_menu_entry: TMenuItem;
    print_group_now_menu_entry: TMenuItem;
    PRINTNOWfunctions1: TMenuItem;
    N281: TMenuItem;
    N197: TMenuItem;
    N279: TMenuItem;
    sb_auto_add_menu_entry: TMenuItem;
    sb_manual_add_menu_entry: TMenuItem;
    sb_include_grid_menu_entry: TMenuItem;
    sb_include_grid_labels_menu_entry: TMenuItem;
    sb_include_picture_shapes_menu_entry: TMenuItem;
    sb_lock_menu_entry: TMenuItem;
    sb_show_items_on_pad_menu_entry: TMenuItem;
    N288: TMenuItem;
    auto_update_diagram_menu_entry: TMenuItem;
    manual_add_update_menu_entry: TMenuItem;
    output_detail_options_menu_entry: TMenuItem;
    N291: TMenuItem;
    sketchboard_menu_entry: TMenuItem;
    N292: TMenuItem;
    N293: TMenuItem;
    sb_save_to_file_menu_entry: TMenuItem;
    sb_reload_from_file_menu_entry: TMenuItem;
    N62: TMenuItem;
    sketchboard_show_menu_entry: TMenuItem;
    N290: TMenuItem;
    export_file_menu_entry: TMenuItem;
    make_control_popup_entry: TMenuItem;
    N280: TMenuItem;
    snap_to_zero_menu_entry: TMenuItem;
    store_bgnd_insert_toolbutton: TSpeedButton;
    colour_panel: TPanel;
    colour_patch: TImage;
    OOSF_menu_entry: TMenuItem;
    N_UK_menu_entry: TMenuItem;
    N_NMRA_menu_entry: TMenuItem;
    S2_menu_entry: TMenuItem;
    S_3p5_menu_entry: TMenuItem;
    gauge1F_menu_entry: TMenuItem;
    N43: TMenuItem;
    shortlist1: TMenuItem;
    N284: TMenuItem;
    N294: TMenuItem;
    N295: TMenuItem;
    N296: TMenuItem;
    N297: TMenuItem;
    OMF_menu_entry: TMenuItem;
    N298: TMenuItem;
    S_gauge_menu_entry: TMenuItem;
    shortlist2: TMenuItem;
    N299: TMenuItem;
    platform_edges_menu_entry: TMenuItem;
    N119: TMenuItem;
    about_generator_menu_entry: TMenuItem;
    show_notch_menu_entry: TMenuItem;
    hide_notch_menu_entry: TMenuItem;
    N182: TMenuItem;
    adjacent_options_menu_entry: TMenuItem;
    adjacent_trackbed_platforms_menu_entry: TMenuItem;
    adjacent_rails_menu_entry: TMenuItem;
    N183: TMenuItem;
    print_platform_edge_colour_menu_entry: TMenuItem;
    print_platform_infill_colour_menu_entry: TMenuItem;
    no_track_centre_lines_menu_radio: TMenuItem;
    bgplatforms_colour_menu_entry: TMenuItem;
    gaunt_options_menu_entry: TMenuItem;
    normal_non_gaunt_turnout_menu_entry: TMenuItem;
    gaunt_turnout_menu_entry: TMenuItem;
    N200: TMenuItem;
    gaunt_offset_menu_entry: TMenuItem;
    gaunt_sleeper_length_menu_entry: TMenuItem;
    N202: TMenuItem;
    gaunt_help_menu_entry: TMenuItem;
    adjust_gaunt_offset_menu_entry: TMenuItem;
    adjust_v_crossing_angle_menu_entry: TMenuItem;
    adjust_k_crossing_angle_menu_entry: TMenuItem;
    swap_red_green_menu_entry: TMenuItem;
    swap_green_blue_menu_entry: TMenuItem;
    half_diamond_timbering_style_menu_entry: TMenuItem;
    make_regular_ladder_menu_entry: TMenuItem;
    k_crossing_angle_menu_entry: TMenuItem;
    N300: TMenuItem;
    notch_on_intersection_popup_entry: TMenuItem;
    intersection_outer_inner_popup_entry: TMenuItem;
    intersection_outer_outer_popup_entry: TMenuItem;
    intersection_inner_outer_popup_entry: TMenuItem;
    intersection_inner_inner_popup_entry: TMenuItem;
    intersection_centre_lines_popup_entry: TMenuItem;
    N301: TMenuItem;
    N302: TMenuItem;
    N303: TMenuItem;
    make_diamond_crossing_at_intersection_popup_entry: TMenuItem;
    f9_crossing_angles_menu_entry: TMenuItem;
    f10_crossing_angles_menu_entry: TMenuItem;
    f9_quarter_steps_menu_entry: TMenuItem;
    f10_quarter_steps_menu_entry: TMenuItem;
    f9_any_angle_menu_entry: TMenuItem;
    f10_any_angle_menu_entry: TMenuItem;
    N304: TMenuItem;
    v_crossing_settings_menu_entry: TMenuItem;
    v_crossing_angle_menu_entry: TMenuItem;
    N305: TMenuItem;
    regular_crossing_menu_entry: TMenuItem;
    parallel_crossing_menu_entry: TMenuItem;
    curviform_crossing_menu_entry: TMenuItem;
    generic_crossing_menu_entry: TMenuItem;
    N306: TMenuItem;
    v_crossings_help_menu_entry: TMenuItem;
    page_outlines_printer_menu_entry: TMenuItem;
    copy_and_make_popup_entry: TMenuItem;
    N307: TMenuItem;
    output_mode_panel: TPanel;
    export_help_menu_entry: TMenuItem;
    N32: TMenuItem;
    corner_page_numbers_font_menu_entry: TMenuItem;
    print_platform_infill_menu_entry: TMenuItem;
    print_platform_no_infill_menu_entry: TMenuItem;
    print_platform_blank_infill_menu_entry: TMenuItem;
    print_platform_hatched_infill_menu_entry: TMenuItem;
    print_platform_crossed_infill_menu_entry: TMenuItem;
    print_platform_solid_infill_menu_entry: TMenuItem;
    rebuild_group_to_match_centre_lines_menu_entry: TMenuItem;
    adjustbondaryrectangle1: TMenuItem;
    adjust_rectangle_left_edge_menu_entry: TMenuItem;
    adjust_rectangle_top_edge_menu_entry: TMenuItem;
    adjust_rectangle_right_edge_menu_entry: TMenuItem;
    adjust_rectangle_bottom_edge_menu_entry: TMenuItem;
    N1: TMenuItem;
    N9: TMenuItem;
    draw_boundary_rectangle_menu_entry: TMenuItem;
    clear_boundary_rectangle_menu_entry: TMenuItem;
    move_rectangle_menu_entry: TMenuItem;
    manual_add_diagram_menu_entry: TMenuItem;
    set_boundary_rectangle_menu_entry: TMenuItem;
    make_screenshot_menu_item: TMenuItem;
    save_screenshot_dialog: TSavePictureDialog;
    grid_150mm_spacing_menu_entry: TMenuItem;
    differ_check_rails_menu_entry: TMenuItem;
    N121: TMenuItem;
    make_tools_restore_check_rails_menu_entry: TMenuItem;
    make_tools_retain_check_rails_menu_entry: TMenuItem;
    N271: TMenuItem;
    gen_inner_foot_edges_menu_entry: TMenuItem;
    gen_outer_foot_edges_menu_entry: TMenuItem;
    N282: TMenuItem;
    rebuild_group_to_match_rail_section_menu_entry: TMenuItem;
    modify_timbering_popup_entry: TMenuItem;
    modify_centre_lines_popup_entry: TMenuItem;
    modify_trackbed_edges_popup_entry: TMenuItem;
    modify_rail_section_popup_entry: TMenuItem;
    repeat_last_mouse_action_popup_entry: TMenuItem;
    N283: TMenuItem;
    k_crossing_wing_rails_menu_entry: TMenuItem;
    Kcrossingpointrailsnyi1: TMenuItem;
    customize_k_crossings_menu_entry: TMenuItem;
    N285: TMenuItem;
    peg_hollow_menu_entry: TMenuItem;
    peg_blank_menu_entry: TMenuItem;
    peg_solid_red_menu_entry: TMenuItem;
    make_a_donation_menu_entry: TMenuItem;
    N286: TMenuItem;
    N287: TMenuItem;
    N308: TMenuItem;
    modifyhelp1: TMenuItem;
    N309: TMenuItem;
    stepshelp1: TMenuItem;
    N310: TMenuItem;
    exithelp1: TMenuItem;
    N311: TMenuItem;
    shortenedhelp1: TMenuItem;
    N312: TMenuItem;
    help1: TMenuItem;
    N313: TMenuItem;
    N314: TMenuItem;
    adjacentoptionshelp1: TMenuItem;
    N315: TMenuItem;
    transitionhelp1: TMenuItem;
    N316: TMenuItem;
    zoneoptionshelp1: TMenuItem;
    N317: TMenuItem;
    F5help1: TMenuItem;
    N318: TMenuItem;
    f9_options_help_menu_entry: TMenuItem;
    N319: TMenuItem;
    F10optionshelp1: TMenuItem;
    lengthhelp1: TMenuItem;
    N320: TMenuItem;
    N321: TMenuItem;
    F7snaphelp1: TMenuItem;
    N322: TMenuItem;
    turnoutroadhelp1: TMenuItem;
    N323: TMenuItem;
    alignhelp1: TMenuItem;
    N326: TMenuItem;
    outputsizeshelp1: TMenuItem;
    N327: TMenuItem;
    N194: TMenuItem;
    timberinfillhelp1: TMenuItem;
    N328: TMenuItem;
    infillhelp1: TMenuItem;
    N329: TMenuItem;
    railinfillhelp1: TMenuItem;
    N330: TMenuItem;
    infilhelp1: TMenuItem;
    N16: TMenuItem;
    align_over_help_popup_entry: TMenuItem;
    N60: TMenuItem;
    alignhelp3: TMenuItem;
    N104: TMenuItem;
    N108: TMenuItem;
    N331: TMenuItem;
    N332: TMenuItem;
    F7snappinghelp1: TMenuItem;
    N333: TMenuItem;
    mouse_wheel_zoom_options_menu_entry: TMenuItem;
    mouse_wheel_zoom_centre_menu_entry: TMenuItem;
    mouse_wheel_zoom_at_mouse_menu_entry: TMenuItem;
    mouse_wheel_zoom_jump_menu_entry: TMenuItem;
    N335: TMenuItem;
    mouse_wheel_help_menu_entry: TMenuItem;
    N334: TMenuItem;
    N336: TMenuItem;
    roll_dummy_vehicle_menu_entry: TMenuItem;
    adjust_dummy_vehicle_clearance_menu_entry: TMenuItem;
    N3: TMenuItem;
    N267: TMenuItem;
    infillhelp2: TMenuItem;
    N337: TMenuItem;
    help3: TMenuItem;
    N338: TMenuItem;
    help4: TMenuItem;
    N339: TMenuItem;
    geometricalradiushelp1: TMenuItem;
    N341: TMenuItem;
    colourshelp1: TMenuItem;
    N342: TMenuItem;
    infillhelp3: TMenuItem;
    N343: TMenuItem;
    help6: TMenuItem;
    N344: TMenuItem;
    help7: TMenuItem;
    move_peg_on_background_template_popup_entry: TMenuItem;
    move_to_ctrl0_popup_entry: TMenuItem;
    move_to_ctrl1_popup_entry: TMenuItem;
    move_to_ctrl3_popup_entry: TMenuItem;
    move_to_ctrl4_popup_entry: TMenuItem;
    move_to_tcp_popup_entry: TMenuItem;
    move_to_mcp_popup_entry: TMenuItem;
    move_to_ctrl5_popup_entry: TMenuItem;
    move_to_ctrl6_popup_entry: TMenuItem;
    move_to_ctrl7_popup_entry: TMenuItem;
    move_to_ctrl8_popup_entry: TMenuItem;
    move_to_ctrl9_popup_entry: TMenuItem;
    move_to_tolp_popup_entry: TMenuItem;
    N346: TMenuItem;
    move_bgnd_peg_help_popup_entry: TMenuItem;
    N347: TMenuItem;
    snap_bgnd_peg_help_popup_entry: TMenuItem;
    snap_to_ctrl2_popup_entry: TMenuItem;
    snap_to_user_defined_popup_entry: TMenuItem;
    N348: TMenuItem;
    move_to_ctrl2_popup_entry: TMenuItem;
    move_to_user_defined_popup_entry: TMenuItem;
    N349: TMenuItem;
    N350: TMenuItem;
    intersection_help_popup_entry: TMenuItem;
    pageoriginprintandPDF1: TMenuItem;
    N351: TMenuItem;
    printer_only_margins_menu_entry: TMenuItem;
    N196: TMenuItem;
    N199: TMenuItem;
    N352: TMenuItem;
    new_template_button: TButton;
    obtain_turnout_radius_popup_entry: TMenuItem;
    move_to_heel_popup_entry: TMenuItem;
    move_to_cesp_popup_entry: TMenuItem;
    move_to_planing_popup_entry: TMenuItem;
    snap_to_planing_popup_entry: TMenuItem;
    snap_to_heel_popup_entry: TMenuItem;
    snap_to_cesp_popup_entry: TMenuItem;
    centre_line_offset_options_menu_entry: TMenuItem;
    centre_line_option_normal_menu_entry: TMenuItem;
    centre_line_option_ts_track_menu_entry: TMenuItem;
    centre_line_option_ms_track_menu_entry: TMenuItem;
    centre_line_option_ts_double_menu_entry: TMenuItem;
    centre_line_option_ms_double_menu_entry: TMenuItem;
    centre_line_option_custom_offet_menu_entry: TMenuItem;
    N52: TMenuItem;
    convert_kcrossing_ram_to_clm_menu_entry: TMenuItem;
    N275: TMenuItem;
    track_background_colour_menu_entry: TMenuItem;
    track_background_width_menu_entry: TMenuItem;
    centre_line_option_custom_menu_entry: TMenuItem;
    N354: TMenuItem;
    add_group_tag_menu_entry: TMenuItem;
    select_by_tag_menu_entry: TMenuItem;
    add_prefix_tag_popup_entry: TMenuItem;
    N177: TMenuItem;
    group_all_with_any_same_tags_popup_entry: TMenuItem;
    group_all_with_same_marker_colour_popup_entry: TMenuItem;
    add_existing_prefix_tag_popup_entry: TMenuItem;
    group_all_with_same_colour_popup_entry: TMenuItem;
    remove_prefix_tag_menu_entry: TMenuItem;
    N324: TMenuItem;
    remove_prefix_tag_popup_entry: TMenuItem;
    deprecatedfunctionsexpert1: TMenuItem;
    shift_group_onto_notch_menu_entry: TMenuItem;
    undo_shift_group_onto_notch_menu_entry: TMenuItem;
    N340: TMenuItem;
    undocumented1: TMenuItem;
    add_background_images_menu_entry: TMenuItem;
    N355: TMenuItem;
    N357: TMenuItem;
    page_map_options_menu_entry: TMenuItem;
    N95: TMenuItem;
    page_map_background_shapes_menu_entry: TMenuItem;
    N356: TMenuItem;
    page_map_sketchboard_items_menu_entry: TMenuItem;
    output_page_map_help_menu_entry: TMenuItem;
    centre_line_option_ts_sleeper_ends_menu_entry: TMenuItem;
    centre_line_option_ms_sleeper_ends_menu_entry: TMenuItem;
    radiuswarning1: TMenuItem;
    N358: TMenuItem;
    modify_group_to_match_min_rad_menu_entry: TMenuItem;
    radius_warning_help_menu_entry: TMenuItem;
    modify_radius_warning_popup_entry: TMenuItem;
    N359: TMenuItem;
    old_pre_templot2_files_menu_entry: TMenuItem;
    do_nothing_menu_entry: TMenuItem;
    get_colour_at_mouse_menu_entry: TMenuItem;
    timber_numbering_on_plain_track_menu_entry: TMenuItem;
    N362: TMenuItem;
    peg_on_ip_menu_entry: TMenuItem;
    undo_deleted_template_menu_entry: TMenuItem;
    pad_file_viewer_menu_entry: TMenuItem;
    N363: TMenuItem;
    retain_length_on_mint_menu_entry: TMenuItem;
    show_margin_coordinates_menu_entry: TMenuItem;
    adjustable_turnout_road_menu_entry: TMenuItem;
    adjust_turnout_road_exit_menu_entry: TMenuItem;
    N149: TMenuItem;
    N364: TMenuItem;
    trackbededges1: TMenuItem;
    N366: TMenuItem;
    show_selected_group_templates_menu_entry: TMenuItem;
    hide_selected_group_templates_menu_entry: TMenuItem;
    pad_wipe_group_menu_entry: TMenuItem;
    N367: TMenuItem;
    N368: TMenuItem;
    show_control_template_menu_entry: TMenuItem;
    N369: TMenuItem;
    N370: TMenuItem;
    N371: TMenuItem;
    show_control_template_popup_entry: TMenuItem;
    show_name_labels_menu_entry: TMenuItem;
    make_branch_crossover_menu_entry: TMenuItem;
    N372: TMenuItem;
    N373: TMenuItem;
    diagram_mode_track_colour_menu_entry: TMenuItem;
    N374: TMenuItem;
    toputtimberingbackon1: TMenuItem;
    clickoneoftheotheroptions1: TMenuItem;
    optionsabove1: TMenuItem;
    N375: TMenuItem;
    N376: TMenuItem;
    watch_a_video_menu_entry: TMenuItem;
    N377: TMenuItem;
    N378: TMenuItem;
    qb_baseboard_outlines_menu_entry: TMenuItem;
    qb_900x500_menu_entry: TMenuItem;
    qb_1200x600_menu_entry: TMenuItem;
    qb_1600x750_menu_entry: TMenuItem;
    qb_2400x1200_menu_entry: TMenuItem;
    qb_3000x1800_menu_entry: TMenuItem;
    qb_5000x3000_menu_entry: TMenuItem;
    qb_7000x5000_menu_entry: TMenuItem;
    qb_2000x1000_menu_entry: TMenuItem;
    qb_3ftx1ft_6in_menu_entry: TMenuItem;
    N379: TMenuItem;
    qb_4ftx2ft_menu_entry: TMenuItem;
    qb_6ftx2ft_6in_menu_entry: TMenuItem;
    qb_8ftx4ft_menu_entry: TMenuItem;
    qb_10ftx8ft_menu_entry: TMenuItem;
    qb_15ftx10ft_menu_entry: TMenuItem;
    qb_20ftx15ft_menu_entry: TMenuItem;
    N380: TMenuItem;
    qb_help_menu_entry: TMenuItem;
    qb_8ftx6ft_menu_entry: TMenuItem;
    qb_9000x7000_menu_entry: TMenuItem;
    qb_30ftx20ft_menu_entry: TMenuItem;
    qb_600x300_menu_entry: TMenuItem;
    qb_2ftx1ft_menu_entry: TMenuItem;
    qb_other_mm_menu_entry: TMenuItem;
    qb_other_ft_menu_entry: TMenuItem;
    qb_other_inch_menu_entry: TMenuItem;
    qb_options_menu_entry: TMenuItem;
    N381: TMenuItem;
    qb_thin_lines_menu_entry: TMenuItem;
    qb_thick_lines_menu_entry: TMenuItem;
    N382: TMenuItem;
    qb_medium_lines_menu_entry: TMenuItem;
    qb_colour_menu_entry: TMenuItem;
    N384: TMenuItem;
    N383: TMenuItem;
    dummy_template_menu_radio: TMenuItem;
    N385: TMenuItem;
    music1_menu_entry: TMenuItem;
    modify_group_to_match_timbering_menu_entry: TMenuItem;
    x1: TMenuItem;
    N386: TMenuItem;
    N387: TMenuItem;
    N388: TMenuItem;
    P32_menu_entry: TMenuItem;
    background_menu: TMenuItem;
    files_menu: TMenuItem;
    CONTROLTEMPLATE1: TMenuItem;
    BACKGROUNDTEMPLATES1: TMenuItem;
    N22: TMenuItem;
    N360: TMenuItem;
    N390: TMenuItem;
    N391: TMenuItem;
    N392: TMenuItem;
    N393: TMenuItem;
    N394: TMenuItem;
    N395: TMenuItem;
    N396: TMenuItem;
    N389: TMenuItem;
    N397: TMenuItem;
    N398: TMenuItem;
    N399: TMenuItem;
    BACKGROUNDSHAPES1: TMenuItem;
    N400: TMenuItem;
    reload_shapes_menu_entry: TMenuItem;
    add_shapes_menu_entry: TMenuItem;
    save_shapes_menu_entry: TMenuItem;
    N401: TMenuItem;
    N402: TMenuItem;
    N403: TMenuItem;
    N129: TMenuItem;
    N145: TMenuItem;
    N289: TMenuItem;
    N404: TMenuItem;
    files_export_menu_entry: TMenuItem;
    N405: TMenuItem;
    N406: TMenuItem;
    N407: TMenuItem;
    background_templates_menu_entry: TMenuItem;
    N408: TMenuItem;
    N409: TMenuItem;
    N410: TMenuItem;
    N411: TMenuItem;
    N412: TMenuItem;
    N413: TMenuItem;
    N414: TMenuItem;
    N415: TMenuItem;
    N416: TMenuItem;
    N417: TMenuItem;
    N418: TMenuItem;
    N419: TMenuItem;
    N420: TMenuItem;
    blank_line_menu_entry: TMenuItem;
    N422: TMenuItem;
    sample_templates_menu_entry: TMenuItem;
    N424: TMenuItem;
    N425: TMenuItem;
    N426: TMenuItem;
    N427: TMenuItem;
    N428: TMenuItem;
    N64: TMenuItem;
    N431: TMenuItem;
    N432: TMenuItem;
    N433: TMenuItem;
    N434: TMenuItem;
    N435: TMenuItem;
    N436: TMenuItem;
    N437: TMenuItem;
    current_spacings_ms_menu_entry: TMenuItem;
    N439: TMenuItem;
    N440: TMenuItem;
    N441: TMenuItem;
    N442: TMenuItem;
    N443: TMenuItem;
    N444: TMenuItem;
    N445: TMenuItem;
    adjust_adjacent_centres_ts_menu_entry: TMenuItem;
    adjust_adjacent_centres_ms_menu_entry: TMenuItem;
    N446: TMenuItem;
    reset_normal_line_position_menu_entry: TMenuItem;
    N447: TMenuItem;
    N448: TMenuItem;
    name_labels_popup_entry: TMenuItem;
    N451: TMenuItem;
    Ememo1: TMenuItem;
    N77: TMenuItem;
    music2_menu_entry: TMenuItem;
    cricket_menu_entry: TMenuItem;
    peg_on_split_deflection_menu_entry: TMenuItem;
    hd_timbering_as_switch_menu_entry: TMenuItem;
    N209: TMenuItem;
    hd_timbering_normal_menu_entry: TMenuItem;
    current_spacings_ts_menu_entry: TMenuItem;
    ms_spacing_info_menu_entry: TMenuItem;
    N450: TMenuItem;
    N452: TMenuItem;
    extend_shorten_to_boundary_popup_entry: TMenuItem;
    N453: TMenuItem;
    extend_to_nearest_boundary_popup_entry: TMenuItem;
    meet_at_ctrl0_popup_entry: TMenuItem;
    meet_at_ctrl6_popup_entry: TMenuItem;
    meet_at_ctrl9_popup_entry: TMenuItem;
    N455: TMenuItem;
    shorten_to_nearest_boundary_popup_entry: TMenuItem;
    peg_on_tminp_menu_entry: TMenuItem;
    peg_on_texitp_menu_entry: TMenuItem;
    move_to_tminp_popup_entry: TMenuItem;
    move_to_texitp_popup_entry: TMenuItem;
    snap_to_tminp_popup_entry: TMenuItem;
    snap_to_texitp_popup_entry: TMenuItem;
    meet_at_tminp_popup_entry: TMenuItem;
    meet_at_texitp_popup_entry: TMenuItem;
    N458: TMenuItem;
    N454: TMenuItem;
    extend_shorten_help_popup_entry: TMenuItem;
    meet_at_tolp_popup_entry: TMenuItem;
    DONOTUSETHEGENERATOR1: TMenuItem;
    generator_menu: TMenuItem;
    N264: TMenuItem;
    N449: TMenuItem;
    N460: TMenuItem;
    N461: TMenuItem;
    N462: TMenuItem;
    THISMENUISNOTFORTRACKDESIGN1: TMenuItem;
    N463: TMenuItem;
    N464: TMenuItem;
    N465: TMenuItem;
    N466: TMenuItem;
    N120: TMenuItem;
    thesesettingscontrolthedisplayandoutput1: TMenuItem;
    usetheothermenusfortrackdesign1: TMenuItem;
    N262: TMenuItem;
    gen_more_information_menu_entry: TMenuItem;
    N468: TMenuItem;
    N469: TMenuItem;
    templot_companion_menu_entry: TMenuItem;
    N467: TMenuItem;
    N470: TMenuItem;
    N481: TMenuItem;
    files_print_menu_entry: TMenuItem;
    N484: TMenuItem;
    N485: TMenuItem;
    N486: TMenuItem;
    draggedontothetrackpad1: TMenuItem;
    N483: TMenuItem;
    bgsshapefilescanalsobe1: TMenuItem;
    N487: TMenuItem;
    go_to_my_documents_menu_entry: TMenuItem;
    N488: TMenuItem;
    N489: TMenuItem;
    N490: TMenuItem;
    N491: TMenuItem;
    N492: TMenuItem;
    add_picture_expert_menu_entry: TMenuItem;
    expert_picture_help_menu_entry: TMenuItem;
    rebuild_group_to_match_cl_options_menu_entry: TMenuItem;
    N493: TMenuItem;
    modify_centre_line_offset_options_popup_entry: TMenuItem;
    knuckle_bend_menu_entry: TMenuItem;
    sharp_knuckle_menu_entry: TMenuItem;
    normal_knuckle_menu_entry: TMenuItem;
    custom_knuckle_menu_entry: TMenuItem;
    custom_knuckle_radius_menu_entry: TMenuItem;
    N457: TMenuItem;
    N494: TMenuItem;
    knuckle_help_menu_entry: TMenuItem;
    N495: TMenuItem;
    N496: TMenuItem;
    N497: TMenuItem;
    explore_page_map_records_menu_entry: TMenuItem;
    printing_page_map_records_menu_entry: TMenuItem;
    pdf_page_map_records_menu_entry: TMenuItem;
    N505: TMenuItem;
    page_map_records_help_menu_entry: TMenuItem;
    N506: TMenuItem;
    N508: TMenuItem;
    rebuild_group_to_match_customize_xing_menu_entry: TMenuItem;
    N509: TMenuItem;
    N510: TMenuItem;
    modify_customized_xing_popup_entry: TMenuItem;
    N511: TMenuItem;
    N512: TMenuItem;
    N513: TMenuItem;
    N514: TMenuItem;
    N515: TMenuItem;
    modify_plain_track_popup_entry: TMenuItem;
    scaling_trackbar: TTrackBar;
    scaling_labels_panel: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    scaling_help_static: TStaticText;
    N516: TMenuItem;
    modify_group_to_match_plain_track_menu_entry: TMenuItem;
    N517: TMenuItem;
    N518: TMenuItem;
    N519: TMenuItem;
    N520: TMenuItem;
    N521: TMenuItem;
    N522: TMenuItem;
    N523: TMenuItem;
    N524: TMenuItem;
    N525: TMenuItem;
    N526: TMenuItem;
    N527: TMenuItem;
    Label9: TLabel;
    scaling_change_button: TButton;
    Label8: TLabel;
    addabackgroundmaporimage1: TMenuItem;
    N529: TMenuItem;
    load_map_menu_entry: TMenuItem;
    N530: TMenuItem;
    N531: TMenuItem;
    N532: TMenuItem;
    N533: TMenuItem;
    N534: TMenuItem;
    N535: TMenuItem;
    N536: TMenuItem;
    N528: TMenuItem;
    trackbed_ballast_edges_menu_entry: TMenuItem;
    N539: TMenuItem;
    N540: TMenuItem;
    N542: TMenuItem;
    N353: TMenuItem;
    add_sketchboard_items_menu_entry: TMenuItem;
    N365: TMenuItem;
    N537: TMenuItem;
    make_slip_menu_entry: TMenuItem;
    make_single_slip_same_hand_menu_entry: TMenuItem;
    make_single_slip_opposite_hand_menu_entry: TMenuItem;
    make_double_slip_menu_entry: TMenuItem;
    N541: TMenuItem;
    N543: TMenuItem;
    make_slip_help_menu_entry: TMenuItem;
    N544: TMenuItem;
    N545: TMenuItem;
    N538: TMenuItem;
    N546: TMenuItem;
    make_single_slip_crossover_menu_entry: TMenuItem;
    N548: TMenuItem;
    N549: TMenuItem;
    N550: TMenuItem;
    make_double_slip_crossover_menu_entry: TMenuItem;
    N551: TMenuItem;
    doublesliptipclearance1: TMenuItem;
    N552: TMenuItem;
    dstip_increase_all_menu_entry: TMenuItem;
    dstip_increase_00EM_menu_entry: TMenuItem;
    dstip_no_increase_menu_entry: TMenuItem;
    tip_clearance_help_menu_entry: TMenuItem;
    doublesliptipclearancefor17andabove1: TMenuItem;
    N553: TMenuItem;
    curviform_timbering_menu_entry: TMenuItem;
    N554: TMenuItem;
    curvi_match_regular_menu_entry: TMenuItem;
    curvi_match_chairs_menu_entry: TMenuItem;
    curviform_timbering_help_menu_entry: TMenuItem;
    N430: TMenuItem;
    N471: TMenuItem;
    ts_spacing_info_menu_entry: TMenuItem;
    prototypemodel1: TMenuItem;
    N473: TMenuItem;
    maps1: TMenuItem;
    N474: TMenuItem;
    N475: TMenuItem;
    N476: TMenuItem;
    N477: TMenuItem;
    N127: TMenuItem;
    N429: TMenuItem;
    N472: TMenuItem;
    N478: TMenuItem;
    split_approach_button: TButton;
    split_exit_button: TButton;
    branch_track_button: TButton;
    Label10: TLabel;
    crossover_button: TButton;
    time_now_panel: TPanel;
    reminder_memo1: TMemo;
    reminder_memo2: TMemo;
    reminder_memo3: TMemo;
    reminder_memo4: TMemo;
    reminder_memo5: TMemo;
    show_reminders_menu_entry: TMenuItem;
    N479: TMenuItem;
    reminder_popup_entry: TMenuItem;
    add_reminder_popup_entry: TMenuItem;
    edit_reminder_popup_entry: TMenuItem;
    remove_reminder_popup_entry: TMenuItem;
    reminder_colour_popup_entry: TMenuItem;
    N482: TMenuItem;
    reminder_popup_menu: TPopupMenu;
    colour_popup_entry: TMenuItem;
    N498: TMenuItem;
    remove_popup_entry: TMenuItem;
    edit_popup_entry: TMenuItem;
    hide_reminders_menu_entry: TMenuItem;
    minimum_turnout_road_menu_entry: TMenuItem;
    snap_to_minimum_exit_menu_entry: TMenuItem;
    main_road_options_menu_entry: TMenuItem;
    minimum_main_road_menu_entry: TMenuItem;
    normal_main_road_menu_entry: TMenuItem;
    N456: TMenuItem;
    mainroadhelp1: TMenuItem;
    main_road_crossover_menu_entry: TMenuItem;
    adjustable_main_road_menu_entry: TMenuItem;
    adjust_main_road_exit_menu_entry: TMenuItem;
    peg_on_mminp_menu_entry: TMenuItem;
    peg_on_mexitp_menu_entry: TMenuItem;
    move_to_mminp_popup_entry: TMenuItem;
    move_to_mexitp_popup_entry: TMenuItem;
    snap_to_mminp_popup_entry: TMenuItem;
    snap_to_mexitp_popup_entry: TMenuItem;
    N192: TMenuItem;
    N499: TMenuItem;
    N500: TMenuItem;
    isolate_crossing_menu_entry: TMenuItem;
    obtain_gaunt_from_turnout_radius_popup_entry: TMenuItem;
    f9_normal_menu_entry: TMenuItem;
    f9_gaunt_radius_fixed_menu_entry: TMenuItem;
    N501: TMenuItem;
    N502: TMenuItem;
    N503: TMenuItem;
    N504: TMenuItem;
    second_toolbar_panel: TPanel;
    peg_indicator_panel: TPanel;
    f7_button: TButton;
    f6_button: TButton;
    f5_button: TButton;
    f4_button: TButton;
    facing_trailing_button: TButton;
    invert_handing_button: TButton;
    ctrlf9_button: TButton;
    xing_indicator_panel: TPanel;
    insert_turnout_button: TButton;
    f8_button: TButton;
    ctrlf5_button: TButton;
    N555: TMenuItem;
    omit_output_trackbed_edges_menu_entry: TMenuItem;
    include_output_trackbed_edges_menu_entry: TMenuItem;
    meet_at_mminp_popup_entry: TMenuItem;
    meet_at_mexitp_popup_entry: TMenuItem;
    gaunt_radius_menu_entry: TMenuItem;
    N556: TMenuItem;
    obtain_negative_curving_menu_entry: TMenuItem;
    obtain_positive_curving_menu_entry: TMenuItem;
    set_full_mouse_draw_menu_entry: TMenuItem;
    N557: TMenuItem;
    adjust_gaunt_radius_menu_entry: TMenuItem;
    N559: TMenuItem;
    pointwork_timbering_menu_entry: TMenuItem;
    switch_timbers_menu_entry: TMenuItem;
    closure_timbers_menu_entry: TMenuItem;
    xing_timbers_menu_entry: TMenuItem;
    approach_track_menu_entry: TMenuItem;
    approach_rails_only_menu_entry: TMenuItem;
    N560: TMenuItem;
    approach_sleepered_menu_entry: TMenuItem;
    approachhelp1: TMenuItem;
    ds_tandem_begin_menu_entry: TMenuItem;
    front_timbers_menu_entry: TMenuItem;
    N561: TMenuItem;
    make3waytandemturnout1: TMenuItem;
    N562: TMenuItem;
    ds_tandem_continue_menu_entry: TMenuItem;
    ss_tandem_begin_menu_entry: TMenuItem;
    ss_tandem_continue_menu_entry: TMenuItem;
    N563: TMenuItem;
    N3way_help_menu_item: TMenuItem;
    N564: TMenuItem;
    tandems_click_first_menu_entry: TMenuItem;
    snap_always_on_background_templates_menu_entry: TMenuItem;
    N565: TMenuItem;
    no_f7_snapping_menu_entry: TMenuItem;
    N566: TMenuItem;
    N567: TMenuItem;
    N568: TMenuItem;
    N569: TMenuItem;
    N570: TMenuItem;
    N571: TMenuItem;
    N572: TMenuItem;
    reset_tandem_turnout_menu_entry: TMenuItem;
    N573: TMenuItem;
    resetderivedpartialtemplate1: TMenuItem;
    N574: TMenuItem;
    N575: TMenuItem;
    N576: TMenuItem;
    N577: TMenuItem;
    N578: TMenuItem;
    N579: TMenuItem;
    N580: TMenuItem;
    N226: TMenuItem;
    N581: TMenuItem;
    help2: TMenuItem;
    N582: TMenuItem;
    f9_k_angle_fixed_menu_entry: TMenuItem;
    f9_hd_radius_fixed_menu_entry: TMenuItem;
    N583: TMenuItem;
    k_crossing_radius_menu_entry: TMenuItem;
    obtain_diagonal_from_turnout_radius_popup_entry: TMenuItem;
    N584: TMenuItem;
    show_bgnd_keeps_in_rect_menu_entry: TMenuItem;
    return_curve_button: TButton;
    double_track_buttom: TButton;
    f3_button: TButton;
    zoom_rectangle_latching_toolbutton: TSpeedButton;
    N236: TMenuItem;
    N586: TMenuItem;
    N587: TMenuItem;
    N588: TMenuItem;
    N589: TMenuItem;
    utils_menu: TMenuItem;
    N69: TMenuItem;
    N361: TMenuItem;
    N590: TMenuItem;
    N591: TMenuItem;
    N592: TMenuItem;
    N593: TMenuItem;
    N594: TMenuItem;
    rotate_group_90degs_acw_menu_entry: TMenuItem;
    rotate_group_90degs_cw_menu_entry: TMenuItem;
    N595: TMenuItem;
    N596: TMenuItem;
    shift_group_into_positve_quadrant_menu_entry: TMenuItem;
    N597: TMenuItem;
    N598: TMenuItem;
    N600: TMenuItem;
    N601: TMenuItem;
    N175: TMenuItem;
    N602: TMenuItem;
    rebuild_group_to_match_chairs_menu_entry: TMenuItem;
    N605: TMenuItem;
    modify_chair_outlines_popup_entry: TMenuItem;
    N607: TMenuItem;
    N608: TMenuItem;
    N609: TMenuItem;
    EXPERIMENTALCHAIRING1: TMenuItem;
    N610: TMenuItem;
    rolledintimbers1: TMenuItem;
    rolled_in_sleepered_menu_entry: TMenuItem;
    rolled_in_rails_only_menu_entry: TMenuItem;
    N611: TMenuItem;
    rolled_in_help_menu_entry: TMenuItem;
    peg_on_dummy_vehicle_menu_entry: TMenuItem;
    N612: TMenuItem;
    N459: TMenuItem;
    N205: TMenuItem;
    changes_this_version_menu_entry: TMenuItem;
    ctrlf10_button: TButton;
    Label11: TLabel;
    convert_to_plain_track_button: TButton;
    how_to_menu_entry: TMenuItem;
    N480: TMenuItem;
    box_menu: TMenuItem;
    make_simple_link_popup_entry: TMenuItem;
    N613: TMenuItem;
    N614: TMenuItem;
    N615: TMenuItem;
    N158: TMenuItem;
    N616: TMenuItem;
    N617: TMenuItem;
    N618: TMenuItem;
    bold_timbers_on_last_menu_entry: TMenuItem;
    normal_timbers_on_last_menu_entry: TMenuItem;
    removetimberoutlineextensionmarks1: TMenuItem;
    remove_extensions_from_all_menu_entry: TMenuItem;
    remove_extensions_from_group_menu_entry: TMenuItem;
    restore_timber_extension_marks_menu_entry: TMenuItem;
    N619: TMenuItem;
    N620: TMenuItem;
    show_corner_info_menu_entry: TMenuItem;
    wide_format_menu_entry: TMenuItem;
    N507: TMenuItem;
    N621: TMenuItem;
    N622: TMenuItem;
    N623: TMenuItem;
    exchange_1_menu_entry: TMenuItem;
    exchange_2_menu_entry: TMenuItem;
    exchange_3_menu_entry: TMenuItem;
    N624: TMenuItem;
    N625: TMenuItem;
    N626: TMenuItem;
    N627: TMenuItem;
    N628: TMenuItem;
    changes_previous_versions_menu_entry: TMenuItem;
    shapes_menu: TMenuItem;
    N35: TMenuItem;
    sketchboard_button: TSpeedButton;
    N63: TMenuItem;
    modified_timbering_infill_menu_entry: TMenuItem;
    N558: TMenuItem;
    designaids1: TMenuItem;
    osk_match_menu_entry: TMenuItem;
    peg_on_osmp_menu_entry: TMenuItem;
    N631: TMenuItem;
    peg_on_osxp_menu_entry: TMenuItem;
    N632: TMenuItem;
    N633: TMenuItem;
    obtain_k_match_popup_entry: TMenuItem;
    N636: TMenuItem;
    group_all_with_all_same_tags_popup_entry: TMenuItem;
    group_all_with_same_tag_popup_entry: TMenuItem;
    N637: TMenuItem;
    N638: TMenuItem;
    adjacent_spacing_ms_menu_entry: TMenuItem;
    N639: TMenuItem;
    N640: TMenuItem;
    timber_numbering_over_platforms_menu_entry: TMenuItem;
    y_scaling_distortion_menu_entry: TMenuItem;
    N325: TMenuItem;
    N635: TMenuItem;
    N641: TMenuItem;
    N642: TMenuItem;
    N643: TMenuItem;
    N644: TMenuItem;
    N645: TMenuItem;
    N646: TMenuItem;
    N647: TMenuItem;
    reset_normal_y_scaling_menu_entry: TMenuItem;
    show_timber_totals_menu_entry: TMenuItem;
    N648: TMenuItem;
    N649: TMenuItem;
    real_omit_menu_entry: TMenuItem;
    set_droppers_gaps_menu_entry: TMenuItem;
    N650: TMenuItem;
    view_reset_org_menu_entry: TMenuItem;
    library_viewer_menu_entry: TMenuItem;
    N651: TMenuItem;
    copy_group_as_library_menu_entry: TMenuItem;
    copy_group_as_unused_menu_entry: TMenuItem;
    N653: TMenuItem;
    N654: TMenuItem;
    N655: TMenuItem;
    N656: TMenuItem;
    show_library_viewer_menu_entry: TMenuItem;
    put_peg_on_intersect_popup_entry: TMenuItem;
    N657: TMenuItem;
    get_file_from_code_menu_entry: TMenuItem;
    N658: TMenuItem;
    N659: TMenuItem;
    pad_dropper_font_label: TLabel;
    move_locator_menu_entry: TMenuItem;
    show_locator_menu_entry: TMenuItem;
    obtain_ext_geo_radius_popup_entry: TMenuItem;
    obtain_positive_geo_menu_entry: TMenuItem;
    N661: TMenuItem;
    obtain_negative_geo_menu_entry: TMenuItem;
    make_y_turnout_menu_entry: TMenuItem;
    force_symmetry_menu_entry: TMenuItem;
    N662: TMenuItem;
    N147: TMenuItem;
    N663: TMenuItem;
    show_template_symbols_menu_entry: TMenuItem;
    hide_template_symbols_menu_entry: TMenuItem;
    N664: TMenuItem;
    D0GA_menu_entry: TMenuItem;
    N660: TMenuItem;
    music3_menu_entry: TMenuItem;
    N665: TMenuItem;
    peg_on_kp1_menu_entry: TMenuItem;
    peg_on_kp2_menu_entry: TMenuItem;
    peg_on_kp3_menu_entry: TMenuItem;
    peg_on_kp4_menu_entry: TMenuItem;
    v_rail_joints_menu_entry: TMenuItem;
    parapets_menu_entry: TMenuItem;
    N278: TMenuItem;
    ts_parapet_menu_entry: TMenuItem;
    ms_parapet_menu_entry: TMenuItem;
    N421: TMenuItem;
    parapets_help_menu_entry: TMenuItem;
    reset_normal_ts_platform_menu_entry: TMenuItem;
    N438: TMenuItem;
    reset_normal_ms_platform_menu_entry: TMenuItem;
    reposition_menu_popup_entry: TMenuItem;
    short_angle_timbering_menu_entry: TMenuItem;
    simplified_short_angle_timbering_menu_entry: TMenuItem;
    normal_short_angle_timbering_menu_entry: TMenuItem;
    N629: TMenuItem;
    shortangletimberinginfo1: TMenuItem;
    N630: TMenuItem;
    online_stl_repair_menu_entry: TMenuItem;
    N170: TMenuItem;
    show_3d_timber_flanges_menu_entry: TMenuItem;
    N666: TMenuItem;
    N668: TMenuItem;
    EXPERIMENTALMODE1: TMenuItem;
    DXFSTLfileexport1: TMenuItem;
    N604: TMenuItem;
    N667: TMenuItem;
    online_mesh_repair_menu_entry: TMenuItem;
    N669: TMenuItem;
    N670: TMenuItem;
    adjust_clip_size_menu_entry: TMenuItem;
    adjust_clip_angle_menu_entry: TMenuItem;
    N671: TMenuItem;
    N672: TMenuItem;
    use_all_bridge_chairs_menu_entry: TMenuItem;
    timberoutlines1: TMenuItem;
    N673: TMenuItem;
    show_2d_cutter_kerf_lines_menu_entry: TMenuItem;
    N674: TMenuItem;
    use_custom_switch_opening_menu_entry: TMenuItem;
    set_custom_switch_opening_menu_entry: TMenuItem;
    chairkeying1: TMenuItem;
    keys_forwards_menu_entry: TMenuItem;
    keys_backwards_menu_entry: TMenuItem;
    keys_random_menu_entry: TMenuItem;
    keys_to_joint_menu_entry: TMenuItem;
    N676: TMenuItem;
    key_offset_max_menu_entry: TMenuItem;
    N678: TMenuItem;
    N423: TMenuItem;
    samples_009_menu_entry: TMenuItem;
    N679: TMenuItem;
    N680: TMenuItem;
    N681: TMenuItem;
    load_ng_templates_menu_entry: TMenuItem;
    drawnewtemplate1: TMenuItem;
    N603: TMenuItem;
    shiftrotategroup1: TMenuItem;
    N684: TMenuItem;
    N153: TMenuItem;
    N154: TMenuItem;
    copygroup1: TMenuItem;
    N246: TMenuItem;
    N685: TMenuItem;
    N223: TMenuItem;
    N634: TMenuItem;
    tagsandlabels1: TMenuItem;
    N268: TMenuItem;
    N652: TMenuItem;
    N686: TMenuItem;
    N599: TMenuItem;
    search_for_menu_entry: TMenuItem;
    N683: TMenuItem;
    trackpadshowsbricktemplates1: TMenuItem;
    N118: TMenuItem;
    show_brick_templates_menu_entry: TMenuItem;
    show_only_brick_templates_menu_entry: TMenuItem;
    N606: TMenuItem;
    use_all_RG_menu_entry: TMenuItem;
    use_all_FG_menu_entry: TMenuItem;
    control_is_brick_menu_entry: TMenuItem;
    N687: TMenuItem;
    N688: TMenuItem;
    group_select_all_bricks_menu_entry: TMenuItem;
    store_as_brick_menu_entry: TMenuItem;
    save_all_brick_templates_menu_entry: TMenuItem;
    cancel_brick_popup_entry: TMenuItem;
    Qbricktemplate1: TMenuItem;
    set_brick_popup_entry: TMenuItem;
    N690: TMenuItem;
    brick_colour_popup_entry: TMenuItem;
    N691: TMenuItem;
    hide_brick_templates_menu_entry: TMenuItem;
    all_brick_templates_menu_entry: TMenuItem;
    current_brick_templates_only_menu_entry: TMenuItem;
    N692: TMenuItem;
    N693: TMenuItem;
    load_sg_templates_menu_entry: TMenuItem;
    samples_0n16p5_menu_entry: TMenuItem;
    N682: TMenuItem;
    mixedgauge1: TMenuItem;
    N694: TMenuItem;
    N695: TMenuItem;
    save_current_brick_templates_menu_entry: TMenuItem;
    group_select_current_brick_menu_entry: TMenuItem;
    deletebricktemplates1: TMenuItem;
    delete_all_brick_templates_menu_entry: TMenuItem;
    delete_current_brick_templates_menu_entry: TMenuItem;
    adjust_slab_angle_menu_entry: TMenuItem;
    N696: TMenuItem;
    bgnd_template_detail_menu_entry: TMenuItem;
    N697: TMenuItem;
    convert_group_menu_entry: TMenuItem;
    N698: TMenuItem;
    music4_menu_entry: TMenuItem;
    N345: TMenuItem;
    kerf_snibs_menu_entry: TMenuItem;
    template_is_waybeams_menu_entry: TMenuItem;
    N699: TMenuItem;
    N700: TMenuItem;
    show_hide_brick_shapes_menu_entry: TMenuItem;
    N701: TMenuItem;
    store_draw_button: TButton;
    output_rectangle_latching_toolbutton: TSpeedButton;
    brick_button: TButton;
    chairs_menu_entry: TMenuItem;
    N702: TMenuItem;
    bgtrackbed_edges_colour_menu_entry: TMenuItem;
    showhidebrickshapesbycolour1: TMenuItem;
    toggle_brick_templates_menu_entry: TMenuItem;
    toggle_group_templates_menu_entry: TMenuItem;
    N704: TMenuItem;
    N705: TMenuItem;
    use_all_SC_menu_entry: TMenuItem;
    N585: TMenuItem;
    N703: TMenuItem;
    show_tagged_templates_menu_entry: TMenuItem;
    hide_tagged_templates_menu_entry: TMenuItem;
    rotate_by_v_angle_menu_entry: TMenuItem;
    rotate_v_angle_anticlock_menu_entry: TMenuItem;
    rotate_v_angle_clock_menu_entry: TMenuItem;
    N706: TMenuItem;
    rotate_by_k_angle_menu_entry: TMenuItem;
    rotate_k_angle_anticlock_menu_entry: TMenuItem;
    rotate_k_angle_clock_menu_entry: TMenuItem;
    how_to_print_template_menu_entry: TMenuItem;
    N707: TMenuItem;
    yellow_drag_panel: TPanel;
    N708: TMenuItem;
    N709: TMenuItem;
    use_all_S1J_on_switch_front_menu_entry: TMenuItem;
    N710: TMenuItem;
    include_key_with_outers_menu_entry: TMenuItem;
    N711: TMenuItem;
    add_rail_seat_menu_entry: TMenuItem;
    slab_bracket_menu_entry: TMenuItem;
    N712: TMenuItem;
    use_S1J_at_wing_front_menu_entry: TMenuItem;
    N713: TMenuItem;
    N714: TMenuItem;
    a_chair_options_menu_entry: TMenuItem;
    N715: TMenuItem;
    cast_a_chair_menu_entry: TMenuItem;
    info1: TMenuItem;
    N675: TMenuItem;
    add_nose_clamp_menu_entry: TMenuItem;
    allow_parallel_wing_DD_menu_entry: TMenuItem;
    add_xing_gap_filler_menu_entry: TMenuItem;
    copy_for_brick_popup_entry: TMenuItem;
    N716: TMenuItem;
    group_select_all_non_bricks_menu_entry: TMenuItem;
    grid_100mm_spacing_menu_entry: TMenuItem;
    grid_4in_spacing_menu_entry: TMenuItem;
    grid_9in_spacing_menu_entry: TMenuItem;
    grid_25mm_spacing_menu_entry: TMenuItem;
    THISISUNFINISHEDWORKINPROGRESS1: TMenuItem;
    MANYFUNCTIONSAREINCOMPLETE1: TMenuItem;
    N717: TMenuItem;
    REFERTOTEMPLOTCLUBUSERFORUM1: TMenuItem;
    N677: TMenuItem;
    N718: TMenuItem;
    CCLCCRcheckrailendchairs1: TMenuItem;
    fixed_ccl_ccr_menu_entry: TMenuItem;
    variable_ccl_ccr_menu_entry: TMenuItem;
    N719: TMenuItem;
    ms_snibs_menu_entry: TMenuItem;
    ts_snibs_menu_entry: TMenuItem;
    N547: TMenuItem;
    N720: TMenuItem;
    switch_drive_sliders_menu_entry: TMenuItem;
    parallelwingVcrossing1: TMenuItem;
    N721: TMenuItem;
    N722: TMenuItem;
    N723: TMenuItem;
    temp_use_wrong_chairs_menu_entry: TMenuItem;
    select_group_by_date_menu_entry: TMenuItem;
    N724: TMenuItem;
    S1andS1Jchairs1: TMenuItem;
    REA_3screws_menu_entry: TMenuItem;
    BRW_2bolts_menu_entry: TMenuItem;
    N689: TMenuItem;
    N725: TMenuItem;

    procedure minimize_panelClick(Sender: TObject);
    procedure OO3D_menu_entryClick(Sender: TObject);
    procedure get_file_from_code_menu_entryClick(Sender: TObject);
    procedure pad_file_viewer_menu_entryClick(Sender: TObject);
    procedure print_control_template_menu_entryClick(Sender: TObject);
    procedure paper_colour_menu_entryClick(Sender: TObject);
    procedure grid_colour_menu_entryClick(Sender: TObject);
    procedure rail_colour_menu_entryClick(Sender: TObject);
    procedure adjust_curving_menu_entryClick(Sender: TObject);
    procedure adjust_both_menu_entryClick(Sender: TObject);
    procedure adjust_turnout_menu_entryClick(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure f12_redraw_popup_entryClick(Sender: TObject);
    procedure free_scaling_menu_entryClick(Sender: TObject);
    procedure lock_scaling_menu_entryClick(Sender: TObject);
    procedure lock_scaling_at_menu_entryClick(Sender: TObject);
    procedure align_colour_menu_entryClick(Sender: TObject);
    procedure sketchboard_buttonClick(Sender: TObject);
    procedure sketchboard_show_menu_entryClick(Sender: TObject);
    procedure T2_panelClick(Sender: TObject);
    procedure T2_panelMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
    procedure timber_colour_menu_entryClick(Sender: TObject);
    procedure show_info_menu_entryClick(Sender: TObject);
    procedure printer_setup_menu_entryClick(Sender: TObject);
    procedure hide_info_menu_entryClick(Sender: TObject);
    procedure print_grid_on_menu_entryClick(Sender: TObject);
    procedure print_grid_off_menu_entryClick(Sender: TObject);
    procedure set_any_grid_spacing_menu_entryClick(Sender: TObject);
    procedure print_screen_menu_entryClick(Sender: TObject);
    procedure back_colour_menu_entryClick(Sender: TObject);
    procedure info_font_menu_entryClick(Sender: TObject);
    procedure min_rad_menu_entryClick(Sender: TObject);
    procedure red_lamp_timerTimer(Sender: TObject);
    procedure keep_this_menu_entryClick(Sender: TObject);
    procedure program_panel_menu_entryClick(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure hatched_infill_menu_entryClick(Sender: TObject);
    procedure solid_infill_menu_entryClick(Sender: TObject);
    procedure cross_hatched_infill_menu_entryClick(Sender: TObject);
    procedure switch_menu_entryClick(Sender: TObject);
    procedure rail_section_menu_entryClick(Sender: TObject);
    procedure crossing_menu_entryClick(Sender: TObject);
    procedure curving_data_menu_entryClick(Sender: TObject);
    procedure outer_edges_only_menu_entryClick(Sender: TObject);
    procedure basic_turnout_menu_entryClick(Sender: TObject);
    procedure pad_quit_menu_entryClick(Sender: TObject);
    procedure sb_black_white_menu_entryClick(Sender: TObject);
    procedure sb_red_yellow_menu_entryClick(Sender: TObject);
    procedure sb_grid_paper_menu_entryClick(Sender: TObject);
    procedure mm_scalebar_menu_entryClick(Sender: TObject);
    procedure inch_scalebar_menu_entryClick(Sender: TObject);
    procedure hide_scalebar_menu_entryClick(Sender: TObject);
    procedure grid_font_menu_entryClick(Sender: TObject);
    procedure screengrid_on_menu_entryClick(Sender: TObject);
    procedure screengrid_off_menu_entryClick(Sender: TObject);
    procedure view_box_menu_entryClick(Sender: TObject);
    procedure checks_menu_entryClick(Sender: TObject);
    procedure adjacent_spacing_ts_menu_entryClick(Sender: TObject);
    procedure lengths_mm_menu_entryClick(Sender: TObject);
    procedure normal_scaling_menu_entryClick(Sender: TObject);
    procedure set_output_size_menu_entryClick(Sender: TObject);
    procedure portrait_menu_entryClick(Sender: TObject);
    procedure landscape_menu_entryClick(Sender: TObject);
    procedure print_grid_colour_menu_entryClick(Sender: TObject);
    procedure margin_colour_menu_entryClick(Sender: TObject);
    procedure print_rail_colour_menu_entryClick(Sender: TObject);
    procedure print_timber_colour_menu_entryClick(Sender: TObject);
    procedure print_font_menu_entryClick(Sender: TObject);
    procedure print_preview_menu_entryClick(Sender: TObject);
    procedure straight_template_menu_entryClick(Sender: TObject);
    procedure constant_radius_menu_entryClick(Sender: TObject);
    procedure rail_infill_colours_menu_entryClick(Sender: TObject);
    procedure swap_hand_menu_entryClick(Sender: TObject);
    procedure lock_switch_popup_entryClick(Sender: TObject);
    procedure lock_xing_popup_entryClick(Sender: TObject);
    procedure show_popup_menu_entryClick(Sender: TObject);
    procedure unlock_both_popup_entryClick(Sender: TObject);
    procedure black_and_white_printing_menu_entryClick(Sender: TObject);
// OT2024     procedure colour_printing_menu_entryClick(Sender: TObject);
    procedure timber_infill_colour_menu_entryClick(Sender: TObject);
    procedure adjust_length_menu_entryClick(Sender: TObject);
    procedure guide_marks_menu_entryClick(Sender: TObject);
    procedure rad_end_marks_menu_entryClick(Sender: TObject);
    procedure nearest_menu_entryClick(Sender: TObject);
    procedure equalized_incremental_menu_entryClick(Sender: TObject);
    procedure square_on_menu_entryClick(Sender: TObject);
    procedure timbering_data_menu_entryClick(Sender: TObject);
    procedure plain_track_data_menu_entryClick(Sender: TObject);
    //procedure reset_to_plain_track_menu_entryClick(Sender: TObject);
    procedure current_timber_centres_menu_entryClick(Sender: TObject);
    procedure current_timber_outlines_menu_entryClick(Sender: TObject);
    procedure show_current_template_guides_menu_entryClick(Sender: TObject);
    //procedure gen_main_side_near_menu_entryClick(Sender: TObject);
    //procedure gen_main_side_far_menu_entryClick(Sender: TObject);
    //procedure gen_turnout_side_near_menu_entryClick(Sender: TObject);
    //procedure gen_turnout_side_far_menu_entryClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure shift_menu_entryClick(Sender: TObject);
    procedure transform_data_menu_entryClick(Sender: TObject);
    procedure rotate_menu_entryClick(Sender: TObject);
    procedure transform_clear_menu_entryClick(Sender: TObject);
    procedure adjust_zoom_menu_entryClick(Sender: TObject);
    procedure transform_normalize_menu_entryClick(Sender: TObject);
    procedure length_free_popup_entryClick(Sender: TObject);
    procedure length_locked_popup_entryClick(Sender: TObject);
    procedure metric_calc_menu_entryClick(Sender: TObject);
    procedure calibrate_printer_menu_entryClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure all_grey_menu_entryClick(Sender: TObject);
    procedure preset_schemes_menu_entryClick(Sender: TObject);
    procedure colour_panelClick(Sender: TObject);
    procedure shift_to_datum_menu_entryClick(Sender: TObject);
    procedure adjust_turnout_approach_menu_entryClick(Sender: TObject);
    procedure long_turnout_road_menu_entryClick(Sender: TObject);
    procedure show_mouse_panel_menu_entryClick(Sender: TObject);
    procedure hide_mouse_panel_menu_entryClick(Sender: TObject);
    procedure print_guide_colour_menu_entryClick(Sender: TObject);
    procedure print_align_colour_menu_entryClick(Sender: TObject);
    procedure startup_colours_menu_entryClick(Sender: TObject);
    procedure guide_colour_menu_entryClick(Sender: TObject);
    procedure page_outlines_pdf_menu_entryClick(Sender: TObject);
    procedure page_outlines_off_menu_entryClick(Sender: TObject);
    procedure print_info_menu_entryClick(Sender: TObject);
    procedure timber_outlines_menu_entryClick(Sender: TObject);
    procedure timber_numbers_menu_entryClick(Sender: TObject);
    procedure timber_centres_menu_entryClick(Sender: TObject);
    procedure both_edges_menu_entryClick(Sender: TObject);
    procedure gauge_faces_only_menu_entryClick(Sender: TObject);
    procedure rail_centrelines_only_menu_entryClick(Sender: TObject);
    procedure stock_rails_menu_entryClick(Sender: TObject);
    procedure crossing_rails_menu_entryClick(Sender: TObject);
    procedure check_rails_menu_entryClick(Sender: TObject);
    procedure f5_quarter_steps_menu_entryClick(Sender: TObject);
    procedure f5_any_angle_menu_entryClick(Sender: TObject);
    procedure joint_marks_menu_entryClick(Sender: TObject);
    procedure print_joint_colour_menu_entryClick(Sender: TObject);
    procedure joint_colour_menu_entryClick(Sender: TObject);
    procedure page_outline_colour_menu_entryClick(Sender: TObject);
    procedure delete_calibration_menu_entryClick(Sender: TObject);
    procedure delete_all_calibrations_menu_entryClick(Sender: TObject);
    procedure proof_sheet_menu_entryClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure move_datum_menu_entryClick(Sender: TObject);
    procedure adjust_rad1_menu_entryClick(Sender: TObject);
    procedure adjust_rad2_menu_entryClick(Sender: TObject);
    procedure adjust_trans_length_menu_entryClick(Sender: TObject);
    procedure trans_colour_menu_entryClick(Sender: TObject);
    procedure move_pad_origin_menu_entryClick(Sender: TObject);
    procedure trace_on_menu_entryClick(Sender: TObject);
    procedure trace_off_menu_entryClick(Sender: TObject);
    procedure trace_on_popup_entryClick(Sender: TObject);
    procedure trace_off_popup_entryClick(Sender: TObject);
    procedure exit_sleepers_menu_entryClick(Sender: TObject);
    procedure exit_timbers_menu_entryClick(Sender: TObject);
    procedure exit_no_timbers_menu_entryClick(Sender: TObject);
    procedure timbers_centralized_menu_entryClick(Sender: TObject);
    procedure timbers_in_line_menu_entryClick(Sender: TObject);
    procedure save_calibration_menu_entryClick(Sender: TObject);
    procedure reload_calibration_menu_entryClick(Sender: TObject);
// OT2024     procedure cal_settings_menu_entryClick(Sender: TObject);
    procedure modify_gauge_menu_entryClick(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure rotate_current_180_menu_entryClick(Sender: TObject);
    procedure generate_with_diagnostics_menu_entryClick(Sender: TObject);
    procedure cancel_distortions_popup_entryClick(Sender: TObject);
    procedure print_timber_numbers_font_menu_entryClick(Sender: TObject);
    procedure snap_to_catch_points_menu_entryClick(Sender: TObject);
    procedure show_shapes_menu_entryClick(Sender: TObject);
    procedure bgnd_shapes_menu_entryClick(Sender: TObject);
    //procedure print_shapes_on_menu_entryxClick(Sender: TObject);
    //procedure print_shapes_off_menu_entryxClick(Sender: TObject);
    procedure hide_shapes_menu_entryClick(Sender: TObject);
    procedure toggle_bgnd_templates_menu_entryClick(Sender: TObject);
    //procedure hide_bgnd_keeps_menu_entryClick(Sender: TObject);
    procedure shapes_colour_menu_entryClick(Sender: TObject);
    procedure bgrails_colour_menu_entryClick(Sender: TObject);
    procedure adjust_spot_zoom_menu_entryClick(Sender: TObject);
    procedure store_and_background_menu_entryClick(Sender: TObject);
    procedure fit_bgnd_menu_entryClick(Sender: TObject);
    procedure fit_org_extents_current_menu_entryClick(Sender: TObject);
    procedure spot_and_scale_menu_entryClick(Sender: TObject);
    procedure show_zoom_target_menu_entryClick(Sender: TObject);
    procedure show_pan_controls_menu_entryClick(Sender: TObject);
    procedure set_skeleton_mouse_draw_menu_entryClick(Sender: TObject);
    procedure view_reset_max_menu_entryClick(Sender: TObject);
    procedure reset_datum_menu_entryClick(Sender: TObject);
    procedure set_datum_menu_entryClick(Sender: TObject);
    procedure main_menuClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure slide_menu_entryClick(Sender: TObject);
    procedure move_ring_menu_entryClick(Sender: TObject);
    procedure adjust_slew_start_menu_entryClick(Sender: TObject);
    procedure adjust_slew_length_menu_entryClick(Sender: TObject);
    procedure shortcuts_list_menu_entryClick(Sender: TObject);
    procedure bgtimber_colour_menu_entryClick(Sender: TObject);
    procedure bgmarks_colour_menu_entryClick(Sender: TObject);
    procedure background_font_menu_entryClick(Sender: TObject);
    procedure reset_peg_menu_entryClick(Sender: TObject);
    procedure peg_on_fp_menu_entryClick(Sender: TObject);
    procedure move_peg_menu_entryClick(Sender: TObject);
    procedure peg_on_joint_end_menu_entryClick(Sender: TObject);
    procedure set_peg_menu_entryClick(Sender: TObject);
    procedure mouse_factors_menu_entryClick(Sender: TObject);
    procedure peg_on_rail4_menu_entryClick(Sender: TObject);
    procedure peg_on_rail3_menu_entryClick(Sender: TObject);
    procedure peg_on_rail2_menu_entryClick(Sender: TObject);
    procedure peg_on_rail1_menu_entryClick(Sender: TObject);
    procedure peg_is_free_menu_entryClick(Sender: TObject);
    procedure explode_normal_menu_entryClick(Sender: TObject);
    procedure shrink_normal_menu_entryClick(Sender: TObject);
    procedure orbit_rad_centre_menu_entryClick(Sender: TObject);
    procedure shift_keeps_menu_entryClick(Sender: TObject);
    procedure rotate_keeps_menu_entryClick(Sender: TObject);
    procedure centre_lines_menu_entryClick(Sender: TObject);
    procedure peg_on_dp_menu_entryClick(Sender: TObject);
    procedure peg_on_rail8_menu_entryClick(Sender: TObject);
    procedure peg_on_rail9_menu_entryClick(Sender: TObject);
    procedure peg_on_tp_menu_entryClick(Sender: TObject);
    procedure peg_on_tcp_menu_entryClick(Sender: TObject);
    procedure peg_on_txp_menu_entryClick(Sender: TObject);
    procedure peg_on_mcp_menu_entryClick(Sender: TObject);
    procedure peg_on_mxp_menu_entryClick(Sender: TObject);
    procedure peg_on_overall_length_menu_entryClick(Sender: TObject);
    procedure pad_on_peg_menu_entryClick(Sender: TObject);
    procedure move_notch_menu_entryClick(Sender: TObject);
    procedure set_notch_menu_entryClick(Sender: TObject);
    procedure notch_under_peg_menu_entryClick(Sender: TObject);
    procedure shift_current_onto_notch_menu_entryClick(Sender: TObject);
    procedure reset_notch_menu_entryClick(Sender: TObject);
    procedure normal_turnout_road_menu_entryClick(Sender: TObject);
    procedure crossover_road_menu_entryClick(Sender: TObject);
    procedure make_simple_crossover_menu_entryClick(Sender: TObject);
    procedure adjust_trans_start_menu_entryClick(Sender: TObject);
    procedure pad_on_notch_menu_entryClick(Sender: TObject);
    procedure select_centre_menu_entryClick(Sender: TObject);
    procedure bg_peg_colour_menu_entryClick(Sender: TObject);
    procedure hide_control_template_menu_entryClick(Sender: TObject);
    procedure peg_on_trp_menu_entryClick(Sender: TObject);
    procedure peg_on_mrp_menu_entryClick(Sender: TObject);
    procedure undo_changes_menu_entryClick(Sender: TObject);
    procedure redo_changes_menu_entryClick(Sender: TObject);
    procedure print_in_normal_colours_menu_entryClick(Sender: TObject);
    procedure print_all_in_single_colour_menu_entryClick(Sender: TObject);
    procedure printed_shapes_colour_menu_entryClick(Sender: TObject);
    procedure set_single_colour_menu_entryClick(Sender: TObject);
    procedure print_entire_pad_menu_entryClick(Sender: TObject);
    procedure peg_on_rail6_menu_entryClick(Sender: TObject);
    procedure peg_on_rail5_menu_entryClick(Sender: TObject);
    procedure peg_on_rail7_menu_entryClick(Sender: TObject);
    procedure peg_on_adjacent_ts_menu_entryClick(Sender: TObject);
    procedure make_double_track_ts_menu_entryClick(Sender: TObject);
    procedure make_double_track_ms_menu_entryClick(Sender: TObject);
    procedure peg_on_adjacent_ms_menu_entryClick(Sender: TObject);
    procedure reduced_ends_menu_entryClick(Sender: TObject);
    procedure double200_menu_entryClick(Sender: TObject);
    procedure half50_menu_entryClick(Sender: TObject);
    procedure third3333_menu_entryClick(Sender: TObject);
    procedure quarter25_menu_entryClick(Sender: TObject);
    procedure fifth20_menu_entryClick(Sender: TObject);
    procedure eighth125_menu_entryClick(Sender: TObject);
    procedure tenth10_menu_entryClick(Sender: TObject);
    procedure sixteenth625_menu_entryClick(Sender: TObject);
    procedure twentieth5_menu_entryClick(Sender: TObject);
    procedure N2ft1667_menu_entryClick(Sender: TObject);
    procedure N1ft833_menu_entryClick(Sender: TObject);
    procedure N05ft417_menu_entryClick(Sender: TObject);
    procedure N025ft208_menu_entryClick(Sender: TObject);
    procedure fortieth25_menu_entryClick(Sender: TObject);
    procedure convert_vcrossing_RAM_to_CLM_menu_entryClick(Sender: TObject);
    procedure peg_on_TORG_menu_entryClick(Sender: TObject);
    procedure spacing_ring_menu_entryClick(Sender: TObject);
    procedure peg_on_trans_start_menu_entryClick(Sender: TObject);
    procedure peg_on_trans_length_menu_entryClick(Sender: TObject);
    procedure outline_extensions_menu_entryClick(Sender: TObject);
    procedure fkey_chart_menu_entryClick(Sender: TObject);
    procedure pad_about_Templot_menu_entryClick(Sender: TObject);
    procedure extra_fine_adjust_menu_entryClick(Sender: TObject);
    procedure fine_adjust_menu_entryClick(Sender: TObject);
    procedure normal_adjust_menu_entryClick(Sender: TObject);
    procedure coarse_adjust_menu_entryClick(Sender: TObject);
    procedure click_bgnd_selection_menu_entryClick(Sender: TObject);
    procedure transparent_names_menu_entryClick(Sender: TObject);
    procedure boxed_over_names_menu_entryClick(Sender: TObject);
    procedure rotate_keeps_180_menu_entryClick(Sender: TObject);
    //procedure shift_keeps_onto_notch_menu_entryClick(Sender: TObject);
    procedure show_group_menu_entryClick(Sender: TObject);
    procedure invert_selections_menu_entryClick(Sender: TObject);
    procedure names_scaled_menu_entryClick(Sender: TObject);
    procedure names_fullsize_menu_entryClick(Sender: TObject);
    //procedure undo_shift_keeps_menu_entryClick(Sender: TObject);
    procedure slewing_data_menu_entryClick(Sender: TObject);
    procedure disable_slewing_menu_entryClick(Sender: TObject);
    procedure adjust_slew_amount_menu_entryClick(Sender: TObject);
    procedure cycle_notch_menu_entryClick(Sender: TObject);
    procedure bring_to_front_menu_entryClick(Sender: TObject);
    procedure send_to_back_menu_entryClick(Sender: TObject);
    procedure mouse_draw_menu_entryClick(Sender: TObject);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure shove_timbers_menu_entryClick(Sender: TObject);
    procedure adjust_print_size_menu_entryClick(Sender: TObject);
    procedure centre_lines_only_menu_radioClick(Sender: TObject);
    procedure restore_and_bgnd_menu_entryClick(Sender: TObject);
    procedure A3_A4_menu_entryClick(Sender: TObject);
    procedure single_sheets_menu_entryClick(Sender: TObject);
    procedure fit_single_page_menu_entryClick(Sender: TObject);
    procedure banner_paper_menu_entryClick(Sender: TObject);
    procedure snap_approach_to_nearest_menu_entryClick(Sender: TObject);
    procedure shorten_approach_one_menu_entryClick(Sender: TObject);
    procedure extend_approach_one_menu_entryClick(Sender: TObject);
    procedure snap_exit_to_nearest_menu_entryClick(Sender: TObject);
    procedure shorten_exit_one_menu_entryClick(Sender: TObject);
    procedure extend_exit_one_menu_entryClick(Sender: TObject);
    procedure peg_on_MVJP_menu_entryClick(Sender: TObject);
    procedure snap_to_MVJP_menu_entryClick(Sender: TObject);
    procedure snap_exit_to_return_curve_menu_entryClick(Sender: TObject);
    procedure make_return_curve_menu_entryClick(Sender: TObject);
    procedure peg_on_TVJP_menu_entryClick(Sender: TObject);
    procedure make_mirror_menu_entryClick(Sender: TObject);
    procedure mirror_keeps_Y_menu_entryClick(Sender: TObject);
    procedure mirror_keeps_X_menu_entryClick(Sender: TObject);
    procedure cross_hairs_pointer_menu_entryClick(Sender: TObject);
    procedure clear_all_selections_menu_entryClick(Sender: TObject);
    procedure invert_handing_menu_entryClick(Sender: TObject);
    procedure invert_curving_rads_menu_entryClick(Sender: TObject);
    procedure repeat_last_action_menu_entryClick(Sender: TObject);
    procedure adjust_roam_menu_entryClick(Sender: TObject);
    procedure insert_turnout_menu_entryClick(Sender: TObject);
    procedure convert_to_plain_track_menu_entryClick(Sender: TObject);
    procedure swap_current_ends_menu_entryClick(Sender: TObject);
    procedure mirror_current_menu_entryClick(Sender: TObject);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure examine_peg_menu_entryClick(Sender: TObject);
    procedure explode_slow_menu_entryClick(Sender: TObject);
    procedure shrink_slow_menu_entryClick(Sender: TObject);
    procedure selection_colour_menu_entryClick(Sender: TObject);
    procedure hover_colour_menu_entryClick(Sender: TObject);
    procedure crop_approach_menu_entryClick(Sender: TObject);
    procedure snap_exit_back_menu_entryClick(Sender: TObject);
    procedure slew_mode1_menu_entryClick(Sender: TObject);
    procedure slew_mode2_menu_entryClick(Sender: TObject);
    procedure snap_to_peg_menu_entryClick(Sender: TObject);
    procedure explode_step_size_menu_entryClick(Sender: TObject);
    procedure blank_to_peg_menu_entryClick(Sender: TObject);
    procedure adjust_slew2_factor_menu_entryClick(Sender: TObject);
    //procedure peg_indicator_panelClick(Sender: TObject);
    procedure cancel_blanking_menu_entryClick(Sender: TObject);
    //procedure include_current_template_menu_entryClick(Sender: TObject);
    //procedure omit_current_template_menu_entryClick(Sender: TObject);
    procedure select_all_keeps_menu_entryClick(Sender: TObject);
    procedure copy_bg_to_current_popup_entryClick(Sender: TObject);
    procedure select_bg_popup_entryClick(Sender: TObject);
    procedure move_label_popup_entryClick(Sender: TObject);
    procedure swap_transition_rads_menu_entryClick(Sender: TObject);
    procedure FormDblClick(Sender: TObject);
    procedure edge_panning_on_menu_entryClick(Sender: TObject);
    procedure edge_panning_off_menu_entryClick(Sender: TObject);
    procedure double_grid_menu_entryClick(Sender: TObject);
    procedure double_CTRLF1_menu_entryClick(Sender: TObject);
    procedure double_ring_menu_entryClick(Sender: TObject);
    procedure double_F4_menu_entryClick(Sender: TObject);
    procedure double_F7_menu_entryClick(Sender: TObject);
    procedure double_none_menu_entryClick(Sender: TObject);
    procedure paper_bunching_on_menu_entryClick(Sender: TObject);
    procedure paper_bunching_off_menu_entryClick(Sender: TObject);
    procedure adjust_paper_bunching_menu_entryClick(Sender: TObject);
    procedure double_bunching_menu_entryClick(Sender: TObject);
    procedure restore_label_popup_entryClick(Sender: TObject);
    procedure make_label_shape_popup_entryClick(Sender: TObject);
    procedure rename_popup_entryClick(Sender: TObject);
    procedure wipe_bg_popup_entryClick(Sender: TObject);
    procedure delete_keep_popup_entryClick(Sender: TObject);
    procedure double_CTRLF9_menu_entryClick(Sender: TObject);
    procedure fit_current_only_menu_entryClick(Sender: TObject);
    procedure set_print_origin_menu_entryClick(Sender: TObject);
    procedure reset_page_origin_menu_entryClick(Sender: TObject);
    procedure move_page_origin_menu_entryClick(Sender: TObject);
    procedure next_run_width_menu_entryClick(Sender: TObject);
    procedure notch_on_ring_menu_entryClick(Sender: TObject);
    procedure enter_shift_keeps_menu_entryClick(Sender: TObject);
    procedure enter_rotation_keeps_menu_entryClick(Sender: TObject);
    procedure shift_current_by_menu_entryClick(Sender: TObject);
    procedure rotate_current_by_menu_entryClick(Sender: TObject);
    procedure previous_run_width_menu_entryClick(Sender: TObject);
    procedure next_run_length_menu_entryClick(Sender: TObject);
    procedure previous_run_length_menu_entryClick(Sender: TObject);
    procedure bright_night_scheme_menu_entryClick(Sender: TObject);
    procedure double_SHIFTCTRLF10_menu_entryClick(Sender: TObject);
    procedure sb_white_black_menu_entryClick(Sender: TObject);
    procedure sb_yellow_blue_menu_entryClick(Sender: TObject);
    procedure sb_silver_grey_menu_entryClick(Sender: TObject);
    procedure sb_teal_aqua_menu_entryClick(Sender: TObject);
    procedure dummy_label_panelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure dummy_label_panelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure dummy_label_panelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure cancel_popup_entryClick(Sender: TObject);
    procedure shift_all_shapes_menu_entryClick(Sender: TObject);
    procedure shift_corner1_menu_entryClick(Sender: TObject);
    procedure shift_corner2_menu_entryClick(Sender: TObject);
    procedure shift_shape_menu_entryClick(Sender: TObject);
    procedure double_shift_shapes_menu_entryClick(Sender: TObject);
    procedure quick_set_menu_entryClick(Sender: TObject);
    procedure mint_menu_entryClick(Sender: TObject);
    procedure pad_save_all_menu_entryClick(Sender: TObject);
    procedure pad_clear_all_menu_entryClick(Sender: TObject);
    procedure timber_numbering_font_menu_entryClick(Sender: TObject);
    procedure mint_popup_entryClick(Sender: TObject);
    procedure rebuild_popup_entryClick(Sender: TObject);
    procedure no_timbering_infill_menu_entryClick(Sender: TObject);
    procedure hatched_timbering_infill_menu_entryClick(Sender: TObject);
    procedure crosshatched_timbering_infill_menu_entryClick(Sender: TObject);
    procedure solid_timbering_infill_menu_entryClick(Sender: TObject);
    procedure print_timber_infill_colour_menu_entryClick(Sender: TObject);
    procedure generator_rebuild_bgnd_menu_entryClick(Sender: TObject);
    procedure scale_timber_numbering_menu_entryClick(Sender: TObject);
    procedure print_timber_numbering_menu_entryClick(Sender: TObject);
    procedure omit_timber_numbering_menu_entryClick(Sender: TObject);
    procedure equalized_constant_menu_entryClick(Sender: TObject);
    procedure click_zoom_rectangle_menu_entryClick(Sender: TObject);
    procedure zoom_to_fit_template_popup_entryClick(Sender: TObject);
    procedure wipe_to_current_popup_entryClick(Sender: TObject);
    procedure generator_normal_menu_entryClick(Sender: TObject);
    procedure generator_skeleton_menu_entryClick(Sender: TObject);
    procedure delete_to_current_popup_entryClick(Sender: TObject);
    procedure notch_under_bgnd_peg_popup_entryClick(Sender: TObject);
    procedure snake_menu_entryClick(Sender: TObject);
    procedure hide_group_menu_entryClick(Sender: TObject);
    procedure sleepers_9ft_menu_entryClick(Sender: TObject);
    procedure sleepers_8ft6in_menu_entryClick(Sender: TObject);
    procedure sleepers_otherlength_menu_entryClick(Sender: TObject);
    procedure bgtimber_infill_colour_menu_entryClick(Sender: TObject);
    procedure info_popup_entryClick(Sender: TObject);
    procedure cancel_mouse_action_popup_entryClick(Sender: TObject);
    procedure peg_facing_facing_popup_entryClick(Sender: TObject);
    procedure peg_facing_trailing_popup_entryClick(Sender: TObject);
    procedure over_facing_facing_popup_entryClick(Sender: TObject);
    procedure over_facing_trailing_popup_entryClick(Sender: TObject);
    procedure numbering_fullsize_only_menu_entryClick(Sender: TObject);
    procedure unpark_1_menu_entryClick(Sender: TObject);
    procedure park_1_menu_entryClick(Sender: TObject);
    procedure park_2_menu_entryClick(Sender: TObject);
    procedure unpark_2_menu_entryClick(Sender: TObject);
    procedure park_3_menu_entryClick(Sender: TObject);
    procedure unpark_3_menu_entryClick(Sender: TObject);
    procedure transition_from_straight_menu_entryClick(Sender: TObject);
    procedure transition_to_straight_menu_entryClick(Sender: TObject);
    procedure transition_previous_menu_entryClick(Sender: TObject);
    procedure transition_help_menu_entryClick(Sender: TObject);
    procedure transition_template_menu_entryClick(Sender: TObject);
    procedure shift_radial_centre_menu_entryClick(Sender: TObject);
    procedure shift_rotate_current_menu_entryClick(Sender: TObject);
    procedure grid_options_menu_entryClick(Sender: TObject);
    procedure show_rings_menu_entryClick(Sender: TObject);
    procedure hide_rings_menu_entryClick(Sender: TObject);
    procedure fit_shapes_menu_entryClick(Sender: TObject);
    procedure toggle_bgnd_menu_entryClick(Sender: TObject);
    procedure toggle_group_menu_entryClick(Sender: TObject);
    procedure pad_reload_menu_entryClick(Sender: TObject);
    procedure trans_calc_timerTimer(Sender: TObject);
    procedure zone_normal_menu_entryClick(Sender: TObject);
    procedure zone_rollout_menu_entryClick(Sender: TObject);
// OT2024     procedure grey_shade_printing_menu_entryClick(Sender: TObject);
    procedure OOBF_menu_entryClick(Sender: TObject);
    procedure EM_menu_entryClick(Sender: TObject);
    procedure S4P4_menu_entryClick(Sender: TObject);
    procedure GOGF_menu_entryClick(Sender: TObject);
    procedure S7_menu_entryClick(Sender: TObject);
    procedure other_gauges_menu_entryClick(Sender: TObject);
    procedure gauge_details_menu_entryClick(Sender: TObject);
    procedure gauge_mint_new_menu_entryClick(Sender: TObject);
    procedure gauge_match_original_menu_entryClick(Sender: TObject);
    procedure no_infill_menu_entryClick(Sender: TObject);
    procedure blank_infill_menu_entryClick(Sender: TObject);
    procedure timbering_infill_menu_entryClick(Sender: TObject);
    procedure blank_timbering_infill_menu_entryClick(Sender: TObject);
    procedure bg_solid_timber_infill_menu_entryClick(Sender: TObject);
    procedure bg_crosshatched_timber_infill_menu_entryClick(Sender: TObject);
    procedure bg_hatched_timber_infill_menu_entryClick(Sender: TObject);
    procedure bg_blank_timber_infill_menu_entryClick(Sender: TObject);
    procedure bg_no_timber_infill_menu_entryClick(Sender: TObject);
    procedure current_timber_numbers_menu_entryClick(Sender: TObject);
    procedure print_solid_timber_infill_menu_entryClick(Sender: TObject);
    procedure print_crosshatched_timber_infill_menu_entryClick(Sender: TObject);
    procedure print_hatched_timber_infill_menu_entryClick(Sender: TObject);
    procedure print_blank_timber_infill_menu_entryClick(Sender: TObject);
    procedure print_no_timber_infill_menu_entryClick(Sender: TObject);
    procedure bgnd_rail_infill_colour_menu_entryClick(Sender: TObject);
    procedure no_timbering_menu_entryClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure peg_on_planing_menu_entryClick(Sender: TObject);
    procedure peg_on_heel_menu_entryClick(Sender: TObject);
    procedure peg_on_CESP_menu_entryClick(Sender: TObject);
    procedure new_transition_settings_menu_entryClick(Sender: TObject);
    procedure make_separate_approach_menu_entryClick(Sender: TObject);
    procedure make_separate_exit_menu_entryClick(Sender: TObject);
    procedure make_split_at_peg_menu_entryClick(Sender: TObject);
    procedure scale_all_shapes_menu_entryClick(Sender: TObject);
    procedure rotate_all_shapes_menu_entryClick(Sender: TObject);
    procedure invert_colours_menu_entryClick(Sender: TObject);
    procedure make_tools_cancel_blanking_menu_entryClick(Sender: TObject);
    procedure make_tools_retain_blanking_menu_entryClick(Sender: TObject);
    procedure make_tools_restore_shoved_menu_entryClick(Sender: TObject);
    procedure make_tools_retain_shoved_menu_entryClick(Sender: TObject);
    procedure swings_in_degs_menu_entryClick(Sender: TObject);
    procedure rotate_colours_menu_entryClick(Sender: TObject);
    procedure swap_red_blue_menu_entryClick(Sender: TObject);
    procedure unlink_group_from_notch_menu_entryClick(Sender: TObject);
    procedure group_linked_warning_panelClick(Sender: TObject);
    procedure scale_shape_menu_entryClick(Sender: TObject);
    procedure group_selection_fence_menu_entryClick(Sender: TObject);
    procedure group_fence_partial_menu_entryClick(Sender: TObject);
    procedure group_fence_whole_menu_entryClick(Sender: TObject);
    procedure peg_on_midlength_menu_entryClick(Sender: TObject);
    procedure shift_radial_centre_to_notch_menu_entryClick(Sender: TObject);
    procedure notch_linked_to_current_menu_entryClick(Sender: TObject);
    procedure notch_unlinked_from_current_menu_entryClick(Sender: TObject);
    procedure set_user_defined_position_menu_entryClick(Sender: TObject);
    procedure peg_on_user_defined_menu_entryClick(Sender: TObject);
    procedure notch_link_help_menu_entryClick(Sender: TObject);
    procedure overscale_joggles_menu_entryClick(Sender: TObject);
    procedure jotter_menu_entryClick(Sender: TObject);
    procedure c_curve_shrinking_transition_menu_entryClick(Sender: TObject);
    procedure c_curve_expanding_transition_menu_entryClick(Sender: TObject);
    procedure s_curve_transition_menu_entryClick(Sender: TObject);
    procedure peg_on_EGTP_menu_entryClick(Sender: TObject);
    procedure peg_on_EGORG_menu_entryClick(Sender: TObject);
    procedure peg_on_IGTP_menu_entryClick(Sender: TObject);
    procedure peg_on_IGORG_menu_entryClick(Sender: TObject);
    procedure peg_on_slew_start_menu_entryClick(Sender: TObject);
    procedure peg_on_slew_length_menu_entryClick(Sender: TObject);
    procedure make_turnout_road_menu_entryClick(Sender: TObject);
    procedure snap_to_EGTP_menu_entryClick(Sender: TObject);
    procedure snap_to_IGTP_menu_entryClick(Sender: TObject);
    procedure make_external_road_menu_entryClick(Sender: TObject);
    procedure make_internal_road_menu_entryClick(Sender: TObject);
    procedure timbering_menu_entryClick(Sender: TObject);
    procedure wing_check_rails_menu_entryClick(Sender: TObject);
    procedure bullhead_rails_menu_entryClick(Sender: TObject);
    procedure no_rails_menu_entryClick(Sender: TObject);
    procedure rails_menu_entryClick(Sender: TObject);
    procedure flatbottom_rails_menu_entryClick(Sender: TObject);
    procedure snap_approach_to_railjoint_menu_entryClick(Sender: TObject);
    procedure snap_exit_to_railjoint_menu_entryClick(Sender: TObject);
    procedure make_link_help_popup_entryClick(Sender: TObject);
    procedure normal_track_centre_lines_menu_radioClick(Sender: TObject);
    procedure bent_flares_menu_entryClick(Sender: TObject);
    procedure machined_flares_menu_entryClick(Sender: TObject);
    procedure notch_on_radial_centre_menu_entryClick(Sender: TObject);
    procedure slew_nudge_menu_entryClick(Sender: TObject);
    procedure move_trans_start_to_peg_menu_entryClick(Sender: TObject);
    procedure move_trans_end_to_peg_menu_entryClick(Sender: TObject);
    procedure move_slew_start_to_peg_menu_entryClick(Sender: TObject);
    procedure move_slew_end_to_peg_menu_entryClick(Sender: TObject);
    procedure notch_on_2nd_radial_centre_menu_entryClick(Sender: TObject);
    procedure angled_on_menu_entryClick(Sender: TObject);
    procedure edit_memo_popup_entryClick(Sender: TObject);
    procedure jotter_to_memo_popup_entryClick(Sender: TObject);
    //procedure chair_baseplate_data_menu_entryClick(Sender: TObject);
    procedure set_line_thicknesses_menu_entryClick(Sender: TObject);
    procedure thin_printed_lines_menu_entryClick(Sender: TObject);
    procedure normal_printed_lines_menu_entryClick(Sender: TObject);
    procedure thick_printed_lines_menu_entryClick(Sender: TObject);
    procedure adjust_line_thickness_menu_entryClick(Sender: TObject);
    procedure line_thickness_help_menu_entryClick(Sender: TObject);
    procedure switch_drive_markx_menu_entryClick(Sender: TObject);
    procedure end_trans_at_peg_menu_entryClick(Sender: TObject);
    procedure duplicate_group_menu_entryClick(Sender: TObject);
    procedure gen_rebuild_group_menu_entryClick(Sender: TObject);
    procedure group_fence_new_menu_entryClick(Sender: TObject);
    procedure group_fence_add_menu_entryClick(Sender: TObject);
    procedure group_fence_toggle_menu_entryClick(Sender: TObject);
    procedure group_fence_remove_menu_entryClick(Sender: TObject);
    procedure printed_grid_solid_menu_entryClick(Sender: TObject);
    procedure printed_grid_dotted_menu_entryClick(Sender: TObject);
    procedure fit_selected_group_only_menu_entryClick(Sender: TObject);
    procedure blunt_nose_menu_entryClick(Sender: TObject);
    procedure wing_front_menu_entryClick(Sender: TObject);
    procedure vee_rail_menu_entryClick(Sender: TObject);
    procedure bonus_timbers_menu_entryClick(Sender: TObject);
    procedure add_bonus_timber_menu_entryClick(Sender: TObject);
    procedure remove_bonus_timber_menu_entryClick(Sender: TObject);
    procedure remove_all_bonus_timbers_menu_entryClick(Sender: TObject);
    procedure normal_joints_menu_entryClick(Sender: TObject);
    procedure staggered_joints_menu_entryClick(Sender: TObject);
    procedure no_joints_menu_entryClick(Sender: TObject);
    procedure plain_track_joints_menu_entryClick(Sender: TObject);
    procedure rail_joints_help_menu_entryClick(Sender: TObject);
    procedure use_marker_colours_all_menu_entryClick(Sender: TObject);
    procedure use_normal_colours_menu_entryClick(Sender: TObject);
    procedure background_templates_colours_menu_entryClick(Sender: TObject);
    procedure use_marker_colours_rails_only_menu_entryClick(Sender: TObject);
    procedure normal_colours_popup_entryClick(Sender: TObject);
    procedure marker_colour_popup_entryClick(Sender: TObject);
    procedure set_marker_colour_popup_entryClick(Sender: TObject);
    procedure normal_print_colours_popup_entryClick(Sender: TObject);
    procedure print_mapping_colour_popup_entryClick(Sender: TObject);
    procedure set_print_marker_colour_popup_entryClick(Sender: TObject);
    procedure template_colours_popup_entryClick(Sender: TObject);
    procedure show_group_normal_colours_menu_entryClick(Sender: TObject);
    procedure show_group_marker_colours_menu_entryClick(Sender: TObject);
    procedure group_marker_colour_menu_entryClick(Sender: TObject);
    procedure print_group_normal_colours_menu_entryClick(Sender: TObject);
    procedure print_group_mapping_colours_menu_entryClick(Sender: TObject);
    procedure group_mapping_colour_menu_entryClick(Sender: TObject);
    procedure print_all_in_mapping_colours_menu_entryClick(Sender: TObject);
    procedure print_rails_only_in_mapping_colours_menu_entryClick(Sender: TObject);
    procedure print_colour_options_menu_entryClick(Sender: TObject);
    procedure print_timbers_only_in_mapping_colours_menu_entryClick(Sender: TObject);
    procedure print_using_pad_marker_colours_menu_entryClick(Sender: TObject);
    procedure use_marker_colours_timbers_only_menu_entryClick(Sender: TObject);
    procedure select_group_by_marker_colour_menu_entryClick(Sender: TObject);
    procedure use_print_mapping_colours_menu_entryClick(Sender: TObject);
    procedure marker_and_mapping_colours_help_menu_entryClick(Sender: TObject);
    procedure marker_and_mapping_colours_help_popup_entryClick(Sender: TObject);
    procedure set_trim_margins_menu_entryClick(Sender: TObject);
    procedure trim_per_printer_menu_entryClick(Sender: TObject);
    procedure show_printable_area_menu_entryClick(Sender: TObject);
    procedure trim_margins_help_menu_entryClick(Sender: TObject);
    procedure pages_staggered_menu_entryClick(Sender: TObject);
    procedure pages_inline_menu_entryClick(Sender: TObject);
    procedure rails_help_menu_entryClick(Sender: TObject);
    procedure vertical_rails_menu_entryClick(Sender: TObject);
    procedure inclined_rails_menu_entryClick(Sender: TObject);
    procedure adjust_blanking_length_menu_entryClick(Sender: TObject);
    procedure warn_if_rails_infringe_menu_entryClick(Sender: TObject);
    procedure warn_if_centrelines_infringe_menu_entryClick(Sender: TObject);
    procedure ring_infringements_menu_entryClick(Sender: TObject);
    procedure roll_rails_by_menu_entryClick(Sender: TObject);
    procedure H0_EU_menu_entryClick(Sender: TObject);
    procedure adjust_roll_sleepers_menu_entryClick(Sender: TObject);
    procedure H0_US_menu_entryClick(Sender: TObject);
    procedure read_first_menu_entryClick(Sender: TObject);
    procedure lengths_rails_menu_entryClick(Sender: TObject);
    procedure peg_on_joints_menu_entryClick(Sender: TObject);
    procedure undo_clear_or_reload_menu_entryClick(Sender: TObject);
    procedure adjust_spacing_ring_size_menu_entryClick(Sender: TObject);
    procedure notch_on_shape_menu_entryClick(Sender: TObject);
    procedure peg_on_trans_org_menu_entryClick(Sender: TObject);
    procedure move_trans_start_to_template_menu_entryClick(Sender: TObject);
    procedure move_trans_end_to_template_menu_entryClick(Sender: TObject);
    procedure start_trans_from_peg_menu_entryClick(Sender: TObject);
    procedure match_trans_start_to_template_menu_entryClick(Sender: TObject);
    procedure match_trans_end_to_template_menu_entryClick(Sender: TObject);
    procedure match_trans_zone_to_template_menu_entryClick(Sender: TObject);
    procedure match_trans_zone_to_slew_menu_entryClick(Sender: TObject);
    procedure normalize_transition_menu_entryClick(Sender: TObject);
    procedure rotate_to_datum_menu_entryClick(Sender: TObject);
    procedure change_transition_zone_menu_entryClick(Sender: TObject);
    procedure slew_help_menu_entryClick(Sender: TObject);
    procedure move_slew_start_to_template_menu_entryClick(Sender: TObject);
    procedure move_slew_end_to_template_menu_entryClick(Sender: TObject);
    procedure move_slew_centre_to_template_menu_entryClick(Sender: TObject);
    procedure match_slew_start_to_template_menu_entryClick(Sender: TObject);
    procedure match_slew_end_to_template_menu_entryClick(Sender: TObject);
    procedure match_slew_zone_to_template_menu_entryClick(Sender: TObject);
    procedure start_slew_from_peg_menu_entryClick(Sender: TObject);
    procedure end_slew_at_peg_menu_entryClick(Sender: TObject);
    procedure match_slew_zone_to_trans_menu_entryClick(Sender: TObject);
    procedure change_slewing_zone_menu_entryClick(Sender: TObject);
    procedure zero_trans_zone_menu_entryClick(Sender: TObject);
    procedure make_tools_normalize_transitions_menu_entryClick(Sender: TObject);
    procedure make_tools_no_normalizing_menu_entryClick(Sender: TObject);
    procedure make_tools_cancel_rolled_menu_entryClick(Sender: TObject);
    procedure make_tools_retain_rolled_menu_entryClick(Sender: TObject);
    procedure background_template_detail_menu_entryClick(Sender: TObject);
    procedure convert_turnout_to_half_diamond_menu_entryClick(Sender: TObject);
    procedure fixed_diamond_menu_entryClick(Sender: TObject);
    procedure movable_diamond_menu_entryClick(Sender: TObject);
    procedure customize_k_crossing_menu_entryClick(Sender: TObject);
    procedure insert_half_diamond_menu_entryClick(Sender: TObject);
    procedure convert_half_diamond_to_turnout_menu_entryClick(Sender: TObject);
    procedure k_crossing_check_rails_menu_entryClick(Sender: TObject);
    procedure auto_diamond_menu_entryClick(Sender: TObject);
    procedure k_crossings_help_menu_entryClick(Sender: TObject);
    procedure head_rail_centreline_only_menu_entryClick(Sender: TObject);
    procedure hd_timbering_as_prototype_menu_entryClick(Sender: TObject);
    procedure hd_timbering_as_model_menu_entryClick(Sender: TObject);
    procedure make_diamond_crossing_menu_entryClick(Sender: TObject);
    procedure store_as_library_menu_entryClick(Sender: TObject);
    procedure turnout_road_options_menu_entryClick(Sender: TObject);
    procedure pad_popup_menuPopup(Sender: TObject);
    procedure f5_sizing_options_menu_entryClick(Sender: TObject);
    procedure undo_toolbuttonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
    procedure undo_toolbuttonMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
    procedure redo_toolbuttonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
    procedure redo_toolbuttonMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
    procedure half_diamond_checkrail_options_menu_entryClick(Sender: TObject);
    procedure normal_hd_checkrails_menu_entryClick(Sender: TObject);
    procedure short_hd_checkrail_ts_menu_entryClick(Sender: TObject);
    procedure short_hd_checkrail_ms_menu_entryClick(Sender: TObject);
    procedure short_hd_checkrails_both_menu_entryClick(Sender: TObject);
    procedure snap_to_heel_menu_entryClick(Sender: TObject);
    procedure blank_to_toe_menu_entryClick(Sender: TObject);
    procedure normal_hd_timbers_menu_entryClick(Sender: TObject);
    procedure extended_hd_timbers_ts_menu_entryClick(Sender: TObject);
    procedure extended_hd_timbers_ms_menu_entryClick(Sender: TObject);
    procedure extended_hd_timbers_both_menu_entryClick(Sender: TObject);
    procedure half_diamond_timbering_menu_entryClick(Sender: TObject);
    procedure hd_timbering_help_menu_entryClick(Sender: TObject);
    procedure six_inch_steps_menu_entryClick(Sender: TObject);
    procedure gradual_steps_menu_entryClick(Sender: TObject);
    procedure other_size_steps_menu_entryClick(Sender: TObject);
    procedure timber_length_increments_menu_entryClick(Sender: TObject);
    procedure move_ruler_1st_end_menu_entryClick(Sender: TObject);
    procedure move_ruler_2nd_end_menu_entryClick(Sender: TObject);
    procedure hide_ruler_menu_entryClick(Sender: TObject);
    procedure ruler_tool_menu_entryClick(Sender: TObject);
    procedure show_ruler_menu_entryClick(Sender: TObject);
    procedure set_ruler_ends_menu_entryClick(Sender: TObject);
    //procedure modify_and_rebuild_popup_entryClick(Sender: TObject);
    procedure create_unused_copy_popup_entryClick(Sender: TObject);
    procedure ruler_as_grid_menu_entryClick(Sender: TObject);
    procedure ruler_mm_menu_entryClick(Sender: TObject);
    procedure ruler_inch_menu_entryClick(Sender: TObject);
    procedure zoom_fit_ruler_menu_entryClick(Sender: TObject);
    procedure ruler_spacing_menu_entryClick(Sender: TObject);
    procedure obtain_switch_popup_entryClick(Sender: TObject);
    procedure obtain_plain_track_popup_entryClick(Sender: TObject);
    procedure ruler_on_ring_menu_entryClick(Sender: TObject);
    procedure ruler_on_notch_menu_entryClick(Sender: TObject);
    procedure swap_ruler_ends_menu_entryClick(Sender: TObject);
    procedure print_group_only_menu_entryClick(Sender: TObject);
    procedure f5_crossing_angles_menu_entryClick(Sender: TObject);
    procedure mouse_options_menu_entryClick(Sender: TObject);
    procedure swell_menu_entryClick(Sender: TObject);
    procedure snap_to_MXP_menu_entryClick(Sender: TObject);
    procedure blank_to_v_crossing_menu_entryClick(Sender: TObject);
    procedure omit_rails_joints_menu_entryClick(Sender: TObject);
    procedure grid_50mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_250mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_300mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_500mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_1000mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_3in_spacing_menu_entryClick(Sender: TObject);
    procedure grid_6in_spacing_menu_entryClick(Sender: TObject);
    procedure grid_1ft_spacing_menu_entryClick(Sender: TObject);
    procedure grid_3ft_spacing_menu_entryClick(Sender: TObject);
    procedure grid_4ft_spacing_menu_entryClick(Sender: TObject);
    procedure grid_12proto_ft_spacing_menu_entryClick(Sender: TObject);
    procedure grid_100proto_ft_spacing_menu_entryClick(Sender: TObject);
    procedure pad_background_options_menu_entryClick(Sender: TObject);
    procedure snap_to_ctrl0_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl1_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl6_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl9_popup_entryClick(Sender: TObject);
    procedure peg_on_tolp_menu_entryClick(Sender: TObject);
    procedure snap_to_tolp_popup_entryClick(Sender: TObject);
    procedure snap_on_background_templates_menu_entryClick(Sender: TObject);
    procedure set_snap_proximity_menu_entryClick(Sender: TObject);
    procedure snap_to_ctrl3_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl4_popup_entryClick(Sender: TObject);
    procedure snap_to_tcp_popup_entryClick(Sender: TObject);
    procedure snap_to_mcp_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl5_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl7_popup_entryClick(Sender: TObject);
    procedure snap_to_ctrl8_popup_entryClick(Sender: TObject);
    procedure snap_to_bgnd_peg_popup_entryClick(Sender: TObject);
    procedure OSF_menu_entryClick(Sender: TObject);
    procedure make_branch_track_menu_itemClick(Sender: TObject);
    procedure snap_to_background_popup_entryClick(Sender: TObject);
    procedure templot_group_menu_entryClick(Sender: TObject);
    procedure www_templot_com_menu_entryClick(Sender: TObject);
    procedure pad_reload_recent_file_menu_entryClick(Sender: TObject);
    procedure pad_add_recent_file_menu_entryClick(Sender: TObject);
    procedure switch_drive_menu_entryClick(Sender: TObject);
    procedure mouse_actions_help_menu_entryClick(Sender: TObject);
    procedure peg_on_blanked_length_menu_entryClick(Sender: TObject);
    procedure f7_snap_popup_entryClick(Sender: TObject);
    procedure enable_f7_snap_popup_entryClick(Sender: TObject);
    procedure disable_f7_snap_popup_entryClick(Sender: TObject);
    procedure make_slip_road_menu_itemClick(Sender: TObject);
    procedure bat_name_label_popup_entryClick(Sender: TObject);
    procedure hide_name_labels_menu_entryClick(Sender: TObject);
    procedure printed_element_options_menu_entryClick(Sender: TObject);
    procedure roll_match_ctrl0_menu_entryClick(Sender: TObject);
    procedure roll_match_ctrl1_menu_entryClick(Sender: TObject);
    procedure arrange_labels_popup_entryClick(Sender: TObject);
    procedure move_name_labels_menu_entryClick(Sender: TObject);
    procedure gen_platforms_trackbed_edges_menu_entryClick(Sender: TObject);
    procedure group_select_all_plain_track_menu_entryClick(Sender: TObject);
    procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
    procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
    procedure orientation_help_menu_entryClick(Sender: TObject);
    procedure align_maintain_length_menu_entryClick(Sender: TObject);
    procedure align_match_length_menu_entryClick(Sender: TObject);
    procedure f6_length_fixed_menu_entryClick(Sender: TObject);
    procedure f6_swing_fixed_menu_entryClick(Sender: TObject);
    procedure F6_curving_options_menu_entryClick(Sender: TObject);
    procedure f6_options_help_menu_entryClick(Sender: TObject);
    procedure adjust_entry_straight_menu_entryClick(Sender: TObject);
    procedure allow_left_drag_panning_menu_entryClick(Sender: TObject);
    procedure delete_group_menu_entryClick(Sender: TObject);
    procedure save_group_menu_entryClick(Sender: TObject);
    procedure restore_group_labels_menu_entryClick(Sender: TObject);
    procedure grid_in_front_of_shapes_menu_entryClick(Sender: TObject);
    procedure output_detail_mode_menu_entryClick(Sender: TObject);
    procedure output_diagram_mode_menu_entryClick(Sender: TObject);
    procedure omit_output_boundaries_menu_entryClick(Sender: TObject);
    procedure include_output_boundaries_menu_entryClick(Sender: TObject);
    procedure output_show_points_menu_entryClick(Sender: TObject);
    procedure write_reminder_menu_entryClick(Sender: TObject);
    procedure print_control_now_menu_entryClick(Sender: TObject);
    procedure print_entire_pad_now_menu_entryClick(Sender: TObject);
    procedure print_group_now_menu_entryClick(Sender: TObject);
    procedure print_help_menu_entryClick(Sender: TObject);
(* OT2024
    procedure sb_auto_add_menu_entryClick(Sender: TObject);
    procedure sb_manual_add_menu_entryClick(Sender: TObject);
    procedure sb_include_grid_menu_entryClick(Sender: TObject);
    procedure sb_include_grid_labels_menu_entryClick(Sender: TObject);
    procedure sb_lock_menu_entryClick(Sender: TObject);
    procedure sb_include_picture_shapes_menu_entryClick(Sender: TObject);
    procedure auto_update_diagram_menu_entryClick(Sender: TObject);
    procedure manual_add_update_menu_entryClick(Sender: TObject);
*)
    procedure export_file_menu_entryClick(Sender: TObject);
    procedure output_mode_help_menu_entryClick(Sender: TObject);
    procedure snap_to_zero_menu_entryClick(Sender: TObject);
    procedure store_bgnd_insert_toolbuttonClick(Sender: TObject);
    procedure make_control_popup_entryClick(Sender: TObject);
    procedure N_NMRA_menu_entryClick(Sender: TObject);
    procedure N_UK_menu_entryClick(Sender: TObject);
    procedure S2_menu_entryClick(Sender: TObject);
    procedure S_3p5_menu_entryClick(Sender: TObject);
    procedure OOSF_menu_entryClick(Sender: TObject);
    procedure S_gauge_menu_entryClick(Sender: TObject);
    procedure OMF_menu_entryClick(Sender: TObject);
    procedure gauge1F_menu_entryClick(Sender: TObject);
    procedure platform_edges_menu_entryClick(Sender: TObject);
    procedure about_generator_menu_entryClick(Sender: TObject);
    procedure show_notch_menu_entryClick(Sender: TObject);
    procedure hide_notch_menu_entryClick(Sender: TObject);
    procedure adjacent_trackbed_platforms_menu_entryClick(Sender: TObject);
    procedure adjacent_rails_menu_entryClick(Sender: TObject);
    procedure print_platform_edge_colour_menu_entryClick(Sender: TObject);
    procedure print_platform_infill_colour_menu_entryClick(Sender: TObject);
    procedure no_track_centre_lines_menu_radioClick(Sender: TObject);
    procedure adjacent_options_menu_entryClick(Sender: TObject);
    procedure bgplatforms_colour_menu_entryClick(Sender: TObject);
    procedure normal_non_gaunt_turnout_menu_entryClick(Sender: TObject);
    procedure gaunt_turnout_menu_entryClick(Sender: TObject);
    procedure gaunt_sleeper_length_menu_entryClick(Sender: TObject);
    procedure adjust_gaunt_offset_menu_entryClick(Sender: TObject);
    procedure gaunt_help_menu_entryClick(Sender: TObject);
    procedure peg_indicator_panelClick(Sender: TObject);
    procedure adjust_k_crossing_angle_menu_entryClick(Sender: TObject);
    procedure adjust_v_crossing_angle_menu_entryClick(Sender: TObject);
    procedure swap_red_green_menu_entryClick(Sender: TObject);
    procedure swap_green_blue_menu_entryClick(Sender: TObject);
    procedure half_diamond_timbering_style_menu_entryClick(Sender: TObject);
    procedure make_regular_ladder_menu_entryClick(Sender: TObject);
    procedure k_crossing_angle_menu_entryClick(Sender: TObject);
    procedure gaunt_offset_menu_entryClick(Sender: TObject);
    procedure intersection_centre_lines_popup_entryClick(Sender: TObject);
    procedure intersection_outer_outer_popup_entryClick(Sender: TObject);
    procedure intersection_inner_inner_popup_entryClick(Sender: TObject);
    procedure intersection_outer_inner_popup_entryClick(Sender: TObject);
    procedure intersection_inner_outer_popup_entryClick(Sender: TObject);
    procedure make_diamond_crossing_at_intersection_popup_entryClick(Sender: TObject);
    procedure f9_crossing_angles_menu_entryClick(Sender: TObject);
    procedure f10_crossing_angles_menu_entryClick(Sender: TObject);
    procedure f9_quarter_steps_menu_entryClick(Sender: TObject);
    procedure f9_any_angle_menu_entryClick(Sender: TObject);
    procedure f10_quarter_steps_menu_entryClick(Sender: TObject);
    procedure f10_any_angle_menu_entryClick(Sender: TObject);
    procedure regular_crossing_menu_entryClick(Sender: TObject);
    procedure curviform_crossing_menu_entryClick(Sender: TObject);
    procedure generic_crossing_menu_entryClick(Sender: TObject);
    procedure parallel_crossing_menu_entryClick(Sender: TObject);
    procedure v_crossing_angle_menu_entryClick(Sender: TObject);
    procedure v_crossing_options_menu_entryClick(Sender: TObject);
    procedure page_outlines_printer_menu_entryClick(Sender: TObject);
    procedure copy_and_make_popup_entryClick(Sender: TObject);
    procedure corner_page_numbers_font_menu_entryClick(Sender: TObject);
    procedure print_platform_solid_infill_menu_entryClick(Sender: TObject);
    procedure print_platform_crossed_infill_menu_entryClick(Sender: TObject);
    procedure print_platform_hatched_infill_menu_entryClick(Sender: TObject);
    procedure print_platform_blank_infill_menu_entryClick(Sender: TObject);
    procedure print_platform_no_infill_menu_entryClick(Sender: TObject);
    procedure rebuild_group_to_match_centre_lines_menu_entryClick(Sender: TObject);
    procedure adjust_rectangle_left_edge_menu_entryClick(Sender: TObject);
    procedure adjust_rectangle_right_edge_menu_entryClick(Sender: TObject);
    procedure adjust_rectangle_top_edge_menu_entryClick(Sender: TObject);
    procedure adjust_rectangle_bottom_edge_menu_entryClick(Sender: TObject);
    procedure draw_boundary_rectangle_menu_entryClick(Sender: TObject);
    procedure clear_boundary_rectangle_menu_entryClick(Sender: TObject);
    procedure move_rectangle_menu_entryClick(Sender: TObject);
    procedure set_boundary_rectangle_menu_entryClick(Sender: TObject);
// OT2024    procedure manual_add_diagram_menu_entryClick(Sender: TObject);
    procedure make_screenshot_menu_itemClick(Sender: TObject);
    procedure grid_150mm_spacing_menu_entryClick(Sender: TObject);
    procedure differ_check_rails_menu_entryClick(Sender: TObject);
    procedure make_tools_restore_check_rails_menu_entryClick(Sender: TObject);
    procedure make_tools_retain_check_rails_menu_entryClick(Sender: TObject);
    procedure gen_inner_foot_edges_menu_entryClick(Sender: TObject);
    procedure gen_outer_foot_edges_menu_entryClick(Sender: TObject);
    procedure rebuild_group_to_match_rail_section_menu_entryClick(Sender: TObject);
    procedure modify_rail_section_popup_entryClick(Sender: TObject);
    procedure modify_centre_lines_popup_entryClick(Sender: TObject);
    procedure modify_timbering_popup_entryClick(Sender: TObject);
    procedure modify_trackbed_edges_popup_entryClick(Sender: TObject);
    procedure reset_options_popup_entryClick(Sender: TObject);
    procedure peg_options_popup_entryClick(Sender: TObject);
    procedure keep_to_background_popup_entryClick(Sender: TObject);
    procedure show_info_popup_entryClick(Sender: TObject);
    procedure hide_info_popup_entryClick(Sender: TObject);
    procedure k_crossing_wing_rails_menu_entryClick(Sender: TObject);
    procedure peg_blank_menu_entryClick(Sender: TObject);
    procedure peg_hollow_menu_entryClick(Sender: TObject);
    procedure peg_solid_red_menu_entryClick(Sender: TObject);
    procedure make_a_donation_menu_entryClick(Sender: TObject);
    procedure mouse_wheel_zoom_centre_menu_entryClick(Sender: TObject);
    procedure mouse_wheel_zoom_at_mouse_menu_entryClick(Sender: TObject);
    procedure mouse_wheel_zoom_jump_menu_entryClick(Sender: TObject);
    procedure mouse_wheel_zoom_options_menu_entryClick(Sender: TObject);
    procedure mouse_wheel_help_menu_entryClick(Sender: TObject);
    procedure roll_dummy_vehicle_menu_entryClick(Sender: TObject);
    procedure adjust_dummy_vehicle_clearance_menu_entryClick(Sender: TObject);
    procedure snap_to_ctrl2_popup_entryClick(Sender: TObject);
    procedure snap_to_user_defined_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl3_popup_entryClick(Sender: TObject);
    procedure move_peg_on_background_template_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl0_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl1_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl2_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl4_popup_entryClick(Sender: TObject);
    procedure move_to_tcp_popup_entryClick(Sender: TObject);
    procedure move_to_mcp_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl5_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl6_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl7_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl8_popup_entryClick(Sender: TObject);
    procedure move_to_tolp_popup_entryClick(Sender: TObject);
    procedure move_to_ctrl9_popup_entryClick(Sender: TObject);
    procedure move_to_user_defined_popup_entryClick(Sender: TObject);
    procedure move_bgnd_peg_help_popup_entryClick(Sender: TObject);
    procedure align_over_help_popup_entryClick(Sender: TObject);
// OT2024    procedure sb_show_items_on_pad_menu_entryClick(Sender: TObject);
    procedure printer_only_margins_menu_entryClick(Sender: TObject);
    procedure obtain_to_control_popup_entryClick(Sender: TObject);
    procedure move_to_cesp_popup_entryClick(Sender: TObject);
    procedure move_to_heel_popup_entryClick(Sender: TObject);
    procedure move_to_planing_popup_entryClick(Sender: TObject);
    procedure snap_to_planing_popup_entryClick(Sender: TObject);
    procedure snap_to_heel_popup_entryClick(Sender: TObject);
    procedure snap_to_cesp_popup_entryClick(Sender: TObject);
    procedure convert_kcrossing_ram_to_clm_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ts_track_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ts_double_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ms_double_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ms_track_menu_entryClick(Sender: TObject);
    procedure centre_line_option_normal_menu_entryClick(Sender: TObject);
    procedure centre_line_offset_options_menu_entryClick(Sender: TObject);
    procedure track_background_width_menu_entryClick(Sender: TObject);
    procedure track_background_colour_menu_entryClick(Sender: TObject);
    procedure centre_line_option_custom_menu_entryClick(Sender: TObject);
    procedure centre_line_option_custom_offet_menu_entryClick(Sender: TObject);
    procedure add_group_tag_menu_entryClick(Sender: TObject);
    procedure group_all_with_same_marker_colour_popup_entryClick(Sender: TObject);
    procedure selection_popupPopup(Sender: TObject);
    procedure add_prefix_tag_popup_entryClick(Sender: TObject);
    procedure group_all_with_any_same_tags_popup_entryClick(Sender: TObject);
    procedure shift_group_onto_notch_menu_entryClick(Sender: TObject);
    procedure undo_shift_group_onto_notch_menu_entryClick(Sender: TObject);
    procedure add_background_images_menu_entryClick(Sender: TObject);
    procedure output_page_map_help_menu_entryClick(Sender: TObject);
    procedure page_map_background_shapes_menu_entryClick(Sender: TObject);
    procedure page_map_sketchboard_items_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ts_sleeper_ends_menu_entryClick(Sender: TObject);
    procedure centre_line_option_ms_sleeper_ends_menu_entryClick(Sender: TObject);
    procedure modify_group_to_match_min_rad_menu_entryClick(Sender: TObject);
    procedure radius_warning_help_menu_entryClick(Sender: TObject);
    procedure modify_radius_warning_popup_entryClick(Sender: TObject);
    procedure rail_infill_style_menu_entryClick(Sender: TObject);
    procedure print_timber_infill_menu_entryClick(Sender: TObject);
    procedure print_platform_infill_menu_entryClick(Sender: TObject);
    procedure old_pre_templot2_files_menu_entryClick(Sender: TObject);
    procedure do_nothing_menu_entryClick(Sender: TObject);
    procedure get_colour_at_mouse_menu_entryClick(Sender: TObject);
    procedure timber_numbering_on_plain_track_menu_entryClick(Sender: TObject);
    procedure peg_on_ip_menu_entryClick(Sender: TObject);
    procedure v_crossings_help_menu_entryClick(Sender: TObject);
    procedure undo_deleted_template_menu_entryClick(Sender: TObject);
    procedure retain_length_on_mint_menu_entryClick(Sender: TObject);
    procedure show_margin_coordinates_menu_entryClick(Sender: TObject);
    procedure adjustable_turnout_road_menu_entryClick(Sender: TObject);
    procedure adjust_turnout_road_exit_menu_entryClick(Sender: TObject);
    procedure pad_wipe_group_menu_entryClick(Sender: TObject);
    procedure show_selected_group_templates_menu_entryClick(Sender: TObject);
    procedure hide_selected_group_templates_menu_entryClick(Sender: TObject);
    procedure show_control_template_menu_entryClick(Sender: TObject);
    procedure show_name_labels_menu_entryClick(Sender: TObject);
    procedure make_branch_crossover_menu_entryClick(Sender: TObject);
    procedure diagram_mode_track_colour_menu_entryClick(Sender: TObject);
    procedure qb_600x300_menu_entryClick(Sender: TObject);
    procedure qb_900x500_menu_entryClick(Sender: TObject);
    procedure qb_1200x600_menu_entryClick(Sender: TObject);
    procedure qb_1600x750_menu_entryClick(Sender: TObject);
    procedure qb_2000x1000_menu_entryClick(Sender: TObject);
    procedure qb_2400x1200_menu_entryClick(Sender: TObject);
    procedure qb_3000x1800_menu_entryClick(Sender: TObject);
    procedure qb_5000x3000_menu_entryClick(Sender: TObject);
    procedure qb_7000x5000_menu_entryClick(Sender: TObject);
    procedure qb_9000x7000_menu_entryClick(Sender: TObject);
    procedure qb_2ftx1ft_menu_entryClick(Sender: TObject);
    procedure qb_3ftx1ft_6in_menu_entryClick(Sender: TObject);
    procedure qb_4ftx2ft_menu_entryClick(Sender: TObject);
    procedure qb_6ftx2ft_6in_menu_entryClick(Sender: TObject);
    procedure qb_8ftx4ft_menu_entryClick(Sender: TObject);
    procedure qb_8ftx6ft_menu_entryClick(Sender: TObject);
    procedure qb_10ftx8ft_menu_entryClick(Sender: TObject);
    procedure qb_15ftx10ft_menu_entryClick(Sender: TObject);
    procedure qb_20ftx15ft_menu_entryClick(Sender: TObject);
    procedure qb_30ftx20ft_menu_entryClick(Sender: TObject);
    procedure qb_other_mm_menu_entryClick(Sender: TObject);
    procedure qb_other_ft_menu_entryClick(Sender: TObject);
    procedure qb_other_inch_menu_entryClick(Sender: TObject);
    procedure qb_help_menu_entryClick(Sender: TObject);
    procedure qb_colour_menu_entryClick(Sender: TObject);
    procedure qb_thin_lines_menu_entryClick(Sender: TObject);
    procedure qb_medium_lines_menu_entryClick(Sender: TObject);
    procedure qb_thick_lines_menu_entryClick(Sender: TObject);
    procedure qb_options_menu_entryClick(Sender: TObject);
    procedure dummy_template_menu_radioClick(Sender: TObject);
    procedure music1_menu_entryClick(Sender: TObject);
    procedure xing_indicator_panelClick(Sender: TObject);
    procedure xing_indicator_panelContextPopup(Sender: TObject;  MousePos: TPoint; var Handled: Boolean);
    procedure modify_group_to_match_timbering_menu_entryClick(Sender: TObject);
    procedure P32_menu_entryClick(Sender: TObject);
    procedure reload_shapes_menu_entryClick(Sender: TObject);
    procedure add_shapes_menu_entryClick(Sender: TObject);
    procedure save_shapes_menu_entryClick(Sender: TObject);
    procedure adjust_adjacent_centres_ts_menu_entryClick(Sender: TObject);
    procedure adjust_adjacent_centres_ms_menu_entryClick(Sender: TObject);
    procedure music2_menu_entryClick(Sender: TObject);
    procedure cricket_menu_entryClick(Sender: TObject);
    procedure peg_on_split_deflection_menu_entryClick(Sender: TObject);
    procedure hd_timbering_as_switch_menu_entryClick(Sender: TObject);
    procedure hd_timbering_normal_menu_entryClick(Sender: TObject);
    procedure extend_shorten_to_boundary_popup_entryClick(Sender: TObject);
    procedure extend_to_nearest_boundary_popup_entryClick(Sender: TObject);
    procedure meet_at_ctrl0_popup_entryClick(Sender: TObject);
    procedure meet_at_ctrl6_popup_entryClick(Sender: TObject);
    procedure meet_at_ctrl9_popup_entryClick(Sender: TObject);
    procedure peg_on_tminp_menu_entryClick(Sender: TObject);
    procedure peg_on_texitp_menu_entryClick(Sender: TObject);
    procedure move_to_tminp_popup_entryClick(Sender: TObject);
    procedure move_to_texitp_popup_entryClick(Sender: TObject);
    procedure snap_to_tminp_popup_entryClick(Sender: TObject);
    procedure snap_to_texitp_popup_entryClick(Sender: TObject);
    procedure meet_at_tminp_popup_entryClick(Sender: TObject);
    procedure meet_at_texitp_popup_entryClick(Sender: TObject);
    procedure shorten_to_nearest_boundary_popup_entryClick(Sender: TObject);
    procedure meet_at_tolp_popup_entryClick(Sender: TObject);
    procedure experimental_chairing_menu_entryClick(Sender: TObject);
    procedure no_chairing_menu_entryClick(Sender: TObject);
    procedure chairs_baseplates_menu_entryClick(Sender: TObject);
    procedure files_print_menu_entryClick(Sender: TObject);
    procedure go_to_my_documents_menu_entryClick(Sender: TObject);
    procedure expert_picture_help_menu_entryClick(Sender: TObject);
    procedure add_picture_expert_menu_entryClick(Sender: TObject);
    procedure rebuild_group_to_match_cl_options_menu_entryClick(Sender:TObject);
    procedure modify_centre_line_offset_options_popup_entryClick(Sender: TObject);
    procedure extend_shorten_help_popup_entryClick(Sender: TObject);
    procedure sharp_knuckle_menu_entryClick(Sender: TObject);
    procedure normal_knuckle_menu_entryClick(Sender: TObject);
    procedure custom_knuckle_menu_entryClick(Sender: TObject);
    procedure knuckle_help_menu_entryClick(Sender: TObject);
    procedure custom_knuckle_radius_menu_entryClick(Sender: TObject);
    procedure knuckle_bend_menu_entryClick(Sender: TObject);
    procedure printing_page_map_records_menu_entryClick(Sender: TObject);
    procedure pdf_page_map_records_menu_entryClick(Sender: TObject);
    procedure page_map_records_help_menu_entryClick(Sender: TObject);
    procedure rebuild_group_to_match_customize_xing_menu_entryClick(Sender: TObject);
    procedure modify_customized_xing_popup_entryClick(Sender: TObject);
    procedure modify_plain_track_popup_entryClick(Sender: TObject);
    procedure scaling_trackbarEnter(Sender: TObject);
    procedure scaling_trackbarChange(Sender: TObject);
    procedure modify_group_to_match_plain_track_menu_entryClick(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure Label4Click(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure Label6Click(Sender: TObject);
    procedure Label7Click(Sender: TObject);
    procedure scaling_change_buttonClick(Sender: TObject);
    procedure Label8Click(Sender: TObject);
    procedure load_map_menu_entryClick(Sender: TObject);
    procedure trackbed_ballast_edges_menu_entryClick(Sender: TObject);
    procedure add_sketchboard_items_menu_entryClick(Sender: TObject);
    procedure make_single_slip_same_hand_menu_entryClick(Sender: TObject);
    procedure make_single_slip_opposite_hand_menu_entryClick(Sender: TObject);
    procedure make_double_slip_menu_entryClick(Sender: TObject);
    procedure dstip_increase_all_menu_entryClick(Sender: TObject);
    procedure dstip_increase_00EM_menu_entryClick(Sender: TObject);
    procedure dstip_no_increase_menu_entryClick(Sender: TObject);
    procedure make_single_slip_crossover_menu_entryClick(Sender: TObject);
    procedure make_double_slip_crossover_menu_entryClick(Sender: TObject);
    procedure make_slip_help_menu_entryClick(Sender: TObject);
    procedure curvi_match_chairs_menu_entryClick(Sender: TObject);
    procedure curvi_match_regular_menu_entryClick(Sender: TObject);
    procedure curviform_timbering_menu_entryClick(Sender: TObject);
    procedure templot_companion_menu_entryClick(Sender: TObject);
    procedure tip_clearance_help_menu_entryClick(Sender: TObject);
    procedure watch_a_video_menu_entryClick(Sender: TObject);
    procedure show_reminders_menu_entryClick(Sender: TObject);
    procedure add_reminder_popup_entryClick(Sender: TObject);
    procedure edit_reminder_popup_entryClick(Sender: TObject);
    procedure remove_reminder_popup_entryClick(Sender: TObject);
    procedure reminder_colour_popup_entryClick(Sender: TObject);
    procedure reminder_popup_entryClick(Sender: TObject);
    procedure reminder_memo1Click(Sender: TObject);
    procedure reminder_memo2Click(Sender: TObject);
    procedure reminder_memo3Click(Sender: TObject);
    procedure reminder_memo4Click(Sender: TObject);
    procedure reminder_memo5Click(Sender: TObject);
    procedure colour_popup_entryClick(Sender: TObject);
    procedure edit_popup_entryClick(Sender: TObject);
    procedure remove_popup_entryClick(Sender: TObject);
    procedure hide_reminders_menu_entryClick(Sender: TObject);
    procedure minimum_turnout_road_menu_entryClick(Sender: TObject);
    procedure snap_to_minimum_exit_menu_entryClick(Sender: TObject);
    procedure main_road_options_menu_entryClick(Sender: TObject);
    procedure minimum_main_road_menu_entryClick(Sender: TObject);
    procedure main_road_crossover_menu_entryClick(Sender: TObject);
    procedure normal_main_road_menu_entryClick(Sender: TObject);
    procedure adjustable_main_road_menu_entryClick(Sender: TObject);
    procedure adjust_main_road_exit_menu_entryClick(Sender: TObject);
    procedure peg_on_mminp_menu_entryClick(Sender: TObject);
    procedure peg_on_mexitp_menu_entryClick(Sender: TObject);
    procedure move_to_mminp_popup_entryClick(Sender: TObject);
    procedure move_to_mexitp_popup_entryClick(Sender: TObject);
    procedure snap_to_mminp_popup_entryClick(Sender: TObject);
    procedure snap_to_mexitp_popup_entryClick(Sender: TObject);
    procedure isolate_crossing_menu_entryClick(Sender: TObject);
    procedure obtain_gaunt_from_turnout_radius_popup_entryClick(Sender: TObject);
    procedure f9_normal_menu_entryClick(Sender: TObject);
    procedure f9_gaunt_radius_fixed_menu_entryClick(Sender: TObject);
    procedure omit_output_trackbed_edges_menu_entryClick(Sender: TObject);
    procedure include_output_trackbed_edges_menu_entryClick(Sender: TObject);
    procedure meet_at_mminp_popup_entryClick(Sender: TObject);
    procedure meet_at_mexitp_popup_entryClick(Sender: TObject);
    procedure gaunt_radius_menu_entryClick(Sender: TObject);
    procedure f9_options_help_menu_entryClick(Sender: TObject);
    procedure obtain_negative_curving_menu_entryClick(Sender: TObject);
    procedure obtain_positive_curving_menu_entryClick(Sender: TObject);
// OT2024    procedure sb_reload_from_file_menu_entryClick(Sender: TObject);
// OT2024    procedure sb_save_to_file_menu_entryClick(Sender: TObject);
    procedure adjust_gaunt_radius_menu_entryClick(Sender: TObject);
    procedure switch_timbers_menu_entryClick(Sender: TObject);
    procedure closure_timbers_menu_entryClick(Sender: TObject);
    procedure xing_timbers_menu_entryClick(Sender: TObject);
    procedure pointwork_timbering_menu_entryClick(Sender: TObject);
    procedure approach_sleepered_menu_entryClick(Sender: TObject);
    procedure approach_rails_only_menu_entryClick(Sender: TObject);
    procedure ds_tandem_begin_menu_entryClick(Sender: TObject);
    procedure front_timbers_menu_entryClick(Sender: TObject);
    procedure ds_tandem_continue_menu_entryClick(Sender: TObject);
    procedure no_f7_snapping_menu_entryClick(Sender: TObject);
    procedure snap_always_on_background_templates_menu_entryClick(Sender: TObject);
    procedure F7snaphelp1Click(Sender: TObject);
    procedure tandems_click_first_menu_entryClick(Sender: TObject);
    procedure reset_tandem_turnout_menu_entryClick(Sender: TObject);
    procedure ss_tandem_begin_menu_entryClick(Sender: TObject);
    procedure ss_tandem_continue_menu_entryClick(Sender: TObject);
    procedure f9_k_angle_fixed_menu_entryClick(Sender: TObject);
    procedure f9_hd_radius_fixed_menu_entryClick(Sender: TObject);
    procedure k_crossing_radius_menu_entryClick(Sender: TObject);
    procedure obtain_diagonal_from_turnout_radius_popup_entryClick(Sender: TObject);
    procedure show_bgnd_keeps_in_rect_menu_entryClick(Sender: TObject);
    procedure rotate_group_90degs_acw_menu_entryClick(Sender: TObject);
    procedure rotate_group_90degs_cw_menu_entryClick(Sender: TObject);
    procedure shift_group_into_positve_quadrant_menu_entryClick(Sender: TObject);
    procedure rebuild_group_to_match_chairs_menu_entryClick(Sender: TObject);
    procedure modify_chair_outlines_popup_entryClick(Sender: TObject);
    procedure rolled_in_sleepered_menu_entryClick(Sender: TObject);
    procedure rolled_in_rails_only_menu_entryClick(Sender: TObject);
    procedure peg_on_dummy_vehicle_menu_entryClick(Sender: TObject);
    procedure changes_this_version_menu_entryClick(Sender: TObject);
    procedure how_to_menu_entryClick(Sender: TObject);
    procedure scaling_help_staticMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure make_simple_link_popup_entryClick(Sender: TObject);
    procedure make_transition_popup_entryClick(Sender: TObject);
    procedure bold_timbers_on_last_menu_entryClick(Sender: TObject);
    procedure normal_timbers_on_last_menu_entryClick(Sender: TObject);
    procedure remove_extensions_from_all_menu_entryClick(Sender: TObject);
    procedure remove_extensions_from_group_menu_entryClick(Sender: TObject);
    procedure restore_timber_extension_marks_menu_entryClick(Sender: TObject);
    procedure show_corner_info_menu_entryClick(Sender: TObject);
    procedure output_grid_options_menu_entryClick(Sender: TObject);
    procedure wide_format_menu_entryClick(Sender: TObject);
    procedure exchange_1_menu_entryClick(Sender: TObject);
    procedure exchange_2_menu_entryClick(Sender: TObject);
    procedure exchange_3_menu_entryClick(Sender: TObject);
    procedure changes_previous_versions_menu_entryClick(Sender: TObject);
// OT2024    procedure sketchboard_buttonClick(Sender: TObject);
    procedure make_control_popup_entryAdvancedDrawItem(Sender:TObject; ACanvas:TCanvas; ARect:TRect; State:TOwnerDrawState);
    procedure make_control_popup_entryMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
    procedure blank_line_menu_entryAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
    procedure top_name_info_popup_entryAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
    procedure top_name_info_popup_entryMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
    procedure modified_timbering_infill_menu_entryClick(Sender: TObject);
    procedure osk_match_menu_entryClick(Sender: TObject);
    procedure peg_on_osmp_menu_entryClick(Sender: TObject);
    procedure peg_on_osxp_menu_entryClick(Sender: TObject);
    procedure obtain_k_match_popup_entryClick(Sender: TObject);
    procedure group_all_with_same_tag_popup_entryClick(Sender: TObject);
    procedure group_all_with_all_same_tags_popup_entryClick(Sender: TObject);
    procedure adjacent_spacing_ms_menu_entryClick(Sender: TObject);
    procedure timber_numbering_over_platforms_menu_entryClick(Sender: TObject);
    procedure output_detail_options_menu_entryClick(Sender: TObject);
    procedure y_scaling_distortion_menu_entryClick(Sender: TObject);
    procedure reset_normal_y_scaling_menu_entryClick(Sender: TObject);
    procedure show_timber_totals_menu_entryClick(Sender: TObject);
    procedure set_droppers_gaps_menu_entryClick(Sender: TObject);
    procedure view_reset_org_menu_entryClick(Sender: TObject);
    procedure library_viewer_menu_entryClick(Sender: TObject);
    procedure copy_group_as_unused_menu_entryClick(Sender: TObject);
    procedure copy_group_as_library_menu_entryClick(Sender: TObject);
    procedure put_peg_on_intersect_popup_entryClick(Sender: TObject);
// OT2024    procedure get_file_from_code_menu_entryClick(Sender: TObject);
    procedure move_locator_menu_entryClick(Sender: TObject);
    procedure show_locator_menu_entryClick(Sender: TObject);
    procedure obtain_positive_geo_menu_entryClick(Sender: TObject);
    procedure obtain_negative_geo_menu_entryClick(Sender: TObject);
    procedure make_y_turnout_menu_entryClick(Sender: TObject);
    procedure force_symmetry_menu_entryClick(Sender: TObject);
    procedure show_template_symbols_menu_entryClick(Sender: TObject);
    procedure hide_template_symbols_menu_entryClick(Sender: TObject);
    procedure D0GA_menu_entryClick(Sender: TObject);
    procedure music3_menu_entryClick(Sender: TObject);
    procedure peg_on_kp1_menu_entryClick(Sender: TObject);
    procedure peg_on_kp2_menu_entryClick(Sender: TObject);
    procedure peg_on_kp3_menu_entryClick(Sender: TObject);
    procedure peg_on_kp4_menu_entryClick(Sender: TObject);
    procedure parapets_help_menu_entryClick(Sender: TObject);
    procedure ts_parapet_menu_entryClick(Sender: TObject);
    procedure reset_normal_ts_platform_menu_entryClick(Sender: TObject);
    procedure ms_parapet_menu_entryClick(Sender: TObject);
    procedure reset_normal_ms_platform_menu_entryClick(Sender: TObject);
    procedure reposition_menu_popup_entryClick(Sender: TObject);
    procedure program_warning_panelClick(Sender: TObject);
    procedure short_angle_timbering_menu_entryClick(Sender: TObject);
    procedure simplified_short_angle_timbering_menu_entryClick(Sender:TObject);
    procedure normal_short_angle_timbering_menu_entryClick(Sender:TObject);
    procedure online_stl_repair_menu_entryClick(Sender: TObject);
    procedure show_3d_timber_flanges_menu_entryClick(Sender: TObject);
    procedure DXFSTLfileexport1Click(Sender: TObject);
    procedure adjust_clip_size_menu_entryClick(Sender: TObject);
    procedure adjust_clip_angle_menu_entryClick(Sender: TObject);
    procedure use_all_bridge_chairs_menu_entryClick(Sender: TObject);
    procedure show_2d_cutter_kerf_lines_menu_entryClick(Sender: TObject);
    procedure use_custom_switch_opening_menu_entryClick(Sender: TObject);
    procedure set_custom_switch_opening_menu_entryClick(Sender: TObject);
    procedure keys_random_menu_entryClick(Sender: TObject);
    procedure keys_forwards_menu_entryClick(Sender: TObject);
    procedure keys_backwards_menu_entryClick(Sender: TObject);
    procedure keys_to_joint_menu_entryClick(Sender: TObject);
    procedure key_offset_max_menu_entryClick(Sender: TObject);
    procedure samples_009_menu_entryClick(Sender: TObject);
    procedure store_draw_buttonClick(Sender: TObject);
    procedure search_for_menu_entryClick(Sender: TObject);
    procedure use_all_RG_menu_entryClick(Sender: TObject);
    procedure use_all_FG_menu_entryClick(Sender: TObject);
    procedure control_is_brick_menu_entryClick(Sender: TObject);
    procedure group_select_all_bricks_menu_entryClick(Sender: TObject);
    procedure store_as_brick_menu_entryClick(Sender: TObject);
    procedure save_all_brick_templates_menu_entryClick(Sender: TObject);
    procedure cancel_brick_popup_entryClick(Sender: TObject);
    procedure set_brick_popup_entryClick(Sender: TObject);
    procedure show_brick_templates_menu_entryClick(Sender: TObject);
    procedure show_only_brick_templates_menu_entryClick(Sender: TObject);
    procedure hide_brick_templates_menu_entryClick(Sender: TObject);
    procedure all_brick_templates_menu_entryClick(Sender: TObject);
    procedure current_brick_templates_only_menu_entryClick(Sender: TObject);
    procedure samples_0n16p5_menu_entryClick(Sender: TObject);
    procedure save_current_brick_templates_menu_entryClick(Sender: TObject);
    procedure group_select_current_brick_menu_entryClick(Sender: TObject);
    procedure delete_all_brick_templates_menu_entryClick(Sender: TObject);
    procedure delete_current_brick_templates_menu_entryClick(Sender: TObject);
    procedure brick_colour_popup_entryClick(Sender: TObject);
    procedure adjust_slab_angle_menu_entryClick(Sender: TObject);
    procedure convert_group_menu_entryClick(Sender: TObject);
    procedure music4_menu_entryClick(Sender: TObject);
    procedure template_is_waybeams_menu_entryClick(Sender: TObject);
    procedure show_hide_brick_shapes_menu_entryClick(Sender: TObject);
    procedure brick_buttonClick(Sender: TObject);
    procedure chairs_menu_entryClick(Sender: TObject);
    procedure bgtrackbed_edges_colour_menu_entryClick(Sender: TObject);
    procedure use_all_SC_menu_entryClick(Sender: TObject);
    procedure rotate_v_angle_anticlock_menu_entryClick(Sender: TObject);
    procedure rotate_v_angle_clock_menu_entryClick(Sender: TObject);
    procedure rotate_k_angle_anticlock_menu_entryClick(Sender: TObject);
    procedure rotate_k_angle_clock_menu_entryClick(Sender: TObject);
    procedure how_to_print_template_menu_entryClick(Sender: TObject);
    procedure toggle_group_templates_menu_entryClick(Sender: TObject);
    procedure toggle_brick_templates_menu_entryClick(Sender: TObject);
    procedure use_all_S1J_on_switch_front_menu_entryClick(Sender: TObject);
    procedure include_key_with_outers_menu_entryClick(Sender: TObject);
    procedure add_rail_seat_menu_entryClick(Sender: TObject);
    procedure slab_bracket_menu_entryClick(Sender: TObject);
    procedure use_S1J_at_wing_front_menu_entryClick(Sender: TObject);
    procedure cast_a_chair_menu_entryClick(Sender: TObject);
    procedure add_nose_clamp_menu_entryClick(Sender: TObject);
    procedure allow_parallel_wing_DD_menu_entryClick(Sender: TObject);
    procedure add_xing_gap_filler_menu_entryClick(Sender: TObject);
    procedure copy_for_brick_popup_entryClick(Sender: TObject);
    procedure group_select_all_non_bricks_menu_entryClick(Sender: TObject);
    procedure grid_25mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_100mm_spacing_menu_entryClick(Sender: TObject);
    procedure grid_4in_spacing_menu_entryClick(Sender: TObject);
    procedure grid_9in_spacing_menu_entryClick(Sender: TObject);
    procedure fixed_ccl_ccr_menu_entryClick(Sender: TObject);
    procedure variable_ccl_ccr_menu_entryClick(Sender: TObject);
    procedure ms_snibs_menu_entryClick(Sender: TObject);
    procedure ts_snibs_menu_entryClick(Sender: TObject);
    procedure switch_drive_sliders_menu_entryClick(Sender: TObject);
    procedure temp_use_wrong_chairs_menu_entryClick(Sender: TObject);
// OT2024    procedure select_group_by_date_menu_entryClick(Sender: TObject);

  private
    original_pad_window_proc:TWndMethod;             // 214a for drag drop
    procedure pad_window_proc (var msg:TMessage);
    procedure pad_file_drop (var msg:TWMDROPFILES);


  public
    { Public declarations }

    procedure show_by_tag_help_menu_entry_click(Sender:TObject);  // 237a
    procedure hide_by_tag_help_menu_entry_click(Sender:TObject);  // 237a

    procedure show_tagged_templates_click(Sender:TObject);      // 237a
    procedure show_all_tagged_templates_click(Sender:TObject);  // 237a
    procedure hide_tagged_templates_click(Sender:TObject);      // 237a

    procedure selected_tag_menu_entry_click(Sender:TObject);        // 206b
    procedure select_by_tag_help_menu_entry_click(Sender:TObject);  // 206b

    procedure remove_group_tag_menu_entry_click(Sender:TObject);       // 206b
    procedure remove_group_tag_help_menu_entry_click(Sender:TObject);  // 206b

    procedure add_this_tag_menu_entry_click(Sender:TObject);        // 206b
    procedure add_this_tag_help_menu_entry_click(Sender:TObject);   // 206b

    procedure remove_this_tag_menu_entry_click(Sender:TObject);       // 206b
    procedure remove_this_tag_help_menu_entry_click(Sender:TObject);  // 206b

  end;

var
  pad_form: Tpad_form;

//______________________________________________________________________________

const

  xy_pts_c=3000;              //   max 3000 points for main rails. if incx is 18" scale (SQRT 9ft scale in 4mm = SQRT(36) =6 mm),
                              //   template max is 4500' scale length.
                              //   ( = 18000 mm or 59ft approx in 4 mm scale).
                              //   ( = 66 A4 sheets long if straight turnout - but normally less for curved turnout).

  aq_max_c=48;                     // currently 49 rail-lines 0-48

  gauge_indexmax_c=84;             // 211b up to 85 different gauges. was =79,  mod 0.79.a was =69

  swtimbco_c=42;  //  !!! don't change (used in file records)    max number of switch timbers = 42,  [ ,0-41] + zero list end marker [ ,42].

  railen_c=11;                     //  space for 12 different rail length settings (including custom).

  psleep_c=51;    // !!! don't chage (used in files)   //  maximum of 51 sleepers per length plus 0 end marker.

  undo_c=79;                       //  80 slots 0-79 in the roll-back register.
  notch_c=11;                      //  12 slots to rollback the notch.

  parking_c=3;                     //  4 slots in parking bay. 3 slots 0-2 for actual use. slot 3 is temporary slot used for exchange function. 223d

  html_back_c=7;                   //  8 slots in html_back history. // 0.91


  ring_count_c=32;                 //  max 32 ring copies (1-32, 0 is moving ring).

  dv_copies_c=31;                  //  max 32 bgnd dummy vehicles 0-31 0.98.a

  dv_outlines_c=4999;              //  max 5000 dummy vehicles to draw outline envelope

  dv_envelopes_c=7;                //  max 8 envelopes


   // this string used for dropped files, and on bgnd shapes dialog...     214a

  picture_buttons_str:string='image has been loaded into this picture shape. You will now probably want to change its size and/or its position on the trackpad.'

  +'||You can do that by clicking buttons on the `0background shapes`3 dialog window, now showing. You may need to move the dialog windows to see it and/or see the picture shape.'

  +'||The buttons needed are on the `0modify shape`1 tab on the background shapes dialog.'
  +' They are currently showing highlighted in <SPAN STYLE="BACKGROUND-COLOR:#FFFF00;">yellow</SPAN>.'

  +'||Templot can automatically adjust the size of a picture shape containing a track plan or map'
  +' to match your current model gauge and scale. Click the `0auto-fit...`1 button.'

  +'||To change the size of this picture shape by mouse action, click the `0size`1 button.'
  +'||To move this picture shape to a new position by mouse action, click the `0shift`1 button.'

  +'||To change the size manually, click the `0re-size...`1 button.'
  +'||To set a new position manually, click the `0shift to...`1 button.'

  +'|||To change the size, position and aspect ratio of the picture shape in one go, click the `0change dimensions...`1 button.|&nbsp;';

//______________________________________________________________________________

type

  Tdtp_shape_tag=record                         // 0.93.a type cast for dtpShape.Tag (integer)
                   no_update:         boolean;  // Tag=0 means all default to False
                   copyright_mark:    boolean;
                   zooming_rectangle: boolean;
                   reference:         boolean;  // 227a  was sparebool
                 end;

  Tmark=record              // mark from p1 to p2.
          p1:TPoint;                // [0],[1]
	         p2:TPoint;                // [2],[3]
          code:integer;             // [4]
	         tb_code:integer;          // [5]   235b  timber number string converted to character and number
          dxf_chair_code:integer;   // [6]   237a  chairing data for 3D exports
          mark_bits:integer;        // [7]   555a  32 bit settings
        end;
  Tmark_array=array of Tmark;

  Tpex=record                      // x,y point floats (TPoint is integer).
         x:extended;
         y:extended;
       end;

  T3pex=record                     // x,y,z point floats 229e
         pex:Tpex;
         z:extended;
       end;

  Tlinepex=record            // 237b
             end1:Tpex;
             end2:Tpex;
             valid:boolean;
           end;

  Textents=record           // 0.93.a
             min:Tpex;
             max:Tpex;
           end;

  Tsnibs_data=record                                 // 243b
                omit_tsn_snibs:boolean;  // TS near
                omit_tsf_snibs:boolean;  // TS far
                omit_msn_snibs:boolean;  // MS near
                omit_msf_snibs:boolean;  // MS far

                add_near_link:boolean;
                add_far_link:boolean;
              end;

  Twebs_data=record                                 //555a  MW 17-AUG-2024
                omit_tsn_web:boolean;  // TS near
                omit_tsf_web:boolean;  // TS far
                omit_msn_web:boolean;  // MS near
                omit_msf_web:boolean;  // MS far
              end;

  Tjaw_option=array[0..5] of boolean;   // 244a  6 options each jaw

  Tjaw_options=array of Tjaw_option;   // 244a


  Theave_rail_chair=record   // 244a  chair heave data for one rail on a shoved timber

                      hv_omit:boolean;               // chair on rail
                      hv_ch:integer;                 // modified chair code

                      hv_sc_outlong:extended;        // custom SC chair dims
                      hv_sc_inlong:extended;
                      hv_sc_halfwide:extended;

                      hv_flip:boolean;               // key flipped
                      hv_omit_key:boolean;           // key omitted    556 MW

                      hv_jaws:boolean;               // jaws customized

                      hv_plug:integer;               // plug customized     0=no change, 1=force clip-fit  2=force snap-fit  3=force press-fit  4=force COT (no plug)

                      hv_jaw_options:array[0..3] of Tjaw_option;   // customized jaws on 4 possible rails in a chair 0..3

                    end;



  Tshove_data=record     // shove data for a single timber ( version 0.71 11-4-01 ).

           sv_code     :integer;     // 0=empty slot, -1=omit this timber,  1=shove this timber.
           sv_x        :extended;    // xtb modifier.
           sv_k        :extended;    // angle modifier.
           sv_o        :extended;    // offset modifier (near end).
           sv_l        :extended;    // length modifier (far end).
           sv_w        :extended;    // width modifier (per side).
           sv_c        :extended;    // crab modifier.  0.78.c  01-02-03.

           sv_tcol:integer;          // 226a modified trackpad infill colour
           sv_ocol:integer;          // 226a modified output colour

           sv_tcol_infill:byte;      // 226a   infill code
           sv_ocol_infill:byte;      // 226a

           sv_use_tcol:boolean;      // 226a   use it flag
           sv_use_ocol:boolean;      // 226a

           sv_bgnd:boolean;          // 226a   also use tcol for bgnd templates on pad
           sv_export:boolean;        // 226a   also use ocol for exported images

           sv_spare:byte;            // 244a  options set for 3D and DXF exports

           sv_option_bits:byte;      // 229a
                                     // msb  hide outline , sv_col_has_been_set , - , spare , omit TS end flange , omit MS end flange , omit FAR side flange , omit NEAR side flange  lsb

         end;//record

  Tshoved_corners_pex=record    // 226a
    p1:Tpex;
    p2:Tpex;
    p3:Tpex;
    p4:Tpex;
  end;//record

  Tshoved_corners=record    // 226a
    p1:TPoint;
    p2:TPoint;
    p3:TPoint;
    p4:TPoint;
  end;//record

  Tshoved_mod_infill=record
    current_shoved_corners:Tshoved_corners;
    stored_shoved_corners:Tshoved_corners;
    shoved_number_str:string[6];            // shoved timber number
  end;//record

  Tshoved_timber=record
                   sv_str:string[6];
                   shove_data:Tshove_data;
                   shoved_mod_infill:Tshoved_mod_infill;

                   snibs_data:Tsnibs_data;    // 243b

                   webs_data:Twebs_data;      // 555a

                   heave_rail_chairs:array[1..4] of Theave_rail_chair;
                 end;//record


  Tshoved_timbers=array of Tshoved_timber;


  Tnotch=record      //  a notch position.
           notch_x:extended;
           notch_y:extended;
           notch_k:extended;
         end;//record


  Tboundary_info=record            // 213b  for extend to boundary function

                    loc_0:Tnotch;     // CTRL-0
                    loc_6:Tnotch;     // CTRL-6
                    loc_9:Tnotch;     // CTRL-9
                    loc_240:Tnotch;   // TMINP
                    loc_241:Tnotch;   // TEXITP
                    loc_260:Tnotch;   // MMINP     // 217a
                    loc_261:Tnotch;   // MEXITP    // 217a
                    loc_600:Tnotch;   // TOLP
                    loc_630:Tnotch;   // THDP      // 226c

                    boundary_diag:extended; // diagonal length between boundaries
                 end;//record


  Tpad_view_data=record                 // 0.91.c  a zoom/pan setting.
                   offset_x:extended;
                   offset_y:extended;
                   width_x:extended;
                 end;//record

  Tpad_view=class(TPersistent)          // 0.91.c    object in pad_view_list.

                 public

                   pad_view_data:Tpad_view_data;

                 end;//class


  Thtml_history=record    // html viewer history record.  // 0.91

                  src_code: integer;       // 1=src_str is file name.  0 or negative =src_str is actual html source (help code).
                  src_position:integer;    // html viewer position within scr_str.
                  src_str:string;
                end;//record


  Timage_shape=record
                 image_bitmap:TBitmap;           // image bitmap.
                 rotated_bitmap:TBitmap;         // rotated bitmap for printing. // 0.93.a also used for curving bitmap

                 rotated_picture:TPicture;       // picture object to contain it.

                 undo_bitmap:TBitmap;            // 227a   for map clarity functions

                 image_metafile:Temf;            // 555a      MW 12-AUG-2024
                 rotated_metafile:Temf;          // 555a

                 image_width:integer;
                 image_height:integer;

               end;//record

  Tbgimage=class(TPersistent)             // 3-2-01

           public                         // 0.85.a

               image_shape:Timage_shape;

           end;//class

  //------------------------------------------------------------------------

         // changes 234b   8th May 2022

  Told_bgnd_shape=record    // loaded from old BGS files

                    // as in BGS file...

                shape_name:string[46];    // name or text string.  205e

                wrap_offset:integer;      // 1/100th mm for picture shape wrapping  205e     !!! also used for brick colour 229a

                show_transparent:boolean; // 0.93.a  for bitmap image    234a also for direction of target clip

                shape_code:integer;       // 0=line, 1=rectangle, 2=circle, 3=text label, 4=target mark / brick clip, -1=picture (bitmap image or metafile)

                shape_style:byte;         // 0=transparent, 1=blank/solid, 2=cross-hatched/dotted line;  // 213b was integer (stored MSB (byte) first)

                picture_is_metafile:boolean;      // 213b

                hide_bits:byte;           // 214a  0=normal,  1=hide on trackpad,  2=hide on output,  3=hide both

                option_bits:byte;         // 226b  0=normal, 1 bit = don't allow sync

                                          // msb  map tile, has_been_interpolated , has_been_2_toned , has_been_low_contrast , has_been_negative , line is brick label tab , pre_227a , don't allow sync    lsb
                                          //        $80         $40                    $20                 $10                      $08                     $04                $02              $01
                p1:Tpex;
                p2:Tpex;
              end;//record

  Tshapefile = file of Told_bgnd_shape;      // the shapes data file

    //--------------------------------

  Tbgnd_shape=record    // new loaded only from BGS3 XML files

                    // as in BGS file...

                shape_name:string[46];    // name or text string.  205e

                wrap_offset:integer;      // 1/100th mm for picture shape wrapping  205e     also used for brick colour 229a

                show_transparent:boolean; // 0.93.a  for bitmap image    234a also for direction of target clip

                shape_code:integer;       // 0=line, 1=rectangle, 2=circle, 3=text label, 4=target mark / brick clip, -1=picture (bitmap image or metafile)

                shape_style:byte;         // 0=transparent, 1=blank/solid, 2=cross-hatched/dotted line;  // 213b was integer (stored MSB (byte) first)

                picture_is_metafile:boolean;      // 213b

                hide_bits:byte;           // 214a  0=normal,  1=hide on trackpad,  2=hide on output,  3=hide both

                option_bits:byte;         // 226b  0=normal, 1 bit = don't allow sync

                                          // msb  map tile, has_been_interpolated , has_been_2_toned , has_been_low_contrast , has_been_negative , line is brick label tab , pre_227a , don't allow sync    lsb
                                          //        $80         $40                    $20                 $10                      $08                     $04                $02              $01

                p1:Tpex;                  // first corner/end
                p2:Tpex;                  // second corner/end or other data

                rect_rot:extended;        // added 234b  rotation angle for rectangles

                clip_pairing_code:TDateTime;    // 234c  brick clips use Now as pairing code    0=not paired

                is_brick:boolean;         // added 234b

                is_brick_boundary_rect:boolean;  // added 234d

                is_brick_wall:boolean;    // 234e

                wall_width:extended;      // 234e
                wall_depth:extended;      // 234e

                brick_label_scaling:extended;  // 236c

                is_kerf:boolean;  // 244a

              end;//record

  Tbgshape=class(TPersistent)

           public                         // 0.85.a

              bgimage:Tbgimage;           // pointer to image object. 3-2-01.
              bgnd_shape:Tbgnd_shape;     // data for a background shape.

            end;//class



   //----------------------------

  Tdummy_vehicle_corners=record         // 0.98.a    mm on grid.
                           pt1:Tpex;
                           pt2:Tpex;
                           pb1:Tpex;
                           pc1:Tpex;
                           pb2:Tpex;
                           pc2:Tpex;
                           b1:Tpex;
                           b2:Tpex;
                           b3:Tpex;
                           b4:Tpex;
                           c1:Tpex;
                           c2:Tpex;
                           c3:Tpex;
                           c4:Tpex;
                           m1:Tpex;
                           m2:Tpex;
                           o1:Tpex;
                           o2:Tpex;
                           o3:Tpex;
                           o4:Tpex;
                         end;//record

  Tdummy_vehicle_envelope=record         // 215c    mm on grid.
                           b1:Tpex;
                           b2:Tpex;
                           b3:Tpex;
                           b4:Tpex;
                           c1:Tpex;
                           c2:Tpex;
                           c3:Tpex;
                           c4:Tpex;
                           o1:Tpex;
                           o2:Tpex;
                           o3:Tpex;
                           o4:Tpex;
                         end;//record

  Tdv_envelopes=record         // 215c
                  dv_outlines:array[0..dv_outlines_c] of Tdummy_vehicle_envelope;  // string of 5000 dummy vehicle copies to create outline envelope 215c.
                  dv_outlines_limit:integer;
                end;//record


  //------

     // new 3D chair lists 237c ...

     // built in drawtimber function
     // read by DXF export

     // entry in a list is a single chair jaw, seat, key, etc

     // 2D data (chair outlines, bases, bolts, plugs, pyramids, etc.) are in the marks list

  Tjaw=record
         chcode:integer;           // type of chair            0=invalid item
         rail:integer;             // which rail it is on
         right_hand:boolean;       // template hand
         inner:boolean;            // on gauge face
         loose_outer:boolean;      // loose outer jaw

         t_str:string[5];    // on which timber number

         j_str:string[9];    // jaw ident name (DXF block mame) ...

         x1:extended;    // dxf double insertion points..  bb angle and mid-insertion point calculated in DXF export
         y1:extended;

         x2:extended;
         y2:extended;

         z_mod:extended;  // insertion height - lower for loose jaws
       end;//record

  Tjaws=array of Tjaw;     // dynamic array

  //---

  Tseat=record
          chcode:integer;       // type of chair            0=invalid item
          rail:integer;         // which rail it is on
          right_hand:boolean;   // template hand

          t_str:string[4];     // which timber number

          s_str:string[9];   // seat ident name (DXF block mame) ...

          x1:extended;    // dxf insertion points..  angle and mid-insertion point calculated
          y1:extended;

          x2:extended;
          y2:extended;
       end;//record

  Tseats=array of Tseat;     // dynamic array

  //---

  Tkey=record
         chcode:integer;       // type of chair            0=invalid item
         rail:integer;         // which rail it is on
         right_hand:boolean;   // template hand
         loose_outer:boolean;  // key is on loose outer jaw

         t_str:string[4];     // which timber number

         k_str:string[9];     // key ident name (DXF block mame) ...

         x1:extended;    // dxf insertion points..  angle and mid-insertion point calculated
         y1:extended;

         x2:extended;
         y2:extended;

         z_mod_key:extended;  // insertion height - lower for loose jaws
       end;//record

  Tkeys=array of Tkey;     // dynamic array

  //---

  Tjmod=record                 // customized chair jaw
          jm_str:string[9];    // jaw ident name (DXF block mame) '...'

          jm_h:integer;        // hand of template

          jm_aq_y:extended;     // for current rail
          jm_aq_k:extended;     // angle
          jm_aq_f:extended;     // check rail flare
        end;//record

  Tjmods=array of Tjmod;     // dynamic array

  //-----------

  Ttimber_count_object=class(TPersistent)    // 227a
  public
    numco:integer;
  end;//class

  Ttimber_count=record
                  num_str:string[20];
                  number:integer;
                end;//record

  Ttimber_counts=array of Ttimber_count;

  Tlib_item=class(TPersistent)     // 227a    library template
  public
    list_index:integer;
    bitmap:TBitmap;
  end;//class


  Tbgnd_keep=record        // drawn data for a background template

               xlist_max:integer;     // max and min list values for printing calcs and DXF,
               xlist_min:integer;     // and pad reset...
               ylist_max:integer;
               ylist_min:integer;

               planing_end_aq1:integer;   // list index for these locations for printing.
               planing_end_aq2:integer;

               text_begin_X:integer;    // name label text locations for mouse select (screen pixels).
               text_begin_Y:integer;

               text_end_X:integer;      // rectangle for mouse hover detect.
               text_end_Y:integer;

               requested_label_string:string;   // his settings.
               full_label_string:string;        // full number+name.
               showing_label_string:string;     // actual string showing.

               text_font_height:integer;   // 211b was textfontsize:integer;

               timber_numbers_string:string;    // the complete numbers sequence, separated by ESC ($1B) characters.

               list_bgnd_marks:array[0..7] of Pointer;               // pointers only, so can't save this data in a file (of Tbgnd_keep). 555a 7 was 6  235b 6 was 4
               list_bgnd_rails:array[0..aq_max_c, 0..1] of Pointer;

               bgnd_endmarks:array[0..aq_max_c, 0..1] of TPoint;     // rail end mark points. 1/100th mm , curved ready for drawing.
               bgnd_endmarks_yn:array[0..aq_max_c, 0..1] of boolean; // flag end points exist.

             end;//record
  //-----------------------


  //   227a symbols ...    20/10/2020

  Tsymbol_data=record       // in file

             symb_list_str:string[14];

             symb_id_str:string[12];

             symb_check_rail:boolean;

             symb_colour:TColor;

             symb_type:integer;    // 0=dropper, 1=gap, 2=sticker
             symb_size:integer;    // 0..3
             symb_rail:integer;    // 1..4

             symb_code:integer;         //  0=normal  1=chair options sticker

             symb_spare_float:extended;

             symb_x:extended;
           end;//record

  Tdrawn_symbol=record   // 227a a drawn symbol

             symbol_back_colour:TColor;

             poly_points:array[0..23] of TPoint;   // up to 24 points to make 24-sided polygon flag or gap tuf
             num_points:integer;                   // number of points
             symbol_point:TPoint;                  // under rail
             end_point:TPoint;                     // end of flagpole
             id_point:TPoint;                      // centre of ID label
             id_height:TPoint;                     // X=ID label text font height (dots), Y=0 not used

             pad_symbol_point:TPoint;    // for click detection..
             pad_proximity:integer;

           end;//record


  Tsymbol=record
             symbol_data:Tsymbol_data;
             drawn_symbol:Tdrawn_symbol;
           end;//record

  Tsymbols=array of Tsymbol;


  //-------------------

  Tgauge_scale=record              // was part of Tgauge_info.
                                   // now used only for the list, not in file. 0.71.a

                 name_str_glist:string;           // 215a gauge designation.

                      scale_glist:extended;       // mm per ft.
                      gauge_glist:extended;       // mm.
                         fw_glist:extended;       // mm flangeway.
                        fwe_glist:extended;       // mm flangeway end gap (flangeway+flare).

                    old_fwe_glist:extended;       // old pre-215a flangeway end gap.

                   trtscent_glist:extended;       // mm track centres, turnout side.
                   trmscent_glist:extended;       // mm ditto, main side.
                 min_radius_glist:extended;       // mm minimum radius for check.
               end;//record



  Tsnap_peg_positions=record        // snapping positions for F7 shift mouse action  0.79.a  27-05-06
                                    // and background popup snap options.

                        ctrl_peg_now_pos:Tnotch;
                        ctrl_0_pos:Tnotch;
                        ctrl_1_pos:Tnotch;

                        ctrl_2_pos:Tnotch;  // added 205c

                        ctrl_planing_pos:Tnotch;   // added 205e for obtain turnout radius to control
                        ctrl_heel_pos:Tnotch;      // added 205e for obtain turnout radius to control

                        ctrl_3_pos:Tnotch;

                        ctrl_cesp_pos:Tnotch;      // added 205e for obtain turnout radius to control

                        ctrl_4_pos:Tnotch;
                        ctrl_5_pos:Tnotch;
                        ctrl_6_pos:Tnotch;
                        ctrl_7_pos:Tnotch;
                        ctrl_8_pos:Tnotch;
                        ctrl_9_pos:Tnotch;
                        ctrl_tcp_pos:Tnotch;   // TCP
                        ctrl_mcp_pos:Tnotch;   // MCP
                        ctrl_tolp_pos:Tnotch;  // TOLP

                        ctrl_tminp_pos:Tnotch;     // TMINP     // 213b
                        ctrl_texitp_pos:Tnotch;    // TEXITP    // 213b

                        ctrl_thdp_pos:Tnotch;      // THDP      // 226c

                        ctrl_mminp_pos:Tnotch;     // MMINP     // 217a
                        ctrl_mexitp_pos:Tnotch;    // MEXITP    // 217a

                        ctrl_tsmidp_pos:Tnotch;    // TS curve mid-point  218a

                        ctrl_knucklebend_pos:Tnotch;  // start of knuckle bend  218a

                        ctrl_atimb_pos:Tnotch;     // "A" timber 218a

                        ctrl_mid_pos:Tnotch;      // mid-length  216a

                        ctrl_user_pos:Tnotch;  // user-defined peg pos    added 205c

                      end;//record


//______________________________________________________________________________

var

  aq_str:array[0..aq_max_c] of string;         //  names of rail-edges.

  xy_ends:array[0..aq_max_c, 0..1] of Tpex;    // rail edge end points  (used to mark rail ends and blunt nose). 14-4-99
                                               // 0=start of edge, 1=end of edge (extended, mm)

  endmarks:array[0..aq_max_c, 0..1] of TPoint;     // rail end mark points. 1/100th mm , curved ready for drawing.
  endmarks_yn:array[0..aq_max_c, 0..1] of boolean; // flag end points exist.

  xy_max:array[0..1] of integer;           // max x and y values in list (could be less than xy_most if drawing all negative).
  xy_min:array[0..1] of integer;           // min x and y values in list (could be more than xy_least if drawing all positive).

  aqyn:array[0..aq_max_c] of boolean;      //  yes/no calc this aq ?  mods 13-6-99.

  xy_p:array[0..aq_max_c, 0..1] of Pointer;   // pointers to integer arrays containing rail data in 1/100 of a mm.

  nlnow_array:array[0..aq_max_c] of integer;     //  ( aq_i )    current index into each aq array.
  nlmax_array:array[0..aq_max_c] of integer;     //  ( aq_i )    max nlnow so far used for each aq.
  nldim_array:array[0..aq_max_c] of integer;     //  ( aq_i )    array length (max index) for each aq.

  rings:array[0..ring_count_c,0..3] of extended;        // for spacing ring copies.
  ring_index:integer=0;
  ring_dia:extended=0;
  ring_has_been_shown:boolean=False;  // 0.98.a

                       // v:0.76.a 1-5-02...

  rings_checkpoints:array[0..ring_count_c,0..3] of integer;   // for spacing ring infringement checks
                                                              // 0=x, 1=y, 2=aq, 3=infringed closer than 2ft scale to ring 0/1.
  min_ring_distance:extended=0;   // v:0.76.a 1-5-02.
  ring_warn:boolean=True;
  ring_copies_warn:boolean=False;
  ring_infringed:boolean=False;
  ring_copies_infringed:boolean=False;
  incx125:extended=875;                    // 1.25*incx in 1/100ths mm , for ring infringement testing.
  warn_centrelines:boolean=False;

  dv_copies:array[0..dv_copies_c] of Tdummy_vehicle_corners;  // up to 32 copies 0.98.a
  dv_copies_index:integer=-1;                                 // init num copies -1

  marks_list:Tmark_array;

  timb_numbers_str:string='';     // accumulated timber numbering strings with $1B separators.

  gauge_str:string='T-55';

  xing_list_i,
  entry_straight_code,    // 0.93.a was xing_sl_i
  xing_k_i:integer;

  xing_ret_i:integer=0;

  list_planing_mark_aq1:integer=0;
  list_planing_mark_aq2:integer=0;

  hand_i:integer;

  xing_type_i:integer=0;     //0.93 18-05-10
  xing_calc_i:integer=0;

  pt_i:integer;
  spiral:boolean=False;
  slewing:boolean=False;     // slewing flag.
  slew_mode:integer=1;

  joggled:boolean=False;

  overscale_joggles:boolean=False;
  switch_drive_markx:boolean=True;

  scale:extended=5.5;         // default 5.5 mm/ft
  inscale:extended=5.5/12;
  incx:extended=7.0;

  mvjpx:extended=200;

  nomrad:extended=3630;
  nomrad1:extended=1.0E8-5000;   // max_rad
  nomrad2:extended=3630;

  max_spiral_constant:extended=500.0E6;  // 0.72  23-7-01.

  egeo_rad:extended=2000;   // geometrical rads, arbitrary start.
  igeo_rad:extended=1815;
  egeo_k:extended=0;
  igeo_k:extended=0;

  egeo_swing:extended=0;
  egpx:extended=0;
  igeo_swing:extended=0;
  igpx:extended=0;

  egeo_orgx:extended=0;
  egeo_orgy:extended=2000;

  igeo_orgx:extended=0;
  igeo_orgy:extended=2000;

  railtop:extended=2.75*5.5/12;        // 2.75" startup
  railbottom:extended=5.5*5.5/12;      // 5.5" startup (flatbottom base).

  rail_height:extended=5.71875;        // 5.23/32" inches full-size BS95R bullhead. - also for foot position/inclination calcs.

  rail_inclination:extended=0.0499584;    // radians (1:20).

  rail_section:integer=1;       // 0=no rails, 1=head only(bullhead), 2=head+foot(flatbottom), 3=rail top-centreline only, 4=rail centreline on timber only.
  vertical_rails:boolean=True;  // False = inclined rails.

  fb_kludge:integer=0;     // 0.94.a kludged foot-lines ..  0=normal, 1=inner foot, 2=outer foot

  track_centre_lines_flag:boolean=True;

  switch_drive_flag:boolean=True;   // 0.82.a

  isolated_crossing:boolean=False;  // 217a


  turnout_road_stock_rail_flag:boolean=True;    // rail switches per template...
  turnout_road_check_rail_flag:boolean=True;
  turnout_road_crossing_rail_flag:boolean=True;
  crossing_vee_flag:boolean=True;
  main_road_crossing_rail_flag:boolean=True;
  main_road_check_rail_flag:boolean=True;
  main_road_stock_rail_flag:boolean=True;

  k_diagonal_side_check_rail_flag:boolean=True;
  k_main_side_check_rail_flag:boolean=True;

  turnoutx, xorg: extended;
  turnoutx_max:extended;
  default_turnoutx:extended;

  turnout_road_endx:extended=0;      // 209a
  min_turnout_road_endx:extended=0;  // 209a

  main_road_endx:extended=0;      // 217a
  min_main_road_endx:extended=0;  // 217a

  startx:extended=0;     // 1-11-99

  pt_blank:extended=0;  // 229a   // plain track blanking from CTRL-1


  notchx:extended=0;
  notchy:extended=0;

  pad_peg_point:Tpex;            // peg position on pad in mm.

  pad_locator_point:Tpex;        // 227a locator position on pad in mm.

  chosen_colour_scheme:integer=4;     // 224a used in user prefs, 4=sky blue startup


                              // init all screen colours to black...

               page_colour:integer=0;
         keep_paper_colour:integer=0;
          keep_grid_colour:integer=0;
          keep_rail_colour:integer=0;
          keep_mark_colour:integer=0;
        keep_timber_colour:integer=0;
              align_colour:integer=0;
              trans_colour:integer=0;
              paper_colour:integer=0;
               rail_colour:integer=0;
        rail_infill_colour:integer=0;
              guide_colour:integer=0;
             timber_colour:integer=0;
      timber_infill_colour:integer=0;
          selection_colour:integer=0;
              hover_colour:integer=0;
             shapes_colour:integer=0;
      shapes_infill_colour:integer=0;      // 239a   
        bgkeep_rail_colour:integer=0;
      bgkeep_timber_colour:integer=0;
  bgkeep_timberfill_colour:integer=0;
        bgkeep_mark_colour:integer=0;
         bgkeep_peg_colour:integer=0;

    bgkeep_platform_colour:integer=0;  // 0.93.a

    bgkeep_trackbed_colour:integer=$0000D0FF;  // 236b default gold


               grid_colour:integer=0;
               ring_colour:integer=0;
          ring_copy_colour:integer=0;
                ink_colour:integer=0;
              joint_colour:integer=0;


  grid_labels_code_i:integer=6;   // mm

  fixed_sl:extended=12;   // 1mm flangeway 1:6 default.

  plain_track:boolean;    // true = plain track only  (was called tpl).

  grid_spacex:extended=150;      // grid spacing mm
  grid_spacey:extended=150;

  paper_bunching:boolean=False;

  y_datum:extended;

  xform:extended=0;
  yform:extended=0;
  xshift:extended=0;
  yshift:extended=0;
  kform:extended=0;
  kform_start:extended=0;

  label_modx:extended=0;    // 211b labels not used for control template, but retained for when stored again
  label_mody:extended=0;    // 211b ditto

  xshift_keeps:extended=0;
  yshift_keeps:extended=0;
  kform_keeps:extended=0;

  xshift_labels:extended=0;    // 0.82.d
  yshift_labels:extended=0;    // 0.82.d

  xshift_labels_old:extended=0;    // 0.82.d
  yshift_labels_old:extended=0;    // 0.82.d

  xshift_quickset:extended=0;  // 0.93.a
  yshift_quickset:extended=0;  // 0.93.a

  shift_keeps_mod:integer=0;
  twist_keeps_mod:integer=0;
  move_labels_mod:integer=0;   // 0.82.d

  porg_mod:integer=0;

  corner1_mod:integer=0;
  corner2_mod:integer=0;

  oneshape_shift_mod:integer=0;
  oneshape_scale_mod:integer=0;

  clip_size_mod:integer=0;
  clip_angle_mod:integer=0;

  allshapes_shift_mod:integer=0;
  allshapes_scale_mod:integer=0;
  allshapes_rotate_mod:integer=0;

  rect_left_mod:integer=0; // output boundary rectangle 0.93.a ...
  rect_right_mod:integer=0;
  rect_top_mod:integer=0;
  rect_bottom_mod:integer=0;
  rect_move_mod:integer=0;

  out_factor_mod:integer=0;

  ruler1_mod:integer=0;
  ruler2_mod:integer=0;
  ring_mod:integer=0;
  ringdia_mod:integer=0;
  notch_mod:integer=0;
  peg_mod:integer=0;

  group_notch_linked:boolean=False;
  notch_linked_to_current:boolean=False;

  paper_way:integer;  // 1=portrait,  2=landscape,   -1=automatic

  info_show_i:integer;

                                        // ruler tool - arbitrary starts...
  ruler_startx:extended=50.0;           // mm..
  ruler_endx:extended=300.0;
  ruler_starty:extended=100.0;
  ruler_endy:extended=200.0;
  ruler_div:extended=50.0;              // 50 mm divisions.
  ruler_units:integer=0;                // ruler units as grid.

  scale_bar_i:integer=0;                // hide scalebar  0.79.a     23-05-06
  sb_colour_use:integer=1;

  mark_index:integer=0;

  printgrid_i:integer;
  rail_infill_i:integer=2;            // solid coloured printed rail infill.

  draw_mode:integer=1;                // free zooming.

  timbering_infill:boolean=True;              // generator switch.
  modified_timbering_infill:boolean=True;     // generator switch.

  pad_timb_infill_style:integer=3;            // solid.
  bgpad_timb_infill_style:integer=3;          // solid.
  print_timb_infill_style:integer=3;          // solid.

  print_platform_infill_style:integer=3;          // solid.   0.93.a

  marker_colours_pad:integer=3;        //   for pad: 0=normal, 1=rails only, 2=timber outlines only, 3=rails and timber outlines, 4=use print mapping colours instead.
  mapping_colours_print:integer=4;     // for print: 0=normal, 1=rails only, 2=timber outlines only, 3=rails and timber outlines, 4=use the pad marker colours instead, -1=single colour.

     // 0.94.a was 3 above. Changed to using the pad colours as default for sketchboard, image files, etc.

  no_printer_available:boolean=True;   // 0.93.a wait for list, before setting false in templot_init.  was False;
  banner_paper:boolean=False;

  calcs_done_and_valid:boolean=False;
  abandon_calcs:boolean=True;
  data_changed:boolean=True;

  gocalc_lock:boolean=False;

  print_entire_pad_flag:boolean=False;     // print flag for printing entire pad including background keeps.
  print_group_only_flag:boolean=False;     // entire pad prints the group only. 0.78.b 10-12-02.

  black_white:boolean=False;          // print in colour..
  grey_shade:boolean=False;

  pad_cols_set:boolean=False;

  tb:extended;
  tbwide:extended;

  zoom_offsetx:extended=0-1122/75;      // mm  227a  start-up defaults    1122mm trial & error screenx
  zoom_offsety:extended=0-1122/150;

  zoom_offsetx_now, zoom_offsety_now:extended;

  print_pages_top_origin_now,print_pages_left_origin_now:extended;

  bunching_jump:extended=250;           // for paper bunching mm. 250 mm default.
  bunching_jump_now:extended=250;
  bunch_jump_i:integer=0;               // ditto in pixels.
  bunch_now:integer=0;

  bunching_shear:extended=0;            // for paper bunching.
  bunching_shear_now:extended=0;
  bunch_shear_i:integer=0;              // ditto in pixels.
  shear_now:integer=0;

  bunch_start:integer=300;              // (default for 640 res).
  bunch_gap:integer=40;

  screenx:extended=1300;      // default 227a
  screeny:extended;

  full_draw:boolean=False;              // default skeleton mouse draw.

  shove_mouse_factor:extended=2.0;      //  mouse response for timber shoving (along/across)

  mouse_gaunt_offset_factor:extended=0.05;  // 0.05 arbitrary.  0.93.a

  mouse_gaunt_radius_factor:extended=100;  // arbitrary.  217b

  mouse_xing_factor:extended=100;       //  100 arbitrary.  F5  size.
  mouse_curv_factor:extended=100;       //  100 arbitrary.  F6 curving.
  mouse_rot_factor:extended=100;        //  F8 rotate.
  mouse_orbit_factor:extended=100;      //  CTRL-F5 orbit.
  fine_adjust:extended=1;               //  factor modifier.

  peg_arm_length:extended=0.75*5.5;      // 227a 9" default in 5.5mm scale    was 3ft 16.5mm

  do_rollback:boolean=True;
  save_hide:boolean=False;
  cl_only:boolean=False;     // draw background as centre-line only.

  dummy_template:boolean=False;  // 211c draw centre-line as a background shape thickness/colour

  cl_options_code:integer=0;            // which centre-line? 0=main road  206a
  cl_options_custom_offset:extended=0;  // custom offset

  hover_keep_index:integer=-1;     // mouse hovering over this one...

  clicked_keep_index:integer=-1;   // this one actually clicked...

  show_margins:integer=0;           // page margins on pad. 0.93.a    was boolean:True;
  screengrid_flag:boolean=True;     // draw grid on pad.

  mouse_modify:integer=-1;          // was modify_on  -1= no mouse actions. 0= mouse action selected. 1+ = mouse action in progress.

  click_bgnd_select:boolean=False;  // ditto for selection list.
  shift_click:boolean=False;        // ditto for selecting with shift key down.
  clicks_accepted:boolean=False;    // if true mouse is over bgnd keep.
  bgnd_form_closed:boolean=False;   // if true, re-open the shapes form after mouse drawing.

  save_sx, save_sy, save_ex, save_by, save_gx, save_gy:extended;

  screenx_max:extended=550000;      // maximum screen width mm (zoom-out) (550m = 100000ft scale at 5.5 mm/ft startup)        215a  was 55m  (to allow for large tiled maps)
  screenx_min:extended=6;           // mm  229c was 10mm   0.93.a was 15mm. minimum screen width mm (zoom in)

  current_shove_str:string='';        // number string for currently selected shove timber.
  shovetimbx:extended=0;              // x to selected shove timber.
  shovetimbx_zero:extended=0;         // zero datum for read-out on shove timber form.   13-1-01.

  shovetimb_len:extended=0;           // length of timber selected for shoving.   13-1-01.
  shovetimb_keq:extended=0;           // angle of timber selected for shoving.    13-1-01.
  shovetimb_throw:extended=0;         // shove throw ditto. 14-1-01. (was across.)
  shovetimb_wide:extended=0;          // timber width ditto   16-5-01.
  shovetimb_crab:extended=0;          // timber shove crabwise.  0.78.c 01-02-03.

  bontimb:integer=0;          // number of bonus timbers 0.76.a 23-10-01.
  rjcode:integer=0;           // plain track rail joints code, 0=normal, 1=staggered, -1=none (cwr).

  nine_foot:boolean=False;      // was True pre 0.93.a (9ft timbering was default).
  eight_foot_six:boolean=True;  // 0.93.a 8ft-6in timbering default

  gaunt:boolean=False;                //^^^ 0.93.a
  gaunt_offset_in:extended=12.0;      //^^^ 0.93.a default gaunt offset 1ft.
  gaunt_curvature:extended=0;         // 217b  mm^-1  0=straight

  half_diamond:boolean=False;     // 0.77.a 19-8-02..
  fixed_diamond:boolean=True;
  hd_proto_timbering:boolean=False;       // 215a    was True

  hd_switch_timbering:boolean=False;  // 213a

  auto_diamond:integer=0;
  hd_vcheck_rails:integer=0;
  hd_timbers:integer=0;

  tandem_timb:integer=0;     // 0=normal  1=for 1st ds tandem turnout   2=for second ds tandem turnout

  tradius_is_straight:boolean=False;  //^^^ 0.93.a

  timbinc:extended=6.0;   // timber length increments.

  mouse_now_x:extended=0;
  mouse_now_y:extended=0;

  mouse_label_string:string='';

  measure_org_x:extended=0;
  measure_org_y:extended=0;

  prev_pad_click_X:integer=-1;      // saved mouse_down pad positions...
  prev_pad_click_Y:integer=-1;      // 0.93.a init -1 invalid for check

  pad_click_X:integer=-1;       // 0.93.a init -1 invalid for check
  pad_click_Y:integer=-1;

  user_popup_X:integer=-1;   // 213a  -1 = use defaults
  user_popup_Y:integer=-1;

  popup_X:integer=4;      // default pad locations for the selection popup menu.
  popup_Y:integer=300;

  backdrop_bmp:TBitmap;             // backdrop.
  offdraw_bmp:TBitmap;              // for off-screen refresh.

  wait_cancel_clicked:boolean=False;

  outline_extensions:boolean=True;  // outline extensions. (needed here for DXF 3-D).

  notch_angle:extended=0;
  tb_roll_percent:extended=0;       // 0.76.a 13-5-02 timber rolling offset (%).

  gaunt_sleeper_mod_in:extended=12.0;   // 0.93.a ex 0.81  extend gaunt sleepers to match default offset.

  omit_swfj_marks:boolean=False;    // 0.79.a  25-02-03
  omit_swrj_marks:boolean=False;
  omit_skj_marks:boolean=False;
  omit_wj_marks:boolean=False;
  omit_vj_marks:boolean=False;

  omit_tsxj_marks:boolean=False;    // 227a
  omit_msxj_marks:boolean=False;    // 227a

  omit_kx_marks:boolean=False;

  omit_tspt_marks:boolean=False;    // 227a  plain track joints, also for turnout approach and exit track
  omit_mspt_marks:boolean=False;    // 227a  plain track joints, also for turnout approach and exit track


  retpar_i:integer=0;  // moved 0.79.a
  peg_code:integer=0;  // moved 0.79.a  // reset peg on rail end.

  hide_name_labels:boolean=False;   // 0.82.b

  output_diagram_mode:boolean=False;            // 0.91.d
  output_include_boundaries:boolean=False;      // 0.91.d
  output_include_trackbed_edges:boolean=False;  // 217a
  output_show_points_mark:boolean=False;        // 0.91.d


  print_now_bang:boolean=False;       // 0.93.a

  beginner_counter:integer=0;         // 0.93.a

  create_image_width_dots:integer=2600;    // 0.93.a
  create_image_height_dots:integer=1800;   // 0.93.a
  create_image_dpi:extended=600;           // 0.93.a

  classic_templot:boolean=True;            // 0.93.a   default was False


  bgnd_clicked_in_quick_mode:boolean=False; // 0.93.a

  t55_counter:integer=0;  // moved here 0.93.a

  pad_view_counter:integer=0;   // 0.91.c  // moved here 0.93.a
  ewf_counter:integer=0;        // 214a
  running_counter:integer=0;    // 212a   time since startup (in 200ms intervals, 5 counts per second)

  modal_form_count:integer=0;                // 212a Wine bug
  modal_form_array:array[1..12] of TForm;    // 212a Wine bug       up to 12 modal forms nested !!!
  showing_message:boolean=False;             // 212a Wine bug
  showing_dialog:boolean=False;              // 212a Wine bug


  f7_beginner:boolean=False;  // 215a

  toolbars_2rows:boolean=True;   // 217a

  mouse_shift_sync_wanted:boolean=False;    // 219a  ..
  mouse_rotate_sync_wanted:boolean=False;

  splitting_for_tangential:boolean=False;    // 223c

  custom_switch_opening:extended=4.25;    // 232c  inches full-size  4.25"

  normal_chair_key_max_offset:extended=1.5;      // 238a  was 1.75       233a  inches full-size  1.5" (key 6" long projects 2.5" from chair jaw 4" wide)
  cot_chair_key_max_offset:extended=0.75;        // 555a MW

  fw_modify_for_gw:extended=0;  // 239a modify check flangeway for gauge-widening    3D chairing only -- no effect in 2D

  slider1_str:string[4]='S1'; // 1st slider on timber S1 244a...
  slider2_str:string[4]='';   // 2nd slider on timber
  slider3_str:string[4]='';   // 3rd slider on timber
  slider4_str:string[4]='';   // 4th slider on timber
  slider5_str:string[4]='';   // 5th slider on timber

  want_timbers_back_on:boolean=True;  // 237c

  show_bgnd_templates:boolean=True;   // 237c
  show_group_templates:boolean=True;  // 237c
  show_brick_templates:boolean=True;  // 237c

  shift_store_count:extended=15.0;   // 241d  at 4mm/ft scale
  shift_store_x:extended=0-15.5;     // 241d  15.5" back multi spacing

  procedure delete_to_current_popup_entry_click(no_alert:boolean);  // moved here 215a for make_slip

  procedure add_reminder_click(index:integer);     // 216a
  procedure edit_reminder_click(index:integer);    // 216a
  procedure remove_reminder_click(index:integer);  // 216a
  procedure reminder_colour_click(index:integer);  // 216a

  procedure do_toolbars;   // 217a

  procedure widen_centres_18in(which:integer);      // 218e
  procedure reduce_centres_18in(which:integer);     // 218e

  procedure zoom_fit_control_template;  // 223c

  procedure do_hi_colour_schemes(i:integer);  // 224a

  procedure t2_swap;

//===================================================================================

implementation

{$BOOLEVAL ON}

{$R *.lfm}

uses

  ShellAPI, Math, Printers, FileCtrl,

  control_room, grid_unit, switch_select, help_sheet, alert_unit, math_unit,
  xing_select, entry_sheet, info_unit, print_unit, gauge_unit, keep_select,
  metric_unit, preview_unit, colour_unit, calibration_unit,
  chat_unit, plain_track_unit, dxf_unit, chairs_unit,
  bgnd_unit, panning_unit, shove_timber, action_unit,
  mint_unit, enter_timber, wait_message, edit_memo_unit, jotter_unit,
  rail_options_unit, print_settings_unit, print_now_box, startup_unit, bgkeeps_unit,

  export_unit, platform_unit, math2_unit,
  check_diffs_unit, image_viewer_unit, mouse_colour_unit, file_viewer, prefs_unit,
  map_loader_unit, trackbed_unit, make_slip_unit, create_tandem,
  bitmap_viewer_unit, track_spacing_unit,
  detail_mode_unit, gaps_unit, lib_unit, intersect_unit, create_y_turnout,
  search_unit, mw_unit, brick_unit, heave_chairs, slider_unit, date_unit;


const

  generator_help_str:string='      `0generator  functions`9'
  +'||The functions in the `0GENERATOR`1 menu are sometimes confusing for inexperienced Templot users. They are not intended for use in track design.'

  +'||The settings in the `0GENERATOR > GENERATOR SETTINGS >`1 menu items provide low-level access to the template generator engine in Templot.'
  +'||These settings can be changed to assist your use of Templot, for example to reduce screen clutter, to speed up screen refresh for large track plans,'
  +' to control the level of detail on printed construction templates, to control the contents of exported files, etc.'

  +'||After making a change to these settings the control template will change immediately, and all subsequent templates stored on the background will also reflect the change.'
  +' The change will also apply to templates when displayed in the Storage Box.'

  +'||To apply any changes retrospectively to existing background templates, click the `0GENERATOR > REBUILD`1 menu items. You will almost always want to do this before using any output or export functions.'

  +'||rp.gif Do not use these `0GENERATOR SETTINGS`1 to apply design details for your track plan. The generator settings are not intended for that and changes to them are not saved in your template data files.'

  +'||green_panel_begin'
  +'tree.gif To make track design changes use the settings in the `0GAUGE`1, `0TEMPLATE`1, `0REAL`1, `0GEOMETRY`1, `0ACTION`1, `0DO`1, `0TOOLS`1, `0GROUP`1, menus.'
  +'||For example, to remove timbering from the control template (e.g. for an ash-pit), click the `0REAL > TIMBERING > NO&nbsp;TIMBERING`1 menu item.'
  +'green_panel_end';


  timbering_help_str:string='      `0Timbering  Sizes  and  Layout`9'

    +'||The timbers used in pointwork normally have lengths increasing in fixed 6 inch steps (UK practice). If a timber is too short to'
    +' provide the minimum distance beyond the rail at each end, a timber 6 inches longer is used instead. Consequently, the timbering'
    +' can be arranged in two ways - CENTRALIZED, or IN-LINE.'

    +'||Centralized timbering means that the rails are centrally placed on each timber, with the result that the stepped lengths are less'
    +' noticeable.||In-line timbering has all the timber ends on the main-road side of the turnout arranged in a neat line,'
    +' with the stepped ends all on the turnout-road side. This only makes sense if you are using SQUARE-ON timbering through'
    +' the crossing, and gives the turnout a modern "neat and tidy" look.'

    +'||With the older-style EQUALIZED arrangement, centralized timbering looks more in keeping.'

    +'||To change between these styles, select the|REAL > TIMBERING > EQUALIZED INCREMENTAL, EQUALIZED CONSTANT or SQUARE-ON menu items.'

    +'||If required the 6" step size can be changed to other step sizes according to your prototype practice. Click the REAL > TIMBERING > TIMBER LENGTH INCREMENTS menu options.'
    +' If the GRADUAL (NO STEPS) option is selected the timber lengths are infinitely variable and all are arranged to be simultaneously in-line and centralized.'
    +' Consequently the CENTRALIZED and IN-LINE options are not then available. This neat effect can be modified by using the REAL > SHOVE TIMBERS functions as required.'

    +'||Templot also provides a variable amount of timber randomizing, both in the positioning of the timber ends and the angle at which the timbers'
    +' are aligned across the track. Experiment by changing the values to get a realistic slight variation for standard gauge or a complete "crazy-track"'
    +' effect for industrial and narrow-gauge lines.'

    +'||Swapping between IN-LINE and CENTRALIZED resets the randomizing to zero each time.'

    +'||Be aware that when randomizing is used every re-draw produces a fresh randomized effect. Background templates are frozen between each REBUILD,'
    +' but you should make as many identical printed templates as you will need all in one Templot session, as there is no way to save the exact timbering layout in your template data files.'
    +' When reloaded via your storage box the template will be redrawn with a fresh randomized timbering layout.'
    +' (When templates are exported in DXF file format the exact timbering layout is included in the file.)'

    +'||As an alternative to randomizing, some variation in timbering can be introduced manually using the shove timber functions. Select the REAL > SHOVE TIMBERS menu item and then click the ?HELP button for more information.';

  helpkck_gen_str:string='      `0About  K-crossings`9'
   +'||A K-crossing is also sometimes called an obtuse crossing or an elbow crossing. Two K-crossings are used at the centre of a diamond-crossing formation, one in each rail.'
   +'||There are two types of K-crossing, fixed and movable. Movable K-crossings are used for crossing angles flatter than 1:8 in straight track, and for sharper angles in curved track.'
   +' In a movable K-crossing the diamond point rails move into contact with the stock rails in a similar way to ordinary switch blades. A diamond-crossing with movable K-crossings is sometimes called switch-diamond.'
   +'||If the REAL > K-CROSSING OPTIONS > AUTOMATIC menu option is selected, Templot will set the type of K-crossing to movable if the crossing angle is flatter than 1:8 and fixed otherwise.'
   +'||You may need to override the automatic setting on curved track, according to the following rules:'

   +'||In radius down to:   the flattest angle for a fixed K-crossing is:'

   +'| 60 chains ( 3960ft )........1:8'
   +'| 30 chains ( 1980ft )........1:7.75'
   +'| 20 chains ( 1320ft )........1:7.5'
   +'| 15 chains ( 990ft )..........1:7.25'
   +'| 12 chains ( 792ft )..........1:7'
   +'| 10 chains ( 660ft )..........1:6.5'
   +'| below 10 chains............1:6'

   +'||This information is dated 1943 for the GWR, and similar rules can be assumed for other companies. However, in models we often need to use sharp curves to represent the easier curves of the prototype.'
   +' In this circumstance the choice of K-crossing type should be based on the known or likely prototype radius, not the full-size equivalent of the model radius. Otherwise nearly all the K-crossings'
   +' on the model would be movable, which is not typical of the prototype where the majority of K-crossings are fixed.'

   +'|-----------'
   +'||Check rails (guard rails) are used only for fixed K-crossings in which the diamond point rails are fixed. Check rails are not required for movable K-crossings because the wheels see no break in the rail.'
   +'||K-crossing point rails are blunted to a tip width 1/8" less than the corresponding V-crossing blunt nose, which can be set by clicking the REAL > CUSTOMIZE V-CROSSING > BLUNT NOSE... menu item.'

   +'|-----------'
   +'||Click ABOUT DIAMOND-CROSSING TIMBERING below for more information.'
   +'||For a diagram and further notes explaining the dimensioning of K-crossings, see "Real Track" in the Templot Companion pages on the Templot web site at  85a.uk/templot/companion .';

  helpkck_timbering_str:string='      `0Timbering  of  Diamond-Crossings`9'
   +'||For all diamond-crossings timbering is equalized to a centre-line linking the V-crossings.'

   +'||For bullhead diamond-crossings (except when shorter than 1:5.5) there is a single timber at the centre datum position, for both fixed and movable K-crossings. In many cases this timber is widened to 14".'
   +' When using the TOOLS > MAKE DIAMOND-CROSSING and TOOLS > MAKE LADDER CROSSOVER functions, this centre timber will be duplicated and overlapped on the two half-diamond templates.'
   +' Use the REAL > SHOVE TIMBERS functions to omit one of them and widen the other.'

   +'||For flat-bottom diamond-crossings, there is a centre-timber only in the case of fixed K-crossings (except when shorter than 1:5).'
   +' For movable K-crossings two timbers are used instead, with a space between them at the centre for the point linkages.'

   +'||Because the K-crossing point rails need to be supported on a timber at their tips, if you are using overscale flangeway gaps it is necessary to modify the timber positions from the prototype spacings.'
   +' Click the REAL > TIMBERING > HALF-DIAMOND TIMBERING > TIMBERING AS MODEL menu option to do this. If you are using exact-scale or near exact-scale flangeways (e.g. S4/P4 or S7), select instead the'
   +' REAL > TIMBERING > HALF-DIAMOND TIMBERING > TIMBERING AS PROTOTYPE menu option.'

   +'|-----------'
   +'||Click ABOUT K-CROSSINGS below for more information.'
   +'||For a diagram and further notes explaining the dimensioning of diamond-crossings, see "Real Track" in the Templot Companion pages on the Templot web site at  85a.uk/templot/companion .';

    help_rail_str:string='php/701    `0Rail  Types  and  Section  Dimensions`9'
   +'||All dimensions should be entered in full-size prototype `0inches`3.'
   +'||Alternatively, if you are using a non-scale rail section, enter the actual model dimensions of the rail in mm, prefixed with a letter s.'
   +' For example, if the rail head is 1.2 mm wide, enter s1.2 which will then be converted to the prototype equivalent in inches at your current model scale.';

  marker_mapping_help_str:string='      `0Using  Marker  Colours  and  Mapping  Colours`9'
   +'||Marker and mapping colours allow individual templates or groups of templates to be displayed and printed in different colours. This is useful when templates are being superimposed,'
   +' or when it is desired to have different areas of the track plan in different colours. For example, the main running lines might be in one colour, sidings and yards in another colour,'
   +' and off-stage storage sidings in a third colour.'

   +'||"Marker colour" is the term used for a colour which applies primarily to the trackpad and sketchboard display on the screen.'
   +'||"Mapping colour" is the term used for a colour which applies primarily to the print and PDF output.'

   +'||Colours for the screen and printing are set independently because some colours which are usable on the screen are not suitable for printing templates (white, yellow, pale pastel colours, etc.).'

   +'||Every stored template has an individual marker colour in which it can be displayed on the trackpad,'
   +' and an option setting for whether this colour should be used instead of the normal colours which are being used for background templates on the trackpad.'
   +' The pre-set marker colour is Red, and the option setting is Off, i.e. the marker colour is not actually used until this option setting is changed for this template.'

   +'||Likewise, every stored template has an individual mapping colour in which it can be printed,'
   +' and an option setting for whether this colour should be used instead of the normal colours which are being used for printing background templates.'
   +' The pre-set mapping colour is Magenta-pink, and the option setting is Off, i.e. the mapping colour is not actually used until this option setting is changed for this template.'

   +'||Marker and mapping colours and these option settings are part of the template specification and are included in template data .box files when templates are saved.'

   +'||To change the colours and options for a single background template, click on the template and then on its pop-up menu select the TEMPLATE COLOURS menu items.'
   +' Changing the marker or mapping colour automatically selects the option to use the relevant colour.'

   +'||To change the colours and options for a group of templates (so that they are all displayed in the same colour), first select the group. Then click the GROUP > GROUP SELECT > TEMPLATE COLOURS FOR GROUP menu items.'
   +'||N.B. PLEASE BE AWARE that a selected group of templates is normally displayed in the GROUP COLOUR. The templates will not appear in the chosen marker colour until the group is de-selected (GROUP > GROUP SELECT > GROUP SELECT NONE menu item).'

   +'||When a number of templates are being displayed in a given marker colour, it is possible to select all those templates as a group by clicking the GROUP > GROUP SELECT > SELECT BY MARKER COLOUR... menu item.'
   +' In this way the marker colour for the whole group can be changed.'

   +'||Handy Hint:'
   +'|It will often be useful to maintain a correlation between coloured areas of the track plan and your remembered groups (GROUP > GROUP SELECT > REMEMBER THIS GROUP menu items).'
   +' There is no automatic link between marker colours and remembered groups, because only you know what the colours signify. It is possible to have every template on the plan in a slightly different colour,'
   +' whereas the number of remembered groups is limited to 8.'

   +'||The way in which the marker colours are actually used in displaying the background templates is set in the TRACKPAD > TRACKPAD BACKGND TEMPLATES COLOURS menu options. You can choose whether these colours should apply to the rails, timbers, or both.'
   +' It is also possible to use the mapping colours instead as a means of previewing the printed output. Changing these settings has no effect on templates which have not had their option setting changed to use their marker or mapping colours.'

   +'||The way in which the mapping colours are actually used in printing background templates is set in the PRINT > PRINTED DRAWING OPTIONS > COLOUR OPTIONS menu options.'
   +' You can choose whether these colours should apply to the rails, timbers, or both. This will often be determined by the current printing size and likely consumption of coloured ink.'
   +' Mapping colours do not apply to any timber infill or rail infill. When mapping colours are used for the rails the rail infill colour is set to grey.'
   +' It is also possible to use the marker colours instead as a means of printing the track plan in the same colours as those in which it is being displayed on the screen.'
   +' Changing these settings has no effect on templates which have not had their option setting changed to use their marker or mapping colours.'

   +'||There is also a SINGLE COLOUR option for printing which overrides all other colour settings and prints the entire track plan in a single colour of your choice.'
   +' Finally there is an OPTIONS > BLACK RAIL-EDGES tickbox on the PRINT PAGES window which overrides all other colour, grey-shade, and print-intensity settings and ensures that the rail-edges are always printed in full black.';

  transition_help_str:string='php/200      `0Transition  Curves  and  Easements`9'
   +'||These are brief notes. For diagrams, tutorials and more information about using transition curves and linking together transition templates, please refer to the Templot Companion pages on the Templot web site or click `0more information online`1 above.'
   +'|------------------------------------'
   +'||For information about the MAKE TRANSITION LINK function which creates a transition curve between two existing templates, click the button below (if present) or click the GEOMETRY > TRANSITION CURVE > ? TRANSITION - HELP menu item.'
   +'|------------------------------------'
   +'||In a transition curve, the curving radius is progressively changed from the 1st or initial radius to the 2nd or final radius within the length of the transition zone.'
   +'||Any track preceding the start point of the transition zone will be curved at the 1st radius. Any track beyond the end point of the transition zone will be curved at the 2nd radius.'
   +'||It is possible for one of the radii to be straight, but not both.'

   +'||An "easement" is a short transition curve in which one end is straight, commonly used to ease the running of rolling stock from straight track to a curve,'
   +' and providing a length in which the superelevation can be ramped up to suit the requirements of the curve.'

   +'||When selecting a transition curve, you have several options for the initial settings, which can be changed subsequently, or you can enter new settings immediately:'

   +'||Selecting C-CURVE SHRINKING TRANSITION retains your existing radius as the larger radius and sets the smaller radius to half of that size in the same direction.'
   +' If the existing radius is straight, the smaller radius is set to 10 chains (scale).'

   +'||Selecting C-CURVE EXPANDING TRANSITION retains your existing radius as the smaller radius and sets the larger radius to double that size in the same direction.'
   +' If the existing radius is straight, a shrinking transition is instead created down to 10 chains (scale) radius.'

   +'||Selecting S-CURVE REVERSE TRANSITION retains your existing radius as one of the radii and sets the other radius to the same size but in the opposite direction.'
   +' If the existing radius is straight, both radii are set to 10 chains (scale) in opposite directions.'

   +'||Selecting EASEMENT FROM STRAIGHT sets the initial radius to straight and retains your existing radius as the final radius.'
   +'||Selecting EASEMENT TO STRAIGHT sets the final radius to straight and retains your existing radius as the initial radius.'

   +'||Before selecting these settings you will normally want to ensure that the fixing peg is at the appropriate end of the template,'
   +' so that the newly modified template remains in alignment with the previous curve.'

   +'||For C-CURVE and S-CURVE transitions, the control template length is divided up as follows: initial radius length = 20%, transition zone length = 60%, final radius length = 20%.'

   +'||For EASEMENTS the transition zone length is set to 2 chains (132ft) (scale), unless this is more than 95% of the length of the control template,'
   +' and the length of the straight section is set to zero.'

   +'||You will probably want to change these settings afterwards to suit your requirements for each situation - see below.'

   +'||Selecting AS PREVIOUS SETTINGS sets a new transition curve with the same radii and length settings that were last used for a transition curve.'
   +' If transition curving is already in force for the control template, this option will have no effect.'

   +'||Selecting NEW TRANSITION SETTINGS... brings up the Templot data entry form on which you can enter your required radii and length settings for the new transition curve.'

   +'||The start and end points for the transition zone section of the curve are indicated by special marks across the track. The transition start mark is a large arrow-head symbol pointing into the transition zone,'
   +' and the transition end mark resembles a set of "goalposts".'

   +'||To move the transition zone along the track, select the MOVE TRANSITION START mouse action (SHIFT+CTRL-F3) or just press the [ key.'
   +'||To lengthen or shorten the transition zone, select the ADJUST TRANSITION LENGTH mouse action (SHIFT+CTRL-F4) or just press the ] key.'

   +'||The transition radii are adjusted using the same ADJUST CURVING (F6) mouse action as for a constant radius curve.'
   +'||To toggle between adjusting the 1st or 2nd radius, click the triangle symbol on the mouse action panel.'
   +' Or select either of the ACTION > TRANSITION RADIUS OPTIONS menu items (SHIFT+CTRL-F1 or SHIFT+CTRL-F2), or press the - (minus) or = (equals) keys for 1st or 2nd radius respectively. You can do this while the mouse action is in force.'

   +'||(These 1st or 2nd radius selections also apply to other mouse actions such as the ORBIT function CTRL-F5. The BACKSPACE key continues to work normally to repeat a previous mouse action.)'

   +'||If the first radius is positive and the second radius negative, or vice versa, an S-curve effect is achieved. For further explanation of the meaning of a negative radius'
   +' click the GEOMETRY > CURVING DATA... menu item and read the HELP notes.'

   +'||When using the MOVE TRANSITION START and ADJUST TRANSITION LENGTH mouse actions, there are two options for the way the curve is calculated (ACTION > TRANSITION ZONE OPTIONS > menu items).'
   +'||The RADII FIXED (NORMAL) option maintains the 1st and 2nd radii constant, and adjusts the transition alignment between them accordingly.'
   +' The TRANSITION FIXED (ROLL-OUT) option maintains a constant alignment in the transition zone, and adjusts the 1st or 2nd radius accordingly.'

   +'||This setting reverts to the RADII FIXED (NORMAL) option whenever a new transition curve is set.'

   +'||As for the other mouse actions, the way in which the template responds to transition and overall length adjustments is determined by the position of the fixing peg within it.'
   +' Normallly, before making an adjustment, the fixing peg should be moved to a position where you want the template alignment to remain unchanged.'

   +'||In achieving the desired alignment the transition markers may sometimes be moved out beyond the actual extent of the template at one or both ends.'
   +' If this is the case it avoids confusion to re-calculate the transition zone and radii to match the ends of the template.'
   +' This can be done by clicking the GEOMETRY > TRANSITION CURVE > NORMALIZE TRANSITION menu item. The alignment of the template is not affected.'

   +'||A frequent need is to slide a template along a transition curve alignment without disturbing the alignment. This is done using the SNAKE (CTRL-F6) mouse action. Compare the results with the otherwise similar SLIDE (F9) mouse action.'

   +'||In addition, a transition curve can be combined with a SLEW to give a virtually unlimited range of alignments. For more information about slewing, click the GEOMETRY > SLEW (NUDGE) > ? SLEW - HELP menu item.'

   +'||To enter the radius and transition length settings directly, select the GEOMETRY > CURVING DATA... menu item while the control template contains a transition, or click the figures showing on the lower line of text in the MOUSE ACTION panel.'

   +'||When changing from a transition to a constant-radius template, GEOMETRY > CONSTANT RADIUS menu item, the new constant radius will be the radius at the current position of the fixing peg within the transition template.'

   +'||Bear in mind when using transitions that a long transition curve will significantly extend redraw times because of the amount of calculation needed to draw it.'
   +' If you are using a slow processor you will want to keep transition zones as short as possible.'

   +'||For more information about the transition mathematics, see the help notes for the PROGRAM > EXPERT > TRANSITION MATHS > items on the PROGRAM PANEL menus.';


  slew_help_str:string='      `0Slewing`9'
    +'||These are brief notes. For diagrams, tutorials and more information about using the slewing functions, please refer to the Templot Companion pages on the Templot web site at  85a.uk/templot/companion .'
    +'|-----------------------------------------------------------'
    +'||The slewing function shifts a section of the track sideways from its normal position. There is a section between the slewed and unslewed portions called the SLEWING ZONE in which the amount of SLEW (sideways shift) is progressively increased'
    +' so that the slewed and unslewed portions are joined by a smooth reverse curve.'
    +'||Slewing is a useful means of nudging the track into an alignment to fit the existing site, but should normally be used for plain track only. A turnout placed in the slewing zone is likely to be distorted and/or difficult'
    +' to construct, and Templot will be unable to warn you about the minimum radius within it.'
    +'||A common use for slewing is to increase the space between double-track running lines to make room for a fixed obstruction such as a bridge girder, or perhaps to accommodate an island platform.'

    +'||Unlike a transition curve, slewing introduces some distortion into the rail lengths and sleeper spacings. This will be negligible if slewing is used as intended to make small adjustments to the alignment.'
    +' If you use the slewing functions to generate a sharp S-curve some noticeable distortion is inevitable. It is better to build up such curves with transitions whenever possible.'

    +'||While slewing is in force a reminder notice appears on the trackpad. This shows in blue normally, but will change to yellow if Templot judges the slew to be excessive.'

    +'||There are two slew MODES, using different maths for the reverse curve. Mode 1 makes the centre reverse curve as gentle as possible to avoid buffer-locking problems and is suitable for slews in large radius curves or straight track.'
    +'||Mode 2 eases the radius at each end of the slewing zone and is therefore more suitable for slews in sharply curving track. But it does this at the expense of a more pronounced reverse curve at the centre of the slewing zone.'

    +'||For Mode 2 slews there is an adjustable SLEW FACTOR which permits fine tuning of the slewing radii by mouse action, select the ACTION > MOUSE ACTIONS CONTROL > ADJUST MODE 2 SLEW FACTOR menu item. (There is no slew factor for slew mode 1.)'

    +'||Slewing is enabled by selecting the GEOMETRY > SLEW (NUDGE) > SLEW USING MODE menu items, and can be cancelled without losing the current settings by selecting the GEOMETRY > SLEW (NUDGE) > CANCEL SLEW menu item.'

    +'||The slewing settings can be adjusted by the mouse actions only while slewing is in force.'

    +'||Note that slewing does not change the track radius (except within the slewing zone). The slewed and unslewed sections are of the same radius, and by zooming out you can see the two radial centre marks, one for each section.'
    +'||If you want the radius of the slewed section to differ, you can combine a slew with a transition curve. By careful adjustment of the starting points and lengths of the transition curve and slewing zone, it is possible to make'
    +' the slewed and unslewed sections concentric.'

    +'||As for the other mouse actions, the way in which the template responds to the slewing adjustments is determined by the position of the fixing peg within it.'
    +' Please experiment fully with the various settings before finalising a template as there are a number of interesting effects.'

    +'||A frequent need is to slide a template along a slewed alignment without disturbing the alignment. This is done using the SNAKE (CTRL-F6) mouse action. Compare the results with the otherwise similar SLIDE (F9) mouse action.';



  group_link_help_str:string='      `0Linking  a  Group  to  the  Pegging  Notch`9'
   +'||Clicking the PEG / ALIGN TOOLS > NOTCH UNDER BACKGROUND PEG menu item on the pop-up menu for a background template which is a member of a GROUP gives you the option of "linking" the whole group to the pegging notch.'
   +'||Activating this function means that the selected group of templates will be linked to subsequent movements of the pegging notch.'
   +'||This means for example that subsequently clicking the GEOMETRY > NOTCH > NOTCH UNDER PEG menu item (or pressing the DIVIDE key) will shift the whole group into alignment with the control template.'
   +'||Occasionally Templot may align the group of templates facing the wrong way. This is easily corrected by clicking the GROUP > ROTATE GROUP 180 DEGREES menu item (or pressing SHIFT-F6).'
   +'||While this function is in force a warning label appears on the trackpad, and this function can be cancelled by clicking the label.'

   +'||Handy Hints :'
   +'||A group of template(s) must be selected before this function can be activated (by clicking on one of them and then NOTCH UNDER BACKGROUND PEG).'
   +'||Group moves made this way can be undone by repeatedly clicking the GEOMETRY > NOTCH > CYCLE NOTCH menu item (CTRL+C).'
   +' But it is wise to save the group templates in a data file before using this function, in case of errors (SAVE GROUP in the STORAGE BOX menus).'
   +'||For static moves this function provides an easier alternative to the GROUP > SHIFT GROUP ONTO NOTCH function,'
   +' and also permits direct pegging between background templates without affecting the control template (click the PEG / ALIGN TOOLS > NOTCH UNDER BACKGROUND PEG menu item for the background template onto which you wish to peg the group).'
   +'||In conjunction with the GEOMETRY > NOTCH > LINK NOTCH TO TEMPLATE AT PEG function, a whole group of templates can be maintained in alignment with the control template while it is being adjusted by mouse action.'
   +'||N.B. Remember to cancel this function as soon as you have finished using it, to avoid making unexpected changes to the group.';

  line_thick_help_str:string='      `0Setting  Printed  Line  Thicknesses`9'
    +'||The settings in the OUTPUT > LINE THICKNESS menu options determine the thickness (width) of the lines which make up the drawing on printed templates.'

    +'||Click the THIN LINES menu option to print all lines on your templates at the minimum thickness which is possible on your printer (or not less than 0.02 mm).'

    +'||Click the NORMAL LINES menu option to use the following settings, or the nearest possible on your printer:'
    +'|Grid lines 0.02 mm or minimum'
    +'|Trim margin lines 0.22 mm'
    +'|Background shapes 0.22 mm'
    +'|Picture shape borders 0.02 mm or minimum'
    +'|Rail-edge lines 0.16 mm'
    +'|Timber outlines 0.16 mm'
    +'|Track centre-lines lines 0.02 mm or minimum'    // 0.79.a
    +'|All other marks 0.16 mm'
    +'|(These slightly odd dimensions have been chosen to give as near as possible equivalent results on different makes of printer.)'

    +'||Click the THICK LINES menu option to use the following settings, or the nearest possible on your printer:'
    +'|Grid lines 0.16 mm'
    +'|Trim-margin lines 0.5 mm'
    +'|Background shapes 0.4 mm'
    +'|Picture shape borders 0.16 mm'
    +'|Rail-edge lines 0.3 mm'
    +'|Timber outlines 0.3 mm'
    +'|Track centre-lines lines 0.16 mm'   // 0.79.a
    +'|All other marks 0.3 mm'

    +'||Or click the SET ANY LINE THICKNESS... menu option to make any other line thickness settings which you require.'

    +'||If the SIZE-ADJUST LINE THICKNESS menu option is ticked, Templot will scale down some of these line thicknesses in accordance with any reduced size setting for printing in the PRINT > ENLARGE/REDUCE SIZE menu options.'
    +' The grid lines and trim-margin lines are not affected.'
    +'||If the SIZE-ADJUST LINE THICKNESS menu option is unticked, all lines will be printed at the set thickness, without regard to any reduced size setting for printing in the PRINT > ENLARGE/REDUCE SIZE menu options.'

    +'||For Picture Shape borders, the set line thickness applies only if the image is being printed. If the OUTLINES ONLY option is selected the outline is printed at the Background Shape line thickness.'

    +'||N.B. If you are using an old-style dot-matrix impact printer (or a pen plotter), Templot draws all lines 1 ink-dot thick, and the settings which you make'
    +' here will have no effect until you change to a non-impact printer.'

    +'||Handy Hints:'
    +'||For the final construction templates printed using Best or Letter-Quality or Photo print quality, the THIN LINES option will give the most precise result.'

    +'||For trial prints using the Economy or Draft setting, the NORMAL LINES option is more prominent.'

    +'||The actual drawn line thickness (line width) may vary from these settings and is determined by the dot size and dpi (dots per inch) resolution for your printer.'

    +'||These settings have no effect on templates exported in DXF file format. The way the templates are rendered in your CAD software is determined only in that program.'

    +'||These line thickness settings affect only the printed output, they have no effect on the screen drawing. To change the appearance of'
    +' the drawing on the screen, select the TRACKPAD menu items.';

  trim_help_str:string='      `0Setting  Trim  Margins`9'
    +'||Templot prints trim margins (normally in magenta-pink) around all four edges of each printed page comprising your template or track plan.'

    +'||Trimming is necessary because very few printers can print to the extreme edge of the sheet of paper, or position it with great accuracy before printing on it.'
    +'||By trimming each page along margin lines which are printed as part of the drawing image you are assured that the pages will fit together accurately.'
    +'||Templot normally sets the trim margins to use nearly all of the printable area on each page. However, because printers and paper sheet sizes vary,'
    +' this usually means that the trimmed page dimensions are not round figures and do not match the printed grid lines.'

    +'||If you wish you can set the trim margins to your own requirements to suit the paper and printer in use. For example, if you are printing on paper which has been punched'
    +' with tractor-feed or ring-binder holes you can increase the margins to avoid printing ink through the holes onto the printer roller.'
    +'||You might also want to change the trim margins so that the trimmed page dimensions are in round figures or match the grid lines. This is useful if you want to mix'
    +' pages printed on different printers or different paper sizes.'

    +'||Because of the traditional paper sizes in use, finding a convenient combination of trimmed page size and grid spacing is not as straightforward as it might seem.'
    +' Here are some suggested dimensions for A4 and US-Letter paper:'

    +'||Grid spacings: 20 mm      trim to: 180 mm x 240 mm'
    +'|Grid spacings: 20 mm      trim to: 180 mm x 260 mm (A4 only)'
    +'|Grid spacings: 30 mm      trim to: 180 mm x 240 mm'
    +'|Grid spacings: 30 mm      trim to: 180 mm x 270 mm (A4 only)'
    +'|Grid spacings: 48 mm      trim to: 192 mm x 240 mm'
    +'|Grid spacings: 60 mm      trim to: 180 mm x 240 mm'
    +'|Grid spacings: 90 mm      trim to: 180 mm x 270 mm (A4 only)'
    +'|Grid spacings: 62.5 mm   trim to: 187.5 mm x 250 mm'
    +'|Grid spacings: 1.5"          trim to: 7.5" x 10.5" (A4 only)'
    +'|Grid spacings: 2.5"          trim to: 7.5" x 10"'

    +'||To set the trim margins and trimmed page size, click the|PRINT > TRIM MARGINS > SET CUSTOM TRIM MARGINS... menu item.'
    +'||To set the grid spacings, click the PRINT > PRINTED GRID OPTIONS > GRID SPACINGS... menu item.'

    +'||It is also possible to change from the standard "brick-bond" pattern of staggered alternate rows of pages to a more conventional in-line (rectilinear tiled) pattern.'
    +' This makes it easier to match the trimmed page size to the grid lines or to use different sizes of paper in a single track plan, but loses the advantage of increased alignment accuracy which the staggered pattern provides.'
    +' Select the PRINT > TRIM MARGINS > ALTERNATE ROWS menu options as required.'

    +'||Click the PRINT > TRIM MARGINS > SHOW MAX PRINTABLE AREA menu item to show an outline around page a/1 (the bottom-leftmost page on the screen) showing the maximum available'
    +' printable area for the current paper size and printer settings. This is a useful guide when setting custom trim margins. Note that this area is normally less than the actual paper sheet size.'

    +'||When printing user the banner/roll paper option, any custom top margin and page length settings are ignored.'

    +'||Handy Hints:'
    +'|Remember that the TOP trim margin corresponds to the left edge of the page outline as shown on the screen, and the LEFT trim margin corresponds to the bottom edge of the page outline as shown on the screen.'
    +'||If the drawing is not conveniently placed between the page margins, the page origin can be moved as an alternative to changing the trim margins.'
    +' Click either the PRINT > PAGE ORIENTATION / ORIGIN > SET PAGE ORIGIN... menu item to enter the new page origin position directly,'
    +' or the ACTION > MOUSE ACTIONS:PAD > MOVE PAGE ORIGIN menu item (SHIFT+CTRL-F10) to move the page origin with the mouse.'

    +'||Likewise when printing the entire trackpad drawing at a reduced size, the printing size can be changed by mouse action to achieve a convenient fit to the pages.'
    +' Click the ACTION > MOUSE ACTIONS:PAD > ADJUST PRINT SIZE menu item. The page outlines on the trackpad will change accordingly.';

  irregular_help_str:string='    `0Irregular Diamond Crossings`9';

  modify_rebuild_str:string='||These changes cannot be undone. If you may want to revert to this template, cancel this and create an unused copy of it first (click the CREATE UNUSED COPY menu item),'
    +' which you can subsequently COPY TO BACKGROUND on the Storage Box if necessary.'
    +'||For more information, click the ? HELP button on the Storage Box, and read about the OPTIONS > MODIFY ON REBUILD menu options.'

    +'||If you simply want to change the appearance of this template by rebuilding it with changed generator settings, cancel this and click the REBUILD menu item instead.'
    +'||Are you sure you want to modify this template now?';

  gaunt_offset_help_str:string='    `0gaunt  offset`9'
    +'||Enter a dimension in full-size prototype INCHES for the amount by which one set of rails in gauntletted track is displaced from the other set of rails.'
    +'||Changing this dimension will have no effect unless or until the control template is a `0gaunt turnout`3.'
    +'||To convert a normal turnout to a gaunt turnout, click the `0template > gaunt options > gaunt turnout`1 menu item.'
    +'||green_panel_begin tree.gif The V-crossing from a gaunt turnout is useful as a partial template in formations such as a tandem turnout,'
    +' allowing the turnout radius to be adjusted independently of the crossing angle.'
    +'||Changing the gaunt offset will modify the gaunt turnout radius.'
    +'||If an invalid dimension is entered, the gaunt offset will be adjusted to fit. The modified dimension is shown in the template info panel.'
    +'||For more information about using gaunt turnouts click the `0more information online`1 link above.green_panel_end';

  gaunt_radius_help_str:string='    `0gaunt  turnout  radius`9'
    +'||Enter a dimension in mm for the turnout radius of a gaunt turnout.'
    +'||This radius applies to the equivalent straight turnout before it is curved. A negative radius is not valid.'
    +'||Changing this dimension will have no effect unless or until the control template is a `0gaunt turnout`3.'
    +'||To convert a normal turnout to a gaunt turnout, click the `0template > gaunt options > gaunt turnout`1 menu item.'
    +'||green_panel_begin tree.gif The V-crossing from a gaunt turnout is useful as a partial template in formations such as a tandem turnout,'
    +' allowing the turnout radius to be adjusted independently of the crossing angle.'
    +'||Changing the gaunt turnout radius will modify the gaunt offset.'
    +'||For more information about using gaunt turnouts click the `0more information online`1 link above.green_panel_end';

  gaunt_sleeper_help_str:string='    `0modified  sleeper  length<BR>    for  gauntletted  track`9'
    +'||Enter a dimension in full-size prototype INCHES for the amount by which sleepers on gauntletted plain track should be longer than standard sleepers.'
    +'||This is usually the same dimension as the current gaunt offset, or the next round 6" step beyond. For example, if the current gaunt offset is 10.5", enter 12".'
    +'||Changing this dimension will have no effect unless or until the control template is a `0gaunt turnout`3 which has some `0approach`3 track (for use as gauntletted plain track).'
    +'||To convert a normal turnout to a gaunt turnout, click the `0template > gaunt options > gaunt turnout`1 menu item.';

//______________________________________________________________________________

var
  no_onresize:boolean=False;  // 211b

  mouse_wheel_pan_dir:integer=0;    // 0.91.a  0=east/west  2=north/south   toggled on mousedown

  ignore_key:boolean=False;

  normal_explode_jump:extended=2;     // spot explode factors.
  slow_explode_jump:extended=1.1;

  original_popup_colour:TColor=clBlack;  // 225b

//___________________________________________________________________________________________

procedure Tpad_form.f12_redraw_popup_entryClick(Sender: TObject);

begin
  show_and_redraw(True,False); // no rollback.
end;
//____________________________________________________________________________________________

procedure Tpad_form.print_control_template_menu_entryClick(Sender: TObject);

var
  num_pages_printed:integer;
  str:string;

begin
  num_pages_printed:=print_control_template(False);    // 0.91.d

  if num_pages_printed<>1
     then str:='s were'
     else str:=' was';

  show_modal_message(IntToStr(num_pages_printed)+' page'+str+' sent to the printer.');
end;
//______________________________________________________________________________

procedure Tpad_form.print_entire_pad_menu_entryClick(Sender: TObject);

var
  num_pages_printed:integer;
  str:string;

begin
  if any_bgnd<1
     then begin
            alert_no_bgnd;
            EXIT;            // no background templates
          end;

  print_group_only_flag:=False;

  num_pages_printed:=print_entire_pad(False);    // 0.91.d

  if num_pages_printed<>1
     then str:='s were'
     else str:=' was';

  show_modal_message(IntToStr(num_pages_printed)+' page'+str+' sent to the printer.');
end;
//__________________________________________________________________________________________

procedure Tpad_form.print_group_only_menu_entryClick(Sender: TObject);

begin
  if any_bgnd=0   // 0.82.a
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0   // 0.82.a
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  print_group_only_flag:=True;
  print_entire_pad(False);    // 0.91.d
end;
//___________________________________________________________________________________________

procedure Tpad_form.paper_colour_menu_entryClick(Sender: TObject);

begin
  paper_colour:=get_colour('choose  a  colour  for  the  trackpad  background',paper_colour);
  pad_form.Color:=paper_colour;             //  set screen colour for trackpad.
end;
//_______________________________________________________________________________________

procedure Tpad_form.selection_colour_menu_entryClick(Sender: TObject);

begin
  selection_colour:=get_colour('choose  a  colour  for  group  templates',selection_colour);
end;
//______________________________________________________________________________________

procedure Tpad_form.hover_colour_menu_entryClick(Sender: TObject);

begin
  hover_colour:=get_colour('choose  a  mouse  hover  colour  when  selecting  background  templates',hover_colour);
end;
//__________________________________________________________________________________________

procedure Tpad_form.grid_colour_menu_entryClick(Sender: TObject);

begin
  grid_colour:=get_colour('choose  a  colour  for  the  grid  lines  on  the  pad',grid_colour);
end;
//_______________________________________________________________________________________

procedure Tpad_form.rail_colour_menu_entryClick(Sender: TObject);

begin
  rail_colour:=get_colour('choose  a  colour  for  the  control  template  rail  lines  on  the  pad',rail_colour);
end;
//_________________________________________________________________________________________

procedure Tpad_form.align_colour_menu_entryClick(Sender: TObject);

begin
  align_colour:=get_colour('choose  a  colour  for  the  control  template  radial  end  marks  on  the  pad',align_colour);
end;
//______________________________________________________________________________

procedure Tpad_form.sketchboard_buttonClick(Sender: TObject);

begin
  do_open_source_bang('SKETCHBOARD');  // OT2024
end;
//______________________________________________________________________________

procedure Tpad_form.sketchboard_show_menu_entryClick(Sender: TObject);

begin
  sketchboard_button.Click;
end;
//______________________________________________________________________________

procedure t2_swap;

var
  swap_str,t2_str:string;

  t2t5_list:TStringList;

  // use emergency backup mechanism for T5 swap

begin
  create_backup_file(False);    // ensure ebk files up to date and include latest contol template changes

  Application.ProcessMessages;

  t2t5_list:=TStringList.Create;
  t2t5_list.Clear;
  t2t5_list.Add('from T%');
  t2t5_list.SaveToFile(exe_str+'t2t5.txt');    // if file exists, flags ebk files are for T5 swap, reload without asking
  t2t5_list.Free;


     // background shapes ...

  swap_str:=exe_str+'t2_t5.bgs3';

  DeleteFile(swap_str);   // remove previous if any

  if bgnd_form.bgnd_shapes_listbox.Items.Count>0
     then begin
            if save_all_shapes_to_file(swap_str,0,control_room_form.bgs3_readable_menu_entry.Checked)=False    // readable/compact XML format
               then begin
                      show_modal_message('error1: Sorry, unable to swap background shapes to Templot2.');
                      EXIT;
                    end;
            try
              repeat
                Application.ProcessMessages;
              until FileExists(swap_str)=True;
            except
              show_modal_message('error2: Sorry, unable to swap background shapes to Templot2.');
              EXIT;
            end;
          end;


  on_idle_can_run:=False;
  under_way:=False;
  prog_running:=False;

  t2_str:=exe_str+'templot_2.exe';

  if ShellExecute(0,'open',PChar(t2_str),nil,nil,SW_SHOWNORMAL)<=32
     then begin
            show_modal_message('error: Sorry, unable to start Templot2.');

            on_idle_can_run:=True;
            under_way:=True;
            prog_running:=True;

            EXIT;
          end;

  Application.Terminate;
end;
  //______________________________________________________________________________

procedure Tpad_form.T2_panelClick(Sender: TObject);

begin
    t2_swap;
end;
//______________________________________________________________________________

procedure Tpad_form.T2_panelMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);

begin
  T2_panel.BorderStyle:=bsNone;
end;
//____________________________________________________________________________________________

procedure Tpad_form.trans_colour_menu_entryClick(Sender: TObject);

begin
  trans_colour:=get_colour('choose  a  colour  for  the  control  template  transition  end  marks  on  the  pad',trans_colour);
end;
//_________________________________________________________________________________________

procedure Tpad_form.timber_colour_menu_entryClick(Sender: TObject);

begin
  timber_colour:=get_colour('choose  a  colour  for  the  control  template  timber  outlines  on  the  pad',timber_colour);
end;
//_________________________________________________________________________________________

procedure Tpad_form.guide_colour_menu_entryClick(Sender: TObject);

begin
  guide_colour:=get_colour('choose  a  colour  for  the  control  template  guide  marks  on  the  pad',guide_colour);
end;
//____________________________________________________________________________________________

procedure Tpad_form.timber_infill_colour_menu_entryClick( Sender: TObject);

begin
  timber_infill_colour:=get_colour('choose  a  colour  for  the  control  template  timber  infill  on  the  pad',timber_infill_colour);
end;
//______________________________________________________________________________________

procedure Tpad_form.joint_colour_menu_entryClick(Sender: TObject);

begin
  joint_colour:=get_colour('choose  a  colour  for  the  control  template  rail-joint  marks  on  the  pad',joint_colour);
end;
//________________________________________________________________________________________

procedure Tpad_form.page_outline_colour_menu_entryClick(Sender: TObject);

begin
  page_colour:=get_colour('choose  a  colour  for  the  page  outlines  on  the  pad',page_colour);
end;
//______________________________________________________________________________________

procedure Tpad_form.adjust_curving_menu_entryClick(Sender: TObject);

var
  mouse_str,trail_str:string;

begin

  cancel_adjusts(True);

  if spiral=True
     then begin
            if adjust_trans_rad=2
               then begin
                      mouse_str:='F6  curving 2nd transition radius';
                      action_panel_hint('adjust 1st radius instead'); // 205c
                    end
               else begin
                      mouse_str:='F6  curving 1st transition radius';
                      action_panel_hint('adjust 2nd radius instead'); // 205c
                    end;
          end
     else mouse_str:='F6  curving';

  if spiral=True then trail_str:=captext(nomrad1)+' mm  /  '+captext(nomrad2)+' mm'
                 else trail_str:=captext(nomrad)+' mm';

  mouse_action_selected('F6    adjust  template  curving ...',mouse_str,trail_str);

  curving_mod:=1;       // set up for curving adjust.
end;
//_______________________________________________________________________________________

procedure Tpad_form.adjust_both_menu_entryClick(Sender: TObject);

var
  trail_str:string;

begin
  if plain_track=True
     then begin
            alert(6,'    adjust  both  size  and  curving',
                    'Adjust both size and curving.'
                   +'||This mouse action applies only to turnout and half-diamond templates.'
                   +'||The control template is plain track.'
                   +'||For plain track use `0F4`2 mouse action to adjust the length, or `0F6`2 mouse action to adjust the curving radius.',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);

  if spiral=True then trail_str:=captext(nomrad1)+' mm  /  '+captext(nomrad2)+' mm'
                 else trail_str:=captext(nomrad)+' mm';

  mouse_action_selected('    adjust  both  size  and  curving ...','size  and  curving',trail_str);

  both_mod:=1;                           // set up for adjusting both.

  lock_xing_popup_entry.Enabled:=True;      // enabled for F5..
  lock_switch_popup_entry.Enabled:=True;

  if half_diamond=True
     then begin
            lock_switch_popup_entry.Click;
            switch_modify_mode:=False;
          end
     else unlock_both;

end;
//___________________________________________________________________________________

procedure Tpad_form.swell_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('CTRL-F10    swell  curving  radius ...','CTRL-F10  swell  curving',captext(nomrad)+' mm');
  swell_mod:=1;
end;
//____________________________________________________________________________________

procedure Tpad_form.shift_menu_entryClick(Sender: TObject);

var
  str:string;

begin
  f7_beginner:=(Sender=f7_button);   // 215a

  if f7_beginner=True
     then str:='  /  snap  join'
     else str:='';

  cancel_adjusts(True);

  action_panel_hint('rotate around peg instead'); // 205c

  mouse_action_selected('F7    shift  template  position'+str+' ...','F7  shift  position'+str,' X : '+captext(xshift)+' mm      Y : '+captext(yshift)+' mm');

  shift_mod:=1;

end;
//__________________________________________________________________________________

procedure Tpad_form.slide_menu_entryClick(Sender: TObject);      // SHIFT+F9

      // unlike snake (below), slide works if peg runs along any rail or centre-line.

begin
  cancel_adjusts(True);

  slide_adjust_radius:=False;    // init 244d..
  slide_adjust_centres:=False;

  if (plain_track=False) and (spiral=False)  // 244d
     then begin
            if (ABS(nomrad)<max_rad_test)  // 244d    curved template
               then begin
                      if alert(4,'      SHIFT-F9  slide  template  through  peg',                                       // 244d
                                 '||The control template is curved.'
                                +'||While sliding, do you want the curving radius to be modified by the change in peg offset?'
                                +'||This option will maintain the template on the original radial centre.'
                                +'||This is useful to keep the main roads concentric when sliding the second turnout in a crossover.',
                                 '','','','yes  please  -  adjust  curving  radius   ','no  thanks  -  leave  template  radius  unchanged          ','',0)=4
                         then begin
                                slide_adjust_radius:=True;
                                slide_adust_pegy_start:=pegy;
                                slide_adust_nomrad_start:=nomrad;

                                if alert(4,'      SHIFT-F9  slide  template  through  peg',   // 244d
                                 '||Do you also want the turnout-side (TS) adjacent track centres to be modified accordingly?'
                                +'||This option will allow subsequent double-track from this template to align with previous templates.'
                                +'||This is useful after sliding the second turnout in a crossover.',
                                 '','','','yes  please  -  also  adjust  TS  track  centres  ','no  thanks  -  leave  track  centres  unchanged        ','',0)=4
                                   then begin
                                          slide_adjust_centres:=True;
                                          slide_adust_trtscent_start:=cpi.trtscent_pi;
                                        end;
                              end;

                    end
               else begin           // 244d straight template
                      if alert(4,'      SHIFT-F9  slide  template  through  peg',
                       '||The control template is straight.'
                      +'||Do you want the turnout-side (TS) adjacent track centres to be modified by the change in peg offset?'
                      +'||This option will allow subsequent double-track from this template to align with previous templates.'
                      +'||This is useful after sliding the second turnout in a crossover.',
                       '','','','yes  please  -  modify  TS  track  centres  ','no  thanks  -  leave  track  centres  unchanged        ','',0)=4
                         then begin
                                slide_adjust_centres:=True;
                                slide_adust_pegy_start:=pegy;
                                slide_adust_trtscent_start:=cpi.trtscent_pi;
                              end;
                    end;

          end;

  if peg_rail=0 then peg_rail:=8;     // can't have free peg moving - so default to ms centre-line.

  set_peg_menu_entry.Checked:=True;         // radio item.
  peg_indicator_panel.Caption:='M';         // show him its down to the Mouse.
  peg_code:=20;                             // flag gocalc to put peg on a rail or centre-line.

  mouse_action_selected('SHIFT-F9    slide  template  through  peg ...','SHIFT-F9  slide  through  peg','X : '+captext(0-pegx)+' mm');
  slide_mod:=1;
  redraw(True);                                          // to move the peg to new rail if required
end;
//__________________________________________________________________________________________

procedure Tpad_form.snake_menu_entryClick(Sender: TObject);

      // trail_snake works only if peg on ms-centre-line...

begin
  cancel_adjusts(True);

  peg_rail:=8;                             // switch to ms centre-line.

  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='M';        // show him its down to the Mouse.
  peg_code:=20;                            // flag gocalc to put peg on a rail or centre-line.

  mouse_action_selected('CTRL-F6    snake  template  through  peg ...','CTRL-F6  snake  through  peg','X : '+captext(0-pegx)+' mm');
  snake_mod:=1;
  redraw(True);                                          // to move the peg to the ms-centre-line.
end;
//___________________________________________________________________________________________

procedure Tpad_form.move_ring_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if ring_has_been_shown=False then grid_form.jump_to_centre_button.Click;    // 0.98.a move to centre on first showing

  mouse_action_selected('    move  spacing-ring  tool ...','move  spacing-ring','X : '+captext(rings[0,0])+' mm   Y : '+captext(rings[0,1])+' mm');
  ring_mod:=1;
  show_spacing_rings:=True;     // otherwise won't see it (no cursor).
  ring_has_been_shown:=True;    // 0.98.a
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.adjust_spacing_ring_size_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if ring_has_been_shown=False then grid_form.jump_to_centre_button.Click;    // 0.98.a move to centre on first showing

  mouse_action_selected('    adjust  spacing-ring  inner  diameter ...','spacing-ring  diameter','inner  dia : '+captext(ring_dia)+' mm');
  ringdia_mod:=1;
  show_spacing_rings:=True;     // otherwise won't see it.
  ring_has_been_shown:=True;    // 0.98.a
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.move_ruler_1st_end_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  action_panel_hint('move 2nd ruler end instead'); // 205c

  mouse_action_selected('    move  ruler  tool  1st  end ...','move  ruler  1st  end','X : '+captext(ruler_startx)+' mm   Y : '+captext(ruler_starty)+' mm');
  ruler1_mod:=1;
  show_ruler_tool:=True;     // otherwise won't see it (no cursor).
  redraw_pad(True,False);
end;
//__________________________________________________________________________

procedure Tpad_form.move_ruler_2nd_end_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  action_panel_hint('move 1st ruler end instead'); // 205c

  mouse_action_selected('    move  ruler  tool  2nd  end ...','move  ruler  2nd  end','X : '+captext(ruler_endx)+' mm   Y : '+captext(ruler_endy)+' mm');
  ruler2_mod:=1;
  show_ruler_tool:=True;     // otherwise won't see it (no cursor).
  redraw_pad(True,False);
end;
//_________________________________________________________________________________________

procedure Tpad_form.move_notch_menu_entryClick(Sender: TObject);

begin
  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'A selected group of templates is currently linked to the pegging notch.'
                      +'||This MOVE NOTCH mouse action will unlink the group.'
                      +'||To move a group of templates, use the SHIFT GROUP (SHIFT+CTRL-F7) mouse action instead.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  cancel_adjusts(True);

  notchx:=mouse_x(Round(xmax/2));                 // jump notch to pad centre.
  notchy:=mouse_y(Round(xmax/2),Round(ymax/2));   // don't put this in cycle notch register.
  notch_angle:=0;

  mouse_action_selected('    move  pegging  notch ...','move  notch','X : '+captext(notchx)+' mm   Y : '+captext(notchy)+' mm');
  notch_mod:=1;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.move_pad_origin_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('    move  trackpad  origin ...','trackpad  origin','X : '+captext(zoom_offsetx)+' mm   Y : '+captext(zoom_offsety)+' mm');
  zoffset_mod:=1;
end;
//___________________________________________________________________________________

procedure Tpad_form.move_locator_menu_entryClick(Sender: TObject);     // 227a

var
  mouse_str:string;

begin
  cancel_adjusts(True);

  case locator_rail of
       1,2,3,4: mouse_str:='locator  along  rail  '+IntToStr(locator_rail);
             5: mouse_str:='locator  along  adj ms-centre';
             6: mouse_str:='locator  along  adj ts-centre';
             7: mouse_str:='locator  along  double-track-centre';
             8: mouse_str:='locator  along  ms-centre';
             9: mouse_str:='locator  along  ts-centre';
           else mouse_str:='locator';
  end;//case

  calc_locator_pad_pos;     // calc current locator position on pad for caption.

  mouse_action_selected('    move  locator ...',mouse_str,'X : '+captext(pad_locator_point.x)+' mm   Y : '+captext(pad_locator_point.y)+' mm');

  locator_mod:=1;

  show_locator_menu_entry.Checked:=True;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.shift_corner1_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    shift  shape  corner 1 ...','shape  corner 1','by  X : '+captext(shapes_shiftx_now)+' mm   Y : '+captext(shapes_shifty_now)+' mm');
  corner1_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.shift_corner2_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    shift  shape  corner 2 ...','shape  corner 2','by  X : '+captext(shapes_shiftx_now)+' mm   Y : '+captext(shapes_shifty_now)+' mm');
  corner2_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.shift_shape_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    shift  shape ...','shift  shape','by  X : '+captext(shapes_shiftx_now)+' mm   Y : '+captext(shapes_shifty_now)+' mm');
  oneshape_shift_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.shift_all_shapes_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    shift  all  shapes ...','shift  all  shapes','by  X : '+captext(0)+' mm   Y : '+captext(0)+' mm');
  allshapes_shift_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.scale_shape_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    scale  shape  ( re-size ) ...','scale  shape  ( re-size )','by : '+captext(100)+' %');
  oneshape_scale_mod:=1;
end;
//_________________________________________________________________________________________

procedure Tpad_form.scale_all_shapes_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    scale  all  shapes ...','scale  all  shapes','by : '+captext(100)+' %');
  allshapes_scale_mod:=1;
end;
//__________________________________________________________________________________________

procedure Tpad_form.rotate_all_shapes_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    rotate  all  shapes ...','rotate  all  shapes','by : '+captext(0)+' degrees');
  allshapes_rotate_mod:=1;
end;
//____________________________________________________________________________________________

procedure Tpad_form.move_page_origin_menu_entryClick(Sender: TObject);

var
  mouse_str:string;

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  mouse_str:='SHIFT+CTRL-F10  page  origin';
  if banner_paper=True then mouse_str:=mouse_str+' ( banner  paper )';

  mouse_action_selected('SHIFT+CTRL-F10    move  page  origin ...',mouse_str,'X : '+captext(print_pages_top_origin)+' mm   Y : '+captext(print_pages_left_origin)+' mm');
  porg_mod:=1;
  if show_margins=0 then show_margins:=1;  // assume printer if off
  redraw_pad(True,False);                  // to show margins if previously hidden.
end;
//_____________________________________________________________________________________

procedure Tpad_form.adjust_print_size_menu_entryClick(Sender: TObject);

var
  mouse_str:string;

begin
  cancel_paper_bunching;   // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  mouse_str:='print  size';
  if banner_paper=True then mouse_str:=mouse_str+' ( banner  paper )';

  mouse_action_selected('    adjust  print  size ...',mouse_str,captext(out_factor*100)+' %');
  out_factor_mod:=1;

  tick_not_normal;
  set_output_size_menu_entry.Checked:=True;        // radio item.
  if show_margins=0 then show_margins:=1;    // assume printer if off
  redraw_pad(True,False);                    // to show margins if previously hidden.
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_paper_bunching_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('    adjust  pad  bunching ...','pad  bunching','bunched  by  (X) : '+captext(bunching_jump)+' mm     sheared  by  (Y) : '+captext(bunching_shear)+' mm');
  bunch_mod:=1;
end;
//__________________________________________________________________________________

procedure Tpad_form.adjust_turnout_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  if plain_track=True
     then begin
            alert(6,'    F5  adjust  size',
                    '  •  F5 adjust size.'
                   +'||The `0F5`2 mouse action applies to turnout and half-diamond templates only.'
                   +'||The control template is currently plain track.'
                   +'||For plain track use `0F4`2 mouse action to adjust the length,||or use `0F6`2 mouse action to adjust the curving radius.| ',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if (half_diamond=True) and (tradius_is_straight=False)
     then begin

            repeat
              i:=alert(7,'    F5  convert  irregular  half-diamond ?',
                         '  •  `0F5`2 convert irregular half-diamond?'
                        +'||The control template is currently an `0irregular`3 type of half-diamond.'
                        +'||Meaning that the K-crossing angle is not the same as the V-crossing angle.'
                        +'||If you continue using the `0F5`2 mouse action, this template will be converted to a `0regular`3 type half-diamond and the K-crossing angle will be changed to match the V-crossing angle.'
                        +'||To retain an `0irregular`3 type of half-diamond having unequal angles, cancel this and:'
                        +'||Use `0F9`2 mouse action to adjust the V-crossing angle independently.'
                        +'||Use `0F10`2 mouse action to adjust the K-crossing angle independently.',
                         '','','','more  information','cancel','continue',4);
              if i=5 then EXIT;

              if i=4 then alert_help(0,irregular_help_str,'');

            until i<>4;

            convert_to_regular_half_diamond;
            redraw_pad(True,True);
          end;

  cancel_adjusts(True);

  mouse_action_selected('F5    adjust  size ...','F5  size','1 : '+captext(k3n));

  sx_mod:=1;

  lock_xing_popup_entry.Enabled:=True;
  lock_switch_popup_entry.Enabled:=True;


  if half_diamond=True
     then begin
            lock_switch_popup_entry.Click;
            switch_modify_mode:=False;
          end
     else unlock_both;

end;
//_____________________________________________________________________________________

procedure Tpad_form.FormMouseMove(Sender:TObject; Shift:TShiftState; X, Y:Integer);

          // !!! N.B. also comes here on Mouse UP (after doing MouseUp).
begin
  T2_panel.BorderStyle:=bsSingle;

  pad_mouse_move(Shift,X,Y);
end;
//___________________________________________________________________________________________

procedure Tpad_form.copy_bg_to_current_popup_entryClick(Sender: TObject);

begin
  click_bgnd_to_current(False);

  clicked_keep_index:=-1;    // so can popup again.
end;
//_____________________________________________________________________________________

procedure Tpad_form.copy_for_brick_popup_entryClick(Sender: TObject);   // 241c

begin
  click_bgnd_to_current(False);

  peg_on_joint_end_menu_entry.Click;     // to CTRL-1
  
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.wipe_to_current_popup_entryClick(Sender: TObject);

begin
  click_bgnd_to_current(False);
  wipe_bg_popup_entry.Click;
  clicked_keep_index:=-1;    // so can popup again.
end;
//_______________________________________________________________________________________

procedure Tpad_form.mint_popup_entryClick(Sender: TObject);

begin
  click_bgnd_to_current(False);
  mint_new_current(0,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________________________________________________________________________

procedure Tpad_form.obtain_switch_popup_entryClick(Sender: TObject);

begin
  obtain_switch(clicked_keep_index);
  clicked_keep_index:=-1;                 // so can popup again.
end;
//__________________________________________________________________________________________

procedure Tpad_form.obtain_plain_track_popup_entryClick(Sender: TObject);

begin
  obtain_plain_track(clicked_keep_index);
  clicked_keep_index:=-1;                 // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_k_match_popup_entryClick(Sender: TObject);

begin
  try
    if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

    if plain_track=True
       then begin
              alert(6,'php/890    obtain  K  match  for  outside-slip',
                      'The control template is plain track.'
                     +'||This function applies only to turnout templates.',
                      '','','','','cancel','',0);
              EXIT;
            end;

    if half_diamond=True
       then begin
              alert(6,'php/890    obtain  K  match  for  outside-slip',
                      'The control template is a half-diamond template.'
                      +'||This function applies only to turnout templates.',
                      '','','','','cancel','',0);
              EXIT;
            end;

    if (Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_half_diamond=False)
    or (Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_plain_track=True)
       then begin
              alert(6,'php/890    obtain  K  match  for  outside-slip',
                      'The selected background template is not a half-diamond template.'
                      +'||It does not have a K-crossing.',
                      '','','','','cancel','',0);
              EXIT;
            end;

    osk_match:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.turnout_info2.crossing_info.hdkn_unit_angle;

    redraw_pad(True,True);

  finally
    clicked_keep_index:=-1;       // so can popup again.
  end;
end;
//______________________________________________________________________________

procedure delete_to_current_popup_entry_click(no_alert:boolean);

  // 0.93.a menu item is disabled in quick mode.

var
  str:string;
  i:integer;

begin
  try
    if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

    if (delete_to_current_msg_pref=False) and (bgnd_clicked_in_quick_mode=False) and (no_alert=False)
       then begin
              str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;     // Delphi bug? - must be a local string, otherwise limits length of alert string.

              alert_box.preferences_checkbox.Checked:=False;       //%%%%
              alert_box.preferences_checkbox.Show;

                // 208b mods..

              i:=alert(7,'      delete  template  to  the  control ?',
                         str
                        +'||You are about to copy this template to the control template and delete the original from your storage box and background drawing, so that it can be modified and stored again later.'

                        +'||If necessary it can be restored unmodified to the background drawing, either by clicking the `0PROGRAM > STORE & BACKGROUND`1 menu item, or pressing the `0INSERT`2 key, before making any changes to it.'

                        +'||Or by clicking the `0EDIT > UNDO DELETE`1 menu item on the storage box before another template is deleted.'

                        +'||Are you sure you want to delete this stored template back to the control template?'

                        +'||If you are not sure, click the green bar.',
                         '','','','','no  -  cancel  delete    ','yes  -  delete  '+str+'  to  control',0);

              delete_to_current_msg_pref:=alert_box.preferences_checkbox.Checked;    //%%%%
              alert_box.preferences_checkbox.Hide;

              if i=5 then EXIT;
            end;

    click_bgnd_to_current(False);
    redraw_pad(False,True);            // to show it.

    list_position:=clicked_keep_index;
    delete_keep(False,False);
  finally
    clicked_keep_index:=-1;    // so can popup again.
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.make_control_popup_entryClick(Sender: TObject);

  // 0.93.a

  // no delete alerts

begin
  bgnd_clicked_in_quick_mode:=True;           // use Quick mode options regardless of mode for make

  if turnoutx=0                                         // ignore storing a zero-length template
     then delete_to_current_popup_entry_click(True)     // True = no delete alert
     else begin
            if store_and_background(False,False)=True          // first store the control unless he cancels
               then delete_to_current_popup_entry_click(True);
          end;

  bgnd_clicked_in_quick_mode:=False;   // reset
  clicked_keep_index:=-1;              // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.copy_and_make_popup_entryClick(Sender: TObject);

  // 0.93.a

begin
  bgnd_clicked_in_quick_mode:=True;       // use Quick mode options regardless of mode for make

  if turnoutx=0                           // ignore storing a zero-length template
     then click_bgnd_to_current(False)
     else begin
            if store_and_background(False,False)=True then click_bgnd_to_current(False);  // first store the control unless he cancels
          end;

  bgnd_clicked_in_quick_mode:=False;   // reset
  clicked_keep_index:=-1;              // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.delete_to_current_popup_entryClick(Sender: TObject);

begin
  delete_to_current_popup_entry_click(False);
end;
//______________________________________________________________________________

procedure Tpad_form.over_facing_facing_popup_entryClick(Sender: TObject);

begin
  if check_peg_on_main=False then EXIT;
  align_current_over_bgnd(clicked_keep_index,True,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.over_facing_trailing_popup_entryClick(Sender: TObject);

begin
  if check_peg_on_main=False then EXIT;
  align_current_over_bgnd(clicked_keep_index,False,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.peg_facing_facing_popup_entryClick(Sender: TObject);

begin
  snake_onto_bgnd_peg(clicked_keep_index,True,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.peg_facing_trailing_popup_entryClick(Sender: TObject);

begin
  snake_onto_bgnd_peg(clicked_keep_index,False,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.align_over_help_popup_entryClick(Sender: TObject);

begin
//
end;
//______________________________________________________________________________

procedure Tpad_form.select_bg_popup_entryClick(Sender: TObject);

begin
  click_bgnd_to_selected;
  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//_______________________________________________________________________________________

procedure Tpad_form.FormMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X, Y:Integer);

begin
  if arrow_button_dummy_trackbar.Showing=True then arrow_button_dummy_trackbar.SetFocus;  // 0.91.c  for arrow keys.

  if slide_on_store>0  // 206a cancel any unfinished sliding after store
     then begin
            slide_on_store:=0;
            xshift:=stored_xshift;
            yshift:=stored_yshift;
          end;

  print_now_form.print_data_sent_label.Hide;  // 0.93.a
  print_now_form.Hide;

  if dummy_label_panel.Showing=True
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            dummy_label_panel.Hide;    // finished moving.
          end;

  if Button=mbMiddle  // 0.91.a
     then begin
            mouse_action_release(False);   // (if any)  0.91.c

            if (ssCtrl in Shift)   // 0.91.c   Ctrl+roll = pan, click changes direction
               then begin
                      if mouse_wheel_pan_dir=0
                         then mouse_wheel_pan_dir:=2
                         else mouse_wheel_pan_dir:=0;  // 0=east/west  2=north/south
                    end
               else begin
                      Screen.Cursor:=crSizeAll;  // 0.91.c

                      zoff_now_x:=X;  // 0.91.c   init pad move
                      zoff_now_y:=Y;
                      zoom_offsetx_now:=zoom_offsetx;
                      zoom_offsety_now:=zoom_offsety;
                    end;

          end            // middle button now has no other meaning.
     else pad_mouse_down(Button,Shift,X,Y);
end;
//____________________________________________________________________________________________

procedure Tpad_form.cancel_mouse_action_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
end;
//_________________________________________________________________________________________

procedure Tpad_form.free_scaling_menu_entryClick(Sender: TObject);

begin
  if (xshift<>0) or (yshift<>0) or (kform<>0) then fit_current_only_menu_entry.Click;     //  if not on datum first set the screen offsets.
  draw_mode:=1;                                                                           //  set free scaling mode.
  if (zoom_mod=1) or (spot_mod=1) then cancel_adjusts(False);     //  adjust zoom won't work now the scaling is free.
  free_scaling_menu_entry.Checked:=True;                          //  radio item.
  zoom_free_popup_entry.Checked:=True;                            //  ditto.
  with info_form do begin
    zoom_lock_label.Font.Color:=clLime;
    zoom_lock_label.Caption:='zoom  free';   //  centred label.
    unlock_button.Enabled:=False;
  end;//with
  do_rollback:=False;       // no need to put this in rollback register on redraw.
  redraw(True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.lock_scaling_menu_entryClick(Sender: TObject);

begin
  if (screenx<minfp) or (screenx=def_req) then screenx:=100*scale;   // zero or negative so make screen 100' scale wide.
  if screenx<screenx_min then screenx:=screenx_min;                  // minimum for screen width (max zoom in).
                                                                     // ( ! getting strange draw problems if zoom in any more).
  if screenx>screenx_max then screenx:=screenx_max;                  // maximum zoom out.

  draw_mode:=2;                              // set scaling locked mode.
  lock_scaling_menu_entry.Checked:=True;     //  radio item.
  zoom_locked_popup_entry.Checked:=True;     //  ditto
  with info_form do begin
    zoom_lock_label.Font.Color:=clWhite;
    zoom_lock_label.Caption:='locked  at :';   //  centred label.
    unlock_button.Enabled:=True;
  end;//with
end;
//_______________________________________________________________________________________

procedure Tpad_form.lock_scaling_at_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;    // [0..7] array of extended;

begin
  if screenx<minfp then screenx:=100*scale;         // turnoutx is zero so make screen 100' scale wide.
  if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
                                                    // ( ! getting strange draw problems if zoom in any more).
  if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

     putdim('',1,'full  width  of  trackpad  represents',screenx,True,True,True,False);       // mm, no negative, no preset, no zero, don't terminate on zero.
     putdim('',1,'offset  to  left  edge  of  pad',zoom_offsetx,False,True,False,False);     // mm, neg ok, no preset, zero ok, don't terminate on zero.
  n:=putdim('',1,'offset  to  bottom  edge  of  pad',zoom_offsety,False,True,False,False);   // mm, neg ok, no preset, zero ok, don't terminate on zero.

  if n<>2 then EXIT;

  if getdims('pad  zoom  settings','',pad_form,n,od)=True
     then begin
            screenx:=ABS(od[0]);
            if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
                                                              // ( ! getting strange draw problems if zoom in any more).
            if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

            zoom_offsetx:=od[1];
            zoom_offsety:=od[2];

            lock_scaling_menu_entry.Click;
            do_rollback:=False;               // no need to put this change in rollback register on redraw.
            redraw(True);
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.show_info_menu_entryClick(Sender: TObject);

begin
  grid_form.Close;              // need KB shortcuts for the info..
  shove_timber_form.Close;
  if Application.Terminated=False then Application.ProcessMessages;

  info_show_i:=1;
  show_info_menu_entry.Checked:=True;                   //  radio item.
  show_info_popup_entry.Checked:=True;                  //  radio item.
  info_form.Show;

end;
//_______________________________________________________________________________________

procedure Tpad_form.hide_info_menu_entryClick(Sender: TObject);

begin
  info_show_i:=0;
  hide_info_menu_entry.Checked:=True;                   //  radio item.
  hide_info_popup_entry.Checked:=True;                  //  radio item.
  info_form.Hide;
end;
//______________________________________________________________________________________

procedure Tpad_form.printer_setup_menu_entryClick(Sender: TObject);

begin
  printer_setup(False,False);
end;
//________________________________________________________________________________________

procedure Tpad_form.print_grid_on_menu_entryClick(Sender: TObject);

begin
  printgrid_i:=1;
end;
//_______________________________________________________________________________________

procedure Tpad_form.print_grid_off_menu_entryClick(Sender: TObject);

begin
  printgrid_i:=0;
end;
//___________________________________________________________________________________________

procedure Tpad_form.printed_grid_solid_menu_entryClick(Sender: TObject);

begin
  printed_grid_solid_menu_entry.Checked:=True;  // radio item.
end;
//_________________________________________________________________

procedure Tpad_form.printed_grid_dotted_menu_entryClick(Sender: TObject);

begin
  printed_grid_dotted_menu_entry.Checked:=True;  // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.set_any_grid_spacing_menu_entryClick(Sender: TObject);

begin
  set_grid_spacings(pad_form);
end;
//____________________________________________________________________________________________

procedure Tpad_form.print_screen_menu_entryClick(Sender: TObject);

const
  sc_help_str:string='      Print  Screen  Contents'
 +'||This function will be most useful when used with a virtual printer, such as a PDF generator program.'
 +'||Printing the screen contents produces a low-resolution copy of the drawing currently on the screen, dot for dot. This is not suitable for use as a construction'
 +' template, but might be useful in other ways. As part of a control panel diagram, for example, or if printed on OHP transparency film it would make'
 +' a colourful image for use perhaps in a club talk on pointwork construction.'
 +'||Hide the information panel, scalebar, screen grid, page outlines, zoom target ring and background details if you do not want any of these to print, and set the required'
 +' DRAWING COLOURS on the TRACKPAD menu (not the OUTPUT menu). Unless you set the paper colour to white, you will use a lot of coloured ink.'
 +'||All the lines drawn on the screen are 1 dot thick, so for the best printed results you will need to experiment with the print quality (click PRINTER SETUP...) and the colours.'
 +' Usually the best results will be obtained by using only the basic ink colours of black, yellow, cyan (the pre-set blue colour used for the grid lines on the printed'
 +' templates), and magenta (the pre-set pink colour used for the trim margins on the printed templates).'
 +'||The scale of this printout will be determined by your current screen and printer resolutions, and will in all probability'
 +' be an odd size. Templot does not use the normal printer calibration corrections when printing the screen contents.'
 +'||For accurate track planning purposes, print reduced scale templates instead. To do this, click the OUTPUT > ENLARGE-REDUCE SIZE menu options.';


var
  screen_rect,print_rect:TRect;
  i:integer;

begin
repeat
  i:=alert(3,'   print  screen  contents ...','Printing the screen contents is not the same thing as printing a usable construction template.'
            +'||You will get a small printout in the corner of the paper which might be useful as part of a control panel or a signal box diagram.'
            ,'more  information','printer  setup ...','print  the  control  template  normally  instead','print  trackpad  templates  normally  instead','cancel  printing','print  the  screen  contents',1);        // 0.93.a
  case i of
      1: alert_help(0,sc_help_str,'');
      2: printer_setup_menu_entry.Click;
      3: print_control_template_menu_entry.Click;
      4: print_entire_pad_menu_entry.Click;
      5: EXIT;
      6: begin
            top_toolbar_panel.Hide;
            second_toolbar_panel.Hide;     // 217a

            brick_button.Hide;       // 235b..
            store_draw_button.Hide;


            screen_rect.Top:=0;
            screen_rect.Left:=0;
            screen_rect.Right:=pad_form.ClientWidth-1;
            screen_rect.Bottom:=pad_form.ClientHeight-1;

            print_rect:=screen_rect;

            Printer.BeginDoc;
            Printer.Canvas.CopyMode:=cmSrcCopy;
            Printer.Canvas.CopyRect(print_rect,pad_form.Canvas,screen_rect);
            Printer.EndDoc;

            top_toolbar_panel.Show;
            second_toolbar_panel.Show;     // 217a

            brick_button.Show;       // 235b..
            store_draw_button.Show;

            redraw(True);
         end;
    else run_error(65);
  end;//case
until i>2;
end;
//_______________________________________________________________________________________

procedure Tpad_form.back_colour_menu_entryClick(Sender: TObject);

begin
  info_form.Color:=get_colour('choose  a  colour  for  the  information  panel  background',info_form.Color);
end;
//__________________________________________________________________________________________

procedure Tpad_form.info_font_menu_entryClick(Sender: TObject);

begin
  info_form.info_memo.Font.Assign(get_font('choose  a  font  and  text  colour  for  the  information  panel',info_form.info_memo.Font,True));
end;
//______________________________________________________________________________________

procedure Tpad_form.undo_toolbuttonMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X,Y:Integer);

            // do first undo here, then via timer if held down.
begin
  cancel_adjusts(False);
  undo_toolbutton.Tag:=1;
  Application.ProcessMessages;    // to show button down or quick back up.
  if undo_toolbutton.Tag<>0 then undo_changes_menu_entry.Click;
end;
//_______________________________

procedure Tpad_form.undo_toolbuttonMouseUp(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X,Y:Integer);

begin
  undo_toolbutton.Tag:=0;
end;
//______________________________________________________________________________________

procedure Tpad_form.redo_toolbuttonMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X,Y:Integer);

            // do first redo here, then via timer if held down.
begin
  cancel_adjusts(False);
  redo_toolbutton.Tag:=1;
  Application.ProcessMessages;    // to show button down or quick back up.
  if redo_toolbutton.Tag<>0 then redo_changes_menu_entry.Click;
end;
//_______________________________

procedure Tpad_form.redo_toolbuttonMouseUp(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X,Y:Integer);

begin
  redo_toolbutton.Tag:=0;
end;
//_________________________________________________________________________________________

const
  help_warn_str:string='    `0Small  Radius  Warning`9'
                     +'||The warning "lamp" on the information panel will flash <span style="color:#FF0000; font-weight:bold;">red</span> if any'
                     +' part of the control template is curved to a radius smaller than this limit dimension (at the track centre-line).'
                     +'||This indicator is a design aid only -- changing this limit has no effect on the actual design of the control template.'
                     +'||green_panel_begin tree.gif The specified limit applies to the current control template only. Stored templates can each have a separate limit setting.'
                     +' This makes it possible to set different limits for different parts of the layout design.'
                     +'||To set the limit for a group of templates, change it for the control template and then click the `0geometry > radius&nbsp;warning > modify group to match`1 menu item.green_panel_end';
//______________________________________________________________________________

procedure Tpad_form.min_rad_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(help_warn_str,1,'show  warning  if  any  radius  is  smaller  than',cpi.min_radius_pi,True,False,False,False);  //  no neg, allow preset and zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('radius  warning','',pad_form,n,od)=True then cpi.min_radius_pi:=ABS(od[0]);
  info_form.limit_rad_label.Caption:=round_str(cpi.min_radius_pi,0)+' mm';
  get_cpi;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.radius_warning_help_menu_entryClick(Sender: TObject);

begin
  help(0,help_warn_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.red_lamp_timerTimer(Sender: TObject);

var
  t55:integer;
  t55_str:string;
  viewer1_str,viewer2_str,content1_str,content2_str:string;  // 214a

begin

  INC(running_counter);   // 212a  count since startup

(* OT2024
  if web_browser_form.Showing=True
     then web_browser_form.Caption:='    Templot  map  viewer :  '+web_browser_form.web_browser.LocationURL;      // 215b


  if (wait_form.Showing=True) and (wait_form.Tag>0)  // 214a
     then begin
            if (running_counter-wait_form.Tag)>50   // external exe file launched  214a more than 10 seconds ago
               then begin
                      wait_form.Tag:=0;
                      wait_form.Hide;
                    end;
          end;
*)

  if (hidden_on_store=1) and (hide_current_flag=True)     // 205c countdown to show control template again
     then show_and_redraw(True,False);

  if hidden_on_store>0 then DEC(hidden_on_store);  // 205c

  if reveal_limit_count>0 then DEC(reveal_limit_count);  // 206a  time limit for sliding control template over stored copy

  if undo_toolbutton.Tag<>0
     then begin
            Application.ProcessMessages;                  // to show button down or quick back up.
            undo_toolbutton.Tag:=0-undo_toolbutton.Tag;   // only on alternate ticks.
            if undo_toolbutton.Tag=1 then undo_changes_menu_entry.Click;
          end;

  if redo_toolbutton.Tag<>0
     then begin
            Application.ProcessMessages;                  // to show button down or quick back up.
            redo_toolbutton.Tag:=0-redo_toolbutton.Tag;   // only on alternate ticks.
            if redo_toolbutton.Tag=1 then redo_changes_menu_entry.Click;
          end;

  with track_spacing_form do begin      // 226c ...

    if Visible=True
       then begin

              if less_toolbutton.Tag<>0
                 then begin
                        Application.ProcessMessages;                  // to show button down or quick back up.
                        less_toolbutton.Tag:=0-less_toolbutton.Tag;   // only on alternate ticks.
                        if less_toolbutton.Tag=1 then less_spacing;
                      end;

              if more_toolbutton.Tag<>0
                 then begin
                        Application.ProcessMessages;                  // to show button down or quick back up.
                        more_toolbutton.Tag:=0-more_toolbutton.Tag;   // only on alternate ticks.
                        if more_toolbutton.Tag=1 then more_spacing;
                      end;
            end;
  end;// with

    // 226c end

    // lists move up-down repeat buttons...

  if keep_form.move_up_button.Tag<>0      // 0.93.a
     then begin
            Application.ProcessMessages;                                    // to show button down or quick back up.
            keep_form.move_up_button.Tag:=0-keep_form.move_up_button.Tag;   // only on alternate ticks.
            if keep_form.move_up_button.Tag=1 then keep_move_up_button_click;
          end;

  if keep_form.move_down_button.Tag<>0    // 0.93.a
     then begin
            Application.ProcessMessages;                                        // to show button down or quick back up.
            keep_form.move_down_button.Tag:=0-keep_form.move_down_button.Tag;   // only on alternate ticks.
            if keep_form.move_down_button.Tag=1 then keep_move_down_button_click;
          end;

  if bgnd_form.move_up_button.Tag<>0      // 205a
     then begin
            Application.ProcessMessages;                                    // to show button down or quick back up.
            bgnd_form.move_up_button.Tag:=0-bgnd_form.move_up_button.Tag;   // only on alternate ticks.
            if bgnd_form.move_up_button.Tag=1 then bgnd_move_up_button_click;
          end;

  if bgnd_form.move_down_button.Tag<>0    // 0.93.a
     then begin
            Application.ProcessMessages;                                        // to show button down or quick back up.
            bgnd_form.move_down_button.Tag:=0-bgnd_form.move_down_button.Tag;   // only on alternate ticks.
            if bgnd_form.move_down_button.Tag=1 then bgnd_move_down_button_click;
          end;


  if min_rad_warn=1 then toggle_radius_lamp             // flash the radius warning lamp.
                    else info_form.min_rad_lamp_panel.Color:=clLime;

  if info_form.ring_lamp_panel.Tag=1 then toggle_ring_lamp;       // flash the rings warning lamp.
  if info_form.ring_lamp_panel.Tag=0
     then begin
            if (cl_only=True) or (warn_centrelines=True)
               then info_form.ring_lamp_panel.Color:=clAqua
               else info_form.ring_lamp_panel.Color:=clLime;
          end;

  if (t55_counter<>-1) and (t55_counter<2005) then INC(t55_counter);

  if t55_counter>2000            // delay 6.67 minutes after startup - 2000*200millisecs.
     then begin
            if (gauge_i<>t_T55_i) or (scale<>5.5) or (g<>25.4)     // mods 0.91.c  gauge has been changed   (scale may have been loaded from control template on file)
               then t55_counter:=-1                                // so stop counter and ignore
               else begin
                      if (pad_form.Active=True) and (mouse_modify=-1)   // wait until no mouse action.
                         then begin
                                t55_counter:=-1;     // only do this once.

                                t55:=any_t55;

                                case t55 of

                                    0: t55_str:='';

                                    1: t55_str:='||There is one T-55 template in your storage box.'
                                               +' If this is unintended, click the `0box > delete T-55 templates`z menu item on the storage box.';

                                  else t55_str:='||There are '+IntToStr(t55)+' T-55 templates in your storage box.'
                                               +' If these are unintended, click the `0box > delete T-55 templates`z menu item on the storage box.';
                                end;//case

                                if alert(3,'php/320    T - 55  gauge',
                                           '    `0T-55  Gauge`9'
                                          +'||You are currently using the fictional T-55 startup gauge.'
                                          +'||Have you forgotten to set your required gauge and scale?'
                                          +t55_str,
                                           '','','','continue  with  T-55  gauge','','change  gauge  and  scale ...',0)=6
                                   then other_gauges_menu_entry.Click;
                              end;
                    end;
          end;

          // 0.91.c ...

  INC(pad_view_counter);

  if pad_view_counter>4              // every 1 second  (5*200 mS)
     then begin
            pad_view_counter:=0;
            check_pad_views;         // in math_unit

            if  (modal_form_count>0) and (running_under_wine=True)   // 212a wine bug
            and (showing_message=False) and (showing_dialog=False)   // 212a Wine bug

               then begin
                      if modal_form_array[modal_form_count].Visible=True then modal_form_array[modal_form_count].BringToFront;   // 212a wine bug
                    end;

            if time_now_panel.Visible=True then time_now_panel.Caption:=TimeToStr(Time);

          end;

end;
//_______________________________________________________________________________________

procedure Tpad_form.keep_this_menu_entryClick(Sender: TObject);

begin
  if check_control_template_is_valid('store')=False then EXIT;  // 0.93.a  zero length

  store_unused(False,False);
  if keep_form.open_on_keep_menu_entry.Checked=True then view_box_menu_entry.Click;
end;
//__________________________________________________________________________________________

procedure Tpad_form.store_as_library_menu_entryClick(Sender: TObject);

begin
  if check_control_template_is_valid('store')=False then EXIT;  // 0.93.a  zero length

  store_unused(True,False);
  if keep_form.open_on_keep_menu_entry.Checked=True then view_box_menu_entry.Click;

  lib_form.lib_listbox.Visible:=(any_library>0);           // 227a
end;
//________________________________________________________________________________________

procedure Tpad_form.program_panel_menu_entryClick(Sender: TObject);

begin
  control_room_form.BorderIcons:=[biSystemMenu,biMinimize];     // 205c
  control_room_form.Show;
  control_room_form.BringToFront;
end;
//_________________________________________________________________________________________

procedure Tpad_form.FormPaint(Sender: TObject);

begin
  if (pad_form.Showing=True) and (under_way=True) and (abandon_calcs=False)
  and (prog_running=True)  and ((mouse_modify<1) or (trace_mouse=False))

     //  ! otherwise clobbers Windows on startup or exit.
     //  ! no repaints while visible mouse action - (moving the action form).

     then copy_draw_to_pad;
end;
//_______________________________________________________________________________________

procedure Tpad_form.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);

var
  mps,mpp:TPoint;      // mouse position (screen, pad co-ords).

begin
  if (Key=VK_NUMPAD5) and (Shift=[])      // finish a left button click.
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            mpp:=pad_form.ScreenToClient(mps);
            pad_mouse_up(mbLeft, [ssLeft], mpp.X, mpp.Y);
            Key:=0;
          end;        // this key will be ignored by OnKeyPress because ignore_key has already been set True by OnKeyDown.
end;
//___________________________________________________________________________________________

procedure Tpad_form.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);

var
  mps,mpp:TPoint;      // mouse position (screen, pad co-ords).
  scroll:extended;

begin
  if gaps_form.symbol_id_edit.Focused=True  // 227a
     then begin
            KeyPreview:=False;
            EXIT;                    // to allow text editing on child form
          end
     else KeyPreview:=True;

  if slide_on_store>0  // 206a cancel any unfinished sliding after store
     then begin
            slide_on_store:=0;
            xshift:=stored_xshift;
            yshift:=stored_yshift;
          end;

  if Key=VK_F10
     then begin
            Key:=0;      //  otherwise selects the menus.
          end;

  if Key=VK_PAUSE
     then begin
            Application.Minimize;       //  hide TEMPLOT on PAUSE key.
            Key:=0;
          end;

  if Key=VK_UP
     then begin

            if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,3,(ssCtrl in Shift));
            arrow_button_dummy_trackbar.Position:=5;    // keep it in the centre.

                 // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            Key:=0;
          end;

  if Key=VK_DOWN
     then begin

            if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,4,(ssCtrl in Shift));
            arrow_button_dummy_trackbar.Position:=5;    // keep it in the centre.

                 // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            Key:=0;
          end;

  if Key=VK_LEFT
     then begin

            if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,1,(ssCtrl in Shift));
            arrow_button_dummy_trackbar.Position:=5;    // keep it in the centre.

                 // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            Key:=0;
          end;

  if Key=VK_RIGHT
     then begin

            if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,2,(ssCtrl in Shift));
            arrow_button_dummy_trackbar.Position:=5;    // keep it in the centre.

                 // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            Key:=0;
          end;

  if Key=VK_DELETE
     then begin
            if mouse_modify=-1
               then snap_to_zero_menu_entry.Click      // no mouse action
               else begin
                      if action_form.Showing=True      //  toggle show of mouse action panel on Delete key.
                         then action_form.Hide
                         else if (mouse_modify<>-1) and (mouse_labels=True)
                                 then action_form.Show;
                    end;
            Key:=0;
          end;

  if Key=VK_CAPITAL                       // caps lock on or off.
     then begin
            redraw(True);                 // to show small labels.
            Key:=0;
          end;

  if ((Key=VK_HOME) and (Shift=[]))            // 209c
  or ((Key=VK_RETURN) and (Shift=[ssCtrl]))    // 215a
     then begin
            if show_control_template_menu_entry.Checked=True
               then hide_control_template_menu_entry.Click        // radio items
               else show_control_template_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_HOME) and (Shift=[ssCtrl])  // 209c  toggle background templates      218d  ignore rectangle option
     then begin
            if any_bgnd<1   // 237c
               then begin
                      show_modal_message('Toggle Background Templates'+#13+#13+'There are no stored background templates at present.');
                      show_bgnd_templates:=True;
                    end
               else begin
                      show_bgnd_templates:= NOT show_bgnd_templates;  //  237c show_bgnd_keeps_menu_entry.Click;   // 237a

                      Key:=0;

                      redraw_pad(True,False);
                    end;
          end;

  if (Key=VK_HOME) and (Shift=[ssShift])  // 209c  toggle background shapes
     then begin
            if show_shapes_menu_entry.Checked=True
               then hide_shapes_menu_entry.Click
               else show_shapes_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_HOME) and (Shift=[ssShift,ssCtrl])  // 209c  toggle group templates
     then begin
            if any_selected<1   // 237c
               then begin
                      show_modal_message('Toggle Group Templates'+#13+#13+'There are no selected group templates at present.');
                      show_group_templates:=True;
                    end
               else begin
                      show_group_templates:= NOT show_group_templates;

                      Key:=0;

                      redraw_pad(True,False);
                    end;
          end;

  if Key=VK_SPACE
     then begin
            hide_current_flag:=False;
            fit_current_only_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD0) and (Shift=[])      // examine peg.
     then begin
            hide_current_flag:=False;
            examine_peg_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD5) and (Shift=[])      // start a left button click.
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            mpp:=pad_form.ScreenToClient(mps);
            pad_mouse_down(mbLeft, [ssLeft], mpp.X, mpp.Y);
            SetCursorPos(mps.X, mps.Y);                   // need a mouse move event.
            Key:=0;
          end;
 //-------------

  if (Key=VK_NUMPAD8) and (Shift=[])      // simulate mouse moves...
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X, mps.Y-1);   // 8 = North
            Key:=0;
          end;

  if (Key=VK_NUMPAD2) and (Shift=[])        // 2 = South
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X, mps.Y+1);
            Key:=0;
          end;

  if (Key=VK_NUMPAD4) and (Shift=[])        // 4 = West
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X-1, mps.Y);
            Key:=0;
          end;

  if (Key=VK_NUMPAD6) and (Shift=[])        // 6 = East
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X+1, mps.Y);
            Key:=0;
          end;

  if (Key=VK_NUMPAD9) and (Shift=[])        // 9 = NE
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X+1, mps.Y-1);
            Key:=0;
          end;

  if (Key=VK_NUMPAD7) and (Shift=[])        // 7 = NW
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X-1, mps.Y-1);
            Key:=0;
          end;

  if (Key=VK_NUMPAD1) and (Shift=[])        // 1 = SW
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X-1, mps.Y+1);
            Key:=0;
          end;

  if (Key=VK_NUMPAD3) and (Shift=[])        // 3 = SE
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;
            SetCursorPos(mps.X+1, mps.Y+1);
            Key:=0;
          end;

  if (Shift=[ssCtrl]) and (Key=VK_INSERT)     // INS is store and background menu shortcut. 211b With Ctrl down = use old name label position
     then begin
            cancel_adjusts(False);
            store_and_background_menu_entry.Click;  // Ctrl will still be down
            Key:=0;
          end;


  if Key=VK_F2             //  toggle info panel on F2.
                           //  this is not a conventional shortcut,
                           //  which I cannot get to work with a toggled shortcut property.
                           //  (The "F2" showing on the menu is actually part of the caption.)
     then begin
            if info_show_i=1 then hide_info_menu_entry.Click     // radio items.
                             else show_info_menu_entry.Click;
            Key:=0;
          end;


  if Key=VK_PRIOR   // PageUP
     then begin
            if Shift=[] then fit_bgnd_menu_entry.Click;   // 205e was clasic_templot_mode // 0.93.a   was free_scaling_menu_entry.Click; // PageUP.

            if Shift=[ssCtrl] then length_free_menu_entry.Click;     // CTRL-PageUP.
            Key:=0;
          end;

  if Key=VK_NEXT    // PageDOWN
     then begin
            if Shift=[] then fit_selected_group_only_menu_entry.Click;  // 205e was quick_mode  // 0.93.a   was lock_scaling_menu_entry.Click; // PageDOWN.

            if Shift=[ssCtrl] then length_locked_menu_entry.Click;   // CTRL-PageDOWN.
            Key:=0;
          end;

  if Key=VK_DECIMAL     // numpad . key
     then begin
            if Shift=[] then begin
                               hide_current_flag:=False;
                               pad_on_peg_menu_entry.Click;
                             end;

            if Shift=[ssCtrl] then pad_on_notch_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_HOME) and (Shift=[ssAlt])   // 234b
     then begin

            show_brick_templates:= NOT show_brick_templates;

            if show_brick_templates=True
               then show_brick_templates_menu_entry.Checked:=True   // radio item
               else hide_brick_templates_menu_entry.Checked:=True;  // radio item

            Key:=0;

            redraw_pad(True,False);
          end;

 //--------------------

  if ( (Key=VK_ADD) and (Shift=[]) ) or ( (key=Word(VkKeyScan('='))) and (Shift=[ssShift,ssCtrl]) )  // numpad + key  or Shift+Ctrl+=
     then begin
            explode_normal_menu_entry.Click;
            Key:=0;
          end;

  if ( (Key=VK_SUBTRACT) and (Shift=[]) ) or ( (key=Word(VkKeyScan('-'))) and (Shift=[ssShift,ssCtrl]) )  // numpad - key  or Shift+Ctrl+-
     then begin
            shrink_normal_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_ADD) and (Shift=[ssCtrl])
     then begin
            explode_slow_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_SUBTRACT) and (Shift=[ssCtrl])
     then begin
            shrink_slow_menu_entry.Click;
            Key:=0;
          end;

 //----------------------

  if (Key=VK_MULTIPLY) or ( (Key=Word(VkKeyScan(''''))) and (Shift=[ssShift,ssCtrl]) )  // numpad * key  or Shift+Ctrl+'
     then begin
            hide_current_flag:=False;
            shift_current_onto_notch_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_DIVIDE) or ( (Key=Word(VkKeyScan('/'))) and (Shift=[ssShift,ssCtrl]) )  // numpad / key  or Shift+Ctrl+/ (slash)
     then begin
            hide_current_flag:=False;
            notch_under_peg_menu_entry.Click;
            Key:=0;
          end;

  //---------------------------------------

  if (Key=VK_NUMPAD0) and (Shift=[ssCtrl])
     then begin
            cancel_adjusts(False);               // need a fresh mouse_down to init.
            hide_current_flag:=False;
            peg_is_free_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD1) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail1_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD2) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail2_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD3) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail3_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD4) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail4_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD5) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail5_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD6) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail6_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD7) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail7_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD8) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail8_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD9) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_rail9_menu_entry.Click;
            Key:=0;
          end;

  //____________________________________

         // 0.91.c  view presets...

  if (Key=VK_NUMPAD1) and (Shift=[ssAlt])
     then begin
            panning_form.view1_button.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD2) and (Shift=[ssAlt])
     then begin
            panning_form.view2_button.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD3) and (Shift=[ssAlt])
     then begin
            panning_form.view3_button.Click;
            Key:=0;
          end;

  if (Key=VK_NUMPAD4) and (Shift=[ssAlt])
     then begin
            panning_form.view4_button.Click;
            Key:=0;
          end;

  //-----------------------------------------

  // these tests must follow those for the numpad keys above...

  if (key=$30) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            reset_peg_menu_entry.Click;
            Key:=0;
          end;

  if (key=$31) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_joint_end_menu_entry.Click;
            Key:=0;
          end;

  if (key=$32) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_tp_menu_entry.Click;
            Key:=0;
          end;

  if (key=$33) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_blanked_length_menu_entry.Click;  // 234e   was peg_on_dp_menu_entry.Click;
            Key:=0;
          end;

  if (key=$34) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_fp_menu_entry.Click;
            Key:=0;
          end;

  if (key=$35) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_txp_menu_entry.Click;
            Key:=0;
          end;

  if (key=$36) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_TVJP_menu_entry.Click;
            Key:=0;
          end;

  if (key=$37) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_mxp_menu_entry.Click;
            Key:=0;
          end;

  if (key=$38) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_MVJP_menu_entry.Click;
            Key:=0;
          end;

  if (key=$39) and (Shift=[ssCtrl])
     then begin
            hide_current_flag:=False;
            peg_on_overall_length_menu_entry.Click;
            Key:=0;
          end;

  if (Key=Word(VkKeyScan('v'))) and (Shift=[ssCtrl])        // 0.93.a CTRL+V is STORE & BACKGROUND (same as INSERT)
     then begin
                  // undocumented for experienced users..   206c
            if keep_form.alert_on_store_menu_entry.Checked then keep_form.hide_on_store_menu_entry.Checked:=True;  // radio item

            cancel_adjusts(False);
            store_and_background_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('.'))) and (Shift=[ssCtrl])        // full-stop key virtual code.
     then begin
            cross_hairs_pointer_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('/')){key=$BF}) and (Shift=[ssCtrl])        // forward slash key virtual code.
     then begin
            if show_reminders_menu_entry.Checked=True                // 216a  toggle reminders.  radio items
               then hide_reminders_menu_entry.Click
               else show_reminders_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('\')){key=$DC}) and (Shift=[ssCtrl])        // backslash key virtual code.
     then begin
            reset_notch_menu_entry.Click;     // 0.93.a change CTRL+BACKSLASH
            Key:=0;
          end;

  if (key=Word(VkKeyScan('-'))) and (Shift=[ssCtrl])        // minus key virtual code.
     then begin
            hide_current_flag:=False;
            shorten_approach_one_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('='))) and (Shift=[ssCtrl])        // equal key virtual code.
     then begin
            hide_current_flag:=False;
            extend_approach_one_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('['))) and (Shift=[ssCtrl])        // left bracket key virtual code.
     then begin
            hide_current_flag:=False;
            shorten_exit_one_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan(']'))) and (Shift=[ssCtrl])        // right bracket key virtual code.
     then begin
            hide_current_flag:=False;
            extend_exit_one_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('`'))) and (Shift=[ssCtrl])              //  ` (top-left) key virtual code.
     then begin
            hide_current_flag:=False;
            snap_to_MVJP_menu_entry.Click;
            Key:=0;
          end;

  if (key=Word(VkKeyScan('`'))) and (Shift=[ssShift,ssCtrl])      //  ` (top-left) key virtual code.
     then begin
            hide_current_flag:=False;
            snap_to_peg_menu_entry.Click;
            Key:=0;
          end;

  if Key=VK_BACK         //  backspace.
     then begin
            repeat_last_action_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_END) and (Shift=[ssCtrl])     // CTRL-END   0.76.a 19-5-02
     then begin
            hide_current_flag:=False;
            peg_on_joints_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_END) and (Shift=[ssShift])  // 218d  rectangle option
     then begin
            show_bgnd_keeps_in_rect_menu_entry.Click;
            Key:=0;
          end;

  if (Key=VK_END) and (Shift=[ssShift,ssCtrl])  // 227a show symbols
     then begin
            if show_template_symbols_menu_entry.Checked=True
               then hide_template_symbols_menu_entry.Click
               else show_template_symbols_menu_entry.Click;    // toggle
            Key:=0;
          end;

  if ((Key=VK_END) and (Shift=[]))             // END   0.82.b 16-10-06
  or ((Key=VK_RETURN) and (Shift=[ssShift]))   // 215a    was ssCtrl 209c
     then begin
            if show_name_labels_menu_entry.Checked=True
               then hide_name_labels_menu_entry.Click        // radio items
               else show_name_labels_menu_entry.Click;

            Key:=0;
          end;

  //------------------------------------------

  save_hide:=hide_current_flag;

  if Key=0 then ignore_key:=True             // flag the keypress handler to ignore this key. This works around an apparent Delphi bug?
           else ignore_key:=False;
end;
//____________________________________________________________________________________________

procedure Tpad_form.FormKeyPress(Sender: TObject; var Key: Char);

begin
  if ignore_key=True then Key:=Chr(0);     // this key was a shortcut and has been handled by KeyDown.

  case Key of

         ',','0','3'..'9','-','=','[',']','''','#': begin
                                                      hide_current_flag:=False;                      // need to see it.
                                                      save_hide:=False;
                                                    end;
  end;//case;

  case Key of

         ',': shove_timbers_menu_entry.Click;           //  SHIFT-F10

         '0': swell_menu_entry.Click;                   //  CTRL-F10
         '1': adjust_spot_zoom_menu_entry.Click;        //  CTRL-F1
         '2': show_pan_controls_menu_entry.Click;       //  CTRL-F2
         '3': adjust_blanking_length_menu_entry.Click;  //  CTRL-F3
         '4': adjust_roll_sleepers_menu_entry.Click;    //  CTRL-F4
         '5': orbit_rad_centre_menu_entry.Click;        //  CTRL-F5
         '6': snake_menu_entry.Click;                   //  CTRL-F6
         '7': adjust_slew_amount_menu_entry.Click;      //  CTRL-F7
         '8': move_peg_menu_entry.Click;                //  CTRL-F8
         '9': adjust_roam_menu_entry.Click;             //  CTRL-F9



         '|': if info_show_i=1 then hide_info_menu_entry.Click   // 211b
                               else show_info_menu_entry.Click;

         '`': begin
                bgkeeps_form.bold_timber_outlines_checkbox.Checked:= NOT bgkeeps_form.bold_timber_outlines_checkbox.Checked;   // 227a
                redraw(True);
              end;


         '-': adjust_rad1_menu_entry.Click;            //  SHIFT+CTRL-F1
         '=': adjust_rad2_menu_entry.Click;            //  SHIFT+CTRL-F2

         '[': adjust_trans_start_menu_entry.Click;     //  SHIFT+CTRL-F3
         ']': adjust_trans_length_menu_entry.Click;    //  SHIFT+CTRL-F4

        '''': adjust_slew_start_menu_entry.Click;      //  SHIFT+CTRL-F5
         '#': adjust_slew_length_menu_entry.Click;     //  SHIFT+CTRL-F6

         '\': shift_keeps_menu_entry.Click;            //  SHIFT+CTRL-F7
         '/': rotate_keeps_menu_entry.Click;           //  SHIFT+CTRL-F8

         '.': differ_check_rails_menu_entry.Click;     // 0.94.a SHIFT+CTRL-F9  was move_ring_menu_entry.Click;

         ';': full_draw:= NOT full_draw;  // 217b  now toggle menu item  if full_draw=True then skeleton_mouse_draw_menu_entry.Click   //  SHIFT+CTRL-F12 toggle.
                                          //                             else full_mouse_draw_menu_entry.Click;

         '@': extra_fine_adjust_menu_entry.Click;
         '%': fine_adjust_menu_entry.Click;
         '!': coarse_adjust_menu_entry.Click;

         '<': paper_bunching_on_menu_entry.Click;
         '>': paper_bunching_off_menu_entry.Click;

    Chr(27) : begin                     // ESC

                got_file:=-1;  // 227a  cancel getfile

                cancel_adjusts(False);
                if arrow_button_dummy_trackbar.Showing=True then arrow_button_dummy_trackbar.SetFocus;    // 0.91.c for arrow keys to work.
              end;

  end;//case

  Key:=Chr(0);
end;
//___________________________________________________________________________________________

procedure Tpad_form.solid_infill_menu_entryClick(Sender: TObject);

begin
  rail_infill_i:=2;                           // solid coloured.
  solid_infill_menu_entry.Checked:=True;      // radio-button - so Windows unchecks the others.
end;
//________________________________________

procedure Tpad_form.cross_hatched_infill_menu_entryClick(Sender: TObject);

begin
  rail_infill_i:=3;
  cross_hatched_infill_menu_entry.Checked:=True;     // radio-button - so Windows unchecks the others.
end;
//________________________________________

procedure Tpad_form.hatched_infill_menu_entryClick(Sender: TObject);

begin
  rail_infill_i:=1;
  hatched_infill_menu_entry.Checked:=True;    // radio-button - so Windows unchecks the others.
end;
//________________________________________

procedure Tpad_form.blank_infill_menu_entryClick(Sender: TObject);

begin
  rail_infill_i:=4;                           // solid, white.
  blank_infill_menu_entry.Checked:=True;      // radio-button - so Windows unchecks the others.
end;
//________________________________________

procedure Tpad_form.no_infill_menu_entryClick(Sender: TObject);

begin
  rail_infill_i:=0;
  no_infill_menu_entry.Checked:=True;    // radio-button - so Windows unchecks the others.
end;
//_____________________________________________________________________________________________

procedure Tpad_form.rail_infill_style_menu_entryClick(Sender: TObject);

   // added 207a for prefs...

begin
  case rail_infill_i of                         // radio items...
    0: no_infill_menu_entry.Checked:=True;
    1: hatched_infill_menu_entry.Checked:=True;
    2: solid_infill_menu_entry.Checked:=True;
    3: cross_hatched_infill_menu_entry.Checked:=True;
    4: blank_infill_menu_entry.Checked:=True;
  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.swap_hand_menu_entryClick(Sender: TObject);

begin
  swap_hand;
  redraw_pad(True,True);
end;
//_____________________________________________________________________________________________

procedure Tpad_form.switch_menu_entryClick(Sender: TObject);

begin
  select_switch;
end;
//__________________________________________________________________________________________

procedure Tpad_form.blunt_nose_menu_entryClick(Sender: TObject);

const
  bnw_str:string='      Width of Blunt Nose'
  +'||Enter a dimension in full-size prototype inches for the width of the nose of the crossing vee.'
  +'||For British standard-gauge bullhead track this dimension is normally 3/4" (0.75").'
  +'||For British standard-gauge flat-bottom track this dimension is normally 5/8" (0.625").'
  +'||(The nose of the crossing vee is not made sharp, otherwise it would be very quickly damaged by the passing of wheels over it.)'
  +'||Handy Hint:'
  +'|For model gauges using overscale flangeway gaps (H0, 00/H0, 00-BF, EM, GOG-F, etc.), improved running may be obtained by making the nose of the crossing vee sharper than exact scale.'
  +' A scale equivalent of 1/4" (0.25") nose width is suggested.'

  +'||In the case of a half-diamond template, the K-crossing point rails are blunted to a tip width 1/8" less than the dimension used for the V-crossing vees.';

  bna_str:string='      Distance from Blunt Nose to Timber Centre'
  +'||Enter a dimension in full-size prototype inches for the distance from the blunt nose to the centre of the "A" timber supporting it.'
  +'||For British standard-gauge bullhead track this dimension is normally 4 inches.'
  +'||For British standard-gauge flat-bottom track this dimension is normally 5 inches.'
  +'||Handy Hint:'
  +'|If you are using sharp-nose vees with underscale nose width, a dimension of 6 inches is suggested. For standard 12 inch wide timbers, this will align the nose of the vee with the edge of the "A" timber.';

var
  n:integer;
  od:Toutdim;

begin
     putdim(bnw_str,2,'width  of  blunt  nose  ( full-size  inches )',  bn_wide,True,False,False,False);       // no neg, pre-set ok, zero ok.
  n:=putdim(bna_str,2,'blunt  nose  to  timber  centre  ( f-s  inches)',bn_to_a,False,False,False,False);      // neg ok, pre-set ok, zero ok.

    if n<>1 then EXIT;
    if getdims('blunt  nose','',pad_form,n,od)=True
       then begin
              if od[0]=def_req then bn_wide:=0.75    // full-size inches.  3/4" blunt nose BH default.
                               else bn_wide:=od[0];

              if od[1]=def_req then bn_to_a:=4.0     // full-size inches - 4" to A timber centre.
                               else bn_to_a:=od[1];

              redraw(True);
            end;
end;
//___________________________________________________________________________________________

procedure Tpad_form.wing_front_menu_entryClick(Sender: TObject);

const
  help_wing_all_size_str:string='    Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers spanned by the wing rail in front of the crossing (i.e. between the wing rail joint and the "A" timber bearing the nose of the vee, but not including the "A" timber itself or any timbers beyond it),'
    +' and the centre-to-centre spacing for these timbers in FULL-SIZE prototype inches.'

    +'||Handy Hint:'
    +'|If the spacing is variable, set an average spacing which will give the required wing rail front length, and then use the REAL > SHOVE TIMBERS function to make an appropriate adjustment to each timber.'

    +'||To set the overall length of the wing rail, click the REAL > CUSTOMIZE V-CROSSING > WING AND CHECK RAILS... menu item.'

    +'||For a diagram of wing rail dimensioning, see "Real Track" in the Templot Companion pages on the Templot web site at  85a.uk/templot/companion .'

    +'||To change the fill timber spacing between the switch and the crossing, click the REAL > TIMBERING > TIMBERING DATA... menu item.'
    +'||To change the timber spacings in the switch, use the SHOVE TIMBERS functions or click the TEMPLATE > SWITCH OPTIONS... menu item and create a CUSTOM SWITCH.'
    +'||To change the sleeper spacing for plain track, click the REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS... menu item.';

  helpw1_str:string='   Size  1  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 1 wing rail fronts.'
    +'||Size 1 wing rail fronts are used when the crossing angle is shorter than 1:4.';

  helpw2_str:string='   Size  2  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 2 wing rail fronts.'
    +'||Size 2 wing rail fronts are used when the crossing angle is between 1:4 and 1:6.75 inclusive.';

  helpw3_str:string='   Size  3  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 3 wing rail fronts.'
    +'||Size 3 wing rail fronts are used when the crossing angle is between 1:7 and 1:10 inclusive.';

  helpw4_str:string='   Size  4  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 4 wing rail fronts.'
    +'||Size 4 wing rail fronts are used when the crossing angle is between 1:10.25 and 1:15 inclusive.';

  helpw5_str:string='   Size  5  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 5 wing rail fronts.'
    +'||Size 5 wing rail fronts are used when the crossing angle is between 1:15.25 and 1:20 inclusive.';

  helpw6_str:string='   Size  6  Wing  Rail  Front  Dimensions'
    +'||Enter the number of timbers in front of the crossing which are spanned by size 6 wing rail fronts.'
    +'||Size 6 wing rail fronts are used when the crossing angle is flatter than 1:20.';

  helpwsp_str:string='    Timber  Spacing  for  Wing  Rail  Front'
   +'||Enter a dimension in full-size inches which will be the timber spacing (centre-to-centre) for the timbers under the wing front part of the crossing (i.e. between the wing rail joint and the "A" timber bearing the nose of the vee).'
   +'||For British standard-gauge bullhead and flatbottom track this dimension is normally 30 inches.'
   +'||If a constant spacing is not wanted, individual timbers can be re-positioned using the REAL > SHOVE TIMBERS menu item functions.';

  helpwj_str:string='   Timber  Spacing  at  Wing  Rail  Joint'
    +'||Enter a dimension in FULL-SIZE prototype INCHES for the timber centre-to-centre spacing at the wing rail joint.'
    +'||For British standard gauge flatbottom track this dimension is normally 26 inches.'
    +'||For British standard gauge bullhead track this dimension varies, but is typically 25 inches.';

  more_str:string='||This setting has no effect when the crossing angle is not within this range.||For more information click the button below.';

var
  n:integer;
  od:Toutdim;

begin
    putdim(helpw1_str+more_str,0,'number of timbers spanned by size 1 wing front',wing_spco1,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpw2_str+more_str,0,'number of timbers spanned by size 2 wing front',wing_spco2,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpw3_str+more_str,0,'number of timbers spanned by size 3 wing front',wing_spco3,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpw4_str+more_str,0,'number of timbers spanned by size 4 wing front',wing_spco4,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpw5_str+more_str,0,'number of timbers spanned by size 5 wing front',wing_spco5,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpw6_str+more_str,0,'number of timbers spanned by size 6 wing front',wing_spco6,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.

    putdim(helpwsp_str,2,'timber spacing for wing rail front (f-s inches)',wingtimb_sp,True,False,False,False);
 n:=putdim(helpwj_str,2,  'timber spacing at wing rail joint (f-s inches)',wingj_sp,   True,False,False,False);         // no neg, preset ok, zero ok, don't terminate on zero.

    if n<>7 then EXIT;

    if getdims('wing  rail  front  dimensions',help_wing_all_size_str,pad_form,n,od)=True
       then begin
                                 // number of timbers - these are byte values...

              if (od[0]<=255) and (od[0]<>def_req) then wing_spco1:=Round(od[0])
                                                   else wing_spco1:=1;

              if (od[1]<=255) and (od[1]<>def_req) then wing_spco2:=Round(od[1])
                                                   else wing_spco2:=3;

              if (od[2]<=255) and (od[2]<>def_req) then wing_spco3:=Round(od[2])
                                                   else wing_spco3:=3;

              if (od[3]<=255) and (od[3]<>def_req) then wing_spco4:=Round(od[3])
                                                   else wing_spco4:=4;

              if (od[4]<=255) and (od[4]<>def_req) then wing_spco5:=Round(od[4])
                                                   else wing_spco5:=5;

              if (od[5]<=255) and (od[5]<>def_req) then wing_spco6:=Round(od[5])
                                                   else wing_spco6:=6;

              if od[6]<>def_req then wingtimb_sp:=od[6]
                                else wingtimb_sp:=30;    // full-size inches - 30" timber spacing for wing rail front part of crossing (up to "A").

              if od[7]<>def_req then wingj_sp:=od[7]
                                else wingj_sp:=25;       // full-size inches - 25" timber spacing at wing rail joint.

              redraw(True);
            end;
end;
//_____________________________________________________________________________________________

procedure Tpad_form.vee_rail_menu_entryClick(Sender: TObject);

const
  help_vee_all_size_str:string='    Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by the vee rail (i.e. from the "A" timber bearing the nose of the vee to the vee rail joint, including the "A" timber itself),'
    +' and the centre-to-centre spacing for these timbers in FULL-SIZE prototype inches.'

    +'||Handy Hint:'
    +'|If the spacing is variable, set an average spacing which will give the required vee rail length, and then use the REAL > SHOVE TIMBERS function to make an appropriate adjustment to each timber.'

    +'||For a diagram of vee rail dimensioning, see "Real Track" in the Templot Companion pages on the Templot web site at  85a.uk/templot/companion .'

    +'||To change the fill timber spacing between the switch and the crossing, click the REAL > TIMBERING > TIMBERING DATA... menu item.'
    +'||To change the timber spacings in the switch, use the SHOVE TIMBERS functions or click the TEMPLATE > SWITCH OPTIONS... menu item and create a CUSTOM SWITCH.'
    +'||To change the sleeper spacing for plain track, click the REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS... menu item.';


  helpv1_str:string='   Size  1  Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by size 1 vee rails.'
    +'||Size 1 vee rails are used when the crossing angle is shorter than 1:4.';

  helpv2_str:string='   Size  2  Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by size 2 vee rails.'
    +'||Size 2 vee rails are used when the crossing angle is between 1:4 and 1:6.75 inclusive.';

  helpv3_str:string='   Size  3  Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by size 3 vee rails.'
    +'||Size 3 vee rails are used when the crossing angle is between 1:7 and 1:10 inclusive.';

  helpv4_str:string='   Size  4  Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by size 4 vee rails.'
    +'||Size 4 vee rails are used when the crossing angle is between 1:10.25 and 1:15 inclusive.';


  helpv5_str:string='   Size  5  Vee  Rail  Dimensions'
    +'||Enter the number of timbers spanned by size 5 vee rails.'
    +'||Size 5 vee rails are used when the crossing angle is between 1:15.25 and 1:20 inclusive.';

  helpv6_str:string='   Size  6  Vee  Rail  Dimensions'
    +'||Enter the mininum number of timbers spanned by size 6 vee rails.'
    +'||Size 6 vee rails are used when the crossing angle is flatter than 1:20.'
    +'||The actual number of timbers may be more than this minimum to ensure adequate separation between the vee point and splice rails at the joint.';

  helpvsp_str:string='    Timber  Spacing  for  Vee  Rail'
   +'||Enter a dimension in full-size inches which will be the timber spacing (centre-to-centre) for the timbers under the vee rail part of the crossing (i.e. from the "A" timber bearing the nose of the vee to the vee rail joint).'
   +'||For British standard-gauge bullhead and flatbottom track this dimension is normally 30 inches.'
   +'||If a constant spacing is not wanted, individual timbers can be re-positioned using the REAL > SHOVE TIMBERS menu item functions.';

  helpvj_str:string='   Timber  to  Vee  Rail  Joint'
    +'||Enter a dimension in FULL-SIZE prototype INCHES for the amount by which the end of the vee rail extends beyond the timber centre at the vee rail joint (the MVJP CTRL-8 position).'
    +'||For British standard gauge flatbottom track this dimension is normally 13 inches.'
    +'||For British standard gauge bullhead track this dimension varies, but is typically 12.5 inches.';

  more_str:string='||This setting has no effect when the crossing angle is not within this range.||For more information click the button below.';

var
  n:integer;
  od:Toutdim;

begin
    putdim(helpv1_str+more_str,0,'number of timbers spanned by size 1 vee rail',vee_spco1,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpv2_str+more_str,0,'number of timbers spanned by size 2 vee rail',vee_spco2,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpv3_str+more_str,0,'number of timbers spanned by size 3 vee rail',vee_spco3,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpv4_str+more_str,0,'number of timbers spanned by size 4 vee rail',vee_spco4,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpv5_str+more_str,0,'number of timbers spanned by size 5 vee rail',vee_spco5,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpv6_str+more_str,0,'number of timbers spanned by size 6 vee rail',vee_spco6,True,False,False,False);   // no neg, preset ok, zero ok, don't terminate on zero.

    putdim(helpvsp_str,2,'timber spacing for vee rail (f-s inches)',   veetimb_sp,True,False,False,False);
 n:=putdim(helpvj_str,2, 'timber to vee rail joint (full-size inches)',mvj_sp,    True,False,False,False);           // no neg, preset ok, zero ok, don't terminate on zero.

    if n<>7 then EXIT;

    if getdims('vee  rail  dimensions',help_vee_all_size_str,pad_form,n,od)=True
       then begin

              if (od[0]<=255) and (od[0]<>def_req) then vee_spco1:=Round(od[0])
                                                   else vee_spco1:=4;

              if (od[1]<=255) and (od[1]<>def_req) then vee_spco2:=Round(od[1])
                                                   else vee_spco2:=5;

              if (od[2]<=255) and (od[2]<>def_req) then vee_spco3:=Round(od[2])
                                                   else vee_spco3:=6;

              if (od[3]<=255) and (od[3]<>def_req) then vee_spco4:=Round(od[3])
                                                   else vee_spco4:=7;

              if (od[4]<=255) and (od[4]<>def_req) then vee_spco5:=Round(od[4])
                                                   else vee_spco5:=8;

              if (od[5]<=255) and (od[5]<>def_req) then vee_spco6:=Round(od[5])
                                                   else vee_spco6:=9;

              if od[6]<>def_req then veetimb_sp:=od[6]
                                else veetimb_sp:=30;    // full-size inches - 30" timber spacing for vee rail.

              if od[7]<>def_req then mvj_sp:=od[7]
                                else mvj_sp:=12.5;      // full-size inches - 12.5" spacing to vee point rail joint.

              redraw(True);
            end;
end;
//___________________________________________________________________________________________

procedure Tpad_form.rail_section_menu_entryClick(Sender: TObject);

const
  helprd_str:string='php/701    `0Rail  Head  Width`9'
                  +'||Enter the rail head width in full-size prototype `0inches`3.'
                  +'||The rail head width for British standard-gauge bullhead (BS-95R) and most flat-bottom rail is 2.75 inches. Narrower rails are'
                  +' often used for narrow-gauge, industrial and light railways. Some USA and European rail is wider.'
                  +'||If you enter a silly dimension, e.g 24 inches, the results may be unexpected or Templot may decline to generate a template.'
                  +'||If you are using a non-scale model rail section, click `0MORE GENERAL INFORMATION`1 below.';

  helprb_str:string='php/701    `0Rail  Foot  Width`9'
                  +'||This dimension is used for flat-bottom rails, and for inclined bullhead rails.'
                  +'||The rail foot width for British standard-gauge FB-109, BS-110A and BS-113A flat-bottom rail is 5.5 inches. Narrower rails are'
                  +' often used for narrow-gauge, industrial and light railways. Some USA and European rail is wider.'
                  +'||For inclined bullhead rails, enter a foot width equal to the head width (2.75 inches for BS-95R section).'
                  +'||If you are using a non-scale model rail section, click `0MORE GENERAL INFORMATION`1 below.';

  helprh_str:string='php/701    `0Rail  Section  Height`9'
                  +'||Templot uses this dimension to correctly position the rail foot when the rail is inclined from vertical.'
                  +' This dimension is also used in exported 3-D DXF files.'
                  +'||The height of BS-95R bullhead rail is 5.23/32" (5.719").'
                  +'||The height of FB-109, BS-110A and BS-113A flat-bottom rail is 6.1/4" (6.25").'
                  +'||If you are using a non-scale model rail section, click `0MORE GENERAL INFORMATION`1 below.';

  helpseat_str:string='php/701    `0Rail  Seating  Height`9'
                  +'||This is the thickness of the bullhead chair base or flat-bottom baseplate below the rail.'
                  +'||This dimension is used in exported 3-D DXF files.'
                  +'||The base thickness of REA bullhead chairs is usually 1.75 inches.'
                  +'||The thickness of FB baseplates varies.'
                  +'||For more information please refer to the Templot Club forum.';


  helprk_str:string='php/701    `0Rail  Inclination  Angle`9'
                  +'||Running rails are normally inclined inwards at the top to match the coning angle on the wheels.'
                  +'||Many modellers ignore this however and build model trackwork with vertical rails for ease of construction.'
                  +'||The usual inclination angle in the UK is 2.86 degrees (1:20).'
                  +'||Templot uses this dimension to correctly position the rail foot on printed templates.'
                  +'||This angle is ignored for exported 3-D DXF files, which always show vertical rails.'
                  +'||green_panel_begintree.gif To enter the angle as a ratio, prefix it with a letter n. For example to enter an angle of 1:20, enter `0n20`z.green_panel_end'
                  +'|If the inclination angle is set to zero the effect is the same as selecting the `0REAL > RAILS > VERTICAL RAILS`1 menu option.'
                  +'||N.B. Any angle setting you make here is ignored while the `0REAL > RAILS > VERTICAL RAILS`1 menu option is in force.';

var
  n:integer;
  od:Toutdim;

begin
  with cpi do begin
                       // these are stored in model mm...

    putdim(helprd_str,2,'rail  head  width  ( full-size inches )',railtop_pi/inscale,False,False,True,False);
    putdim(helprb_str,2,'rail  foot  width  ( full-size inches )',railbottom_pi/inscale,True,False,True,False);  // no neg, preset ok, no zero, don't terminate on zero.

                       // these are stored in FULL-SIZE INCHES (also for DXF)...

    putdim(helprh_str,2,'rail  section  height  ( full-size inches )',rail_height_pi,True,False,False,False);  // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpseat_str,2,'rail  seat  height  above  timber  ( full-size inches )',rail_seat_height_pi,False,False,False,False);  // 235a neg ok, preset ok, zero ok, don't terminate on zero.

 n:=putdim(helprk_str,3,'rail  inclination  angle',rail_inclination_pi*180/Pi,True,False,False,False);         // no neg, preset ok, zero ok, don't terminate on zero.

    if n<>4 then EXIT;

    if getdims('prototype  rail  section  dimensions  ',help_rail_str,pad_form,n,od)=True
       then begin
              railtop_pi:=od[0];
              if railtop_pi<>def_req then railtop_pi:=od[0]*inscale;   // mm.

              railbottom_pi:=od[1];
              if railbottom_pi<>def_req then railbottom_pi:=od[1]*inscale;   // mm.

              rail_height_pi:=od[2];

              rail_seat_height_pi:=od[3];   // 235a

              rail_inclination_pi:=od[4];
              if rail_inclination_pi<>def_req then rail_inclination_pi:=od[4]*Pi/180;   // to radians.

              reset_defaults;
              redraw(True);
            end;
  end;//with
end;
//___________________________________________________________________________________________

procedure Tpad_form.rails_help_menu_entryClick(Sender: TObject);

begin
  help(0,help_rail_str,'');
end;
//_________________________________________________________________________________________

procedure Tpad_form.wing_check_rails_menu_entryClick(Sender: TObject);

   // mods for 0.94.a  TS modifiers removed

const

 help_gen_str:string='php/601  `0Wing Rails and Check Rails (Guard Rails)`9'

 +'||green_panel_begintree.gif The settings here are the basic check rail and wing rail dimensions which apply to all check and wing rails.'
 +' These basic dimensions are intended to be derived from prototype trackwork data.'
 +'||If you are customizing templates for a specific formation, you can adjust each check rail individually as required. Cancel this and click the `0real > adjust check rails...`1 menu item instead.'
 +'green_panel_end'

 +'|For diagrams and further notes explaining the dimensioning of wing and check rails, click <A HREF="online_ref601.85a">more information online</A>.'

 +'||The wing rails are the short lengths of running rail with bent extensions which lie alongside the nose of the crossing vee.'

 +'||The wing rail "reach" length is measured from the centre of the "A" timber (the timber bearing the nose of the vee) to the free end of the wing rail.'
 +'||(To set the wing rail "front" length from the rail joint to the "A" timber, click the REAL > CUSTOMIZE V-CROSSING > WING RAIL FRONT ... menu item.)'

 +'||The check rails (guard rails) are the short lengths of rail fixed alongside the opposite running rail to prevent the wheels from taking the wrong path at the nose of the crossing.'

 +'||For dimensioning purposes the overall length of a check rail is divided into two component lengths, named "working length" and "extension length".'
 +'||The check rail "working" length is measured from the position where it crosses the centre-line of the "A" timber, to the near end of the check rail (the end which is nearer to the switch) (point blades).'
 +'||The check rail "extension" length is the remaining length from the "A" timber to the far end of the check rail.'

 +'||Templot uses 2 sizes of wing rail reach length, 3 sizes of check rail working length and 2 sizes of check rail extension length, according to the crossing angle.'
 +' These sizes are preset in increasing lengths, but can be set to be all the same, or to any desired lengths.'

 +'||Here is a summary of the way these sizes are used according to the current crossing angle:'
 +'||angle:          chk working len:   chk ext len:    wing reach len:'
 +'||under 1:6                 size 1              size 1             size 1'
  +'|1:6 to 1:10                size 2              size 1             size 1'
  +'|over 1:10 to 1:12     size 2              size 2             size 2'
  +'|over 1:12                 size 3              size 2             size 2'

 +'||In the majority of cases, the check rail extension length is the same dimension as the wing rail reach length, so that the far end of the check rail is aligned with the end of the wing rail,'
 +' but this can be changed as necessary by entering the appropriate dimensions.'

 +'||These dimensions for the wing and check rails should be entered in full-size prototype INCHES and apply to the main-side (MS) wing rail and check rail (in the main-road of the turnout).'

 +'||The turnout-side (TS) wing rail (in the turnout-road) can be made longer or shorter than the main-side wing rail by setting a non-zero dimension for the turnout-side wing rail reach length modifier.'

 +'||The turnout-side (TS) check rail working length can be made longer or shorter than the main-side check rail working length by setting a non-zero dimension for the turnout-side check rail working length modifier.'
 +'||The turnout-side (TS) check rail extension length can be made longer or shorter than the main-side check rail extension length by setting a non-zero dimension for the turnout-side check rail extension length modifier.'

 +'||For specific information about each dimension, click the ? HELP flag on each line or press the F2 key.'

 +'||For diagrams and further notes explaining the dimensioning of wing and check rails, see "Real Track" on the Templot Companion web site, or click <A HREF="online_ref601.85a">more information online</A>.'

 +'||green_panel_begintree.gif Be aware that because the check rails are linked to the "A" timber, the position of the check rails will change when changing the style of timbering (EQUALIZED, SQUARE-ON, or ANGLED-ON).'
 +' But their position is NOT affected by any TIMBER SHOVING which is applied to the "A" timber.'
 +'green_panel_end';

 helpwr1_str:string='php/601    `0Size 1 Wing Rail Reach Length`9'
 +'||The reach length is measured from the centre of the "A" timber (the timber which carries the nose of the vee) to the end of the wing rail.'
 +'||The entered length will apply to both wing rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each wing rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|A size 1 (normally short) wing rail is used when the crossing angle is 1:10 or shorter. The preset reach length for size 1 wing rails is 48 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently longer than 1:10.'
 +'||For more information click the button below.';


 helpwr2_str:string='php/601    `0Size  2  Wing  Rail  Reach Length`9'
 +'||The reach length is measured from the centre of the "A" timber (the timber which carries the nose of the vee) to the end of the wing rail.'
 +'||The entered length will apply to both wing rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each wing rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|A size 2 (normally long) wing rail is used when the crossing angle is longer than 1:10. The preset reach length for size 2 wing rails is 78 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently 1:10 or shorter.'
 +'||For more information click the button below.';

 helpf_str:string='php/601    `0Flared (Splayed) Ends on Wing and Check Rails`9'
 +'||The exposed ends of wing rails and check rails (guard rails) are normally splayed out away from the running rail to provide a flared entry for the wheels.'
 +'||The entered flared length will apply to both wing rails, and to both ends of both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each rail end separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Templot will ignore your changes to the flared length if there is insufficient space within the check rail and wing rail lengths,'
 +' and set the maximum flared length which will fit.'
 +'||To set the flangeway end gap at the end of the check rail, and thus the amount of flare, click the `0GAUGE > MODIFY CURRENT SETTINGS > MODIFY FLANGEWAY GAP...`1 menu item.'
 +'||For more information click the button below.';

 helpckw1_str:string='php/601    `0Size 1 Check Rail Working Length`9'
 +'||The entered length will apply to both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each check rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Check rails with size 1 working length are used when the crossing angle is shorter than 1:6. The preset working length for size 1 check rails is 78 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently 1:6 or longer.'
 +'||For an explanation of the meaning of "working length" click the button below.';

 helpckw2_str:string='php/601    `0Size 2 Check Rail Working Length`9'
 +'||The entered length will apply to both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each check rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Check rails with size 2 working length are used when the crossing angle is between 1:6 and 1:12 inclusive. The preset working length for size 2 check rails is 108 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently shorter than 1:6, or longer than 1:12.'
 +'||For an explanation of the meaning of "working length" click the button below.';

 helpckw3_str:string='php/601    `0Size 3 Check Rail Working Length`9'
 +'||The entered length will apply to both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each check rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Check rails with size 3 working length are used when the crossing angle is longer than 1:12. The preset working length for size 3 check rails is 138 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently 1:12 or shorter.'
 +'||For an explanation of the meaning of "working length" click the button below.';

 helpcke1_str:string='php/601    `0Size 1 Check Rail Extension Length`9'
 +'||The entered length will apply to the both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each check rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Check rails with size 1 (normally short) extension length are used when the crossing angle is 1:10 or shorter. The preset extension length for size 1 check rails is 48 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently longer than 1:10.'
 +'||For an explanation of the meaning of "extension length" click the button below.';

 helpcke2_str:string='php/601    `0Size 2 Check Rail Extension Length`9'
 +'||The entered length will apply to both check rails, and should be in full-size prototype `0inches`3.'
 +'||green_panel_begintree.gif To adjust each check rail separately,|click the `0real > adjust check rails...`1 menu item.green_panel_end'
 +'|Check rails with size 2 (normally long) extension length are used when the crossing angle is longer than 1:10. The preset extension length for size 2 check rails is 78 inches.'
 +'||Changing this dimension will have no effect on the control template if the crossing angle is currently 1:10 or shorter.'
 +'||For an explanation of the meaning of "extension length" click the button below.';

var
  n:integer;
  od:Toutdim;
  save_cpi:Tproto_info;
  xing_str:string;

begin
    if alert(3,'php/601    wing  and  check  rails',
             'You are about to set the basic check rail and wing rail dimensions which apply to all check and wing rails. These basic dimensions are intended to be derived from prototype trackwork data.'
            +'||If you are customizing templates for a specific formation, you can adjust each check rail individually as required. Cancel this and click the REAL > ADJUST CHECK RAILS... menu item instead.',
             '','','','','cancel','continue',0)=5 then EXIT;

  save_cpi:=cpi;      // in case he cancels.

  xing_str:='||( The current crossing angle is  1: '+round_str(k3n,2)+' )';

  with cpi do begin

    putdim(helpwr1_str+xing_str,2,'size 1 wing-rail reach length (full-size)',wing_ms_reach1_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpwr2_str+xing_str,2,'size 2 wing-rail reach length (full-size)',wing_ms_reach2_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.

    putdim(helpckw1_str+xing_str,2,'size 1 check-rail working length (full-size)',ck_ms_working1_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpckw2_str+xing_str,2,'size 2 check-rail working length (full-size)',ck_ms_working2_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpckw3_str+xing_str,2,'size 3 check-rail working length (full-size)',ck_ms_working3_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.

    putdim(helpcke1_str+xing_str,2,'size 1 check-rail extension length (f-s)',ck_ms_ext1_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.
    putdim(helpcke2_str+xing_str,2,'size 2 check-rail extension length (f-s)',ck_ms_ext2_pi,True,False,False,False);      // no neg, preset ok, zero ok, don't terminate on zero.

 n:=putdim(helpf_str,2,'flared length on wing and check rail ends (f-s)',xing_fl_pi/inscale,True,False,False,False);    // no neg, preset ok, zero ok, don't terminate on zero.

    if n<>7 then EXIT;
    if getdims('wing-rail  and  check-rail  dimensions',help_gen_str,pad_form,n,od)=True
       then begin

              wing_ms_reach1_pi:=od[0];       // inches full-size.
              wing_ms_reach2_pi:=od[1];       // inches full-size.

              ck_ms_working1_pi:=od[2];       // inches full-size.
              ck_ms_working2_pi:=od[3];       // inches full-size.
              ck_ms_working3_pi:=od[4];       // inches full-size.

              ck_ms_ext1_pi:=od[5];           // inches full-size.
              ck_ms_ext2_pi:=od[6];           // inches full-size.

              xing_fl_pi:=od[7];
              if xing_fl_pi<>def_req then xing_fl_pi:=od[7]*inscale;   // mm.

            end
       else begin
              cpi:=save_cpi;   // restore rail dimensions
              EXIT;
            end;
  end;//with

  reset_defaults;

  redraw_pad(True,True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.half_diamond_checkrail_options_menu_entryClick(Sender:TObject);

begin
  case hd_vcheck_rails of
        0: normal_hd_checkrails_menu_entry.Checked:=True;      // radio item.
        1: short_hd_checkrail_ts_menu_entry.Checked:=True;     // radio item.
        2: short_hd_checkrail_ms_menu_entry.Checked:=True;     // radio item.
        3: short_hd_checkrails_both_menu_entry.Checked:=True;  // radio item.
  end;//case
end;
//___________________________

procedure Tpad_form.normal_hd_checkrails_menu_entryClick(Sender:TObject);

begin
  hd_vcheck_rails:=0;
  redraw_pad(True,True);
end;
//___________________________

procedure Tpad_form.short_hd_checkrail_ts_menu_entryClick(Sender:TObject);

begin
  hd_vcheck_rails:=1;
  redraw_pad(True,True);
end;
//___________________________

procedure Tpad_form.short_hd_checkrail_ms_menu_entryClick(Sender:TObject);

begin
  hd_vcheck_rails:=2;
  redraw_pad(True,True);
end;
//___________________________

procedure Tpad_form.short_hd_checkrails_both_menu_entryClick(Sender:TObject);

begin
  hd_vcheck_rails:=3;
  redraw_pad(True,True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.half_diamond_timbering_menu_entryClick(Sender: TObject);

begin
  case hd_timbers of
        0: normal_hd_timbers_menu_entry.Checked:=True;          // radio item.
        1: extended_hd_timbers_ts_menu_entry.Checked:=True;     // radio item.
        2: extended_hd_timbers_ms_menu_entry.Checked:=True;     // radio item.
        3: extended_hd_timbers_both_menu_entry.Checked:=True;   // radio item.
  end;//case

  if hd_switch_timbering=True then hd_timbering_as_switch_menu_entry.Checked:=True   // 213a    radio item
                              else hd_timbering_normal_menu_entry.Checked:=True;     // 213a    radio item

  if hd_proto_timbering=True then hd_timbering_as_prototype_menu_entry.Checked:=True   // radio item.
                             else hd_timbering_as_model_menu_entry.Checked:=True;      // radio item.
end;
//_______________________________

procedure Tpad_form.normal_hd_timbers_menu_entryClick(Sender: TObject);

begin
  hd_timbers:=0;
  redraw_pad(True,True);
end;
//________________________________

procedure Tpad_form.extended_hd_timbers_ts_menu_entryClick(Sender: TObject);

begin
  hd_timbers:=1;
  redraw_pad(True,True);
end;
//________________________________

procedure Tpad_form.extended_hd_timbers_ms_menu_entryClick(Sender: TObject);

begin
  hd_timbers:=2;
  redraw_pad(True,True);
end;
//________________________________

procedure Tpad_form.extended_hd_timbers_both_menu_entryClick(Sender: TObject);

begin
  hd_timbers:=3;
  redraw_pad(True,True);
end;
//___________________________________________________________________________________

procedure Tpad_form.k_crossing_wing_rails_menu_entryClick(Sender: TObject);  // 0.95.a

const
  help_k_wing_str:string='php/602    `0K-Crossing Wing Rail Length`9'
 +'||The entered length will apply to both K-crossing wing rails, and should be in full-size prototype `0inches`3.'
 +'||This dimension applies only to half-diamond templates and is the full K-crossing wing rail length (over both halves).'
 +' This dimension controls the position of the wing rail joint marks, and the adjacent timber spacing.'
 +'||The default dimensions used by Templot correspond to the UK REA dimensions, as follows:'
 +'||<TABLE ALIGN="CENTER" BORDER="1" CELLSPACING="0" CELLPADDING="6" STYLE="FONT-SIZE:15px; COLOR:#000099; BACKGROUND-COLOR:#DDEEFF; TEXT-ALIGN:CENTER;">'
 +'<TR STYLE="BACKGROUND-COLOR:#EEFFDD;"><TD NOWRAP>wing rail length</TD><TD NOWRAP>BH bullhead rail</TD><TD NOWRAP>FB flat-bottom rail</TD></TR>'
 +'<TR><TD NOWRAP>fixed K-crossings<BR>1:4 to 1:6.25</TD><TD NOWRAP><B>173</B> inches</TD><TD NOWRAP><B>168</B> inches</TD></TR>'
 +'<TR><TD NOWRAP>fixed K-crossings<BR>1:6.5 to 1:8</TD><TD NOWRAP><B>185</B> inches</TD><TD NOWRAP><B>220</B> inches</TD></TR>'
 +'<TR><TD NOWRAP>movable K-crossings<BR>over 1:8</TD><TD NOWRAP><B>216</B> inches</TD><TD NOWRAP><B>193</B> inches</TD></TR></TABLE>'

 +'|To revert to using these dimensions, click the `0use default K-crossing wing rails`z option.'
 +'||The FB dimensions apply to FB-109, BS-110A, BS-113A inclined-rail K-crossings.';

var
  i:integer;
  custom_str:string;

  n:integer;
  od:Toutdim;

begin

  if use_k_custom_wing_rails=True
     then custom_str:='||The current setting has been customized.| '
     else custom_str:='||The current setting has not been customized and the default settings apply.| ';

  repeat
    i:=alert(3,'php/602    K-crossing  wing  rails',
             'This setting applies only to half-diamond templates. Changing this setting for a turnout or plain-track template will have no effect unless and until it is converted to a half-diamond template.'
            +'||You are about to set a customized K-crossing wing rail length which will apply to both K-crossing wing rails, for all K-crossing angles. This dimension is intended to be derived from your prototype trackwork data.'
            +'||This dimension controls the marked position on the template for the K-crossing wing rail joint and the adjacent timber spacing, but has no effect on the template geometry.'
            +'||To revert to using the default settings, click USE DEFAULT K-CROSSING WING RAILS.'
            +'||To see the default settings, click MORE INFORMATION.'
            +custom_str,
             '','','more  information','use  default  K-crossing  wing  rails','cancel','customize  K-crossing  wing  rails',3);

    if i=5 then EXIT;

    if i=4 then begin
                  use_k_custom_wing_rails:=False;
                  if half_diamond=True then redraw_pad(True,True);
                  EXIT;
                end;

    if i=3 then alert_help(0,help_k_wing_str,'');

  until i<>3;

  n:=putdim(help_k_wing_str,2,'K - crossing  wing  rail  length  ( full - size )',k_custom_wing_long,True,True,False,False);  // no neg, no preset, zero ok, don't terminate on zero.

  if n<>0 then EXIT;

  if getdims('K - crossing  wing  rail  length','',pad_form,n,od)=True
     then begin
            k_custom_wing_long:=od[0];        // inches full-size.
            use_k_custom_wing_rails:=True;
          end
     else EXIT;

  if half_diamond=True then redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.k_crossing_check_rails_menu_entryClick(Sender: TObject);

const
 helpkck1_str:string='php/601  `0Size 1 Fixed K-crossing Check Rail Length`9'
 +'||The entered length will apply to both K-crossing check rails, and should be in full-size prototype `0inches`3.'
 +'||This dimension applies only to half-diamond templates and is the full check rail length (over both halves).'
 +'||Size 1 K-crossing check rails are used when the K-crossing angle is 1:6 or shorter.'
 +'||Changing this dimension has no effect for templates in which the K-crossing angle is longer than 1:6.'
 +'||If the control template is not a half-diamond template, changing this dimension will have no effect until the control template is converted to half-diamond template by clicking the'
 +'|`0TEMPLATE > CONVERT TURNOUT TO HALF-DIAMOND`1 or|`0TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK`1 menu items.'
 +'||For UK bullhead K-crossings, this dimension is normally 185 inches (144 inches on the GWR).'
 +'||For UK flat-bottom K-crossings, this dimension is normally 156 inches.'
 +'||When a slip road is added, this dimension is typically reduced to 142 inches. If overscale flangeway gaps are being used, this dimension may need to be further reduced.'
 +'||For more information click the button below.';

 helpkck2_str:string='php/601  `0Size 2 Fixed K-crossing Check Rail Length`9'
 +'||The entered length will apply to both K-crossing check rails, and should be in full-size prototype `0inches`3.'
 +'||This dimension applies only to half-diamond templates and is the full check rail length (over both halves).'
 +'||Size 2 K-crossing check rails are used when the K-crossing angle is longer than 1:6.'
 +'||Changing this dimension has no effect for templates in which the K-crossing angle is 1:6 or shorter.'
 +'||If the control template is not a half-diamond template, changing this dimension will have no effect until the control template is converted to half-diamond template by clicking the'
 +'|`0TEMPLATE > CONVERT TURNOUT TO HALF-DIAMOND`1 or|`0TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK`1 menu items.'
 +'||For UK bullhead K-crossings, this dimension is normally 197 inches (144 inches on the GWR).'
 +'||For UK flat-bottom K-crossings, this dimension is normally 156 inches.'
 +'||When a slip road is added, this dimension is typically reduced to 142 inches for crossings 1:7 or shorter. If overscale flangeway gaps are being used, this dimension may need to be further reduced.'
 +'||For more information click the button below.';

 helpkckfl_str:string='php/601`0  Flared (Splayed) Ends on<BR>  K-crossing Check Rails`9'
 +'||The exposed ends of wing rails and check rails (guard rails) are normally splayed out away from the running rail to provide a flared entry for the wheels.'
 +'||The entered flared length will apply to both ends of both K-crossing check rails, and should be in full-size prototype `0inches`3.'
 +'||Templot will ignore your changes to the flared length if there is insufficient space within the check rail length, and set the maximum flared length which will fit.'
 +'||If the control template is not a half-diamond template, changing this dimension will have no effect until the control template is converted to half-diamond template by clicking the'
 +'|`0TEMPLATE > CONVERT TURNOUT TO HALF-DIAMOND`1 or|`0TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK`1 menu items.'
 +'||To set the flangeway end gap at the end of the check rail, and thus the amount of flare, click the `0GAUGE > MODIFY CURRENT SETTINGS > MODIFY FLANGEWAY GAP...`1 menu item.'
 +'||For more information click the button below.';

var
  n:integer;
  od:Toutdim;
  xing_str:string;

begin
  if alert(3,'php/601    K-crossing  check  rails',
             'You are about to set the basic K-crossing check rail dimensions which apply to both K-crossing check rails. These basic dimensions are intended to be derived from prototype trackwork data.'
            +'||If you are customizing templates for a specific formation, you can adjust each check rail individually as required. Cancel this and click the REAL > ADJUST CHECK RAILS... menu item instead.',
             '','','','','cancel','continue',0)=5 then EXIT;

  xing_str:='||( The current K-crossing angle is  1: '+round_str(hdkn,2)+' )';

     putdim(helpkck1_str+xing_str,2,'size 1 K-crossing check rail length (full-size)',  kck1_long,   True,True,False,False);  // no neg, no preset, zero ok, don't terminate on zero.
     putdim(helpkck2_str+xing_str,2,'size 2 K-crossing check rail length (full-size)',  kck2_long,   True,True,False,False);  // no neg, no preset, zero ok, don't terminate on zero.
  n:=putdim(helpkckfl_str,        2,'flared length on K-crossing check rail ends (f-s)',k_flare_len, True,True,False,False);  // no neg, no preset, zero ok, don't terminate on zero.

    if n<>2 then EXIT;
    if getdims('fixed  K-crossing  check-rail  dimensions',helpkck_gen_str,pad_form,n,od)=True
       then begin
              kck1_long:=od[0];  // inches full-size.
              kck2_long:=od[1];  // inches full-size.

              k_flare_len:=od[2];     // inches full-size.
            end
       else EXIT;
  if half_diamond=True then redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.k_crossings_help_menu_entryClick(Sender: TObject);

begin
  if help(0,helpkck_gen_str,'about  diamond-crossing  timbering')=1 then hd_timbering_help_menu_entry.Click;
end;
//_________________________________________________________________________________________

procedure Tpad_form.hd_timbering_help_menu_entryClick(Sender: TObject);

begin
  if help(0,helpkck_timbering_str,'about  K-crossings')=1 then k_crossings_help_menu_entry.Click;
end;
//________________________________________________________________________________________

procedure Tpad_form.crossing_menu_entryClick(Sender: TObject);

    //   crossing type (xing_i) :
    //
    // -1 = generic straight crossing, straight begins at fine-point.  "original" pattern crossing.
    //  0 = straight crossing, straight begins in front of fine-point.  "normal" pattern crossing.
    //  1 = curviform V-crossing, turnout curve continues through crossing, no straight.  "curved" pattern crossing.

var
  n, n1,n2,n3:integer;
  od:Toutdim;
  ok:boolean;
  dummy:extended;

begin
  if plain_track=True
     then begin
            if alert(3,'    plain  track',
                       'The control template is plain track.'
                      +'||Any changes which you make to the crossing settings will have no effect until you change to a turnout or a half-diamond template'
                      +' by clicking the|TEMPLATE > INSERT TURNOUT IN PLAIN TRACK or|TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK|menu items.',
                       '','','','','cancel','continue  -  set  crossing ...',0)=5 then EXIT;
          end;
                                //  set list index for current crossing type...
  case xing_type_i of
            0: case retpar_i of
                           0: xing_list_i:=0;       // straight crossing (normal).
                           1: xing_list_i:=1;       // straight crossing returns parallel.
               end;//case
            1: xing_list_i:=2;                      // curviform V-crossing.
           -1: xing_list_i:=3;                      // original crossing (no straight at knuckle).
          else run_error(51);
  end;//case

            //  get the new list index and crossing angle.
            //  and then set up the new current crossing :

  set_xing_k_i;   // set list index from current k3n. mod 0.73.a 20-9-01.

  get_xing(xing_k_i, xing_list_i, entry_straight_code, xing_ret_i);

  case xing_list_i of
                 0: begin
                      if retpar_i=1 then turnout_road_i:=0;  // 0.93.a changing from parallel, assume long turnout road not now needed.
                      xing_type_i:=0;                        // regular crossing (normal)...
                      retpar_i:=0;
                      snap_exit_to_return_curve_menu_entry.Enabled:=False;

                      if (peg_code=7) or (peg_code=10)
                         then begin
                                reset_peg_menu_entry.Click;
                                gocalc(0,0);                    // calc new pegx
                              end;
                    end;

                 1: begin
                      xing_type_i:=0;             // parallel...
                      retpar_i:=1;

                      turnout_road_i:=1;       // long turnout road needed.

                      snap_exit_to_return_curve_menu_entry.Enabled:=True;
                    end;

                 2: begin
                      if retpar_i=1 then turnout_road_i:=0;  // 0.93.a changing from parallel, assume long turnout road not now needed.
                      xing_type_i:=1;             // curviform...
                      retpar_i:=0;
                      snap_exit_to_return_curve_menu_entry.Enabled:=False;

                      if (peg_code=7) or (peg_code=10) or (peg_code=108)    // 205e  108 CESP added
                         then begin
                                reset_peg_menu_entry.Click;
                                gocalc(0,0);                    // calc new pegx
                              end;
                    end;

                 3: begin                    // generic...
                      if retpar_i=1 then turnout_road_i:=0;  // 0.93.a changing from parallel, assume long turnout road not now needed.
                      xing_type_i:=-1;
                      retpar_i:=0;

                      generic_was_short_swapped:=False;  // 228a

                      snap_exit_to_return_curve_menu_entry.Enabled:=False;

                      if (peg_code=7) or (peg_code=10) or (peg_code=108)    // 205e  108 CESP added
                         then begin
                                reset_peg_menu_entry.Click;
                                gocalc(0,0);                    // calc new pegx
                              end;
                    end;

               else run_error(52);
  end;//case

  other_k3n_i:=0;             //  init other wanted flag.
  case xing_k_i of            //  set required crossing angle.
            0: k3n:=4;
            1: k3n:=4.5;
            2: k3n:=4.75;
            3: k3n:=5;
            4: k3n:=5.25;
            5: k3n:=5.5;
            6: k3n:=5.75;
            7: k3n:=6;
            8: k3n:=6.25;
            9: k3n:=6.5;
           10: k3n:=7;
           11: k3n:=7.5;
           12: k3n:=8;
           13: k3n:=9;
           14: k3n:=10;
           15: k3n:=12;
           16: other_k3n_i:=1;           // he wants some other angle.
          else run_error(53);
  end;//case


  n1:=-1;      // in case not used.
  n2:=-1;
  n3:=-1;

  n:=0;        // keep compiler happy

  if other_k3n_i=1
     then begin
            n:=putdim('',0,'V - crossing  angle  1:',k3n,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
            if n<0 then EXIT;
            n1:=n;
          end;

  if (xing_type_i=0) and (entry_straight_code=1)  //  she wants to set sl...
     then begin
                    // mod 227a   zero ok,  was  no zero

            n:=putdim('',1,'fixed  length  of  entry  straight  in  front  of  FP',fixed_sl,True,True,False,False);   // no neg, no preset, zero ok, don't terminate on zero.
            if n<0 then EXIT;
            n2:=n;
          end;
  if (xing_type_i<1) and (retpar_i=1)   //  return curve, parallel crossing...
     then begin
            if xing_ret_i=1        //  he wants to set the parallel centres.
               then begin
                      n:=putdim('',1,'turnout  road  track  centres',cpi.retcent_pi,True,False,True,False);           // no neg, preset ok, no zero, don't terminate on zero.
                      if n<0 then EXIT;
                      n3:=n;
                    end
               else cpi.retcent_pi:=cpi.trtscent_pi;    // as adjacent TS spacing.
          end;

  if (n1+n2+n3)>(0-3) then ok:=getdims('crossing','',pad_form,n,od)
                      else ok:=False;

  if (n1>=0) and (ok=True)
     then begin
            if od[n1]<(0.5-minfp)    // 227e
               then begin
                      if alert(6,'php/108    invalid  V - crossing  angle',
                                 'The V-crossing angle cannot be less than 1:0.5  (RAM)',
                                 '','','','','cancel','change  angle  to  1:0.5  and  continue',0)=6
                         then begin
                                k3n:=0.5;
                                set_xing_k_i;      // set selector list index to match k3n.
                              end
                         else EXIT;
                    end
               else begin
                      k3n:=od[n1];      // angle ok.
                      set_xing_k_i;     // set selector list index to match k3n.
                    end;
          end;

  if (n2>=0) and (ok=True) then begin
                                  fixed_sl:=od[n2];
                                  if fixed_sl<0 {ABS(fw*k3n)} then fixed_sl:=0;  // mods 227a ABS(fw*k3n);   // minimum sl to ensure knuckle is on the straight (if straight crossing).
                                end
                           else fixed_sl:=def_req;

  if (n3>=0) and (ok=True) then cpi.retcent_pi:=od[n3]
                           else cpi.retcent_pi:=def_req;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//______________________________________________________________________________________

procedure Tpad_form.curving_data_menu_entryClick(Sender: TObject);

             // ask nomrad, etc.
const
  rad_help_str:string='      Constant  Curving  Radius'
   +'||Enter a radius dimension in millimetres onto which the whole template will be curved. This radius will apply along the full length of the main road of a turnout'
   +' template and any approach or exit tracks.'
   +'||The radius is measured to the track centre-line.'

   +'||If the radius figure is positive the curving will be in the same direction as the hand of the turnout: a left-hand turnout will curve to the left and a right-hand'
   +' turnout will curve to the right. If the radius is negative the turnout will curve in the opposite direction to the hand, producing a Y-effect turnout.'

   +'||If a straight template is wanted, enter a slash "/".'

   +'||The curving radius can also be quickly adjusted by means of the F6 mouse action, select the ACTION > MOUSE ACTIONS:GEOMETRY > ADJUST CURVING RADIUS ONLY menu item (F6).'

   +'||Bear in mind that despite appearances a left-hand turnout curved to the right remains a left-hand turnout, with a left-hand switch deflection to (and consequently a reduced speed restriction'
   +' over) the turnout road on the left, and a constant radius in the main running road on the right.'

   +'||N.B. Plain track is also handed, so take care to enter a positive or negative radius as required. The hand of the current plain track is shown in the information panel.';

  transgo_help_str:string='      Transition  Curving  Data'
   +'||Enter the required length and radius settings in mm. It is usually easier to adjust transition curves using the mouse actions.'
   +'||The pre-set dimensions (available by entering a forward slash "/") are these:'
   +'||Initial Radius pre-set = STRAIGHT.'
   +'||Final Radius pre-set = STRAIGHT, unless the Initial Radius is straight, in which case 660ft radius (10 chains) scale.'
   +'||Length along Initial Radius pre-set = zero.'
   +'||Length along Transition Zone pre-set = 66ft (1 chain) scale.'
   +'||For more information, please click the button below and refer to the general transition help notes.';

var
  n:integer;
  od:Toutdim;
  temp:extended;
  dummy:extended;

begin
  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

try
  if spiral=False        // fixed radius curving...
     then begin
            repeat
              n:=putdim(  rad_help_str,1,'constant  radius  at  the  track  centre-line',nomrad,False,False,True,False);    // neg ok, no preset, 0 not allowed, don't terminate on zero.
              if n<>0 then EXIT;
              if getdims('constant  curving  radius',{ycurv_help_str+'|||'+}rad_help_str,pad_form,n,od)=True
                 then begin
                        if od[0]=def_req then od[0]:=max_rad; // straight pre-set. //660*scale;              // 660ft = 10 chains.
                        if check_radius(True,od[0])=False then CONTINUE;
                        nomrad:=od[0];
                        BREAK;
                      end
                 else BREAK;
            until 0<>0;

          end
     else begin    // transition curving...
            repeat
              n:=putdim(transgo_help_str,1,'1st  ( initial )  radius  at  the  track  centre-line',nomrad1,False,False,True,False); // neg ok, preset OK, 0 not allowed, don't terminate on zero.
              n:=putdim(transgo_help_str,1,'2nd  ( final )  radius  at  the  track  centre-line',nomrad2,False,False,True,False);   // neg ok, preset OK, 0 not allowed.
              n:=putdim(transgo_help_str,1,'length  along  1st  ( initial )  radius',os,False,False,False,False);         // neg ok, preset OK, 0 OK.
              n:=putdim(transgo_help_str,1,'length  along  transition  zone',tst,True,False,False,False);    // no neg, preset OK, 0 OK.
              if n<>3 then EXIT;
              if getdims('transition  curve  settings',
                          transition_help_str+'||||'+rad_help_str{+'||||'+ycurv_help_str},
                          pad_form,n,od)=True
                 then begin
                        if od[0]=def_req then od[0]:=max_rad;    // straight.
                        if od[1]=def_req
                           then begin
                                  if ABS(od[0])>=max_rad_test then od[1]:=660*scale   // 660ft (10 chains) if first rad is straight.
                                                              else od[1]:=max_rad;    // straight.
                                end;

                        if od[2]=def_req then od[2]:=0;                  // nil initial length.
                        if od[3]=def_req then od[3]:=66*scale;           // transition length 66ft (1 chain).

                        if check_radius(True,od[0])=False then CONTINUE;

                        if check_radius(True,od[1])=False then CONTINUE;

                        temp:=od[0]-od[1];

                        if ABS(temp)>minfp            // no good if rads equal.
                           then begin

                                  if ABS(od[0]*od[1]*od[3]/temp)<max_spiral_constant
                                     then begin                    //  ok, change settings.
                                            nomrad1:=od[0];
                                            nomrad2:=od[1];
                                            os:=od[2];
                                            tst:=ABS(od[3]);       //  transition length cannot be negative.
                                            BREAK;
                                          end
                                     else if alert(6,'  transition  too  gentle ...',
                                        '1st (initial) radius = '+captext(od[0])+' mm'
                                       +'|2nd (final) radius = '+captext(od[1])+' mm'
                                       +'|Transition zone length = '+round_str(od[3],2)+' mm'
                                       +'||( spiral constant = '+round_str(od[0]*od[1]*od[3]/temp/1.0E6,4)+' )'
                                       +'||These settings would create a transition curve which is too gentle to be generated without error.'
                                       +'||Try reducing the smaller radius slightly and/or increasing the larger radius slightly and/or shortening the transition zone.'
                                       +'||For more information click the PROGRAM > EXPERT > TRANSITION MATHS > MAX SPIRAL... item on the PROGRAM PANEL menus.',
                                        '','','','','cancel','re-try',0)=5 then BREAK;

                                end
                           else if alert(6,'    equal  radii ...',
                                        '1st (initial) radius = '+captext(od[0])+' mm'
                                       +'|2nd (final) radius = '+captext(od[1])+' mm'
                                       +'||A transition curve cannot be generated if these two radii are equal.'
                                       +'||If you want a constant curving radius, click the'
                                       +'|GEOMETRY > CONSTANT RADIUS menu item.',
                                        '','','','','cancel','re-try',0)=5 then BREAK;
                      end
                 else BREAK;
            until 0<>0;
          end;
finally
  peg_curve;             //  adjust shifts and rotates for current peg position.
  redraw(True);          //  redraw new radius onto peg.
end;//try
end;
//__________________________________________________________________________________________

procedure Tpad_form.slewing_data_menu_entryClick(Sender: TObject);

const
  help_slews_str:string='      Start of Slewing Zone'
  +'||Enter the required distance in mm from the datum end of the template to the start of the slewing zone. This setting can also be adjusted by mouse action SHIFT+CTRL-F5.'
  +'||If a negative dimension is entered, the start or all of the slewing zone will not be shown and the datum end of the template will be within or beyond the slewing zone.'
  +'||If the pre-set dimension is requested (enter a "/" slash), the start of the slewing zone is set to zero. (Slewing starts at the template datum.)'
  +'||While slewing is in force the start of the slewing zone is indicated by a double-arrowhead mark across the track.'
  +'||For more general information about slewing click the button below.';

  help_slewl_str:string='      Length of Slewing Zone'
  +'||Enter the required length of the slewing zone in mm. The length should be made as long as possible to ease the slewing radius between the slewed and unslewed sections.'
  +' This is especially important when the slew occurs on a sharp curve. This setting can also be adjusted by mouse action SHIFT+CTRL-F6.'
  +'||The minimum length of the slewing zone is equal to the current amount of slew, and will be reset to this if you enter a shorter dimension.'
  +' (If it is important to have a shorter slewing zone, you must reduce the amount of slew accordingly. This limit is to prevent calculation problems, it will be a very unusual template which is affected by it.)'
  +'||If the pre-set dimension is requested (enter a "/" slash), the length of the slewing zone is calculated to give a radius at each end of the slewing zone (for straight track) of 500ft scale.'
  +' If the slewing zone is in curved track the radius at one end will be less than this, and at the other end it will be more than this.'
  +'||While slewing is in force the end of the slewing zone is indicated by a double-fork mark across the track.'
  +'||For more general information about slewing click the button below.';

  help_slew_str:string='      Amount of Slew'
  +'||Enter the required slew (sideways shift) in mm. This setting can also be adjusted by mouse action CTRL-F7.'
  +'||If a positive dimension is entered, the slew will be in the same direction as the hand of the template. If a negative dimension is entered the slew will be in the opposite direction.'
  +'||If the pre-set dimension is requested (enter a "/" slash), the amount of slew is set to match the current turnout-side adjacent track spacing.'
  +'||For more general information about slewing click the button below.';

  help_slew_stretch_str:string='      Mode  2  Slew  Factor'

  +'||If you enter zero, slewing will be changed to Mode 1.'
  +'||If you enter any other figure, slewing will be changed to Mode 2, and the figure entered will be used as the slew factor.'

  +'||When using slewing mode 2, reducing this figure eases the reverse curve at the centre of the slewing zone.'
  +'||Moderately increasing this figure eases the curves at each end of the slewing zone.'
  +'||The sensible range of figures is 5-200. The pre-set figure is 100. The minimum and maximum figures are 1-500.'
  +'||It is easier to see the effect of changes if you adjust this factor by mouse action, select the ACTION > MOUSE ACTIONS CONTROL > ADJUST MODE 2 SLEW FACTOR menu item.'
  +'||For more general information about the slewing modes click the button below.';

var
  n:integer;
  od:Toutdim;
  temp:extended;
  dummy:extended;
  slew_factor_value:extended;

begin
  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

  if slew_mode=1 then slew_factor_value:=0                  // mode 1
                 else slew_factor_value:=slew2_kmax*50;     // mode 2


     putdim(       help_slews_str,1,'length  ( along  track )  to  start  of  slew',slew_s,False,False,False,False);          // neg ok, preset ok, zero ok, don't terminate on zero.
     putdim(       help_slewl_str,1,                    'length  of  slewing  zone',slew_l, True,False,True,False);           // no neg, preset ok, no zero, don't terminate on zero.
     putdim(        help_slew_str,1,                             'amount  of  slew',slew,False,False,False,False);            // neg ok, preset ok, zero ok, don't terminate on zero.
  n:=putdim(help_slew_stretch_str,0,'slewing  factor  for  mode  2  ( 0  for  mode  1 )',slew_factor_value, True,False,False,False);  // no neg, preset ok, zero ok, don't terminate on zero.

  if n<>3 then EXIT;
  if getdims('slewing',slew_help_str+'||For more information about the slew settings, click the HELP flag for each one.',pad_form,n,od)=True
     then begin
            slew_s:=od[0];
            slew_l:=od[1];
            slew:=od[2];

            if od[3]=0
               then slew_mode:=1       // change to mode 1.
               else begin
                      slew_mode:=2;                               // change to mode 2.
                      if od[3]=def_req then slew2_kmax:=2         // default factor.
                                       else slew2_kmax:=od[3]/50;
                    end;
          end;

  if slew=def_req then slew:=trtscent;     // default slew to adjacent track.
  if slew_s=def_req then slew_s:=0;
  if slew_l=def_req
     then begin
            case slew_mode of
              1: begin
                   temp:=500*scale*ABS(slew)*SQR(Pi)/2;     // set default length for 500ft scale slewing rads.
                   if temp>minfp then slew_l:=SQRT(temp)
                                 else slew_l:=600;          // ???  600 mm otherwise.
                 end;
              2: slew_l:=ABS(slew)*10;                      // arbitrary.
            end;//case
          end;

  if slew_l<ABS(slew) then slew_l:=ABS(slew);   // arbitrary minimum. (can't go neg).
  if slew_l<1 then slew_l:=1;                   // 1 mm safety minimum (div by zero).

  if slew2_kmax>10 then slew2_kmax:=10;         // sensible max, min...
  if slew2_kmax<0.02 then slew2_kmax:=0.02;

  enable_slewing(slew_mode,False);   // also does peg_curve and redraw.
end;
//____________________________________________________________________________________________

procedure Tpad_form.basic_turnout_menu_entryClick(Sender: TObject);

begin
  xorg:=0;                                // remove any aproach track;
  turnout_i:=0;                           // length free. default overall length.
  reset_peg_menu_entry.Click;             // Ctrl-0 position.
  turnout_road_i:=0;

  fit_current_only_menu_entry.Click;
  clear_transform_data;
  show_and_redraw(True,True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.pad_quit_menu_entryClick(Sender: TObject);

begin
  control_room_form.quit_menu_entry.Click;
end;
//______________________________________________________________________________________

procedure Tpad_form.sb_grid_paper_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=0;
  sb_grid_paper_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                        // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.sb_black_white_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=1;
  sb_black_white_menu_entry.Checked:=True;   // radio item.
  do_rollback:=False;                        // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.sb_red_yellow_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=2;
  sb_red_yellow_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                        // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.sb_silver_grey_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=3;
  sb_silver_grey_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                         // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.sb_yellow_blue_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=4;
  sb_yellow_blue_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                         // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.sb_white_black_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=5;
  sb_white_black_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                         // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.sb_teal_aqua_menu_entryClick(Sender: TObject);

begin
  sb_colour_use:=6;
  sb_teal_aqua_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;                         // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.mm_scalebar_menu_entryClick(Sender: TObject);

begin
  scale_bar_i:=1;                            //  show mm scalebar.
  mm_scalebar_menu_entry.Checked:=True;      //  radio item.
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.inch_scalebar_menu_entryClick(Sender: TObject);

begin
  scale_bar_i:=2;                                  //  show inch scalebar.
  inch_scalebar_menu_entry.Checked:=True;          //  radio item.
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.hide_scalebar_menu_entryClick(Sender: TObject);

begin
  scale_bar_i:=0;                              //  hide the scalebar.
  hide_scalebar_menu_entry.Checked:=True;      //  radio item.
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.timber_numbering_font_menu_entryClick(Sender: TObject);

begin
  pad_timber_font_label.Font.Assign(get_font('choose  a  font  and  text  colour  for  the  trackpad  timber  numbering',pad_timber_font_label.Font,True));
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.grid_font_menu_entryClick(Sender: TObject);

begin
  pad_form.Font.Assign(get_font('choose  a  font  and  text  colour  for  the  grid  labels',pad_form.Font,True));
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.screengrid_on_menu_entryClick(Sender: TObject);

begin
  screengrid_flag:=True;
  do_rollback:=False;                            // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.screengrid_off_menu_entryClick(Sender: TObject);

begin
  screengrid_flag:=False;
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.H0_US_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_H0US_i);
end;
//_________________________________________________________________________________________

procedure Tpad_form.H0_EU_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_H0EU_i);
end;
//_________________________________________________________________________________________

procedure Tpad_form.OOBF_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_00BF_i);
end;
//______________________________________________________________________________

procedure Tpad_form.D0GA_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_00DGI_i);       // 227a
end;
//_________________________________________________________________________________________

procedure Tpad_form.EM_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_EM_i);
end;
//_______________________________________________________________________________________

procedure Tpad_form.S4P4_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_S4P4_i);
end;
//_______________________________________________________________________________

procedure Tpad_form.OSF_menu_entryClick(Sender: TObject);   // 0.79.a

begin
  quick_gauge_click(t_0SF_i);
end;
//______________________________________________________________________________

procedure Tpad_form.GOGF_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_GOGF_i);
end;
//___________________________________________________________________________________

procedure Tpad_form.S7_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_S7_i);
end;
//______________________________________________________________________________

       // added in 0.93.a ...

procedure Tpad_form.N_NMRA_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_N_NMRA_i);
end;
//______________________________________________________________________________

procedure Tpad_form.N_UK_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_N_UK_i);
end;
//______________________________________________________________________________

procedure Tpad_form.S2_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_S2_i);
end;
//______________________________________________________________________________

procedure Tpad_form.S_3p5_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_S3p5_i);
end;
//______________________________________________________________________________

procedure Tpad_form.OOSF_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_00SF_i);
end;
//______________________________________________________________________________

procedure Tpad_form.OO3D_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_003D_i);
end;
//______________________________________________________________________________

procedure Tpad_form.minimize_panelClick(Sender: TObject);

begin
  Application.Minimize;       //  hide TEMPLOT on PAUSE key   556a MW
end;
//______________________________________________________________________________

procedure Tpad_form.S_gauge_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_S_gauge_i);
end;
//______________________________________________________________________________

procedure Tpad_form.OMF_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_0MF_i);
end;
//______________________________________________________________________________

procedure Tpad_form.P32_menu_entryClick(Sender: TObject);   // 212a

begin
  quick_gauge_click(t_P32_i);
end;
//______________________________________________________________________________

procedure Tpad_form.gauge1F_menu_entryClick(Sender: TObject);

begin
  quick_gauge_click(t_1F_i);
end;
//______________________________________________________________________________

procedure Tpad_form.other_gauges_menu_entryClick(Sender: TObject);

begin
  show_gauge_details:=False;    // show the full list.
  gauge_form.Tag:=0;            // permit warning panel.
                                // can't show modal, or exact/custom data-entry does not work.
  gauge_form.Show;              // allow him to set new gauge and/or scale.
  gauge_form.BringToFront;
end;
//____________________________________________________________________________________

procedure Tpad_form.gauge_mint_new_menu_entryClick(Sender: TObject);

begin
  gauge_form.mint_new_radio_button.Checked:=True;    // radio item.
  gauge_form.retain_length_checkbox.Enabled:=True;   // 208d
  retain_length_on_mint_menu_entry.Enabled:=True;    // 208d
end;
//______________________________________________________________________________

procedure Tpad_form.gauge_match_original_menu_entryClick(Sender: TObject);

begin
  gauge_form.match_original_radio_button.Checked:=True;      // radio item.
  gauge_form.retain_length_checkbox.Enabled:=False;          // 208d
  retain_length_on_mint_menu_entry.Enabled:=False;           // 208d
end;
//______________________________________________________________________________

procedure Tpad_form.retain_length_on_mint_menu_entryClick(Sender: TObject);       // 208d

begin
  retain_length_on_mint_menu_entry.Checked:= NOT retain_length_on_mint_menu_entry.Checked;
  gauge_form.retain_length_checkbox.Checked:=retain_length_on_mint_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.gauge_details_menu_entryClick(Sender: TObject);

begin
  show_gauge_details:=True;     // show the current details.
  gauge_form.Tag:=0;            // permit warning panel.
                                // can't show modal, or exact/custom data-entry does not work.
  gauge_form.Show;              // allow him to set new gauge and/or scale.
  gauge_form.BringToFront;
end;
//_______________________________________________________________________________________

procedure Tpad_form.view_box_menu_entryClick(Sender: TObject);

begin
  if Sender=box_menu then main_menu.Click;               // 224a
  keep_form.Show;          //  show the storage box.
  keep_form.BringToFront;
end;
//______________________________________________________________________________________

procedure Tpad_form.library_viewer_menu_entryClick(Sender: TObject);

begin
  lib_form.lib_listbox.Visible:=(any_library>0);
  lib_form.Show;
end;
//______________________________________________________________________________

procedure Tpad_form.modify_gauge_menu_entryClick(Sender: TObject);

const
  helpg_str:string='    `0Modified  Track  Gauge`9'
                  +'||Enter the new track gauge in millimetres.'

                  +'||rp.gif Modifying the track gauge disrupts the template alignment.'
                  +' If this template is part of a track plan, it will need to be realigned to the adjacent templates after modifying the track gauge.'

                  +'||green_panel_begintree.gif Changes made here affect only the distance between the rails, i.e. they do not affect the current scale ratio or timbering sizes.'
                  +'||To change to a different gauge/scale combination (for example to change from N Gauge to 0 Gauge), or to establish a custom gauge/scale setting,'
                  +' cancel this and select the `0GAUGE`1 menu items instead.green_panel_end'

                  +'|If you change the track gauge dimension here, the information panel will continue to show the original gauge name, i.e. it would continue'
                  +' to show, say, EM even though you had changed the track gauge here to, say, 18.83 mm, and the flangeway gaps and other settings would continue to be those for EM Gauge.'

                  +'||The option of changing the track gauge here is intended for making minor adjustments only, for example to introduce some gauge-widening on sharp curves.';
var
  n:integer;
  od:Toutdim;

begin                                                                  // no negatives, preset ok, 0 ok, don't terminate on zero.
    n:=putdim(helpg_str,1,'modified  track  gauge  between  rails',cpi.gauge_pi,True,False,False,False);
    if n<>0 then EXIT;
    if getdims('modified  track  gauge','',pad_form,n,od)=True
       then cpi.gauge_pi:=od[0];

    get_cpi;
    redraw(True);          //  redraw.
end;

//________________________________________________________________________________________

procedure Tpad_form.checks_menu_entryClick(Sender: TObject);   // get new CHECK RAILS data.

const
  helpf_str:string='    `0Modified  Crossing-Flangeway  Gap`9'
                  +'||Enter the new crossing-flangeway gap (CF) dimension for the|V-crossing wing rails and K-crossing wing rails in millimetres.'

                  +'||rp.gif Modifying the crossing-flangeway gap disrupts the alignment of templates which have a `0regular`3 type V-crossing.'
                  +' If such a template is part of a track plan, it will need to be realigned to the adjacent templates after modifying the crossing-flangeway gap.'

                  +'||green_panel_begintree.gif Changes made here affect only the crossing-flangeway gaps, i.e. they do not affect the current scale ratio or track gauge.'
                  +'||To change to a different gauge/scale combination (for example to change from N Gauge to 0 Gauge), or to establish a custom gauge/scale setting,'
                  +' cancel this and select the `0GAUGE`1 menu items instead.green_panel_end'

                  +'|If you change the flangeway gap dimension here, the information panel will continue to show the original gauge name, i.e. it would continue'
                  +' to show, say, EM even though you had changed the flangeway gap here to, say, 1.5 mm, and the track gauge and other settings would continue to be those for EM Gauge.'

                  +'||The option of changing the flangeway gap here is intended for making minor adjustments (e.g. for non-standard rolling stock) and for setting narrow-gauge requirements.'

                  +'||green_panel_begintree.gif  This flangeway gap setting is also used on the printed paper templates for showing the check rails. For construction purposes the check rails should be set'
                  +' using check gauge tools and not by reference to the printed gap.'
                  +'||rp.gif For experimental 3-D chairing, adjustments to the check rail gap should be made on the `0DXF/STL export > rail`z dialog and not here (e.g. for gauge-widened curves).green_panel_end';

  helpe_str:string='    `0Modified  Flangeway  End  Gap`9'
                  +'||Enter the size in millimetres of the increased gap at the end of the flared-out sections of the check and wing rail ends.'
                  +'||green_panel_begintree.gif This dimension can be easily adjusted on each check rail by mouse action. Click the `0real > adjust check rails...`1 menu item.green_panel_end'
                  +'|This dimension will be reset if you change the current gauge/scale setting.';
var
  n:integer;
  od:Toutdim;

begin                                                                  // no negatives, preset ok, 0 ok, don't terminate on zero.
    n:=putdim(helpf_str,1,'modified  crossing - flangeway  gap',  cpi.fw_pi,True,False,False,False);
    n:=putdim(helpe_str,1,'flare - out  ( flangeway  end  gap )',cpi.fwe_pi,True,False,False,False);
    if n<>1 then EXIT;
    if getdims('modified  crossing-flangeway  gap  settings ...','',pad_form,n,od)=True
       then begin
              if (od[0]<>def_req) and ((od[0]>(g/2)) or (od[0]<0)) then od[0]:=cpi.fw_pi;    // no change on invalid data.
              if (od[1]<>def_req) and ((od[1]>(g/2)) or (od[1]<0)) then od[1]:=cpi.fwe_pi;   // no change on invalid data.
              cpi.fw_pi:=od[0];
              cpi.fwe_pi:=od[1];
            end;

    get_cpi;
    redraw(True);          //  redraw.
end;
//_________________________________________________________________________________________

procedure Tpad_form.roll_rails_by_menu_entryClick(Sender: TObject);

const
  help_roll1_str:string='     Rolling  Plain  Track  Rail  Lengths  and  Sleepers.'
  +'||This function permits the insertion of a partial rail length between the nominal "joint" `0CTRL-1`2 end of a plain track template and the first actual rail joint.'
  +'||This is useful when it is desired to have the correct rail lengths and sleeper spacing pattern bridging adjacent templates.'
  +'||Sleepers within this partial rail length are numbered with an "N" prefix.'

  +'||Sleepers within this length can be omitted if desired, leaving only the rails. This is useful for example where a branch track is connected to an adjusted V-crossing exit,'
  +' over the long crossing timbers. The options for this are at `0real > timbering > rolled-in timbering >`1 menu item.'

  +'||Enter the fraction of a full rail length as a percentage. Valid figures are in the range 0% to 100% of the current rail length setting.'
  +'||The current rail length setting (in full-size inches) is ';

  help_roll2_str:string=' inches per rail.||To change the current rail length, click the `0REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS...`1 menu item.'
  +'||The section of the template from the first rail joint to the `0CTRL-0`2 datum end is called the "rolled-out" length.'
  +'||The section of the template comprising the inserted partial rail length from the first rail joint to the `0CTRL-1`2 end is called the "rolled-in" length.'

  +'||This function is available only for plain track templates. If it is desired to roll the rail lengths within the approach or exit tracks of a turnout template,'
  +' these should first be split off as separate plain track templates: `0TOOLS > MAKE SPLIT > `1 menu items.'
  +'||Handy Hint:'
  +'|Rolling rail lengths and sleepers is usually more conveniently done by mouse action `0CTRL-F4`2 `0roll rails and sleepers`3,'
  +' the INFORMATION panel shows the current percentage of rail length and number of sleepers inserted.'
  +'||N.B. If bonus timbers are added to a rolled template `0REAL > TIMBERING > BONUS TIMBERS > ADD ONE`1 menu item, they will appear initially at the first rail joint,'
  +' from where they can then be shoved to the desired position. Existing bonus timbers will roll along with the other sleepers.';

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(help_roll1_str+round_str(railen[pt_i],2)+help_roll2_str,4,'roll  rail  lengths  and  sleepers  by',tb_roll_percent,True,True,False,False);   // no negative, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('rolling  plain  track  rail  lengths','',pad_form,n,od)=True
     then begin
            tb_roll_percent:=od[0];
            if tb_roll_percent<0 then tb_roll_percent:=0;
            if tb_roll_percent>100 then tb_roll_percent:=100;
            if peg_code=-2 then peg_code:=-1;                     // so peg on joints can re-intialise.
            redraw(True);
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.adjacent_spacing_ts_menu_entryClick(Sender: TObject);

begin
  way_spacings_top_str:='    TS  spacing';       // 226c
  way_spacings_cancel_str:='cancel     ';        // 226c

  do_way_spacings(False,1);  // 226c
end;
//_____________________________________________________________________________

procedure Tpad_form.adjacent_spacing_ms_menu_entryClick(Sender: TObject);

begin
  way_spacings_top_str:='    MS  spacing';      // 226c
  way_spacings_cancel_str:='cancel     ';       // 226c

  do_way_spacings(False,-1);  // 226c
end;
//______________________________________________________________________________

procedure Tpad_form.lengths_mm_menu_entryClick(Sender: TObject);

begin
  lengths_click(False);
end;
//___________________________________________________________________________________________

procedure Tpad_form.swings_in_degs_menu_entryClick(Sender: TObject);

begin
  lengths_click(True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.lengths_rails_menu_entryClick(Sender: TObject);

const
  pt_rail1_str:string='  Overall  Length  of  Plain Track  in  Scale  Rail  Lengths'
  +'||Enter the required overall length of the current plain track template as a number of scale rail lengths.'
  +'||The current rail length setting (in full-size prototype inches) is ';

  pt_rail2_str:string=' inches per rail.||To change the current rail length, click the REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS... menu item.'
  +'||The template length can also be entered in model mm or (if a curved template) as an angular swing in degrees.'
  +' To do so cancel this and click the GEOMETRY > TEMPLATE LENGTHS (IN MM)... or GEOMETRY > SWING ANGLES (IN DEGREES)... menu items instead.';


var
  rail_len_mm:extended;
  n:integer;
  od:Toutdim;
  old_xorg,dummy:extended;

begin
  if plain_track=False then EXIT;      //??? should be disabled.

  rail_len_mm:=railen[pt_i]*inscale;
  if rail_len_mm<minfp then EXIT;      // div 0.

  old_xorg:=xorg;

  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

  n:=putdim(pt_rail1_str+round_str(railen[pt_i],2)+pt_rail2_str,0,'overall  length  of  plain  track  in  rail  lengths',xorg/rail_len_mm,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;

  if getdims('plain  track  length  in  scale  rail  lengths','',pad_form,n,od)=True
     then begin
            xorg:=ABS(od[0]*rail_len_mm);
            turnoutx:=xorg;

            if turnoutx>turnoutx_max
               then begin
                      turnoutx:=turnoutx_max;
                      xorg:=turnoutx;
                    end;

            if peg_code<>0
               then begin
                      if spiral=True then os:=os+xorg-old_xorg;           //  os transition start changes with xorg ditto.
                      if slewing=True then slew_s:=slew_s+xorg-old_xorg;  //  slewing ditto
                    end;

            pegx:=pegx-old_xorg+xorg;         // update the peg if free...
            udpegx:=udpegx-old_xorg+xorg;

            turnout_i:=1;      // length locked at new turnoutx.

            gocalc(0,0);       //  to calc new pegx.
            peg_curve;         //  adjust shifts and rotates for current peg position.

            do_rollback:=True;
            show_and_redraw(True,True);
          end;
end;
//_______________________________________________________________________________________

procedure Tpad_form.normal_scaling_menu_entryClick(Sender: TObject);

begin
  normal_scaling_menu_entry.Checked:=True;         // radio item.
  set_output_size_menu_entry.Checked:=True;        // radio item.
  out_factor:=1.0;
  fit_single_sheet:=False;
  redraw(True);                                    // for the page margins on the pad.
end;
//__________________________________________________________________________________________

procedure Tpad_form.double200_menu_entryClick(Sender: TObject);

begin
  tick_not_normal;
  double200_menu_entry.Checked:=True;  // radio item.
  out_factor:=2;
end;

procedure Tpad_form.A3_A4_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  A3_A4_menu_entry.Checked:=True;  // radio item.
  out_factor:=SQRT(0.5);
end;

procedure Tpad_form.half50_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  half50_menu_entry.Checked:=True;  // radio item.
  out_factor:=0.5;
end;

procedure Tpad_form.third3333_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  third3333_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/3;
end;

procedure Tpad_form.quarter25_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  quarter25_menu_entry.Checked:=True;  // radio item.
  out_factor:=0.25;
end;

procedure Tpad_form.fifth20_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  fifth20_menu_entry.Checked:=True;  // radio item.
  out_factor:=0.2;
end;

procedure Tpad_form.eighth125_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  eighth125_menu_entry.Checked:=True;  // radio item.
  out_factor:=0.125;
end;

procedure Tpad_form.tenth10_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  tenth10_menu_entry.Checked:=True;  // radio item.
  out_factor:=0.1;
end;

procedure Tpad_form.sixteenth625_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  sixteenth625_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/16;
end;

procedure Tpad_form.twentieth5_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  twentieth5_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/20;
end;

procedure Tpad_form.fortieth25_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  fortieth25_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/40;
end;

procedure Tpad_form.N2ft1667_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  N2ft1667_menu_entry.Checked:=True;  // radio item.
  out_factor:=2/12;
end;

procedure Tpad_form.N1ft833_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  N1ft833_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/12;
end;

procedure Tpad_form.N05ft417_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  N05ft417_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/24;
end;

procedure Tpad_form.N025ft208_menu_entryClick(Sender: TObject);
begin
  tick_not_normal;
  N025ft208_menu_entry.Checked:=True;  // radio item.
  out_factor:=1/48;
end;
//______________________________________________________________________________

procedure Tpad_form.fit_single_page_menu_entryClick(Sender: TObject);

begin
  if (print_pages_top_origin<>0) or (print_pages_left_origin<>0)
     then begin
            if alert(2,'    fit  single  page  -  page  origin  is  offset',
                       'Your current page origin is not at the drawing datum.'
                      +'||In order to fit the drawing on a single page the page origin will be reset.',
                       '','','','','cancel  single  page  -  no  changes    ','O K',0)=5
               then EXIT;
          end;

  print_pages_top_origin:=0;
  print_pages_left_origin:=0;

  fit_single_page_menu_entry.Checked:=True;  // radio item.

  set_output_size_menu_entry.Checked:=True;  // radio item.

  fit_single_sheet:=True;                    // flag that we need to calculate it.
  page_info(True,True,False,0);              // 0.93.a for the page outlines on the pad.
  redraw(True);                              // for the page outlines on the pad.
end;
//______________________________________________________________________________

procedure Tpad_form.set_output_size_menu_entryClick(Sender: TObject);

const
  help_str:string='     Print  Size'
    +'||Enter here the scaling factor to be used when printing the template pages.'

    +'||For example, if you want to print your template reduced to three-quarters of the normal size ( 3/4 ), change the'
    +' value showing to 75 % and then click ENTER. This might be useful when planning your railway'
    +' if the full-size printouts would be too large to handle comfortably. You can also print'
    +' enlargements of the template by entering values greater than 100 %. If you enter 250 % for example,'
    +' you would get a printout two-and-a-half times the normal size.||To change back to normal printing,'
    +' click the|PRINT > PRINT NORMAL SIZE 100% menu item or enter a scaling factor of 100 % ( or a slash " / "'
    +' which will select 100 % as the pre-set ).'

    +'||Do not confuse this scaling factor with the zoom facility on the trackpad, which is a design aid'
    +' and applies only to the screen display.'

    +'||A scaling factor entered here affects only the printed output, and has no effect on the recorded dimensions of your templates or on anything'
    +' which appears on the screen, other than the page outlines and the print pages preview.'
    +'||If you print at a reduced size (less than 100 %), the thickness of the printed rail edges is reduced accordingly. If this is'
    +' not desired, increase the rail edge thickness beforehand. If you print at an enlarged size (more than 100 %) the line thickness'
    +' remains unchanged.'
    +'||N.B. ! It is not sensible to use this printout scaling facility as a means of changing the track gauge for a'
    +' usable construction template, as the flangeway and other dimensions are likely to be incorrect, the timbering will not be to scale, and the printed grid sizes'
    +' will be wrong. Select the proper TEMPLATE > GAUGE AND SCALE > combination from the list instead, or enter a custom size.'
    +'||Do not use this scaling factor as a means of correcting the printed sizes from your printer - do a proper printer calibration instead'
    +' (PRINT > PRINTER CALIBRATION menu item).'
    +'||Handy Hints:'
    +'|If you have an A4 printer it can be useful to print at or near 70.71 %. You can then enlarge the pages on a photocopier from A4 to A3 size'
    +' to produce an accurate full-size A3 template. Photocopiers vary, so you will need to experiment to find the exact scaling factor which gives accurate results.'
    +'||When you are more concerned with the fit on the pages than the exact scaling factor, you can adjust the print size by mouse action.'
    +' Select the ACTION > MOUSE ACTIONS: TRACKPAD > ADJUST PRINT SIZE menu item. The page outlines on the pad will change accordingly.';
var
  n:integer;
  od:Toutdim;

begin
  tick_not_normal;
  set_output_size_menu_entry.Checked:=True;        // radio item.

  n:=putdim(help_str,4,'print  output  scaling  factor',out_factor*100,True,False,True,False);  // no neg, preset ok, no zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('print  size  setting','',pad_form,0,od)=True
     then begin
            if od[0]=def_req then out_factor:=1
                             else out_factor:=od[0]/100;
          end;

  if out_factor=1 then normal_scaling_menu_entry.Click;    // change menu ticks.
  redraw(True);                                            // for the pad page outlines
end;
//___________________________________________________________________________________________

procedure Tpad_form.portrait_menu_entryClick(Sender: TObject);

begin
  portrait_menu_entry.Checked:=True;    //  radio item.
  paper_way:=1;
  Printer.Orientation:=poPortrait;
  page_info(True,True,False,0);
  do_rollback:=False;          // no need to put this change in rollback register on redraw.
  redraw(True);                //  change page outlines.
end;
//___________________________________________________________________________

procedure Tpad_form.landscape_menu_entryClick(Sender: TObject);

begin
  if banner_paper=True
     then begin
            if alert(1,'    sideways (landscape)  -  banner  printing',
                       'Templot is currently set for printing on banner or roll paper.'
                      +'||For all standard printers banner printing from Templot works correctly only if the printer is set for upright (portrait) printing.',
                       '','','sideways  ( landscape )  printing  on  banner  paper','','cancel','',0)=5
               then EXIT;
          end;                            // !!! don't call single_sheets.click   - infinite loop via printer_setup !!!

  Printer.Orientation:=poLandscape;
  landscape_menu_entry.Checked:=True;    //  radio item.
  paper_way:=2;

  page_info(True,True,False,0);     //  for the page outlines.
  do_rollback:=False;               //  no need to put this change in rollback register on redraw.
  redraw(True);                     //  change page outlines.
end;
//___________________________________________________________________________

procedure Tpad_form.thin_printed_lines_menu_entryClick(Sender: TObject);

begin
  thin_printed_lines_menu_entry.Checked:=True;     // radio item.

  printgrid_thick:=0.02;             // mm all minimum thickness... (calcs to 1 dot minimum).
  printmargin_thick:=0.02;           // mm.
  printtimber_thick:=0.02;           // mm.
  printrail_thick:=0.02;             // mm
  printmark_thick:=0.02;             // mm.
  printshape_thick:=0.02;            // mm.
  printpicborder_thick:=0.02;        // mm.
  printcl_thick:=0.02;               // mm.  0.79.a
end;
//____________________________________________________________________________________

procedure Tpad_form.normal_printed_lines_menu_entryClick(Sender: TObject);

begin
  normal_printed_lines_menu_entry.Checked:=True;     // radio item.

  printpicborder_thick:=0.02;        // mm minimum thickness. (1 dot).
  printgrid_thick:=0.02;             // mm minimum thickness. (1 dot).

  printmargin_thick:=0.22;           // mm.   (3 dots at 300/360 dpi)
  printshape_thick:=0.22;            // mm.   (3 dots at 300/360 dpi)

  printtimber_thick:=0.16;           // mm.   (2 dots at 300/360 dpi)
  printrail_thick:=0.16;             // mm    (2 dots at 300/360 dpi)
  printmark_thick:=0.16;             // mm.   (2 dots at 300/360 dpi)

  printcl_thick:=0.02;               // mm minimum 1 dot   0.79.a
end;
//___________________________________________________________________________________

procedure Tpad_form.thick_printed_lines_menu_entryClick(Sender: TObject);

begin
  thick_printed_lines_menu_entry.Checked:=True;     // radio item.

  printgrid_thick:=0.16;             // mm.
  printpicborder_thick:=0.16;        // mm.

  printmargin_thick:=0.5;            // mm.
  printtimber_thick:=0.3;            // mm.
  printrail_thick:=0.3;              // mm
  printmark_thick:=0.3;              // mm.
  printshape_thick:=0.4;             // mm.

  printcl_thick:=0.16;               // mm 2 dots   0.79.a
end;
//___________________________________________________________________________________

procedure Tpad_form.set_line_thicknesses_menu_entryClick(Sender: TObject);

const
  thick_str:string='For more information about setting the printed line thicknesses, click the button below.';

var
  n:integer;
  od:Toutdim;

begin
     putdim(thick_str,1,'printed  grid  line  thickness',                 printgrid_thick,True,True,True,False);  // no neg, no preset, no zero, don't terminate on zero.
     putdim(thick_str,1,'printed  trim-margin  line  thickness',        printmargin_thick,True,True,True,False);  // ditto...
     putdim(thick_str,1,'printed  background-shape  line  thickness',    printshape_thick,True,True,True,False);
     putdim(thick_str,1,'printed  picture-shape  border  thickness', printpicborder_thick,True,True,True,False);
     putdim(thick_str,1,'printed  rail-edge  line  thickness',            printrail_thick,True,True,True,False);
     putdim(thick_str,1,'printed  timber  outline  thickness',          printtimber_thick,True,True,True,False);
     putdim(thick_str,1,'printed  track  centre-line  thickness',           printcl_thick,True,True,True,False);   // 0.79.a
  n:=putdim(thick_str,1,'other  printed  marks  line  thickness',         printmark_thick,True,True,True,False);

  if n<>7 then EXIT;        // 0.79.a   was 6
  if getdims('printed  templates  -  line  thicknesses',line_thick_help_str,pad_form,n,od)=True
     then begin
              printgrid_thick:=od[0];
            printmargin_thick:=od[1];
             printshape_thick:=od[2];
         printpicborder_thick:=od[3];
              printrail_thick:=od[4];
            printtimber_thick:=od[5];
                printcl_thick:=od[6];  // 0.79.a
              printmark_thick:=od[7];

            set_line_thicknesses_menu_entry.Checked:=True;   // radio item.

            detail_mode_form.line_thickness_button.Tag:=1;    // don't use default gauge size if he has set it himself
          end;
end;
//_________________________________________________________________________________________

procedure Tpad_form.adjust_line_thickness_menu_entryClick(Sender: TObject);

begin
  adjust_line_thickness_menu_entry.Checked:= NOT adjust_line_thickness_menu_entry.Checked;
end;
//_________________________________________________________________________________________

procedure Tpad_form.line_thickness_help_menu_entryClick(Sender: TObject);

begin
  help(0,line_thick_help_str,'');
end;
//__________________________________________________________________________________________

procedure Tpad_form.print_solid_timber_infill_menu_entryClick(Sender: TObject);

begin
  print_timb_infill_style:=3;
  print_solid_timber_infill_menu_entry.Checked:=True;         // radio item.
end;
//_______________________________________________________

procedure Tpad_form.print_crosshatched_timber_infill_menu_entryClick(Sender: TObject);

begin
  print_timb_infill_style:=2;
  print_crosshatched_timber_infill_menu_entry.Checked:=True;         // radio item.
end;
//_______________________________________________________

procedure Tpad_form.print_hatched_timber_infill_menu_entryClick(Sender: TObject);

begin
  print_timb_infill_style:=1;
  print_hatched_timber_infill_menu_entry.Checked:=True;         // radio item.
end;
//_______________________________________________________

procedure Tpad_form.print_blank_timber_infill_menu_entryClick(Sender: TObject);

begin
  print_timb_infill_style:=4;
  print_blank_timber_infill_menu_entry.Checked:=True;         // radio item.
end;
//________________________________________________________

procedure Tpad_form.print_no_timber_infill_menu_entryClick(Sender: TObject);

begin
  print_timb_infill_style:=0;
  print_no_timber_infill_menu_entry.Checked:=True;         // radio item.
end;
//_________________________________________________________________________________________

procedure Tpad_form.print_timber_infill_menu_entryClick(Sender: TObject);

   // 207a added for prefs...

begin
  case print_timb_infill_style of
    0: print_no_timber_infill_menu_entry.Checked:=True;            // radio item.
    1: print_hatched_timber_infill_menu_entry.Checked:=True;       // radio item.
    2: print_crosshatched_timber_infill_menu_entry.Checked:=True;  // radio item.
    3: print_solid_timber_infill_menu_entry.Checked:=True;         // radio item.
    4: print_blank_timber_infill_menu_entry.Checked:=True;         // radio item.
  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.print_platform_solid_infill_menu_entryClick(Sender:TObject);

begin
  print_platform_infill_style:=3;                               // 0.93.a
  print_platform_solid_infill_menu_entry.Checked:=True;         // radio item.
end;
//_________________________________________________________

procedure Tpad_form.print_platform_crossed_infill_menu_entryClick(Sender:TObject);

begin
  print_platform_infill_style:=2;                               // 0.93.a
  print_platform_crossed_infill_menu_entry.Checked:=True;       // radio item.
end;
//_________________________________________________________

procedure Tpad_form.print_platform_hatched_infill_menu_entryClick(Sender:TObject);

begin
  print_platform_infill_style:=1;                               // 0.93.a
  print_platform_hatched_infill_menu_entry.Checked:=True;       // radio item.
end;
//_________________________________________________________

procedure Tpad_form.print_platform_blank_infill_menu_entryClick(Sender:TObject);

begin
  print_platform_infill_style:=4;                               // 0.93.a
  print_platform_blank_infill_menu_entry.Checked:=True;         // radio item.
end;
//_________________________________________________________

procedure Tpad_form.print_platform_no_infill_menu_entryClick(Sender:TObject);
begin

  print_platform_infill_style:=0;                               // 0.93.a
  print_platform_no_infill_menu_entry.Checked:=True;            // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.print_platform_infill_menu_entryClick(Sender: TObject);

    // 207a  added for prefs...

begin
  case print_platform_infill_style of
    0: print_platform_no_infill_menu_entry.Checked:=True;            // radio item.
    1: print_platform_hatched_infill_menu_entry.Checked:=True;       // radio item.
    2: print_platform_crossed_infill_menu_entry.Checked:=True;       // radio item.
    3: print_platform_solid_infill_menu_entry.Checked:=True;         // radio item.
    4: print_platform_blank_infill_menu_entry.Checked:=True;         // radio item.
  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.print_rail_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_prc:=get_colour('choose  a  colour  for  the  printed  rail-edges',save_prc);
  if (save_prc=0) and (black_white=False) then save_prc:=virtual_black_colour;  // !!! HP driver bug.
end;
//_________________________________________________________________________________________

procedure Tpad_form.print_timber_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_ptc:=get_colour('choose  a  colour  for  the  printed  timber  outlines',save_ptc);
end;
//_______________________________________________________________________________________

procedure Tpad_form.rail_infill_colours_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_priccu:=get_colour('choose  a  colour  for  the  control  template  printed  rail  infill',save_priccu);
end;
//_______________________________________________________________________________________

procedure Tpad_form.print_timber_infill_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_ptic:=get_colour('choose  a  colour  for  the  printed  timbering  infill',save_ptic);
end;
//___________________________________________________________________________________________

procedure Tpad_form.print_grid_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_grc:=get_colour('choose  a  colour  for  the  printed  grid  lines',save_grc);
end;
//______________________________________________________________________________________

procedure Tpad_form.margin_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pmc:=get_colour('choose  a  colour  for  the  printed  trim  margins',save_pmc);
end;
//________________________________________________________________________________________

procedure Tpad_form.print_guide_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pgc:=get_colour('choose  a  colour  for  the  printed  guide  marks',save_pgc);
end;
//________________________________________________________________________________________

procedure Tpad_form.print_joint_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pjc:=get_colour('choose  a  colour  for  the  printed  rail-joint  marks',save_pjc);
end;
//____________________________________________________________________________________________

procedure Tpad_form.print_align_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pac:=get_colour('choose  a  colour  for  the  printed  radial  end  marks',save_pac);
end;
//___________________________________________________________________________________________

procedure Tpad_form.printed_shapes_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_psc:=get_colour('choose  a  colour  for  the  printed  background  shapes',save_psc);
end;
//__________________________________________________________________________________________

procedure Tpad_form.set_single_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pbg:=get_colour('choose  a  single  colour  for  the  printed  background  templates',save_pbg);
  if (save_pbg=0) and (black_white=False) then save_pbg:=virtual_black_colour;  // !!! HP driver bug.

  mapping_colours_print:=-1;    // assume he wants to use it. 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD marker colour instead, -1=single colour.
end;
//___________________________________________________________________________________________

procedure Tpad_form.bgnd_rail_infill_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_pricbg:=get_colour('choose  a  colour  for  the  background  templates  printed  rail  infill',save_pricbg);
end;
//___________________________________________________________________________________________

procedure Tpad_form.print_platform_edge_colour_menu_entryClick(Sender: TObject);      // 0.93.a platforms ..

begin
  if check_black_white=True then EXIT;
  save_priplatedge:=get_colour('choose  a  colour  for  the  printed  platform  edges',save_priplatedge);
  if (save_priplatedge=0) and (black_white=False) then save_priplatedge:=virtual_black_colour;  // !!! HP driver bug.
end;
//______________________________________________________________________________

procedure Tpad_form.print_platform_infill_colour_menu_entryClick(Sender: TObject);

begin
  if check_black_white=True then EXIT;
  save_priplatfill:=get_colour('choose  a  colour  for  the  printed  platform  infill',save_priplatfill);
end;
//______________________________________________________________________________

procedure Tpad_form.print_font_menu_entryClick(Sender: TObject);

begin
  print_labels_font.Assign(get_font('choose  a  font  and  text  colour  for  the  printed  grid  labels',print_labels_font,True));

  if (print_labels_font.Color<>clBlack) and ((black_white=True) or (grey_shade=True))
     then begin
            if check_black_white=True then EXIT;   // font colour will be reset on printing.
          end;

  save_fc:=print_labels_font.Color;
end;
//__________________________________________________________________________________________

procedure Tpad_form.print_timber_numbers_font_menu_entryClick(Sender: TObject);

begin
  print_timber_numbers_font.Assign(get_font('choose  a  font  and  text  colour  for  the  printed  timber  numbering',print_timber_numbers_font,True));

  if (print_timber_numbers_font.Color<>clBlack) and ((black_white=True) or (grey_shade=True))
     then begin
            if check_black_white=True then EXIT;   // font colour will be reset on printing.
          end;

  save_tnfc:=print_timber_numbers_font.Color;
end;
//_________________________________________________________________________________________

procedure Tpad_form.corner_page_numbers_font_menu_entryClick(Sender: TObject);

  // 0.93.a  added

begin
  print_corner_page_numbers_font.Assign(get_font('choose  a  font  and  text  colour  for  the  printed  corner  page  numbers  and  date',print_corner_page_numbers_font,True));

  if (print_corner_page_numbers_font.Color<>clBlack) and ((black_white=True) or (grey_shade=True))
     then begin
            if check_black_white=True then EXIT;   // font colour will be reset on printing.
          end;

  save_cpnfc:=print_corner_page_numbers_font.Color;
end;
//______________________________________________________________________________

procedure Tpad_form.print_preview_menu_entryClick(Sender: TObject);

var
  problem_str:string;
  i:integer;

begin
  if paper_bunching=True then cancel_paper_bunching; // don't want bunching in the preview.

  problem_str:='      Page-Map  Problems'
  +'||There is a problem showing the pages of your control template.'
  +'||Has your printer paper-size been set up correctly?'
  +'||Have you shifted the template completely below or to the left of the trim margins?'
  +'||Or shifted the template beyond the printing area of '+IntToStr(sheet_down_c+1)+' pages long by '+IntToStr(sheet_across_c+1)+' pages wide?'
  +'||If so, please adjust the page origin or trim margins accordingly.'
  +'||Have you changed the page origin so far that all the pages are empty? If so click the PRINT > PAGE ORIENTATION / ORIGIN > RESET PAGE ORIGIN menu item.'
  +'||If none of these apply, click the TEMPLATE > NEW TEMPLATE (QUICK SET)... menu item.';

  cancel_adjusts(False);           //  in case he bumps the mouse.
  Caption:='                 show  output  page-map  for  the  control  template';

  print_entire_pad_flag:=False;    //  only the control template.

  if print_preview(True,False,0)=True
     then begin
             case paper_way of
                         1: preview_form.Caption:='   page-map  for  the  control  template   ( end - run )';
                         2: preview_form.Caption:='   page-map  for  the  control  template   ( side - run )';
             end;//case

             if banner_paper=True then preview_form.Caption:=preview_form.Caption+'    ( banner  paper )';

             if out_factor=1 then preview_form.scaling_label.Caption:='at normal size ( 100 % )'
                             else preview_form.scaling_label.Caption:='scaled at  '+round_str(out_factor*100,2)+' % of normal size';

             if (fit_single_sheet=True) and (out_factor<>1)
                then preview_form.scaling_label.Caption:=preview_form.scaling_label.Caption+'  ( to fit a single page ).'
                else preview_form.scaling_label.Caption:=preview_form.scaling_label.Caption+'.';

             preview_form.origin_label.Caption:='page origin :  X = '+round_str(print_pages_top_origin,2)+' mm    Y = '+round_str(print_pages_left_origin,2)+' mm';

             do_show_modal(preview_form);     // 212a  ShowModal                                      // draw the preview and wait for the OK.
             if preview_form.ModalResult=mrYes then pad_form.print_control_template_menu_entry.Click; // 245a was print_control_template(False,False);    // 0.91.d
           end
      else begin
              repeat
                i:=alert(6,'      problem  with  page-map',
                 'Sorry, unable to show the pages of your control template.',
                 '','?  help','printer  setup...','clear  shift  data','cancel  page-map / print','B-6  LH  turnout  reset',2);
                case i of
                    2: alert_help(0,problem_str,'');
                    3: printer_setup(False,False);
                    4: clear_transform_data;
                    6: error_b6_lh_reset;

                end;//case
              until i<>2;
           end;
  cancel_adjusts(False);                                                //  re-draw and update the caption.

  redraw_pad(False,False);         // force a redraw when finished.
end;
//_________________________________________________________________________________________

procedure Tpad_form.straight_template_menu_entryClick(Sender: TObject);

var
  dummy1:extended;

begin
  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy1);    // save current peg data for peg_curve calcs.

  nomrad:=max_rad;
  spiral:=False;

  if (peg_code=200) or (peg_code=220) then gocalc(0,0);    // to keep peg on geometrical tangent points.

  peg_curve;                 // straight turnout on peg.
  redraw_pad(True,True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.constant_radius_menu_entryClick(Sender: TObject);

begin
  if (ABS(nomrad)>max_rad_test) and (spiral=False)   // straight template.
     then curving_data_menu_entry.Click              // ask new radius instead.
     else fix_radius(clrad_at_x(pegx),True);         // set nomrad from centre-line radius at peg.
end;
//__________________________________________________________________________________________

procedure Tpad_form.transition_template_menu_entryClick(Sender: TObject);

begin
  transition_previous_menu_entry.Enabled:= NOT spiral;    // no effect if transition already in force.
  move_transition_zone_menu_entry.Enabled:=spiral;
  change_transition_zone_menu_entry.Enabled:=spiral;
  swap_transition_rads_menu_entry.Enabled:=spiral;
  zero_trans_zone_menu_entry.Enabled:=spiral;
  normalize_transition_menu_entry.Enabled:=(spiral=True) and ( (os<0) or ((os+tst)>turnoutx) );
end;
//________________________________________________________________________________________

procedure Tpad_form.transition_previous_menu_entryClick(Sender: TObject);

begin
  transition_clicked(0);    // use existing trans radii.
end;

//_____________________________

procedure Tpad_form.transition_from_straight_menu_entryClick(Sender: TObject);

begin
  transition_clicked(1);
end;
//_____________________________

procedure Tpad_form.transition_to_straight_menu_entryClick(Sender: TObject);

begin
  transition_clicked(2);
end;
//_____________________________

procedure Tpad_form.c_curve_shrinking_transition_menu_entryClick(Sender: TObject);

begin
  transition_clicked(3);
end;
//_____________________________

procedure Tpad_form.c_curve_expanding_transition_menu_entryClick(Sender: TObject);

begin
  transition_clicked(4);
end;
//_____________________________

procedure Tpad_form.s_curve_transition_menu_entryClick(Sender: TObject);

begin
  transition_clicked(5);
end;
//_________________________________________________________________________________________

procedure Tpad_form.new_transition_settings_menu_entryClick(Sender: TObject);

begin
  transition_clicked(0);           // first set up to use existing trans radii.
  gocalc(0,0);                     // do peg calcs.
  curving_data_menu_entry.Click;   // go ask new settings and redraw.
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_transition_popup_entryClick(Sender: TObject);

begin
  make_transition_click(1);
end;
//______________________________________________________________________________

procedure Tpad_form.make_link_help_popup_entryClick(Sender: TObject);

const
  str:string='php/160`0            Making  Link  Tracks`9'
            +'||There are 2 ways to create a track linking between two existing templates:'
            +'||1. `0make simple link`1 for yards and sidings - similar to the result when clipping together items of set-track.'
            +'||2. `0make transition link`1 for fast running lines - a smooth flowing transition curve. Scroll down for more notes.'
            +'||For more explanation, diagrams and videos,|click `0more information online`a above.'
            +'||<HR>|';

var
  simple_help_str:string;

begin
  simple_help_str:='`0    1.  Make  Simple  Link`9'
  +'||"Simple" means making a tangential alignment at the template boundaries, similar to the result when clipping together items of set-track.'

  +'||A simple link like this creates an abrupt change of radius at the template boundary, suitable only for low speeds.'
  +' When a smooth flowing connection is needed for fast running lines, it is better to use the `0make transition link`1 function instead.'

  +'||The simple link function creates a template linking from the current peg position on the control template, to make a tangential join with the selected background template, and modifies the background template to fit.'
  +'||Before using this function, it is necessary to help Templot by creating a dummy "guide" template. The guide template should lead towards the required background template, with its fixing peg at the opposite end, like this:'

  +'||<IMG SRC="'+exe_str+'internal\hlp\make_simple1_476x136.png">'

  +'|Such a guide template might typically be the result of using the `0tools > make branch track`1 function, as above.'

  +'||The peg position is important, but the length and radius of the guide template do not matter. It is helpful to curve it towards the background template, so that you can see roughly how the link track is likely to fit.'

  +'||Select the required background template, and then click the|`0PEG / ALIGN TOOLS > make simple link`z item on its menu.'
  +'|The result will be:'

  +'||<IMG SRC="'+exe_str+'internal\hlp\make_simple2_476x136.png">'

  +'|The link track template has been created and stored, and the background template has been modified to fit. A fresh length of plain track is available in the control template ready for further track design work.'
  +'||<HR>|`0    2.  Make  Transition  Link`9||';

  if help(0,str+simple_help_str+make_trans_help_str,'about  transition  curves')=1 then pad_form.transition_help_menu_entry.Click;
end;
//_________________________________________________________________________________________

procedure Tpad_form.make_simple_link_popup_entryClick(Sender: TObject);   // 223c

begin
  make_tangential_link;  // 223c
  clicked_keep_index:=-1;                         // so can popup again.
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.transition_help_menu_entryClick(Sender: TObject);

begin
  if help(0,transition_help_str,'about  the  make  transition  link  function')=1 then pad_form.make_link_help_popup_entry.Click;
end;
//_________________________________________________________________________________________

procedure Tpad_form.trans_calc_timerTimer(Sender: TObject);

                  // do calcs while the wait message shows modal.
var
  code:integer;

begin
  trans_calc_timer.Enabled:=False;   // one-shot only.

  code:=trans_calc_timer.Tag;        // required action code.

  case code of

        0: trans_calc_timer.Tag:=make_transition_from_current_calcs;    // return error code the same way.

     -1,1: make_double_track_calcs(trans_calc_timer.Tag);  // code is +1 or -1 for side of track.

        9: trans_calc_timer.Tag:=do_auto_trans_swing_adjust(make_trans_data.old_rad2_orgx, make_trans_data.old_rad2_orgy);    // return error code the same way.

       15: trans_calc_timer.Tag:=do_degs_length_adjust(length_in_degs,length_in_mm);    // return error code the same way.

  end;//case

  wait_form.Close;        // calculating done.
end;
//_______________________________________________________________________________________

procedure Tpad_form.lock_switch_popup_entryClick(Sender: TObject);

begin
  lock_switch_popup_entry.Checked:=True;       // radio item.
  switch_free:=False;
  xing_free:=True;                             // only one can be locked.
  info_form.info_gauge_panel.Color:=clFuchsia; // remind him something's locked.
end;
//_______________________________________________________________________________________

procedure Tpad_form.lock_xing_popup_entryClick(Sender: TObject);

begin
  lock_xing_popup_entry.Checked:=True;         // radio item.
  xing_free:=False;
  switch_free:=True;                           // only one can be locked.
  info_form.info_gauge_panel.Color:=clFuchsia; // remind him something's locked.
end;
//_______________________________________________________________________________________

procedure Tpad_form.show_popup_menu_entryClick(Sender: TObject);

begin
  pad_popup_menu.Popup(Screen.DesktopLeft+Screen.DesktopWidth div 3, Screen.DesktopTop+Screen.DesktopHeight div 8);    //  display the popup menu.
end;
//_________________________________________________________________________________________

procedure Tpad_form.unlock_both_popup_entryClick(Sender: TObject);

begin
  unlock_both;
end;
//_______________________________________________________________________________________

procedure Tpad_form.black_and_white_printing_menu_entryClick(Sender: TObject);

begin
  set_black_and_white;   // return not needed.
end;
//_____________________________________________________________________________________
(* OT2024

procedure Tpad_form.grey_shade_printing_menu_entryClick(Sender: TObject);

var
  i,colour_depth_bits:integer;

begin
  colour_depth_bits:=GetDeviceCaps(Printer.Handle,BITSPIXEL)*GetDeviceCaps(Printer.Handle,PLANES);

  if colour_depth_bits=1
     then begin
            i:=alert(6,'    monochrome  printer',
                       'Your current printer is a black & white printer, or has been set for black & white printing only.',
                       '','','ignore  this  message','printer  setup ...','cancel  grey - shade  printing','',0);
            if i=4 then begin
                          printer_setup(False,False);
                          EXIT;
                        end;

            if i=5 then EXIT;
          end;

  black_white:=False;
  printed_grid_solid_menu_entry.Click;

  grey_shade:=True;

  print_form.reset_button.Click;

  grey_shade_printing_menu_entry.Checked:=True;     // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.colour_printing_menu_entryClick(Sender: TObject);

var
  i,colour_depth_bits:integer;

begin
  colour_depth_bits:=GetDeviceCaps(Printer.Handle,BITSPIXEL)*GetDeviceCaps(Printer.Handle,PLANES);

  if colour_depth_bits=1
     then begin
            i:=alert(6,'    monochrome  printer',
                       'Your current printer is not a colour printer, or has not been set for colour printing.',
                       '','','ignore  this  message','printer  setup ...','cancel  colour  printing','',0);
            if i=4 then begin
                          printer_setup(False,False);
                          EXIT;
                        end;

            if i=5 then EXIT;
          end;

  black_white:=False;
  printed_grid_solid_menu_entry.Click;

  grey_shade:=False;

  print_form.reset_button.Click;

  colour_printing_menu_entry.Checked:=True;        //  radio item
end;
//________________________________________________________________________________________
*)

procedure Tpad_form.convert_to_plain_track_menu_entryClick(Sender: TObject);

                 // replace turnout with plain track on same alignment.
begin
  if plain_track=True then EXIT;           // ? shouldn't get here, menu disabled for plain track.

  rail_options_form.restore_all_button.Click;  // 211c

  pt_convert(True);  // show it
end;
//_________________________________________________________________________________________

procedure Tpad_form.invert_curving_rads_menu_entryClick(Sender: TObject);

begin
  invert_curving;
  redraw_pad(True,True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.force_symmetry_menu_entryClick(Sender: TObject);      // 227a

begin
  if force_symmetry(True,max_rad)=True
     then redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.invert_handing_menu_entryClick(Sender: TObject);

begin
  invert_handing;
  redraw_pad(True,True);
end;
//____________________________________________________________________________________

procedure Tpad_form.guide_marks_menu_entryClick(Sender: TObject);

begin
  guide_marks_menu_entry.Checked:= NOT guide_marks_menu_entry.Checked;   // toggle guide marks calc.
  guide_marks:=guide_marks_menu_entry.Checked;

  redraw(True);               //  do a re-draw
end;
//_____________________________________________________________________________________

procedure Tpad_form.rad_end_marks_menu_entryClick(Sender: TObject);

begin
  rad_end_marks_menu_entry.Checked:= NOT rad_end_marks_menu_entry.Checked;  // toggle rad ends calc.
  rad_ends:=rad_end_marks_menu_entry.Checked;

  redraw(True);               //  do a re-draw
end;
//________________________________________________________________________________________

procedure Tpad_form.joint_marks_menu_entryClick(Sender: TObject);

begin
  joint_marks_menu_entry.Checked:= NOT joint_marks_menu_entry.Checked;   // toggle joint marks calc.
  joint_marks:=joint_marks_menu_entry.Checked;

  redraw(True);               //  do a re-draw
end;
//______________________________________________________________________________

procedure Tpad_form.switch_drive_markx_menu_entryClick(Sender: TObject);

begin
  switch_drive_markx_menu_entry.Checked:= NOT switch_drive_markx_menu_entry.Checked;
  switch_drive_markx:=switch_drive_markx_menu_entry.Checked;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.nearest_menu_entryClick(Sender: TObject);

begin
  entry_straight_code:=0;                        // re-set auto fits.
  xing_ret_i:=0;

  generate_nearest:=True;
  gocalc(0,0);
  generate_nearest:=False;

  redraw(True);
end;
//______________________________________________________________________________________________

function warn_if_no_timbers:boolean;  // 208c

begin
  if cl_only=True
     then begin
            if alert(3,'    no  timbers  showing',
                       'There are no timbers showing because the control template has been set to show track centre-lines only.'
                      +'||Do you want to restore the rails and timbers for this template?',
                       '','','','','no','yes  -  restore  rails  and  timbers',0)=5
               then begin
                      RESULT:=False;
                      EXIT;
                    end;

            pad_form.normal_track_centre_lines_menu_radio.Click;   // radio item.
          end;

  RESULT:=True;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.equalized_incremental_menu_entryClick(Sender: TObject);

begin
  timbers_equalized:=True;
  equalizing_fixed:=False;
  no_timbering:=False;

  timbers_centralized_menu_entry.Click;   // 0.93.a change to equalized

  want_timbers_back_on:=warn_if_no_timbers;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.equalized_constant_menu_entryClick(Sender: TObject);

begin
  timbers_equalized:=True;
  equalizing_fixed:=True;
  no_timbering:=False;

  timbers_centralized_menu_entry.Click;   // 0.93.a change to equalized

  want_timbers_back_on:=warn_if_no_timbers;
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.square_on_menu_entryClick(Sender: TObject);

begin
  timbers_equalized:=False;
  square_on_angled:=False;
  no_timbering:=False;

  timbers_in_line_menu_entry.Click;   // 0.93.a change to in-line

  want_timbers_back_on:=warn_if_no_timbers;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.angled_on_menu_entryClick(Sender: TObject);

begin
  timbers_equalized:=False;
  square_on_angled:=True;
  no_timbering:=False;

  timbers_in_line_menu_entry.Click;   // 0.93.a change to in-line

  want_timbers_back_on:=warn_if_no_timbers;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.half_diamond_timbering_style_menu_entryClick(Sender: TObject);

begin
  no_timbering:=False;
  want_timbers_back_on:=warn_if_no_timbers;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.no_timbering_menu_entryClick(Sender: TObject);

begin
  shove_timber_form.Close;
  no_timbering:=True;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.approach_sleepered_menu_entryClick(Sender: TObject);   // 218a

begin
  approach_rails_only:=False;                    // sleepers
  approach_sleepered_menu_entry.Checked:=True;   // radio item.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.approach_rails_only_menu_entryClick(Sender: TObject);  // 218a

begin
  approach_rails_only:=True;                      // sleepers
  approach_rails_only_menu_entry.Checked:=True;   // radio item.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.exit_sleepers_menu_entryClick(Sender: TObject);

begin
  exittb_i:=2;                              // sleepers
  exit_sleepers_menu_entry.Checked:=True;   // radio item.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.exit_timbers_menu_entryClick(Sender: TObject);

begin
 exittb_i:=1;                                // timbers
 exit_timbers_menu_entry.Checked:=True;      // radio item.
 redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.exit_no_timbers_menu_entryClick(Sender: TObject);

begin
  exittb_i:=0;                               // none
  exit_no_timbers_menu_entry.Checked:=True;  // radio item.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.rolled_in_sleepered_menu_entryClick(Sender: TObject);

begin
  rolled_in_sleepered:=True;    // sleepers present
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.rolled_in_rails_only_menu_entryClick(Sender: TObject);

begin
  rolled_in_sleepered:=False;   // rails only
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.timbers_centralized_menu_entryClick(Sender: TObject);

begin
  with cpi do begin
    mainside_ends_pi:=False;     // centralize.
    random_end_pi:=0;            // cancel any randomising.
    random_angle_pi:=0;
  end;//with

  timbers_centralized_menu_entry.Checked:=True;    // radio item

  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.timbers_in_line_menu_entryClick(Sender: TObject);

begin
  with cpi do begin
    mainside_ends_pi:=True;             // in-line.
    random_end_pi:=0;                   // cancel any randomizing.
    random_angle_pi:=0;
  end;//with

  timbers_in_line_menu_entry.Checked:=True;    // radio item

  redraw(True);
end;
//________________________________________________________________________________________

       // 218a ...


procedure Tpad_form.front_timbers_menu_entryClick(Sender: TObject);

begin
  include_front_timbers:= NOT include_front_timbers;
  redraw(True);
end;
//_____________________

procedure Tpad_form.switch_timbers_menu_entryClick(Sender: TObject);

begin
  include_switch_timbers:= NOT include_switch_timbers;
  redraw(True);
end;
//_____________________

procedure Tpad_form.closure_timbers_menu_entryClick(Sender: TObject);

begin
  include_closure_timbers:= NOT include_closure_timbers;
  redraw(True);
end;
//_____________________

procedure Tpad_form.xing_timbers_menu_entryClick(Sender: TObject);

begin
  include_xing_timbers:= NOT include_xing_timbers;
  redraw(True);
end;
//_____________________

procedure Tpad_form.pointwork_timbering_menu_entryClick(Sender: TObject);

begin
  front_timbers_menu_entry.Checked:=include_front_timbers;
  switch_timbers_menu_entry.Checked:=include_switch_timbers;
  closure_timbers_menu_entry.Checked:=include_closure_timbers;
  xing_timbers_menu_entry.Checked:=include_xing_timbers;
end;
//______________________________________________________________________________

procedure Tpad_form.timbering_data_menu_entryClick(Sender: TObject);

const
  helptl_str:string='    `0Plain  Track  Sleeper  Length`9|    `0Nominal  Turnout  Timber  Length`9'
     +'||The dimension entered here is used for plain track sleeper lengths and for the nominal length of turnout timbers.'
     +'||By "nominal" is meant that this length will apply only to the first few timbers at the front of the switch. The remaining turnout timbers increase in 6 inch increments as necessary to accommodate the rails.'
     +'||Enter the length dimension in full-size inches.'
     +'||For British standard-gauge bullhead track this dimension was normally 108 inches (9ft) in the pre-grouping era, and 102 inches (8ft-6in) subsequently.'
     +' But 9ft sleepers remained in use for many years after grouping and could still be found in yards and sidings to the end of the traditional steam railway.'
     +'||Templot is pre-set to draw 8ft-6in timbers. If the setting is changed to 9ft timbers, an additional mark is drawn on the printed templates showing the end positions for 8ft-6in timbers.'
     +'||The length of individual timbers can be changed using the <I>shove timbers</I> functions. Select the `0REAL > SHOVE TIMBERS`1 menu item and read the help notes.';

  helpsw_str:string='    `0Plain  Track  Sleeper  Width`9'
     +'||Enter a dimension in full-size inches for the width of the plain track sleepers.'
     +'||For British standard-gauge bullhead track this dimension is normally 10 inches.'
     +'||The width of individual sleepers can be changed subsequently using the `0REAL > SHOVE TIMBERS`1 functions.'
     +'||Some pre-grouping UK companies used sleepers 12 inches wide on each side of a rail joint. For this enter 10 inches here and 12 inches on the next line.'
     +'||The timbers in the switch front at the toe of a turnout (usually two of them, numbered J1 and J2) may be either plain track sleepers or turnout timbers, according to the design of the switch.'
     +'||If they are turnout timbers they will not be affected by changes to this plain track sleeper width setting. To reduce the width of them to match the plain track sleepers, use the <I>shove timbers</I> width functions,'
     +' or create a custom switch.';

  helpjw_str:string='    `0Plain  Track  Joint  Sleeper  Width`9'
     +'||Some pre-grouping UK companies used sleepers 12 inches wide on each side of a rail joint.'
     +'||Enter a dimension in full-size inches for the width of these joint sleepers (e.g. 12 inches).'
     +'||If wide joint sleepers are not wanted enter the same dimension here as on the previous line (e.g. 10 inches in UK) or enter zero (0).';

 helptw_str:string='    `0Turnout  Timber  Width`9'
   +'||Enter a dimension in full-size inches for the width of the turnout timbers.'
   +'||For British standard-gauge bullhead track this dimension is normally 12 inches.'
   +'||The width of individual timbers can be changed subsequently using the `0REAL > SHOVE TIMBERS`1 width functions.'
   +'||The timbers in the switch front at the toe of a turnout (usually two of them, numbered J1 and J2) may be either plain track sleepers or turnout timbers, according to the design of the switch.'
   +'||If they are plain track sleepers they will not be affected by changes to this turnout timber width setting. To widen them to match the turnout timbers, use the <I>shove timbers</I> width functions,'
   +' or create a custom switch.';

 helps_str:string='    `0Fill  Timber  Spacing`9'
   +'||Enter a dimension in full-size inches which will be the MAXIMUM timber spacing (centre-to-centre) for the timbers filling the space between the'
   +' heel of the switch and the wing rail joint. The actual spacing used is likely to be less than this in order to fit the space evenly with a whole number of timbers.'
   +'||If a constant spacing is not wanted, individual timbers can be re-positioned using the `0REAL > SHOVE TIMBERS`1 functions.'
   +'||To change the timber spacings in the switch, use the <I>shove timber</I> functions or click the `0REAL > SWITCH SETTINGS...`1 menu item and create a `0CUSTOM SWITCH`1.'
   +'||To change the timber spacings in the crossing, use the <I>shove timber</I> functions or click the `0REAL > CUSTOMIZE V-CROSSING >`1 menu items.'
   +'||To change the sleeper spacing for plain track, click the `0REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS...`1 menu item.'
   +'||Handy Hint:'
   +'|When the fill space is very short it can be difficult to find a setting for this maximum dimension which gives the desired result. It is often easier to leave the'
   +' pre-set dimension and use the `0REAL > SHOVE TIMBERS`1 menu item functions to set the timber positions manually.';

 helpofs_str:string='    `0Timber  Throw`9'
     +'||Enter a dimension in full-size inches for the distance by which all timbers are thrown across from their normal position.'
     +'||For all normal purposes this dimension is zero.'
     +'||It can be used as an aid to timber shoving for an entire template, for example in creating waybeams. The positive throw direction is from the MS main side towards the TS turnout side.';

 rend_help_str:string='      `0Timber  End  Randomizing`9'

  +'||Enter the maximum amount in FULL-SIZE INCHES by which a timber can be displaced endways from its correct position.'
  +' The actual displacement of each timber will be less than this, being a random amount between zero and this maximum.'
  +'||For standard-gauge main running lines, plain track is normally carefully laid and maintained so no end-randomizing is appropriate - enter zero.'
  +' For sidings and goods lines a figure up to about 2 inches will produce a realistic slight variation for plain track.'
  +'||For pointwork and junctions more variation is possible, up to about 4 inches.'
  +'||For narrow-gauge, industrial and light railways a figure up to about 6 inches will look in keeping, but more than this may generate a "crazy-track"'
  +' effect which begins to look silly.'
  +'||The pre-set amount is zero, meaning no randomizing of the timber ends and all timbers correctly placed.'
  +'||All randomizing is reset to zero each time you swap between IN-LINE and CENTRALIZED timber ends. If end-randomizing is more than about 2 inches, the'
  +' distinction between these two styles will be overwhelmed by the randomizing. See the general help below for more explanation.';


 twist_help_str:string='      `0Timber  Twist  Randomizing  Factor`9'

  +'||Enter a figure in the range 0 to 9.0 to set the maximum amount by which a timber can be twisted away from its correct alignment. Except where EQUALIZED timbering is in force'
  +' within a turnout, the correct alignment is normally square across the rails (SQUARE-ON). The maximum factor setting of 9.0 corresponds to a maximum twist of approximately 10 degrees,'
  +' but the actual twist of each timber will be less than this, being a random amount between zero and this maximum.'
  +'||For standard-gauge track the normal setting should be zero, or very close to zero, for properly laid and maintained track.'
  +'||For narrow-gauge, industrial and light railways a twist factor up to about 2 or 3 can be used, but more than this may generate a "crazy-track" effect which begins to look silly.'
  +'||The pre-set figure is zero, meaning no random twisting of the timbers and all timbers correctly aligned.'
  +'||If both twist and end-randomizing are used together, the settings may need to be reduced to maintain a realistic look. Compare your printed templates with photographs'
  +' of the real thing - randomizing can easily be overdone.'
  +'||All randomizing is reset to zero each time you swap between the IN-LINE and CENTRALIZED styles for the timber ends. See the general help notes below for more explanation.';

var
  n:integer;
  od:Toutdim;
  dummy_i:integer;

begin
     putdim(helptl_str,2,'plain-sleeper length (full-size inches)',cpi.tb_pi/inscale,True,False,True,False);        // inches, no neg, preset ok, no zero, don't terminate on zero.
     putdim(helpsw_str,2,'plain-sleeper width (full-size inches)',cpi.slwide_pi,True,False,False,False);            // no neg, preset ok, zero ok, don't terminate on zero.

     putdim(helpjw_str,2,'joint-sleeper width (full-size inches)',cpi.jt_slwide_pi,True,False,False,False);         // no neg, preset ok, zero ok, don't terminate on zero.  212a

     putdim(helptw_str,2,'turnout-timber width (full-size inches)',cpi.tbwide_pi,True,False,False,False);           // no neg, preset ok, zero ok, don't terminate on zero.

     putdim(helps_str,2,'fill timber spacing (maximum, full-size inches)',cpi.ftimbspmax_pi,True,False,True,False); // no neg, preset ok, no zero, don't terminate on zero.

     putdim(helpofs_str,2,'timber  throw (full-size inches)',cpi.tb_end_offset_pi,False,False,False,False);         // neg ok, preset ok, zero ok, don't terminate on zero.

     putdim(rend_help_str,2,'end-randomizing (full-size inches)',cpi.random_end_pi/inscale,True,False,False,False);       // inches, no neg, preset ok, zero ok.
  n:=putdim(twist_help_str,0,'timber twist randomizing factor (0 - 9.0)',cpi.random_angle_pi,True,False,False,False);     // no neg, preset ok, zero ok.

  if n<>7 then EXIT;

  if getdims('sleeper  and  timber  sizes  and  turnout  fill  spacing',timbering_help_str,pad_form,n,od)=True
     then begin
            if od[0]=def_req then cpi.tb_pi:=102*inscale        // preset 8ft-6in timbering. was 9ft pre 0.93.a
                             else cpi.tb_pi:=od[0]*inscale;

            if Abs(cpi.tb_pi-108*inscale)<minfp
               then begin
                      nine_foot:=True;
                      eight_foot_six:=False;
                      sleepers_9ft_menu_entry.Checked:=True;    // radio item.
                    end
               else begin
                      nine_foot:=False;                        // non 9ft-standard length.
                      if Abs(cpi.tb_pi-102*inscale)<minfp
                         then begin
                                sleepers_8ft6in_menu_entry.Checked:=True;         // radio item.
                                eight_foot_six:=True;
                              end
                         else begin
                                sleepers_otherlength_menu_entry.Checked:=True;   // radio item.
                                eight_foot_six:=False;
                              end;
                    end;

            if od[1]=def_req then cpi.slwide_pi:=10            // 10"
                             else cpi.slwide_pi:=od[1];

            if od[2]=def_req then cpi.jt_slwide_pi:=10                                 // 10" joint sleepers  212a
                             else if od[2]=0 then cpi.jt_slwide_pi:=cpi.slwide_pi
                                             else cpi.jt_slwide_pi:=od[2];

            if od[3]=def_req then cpi.tbwide_pi:=12            // 12"
                             else cpi.tbwide_pi:=od[3];

            if od[4]=def_req then cpi.ftimbspmax_pi:=30        // 30" ditto for closure space.
                             else cpi.ftimbspmax_pi:=od[4];

            if od[5]=def_req then cpi.tb_end_offset_pi:=0
                             else cpi.tb_end_offset_pi:=od[5];

            if od[6]=def_req then cpi.random_end_pi:=0
                             else cpi.random_end_pi:=od[6]*inscale;

            if od[7]=def_req then cpi.random_angle_pi:=0             //  preset no angle randomizing.
                             else cpi.random_angle_pi:=od[7];

               cpi.random_angle_pi:=limits(0,9,cpi.random_angle_pi,dummy_i);   //  force within limits.

          end;

  get_cpi;            // use these dims.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.sleepers_9ft_menu_entryClick(Sender: TObject);

begin
  sleepers_9ft_menu_entry.Checked:=True;        // radio item.
  cpi.tb_pi:=108*inscale;                       // 9ft timbering.
  nine_foot:=True;
  eight_foot_six:=False;
  get_cpi;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.sleepers_8ft6in_menu_entryClick(Sender: TObject);

begin
  sleepers_8ft6in_menu_entry.Checked:=True;    // radio item.
  cpi.tb_pi:=102*inscale;                      // 8ft 6in timbering.
  nine_foot:=False;
  eight_foot_six:=True;
  get_cpi;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.sleepers_otherlength_menu_entryClick(Sender: TObject);

begin
  sleepers_otherlength_menu_entry.Checked:=True;    // radio item.
  timbering_data_menu_entry.Click;
end;
//___________________________________________________________________________________________

procedure Tpad_form.plain_track_data_menu_entryClick(Sender: TObject);

begin
  plain_track_spacings_click;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.current_timber_centres_menu_entryClick(Sender: TObject);

begin
  if (current_timber_centres_menu_entry.Checked=False) and (timber_centres_menu_entry.Checked=False)
     then begin
            if alert(3,'  show  control  template  with  timber  centres',
                       'It is not possible to show the control template with timber centre-lines while this feature remains switched off in the GENERATOR SETTINGS.',
                       '','','','','cancel','change  generator  setting  -  timber  centres  on',0)=5
                       then EXIT;
                       timber_centres_menu_entry.Click;
          end;
  current_timber_centres_menu_entry.Checked:= NOT current_timber_centres_menu_entry.Checked;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.current_timber_numbers_menu_entryClick(Sender: TObject);

begin
  if (current_timber_numbers_menu_entry.Checked=False) and (timber_numbers_menu_entry.Checked=False)
     then begin
            if alert(3,'  show  control  template  with  timber  numbers',
                       'It is not possible to show the control template with timber numbers while this feature remains switched off in the GENERATOR SETTINGS.',
                       '','','','','cancel','change  generator  setting  -  timber  numbers  on',0)=5
                       then EXIT;
                       timber_numbers_menu_entry.Click;
          end;

  current_timber_numbers_menu_entry.Checked:= NOT current_timber_numbers_menu_entry.Checked;
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.current_timber_outlines_menu_entryClick(Sender: TObject);

begin
  if (current_timber_outlines_menu_entry.Checked=False) and (timber_outlines_menu_entry.Checked=False)
     then begin
            if alert(3,'    show  control  template  with  timber  outlines',
                       'It is not possible to show the control template with timber outlines while this feature remains switched off in the GENERATOR SETTINGS.',
                       '','','','','cancel','change  generator  setting  -  timber  outlines  on',0)=5
                       then EXIT;
                       timber_outlines_menu_entry.Click;
          end;
  current_timber_outlines_menu_entry.Checked:= NOT current_timber_outlines_menu_entry.Checked;
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.no_timbering_infill_menu_entryClick(Sender: TObject);

begin
  pad_timb_infill_style:=0;
  no_timbering_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.hatched_timbering_infill_menu_entryClick(Sender: TObject);

begin
  if check_infill_ok('hatched')=False then EXIT;
  pad_timb_infill_style:=1;
  hatched_timbering_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.crosshatched_timbering_infill_menu_entryClick(Sender: TObject);

begin
  if check_infill_ok('cross-hatched')=False then EXIT;
  pad_timb_infill_style:=2;
  crosshatched_timbering_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.solid_timbering_infill_menu_entryClick(Sender: TObject);

begin
  if check_infill_ok('solid')=False then EXIT;
  pad_timb_infill_style:=3;
  solid_timbering_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.blank_timbering_infill_menu_entryClick(Sender: TObject);

begin
  if check_infill_ok('blank')=False then EXIT;
  pad_timb_infill_style:=4;
  blank_timbering_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.bg_solid_timber_infill_menu_entryClick(Sender: TObject);

begin
  bgkeeps_form.timber_infill_checkbox.Checked:=True;
  bgpad_timb_infill_style:=3;
  bg_solid_timber_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//_______________________________

procedure Tpad_form.bg_crosshatched_timber_infill_menu_entryClick(Sender: TObject);

begin
  bgkeeps_form.timber_infill_checkbox.Checked:=True;
  bgpad_timb_infill_style:=2;
  bg_crosshatched_timber_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//_______________________________

procedure Tpad_form.bg_hatched_timber_infill_menu_entryClick(Sender: TObject);

begin
  bgkeeps_form.timber_infill_checkbox.Checked:=True;
  bgpad_timb_infill_style:=1;
  bg_hatched_timber_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//_______________________________

procedure Tpad_form.bg_blank_timber_infill_menu_entryClick(Sender: TObject);

begin
  bgkeeps_form.timber_infill_checkbox.Checked:=True;
  bgpad_timb_infill_style:=4;
  bg_blank_timber_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//_______________________________

procedure Tpad_form.bg_no_timber_infill_menu_entryClick(Sender: TObject);

begin
  bgkeeps_form.timber_infill_checkbox.Checked:=False;
  bgpad_timb_infill_style:=0;
  bg_no_timber_infill_menu_entry.Checked:=True;         // radio item.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.show_current_template_guides_menu_entryClick(Sender: TObject);

begin
  show_current_template_guides_menu_entry.Checked:= NOT show_current_template_guides_menu_entry.Checked;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.FormResize(Sender: TObject);

begin
  if no_onresize=True then EXIT;  // 211b


    // !! N.B. We get a resize if we change menus, and the new one requires more or fewer rows
    // in the menu bar than the old one.

  if (pad_form.Showing=True) and (under_way=True)
     then begin
            cancel_adjusts(False);
            show_and_redraw(True,False);

            if (Width<Screen.DesktopWidth) or (Height<Screen.DesktopHeight) then edge_panning_off_menu_entry.Click;  // normally off if not maximized.

            cancel_paper_bunching;   // he will need to re-init this.
          end;

  if pad_form.Showing=True
     then begin

                // leave room for edge-panning or shrunk jotter.

            if panning_form.Left>(pad_form.ClientWidth-panning_form.Width-10) then panning_form.Left:=pad_form.ClientWidth-panning_form.Width-10;

          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.transform_data_menu_entryClick(Sender: TObject);

                            // get transform and shift data

                            //  adjust y and k for hand of turnout.
var
  n:integer;
  od:Toutdim;

begin
  n:=putdim('',1,'rotation centre dimension X ( from left )   ',xform,False,True,False,False);            // neg ok, no preset, allow zero, don't terminate on zero.
  n:=putdim('',1,'rotation centre dimension Y (from bottom)',yform*hand_i+y_datum,False,True,False,False);        // ditto.
  n:=putdim('',3,'rotation  angle  ( + = anticlockwise ) ',kform*hand_i*180.0/Pi,False,True,False,False); // ditto.
  n:=putdim('',1,'+ / -  X  shift  (after rotation) ',xshift,False,True,False,False);                     // ditto.
  n:=putdim('',1,'+ / -  Y  shift  (after rotation) ',yshift*hand_i,False,True,False,False);              // ditto.
  if n<>4 then EXIT;
  if getdims('control  template  -  shifts  and  rotations','',pad_form,n,od)=True
     then begin
            xform:=od[0];
            yform:=(od[1]-y_datum)*hand_i;

            kform:=od[2]*hand_i*Pi/180.0;     // to rads. adjust for hand of turnout.
            normalize_kform;

            xshift:=od[3];
            yshift:=od[4]*hand_i;

            redraw(True);
          end;
end;
//_________________________________________________________________________________________

procedure Tpad_form.rotate_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  action_panel_hint('shift template position instead'); // 205c

  kform_start:=kform;     // for angle read-out.

  mouse_action_selected('F8    rotate  around  fixing  peg ...','F8  rotate  around  peg','by : '+captext((kform-kform_start)*hand_i*180/Pi)+' degrees.   peg  at : '+captext(arm_angle*hand_i*180/Pi)+' degrees'+k_ram_str(arm_angle*hand_i));
  twist_mod:=1;
end;
//_______________________________________________________________________________________

procedure Tpad_form.orbit_rad_centre_menu_entryClick(Sender: TObject);

var
  mouse_str:string;

begin
  cancel_adjusts(True);

  if spiral=True
     then begin
            if adjust_trans_rad=2
               then begin
                      mouse_str:='CTRL-F5  orbit around 2nd radial centre';
                      action_panel_hint('orbit 1st radial centre instead');       // 205c
                    end
               else begin
                      mouse_str:='CTRL-F5  orbit around 1st radial centre';
                      action_panel_hint('orbit 2nd radial centre instead');       // 205c
                    end;
          end
     else mouse_str:='CTRL-F5  orbit around radial centre';

  mouse_action_selected('CTRL-F5    orbit  template  around  radial  centre ...',mouse_str,'peg  at : '+captext(arm_angle*hand_i*180/Pi)+' degrees'+k_ram_str(arm_angle*hand_i));
  orbit_mod:=1;
end;
//________________________________________________________________________________________

procedure Tpad_form.transform_clear_menu_entryClick(Sender: TObject);

begin
  clear_transform_data;
  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_spot_zoom_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('CTRL-F1    spot  zoom  and  lock ...','CTRL-F1  spot  zoom','pad  width : '+captext(screenx)+' mm');
  spot_mod:=1;
  lock_scaling_menu_entry.Click;                   //  otherwise calcs reset screenx.
end;
//_____________________________________________________________________________________

procedure Tpad_form.adjust_zoom_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('    scale  zoom  and  lock ...','scale  zoom','pad  width : '+captext(screenx)+' mm');
  zoom_mod:=1;
  lock_scaling_menu_entry.Click;                  //  otherwise calcs reset screenx.
end;
//_______________________________________________________________________________________

procedure Tpad_form.transform_normalize_menu_entryClick(Sender: TObject);

begin
  normalize_transforms;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.length_free_popup_entryClick(Sender: TObject);

begin
  if swell_mod=1 then EXIT;   // swell mouse action in force (needs constant length).
  turnout_i:=0;               // length free.
  redraw_pad(True,True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.length_locked_popup_entryClick(Sender: TObject);

begin
  turnout_i:=1;      // length locked as is.  no need for a redraw.
end;
//___________________________________________________________________________________________

procedure Tpad_form.f5_sizing_options_menu_entryClick(Sender: TObject);

begin
  case turnout_i of
    0: length_free_menu_entry.Checked:=True;     // radio item.
    1: length_locked_menu_entry.Checked:=True;   // radio item.
  end;//case
end;
//_______________________________________________________________________________________

procedure Tpad_form.pad_popup_menuPopup(Sender: TObject);

begin
  case turnout_i of
    0: length_free_popup_entry.Checked:=True;     // radio item.
    1: length_locked_popup_entry.Checked:=True;   // radio item.
  end;//case

end;
//________________________________________________________________________________________

procedure Tpad_form.metric_calc_menu_entryClick(Sender: TObject);

begin
  metric_form.Show;
end;
//_________________________________________________________________________________________

procedure Tpad_form.calibrate_printer_menu_entryClick(Sender: TObject);

begin
  calibrate_printer;
end;
//___________________________________________________________________________________________

procedure Tpad_form.FormActivate(Sender: TObject);

begin
  top_toolbar_panel.Show;        // may have been hidden by print unit..
  second_toolbar_panel.Show;     // 217a

  brick_button.Show;       // 235b..
  store_draw_button.Show;

  info_form.RePaint;                                     // update any changes.
  if distortions<>0 then distortion_warning_panel.Show
                    else distortion_warning_panel.Hide;

  if save_hide=True then do_hide_current;                // restore hidden status.

  arrow_button_dummy_trackbar.SetFocus;                  // for arrow keys to work.

      // 0.93.a ...
(* OT2024

  sketchboard_trackplan_update_needed:=True;    // flag sketchboard that there may be trackplan changes.

  if go_sketchboard=True then dtp_form.dtp_document.CurrentPage.PageColor:=paper_colour;  // match background for sketchboard items, if sketchboard in use.

  dtp_settings_form.Hide;    // these are StayOnTop ...
  sketchboard_form.Hide;     // copyboard

  dtp_form.Hide;   // 205a
*)

end;
//___________________________________________________________________________________________

procedure Tpad_form.FormDeactivate(Sender: TObject);

begin
  cancel_adjusts(False);
  save_hide:=hide_current_flag;    // save his hidden status.
  hide_current_flag:=False;        // calcs needed elsewhere.

          // 0.91.b  ...

  if WindowState=wsMinimized       // minimize the application instead.
     then begin
            if Application.Terminated=False then Application.ProcessMessages;
            Application.Minimize;
          end;
end;
//_______________________________________________________________________________________

procedure Tpad_form.all_grey_menu_entryClick(Sender: TObject);

begin
  pad_all_grey;                    // set grey scheme colours.
  pad_form.Color:=paper_colour;    // change the pad colour if nec.
  do_rollback:=False;              // no need to put this in rollback register on redraw.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.colour_panelClick(Sender: TObject);

begin
  preset_schemes_menu_entry.Click;
end;
//_________________________________________________________________________________________

procedure Tpad_form.shift_to_datum_menu_entryClick(Sender: TObject);

                // find template for him by shifting it back to the origin...
begin
  cancel_adjusts(False);
  normalize_transforms;       // retain any rotation,
  xshift:=0;                  // but cancel current shifts.
  yshift:=0;

  redraw(True);
end;
//_____________________________________________________________________________________________

procedure Tpad_form.rotate_to_datum_menu_entryClick(Sender: TObject);

                // rotate template to horizontal datum.
begin
  cancel_adjusts(False);
  normalize_transforms;
  kform:=0;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure do_f3;      // 205a  extracted from menu click

var
  pad_str,mouse_str:string;

begin
  if half_diamond=True   // menu item should be disabled, but could be repeat_last_action call or beginner button
     then begin
            alert(6,'    F3  adjust  turnout  approach  length',
                    'F3  adjust  turnout  approach  length.'
                   +'||This mouse action applies only to turnout templates.'
                   +'||The control template is a half-diamond.'
                   +'||Use F4 to adjust the overall length of a half-diamond template.',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);
  if plain_track=False
     then begin
            pad_str:='F3    adjust  length  of  turnout  approach  track ...';
            mouse_str:='F3  approach  length';
          end
     else begin
            pad_str:='F3 / F4    adjust  length  of  plain  track ...';
            mouse_str:='F3 / F4  plain-track  length';
          end;

  mouse_action_selected(pad_str,mouse_str,captext(xorg)+' mm');
  approach_mod:=1;
  end;
//________________________________________________________________________________________


procedure Tpad_form.adjust_turnout_approach_menu_entryClick(Sender: TObject);     // F3

begin
  do_f3;     // 205a   menu disabled for half-diamond
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_length_menu_entryClick(Sender: TObject);   // F4

begin
  if plain_track=False
     then begin
            cancel_adjusts(True);
            mouse_action_selected('F4    adjust  overall  length  of  turnout ...','F4  overall  length',captext(turnoutx)+' mm');
            length_mod:=1;
          end
     else do_f3;    // 205a  adjust approach length instead for plain track.
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_blanking_length_menu_entryClick(Sender: TObject);

begin
  if plain_track=True
     then begin
            cancel_adjusts(True);

            mouse_action_selected('CTRL-F3    adjust  blanking  length ...','CTRL-F3  blanking  length',captext(pt_blank)+' mm');
            pt_blanking_mod:=1;
          end
     else begin
            if isolated_crossing=True
               then begin
                      alert(6,'    CTRL-F3  adjust  blanking  length',
                              'The V-crossing has been isolated.'
                             +'||Blanking is not available when the V-crossing is isolated.',
                              '','','','','','O K',0);
                      EXIT;
                    end;

            cancel_adjusts(True);

            mouse_action_selected('CTRL-F3    adjust  blanking  length ...','CTRL-F3  blanking  length',captext(startx)+' mm');
            blanking_mod:=1;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_roll_sleepers_menu_entryClick(Sender: TObject);

begin
  if plain_track=False
     then begin
            alert(6,'    CTRL-F4  roll  rails  and  sleepers',
                    'CTRL-F4 roll rails and sleepers.'
                   +'||This mouse action applies only to plain track templates.'
                   +'||The control template is a turnout template.'
                   +'||To roll the approach or exit tracks in a turnout template, first split them off as separate plain track templates.|( TOOLS > MAKE SPLIT menu items. )',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);

  if (railen[pt_i]<minfp) or (inscale<minfp) then EXIT;      // div 0

  full_draw:=True;  // 223a skeleton draw no good -- need to see rail joints

  tb_roll_factor:=ffx/railen[pt_i]/inscale*100;              // all in mm, 100 is for percentage.

  mouse_action_selected('CTRL-F4    roll  rails  and  sleepers ...','CTRL-F4  roll  rails  and  sleepers','rolled - in : '+captext(tb_roll_percent)+' %  of  a  rail');
  roll_mod:=1;
  if peg_code=-2 then peg_code:=-1;  // so peg on joints can re-initialise.
end;
//__________________________________________________________________________________________

procedure Tpad_form.adjust_roam_menu_entryClick(Sender: TObject);

begin
  if plain_track=True
     then begin
            alert(6,'    CTRL-F9  ROAM  turnout  along  length',
                    '`0CTRL-F9`2|`0Roam turnout along length of template`9'
                   +'||This mouse action applies to turnout templates only.'
                   +'||The control template is a plain track template, not a turnout.',
                    '','','','','','O K',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'    CTRL-F9  ROAM  turnout  along  length',
                    '`0CTRL-F9`2|`0Roam turnout along length of template`9'
                   +'||This mouse action applies to turnout templates only.'
                   +'||The control template is a half-diamond, not a turnout.'
                   +'||Use the `0CTRL-F6`2 SNAKE mouse action instead.',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);
  mouse_action_selected('CTRL-F9    roam  turnout  along  length  of  template ...','CTRL-F9  roam  along  length','approach  length : '+captext(xorg)+' mm');
  roam_mod:=1;
end;
//________________________________________________________________________________________

procedure Tpad_form.long_turnout_road_menu_entryClick(Sender: TObject);

begin
  turnout_road_i:=1;
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.adjustable_turnout_road_menu_entryClick(Sender: TObject);    // 209a

  // 209a sets to turnout_road_endx from CTRL-1, adjustable by mouse action

begin
  if retpar_i=1
     then begin
            alert(6,'    adjustable  turnout-road  exit',
                    'The control template has a parallel V-crossing.'
                   +'||The turnout road on parallel V-crossings cannot be made adjustable.'
                   +'||If you wish to adjust the turnout-road exit length,|first change to a different type of V-crossing at|`0real > V-crossing options >`z menu options.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  turnout_road_i:=2;
  turnout_i:=1;              // 209b  length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.normal_turnout_road_menu_entryClick(Sender: TObject);

begin
  turnout_road_i:=0;
  redraw_pad(True,True);                     //  do a re-draw.
end;
//______________________________________________________________________________

procedure Tpad_form.crossover_road_menu_entryClick(Sender: TObject);

begin
  turnout_road_i:=-1;
  redraw_pad(True,True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.minimum_turnout_road_menu_entryClick(Sender: TObject);

begin
  if retpar_i=1
     then begin
            alert(6,'    mimimum  turnout-road  exit',
                    'The control template has a parallel V-crossing.'
                   +'||The turnout road on parallel V-crossings cannot be reduced to a minimum.'
                   +'||If you wish to reduce the turnout-road exit length to a minimum,|first change to a different type of V-crossing at|`0real > V-crossing options >`z menu options.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  turnout_road_i:=3;
  turnout_i:=1;            // length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.turnout_road_options_menu_entryClick(Sender: TObject);

begin
  case turnout_road_i of
     -1: pad_form.crossover_road_menu_entry.Checked:=True;           //  radio item.
      0: pad_form.normal_turnout_road_menu_entry.Checked:=True;      //  radio item.
      1: pad_form.long_turnout_road_menu_entry.Checked:=True;        //  radio item.
      2: pad_form.adjustable_turnout_road_menu_entry.Checked:=True;  //  radio item.
      3: pad_form.minimum_turnout_road_menu_entry.Checked:=True;     //  radio item.
  end;//case
end;
//______________________________________________________________________________________

procedure Tpad_form.main_road_options_menu_entryClick(Sender: TObject);   // 217a

begin
    case main_road_i of
     -1: pad_form.main_road_crossover_menu_entry.Checked:=True;   //  radio item.
      0: pad_form.normal_main_road_menu_entry.Checked:=True;      //  radio item.
      2: pad_form.adjustable_main_road_menu_entry.Checked:=True;  //  radio item.
      3: pad_form.minimum_main_road_menu_entry.Checked:=True;     //  radio item.
  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.minimum_main_road_menu_entryClick(Sender: TObject);    // 217a ...

begin
  main_road_i:=3;
  turnout_i:=1;            // length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.main_road_crossover_menu_entryClick(Sender: TObject);

begin
  main_road_i:=-1;
  turnout_i:=1;            // length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.normal_main_road_menu_entryClick(Sender: TObject);

begin
  main_road_i:=0;
  turnout_i:=1;            // length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.adjustable_main_road_menu_entryClick(Sender: TObject);

begin
  main_road_i:=2;
  turnout_i:=1;            // length needs to be locked
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.show_mouse_panel_menu_entryClick(Sender: TObject);

begin
  mouse_labels:=True;
  show_mouse_panel_menu_entry.Checked:=True;    // radio item.
end;
//________________________________________________________________________________________

procedure Tpad_form.hide_mouse_panel_menu_entryClick(Sender: TObject);

begin
  mouse_labels:=False;
  hide_mouse_panel_menu_entry.Checked:=True;    // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.background_font_menu_entryClick(Sender: TObject);

begin
  pad_form.bgnd_keeps_font_label.Font.Assign(get_font('choose  a  font  and  text  colour  for  the  template  name  labels',pad_form.bgnd_keeps_font_label.Font,True));
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure do_hi_colour_schemes(i:integer);    // 224a

begin
  case i of
      1: pad_bright;                     // grey day.

      2: begin                           // snow white...
           paper_colour:=clWhite;
           grid_colour:=clSilver;
           ring_colour:=clGreen;
           ring_copy_colour:=$00FF0080;         // violet ring copies. // 0.98.a
           page_colour:=clMaroon;
           pad_form.Font.Color:=clTeal;
           preview_form.Font.Color:=clBlack;

           selection_colour:=clGreen;
           hover_colour:=clFuchsia;

           rail_colour:=clBlack;
           timber_colour:=clGreen;
           timber_infill_colour:=clYellow;

           shapes_colour:=clPurple;
           shapes_label_font.Color:=shapes_colour;

           bgkeep_rail_colour:=clBlue;
           bgkeep_timber_colour:=clPurple;
           bgkeep_timberfill_colour:=clSilver;

           bgkeep_mark_colour:=clRed;
           bgkeep_peg_colour:=clBlack;

           bgkeep_platform_colour:=$0000A0FF;   // 0.93.a  orange

           align_colour:=clRed;
           trans_colour:=clFuchsia;
           guide_colour:=clPurple;
           joint_colour:=clRed;
           pad_form.bgnd_keeps_font_label.Font.Color:=clBlue;      // bgnd keeps.
           pad_form.pad_timber_font_label.Font.Color:=clBlue;      // timber numbers.

           pad_form.sb_red_yellow_menu_entry.Click;            // scalebar colours.
           info_form.Color:=$00F1E3D7;  // 0.93.a for Windows 7 child borders

           keep_colours3;    // colours for the keep form
         end;

      3: begin               // coal black...
           pad_bright;
           timber_colour:=clOlive;
           timber_infill_colour:=clMaroon;
           paper_colour:=clBlack;

           selection_colour:=clYellow;
           hover_colour:=clWhite;

           grid_colour:=clTeal;
           ring_colour:=clLime;
           ring_copy_colour:=clFuchsia;
           pad_form.Font.Color:=clSilver;
           preview_form.Font.Color:=clWhite;
           pad_form.bgnd_keeps_font_label.Font.Color:=clSilver;  // bgnd keeps.
           pad_form.pad_timber_font_label.Font.Color:=clSilver;  // timber numbers.
           shapes_colour:=clLime;
           shapes_label_font.Color:=shapes_colour;

           info_form.Color:=$00F1E3D7;  // 0.93.a for Windows 7 child borders
           bgkeep_timber_colour:=clGray;
           bgkeep_timberfill_colour:=clNavy;

           bgkeep_mark_colour:=clFuchsia;
           pad_form.sb_yellow_blue_menu_entry.Click;            // scalebar colours.

           keep_colours1;             // colours for the keep form.

         end;

      4: set_pad_start_colours(True);     // sky blue startup.

      5: EXIT;

      6: pad_form.bright_night_scheme_menu_entry.Click;

    else EXIT;

  end;//case

  pad_form.Color:=paper_colour;   // change the pad colour if nec.

  do_rollback:=False;             // no need to put this in rollback register on redraw.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.preset_schemes_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  cancel_adjusts(False);  // might be a change of paper colour for the backdrop (colour_button clicked).

  if hi_color=False
     then begin
            i:=alert(2,'php/901   trackpad  colours  -  pre-set  schemes ...',
                       'Here are some simple pre-set colour schemes for the trackpad, using only the basic colours.'
                      +'||For a wider choice of colours click the `0TRACKPAD > TRACKPAD COLOURS`1 > menu items.| ',
                       'classic  grey','snow  white','silver  paper','sunshine  yellow','cancel  -  no  change    ','coal  black    ',0);
            case i of
                1: pad_bright;

                2: begin
                     paper_colour:=clWhite;
                     grid_colour:=clSilver;
                     ring_colour:=clGreen;
                     ring_copy_colour:=$00FF0080;         // violet ring copies. // 0.98.a
                     page_colour:=clMaroon;
                     pad_form.Font.Color:=clTeal;
                     preview_form.Font.Color:=clBlack;

                     selection_colour:=clGreen;
                     hover_colour:=clFuchsia;

                     rail_colour:=clBlack;
                     timber_colour:=clGreen;
                     timber_infill_colour:=clYellow;

                     shapes_colour:=clPurple;
                     shapes_label_font.Color:=shapes_colour;

                     bgkeep_rail_colour:=clBlue;
                     bgkeep_timber_colour:=clPurple;
                     bgkeep_timberfill_colour:=clSilver;

                     bgkeep_mark_colour:=clRed;
                     bgkeep_peg_colour:=clBlack;

                     bgkeep_platform_colour:=clOlive;   // 0.93.a

                     align_colour:=clRed;
                     trans_colour:=clFuchsia;
                     guide_colour:=clPurple;
                     joint_colour:=clRed;
                     pad_form.bgnd_keeps_font_label.Font.Color:=clBlue;      // bgnd keeps.
                     pad_form.pad_timber_font_label.Font.Color:=clBlue;      // timber numbers.

                     sb_red_yellow_menu_entry.Click;            // scalebar colours.
                     info_form.Color:=$00F1E3D7;                // 0.93.a for Windows 7 child borders

                     keep_colours3;    // colours for the keep form
                   end;

                3: pad_silver;

                4: begin
                     paper_colour:=clYellow;
                     grid_colour:=clSilver;
                     ring_colour:=clGreen;
                     ring_copy_colour:=$00FF0080;         // violet ring copies. // 0.98.a
                     page_colour:=clRed;
                     pad_form.Font.Color:=clBlack;
                     preview_form.Font.Color:=clBlack;

                     selection_colour:=clBlack;
                     hover_colour:=clFuchsia;

                     rail_colour:=clBlue;
                     timber_colour:=clOlive;
                     timber_infill_colour:=clWhite;

                     shapes_colour:=clpurple;
                     shapes_label_font.Color:=shapes_colour;

                     bgkeep_rail_colour:=clRed;
                     bgkeep_timber_colour:=clPurple;
                     bgkeep_timberfill_colour:=clSilver;

                     bgkeep_mark_colour:=clBlue;
                     bgkeep_peg_colour:=clBlack;

                     bgkeep_platform_colour:=clPurple;   // 0.93.a

                     align_colour:=clRed;
                     trans_colour:=clFuchsia;
                     guide_colour:=clBlack;
                     joint_colour:=clRed;
                     pad_form.bgnd_keeps_font_label.Font.Color:=clBlue;      // bgnd keps.
                     pad_form.pad_timber_font_label.Font.Color:=clBlue;      // timber numbers.

                     sb_black_white_menu_entry.Click;            // scalebar colours.
                     info_form.Color:=$00F1E3D7;  // 0.93.a for Windows 7 child borders

                     keep_colours2;            // colours for the keep form.
                   end;

                5: EXIT;

                6: begin
                     pad_bright;                // coal black
                     timber_colour:=clOlive;
                     timber_infill_colour:=clMaroon;
                     paper_colour:=clBlack;

                     selection_colour:=clYellow;
                     hover_colour:=clWhite;

                     grid_colour:=clTeal;
                     ring_colour:=clLime;
                     ring_copy_colour:=clFuchsia;
                     pad_form.Font.Color:=clSilver;
                     preview_form.Font.Color:=clWhite;
                     bgnd_keeps_font_label.Font.Color:=clSilver;               // bgnd keeps.
                     pad_form.pad_timber_font_label.Font.Color:=clSilver;      // timber numbers.
                     shapes_colour:=clLime;
                     shapes_label_font.Color:=shapes_colour;

                     info_form.Color:=$00F1E3D7;  // 0.93.a for Windows 7 child borders
                     bgkeep_timber_colour:=clGray;
                     bgkeep_timberfill_colour:=clNavy;

                     bgkeep_mark_colour:=clFuchsia;
                     sb_yellow_blue_menu_entry.Click;            // scalebar colours.

                     keep_colours1;             // colours for the keep form.
                   end;

              else run_error(141);
            end;//case
          end

     else begin
            i:=alert(2,'php/901   trackpad  colours  -  pre-set  schemes ...',
                       'Here are some pre-set colour schemes for the trackpad. The 8-bit schemes use only the basic colours.'
                      +'||For a wider choice of colours click the `0TRACKPAD > TRACKPAD COLOURS`1 > menu items.| ',
                       'classic  grey    ( 8-bit )','snow  white    ( 8-bit )','coal  black    ( 8-bit )','sky  blue  startup    ( 16-bit )','cancel  -  no  change    ','bright  night    ( 16-bit )    ',0);

            do_hi_colour_schemes(i);

            if i<>5 then chosen_colour_scheme:=i;    // for user prefs

          end;

  do_rollback:=False;             // no need to put this in rollback register on redraw.
  redraw(True);
end;
//____________________________________________________________________________________________

function invert_colours(colour:integer):integer;    // invert colour.

begin
  RESULT:=colour XOR $00FFFFFF;
end;
//___________________________________________________________________________________________

procedure Tpad_form.invert_colours_menu_entryClick(Sender: TObject);

begin
   paper_colour:=invert_colours(paper_colour);
   grid_colour:=invert_colours(grid_colour);
   ring_colour:=invert_colours(ring_colour);
   ring_copy_colour:=invert_colours(ring_copy_colour);
   page_colour:=invert_colours(page_colour);
   pad_form.Font.Color:=invert_colours(pad_form.Font.Color);
   preview_form.Font.Color:=invert_colours(preview_form.Font.Color);

   selection_colour:=invert_colours(selection_colour);
   hover_colour:=invert_colours(hover_colour);

   rail_colour:=invert_colours(rail_colour);
   timber_colour:=invert_colours(timber_colour);
   timber_infill_colour:=invert_colours(timber_infill_colour);

   shapes_colour:=invert_colours(shapes_colour);
   shapes_label_font.Color:=invert_colours(shapes_label_font.Color);

   bgkeep_rail_colour:=invert_colours(bgkeep_rail_colour);
   bgkeep_timber_colour:=invert_colours(bgkeep_timber_colour);
   bgkeep_timberfill_colour:=invert_colours(bgkeep_timberfill_colour);

   bgkeep_mark_colour:=invert_colours(bgkeep_mark_colour);
   bgkeep_peg_colour:=invert_colours(bgkeep_peg_colour);

   bgkeep_platform_colour:=invert_colours(bgkeep_platform_colour);   // 0.93.a

   align_colour:=invert_colours(align_colour);
   trans_colour:=invert_colours(trans_colour);
   guide_colour:=invert_colours(guide_colour);
   joint_colour:=invert_colours(joint_colour);

   pad_form.bgnd_keeps_font_label.Font.Color:=invert_colours(pad_form.bgnd_keeps_font_label.Font.Color);      // bgnd keeps.
   pad_form.pad_timber_font_label.Font.Color:=invert_colours(pad_form.pad_timber_font_label.Font.Color);      // timber numbers.

  pad_form.Color:=paper_colour;             // 0.93.a set screen colour for trackpad.
  redraw(True);
end;
//____________________________________________________________________________________________

function rotate_colours(colour:integer):integer;    // rotate red, green, blue components.

var
  red,green,blue,temp:integer;

begin
  red:=(colour AND $000000FF);
  green:=(colour AND $0000FF00) div $100;
  blue:=(colour AND $00FF0000) div $10000;

            // rotate colours...

  temp:=red;
  red:=green;
  green:=blue;
  blue:=temp;

  RESULT:=(blue*$10000)+(green*$100)+red;
end;
//___________________________________________________________________________________________

procedure Tpad_form.rotate_colours_menu_entryClick(Sender: TObject);

begin
   paper_colour:=rotate_colours(paper_colour);
   grid_colour:=rotate_colours(grid_colour);
   ring_colour:=rotate_colours(ring_colour);
   ring_copy_colour:=rotate_colours(ring_copy_colour);
   page_colour:=rotate_colours(page_colour);
   pad_form.Font.Color:=rotate_colours(pad_form.Font.Color);
   preview_form.Font.Color:=rotate_colours(preview_form.Font.Color);

   selection_colour:=rotate_colours(selection_colour);
   hover_colour:=rotate_colours(hover_colour);

   rail_colour:=rotate_colours(rail_colour);
   timber_colour:=rotate_colours(timber_colour);
   timber_infill_colour:=rotate_colours(timber_infill_colour);

   shapes_colour:=rotate_colours(shapes_colour);
   shapes_label_font.Color:=rotate_colours(shapes_label_font.Color);

   bgkeep_rail_colour:=rotate_colours(bgkeep_rail_colour);
   bgkeep_timber_colour:=rotate_colours(bgkeep_timber_colour);
   bgkeep_timberfill_colour:=rotate_colours(bgkeep_timberfill_colour);

   bgkeep_mark_colour:=rotate_colours(bgkeep_mark_colour);
   bgkeep_peg_colour:=rotate_colours(bgkeep_peg_colour);

   bgkeep_platform_colour:=rotate_colours(bgkeep_platform_colour);   // 0.93.a

   align_colour:=rotate_colours(align_colour);
   trans_colour:=rotate_colours(trans_colour);
   guide_colour:=rotate_colours(guide_colour);
   joint_colour:=rotate_colours(joint_colour);

   pad_form.bgnd_keeps_font_label.Font.Color:=rotate_colours(pad_form.bgnd_keeps_font_label.Font.Color);      // bgnd keeps.
   pad_form.pad_timber_font_label.Font.Color:=rotate_colours(pad_form.pad_timber_font_label.Font.Color);      // timber numbers.

  pad_form.Color:=paper_colour;             // 0.93.a  set screen colour for trackpad.
  redraw(True);
end;
//____________________________________________________________________________________________

function swap_colours_rgb(colour,code:integer):integer;    // swap red, green, blue components.

var
  red,green,blue,temp:integer;

begin
  red:=(colour AND $000000FF);
  green:=(colour AND $0000FF00) div $100;
  blue:=(colour AND $00FF0000) div $10000;

            // swap colours...

  case code of

     1: begin           // swap red-blue
          temp:=red;
          red:=blue;
          blue:=temp;
        end;

     2: begin           // swap red-green
          temp:=red;
          red:=green;
          green:=temp;
        end;

     3: begin           // swap blue-green
          temp:=blue;
          blue:=green;
          green:=temp;
        end;

  end;//case

  RESULT:=(blue*$10000)+(green*$100)+red;
end;
//_________________________________________________________________________________________

procedure swap_all_colours(n:integer);

begin
   paper_colour:=swap_colours_rgb(paper_colour,n);
   grid_colour:=swap_colours_rgb(grid_colour,n);
   ring_colour:=swap_colours_rgb(ring_colour,n);
   ring_copy_colour:=swap_colours_rgb(ring_copy_colour,n);
   page_colour:=swap_colours_rgb(page_colour,n);
   pad_form.Font.Color:=swap_colours_rgb(pad_form.Font.Color,n);
   preview_form.Font.Color:=swap_colours_rgb(preview_form.Font.Color,n);

   selection_colour:=swap_colours_rgb(selection_colour,n);
   hover_colour:=swap_colours_rgb(hover_colour,n);

   rail_colour:=swap_colours_rgb(rail_colour,n);
   timber_colour:=swap_colours_rgb(timber_colour,n);
   timber_infill_colour:=swap_colours_rgb(timber_infill_colour,n);

   shapes_colour:=swap_colours_rgb(shapes_colour,n);
   shapes_label_font.Color:=swap_colours_rgb(shapes_label_font.Color,n);

   bgkeep_rail_colour:=swap_colours_rgb(bgkeep_rail_colour,n);
   bgkeep_timber_colour:=swap_colours_rgb(bgkeep_timber_colour,n);
   bgkeep_timberfill_colour:=swap_colours_rgb(bgkeep_timberfill_colour,n);

   bgkeep_mark_colour:=swap_colours_rgb(bgkeep_mark_colour,n);
   bgkeep_peg_colour:=swap_colours_rgb(bgkeep_peg_colour,n);

   bgkeep_platform_colour:=swap_colours_rgb(bgkeep_platform_colour,n);   // 0.93.a

   align_colour:=swap_colours_rgb(align_colour,n);
   trans_colour:=swap_colours_rgb(trans_colour,n);
   guide_colour:=swap_colours_rgb(guide_colour,n);
   joint_colour:=swap_colours_rgb(joint_colour,n);

   pad_form.bgnd_keeps_font_label.Font.Color:=swap_colours_rgb(pad_form.bgnd_keeps_font_label.Font.Color,n);      // bgnd keeps.
   pad_form.pad_timber_font_label.Font.Color:=swap_colours_rgb(pad_form.pad_timber_font_label.Font.Color,n);      // timber numbers.

  pad_form.Color:=paper_colour;             // 0.93.a    set screen colour for trackpad.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.swap_red_blue_menu_entryClick(Sender: TObject);

begin
  swap_all_colours(1);
end;
//______________________________________________________________________________

procedure Tpad_form.swap_red_green_menu_entryClick(Sender: TObject);

begin
  swap_all_colours(2);
end;
//______________________________________________________________________________

procedure Tpad_form.swap_green_blue_menu_entryClick(Sender: TObject);

begin
  swap_all_colours(3);
end;
//______________________________________________________________________________

procedure Tpad_form.startup_colours_menu_entryClick(Sender: TObject);

begin                                // restore default pad colours.
  set_pad_start_colours(True);
  do_rollback:=False;
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.bright_night_scheme_menu_entryClick(Sender: TObject);

                    // "bright night" scheme.
begin
   pad_bright;
   timber_colour:=$000050A0;          // brown.
   timber_infill_colour:=$00004060;   //$00585048;   // blue-grey.

   paper_colour:=$00403830;      // dark bluish grey.

   selection_colour:=clWhite;
   hover_colour:=$008000FF;

   grid_colour:=clBlack;
   ring_colour:=$000080FF;                // orange.
   ring_copy_colour:=clWhite;
   pad_form.Font.Color:=$0000D098;                  // pea green.
   preview_form.Font.Color:=clYellow;

   bgnd_keeps_font_label.Font.Color:=$0060B0FF;           // bgnd keeps labels  peach.
   pad_form.pad_timber_font_label.Font.Color:=$00FFB060;  // blueberry timber numbers.

   page_colour:=clTeal;
   trans_colour:=$00FF8000;                    // violet.

   shapes_colour:=$00FF00C0;                   // mauve.
   shapes_label_font.Color:=shapes_colour;

   info_form.Color:=$00F1E3D7;                 //Win7 child border       // $00B0FFFF;                 // primrose.
   bgkeep_timber_colour:=$00B06060;            // blue-grey.
   bgkeep_timberfill_colour:=$00604000;

   bgkeep_mark_colour:=$008000FF;              // pink.

   keep_paper_colour:=clWhite;  // 223a   was $00FFF0D8;      // ice blue,  colours for the keep form...
   keep_grid_colour:=clTeal;

   keep_rail_colour:=clBlack;
   keep_mark_colour:=clGray;
   keep_timber_colour:=clMaroon;

   pad_form.Color:=paper_colour;      // change the pad colour if nec.

   sb_teal_aqua_menu_entry.Click;   // scalebar colours. (does the redraw).
end;
//________________________________________________________________________________________

procedure Tpad_form.grid_options_menu_entryClick(Sender: TObject);

begin
  if ABS(grid_spacex-grid_spacey)<minfp
    then begin

           case  grid_labels_code_i of

                1: begin   //feet
                     if ABS(grid_spacex-304.8)<minfp then pad_form.grid_1ft_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-3*304.8)<minfp then pad_form.grid_3ft_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-4*304.8)<minfp then pad_form.grid_4ft_spacing_menu_entry.Checked:=True;   // radio item
                   end;

                2: begin  // inches
                     if ABS(grid_spacex-3*25.4)<minfp then pad_form.grid_3in_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-6*25.4)<minfp then pad_form.grid_6in_spacing_menu_entry.Checked:=True;   // radio item
                   end;

                3: begin  // proto-feet
                     if ABS(grid_spacex-12*scale)<minfp then pad_form.grid_12proto_ft_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-100*scale)<minfp then pad_form.grid_100proto_ft_spacing_menu_entry.Checked:=True;   // radio item
                   end;

                6: begin  //mm
                     if ABS(grid_spacex-50)<minfp then pad_form.grid_50mm_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-150)<minfp then pad_form.grid_150mm_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-250)<minfp then pad_form.grid_250mm_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-300)<minfp then pad_form.grid_300mm_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-500)<minfp then pad_form.grid_500mm_spacing_menu_entry.Checked:=True;   // radio item
                     if ABS(grid_spacex-1000)<minfp then pad_form.grid_1000mm_spacing_menu_entry.Checked:=True;   // radio item
                   end;

              else pad_form.set_any_grid_spacing_menu_entry.Checked:=True;  // radio item
           end;//case

         end // if x space = y space
    else pad_form.set_any_grid_spacing_menu_entry.Checked:=True;  // radio item

  if screengrid_flag=True then screengrid_on_menu_entry.Checked:=True        // radio item
                          else screengrid_off_menu_entry.Checked:=True;

end;
//__________________________________________________________________________________________

procedure Tpad_form.show_rings_menu_entryClick(Sender: TObject);

begin
  if ring_has_been_shown=False then grid_form.jump_to_centre_button.Click;    // 0.98.a move to centre on first showing

  show_spacing_rings:=True;
  ring_has_been_shown:=True;    // 0.98.a
  redraw_pad(True,False);
end;
//______________________________________________________________________________________

procedure Tpad_form.hide_rings_menu_entryClick(Sender: TObject);

begin
  show_spacing_rings:=False;
  redraw_pad(True,False);
end;
//__________________________________________________________________________________________

procedure Tpad_form.page_outlines_printer_menu_entryClick(Sender: TObject);

begin
  show_margins:=1;          // 0.93.a
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.page_outlines_pdf_menu_entryClick(Sender: TObject);

begin
  show_margins:=2;          // 0.93.a
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.page_outlines_off_menu_entryClick(Sender: TObject);

begin
  show_margins:=0;          // 0.93.a
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.print_info_menu_entryClick(Sender: TObject);

begin
  info_form.print_button.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.timber_outlines_menu_entryClick(Sender: TObject);

begin
  timber_outlines_menu_entry.Checked:= NOT timber_outlines_menu_entry.Checked;          // toggle outlines calc

  timber_marks:=timber_centres_menu_entry.Checked
             or timber_outlines_menu_entry.Checked
             or timber_numbers_menu_entry.Checked;  // set timbering calcs flag.

  redraw(True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.timber_numbers_menu_entryClick(Sender: TObject);

begin
  timber_numbers_menu_entry.Checked:= NOT timber_numbers_menu_entry.Checked;         // toggle timber numbers calc.

  timber_marks:=timber_centres_menu_entry.Checked
             or timber_outlines_menu_entry.Checked
             or timber_numbers_menu_entry.Checked;  // set timbering calcs flag.

  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.timber_centres_menu_entryClick(Sender: TObject);

begin
  timber_centres_menu_entry.Checked:= NOT timber_centres_menu_entry.Checked;         // toggle timber centres calc.

  timber_marks:=timber_centres_menu_entry.Checked
             or timber_outlines_menu_entry.Checked
             or timber_numbers_menu_entry.Checked;  // set timbering calcs flag.

  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.reduced_ends_menu_entryClick(Sender: TObject);

begin
  reduced_ends_menu_entry.Checked:= NOT reduced_ends_menu_entry.Checked;    // toggle_flag
  reduced_ends:=reduced_ends_menu_entry.Checked;
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.outline_extensions_menu_entryClick(Sender: TObject);

begin
  outline_extensions_menu_entry.Checked:= NOT outline_extensions_menu_entry.Checked;    // toggle flag
  outline_extensions:=outline_extensions_menu_entry.Checked;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.timbering_infill_menu_entryClick(Sender: TObject);

begin
  timbering_infill_menu_entry.Checked:= NOT timbering_infill_menu_entry.Checked;    // toggle flag
  timbering_infill:=timbering_infill_menu_entry.Checked;

  redraw(True);
end;
//_____________________________________________________________________________

procedure Tpad_form.modified_timbering_infill_menu_entryClick(Sender: TObject);   // 226a

begin
  modified_timbering_infill_menu_entry.Checked:= NOT modified_timbering_infill_menu_entry.Checked;    // toggle flag
  modified_timbering_infill:=modified_timbering_infill_menu_entry.Checked;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.both_edges_menu_entryClick(Sender: TObject);

begin
  both_edges_menu_entry.Checked:=True;    // radio item.

  gauge_faces:=True;                                   // gauge faces on.
  outer_edges:=True;                                   // outer edges on.
  midline:=False;                                      // outer edge is full-width of railtop.
  railedges(gauge_faces,outer_edges,centre_lines);     // set up the flags for each rail.
  redraw(True);                                        // and do a re-draw.

end;
//_________________________________________________________________________________________

procedure Tpad_form.outer_edges_only_menu_entryClick(Sender: TObject);

begin
  outer_edges_only_menu_entry.Checked:=True;    // radio item.

  gauge_faces:=False;                                  // gauge faces off.
  outer_edges:=True;                                   // outer edges on.
  midline:=False;                                      // outer edge is full-width of railtop.
  railedges(gauge_faces,outer_edges,centre_lines);     // set up the flags for each rail.
  redraw(True);                                        // and do a re-draw.
end;
//_________________________________________________________________________________________

procedure Tpad_form.gauge_faces_only_menu_entryClick(Sender: TObject);

begin
  gauge_faces_only_menu_entry.Checked:=True;    // radio item.

  gauge_faces:=True;                               // gauge faces on.
  outer_edges:=False;                              // outer edges off.
  midline:=False;                                  // outer edge is full-width of railtop.
  railedges(gauge_faces,outer_edges,centre_lines); // set up the flags for each rail.
  redraw(True);                                    // and do a re-draw.
end;
//________________________________________________________________________________________

procedure Tpad_form.rail_centrelines_only_menu_entryClick(Sender: TObject);

begin
  rail_centrelines_only_menu_entry.Checked:=True;    // radio item.

  gauge_faces:=False;                               // gauge faces off.
  outer_edges:=True;                                // outer edges on.
  midline:=True;                                    // but outer edge is half railtop.
  railedges(gauge_faces,outer_edges,centre_lines);  // set up the flags for each rail.
  redraw(True);                                     // and do a re-draw.
end;
//___________________________________________________________________________________________

procedure Tpad_form.overscale_joggles_menu_entryClick(Sender: TObject);

begin
  overscale_joggles_menu_entry.Checked:= NOT overscale_joggles_menu_entry.Checked;
  overscale_joggles:=overscale_joggles_menu_entry.Checked;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.centre_lines_menu_entryClick(Sender: TObject);

begin
  gen_centre_lines_were_off:=False;  // he clicked, so cancel the flag used in copy_keep.

  centre_lines_menu_entry.Checked:= NOT centre_lines_menu_entry.Checked;
  centre_lines:=centre_lines_menu_entry.Checked;
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(False);                                      //  do a re-draw before the warning.
  no_rails_warn;
end;
//____________________________________________________________________________________________

procedure Tpad_form.stock_rails_menu_entryClick(Sender: TObject);

begin
  stock_rails_menu_entry.Checked:= NOT stock_rails_menu_entry.Checked;
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(False);                                      //  do a re-draw before the warning.
  no_rails_warn;
end;
//___________________________________________________________________________________________

procedure Tpad_form.crossing_rails_menu_entryClick(Sender: TObject);

begin
  crossing_rails_menu_entry.Checked:= NOT crossing_rails_menu_entry.Checked;
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.check_rails_menu_entryClick(Sender: TObject);

begin
  check_rails_menu_entry.Checked:= NOT check_rails_menu_entry.Checked;
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.f5_quarter_steps_menu_entryClick(Sender: TObject);

begin
  f5_quarter_steps:=True;             // mouse adjusts crossing angle in 1/4 steps.
end;
//_______________________________

procedure Tpad_form.f5_any_angle_menu_entryClick(Sender: TObject);

begin
  f5_quarter_steps:=False;            // mouse adjusts crossing angle continuously.
end;
//_______________________________

procedure Tpad_form.f9_quarter_steps_menu_entryClick(Sender: TObject);

begin
  f9_quarter_steps:=True;
end;
//_______________________________

procedure Tpad_form.f9_any_angle_menu_entryClick(Sender: TObject);

begin
  f9_quarter_steps:=False;
end;
//_______________________________

procedure Tpad_form.f10_quarter_steps_menu_entryClick(Sender: TObject);

begin
  f10_quarter_steps:=True;
end;
//_______________________________

procedure Tpad_form.f10_any_angle_menu_entryClick(Sender: TObject);

begin
  f10_quarter_steps:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.f5_crossing_angles_menu_entryClick(Sender: TObject);

begin
  if f5_quarter_steps=True then f5_quarter_steps_menu_entry.Checked:=True   // radio item.
                           else f5_any_angle_menu_entry.Checked:=True;      // radio item.
end;
//___________________________________________________________________________________________

procedure Tpad_form.f9_crossing_angles_menu_entryClick(Sender: TObject);

begin
  if f9_quarter_steps=True then f9_quarter_steps_menu_entry.Checked:=True   // radio item.
                           else f9_any_angle_menu_entry.Checked:=True;      // radio item.

  if f9_gaunt_rad=True then f9_gaunt_radius_fixed_menu_entry.Checked:=True   // radio item.   217a
                       else f9_normal_menu_entry.Checked:=True;              // radio item.

  if f9_hd_rad=True then f9_hd_radius_fixed_menu_entry.Checked:=True   // radio item.   218b
                    else f9_k_angle_fixed_menu_entry.Checked:=True;    // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.f10_crossing_angles_menu_entryClick(Sender: TObject);

begin
  if f10_quarter_steps=True then f10_quarter_steps_menu_entry.Checked:=True   // radio item.
                            else f10_any_angle_menu_entry.Checked:=True;      // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.f9_normal_menu_entryClick(Sender: TObject);       // 217a

begin
  f9_gaunt_rad:=False;
end;
//_______________________________

procedure Tpad_form.f9_gaunt_radius_fixed_menu_entryClick(Sender: TObject);

begin
  f9_gaunt_rad:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.f9_k_angle_fixed_menu_entryClick(Sender: TObject);

begin
  f9_hd_rad:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.f9_hd_radius_fixed_menu_entryClick(Sender: TObject);

begin
  f9_hd_rad:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.program_warning_panelClick(Sender: TObject);

begin
  help(0,program_help_str,'');
end;
//___________________________________________________________________________________________

procedure Tpad_form.delete_calibration_menu_entryClick(Sender: TObject);

var
  prindex:integer;
  prstr:string;

begin
  if get_prindex(prindex)=False then EXIT;

  prstr:=printer_list.Strings[prindex];

  if alert(7,'    delete  calibration',
             'You are about to delete the calibration information (if any)'
            +'|for  '+prstr
            +'||Templates printed on this printer may become dimensionally inaccurate and unusable until you re-calibrate this printer (Shift+F5),'
            +' or reload calibration information for it.',
             '','','','','cancel','O K  -  delete  calibration',0)=6
     then begin

            printer_setup_done:=False;    // so it shows again.

            with Tprint_cal(printer_list.Objects[prindex]).cal_data do begin
              printer_impact:=-1;                                      // type now unknown.
              printer_calibrated:=False;
              printer_head_factor:=1.0;
              printer_roller_factor:=1.0;
            end;//with

            page_info(True,True,False,0); // for page outlines on pad.
            redraw(True);
          end;
end;
//____________________________________________________________________________________________

procedure Tpad_form.delete_all_calibrations_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if alert(7,'    delete  all  calibrations',
             'You are about to delete the calibration information (if any) for all of your printers.'
            +'||Your templates may become dimensionally inaccurate and unusable until you re-calibrate your printer (Shift+F5),'
            +' or reload calibration information for it.',
             '','','','','cancel','O K  -  delete  all  calibrations',0)=6
     then begin

            printer_setup_done:=False;    // so it shows again.

            for n:=0 to printer_list.Count-1 do begin

              with Tprint_cal(printer_list.Objects[n]).cal_data do begin
                printer_impact:=-1;                                      // type now unknown.
                printer_calibrated:=False;
                printer_head_factor:=1.0;
                printer_roller_factor:=1.0;
              end;//with

            end;
            page_info(True,True,False,0); // for page outlines on pad.
            redraw(True);
          end;
end;
//_______________________________________________________________________________________

procedure Tpad_form.proof_sheet_menu_entryClick(Sender: TObject);

begin
  proof_sheet;
end;
//_____________________________________________________________________________________

procedure Tpad_form.FormCreate(Sender: TObject);

begin
  AutoScroll:=False;

  top_toolbar_panel.DoubleBuffered:=True;
  second_toolbar_panel.DoubleBuffered:=True;

  peg_indicator_panel.DoubleBuffered:=True;
  xing_indicator_panel.DoubleBuffered:=True;
  colour_panel.DoubleBuffered:=True;

  ClientWidth:=1360;     // can be changed on program panel / control room  216a
  ClientHeight:=748;

  Font.Size:=8;    // for lo-res screens.  n.b. can't write  "pad_form.Font"  until after pad_form is created.


  arrow_button_dummy_trackbar.Width:=0; // so still "Visible=True" but not actually visible on pad.
                                        // used to receive arrow keys, which can then be intercepted.

  pad_about_Templot_menu_entry.Caption:='&about  Templot      ( v : '+FormatFloat('0.00',program_version/100)+version_build+' )';

  old_pre_templot2_files_menu_entry.Enabled:=DirectoryExists('C:\TEMPLOT\BOX-FILES');  // 207a


  original_pad_window_proc:=pad_form.WindowProc;     // temp save WindowProc for the pad    214a...
  pad_form.WindowProc:=pad_window_proc;              // and replace it

  DragAcceptFiles(pad_form.Handle,True);

end;
//___________________________________________________________________________________________

procedure Tpad_form.move_datum_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('    move  datum ...','datum',captext(y_datum)+' mm');
  datum_mod:=1;
end;
//______________________________________________________________________________________

procedure Tpad_form.adjust_rad1_menu_entryClick(Sender: TObject);

begin
  adjust_trans_rad:=1;
  adjust_rad1_menu_entry.Checked:=True;          // radio item.

  if spiral=True      // transition
     then begin
            if curving_mod=1
               then begin
                      mouse_label_string:='F6  curving 1st transition radius';
                      action_panel_hint('adjust 2nd radius instead');           // 205c
                    end;

            if orbit_mod=1
               then begin
                      mouse_label_string:='CTRL-F5  orbit around 1st radial centre';
                      action_panel_hint('orbit 2nd radial centre instead');     // 205c
                    end;

            if mouse_action_button_down=True                                      // moved with button down.
               then action_form.action_label.Caption:=' •  '+mouse_label_string   // add bullet marker.
               else action_form.action_label.Caption:=mouse_label_string;

            action_form.action_label.Width:=action_form.Canvas.TextWidth(action_form.action_label.Caption)+2; // bug fix for Wine
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_rad2_menu_entryClick(Sender: TObject);

begin
  adjust_trans_rad:=2;
  adjust_rad2_menu_entry.Checked:=True;          // radio item.

  if spiral=True      // transition
     then begin

            if curving_mod=1
               then begin
                      mouse_label_string:='F6  curving 2nd transition radius';
                      action_panel_hint('adjust 1st radius instead');           // 205c
                    end;

            if orbit_mod=1
               then begin
                      mouse_label_string:='CTRL-F5  orbit around 2nd radial centre';
                      action_panel_hint('orbit 1st radial centre instead');     // 205c
                    end;

            if mouse_action_button_down=True                                      // moved with button down.
               then action_form.action_label.Caption:=' •  '+mouse_label_string   // add bullet marker.
               else action_form.action_label.Caption:=mouse_label_string;

            action_form.action_label.Width:=action_form.Canvas.TextWidth(action_form.action_label.Caption)+2; // bug fix for Wine
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_trans_start_menu_entryClick(Sender: TObject);

var
  mode_str:string;

begin
  if zone_rollout_menu_entry.Checked=True then mode_str:='( roll-out )'
                                          else mode_str:='( normal )';

  cancel_adjusts(True);

  action_panel_hint('adjust transition length instead'); // 205c

  mouse_action_selected('SHIFT+CTRL-F3   adjust  transition  start  '+mode_str+' ...','SHIFT+CTRL-F3  transition  start  '+mode_str,captext(os)+' mm');
  trans_start_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.adjust_trans_length_menu_entryClick(Sender: TObject);

var
  mode_str:string;

begin
  if zone_rollout_menu_entry.Checked=True then mode_str:='( roll-out )'
                                          else mode_str:='( normal )';

  cancel_adjusts(True);

  action_panel_hint('adjust transition start instead'); // 205c

  mouse_action_selected('SHIFT+CTRL-F4   adjust  transition  length  '+mode_str+' ...','SHIFT+CTRL-F4  transition  length  '+mode_str,captext(tst)+' mm');
  trans_length_mod:=1;
end;
//_____________________________________________________________________________________

procedure Tpad_form.adjust_slew_start_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('SHIFT+CTRL-F5   adjust  slewing  start ...','SHIFT+CTRL-F5  slew  start',captext(slew_s)+' mm');
  slew_start_mod:=1;
end;
//_________________________________________________________________________________________

procedure Tpad_form.adjust_slew_length_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('SHIFT+CTRL-F6   adjust  slewing  length ...','SHIFT+CTRL-F6  slew  length',captext(slew_l)+' mm');
  slew_length_mod:=1;
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_slew_amount_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('CTRL-F7   adjust  amount  of  slew ...','CTRL-F7  slew  amount',captext(slew)+' mm');
  slew_amount_mod:=1;
end;
//_________________________________________________________________________________________

procedure Tpad_form.adjust_slew2_factor_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);
  mouse_action_selected('    adjust  mode  2  slew  factor ...','mode 2 slew factor',captext(slew2_kmax*50));
  slew_factor_mod:=1;
end;
//_________________________________________________________________________________________

procedure Tpad_form.trace_on_menu_entryClick(Sender: TObject);

begin
  trace_mouse:=True;                    // redraw on mouse moves.
  trace_on_menu_entry.Checked:=True;    // radio item.
  trace_on_popup_entry.Checked:=True;   // radio item.
end;
//____________________________________________________________________________________

procedure Tpad_form.trace_off_menu_entryClick(Sender: TObject);

begin
  trace_mouse:=False;                    // no redraw on mouse moves.
  trace_off_menu_entry.Checked:=True;    // radio item.
  trace_off_popup_entry.Checked:=True;   // radio item.
end;
//____________________________________________________________________________________

procedure Tpad_form.trace_on_popup_entryClick(Sender: TObject);

begin
  pad_form.trace_on_menu_entry.Click;
end;
//_______________________________________________________________________________________

procedure Tpad_form.trace_off_popup_entryClick(Sender: TObject);

begin
  pad_form.trace_off_menu_entry.Click;
end;
//________________________________________________________________________________________

procedure Tpad_form.save_calibration_menu_entryClick(Sender: TObject);

var
  prindex:integer;

begin
  if get_prindex(prindex)=False then EXIT;
  calibration_save(prindex);
end;
//________________________________________________________________________________________

procedure Tpad_form.reload_calibration_menu_entryClick(Sender: TObject);

var
  prindex:integer;

begin
  if get_prindex(prindex)=False then EXIT;
  calibration_load(prindex);
end;
//________________________________________________________________________________________
(* OT2024

procedure Tpad_form.cal_settings_menu_entryClick(Sender: TObject);

                                    // print out the current calibration settings.
var
  cur_cal:Tcal_data;
  n:integer;
  cal_file:TextFile;

begin
  if no_printer_available=True     // 0.93.a
     then begin
            ShowMessage('No printer available.');
            EXIT;
          end;

  with TPrintDialog.Create(nil) do begin   // 0.93.a created in code because of startup error if no printer available.
    try
      if Execute=False then EXIT;
    finally
      Free;
    end;//try
  end;//with

  with Printer.Canvas do begin

    Font.Assign(set_font('Arial',10,[fsBold],clBlack));

    Brush.Color:=clWhite;
    Brush.Style:=bsSolid;
  end;//with

  AssignPrn(cal_file);
  Rewrite(cal_file);

  Writeln(cal_file,' ');
  Writeln(cal_file,'     TEMPLOT  -   CONTROL  PRINTER  CALIBRATION  SETTINGS   '+DateToStr(Date)+'   '+TimeToStr(Time));
  Writeln(cal_file,' ');
  Printer.Canvas.Font.Style:=[];

  for n:=0 to printer_list.Count-1 do begin
    cur_cal:=Tprint_cal(printer_list.Objects[n]).cal_data;
    Writeln(cal_file,'---------------------------------------------------------------');
    Writeln(cal_file,' ');

    Writeln(cal_file,'Printer :   '+printer_list.Strings[n]);
    Writeln(cal_file,' ');

    if cur_cal.printer_calibrated=True
       then begin
              Writeln(cal_file,'  This printer is currently calibrated as follows :');
              Writeln(cal_file,' ');
              Writeln(cal_file,'    the head-factor is     '+FormatFloat('0.00',cur_cal.printer_head_factor*100)+' %');
              Writeln(cal_file,'    the roller-factor is    '+FormatFloat('0.00',cur_cal.printer_roller_factor*100)+' %');
            end
       else Writeln(cal_file,'  This printer is currently uncalibrated.');

    Writeln(cal_file,' ');

    case cur_cal.printer_impact of
                             -1: Writeln(cal_file,'  The type of this printer is not recorded in Templot.');
                              0: Writeln(cal_file,'  This is recorded in Templot as an inkjet or laser printer.');
                              1: Writeln(cal_file,'  This is recorded in Templot as an impact printer.');
                              2: Writeln(cal_file,'  This is a pen plotter.');
    end;//case
    Writeln(cal_file,' ');
  end;//for
  CloseFile(cal_file);
end;
//___________________________________________________________________________________________
*)

procedure Tpad_form.read_first_menu_entryClick(Sender: TObject);

const
  templot_help_str:string='<HTML><HEAD><TITLE>Please read This First</TITLE><STYLE>body a:hover { color:red; } </STYLE></HEAD>'
    +'<BODY>'
    +'<HR NOSHADE>'
    +'<P CLASS="spacer">&nbsp;</P><P>Thank you for adopting Templot track design as part of your model railway hobby. I hope that you enjoy using Templot and find it a useful addition to your modelling resources.</P>'

    +'<P CLASS="spacer">&nbsp;</P>'

    +'<P>To help you get started please be sure to click <SPAN CLASS="firm">Templot&nbsp;Companion User&nbsp;Guide</SPAN> on the <SPAN CLASS="firm">help</SPAN> menu.'
    +' There is a "Templot Explained" beginners section on there in addition to the more detailed explanations about Templot, with diagrams, tutorials and videos.'
    +' Click <A HREF="go_to_templot_explained.85a">Templot&nbsp;Explained</A> to go there now.</P>'

    +'<P CLASS="spacer">&nbsp;</P>'

    +'<P>The full <SPAN CLASS="firm">Templot&nbsp;Companion</SPAN> is the main help resource for Templot users, and is being frequently updated and extended. Remember to return there often to see the latest updates.'
    +' Click <A HREF="go_to_templot_companion.85a">Templot&nbsp;Companion</A> to go there now.</P>'

    +'<P CLASS="spacer">&nbsp;</P>'

    +'<P>To get the most from Templot and keep up to date with the latest developments, please join the friendly and helpful <SPAN CLASS="firm">Templot&nbsp;Club</SPAN> user forum.'
    +' Membership is free and open to all. Full details are on the Templot web site, or click <A HREF="go_to_templot_club.85a">Templot&nbsp;Club</A> now.</P>'

    +'<P CLASS="spacer">&nbsp;</P>'

    +'<P>Members of Templot Club take part in frequent online Zoom meetings, where you can meet and chat to other Templot users and ask questions about Templot.'
    +' For information about taking part, click <A HREF="go_to_Zoom.85a">next Zoom meeting</A>. You would be very welcome.</P>'

    +'<P CLASS="spacer">&nbsp;</P>'

    +'<P>Templot is my hobby project and the result of countless hours of development work over many years. It is available for you to use free of charge.'
    +' If you find it useful you may like to <A HREF="go_to_donation.85a">make&nbsp;a&nbsp;donation</A> towards the costs and help me to develop it further. Thank you.</P>'

    +'<P CLASS="spacer">&nbsp;</P>';

var
  logo_str,sig_str:string;

begin
  logo_str:='<P CLASS="spacer">&nbsp;</P>'
           +'<TABLE WIDTH="90%" ALIGN="CENTER"><TR>'
           +'<TD ROWSPAN="2" VALIGN="BOTTOM"><IMG SRC="'+exe_str+'internal\hlp\templot5_logo.png"></TD>'
           +'<TD ROWSPAN="2">&nbsp; &nbsp; &nbsp;</TD>'
           +'<TD CLASS="mainheading" ALIGN="CENTER">welcome &nbsp;to &nbsp;Templot</TD>'
           +'</TR><TR>'
           +'<TD CLASS="subheading" ALIGN="CENTER">Getting &nbsp;Started &nbsp;and &nbsp;Finding &nbsp;Help</TD>'
           +'</TR></TABLE>';

  sig_str:='<P>Welcome to Templot and happy modelling. <img src="'+exe_str+'internal\hlp\smile.gif"></P>'
          +'<P CLASS="spacer">&nbsp;</P>'
          +'<P>Martin.</P>';

  no_new_help_sizes:=True;      // don't change the user's default sizes.

  help_form.ClientWidth:=780;
  help_form.ClientHeight:=740;

  resize_help_form;

  help(-150,logo_str+templot_help_str+sig_str,'');

  no_new_help_sizes:=False;    // allow user drag resize again.
end;
//______________________________________________________________________________________

procedure Tpad_form.rotate_current_180_menu_entryClick(Sender: TObject);

begin
  rotate_turnout(Pi,True);     // rotate turnout 180 degrees anti-clockwise around peg.

  saved_pegging_rot:=saved_pegging_rot+Pi;  // for shifting keeps onto notch.
  normalize_angle(saved_pegging_rot);
end;
//______________________________________________________________________________________

procedure Tpad_form.generate_with_diagnostics_menu_entryClick(Sender: TObject);

var
  save_mode:integer;

begin
  save_mode:=draw_mode;
  draw_mode:=0;              // this allows all the alerts to show.
  calcturnout;
  draw_mode:=save_mode;
  redraw(True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.cancel_distortions_popup_entryClick(Sender: TObject);

begin
  control_room_form.cancel_all_distortions_menu_entry.Click;
end;
//______________________________________________________________________________________

procedure Tpad_form.snap_to_zero_menu_entryClick(Sender: TObject);     // 0.93.a

  // invalidate template...  (Delete key)

begin
  if (turnoutx=0) and (snap_to_zero_menu_entry.Tag=0)
     then begin
            extend_template_from_zero;  // he reduced it to zero himself.
            EXIT;
          end;  

  if (turnoutx=0) and (snap_to_zero_menu_entry.Tag=1)
     then begin
            snap_to_zero_menu_entry.Tag:=0;
            copy_keep(invalidated_zero_save);    // retrieve previous control template
          end
     else begin
            snap_to_zero_menu_entry.Tag:=1;
            fill_kd(invalidated_zero_save);   // save existing.

            reset_peg_menu_entry.Click;  // first do Ctrl-0

            xorg:=0;
            turnoutx:=0;
            startx:=0;

            turnout_i:=1;            // length locked at turnoutx.
          end;

  show_and_redraw(True,True);   // make the red Z visible.
end;
//______________________________________________________________________________

procedure Tpad_form.snap_to_catch_points_menu_entryClick(Sender: TObject);

var
  len:extended;
                        // snap length to switch only...
begin
  len:=csi.switch_front_inches+csi.switch_rail;    // end of switch rail.
  if len<csi.stock_rail then len:=csi.stock_rail;  // end of stock rail.

  turnoutx:=xorg+len*inscale;
  turnout_i:=1;                  // length locked at turnoutx.
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.snap_to_heel_menu_entryClick(Sender: TObject);

begin
  turnoutx:=heelx;
  turnout_i:=1;            // length locked at turnoutx.
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.snap_to_minimum_exit_menu_entryClick(Sender: TObject);          // 217a

begin
  turnoutx:=xorg+min_main_road_endx;
  turnout_i:=1;                          // length locked at turnoutx.
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.snap_to_MVJP_menu_entryClick(Sender: TObject);

begin
  turnoutx:=mvjpx;
  turnout_i:=1;            // length locked at turnoutx.
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.snap_to_MXP_menu_entryClick(Sender: TObject);

begin
  turnoutx:=mxpx;
  turnout_i:=1;            // length locked at turnoutx.
  redraw_pad(True,True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.snap_exit_to_return_curve_menu_entryClick(Sender: TObject);

begin
  if retpar_i<>1 then EXIT;
  turnoutx:=retrorgx;           // end of return curve.
  turnout_i:=1;                 // length locked at turnoutx.
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.show_shapes_menu_entryClick(Sender: TObject);

begin
  show_shapes_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//________________________________________________________________________________

procedure Tpad_form.hide_shapes_menu_entryClick(Sender: TObject);

begin
  hide_shapes_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//________________________________________________________________________________________

procedure Tpad_form.bgnd_shapes_menu_entryClick(Sender: TObject);

begin
  do_bgnd(False);  // False = show new shape tab
end;
//________________________________________________________________________________________

procedure Tpad_form.add_background_images_menu_entryClick(Sender: TObject);   // 206d

begin
  bgnd_form.add_picture_shape_button.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.print_in_normal_colours_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=0;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//________________________________________________________________________________________

procedure Tpad_form.print_rails_only_in_mapping_colours_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=1;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//_________________________________________________________________________________________

procedure Tpad_form.print_timbers_only_in_mapping_colours_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=2;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//_____________________________________________________________________________________________

procedure Tpad_form.print_all_in_mapping_colours_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=3;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//________________________________________________________________________________________

procedure Tpad_form.print_using_pad_marker_colours_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=4;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//_________________________________________________________________________________________

procedure Tpad_form.print_all_in_single_colour_menu_entryClick(Sender: TObject);

begin
  mapping_colours_print:=-1;    // 0=normal, 1=rails only, 2=timbers only, 3=rails and timber outlines, 4:=use the PAD colour instead, -1=single colour.
end;
//_________________________________________________________________________________________

procedure Tpad_form.print_colour_options_menu_entryClick(Sender: TObject);

begin
  case mapping_colours_print of

     -1: print_all_in_single_colour_menu_entry.Checked:=True;            // radio item.
      0: print_in_normal_colours_menu_entry.Checked:=True;               // radio item.
      1: print_rails_only_in_mapping_colours_menu_entry.Checked:=True;   // radio item.
      2: print_timbers_only_in_mapping_colours_menu_entry.Checked:=True; // radio item.
      3: print_all_in_mapping_colours_menu_entry.Checked:=True;          // radio item.
      4: print_using_pad_marker_colours_menu_entry.Checked:=True;        // radio item.
  end;//case
end;
//_________________________________________________________________________________________

procedure Tpad_form.toggle_bgnd_templates_menu_entryClick(Sender: TObject);

begin
  show_bgnd_templates:= NOT show_bgnd_templates;     // 237c show_bgnd_keeps_menu_entry.Checked:= NOT show_bgnd_keeps_menu_entry.Checked;

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.toggle_group_templates_menu_entryClick(Sender: TObject);

begin
  if any_selected<1
     then begin
            show_modal_message('Group Templates'+#13+#13+'There are no selected group templates at present.');
            show_group_templates:=True;
            EXIT;
          end;

  show_group_templates:= NOT show_group_templates;

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.toggle_brick_templates_menu_entryClick(Sender: TObject);

begin
  show_brick_templates:= NOT show_brick_templates;

  if show_brick_templates=True                      // 237c
     then show_brick_templates_menu_entry.Click
     else hide_brick_templates_menu_entry.Click;

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure normalize_show_output_rectangle;

var
  x1,y1,x2,y2:extended;

begin

  if draw_export_rectangle_flag=False       // no rectangle, so init rectangle to centre area of pad
     then begin
            output_rectangle_x1:=zoom_offsetx+screenx/4;
            output_rectangle_x2:=output_rectangle_x1+screenx/2;

            output_rectangle_y1:=zoom_offsety+screeny/4;
            output_rectangle_y2:=output_rectangle_y1+screeny/2;

            draw_export_rectangle_flag:=True;

            redraw_pad(True,False);    // to show rectangle.
          end
     else begin
            if output_rectangle_x1<output_rectangle_x2
              then begin
                     x1:=output_rectangle_x1;
                     x2:=output_rectangle_x2;
                   end
              else begin
                     x1:=output_rectangle_x2;
                     x2:=output_rectangle_x1;
                   end;

            if output_rectangle_y1<output_rectangle_y2
              then begin
                     y1:=output_rectangle_y1;
                     y2:=output_rectangle_y2;
                   end
              else begin
                     y1:=output_rectangle_y2;
                     y2:=output_rectangle_y1;
                   end;

            output_rectangle_x1:=x1;
            output_rectangle_x2:=x2;

            output_rectangle_y1:=y1;
            output_rectangle_y2:=y2;
          end;

  output_rectangle_width:=ABS(output_rectangle_x2-output_rectangle_x1);
  output_rectangle_height:=ABS(output_rectangle_y2-output_rectangle_y1);

end;
//______________________________________________________________________________

procedure Tpad_form.show_bgnd_keeps_in_rect_menu_entryClick(Sender: TObject);      // 218d

begin
  show_bgnd_keeps_in_rect_menu_entry.Checked:= NOT show_bgnd_keeps_in_rect_menu_entry.Checked;

  if show_bgnd_keeps_in_rect_menu_entry.Checked=True
     then begin
            pad_form.top_toolbar_panel.ParentColor:=False;
            pad_form.top_toolbar_panel.Color:=$00E0FFE0;       // shows pale green

            normalize_show_output_rectangle;    // set centre of pad and show if not showing
          end
     else begin
            if classic_templot=False
               then begin
                      pad_form.top_toolbar_panel.ParentColor:=False;
                      pad_form.top_toolbar_panel.Color:=$003399FF;       // shows orangey
                    end
               else pad_form.top_toolbar_panel.ParentColor:=True;        // normal
          end;

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.show_selected_group_templates_menu_entryClick(Sender: TObject);  // 209c

begin
  if any_selected<1
     then begin
            show_modal_message('Show Group Templates'+#13+#13+'There are no selected group templates at present.');
            show_group_templates:=True;
            EXIT;
          end;

  show_group_templates:=True;
                                    // 237c show_group_templates_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_selected_group_templates_menu_entryClick(Sender: TObject);   // 209c

begin
  if any_selected<1
     then begin
            show_modal_message('Hide Group Templates'+#13+#13+'There are no selected group templates at present.');
            show_group_templates:=True;
            EXIT;
          end;

  show_group_templates:=False;
                                       // 237c hide_group_templates_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.background_template_detail_menu_entryClick(Sender: TObject);

begin
  do_show_modal(bgkeeps_form);     // 212a  ShowModal
end;
//__________________________________________________________________________________________

procedure Tpad_form.shapes_colour_menu_entryClick(Sender: TObject);

begin
  shapes_colour:=get_colour('choose  a  colour  for  the  background  shape  outlines on  the  trackpad',shapes_colour);

  shapes_infill_colour:=get_colour('choose  a  colour  for  the  background  shape  infill  on  the  trackpad',shapes_infill_colour);    // 239a
end;
//________________________________________________________________________________________

procedure Tpad_form.bgrails_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_rail_colour:=get_colour('choose  a  colour  for  the  background  templates  rail  lines  on  the  trackpad',bgkeep_rail_colour);
end;
//________________________________________________________________________________________

procedure Tpad_form.bgtimber_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_timber_colour:=get_colour('choose  a  colour  for  the  background  templates  timber  outlines  on  the  trackpad',bgkeep_timber_colour);
end;
//_________________________________________________________________________________________

procedure Tpad_form.bgplatforms_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_platform_colour:=get_colour('choose  a  colour  for  the  background  templates  platform  edges  on  the  trackpad',bgkeep_platform_colour);    // 0.93.a
end;
//______________________________________________________________________________

procedure Tpad_form.bgtrackbed_edges_colour_menu_entryClick(Sender: TObject);    // 236b

begin
  bgkeep_trackbed_colour:=get_colour('choose  a  colour  for  the  background  templates  trackbed  edges  on  the  trackpad',bgkeep_trackbed_colour);
end;
//______________________________________________________________________________

procedure Tpad_form.bgtimber_infill_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_timberfill_colour:=get_colour('choose  a  colour  for  the  background  templates  timber  infill',bgkeep_timberfill_colour);
end;
//___________________________________________________________________________________________

procedure Tpad_form.bg_peg_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_peg_colour:=get_colour('choose  a  colour  for  the  pegs  on  the  background  on  the  trackpad',bgkeep_peg_colour);
end;
//____________________________________________________________________________________________

procedure Tpad_form.bgmarks_colour_menu_entryClick(Sender: TObject);

begin
  bgkeep_mark_colour:=get_colour('choose  a  colour  for  the  background  marks  on  the  trackpad',bgkeep_mark_colour);
end;
//_________________________________________________________________________________________

procedure Tpad_form.toggle_bgnd_menu_entryClick(Sender: TObject);

begin
  keep_form.toggle_all_bgnd_menu_entry.Click;
end;
//__________________________________________________________________________________________

procedure Tpad_form.store_as_brick_menu_entryClick(Sender: TObject);      // 234a

begin
  timbering_brick:=True;
  inherited_use_marker:=True;                                    // 241b  make sure marker colour shows
  keep_form.use_inherited_colours_menu_entry.Checked:=True;
  store_and_background(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.store_and_background_menu_entryClick(Sender:TObject);

begin
  if brick_form.bricklaying_checkbox.Checked=True       // 234a
     then begin
            timbering_brick:=True;
            inherited_use_marker:=True;                                 // 241b  make sure marker colour shows ..
            keep_form.use_inherited_colours_menu_entry.Checked:=True;
          end;

  store_and_background(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.restore_and_bgnd_menu_entryClick(Sender: TObject);

begin
  store_and_background_menu_entry.Click;
  if keep_added=False then EXIT;
  do_restore_swap;
end;
//________________________________________________________________________________________

procedure Tpad_form.fit_bgnd_menu_entryClick(Sender: TObject);   // zoom to fit background.

begin
  pad_view_fit_bgnd(0,0);   // 0=all templates
end;
//________________________________________________________________________________________

procedure Tpad_form.fit_selected_group_only_menu_entryClick(Sender: TObject);

begin
  if keeps_list.Count<1 then EXIT;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  pad_view_fit_bgnd(1,0);   // 1=group only
end;
//__________________________________________________________________________________________

procedure Tpad_form.fit_shapes_menu_entryClick(Sender: TObject);

var
  n:integer;
  xmax,xmin,ymax,ymin:extended;
  wl_factor:extended;
  margin_factor:extended;

  reduced_screeny:extended;   // 216c

begin
  cancel_adjusts(False);

    // mods 216c for increased size of top toolbar ...

  if ABS(fy)<minfp then EXIT;   // ??  div 0

  reduced_screeny:=screeny-top_toolbar_panel.Height/ABS(fy);  // 217a

  if ABS(reduced_screeny)<minfp then EXIT;    // ??  div 0

  wl_factor:=screenx/reduced_screeny;


  with bgnd_form.bgnd_shapes_listbox do begin

    if Items.Count<1
       then begin
              alert(6,'    no  shapes',
                      'No background shapes are currently defined.',
                      '','','','','cancel  fit  shapes','',0);
              EXIT;
            end;

    xmax:=0-maxfp;      // init for limits check.
    ymax:=0-maxfp;
    xmin:=maxfp;
    ymin:=maxfp;

    for n:=0 to (Items.Count-1) do begin

      with Tbgshape(Items.Objects[n]).bgnd_shape do begin

        if (hide_bits AND $01)<>0 then CONTINUE;   // ignore any shapes hidden on trackpad

        if xmax<p1.x then xmax:=p1.x;
        if xmin>p1.x then xmin:=p1.x;

        if ymax<p1.y then ymax:=p1.y;
        if ymin>p1.y then ymin:=p1.y;

        if shape_code<3
           then begin
                  if xmax<p2.x then xmax:=p2.x;
                  if xmin>p2.x then xmin:=p2.x;

                  if ymax<p2.y then ymax:=p2.y;
                  if ymin>p2.y then ymin:=p2.y;
                end;
      end;//with

    end;//next shape
  end;//with

  margin_factor:=1.05;         // arbitrary 5% extra for margins.

  screenx:=(xmax-xmin)*margin_factor;

  if screenx<((ymax-ymin)*margin_factor*wl_factor) then screenx:=(ymax-ymin)*margin_factor*wl_factor;

  if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
  if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

             // centralize on pad..

  zoom_offsetx:=xmin-(screenx-(xmax-xmin))/2;
  if wl_factor>minfp then zoom_offsety:=ymin-(screenx/wl_factor-(ymax-ymin))/2;

  lock_scaling_menu_entry.Click;       // lock pad zoom.
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.fit_org_extents_current_menu_entryClick(Sender: TObject);  // zoom to fit control template in view.
                                                                          // if shift is negative, return it to datum.
var
  max_long,max_wide:extended;
  wl_factor:extended;

  reduced_screeny:extended;   // 216c

begin
  cancel_adjusts(False);

  max_wide:=y_datum*100+xy_max[1];   //xy_most[1];   // init for control template in 1/100th mm...
  max_long:=xy_max[0];               //xy_most[0];

  if (max_long<0) or (max_wide<0)    // all negative.
     then begin
            if alert(6,'    control  template  all  negative',
                       '||Your control template is entirely to the left of or below the trackpad margins.'
                      +'||Unable to fit the trackpad to the extent of the control template.',
                       '','','','','cancel','fit  the  extent  of  the  background      ',0)=6
               then fit_bgnd_menu_entry.Click;
            EXIT;
          end;

    // mods 216c for increased size of top toolbar ...

  if ABS(fy)<minfp then EXIT;   // ??  div 0

  reduced_screeny:=screeny-top_toolbar_panel.Height/ABS(fy);  // 217a

  if ABS(reduced_screeny)<minfp then EXIT;    // ??  div 0

  wl_factor:=screenx/reduced_screeny;


  max_long:=(max_long)/100;  // to mm.
  max_wide:=(max_wide)/100;

                            // set new zoom size...
  screenx:=max_long+g*2;    // g*2 arbitrary margin.

  zoom_offsetx:=0-screenx/75;          // 227a
  zoom_offsety:=zoom_offsetx/2;

  if screenx<((max_wide-zoom_offsety+g/2)*wl_factor) then screenx:=(max_wide-zoom_offsety+g/2)*wl_factor;

  if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
  if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

  lock_scaling_menu_entry.Click;    // lock pad zoom.
  redraw(True);
end;
//________________________________________________________________________________________

procedure zoom_fit_control_template;

          // zoom to show just the control template.
var
  max_long,max_wide,min_long,min_wide:extended;
  wl_factor:extended;
  margin_factor:extended;

  reduced_screeny:extended;   // 216c

begin
  with pad_form do begin

    cancel_adjusts(False);

    if turnoutx=0   // 0.93.a
       then begin
              examine_peg_menu_entry.Click;
              EXIT;
            end;

      // mods 216c for increased size of top toolbar ...

    if ABS(fy)<minfp then EXIT;   // ??  div 0

    reduced_screeny:=screeny-top_toolbar_panel.Height/ABS(fy);  // 217a

    if ABS(reduced_screeny)<minfp then EXIT;    // ??  div 0

    wl_factor:=screenx/reduced_screeny;


    max_long:=xy_max[0]/100;          // to mm...
    max_wide:=xy_max[1]/100+y_datum;

    min_long:=xy_min[0]/100;
    min_wide:=xy_min[1]/100+y_datum;

    margin_factor:=1.10;               // 216c arbitrary 10% extra for margins           was 15%

    screenx:=(max_long-min_long)*margin_factor;

    if screenx<((max_wide-min_wide)*margin_factor*wl_factor) then screenx:=(max_wide-min_wide)*margin_factor*wl_factor;

    if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
    if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

               // centralize on pad..

    zoom_offsetx:=min_long-(screenx-(max_long-min_long))/2;
    if wl_factor>minfp then zoom_offsety:=min_wide-(screenx/wl_factor-(max_wide-min_wide))/2;

    if (screenx<minfp) or (screenx=def_req) then screenx:=100*scale;   // zero or negative so make screen 100' scale wide.
    if screenx<screenx_min then screenx:=screenx_min;                  // minimum for screen width (max zoom in).
                                                                       // ( ! getting strange draw problems if zoom in any more).
    if screenx>screenx_max then screenx:=screenx_max;                  // maximum zoom out.

    draw_mode:=2;                              // set scaling locked mode.
    lock_scaling_menu_entry.Checked:=True;     //  radio item.
    zoom_locked_popup_entry.Checked:=True;     //  ditto
  end;//with

  with info_form do begin
    zoom_lock_label.Font.Color:=clWhite;
    zoom_lock_label.Caption:='locked  at :';   //  centred label.
    unlock_button.Enabled:=True;
  end;//with

  show_and_redraw(False,False);   // force immediate calcs, no rollback.
end;
//__________________________________________________________________________________________

procedure Tpad_form.fit_current_only_menu_entryClick(Sender: TObject);  // (this is now Shift-F11 1-12-99).

begin
  zoom_fit_control_template;     // moved out 223c for make simple link modal
end;
//______________________________________________________________________________

procedure Tpad_form.zoom_fit_ruler_menu_entryClick(Sender: TObject);

          // zoom to fit ruler tool.
var
  max_long,max_wide,min_long,min_wide:extended;
  wl_factor:extended;
  margin_factor:extended;

    reduced_screeny:extended;   // 216c

begin
  cancel_adjusts(False);

    // mods 216c for increased size of top toolbar ...

  if ABS(fy)<minfp then EXIT;   // ??  div 0

  reduced_screeny:=screeny-top_toolbar_panel.Height/ABS(fy);  // 217a

  if ABS(reduced_screeny)<minfp then EXIT;    // ??  div 0

  wl_factor:=screenx/reduced_screeny;


  if ruler_endx>ruler_startx
     then begin
            max_long:=ruler_endx;
            min_long:=ruler_startx;
          end
     else begin
            max_long:=ruler_startx;
            min_long:=ruler_endx;
          end;

  if ruler_endy>ruler_starty
     then begin
            max_wide:=ruler_endy;
            min_wide:=ruler_starty;
          end
     else begin
            max_wide:=ruler_starty;
            min_wide:=ruler_endy;
          end;

  margin_factor:=1.10;               // 216c  arbitrary 10% extra for margins       was 15%

  screenx:=(max_long-min_long)*margin_factor;

  if screenx<((max_wide-min_wide)*margin_factor*wl_factor) then screenx:=(max_wide-min_wide)*margin_factor*wl_factor;

  if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
  if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

             // centralize on pad..

  zoom_offsetx:=min_long-(screenx-(max_long-min_long))/2;
  if wl_factor>minfp then zoom_offsety:=min_wide-(screenx/wl_factor-(max_wide-min_wide))/2;

  lock_scaling_menu_entry.Click;  // lock pad zoom.
  redraw_pad(True,False);
end;
//___________________________________________________________________________________________

procedure Tpad_form.spot_and_scale_menu_entryClick(Sender: TObject);

begin
  spot_and_scale_menu_entry.Checked:= NOT spot_and_scale_menu_entry.Checked;
end;
//_________________________________________________________________________________________

procedure Tpad_form.show_zoom_target_menu_entryClick(Sender: TObject);

begin
  show_zoom_target_menu_entry.Checked:= NOT show_zoom_target_menu_entry.Checked;
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.show_pan_controls_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);

    // 0.95.a mods ...

  if panning_form.Showing=True
     then begin
            show_pan_controls_menu_entry.Checked:=False;
            panning_form.Hide;
          end
     else begin
            show_pan_controls_menu_entry.Checked:=True;
            panning_form.Show;
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.set_skeleton_mouse_draw_menu_entryClick(Sender: TObject);     // 217b

begin
  full_draw:= NOT full_draw;
end;
//_____________________________________________________________________________________

procedure Tpad_form.view_reset_max_menu_entryClick(Sender: TObject);

var
  screen_factor:extended;

begin
  screen_factor:=screeny/screenx;

  screenx:=screenx_max;
  zoom_offsetx:=0-screenx/2;
  zoom_offsety:=zoom_offsetx*screen_factor;
  lock_scaling_menu_entry.Click;             // lock pad zoom.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________

procedure Tpad_form.view_reset_org_menu_entryClick(Sender: TObject);  // 227a

  // come here on startup loading too

begin
      // mm arbitrary default settings ...

  zoom_offsetx:=0-screenx/75;
  zoom_offsety:=zoom_offsetx/2;

  lock_scaling_menu_entry.Click;             // lock pad zoom.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.reset_datum_menu_entryClick(Sender: TObject);

begin
  set_y_datum;
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.set_datum_menu_entryClick(Sender: TObject);

const
  helpdp_str:string='     Set  Datum'
                  +'||Enter a new Y-dimension for the datum point (green dot) in millimetres.'
                  +'||The datum point is normally located on the Y-axis (i.e. where the X dimension is zero), and represents the base point from which'
                  +' all the template dimensions are calculated.'
                  +'||( It can only be moved off the Y-axis by means of RE-ORIGINATION; see the PROGRAM > EXPERT menu items on the PROGRAM PANEL window.)';
var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(helpdp_str,1,'datum  Y - dimension',y_datum,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('control  template  -  datum  point','',pad_form,n,od)=True
     then y_datum:=od[0];

  redraw(True);          //  redraw.
end;
//______________________________________________________________________________

procedure Tpad_form.show_all_tagged_templates_click(Sender:TObject);  // 237a

  // reset all hidden tagged templates

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;  // ???

  for n:=0 to keeps_list.Count-1 do Ttemplate(keeps_list.Objects[n]).tagged_hidden:=False;  // show all templates
end;
//______________________________________________________________________________

procedure Tpad_form.show_tagged_templates_click(Sender:TObject);        // 237a

    // show all templates prefixed with selected tag

var
  tag_str:string;

begin
  if (Sender is TMenuItem) then tag_str:=TMenuItem(Sender).Caption
                           else EXIT;

  show_tagged(tag_str);

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_tagged_templates_click(Sender:TObject);        // 237a

    // hide all templates prefixed with selected tag

var
  tag_str:string;

begin
  if (Sender is TMenuItem) then tag_str:=TMenuItem(Sender).Caption
                           else EXIT;

  hide_tagged(tag_str);

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.selected_tag_menu_entry_click(Sender:TObject);        // 206b

    // create group from selected tag

var
  tag_str:string;

begin
  if (Sender is TMenuItem) then tag_str:=TMenuItem(Sender).Caption
                           else EXIT;

  create_group_from_tag(tag_str,False);    // False = alert him if existing group

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.show_by_tag_help_menu_entry_click(Sender:TObject);  // 237a

const
  str:string='php/330    `0show  templates  by  prefix  tag`9'
            +'||Click a tag listed on the sub-menu to show all the templates so tagged.'
            +'||If the listed tag is greyed out, those templates are already showing. If they are not showing they may be unused (wiped) templates, or they may be in a hidden group.'
            +'||For more information about using prefix tags,|click `0more information online`1 above.';

begin
  help(0,str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.hide_by_tag_help_menu_entry_click(Sender:TObject);  // 237a

const
  str:string='php/330    `0hide  templates  by  prefix  tag`9'
            +'||Click a tag listed on the sub-menu to hide all the templates so tagged when they are not members of a group.'
            +'||If the listed tag is greyed out, all those templates are already hidden. If some of them are currently showing, they may be members of a group.'
            +'||For more information about using prefix tags,|click `0more information online`1 above.';

begin
  help(0,str,'');
end;
//______________________________________________________________________________


procedure Tpad_form.select_by_tag_help_menu_entry_click(Sender:TObject);  // 206b

const
  str:string='php/330    `0select  a  group  by  prefix  tag`9'
            +'||Click a tag listed on the sub-menu to create a group of all the templates so tagged.'
            +'||By this means you can quickly re-create a defined group of templates at any time.'
            +'||green_panel_begintree.gif Click the `0group > add prefix tag to names ...`1 menu item to add a tag to all the templates in a group.green_panel_end'
            +'|For more information about using prefix tags,|click `0more information online`1 above.';

begin
  help(0,str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.remove_group_tag_help_menu_entry_click(Sender:TObject);  // 206b

const
  str:string='php/330    `0remove  prefix  tag  from  group`9'
            +'||Click a tag listed on the sub-menu to remove it from all the templates in the group.'
            +'||For more information about using prefix tags,|click `0more information online`1 above.';

begin
  help(0,str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.remove_group_tag_menu_entry_click(Sender:TObject);        // 206b

    // remove tag from all group templates

var
  name_str,tag1_str,tag2_str:string;
  n:integer;

begin
  if (Sender is TMenuItem) then tag1_str:='['+TMenuItem(Sender).Caption+']'
                           else EXIT;

  if keeps_list.Count<1 then EXIT;

  tag2_str:=tag1_str+' ';       // include trailing space

  for n:=0 to keeps_list.Count-1 do begin

    if Ttemplate(keeps_list.Objects[n]).group_selected=False then CONTINUE;

    name_str:=Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1.reference_string;

    name_str:=StringReplace(name_str,tag2_str,'',[rfReplaceAll,rfIgnoreCase]);

    name_str:=StringReplace(name_str,tag1_str,'',[rfReplaceAll,rfIgnoreCase]);    // in case the tailing space was missing

    with Ttemplate(keeps_list.Objects[n]) do begin

      template_info.keep_dims.box_dims1.reference_string:=name_str;

      tagged_hidden:=False;  // 237a  in case hidden

    end;//with

  end;//next

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.main_menuClick(Sender: TObject);

var
  group_exists:boolean;      // 0.91.a

  new_entry:TMenuItem;

  n,tag_count:integer;

begin      // this handler is called by all the menus.

  if arrow_button_dummy_trackbar.Showing=True then arrow_button_dummy_trackbar.SetFocus;  // 0.91.c

  yellow_drag_panel.Visible:=False;    // 233b    draw new     template indicator

  if slide_on_store>0  // 206a cancel any unfinished sliding after store
     then begin
            slide_on_store:=0;
            xshift:=stored_xshift;
            yshift:=stored_yshift;
          end;

  cancel_adjusts(False);

  redo_toolbutton.Tag:=0;      // cancel any repeats - drawing is done immediate.
  undo_toolbutton.Tag:=0;

  print_now_form.Hide;      // 0.93.a
  print_now_bang:=False;    // 0.93.a

  if hide_current_flag=True
     then begin
            if (Sender=gauge_menu)        // show the control if hidden...
            or (Sender=template_menu)
            or (Sender=real_menu)
            or (Sender=geometry_menu)
            or (Sender=action_menu)
            or (Sender=do_menu)
               then begin
                      hide_current_flag:=False;
                      save_hide:=False;

                      show_control_template_menu_entry.Checked:=True;   // 209c  radio item
                      show_control_template_popup_entry.Checked:=True;  // 209c  radio item
                    end;
          end;

  if Sender=pad_menu
     then begin
            hide_control_template_menu_entry.Checked:=hide_current_flag;       // 209c  radio item

            show_control_template_menu_entry.Checked:= NOT hide_current_flag;  // 209c  radio item

            case show_margins of

              0: page_outlines_off_menu_entry.Checked:=True;          // radio item.

              1: page_outlines_printer_menu_entry.Checked:=True;      // radio item.

              2: page_outlines_pdf_menu_entry.Checked:=True;          // radio item.

            end;//case

            bold_timbers_on_last_menu_entry.Checked:=bgkeeps_form.bold_timber_outlines_checkbox.Checked;             // radio items  223c
            normal_timbers_on_last_menu_entry.Checked:= NOT bgkeeps_form.bold_timber_outlines_checkbox.Checked;

              // build list of tags in show_tagged menu...  237a

            show_tagged_templates_menu_entry.Clear;

            tag_count:=build_tag_list(False);    // tag_count not used

            if tag_list.Count>0
               then begin
                      show_tagged_templates_menu_entry.Enabled:=True;

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='         SHOW :';
                      new_entry.Enabled:=False;
                      show_tagged_templates_menu_entry.Add(new_entry);

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line
                      show_tagged_templates_menu_entry.Add(new_entry);

                      for n:=0 to tag_list.Count-1 do begin

                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:=tag_list.Strings[n];
                        new_entry.OnClick:=show_tagged_templates_click;

                        new_entry.Enabled:=find_if_any_tagged_hidden(tag_list.Strings[n]);   // disable show if not needed

                        show_tagged_templates_menu_entry.Add(new_entry);

                      end;//next

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line
                      show_tagged_templates_menu_entry.Add(new_entry);

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='all  tagged  templates';
                      new_entry.OnClick:=show_all_tagged_templates_click;

                      new_entry.Enabled:=find_if_any_tagged_hidden('@|@');   // finds any tag   disable show if not needed

                      show_tagged_templates_menu_entry.Add(new_entry);



                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line

                      // if win7_menu_style=True
                      // then new_entry.Bitmap:=nil
                      // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                      show_tagged_templates_menu_entry.Add(new_entry);


                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='   ? show  tagged  templates  -  &help';
                      new_entry.OnClick:=show_by_tag_help_menu_entry_click;
                      show_tagged_templates_menu_entry.Add(new_entry);

                    end
               else show_tagged_templates_menu_entry.Enabled:=False;


              // build list of tags in hide_tagged menu...  237a

            hide_tagged_templates_menu_entry.Clear;

            tag_count:=build_tag_list(False);    // tag_count not used

            if tag_list.Count>0
               then begin
                      hide_tagged_templates_menu_entry.Enabled:=True;

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='         HIDE :';
                      new_entry.Enabled:=False;
                      hide_tagged_templates_menu_entry.Add(new_entry);

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line
                      hide_tagged_templates_menu_entry.Add(new_entry);

                      for n:=0 to tag_list.Count-1 do begin

                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:=tag_list.Strings[n];
                        new_entry.OnClick:=hide_tagged_templates_click;

                        new_entry.Enabled:= NOT find_if_all_tagged_hidden(tag_list.Strings[n]);   // disable hide if all already hidden

                        hide_tagged_templates_menu_entry.Add(new_entry);

                      end;//next

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line

                      // if win7_menu_style=True
                      // then new_entry.Bitmap:=nil
                      // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                      hide_tagged_templates_menu_entry.Add(new_entry);


                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='   ? hide  tagged  templates  -  &help';
                      new_entry.OnClick:=hide_by_tag_help_menu_entry_click;
                      hide_tagged_templates_menu_entry.Add(new_entry);

                    end
               else hide_tagged_templates_menu_entry.Enabled:=False;

          end;


  if Sender=do_menu  // 0.93.a
     then begin
            snap_to_zero_menu_entry.Checked:=(turnoutx=0);
          end;


  if Sender=group_menu
     then begin

            show_selected_group_templates_menu_entry.Checked:=show_group_templates;       // 237c
            hide_selected_group_templates_menu_entry.Checked:= NOT show_group_templates;  // 237c

            group_exists:=(any_selected>0);

            toggle_group_menu_entry.Enabled:=group_exists;
            group_template_colours_menu_entry.Enabled:=group_exists;

            show_group_normal_colours_menu_entry.Enabled:=group_exists;
            show_group_marker_colours_menu_entry.Enabled:=group_exists;
            group_marker_colour_menu_entry.Enabled:=group_exists;
            print_group_normal_colours_menu_entry.Enabled:=group_exists;
            print_group_mapping_colours_menu_entry.Enabled:=group_exists;
            group_mapping_colour_menu_entry.Enabled:=group_exists;

              // build list of tags in selector menu...  206b

            select_by_tag_menu_entry.Clear;

            tag_count:=build_tag_list(False);    // tag_count not used

            if tag_list.Count>0
               then begin
                      select_by_tag_menu_entry.Enabled:=True;

                      for n:=0 to tag_list.Count-1 do begin

                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:=tag_list.Strings[n];
                        new_entry.OnClick:=selected_tag_menu_entry_click;

                        select_by_tag_menu_entry.Add(new_entry);

                      end;//next

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line

                      // if win7_menu_style=True
                      // then new_entry.Bitmap:=nil
                      // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                      select_by_tag_menu_entry.Add(new_entry);


                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='? group  by  prefix  tag  -  &help';
                      new_entry.OnClick:=select_by_tag_help_menu_entry_click;
                      select_by_tag_menu_entry.Add(new_entry);

                    end
               else select_by_tag_menu_entry.Enabled:=False;

              // build list of group tags in remove menu...  206b

            remove_prefix_tag_menu_entry.Clear;

            tag_count:=build_tag_list(True);    // tag_count not used. True = group templates only

            if tag_list.Count>0
               then begin
                      remove_prefix_tag_menu_entry.Enabled:=True;

                      for n:=0 to tag_list.Count-1 do begin

                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:=tag_list.Strings[n];
                        new_entry.OnClick:=remove_group_tag_menu_entry_click;

                        remove_prefix_tag_menu_entry.Add(new_entry);

                      end;//next

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line

                      // if win7_menu_style=True
                      // then new_entry.Bitmap:=nil
                      // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                      remove_prefix_tag_menu_entry.Add(new_entry);


                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='? remove  prefix  tag  -  &help';
                      new_entry.OnClick:=remove_group_tag_help_menu_entry_click;
                      remove_prefix_tag_menu_entry.Add(new_entry);

                    end
               else remove_prefix_tag_menu_entry.Enabled:=False;
          end;


  if Sender=gauge_menu      // 211b moved here (bug fix)
     then begin

            if gauge_form.mint_new_radio_button.Checked=True    // radio item.
               then gauge_mint_new_menu_entry.Checked:=True     // radio item.
               else gauge_match_original_menu_entry.Checked:=True;   // radio item.

            retain_length_on_mint_menu_entry.Checked:=gauge_form.retain_length_checkbox.Checked;


                 if gauge_i=t_H0US_i then H0_US_menu_entry.Checked:=True   // radio item.
            else if gauge_i=t_H0EU_i then H0_EU_menu_entry.Checked:=True   // radio item.
            else if gauge_i=t_00BF_i then OOBF_menu_entry.Checked:=True    // radio item.

            else if gauge_i=t_00DGI_i then D0GA_menu_entry.Checked:=True    // radio item.  227a

            //if gauge_i=t_00H0_i then begin OOH0_menu_entry.Checked:=True;    EXIT; end;   // radio item.  out 0.93.a

            else if gauge_i=t_EM_i   then EM_menu_entry.Checked:=True      // radio item.
            else if gauge_i=t_S4P4_i then S4P4_menu_entry.Checked:=True    // radio item.

            //else if gauge_i=t_0SF_i  then OSF_menu_entry.Checked:=True     // radio item.  out 212a

            else if gauge_i=t_GOGF_i then GOGF_menu_entry.Checked:=True    // radio item.
            else if gauge_i=t_S7_i   then S7_menu_entry.Checked:=True      // radio item.

              // 0.97.a these items were added 0.93.a  ...

            else if gauge_i=t_N_NMRA_i  then N_NMRA_menu_entry.Checked:=True  // radio item.
            //else if gauge_i=t_NFX_i     then N_FX_menu_entry.Checked:=True    // radio item.  // 233c
            else if gauge_i=t_N_UK_i    then N_UK_menu_entry.Checked:=True    // radio item.
            else if gauge_i=t_S2_i      then S2_menu_entry.Checked:=True      // radio item.
            else if gauge_i=t_S3p5_i    then S_3p5_menu_entry.Checked:=True   // radio item.
            else if gauge_i=t_00SF_i    then OOSF_menu_entry.Checked:=True    // radio item.
            else if gauge_i=t_003D_i    then OO3D_menu_entry.Checked:=True    // radio item.   // 555a
            else if gauge_i=t_S_gauge_i then S_gauge_menu_entry.Checked:=True // radio item.
            else if gauge_i=t_0MF_i     then OMF_menu_entry.Checked:=True     // radio item.
            else if gauge_i=t_1F_i      then gauge1F_menu_entry.Checked:=True // radio item.


            else if gauge_i=t_P32_i     then P32_menu_entry.Checked:=True // radio item   added 212a

            else other_gauges_menu_entry.Checked:=True;  // radio item.
          end;

  if Sender=tools_menu   // 213b
     then begin
            ts_spacing_info_menu_entry.Caption:='  TS  =   '+FormatFloat('0.##',cpi.trtscent_pi/inscale)+'"            '+FormatFloat('0.##',cpi.trtscent_pi)+' mm';      // 215b
            ms_spacing_info_menu_entry.Caption:=' MS =   '+FormatFloat('0.##',cpi.trmscent_pi/inscale)+'"            '+FormatFloat('0.##',cpi.trmscent_pi)+' mm';        // 215b
          end;

  if Sender=utils_menu
     then begin
            if show_ruler_tool=True then show_ruler_menu_entry.Checked:=True    // radio item.
                                    else hide_ruler_menu_entry.Checked:=True;   // radio item.
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.explode_step_size_menu_entryClick(Sender: TObject);

const
  help_jump_str:string='    Explode / Shrink  Step  Size'
  +'||Enter the explosion factor for each spot zoom step.'
  +'||The preset factor is 200 %, meaning that the trackpad width is doubled or halved each time.'
  +'||To make the trackpad zoom in or out faster, increase this number.'
  +'||To make the trackpad zoom in or out more slowly, reduce this number.'
  +'||If you set 141.42 %, it will take 2 steps to exactly double or halve the trackpad width.'
  +'||The preset for the slow zoom step is 110 %. The minimum setting for either is 100.5 %.'
  +'||Handy Hints :'
  +'||You can zoom in or out to a precise size using the SPOT ZOOM mouse action (CTRL-F1) or the SCALE ZOOM mouse action.'

  +'||Or you can zoom in by drawing a rectangle on the pad. Select the TRACKPAD > ZOOM (EXPLODE/SHRINK) > CLICK-DRAG ZOOM RECTANGLE... menu item, or click the zoom rectangle button at the top of the pad.'

  +'||It is also possible to enter the zoom settings directly by selecting the TRACKPAD > ZOOM/PAN OPTIONS > LOCK ZOOM AT... menu item.';

var
  n:integer;
  od:Toutdim;

begin       // no negatives, preset ok, no zero, don't terminate on zero.

    putdim(help_jump_str,4,'normal  explosion  factor',normal_explode_jump*100,True,False,True,False);
 n:=putdim(help_jump_str,4,  'slow  explosion  factor',  slow_explode_jump*100,True,False,True,False);
    if n<>1 then EXIT;
    if getdims('explode / shrink  factors','',pad_form,n,od)=True
       then begin
              if od[0]=def_req then normal_explode_jump:=2
                               else normal_explode_jump:=od[0]/100;

              if normal_explode_jump<1.005 then normal_explode_jump:=1.005;

              if od[1]=def_req then slow_explode_jump:=1.1
                               else slow_explode_jump:=od[1]/100;

              if slow_explode_jump<1.005 then slow_explode_jump:=1.005;

            end;
end;
//_______________________________________________________________________________________

procedure Tpad_form.explode_normal_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  explode_shrink(screenx/normal_explode_jump,False,False);    // zoom in and force redraw (so every click counts).
end;
//_____________________________________________________________________________________

procedure Tpad_form.explode_slow_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  explode_shrink(screenx/slow_explode_jump,False,False);    // zoom in and force redraw (so every click counts).
end;
//______________________________________________________________________________________

procedure Tpad_form.shrink_normal_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  explode_shrink(screenx*normal_explode_jump,False,False);    // zoom out and force redraw (so every click counts).
end;
//_________________________________________________________________________________________

procedure Tpad_form.shrink_slow_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  explode_shrink(screenx*slow_explode_jump,False,False); // zoom out and force redraw (so every click counts).
end;
//__________________________________________________________________________________________

procedure Tpad_form.shortcuts_list_menu_entryClick(Sender: TObject);

const
  sc_key_help_str:string='`0TEMPLOT  KEYBOARD  SHORTCUTS<BR><BR> &nbsp; trackpad  menus`6'

+'|Click the `0print`1 button above to obtain a handy printout of this list.'
+'||A useful chart showing only the function key shortcuts can be printed out and placed behind your keyboard - select the `0help > print F key chart`z menu item'
+' or click the button below.'
+'||This list will be easier to read if you widen this window (by dragging the right-hand edge).'
+'<HR>'
 +'|CTRL-A    GROUP SELECT ALL'+           '|                    selects all stored templates as members of a group.'
+'||CTRL-B    STORAGE BOX'+                '|                    shows the storage box.'
+'||CTRL-C    CYCLE RECENT NOTCH LOCATIONS|                    cycles the pegging notch through recent locations'
+'||CTRL-D    RE-DO CHANGES'+              '|                    cycles roll-back register forwards (cancels UNDO CHANGES).'
+'||CTRL-E    MAKE SEPARATE EXIT TRACK'+   '|                    splits off the exit track from the current turnout template as a separate plain track control template, and stores the turnout part.'
+'||CTRL-F    MAKE SEPARATE APPROACH TRACK|                    splits off the approach track from the current turnout template as a separate plain track control template, and stores the turnout part.'
+'||CTRL-G    MAKE SPLIT AT PEG'+          '|                    splits a plain track template at the current peg position into two separate plain track templates. One becomes the current control template, the other is stored.'
+'||CTRL-H    MIRROR HAND'+                '|                    mirrors the control template to the opposite hand (i.e. flips the entire template, see also CTRL-X).'
+'||CTRL-I    INSERT TURNOUT IN PLAIN TRACK |                    plain track template is converted to turnout template on the same alignment.'
+'||CTRL-J    JOTTER (TOGGLE)'+            '|                    shows or hides the jotter window for your jottings.'
+'||CTRL-K    CONVERT TURNOUT TO HALF-DIAMOND|                    converts a turnout template to a half-diamond template with the same crossing angle and on the same alignment.'
+'||CTRL-L    CONVERT TO PLAIN TRACK'+     '|                    turnout template is converted to plain track template on the same alignment.'
+'||CTRL-M    EXCHANGE PARKED # 1'+        '|                    exchanges the current control template with the one parked in parking bay no. 1'
+'||CTRL-N    SWAP END-FOR-END'+           '|                    the control template is swapped end-for-end on the same alignment.'
+'||CTRL-N    SWAP FACING-TRAILING'+       '|                    same as CTRL-N SWAP END-FOR-END above.'
+'||CTRL-O    OMIT RAILS AND JOINT MARKS'+ '|                    shows the dialog to omit individual rails and joint marks from the control template.'
+'||CTRL-P    PARK CONTROL # 1'+           '|                    parks a copy of the control template in parking bay no. 1'
+'||CTRL-Q    QUICK SET...'+               '|                    quickly set a new mint template.'
+'||CTRL-R    RETRIEVE PARKED # 1'+        '|                    retrieves the control template from the copy in parking bay no. 1'
+'||CTRL-S    BACKGROUND SHAPES'+          '|                    shows the background shapes list'
+'||CTRL-T    CONVERT HALF-DIAMOND TO TURNOUT|                    converts a half-diamond template to a turnout template with the same crossing angle and on the same alignment'
+'||CTRL-U    UNDO CHANGES'+               '|                    cycles roll-back register backwards (cancels RE-DO CHANGES)'
+'||CTRL-V    STORE AND BACKGROUND'+       '|                    stores a copy of the control template in the storage box and copies it to the background - same as INSERT key or ` (back-quote) key (UK top-left key)'
+'||CTRL-W    INSERT HALF-DIAMOND IN PLAIN TRACK|                    plain track template is converted to a half-diamond template on the same alignment.'
+'||CTRL-X    SWAP HAND'+                  '|                    swaps the handing of the control template (i.e. swaps TS and MS, the main road alignment is preserved, see also CTRL-H)'
+'||CTRL-Y    GROUP SELECT NONE'+          '|                    de-selects all background templates from a group'
+'||CTRL-Z    UNDO DELETED TEMPLATE'+      '|                    restores the most recently deleted template back to the storage box and background drawing'
+'|'
+'||CTRL-DELETE    CLEAR ALL TEMPLATES'+   '|                    clears (deletes) all stored templates and the background drawing'
+'|'
+'||CTRL-0    RESET PEG'+                  '|                    resets the fixing peg on the template datum end'
+'||CTRL-1    PEG ON JOINT'+               '|                    sets the fixing peg at the turnout toe rail-joint, or at the joint end of plain track'
+'||CTRL-2    PEG ON TP'+                  '|                    sets the fixing peg at the toe-point'
+'||CTRL-3    PEG ON DP'+                  '|                    sets the fixing peg at the deflection-point'
+'||CTRL-4    PEG ON FP'+                  '|                    sets the fixing peg at the fine-point'
+'||CTRL-5    PEG ON TXP'+                 '|                    sets the fixing peg at the turnout-side mid-point'
+'||CTRL-6    PEG ON TVJP'+                '|                    sets the fixing peg at the turnout-side vee joint (vee splice rail end)'
+'||CTRL-7    PEG ON MXP'+                 '|                    sets the fixing peg at the main-side mid-point'
+'||CTRL-8    PEG ON MVJP'+                '|                    sets the fixing peg at the main-side vee joint (vee point rail end)'
+'||CTRL-9    PEG ON LENGTH'+              '|                    sets the fixing peg at the full template length'
+'||CTRL-END  PEG ON RAIL JOINTS'+         '|                    sets the fixing peg on a plain track rail joint (CTRL + End key)'
+'|'
+'||F1        HELP BUTTONS AND BARS'+      '|                    shows help texts (where available)'
+'||F2        INFO TOGGLE'+                '|                    shows or hides the template information panel'
+'||F3        ADJUST TURNOUT APPROACH LENGTH|                    MOUSE ACTION adjusts the turnout approach track length and modifies the overall template length accordingly'
+'||F4        ADJUST OVERALL TEMPLATE LENGTH|                    MOUSE ACTION adjusts the overall turnout template length and adds or removes exit track accordingly'
+'||F4        ADJUST PLAIN TRACK LENGTH'+  '|                    MOUSE ACTION adjusts the length of plain track template'
+'||N.B. The F3 and F4 mouse actions are identical when adjusting plain track.'
+'|'
+'||F5        ADJUST TURNOUT SIZE'+        '|                    MOUSE ACTION adjusts the turnout size'
+'||F6        ADJUST CURVING RADIUS'+      '|                    MOUSE ACTION adjusts the curving-line radius (template pegged)'
+'||F7        SHIFT TEMPLATE POSITION'+    '|                    MOUSE ACTION moves the template across the grid'
+'||F8        ROTATE AROUND PEG'+          '|                    MOUSE ACTION rotates the template around the fixing peg'
+'||F9        ADJUST V-CROSSING ANGLE'+    '|                    MOUSE ACTION adjusts the V-crossing angle'
+'||F10       ADJUST K-CROSSING ANGLE'+    '|                    MOUSE ACTION adjusts the K-crossing angle on half-diamond templates'
+'||F11       PRINT CONTROL TEMPLATE'+     '|                    prints the control template only'
+'||F12       REDRAW + SHOW CONTROL'+      '|                    reset and re-draw; cancel MOUSE actions'
+'|'
+'||CTRL-F1   SPOT ZOOM AND LOCK'+         '| or 1 key           MOUSE ACTION zooms on the spot'
+'||CTRL-F2   ZOOM/VIEW TOGGLE'+           '| or 2 key           shows or hides the zoom/view controls'
+'||CTRL-F3   ADJUST TURNOUT BLANKING LENGTH| or 3 key           MOUSE ACTION adjusts the blanked out length on turnout template.'
+'||CTRL-F4   ROLL RAILS AND SLEEPERS'+    '| or 4 key           MOUSE ACTION rolls in a partial rail length at the joint end of a plain track template'
+'||CTRL-F5   ORBIT AROUND RADIAL CENTRE'+ '| or 5 key           MOUSE ACTION orbits the template around the radial centre'
+'||CTRL-F6   SNAKE THROUGH PEG'+          '| or 6 key           MOUSE ACTION snakes the template through the peg position (alignment fixed)'
+'||CTRL-F7   ADJUST SLEW AMOUNT'+         '| or 7 key           MOUSE ACTION adjusts the amount of slew'
+'||CTRL-F8   MOVE PEG'+                   '| or 8 key           MOUSE ACTION moves the fixing peg'
+'||CTRL-F9   ROAM TURNOUT ALONG LENGTH'+  '| or 9 key           MOUSE ACTION adjusts the approach track length but maintains the overall length constant'
+'||CTRL-F10  SWELL CURVING RADIUS'+       '| or 0 key           MOUSE ACTION adjusts the curving-line radius (with template ends fixed)'
+'||CTRL-F11  PRINT BACKGROUND TEMPLATES'+ '|                    prints all the background templates, i.e. the track plan on the trackpad'
+'||CTRL-F12  ADJUST TURNOUT-ROAD EXIT LENGTH|                    MOUSE ACTION adjusts the length of the turnout-road exit'
+'||N.B. The above number-key alternatives to the CTRL-F shortcuts are not available while the MEMO text panel is being (or has been) used. Press the ESCAPE (Esc) key to restore normal working.'
+'|'
+'||SHIFT-F1    MAKE DIAMOND-CROSSING'+    '|                    duplicates the current half-diamond template to form a diamond-crossing.'
+'||SHIFT-F2    MAKE ORDINARY CROSSOVER'+  '|                    duplicates the current turnout template to form an ordinary crossover between double tracks.'
+'||SHIFT-F3    MAKE DOUBLE-TRACK TS'+     '|                    draws plain track on the turnout-side for double-track.'
+'||SHIFT-F4    MAKE DOUBLE-TRACK MS'+     '|                    draws plain track on the main-side for double-track.'
+'||SHIFT-F5    CALIBRATE PRINTER'+        '|                    performs the printer calibration process'
+'||SHIFT-F6    ROTATE GROUP 180 DEGREES|                    rotates a group of templates 180 degrees around the pegging notch'
+'||SHIFT-F7    MAKE BRANCH TRACK'+        '|                    adds a new length of plain track to the diverging turnout road or diagonal road of a template.'
+'||SHIFT-F8    ROTATE CONTROL 180 DEGREES'+'|                    rotates the control template 180 degrees around the fixing peg'
+'||SHIFT-F9    SLIDE THROUGH PEG'+        '|                    MOUSE ACTION slides the template through the peg position'
+'||SHIFT-F10   SHOVE TIMBERS'+            '|                    show the dialog for the shove timber functions (or , key)'
+'||SHIFT-F11   ADJUST CROSSING ENTRY STRAIGHT|                   MOUSE ACTION adjusts the length of the crossing entry straight'
+'||SHIFT-F12   ADJUST GAUNT OFFSET'+      '|                    MOUSE ACTION adjusts the offset on a gaunt turnout'
+'|'
+'||SHIFT+CTRL-F1    MOUSE 1st TRANSITION RADIUS'+'|                    mouse actions apply to 1st transition radius (or - key)'
+'||SHIFT+CTRL-F2    MOUSE 2nd TRANSITION RADIUS'+'|                    mouse actions apply to 2nd transition radius (or = key)'
+'||SHIFT+CTRL-F3    MOVE TRANSITION START'+'|                    MOUSE ACTION moves the transition zone start point (or [ key)'
+'||SHIFT+CTRL-F4    ADJUST TRANSITION LENGTH|                    MOUSE ACTION adjusts transition zone length (or ] key)'
+'||SHIFT+CTRL-F5    MOVE SLEWING START'+   '|                    MOUSE ACTION moves the slewing zone start point (or '' key)'
+'||SHIFT+CTRL-F6    ADJUST SLEWING LENGTH'+'|                    MOUSE ACTION adjusts the length of the slewing zone (or # key)'
+'||SHIFT+CTRL-F7    SHIFT GROUP'+         '|                    MOUSE ACTION shifts all or a selected group of background templates (or \ key)'
+'||SHIFT+CTRL-F8    ROTATE GROUP'+        '|                    MOUSE ACTION rotates all or a selected group of background templates around the notch (or / key)'
+'||SHIFT+CTRL-F9    ADJUST CHECK RAILS'+  '|                    show the check rail adjustment dialog (or . key)'
+'||SHIFT+CTRL-F10    MOVE PAGE ORIGIN'+   '|                    MOUSE ACTION moves the origin point for the printed page margins'
+'||SHIFT+CTRL-F11   ADJUST TS TRACK CENTRES|                    MOUSE ACTION adjusts the TS (turnout-side) adjacent track centres'
+'||SHIFT+CTRL-F12    SKELETON MOUSE DRAW'+'|                    shows skeleton control template during mouse actions (toggle on-off) (or ; key)'
+'|'
+'||HOME Key        HIDE CONTROL TEMPLATE'+'|                    shows background templates only (toggle or F12 to show the control template again)'
+'||BACKSPACE Key   REPEAT LAST ACTION'+   '|                    repeats the most recently used mouse action'
+'||DELETE Key       HIDE MOUSE ACTION PANEL|                    hides the mouse action panel without cancelling the mouse action (toggle hide-show)'
+'||END Key     HIDE TEMPLATE NAME LABELS'+'|                    hides name labels on background templates (toggle to show them again)'
+'||SHIFT+END HIDE TEMPLATES OUTSIDE BOUNDARY RECTANGLE'+'|                    background templates entirely outside the boundary rectangle are not shown (toggle)'
+'|'
+'||NUMPAD 2,4,6,8   MOVE MOUSE POINTER'+  '|                    moves the mouse pointer using the number-pad keys, for mouse actions (square moves)'
+'||NUMPAD 1,3,7,9   MOVE MOUSE POINTER'+  '|                    moves the mouse pointer using the number-pad keys, for mouse actions (diagonal moves)'
+'||NUMPAD 5   CLICK MOUSE'+               '|                    makes a mouse click with the key instead of the mouse button'
+'|'
+'||CTRL+LEFT-CLICK  MAKE THE CONTROL TEMPLATE'+'|                    on a background template does `0make the control`1 function'    // 223c
+'|'
+'||CTRL- \    RESET NOTCH ON GRID ORIGIN'+'|                    resets the pegging notch on the grid origin'
+'||CTRL- -    SHORTEN BY ONE SLEEPER'+    '|                    shortens the length of approach track or plain track by one sleeper (CTRL + hyphen key)'
+'||CTRL- =    EXTEND TO NEXT SLEEPER'+    '|                    extends the length of approach track or plain track by one sleeper (CTRL + equal key)'
+'|'
+'||CTRL- /    SHOW/HIDE REMINDERS'       +'|                    toggles the on-screen reminders on or off'
+'||CTRL- [    SHORTEN EXIT BY ONE SLEEPER'+'|                    shortens the length of exit track by one sleeper'
+'||CTRL- ]    EXTEND EXIT TO NEXT SLEEPER'+'|                    extends the length of exit track by one sleeper'
+'||CTRL- `    SNAP TURNOUT LENGTH TO VEE JOINT'+'|                    snaps the turnout length to the end of the vee point rail (CTRL + ` (top left) key)'
+'||SHIFT+CTRL- `    CROP AT PEG'+         '|                    shortens the control template to the peg position (SHIFT+CTRL + ` (top left) key)'
+'|'
+'||CTRL- .    CROSS-HAIRS MOUSE POINTER'+ '|                    changes the mouse pointer to a cross-hairs symbol (CTRL + full stop (period) key) (click or F12 to cancel)'
+'|'
+'||ADD Key         SPOT EXPLODE'+         '|                    zooms in one normal step (number-pad + key)'
+'||SUBTRACT Key    SPOT SHRINK'+          '|                    zooms out one normal step (number-pad - key)'
+'|'
+'||CTRL-ADD        SPOT EXPLODE (SLOW)'+  '|                    zooms in one small step (CTRL+ number-pad + key)'
+'||CTRL-SUBTRACT   SPOT SHRINK (SlOW)'+   '|                    zooms out one small step (CTRL+ number-pad - key)'
+'|'
+'||MULTIPLY Key    SHIFT PEG ONTO NOTCH'+ '|                    shifts the template to engage the fixing peg on the pegging notch (number-pad * key)'
+'||DIVIDE Key      MOVE NOTCH UNDER PEG'+ '|                    moves the pegging notch under the current fixing peg (number-pad / key)'
+'|||The following four shortcuts repeat the above and are intended for laptop computers without number-pads:'
+'||SHIFT+CTRL- =   SPOT EXPLODE'+         '|                    same as ADD key above (SHIFT+CTRL+ equals key)'
+'||SHIFT+CTRL- -   SPOT SHRINK'+          '|                    same as SUBTRACT key above (SHIFT+CTRL+ minus key)'
+'||SHIFT+CTRL- ''   SHIFT PEG ONTO NOTCH'+ '|                    same as MULTIPLY key above (SHIFT+CTRL+ quote key)'
+'||SHIFT+CTRL- /   MOVE NOTCH UNDER PEG'+ '|                    same as DIVIDE key above (SHIFT+CTRL+ forwardslash key)'
+'|'
+'||DECIMAL Key     TRACKPAD VIEW CENTRED ON PEG'+'|                    same as SHIFT-F9 above (number-pad . key)'
+'||CTRL-DECIMAL    TRACKPAD VIEW CENTRED ON NOTCH'+'|                    centralizes the trackpad view on the pegging notch (CTRL + number-pad . key)'
+'||NUMPAD 0        EXAMINE PEG'+          '|                    centralizes the trackpad on the control template fixing peg and zooms in close (toggle to return)'
+'|'
+'||INSERT Key      STORE AND BACKGROUND'+ '|                    stores a copy of the control template in the storage box and copies it to background - same as CTRL+V key or ` key (top-left key)'
+'||CTRL-INSERT     STORE AND BACKGROUND SPECIAL'+'|                    as above but the previous name label position is retained'
+'|'
+'||CTRL-PAGE UP    LENGTH FREE MODE'+     '|                    turnout length changes with size'
+'||CTRL-PAGE DOWN  LENGTH LOCKED MODE'+   '|                    turnout length is fixed regardless of size'
+'|'
+'||CTRL-NUMPAD 0    PEG FREE'+            '|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg free of constraints'
+'||CTRL-NUMPAD 1    PEG ON MAIN-ROAD STOCK RAIL|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the main-road stock rail (gauge-face)'
+'||CTRL-NUMPAD 2    PEG ON TURNOUT-ROAD CROSSING RAIL|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the turnout-road crossing rail (gauge-face)'
+'||CTRL-NUMPAD 3    PEG ON MAIN-ROAD CROSSING RAIL|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the main-road crossing rail (gauge-face)'
+'||CTRL-NUMPAD 4    PEG ON TURNOUT-ROAD STOCK RAIL|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the turnout-road stock rail (gauge-face)'
+'||CTRL-NUMPAD 5    PEG ON ADJACENT TRACK CENTRE MS|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the adjacent track (main-side) centre-line'
+'||CTRL-NUMPAD 6    PEG ON ADJACENT TRACK CENTRE TS|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the adjacent track (turnout-side) centre-line'
+'||CTRL-NUMPAD 7    PEG ON DOUBLE-TRACK CENTRE-LINE|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the double-track (turnout-side) centre-line'
+'||CTRL-NUMPAD 8    PEG ON MAIN-ROAD CENTRE-LINE|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the main-road centre-line'
+'||CTRL-NUMPAD 9    PEG ON TURNOUT-ROAD CENTRE-LINE|                    the CTRL-F8 MOVE PEG mouse action will move the fixing peg along the turnout-road centre-line'
+'|'
+'||@  Key    EXTRA-FINE ADJUST'+          '|                    sets extra-fine mouse action response rate'
+'||%  Key    FINE ADJUST'+                '|                    sets fine mouse action response rate'
+'||!  Key    COARSE ADJUST'+              '|                    sets coarse mouse action response rate'
+'|'
+'||<  Key    PAD BUNCHING ON'+            '|                    switches on pad bunching for the trackpad'
+'||>  Key    PAD BUNCHING OFF'+           '|                    switches off pad bunching for the trackpad'
+'|'
+'||PAUSE Key       MINIMIZE TEMPLOT'+     '|                    Templot minimizes to taskbar'
+'|'
+'||-  Key    MOUSE 1st TRANSITION RADIUS'+'|                    (hyphen) same as SHIFT+CTRL-F1 above'
+'||=  Key    MOUSE 2nd TRANSITION RADIUS'+'|                    (equal) same as SHIFT+CTRL-F2 above'
+'||[  Key    MOVE TRANSITION START'+      '|                    (left-bracket) same as SHIFT+CTRL-F3 above'
+'||]  Key    ADJUST TRANSITION LENGTH'+   '|                    (right-bracket) same as SHIFT+CTRL-F4 above'
+'||''  Key    MOVE SLEWING START'+        '|                    (quote) same as SHIFT+CTRL-F5 above'
+'||#  Key    ADJUST SLEWING LENGTH'+      '|                    (hash) same as SHIFT+CTRL-F6 above'

+'|'
+'||\  Key    SHIFT GROUP'+                '|                    (backslash) same as SHIFT+CTRL-F7 above'
+'||/  Key    ROTATE GROUP'+               '|                    (forwardslash) same as SHIFT+CTRL-F8 above'
+'||.  Key    ADJUST CHECK RAILS'+         '|                    (full stop)(period) same as SHIFT+CTRL-F9 above'

+'|'
+'||;  Key    TOGGLE MOUSE DRAW'+          '|                    (semi-colon) toggles skeleton mouse draw as SHIFT+CTRL-F12 above'
+'|'
+'||PageUp  Key  ZOOM TO FIT ALL TEMPLATES'+'|                    zoom the trackpad to show all background templates'
+'||PageDown  Key  ZOOM TO FIT GROUP TEMPLATES'+'|                    zoom the trackpad to show all group templates only'
+'||Space Bar ZOOM TO FIT CONTROL ONLY'+   '|                    (spacebar) zoom the trackpad to show the control template only'

+'|'
+'||,  Key    SHOVE TIMBERS'+              '|                    (comma) same as SHIFT-F10 above'
+'||¬  Key    BOLD TIMBERS ON LAST STORED'+'|                    (top-left key) toggle showing timbers in bold on the last template stored'
+'|'
+'||SHIFT and CAPSLOCK keys :'
+'|If the SHIFT key is held down, or CAPSLOCK is ON, templates drawn on the background will be highlighted as the mouse pointer passes over their name labels, and a click on the label will show the popup menu of selection options.'
+' This makes it possible to select overlapping templates when it is difficult to click them directly.'
+'||N.B. The BACKSPACE and DELETE keys and the above single-key alternatives to the CTRL-F# and SHIFT-F# shortcuts are not available while the MEMO text panel is being (or has been) used.'
+' Press the ESCAPE (Esc) key to restore normal working for them.'

+'||The number-pad shortcuts will work only if NUMLOCK is ON and properly initialised. This may require NUMLOCK to be pressed  OFF and then ON again.'
+' (This is a feature of some Windows Accessibilty functions, not Templot).'

+'||If you use the Windows Accessiblity MouseKeys function it should be set to apply when NUMLOCK is OFF,'
+' otherwise the number-pad shortcuts will not work. To change the setting click Start > Settings > Control Panel > Accessibility Options > Mouse > Settings.'
+' A function similar to MouseKeys is available within Templot (when NUMLOCK is ON) for use with the mouse actions, as shown in the list.'

+'||There are some alternatives to the number-pad shortcuts for use on laptop computers - see the notes in the list.'

+'||This list contains only the `0TRACKPAD`1 menu items for which there is a keyboard shortcut. There are many other menu items not listed here.'

+'||The SKETCHBOARD, PROGRAM PANEL, STORAGE BOX and BACKGROUND SHAPES each have their own menus and a different set of shortcuts, some of which actually correspond to the Windows standard.'
;

begin
  if help(0,sc_key_help_str,'print  function  keys  chart')=1 then do_fkey_chart;
end;
//__________________________________________________________________________________________

procedure Tpad_form.move_peg_menu_entryClick(Sender: TObject);

var
  mouse_str:string;

begin
  cancel_adjusts(True);

  set_peg_menu_entry.Checked:=True;         // radio item.
  peg_code:=20;                             // flag gocalc to put peg on a rail or centre-line.
  peg_indicator_panel.Caption:='M';         // show him its down to the Mouse.

  case peg_rail of
       1,2,3,4: mouse_str:='CTRL-F8  peg  along  rail  '+IntToStr(peg_rail);
             5: mouse_str:='CTRL-F8  peg  along  adj ms-centre';
             6: mouse_str:='CTRL-F8  peg  along  adj ts-centre';
             7: mouse_str:='CTRL-F8  peg  along  double-track-centre';
             8: mouse_str:='CTRL-F8  peg  along  ms-centre';
             9: mouse_str:='CTRL-F8  peg  along  ts-centre';
           else mouse_str:='CTRL-F8  move  peg';
  end;//case

  calc_peg_pad_pos;     // calc current peg position on pad for caption.

  mouse_action_selected('CTRL-F8    move  fixing  peg ...',mouse_str,'X : '+captext(pad_peg_point.x)+' mm   Y : '+captext(pad_peg_point.y)+' mm');

  peg_mod:=1;
end;
//___________________________________________________________________________________________

procedure Tpad_form.set_peg_menu_entryClick(Sender: TObject);

const
  help_peg_str:string='     Set  Fixing  Peg'
                  +'||Enter new X and Y dimensions for the fixing peg in millimetres.'
                  +'||The fixing peg "belongs" to the template, not the trackpad. The dimensions to be entered here are internal to the template, i.e. they are'
                  +' referenced from the rail-end (CTRL-0) for the equivalent STRAIGHT turnout. Regardless of the hand of the turnout or it''s orientation on the pad, X-dimensions are positive'
                  +' from the rail-end towards the crossing (vee); and Y-dimensions are positive from the running-edge of the straight stock rail towards the turnout-road side of the turnout.'
                  +'||To avoid mistakes, it is helpful to temporarily convert to a straight left-hand turnout when setting the fixing peg dimensions directly.'
                  +'||The dimensions displayed when moving the peg with the mouse will differ, and show the actual trackpad position of the peg after any curving or shifting of the turnout.'
                  +'||For plain track templates, peg X-dimensions are similarly referenced from the CTRL-0 datum end, Y-dimensions are positive from the opposite running rail-edge towards the hand of the template.'
                  +'||For most purposes, it is easier to move the fixing peg with the mouse actions, or select the GEOMETRY > PEG POSITIONS menu items, or use the CTRL-0 to CTRL-9 keyboard shortcuts.';
var
  n:integer;
  od:Toutdim;

begin
       putdim(help_peg_str,1,'fixing  peg  X - dimension',pegx,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
    n:=putdim(help_peg_str,1,'fixing  peg  Y - dimension',pegy,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
    if n<>1 then EXIT;
    if getdims('set  fixing  peg','',pad_form,n,od)=True
       then begin
              set_peg_menu_entry.Checked:=True;         // radio item.
              peg_code:=-1;                             // flag gocalc to leave peg as is.

              pegx:=od[0];
              pegy:=od[1];

              peg_indicator_panel.Caption:='S';         // show him he set it.

            end;
    redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.peg_on_joints_menu_entryClick(Sender: TObject);

begin
  if plain_track=False then EXIT;    // ??? should be disabled

  cancel_adjusts(False);

  if peg_code=-2                                                    // already on a joint.
     then pegx:=pegx-railen[pt_i]*inscale                           // to the next joint.
     else pegx:=turnoutx-tb_roll_percent*railen[pt_i]*inscale/100;  // to the first joint.

  if pegx<0 then pegx:=turnoutx-tb_roll_percent*railen[pt_i]*inscale/100;  // back to the first joint.

  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=-2;                             // flag gocalc peg is on rail joint.
  peg_indicator_panel.Caption:='J';         // show him he set it.
  peg_on_joints_menu_entry.Checked:=True;   // radio item.

  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.set_user_defined_position_menu_entryClick(Sender: TObject);

begin
  udpegx:=pegx;
  udpegy:=pegy;
  udpegangle:=pegangle;

  udpeg_rail:=peg_rail;

  udpeg_valid:=True;

  peg_on_user_defined_menu_entry.Click;  // update peg_code for it.
end;
//__________________________________________________________________________________________

procedure Tpad_form.set_notch_menu_entryClick(Sender: TObject);

const
  help_notch_str:string='     Set  Notch  Position'

  +'||Enter new X and Y dimensions for the centre of the pegging notch in millimetres.'
  +'||The pegging notch "belongs" to the trackpad, not to the templates, and there is only one notch.'
  +'||The dimensions to be entered here are referenced from the trackpad origin point, and can be determined from the grid margin scales.'
  +' X-dimensions are positive across the trackpad from the left and read along the bottom margin,'
  +' Y-dimensions are positive up the trackpad from the bottom and read along the left margin.'
  +'||For many purposes, it is easier to move the notch with the mouse action, or by selecting the GEOMETRY > NOTCH > NOTCH UNDER PEG'
  +' menu item (or pressing the DIVIDE key) after setting the position of the fixing peg within the control template.';

  help_notchangle_str:string='     Set  Notch  Pegging  Angle'

  +'||Enter the angle in degrees at which the control template will be pegged onto the notch when the GEOMETRY > NOTCH > SHIFT ONTO NOTCH menu item is selected (or MULTIPLY key pressed).'
  +'||The pegging angle is zero when parallel with the bottom margin. The angle is positive when measured anticlockwise from the bottom margin and negative when measured clockwise.'
  +'||It is more usual to let the pegging angle be set automatically when the GEOMETRY > NOTCH > NOTCH UNDER PEG menu item is selected (or DIVIDE key pressed) after setting the position'
  +' of the fixing peg within the control template.';

var
  n:integer;
  od:Toutdim;
  new_notch_data:Tnotch;

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

     putdim(help_notch_str,1,'notch  X - dimension',notchx,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
     putdim(help_notch_str,1,'notch  Y - dimension',notchy,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  n:=putdim(help_notchangle_str,3,'notch  pegging  angle',notch_angle*180/Pi,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.

  if n<>2 then EXIT;
  if getdims('set  notch  position  and  pegging  angle','',pad_form,n,od)=True
     then begin
            with new_notch_data do begin
              notch_x:=od[0];
              notch_y:=od[1];
              notch_k:=od[2]*Pi/180;
              normalize_angle(notch_k);
            end;//with
            new_notch(new_notch_data,True);      // new data, and link group if wanted.
          end;
  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.reset_notch_menu_entryClick(Sender: TObject);

var
  new_notch_data:Tnotch;

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  with new_notch_data do begin
    notch_x:=0;
    notch_y:=0;
    notch_k:=0;
  end;//with
  new_notch(new_notch_data,True);      // new data, and link group if wanted.

  do_rollback:=False;   // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.notch_on_ring_menu_entryClick(Sender: TObject);

var
  new_notch_data:Tnotch;

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  with new_notch_data do begin
    notch_x:=rings[0,0];
    notch_y:=rings[0,1];
    notch_k:=0;
  end;//with
  new_notch(new_notch_data,True);      // new data, and link group if wanted.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.notch_on_shape_menu_entryClick(Sender: TObject);

var
  new_notch_data:Tnotch;
  x,y:extended;
  n:integer;

begin
  with bgnd_form.bgnd_shapes_listbox do begin

    if Items.Count<1 then EXIT;                     // list empty...

    n:=ItemIndex;      // line selected.
    if n<0 then n:=0;  // if none make it the top one.

    with Tbgshape(Items.Objects[n]).bgnd_shape do begin

      case shape_code of

            -1,0,1,2: begin                         // picture, line, rectangle or circle.
                        x:=(p1.x+p2.x)/2;   // on centre.
                        y:=(p1.y+p2.y)/2;
                      end;

                 else begin                // target mark or label.
                        x:=p1.x;
                        y:=p1.y;
                      end;
      end;//case
    end;//with shape
  end;//with listbox

  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  with new_notch_data do begin
    notch_x:=x;
    notch_y:=y;
    notch_k:=0;
  end;//with
  new_notch(new_notch_data,True);      // new data, and link group if wanted.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.mouse_factors_menu_entryClick(Sender: TObject);

const
  help_f8_str:string='      Mouse  Response  Rate  for  F8  Rotate'
                  +'||Enter a setting for the mouse sensitivity when doing mouse action rotations (F8).'
                  +'||Higher figures cause the template to rotate more slowly as the mouse is moved.'
                  +'||Lower figures cause the template to rotate more rapidly as the mouse is moved.'
                  +'||The pre-set figure is 100. Sensible figures are in the range 10 to 5000.'
                  +'||The actual angular rate of change is determined by the current zoom setting.'

                  +'||Handy Hints :'
                  +'|Setting changes made here are intended to apply for the whole working session.'
                  +' A quick way to make a temporary change to the mouse response rate is to select instead the ACTION > MODIFY MOUSE RESPONSE menu items.'
                  +' The change will remain in force while you make the adjustment and be reset to normal on the next F12 redraw.'

                  +'||If you need to set an exact rotation angle, it is easier to use the GEOMETRY > SHIFT/ROTATE > ROTATE BY... menu item.';

  help_orbit_str:string='      Mouse  Response  Rate  for  CTRL-F5  Orbit'
                  +'||Enter a setting for the mouse sensitivity when doing mouse action orbital adjustments (CTRL-F5).'
                  +'||Higher figures cause the template to orbit more slowly as the mouse is moved.'
                  +'||Lower figures cause the template to orbit more rapidly as the mouse is moved.'
                  +'||The pre-set figure is 100. Sensible figures are in the range 10 to 5000.'
                  +'||The actual speed of orbit is determined by the curving radius and the current zoom setting.'

                  +'||Handy Hint :'
                  +'|Setting changes made here are intended to apply for the whole working session.'
                  +' A quick way to make a temporary change to the mouse response rate is to select instead the ACTION > MODIFY MOUSE RESPONSE menu items.'
                  +' The change will remain in force while you make the adjustment and be reset to normal on the next F12 redraw.';

  help_f6_str:string='      Mouse  Response  Rate  for  F6  Adjust  Curving'
                  +'||Enter a setting for the mouse sensitivity when doing mouse action curving (F6).'
                  +'||Higher figures cause the curving radius to change more slowly as the mouse is moved.'
                  +'||Lower figures cause the curving radius to change more rapidly as the mouse is moved.'
                  +'||The pre-set figure is 100. Sensible figures are in the range 10 to 5000.'
                  +'||The actual rate of change of the radius is determined by the current zoom setting.'

                  +'||Handy Hints :'
                  +'|Setting changes made here are intended to apply for the whole working session.'
                  +' A quick way to make a temporary change to the mouse response rate is to select instead the ACTION > MODIFY MOUSE RESPONSE menu items.'
                  +' The change will remain in force while you make the adjustment and be reset to normal on the next F12 redraw.'

                  +'||If you need to set an exact curving radius, it is easier to use the GEOMETRY > CURVING DATA... menu item.';

  help_f5_str:string='      Mouse  Response  Rate  for  F5  Adjust  Size'
                  +'||Enter a setting for the mouse sensitivity when adjusting the size of the turnout (mouse action F5).'
                  +'||Higher figures cause the turnout size to change more slowly as the mouse is moved.'
                  +'||Lower figures cause the turnout size to change more rapidly as the mouse is moved.'
                  +'||The pre-set figure is 100. Sensible figures are in the range 20 to 2500.'

                  +'||Handy Hints :'
                  +'|Setting changes made here are intended to apply for the whole working session.'
                  +' A quick way to make a temporary change to the mouse response rate is to select instead the ACTION > MODIFY MOUSE RESPONSE menu items.'
                  +' The change will remain in force while you make the adjustment and be reset to normal on the next F12 redraw.'

                  +'||If you need to set a known turnout size, it might be quicker to use the TEMPLATE > SWITCH OPTIONS.. or TEMPLATE > V-CROSSING OPTIONS... menu items.';

var
  n:integer;
  od:Toutdim;

begin
    putdim(help_f5_str,0,'mouse  action  response  rate  ( F5  size )',mouse_xing_factor,True,False,True,False);
    putdim(help_f6_str,0,'mouse  action  response  rate  ( F6  curving )',mouse_curv_factor,True,False,True,False);
    putdim(help_f8_str,0,'mouse  action  response  rate  ( F8  rotate )',mouse_rot_factor,True,False,True,False);      // no negatives, preset ok, no zero, don't terminate on zero.
 n:=putdim(help_orbit_str,0,'mouse  action  response  rate  ( CTRL-F5  orbit )',mouse_orbit_factor,True,False,True,False);      // no negatives, preset ok, no zero, don't terminate on zero.
    if n<>3 then EXIT;
    if getdims('mouse  response  factors','',pad_form,n,od)=True
       then begin
              if od[0]=def_req then mouse_xing_factor:=100
                               else mouse_xing_factor:=od[0];

              if od[1]=def_req then mouse_curv_factor:=100
                               else mouse_curv_factor:=od[1];

              if od[2]=def_req then mouse_rot_factor:=100
                               else mouse_rot_factor:=od[2];

              if od[3]=def_req then mouse_orbit_factor:=100
                               else mouse_orbit_factor:=od[3];

            end;
end;
//___________________________________________________________________________________________

procedure Tpad_form.peg_on_rail9_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;           // no turnout-side centre-line.

  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=9;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_rail8_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=8;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.peg_on_rail7_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=7;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.peg_on_rail6_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=6;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_rail5_menu_entryClick(Sender: TObject);
 begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=5;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_rail4_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=4;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.peg_on_rail3_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;           // no straight turnout rail.

  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=3;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//___________________________________________________________________________________

procedure Tpad_form.peg_on_rail2_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;           // no curved turnout rail.

  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=2;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.peg_on_rail1_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=1;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.peg_is_free_menu_entryClick(Sender: TObject);

begin
  set_peg_menu_entry.Checked:=True;        // radio item.
  peg_indicator_panel.Caption:='F';

  peg_rail:=0;
  peg_code:=20;                     // flag gocalc to use peg_rail.
  redraw(True);
end;
//___________________________________________________________________________________

procedure Tpad_form.shift_keeps_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the notch.'
                      +'||This `0SHIFT GROUP`1 function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  action_panel_hint('rotate group instead'); // 205c

  mouse_action_selected('SHIFT+CTRL-F7    shift  group  of  templates ...','SHIFT+CTRL-F7  shift  group','X  by : '+captext(xshift_keeps)+' mm   Y  by : '+captext(yshift_keeps)+' mm');

  shift_keeps_mod:=1;

  do_rollback:=False;
  redraw(True);

  if (bgnd_form.bgnd_shapes_listbox.Items.Count<1) or (bgnd_form.allow_sync_checkbox.Checked=False)
     then begin
            mouse_shift_sync_wanted:=False;
            EXIT;
          end;

  if alert(4,'    shift  background  shapes  in  sync ?',
             '||Do you want your background shapes to be shifted by the same amount?'
            +'||The shapes will shift when this mouse action terminates.'
            +'||Any shapes which have their `0allow to sync with templates`1 option box unticked will not be shifted.',
             '','','','yes  please  -  keep  shapes  in  sync','no  thanks  -  leave  shapes  where  they  are       ','',0)=5

     then mouse_shift_sync_wanted:=False
     else mouse_shift_sync_wanted:=True;

end;
//__________________________________________________________________________________

procedure Tpad_form.rotate_keeps_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the notch.'
                      +'||This `0ROTATE GROUP`1 function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  action_panel_hint('shift group position instead'); // 205c

  mouse_action_selected('SHIFT+CTRL-F8    rotate  group  around  notch ...','SHIFT+CTRL-F8  rotate  group','by : '+captext(0-kform_keeps*180/Pi)+' degrees'+k_ram_str(0-kform_keeps));  // change of kform sign needed because of ??
  twist_keeps_mod:=1;

  do_rollback:=False;
  redraw(True);                                             //  to show selected keeps

  if (bgnd_form.bgnd_shapes_listbox.Items.Count<1) or (bgnd_form.allow_sync_checkbox.Checked=False)
     then begin
            mouse_rotate_sync_wanted:=False;
            EXIT;
          end;

  if alert(4,'    rotate  background  shapes  in  sync ?',
             '||Do you want your background shapes to be rotated by the same amount?'
            +'||The shapes will rotate when this mouse action terminates.'
            +'||Any shapes which have their `0allow to sync with templates`1 option box unticked will not be rotated.'
            +'||If there are any picture shapes, rotation may take several seconds to complete.'
            +'||rp.gif If the rotation angle is not 90 degrees or 180 degrees, picture shapes will gain white corners. If they overlap, it will be necessary to set them transparent in order to be viewed properly.'
            +'|Click the `0all > all picture shapes transparent`1 menu item on the background shapes dialog. Note that this will restrict deep zooming over them, and slow down trackpad panning.',
             '','','','yes  please  -  keep  shapes  in  sync','no  thanks  -  leave  shapes  where  they  are       ','',0)=5

     then mouse_rotate_sync_wanted:=False
     else mouse_rotate_sync_wanted:=True;

end;
//______________________________________________________________________________

procedure Tpad_form.move_name_labels_menu_entryClick(Sender: TObject);

          // 0.82.d  mouse action -- move group name labels.

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  xshift_labels:=0;     // init moves...
  yshift_labels:=0;

  xshift_labels_old:=0;
  yshift_labels_old:=0;

  cancel_adjusts(True);

  mouse_action_selected('    move  group  name  labels ...','move  group  name  labels','X  by : '+captext(xshift_labels)+' mm   Y  by : '+captext(yshift_labels)+' mm');
  move_labels_mod:=1;

  do_rollback:=False;
  redraw(True);                                             //  to show selected keeps
end;
//___________________________________________________________________________________________

procedure Tpad_form.enter_shift_keeps_menu_entryClick(Sender: TObject);

const
  help_xshift_str:string='     Shift  selected  group  on  X.'
                  +'||Enter an X-dimension in millimetres for the amount to shift the currently selected group of background templates.'
                  +'||X-dimensions are measured across the width of the screen, positive from left to right.'
                  +'||Shifting templates can also be done with a mouse action, select the|ACTION >  MOUSE ACTIONS:GROUP > SHIFT GROUP menu item (or press SHIFT+CTRL-F7 or just the "\" BACKSLASH key).'
                  +'||( This function does not shift the control template. To do that select instead the F7 SHIFT mouse action, or the GEOMETRY > SHIFT/ROTATE menu items.)';

  help_yshift_str:string='     Shift  selected  group  on  Y.'
                  +'||Enter a Y-dimension in millimetres for the amount to shift the currently selected group of background templates.'
                  +'||Y-dimensions are measured vertically on the screen, the positive direction is upwards from the bottom.'
                  +'||Shifting templates can also be done with a mouse action, select the|ACTION >  MOUSE ACTIONS:GROUP > SHIFT GROUP menu item (or press SHIFT+CTRL-F7 or just the "\" BACKSLASH key).'
                  +'||( This function does not shift the control template. To do that select instead the F7 SHIFT mouse action, or the GEOMETRY > SHIFT/ROTATE menu items.)';
var
  n:integer;
  od:Toutdim;

  xshapes,yshapes:extended;

begin
  mouse_shift_sync_wanted:=False;    // not mouse action here

  cancel_adjusts(False);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This SHIFT GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  xshift_keeps:=0;
  yshift_keeps:=0;

  kform_keeps:=0;      // (need to clear this for cancel_adjusts)

     putdim(help_xshift_str,1,'shift  selected  group  by  X  ( from  left )',xshift_keeps,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  n:=putdim(help_yshift_str,1,'shift  selected  group  by  Y  ( from  bottom )',yshift_keeps,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.

  if n<>1 then EXIT;
  if getdims('shift  selected  group','',pad_form,n,od)=True
     then begin
            xshift_keeps:=od[0];
            yshift_keeps:=od[1];

            xshapes:=xshift_keeps;
            yshapes:=yshift_keeps;

            cancel_adjusts(False);                                //  does the rebuild.

            redraw(True);

            if (bgnd_form.bgnd_shapes_listbox.Items.Count<1) or (bgnd_form.allow_sync_checkbox.Checked=False) then EXIT;

            if alert(4,'    shift  background  shapes  in  sync ?',
                       'The group templates have been shifted.'
                      +'||Do you now want your background shapes to be shifted by the same amount?'
                      +'||Any shapes which have their `0allow to sync with templates`1 option box unticked will not be shifted.',
                       '','','','','no  thanks','yes  please',0)=5
               then EXIT;

            shift_all_shapes(True,xshapes,yshapes); // True=sync 226b

            shapes_saved:=False;      // need a resave.
            shapes_current_state;

            do_rollback:=False;
            redraw(True);
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.shift_group_into_positve_quadrant_menu_entryClick(Sender: TObject);     // 219a

begin
  shift_group_into_positive_quadrant(True);       // True = alert first
end;
//______________________________________________________________________________

procedure sync_shapes(degs90:boolean; ksync:extended);

var
  trans_str:string;

begin
  if (bgnd_form.bgnd_shapes_listbox.Items.Count<1) or (bgnd_form.allow_sync_checkbox.Checked=False) then EXIT;

  if degs90=True
     then trans_str:=''
     else trans_str:='||rp.gif If the rotation angle is not 90 degrees or 180 degrees, picture shapes will gain white corners. If they overlap, it will be necessary to set them transparent in order to be viewed properly.'
                    +'|Click the `0all > all picture shapes transparent`1 menu item on the background shapes dialog. Note that this will restrict deep zooming over them, and slow down trackpad panning.';

  if alert(4,'    rotate  background  shapes  in  sync ?',
             'The group templates have been rotated.'
            +'||Do you now want your background shapes to be rotated by the same amount?'
            +'||Any shapes which have their `0allow to sync with templates`1 option box unticked will not be rotated.'
            +'||If there are any picture shapes this may take several seconds to complete.'
            +trans_str,
             '','','','','no  thanks','yes  please  -  rotate  shapes',0)=5
     then EXIT;

  bgnd_form.lock_notch_radiobutton.Checked:=True;

  rotate_centre_code:=1;

  rotate_all_shapes(True,True,ksync);  //   True = include pictures

  shapes_saved:=False;      // need a resave.
  shapes_current_state;

  do_rollback:=False;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.enter_rotation_keeps_menu_entryClick(Sender: TObject);

const
  help_kshift_str:string='     Rotate  selected  group  around  notch.'
                  +'||Enter an angle in degrees for the amount by which to rotate the currently selected group of background templates around the current position of the notch.'
                  +'||Angles are measured positive in the anti-clockwise direction, and negative in the clockwise direction.'
                  +'||Rotating templates can also be done with a mouse action, select the|ACTION >  MOUSE ACTIONS:GROUP > ROTATE GROUP menu item (or press SHIFT+CTRL-F8 or just the "/" FORWARD-SLASH key).'
                  +'||( This function does not rotate the control template. To do that select instead the F8 ROTATE mouse action, or the GEOMETRY > SHIFT/ROTATE menu items.)';
var
  n:integer;
  od:Toutdim;

begin
  mouse_rotate_sync_wanted:=False;  // not here for mouse action
  
  cancel_adjusts(False);
  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This ROTATE GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  xshift_keeps:=0;   // (need to clear these for cancel_adjusts)
  yshift_keeps:=0;

  kform_keeps:=0;

  n:=putdim(help_kshift_str,3,'rotate  selected  group  by',kform_keeps,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.

  if n<>0 then EXIT;
  if getdims('rotate  selected  group  around  notch','',pad_form,n,od)=True
     then begin
            kform_keeps:=0-od[0]*Pi/180;   // change of sign needed because of ??
            normalize_angle(kform_keeps);

            cancel_adjusts(False); //  does the rebuild.
          end;

  sync_shapes(False,od[0]*Pi/180);     // False = may not be 90 degs
end;
//_____________________________________________________________________________________

procedure Tpad_form.shift_rotate_current_menu_entryClick(Sender: TObject);

begin
  shift_radial_centre_menu_entry.Enabled:=((ABS(nomrad)<max_rad_test) or (spiral=True));           // only for curved template.
  shift_radial_centre_to_notch_menu_entry.Enabled:=((ABS(nomrad)<max_rad_test) or (spiral=True));

  rotate_by_v_angle_menu_entry.Enabled:=(plain_track=False);                            // 237b ..
  rotate_by_k_angle_menu_entry.Enabled:=((plain_track=False) and (half_diamond=True));

end;
//_______________________________________________________________________________________

procedure Tpad_form.shift_radial_centre_to_notch_menu_entryClick(Sender: TObject);

begin
  shift_radial_centre(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.shift_radial_centre_menu_entryClick(Sender: TObject);

begin
  shift_radial_centre(False);
end;
//________________________________________________________________________________________

procedure Tpad_form.shift_current_by_menu_entryClick(Sender: TObject);

const
  help_xcushift_str:string='     Shift  control  template  on  X.'
                  +'||Enter an X-dimension in millimetres for the amount by which to shift the position of the control template.'
                  +'||X-dimensions are measured across the width of the screen, positive from left to right.'
                  +'||Shifting the control template is more usually done with the mouse action, select the|ACTION >  MOUSE ACTIONS:GEOMETRY > SHIFT POSITION menu item (or press F7).';

  help_ycushift_str:string='     Shift  control  template  on  Y.'
                  +'||Enter a Y-dimension in millimetres for the amount by which to shift the position of the control template.'
                  +'||Y-dimensions are measured vertically on the screen, the positive direction is upwards from the bottom.'
                  +'||Shifting the control template is more usually done with the mouse action, select the|ACTION >  MOUSE ACTIONS:GEOMETRY > SHIFT POSITION menu item (or press F7).';
var
  n:integer;
  od:Toutdim;

begin
     putdim(help_xcushift_str,1,'shift  control  template  by  X  ( from  left )',0,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  n:=putdim(help_ycushift_str,1,'shift  control  template  by  Y  ( from  bottom )',0,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.

  if n<>1 then EXIT;
  if getdims('shift  control  template','',pad_form,n,od)=True
     then begin
            xshift:=xshift+od[0];
            yshift:=yshift+od[1]*hand_i;

            redraw(True);
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.rotate_current_by_menu_entryClick(Sender: TObject);

const
  help_kcushift_str:string='     Rotate  control  template  around  peg.'
                  +'||Enter an angle in degrees for the amount by which to rotate the control template around its fixing peg.'
                  +'||Angles are measured positive in the anti-clockwise direction, and negative in the clockwise direction.'
                  +'||Rotating the control template is more usually done with the mouse action, select the|ACTION >  MOUSE ACTIONS:GEOMETRY > ROTATE AROUND PEG menu item (or press F8).';
var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(help_kcushift_str,3,'rotate  control  template  by',0,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('rotate  control  template  around  peg','',pad_form,n,od)=True
     then rotate_turnout(od[0]*hand_i*Pi/180,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.rotate_v_angle_anticlock_menu_entryClick(Sender: TObject);

begin
  rotate_turnout(k3*hand_i,True);
end;
//______________________________________________________________________________

procedure Tpad_form.rotate_v_angle_clock_menu_entryClick(Sender: TObject);

begin
  rotate_turnout(0-k3*hand_i,True);
end;
//______________________________________________________________________________

procedure Tpad_form.rotate_k_angle_anticlock_menu_entryClick(Sender: TObject);

begin
  rotate_turnout(hdk*hand_i,True);
end;
//______________________________________________________________________________

procedure Tpad_form.rotate_k_angle_clock_menu_entryClick(Sender: TObject);

begin
  rotate_turnout(0-hdk*hand_i,True);
end;
//______________________________________________________________________________

procedure Tpad_form.reset_peg_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=0;                              // then set it.
  peg_indicator_panel.Caption:='0';         // show him Ctrl-0
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.peg_on_joint_end_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=1;                              // then set it.
  peg_indicator_panel.Caption:='1';         // show him Ctrl-1
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.peg_on_tp_menu_entryClick(Sender: TObject);

var
  save_peg_code:integer;

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  save_peg_code:=peg_code;

  cancel_adjusts(False);

  if save_peg_code=2 then peg_on_rail9_menu_entry.Click   // 244d  turnout-road centre-line (sets peg_code=20, so do first)
                     else peg_on_rail8_menu_entry.Click;  // main-road centre-line (sets peg_code=20, so do first)

  if save_peg_code=2
     then begin
            peg_code:=22;                        // toggle to turnout side peg angle.
            peg_indicator_panel.Caption:='22';   // show him
          end
     else begin
            peg_code:=2;                         // main side peg angle.
            peg_indicator_panel.Caption:='2';    // show him Ctrl-2
          end;
            
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.peg_on_split_deflection_menu_entryClick(Sender:TObject);  // 213a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_is_free_menu_entry.Click;

  peg_code:=222;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_kp1_menu_entryClick(Sender: TObject);     // 227a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail1_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=801;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_kp2_menu_entryClick(Sender: TObject);     // 227a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail2_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=802;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_kp3_menu_entryClick(Sender: TObject);     // 227a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail3_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=803;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_kp4_menu_entryClick(Sender: TObject);     // 227a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail4_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=804;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_planing_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);

  peg_on_rail9_menu_entry.Click;   // 244d  turnout-road centre-line (sets peg_code=20, so do first)

  peg_code:=100;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.peg_on_heel_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);

  peg_on_rail9_menu_entry.Click;    // 213a turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=104;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_dp_menu_entryClick(Sender: TObject);

var
  save_peg_code:integer;

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  save_peg_code:=peg_code;

  cancel_adjusts(False);

  peg_on_rail8_menu_entry.Click;  // main-road centre-line (sets peg_code=20, so do first)

  if save_peg_code=3 then peg_code:=33         // toggle to turnout side peg angle.
                     else peg_code:=3;         // main side peg angle.

  peg_indicator_panel.Caption:='N';            // show him N 234e   was 3
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_ip_menu_entryClick(Sender:TObject);    // 208a

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=615;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_osmp_menu_entryClick(Sender: TObject);    // 226a

var
  i:integer;

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  if xing_type_i<>1
     then begin
            i:=alert(3,'php/890    peg  on  OSMP',
                       'Outside-slip design aid - peg position OSMP'
                      +'||To be usable this peg position normally requires a curviform V-crossing.'
                      +'||The current V-crossing is not curviform.',
                       '','','','continue  unchanged','cancel','change  to  curviform  and  continue',0);

            if i=5 then EXIT;
            if i=6 then curviform_crossing_menu_entry.Click;
          end;

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;    // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=620;      // OSMP

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_osxp_menu_entryClick(Sender: TObject);  // 226a

var
  i:integer;
  
begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  if xing_type_i<>1
     then begin
            i:=alert(3,'php/890    peg  on  OSXP',
                       'Outside-slip design aid - peg position OSXP'
                      +'||To be usable this peg position normally requires a curviform V-crossing.'
                      +'||The current V-crossing is not curviform.',
                       '','','','continue  unchanged','cancel','change  to  curviform  and  continue',0);

            if i=5 then EXIT;
            if i=6 then curviform_crossing_menu_entry.Click;
          end;

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;    // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=625;    // OSXP

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_CESP_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  if xing_type_i<>0        // curviform or generic crossing.
     then begin
            alert(6,'    curviform  or  generic  crossing',
                    '||The control template contains a curviform or generic V-crossing type.'
                   +'||There is no crossing entry straight in these types of V-crossings.'
                   +'||To change to a regular or parallel V-crossing type with an entry straight, click the `0template > V-crossing settings...`z menu item,'
                   +' or click the green indicator at the top left of the trackpad.',
                    '','','','','','O K',0);
            EXIT;
          end;
          

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;    // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=108;

  peg_indicator_panel.Caption:='N';         // show him no shortcut
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_fp_menu_entryClick(Sender: TObject);

var
  save_peg_code:integer;

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  save_peg_code:=peg_code;

  cancel_adjusts(False);

  if creating_tandem=True    // 218c
     then begin
            peg_on_rail2_menu_entry.Click;
            peg_code:=4;
          end
     else begin
            if save_peg_code=4 then peg_on_rail2_menu_entry.Click   // turnout-road crossing rail (sets peg_code=20, so do first)
                               else peg_on_rail3_menu_entry.Click;  // main-road crossing rail (sets peg_code=20, so do first)

            if save_peg_code=4 then peg_code:=44   // toggle to turnout side peg angle.
                               else peg_code:=4;   // main side peg angle.
          end;

  peg_indicator_panel.Caption:='4';      // show him Ctrl-4
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.peg_on_tcp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;            // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=5;                              // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_txp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;            // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=6;                              // then set it.
  peg_indicator_panel.Caption:='5';         // show him Ctrl-5
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.peg_on_trp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;            // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=7;                              // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_mcp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=8;                              // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_mxp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;             // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=9;                               // then set it.
  peg_indicator_panel.Caption:='7';          // show him Ctrl-7
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_mrp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=10;                             // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_overall_length_menu_entryClick(Sender: TObject);

begin
  if plain_track=True
     then begin
            peg_on_joint_end_menu_entry.Click;   // CTRL-1 instead   added 205c
            EXIT;
          end;  

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;                // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=11;                                 // then set it.
  peg_indicator_panel.Caption:='9';             // show him Ctrl-9
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.peg_on_adjacent_ts_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail6_menu_entry.Click;           // adjacent turnout-side centre-line (sets peg_code=20, so do first),

  peg_code:=12;                            // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_adjacent_ms_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail5_menu_entry.Click;           // adjacent main-side centre-line (sets peg_code=20, so do first),

  peg_code:=13;                            // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_EGTP_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;             // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=200;                             // then set it.
  peg_indicator_panel.Caption:='N';          // show him 'N'
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_EGORG_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;             // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=201;                             // then set it.
  peg_indicator_panel.Caption:='N';          // show him 'N'
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_IGTP_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;             // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=220;                             // then set it.
  peg_indicator_panel.Caption:='N';          // show him 'N'
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_IGORG_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;             // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=221;                             // then set it.
  peg_indicator_panel.Caption:='N';          // show him 'N'
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_TORG_menu_entryClick(Sender: TObject);

begin
               // only for a straight turnout with a curved crossing...

  if (plain_track=True) or (ABS(nomrad)<max_rad_test) or (spiral=True) or (xing_type_i<>1) then EXIT;  // ??? menu should be disabled.

  if tradius_is_straight=True      // 0.93.a ex 081
     then begin
            alert(6,'    peg  on  TORG  position',
                    'The switch heel angle and V-crossing angle for your current turnout are equal.'
                   +'||This means that the turnout radius is straight (infinite radius), and it is not therefore possible to put the fixing peg on its radial centre.',
                    '','','','','','O K  -  cancel',0);
            EXIT;
          end;

  cancel_adjusts(False);

  peg_on_rail9_menu_entry.Click;           // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=14;                            // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.peg_on_trans_start_menu_entryClick(Sender: TObject);

begin                          // peg on transition start.
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=15;                            // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_trans_length_menu_entryClick(Sender: TObject);

begin                          // peg on transition end.
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=16;                            // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.peg_on_trans_org_menu_entryClick(Sender: TObject);

begin                          // peg on transition calcs origin.
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=400;                           // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.peg_on_slew_start_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=300;                           // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.peg_on_slew_length_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=301;                           // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_MVJP_menu_entryClick(Sender: TObject);

begin                          // peg on main-side vee joint point (point rail end).
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=17;                             // then set it.
  peg_indicator_panel.Caption:='8';         // show him Ctrl-8
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_tminp_menu_entryClick(Sender: TObject);    // 213b

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;            // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=240;                            // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_texitp_menu_entryClick(Sender: TObject);   // 213b

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;            // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=241;                            // then set it.
  peg_indicator_panel.Caption:='E';         // show him no shortcut.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_mminp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=260;                            // then set it.
  peg_indicator_panel.Caption:='N';         // show him no shortcut.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_mexitp_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;            // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=261;                            // then set it.
  peg_indicator_panel.Caption:='E';         // show him no shortcut.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_TVJP_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;           // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=18;                            // then set it.
  peg_indicator_panel.Caption:='6';        // show him Ctrl-6
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.peg_on_midlength_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;                // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=19;                                 // then set it.
  peg_indicator_panel.Caption:='N';             // show him N
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.peg_on_dummy_vehicle_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;           // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=700;                           // then set it.
  peg_indicator_panel.Caption:='N';        // show him no shortcut.
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_user_defined_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);

  if udpeg_valid=True
     then begin
            case udpeg_rail of
                            0: peg_is_free_menu_entry.Click;    // sets peg_code=20, so do first...
                            1: peg_on_rail1_menu_entry.Click;
                            2: peg_on_rail2_menu_entry.Click;
                            3: peg_on_rail3_menu_entry.Click;
                            4: peg_on_rail4_menu_entry.Click;
                            5: peg_on_rail5_menu_entry.Click;
                            6: peg_on_rail6_menu_entry.Click;
                            7: peg_on_rail7_menu_entry.Click;
                            8: peg_on_rail8_menu_entry.Click;
                            9: peg_on_rail9_menu_entry.Click;
                          else peg_on_rail8_menu_entry.Click;   // ms centre-line.
            end;//case
          end
     else peg_on_rail8_menu_entry.Click;    // ms centre-line.

  peg_code:=999;                                // then set it.
  peg_indicator_panel.Caption:='U';             // show him U
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.pad_on_peg_menu_entryClick(Sender: TObject);

var
  padpegx,padpegy,dummy1,dummy2:extended;

begin
  if draw_mode<>2 then pad_form.lock_scaling_menu_entry.Click;
  normalize_transforms;
  docurving(True,True,pegx,pegy,padpegx,padpegy,dummy1,dummy2);   // calc current peg position.

  zoom_offsetx:=padpegx-screenx/2;
  zoom_offsety:=padpegy*hand_i+y_datum-screeny/2;
  redraw_pad(True,False);
end;
//___________________________________________________________________________________________

procedure Tpad_form.pad_on_notch_menu_entryClick(Sender: TObject);

begin
  if draw_mode<>2 then pad_form.lock_scaling_menu_entry.Click;

  zoom_offsetx:=notchx-screenx/2;
  zoom_offsety:=notchy-screeny/2;
  do_rollback:=False;                // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.notch_under_peg_menu_entryClick(Sender: TObject);

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.
  new_notch(get_peg_for_notch,True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.notch_linked_to_current_menu_entryClick(Sender: TObject);

begin
  notch_linked_to_current:=True;
  notch_linked_to_current_menu_entry.Checked:=True;      // radio item.
  notch_linked_code:=peg_code;
  do_linked_notch;                // move notch.
  redraw(True);                   // show it.
end;
//__________________________________________________________________________________________

procedure Tpad_form.notch_unlinked_from_current_menu_entryClick(Sender: TObject);

begin
  notch_linked_to_current:=False;
  notch_unlinked_from_current_menu_entry.Checked:=True;   // radio item.
end;
//___________________________________________________________________________________________

procedure Tpad_form.cycle_notch_menu_entryClick(Sender: TObject);

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  old_notchx:=notchx;      // for group linking...
  old_notchy:=notchy;
  old_notch_angle:=notch_angle;

  DEC(notch_index);                             // roll back to previous slot.
  if notch_index<0 then notch_index:=notch_c;

  notchx:=     undo_notch[notch_index].notch_x;       // retrieve previous entry...
  notchy:=     undo_notch[notch_index].notch_y;
  notch_angle:=undo_notch[notch_index].notch_k;

  if group_notch_linked=True then do_group_link_to_notch;

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.shift_current_onto_notch_menu_entryClick(Sender: TObject);

begin
  shift_onto_notch(True,True);
end;
//____________________________________________________________________________________

procedure Tpad_form.notch_under_bgnd_peg_popup_entryClick(Sender: TObject);   // mods for 0.79.a  02-06-06

var
  i:integer;
  link_wanted:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  link_wanted:=False;  // init.

  if Ttemplate(keeps_list.Objects[clicked_keep_index]).group_selected=True
     then begin
            if group_notch_linked=False
               then begin
                      repeat
                        i:=alert(4,'    link  group  to  notch ?',
                                   'Do you want to link the selected group of template(s) to subsequent moves of the pegging notch?',
                                   '','','more  information','yes  -  put  notch  under  peg  and  link  group','cancel','no  -  put  notch  under  peg  without  linking',3);
                        case i of
                              3: alert_help(0,group_link_help_str,'');
                              4: link_wanted:=True;
                              5: EXIT;
                        end;//case
                      until i<>3;
                    end
               else begin
                      i:=alert(2,'    group  linked  to  notch',
                                 'This template is a member of a group of templates which is currently linked to the pegging notch.'
                                +'||The notch can only be moved under the fixing peg on a background template if that template is not currently linked to it.',
                                 '','','','remove  template  from  group  and  move  notch','cancel','unlink  group  and  move  notch',0);
                      case i of
                           4: Ttemplate(keeps_list.Objects[clicked_keep_index]).group_selected:=False;
                           5: EXIT;
                           6: unlink_group;
                      end;//case
                    end;
          end;//group_selected

  new_notch(Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.notch_info,True);

                   // now switch on group linking if wanted...

  if link_wanted=True
     then begin
            group_notch_linked:=True;
            pad_form.group_linked_warning_panel.Show;
            pad_form.unlink_group_from_notch_menu_entry.Enabled:=True;
          end;

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________________________________________________________________________

procedure Tpad_form.set_brick_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (memo_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  with Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1 do begin

    timbering_brick_flag:=True;

    pad_marker_colour:=brick_form.store_marker_colour_panel.Color;
    use_pad_marker_colour:=True;

  end;//with

  clicked_keep_index:=-1;    // so can popup again.
  do_rollback:=False;
  redraw(True);              // to hide the highlighting.
end;
//______________________________________________________________________________

procedure Tpad_form.cancel_brick_popup_entryClick(Sender: TObject);     // 234a

begin
  if (keeps_list.Count<1) or (memo_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.timbering_brick_flag:=False;

  clicked_keep_index:=-1;    // so can popup again.
  do_rollback:=False;
  redraw(True);              // to hide the highlighting.
end;
//______________________________________________________________________________

procedure Tpad_form.info_popup_entryClick(Sender: TObject);

var
  info_str,memo_text_str:string;

begin
  if (keeps_list.Count<1) or (memo_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  memo_text_str:=memo_list.Strings[list_position];

  with Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1 do begin

    info_str:='    '+IntToStr(list_position+1)+'  '+reference_string+'   '+id_number_str
                           +'||  '+top_label
                           +'||--------------------------------------------------------------'
                           +'||      Information  about  this  template :'
                           +'||( all dimensions in millimetres )'
                           +'||'+keeps_list.Strings[list_position]
                           +'||--------------------------------------------------------------'
                           +'||      Your  memo  notes  for  this  template :'
                           +'||'+memo_text_str{) out 0.91.b};
  end;//with

  help(-3,info_str,'');

  clicked_keep_index:=-1;    // so can popup again.
  do_rollback:=False;
  redraw(True);              // to hide the highlighting.
end;
//_________________________________________________________________________________________

procedure Tpad_form.edit_memo_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (memo_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  keep_form.edit_memo_menu_entry.Click;

  clicked_keep_index:=-1;    // so can popup again.
  do_rollback:=False;
  redraw(True);              // to hide the highlighting.
end;
//__________________________________________________________________________________________

procedure Tpad_form.jotter_to_memo_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (memo_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  keep_form.add_jotter_to_memo_menu_entry.Click;

  clicked_keep_index:=-1;    // so can popup again.
  do_rollback:=False;
  redraw(True);              // to hide the highlighting.
end;
//________________________________________________________________________________________

procedure Tpad_form.make_double_track_ts_menu_entryClick(Sender: TObject);

begin
  make_double_track(1);
end;
//______________________________________________________________________________________

procedure Tpad_form.make_double_track_ms_menu_entryClick(Sender: TObject);

begin
  make_double_track(0-1);
end;
//_______________________________________________________________________________________

procedure Tpad_form.make_external_road_menu_entryClick(Sender: TObject);

begin
  make_pt_geo_rad(1,True);   // click=True.
end;
//_________________________________________________________________________________________

procedure Tpad_form.make_internal_road_menu_entryClick(Sender: TObject);

begin
  make_pt_geo_rad(-1,True);   // click=True.
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_separate_approach_menu_entryClick(Sender: TObject);

begin
  make_separate_approach(True);   // click=True
end;
//_______________________________________________________________________________________

procedure Tpad_form.make_separate_exit_menu_entryClick(Sender: TObject);

var
  saved_control,new_template:Ttemplate_info;

begin
  if plain_track=True
     then begin
            alert(6,'    make  separate  exit  track',
                    'The control template is a plain track template.'
                    +'||A plain track template has no exit track to be split off.'
                    +'||To make a split in plain track, click the `0tools > make split > make split at peg`1 menu item.',
                    '','','','','cancel','',0);
            EXIT;
          end;


  if retpar_i=1  // 0.82.a  not for a parallel crossing...
     then begin
            alert(6,'    make  separate  exit  track  -  parallel  V-crossing',
                    'This turnout has a parallel type of V-crossing.'
                   +'||It is not possible to split separate exit tracks for a parallel V-crossing.'
                   +'||Click the TEMPLATE > V-CROSSING OPTIONS... menu item to change to a different type of V-crossing.',
                    '','','','','cancel','',0);
            EXIT;
          end;


  if turnoutx<=(mvjpx+minfp)
     then begin
            alert(6,'    no  exit  track',
                    'This turnout has no exit track to be separated.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if (turnoutx-mvjpx)<(10*scale)            // 10ft scale arbitrary minimum
     then begin
            if alert(7,'    make  separate  exit  track  -  very  short',
                       'The exit track from this turnout is very short.'
                      +'||Are you sure you want it to be a separate template?',
                       '','','','','no  -  cancel','yes  -  make  separate  exit  track',0)=5
               then EXIT;
          end;

  if check_control_template_is_valid('split')=False then EXIT;  // 0.93.a  zero length

  saved_control:=hold_the_control;  // 227a

  try

    turnoutx:=mvjpx;   // crop all exit track.
    turnout_i:=1;      // length locked at turnoutx.

    do_rollback:=False;
    peg_on_overall_length_menu_entry.Click;       // and put peg there.

    gocalc(0,0);

    new_template:=hold_the_control;  // 227a

    if (spiral=True) and (pad_form.make_tools_normalize_transitions_menu_entry.Checked=True)
       then begin
              gocalc(0,0);                 // peg calcs.
              normalize_transition;        // ignore result.
            end;

    if (slewing=True) and (slew_s>turnoutx)
       then begin
              gocalc(0,0);                                 // peg calcs.
              pad_form.disable_slewing_menu_entry.Click;   // new template in unslewed section.
            end;

    gocalc(0,0);    // do peg calcs.

    do_rollback:=False;
    store_and_background(False,False);  // keep it and copy to background.
    if keep_added=False
       then begin
              unhold_the_control(saved_control);   // 227a
              show_and_redraw(True,False);
              EXIT;                         // he cancelled.
            end;

              // now change previous current to plain track...

    unhold_the_control(saved_control);   // 227a

    retain_on_make;    // do blanking, shoves, diffs, crossing entry straight, cancel platforms  213a

    turnoutx:=turnoutx-mvjpx;          // only the exit track wanted.
    xorg:=turnoutx;

    plain_track:=True;
    set_plain_track(True,True);

    do_rollback:=False;
    peg_on_joint_end_menu_entry.Click;     // put peg at CTRL-1 rail joint with turnout.

    gocalc(0,0);       // peg calcs.

    snake_onto_this_peg(new_template.notch_info,new_template.keep_dims,False,False);   // align over it and snake onto peg (facing-trailing).

    if (spiral=True) and (pad_form.make_tools_normalize_transitions_menu_entry.Checked=True)
       then begin
              gocalc(0,0);                 // peg calcs.
              normalize_transition;        // ignore result.
            end;

    if (slewing=True) and (slew_s>turnoutx)
       then begin
              gocalc(0,0);                                 // peg calcs.
              pad_form.disable_slewing_menu_entry.Click;   // new template in unslewed section.
            end;

    clear_current_name;

    rail_options_form.restore_all_button.Click;  // 211c

  finally
    show_and_redraw(True,True);                 // in case copy caused a current hide.
  end;//try
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_split_at_peg_menu_entryClick(Sender: TObject);

var
  saved_control:Ttemplate_info;
  new_len:extended;

  split_str:string;

begin
  if plain_track=False
     then begin
            alert(6,'    make  split  at  peg  -  not  plain  track',
                    'Make split at peg.'
                   +'||The control template is not plain track.'
                   +'||It is not possible to use this function to split a turnout or half-diamond. This function applies only to plain track.'
                   +'||You should first use the `0TOOLS > MAKE SPLIT > MAKE SEPARATE APPROACH TRACK`1 and/or `0MAKE SEPARATE EXIT TRACK`1 menu items to split a new plain track template from a turnout.',
                    '','','','','cancel  split','',0);
            EXIT;
          end;

  if splitting_for_tangential=True
     then split_str:=' for the simple link, or reset the peg at `0CTRL-0`2.'
     else split_str:='.';

  if (pegx<=minfp) or (pegx>=(turnoutx-minfp))
     then begin
            alert(6,'    make  split  at  peg  -  beyond  limits',
                    'The current fixing peg position is not within the template length.'
                   +'||Use the `0CTRL-F8`2 `0move peg`3 mouse action to position the fixing peg at the desired split location'+split_str,
                    '','','','','cancel  split','',0);
            EXIT;
          end;


  if ((turnoutx-pegx)<(10*scale)) or (pegx<(10*scale))                // 10ft scale arbitrary minimum
  and (splitting_for_tangential=False)
     then begin
            if alert(7,'    make  split  at  peg  -  short  template',
                       'The current fixing peg position will result in a very short split template.'
                      +'||Are you sure you want to split this template?',
                       '','','','','no  -  cancel  split','yes  -  make  split  at  peg',0)=5
               then EXIT;
          end;


  if check_control_template_is_valid('split')=False then EXIT;  // 0.93.a  zero length

  if make_tools_cancel_blanking_menu_entry.Checked=True then startx:=0;         // cancel any blanking
  if make_tools_cancel_rolled_menu_entry.Checked=True then tb_roll_percent:=0;  // cancel for both templates (new joint at peg).

  new_len:=turnoutx-pegx;    // save for the new curent template

  saved_control:=hold_the_control;  // 227a

  try
    turnoutx:=pegx;                       // shorten existing to peg
    xorg:=turnoutx;

    peg_on_joint_end_menu_entry.Click;    // peg at new CTRL-1.
    gocalc(0,0);                          // do peg calcs.

    if (spiral=True) and (make_tools_normalize_transitions_menu_entry.Checked=True)
       then begin
              gocalc(0,0);                 // peg calcs.
              normalize_transition;        // ignore result.
            end;

    store_and_background(False,False);   // keep it and copy to background.
    if keep_added=False
       then begin
              unhold_the_control(saved_control);   // 227a
              // done above copy_keep(cur_tem);            // restore original.
              show_and_redraw(True,False);
              EXIT;                          // he cancelled.
            end;

      // now change previous current...

    unhold_the_control(saved_control);   // 227a

    retain_on_make;    // do blanking, shoves, diffs, crossing entry straight, cancel platforms  213a

    gocalc(0,0);            // init peg calcs.

    swap_end_for_end;
    gocalc(0,0);            // new peg calcs.

    turnoutx:=new_len;      // shorten to saved length.
    xorg:=turnoutx;

    clear_current_name;

    peg_on_joint_end_menu_entry.Click; // put peg at CTRL-1 rail joint.
    gocalc(0,0);                       // peg calcs.

    if (spiral=True) and (make_tools_normalize_transitions_menu_entry.Checked=True)
       then begin
              gocalc(0,0);                 // peg calcs.
              normalize_transition;        // ignore result.
            end;

    if (slewing=True) and (slew_s>turnoutx)
       then begin
              gocalc(0,0);                        // peg calcs.
              disable_slewing_menu_entry.Click;   // new template in unslewed section.
            end;

  finally
    show_and_redraw(True,True);                 // in case copy caused a current hide.
  end;//try
end;
//___________________________________________________________________________________________

procedure Tpad_form.make_simple_crossover_menu_entryClick(Sender: TObject);

begin
  way_spacings_top_str:='    make  ordinary  crossover';    // 226c
  way_spacings_cancel_str:='cancel  crossover     ';        // 226c

  make_crossover(True,False,False);      // ignore result
end;
//_____________________________________________________________________________________

procedure Tpad_form.make_branch_crossover_menu_entryClick(Sender: TObject);  // 209c

begin
  make_branch_crossover;   // ignore result
end;
//______________________________________________________________________________

procedure Tpad_form.make_y_turnout_menu_entryClick(Sender: TObject);   // 227a

var
  modal_result:TModalResult;   // 212a wine bug

begin
  modal_result:=do_show_modal(create_y_form);

  if modal_result=mrOk
     then begin
                 if create_y_form.very_short_radio.Checked=True then make_symm_y_turnout(0)  // very short Y-turnout
            else if create_y_form.short_radio.Checked=True      then make_symm_y_turnout(1)  // short Y-turnout
            else if create_y_form.normal_radio.Checked=True     then make_symm_y_turnout(2)  // normal Y-turnout
            else if create_y_form.long_radio.Checked=True       then make_symm_y_turnout(3); // long Y-turnout
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.make_regular_ladder_menu_entryClick(Sender: TObject);

var
  save_timbering:boolean;
  i:integer;

begin
  save_timbering:=square_on_menu_entry.Checked;

  if save_timbering=True
     then begin
                    // change to equalized timbering ...

            equalized_incremental_menu_entry.Enabled:=True;
            equalized_incremental_menu_entry.Click;
          end;

  way_spacings_top_str:='    make  regular  ladder';          // 226c
  way_spacings_cancel_str:='cancel  regular  ladder     ';    // 226c

  if make_crossover(False,False,False)=False     // not simple, no curviform
     then begin
            if save_timbering=True   // restore his square-on
               then begin
                      square_on_menu_entry.Enabled:=True;
                      square_on_menu_entry.Click;
                    end;
            EXIT;
          end;

  gocalc(0,0);
  if make_diamond_crossing=False then EXIT;
  gocalc(0,0);
  pad_form.pad_on_peg_menu_entry.Click;       // centralize pad on it.
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.make_return_curve_menu_entryClick(Sender: TObject);

   // mods for 218d ...

var
  i:integer;

  rcurve,rlen,chord,turn_angle:extended;

  exit_notch,mid_notch,trp_notch,match_notch:Tnotch;

  dir,mis_match,prev_mis_match,curvature:extended;
  temp1,temp2,temp3,trans_trp_rad:extended;

begin
  if check_control_template_is_valid('return  curve')=False then EXIT;  // 0.93.a  zero length

  if plain_track=True
     then begin
            alert(6,'    make  return  curve  -  plain  track',
                    'The control template is plain track.'
                   +'||It is not meaningful to construct a return curve from a plain track template. The control template must be a turnout or half-diamond.'
                   +'||Select the `0TEMPLATE > INSERT TURNOUT IN PLAIN TRACK`1 menu item.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if retpar_i=1
     then begin
            alert(6,'    make  return  curve  -  parallel  crossing',
                    'Your current V-crossing type is parallel, which already includes a return curve.'
                   +' You may need to extend the length of the turnout to see it, using the `0ADJUST OVERALL LENGTH`1 mouse action `0F4`2.'
                   +'||It is not possible to add another return curve when the crossing type is parallel.'
                   +'||To change to a regular or generic type of V-crossing from which this function can make a return curve, select the'
                   +'|`0template > V-crossing settings...`z menu item.',
                  '','','','','cancel','',0);
            EXIT;
          end;

  if slewing=True
     then begin
            alert(6,'    make  return  curve  -  slewed  track',
                    'Your control template contains a slew.'
                   +'||Sorry, this return curve function is not available for slewed track.'
                   +'||You can add a return curve by other means, for example by selecting a parallel type of V-crossing, or by making a branch track or simple link.',
                  '','','','','cancel','',0);
            EXIT;
          end;

  if xing_type_i=1
     then begin
            if alert(3,'    make  return  curve  -  curviform  V-crossing',
                   'Your current V-crossing type is curviform.'
                  +'||It would be unusual to have a return curve from a curviform V-crossing. In many cases the result will be a sharper radius than necessary and an instant curve reversal at the join, leading to rough running.'
                  +'||To change to a regular or generic type of V-crossing more suitable for a return curve, select the'
                  +'|`0template > V-crossing settings...`z menu item.',
                   '','','','','cancel','continue  -  make  return  curve  anyway',0)=5 then EXIT;
          end;

  if spiral=True
     then begin
            if alert(3,'    make  return  curve  -  transition  curve',
                   'The control template contains a transition curve.'
                  +'||The return curve function will attempt to create a matching return curve as a fixed-radius template. This may take a few seconds.'
                  +'||The result will be satisfactory in most cases, but if the transition curve is very short or sharp you may need to make some further adjustment.'
                  +'||Or alternatively change to a parallel type V-crossing instead. Or use the `0simple link`1 function.',
                   '','','','','cancel','continue  -  make  return  curve',0)=5 then EXIT;
          end;

  way_spacings_top_str:='    make  return  curve';              // 226c
  way_spacings_cancel_str:='cancel  return  curve     ';        // 226c

  if do_way_spacings(True,1)=False then EXIT;

  if (g>(47*inscale)) and (cpi.trtscent_pi<(134*inscale))
     then begin
            if alert(1,'   make  return  curve',
               'Your current setting for the TS (turnout-side) track spacing is less than the 6ft WAY (11ft-2in centres, 134 inches) minimum for running lines on UK standard-gauge railways.'
              +'||For sidings and marshalling yards a closer track spacing down to 5ft WAY is sometimes used.'
              +'||If the tracks are sharply curved you will need additional track spacing above the minimum to provide sufficient clearance.',
               '','','','','cancel','continue - make  return  curve  at  current  setting    ',0)=5 then EXIT;
          end;

  rcurve:=calculate_return_curve_radius(exit_notch,mid_notch,trp_notch);  // 218d

  if spiral=True
     then begin
            docurving(False,True,trpx,g/2,temp1,temp2,temp3,trans_trp_rad);  // get curving radius at TRP
            rcurve:=rcurve*SGZ(curved_onto_calc(retr,0-trans_trp_rad));      // adjust sign of radius
          end
     else rcurve:=rcurve*SGZ(curved_onto_calc(retr,0-clrad1));   // adjust sign of radius

   // modify control template and store...

  if turnoutx<mvjpx then turnoutx:=mvjpx;
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;

  turnout_road_i:=0;               // need standard length.

  peg_on_trp_menu_entry.Click;              // peg on end of return curve
  gocalc(0,0);
  new_notch(get_peg_for_notch,False);       // and notch under

  reset_peg_menu_entry.Click;             // peg on CTRL-0

  redraw(False);                          // calc these.

  store_and_background(False,False);     // keep it and copy to background.
  if keep_added=False then EXIT;         // he cancelled.

  retain_on_make;    // do blanking, shoves, diffs, crossing entry straight, cancel platforms  213a

  spiral:=False;
  slewing:=False;

  plain_track:=True;
  set_plain_track(True,True);

  if railen[pt_i]>minfp then tb_roll_percent:=(1-13.25/railen[pt_i])*100;  // roll rails by 13.25" arbitrary below 100%, for best match to parallel crossing, adjust joint at far end  223c

  rolled_in_sleepered:=True;    // rolled-in sleepers present   223c

  hand_i:=0-hand_i;       // return curve is opposite hand to turnout

  chord:=get_notch_distance(exit_notch,trp_notch);
  turn_angle:=ARCSIN(chord/2/rcurve)*2;
  rlen:=rcurve*turn_angle;                           // length of return curve.

  xorg:=ABS(rlen);
  turnoutx:=xorg;

  nomrad:=rcurve;

  peg_on_joint_end_menu_entry.Click;   // to Ctrl-1

  gocalc(0,0);                         // force a recalc for the peg.

  shift_onto_notch(False,False);       // put it on TRP
  gocalc(0,0);

  reset_notch_menu_entry.Click;        // put notch away
  Application.ProcessMessages;
  
  reset_peg_menu_entry.Click;          // peg on CTRL-0
  gocalc(0,0);

  swap_end_for_end;                    // CTRL-0 now at TRP
  gocalc(0,0);

      // adjust radius for better match at TVJP ...

  match_notch:=get_snap_peg_xy_data(1);     // CTRL-1

  mis_match:=get_notch_distance(exit_notch,match_notch);

  i:=0;    // init

  if mis_match>=0.005    // arbitrary
     then begin

            wait_form.waiting_label.Caption:='please  wait ...';
            wait_form.waiting_label.Width:=wait_form.Canvas.TextWidth(wait_form.waiting_label.Caption);  // bug fix for Wine

            wait_form.wait_progressbar.Visible:=False;
            wait_form.cancel_button.Visible:=False;
            wait_form.Show;

            Application.ProcessMessages;

            curvature:=1/ABS(nomrad);
            dir:=curvature/10;            // initial step 10%

            repeat
              INC (i);
              if i>10000 then BREAK;      // safety  arbitrary

              prev_mis_match:=mis_match;

              curvature:=curvature+dir;
              nomrad:=1/curvature;        // modify radius

              turn_angle:=ARCSIN(chord/2/ABS(nomrad))*2;
              rlen:=ABS(nomrad)*turn_angle;                // adjust length of return curve for new rad

              xorg:=ABS(rlen);
              turnoutx:=xorg;

              gocalc(0,0);

              match_notch:=get_snap_peg_xy_data(1);     // CTRL-1

              mis_match:=get_notch_distance(exit_notch,match_notch);

              if mis_match>prev_mis_match
                 then dir:=0-dir/10;            // try smaller increments and go back

            until mis_match<0.005;    // or break

            wait_form.Hide;

            Application.ProcessMessages;

          end;

  gocalc(0,0);   // redraw(False);   // in case copy caused a current hide.

  clear_current_name;

  rail_options_form.restore_all_button.Click;  // 211c

  redraw(False);

  if i>10000
     then begin
            ShowMessage('Sorry, it has not been possible to make a return curve.'
                        +#13+#13+'The template showing will need further manual adjustment.');
            EXIT;
          end;

  clicked_keep_index:=keeps_list.Count-1;  // get the turnout back
  make_control_popup_entry.Click;

  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.make_branch_track_menu_itemClick(Sender: TObject);       // 0.79.a

begin
  if plain_track=True
     then begin
            alert(6,'    make  branch  track  -  plain  track',
                    'The control template is plain track.'
                   +'||It is not meaningful to add a branch track to a plain track template. The control template must be a turnout or half-diamond.'
                   +'||Select the `0TEMPLATE > INSERT TURNOUT IN PLAIN TRACK`1 or `0TEMPLATE > NEW TEMPLATE (QUICK SET)...`1 menu items, or copy an existing background template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if retpar_i=1
     then begin
            if alert(3,'    make  branch  track  -  parallel  V-crossing',
                      'Your current V-crossing type is parallel, which already includes a branch track as a return curve.'
                     +' You may need to extend the length of the template to see it, using the ADJUST OVERALL LENGTH mouse action (F4).'
                     +'||This function will create an additional separate length of branch track.',
                      '','','','','cancel','continue',0)=5
               then EXIT;
          end;

  if check_control_template_is_valid('branch  track')=False then EXIT;  // 0.93.a  zero length

  do_rollback:=False;  // while pegging.

  if (turnoutx<mvjpx) and (creating_tandem=False) then turnoutx:=mvjpx;    // 218a
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;

  if retpar_i<>1       // not parallel V-crossing
     then begin
            turnout_road_i:=0;                // need standard length.
            peg_on_TVJP_menu_entry.Click;     // put the peg on splice rail joint.
           end
      else peg_on_tolp_menu_entry.Click;      // parallel V-crossing. put peg on end of turnout road.

  gocalc(0,0);     // calc these.

  do_rollback:=False;
  store_and_background(False,False);  // keep it and copy to background.
  if keep_added=False then EXIT;      // he cancelled.

  startx:=0;         // plain track   no blanking
  retain_on_make;    // shoves, diffs, crossing entry straight, cancel platforms  213a

  do_rollback:=False;
  new_notch(get_peg_for_notch,False);

  notch_angle:=notch_angle+Pi;  // pegging Ctrl-1 means trailing-to-trailing.

            // now change to curved plain track...

  if spiral=True then nomrad:=clrad_at_x(pegx);    // use curving rad at peg.

  spiral:=False;   // plain curve for branch track.

  if slewing=True then disable_slewing_menu_entry.Click;

  plain_track:=True;
  set_plain_track(True,True);

  hand_i:=0-hand_i;       // branch track is opposite hand to turnout.

  if creating_tandem=False
     then begin
            xorg:=132*scale;        // length of branch track.  2 chains arbitrary.
            turnoutx:=xorg;
          end
     else begin
            xorg:=99*scale;         // length of branch track.  1.5 chain arbitrary.
            turnoutx:=xorg;
          end;

  if xing_calc_i=1 then nomrad:=curved_onto_calc(tradius-g/2,nomrad);   // change radius if curviform crossing. (resultant turnout radius).

  if retpar_i=1 then nomrad:=nomrad-retcent;  // change radius to parallel crossing exit.

  do_rollback:=False;
  peg_on_joint_end_menu_entry.Click;   // to Ctrl-1

  gocalc(0,0); //redraw_pad(False,False);             // force a recalc for the peg.

  shift_onto_notch(False,False);       // finally join branch track onto turnout.

  do_rollback:=False;
  pad_on_peg_menu_entry.Click;          // put it in centre of pad.

  show_and_redraw(True,False);   // in case copy caused a current hide.

  clear_current_name;

  rail_options_form.restore_all_button.Click;  // 211c

  redraw_pad(True,True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.mirror_current_menu_entryClick(Sender: TObject);

begin
  do_rollback:=False;
  rotate_current_180_menu_entry.Click;      // rotate it.
  gocalc(0,0);                              // need a recalc so can swap hand.

  swap_hand;               // to opposite hand
  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.make_mirror_menu_entryClick(Sender: TObject);

begin
  make_mirror_on_peg;              // ignore RESULT.
  show_and_redraw(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.make_diamond_crossing_menu_entryClick(Sender: TObject);

begin
  make_diamond_crossing;      // ignore result.
  show_and_redraw(True,True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.select_centre_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  select_centre:=True;
  if check_grey_paper=False then Cursor:=cross_hairs_cursor;  //crCross; mod 13-1-01.
  pad_caption('select  trackpad  centre ...');
end;
//___________________________________________________________________________________

procedure Tpad_form.show_control_template_menu_entryClick(Sender: TObject);   // 209c

begin
  hidden_on_store:=0;             // user has now overridden this
  show_and_redraw(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_control_template_menu_entryClick(Sender: TObject);

begin                             // hide the control template (shows background items only).
  hidden_on_store:=0;             // 205c user has now overridden this
  do_hide_current;                // 209c
end;
//__________________________________________________________________________________________

procedure Tpad_form.undo_changes_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
                 // first check previous slot contains valid data..

  if turnoutx=0 then n:=undo_index     // 0.93.a invalidated templates are not in the register
                else n:=undo_index-1;

  if n<0 then n:=undo_c;
  if rollback_reg[n].valid_flag=False then EXIT;

  if turnoutx<>0 then DEC(undo_index);         // if 0.93.a, ok, roll back to previous slot.

  if undo_index<0 then undo_index:=undo_c;

  copy_keep(rollback_reg[undo_index].rollback_info); // retrieve previous entry.

               // 0.93.a ...

  current_name_str:=rollback_reg[undo_index].rollback_name_str;
  current_memo_str:=rollback_reg[undo_index].rollback_memo_str;
  info_form.ref_name_label.Caption:=current_name_str;

    // flag this is a undo changes redraw (no rollback)..

  show_and_redraw(False,False);   // immediate redraw in case shortcut held down.
end;
//_______________________________________________________________________________________

procedure Tpad_form.redo_changes_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
                  // first check previous slot contains valid data..

  if turnoutx=0 then n:=undo_index     // 0.93.a invalidated templates are not in the register
                else n:=undo_index+1;

  if n>undo_c then n:=0;
  if rollback_reg[n].valid_flag=False then EXIT;

  if turnoutx<>0 then INC(undo_index);        // ok, roll forward to next slot.
  if undo_index>undo_c then undo_index:=0;

  copy_keep(rollback_reg[undo_index].rollback_info);   // retrieve next entry.

             // 0.93.a ...

  current_name_str:=rollback_reg[undo_index].rollback_name_str;
  current_memo_str:=rollback_reg[undo_index].rollback_memo_str;
  info_form.ref_name_label.Caption:=current_name_str;

       // flag this is a redo changes redraw (no rollback)..

  show_and_redraw(False,False);       // immediate redraw in case shortcut held down.
end;
//___________________________________________________________________________________________

procedure unpark_template(n:integer);   // 223d

begin
  if classic_templot=False then store_and_background(False,False);  // 0.93.a Quick mode - first store existing control template

  copy_keep(parking_bay[n]);           // retrieve parked entry.
  show_and_redraw(True,True);          // redraw pad when ready.
  current_name_str:=park_name_str[n];
  current_memo_str:=park_memo_str[n];
  info_form.ref_name_label.Caption:=current_name_str;
end;
//______________________________________________________________________________

procedure Tpad_form.park_1_menu_entryClick(Sender: TObject);

begin
  fill_kd(parking_bay[0]);              // put template in bay slot.
  unpark_1_menu_entry.Enabled:=True;
  exchange_1_menu_entry.Enabled:=True;  // 223d

  if current_name_str=''
     then begin
            unpark_1_menu_entry.Caption:='bay 1 :   &retrieve  parked  template';          // 208a mods
            exchange_1_menu_entry.Caption:='bay 1 :   e&xchange  with  parked  template';        // 223d
          end
     else begin
            unpark_1_menu_entry.Caption:='bay 1 :   &retrieve  "'+current_name_str+'"';
            exchange_1_menu_entry.Caption:='bay 1 :   e&xchange  with  "'+current_name_str+'"';    // 223d
          end;

  park_name_str[0]:=current_name_str;
  park_memo_str[0]:=current_memo_str;
end;
//_______________________________

procedure Tpad_form.unpark_1_menu_entryClick(Sender: TObject);

begin
  unpark_template(0);
end;
//________________________________________________________________________________

procedure Tpad_form.exchange_1_menu_entryClick(Sender: TObject);    // 223d

begin
  copy_template_info_from_to(False,parking_bay[0],parking_bay[3]);    // bay 3 is temp storage
  park_name_str[3]:=park_name_str[0];
  park_memo_str[3]:=park_memo_str[0];

  park_1_menu_entry.Click;     // park new one in bay 1

  unpark_template(3);     // retrieve from temp
end;
//______________________________________________________________________________

procedure Tpad_form.park_2_menu_entryClick(Sender: TObject);

begin
  fill_kd(parking_bay[1]);              // put template in bay slot.
  unpark_2_menu_entry.Enabled:=True;
  exchange_2_menu_entry.Enabled:=True;  // 223d

  if current_name_str=''
     then begin
            unpark_2_menu_entry.Caption:='bay 2 :   r&etrieve  parked  template';          // 208a mods
            exchange_2_menu_entry.Caption:='bay 2 :   ex&change  with  parked  template';        // 223d
          end
     else begin
            unpark_2_menu_entry.Caption:='bay 2 :   r&etrieve  "'+current_name_str+'"';
            exchange_2_menu_entry.Caption:='bay 2 :   ex&change  with  "'+current_name_str+'"';    // 223d
          end;

  park_name_str[1]:=current_name_str;
  park_memo_str[1]:=current_memo_str;
end;
//_______________________________

procedure Tpad_form.unpark_2_menu_entryClick(Sender: TObject);

begin
  unpark_template(1);
end;
//______________________________________________________________________________

procedure Tpad_form.exchange_2_menu_entryClick(Sender: TObject);    // 223d

begin
  copy_template_info_from_to(False,parking_bay[1],parking_bay[3]);    // bay 3 is temp storage
  park_name_str[3]:=park_name_str[1];
  park_memo_str[3]:=park_memo_str[1];

  park_2_menu_entry.Click;     // park new one in bay 2

  unpark_template(3);     // retrieve from temp
end;
//______________________________________________________________________________

procedure Tpad_form.park_3_menu_entryClick(Sender: TObject);

begin
  fill_kd(parking_bay[2]);              // put template in bay slot.
  unpark_3_menu_entry.Enabled:=True;
  exchange_3_menu_entry.Enabled:=True;  // 223d

  if current_name_str=''
     then begin
            unpark_3_menu_entry.Caption:='bay 3 :   re&trieve  parked  template';          // 208a mods
            exchange_3_menu_entry.Caption:='bay 3 :   exch&ange  with  parked  template';        // 223d
          end
     else begin
            unpark_3_menu_entry.Caption:='bay 3 :   re&trieve  "'+current_name_str+'"';
            exchange_3_menu_entry.Caption:='bay 3 :   exch&ange  with  "'+current_name_str+'"';    // 223d
          end;

  park_name_str[2]:=current_name_str;
  park_memo_str[2]:=current_memo_str;
end;
//_______________________________

procedure Tpad_form.unpark_3_menu_entryClick(Sender: TObject);

begin
  unpark_template(2);
end;
//______________________________________________________________________________

procedure Tpad_form.exchange_3_menu_entryClick(Sender: TObject);    // 223d

begin
  copy_template_info_from_to(False,parking_bay[2],parking_bay[3]);    // bay 3 is temp storage
  park_name_str[3]:=park_name_str[2];
  park_memo_str[3]:=park_memo_str[2];

  park_3_menu_entry.Click;     // park new one in bay 3

  unpark_template(3);          // retrieve from temp
end;
//______________________________________________________________________________

procedure Tpad_form.convert_vcrossing_RAM_to_CLM_menu_entryClick(Sender: TObject);

var
  k,k3n_old:extended;

begin
  if k3n<minfp then EXIT;     // div 0 or negative angle ??
  k3n_old:=k3n;

  try
    k:=2*ARCTAN(1/2/k3n);     // new angle for existing k3n units in CLM.
    k3n:=1/TAN(k);            // set new k3n RAM to give this angle.
    redraw(True);
  except
    k3n:=k3n_old;             // all gone wrong?? restore k3n.
  end;//try

  set_xing_k_i;      // set selector list index to match current k3n.
end;
//______________________________________________________________________________

procedure Tpad_form.convert_kcrossing_ram_to_clm_menu_entryClick(Sender: TObject);

var
  k,hdkn_old:extended;

begin
  if hdkn<minfp then EXIT;    // div 0 or negative angle ??
  hdkn_old:=hdkn;

  try
    k:=2*ARCTAN(1/2/hdkn);    // new angle for existing hdkn units in CLM.
    hdkn:=1/TAN(k);           // set new hdkn RAM to give this angle.
    redraw(True);
  except
    hdkn:=hdkn_old;           // all gone wrong?? restore hdkn.
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.spacing_ring_menu_entryClick(Sender: TObject);

begin
  if ring_has_been_shown=False then grid_form.jump_to_centre_button.Click;    // 0.98.a move to centre on first showing

  show_spacing_rings:=True;
  ring_has_been_shown:=True;    // 0.98.a

  hide_info_menu_entry.Click;   // hide the info panel, so that KB shortcut keys are available for the buttons.
  shove_timber_form.Close;      // ditto.
  if Application.Terminated=False then Application.ProcessMessages;

  grid_form.Show;

  do_rollback:=False;
  redraw(True);
end;
//________________________________________________________________________________

procedure Tpad_form.fkey_chart_menu_entryClick(Sender: TObject);

begin
  do_fkey_chart;
end;
//_____________________________________________________________________________________________

procedure Tpad_form.pad_about_Templot_menu_entryClick(Sender: TObject);

begin
  mw_form.Left:=pad_form.ClientWidth-100;
  mw_form.Top:=0;

  mw_form.Show;     // 234c

  with control_room_form do begin
    about_templot_version_menu_entry.Click;
  end;//with
end;
//__________________________________________________________________________________________

procedure Tpad_form.extra_fine_adjust_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);                           // need a recalc from now_X etc.
  extra_fine_adjust_menu_entry.Checked:=True;      // radio item.
  fine_adjust:=25;                                 // modify mouse response factors.
end;
//__________________________________________________________________________________________

procedure Tpad_form.fine_adjust_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);                            // need a recalc from now_X etc.
  fine_adjust_menu_entry.Checked:=True;      // radio item.
  fine_adjust:=5;                            // modify mouse response factors.
end;
//__________________________________________________________________________________________

procedure Tpad_form.normal_adjust_menu_entryClick(Sender: TObject);

begin
  normal_adjust_menu_entry_click;
end;
//___________________________________________________________________________________________

procedure Tpad_form.coarse_adjust_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);                       // need a recalc from now_X etc.
  coarse_adjust_menu_entry.Checked:=True;      // radio item.
  fine_adjust:=1/5;                            // modify mouse response factors.
end;
//__________________________________________________________________________________________

procedure Tpad_form.click_bgnd_selection_menu_entryClick(Sender: TObject);

             // toggle group selections by clicking name labels.
begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  cancel_adjusts(False);

  hide_name_labels:=False;
  show_name_labels_menu_entry.Checked:=True;  // radio item

  clicked_keep_index:=-1;
  click_bgnd_select:=True;
  name_highlighted:=-1;
  pad_caption('click  backgnd  template  to  group  select  or  de-select ...');
  redraw_pad(True,False);    // to add small names and show existing selections.
end;
//________________________________________________________________________________________

procedure Tpad_form.transparent_names_menu_entryClick(Sender: TObject);

begin
  transparent_names_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.boxed_over_names_menu_entryClick(Sender: TObject);

begin
  boxed_over_names_menu_entry.Checked:=True;    // radio item.
  do_rollback:=False;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.names_scaled_menu_entryClick(Sender: TObject);

begin
  names_scaled_menu_entry.Checked:=True;     // radio item
  do_rollback:=False;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.names_fullsize_menu_entryClick(Sender: TObject);

begin
  names_fullsize_menu_entry.Checked:=True;     // radio item
  do_rollback:=False;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.rotate_keeps_180_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  mouse_rotate_sync_wanted:=False;  // not here for mouse action

  cancel_adjusts(False);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  do_rollback:=False;
  redraw(False);           //  to show selected keeps

  if k180_message_msg_pref=False
      then begin
             alert_box.preferences_checkbox.Checked:=False;       //%%%%
             alert_box.preferences_checkbox.Show;


             i:=alert(7,'    rotate  group  180  degrees',
                      '|You are about to rotate the currently selected group of background templates through 180 degrees around the notch.'
                     +'||This can be undone by repeating the process, but only if the notch has not been subsequently moved.'
                     +'||( If the notch is at the startup position on the origin, after this process you will probably need to zoom out'
                     +' to see the rotated templates, and/or need to shift them back into the printed area.)',
                     '','','','','cancel  rotate','O K  -  continue',0);

             k180_message_msg_pref:=alert_box.preferences_checkbox.Checked;
             alert_box.preferences_checkbox.Hide;

             if i=5 then EXIT;

             redraw(False);   // otherwise blank patch during following calcs.
           end;

  try
    Screen.Cursor:=crHourglass;
    kform_keeps:=Pi;
    twist_all_group(False);
    rebuild_group(False,False);
  finally
    Screen.Cursor:=crDefault;
  end;//try

  sync_shapes(True,Pi);     // True = 90 degs multiple
end;
//______________________________________________________________________________

procedure Tpad_form.rotate_group_90degs_acw_menu_entryClick(Sender: TObject);

begin
  mouse_rotate_sync_wanted:=False;  // not here for mouse action
  
  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  Screen.Cursor:=crHourglass;
  kform_keeps:=0-Pi/2;
  twist_all_group(False);
  rebuild_group(False,False);

  Screen.Cursor:=crDefault;

  sync_shapes(True,Pi/2);    // True = 90 degs
end;
//______________________________________________________________________________

procedure Tpad_form.rotate_group_90degs_cw_menu_entryClick(Sender: TObject);

begin
  mouse_rotate_sync_wanted:=False;  // not here for mouse action
  
  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  Screen.Cursor:=crHourglass;
  kform_keeps:=Pi/2;
  twist_all_group(False);
  rebuild_group(False,False);

  Screen.Cursor:=crDefault;

  sync_shapes(True,0-Pi/2);      // True = 90 degs
end;
//______________________________________________________________________________

procedure Tpad_form.shift_group_onto_notch_menu_entryClick(Sender:TObject);    // deprecated 206c

const
  k_notch_str:string='      Shift  Group  onto  Notch'

  +'||N.B. There is an alternative LINK GROUP TO NOTCH function which is easier to use. Click the button below for more information.|---------------------------------------------------'

  +'||This function will align a selected group of background templates with the pegging notch, but needs to be used methodically. In case of mistakes, it makes sense to save your work first (FILES > SAVE ALL TEMPLATES... menu item).'

  +'||Assuming that the notch is already in the desired position on some existing track (GEOMETRY > NOTCH > NOTCH UNDER PEG menu item, or press the DIVIDE key), do this:'

  +'||1. If the control template will be needed again, park a copy of it now (DO > PARKING BAY > PARK CONTROL menu items).'

  +'||2. Select the members of the group (click on each template in turn and select GROUP SELECT (TOGGLE) on the pop-up menu).'

  +'||3. Copy the member of the group of templates which will actually engage the notch to the control template (click on it and select COPY TO CONTROL on the pop-up menu),'
  +' and position its fixing peg accordingly. This template will "lead the way" onto the notch for the others.'

  +'||4. Shift it onto the notch (GEOMETRY > NOTCH > SHIFT ONTO NOTCH menu item, or press the MULTIPLY key).'

  +'||N.B. If it is facing the wrong way, do NOT press MULTIPLY again yet.'

  +'||5. Only when you have completed all of the above, click the GROUP > SHIFT GROUP ONTO NOTCH menu item.'
  +'||The selected templates will now follow and re-align with the leading one.'

  +'||6. If Templot got it wrong and the templates are facing the wrong way, repeat operations 4 and 5.'

  +'||7. If desired, retrieve the original control template (DO > PARKING BAY > RETRIEVE menu items).'

  +'||Handy Hints :'
  +'|The shift can be undone by selecting the GROUP > UNDO SHIFT GROUP menu item, but this will work only if no subsequent peg or notch changes have been made.'
  +'||Bear in mind that the selected templates are not "glued" together; if you omit to select one it will get left behind. If this happens simply select it by itself (remember to de-select the others)'
  +' and then click SHIFT GROUP ONTO NOTCH again. This is the reason why this function has been implemented as a two-stage process.';

var
  i:integer;

begin
  cancel_adjusts(False);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This SHIFT GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  do_rollback:=False;
  redraw(False);           //  to show selected keeps

  if k_notch_msg_pref=False
      then begin

             alert_box.preferences_checkbox.Checked:=False;       //%%%%
             alert_box.preferences_checkbox.Show;

             repeat
               i:=alert(7,'    shift  group  onto  notch',
                      'N.B. There is an alternative LINK GROUP TO NOTCH function which is easier to use. Click the HELP bar for more information.|----------------------------------'
                     +'||You are about to shift all or a selected group of background templates onto the current position of the pegging notch.'
                     +' In case of mistakes it is sensible to save your work before proceeding.'
                     +'||Ensure that the required group templates have been selected, and that the engaging template has previously been copied to the control template'
                     +' and successfully shifted onto the notch to "lead the way" for the others.',
                     '','','','?  help','cancel  shift','O K  -  continue',4);

               if i=4
                  then begin
                         if alert_help(0,k_notch_str,'about  group  linking')=1 then alert_help(0,group_link_help_str,'');
                       end;
             until i<>4;

             k_notch_msg_pref:=alert_box.preferences_checkbox.Checked;    //%%%%
             alert_box.preferences_checkbox.Hide;

             if i=5 then EXIT;

             redraw(False);   // otherwise blank patch during calcs.
           end;
  try
    Screen.Cursor:=crHourglass;

    xshift_keeps:=saved_pegging_shiftx;
    yshift_keeps:=saved_pegging_shifty;
    shift_all_group(True);

    kform_keeps:=saved_pegging_rot;
    twist_all_group(True);

    rebuild_group(False,False);
  finally
    Screen.Cursor:=crDefault;
  end;//try
end;
//________________________________________________________________________________________

procedure Tpad_form.undo_shift_group_onto_notch_menu_entryClick(Sender:TObject);  // deprecated 206c

begin
  cancel_adjusts(False);

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This SHIFT GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  do_rollback:=False;
  redraw(False);           //  to show selected keeps

  if alert(7,'    undo  shift  group  from  notch',
             '|You are about to undo a previous shift of a group of templates.'
            +'||Ensure that the required group of templates are currently selected.'
            +'||Do not use this function if there was no previous shift, or you have subsequently made other peg or notch moves.'
            +'||Handy Hint : You can re-do the shift by selecting SHIFT GROUP ONTO NOTCH again. There should be no need to move the control template again.',
             '','','','','cancel','O K  -  undo  shift',0)=5 then EXIT;

  redraw(False);   // otherwise blank patch during calcs.

  try
    Screen.Cursor:=crHourglass;

    saved_pegging_shiftx:=0-saved_pegging_shiftx;
    saved_pegging_shifty:=0-saved_pegging_shifty;
    saved_pegging_rot:=0-saved_pegging_rot;

    kform_keeps:=saved_pegging_rot;      // must twist first for undo.
    twist_all_group(True);

    xshift_keeps:=saved_pegging_shiftx;
    yshift_keeps:=saved_pegging_shifty;
    shift_all_group(True);

    rebuild_group(False,False);

    saved_pegging_shiftx:=0-saved_pegging_shiftx;    // so can shift again.
    saved_pegging_shifty:=0-saved_pegging_shifty;
    saved_pegging_rot:=0-saved_pegging_rot;
  finally
    Screen.Cursor:=crDefault;
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.group_linked_warning_panelClick(Sender: TObject);

begin
  unlink_group;
end;
//______________________________________________________________________________

procedure Tpad_form.unlink_group_from_notch_menu_entryClick(Sender: TObject);

begin
  unlink_group;
end;
//_________________________________________________________________________________________

procedure Tpad_form.show_group_menu_entryClick(Sender: TObject);

begin
  show_group_menu_entry.Checked:=True;  // radio item.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.hide_group_menu_entryClick(Sender: TObject);

begin
  hide_group_menu_entry.Checked:=True;  // radio item.
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.toggle_group_menu_entryClick(Sender: TObject);

begin
  keep_form.toggle_group_bgnd_menu_entry.Click;
end;
//_______________________________________________________________________________________

procedure Tpad_form.invert_selections_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if template_info.keep_dims.box_dims1.bgnd_code_077<>-1
         then group_selected:= NOT group_selected
         else group_selected:=False;                       // library template???
    end;//with
  end;//for

  cancel_adjusts(False);

  unlink_group;
  do_rollback:=False;
  redraw(True);              //  to show selected keeps
end;
//_________________________________________________________________________________________

procedure Tpad_form.clear_all_selections_menu_entryClick(Sender: TObject);

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  keep_form.deselect_all_button.Click;
  do_rollback:=False;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.select_all_keeps_menu_entryClick(Sender: TObject);

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  clear_all_selections_menu_entry.Click;
  invert_selections_menu_entry.Click;
end;
//___________________________________________________________________________________________

procedure Tpad_form.slew_nudge_menu_entryClick(Sender: TObject);

begin
  move_slewing_zone_menu_entry.Enabled:=slewing;
  change_slewing_zone_menu_entry.Enabled:=slewing;
end;
//___________________________________________________________________________________________

procedure Tpad_form.slew_mode1_menu_entryClick(Sender: TObject);

begin
  enable_slewing(1,True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.slew_mode2_menu_entryClick(Sender: TObject);

begin
  enable_slewing(2,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.disable_slewing_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  disable_slewing_menu_entry.Checked:=True;     // radio item.
  slew_nudge_menu_entry.Checked:=False;

  adjust_slew_start_menu_entry.Enabled:=False;
  adjust_slew_length_menu_entry.Enabled:=False;
  adjust_slew_amount_menu_entry.Enabled:=False;
  adjust_slew2_factor_menu_entry.Enabled:=False;

  with info_form do begin
    slew_warn_panel.Hide;           // cover min rad box.
    min_rad_box.Show;               // restore rad change button...
    limit_rad_box.Show;
  end;//with

  slewing_panel.Hide;

  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy); // current peg data for peg_curve calcs.

  slewing:=False;
  peg_curve;                                                      // slew curve onto peg.

  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.bring_to_front_menu_entryClick(Sender: TObject);

begin
  Show;
  BringToFront;
end;
//_______________________________________________________________________________________

procedure Tpad_form.send_to_back_menu_entryClick(Sender: TObject);

begin
  SendToBack;
end;
//_______________________________________________________________________________________

procedure Tpad_form.mouse_draw_menu_entryClick(Sender: TObject);

begin
  pad_caption('draw  lines  with  mouse');
  if check_grey_paper=False then Cursor:=cross_hairs_cursor;  //crCross; 13-1-01.
  mouse_draw_lines:=True;
end;
//___________________________________________________________________________________

procedure Tpad_form.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

begin
  pad_mouse_up(Button, Shift, X, Y);
end;
//__________________________________________________________________________________________

procedure Tpad_form.differ_check_rails_menu_entryClick(Sender: TObject);

  // 0.94.a

begin
  if plain_track=True
     then begin
            alert(6,'    adjust  check  rails',
                    '  •  adjust check rails.'
                   +'||The control template is currently plain track.'
                   +'||Plain track doesn''t have any check rails.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  current_diff_code:=0;  // init

  cancel_adjusts(False);
  pad_form.hide_info_menu_entry.Click;   // hide the info panel, so that KB shortcut keys are available for the buttons.
  grid_form.Close;                       // ditto.
  shove_timber_form.Close;               // ditto.

  if turnoutx=0 then extend_template_from_zero; // 0.93.a

  if Application.Terminated=False then Application.ProcessMessages;

  check_diffs_form.Show;

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.shove_timbers_menu_entryClick(Sender: TObject);

begin
  if check_shove=False then EXIT;    // no timbers to shove.

  cancel_adjusts(False);
  pad_form.hide_info_menu_entry.Click;   // hide the info panel, so that KB shortcut keys are available for the buttons.
  grid_form.Close;                       // ditto.
  check_diffs_form.Close;                // ditto.

  if turnoutx=0 then extend_template_from_zero; // 0.93.a

  if Application.Terminated=False then Application.ProcessMessages;

  shove_timber_form.Show;
end;
//___________________________________________________________________________________________

procedure Tpad_form.single_sheets_menu_entryClick(Sender: TObject);

begin
  if banner_paper=True
     then begin
            per_printer_margins:=True;    // cancels user margins in page_info.
            printer_setup(False,False);   // so he can change the settings. (setting Landscape comes here also).
          end;

  single_sheets_menu_entry.Checked:=True;           // radio item.
  banner_paper:=False;

  page_info(True,True,False,0); // for the page outlines.
  do_rollback:=False;
  redraw(True);                 // to replace vertical page margins.
end;
//_________________________________________________________________________________________

procedure Tpad_form.wide_format_menu_entryClick(Sender: TObject);      // 223d

begin
  if alert(3,'    wide-format  roll-paper  printing',
           'To print long track plans on a CAD-style wide-format roll-paper printer/plotter, you should normally create a suitable large custom paper size, and select it for use in the printer setup.'
          +'||Do not use the banner printing option, which is intended for multiple pages on perforated Z-fold listing paper.'
          +'||For large-format printing an accurate printer calibration is especially important to maintain accuracy over long print runs. Remember to do a separate calibration for each type of roll paper which you are using.'
          +' For more information click the `0OUTPUT > PRINTER CALIBRATION > CALIBRATE PRINTER...`1 menu item.',
           '','','','','cancel  wide-format  printing','O K   -   printer  setup  for  wide-format  ...',0)=5 then EXIT;

  printer_setup(False,False);     // he must do the printer settings

  if banner_paper=True
     then begin
            per_printer_margins:=True;    // cancels user margins in page_info.
            printer_setup(False,False);   // so he can change the settings.
          end;

  wide_format_menu_entry.Checked:=True;           // radio item.
  banner_paper:=False;

  page_info(True,True,False,0); // for the page outlines.
  do_rollback:=False;
  redraw(True);                 // to replace vertical page margins.
end;
//______________________________________________________________________________

procedure Tpad_form.banner_paper_menu_entryClick(Sender: TObject);

const
  banner_help_str:string='      Banner  Z-fold  Paper  Printing'
  +'||If your printer is capable of printing continuous banners on Z-fold or roll paper this can usefully eliminate most (or all) of the page-joins for a large printed template.'

  +'||You must set up the printer for banner paper printing. Templot cannot make these settings for you.'
  +'||( Refer to your printer documentation. It will probably be necessary to click a button or tab marked OPTIONS or SETUP or PROPERTIES or FEATURES in the printer setup window to find the banner paper settings.'
  +' It may also be necessary to move a switch or lever on the printer itself when loading the banner paper.)'

  +'||Note that for Z-fold paper it is important that the paper size is set correctly. This paper is more commonly available in US Letter size (11in x 8.5in) than A4.'

  +'||Because of the effects of the printer calibration, and manufacturing tolerances on the paper size, it is unlikely that the printed page alignment marks will exactly coincide with the folds in Z-fold paper.'
  +' This does not affect the accuracy of the printed templates.'

  +'||If you are using Z-fold computer listing paper as banner paper, you can prevent printing through the sprocket holes by adjusting the trim margins.'
  +' Click the OUTPUT > TRIM MARGINS > ? TRIM MARGINS HELP menu item for more information.'

  +'||For continuous banner printing an accurate printer calibration is especially important to maintain accuracy over long print runs. Remember to do a separate calibration for the banner paper which you are using.'
  +' For more information click the OUTPUT > PRINTER CALIBRATION > CALIBRATE PRINTER... menu item.'

  +'||When printing on single sheets of paper Templot ignores any empty (blank) pages and prints only the pages of your drawing which actually contain track.'
  +'||If the BANNER FILL option box on the print pages window is ticked, any such empty pages will be included in the print run when printing on banner or roll paper, so that no lengthwise page joins are needed.'
  +'||Bear in mind that for some track plans this could mean printing a great many blank pages (e.g. for a circular layout you would be printing blank pages to fill the whole of the centre space).'
  +'||In such cases you will probably want to untick the box and separate out the individual pages from the banner print run.'
  +'||This option box has no effect when printing on single sheets.'

  +'||N.B. Do not change to BANNER printing in Templot without making the corresponding banner settings for the printer. If you leave the printer set for single sheets you will lose the top and bottom'
  +' trim margins and be unable to join the pages accurately.'

  +'||For Templot to print templates on banner paper correctly it is necessary to select Upright / Portrait printing on all standard printers.'

  +'||For more information click the ? HELP button on the PRINT PAGES window when it appears.';

var
  i:integer;

begin
  repeat i:=alert(7,'    continuous  banner  Z-fold  paper  printing',
                    'rp.gif This Z-fold option is not for CAD-style printer/plotters on wide-format roll-paper. Use the `0wide-format`1 menu option and set a suitable large custom paper size.'
                   +'|||You must make the appropriate settings on your printer for Z-fold banner printing to work correctly.'
                   +'||Templot cannot make these settings for you.',
                    '','','','read  this  first','cancel  banner  printing','O K   -   printer  setup  for  banner  paper ...',4);
    case i of
        4: alert_help(0,banner_help_str,'');
        5: EXIT;
    end;//case

  until i<>4;

  printer_setup(False,False);     // he must do the printer settings.

  if paper_way=2
     then begin
            i:=alert(1,'    sideways  ( landscape )  printing',
                       '||Printing on banner paper.'
                      +'||The printer is currently set for sideways (landscape) printing.'
                      +'||For all standard printers you should change to upright (portrait) printing so that Templot can print correctly on banner paper.',
                       '','','','continue  with  sideways  ( landscape )  printing','cancel  banner  printing','change  to  upright  ( portrait )  printing',0);
            case i of
                5: EXIT;
                6: portrait_menu_entry.Click;
            end;//case
          end;

  if banner_paper=False then per_printer_margins:=True;    // cancels user margins in page_info.

  banner_paper_menu_entry.Checked:=True;      // radio item.
  banner_paper:=True;

  page_info(True,True,False,0); // for the page outlines.
  do_rollback:=False;
  redraw(True);                 // to remove vertical page margins.
end;
//___________________________________________________________________________________________

procedure Tpad_form.snap_approach_to_nearest_menu_entryClick(Sender: TObject);

var
  t_only,dummy1:extended;

begin
  if (xorg<minfp) or (cl_only=True) or (no_timbering=True) then EXIT;  // no approach track or no sleeper centres.

  startx:=0;                           // cancel any blanking, so he can see the change.

  t_only:=turnoutx-xorg;               // length of turnout portion.

  xorg:=xorg-approach_last_xtb;        // snap the lengths to the first sleeper centre...

  if xorg<0 then xorg:=0;              // keep within limits...
  if xorg>(turnoutx_max-t_only) then xorg:=turnoutx_max-t_only;

  turnoutx:=xorg+t_only;    // correct overall length.

             // belt and braces: keep turnoutx within limits...

  if turnoutx<0 then turnoutx:=0;
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;
  if plain_track=True then turnoutx:=xorg;               //  keep lengths equal for plain track.

  turnout_i:=1;      // length locked at turnoutx.

  udpegx:=udpegx-approach_last_xtb;       // user defined position.

  if peg_code<>0
     then begin
            kform_now:=kform;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy1);    // get current peg data for peg_curve calcs.

            pegx:=pegx-approach_last_xtb;                            //  pegx changes with xorg unless peg is reset on rail-end.
            if spiral=True then os:=os-approach_last_xtb;            //  os transition start changes with xorg ditto.
            if slewing=True then slew_s:=slew_s-approach_last_xtb;   //  ditto slewing.
            peg_curve;                                               // keep turnout on the peg.
          end;

  redraw_pad(True,(approach_last_xtb<>0));  // if approach_last_xtb=0 then no change, don't need rollback.
end;
//________________________________________________________________________________________

procedure Tpad_form.shorten_approach_one_menu_entryClick(Sender: TObject);

begin
  if (xorg<=0) or (cl_only=True) or (no_timbering=True) then EXIT;      // nothing to shorten or no sleeper centres.

  if sleeper_count[pt_i]<1 then EXIT;                    // no sleepers in length.

  fix_approach_length(True,0-scale);      // reduce lengths by 1ft (enough to lose a sleeper after snapping). 27-2-00.
  redraw_pad(False,True);                 // force immediate draw in case he holds the shortcut key down.
end;
//_____________________________________________________________________________________________

procedure Tpad_form.extend_approach_one_menu_entryClick(Sender: TObject);

var
  avspace:extended;

begin
  if (cl_only=True) or (no_timbering=True) then EXIT;    // no sleeper centres.
  if sleeper_count[pt_i]<1 then EXIT;                    // no sleepers in length.
  avspace:=railen[pt_i]*inscale/sleeper_count[pt_i];     // average sleeper spacing.

  if xorg=0 then fix_approach_length(True,avspace)         // otherwise adds 2 sleepers.
            else fix_approach_length(True,avspace+scale);  // increase lengths to next sleeper (after snapping).(1ft arbitrary).
  redraw_pad(False,True);                                  // force immediate draw in case he holds the shortcut key down.
end;
//__________________________________________________________________________________________

procedure Tpad_form.snap_to_EGTP_menu_entryClick(Sender: TObject);

begin
  fix_approach_length(False,(0-egpx));
  redraw_pad(True,True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.snap_to_IGTP_menu_entryClick(Sender: TObject);

begin
  fix_approach_length(False,(0-igpx));
  redraw_pad(True,True);
end;
//____________________________________________________________________________________________

procedure Tpad_form.snap_exit_to_nearest_menu_entryClick(Sender: TObject);

var
  dummy1:extended;

begin
  if (cl_only=True) or (no_timbering=True)  then EXIT;      // no sleeper centres.

  turnout_i:=1;      // length locked.

  if turnoutx=exit_last_xtb then EXIT;        // already there.

  turnoutx:=exit_last_xtb;             // snap the length to the last sleeper centre.
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;

  if peg_code=11
     then begin               // peg is on length...
            kform_now:=kform;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy1);    // get current peg data for peg_curve calcs.

            pegx:=turnoutx;
            peg_curve;        // keep peg constant.
          end;

  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.shorten_exit_one_menu_entryClick(Sender: TObject);

begin
  if (cl_only=True) or (no_timbering=True)  then EXIT;   // no sleeper centres.
  if sleeper_count[pt_i]<1 then EXIT;                    // no sleepers in length.

  if (exittb_i=0) or (turnoutx<(tb_xing_end+scale)) then EXIT;  // rails only or no exit track or exit timbered (allow 1ft scale overlap).

  fix_exit_length(0-scale);      // reduce length by 1ft scale (sufficient to snap to the next sleeper).
end;
//_________________________________________________________________________________________

procedure Tpad_form.extend_exit_one_menu_entryClick(Sender: TObject);

var
  avspace:extended;

begin
  if (cl_only=True) or (no_timbering=True)  then EXIT;   // no sleeper centres.

  if (exittb_i=0) or (turnoutx<=tb_xing_end)    // no exit there...
     then begin
            snap_exit_back_menu_entry.Click;    // restore default length.
            gocalc(1,0);                        // need a list to get the sleepers.
            shorten_exit_one_menu_entry.Click;  // then reduce back.
            EXIT;
          end;

  if sleeper_count[pt_i]<1 then EXIT;                    // no sleepers in rail length.
  avspace:=railen[pt_i]*inscale/sleeper_count[pt_i];     // average sleeper spacing.

  fix_exit_length(avspace);        // increase length to next sleeper.
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.mirror_keeps_Y_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  cancel_adjusts(False);
  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This MIRROR GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  do_rollback:=False;
  redraw(False);           //  to show selected keeps

  if mirrory_msg_pref=False
      then begin

             alert_box.preferences_checkbox.Checked:=False;
             alert_box.preferences_checkbox.Show;

             i:=alert(7,'    mirror  group  on  Y  at  notch',
                      '|           Mirror on Y  =  Flip top-to-bottom'
                     +'||You are about to mirror the currently selected group of background templates on a horizontal line through the current notch position.'
                     +' (Flip them top-to-bottom.)'
                     +'||This can be undone by simply repeating the process, provided the notch has not been moved subsequently.'
                     +'||Before using this function you will normally want to set the notch at your intended mirror line by clicking the GEOMETRY > NOTCH > SET NOTCH POSITION AND ANGLE... menu item,'
                     +' and then setting the Y dimension accordingly. The notch X dimension and notch angle have no effect on this function, and can be left unchanged or set to zero.',
                     '','','','','cancel  mirror','O K  -  mirror  group  on  Y',0);

             mirrory_msg_pref:=alert_box.preferences_checkbox.Checked;
             alert_box.preferences_checkbox.Hide;

             if i=5 then EXIT;

             redraw(False);   // otherwise blank patch during calcs.
           end;
  try
    Screen.Cursor:=crHourglass;

    mirror_keeps_x;      // first mirror on x

    kform_keeps:=Pi;
    twist_all_group(False);     // then rotate 180 degs around notch

    rebuild_group(False,False);
  finally
    Screen.Cursor:=crDefault;
  end;//try
end;
//________________________________________________________________________________________

procedure Tpad_form.mirror_keeps_X_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  cancel_adjusts(False);
  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if (any_selected>0) and (group_notch_linked=True)
     then begin
            if alert(2,'    group  linked  to  notch',
                       'The selected group is currently linked to the pegging notch.'
                      +'||This MIRROR GROUP function will unlink the group.',
                       '','','','','cancel','O K  -  unlink  group  and  continue',0)=5 then EXIT;
            unlink_group;
          end;

  do_rollback:=False;
  redraw(False);           //  to show selected templates

  if mirrorx_msg_pref=False
      then begin

             alert_box.preferences_checkbox.Checked:=False;
             alert_box.preferences_checkbox.Show;

             i:=alert(7,'    mirror  group  on  X  at  notch',
                       '|              Mirror on X  =  Flip sideways'
                      +'||You are about to mirror the currently selected group of background templates on a vertical line through the current notch position.'
                      +' (Flip them sideways.)'
                      +'||This can be undone by simply repeating the process, provided the notch has not been moved subsequently.'
                      +'||Before using this function you will normally want to set the notch at your intended mirror line by clicking the GEOMETRY > NOTCH > SET NOTCH POSITION AND ANGLE... menu item,'
                      +' and then setting the X dimension accordingly. The notch Y dimension and notch angle have no effect on this function, and can be left unchanged or set to zero.',
                       '','','','','cancel  mirror','O K  -  mirror  group  on  X',0);

             mirrorx_msg_pref:=alert_box.preferences_checkbox.Checked;
             alert_box.preferences_checkbox.Hide;

             if i=5 then EXIT;

             redraw(False);   // otherwise blank patch during calcs.
           end;
  try
    Screen.Cursor:=crHourglass;
    mirror_keeps_x;
    rebuild_group(False,False);
  finally
    Screen.Cursor:=crDefault;
  end;//try
end;
//___________________________________________________________________________________________

procedure Tpad_form.duplicate_group_menu_entryClick(Sender: TObject);

begin
  create_copied_group(False,False);
end;
//______________________________________________________________________________

procedure Tpad_form.copy_group_as_unused_menu_entryClick(Sender: TObject);     // 227a

begin
  create_copied_group(False,True);
end;
//______________________________________________________________________________

procedure Tpad_form.copy_group_as_library_menu_entryClick(Sender: TObject);    // 227a

begin
  create_copied_group(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.cross_hairs_pointer_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  while check_grey_paper=True do begin
    i:=alert(3,'    cross-hairs  symbol  on  grey  paper',
               'Using the cross-hairs symbol as the mouse pointer.'
              +'||Your trackpad colour is mid-grey or near to mid-grey.'
              +'||This may mean that the cross-hairs symbol is invisible or appears very faint.',
               '','','','continue  with  grey  paper    ','cancel  cross-hairs  symbol      ','O K   -   change  trackpad  colour      ',0);
            case i of
                4: BREAK;
                5: EXIT;
                6: paper_colour_menu_entry.Click;
            end;//case
  end;//while

  Cursor:=cross_hairs_cursor;
end;
//___________________________________________________________________________________________

procedure Tpad_form.timber_numbering_over_platforms_menu_entryClick(Sender: TObject);     // 226d

begin
  timber_numbering_over_platforms_menu_entry.Checked:= NOT timber_numbering_over_platforms_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.timber_numbering_on_plain_track_menu_entryClick(Sender:TObject);  // 208a

begin
  timber_numbering_on_plain_track_menu_entry.Checked:= NOT timber_numbering_on_plain_track_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.scale_timber_numbering_menu_entryClick(Sender: TObject);

begin
  scale_timber_numbering_menu_entry.Checked:= NOT scale_timber_numbering_menu_entry.Checked;
end;
//________________________________________________________________________________________

procedure Tpad_form.print_timber_numbering_menu_entryClick(Sender: TObject);

begin
  print_timber_numbering_menu_entry.Checked:=True;    // radio item.
end;
//_________________________________________________________________________________________

procedure Tpad_form.numbering_fullsize_only_menu_entryClick(Sender: TObject);

begin
  numbering_fullsize_only_menu_entry.Checked:=True;   // radio item.
end;
//________________________________________________________________________________________

procedure Tpad_form.omit_timber_numbering_menu_entryClick(Sender: TObject);

begin
  omit_timber_numbering_menu_entry.Checked:=True;    // radio item.
end;
//_________________________________________________________________________________________

procedure Tpad_form.repeat_last_action_menu_entryClick(Sender: TObject);

begin

  case repeat_last_index of

{spot_mod:=1        }   0: adjust_spot_zoom_menu_entry.Click;
{zoom_mod:=1        }   1: adjust_zoom_menu_entry.Click;
{datum_mod:=1       }   2: move_datum_menu_entry.Click;
{peg_mod:=1         }   3: move_peg_menu_entry.Click;
{notch_mod:=1       }   4: move_notch_menu_entry.Click;
{out_factor_mod:=1  }   5: adjust_print_size_menu_entry.Click;
{shove_along_mod:=1 }   6: if shove_timber_form.Showing=true then shove_along_mouse_action;
{shove_throw_mod:=1}    7: if shove_timber_form.Showing=true then shove_throw_mouse_action;
{trans_length_mod:=1}   8: adjust_trans_length_menu_entry.Click;
{trans_start_mod:=1 }   9: adjust_trans_start_menu_entry.Click;
{slew_amount_mod:=1 }  10: adjust_slew_amount_menu_entry.Click;
{slew_length_mod:=1 }  11: adjust_slew_length_menu_entry.Click;
{slew_start_mod:=1  }  12: adjust_slew_start_menu_entry.Click;
{length_mod:=1      }  13: adjust_length_menu_entry.Click;

{approach_mod:=1    }  14: do_f3; //adjust_approach_menu_entry.Click;   205a

{shift_mod:=1       }  15: shift_menu_entry.Click;
{slide_mod:=1       }  16: slide_menu_entry.Click;
{ring_mod:=1        }  17: move_ring_menu_entry.Click;
{shift_keeps_mod:=1 }  18: shift_keeps_menu_entry.Click;
{twist_keeps_mod:=1 }  19: rotate_keeps_menu_entry.Click;
{zoffset_mod:=1     }  20: move_pad_origin_menu_entry.Click;
{twist_mod:=1       }  21: rotate_menu_entry.Click;
{orbit_mod:=1       }  22: orbit_rad_centre_menu_entry.Click;
{both_mod:=1        }  23: adjust_both_menu_entry.Click;
{sx_mod:=1          }  24: adjust_turnout_menu_entry.Click;
{curving_mod:=1     }  25: adjust_curving_menu_entry.Click;
{roam_mod:=1        }  26: adjust_roam_menu_entry.Click;
{slew_factor_mod:=1 }  27: adjust_slew2_factor_menu_entry.Click;
{bunch_mod:=1       }  28: adjust_paper_bunching_menu_entry.Click;
{porg_mod:=1        }  29: move_page_origin_menu_entry.Click;
{corner1_mod:=1     }  30: shift_corner1_menu_entry.Click;
{corner2_mod:=1     }  31: shift_corner2_menu_entry.Click;

{oneshape_shift_mod:=1    }  32: shift_shape_menu_entry.Click;
{allshapes_shift_mod:=1   }  33: shift_all_shapes_menu_entry.Click;

{snake_mod:=1             }  34: snake_menu_entry.Click;

{allshapes_scale_mod:=1   }  35: scale_all_shapes_menu_entry.Click;
{allshapes_rotate_mod:=1  }  36: rotate_all_shapes_menu_entry.Click;

{oneshape_scale_mod:=1    }  37: scale_shape_menu_entry.Click;

{shove_length_mod:=1      }  38: if shove_timber_form.Showing=true then shove_length_mouse_action;
{shove_width_mod:=1       }  39: if shove_timber_form.Showing=true then shove_width_mouse_action;
{shove_twist_mod:=1       }  40: if shove_timber_form.Showing=true then shove_twist_mouse_action;

{blanking_mod:=1          }  41: adjust_blanking_length_menu_entry.Click;

{roll_mod:=1              }  42: adjust_roll_sleepers_menu_entry.Click;

{ringdia_mod:=1           }  43: adjust_spacing_ring_size_menu_entry.Click;

{ruler1_mod:=1            }  44: move_ruler_1st_end_menu_entry.Click;
{ruler2_mod:=1            }  45: move_ruler_2nd_end_menu_entry.Click;

{swell_mod:=1             }  46: swell_menu_entry.Click;

{shove_crab_mod:=1        }  47: if shove_timber_form.Showing=true then shove_crab_mouse_action;

{move_labels_mod:=1       }  48: move_name_labels_menu_entry.Click;  // 0.82.d

{entry_straight_mod:=1    }  49: adjust_entry_straight_menu_entry.Click;  // 0.91.b

      // 0.93.a ...
      
{plat_ts_start_mod=1      }  50: platform_form.mouse_ts_start_button.Click;
{plat_ts_length_mod=1     }  51: platform_form.mouse_ts_length_button.Click;
{plat_ts_width1_mod=1     }  52: platform_form.mouse_ts_width1_button.Click;
{plat_ts_width2_mod=1     }  53: platform_form.mouse_ts_width2_button.Click;

{plat_ms_start_mod=1      }  54: platform_form.mouse_ms_start_button.Click;
{plat_ms_length_mod=1     }  55: platform_form.mouse_ms_length_button.Click;
{plat_ms_width1_mod=1     }  56: platform_form.mouse_ms_width1_button.Click;
{plat_ms_width2_mod=1     }  57: platform_form.mouse_ms_width2_button.Click;

{gaunt_offset_mod=1       }  58: adjust_gaunt_offset_menu_entry.Click;      // SHIFT+F12  // 0.93.a ex 081
{vee_mod=1                }  59: adjust_v_crossing_angle_menu_entry.Click;  // F9         // 0.93.a ex 081
{hdk_mod=1                }  60: adjust_k_crossing_angle_menu_entry.Click;  // F10        // 0.93.a ex 081

{rect_left_mod=1          }  61: adjust_rectangle_left_edge_menu_entry.Click; // output boundary rectangle 0.93.a ...
{rect_right_mod=1         }  62: adjust_rectangle_right_edge_menu_entry.Click;
{rect_top_mod=1           }  63: adjust_rectangle_top_edge_menu_entry.Click;
{rect_bottom_mod=1        }  64: adjust_rectangle_bottom_edge_menu_entry.Click;
{rect_move_mod=1          }  65: move_rectangle_menu_entry.Click;

{check_diffs_len_mod=1    }  66: diffs_length_mouse_action;  // 0.94.a  mouse check rails
{check_diffs_flare_mod=1  }  67: diffs_flare_mouse_action;   // 0.94.a
{check_diffs_gap_mod=1    }  68: diffs_gap_mouse_action;     // 0.94.a

{dv_mod=1                 }  69: roll_dummy_vehicle_menu_entry.Click;              // 0.98.a  dummy vehicle
{dv_clear_mod=1           }  70: adjust_dummy_vehicle_clearance_menu_entry.Click;  // 0.98.a  dummy vehicle

{plat_ms_skew1_mod=1      }  71: platform_form.mouse_ms_skew1_button.Click;    // 207a
{plat_ms_skew2_mod=1      }  72: platform_form.mouse_ms_skew2_button.Click;    // 207a
{plat_ts_skew1_mod=1      }  73: platform_form.mouse_ts_skew1_button.Click;    // 207a
{plat_ts_skew2_mod=1      }  74: platform_form.mouse_ts_skew2_button.Click;    // 207a

{turnout_road_mod:=1      }  75: adjust_turnout_road_exit_menu_entry.Click;    // 209a CTRL+F12

{adjacent_ts_mod=1        }  76: adjust_adjacent_centres_ts_menu_entry.Click;  // 213a
{adjacent_ms_mod=1        }  77: adjust_adjacent_centres_ms_menu_entry.Click;  // 213a


{edge_ts_start_mod=1      }  78: trackbed_form.mouse_ts_start_button.Click;    // 215a ...
{edge_ts_length_mod=1     }  79: trackbed_form.mouse_ts_length_button.Click;
{edge_ms_start_mod=1      }  80: trackbed_form.mouse_ms_start_button.Click;
{edge_ms_length_mod=1     }  81: trackbed_form.mouse_ms_length_button.Click;

{main_road_mod:=1         }  82: adjust_main_road_exit_menu_entry.Click;       // 217a

{gaunt_radius_mod=1       }  83: adjust_gaunt_radius_menu_entry.Click;         // 217b

{locator_mod:=1           }  84: move_locator_menu_entry.Click;                // 227a

{clip_size_mod=1          }  85: bgnd_form.clip_adjust_size_menu_entry.Click;  // 229a
{clip_angle_mod=1         }  86: begin                                         // 234b mods
                                   if adjust_clip_angle_menu_entry.Tag=4
                                      then bgnd_form.clip_adjust_angle_menu_entry.Click
                                      else if adjust_clip_angle_menu_entry.Tag=1
                                              then bgnd_form.slab_adjust_angle_menu_entry.Click;
                                 end;
{pt_blanking_mod=1        }  87: adjust_blanking_length_menu_entry.Click;      // 229a


                      else EXIT;       // -1 = nothing there (startup).
  end;//case
end;
//________________________________________________________________________________________

procedure Tpad_form.insert_turnout_menu_entryClick(Sender: TObject);

begin
  insert_turnout;
  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.swap_current_ends_menu_entryClick(Sender: TObject);

begin
  swap_end_for_end;
  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.zero_trans_zone_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(pegx,0);
end;
//___________________________________________________________________________________________

procedure Tpad_form.move_trans_start_to_peg_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(pegx,tst);
end;
//__________________________________________________________________________________________

procedure Tpad_form.move_trans_end_to_peg_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(pegx-tst,tst);
end;
//______________________________________________________________________________________

procedure Tpad_form.move_trans_start_to_template_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(0,tst);
end;
//________________________________________________________________________________________

procedure Tpad_form.move_trans_end_to_template_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(turnoutx-tst,tst);
end;
//_______________________________________________________________________________________

procedure Tpad_form.start_trans_from_peg_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=os+tst-pegx;
  set_trans_position_from_ctrl_0(pegx,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.end_trans_at_peg_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=pegx-os;
  set_trans_position_from_ctrl_0(os,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_trans_start_to_template_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=os+tst;
  set_trans_position_from_ctrl_0(0,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_trans_end_to_template_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=turnoutx-os;
  set_trans_position_from_ctrl_0(os,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_trans_zone_to_template_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(0,turnoutx);
end;
//__________________________________________________________________________________________

procedure Tpad_form.match_trans_zone_to_slew_menu_entryClick(Sender: TObject);

begin
  set_trans_position_from_ctrl_0(slew_s,slew_l);
end;
//_________________________________________________________________________________________

procedure Tpad_form.change_transition_zone_menu_entryClick(Sender: TObject);

       // enable only if template end will be beyond or equal to the start...
begin
  start_trans_from_peg_menu_entry.Enabled:=          ((os+tst)>=(pegx-minfp));
  end_trans_at_peg_menu_entry.Enabled:=              (pegx>=(os-minfp));
  match_trans_start_to_template_menu_entry.Enabled:= ((os+tst)>=(0-minfp));
  match_trans_end_to_template_menu_entry.Enabled:=   (turnoutx>=(os-minfp));

  match_trans_zone_to_slew_menu_entry.Enabled:=slewing;
end;
//_________________________________________________________________________________________

procedure Tpad_form.slew_help_menu_entryClick(Sender: TObject);

begin
  help(0,slew_help_str+'||For more information about the slew settings, click the GEOMETRY > SLEW (NUDGE) > NEW SLEW SETTINGS... menu item, and click the HELP flags for each setting.','');
end;
//________________________________________________________________________________________

procedure Tpad_form.move_slew_start_to_peg_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(pegx,slew_l);
end;
//__________________________________________________________________________________________

procedure Tpad_form.move_slew_end_to_peg_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(pegx-slew_l,slew_l);
end;
//______________________________________________________________________________________

procedure Tpad_form.move_slew_start_to_template_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(0,slew_l);
end;
//________________________________________________________________________________________

procedure Tpad_form.move_slew_end_to_template_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(turnoutx-slew_l,slew_l);
end;
//_______________________________________________________________________________________

procedure Tpad_form.move_slew_centre_to_template_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0((turnoutx-slew_l)/2,slew_l);
end;
//__________________________________________________________________________________________

procedure Tpad_form.start_slew_from_peg_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=slew_s+slew_l-pegx;
  set_slew_position_from_ctrl_0(pegx,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.end_slew_at_peg_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=pegx-slew_s;
  set_slew_position_from_ctrl_0(slew_s,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_slew_start_to_template_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=slew_s+slew_l;
  set_slew_position_from_ctrl_0(0,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_slew_end_to_template_menu_entryClick(Sender: TObject);

var
  new_len:extended;

begin
  new_len:=turnoutx-slew_s;
  set_slew_position_from_ctrl_0(slew_s,new_len);
end;
//_______________________________________________________________________________________

procedure Tpad_form.match_slew_zone_to_template_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(0,turnoutx);
end;
//__________________________________________________________________________________________

procedure Tpad_form.match_slew_zone_to_trans_menu_entryClick(Sender: TObject);

begin
  set_slew_position_from_ctrl_0(os,tst);
end;
//_________________________________________________________________________________________

procedure Tpad_form.change_slewing_zone_menu_entryClick(Sender: TObject);

       // enable only if zone end will be beyond or equal to the start...
begin
  start_slew_from_peg_menu_entry.Enabled:=          ((slew_s+slew_l)>=(pegx-minfp));
  end_slew_at_peg_menu_entry.Enabled:=              (pegx>=(slew_s-minfp));
  match_slew_start_to_template_menu_entry.Enabled:= ((slew_s+slew_l)>=(0-minfp));
  match_slew_end_to_template_menu_entry.Enabled:=   (turnoutx>=(slew_s-minfp));

  match_slew_zone_to_trans_menu_entry.Enabled:=spiral;
end;
//_________________________________________________________________________________________

procedure Tpad_form.swap_transition_rads_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

  clrad2:=nomrad1;         // new centre-line 1st radius.
  clrad1:=nomrad2;         // new centre-line 2nd radius.

  nomrad2:=clrad2;
  nomrad1:=clrad1;

  peg_curve;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.normalize_transition_menu_entryClick(Sender: TObject);

begin
  if normalize_transition=False
     then alert(2,'    unable  to  normalize',
                  'Sorry, this transition curve template cannot be normalized.'
                 +'||If no other error message appears you may continue to use this template as it stands.',
                  '','','','','cancel  normalize','',0)
     else redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.examine_peg_menu_entryClick(Sender: TObject);   // centralize on peg and zoom in.

begin
  cancel_adjusts(False);

  if (zoom_offsetx=examined_peg_x) and (zoom_offsety=examined_peg_y) and (screenx=examined_peg_screen)
     then begin
            explode_shrink(pre_examine_peg_screen,True,False);   // already examined so toggle back ...
            zoom_offsetx:=pre_examine_peg_x;
            zoom_offsety:=pre_examine_peg_y;
            redraw(True);
          end
     else begin
            pre_examine_peg_x:=zoom_offsetx;     // save existing for toggle...
            pre_examine_peg_y:=zoom_offsety;
            pre_examine_peg_screen:=screenx;

            pad_on_peg_menu_entry.Click;
            explode_shrink(g*2,True,False);      // zoom in to g*2 width (arbitrary) and redraw via loop.

            examined_peg_x:=zoom_offsetx;        // save new position for toggle check.
            examined_peg_y:=zoom_offsety;
            examined_peg_screen:=screenx;
          end;
end;
//________________________________________________________________________________________

procedure Tpad_form.crop_approach_menu_entryClick(Sender: TObject);

begin
  crop_approach;
  redraw_pad(True,True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.snap_approach_to_railjoint_menu_entryClick(Sender: TObject);

var
  new_xorg, roll_outmm, roll_inmm, new_roll_outmm:extended;

begin
  if (railen[pt_i]*inscale)<minfp then EXIT;

  peg_on_joint_end_menu_entry.Click;

  if plain_track=False    // turnout, no rolled rails...
     then begin
            new_xorg:=Round(xorg/(railen[pt_i]*inscale))*railen[pt_i]*inscale;
            fix_approach_length(False,new_xorg-xorg);   // set new xorg.
            gocalc(0,0);
            reset_peg_menu_entry.Click;                 // for a turnout put peg on Ctrl-0.
          end
     else begin          // plain track...

            roll_inmm:=tb_roll_percent*railen[pt_i]*inscale/100;  // all in mm, 100 is for percent.
            roll_outmm:=turnoutx-roll_inmm;                       // length of rolled-out section.

            new_roll_outmm:=Round(roll_outmm/(railen[pt_i]*inscale))*railen[pt_i]*inscale;

            if new_roll_outmm<minfp then new_roll_outmm:=railen[pt_i]*inscale;  // minimum 1 rolled length for plain track.

            fix_approach_length(False,new_roll_outmm+roll_inmm-xorg);   // set new xorg.

            redraw_pad(True,True);   // for plain track leave on Ctrl-1.
          end
end;
//________________________________________________________________________________________

procedure Tpad_form.snap_exit_to_railjoint_menu_entryClick(Sender: TObject);

var
  new_exit:extended;

begin
  if (railen[pt_i]*inscale)<minfp then EXIT;   // !!! zero rail length.

  if (plain_track=True) or (turnoutx<(mvjpx+minfp)) then EXIT;    // no exit track.

  if peg_code=11 then reset_peg_menu_entry.Click;   // peg was on length.

  new_exit:=Round((turnoutx-mvjpx)/(railen[pt_i]*inscale))*railen[pt_i]*inscale;

  turnoutx:=mvjpx+new_exit;
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;
  if xorg>turnoutx then xorg:=turnoutx;

  turnout_i:=1;            // length locked at turnoutx.
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.snap_exit_back_menu_entryClick(Sender: TObject);

var
  save_xorg:extended;

begin
  if plain_track=True then EXIT;      // only for turnouts.

  save_xorg:=xorg;
  turnout_i:=0;          // length free.  reset default.
  gocalc(0,0);
  xorg:=save_xorg;
  turnout_i:=1;          // length locked again at new turnoutx.
  redraw_pad(True,True);
end;
//______________________________________________________________________________________

procedure Tpad_form.snap_to_peg_menu_entryClick(Sender: TObject);

begin
  if pegx<scale      // arbitrary 1ft scale minimum snapped length
     then begin
            alert(6,'    snap  length  to  peg',
                    'Unable to snap the template length to the fixing peg with the peg in its current position.',
                    '','','','','','O K',0);
            EXIT;
          end;

  turnoutx:=pegx;
  turnout_i:=1;      // length locked at turnoutx.

  if (xorg>turnoutx) or (plain_track=True) then xorg:=turnoutx;

  if plain_track=True then peg_on_joint_end_menu_entry.Click
                      else peg_on_overall_length_menu_entry.Click;
end;
//_____________________________________________________________________________________

procedure Tpad_form.blank_to_peg_menu_entryClick(Sender: TObject);

begin
  if plain_track=True then EXIT;   // ??? menu should be disabled.

  if pegx>=(turnoutx-incx*2)       // peg beyond end (less 2 steps) , no can do...
     then begin
            alert(6,'    blank  template  to  peg',
                    'Unable to blank the template up to the fixing peg with the peg in its current position.',
                    '','','','','','O K',0);
            EXIT;
          end;

  turnout_i:=1;      // length locked at turnoutx.
  startx:=pegx;
  redraw_pad(True,True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.blank_to_toe_menu_entryClick(Sender: TObject);

begin
  startx:=setx-9*inscale;    // allow 9" for any joggle (arbitrary).
  redraw_pad(True,True);
end;
//______________________________________________________________________________________

procedure Tpad_form.blank_to_v_crossing_menu_entryClick(Sender: TObject);

var
  xblank:extended;

begin
  if ckx_ms<cuckx then xblank:=ckx_ms     // main-side check rail start.
                  else xblank:=cuckx;     // turnout-side check rail start.

  xblank:=xblank-scale/2;                 // allow 6" in front (arbitrary).

  if xblank>minfp
     then begin
            startx:=xblank;
            redraw_pad(True,True);
          end;
end;
//_______________________________________________________________________________________

procedure Tpad_form.cancel_blanking_menu_entryClick(Sender: TObject);

begin
  startx:=0;
  pt_blank:=0;              // 229a  plain track
  redraw_pad(True,True);
end;
//______________________________________________________________________________________

procedure Tpad_form.dummy_label_panelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var
  mousedown_p, label_p:TPoint;
  menu_caption_str:string;
  fb_str:string;   // 0.95.a

begin
  if Button=mbRight         // right-click, show the popup again.
     then begin
            new_label_position;                    // in case he is in mid drag.

            with dummy_label_panel do begin
              Hide;                                  // only one click is valid. list indices might change on a wipe or delete.
              if Application.Terminated=False then Application.ProcessMessages;           // call repaint before highlighting.
              mouse_on_bgkeep(Left+25,Top+5,False);  // highlight the label again (in keep_select).
            end;//with

            if clicks_accepted=True                  // should still be over it.
               then begin
                      clicks_accepted:=False;                   // only one click.

                      clicked_keep_index:=hover_keep_index;     // save the list indices.

                      list_position:=clicked_keep_index;  // make it current in the box.

                      if (clicked_keep_index>-1) and (clicked_keep_index<keeps_list.Count) and (keeps_list.Count>0)
                         then begin

                                 with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin
                                   if (template_info.keep_dims.box_dims1.mod_text_x=0) and (template_info.keep_dims.box_dims1.mod_text_y=0)
                                      then pad_form.restore_label_popup_entry.Enabled:=False
                                      else pad_form.restore_label_popup_entry.Enabled:=True;

                                   pad_form.select_bg_popup_entry.Checked:=group_selected;
                                   menu_caption_str:=UpperCase(Trim(template_info.bgnd_keep.full_label_string));
                                 end;//with

                                 if Length(menu_caption_str)>20 then menu_caption_str:=Copy(menu_caption_str,1,18)+'...';  // 20 arbitrary.

                                 with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do begin

                                   pad_form.align_current_popup_entry.Enabled:=(ABS(proto_info.gauge_pi-g)<minfp);  // 205d disabled for mixed-gauge templates

                                   if rail_type=2   // 0.95.a FB rail
                                      then fb_str:='FB •  '
                                      else fb_str:='BH •  ';

                                 end;//with


                                 pad_form.top_name_info_popup_entry.Caption:='I  '+fb_str+menu_caption_str;  // 0.95.a

                                 pad_form.selection_popup.PopUp(popup_X,popup_Y);

                                 cancel_adjusts(False);           // update the pad caption. 13-1-00.
                                 do_rollback:=False;
                                 redraw(False);        // remove highlighting (must be False (immediate redraw) in case we want to re-highlight for label moving).
                              end;
                    end;
            EXIT;
          end;// right-click

       // left button mousedown, drag label...

  if GetCursorPos(mousedown_p)=False then begin mousedown_p.X:=0; mousedown_p.Y:=0; end; // mouse position in screen co-ords.

  label_p.X:= dummy_label_panel.Left;
  label_p.Y:= dummy_label_panel.Top;

  label_mousedown_X:=mousedown_p.X-(pad_form.ClientToScreen(label_p)).X;  // mouse offset within the panel (can't use X,Y parameters because may have been called from the contained labels).
  label_mousedown_Y:=mousedown_p.Y-(pad_form.ClientToScreen(label_p)).Y;

  draw_background_templates(offdraw_bmp.Canvas,0,clicked_keep_index,True,hover_colour);   // highlight on the off-screen bitmap ready for repaints on moving the label.
  copy_draw_to_pad;
end;
//____________________________________________________________________________________________

procedure Tpad_form.dummy_label_panelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

var
  mps:TPoint;

begin
  if Shift=[ssLeft]   // mouse down ?
     then begin
            if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end;                       // make the panel track the mouse..

            with dummy_label_panel do begin
              Left:=(pad_form.ScreenToClient(mps)).X-label_mousedown_X;
              Top:=(pad_form.ScreenToClient(mps)).Y-label_mousedown_Y;
            end;//with

            save_done:=False;     // moved the label position.
          end;
end;
//__________________________________________________________________________________________

procedure Tpad_form.dummy_label_panelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

begin
  new_label_position;
end;
//___________________________________________________________________________________________

procedure Tpad_form.move_label_popup_entryClick(Sender: TObject);

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    if bg_copied=False then EXIT;  // ??? not on background.

    with template_info.bgnd_keep do begin

      moving_name_label.Font.Assign(bgnd_keeps_font_label.Font);
      moving_name_label.Font.Height:=text_font_height;
      moving_name_label.Font.Color:=clBlack;

      moving_name_label.Caption:=requested_label_string;

      with dummy_label_panel do begin    // show the dummy label.

        if Screen.PixelsPerInch>120
           then begin
                  Left:=text_begin_X-30;
                  Top:=text_begin_Y-2;
                  Width:=text_end_X-text_begin_X+40;
                  Height:=text_end_Y-text_begin_Y+4;
                  if Height<26 then Height:=26;

                  moving_name_label.Width:=Width-40;  // 205b bug-fix for Wine
                end
           else begin
                  Left:=text_begin_X-22;   // 2+20, extra is for moving_name_label Left offset.
                  Top:=text_begin_Y-2;
                  Width:=text_end_X-text_begin_X+24;
                  Height:=text_end_Y-text_begin_Y+4;
                  if Height<20 then Height:=20;

                  moving_name_label.Width:=Width-24;  // 205b bug-fix for Wine
                end;

        Show;
      end;//with panel.
    end;//with bgnd_keep.
  end;//with template

  draw_background_templates(offdraw_bmp.Canvas,0,clicked_keep_index,True,hover_colour);   // highlight on the off-screen bitmap ready for repaints on moving the label.
  copy_draw_to_pad;
end;
//______________________________________________________________________________________

procedure Tpad_form.restore_label_popup_entryClick(Sender: TObject);

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do begin
    mod_text_x:=0;
    mod_text_y:=0;
  end;//with

  save_done:=False;         // moved the label position.
  backup_wanted:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//__________________________________________________________________________________________

procedure Tpad_form.bat_name_label_popup_entryClick(Sender: TObject);   // 0.82.a

      // 0.82.a bat label sideways.

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do begin
    mod_text_y:=mod_text_y+scale*10;   // bat label sideways by 10ft arbitrary.
  end;//with

  save_done:=False;         // moved the label position.
  backup_wanted:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//__________________________________________________________________________________________

procedure Tpad_form.arrange_labels_popup_entryClick(Sender: TObject);

      // 0.82.d arrange other group labels next to this one.

const
  arrange_help_str:string='      Arrange  Name  Labels'
  +'||This function will neatly arrange the background template name labels into a row or a column.'
  +'||The name labels of the currently selected group of background templates will be arranged in a column below, or a row alongside, the current position of the label for this selected template.'
  +'||Before using this function zoom out to an appropriate size and make sure that the name label for this template is in an appropriate starting position. To move it, cancel this and select MOVE NAME LABEL on its menu.'
  +'||To arrange ALL the name labels, first click the GROUP > GROUP SELECT ALL TEMPLATES menu item to select all the background templates as a group.'
  +'||HANDY HINTS:'
  +'||By selecting different groups of background templates you can arrange the name labels in multiple columns or rows.'
  +'||If this selected template is itself a member of the group, its name label will be moved down or along into numerical order within the other name labels.'
  +'||While moving a name label, you can get the menu again by right-clicking on the label.'
  +'||If you use this function while zoomed too far in, the name labels are likely to overlap as you zoom out. Zoom out first.'
  +'||After arranging the group name labels, you can move them all in one go to a new position using the ACTION > MOUSE ACTIONS: GROUP > MOVE TEMPLATE NAME LABELS mouse action.'
  +'||See also the different styles of label available on the TRACKPAD > TRACKPAD BACKGROUND OPTIONS > BACKGROUND NAME LABELS > menu options.'
  +' If the BOXED OVER style is wanted, select this first before arranging the name labels.';

var
  i,n:integer;
  top_X,top_Y:integer;
  X_width,Y_height:integer;
  next_left,next_top:integer;
  h_space,v_space:integer;
  this_X,this_Y:integer;
  mod_X,mod_Y:integer;
  in_a_row:boolean;

begin
  try
    if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

    in_a_row:=False; // init, keep compiler happy.

    repeat
      i:=alert(7,'        arrange  name  labels',
                 'This function will neatly arrange the name labels for the background templates.'
              +'||Click MORE INFORMATION for some handy hints about using this function.| ',
               '','','more  information','arrange  group  template  name  labels  in  a  row   ','cancel','arrange  group  template  name  labels  in  a  column     ',3);

      case i of
           3: alert_help(0,arrange_help_str,'');
           4: in_a_row:=True;
           5: EXIT;
           6: in_a_row:=False;  // 4=row, 6=column.
      end;//case
    until i<>3;

    if any_bgnd<2
       then begin
              alert(6,'    no  other  background  templates',
                      'There are no other background templates to have labels arranged.',
                      '','','','','cancel','',0);
              EXIT;
            end;

    if any_selected=0
       then begin
              if alert_no_group=True    // alert him, and does he want all?
                 then EXIT;
            end;

    h_space:=8;  // pixels, init spacings, arbitrary.
    v_space:=2;

    if boxed_over_names_menu_entry.Checked=True
       then begin
              h_space:=h_space+8;  // pixels, init wider spacings
              v_space:=v_space+8;
            end;

    with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      with template_info do begin

        top_X:=bgnd_keep.text_begin_X;   // screen pixels, top label position and height.
        top_Y:=bgnd_keep.text_begin_Y;

        X_width:=bgnd_keep.text_end_X-bgnd_keep.text_begin_X;  // in screen pixels -- for first only (row).
        Y_height:=bgnd_keep.text_end_Y-bgnd_keep.text_begin_Y; // in screen pixels -- same for all (column).

      end;//with

      next_left:=top_X; // init..
      next_top:=top_Y;

      if group_selected=True   // will be moving this one
         then begin
                if in_a_row=True then next_left:=next_left-X_width-h_space   // so overwrite first in row
                                 else next_top:=next_top-Y_height-v_space;   // or overwrite first in column.
              end;
    end;//with

    for n:=0 to (keeps_list.Count-1) do begin

      with Ttemplate(keeps_list.Objects[n]) do begin

        if group_selected=False then CONTINUE;     // not in group.

        if bg_copied=False then CONTINUE;          // not on background.

        with template_info do begin

          this_X:=bgnd_keep.text_begin_X;   // screen pixels, this label position and height.
          this_Y:=bgnd_keep.text_begin_Y;

          if in_a_row=True
             then begin                                   // row
                    next_left:=next_left+X_width+h_space; // add spacing.
                    mod_X:=next_left-this_X;              // pixel moves needed -- all in row, make Y constant.
                    mod_Y:=top_Y-this_Y;
                  end
             else begin                                   // column
                    next_top:=next_top+Y_height+v_space;  // add spacing.
                    mod_X:=top_X-this_X;                  // pixel moves needed -- all in column, make X constant.
                    mod_Y:=next_top-this_Y;
                  end;

          with keep_dims.box_dims1 do begin

            mod_text_x:=mod_text_x+mod_X*ffx;  // modify the template mm data..
            mod_text_y:=mod_text_y+mod_Y*ffy;

          end;//with

          X_width:=bgnd_keep.text_end_X-bgnd_keep.text_begin_X;  // screen pixels -- update width for next.

        end;//with
      end;//with

    end;//next template

    save_done:=False;         // moved the label position.
    backup_wanted:=True;

  finally
    clicked_keep_index:=-1;    // so can popup again.
    redraw_pad(True,False);
  end;//try
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_label_shape_popup_entryClick(Sender: TObject);

var                               // convert the keep name label to a background shape.
  new_shape:Tbgnd_shape;
  n:integer;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    if bg_copied=False then EXIT;  // ??? not on background.

    new_shape:=init_bgnd_shape;  // 234b

    with template_info.bgnd_keep do begin

      with new_shape do begin

        shape_name:=template_info.keep_dims.box_dims1.reference_string;  // don't include the keep number (it might change).

            // 208d mod to include ID..

        if Trim(shape_name)='' then shape_name:=template_info.keep_dims.box_dims1.id_number_str
                               else shape_name:=shape_name+' - '+template_info.keep_dims.box_dims1.id_number_str;  // 208d

        hide_bits:=0;    // 214a  normal visibility
        option_bits:=0;  // byte;

        shape_code:=3;      // 0=line, 1=rectangle, 2=circle, 3=label.
        shape_style:=0;

        p1.x:=mouse_x(text_begin_X);                   // in mm..
        p1.y:=mouse_y(text_begin_X,text_begin_Y);

        p2.x:=0;
        p2.y:=0;

        rect_rot:=0;  // 234b

      end;//with new_shape
    end;//with bgnd_keep data.
  end;//with template.

  with bgnd_form.bgnd_shapes_listbox do begin
    n:=Items.AddObject(new_shape.shape_name,Tbgshape.Create);  // create and add a new line in the shapes list.

    Tbgshape(Items.Objects[n]).bgimage:=nil;                   // not bitmap image 3-2-01.
    Tbgshape(Items.Objects[n]).bgnd_shape:=new_shape;          // put data in list.
    ItemIndex:=n;                                              // make it current.
  end;//with

  shapes_saved:=False;            // need a fresh save.
  shapes_current_state;           // update the form.

  clicked_keep_index:=-1;   // so can popup again.
  redraw_pad(True,False);
end;
//_________________________________________________________________________________________

procedure Tpad_form.rename_popup_entryClick(Sender: TObject);   // mods 208a

var
  keep_name_str,idnum_str,s:string;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do begin

    keep_name_str:=reference_string;
    idnum_str:=id_number_str; // 208a ID number

  end;//with

  with math_form do begin
    Caption:='   name  or  rename  this  template ...';
    big_label.Caption:=insert_crlf_str('|             Name or rename template :  '+idnum_str
                                    +'|||'+keep_name_str
                                    +'|||Name or rename this template by entering a new name below.'
                                    +'|||If the existing name includes any prefix tags in square brackets,|take care not to delete or modify them unintentionally.'
                                    +'|Enter the new name after the square brackets.');
                                    
    math_editbox.Text:=keep_name_str;

    do_show_modal(math_form);     // 212a  ShowModal

    if ModalResult=mrOK
       then begin
              s:=Trim(math_editbox.Text);
              if s<>keep_name_str              // has he changed it?
                 then begin
                        keep_name_str:=s;

                        Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string:=keep_name_str;
                        save_done:=False;
                        backup_wanted:=True;
                      end;
            end;

    Caption:='    TEMPLOT';   // reset form caption.
  end;//with

  redraw_pad(True,False);    // update name label

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.wipe_bg_popup_entryClick(Sender: TObject);

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  wipe_it(clicked_keep_index);    // wipe the background template (ignore result).

  clicked_keep_index:=-1;    // so can popup again.
end;
//__________________________________________________________________________________________

procedure Tpad_form.rebuild_popup_entryClick(Sender: TObject);

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  Screen.Cursor:=crHourGlass;        // might take a while.

  rebuild_it(clicked_keep_index,0,0,False);    // rebuild the background template (ignore result).

  redraw(True);  // 227d

  Screen.Cursor:=crDefault;
  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_plain_track_popup_entryClick(Sender: TObject);   // 214c

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  plain - track  rail  lengths',
          'Modify and rebuild plain-track rail lengths'
         +'||This function will modify the plain-track rail lengths and sleeper spacing settings on the selected background template to match the current settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.plain_track_as_stored_menu_entry.Checked;
  keep_form.plain_track_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.plain_track_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_rail_section_popup_entryClick(Sender: TObject);

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  rail  section',
          'Modify and rebuild rail section'
         +'||This function will modify the rail section settings on the selected background template to match the current settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.rail_section_data_as_stored_menu_entry.Checked;
  keep_form.rail_section_data_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.rail_section_data_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_centre_lines_popup_entryClick(Sender: TObject);

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  track  centre - lines',
          'Modify and rebuild track centre-line settings.'
         +'||This function will modify the centre-line settings on the selected background template to match the current centre-line settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.centre_lines_as_stored_menu_entry.Checked;
  keep_form.centre_lines_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.centre_lines_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_centre_line_offset_options_popup_entryClick(Sender:TObject);   // 214a

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  centre - line  offset  option',
          'Modify and rebuild centre-line offset option.'
         +'||This function will modify the centre-line offset option on the selected background template to match the current setting on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.centre_line_offset_options_as_stored_menu_entry.Checked;
  keep_form.centre_line_offset_options_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.centre_line_offset_options_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_customized_xing_popup_entryClick(Sender:TObject);   // 214b

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  V-crossing',
          'Modify and rebuild using customized V-crossing settings'
         +'||This function will modify the V-crossing settings on the selected background template to match the current settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.customize_xing_as_stored_menu_entry.Checked;
  keep_form.customize_xing_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.customize_xing_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_timbering_popup_entryClick(Sender: TObject);

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  timbering',
          'Modify and rebuild timbering'
         +'||This function will modify the timbering styles and sizes on the selected background template to match the current settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.timbering_as_stored_menu_entry.Checked;
  keep_form.timbering_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.timbering_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_trackbed_edges_popup_entryClick(Sender:TObject);

var
  his_option:boolean;

begin
  if alert(7,'    modify  and  rebuild  trackbed  edges',
          'Modify and rebuild trackbed edges'
         +'||This function will modify the trackbed edge settings on the selected background template to match the current settings on the control template.'
         +modify_rebuild_str,
          '','','','','no  -  cancel','yes  -  modify  and  rebuild',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.trackbed_edges_as_stored_menu_entry.Checked;
  keep_form.trackbed_edges_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.trackbed_edges_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_radius_warning_popup_entryClick(Sender:TObject);

var
  his_option:boolean;

begin
  if alert(7,'php/208    modify  template  to  match  radius  warning  limit',
          'This function will modify the radius warning limit on the selected background template to match the current setting on the control template.',
          '','','','','cancel','modify  template  to  match  radius  warning  limit',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.radius_warning_limit_as_stored_menu_entry.Checked;
  keep_form.radius_warning_limit_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.radius_warning_limit_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_chair_outlines_popup_entryClick(Sender: TObject);      // 221a

var
  his_option:boolean;

begin
  if alert(7,'php/219    modify  template  to  match  chair  options',
          'This function will modify the chair options on the selected background template to match the current settings on the control template.',
          '','','','','cancel','modify  template  to  match  chair  options',0)=5
     then begin
            clicked_keep_index:=-1;    // so can popup again.
            redraw_pad(True,False);    // to cancel highlighting.
            EXIT;
          end;

  his_option:=keep_form.chair_options_as_stored_menu_entry.Checked;
  keep_form.chair_options_as_control_menu_entry.Checked:=True;                          // radio item.
  rebuild_popup_entry.Click;
  if his_option=True then keep_form.chair_options_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.create_unused_copy_popup_entryClick(Sender: TObject);

var
  n:integer;
  saved_control:Ttemplate_info;
  saved_name_str:string;
  saved_current_memo_str:string;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  try
    turnout_i:=1;      // length locked at turnoutx.  so that plain track or approach and exit tracks can be drawn.

    saved_control:=hold_the_control;       // 227a

    n:=clicked_keep_index;

    list_position:=n;                                 // make it current in the keeps box.
    copy_keep_to_current(False,False,False,False);    // copy to pad.
    store_unused(False,False);
  finally
    unhold_the_control(saved_control);   // 227a

    save_done:=False;
    backup_wanted:=True;
    clicked_keep_index:=-1;    // so can popup again.

    redraw_pad(True,False);
  end;//try
end;
//_________________________________________________________________________________________

procedure Tpad_form.delete_keep_popup_entryClick(Sender: TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  list_position:=clicked_keep_index;
  delete_keep(False,True);
  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________________________________________________________________________

procedure zoom_to_fit_template(index:integer);      // 216a mods

var
  max_long,max_wide:extended;
  min_long,min_wide:extended;
  wl_factor:extended;
  margin_factor:extended;

  reduced_screeny:extended;   // 216c

begin
  cancel_adjusts(False);

  if (any_bgnd=0) or (index<0) or (index>(keeps_list.Count-1)) then EXIT;

    // mods 216c for increased size of top toolbar ...

  if ABS(fy)<minfp then EXIT;   // ??  div 0

  reduced_screeny:=screeny-pad_form.top_toolbar_panel.Height/ABS(fy);  // 217a

  if ABS(reduced_screeny)<minfp then EXIT;    // ??  div 0

  wl_factor:=screenx/reduced_screeny;


  with Ttemplate(keeps_list.Objects[index]) do begin

    if bg_copied=False then EXIT;  // ??? not on background.

    with template_info.bgnd_keep do begin

      max_long:=xlist_max/100;   // to mm.
      max_wide:=ylist_max/100;

      min_long:=xlist_min/100;
      min_wide:=ylist_min/100;

    end;//with bgnd_keep data.
  end;//with template.

  margin_factor:=1.10;               // 216c arbitrary 10% extra for margins             was 15%

  screenx:=(max_long-min_long)*margin_factor;

  if screenx<((max_wide-min_wide)*margin_factor*wl_factor) then screenx:=(max_wide-min_wide)*margin_factor*wl_factor;

  if screenx<screenx_min then screenx:=screenx_min; // minimum for screen width (max zoom in).
  if screenx>screenx_max then screenx:=screenx_max; // maximum zoom out.

             // centralize on pad..

  zoom_offsetx:=min_long-(screenx-(max_long-min_long))/2;
  if wl_factor>minfp then zoom_offsety:=min_wide-(screenx/wl_factor-(max_wide-min_wide))/2;

  pad_form.lock_scaling_menu_entry.Click;       // lock pad zoom.
  gocalc(2,0);

end;
//______________________________________________________________________________

procedure Tpad_form.zoom_to_fit_template_popup_entryClick(Sender: TObject);      // 216a

begin
  zoom_to_fit_template(clicked_keep_index);
  clicked_keep_index:=-1;                        // so can popup again.
end;
//______________________________________________________________________________

procedure form_double_click(mouse_clicks:boolean);

begin

  if mouse_modify<>-1             // 0.91.c  ignore if mouse, cancel mouse action if toolbutton.
     then begin
            if mouse_clicks=True
               then EXIT
               else cancel_adjusts(False);
          end;

  with pad_form do begin
    if double_grid_menu_entry.Checked=True
       then begin
              if zoffset_mod=1
                 then repeat_last_action_menu_entry.Click
                 else move_pad_origin_menu_entry.Click;
              EXIT;
            end;

    if double_SHIFTCTRLF10_menu_entry.Checked=True
       then begin
              if porg_mod=1
                 then repeat_last_action_menu_entry.Click
                 else move_page_origin_menu_entry.Click;
              EXIT;
            end;

    if double_CTRLF1_menu_entry.Checked=True
       then begin
              if spot_mod=1
                 then repeat_last_action_menu_entry.Click
                 else adjust_spot_zoom_menu_entry.Click;
              EXIT;
            end;

    if double_ring_menu_entry.Checked=True
       then begin
              if ring_mod=1
                 then repeat_last_action_menu_entry.Click
                 else move_ring_menu_entry.Click;
              EXIT;
            end;

    if double_bunching_menu_entry.Checked=True
       then begin
              if bunch_mod=1
                 then repeat_last_action_menu_entry.Click
                 else adjust_paper_bunching_menu_entry.Click;
              EXIT;
            end;

    if double_F4_menu_entry.Checked=True
       then begin
              if length_mod=1
                 then repeat_last_action_menu_entry.Click
                 else adjust_length_menu_entry.Click;
              EXIT;
            end;

    if double_CTRLF9_menu_entry.Checked=True
       then begin
              if roam_mod=1
                 then repeat_last_action_menu_entry.Click
                 else adjust_roam_menu_entry.Click;
              EXIT;
            end;

    if double_F7_menu_entry.Checked=True
       then begin
              if shift_mod=1
                 then repeat_last_action_menu_entry.Click
                 else shift_menu_entry.Click;
              EXIT;
            end;

    if double_shift_shapes_menu_entry.Checked=True
       then begin
              if allshapes_shift_mod=1
                 then repeat_last_action_menu_entry.Click
                 else shift_all_shapes_menu_entry.Click;
              EXIT;
            end;
  end;//with
end;
//__________________________________________________________________________________________

procedure Tpad_form.FormDblClick(Sender: TObject);

begin
  form_double_click(True);  // moved 0.91.c
end;
//_______________________________________________________________________________________

procedure Tpad_form.edge_panning_on_menu_entryClick(Sender: TObject);

begin
  edge_panning_on_menu_entry.Checked:=True;          // radio item
  panning_form.edge_on_radio_button.Checked:=True;
end;
//________________________________________________________________________________________

procedure Tpad_form.edge_panning_off_menu_entryClick(Sender: TObject);

begin
  edge_panning_off_menu_entry.Checked:=True;         // radio item
  panning_form.edge_off_radio_button.Checked:=True;
end;
//_______________________________________________________________________________________

procedure Tpad_form.double_CTRLF1_menu_entryClick(Sender: TObject);

begin
  double_CTRLF1_menu_entry.Checked:=True;  // radio item.
end;
//_____________________________________________________________________________________

procedure Tpad_form.double_grid_menu_entryClick(Sender: TObject);

begin
  double_grid_menu_entry.Checked:=True;  // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.double_SHIFTCTRLF10_menu_entryClick(Sender: TObject);

begin
  double_SHIFTCTRLF10_menu_entry.Checked:=True;  // radio item.
end;
//________________________________________________________________________________________

procedure Tpad_form.double_ring_menu_entryClick(Sender: TObject);

begin
  double_ring_menu_entry.Checked:=True;  // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.double_bunching_menu_entryClick(Sender: TObject);

begin
  double_bunching_menu_entry.Checked:=True;     // radio item
end;
//_______________________________________________________________________________________

procedure Tpad_form.double_F4_menu_entryClick(Sender: TObject);

begin
  double_F4_menu_entry.Checked:=True;  // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.double_CTRLF9_menu_entryClick(Sender: TObject);

begin
  double_CTRLF9_menu_entry.Checked:=True;  // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.double_F7_menu_entryClick(Sender: TObject);

begin
  double_F7_menu_entry.Checked:=True;  // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.double_shift_shapes_menu_entryClick(Sender: TObject);

begin
  double_shift_shapes_menu_entry.Checked:=True;  // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.double_none_menu_entryClick(Sender: TObject);

begin
  double_none_menu_entry.Checked:=True;  // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.paper_bunching_on_menu_entryClick(Sender: TObject);

begin
  bunch_start:=Round((ex+xmax)/2)-ClientWidth div 60;       // gap = 1/30th of screen (1/60th each side of centre).
  bunch_gap:=ClientWidth div 30;

  paper_bunching:=True;
  paper_bunching_on_menu_entry.Checked:=True;           // radio item.
  adjust_paper_bunching_menu_entry.Enabled:=True;
  screengrid_on_menu_entry.Click;                       // so can see the bunch zone, also does the redraw.
end;
//________________________________________________________________________________________

procedure Tpad_form.paper_bunching_off_menu_entryClick(Sender: TObject);

begin
  cancel_paper_bunching;
  redraw_pad(True,False);    // no need to put this in rollback register.
end;
//______________________________________________________________________________________

procedure Tpad_form.set_print_origin_menu_entryClick(Sender: TObject);

const
  help_x_str:string='     Page  Origin  X  in  mm'
                  +'||Enter a new X-dimension in millimetres for the origin point of the printed pages.'
                  +'||X-dimensions are measured across the width of the screen from the left.'
                  +'||The page origin can also be moved with the mouse, select the ACTION > MOUSE ACTIONS:PAD > MOVE PAGE ORIGIN menu item (SHIFT+CTRL-F10).';

  help_y_str:string='     Page  Origin  Y  in  mm'
                  +'||Enter a new Y-dimension in millimetres for the origin point of the printed pages.'
                  +'||Y-dimensions are measured upwards from the bottom of the screen.'
                  +'||The page origin can also be moved with the mouse, select the ACTION > MOUSE ACTIONS:PAD > MOVE PAGE ORIGIN menu item (SHIFT+CTRL-F10).';

  help_xpages_str:string='     Page  Origin  X  in  page-lengths'
                  +'||Enter a new X-setting as the number of page-lengths from the drawing datum to the origin point of the printed pages.'
                  +'||Negative and fractional settings are permissible.'

                  +'||The page-length is determined by your current paper-size for the printer and the current trim margins which have been set in the PRINT > TRIM MARGINS menu items.'
                  +' The apparent page length dimensions shown on the trackpad reflect the current print size setting in the PRINT > ENLARGE/REDUCE SIZE menu options.'

                  +'||The page origin can also be moved with the mouse, select the ACTION > MOUSE ACTIONS:PAD > MOVE PAGE ORIGIN menu item (SHIFT+CTRL-F10).';

  help_ypages_str:string='     Page  Origin  Y  in  page-widths'
                  +'||Enter a new Y-setting as the number of page-widths from the drawing datum to the origin point of the printed pages.'
                  +'||Negative and fractional settings are permissible.'

                  +'||The page-width is determined by your current paper-size for the printer and the current trim margins which have been set in the PRINT > TRIM MARGINS menu items.'
                  +' The apparent page width dimensions shown on the trackpad reflect the current print size setting in the PRINT > ENLARGE/REDUCE SIZE menu options.'

                  +'||The page origin can also be moved with the mouse, select the ACTION > MOUSE ACTIONS:PAD > MOVE PAGE ORIGIN menu item (SHIFT+CTRL-F10).';


  help_porg_str:string='     Set  Page  Origin'
                  +'||You can change the X and Y dimensions for the origin point of the printed pages.'
                  +'||The origin point is the bottom-left corner of the page outlines on the screen, and the top-left corner of page a/1 when printed.'
                  +'||Changing the page origin is useful if the page margins are inconveniently positioned within the drawing.'
                  +'||The pre-set dimensions are zero, so that the page origin normally co-incides with the drawing datum.'
                  +'||Negative dimensions for the page origin are permissible.'
                  +'||Handy Hints:'
                  +'|The page origin setting is not saved between Templot sessions. If you will need the same setting again, make a note of the page origin dimensions'
                  +' in the MEMO panel for the first template in the storage box. Then you can quickly copy and paste them back here on reloading.'

                  +'||The size of the page outlines is determined by your current paper-size for the printer and the current trim margins which have been set in the PRINT > TRIM MARGINS menu items.'
                  +' The apparent page size dimensions shown on the trackpad reflect the current print size setting in the PRINT > ENLARGE/REDUCE SIZE menu options.';

var
  i,n:integer;
  od:Toutdim;

begin
    if fit_single_sheet=True
       then begin
              i:=alert(3,'    set  page  origin  -  fit  single  page',
                         'You are currently set to print the drawing reduced to fit on a single page.'
                        +'||If you change the page origin not all of your drawing may be printed, or more than one page may be printed.',
                         '','','','change  to  normal  size  printing  ( 100 % )    ','cancel  -  no  changes    ','O K',0);
              case i of
                  4: normal_scaling_menu_entry.Click;
                  5: EXIT;
              end;//case
            end;


    i:=alert(4,' set  page  origin  -  mm  or  number  of  pages ?',
               'The page origin position can be set in millimetres or as a number of pages from the drawing datum.',
               '','','','number  of  pages','cancel','mm',0);

    case i of
        4: begin
              putdim(help_xpages_str,0,'page  origin  X  in  page-lengths',print_pages_top_origin*100*out_factor/page_length,False,False,False,False);   // negative ok, preset ok, zero ok, don't terminate on zero.
           n:=putdim(help_ypages_str,0,'page  origin  Y  in  page-widths',print_pages_left_origin*100*out_factor/page_width,False,False,False,False);   // negative ok, preset ok, zero ok, don't terminate on zero.

              if n<>1 then EXIT;
              if getdims('page  origin  in  number  of  pages',help_porg_str,pad_form,n,od)=True
                 then begin

                        if od[0]=def_req then print_pages_top_origin:=0
                                         else print_pages_top_origin:=od[0]*page_length/100/out_factor;

                        if od[1]=def_req then print_pages_left_origin:=0
                                         else print_pages_left_origin:=od[1]*page_width/100/out_factor;
                      end;
           end;

        5: EXIT;

        6: begin
              putdim(help_x_str,1,'page  origin  X',print_pages_top_origin,False,False,False,False);   // negative ok, preset ok, zero ok, don't terminate on zero.
           n:=putdim(help_y_str,1,'page  origin  Y',print_pages_left_origin,False,False,False,False);   // negative ok, preset ok, zero ok, don't terminate on zero.

              if n<>1 then EXIT;
              if getdims('page  origin  in  mm',help_porg_str,pad_form,n,od)=True
                 then begin
                        if od[0]=def_req then print_pages_top_origin:=0
                                         else print_pages_top_origin:=od[0];

                        if od[1]=def_req then print_pages_left_origin:=0
                                         else print_pages_left_origin:=od[1];
                      end;
           end;
    end;//case

    do_rollback:=False;
    page_info(True,True,False,0);  // for the page outlines on the pad.
    redraw(True);                  // redraw them.
end;
//________________________________________________________________________________________

procedure Tpad_form.reset_page_origin_menu_entryClick(Sender: TObject);

begin
  print_pages_top_origin:=0;
  print_pages_left_origin:=0;

  do_rollback:=False;

  page_info(True,True,False,0); // for the page outlines on the pad.
  redraw(True);                 // redraw them.
end;
//_________________________________________________________________________________________

procedure Tpad_form.printer_only_margins_menu_entryClick(Sender: TObject);     // 205e

begin
  if per_printer_margins=True
     then trim_per_printer_menu_entry.Checked:=True    // radio item.
     else set_trim_margins_menu_entry.Checked:=True;   // radio item.

  if (show_margins>0) and (out_factor=1.0)
     then show_printable_area_menu_entry.Enabled:=True
     else begin
            show_printable_area_menu_entry.Checked:=False;
            show_printable_area_menu_entry.Enabled:=False;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.trim_per_printer_menu_entryClick(Sender: TObject);

begin
  per_printer_margins:=True;

  do_rollback:=False;
  page_info(True,True,False,0);  // for the page outlines on the pad.
  redraw(True);                  // redraw them.
end;
//_________________________________________________________________________________________

procedure Tpad_form.set_trim_margins_menu_entryClick(Sender: TObject);

const
  help_trleft_str:string='     Left  Trim  Margin'
                  +'||Enter a dimension in millimetres for the distance between the left edge of the printable area and the left-side trim margin line.'
                  +'||Note that the edge of the printable area is usually a little way inside the actual edge of the paper. (Refer to your printer documentation for the actual dimension.)'
                  +'||The left trim margin corresponds to the bottom edge of the page outline as shown on the trackpad screen view.'
                  +'||The minimum dimension which Templot will accept is 1 mm. The pre-set dimension is 7 mm. Dimensions in inches can be entered by prefixing with the letter i. For example i0.25 sets a trim margin of 1/4".'
                  +'||For more general information about setting the trim margins, click MORE GENERAL INFORMATION below.';

  help_trtop_str:string='     Top  Trim  Margin'
                  +'||Enter a dimension in millimetres for the distance between the top edge of the printable area and the top trim margin line.'
                  +'||Note that the edge of the printable area is usually a little way inside the actual edge of the paper. (Refer to your printer documentation for the actual dimension.)'
                  +'||The top trim margin corresponds to the left edge of the page outline as shown on the trackpad screen view.'
                  +'||The minimum dimension which Templot will accept is 1 mm. The pre-set dimension is 6 mm. Dimensions in inches can be entered by prefixing with the letter i. For example i0.25 sets a trim margin of 1/4".'
                  +'||For more general information about setting the trim margins, click MORE GENERAL INFORMATION below.';

  help_trwidth_str:string='     Trimmed  Page  Width'
                  +'||Enter a dimension in millimetres for the width of the trimmed page between the left and right trim margin lines.'
                  +'||The left and right trim margins correspond to the bottom and top edges respectively of the page outline as shown on the trackpad screen view.'
                  +'||The maximum dimension which Templot will accept is that which results in a right trim margin of at least 1 mm inside the right edge of the printable area, at the current left trim margin setting.'
                  +'||Note that the edge of the printable area is usually a little way inside the actual edge of the paper. (Refer to your printer documentation for the actual dimension.)'
                  +'||Dimensions in inches can be entered by prefixing with the letter i. For example i7.5 sets a trimmed page width of 7.1/2".'
                  +'||For more general information about setting the trimmed page size, click MORE GENERAL INFORMATION below.';

  help_trlength_str:string='     Trimmed  Page  Length'
                  +'||Enter a dimension in millimetres for the length of the trimmed page between the top and bottom trim margin lines.'
                  +'||The top and bottom trim margins correspond to the left and right edges respectively of the page outline as shown on the trackpad screen view.'
                  +'||The maximum dimension which Templot will accept is that which results in a bottom trim margin of at least 1 mm inside the bottom edge of the printable area, at the current top trim margin setting.'
                  +'||Note that the edge of the printable area is usually a little way inside the actual edge of the paper. (Refer to your printer documentation for the actual dimension.)'
                  +'||Dimensions in inches can be entered by prefixing with the letter i. For example i10.5 sets a trimmed page length of 10.1/2".'
                  +'||For more general information about setting the trimmed page size, click MORE GENERAL INFORMATION below.';

var
  i,n:integer;
  od:Toutdim;
  max_trim_length, max_trim_width:extended;
  trim_length, trim_width:extended;
  warn:boolean;

begin
  if page_info(True,True,False,0)=False then EXIT;   // get the page sizes.

  try

    if banner_paper=False
       then begin
              repeat
                warn:=False;   // init.

                   putdim(help_trleft_str,1,'left  trim  margin',page_margin_left_mm,True,False,True,False);   // no neg, preset ok, no zero, don't terminate on zero.
                n:=putdim( help_trtop_str,1, 'top  trim  margin', page_margin_top_mm,True,False,True,False);   // no neg, preset ok, no zero, don't terminate on zero.

                if n<>1 then EXIT;
                if getdims('left  and  top  trim  margins',trim_help_str,pad_form,n,od)=False then EXIT;

                if od[0]<>def_req then page_margin_left_mm:=od[0]
                                  else page_margin_left_mm:=7.0;    // pre-set.

                if page_margin_left_mm<1.0
                   then begin
                          page_margin_left_mm:=1.0;    // 1mm arbitrary.
                          warn:=True;
                        end;

                if od[1]<>def_req then page_margin_top_mm:=od[1]
                                  else page_margin_top_mm:=6.0;

                if page_margin_top_mm<1.0
                   then begin
                          page_margin_top_mm:=1.0;
                          warn:=True;
                        end;

                if warn=True
                   then begin
                          repeat
                            i:=alert(6,'    trim  margins  wrong',
                                       'The left trim margin cannot be less than 1 mm.'
                                      +'||You are currently set to print on single sheets, for which the top trim margin cannot be less than 1 mm.',
                                       '','','','help  information','reset  normal  margins','re - try ...',4);
                            case i of
                                  4: alert_help(0,trim_help_str,'');
                                  5: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       EXIT;
                                     end;
                            end;//case
                          until i<>4;
                        end;
              until warn=False;

                //-----------

              max_trim_width:=print_width/100-page_margin_left_mm-1.0;     // max printable area between margins mm.
              max_trim_length:=print_length/100-page_margin_top_mm-1.0;    // length ditto.

              trim_width:=print_width/100-page_margin_left_mm-page_margin_right_mm;     // current width per page between margins mm.
              trim_length:=print_length/100-page_margin_top_mm-page_margin_bottom_mm;   // length ditto.

              repeat
                warn:=False;  // init

                   putdim( help_trwidth_str,1, 'trimmed width between left and right margins', trim_width,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
                n:=putdim(help_trlength_str,1,'trimmed length between top and bottom margins',trim_length,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.

                if n<>1 then EXIT;
                if getdims('trimmed  page  width  and  length',trim_help_str,pad_form,n,od)=False then EXIT;

                page_margin_right_mm:=print_width/100-page_margin_left_mm-od[0];

                if page_margin_right_mm<1.0
                   then begin
                          page_margin_right_mm:=1.0;    // 1mm arbitrary.
                          warn:=True;
                        end;

                page_margin_bottom_mm:=print_length/100-page_margin_top_mm-od[1];

                if page_margin_bottom_mm<1.0
                   then begin
                          page_margin_bottom_mm:=1.0;
                          warn:=True;
                        end;

                if warn=True
                   then begin
                          repeat
                            i:=alert(6,'    trim  margins  wrong',
                                       'For the current paper size and printer calibration settings the following limits apply:'
                                      +'||With the current left trim margin setting of '+round_str(page_margin_left_mm,2)+' mm, the trimmed page width cannot be more than '+round_str(max_trim_width,2)+' mm.'
                                      +'||With the current top trim margin setting of '+round_str(page_margin_top_mm,2)+' mm, the trimmed page length cannot be more than '+round_str(max_trim_length,2)+' mm (currently printing on single sheets).',
                                       '','','help  information','printer  setup ...','reset  normal  margins','re - try ...',3);
                            case i of
                                  3: alert_help(0,trim_help_str,'');

                                  4: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       printer_setup(False,False);
                                       EXIT;
                                     end;

                                  5: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       EXIT;
                                     end;
                            end;//case
                          until i<>3;
                        end;
              until warn=False;

            end
       else begin        // banner paper...
              repeat
                n:=putdim(help_trleft_str,1,'left  trim  margin  ( banner  paper )',page_margin_left_mm,True,False,True,False);   // no neg, preset ok, no zero, don't terminate on zero.

                if n<>0 then EXIT;
                if getdims('left  trim  margin  ( banner  paper )',trim_help_str,pad_form,n,od)=False then EXIT;

                if od[0]<>def_req then page_margin_left_mm:=od[0]
                                  else page_margin_left_mm:=7.0;    // pre-set.

                if page_margin_left_mm<1.0
                   then begin
                          page_margin_left_mm:=1.0;    // 1mm arbitrary.

                          repeat
                            i:=alert(6,'    trim  margin  wrong',
                                       'The left trim margin cannot be less than 1 mm.',
                                       '','','','help  information','reset  normal  margins','re - try ...',4);
                            case i of
                                  4: alert_help(0,trim_help_str,'');
                                  5: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       EXIT;
                                     end;
                            end;//case
                          until i<>4;
                        end
                   else BREAK;
              until 0<>0;

              //-----------

              max_trim_width:=print_width/100-page_margin_left_mm-1.0;             // max printable area between margins mm.

              trim_width:=print_width/100-page_margin_left_mm-page_margin_right_mm;     // current width per page between margins mm.

              repeat
                n:=putdim( help_trwidth_str,1, 'trimmed width between left and right margins', trim_width,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.

                if n<>0 then EXIT;
                if getdims('trimmed  page  width  ( banner  paper )',trim_help_str,pad_form,n,od)=False then EXIT;

                page_margin_right_mm:=print_width/100-page_margin_left_mm-od[0];

                if page_margin_right_mm<1.0
                   then begin
                          page_margin_right_mm:=1.0;    // 1mm arbitrary.
                          repeat
                            i:=alert(6,'    trim  margins  wrong',
                                       'For the current paper size and printer calibration settings the following limit applies (banner paper):'
                                      +'||With the current left trim margin setting of '+round_str(page_margin_left_mm,2)+' mm, the trimmed page width cannot be more than '+round_str(max_trim_width,2)+' mm.',
                                       '','','help  information','printer  setup ...','reset  normal  margins','re - try ...',3);
                            case i of
                                  3: alert_help(0,trim_help_str,'');

                                  4: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       printer_setup(False,False);
                                       EXIT;
                                     end;

                                  5: begin
                                       per_printer_margins:=True;    // cancels above entries.
                                       EXIT;
                                     end;
                            end;//case
                          until i<>3;
                        end
                   else BREAK;
              until 0<>0;

            end;

    per_printer_margins:=False;   // use the new settings.

  finally
    do_rollback:=False;
    page_info(True,True,False,0);  // for the page outlines on the pad.
    redraw(True);                  // redraw them.
  end;//try
end;
//__________________________________________________________________________________

procedure Tpad_form.show_printable_area_menu_entryClick(Sender: TObject);

begin
  show_printable_area_menu_entry.Checked:= NOT show_printable_area_menu_entry.Checked;
  do_rollback:=False;
  redraw(True);
end;
//___________________________________________________________________________________

procedure Tpad_form.trim_margins_help_menu_entryClick(Sender: TObject);

begin
  help(0,trim_help_str,'');
end;
//_____________________________________________________________________________________

procedure Tpad_form.pages_staggered_menu_entryClick(Sender: TObject);

begin
  staggered_pages:=True;
  pages_staggered_menu_entry.Checked:=True;       // radio item.
  do_rollback:=False;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.pages_inline_menu_entryClick(Sender: TObject);

begin
  staggered_pages:=False;
  pages_inline_menu_entry.Checked:=True;     // radio item.
  do_rollback:=False;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.next_run_width_menu_entryClick(Sender: TObject);

begin
  get_show_margins_info(True);  // 0.93.a
  print_pages_left_origin:=print_pages_left_origin+page_width*(sheet_across_c+1)/100/out_factor;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.previous_run_width_menu_entryClick(Sender: TObject);

begin
  get_show_margins_info(True);  // 0.93.a
  print_pages_left_origin:=print_pages_left_origin-page_width*(sheet_across_c+1)/100/out_factor;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.next_run_length_menu_entryClick(Sender: TObject);

begin
  get_show_margins_info(True);  // 0.93.a
  print_pages_top_origin:=print_pages_top_origin+page_length*(sheet_down_c+1)/100/out_factor;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.previous_run_length_menu_entryClick(Sender: TObject);

begin
  get_show_margins_info(True);  // 0.93.a
  print_pages_top_origin:=print_pages_top_origin-page_length*(sheet_down_c+1)/100/out_factor;
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.cancel_popup_entryClick(Sender: TObject);

begin
  show_and_redraw(True,False);
  clicked_keep_index:=-1;
end;
//______________________________________________________________________________


procedure Tpad_form.reposition_menu_popup_entryClick(Sender: TObject);

begin
  control_room_form.popup_menu_position_menu_entry.Click;

  show_and_redraw(True,False);
  clicked_keep_index:=-1;
end;
//______________________________________________________________________________

procedure Tpad_form.quick_set_menu_entryClick(Sender: TObject);

var
  radius:extended;
  sx_index,sz:integer;
  on_datum:boolean;
  form_left_max:integer;

begin
  cancel_adjusts(False);   // 205e

  normalize_transforms;

  if (xshift=0) and (yshift=0) and (kform=0)
     then begin
            clear_transform_data;  // clear shifts if not already.
                on_datum:=True;    // set this now - routines below include a peg_curve.
              end
         else on_datum:=False;

  form_left_max:=Screen.DesktopWidth-mint_form.Width;

  with mint_form do begin

    Left:=pad_form.Left+info_form.Left+290;  // 0.93.a so can see rad info for new template (info_form is child of pad_form).

    if Left>form_left_max then Left:=form_left_max;

    joggled_rails_checkbox.Checked:=False;  // default for REA switches.

    mint_current_button.Enabled:=True;  // in case disabled on preview last time.
    zoom_fit_button.Enabled:=False;     // not until previewed

    chairing_checkbox.Checked:=exp_chairing;  // 242a

    repeat
      do_show_modal(mint_form);     // 212a  ShowModal

      if ModalResult=mrAll     // 233b
         then begin
                store_draw_button.Click;
                BREAK;
              end;

      if ModalResult=mrNo      // 218a
         then begin
                reset_tandem_turnout_menu_entry.Click;
                BREAK;
              end;

      if (ModalResult=mrNone) or (ModalResult=mrCancel) then BREAK;

              // modal results set in html viewer ...  0.93.a

      if ModalResult>99
         then begin

                if turnoutx=0 then extend_template_from_zero;

                if ModalResult=100 then select_switch;
                if ModalResult=101 then crossing_menu_entry.Click;
                if ModalResult=102 then curving_data_menu_entry.Click;

                show_and_redraw(True,True);

                BREAK;
              end;


         // 0.93.a Quick mode - first store existing control template but not if it's on datum or still where we quick-set it.
         // (i.e. not part of a track plan)

      if classic_templot=False    // Quick mode      0.93.a
         then begin
                if (on_datum=True)                                           // on datum
                or ((xshift=xshift_quickset) and (yshift=yshift_quickset))   // still where we quick-set it
                or (turnoutx=0)                                              // invalid template
                then begin
                       do_nothing;
                     end
                else begin
                       store_and_background(False,False);
                     end;
              end;

      if ModalResult<>mrIgnore
         then begin

                      // set new template from drop-downs ...

                if left_hand_radio_button.Checked=True then hand_i:=1
                                                       else hand_i:=-1;

                sx_index:=turnout_combo.ItemIndex;

                plain_track:=False;      // default init for turnouts.

                sz:=2;                   // keep compiler happy.
                case sx_index of

                           0: plain_track:=True; // plain track

                           1: begin sz:=1; k3n:=4.5; end;  // REA A-4.5
                           2: begin sz:=1; k3n:=5;   end;  // REA A-5
                           3: begin sz:=1; k3n:=5.5; end;  // REA A-5.5
                           4: begin sz:=1; k3n:=6;   end;  // REA A-6

                           5: begin sz:=2; k3n:=5.5; end;  // REA B-5.5
                           6: begin sz:=2; k3n:=6;   end;  // REA B-6
                           7: begin sz:=2; k3n:=6.5; end;  // REA B-6.5
                           8: begin sz:=2; k3n:=7;   end;  // REA B-7
                           9: begin sz:=2; k3n:=7.5; end;  // REA B-7.5
                          10: begin sz:=2; k3n:=8;   end;  // REA B-8

                          11: begin sz:=3; k3n:=8;   end;  // REA C-8
                          12: begin sz:=3; k3n:=9;   end;  // REA C-9
                          13: begin sz:=3; k3n:=10;  end;  // REA C-10

                          14: begin sz:=4; k3n:=10; end;   // REA D-10
                          15: begin sz:=4; k3n:=12; end;   // REA D-12

                         else begin sz:=2; k3n:=6;   end;  // REA B-6
                end;//case

                if sx_index<>0
                   then begin
                          if set_csi_data(2,sz)=False  // set REA switch data from listbox entries for control template.
                             then run_error(76);
                        end;

                csi.joggled_stock_rail:=joggled_rails_checkbox.Checked;

                set_xing_k_i;     // set selector list index to match k3n.

                if chairing_checkbox.Checked=True
                   then experimental_chairing_menu_entry.Click   // 242a ..
                   else no_chairing_menu_entry.Click;

                set_plain_track(plain_track,True);
              end;

      mint_new_current(0,True);    // mint a fresh one using above or existing.

      if (ModalResult<>mrIgnore) and (quick_set_radius(radius)=True)     // get the new radius
         then begin
                if radius<>0 then begin
                                    nomrad:=radius;
                                    spiral:=False;     // 0.77.b
                                  end
                             else straight_template_menu_entry.Click;
              end;

      if on_datum=True
         then begin
                xshift:=0;                  // cancel any shifts.
                yshift:=0;

                gocalc(2,0);                            // need screen calcs to set y_datum.
                set_y_datum;                            // in case RH.

                fit_current_only_menu_entry.Click;      // 0.93.a     //fit_org_extents_current_menu_entry.Click;    // zoom to fit on datum.

                show_and_redraw(False,True);            // in case hidden.
              end
         else begin
                show_and_redraw(False,True);            // force immediate calcs.
                //fit_current_only_menu_entry.Click;      // calcs needed first.
              end;

      xshift_quickset:=xshift;  // 0.93.a   save these for quick-set store check next time
      yshift_quickset:=yshift;  // 0.93.a

    until ModalResult<>mrRetry;    // 0.93.a

  end;//with
end;
//_____________________________________________________________________________________

procedure Tpad_form.mint_menu_entryClick(Sender: TObject);

begin
  if (classic_templot=False) and (turnoutx<>0)     // Quick mode      0.93.a
     then store_and_background(False,False);

  mint_new_current(0,True);

  show_and_redraw(False,True);      // force immediate calcs.
end;
//__________________________________________________________________________________________

procedure Tpad_form.pad_save_all_menu_entryClick(Sender: TObject);

begin
  save_box(0,0,0,'');         // don't need result flag.
end;
//____________________________________________________________________________________________

procedure reload_add_file(old_templot_folder:boolean);     // old folder option added 207a

var
  append:boolean;
  hl:integer;

begin
  append:=False;

  try   // 208d
                                                                           // he might change it.
    if load_storage_box(True,old_templot_folder,'',False,False,append,hl)=False then EXIT;   // nothing was loaded.

        // 0.93.a ...

    if keeps_list.Count=0 then EXIT;

    if append=True then EXIT;

    if (loaded_version<93) and (hl>-1) and (hl<keeps_list.Count) then mint_final_or_copy_control(hl);   // if something loaded mint from highest bgnd if he so wants.
    if (loaded_version>92) then mint_final_or_copy_control(hl);                                         // copy the control template if there is one in the file.

    pad_form.fit_bgnd_menu_entry.Click;     // in case it's larger than the background, e.g. all background unused.

  finally  // bug-fix  208d
    redraw_pad(True,True);
  end;//try
end;
//_______________________________________________________________________________________

procedure Tpad_form.pad_reload_menu_entryClick(Sender: TObject);

begin
  reload_add_file(False);
end;
//______________________________________________________________________________

procedure Tpad_form.old_pre_templot2_files_menu_entryClick(Sender:TObject);

begin
  reload_add_file(True);
end;
//______________________________________________________________________________

procedure Tpad_form.pad_clear_all_menu_entryClick(Sender: TObject);

begin
  if keeps_list.Count<1
     then begin
            if alert(6,'    no  stored  templates',
                       'Your storage box is currently empty, so there is nothing to clear.'
                      +'||For more information about storing background templates click the ? HELP button in the storage box.'
                      +'||To remove the control template, click the red Z toolbutton at the top of the trackpad, or press the Delete key on the keyboard. To simply hide it from view, press the Home key on the keyboard.',
                       '','','','','cancel  clear','show  storage  box',0)=6
               then begin
                      keep_form.Show;
                      keep_form.BringToFront;
                    end;
            EXIT;
          end;
  keep_form.clear_menu_entry.Click;
end;
//___________________________________________________________________________________________

procedure Tpad_form.undo_clear_or_reload_menu_entryClick(Sender: TObject);

begin
  keep_form.undo_clear_menu_entry.Click;
end;
//___________________________________________________________________________________________

procedure Tpad_form.generator_normal_menu_entryClick(Sender: TObject);

begin
  if guide_marks_menu_entry.Checked=False then guide_marks_menu_entry.Click;        // toggle guide marks on.
  if rad_end_marks_menu_entry.Checked=False then rad_end_marks_menu_entry.Click;    // toggle rad end marks on.
  if joint_marks_menu_entry.Checked=False then joint_marks_menu_entry.Click;        // toggle joint marks on.

  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;

  if timber_outlines_menu_entry.Checked=False then timber_outlines_menu_entry.Click;        // toggle outlines on.
  if outline_extensions_menu_entry.Checked=False then outline_extensions_menu_entry.Click;  // toggle extensions on.
  if reduced_ends_menu_entry.Checked=False then reduced_ends_menu_entry.Click;
  if timber_centres_menu_entry.Checked=False then timber_centres_menu_entry.Click;       // toggle timber centres on.
  if timber_numbers_menu_entry.Checked=False then timber_numbers_menu_entry.Click;       // toggle timber numbers on.
  if timbering_infill_menu_entry.Checked=False then timbering_infill_menu_entry.Click;                        // toggle timber infill on.
  if modified_timbering_infill_menu_entry.Checked=False then modified_timbering_infill_menu_entry.Click;      // 226a

  if stock_rails_menu_entry.Checked=False then stock_rails_menu_entry.Click;
  if crossing_rails_menu_entry.Checked=False then crossing_rails_menu_entry.Click;
  if check_rails_menu_entry.Checked=False then check_rails_menu_entry.Click;

  both_edges_menu_entry.Click;   // radio item.

  if gen_platforms_trackbed_edges_menu_entry.Checked=False then gen_platforms_trackbed_edges_menu_entry.Click;   // 0.93.a

end;
//_____________________________________________________________________________________

procedure Tpad_form.generator_skeleton_menu_entryClick(Sender: TObject);

begin
  if guide_marks_menu_entry.Checked=False then guide_marks_menu_entry.Click;        // toggle guide marks on.
  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;

  if stock_rails_menu_entry.Checked=False then stock_rails_menu_entry.Click;
  if crossing_rails_menu_entry.Checked=False then crossing_rails_menu_entry.Click;
  if check_rails_menu_entry.Checked=False then check_rails_menu_entry.Click;

  gauge_faces_only_menu_entry.Click;   // radio item.

      // all the rest switched off for skeleton settings...

  if joint_marks_menu_entry.Checked=True then joint_marks_menu_entry.Click;           // toggle joint marks off.

  if timber_outlines_menu_entry.Checked=True then timber_outlines_menu_entry.Click;        // toggle outlines off
  if outline_extensions_menu_entry.Checked=True then outline_extensions_menu_entry.Click;  // toggle extensions off.
  if reduced_ends_menu_entry.Checked=True then reduced_ends_menu_entry.Click;
  if timber_centres_menu_entry.Checked=True then timber_centres_menu_entry.Click;          // toggle timber centres off.
  if timber_numbers_menu_entry.Checked=True then timber_numbers_menu_entry.Click;          // toggle timber numbers off.
  if timbering_infill_menu_entry.Checked=True then timbering_infill_menu_entry.Click;                        // toggle timber infill off.
  if modified_timbering_infill_menu_entry.Checked=True then modified_timbering_infill_menu_entry.Click;      // 226a

  if gen_platforms_trackbed_edges_menu_entry.Checked=True then gen_platforms_trackbed_edges_menu_entry.Click;   // 0.93.a  toggle platforms/trackbeds off

end;
//________________________________________________________________________________________

procedure Tpad_form.generator_rebuild_bgnd_menu_entryClick(Sender: TObject);

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  Screen.Cursor:=crHourglass;

  try
    rebuild_background(True,False);
  finally
    Screen.Cursor:=crDefault;
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.gen_rebuild_group_menu_entryClick(Sender: TObject);

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  rebuild_group(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.click_zoom_rectangle_menu_entryClick(Sender: TObject);

begin
  if zoom_rectangle=True
     then begin
            zoom_rectangle:=False;
            panning_form.zoom_rectangle_latching_toolbutton.Down:=False;     // he changed his mind, so toggle.
            zoom_rectangle_latching_toolbutton.Down:=False;
            pad_caption('');
            Cursor:=crDefault;
            EXIT;
          end;

  cancel_adjusts(False);
  zoom_rectangle:=True;

  if check_grey_paper=False then Cursor:=zoom_rectangle_cursor;  // crCross; mod 13-1-01.
  pad_caption('click-drag  zoom  rectangle ...');
  panning_form.zoom_rectangle_latching_toolbutton.Down:=True;
  zoom_rectangle_latching_toolbutton.Down:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.group_selection_fence_menu_entryClick(Sender: TObject);

begin
  if group_fence_rectangle=True
     then begin
            group_fence_rectangle:=False;
            group_fence_latching_toolbutton.Down:=False;     // he changed his mind, so toggle.
            pad_caption('');
            Cursor:=crDefault;
            EXIT;
          end;

  cancel_adjusts(False);
  group_fence_rectangle:=True;

  if check_grey_paper=False then Cursor:=group_rectangle_cursor;  // crCross; mod 13-1-01.
  pad_caption('click-drag  group-selection  fence ...');
  group_fence_latching_toolbutton.Down:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.zone_normal_menu_entryClick(Sender: TObject);

begin
  zone_normal_menu_entry.Checked:=True;      // radio item.
end;
//__________________________________________________________________________________________

procedure Tpad_form.zone_rollout_menu_entryClick(Sender: TObject);

begin
  if tst<g         // 0.93.a  ...  (g arbitrary)
     then begin
            ShowMessage('The transition zone is currently too short to allow roll-out mode.');
            EXIT;
          end;

  zone_rollout_menu_entry.Checked:=True;      // radio item.
end;
//________________________________________________________________________________________

procedure Tpad_form.FormCloseQuery(Sender: TObject; var CanClose: Boolean);

begin
  control_room_form.quit_menu_entry.Click;    // terminate completely (if he wants to).
  CanClose:=quit_alert_done;                  // not if he cancelled.
end;
//___________________________________________________________________________________________

procedure Tpad_form.make_tools_cancel_blanking_menu_entryClick(Sender: TObject);

begin
  make_tools_cancel_blanking_menu_entry.Checked:=True;    // radio item.
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_tools_retain_blanking_menu_entryClick(Sender: TObject);

begin
  make_tools_retain_blanking_menu_entry.Checked:=True;    // radio item.
end;
//___________________________________________________________________________________________

procedure Tpad_form.make_tools_restore_shoved_menu_entryClick(Sender:TObject);

begin
  retain_shoves_on_make:=False;
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_tools_retain_shoved_menu_entryClick(Sender: TObject);

begin
  retain_shoves_on_make:=True;
end;
//__________________________________________________________________________________________

procedure Tpad_form.make_tools_restore_check_rails_menu_entryClick(Sender:TObject);

begin
  retain_diffs_on_make:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.make_tools_retain_check_rails_menu_entryClick(Sender:TObject);

begin
  retain_diffs_on_make:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.make_tools_cancel_rolled_menu_entryClick(Sender: TObject);

begin
  make_tools_cancel_rolled_menu_entry.Checked:=True;    // radio item.
end;
//_________________________________________________________________________________________

procedure Tpad_form.make_tools_retain_rolled_menu_entryClick(Sender: TObject);

begin
  make_tools_retain_rolled_menu_entry.Checked:=True;    // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.make_tools_normalize_transitions_menu_entryClick(Sender: TObject);

begin
  make_tools_normalize_transitions_menu_entry.Checked:=True;    // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.make_tools_no_normalizing_menu_entryClick(Sender: TObject);

begin
  make_tools_no_normalizing_menu_entry.Checked:=True;    // radio item.
end;
//_______________________________________________________________________________________

procedure Tpad_form.group_fence_partial_menu_entryClick(Sender: TObject);

begin
  group_fence_partial_menu_entry.Checked:=True;    // radio item.
end;
//____________________________

procedure Tpad_form.group_fence_whole_menu_entryClick(Sender: TObject);

begin
  group_fence_whole_menu_entry.Checked:=True;    // radio item.
end;
//_________________________________________________________________________________________

procedure Tpad_form.group_fence_new_menu_entryClick(Sender: TObject);

begin
  group_fence_new_menu_entry.Checked:=True;  // radio item.
end;
//____________________________________

procedure Tpad_form.group_fence_add_menu_entryClick(Sender: TObject);

begin
  group_fence_add_menu_entry.Checked:=True;  // radio item.
end;
//____________________________________

procedure Tpad_form.group_fence_toggle_menu_entryClick(Sender: TObject);

begin
  group_fence_toggle_menu_entry.Checked:=True;  // radio item.
end;
//____________________________________

procedure Tpad_form.group_fence_remove_menu_entryClick(Sender: TObject);

begin
  group_fence_remove_menu_entry.Checked:=True;   // radio item
end;
//___________________________________________________________________________________________

procedure Tpad_form.notch_link_help_menu_entryClick(Sender: TObject);

const
  notch_link_help_str:string='      Linking the Pegging Notch to the Control Template'
  +'||Clicking the LINK NOTCH TO TEMPLATE AT PEG menu item moves the pegging notch under the fixing peg at its current position on the control template, in the same way as the normal NOTCH UNDER PEG function (DIVIDE key).'
  +'||In addition however, if the peg is at a pre-set position (peg-indicator showing numbers 0-9, N, or U), this position within the template will be remembered,'
  +' and the notch will be maintained there as the control template is adjusted by mouse action.'

  +'||Note that it is NOT subsequently necessary for the fixing peg to also remain at this position, you will often want to move it to a different position to maintain the track alignment for the mouse action.'

  +'||If the peg is not at a pre-set position (peg-indicator showing F, M, or S), for example after moving the peg manually (CTRL-F8 MOVE PEG mouse action),'
  +' the notch will follow the position of the peg as the control template is adjusted by mouse action.'

  +'||The linking will be cancelled if you move the position of the notch manually, or click the NOTCH UNLINKED menu item.'
  +'||N.B. This linking to the control template applies only while a mouse action is in force. Other changes to the control template will not change the position of the notch on the trackpad.'
  +' The normal unlinked peg and notch functions are used in this case.'

  +'||Handy Hint :'
  +'|This function is primarily intended for use when a selected group of background templates have been previously linked to the notch.'
  +' In this way a group of templates can be maintained in alignment with the control template while it is being adjusted.'
  +'||For more information about GROUP LINKING, click the button below.';

begin
  if help(0,notch_link_help_str,'about  group  linking')=1 then help(0,group_link_help_str,'');
end;
//_________________________________________________________________________________________

procedure Tpad_form.jotter_menu_entryClick(Sender: TObject);

begin
  if jotter_form.Showing=True then jotter_form.Close
                              else begin
                                     jotter_form.Show;
                                     pad_form.Show;  // don't make it active until clicked (so that CTRL-J can toggle).
                                   end;
end;
//________________________________________________________________________________________

procedure Tpad_form.make_turnout_road_menu_entryClick(Sender: TObject);

begin
  make_external_road_menu_entry.Enabled:=(egpx>(0-minfp_big));
  make_internal_road_menu_entry.Enabled:=(igpx>(0-minfp_big));
end;
//________________________________________________________________________________________

procedure Tpad_form.timbering_menu_entryClick(Sender: TObject);

begin
  case exittb_i of
             0: exit_no_timbers_menu_entry.Checked:=True;        // radio item.
             1: exit_timbers_menu_entry.Checked:=True;           // radio item.
             2: exit_sleepers_menu_entry.Checked:=True;          // radio item.
           else run_error(218);
  end;//case

           // 218a ..

  approach_sleepered_menu_entry.Checked:= NOT approach_rails_only;     // radio item
  approach_rails_only_menu_entry.Checked:=approach_rails_only;         // radio item.
end;
//___________________________________________________________________________________________

procedure Tpad_form.flatbottom_rails_menu_entryClick(Sender: TObject);

const
  fb_help_str:string='php/701    `0Rail Foot Edges (flat-bottom rails)`9'

          +'||This template option causes the rail-foot edges to be shown in the output in addition to the rail-head edges.'
          +'||This is intended for construction templates for track having flat-bottom rails (FB track).'
          +' The rail-foot edge lines can be used to align the rails over the printed template where the width of the rail foot obscures the rail-head edge lines.'

          +'||rp.gif  <span style="color:red;">This function is a provisional implementation in this version of Templot with the following limitations:</span>'

          +'||rp.gif  Rail foot edges are shown in the output only, and on background templates only. They are not available on the control template.'
          +'||rp.gif  Sorry, the rail-foot indication on the trackpad screen, and on the storage box, is not yet implemented in this version of Templot.'

          +'||If `0detail-mode`3 output is in force, rail foot edges are shown on printed templates, in exported PDF and image files, and on the sketchboard.'
          +'||Rail foot edge lines are also included in exported DXF files (2-D only).'

          +'||The representation of the rail foot in the region of the switch rail tips (points) will be improved in later versions of Templot.'
          +'||green_panel_begintree.gif The rail foot dimensions can be set at `0REAL > RAILS > RAIL SECTION DATA...`1 menu item.'
          +'||The rail inclination angle, if any, will be ignored if the `0REAL > RAILS > VERTICAL RAILS`1 menu option is in force.'
          +'||If the `0REAL > RAILS > INCLINED RAILS`1 menu option is selected for canted rails, the rail foot edges will be offset accordingly to maintain the correct track gauge at the rail head.'
          +'green_panel_end'

          +'|green_panel_begintree.gif If inclined bullhead rails are used, this function can be used to show the outer edge of the foot in the larger scales.'
          +' Set the foot width to match the head width.'
          +'green_panel_end'; 

var
  i:integer;

begin

  repeat
    i:=alert (2,'php/701    FB  (flat-bottom)  rails',
                'Show rail-foot edge lines for FB track (flat-bottom rails).'
               +'||This option causes rail-foot edges to be shown in addition to the rail-head edges.'
               +'||rp.gif  This function is a provisional implementation in this version of Templot.'
               +'||rp.gif  Please be sure to click `0MORE INFORMATION`1 below and read the notes.',
             '','','','more  information','cancel  -  no  change','O K',4);

    if i=5 then EXIT;

    if i=4 then help(0,fb_help_str,'');

  until i=6;

  rail_section:=2;
  
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//_____________________________

procedure Tpad_form.bullhead_rails_menu_entryClick(Sender: TObject);

begin
  rail_section:=1;

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//_____________________________

procedure Tpad_form.no_rails_menu_entryClick(Sender: TObject);

begin
  rail_section:=0;

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.vertical_rails_menu_entryClick(Sender: TObject);

begin
  vertical_rails:=True;
  redraw(True);
end;
//_________________________________

procedure Tpad_form.inclined_rails_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  if rail_section=1
     then begin
            repeat
              i:=alert(3,'    inclined  rails  -  bullhead',
                         'Select the REAL > RAILS > HEAD AND FOOT menu option if you want the template to include the outer foot line of inclined bullhead rails.',
                         '','','','?  help','cancel  inclined  rails','OK  -  continue',4);
              case i of
                     4: alert_help(0,help_rail_str,'');
                     5: begin
                          vertical_rails_menu_entry.Click;
                          EXIT;
                        end;
              end;//case
            until i<>4;
          end;

  vertical_rails:=False;
  redraw(True);
end;
//________________________________________________________________________________________

procedure Tpad_form.rails_menu_entryClick(Sender: TObject);

begin
  case rail_section of
                 0: no_rails_menu_entry.Checked:=True;         // radio item.
                 1: bullhead_rails_menu_entry.Checked:=True;   // radio item.
                 2: flatbottom_rails_menu_entry.Checked:=True; // radio item.
  end;//case

  if vertical_rails=True then vertical_rails_menu_entry.Checked:=True    // radio item.
                         else inclined_rails_menu_entry.Checked:=True;   // radio item.

  case flare_type of
                0: bent_flares_menu_entry.Checked:=True;       // radio item.
                1: machined_flares_menu_entry.Checked:=True;   // radio item.
  end;//case

end;
//______________________________________________________________________________

procedure Tpad_form.normal_track_centre_lines_menu_radioClick(Sender: TObject);

begin
  normal_track_centre_lines_menu_radio.Checked:=True;   // radio item

  track_centre_lines_flag:=True;
  cl_only:=False;

  dummy_template:=False;  // 211c

  rail_options_form.restore_all_button.Click;  // 211c

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.centre_lines_only_menu_radioClick(Sender: TObject);

begin
  centre_lines_only_menu_radio.Checked:=True;   // radio item

  track_centre_lines_flag:=True;
  cl_only:=True;

  dummy_template:=False;   // 211c

  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;  // make sure generator centre-lines are on.

  shove_timber_form.Close;   // no timbers to shove.

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.no_track_centre_lines_menu_radioClick(Sender: TObject);

begin
  no_track_centre_lines_menu_radio.Checked:=True;   // radio item

  track_centre_lines_flag:=False;
  cl_only:=False;

  dummy_template:=False;     // 211c

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.dummy_template_menu_radioClick(Sender: TObject);  // 211c

   // same as centre-lines only, but drawn as background shape. 211c

begin

  dummy_template_menu_radio.Checked:=True;   // radio item

  track_centre_lines_flag:=True;
  cl_only:=True;

  dummy_template:=True;     // 211c

  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;  // make sure generator centre-lines are on.

  shove_timber_form.Close;   // no timbers to shove.

  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.switch_drive_menu_entryClick(Sender: TObject);   // 0.82.a 13-10-06  option in file.

begin
  switch_drive_flag:= NOT switch_drive_flag;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.bent_flares_menu_entryClick(Sender: TObject);

begin
  flare_type:=0;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.machined_flares_menu_entryClick(Sender: TObject);

begin
  if fw_end>(fw+railtop-0.125*inscale)  // 1/8" minimum end.
     then begin
            if alert(2,'    machined  flared  ends',
                    'Machined flared ends are not possible because your current setting for the flangeway end gap is wider than the available rail width.',
                    '','','','','cancel','reduce  flangeway  end  gap  to  fit',0)=5
               then EXIT;
            cpi.fwe_pi:=fw+railtop-0.125*inscale;
            get_cpi;
          end;

  flare_type:=1;
  redraw(True);
end;
//__________________________________________________________________________________________

procedure Tpad_form.notch_on_radial_centre_menu_entryClick(Sender: TObject);

var
  new_notch_data:Tnotch;

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  with new_notch_data do begin
    notch_x:=rad1_orgx;
    notch_y:=rad1_orgy;
    notch_k:=0;
  end;//with
  new_notch(new_notch_data,True);      // new data, and link group if wanted.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.notch_on_2nd_radial_centre_menu_entryClick(Sender: TObject);

var
  new_notch_data:Tnotch;

begin
  notch_unlinked_from_current_menu_entry.Click;  // radio item - cancel any moving the notch in mouse actions.

  with new_notch_data do begin
    notch_x:=rad2_orgx;
    notch_y:=rad2_orgy;
    notch_k:=0;
  end;//with
  new_notch(new_notch_data,True);      // new data, and link group if wanted.

  do_rollback:=False;       // no need to put this change in rollback register on redraw.
  redraw(True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.select_group_by_marker_colour_menu_entryClick(Sender: TObject);

var
 n,col:integer;

begin
  if keeps_list.Count<1 then EXIT;

  unlink_group;

  col:=get_colour('specify  the  template  marker  colour  required  for  selection  to  a  new  group',clRed);

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if template_info.keep_dims.box_dims1.bgnd_code_077=-1
         then group_selected:=False   // library template???
         else group_selected:=( (template_info.keep_dims.box_dims1.pad_marker_colour=col) and (template_info.keep_dims.box_dims1.use_pad_marker_colour=True) );
    end;//with
  end;//for

  if any_selected<1
     then alert(6,'    no  matching  templates  for  group',
                  'There are no background templates matching the specified marker colour.'
                 +'||No group is selected.',
                  '','','','','','continue',0);

  redraw_pad(True,False);    // show them.  // 0.82.d
end;
//__________________________________________________________________________________________
(* OT2024

procedure Tpad_form.select_group_by_date_menu_entryClick(Sender: TObject);        // 244d

var
  group_date:TDate;
  mr:TModalResult;
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  mr:=do_show_modal(date_form);

  group_date:=date_form.date_time_picker.Date;

  if mr=mrNo          // before date
     then for n:=0 to (keeps_list.Count-1) do Ttemplate(keeps_list.Objects[n]).group_selected:=(StrToDate(Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1.keep_date)<group_date);

  if mr=mrRetry       // on date
     then for n:=0 to (keeps_list.Count-1) do Ttemplate(keeps_list.Objects[n]).group_selected:=(StrToDate(Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1.keep_date)=group_date);

  if mr=mrYes         // on or after date
     then for n:=0 to (keeps_list.Count-1) do Ttemplate(keeps_list.Objects[n]).group_selected:=(StrToDate(Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1.keep_date)>=group_date);

  redraw(True);   
end;
//______________________________________________________________________________
*)
procedure Tpad_form.group_select_all_plain_track_menu_entryClick(Sender: TObject);

                 // 0.82.d  for use with trackbed edges (rebuild group).
var
 n:integer;

begin
  if keeps_list.Count<1 then EXIT;   // ??? menu should be disabled

  unlink_group;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if template_info.keep_dims.box_dims1.bgnd_code_077<>1   // not on background
         then group_selected:=False
         else group_selected:=template_info.keep_dims.box_dims1.turnout_info1.plain_track_flag;
    end;//with
  end;//for

  if any_selected<1
     then alert(6,'    no  plain  track  templates  for  group',
                  'There are no plain track background templates.'
                 +'||No group is selected.',
                  '','','','','','continue',0);
  redraw_pad(True,False);    // show them.
end;
//______________________________________________________________________________

procedure Tpad_form.group_select_all_bricks_menu_entryClick(Sender: TObject);       // 234a

var
 n,nb:integer;

begin
  if keeps_list.Count<1 then EXIT;

  unlink_group;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      group_selected:=template_info.keep_dims.box_dims1.timbering_brick_flag;   // template is a member of a timbering brick
    end;//with
  end;//for

  nb:=any_selected;     // number of brick templates

  if nb<1
     then alert(6,'    no  brick  templates  for  group',
                  'There are no templates which are members of a timbering brick.'
                 +'||No group is selected.',
                  '','','','','','continue',0)
     else show_modal_message('The group contains '+IntToStr(nb)+' templates which are members of timbering bricks.');

  redraw_pad(True,False);    // show them.
end;
//______________________________________________________________________________

procedure Tpad_form.group_select_all_non_bricks_menu_entryClick( Sender: TObject);

var
 n,nb:integer;

begin
  if keeps_list.Count<1 then EXIT;

  unlink_group;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      group_selected:= NOT template_info.keep_dims.box_dims1.timbering_brick_flag;   // template is not a member of a timbering brick
    end;//with
  end;//for

  nb:=any_selected;     // number of non-brick templates

  if nb<1
     then alert(6,'    no  non-brick  templates  for  group',
                  'There are no templates which are not members of a timbering brick.'
                 +'||No group is selected.',
                  '','','','','','continue',0)
     else show_modal_message('The group contains '+IntToStr(nb)+' templates which are not members of timbering bricks.');

  redraw_pad(True,False);    // show them.
end;
//______________________________________________________________________________

procedure Tpad_form.group_select_current_brick_menu_entryClick(Sender: TObject);  //234a

var
 n,nb:integer;

begin
  if keeps_list.Count<1 then EXIT;

  unlink_group;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1 do begin
      Ttemplate(keeps_list.Objects[n]).group_selected:=(timbering_brick_flag=True) and (use_pad_marker_colour=True) and (pad_marker_colour=brick_form.store_marker_colour_panel.Color);   // template is a member of current timbering brick
    end;//with
  end;//for

  nb:=any_selected;     // number of brick templates

  if nb<1
     then alert(6,'    no  brick  templates  for  group',
                  'There are no templates which are members of the current timbering brick.'
                 +'||No group is selected.',
                  '','','','','','continue',0)
     else show_modal_message('The group contains '+IntToStr(nb)+' templates which are members of the current timbering brick.');

  redraw_pad(True,False);    // show them.
end;
//______________________________________________________________________________

procedure Tpad_form.bonus_timbers_menu_entryClick(Sender: TObject);

begin
  remove_bonus_timber_menu_entry.Enabled:=(bontimb>0);
  remove_all_bonus_timbers_menu_entry.Enabled:=(bontimb>0);
end;
//___________________________________

procedure Tpad_form.add_bonus_timber_menu_entryClick(Sender: TObject);

begin
  INC(bontimb);
  redraw(True);
end;
//____________________________________

procedure Tpad_form.remove_bonus_timber_menu_entryClick(Sender: TObject);

begin
  DEC(bontimb);
  If bontimb<0 then bontimb:=0;
  redraw(True);
end;
//_____________________________________

procedure Tpad_form.remove_all_bonus_timbers_menu_entryClick(Sender: TObject);

begin
  bontimb:=0;
  redraw(True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.normal_joints_menu_entryClick(Sender: TObject);

begin
  rjcode:=0;
  redraw(True);
end;
//_______________________________________

procedure Tpad_form.staggered_joints_menu_entryClick(Sender: TObject);

begin
  rjcode:=1;
  redraw(True);
end;
//_______________________________________

procedure Tpad_form.no_joints_menu_entryClick(Sender: TObject);

begin
  rjcode:=0-1;
  redraw(True);
end;
//________________________________________

procedure Tpad_form.plain_track_joints_menu_entryClick(Sender: TObject);

begin
  case rjcode of      // plain track rail joints code, 0=normal, 1=staggered, -1=none (cwr).

          -1:no_joints_menu_entry.Checked:=True;          // radio item.
           0:normal_joints_menu_entry.Checked:=True;      // radio item.
           1:staggered_joints_menu_entry.Checked:=True;   // radio item.
  end;//case
end;
//_____________________________________________________________________________________

procedure Tpad_form.rail_joints_help_menu_entryClick(Sender: TObject);

const
  rjhelp_str:string='    Rail  Joint  Marks'
    +'||These options can be used to represent staggered rail joints (for US and some Irish practice), and CWR (long-welded rail).'
    +'||Click the REAL > PLAIN TRACK OPTIONS > RAIL LENGTHS AND SLEEPER SPACINGS... menu item, select one of the custom slots in the list,'
    +' then click the CUSTOM SETTINGS... button and read the help notes for more information.';

begin
  help(0,rjhelp_str,'');
end;
//____________________________________________________________________________________

procedure Tpad_form.use_normal_colours_menu_entryClick(Sender: TObject);

begin
  marker_colours_pad:=0;
  do_rollback:=False;
  redraw(True);
end;
//_________________________________

procedure Tpad_form.use_marker_colours_rails_only_menu_entryClick(Sender: TObject);

begin
  marker_colours_pad:=1;
  do_rollback:=False;
  redraw(True);
end;
//_________________________________

procedure Tpad_form.use_marker_colours_timbers_only_menu_entryClick(Sender: TObject);

begin
  marker_colours_pad:=2;
  do_rollback:=False;
  redraw(True);
end;
//____________________________________

procedure Tpad_form.use_marker_colours_all_menu_entryClick(Sender: TObject);

  //   for pad: 0=normal, 1=rails only, 2=timber outlines only, 3=rails and timber outlines, 4=print  mapping  colours instead.

begin
  marker_colours_pad:=3;
  do_rollback:=False;
  redraw(True);
end;
//________________________________

procedure Tpad_form.use_print_mapping_colours_menu_entryClick(Sender: TObject);

begin
  marker_colours_pad:=4;
  do_rollback:=False;
  redraw(True);
end;
//________________________________

procedure Tpad_form.background_templates_colours_menu_entryClick(Sender: TObject);

begin
  case marker_colours_pad of
             0: use_normal_colours_menu_entry.Checked:=True;              // radio item.
             1: use_marker_colours_rails_only_menu_entry.Checked:=True;   // radio item.
             2: use_marker_colours_timbers_only_menu_entry.Checked:=True; // radio item.
             3: use_marker_colours_all_menu_entry.Checked:=True;          // radio item.
             4: use_print_mapping_colours_menu_entry.Checked:=True;       // radio item.
  end;//case
end;
//________________________________________________________________________________________

procedure Tpad_form.normal_colours_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_pad_marker_colour:=False;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//____________________________________________________________________________________

procedure Tpad_form.marker_colour_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_pad_marker_colour:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//________________________________________________________________________________________

procedure Tpad_form.set_marker_colour_popup_entryClick(Sender: TObject);

var
  col,new_col:integer;

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  col:=Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.pad_marker_colour;

  new_col:=get_colour('choose  a  marker  colour  for  this  background  template  on  the  trackpad',col);

  with Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1 do begin
    pad_marker_colour:=new_col;
    use_pad_marker_colour:=True;         // assume he wants to use it.
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//______________________________________________________________________________

procedure Tpad_form.brick_colour_popup_entryClick(Sender: TObject);

begin
  set_marker_colour_popup_entry.Click; // 234a
end;
//______________________________________________________________________________

procedure Tpad_form.normal_print_colours_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_print_mapping_colour:=False;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//__________________________________________________________________________________________

procedure Tpad_form.print_mapping_colour_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_print_mapping_colour:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//_________________________________________________________________________________________

procedure Tpad_form.set_print_marker_colour_popup_entryClick(Sender: TObject);

var
  col,new_col:integer;

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  col:=Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.print_mapping_colour;

  new_col:=get_colour('choose  a  mapping  colour  for  this  background  template  when  printed',col);

  with Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1 do begin
    print_mapping_colour:=new_col;
    use_print_mapping_colour:=True;         // assume he wants to use it.
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//________________________________________________________________________________________

procedure Tpad_form.template_colours_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  if Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_pad_marker_colour=True
     then marker_colour_popup_entry.Checked:=True
     else normal_colours_popup_entry.Checked:=True;   // radio items.

  if Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.use_print_mapping_colour=True
     then print_mapping_colour_popup_entry.Checked:=True
     else normal_print_colours_popup_entry.Checked:=True;   // radio items.

end;
//____________________________________________________________________________________________

procedure Tpad_form.marker_and_mapping_colours_help_popup_entryClick(Sender: TObject);

begin
  marker_and_mapping_colours_help_menu_entry.Click;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//_________________________________________________________________________________________

procedure Tpad_form.show_group_normal_colours_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;

      template_info.keep_dims.box_dims1.use_pad_marker_colour:=False;
    end;//with
  end;//for
end;
//_________________________________________________________________________________________

procedure Tpad_form.show_group_marker_colours_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;

      template_info.keep_dims.box_dims1.use_pad_marker_colour:=True;
    end;//with
  end;//for

  warn_group_colour;
end;
//_______________________________________________________________________________________

procedure Tpad_form.group_marker_colour_menu_entryClick(Sender: TObject);

var
 n,col:integer;

begin
  if keeps_list.Count<1 then EXIT;

  col:=get_colour('choose  a  marker  colour  for  all  this  group  of  background  templates  on  the  trackpad',clRed);

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;
      template_info.keep_dims.box_dims1.pad_marker_colour:=col;
      template_info.keep_dims.box_dims1.use_pad_marker_colour:=True;         // assume he wants to use it.
    end;//with
  end;//for
  warn_group_colour;
end;
//________________________________________________________________________________________

procedure Tpad_form.marker_and_mapping_colours_help_menu_entryClick(Sender: TObject);

begin
  help(0,marker_mapping_help_str,'');
end;
//_______________________________________________________________________________________

procedure Tpad_form.print_group_normal_colours_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;

      template_info.keep_dims.box_dims1.use_print_mapping_colour:=False;
    end;//with
  end;//for

end;
//__________________________________________________________________________________

procedure Tpad_form.print_group_mapping_colours_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;

      template_info.keep_dims.box_dims1.use_print_mapping_colour:=True;
    end;//with
  end;//for
end;
//_________________________________________________________________________________

procedure Tpad_form.group_mapping_colour_menu_entryClick(Sender: TObject);

var
 n,new_col:integer;

begin
  if keeps_list.Count<1 then EXIT;

  new_col:=get_colour('choose  a  mapping  colour  for  all  this  group  of  background  templates  when  printed',clFuchsia);

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;
      template_info.keep_dims.box_dims1.print_mapping_colour:=new_col;    // set colour.
      template_info.keep_dims.box_dims1.use_print_mapping_colour:=True;   // assume he wants to use it.
    end;//with
  end;//for
end;
//____________________________________________________________________________________

procedure Tpad_form.mouse_actions_help_menu_entryClick(Sender: TObject);

const
  url_str:string='https://85a.uk/templot/companion/using_mouse_actions.php';    // 0.82.a

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,SW_SHOWNORMAL)<=32   // 0.79.a
     then begin
            alert(2,'    connection  failed',
                    ' |Sorry, unable to open your browser window and connect to the Templot web site.',
                    '','','','','','continue',0);
          end;
end;
//_________________________________________________________________________________________

procedure Tpad_form.templot_group_menu_entryClick(Sender: TObject);

begin
  go_to_templot_club;
end;
//_______________________________________________________________________________________

procedure Tpad_form.www_templot_com_menu_entryClick(Sender: TObject);

begin
  go_to_templot_com;
end;
//_______________________________________________________________________________________

procedure Tpad_form.warn_if_rails_infringe_menu_entryClick(Sender: TObject);

begin
  warn_centrelines:=False;
  redraw(True);             // update lamp.
end;
//_________________________________

procedure Tpad_form.warn_if_centrelines_infringe_menu_entryClick(Sender: TObject);

begin
  warn_centrelines:=True;
  redraw(True);             // update lamp.
end;
//__________________________________

procedure Tpad_form.ring_infringements_menu_entryClick(Sender: TObject);

begin
  if warn_centrelines=True then warn_if_centrelines_infringe_menu_entry.Checked:=True  // radio items
                           else warn_if_rails_infringe_menu_entry.Checked:=True;

end;
//________________________________________________________________________________________

procedure Tpad_form.convert_turnout_to_half_diamond_menu_entryClick(Sender: TObject);

begin
  convert_to_regular_half_diamond;
  redraw_pad(True,True);
end;
//________________________________________________________________________________________

procedure Tpad_form.convert_half_diamond_to_turnout_menu_entryClick(Sender: TObject);

begin
  convert_to_turnout;
  redraw_pad(True,True);
end;
//_________________________________________________________________________________________

procedure Tpad_form.auto_diamond_menu_entryClick(Sender: TObject);

begin
  auto_diamond:=0;
  if half_diamond=True then redraw_pad(True,True);
end;
//______________________________

procedure Tpad_form.fixed_diamond_menu_entryClick(Sender: TObject);

begin
  auto_diamond:=1;
  if half_diamond=True then redraw_pad(True,True);
end;
//________________________________

procedure Tpad_form.movable_diamond_menu_entryClick(Sender: TObject);

begin
  auto_diamond:=2;
  if half_diamond=True then redraw_pad(True,True);
end;
//________________________________________________________

procedure Tpad_form.hd_timbering_as_prototype_menu_entryClick(Sender: TObject);

begin
  hd_proto_timbering:=True;
  if half_diamond=True then redraw_pad(True,True);
end;
//______________________________

procedure Tpad_form.hd_timbering_as_model_menu_entryClick(Sender: TObject);

begin
  hd_proto_timbering:=False;
  if half_diamond=True then redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.hd_timbering_normal_menu_entryClick(Sender: TObject);    // 213a

begin
  hd_switch_timbering:=False;
  if half_diamond=True then redraw_pad(True,True);
end;
//_________________________________

procedure Tpad_form.hd_timbering_as_switch_menu_entryClick(Sender:TObject);  // 213a

begin
  hd_switch_timbering:=True;
  if half_diamond=True then redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.customize_k_crossing_menu_entryClick(Sender: TObject);

begin
  case auto_diamond of
        0: auto_diamond_menu_entry.Checked:=True;     // radio item.
        1: fixed_diamond_menu_entry.Checked:=True;    // radio item.
        2: movable_diamond_menu_entry.Checked:=True;  // radio item.
  end;//case

  if (half_diamond=True) and (auto_diamond=0)
     then begin
            if fixed_diamond=True
               then auto_diamond_menu_entry.Caption:='&automatic  ( currently  fixed )'
               else auto_diamond_menu_entry.Caption:='&automatic  ( currently  movable )'
          end
     else auto_diamond_menu_entry.Caption:='&automatic';
end;
//____________________________________________________________________________________

procedure Tpad_form.insert_half_diamond_menu_entryClick(Sender: TObject);

begin
  insert_half_diamond;
  redraw_pad(True,True);
end;
//_____________________________________________________________________________________

procedure Tpad_form.head_rail_centreline_only_menu_entryClick(Sender: TObject);

begin
  help(0,'php/720    `0rail centre-line option`9'
         +'||To create templates showing the rails as centre-lines only, please use the `0GENERATOR SETTINGS`1.'
         +'||Select the `0GENERATOR > GENERATOR SETTINGS > RAILS > RAIL CENTRE-LINES ONLY`1 menu option, and then if necessary `0REBUILD`1 any background templates.'
         +'||If the `0GENERATOR`1 menu is disabled (greyed out), click the `0MAIN > ENABLE GENERATOR MENU`1 menu item.'
         +'||green_panel_begintree.gif  If you are using traditional plywood and rivet construction for UK bullhead track,'
         +' printing a template with the rails shown as centre-lines is a handy way to get the hole centres for the rivets.'
         +' For accurate results make sure that the `0real > rails > vertical rails`1 option is set.'
         +'||For more information about this method, click the `0more&nbsp;information&nbsp;online`1 link above.'
         +'green_panel_end','');
end;
//_____________________________________________________________________________________


procedure Tpad_form.six_inch_steps_menu_entryClick(Sender: TObject);

begin
  timbinc:=6;
  redraw_pad(True,True);
end;
//_________________________

procedure Tpad_form.gradual_steps_menu_entryClick(Sender: TObject);

begin
  timbinc:=0;
  redraw_pad(True,True);
end;
//______________________

procedure Tpad_form.other_size_steps_menu_entryClick(Sender: TObject);

const
  step_help_str:string='    Timber  Length  Increments'
  +'||Enter a dimension in full-size prototype INCHES for the step size to be used when lengthening turnout timbers.'
  +'||The normal step size for UK standard-gauge practice is 6 inches.'
  +'||For more information click the button below.';

  var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(step_help_str,2,'timber  length  increments  ( step  size )',timbinc,True,True,False,False);   // no negative, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('timber  length  increments',timbering_help_str,pad_form,n,od)=True
     then timbinc:=od[0];

  redraw_pad(True,True);
end;
//________________________

procedure Tpad_form.timber_length_increments_menu_entryClick(Sender: TObject);

begin
  if ABS(timbinc-6.0)<minfp     // standard 6" steps.
     then begin
            six_inch_steps_menu_entry.Checked:=True;  // radio item.
            EXIT;
          end;

  if timbinc<minfp              // zero step size.
     then begin
            gradual_steps_menu_entry.Checked:=True;   // radio item.
            EXIT;
          end;

  other_size_steps_menu_entry.Checked:=True;  // radio item.
end;
//___________________________________________________________________________________

procedure Tpad_form.show_ruler_menu_entryClick(Sender: TObject);

begin
  show_ruler_tool:=True;
  redraw_pad(True,False);
end;
//_________________________

procedure Tpad_form.hide_ruler_menu_entryClick(Sender: TObject);

begin
  show_ruler_tool:=False;
  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.ruler_tool_menu_entryClick(Sender: TObject);

begin
  case ruler_units of
                0: ruler_as_grid_menu_entry.Checked:=True;   // radio item.
                1: ruler_mm_menu_entry.Checked:=True;        // radio item.
                2: ruler_inch_menu_entry.Checked:=True;      // radio item.
  end;//case
end;
//_________________________________________________________________

procedure Tpad_form.set_ruler_ends_menu_entryClick(Sender: TObject);

const
  help_ruler_str:string='     Set  Ruler  Ends'

  +'||Enter new X and Y dimensions in millimetres for the position of each end of the ruler tool.'
  +'||To enter dimensions in inches, prefix the figure with a letter i, e.g. enter i12 for 12 inches.'
  +'||The dimensions to be entered here are referenced from the trackpad origin point, and can be determined from the grid margin scales.'
  +' X-dimensions are positive across the trackpad from the left and read along the bottom margin,'
  +' Y-dimensions are positive up the trackpad from the bottom and read along the left margin.'
  +'||For many purposes, it is easier to move the ends of the ruler with the mouse actions, click the ACTION > MOUSE ACTIONS: TRACKPAD > MOVE RULER TOOL END menu items.'
  +'||The ends of the ruler can also be positioned by holding down the ALT key and clicking the mouse. A left-button click sets the 1st end at the mouse pointer position,'
  +' a right-button click sets the 2nd end. The mouse pointer can be changed to cross-hairs by clicking the TRACKPAD > CROSS-HAIRS MOUSE POINTER menu item.'
  +'||The ALT click functions will work while a mouse action is in force (including moving the ends by mouse action), but are available only while the ruler is actually showing.'
  +' Be aware that ALT-LEFT click also zeroes the MOVED BY read-out on the Jotter. If you want to do this without moving the ruler, temporarily hide the ruler (UTILS > RULER > HIDE RULER menu item).';

var
  n:integer;
  od:Toutdim;

begin
     putdim(help_ruler_str,1,'ruler  1st  end  X - dimension',ruler_startx,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
     putdim(help_ruler_str,1,'ruler  1st  end  Y - dimension',ruler_starty,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
     putdim(help_ruler_str,1,'ruler  2nd  end  X - dimension',ruler_endx,  False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  n:=putdim(help_ruler_str,1,'ruler  2nd  end  Y - dimension',ruler_endy,  False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.

  if n<>3 then EXIT;
  if getdims('ruler  end  positions','',pad_form,n,od)=True
     then begin
            ruler_startx:=od[0];
            ruler_starty:=od[1];
            ruler_endx:=od[2];
            ruler_endy:=od[3];
          end;
  redraw_pad(True,False);
end;
//____________________________________________________________________________________________

procedure Tpad_form.ruler_on_ring_menu_entryClick(Sender: TObject);

begin
  ruler_startx:=rings[0,0];
  ruler_starty:=rings[0,1];
  redraw_pad(True,False);
end;
//_________________________________________________________________________________________

procedure Tpad_form.ruler_on_notch_menu_entryClick(Sender: TObject);

begin
  ruler_startx:=notchx;
  ruler_starty:=notchy;
  redraw_pad(True,False);
end;
//_______________________________________________________________________________________

procedure Tpad_form.swap_ruler_ends_menu_entryClick(Sender: TObject);

var
  tempx,tempy:extended;

begin
  tempx:=ruler_startx;
  tempy:=ruler_starty;

  ruler_startx:=ruler_endx;
  ruler_starty:=ruler_endy;

  ruler_endx:=tempx;
  ruler_endy:=tempy;

  redraw_pad(True,False);
end;
//________________________________________________________________________________________

procedure Tpad_form.ruler_spacing_menu_entryClick(Sender: TObject);

const
  help_ruler_div_str:string='     Set  Ruler  Division  Spacing'

  +'||Enter a new dimension in millimetres for the spacing between each division marked on the ruler tool.'
  +'||To enter a dimension in inches, prefix the figure with a letter i, e.g. enter i12 for 12 inches.'
  +'||To enter a dimension in proto-feet, enter the corresponding dimension in millimetres at your current model scale,'
  +' e.g. enter 80 mm for 20 proto-feet spacings in 4mm/ft scale.'
  +'||<SPAN STYLE="color:#FF0000;">n.b.</SPAN> If you change the grid spacing on the trackpad and the ruler UNITS AS GRID option is in force,'
  +' the ruler division spacing is automatically set to match the grid X spacing.'
  +' If that is not wanted, you should change the grid spacing first, and then come here to change the ruler division spacing afterwards.';     // mod 0.93.a

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(help_ruler_div_str,1,'ruler  division  mark  spacing',ruler_div,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('ruler  division  mark  spacing','',pad_form,n,od)=True
     then ruler_div:=od[0];
  redraw_pad(True,False);
end;
//___________________________________________________________________________________________

procedure Tpad_form.ruler_as_grid_menu_entryClick(Sender: TObject);

begin
  ruler_units:=0;
  case grid_labels_code_i of                          //  0.91.b convert to sensible divisions in new units
      1: ruler_div:=ROUND(ruler_div/304.8)*304.8;     //  labels in feet.
      2: ruler_div:=ROUND(ruler_div/25.4)*25.4;       //  labels in inches.
      3: ruler_div:=ROUND(ruler_div/scale)*scale;     //  labels in prototype feet.
      4: ruler_div:=ROUND(ruler_div/10)*10;           //  labels in cm.
    else ruler_div:=ROUND(ruler_div);                 //  labels in mm.
  end;//case
  if ruler_div<1 then ruler_div:=1;                   //  1mm prevent neg or zero.
  redraw_pad(True,False);
end;
//_________________________

procedure Tpad_form.ruler_mm_menu_entryClick(Sender: TObject);

begin
  ruler_units:=1;
  ruler_div:=ROUND(ruler_div);                //  labels in mm.
  if ruler_div<1 then ruler_div:=1;           //  1mm prevent neg or zero.
  redraw_pad(True,False);
end;
//_________________________

procedure Tpad_form.ruler_inch_menu_entryClick(Sender: TObject);

begin
  ruler_units:=2;
  ruler_div:=ROUND(ruler_div/25.4)*25.4;       //  labels in inches.
  if ruler_div<1 then ruler_div:=1;            //  1mm prevent neg or zero.
  redraw_pad(True,False);
end;
//_____________________________________________________________________________________

procedure Tpad_form.mouse_options_menu_entryClick(Sender: TObject);   // 217b now toggle

begin
  if full_draw=True then set_full_mouse_draw_menu_entry.Checked:=True       // radio item.
                    else set_skeleton_mouse_draw_menu_entry.Checked:=True;  // radio item.
end;
//______________________________________________________________________________________

procedure Tpad_form.omit_rails_joints_menu_entryClick(Sender: TObject);

begin
  rail_options_form.Show;          // 206b
end;
//______________________________________________________________________________

procedure Tpad_form.grid_25mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=25;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_50mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=50;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_100mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=100;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_150mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=150;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_250mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=250;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_300mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=300;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_500mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=500;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_1000mm_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=6; // mm
  grid_spacex:=1000;
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_3in_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=2;      // inches
  grid_spacex:=3*25.4;        // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_4in_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=2;      // inches
  grid_spacex:=4*25.4;        // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_6in_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=2;      // inches
  grid_spacex:=6*25.4;        // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_9in_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=2;      // inches
  grid_spacex:=9*25.4;        // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_1ft_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=1;      // feet
  grid_spacex:=304.8;         // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_3ft_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=1;      // feet
  grid_spacex:=3*304.8;       // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_4ft_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=1;      // feet
  grid_spacex:=4*304.8;       // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_12proto_ft_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=3;      // proto-feet
  grid_spacex:=12*scale;      // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.grid_100proto_ft_spacing_menu_entryClick(Sender: TObject);

begin
  grid_labels_code_i:=3;      // proto-feet
  grid_spacex:=100*scale;     // convert to mm
  grid_spacey:=grid_spacex;

  if ruler_units=0 then update_ruler_div;   // 0.93.a  ruler as grid option

  redraw_pad(True,False);
end;
//__________________________

procedure Tpad_form.pad_background_options_menu_entryClick(Sender:TObject);

begin
  if show_spacing_rings=True then show_rings_menu_entry.Checked:=True
                             else hide_rings_menu_entry.Checked:=True;   // radio item - setting False doesn't work the others.

  toggle_bgnd_templates_menu_entry.Checked:=show_bgnd_templates;
  toggle_group_templates_menu_entry.Checked:=show_group_templates;
  toggle_brick_templates_menu_entry.Checked:=show_brick_templates;
end;
//_______________________________________________________________________________________

procedure Tpad_form.extend_shorten_to_boundary_popup_entryClick(Sender: TObject);   // 213b

var
  bg_pt,bg_hd,bg_rp:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  bg_pt:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_plain_track;
  bg_hd:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_half_diamond;
  bg_rp:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_retpar;        // parallel crossing

  meet_at_ctrl0_popup_entry.Enabled:=  (NOT bg_hd);
  meet_at_ctrl6_popup_entry.Enabled:=  (NOT bg_pt);
  meet_at_tminp_popup_entry.Enabled:=  (NOT bg_pt);
  meet_at_texitp_popup_entry.Enabled:= (NOT bg_pt);
  meet_at_mminp_popup_entry.Enabled:=  (NOT bg_pt);      // 217a
  meet_at_mexitp_popup_entry.Enabled:= (NOT bg_pt);      // 217a 
  meet_at_tolp_popup_entry.Enabled:=   (NOT bg_pt) and bg_rp;
end;
//______________________________________________________________________________

procedure Tpad_form.shorten_to_nearest_boundary_popup_entryClick(Sender:TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,-1,False,False);   // in math2 unit  -1 = at nearest   False = shorten, don't ignore errors

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.extend_to_nearest_boundary_popup_entryClick(Sender: TObject);   // 213b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,-1,True,False);   // in math2 unit  -1 = at nearest   True = extend

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_ctrl0_popup_entryClick(Sender: TObject);   // 213b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,0,True,False);   // in math2 unit  0 = at CTRL-0   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_ctrl6_popup_entryClick(Sender: TObject);   // 213b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,6,True,False);   // in math2 unit  6 = at CTRL-6   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_ctrl9_popup_entryClick(Sender: TObject);   // 213b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,9,True,False);   // in math2 unit  9 = at CTRL-9   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_tminp_popup_entryClick(Sender: TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,240,True,False);   // in math2 unit  240 = at TMINP   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_texitp_popup_entryClick(Sender: TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,241,True,False);   // in math2 unit  241 = at TEXITP   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_mminp_popup_entryClick(Sender: TObject);       // 217a

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,260,True,False);   // in math2 unit  260 = at MMINP   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_mexitp_popup_entryClick(Sender: TObject);     // 217a

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,261,True,False);   // in math2 unit  261 = at MEXITP   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.meet_at_tolp_popup_entryClick(Sender: TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  extend_to_boundary(clicked_keep_index,600,True,False);   // in math2 unit  600 = at TOLP   True ignored

  clicked_keep_index:=-1;    // so can popup again.

  do_rollback:=True;
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.extend_shorten_help_popup_entryClick(Sender: TObject);  // 214a

begin
  companion_help('extend_shorten_to_meet.php');
end;
//______________________________________________________________________________

procedure Tpad_form.snap_to_bgnd_peg_popup_entryClick(Sender: TObject);

                 // !!!background!!! peg    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if both on Ctrl-0, or neither, this is facing-to-facing or trailing-to-trailing. Otherwise facing-to-trailing.

    facing_to_trailing:=((bgnd_peg_on_zero=True) xor (peg_code=0));

    snap_current_to_bgnd(snap_peg_positions.ctrl_peg_now_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//_________________________________________________________________________________________

procedure Tpad_form.snap_to_ctrl0_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-0    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if both on Ctrl-0, or neither, this is facing-to-facing or trailing-to-trailing. Otherwise facing-to-trailing.

    facing_to_trailing:=(peg_code<>0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_0_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl1_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-1    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_1_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________

procedure Tpad_form.snap_to_ctrl2_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-2    // 205c
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_2_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________

procedure Tpad_form.snap_to_planing_popup_entryClick(Sender: TObject);

                 // !!!background!!! end of planing    // 205e
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_planing_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________

procedure Tpad_form.snap_to_heel_popup_entryClick(Sender: TObject);

                 // !!!background!!! switch heel    // 205e
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=True; // 217a (peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_heel_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________

procedure Tpad_form.snap_to_ctrl3_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-3    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_3_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_cesp_popup_entryClick(Sender: TObject);

                 // !!!background!!! CESP    // 205e
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_cesp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//___________________________

procedure Tpad_form.snap_to_ctrl4_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-4    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_4_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_tcp_popup_entryClick(Sender: TObject);

                 // !!!background!!! TCP       // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    facing_to_trailing:=False;  // 0.82.a  better for slip switches

    snap_current_to_bgnd(snap_peg_positions.ctrl_tcp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_mcp_popup_entryClick(Sender: TObject);

                 // !!!background!!! MCP       // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    facing_to_trailing:=False;  // 0.82.a  better for slip switches

    snap_current_to_bgnd(snap_peg_positions.ctrl_mcp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl5_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-5    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_5_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl6_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-6    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_6_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_tminp_popup_entryClick(Sender: TObject);

                 // !!!background!!! TMINP   213b
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_tminp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_texitp_popup_entryClick(Sender: TObject);

                 // !!!background!!! TEXITP   213b
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_texitp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_mminp_popup_entryClick(Sender: TObject);

                 // !!!background!!! MMINP   217a
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_mminp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_mexitp_popup_entryClick(Sender: TObject);

                 // !!!background!!! MEXITP   217a
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_mexitp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl7_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-7    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_7_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl8_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-8    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_8_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_ctrl9_popup_entryClick(Sender: TObject);

                 // !!!background!!! ctrl-9    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_9_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_tolp_popup_entryClick(Sender: TObject);

                 // !!!background!!! TOLP    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_tolp_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//____________________________

procedure Tpad_form.snap_to_user_defined_popup_entryClick(Sender: TObject);

                 // !!!background!!! TOLP    // 0.79.a  27-05-06
var
  facing_to_trailing:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

      // if control template peg is on Ctrl-0, this is facing-to-trailing. Otherwise trailing-to-trailing.

    facing_to_trailing:=(peg_code=0);

    snap_current_to_bgnd(snap_peg_positions.ctrl_user_pos,facing_to_trailing);
  end;//with

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.peg_on_tolp_menu_entryClick(Sender: TObject);   // turnout road opposite length (end of main road).

   //   0.79.a  29-05-06

begin
  if plain_track=True then EXIT;  // ??? menu should be disabled.

  cancel_adjusts(False);
  peg_on_rail9_menu_entry.Click;           // turnout-road centre-line (sets peg_code=20, so do first),

  peg_code:=600;                           // then set it.
  peg_indicator_panel.Caption:='N';
  redraw(True);
end;
//______________________________________________________________________________________

procedure Tpad_form.peg_on_blanked_length_menu_entryClick(Sender: TObject);   //  0.82.a

       // 0.82.a  14-10-06

begin
  //if plain_track=True then EXIT;  // ??? menu should be disabled.    out 234e

  cancel_adjusts(False);
  peg_on_rail8_menu_entry.Click;                // main-road centre-line (sets peg_code=20, so do first),

  peg_code:=610;                                // then set it.
  peg_indicator_panel.Caption:='3';             // show him 3
  redraw(True);
end;
//___________________________________________________________________________________________

procedure Tpad_form.no_f7_snapping_menu_entryClick(Sender: TObject);

begin
  no_f7_snapping_menu_entry.Checked:=True;  // radio item   218a
end;
//______________________________________________________________________________

procedure Tpad_form.snap_on_background_templates_menu_entryClick(Sender: TObject);

begin
  snap_on_background_templates_menu_entry.Checked:=True;  // radio item   218a
end;
//______________________________________________________________________________

procedure Tpad_form.snap_always_on_background_templates_menu_entryClick(Sender: TObject);

begin
  snap_always_on_background_templates_menu_entry.Checked:=True;  // radio item   218a
end;
//______________________________________________________________________________

procedure Tpad_form.set_snap_proximity_menu_entryClick(Sender: TObject);

const
  snap_help_str:string='    F7  Shift  Snap  Proximity'
  +'||Enter a dimension in equivalent prototype INCHES for the snap proximity limit when using the F7 SHIFT mouse action.'
  +'||When the F7 mouse action is released, if a free end of the control template is within this distance from an end position on a background template,'
  +' the control template will be snapped into alignment with the background template.'
  +'||The default setting is the scale equivalent of 36 inches. If this dimension is increased too far, Templot may be unable to differentiate between the turnout-road and main-road exit positions.'
  +'||For more complex alignment tasks, use instead the full range of peg and notch functions.';

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(snap_help_str,2,'F7  snap  proximity  limit  ( prototype  equivalent )',snap_proximity_limit,True,True,False,False);   // no negative, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('F7  snap  proximity  limit','',pad_form,n,od)=True
     then snap_proximity_limit:=od[0];
end;
//_______________________________________________________________________________________

procedure Tpad_form.snap_to_background_popup_entryClick(Sender: TObject);

var
  bg_pt,bg_hd,bg_regular:boolean;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  bg_pt:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_plain_track;
  bg_hd:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_half_diamond;

  bg_regular:=(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_xing_type=0);

  if bg_pt=True then snap_to_ctrl1_popup_entry.Caption:='1   to  CTRL-&1   rail  joint'
                else snap_to_ctrl1_popup_entry.Caption:='1   to  CTRL-&1   switch  front';

  snap_to_ctrl1_popup_entry.Enabled:=                   (NOT bg_hd);
  snap_to_ctrl2_popup_entry.Enabled:=   (NOT bg_pt) and (NOT bg_hd);
  snap_to_planing_popup_entry.Enabled:= (NOT bg_pt) and (NOT bg_hd);   // 205e
  snap_to_heel_popup_entry.Enabled:=    (NOT bg_pt) and (NOT bg_hd);   // 205e
  snap_to_ctrl3_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_cesp_popup_entry.Enabled:=    (NOT bg_pt) and bg_regular;    // 205e
  snap_to_ctrl4_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_tcp_popup_entry.Enabled:=     (NOT bg_pt);
  snap_to_mcp_popup_entry.Enabled:=     (NOT bg_pt);
  snap_to_ctrl5_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_ctrl6_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_ctrl7_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_ctrl8_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_ctrl9_popup_entry.Enabled:=   (NOT bg_pt);
  snap_to_tolp_popup_entry.Enabled:=    (NOT bg_pt);

  snap_to_tminp_popup_entry.Enabled:=    (NOT bg_pt);    // 213b
  snap_to_texitp_popup_entry.Enabled:=   (NOT bg_pt);    // 213b

  snap_to_mminp_popup_entry.Enabled:=    (NOT bg_pt);
  snap_to_mexitp_popup_entry.Enabled:=   (NOT bg_pt);

end;
//______________________________________________________________________________

procedure Tpad_form.move_peg_on_background_template_popup_entryClick(Sender: TObject);   // added 205c

var
  bg_pt,bg_hd,bg_regular:boolean;
  old_peg_code:integer;

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  bg_pt:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_plain_track;
  bg_hd:=Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_half_diamond;

  bg_regular:=(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_xing_type=0);

  old_peg_code:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.transform_info.peg_point_code;

  if bg_pt=True then move_to_ctrl1_popup_entry.Caption:='1   to  CTRL-&1   rail  joint'
                else move_to_ctrl1_popup_entry.Caption:='1   to  CTRL-&1   switch  front';

  move_to_ctrl0_popup_entry.Enabled:=                   (old_peg_code<>0);
  move_to_ctrl1_popup_entry.Enabled:=                   (old_peg_code<>1)   and (NOT bg_hd);
  move_to_ctrl2_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>2)   and (NOT bg_hd);
  move_to_planing_popup_entry.Enabled:= (NOT bg_pt) and (old_peg_code<>100) and (NOT bg_hd);   // 205e
  move_to_heel_popup_entry.Enabled:=    (NOT bg_pt) and (old_peg_code<>104) and (NOT bg_hd);   // 205e
  move_to_ctrl3_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>3);
  move_to_cesp_popup_entry.Enabled:=    (NOT bg_pt) and (old_peg_code<>108) and bg_regular;    // 205e
  move_to_ctrl4_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>4);
  move_to_tcp_popup_entry.Enabled:=     (NOT bg_pt) and (old_peg_code<>5);
  move_to_mcp_popup_entry.Enabled:=     (NOT bg_pt) and (old_peg_code<>8);
  move_to_ctrl5_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>6);
  move_to_ctrl6_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>18);
  move_to_ctrl7_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>9);
  move_to_ctrl8_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>17);
  move_to_ctrl9_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>11);
  move_to_tolp_popup_entry.Enabled:=    (NOT bg_pt) and (old_peg_code<>600);

  move_to_tminp_popup_entry.Enabled:=    (NOT bg_pt) and (old_peg_code<>240);
  move_to_texitp_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>241);

  move_to_mminp_popup_entry.Enabled:=    (NOT bg_pt) and (old_peg_code<>260);
  move_to_mexitp_popup_entry.Enabled:=   (NOT bg_pt) and (old_peg_code<>261);

  move_to_user_defined_popup_entry.Enabled:=            (old_peg_code<>999);
end;
//______________________________________________________________________________

procedure Tpad_form.pad_reload_recent_file_menu_entryClick(Sender: TObject);

begin
  keep_form.reload_recent_file_menu_entry.Click;
end;
//_________________________________________

procedure Tpad_form.pad_add_recent_file_menu_entryClick(Sender: TObject);

begin
  keep_form.add_recent_file_menu_entry.Click;
end;
//_______________________________________________________________________________________

procedure Tpad_form.f7_snap_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  if Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.disable_f7_snap=True
     then disable_f7_snap_popup_entry.Checked:=True
     else enable_f7_snap_popup_entry.Checked:=True;   // radio items.
end;
//__________________________________________

procedure Tpad_form.enable_f7_snap_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.disable_f7_snap:=False;

  save_done:=False;         // file change.
  backup_wanted:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//__________________________________________

procedure Tpad_form.disable_f7_snap_popup_entryClick(Sender: TObject);

begin
  if (keeps_list.Count<1) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) then EXIT;

  list_position:=clicked_keep_index;

  Ttemplate(keeps_list.Objects[list_position]).template_info.keep_dims.box_dims1.disable_f7_snap:=True;

  save_done:=False;         // file change.
  backup_wanted:=True;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);    // to hide the highlighting.
end;
//_____________________________________________________________________________________

procedure Tpad_form.make_slip_road_menu_itemClick(Sender: TObject);

                   // 0.82.a

begin
  if plain_track=True
     then begin
            alert(6,'    make  slip  road  -  plain  track',
                    'The control template is plain track.'
                   +'||It is not meaningful to make a slip road from a plain track template. The control template must be a turnout.'
                   +'||Select the TEMPLATE > INSERT TURNOUT IN PLAIN TRACK or TEMPLATE > QUICK SET... menu items, or copy an existing background template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'    make  slip  road  -  half-diamond',
                    'The control template is a half-diamond.'
                   +'||It is not meaningful to make a slip road from a half-diamond template. The control template must be a turnout.'
                   +'||Select the TEMPLATE > CONVERT HALF-DIAMOND TO TURNOUT or TEMPLATE > QUICK SET... menu items, or copy an existing background template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if check_control_template_is_valid('slip  road')=False then EXIT;  // 0.93.a  zero length

  do_rollback:=False;  // while pegging.

      // reduce turnout to switch only...

      // DON'T do retain_on_make !!! need to retain hd timbers, check rails.

  clear_shovedata;     // clear any shoved timbers.

  clear_check_diffs;   // 0.94.a clear any check rail diffs

  no_timbering_menu_entry.Click;

  turnoutx:=plox/COS(k1)+2*inscale;  // on end of switch planing.     215a 2" overlap for neater result for the rails
  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;

  turnout_i:=1;      // length locked at new turnoutx. 0.91.b (was missing = bug)

  startx:=setx-9*inscale;    // blank up to toe. allow 9" for any joggle (arbitrary).

  peg_on_planing_menu_entry.Enabled:=True;    // 215a

  peg_on_planing_menu_entry.Click;     // put the peg on end of planing.

  gocalc(0,0);

  store_and_background(False,False);   // keep it and copy to background.
  if keep_added=False then EXIT;       // he cancelled.

  do_rollback:=False;
  new_notch(get_peg_for_notch,False);

  notch_angle:=notch_angle+Pi;  // pegging Ctrl-1 on slip road means trailing-to-trailing.

            // now change to straight plain track...

  nomrad:=max_rad;
  spiral:=False;

  if slewing=True then disable_slewing_menu_entry.Click;

  plain_track:=True;
  set_plain_track(True,True);

  xorg:=45*scale;        // length of slip road 45ft arbitrary.
  turnoutx:=xorg;

  do_rollback:=False;
  peg_on_joint_end_menu_entry.Click;   // to Ctrl-1

  gocalc(0,0); //redraw_pad(False,False);             // force a recalc for the peg.

  shift_onto_notch(False,False);       // finally join slip road onto switch.

  do_rollback:=False;

  show_and_redraw(True,False);   // in case copy caused a current hide.

  clear_current_name;

  rail_options_form.restore_all_button.Click;  // 211c

  redraw_pad(True,True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.show_name_labels_menu_entryClick(Sender: TObject);  // 209c

begin
  hide_name_labels:=False;
  show_name_labels_menu_entry.Checked:=True;  // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_name_labels_menu_entryClick(Sender: TObject);

   // 209c mods          0.82.b  16-10-06

begin
  hide_name_labels:=True;
  hide_name_labels_menu_entry.Checked:=True;  // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.show_template_symbols_menu_entryClick(Sender: TObject);   // 227a

begin
  show_template_symbols_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_template_symbols_menu_entryClick(Sender: TObject);   // 227a

begin
  hide_template_symbols_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.show_reminders_menu_entryClick(Sender: TObject);    // 216a

begin
  show_reminders_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_reminders_menu_entryClick(Sender: TObject);

begin
  hide_reminders_menu_entry.Checked:=True;     // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.printed_element_options_menu_entryClick(Sender: TObject);

    // 0.82.b

begin
  do_show_modal(print_settings_form);     // 212a  ShowModal   print_settings_form.ShowModal;
end;
//_________________________________________________________________________________________

procedure Tpad_form.roll_match_ctrl0_menu_entryClick(Sender: TObject);

begin
  match_rolled_lengths(0);
end;
//_____________________________________________________________________________________

procedure Tpad_form.roll_match_ctrl1_menu_entryClick(Sender: TObject);

begin
  match_rolled_lengths(1);
end;
//_____________________________________________________________________________________

procedure Tpad_form.gen_platforms_trackbed_edges_menu_entryClick(Sender: TObject);

   // 0.93.a mods

begin
  gen_platforms_trackbed_edges_menu_entry.Checked:= NOT gen_platforms_trackbed_edges_menu_entry.Checked;    // toggle_flag
  gen_platforms:=gen_platforms_trackbed_edges_menu_entry.Checked;
  railedges(gauge_faces,outer_edges,centre_lines);
  redraw(True);
end;
//____________________________________________________________________________________

procedure Tpad_form.gen_inner_foot_edges_menu_entryClick(Sender: TObject);

  // 0.94.a   FB kludge ...

begin
  gen_inner_foot_edges_menu_entry.Checked:= NOT gen_inner_foot_edges_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.gen_outer_foot_edges_menu_entryClick(Sender: TObject);

  // 0.94.a   FB kludge ...

begin
  gen_outer_foot_edges_menu_entry.Checked:= NOT gen_outer_foot_edges_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.FormMouseWheelDown(Sender:TObject; Shift:TShiftState; MousePos:TPoint; var Handled:Boolean);

var
  scroll:extended;

begin
  Handled:=True;

  if slide_on_store>0  // 206a cancel any unfinished sliding after store
     then begin
            slide_on_store:=0;
            xshift:=stored_xshift;
            yshift:=stored_yshift;
          end;

  if (Shift=[ssShift]) and (panning_form.mouse_wheel_view_checkbox.Checked=True)   // 0.91.c
     then begin
            if panning_form.scroll_option_button.Checked=True
               then panning_form.previous_view_button.Click
               else if panning_form.next_view_button.Enabled=true then panning_form.next_view_button.Click;
            EXIT;
          end;

  if Shift=[ssCtrl]
     then begin
           if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,mouse_wheel_pan_dir+1,False);    // mouse_wheel_pan_dir 0=east/west  2=north/south

            // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            EXIT;
          end;

  if Shift=[ssShift,ssCtrl]
     then begin
            undo_changes_menu_entry.Click;
            EXIT;
          end;

            // pad zooming ... mods 0.97.d ...

  cancel_adjusts(False);

  if (Shift=[ssShift]) and (panning_form.mouse_wheel_view_checkbox.Checked=False)   // zoom fast
     then begin
            if panning_form.scroll_option_button.Checked=True
               then explode_shrink(screenx*normal_explode_jump,False,True)   // zoom out and force redraw. True=mouse wheel.
               else explode_shrink(screenx/normal_explode_jump,False,True);  // zoom in and force redraw. True=mouse wheel.
            EXIT;
          end;

   // no modifier keys...  zoom slow...

  if panning_form.scroll_option_button.Checked=True
     then explode_shrink(screenx*slow_explode_jump,False,True)   // zoom out and force redraw. True=mouse wheel.
     else explode_shrink(screenx/slow_explode_jump,False,True);  // zoom in and force redraw. True=mouse wheel.
end;
//______________________________________________________________________________

procedure Tpad_form.FormMouseWheelUp(Sender:TObject; Shift:TShiftState; MousePos:TPoint; var Handled:Boolean);

var
  scroll:extended;

begin
  Handled:=True;

  if slide_on_store>0  // 206a cancel any unfinished sliding after store
     then begin
            slide_on_store:=0;
            xshift:=stored_xshift;
            yshift:=stored_yshift;
          end;

  if (Shift=[ssShift]) and (panning_form.mouse_wheel_view_checkbox.Checked=True)   // 0.91.c
     then begin
            if panning_form.scroll_option_button.Checked=False
               then panning_form.previous_view_button.Click
               else if panning_form.next_view_button.Enabled=true then panning_form.next_view_button.Click;
            EXIT;
          end;

  if Shift=[ssCtrl]
     then begin
           if panning_form.scroll_option_button.Checked=True
               then scroll:=1.0
               else scroll:=-1.0;

            pan_button_click(scroll,mouse_wheel_pan_dir+2,False);    // mouse_wheel_pan_dir 0=east/west  2=north/south

            // dir= 1=left, 2=right, 3=up, 4=down.   // scroll=-1.0 is paper, +1.0 is scroll.

            EXIT;
          end;

  if Shift=[ssShift,ssCtrl]
     then begin
            redo_changes_menu_entry.Click;
            EXIT;
          end;

            // pad zooming ... mods 0.97.d ...

  cancel_adjusts(False);

  if (Shift=[ssShift]) and (panning_form.mouse_wheel_view_checkbox.Checked=False)   // zoom fast
     then begin
            if panning_form.scroll_option_button.Checked=False
               then explode_shrink(screenx*normal_explode_jump,False,True)   // zoom out and force redraw. True=mouse wheel.
               else explode_shrink(screenx/normal_explode_jump,False,True);  // zoom in and force redraw. True=mouse wheel.
            EXIT;
          end;

   // no modifier keys...  zoom slow...

  if panning_form.scroll_option_button.Checked=False
     then explode_shrink(screenx*slow_explode_jump,False,True)   // zoom out and force redraw. True=mouse wheel.
     else explode_shrink(screenx/slow_explode_jump,False,True);  // zoom in and force redraw. True=mouse wheel.

end;
//______________________________________________________________________________

procedure Tpad_form.orientation_help_menu_entryClick(Sender: TObject);

const
  orientation_help_str:string='    Page  Orientation`6'
  +'||The `0end-run`1 option is the normal setting and corresponds to "landscape" (wide) page outlines on the trackpad (and "portrait" setting for text on the printer).'
  +' This setting is recommended and will be found to be the most convenient in the majority of cases.'
  +'||The `0side-run`1 option corresponds to "portrait" (tall) page outlines on the trackpad (and "landscape" setting for text on the printer).'
  +'||`0Important: For banner printing on roll or z-fold paper, the end-run option is necessary.`3'
  +'||Note that in all cases the top of the printed page corresponds to the left edge of the page outline shown on the trackpad.';

begin
  help(0,orientation_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.align_maintain_length_menu_entryClick(Sender: TObject);

begin
  align_maintain_length_menu_entry.Checked:=True;    // radio item.
end;
//__________________________________

procedure Tpad_form.align_match_length_menu_entryClick(Sender: TObject);

begin
  align_match_length_menu_entry.Checked:=True;    // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.f6_length_fixed_menu_entryClick(Sender: TObject);

begin
  f6_swing_fixed:=False;   // 0.91.b
end;
//__________________________________

procedure Tpad_form.f6_swing_fixed_menu_entryClick(Sender: TObject);

begin
  f6_swing_fixed:=True;    // 0.91.b
end;
//__________________________________

procedure Tpad_form.F6_curving_options_menu_entryClick(Sender: TObject);

begin
  if f6_swing_fixed=True    // 0.91.b
     then f6_swing_fixed_menu_entry.Checked:=True    // radio item.
     else f6_length_fixed_menu_entry.Checked:=True;  // radio item.
end;
//__________________________________

procedure Tpad_form.f6_options_help_menu_entryClick(Sender: TObject);

const
  f6_options_help_str:string='`0    F6  Curving  Options`9'
  +'||These options apply when using the `0F6`2 mouse action to adjust the template curving radius.'

  +'||If the normal `0length fixed`1 menu option is in force, the length of the template will remain constant as the radius changes.'

  +'||green_panel_begintree.gif The template length is measured along the curve, following the track centre-line.green_panel_end'

  +'|If the `0swing angle fixed`1 menu option is in force, the length of the template will be adjusted as the radius changes so that the angle turned along the template remains constant.'
  +' This is a useful option when adjusting a return curve where the main road is straight.'

  +'||If the `0swing angle fixed`1 menu option is in force, and the starting template is `0straight`3, the swing angle will be set to 1:7 RAM (8.13 degrees). This may cause a significant initial change in the template length.'
  +'||To set some other swing angle, click the `0geometry > swing angles (in degrees) ...`1 menu item after curving to the required radius.'

  +'||rp.gif The `0swing angle fixed`1 option applies only when adjusting a template of `0constant radius`3.'
  +' When a `0transition curve`3 template is being adjusted, this option setting is ignored and the template length remains constant.'

  +'||rp.gif Care is needed if the `0swing angle fixed`1 option is applied when adjusting a template containing a `0slew`3, to ensure the result is as intended.'

  +'||To change the option in force click the `0action > F6 curving options >`z menu items.';

begin
  help(0,f6_options_help_str,'');   // 0.91.b
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_entry_straight_menu_entryClick(Sender: TObject);

begin
  if plain_track=True
     then begin
            alert(6,'    adjust  V-Crossing  entry  straight',
                    'Adjust V-Crossing entry straight.'
                   +'||This mouse action applies only to turnout templates and irregular half-diamond templates.'
                   +'||The current control template is plain track.'
                   +'||For plain track use F4 to adjust the length, or F6 to adjust the curving radius.',
                    '','','','','','O K',0);
            EXIT;
          end;

  if (half_diamond=True) and (tradius_is_straight=True)
     then begin
            alert(6,'    adjust  V-crossing  entry  straight',
                    'Adjust V-crossing entry straight.'
                   +'||This mouse action applies only to turnout templates and irregular half-diamond templates.'
                   +'||The current control template is a regular half-diamond.'
                   +'||To maintain as a regular half-diamond, use F4 to adjust the length, or F5 to adjust the crossing angles, or F6 to adjust the curving radius.'
                   +'||To change to an irregular half-diamond, use F9 to adjust only the V-crossing angle, or F10 to adjust only the K-crossing angle.',
                    '','','','','','O K',0);
            EXIT;
          end;

  if xing_type_i<>0
     then begin
            alert(6,'    adjust  V-crossing  entry  straight',
                    'Adjust V-crossing entry straight.'
                   +'||This mouse action applies only to `0regular`3 type|V-crossings.'
                   +'||The current V-crossing in the control template is not regular type.'
                   +'||To change the V-crossing type, click the `0real > V-crossing options >`z menu options,'
                   +' or click the green indicator at the top left of the trackpad until it shows <SPAN STYLE="COLOR:GREEN;"><B>R</B></SPAN> .',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);

  if entry_straight_code=0    // currently auto-fit
     then begin
            entry_straight_code:=1;  // change to non-auto-fit sl
            fixed_sl:=sl;            // init as existing.
          end;

  mouse_action_selected('SHIFT-F11    adjust  V-crossing  entry  straight ...','SHIFT-F11  V-crossing  entry  straight',captext(fixed_sl)+' mm');

  entry_straight_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_gaunt_offset_menu_entryClick(Sender: TObject);

var
  i:integer;
  str:string;

begin
  if (plain_track=True) or (half_diamond=True)
     then begin
            if half_diamond=True then str:=' |    •  half-diamond'
                                 else str:=' |    •  plain track';

            alert(6,'    adjust  gaunt  offset',
                   str
                   +'||The control template is not a turnout template.'
                   +'||Only a turnout can be gaunt.| ',
                    '','','','','cancel','',0);
            EXIT;
          end;

   if gaunt=False
     then begin
            i:=alert(2,'    adjust  gaunt  offset',
                       ' |The control template is not a gaunt turnout.| ',
                       '','','','convert  to  a  gaunt  turnout  and  adjust  offset     ','cancel','more  information',0);
            if i=5 then EXIT;

            if i=6
               then begin
                      gaunt_help_menu_entry.Click;
                      EXIT;
                    end;

            convert_to_or_from_gaunt(True);

            redraw_pad(False,True);
          end;

  cancel_adjusts(True);

  action_panel_hint('adjust V-crossing angle instead'); // 205c

  mouse_action_selected('SHIFT-F12    adjust  gaunt  offset ...','SHIFT-F12  gaunt  offset',captext(gaunt_offset_in)+'  inches full-size');
  gaunt_offset_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_gaunt_radius_menu_entryClick(Sender: TObject);

var
  i:integer;
  str:string;

begin
  if (plain_track=True) or (half_diamond=True)
     then begin
            if half_diamond=True then str:=' |    •  half-diamond'
                                 else str:=' |    •  plain track';

            alert(6,'    adjust  gaunt  radius',
                   str
                   +'||The control template is not a turnout template.'
                   +'||Only a turnout can be gaunt.| ',
                    '','','','','cancel','',0);
            EXIT;
          end;

   if gaunt=False
     then begin
            i:=alert(2,'    adjust  gaunt  radius',
                       ' |The control template is not a gaunt turnout.| ',
                       '','','','convert  to  a  gaunt  turnout  and  adjust  radius     ','cancel','more  information',0);
            if i=5 then EXIT;

            if i=6
               then begin
                      gaunt_help_menu_entry.Click;
                      EXIT;
                    end;

            convert_to_or_from_gaunt(True);

            redraw_pad(False,True);
          end;

  cancel_adjusts(True);

  action_panel_hint('adjust V-crossing angle instead'); // 205c

  gaunt_curvature:=1/(tradius-g/2);

  mouse_action_selected('    adjust  gaunt  radius ...','gaunt  turnout  radius',captext(tradius-g/2{1/gaunt_curvature})+' mm');
  gaunt_radius_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.allow_left_drag_panning_menu_entryClick(Sender: TObject);

begin
  allow_left_drag_panning_menu_entry.Checked:= NOT allow_left_drag_panning_menu_entry.Checked;  // 0.91.c
end;
//______________________________________________________________________________

procedure Tpad_form.delete_group_menu_entryClick(Sender: TObject);   // 0.91.c

begin
  keep_form.delete_group_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.save_group_menu_entryClick(Sender: TObject);     // 0.91.c

begin
  keep_form.save_group_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.pad_wipe_group_menu_entryClick(Sender: TObject);  // added 209c

begin
  keep_form.wipe_group_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.restore_group_labels_menu_entryClick(Sender: TObject);

    // 0.91.c

var
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if group_selected=False then CONTINUE;

      with template_info.keep_dims.box_dims1 do begin
        mod_text_x:=0;
        mod_text_y:=0;
      end;//with
    end;//with
  end;//for

  save_done:=False;         // moved the label position.
  backup_wanted:=True;
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.grid_in_front_of_shapes_menu_entryClick(Sender: TObject);   // 0.91.c

begin
  bgnd_form.trackpad_grid_in_front_checkbox.Checked:= NOT bgnd_form.trackpad_grid_in_front_checkbox.Checked;
  grid_in_front_of_shapes_menu_entry.Checked:=bgnd_form.trackpad_grid_in_front_checkbox.Checked;

  do_rollback:=False;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.output_detail_mode_menu_entryClick(Sender: TObject);

   // 0.91.d

begin
  output_detail_mode_menu_entry.Checked:=True;           // radio item
  output_diagram_mode:=False;
end;
//_______________________

procedure Tpad_form.output_diagram_mode_menu_entryClick(Sender: TObject);

   // 0.91.d

begin
  output_diagram_mode_menu_entry.Checked:=True;  // radio item
  output_diagram_mode:=True;
end;                                                           
//______________________________________________________________________________

procedure Tpad_form.omit_output_boundaries_menu_entryClick(Sender: TObject);

begin
  omit_output_boundaries_menu_entry.Checked:=True;  // radio item
  output_include_boundaries:=False;
end;
//_________________________

procedure Tpad_form.include_output_boundaries_menu_entryClick(Sender: TObject);

begin
  include_output_boundaries_menu_entry.Checked:=True;  // radio item
  output_include_boundaries:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.omit_output_trackbed_edges_menu_entryClick(Sender: TObject);      // 217a

begin
  omit_output_trackbed_edges_menu_entry.Checked:=True;  // radio item
  output_include_trackbed_edges:=False;
end;
//_____________________________

procedure Tpad_form.include_output_trackbed_edges_menu_entryClick(Sender: TObject);   // 217a

begin
  include_output_trackbed_edges_menu_entry.Checked:=True;  // radio item
  output_include_trackbed_edges:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.output_show_points_menu_entryClick(Sender: TObject);

begin
  output_show_points_menu_entry.Checked:= NOT output_show_points_menu_entry.Checked;
  output_show_points_mark:=output_show_points_menu_entry.Checked;
end;
//______________________________________________________________________________
(* OT2024

procedure Tpad_form.sketchboard_buttonClick(Sender: TObject);  // SpeedButton

const
  go_sb_help_str:string='Sorry, the sketchboard help notes are not yet available.';

var
  i:integer;

begin

  if FileExists(exe_str+'dpi_yes.txt')=True     // 211b
     then begin
            if alert(2,'php/970    screen  scaling  virtualized',
                       'You have previously changed the screen scaling to the old-style Windows virtualization method.'
                      +'||The sketchboard functions are not available when using this method.',
                       '','','','','cancel','change  back  to  high-definition  screen  scaling',0)=6

               then control_room_form.screen_scaling_menu_entry.Click;

            EXIT;
          end;

  i:=2; // init

  if go_sketchboard=False
     then begin
            repeat
              i:=alert(7,'php/500    sketchboard  start-up',
                         'Please choose a start-up option for the sketchboard.'
                        +'||              Not sure?  -  click the <SPAN STYLE="COLOR:#008000;">green</SPAN> bar.'
                        +'||(If you are creating a mimic control panel or signal box diagram, you may find it preferable to start with an empty sketchboard.)',
                         'more  information','more  about  creating  control  panels','start  with  empty  sketchboard','reload  an  existing  sketchboard  file','cancel','new  drawing  with  current  trackplan',1);
              case i of

                1: alert_help(0,go_sb_help_str,'');

                2: more_info(570);

                3: begin
                     sb_lock_menu_entry.Click;
                     go_sketchboard:=True;
                   end;

                4: begin
                     sb_lock_menu_entry.Click;
                     go_sketchboard:=True;
                   end;

                5: EXIT;

                6: go_sketchboard:=True;

                else run_error(66);
              end;//case
            until i>2;
          end;

  dtp_form.Show;
  dtp_form.BringToFront;

  dtp_settings_form.Show;
  dtp_settings_form.BringToFront;

  dtp_form.SetFocus;

  Application.ProcessMessages;

  if i=4 then dtp_form.load_dtp_menu_entry.Click;

end;
//______________________________________________________________________________
*)

procedure Tpad_form.write_reminder_menu_entryClick(Sender: TObject);

begin
  control_room_form.reminder_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.print_help_menu_entryClick(Sender: TObject);

var
  help_str:string;

begin
  print_now_form.print_data_sent_label.Hide;
  print_now_form.Hide;

  help_str:='php/280    `0Print and  Output  Functions`9'
  +'||The `0print-now!`3 functions print immediately to your current printer using your current settings. These rapid printing functions are provided for your convenience.'
  +'||For the normal print preview and setup functions, and the full printing and output options and settings, please click the `0output`1 menu items instead:'
  +'||<IMG SRC="'+exe_str+'internal\hlp\output_menu.png">'
  +'||For more information please click <A HREF="online_ref280.85a">more information online</A>.';

  if help(0,help_str,'more  about  printing  templates')=1 then print_form.help_button.Click;

end;
//______________________________________________________________________________

procedure Tpad_form.print_control_now_menu_entryClick(Sender:TObject);

begin
  print_now_bang:=True;
  print_control_template_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.print_entire_pad_now_menu_entryClick(Sender: TObject);

begin
  if any_bgnd<1
     then begin
            alert_no_bgnd;
            EXIT;            // no background templates
          end;

  print_now_bang:=True;
  print_entire_pad_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.print_group_now_menu_entryClick(Sender: TObject);

begin
  print_now_bang:=True;
  print_group_only_menu_entry.Click;
end;
//______________________________________________________________________________
(* OT2024

procedure Tpad_form.sb_auto_add_menu_entryClick(Sender: TObject);

begin
  with dtp_settings_form do begin
    auto_add_radiobutton.Checked:=True;

    auto_update_diagram_checkbox.Enabled:=True;
    manual_add_update_checkbox.Enabled:=False;
    manual_add_diagram_checkbox.Enabled:=False;

    add_dragged_trackplan_button.Enabled:=False;
    add_full_page_trackplan_button.Enabled:=False;
  end;//with

  sb_auto_add_menu_entry.Checked:=True;  // radio item

  auto_update_diagram_menu_entry.Enabled:=True;
  manual_add_update_menu_entry.Enabled:=False;
  manual_add_diagram_menu_entry.Enabled:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_manual_add_menu_entryClick(Sender: TObject);

begin
  with dtp_settings_form do begin
    manual_add_radiobutton.Checked:=True;

    auto_update_diagram_checkbox.Enabled:=False;
    manual_add_update_checkbox.Enabled:=True;
    manual_add_diagram_checkbox.Enabled:=True;

    add_dragged_trackplan_button.Enabled:=True;
    add_full_page_trackplan_button.Enabled:=True;
  end;//with

  sb_manual_add_menu_entry.Checked:=True;  // radio item

  auto_update_diagram_menu_entry.Enabled:=False;
  manual_add_update_menu_entry.Enabled:=True;
  manual_add_diagram_menu_entry.Enabled:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_lock_menu_entryClick(Sender: TObject);

begin
  with dtp_settings_form do begin
    lock_radiobutton.Checked:=True;

    auto_update_diagram_checkbox.Enabled:=False;
    manual_add_update_checkbox.Enabled:=False;
    manual_add_diagram_checkbox.Enabled:=False;

    add_dragged_trackplan_button.Enabled:=False;
    add_full_page_trackplan_button.Enabled:=False;
  end;//with

  sb_lock_menu_entry.Checked:=True;  // radio item

  auto_update_diagram_menu_entry.Enabled:=False;
  manual_add_update_menu_entry.Enabled:=False;
  manual_add_diagram_menu_entry.Enabled:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_include_grid_menu_entryClick(Sender:TObject);

begin
  sb_include_grid_menu_entry.Checked:= NOT sb_include_grid_menu_entry.Checked;
  dtp_settings_form.include_grid_checkbox.Checked:=sb_include_grid_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_include_grid_labels_menu_entryClick(Sender:TObject);

begin
  sb_include_grid_labels_menu_entry.Checked:= NOT sb_include_grid_labels_menu_entry.Checked;
  dtp_settings_form.include_grid_labels_checkbox.Checked:=sb_include_grid_labels_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_include_picture_shapes_menu_entryClick(Sender:TObject);

begin
  sb_include_picture_shapes_menu_entry.Checked:= NOT sb_include_picture_shapes_menu_entry.Checked;
  dtp_settings_form.include_picture_shapes_checkbox.Checked:=sb_include_picture_shapes_menu_entry.Checked;

  dtp_settings_form.include_picture_borders_checkbox.Enabled:=dtp_settings_form.include_picture_shapes_checkbox.Checked;  // 205a
end;
//______________________________________________________________________________

procedure Tpad_form.auto_update_diagram_menu_entryClick(Sender:TObject);

begin
  auto_update_diagram_menu_entry.Checked:= NOT auto_update_diagram_menu_entry.Checked;             // toggle
  dtp_settings_form.auto_update_diagram_checkbox.Checked:=auto_update_diagram_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.manual_add_diagram_menu_entryClick(Sender: TObject);

begin
  manual_add_diagram_menu_entry.Checked:= NOT manual_add_diagram_menu_entry.Checked;            // toggle
  dtp_settings_form.manual_add_diagram_checkbox.Checked:=manual_add_diagram_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.manual_add_update_menu_entryClick(Sender:TObject);

begin
  manual_add_update_menu_entry.Checked:= NOT manual_add_update_menu_entry.Checked;
  dtp_settings_form.manual_add_update_checkbox.Checked:=manual_add_update_menu_entry.Checked;
end;
//______________________________________________________________________________
*)

procedure Tpad_form.export_file_menu_entryClick(Sender: TObject);

begin
  export_form.Show;
  export_form.BringToFront;
end;
//______________________________________________________________________________

procedure Tpad_form.output_mode_help_menu_entryClick(Sender: TObject);

begin
  more_info(1050);
end;
//______________________________________________________________________________

procedure Tpad_form.store_bgnd_insert_toolbuttonClick(Sender: TObject);

begin
  cancel_adjusts(False);
  store_and_background_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.rebuild_group_to_match_customize_xing_menu_entryClick(Sender: TObject);  // 214b

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/209    modify  group  to  match  customized  V-crossing  settings',
          'This function will modify the following dimension settings on the selected group of background templates to match the current settings on the control template:'
         +'||blunt nose'
         +'|vee rails'
         +'|wing rails'
         +'|check rails'
         +'||This function is useful when you want to update all or part of the background track plan to correspond with the control template, if custom settings have been entered for the V-crossing.',
          '','','','','cancel','modify  group  to  match  V-crossing  settings',0)=5
     then EXIT;

  his_option:=keep_form.customize_xing_as_stored_menu_entry.Checked;
  keep_form.customize_xing_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.customize_xing_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_group_to_match_min_rad_menu_entryClick(Sender: TObject);

   // 206e

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/208    modify  group  to  match  radius  warning  limit',
          'This function will modify the radius warning limit on the selected group of background templates to match the current setting on the control template.',
          '','','','','cancel','modify  group  to  match  radius  warning  limit',0)=5
     then EXIT;

  his_option:=keep_form.radius_warning_limit_as_stored_menu_entry.Checked;
  keep_form.radius_warning_limit_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.radius_warning_limit_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.rebuild_group_to_match_chairs_menu_entryClick(Sender: TObject);    // 221a

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/219    modify  group  to  match  chair  options',
          'This function will modify the chair options on the selected group of background templates to match the current settings on the control template.',
          '','','','','cancel','modify  group  to  match  chair  options',0)=5
     then EXIT;

  his_option:=keep_form.chair_options_as_stored_menu_entry.Checked;
  keep_form.chair_options_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.chair_options_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_group_to_match_timbering_menu_entryClick(Sender:TObject);   // 212a

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/207    modify  group  to  match  timbering  settings',
          'This function will modify the following timbering settings on the selected group of background templates to match the current settings on the control template:'
         +'||plain-track sleepers length and width'
         +'||turnout timbers length and width'
         +'|turnout timbers length increments setting'
         +'|turnout timber fill spacings'
         +'|turnout timber equalizing and centralizing styles'
         +'||timber randomizing settings'
         +'||This function is useful when you want to update all or part of the background track plan to correspond with the control template, for example if a custom setting has been entered for the sleeper length.',
          '','','','','cancel','modify  group  to  match  timbering  settings',0)=5
     then EXIT;

  his_option:=keep_form.timbering_as_stored_menu_entry.Checked;
  keep_form.timbering_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.timbering_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.modify_group_to_match_plain_track_menu_entryClick(Sender: TObject);        // 214c

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/207    modify  group  to  match  plain  track  rail  lengths',
          'This function will modify the plain track rail lengths and sleeper spacing settings on the selected group of background templates to match the current settings on the control template.'
         +'||This function is useful when you want to update all or part of the background track plan to correspond with the control template, for example if a custom setting has been entered for the rail length.',
          '','','','','cancel','modify  group  to  match  rail  length  settings',0)=5
     then EXIT;

  his_option:=keep_form.plain_track_as_stored_menu_entry.Checked;
  keep_form.plain_track_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.plain_track_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.rebuild_group_to_match_centre_lines_menu_entryClick(Sender:TObject);

   // 0.93.a

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/204    modify  group  to  match  track  centre - lines',
          'This function will modify the track centre-line settings on the selected group of background templates to match the current settings on the control template.',
          '','','','','cancel','modify  group  to  match  track  centre - lines',0)=5
     then EXIT;

  his_option:=keep_form.centre_lines_as_stored_menu_entry.Checked;
  keep_form.centre_lines_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.centre_lines_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.rebuild_group_to_match_rail_section_menu_entryClick(Sender:TObject);

   // 0.94.a

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/206    modify  group  to  match  rail - section  settings',
          'This function will modify the rail-section settings on the selected group of background templates to match the current settings on the control template.',
          '','','','','cancel','modify  group  to  match  rail - section  settings',0)=5
     then EXIT;

  his_option:=keep_form.rail_section_data_as_stored_menu_entry.Checked;
  keep_form.rail_section_data_as_control_menu_entry.Checked:=True;             // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.rail_section_data_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.platform_edges_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);

  if turnoutx=0 then extend_template_from_zero; // 0.93.a

  if Application.Terminated=False then Application.ProcessMessages;

  adjacent_trackbed_platforms_menu_entry.Click;  // cancel adjacent tracks if necessary

  platform_form.Show;
end;
//______________________________________________________________________________

procedure Tpad_form.about_generator_menu_entryClick(Sender: TObject);

var
  i:integer;

begin
  help(0,generator_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.show_notch_menu_entryClick(Sender: TObject);

begin
  show_notch_menu_entry.Checked:=True;  // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.hide_notch_menu_entryClick(Sender: TObject);

begin

  if alert(7,'    hide  notch',
             ' |The pegging notch is a very useful design aid.'
            +'||Hiding it from view will make it difficult or impossible to use some functions.'
            +'||Are you sure you want to hide the notch?| ',
             '','','','','no  -  cancel','yes  -  hide  notch',0)=5
     then EXIT;

  hide_notch_menu_entry.Checked:=True;  // radio item
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.adjacent_trackbed_platforms_menu_entryClick(Sender:TObject);

begin
  adjacent_trackbed_platforms_menu_entry.Checked:=True;  // radio item
  adjacent_edges:=True;

  do_railedges;
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.adjacent_rails_menu_entryClick(Sender: TObject);

begin

  if alert(7,'    adjacent  rails  option',
             'This option shows the rails of adjacent tracks for use as a design guide on the trackpad.'
            +'||The adjacent track spacings are set at|`0GEOMETRY > ADJACENT TRACK CENTRES...`1 menu item.'
            +'||The spacings can also be adjusted by mouse action at `0action > mouse actions: control/geometry > adjacent track centres`1 menu items.'
            +'||While this option is in force it will remove any platforms and/or trackbed edges from this template.'
            +'||They can be restored by clicking the `0GEOMETRY > ADJACENT OPTIONS > TRACKBED EDGES AND PLATFORMS`1 menu option.'
            +'||green_panel_begin tree.gif This option is for use as a design guide on the trackpad only. The adjacent rails do not appear on the output.'
            +'||If such design guides are needed on the output, dummy background templates can be used for the purpose.green_panel_end',
             '','','','','cancel','show  adjacent  rails',0)=5 then EXIT;

  trackbed_form.Hide;  // 215a

  adjacent_rails_menu_entry.Checked:=True;  // radio item
  adjacent_edges:=False;

  do_railedges;
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.adjacent_options_menu_entryClick(Sender: TObject);

begin
  adjacent_trackbed_platforms_menu_entry.Checked:=adjacent_edges;  // radio items.
  adjacent_rails_menu_entry.Checked:= NOT adjacent_edges;
end;
//______________________________________________________________________________


procedure Tpad_form.gaunt_turnout_menu_entryClick(Sender: TObject);

begin
  if gaunt=True then EXIT;
  convert_to_or_from_gaunt(True);
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.normal_non_gaunt_turnout_menu_entryClick(Sender: TObject);

begin
  if gaunt=False then EXIT;
  convert_to_or_from_gaunt(False);
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.gaunt_offset_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;

  dummy:extended;
  old_dp,new_dp:extended;

begin

  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

  old_dp:=dpx-xorg;

  n:=putdim('php/151'+gaunt_offset_help_str,2,'gaunt  offset  ( full-size )',gaunt_offset_in,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('gaunt  offset','',pad_form,n,od)=False then EXIT;

  gaunt_offset_in:=od[0];

    // offset can't exceed the knuckle..

  if gaunt_offset_in>((g-fw-minfp)/inscale) then gaunt_offset_in:=(g-fw-minfp)/inscale;

    // or the entry straight if any (for curviform and generic crossings, th=g)..

  if gaunt_offset_in>((th-minfp)/inscale) then gaunt_offset_in:=(th-minfp)/inscale;

    // negative offset can't go beyond MS centres (arbitrary)...

  gocalc(0,0);              // calc new dpx

  new_dp:=dpx-xorg;         // maintain overall length and V-crossing alignment
  xorg:=xorg+old_dp-new_dp;

  if xorg<0
     then begin
            turnoutx:=turnoutx-xorg;          // increase overall length to keep V-crossing and exit track.
            if spiral=True then os:=os-xorg;
            if slewing=True then slew_s:=slew_s-xorg;
            xorg:=0;
          end;

  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;
  if xorg>turnoutx then xorg:=turnoutx;

  gocalc(0,0);   // recalc to get new pegx, pegy, arm_angle.

  peg_curve;     //  adjust shifts and rotates for current peg position.

  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.gaunt_radius_menu_entryClick(Sender: TObject);    // 217a

var
  n:integer;
  od:Toutdim;

  dummy,gaunt_rad:extended;
  old_dp,new_dp:extended;
  new_gaunt_offset:extended;

begin
  if plain_track=True
     then begin
            alert(6,'php/151    set  gaunt  turnout  radius',
                    'The control template is plain track.'
                   +'||This function applies only to gaunt turnout templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'php/151    set  gaunt  turnout  radius',
                    'The control template is a half-diamond template.'
                    +'||This function applies only to gaunt turnout templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if spiral=True
     then begin
            alert(6,'php/151    set  gaunt  turnout  radius',
                    'The control template contains a transition curve.'
                    +'||It is not possible to use this function on a transition curve template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if xing_calc_i<>1
     then begin
            if alert(2,'php/151    set  gaunt  turnout  radius',
                      'The V-crossing in the control template is not currently curviform.'
                      +'||This function is intended for use with curviform V-crossings only.'
                      +'||Change to curviform ?',
                       '','','','','cancel','change  to  curviform  V - crossing',0)=5 then EXIT;

            curviform_crossing_menu_entry.Click;
            gocalc(0,0);
            redraw(False);
          end;

  if gaunt=False
     then begin
            if alert(2,'php/151    set  gaunt  turnout  radius',
                      'The control template is not currently a gaunt turnout.'
                      +'||Change to a gaunt turnout ?',
                       '','','','','cancel','change  to  gaunt  turnout',0)=5 then EXIT;

            convert_to_or_from_gaunt(True);
            gocalc(0,0);
          end;

  kform_now:=kform;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.

  old_dp:=dpx-xorg;
  gaunt_rad:=tradius;       // to gauge-face

  n:=putdim('php/151'+gaunt_radius_help_str,1,'gaunt  turnout  radius',tradius-g/2,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('gaunt  turnout  radius','',pad_form,n,od)=False then EXIT;

  gaunt_rad:=od[0]+g/2;

  try
    new_gaunt_offset:=gaunt_rad*(COS(k3)-1)+g;
  except
    ShowMessage('Sorry, the entered radius does not fit this template.');
    EXIT;
  end;//try

  if new_gaunt_offset>(g-fw-minfp)     // don't let gaunt_offset_in go out of range.
     then begin
            ShowMessage('Sorry, the entered radius does not fit this template.');
            EXIT;
          end
     else gaunt_offset_in:=new_gaunt_offset/inscale;

  gocalc(0,0);              // calc new dpx

  new_dp:=dpx-xorg;         // maintain overall length and V-crossing alignment
  xorg:=xorg+old_dp-new_dp;

  if xorg<0
     then begin
            turnoutx:=turnoutx-xorg;          // increase overall length to keep V-crossing and exit track.
            if slewing=True then slew_s:=slew_s-xorg;
            xorg:=0;
          end;

  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;
  if xorg>turnoutx then xorg:=turnoutx;

  gocalc(0,0);

  peg_curve;             //  adjust shifts and rotates for current peg position.

  redraw_pad(True,True);
end;
//_______________________________________________________________________________________

procedure Tpad_form.gaunt_sleeper_length_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim('php/151'+gaunt_sleeper_help_str,2,'gauntlet  sleeper  length  modifier  ( full-size )',gaunt_sleeper_mod_in,False,True,False,False);   // negative ok, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('gauntlet  sleeper  length  modifier','',pad_form,n,od)=True
     then gaunt_sleeper_mod_in:=od[0];

  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.gaunt_help_menu_entryClick(Sender: TObject);

begin
  help(0,'php/151'+gaunt_offset_help_str+'|'+gaunt_radius_help_str+'|'+gaunt_sleeper_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.peg_indicator_panelClick(Sender: TObject);

begin
  peg_indicator_click;
end;
//______________________________________________________________________________

procedure Tpad_form.xing_indicator_panelClick(Sender: TObject);

begin
  if xing_type_i=0 then curviform_crossing_menu_entry.Click
                   else regular_crossing_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.xing_indicator_panelContextPopup(Sender:TObject; MousePos:TPoint; var Handled: Boolean);

begin
  crossing_menu_entry.Click;
end;
//______________________________________________________________________________


procedure Tpad_form.adjust_k_crossing_angle_menu_entryClick(Sender: TObject);

begin
  if half_diamond=False
     then begin
            alert(6,'    adjust  K-crossing  angle',
                    'Adjust K-crossing angle.'
                   +'||This mouse action applies only to half-diamond templates.'
                   +'||For a turnout use the F9 ADJUST V-CROSSING ANGLE mouse action to adjust only the V-crossing angle,'
                   +' or the F5 ADJUST SIZE mouse action to adjust both the V-crossing angle and the switch size.',
                    '','','','','','O K',0);
            EXIT;
          end;

  cancel_adjusts(True);

  action_panel_hint('adjust V-crossing angle instead'); // 205c

  mouse_action_selected('F10    adjust  K-crossing  angle ...','F10  K-crossing angle','1 : '+captext(hdkn));
  hdk_mod:=1;
end;
//________________________________________________________________________________________

procedure Tpad_form.adjust_v_crossing_angle_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  if half_diamond=True then action_panel_hint('adjust K-crossing angle instead'); // 205c

  if gaunt=True then action_panel_hint('adjust gaunt turnout radius instead'); // 205c

  mouse_action_selected('F9    adjust  V-crossing  angle ...','F9  V-crossing angle','1 : '+captext(k3n));
  vee_mod:=1;
end;
//_______________________________________________________________________________________

procedure Tpad_form.v_crossing_angle_menu_entryClick(Sender: TObject);

const
  vk_str:string='php/112    `0V - Crossing  Angle`9'
  +'||Enter the required V-crossing angle in RAM units.'
  +'||Do not enter the 1: part. For example to set the V-crossing angle to 1:8, simply enter 8.'
  +'||For more information click the white bar below.';

var
  n:integer;
  od:Toutdim;
  dummy:extended;

begin
  if plain_track=True
     then begin
            if alert(6,'php/112    set  V - crossing  angle',
                       'V-crossings apply only to turnout and half-diamond templates.'
                      +'||The control template is currently plain track.'
                      +'||To work with turnout or half-diamond templates click the TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK menu item.',
                       '','','','more  information','O K  -  cancel','',4)=4 then v_crossings_help_menu_entry.Click;
            EXIT;
          end;

  n:=putdim(vk_str,0,'V - crossing  angle  1: ',k3n,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;

  if getdims('V - crossing  angle',v_xing_angle_help_str,pad_form,n,od)=True
     then begin
            if od[0]<(0.5-minfp)        // 228a
               then begin
                      if alert(6,'php/104    invalid  V - crossing  angle',
                                 'The V-crossing angle cannot be less than 1:0.5  (RAM)',
                                 '','','','','cancel','change  angle  to  1:0.5  and  continue',0)=6
                         then k3n:=0.5
                         else EXIT;
                    end
               else k3n:=od[0];      // angle ok.
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//______________________________________________________________________________

procedure Tpad_form.k_crossing_angle_menu_entryClick(Sender: TObject);

const
  hk_str:string='php/106    `0K - Crossing  Angle`9'
  +'||Enter the required K-crossing angle in RAM units.'
  +'||Do not enter the 1: part. For example to set the K-crossing angle to 1:8, simply enter 8.'
  +'||For more information click the white bar below.';

var
  n:integer;
  od:Toutdim;
  dummy:extended;

begin
  if plain_track=True
     then begin
            if alert(6,'php/106    set  K - crossing  angle',
                       'K-crossings apply only to half-diamond templates.'
                      +'||The control template is currently plain track.'
                      +'||To work with half-diamond templates click the TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK menu item.',
                       '','','','more  information','O K  -  cancel','',4)=4 then k_crossings_help_menu_entry.Click;
            EXIT;
          end;


  if half_diamond=False
     then begin
            if alert(6,'php/105    set  K - crossing  angle',
                       'K-crossings apply only to half-diamond templates.'
                      +'||The control template is currently a turnout template.'
                      +'||To work with half-diamond templates click the TEMPLATE > CONVERT TURNOUT TO HALF-DIAMOND menu item or the TOOLS > MAKE DIAMOND-CROSSING menu item.',
                       '','','','more  information','O K  -  cancel','',4)=4 then k_crossings_help_menu_entry.Click;
            EXIT;
          end;

  n:=putdim(hk_str,0,'K - crossing  angle  1: ',hdkn,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;

  if getdims('K - crossing  angle',helpkck_gen_str,pad_form,n,od)=True
     then begin
            if od[0]<(0.5-minfp)            // 228a ...
               then begin
                      if alert(6,'php/104    invalid  K - crossing  angle',
                                 'The K-crossing angle cannot be less than 1:0.5  (RAM)',
                                 '','','','','cancel','change  angle  to  1:0.5  and  continue',0)=6
                         then hdkn:=0.5

                         else EXIT;
                    end
               else hdkn:=od[0];      // angle ok.
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//______________________________________________________________________________

procedure Tpad_form.k_crossing_radius_menu_entryClick(Sender: TObject);

const
  k_rad_str:string='    `0K - Crossing  Diagonal  Radius`9'
  +'||Enter the required diagonal centre-line radius. This should be the equivalent radius for a straight template before curving.'
  +'||The K-crossing angle will be modified to create the desired radius in the diagonal road of the half-diamond template.'
  +'||The V-crossing angle will not be changed. This means that the half-diamond will become irregular, if it was not before (angles not equal).'
  +'||(If the existing half-diamond is regular (angles equal), the existing radius showing will be very large.)'
  +'||For more information click the white bar below.';

var
  i,n:integer;
  od:Toutdim;
  dummy:extended;

  new_krad:extended;

begin
  if plain_track=True
     then begin
            if alert(6,'    set  K - crossing  diagonal  radius',
                       'K-crossings apply only to half-diamond templates.'
                      +'||The control template is currently plain track.'
                      +'||To work with half-diamond templates click the TEMPLATE > INSERT HALF-DIAMOND IN PLAIN TRACK menu item.',
                       '','','','more  information','O K  -  cancel','',4)=4 then k_crossings_help_menu_entry.Click;
            EXIT;
          end;

  if half_diamond=False
     then begin
            if alert(6,'    set  K - crossing  diagonal  radius',
                       'K-crossings apply only to half-diamond templates.'
                      +'||The control template is currently a turnout template.'
                      +'||To work with half-diamond templates click the TEMPLATE > CONVERT TURNOUT TO HALF-DIAMOND menu item or the TOOLS > MAKE DIAMOND-CROSSING menu item.',
                       '','','','more  information','O K  -  cancel','',4)=4 then k_crossings_help_menu_entry.Click;
            EXIT;
          end;

  if xing_calc_i<>1
     then begin
            repeat
              i:=alert(6,'    set  K - crossing  diagonal  radius',
                       'This function applies only to half-diamond templates having a curviform V-crossing.'
                      +'||The V-crossing in the control template is not currently set to curviform.'
                      +'||Do you want to change it to curviform ?',
                       '','','','more  information','no  -  cancel','yes  -  change  to  curviform  V - crossing',4);

              if i=4 then alert_help(0,helpkck_gen_str,'');

              if i=5 then EXIT;

              if i=6 then begin
                            curviform_crossing_menu_entry.Click;
                            gocalc(0,0);
                          end;

            until i<>4;
          end;

  new_krad:=tradius-g/2;  // init  to centre-line

  n:=putdim(k_rad_str,1,'K - crossing  diagonal  radius',new_krad,False,True,True,False);   // neg ok, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;

  if getdims('K - crossing  diagonal  radius',helpkck_gen_str,pad_form,n,od)=True
     then begin
            try
              new_krad:=od[0]+g/2;                // back to rail gauge-face
              hdk:=ARCCOS(COS(k3)+g/new_krad);
              hdkn:=1/TAN(hdk);
            except
              ShowMessage('Sorry, it has not been possible to set the diagonal radius to '+round_str(new_krad,2)+' mm.');
              EXIT;
            end;//try
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//______________________________________________________________________________

procedure Tpad_form.intersection_centre_lines_popup_entryClick(Sender: TObject);

begin
  do_notch_on_intersection(False,True,0,0,'','');
end;
//______________________________________________________________________________

procedure Tpad_form.intersection_outer_outer_popup_entryClick(Sender: TObject);

begin
  do_notch_on_intersection(False,True,1,1,'','');
end;
//______________________________________________________________________________

procedure Tpad_form.intersection_inner_inner_popup_entryClick(Sender: TObject);

begin
  do_notch_on_intersection(False,True,0-1,0-1,'','');
end;
//______________________________________________________________________________

procedure Tpad_form.intersection_outer_inner_popup_entryClick(Sender: TObject);

begin
  do_notch_on_intersection(False,True,1,0-1,'','');
end;
//______________________________________________________________________________

procedure Tpad_form.intersection_inner_outer_popup_entryClick(Sender: TObject);

begin
  do_notch_on_intersection(False,True,0-1,1,'','');
end;
//______________________________________________________________________________

procedure Tpad_form.make_diamond_crossing_at_intersection_popup_entryClick(Sender:TObject);

begin
  make_diamond_crossing_at_intersection;

  clicked_keep_index:=-1;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.regular_crossing_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  if retpar_i=1 then turnout_road_i:=0;  // changing from parallel, assume long turnout road not now needed.

  xing_type_i:=0;
  retpar_i:=0;

  snap_exit_to_return_curve_menu_entry.Enabled:=False;

  if (peg_code=7) or (peg_code=10)
     then begin
            reset_peg_menu_entry.Click;
            gocalc(0,0);                    // calc new pegx
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//________________________________

procedure Tpad_form.curviform_crossing_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  if retpar_i=1 then turnout_road_i:=0;  // changing from parallel, assume long turnout road not now needed.

  xing_type_i:=1;
  retpar_i:=0;

  snap_exit_to_return_curve_menu_entry.Enabled:=False;

  if (peg_code=7) or (peg_code=10) or (peg_code=108)  // added 205e  108 peg is on CESP
     then begin
            reset_peg_menu_entry.Click;
            gocalc(0,0);                    // calc new pegx
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//________________________________

procedure Tpad_form.generic_crossing_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  if retpar_i=1 then turnout_road_i:=0;  // changing from parallel, assume long turnout road not now needed.

  xing_type_i:=0-1;
  retpar_i:=0;

  generic_was_short_swapped:=False;  // 228a

  snap_exit_to_return_curve_menu_entry.Enabled:=False;

  if (peg_code=7) or (peg_code=10) or (peg_code=108)  // added 205e  108 peg is on CESP
     then begin
            reset_peg_menu_entry.Click;
            gocalc(0,0);                    // calc new pegx
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//________________________________

procedure Tpad_form.parallel_crossing_menu_entryClick(Sender: TObject);

var
  dummy:extended;

begin
  xing_type_i:=0;
  retpar_i:=1;

  cpi.retcent_pi:=cpi.trtscent_pi;   // use TS centres.  bug fix 214a

  turnout_road_i:=1;       // long turnout road needed.
  snap_exit_to_return_curve_menu_entry.Enabled:=True;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

  gocalc(0,0);                                          // recalc to get new pegx, pegy, arm_angle.

  peg_curve;             //  adjust shifts and rotates for current peg position.
  gocalc(0,0);           //  get new arm_angle (peg might be on turnout road).

  rotate_turnout(arm_angle_now-arm_angle,True);        // re-align to previous angle and redraw.
end;
//________________________________

procedure Tpad_form.v_crossing_options_menu_entryClick(Sender: TObject);

    // radio items ...

begin

     // 215a ...

  regular_crossing_menu_entry.Checked:=((xing_calc_i=0) and (retpar_i=0));
  curviform_crossing_menu_entry.Checked:=(xing_calc_i=1);
  generic_crossing_menu_entry.Checked:=(xing_calc_i=(0-1));
  parallel_crossing_menu_entry.Checked:=((xing_calc_i=0) and (retpar_i=1));

end;
//______________________________________________________________________________

procedure Tpad_form.adjust_rectangle_left_edge_menu_entryClick(Sender:TObject);

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  normalize_show_output_rectangle;

  mouse_action_selected('    boundary  rectangle  left  edge ...','boundary rectangle left edge','X : '+captext(output_rectangle_x1)+' mm');
  rect_left_mod:=1;
end;
//__________________________________________

procedure Tpad_form.adjust_rectangle_right_edge_menu_entryClick(Sender:TObject);

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  normalize_show_output_rectangle;

  mouse_action_selected('    boundary  rectangle  right  edge ...','boundary rectangle right edge','X : '+captext(output_rectangle_x2)+' mm');
  rect_right_mod:=1;
end;
//__________________________________________

procedure Tpad_form.adjust_rectangle_top_edge_menu_entryClick(Sender:TObject);

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  normalize_show_output_rectangle;

  mouse_action_selected('    boundary  rectangle  top  edge ...','boundary rectangle top edge','Y : '+captext(output_rectangle_y2)+' mm');
  rect_top_mod:=1;
end;
//__________________________________________

procedure Tpad_form.adjust_rectangle_bottom_edge_menu_entryClick(Sender:TObject);

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  normalize_show_output_rectangle;

  mouse_action_selected('    boundary  rectangle  bottom  edge ...','boundary rectangle bottom edge','Y : '+captext(output_rectangle_y1)+' mm');
  rect_bottom_mod:=1;
end;
//__________________________________________

procedure Tpad_form.move_rectangle_menu_entryClick(Sender: TObject);

begin
  cancel_paper_bunching;         // does a cancel_adjusts if adjust in progress.
  cancel_adjusts(True);

  normalize_show_output_rectangle;

  mouse_action_selected('    move  boundary  rectangle ...','move boundary rectangle','X : '+captext(output_rectangle_x1)+' mm   Y : '+captext(output_rectangle_y1)+' mm');
  rect_move_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.draw_boundary_rectangle_menu_entryClick(Sender:TObject);

  // 0.93.a draw a rectangle for image file output and sketchboard...

begin
  if output_boundary_rectangle=True
     then begin
            output_boundary_rectangle:=False;
            output_rectangle_latching_toolbutton.Down:=False;     // he changed his mind, so toggle.
            pad_caption('');
            Screen.Cursor:=crDefault;
            EXIT;
          end;

  cancel_adjusts(False);
  output_boundary_rectangle:=True;

  if check_grey_paper=False then Screen.Cursor:=cross_hairs_cursor;
  pad_caption('click-drag  output  boundary  rectangle ...');
  output_rectangle_latching_toolbutton.Down:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.clear_boundary_rectangle_menu_entryClick(Sender:TObject);

begin
  draw_export_rectangle_flag:=False; // clear existing rectangle if any.

  show_bgnd_keeps_in_rect_menu_entry.Checked:=False;      // 218d

  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.set_boundary_rectangle_menu_entryClick(Sender: TObject);

begin
  set_boundary_rectangle_dims(pad_form);
end;
//______________________________________________________________________________

procedure Tpad_form.make_screenshot_menu_itemClick(Sender: TObject);

var
  screen_rect,print_rect:TRect;

  create_bitmap:TBitmap;
  create_png:TPortableNetworkGraphic;

  folder_str:string;
  file_name_str:string;  // name part
  file_str:string;       // including path

  i:integer;

  dummy_emf:Temf; // 555a


begin

  if alert(7,'   make  a  trackpad  screenshot',
             'This function makes an exact copy of the current trackpad screen, similar to using the Windows `0Print`2&nbsp;`0Screen`2 key.'
            +'||green_panel_begin tree.gif It is usually more useful to export an image file of your track plan, which will give much better image quality and allow control of the background colour and other details.'
            +'||To export an image file, cancel this and click the `0output&nbsp;>&nbsp;export&nbsp;a&nbsp;file ...`1 menu item instead.green_panel_end',
              '','','','make  screenshot  image','cancel','',0)=5 then EXIT;

  file_name_str:=remove_invalid_str('trackpad_screenshot'+FormatDateTime('_yyyy_mm_dd_hhmm_ss',Date+Time));

  with save_screenshot_dialog do begin

    if his_image_file_name<>'' then InitialDir:=ExtractFilePath(his_image_file_name)
                               else InitialDir:=exe_str+'IMAGE-FILES\';

    DefaultExt:='png';
    FileName:=file_name_str+'.png';

    if Execute=False then EXIT;

    his_image_file_name:=FileName;        // so we can use the same folder next time.

      // invalid entered chars removed by dialog

    file_str:=ExtractFilePath(FileName)+lower_case_filename(ExtractFileName(FileName));   // to underscores and lower case

  end;//with

  Screen.Cursor:=crHourGlass;  // needed for large images or slow systems

  create_bitmap:=TBitmap.Create;
  create_png:=TPortableNetworkGraphic.Create;

  screen_rect.Top:=0;
  screen_rect.Left:=0;
  screen_rect.Right:=pad_form.ClientWidth-1;
  screen_rect.Bottom:=pad_form.ClientHeight-1;

  print_rect:=screen_rect;


  try
    create_bitmap.Width:=pad_form.ClientWidth;
    create_bitmap.Height:=pad_form.ClientHeight;

    try
      create_bitmap.Canvas.CopyMode:=cmSrcCopy;
      create_bitmap.Canvas.CopyRect(print_rect,pad_form.Canvas,screen_rect);

      create_png.Assign(create_bitmap);
      create_png.SaveToFile(file_str);

      repeat

        i:=alert(2,'   screenshot  image  file  created',
                   'The screenshot image file was created successfully:||`0'+file_str+'`f'
                  +'||Click <A HREF="alert_2.85a">view image in Templot</A> to see it.',
                   '','view  image  in  Templot','view  image  in  your  usual  image  viewer','open  the  containing  folder','','continue',0);

        if i=2 then show_an_image_file(False,file_str,dummy_emf);

        if i=3
           then begin
                  folder_str:=file_str;

                  if ShellExecute(0,'open',PChar(folder_str),nil,nil,SW_SHOWNORMAL)<=32
                     then ShowMessage('Sorry, unable to display the image.')
                     else external_window_showing:=True;
                end;

        if i=4
           then begin
                  folder_str:=ExtractFilePath(file_str);

                  if ShellExecute(0,'explore',PChar(folder_str),nil,nil,SW_SHOWNORMAL)<=32
                     then ShowMessage('Sorry, unable to open the folder.')
                     else external_window_showing:=True;
                end;

      until ((i<>2) or (FileExists(file_str)=False));    // may be deleted in image viewer

    except
      ShowMessage('Sorry, an error occurred in creating the screenshot image file.');
    end;//try


  finally
    create_png.Free;
    create_bitmap.Free;
  end;//try

  Screen.Cursor:=crDefault;
end;
//______________________________________________________________________________

  // 0.95.a  changes to cancel mouse action on popup item clicks...
  
procedure Tpad_form.reset_options_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
end;
//______________________________________________________________________________

procedure Tpad_form.peg_options_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
end;
//______________________________________________________________________________

procedure Tpad_form.keep_to_background_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  store_and_background_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.show_info_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  show_info_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.hide_info_popup_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);
  hide_info_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.peg_blank_menu_entryClick(Sender: TObject);

begin
  peg_blank_menu_entry.Checked:=True;   // radio item 0.95.a
  show_and_redraw(True,False);          // no rollback needed.
end;
//______________________________________________________________________________

procedure Tpad_form.peg_solid_red_menu_entryClick(Sender: TObject);

begin
  peg_solid_red_menu_entry.Checked:=True;   // radio item 0.95.a
  show_and_redraw(True,False);              // no rollback needed.
end;
//______________________________________________________________________________

procedure Tpad_form.peg_hollow_menu_entryClick(Sender: TObject);

begin
  peg_hollow_menu_entry.Checked:=True;   // radio item 0.95.a
  show_and_redraw(True,False);           // no rollback needed.
end;
//______________________________________________________________________________

procedure Tpad_form.make_a_donation_menu_entryClick(Sender: TObject);

begin
  go_to_donation;
end;
//______________________________________________________________________________

procedure Tpad_form.mouse_wheel_zoom_centre_menu_entryClick(Sender:TObject);

begin
  wheel_zoom_code:=0;
  mouse_wheel_zoom_centre_menu_entry.Checked:=True;   // radio item
end;
//______________________________________________________________________________

procedure Tpad_form.mouse_wheel_zoom_at_mouse_menu_entryClick(Sender:TObject);

begin
  wheel_zoom_code:=1;
  mouse_wheel_zoom_at_mouse_menu_entry.Checked:=True;   // radio item
end;
//______________________________________________________________________________

procedure Tpad_form.mouse_wheel_zoom_jump_menu_entryClick(Sender:TObject);

begin
  wheel_zoom_code:=2;
  mouse_wheel_zoom_jump_menu_entry.Checked:=True;   // radio item
end;
//______________________________________________________________________________

procedure Tpad_form.mouse_wheel_zoom_options_menu_entryClick(Sender:TObject);

begin
  case wheel_zoom_code of

   0: mouse_wheel_zoom_centre_menu_entry.Checked:=True;   // radio item

   1: mouse_wheel_zoom_at_mouse_menu_entry.Checked:=True;   // radio item

   2: mouse_wheel_zoom_jump_menu_entry.Checked:=True;   // radio item

  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.mouse_wheel_help_menu_entryClick(Sender: TObject);

const
  wheel_help_str:string='php/420    `0Mouse  Wheel  Functions`9'
  +'||The settings on the `0trackpad > zoom and pan options > mouse wheel zoom options >`1 menu options control the way that the trackpad view responds to rolling the mouse wheel.'
  +' If you are familiar with a CAD program you can set Templot to match your CAD zoom settings.'
  +'||For more information about these settings, and the other functions available using the mouse wheel, please click <A HREF="online_ref420.85a">more&nbsp;information&nbsp;online</A> .';

begin
  help(0,wheel_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.roll_dummy_vehicle_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(True);

  grid_form.show_dummy_vehicles_radio_button.Checked:=True;  // make sure showing   213a

  mouse_action_selected('    roll  dummy  vehicle ...','roll  dummy  vehicle','roll  to :  '+captext(cdvi.dv_start*inscale)+' mm');
  dv_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_dummy_vehicle_clearance_menu_entryClick(Sender:TObject);

begin
  cancel_adjusts(True);

  grid_form.show_dummy_vehicles_radio_button.Checked:=True;  // make sure showing   213a

  mouse_action_selected('    dummy  vehicle  clearance...','dummy  vehicle  clearance',captext(cdvi.dv_clearance)+' inches  ( '+captext(cdvi.dv_clearance*inscale)+' mm )');
  dv_clear_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_adjacent_centres_ts_menu_entryClick(Sender:TObject);

begin
  cancel_adjusts(True);

  if track_centre_lines_flag=False then normal_track_centre_lines_menu_radio.Click;  // make sure showing

  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;  // make sure generator centre-lines are on.

  if adjacent_edges=True then centre_line_option_ts_track_menu_entry.Click;  // put centre-line on TS if rails not showing

  mouse_action_selected('    adjacent  centres  TS ...','adjacent  centres  TS',captext(cpi.trtscent_pi)+' mm');
  adjacent_ts_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_adjacent_centres_ms_menu_entryClick(Sender:TObject);

begin
  cancel_adjusts(True);

  if track_centre_lines_flag=False then normal_track_centre_lines_menu_radio.Click;  // make sure showing

  if centre_lines_menu_entry.Checked=False then centre_lines_menu_entry.Click;  // make sure generator centre-lines are on.

  if adjacent_edges=True then centre_line_option_ms_track_menu_entry.Click;  // put centre-line on MS if rails not showing.

  mouse_action_selected('    adjacent  centres  MS ...','adjacent  centres  MS',captext(cpi.trmscent_pi)+' mm');
  adjacent_ms_mod:=1;
end;
//______________________________________________________________________________

procedure move_bgnd_peg_notch_under(new_peg_code,new_peg_rail:integer);

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  try
    rebuild_it(clicked_keep_index,new_peg_code,new_peg_rail,True);      // rebuild the background template (ignore result).

    if GetKeyState(VK_SHIFT)>-1
       then pad_form.notch_under_bgnd_peg_popup_entry.Click    // and put notch under (unless SHIFT key is down)
       else redraw(True);                                      // 227d

  finally
    clicked_keep_index:=-1;    // so can popup again.
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.move_to_ctrl0_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(0,8);
end;
//____________________

procedure Tpad_form.move_to_ctrl1_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(1,8);
end;
//____________________

procedure Tpad_form.move_to_ctrl2_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(2,8);
end;
//____________________

procedure Tpad_form.move_to_planing_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(100,2);
end;
//____________________

procedure Tpad_form.move_to_heel_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(104,2);
end;
//____________________

procedure Tpad_form.move_to_ctrl3_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(3,8);
end;
//____________________

procedure Tpad_form.move_to_cesp_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(108,9);
end;
//____________________

procedure Tpad_form.move_to_ctrl4_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(4,3);
end;
//____________________

procedure Tpad_form.move_to_tcp_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(5,9);
end;
//____________________

procedure Tpad_form.move_to_mcp_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(8,8);
end;
//____________________

procedure Tpad_form.move_to_ctrl5_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(6,9);
end;
//____________________

procedure Tpad_form.move_to_ctrl6_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(18,9);
end;
//____________________

procedure Tpad_form.move_to_ctrl7_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(9,8);
end;
//____________________

procedure Tpad_form.move_to_ctrl8_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(17,8);
end;
//____________________

procedure Tpad_form.move_to_tolp_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(600,9);
end;
//____________________

procedure Tpad_form.move_to_ctrl9_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(11,8);
end;
//____________________

procedure Tpad_form.move_to_tminp_popup_entryClick(Sender: TObject);  // 213b

begin
  move_bgnd_peg_notch_under(240,9);
end;
//____________________

procedure Tpad_form.move_to_texitp_popup_entryClick(Sender: TObject);  // 213b

begin
  move_bgnd_peg_notch_under(241,9);
end;
//____________________

procedure Tpad_form.move_to_mminp_popup_entryClick(Sender: TObject);    // 217a

begin
  move_bgnd_peg_notch_under(260,8);
end;
//____________________

procedure Tpad_form.move_to_mexitp_popup_entryClick(Sender: TObject);   // 217a

begin
  move_bgnd_peg_notch_under(261,8);
end;
//____________________

procedure Tpad_form.move_to_user_defined_popup_entryClick(Sender: TObject);

begin
  move_bgnd_peg_notch_under(999,8);
end;
//______________________________________________________________________________

procedure Tpad_form.move_bgnd_peg_help_popup_entryClick(Sender: TObject);

begin
//
end;
//______________________________________________________________________________
(* OT2024

procedure Tpad_form.sb_show_items_on_pad_menu_entryClick(Sender: TObject);

   // 205e

begin
  sb_show_items_on_pad_menu_entry.Checked:= NOT sb_show_items_on_pad_menu_entry.Checked;

  dtp_form.show_dtp_on_pad_checkbox.Checked:=sb_show_items_on_pad_menu_entry.Checked;

  if sb_show_items_on_pad_menu_entry.Checked=False
     then begin
            redraw(True);  // remove items if any
            EXIT;
          end;

  if go_sketchboard=True        // sketchboard has been started
     then do_dtp_form_hide      // setup and show items
     else begin
            if alert(6,'php/500    sketchboard  not  in  use',
                       'The sketchboard is not currently in use.'
                      +'||To start using the sketchboard so that items on the sketchboard can be shown on the trackpad,|click `0show  sketchboard`1 below.',
                       '','','','','cancel','show  sketchboard',0)=5 then EXIT;

            sketchboard_button.Click;
          end;
end;
//______________________________________________________________________________
*)

procedure Tpad_form.obtain_to_control_popup_entryClick(Sender: TObject);   // 205e

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    obtain_turnout_radius_popup_entry.Enabled:= NOT (bgnd_plain_track or bgnd_spiral);

    if bgnd_half_diamond=True
       then obtain_turnout_radius_popup_entry.Caption:='C   &curve  the  control  to  this  diagonal-road  radius'
       else obtain_turnout_radius_popup_entry.Caption:='C   &curve  the  control  to  this  turnout-road  radius';

    obtain_ext_geo_radius_popup_entry.Enabled:= NOT (bgnd_plain_track or bgnd_half_diamond or bgnd_spiral or bgnd_slewing);     // 227a

  end;//with

end;
//______________________________________________________________________________

procedure Tpad_form.obtain_negative_curving_menu_entryClick(Sender: TObject);       // 217b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  fix_radius(0-ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_turnout_radius),True);

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_positive_curving_menu_entryClick(Sender: TObject);       // 217b

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  fix_radius(ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_turnout_radius),True);

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_negative_geo_menu_entryClick(Sender: TObject);  // 227a

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  fix_radius(0-ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_ext_geo_radius),True);

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_positive_geo_menu_entryClick(Sender: TObject);  // 227a

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;     // !!!

  fix_radius(ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_ext_geo_radius),True);

  clicked_keep_index:=-1;    // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_gaunt_from_turnout_radius_popup_entryClick(Sender: TObject);     // 217a

var
  bgnd_ts_rad:extended;
  equiv_rad:extended;
  gaunt_offset:extended;
  old_dp,new_dp:extended;

  dummy1,dummy2:extended;
  pc,pf:Tpex;

begin
  if plain_track=True
     then begin
            alert(6,'php/151    set  gaunt  radius  from  background  template',
                    'The control template is plain track.'
                   +'||This function applies only to gaunt turnout templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'php/151    set  gaunt  radius  from  background  template',
                    'The control template is a half-diamond template.'
                    +'||This function applies only to gaunt turnout templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_spiral=True
     then begin
            alert(6,'php/151    set  gaunt  radius  from  background  template',
                    'The selected background template contains a transition curve.'
                    +'||It is not possible to set the gaunt radius from a transition curve template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if xing_calc_i<>1
     then begin
            if alert(2,'php/151    set  gaunt  radius  from  background  template',
                      'The V-crossing in the control template is not currently curviform.'
                      +'||This function is intended for use with curviform V-crossings only.'
                      +'||Change to curviform ?',
                       '','','','','cancel','change  to  curviform  V - crossing',0)=5 then EXIT;

            curviform_crossing_menu_entry.Click;
            gocalc(0,0);
          end;

  if gaunt=False
     then begin
            if alert(2,'php/151    set  gaunt  radius  from  background  template',
                      'The control template is not currently a gaunt turnout.'
                      +'||Change to a gaunt turnout ?',
                       '','','','','cancel','change  to  gaunt  turnout',0)=5 then EXIT;

            convert_to_or_from_gaunt(True);
            gocalc(0,0);
          end;

  kform_now:=kform;
  arm_angle_now:=arm_angle;
  pegangle_now:=pegangle;
  docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy1);    // save current peg position on pad and curving angle.

  old_dp:=dpx-xorg;

  bgnd_ts_rad:=ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_turnout_radius);

  equiv_rad:=ABS(equiv_rad_calc(bgnd_ts_rad,clrad1))+g/2;     // rad to gauge-face

  if equiv_rad>(2000*g)
     then begin
            equiv_rad:=2000*g;    // 217b  2000g radius top limit (xorg becomes excessive)

            if alert(2,'php/151    set  gaunt  radius  from  background  template',
                       'You are setting a gaunt turnout radius which is very similar in size and direction to the current curving radius in the main-road.'
                      +'||This will create a very long, strange-looking gaunt turnout template.'
                      +'||If you intend to use the `0do > isolate V-crossing`z function there will be no problem.'
                      +'||If not, this is most likely an error and you should probably cancel.',
                       '','','','','cancel','continue',0)=5
            then begin
                   convert_to_or_from_gaunt(False);
                   clicked_keep_index:=-1;    // so can popup again.
                   redraw_pad(True,True);
                   EXIT;
                 end;
          end;

  gaunt_offset:=equiv_rad*COS(k3)-equiv_rad+g;

  gaunt_offset_in:=gaunt_offset/inscale;

      // offset can't exceed the knuckle..

  if gaunt_offset_in>((g-fw-minfp)/inscale) then gaunt_offset_in:=(g-fw-minfp)/inscale;

  gocalc(0,0);              // calc new dpx

  new_dp:=dpx-xorg;         // maintain overall length and V-crossing alignment
  xorg:=xorg+old_dp-new_dp;

  if xorg<0
     then begin
            turnoutx:=turnoutx-xorg;          // increase overall length to keep V-crossing and exit track.
            if spiral=True then os:=os-xorg;
            if slewing=True then slew_s:=slew_s-xorg;
            xorg:=0;
          end;

  if turnoutx>turnoutx_max then turnoutx:=turnoutx_max;
  if xorg>turnoutx then xorg:=turnoutx;

  gocalc(0,0);   // recalc to get new pegx, pegy, arm_angle.

  docurving(False,True,pegx,pegy,pc.x,pc.y,dummy1,dummy2);  // first curve peg position.

  dotransform(kform,xform,yform,pc,pf);      // then rotate it (without shifts).

  xshift:=now_peg_x - pf.x;      // maintain peg position constant (now_peg includes the now_shift).
  yshift:=now_peg_y - pf.y;

  rotate_turnout(arm_angle_now-arm_angle,False);    // re-align to previous angle.

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.obtain_diagonal_from_turnout_radius_popup_entryClick(Sender: TObject);       // 218c

var
  dummy_notch1,dummy_notch2,dummy_notch3:Tnotch;

  equivalent_rad,bgnd_ts_rad:extended;

begin

  if plain_track=True
     then begin
            alert(6,'php/151    set  diagonal  radius  from  background  template',
                    'The control template is plain track.'
                   +'||This function applies only to half-diamond templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=False
     then begin
            alert(6,'php/151    set  diagonal  radius  from  background  template',
                    'The control template is a turnout template.'
                    +'||This function applies only to half-diamond templates.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_spiral=True
     then begin
            alert(6,'php/151    set  diagonal  radius  from  background  template',
                    'The selected background template contains a transition curve.'
                    +'||It is not possible to set the diagonal-road radius from a transition curve template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if xing_calc_i<>1
     then begin
            if alert(2,'php/151    set  diagonal  radius  from  background  template',
                      'The V-crossing in the control template is not currently curviform.'
                      +'||This function is intended for use with curviform V-crossings only.'
                      +'||Change to curviform ?',
                       '','','','','cancel','change  to  curviform  V - crossing',0)=5 then EXIT;

            curviform_crossing_menu_entry.Click;
            gocalc(0,0);
          end;

  reset_peg_menu_entry.Click;  // to CTRL-0

  gocalc(0,0);

  bgnd_ts_rad:=ABS(Ttemplate(keeps_list.Objects[clicked_keep_index]).bgnd_turnout_radius);

  equivalent_rad:=ABS(equiv_rad_calc(bgnd_ts_rad,clrad1))+g/2;     // equiv rad to gauge-face when straight

    // modify K-crossing angle to produce required radius ...

  try
    hdk:=ARCCOS(COS(k3)+g/equivalent_rad);
    hdkn:=1/TAN(hdk);

    gocalc(0,0);

    if turnoutx<mvjpx then turnoutx:=mvjpx;

    gocalc(0,0);
  except
    ShowMessage('Sorry, it is not possible to set the diagonal-road radius on this half-diamond template'
              +' to match the turnout-road radius on the background template.'
              +#13+#13+'Try starting with a different V-crossing angle.');
  end;//try

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.centre_line_option_ts_track_menu_entryClick(Sender: TObject);  // 206a ...

begin
  cl_options_code:=2;
  redraw_pad(True,True);
end;
//___________________

procedure Tpad_form.centre_line_option_ts_double_menu_entryClick(Sender: TObject);

begin
  cl_options_code:=1;
  redraw_pad(True,True);
end;
//___________________

procedure Tpad_form.centre_line_option_ts_sleeper_ends_menu_entryClick(Sender:TObject);

begin
  cl_options_code:=3;
  redraw_pad(True,True)
end;
//___________________

procedure Tpad_form.centre_line_option_normal_menu_entryClick(Sender: TObject);

begin
  cl_options_code:=0;
  redraw_pad(True,True);
end;
//___________________

procedure Tpad_form.centre_line_option_ms_sleeper_ends_menu_entryClick(Sender:TObject);

begin
  cl_options_code:=-3;
  redraw_pad(True,True);
end;
//___________________

procedure Tpad_form.centre_line_option_ms_double_menu_entryClick(Sender: TObject);

begin
  cl_options_code:=-1;
  redraw_pad(True,True);
end;
//___________________

procedure Tpad_form.centre_line_option_ms_track_menu_entryClick(Sender: TObject);

begin
  cl_options_code:=-2;
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.centre_line_option_custom_menu_entryClick(Sender: TObject);

begin
  cl_options_code:=99;
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.centre_line_offset_options_menu_entryClick(Sender: TObject);   // 206a

begin
  case cl_options_code of
   -3: centre_line_option_ms_sleeper_ends_menu_entry.Checked:=True; // radio item
   -2: centre_line_option_ms_track_menu_entry.Checked:=True;        // radio item
   -1: centre_line_option_ms_double_menu_entry.Checked:=True;       // radio item
    0: centre_line_option_normal_menu_entry.Checked:=True;          // radio item
    1: centre_line_option_ts_double_menu_entry.Checked:=True;       // radio item
    2: centre_line_option_ts_track_menu_entry.Checked:=True;        // radio item
    3: centre_line_option_ts_sleeper_ends_menu_entry.Checked:=True; // radio item
   99: centre_line_option_custom_menu_entry.Checked:=True;          // radio item
  end//case;
end;
//______________________________________________________________________________

procedure Tpad_form.rebuild_group_to_match_cl_options_menu_entryClick(Sender:TObject);      // 214a

var
  his_option:boolean;

begin
  if any_bgnd=0
     then begin
            alert_no_bgnd;
            EXIT;
          end;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;

  if alert(7,'php/204    modify  group  to  match  centre - line  offset  options',
          'This function will modify the centre-line offset options on the selected group of background templates to match the current settings on the control template.',
          '','','','','cancel','modify  group  to  match  centre - line  offset  options',0)=5
     then EXIT;

  his_option:=keep_form.centre_line_offset_options_as_stored_menu_entry.Checked;
  keep_form.centre_line_offset_options_as_control_menu_entry.Checked:=True;         // radio item.

  rebuild_group(True,True);

  if his_option=True then keep_form.centre_line_offset_options_as_stored_menu_entry.Checked:=True;   // radio item.
end;
//______________________________________________________________________________

procedure Tpad_form.track_background_width_menu_entryClick(Sender: TObject);   // 206a

const
  bgnd_width_help_str:string='    `0track background width`9'
  +'||Enter a dimension in full-size prototype <B>inches</B> for the width of the coloured track background.'
  +'||green_panel_begin tree.gif This applies only to diagram-mode track plans, shown on the sketchboard and in exported image files.'
  +'||The track background is intended to represent the area inside the railway fence on coloured layout plans.'
  +'||A typical width for a single track railway on level ground would be at least 24ft between the fences - entered as 288 inches (or f24 using the f letter prefix for feet).'
  +' Often the fenced width is much wider.green_panel_end'
  +'|rp.gif This track background function requires templates to be created with track centre-lines.'
  +'||blue_bullet Note that this is not the same as the `0geometry > trackbed edges...`1 functions which are intended as construction guide lines for the model.'
  +' The coloured track background is intended for neat small-scale displays. If used on construction templates it would consume excessive quantities of ink.';

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(bgnd_width_help_str,2,'track  background  width  ( full-size  INCHES )',track_bgnd_width_in,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('track  background  width','',pad_form,n,od)=True
     then track_bgnd_width_in:=od[0];
end;
//______________________________________________________________________________

procedure Tpad_form.track_background_colour_menu_entryClick(Sender: TObject);  // 206a

begin
  save_sb_track_bgnd:=get_colour('choose  a  background  colour  for  track  in  diagram  mode',save_sb_track_bgnd);
end;
//______________________________________________________________________________

procedure Tpad_form.diagram_mode_track_colour_menu_entryClick(Sender: TObject);

begin
  save_sb_diagram_col:=get_colour('choose  a  colour  for  track  in  diagram  mode',save_sb_diagram_col);
end;
//______________________________________________________________________________

procedure Tpad_form.centre_line_option_custom_offet_menu_entryClick(Sender: TObject);

const
  help_custom_offset_str:string='php/180    `0centre-line  options  -  custom  offset`9'
  +'||Enter a distance in millimetres to offset the main-road centre-line. This is sometimes useful as a design guide.'

  +'||The dimension should be positive for an offset to TS, and negative for an offset to MS.'

  +'||TS is "turnout-side", i.e. the same side as the hand of the template. MS is "main-side", i.e. the opposite side to the hand of the template.'

  +'||green_panel_begin tree.gif Changes to this dimension will take effect only while the `0geometry > centre-line options > custom`1 menu option is selected.green_panel_end';

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(help_custom_offset_str,1,'centre - line  offset',cl_options_custom_offset,False,True,False,False);   // neg ok, no preset, zero ok, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('custom  centre - line  offset','',pad_form,n,od)=False then EXIT;

  cl_options_custom_offset:=od[0];
  redraw_pad(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.add_group_tag_menu_entryClick(Sender: TObject);

var
  prefix_str,name_str:string;
  n:integer;

begin
  if keeps_list.Count<1 then EXIT;

  if any_selected=0
     then begin
            if alert_no_group=True    // alert him, and does he want all?
               then EXIT;
          end;


  with math_form do begin
    Caption:='    add  a  prefix  tag  to  all  template  names  in  group';
    big_label.Caption:=insert_crlf_str('           Add  a  prefix  tag  to  template  names.'
                                    +'||You can add a prefix tag to the names of all the templates in the group by entering the required tag below.'
                                    +' This will make it easier to sort templates in the storage box, and to recreate the same group at a later time.'
                                    +'||The tag can be any string of letters and numbers, but ideally should be kept as short as possible.'
                                    +' For example, all the templates forming a second goods yard could be tagged: yard 2.'
                                    +'||The tag string will be enclosed in square brackets like this: [yard 2].|Do not enter the square brackets, they will be added automatically.'
                                    +'||You can repeat this process to add multiple tags, so that a template can be in more than one group, for example: [up loop] [yard 2].');
    math_editbox.Text:='';

    do_show_modal(math_form);     // 212a  ShowModal

    Caption:='    TEMPLOT';   // reset form caption.

    if ModalResult=mrOK then prefix_str:=Trim(math_editbox.Text)
                        else EXIT;

  end;//with form

  if prefix_str='' then EXIT;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin

      if group_selected=False then CONTINUE;

      name_str:=template_info.keep_dims.box_dims1.reference_string;

      name_str:='['+prefix_str+'] '+name_str;

      repeat
        Application.ProcessMessages;
        name_str:=StringReplace(name_str,'[[','[',[rfReplaceAll,rfIgnoreCase]);    // in case he added [
        name_str:=StringReplace(name_str,']]',']',[rfReplaceAll,rfIgnoreCase]);    // in case he added ]
      until ((Pos('[[',name_str)=0) and (Pos(']]',name_str)=0));

      template_info.keep_dims.box_dims1.reference_string:=name_str;

    end;//with
  end;//for

  do_rollback:=False;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.selection_popupPopup(Sender: TObject);

var
  new_entry:TMenuItem;

  n,tag_count:integer;

  name_str,tag_str:string;

  this_one_tags_list:TStringList;

  a,b:integer;  // 226c


begin

  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  name_str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;

      // build list of existing tags in menu...  206b

  add_existing_prefix_tag_popup_entry.Clear;

  tag_count:=build_tag_list(False);    // tag_count not used

  if tag_list.Count>0
     then begin
            add_existing_prefix_tag_popup_entry.Enabled:=True;

            for n:=0 to tag_list.Count-1 do begin

              tag_str:='['+tag_list.Strings[n]+']';

              if Pos(tag_str,name_str)<>0 then CONTINUE;  // this tag already on this template

              new_entry:=TMenuItem.Create(Self);
              new_entry.Caption:=tag_list.Strings[n];
              new_entry.OnClick:=add_this_tag_menu_entry_click;

              add_existing_prefix_tag_popup_entry.Add(new_entry);

            end;//next

            if add_existing_prefix_tag_popup_entry.Count>0
               then begin

                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='-';            // separator line

                      // if win7_menu_style=True
                      // then new_entry.Bitmap:=nil
                      // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                      add_existing_prefix_tag_popup_entry.Add(new_entry);


                      new_entry:=TMenuItem.Create(Self);
                      new_entry.Caption:='H   ? add  existing  tag  -  &help';
                      new_entry.OnClick:=add_this_tag_help_menu_entry_click;

                      add_existing_prefix_tag_popup_entry.Add(new_entry);
                    end;
          end;

  add_existing_prefix_tag_popup_entry.Enabled:=(add_existing_prefix_tag_popup_entry.Count>0);

      // build list of this one's tags in remove menu...

  remove_prefix_tag_popup_entry.Clear;

  this_one_tags_list:=TStringList.Create;

  try

    tag_count:=return_prefix_tags_list(clicked_keep_index,this_one_tags_list);

    if this_one_tags_list.Count>0
       then begin
              remove_prefix_tag_popup_entry.Enabled:=True;

              for n:=0 to this_one_tags_list.Count-1 do begin

                new_entry:=TMenuItem.Create(Self);
                new_entry.Caption:=this_one_tags_list.Strings[n];
                new_entry.OnClick:=remove_this_tag_menu_entry_click;

                remove_prefix_tag_popup_entry.Add(new_entry);

              end;//next

              if remove_prefix_tag_popup_entry.Count>0
                 then begin
                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:='-';            // separator line

                        // if win7_menu_style=True
                        // then new_entry.Bitmap:=nil
                        // else new_entry.Bitmap:=control_room_form.menu_kludge_image.Picture.Bitmap;

                        remove_prefix_tag_popup_entry.Add(new_entry);


                        new_entry:=TMenuItem.Create(Self);
                        new_entry.Caption:='H   ? remove  tag  -  &help';
                        new_entry.OnClick:=remove_this_tag_help_menu_entry_click;

                        remove_prefix_tag_popup_entry.Add(new_entry);
                      end;
          end;

    remove_prefix_tag_popup_entry.Enabled:=(remove_prefix_tag_popup_entry.Count>0);

    group_all_with_same_tag_popup_entry.Enabled:=(tag_count=1);         // 226c

    group_all_with_any_same_tags_popup_entry.Enabled:=(tag_count>1);    // 226c any    was ( (Pos('[',name_str)<>0) and (Pos(']',name_str)<>0) );        //
    group_all_with_all_same_tags_popup_entry.Enabled:=(tag_count>1);    // 226c all    was ( (Pos('[',name_str)<>0) and (Pos(']',name_str)<>0) );

  finally
    this_one_tags_list.Free;
  end;///try

    // see if showing in marker colour..

  with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do begin

    group_all_with_same_marker_colour_popup_entry.Enabled:=use_pad_marker_colour;

    group_all_with_same_colour_popup_entry.Enabled:=group_all_with_same_marker_colour_popup_entry.Enabled;  // duplicate popup entry in colour options


    cancel_brick_popup_entry.Enabled:=timbering_brick_flag;        // 234a ..
    brick_colour_popup_entry.Enabled:=timbering_brick_flag;
    set_brick_popup_entry.Enabled:= NOT timbering_brick_flag;

    if (timbering_brick_flag=True) and (use_pad_marker_colour=True)
       then brick_colour_popup_entry.Caption:='&C   '+get_rgb_text(pad_marker_colour)  // 234b brick label colour RGB
       else brick_colour_popup_entry.Caption:='&C       - - ';

  end;//with
end;
//______________________________________________________________________________

procedure Tpad_form.add_this_tag_menu_entry_click(Sender:TObject);   // 206b

    // add selected existing tag as name prefix

var
  tag_str:string;

begin
  if (Sender is TMenuItem) then tag_str:='['+TMenuItem(Sender).Caption+'] '
                           else EXIT;

  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1 do reference_string:=tag_str+reference_string;

  save_done:=False;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.add_this_tag_help_menu_entry_click(Sender:TObject);   // 206b

const
  str1:string='php/330    `0add  an  existing  prefix  tag`9||   <I>';

  str2:string='</I>||Click a tag listed on the sub-menu to add it to the above template.'
             +'||The list shows all the prefix tags currently in use on your templates (except any tags already on this template).'
             +'||If you want to create and add a new prefix tag, click the|`0add a new prefix tag...`1 menu item, or click the button below.'
             +'||green_panel_begintree.gif If you want to edit the template tags directly,|click `0rename...`1 on the full menu.green_panel_end'
             +'|For more information about using prefix tags,|click `0more information online`1 above.';

var
  name_str:string;

begin
  name_str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;

  if help(0,str1+name_str+str2,'add  a  new  prefix  tag ...')=1 then add_prefix_tag_popup_entry.Click;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_this_tag_menu_entry_click(Sender:TObject);   // 206b

    // remove selected existing tag

var
  name_str,tag1_str,tag2_str:string;

begin
  if (Sender is TMenuItem) then tag1_str:='['+TMenuItem(Sender).Caption+']'
                           else EXIT;

  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  tag2_str:=tag1_str+' ';       // include trailing space

  name_str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;

  name_str:=StringReplace(name_str,tag2_str,'',[rfReplaceAll,rfIgnoreCase]);

  name_str:=StringReplace(name_str,tag1_str,'',[rfReplaceAll,rfIgnoreCase]);    // in case the tailing space was missing

  with Ttemplate(keeps_list.Objects[clicked_keep_index]) do begin

    template_info.keep_dims.box_dims1.reference_string:=name_str;

    tagged_hidden:=False;  // 237a    in case not being shown on pad  (clicked while grouped)

  end;//with

  save_done:=False;
  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_this_tag_help_menu_entry_click(Sender:TObject);   // 206b

const
  str1:string='php/330    `0remove  prefix  tag`9||   <I>';

  str2:string='</I>||Click a tag listed on the sub-menu to remove it from the above template.'
             +'||green_panel_begintree.gif If you want to edit the template tags directly,|click `0rename...`1 on the full menu,'
             +'||or click the `0rename this template...`1 button below.green_panel_end'
             +'|For more information about using prefix tags,|click `0more information online`1 above.';

var
  name_str:string;

begin
  name_str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;

  if help(0,str1+name_str+str2,'rename  this  template ...')=1 then rename_popup_entry.Click;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.add_prefix_tag_popup_entryClick(Sender: TObject);

var
  prefix_str,name_str:string;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with math_form do begin
    Caption:='    add  a  prefix  tag  to  this  template  name';
    big_label.Caption:=insert_crlf_str('       Add  a  prefix  tag  to  this  template  name.'
                                    +'||You can add a prefix tag to the name of this template by entering the required tag below.'
                                    +' This will make it easier to sort templates in the storage box, and to recreate the same group at a later time.'
                                    +'||The tag can be any string of letters and numbers, but ideally should be kept as short as possible.'
                                    +' For example, all the templates forming a second goods yard could be tagged: yard 2.'
                                    +'||The tag string will be enclosed in square brackets like this: [yard 2].|Do not enter the square brackets, they will be added automatically.'
                                    +'||You can repeat this process to add multiple tags, so that a template can be in more than one group, for example: [up loop] [yard 2].');
    math_editbox.Text:='';

    do_show_modal(math_form);     // 212a  ShowModal

    Caption:='    TEMPLOT';   // reset form caption.

    if ModalResult=mrOK then prefix_str:=Trim(math_editbox.Text)
                        else EXIT;

  end;//with form

  if prefix_str='' then EXIT;

  name_str:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string;

  name_str:='['+prefix_str+'] '+name_str;

  repeat
    Application.ProcessMessages;
    name_str:=StringReplace(name_str,'[[','[',[rfReplaceAll,rfIgnoreCase]);    // in case he added [
    name_str:=StringReplace(name_str,']]',']',[rfReplaceAll,rfIgnoreCase]);    // in case he added ]
  until ((Pos('[[',name_str)=0) and (Pos(']]',name_str)=0));

  Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.reference_string:=name_str;

  save_done:=False;

  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.group_all_with_any_same_tags_popup_entryClick(Sender:TObject);  // 206b

var
  this_one_tags_list:TStringList;
  i,n,tag_count:integer;
  tag_str:string;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  this_one_tags_list:=TStringList.Create;

  try
    if any_selected>0       // 226c
       then begin
              i:=alert(4,'php/330    add  templates  to  existing  group ?',
                         '`0Select matching tagged templates as a group.`9'
                        +'||There is an existing group of one or more templates.'
                        +'||Do you want to create a new group, or add the tagged templates to the existing group?',
                         '','','','add  to  existing  group','cancel','create  new  group',0);

              if i=5 then EXIT;

              if i=6 then clear_all_selections;  // 226c remove any existing group first
            end;

    tag_count:=return_prefix_tags_list(clicked_keep_index,this_one_tags_list);    // tag_count not used

    if this_one_tags_list.Count<1 then EXIT;

    for n:=0 to this_one_tags_list.Count-1 do begin

      tag_str:=this_one_tags_list.Strings[n];

      create_group_from_tag(tag_str,True);   // True = don't alert existing group when adding each one
    end;//next tag

  finally
    this_one_tags_list.Free;

    unlink_group;
    clicked_keep_index:=-1;    // so can popup again.
    redraw_pad(True,False);
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.group_all_with_all_same_tags_popup_entryClick(Sender: TObject); // 226c
var
  this_one_tags_list:TStringList;
  i,n,tag_count:integer;
  full_tag_str:string;
  not_this_one:boolean;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  this_one_tags_list:=TStringList.Create;

  try
    if any_selected>0       // 226c
       then begin
              i:=alert(4,'php/330    add  templates  to  existing  group ?',
                         '`0Select matching tagged templates as a group.`9'
                        +'||There is an existing group of one or more templates.'
                        +'||Do you want to create a new group, or add the tagged templates to the existing group?',
                         '','','','add  to  existing  group','cancel','create  new  group',0);

              if i=5 then EXIT;

              if i=6 then clear_all_selections;  // 226c remove any existing group first
            end;

    tag_count:=return_prefix_tags_list(clicked_keep_index,this_one_tags_list);    // tag_count not used

    if this_one_tags_list.Count<1 then EXIT;

    not_this_one:=True;  // keep compiler happy

    for n:=0 to keeps_list.Count-1 do begin

      for i:=0 to this_one_tags_list.Count-1 do begin

        full_tag_str:='['+this_one_tags_list.Strings[i]+']';

        not_this_one:=(Pos(full_tag_str,Ttemplate(keeps_list.Objects[n]).template_info.keep_dims.box_dims1.reference_string)=0);

        if not_this_one=True then BREAK;
      end;//next tag

      if not_this_one=True then CONTINUE;

      Ttemplate(keeps_list.Objects[n]).group_selected:=True;
    end;//next template

  finally
    this_one_tags_list.Free;

    unlink_group;
    clicked_keep_index:=-1;    // so can popup again.
    redraw_pad(True,False);
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.group_all_with_same_tag_popup_entryClick(Sender: TObject);  // 226c

var
  this_one_tags_list:TStringList;
  i,n,tag_count:integer;
  tag_str:string;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  this_one_tags_list:=TStringList.Create;

  try
    tag_count:=return_prefix_tags_list(clicked_keep_index,this_one_tags_list);    // tag_count not used

    if this_one_tags_list.Count<>1 then EXIT;   // ??? menu should not be enabled

    tag_str:=this_one_tags_list.Strings[0];

    if any_selected>0       // 226c
       then begin
              i:=alert(4,'php/330    add  templates  to  existing  group ?',
                         '`0Select all templates tagged  ['+tag_str+']  as a group.`9'
                        +'||There is an existing group of one or more templates.'
                        +'||Do you want to create a new group, or add the tagged templates to the existing group?',
                         '','','','add  to  existing  group','cancel','create  new  group',0);

              if i=5 then EXIT;

              if i=6 then clear_all_selections;  // 226c remove any existing group first
            end;

  create_group_from_tag(tag_str,True);   // True = don't alert existing group when adding each one

  finally
    this_one_tags_list.Free;

    unlink_group;
    clicked_keep_index:=-1;    // so can popup again.
    redraw_pad(True,False);
  end;//try
end;
//______________________________________________________________________________

procedure Tpad_form.group_all_with_same_marker_colour_popup_entryClick(Sender:TObject);  // 206b

var
 n,col:integer;

begin
  if (any_bgnd=0) or (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  col:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.pad_marker_colour;

  for n:=0 to keeps_list.Count-1 do begin
    with Ttemplate(keeps_list.Objects[n]) do begin
      if template_info.keep_dims.box_dims1.bgnd_code_077=-1
         then group_selected:=False   // library template???
         else group_selected:=( (template_info.keep_dims.box_dims1.pad_marker_colour=col) and (template_info.keep_dims.box_dims1.use_pad_marker_colour=True) );
    end;//with
  end;//for

  if any_selected<2 then ShowMessage('There are no other background templates matching the marker colour of this template.');

  unlink_group;
  clicked_keep_index:=-1;    // so can popup again.
  redraw_pad(True,False);
end;
//______________________________________________________________________________

procedure Tpad_form.changes_this_version_menu_entryClick(Sender: TObject);     // 223b

const
  url_str:string='https://85a.uk/templot/companion/info.php?ref=999';

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to the internet.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.changes_previous_versions_menu_entryClick(Sender: TObject);     // 223e

const
  url_str:string='https://85a.uk/templot/companion/info.php?ref=998';

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to the internet.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.music1_menu_entryClick(Sender: TObject);     // 212a

const
  url_str:string='https://radioparadise.com/player/slideshow';

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to internet radio.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.music2_menu_entryClick(Sender: TObject);     // 213a

const
  url_str:string='https://www.radionz.co.nz/audio/live/concert';

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to internet radio.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.music3_menu_entryClick(Sender: TObject);     // 227a

const
  url_str:string='https://www.bbc.co.uk/programmes/b00dnzs9';   // Ralph McLean

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to internet radio.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.music4_menu_entryClick(Sender: TObject);

const
  url_str:string='https://www.bbc.co.uk/programmes/m0019xq5';   // Radio 3 mix

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to internet radio.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.cricket_menu_entryClick(Sender: TObject);

const
  url_str:string='https://www.bbc.co.uk/sounds/play/live:bbc_radio_five_live_sports_extra';

begin
  if ShellExecute(0,'open',PChar(url_str),nil,nil,0)<=32
     then begin
            alert(2,'    connection  failed',
                    'Sorry, unable to open your browser window and connect to internet radio.',
                    '','','','','','continue',0);
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.output_page_map_help_menu_entryClick(Sender: TObject);

const
  help_preview_str:string='     `0page  map  options`9'
  +'||These menu options control which features are shown on the page map screen.'
  +'||They have no effect on the actual output.'
  +'||To control which features are included in the output, click the `0output > output elements...`1 menu item,'
  +' and also tick the option boxes for each page on the print pages dialog - on the `0options`1 and `0picture shapes`1 tabs.'
  +'||To control the order in which these features are output, click the `0background > shapes`1 menu item, and tick the option boxes on the `0general options`1 tab.';

begin
  help(0,help_preview_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.page_map_background_shapes_menu_entryClick(Sender:TObject);

begin
  page_map_background_shapes_menu_entry.Checked:= NOT page_map_background_shapes_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.page_map_sketchboard_items_menu_entryClick(Sender:TObject);

begin
  page_map_sketchboard_items_menu_entry.Checked:= NOT page_map_sketchboard_items_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.do_nothing_menu_entryClick(Sender: TObject);

begin
  do_nothing;  // added 207a
end;
//______________________________________________________________________________

procedure Tpad_form.get_colour_at_mouse_menu_entryClick(Sender: TObject);

begin
  do_show_modal(mouse_colour_form);       // 212a  ShowModal   // 208a
end;
//______________________________________________________________________________

procedure Tpad_form.v_crossings_help_menu_entryClick(Sender: TObject);

begin
  help(0,v_xing_angle_help_str+'||'+v_xing_types_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.undo_deleted_template_menu_entryClick(Sender: TObject);   // 208b

begin
  if keep_form.undo_delete_menu_entry.Enabled=False
     then begin

            alert(2,'    undo  deleted  template',
                    'rp.gif There is nothing to undo.'
                   +'||No stored template has yet been deleted from the storage box and background drawing.'
                   +'||green_panel_begin tree.gif To undo changes to the control template,'
                   +'||click the `0do > undo changes`1 menu item,|or click the <img src="'+exe_str+'internal\hlp\undo_changes.png"> button, or press `0CTRL+U`2.green_panel_end',
                    '','','','','','continue',0);
            EXIT;
          end;

  if alert(2,'    undo  deleted  template',
             'You are about to restore the most recently deleted stored template back to the storage box and background drawing.'
            +'||green_panel_begin tree.gif To undo changes to the control template,'
            +'||click the `0do > undo changes`1 menu item,|or click the <img src="'+exe_str+'internal\hlp\undo_changes.png"> button, or press `0CTRL+U`2.green_panel_end',
             '','','','','cancel  undo','undo  deleted  template',0)=5 then EXIT;

  keep_form.undo_delete_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.show_corner_info_menu_entryClick(Sender: TObject);     // 223d

begin
  show_corner_info_menu_entry.Checked:= NOT show_corner_info_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.show_margin_coordinates_menu_entryClick(Sender:TObject);  // 208g

begin
  show_margin_coordinates_menu_entry.Checked:= NOT show_margin_coordinates_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_turnout_road_exit_menu_entryClick(Sender: TObject);

   // 209a  CTRL+F12

begin
  cancel_adjusts(True);

  if plain_track=True
     then begin
            alert(6,'    CTRL+F12  adjust  turnout-road  exit',
                    '    `0CTRL+F12`2  adjust turnout-road exit'
                   +'||The control template is plain track.'
                   +'||This function is not meaningful for plain track.'
                   +'||Instead you can use the `0F4`2 mouse action to adjust the overall length of the template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if turnoutx<(xorg+min_turnout_road_endx)
     then begin
            alert(6,'    CTRL+F12  adjust  turnout-road  exit',
                    '    `0CTRL+F12`2  adjust turnout-road exit'
                   +'||The control template is not long enough to have any exit on the turnout road.'
                   +'||If you wish to adjust the turnout-road exit length, first extend the overall length using the `0F4`2 mouse action.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if retpar_i=1
     then begin
            alert(6,'    CTRL+F12  adjust  turnout-road  exit',
                    '    `0CTRL+F12`2  adjust turnout-road exit'
                   +'||The control template has a parallel V-crossing.'
                   +'||This function is not available to adjust parallel V-crossings.'
                   +'||If you wish to adjust the turnout-road exit length,|first change to a different type of V-crossing at|`0real > V-crossing options >`z menu options.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  turnout_road_i:=2;         // set control template adjustable
  turnout_i:=1;              // 209b  length needs to be locked

  redraw_pad(False,True);          // and show it like that

  mouse_action_selected('CTRL+F12    adjust  turnout-road  exit ...','CTRL+F12  turnout-road  exit',captext(xorg+turnout_road_endx)+' mm');
  turnout_road_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_main_road_exit_menu_entryClick(Sender: TObject);      // 217a

begin
  cancel_adjusts(True);

  if plain_track=True
     then begin
            alert(6,'    adjust  main-road  exit',
                    '    adjust main-road exit'
                   +'||The control template is plain track.'
                   +'||This function is not meaningful for plain track.'
                   +'||Instead you can use the `0F4`2 mouse action to adjust the overall length of the template.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if turnoutx<(xorg+min_main_road_endx)
     then begin
            alert(6,'    adjust  main-road  exit',
                    '    adjust main-road exit'
                   +'||The control template is not long enough to have any exit on the main road.'
                   +'||If you wish to adjust the main-road exit length, first extend the overall length using the `0F4`2 mouse action.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  main_road_i:=2;         // set control template adjustable
  turnout_i:=1;           // length needs to be locked

  redraw_pad(False,True);          // and show it like that

  mouse_action_selected('    adjust  main-road  exit ...','main-road  exit',captext(xorg+main_road_endx)+' mm');
  main_road_mod:=1;
end;
//______________________________________________________________________________

    // 211b  baseboards...

procedure add_baseboard_shape(factor,x2,y2:extended; name_str:string);     // add a rectangle background shape

var
  new_shape:Tbgnd_shape;
  n:integer;

begin
  new_shape:=init_bgnd_shape;  // 234b

  with new_shape do begin

    shape_name:='baseboard: '+name_str;

    hide_bits:=0;  // 214a  normal visibility
    option_bits:=0;     // byte;

    shape_code:=1;    // 1=rectangle
    shape_style:=0;   // 0=transparent/empty

    wrap_offset:=0;                   // default (used only for image wrapping)
    show_transparent:=False;          // default (used only for images)
    picture_is_metafile:=False;       // default (used only for images) //213b

    p1.x:=0;
    p1.y:=0;

    p2.x:=x2*factor;       // factor used to convert to mm
    p2.y:=y2*factor;

    rect_rot:=0;  // 234b


  end;//with

  with bgnd_form.bgnd_shapes_listbox do begin
    with Items do begin
      n:=AddObject(new_shape.shape_name,Tbgshape.Create);  // create and insert a new line in the shapes list.

      Tbgshape(Objects[n]).bgimage:=nil;  // 3-2-01.
      Tbgshape(Objects[n]).bgnd_shape:=new_shape;            // put data in list.

      ItemIndex:=n;                                          // make it current.
    end;//with
  end;//with

  pad_form.fit_shapes_menu_entry.Click;     // does redraw.

  shapes_saved:=False;   // need a fresh save.
  shapes_current_state;  // update the form.

end;
//______________________________________________________________________________


procedure Tpad_form.qb_600x300_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,600,300,'600mm x 300mm');
end;

procedure Tpad_form.qb_900x500_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,900,500,'900mm x 500mm');
end;

procedure Tpad_form.qb_1200x600_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,1200,600,'1200mm x 600mm');
end;

procedure Tpad_form.qb_1600x750_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,1600,750,'1600mm x 750mm');
end;

procedure Tpad_form.qb_2000x1000_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,2000,1000,'2000mm x 1000mm');
end;

procedure Tpad_form.qb_2400x1200_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,2400,1200,'2400mm x 1200mm');
end;

procedure Tpad_form.qb_3000x1800_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,3000,1800,'3000mm x 1800mm');
end;

procedure Tpad_form.qb_5000x3000_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,5000,3000,'5000mm x 3000mm');
end;

procedure Tpad_form.qb_7000x5000_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,7000,5000,'7000mm x 5000mm');
end;

procedure Tpad_form.qb_9000x7000_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(1,9000,7000,'9000mm x 7000mm');
end;

procedure Tpad_form.qb_2ftx1ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,24,12,'2ft x 1ft');
end;

procedure Tpad_form.qb_3ftx1ft_6in_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,36,18,'3ft x 1ft-6in');
end;

procedure Tpad_form.qb_4ftx2ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,48,24,'4ft x 2ft');
end;

procedure Tpad_form.qb_6ftx2ft_6in_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,72,30,'6ft x 2ft-6in');
end;

procedure Tpad_form.qb_8ftx4ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,96,48,'8ft x 4ft');    // 227a correction
end;

procedure Tpad_form.qb_8ftx6ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,96,72,'8ft x 6ft');
end;

procedure Tpad_form.qb_10ftx8ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,120,96,'10ft x 8ft');
end;

procedure Tpad_form.qb_15ftx10ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,180,120,'15ft x 10ft');
end;

procedure Tpad_form.qb_20ftx15ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,240,180,'20ft x 15ft');
end;

procedure Tpad_form.qb_30ftx20ft_menu_entryClick(Sender: TObject);
begin
  add_baseboard_shape(25.4,360,240,'30ft x 20ft');
end;
//______________________________________________________________________________

procedure Tpad_form.qb_other_mm_menu_entryClick(Sender: TObject);

const
  help_qbx_mm_str:string='     `0baseboard length in mm`9'
                  +'||Enter a dimension in millimetres for the length of the baseboard.'
                  +'||This is measured horizontally on the screen, from left to right.';

  help_qby_mm_str:string='     `0baseboard width in mm`9'
                  +'||Enter a dimension in millimetres for the width of the baseboard.'
                  +'||This is measured vertically on the screen, from bottom to top.';

var
  n:integer;
  od:Toutdim;

  x2,y2:extended;
  x_str,y_str:string;

begin
     putdim(help_qbx_mm_str,1,'baseboard  length',1200,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  n:=putdim(help_qby_mm_str,1,'baseboard  width',600,True,True,True,False);

  if n<>1 then EXIT;
  if getdims('other  baseboard  size  in  mm','',pad_form,n,od)=True
     then begin
            x2:=od[0];
            y2:=od[1];

            x_str:=FormatFloat('0.##',x2);
            y_str:=FormatFloat('0.##',y2);

            add_baseboard_shape(1,x2,y2,x_str+'mm x '+y_str+'mm');
          end;

end;
//______________________________________________________________________________


procedure Tpad_form.qb_other_ft_menu_entryClick(Sender: TObject);

const
  help_qbx_ft_str:string='     `0baseboard length in feet`9'
                  +'||Enter a dimension in feet for the length of the baseboard.'
                  +'||This is measured horizontally on the screen, from left to right.';

  help_qby_ft_str:string='     `0baseboard width in feet`9'
                  +'||Enter a dimension in feet for the width of the baseboard.'
                  +'||This is measured vertically on the screen, from bottom to top.';

var
  n:integer;
  od:Toutdim;

  x2,y2:extended;
  x_str,y_str:string;

begin
     putdim(help_qbx_ft_str,6,'baseboard  length',4,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  n:=putdim(help_qby_ft_str,6,'baseboard  width',2,True,True,True,False);

  if n<>1 then EXIT;
  if getdims('other  baseboard  size  in  feet','',pad_form,n,od)=True
     then begin
            x2:=od[0];
            y2:=od[1];

            x_str:=FormatFloat('0.##',x2);
            y_str:=FormatFloat('0.##',y2);

            add_baseboard_shape(304.8,x2,y2,x_str+'ft x '+y_str+'ft');
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.qb_other_inch_menu_entryClick(Sender: TObject);

const
  help_qbx_in_str:string='     `0baseboard length in inches`9'
                  +'||Enter a dimension in inches for the length of the baseboard.'
                  +'||This is measured horizontally on the screen, from left to right.';

  help_qby_in_str:string='     `0baseboard width in inches`9'
                  +'||Enter a dimension in inches for the width of the baseboard.'
                  +'||This is measured vertically on the screen, from bottom to top.';

var
  n:integer;
  od:Toutdim;

  x2,y2:extended;
  x_str,y_str:string;

begin
     putdim(help_qbx_in_str,2,'baseboard  length',48,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  n:=putdim(help_qby_in_str,2,'baseboard  width',24,True,True,True,False);

  if n<>1 then EXIT;
  if getdims('other  baseboard  size  in  inches','',pad_form,n,od)=True
     then begin
            x2:=od[0];
            y2:=od[1];

            x_str:=FormatFloat('0.##',x2);
            y_str:=FormatFloat('0.##',y2);

            add_baseboard_shape(25.4,x2,y2,x_str+'in x '+y_str+'in');
          end;

end;
//______________________________________________________________________________

procedure Tpad_form.qb_help_menu_entryClick(Sender: TObject);

const
  qb_help_str:string='php/410    `0  quick  baseboard  outlines`9'
  +'||green_panel_begin tree.gif  These menu options provide a shortcut to the|`0background shapes`3 functions, to add one or more simple rectangle shapes as baseboard outlines.'
  +'||More complex baseboard outlines can be created using the full background shapes functions, or by using the `0sketchboard`3.green_panel_end'
  +'|Baseboard outlines added this way will have their bottom-left corner initially located at the grid origin position (0mm, 0mm).'
  +'||After adding a baseboard outline, it can be adjusted for size or position by mouse action using the|`0action > mouse actions: shapes >`1 menu items.'
  +'||Or by using the mouse action buttons on the background shapes dialog at `0modify shape > mouse actions:`1.'
  +'||green_panel_begin tree.gif If you have added baseboard outlines remember to save your background shapes before quitting Templot.'
  +'||If you name the file `0start.bgs3`f it will be loaded automatically when you start the next Templot session.green_panel_end'
  +'|You can change the colour and line thickness for the displayed outline(s) by clicking the|`0background > quick baseboard outline > other sizes and options`1 menu items.'
  +'||To see the full background shapes functions and options click the button below, or click the|`0background > shapes`1 menu item.';

begin
  if help(0,qb_help_str,'go  to  background  shapes')=1 then bgnd_shapes_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.qb_colour_menu_entryClick(Sender: TObject);

begin
  shapes_colour_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.qb_thin_lines_menu_entryClick(Sender: TObject);

begin
  bgnd_form.pad_shapes_linewidth_1_radiobutton.Checked:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.qb_medium_lines_menu_entryClick(Sender: TObject);

begin
  bgnd_form.pad_shapes_linewidth_2_radiobutton.Checked:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.qb_thick_lines_menu_entryClick(Sender: TObject);

begin
  bgnd_form.pad_shapes_linewidth_3_radiobutton.Checked:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.qb_options_menu_entryClick(Sender: TObject);

  // radio items...

begin
  qb_thin_lines_menu_entry.Checked:=bgnd_form.pad_shapes_linewidth_1_radiobutton.Checked;
  qb_medium_lines_menu_entry.Checked:=bgnd_form.pad_shapes_linewidth_2_radiobutton.Checked;
  qb_thick_lines_menu_entry.Checked:=bgnd_form.pad_shapes_linewidth_3_radiobutton.Checked;

  do_rollback:=False;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.reload_shapes_menu_entryClick(Sender: TObject);   // 212a

begin
  load_shapes('',False,False,False);
end;
//______________________________________________________________________________

procedure Tpad_form.add_shapes_menu_entryClick(Sender: TObject);   // 212a

begin
  load_shapes('',True,False,False);
end;
//______________________________________________________________________________

procedure Tpad_form.save_shapes_menu_entryClick(Sender: TObject);  // 212a

begin
  bgnd_form.save_all_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.experimental_chairing_menu_entryClick(Sender: TObject);  // 214a

begin
  if alert(2,'    experimental  3D  chairing',
             'It is now possible to have some REA bullhead chair positions shown on the trackpad templates,'
             +' and for exported 3-D DXF and STL files to contain REA chair detail suitable for CAD rendering, 3D printing, CNC milling, and laser cutting.'
             +'||rp.gif In order for the 3-D chair detail to be generated correctly, it is necessary for the rail section data in the templates to match the model rail section currently selected on the DXF dialog.'
            +' This means the rail height and the rail head and foot widths.'
            +'||green_panel_begin tree.gif &nbsp;If you continue your current rail section data set at `0real > rails >`1 will be ignored.||Rails will be vertical - any rail inclination angle will be ignored.green_panel_end'
            +'|At present this function is fully functional only for plain track and turnout templates. Chairing of half-diamond templates is incomplete.'
            +'||At present the chair outlines are not shown on printed construction templates, exported PDF and image files, or on the sketchboard.'
            +'||rp.gif  This function is still an experimental work in progress and subject to much further development and change. For updated information please refer to the Templot Club user forum.'
            +'||rp.gif  Please be aware that this function is likely to slow down the screen response significantly. It would be wise to leave this function switched off while doing track design work. It is intended for the final output only.'
            +'||Your feedback is welcome. Thanks.',
             '','','','','cancel','do  experimental  chairing',0)=5 then EXIT;


  experimental_chairing_menu_entry.Checked:=True;           // radio item
  rebuild_group_to_match_chairs_menu_entry.Enabled:=True;

  exp_chairing:=True;

  brick_form.bgnd_chairs_checkbox.Checked:=True;  // 232a  assume he wants to see them all

  brick_form.Show;

  redraw(False);
end;
//______________________________________________________________________________

procedure Tpad_form.no_chairing_menu_entryClick(Sender: TObject);  // 214a

begin
  no_chairing_menu_entry.Checked:=True;  // radio item
  exp_chairing:=False;

  heave_chairs_form.Hide;  // 244a

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.template_is_waybeams_menu_entryClick(Sender: TObject);

begin
  waybeams_template:= NOT waybeams_template;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.use_S1J_at_wing_front_menu_entryClick(Sender: TObject);

begin
  cpi.s1j_on_wing_pi:= NOT cpi.s1j_on_wing_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.use_all_S1J_on_switch_front_menu_entryClick(Sender: TObject);

begin
  cpi.s1j_on_j1_pi:= NOT cpi.s1j_on_j1_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.slab_bracket_menu_entryClick(Sender: TObject);

begin
  cpi.slab_bracket_pi:=True;  // 239a       // radio item

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.cast_a_chair_menu_entryClick(Sender: TObject);

begin
  cpi.slab_bracket_pi:=False;  // 239a

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.add_nose_clamp_menu_entryClick(Sender: TObject);

begin
  cpi.nose_clamp_pi:= NOT cpi.nose_clamp_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.add_xing_gap_filler_menu_entryClick(Sender: TObject);

begin
  cpi.xing_filler_pi:= NOT cpi.xing_filler_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.ms_snibs_menu_entryClick(Sender: TObject);

begin
  cpi.ms_snibs_pi:= NOT cpi.ms_snibs_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.ts_snibs_menu_entryClick(Sender: TObject);

begin
  cpi.ts_snibs_pi:= NOT cpi.ts_snibs_pi;
  
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.include_key_with_outers_menu_entryClick(Sender: TObject);

begin
  cpi.keys_on_outer_jaws_pi:= NOT cpi.keys_on_outer_jaws_pi;

  if cpi.keys_on_outer_jaws_pi=False
     then begin
            if alert(3,'    experimental  chairing  -  omit  chair  keys',
                       'You have removed the keys from every chair on this template.'
                      +'||This means that the rail will not fit the chairs properly.'
                      +'||green_panel_begin tree.gif  This option is provided for cases where you want to construct a chair manually, and also to create model chair castings for wagon loads and other scenic purposes.',
                       '','','','','cancel  -  restore  chair  keys','continue',0)=5 then cpi.keys_on_outer_jaws_pi:=True;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.add_rail_seat_menu_entryClick(Sender: TObject);

begin
  cpi.rail_seats_pi:= NOT cpi.rail_seats_pi;

  if cpi.rail_seats_pi=False
     then begin
            if alert(3,'    experimental  chairing  -  omit  rail  seats',
                       'You have removed the rail seats from every chair on this template.'
                      +'||This means that the rail will not fit the chairs and will be unsupported in them.'
                      +'||green_panel_begin tree.gif  This option is provided for cases where you want to construct a chair manually from a plain chair base, typically on a short partial template.green_panel_end',
                       '','','','','cancel  -  restore  rail  seats','continue',0)=5 then cpi.rail_seats_pi:=True;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.use_all_bridge_chairs_menu_entryClick(Sender: TObject);

begin
  use_all_bridge_chairs:= NOT use_all_bridge_chairs;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.allow_parallel_wing_DD_menu_entryClick(Sender: TObject);

begin
  cpi.temp_dd_parallel_wing_pi:= NOT cpi.temp_dd_parallel_wing_pi;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.temp_use_wrong_chairs_menu_entryClick(Sender: TObject);   // 244a

begin
  cpi.temp_wrong_k_xing_pi:= NOT cpi.temp_wrong_k_xing_pi;

  redraw(True)
end;
//______________________________________________________________________________

procedure Tpad_form.use_all_SC_menu_entryClick(Sender: TObject);

begin
  use_all_SC_chairs:= NOT use_all_SC_chairs;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.use_all_RG_menu_entryClick(Sender: TObject);    // 234a

begin
  use_all_RG_chairs:= NOT use_all_RG_chairs;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.use_all_FG_menu_entryClick(Sender: TObject);    // 234a

begin
  use_all_FG_chairs:= NOT use_all_FG_chairs;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.use_custom_switch_opening_menu_entryClick(Sender: TObject);

begin
  use_custom_switch_opening:= NOT use_custom_switch_opening;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.set_custom_switch_opening_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim('please refer to Templot Club forum',2,'custom  switch  opening  ( full-size  inches )',custom_switch_opening,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.

  if n<>0 then EXIT;

  if getdims('custom  switch  opening ...','',pad_form,n,od)=True
     then begin
            custom_switch_opening:=od[0];

            use_custom_switch_opening:=True;
          end;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.key_offset_max_menu_entryClick(Sender: TObject);

var
  n:integer;
  od:Toutdim;

begin
     putdim('please refer to Templot Club forum',2,'NORMAL  key  off-centre  by  max  ( full-size  inches )',normal_chair_key_max_offset,True,True,False,False);   // no negative, no preset, zero ok, don't terminate on zero.
  n:=putdim('please refer to Templot Club forum',2,'COT  key  off-centre  by  max  ( full-size  inches )',cot_chair_key_max_offset,True,True,False,False);      // no negative, no preset, zero ok, don't terminate on zero.

  if n<>1 then EXIT;

  if getdims('chair  key  off-centre  maximum ...','',pad_form,n,od)=True
     then begin
            normal_chair_key_max_offset:=od[0];
            cot_chair_key_max_offset:=od[1];         // 555a MW
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.chairs_baseplates_menu_entryClick(Sender: TObject);

begin
  experimental_chairing_menu_entry.Checked:=exp_chairing;                         // experimental chairs  // radio items
  no_chairing_menu_entry.Checked:= NOT experimental_chairing_menu_entry.Checked;

  use_S1J_at_wing_front_menu_entry.Checked:=cpi.s1j_on_wing_pi;

  use_all_S1J_on_switch_front_menu_entry.Checked:=cpi.s1j_on_j1_pi;

  slab_bracket_menu_entry.Checked:=cpi.slab_bracket_pi;     // 239a     radio items
  cast_a_chair_menu_entry.Checked:= NOT cpi.slab_bracket_pi;

  variable_ccl_ccr_menu_entry.Checked:=cpi.ccl_ccr_variable_pi;    // 243a  CCL CCR check end chairs variable size
  fixed_ccl_ccr_menu_entry.Checked:= NOT cpi.ccl_ccr_variable_pi;  // 243a  CCL CCR check end chairs fixed size

  add_nose_clamp_menu_entry.Checked:=cpi.nose_clamp_pi;        // 241a
  add_xing_gap_filler_menu_entry.Checked:=cpi.xing_filler_pi;  // 241a

  allow_parallel_wing_DD_menu_entry.Checked:=cpi.temp_dd_parallel_wing_pi;  // 244a

  temp_use_wrong_chairs_menu_entry.Checked:=cpi.temp_wrong_k_xing_pi;   // 244a temporary for customizing

  include_key_with_outers_menu_entry.Checked:=cpi.keys_on_outer_jaws_pi;

  add_rail_seat_menu_entry.Checked:=cpi.rail_seats_pi;

  ts_snibs_menu_entry.Checked:=cpi.ts_snibs_pi;     // 244a
  ms_snibs_menu_entry.Checked:=cpi.ms_snibs_pi;     // 244a

  use_all_bridge_chairs_menu_entry.Checked:=use_all_bridge_chairs;


  use_all_SC_menu_entry.Checked:=use_all_SC_chairs;    // 237a

  use_all_RG_menu_entry.Checked:=use_all_RG_chairs;    // 234a
  use_all_FG_menu_entry.Checked:=use_all_FG_chairs;    // 234a

  keys_to_joint_menu_entry.Checked:=keys_towards_joint;
  use_custom_switch_opening_menu_entry.Checked:=use_custom_switch_opening;

  keys_to_joint_menu_entry.Checked:=(key_direction=0) and (keys_towards_joint=True);    // radio items ...
  keys_random_menu_entry.Checked:=(key_direction=0) and (keys_towards_joint=False);
  keys_forwards_menu_entry.Checked:=(key_direction=1);
  keys_backwards_menu_entry.Checked:=(key_direction=-1);

  template_is_waybeams_menu_entry.Checked:=waybeams_template;   // 235a
end;
//______________________________________________________________________________

procedure Tpad_form.keys_random_menu_entryClick(Sender: TObject);

begin
  keys_random_menu_entry.Checked:=True;   // radio item
  key_direction:=0;
  keys_towards_joint:=False;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.keys_forwards_menu_entryClick(Sender: TObject);

begin
  keys_forwards_menu_entry.Checked:=True;   // radio item
  key_direction:=1;
  keys_towards_joint:=False;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.keys_backwards_menu_entryClick(Sender: TObject);

begin
  keys_backwards_menu_entry.Checked:=True;   // radio item
  key_direction:=0-1;
  keys_towards_joint:=False;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.keys_to_joint_menu_entryClick(Sender: TObject);

begin
  keys_to_joint_menu_entry.Checked:=True;   // radio item
  key_direction:=0;
  keys_towards_joint:=True;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.pad_window_proc(var msg:TMessage);       // 214a

begin
  if msg.Msg=WM_DROPFILES
     then pad_file_drop(TWMDROPFILES(msg))
     else original_pad_window_proc(msg);
end;
//______________________________________________________________________________

procedure Tpad_form.pad_file_drop(var msg:TWMDROPFILES);    // 214a

const
  dropped_picture_str:string='        `0New  Picture  Shape`9'
  +'||A new picture shape has been created for the dropped image file:||';

var
  num_files:integer;
  buffer:array[0..MAX_PATH] of char;

  dropped_file_name,dropped_file_ext:string;

  dropped_picture:TPicture;

  i:integer;

  her_file_name_str:string;

            ////////////////////////////////////////////////////////////////////

            procedure load_dropped_box_file;

            var
              append:boolean;
              i,hl,old_count:integer;

            begin
              append:=False;  // init
              hl:=0;          // init

              old_count:=keeps_list.Count;  // init

              if keeps_list.Count>0
                 then begin

                        if save_done=False     // not saved...
                           then begin
                                  i:=alert(7,'reload  storage  box  from  dropped  file  -  save  first ?',
                                             'Dropped file:'
                                            +'||`0'+her_file_name_str+'`f'
                                            +'||Your storage box contains one or more templates which have not yet been saved.'
                                            +'||Reloading your storage box from the dropped file will replace all of the existing contents and the background track plan drawing.'
                                            +'||These templates can be restored by clicking the `0FILES > UNDO RELOAD / UNDO CLEAR`1 menu item.'
                                            +' But if any of these templates may be needed again, you should save them in a named data file.'

                                            +'||Do you want to save the existing contents before reloading?'
                                            +'||Or add the new templates from the dropped file to the existing contents instead?',
                                             '','','add  new  templates  to  existing','replace  existing  contents  without  saving','cancel  drop','save  existing  contents  before  reloading',0);
                                  case i of
                                     3: append:=True;
                                     5: EXIT;
                                     6: if save_box(0,0,0,'')=False then EXIT;     // go save all the keeps box.
                                  end;//case
                                end
                           else begin      //  it has been saved...
                                  i:=alert(7,'reload  storage  box  from  dropped  file  -  clear  first ?',
                                             'Dropped file:'
                                            +'||`0'+her_file_name_str+'`f'
                                            +'||Your storage box contains one or more existing templates.'
                                            +'||Reloading your storage box from the dropped file will replace all of the existing contents and the background track plan drawing.'
                                            +'||These templates can be restored by clicking the `0FILES > UNDO RELOAD / UNDO CLEAR`1 menu item.'
                                            +'||Are you sure you want to replace the existing templates?'
                                            +'||Or add the new templates from the dropped file to the existing contents instead?',
                                             '','','','add  new  templates  to  existing','cancel  drop','replace  existing  contents',0);
                                  case i of
                                     4: append:=True;
                                     5: EXIT;
                                  end;//case
                                end;
                      end;

              try

                if load_storage_box(True,False,dropped_file_name,False,False,append,hl)=True  // hl= highest loaded index
                   then begin
                          if keeps_list.Count>0
                             then begin
                                    if append=False
                                       then begin
                                              save_done:=True;  // box contents matches loaded file.
                                              keep_form.box_file_label.Caption:=' last reloaded from :  '+dropped_file_name;
                                              keep_form.box_file_label.Hint:=keep_form.box_file_label.Caption;  // in case too long for caption
                                            end
                                       else begin
                                              if keeps_list.Count>old_count
                                                 then begin
                                                        save_done:=False;
                                                        keep_form.box_file_label.Caption:=' last added from :  '+dropped_file_name;
                                                        keep_form.box_file_label.Hint:=keep_form.box_file_label.Caption;  // in case too long for caption
                                                      end;
                                            end;

                                    reloaded_box_str:=reloaded_box_str+'|    '+dropped_file_name; // for print of box contents list.

                                    if append=True then EXIT;
                                    if (loaded_version<93) and (hl>-1) and (hl<keeps_list.Count) then mint_final_or_copy_control(hl);   // if something loaded mint from highest bgnd if he so wants.
                                    if (loaded_version>92) then mint_final_or_copy_control(hl);                                         // copy the control template if there is one in the file.
                                  end;
                        end
                   else ShowMessage('Sorry, an error occurred in loading the dropped .box file.');

              finally
                redraw_pad(True,False);
              end;//try
            end;
            ////////////////////////////////////////////////////////////////////

            procedure add_dropped_picture_shape(hlp_str:string);

            var
              new_shape:Tbgnd_shape;
              n:integer;
              succesful:boolean;

            begin

              succesful:=False;  // init

              new_shape:=init_bgnd_shape;  // 234b

              with new_shape do begin

                shape_code:=-1;   // -1=picture
                shape_style:=0;   // not used

                wrap_offset:=0;               // default
                show_transparent:=False;      // default
                picture_is_metafile:=False;   // default

                shape_name:='picture';        // name or label

                hide_bits:=0;  // normal visibility
                option_bits:=0;     // byte;

                p1.x:=mouse_now_x;     // dropped position is p1.
                p1.y:=mouse_now_y;

                p2.x:=p1.x+screenx*2/5;     // arbitrary
                p2.y:=p1.y+screenx*9/40;    // default 16:9 aspect ratio (modified on loading)

                rect_rot:=0;  // 234b
              end;//with

              with bgnd_form.bgnd_shapes_listbox do begin

                n:=Items.AddObject(new_shape.shape_name,Tbgshape.Create);  // create and insert a new entry in the shapes list.

                Tbgshape(Items.Objects[n]).bgnd_shape:=new_shape;      // put data in list.

                ItemIndex:=n;                                          // make it current.

                with Tbgshape(Items.Objects[n]) do begin

                  bgnd_shape.show_transparent:=False;

                  bgimage:=Tbgimage.Create;     // create new image  3-2-01.

                  with bgimage.image_shape do begin

                    image_bitmap:=TBitmap.Create;
                    rotated_bitmap:=TBitmap.Create;

//OT2024                    image_metafile:=TMetafile.Create;    // 213b
//OT2024                    rotated_metafile:=TMetafile.Create;  // 213b

                    rotated_picture:=TPicture.Create;

                    try
(* OT2024
                      if dropped_picture.Graphic is TMetafile
                         then begin

                                  // OT2024 out...

                                image_bitmap.Width:=200;            // arbitrary.
                                image_bitmap.Height:=150;           // arbitrary.

                                image_width:=image_bitmap.Width;
                                image_height:=image_bitmap.Height;

                                with image_bitmap.Canvas do begin     // blank the picture area...
                                  Brush.Color:=clWhite;
                                  Brush.Style:=bsSolid;
                                  FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
                                end;//with

                                bgnd_shape.picture_is_metafile:=False;

                                show_modal_message('Sorry, unable to create picture shape from the dropped image.');

{OT2024                        image_metafile.Assign(dropped_picture.Graphic);

                                image_width:=image_metafile.Width;
                                image_height:=image_metafile.Height;

                                bgnd_shape.picture_is_metafile:=True;
}
                              end
                         else begin
*)

                                bgnd_shape.picture_is_metafile:=False;

                                if dropped_picture.Graphic is TIcon    // convert it to bitmap
                                   then begin
                                          image_bitmap.Width:=dropped_picture.Graphic.Width;
                                          image_bitmap.Height:=dropped_picture.Graphic.Height;

                                          image_bitmap.Canvas.Draw(0,0,dropped_picture.Graphic);
                                        end
                                   else image_bitmap.Assign(dropped_picture.Graphic);

                                image_width:=image_bitmap.Width;
                                image_height:=image_bitmap.Height;

                                if image_bitmap.PixelFormat<>pf8bit then image_bitmap.PixelFormat:=pf24bit;    // 215b  down from 32bit for deep zooming (also workaround for TPngImage on lower than 8bit)

// OT2024                              end;

                      with bgnd_shape do p2.y:=p1.y+(p2.x-p1.x)*image_height/image_width;   // adjust height to aspect ratio of loaded image

                      succesful:=True;

                    except
                      image_bitmap.Width:=200;            // arbitrary.
                      image_bitmap.Height:=150;           // arbitrary.

                      image_width:=image_bitmap.Width;
                      image_height:=image_bitmap.Height;

                      with image_bitmap.Canvas do begin     // blank the picture area...
                        Brush.Color:=clWhite;
                        Brush.Style:=bsSolid;
                        FillRect(Rect(0,0,image_bitmap.Width,image_bitmap.Height));
                      end;//with

                      bgnd_shape.picture_is_metafile:=False;

                      show_modal_message('Sorry, unable to create picture shape from the dropped image.');
                    end;//try

                  end;//with
                end;//with
              end;//with

              shapes_saved:=False;      // need a resave.
              shapes_current_state;
              do_rollback:=False;       // no need to put this change in rollback register on redraw.

              redraw(False);                                                      // changes to default pad cursor.
              if check_grey_paper=False then pad_form.Cursor:=cross_hairs_cursor; // so change it back again.

              if succesful=True
                 then begin
                        do_bgnd(True);  // show background shapes dialog with modify shape tab active

                        if yellow_msg_pref=False
                           then begin
                                  bgnd_form.new_picture_shape1.Visible:=True;  // show him which buttons to use (yellow patch)
                                  bgnd_form.new_picture_shape2.Visible:=True;
                                  bgnd_form.new_picture_shape3.Visible:=True;

                                  if help(0,hlp_str,'don''t  show  this  again')=1 then yellow_msg_pref:=True;
                                end;
                      end;
            end;
            ////////////////////////////////////////////////////////////////////

begin

  her_file_name_str:='';   // keep compiler happy

  num_files:=DragQueryFile(msg.Drop,$FFFFFFFF,nil,0);
  if num_files>1
     then begin
            show_modal_message('error - attempt to drop more than one file');
            EXIT;
          end;

  DragQueryFile(msg.Drop,0,@buffer,SizeOf(buffer));

  her_file_name_str:=buffer;

  dropped_file_name:=change_jpeg_filename(buffer);   // if nec       full path to file

  dropped_file_ext:=LowerCase(ExtractFileExt(dropped_file_name));

  if dropped_file_ext='.box' then load_dropped_box_file     // load or add .box file

  else if dropped_file_ext='.bgs3' then load_shapes(dropped_file_name,False,False,True)

 (* OT2024
  else if dropped_file_ext='.sk9'
          then begin
                 if dtp_form.dtp_document.Modified=True
                    then begin
                           i:=alert(4,'php/501    dropped  sketchboard  file  -  save  first?',
                                      'There are unsaved changes on the sketchboard which will be lost if not saved.'
                                     +'||Do you want to save them before reloading the sketchboard from the dropped file?',
                                      '','','','no  -  load  dropped  file  without  saving','cancel','yes  -  save  first',0);
                           if i=5 then EXIT;

                           if i=6 then dtp_form.save_dtp_as_menu_entry.Click;
                         end;

                 load_sketchboard_file(dropped_file_name);
               end
 *)

  else begin   // image file

         dropped_picture:=TPicture.Create;

         try
           dropped_picture.LoadFromFile(dropped_file_name);
           add_dropped_picture_shape(dropped_picture_str+'`0'+her_file_name_str+'`f||The '+picture_buttons_str);
         except
           on EInvalidGraphic do begin
             ShowMessage('error - the '+dropped_file_ext+' file format is not supported');
           end;//on
         end;//try

         dropped_picture.Free;
       end;
end;
//______________________________________________________________________________

procedure Tpad_form.files_print_menu_entryClick(Sender: TObject);

const
  str:string='      `0printing from Templot`9'
  +'||The full range of printing functions are on the `0OUTPUT`1 menu. You can see a preview of the page map, select which pages to print, and change the settings.'
  +'||Or for a quick print, by-passing all the previews and settings, click instead the `0print-now!`1 menu items.'
  +'||Or you can click the button below if you simply want a quick print of the control template now.'
  +'||If you are new to Templot, the control template is the one you have been adjusting.';

begin
  if help(0,str,'print  the  control  template  now !')=1 then print_control_now_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.go_to_my_documents_menu_entryClick(Sender: TObject);

begin
  open_MyDocuments;   // 214a
end;
//______________________________________________________________________________

procedure Tpad_form.expert_picture_help_menu_entryClick(Sender: TObject);

const
  str:string='php/401      `0Background  Images`9'
  +'||Background images can be displayed on the trackpad. They are called `0picture shapes`3.'
  +'||The usual reason for doing that is to use them as a guide to Templot track planning.'

  +'|||Images which you have scanned from sketches, maps, and model track plans can be scaled (re-sized) automatically to match your model scale.'
  +'||For full explanations and options click `0add your own map or background image ...`1 menu item.'

  +'|||Maps and aerial images can also be captured as screenshots from many web sites. In many cases Templot can make the screenshot for you, and scale (re-size) it automatically to match your model scale.'
  +'||For more about this, click the `0background > maps`1 menu item, or click the `0read about maps on Templot Companion`z button below.'

  +'|||Templot can also load some types of map directly from the web without making screenshots, and scale (re-size) them automatically to match your model scale.'
  +' These maps are comprised of multiple small picture shapes, each one containing a map "tile".'
  +'||Unlike screenshots, such tiled maps are not limited by the size of your computer screen. The map area can be easily enlarged by adding additional rows or columns of tiles, to any size.'
  +'||For more details click the `0background > maps`1 menu item, or click the `0read about maps on Templot Companion`z button below.'

  +'||||Alternatively if you know what you are doing, click `0add a picture shape quick ... (expert)`1 menu item.| ';

begin
  if help(0,str,'read  about  maps  on  Templot  Companion')=1 then go_to_url('https://85a.uk/templot/companion/get_map_from_the_web.php');
end;
//______________________________________________________________________________

procedure Tpad_form.add_picture_expert_menu_entryClick(Sender: TObject);

begin
  add_picture_expert;  // bgnd_unit
end;
//______________________________________________________________________________

procedure Tpad_form.knuckle_bend_menu_entryClick(Sender: TObject);

begin
  case knuckle_code of
    -1: sharp_knuckle_menu_entry.Checked:=True;    // radio item
     0: normal_knuckle_menu_entry.Checked:=True;   // radio item
     1: custom_knuckle_menu_entry.Checked:=True;   // radio item
  end;//case
end;
//______________________________________________________________________________

procedure Tpad_form.sharp_knuckle_menu_entryClick(Sender: TObject);

begin
  knuckle_code:=-1;      // 214a  0=normal, -1=sharp, 1=use custom knuckle radius
  redraw(True);
end;
//______________________

procedure Tpad_form.normal_knuckle_menu_entryClick(Sender: TObject);

begin
  knuckle_code:=0;      // 214a  0=normal, -1=sharp, 1=use custom knuckle radius
  redraw(True);
end;
//______________________

procedure Tpad_form.custom_knuckle_menu_entryClick(Sender: TObject);

begin
  knuckle_code:=1;      // 214a  0=normal, -1=sharp, 1=use custom knuckle radius
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.knuckle_help_menu_entryClick(Sender: TObject);

begin
  companion_help('knuckle_radius.php');
end;
//______________________________________________________________________________

procedure Tpad_form.custom_knuckle_radius_menu_entryClick(Sender: TObject);

const
  knuckle_help_str:string='    `0custom  knuckle  bend  radius`9'
  +'||Enter a custom dimension in full-size prototype INCHES for the radius in the wing rail at the knuckle bend.'
  +'||In order for your custom radius to be used the `0custom`1 option setting must be selected in the menu.'
  +'||The `0normal`1 option setting causes the bend radius to match the V-crossing angle in feet. For example a 1:7 V-crossing has a knuckle bend radius of 7ft (84 inches).'
  +'||Do not enter a zero radius - instead select the `0sharp`1 option setting.';

var
  n:integer;
  od:Toutdim;

begin
  n:=putdim(knuckle_help_str,2,'custom  knuckle  bend  radius',knuckle_radius,True,True,True,False);   // no negative, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;
  if getdims('custom  knuckle  bend  radius','',pad_form,n,od)=True
     then begin
            knuckle_radius:=od[0];
            knuckle_code:=1;         // use it
          end;
          
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.printing_page_map_records_menu_entryClick(Sender:TObject);

var
  folder_str:string;

begin
  folder_str:=exe_str+'PRINT-PAGEMAP-RECORD-FILES\';

  if ShellExecute(0,'explore',PChar(folder_str),nil,nil,SW_SHOWNORMAL)<=32
     then ShowMessage('Sorry, unable to open the folder.')
     else external_window_showing:=True;
end;
//______________________________________

procedure Tpad_form.pdf_page_map_records_menu_entryClick(Sender:TObject);

var
  folder_str:string;

begin
  folder_str:=exe_str+'PDF-PAGEMAP-RECORD-FILES\';

  if ShellExecute(0,'explore',PChar(folder_str),nil,nil,SW_SHOWNORMAL)<=32
     then ShowMessage('Sorry, unable to open the folder.')
     else external_window_showing:=True;
end;
//______________________________________

procedure Tpad_form.page_map_records_help_menu_entryClick(Sender: TObject);

begin
//
end;
//______________________________________________________________________________

procedure Tpad_form.scaling_trackbarChange(Sender: TObject);   // 214c

begin
  if pad_form.Showing then scaling_labels_panel.Visible:=True;
  current_scaling_position:=scaling_trackbar.Position;
end;
//______________________________________________________________________________

procedure Tpad_form.scaling_trackbarEnter(Sender: TObject);   // 214c

begin
  scaling_labels_panel.Visible:=True;
end;
//______________________________________________________________________________

procedure hide_program_size_controls;  // 223c

begin
  pad_form.scaling_help_static.Hide;
  pad_form.scaling_trackbar.Hide;
  pad_form.scaling_labels_panel.Hide;
end;
//______________________________________________________________________________

procedure Tpad_form.scaling_help_staticMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X,Y:Integer);

const
  str:string='php/995    `0Change  Program  Size`9'
            +'||Program size means the size of Templot''s dialog windows, buttons, text, etc.'
            +'||Using the vertical slider the program size can be changed to be more comfortable on your screen, for example on tablet computers or on wide-screen monitors.'
            +' The program size setting has no effect on track design.'
            +'||You can hide the slider by clicking the bar below, or by right-button clicking on the `0?`2 icon. To see it again you will need to restart Templot.'
            +'|||The available sizes are:'
            +'||<i>smallest - smaller - small - medium - large - larger - largest</i>'
            +'||The actual sizes these represent will be determined by your current Windows screen settings.'
            +'||If you are currently using the <i>medium</i> size, the change to any other size will take place immediately when you click the `0change`1 button.'
            +'||Otherwise the change will take place after you next quit and restart Templot. Remember to save your work first.';

begin
  if Button=mbRight   // 223c
     then begin
            hide_program_size_controls;
            EXIT;
          end
     else begin
            scaling_labels_panel.Visible:=True;
            if help(0,str,'hide  the  program  size  controls')=1 then hide_program_size_controls;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.Label1Click(Sender: TObject);
begin
  scaling_trackbar.Position:=1;
end;

procedure Tpad_form.Label2Click(Sender: TObject);
begin
  scaling_trackbar.Position:=2;
end;

procedure Tpad_form.Label3Click(Sender: TObject);
begin
  scaling_trackbar.Position:=3;
end;

procedure Tpad_form.Label4Click(Sender: TObject);
begin
  scaling_trackbar.Position:=4;
end;

procedure Tpad_form.Label5Click(Sender: TObject);
begin
  scaling_trackbar.Position:=5;
end;

procedure Tpad_form.Label6Click(Sender: TObject);
begin
  scaling_trackbar.Position:=6;
end;

procedure Tpad_form.Label7Click(Sender: TObject);
begin
  scaling_trackbar.Position:=7;
end;
//______________________________________________________________________________

procedure Tpad_form.scaling_change_buttonClick(Sender: TObject);

var
  i:integer;
  str,prev_str:string;


                          //////////////////////////////////////////////////////

                          procedure save_scaling_to_file;

                          var
                            sz_str:string;
                            sz_list:TStringList;

                          begin
                            sz_str:=ExtractFilePath(Application.ExeName)+'internal\dpi\sz.szx';
                            sz_list:=TStringList.Create;

                            sz_list.Text:=IntToStr(current_scaling_position);

                            sz_list.SaveToFile(sz_str);

                            sz_list.Free;
                          end;
                          //////////////////////////////////////////////////////

begin
  scaling_labels_panel.Visible:=False;

  if current_scaling_position=old_scaling_position then EXIT;

  case current_scaling_position of

         1: str:='largest';    // top to bottom of trackbar
         2: str:='larger';
         3: str:='large';
         4: str:='medium';
         5: str:='small';
         6: str:='smaller';
         7: str:='smallest';
       else str:='medium';

  end;//case

  case old_scaling_position of

         1: prev_str:='largest';    // top to bottom of trackbar
         2: prev_str:='larger';
         3: prev_str:='large';
         4: prev_str:='medium';
         5: prev_str:='small';
         6: prev_str:='smaller';
         7: prev_str:='smallest';
       else prev_str:='medium';

  end;//case

  if scaling_done_at_least_once=False
     then begin      // immediate

            i:=alert(2,'php/995     change  program  size to  '+str+' ?',
                      'Program size means the size of Templot''s dialog windows, buttons, text, etc.'
                      +'||The program size can be changed to be more comfortable on your screen, for example on tablet computers or on wide-screen monitors.'
                      +'||The program size setting has no effect on track design.'
                      +'||The available sizes are:'
                      +'||<i>smallest - smaller - small - medium - large - larger - largest</i>'
                      +'||The actual sizes these represent will be determined by your current Windows screen settings.'
                      +'||The current program size is `0'+prev_str+'`3.'
                      +'||The program size will be changed to `0'+str+'`3 when you click `0yes`1 below. Changing back to any other size afterwards will require you to quit and restart Templot.'
                      +'||Change  program  size to  `0'+str+'`3 ?',

                      '','','','','no  -  cancel','yes',0);

            if i=5
               then begin
                      current_scaling_position:=old_scaling_position;
                      pad_form.scaling_trackbar.Position:=current_scaling_position;

                      EXIT;
                    end;

            save_scaling_to_file;

            do_dpi_aware_scaling(current_scaling_position);
          end
     else begin      // on restart


            i:=alert(2,'php/995     change  program  size to  '+str+' ?',
                      'Program size means the size of Templot''s dialog windows, buttons, text, etc.'
                      +'||The program size can be changed to be more comfortable on your screen, for example on tablet computers or on wide-screen monitors.'
                      +'||The program size setting has no effect on track design.'
                      +'||The available sizes are:'
                      +'||<i>smallest - smaller - small - medium - large - larger - largest</i>'
                      +'||The actual sizes these represent will be determined by your current Windows screen settings.'
                      +'||The current program size is `0'+prev_str+'`3.'
                      +'||The program size will be changed to `0'+str+'`3 after you next quit and restart Templot. Remember to save your work first.'
                      +'||Change  program  size to  `0'+str+'`3 ?',

                      '','','','yes  -  quit  now','no  -  cancel','yes  next  time  -  continue  unchanged  for  now',0);

            if i=5
               then begin
                      current_scaling_position:=old_scaling_position;
                      pad_form.scaling_trackbar.Position:=current_scaling_position;

                      EXIT;
                    end;

            save_scaling_to_file;

            if i=4
               then begin
                      control_room_form.quit_menu_entry.Click;
                      EXIT;
                    end;

          end;
end;
//______________________________________________________________________________

procedure Tpad_form.Label8Click(Sender: TObject);

begin
  current_scaling_position:=old_scaling_position;
  scaling_trackbar.Position:=current_scaling_position;
  scaling_labels_panel.Visible:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.load_map_menu_entryClick(Sender: TObject);

begin
  map_loader_form.Show;
end;
//______________________________________________________________________________

procedure Tpad_form.trackbed_ballast_edges_menu_entryClick(Sender: TObject);

begin
  cancel_adjusts(False);

  if turnoutx=0 then extend_template_from_zero; // 0.93.a

  if Application.Terminated=False then Application.ProcessMessages;

  adjacent_trackbed_platforms_menu_entry.Click;  // cancel adjacent tracks if necessary

  trackbed_form.Show;
end;
//______________________________________________________________________________

procedure Tpad_form.add_sketchboard_items_menu_entryClick(Sender: TObject);

begin
  sketchboard_button.Click;
  Application.ProcessMessages;

  alert(2,'   show  sketchboard  items  on  trackpad',
          'To show items from the sketchboard on the trackpad background:'
         +'||1. start the sketchboard with your current trackplan, if not already.'
         +'||2. add some items.'
         +'||3. tick the `0show items on trackpad`1 box (top left):'
         +'||<IMG SRC="'+exe_str+'internal\hlp\sb_show_items.png">'
         +'||4. click the `0file > hide sketchboard`1 menu item on the sketchboard, or click the usual <SPAN STYLE="COLOR:WHITE; FONT-WEIGHT:BOLD; BACKGROUND-COLOR:RED;">&nbsp;X&nbsp;</SPAN> close button, to hide the sketchboard and return to the trackpad.',
         '','','','','','continue',0);

end;
//______________________________________________________________________________

procedure Tpad_form.make_single_slip_same_hand_menu_entryClick(Sender: TObject);

begin
  if make_slip(1,False)=False then EXIT;

  gocalc(0,0);
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.make_single_slip_opposite_hand_menu_entryClick(Sender: TObject);

begin
  if make_slip(-1,False)=False then EXIT;

  gocalc(0,0);
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.make_double_slip_menu_entryClick(Sender: TObject);

begin
  if make_slip(0,False)=False then EXIT;

  gocalc(0,0);
  show_and_redraw(True,True);
end;
//______________________________________________________________________________

procedure Tpad_form.dstip_increase_all_menu_entryClick(Sender: TObject);

begin
  dstip_increase_all_menu_entry.Checked:=True;   // radio item
  mod_double_slip:=2;
end;
//______________________________________________________________________________

procedure Tpad_form.dstip_increase_00EM_menu_entryClick(Sender: TObject);

begin
  dstip_increase_00EM_menu_entry.Checked:=True;   // radio item
  mod_double_slip:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.dstip_no_increase_menu_entryClick(Sender: TObject);

begin
  dstip_no_increase_menu_entry.Checked:=True;   // radio item
  mod_double_slip:=0;
end;
//______________________________________________________________________________

procedure make_slip_crossover(num_sides:integer);

   //    num_sides =1 single slip   =2 double slip

var
  save_timbering:boolean;
  i:integer;

begin
  save_timbering:=pad_form.square_on_menu_entry.Checked;

  if save_timbering=True
     then begin
                    // change to equalized timbering ...

            pad_form.equalized_incremental_menu_entry.Enabled:=True;
            pad_form.equalized_incremental_menu_entry.Click;
          end;

  if num_sides=1 then make_slip(1,True);     // same-side single slip
  if num_sides=2 then make_slip(0,True);     // double slip

  if save_timbering=True   // restore his square-on
     then begin
            pad_form.square_on_menu_entry.Enabled:=True;
            pad_form.square_on_menu_entry.Click;
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.make_single_slip_crossover_menu_entryClick(Sender: TObject);

begin
  make_slip_crossover(1);
end;
//______________________________________________________________________________

procedure Tpad_form.make_double_slip_crossover_menu_entryClick(Sender: TObject);

begin
  make_slip_crossover(2);
end;
//______________________________________________________________________________

procedure Tpad_form.make_slip_help_menu_entryClick(Sender: TObject);

const
  slip_help_str:string='php/115    `0make  slip`9'
  +'||This function will create a collection of background templates comprising a slip formation.'
  +'||Start with a turnout or half-diamond in the control template, of the required crossing angle, and in the location where you want the slip. It can be straight, curved or on a transition curve.'
  +'||For a single slip it is convenient to start with a turnout, so that you can easily see whether you want a slip of the same hand (same side) or opposite hand.'
  +'||If starting with a half-diamond do not create the full diamond-crossing, this function will do that. Otherwise you will get duplicated templates. If the other half-diamond already exists, delete it before making the slip.'

  +'||For a single-slip there will be 5 templates. For a double-slip there will be 8 templates. The templates will be given a unique prefix tag, so that you can easily select them as a group if you need to move the entire slip, or to delete it.'
  +' To do that, click the `0group > create smaller group > group by prefix tag >`1 menu item.'

  +'||green_panel_begin tree.gif  After the slip has been created, it is likely that you will want to delete one of the half-diamonds to the control template, so that you can continue your track planning.'
  +'||After storing it again, be sure to move it above the slip roads and switches in the storage box, so that the slip switches are drawn correctly in the output.'
  +'||You can do that for all the half-diamonds in the storage box by clicking the `0box > sort half-diamonds to first (back)`1 menu item on the storage box.'
  +'||For more about the `0tools > make slip`1 function please ask on the <A HREF="go_to_templot_club.85a"><U>Templot&nbsp;Club</U></A> user forum.green_panel_end'

  +'|rp.gif If the starting template is on a transition curve, Templot will do its best to create the slip on the transition, using fixed arcs for the slip roads. That will be satisfactory in the majority of cases,'
  +' but if the transition is severe the slip roads may not align well with the slip switches.||You will then want to replace the slip roads with transition curves, using the `0make transition link`1 function.'
  +' Templot can''t do that for you because it requires a human eyeball to arrive at the optimum alignment.'
  +'||A slip on a transition curve isn''t prototypical, but sometimes model space constraints leave no choice.';

begin
  help(0,slip_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.curvi_match_chairs_menu_entryClick(Sender: TObject);   // 215a

begin
  curviform_timbering:=True;
  curvi_match_chairs_menu_entry.Checked:=True;   // radio item
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.curvi_match_regular_menu_entryClick(Sender: TObject);  // 215a

begin
  curviform_timbering:=False;
  curvi_match_regular_menu_entry.Checked:=True;   // radio item
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.curviform_timbering_menu_entryClick(Sender: TObject);  // 215a

begin
  if curviform_timbering=True
     then curvi_match_chairs_menu_entry.Checked:=True     // radio item
     else curvi_match_regular_menu_entry.Checked:=True;   // radio item
end;
//______________________________________________________________________________

procedure Tpad_form.simplified_short_angle_timbering_menu_entryClick(Sender:TObject);   // 228a

begin
  simplified_short_angle:=True;
  simplified_short_angle_timbering_menu_entry.Checked:=True;   // radio item
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.normal_short_angle_timbering_menu_entryClick(Sender:TObject);   // 228a

begin
  simplified_short_angle:=False;
  normal_short_angle_timbering_menu_entry.Checked:=True;   // radio item
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.short_angle_timbering_menu_entryClick(Sender: TObject);  // 228a

begin
  if simplified_short_angle=True
     then simplified_short_angle_timbering_menu_entry.Checked:=True  // radio item
     else normal_short_angle_timbering_menu_entry.Checked:=True;     // radio item
end;
//______________________________________________________________________________

procedure Tpad_form.templot_companion_menu_entryClick(Sender: TObject);

begin
  go_to_templot_companion;
end;
//______________________________________________________________________________

procedure Tpad_form.tip_clearance_help_menu_entryClick(Sender: TObject);

const
  sliptips_help_str:string='php/115    `0double-slip  tip  clearance`9'

  +'||For a double-slip flatter than 1:6.5, there is an option to move the switch tips one timber further from the V-crossing than for a single-slip.'
  +'||This provides some increased model clearance for the opened switch blades and the need to maintain insulation between them, and corresponds to some prototype practice.'
  +'||The default setting for this option `0on`1 for gauges requiring a wider flangeway such as 00/EM etc, but `0off`1 for P4/S7 etc. This can be changed as required before making a double-slip.'
  +'||This option reduces the slip road radius and shortens the length available for the switch blades, which is the reason it applies only on slips flatter than 1:6.5 crossing angle.';

begin
  help(0,sliptips_help_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.how_to_menu_entryClick(Sender: TObject);

begin
  go_to_templot_companion_page('how_to_do_tasks.php');    // 214a
end;
//______________________________________________________________________________

procedure Tpad_form.how_to_print_template_menu_entryClick(Sender: TObject);

begin
  go_to_templot_companion_page('your_first_printed_template.php');    // 237c
end;
//______________________________________________________________________________

procedure Tpad_form.watch_a_video_menu_entryClick(Sender: TObject);  // 216a

begin
  go_to_templot_companion_page('online_video_list.php');    // 214a
end;
//______________________________________________________________________________

procedure add_reminder_click(index:integer);     // 216a

begin
  if (index<0) or (index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with math_form do begin
    Caption:='    template  reminder  message ...';
    big_label.Caption:=insert_crlf_str('      Add  Reminder  Message'
                                    +'||Enter below a reminder message for the selected template.'
                                    +'||This will appear in one of the the reminder boxes on the right of the screen. Click on the reminder box to zoom the trackpad to the relevant template. Right-click on the box for options.'
                                    +' Hover the mouse over the box to see the full message if it does not fit in the box. To hide the reminders click the trackpad > hide reminders menu item ( CTRL+/ ).'
                                    +'||Only the first 5 reminders found in the storage box list of background templates will be shown in the boxes. Any remaining reminder templates will be shown with a coloured marker only,'
                                    +' and shown in the boxes when one or more of the first 5 reminders are removed.'
                                    +'||If a stored template is deleted to the control template, its reminder will be discarded, but can be seen for later reference on the jotter.'
                                    +'||Reminder messages are limited to 200 characters maximum and'
                                    +'|are saved in the template data file between working sessions.');
    math_editbox.Text:='';

    do_show_modal(math_form);    // 212a

    if ModalResult=mrOK
       then begin
              with Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info do begin

                reminder_str:=Trim(math_editbox.Text);
                reminder_flag:=(Trim(math_editbox.Text)<>'');

              end;//with

              save_done:=False;
              backup_wanted:=True;
            end;

    Caption:='    TEMPLOT';   // reset form caption.
  end;//with

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.add_reminder_popup_entryClick(Sender: TObject);     // 216a

begin
  add_reminder_click(clicked_keep_index);
  clicked_keep_index:=-1;                   // so can popup again.
end;
//______________________________________________________________________________

procedure edit_reminder_click(index:integer);   // 216a

begin
  if (index<0) or (index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  if Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info.reminder_flag=False then EXIT;

  with math_form do begin
    Caption:='    template  reminder  message ...';
    big_label.Caption:=insert_crlf_str('||      Edit  Reminder  Message'
                                    +'|||You can edit below the current reminder message for the selected template.'
                                    +'||If you leave the reminder message blank, the reminder will be removed.'
                                    +'||Reminder messages are limited to 200 characters maximum.');

    math_editbox.Text:=Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info.reminder_str;

    do_show_modal(math_form);    // 212a

    if ModalResult=mrOK
       then begin
              with Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info do begin

                reminder_str:=Trim(math_editbox.Text);
                reminder_flag:=(Trim(math_editbox.Text)<>'');
              end;//with

              save_done:=False;
              backup_wanted:=True;

            end;

    Caption:='    TEMPLOT';   // reset form caption.
  end;//with

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.edit_reminder_popup_entryClick(Sender: TObject);   // 216a

begin
  edit_reminder_click(clicked_keep_index);
  clicked_keep_index:=-1;                    // so can popup again.
end;
//______________________________________________________________________________

procedure remove_reminder_click(index:integer);  // 216a

begin
  if (index<0) or (index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info do begin

    reminder_str:='';
    reminder_flag:=False;

  end;//with

  save_done:=False;
  backup_wanted:=True;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_reminder_popup_entryClick(Sender: TObject);  // 216a

begin
  remove_reminder_click(clicked_keep_index);
  clicked_keep_index:=-1;                    // so can popup again.
end;
//______________________________________________________________________________

procedure reminder_colour_click(index:integer);  // 216a

begin
  if (index<0) or (index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  with Ttemplate(keeps_list.Objects[index]).template_info.keep_dims.box_dims1.align_info do begin

    if reminder_flag=False then EXIT; // ???  no reminder here

    reminder_colour:=get_colour('choose  a  colour  for  this  reminder',reminder_colour);

  end;//with

  save_done:=False;
  backup_wanted:=True;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.reminder_colour_popup_entryClick(Sender: TObject);  // 216a

begin
  reminder_colour_click(clicked_keep_index);
  clicked_keep_index:=-1;                     // so can popup again.
end;
//______________________________________________________________________________

procedure Tpad_form.reminder_popup_entryClick(Sender: TObject);

begin
  if (clicked_keep_index<0) or (clicked_keep_index>(keeps_list.Count-1)) or (keeps_list.Count<1) then EXIT;

  edit_reminder_popup_entry.Enabled:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.align_info.reminder_flag;
  remove_reminder_popup_entry.Enabled:=Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.align_info.reminder_flag;

  add_reminder_popup_entry.Enabled:= NOT Ttemplate(keeps_list.Objects[clicked_keep_index]).template_info.keep_dims.box_dims1.align_info.reminder_flag;
end;
//______________________________________________________________________________

procedure Tpad_form.reminder_memo1Click(Sender: TObject);

begin
  zoom_to_fit_template(reminder_memo1.Tag);
end;
//__________

procedure Tpad_form.reminder_memo2Click(Sender: TObject);

begin
  zoom_to_fit_template(reminder_memo2.Tag);
end;
//__________

procedure Tpad_form.reminder_memo3Click(Sender: TObject);

begin
  zoom_to_fit_template(reminder_memo3.Tag);
end;
//__________

procedure Tpad_form.reminder_memo4Click(Sender: TObject);

begin
  zoom_to_fit_template(reminder_memo4.Tag);
end;
//__________

procedure Tpad_form.reminder_memo5Click(Sender: TObject);

begin
  zoom_to_fit_template(reminder_memo5.Tag);
end;
//______________________________________________________________________________

procedure Tpad_form.edit_popup_entryClick(Sender: TObject);

begin
  if reminder_popup_menu.PopupComponent is TMemo then edit_reminder_click(TMemo(reminder_popup_menu.PopupComponent).Tag);
end;
//______________________________________________________________________________

procedure Tpad_form.colour_popup_entryClick(Sender: TObject);

begin
  if reminder_popup_menu.PopupComponent is TMemo then reminder_colour_click(TMemo(reminder_popup_menu.PopupComponent).Tag);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_popup_entryClick(Sender: TObject);

begin
  if reminder_popup_menu.PopupComponent is TMemo then remove_reminder_click(TMemo(reminder_popup_menu.PopupComponent).Tag);
end;
//______________________________________________________________________________

procedure Tpad_form.isolate_crossing_menu_entryClick(Sender: TObject);

begin
  isolated_crossing:= NOT isolated_crossing;

  if isolated_crossing=True
     then begin
            main_road_i:=3;   // minimum..
            turnout_road_i:=3;

            main_road_stock_rail_flag:=False;
            turnout_road_stock_rail_flag:=False;

            no_track_centre_lines_menu_radio.Click;

            peg_on_mcp_menu_entry.Click;
          end
     else begin
            main_road_i:=0;      // normal..
            turnout_road_i:=0;

            with rail_options_form do begin
              main_road_stock_rail_flag:=main_road_stock_rail_checkbox.Checked;
              turnout_road_stock_rail_flag:=turnout_road_stock_rail_checkbox.Checked;
            end;//with

            normal_track_centre_lines_menu_radio.Click;

            startx:=0;  // cancel the blanking
          end;

  do_railedges;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.f9_options_help_menu_entryClick(Sender: TObject);

const
  f9_help_str:string='  `0F9 mouse  action  -  adjust  V-crossing  angle`9||  `0Options`9'
                    +'||The `0keep gaunt radius fixed`1 option applies only for gaunt turnouts having a curviform V-crossing.'
                    +'||This option is not available for transition curve templates.'
                    +'||Changing the gaunt turnout radius will modify the gaunt offset.'
                    +'||When this option is not available, the `0keep gaunt offset fixed`1 option applies.';

begin
  help(0,f9_help_str,'');
end;
//______________________________________________________________________________

procedure do_toolbars;   // 217a       // called from startup unit     not all created

begin

  with pad_form do begin

    top_toolbar_panel.Width:=zoom_rectangle_latching_toolbutton.Left+zoom_rectangle_latching_toolbutton.Width+3;

    second_toolbar_panel.Width:=ctrlf10_button.Left+ctrlf10_button.Width+3;

    top_toolbar_panel.Top:=make_slip_form.Top-2;

    if Screen.Width>(make_slip_form.Width+top_toolbar_panel.Width)
       then top_toolbar_panel.Left:=make_slip_form.Left+make_slip_form.Width+6;

    if toolbars_2rows=False         // 1 long row
       then begin
              second_toolbar_panel.Left:=top_toolbar_panel.Left+top_toolbar_panel.Width;
              second_toolbar_panel.Top:=top_toolbar_panel.Top+new_template_button.Top;   // align buttons
            end
       else begin
              second_toolbar_panel.Top:=top_toolbar_panel.Top+top_toolbar_panel.Height;
              second_toolbar_panel.Left:=top_toolbar_panel.Left;
            end;

    with store_draw_button do begin Left:=make_slip_form.Left; Top:=(store_draw_button.Height div 10)+Round(Max((make_slip_form.Top+make_slip_form.Height),(second_toolbar_panel.Top+second_toolbar_panel.Height))); end;  // 237c

    with yellow_drag_panel do begin Left:=store_draw_button.Left+store_draw_button.Width+4; Top:=store_draw_button.Top; end;

  end;//with
end;
//______________________________________________________________________________
(* OT2024

procedure Tpad_form.sb_reload_from_file_menu_entryClick(Sender: TObject);     // 217b

begin
  if FileExists(exe_str+'dpi_yes.txt')=True
     then begin
            if alert(2,'php/970    screen  scaling  vitualized',
                       'You have previously changed the screen scaling to the old-style Windows virtualization method.'
                      +'||The sketchboard functions are not available when using this method.',
                       '','','','','cancel','change  back  to  high-definition  screen  scaling',0)=6

               then control_room_form.screen_scaling_menu_entry.Click;

            EXIT;
          end;

  sb_lock_menu_entry.Click;
  go_sketchboard:=True;

  dtp_form.Show;
  dtp_form.BringToFront;

  dtp_settings_form.Show;
  dtp_settings_form.BringToFront;

  dtp_form.SetFocus;

  Application.ProcessMessages;

  dtp_form.load_dtp_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.sb_save_to_file_menu_entryClick(Sender: TObject);    // 217b

begin
  if FileExists(exe_str+'dpi_yes.txt')=True
     then begin
            if alert(2,'php/970    screen  scaling  vitualized',
                       'You have previously changed the screen scaling to the old-style Windows virtualization method.'
                      +'||The sketchboard functions are not available when using this method.',
                       '','','','','cancel','change  back  to  high-definition  screen  scaling',0)=6

               then control_room_form.screen_scaling_menu_entry.Click;

            EXIT;
          end;

  sb_lock_menu_entry.Click;
  go_sketchboard:=True;

  dtp_form.Show;
  dtp_form.BringToFront;

  dtp_settings_form.Show;
  dtp_settings_form.BringToFront;

  dtp_form.SetFocus;

  Application.ProcessMessages;

  dtp_form.save_dtp_as_menu_entry.Click;
end;
//______________________________________________________________________________
*)

procedure Tpad_form.ds_tandem_begin_menu_entryClick(Sender: TObject);

begin

  if plain_track=True
     then begin
            alert(6,'    make  tandem  -  plain  track',
                    'Sorry, this function is not available because the control template is plain track.'
                   +'||This function requires a turnout as its starting point to create a tandem turnout.'
                   +'||You must first change to a turnout template, by clicking the `0TEMPLATE > INSERT TURNOUT IN PLAIN TRACK`1 menu item.'
                   +'||And then setting the hand and facing/trailing direction as required.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'    make  tandem  -  half - diamond',
                    'Sorry, this function is not available because the control template is a half-diamond.'
                   +'||This function requires a turnout as its starting point to create a tandem turnout.'
                   +'||You must first change to a turnout template, by clicking the `0TEMPLATE > CONVERT HALF-DIAMOND TO TURNOUT`1 menu item.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if spiral=True
     then begin
            alert(6,'    make  tandem  -  transition  curve',
                    'Sorry, this function is not available because the control template contains a transition curve.'
                   +'||A tandem turnout could be created manually within a transition zone if necessary, but it would be a complex design (and not very prototypical).',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if slewing=True
     then begin
            alert(6,'    make  tandem  -  slewed  track',
                    'Sorry, this function is not available because the control template contains a slew.'
                   +'||A tandem could be created manually, but it is generally unwise to create a tandem turnout if any part of it will be within a slewing zone.'
                   +'||The slewing function is intended primarily for plain track.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if (csi.group_code<1) or (csi.group_code>6)  // not specials
     then begin
            alert(6,'    make  tandem  -  wrong  switch  size',
                    'Sorry, this function is not available because the turnout in the control template contains a special switch or a custom switch.'
                   +'||To change to one of the standard switches click the `0template > switch settings...`1 menu item and select a switch from within the first 6 groups.'
                   +'||A tandem turnout containing other switches could be created manually.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if (xing_calc_i=0) and (sl>(fw*2*k3n+1))    // allow 1mm past default max
     then begin
            alert(6,'    make  tandem  -  crossing  straight  too  long',
                    'Sorry, this function is not available because the turnout in the control template has a regular-type|V-crossing with an extended length of crossing entry straight.'
                   +'||To change this use the `0F5`2 mouse action to set a more conventional turnout size.'
                   +'||Alternatively click the `0template > V-crossing settings...`z menu item and select the `0auto-fit`1 option for the entry staight.'
                   +'||Or change to a generic or curviform type of V-crossing.'
                   +'||A tandem turnout containing a long crossing entry straight could be created manually.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if k3n<5.95
     then begin
            if alert(3,'    make  tandem  -  short  turnout',
                       'The starting turnout is very short.'
                      +'||If you continue, the created tandem turnout is likely to include a sharp radius.',
                       '','','','','cancel','continue',0)=5
               then EXIT;
          end;

  tandem_form.Caption:='make  3-way  tandem  turnout  -  double-sided';

  tandem_form.comprised_label.Caption:='The tandem turnout will be comprised of 7 partial templates.';
  tandem_form.derived_label.Caption:='The new middle V-crossing will be derived from a gaunt turnout.';

  tandem_form.ds_label.Visible:=True;

  tandem_form.xing_type_groupbox.Visible:=True;    // regular/cuviform option for double-sided

  tandem_form.Color:=$00F0FFFF;

  if do_show_modal(tandem_form)=mrOk then create_double_sided_tandem(tandem_form.curviform_xing_radio.Checked,False);
end;
//______________________________________________________________________________

procedure Tpad_form.ds_tandem_continue_menu_entryClick(Sender: TObject);

begin
  create_double_sided_tandem(False,True);    // False will be ignored
end;
//______________________________________________________________________________

procedure Tpad_form.tandems_click_first_menu_entryClick(Sender: TObject);

begin
  go_to_templot_companion_page('3_way_tandem_turnouts.php');
end;
//______________________________________________________________________________

procedure Tpad_form.reset_tandem_turnout_menu_entryClick(Sender: TObject);   // 218a

var
  dummy:extended;

begin
  rail_options_form.restore_all_button.Click;

  if csi.group_code=9  // tandem switch
     then begin
            if (plain_track=False) and (peg_code<>4) then peg_on_fp_menu_entry.Click;  // onto FP 4
            gocalc(0,0);
            kform_now:=kform;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg data for peg_curve calcs.
            gocalc(0,0);
            if set_csi_data(2,2)=False then ShowMessage('Sorry, unable to restore REA "B" switch');
            gocalc(0,0);
            peg_curve;     // keep aligned after changing switch
            gocalc(0,0);
            if plain_track=False
               then begin
                      reset_peg_menu_entry.Click;                // put it on 0 to finish
                      if turnoutx<mvjpx then turnoutx:=mvjpx;    // and a full turnout
                      gocalc(0,0);
                    end;
          end;

  include_closure_timbers:=True;
  include_front_timbers:=True;
  include_switch_timbers:=True;
  include_front_timbers:=True;

  turnout_road_stock_rail_flag:=True;
  turnout_road_crossing_rail_flag:=True;
  turnout_road_check_rail_flag:=True;

  crossing_vee_flag:=True;

  main_road_check_rail_flag:=True;
  main_road_crossing_rail_flag:=True;
  main_road_stock_rail_flag:=True;

  approach_rails_only:=False;

  exittb_i:=2;
  tandem_timb:=0;
  isolated_crossing:=False;

  if turnout_road_i>0 then turnout_road_i:=0;      // normal    no change if set to crossover (-1)
  main_road_i:=0;                                  // normal

  startx:=0;

  square_on_menu_entry.Click;
  normal_track_centre_lines_menu_radio.Click;

  do_railedges;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.ss_tandem_begin_menu_entryClick(Sender: TObject);

begin

  if plain_track=True
     then begin
            alert(6,'    make  tandem  -  plain  track',
                    'Sorry, this function is not available because the control template is plain track.'
                   +'||This function requires a turnout as its starting point to create a tandem turnout.'
                   +'||You must first change to a turnout template, by clicking the `0TEMPLATE > INSERT TURNOUT IN PLAIN TRACK`1 menu item.'
                   +'||And then setting the hand and facing/trailing direction as required.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if half_diamond=True
     then begin
            alert(6,'    make  tandem  -  half - diamond',
                    'Sorry, this function is not available because the control template is a half-diamond.'
                   +'||This function requires a turnout as its starting point to create a tandem turnout.'
                   +'||You must first change to a turnout template, by clicking the `0TEMPLATE > CONVERT HALF-DIAMOND TO TURNOUT`1 menu item.',
                    '','','','','cancel','',0);
            EXIT;
          end;

  if spiral=True
     then begin
            alert(6,'    make  tandem  -  transition  curve',
                    'Sorry, this function is not available because the control template contains a transition curve.'
                   +'||A tandem turnout could be created manually within a transition zone if necessary, but it would be a complex design (and not very prototypical).',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if slewing=True
     then begin
            alert(6,'    make  tandem  -  slewed  track',
                    'Sorry, this function is not available because the control template contains a slew.'
                   +'||A tandem could be created manually, but it is generally unwise to create a tandem turnout if any part of it will be within a slewing zone.'
                   +'||The slewing function is intended primarily for plain track.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if (csi.group_code<1) or (csi.group_code>6)  // not specials
     then begin
            alert(6,'    make  tandem  -  wrong  switch  size',
                    'Sorry, this function is not available because the turnout in the control template contains a special switch or a custom switch.'
                   +'||To change to one of the standard switches click the `0template > switch settings...`1 menu item and select a switch from within the first 6 groups.'
                   +'||A tandem turnout containing other switches could be created manually.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  if (xing_calc_i=0) and (sl>(fw*2*k3n+1))    // allow 1mm past default max
     then begin
            alert(6,'    make  tandem  -  crossing  straight  too  long',
                    'Sorry, this function is not available because the turnout in the control template has a regular-type|V-crossing with an extended length of crossing entry straight.'
                   +'||To change this use the `0F5`2 mouse action to set a more conventional turnout size.'
                   +'||Alternatively click the `0template > V-crossing settings...`z menu item and select the `0auto-fit`1 option for the entry staight.'
                   +'||Or change to a generic or curviform type of V-crossing.'
                   +'||A tandem turnout containing a long crossing entry straight could be created manually.',
                    '','','','','cancel','',0);
             EXIT;
          end;

  tandem_form.Caption:='make  3-way  tandem  turnout  -  single-sided';

  tandem_form.comprised_label.Caption:='The tandem turnout will be comprised of 5 partial templates.';
  tandem_form.derived_label.Caption:='In most cases the new V-crossing will be derived from an irregular half-diamond.';

  tandem_form.ds_label.Visible:=False;

  tandem_form.xing_type_groupbox.Visible:=False;    // no regular option for single-sided       reveal single-side label

  tandem_form.Color:=$00F0F8F0;

  if do_show_modal(tandem_form)=mrOk then create_single_sided_tandem(False);
end;
//______________________________________________________________________________

procedure Tpad_form.ss_tandem_continue_menu_entryClick(Sender: TObject);

begin
  create_single_sided_tandem(True);
end;
//______________________________________________________________________________

procedure Tpad_form.F7snaphelp1Click(Sender: TObject);

const
  snap_help_str='      `0F7  Snap  Options`9'
               +'||If the `0snap conditionally on background templates`1 option is selected, the control template will snap onto background templates according to the position of the `0SHIFT`2 key on the keyboard, as follows:'
               +' 1. If the `0F7`2 keyboard shortcut is used to start the mouse action, or the menu item, snapping will take place <U>only</U> if the `0SHIFT`2 key is held down.'
               +' 2. If the `0SHIFT & JOIN F7`z top tool-button is used to start the mouse action, snapping will take place <U>unless</U> the `0SHIFT`2 key is held down.'

               +'||If the `0snap always on background templates`1 option is selected, snapping will take place regardless of the `0SHIFT`2 key.'

               +'||If the `0no snapping`1 option is selected, no snapping will take place.'

               +'||Regardless of these option settings, snapping can be prevented on an individual background template by clicking it, and selecting its `0F7 snapping > disable snapping for this template`z menu option.'

               +'||These snap options are included in your `0program preferences`3, if they are being saved.';

begin
  help(0,snap_help_str,'');
end;
//______________________________________________________________________________

procedure widen_centres_18in(which:integer);      // 218e

  // which  1=TS, 2=MS, 3=both

var
  dummy:extended;

begin

  if which<>2 then cpi.trtscent_pi:=cpi.trtscent_pi+18*inscale;
  if which<>1 then cpi.trmscent_pi:=cpi.trmscent_pi+18*inscale;

  if (xing_type_i<1) and (retpar_i=1) and (xing_ret_i=0) and (which<>2)       // parallel crossing with return curve centres as adjacent track.
     then begin
            cpi.retcent_pi:=cpi.trtscent_pi; //  set new return curve centres.

            get_cpi;            //  use the new values.

            kform_now:=kform;
            arm_angle_now:=arm_angle;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

            gocalc(0,0);       //  recalc to get new pegx, pegy, arm_angle.

            peg_curve;         //  adjust shifts and rotates for current peg position.
            gocalc(0,0);       //  get new arm_angle (peg might be on return curve).

            rotate_turnout(arm_angle_now-arm_angle,True);  // re-align to previous angle and redraw.
          end
     else begin
            get_cpi;            //  use the new values.

            kform_now:=kform;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

            gocalc(0,0);       //  recalc to get new pegx, pegy.
            peg_curve;         //  adjust shifts and rotates for current peg position.
            redraw(True);
          end;
end;
//______________________________________________________________________________

procedure reduce_centres_18in(which:integer);         // 218e

  // which  1=TS, 2=MS, 3=both

var
  dummy:extended;

begin

  if which<>2 then cpi.trtscent_pi:=cpi.trtscent_pi-18*inscale;
  if which<>1 then cpi.trmscent_pi:=cpi.trmscent_pi-18*inscale;

  if (xing_type_i<1) and (retpar_i=1) and (xing_ret_i=0) and (which<>2)       // parallel crossing with return curve centres as adjacent track.
     then begin
            cpi.retcent_pi:=cpi.trtscent_pi; //  set new return curve centres.

            get_cpi;            //  use the new values.

            kform_now:=kform;
            arm_angle_now:=arm_angle;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

            gocalc(0,0);       //  recalc to get new pegx, pegy, arm_angle.

            peg_curve;         //  adjust shifts and rotates for current peg position.
            gocalc(0,0);       //  get new arm_angle (peg might be on return curve).

            rotate_turnout(arm_angle_now-arm_angle,True);  // re-align to previous angle and redraw.
          end
     else begin
            get_cpi;            //  use the new values.

            kform_now:=kform;
            docurving(True,True,pegx,pegy,now_peg_x,now_peg_y,now_peg_k,dummy);    // save current peg position on pad and curving angle.

            gocalc(0,0);       //  recalc to get new pegx, pegy.
            peg_curve;         //  adjust shifts and rotates for current peg position.
            redraw(True);
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.bold_timbers_on_last_menu_entryClick(Sender: TObject);    // 223c

begin
  bgkeeps_form.bold_timber_outlines_checkbox.Checked:=True;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.normal_timbers_on_last_menu_entryClick(Sender: TObject);   // 223c

begin
  bgkeeps_form.bold_timber_outlines_checkbox.Checked:=False;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_extensions_from_all_menu_entryClick(Sender: TObject);   // 223d

begin
  if outline_extensions=False    // already off, just rebuild all
     then begin
            generator_rebuild_bgnd_menu_entry.Click;
            EXIT;
          end;

     // switch off, rebuild, back on

  outline_extensions_menu_entry.Checked:=False;
  outline_extensions:=False;

  generator_rebuild_bgnd_menu_entry.Click;
  redraw(False);

  outline_extensions_menu_entry.Checked:=True;
  outline_extensions:=True;

  if remove_extensions_from_all_menu_entry.Tag=0
     then ShowMessage('Hint: to remove the extension marks from future templates,'+#13+'          untick the menu item in the generator settings.');

  remove_extensions_from_all_menu_entry.Tag:=0;   // reset

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.remove_extensions_from_group_menu_entryClick(Sender: TObject);    // 223d

begin
  if outline_extensions=False    // already off, just rebuild group
     then begin
            gen_rebuild_group_menu_entry.Click;
            EXIT;
          end;

     // switch off, rebuild, back on ...

  outline_extensions_menu_entry.Checked:=False;
  outline_extensions:=False;

  gen_rebuild_group_menu_entry.Click;
  redraw(False);

  outline_extensions_menu_entry.Checked:=True;
  outline_extensions:=True;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.restore_timber_extension_marks_menu_entryClick(Sender: TObject);     // 223d

begin
  outline_extensions_menu_entry.Checked:=True;
  outline_extensions:=True;

  generator_rebuild_bgnd_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.output_grid_options_menu_entryClick(Sender: TObject);     // 223d

begin
  print_grid_on_menu_entry.Checked:=(printgrid_i=1);        // radio items
  print_grid_off_menu_entry.Checked:=(printgrid_i=0);
end;
//______________________________________________________________________________

procedure Tpad_form.make_control_popup_entryAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);

begin
  with ACanvas do begin
    if (odSelected in State)=True
           then begin
                  Brush.Color:=$000070E0;   // orange
                  FillRect(ARect);          // blank the entry first.

                  Font.Height:=Round(Font.Height*1.2);
                  Font.Color:=clWhite;

                  TextOut(ARect.Left,ARect.Top-Font.Height div 2,'  '+StringReplace(TMenuItem(Sender).Caption,'&','',[rfReplaceAll,rfIgnoreCase]));
               end
           else begin
                  Brush.Color:=clWhite;
                  FillRect(ARect);       // blank the entry first.

                  Font.Height:=Round(Font.Height*1.2);
                  Font.Color:=clBlue;

                  TextOut(ARect.Left,ARect.Top-Font.Height div 2,'  '+StringReplace(TMenuItem(Sender).Caption,'&','',[rfReplaceAll,rfIgnoreCase]));
                end;
  end;//with
end;
//______________________________________________________________________________

procedure Tpad_form.make_control_popup_entryMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);

begin
  Height:=Height*2;
end;
//______________________________________________________________________________

procedure Tpad_form.blank_line_menu_entryAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; State: TOwnerDrawState);

begin

  with ACanvas do begin
    Brush.Color:=original_popup_colour; //clBtnFace;
    Brush.Style:=bsSolid;

    FillRect(ARect);
  end;//with

end;
//______________________________________________________________________________

procedure Tpad_form.top_name_info_popup_entryAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);

begin
  with ACanvas do begin
    if (odSelected in State)=True
           then begin
                  FillRect(ARect);          // blank the entry first.

                  Font.Name:='Courier New';
                  Font.Size:=Font.Size+2;
                  Font.Style:=[fsBold];

                  TextOut(ARect.Left+TextWidth(' ') div 2,ARect.Top-Font.Height div 2,StringReplace(TMenuItem(Sender).Caption,'&','',[rfReplaceAll,rfIgnoreCase]));
               end
           else begin
                  if original_popup_colour=clBlack then original_popup_colour:=ACanvas.Brush.Color;  // global, set it first time

                  Brush.Color:=$0090D8FF;   // sand
                  FillRect(ARect);          // blank the entry first.

                  Font.Name:='Courier New';
                  Font.Size:=Font.Size+2;
                  Font.Style:=[fsBold];

                  TextOut(ARect.Left+TextWidth(' ') div 2,ARect.Top-Font.Height div 2,StringReplace(TMenuItem(Sender).Caption,'&','',[rfReplaceAll,rfIgnoreCase]));
                end;
  end;//with
end;
//______________________________________________________________________________

procedure Tpad_form.top_name_info_popup_entryMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);

begin
  Height:=Round(Height*14/9);      // arbitrary
end;
//______________________________________________________________________________

procedure Tpad_form.osk_match_menu_entryClick(Sender: TObject);      // 226a

const
  hk_str:string='php/890    `0outside-slip  K  match`9'
  +'||Enter the matching K-crossing angle in RAM units.'
  +'||Do not enter the 1: part. For example to match K-crossing angle 1:8, simply enter 8.';

var
  n:integer;
  od:Toutdim;
  dummy:extended;

begin

  n:=putdim(hk_str,0,'match  K - crossing  angle  1: ',osk_match,True,True,True,False);   // no neg, no preset, no zero, don't terminate on zero.
  if n<>0 then EXIT;

  if getdims('outside-slip  K  match','',pad_form,n,od)=True
     then osk_match:=od[0];

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.output_detail_options_menu_entryClick(Sender: TObject);

begin
  detail_mode_form.Show;     // 226e
end;
//______________________________________________________________________________

procedure Tpad_form.y_scaling_distortion_menu_entryClick(Sender: TObject);  // 226e

begin
  control_room_form.y_scaling_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.reset_normal_y_scaling_menu_entryClick(Sender: TObject);  // 226f

var
  bgnd_count:integer;

begin
  bgnd_count:=any_bgnd;

  if bgnd_count>0 then keep_form.wipe_all_menu_entry.Click;

  y_distortion_factor:=1;
  control_room_form.y_scaling_menu_entry.Checked:=False;

   if bgnd_count>0 then keep_form.all_to_bgnd_menu_entry.Click;

   redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.show_timber_totals_menu_entryClick(Sender: TObject);

var
  msg_str:string;
  str:string;
  n:integer;
  len:extended;     // inches

begin
  if timb_len_list.Count<1 then EXIT;

  timb_len_list.Sort;

  msg_str:='<P ALIGN="CENTER" STYLE="COLOR:#AA5500; FONT-SIZE:24px; FONT-WEIGHT:BOLD; MARGIN-BOTTOM:20PX;">Timber and Sleeper Lengths<BR><SPAN STYLE="FONT-WEIGHT:NORMAL;">(control template)</SPAN></P>';

  msg_str:=msg_str+'<TABLE ALIGN="CENTER" STYLE="FONT-SIZE:16px; FONT-WEIGHT:BOLD;">'
  +'<TR><TD STYLE="TEXT-ALIGN:RIGHT; PADDING-RIGHT:20PX;">timber&nbsp;length:</TD>'
      +'<TD STYLE="TEXT-ALIGN:CENTER;">number&nbsp;of<BR>timbers:</TD><TD STYLE="PADDING-LEFT:20PX;">model&nbsp;mm&nbsp;&nbsp;&nbsp;<SPAN STYLE="FONT-WEIGHT:NORMAL;">(at&nbsp;'+FormatFloat('#.##',scale)+'&nbsp;mm/ft)</SPAN></TD></TR>';

  msg_str:=msg_str+'<TR><TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD></TR>';


  for n:=0 to timb_len_list.Count-1 do begin

    str:=timb_len_list.Strings[n];

    if POS('z',str)>0 then CONTINUE;  // sleepers not yet

    Delete(str,1,1);

    len:=StrToFloat(str);

    str:=str+'<SPAN STYLE="FONT-SIZE:12px;">-inch</SPAN>';

    msg_str:=msg_str+'<TR><TD STYLE="TEXT-ALIGN:RIGHT;">'+str+'</TD>'
                    +'<TD STYLE="TEXT-ALIGN:CENTER;">'+IntToStr(Ttimber_count_object(timb_len_list.Objects[n]).numco)+'</TD>'
                    +'<TD STYLE="PADDING-LEFT:20PX;">'+FormatFloat('#.##',len*inscale)+'</TD></TR>';
  end;//next

  msg_str:=msg_str+'<TR><TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD></TR>';


  msg_str:=msg_str+'<TR><TD STYLE="TEXT-ALIGN:RIGHT;">total&nbsp;timbers&nbsp;:</TD>'
                  +'<TD STYLE="TEXT-ALIGN:CENTER;">'+IntToStr(template_number_of_timbers)+'</TD>'
                  +'<TD>total&nbsp;length&nbsp;: &nbsp;'+round_str(total_template_timber_length,2)+'&nbsp;mm</TD></TR>';

  msg_str:=msg_str+'<TR><TD COLSPAN="3"><HR></TD></TR>';

  msg_str:=msg_str+'<TR><TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD></TR>';

  msg_str:=msg_str+'<TR><TD STYLE="TEXT-ALIGN:RIGHT; PADDING-RIGHT:20PX;">sleeper&nbsp;length:</TD>'
      +'<TD STYLE="TEXT-ALIGN:CENTER;">number&nbsp;of<BR>sleepers:</TD><TD STYLE="PADDING-LEFT:20PX;">model&nbsp;mm&nbsp;&nbsp;&nbsp;<SPAN STYLE="FONT-WEIGHT:NORMAL;">(at&nbsp;'+FormatFloat('#.##',scale)+'&nbsp;mm/ft)</SPAN></TD></TR>';

  msg_str:=msg_str+'<TR><TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD></TR>';


  for n:=0 to timb_len_list.Count-1 do begin

    str:=timb_len_list.Strings[n];

    if POS('z',str)=0 then CONTINUE;  // timbers done

    Delete(str,1,1);

    len:=StrToFloat(str);

    str:=str+'<SPAN STYLE="FONT-SIZE:12px;">-inch</SPAN>';

    msg_str:=msg_str+'<TR><TD STYLE="TEXT-ALIGN:RIGHT;">'+str+'</TD>'
                    +'<TD STYLE="TEXT-ALIGN:CENTER;">'+IntToStr(Ttimber_count_object(timb_len_list.Objects[n]).numco)+'</TD>'
                    +'<TD STYLE="PADDING-LEFT:20PX;">'+FormatFloat('#.##',len*inscale)+'</TD></TR>';
  end;//next

  msg_str:=msg_str+'<TR><TD COLSPAN="3" ALIGN="CENTER">&nbsp;</TD></TR>';


  msg_str:=msg_str+'<TR><TD STYLE="TEXT-ALIGN:RIGHT;">total&nbsp;sleepers&nbsp;:</TD>'
                  +'<TD STYLE="TEXT-ALIGN:CENTER;">'+IntToStr(template_number_of_sleepers)+'</TD>'
                  +'<TD>total&nbsp;length&nbsp;: &nbsp;'+round_str(total_template_sleeper_length,2)+'&nbsp;mm</TD></TR>';

  msg_str:=msg_str+'</TABLE>';

  help(-280,msg_str,'');
end;
//______________________________________________________________________________

procedure Tpad_form.set_droppers_gaps_menu_entryClick(Sender: TObject);

begin
  show_locator_menu_entry.Checked:=True;
  gaps_form.Show;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.put_peg_on_intersect_popup_entryClick(Sender: TObject);

begin
  intersect_form.find_intersect_button.Tag:=clicked_keep_index;     // reset if keeps_list OnChange
  clicked_keep_index:=-1;                                           // reset for next

  intersect_form.Show;   // 227a

  redraw(True);  // remove highlighting
end;
//______________________________________________________________________________
(* OT2024

procedure Tpad_form.get_file_from_code_menu_entryClick(Sender: TObject);     // 227a

begin
  get_file_from_code;     // in control_room
end;
//______________________________________________________________________________
*)

procedure Tpad_form.show_locator_menu_entryClick(Sender: TObject);

begin
  show_locator_menu_entry.Checked:= NOT show_locator_menu_entry.Checked;
  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.parapets_help_menu_entryClick(Sender: TObject);    // 227a

begin
  show_modal_message('Parapets'+#13+#13+'These options use the platforms function to represent a'
  +#13+'parapet wall alongside the track on a bridge or viaduct.'
  +#13+#13+'The dimensions can be adjusted on the platforms dialog.');
end;
//______________________________________________________________________________

procedure Tpad_form.ts_parapet_menu_entryClick(Sender: TObject);

begin
  platform_ts_front_edge_ins:=92;
  platform_ts_start_width_ins:=18;
  platform_ts_end_width_ins:=18;

  platform_edges_menu_entry.Click;                   // show form
  platform_form.ts_platform_checkbox.Checked:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.reset_normal_ts_platform_menu_entryClick(Sender: TObject);

begin
  platform_ts_front_edge_ins:=57;
  platform_ts_start_width_ins:=144;
  platform_ts_end_width_ins:=144;

  platform_edges_menu_entry.Click;                    // show form
  platform_form.ts_platform_checkbox.Checked:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.ms_parapet_menu_entryClick(Sender: TObject);

begin
  platform_ms_front_edge_ins:=92;
  platform_ms_start_width_ins:=18;
  platform_ms_end_width_ins:=18;

  platform_edges_menu_entry.Click;                     // show form
  platform_form.ms_platform_checkbox.Checked:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.reset_normal_ms_platform_menu_entryClick(Sender: TObject);

begin
  platform_ms_front_edge_ins:=57;
  platform_ms_start_width_ins:=144;
  platform_ms_end_width_ins:=144;

  platform_edges_menu_entry.Click;                     // show form
  platform_form.ms_platform_checkbox.Checked:=False;
end;
//______________________________________________________________________________

procedure Tpad_form.online_stl_repair_menu_entryClick(Sender: TObject);   // 228a

begin
  go_to_url('https://www.formware.co/onlinestlrepair');
end;
//______________________________________________________________________________

procedure Tpad_form.show_3d_timber_flanges_menu_entryClick(Sender: TObject);

begin
  show_3d_timber_flanges_menu_entry.Checked:= NOT show_3d_timber_flanges_menu_entry.Checked;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.show_2d_cutter_kerf_lines_menu_entryClick(Sender: TObject);  // 232a

begin
  show_2d_cutter_kerf_lines_menu_entry.Checked:= NOT show_2d_cutter_kerf_lines_menu_entry.Checked;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.save_all_brick_templates_menu_entryClick(Sender: TObject);  // 234a

begin
 keep_form.all_bricks_save_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.save_current_brick_templates_menu_entryClick(Sender: TObject);  // 234a

begin
  keep_form.current_brick_save_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.delete_all_brick_templates_menu_entryClick(Sender: TObject);  // 234a

begin
  keep_form.all_bricks_delete_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.delete_current_brick_templates_menu_entryClick(Sender: TObject);  // 234a

begin
  keep_form.current_brick_delete_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.DXFSTLfileexport1Click(Sender: TObject);

begin
  export_templates_dxf;        // go export a DXF/STL file
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_clip_size_menu_entryClick(Sender: TObject);

var
  n:integer;

begin
  with bgnd_form.bgnd_shapes_listbox do begin
    n:=ItemIndex;

    if (Items.Count<1) or (n<0) or (n>(Items.Count-1)) then EXIT;

    with Tbgshape(Items.Objects[n]).bgnd_shape do begin

      if (shape_code<>4) or (is_brick<>True)
       then begin
              show_modal_message('invalid: The currently selected background shape'+#13+'is not a brick connector clip.');
              EXIT;
            end;

       clip_size:=p2.x;

    end;//with
  end;//with

  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  mouse_action_selected('    clip  size ...','clip  size',captext(clip_size)+' mm');
  clip_size_mod:=1;
end;
//______________________________________________________________________________

procedure mouse_adjust_clip_slab_angle(n,shape_code:integer);

begin
  with bgnd_form.bgnd_shapes_listbox.Items do begin

    if (Count<1) or (n<0) or (n>(Count-1)) then EXIT;

    case shape_code of

        1: begin      // rectangle/slab

             clip_angle:=Tbgshape(Objects[n]).bgnd_shape.rect_rot;
           end;

        4: begin      // target mark/clip

             clip_angle:=Tbgshape(Objects[n]).bgnd_shape.p2.y;
           end;

      else EXIT;

    end;//case

  end;//with

  cancel_adjusts(True);

  if bgnd_form.Visible=True
     then begin
            bgnd_form.Close;
            bgnd_form_closed:=True;
          end;

  if shape_code=1
     then mouse_action_selected('    rectangle / slab  twist  angle ...','rectangle / slab  twist  angle',captext(clip_angle*180/Pi)+' degs')
     else mouse_action_selected('    clip  twist  angle ...','clip  twist  angle',captext(clip_angle*180/Pi)+' degs');

  clip_angle_mod:=1;
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_clip_angle_menu_entryClick(Sender: TObject);           // 234b mods

var
  n,shape_code:integer;
  is_brick:boolean;

begin
  with bgnd_form.bgnd_shapes_listbox do begin
    n:=ItemIndex;

    if (Items.Count<1) or (n<0) or (n>(Items.Count-1)) then EXIT;

    shape_code:=Tbgshape(Items.Objects[n]).bgnd_shape.shape_code;
    is_brick:=Tbgshape(Items.Objects[n]).bgnd_shape.is_brick;

  end;//with

  adjust_clip_angle_menu_entry.Tag:=shape_code;       // for repeat action

  if (shape_code<>4) or (is_brick<>True)
     then show_modal_message('invalid: The currently selected background shape'+#13+'is not a brick connector clip.')
     else mouse_adjust_clip_slab_angle(n,shape_code);
end;
//______________________________________________________________________________

procedure Tpad_form.adjust_slab_angle_menu_entryClick(Sender: TObject);           // 234b mods for slab option

var
  n,shape_code:integer;

begin
  with bgnd_form.bgnd_shapes_listbox do begin
    n:=ItemIndex;

    if (Items.Count<1) or (n<0) or (n>(Items.Count-1)) then EXIT;

    shape_code:=Tbgshape(Items.Objects[n]).bgnd_shape.shape_code;
  end;//with

  adjust_clip_angle_menu_entry.Tag:=shape_code;          // for repeat action

  if shape_code<>1
     then show_modal_message('invalid: The currently selected background shape'+#13+'is not a rectangle/slab.')
     else mouse_adjust_clip_slab_angle(n,shape_code);
end;
//______________________________________________________________________________

procedure Tpad_form.samples_009_menu_entryClick(Sender: TObject);    // 233a

var
  file_str:string;

begin
  if alert(3,'    load  sample  009  templates',
                    '`0  009 templates  -  9mm gauge  4mm/ft`9'
                   +'||Loading these sample templates will replace all your existing templates.'
                   +'||You may want to cancel this and save your work first.'
                   +'||These templates are for 9mm narrow-gauge in 4mm/ft scale.'
                   +'||The templates will load as library templates. Click a template in the library viewer to copy it onto the trackpad.',
                    '','','','','cancel','continue',0)=5
     then EXIT;

  file_str:=exe_str+'internal\samples\009_sample_templates_lib.box';

  reload_specified_file(False,False,file_str);
end;
//______________________________________________________________________________

procedure Tpad_form.samples_0n16p5_menu_entryClick(Sender: TObject);

var
  file_str:string;

begin
  if alert(3,'    load  sample  0n16.5  templates',
                    '`0 0n16.5 templates  -  16.5mm gauge  7mm/ft`9'
                   +'||Loading these sample templates will replace all your existing templates.'
                   +'||You may want to cancel this and save your work first.'
                   +'||These templates are for 16.5mm narrow-gauge in 7mm/ft scale.'
                   +'||The templates will load as library templates. Click a template in the library viewer to copy it onto the trackpad.',
                    '','','','','cancel','continue',0)=5
     then EXIT;

  file_str:=exe_str+'internal\samples\0n16p5_sample_templates_lib.box';

  reload_specified_file(False,False,file_str);
end;
//______________________________________________________________________________

procedure Tpad_form.store_draw_buttonClick(Sender: TObject);      // 233b

begin
  if draw_template_direct=True       // he wants to cancel
     then begin
            draw_template_direct:=False;

            yellow_drag_panel.Visible:=False;

            Cursor:=crDefault;
            EXIT;
          end;

  cancel_adjusts(False);
  if pad_form.arrow_button_dummy_trackbar.Showing=True then pad_form.arrow_button_dummy_trackbar.SetFocus;

  pad_caption('draw  new  template  ');
  if check_grey_paper=False then Cursor:=cross_hairs_cursor;
  draw_template_direct:=True;

  yellow_drag_panel.Visible:=True;
end;
//______________________________________________________________________________

procedure Tpad_form.search_for_menu_entryClick(Sender: TObject);   // 233c

begin
  search_form.Show;
end;
//______________________________________________________________________________

procedure Tpad_form.control_is_brick_menu_entryClick(Sender: TObject);  // 234a

begin
  control_is_brick_menu_entry.Checked:= NOT control_is_brick_menu_entry.Checked;

  timbering_brick:=control_is_brick_menu_entry.Checked;
end;
//______________________________________________________________________________

procedure Tpad_form.show_brick_templates_menu_entryClick(Sender: TObject);

begin
  show_brick_templates_menu_entry.Checked:=True;  // radio item

  show_brick_templates:=True;  // 237c for trackpad menu

  redraw(True);
end;
//_______________________________________________

procedure Tpad_form.hide_brick_templates_menu_entryClick(Sender: TObject);

begin
  hide_brick_templates_menu_entry.Checked:=True;  // radio item

  show_brick_templates:=False;  // 237c for trackpad menu

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.show_only_brick_templates_menu_entryClick(Sender: TObject);

begin
  show_only_brick_templates_menu_entry.Checked:=True;  // radio item

  redraw(True);
end;
//_______________________________________________

procedure Tpad_form.all_brick_templates_menu_entryClick(Sender: TObject);

begin
  all_brick_templates_menu_entry.Checked:=True;  // radio item

  redraw(True);
end;
//_______________________________________________

procedure Tpad_form.current_brick_templates_only_menu_entryClick(Sender: TObject);

begin
  current_brick_templates_only_menu_entry.Checked:=True;  // radio item

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.show_hide_brick_shapes_menu_entryClick(Sender: TObject);  // 235a

begin
  bgnd_form.show_hide_brick_shapes_colour_menu_entry.Click;
end;
//______________________________________________________________________________

procedure Tpad_form.convert_group_menu_entryClick(Sender: TObject);

begin
  other_gauges_menu_entry.Click;

  if alert(3,'    convert  group',
             'green_panel_begin tree.gif ||To convert a group of templates to a different gauge or scale, click the `0convert group`1 button above the gauge list. green_panel_end | ',
             '','','','','cancel','OK',0)=5 then gauge_form.Close;

end;
//______________________________________________________________________________

procedure Tpad_form.brick_buttonClick(Sender: TObject);    // 235b

begin
  brick_form.Show;
  redraw(True);     // show chair labels
end;
//______________________________________________________________________________

procedure add_chair_options_sticker(option:integer);

  // option  1=solid jaws  2=jaw slots   3=jaws only   4=mixed jaws

  // add a sticker

var
  n,t:integer;
  str,list_str:string;


begin
  delete_existing_symbols_by_code(1);   // if any  (code 1)

  case option of
    1: str:='solid jaws';   // max 12 chars..
    2: str:='jaw slots';
    3: str:='jaws only';
    4: str:='mixed jaws';
  end;//case

  t:=2;      // sticker

  list_str:='# '+str;  // sticker

  SetLength(current_symbols,Length(current_symbols)+1);  // create a new line in symbols list

  n:=HIGH(current_symbols);   // index to it

  with current_symbols[n].symbol_data do begin

    str:=str+'                ';              // ensure file is filled..
    list_str:=list_str+'                ';

    symb_list_str:=Copy(list_str,1,14);
    symb_id_str:=Copy(str,1,12);

    symb_check_rail:=False;

  case option of
    1: symb_colour:=clAqua;    //sticker_colour_panel.Color;
    2: symb_colour:=clFuchsia;
    3: symb_colour:=clLime;
    4: symb_colour:=clYellow;
  end;//case

    symb_type:=t;

    symb_size:=3;
    symb_rail:=2;  // turnout-road crossing rail    locator_rail;

    symb_code:=1;          // chair options sticker
    symb_spare_float:=0;

    if plain_track=True
       then symb_x:=0-xorg/2
       else symb_x:=dpx-xorg;   // locatorx-xorg;    // from CTRL-1 to allow roaming and tools>make etc.

  end;//with

  update_symbols_dialog;

  highlit_symbol:=-1; // reset

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.chairs_menu_entryClick(Sender: TObject);

var
  n:integer;

begin

   // 238a  experimental chairing

  for n:=0 to High(chair_frames) do begin         // init checkboxes on chairs_form ...

    chair_frames[n].include_checkbox0.Checked:=current_jaw_options_set[n][0];     // include inner jaw
    chair_frames[n].include_checkbox1.Checked:=current_jaw_options_set[n][1];     // include outer jaw

    chair_frames[n].loose_checkbox0.Checked:=current_jaw_options_set[n][2];     // outer jaw is loose

    chair_frames[n].export_checkbox1.Checked:=current_jaw_options_set[n][3];    // export loose jaw only
    chair_frames[n].export_checkbox2.Checked:=current_jaw_options_set[n][4];    // export rail seat

    chair_frames[n].include_checkbox2.Checked:=current_jaw_options_set[n][5];   // include key on outer jaw

  end;//next frame

  if do_show_modal(chairs_form)=mrOK
     then begin
            for n:=0 to High(chair_frames) do begin    // update from checkboxes on chairs_form ...

              current_jaw_options_set[n][0]:=chair_frames[n].include_checkbox0.Checked;     // include inner jaw
              current_jaw_options_set[n][1]:=chair_frames[n].include_checkbox1.Checked;     // include outer jaw

              current_jaw_options_set[n][2]:=chair_frames[n].loose_checkbox0.Checked;     // outer jaw is loose

              current_jaw_options_set[n][3]:=chair_frames[n].export_checkbox1.Checked;    // export loose jaw only
              current_jaw_options_set[n][4]:=chair_frames[n].export_checkbox2.Checked;    // export rail seat

              current_jaw_options_set[n][5]:=chair_frames[n].include_checkbox2.Checked;   // include key on outer jaw

            end;//next frame

            add_chair_options_sticker(chair_option_clicked);
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.fixed_ccl_ccr_menu_entryClick(Sender: TObject);

begin
  cpi.ccl_ccr_variable_pi:=False;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.variable_ccl_ccr_menu_entryClick(Sender: TObject);

begin
  cpi.ccl_ccr_variable_pi:=True;

  redraw(True);
end;
//______________________________________________________________________________

procedure Tpad_form.switch_drive_sliders_menu_entryClick(Sender: TObject);       // 244a

begin
  with sliders_form do begin
    slider1_edit.Text:=slider1_str;
    slider2_edit.Text:=slider2_str;
    slider3_edit.Text:=slider3_str;
    slider4_edit.Text:=slider4_str;
    slider5_edit.Text:=slider5_str;
  end;//with

  if do_show_modal(sliders_form)=mrOk
     then begin
            with sliders_form do begin
              slider1_str:=UpperCase(slider1_edit.Text);
              slider2_str:=UpperCase(slider2_edit.Text);
              slider3_str:=UpperCase(slider3_edit.Text);
              slider4_str:=UpperCase(slider4_edit.Text);
              slider5_str:=UpperCase(slider5_edit.Text);
            end;//with

            redraw(True);
          end;
end;
//______________________________________________________________________________

procedure Tpad_form.pad_file_viewer_menu_entryClick(Sender: TObject);

begin
  keep_form_was_showing:=False;
  do_show_modal(file_viewer_form);
end;
//______________________________________________________________________________

procedure Tpad_form.get_file_from_code_menu_entryClick(Sender: TObject);

begin
  do_open_source_bang('GET FILE FROM CODE');  // OT2024
end;
//______________________________________________________________________________


end.



