From 5f0e6a2b153cfdb2cea43cb2356fb7f6f2aba720 Mon Sep 17 00:00:00 2001 From: Mattia Affabris Date: Fri, 24 Feb 2017 19:38:25 +0100 Subject: [PATCH] better usage flags --- CHANGELOG.md | 6 ++- source/args.py | 118 +++++++++++++++++++++++----------------------- source/tacview.py | 60 +++++++++++------------ 3 files changed, 94 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e2c5ac..9789b16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ + usage documentation + minor bugfixes + heading fix -+ heading flag ++ heading override + conventional ranges data + better rendering + +#### 0.7.0 + ++ better usage flags diff --git a/source/args.py b/source/args.py index 5a5689f..d6cf950 100644 --- a/source/args.py +++ b/source/args.py @@ -8,64 +8,64 @@ RANGE = None TARGET = None FILE = None -LEEWAY = None -ENTRY = None -DIRECTION = None -BASE = None -ROLL = None -TRACK = None -PICKLE = None -ABORT = None -FLOOR = None +LEEWAY_ALT = None +LEEWAY_HDG = None +ATTACK_HDG = None +BASE_DIST = None +BASE_ALT = None +TRACK_ALT = None +RELEASE_ALT = None +ABORT_ALT = None +FLOOR_ALT = None def parse(): global RANGE global TARGET global FILE - global LEEWAY - global ENTRY - global DIRECTION - global BASE - global ROLL - global TRACK - global PICKLE - global ABORT - global FLOOR - - parser = argparse.ArgumentParser(description="generate .xml files to visually render SLED attack profiles in the Tacview 3D environment version: 0.6.0-beta1") - parser.add_argument("-v", "--version", action="version", version="0.6.0-beta1") + global LEEWAY_ALT + global LEEWAY_HDG + global ATTACK_HDG + global BASE_DIST + global BASE_ALT + global TRACK_ALT + global RELEASE_ALT + global ABORT_ALT + global FLOOR_ALT + + parser = argparse.ArgumentParser(description="generate .xml files to visually render SLED attack profiles in the Tacview 3D environment version: 0.6.0-beta1", formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=30)) + parser.add_argument("-v", "--version", action="version", version="0.7.0") parser.add_argument("range", type=str, help="the range containing the attacked target") parser.add_argument("target", type=str, help="the attacked target") optional_options = parser.add_argument_group("optional other parameters") - optional_options.add_argument("-o", "--out", type=str, help="name of the generated .xml file: default \"sled\"", metavar="file", default="sled") - optional_options.add_argument("-l", "--leeway", type=_positive_int, help="available +/- leeway for the SLED's roll-in, release, and track altitudes (in feet) [default: 200ft]", metavar="ft", default=200) - optional_options.add_argument("-e", "--entry", type=_angle, help="available +/- leeway for the range's attack heading at the SLED's roll-in altitude (in degrees) [default: 10°]", metavar="°", default=10) - optional_options.add_argument("-d", "--direction", type=_heading, help="required attack heading, overrides the range's default (in degrees)", metavar="°", default=None) + optional_options.add_argument("-fn", "--filename", type=str, help="name of the generated .xml file [default: \"sled\"]", metavar="str", default="sled") + optional_options.add_argument("-la", "--leewayalt", type=_positive_int, help="available +/- leeway for the SLED's base, release, and track altitudes (in feet) [default: 200ft]", metavar="ft", default=200) + optional_options.add_argument("-lh", "--leewayhdg", type=_angle, help="available +/- leeway for the range's attack heading at the SLED's base altitude (in degrees) [default: 10°]", metavar="°", default=10) + optional_options.add_argument("-ah", "--attackhdg", type=_heading, help="required attack heading, overrides the range's default (in degrees)", metavar="°", default=None) required_options = parser.add_argument_group("required SLED parametes") - required_options.add_argument("-b", "--base", type=_positive_int, help="base distance (in nautical miles)", metavar="nm", required=True) - required_options.add_argument("-r", "--roll", type=_positive_float, help="roll-in altitude (in feet MSL)", metavar="ft", required=True) - required_options.add_argument("-t", "--track", type=_positive_float, help="track altitude (in feet MSL)", metavar="ft", required=True) - required_options.add_argument("-p", "--pickle", type=_positive_float, help="release altitude (in feet MSL)", metavar="ft", required=True) - required_options.add_argument("-a", "--abort", type=_positive_float, help="abort altitude (in feet MSL)", metavar="ft", required=True) - required_options.add_argument("-f", "--floor", type=_positive_float, help="minimum altitude (in feet MSL)", metavar="ft", required=True) + required_options.add_argument("-bd", "--basedist", type=_positive_int, help="base distance (in nautical miles)", metavar="nm", required=True) + required_options.add_argument("-ba", "--basealt", type=_positive_float, help="base altitude (in feet MSL)", metavar="ft", required=True) + required_options.add_argument("-ta", "--trackalt", type=_positive_float, help="track altitude (in feet MSL)", metavar="ft", required=True) + required_options.add_argument("-ra", "--releasealt", type=_positive_float, help="release altitude (in feet MSL)", metavar="ft", required=True) + required_options.add_argument("-aa", "--abortalt", type=_positive_float, help="abort altitude (in feet MSL)", metavar="ft", required=True) + required_options.add_argument("-fa", "--flooralt", type=_positive_float, help="minimum altitude (in feet MSL)", metavar="ft", required=True) args = parser.parse_args() RANGE = args.range TARGET = args.target - FILE = args.out - LEEWAY = args.leeway - ENTRY = args.entry - DIRECTION = args.direction - BASE = args.base - ROLL = args.roll - TRACK = args.track - PICKLE = args.pickle - ABORT = args.abort - FLOOR = args.floor + FILE = args.filename + LEEWAY_ALT = args.leewayalt + LEEWAY_HDG = args.leewayhdg + ATTACK_HDG = args.attackhdg + BASE_DIST = args.basedist + BASE_ALT = args.basealt + TRACK_ALT = args.trackalt + RELEASE_ALT = args.releasealt + ABORT_ALT = args.abortalt + FLOOR_ALT = args.flooralt def check_range(): global RANGE @@ -100,24 +100,24 @@ def check_target(): raise Exception def convert(): - global LEEWAY - global DIRECTION - global BASE - global ROLL - global TRACK - global PICKLE - global ABORT - global FLOOR - - LEEWAY = calc.ft_to_m(LEEWAY) - if DIRECTION is not None: - DIRECTION = calc.thdg_to_mhdg(DIRECTION) - BASE = calc.ft_to_m(BASE) - ROLL = calc.ft_to_m(ROLL) - TRACK = calc.ft_to_m(TRACK) - PICKLE = calc.ft_to_m(PICKLE) - ABORT = calc.ft_to_m(ABORT) - FLOOR = calc.ft_to_m(FLOOR) + global LEEWAY_ALT + global ATTACK_HDG + global BASE_DIST + global BASE_ALT + global TRACK_ALT + global RELEASE_ALT + global ABORT_ALT + global FLOOR_ALT + + LEEWAY_ALT = calc.ft_to_m(LEEWAY_ALT) + if ATTACK_HDG is not None: + ATTACK_HDG = calc.thdg_to_mhdg(ATTACK_HDG) + BASE_DIST = calc.ft_to_m(BASE_DIST) + BASE_ALT = calc.ft_to_m(BASE_ALT) + TRACK_ALT = calc.ft_to_m(TRACK_ALT) + RELEASE_ALT = calc.ft_to_m(RELEASE_ALT) + ABORT_ALT = calc.ft_to_m(ABORT_ALT) + FLOOR_ALT = calc.ft_to_m(FLOOR_ALT) def _positive_int(value): number = int(value) diff --git a/source/tacview.py b/source/tacview.py index aecdaba..dbd4e9a 100644 --- a/source/tacview.py +++ b/source/tacview.py @@ -11,34 +11,34 @@ def generate(): template = data.load("data/template.yaml") target_altitude = calc.ft_to_m(args.TARGET["altitude"]) - if args.DIRECTION is None: + if args.ATTACK_HDG is None: attack_heading = calc.reverse_heading(calc.thdg_to_mhdg(args.TARGET["heading"])) else: - attack_heading = calc.reverse_heading(args.DIRECTION) + attack_heading = calc.reverse_heading(args.ATTACK_HDG) - wire_length = calc.hypotenuse_from_catheti(args.BASE, args.ROLL-target_altitude) - wire_angle = calc.angle_from_catheti(args.ROLL, args.BASE) - wire_entry_width = calc.sin_cathetus_from_angle(wire_length, args.ENTRY) + wire_length = calc.hypotenuse_from_catheti(args.BASE_DIST, args.BASE_ALT-target_altitude) + wire_angle = calc.angle_from_catheti(args.BASE_ALT, args.BASE_DIST) + wire_entry_width = calc.sin_cathetus_from_angle(wire_length, args.LEEWAY_HDG) - floor_lat, floor_lon = calc.shift_coords(args.TARGET["position"], args.BASE*0.3, -attack_heading) + floor_lat, floor_lon = calc.shift_coords(args.TARGET["position"], args.BASE_DIST*0.3, -attack_heading) abort_lat, abort_lon = floor_lat, floor_lon - pickle_lat, pickle_lon = calc.shift_coords(args.TARGET["position"], calc.cos_cathetus_from_angle(args.PICKLE-target_altitude, wire_angle), -attack_heading) - track_lat, track_lon = calc.shift_coords(args.TARGET["position"], calc.cos_cathetus_from_angle(args.TRACK-target_altitude, wire_angle), -attack_heading) + release_lat, release_lon = calc.shift_coords(args.TARGET["position"], calc.cos_cathetus_from_angle(args.RELEASE_ALT-target_altitude, wire_angle), -attack_heading) + track_lat, track_lon = calc.shift_coords(args.TARGET["position"], calc.cos_cathetus_from_angle(args.TRACK_ALT-target_altitude, wire_angle), -attack_heading) - floor_altitude = args.FLOOR/2 - abort_altitude = args.FLOOR+((args.ABORT-args.FLOOR)/2) - pickle_altitude = args.PICKLE - track_altitude = args.TRACK + floor_altitude = args.FLOOR_ALT/2 + abort_altitude = args.FLOOR_ALT+((args.ABORT_ALT-args.FLOOR_ALT)/2) + release_altitude = args.RELEASE_ALT + track_altitude = args.TRACK_ALT - abort_width = wire_entry_width/2 - floor_width = abort_width - pickle_width = wire_entry_width/1.5 - track_width = pickle_width + floor_width = wire_entry_width/2 + abort_width = floor_width + release_width = wire_entry_width/1.5 + track_width = release_width - abort_length = args.BASE - floor_length = abort_length - pickle_length = args.BASE*0.5 - track_length = pickle_length + floor_length = args.BASE_DIST + abort_length = floor_length + release_length = args.BASE_DIST*0.5 + track_length = release_length template[0]["Position"]["Latitude"] = args.TARGET["position"]["latitude"] template[0]["Position"]["Longitude"] = args.TARGET["position"]["longitude"] @@ -47,7 +47,7 @@ def generate(): template[0]["Orientation"]["Yaw"] = attack_heading template[0]["Size"]["Width"] = wire_entry_width template[0]["Size"]["Length"] = wire_length - template[0]["Size"]["Height"] = args.LEEWAY*2 + template[0]["Size"]["Height"] = args.LEEWAY_ALT*2 template[1]["Position"]["Latitude"] = floor_lat template[1]["Position"]["Longitude"] = floor_lon @@ -55,7 +55,7 @@ def generate(): template[1]["Orientation"]["Yaw"] = attack_heading template[1]["Size"]["Width"] = floor_width template[1]["Size"]["Length"] = floor_length - template[1]["Size"]["Height"] = args.FLOOR + template[1]["Size"]["Height"] = args.FLOOR_ALT template[2]["Position"]["Latitude"] = abort_lat template[2]["Position"]["Longitude"] = abort_lon @@ -63,15 +63,15 @@ def generate(): template[2]["Orientation"]["Yaw"] = attack_heading template[2]["Size"]["Width"] = abort_width template[2]["Size"]["Length"] = abort_length - template[2]["Size"]["Height"] = args.ABORT-args.FLOOR + template[2]["Size"]["Height"] = args.ABORT_ALT-args.FLOOR_ALT - template[3]["Position"]["Latitude"] = pickle_lat - template[3]["Position"]["Longitude"] = pickle_lon - template[3]["Position"]["Altitude"] = pickle_altitude + template[3]["Position"]["Latitude"] = release_lat + template[3]["Position"]["Longitude"] = release_lon + template[3]["Position"]["Altitude"] = release_altitude template[3]["Orientation"]["Yaw"] = attack_heading - template[3]["Size"]["Width"] = pickle_width - template[3]["Size"]["Length"] = pickle_length - template[3]["Size"]["Height"] = args.LEEWAY*2 + template[3]["Size"]["Width"] = release_width + template[3]["Size"]["Length"] = release_length + template[3]["Size"]["Height"] = args.LEEWAY_ALT*2 template[4]["Position"]["Latitude"] = track_lat template[4]["Position"]["Longitude"] = track_lon @@ -79,7 +79,7 @@ def generate(): template[4]["Orientation"]["Yaw"] = attack_heading template[4]["Size"]["Width"] = track_width template[4]["Size"]["Length"] = track_length - template[4]["Size"]["Height"] = args.LEEWAY*2 + template[4]["Size"]["Height"] = args.LEEWAY_ALT*2 _dict_to_file(template)